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
10 #include <afs/param.h>
12 #include <afs/com_err.h>
23 #include <rx/rx_globals.h>
27 #include <afs/cellconfig.h>
28 #include <afs/ptserver.h>
29 #include <afs/ptuser.h>
30 #include <afs/volser.h>
31 #include <WINNT\afsreg.h>
41 #define MAXCELLHOSTS 8
44 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
45 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
46 #define CELL_MAXNAMELEN 256
47 #define MAXHOSTCHARS 64
49 static char space[MAXSIZE];
50 static char tspace[1024];
52 static struct ubik_client *uclient;
54 static int GetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
55 static int SetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
56 static int FlushMountCmd(struct cmd_syndesc *asp, void *arock);
57 static int RxStatProcCmd(struct cmd_syndesc *asp, void *arock);
58 static int RxStatPeerCmd(struct cmd_syndesc *asp, void *arock);
60 extern struct cmd_syndesc *cmd_CreateSyntax();
62 static int MemDumpCmd(struct cmd_syndesc *asp, void *arock);
63 static int CSCPolicyCmd(struct cmd_syndesc *asp, void *arock);
64 static int MiniDumpCmd(struct cmd_syndesc *asp, void *arock);
66 static char pn[] = "fs";
67 static int rxInitDone = 0;
70 * Character to use between name and rights in printed representation for
73 #define DFS_SEPARATOR ' '
75 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
78 int dfs; /* Originally true if a dfs acl; now also the type
79 * of the acl (1, 2, or 3, corresponding to object,
80 * initial dir, or initial object). */
81 sec_rgy_name_t cell; /* DFS cell name */
84 struct AclEntry *pluslist;
85 struct AclEntry *minuslist;
89 struct AclEntry *next;
95 ZapAcl (struct Acl *acl)
100 ZapList(acl->pluslist);
101 ZapList(acl->minuslist);
106 * Mods for the AFS/DFS protocol translator.
108 * DFS rights. It's ugly to put these definitions here, but they
109 * *cannot* change, because they're part of the wire protocol.
110 * In any event, the protocol translator will guarantee these
111 * assignments for AFS cache managers.
113 #define DFS_READ 0x01
114 #define DFS_WRITE 0x02
115 #define DFS_EXECUTE 0x04
116 #define DFS_CONTROL 0x08
117 #define DFS_INSERT 0x10
118 #define DFS_DELETE 0x20
120 /* the application definable ones (backwards from AFS) */
121 #define DFS_USR0 0x80000000 /* "A" bit */
122 #define DFS_USR1 0x40000000 /* "B" bit */
123 #define DFS_USR2 0x20000000 /* "C" bit */
124 #define DFS_USR3 0x10000000 /* "D" bit */
125 #define DFS_USR4 0x08000000 /* "E" bit */
126 #define DFS_USR5 0x04000000 /* "F" bit */
127 #define DFS_USR6 0x02000000 /* "G" bit */
128 #define DFS_USR7 0x01000000 /* "H" bit */
129 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
130 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
133 * Offset of -id switch in command structure for various commands.
134 * The -if switch is the next switch always.
136 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
139 * Determine whether either the -id or -if switches are present, and
140 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
142 /* int id; Offset of -id switch; -if is next switch */
144 getidf(struct cmd_syndesc *as, int id)
148 if (as->parms[id].items) {
151 if (as->parms[id + 1].items) {
156 "%s: you may specify either -id or -if, but not both switches\n",
164 PRights(afs_int32 arights, int dfs)
167 if (arights & PRSFS_READ)
169 if (arights & PRSFS_LOOKUP)
171 if (arights & PRSFS_INSERT)
173 if (arights & PRSFS_DELETE)
175 if (arights & PRSFS_WRITE)
177 if (arights & PRSFS_LOCK)
179 if (arights & PRSFS_ADMINISTER)
181 if (arights & PRSFS_USR0)
183 if (arights & PRSFS_USR1)
185 if (arights & PRSFS_USR2)
187 if (arights & PRSFS_USR3)
189 if (arights & PRSFS_USR4)
191 if (arights & PRSFS_USR5)
193 if (arights & PRSFS_USR6)
195 if (arights & PRSFS_USR7)
198 if (arights & DFS_READ)
202 if (arights & DFS_WRITE)
206 if (arights & DFS_EXECUTE)
210 if (arights & DFS_CONTROL)
214 if (arights & DFS_INSERT)
218 if (arights & DFS_DELETE)
222 if (arights & (DFS_USRALL))
224 if (arights & DFS_USR0)
226 if (arights & DFS_USR1)
228 if (arights & DFS_USR2)
230 if (arights & DFS_USR3)
232 if (arights & DFS_USR4)
234 if (arights & DFS_USR5)
236 if (arights & DFS_USR6)
238 if (arights & DFS_USR7)
244 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
248 struct ViceIoctl blob;
249 cm_ioctlQueryOptions_t options;
253 memset(&options, 0, sizeof(options));
254 options.size = sizeof(options);
255 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
257 blob.in_size = options.size; /* no variable length data */
259 blob.out_size = sizeof(cm_fid_t);
260 blob.out = (char *) &fid;
262 code = pioctl_utf8(apath, VIOCGETFID, &blob, 1);
264 if ((errno == EINVAL) || (errno == ENOENT))
271 IsFreelanceRoot(char *apath)
273 struct ViceIoctl blob;
277 blob.out_size = MAXSIZE;
280 code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
282 return !cm_strnicmp_utf8N("Freelance.Local.Root",space, blob.out_size);
284 return 1; /* assume it is because it is more restrictive that way */
287 /* return a static pointer to a buffer */
292 strcpy(tspace, apath);
293 tp = strrchr(tspace, '\\');
295 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
298 fs_ExtractDriveLetter(apath, tspace);
304 enum rtype {add, destroy, deny};
307 Convert(char *arights, int dfs, enum rtype *rtypep)
313 *rtypep = add; /* add rights, by default */
316 if (!strcmp(arights, "null")) {
320 if (!strcmp(arights,"read"))
321 return DFS_READ | DFS_EXECUTE;
322 if (!strcmp(arights, "write"))
323 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
325 if (!strcmp(arights, "all"))
326 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
327 DFS_WRITE | DFS_CONTROL;
329 if (!strcmp(arights,"read"))
330 return PRSFS_READ | PRSFS_LOOKUP;
331 if (!strcmp(arights, "write"))
332 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
333 PRSFS_WRITE | PRSFS_LOCK;
334 if (!strcmp(arights, "mail"))
335 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
336 if (!strcmp(arights, "all"))
337 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
338 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
340 if (!strcmp(arights, "none")) {
341 *rtypep = destroy; /* Remove entire entry */
344 len = (int)strlen(arights);
380 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
388 mode |= PRSFS_LOOKUP;
390 mode |= PRSFS_INSERT;
392 mode |= PRSFS_DELETE;
398 mode |= PRSFS_ADMINISTER;
416 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
425 static struct AclEntry *
426 FindList (struct AclEntry *alist, char *aname)
429 if (!strcasecmp(alist->name, aname))
436 /* if no parm specified in a particular slot, set parm to be "." instead */
438 SetDotDefault(struct cmd_item **aitemp)
442 return; /* already has value */
443 /* otherwise, allocate an item representing "." */
444 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
446 ti->next = (struct cmd_item *) 0;
447 ti->data = (char *) malloc(2);
449 strcpy(ti->data, ".");
454 ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
456 struct AclEntry *tlist;
457 tlist = (plus ? al->pluslist : al->minuslist);
458 tlist = FindList (tlist, aname);
460 /* Found the item already in the list. */
461 tlist->rights = arights;
463 al->nplus -= PruneList(&al->pluslist, al->dfs);
465 al->nminus -= PruneList(&al->minuslist, al->dfs);
468 /* Otherwise we make a new item and plug in the new data. */
469 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
471 strcpy(tlist->name, aname);
472 tlist->rights = arights;
474 tlist->next = al->pluslist;
475 al->pluslist = tlist;
477 if (arights == 0 || arights == -1)
478 al->nplus -= PruneList(&al->pluslist, al->dfs);
480 tlist->next = al->minuslist;
481 al->minuslist = tlist;
484 al->nminus -= PruneList(&al->minuslist, al->dfs);
489 ZapList (struct AclEntry *alist)
491 struct AclEntry *tp, *np;
492 for (tp = alist; tp; tp = np) {
499 PruneList (struct AclEntry **ae, int dfs)
501 struct AclEntry **lp;
502 struct AclEntry *te, *ne;
506 for(te = *ae;te;te=ne) {
507 if ((!dfs && te->rights == 0) || te->rights == -1) {
521 SkipLine (char *astr)
530 * Create an empty acl, taking into account whether the acl pointed
531 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
532 * can recover from problems caused by bogus ACL's (in that case, always
533 * assume that the acl is AFS: for DFS, the user can always resort to
534 * acl_edit, but for AFS there may be no other way out).
542 tp = (struct Acl *)malloc(sizeof (struct Acl));
544 tp->nplus = tp->nminus = 0;
545 tp->pluslist = tp->minuslist = 0;
547 if (astr == NULL || sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell) <= 0) {
555 ParseAcl (char *astr)
557 int nplus, nminus, i, trights, ret;
559 struct AclEntry *first, *next, *last, *tl;
563 if (astr == NULL || strlen(astr) == 0)
566 ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
571 astr = SkipLine(astr);
572 ret = sscanf(astr, "%d", &ta->nminus);
577 astr = SkipLine(astr);
584 for(i=0;i<nplus;i++) {
585 ret = sscanf(astr, "%100s %d", tname, &trights);
588 astr = SkipLine(astr);
589 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
594 strcpy(tl->name, tname);
595 tl->rights = trights;
601 ta->pluslist = first;
605 for(i=0;i<nminus;i++) {
606 ret = sscanf(astr, "%100s %d", tname, &trights);
609 astr = SkipLine(astr);
610 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
615 strcpy(tl->name, tname);
616 tl->rights = trights;
622 ta->minuslist = first;
627 for (;first; first = next) {
631 first = ta->pluslist;
634 for (;first; first = next) {
643 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
645 printf("Volume status for vid = %u named %s is\n",status->Vid, name);
647 printf("Current offline message is %s\n",offmsg);
649 printf("Current message of the day is %s\n",motd);
650 printf("Current disk quota is ");
651 if (status->MaxQuota != 0)
652 printf("%d\n", status->MaxQuota);
654 printf("unlimited\n");
655 printf("Current blocks used are %d\n",status->BlocksInUse);
656 printf("The partition has %d blocks available out of %d\n",
657 status->PartBlocksAvail, status->PartMaxBlocks);
662 QuickPrintStatus(VolumeStatus *status, char *name)
664 double QuotaUsed =0.0;
665 double PartUsed =0.0;
667 printf("%-25.25s",name);
669 if (status->MaxQuota != 0) {
670 printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
671 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
673 printf(" no limit %10d", status->BlocksInUse);
675 if (QuotaUsed > 90.0){
676 printf(" %5.0f%%<<", QuotaUsed);
679 printf(" %5.0f%% ", QuotaUsed);
680 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
681 if (PartUsed > 97.0){
682 printf(" %9.0f%%<<", PartUsed);
685 printf(" %9.0f%% ", PartUsed);
687 printf(" <<WARNING\n");
694 QuickPrintSpace(VolumeStatus *status, char *name)
696 double PartUsed =0.0;
698 printf("%-25.25s",name);
700 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
702 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
703 if (PartUsed > 90.0){
704 printf(" %4.0f%%<<", PartUsed);
707 printf(" %4.0f%% ", PartUsed);
709 printf(" <<WARNING\n");
716 AclToString(struct Acl *acl)
718 static char mydata[MAXSIZE];
719 char tstring[MAXSIZE];
724 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
727 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
728 for (tp = acl->pluslist;tp;tp=tp->next) {
729 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
730 strcat(mydata, tstring);
732 for (tp = acl->minuslist;tp;tp=tp->next) {
733 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
734 strcat(mydata, tstring);
739 static DWORD IsFreelance(void)
746 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
747 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
748 if (code == ERROR_SUCCESS) {
749 dummyLen = sizeof(cm_freelanceEnabled);
750 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
751 (BYTE *) &enabled, &dummyLen);
752 RegCloseKey (parmKey);
757 static const char * NetbiosName(void)
759 static char buffer[1024] = "AFS";
765 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
766 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
767 if (code == ERROR_SUCCESS) {
768 dummyLen = sizeof(buffer);
769 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
771 RegCloseKey (parmKey);
773 strcpy(buffer, "AFS");
778 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
780 static BOOL IsAdmin (void)
782 static BOOL fAdmin = FALSE;
783 static BOOL fTested = FALSE;
787 /* Obtain the SID for the AFS client admin group. If the group does
788 * not exist, then assume we have AFS client admin privileges.
790 PSID psidAdmin = NULL;
791 DWORD dwSize, dwSize2;
792 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
793 char *pszRefDomain = NULL;
794 SID_NAME_USE snu = SidTypeGroup;
796 dwSize = sizeof(pszAdminGroup);
798 if (!GetComputerName(pszAdminGroup, &dwSize)) {
799 /* Can't get computer name. We return false in this case.
800 Retain fAdmin and fTested. This shouldn't happen.*/
807 strcat(pszAdminGroup,"\\");
808 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
810 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
811 /* that should always fail. */
813 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
814 /* if we can't find the group, then we allow the operation */
819 if (dwSize == 0 || dwSize2 == 0) {
825 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
827 pszRefDomain = (char *)malloc(dwSize2);
828 assert(pszRefDomain);
830 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
831 /* We can't lookup the group now even though we looked it up earlier.
832 Could this happen? */
835 /* Then open our current ProcessToken */
838 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
841 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
842 /* We'll have to allocate a chunk of memory to store the list of
843 * groups to which this user belongs; find out how much memory
847 PTOKEN_GROUPS pGroups;
849 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
851 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
854 /* Allocate that buffer, and read in the list of groups. */
855 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
857 /* Look through the list of group SIDs and see if any of them
858 * matches the AFS Client Admin group SID.
861 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
863 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
873 /* if do not have permission because we were not explicitly listed
874 * in the Admin Client Group let's see if we are the SYSTEM account
877 PTOKEN_USER pTokenUser;
878 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
879 PSID pSidLocalSystem = 0;
882 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
884 pTokenUser = (PTOKEN_USER)malloc(dwSize);
887 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
888 gle = GetLastError();
890 if (AllocateAndInitializeSid( &SIDAuth, 1,
891 SECURITY_LOCAL_SYSTEM_RID,
895 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
899 FreeSid(pSidLocalSystem);
918 SetACLCmd(struct cmd_syndesc *as, void *arock)
921 struct ViceIoctl blob;
923 struct cmd_item *ti, *ui;
927 int idf = getidf(as, parm_setacl_id);
931 if (as->parms[2].items)
935 plusp = !(as->parms[3].items);
936 for(ti=as->parms[0].items; ti;ti=ti->next) {
937 blob.out_size = MAXSIZE;
939 blob.in = blob.out = space;
940 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
942 Die(errno, ti->data);
948 ta = ParseAcl(space);
951 "fs: %s: invalid acl data returned from VIOCGETAL\n",
956 if (!plusp && ta->dfs) {
958 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
960 "(you may specify \"null\" to revoke all rights, however)\n");
967 ta = EmptyAcl(space);
969 ta = ParseAcl(space);
972 "fs: %s: invalid acl data returned from VIOCGETAL\n",
977 CleanAcl(ta, ti->data);
978 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
982 "%s: Missing second half of user/access pair.\n", pn);
986 rights = Convert(ui->next->data, ta->dfs, &rtype);
987 if (rtype == destroy && !ta->dfs) {
988 struct AclEntry *tlist;
990 tlist = (plusp ? ta->pluslist : ta->minuslist);
991 if (!FindList(tlist, ui->data))
994 if (rtype == deny && !ta->dfs)
996 if (rtype == destroy && ta->dfs)
998 ChangeList(ta, plusp, ui->data, rights);
1000 blob.in = AclToString(ta);
1002 blob.in_size = 1+(long)strlen(blob.in);
1003 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1005 if (errno == EINVAL) {
1007 static char *fsenv = 0;
1009 fsenv = (char *)getenv("FS_EXPERT");
1011 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
1014 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1015 "\nPossible reasons for this include:\n\n",
1016 " -You may have specified an inappropriate combination of rights.\n",
1017 " For example, some DFS-supported filesystems may not allow you to\n",
1018 " drop the \"c\" right from \"user_obj\".\n\n",
1019 " -A mask_obj may be required (it is likely required by the underlying\n",
1020 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
1021 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
1022 " does not automatically create or update the mask_obj. Try setting\n",
1023 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
1024 " users or groups. You can do this with a single command, such as\n",
1025 " \"fs sa mask_obj all user:somename read\"\n\n",
1026 " -A specified user or group may not exist.\n\n",
1027 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
1028 " This is probably not allowed by the underlying file system.\n\n",
1029 " -If you add a user or group to a DFS ACL, remember that it must be\n",
1030 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
1031 " may be local requirements on the format of the user or group name.\n",
1032 " Check with your cell administrator.\n\n",
1033 " -Or numerous other possibilities. It would be great if we could be more\n",
1034 " precise about the actual problem, but for various reasons, this is\n",
1035 " impractical via this interface. If you can't figure it out, you\n",
1036 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
1037 " whatever is provided). You may get better results. Good luck!\n\n",
1038 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
1042 "%s: Invalid argument, possible reasons include:\n",
1044 fprintf(stderr,"\t-File not in AFS\n");
1046 "\t-Too many users on access control list\n");
1048 "\t-Tried to add non-existent user to access control list\n");
1051 Die(errno, ti->data);
1062 CopyACLCmd(struct cmd_syndesc *as, void *arock)
1065 struct ViceIoctl blob;
1066 struct Acl *fa, *ta = 0;
1067 struct AclEntry *tp;
1068 struct cmd_item *ti;
1070 int idf = getidf(as, parm_copyacl_id);
1073 if (as->parms[2].items)
1077 blob.out_size = MAXSIZE;
1079 blob.in = blob.out = space;
1080 code = pioctl_utf8(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1082 Die(errno, as->parms[0].items->data);
1085 fa = ParseAcl(space);
1088 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1089 as->parms[0].items->data);
1092 CleanAcl(fa, as->parms[0].items->data);
1093 for (ti=as->parms[1].items; ti;ti=ti->next) {
1094 blob.out_size = MAXSIZE;
1096 blob.in = blob.out = space;
1097 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1099 Die(errno, ti->data);
1106 ta = EmptyAcl(space);
1108 ta = ParseAcl(space);
1111 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1116 CleanAcl(ta, ti->data);
1117 if (ta->dfs != fa->dfs) {
1119 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1125 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1127 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1132 strcpy(ta->cell, fa->cell);
1134 for (tp = fa->pluslist;tp;tp=tp->next)
1135 ChangeList(ta, 1, tp->name, tp->rights);
1136 for (tp = fa->minuslist;tp;tp=tp->next)
1137 ChangeList(ta, 0, tp->name, tp->rights);
1138 blob.in = AclToString(ta);
1140 blob.in_size = 1+(long)strlen(blob.in);
1141 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1143 if (errno == EINVAL) {
1145 "%s: Invalid argument, possible reasons include:\n", pn);
1146 fprintf(stderr,"\t-File not in AFS\n");
1148 Die(errno, ti->data);
1159 /* pioctl_utf8() call to get the cellname of a pathname */
1161 GetCell(char *fname, char *cellname)
1164 struct ViceIoctl blob;
1167 blob.out_size = CELL_MAXNAMELEN;
1168 blob.out = cellname;
1170 code = pioctl_utf8(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1172 cellname[blob.out_size - 1] = '\0';
1176 /* Check if a username is valid: If it contains only digits (or a
1177 * negative sign), then it might be bad. We then query the ptserver
1181 BadName(char *aname, char *fname)
1183 afs_int32 tc, code, id;
1185 char cell[CELL_MAXNAMELEN];
1188 for ( nm = aname; tc = *nm; nm++) {
1189 /* all must be '-' or digit to be bad */
1190 if (tc != '-' && (tc < '0' || tc > '9'))
1194 /* Go to the PRDB and see if this all number username is valid */
1195 code = GetCell(fname, cell);
1199 cm_GetConfigDir(confDir, sizeof(confDir));
1201 pr_Initialize(1, confDir, cell);
1202 code = pr_SNameToId(aname, &id);
1205 /* 1=>Not-valid; 0=>Valid */
1206 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1210 /* clean up an access control list of its bad entries; return 1 if we made
1211 any changes to the list, and 0 otherwise */
1213 CleanAcl(struct Acl *aa, char *fname)
1215 struct AclEntry *te, **le, *ne;
1218 /* Don't correct DFS ACL's for now */
1222 /* prune out bad entries */
1223 changes = 0; /* count deleted entries */
1225 for(te = aa->pluslist; te; te=ne) {
1227 if (BadName(te->name, fname)) {
1237 le = &aa->minuslist;
1238 for(te = aa->minuslist; te; te=ne) {
1240 if (BadName(te->name, fname)) {
1254 /* clean up an acl to not have bogus entries */
1256 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1260 struct ViceIoctl blob;
1262 struct cmd_item *ti;
1263 struct AclEntry *te;
1266 SetDotDefault(&as->parms[0].items);
1267 for(ti=as->parms[0].items; ti; ti=ti->next) {
1268 blob.out_size = MAXSIZE;
1271 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1273 Die(errno, ti->data);
1279 ta = ParseAcl(space);
1282 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1289 "%s: cleanacl is not supported for DFS access lists.\n",
1295 changes = CleanAcl(ta, ti->data);
1298 /* now set the acl */
1299 blob.in=AclToString(ta);
1300 blob.in_size = (long)strlen(blob.in)+1;
1302 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1304 if (errno == EINVAL) {
1306 "%s: Invalid argument, possible reasons include\n",
1308 fprintf(stderr,"%s: File not in vice or\n", pn);
1310 "%s: Too many users on access control list or\n",
1313 Die(errno, ti->data);
1319 /* now list the updated acl */
1320 printf("Access list for %s is now\n", ti->data);
1321 if (ta->nplus > 0) {
1323 printf("Normal rights:\n");
1324 for(te = ta->pluslist;te;te=te->next) {
1325 printf(" %s ", te->name);
1326 PRights(te->rights, ta->dfs);
1330 if (ta->nminus > 0) {
1331 printf("Negative rights:\n");
1332 for(te = ta->minuslist;te;te=te->next) {
1333 printf(" %s ", te->name);
1334 PRights(te->rights, ta->dfs);
1341 printf("Access list for %s is fine.\n", ti->data);
1349 ListACLCmd(struct cmd_syndesc *as, void *arock)
1353 struct ViceIoctl blob;
1354 struct AclEntry *te;
1355 struct cmd_item *ti;
1356 int idf = getidf(as, parm_listacl_id);
1359 SetDotDefault(&as->parms[0].items);
1360 for(ti=as->parms[0].items; ti; ti=ti->next) {
1362 blob.out_size = MAXSIZE;
1364 blob.in = blob.out = space;
1365 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1367 Die(errno, ti->data);
1371 ta = ParseAcl(space);
1374 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1381 printf("Access list for %s is\n", ti->data);
1384 printf("DFS access list for %s is\n", ti->data);
1387 printf("DFS initial directory access list of %s is\n", ti->data);
1390 printf("DFS initial file access list of %s is\n", ti->data);
1394 printf(" Default cell = %s\n", ta->cell);
1396 separator = ta->dfs? DFS_SEPARATOR : ' ';
1397 if (ta->nplus > 0) {
1399 printf("Normal rights:\n");
1400 for(te = ta->pluslist;te;te=te->next) {
1401 printf(" %s%c", te->name, separator);
1402 PRights(te->rights, ta->dfs);
1406 if (ta->nminus > 0) {
1407 printf("Negative rights:\n");
1408 for(te = ta->minuslist;te;te=te->next) {
1409 printf(" %s ", te->name);
1410 PRights(te->rights, ta->dfs);
1422 FlushAllCmd(struct cmd_syndesc *as, void *arock)
1425 struct ViceIoctl blob;
1427 blob.in_size = blob.out_size = 0;
1428 code = pioctl_utf8(NULL, VIOC_FLUSHALL, &blob, 0);
1430 fprintf(stderr, "Error flushing all ");
1437 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1440 struct ViceIoctl blob;
1441 struct cmd_item *ti;
1444 SetDotDefault(&as->parms[0].items);
1445 for(ti=as->parms[0].items; ti; ti=ti->next) {
1446 blob.in_size = blob.out_size = 0;
1447 code = pioctl_utf8(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1449 fprintf(stderr, "Error flushing volume ");
1459 FlushCmd(struct cmd_syndesc *as, void *arock)
1462 struct ViceIoctl blob;
1463 struct cmd_item *ti;
1466 cm_ioctlQueryOptions_t options;
1468 if (as->parms[1].items)
1471 for(ti=as->parms[0].items; ti; ti=ti->next) {
1473 memset(&options, 0, sizeof(options));
1474 options.size = sizeof(options);
1475 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1476 options.literal = literal;
1477 blob.in_size = options.size; /* no variable length data */
1481 code = pioctl_utf8(ti->data, VIOCFLUSH, &blob, 0);
1483 if (errno == EMFILE) {
1484 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1487 fprintf(stderr, "%s: Error flushing file ", pn);
1497 /* all this command does is repackage its args and call SetVolCmd */
1499 SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
1500 struct cmd_syndesc ts;
1502 /* copy useful stuff from our command slot; we may later have to reorder */
1503 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1504 return SetVolCmd(&ts, arock);
1508 SetVolCmd(struct cmd_syndesc *as, void *arock) {
1510 struct ViceIoctl blob;
1511 struct cmd_item *ti;
1512 struct VolumeStatus *status;
1513 char *motd, *offmsg, *input;
1516 SetDotDefault(&as->parms[0].items);
1517 for(ti=as->parms[0].items; ti; ti=ti->next) {
1519 blob.out_size = MAXSIZE;
1520 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1523 status = (VolumeStatus *)space;
1524 status->MinQuota = status->MaxQuota = -1;
1525 motd = offmsg = NULL;
1526 if (as->parms[1].items) {
1527 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1529 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1534 if (as->parms[2].items)
1535 motd = as->parms[2].items->data;
1536 if (as->parms[3].items)
1537 offmsg = as->parms[3].items->data;
1538 input = (char *)status + sizeof(*status);
1539 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1541 if (strlen(offmsg) >= VMSGSIZE) {
1542 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1547 strcpy(input,offmsg);
1548 blob.in_size += (long)strlen(offmsg);
1549 input += strlen(offmsg) + 1;
1553 if (strlen(motd) >= VMSGSIZE) {
1554 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1559 blob.in_size += (long)strlen(motd);
1560 input += strlen(motd) + 1;
1563 code = pioctl_utf8(ti->data,VIOCSETVOLSTAT, &blob, 1);
1565 Die(errno, ti->data);
1572 /* values match cache manager File Types */
1574 filetypestr(afs_uint32 type)
1576 char * s = "Object";
1599 ExamineCmd(struct cmd_syndesc *as, void *arock)
1602 struct ViceIoctl blob;
1603 struct cmd_item *ti;
1604 struct VolumeStatus *status;
1605 char *name, *offmsg, *motd;
1608 cm_ioctlQueryOptions_t options;
1610 if (as->parms[1].items)
1613 SetDotDefault(&as->parms[0].items);
1614 for(ti=as->parms[0].items; ti; ti=ti->next) {
1616 afs_uint32 filetype;
1617 afs_uint32 owner[2];
1618 char cell[CELL_MAXNAMELEN];
1621 memset(&fid, 0, sizeof(fid));
1622 memset(&options, 0, sizeof(options));
1624 options.size = sizeof(options);
1625 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1626 options.literal = literal;
1627 blob.in_size = options.size; /* no variable length data */
1630 blob.out_size = sizeof(cm_fid_t);
1631 blob.out = (char *) &fid;
1632 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
1633 blob.out_size == sizeof(cm_fid_t)) {
1634 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1637 Die(errno, ti->data);
1642 blob.out_size = sizeof(filetype);
1643 blob.out = &filetype;
1645 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1646 if (code || blob.out_size != sizeof(filetype)) {
1647 Die(errno, ti->data);
1652 blob.out_size = CELL_MAXNAMELEN;
1655 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1657 cell[blob.out_size-1] = '\0';
1658 printf("%s %s (%u.%u.%u) contained in cell %s\n",
1659 filetypestr(filetype),
1660 ti->data, fid.volume, fid.vnode, fid.unique,
1661 code ? "unknown-cell" : cell);
1663 blob.out_size = 2 * sizeof(afs_uint32);
1664 blob.out = (char *) &owner;
1665 if (0 == pioctl_utf8(ti->data, VIOCGETOWNER, &blob, 1) &&
1666 blob.out_size == 2 * sizeof(afs_uint32)) {
1667 char oname[PR_MAXNAMELEN] = "(unknown)";
1668 char gname[PR_MAXNAMELEN] = "(unknown)";
1671 /* Go to the PRDB and see if this all number username is valid */
1672 cm_GetConfigDir(confDir, sizeof(confDir));
1674 pr_Initialize(1, confDir, cell);
1675 pr_SIdToName(owner[0], oname);
1676 pr_SIdToName(owner[1], gname);
1677 printf("Owner %s (%u) Group %s (%u)\n", oname, owner[0], gname, owner[1]);
1681 blob.out_size = MAXSIZE;
1682 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1684 space[blob.out_size - 1] = '\0';
1685 status = (VolumeStatus *)space;
1686 name = (char *)status + sizeof(*status);
1687 offmsg = name + strlen(name) + 1;
1688 motd = offmsg + strlen(offmsg) + 1;
1689 PrintStatus(status, name, motd, offmsg);
1691 Die(errno, ti->data);
1695 code = pioctl_utf8(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
1698 printf("Volume is online\n");
1701 printf("Volume is offline\n");
1704 printf("All Volume servers are down\n");
1707 printf("All volume servers are busy\n");
1710 printf("Unknown volume state\n");
1711 Die(errno, ti->data);
1719 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1722 struct ViceIoctl blob;
1723 struct cmd_item *ti;
1724 struct VolumeStatus *status;
1729 printf("%-25s%-11s%-11s%-7s%-13s\n", "Volume Name", " Quota",
1730 " Used", " %Used", " Partition");
1731 SetDotDefault(&as->parms[0].items);
1732 for(ti=as->parms[0].items; ti; ti=ti->next) {
1734 blob.out_size = MAXSIZE;
1737 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1739 Die(errno, ti->data);
1743 space[blob.out_size - 1] = '\0';
1744 status = (VolumeStatus *)space;
1745 name = (char *)status + sizeof(*status);
1746 QuickPrintStatus(status, name);
1752 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1755 struct ViceIoctl blob;
1756 struct cmd_item *ti;
1762 cm_ioctlQueryOptions_t options;
1764 if (as->parms[1].items)
1767 SetDotDefault(&as->parms[0].items);
1768 for(ti=as->parms[0].items; ti; ti=ti->next) {
1770 afs_uint32 filetype;
1773 memset(&fid, 0, sizeof(fid));
1774 memset(&options, 0, sizeof(options));
1776 options.size = sizeof(options);
1777 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1778 options.literal = literal;
1779 blob.in_size = options.size; /* no variable length data */
1782 blob.out_size = sizeof(cm_fid_t);
1783 blob.out = (char *) &fid;
1784 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
1785 blob.out_size == sizeof(cm_fid_t)) {
1786 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1789 Die(errno, ti->data);
1794 blob.out_size = sizeof(filetype);
1795 blob.out = &filetype;
1797 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1798 if (code || blob.out_size != sizeof(filetype)) {
1799 Die(errno, ti->data);
1803 blob.out_size = MAXSIZE;
1805 memset(space, 0, sizeof(space));
1806 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
1808 Die(errno, ti->data);
1812 hosts = (afs_int32 *) space;
1813 printf("%s %s is on host%s ",
1814 filetypestr(filetype),
1816 (hosts[0] && !hosts[1]) ? "": "s");
1817 for(j=0; j<MAXHOSTS; j++) {
1820 tp = hostutil_GetNameByINet(hosts[j]);
1830 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1833 struct ViceIoctl blob;
1834 struct cmd_item *ti;
1836 struct VolumeStatus *status;
1839 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1840 " used", " avail", " %used");
1841 SetDotDefault(&as->parms[0].items);
1842 for(ti=as->parms[0].items; ti; ti=ti->next) {
1844 blob.out_size = MAXSIZE;
1847 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1849 Die(errno, ti->data);
1853 space[blob.out_size - 1] = '\0';
1854 status = (VolumeStatus *)space;
1855 name = (char *)status + sizeof(*status);
1856 QuickPrintSpace(status, name);
1862 QuotaCmd(struct cmd_syndesc *as, void *arock)
1865 struct ViceIoctl blob;
1866 struct cmd_item *ti;
1868 struct VolumeStatus *status;
1871 SetDotDefault(&as->parms[0].items);
1872 for(ti=as->parms[0].items; ti; ti=ti->next) {
1874 blob.out_size = MAXSIZE;
1877 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1878 if (code || blob.out_size != sizeof(*status)) {
1879 Die(errno, ti->data);
1883 status = (VolumeStatus *)space;
1884 if (status->MaxQuota)
1885 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1888 printf("%2.0f%% of quota used.\n", quotaPct);
1894 ListMountCmd(struct cmd_syndesc *as, void *arock)
1897 struct ViceIoctl blob;
1898 struct cmd_item *ti;
1899 char orig_name[1024]; /*Original name, may be modified*/
1900 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1901 char parent_dir[1024]; /*Parent directory of true name*/
1902 char *last_component; /*Last component of true name*/
1904 struct stat statbuff; /*Buffer for status info*/
1905 #endif /* not WIN32 */
1907 int link_chars_read; /*Num chars read in readlink()*/
1908 #endif /* not WIN32 */
1909 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1912 for(ti=as->parms[0].items; ti; ti=ti->next) {
1916 strcpy(orig_name, ti->data);
1917 #else /* not WIN32 */
1918 sprintf(orig_name, "%s%s",
1919 (ti->data[0] == '/') ? "" : "./",
1921 #endif /* not WIN32 */
1924 if (lstat(orig_name, &statbuff) < 0) {
1925 /* if lstat fails, we should still try the pioctl, since it
1926 * may work (for example, lstat will fail, but pioctl will
1927 * work if the volume of offline (returning ENODEV). */
1928 statbuff.st_mode = S_IFDIR; /* lie like pros */
1932 * The lstat succeeded. If the given file is a symlink, substitute
1933 * the file name with the link name.
1935 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1938 * Read name of resolved file.
1940 link_chars_read = readlink(orig_name, true_name, 1024);
1941 if (link_chars_read <= 0) {
1943 "%s: Can't read target name for '%s' symbolic link!\n",
1950 * Add a trailing null to what was read, bump the length.
1952 true_name[link_chars_read++] = 0;
1955 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1956 * have to create a full pathname using the original name and the
1957 * relative symlink name. Find the rightmost slash in the original
1958 * name (we know there is one) and splice in the symlink value.
1960 if (true_name[0] != '\\') {
1961 last_component = (char *) strrchr(orig_name, '\\');
1962 strcpy(++last_component, true_name);
1963 strcpy(true_name, orig_name);
1966 strcpy(true_name, orig_name);
1968 strcpy(true_name, orig_name);
1972 * Find rightmost slash, if any.
1975 last_component = (char *) strrchr(true_name, '\\');
1976 if (!last_component)
1978 last_component = (char *) strrchr(true_name, '/');
1979 if (last_component) {
1981 * Found it. Designate everything before it as the parent directory,
1982 * everything after it as the final component.
1984 strncpy(parent_dir, true_name, last_component - true_name + 1);
1985 parent_dir[last_component - true_name + 1] = 0;
1986 last_component++; /*Skip the slash*/
1988 if (!InAFS(parent_dir)) {
1989 const char * nbname = NetbiosName();
1990 int len = (int)strlen(nbname);
1992 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
1993 parent_dir[len+2] == '\\' &&
1994 parent_dir[len+3] == '\0' &&
1995 !strnicmp(nbname,&parent_dir[2],len))
1997 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
2003 * No slash appears in the given file name. Set parent_dir to the current
2004 * directory, and the last component as the given name.
2006 fs_ExtractDriveLetter(true_name, parent_dir);
2007 strcat(parent_dir, ".");
2008 last_component = true_name;
2009 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
2012 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
2013 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
2014 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
2019 blob.in = last_component;
2020 blob.in_size = (long)strlen(last_component)+1;
2021 blob.out_size = MAXSIZE;
2023 memset(space, 0, MAXSIZE);
2025 code = pioctl_utf8(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
2028 printf("'%s' is a %smount point for volume '%.*s'\n",
2030 (thru_symlink ? "symbolic link, leading to a " : ""),
2035 if (errno == EINVAL) {
2036 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
2038 Die(errno, (ti->data ? ti->data : parent_dir));
2047 MakeMountCmd(struct cmd_syndesc *as, void *arock)
2050 char *cellName, *volName, *tmpName;
2052 char localCellName[128];
2054 char path[1024] = "";
2055 struct afsconf_cell info;
2056 struct vldbentry vldbEntry;
2057 struct ViceIoctl blob;
2060 memset(&info, 0, sizeof(info));
2062 if (as->parms[2].items) /* cell name specified */
2063 cellName = as->parms[2].items->data;
2066 volName = as->parms[1].items->data;
2068 if (strlen(volName) >= 64) {
2069 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
2073 /* Check for a cellname in the volume specification, and complain
2074 * if it doesn't match what was specified with -cell */
2075 if (tmpName = strchr(volName, ':')) {
2078 if (strcasecmp(cellName,volName)) {
2079 fprintf(stderr,"fs: cellnames do not match.\n");
2084 volName = ++tmpName;
2087 parent = Parent(as->parms[0].items->data);
2088 if (!InAFS(parent)) {
2090 const char * nbname = NetbiosName();
2091 int len = (int)strlen(nbname);
2093 if (parent[0] == '\\' && parent[1] == '\\' &&
2094 parent[len+2] == '\\' &&
2095 parent[len+3] == '\0' &&
2096 !strnicmp(nbname,&parent[2],len))
2098 sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
2099 parent = Parent(path);
2100 if (!InAFS(parent)) {
2101 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2107 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2112 if ( strlen(path) == 0 )
2113 strcpy(path, as->parms[0].items->data);
2115 if ( IsFreelanceRoot(parent) ) {
2117 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2123 blob.out_size = sizeof(localCellName);
2124 blob.out = localCellName;
2125 code = pioctl_utf8(parent, VIOC_GET_WS_CELL, &blob, 1);
2127 localCellName[sizeof(localCellName) - 1] = '\0';
2128 cellName = localCellName;
2133 code = GetCell(parent,space);
2139 code = GetCellName(cellName?cellName:space, &info);
2143 if (!(as->parms[4].items)) {
2144 /* not fast, check which cell the mountpoint is being created in */
2146 /* not fast, check name with VLDB */
2148 code = VLDBInit(1, &info);
2150 /* make the check. Don't complain if there are problems with init */
2151 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2152 if (code == VL_NOENT) {
2153 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2154 pn, volName, cellName ? cellName : space);
2159 if (as->parms[3].items) /* if -rw specified */
2164 /* cellular mount point, prepend cell prefix */
2165 strcat(space, info.name);
2168 strcat(space, volName); /* append volume name */
2169 strcat(space, "."); /* stupid convention; these end with a period */
2171 /* create symlink with a special pioctl for Windows NT, since it doesn't
2172 * have a symlink system call.
2175 blob.in_size = 1 + (long)strlen(space);
2178 code = pioctl_utf8(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2179 #else /* not WIN32 */
2180 code = symlink(space, path);
2181 #endif /* not WIN32 */
2183 if (info.linkedCell)
2184 free(info.linkedCell);
2194 * Delete AFS mount points. Variables are used as follows:
2195 * tbuffer: Set to point to the null-terminated directory name of the mount point
2196 * (or ``.'' if none is provided)
2197 * tp: Set to point to the actual name of the mount point to nuke.
2200 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2202 struct ViceIoctl blob;
2203 struct cmd_item *ti;
2205 char lsbuffer[1024];
2209 for(ti=as->parms[0].items; ti; ti=ti->next) {
2211 tp = (char *) strrchr(ti->data, '\\');
2213 tp = (char *) strrchr(ti->data, '/');
2215 strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1)); /* the dir name */
2217 tp++; /* skip the slash */
2220 if (!InAFS(tbuffer)) {
2221 const char * nbname = NetbiosName();
2222 int len = (int)strlen(nbname);
2224 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2225 tbuffer[len+2] == '\\' &&
2226 tbuffer[len+3] == '\0' &&
2227 !strnicmp(nbname,&tbuffer[2],len))
2229 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
2234 fs_ExtractDriveLetter(ti->data, tbuffer);
2235 strcat(tbuffer, ".");
2237 fs_StripDriveLetter(tp, tp, 0);
2240 blob.in_size = (long)strlen(tp)+1;
2241 blob.out = lsbuffer;
2242 blob.out_size = sizeof(lsbuffer);
2243 code = pioctl_utf8(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2245 if (errno == EINVAL) {
2246 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2248 Die(errno, ti->data);
2251 continue; /* don't bother trying */
2254 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2255 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2257 continue; /* skip */
2262 blob.in_size = (long)strlen(tp)+1;
2263 code = pioctl_utf8(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2265 Die(errno, ti->data);
2276 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2279 struct ViceIoctl blob;
2283 struct afsconf_cell info;
2284 struct chservinfo checkserv;
2286 memset(&info, 0, sizeof(info));
2287 memset(&checkserv, 0, sizeof(struct chservinfo));
2288 blob.in_size=sizeof(struct chservinfo);
2289 blob.in=(caddr_t)&checkserv;
2291 blob.out_size = MAXSIZE;
2293 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2295 /* prepare flags for checkservers command */
2296 temp = 2; /* default to checking local cell only */
2297 if (as->parms[2].items)
2298 temp |= 1; /* set fast flag */
2299 if (as->parms[1].items)
2300 temp &= ~2; /* turn off local cell check */
2302 checkserv.magic = 0x12345678; /* XXX */
2303 checkserv.tflags=temp;
2305 /* now copy in optional cell name, if specified */
2306 if (as->parms[0].items) {
2307 code = GetCellName(as->parms[0].items->data, &info);
2311 strcpy(checkserv.tbuffer,info.name);
2312 checkserv.tsize=(int)strlen(info.name)+1;
2313 if (info.linkedCell)
2314 free(info.linkedCell);
2316 strcpy(checkserv.tbuffer,"\0");
2320 if(as->parms[3].items) {
2321 checkserv.tinterval=atol(as->parms[3].items->data);
2324 if(checkserv.tinterval<0) {
2325 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2326 checkserv.tinterval=-1;
2327 } else if(checkserv.tinterval> 600) {
2328 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2329 checkserv.tinterval=600; /* 10 min max interval */
2332 checkserv.tinterval = -1; /* don't change current interval */
2335 if ( checkserv.tinterval >= 0 ) {
2338 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2343 fprintf (stderr,"Permission denied: requires root access.\n");
2349 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
2351 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2352 printf("Must be root to change -interval\n");
2358 memcpy(&temp, space, sizeof(afs_int32));
2359 if (checkserv.tinterval >= 0) {
2360 if (checkserv.tinterval > 0)
2361 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2362 checkserv.tinterval, temp);
2364 printf("The current down server probe interval is %d secs\n", temp);
2368 printf("All servers are running.\n");
2370 printf("These servers unavailable due to network or server problems: ");
2371 for(j=0; j < MAXHOSTS; j++) {
2372 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2375 tp = hostutil_GetNameByINet(temp);
2385 MessagesCmd(struct cmd_syndesc *as, void *arock)
2388 struct ViceIoctl blob;
2389 struct gaginfo gagflags;
2390 struct cmd_item *show;
2392 memset(&gagflags, 0, sizeof(struct gaginfo));
2393 blob.in_size = sizeof(struct gaginfo);
2394 blob.in = (caddr_t ) &gagflags;
2395 blob.out_size = MAXSIZE;
2397 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2399 if (show = as->parms[0].items) {
2400 if (!strcasecmp (show->data, "user"))
2401 gagflags.showflags |= GAGUSER;
2402 else if (!strcasecmp (show->data, "console"))
2403 gagflags.showflags |= GAGCONSOLE;
2404 else if (!strcasecmp (show->data, "all"))
2405 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2406 else if (!strcasecmp (show->data, "none"))
2410 "unrecognized flag %s: must be in {user,console,all,none}\n",
2419 code = pioctl_utf8(0, VIOC_GAG, &blob, 1);
2428 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2431 struct ViceIoctl blob;
2435 code = pioctl_utf8(0, VIOCCKBACK, &blob, 1);
2440 printf("All volumeID/name mappings checked.\n");
2446 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2449 struct ViceIoctl blob;
2454 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2459 fprintf (stderr,"Permission denied: requires root access.\n");
2464 if (!as->parms[0].items && !as->parms[1].items) {
2465 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2468 if (as->parms[0].items) {
2469 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2471 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2476 blob.in = (char *) &temp;
2477 blob.in_size = sizeof(afs_int32);
2479 code = pioctl_utf8(0, VIOCSETCACHESIZE, &blob, 1);
2481 Die(errno, (char *) 0);
2485 printf("New cache size set.\n");
2490 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2493 struct ViceIoctl blob;
2494 cm_cacheParms_t parms;
2496 memset(&parms, 0, sizeof(parms));
2499 blob.out_size = sizeof(parms);
2500 blob.out = (char *) &parms;
2501 code = pioctl_utf8(0, VIOCGETCACHEPARMS, &blob, 1);
2502 if (code || blob.out_size != sizeof(parms)) {
2507 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2508 parms.parms[1], parms.parms[0]);
2509 if (parms.parms[1] > parms.parms[0])
2510 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2515 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2518 afs_int32 i, j, *lp, magic, size;
2520 afs_int32 addr, maxa = OMAXHOSTS;
2521 struct ViceIoctl blob;
2524 resolve = !(as->parms[0].items); /* -numeric */
2526 for(i=0;i<1000;i++) {
2528 memcpy(tp, &i, sizeof(afs_int32));
2529 tp = (char *)(space + sizeof(afs_int32));
2530 lp = (afs_int32 *)tp;
2532 size = sizeof(afs_int32) + sizeof(afs_int32);
2533 blob.out_size = MAXSIZE;
2534 blob.in_size = sizeof(afs_int32);
2537 code = pioctl_utf8(0, VIOCGETCELL, &blob, 1);
2540 break; /* done with the list */
2545 memcpy(&magic, tp, sizeof(afs_int32));
2546 if (magic == 0x12345678) {
2548 tp += sizeof(afs_int32);
2550 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2551 for(j=0; j < maxa && j*sizeof(afs_int32) < MAXSIZE; j++) {
2552 char *name, tbuffer[20];
2554 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2559 name = hostutil_GetNameByINet(addr);
2562 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2563 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2566 printf(" %s", name);
2575 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2578 char *tp, *aliasName, *realName;
2579 struct ViceIoctl blob;
2583 memcpy(tp, &i, sizeof(afs_int32));
2584 blob.out_size = MAXSIZE;
2585 blob.in_size = sizeof(afs_int32);
2588 code = pioctl_utf8(0, VIOC_GETALIAS, &blob, 1);
2591 break; /* done with the list */
2595 space[blob.out_size - 1] = '\0';
2598 tp += strlen(aliasName) + 1;
2600 printf("Alias %s for cell %s\n", aliasName, realName);
2606 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2609 struct ViceIoctl blob;
2610 struct cmd_item *ti;
2612 struct hostent *thp;
2616 ti = as->parms[0].items;
2619 thp = hostutil_GetHostByName(ti->data);
2621 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2624 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2626 hostAddr = 0; /* means don't set host */
2627 setp = 0; /* aren't setting host */
2630 /* now do operation */
2631 blob.in_size = sizeof(afs_int32);
2632 blob.out_size = sizeof(afs_int32);
2633 blob.in = (char *) &hostAddr;
2634 blob.out = (char *) &hostAddr;
2636 code = pioctl_utf8(0, VIOC_CBADDR, &blob, 1);
2646 NewCellCmd(struct cmd_syndesc *as, void *arock)
2649 afs_int32 code, linkedstate=0, size=0, *lp;
2650 struct ViceIoctl blob;
2651 struct cmd_item *ti;
2652 char *tp, *cellname=0;
2653 struct hostent *thp;
2654 afs_int32 fsport = 0, vlport = 0;
2656 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
2658 lp = (afs_int32 *)tp;
2660 tp += sizeof(afs_int32);
2661 for(ti=as->parms[1].items; ti; ti=ti->next) {
2662 thp = hostutil_GetHostByName(ti->data);
2664 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2668 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2669 tp += sizeof(afs_int32);
2672 if (as->parms[2].items) {
2674 * Link the cell, for the purposes of volume location, to the specified
2677 cellname = as->parms[2].items->data;
2680 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2681 if (as->parms[3].items) {
2682 code = util_GetInt32(as->parms[3].items->data, &vlport);
2684 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2688 if (as->parms[4].items) {
2689 code = util_GetInt32(as->parms[4].items->data, &fsport);
2691 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2696 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
2697 lp = (afs_int32 *)tp;
2701 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2702 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2703 tp = (char *)(space + size);
2705 strcpy(tp, cellname);
2706 size += strlen(cellname) + 1;
2708 blob.in_size = size;
2711 code = pioctl_utf8(0, VIOCNEWCELL, &blob, 1);
2717 struct ViceIoctl blob;
2720 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2725 blob.in = (char *) 0;
2726 blob.out_size = MAXSIZE;
2729 code = pioctl_utf8((char *) 0, VIOCNEWCELL, &blob, 1);
2732 Die(errno, (char *) 0);
2736 printf("Cell servers information refreshed\n");
2743 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2746 struct ViceIoctl blob;
2748 char *aliasName, *realName;
2750 /* Setup and do the NEWALIAS pioctl call */
2751 aliasName = as->parms[0].items->data;
2752 realName = as->parms[1].items->data;
2754 strcpy(tp, aliasName);
2755 tp += strlen(aliasName) + 1;
2756 strcpy(tp, realName);
2757 tp += strlen(realName) + 1;
2759 blob.in_size = tp - space;
2763 code = pioctl_utf8(0, VIOC_NEWALIAS, &blob, 1);
2765 if (errno == EEXIST) {
2767 "%s: cell name `%s' in use by an existing cell.\n", pn,
2779 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2782 struct cmd_item *ti;
2783 struct ViceIoctl blob;
2786 cm_ioctlQueryOptions_t options;
2788 if (as->parms[1].items)
2791 SetDotDefault(&as->parms[0].items);
2792 for(ti=as->parms[0].items; ti; ti=ti->next) {
2794 afs_uint32 filetype;
2795 char cell[CELL_MAXNAMELEN];
2798 memset(&fid, 0, sizeof(fid));
2799 memset(&options, 0, sizeof(options));
2801 options.size = sizeof(options);
2802 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
2803 options.literal = literal;
2804 blob.in_size = options.size; /* no variable length data */
2807 blob.out_size = sizeof(cm_fid_t);
2808 blob.out = (char *) &fid;
2809 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
2810 blob.out_size == sizeof(cm_fid_t)) {
2811 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
2814 Die(errno, ti->data);
2819 blob.out_size = sizeof(filetype);
2820 blob.out = &filetype;
2822 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
2823 if (code || blob.out_size != sizeof(filetype)) {
2824 Die(errno, ti->data);
2828 blob.out_size = CELL_MAXNAMELEN;
2831 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
2833 if (errno == ENOENT)
2834 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2836 Die(errno, ti->data);
2840 cell[CELL_MAXNAMELEN - 1] = '\0';
2841 printf("%s %s lives in cell '%s'\n",
2842 filetypestr(filetype),
2849 WSCellCmd(struct cmd_syndesc *as, void *arock)
2852 struct ViceIoctl blob;
2856 blob.out_size = MAXSIZE;
2859 code = pioctl_utf8(NULL, VIOC_GET_WS_CELL, &blob, 1);
2865 space[MAXSIZE - 1] = '\0';
2866 printf("This workstation belongs to cell '%s'\n", space);
2872 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
2874 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2879 #ifndef AFS_NT40_ENV
2881 MonitorCmd(struct cmd_syndesc *as, void *arock)
2884 struct ViceIoctl blob;
2885 struct cmd_item *ti;
2887 struct hostent *thp;
2891 ti = as->parms[0].items;
2895 if (!strcmp(ti->data, "off")) {
2896 hostAddr = 0xffffffff;
2898 thp = hostutil_GetHostByName(ti->data);
2900 if (!strcmp(ti->data, "localhost")) {
2901 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2902 hostAddr = htonl(0x7f000001);
2904 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2908 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2912 hostAddr = 0; /* means don't set host */
2913 setp = 0; /* aren't setting host */
2916 /* now do operation */
2917 blob.in_size = sizeof(afs_int32);
2918 blob.out_size = sizeof(afs_int32);
2919 blob.in = (char *) &hostAddr;
2920 blob.out = (char *) &hostAddr;
2921 code = pioctl_utf8(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2922 if (code || blob.out_size != sizeof(afs_int32)) {
2927 printf("%s: new monitor host set.\n", pn);
2929 /* now decode old address */
2930 if (hostAddr == 0xffffffff) {
2931 printf("Cache monitoring is currently disabled.\n");
2933 tp = hostutil_GetNameByINet(hostAddr);
2934 printf("Using host %s for monitor services.\n", tp);
2939 #endif /* AFS_NT40_ENV */
2942 SysNameCmd(struct cmd_syndesc *as, void *arock)
2945 struct ViceIoctl blob;
2946 struct cmd_item *ti;
2947 char *input = space;
2950 ti = as->parms[0].items;
2954 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2959 fprintf (stderr,"Permission denied: requires root access.\n");
2967 blob.out_size = MAXSIZE;
2968 blob.in_size = sizeof(afs_int32);
2969 memcpy(input, &setp, sizeof(afs_int32));
2970 input += sizeof(afs_int32);
2971 for (; ti; ti = ti->next) {
2973 blob.in_size += (long)strlen(ti->data) + 1;
2974 if (blob.in_size > MAXSIZE) {
2975 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2976 setp > 1 ? "s" : "");
2979 strcpy(input, ti->data);
2980 input += strlen(ti->data);
2983 memcpy(space, &setp, sizeof(afs_int32));
2984 code = pioctl_utf8(0, VIOC_AFS_SYSNAME, &blob, 1);
2990 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2995 memcpy(&setp, input, sizeof(afs_int32));
2996 input += sizeof(afs_int32);
2998 fprintf(stderr,"No sysname name value was found\n");
3001 space[blob.out_size - 1] = '\0';
3002 printf("Current sysname%s is", setp > 1 ? " list" : "");
3003 for (; setp > 0; --setp ) {
3004 printf(" \'%s\'", input);
3005 input += strlen(input) + 1;
3011 #ifndef AFS_NT40_ENV
3012 static char *exported_types[] = {"null", "nfs", ""};
3013 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
3016 struct ViceIoctl blob;
3017 struct cmd_item *ti;
3018 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
3019 int exportcall, pwsync = 0, smounts = 0;
3023 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3028 fprintf (stderr,"Permission denied: requires root access.\n");
3033 ti = as->parms[0].items;
3034 if (strcmp(ti->data, "nfs") == 0)
3035 type = 0x71; /* NFS */
3038 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
3041 ti = as->parms[1].items;
3043 if (strcmp(ti->data, "on") == 0)
3045 else if (strcmp(ti->data, "off") == 0)
3048 fprintf(stderr, "Illegal argument %s\n", ti->data);
3053 if (ti = as->parms[2].items) { /* -noconvert */
3054 if (strcmp(ti->data, "on") == 0)
3056 else if (strcmp(ti->data, "off") == 0)
3059 fprintf(stderr, "Illegal argument %s\n", ti->data);
3063 if (ti = as->parms[3].items) { /* -uidcheck */
3064 if (strcmp(ti->data, "on") == 0)
3066 else if (strcmp(ti->data, "off") == 0)
3069 fprintf(stderr, "Illegal argument %s\n", ti->data);
3073 if (ti = as->parms[4].items) { /* -submounts */
3074 if (strcmp(ti->data, "on") == 0)
3076 else if (strcmp(ti->data, "off") == 0)
3079 fprintf(stderr, "Illegal argument %s\n", ti->data);
3083 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
3086 blob.in = (char *) &exportcall;
3087 blob.in_size = sizeof(afs_int32);
3088 blob.out = (char *) &exportcall;
3089 blob.out_size = sizeof(afs_int32);
3090 code = pioctl_utf8(0, VIOC_EXPORTAFS, &blob, 1);
3092 if (errno == ENODEV) {
3094 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
3101 if (exportcall & 1) {
3102 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
3103 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
3104 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
3105 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
3107 printf("'%s' translator is disabled\n", exported_types[type]);
3116 GetCellCmd(struct cmd_syndesc *as, void *arock)
3119 struct ViceIoctl blob;
3120 struct afsconf_cell info;
3121 struct cmd_item *ti;
3128 memset(&info, 0, sizeof(info));
3129 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3130 for(ti=as->parms[0].items; ti; ti=ti->next) {
3132 blob.out_size = sizeof(args);
3133 blob.out = (caddr_t) &args;
3134 code = GetCellName(ti->data, &info);
3139 if (info.linkedCell)
3140 free(info.linkedCell);
3141 blob.in_size = 1+(long)strlen(info.name);
3142 blob.in = info.name;
3143 code = pioctl_utf8(0, VIOC_GETCELLSTATUS, &blob, 1);
3145 if (errno == ENOENT)
3146 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3148 Die(errno, info.name);
3152 printf("Cell %s status: ", info.name);
3158 printf("no setuid allowed");
3160 printf("setuid allowed");
3162 printf(", using old VLDB");
3168 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3171 struct ViceIoctl blob;
3172 struct afsconf_cell info;
3173 struct cmd_item *ti;
3181 memset(&info, 0, sizeof(info));
3183 /* Check arguments. */
3184 if (as->parms[1].items && as->parms[2].items) {
3185 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3189 /* figure stuff to set */
3195 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3200 fprintf (stderr,"Permission denied: requires root access.\n");
3205 if (! as->parms[1].items)
3206 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3208 /* set stat for all listed cells */
3209 for(ti=as->parms[0].items; ti; ti=ti->next) {
3211 code = GetCellName(ti->data, &info);
3216 if (info.linkedCell)
3217 free(info.linkedCell);
3218 strcpy(args.cname, info.name);
3219 blob.in_size = sizeof(args);
3220 blob.in = (caddr_t) &args;
3222 blob.out = (caddr_t) 0;
3223 code = pioctl_utf8(0, VIOC_SETCELLSTATUS, &blob, 1);
3225 Die(errno, info.name); /* XXX added cell name to Die() call */
3233 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3235 strcpy(infop->name, cellNamep);
3240 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3245 cm_GetConfigDir(confDir, sizeof(confDir));
3247 code = ugen_ClientInit(noAuthFlag, confDir,
3248 info->name, 0, &uclient,
3249 NULL, pn, rxkad_clear,
3250 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3251 0, 0, USER_SERVICE_ID);
3256 static struct ViceIoctl gblob;
3257 static int debug = 0;
3259 * here follow some routines in suport of the setserverprefs and
3260 * getserverprefs commands. They are:
3261 * SetPrefCmd "top-level" routine
3262 * addServer adds a server to the list of servers to be poked into the
3263 * kernel. Will poke the list into the kernel if it threatens
3265 * pokeServers pokes the existing list of servers and ranks into the kernel
3266 * GetPrefCmd reads the Cache Manager's current list of server ranks
3275 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3277 ssp = (cm_SSetPref_t *)space;
3278 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3284 * returns -1 if error message printed,
3286 * errno value if error and no error message printed
3293 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3294 if (code && (errno == EINVAL)) {
3295 struct setspref *ssp;
3296 ssp = (struct setspref *)gblob.in;
3297 if (!(ssp->flags & DBservers)) {
3298 gblob.in = (void *)&(ssp->servers[0]);
3299 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3300 code = pioctl_utf8(0, VIOC_SETSPREFS33, &gblob, 1);
3301 return code ? errno : 0;
3304 "This cache manager does not support VL server preferences.\n");
3308 return code ? errno : 0;
3314 addServer(char *name, unsigned short rank)
3319 struct hostent *thostent;
3323 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3325 #define MAXUSHORT ((unsigned short) ~0)
3330 thostent = hostutil_GetHostByName(name);
3332 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3336 ssp = (cm_SSetPref_t *)(gblob.in);
3338 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3339 code = pokeServers();
3340 ssp->num_servers = 0;
3343 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3344 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3345 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3346 gblob.in_size += sizeof(cm_SPref_t);
3349 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3355 * returns -1 if error message printed,
3357 * errno value if error and no error message printed
3360 addServer(char *name, afs_int32 rank)
3363 struct setspref *ssp;
3365 struct hostent *thostent;
3371 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3373 #define MAXUSHORT ((unsigned short) ~0)
3377 thostent = hostutil_GetHostByName(name);
3379 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3383 ssp = (struct setspref *)(gblob.in);
3385 for (t = 0; thostent->h_addr_list[t]; t++) {
3386 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3387 code = pokeServers();
3390 ssp->num_servers = 0;
3393 sp = (struct spref *)(gblob.in + gblob.in_size);
3394 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3395 sizeof(afs_uint32));
3396 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3397 gblob.in_size += sizeof(struct spref);
3401 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3402 name, sp->rank, sp->server.s_addr);
3410 static BOOL IsWindowsNT (void)
3412 static BOOL fChecked = FALSE;
3413 static BOOL fIsWinNT = FALSE;
3417 OSVERSIONINFO Version;
3421 memset (&Version, 0x00, sizeof(Version));
3422 Version.dwOSVersionInfoSize = sizeof(Version);
3424 if (GetVersionEx (&Version))
3426 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3436 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3440 struct cmd_item *ti;
3445 ssp = (cm_SSetPref_t *)space;
3447 ssp->num_servers = 0;
3448 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3451 gblob.out_size = MAXSIZE;
3454 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3460 ti = as->parms[2].items; /* -file */
3462 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3463 if (!(infd = fopen(ti->data,"r" ))) {
3465 Die(errno,ti->data);
3468 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3469 code = addServer (name, (unsigned short) rank);
3473 ti = as->parms[3].items; /* -stdin */
3475 while ( scanf("%79s%ld", name, &rank) != EOF) {
3476 code = addServer (name, (unsigned short) rank);
3480 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3485 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3487 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3491 code = pokeServers();
3493 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3495 ssp = (cm_SSetPref_t *)space;
3496 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3498 ssp->flags = CM_SPREF_VLONLY;
3499 ssp->num_servers = 0;
3501 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3506 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3508 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3513 if (as->parms[1].items) {
3515 printf("now poking vlservers\n");
3516 code = pokeServers();
3526 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3530 struct cmd_item *ti;
3533 struct setspref *ssp;
3534 int error = 0; /* -1 means error message printed,
3535 * >0 means errno value for unprinted message */
3537 ssp = (struct setspref *)space;
3539 ssp->num_servers = 0;
3540 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3543 gblob.out_size = MAXSIZE;
3547 fprintf(stderr, "Permission denied: requires root access.\n");
3551 ti = as->parms[2].items; /* -file */
3554 fprintf(stderr, "opening file %s\n", ti->data);
3555 if (!(infd = fopen(ti->data, "r"))) {
3559 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3560 code = addServer(name, (unsigned short)rank);
3567 ti = as->parms[3].items; /* -stdin */
3569 while (scanf("%79s%ld", name, &rank) != EOF) {
3570 code = addServer(name, (unsigned short)rank);
3576 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3581 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3585 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3589 code = pokeServers();
3593 printf("now working on vlservers, code=%d\n", code);
3595 ssp = (struct setspref *)space;
3596 ssp->flags = DBservers;
3597 ssp->num_servers = 0;
3598 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3601 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3606 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3610 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3615 if (as->parms[1].items) {
3617 printf("now poking vlservers\n");
3618 code = pokeServers();
3626 return error ? 1 : 0;
3632 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3635 struct cmd_item *ti;
3636 char *name, tbuffer[20];
3641 struct ViceIoctl blob;
3642 struct cm_SPrefRequest *in;
3643 struct cm_SPrefInfo *out;
3647 ti = as->parms[0].items; /* -file */
3649 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3650 if (!(outfd = freopen(ti->data,"w",stdout))) {
3651 Die(errno,ti->data);
3656 ti = as->parms[1].items; /* -numeric */
3658 ti = as->parms[2].items; /* -vlservers */
3659 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3660 /* ti = as->parms[3].items; -cell */
3662 in = (struct cm_SPrefRequest *)space;
3666 blob.in_size=sizeof(struct cm_SPrefRequest);
3667 blob.in = (char *)in;
3669 blob.out_size = MAXSIZE;
3671 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3672 in->flags = vlservers;
3674 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3676 perror("getserverprefs pioctl");
3680 out = (struct cm_SPrefInfo *) blob.out;
3682 for (i=0;i<out->num_servers;i++) {
3684 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3687 addr = ntohl(out->servers[i].host.s_addr);
3688 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3689 (addr>>8) & 0xff, addr & 0xff);
3692 printf ("%-50s %5u\n",name,out->servers[i].rank);
3695 in->offset = out->next_offset;
3697 } while (!code && out->next_offset > 0);
3703 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3706 struct cmd_item *ti;
3707 char *name, tbuffer[20];
3708 afs_int32 rank, addr;
3712 struct ViceIoctl blob;
3713 struct sprefrequest *in;
3714 struct sprefinfo *out;
3717 ti = as->parms[0].items; /* -file */
3720 fprintf(stderr, "opening file %s\n", ti->data);
3721 if (!(outfd = freopen(ti->data, "w", stdout))) {
3727 ti = as->parms[1].items; /* -numeric */
3729 ti = as->parms[2].items; /* -vlservers */
3730 vlservers |= (ti ? DBservers : 0);
3731 /* ti = as->parms[3].items; -cell */
3733 in = (struct sprefrequest *)space;
3737 blob.in_size = sizeof(struct sprefrequest);
3738 blob.in = (char *)in;
3740 blob.out_size = MAXSIZE;
3743 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3744 in->flags = vlservers;
3746 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3748 perror("getserverprefs pioctl");
3752 out = (struct sprefinfo *)blob.out;
3754 for (i = 0; i < out->num_servers; i++) {
3756 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3758 addr = ntohl(out->servers[i].server.s_addr);
3759 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3760 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3763 printf("%-50s %5u\n", name, out->servers[i].rank);
3766 in->offset = out->next_offset;
3767 } while (out->next_offset > 0);
3774 SmbUnicodeCmd(struct cmd_syndesc * asp, void * arock)
3780 struct ViceIoctl blob;
3782 if (asp->parms[0].items) {
3786 } else if (asp->parms[1].items) {
3792 if (inValue != 0 && !IsAdmin()) {
3793 fprintf (stderr, "Permission denied: Requires AFS Client Administrator access.\n");
3797 blob.in_size = sizeof(inValue);
3798 blob.in = (char *) &inValue;
3799 blob.out_size = sizeof(outValue);
3800 blob.out = (char *) &outValue;
3802 code = pioctl_utf8(NULL, VIOC_UNICODECTL, &blob, 1);
3808 if (outValue != 2) {
3809 printf("Unicode support is %s%s.\n",
3810 ((outValue != 0)? "enabled":"disabled"),
3811 ((inValue != 0)? " for new SMB connections":""));
3813 printf("Unicode support is absent in this installation of OpenAFS.\n");
3820 GetFidCmd(struct cmd_syndesc *as, void *arock)
3823 struct ViceIoctl blob;
3824 struct cmd_item *ti;
3827 cm_ioctlQueryOptions_t options;
3829 if (as->parms[1].items)
3832 SetDotDefault(&as->parms[0].items);
3833 for(ti=as->parms[0].items; ti; ti=ti->next) {
3835 afs_uint32 filetype;
3836 char cell[CELL_MAXNAMELEN];
3839 memset(&fid, 0, sizeof(fid));
3840 memset(&options, 0, sizeof(options));
3842 options.size = sizeof(options);
3843 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
3844 options.literal = literal;
3845 blob.in_size = options.size; /* no variable length data */
3848 blob.out_size = sizeof(cm_fid_t);
3849 blob.out = (char *) &fid;
3850 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
3851 blob.out_size == sizeof(cm_fid_t)) {
3852 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
3855 Die(errno, ti->data);
3860 blob.out_size = sizeof(filetype);
3861 blob.out = &filetype;
3863 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
3864 if (code || blob.out_size != sizeof(filetype)) {
3865 Die(errno, ti->data);
3869 blob.out_size = CELL_MAXNAMELEN;
3872 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
3874 cell[CELL_MAXNAMELEN - 1] = '\0';
3875 printf("%s %s (%u.%u.%u) contained in cell %s\n",
3876 filetypestr(filetype),
3877 ti->data, fid.volume, fid.vnode, fid.unique,
3878 code ? "unknown-cell" : cell);
3884 UuidCmd(struct cmd_syndesc *asp, void *arock)
3889 struct ViceIoctl blob;
3890 char * uuidstring = NULL;
3892 if (asp->parms[0].items) {
3895 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3900 fprintf (stderr, "Permission denied: requires root access.\n");
3904 inValue = 1; /* generate new UUID */
3906 inValue = 0; /* just show the current UUID */
3909 blob.in_size = sizeof(inValue);
3910 blob.in = (char *) &inValue;
3911 blob.out_size = sizeof(outValue);
3912 blob.out = (char *) &outValue;
3914 code = pioctl_utf8(NULL, VIOC_UUIDCTL, &blob, 1);
3915 if (code || blob.out_size != sizeof(outValue)) {
3920 UuidToString((UUID *) &outValue, &uuidstring);
3922 printf("%sUUID: %s",
3923 ((inValue == 1)?"New ":""),
3927 RpcStringFree(&uuidstring);
3933 TraceCmd(struct cmd_syndesc *asp, void *arock)
3936 struct ViceIoctl blob;
3942 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3947 fprintf (stderr,"Permission denied: requires root access.\n");
3952 if ((asp->parms[0].items && asp->parms[1].items)) {
3953 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
3957 /* determine if we're turning this tracing on or off */
3959 if (asp->parms[0].items)
3960 inValue = 3; /* enable */
3961 else if (asp->parms[1].items)
3962 inValue = 2; /* disable */
3963 if (asp->parms[2].items)
3964 inValue |= 4; /* do reset */
3965 if (asp->parms[3].items)
3966 inValue |= 8; /* dump */
3968 blob.in_size = sizeof(long);
3969 blob.in = (char *) &inValue;
3970 blob.out_size = sizeof(long);
3971 blob.out = (char *) &outValue;
3973 code = pioctl_utf8(NULL, VIOC_TRACECTL, &blob, 1);
3974 if (code || blob.out_size != sizeof(long)) {
3980 printf("AFS tracing enabled.\n");
3982 printf("AFS tracing disabled.\n");
3987 static void sbusage(void)
3989 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
3990 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
3993 /* fs sb -kbytes 9999 -files *.o -default 64 */
3995 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3998 struct ViceIoctl blob;
3999 struct cmd_item *ti;
4000 struct sbstruct tsb, tsb2;
4008 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4013 tsb.sb_thisfile = -1;
4014 ti = as->parms[0].items; /* -kbytes */
4016 if (!as->parms[1].items) {
4017 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
4021 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
4022 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
4023 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
4029 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
4030 ti = as->parms[2].items; /* -allfiles */
4032 allfiles = strtol(ti->data, &t, 10) * 1024;
4033 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
4034 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
4040 /* -verbose or -file only or no options */
4041 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
4042 || (!as->parms[0].items && !as->parms[1].items
4043 && !as->parms[2].items))
4046 blob.in = (char *)&tsb;
4047 blob.out = (char *)&tsb2;
4048 blob.in_size = blob.out_size = sizeof(struct sbstruct);
4049 memset(&tsb2, 0, sizeof(tsb2));
4051 /* once per -file */
4052 for (ti = as->parms[1].items; ti; ti = ti->next) {
4053 /* Do this solely to see if the file is there */
4054 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
4056 Die(errno, ti->data);
4061 code = pioctl_utf8(ti->data, VIOC_STOREBEHIND, &blob, 1);
4063 Die(errno, ti->data);
4068 if (verbose && (blob.out_size == sizeof(tsb2))) {
4069 if (tsb2.sb_thisfile == -1) {
4070 fprintf(stdout, "Will store %s according to default.\n",
4074 "Will store up to %d kbytes of %s asynchronously.\n",
4075 (tsb2.sb_thisfile / 1024), ti->data);
4080 /* If no files - make at least one pioctl call, or
4081 * set the allfiles default if we need to.
4083 if (!as->parms[1].items || (allfiles != -1)) {
4084 tsb.sb_default = allfiles;
4085 code = pioctl_utf8(0, VIOC_STOREBEHIND, &blob, 1);
4087 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
4092 /* Having no arguments also reports the default store asynchrony */
4093 if (verbose && (blob.out_size == sizeof(tsb2))) {
4094 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
4095 (tsb2.sb_default / 1024));
4102 SetCryptCmd(struct cmd_syndesc *as, void *arock)
4104 afs_int32 code = 0, flag;
4105 struct ViceIoctl blob;
4110 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4115 tp = as->parms[0].items->data;
4116 if (strcmp(tp, "on") == 0)
4118 else if (strcmp(tp, "off") == 0)
4120 else if (strcmp(tp, "auth") == 0)
4123 fprintf (stderr, "%s: %s must be \"on\", \"auth\", or \"off\".\n", pn, tp);
4127 blob.in = (char *) &flag;
4128 blob.in_size = sizeof(flag);
4130 code = pioctl_utf8(0, VIOC_SETRXKCRYPT, &blob, 1);
4137 GetCryptCmd(struct cmd_syndesc *as, void *arock)
4139 afs_int32 code = 0, flag;
4140 struct ViceIoctl blob;
4145 blob.out_size = sizeof(flag);
4148 code = pioctl_utf8(0, VIOC_GETRXKCRYPT, &blob, 1);
4150 if (code || blob.out_size != sizeof(flag))
4154 memcpy(&flag, tp, sizeof(afs_int32));
4155 printf("Security level is currently ");
4157 printf("auth (data integrity).\n");
4159 printf("crypt (data security).\n");
4167 MemDumpCmd(struct cmd_syndesc *asp, void *arock)
4170 struct ViceIoctl blob;
4175 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4179 if ((asp->parms[0].items && asp->parms[1].items)) {
4180 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
4184 /* determine if we're turning this tracing on or off */
4185 if (asp->parms[0].items)
4186 inValue = 1; /* begin */
4187 else if (asp->parms[1].items)
4188 inValue = 0; /* end */
4191 blob.in_size = sizeof(long);
4192 blob.in = (char *) &inValue;
4193 blob.out_size = sizeof(long);
4194 blob.out = (char *) &outValue;
4196 code = pioctl_utf8(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
4197 if (code || blob.out_size != sizeof(long)) {
4203 printf("AFS memdump created.\n");
4206 printf("AFS memdump failed.\n");
4212 MiniDumpCmd(struct cmd_syndesc *asp, void *arock)
4215 SERVICE_STATUS status;
4216 SC_HANDLE hManager = NULL;
4217 SC_HANDLE hService = NULL;
4220 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4224 hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
4228 hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
4232 success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
4235 CloseServiceHandle(hService);
4236 CloseServiceHandle(hManager);
4238 printf("AFS minidump generated.\n");
4244 CloseServiceHandle(hService);
4246 CloseServiceHandle(hManager);
4248 printf("AFS minidump failed.\n");
4253 CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
4255 struct cmd_item *ti;
4260 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4264 for(ti=asp->parms[0].items; ti;ti=ti->next) {
4276 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4277 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4280 REG_OPTION_NON_VOLATILE,
4281 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
4286 if ( hkCSCPolicy == NULL ) {
4287 fprintf (stderr,"Permission denied: requires Administrator access.\n");
4292 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4293 RegCloseKey(hkCSCPolicy);
4299 if (asp->parms[1].items)
4301 if (asp->parms[2].items)
4302 policy = "programs";
4303 if (asp->parms[3].items)
4304 policy = "documents";
4305 if (asp->parms[4].items)
4308 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, (DWORD)strlen(policy)+1);
4310 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
4311 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
4315 DWORD dwIndex, dwPolicies;
4316 char policyName[256];
4317 DWORD policyNameLen;
4322 /* list current csc policies */
4324 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4325 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4328 REG_OPTION_NON_VOLATILE,
4329 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_QUERY_VALUE,
4334 RegQueryInfoKey( hkCSCPolicy,
4336 NULL, /* lpcClass */
4337 NULL, /* lpReserved */
4338 NULL, /* lpcSubKeys */
4339 NULL, /* lpcMaxSubKeyLen */
4340 NULL, /* lpcMaxClassLen */
4341 &dwPolicies, /* lpcValues */
4342 NULL, /* lpcMaxValueNameLen */
4343 NULL, /* lpcMaxValueLen */
4344 NULL, /* lpcbSecurityDescriptor */
4345 NULL /* lpftLastWriteTime */
4348 printf("Current CSC policies:\n");
4349 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
4351 policyNameLen = sizeof(policyName);
4352 policyLen = sizeof(policy);
4353 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
4354 &dwType, policy, &policyLen);
4356 printf(" %s = %s\n", policyName, policy);
4360 RegCloseKey(hkCSCPolicy);
4365 /* get clients interface addresses */
4367 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4370 struct cmd_item *ti;
4372 struct ViceIoctl blob;
4373 struct sprefrequest *in;
4374 struct sprefinfo *out;
4376 in = (struct sprefrequest *)space;
4380 blob.in_size = sizeof(struct sprefrequest);
4381 blob.in = (char *)in;
4383 blob.out_size = MAXSIZE;
4386 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4387 /* returns addr in network byte order */
4388 code = pioctl_utf8(0, VIOC_GETCPREFS, &blob, 1);
4390 perror("getClientInterfaceAddr pioctl");
4396 out = (struct sprefinfo *)blob.out;
4397 for (i = 0; i < out->num_servers; i++) {
4400 addr = ntohl(out->servers[i].server.s_addr);
4401 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
4402 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
4403 printf("%-50s\n", tbuffer);
4405 in->offset = out->next_offset;
4407 } while (out->next_offset > 0);
4413 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4415 afs_int32 code, addr;
4416 struct cmd_item *ti;
4418 struct ViceIoctl blob;
4419 struct setspref *ssp;
4420 int sizeUsed = 0, i, flag;
4421 afs_int32 existingAddr[1024]; /* existing addresses on this host */
4425 ssp = (struct setspref *)space;
4426 ssp->num_servers = 0;
4429 blob.out_size = MAXSIZE;
4432 fprintf(stderr, "Permission denied: requires root access.\n");
4436 /* extract all existing interface addresses */
4437 existNu = rx_getAllAddr(existingAddr, 1024);
4441 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4442 for (ti = as->parms[0].items; ti; ti = ti->next) {
4443 if (sizeUsed >= sizeof(space)) {
4444 fprintf(stderr, "No more space\n");
4447 addr = extractAddr(ti->data, 20); /* network order */
4448 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4449 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4454 /* see if it is an address that really exists */
4455 for (flag = 0, i = 0; i < existNu; i++)
4456 if (existingAddr[i] == addr) {
4460 if (!flag) { /* this is an nonexistent address */
4461 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4465 /* copy all specified addr into ioctl buffer */
4466 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4467 printf("Adding 0x%08x\n", addr);
4469 sizeUsed += sizeof(struct spref);
4471 if (ssp->num_servers < 1) {
4472 fprintf(stderr, "No addresses specified\n");
4475 blob.in_size = sizeUsed - sizeof(struct spref);
4477 code = pioctl_utf8(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4487 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4490 struct ViceIoctl blob;
4491 struct cmd_item *ti;
4492 char orig_name[1024]; /*Original name, may be modified */
4493 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4494 char parent_dir[1024]; /*Parent directory of true name */
4495 char *last_component; /*Last component of true name */
4496 struct stat statbuff; /*Buffer for status info */
4497 int link_chars_read; /*Num chars read in readlink() */
4498 int thru_symlink; /*Did we get to a mount point via a symlink? */
4501 for (ti = as->parms[0].items; ti; ti = ti->next) {
4504 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4507 if (lstat(orig_name, &statbuff) < 0) {
4508 /* if lstat fails, we should still try the pioctl, since it
4509 * may work (for example, lstat will fail, but pioctl will
4510 * work if the volume of offline (returning ENODEV). */
4511 statbuff.st_mode = S_IFDIR; /* lie like pros */
4515 * The lstat succeeded. If the given file is a symlink, substitute
4516 * the file name with the link name.
4518 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4521 * Read name of resolved file.
4523 link_chars_read = readlink(orig_name, true_name, 1024);
4524 if (link_chars_read <= 0) {
4526 "%s: Can't read target name for '%s' symbolic link!\n",
4533 * Add a trailing null to what was read, bump the length.
4535 true_name[link_chars_read++] = 0;
4538 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4539 * have to create a full pathname using the original name and the
4540 * relative symlink name. Find the rightmost slash in the original
4541 * name (we know there is one) and splice in the symlink value.
4543 if (true_name[0] != '/') {
4544 last_component = (char *)strrchr(orig_name, '/');
4545 strcpy(++last_component, true_name);
4546 strcpy(true_name, orig_name);
4549 strcpy(true_name, orig_name);
4552 * Find rightmost slash, if any.
4554 last_component = (char *)strrchr(true_name, '/');
4555 if (last_component) {
4557 * Found it. Designate everything before it as the parent directory,
4558 * everything after it as the final component.
4560 strncpy(parent_dir, true_name, last_component - true_name);
4561 parent_dir[last_component - true_name] = 0;
4562 last_component++; /*Skip the slash */
4565 * No slash appears in the given file name. Set parent_dir to the current
4566 * directory, and the last component as the given name.
4568 strcpy(parent_dir, ".");
4569 last_component = true_name;
4572 if (strcmp(last_component, ".") == 0
4573 || strcmp(last_component, "..") == 0) {
4575 "%s: you may not use '.' or '..' as the last component\n",
4577 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4583 blob.in = last_component;
4584 blob.in_size = strlen(last_component) + 1;
4586 memset(space, 0, MAXSIZE);
4588 code = pioctl_utf8(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4591 if (errno == EINVAL) {
4592 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4594 Die(errno, (ti->data ? ti->data : parent_dir));
4604 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4607 afs_int32 flags = 0;
4608 struct ViceIoctl blob;
4610 if (as->parms[0].items) { /* -enable */
4611 flags |= AFSCALL_RXSTATS_ENABLE;
4613 if (as->parms[1].items) { /* -disable */
4614 flags |= AFSCALL_RXSTATS_DISABLE;
4616 if (as->parms[2].items) { /* -clear */
4617 flags |= AFSCALL_RXSTATS_CLEAR;
4620 fprintf(stderr, "You must specify at least one argument\n");
4624 blob.in = (char *)&flags;
4625 blob.in_size = sizeof(afs_int32);
4628 code = pioctl_utf8(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4638 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4641 afs_int32 flags = 0;
4642 struct ViceIoctl blob;
4644 if (as->parms[0].items) { /* -enable */
4645 flags |= AFSCALL_RXSTATS_ENABLE;
4647 if (as->parms[1].items) { /* -disable */
4648 flags |= AFSCALL_RXSTATS_DISABLE;
4650 if (as->parms[2].items) { /* -clear */
4651 flags |= AFSCALL_RXSTATS_CLEAR;
4654 fprintf(stderr, "You must specify at least one argument\n");
4658 blob.in = (char *)&flags;
4659 blob.in_size = sizeof(afs_int32);
4662 code = pioctl_utf8(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4672 TestVolStatCmd(struct cmd_syndesc *as, void *arock)
4675 struct VolStatTest test;
4676 struct ViceIoctl blob;
4680 memset(&test, 0, sizeof(test));
4682 if (as->parms[0].items) { /* -network */
4683 tp = as->parms[0].items->data;
4684 if (strcmp(tp, "up") == 0)
4685 test.flags |= VOLSTAT_TEST_NETWORK_UP;
4686 else if (strcmp(tp, "down") == 0)
4687 test.flags |= VOLSTAT_TEST_NETWORK_DOWN;
4689 fprintf (stderr, "%s: %s must be \"up\" or \"down\".\n", pn, tp);
4693 if (as->parms[1].items) { /* check */
4694 test.flags |= VOLSTAT_TEST_CHECK_VOLUME;
4696 if (as->parms[2].items) { /* cell */
4697 tp = as->parms[2].items->data;
4702 strncpy(test.cellname, tp, sizeof(test.cellname));
4703 test.cellname[sizeof(test.cellname)-1] = '\0';
4706 if (as->parms[3].items) { /* volume */
4707 tp = as->parms[3].items->data;
4710 test.fid.volume = n;
4712 strncpy(test.volname, tp, sizeof(test.volname));
4713 test.volname[sizeof(test.volname)-1] = '\0';
4716 if (as->parms[4].items) { /* state */
4717 tp = as->parms[4].items->data;
4718 if (strcmp(tp, "online") == 0)
4719 test.state = vl_online;
4720 else if (strcmp(tp, "busy") == 0)
4721 test.state = vl_busy;
4722 else if (strcmp(tp, "offline") == 0)
4723 test.state = vl_offline;
4724 else if (strcmp(tp, "down") == 0)
4725 test.state = vl_alldown;
4727 fprintf (stderr, "%s: %s must be \"online\", \"busy\", \"offline\" or \"down\".\n", pn, tp);
4732 if ((test.fid.cell || test.cellname[0]) && !(test.fid.volume || test.volname[0]) ||
4733 !(test.fid.cell || test.cellname[0]) && (test.fid.volume || test.volname[0])) {
4734 fprintf (stderr, "%s: both a cell and a volume must be specified.\n", pn, tp);
4738 blob.in = (char *)&test;
4739 blob.in_size = sizeof(test);
4742 code = pioctl_utf8(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
4752 ChOwnCmd(struct cmd_syndesc *as, void *arock)
4755 struct ViceIoctl blob;
4756 struct cmd_item *ti;
4760 cm_ioctlQueryOptions_t options;
4767 cm_GetConfigDir(confDir, sizeof(confDir));
4769 if (as->parms[2].items)
4772 ownerStr = as->parms[0].items->data;
4773 ownerId = atoi(ownerStr);
4775 SetDotDefault(&as->parms[1].items);
4776 for(ti=as->parms[1].items; ti; ti=ti->next) {
4778 afs_uint32 filetype;
4779 char cell[CELL_MAXNAMELEN];
4782 memset(&fid, 0, sizeof(fid));
4783 memset(&inData, 0, sizeof(inData));
4785 inData.options.size = sizeof(inData.options);
4786 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
4787 inData.options.literal = literal;
4788 blob.in_size = inData.options.size; /* no variable length data */
4791 blob.out_size = sizeof(cm_fid_t);
4792 blob.out = (char *) &fid;
4793 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
4794 blob.out_size == sizeof(cm_fid_t)) {
4795 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
4796 inData.options.fid = fid;
4798 Die(errno, ti->data);
4804 * if the owner was specified as a numeric value,
4805 * then we can just use it. Otherwise, we need
4806 * to know the cell of the path to determine which
4807 * ptserver to contact in order to convert the name
4808 * to a numeric value.
4811 blob.out_size = CELL_MAXNAMELEN;
4814 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
4816 Die(errno, ti->data);
4820 cell[CELL_MAXNAMELEN - 1] = '\0';
4822 * We now know the cell for the target and we need to
4823 * convert the ownerStr to the Id for this user
4825 pr_Initialize(1, confDir, cell);
4826 code = pr_SNameToId(ownerStr, &inData.owner);
4829 if (code || inData.owner == ANONYMOUSID ) {
4830 Die(ECHILD, ti->data);
4835 inData.owner = ownerId;
4838 blob.in_size = sizeof(inData);
4841 code = pioctl_utf8(ti->data, VIOC_SETOWNER, &blob, 1);
4843 Die(errno, ti->data);
4850 ChGrpCmd(struct cmd_syndesc *as, void *arock)
4853 struct ViceIoctl blob;
4854 struct cmd_item *ti;
4858 cm_ioctlQueryOptions_t options;
4865 cm_GetConfigDir(confDir, sizeof(confDir));
4867 if (as->parms[2].items)
4870 groupStr = as->parms[0].items->data;
4871 groupId = atoi(groupStr);
4873 SetDotDefault(&as->parms[1].items);
4874 for(ti=as->parms[1].items; ti; ti=ti->next) {
4876 afs_uint32 filetype;
4877 char cell[CELL_MAXNAMELEN];
4880 memset(&fid, 0, sizeof(fid));
4881 memset(&inData, 0, sizeof(inData));
4883 inData.options.size = sizeof(inData.options);
4884 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
4885 inData.options.literal = literal;
4886 blob.in_size = inData.options.size; /* no variable length data */
4889 blob.out_size = sizeof(cm_fid_t);
4890 blob.out = (char *) &fid;
4891 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
4892 blob.out_size == sizeof(cm_fid_t)) {
4893 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
4894 inData.options.fid = fid;
4896 Die(errno, ti->data);
4902 * if the group was specified as a numeric value,
4903 * then we can just use it. Otherwise, we need
4904 * to know the cell of the path to determine which
4905 * ptserver to contact in order to convert the name
4906 * to a numeric value.
4909 blob.out_size = CELL_MAXNAMELEN;
4912 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
4914 Die(errno, ti->data);
4918 cell[CELL_MAXNAMELEN - 1] = '\0';
4920 * We now know the cell for the target and we need to
4921 * convert the groupStr to the Id for this user
4923 pr_Initialize(1, confDir, cell);
4924 code = pr_SNameToId(groupStr, &inData.group);
4927 if (code || inData.group == ANONYMOUSID ) {
4928 Die(ECHILD, ti->data);
4933 inData.group = groupId;
4936 blob.in_size = sizeof(inData);
4939 code = pioctl_utf8(ti->data, VIOC_SETGROUP, &blob, 1);
4941 Die(errno, ti->data);
4948 #include "AFS_component_version_number.c"
4952 FreeUtf8CmdLine(int argc, char ** argv)
4955 for (i=0; i < argc; i++) {
4963 MakeUtf8Cmdline(int argc, const wchar_t **wargv)
4968 argv = calloc(argc, sizeof(argv[0]));
4972 for (i=0; i < argc; i++) {
4975 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, FALSE);
4977 (argv[i] = calloc(s+1, sizeof(char))) == NULL) {
4981 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], s+1, NULL, FALSE);
4988 FreeUtf8CmdLine(argc, argv);
4995 int wmain(int argc, wchar_t **wargv)
4998 struct cmd_syndesc *ts;
5001 #ifdef AFS_AIX32_ENV
5003 * The following signal action for AIX is necessary so that in case of a
5004 * crash (i.e. core is generated) we can include the user's data section
5005 * in the core dump. Unfortunately, by default, only a partial core is
5006 * generated which, in many cases, isn't too useful.
5008 struct sigaction nsa;
5010 sigemptyset(&nsa.sa_mask);
5011 nsa.sa_handler = SIG_DFL;
5012 nsa.sa_flags = SA_FULLDUMP;
5013 sigaction(SIGSEGV, &nsa, NULL);
5018 WSAStartup(0x0101, &WSAjunk);
5021 argv = MakeUtf8Cmdline(argc, wargv);
5023 /* try to find volume location information */
5027 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
5028 "get client network interface addresses");
5029 cmd_CreateAlias(ts, "gc");
5031 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
5032 "set client network interface addresses");
5033 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
5034 "client network interfaces");
5035 cmd_CreateAlias(ts, "sc");
5038 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL, "set server ranks");
5039 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
5040 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
5041 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
5042 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
5043 cmd_CreateAlias(ts, "sp");
5045 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL, "get server ranks");
5046 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
5047 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
5048 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
5049 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
5050 cmd_CreateAlias(ts, "gp");
5052 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
5053 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5054 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
5055 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
5056 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
5057 parm_setacl_id = ts->nParms;
5058 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
5059 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
5060 cmd_CreateAlias(ts, "sa");
5062 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL, "list access control list");
5063 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5064 parm_listacl_id = ts->nParms;
5065 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
5066 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
5067 cmd_CreateAlias(ts, "la");
5069 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL, "clean up access control list");
5070 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5072 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL, "copy access control list");
5073 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
5074 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
5075 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
5076 parm_copyacl_id = ts->nParms;
5077 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
5078 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
5080 cmd_CreateAlias(ts, "ca");
5082 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
5083 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5084 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5087 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
5088 "flush mount symlink from cache");
5089 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5092 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
5093 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5094 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
5096 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
5098 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
5099 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
5100 cmd_CreateAlias(ts, "sv");
5102 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL, "control Cache Manager messages");
5103 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
5105 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
5106 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5107 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5108 cmd_CreateAlias(ts, "lv");
5109 cmd_CreateAlias(ts, "listvol");
5111 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
5112 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5113 cmd_CreateAlias(ts, "lq");
5115 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL, "show server disk space usage");
5116 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5117 cmd_CreateAlias(ts, "df");
5119 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
5120 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5122 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
5123 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5125 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
5126 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
5127 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
5128 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
5129 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
5130 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
5136 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
5140 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
5141 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5143 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL, "check local cell's servers");
5144 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
5145 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
5146 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
5147 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
5149 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL, "check volumeID/name mappings");
5150 cmd_CreateAlias(ts, "checkbackups");
5153 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL, "set cache size");
5154 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
5155 cmd_CreateAlias(ts, "cachesize");
5157 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
5159 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL, "get cache usage info");
5161 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL, "list configured cells");
5162 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
5164 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
5165 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
5166 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
5168 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
5170 cmd_CreateAlias(ts, "sq");
5172 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
5174 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
5175 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
5176 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
5178 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
5180 * Turn this on only if you wish to be able to talk to a server which is listening
5181 * on alternative ports. This is not intended for general use and may not be
5182 * supported in the cache manager. It is not a way to run two servers at the
5183 * same host, since the cache manager cannot properly distinguish those two hosts.
5185 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
5186 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
5189 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
5190 "configure new cell alias");
5191 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
5192 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
5195 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
5196 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5197 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5199 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
5200 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5201 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5203 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
5206 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
5209 #ifndef AFS_NT40_ENV
5210 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, "set cache monitor host address");
5211 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
5212 cmd_CreateAlias(ts, "mariner");
5215 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
5216 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
5218 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
5219 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
5220 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
5221 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
5223 ts = cmd_CreateSyntax("flushall", FlushAllCmd, NULL, "flush all data");
5225 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL, "flush all data in volume");
5226 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5228 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL, "get/set sysname (i.e. @sys) value");
5229 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
5231 #ifndef AFS_NT40_ENV
5232 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL, "enable/disable translators to AFS");
5233 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
5234 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
5235 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
5236 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
5237 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
5240 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
5241 "store to server after file close");
5242 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
5243 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
5244 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
5245 cmd_CreateAlias(ts, "sb");
5247 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL, "set cache manager encryption flag");
5248 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
5250 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL, "get cache manager encryption flag");
5252 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
5253 "Manage per process RX statistics");
5254 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
5255 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
5256 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
5258 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
5259 "Manage per peer RX statistics");
5260 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
5261 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
5262 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
5265 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
5266 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
5269 ts = cmd_CreateSyntax("trace", TraceCmd, NULL, "enable or disable CM tracing");
5270 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
5271 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
5272 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
5273 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
5274 cmd_CreateAlias(ts, "tr");
5276 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
5277 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
5279 ts = cmd_CreateSyntax("memdump", MemDumpCmd, NULL, "dump memory allocs in debug builds");
5280 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
5281 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
5283 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, NULL, "change client side caching policy for AFS shares");
5284 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
5285 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
5286 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
5287 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
5288 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
5290 ts = cmd_CreateSyntax("minidump", MiniDumpCmd, NULL, "Generate MiniDump of current service state");
5292 ts = cmd_CreateSyntax("test_volstat", TestVolStatCmd, NULL, (char *)CMD_HIDDEN);
5293 cmd_AddParm(ts, "-network", CMD_SINGLE, CMD_OPTIONAL, "set network state up or down");
5294 cmd_AddParm(ts, "-check", CMD_FLAG, CMD_OPTIONAL, "check state of offline volumes");
5295 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name or number");
5296 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or number");
5297 cmd_AddParm(ts, "-state", CMD_SINGLE, CMD_OPTIONAL, "new volume state: online, busy, offline, down");
5299 ts = cmd_CreateSyntax("smbunicode", SmbUnicodeCmd, NULL, "enable or disable Unicode on new SMB connections");
5300 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable Unicode on new connections");
5301 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable Unicode on new connections");
5303 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL, "get file id for object(s) in afs");
5304 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5305 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5307 ts = cmd_CreateSyntax("chown", ChOwnCmd, NULL, "set owner for object(s) in afs");
5308 cmd_AddParm(ts, "-owner", CMD_SINGLE, 0, "user name or id");
5309 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5310 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5312 ts = cmd_CreateSyntax("chgrp", ChGrpCmd, NULL, "set owner for object(s) in afs");
5313 cmd_AddParm(ts, "-group", CMD_SINGLE, 0, "user/group name or id");
5314 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5315 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5317 code = cmd_Dispatch(argc, argv);
5322 FreeUtf8CmdLine(argc, argv);
5328 Die(int code, char *filename)
5331 if (code == EINVAL) {
5333 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
5335 fprintf(stderr,"%s: Invalid argument.\n", pn);
5337 else if (code == ENOENT) {
5339 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
5341 fprintf(stderr,"%s: no such file returned\n", pn);
5343 else if (code == EROFS)
5344 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
5345 else if (code == EACCES || code == EPERM) {
5347 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
5349 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
5351 else if (code == ENODEV) {
5352 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
5354 else if (code == ESRCH) { /* hack */
5355 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
5357 else if (code == EPIPE) { /* hack */
5358 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
5360 else if (code == EFBIG) {
5361 fprintf(stderr,"%s: Cache size too large.\n", pn);
5363 else if (code == ETIMEDOUT) {
5365 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
5367 fprintf(stderr,"%s: Connection timed out", pn);
5369 else if (code == EBUSY) {
5371 fprintf(stderr,"%s: All servers are busy on which '%s' resides\n", pn, filename);
5373 fprintf(stderr,"%s: All servers are busy\n", pn);
5375 else if (code == ENXIO) {
5377 fprintf(stderr,"%s: All volume instances are offline on which '%s' resides\n", pn, filename);
5379 fprintf(stderr,"%s: All volume instances are offline\n", pn);
5381 else if (code == ENOSYS) {
5383 fprintf(stderr,"%s: All servers are down on which '%s' resides\n", pn, filename);
5385 fprintf(stderr,"%s: All servers are down\n", pn);
5387 else if (code == ECHILD) { /* hack */
5389 fprintf(stderr,"%s: Invalid owner specified for '%s'\n", pn, filename);
5391 fprintf(stderr,"%s: Invalid owner specified\n", pn);
5395 fprintf(stderr,"%s:'%s'", pn, filename);
5397 fprintf(stderr,"%s", pn);
5399 fprintf(stderr, ": code 0x%x\n", code);
5400 #else /* not WIN32 */
5401 fprintf(stderr,": %s\n", afs_error_message(code));
5402 #endif /* not WIN32 */