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 PCCHAR(str) ((char *)(const char *)(str))
45 #define VL_NOENT (363524L)
51 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
52 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
54 #define MAXCELLCHARS 64
55 #define MAXHOSTCHARS 64
56 #define MAXHOSTSPERCELL 8
58 static char space[MAXSIZE];
59 static char tspace[1024];
61 static struct ubik_client *uclient;
62 static int rxInitDone = 0;
63 static char pn[] = "fs";
65 // #define LOGGING_ON // Enable this to log certain pioctl calls
68 static char *szLogFileName = "afsguilog.txt";
72 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
76 code = ugen_ClientInit(noAuthFlag, (char *)AFSDIR_CLIENT_ETC_DIRPATH,
77 info->name, 0, &uclient,
78 NULL, pn, rxkad_clear,
79 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
80 0, 0, USER_SERVICE_ID);
85 FILE *OpenFile(char *file, char *rwp)
92 code = GetWindowsDirectory(wdir, sizeof(wdir));
93 if (code == 0 || code > sizeof(wdir))
96 /* add trailing backslash, if required */
98 if (wdir[tlen - 1] != '\\')
103 fp = fopen(wdir, rwp);
108 CString StripPath(CString& strPath)
110 int nIndex = strPath.ReverseFind('\\');
112 CString strFile = strPath.Mid(nIndex + 1);
113 if (strFile.IsEmpty())
119 CStringArray& StripPath(CStringArray& files)
121 for (int i = 0; i < files.GetSize(); i++)
122 files[i] = StripPath(files[i]);
127 void Flush(const CStringArray& files)
130 struct ViceIoctl blob;
135 for (int i = 0; i < files.GetSize(); i++) {
136 blob.in_size = blob.out_size = 0;
138 code = pioctl(PCCHAR(files[i]), VIOCFLUSH, &blob, 0);
142 ShowMessageBox(IDS_FLUSH_FAILED, MB_ICONERROR, IDS_FLUSH_FAILED, files[i]);
144 ShowMessageBox(IDS_FLUSH_ERROR, MB_ICONERROR, IDS_FLUSH_ERROR, files[i], strerror(errno));
149 ShowMessageBox(IDS_FLUSH_OK, MB_ICONINFORMATION, IDS_FLUSH_OK);
152 void FlushVolume(const CStringArray& files)
155 struct ViceIoctl blob;
160 for (int i = 0; i < files.GetSize(); i++) {
161 blob.in_size = blob.out_size = 0;
163 code = pioctl(PCCHAR(files[i]), VIOC_FLUSHVOLUME, &blob, 0);
166 ShowMessageBox(IDS_FLUSH_VOLUME_ERROR, MB_ICONERROR, IDS_FLUSH_VOLUME_ERROR, files[i], strerror(errno));
171 ShowMessageBox(IDS_FLUSH_VOLUME_OK, MB_ICONINFORMATION, IDS_FLUSH_VOLUME_OK);
174 void WhichCell(CStringArray& files)
177 struct ViceIoctl blob;
182 CStringArray results;
188 for (int i = 0; i < files.GetSize(); i++) {
190 blob.out_size = MAXSIZE;
193 code = pioctl(PCCHAR(files[i]), VIOC_FILE_CELL_NAME, &blob, 1);
195 if (code == ENOENT) {
196 LoadString (str, IDS_CANT_GET_CELL);
199 results.Add(GetAfsError(errno));
204 LoadString (str, IDS_SHOW_CELL);
205 LoadString (str2, IDS_SHOW_CELL_COLUMN);
206 CResultsDlg dlg(SHOW_CELL_HELP_ID);
207 dlg.SetContents(str, str2, StripPath(files), results);
214 struct ViceIoctl blob;
219 blob.in = (char *) 0;
220 blob.out_size = MAXSIZE;
223 code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1);
226 //Die(errno, (char *) 0);
229 //printf("This workstation belongs to cell '%s'\n", space);
235 struct ViceIoctl blob;
239 code = pioctl(0, VIOCCKBACK, &blob, 1);
241 ShowMessageBox(IDS_CHECK_VOLUMES_ERROR, MB_ICONERROR, IDS_CHECK_VOLUMES_ERROR, GetAfsError(errno, CString()));
245 ShowMessageBox(IDS_CHECK_VOLUMES_OK, MB_OK|MB_ICONINFORMATION, IDS_CHECK_VOLUMES_OK);
250 void SetCacheSizeCmd(LONG nNewCacheSize)
253 struct ViceIoctl blob;
257 blob.in = (char *) &nNewCacheSize;
258 blob.in_size = sizeof(LONG);
261 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
263 // Die(errno, (char *) 0);
265 // printf("New cache size set.\n");
268 void WhereIs(CStringArray& files)
271 struct ViceIoctl blob;
272 CStringArray servers;
273 CStringArray resultFiles;
279 for (int i = 0; i < files.GetSize(); i++) {
280 blob.out_size = MAXSIZE;
283 memset(space, 0, sizeof(space));
285 code = pioctl(PCCHAR(files[i]), VIOCWHEREIS, &blob, 1);
287 resultFiles.Add(StripPath(files[i]));
288 servers.Add(GetAfsError(errno));
292 LONG *hosts = (LONG *)space;
296 for (int j = 0; j < MAXHOSTS; j++) {
299 char *hostName = hostutil_GetNameByINet(hosts[j]);
301 resultFiles.Add(StripPath(files[i]));
304 resultFiles.Add(" ");
305 servers.Add(hostName);
309 LoadString (str, IDS_SHOW_FS);
310 LoadString (str2, IDS_SHOW_FS_COLUMN);
311 CResultsDlg dlg(SHOW_FILE_SERVERS_HELP_ID);
312 dlg.SetContents(str, str2, resultFiles, servers);
317 CMtoUNIXerror(int cm_code)
320 case CM_ERROR_TIMEDOUT:
322 case CM_ERROR_NOACCESS:
324 case CM_ERROR_NOSUCHFILE:
330 case CM_ERROR_EXISTS:
332 case CM_ERROR_CROSSDEVLINK:
334 case CM_ERROR_NOTDIR:
338 case CM_ERROR_READONLY:
340 case CM_ERROR_WOULDBLOCK:
342 case CM_ERROR_NOSUCHCELL:
343 return ESRCH; /* hack */
344 case CM_ERROR_NOSUCHVOLUME:
345 return EPIPE; /* hack */
346 case CM_ERROR_NOMORETOKENS:
347 return EDOM; /* hack */
348 case CM_ERROR_TOOMANYBUFS:
349 return EFBIG; /* hack */
351 if (cm_code > 0 && cm_code < EILSEQ)
358 CString GetAfsError(int code, const char *filename)
362 code = CMtoUNIXerror(code);
364 if (code == EINVAL) {
366 strMsg.Format("Invalid argument; it is possible that the file is not in AFS");
368 strMsg.Format("Invalid argument");
369 } else if (code == ENOENT) {
371 strMsg.Format("The file does not exist");
373 strMsg.Format("No such file returned");
374 } else if (code == EROFS) {
375 strMsg.Format("You can not change a backup or readonly volume");
376 } else if (code == EACCES || code == EPERM) {
377 strMsg.Format("You do not have the required rights to do this operation");
378 } else if (code == ENODEV) {
379 strMsg.Format("AFS service may not have started");
380 } else if (code == ESRCH) {
381 strMsg.Format("Cell name not recognized");
382 } else if (code == ETIMEDOUT) {
383 strMsg.Format("Connection timed out");
384 } else if (code == EPIPE) {
385 strMsg.Format("Volume name or ID not recognized");
387 strMsg.Format("Error 0x%x occurred", code);
394 /************************************************************************
395 ************************** ACL Code *************************************
396 ************************************************************************/
398 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
401 struct AclEntry *next;
407 int dfs; // Originally true if a dfs acl; now also the type
408 // of the acl (1, 2, or 3, corresponding to object,
409 // initial dir, or initial object).
410 sec_rgy_name_t cell; // DFS cell name
413 struct AclEntry *pluslist;
414 struct AclEntry *minuslist;
417 int foldcmp (register char *a, register char *b)
423 if (t >= 'A' && t <= 'Z') t += 0x20;
424 if (u >= 'A' && u <= 'Z') u += 0x20;
425 if (t != u) return 1;
426 if (t == 0) return 0;
430 extern "C" void ZapList(struct AclEntry *alist)
432 register struct AclEntry *tp, *np;
434 for (tp = alist; tp; tp = np) {
440 extern "C" void ZapAcl (struct Acl *acl)
442 ZapList(acl->pluslist);
443 ZapList(acl->minuslist);
447 extern "C" int PruneList (struct AclEntry **ae, int dfs)
449 struct AclEntry **lp = ae;
450 struct AclEntry *te, *ne;
453 for (te = *ae; te; te = ne) {
454 if ((!dfs && te->rights == 0) || te->rights == -1) {
469 char *SkipLine (register char *astr)
471 while (*astr != '\n')
479 /* tell if a name is 23 or -45 (digits or minus digits), which are bad names we must prune */
480 static int BadName(register char *aname)
484 /* all must be '-' or digit to be bad */
485 while (tc = *aname++) {
486 if ((tc != '-') && (tc < '0' || tc > '9'))
493 CString GetRightsString(register LONG arights, int dfs)
498 if (arights & PRSFS_READ) str += "r";
499 if (arights & PRSFS_LOOKUP) str += "l";
500 if (arights & PRSFS_INSERT) str += "i";
501 if (arights & PRSFS_DELETE) str += "d";
502 if (arights & PRSFS_WRITE) str += "w";
503 if (arights & PRSFS_LOCK) str += "k";
504 if (arights & PRSFS_ADMINISTER) str += "a";
508 if (arights & DFS_READ) str += "r"; else str += "-";
509 if (arights & DFS_WRITE) str += "w"; else printf("-");
510 if (arights & DFS_EXECUTE) str += "x"; else printf("-");
511 if (arights & DFS_CONTROL) str += "c"; else printf("-");
512 if (arights & DFS_INSERT) str += "i"; else printf("-");
513 if (arights & DFS_DELETE) str += "d"; else printf("-");
514 if (arights & (DFS_USRALL)) str += "+";
521 char *AclToString(struct Acl *acl)
523 static char mydata[MAXSIZE];
524 char tstring[MAXSIZE];
529 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
532 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
534 for(tp = acl->pluslist; tp; tp = tp->next) {
535 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
536 strcat(mydata, tstring);
539 for(tp = acl->minuslist; tp; tp = tp->next) {
540 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
541 strcat(mydata, tstring);
547 struct Acl *EmptyAcl(const CString& strCellName)
549 register struct Acl *tp;
551 tp = (struct Acl *)malloc(sizeof (struct Acl));
552 tp->nplus = tp->nminus = 0;
553 tp->pluslist = tp->minuslist = 0;
555 strcpy(tp->cell, strCellName);
560 struct Acl *ParseAcl(char *astr)
562 int nplus, nminus, i, trights;
564 struct AclEntry *first, *last, *tl;
567 ta = (struct Acl *) malloc (sizeof (struct Acl));
569 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
570 astr = SkipLine(astr);
571 sscanf(astr, "%d", &ta->nminus);
572 astr = SkipLine(astr);
579 for(i = 0; i < nplus; i++) {
580 sscanf(astr, "%100s %d", tname, &trights);
581 astr = SkipLine(astr);
582 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
585 strcpy(tl->name, tname);
586 tl->rights = trights;
592 ta->pluslist = first;
596 for(i=0; i < nminus; i++) {
597 sscanf(astr, "%100s %d", tname, &trights);
598 astr = SkipLine(astr);
599 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
602 strcpy(tl->name, tname);
603 tl->rights = trights;
609 ta->minuslist = first;
614 /* clean up an access control list of its bad entries; return 1 if we made
615 any changes to the list, and 0 otherwise */
616 extern "C" int CleanAcl(struct Acl *aa)
618 register struct AclEntry *te, **le, *ne;
623 /* Don't correct DFS ACL's for now */
627 /* prune out bad entries */
628 changes = 0; /* count deleted entries */
630 for(te = aa->pluslist; te; te = ne) {
632 if (BadName(te->name)) {
645 for(te = aa->minuslist; te; te = ne) {
647 if (BadName(te->name)) {
661 void CleanACL(CStringArray& names)
664 register struct Acl *ta;
665 struct ViceIoctl blob;
668 ShowMessageBox(IDS_CLEANACL_MSG, MB_OK|MB_ICONINFORMATION, IDS_CLEANACL_MSG);
672 for (int i = 0; i < names.GetSize(); i++) {
673 blob.out_size = MAXSIZE;
677 code = pioctl(PCCHAR(names[i]), VIOCGETAL, &blob, 1);
679 ShowMessageBox(IDS_CLEANACL_ERROR, MB_ICONERROR, 0, names[i], GetAfsError(errno));
683 ta = ParseAcl(space);
685 ShowMessageBox(IDS_CLEANACL_NOT_SUPPORTED, MB_ICONERROR, IDS_CLEANACL_NOT_SUPPORTED, names[i]);
689 changes = CleanAcl(ta);
693 /* now set the acl */
694 blob.in = AclToString(ta);
695 blob.in_size = strlen((char *)blob.in) + 1;
698 code = pioctl(PCCHAR(names[i]), VIOCSETAL, &blob, 1);
700 if (errno == EINVAL) {
701 ShowMessageBox(IDS_CLEANACL_INVALID_ARG, MB_ICONERROR, IDS_CLEANACL_INVALID_ARG, names[i]);
705 ShowMessageBox(IDS_CLEANACL_ERROR, MB_ICONERROR, 0, names[i], GetAfsError(errno));
712 // Derived from fs.c's ListAclCmd
713 BOOL GetRights(const CString& strDir, CStringArray& strNormal, CStringArray& strNegative)
716 register struct Acl *ta;
717 struct ViceIoctl blob;
719 int idf = 0; //getidf(as, parm_listacl_id);
723 blob.out_size = MAXSIZE;
725 blob.in = blob.out = space;
727 code = pioctl(PCCHAR(strDir), VIOCGETAL, &blob, 1);
729 ShowMessageBox(IDS_GETRIGHTS_ERROR, MB_ICONERROR, IDS_GETRIGHTS_ERROR, strDir, GetAfsError(errno));
733 ta = ParseAcl(space);
735 ShowMessageBox(IDS_DFSACL_ERROR, MB_ICONERROR, IDS_DFSACL_ERROR);
740 // printf(" Default cell = %s\n", ta->cell);
745 for (te = ta->pluslist; te; te = te->next) {
746 strNormal.Add(te->name);
747 strNormal.Add(GetRightsString(te->rights, ta->dfs));
751 if (ta->nminus > 0) {
752 for (te = ta->minuslist; te; te = te->next) {
753 strNegative.Add(te->name);
754 strNegative.Add(GetRightsString(te->rights, ta->dfs));
761 struct AclEntry *FindList(register struct AclEntry *pCurEntry, const char *entryName)
764 if (!foldcmp(pCurEntry->name, PCCHAR(entryName)))
766 pCurEntry = pCurEntry->next;
772 void ChangeList (struct Acl *pAcl, BYTE bNormalRights, const char *entryName, LONG nEntryRights)
777 struct AclEntry *pEntry;
781 pEntry = (bNormalRights ? pAcl->pluslist : pAcl->minuslist);
782 pEntry = FindList(pEntry, entryName);
784 /* Found the item already in the list. */
786 pEntry->rights = nEntryRights;
788 pAcl->nplus -= PruneList(&pAcl->pluslist, pAcl->dfs);
790 pAcl->nminus -= PruneList(&pAcl->minuslist, pAcl->dfs);
794 /* Otherwise we make a new item and plug in the new data. */
795 pEntry = (struct AclEntry *) malloc(sizeof (struct AclEntry));
798 strcpy(pEntry->name, entryName);
799 pEntry->rights = nEntryRights;
802 pEntry->next = pAcl->pluslist;
803 pAcl->pluslist = pEntry;
805 if (nEntryRights == 0 || nEntryRights == -1)
806 pAcl->nplus -= PruneList(&pAcl->pluslist, pAcl->dfs);
809 pEntry->next = pAcl->minuslist;
810 pAcl->minuslist = pEntry;
812 if (nEntryRights == 0)
813 pAcl->nminus -= PruneList(&pAcl->minuslist, pAcl->dfs);
817 enum rtype {add, destroy, deny};
819 LONG Convert(const register char *arights, int dfs, enum rtype *rtypep)
825 *rtypep = add; /* add rights, by default */
827 if (!strcmp(arights,"read"))
828 return PRSFS_READ | PRSFS_LOOKUP;
829 if (!strcmp(arights, "write"))
830 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK;
831 if (!strcmp(arights, "mail"))
832 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
833 if (!strcmp(arights, "all"))
834 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
836 if (!strcmp(arights, "none")) {
837 *rtypep = destroy; /* Remove entire entry */
841 len = strlen(arights);
844 for (i = 0; i < len; i++) {
846 if (tc == 'r') mode |= PRSFS_READ;
847 else if (tc == 'l') mode |= PRSFS_LOOKUP;
848 else if (tc == 'i') mode |= PRSFS_INSERT;
849 else if (tc == 'd') mode |= PRSFS_DELETE;
850 else if (tc == 'w') mode |= PRSFS_WRITE;
851 else if (tc == 'k') mode |= PRSFS_LOCK;
852 else if (tc == 'a') mode |= PRSFS_ADMINISTER;
854 fprintf(stderr, "illegal rights character '%c'.\n", tc);
861 BOOL SaveACL(const CString& strCellName, const CString& strDir, const CStringArray& normal, const CStringArray& negative)
864 struct ViceIoctl blob;
872 pAcl = EmptyAcl(strCellName);
874 // Set its normal rights
876 for (i = 0; i < normal.GetSize(); i += 2) {
877 rights = Convert(normal[i + 1], 0, &rtype);
878 ChangeList(pAcl, TRUE, normal[i], rights);
881 // Set its negative rights
882 for (i = 0; i < negative.GetSize(); i += 2) {
883 rights = Convert(negative[i + 1], 0, &rtype);
884 ChangeList(pAcl, FALSE, negative[i], rights);
888 blob.in = AclToString(pAcl);
890 blob.in_size = 1 + strlen((const char *)blob.in);
892 code = pioctl(PCCHAR(strDir), VIOCSETAL, &blob, 1);
895 ShowMessageBox(IDS_SAVE_ACL_EINVAL_ERROR, MB_ICONERROR, IDS_SAVE_ACL_EINVAL_ERROR, strDir);
897 ShowMessageBox(IDS_SAVE_ACL_ERROR, MB_ICONERROR, IDS_SAVE_ACL_ERROR, strDir, GetAfsError(errno, strDir));
905 BOOL CopyACL(const CString& strToDir, const CStringArray& normal, const CStringArray& negative, BOOL bClear)
908 struct ViceIoctl blob;
910 int idf = 0; // getidf(as, parm_copyacl_id);
914 // Get ACL to copy to
915 blob.out_size = MAXSIZE;
917 blob.in = blob.out = space;
919 code = pioctl(PCCHAR(strToDir), VIOCGETAL, &blob, 1);
921 ShowMessageBox(IDS_ACL_READ_ERROR, MB_ICONERROR, IDS_ACL_READ_ERROR, strToDir, GetAfsError(errno, strToDir));
926 pToAcl = EmptyAcl(space);
928 pToAcl = ParseAcl(space);
933 ShowMessageBox(IDS_NO_DFS_COPY_ACL, MB_ICONERROR, IDS_NO_DFS_COPY_ACL, strToDir);
942 for (i = 0; i < normal.GetSize(); i += 2) {
943 LONG rights = Convert(normal[i + 1], 0, &rtype);
944 ChangeList(pToAcl, TRUE, normal[i], rights);
947 // Set negative rights
948 for (i = 0; i < negative.GetSize(); i += 2) {
949 LONG rights = Convert(negative[i + 1], 0, &rtype);
950 ChangeList(pToAcl, FALSE, normal[i], rights);
954 blob.in = AclToString(pToAcl);
956 blob.in_size = 1 + strlen((char *)blob.in);
958 code = pioctl(PCCHAR(strToDir), VIOCSETAL, &blob, 1);
962 ShowMessageBox(IDS_COPY_ACL_EINVAL_ERROR, MB_ICONERROR, IDS_COPY_ACL_EINVAL_ERROR, strToDir);
964 ShowMessageBox(IDS_COPY_ACL_ERROR, MB_ICONERROR, IDS_COPY_ACL_ERROR, strToDir, GetAfsError(errno, strToDir));
970 ShowMessageBox(IDS_COPY_ACL_OK, MB_OK|MB_ICONINFORMATION, IDS_COPY_ACL_OK);
975 CString ParseMountPoint(const CString strFile, CString strMountPoint)
980 CString strMountPointInfo;
982 if (strMountPoint[0] == '#')
984 else if (strMountPoint[0] == '%')
985 strType = "Read/Write";
987 int nColon = strMountPoint.Find(':');
989 strCell = strMountPoint.Mid(1, nColon - 1);
990 strVolume = strMountPoint.Mid(nColon + 1);
992 strVolume = strMountPoint.Mid(1);
994 strMountPointInfo = strFile + "\t" + strVolume + "\t" + strCell + "\t" + strType;
996 return strMountPointInfo;
999 CString ParseSymlink(const CString strFile, CString strSymlink)
1001 CString strSymlinkInfo;
1003 strSymlinkInfo = strFile + "\t" + strSymlink;
1005 return strSymlinkInfo;
1008 BOOL IsPathInAfs(const CHAR *strPath)
1010 struct ViceIoctl blob;
1013 HOURGLASS hourglass;
1016 sprintf(buf, "IsPathInAfs(%s)", strPath);
1017 OutputDebugString(buf);
1020 blob.out_size = MAXSIZE;
1023 code = pioctl((LPTSTR)((LPCTSTR)strPath), VIOC_FILE_CELL_NAME, &blob, 1);
1025 sprintf(buf, "VIOC_FILE_CELL_NAME=%d", code);
1026 OutputDebugString(buf);
1029 if ((errno == EINVAL) || (errno == ENOENT))
1036 IsFreelanceRoot(char *apath)
1038 struct ViceIoctl blob;
1042 blob.out_size = MAXSIZE;
1045 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
1047 return !strcmp("Freelance.Local.Root",space);
1048 return 1; /* assume it is because it is more restrictive that way */
1051 const char * NetbiosName(void)
1053 static char buffer[1024] = "AFS";
1059 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
1060 0, KEY_QUERY_VALUE, &parmKey);
1061 if (code == ERROR_SUCCESS) {
1062 dummyLen = sizeof(buffer);
1063 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
1064 (LPBYTE)buffer, &dummyLen);
1065 RegCloseKey (parmKey);
1067 strcpy(buffer, "AFS");
1072 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
1074 static BOOL IsAdmin (void)
1076 static BOOL fAdmin = FALSE;
1077 static BOOL fTested = FALSE;
1081 /* Obtain the SID for the AFS client admin group. If the group does
1082 * not exist, then assume we have AFS client admin privileges.
1084 PSID psidAdmin = NULL;
1085 DWORD dwSize, dwSize2;
1086 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
1087 char *pszRefDomain = NULL;
1088 SID_NAME_USE snu = SidTypeGroup;
1090 dwSize = sizeof(pszAdminGroup);
1092 if (!GetComputerName(pszAdminGroup, &dwSize)) {
1093 /* Can't get computer name. We return false in this case.
1094 Retain fAdmin and fTested. This shouldn't happen.*/
1101 strcat(pszAdminGroup,"\\");
1102 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
1104 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
1105 /* that should always fail. */
1107 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
1108 /* if we can't find the group, then we allow the operation */
1113 if (dwSize == 0 || dwSize2 == 0) {
1119 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
1120 pszRefDomain = (char *)malloc(dwSize2);
1122 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
1123 /* We can't lookup the group now even though we looked it up earlier.
1124 Could this happen? */
1127 /* Then open our current ProcessToken */
1130 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
1133 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
1134 /* We'll have to allocate a chunk of memory to store the list of
1135 * groups to which this user belongs; find out how much memory
1139 PTOKEN_GROUPS pGroups;
1141 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
1143 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
1145 /* Allocate that buffer, and read in the list of groups. */
1146 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
1148 /* Look through the list of group SIDs and see if any of them
1149 * matches the AFS Client Admin group SID.
1152 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
1154 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
1164 /* if do not have permission because we were not explicitly listed
1165 * in the Admin Client Group let's see if we are the SYSTEM account
1168 PTOKEN_USER pTokenUser;
1169 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
1170 PSID pSidLocalSystem = 0;
1173 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
1175 pTokenUser = (PTOKEN_USER)malloc(dwSize);
1177 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
1178 gle = GetLastError();
1180 if (AllocateAndInitializeSid( &SIDAuth, 1,
1181 SECURITY_LOCAL_SYSTEM_RID,
1182 0, 0, 0, 0, 0, 0, 0,
1185 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
1189 FreeSid(pSidLocalSystem);
1207 /* return a static pointer to a buffer */
1208 static char *Parent(char *apath)
1212 strcpy(tspace, apath);
1213 tp = strrchr(tspace, '\\');
1215 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
1218 fs_ExtractDriveLetter(apath, tspace);
1219 strcat(tspace, ".");
1226 GetCell(char *fname, char *cellname)
1229 struct ViceIoctl blob;
1232 blob.out_size = MAXCELLCHARS;
1233 blob.out = cellname;
1235 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1236 return code ? errno : 0;
1240 BOOL ListMount(CStringArray& files)
1243 struct ViceIoctl blob;
1245 char orig_name[1024]; /* Original name, may be modified */
1246 char true_name[1024]; /* ``True'' dirname (e.g., symlink target) */
1247 char parent_dir[1024]; /* Parent directory of true name */
1248 register char *last_component; /* Last component of true name */
1249 CStringArray mountPoints;
1251 HOURGLASS hourglass;
1255 for (int i = 0; i < files.GetSize(); i++) {
1256 strcpy(orig_name, files[i]);
1257 strcpy(true_name, orig_name);
1260 * Find rightmost slash, if any.
1262 last_component = (char *)strrchr(true_name, '\\');
1263 if (last_component) {
1265 * Found it. Designate everything before it as the parent directory,
1266 * everything after it as the final component.
1268 strncpy(parent_dir, true_name, last_component - true_name + 1);
1269 parent_dir[last_component - true_name + 1] = 0;
1270 last_component++; /* Skip the slash */
1272 if (!IsPathInAfs(parent_dir)) {
1273 const char * nbname = NetbiosName();
1274 int len = strlen(nbname);
1276 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
1277 parent_dir[len+2] == '\\' &&
1278 parent_dir[len+3] == '\0' &&
1279 !strnicmp(nbname,&parent_dir[2],len))
1281 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
1287 * No slash appears in the given file name. Set parent_dir to the current
1288 * directory, and the last component as the given name.
1290 fs_ExtractDriveLetter(true_name, parent_dir);
1291 strcat(parent_dir, ".");
1292 last_component = true_name;
1293 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1296 blob.in = last_component;
1297 blob.in_size = strlen(last_component) + 1;
1298 blob.out_size = MAXSIZE;
1300 memset(space, 0, MAXSIZE);
1302 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1304 int nPos = strlen(space) - 1;
1305 if (space[nPos] == '.')
1307 mountPoints.Add(ParseMountPoint(StripPath(files[i]), space));
1310 if (errno == EINVAL)
1311 mountPoints.Add(GetMessageString(IDS_NOT_MOUNT_POINT_ERROR, StripPath(files[i])));
1313 mountPoints.Add(GetMessageString(IDS_LIST_MOUNT_POINT_ERROR, GetAfsError(errno, StripPath(files[i]))));
1317 CMountPointsDlg dlg;
1318 dlg.SetMountPoints(mountPoints);
1324 BOOL MakeMount(const CString& strDir, const CString& strVolName, const CString& strCellName, BOOL bRW)
1327 register char *cellName;
1328 char localCellName[128];
1329 struct afsconf_cell info;
1331 struct vldbentry vldbEntry;
1333 struct ViceIoctl blob;
1335 char path[1024] = "";
1337 HOURGLASS hourglass;
1339 ASSERT(strVolName.GetLength() < 64);
1341 if (strCellName.GetLength() > 0) /* cell name specified */
1342 cellName = PCCHAR(strCellName);
1344 cellName = (char *) 0;
1346 parent = Parent(PCCHAR(strDir));
1347 if (!IsPathInAfs(parent)) {
1348 const char * nbname = NetbiosName();
1349 int len = strlen(nbname);
1351 if (parent[0] == '\\' && parent[1] == '\\' &&
1352 parent[len+2] == '\\' &&
1353 parent[len+3] == '\0' &&
1354 !strnicmp(nbname,&parent[2],len))
1356 sprintf(path,"%sall\\%s", parent, &(PCCHAR(strDir)[strlen(parent)]));
1357 parent = Parent(path);
1358 if (!IsPathInAfs(parent)) {
1359 ShowMessageBox(IDS_MAKE_MP_NOT_AFS_ERROR, MB_ICONERROR, IDS_MAKE_MP_NOT_AFS_ERROR);
1363 ShowMessageBox(IDS_MAKE_MP_NOT_AFS_ERROR, MB_ICONERROR, IDS_MAKE_MP_NOT_AFS_ERROR);
1368 if ( strlen(path) == 0 )
1369 strcpy(path, PCCHAR(strDir));
1371 if ( IsFreelanceRoot(parent) ) {
1373 ShowMessageBox(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, MB_ICONERROR, IDS_NOT_AFS_CLIENT_ADMIN_ERROR);
1379 blob.out_size = sizeof(localCellName);
1380 blob.out = localCellName;
1381 code = pioctl(parent, VIOC_GET_WS_CELL, &blob, 1);
1383 cellName = localCellName;
1387 GetCell(parent,space);
1390 code = GetCellName(cellName?cellName:space, &info);
1396 code = VLDBInit(1, &info);
1398 /* make the check. Don't complain if there are problems with init */
1399 code = ubik_VL_GetEntryByNameO(uclient, 0, PCCHAR(strVolName), &vldbEntry);
1400 if (code == VL_NOENT) {
1401 ShowMessageBox(IDS_WARNING, MB_ICONWARNING, IDS_VOLUME_NOT_IN_CELL_WARNING,
1402 PCCHAR(strVolName), cellName ? cellName : space);
1409 if (bRW) /* if -rw specified */
1414 /* If cellular mount point, prepend cell prefix */
1416 strcat(space, info.name);
1420 strcat(space, strVolName); /* append volume name */
1421 strcat(space, "."); /* stupid convention; these end with a period */
1423 /* create symlink with a special pioctl for Windows NT, since it doesn't
1424 * have a symlink system call.
1427 blob.in_size = 1 + strlen(space);
1430 code = pioctl(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
1433 ShowMessageBox(IDS_MOUNT_POINT_ERROR, MB_ICONERROR, IDS_MOUNT_POINT_ERROR, GetAfsError(errno, strDir));
1442 long fs_ExtractDriveLetter(const char *inPathp, char *outPathp)
1444 if (inPathp[0] != 0 && inPathp[1] == ':') {
1445 /* there is a drive letter */
1446 *outPathp++ = *inPathp++;
1447 *outPathp++ = *inPathp++;
1455 /* strip the drive letter from a component */
1456 long fs_StripDriveLetter(const char *inPathp, char *outPathp, long outSize)
1458 char tempBuffer[1000];
1459 strcpy(tempBuffer, inPathp);
1460 if (tempBuffer[0] != 0 && tempBuffer[1] == ':') {
1461 /* drive letter present */
1462 strcpy(outPathp, tempBuffer+2);
1465 /* no drive letter present */
1466 strcpy(outPathp, tempBuffer);
1472 BOOL RemoveSymlink(const char * linkName)
1476 struct ViceIoctl blob;
1478 char lsbuffer[1024];
1479 char tpbuffer[1024];
1482 HOURGLASS hourglass;
1484 tp = (char *) strrchr(linkName, '\\');
1486 tp = (char *) strrchr(linkName, '/');
1488 strncpy(tbuffer, linkName, code=tp-linkName+1); /* the dir name */
1490 tp++; /* skip the slash */
1492 if (!IsPathInAfs(tbuffer)) {
1493 const char * nbname = NetbiosName();
1494 int len = strlen(nbname);
1496 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
1497 tbuffer[len+2] == '\\' &&
1498 tbuffer[len+3] == '\0' &&
1499 !strnicmp(nbname,&tbuffer[2],len))
1501 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
1506 fs_ExtractDriveLetter(linkName, tbuffer);
1507 strcat(tbuffer, ".");
1508 fs_StripDriveLetter(tp, tpbuffer, 0);
1512 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
1513 ShowMessageBox(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, MB_ICONERROR, IDS_NOT_AFS_CLIENT_ADMIN_ERROR);
1518 blob.in_size = strlen(tp)+1;
1519 blob.out = lsbuffer;
1520 blob.out_size = sizeof(lsbuffer);
1521 code = pioctl(tbuffer, VIOC_LISTSYMLINK, &blob, 0);
1526 blob.in_size = strlen(tp)+1;
1527 return (pioctl(tbuffer, VIOC_DELSYMLINK, &blob, 0)==0);
1530 BOOL IsSymlink(const char * true_name)
1532 char parent_dir[MAXSIZE]; /*Parent directory of true name*/
1533 char strip_name[MAXSIZE];
1534 struct ViceIoctl blob;
1535 char *last_component;
1538 HOURGLASS hourglass;
1541 sprintf(buf, "IsSymlink(%s)", true_name);
1542 OutputDebugString(buf);
1544 last_component = (char *) strrchr(true_name, '\\');
1545 if (!last_component)
1546 last_component = (char *) strrchr(true_name, '/');
1547 if (last_component) {
1549 * Found it. Designate everything before it as the parent directory,
1550 * everything after it as the final component.
1552 strncpy(parent_dir, true_name, last_component - true_name + 1);
1553 parent_dir[last_component - true_name + 1] = 0;
1554 last_component++; /*Skip the slash*/
1556 if (!IsPathInAfs(parent_dir)) {
1557 const char * nbname = NetbiosName();
1558 int len = strlen(nbname);
1560 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
1561 parent_dir[len+2] == '\\' &&
1562 parent_dir[len+3] == '\0' &&
1563 !strnicmp(nbname,&parent_dir[2],len))
1565 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
1571 * No slash appears in the given file name. Set parent_dir to the current
1572 * directory, and the last component as the given name.
1574 fs_ExtractDriveLetter(true_name, parent_dir);
1575 strcat(parent_dir, ".");
1576 last_component = strip_name;
1577 fs_StripDriveLetter(true_name, strip_name, sizeof(strip_name));
1580 sprintf(buf, "last_component=%s", last_component);
1581 OutputDebugString(buf);
1583 blob.in = last_component;
1584 blob.in_size = strlen(last_component)+1;
1585 blob.out_size = MAXSIZE;
1587 memset(space, 0, MAXSIZE);
1588 code = pioctl(parent_dir, VIOC_LISTSYMLINK, &blob, 1);
1593 BOOL IsMountPoint(const char * name)
1595 register LONG code = 0;
1596 struct ViceIoctl blob;
1598 char lsbuffer[1024];
1600 char szCurItem[1024];
1602 HOURGLASS hourglass;
1604 strcpy(szCurItem, name);
1607 sprintf(buf, "IsMountPoint(%s)", name);
1608 OutputDebugString(buf);
1610 tp = (char *)strrchr(szCurItem, '\\');
1612 strncpy(tbuffer, szCurItem, code = tp - szCurItem + 1); /* the dir name */
1614 tp++; /* skip the slash */
1616 if (!IsPathInAfs(tbuffer)) {
1617 const char * nbname = NetbiosName();
1618 int len = strlen(nbname);
1620 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
1621 tbuffer[len+2] == '\\' &&
1622 tbuffer[len+3] == '\0' &&
1623 !strnicmp(nbname,&tbuffer[2],len))
1625 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
1629 fs_ExtractDriveLetter(szCurItem, tbuffer);
1630 strcat(tbuffer, ".");
1632 fs_StripDriveLetter(tp, tp, 0);
1635 sprintf(buf, "last_component=%s", tp);
1636 OutputDebugString(buf);
1639 blob.in_size = strlen(tp)+1;
1640 blob.out = lsbuffer;
1641 blob.out_size = sizeof(lsbuffer);
1643 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1650 * Delete AFS mount points. Variables are used as follows:
1651 * tbuffer: Set to point to the null-terminated directory name of the mount point
1652 * (or ``.'' if none is provided)
1653 * tp: Set to point to the actual name of the mount point to nuke.
1655 BOOL RemoveMount(CStringArray& files)
1657 register LONG code = 0;
1658 struct ViceIoctl blob;
1661 char szCurItem[1024];
1663 CStringArray results;
1667 HOURGLASS hourglass;
1669 for (int i = 0; i < files.GetSize(); i++) {
1670 if (!IsMountPoint(files[i])) {
1672 if (errno == EINVAL)
1673 results.Add(GetMessageString(IDS_NOT_MOUNT_POINT_ERROR, StripPath(files[i])));
1675 results.Add(GetMessageString(IDS_ERROR, GetAfsError(errno, StripPath(files[i]))));
1676 continue; // don't bother trying
1679 strcpy(szCurItem, files[i]);
1681 tp = (char *)strrchr(szCurItem, '\\');
1683 strncpy(tbuffer, szCurItem, code = tp - szCurItem + 1); /* the dir name */
1685 tp++; /* skip the slash */
1687 if (!IsPathInAfs(tbuffer)) {
1688 const char * nbname = NetbiosName();
1689 int len = strlen(nbname);
1691 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
1692 tbuffer[len+2] == '\\' &&
1693 tbuffer[len+3] == '\0' &&
1694 !strnicmp(nbname,&tbuffer[2],len))
1696 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
1700 fs_ExtractDriveLetter(szCurItem, tbuffer);
1701 strcat(tbuffer, ".");
1703 fs_StripDriveLetter(tp, tp, 0);
1706 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
1707 results.Add(GetMessageString(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, StripPath(files[i])));
1709 continue; /* skip */
1714 blob.in_size = strlen(tp)+1;
1716 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1719 results.Add(GetMessageString(IDS_ERROR, GetAfsError(errno, StripPath(files[i]))));
1721 results.Add(GetMessageString(IDS_DELETED));
1724 LoadString (str, IDS_REMOVE_MP);
1725 LoadString (str2, IDS_REMOVE_MP_COLUMN);
1726 CResultsDlg dlg(REMOVE_MOUNT_POINTS_HELP_ID);
1727 dlg.SetContents(str, str2, StripPath(files), results);
1733 BOOL GetVolumeInfo(CString strFile, CVolInfo& volInfo)
1736 struct ViceIoctl blob;
1737 struct VolumeStatus *status;
1740 HOURGLASS hourglass;
1742 volInfo.m_strFilePath = strFile;
1743 volInfo.m_strFileName = StripPath(strFile);
1746 volInfo.m_strName = "VolumeName";
1748 volInfo.m_nQuota = 20 * 1024 * 1024;
1749 volInfo.m_nNewQuota = volInfo.m_nQuota;
1750 volInfo.m_nUsed = volInfo.m_nQuota / 2;
1751 volInfo.m_nPartSize = 50 * 1024 * 1024;
1752 volInfo.m_nPartFree = 30 * 1024 * 1024;
1753 volInfo.m_nDup = -1;
1757 blob.out_size = MAXSIZE;
1761 code = pioctl(PCCHAR(strFile), VIOCGETVOLSTAT, &blob, 1);
1763 volInfo.m_strErrorMsg = GetAfsError(errno, strFile);
1767 status = (VolumeStatus *)space;
1768 name = (char *)status + sizeof(*status);
1770 volInfo.m_strName = name;
1771 volInfo.m_nID = status->Vid;
1772 volInfo.m_nQuota = status->MaxQuota;
1773 volInfo.m_nNewQuota = status->MaxQuota;
1774 volInfo.m_nUsed = status->BlocksInUse;
1775 volInfo.m_nPartSize = status->PartMaxBlocks;
1776 volInfo.m_nPartFree = status->PartBlocksAvail;
1777 volInfo.m_nDup = -1;
1782 BOOL SetVolInfo(CVolInfo& volInfo)
1785 struct ViceIoctl blob;
1786 struct VolumeStatus *status;
1789 HOURGLASS hourglass;
1791 blob.out_size = MAXSIZE;
1792 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1796 status = (VolumeStatus *)space;
1797 status->MinQuota = -1;
1798 status->MaxQuota = volInfo.m_nNewQuota;
1800 input = (char *)status + sizeof(*status);
1801 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1802 *(input++) = '\0'; // No offmsg
1803 *(input++) = '\0'; // No motd
1806 FILE *fp = OpenFile(szLogFileName, "a");
1808 fprintf(fp, "\nSetVolInfo() pioctl parms:\n");
1809 fprintf(fp, "\tpathp = %s\n\topcode = VIOCSETVOLSTAT (%d)\n\tblobp = %ld\n", PCCHAR(volInfo.m_strFilePath), VIOCSETVOLSTAT, &blob);
1810 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);
1811 fprintf(fp, "\t\t\tstatus->MinQuota = %ld\n", status->MinQuota);
1812 fprintf(fp, "\t\t\tstatus->MaxQuota = %ld\n", status->MaxQuota);
1813 fprintf(fp, "\t\t\tOther status fields aren't set\n");
1814 fprintf(fp, "\t\t\t3 nulls follow the VolumeStatus structure.\n");
1815 fprintf(fp, "\tfollow = 1\n");
1820 code = pioctl(PCCHAR(volInfo.m_strFilePath), VIOCSETVOLSTAT, &blob, 1);
1822 ShowMessageBox(IDS_SET_QUOTA_ERROR, MB_ICONERROR, IDS_SET_QUOTA_ERROR, GetAfsError(errno, volInfo.m_strName));
1829 int GetCellName(char *cellNamep, struct afsconf_cell *infop)
1831 strcpy(infop->name, cellNamep);
1835 BOOL CheckServers(const CString& strCellName, WHICH_CELLS nCellsToCheck, BOOL bFast)
1838 struct ViceIoctl blob;
1841 struct afsconf_cell info;
1842 struct chservinfo checkserv;
1844 HOURGLASS hourglass;
1846 memset(&checkserv, 0, sizeof(struct chservinfo));
1847 blob.in_size = sizeof(struct chservinfo);
1848 blob.in = (caddr_t)&checkserv;
1850 blob.out_size = MAXSIZE;
1852 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1854 if (nCellsToCheck == SPECIFIC_CELL) {
1856 GetCellName(PCCHAR(strCellName), &info);
1857 strcpy(checkserv.tbuffer,info.name);
1858 checkserv.tsize = strlen(info.name) + 1;
1860 if (nCellsToCheck != ALL_CELLS)
1862 strcpy(checkserv.tbuffer, "\0");
1863 checkserv.tsize = 0;
1866 temp |= 1; /* set fast flag */
1868 checkserv.magic = 0x12345678; /* XXX */
1869 checkserv.tflags = temp;
1870 checkserv.tinterval = -1; /* don't change current interval */
1872 code = pioctl(0, VIOCCKSERV, &blob, 1);
1874 ShowMessageBox(IDS_CHECK_SERVERS_ERROR, MB_ICONERROR, IDS_CHECK_SERVERS_ERROR, GetAfsError(errno, CString()));
1878 memcpy(&temp, space, sizeof(LONG));
1881 ShowMessageBox(IDS_ALL_SERVERS_RUNNING, MB_OK|MB_ICONINFORMATION, IDS_ALL_SERVERS_RUNNING);
1885 CStringArray servers;
1886 for (j = 0; j < MAXHOSTS; j++) {
1887 memcpy(&temp, space + j * sizeof(LONG), sizeof(LONG));
1891 char *name = hostutil_GetNameByINet(temp);
1895 CDownServersDlg dlg;
1896 dlg.SetServerNames(servers);
1902 BOOL GetTokenInfo(CStringArray& tokenInfo)
1906 time_t current_time;
1907 time_t tokenExpireTime;
1911 struct ktc_principal serviceName, clientName;
1912 struct ktc_token token;
1914 CString strTokenInfo;
1915 CString strUserName;
1916 CString strCellName;
1919 // tokenInfo.Add("");
1923 HOURGLASS hourglass;
1925 // printf("\nTokens held by the Cache Manager:\n\n");
1927 current_time = time(0);
1930 rc = ktc_ListTokens(cellNum, &cellNum, &serviceName);
1931 if (rc == KTC_NOENT) {
1933 // printf(" --End of list --\n");
1936 else if (rc == KTC_NOCM) {
1937 ShowMessageBox(IDS_GET_TOKENS_NO_AFS_SERVICE);
1938 // printf("AFS service may not have started\n");
1942 ShowMessageBox(IDS_GET_TOKENS_UNEXPECTED_ERROR, MB_ICONERROR, IDS_GET_TOKENS_UNEXPECTED_ERROR, rc);
1944 // printf("Unexpected error, code %d\n", rc);
1948 rc = ktc_GetToken(&serviceName, &token, sizeof(token), &clientName);
1950 ShowMessageBox(IDS_GET_TOKENS_UNEXPECTED_ERROR2, MB_ICONERROR, IDS_GET_TOKENS_UNEXPECTED_ERROR2,
1951 serviceName.name, serviceName.instance, serviceName.cell, rc);
1955 tokenExpireTime = token.endTime;
1957 strcpy(userName, clientName.name);
1958 if (clientName.instance[0] != 0) {
1959 strcat(userName, ".");
1960 strcat(userName, clientName.instance);
1963 BOOL bShowName = FALSE;
1965 if (userName[0] == '\0')
1966 ; //printf("Tokens");
1967 // AFS ID is not returned at this time.
1968 // else if (strncmp(userName, "AFS ID", 6) == 0)
1969 // printf("User's (%s) tokens", userName);
1970 // sscanf(userName, "(AFS ID %s)", szAfsID);
1971 else if (strncmp(userName, "Unix UID", 8) == 0)
1972 ; //printf("Tokens");
1974 strUserName = userName;
1975 // printf("User %s's tokens", userName);
1977 // printf(" for %s%s%s@%s ", serviceName.name, serviceName.instance[0] ? "." : "", serviceName.instance, serviceName.cell);
1978 strCellName = serviceName.cell;
1980 if (tokenExpireTime <= current_time)
1981 strExpir = "[>> Expired <<]";
1982 // printf("[>> Expired <<]\n");
1984 expireString = ctime(&tokenExpireTime);
1985 expireString += 4; /* Skip day of week */
1986 expireString[12] = '\0'; /* Omit secs & year */
1987 // printf("[Expires %s]\n", expireString);
1988 strExpir.Format("%s", expireString);
1991 strTokenInfo = strUserName + "\t" + strCellName + "\t" + strExpir + "\t" + strCellName;
1992 tokenInfo.Add(strTokenInfo);
1996 // printf("Press <Enter> or <Return> when finished: ");
2001 UINT MakeSymbolicLink(const char *strName, const char *strTarget)
2003 struct ViceIoctl blob;
2004 char space[MAXSIZE];
2006 char path[1024] = "";
2009 HOURGLASS hourglass;
2010 static char message[2048];
2012 strcpy(path, strName);
2013 parent = Parent(path);
2015 sprintf(message,"MakeSymbolicLink: name = %s target = %s parent = %s\n",strName,strTarget, parent);
2016 OutputDebugString(message);
2018 if ( IsFreelanceRoot(parent) && !IsAdmin() ) {
2019 ShowMessageBox(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, MB_ICONERROR, IDS_NOT_AFS_CLIENT_ADMIN_ERROR);
2023 LPTSTR lpsz = new TCHAR[strlen(strTarget)+1];
2024 _tcscpy(lpsz, strName);
2025 strcpy(space, strTarget);
2027 blob.in_size = 1 + strlen(space);
2030 code=pioctl(lpsz, VIOC_SYMLINK, &blob, 0);
2037 void ListSymbolicLinkPath(const char *strName,char *strPath,UINT nlenPath)
2039 ASSERT(nlenPath<MAX_PATH);
2040 struct ViceIoctl blob;
2041 char orig_name[MAX_PATH+1]; /*Original name, may be modified*/
2042 char true_name[MAX_PATH+1]; /*``True'' dirname (e.g., symlink target)*/
2043 char parent_dir[MAX_PATH+1]; /*Parent directory of true name*/
2044 char *last_component; /*Last component of true name*/
2047 HOURGLASS hourglass;
2049 strcpy(orig_name, strName);
2050 strcpy(true_name, orig_name);
2052 * Find rightmost slash, if any.
2054 last_component = (char *) strrchr(true_name, '\\');
2055 if (!last_component)
2056 last_component = (char *) strrchr(true_name, '/');
2057 if (last_component) {
2059 * Found it. Designate everything before it as the parent directory,
2060 * everything after it as the final component.
2062 strncpy(parent_dir, true_name, last_component - true_name + 1);
2063 parent_dir[last_component - true_name + 1] = 0;
2064 last_component++; /*Skip the slash*/
2066 if (!IsPathInAfs(parent_dir)) {
2067 const char * nbname = NetbiosName();
2068 int len = strlen(nbname);
2070 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
2071 parent_dir[len+2] == '\\' &&
2072 parent_dir[len+3] == '\0' &&
2073 !strnicmp(nbname,&parent_dir[2],len))
2075 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
2081 * No slash appears in the given file name. Set parent_dir to the current
2082 * directory, and the last component as the given name.
2084 fs_ExtractDriveLetter(true_name, parent_dir);
2085 strcat(parent_dir, ".");
2086 last_component = true_name;
2087 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
2089 blob.in = last_component;
2090 blob.in_size = strlen(last_component)+1;
2091 blob.out_size = MAXSIZE;
2093 memset(space, 0, MAXSIZE);
2094 if ((code = pioctl(parent_dir, VIOC_LISTSYMLINK, &blob, 1)))
2095 strcpy(space,"???");
2096 ASSERT(strlen(space)<MAX_PATH);
2097 strncpy(strPath,space,nlenPath);
2100 BOOL ListSymlink(CStringArray& files)
2103 struct ViceIoctl blob;
2105 char orig_name[1024]; /* Original name, may be modified */
2106 char true_name[1024]; /* ``True'' dirname (e.g., symlink target) */
2107 char parent_dir[1024]; /* Parent directory of true name */
2108 register char *last_component; /* Last component of true name */
2109 CStringArray symlinks;
2111 HOURGLASS hourglass;
2115 for (int i = 0; i < files.GetSize(); i++) {
2116 strcpy(orig_name, files[i]);
2117 strcpy(true_name, orig_name);
2120 * Find rightmost slash, if any.
2122 last_component = (char *)strrchr(true_name, '\\');
2123 if (last_component) {
2125 * Found it. Designate everything before it as the parent directory,
2126 * everything after it as the final component.
2128 strncpy(parent_dir, true_name, last_component - true_name + 1);
2129 parent_dir[last_component - true_name + 1] = 0;
2130 last_component++; /* Skip the slash */
2132 if (!IsPathInAfs(parent_dir)) {
2133 const char * nbname = NetbiosName();
2134 int len = strlen(nbname);
2136 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
2137 parent_dir[len+2] == '\\' &&
2138 parent_dir[len+3] == '\0' &&
2139 !strnicmp(nbname,&parent_dir[2],len))
2141 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
2147 * No slash appears in the given file name. Set parent_dir to the current
2148 * directory, and the last component as the given name.
2150 fs_ExtractDriveLetter(true_name, parent_dir);
2151 strcat(parent_dir, ".");
2152 last_component = true_name;
2153 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
2156 blob.in = last_component;
2157 blob.in_size = strlen(last_component) + 1;
2158 blob.out_size = MAXSIZE;
2160 memset(space, 0, MAXSIZE);
2162 code = pioctl(parent_dir, VIOC_LISTSYMLINK, &blob, 1);
2164 int nPos = strlen(space) - 1;
2165 if (space[nPos] == '.')
2167 symlinks.Add(ParseSymlink(StripPath(files[i]), space));
2170 if (errno == EINVAL)
2171 symlinks.Add(GetMessageString(IDS_NOT_SYMLINK_ERROR, StripPath(files[i])));
2173 symlinks.Add(GetMessageString(IDS_LIST_MOUNT_POINT_ERROR, GetAfsError(errno, StripPath(files[i]))));
2178 dlg.SetSymlinks(symlinks);