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/cellconfig.h>
37 #include <afs/vldbint.h>
38 #include <afs/volser.h>
40 #include <WINNT\afsreg.h>
44 #define STRSAFE_NO_DEPRECATE
47 #define PCCHAR(str) ((char *)(const char *)(str))
48 #define VL_NOENT (363524L)
54 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
55 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
57 #define MAXCELLCHARS 64
58 #define MAXHOSTCHARS 64
59 #define MAXHOSTSPERCELL 8
61 static char space[MAXSIZE];
62 static char tspace[1024];
64 static struct ubik_client *uclient;
65 static int rxInitDone = 0;
66 static char pn[] = "fs";
68 // #define LOGGING_ON // Enable this to log certain pioctl calls
71 static char *szLogFileName = "afsguilog.txt";
75 class CStringUtf8 : public CStringA
78 CStringUtf8(const CStringW& csw) : CStringA()
83 CStringUtf8(const char * cp) : CStringA(cp) {}
85 CStringUtf8() :CStringA() {}
87 void SetString(const CStringW& csw)
92 rv = WideCharToMultiByte(CP_UTF8, 0, csw, -1,
93 buffer, sizeof(buffer),
97 CStringA::SetString(buffer);
99 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
102 cb_req = WideCharToMultiByte(CP_UTF8, 0, csw, -1, NULL, 0, NULL, FALSE);
106 WideCharToMultiByte(CP_UTF8, 0, csw, -1, CStringA::GetBuffer(cb_req), cb_req, NULL, FALSE);
107 CStringA::ReleaseBuffer();
117 static CString _Utf8ToCString(const char * ustr)
122 cch = MultiByteToWideChar(CP_UTF8, 0, ustr, -1, NULL, 0);
129 cch = MultiByteToWideChar(CP_UTF8, 0, ustr, -1, cs.GetBuffer(cch), cch);
136 long pioctl_T(const CString& path, long opcode, struct ViceIoctl * blob, int follow)
138 CStringUtf8 upath(path);
140 return pioctl_utf8(PCCHAR(upath), opcode, blob, follow);
143 #define Utf8ToCString(cs) CStringUtf8::_Utf8ToCString(cs)
145 #define pioctl_T(path, op, vblob, follow) pioctl(PCCHAR(path), op, vblob, follow)
146 #define Utf8ToCString(cs) (cs)
152 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
156 code = ugen_ClientInit(noAuthFlag, (char *)AFSDIR_CLIENT_ETC_DIRPATH,
157 info->name, 0, &uclient,
158 NULL, pn, rxkad_clear,
159 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
160 0, 0, USER_SERVICE_ID);
166 OpenFile(char *file, char *rwp)
173 code = GetWindowsDirectoryA(wdir, sizeof(wdir));
174 if (code == 0 || code > sizeof(wdir))
177 /* add trailing backslash, if required */
179 if (wdir[tlen - 1] != '\\')
184 fp = fopen(wdir, rwp);
189 CString StripPath(CString& strPath)
191 int nIndex = strPath.ReverseFind('\\');
193 CString strFile = strPath.Mid(nIndex + 1);
194 if (strFile.IsEmpty())
200 CStringArray& StripPath(CStringArray& files)
202 for (int i = 0; i < files.GetSize(); i++)
203 files[i] = StripPath(files[i]);
208 void Flush(const CStringArray& files)
211 struct ViceIoctl blob;
216 for (int i = 0; i < files.GetSize(); i++) {
217 blob.in_size = blob.out_size = 0;
219 code = pioctl_T(files[i], VIOCFLUSH, &blob, 0);
223 ShowMessageBox(IDS_FLUSH_FAILED, MB_ICONERROR, IDS_FLUSH_FAILED, files[i]);
225 ShowMessageBox(IDS_FLUSH_ERROR, MB_ICONERROR, IDS_FLUSH_ERROR, files[i], strerror(errno));
230 ShowMessageBox(IDS_FLUSH_OK, MB_ICONINFORMATION, IDS_FLUSH_OK);
233 void FlushVolume(const CStringArray& files)
236 struct ViceIoctl blob;
241 for (int i = 0; i < files.GetSize(); i++) {
242 blob.in_size = blob.out_size = 0;
244 code = pioctl_T(files[i], VIOC_FLUSHVOLUME, &blob, 0);
247 ShowMessageBox(IDS_FLUSH_VOLUME_ERROR, MB_ICONERROR, IDS_FLUSH_VOLUME_ERROR, files[i], strerror(errno));
252 ShowMessageBox(IDS_FLUSH_VOLUME_OK, MB_ICONINFORMATION, IDS_FLUSH_VOLUME_OK);
255 void WhichCell(CStringArray& files)
258 struct ViceIoctl blob;
263 CStringArray results;
269 for (int i = 0; i < files.GetSize(); i++) {
271 blob.out_size = MAXSIZE;
274 code = pioctl_T(files[i], VIOC_FILE_CELL_NAME, &blob, 1);
276 if (code == ENOENT) {
277 LoadString (str, IDS_CANT_GET_CELL);
280 results.Add(GetAfsError(errno));
282 results.Add(Utf8ToCString(space));
286 LoadString (str, IDS_SHOW_CELL);
287 LoadString (str2, IDS_SHOW_CELL_COLUMN);
288 CResultsDlg dlg(SHOW_CELL_HELP_ID);
289 dlg.SetContents(str, str2, StripPath(files), results);
296 struct ViceIoctl blob;
301 blob.in = (char *) 0;
302 blob.out_size = MAXSIZE;
305 code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1);
308 //Die(errno, (char *) 0);
311 //printf("This workstation belongs to cell '%s'\n", space);
317 struct ViceIoctl blob;
321 code = pioctl(0, VIOCCKBACK, &blob, 1);
323 ShowMessageBox(IDS_CHECK_VOLUMES_ERROR, MB_ICONERROR, IDS_CHECK_VOLUMES_ERROR, GetAfsError(errno, CString()));
327 ShowMessageBox(IDS_CHECK_VOLUMES_OK, MB_OK|MB_ICONINFORMATION, IDS_CHECK_VOLUMES_OK);
332 void SetCacheSizeCmd(LONG nNewCacheSize)
335 struct ViceIoctl blob;
339 blob.in = (char *) &nNewCacheSize;
340 blob.in_size = sizeof(LONG);
343 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
345 // Die(errno, (char *) 0);
347 // printf("New cache size set.\n");
350 void WhereIs(CStringArray& files)
353 struct ViceIoctl blob;
354 CStringArray servers;
355 CStringArray resultFiles;
361 for (int i = 0; i < files.GetSize(); i++) {
362 blob.out_size = MAXSIZE;
365 memset(space, 0, sizeof(space));
367 code = pioctl_T(files[i], VIOCWHEREIS, &blob, 1);
369 resultFiles.Add(StripPath(files[i]));
370 servers.Add(GetAfsError(errno));
374 LONG *hosts = (LONG *)space;
378 for (int j = 0; j < MAXHOSTS; j++) {
381 char *hostName = hostutil_GetNameByINet(hosts[j]);
383 resultFiles.Add(StripPath(files[i]));
386 resultFiles.Add(" ");
387 servers.Add(hostName);
391 LoadString (str, IDS_SHOW_FS);
392 LoadString (str2, IDS_SHOW_FS_COLUMN);
393 CResultsDlg dlg(SHOW_FILE_SERVERS_HELP_ID);
394 dlg.SetContents(str, str2, resultFiles, servers);
399 CMtoUNIXerror(int cm_code)
402 case CM_ERROR_TIMEDOUT:
404 case CM_ERROR_NOACCESS:
406 case CM_ERROR_NOSUCHFILE:
412 case CM_ERROR_EXISTS:
414 case CM_ERROR_CROSSDEVLINK:
416 case CM_ERROR_NOTDIR:
420 case CM_ERROR_READONLY:
422 case CM_ERROR_WOULDBLOCK:
424 case CM_ERROR_NOSUCHCELL:
425 return ESRCH; /* hack */
426 case CM_ERROR_NOSUCHVOLUME:
427 return EPIPE; /* hack */
428 case CM_ERROR_NOMORETOKENS:
429 return EDOM; /* hack */
430 case CM_ERROR_TOOMANYBUFS:
431 return EFBIG; /* hack */
433 if (cm_code > 0 && cm_code < EILSEQ)
440 CString GetAfsError(int code, const TCHAR *filename)
444 code = CMtoUNIXerror(code);
446 if (code == EINVAL) {
448 strMsg.Format(_T("Invalid argument; it is possible that the file is not in AFS"));
450 strMsg.Format(_T("Invalid argument"));
451 } else if (code == ENOENT) {
453 strMsg.Format(_T("The file does not exist"));
455 strMsg.Format(_T("No such file returned"));
456 } else if (code == EROFS) {
457 strMsg.Format(_T("You can not change a backup or readonly volume"));
458 } else if (code == EACCES || code == EPERM) {
459 strMsg.Format(_T("You do not have the required rights to do this operation"));
460 } else if (code == ENODEV) {
461 strMsg.Format(_T("AFS service may not have started"));
462 } else if (code == ESRCH) {
463 strMsg.Format(_T("Cell name not recognized"));
464 } else if (code == ETIMEDOUT) {
465 strMsg.Format(_T("Connection timed out"));
466 } else if (code == EPIPE) {
467 strMsg.Format(_T("Volume name or ID not recognized"));
469 strMsg.Format(_T("Error 0x%x occurred"), code);
476 /************************************************************************
477 ************************** ACL Code *************************************
478 ************************************************************************/
480 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
483 struct AclEntry *next;
489 int dfs; // Originally true if a dfs acl; now also the type
490 // of the acl (1, 2, or 3, corresponding to object,
491 // initial dir, or initial object).
492 sec_rgy_name_t cell; // DFS cell name
495 struct AclEntry *pluslist;
496 struct AclEntry *minuslist;
499 int foldcmp (register char *a, register char *b)
505 if (t >= 'A' && t <= 'Z') t += 0x20;
506 if (u >= 'A' && u <= 'Z') u += 0x20;
507 if (t != u) return 1;
508 if (t == 0) return 0;
512 extern "C" void ZapList(struct AclEntry *alist)
514 register struct AclEntry *tp, *np;
516 for (tp = alist; tp; tp = np) {
522 extern "C" void ZapAcl (struct Acl *acl)
524 ZapList(acl->pluslist);
525 ZapList(acl->minuslist);
529 extern "C" int PruneList (struct AclEntry **ae, int dfs)
531 struct AclEntry **lp = ae;
532 struct AclEntry *te, *ne;
535 for (te = *ae; te; te = ne) {
536 if ((!dfs && te->rights == 0) || te->rights == -1) {
551 char *SkipLine (register char *astr)
553 while (*astr != '\n')
561 /* tell if a name is 23 or -45 (digits or minus digits), which are bad names we must prune */
562 static int BadName(register char *aname)
566 /* all must be '-' or digit to be bad */
567 while (tc = *aname++) {
568 if ((tc != '-') && (tc < '0' || tc > '9'))
575 CString GetRightsString(register LONG arights, int dfs)
580 if (arights & PRSFS_READ) str += _T("r");
581 if (arights & PRSFS_LOOKUP) str += _T("l");
582 if (arights & PRSFS_INSERT) str += _T("i");
583 if (arights & PRSFS_DELETE) str += _T("d");
584 if (arights & PRSFS_WRITE) str += _T("w");
585 if (arights & PRSFS_LOCK) str += _T("k");
586 if (arights & PRSFS_ADMINISTER) str += _T("a");
590 if (arights & DFS_READ) str += _T("r"); else str += _T("-");
591 if (arights & DFS_WRITE) str += _T("w"); else printf(_T("-"));
592 if (arights & DFS_EXECUTE) str += _T("x"); else printf(_T("-"));
593 if (arights & DFS_CONTROL) str += _T("c"); else printf(_T("-"));
594 if (arights & DFS_INSERT) str += _T("i"); else printf(_T("-"));
595 if (arights & DFS_DELETE) str += _T("d"); else printf(_T("-"));
596 if (arights & (DFS_USRALL)) str += _T("+");
603 char *AclToString(struct Acl *acl)
605 static char mydata[MAXSIZE];
606 char tstring[MAXSIZE];
611 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
614 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
616 for(tp = acl->pluslist; tp; tp = tp->next) {
617 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
618 strcat(mydata, tstring);
621 for(tp = acl->minuslist; tp; tp = tp->next) {
622 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
623 strcat(mydata, tstring);
629 struct Acl *EmptyAcl(const CString& strCellName)
631 register struct Acl *tp;
632 CStringUtf8 ustrCell(strCellName);
634 tp = (struct Acl *)malloc(sizeof (struct Acl));
635 tp->nplus = tp->nminus = 0;
636 tp->pluslist = tp->minuslist = 0;
638 StringCbCopyA(tp->cell, sizeof(tp->cell), ustrCell);
643 struct Acl *EmptyAcl(char *astr)
645 register struct Acl *tp;
648 tp = (struct Acl *)malloc(sizeof (struct Acl));
649 tp->nplus = tp->nminus = 0;
650 tp->pluslist = tp->minuslist = 0;
652 if (astr == NULL || sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell) <= 0) {
660 ParseAcl (char *astr)
662 int nplus, nminus, i, trights, ret;
664 struct AclEntry *first, *next, *last, *tl;
668 if (astr == NULL || strlen(astr) == 0)
671 ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
676 astr = SkipLine(astr);
677 ret = sscanf(astr, "%d", &ta->nminus);
682 astr = SkipLine(astr);
689 for(i=0;i<nplus;i++) {
690 ret = sscanf(astr, "%100s %d", tname, &trights);
693 astr = SkipLine(astr);
694 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
699 strcpy(tl->name, tname);
700 tl->rights = trights;
706 ta->pluslist = first;
710 for(i=0;i<nminus;i++) {
711 ret = sscanf(astr, "%100s %d", tname, &trights);
714 astr = SkipLine(astr);
715 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
720 strcpy(tl->name, tname);
721 tl->rights = trights;
727 ta->minuslist = first;
732 for (;first; first = next) {
736 first = ta->pluslist;
739 for (;first; first = next) {
747 /* clean up an access control list of its bad entries; return 1 if we made
748 any changes to the list, and 0 otherwise */
749 extern "C" int CleanAcl(struct Acl *aa)
751 register struct AclEntry *te, **le, *ne;
756 /* Don't correct DFS ACL's for now */
760 /* prune out bad entries */
761 changes = 0; /* count deleted entries */
763 for(te = aa->pluslist; te; te = ne) {
765 if (BadName(te->name)) {
778 for(te = aa->minuslist; te; te = ne) {
780 if (BadName(te->name)) {
794 void CleanACL(CStringArray& names)
797 register struct Acl *ta;
798 struct ViceIoctl blob;
801 ShowMessageBox(IDS_CLEANACL_MSG, MB_OK|MB_ICONINFORMATION, IDS_CLEANACL_MSG);
805 for (int i = 0; i < names.GetSize(); i++) {
806 blob.out_size = MAXSIZE;
810 code = pioctl_T(names[i], VIOCGETAL, &blob, 1);
812 ShowMessageBox(IDS_CLEANACL_ERROR, MB_ICONERROR, 0, names[i], GetAfsError(errno));
816 ta = ParseAcl(space);
818 ShowMessageBox(IDS_INVALID_ACL_DATA, MB_ICONERROR, IDS_INVALID_ACL_DATA);
822 ShowMessageBox(IDS_CLEANACL_NOT_SUPPORTED, MB_ICONERROR, IDS_CLEANACL_NOT_SUPPORTED, names[i]);
826 changes = CleanAcl(ta);
830 /* now set the acl */
831 blob.in = AclToString(ta);
832 blob.in_size = strlen((char *)blob.in) + 1;
835 code = pioctl_T(names[i], VIOCSETAL, &blob, 1);
837 if (errno == EINVAL) {
838 ShowMessageBox(IDS_CLEANACL_INVALID_ARG, MB_ICONERROR, IDS_CLEANACL_INVALID_ARG, names[i]);
842 ShowMessageBox(IDS_CLEANACL_ERROR, MB_ICONERROR, 0, names[i], GetAfsError(errno));
849 // Derived from fs.c's ListAclCmd
850 BOOL GetRights(const CString& strDir, CStringArray& strNormal, CStringArray& strNegative)
853 register struct Acl *ta;
854 struct ViceIoctl blob;
856 int idf = 0; //getidf(as, parm_listacl_id);
860 blob.out_size = MAXSIZE;
862 blob.in = blob.out = space;
864 code = pioctl_T(strDir, VIOCGETAL, &blob, 1);
866 ShowMessageBox(IDS_GETRIGHTS_ERROR, MB_ICONERROR, IDS_GETRIGHTS_ERROR, strDir, GetAfsError(errno));
870 ta = ParseAcl(space);
872 ShowMessageBox(IDS_INVALID_ACL_DATA, MB_ICONERROR, IDS_INVALID_ACL_DATA);
876 ShowMessageBox(IDS_DFSACL_ERROR, MB_ICONERROR, IDS_DFSACL_ERROR);
881 // printf(" Default cell = %s\n", ta->cell);
886 for (te = ta->pluslist; te; te = te->next) {
887 strNormal.Add(te->name);
888 strNormal.Add(GetRightsString(te->rights, ta->dfs));
892 if (ta->nminus > 0) {
893 for (te = ta->minuslist; te; te = te->next) {
894 strNegative.Add(te->name);
895 strNegative.Add(GetRightsString(te->rights, ta->dfs));
902 struct AclEntry *FindList(register struct AclEntry *pCurEntry, const char *entryName)
905 if (!foldcmp(pCurEntry->name, PCCHAR(entryName)))
907 pCurEntry = pCurEntry->next;
913 void ChangeList(struct Acl *pAcl, BYTE bNormalRights, const CString & entryName, LONG nEntryRights)
918 struct AclEntry *pEntry;
919 CStringUtf8 uEntryName(entryName);
923 pEntry = (bNormalRights ? pAcl->pluslist : pAcl->minuslist);
924 pEntry = FindList(pEntry, uEntryName);
926 /* Found the item already in the list. */
928 pEntry->rights = nEntryRights;
930 pAcl->nplus -= PruneList(&pAcl->pluslist, pAcl->dfs);
932 pAcl->nminus -= PruneList(&pAcl->minuslist, pAcl->dfs);
936 /* Otherwise we make a new item and plug in the new data. */
937 pEntry = (struct AclEntry *) malloc(sizeof (struct AclEntry));
940 strcpy(pEntry->name, uEntryName);
941 pEntry->rights = nEntryRights;
944 pEntry->next = pAcl->pluslist;
945 pAcl->pluslist = pEntry;
947 if (nEntryRights == 0 || nEntryRights == -1)
948 pAcl->nplus -= PruneList(&pAcl->pluslist, pAcl->dfs);
951 pEntry->next = pAcl->minuslist;
952 pAcl->minuslist = pEntry;
954 if (nEntryRights == 0)
955 pAcl->nminus -= PruneList(&pAcl->minuslist, pAcl->dfs);
959 enum rtype {add, destroy, deny};
961 static LONG Convert(const CString& strRights, int dfs, enum rtype *rtypep)
966 *rtypep = add; /* add rights, by default */
968 if (strRights == _T("read"))
969 return PRSFS_READ | PRSFS_LOOKUP;
970 if (strRights == _T("write"))
971 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK;
972 if (strRights == _T("mail"))
973 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
974 if (strRights == _T("all"))
975 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
977 if (strRights == _T("none")) {
978 *rtypep = destroy; /* Remove entire entry */
982 len = strRights.GetLength();
985 for (i = 0; i < len; i++) {
986 TCHAR c = strRights[i];
987 if (c == _T('r')) mode |= PRSFS_READ;
988 else if (c == _T('l')) mode |= PRSFS_LOOKUP;
989 else if (c == _T('i')) mode |= PRSFS_INSERT;
990 else if (c == _T('d')) mode |= PRSFS_DELETE;
991 else if (c == _T('w')) mode |= PRSFS_WRITE;
992 else if (c == _T('k')) mode |= PRSFS_LOCK;
993 else if (c == _T('a')) mode |= PRSFS_ADMINISTER;
995 fprintf(stderr, "illegal rights character '%c'.\n", c);
1002 BOOL SaveACL(const CString& strCellName, const CString& strDir, const CStringArray& normal, const CStringArray& negative)
1005 struct ViceIoctl blob;
1010 HOURGLASS hourglass;
1013 pAcl = EmptyAcl(strCellName);
1015 // Set its normal rights
1017 for (i = 0; i < normal.GetSize(); i += 2) {
1018 rights = Convert(normal[i + 1], 0, &rtype);
1019 ChangeList(pAcl, TRUE, normal[i], rights);
1022 // Set its negative rights
1023 for (i = 0; i < negative.GetSize(); i += 2) {
1024 rights = Convert(negative[i + 1], 0, &rtype);
1025 ChangeList(pAcl, FALSE, negative[i], rights);
1029 blob.in = AclToString(pAcl);
1031 blob.in_size = 1 + strlen((const char *)blob.in);
1033 code = pioctl_T(strDir, VIOCSETAL, &blob, 1);
1035 if (errno == EINVAL)
1036 ShowMessageBox(IDS_SAVE_ACL_EINVAL_ERROR, MB_ICONERROR, IDS_SAVE_ACL_EINVAL_ERROR, strDir);
1038 ShowMessageBox(IDS_SAVE_ACL_ERROR, MB_ICONERROR, IDS_SAVE_ACL_ERROR, strDir, GetAfsError(errno, strDir));
1046 BOOL CopyACL(const CString& strToDir, const CStringArray& normal, const CStringArray& negative, BOOL bClear)
1049 struct ViceIoctl blob;
1051 int idf = 0; // getidf(as, parm_copyacl_id);
1053 HOURGLASS hourglass;
1055 // Get ACL to copy to
1056 blob.out_size = MAXSIZE;
1058 blob.in = blob.out = space;
1060 code = pioctl_T(strToDir, VIOCGETAL, &blob, 1);
1062 ShowMessageBox(IDS_ACL_READ_ERROR, MB_ICONERROR, IDS_ACL_READ_ERROR, strToDir, GetAfsError(errno, strToDir));
1067 pToAcl = EmptyAcl(space);
1069 pToAcl = ParseAcl(space);
1071 if (pToAcl == NULL) {
1072 ShowMessageBox(IDS_INVALID_ACL_DATA, MB_ICONERROR, IDS_INVALID_ACL_DATA);
1079 ShowMessageBox(IDS_NO_DFS_COPY_ACL, MB_ICONERROR, IDS_NO_DFS_COPY_ACL, strToDir);
1086 // Set normal rights
1088 for (i = 0; i < normal.GetSize(); i += 2) {
1089 LONG rights = Convert(normal[i + 1], 0, &rtype);
1090 ChangeList(pToAcl, TRUE, normal[i], rights);
1093 // Set negative rights
1094 for (i = 0; i < negative.GetSize(); i += 2) {
1095 LONG rights = Convert(negative[i + 1], 0, &rtype);
1096 ChangeList(pToAcl, FALSE, normal[i], rights);
1099 // Save modified ACL
1100 blob.in = AclToString(pToAcl);
1102 blob.in_size = 1 + strlen((char *)blob.in);
1104 code = pioctl_T(strToDir, VIOCSETAL, &blob, 1);
1107 if (errno == EINVAL)
1108 ShowMessageBox(IDS_COPY_ACL_EINVAL_ERROR, MB_ICONERROR, IDS_COPY_ACL_EINVAL_ERROR, strToDir);
1110 ShowMessageBox(IDS_COPY_ACL_ERROR, MB_ICONERROR, IDS_COPY_ACL_ERROR, strToDir, GetAfsError(errno, strToDir));
1116 ShowMessageBox(IDS_COPY_ACL_OK, MB_OK|MB_ICONINFORMATION, IDS_COPY_ACL_OK);
1121 CString ParseMountPoint(const CString strFile, CString strMountPoint)
1126 CString strMountPointInfo;
1128 if (strMountPoint[0] == '#')
1129 strType = "Regular";
1130 else if (strMountPoint[0] == '%')
1131 strType = "Read/Write";
1133 int nColon = strMountPoint.Find(':');
1135 strCell = strMountPoint.Mid(1, nColon - 1);
1136 strVolume = strMountPoint.Mid(nColon + 1);
1138 strVolume = strMountPoint.Mid(1);
1140 strMountPointInfo = strFile + _T("\t") + strVolume + _T("\t") + strCell + _T("\t") + strType;
1142 return strMountPointInfo;
1145 CString ParseSymlink(const CString strFile, CString strSymlink)
1147 CString strSymlinkInfo;
1149 strSymlinkInfo = strFile + _T("\t") + strSymlink;
1151 return strSymlinkInfo;
1154 BOOL IsPathInAfs(const CString & strPath)
1156 struct ViceIoctl blob;
1159 HOURGLASS hourglass;
1163 debugBuf.Format(_T("IsPathInAfs(%s)"), strPath);
1164 OutputDebugString(debugBuf);
1167 blob.out_size = MAXSIZE;
1170 code = pioctl_T(strPath, VIOC_FILE_CELL_NAME, &blob, 1);
1172 debugBuf.Format(_T("VIOC_FILE_CELL_NAME=%d"), code);
1173 OutputDebugString(debugBuf);
1176 if ((errno == EINVAL) || (errno == ENOENT))
1183 IsFreelanceRoot(const CString& apath)
1185 struct ViceIoctl blob;
1189 blob.out_size = MAXSIZE;
1192 code = pioctl_T(apath, VIOC_FILE_CELL_NAME, &blob, 1);
1194 return !strcmp("Freelance.Local.Root",space);
1195 return 1; /* assume it is because it is more restrictive that way */
1198 static const char * NetbiosName(void)
1200 static char buffer[1024] = "AFS";
1206 code = RegOpenKeyExA(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
1207 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
1208 if (code == ERROR_SUCCESS) {
1209 dummyLen = sizeof(buffer);
1210 code = RegQueryValueExA(parmKey, "NetbiosName", NULL, NULL,
1211 (LPBYTE)buffer, &dummyLen);
1212 RegCloseKey (parmKey);
1214 strcpy(buffer, "AFS");
1219 static void FixNetbiosPath(CString& path)
1221 if (!IsPathInAfs(path)) {
1223 const char * nbname = NetbiosName();
1226 nbroot.Format(_T("\\\\%S\\"), nbname);
1228 nbroot.Format(_T("\\\\%s\\"), nbname);
1231 if (nbroot.CompareNoCase(path) == 0) {
1232 path.Append(_T("all\\"));
1237 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
1239 static BOOL IsAdmin (void)
1241 static BOOL fAdmin = FALSE;
1242 static BOOL fTested = FALSE;
1246 /* Obtain the SID for the AFS client admin group. If the group does
1247 * not exist, then assume we have AFS client admin privileges.
1249 PSID psidAdmin = NULL;
1250 DWORD dwSize, dwSize2;
1251 TCHAR pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
1252 TCHAR *pszRefDomain = NULL;
1253 SID_NAME_USE snu = SidTypeGroup;
1255 dwSize = sizeof(pszAdminGroup);
1257 if (!GetComputerName(pszAdminGroup, &dwSize)) {
1258 /* Can't get computer name. We return false in this case.
1259 Retain fAdmin and fTested. This shouldn't happen.*/
1266 lstrcat(pszAdminGroup, _T("\\"));
1267 lstrcat(pszAdminGroup, _T(AFSCLIENT_ADMIN_GROUPNAME));
1269 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
1270 /* that should always fail. */
1272 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
1273 /* if we can't find the group, then we allow the operation */
1278 if (dwSize == 0 || dwSize2 == 0) {
1284 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
1285 pszRefDomain = (TCHAR *)malloc(dwSize2);
1287 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
1288 /* We can't lookup the group now even though we looked it up earlier.
1289 Could this happen? */
1292 /* Then open our current ProcessToken */
1295 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
1298 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
1299 /* We'll have to allocate a chunk of memory to store the list of
1300 * groups to which this user belongs; find out how much memory
1304 PTOKEN_GROUPS pGroups;
1306 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
1308 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
1310 /* Allocate that buffer, and read in the list of groups. */
1311 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
1313 /* Look through the list of group SIDs and see if any of them
1314 * matches the AFS Client Admin group SID.
1317 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
1319 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
1329 /* if do not have permission because we were not explicitly listed
1330 * in the Admin Client Group let's see if we are the SYSTEM account
1333 PTOKEN_USER pTokenUser;
1334 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
1335 PSID pSidLocalSystem = 0;
1338 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
1340 pTokenUser = (PTOKEN_USER)malloc(dwSize);
1342 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
1343 gle = GetLastError();
1345 if (AllocateAndInitializeSid( &SIDAuth, 1,
1346 SECURITY_LOCAL_SYSTEM_RID,
1347 0, 0, 0, 0, 0, 0, 0,
1350 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
1354 FreeSid(pSidLocalSystem);
1372 CString Parent(const CString& path)
1374 int last_slash = path.ReverseFind(_T('\\'));
1376 if (last_slash != -1) {
1377 CString ret = path.Left(last_slash + 1);
1380 if (path.GetLength() >= 2 && path[1] == _T(':')) {
1381 CString ret = path.Left(2);
1382 ret.AppendChar(_T('.'));
1385 CString ret = _T(".");
1391 CString LastComponent(const CString& path)
1393 int last_slash = path.ReverseFind(_T('\\'));
1395 if (last_slash != -1) {
1396 CString ret = path.Mid(last_slash + 1);
1399 if (path.GetLength() >= 2 && path[1] == _T(':')) {
1400 CString ret = path.Mid(2);
1410 GetCell(const CString & path)
1412 char cellname[MAXCELLCHARS];
1414 struct ViceIoctl blob;
1417 blob.out_size = sizeof(cellname);
1418 blob.out = cellname;
1420 code = pioctl_T(path, VIOC_FILE_CELL_NAME, &blob, 1);
1427 return Utf8ToCString(cellname);
1432 BOOL ListMount(CStringArray& files)
1435 struct ViceIoctl blob;
1438 CString parent_dir; /* Parent directory of true name */
1439 CStringUtf8 last_component; /* Last component of true name */
1441 CStringArray mountPoints;
1443 HOURGLASS hourglass;
1447 for (int i = 0; i < files.GetSize(); i++) {
1448 int last_slash = files[i].ReverseFind(_T('\\'));
1450 if (last_slash != -1) {
1451 last_component.SetString( files[i].Mid(last_slash + 1) );
1452 parent_dir.SetString( files[i].Left(last_slash + 1) );
1453 FixNetbiosPath(parent_dir);
1455 // The path is of the form "C:foo" or just "foo". If
1456 // there is a drive, then use the current directory of
1457 // that drive. Otherwise we just use '.'.
1459 if (files[i].GetLength() >= 2 && files[i][1] == _T(':')) {
1460 parent_dir.Format(_T("%c:."), files[i][0]);
1461 last_component.SetString( files[i].Mid(2) );
1463 parent_dir.SetString( _T("."));
1464 last_component.SetString( files[i] );
1468 blob.in_size = last_component.GetLength() + 1;
1469 blob.in = last_component.GetBuffer();
1470 blob.out_size = MAXSIZE;
1472 memset(space, 0, MAXSIZE);
1474 code = pioctl_T(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1476 last_component.ReleaseBuffer();
1479 int nPos = strlen(space) - 1;
1480 if (space[nPos] == '.')
1482 mountPoints.Add(ParseMountPoint(StripPath(files[i]), Utf8ToCString(space)));
1485 if (errno == EINVAL)
1486 mountPoints.Add(GetMessageString(IDS_NOT_MOUNT_POINT_ERROR, StripPath(files[i])));
1488 mountPoints.Add(GetMessageString(IDS_LIST_MOUNT_POINT_ERROR, GetAfsError(errno, StripPath(files[i]))));
1492 CMountPointsDlg dlg;
1493 dlg.SetMountPoints(mountPoints);
1500 MakeMount(const CString& strDir,
1501 const CString& strVolName,
1502 const CString& strInCellName,
1506 struct ViceIoctl blob;
1507 HOURGLASS hourglass;
1509 ASSERT(strVolName.GetLength() < 64);
1511 CString strParent = Parent(strDir);
1513 FixNetbiosPath(strParent);
1514 if (!IsPathInAfs(strParent)) {
1515 ShowMessageBox(IDS_MAKE_MP_NOT_AFS_ERROR, MB_ICONERROR, IDS_MAKE_MP_NOT_AFS_ERROR);
1519 CString strPath = strParent + LastComponent(strDir);
1521 if ( IsFreelanceRoot(strParent) && !IsAdmin() ) {
1522 ShowMessageBox(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, MB_ICONERROR,
1523 IDS_NOT_AFS_CLIENT_ADMIN_ERROR);
1529 strMount.Format(_T("%c%s%s%s."),
1530 ((bRW)?_T('%'):_T('#')),
1532 ((strInCellName.IsEmpty())?_T(""):_T(":")),
1535 CStringUtf8 ustrMount(strMount);
1538 blob.in_size = ustrMount.GetLength() + 1;
1539 blob.in = ustrMount.GetBuffer();
1542 code = pioctl_T(strPath, VIOC_AFS_CREATE_MT_PT, &blob, 0);
1544 ustrMount.ReleaseBuffer();
1547 ShowMessageBox(IDS_MOUNT_POINT_ERROR, MB_ICONERROR, IDS_MOUNT_POINT_ERROR, GetAfsError(errno, strDir));
1556 long fs_ExtractDriveLetter(const char *inPathp, char *outPathp)
1558 if (inPathp[0] != 0 && inPathp[1] == ':') {
1559 /* there is a drive letter */
1560 *outPathp++ = *inPathp++;
1561 *outPathp++ = *inPathp++;
1569 /* strip the drive letter from a component */
1570 long fs_StripDriveLetter(const char *inPathp, char *outPathp, long outSize)
1572 char tempBuffer[1000];
1573 strcpy(tempBuffer, inPathp);
1574 if (tempBuffer[0] != 0 && tempBuffer[1] == ':') {
1575 /* drive letter present */
1576 strcpy(outPathp, tempBuffer+2);
1579 /* no drive letter present */
1580 strcpy(outPathp, tempBuffer);
1586 BOOL RemoveSymlink(const CString& strName)
1590 struct ViceIoctl blob;
1591 char lsbuffer[1024];
1593 HOURGLASS hourglass;
1595 CString strParent = Parent(strName);
1596 CStringUtf8 ustrLast(LastComponent(strName));
1597 FixNetbiosPath(strParent);
1599 if ( IsFreelanceRoot(strParent) && !IsAdmin() ) {
1600 ShowMessageBox(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, MB_ICONERROR, IDS_NOT_AFS_CLIENT_ADMIN_ERROR);
1604 blob.in_size = ustrLast.GetLength() + 1;
1605 blob.in = ustrLast.GetBuffer();
1606 blob.out = lsbuffer;
1607 blob.out_size = sizeof(lsbuffer);
1608 code = pioctl_T(strParent, VIOC_LISTSYMLINK, &blob, 0);
1609 ustrLast.ReleaseBuffer();
1613 blob.in_size = ustrLast.GetLength() + 1;
1614 blob.in = ustrLast.GetBuffer();
1616 code = pioctl_T(strParent, VIOC_DELSYMLINK, &blob, 0);
1618 ustrLast.ReleaseBuffer();
1623 BOOL IsSymlink(const CString& strName)
1625 struct ViceIoctl blob;
1628 HOURGLASS hourglass;
1632 str.Format(_T("IsSymlink(%s)"), strName);
1633 OutputDebugString(str);
1636 CStringUtf8 ustrLast(LastComponent(strName));
1637 CString strParent = Parent(strName);
1639 FixNetbiosPath(strParent);
1641 blob.in_size = ustrLast.GetLength() + 1;
1642 blob.in = ustrLast.GetBuffer();
1643 blob.out_size = MAXSIZE;
1645 memset(space, 0, MAXSIZE);
1647 code = pioctl_T(strParent, VIOC_LISTSYMLINK, &blob, 1);
1649 ustrLast.ReleaseBuffer();
1655 BOOL IsMountPoint(const CString& path)
1657 register LONG code = 0;
1658 struct ViceIoctl blob;
1659 char lsbuffer[1024];
1661 HOURGLASS hourglass;
1665 str.Format(_T("IsMountPoint(%s)"), path);
1666 OutputDebugString(str);
1669 CString parent = Parent(path);
1670 FixNetbiosPath(parent);
1672 CStringUtf8 mountpoint(LastComponent(path));
1677 str.Format(_T("last_component=%S"), mountpoint);
1679 str.Format(_T("last_component=%s"), mountpoint);
1681 OutputDebugString(str);
1684 blob.in_size = mountpoint.GetLength() + 1;
1685 blob.in = mountpoint.GetBuffer();
1686 blob.out = lsbuffer;
1687 blob.out_size = sizeof(lsbuffer);
1689 code = pioctl_T(parent, VIOC_AFS_STAT_MT_PT, &blob, 0);
1691 mountpoint.ReleaseBuffer();
1698 * Delete AFS mount points. Variables are used as follows:
1699 * tbuffer: Set to point to the null-terminated directory name of the mount point
1700 * (or ``.'' if none is provided)
1701 * tp: Set to point to the actual name of the mount point to nuke.
1703 BOOL RemoveMount(CStringArray& files)
1705 register LONG code = 0;
1706 struct ViceIoctl blob;
1708 CStringArray results;
1712 HOURGLASS hourglass;
1714 for (int i = 0; i < files.GetSize(); i++) {
1715 if (!IsMountPoint(files[i])) {
1717 if (errno == EINVAL)
1718 results.Add(GetMessageString(IDS_NOT_MOUNT_POINT_ERROR, StripPath(files[i])));
1720 results.Add(GetMessageString(IDS_ERROR, GetAfsError(errno, StripPath(files[i]))));
1721 continue; // don't bother trying
1724 CString parent = Parent(files[i]);
1725 CStringUtf8 mountpoint(LastComponent(files[i]));
1726 FixNetbiosPath(parent);
1728 if ( IsFreelanceRoot(parent) && !IsAdmin() ) {
1729 results.Add(GetMessageString(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, StripPath(files[i])));
1731 continue; /* skip */
1735 blob.in_size = mountpoint.GetLength() + 1;
1736 blob.in = mountpoint.GetBuffer();
1738 code = pioctl_T(parent, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1740 mountpoint.ReleaseBuffer();
1744 results.Add(GetMessageString(IDS_ERROR, GetAfsError(errno, StripPath(files[i]))));
1746 results.Add(GetMessageString(IDS_DELETED));
1749 LoadString (str, IDS_REMOVE_MP);
1750 LoadString (str2, IDS_REMOVE_MP_COLUMN);
1751 CResultsDlg dlg(REMOVE_MOUNT_POINTS_HELP_ID);
1752 dlg.SetContents(str, str2, StripPath(files), results);
1758 BOOL GetVolumeInfo(CString strFile, CVolInfo& volInfo)
1761 struct ViceIoctl blob;
1762 struct VolumeStatus *status;
1765 HOURGLASS hourglass;
1767 volInfo.m_strFilePath = strFile;
1768 volInfo.m_strFileName = StripPath(strFile);
1771 volInfo.m_strName = "VolumeName";
1773 volInfo.m_nQuota = 20 * 1024 * 1024;
1774 volInfo.m_nNewQuota = volInfo.m_nQuota;
1775 volInfo.m_nUsed = volInfo.m_nQuota / 2;
1776 volInfo.m_nPartSize = 50 * 1024 * 1024;
1777 volInfo.m_nPartFree = 30 * 1024 * 1024;
1778 volInfo.m_nDup = -1;
1782 blob.out_size = MAXSIZE;
1786 code = pioctl_T(strFile, VIOCGETVOLSTAT, &blob, 1);
1788 volInfo.m_strErrorMsg = GetAfsError(errno, strFile);
1792 status = (VolumeStatus *)space;
1793 name = (char *)status + sizeof(*status);
1795 volInfo.m_strName = Utf8ToCString(name);
1796 volInfo.m_nID = status->Vid;
1797 volInfo.m_nQuota = status->MaxQuota;
1798 volInfo.m_nNewQuota = status->MaxQuota;
1799 volInfo.m_nUsed = status->BlocksInUse;
1800 volInfo.m_nPartSize = status->PartMaxBlocks;
1801 volInfo.m_nPartFree = status->PartBlocksAvail;
1802 volInfo.m_nDup = -1;
1807 BOOL SetVolInfo(CVolInfo& volInfo)
1810 struct ViceIoctl blob;
1811 struct VolumeStatus *status;
1814 HOURGLASS hourglass;
1816 blob.out_size = MAXSIZE;
1817 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1821 status = (VolumeStatus *)space;
1822 status->MinQuota = -1;
1823 status->MaxQuota = volInfo.m_nNewQuota;
1825 input = (char *)status + sizeof(*status);
1826 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1827 *(input++) = '\0'; // No offmsg
1828 *(input++) = '\0'; // No motd
1831 FILE *fp = OpenFile(szLogFileName, "a");
1833 fprintf(fp, "\nSetVolInfo() pioctl parms:\n");
1834 fprintf(fp, "\tpathp = %s\n\topcode = VIOCSETVOLSTAT (%d)\n\tblobp = %ld\n", PCCHAR(volInfo.m_strFilePath), VIOCSETVOLSTAT, &blob);
1835 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);
1836 fprintf(fp, "\t\t\tstatus->MinQuota = %ld\n", status->MinQuota);
1837 fprintf(fp, "\t\t\tstatus->MaxQuota = %ld\n", status->MaxQuota);
1838 fprintf(fp, "\t\t\tOther status fields aren't set\n");
1839 fprintf(fp, "\t\t\t3 nulls follow the VolumeStatus structure.\n");
1840 fprintf(fp, "\tfollow = 1\n");
1845 code = pioctl_T(volInfo.m_strFilePath, VIOCSETVOLSTAT, &blob, 1);
1847 ShowMessageBox(IDS_SET_QUOTA_ERROR, MB_ICONERROR, IDS_SET_QUOTA_ERROR, GetAfsError(errno, volInfo.m_strName));
1854 void GetCellName(const CString& cellNamep, struct afsconf_cell *infop)
1856 CStringUtf8 uCellName(cellNamep);
1858 StringCbCopyA(infop->name, sizeof(infop->name), uCellName);
1861 BOOL CheckServers(const CString& strCellName, WHICH_CELLS nCellsToCheck, BOOL bFast)
1864 struct ViceIoctl blob;
1867 struct afsconf_cell info;
1868 struct chservinfo checkserv;
1870 HOURGLASS hourglass;
1872 memset(&checkserv, 0, sizeof(struct chservinfo));
1873 blob.in_size = sizeof(struct chservinfo);
1874 blob.in = (caddr_t)&checkserv;
1876 blob.out_size = MAXSIZE;
1878 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1880 if (nCellsToCheck == SPECIFIC_CELL) {
1882 GetCellName(strCellName, &info);
1883 strcpy(checkserv.tbuffer,info.name);
1884 checkserv.tsize = strlen(info.name) + 1;
1886 if (nCellsToCheck != ALL_CELLS)
1888 strcpy(checkserv.tbuffer, "\0");
1889 checkserv.tsize = 0;
1892 temp |= 1; /* set fast flag */
1894 checkserv.magic = 0x12345678; /* XXX */
1895 checkserv.tflags = temp;
1896 checkserv.tinterval = -1; /* don't change current interval */
1898 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
1900 ShowMessageBox(IDS_CHECK_SERVERS_ERROR, MB_ICONERROR, IDS_CHECK_SERVERS_ERROR, GetAfsError(errno, CString()));
1904 memcpy(&temp, space, sizeof(LONG));
1907 ShowMessageBox(IDS_ALL_SERVERS_RUNNING, MB_OK|MB_ICONINFORMATION, IDS_ALL_SERVERS_RUNNING);
1911 CStringArray servers;
1912 for (j = 0; j < MAXHOSTS; j++) {
1913 memcpy(&temp, space + j * sizeof(LONG), sizeof(LONG));
1917 char *name = hostutil_GetNameByINet(temp);
1921 CDownServersDlg dlg;
1922 dlg.SetServerNames(servers);
1928 BOOL GetTokenInfo(CStringArray& tokenInfo)
1932 time_t current_time;
1933 time_t tokenExpireTime;
1937 struct ktc_principal serviceName, clientName;
1938 struct ktc_token token;
1940 CString strTokenInfo;
1941 CString strUserName;
1942 CString strCellName;
1945 // tokenInfo.Add("");
1949 HOURGLASS hourglass;
1951 // printf("\nTokens held by the Cache Manager:\n\n");
1953 current_time = time(0);
1956 rc = ktc_ListTokens(cellNum, &cellNum, &serviceName);
1957 if (rc == KTC_NOENT) {
1959 // printf(" --End of list --\n");
1962 else if (rc == KTC_NOCM) {
1963 ShowMessageBox(IDS_GET_TOKENS_NO_AFS_SERVICE);
1964 // printf("AFS service may not have started\n");
1968 ShowMessageBox(IDS_GET_TOKENS_UNEXPECTED_ERROR, MB_ICONERROR, IDS_GET_TOKENS_UNEXPECTED_ERROR, rc);
1970 // printf("Unexpected error, code %d\n", rc);
1974 rc = ktc_GetToken(&serviceName, &token, sizeof(token), &clientName);
1976 ShowMessageBox(IDS_GET_TOKENS_UNEXPECTED_ERROR2, MB_ICONERROR, IDS_GET_TOKENS_UNEXPECTED_ERROR2,
1977 serviceName.name, serviceName.instance, serviceName.cell, rc);
1981 tokenExpireTime = token.endTime;
1983 strcpy(userName, clientName.name);
1984 if (clientName.instance[0] != 0) {
1985 strcat(userName, ".");
1986 strcat(userName, clientName.instance);
1989 BOOL bShowName = FALSE;
1991 if (userName[0] == '\0')
1992 ; //printf("Tokens");
1993 // AFS ID is not returned at this time.
1994 // else if (strncmp(userName, "AFS ID", 6) == 0)
1995 // printf("User's (%s) tokens", userName);
1996 // sscanf(userName, "(AFS ID %s)", szAfsID);
1997 else if (strncmp(userName, "Unix UID", 8) == 0)
1998 ; //printf("Tokens");
2000 strUserName = userName;
2001 // printf("User %s's tokens", userName);
2003 // printf(" for %s%s%s@%s ", serviceName.name, serviceName.instance[0] ? "." : "", serviceName.instance, serviceName.cell);
2004 strCellName = serviceName.cell;
2006 if (tokenExpireTime <= current_time)
2007 strExpir = "[>> Expired <<]";
2008 // printf("[>> Expired <<]\n");
2010 expireString = ctime(&tokenExpireTime);
2011 expireString += 4; /* Skip day of week */
2012 expireString[12] = '\0'; /* Omit secs & year */
2013 // printf("[Expires %s]\n", expireString);
2015 strExpir.Format(_T("%S"), expireString);
2017 strExpir.Format(_T("%s"), expireString);
2021 strTokenInfo = strUserName + "\t" + strCellName + "\t" + strExpir + "\t" + strCellName;
2022 tokenInfo.Add(strTokenInfo);
2026 // printf("Press <Enter> or <Return> when finished: ");
2031 UINT MakeSymbolicLink(const CString& strName, const CString& strTarget)
2033 struct ViceIoctl blob;
2035 HOURGLASS hourglass;
2037 CString strParent = Parent(strName);
2038 FixNetbiosPath(strParent);
2042 str.Format(_T("MakeSymbolicLink: name = %s target = %s parent = %s\n"),
2043 strName, strTarget, strParent);
2044 OutputDebugString(str);
2047 if ( IsFreelanceRoot(strParent) && !IsAdmin() ) {
2048 ShowMessageBox(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, MB_ICONERROR, IDS_NOT_AFS_CLIENT_ADMIN_ERROR);
2052 CStringUtf8 ustrTarget(strTarget);
2054 blob.in_size = ustrTarget.GetLength() + 1;
2055 blob.in = ustrTarget.GetBuffer();
2059 code = pioctl_T(strName, VIOC_SYMLINK, &blob, 0);
2061 ustrTarget.ReleaseBuffer();
2068 void ListSymbolicLinkPath(const char *strName,char *strPath,UINT nlenPath)
2070 ASSERT(nlenPath<MAX_PATH);
2071 struct ViceIoctl blob;
2072 char orig_name[MAX_PATH+1]; /*Original name, may be modified*/
2073 char true_name[MAX_PATH+1]; /*``True'' dirname (e.g., symlink target)*/
2074 char parent_dir[MAX_PATH+1]; /*Parent directory of true name*/
2075 char *last_component; /*Last component of true name*/
2078 HOURGLASS hourglass;
2080 strcpy(orig_name, strName);
2081 strcpy(true_name, orig_name);
2083 * Find rightmost slash, if any.
2085 last_component = (char *) strrchr(true_name, '\\');
2086 if (!last_component)
2087 last_component = (char *) strrchr(true_name, '/');
2088 if (last_component) {
2090 * Found it. Designate everything before it as the parent directory,
2091 * everything after it as the final component.
2093 strncpy(parent_dir, true_name, last_component - true_name + 1);
2094 parent_dir[last_component - true_name + 1] = 0;
2095 last_component++; /*Skip the slash*/
2097 if (!IsPathInAfs(parent_dir)) {
2098 const char * nbname = NetbiosName();
2099 int len = strlen(nbname);
2101 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
2102 parent_dir[len+2] == '\\' &&
2103 parent_dir[len+3] == '\0' &&
2104 !strnicmp(nbname,&parent_dir[2],len))
2106 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
2112 * No slash appears in the given file name. Set parent_dir to the current
2113 * directory, and the last component as the given name.
2115 fs_ExtractDriveLetter(true_name, parent_dir);
2116 strcat(parent_dir, ".");
2117 last_component = true_name;
2118 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
2120 blob.in = last_component;
2121 blob.in_size = strlen(last_component)+1;
2122 blob.out_size = MAXSIZE;
2124 memset(space, 0, MAXSIZE);
2125 if ((code = pioctl(parent_dir, VIOC_LISTSYMLINK, &blob, 1)))
2126 strcpy(space,"???");
2127 ASSERT(strlen(space)<MAX_PATH);
2128 strncpy(strPath,space,nlenPath);
2131 BOOL ListSymlink(CStringArray& files)
2134 struct ViceIoctl blob;
2136 CStringArray symlinks;
2138 HOURGLASS hourglass;
2142 for (int i = 0; i < files.GetSize(); i++) {
2144 CString strParent = Parent(files[i]);
2145 CStringUtf8 ustrLast(LastComponent(files[i]));
2147 FixNetbiosPath(strParent);
2149 blob.in_size = ustrLast.GetLength() + 1;
2150 blob.in = ustrLast.GetBuffer();
2151 blob.out_size = MAXSIZE;
2153 memset(space, 0, MAXSIZE);
2155 code = pioctl_T(strParent, VIOC_LISTSYMLINK, &blob, 1);
2157 ustrLast.ReleaseBuffer();
2160 CString syml = Utf8ToCString(space);
2161 int len = syml.GetLength();
2164 if (syml[len - 1] == _T('.'))
2165 syml.Truncate(len - 1);
2168 symlinks.Add(ParseSymlink(StripPath(files[i]), syml));
2172 if (errno == EINVAL)
2173 symlinks.Add(GetMessageString(IDS_NOT_SYMLINK_ERROR, StripPath(files[i])));
2175 symlinks.Add(GetMessageString(IDS_LIST_MOUNT_POINT_ERROR, GetAfsError(errno, StripPath(files[i]))));
2180 dlg.SetSymlinks(symlinks);