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 <afsconfig.h>
16 #include <afs/param.h>
26 #include "results_dlg.h"
27 #include "volume_inf.h"
28 #include "mount_points_dlg.h"
29 #include "symlinks_dlg.h"
30 #include "hourglass.h"
31 #include "down_servers_dlg.h"
34 #include <rx/rx_globals.h>
37 #include <afs/afsint.h>
38 #include <afs/afs_consts.h>
39 #include <afs/cellconfig.h>
40 #include <afs/vldbint.h>
41 #include <afs/volser.h>
43 #include <WINNT\afsreg.h>
48 #include <cm_scache.h>
52 #define STRSAFE_NO_DEPRECATE
56 * the NO_CALLER symbol is used to document functions
57 * that are present in this file but have no caller
62 #define PCCHAR(str) ((char *)(const char *)(str))
63 #define VL_NOENT (363524L)
66 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
67 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
69 #define MAXCELLCHARS 64
70 #define MAXHOSTCHARS 64
71 #define MAXHOSTSPERCELL 8
73 static char space[AFS_PIOCTL_MAXSIZE];
74 static char tspace[1024];
76 static struct ubik_client *uclient;
77 static int rxInitDone = 0;
78 static char pn[] = "fs";
80 // #define LOGGING_ON // Enable this to log certain pioctl calls
83 static char *szLogFileName = "afsguilog.txt";
87 class CStringUtf8 : public CStringA
90 CStringUtf8(const CStringW& csw) : CStringA()
95 CStringUtf8(const char * cp) : CStringA(cp) {}
97 CStringUtf8() :CStringA() {}
99 void SetString(const CStringW& csw)
104 rv = WideCharToMultiByte(CP_UTF8, 0, csw, -1,
105 buffer, sizeof(buffer),
109 CStringA::SetString(buffer);
111 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
114 cb_req = WideCharToMultiByte(CP_UTF8, 0, csw, -1, NULL, 0, NULL, FALSE);
118 WideCharToMultiByte(CP_UTF8, 0, csw, -1, CStringA::GetBuffer(cb_req), cb_req, NULL, FALSE);
119 CStringA::ReleaseBuffer();
129 static CString _Utf8ToCString(const char * ustr)
134 cch = MultiByteToWideChar(CP_UTF8, 0, ustr, -1, NULL, 0);
141 cch = MultiByteToWideChar(CP_UTF8, 0, ustr, -1, cs.GetBuffer(cch), cch);
149 pioctl_T(const CString& path, long opcode, struct ViceIoctl * blob, int follow)
151 CStringUtf8 upath(path);
153 return pioctl_utf8(PCCHAR(upath), opcode, blob, follow);
156 #define Utf8ToCString(cs) CStringUtf8::_Utf8ToCString(cs)
158 #define pioctl_T(path, op, vblob, follow) pioctl(PCCHAR(path), op, vblob, follow)
159 #define Utf8ToCString(cs) (cs)
163 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
167 code = ugen_ClientInit(noAuthFlag, (char *)AFSDIR_CLIENT_ETC_DIRPATH,
168 info->name, 0, &uclient,
169 NULL, pn, rxkad_clear,
170 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
171 0, 0, USER_SERVICE_ID);
177 OpenFile(char *file, char *rwp)
184 code = GetWindowsDirectoryA(wdir, sizeof(wdir));
185 if (code == 0 || code > sizeof(wdir))
188 /* add trailing backslash, if required */
190 if (wdir[tlen - 1] != '\\')
195 fp = fopen(wdir, rwp);
200 CString StripPath(CString& strPath)
202 int nIndex = strPath.ReverseFind('\\');
204 CString strFile = strPath.Mid(nIndex + 1);
205 if (strFile.IsEmpty())
212 StripPath(CStringArray& files)
214 for (int i = 0; i < files.GetSize(); i++)
215 files[i] = StripPath(files[i]);
221 Flush(const CStringArray& files)
224 struct ViceIoctl blob;
229 for (int i = 0; i < files.GetSize(); i++) {
230 blob.in_size = blob.out_size = 0;
232 code = pioctl_T(files[i], VIOCFLUSH, &blob, 0);
236 ShowMessageBox(IDS_FLUSH_FAILED, MB_ICONERROR, IDS_FLUSH_FAILED, files[i]);
238 ShowMessageBox(IDS_FLUSH_ERROR, MB_ICONERROR, IDS_FLUSH_ERROR, files[i], strerror(errno));
243 ShowMessageBox(IDS_FLUSH_OK, MB_ICONINFORMATION, IDS_FLUSH_OK);
247 FlushVolume(const CStringArray& files)
250 struct ViceIoctl blob;
255 for (int i = 0; i < files.GetSize(); i++) {
256 blob.in_size = blob.out_size = 0;
258 code = pioctl_T(files[i], VIOC_FLUSHVOLUME, &blob, 0);
261 ShowMessageBox(IDS_FLUSH_VOLUME_ERROR, MB_ICONERROR, IDS_FLUSH_VOLUME_ERROR, files[i], strerror(errno));
266 ShowMessageBox(IDS_FLUSH_VOLUME_OK, MB_ICONINFORMATION, IDS_FLUSH_VOLUME_OK);
270 WhichCell(CStringArray& files)
273 struct ViceIoctl blob;
278 CStringArray results;
284 for (int i = 0; i < files.GetSize(); i++) {
286 blob.out_size = AFS_PIOCTL_MAXSIZE;
289 code = pioctl_T(files[i], VIOC_FILE_CELL_NAME, &blob, 1);
291 if (code == ENOENT) {
292 LoadString (str, IDS_CANT_GET_CELL);
295 results.Add(GetAfsError(errno));
297 space[AFS_PIOCTL_MAXSIZE - 1] = '\0';
298 results.Add(Utf8ToCString(space));
302 LoadString (str, IDS_SHOW_CELL);
303 LoadString (str2, IDS_SHOW_CELL_COLUMN);
304 CResultsDlg dlg(SHOW_CELL_HELP_ID);
305 dlg.SetContents(str, str2, StripPath(files), results);
313 struct ViceIoctl blob;
318 blob.in = (char *) 0;
319 blob.out_size = AFS_PIOCTL_MAXSIZE;
322 code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1);
325 * Cell name is left in 'space' as side effect.
326 * At present no callers of this function.
334 struct ViceIoctl blob;
338 code = pioctl(0, VIOCCKBACK, &blob, 1);
340 ShowMessageBox(IDS_CHECK_VOLUMES_ERROR, MB_ICONERROR, IDS_CHECK_VOLUMES_ERROR, GetAfsError(errno, CString()));
344 ShowMessageBox(IDS_CHECK_VOLUMES_OK, MB_OK|MB_ICONINFORMATION, IDS_CHECK_VOLUMES_OK);
350 SetCacheSizeCmd(LONG nNewCacheSize)
353 struct ViceIoctl blob;
357 blob.in = (char *) &nNewCacheSize;
358 blob.in_size = sizeof(LONG);
361 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
363 /* error handling? */
367 WhereIs(CStringArray& files)
370 struct ViceIoctl blob;
371 CStringArray servers;
372 CStringArray resultFiles;
378 for (int i = 0; i < files.GetSize(); i++) {
379 blob.out_size = AFS_PIOCTL_MAXSIZE;
382 memset(space, 0, sizeof(space));
384 code = pioctl_T(files[i], VIOCWHEREIS, &blob, 1);
386 resultFiles.Add(StripPath(files[i]));
387 servers.Add(GetAfsError(errno));
391 LONG *hosts = (LONG *)space;
395 for (int j = 0; j < AFS_MAXHOSTS; j++) {
398 char *hostName = hostutil_GetNameByINet(hosts[j]);
400 resultFiles.Add(StripPath(files[i]));
403 resultFiles.Add(" ");
404 servers.Add(hostName);
408 LoadString (str, IDS_SHOW_FS);
409 LoadString (str2, IDS_SHOW_FS_COLUMN);
410 CResultsDlg dlg(SHOW_FILE_SERVERS_HELP_ID);
411 dlg.SetContents(str, str2, resultFiles, servers);
416 CMtoUNIXerror(int cm_code)
419 case CM_ERROR_TIMEDOUT:
421 case CM_ERROR_NOACCESS:
423 case CM_ERROR_NOSUCHFILE:
429 case CM_ERROR_EXISTS:
431 case CM_ERROR_CROSSDEVLINK:
433 case CM_ERROR_NOTDIR:
437 case CM_ERROR_READONLY:
439 case CM_ERROR_WOULDBLOCK:
441 case CM_ERROR_NOSUCHCELL:
442 return ESRCH; /* hack */
443 case CM_ERROR_NOSUCHVOLUME:
444 return EPIPE; /* hack */
445 case CM_ERROR_NOMORETOKENS:
446 return EDOM; /* hack */
447 case CM_ERROR_TOOMANYBUFS:
448 return EFBIG; /* hack */
450 if (cm_code > 0 && cm_code < EILSEQ)
458 GetAfsError(int code, const TCHAR *filename)
462 code = CMtoUNIXerror(code);
464 if (code == EINVAL) {
466 strMsg.Format(_T("Invalid argument; it is possible that the file is not in AFS"));
468 strMsg.Format(_T("Invalid argument"));
469 } else if (code == ENOENT) {
471 strMsg.Format(_T("The file does not exist"));
473 strMsg.Format(_T("No such file returned"));
474 } else if (code == EROFS) {
475 strMsg.Format(_T("You can not change a backup or readonly volume"));
476 } else if (code == EACCES || code == EPERM) {
477 strMsg.Format(_T("You do not have the required rights to do this operation"));
478 } else if (code == ENODEV) {
479 strMsg.Format(_T("AFS service may not have started"));
480 } else if (code == ESRCH) {
481 strMsg.Format(_T("Cell name not recognized"));
482 } else if (code == ETIMEDOUT) {
483 strMsg.Format(_T("Connection timed out"));
484 } else if (code == EPIPE) {
485 strMsg.Format(_T("Volume name or ID not recognized"));
487 strMsg.Format(_T("Error 0x%x occurred"), code);
495 foldcmp (char *a, char *b)
501 if (t >= 'A' && t <= 'Z') t += 0x20;
502 if (u >= 'A' && u <= 'Z') u += 0x20;
503 if (t != u) return 1;
504 if (t == 0) return 0;
509 GetRightsString(LONG arights, int dfs)
514 if (arights & PRSFS_READ) str += _T("r");
515 if (arights & PRSFS_LOOKUP) str += _T("l");
516 if (arights & PRSFS_INSERT) str += _T("i");
517 if (arights & PRSFS_DELETE) str += _T("d");
518 if (arights & PRSFS_WRITE) str += _T("w");
519 if (arights & PRSFS_LOCK) str += _T("k");
520 if (arights & PRSFS_ADMINISTER) str += _T("a");
524 if (arights & DFS_READ) str += _T("r"); else str += _T("-");
525 if (arights & DFS_WRITE) str += _T("w"); else printf(_T("-"));
526 if (arights & DFS_EXECUTE) str += _T("x"); else printf(_T("-"));
527 if (arights & DFS_CONTROL) str += _T("c"); else printf(_T("-"));
528 if (arights & DFS_INSERT) str += _T("i"); else printf(_T("-"));
529 if (arights & DFS_DELETE) str += _T("d"); else printf(_T("-"));
530 if (arights & (DFS_USRALL)) str += _T("+");
538 EmptyAcl(const CString& strCellName)
541 CStringUtf8 ustrCell(strCellName);
543 tp = (struct Acl *)malloc(sizeof (struct Acl));
544 tp->nplus = tp->nminus = 0;
545 tp->pluslist = tp->minuslist = 0;
547 StringCbCopyA(tp->cell, sizeof(tp->cell), ustrCell);
553 CleanACL(CStringArray& names)
557 struct ViceIoctl blob;
560 ShowMessageBox(IDS_CLEANACL_MSG, MB_OK|MB_ICONINFORMATION, IDS_CLEANACL_MSG);
564 for (int i = 0; i < names.GetSize(); i++) {
565 blob.out_size = AFS_PIOCTL_MAXSIZE;
569 code = pioctl_T(names[i], VIOCGETAL, &blob, 1);
571 ShowMessageBox(IDS_CLEANACL_ERROR, MB_ICONERROR, 0, names[i], GetAfsError(errno));
575 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
577 ShowMessageBox(IDS_INVALID_ACL_DATA, MB_ICONERROR, IDS_INVALID_ACL_DATA);
581 ShowMessageBox(IDS_CLEANACL_NOT_SUPPORTED, MB_ICONERROR, IDS_CLEANACL_NOT_SUPPORTED, names[i]);
585 changes = CleanAcl(ta, NULL);
589 /* now set the acl */
590 blob.in = AclToString(ta);
591 blob.in_size = strlen((char *)blob.in) + 1;
594 code = pioctl_T(names[i], VIOCSETAL, &blob, 1);
596 if (errno == EINVAL) {
597 ShowMessageBox(IDS_CLEANACL_INVALID_ARG, MB_ICONERROR, IDS_CLEANACL_INVALID_ARG, names[i]);
601 ShowMessageBox(IDS_CLEANACL_ERROR, MB_ICONERROR, 0, names[i], GetAfsError(errno));
608 // Derived from fs.c's ListAclCmd
610 GetRights(const CString& strDir, CStringArray& strNormal, CStringArray& strNegative)
614 struct ViceIoctl blob;
616 int idf = 0; //getidf(as, parm_listacl_id);
620 blob.out_size = AFS_PIOCTL_MAXSIZE;
622 blob.in = blob.out = space;
624 code = pioctl_T(strDir, VIOCGETAL, &blob, 1);
626 ShowMessageBox(IDS_GETRIGHTS_ERROR, MB_ICONERROR, IDS_GETRIGHTS_ERROR, strDir, GetAfsError(errno));
630 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
632 ShowMessageBox(IDS_INVALID_ACL_DATA, MB_ICONERROR, IDS_INVALID_ACL_DATA);
636 ShowMessageBox(IDS_DFSACL_ERROR, MB_ICONERROR, IDS_DFSACL_ERROR);
641 // printf(" Default cell = %s\n", ta->cell);
646 for (te = ta->pluslist; te; te = te->next) {
647 strNormal.Add(te->name);
648 strNormal.Add(GetRightsString(te->rights, ta->dfs));
652 if (ta->nminus > 0) {
653 for (te = ta->minuslist; te; te = te->next) {
654 strNegative.Add(te->name);
655 strNegative.Add(GetRightsString(te->rights, ta->dfs));
663 FindList(struct AclEntry *pCurEntry, const char *entryName)
666 if (!foldcmp(pCurEntry->name, PCCHAR(entryName)))
668 pCurEntry = pCurEntry->next;
675 ChangeList(struct Acl *pAcl, BYTE bNormalRights, const CString & entryName, LONG nEntryRights)
680 struct AclEntry *pEntry;
681 CStringUtf8 uEntryName(entryName);
685 pEntry = (bNormalRights ? pAcl->pluslist : pAcl->minuslist);
686 pEntry = FindList(pEntry, uEntryName);
688 /* Found the item already in the list. */
690 pEntry->rights = nEntryRights;
692 pAcl->nplus -= PruneList(&pAcl->pluslist, pAcl->dfs);
694 pAcl->nminus -= PruneList(&pAcl->minuslist, pAcl->dfs);
698 /* Otherwise we make a new item and plug in the new data. */
699 pEntry = (struct AclEntry *) malloc(sizeof (struct AclEntry));
702 strcpy(pEntry->name, uEntryName);
703 pEntry->rights = nEntryRights;
706 pEntry->next = pAcl->pluslist;
707 pAcl->pluslist = pEntry;
709 if (nEntryRights == 0 || nEntryRights == -1)
710 pAcl->nplus -= PruneList(&pAcl->pluslist, pAcl->dfs);
713 pEntry->next = pAcl->minuslist;
714 pAcl->minuslist = pEntry;
716 if (nEntryRights == 0)
717 pAcl->nminus -= PruneList(&pAcl->minuslist, pAcl->dfs);
722 Convert(const CString& strRights, int dfs, enum rtype *rtypep)
727 *rtypep = add; /* add rights, by default */
729 if (strRights == _T("read"))
730 return PRSFS_READ | PRSFS_LOOKUP;
731 if (strRights == _T("write"))
732 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK;
733 if (strRights == _T("mail"))
734 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
735 if (strRights == _T("all"))
736 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
738 if (strRights == _T("none")) {
739 *rtypep = destroy; /* Remove entire entry */
743 len = strRights.GetLength();
746 for (i = 0; i < len; i++) {
747 TCHAR c = strRights[i];
748 if (c == _T('r')) mode |= PRSFS_READ;
749 else if (c == _T('l')) mode |= PRSFS_LOOKUP;
750 else if (c == _T('i')) mode |= PRSFS_INSERT;
751 else if (c == _T('d')) mode |= PRSFS_DELETE;
752 else if (c == _T('w')) mode |= PRSFS_WRITE;
753 else if (c == _T('k')) mode |= PRSFS_LOCK;
754 else if (c == _T('a')) mode |= PRSFS_ADMINISTER;
756 fprintf(stderr, "illegal rights character '%c'.\n", c);
764 SaveACL(const CString& strCellName, const CString& strDir, const CStringArray& normal, const CStringArray& negative)
767 struct ViceIoctl blob;
775 pAcl = EmptyAcl(strCellName);
777 // Set its normal rights
779 for (i = 0; i < normal.GetSize(); i += 2) {
780 rights = Convert(normal[i + 1], 0, &rtype);
781 ChangeList(pAcl, TRUE, normal[i], rights);
784 // Set its negative rights
785 for (i = 0; i < negative.GetSize(); i += 2) {
786 rights = Convert(negative[i + 1], 0, &rtype);
787 ChangeList(pAcl, FALSE, negative[i], rights);
791 blob.in = AclToString(pAcl);
793 blob.in_size = 1 + strlen((const char *)blob.in);
795 code = pioctl_T(strDir, VIOCSETAL, &blob, 1);
798 ShowMessageBox(IDS_SAVE_ACL_EINVAL_ERROR, MB_ICONERROR, IDS_SAVE_ACL_EINVAL_ERROR, strDir);
800 ShowMessageBox(IDS_SAVE_ACL_ERROR, MB_ICONERROR, IDS_SAVE_ACL_ERROR, strDir, GetAfsError(errno, strDir));
809 CopyACL(const CString& strToDir, const CStringArray& normal, const CStringArray& negative, BOOL bClear)
812 struct ViceIoctl blob;
814 int idf = 0; // getidf(as, parm_copyacl_id);
818 // Get ACL to copy to
819 blob.out_size = AFS_PIOCTL_MAXSIZE;
821 blob.in = blob.out = space;
823 code = pioctl_T(strToDir, VIOCGETAL, &blob, 1);
825 ShowMessageBox(IDS_ACL_READ_ERROR, MB_ICONERROR, IDS_ACL_READ_ERROR, strToDir, GetAfsError(errno, strToDir));
830 pToAcl = EmptyAcl(space);
832 pToAcl = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
834 if (pToAcl == NULL) {
835 ShowMessageBox(IDS_INVALID_ACL_DATA, MB_ICONERROR, IDS_INVALID_ACL_DATA);
839 CleanAcl(pToAcl, NULL);
842 ShowMessageBox(IDS_NO_DFS_COPY_ACL, MB_ICONERROR, IDS_NO_DFS_COPY_ACL, strToDir);
851 for (i = 0; i < normal.GetSize(); i += 2) {
852 LONG rights = Convert(normal[i + 1], 0, &rtype);
853 ChangeList(pToAcl, TRUE, normal[i], rights);
856 // Set negative rights
857 for (i = 0; i < negative.GetSize(); i += 2) {
858 LONG rights = Convert(negative[i + 1], 0, &rtype);
859 ChangeList(pToAcl, FALSE, normal[i], rights);
863 blob.in = AclToString(pToAcl);
865 blob.in_size = 1 + strlen((char *)blob.in);
867 code = pioctl_T(strToDir, VIOCSETAL, &blob, 1);
871 ShowMessageBox(IDS_COPY_ACL_EINVAL_ERROR, MB_ICONERROR, IDS_COPY_ACL_EINVAL_ERROR, strToDir);
873 ShowMessageBox(IDS_COPY_ACL_ERROR, MB_ICONERROR, IDS_COPY_ACL_ERROR, strToDir, GetAfsError(errno, strToDir));
879 ShowMessageBox(IDS_COPY_ACL_OK, MB_OK|MB_ICONINFORMATION, IDS_COPY_ACL_OK);
885 ParseMountPoint(const CString strFile, CString strMountPoint)
890 CString strMountPointInfo;
892 if (strMountPoint[0] == '#')
894 else if (strMountPoint[0] == '%')
895 strType = "Read/Write";
897 int nColon = strMountPoint.Find(':');
899 strCell = strMountPoint.Mid(1, nColon - 1);
900 strVolume = strMountPoint.Mid(nColon + 1);
902 strVolume = strMountPoint.Mid(1);
904 strMountPointInfo = strFile + _T("\t") + strVolume + _T("\t") + strCell + _T("\t") + strType;
906 return strMountPointInfo;
910 ParseSymlink(const CString strFile, CString strSymlink)
912 CString strSymlinkInfo;
914 strSymlinkInfo = strFile + _T("\t") + strSymlink;
916 return strSymlinkInfo;
920 IsPathInAfs(const CString & strPath)
922 struct ViceIoctl blob;
923 cm_ioctlQueryOptions_t options;
929 memset(&options, 0, sizeof(options));
930 options.size = sizeof(options);
931 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
933 blob.in_size = options.size; /* no variable length data */
935 blob.out_size = sizeof(cm_fid_t);
936 blob.out = (char *) &fid;
938 code = pioctl_T(strPath, VIOCGETFID, &blob, 1);
940 if ((errno == EINVAL) || (errno == ENOENT))
947 IsFreelanceRoot(const CString& apath)
949 struct ViceIoctl blob;
953 blob.out_size = AFS_PIOCTL_MAXSIZE;
956 code = pioctl_T(apath, VIOC_FILE_CELL_NAME, &blob, 1);
958 return !strcmp("Freelance.Local.Root",space);
959 return 1; /* assume it is because it is more restrictive that way */
965 static char buffer[1024] = "AFS";
971 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
972 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
973 if (code == ERROR_SUCCESS) {
974 dummyLen = sizeof(buffer);
975 code = RegQueryValueExA(parmKey, "NetbiosName", NULL, NULL,
976 (LPBYTE)buffer, &dummyLen);
977 RegCloseKey (parmKey);
979 strcpy(buffer, "AFS");
985 FixNetbiosPath(CString& path)
987 if (!IsPathInAfs(path)) {
989 const char * nbname = NetbiosName();
992 nbroot.Format(_T("\\\\%S\\"), nbname);
994 nbroot.Format(_T("\\\\%s\\"), nbname);
997 if (nbroot.CompareNoCase(path) == 0) {
998 path.Append(_T("all\\"));
1003 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
1008 static BOOL fAdmin = FALSE;
1009 static BOOL fTested = FALSE;
1013 /* Obtain the SID for the AFS client admin group. If the group does
1014 * not exist, then assume we have AFS client admin privileges.
1016 PSID psidAdmin = NULL;
1017 DWORD dwSize, dwSize2;
1018 TCHAR pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
1019 TCHAR *pszRefDomain = NULL;
1020 SID_NAME_USE snu = SidTypeGroup;
1022 dwSize = sizeof(pszAdminGroup);
1024 if (!GetComputerName(pszAdminGroup, &dwSize)) {
1025 /* Can't get computer name. We return false in this case.
1026 Retain fAdmin and fTested. This shouldn't happen.*/
1033 lstrcat(pszAdminGroup, _T("\\"));
1034 lstrcat(pszAdminGroup, _T(AFSCLIENT_ADMIN_GROUPNAME));
1036 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
1037 /* that should always fail. */
1039 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
1040 /* if we can't find the group, then we allow the operation */
1045 if (dwSize == 0 || dwSize2 == 0) {
1051 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
1052 pszRefDomain = (TCHAR *)malloc(dwSize2);
1054 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
1055 /* We can't lookup the group now even though we looked it up earlier.
1056 Could this happen? */
1059 /* Then open our current ProcessToken */
1062 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
1065 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
1066 /* We'll have to allocate a chunk of memory to store the list of
1067 * groups to which this user belongs; find out how much memory
1071 PTOKEN_GROUPS pGroups;
1073 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
1075 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
1077 /* Allocate that buffer, and read in the list of groups. */
1078 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
1080 /* Look through the list of group SIDs and see if any of them
1081 * matches the AFS Client Admin group SID.
1084 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
1086 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
1096 /* if do not have permission because we were not explicitly listed
1097 * in the Admin Client Group let's see if we are the SYSTEM account
1100 PTOKEN_USER pTokenUser;
1101 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
1102 PSID pSidLocalSystem = 0;
1105 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
1107 pTokenUser = (PTOKEN_USER)malloc(dwSize);
1109 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
1110 gle = GetLastError();
1112 if (AllocateAndInitializeSid( &SIDAuth, 1,
1113 SECURITY_LOCAL_SYSTEM_RID,
1114 0, 0, 0, 0, 0, 0, 0,
1117 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
1121 FreeSid(pSidLocalSystem);
1140 Parent(const CString& path)
1142 int last_slash = path.ReverseFind(_T('\\'));
1144 if (last_slash != -1) {
1145 CString ret = path.Left(last_slash + 1);
1148 if (path.GetLength() >= 2 && path[1] == _T(':')) {
1149 CString ret = path.Left(2);
1150 ret.AppendChar(_T('.'));
1153 CString ret = _T(".");
1160 LastComponent(const CString& path)
1162 int last_slash = path.ReverseFind(_T('\\'));
1164 if (last_slash != -1) {
1165 CString ret = path.Mid(last_slash + 1);
1168 if (path.GetLength() >= 2 && path[1] == _T(':')) {
1169 CString ret = path.Mid(2);
1179 GetCell(const CString & path)
1181 char cellname[MAXCELLCHARS];
1183 struct ViceIoctl blob;
1186 blob.out_size = sizeof(cellname);
1187 blob.out = cellname;
1189 code = pioctl_T(path, VIOC_FILE_CELL_NAME, &blob, 1);
1196 return Utf8ToCString(cellname);
1202 ListMount(CStringArray& files)
1205 struct ViceIoctl blob;
1208 CString parent_dir; /* Parent directory of true name */
1209 CStringUtf8 last_component; /* Last component of true name */
1211 CStringArray mountPoints;
1213 HOURGLASS hourglass;
1217 for (int i = 0; i < files.GetSize(); i++) {
1218 int last_slash = files[i].ReverseFind(_T('\\'));
1220 if (last_slash != -1) {
1221 last_component.SetString( files[i].Mid(last_slash + 1) );
1222 parent_dir.SetString( files[i].Left(last_slash + 1) );
1223 FixNetbiosPath(parent_dir);
1225 // The path is of the form "C:foo" or just "foo". If
1226 // there is a drive, then use the current directory of
1227 // that drive. Otherwise we just use '.'.
1229 if (files[i].GetLength() >= 2 && files[i][1] == _T(':')) {
1230 parent_dir.Format(_T("%c:."), files[i][0]);
1231 last_component.SetString( files[i].Mid(2) );
1233 parent_dir.SetString( _T("."));
1234 last_component.SetString( files[i] );
1238 blob.in_size = last_component.GetLength() + 1;
1239 blob.in = last_component.GetBuffer();
1240 blob.out_size = AFS_PIOCTL_MAXSIZE;
1242 memset(space, 0, AFS_PIOCTL_MAXSIZE);
1244 code = pioctl_T(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1246 last_component.ReleaseBuffer();
1250 space[AFS_PIOCTL_MAXSIZE - 1] = '\0';
1251 nPos = strlen(space) - 1;
1252 if (space[nPos] == '.')
1254 mountPoints.Add(ParseMountPoint(StripPath(files[i]), Utf8ToCString(space)));
1257 if (errno == EINVAL)
1258 mountPoints.Add(GetMessageString(IDS_NOT_MOUNT_POINT_ERROR, StripPath(files[i])));
1260 mountPoints.Add(GetMessageString(IDS_LIST_MOUNT_POINT_ERROR, GetAfsError(errno, StripPath(files[i]))));
1264 CMountPointsDlg dlg;
1265 dlg.SetMountPoints(mountPoints);
1272 MakeMount(const CString& strDir,
1273 const CString& strVolName,
1274 const CString& strInCellName,
1278 struct ViceIoctl blob;
1279 HOURGLASS hourglass;
1281 ASSERT(strVolName.GetLength() < 64);
1283 CString strParent = Parent(strDir);
1285 FixNetbiosPath(strParent);
1286 if (!IsPathInAfs(strParent)) {
1287 ShowMessageBox(IDS_MAKE_MP_NOT_AFS_ERROR, MB_ICONERROR, IDS_MAKE_MP_NOT_AFS_ERROR);
1291 CString strPath = strParent + LastComponent(strDir);
1293 if ( IsFreelanceRoot(strParent) && !IsAdmin() ) {
1294 ShowMessageBox(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, MB_ICONERROR,
1295 IDS_NOT_AFS_CLIENT_ADMIN_ERROR);
1301 strMount.Format(_T("%c%s%s%s."),
1302 ((bRW)?_T('%'):_T('#')),
1304 ((strInCellName.IsEmpty())?_T(""):_T(":")),
1307 CStringUtf8 ustrMount(strMount);
1310 blob.in_size = ustrMount.GetLength() + 1;
1311 blob.in = ustrMount.GetBuffer();
1314 code = pioctl_T(strPath, VIOC_AFS_CREATE_MT_PT, &blob, 0);
1316 ustrMount.ReleaseBuffer();
1319 ShowMessageBox(IDS_MOUNT_POINT_ERROR, MB_ICONERROR, IDS_MOUNT_POINT_ERROR, GetAfsError(errno, strDir));
1327 RemoveSymlink(const CString& strName)
1331 struct ViceIoctl blob;
1332 char lsbuffer[1024];
1334 HOURGLASS hourglass;
1336 CString strParent = Parent(strName);
1337 CStringUtf8 ustrLast(LastComponent(strName));
1338 FixNetbiosPath(strParent);
1340 if ( IsFreelanceRoot(strParent) && !IsAdmin() ) {
1341 ShowMessageBox(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, MB_ICONERROR, IDS_NOT_AFS_CLIENT_ADMIN_ERROR);
1345 blob.in_size = ustrLast.GetLength() + 1;
1346 blob.in = ustrLast.GetBuffer();
1347 blob.out = lsbuffer;
1348 blob.out_size = sizeof(lsbuffer);
1349 code = pioctl_T(strParent, VIOC_LISTSYMLINK, &blob, 0);
1350 ustrLast.ReleaseBuffer();
1354 blob.in_size = ustrLast.GetLength() + 1;
1355 blob.in = ustrLast.GetBuffer();
1357 code = pioctl_T(strParent, VIOC_DELSYMLINK, &blob, 0);
1359 ustrLast.ReleaseBuffer();
1365 IsSymlink(const CString& strName)
1367 struct ViceIoctl blob;
1370 HOURGLASS hourglass;
1372 CStringUtf8 ustrLast(LastComponent(strName));
1373 CString strParent = Parent(strName);
1375 FixNetbiosPath(strParent);
1377 blob.in_size = ustrLast.GetLength() + 1;
1378 blob.in = ustrLast.GetBuffer();
1379 blob.out_size = AFS_PIOCTL_MAXSIZE;
1381 memset(space, 0, AFS_PIOCTL_MAXSIZE);
1383 code = pioctl_T(strParent, VIOC_LISTSYMLINK, &blob, 1);
1385 ustrLast.ReleaseBuffer();
1392 IsMountPoint(const CString& path)
1395 struct ViceIoctl blob;
1396 char lsbuffer[1024];
1398 HOURGLASS hourglass;
1400 CString parent = Parent(path);
1401 FixNetbiosPath(parent);
1403 CStringUtf8 mountpoint(LastComponent(path));
1405 blob.in_size = mountpoint.GetLength() + 1;
1406 blob.in = mountpoint.GetBuffer();
1407 blob.out = lsbuffer;
1408 blob.out_size = sizeof(lsbuffer);
1410 code = pioctl_T(parent, VIOC_AFS_STAT_MT_PT, &blob, 0);
1412 mountpoint.ReleaseBuffer();
1419 * Delete AFS mount points. Variables are used as follows:
1420 * tbuffer: Set to point to the null-terminated directory name of the mount point
1421 * (or ``.'' if none is provided)
1422 * tp: Set to point to the actual name of the mount point to nuke.
1425 RemoveMount(CStringArray& files)
1428 struct ViceIoctl blob;
1430 CStringArray results;
1434 HOURGLASS hourglass;
1436 for (int i = 0; i < files.GetSize(); i++) {
1437 if (!IsMountPoint(files[i])) {
1439 if (errno == EINVAL)
1440 results.Add(GetMessageString(IDS_NOT_MOUNT_POINT_ERROR, StripPath(files[i])));
1442 results.Add(GetMessageString(IDS_ERROR, GetAfsError(errno, StripPath(files[i]))));
1443 continue; // don't bother trying
1446 CString parent = Parent(files[i]);
1447 CStringUtf8 mountpoint(LastComponent(files[i]));
1448 FixNetbiosPath(parent);
1450 if ( IsFreelanceRoot(parent) && !IsAdmin() ) {
1451 results.Add(GetMessageString(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, StripPath(files[i])));
1453 continue; /* skip */
1457 blob.in_size = mountpoint.GetLength() + 1;
1458 blob.in = mountpoint.GetBuffer();
1460 code = pioctl_T(parent, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1462 mountpoint.ReleaseBuffer();
1466 results.Add(GetMessageString(IDS_ERROR, GetAfsError(errno, StripPath(files[i]))));
1468 results.Add(GetMessageString(IDS_DELETED));
1471 LoadString (str, IDS_REMOVE_MP);
1472 LoadString (str2, IDS_REMOVE_MP_COLUMN);
1473 CResultsDlg dlg(REMOVE_MOUNT_POINTS_HELP_ID);
1474 dlg.SetContents(str, str2, StripPath(files), results);
1481 GetVolumeInfo(CString strFile, CVolInfo& volInfo)
1484 struct ViceIoctl blob;
1485 struct VolumeStatus *status;
1488 HOURGLASS hourglass;
1490 volInfo.m_strFilePath = strFile;
1491 volInfo.m_strFileName = StripPath(strFile);
1494 volInfo.m_strName = "VolumeName";
1496 volInfo.m_nQuota = 20 * 1024 * 1024;
1497 volInfo.m_nNewQuota = volInfo.m_nQuota;
1498 volInfo.m_nUsed = volInfo.m_nQuota / 2;
1499 volInfo.m_nPartSize = 50 * 1024 * 1024;
1500 volInfo.m_nPartFree = 30 * 1024 * 1024;
1501 volInfo.m_nDup = -1;
1505 blob.out_size = AFS_PIOCTL_MAXSIZE;
1509 code = pioctl_T(strFile, VIOCGETVOLSTAT, &blob, 1);
1510 if (code || blob.out_size < sizeof(*status)) {
1511 volInfo.m_strErrorMsg = GetAfsError(errno, strFile);
1515 status = (VolumeStatus *)space;
1516 name = (char *)status + sizeof(*status);
1518 volInfo.m_strName = Utf8ToCString(name);
1519 volInfo.m_nID = status->Vid;
1520 volInfo.m_nQuota = status->MaxQuota;
1521 volInfo.m_nNewQuota = status->MaxQuota;
1522 volInfo.m_nUsed = status->BlocksInUse;
1523 volInfo.m_nPartSize = status->PartMaxBlocks;
1524 volInfo.m_nPartFree = status->PartBlocksAvail;
1525 volInfo.m_nDup = -1;
1531 SetVolInfo(CVolInfo& volInfo)
1534 struct ViceIoctl blob;
1535 struct VolumeStatus *status;
1538 HOURGLASS hourglass;
1540 blob.out_size = AFS_PIOCTL_MAXSIZE;
1541 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1545 status = (VolumeStatus *)space;
1546 status->MinQuota = -1;
1547 status->MaxQuota = volInfo.m_nNewQuota;
1549 input = (char *)status + sizeof(*status);
1550 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1551 *(input++) = '\0'; // No offmsg
1552 *(input++) = '\0'; // No motd
1555 FILE *fp = OpenFile(szLogFileName, "a");
1557 fprintf(fp, "\nSetVolInfo() pioctl parms:\n");
1558 fprintf(fp, "\tpathp = %s\n\topcode = VIOCSETVOLSTAT (%d)\n\tblobp = %ld\n", PCCHAR(volInfo.m_strFilePath), VIOCSETVOLSTAT, &blob);
1559 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);
1560 fprintf(fp, "\t\t\tstatus->MinQuota = %ld\n", status->MinQuota);
1561 fprintf(fp, "\t\t\tstatus->MaxQuota = %ld\n", status->MaxQuota);
1562 fprintf(fp, "\t\t\tOther status fields aren't set\n");
1563 fprintf(fp, "\t\t\t3 nulls follow the VolumeStatus structure.\n");
1564 fprintf(fp, "\tfollow = 1\n");
1569 code = pioctl_T(volInfo.m_strFilePath, VIOCSETVOLSTAT, &blob, 1);
1570 if (code || blob.out_size < sizeof(*status)) {
1571 ShowMessageBox(IDS_SET_QUOTA_ERROR, MB_ICONERROR, IDS_SET_QUOTA_ERROR, GetAfsError(errno, volInfo.m_strName));
1579 GetCellName(const CString& cellNamep, struct afsconf_cell *infop)
1581 CStringUtf8 uCellName(cellNamep);
1583 StringCbCopyA(infop->name, sizeof(infop->name), uCellName);
1587 CheckServers(const CString& strCellName, WHICH_CELLS nCellsToCheck, BOOL bFast)
1590 struct ViceIoctl blob;
1593 struct afsconf_cell info;
1594 struct chservinfo checkserv;
1596 HOURGLASS hourglass;
1598 memset(&checkserv, 0, sizeof(struct chservinfo));
1599 blob.in_size = sizeof(struct chservinfo);
1600 blob.in = (caddr_t)&checkserv;
1602 blob.out_size = AFS_PIOCTL_MAXSIZE;
1604 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1606 if (nCellsToCheck == SPECIFIC_CELL) {
1608 GetCellName(strCellName, &info);
1609 strcpy(checkserv.tbuffer,info.name);
1610 checkserv.tsize = strlen(info.name) + 1;
1612 if (nCellsToCheck != ALL_CELLS)
1614 strcpy(checkserv.tbuffer, "\0");
1615 checkserv.tsize = 0;
1618 temp |= 1; /* set fast flag */
1620 checkserv.magic = 0x12345678; /* XXX */
1621 checkserv.tflags = temp;
1622 checkserv.tinterval = -1; /* don't change current interval */
1624 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
1626 ShowMessageBox(IDS_CHECK_SERVERS_ERROR, MB_ICONERROR, IDS_CHECK_SERVERS_ERROR, GetAfsError(errno, CString()));
1630 memcpy(&temp, space, sizeof(LONG));
1633 ShowMessageBox(IDS_ALL_SERVERS_RUNNING, MB_OK|MB_ICONINFORMATION, IDS_ALL_SERVERS_RUNNING);
1637 CStringArray servers;
1638 for (j = 0; j < AFS_MAXHOSTS; j++) {
1639 memcpy(&temp, space + j * sizeof(LONG), sizeof(LONG));
1643 char *name = hostutil_GetNameByINet(temp);
1647 CDownServersDlg dlg;
1648 dlg.SetServerNames(servers);
1655 GetTokenInfo(CStringArray& tokenInfo)
1659 time_t current_time;
1660 time_t tokenExpireTime;
1664 struct ktc_principal serviceName, clientName;
1665 struct ktc_token token;
1667 CString strTokenInfo;
1668 CString strUserName;
1669 CString strCellName;
1672 // tokenInfo.Add("");
1676 HOURGLASS hourglass;
1678 // printf("\nTokens held by the Cache Manager:\n\n");
1680 current_time = time(0);
1683 rc = ktc_ListTokens(cellNum, &cellNum, &serviceName);
1684 if (rc == KTC_NOENT) {
1686 // printf(" --End of list --\n");
1689 else if (rc == KTC_NOCM) {
1690 ShowMessageBox(IDS_GET_TOKENS_NO_AFS_SERVICE);
1691 // printf("AFS service may not have started\n");
1695 ShowMessageBox(IDS_GET_TOKENS_UNEXPECTED_ERROR, MB_ICONERROR, IDS_GET_TOKENS_UNEXPECTED_ERROR, rc);
1697 // printf("Unexpected error, code %d\n", rc);
1701 rc = ktc_GetToken(&serviceName, &token, sizeof(token), &clientName);
1703 ShowMessageBox(IDS_GET_TOKENS_UNEXPECTED_ERROR2, MB_ICONERROR, IDS_GET_TOKENS_UNEXPECTED_ERROR2,
1704 serviceName.name, serviceName.instance, serviceName.cell, rc);
1708 tokenExpireTime = token.endTime;
1710 strcpy(userName, clientName.name);
1711 if (clientName.instance[0] != 0) {
1712 strcat(userName, ".");
1713 strcat(userName, clientName.instance);
1716 BOOL bShowName = FALSE;
1718 if (userName[0] == '\0')
1719 ; //printf("Tokens");
1720 // AFS ID is not returned at this time.
1721 // else if (strncmp(userName, "AFS ID", 6) == 0)
1722 // printf("User's (%s) tokens", userName);
1723 // sscanf(userName, "(AFS ID %s)", szAfsID);
1724 else if (strncmp(userName, "Unix UID", 8) == 0)
1725 ; //printf("Tokens");
1727 strUserName = userName;
1728 // printf("User %s's tokens", userName);
1730 // printf(" for %s%s%s@%s ", serviceName.name, serviceName.instance[0] ? "." : "", serviceName.instance, serviceName.cell);
1731 strCellName = serviceName.cell;
1733 if (tokenExpireTime <= current_time)
1734 strExpir = "[>> Expired <<]";
1735 // printf("[>> Expired <<]\n");
1737 expireString = ctime(&tokenExpireTime);
1738 expireString += 4; /* Skip day of week */
1739 expireString[12] = '\0'; /* Omit secs & year */
1740 // printf("[Expires %s]\n", expireString);
1742 strExpir.Format(_T("%S"), expireString);
1744 strExpir.Format(_T("%s"), expireString);
1748 strTokenInfo = strUserName + "\t" + strCellName + "\t" + strExpir + "\t" + strCellName;
1749 tokenInfo.Add(strTokenInfo);
1753 // printf("Press <Enter> or <Return> when finished: ");
1759 MakeSymbolicLink(const CString& strName, const CString& strTarget)
1761 struct ViceIoctl blob;
1763 HOURGLASS hourglass;
1765 CString strParent = Parent(strName);
1766 FixNetbiosPath(strParent);
1768 if ( IsFreelanceRoot(strParent) && !IsAdmin() ) {
1769 ShowMessageBox(IDS_NOT_AFS_CLIENT_ADMIN_ERROR, MB_ICONERROR, IDS_NOT_AFS_CLIENT_ADMIN_ERROR);
1773 CStringUtf8 ustrTarget(strTarget);
1775 blob.in_size = ustrTarget.GetLength() + 1;
1776 blob.in = ustrTarget.GetBuffer();
1780 code = pioctl_T(strName, VIOC_SYMLINK, &blob, 0);
1782 ustrTarget.ReleaseBuffer();
1790 ListSymbolicLinkPath(const char *strName,char *strPath,UINT nlenPath)
1792 ASSERT(nlenPath<MAX_PATH);
1793 struct ViceIoctl blob;
1794 char orig_name[MAX_PATH+1]; /*Original name, may be modified*/
1795 char true_name[MAX_PATH+1]; /*``True'' dirname (e.g., symlink target)*/
1796 char parent_dir[MAX_PATH+1]; /*Parent directory of true name*/
1797 char *last_component; /*Last component of true name*/
1800 HOURGLASS hourglass;
1802 strcpy(orig_name, strName);
1803 strcpy(true_name, orig_name);
1805 * Find rightmost slash, if any.
1807 last_component = (char *) strrchr(true_name, '\\');
1808 if (!last_component)
1809 last_component = (char *) strrchr(true_name, '/');
1810 if (last_component) {
1812 * Found it. Designate everything before it as the parent directory,
1813 * everything after it as the final component.
1815 strncpy(parent_dir, true_name, last_component - true_name + 1);
1816 parent_dir[last_component - true_name + 1] = 0;
1817 last_component++; /*Skip the slash*/
1819 if (!IsPathInAfs(parent_dir)) {
1820 const char * nbname = NetbiosName();
1821 int len = strlen(nbname);
1823 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
1824 parent_dir[len+2] == '\\' &&
1825 parent_dir[len+3] == '\0' &&
1826 !strnicmp(nbname,&parent_dir[2],len))
1828 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
1834 * No slash appears in the given file name. Set parent_dir to the current
1835 * directory, and the last component as the given name.
1837 fs_ExtractDriveLetter(true_name, parent_dir);
1838 strcat(parent_dir, ".");
1839 last_component = true_name;
1840 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1842 blob.in = last_component;
1843 blob.in_size = strlen(last_component)+1;
1844 blob.out_size = AFS_PIOCTL_MAXSIZE;
1846 memset(space, 0, AFS_PIOCTL_MAXSIZE);
1847 if ((code = pioctl(parent_dir, VIOC_LISTSYMLINK, &blob, 1)))
1848 strcpy(space,"???");
1849 ASSERT(strlen(space)<MAX_PATH);
1850 strncpy(strPath,space,nlenPath);
1854 ListSymlink(CStringArray& files)
1857 struct ViceIoctl blob;
1859 CStringArray symlinks;
1861 HOURGLASS hourglass;
1865 for (int i = 0; i < files.GetSize(); i++) {
1867 CString strParent = Parent(files[i]);
1868 CStringUtf8 ustrLast(LastComponent(files[i]));
1870 FixNetbiosPath(strParent);
1872 blob.in_size = ustrLast.GetLength() + 1;
1873 blob.in = ustrLast.GetBuffer();
1874 blob.out_size = AFS_PIOCTL_MAXSIZE;
1876 memset(space, 0, AFS_PIOCTL_MAXSIZE);
1878 code = pioctl_T(strParent, VIOC_LISTSYMLINK, &blob, 1);
1880 ustrLast.ReleaseBuffer();
1886 space[AFS_PIOCTL_MAXSIZE - 1] = '\0';
1887 syml = Utf8ToCString(space);
1888 len = syml.GetLength();
1891 if (syml[len - 1] == _T('.'))
1892 syml.Truncate(len - 1);
1895 symlinks.Add(ParseSymlink(StripPath(files[i]), syml));
1899 if (errno == EINVAL)
1900 symlinks.Add(GetMessageString(IDS_NOT_SYMLINK_ERROR, StripPath(files[i])));
1902 symlinks.Add(GetMessageString(IDS_LIST_MOUNT_POINT_ERROR, GetAfsError(errno, StripPath(files[i]))));
1907 dlg.SetSymlinks(symlinks);