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>
22 #include <rx/rx_globals.h>
26 #include <afs/cellconfig.h>
27 #include <afs/ptserver.h>
28 #include <afs/ptuser.h>
29 #include <afs/volser.h>
30 #include <WINNT\afsreg.h>
40 #define MAXCELLHOSTS 8
43 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
44 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
45 #define MAXCELLCHARS 64
46 #define MAXHOSTCHARS 64
48 static char space[MAXSIZE];
49 static char tspace[1024];
51 static struct ubik_client *uclient;
53 static int GetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
54 static int SetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
55 static int FlushMountCmd(struct cmd_syndesc *asp, void *arock);
56 static int RxStatProcCmd(struct cmd_syndesc *asp, void *arock);
57 static int RxStatPeerCmd(struct cmd_syndesc *asp, void *arock);
59 extern struct cmd_syndesc *cmd_CreateSyntax();
61 static int MemDumpCmd(struct cmd_syndesc *asp, void *arock);
62 static int CSCPolicyCmd(struct cmd_syndesc *asp, void *arock);
63 static int MiniDumpCmd(struct cmd_syndesc *asp, void *arock);
65 static char pn[] = "fs";
66 static int rxInitDone = 0;
69 * Character to use between name and rights in printed representation for
72 #define DFS_SEPARATOR ' '
74 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
77 int dfs; /* Originally true if a dfs acl; now also the type
78 * of the acl (1, 2, or 3, corresponding to object,
79 * initial dir, or initial object). */
80 sec_rgy_name_t cell; /* DFS cell name */
83 struct AclEntry *pluslist;
84 struct AclEntry *minuslist;
88 struct AclEntry *next;
94 ZapAcl (struct Acl *acl)
99 ZapList(acl->pluslist);
100 ZapList(acl->minuslist);
105 * Mods for the AFS/DFS protocol translator.
107 * DFS rights. It's ugly to put these definitions here, but they
108 * *cannot* change, because they're part of the wire protocol.
109 * In any event, the protocol translator will guarantee these
110 * assignments for AFS cache managers.
112 #define DFS_READ 0x01
113 #define DFS_WRITE 0x02
114 #define DFS_EXECUTE 0x04
115 #define DFS_CONTROL 0x08
116 #define DFS_INSERT 0x10
117 #define DFS_DELETE 0x20
119 /* the application definable ones (backwards from AFS) */
120 #define DFS_USR0 0x80000000 /* "A" bit */
121 #define DFS_USR1 0x40000000 /* "B" bit */
122 #define DFS_USR2 0x20000000 /* "C" bit */
123 #define DFS_USR3 0x10000000 /* "D" bit */
124 #define DFS_USR4 0x08000000 /* "E" bit */
125 #define DFS_USR5 0x04000000 /* "F" bit */
126 #define DFS_USR6 0x02000000 /* "G" bit */
127 #define DFS_USR7 0x01000000 /* "H" bit */
128 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
129 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
132 * Offset of -id switch in command structure for various commands.
133 * The -if switch is the next switch always.
135 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
138 * Determine whether either the -id or -if switches are present, and
139 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
141 /* int id; Offset of -id switch; -if is next switch */
143 getidf(struct cmd_syndesc *as, int id)
147 if (as->parms[id].items) {
150 if (as->parms[id + 1].items) {
155 "%s: you may specify either -id or -if, but not both switches\n",
163 PRights(afs_int32 arights, int dfs)
166 if (arights & PRSFS_READ)
168 if (arights & PRSFS_LOOKUP)
170 if (arights & PRSFS_INSERT)
172 if (arights & PRSFS_DELETE)
174 if (arights & PRSFS_WRITE)
176 if (arights & PRSFS_LOCK)
178 if (arights & PRSFS_ADMINISTER)
180 if (arights & PRSFS_USR0)
182 if (arights & PRSFS_USR1)
184 if (arights & PRSFS_USR2)
186 if (arights & PRSFS_USR3)
188 if (arights & PRSFS_USR4)
190 if (arights & PRSFS_USR5)
192 if (arights & PRSFS_USR6)
194 if (arights & PRSFS_USR7)
197 if (arights & DFS_READ)
201 if (arights & DFS_WRITE)
205 if (arights & DFS_EXECUTE)
209 if (arights & DFS_CONTROL)
213 if (arights & DFS_INSERT)
217 if (arights & DFS_DELETE)
221 if (arights & (DFS_USRALL))
223 if (arights & DFS_USR0)
225 if (arights & DFS_USR1)
227 if (arights & DFS_USR2)
229 if (arights & DFS_USR3)
231 if (arights & DFS_USR4)
233 if (arights & DFS_USR5)
235 if (arights & DFS_USR6)
237 if (arights & DFS_USR7)
243 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
247 struct ViceIoctl blob;
251 blob.out_size = MAXSIZE;
254 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
256 if ((errno == EINVAL) || (errno == ENOENT))
263 IsFreelanceRoot(char *apath)
265 struct ViceIoctl blob;
269 blob.out_size = MAXSIZE;
272 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
274 return !stricmp("Freelance.Local.Root",space);
275 return 1; /* assume it is because it is more restrictive that way */
278 /* return a static pointer to a buffer */
283 strcpy(tspace, apath);
284 tp = strrchr(tspace, '\\');
286 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
289 fs_ExtractDriveLetter(apath, tspace);
295 enum rtype {add, destroy, deny};
298 Convert(char *arights, int dfs, enum rtype *rtypep)
304 *rtypep = add; /* add rights, by default */
307 if (!strcmp(arights, "null")) {
311 if (!strcmp(arights,"read"))
312 return DFS_READ | DFS_EXECUTE;
313 if (!strcmp(arights, "write"))
314 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
316 if (!strcmp(arights, "all"))
317 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
318 DFS_WRITE | DFS_CONTROL;
320 if (!strcmp(arights,"read"))
321 return PRSFS_READ | PRSFS_LOOKUP;
322 if (!strcmp(arights, "write"))
323 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
324 PRSFS_WRITE | PRSFS_LOCK;
325 if (!strcmp(arights, "mail"))
326 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
327 if (!strcmp(arights, "all"))
328 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
329 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
331 if (!strcmp(arights, "none")) {
332 *rtypep = destroy; /* Remove entire entry */
335 len = (int)strlen(arights);
371 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
379 mode |= PRSFS_LOOKUP;
381 mode |= PRSFS_INSERT;
383 mode |= PRSFS_DELETE;
389 mode |= PRSFS_ADMINISTER;
407 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
416 static struct AclEntry *
417 FindList (struct AclEntry *alist, char *aname)
420 if (!strcasecmp(alist->name, aname))
427 /* if no parm specified in a particular slot, set parm to be "." instead */
429 SetDotDefault(struct cmd_item **aitemp)
433 return; /* already has value */
434 /* otherwise, allocate an item representing "." */
435 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
437 ti->next = (struct cmd_item *) 0;
438 ti->data = (char *) malloc(2);
440 strcpy(ti->data, ".");
445 ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
447 struct AclEntry *tlist;
448 tlist = (plus ? al->pluslist : al->minuslist);
449 tlist = FindList (tlist, aname);
451 /* Found the item already in the list. */
452 tlist->rights = arights;
454 al->nplus -= PruneList(&al->pluslist, al->dfs);
456 al->nminus -= PruneList(&al->minuslist, al->dfs);
459 /* Otherwise we make a new item and plug in the new data. */
460 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
462 strcpy(tlist->name, aname);
463 tlist->rights = arights;
465 tlist->next = al->pluslist;
466 al->pluslist = tlist;
468 if (arights == 0 || arights == -1)
469 al->nplus -= PruneList(&al->pluslist, al->dfs);
471 tlist->next = al->minuslist;
472 al->minuslist = tlist;
475 al->nminus -= PruneList(&al->minuslist, al->dfs);
480 ZapList (struct AclEntry *alist)
482 struct AclEntry *tp, *np;
483 for (tp = alist; tp; tp = np) {
490 PruneList (struct AclEntry **ae, int dfs)
492 struct AclEntry **lp;
493 struct AclEntry *te, *ne;
497 for(te = *ae;te;te=ne) {
498 if ((!dfs && te->rights == 0) || te->rights == -1) {
512 SkipLine (char *astr)
521 * Create an empty acl, taking into account whether the acl pointed
522 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
523 * can recover from problems caused by bogus ACL's (in that case, always
524 * assume that the acl is AFS: for DFS, the user can always resort to
525 * acl_edit, but for AFS there may be no other way out).
533 tp = (struct Acl *)malloc(sizeof (struct Acl));
535 tp->nplus = tp->nminus = 0;
536 tp->pluslist = tp->minuslist = 0;
538 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
543 ParseAcl (char *astr)
545 int nplus, nminus, i, trights;
547 struct AclEntry *first, *last, *tl;
550 ta = (struct Acl *) malloc (sizeof (struct Acl));
553 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
554 astr = SkipLine(astr);
555 sscanf(astr, "%d", &ta->nminus);
556 astr = SkipLine(astr);
563 for(i=0;i<nplus;i++) {
564 sscanf(astr, "%100s %d", tname, &trights);
565 astr = SkipLine(astr);
566 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
570 strcpy(tl->name, tname);
571 tl->rights = trights;
577 ta->pluslist = first;
581 for(i=0;i<nminus;i++) {
582 sscanf(astr, "%100s %d", tname, &trights);
583 astr = SkipLine(astr);
584 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
588 strcpy(tl->name, tname);
589 tl->rights = trights;
595 ta->minuslist = first;
601 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
603 printf("Volume status for vid = %u named %s is\n",status->Vid, name);
605 printf("Current offline message is %s\n",offmsg);
607 printf("Current message of the day is %s\n",motd);
608 printf("Current disk quota is ");
609 if (status->MaxQuota != 0)
610 printf("%d\n", status->MaxQuota);
612 printf("unlimited\n");
613 printf("Current blocks used are %d\n",status->BlocksInUse);
614 printf("The partition has %d blocks available out of %d\n",
615 status->PartBlocksAvail, status->PartMaxBlocks);
620 QuickPrintStatus(VolumeStatus *status, char *name)
622 double QuotaUsed =0.0;
623 double PartUsed =0.0;
625 printf("%-25.25s",name);
627 if (status->MaxQuota != 0) {
628 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
629 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
631 printf("no limit%10d", status->BlocksInUse);
633 if (QuotaUsed > 90.0){
634 printf(" %5.0f%%<<", QuotaUsed);
637 printf(" %5.0f%% ", QuotaUsed);
638 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
639 if (PartUsed > 97.0){
640 printf(" %9.0f%%<<", PartUsed);
643 printf(" %9.0f%% ", PartUsed);
645 printf(" <<WARNING\n");
652 QuickPrintSpace(VolumeStatus *status, char *name)
654 double PartUsed =0.0;
656 printf("%-25.25s",name);
658 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
660 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
661 if (PartUsed > 90.0){
662 printf(" %4.0f%%<<", PartUsed);
665 printf(" %4.0f%% ", PartUsed);
667 printf(" <<WARNING\n");
674 AclToString(struct Acl *acl)
676 static char mydata[MAXSIZE];
677 char tstring[MAXSIZE];
682 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
685 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
686 for (tp = acl->pluslist;tp;tp=tp->next) {
687 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
688 strcat(mydata, tstring);
690 for (tp = acl->minuslist;tp;tp=tp->next) {
691 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
692 strcat(mydata, tstring);
697 static DWORD IsFreelance(void)
704 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
705 0, KEY_QUERY_VALUE, &parmKey);
706 if (code == ERROR_SUCCESS) {
707 dummyLen = sizeof(cm_freelanceEnabled);
708 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
709 (BYTE *) &enabled, &dummyLen);
710 RegCloseKey (parmKey);
715 static const char * NetbiosName(void)
717 static char buffer[1024] = "AFS";
723 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
724 0, KEY_QUERY_VALUE, &parmKey);
725 if (code == ERROR_SUCCESS) {
726 dummyLen = sizeof(buffer);
727 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
729 RegCloseKey (parmKey);
731 strcpy(buffer, "AFS");
736 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
738 static BOOL IsAdmin (void)
740 static BOOL fAdmin = FALSE;
741 static BOOL fTested = FALSE;
745 /* Obtain the SID for the AFS client admin group. If the group does
746 * not exist, then assume we have AFS client admin privileges.
748 PSID psidAdmin = NULL;
749 DWORD dwSize, dwSize2;
750 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
751 char *pszRefDomain = NULL;
752 SID_NAME_USE snu = SidTypeGroup;
754 dwSize = sizeof(pszAdminGroup);
756 if (!GetComputerName(pszAdminGroup, &dwSize)) {
757 /* Can't get computer name. We return false in this case.
758 Retain fAdmin and fTested. This shouldn't happen.*/
765 strcat(pszAdminGroup,"\\");
766 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
768 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
769 /* that should always fail. */
771 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
772 /* if we can't find the group, then we allow the operation */
777 if (dwSize == 0 || dwSize2 == 0) {
783 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
785 pszRefDomain = (char *)malloc(dwSize2);
786 assert(pszRefDomain);
788 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
789 /* We can't lookup the group now even though we looked it up earlier.
790 Could this happen? */
793 /* Then open our current ProcessToken */
796 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
799 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
800 /* We'll have to allocate a chunk of memory to store the list of
801 * groups to which this user belongs; find out how much memory
805 PTOKEN_GROUPS pGroups;
807 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
809 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
812 /* Allocate that buffer, and read in the list of groups. */
813 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
815 /* Look through the list of group SIDs and see if any of them
816 * matches the AFS Client Admin group SID.
819 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
821 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
831 /* if do not have permission because we were not explicitly listed
832 * in the Admin Client Group let's see if we are the SYSTEM account
835 PTOKEN_USER pTokenUser;
836 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
837 PSID pSidLocalSystem = 0;
840 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
842 pTokenUser = (PTOKEN_USER)malloc(dwSize);
845 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
846 gle = GetLastError();
848 if (AllocateAndInitializeSid( &SIDAuth, 1,
849 SECURITY_LOCAL_SYSTEM_RID,
853 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
857 FreeSid(pSidLocalSystem);
876 SetACLCmd(struct cmd_syndesc *as, void *arock)
879 struct ViceIoctl blob;
881 struct cmd_item *ti, *ui;
885 int idf = getidf(as, parm_setacl_id);
889 if (as->parms[2].items)
893 plusp = !(as->parms[3].items);
894 for(ti=as->parms[0].items; ti;ti=ti->next) {
895 blob.out_size = MAXSIZE;
897 blob.in = blob.out = space;
898 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
900 Die(errno, ti->data);
906 ta = ParseAcl(space);
907 if (!plusp && ta->dfs) {
909 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
911 "(you may specify \"null\" to revoke all rights, however)\n");
918 ta = EmptyAcl(space);
920 ta = ParseAcl(space);
921 CleanAcl(ta, ti->data);
922 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
926 "%s: Missing second half of user/access pair.\n", pn);
930 rights = Convert(ui->next->data, ta->dfs, &rtype);
931 if (rtype == destroy && !ta->dfs) {
932 struct AclEntry *tlist;
934 tlist = (plusp ? ta->pluslist : ta->minuslist);
935 if (!FindList(tlist, ui->data))
938 if (rtype == deny && !ta->dfs)
940 if (rtype == destroy && ta->dfs)
942 ChangeList(ta, plusp, ui->data, rights);
944 blob.in = AclToString(ta);
946 blob.in_size = 1+(long)strlen(blob.in);
947 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
949 if (errno == EINVAL) {
951 static char *fsenv = 0;
953 fsenv = (char *)getenv("FS_EXPERT");
955 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
958 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
959 "\nPossible reasons for this include:\n\n",
960 " -You may have specified an inappropriate combination of rights.\n",
961 " For example, some DFS-supported filesystems may not allow you to\n",
962 " drop the \"c\" right from \"user_obj\".\n\n",
963 " -A mask_obj may be required (it is likely required by the underlying\n",
964 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
965 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
966 " does not automatically create or update the mask_obj. Try setting\n",
967 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
968 " users or groups. You can do this with a single command, such as\n",
969 " \"fs sa mask_obj all user:somename read\"\n\n",
970 " -A specified user or group may not exist.\n\n",
971 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
972 " This is probably not allowed by the underlying file system.\n\n",
973 " -If you add a user or group to a DFS ACL, remember that it must be\n",
974 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
975 " may be local requirements on the format of the user or group name.\n",
976 " Check with your cell administrator.\n\n",
977 " -Or numerous other possibilities. It would be great if we could be more\n",
978 " precise about the actual problem, but for various reasons, this is\n",
979 " impractical via this interface. If you can't figure it out, you\n",
980 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
981 " whatever is provided). You may get better results. Good luck!\n\n",
982 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
986 "%s: Invalid argument, possible reasons include:\n",
988 fprintf(stderr,"\t-File not in AFS\n");
990 "\t-Too many users on access control list\n");
992 "\t-Tried to add non-existent user to access control list\n");
995 Die(errno, ti->data);
1006 CopyACLCmd(struct cmd_syndesc *as, void *arock)
1009 struct ViceIoctl blob;
1010 struct Acl *fa, *ta = 0;
1011 struct AclEntry *tp;
1012 struct cmd_item *ti;
1014 int idf = getidf(as, parm_copyacl_id);
1017 if (as->parms[2].items)
1021 blob.out_size = MAXSIZE;
1023 blob.in = blob.out = space;
1024 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1026 Die(errno, as->parms[0].items->data);
1029 fa = ParseAcl(space);
1030 CleanAcl(fa, as->parms[0].items->data);
1031 for (ti=as->parms[1].items; ti;ti=ti->next) {
1032 blob.out_size = MAXSIZE;
1034 blob.in = blob.out = space;
1035 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1037 Die(errno, ti->data);
1044 ta = EmptyAcl(space);
1046 ta = ParseAcl(space);
1047 CleanAcl(ta, ti->data);
1048 if (ta->dfs != fa->dfs) {
1050 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1056 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1058 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1063 strcpy(ta->cell, fa->cell);
1065 for (tp = fa->pluslist;tp;tp=tp->next)
1066 ChangeList(ta, 1, tp->name, tp->rights);
1067 for (tp = fa->minuslist;tp;tp=tp->next)
1068 ChangeList(ta, 0, tp->name, tp->rights);
1069 blob.in = AclToString(ta);
1071 blob.in_size = 1+(long)strlen(blob.in);
1072 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1074 if (errno == EINVAL) {
1076 "%s: Invalid argument, possible reasons include:\n", pn);
1077 fprintf(stderr,"\t-File not in AFS\n");
1079 Die(errno, ti->data);
1090 /* pioctl() call to get the cellname of a pathname */
1092 GetCell(char *fname, char *cellname)
1095 struct ViceIoctl blob;
1098 blob.out_size = MAXCELLCHARS;
1099 blob.out = cellname;
1101 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1105 /* Check if a username is valid: If it contains only digits (or a
1106 * negative sign), then it might be bad. We then query the ptserver
1110 BadName(char *aname, char *fname)
1112 afs_int32 tc, code, id;
1114 char cell[MAXCELLCHARS];
1116 for ( nm = aname; tc = *nm; nm++) {
1117 /* all must be '-' or digit to be bad */
1118 if (tc != '-' && (tc < '0' || tc > '9'))
1122 /* Go to the PRDB and see if this all number username is valid */
1123 code = GetCell(fname, cell);
1127 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
1128 code = pr_SNameToId(aname, &id);
1131 /* 1=>Not-valid; 0=>Valid */
1132 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1136 /* clean up an access control list of its bad entries; return 1 if we made
1137 any changes to the list, and 0 otherwise */
1139 CleanAcl(struct Acl *aa, char *fname)
1141 struct AclEntry *te, **le, *ne;
1144 /* Don't correct DFS ACL's for now */
1148 /* prune out bad entries */
1149 changes = 0; /* count deleted entries */
1151 for(te = aa->pluslist; te; te=ne) {
1153 if (BadName(te->name, fname)) {
1163 le = &aa->minuslist;
1164 for(te = aa->minuslist; te; te=ne) {
1166 if (BadName(te->name, fname)) {
1180 /* clean up an acl to not have bogus entries */
1182 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1186 struct ViceIoctl blob;
1188 struct cmd_item *ti;
1189 struct AclEntry *te;
1192 SetDotDefault(&as->parms[0].items);
1193 for(ti=as->parms[0].items; ti; ti=ti->next) {
1194 blob.out_size = MAXSIZE;
1197 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1199 Die(errno, ti->data);
1205 ta = ParseAcl(space);
1209 "%s: cleanacl is not supported for DFS access lists.\n",
1215 changes = CleanAcl(ta, ti->data);
1218 /* now set the acl */
1219 blob.in=AclToString(ta);
1220 blob.in_size = (long)strlen(blob.in)+1;
1222 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1224 if (errno == EINVAL) {
1226 "%s: Invalid argument, possible reasons include\n",
1228 fprintf(stderr,"%s: File not in vice or\n", pn);
1230 "%s: Too many users on access control list or\n",
1233 Die(errno, ti->data);
1239 /* now list the updated acl */
1240 printf("Access list for %s is now\n", ti->data);
1241 if (ta->nplus > 0) {
1243 printf("Normal rights:\n");
1244 for(te = ta->pluslist;te;te=te->next) {
1245 printf(" %s ", te->name);
1246 PRights(te->rights, ta->dfs);
1250 if (ta->nminus > 0) {
1251 printf("Negative rights:\n");
1252 for(te = ta->minuslist;te;te=te->next) {
1253 printf(" %s ", te->name);
1254 PRights(te->rights, ta->dfs);
1261 printf("Access list for %s is fine.\n", ti->data);
1269 ListACLCmd(struct cmd_syndesc *as, void *arock)
1273 struct ViceIoctl blob;
1274 struct AclEntry *te;
1275 struct cmd_item *ti;
1276 int idf = getidf(as, parm_listacl_id);
1279 SetDotDefault(&as->parms[0].items);
1280 for(ti=as->parms[0].items; ti; ti=ti->next) {
1282 blob.out_size = MAXSIZE;
1284 blob.in = blob.out = space;
1285 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1287 Die(errno, ti->data);
1291 ta = ParseAcl(space);
1294 printf("Access list for %s is\n", ti->data);
1297 printf("DFS access list for %s is\n", ti->data);
1300 printf("DFS initial directory access list of %s is\n", ti->data);
1303 printf("DFS initial file access list of %s is\n", ti->data);
1307 printf(" Default cell = %s\n", ta->cell);
1309 separator = ta->dfs? DFS_SEPARATOR : ' ';
1310 if (ta->nplus > 0) {
1312 printf("Normal rights:\n");
1313 for(te = ta->pluslist;te;te=te->next) {
1314 printf(" %s%c", te->name, separator);
1315 PRights(te->rights, ta->dfs);
1319 if (ta->nminus > 0) {
1320 printf("Negative rights:\n");
1321 for(te = ta->minuslist;te;te=te->next) {
1322 printf(" %s ", te->name);
1323 PRights(te->rights, ta->dfs);
1335 FlushAllCmd(struct cmd_syndesc *as, void *arock)
1338 struct ViceIoctl blob;
1340 blob.in_size = blob.out_size = 0;
1341 code = pioctl(NULL, VIOC_FLUSHALL, &blob, 0);
1343 fprintf(stderr, "Error flushing all ");
1350 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1353 struct ViceIoctl blob;
1354 struct cmd_item *ti;
1357 SetDotDefault(&as->parms[0].items);
1358 for(ti=as->parms[0].items; ti; ti=ti->next) {
1359 blob.in_size = blob.out_size = 0;
1360 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1362 fprintf(stderr, "Error flushing volume ");
1372 FlushCmd(struct cmd_syndesc *as, void *arock)
1375 struct ViceIoctl blob;
1376 struct cmd_item *ti;
1379 cm_ioctlQueryOptions_t options;
1381 if (as->parms[1].items)
1384 for(ti=as->parms[0].items; ti; ti=ti->next) {
1386 memset(&options, 0, sizeof(options));
1387 options.size = sizeof(options);
1388 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1389 options.literal = literal;
1390 blob.in_size = options.size; /* no variable length data */
1394 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1396 if (errno == EMFILE) {
1397 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1400 fprintf(stderr, "%s: Error flushing file ", pn);
1410 /* all this command does is repackage its args and call SetVolCmd */
1412 SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
1413 struct cmd_syndesc ts;
1415 /* copy useful stuff from our command slot; we may later have to reorder */
1416 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1417 return SetVolCmd(&ts, arock);
1421 SetVolCmd(struct cmd_syndesc *as, void *arock) {
1423 struct ViceIoctl blob;
1424 struct cmd_item *ti;
1425 struct VolumeStatus *status;
1426 char *motd, *offmsg, *input;
1429 SetDotDefault(&as->parms[0].items);
1430 for(ti=as->parms[0].items; ti; ti=ti->next) {
1432 blob.out_size = MAXSIZE;
1433 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1436 status = (VolumeStatus *)space;
1437 status->MinQuota = status->MaxQuota = -1;
1438 motd = offmsg = NULL;
1439 if (as->parms[1].items) {
1440 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1442 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1447 if (as->parms[2].items)
1448 motd = as->parms[2].items->data;
1449 if (as->parms[3].items)
1450 offmsg = as->parms[3].items->data;
1451 input = (char *)status + sizeof(*status);
1452 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1454 if (strlen(offmsg) >= VMSGSIZE) {
1455 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1460 strcpy(input,offmsg);
1461 blob.in_size += (long)strlen(offmsg);
1462 input += strlen(offmsg) + 1;
1466 if (strlen(motd) >= VMSGSIZE) {
1467 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1472 blob.in_size += (long)strlen(motd);
1473 input += strlen(motd) + 1;
1476 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1478 Die(errno, ti->data);
1485 /* values match cache manager File Types */
1487 filetypestr(afs_uint32 type)
1489 char * s = "Object";
1512 ExamineCmd(struct cmd_syndesc *as, void *arock)
1515 struct ViceIoctl blob;
1516 struct cmd_item *ti;
1517 struct VolumeStatus *status;
1518 char *name, *offmsg, *motd;
1521 cm_ioctlQueryOptions_t options;
1523 if (as->parms[1].items)
1526 SetDotDefault(&as->parms[0].items);
1527 for(ti=as->parms[0].items; ti; ti=ti->next) {
1529 afs_uint32 filetype;
1530 afs_uint32 owner[2];
1531 char cell[MAXCELLCHARS];
1534 memset(&fid, 0, sizeof(fid));
1535 memset(&options, 0, sizeof(options));
1537 options.size = sizeof(options);
1538 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1539 options.literal = literal;
1540 blob.in_size = options.size; /* no variable length data */
1543 blob.out_size = sizeof(cm_fid_t);
1544 blob.out = (char *) &fid;
1545 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1546 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1549 Die(errno, ti->data);
1554 blob.out_size = sizeof(filetype);
1555 blob.out = &filetype;
1557 code = pioctl(ti->data, VIOC_GETFILETYPE, &blob, 1);
1559 blob.out_size = MAXCELLCHARS;
1562 code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1563 printf("%s %s (%u.%u.%u) contained in cell %s\n",
1564 filetypestr(filetype),
1565 ti->data, fid.volume, fid.vnode, fid.unique,
1566 code ? "unknown-cell" : cell);
1568 blob.out_size = 2 * sizeof(afs_uint32);
1569 blob.out = (char *) &owner;
1570 if (0 == pioctl(ti->data, VIOCGETOWNER, &blob, 1)) {
1571 char oname[PR_MAXNAMELEN] = "(unknown)";
1573 /* Go to the PRDB and see if this all number username is valid */
1574 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
1575 pr_SIdToName(owner[0], oname);
1576 printf("Owner %s (%u) Group %u\n", oname, owner[0], owner[1]);
1580 blob.out_size = MAXSIZE;
1581 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1583 status = (VolumeStatus *)space;
1584 name = (char *)status + sizeof(*status);
1585 offmsg = name + strlen(name) + 1;
1586 motd = offmsg + strlen(offmsg) + 1;
1588 PrintStatus(status, name, motd, offmsg);
1590 Die(errno, ti->data);
1594 code = pioctl(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
1597 printf("Volume is online\n");
1600 printf("Volume is offline\n");
1603 printf("All Volume servers are down\n");
1606 printf("All volume servers are busy\n");
1609 printf("Unknown volume state\n");
1610 Die(errno, ti->data);
1618 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1621 struct ViceIoctl blob;
1622 struct cmd_item *ti;
1623 struct VolumeStatus *status;
1628 printf("%-25s%-10s%-10s%-7s%-13s\n",
1629 "Volume Name", " Quota", " Used", " %Used", " Partition");
1630 SetDotDefault(&as->parms[0].items);
1631 for(ti=as->parms[0].items; ti; ti=ti->next) {
1633 blob.out_size = MAXSIZE;
1636 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1638 Die(errno, ti->data);
1642 status = (VolumeStatus *)space;
1643 name = (char *)status + sizeof(*status);
1644 QuickPrintStatus(status, name);
1650 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1653 struct ViceIoctl blob;
1654 struct cmd_item *ti;
1660 cm_ioctlQueryOptions_t options;
1662 if (as->parms[1].items)
1665 SetDotDefault(&as->parms[0].items);
1666 for(ti=as->parms[0].items; ti; ti=ti->next) {
1668 afs_uint32 filetype;
1671 memset(&fid, 0, sizeof(fid));
1672 memset(&options, 0, sizeof(options));
1674 options.size = sizeof(options);
1675 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1676 options.literal = literal;
1677 blob.in_size = options.size; /* no variable length data */
1680 blob.out_size = sizeof(cm_fid_t);
1681 blob.out = (char *) &fid;
1682 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1683 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1686 Die(errno, ti->data);
1691 blob.out_size = sizeof(filetype);
1692 blob.out = &filetype;
1694 code = pioctl(ti->data, VIOC_GETFILETYPE, &blob, 1);
1696 blob.out_size = MAXSIZE;
1698 memset(space, 0, sizeof(space));
1699 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1701 Die(errno, ti->data);
1705 hosts = (afs_int32 *) space;
1706 printf("%s %s is on host%s ",
1707 filetypestr(filetype),
1709 (hosts[0] && !hosts[1]) ? "": "s");
1710 for(j=0; j<MAXHOSTS; j++) {
1713 tp = hostutil_GetNameByINet(hosts[j]);
1723 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1726 struct ViceIoctl blob;
1727 struct cmd_item *ti;
1729 struct VolumeStatus *status;
1732 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1733 " used", " avail", " %used");
1734 SetDotDefault(&as->parms[0].items);
1735 for(ti=as->parms[0].items; ti; ti=ti->next) {
1737 blob.out_size = MAXSIZE;
1740 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1742 Die(errno, ti->data);
1746 status = (VolumeStatus *)space;
1747 name = (char *)status + sizeof(*status);
1748 QuickPrintSpace(status, name);
1754 QuotaCmd(struct cmd_syndesc *as, void *arock)
1757 struct ViceIoctl blob;
1758 struct cmd_item *ti;
1760 struct VolumeStatus *status;
1763 SetDotDefault(&as->parms[0].items);
1764 for(ti=as->parms[0].items; ti; ti=ti->next) {
1766 blob.out_size = MAXSIZE;
1769 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1771 Die(errno, ti->data);
1775 status = (VolumeStatus *)space;
1776 if (status->MaxQuota)
1777 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1780 printf("%2.0f%% of quota used.\n", quotaPct);
1786 ListMountCmd(struct cmd_syndesc *as, void *arock)
1789 struct ViceIoctl blob;
1790 struct cmd_item *ti;
1791 char orig_name[1024]; /*Original name, may be modified*/
1792 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1793 char parent_dir[1024]; /*Parent directory of true name*/
1794 char *last_component; /*Last component of true name*/
1796 struct stat statbuff; /*Buffer for status info*/
1797 #endif /* not WIN32 */
1799 int link_chars_read; /*Num chars read in readlink()*/
1800 #endif /* not WIN32 */
1801 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1804 for(ti=as->parms[0].items; ti; ti=ti->next) {
1808 strcpy(orig_name, ti->data);
1809 #else /* not WIN32 */
1810 sprintf(orig_name, "%s%s",
1811 (ti->data[0] == '/') ? "" : "./",
1813 #endif /* not WIN32 */
1816 if (lstat(orig_name, &statbuff) < 0) {
1817 /* if lstat fails, we should still try the pioctl, since it
1818 * may work (for example, lstat will fail, but pioctl will
1819 * work if the volume of offline (returning ENODEV). */
1820 statbuff.st_mode = S_IFDIR; /* lie like pros */
1824 * The lstat succeeded. If the given file is a symlink, substitute
1825 * the file name with the link name.
1827 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1830 * Read name of resolved file.
1832 link_chars_read = readlink(orig_name, true_name, 1024);
1833 if (link_chars_read <= 0) {
1835 "%s: Can't read target name for '%s' symbolic link!\n",
1842 * Add a trailing null to what was read, bump the length.
1844 true_name[link_chars_read++] = 0;
1847 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1848 * have to create a full pathname using the original name and the
1849 * relative symlink name. Find the rightmost slash in the original
1850 * name (we know there is one) and splice in the symlink value.
1852 if (true_name[0] != '\\') {
1853 last_component = (char *) strrchr(orig_name, '\\');
1854 strcpy(++last_component, true_name);
1855 strcpy(true_name, orig_name);
1858 strcpy(true_name, orig_name);
1860 strcpy(true_name, orig_name);
1864 * Find rightmost slash, if any.
1867 last_component = (char *) strrchr(true_name, '\\');
1868 if (!last_component)
1870 last_component = (char *) strrchr(true_name, '/');
1871 if (last_component) {
1873 * Found it. Designate everything before it as the parent directory,
1874 * everything after it as the final component.
1876 strncpy(parent_dir, true_name, last_component - true_name + 1);
1877 parent_dir[last_component - true_name + 1] = 0;
1878 last_component++; /*Skip the slash*/
1880 if (!InAFS(parent_dir)) {
1881 const char * nbname = NetbiosName();
1882 int len = (int)strlen(nbname);
1884 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
1885 parent_dir[len+2] == '\\' &&
1886 parent_dir[len+3] == '\0' &&
1887 !strnicmp(nbname,&parent_dir[2],len))
1889 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
1895 * No slash appears in the given file name. Set parent_dir to the current
1896 * directory, and the last component as the given name.
1898 fs_ExtractDriveLetter(true_name, parent_dir);
1899 strcat(parent_dir, ".");
1900 last_component = true_name;
1901 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1904 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1905 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
1906 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
1911 blob.in = last_component;
1912 blob.in_size = (long)strlen(last_component)+1;
1913 blob.out_size = MAXSIZE;
1915 memset(space, 0, MAXSIZE);
1917 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1920 printf("'%s' is a %smount point for volume '%s'\n",
1922 (thru_symlink ? "symbolic link, leading to a " : ""),
1926 if (errno == EINVAL) {
1927 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
1929 Die(errno, (ti->data ? ti->data : parent_dir));
1938 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1941 char *cellName, *volName, *tmpName;
1943 char localCellName[128];
1945 char path[1024] = "";
1946 struct afsconf_cell info;
1947 struct vldbentry vldbEntry;
1948 struct ViceIoctl blob;
1951 if (as->parms[2].items) /* cell name specified */
1952 cellName = as->parms[2].items->data;
1955 volName = as->parms[1].items->data;
1957 if (strlen(volName) >= 64) {
1958 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
1962 /* Check for a cellname in the volume specification, and complain
1963 * if it doesn't match what was specified with -cell */
1964 if (tmpName = strchr(volName, ':')) {
1967 if (strcasecmp(cellName,volName)) {
1968 fprintf(stderr,"fs: cellnames do not match.\n");
1973 volName = ++tmpName;
1976 parent = Parent(as->parms[0].items->data);
1977 if (!InAFS(parent)) {
1979 const char * nbname = NetbiosName();
1980 int len = (int)strlen(nbname);
1982 if (parent[0] == '\\' && parent[1] == '\\' &&
1983 parent[len+2] == '\\' &&
1984 parent[len+3] == '\0' &&
1985 !strnicmp(nbname,&parent[2],len))
1987 sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
1988 parent = Parent(path);
1989 if (!InAFS(parent)) {
1990 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
1996 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2001 if ( strlen(path) == 0 )
2002 strcpy(path, as->parms[0].items->data);
2004 if ( IsFreelanceRoot(parent) ) {
2006 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2012 blob.out_size = sizeof(localCellName);
2013 blob.out = localCellName;
2014 code = pioctl(parent, VIOC_GET_WS_CELL, &blob, 1);
2016 cellName = localCellName;
2020 code = GetCell(parent,space);
2026 code = GetCellName(cellName?cellName:space, &info);
2030 if (!(as->parms[4].items)) {
2031 /* not fast, check which cell the mountpoint is being created in */
2033 /* not fast, check name with VLDB */
2035 code = VLDBInit(1, &info);
2037 /* make the check. Don't complain if there are problems with init */
2038 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2039 if (code == VL_NOENT) {
2040 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2041 pn, volName, cellName ? cellName : space);
2046 if (as->parms[3].items) /* if -rw specified */
2051 /* cellular mount point, prepend cell prefix */
2052 strcat(space, info.name);
2055 strcat(space, volName); /* append volume name */
2056 strcat(space, "."); /* stupid convention; these end with a period */
2058 /* create symlink with a special pioctl for Windows NT, since it doesn't
2059 * have a symlink system call.
2062 blob.in_size = 1 + (long)strlen(space);
2065 code = pioctl(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2066 #else /* not WIN32 */
2067 code = symlink(space, path);
2068 #endif /* not WIN32 */
2077 * Delete AFS mount points. Variables are used as follows:
2078 * tbuffer: Set to point to the null-terminated directory name of the mount point
2079 * (or ``.'' if none is provided)
2080 * tp: Set to point to the actual name of the mount point to nuke.
2083 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2085 struct ViceIoctl blob;
2086 struct cmd_item *ti;
2088 char lsbuffer[1024];
2092 for(ti=as->parms[0].items; ti; ti=ti->next) {
2094 tp = (char *) strrchr(ti->data, '\\');
2096 tp = (char *) strrchr(ti->data, '/');
2098 strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1)); /* the dir name */
2100 tp++; /* skip the slash */
2103 if (!InAFS(tbuffer)) {
2104 const char * nbname = NetbiosName();
2105 int len = (int)strlen(nbname);
2107 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2108 tbuffer[len+2] == '\\' &&
2109 tbuffer[len+3] == '\0' &&
2110 !strnicmp(nbname,&tbuffer[2],len))
2112 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
2117 fs_ExtractDriveLetter(ti->data, tbuffer);
2118 strcat(tbuffer, ".");
2120 fs_StripDriveLetter(tp, tp, 0);
2123 blob.in_size = (long)strlen(tp)+1;
2124 blob.out = lsbuffer;
2125 blob.out_size = sizeof(lsbuffer);
2126 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2128 if (errno == EINVAL) {
2129 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2131 Die(errno, ti->data);
2134 continue; /* don't bother trying */
2137 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2138 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2140 continue; /* skip */
2145 blob.in_size = (long)strlen(tp)+1;
2146 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2148 Die(errno, ti->data);
2159 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2162 struct ViceIoctl blob;
2166 struct afsconf_cell info;
2167 struct chservinfo checkserv;
2169 memset(&checkserv, 0, sizeof(struct chservinfo));
2170 blob.in_size=sizeof(struct chservinfo);
2171 blob.in=(caddr_t)&checkserv;
2173 blob.out_size = MAXSIZE;
2175 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2177 /* prepare flags for checkservers command */
2178 temp = 2; /* default to checking local cell only */
2179 if (as->parms[2].items)
2180 temp |= 1; /* set fast flag */
2181 if (as->parms[1].items)
2182 temp &= ~2; /* turn off local cell check */
2184 checkserv.magic = 0x12345678; /* XXX */
2185 checkserv.tflags=temp;
2187 /* now copy in optional cell name, if specified */
2188 if (as->parms[0].items) {
2189 code = GetCellName(as->parms[0].items->data, &info);
2193 strcpy(checkserv.tbuffer,info.name);
2194 checkserv.tsize=(int)strlen(info.name)+1;
2196 strcpy(checkserv.tbuffer,"\0");
2200 if(as->parms[3].items) {
2201 checkserv.tinterval=atol(as->parms[3].items->data);
2204 if(checkserv.tinterval<0) {
2205 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2206 checkserv.tinterval=-1;
2207 } else if(checkserv.tinterval> 600) {
2208 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2209 checkserv.tinterval=600; /* 10 min max interval */
2212 checkserv.tinterval = -1; /* don't change current interval */
2215 if ( checkserv.tinterval >= 0 ) {
2218 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2223 fprintf (stderr,"Permission denied: requires root access.\n");
2229 code = pioctl(0, VIOCCKSERV, &blob, 1);
2231 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2232 printf("Must be root to change -interval\n");
2238 memcpy(&temp, space, sizeof(afs_int32));
2239 if (checkserv.tinterval >= 0) {
2240 if (checkserv.tinterval > 0)
2241 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2242 checkserv.tinterval, temp);
2244 printf("The current down server probe interval is %d secs\n", temp);
2248 printf("All servers are running.\n");
2250 printf("These servers unavailable due to network or server problems: ");
2251 for(j=0; j < MAXHOSTS; j++) {
2252 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2255 tp = hostutil_GetNameByINet(temp);
2265 MessagesCmd(struct cmd_syndesc *as, void *arock)
2268 struct ViceIoctl blob;
2269 struct gaginfo gagflags;
2270 struct cmd_item *show;
2272 memset(&gagflags, 0, sizeof(struct gaginfo));
2273 blob.in_size = sizeof(struct gaginfo);
2274 blob.in = (caddr_t ) &gagflags;
2275 blob.out_size = MAXSIZE;
2277 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2279 if (show = as->parms[0].items) {
2280 if (!strcasecmp (show->data, "user"))
2281 gagflags.showflags |= GAGUSER;
2282 else if (!strcasecmp (show->data, "console"))
2283 gagflags.showflags |= GAGCONSOLE;
2284 else if (!strcasecmp (show->data, "all"))
2285 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2286 else if (!strcasecmp (show->data, "none"))
2290 "unrecognized flag %s: must be in {user,console,all,none}\n",
2299 code = pioctl(0, VIOC_GAG, &blob, 1);
2308 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2311 struct ViceIoctl blob;
2315 code = pioctl(0, VIOCCKBACK, &blob, 1);
2320 printf("All volumeID/name mappings checked.\n");
2326 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2329 struct ViceIoctl blob;
2334 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2339 fprintf (stderr,"Permission denied: requires root access.\n");
2344 if (!as->parms[0].items && !as->parms[1].items) {
2345 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2348 if (as->parms[0].items) {
2349 code = util_GetInt32(as->parms[0].items->data, &temp);
2351 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2356 blob.in = (char *) &temp;
2357 blob.in_size = sizeof(afs_int32);
2359 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2361 Die(errno, (char *) 0);
2365 printf("New cache size set.\n");
2370 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2373 struct ViceIoctl blob;
2374 cm_cacheParms_t parms;
2376 memset(&parms, 0, sizeof(parms));
2379 blob.out_size = sizeof(parms);
2380 blob.out = (char *) &parms;
2381 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2387 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2388 parms.parms[1], parms.parms[0]);
2389 if (parms.parms[1] > parms.parms[0])
2390 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2395 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2398 afs_int32 i, j, *lp, magic, size;
2400 afs_int32 addr, maxa = OMAXHOSTS;
2401 struct ViceIoctl blob;
2404 resolve = !(as->parms[0].items); /* -numeric */
2406 for(i=0;i<1000;i++) {
2408 memcpy(tp, &i, sizeof(afs_int32));
2409 tp = (char *)(space + sizeof(afs_int32));
2410 lp = (afs_int32 *)tp;
2412 size = sizeof(afs_int32) + sizeof(afs_int32);
2413 blob.out_size = MAXSIZE;
2414 blob.in_size = sizeof(afs_int32);
2417 code = pioctl(0, VIOCGETCELL, &blob, 1);
2420 break; /* done with the list */
2425 memcpy(&magic, tp, sizeof(afs_int32));
2426 if (magic == 0x12345678) {
2428 tp += sizeof(afs_int32);
2430 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2431 for(j=0; j < maxa; j++) {
2432 char *name, tbuffer[20];
2434 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2439 name = hostutil_GetNameByINet(addr);
2442 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2443 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2446 printf(" %s", name);
2455 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2458 char *tp, *aliasName, *realName;
2459 struct ViceIoctl blob;
2463 memcpy(tp, &i, sizeof(afs_int32));
2464 blob.out_size = MAXSIZE;
2465 blob.in_size = sizeof(afs_int32);
2468 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2471 break; /* done with the list */
2477 tp += strlen(aliasName) + 1;
2479 printf("Alias %s for cell %s\n", aliasName, realName);
2485 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2488 struct ViceIoctl blob;
2489 struct cmd_item *ti;
2491 struct hostent *thp;
2495 ti = as->parms[0].items;
2498 thp = hostutil_GetHostByName(ti->data);
2500 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2503 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2505 hostAddr = 0; /* means don't set host */
2506 setp = 0; /* aren't setting host */
2509 /* now do operation */
2510 blob.in_size = sizeof(afs_int32);
2511 blob.out_size = sizeof(afs_int32);
2512 blob.in = (char *) &hostAddr;
2513 blob.out = (char *) &hostAddr;
2515 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2525 NewCellCmd(struct cmd_syndesc *as, void *arock)
2528 afs_int32 code, linkedstate=0, size=0, *lp;
2529 struct ViceIoctl blob;
2530 struct cmd_item *ti;
2531 char *tp, *cellname=0;
2532 struct hostent *thp;
2533 afs_int32 fsport = 0, vlport = 0;
2535 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
2537 lp = (afs_int32 *)tp;
2539 tp += sizeof(afs_int32);
2540 for(ti=as->parms[1].items; ti; ti=ti->next) {
2541 thp = hostutil_GetHostByName(ti->data);
2543 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2547 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2548 tp += sizeof(afs_int32);
2551 if (as->parms[2].items) {
2553 * Link the cell, for the purposes of volume location, to the specified
2556 cellname = as->parms[2].items->data;
2559 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2560 if (as->parms[3].items) {
2561 code = util_GetInt32(as->parms[3].items->data, &vlport);
2563 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2567 if (as->parms[4].items) {
2568 code = util_GetInt32(as->parms[4].items->data, &fsport);
2570 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2575 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
2576 lp = (afs_int32 *)tp;
2580 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2581 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2582 tp = (char *)(space + size);
2584 strcpy(tp, cellname);
2585 size += strlen(cellname) + 1;
2587 blob.in_size = size;
2590 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2596 struct ViceIoctl blob;
2599 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2604 blob.in = (char *) 0;
2605 blob.out_size = MAXSIZE;
2608 code = pioctl((char *) 0, VIOCNEWCELL, &blob, 1);
2611 Die(errno, (char *) 0);
2615 printf("Cell servers information refreshed\n");
2622 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2625 struct ViceIoctl blob;
2627 char *aliasName, *realName;
2629 /* Setup and do the NEWALIAS pioctl call */
2630 aliasName = as->parms[0].items->data;
2631 realName = as->parms[1].items->data;
2633 strcpy(tp, aliasName);
2634 tp += strlen(aliasName) + 1;
2635 strcpy(tp, realName);
2636 tp += strlen(realName) + 1;
2638 blob.in_size = tp - space;
2642 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2644 if (errno == EEXIST) {
2646 "%s: cell name `%s' in use by an existing cell.\n", pn,
2658 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2661 struct cmd_item *ti;
2662 struct ViceIoctl blob;
2665 cm_ioctlQueryOptions_t options;
2667 if (as->parms[1].items)
2670 SetDotDefault(&as->parms[0].items);
2671 for(ti=as->parms[0].items; ti; ti=ti->next) {
2673 afs_uint32 filetype;
2674 char cell[MAXCELLCHARS];
2677 memset(&fid, 0, sizeof(fid));
2678 memset(&options, 0, sizeof(options));
2680 options.size = sizeof(options);
2681 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
2682 options.literal = literal;
2683 blob.in_size = options.size; /* no variable length data */
2686 blob.out_size = sizeof(cm_fid_t);
2687 blob.out = (char *) &fid;
2688 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
2689 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
2692 Die(errno, ti->data);
2697 blob.out_size = sizeof(filetype);
2698 blob.out = &filetype;
2700 code = pioctl(ti->data, VIOC_GETFILETYPE, &blob, 1);
2702 blob.out_size = MAXCELLCHARS;
2705 code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
2707 if (errno == ENOENT)
2708 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2710 Die(errno, ti->data);
2714 printf("%s %s lives in cell '%s'\n",
2715 filetypestr(filetype),
2722 WSCellCmd(struct cmd_syndesc *as, void *arock)
2725 struct ViceIoctl blob;
2729 blob.out_size = MAXSIZE;
2732 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2739 printf("This workstation belongs to cell '%s'\n", space);
2745 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
2747 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2752 #ifndef AFS_NT40_ENV
2754 MonitorCmd(struct cmd_syndesc *as, void *arock)
2757 struct ViceIoctl blob;
2758 struct cmd_item *ti;
2760 struct hostent *thp;
2764 ti = as->parms[0].items;
2768 if (!strcmp(ti->data, "off")) {
2769 hostAddr = 0xffffffff;
2771 thp = hostutil_GetHostByName(ti->data);
2773 if (!strcmp(ti->data, "localhost")) {
2774 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2775 hostAddr = htonl(0x7f000001);
2777 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2781 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2785 hostAddr = 0; /* means don't set host */
2786 setp = 0; /* aren't setting host */
2789 /* now do operation */
2790 blob.in_size = sizeof(afs_int32);
2791 blob.out_size = sizeof(afs_int32);
2792 blob.in = (char *) &hostAddr;
2793 blob.out = (char *) &hostAddr;
2794 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2800 printf("%s: new monitor host set.\n", pn);
2802 /* now decode old address */
2803 if (hostAddr == 0xffffffff) {
2804 printf("Cache monitoring is currently disabled.\n");
2806 tp = hostutil_GetNameByINet(hostAddr);
2807 printf("Using host %s for monitor services.\n", tp);
2812 #endif /* AFS_NT40_ENV */
2815 SysNameCmd(struct cmd_syndesc *as, void *arock)
2818 struct ViceIoctl blob;
2819 struct cmd_item *ti;
2820 char *input = space;
2823 ti = as->parms[0].items;
2827 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2832 fprintf (stderr,"Permission denied: requires root access.\n");
2840 blob.out_size = MAXSIZE;
2841 blob.in_size = sizeof(afs_int32);
2842 memcpy(input, &setp, sizeof(afs_int32));
2843 input += sizeof(afs_int32);
2844 for (; ti; ti = ti->next) {
2846 blob.in_size += (long)strlen(ti->data) + 1;
2847 if (blob.in_size > MAXSIZE) {
2848 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2849 setp > 1 ? "s" : "");
2852 strcpy(input, ti->data);
2853 input += strlen(ti->data);
2856 memcpy(space, &setp, sizeof(afs_int32));
2857 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2863 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2868 memcpy(&setp, input, sizeof(afs_int32));
2869 input += sizeof(afs_int32);
2871 fprintf(stderr,"No sysname name value was found\n");
2875 printf("Current sysname%s is", setp > 1 ? " list" : "");
2876 for (; setp > 0; --setp ) {
2877 printf(" \'%s\'", input);
2878 input += strlen(input) + 1;
2884 #ifndef AFS_NT40_ENV
2885 static char *exported_types[] = {"null", "nfs", ""};
2886 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2889 struct ViceIoctl blob;
2890 struct cmd_item *ti;
2891 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
2892 int exportcall, pwsync = 0, smounts = 0;
2896 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2901 fprintf (stderr,"Permission denied: requires root access.\n");
2906 ti = as->parms[0].items;
2907 if (strcmp(ti->data, "nfs") == 0)
2908 type = 0x71; /* NFS */
2911 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2914 ti = as->parms[1].items;
2916 if (strcmp(ti->data, "on") == 0)
2918 else if (strcmp(ti->data, "off") == 0)
2921 fprintf(stderr, "Illegal argument %s\n", ti->data);
2926 if (ti = as->parms[2].items) { /* -noconvert */
2927 if (strcmp(ti->data, "on") == 0)
2929 else if (strcmp(ti->data, "off") == 0)
2932 fprintf(stderr, "Illegal argument %s\n", ti->data);
2936 if (ti = as->parms[3].items) { /* -uidcheck */
2937 if (strcmp(ti->data, "on") == 0)
2939 else if (strcmp(ti->data, "off") == 0)
2942 fprintf(stderr, "Illegal argument %s\n", ti->data);
2946 if (ti = as->parms[4].items) { /* -submounts */
2947 if (strcmp(ti->data, "on") == 0)
2949 else if (strcmp(ti->data, "off") == 0)
2952 fprintf(stderr, "Illegal argument %s\n", ti->data);
2956 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2959 blob.in = (char *) &exportcall;
2960 blob.in_size = sizeof(afs_int32);
2961 blob.out = (char *) &exportcall;
2962 blob.out_size = sizeof(afs_int32);
2963 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2965 if (errno == ENODEV) {
2967 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
2974 if (exportcall & 1) {
2975 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
2976 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
2977 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
2978 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
2980 printf("'%s' translator is disabled\n", exported_types[type]);
2989 GetCellCmd(struct cmd_syndesc *as, void *arock)
2992 struct ViceIoctl blob;
2993 struct afsconf_cell info;
2994 struct cmd_item *ti;
3001 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3002 for(ti=as->parms[0].items; ti; ti=ti->next) {
3004 blob.out_size = sizeof(args);
3005 blob.out = (caddr_t) &args;
3006 code = GetCellName(ti->data, &info);
3011 blob.in_size = 1+(long)strlen(info.name);
3012 blob.in = info.name;
3013 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
3015 if (errno == ENOENT)
3016 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3018 Die(errno, info.name);
3022 printf("Cell %s status: ", info.name);
3028 printf("no setuid allowed");
3030 printf("setuid allowed");
3032 printf(", using old VLDB");
3038 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3041 struct ViceIoctl blob;
3042 struct afsconf_cell info;
3043 struct cmd_item *ti;
3051 /* Check arguments. */
3052 if (as->parms[1].items && as->parms[2].items) {
3053 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3057 /* figure stuff to set */
3063 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3068 fprintf (stderr,"Permission denied: requires root access.\n");
3073 if (! as->parms[1].items)
3074 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3076 /* set stat for all listed cells */
3077 for(ti=as->parms[0].items; ti; ti=ti->next) {
3079 code = GetCellName(ti->data, &info);
3084 strcpy(args.cname, info.name);
3085 blob.in_size = sizeof(args);
3086 blob.in = (caddr_t) &args;
3088 blob.out = (caddr_t) 0;
3089 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
3091 Die(errno, info.name); /* XXX added cell name to Die() call */
3100 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3102 strcpy(infop->name, cellNamep);
3107 GetCellName(char *cellName, struct afsconf_cell *info)
3109 struct afsconf_dir *tdir;
3112 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_CLIENTNAME);
3115 "Could not process files in configuration directory (%s).\n",
3116 AFSDIR_CLIENT_ETC_CLIENTNAME);
3120 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
3122 fprintf(stderr,"fs: cell %s not in %s/CellServDB\n", cellName,
3123 AFSDIR_CLIENT_ETC_CLIENTNAME);
3129 #endif /* not WIN32 */
3132 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3136 code = ugen_ClientInit(noAuthFlag, (char *)AFSDIR_CLIENT_ETC_DIRPATH,
3137 info->name, 0, &uclient,
3138 NULL, pn, rxkad_clear,
3139 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3140 0, 0, USER_SERVICE_ID);
3145 static struct ViceIoctl gblob;
3146 static int debug = 0;
3148 * here follow some routines in suport of the setserverprefs and
3149 * getserverprefs commands. They are:
3150 * SetPrefCmd "top-level" routine
3151 * addServer adds a server to the list of servers to be poked into the
3152 * kernel. Will poke the list into the kernel if it threatens
3154 * pokeServers pokes the existing list of servers and ranks into the kernel
3155 * GetPrefCmd reads the Cache Manager's current list of server ranks
3164 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3166 ssp = (cm_SSetPref_t *)space;
3167 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3173 * returns -1 if error message printed,
3175 * errno value if error and no error message printed
3182 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3183 if (code && (errno == EINVAL)) {
3184 struct setspref *ssp;
3185 ssp = (struct setspref *)gblob.in;
3186 if (!(ssp->flags & DBservers)) {
3187 gblob.in = (void *)&(ssp->servers[0]);
3188 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3189 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
3190 return code ? errno : 0;
3193 "This cache manager does not support VL server preferences.\n");
3197 return code ? errno : 0;
3203 addServer(char *name, unsigned short rank)
3208 struct hostent *thostent;
3212 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3214 #define MAXUSHORT ((unsigned short) ~0)
3219 thostent = hostutil_GetHostByName(name);
3221 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3225 ssp = (cm_SSetPref_t *)(gblob.in);
3227 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3228 code = pokeServers();
3229 ssp->num_servers = 0;
3232 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3233 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3234 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3235 gblob.in_size += sizeof(cm_SPref_t);
3238 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3244 * returns -1 if error message printed,
3246 * errno value if error and no error message printed
3249 addServer(char *name, afs_int32 rank)
3252 struct setspref *ssp;
3254 struct hostent *thostent;
3260 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3262 #define MAXUSHORT ((unsigned short) ~0)
3266 thostent = hostutil_GetHostByName(name);
3268 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3272 ssp = (struct setspref *)(gblob.in);
3274 for (t = 0; thostent->h_addr_list[t]; t++) {
3275 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3276 code = pokeServers();
3279 ssp->num_servers = 0;
3282 sp = (struct spref *)(gblob.in + gblob.in_size);
3283 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3284 sizeof(afs_uint32));
3285 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3286 gblob.in_size += sizeof(struct spref);
3290 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3291 name, sp->rank, sp->server.s_addr);
3299 static BOOL IsWindowsNT (void)
3301 static BOOL fChecked = FALSE;
3302 static BOOL fIsWinNT = FALSE;
3306 OSVERSIONINFO Version;
3310 memset (&Version, 0x00, sizeof(Version));
3311 Version.dwOSVersionInfoSize = sizeof(Version);
3313 if (GetVersionEx (&Version))
3315 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3325 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3329 struct cmd_item *ti;
3334 ssp = (cm_SSetPref_t *)space;
3336 ssp->num_servers = 0;
3337 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3340 gblob.out_size = MAXSIZE;
3343 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3349 ti = as->parms[2].items; /* -file */
3351 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3352 if (!(infd = fopen(ti->data,"r" ))) {
3354 Die(errno,ti->data);
3357 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3358 code = addServer (name, (unsigned short) rank);
3362 ti = as->parms[3].items; /* -stdin */
3364 while ( scanf("%79s%ld", name, &rank) != EOF) {
3365 code = addServer (name, (unsigned short) rank);
3369 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3374 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3376 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3380 code = pokeServers();
3382 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3384 ssp = (cm_SSetPref_t *)space;
3385 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3387 ssp->flags = CM_SPREF_VLONLY;
3388 ssp->num_servers = 0;
3390 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3395 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3397 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3402 if (as->parms[1].items) {
3404 printf("now poking vlservers\n");
3405 code = pokeServers();
3415 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3419 struct cmd_item *ti;
3422 struct setspref *ssp;
3423 int error = 0; /* -1 means error message printed,
3424 * >0 means errno value for unprinted message */
3426 ssp = (struct setspref *)space;
3428 ssp->num_servers = 0;
3429 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3432 gblob.out_size = MAXSIZE;
3436 fprintf(stderr, "Permission denied: requires root access.\n");
3440 ti = as->parms[2].items; /* -file */
3443 fprintf(stderr, "opening file %s\n", ti->data);
3444 if (!(infd = fopen(ti->data, "r"))) {
3448 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3449 code = addServer(name, (unsigned short)rank);
3456 ti = as->parms[3].items; /* -stdin */
3458 while (scanf("%79s%ld", name, &rank) != EOF) {
3459 code = addServer(name, (unsigned short)rank);
3465 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3470 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3474 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3478 code = pokeServers();
3482 printf("now working on vlservers, code=%d\n", code);
3484 ssp = (struct setspref *)space;
3485 ssp->flags = DBservers;
3486 ssp->num_servers = 0;
3487 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3490 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3495 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3499 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3504 if (as->parms[1].items) {
3506 printf("now poking vlservers\n");
3507 code = pokeServers();
3515 return error ? 1 : 0;
3521 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3524 struct cmd_item *ti;
3525 char *name, tbuffer[20];
3530 struct ViceIoctl blob;
3531 struct cm_SPrefRequest *in;
3532 struct cm_SPrefInfo *out;
3536 ti = as->parms[0].items; /* -file */
3538 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3539 if (!(outfd = freopen(ti->data,"w",stdout))) {
3540 Die(errno,ti->data);
3545 ti = as->parms[1].items; /* -numeric */
3547 ti = as->parms[2].items; /* -vlservers */
3548 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3549 /* ti = as->parms[3].items; -cell */
3551 in = (struct cm_SPrefRequest *)space;
3555 blob.in_size=sizeof(struct cm_SPrefRequest);
3556 blob.in = (char *)in;
3558 blob.out_size = MAXSIZE;
3560 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3561 in->flags = vlservers;
3563 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3565 perror("getserverprefs pioctl");
3569 out = (struct cm_SPrefInfo *) blob.out;
3571 for (i=0;i<out->num_servers;i++) {
3573 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3576 addr = ntohl(out->servers[i].host.s_addr);
3577 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3578 (addr>>8) & 0xff, addr & 0xff);
3581 printf ("%-50s %5u\n",name,out->servers[i].rank);
3584 in->offset = out->next_offset;
3586 } while (!code && out->next_offset > 0);
3592 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3595 struct cmd_item *ti;
3596 char *name, tbuffer[20];
3597 afs_int32 rank, addr;
3601 struct ViceIoctl blob;
3602 struct sprefrequest *in;
3603 struct sprefinfo *out;
3606 ti = as->parms[0].items; /* -file */
3609 fprintf(stderr, "opening file %s\n", ti->data);
3610 if (!(outfd = freopen(ti->data, "w", stdout))) {
3616 ti = as->parms[1].items; /* -numeric */
3618 ti = as->parms[2].items; /* -vlservers */
3619 vlservers |= (ti ? DBservers : 0);
3620 /* ti = as->parms[3].items; -cell */
3622 in = (struct sprefrequest *)space;
3626 blob.in_size = sizeof(struct sprefrequest);
3627 blob.in = (char *)in;
3629 blob.out_size = MAXSIZE;
3632 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3633 in->flags = vlservers;
3635 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3637 perror("getserverprefs pioctl");
3641 out = (struct sprefinfo *)blob.out;
3643 for (i = 0; i < out->num_servers; i++) {
3645 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3647 addr = ntohl(out->servers[i].server.s_addr);
3648 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3649 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3652 printf("%-50s %5u\n", name, out->servers[i].rank);
3655 in->offset = out->next_offset;
3656 } while (out->next_offset > 0);
3663 UuidCmd(struct cmd_syndesc *asp, void *arock)
3668 struct ViceIoctl blob;
3669 char * uuidstring = NULL;
3671 if (asp->parms[0].items) {
3674 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3679 fprintf (stderr, "Permission denied: requires root access.\n");
3683 inValue = 1; /* generate new UUID */
3685 inValue = 0; /* just show the current UUID */
3688 blob.in_size = sizeof(inValue);
3689 blob.in = (char *) &inValue;
3690 blob.out_size = sizeof(outValue);
3691 blob.out = (char *) &outValue;
3693 code = pioctl(NULL, VIOC_UUIDCTL, &blob, 1);
3699 UuidToString((UUID *) &outValue, &uuidstring);
3701 printf("%sUUID: %s",
3702 ((inValue == 1)?"New ":""),
3706 RpcStringFree(&uuidstring);
3712 TraceCmd(struct cmd_syndesc *asp, void *arock)
3715 struct ViceIoctl blob;
3721 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3726 fprintf (stderr,"Permission denied: requires root access.\n");
3731 if ((asp->parms[0].items && asp->parms[1].items)) {
3732 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
3736 /* determine if we're turning this tracing on or off */
3738 if (asp->parms[0].items)
3739 inValue = 3; /* enable */
3740 else if (asp->parms[1].items)
3741 inValue = 2; /* disable */
3742 if (asp->parms[2].items)
3743 inValue |= 4; /* do reset */
3744 if (asp->parms[3].items)
3745 inValue |= 8; /* dump */
3747 blob.in_size = sizeof(long);
3748 blob.in = (char *) &inValue;
3749 blob.out_size = sizeof(long);
3750 blob.out = (char *) &outValue;
3752 code = pioctl(NULL, VIOC_TRACECTL, &blob, 1);
3759 printf("AFS tracing enabled.\n");
3761 printf("AFS tracing disabled.\n");
3766 static void sbusage(void)
3768 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
3769 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
3772 /* fs sb -kbytes 9999 -files *.o -default 64 */
3774 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3777 struct ViceIoctl blob;
3778 struct cmd_item *ti;
3779 struct sbstruct tsb, tsb2;
3787 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3792 tsb.sb_thisfile = -1;
3793 ti = as->parms[0].items; /* -kbytes */
3795 if (!as->parms[1].items) {
3796 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3800 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3801 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3802 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3808 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3809 ti = as->parms[2].items; /* -allfiles */
3811 allfiles = strtol(ti->data, &t, 10) * 1024;
3812 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3813 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3819 /* -verbose or -file only or no options */
3820 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3821 || (!as->parms[0].items && !as->parms[1].items
3822 && !as->parms[2].items))
3825 blob.in = (char *)&tsb;
3826 blob.out = (char *)&tsb2;
3827 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3828 memset(&tsb2, 0, sizeof(tsb2));
3830 /* once per -file */
3831 for (ti = as->parms[1].items; ti; ti = ti->next) {
3832 /* Do this solely to see if the file is there */
3833 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3835 Die(errno, ti->data);
3840 code = pioctl(ti->data, VIOC_STOREBEHIND, &blob, 1);
3842 Die(errno, ti->data);
3847 if (verbose && (blob.out_size == sizeof(tsb2))) {
3848 if (tsb2.sb_thisfile == -1) {
3849 fprintf(stdout, "Will store %s according to default.\n",
3853 "Will store up to %d kbytes of %s asynchronously.\n",
3854 (tsb2.sb_thisfile / 1024), ti->data);
3859 /* If no files - make at least one pioctl call, or
3860 * set the allfiles default if we need to.
3862 if (!as->parms[1].items || (allfiles != -1)) {
3863 tsb.sb_default = allfiles;
3864 code = pioctl(0, VIOC_STOREBEHIND, &blob, 1);
3866 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3871 /* Having no arguments also reports the default store asynchrony */
3872 if (verbose && (blob.out_size == sizeof(tsb2))) {
3873 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3874 (tsb2.sb_default / 1024));
3881 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3883 afs_int32 code = 0, flag;
3884 struct ViceIoctl blob;
3889 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3894 tp = as->parms[0].items->data;
3895 if (strcmp(tp, "on") == 0)
3897 else if (strcmp(tp, "off") == 0)
3900 fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3904 blob.in = (char *) &flag;
3905 blob.in_size = sizeof(flag);
3907 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3914 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3916 afs_int32 code = 0, flag;
3917 struct ViceIoctl blob;
3922 blob.out_size = sizeof(flag);
3925 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3931 memcpy(&flag, tp, sizeof(afs_int32));
3932 printf("Security level is currently ");
3934 printf("crypt (data security).\n");
3942 MemDumpCmd(struct cmd_syndesc *asp, void *arock)
3945 struct ViceIoctl blob;
3950 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3954 if ((asp->parms[0].items && asp->parms[1].items)) {
3955 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
3959 /* determine if we're turning this tracing on or off */
3960 if (asp->parms[0].items)
3961 inValue = 1; /* begin */
3962 else if (asp->parms[1].items)
3963 inValue = 0; /* end */
3966 blob.in_size = sizeof(long);
3967 blob.in = (char *) &inValue;
3968 blob.out_size = sizeof(long);
3969 blob.out = (char *) &outValue;
3971 code = pioctl(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
3978 printf("AFS memdump created.\n");
3981 printf("AFS memdump failed.\n");
3987 MiniDumpCmd(struct cmd_syndesc *asp, void *arock)
3990 SERVICE_STATUS status;
3991 SC_HANDLE hManager = NULL;
3992 SC_HANDLE hService = NULL;
3995 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3999 hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
4003 hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
4007 success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
4010 CloseServiceHandle(hService);
4011 CloseServiceHandle(hManager);
4013 printf("AFS minidump generated.\n");
4019 CloseServiceHandle(hService);
4021 CloseServiceHandle(hManager);
4023 printf("AFS minidump failed.\n");
4028 CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
4030 struct cmd_item *ti;
4035 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4039 for(ti=asp->parms[0].items; ti;ti=ti->next) {
4051 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4052 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4055 REG_OPTION_NON_VOLATILE,
4061 if ( hkCSCPolicy == NULL ) {
4062 fprintf (stderr,"Permission denied: requires Administrator access.\n");
4067 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4068 RegCloseKey(hkCSCPolicy);
4074 if (asp->parms[1].items)
4076 if (asp->parms[2].items)
4077 policy = "programs";
4078 if (asp->parms[3].items)
4079 policy = "documents";
4080 if (asp->parms[4].items)
4083 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, (DWORD)strlen(policy)+1);
4085 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
4086 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
4090 DWORD dwIndex, dwPolicies;
4091 char policyName[256];
4092 DWORD policyNameLen;
4097 /* list current csc policies */
4099 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4100 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4103 REG_OPTION_NON_VOLATILE,
4104 KEY_READ|KEY_QUERY_VALUE,
4109 RegQueryInfoKey( hkCSCPolicy,
4111 NULL, /* lpcClass */
4112 NULL, /* lpReserved */
4113 NULL, /* lpcSubKeys */
4114 NULL, /* lpcMaxSubKeyLen */
4115 NULL, /* lpcMaxClassLen */
4116 &dwPolicies, /* lpcValues */
4117 NULL, /* lpcMaxValueNameLen */
4118 NULL, /* lpcMaxValueLen */
4119 NULL, /* lpcbSecurityDescriptor */
4120 NULL /* lpftLastWriteTime */
4123 printf("Current CSC policies:\n");
4124 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
4126 policyNameLen = sizeof(policyName);
4127 policyLen = sizeof(policy);
4128 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
4129 &dwType, policy, &policyLen);
4131 printf(" %s = %s\n", policyName, policy);
4135 RegCloseKey(hkCSCPolicy);
4140 /* get clients interface addresses */
4142 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4145 struct cmd_item *ti;
4147 struct ViceIoctl blob;
4148 struct sprefrequest *in;
4149 struct sprefinfo *out;
4151 in = (struct sprefrequest *)space;
4155 blob.in_size = sizeof(struct sprefrequest);
4156 blob.in = (char *)in;
4158 blob.out_size = MAXSIZE;
4161 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4162 /* returns addr in network byte order */
4163 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
4165 perror("getClientInterfaceAddr pioctl");
4171 out = (struct sprefinfo *)blob.out;
4172 for (i = 0; i < out->num_servers; i++) {
4175 addr = ntohl(out->servers[i].server.s_addr);
4176 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
4177 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
4178 printf("%-50s\n", tbuffer);
4180 in->offset = out->next_offset;
4182 } while (out->next_offset > 0);
4188 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4190 afs_int32 code, addr;
4191 struct cmd_item *ti;
4193 struct ViceIoctl blob;
4194 struct setspref *ssp;
4195 int sizeUsed = 0, i, flag;
4196 afs_int32 existingAddr[1024]; /* existing addresses on this host */
4200 ssp = (struct setspref *)space;
4201 ssp->num_servers = 0;
4204 blob.out_size = MAXSIZE;
4207 fprintf(stderr, "Permission denied: requires root access.\n");
4211 /* extract all existing interface addresses */
4212 existNu = rx_getAllAddr(existingAddr, 1024);
4216 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4217 for (ti = as->parms[0].items; ti; ti = ti->next) {
4218 if (sizeUsed >= sizeof(space)) {
4219 fprintf(stderr, "No more space\n");
4222 addr = extractAddr(ti->data, 20); /* network order */
4223 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4224 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4229 /* see if it is an address that really exists */
4230 for (flag = 0, i = 0; i < existNu; i++)
4231 if (existingAddr[i] == addr) {
4235 if (!flag) { /* this is an nonexistent address */
4236 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4240 /* copy all specified addr into ioctl buffer */
4241 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4242 printf("Adding 0x%08x\n", addr);
4244 sizeUsed += sizeof(struct spref);
4246 if (ssp->num_servers < 1) {
4247 fprintf(stderr, "No addresses specified\n");
4250 blob.in_size = sizeUsed - sizeof(struct spref);
4252 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4262 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4265 struct ViceIoctl blob;
4266 struct cmd_item *ti;
4267 char orig_name[1024]; /*Original name, may be modified */
4268 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4269 char parent_dir[1024]; /*Parent directory of true name */
4270 char *last_component; /*Last component of true name */
4271 struct stat statbuff; /*Buffer for status info */
4272 int link_chars_read; /*Num chars read in readlink() */
4273 int thru_symlink; /*Did we get to a mount point via a symlink? */
4276 for (ti = as->parms[0].items; ti; ti = ti->next) {
4279 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4282 if (lstat(orig_name, &statbuff) < 0) {
4283 /* if lstat fails, we should still try the pioctl, since it
4284 * may work (for example, lstat will fail, but pioctl will
4285 * work if the volume of offline (returning ENODEV). */
4286 statbuff.st_mode = S_IFDIR; /* lie like pros */
4290 * The lstat succeeded. If the given file is a symlink, substitute
4291 * the file name with the link name.
4293 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4296 * Read name of resolved file.
4298 link_chars_read = readlink(orig_name, true_name, 1024);
4299 if (link_chars_read <= 0) {
4301 "%s: Can't read target name for '%s' symbolic link!\n",
4308 * Add a trailing null to what was read, bump the length.
4310 true_name[link_chars_read++] = 0;
4313 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4314 * have to create a full pathname using the original name and the
4315 * relative symlink name. Find the rightmost slash in the original
4316 * name (we know there is one) and splice in the symlink value.
4318 if (true_name[0] != '/') {
4319 last_component = (char *)strrchr(orig_name, '/');
4320 strcpy(++last_component, true_name);
4321 strcpy(true_name, orig_name);
4324 strcpy(true_name, orig_name);
4327 * Find rightmost slash, if any.
4329 last_component = (char *)strrchr(true_name, '/');
4330 if (last_component) {
4332 * Found it. Designate everything before it as the parent directory,
4333 * everything after it as the final component.
4335 strncpy(parent_dir, true_name, last_component - true_name);
4336 parent_dir[last_component - true_name] = 0;
4337 last_component++; /*Skip the slash */
4340 * No slash appears in the given file name. Set parent_dir to the current
4341 * directory, and the last component as the given name.
4343 strcpy(parent_dir, ".");
4344 last_component = true_name;
4347 if (strcmp(last_component, ".") == 0
4348 || strcmp(last_component, "..") == 0) {
4350 "%s: you may not use '.' or '..' as the last component\n",
4352 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4358 blob.in = last_component;
4359 blob.in_size = strlen(last_component) + 1;
4361 memset(space, 0, MAXSIZE);
4363 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4366 if (errno == EINVAL) {
4367 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4369 Die(errno, (ti->data ? ti->data : parent_dir));
4379 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4382 afs_int32 flags = 0;
4383 struct ViceIoctl blob;
4385 if (as->parms[0].items) { /* -enable */
4386 flags |= AFSCALL_RXSTATS_ENABLE;
4388 if (as->parms[1].items) { /* -disable */
4389 flags |= AFSCALL_RXSTATS_DISABLE;
4391 if (as->parms[2].items) { /* -clear */
4392 flags |= AFSCALL_RXSTATS_CLEAR;
4395 fprintf(stderr, "You must specify at least one argument\n");
4399 blob.in = (char *)&flags;
4400 blob.in_size = sizeof(afs_int32);
4403 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4413 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4416 afs_int32 flags = 0;
4417 struct ViceIoctl blob;
4419 if (as->parms[0].items) { /* -enable */
4420 flags |= AFSCALL_RXSTATS_ENABLE;
4422 if (as->parms[1].items) { /* -disable */
4423 flags |= AFSCALL_RXSTATS_DISABLE;
4425 if (as->parms[2].items) { /* -clear */
4426 flags |= AFSCALL_RXSTATS_CLEAR;
4429 fprintf(stderr, "You must specify at least one argument\n");
4433 blob.in = (char *)&flags;
4434 blob.in_size = sizeof(afs_int32);
4437 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4447 TestVolStatCmd(struct cmd_syndesc *as, void *arock)
4450 struct VolStatTest test;
4451 struct ViceIoctl blob;
4455 memset(&test, 0, sizeof(test));
4457 if (as->parms[0].items) { /* -network */
4458 tp = as->parms[0].items->data;
4459 if (strcmp(tp, "up") == 0)
4460 test.flags |= VOLSTAT_TEST_NETWORK_UP;
4461 else if (strcmp(tp, "down") == 0)
4462 test.flags |= VOLSTAT_TEST_NETWORK_DOWN;
4464 fprintf (stderr, "%s: %s must be \"up\" or \"down\".\n", pn, tp);
4468 if (as->parms[1].items) { /* check */
4469 test.flags |= VOLSTAT_TEST_CHECK_VOLUME;
4471 if (as->parms[2].items) { /* cell */
4472 tp = as->parms[2].items->data;
4477 strncpy(test.cellname, tp, sizeof(test.cellname));
4478 test.cellname[sizeof(test.cellname)-1] = '\0';
4481 if (as->parms[3].items) { /* volume */
4482 tp = as->parms[3].items->data;
4485 test.fid.volume = n;
4487 strncpy(test.volname, tp, sizeof(test.volname));
4488 test.volname[sizeof(test.volname)-1] = '\0';
4491 if (as->parms[4].items) { /* state */
4492 tp = as->parms[4].items->data;
4493 if (strcmp(tp, "online") == 0)
4494 test.state = vl_online;
4495 else if (strcmp(tp, "busy") == 0)
4496 test.state = vl_busy;
4497 else if (strcmp(tp, "offline") == 0)
4498 test.state = vl_offline;
4499 else if (strcmp(tp, "down") == 0)
4500 test.state = vl_alldown;
4502 fprintf (stderr, "%s: %s must be \"online\", \"busy\", \"offline\" or \"down\".\n", pn, tp);
4507 if ((test.fid.cell || test.cellname[0]) && !(test.fid.volume || test.volname[0]) ||
4508 !(test.fid.cell || test.cellname[0]) && (test.fid.volume || test.volname[0])) {
4509 fprintf (stderr, "%s: both a cell and a volume must be specified.\n", pn, tp);
4513 blob.in = (char *)&test;
4514 blob.in_size = sizeof(test);
4517 code = pioctl(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
4527 #include "AFS_component_version_number.c"
4530 main(int argc, char **argv)
4533 struct cmd_syndesc *ts;
4535 #ifdef AFS_AIX32_ENV
4537 * The following signal action for AIX is necessary so that in case of a
4538 * crash (i.e. core is generated) we can include the user's data section
4539 * in the core dump. Unfortunately, by default, only a partial core is
4540 * generated which, in many cases, isn't too useful.
4542 struct sigaction nsa;
4544 sigemptyset(&nsa.sa_mask);
4545 nsa.sa_handler = SIG_DFL;
4546 nsa.sa_flags = SA_FULLDUMP;
4547 sigaction(SIGSEGV, &nsa, NULL);
4552 WSAStartup(0x0101, &WSAjunk);
4555 /* try to find volume location information */
4559 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
4560 "get client network interface addresses");
4561 cmd_CreateAlias(ts, "gc");
4563 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
4564 "set client network interface addresses");
4565 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
4566 "client network interfaces");
4567 cmd_CreateAlias(ts, "sc");
4570 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL, "set server ranks");
4571 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
4572 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
4573 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
4574 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
4575 cmd_CreateAlias(ts, "sp");
4577 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL, "get server ranks");
4578 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
4579 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4580 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
4581 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
4582 cmd_CreateAlias(ts, "gp");
4584 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
4585 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4586 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
4587 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
4588 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
4589 parm_setacl_id = ts->nParms;
4590 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
4591 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
4592 cmd_CreateAlias(ts, "sa");
4594 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL, "list access control list");
4595 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4596 parm_listacl_id = ts->nParms;
4597 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4598 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4599 cmd_CreateAlias(ts, "la");
4601 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL, "clean up access control list");
4602 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4604 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL, "copy access control list");
4605 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
4606 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
4607 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
4608 parm_copyacl_id = ts->nParms;
4609 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4610 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4612 cmd_CreateAlias(ts, "ca");
4614 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
4615 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4616 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4619 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
4620 "flush mount symlink from cache");
4621 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4624 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
4625 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4626 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
4628 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
4630 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
4631 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
4632 cmd_CreateAlias(ts, "sv");
4634 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL, "control Cache Manager messages");
4635 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
4637 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
4638 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4639 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4640 cmd_CreateAlias(ts, "lv");
4641 cmd_CreateAlias(ts, "listvol");
4643 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
4644 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4645 cmd_CreateAlias(ts, "lq");
4647 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL, "show server disk space usage");
4648 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4649 cmd_CreateAlias(ts, "df");
4651 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
4652 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4654 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
4655 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4657 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
4658 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
4659 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
4660 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
4661 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
4662 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
4668 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
4672 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
4673 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4675 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL, "check local cell's servers");
4676 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
4677 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
4678 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
4679 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
4681 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL, "check volumeID/name mappings");
4682 cmd_CreateAlias(ts, "checkbackups");
4685 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL, "set cache size");
4686 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
4687 cmd_CreateAlias(ts, "cachesize");
4689 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
4691 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL, "get cache usage info");
4693 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL, "list configured cells");
4694 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4696 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
4697 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
4698 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
4700 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
4702 cmd_CreateAlias(ts, "sq");
4704 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
4706 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
4707 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
4708 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
4710 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
4712 * Turn this on only if you wish to be able to talk to a server which is listening
4713 * on alternative ports. This is not intended for general use and may not be
4714 * supported in the cache manager. It is not a way to run two servers at the
4715 * same host, since the cache manager cannot properly distinguish those two hosts.
4717 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
4718 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
4721 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
4722 "configure new cell alias");
4723 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
4724 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
4727 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
4728 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4729 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4731 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
4732 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4733 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4735 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
4738 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
4741 #ifndef AFS_NT40_ENV
4742 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, "set cache monitor host address");
4743 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
4744 cmd_CreateAlias(ts, "mariner");
4747 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
4748 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4750 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
4751 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4752 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
4753 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
4755 ts = cmd_CreateSyntax("flushall", FlushAllCmd, NULL, "flush all data");
4757 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL, "flush all data in volume");
4758 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4760 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL, "get/set sysname (i.e. @sys) value");
4761 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
4763 #ifndef AFS_NT40_ENV
4764 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL, "enable/disable translators to AFS");
4765 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
4766 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
4767 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
4768 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
4769 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
4772 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
4773 "store to server after file close");
4774 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
4775 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
4776 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
4777 cmd_CreateAlias(ts, "sb");
4779 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL, "set cache manager encryption flag");
4780 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
4782 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL, "get cache manager encryption flag");
4784 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
4785 "Manage per process RX statistics");
4786 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4787 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4788 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4790 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
4791 "Manage per peer RX statistics");
4792 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4793 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4794 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4797 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
4798 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
4801 ts = cmd_CreateSyntax("trace", TraceCmd, NULL, "enable or disable CM tracing");
4802 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
4803 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
4804 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
4805 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
4806 cmd_CreateAlias(ts, "tr");
4808 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
4809 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
4811 ts = cmd_CreateSyntax("memdump", MemDumpCmd, NULL, "dump memory allocs in debug builds");
4812 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
4813 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
4815 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, NULL, "change client side caching policy for AFS shares");
4816 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
4817 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
4818 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
4819 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
4820 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
4822 ts = cmd_CreateSyntax("minidump", MiniDumpCmd, NULL, "Generate MiniDump of current service state");
4824 ts = cmd_CreateSyntax("test_volstat", TestVolStatCmd, NULL, (char *)CMD_HIDDEN);
4825 cmd_AddParm(ts, "-network", CMD_SINGLE, CMD_OPTIONAL, "set network state up or down");
4826 cmd_AddParm(ts, "-check", CMD_FLAG, CMD_OPTIONAL, "check state of offline volumes");
4827 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name or number");
4828 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or number");
4829 cmd_AddParm(ts, "-state", CMD_SINGLE, CMD_OPTIONAL, "new volume state: online, busy, offline, down");
4831 code = cmd_Dispatch(argc, argv);
4840 Die(int code, char *filename)
4843 if (code == EINVAL) {
4845 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
4847 fprintf(stderr,"%s: Invalid argument.\n", pn);
4849 else if (code == ENOENT) {
4851 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
4853 fprintf(stderr,"%s: no such file returned\n", pn);
4855 else if (code == EROFS)
4856 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
4857 else if (code == EACCES || code == EPERM) {
4859 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
4861 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
4863 else if (code == ENODEV) {
4864 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
4866 else if (code == ESRCH) { /* hack */
4867 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
4869 else if (code == EPIPE) { /* hack */
4870 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
4872 else if (code == EFBIG) {
4873 fprintf(stderr,"%s: Cache size too large.\n", pn);
4875 else if (code == ETIMEDOUT) {
4877 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
4879 fprintf(stderr,"%s: Connection timed out", pn);
4881 else if (code == EBUSY) {
4883 fprintf(stderr,"%s: All servers are busy on which '%s' resides\n", pn, filename);
4885 fprintf(stderr,"%s: All servers are busy\n", pn);
4887 else if (code == ENXIO) {
4889 fprintf(stderr,"%s: All volume instances are offline on which '%s' resides\n", pn, filename);
4891 fprintf(stderr,"%s: All volume instances are offline\n", pn);
4893 else if (code == ENOSYS) {
4895 fprintf(stderr,"%s: All servers are down on which '%s' resides\n", pn, filename);
4897 fprintf(stderr,"%s: All servers are down\n", pn);
4901 fprintf(stderr,"%s:'%s'", pn, filename);
4903 fprintf(stderr,"%s", pn);
4905 fprintf(stderr, ": code 0x%x\n", code);
4906 #else /* not WIN32 */
4907 fprintf(stderr,": %s\n", afs_error_message(code));
4908 #endif /* not WIN32 */