2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
15 #include <afs/param.h>
24 #include "results_dlg.h"
25 #include "volume_inf.h"
26 #include "mount_points_dlg.h"
27 #include "symlinks_dlg.h"
28 #include "hourglass.h"
29 #include "down_servers_dlg.h"
32 #include <rx/rx_globals.h>
36 #include <afs/afs_consts.h>
37 #include <afs/cellconfig.h>
38 #include <afs/vldbint.h>
39 #include <afs/volser.h>
41 #include <WINNT\afsreg.h>
46 #include <cm_scache.h>
50 #define STRSAFE_NO_DEPRECATE
53 #define PCCHAR(str) ((char *)(const char *)(str))
54 #define VL_NOENT (363524L)
57 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
58 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
60 #define MAXCELLCHARS 64
61 #define MAXHOSTCHARS 64
62 #define MAXHOSTSPERCELL 8
64 static char space[MAXSIZE];
65 static char tspace[1024];
67 static struct ubik_client *uclient;
68 static int rxInitDone = 0;
69 static char pn[] = "fs";
71 // #define LOGGING_ON // Enable this to log certain pioctl calls
74 static char *szLogFileName = "afsguilog.txt";
78 class CStringUtf8 : public CStringA
81 CStringUtf8(const CStringW& csw) : CStringA()
86 CStringUtf8(const char * cp) : CStringA(cp) {}
88 CStringUtf8() :CStringA() {}
90 void SetString(const CStringW& csw)
95 rv = WideCharToMultiByte(CP_UTF8, 0, csw, -1,
96 buffer, sizeof(buffer),
100 CStringA::SetString(buffer);
102 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
105 cb_req = WideCharToMultiByte(CP_UTF8, 0, csw, -1, NULL, 0, NULL, FALSE);
109 WideCharToMultiByte(CP_UTF8, 0, csw, -1, CStringA::GetBuffer(cb_req), cb_req, NULL, FALSE);
110 CStringA::ReleaseBuffer();
120 static CString _Utf8ToCString(const char * ustr)
125 cch = MultiByteToWideChar(CP_UTF8, 0, ustr, -1, NULL, 0);
132 cch = MultiByteToWideChar(CP_UTF8, 0, ustr, -1, cs.GetBuffer(cch), cch);
139 long pioctl_T(const CString& path, long opcode, struct ViceIoctl * blob, int follow)
141 CStringUtf8 upath(path);
143 return pioctl_utf8(PCCHAR(upath), opcode, blob, follow);
146 #define Utf8ToCString(cs) CStringUtf8::_Utf8ToCString(cs)
148 #define pioctl_T(path, op, vblob, follow) pioctl(PCCHAR(path), op, vblob, follow)
149 #define Utf8ToCString(cs) (cs)
155 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
159 code = ugen_ClientInit(noAuthFlag, (char *)AFSDIR_CLIENT_ETC_DIRPATH,
160 info->name, 0, &uclient,
161 NULL, pn, rxkad_clear,
162 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
163 0, 0, USER_SERVICE_ID);
169 OpenFile(char *file, char *rwp)
176 code = GetWindowsDirectoryA(wdir, sizeof(wdir));
177 if (code == 0 || code > sizeof(wdir))
180 /* add trailing backslash, if required */
182 if (wdir[tlen - 1] != '\\')
187 fp = fopen(wdir, rwp);
192 CString StripPath(CString& strPath)
194 int nIndex = strPath.ReverseFind('\\');
196 CString strFile = strPath.Mid(nIndex + 1);
197 if (strFile.IsEmpty())
203 CStringArray& StripPath(CStringArray& files)
205 for (int i = 0; i < files.GetSize(); i++)
206 files[i] = StripPath(files[i]);
211 void Flush(const CStringArray& files)
214 struct ViceIoctl blob;
219 for (int i = 0; i < files.GetSize(); i++) {
220 blob.in_size = blob.out_size = 0;
222 code = pioctl_T(files[i], VIOCFLUSH, &blob, 0);
226 ShowMessageBox(IDS_FLUSH_FAILED, MB_ICONERROR, IDS_FLUSH_FAILED, files[i]);
228 ShowMessageBox(IDS_FLUSH_ERROR, MB_ICONERROR, IDS_FLUSH_ERROR, files[i], strerror(errno));
233 ShowMessageBox(IDS_FLUSH_OK, MB_ICONINFORMATION, IDS_FLUSH_OK);
236 void FlushVolume(const CStringArray& files)
239 struct ViceIoctl blob;
244 for (int i = 0; i < files.GetSize(); i++) {
245 blob.in_size = blob.out_size = 0;
247 code = pioctl_T(files[i], VIOC_FLUSHVOLUME, &blob, 0);
250 ShowMessageBox(IDS_FLUSH_VOLUME_ERROR, MB_ICONERROR, IDS_FLUSH_VOLUME_ERROR, files[i], strerror(errno));
255 ShowMessageBox(IDS_FLUSH_VOLUME_OK, MB_ICONINFORMATION, IDS_FLUSH_VOLUME_OK);
258 void WhichCell(CStringArray& files)
261 struct ViceIoctl blob;
266 CStringArray results;
272 for (int i = 0; i < files.GetSize(); i++) {
274 blob.out_size = MAXSIZE;
277 code = pioctl_T(files[i], VIOC_FILE_CELL_NAME, &blob, 1);
279 if (code == ENOENT) {
280 LoadString (str, IDS_CANT_GET_CELL);
283 results.Add(GetAfsError(errno));
285 space[MAXSIZE - 1] = '\0';
286 results.Add(Utf8ToCString(space));
290 LoadString (str, IDS_SHOW_CELL);
291 LoadString (str2, IDS_SHOW_CELL_COLUMN);
292 CResultsDlg dlg(SHOW_CELL_HELP_ID);
293 dlg.SetContents(str, str2, StripPath(files), results);
300 struct ViceIoctl blob;
305 blob.in = (char *) 0;
306 blob.out_size = MAXSIZE;
309 code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1);
312 //Die(errno, (char *) 0);
315 //printf("This workstation belongs to cell '%s'\n", space);
321 struct ViceIoctl blob;
325 code = pioctl(0, VIOCCKBACK, &blob, 1);
327 ShowMessageBox(IDS_CHECK_VOLUMES_ERROR, MB_ICONERROR, IDS_CHECK_VOLUMES_ERROR, GetAfsError(errno, CString()));
331 ShowMessageBox(IDS_CHECK_VOLUMES_OK, MB_OK|MB_ICONINFORMATION, IDS_CHECK_VOLUMES_OK);
336 void SetCacheSizeCmd(LONG nNewCacheSize)
339 struct ViceIoctl blob;
343 blob.in = (char *) &nNewCacheSize;
344 blob.in_size = sizeof(LONG);
347 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
349 // Die(errno, (char *) 0);
351 // printf("New cache size set.\n");
354 void WhereIs(CStringArray& files)
357 struct ViceIoctl blob;
358 CStringArray servers;
359 CStringArray resultFiles;
365 for (int i = 0; i < files.GetSize(); i++) {
366 blob.out_size = MAXSIZE;
369 memset(space, 0, sizeof(space));
371 code = pioctl_T(files[i], VIOCWHEREIS, &blob, 1);
373 resultFiles.Add(StripPath(files[i]));
374 servers.Add(GetAfsError(errno));
378 LONG *hosts = (LONG *)space;
382 for (int j = 0; j < MAXHOSTS; j++) {
385 char *hostName = hostutil_GetNameByINet(hosts[j]);
387 resultFiles.Add(StripPath(files[i]));
390 resultFiles.Add(" ");
391 servers.Add(hostName);
395 LoadString (str, IDS_SHOW_FS);
396 LoadString (str2, IDS_SHOW_FS_COLUMN);
397 CResultsDlg dlg(SHOW_FILE_SERVERS_HELP_ID);
398 dlg.SetContents(str, str2, resultFiles, servers);
403 CMtoUNIXerror(int cm_code)
406 case CM_ERROR_TIMEDOUT:
408 case CM_ERROR_NOACCESS:
410 case CM_ERROR_NOSUCHFILE:
416 case CM_ERROR_EXISTS:
418 case CM_ERROR_CROSSDEVLINK:
420 case CM_ERROR_NOTDIR:
424 case CM_ERROR_READONLY:
426 case CM_ERROR_WOULDBLOCK:
428 case CM_ERROR_NOSUCHCELL:
429 return ESRCH; /* hack */
430 case CM_ERROR_NOSUCHVOLUME:
431 return EPIPE; /* hack */
432 case CM_ERROR_NOMORETOKENS:
433 return EDOM; /* hack */
434 case CM_ERROR_TOOMANYBUFS:
435 return EFBIG; /* hack */
437 if (cm_code > 0 && cm_code < EILSEQ)
444 CString GetAfsError(int code, const TCHAR *filename)
448 code = CMtoUNIXerror(code);
450 if (code == EINVAL) {
452 strMsg.Format(_T("Invalid argument; it is possible that the file is not in AFS"));
454 strMsg.Format(_T("Invalid argument"));
455 } else if (code == ENOENT) {
457 strMsg.Format(_T("The file does not exist"));
459 strMsg.Format(_T("No such file returned"));
460 } else if (code == EROFS) {
461 strMsg.Format(_T("You can not change a backup or readonly volume"));
462 } else if (code == EACCES || code == EPERM) {
463 strMsg.Format(_T("You do not have the required rights to do this operation"));
464 } else if (code == ENODEV) {
465 strMsg.Format(_T("AFS service may not have started"));
466 } else if (code == ESRCH) {
467 strMsg.Format(_T("Cell name not recognized"));
468 } else if (code == ETIMEDOUT) {
469 strMsg.Format(_T("Connection timed out"));
470 } else if (code == EPIPE) {
471 strMsg.Format(_T("Volume name or ID not recognized"));
473 strMsg.Format(_T("Error 0x%x occurred"), code);
480 /************************************************************************
481 ************************** ACL Code *************************************
482 ************************************************************************/
484 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
487 struct AclEntry *next;
493 int dfs; // Originally true if a dfs acl; now also the type
494 // of the acl (1, 2, or 3, corresponding to object,
495 // initial dir, or initial object).
496 sec_rgy_name_t cell; // DFS cell name
499 struct AclEntry *pluslist;
500 struct AclEntry *minuslist;
503 int foldcmp (char *a, char *b)
509 if (t >= 'A' && t <= 'Z') t += 0x20;
510 if (u >= 'A' && u <= 'Z') u += 0x20;
511 if (t != u) return 1;
512 if (t == 0) return 0;
516 extern "C" void ZapList(struct AclEntry *alist)
518 struct AclEntry *tp, *np;
520 for (tp = alist; tp; tp = np) {
526 extern "C" void ZapAcl (struct Acl *acl)
528 ZapList(acl->pluslist);
529 ZapList(acl->minuslist);
533 extern "C" int PruneList (struct AclEntry **ae, int dfs)
535 struct AclEntry **lp = ae;
536 struct AclEntry *te, *ne;
539 for (te = *ae; te; te = ne) {
540 if ((!dfs && te->rights == 0) || te->rights == -1) {
555 char *SkipLine (char *astr)
557 while (*astr != '\n')
565 /* tell if a name is 23 or -45 (digits or minus digits), which are bad names we must prune */
566 static int BadName(char *aname)
570 /* all must be '-' or digit to be bad */
571 while (tc = *aname++) {
572 if ((tc != '-') && (tc < '0' || tc > '9'))
579 CString GetRightsString(LONG arights, int dfs)
584 if (arights & PRSFS_READ) str += _T("r");
585 if (arights & PRSFS_LOOKUP) str += _T("l");
586 if (arights & PRSFS_INSERT) str += _T("i");
587 if (arights & PRSFS_DELETE) str += _T("d");
588 if (arights & PRSFS_WRITE) str += _T("w");
589 if (arights & PRSFS_LOCK) str += _T("k");
590 if (arights & PRSFS_ADMINISTER) str += _T("a");
594 if (arights & DFS_READ) str += _T("r"); else str += _T("-");
595 if (arights & DFS_WRITE) str += _T("w"); else printf(_T("-"));
596 if (arights & DFS_EXECUTE) str += _T("x"); else printf(_T("-"));
597 if (arights & DFS_CONTROL) str += _T("c"); else printf(_T("-"));
598 if (arights & DFS_INSERT) str += _T("i"); else printf(_T("-"));
599 if (arights & DFS_DELETE) str += _T("d"); else printf(_T("-"));
600 if (arights & (DFS_USRALL)) str += _T("+");
607 char *AclToString(struct Acl *acl)
609 static char mydata[MAXSIZE];
610 char tstring[MAXSIZE];
615 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
618 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
620 for(tp = acl->pluslist; tp; tp = tp->next) {
621 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
622 strcat(mydata, tstring);
625 for(tp = acl->minuslist; tp; tp = tp->next) {
626 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
627 strcat(mydata, tstring);
633 struct Acl *EmptyAcl(const CString& strCellName)
636 CStringUtf8 ustrCell(strCellName);
638 tp = (struct Acl *)malloc(sizeof (struct Acl));
639 tp->nplus = tp->nminus = 0;
640 tp->pluslist = tp->minuslist = 0;
642 StringCbCopyA(tp->cell, sizeof(tp->cell), ustrCell);
647 struct Acl *EmptyAcl(char *astr)
652 tp = (struct Acl *)malloc(sizeof (struct Acl));
653 tp->nplus = tp->nminus = 0;
654 tp->pluslist = tp->minuslist = 0;
656 if (astr == NULL || sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell) <= 0) {
664 ParseAcl (char *astr)
666 int nplus, nminus, i, trights, ret;
668 struct AclEntry *first, *next, *last, *tl;
672 if (astr == NULL || strlen(astr) == 0)
675 ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
680 astr = SkipLine(astr);
681 ret = sscanf(astr, "%d", &ta->nminus);
686 astr = SkipLine(astr);
693 for(i=0;i<nplus;i++) {
694 ret = sscanf(astr, "%100s %d", tname, &trights);
697 astr = SkipLine(astr);
698 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
703 strcpy(tl->name, tname);
704 tl->rights = trights;
710 ta->pluslist = first;
714 for(i=0;i<nminus;i++) {
715 ret = sscanf(astr, "%100s %d", tname, &trights);
718 astr = SkipLine(astr);
719 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
724 strcpy(tl->name, tname);
725 tl->rights = trights;
731 ta->minuslist = first;
736 for (;first; first = next) {
740 first = ta->pluslist;
743 for (;first; first = next) {
751 /* clean up an access control list of its bad entries; return 1 if we made
752 any changes to the list, and 0 otherwise */
753 extern "C" int CleanAcl(struct Acl *aa)
755 struct AclEntry *te, **le, *ne;
760 /* Don't correct DFS ACL's for now */
764 /* prune out bad entries */
765 changes = 0; /* count deleted entries */
767 for(te = aa->pluslist; te; te = ne) {
769 if (BadName(te->name)) {
782 for(te = aa->minuslist; te; te = ne) {
784 if (BadName(te->name)) {
798 void CleanACL(CStringArray& names)
802 struct ViceIoctl blob;
805 ShowMessageBox(IDS_CLEANACL_MSG, MB_OK|MB_ICONINFORMATION, IDS_CLEANACL_MSG);
809 for (int i = 0; i < names.GetSize(); i++) {
810 blob.out_size = MAXSIZE;
814 code = pioctl_T(names[i], VIOCGETAL, &blob, 1);
816 ShowMessageBox(IDS_CLEANACL_ERROR, MB_ICONERROR, 0, names[i], GetAfsError(errno));
820 ta = ParseAcl(space);
822 ShowMessageBox(IDS_INVALID_ACL_DATA, MB_ICONERROR, IDS_INVALID_ACL_DATA);
826 ShowMessageBox(IDS_CLEANACL_NOT_SUPPORTED, MB_ICONERROR, IDS_CLEANACL_NOT_SUPPORTED, names[i]);
830 changes = CleanAcl(ta);
834 /* now set the acl */
835 blob.in = AclToString(ta);
836 blob.in_size = strlen((char *)blob.in) + 1;
839 code = pioctl_T(names[i], VIOCSETAL, &blob, 1);
841 if (errno == EINVAL) {
842 ShowMessageBox(IDS_CLEANACL_INVALID_ARG, MB_ICONERROR, IDS_CLEANACL_INVALID_ARG, names[i]);
846 ShowMessageBox(IDS_CLEANACL_ERROR, MB_ICONERROR, 0, names[i], GetAfsError(errno));
853 // Derived from fs.c's ListAclCmd
854 BOOL GetRights(const CString& strDir, CStringArray& strNormal, CStringArray& strNegative)
858 struct ViceIoctl blob;
860 int idf = 0; //getidf(as, parm_listacl_id);
864 blob.out_size = MAXSIZE;
866 blob.in = blob.out = space;
868 code = pioctl_T(strDir, VIOCGETAL, &blob, 1);
870 ShowMessageBox(IDS_GETRIGHTS_ERROR, MB_ICONERROR, IDS_GETRIGHTS_ERROR, strDir, GetAfsError(errno));
874 ta = ParseAcl(space);
876 ShowMessageBox(IDS_INVALID_ACL_DATA, MB_ICONERROR, IDS_INVALID_ACL_DATA);
880 ShowMessageBox(IDS_DFSACL_ERROR, MB_ICONERROR, IDS_DFSACL_ERROR);
885 // printf(" Default cell = %s\n", ta->cell);
890 for (te = ta->pluslist; te; te = te->next) {
891 strNormal.Add(te->name);
892 strNormal.Add(GetRightsString(te->rights, ta->dfs));
896 if (ta->nminus > 0) {
897 for (te = ta->minuslist; te; te = te->next) {
898 strNegative.Add(te->name);
899 strNegative.Add(GetRightsString(te->rights, ta->dfs));
906 struct AclEntry *FindList(struct AclEntry *pCurEntry, const char *entryName)
909 if (!foldcmp(pCurEntry->name, PCCHAR(entryName)))
911 pCurEntry = pCurEntry->next;
917 void ChangeList(struct Acl *pAcl, BYTE bNormalRights, const CString & entryName, LONG nEntryRights)
922 struct AclEntry *pEntry;
923 CStringUtf8 uEntryName(entryName);
927 pEntry = (bNormalRights ? pAcl->pluslist : pAcl->minuslist);
928 pEntry = FindList(pEntry, uEntryName);
930 /* Found the item already in the list. */
932 pEntry->rights = nEntryRights;
934 pAcl->nplus -= PruneList(&pAcl->pluslist, pAcl->dfs);
936 pAcl->nminus -= PruneList(&pAcl->minuslist, pAcl->dfs);
940 /* Otherwise we make a new item and plug in the new data. */
941 pEntry = (struct AclEntry *) malloc(sizeof (struct AclEntry));
944 strcpy(pEntry->name, uEntryName);
945 pEntry->rights = nEntryRights;
948 pEntry->next = pAcl->pluslist;
949 pAcl->pluslist = pEntry;
951 if (nEntryRights == 0 || nEntryRights == -1)
952 pAcl->nplus -= PruneList(&pAcl->pluslist, pAcl->dfs);
955 pEntry->next = pAcl->minuslist;
956 pAcl->minuslist = pEntry;
958 if (nEntryRights == 0)
959 pAcl->nminus -= PruneList(&pAcl->minuslist, pAcl->dfs);
963 enum rtype {add, destroy, deny};
965 static LONG Convert(const CString& strRights, int dfs, enum rtype *rtypep)
970 *rtypep = add; /* add rights, by default */
972 if (strRights == _T("read"))
973 return PRSFS_READ | PRSFS_LOOKUP;
974 if (strRights == _T("write"))
975 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK;
976 if (strRights == _T("mail"))
977 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
978 if (strRights == _T("all"))
979 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
981 if (strRights == _T("none")) {
982 *rtypep = destroy; /* Remove entire entry */
986 len = strRights.GetLength();
989 for (i = 0; i < len; i++) {
990 TCHAR c = strRights[i];
991 if (c == _T('r')) mode |= PRSFS_READ;
992 else if (c == _T('l')) mode |= PRSFS_LOOKUP;
993 else if (c == _T('i')) mode |= PRSFS_INSERT;
994 else if (c == _T('d')) mode |= PRSFS_DELETE;
995 else if (c == _T('w')) mode |= PRSFS_WRITE;
996 else if (c == _T('k')) mode |= PRSFS_LOCK;
997 else if (c == _T('a')) mode |= PRSFS_ADMINISTER;
999 fprintf(stderr, "illegal rights character '%c'.\n", c);
1006 BOOL SaveACL(const CString& strCellName, const CString& strDir, const CStringArray& normal, const CStringArray& negative)
1009 struct ViceIoctl blob;
1014 HOURGLASS hourglass;
1017 pAcl = EmptyAcl(strCellName);
1019 // Set its normal rights
1021 for (i = 0; i < normal.GetSize(); i += 2) {
1022 rights = Convert(normal[i + 1], 0, &rtype);
1023 ChangeList(pAcl, TRUE, normal[i], rights);
1026 // Set its negative rights
1027 for (i = 0; i < negative.GetSize(); i += 2) {
1028 rights = Convert(negative[i + 1], 0, &rtype);
1029 ChangeList(pAcl, FALSE, negative[i], rights);
1033 blob.in = AclToString(pAcl);
1035 blob.in_size = 1 + strlen((const char *)blob.in);
1037 code = pioctl_T(strDir, VIOCSETAL, &blob, 1);
1039 if (errno == EINVAL)
1040 ShowMessageBox(IDS_SAVE_ACL_EINVAL_ERROR, MB_ICONERROR, IDS_SAVE_ACL_EINVAL_ERROR, strDir);
1042 ShowMessageBox(IDS_SAVE_ACL_ERROR, MB_ICONERROR, IDS_SAVE_ACL_ERROR, strDir, GetAfsError(errno, strDir));
1050 BOOL CopyACL(const CString& strToDir, const CStringArray& normal, const CStringArray& negative, BOOL bClear)
1053 struct ViceIoctl blob;
1055 int idf = 0; // getidf(as, parm_copyacl_id);
1057 HOURGLASS hourglass;
1059 // Get ACL to copy to
1060 blob.out_size = MAXSIZE;
1062 blob.in = blob.out = space;
1064 code = pioctl_T(strToDir, VIOCGETAL, &blob, 1);
1066 ShowMessageBox(IDS_ACL_READ_ERROR, MB_ICONERROR, IDS_ACL_READ_ERROR, strToDir, GetAfsError(errno, strToDir));
1071 pToAcl = EmptyAcl(space);
1073 pToAcl = ParseAcl(space);
1075 if (pToAcl == NULL) {
1076 ShowMessageBox(IDS_INVALID_ACL_DATA, MB_ICONERROR, IDS_INVALID_ACL_DATA);
1083 ShowMessageBox(IDS_NO_DFS_COPY_ACL, MB_ICONERROR, IDS_NO_DFS_COPY_ACL, strToDir);
1090 // Set normal rights
1092 for (i = 0; i < normal.GetSize(); i += 2) {
1093 LONG rights = Convert(normal[i + 1], 0, &rtype);
1094 ChangeList(pToAcl, TRUE, normal[i], rights);
1097 // Set negative rights
1098 for (i = 0; i < negative.GetSize(); i += 2) {
1099 LONG rights = Convert(negative[i + 1], 0, &rtype);
1100 ChangeList(pToAcl, FALSE, normal[i], rights);
1103 // Save modified ACL
1104 blob.in = AclToString(pToAcl);
1106 blob.in_size = 1 + strlen((char *)blob.in);
1108 code = pioctl_T(strToDir, VIOCSETAL, &blob, 1);
1111 if (errno == EINVAL)
1112 ShowMessageBox(IDS_COPY_ACL_EINVAL_ERROR, MB_ICONERROR, IDS_COPY_ACL_EINVAL_ERROR, strToDir);
1114 ShowMessageBox(IDS_COPY_ACL_ERROR, MB_ICONERROR, IDS_COPY_ACL_ERROR, strToDir, GetAfsError(errno, strToDir));
1120 ShowMessageBox(IDS_COPY_ACL_OK, MB_OK|MB_ICONINFORMATION, IDS_COPY_ACL_OK);
1125 CString ParseMountPoint(const CString strFile, CString strMountPoint)
1130 CString strMountPointInfo;
1132 if (strMountPoint[0] == '#')
1133 strType = "Regular";
1134 else if (strMountPoint[0] == '%')
1135 strType = "Read/Write";
1137 int nColon = strMountPoint.Find(':');
1139 strCell = strMountPoint.Mid(1, nColon - 1);
1140 strVolume = strMountPoint.Mid(nColon + 1);
1142 strVolume = strMountPoint.Mid(1);
1144 strMountPointInfo = strFile + _T("\t") + strVolume + _T("\t") + strCell + _T("\t") + strType;
1146 return strMountPointInfo;
1149 CString ParseSymlink(const CString strFile, CString strSymlink)
1151 CString strSymlinkInfo;
1153 strSymlinkInfo = strFile + _T("\t") + strSymlink;
1155 return strSymlinkInfo;
1158 BOOL IsPathInAfs(const CString & strPath)
1160 struct ViceIoctl blob;
1161 cm_ioctlQueryOptions_t options;
1165 HOURGLASS hourglass;
1167 memset(&options, 0, sizeof(options));
1168 options.size = sizeof(options);
1169 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1170 options.literal = 1;
1171 blob.in_size = options.size; /* no variable length data */
1173 blob.out_size = sizeof(cm_fid_t);
1174 blob.out = (char *) &fid;
1176 code = pioctl_T(strPath, VIOCGETFID, &blob, 1);
1178 if ((errno == EINVAL) || (errno == ENOENT))
1185 IsFreelanceRoot(const CString& apath)
1187 struct ViceIoctl blob;
1191 blob.out_size = MAXSIZE;
1194 code = pioctl_T(apath, VIOC_FILE_CELL_NAME, &blob, 1);
1196 return !strcmp("Freelance.Local.Root",space);
1197 return 1; /* assume it is because it is more restrictive that way */
1200 static const char * NetbiosName(void)
1202 static char buffer[1024] = "AFS";
1208 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
1209 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
1210 if (code == ERROR_SUCCESS) {
1211 dummyLen = sizeof(buffer);
1212 code = RegQueryValueExA(parmKey, "NetbiosName", NULL, NULL,
1213 (LPBYTE)buffer, &dummyLen);
1214 RegCloseKey (parmKey);
1216 strcpy(buffer, "AFS");
1221 static void FixNetbiosPath(CString& path)
1223 if (!IsPathInAfs(path)) {
1225 const char * nbname = NetbiosName();
1228 nbroot.Format(_T("\\\\%S\\"), nbname);
1230 nbroot.Format(_T("\\\\%s\\"), nbname);
1233 if (nbroot.CompareNoCase(path) == 0) {
1234 path.Append(_T("all\\"));
1239 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
1241 static BOOL IsAdmin (void)
1243 static BOOL fAdmin = FALSE;
1244 static BOOL fTested = FALSE;
1248 /* Obtain the SID for the AFS client admin group. If the group does
1249 * not exist, then assume we have AFS client admin privileges.
1251 PSID psidAdmin = NULL;
1252 DWORD dwSize, dwSize2;
1253 TCHAR pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
1254 TCHAR *pszRefDomain = NULL;
1255 SID_NAME_USE snu = SidTypeGroup;
1257 dwSize = sizeof(pszAdminGroup);
1259 if (!GetComputerName(pszAdminGroup, &dwSize)) {
1260 /* Can't get computer name. We return false in this case.
1261 Retain fAdmin and fTested. This shouldn't happen.*/
1268 lstrcat(pszAdminGroup, _T("\\"));
1269 lstrcat(pszAdminGroup, _T(AFSCLIENT_ADMIN_GROUPNAME));
1271 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
1272 /* that should always fail. */
1274 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
1275 /* if we can't find the group, then we allow the operation */
1280 if (dwSize == 0 || dwSize2 == 0) {
1286 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
1287 pszRefDomain = (TCHAR *)malloc(dwSize2);
1289 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
1290 /* We can't lookup the group now even though we looked it up earlier.
1291 Could this happen? */
1294 /* Then open our current ProcessToken */
1297 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
1300 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
1301 /* We'll have to allocate a chunk of memory to store the list of
1302 * groups to which this user belongs; find out how much memory
1306 PTOKEN_GROUPS pGroups;
1308 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
1310 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
1312 /* Allocate that buffer, and read in the list of groups. */
1313 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
1315 /* Look through the list of group SIDs and see if any of them
1316 * matches the AFS Client Admin group SID.
1319 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
1321 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
1331 /* if do not have permission because we were not explicitly listed
1332 * in the Admin Client Group let's see if we are the SYSTEM account
1335 PTOKEN_USER pTokenUser;
1336 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
1337 PSID pSidLocalSystem = 0;
1340 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
1342 pTokenUser = (PTOKEN_USER)malloc(dwSize);
1344 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
1345 gle = GetLastError();
1347 if (AllocateAndInitializeSid( &SIDAuth, 1,
1348 SECURITY_LOCAL_SYSTEM_RID,
1349 0, 0, 0, 0, 0, 0, 0,
1352 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
1356 FreeSid(pSidLocalSystem);
1374 CString Parent(const CString& path)
1376 int last_slash = path.ReverseFind(_T('\\'));
1378 if (last_slash != -1) {
1379 CString ret = path.Left(last_slash + 1);
1382 if (path.GetLength() >= 2 && path[1] == _T(':')) {
1383 CString ret = path.Left(2);
1384 ret.AppendChar(_T('.'));
1387 CString ret = _T(".");
1393 CString LastComponent(const CString& path)
1395 int last_slash = path.ReverseFind(_T('\\'));
1397 if (last_slash != -1) {
1398 CString ret = path.Mid(last_slash + 1);
1401 if (path.GetLength() >= 2 && path[1] == _T(':')) {
1402 CString ret = path.Mid(2);
1412 GetCell(const CString & path)
1414 char cellname[MAXCELLCHARS];
1416 struct ViceIoctl blob;
1419 blob.out_size = sizeof(cellname);
1420 blob.out = cellname;
1422 code = pioctl_T(path, VIOC_FILE_CELL_NAME, &blob, 1);
1429 return Utf8ToCString(cellname);
1434 BOOL ListMount(CStringArray& files)
1437 struct ViceIoctl blob;
1440 CString parent_dir; /* Parent directory of true name */
1441 CStringUtf8 last_component; /* Last component of true name */
1443 CStringArray mountPoints;
1445 HOURGLASS hourglass;
1449 for (int i = 0; i < files.GetSize(); i++) {
1450 int last_slash = files[i].ReverseFind(_T('\\'));
1452 if (last_slash != -1) {
1453 last_component.SetString( files[i].Mid(last_slash + 1) );
1454 parent_dir.SetString( files[i].Left(last_slash + 1) );
1455 FixNetbiosPath(parent_dir);
1457 // The path is of the form "C:foo" or just "foo". If
1458 // there is a drive, then use the current directory of
1459 // that drive. Otherwise we just use '.'.
1461 if (files[i].GetLength() >= 2 && files[i][1] == _T(':')) {
1462 parent_dir.Format(_T("%c:."), files[i][0]);
1463 last_component.SetString( files[i].Mid(2) );
1465 parent_dir.SetString( _T("."));
1466 last_component.SetString( files[i] );
1470 blob.in_size = last_component.GetLength() + 1;
1471 blob.in = last_component.GetBuffer();
1472 blob.out_size = MAXSIZE;
1474 memset(space, 0, MAXSIZE);
1476 code = pioctl_T(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1478 last_component.ReleaseBuffer();
1482 space[MAXSIZE - 1] = '\0';
1483 nPos = strlen(space) - 1;
1484 if (space[nPos] == '.')
1486 mountPoints.Add(ParseMountPoint(StripPath(files[i]), Utf8ToCString(space)));
1489 if (errno == EINVAL)
1490 mountPoints.Add(GetMessageString(IDS_NOT_MOUNT_POINT_ERROR, StripPath(files[i])));
1492 mountPoints.Add(GetMessageString(IDS_LIST_MOUNT_POINT_ERROR, GetAfsError(errno, StripPath(files[i]))));
1496 CMountPointsDlg dlg;
1497 dlg.SetMountPoints(mountPoints);
1504 MakeMount(const CString& strDir,
1505 const CString& strVolName,
1506 const CString& strInCellName,
1510 struct ViceIoctl blob;
1511 HOURGLASS hourglass;
1513 ASSERT(strVolName.GetLength() < 64);
1515 CString strParent = Parent(strDir);
1517 FixNetbiosPath(strParent);
1518 if (!IsPathInAfs(strParent)) {
1519 ShowMessageBox(IDS_MAKE_MP_NOT_AFS_ERROR, MB_ICONERROR, IDS_MAKE_MP_NOT_AFS_ERROR);
1523 CString strPath = strParent + LastComponent(strDir);
1525 if ( IsFreelanceRoot(strParent) && !IsAdmin() ) {
1526 ShowMessageBox(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, MB_ICONERROR,
1527 IDS_NOT_AFS_CLIENT_ADMIN_ERROR);
1533 strMount.Format(_T("%c%s%s%s."),
1534 ((bRW)?_T('%'):_T('#')),
1536 ((strInCellName.IsEmpty())?_T(""):_T(":")),
1539 CStringUtf8 ustrMount(strMount);
1542 blob.in_size = ustrMount.GetLength() + 1;
1543 blob.in = ustrMount.GetBuffer();
1546 code = pioctl_T(strPath, VIOC_AFS_CREATE_MT_PT, &blob, 0);
1548 ustrMount.ReleaseBuffer();
1551 ShowMessageBox(IDS_MOUNT_POINT_ERROR, MB_ICONERROR, IDS_MOUNT_POINT_ERROR, GetAfsError(errno, strDir));
1560 long fs_ExtractDriveLetter(const char *inPathp, char *outPathp)
1562 if (inPathp[0] != 0 && inPathp[1] == ':') {
1563 /* there is a drive letter */
1564 *outPathp++ = *inPathp++;
1565 *outPathp++ = *inPathp++;
1573 /* strip the drive letter from a component */
1574 long fs_StripDriveLetter(const char *inPathp, char *outPathp, long outSize)
1576 char tempBuffer[1000];
1577 strcpy(tempBuffer, inPathp);
1578 if (tempBuffer[0] != 0 && tempBuffer[1] == ':') {
1579 /* drive letter present */
1580 strcpy(outPathp, tempBuffer+2);
1583 /* no drive letter present */
1584 strcpy(outPathp, tempBuffer);
1590 BOOL RemoveSymlink(const CString& strName)
1594 struct ViceIoctl blob;
1595 char lsbuffer[1024];
1597 HOURGLASS hourglass;
1599 CString strParent = Parent(strName);
1600 CStringUtf8 ustrLast(LastComponent(strName));
1601 FixNetbiosPath(strParent);
1603 if ( IsFreelanceRoot(strParent) && !IsAdmin() ) {
1604 ShowMessageBox(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, MB_ICONERROR, IDS_NOT_AFS_CLIENT_ADMIN_ERROR);
1608 blob.in_size = ustrLast.GetLength() + 1;
1609 blob.in = ustrLast.GetBuffer();
1610 blob.out = lsbuffer;
1611 blob.out_size = sizeof(lsbuffer);
1612 code = pioctl_T(strParent, VIOC_LISTSYMLINK, &blob, 0);
1613 ustrLast.ReleaseBuffer();
1617 blob.in_size = ustrLast.GetLength() + 1;
1618 blob.in = ustrLast.GetBuffer();
1620 code = pioctl_T(strParent, VIOC_DELSYMLINK, &blob, 0);
1622 ustrLast.ReleaseBuffer();
1627 BOOL IsSymlink(const CString& strName)
1629 struct ViceIoctl blob;
1632 HOURGLASS hourglass;
1634 CStringUtf8 ustrLast(LastComponent(strName));
1635 CString strParent = Parent(strName);
1637 FixNetbiosPath(strParent);
1639 blob.in_size = ustrLast.GetLength() + 1;
1640 blob.in = ustrLast.GetBuffer();
1641 blob.out_size = MAXSIZE;
1643 memset(space, 0, MAXSIZE);
1645 code = pioctl_T(strParent, VIOC_LISTSYMLINK, &blob, 1);
1647 ustrLast.ReleaseBuffer();
1653 BOOL IsMountPoint(const CString& path)
1656 struct ViceIoctl blob;
1657 char lsbuffer[1024];
1659 HOURGLASS hourglass;
1661 CString parent = Parent(path);
1662 FixNetbiosPath(parent);
1664 CStringUtf8 mountpoint(LastComponent(path));
1666 blob.in_size = mountpoint.GetLength() + 1;
1667 blob.in = mountpoint.GetBuffer();
1668 blob.out = lsbuffer;
1669 blob.out_size = sizeof(lsbuffer);
1671 code = pioctl_T(parent, VIOC_AFS_STAT_MT_PT, &blob, 0);
1673 mountpoint.ReleaseBuffer();
1680 * Delete AFS mount points. Variables are used as follows:
1681 * tbuffer: Set to point to the null-terminated directory name of the mount point
1682 * (or ``.'' if none is provided)
1683 * tp: Set to point to the actual name of the mount point to nuke.
1685 BOOL RemoveMount(CStringArray& files)
1688 struct ViceIoctl blob;
1690 CStringArray results;
1694 HOURGLASS hourglass;
1696 for (int i = 0; i < files.GetSize(); i++) {
1697 if (!IsMountPoint(files[i])) {
1699 if (errno == EINVAL)
1700 results.Add(GetMessageString(IDS_NOT_MOUNT_POINT_ERROR, StripPath(files[i])));
1702 results.Add(GetMessageString(IDS_ERROR, GetAfsError(errno, StripPath(files[i]))));
1703 continue; // don't bother trying
1706 CString parent = Parent(files[i]);
1707 CStringUtf8 mountpoint(LastComponent(files[i]));
1708 FixNetbiosPath(parent);
1710 if ( IsFreelanceRoot(parent) && !IsAdmin() ) {
1711 results.Add(GetMessageString(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, StripPath(files[i])));
1713 continue; /* skip */
1717 blob.in_size = mountpoint.GetLength() + 1;
1718 blob.in = mountpoint.GetBuffer();
1720 code = pioctl_T(parent, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1722 mountpoint.ReleaseBuffer();
1726 results.Add(GetMessageString(IDS_ERROR, GetAfsError(errno, StripPath(files[i]))));
1728 results.Add(GetMessageString(IDS_DELETED));
1731 LoadString (str, IDS_REMOVE_MP);
1732 LoadString (str2, IDS_REMOVE_MP_COLUMN);
1733 CResultsDlg dlg(REMOVE_MOUNT_POINTS_HELP_ID);
1734 dlg.SetContents(str, str2, StripPath(files), results);
1740 BOOL GetVolumeInfo(CString strFile, CVolInfo& volInfo)
1743 struct ViceIoctl blob;
1744 struct VolumeStatus *status;
1747 HOURGLASS hourglass;
1749 volInfo.m_strFilePath = strFile;
1750 volInfo.m_strFileName = StripPath(strFile);
1753 volInfo.m_strName = "VolumeName";
1755 volInfo.m_nQuota = 20 * 1024 * 1024;
1756 volInfo.m_nNewQuota = volInfo.m_nQuota;
1757 volInfo.m_nUsed = volInfo.m_nQuota / 2;
1758 volInfo.m_nPartSize = 50 * 1024 * 1024;
1759 volInfo.m_nPartFree = 30 * 1024 * 1024;
1760 volInfo.m_nDup = -1;
1764 blob.out_size = MAXSIZE;
1768 code = pioctl_T(strFile, VIOCGETVOLSTAT, &blob, 1);
1769 if (code || blob.out_size < sizeof(*status)) {
1770 volInfo.m_strErrorMsg = GetAfsError(errno, strFile);
1774 status = (VolumeStatus *)space;
1775 name = (char *)status + sizeof(*status);
1777 volInfo.m_strName = Utf8ToCString(name);
1778 volInfo.m_nID = status->Vid;
1779 volInfo.m_nQuota = status->MaxQuota;
1780 volInfo.m_nNewQuota = status->MaxQuota;
1781 volInfo.m_nUsed = status->BlocksInUse;
1782 volInfo.m_nPartSize = status->PartMaxBlocks;
1783 volInfo.m_nPartFree = status->PartBlocksAvail;
1784 volInfo.m_nDup = -1;
1789 BOOL SetVolInfo(CVolInfo& volInfo)
1792 struct ViceIoctl blob;
1793 struct VolumeStatus *status;
1796 HOURGLASS hourglass;
1798 blob.out_size = MAXSIZE;
1799 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1803 status = (VolumeStatus *)space;
1804 status->MinQuota = -1;
1805 status->MaxQuota = volInfo.m_nNewQuota;
1807 input = (char *)status + sizeof(*status);
1808 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1809 *(input++) = '\0'; // No offmsg
1810 *(input++) = '\0'; // No motd
1813 FILE *fp = OpenFile(szLogFileName, "a");
1815 fprintf(fp, "\nSetVolInfo() pioctl parms:\n");
1816 fprintf(fp, "\tpathp = %s\n\topcode = VIOCSETVOLSTAT (%d)\n\tblobp = %ld\n", PCCHAR(volInfo.m_strFilePath), VIOCSETVOLSTAT, &blob);
1817 fprintf(fp, "\t\tblobp.in = %ld (VolumeStatus *status)\n\t\tblobp.in_size = %ld\n\t\tblobp.out = %ld ((VolumeStatus *status))\n\t\tblobp.out_size = %ld\n", blob.in, blob.in_size, blob.out, blob.out_size);
1818 fprintf(fp, "\t\t\tstatus->MinQuota = %ld\n", status->MinQuota);
1819 fprintf(fp, "\t\t\tstatus->MaxQuota = %ld\n", status->MaxQuota);
1820 fprintf(fp, "\t\t\tOther status fields aren't set\n");
1821 fprintf(fp, "\t\t\t3 nulls follow the VolumeStatus structure.\n");
1822 fprintf(fp, "\tfollow = 1\n");
1827 code = pioctl_T(volInfo.m_strFilePath, VIOCSETVOLSTAT, &blob, 1);
1828 if (code || blob.out_size < sizeof(*status)) {
1829 ShowMessageBox(IDS_SET_QUOTA_ERROR, MB_ICONERROR, IDS_SET_QUOTA_ERROR, GetAfsError(errno, volInfo.m_strName));
1836 void GetCellName(const CString& cellNamep, struct afsconf_cell *infop)
1838 CStringUtf8 uCellName(cellNamep);
1840 StringCbCopyA(infop->name, sizeof(infop->name), uCellName);
1843 BOOL CheckServers(const CString& strCellName, WHICH_CELLS nCellsToCheck, BOOL bFast)
1846 struct ViceIoctl blob;
1849 struct afsconf_cell info;
1850 struct chservinfo checkserv;
1852 HOURGLASS hourglass;
1854 memset(&checkserv, 0, sizeof(struct chservinfo));
1855 blob.in_size = sizeof(struct chservinfo);
1856 blob.in = (caddr_t)&checkserv;
1858 blob.out_size = MAXSIZE;
1860 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1862 if (nCellsToCheck == SPECIFIC_CELL) {
1864 GetCellName(strCellName, &info);
1865 strcpy(checkserv.tbuffer,info.name);
1866 checkserv.tsize = strlen(info.name) + 1;
1868 if (nCellsToCheck != ALL_CELLS)
1870 strcpy(checkserv.tbuffer, "\0");
1871 checkserv.tsize = 0;
1874 temp |= 1; /* set fast flag */
1876 checkserv.magic = 0x12345678; /* XXX */
1877 checkserv.tflags = temp;
1878 checkserv.tinterval = -1; /* don't change current interval */
1880 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
1882 ShowMessageBox(IDS_CHECK_SERVERS_ERROR, MB_ICONERROR, IDS_CHECK_SERVERS_ERROR, GetAfsError(errno, CString()));
1886 memcpy(&temp, space, sizeof(LONG));
1889 ShowMessageBox(IDS_ALL_SERVERS_RUNNING, MB_OK|MB_ICONINFORMATION, IDS_ALL_SERVERS_RUNNING);
1893 CStringArray servers;
1894 for (j = 0; j < MAXHOSTS; j++) {
1895 memcpy(&temp, space + j * sizeof(LONG), sizeof(LONG));
1899 char *name = hostutil_GetNameByINet(temp);
1903 CDownServersDlg dlg;
1904 dlg.SetServerNames(servers);
1910 BOOL GetTokenInfo(CStringArray& tokenInfo)
1914 time_t current_time;
1915 time_t tokenExpireTime;
1919 struct ktc_principal serviceName, clientName;
1920 struct ktc_token token;
1922 CString strTokenInfo;
1923 CString strUserName;
1924 CString strCellName;
1927 // tokenInfo.Add("");
1931 HOURGLASS hourglass;
1933 // printf("\nTokens held by the Cache Manager:\n\n");
1935 current_time = time(0);
1938 rc = ktc_ListTokens(cellNum, &cellNum, &serviceName);
1939 if (rc == KTC_NOENT) {
1941 // printf(" --End of list --\n");
1944 else if (rc == KTC_NOCM) {
1945 ShowMessageBox(IDS_GET_TOKENS_NO_AFS_SERVICE);
1946 // printf("AFS service may not have started\n");
1950 ShowMessageBox(IDS_GET_TOKENS_UNEXPECTED_ERROR, MB_ICONERROR, IDS_GET_TOKENS_UNEXPECTED_ERROR, rc);
1952 // printf("Unexpected error, code %d\n", rc);
1956 rc = ktc_GetToken(&serviceName, &token, sizeof(token), &clientName);
1958 ShowMessageBox(IDS_GET_TOKENS_UNEXPECTED_ERROR2, MB_ICONERROR, IDS_GET_TOKENS_UNEXPECTED_ERROR2,
1959 serviceName.name, serviceName.instance, serviceName.cell, rc);
1963 tokenExpireTime = token.endTime;
1965 strcpy(userName, clientName.name);
1966 if (clientName.instance[0] != 0) {
1967 strcat(userName, ".");
1968 strcat(userName, clientName.instance);
1971 BOOL bShowName = FALSE;
1973 if (userName[0] == '\0')
1974 ; //printf("Tokens");
1975 // AFS ID is not returned at this time.
1976 // else if (strncmp(userName, "AFS ID", 6) == 0)
1977 // printf("User's (%s) tokens", userName);
1978 // sscanf(userName, "(AFS ID %s)", szAfsID);
1979 else if (strncmp(userName, "Unix UID", 8) == 0)
1980 ; //printf("Tokens");
1982 strUserName = userName;
1983 // printf("User %s's tokens", userName);
1985 // printf(" for %s%s%s@%s ", serviceName.name, serviceName.instance[0] ? "." : "", serviceName.instance, serviceName.cell);
1986 strCellName = serviceName.cell;
1988 if (tokenExpireTime <= current_time)
1989 strExpir = "[>> Expired <<]";
1990 // printf("[>> Expired <<]\n");
1992 expireString = ctime(&tokenExpireTime);
1993 expireString += 4; /* Skip day of week */
1994 expireString[12] = '\0'; /* Omit secs & year */
1995 // printf("[Expires %s]\n", expireString);
1997 strExpir.Format(_T("%S"), expireString);
1999 strExpir.Format(_T("%s"), expireString);
2003 strTokenInfo = strUserName + "\t" + strCellName + "\t" + strExpir + "\t" + strCellName;
2004 tokenInfo.Add(strTokenInfo);
2008 // printf("Press <Enter> or <Return> when finished: ");
2013 UINT MakeSymbolicLink(const CString& strName, const CString& strTarget)
2015 struct ViceIoctl blob;
2017 HOURGLASS hourglass;
2019 CString strParent = Parent(strName);
2020 FixNetbiosPath(strParent);
2022 if ( IsFreelanceRoot(strParent) && !IsAdmin() ) {
2023 ShowMessageBox(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, MB_ICONERROR, IDS_NOT_AFS_CLIENT_ADMIN_ERROR);
2027 CStringUtf8 ustrTarget(strTarget);
2029 blob.in_size = ustrTarget.GetLength() + 1;
2030 blob.in = ustrTarget.GetBuffer();
2034 code = pioctl_T(strName, VIOC_SYMLINK, &blob, 0);
2036 ustrTarget.ReleaseBuffer();
2043 void ListSymbolicLinkPath(const char *strName,char *strPath,UINT nlenPath)
2045 ASSERT(nlenPath<MAX_PATH);
2046 struct ViceIoctl blob;
2047 char orig_name[MAX_PATH+1]; /*Original name, may be modified*/
2048 char true_name[MAX_PATH+1]; /*``True'' dirname (e.g., symlink target)*/
2049 char parent_dir[MAX_PATH+1]; /*Parent directory of true name*/
2050 char *last_component; /*Last component of true name*/
2053 HOURGLASS hourglass;
2055 strcpy(orig_name, strName);
2056 strcpy(true_name, orig_name);
2058 * Find rightmost slash, if any.
2060 last_component = (char *) strrchr(true_name, '\\');
2061 if (!last_component)
2062 last_component = (char *) strrchr(true_name, '/');
2063 if (last_component) {
2065 * Found it. Designate everything before it as the parent directory,
2066 * everything after it as the final component.
2068 strncpy(parent_dir, true_name, last_component - true_name + 1);
2069 parent_dir[last_component - true_name + 1] = 0;
2070 last_component++; /*Skip the slash*/
2072 if (!IsPathInAfs(parent_dir)) {
2073 const char * nbname = NetbiosName();
2074 int len = strlen(nbname);
2076 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
2077 parent_dir[len+2] == '\\' &&
2078 parent_dir[len+3] == '\0' &&
2079 !strnicmp(nbname,&parent_dir[2],len))
2081 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
2087 * No slash appears in the given file name. Set parent_dir to the current
2088 * directory, and the last component as the given name.
2090 fs_ExtractDriveLetter(true_name, parent_dir);
2091 strcat(parent_dir, ".");
2092 last_component = true_name;
2093 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
2095 blob.in = last_component;
2096 blob.in_size = strlen(last_component)+1;
2097 blob.out_size = MAXSIZE;
2099 memset(space, 0, MAXSIZE);
2100 if ((code = pioctl(parent_dir, VIOC_LISTSYMLINK, &blob, 1)))
2101 strcpy(space,"???");
2102 ASSERT(strlen(space)<MAX_PATH);
2103 strncpy(strPath,space,nlenPath);
2106 BOOL ListSymlink(CStringArray& files)
2109 struct ViceIoctl blob;
2111 CStringArray symlinks;
2113 HOURGLASS hourglass;
2117 for (int i = 0; i < files.GetSize(); i++) {
2119 CString strParent = Parent(files[i]);
2120 CStringUtf8 ustrLast(LastComponent(files[i]));
2122 FixNetbiosPath(strParent);
2124 blob.in_size = ustrLast.GetLength() + 1;
2125 blob.in = ustrLast.GetBuffer();
2126 blob.out_size = MAXSIZE;
2128 memset(space, 0, MAXSIZE);
2130 code = pioctl_T(strParent, VIOC_LISTSYMLINK, &blob, 1);
2132 ustrLast.ReleaseBuffer();
2138 space[MAXSIZE - 1] = '\0';
2139 syml = Utf8ToCString(space);
2140 len = syml.GetLength();
2143 if (syml[len - 1] == _T('.'))
2144 syml.Truncate(len - 1);
2147 symlinks.Add(ParseSymlink(StripPath(files[i]), syml));
2151 if (errno == EINVAL)
2152 symlinks.Add(GetMessageString(IDS_NOT_SYMLINK_ERROR, StripPath(files[i])));
2154 symlinks.Add(GetMessageString(IDS_LIST_MOUNT_POINT_ERROR, GetAfsError(errno, StripPath(files[i]))));
2159 dlg.SetSymlinks(symlinks);