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;
252 blob.out_size = MAXSIZE;
255 code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
257 if ((errno == EINVAL) || (errno == ENOENT))
264 IsFreelanceRoot(char *apath)
266 struct ViceIoctl blob;
270 blob.out_size = MAXSIZE;
273 code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
275 return !cm_stricmp_utf8N("Freelance.Local.Root",space);
276 return 1; /* assume it is because it is more restrictive that way */
279 /* return a static pointer to a buffer */
284 strcpy(tspace, apath);
285 tp = strrchr(tspace, '\\');
287 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
290 fs_ExtractDriveLetter(apath, tspace);
296 enum rtype {add, destroy, deny};
299 Convert(char *arights, int dfs, enum rtype *rtypep)
305 *rtypep = add; /* add rights, by default */
308 if (!strcmp(arights, "null")) {
312 if (!strcmp(arights,"read"))
313 return DFS_READ | DFS_EXECUTE;
314 if (!strcmp(arights, "write"))
315 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
317 if (!strcmp(arights, "all"))
318 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
319 DFS_WRITE | DFS_CONTROL;
321 if (!strcmp(arights,"read"))
322 return PRSFS_READ | PRSFS_LOOKUP;
323 if (!strcmp(arights, "write"))
324 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
325 PRSFS_WRITE | PRSFS_LOCK;
326 if (!strcmp(arights, "mail"))
327 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
328 if (!strcmp(arights, "all"))
329 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
330 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
332 if (!strcmp(arights, "none")) {
333 *rtypep = destroy; /* Remove entire entry */
336 len = (int)strlen(arights);
372 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
380 mode |= PRSFS_LOOKUP;
382 mode |= PRSFS_INSERT;
384 mode |= PRSFS_DELETE;
390 mode |= PRSFS_ADMINISTER;
408 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
417 static struct AclEntry *
418 FindList (struct AclEntry *alist, char *aname)
421 if (!strcasecmp(alist->name, aname))
428 /* if no parm specified in a particular slot, set parm to be "." instead */
430 SetDotDefault(struct cmd_item **aitemp)
434 return; /* already has value */
435 /* otherwise, allocate an item representing "." */
436 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
438 ti->next = (struct cmd_item *) 0;
439 ti->data = (char *) malloc(2);
441 strcpy(ti->data, ".");
446 ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
448 struct AclEntry *tlist;
449 tlist = (plus ? al->pluslist : al->minuslist);
450 tlist = FindList (tlist, aname);
452 /* Found the item already in the list. */
453 tlist->rights = arights;
455 al->nplus -= PruneList(&al->pluslist, al->dfs);
457 al->nminus -= PruneList(&al->minuslist, al->dfs);
460 /* Otherwise we make a new item and plug in the new data. */
461 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
463 strcpy(tlist->name, aname);
464 tlist->rights = arights;
466 tlist->next = al->pluslist;
467 al->pluslist = tlist;
469 if (arights == 0 || arights == -1)
470 al->nplus -= PruneList(&al->pluslist, al->dfs);
472 tlist->next = al->minuslist;
473 al->minuslist = tlist;
476 al->nminus -= PruneList(&al->minuslist, al->dfs);
481 ZapList (struct AclEntry *alist)
483 struct AclEntry *tp, *np;
484 for (tp = alist; tp; tp = np) {
491 PruneList (struct AclEntry **ae, int dfs)
493 struct AclEntry **lp;
494 struct AclEntry *te, *ne;
498 for(te = *ae;te;te=ne) {
499 if ((!dfs && te->rights == 0) || te->rights == -1) {
513 SkipLine (char *astr)
522 * Create an empty acl, taking into account whether the acl pointed
523 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
524 * can recover from problems caused by bogus ACL's (in that case, always
525 * assume that the acl is AFS: for DFS, the user can always resort to
526 * acl_edit, but for AFS there may be no other way out).
534 tp = (struct Acl *)malloc(sizeof (struct Acl));
536 tp->nplus = tp->nminus = 0;
537 tp->pluslist = tp->minuslist = 0;
539 if (astr == NULL || sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell) <= 0) {
547 ParseAcl (char *astr)
549 int nplus, nminus, i, trights, ret;
551 struct AclEntry *first, *next, *last, *tl;
555 if (astr == NULL || strlen(astr) == 0)
558 ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
563 astr = SkipLine(astr);
564 ret = sscanf(astr, "%d", &ta->nminus);
569 astr = SkipLine(astr);
576 for(i=0;i<nplus;i++) {
577 ret = sscanf(astr, "%100s %d", tname, &trights);
580 astr = SkipLine(astr);
581 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
586 strcpy(tl->name, tname);
587 tl->rights = trights;
593 ta->pluslist = first;
597 for(i=0;i<nminus;i++) {
598 ret = sscanf(astr, "%100s %d", tname, &trights);
601 astr = SkipLine(astr);
602 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
607 strcpy(tl->name, tname);
608 tl->rights = trights;
614 ta->minuslist = first;
619 for (;first; first = next) {
623 first = ta->pluslist;
626 for (;first; first = next) {
635 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
637 printf("Volume status for vid = %u named %s is\n",status->Vid, name);
639 printf("Current offline message is %s\n",offmsg);
641 printf("Current message of the day is %s\n",motd);
642 printf("Current disk quota is ");
643 if (status->MaxQuota != 0)
644 printf("%d\n", status->MaxQuota);
646 printf("unlimited\n");
647 printf("Current blocks used are %d\n",status->BlocksInUse);
648 printf("The partition has %d blocks available out of %d\n",
649 status->PartBlocksAvail, status->PartMaxBlocks);
654 QuickPrintStatus(VolumeStatus *status, char *name)
656 double QuotaUsed =0.0;
657 double PartUsed =0.0;
659 printf("%-25.25s",name);
661 if (status->MaxQuota != 0) {
662 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
663 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
665 printf("no limit%10d", status->BlocksInUse);
667 if (QuotaUsed > 90.0){
668 printf(" %5.0f%%<<", QuotaUsed);
671 printf(" %5.0f%% ", QuotaUsed);
672 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
673 if (PartUsed > 97.0){
674 printf(" %9.0f%%<<", PartUsed);
677 printf(" %9.0f%% ", PartUsed);
679 printf(" <<WARNING\n");
686 QuickPrintSpace(VolumeStatus *status, char *name)
688 double PartUsed =0.0;
690 printf("%-25.25s",name);
692 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
694 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
695 if (PartUsed > 90.0){
696 printf(" %4.0f%%<<", PartUsed);
699 printf(" %4.0f%% ", PartUsed);
701 printf(" <<WARNING\n");
708 AclToString(struct Acl *acl)
710 static char mydata[MAXSIZE];
711 char tstring[MAXSIZE];
716 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
719 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
720 for (tp = acl->pluslist;tp;tp=tp->next) {
721 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
722 strcat(mydata, tstring);
724 for (tp = acl->minuslist;tp;tp=tp->next) {
725 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
726 strcat(mydata, tstring);
731 static DWORD IsFreelance(void)
738 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
739 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
740 if (code == ERROR_SUCCESS) {
741 dummyLen = sizeof(cm_freelanceEnabled);
742 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
743 (BYTE *) &enabled, &dummyLen);
744 RegCloseKey (parmKey);
749 static const char * NetbiosName(void)
751 static char buffer[1024] = "AFS";
757 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
758 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
759 if (code == ERROR_SUCCESS) {
760 dummyLen = sizeof(buffer);
761 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
763 RegCloseKey (parmKey);
765 strcpy(buffer, "AFS");
770 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
772 static BOOL IsAdmin (void)
774 static BOOL fAdmin = FALSE;
775 static BOOL fTested = FALSE;
779 /* Obtain the SID for the AFS client admin group. If the group does
780 * not exist, then assume we have AFS client admin privileges.
782 PSID psidAdmin = NULL;
783 DWORD dwSize, dwSize2;
784 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
785 char *pszRefDomain = NULL;
786 SID_NAME_USE snu = SidTypeGroup;
788 dwSize = sizeof(pszAdminGroup);
790 if (!GetComputerName(pszAdminGroup, &dwSize)) {
791 /* Can't get computer name. We return false in this case.
792 Retain fAdmin and fTested. This shouldn't happen.*/
799 strcat(pszAdminGroup,"\\");
800 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
802 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
803 /* that should always fail. */
805 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
806 /* if we can't find the group, then we allow the operation */
811 if (dwSize == 0 || dwSize2 == 0) {
817 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
819 pszRefDomain = (char *)malloc(dwSize2);
820 assert(pszRefDomain);
822 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
823 /* We can't lookup the group now even though we looked it up earlier.
824 Could this happen? */
827 /* Then open our current ProcessToken */
830 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
833 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
834 /* We'll have to allocate a chunk of memory to store the list of
835 * groups to which this user belongs; find out how much memory
839 PTOKEN_GROUPS pGroups;
841 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
843 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
846 /* Allocate that buffer, and read in the list of groups. */
847 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
849 /* Look through the list of group SIDs and see if any of them
850 * matches the AFS Client Admin group SID.
853 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
855 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
865 /* if do not have permission because we were not explicitly listed
866 * in the Admin Client Group let's see if we are the SYSTEM account
869 PTOKEN_USER pTokenUser;
870 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
871 PSID pSidLocalSystem = 0;
874 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
876 pTokenUser = (PTOKEN_USER)malloc(dwSize);
879 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
880 gle = GetLastError();
882 if (AllocateAndInitializeSid( &SIDAuth, 1,
883 SECURITY_LOCAL_SYSTEM_RID,
887 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
891 FreeSid(pSidLocalSystem);
910 SetACLCmd(struct cmd_syndesc *as, void *arock)
913 struct ViceIoctl blob;
915 struct cmd_item *ti, *ui;
919 int idf = getidf(as, parm_setacl_id);
923 if (as->parms[2].items)
927 plusp = !(as->parms[3].items);
928 for(ti=as->parms[0].items; ti;ti=ti->next) {
929 blob.out_size = MAXSIZE;
931 blob.in = blob.out = space;
932 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
934 Die(errno, ti->data);
940 ta = ParseAcl(space);
943 "fs: %s: invalid acl data returned from VIOCGETAL\n",
948 if (!plusp && ta->dfs) {
950 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
952 "(you may specify \"null\" to revoke all rights, however)\n");
959 ta = EmptyAcl(space);
961 ta = ParseAcl(space);
964 "fs: %s: invalid acl data returned from VIOCGETAL\n",
969 CleanAcl(ta, ti->data);
970 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
974 "%s: Missing second half of user/access pair.\n", pn);
978 rights = Convert(ui->next->data, ta->dfs, &rtype);
979 if (rtype == destroy && !ta->dfs) {
980 struct AclEntry *tlist;
982 tlist = (plusp ? ta->pluslist : ta->minuslist);
983 if (!FindList(tlist, ui->data))
986 if (rtype == deny && !ta->dfs)
988 if (rtype == destroy && ta->dfs)
990 ChangeList(ta, plusp, ui->data, rights);
992 blob.in = AclToString(ta);
994 blob.in_size = 1+(long)strlen(blob.in);
995 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
997 if (errno == EINVAL) {
999 static char *fsenv = 0;
1001 fsenv = (char *)getenv("FS_EXPERT");
1003 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
1006 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1007 "\nPossible reasons for this include:\n\n",
1008 " -You may have specified an inappropriate combination of rights.\n",
1009 " For example, some DFS-supported filesystems may not allow you to\n",
1010 " drop the \"c\" right from \"user_obj\".\n\n",
1011 " -A mask_obj may be required (it is likely required by the underlying\n",
1012 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
1013 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
1014 " does not automatically create or update the mask_obj. Try setting\n",
1015 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
1016 " users or groups. You can do this with a single command, such as\n",
1017 " \"fs sa mask_obj all user:somename read\"\n\n",
1018 " -A specified user or group may not exist.\n\n",
1019 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
1020 " This is probably not allowed by the underlying file system.\n\n",
1021 " -If you add a user or group to a DFS ACL, remember that it must be\n",
1022 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
1023 " may be local requirements on the format of the user or group name.\n",
1024 " Check with your cell administrator.\n\n",
1025 " -Or numerous other possibilities. It would be great if we could be more\n",
1026 " precise about the actual problem, but for various reasons, this is\n",
1027 " impractical via this interface. If you can't figure it out, you\n",
1028 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
1029 " whatever is provided). You may get better results. Good luck!\n\n",
1030 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
1034 "%s: Invalid argument, possible reasons include:\n",
1036 fprintf(stderr,"\t-File not in AFS\n");
1038 "\t-Too many users on access control list\n");
1040 "\t-Tried to add non-existent user to access control list\n");
1043 Die(errno, ti->data);
1054 CopyACLCmd(struct cmd_syndesc *as, void *arock)
1057 struct ViceIoctl blob;
1058 struct Acl *fa, *ta = 0;
1059 struct AclEntry *tp;
1060 struct cmd_item *ti;
1062 int idf = getidf(as, parm_copyacl_id);
1065 if (as->parms[2].items)
1069 blob.out_size = MAXSIZE;
1071 blob.in = blob.out = space;
1072 code = pioctl_utf8(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1074 Die(errno, as->parms[0].items->data);
1077 fa = ParseAcl(space);
1080 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1081 as->parms[0].items->data);
1084 CleanAcl(fa, as->parms[0].items->data);
1085 for (ti=as->parms[1].items; ti;ti=ti->next) {
1086 blob.out_size = MAXSIZE;
1088 blob.in = blob.out = space;
1089 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1091 Die(errno, ti->data);
1098 ta = EmptyAcl(space);
1100 ta = ParseAcl(space);
1103 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1108 CleanAcl(ta, ti->data);
1109 if (ta->dfs != fa->dfs) {
1111 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1117 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1119 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1124 strcpy(ta->cell, fa->cell);
1126 for (tp = fa->pluslist;tp;tp=tp->next)
1127 ChangeList(ta, 1, tp->name, tp->rights);
1128 for (tp = fa->minuslist;tp;tp=tp->next)
1129 ChangeList(ta, 0, tp->name, tp->rights);
1130 blob.in = AclToString(ta);
1132 blob.in_size = 1+(long)strlen(blob.in);
1133 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1135 if (errno == EINVAL) {
1137 "%s: Invalid argument, possible reasons include:\n", pn);
1138 fprintf(stderr,"\t-File not in AFS\n");
1140 Die(errno, ti->data);
1151 /* pioctl_utf8() call to get the cellname of a pathname */
1153 GetCell(char *fname, char *cellname)
1156 struct ViceIoctl blob;
1159 blob.out_size = CELL_MAXNAMELEN;
1160 blob.out = cellname;
1162 code = pioctl_utf8(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1166 /* Check if a username is valid: If it contains only digits (or a
1167 * negative sign), then it might be bad. We then query the ptserver
1171 BadName(char *aname, char *fname)
1173 afs_int32 tc, code, id;
1175 char cell[CELL_MAXNAMELEN];
1178 for ( nm = aname; tc = *nm; nm++) {
1179 /* all must be '-' or digit to be bad */
1180 if (tc != '-' && (tc < '0' || tc > '9'))
1184 /* Go to the PRDB and see if this all number username is valid */
1185 code = GetCell(fname, cell);
1189 cm_GetConfigDir(confDir, sizeof(confDir));
1191 pr_Initialize(1, confDir, cell);
1192 code = pr_SNameToId(aname, &id);
1195 /* 1=>Not-valid; 0=>Valid */
1196 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1200 /* clean up an access control list of its bad entries; return 1 if we made
1201 any changes to the list, and 0 otherwise */
1203 CleanAcl(struct Acl *aa, char *fname)
1205 struct AclEntry *te, **le, *ne;
1208 /* Don't correct DFS ACL's for now */
1212 /* prune out bad entries */
1213 changes = 0; /* count deleted entries */
1215 for(te = aa->pluslist; te; te=ne) {
1217 if (BadName(te->name, fname)) {
1227 le = &aa->minuslist;
1228 for(te = aa->minuslist; te; te=ne) {
1230 if (BadName(te->name, fname)) {
1244 /* clean up an acl to not have bogus entries */
1246 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1250 struct ViceIoctl blob;
1252 struct cmd_item *ti;
1253 struct AclEntry *te;
1256 SetDotDefault(&as->parms[0].items);
1257 for(ti=as->parms[0].items; ti; ti=ti->next) {
1258 blob.out_size = MAXSIZE;
1261 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1263 Die(errno, ti->data);
1269 ta = ParseAcl(space);
1272 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1279 "%s: cleanacl is not supported for DFS access lists.\n",
1285 changes = CleanAcl(ta, ti->data);
1288 /* now set the acl */
1289 blob.in=AclToString(ta);
1290 blob.in_size = (long)strlen(blob.in)+1;
1292 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1294 if (errno == EINVAL) {
1296 "%s: Invalid argument, possible reasons include\n",
1298 fprintf(stderr,"%s: File not in vice or\n", pn);
1300 "%s: Too many users on access control list or\n",
1303 Die(errno, ti->data);
1309 /* now list the updated acl */
1310 printf("Access list for %s is now\n", ti->data);
1311 if (ta->nplus > 0) {
1313 printf("Normal rights:\n");
1314 for(te = ta->pluslist;te;te=te->next) {
1315 printf(" %s ", te->name);
1316 PRights(te->rights, ta->dfs);
1320 if (ta->nminus > 0) {
1321 printf("Negative rights:\n");
1322 for(te = ta->minuslist;te;te=te->next) {
1323 printf(" %s ", te->name);
1324 PRights(te->rights, ta->dfs);
1331 printf("Access list for %s is fine.\n", ti->data);
1339 ListACLCmd(struct cmd_syndesc *as, void *arock)
1343 struct ViceIoctl blob;
1344 struct AclEntry *te;
1345 struct cmd_item *ti;
1346 int idf = getidf(as, parm_listacl_id);
1349 SetDotDefault(&as->parms[0].items);
1350 for(ti=as->parms[0].items; ti; ti=ti->next) {
1352 blob.out_size = MAXSIZE;
1354 blob.in = blob.out = space;
1355 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1357 Die(errno, ti->data);
1361 ta = ParseAcl(space);
1364 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1371 printf("Access list for %s is\n", ti->data);
1374 printf("DFS access list for %s is\n", ti->data);
1377 printf("DFS initial directory access list of %s is\n", ti->data);
1380 printf("DFS initial file access list of %s is\n", ti->data);
1384 printf(" Default cell = %s\n", ta->cell);
1386 separator = ta->dfs? DFS_SEPARATOR : ' ';
1387 if (ta->nplus > 0) {
1389 printf("Normal rights:\n");
1390 for(te = ta->pluslist;te;te=te->next) {
1391 printf(" %s%c", te->name, separator);
1392 PRights(te->rights, ta->dfs);
1396 if (ta->nminus > 0) {
1397 printf("Negative rights:\n");
1398 for(te = ta->minuslist;te;te=te->next) {
1399 printf(" %s ", te->name);
1400 PRights(te->rights, ta->dfs);
1412 FlushAllCmd(struct cmd_syndesc *as, void *arock)
1415 struct ViceIoctl blob;
1417 blob.in_size = blob.out_size = 0;
1418 code = pioctl_utf8(NULL, VIOC_FLUSHALL, &blob, 0);
1420 fprintf(stderr, "Error flushing all ");
1427 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1430 struct ViceIoctl blob;
1431 struct cmd_item *ti;
1434 SetDotDefault(&as->parms[0].items);
1435 for(ti=as->parms[0].items; ti; ti=ti->next) {
1436 blob.in_size = blob.out_size = 0;
1437 code = pioctl_utf8(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1439 fprintf(stderr, "Error flushing volume ");
1449 FlushCmd(struct cmd_syndesc *as, void *arock)
1452 struct ViceIoctl blob;
1453 struct cmd_item *ti;
1456 cm_ioctlQueryOptions_t options;
1458 if (as->parms[1].items)
1461 for(ti=as->parms[0].items; ti; ti=ti->next) {
1463 memset(&options, 0, sizeof(options));
1464 options.size = sizeof(options);
1465 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1466 options.literal = literal;
1467 blob.in_size = options.size; /* no variable length data */
1471 code = pioctl_utf8(ti->data, VIOCFLUSH, &blob, 0);
1473 if (errno == EMFILE) {
1474 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1477 fprintf(stderr, "%s: Error flushing file ", pn);
1487 /* all this command does is repackage its args and call SetVolCmd */
1489 SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
1490 struct cmd_syndesc ts;
1492 /* copy useful stuff from our command slot; we may later have to reorder */
1493 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1494 return SetVolCmd(&ts, arock);
1498 SetVolCmd(struct cmd_syndesc *as, void *arock) {
1500 struct ViceIoctl blob;
1501 struct cmd_item *ti;
1502 struct VolumeStatus *status;
1503 char *motd, *offmsg, *input;
1506 SetDotDefault(&as->parms[0].items);
1507 for(ti=as->parms[0].items; ti; ti=ti->next) {
1509 blob.out_size = MAXSIZE;
1510 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1513 status = (VolumeStatus *)space;
1514 status->MinQuota = status->MaxQuota = -1;
1515 motd = offmsg = NULL;
1516 if (as->parms[1].items) {
1517 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1519 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1524 if (as->parms[2].items)
1525 motd = as->parms[2].items->data;
1526 if (as->parms[3].items)
1527 offmsg = as->parms[3].items->data;
1528 input = (char *)status + sizeof(*status);
1529 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1531 if (strlen(offmsg) >= VMSGSIZE) {
1532 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1537 strcpy(input,offmsg);
1538 blob.in_size += (long)strlen(offmsg);
1539 input += strlen(offmsg) + 1;
1543 if (strlen(motd) >= VMSGSIZE) {
1544 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1549 blob.in_size += (long)strlen(motd);
1550 input += strlen(motd) + 1;
1553 code = pioctl_utf8(ti->data,VIOCSETVOLSTAT, &blob, 1);
1555 Die(errno, ti->data);
1562 /* values match cache manager File Types */
1564 filetypestr(afs_uint32 type)
1566 char * s = "Object";
1589 ExamineCmd(struct cmd_syndesc *as, void *arock)
1592 struct ViceIoctl blob;
1593 struct cmd_item *ti;
1594 struct VolumeStatus *status;
1595 char *name, *offmsg, *motd;
1598 cm_ioctlQueryOptions_t options;
1600 if (as->parms[1].items)
1603 SetDotDefault(&as->parms[0].items);
1604 for(ti=as->parms[0].items; ti; ti=ti->next) {
1606 afs_uint32 filetype;
1607 afs_uint32 owner[2];
1608 char cell[CELL_MAXNAMELEN];
1611 memset(&fid, 0, sizeof(fid));
1612 memset(&options, 0, sizeof(options));
1614 options.size = sizeof(options);
1615 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1616 options.literal = literal;
1617 blob.in_size = options.size; /* no variable length data */
1620 blob.out_size = sizeof(cm_fid_t);
1621 blob.out = (char *) &fid;
1622 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
1623 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1626 Die(errno, ti->data);
1631 blob.out_size = sizeof(filetype);
1632 blob.out = &filetype;
1634 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1636 blob.out_size = CELL_MAXNAMELEN;
1639 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1640 printf("%s %s (%u.%u.%u) contained in cell %s\n",
1641 filetypestr(filetype),
1642 ti->data, fid.volume, fid.vnode, fid.unique,
1643 code ? "unknown-cell" : cell);
1645 blob.out_size = 2 * sizeof(afs_uint32);
1646 blob.out = (char *) &owner;
1647 if (0 == pioctl_utf8(ti->data, VIOCGETOWNER, &blob, 1)) {
1648 char oname[PR_MAXNAMELEN] = "(unknown)";
1651 /* Go to the PRDB and see if this all number username is valid */
1652 cm_GetConfigDir(confDir, sizeof(confDir));
1654 pr_Initialize(1, confDir, cell);
1655 pr_SIdToName(owner[0], oname);
1656 printf("Owner %s (%u) Group %u\n", oname, owner[0], owner[1]);
1660 blob.out_size = MAXSIZE;
1661 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1663 status = (VolumeStatus *)space;
1664 name = (char *)status + sizeof(*status);
1665 offmsg = name + strlen(name) + 1;
1666 motd = offmsg + strlen(offmsg) + 1;
1668 PrintStatus(status, name, motd, offmsg);
1670 Die(errno, ti->data);
1674 code = pioctl_utf8(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
1677 printf("Volume is online\n");
1680 printf("Volume is offline\n");
1683 printf("All Volume servers are down\n");
1686 printf("All volume servers are busy\n");
1689 printf("Unknown volume state\n");
1690 Die(errno, ti->data);
1698 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1701 struct ViceIoctl blob;
1702 struct cmd_item *ti;
1703 struct VolumeStatus *status;
1708 printf("%-25s%-10s%-10s%-7s%-13s\n",
1709 "Volume Name", " Quota", " Used", " %Used", " Partition");
1710 SetDotDefault(&as->parms[0].items);
1711 for(ti=as->parms[0].items; ti; ti=ti->next) {
1713 blob.out_size = MAXSIZE;
1716 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1718 Die(errno, ti->data);
1722 status = (VolumeStatus *)space;
1723 name = (char *)status + sizeof(*status);
1724 QuickPrintStatus(status, name);
1730 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1733 struct ViceIoctl blob;
1734 struct cmd_item *ti;
1740 cm_ioctlQueryOptions_t options;
1742 if (as->parms[1].items)
1745 SetDotDefault(&as->parms[0].items);
1746 for(ti=as->parms[0].items; ti; ti=ti->next) {
1748 afs_uint32 filetype;
1751 memset(&fid, 0, sizeof(fid));
1752 memset(&options, 0, sizeof(options));
1754 options.size = sizeof(options);
1755 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1756 options.literal = literal;
1757 blob.in_size = options.size; /* no variable length data */
1760 blob.out_size = sizeof(cm_fid_t);
1761 blob.out = (char *) &fid;
1762 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
1763 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1766 Die(errno, ti->data);
1771 blob.out_size = sizeof(filetype);
1772 blob.out = &filetype;
1774 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1776 blob.out_size = MAXSIZE;
1778 memset(space, 0, sizeof(space));
1779 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
1781 Die(errno, ti->data);
1785 hosts = (afs_int32 *) space;
1786 printf("%s %s is on host%s ",
1787 filetypestr(filetype),
1789 (hosts[0] && !hosts[1]) ? "": "s");
1790 for(j=0; j<MAXHOSTS; j++) {
1793 tp = hostutil_GetNameByINet(hosts[j]);
1803 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1806 struct ViceIoctl blob;
1807 struct cmd_item *ti;
1809 struct VolumeStatus *status;
1812 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1813 " used", " avail", " %used");
1814 SetDotDefault(&as->parms[0].items);
1815 for(ti=as->parms[0].items; ti; ti=ti->next) {
1817 blob.out_size = MAXSIZE;
1820 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1822 Die(errno, ti->data);
1826 status = (VolumeStatus *)space;
1827 name = (char *)status + sizeof(*status);
1828 QuickPrintSpace(status, name);
1834 QuotaCmd(struct cmd_syndesc *as, void *arock)
1837 struct ViceIoctl blob;
1838 struct cmd_item *ti;
1840 struct VolumeStatus *status;
1843 SetDotDefault(&as->parms[0].items);
1844 for(ti=as->parms[0].items; ti; ti=ti->next) {
1846 blob.out_size = MAXSIZE;
1849 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1851 Die(errno, ti->data);
1855 status = (VolumeStatus *)space;
1856 if (status->MaxQuota)
1857 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1860 printf("%2.0f%% of quota used.\n", quotaPct);
1866 ListMountCmd(struct cmd_syndesc *as, void *arock)
1869 struct ViceIoctl blob;
1870 struct cmd_item *ti;
1871 char orig_name[1024]; /*Original name, may be modified*/
1872 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1873 char parent_dir[1024]; /*Parent directory of true name*/
1874 char *last_component; /*Last component of true name*/
1876 struct stat statbuff; /*Buffer for status info*/
1877 #endif /* not WIN32 */
1879 int link_chars_read; /*Num chars read in readlink()*/
1880 #endif /* not WIN32 */
1881 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1884 for(ti=as->parms[0].items; ti; ti=ti->next) {
1888 strcpy(orig_name, ti->data);
1889 #else /* not WIN32 */
1890 sprintf(orig_name, "%s%s",
1891 (ti->data[0] == '/') ? "" : "./",
1893 #endif /* not WIN32 */
1896 if (lstat(orig_name, &statbuff) < 0) {
1897 /* if lstat fails, we should still try the pioctl, since it
1898 * may work (for example, lstat will fail, but pioctl will
1899 * work if the volume of offline (returning ENODEV). */
1900 statbuff.st_mode = S_IFDIR; /* lie like pros */
1904 * The lstat succeeded. If the given file is a symlink, substitute
1905 * the file name with the link name.
1907 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1910 * Read name of resolved file.
1912 link_chars_read = readlink(orig_name, true_name, 1024);
1913 if (link_chars_read <= 0) {
1915 "%s: Can't read target name for '%s' symbolic link!\n",
1922 * Add a trailing null to what was read, bump the length.
1924 true_name[link_chars_read++] = 0;
1927 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1928 * have to create a full pathname using the original name and the
1929 * relative symlink name. Find the rightmost slash in the original
1930 * name (we know there is one) and splice in the symlink value.
1932 if (true_name[0] != '\\') {
1933 last_component = (char *) strrchr(orig_name, '\\');
1934 strcpy(++last_component, true_name);
1935 strcpy(true_name, orig_name);
1938 strcpy(true_name, orig_name);
1940 strcpy(true_name, orig_name);
1944 * Find rightmost slash, if any.
1947 last_component = (char *) strrchr(true_name, '\\');
1948 if (!last_component)
1950 last_component = (char *) strrchr(true_name, '/');
1951 if (last_component) {
1953 * Found it. Designate everything before it as the parent directory,
1954 * everything after it as the final component.
1956 strncpy(parent_dir, true_name, last_component - true_name + 1);
1957 parent_dir[last_component - true_name + 1] = 0;
1958 last_component++; /*Skip the slash*/
1960 if (!InAFS(parent_dir)) {
1961 const char * nbname = NetbiosName();
1962 int len = (int)strlen(nbname);
1964 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
1965 parent_dir[len+2] == '\\' &&
1966 parent_dir[len+3] == '\0' &&
1967 !strnicmp(nbname,&parent_dir[2],len))
1969 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
1975 * No slash appears in the given file name. Set parent_dir to the current
1976 * directory, and the last component as the given name.
1978 fs_ExtractDriveLetter(true_name, parent_dir);
1979 strcat(parent_dir, ".");
1980 last_component = true_name;
1981 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1984 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1985 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
1986 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
1991 blob.in = last_component;
1992 blob.in_size = (long)strlen(last_component)+1;
1993 blob.out_size = MAXSIZE;
1995 memset(space, 0, MAXSIZE);
1997 code = pioctl_utf8(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
2000 printf("'%s' is a %smount point for volume '%s'\n",
2002 (thru_symlink ? "symbolic link, leading to a " : ""),
2006 if (errno == EINVAL) {
2007 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
2009 Die(errno, (ti->data ? ti->data : parent_dir));
2018 MakeMountCmd(struct cmd_syndesc *as, void *arock)
2021 char *cellName, *volName, *tmpName;
2023 char localCellName[128];
2025 char path[1024] = "";
2026 struct afsconf_cell info;
2027 struct vldbentry vldbEntry;
2028 struct ViceIoctl blob;
2031 memset(&info, 0, sizeof(info));
2033 if (as->parms[2].items) /* cell name specified */
2034 cellName = as->parms[2].items->data;
2037 volName = as->parms[1].items->data;
2039 if (strlen(volName) >= 64) {
2040 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
2044 /* Check for a cellname in the volume specification, and complain
2045 * if it doesn't match what was specified with -cell */
2046 if (tmpName = strchr(volName, ':')) {
2049 if (strcasecmp(cellName,volName)) {
2050 fprintf(stderr,"fs: cellnames do not match.\n");
2055 volName = ++tmpName;
2058 parent = Parent(as->parms[0].items->data);
2059 if (!InAFS(parent)) {
2061 const char * nbname = NetbiosName();
2062 int len = (int)strlen(nbname);
2064 if (parent[0] == '\\' && parent[1] == '\\' &&
2065 parent[len+2] == '\\' &&
2066 parent[len+3] == '\0' &&
2067 !strnicmp(nbname,&parent[2],len))
2069 sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
2070 parent = Parent(path);
2071 if (!InAFS(parent)) {
2072 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2078 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2083 if ( strlen(path) == 0 )
2084 strcpy(path, as->parms[0].items->data);
2086 if ( IsFreelanceRoot(parent) ) {
2088 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2094 blob.out_size = sizeof(localCellName);
2095 blob.out = localCellName;
2096 code = pioctl_utf8(parent, VIOC_GET_WS_CELL, &blob, 1);
2098 cellName = localCellName;
2102 code = GetCell(parent,space);
2108 code = GetCellName(cellName?cellName:space, &info);
2112 if (!(as->parms[4].items)) {
2113 /* not fast, check which cell the mountpoint is being created in */
2115 /* not fast, check name with VLDB */
2117 code = VLDBInit(1, &info);
2119 /* make the check. Don't complain if there are problems with init */
2120 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2121 if (code == VL_NOENT) {
2122 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2123 pn, volName, cellName ? cellName : space);
2128 if (as->parms[3].items) /* if -rw specified */
2133 /* cellular mount point, prepend cell prefix */
2134 strcat(space, info.name);
2137 strcat(space, volName); /* append volume name */
2138 strcat(space, "."); /* stupid convention; these end with a period */
2140 /* create symlink with a special pioctl for Windows NT, since it doesn't
2141 * have a symlink system call.
2144 blob.in_size = 1 + (long)strlen(space);
2147 code = pioctl_utf8(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2148 #else /* not WIN32 */
2149 code = symlink(space, path);
2150 #endif /* not WIN32 */
2152 if (info.linkedCell)
2153 free(info.linkedCell);
2163 * Delete AFS mount points. Variables are used as follows:
2164 * tbuffer: Set to point to the null-terminated directory name of the mount point
2165 * (or ``.'' if none is provided)
2166 * tp: Set to point to the actual name of the mount point to nuke.
2169 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2171 struct ViceIoctl blob;
2172 struct cmd_item *ti;
2174 char lsbuffer[1024];
2178 for(ti=as->parms[0].items; ti; ti=ti->next) {
2180 tp = (char *) strrchr(ti->data, '\\');
2182 tp = (char *) strrchr(ti->data, '/');
2184 strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1)); /* the dir name */
2186 tp++; /* skip the slash */
2189 if (!InAFS(tbuffer)) {
2190 const char * nbname = NetbiosName();
2191 int len = (int)strlen(nbname);
2193 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2194 tbuffer[len+2] == '\\' &&
2195 tbuffer[len+3] == '\0' &&
2196 !strnicmp(nbname,&tbuffer[2],len))
2198 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
2203 fs_ExtractDriveLetter(ti->data, tbuffer);
2204 strcat(tbuffer, ".");
2206 fs_StripDriveLetter(tp, tp, 0);
2209 blob.in_size = (long)strlen(tp)+1;
2210 blob.out = lsbuffer;
2211 blob.out_size = sizeof(lsbuffer);
2212 code = pioctl_utf8(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2214 if (errno == EINVAL) {
2215 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2217 Die(errno, ti->data);
2220 continue; /* don't bother trying */
2223 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2224 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2226 continue; /* skip */
2231 blob.in_size = (long)strlen(tp)+1;
2232 code = pioctl_utf8(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2234 Die(errno, ti->data);
2245 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2248 struct ViceIoctl blob;
2252 struct afsconf_cell info;
2253 struct chservinfo checkserv;
2255 memset(&info, 0, sizeof(info));
2256 memset(&checkserv, 0, sizeof(struct chservinfo));
2257 blob.in_size=sizeof(struct chservinfo);
2258 blob.in=(caddr_t)&checkserv;
2260 blob.out_size = MAXSIZE;
2262 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2264 /* prepare flags for checkservers command */
2265 temp = 2; /* default to checking local cell only */
2266 if (as->parms[2].items)
2267 temp |= 1; /* set fast flag */
2268 if (as->parms[1].items)
2269 temp &= ~2; /* turn off local cell check */
2271 checkserv.magic = 0x12345678; /* XXX */
2272 checkserv.tflags=temp;
2274 /* now copy in optional cell name, if specified */
2275 if (as->parms[0].items) {
2276 code = GetCellName(as->parms[0].items->data, &info);
2280 strcpy(checkserv.tbuffer,info.name);
2281 checkserv.tsize=(int)strlen(info.name)+1;
2282 if (info.linkedCell)
2283 free(info.linkedCell);
2285 strcpy(checkserv.tbuffer,"\0");
2289 if(as->parms[3].items) {
2290 checkserv.tinterval=atol(as->parms[3].items->data);
2293 if(checkserv.tinterval<0) {
2294 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2295 checkserv.tinterval=-1;
2296 } else if(checkserv.tinterval> 600) {
2297 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2298 checkserv.tinterval=600; /* 10 min max interval */
2301 checkserv.tinterval = -1; /* don't change current interval */
2304 if ( checkserv.tinterval >= 0 ) {
2307 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2312 fprintf (stderr,"Permission denied: requires root access.\n");
2318 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
2320 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2321 printf("Must be root to change -interval\n");
2327 memcpy(&temp, space, sizeof(afs_int32));
2328 if (checkserv.tinterval >= 0) {
2329 if (checkserv.tinterval > 0)
2330 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2331 checkserv.tinterval, temp);
2333 printf("The current down server probe interval is %d secs\n", temp);
2337 printf("All servers are running.\n");
2339 printf("These servers unavailable due to network or server problems: ");
2340 for(j=0; j < MAXHOSTS; j++) {
2341 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2344 tp = hostutil_GetNameByINet(temp);
2354 MessagesCmd(struct cmd_syndesc *as, void *arock)
2357 struct ViceIoctl blob;
2358 struct gaginfo gagflags;
2359 struct cmd_item *show;
2361 memset(&gagflags, 0, sizeof(struct gaginfo));
2362 blob.in_size = sizeof(struct gaginfo);
2363 blob.in = (caddr_t ) &gagflags;
2364 blob.out_size = MAXSIZE;
2366 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2368 if (show = as->parms[0].items) {
2369 if (!strcasecmp (show->data, "user"))
2370 gagflags.showflags |= GAGUSER;
2371 else if (!strcasecmp (show->data, "console"))
2372 gagflags.showflags |= GAGCONSOLE;
2373 else if (!strcasecmp (show->data, "all"))
2374 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2375 else if (!strcasecmp (show->data, "none"))
2379 "unrecognized flag %s: must be in {user,console,all,none}\n",
2388 code = pioctl_utf8(0, VIOC_GAG, &blob, 1);
2397 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2400 struct ViceIoctl blob;
2404 code = pioctl_utf8(0, VIOCCKBACK, &blob, 1);
2409 printf("All volumeID/name mappings checked.\n");
2415 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2418 struct ViceIoctl blob;
2423 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2428 fprintf (stderr,"Permission denied: requires root access.\n");
2433 if (!as->parms[0].items && !as->parms[1].items) {
2434 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2437 if (as->parms[0].items) {
2438 code = util_GetInt32(as->parms[0].items->data, &temp);
2440 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2445 blob.in = (char *) &temp;
2446 blob.in_size = sizeof(afs_int32);
2448 code = pioctl_utf8(0, VIOCSETCACHESIZE, &blob, 1);
2450 Die(errno, (char *) 0);
2454 printf("New cache size set.\n");
2459 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2462 struct ViceIoctl blob;
2463 cm_cacheParms_t parms;
2465 memset(&parms, 0, sizeof(parms));
2468 blob.out_size = sizeof(parms);
2469 blob.out = (char *) &parms;
2470 code = pioctl_utf8(0, VIOCGETCACHEPARMS, &blob, 1);
2476 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2477 parms.parms[1], parms.parms[0]);
2478 if (parms.parms[1] > parms.parms[0])
2479 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2484 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2487 afs_int32 i, j, *lp, magic, size;
2489 afs_int32 addr, maxa = OMAXHOSTS;
2490 struct ViceIoctl blob;
2493 resolve = !(as->parms[0].items); /* -numeric */
2495 for(i=0;i<1000;i++) {
2497 memcpy(tp, &i, sizeof(afs_int32));
2498 tp = (char *)(space + sizeof(afs_int32));
2499 lp = (afs_int32 *)tp;
2501 size = sizeof(afs_int32) + sizeof(afs_int32);
2502 blob.out_size = MAXSIZE;
2503 blob.in_size = sizeof(afs_int32);
2506 code = pioctl_utf8(0, VIOCGETCELL, &blob, 1);
2509 break; /* done with the list */
2514 memcpy(&magic, tp, sizeof(afs_int32));
2515 if (magic == 0x12345678) {
2517 tp += sizeof(afs_int32);
2519 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2520 for(j=0; j < maxa; j++) {
2521 char *name, tbuffer[20];
2523 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2528 name = hostutil_GetNameByINet(addr);
2531 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2532 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2535 printf(" %s", name);
2544 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2547 char *tp, *aliasName, *realName;
2548 struct ViceIoctl blob;
2552 memcpy(tp, &i, sizeof(afs_int32));
2553 blob.out_size = MAXSIZE;
2554 blob.in_size = sizeof(afs_int32);
2557 code = pioctl_utf8(0, VIOC_GETALIAS, &blob, 1);
2560 break; /* done with the list */
2566 tp += strlen(aliasName) + 1;
2568 printf("Alias %s for cell %s\n", aliasName, realName);
2574 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2577 struct ViceIoctl blob;
2578 struct cmd_item *ti;
2580 struct hostent *thp;
2584 ti = as->parms[0].items;
2587 thp = hostutil_GetHostByName(ti->data);
2589 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2592 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2594 hostAddr = 0; /* means don't set host */
2595 setp = 0; /* aren't setting host */
2598 /* now do operation */
2599 blob.in_size = sizeof(afs_int32);
2600 blob.out_size = sizeof(afs_int32);
2601 blob.in = (char *) &hostAddr;
2602 blob.out = (char *) &hostAddr;
2604 code = pioctl_utf8(0, VIOC_CBADDR, &blob, 1);
2614 NewCellCmd(struct cmd_syndesc *as, void *arock)
2617 afs_int32 code, linkedstate=0, size=0, *lp;
2618 struct ViceIoctl blob;
2619 struct cmd_item *ti;
2620 char *tp, *cellname=0;
2621 struct hostent *thp;
2622 afs_int32 fsport = 0, vlport = 0;
2624 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
2626 lp = (afs_int32 *)tp;
2628 tp += sizeof(afs_int32);
2629 for(ti=as->parms[1].items; ti; ti=ti->next) {
2630 thp = hostutil_GetHostByName(ti->data);
2632 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2636 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2637 tp += sizeof(afs_int32);
2640 if (as->parms[2].items) {
2642 * Link the cell, for the purposes of volume location, to the specified
2645 cellname = as->parms[2].items->data;
2648 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2649 if (as->parms[3].items) {
2650 code = util_GetInt32(as->parms[3].items->data, &vlport);
2652 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2656 if (as->parms[4].items) {
2657 code = util_GetInt32(as->parms[4].items->data, &fsport);
2659 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2664 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
2665 lp = (afs_int32 *)tp;
2669 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2670 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2671 tp = (char *)(space + size);
2673 strcpy(tp, cellname);
2674 size += strlen(cellname) + 1;
2676 blob.in_size = size;
2679 code = pioctl_utf8(0, VIOCNEWCELL, &blob, 1);
2685 struct ViceIoctl blob;
2688 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2693 blob.in = (char *) 0;
2694 blob.out_size = MAXSIZE;
2697 code = pioctl_utf8((char *) 0, VIOCNEWCELL, &blob, 1);
2700 Die(errno, (char *) 0);
2704 printf("Cell servers information refreshed\n");
2711 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2714 struct ViceIoctl blob;
2716 char *aliasName, *realName;
2718 /* Setup and do the NEWALIAS pioctl call */
2719 aliasName = as->parms[0].items->data;
2720 realName = as->parms[1].items->data;
2722 strcpy(tp, aliasName);
2723 tp += strlen(aliasName) + 1;
2724 strcpy(tp, realName);
2725 tp += strlen(realName) + 1;
2727 blob.in_size = tp - space;
2731 code = pioctl_utf8(0, VIOC_NEWALIAS, &blob, 1);
2733 if (errno == EEXIST) {
2735 "%s: cell name `%s' in use by an existing cell.\n", pn,
2747 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2750 struct cmd_item *ti;
2751 struct ViceIoctl blob;
2754 cm_ioctlQueryOptions_t options;
2756 if (as->parms[1].items)
2759 SetDotDefault(&as->parms[0].items);
2760 for(ti=as->parms[0].items; ti; ti=ti->next) {
2762 afs_uint32 filetype;
2763 char cell[CELL_MAXNAMELEN];
2766 memset(&fid, 0, sizeof(fid));
2767 memset(&options, 0, sizeof(options));
2769 options.size = sizeof(options);
2770 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
2771 options.literal = literal;
2772 blob.in_size = options.size; /* no variable length data */
2775 blob.out_size = sizeof(cm_fid_t);
2776 blob.out = (char *) &fid;
2777 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
2778 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
2781 Die(errno, ti->data);
2786 blob.out_size = sizeof(filetype);
2787 blob.out = &filetype;
2789 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
2791 blob.out_size = CELL_MAXNAMELEN;
2794 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
2796 if (errno == ENOENT)
2797 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2799 Die(errno, ti->data);
2803 printf("%s %s lives in cell '%s'\n",
2804 filetypestr(filetype),
2811 WSCellCmd(struct cmd_syndesc *as, void *arock)
2814 struct ViceIoctl blob;
2818 blob.out_size = MAXSIZE;
2821 code = pioctl_utf8(NULL, VIOC_GET_WS_CELL, &blob, 1);
2828 printf("This workstation belongs to cell '%s'\n", space);
2834 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
2836 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2841 #ifndef AFS_NT40_ENV
2843 MonitorCmd(struct cmd_syndesc *as, void *arock)
2846 struct ViceIoctl blob;
2847 struct cmd_item *ti;
2849 struct hostent *thp;
2853 ti = as->parms[0].items;
2857 if (!strcmp(ti->data, "off")) {
2858 hostAddr = 0xffffffff;
2860 thp = hostutil_GetHostByName(ti->data);
2862 if (!strcmp(ti->data, "localhost")) {
2863 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2864 hostAddr = htonl(0x7f000001);
2866 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2870 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2874 hostAddr = 0; /* means don't set host */
2875 setp = 0; /* aren't setting host */
2878 /* now do operation */
2879 blob.in_size = sizeof(afs_int32);
2880 blob.out_size = sizeof(afs_int32);
2881 blob.in = (char *) &hostAddr;
2882 blob.out = (char *) &hostAddr;
2883 code = pioctl_utf8(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2889 printf("%s: new monitor host set.\n", pn);
2891 /* now decode old address */
2892 if (hostAddr == 0xffffffff) {
2893 printf("Cache monitoring is currently disabled.\n");
2895 tp = hostutil_GetNameByINet(hostAddr);
2896 printf("Using host %s for monitor services.\n", tp);
2901 #endif /* AFS_NT40_ENV */
2904 SysNameCmd(struct cmd_syndesc *as, void *arock)
2907 struct ViceIoctl blob;
2908 struct cmd_item *ti;
2909 char *input = space;
2912 ti = as->parms[0].items;
2916 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2921 fprintf (stderr,"Permission denied: requires root access.\n");
2929 blob.out_size = MAXSIZE;
2930 blob.in_size = sizeof(afs_int32);
2931 memcpy(input, &setp, sizeof(afs_int32));
2932 input += sizeof(afs_int32);
2933 for (; ti; ti = ti->next) {
2935 blob.in_size += (long)strlen(ti->data) + 1;
2936 if (blob.in_size > MAXSIZE) {
2937 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2938 setp > 1 ? "s" : "");
2941 strcpy(input, ti->data);
2942 input += strlen(ti->data);
2945 memcpy(space, &setp, sizeof(afs_int32));
2946 code = pioctl_utf8(0, VIOC_AFS_SYSNAME, &blob, 1);
2952 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2957 memcpy(&setp, input, sizeof(afs_int32));
2958 input += sizeof(afs_int32);
2960 fprintf(stderr,"No sysname name value was found\n");
2964 printf("Current sysname%s is", setp > 1 ? " list" : "");
2965 for (; setp > 0; --setp ) {
2966 printf(" \'%s\'", input);
2967 input += strlen(input) + 1;
2973 #ifndef AFS_NT40_ENV
2974 static char *exported_types[] = {"null", "nfs", ""};
2975 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2978 struct ViceIoctl blob;
2979 struct cmd_item *ti;
2980 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
2981 int exportcall, pwsync = 0, smounts = 0;
2985 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2990 fprintf (stderr,"Permission denied: requires root access.\n");
2995 ti = as->parms[0].items;
2996 if (strcmp(ti->data, "nfs") == 0)
2997 type = 0x71; /* NFS */
3000 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
3003 ti = as->parms[1].items;
3005 if (strcmp(ti->data, "on") == 0)
3007 else if (strcmp(ti->data, "off") == 0)
3010 fprintf(stderr, "Illegal argument %s\n", ti->data);
3015 if (ti = as->parms[2].items) { /* -noconvert */
3016 if (strcmp(ti->data, "on") == 0)
3018 else if (strcmp(ti->data, "off") == 0)
3021 fprintf(stderr, "Illegal argument %s\n", ti->data);
3025 if (ti = as->parms[3].items) { /* -uidcheck */
3026 if (strcmp(ti->data, "on") == 0)
3028 else if (strcmp(ti->data, "off") == 0)
3031 fprintf(stderr, "Illegal argument %s\n", ti->data);
3035 if (ti = as->parms[4].items) { /* -submounts */
3036 if (strcmp(ti->data, "on") == 0)
3038 else if (strcmp(ti->data, "off") == 0)
3041 fprintf(stderr, "Illegal argument %s\n", ti->data);
3045 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
3048 blob.in = (char *) &exportcall;
3049 blob.in_size = sizeof(afs_int32);
3050 blob.out = (char *) &exportcall;
3051 blob.out_size = sizeof(afs_int32);
3052 code = pioctl_utf8(0, VIOC_EXPORTAFS, &blob, 1);
3054 if (errno == ENODEV) {
3056 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
3063 if (exportcall & 1) {
3064 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
3065 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
3066 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
3067 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
3069 printf("'%s' translator is disabled\n", exported_types[type]);
3078 GetCellCmd(struct cmd_syndesc *as, void *arock)
3081 struct ViceIoctl blob;
3082 struct afsconf_cell info;
3083 struct cmd_item *ti;
3090 memset(&info, 0, sizeof(info));
3091 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3092 for(ti=as->parms[0].items; ti; ti=ti->next) {
3094 blob.out_size = sizeof(args);
3095 blob.out = (caddr_t) &args;
3096 code = GetCellName(ti->data, &info);
3101 if (info.linkedCell)
3102 free(info.linkedCell);
3103 blob.in_size = 1+(long)strlen(info.name);
3104 blob.in = info.name;
3105 code = pioctl_utf8(0, VIOC_GETCELLSTATUS, &blob, 1);
3107 if (errno == ENOENT)
3108 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3110 Die(errno, info.name);
3114 printf("Cell %s status: ", info.name);
3120 printf("no setuid allowed");
3122 printf("setuid allowed");
3124 printf(", using old VLDB");
3130 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3133 struct ViceIoctl blob;
3134 struct afsconf_cell info;
3135 struct cmd_item *ti;
3143 memset(&info, 0, sizeof(info));
3145 /* Check arguments. */
3146 if (as->parms[1].items && as->parms[2].items) {
3147 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3151 /* figure stuff to set */
3157 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3162 fprintf (stderr,"Permission denied: requires root access.\n");
3167 if (! as->parms[1].items)
3168 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3170 /* set stat for all listed cells */
3171 for(ti=as->parms[0].items; ti; ti=ti->next) {
3173 code = GetCellName(ti->data, &info);
3178 if (info.linkedCell)
3179 free(info.linkedCell);
3180 strcpy(args.cname, info.name);
3181 blob.in_size = sizeof(args);
3182 blob.in = (caddr_t) &args;
3184 blob.out = (caddr_t) 0;
3185 code = pioctl_utf8(0, VIOC_SETCELLSTATUS, &blob, 1);
3187 Die(errno, info.name); /* XXX added cell name to Die() call */
3195 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3197 strcpy(infop->name, cellNamep);
3202 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3207 cm_GetConfigDir(confDir, sizeof(confDir));
3209 code = ugen_ClientInit(noAuthFlag, confDir,
3210 info->name, 0, &uclient,
3211 NULL, pn, rxkad_clear,
3212 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3213 0, 0, USER_SERVICE_ID);
3218 static struct ViceIoctl gblob;
3219 static int debug = 0;
3221 * here follow some routines in suport of the setserverprefs and
3222 * getserverprefs commands. They are:
3223 * SetPrefCmd "top-level" routine
3224 * addServer adds a server to the list of servers to be poked into the
3225 * kernel. Will poke the list into the kernel if it threatens
3227 * pokeServers pokes the existing list of servers and ranks into the kernel
3228 * GetPrefCmd reads the Cache Manager's current list of server ranks
3237 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3239 ssp = (cm_SSetPref_t *)space;
3240 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3246 * returns -1 if error message printed,
3248 * errno value if error and no error message printed
3255 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3256 if (code && (errno == EINVAL)) {
3257 struct setspref *ssp;
3258 ssp = (struct setspref *)gblob.in;
3259 if (!(ssp->flags & DBservers)) {
3260 gblob.in = (void *)&(ssp->servers[0]);
3261 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3262 code = pioctl_utf8(0, VIOC_SETSPREFS33, &gblob, 1);
3263 return code ? errno : 0;
3266 "This cache manager does not support VL server preferences.\n");
3270 return code ? errno : 0;
3276 addServer(char *name, unsigned short rank)
3281 struct hostent *thostent;
3285 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3287 #define MAXUSHORT ((unsigned short) ~0)
3292 thostent = hostutil_GetHostByName(name);
3294 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3298 ssp = (cm_SSetPref_t *)(gblob.in);
3300 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3301 code = pokeServers();
3302 ssp->num_servers = 0;
3305 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3306 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3307 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3308 gblob.in_size += sizeof(cm_SPref_t);
3311 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3317 * returns -1 if error message printed,
3319 * errno value if error and no error message printed
3322 addServer(char *name, afs_int32 rank)
3325 struct setspref *ssp;
3327 struct hostent *thostent;
3333 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3335 #define MAXUSHORT ((unsigned short) ~0)
3339 thostent = hostutil_GetHostByName(name);
3341 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3345 ssp = (struct setspref *)(gblob.in);
3347 for (t = 0; thostent->h_addr_list[t]; t++) {
3348 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3349 code = pokeServers();
3352 ssp->num_servers = 0;
3355 sp = (struct spref *)(gblob.in + gblob.in_size);
3356 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3357 sizeof(afs_uint32));
3358 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3359 gblob.in_size += sizeof(struct spref);
3363 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3364 name, sp->rank, sp->server.s_addr);
3372 static BOOL IsWindowsNT (void)
3374 static BOOL fChecked = FALSE;
3375 static BOOL fIsWinNT = FALSE;
3379 OSVERSIONINFO Version;
3383 memset (&Version, 0x00, sizeof(Version));
3384 Version.dwOSVersionInfoSize = sizeof(Version);
3386 if (GetVersionEx (&Version))
3388 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3398 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3402 struct cmd_item *ti;
3407 ssp = (cm_SSetPref_t *)space;
3409 ssp->num_servers = 0;
3410 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3413 gblob.out_size = MAXSIZE;
3416 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3422 ti = as->parms[2].items; /* -file */
3424 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3425 if (!(infd = fopen(ti->data,"r" ))) {
3427 Die(errno,ti->data);
3430 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3431 code = addServer (name, (unsigned short) rank);
3435 ti = as->parms[3].items; /* -stdin */
3437 while ( scanf("%79s%ld", name, &rank) != EOF) {
3438 code = addServer (name, (unsigned short) rank);
3442 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3447 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3449 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3453 code = pokeServers();
3455 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3457 ssp = (cm_SSetPref_t *)space;
3458 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3460 ssp->flags = CM_SPREF_VLONLY;
3461 ssp->num_servers = 0;
3463 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3468 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3470 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3475 if (as->parms[1].items) {
3477 printf("now poking vlservers\n");
3478 code = pokeServers();
3488 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3492 struct cmd_item *ti;
3495 struct setspref *ssp;
3496 int error = 0; /* -1 means error message printed,
3497 * >0 means errno value for unprinted message */
3499 ssp = (struct setspref *)space;
3501 ssp->num_servers = 0;
3502 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3505 gblob.out_size = MAXSIZE;
3509 fprintf(stderr, "Permission denied: requires root access.\n");
3513 ti = as->parms[2].items; /* -file */
3516 fprintf(stderr, "opening file %s\n", ti->data);
3517 if (!(infd = fopen(ti->data, "r"))) {
3521 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3522 code = addServer(name, (unsigned short)rank);
3529 ti = as->parms[3].items; /* -stdin */
3531 while (scanf("%79s%ld", name, &rank) != EOF) {
3532 code = addServer(name, (unsigned short)rank);
3538 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3543 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3547 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3551 code = pokeServers();
3555 printf("now working on vlservers, code=%d\n", code);
3557 ssp = (struct setspref *)space;
3558 ssp->flags = DBservers;
3559 ssp->num_servers = 0;
3560 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3563 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3568 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3572 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3577 if (as->parms[1].items) {
3579 printf("now poking vlservers\n");
3580 code = pokeServers();
3588 return error ? 1 : 0;
3594 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3597 struct cmd_item *ti;
3598 char *name, tbuffer[20];
3603 struct ViceIoctl blob;
3604 struct cm_SPrefRequest *in;
3605 struct cm_SPrefInfo *out;
3609 ti = as->parms[0].items; /* -file */
3611 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3612 if (!(outfd = freopen(ti->data,"w",stdout))) {
3613 Die(errno,ti->data);
3618 ti = as->parms[1].items; /* -numeric */
3620 ti = as->parms[2].items; /* -vlservers */
3621 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3622 /* ti = as->parms[3].items; -cell */
3624 in = (struct cm_SPrefRequest *)space;
3628 blob.in_size=sizeof(struct cm_SPrefRequest);
3629 blob.in = (char *)in;
3631 blob.out_size = MAXSIZE;
3633 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3634 in->flags = vlservers;
3636 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3638 perror("getserverprefs pioctl");
3642 out = (struct cm_SPrefInfo *) blob.out;
3644 for (i=0;i<out->num_servers;i++) {
3646 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3649 addr = ntohl(out->servers[i].host.s_addr);
3650 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3651 (addr>>8) & 0xff, addr & 0xff);
3654 printf ("%-50s %5u\n",name,out->servers[i].rank);
3657 in->offset = out->next_offset;
3659 } while (!code && out->next_offset > 0);
3665 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3668 struct cmd_item *ti;
3669 char *name, tbuffer[20];
3670 afs_int32 rank, addr;
3674 struct ViceIoctl blob;
3675 struct sprefrequest *in;
3676 struct sprefinfo *out;
3679 ti = as->parms[0].items; /* -file */
3682 fprintf(stderr, "opening file %s\n", ti->data);
3683 if (!(outfd = freopen(ti->data, "w", stdout))) {
3689 ti = as->parms[1].items; /* -numeric */
3691 ti = as->parms[2].items; /* -vlservers */
3692 vlservers |= (ti ? DBservers : 0);
3693 /* ti = as->parms[3].items; -cell */
3695 in = (struct sprefrequest *)space;
3699 blob.in_size = sizeof(struct sprefrequest);
3700 blob.in = (char *)in;
3702 blob.out_size = MAXSIZE;
3705 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3706 in->flags = vlservers;
3708 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3710 perror("getserverprefs pioctl");
3714 out = (struct sprefinfo *)blob.out;
3716 for (i = 0; i < out->num_servers; i++) {
3718 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3720 addr = ntohl(out->servers[i].server.s_addr);
3721 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3722 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3725 printf("%-50s %5u\n", name, out->servers[i].rank);
3728 in->offset = out->next_offset;
3729 } while (out->next_offset > 0);
3736 SmbUnicodeCmd(struct cmd_syndesc * asp, void * arock)
3742 struct ViceIoctl blob;
3744 if (asp->parms[0].items) {
3748 } else if (asp->parms[1].items) {
3754 if (inValue != 0 && !IsAdmin()) {
3755 fprintf (stderr, "Permission denied: Requires AFS Client Administrator access.\n");
3759 blob.in_size = sizeof(inValue);
3760 blob.in = (char *) &inValue;
3761 blob.out_size = sizeof(outValue);
3762 blob.out = (char *) &outValue;
3764 code = pioctl_utf8(NULL, VIOC_UNICODECTL, &blob, 1);
3770 if (outValue != 2) {
3771 printf("Unicode support is %s%s.\n",
3772 ((outValue != 0)? "enabled":"disabled"),
3773 ((inValue != 0)? " for new SMB connections":""));
3775 printf("Unicode support is absent in this installation of OpenAFS.\n");
3782 UuidCmd(struct cmd_syndesc *asp, void *arock)
3787 struct ViceIoctl blob;
3788 char * uuidstring = NULL;
3790 if (asp->parms[0].items) {
3793 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3798 fprintf (stderr, "Permission denied: requires root access.\n");
3802 inValue = 1; /* generate new UUID */
3804 inValue = 0; /* just show the current UUID */
3807 blob.in_size = sizeof(inValue);
3808 blob.in = (char *) &inValue;
3809 blob.out_size = sizeof(outValue);
3810 blob.out = (char *) &outValue;
3812 code = pioctl_utf8(NULL, VIOC_UUIDCTL, &blob, 1);
3818 UuidToString((UUID *) &outValue, &uuidstring);
3820 printf("%sUUID: %s",
3821 ((inValue == 1)?"New ":""),
3825 RpcStringFree(&uuidstring);
3831 TraceCmd(struct cmd_syndesc *asp, void *arock)
3834 struct ViceIoctl blob;
3840 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3845 fprintf (stderr,"Permission denied: requires root access.\n");
3850 if ((asp->parms[0].items && asp->parms[1].items)) {
3851 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
3855 /* determine if we're turning this tracing on or off */
3857 if (asp->parms[0].items)
3858 inValue = 3; /* enable */
3859 else if (asp->parms[1].items)
3860 inValue = 2; /* disable */
3861 if (asp->parms[2].items)
3862 inValue |= 4; /* do reset */
3863 if (asp->parms[3].items)
3864 inValue |= 8; /* dump */
3866 blob.in_size = sizeof(long);
3867 blob.in = (char *) &inValue;
3868 blob.out_size = sizeof(long);
3869 blob.out = (char *) &outValue;
3871 code = pioctl_utf8(NULL, VIOC_TRACECTL, &blob, 1);
3878 printf("AFS tracing enabled.\n");
3880 printf("AFS tracing disabled.\n");
3885 static void sbusage(void)
3887 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
3888 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
3891 /* fs sb -kbytes 9999 -files *.o -default 64 */
3893 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3896 struct ViceIoctl blob;
3897 struct cmd_item *ti;
3898 struct sbstruct tsb, tsb2;
3906 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3911 tsb.sb_thisfile = -1;
3912 ti = as->parms[0].items; /* -kbytes */
3914 if (!as->parms[1].items) {
3915 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3919 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3920 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3921 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3927 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3928 ti = as->parms[2].items; /* -allfiles */
3930 allfiles = strtol(ti->data, &t, 10) * 1024;
3931 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3932 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3938 /* -verbose or -file only or no options */
3939 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3940 || (!as->parms[0].items && !as->parms[1].items
3941 && !as->parms[2].items))
3944 blob.in = (char *)&tsb;
3945 blob.out = (char *)&tsb2;
3946 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3947 memset(&tsb2, 0, sizeof(tsb2));
3949 /* once per -file */
3950 for (ti = as->parms[1].items; ti; ti = ti->next) {
3951 /* Do this solely to see if the file is there */
3952 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
3954 Die(errno, ti->data);
3959 code = pioctl_utf8(ti->data, VIOC_STOREBEHIND, &blob, 1);
3961 Die(errno, ti->data);
3966 if (verbose && (blob.out_size == sizeof(tsb2))) {
3967 if (tsb2.sb_thisfile == -1) {
3968 fprintf(stdout, "Will store %s according to default.\n",
3972 "Will store up to %d kbytes of %s asynchronously.\n",
3973 (tsb2.sb_thisfile / 1024), ti->data);
3978 /* If no files - make at least one pioctl call, or
3979 * set the allfiles default if we need to.
3981 if (!as->parms[1].items || (allfiles != -1)) {
3982 tsb.sb_default = allfiles;
3983 code = pioctl_utf8(0, VIOC_STOREBEHIND, &blob, 1);
3985 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3990 /* Having no arguments also reports the default store asynchrony */
3991 if (verbose && (blob.out_size == sizeof(tsb2))) {
3992 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3993 (tsb2.sb_default / 1024));
4000 SetCryptCmd(struct cmd_syndesc *as, void *arock)
4002 afs_int32 code = 0, flag;
4003 struct ViceIoctl blob;
4008 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4013 tp = as->parms[0].items->data;
4014 if (strcmp(tp, "on") == 0)
4016 else if (strcmp(tp, "off") == 0)
4018 else if (strcmp(tp, "auth") == 0)
4021 fprintf (stderr, "%s: %s must be \"on\", \"auth\", or \"off\".\n", pn, tp);
4025 blob.in = (char *) &flag;
4026 blob.in_size = sizeof(flag);
4028 code = pioctl_utf8(0, VIOC_SETRXKCRYPT, &blob, 1);
4035 GetCryptCmd(struct cmd_syndesc *as, void *arock)
4037 afs_int32 code = 0, flag;
4038 struct ViceIoctl blob;
4043 blob.out_size = sizeof(flag);
4046 code = pioctl_utf8(0, VIOC_GETRXKCRYPT, &blob, 1);
4052 memcpy(&flag, tp, sizeof(afs_int32));
4053 printf("Security level is currently ");
4055 printf("auth (data integrity).\n");
4057 printf("crypt (data security).\n");
4065 MemDumpCmd(struct cmd_syndesc *asp, void *arock)
4068 struct ViceIoctl blob;
4073 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4077 if ((asp->parms[0].items && asp->parms[1].items)) {
4078 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
4082 /* determine if we're turning this tracing on or off */
4083 if (asp->parms[0].items)
4084 inValue = 1; /* begin */
4085 else if (asp->parms[1].items)
4086 inValue = 0; /* end */
4089 blob.in_size = sizeof(long);
4090 blob.in = (char *) &inValue;
4091 blob.out_size = sizeof(long);
4092 blob.out = (char *) &outValue;
4094 code = pioctl_utf8(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
4101 printf("AFS memdump created.\n");
4104 printf("AFS memdump failed.\n");
4110 MiniDumpCmd(struct cmd_syndesc *asp, void *arock)
4113 SERVICE_STATUS status;
4114 SC_HANDLE hManager = NULL;
4115 SC_HANDLE hService = NULL;
4118 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4122 hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
4126 hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
4130 success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
4133 CloseServiceHandle(hService);
4134 CloseServiceHandle(hManager);
4136 printf("AFS minidump generated.\n");
4142 CloseServiceHandle(hService);
4144 CloseServiceHandle(hManager);
4146 printf("AFS minidump failed.\n");
4151 CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
4153 struct cmd_item *ti;
4158 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4162 for(ti=asp->parms[0].items; ti;ti=ti->next) {
4174 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4175 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4178 REG_OPTION_NON_VOLATILE,
4179 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
4184 if ( hkCSCPolicy == NULL ) {
4185 fprintf (stderr,"Permission denied: requires Administrator access.\n");
4190 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4191 RegCloseKey(hkCSCPolicy);
4197 if (asp->parms[1].items)
4199 if (asp->parms[2].items)
4200 policy = "programs";
4201 if (asp->parms[3].items)
4202 policy = "documents";
4203 if (asp->parms[4].items)
4206 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, (DWORD)strlen(policy)+1);
4208 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
4209 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
4213 DWORD dwIndex, dwPolicies;
4214 char policyName[256];
4215 DWORD policyNameLen;
4220 /* list current csc policies */
4222 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4223 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4226 REG_OPTION_NON_VOLATILE,
4227 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_QUERY_VALUE,
4232 RegQueryInfoKey( hkCSCPolicy,
4234 NULL, /* lpcClass */
4235 NULL, /* lpReserved */
4236 NULL, /* lpcSubKeys */
4237 NULL, /* lpcMaxSubKeyLen */
4238 NULL, /* lpcMaxClassLen */
4239 &dwPolicies, /* lpcValues */
4240 NULL, /* lpcMaxValueNameLen */
4241 NULL, /* lpcMaxValueLen */
4242 NULL, /* lpcbSecurityDescriptor */
4243 NULL /* lpftLastWriteTime */
4246 printf("Current CSC policies:\n");
4247 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
4249 policyNameLen = sizeof(policyName);
4250 policyLen = sizeof(policy);
4251 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
4252 &dwType, policy, &policyLen);
4254 printf(" %s = %s\n", policyName, policy);
4258 RegCloseKey(hkCSCPolicy);
4263 /* get clients interface addresses */
4265 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4268 struct cmd_item *ti;
4270 struct ViceIoctl blob;
4271 struct sprefrequest *in;
4272 struct sprefinfo *out;
4274 in = (struct sprefrequest *)space;
4278 blob.in_size = sizeof(struct sprefrequest);
4279 blob.in = (char *)in;
4281 blob.out_size = MAXSIZE;
4284 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4285 /* returns addr in network byte order */
4286 code = pioctl_utf8(0, VIOC_GETCPREFS, &blob, 1);
4288 perror("getClientInterfaceAddr pioctl");
4294 out = (struct sprefinfo *)blob.out;
4295 for (i = 0; i < out->num_servers; i++) {
4298 addr = ntohl(out->servers[i].server.s_addr);
4299 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
4300 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
4301 printf("%-50s\n", tbuffer);
4303 in->offset = out->next_offset;
4305 } while (out->next_offset > 0);
4311 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4313 afs_int32 code, addr;
4314 struct cmd_item *ti;
4316 struct ViceIoctl blob;
4317 struct setspref *ssp;
4318 int sizeUsed = 0, i, flag;
4319 afs_int32 existingAddr[1024]; /* existing addresses on this host */
4323 ssp = (struct setspref *)space;
4324 ssp->num_servers = 0;
4327 blob.out_size = MAXSIZE;
4330 fprintf(stderr, "Permission denied: requires root access.\n");
4334 /* extract all existing interface addresses */
4335 existNu = rx_getAllAddr(existingAddr, 1024);
4339 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4340 for (ti = as->parms[0].items; ti; ti = ti->next) {
4341 if (sizeUsed >= sizeof(space)) {
4342 fprintf(stderr, "No more space\n");
4345 addr = extractAddr(ti->data, 20); /* network order */
4346 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4347 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4352 /* see if it is an address that really exists */
4353 for (flag = 0, i = 0; i < existNu; i++)
4354 if (existingAddr[i] == addr) {
4358 if (!flag) { /* this is an nonexistent address */
4359 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4363 /* copy all specified addr into ioctl buffer */
4364 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4365 printf("Adding 0x%08x\n", addr);
4367 sizeUsed += sizeof(struct spref);
4369 if (ssp->num_servers < 1) {
4370 fprintf(stderr, "No addresses specified\n");
4373 blob.in_size = sizeUsed - sizeof(struct spref);
4375 code = pioctl_utf8(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4385 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4388 struct ViceIoctl blob;
4389 struct cmd_item *ti;
4390 char orig_name[1024]; /*Original name, may be modified */
4391 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4392 char parent_dir[1024]; /*Parent directory of true name */
4393 char *last_component; /*Last component of true name */
4394 struct stat statbuff; /*Buffer for status info */
4395 int link_chars_read; /*Num chars read in readlink() */
4396 int thru_symlink; /*Did we get to a mount point via a symlink? */
4399 for (ti = as->parms[0].items; ti; ti = ti->next) {
4402 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4405 if (lstat(orig_name, &statbuff) < 0) {
4406 /* if lstat fails, we should still try the pioctl, since it
4407 * may work (for example, lstat will fail, but pioctl will
4408 * work if the volume of offline (returning ENODEV). */
4409 statbuff.st_mode = S_IFDIR; /* lie like pros */
4413 * The lstat succeeded. If the given file is a symlink, substitute
4414 * the file name with the link name.
4416 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4419 * Read name of resolved file.
4421 link_chars_read = readlink(orig_name, true_name, 1024);
4422 if (link_chars_read <= 0) {
4424 "%s: Can't read target name for '%s' symbolic link!\n",
4431 * Add a trailing null to what was read, bump the length.
4433 true_name[link_chars_read++] = 0;
4436 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4437 * have to create a full pathname using the original name and the
4438 * relative symlink name. Find the rightmost slash in the original
4439 * name (we know there is one) and splice in the symlink value.
4441 if (true_name[0] != '/') {
4442 last_component = (char *)strrchr(orig_name, '/');
4443 strcpy(++last_component, true_name);
4444 strcpy(true_name, orig_name);
4447 strcpy(true_name, orig_name);
4450 * Find rightmost slash, if any.
4452 last_component = (char *)strrchr(true_name, '/');
4453 if (last_component) {
4455 * Found it. Designate everything before it as the parent directory,
4456 * everything after it as the final component.
4458 strncpy(parent_dir, true_name, last_component - true_name);
4459 parent_dir[last_component - true_name] = 0;
4460 last_component++; /*Skip the slash */
4463 * No slash appears in the given file name. Set parent_dir to the current
4464 * directory, and the last component as the given name.
4466 strcpy(parent_dir, ".");
4467 last_component = true_name;
4470 if (strcmp(last_component, ".") == 0
4471 || strcmp(last_component, "..") == 0) {
4473 "%s: you may not use '.' or '..' as the last component\n",
4475 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4481 blob.in = last_component;
4482 blob.in_size = strlen(last_component) + 1;
4484 memset(space, 0, MAXSIZE);
4486 code = pioctl_utf8(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4489 if (errno == EINVAL) {
4490 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4492 Die(errno, (ti->data ? ti->data : parent_dir));
4502 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4505 afs_int32 flags = 0;
4506 struct ViceIoctl blob;
4508 if (as->parms[0].items) { /* -enable */
4509 flags |= AFSCALL_RXSTATS_ENABLE;
4511 if (as->parms[1].items) { /* -disable */
4512 flags |= AFSCALL_RXSTATS_DISABLE;
4514 if (as->parms[2].items) { /* -clear */
4515 flags |= AFSCALL_RXSTATS_CLEAR;
4518 fprintf(stderr, "You must specify at least one argument\n");
4522 blob.in = (char *)&flags;
4523 blob.in_size = sizeof(afs_int32);
4526 code = pioctl_utf8(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4536 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4539 afs_int32 flags = 0;
4540 struct ViceIoctl blob;
4542 if (as->parms[0].items) { /* -enable */
4543 flags |= AFSCALL_RXSTATS_ENABLE;
4545 if (as->parms[1].items) { /* -disable */
4546 flags |= AFSCALL_RXSTATS_DISABLE;
4548 if (as->parms[2].items) { /* -clear */
4549 flags |= AFSCALL_RXSTATS_CLEAR;
4552 fprintf(stderr, "You must specify at least one argument\n");
4556 blob.in = (char *)&flags;
4557 blob.in_size = sizeof(afs_int32);
4560 code = pioctl_utf8(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4570 TestVolStatCmd(struct cmd_syndesc *as, void *arock)
4573 struct VolStatTest test;
4574 struct ViceIoctl blob;
4578 memset(&test, 0, sizeof(test));
4580 if (as->parms[0].items) { /* -network */
4581 tp = as->parms[0].items->data;
4582 if (strcmp(tp, "up") == 0)
4583 test.flags |= VOLSTAT_TEST_NETWORK_UP;
4584 else if (strcmp(tp, "down") == 0)
4585 test.flags |= VOLSTAT_TEST_NETWORK_DOWN;
4587 fprintf (stderr, "%s: %s must be \"up\" or \"down\".\n", pn, tp);
4591 if (as->parms[1].items) { /* check */
4592 test.flags |= VOLSTAT_TEST_CHECK_VOLUME;
4594 if (as->parms[2].items) { /* cell */
4595 tp = as->parms[2].items->data;
4600 strncpy(test.cellname, tp, sizeof(test.cellname));
4601 test.cellname[sizeof(test.cellname)-1] = '\0';
4604 if (as->parms[3].items) { /* volume */
4605 tp = as->parms[3].items->data;
4608 test.fid.volume = n;
4610 strncpy(test.volname, tp, sizeof(test.volname));
4611 test.volname[sizeof(test.volname)-1] = '\0';
4614 if (as->parms[4].items) { /* state */
4615 tp = as->parms[4].items->data;
4616 if (strcmp(tp, "online") == 0)
4617 test.state = vl_online;
4618 else if (strcmp(tp, "busy") == 0)
4619 test.state = vl_busy;
4620 else if (strcmp(tp, "offline") == 0)
4621 test.state = vl_offline;
4622 else if (strcmp(tp, "down") == 0)
4623 test.state = vl_alldown;
4625 fprintf (stderr, "%s: %s must be \"online\", \"busy\", \"offline\" or \"down\".\n", pn, tp);
4630 if ((test.fid.cell || test.cellname[0]) && !(test.fid.volume || test.volname[0]) ||
4631 !(test.fid.cell || test.cellname[0]) && (test.fid.volume || test.volname[0])) {
4632 fprintf (stderr, "%s: both a cell and a volume must be specified.\n", pn, tp);
4636 blob.in = (char *)&test;
4637 blob.in_size = sizeof(test);
4640 code = pioctl_utf8(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
4650 #include "AFS_component_version_number.c"
4654 FreeUtf8CmdLine(int argc, char ** argv)
4657 for (i=0; i < argc; i++) {
4665 MakeUtf8Cmdline(int argc, const wchar_t **wargv)
4670 argv = calloc(argc, sizeof(argv[0]));
4674 for (i=0; i < argc; i++) {
4677 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, FALSE);
4679 (argv[i] = calloc(s+1, sizeof(char))) == NULL) {
4683 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], s+1, NULL, FALSE);
4690 FreeUtf8CmdLine(argc, argv);
4697 int wmain(int argc, wchar_t **wargv)
4700 struct cmd_syndesc *ts;
4703 #ifdef AFS_AIX32_ENV
4705 * The following signal action for AIX is necessary so that in case of a
4706 * crash (i.e. core is generated) we can include the user's data section
4707 * in the core dump. Unfortunately, by default, only a partial core is
4708 * generated which, in many cases, isn't too useful.
4710 struct sigaction nsa;
4712 sigemptyset(&nsa.sa_mask);
4713 nsa.sa_handler = SIG_DFL;
4714 nsa.sa_flags = SA_FULLDUMP;
4715 sigaction(SIGSEGV, &nsa, NULL);
4720 WSAStartup(0x0101, &WSAjunk);
4723 argv = MakeUtf8Cmdline(argc, wargv);
4725 /* try to find volume location information */
4729 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
4730 "get client network interface addresses");
4731 cmd_CreateAlias(ts, "gc");
4733 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
4734 "set client network interface addresses");
4735 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
4736 "client network interfaces");
4737 cmd_CreateAlias(ts, "sc");
4740 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL, "set server ranks");
4741 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
4742 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
4743 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
4744 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
4745 cmd_CreateAlias(ts, "sp");
4747 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL, "get server ranks");
4748 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
4749 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4750 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
4751 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
4752 cmd_CreateAlias(ts, "gp");
4754 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
4755 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4756 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
4757 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
4758 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
4759 parm_setacl_id = ts->nParms;
4760 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
4761 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
4762 cmd_CreateAlias(ts, "sa");
4764 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL, "list access control list");
4765 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4766 parm_listacl_id = ts->nParms;
4767 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4768 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4769 cmd_CreateAlias(ts, "la");
4771 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL, "clean up access control list");
4772 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4774 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL, "copy access control list");
4775 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
4776 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
4777 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
4778 parm_copyacl_id = ts->nParms;
4779 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4780 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4782 cmd_CreateAlias(ts, "ca");
4784 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
4785 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4786 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4789 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
4790 "flush mount symlink from cache");
4791 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4794 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
4795 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4796 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
4798 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
4800 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
4801 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
4802 cmd_CreateAlias(ts, "sv");
4804 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL, "control Cache Manager messages");
4805 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
4807 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
4808 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4809 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4810 cmd_CreateAlias(ts, "lv");
4811 cmd_CreateAlias(ts, "listvol");
4813 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
4814 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4815 cmd_CreateAlias(ts, "lq");
4817 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL, "show server disk space usage");
4818 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4819 cmd_CreateAlias(ts, "df");
4821 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
4822 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4824 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
4825 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4827 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
4828 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
4829 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
4830 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
4831 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
4832 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
4838 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
4842 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
4843 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4845 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL, "check local cell's servers");
4846 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
4847 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
4848 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
4849 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
4851 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL, "check volumeID/name mappings");
4852 cmd_CreateAlias(ts, "checkbackups");
4855 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL, "set cache size");
4856 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
4857 cmd_CreateAlias(ts, "cachesize");
4859 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
4861 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL, "get cache usage info");
4863 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL, "list configured cells");
4864 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4866 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
4867 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
4868 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
4870 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
4872 cmd_CreateAlias(ts, "sq");
4874 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
4876 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
4877 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
4878 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
4880 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
4882 * Turn this on only if you wish to be able to talk to a server which is listening
4883 * on alternative ports. This is not intended for general use and may not be
4884 * supported in the cache manager. It is not a way to run two servers at the
4885 * same host, since the cache manager cannot properly distinguish those two hosts.
4887 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
4888 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
4891 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
4892 "configure new cell alias");
4893 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
4894 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
4897 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
4898 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4899 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4901 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
4902 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4903 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4905 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
4908 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
4911 #ifndef AFS_NT40_ENV
4912 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, "set cache monitor host address");
4913 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
4914 cmd_CreateAlias(ts, "mariner");
4917 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
4918 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4920 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
4921 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4922 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
4923 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
4925 ts = cmd_CreateSyntax("flushall", FlushAllCmd, NULL, "flush all data");
4927 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL, "flush all data in volume");
4928 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4930 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL, "get/set sysname (i.e. @sys) value");
4931 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
4933 #ifndef AFS_NT40_ENV
4934 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL, "enable/disable translators to AFS");
4935 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
4936 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
4937 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
4938 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
4939 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
4942 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
4943 "store to server after file close");
4944 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
4945 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
4946 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
4947 cmd_CreateAlias(ts, "sb");
4949 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL, "set cache manager encryption flag");
4950 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
4952 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL, "get cache manager encryption flag");
4954 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
4955 "Manage per process RX statistics");
4956 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4957 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4958 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4960 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
4961 "Manage per peer RX statistics");
4962 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4963 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4964 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4967 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
4968 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
4971 ts = cmd_CreateSyntax("trace", TraceCmd, NULL, "enable or disable CM tracing");
4972 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
4973 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
4974 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
4975 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
4976 cmd_CreateAlias(ts, "tr");
4978 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
4979 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
4981 ts = cmd_CreateSyntax("memdump", MemDumpCmd, NULL, "dump memory allocs in debug builds");
4982 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
4983 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
4985 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, NULL, "change client side caching policy for AFS shares");
4986 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
4987 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
4988 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
4989 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
4990 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
4992 ts = cmd_CreateSyntax("minidump", MiniDumpCmd, NULL, "Generate MiniDump of current service state");
4994 ts = cmd_CreateSyntax("test_volstat", TestVolStatCmd, NULL, (char *)CMD_HIDDEN);
4995 cmd_AddParm(ts, "-network", CMD_SINGLE, CMD_OPTIONAL, "set network state up or down");
4996 cmd_AddParm(ts, "-check", CMD_FLAG, CMD_OPTIONAL, "check state of offline volumes");
4997 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name or number");
4998 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or number");
4999 cmd_AddParm(ts, "-state", CMD_SINGLE, CMD_OPTIONAL, "new volume state: online, busy, offline, down");
5001 ts = cmd_CreateSyntax("smbunicode", SmbUnicodeCmd, NULL, "enable or disable Unicode on new SMB connections");
5002 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable Unicode on new connections");
5003 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable Unicode on new connections");
5005 code = cmd_Dispatch(argc, argv);
5010 FreeUtf8CmdLine(argc, argv);
5016 Die(int code, char *filename)
5019 if (code == EINVAL) {
5021 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
5023 fprintf(stderr,"%s: Invalid argument.\n", pn);
5025 else if (code == ENOENT) {
5027 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
5029 fprintf(stderr,"%s: no such file returned\n", pn);
5031 else if (code == EROFS)
5032 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
5033 else if (code == EACCES || code == EPERM) {
5035 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
5037 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
5039 else if (code == ENODEV) {
5040 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
5042 else if (code == ESRCH) { /* hack */
5043 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
5045 else if (code == EPIPE) { /* hack */
5046 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
5048 else if (code == EFBIG) {
5049 fprintf(stderr,"%s: Cache size too large.\n", pn);
5051 else if (code == ETIMEDOUT) {
5053 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
5055 fprintf(stderr,"%s: Connection timed out", pn);
5057 else if (code == EBUSY) {
5059 fprintf(stderr,"%s: All servers are busy on which '%s' resides\n", pn, filename);
5061 fprintf(stderr,"%s: All servers are busy\n", pn);
5063 else if (code == ENXIO) {
5065 fprintf(stderr,"%s: All volume instances are offline on which '%s' resides\n", pn, filename);
5067 fprintf(stderr,"%s: All volume instances are offline\n", pn);
5069 else if (code == ENOSYS) {
5071 fprintf(stderr,"%s: All servers are down on which '%s' resides\n", pn, filename);
5073 fprintf(stderr,"%s: All servers are down\n", pn);
5077 fprintf(stderr,"%s:'%s'", pn, filename);
5079 fprintf(stderr,"%s", pn);
5081 fprintf(stderr, ": code 0x%x\n", code);
5082 #else /* not WIN32 */
5083 fprintf(stderr,": %s\n", afs_error_message(code));
5084 #endif /* not WIN32 */