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, (IsWow64()?KEY_WOW64_64KEY: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, (IsWow64()?KEY_WOW64_64KEY: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];
1117 for ( nm = aname; tc = *nm; nm++) {
1118 /* all must be '-' or digit to be bad */
1119 if (tc != '-' && (tc < '0' || tc > '9'))
1123 /* Go to the PRDB and see if this all number username is valid */
1124 code = GetCell(fname, cell);
1128 cm_GetConfigDir(confDir, sizeof(confDir));
1130 pr_Initialize(1, confDir, cell);
1131 code = pr_SNameToId(aname, &id);
1134 /* 1=>Not-valid; 0=>Valid */
1135 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1139 /* clean up an access control list of its bad entries; return 1 if we made
1140 any changes to the list, and 0 otherwise */
1142 CleanAcl(struct Acl *aa, char *fname)
1144 struct AclEntry *te, **le, *ne;
1147 /* Don't correct DFS ACL's for now */
1151 /* prune out bad entries */
1152 changes = 0; /* count deleted entries */
1154 for(te = aa->pluslist; te; te=ne) {
1156 if (BadName(te->name, fname)) {
1166 le = &aa->minuslist;
1167 for(te = aa->minuslist; te; te=ne) {
1169 if (BadName(te->name, fname)) {
1183 /* clean up an acl to not have bogus entries */
1185 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1189 struct ViceIoctl blob;
1191 struct cmd_item *ti;
1192 struct AclEntry *te;
1195 SetDotDefault(&as->parms[0].items);
1196 for(ti=as->parms[0].items; ti; ti=ti->next) {
1197 blob.out_size = MAXSIZE;
1200 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1202 Die(errno, ti->data);
1208 ta = ParseAcl(space);
1212 "%s: cleanacl is not supported for DFS access lists.\n",
1218 changes = CleanAcl(ta, ti->data);
1221 /* now set the acl */
1222 blob.in=AclToString(ta);
1223 blob.in_size = (long)strlen(blob.in)+1;
1225 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1227 if (errno == EINVAL) {
1229 "%s: Invalid argument, possible reasons include\n",
1231 fprintf(stderr,"%s: File not in vice or\n", pn);
1233 "%s: Too many users on access control list or\n",
1236 Die(errno, ti->data);
1242 /* now list the updated acl */
1243 printf("Access list for %s is now\n", ti->data);
1244 if (ta->nplus > 0) {
1246 printf("Normal rights:\n");
1247 for(te = ta->pluslist;te;te=te->next) {
1248 printf(" %s ", te->name);
1249 PRights(te->rights, ta->dfs);
1253 if (ta->nminus > 0) {
1254 printf("Negative rights:\n");
1255 for(te = ta->minuslist;te;te=te->next) {
1256 printf(" %s ", te->name);
1257 PRights(te->rights, ta->dfs);
1264 printf("Access list for %s is fine.\n", ti->data);
1272 ListACLCmd(struct cmd_syndesc *as, void *arock)
1276 struct ViceIoctl blob;
1277 struct AclEntry *te;
1278 struct cmd_item *ti;
1279 int idf = getidf(as, parm_listacl_id);
1282 SetDotDefault(&as->parms[0].items);
1283 for(ti=as->parms[0].items; ti; ti=ti->next) {
1285 blob.out_size = MAXSIZE;
1287 blob.in = blob.out = space;
1288 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1290 Die(errno, ti->data);
1294 ta = ParseAcl(space);
1297 printf("Access list for %s is\n", ti->data);
1300 printf("DFS access list for %s is\n", ti->data);
1303 printf("DFS initial directory access list of %s is\n", ti->data);
1306 printf("DFS initial file access list of %s is\n", ti->data);
1310 printf(" Default cell = %s\n", ta->cell);
1312 separator = ta->dfs? DFS_SEPARATOR : ' ';
1313 if (ta->nplus > 0) {
1315 printf("Normal rights:\n");
1316 for(te = ta->pluslist;te;te=te->next) {
1317 printf(" %s%c", te->name, separator);
1318 PRights(te->rights, ta->dfs);
1322 if (ta->nminus > 0) {
1323 printf("Negative rights:\n");
1324 for(te = ta->minuslist;te;te=te->next) {
1325 printf(" %s ", te->name);
1326 PRights(te->rights, ta->dfs);
1338 FlushAllCmd(struct cmd_syndesc *as, void *arock)
1341 struct ViceIoctl blob;
1343 blob.in_size = blob.out_size = 0;
1344 code = pioctl(NULL, VIOC_FLUSHALL, &blob, 0);
1346 fprintf(stderr, "Error flushing all ");
1353 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1356 struct ViceIoctl blob;
1357 struct cmd_item *ti;
1360 SetDotDefault(&as->parms[0].items);
1361 for(ti=as->parms[0].items; ti; ti=ti->next) {
1362 blob.in_size = blob.out_size = 0;
1363 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1365 fprintf(stderr, "Error flushing volume ");
1375 FlushCmd(struct cmd_syndesc *as, void *arock)
1378 struct ViceIoctl blob;
1379 struct cmd_item *ti;
1382 cm_ioctlQueryOptions_t options;
1384 if (as->parms[1].items)
1387 for(ti=as->parms[0].items; ti; ti=ti->next) {
1389 memset(&options, 0, sizeof(options));
1390 options.size = sizeof(options);
1391 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1392 options.literal = literal;
1393 blob.in_size = options.size; /* no variable length data */
1397 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1399 if (errno == EMFILE) {
1400 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1403 fprintf(stderr, "%s: Error flushing file ", pn);
1413 /* all this command does is repackage its args and call SetVolCmd */
1415 SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
1416 struct cmd_syndesc ts;
1418 /* copy useful stuff from our command slot; we may later have to reorder */
1419 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1420 return SetVolCmd(&ts, arock);
1424 SetVolCmd(struct cmd_syndesc *as, void *arock) {
1426 struct ViceIoctl blob;
1427 struct cmd_item *ti;
1428 struct VolumeStatus *status;
1429 char *motd, *offmsg, *input;
1432 SetDotDefault(&as->parms[0].items);
1433 for(ti=as->parms[0].items; ti; ti=ti->next) {
1435 blob.out_size = MAXSIZE;
1436 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1439 status = (VolumeStatus *)space;
1440 status->MinQuota = status->MaxQuota = -1;
1441 motd = offmsg = NULL;
1442 if (as->parms[1].items) {
1443 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1445 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1450 if (as->parms[2].items)
1451 motd = as->parms[2].items->data;
1452 if (as->parms[3].items)
1453 offmsg = as->parms[3].items->data;
1454 input = (char *)status + sizeof(*status);
1455 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1457 if (strlen(offmsg) >= VMSGSIZE) {
1458 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1463 strcpy(input,offmsg);
1464 blob.in_size += (long)strlen(offmsg);
1465 input += strlen(offmsg) + 1;
1469 if (strlen(motd) >= VMSGSIZE) {
1470 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1475 blob.in_size += (long)strlen(motd);
1476 input += strlen(motd) + 1;
1479 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1481 Die(errno, ti->data);
1488 /* values match cache manager File Types */
1490 filetypestr(afs_uint32 type)
1492 char * s = "Object";
1515 ExamineCmd(struct cmd_syndesc *as, void *arock)
1518 struct ViceIoctl blob;
1519 struct cmd_item *ti;
1520 struct VolumeStatus *status;
1521 char *name, *offmsg, *motd;
1524 cm_ioctlQueryOptions_t options;
1526 if (as->parms[1].items)
1529 SetDotDefault(&as->parms[0].items);
1530 for(ti=as->parms[0].items; ti; ti=ti->next) {
1532 afs_uint32 filetype;
1533 afs_uint32 owner[2];
1534 char cell[MAXCELLCHARS];
1537 memset(&fid, 0, sizeof(fid));
1538 memset(&options, 0, sizeof(options));
1540 options.size = sizeof(options);
1541 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1542 options.literal = literal;
1543 blob.in_size = options.size; /* no variable length data */
1546 blob.out_size = sizeof(cm_fid_t);
1547 blob.out = (char *) &fid;
1548 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1549 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1552 Die(errno, ti->data);
1557 blob.out_size = sizeof(filetype);
1558 blob.out = &filetype;
1560 code = pioctl(ti->data, VIOC_GETFILETYPE, &blob, 1);
1562 blob.out_size = MAXCELLCHARS;
1565 code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1566 printf("%s %s (%u.%u.%u) contained in cell %s\n",
1567 filetypestr(filetype),
1568 ti->data, fid.volume, fid.vnode, fid.unique,
1569 code ? "unknown-cell" : cell);
1571 blob.out_size = 2 * sizeof(afs_uint32);
1572 blob.out = (char *) &owner;
1573 if (0 == pioctl(ti->data, VIOCGETOWNER, &blob, 1)) {
1574 char oname[PR_MAXNAMELEN] = "(unknown)";
1577 /* Go to the PRDB and see if this all number username is valid */
1578 cm_GetConfigDir(confDir, sizeof(confDir));
1580 pr_Initialize(1, confDir, cell);
1581 pr_SIdToName(owner[0], oname);
1582 printf("Owner %s (%u) Group %u\n", oname, owner[0], owner[1]);
1586 blob.out_size = MAXSIZE;
1587 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1589 status = (VolumeStatus *)space;
1590 name = (char *)status + sizeof(*status);
1591 offmsg = name + strlen(name) + 1;
1592 motd = offmsg + strlen(offmsg) + 1;
1594 PrintStatus(status, name, motd, offmsg);
1596 Die(errno, ti->data);
1600 code = pioctl(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
1603 printf("Volume is online\n");
1606 printf("Volume is offline\n");
1609 printf("All Volume servers are down\n");
1612 printf("All volume servers are busy\n");
1615 printf("Unknown volume state\n");
1616 Die(errno, ti->data);
1624 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1627 struct ViceIoctl blob;
1628 struct cmd_item *ti;
1629 struct VolumeStatus *status;
1634 printf("%-25s%-10s%-10s%-7s%-13s\n",
1635 "Volume Name", " Quota", " Used", " %Used", " Partition");
1636 SetDotDefault(&as->parms[0].items);
1637 for(ti=as->parms[0].items; ti; ti=ti->next) {
1639 blob.out_size = MAXSIZE;
1642 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1644 Die(errno, ti->data);
1648 status = (VolumeStatus *)space;
1649 name = (char *)status + sizeof(*status);
1650 QuickPrintStatus(status, name);
1656 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1659 struct ViceIoctl blob;
1660 struct cmd_item *ti;
1666 cm_ioctlQueryOptions_t options;
1668 if (as->parms[1].items)
1671 SetDotDefault(&as->parms[0].items);
1672 for(ti=as->parms[0].items; ti; ti=ti->next) {
1674 afs_uint32 filetype;
1677 memset(&fid, 0, sizeof(fid));
1678 memset(&options, 0, sizeof(options));
1680 options.size = sizeof(options);
1681 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1682 options.literal = literal;
1683 blob.in_size = options.size; /* no variable length data */
1686 blob.out_size = sizeof(cm_fid_t);
1687 blob.out = (char *) &fid;
1688 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1689 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1692 Die(errno, ti->data);
1697 blob.out_size = sizeof(filetype);
1698 blob.out = &filetype;
1700 code = pioctl(ti->data, VIOC_GETFILETYPE, &blob, 1);
1702 blob.out_size = MAXSIZE;
1704 memset(space, 0, sizeof(space));
1705 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1707 Die(errno, ti->data);
1711 hosts = (afs_int32 *) space;
1712 printf("%s %s is on host%s ",
1713 filetypestr(filetype),
1715 (hosts[0] && !hosts[1]) ? "": "s");
1716 for(j=0; j<MAXHOSTS; j++) {
1719 tp = hostutil_GetNameByINet(hosts[j]);
1729 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1732 struct ViceIoctl blob;
1733 struct cmd_item *ti;
1735 struct VolumeStatus *status;
1738 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1739 " used", " avail", " %used");
1740 SetDotDefault(&as->parms[0].items);
1741 for(ti=as->parms[0].items; ti; ti=ti->next) {
1743 blob.out_size = MAXSIZE;
1746 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1748 Die(errno, ti->data);
1752 status = (VolumeStatus *)space;
1753 name = (char *)status + sizeof(*status);
1754 QuickPrintSpace(status, name);
1760 QuotaCmd(struct cmd_syndesc *as, void *arock)
1763 struct ViceIoctl blob;
1764 struct cmd_item *ti;
1766 struct VolumeStatus *status;
1769 SetDotDefault(&as->parms[0].items);
1770 for(ti=as->parms[0].items; ti; ti=ti->next) {
1772 blob.out_size = MAXSIZE;
1775 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1777 Die(errno, ti->data);
1781 status = (VolumeStatus *)space;
1782 if (status->MaxQuota)
1783 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1786 printf("%2.0f%% of quota used.\n", quotaPct);
1792 ListMountCmd(struct cmd_syndesc *as, void *arock)
1795 struct ViceIoctl blob;
1796 struct cmd_item *ti;
1797 char orig_name[1024]; /*Original name, may be modified*/
1798 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1799 char parent_dir[1024]; /*Parent directory of true name*/
1800 char *last_component; /*Last component of true name*/
1802 struct stat statbuff; /*Buffer for status info*/
1803 #endif /* not WIN32 */
1805 int link_chars_read; /*Num chars read in readlink()*/
1806 #endif /* not WIN32 */
1807 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1810 for(ti=as->parms[0].items; ti; ti=ti->next) {
1814 strcpy(orig_name, ti->data);
1815 #else /* not WIN32 */
1816 sprintf(orig_name, "%s%s",
1817 (ti->data[0] == '/') ? "" : "./",
1819 #endif /* not WIN32 */
1822 if (lstat(orig_name, &statbuff) < 0) {
1823 /* if lstat fails, we should still try the pioctl, since it
1824 * may work (for example, lstat will fail, but pioctl will
1825 * work if the volume of offline (returning ENODEV). */
1826 statbuff.st_mode = S_IFDIR; /* lie like pros */
1830 * The lstat succeeded. If the given file is a symlink, substitute
1831 * the file name with the link name.
1833 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1836 * Read name of resolved file.
1838 link_chars_read = readlink(orig_name, true_name, 1024);
1839 if (link_chars_read <= 0) {
1841 "%s: Can't read target name for '%s' symbolic link!\n",
1848 * Add a trailing null to what was read, bump the length.
1850 true_name[link_chars_read++] = 0;
1853 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1854 * have to create a full pathname using the original name and the
1855 * relative symlink name. Find the rightmost slash in the original
1856 * name (we know there is one) and splice in the symlink value.
1858 if (true_name[0] != '\\') {
1859 last_component = (char *) strrchr(orig_name, '\\');
1860 strcpy(++last_component, true_name);
1861 strcpy(true_name, orig_name);
1864 strcpy(true_name, orig_name);
1866 strcpy(true_name, orig_name);
1870 * Find rightmost slash, if any.
1873 last_component = (char *) strrchr(true_name, '\\');
1874 if (!last_component)
1876 last_component = (char *) strrchr(true_name, '/');
1877 if (last_component) {
1879 * Found it. Designate everything before it as the parent directory,
1880 * everything after it as the final component.
1882 strncpy(parent_dir, true_name, last_component - true_name + 1);
1883 parent_dir[last_component - true_name + 1] = 0;
1884 last_component++; /*Skip the slash*/
1886 if (!InAFS(parent_dir)) {
1887 const char * nbname = NetbiosName();
1888 int len = (int)strlen(nbname);
1890 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
1891 parent_dir[len+2] == '\\' &&
1892 parent_dir[len+3] == '\0' &&
1893 !strnicmp(nbname,&parent_dir[2],len))
1895 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
1901 * No slash appears in the given file name. Set parent_dir to the current
1902 * directory, and the last component as the given name.
1904 fs_ExtractDriveLetter(true_name, parent_dir);
1905 strcat(parent_dir, ".");
1906 last_component = true_name;
1907 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1910 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1911 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
1912 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
1917 blob.in = last_component;
1918 blob.in_size = (long)strlen(last_component)+1;
1919 blob.out_size = MAXSIZE;
1921 memset(space, 0, MAXSIZE);
1923 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1926 printf("'%s' is a %smount point for volume '%s'\n",
1928 (thru_symlink ? "symbolic link, leading to a " : ""),
1932 if (errno == EINVAL) {
1933 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
1935 Die(errno, (ti->data ? ti->data : parent_dir));
1944 MakeMountCmd(struct cmd_syndesc *as, void *arock)
1947 char *cellName, *volName, *tmpName;
1949 char localCellName[128];
1951 char path[1024] = "";
1952 struct afsconf_cell info;
1953 struct vldbentry vldbEntry;
1954 struct ViceIoctl blob;
1957 if (as->parms[2].items) /* cell name specified */
1958 cellName = as->parms[2].items->data;
1961 volName = as->parms[1].items->data;
1963 if (strlen(volName) >= 64) {
1964 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
1968 /* Check for a cellname in the volume specification, and complain
1969 * if it doesn't match what was specified with -cell */
1970 if (tmpName = strchr(volName, ':')) {
1973 if (strcasecmp(cellName,volName)) {
1974 fprintf(stderr,"fs: cellnames do not match.\n");
1979 volName = ++tmpName;
1982 parent = Parent(as->parms[0].items->data);
1983 if (!InAFS(parent)) {
1985 const char * nbname = NetbiosName();
1986 int len = (int)strlen(nbname);
1988 if (parent[0] == '\\' && parent[1] == '\\' &&
1989 parent[len+2] == '\\' &&
1990 parent[len+3] == '\0' &&
1991 !strnicmp(nbname,&parent[2],len))
1993 sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
1994 parent = Parent(path);
1995 if (!InAFS(parent)) {
1996 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2002 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2007 if ( strlen(path) == 0 )
2008 strcpy(path, as->parms[0].items->data);
2010 if ( IsFreelanceRoot(parent) ) {
2012 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2018 blob.out_size = sizeof(localCellName);
2019 blob.out = localCellName;
2020 code = pioctl(parent, VIOC_GET_WS_CELL, &blob, 1);
2022 cellName = localCellName;
2026 code = GetCell(parent,space);
2032 code = GetCellName(cellName?cellName:space, &info);
2036 if (!(as->parms[4].items)) {
2037 /* not fast, check which cell the mountpoint is being created in */
2039 /* not fast, check name with VLDB */
2041 code = VLDBInit(1, &info);
2043 /* make the check. Don't complain if there are problems with init */
2044 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2045 if (code == VL_NOENT) {
2046 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2047 pn, volName, cellName ? cellName : space);
2052 if (as->parms[3].items) /* if -rw specified */
2057 /* cellular mount point, prepend cell prefix */
2058 strcat(space, info.name);
2061 strcat(space, volName); /* append volume name */
2062 strcat(space, "."); /* stupid convention; these end with a period */
2064 /* create symlink with a special pioctl for Windows NT, since it doesn't
2065 * have a symlink system call.
2068 blob.in_size = 1 + (long)strlen(space);
2071 code = pioctl(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2072 #else /* not WIN32 */
2073 code = symlink(space, path);
2074 #endif /* not WIN32 */
2083 * Delete AFS mount points. Variables are used as follows:
2084 * tbuffer: Set to point to the null-terminated directory name of the mount point
2085 * (or ``.'' if none is provided)
2086 * tp: Set to point to the actual name of the mount point to nuke.
2089 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2091 struct ViceIoctl blob;
2092 struct cmd_item *ti;
2094 char lsbuffer[1024];
2098 for(ti=as->parms[0].items; ti; ti=ti->next) {
2100 tp = (char *) strrchr(ti->data, '\\');
2102 tp = (char *) strrchr(ti->data, '/');
2104 strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1)); /* the dir name */
2106 tp++; /* skip the slash */
2109 if (!InAFS(tbuffer)) {
2110 const char * nbname = NetbiosName();
2111 int len = (int)strlen(nbname);
2113 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2114 tbuffer[len+2] == '\\' &&
2115 tbuffer[len+3] == '\0' &&
2116 !strnicmp(nbname,&tbuffer[2],len))
2118 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
2123 fs_ExtractDriveLetter(ti->data, tbuffer);
2124 strcat(tbuffer, ".");
2126 fs_StripDriveLetter(tp, tp, 0);
2129 blob.in_size = (long)strlen(tp)+1;
2130 blob.out = lsbuffer;
2131 blob.out_size = sizeof(lsbuffer);
2132 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2134 if (errno == EINVAL) {
2135 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2137 Die(errno, ti->data);
2140 continue; /* don't bother trying */
2143 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2144 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2146 continue; /* skip */
2151 blob.in_size = (long)strlen(tp)+1;
2152 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2154 Die(errno, ti->data);
2165 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2168 struct ViceIoctl blob;
2172 struct afsconf_cell info;
2173 struct chservinfo checkserv;
2175 memset(&checkserv, 0, sizeof(struct chservinfo));
2176 blob.in_size=sizeof(struct chservinfo);
2177 blob.in=(caddr_t)&checkserv;
2179 blob.out_size = MAXSIZE;
2181 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2183 /* prepare flags for checkservers command */
2184 temp = 2; /* default to checking local cell only */
2185 if (as->parms[2].items)
2186 temp |= 1; /* set fast flag */
2187 if (as->parms[1].items)
2188 temp &= ~2; /* turn off local cell check */
2190 checkserv.magic = 0x12345678; /* XXX */
2191 checkserv.tflags=temp;
2193 /* now copy in optional cell name, if specified */
2194 if (as->parms[0].items) {
2195 code = GetCellName(as->parms[0].items->data, &info);
2199 strcpy(checkserv.tbuffer,info.name);
2200 checkserv.tsize=(int)strlen(info.name)+1;
2202 strcpy(checkserv.tbuffer,"\0");
2206 if(as->parms[3].items) {
2207 checkserv.tinterval=atol(as->parms[3].items->data);
2210 if(checkserv.tinterval<0) {
2211 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2212 checkserv.tinterval=-1;
2213 } else if(checkserv.tinterval> 600) {
2214 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2215 checkserv.tinterval=600; /* 10 min max interval */
2218 checkserv.tinterval = -1; /* don't change current interval */
2221 if ( checkserv.tinterval >= 0 ) {
2224 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2229 fprintf (stderr,"Permission denied: requires root access.\n");
2235 code = pioctl(0, VIOCCKSERV, &blob, 1);
2237 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2238 printf("Must be root to change -interval\n");
2244 memcpy(&temp, space, sizeof(afs_int32));
2245 if (checkserv.tinterval >= 0) {
2246 if (checkserv.tinterval > 0)
2247 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2248 checkserv.tinterval, temp);
2250 printf("The current down server probe interval is %d secs\n", temp);
2254 printf("All servers are running.\n");
2256 printf("These servers unavailable due to network or server problems: ");
2257 for(j=0; j < MAXHOSTS; j++) {
2258 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2261 tp = hostutil_GetNameByINet(temp);
2271 MessagesCmd(struct cmd_syndesc *as, void *arock)
2274 struct ViceIoctl blob;
2275 struct gaginfo gagflags;
2276 struct cmd_item *show;
2278 memset(&gagflags, 0, sizeof(struct gaginfo));
2279 blob.in_size = sizeof(struct gaginfo);
2280 blob.in = (caddr_t ) &gagflags;
2281 blob.out_size = MAXSIZE;
2283 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2285 if (show = as->parms[0].items) {
2286 if (!strcasecmp (show->data, "user"))
2287 gagflags.showflags |= GAGUSER;
2288 else if (!strcasecmp (show->data, "console"))
2289 gagflags.showflags |= GAGCONSOLE;
2290 else if (!strcasecmp (show->data, "all"))
2291 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2292 else if (!strcasecmp (show->data, "none"))
2296 "unrecognized flag %s: must be in {user,console,all,none}\n",
2305 code = pioctl(0, VIOC_GAG, &blob, 1);
2314 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2317 struct ViceIoctl blob;
2321 code = pioctl(0, VIOCCKBACK, &blob, 1);
2326 printf("All volumeID/name mappings checked.\n");
2332 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2335 struct ViceIoctl blob;
2340 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2345 fprintf (stderr,"Permission denied: requires root access.\n");
2350 if (!as->parms[0].items && !as->parms[1].items) {
2351 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2354 if (as->parms[0].items) {
2355 code = util_GetInt32(as->parms[0].items->data, &temp);
2357 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2362 blob.in = (char *) &temp;
2363 blob.in_size = sizeof(afs_int32);
2365 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2367 Die(errno, (char *) 0);
2371 printf("New cache size set.\n");
2376 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2379 struct ViceIoctl blob;
2380 cm_cacheParms_t parms;
2382 memset(&parms, 0, sizeof(parms));
2385 blob.out_size = sizeof(parms);
2386 blob.out = (char *) &parms;
2387 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2393 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2394 parms.parms[1], parms.parms[0]);
2395 if (parms.parms[1] > parms.parms[0])
2396 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2401 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2404 afs_int32 i, j, *lp, magic, size;
2406 afs_int32 addr, maxa = OMAXHOSTS;
2407 struct ViceIoctl blob;
2410 resolve = !(as->parms[0].items); /* -numeric */
2412 for(i=0;i<1000;i++) {
2414 memcpy(tp, &i, sizeof(afs_int32));
2415 tp = (char *)(space + sizeof(afs_int32));
2416 lp = (afs_int32 *)tp;
2418 size = sizeof(afs_int32) + sizeof(afs_int32);
2419 blob.out_size = MAXSIZE;
2420 blob.in_size = sizeof(afs_int32);
2423 code = pioctl(0, VIOCGETCELL, &blob, 1);
2426 break; /* done with the list */
2431 memcpy(&magic, tp, sizeof(afs_int32));
2432 if (magic == 0x12345678) {
2434 tp += sizeof(afs_int32);
2436 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2437 for(j=0; j < maxa; j++) {
2438 char *name, tbuffer[20];
2440 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2445 name = hostutil_GetNameByINet(addr);
2448 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2449 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2452 printf(" %s", name);
2461 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2464 char *tp, *aliasName, *realName;
2465 struct ViceIoctl blob;
2469 memcpy(tp, &i, sizeof(afs_int32));
2470 blob.out_size = MAXSIZE;
2471 blob.in_size = sizeof(afs_int32);
2474 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2477 break; /* done with the list */
2483 tp += strlen(aliasName) + 1;
2485 printf("Alias %s for cell %s\n", aliasName, realName);
2491 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2494 struct ViceIoctl blob;
2495 struct cmd_item *ti;
2497 struct hostent *thp;
2501 ti = as->parms[0].items;
2504 thp = hostutil_GetHostByName(ti->data);
2506 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2509 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2511 hostAddr = 0; /* means don't set host */
2512 setp = 0; /* aren't setting host */
2515 /* now do operation */
2516 blob.in_size = sizeof(afs_int32);
2517 blob.out_size = sizeof(afs_int32);
2518 blob.in = (char *) &hostAddr;
2519 blob.out = (char *) &hostAddr;
2521 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2531 NewCellCmd(struct cmd_syndesc *as, void *arock)
2534 afs_int32 code, linkedstate=0, size=0, *lp;
2535 struct ViceIoctl blob;
2536 struct cmd_item *ti;
2537 char *tp, *cellname=0;
2538 struct hostent *thp;
2539 afs_int32 fsport = 0, vlport = 0;
2541 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
2543 lp = (afs_int32 *)tp;
2545 tp += sizeof(afs_int32);
2546 for(ti=as->parms[1].items; ti; ti=ti->next) {
2547 thp = hostutil_GetHostByName(ti->data);
2549 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2553 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2554 tp += sizeof(afs_int32);
2557 if (as->parms[2].items) {
2559 * Link the cell, for the purposes of volume location, to the specified
2562 cellname = as->parms[2].items->data;
2565 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2566 if (as->parms[3].items) {
2567 code = util_GetInt32(as->parms[3].items->data, &vlport);
2569 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2573 if (as->parms[4].items) {
2574 code = util_GetInt32(as->parms[4].items->data, &fsport);
2576 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2581 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
2582 lp = (afs_int32 *)tp;
2586 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2587 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2588 tp = (char *)(space + size);
2590 strcpy(tp, cellname);
2591 size += strlen(cellname) + 1;
2593 blob.in_size = size;
2596 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2602 struct ViceIoctl blob;
2605 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2610 blob.in = (char *) 0;
2611 blob.out_size = MAXSIZE;
2614 code = pioctl((char *) 0, VIOCNEWCELL, &blob, 1);
2617 Die(errno, (char *) 0);
2621 printf("Cell servers information refreshed\n");
2628 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2631 struct ViceIoctl blob;
2633 char *aliasName, *realName;
2635 /* Setup and do the NEWALIAS pioctl call */
2636 aliasName = as->parms[0].items->data;
2637 realName = as->parms[1].items->data;
2639 strcpy(tp, aliasName);
2640 tp += strlen(aliasName) + 1;
2641 strcpy(tp, realName);
2642 tp += strlen(realName) + 1;
2644 blob.in_size = tp - space;
2648 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2650 if (errno == EEXIST) {
2652 "%s: cell name `%s' in use by an existing cell.\n", pn,
2664 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2667 struct cmd_item *ti;
2668 struct ViceIoctl blob;
2671 cm_ioctlQueryOptions_t options;
2673 if (as->parms[1].items)
2676 SetDotDefault(&as->parms[0].items);
2677 for(ti=as->parms[0].items; ti; ti=ti->next) {
2679 afs_uint32 filetype;
2680 char cell[MAXCELLCHARS];
2683 memset(&fid, 0, sizeof(fid));
2684 memset(&options, 0, sizeof(options));
2686 options.size = sizeof(options);
2687 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
2688 options.literal = literal;
2689 blob.in_size = options.size; /* no variable length data */
2692 blob.out_size = sizeof(cm_fid_t);
2693 blob.out = (char *) &fid;
2694 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
2695 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
2698 Die(errno, ti->data);
2703 blob.out_size = sizeof(filetype);
2704 blob.out = &filetype;
2706 code = pioctl(ti->data, VIOC_GETFILETYPE, &blob, 1);
2708 blob.out_size = MAXCELLCHARS;
2711 code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
2713 if (errno == ENOENT)
2714 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2716 Die(errno, ti->data);
2720 printf("%s %s lives in cell '%s'\n",
2721 filetypestr(filetype),
2728 WSCellCmd(struct cmd_syndesc *as, void *arock)
2731 struct ViceIoctl blob;
2735 blob.out_size = MAXSIZE;
2738 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2745 printf("This workstation belongs to cell '%s'\n", space);
2751 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
2753 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2758 #ifndef AFS_NT40_ENV
2760 MonitorCmd(struct cmd_syndesc *as, void *arock)
2763 struct ViceIoctl blob;
2764 struct cmd_item *ti;
2766 struct hostent *thp;
2770 ti = as->parms[0].items;
2774 if (!strcmp(ti->data, "off")) {
2775 hostAddr = 0xffffffff;
2777 thp = hostutil_GetHostByName(ti->data);
2779 if (!strcmp(ti->data, "localhost")) {
2780 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2781 hostAddr = htonl(0x7f000001);
2783 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2787 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2791 hostAddr = 0; /* means don't set host */
2792 setp = 0; /* aren't setting host */
2795 /* now do operation */
2796 blob.in_size = sizeof(afs_int32);
2797 blob.out_size = sizeof(afs_int32);
2798 blob.in = (char *) &hostAddr;
2799 blob.out = (char *) &hostAddr;
2800 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2806 printf("%s: new monitor host set.\n", pn);
2808 /* now decode old address */
2809 if (hostAddr == 0xffffffff) {
2810 printf("Cache monitoring is currently disabled.\n");
2812 tp = hostutil_GetNameByINet(hostAddr);
2813 printf("Using host %s for monitor services.\n", tp);
2818 #endif /* AFS_NT40_ENV */
2821 SysNameCmd(struct cmd_syndesc *as, void *arock)
2824 struct ViceIoctl blob;
2825 struct cmd_item *ti;
2826 char *input = space;
2829 ti = as->parms[0].items;
2833 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2838 fprintf (stderr,"Permission denied: requires root access.\n");
2846 blob.out_size = MAXSIZE;
2847 blob.in_size = sizeof(afs_int32);
2848 memcpy(input, &setp, sizeof(afs_int32));
2849 input += sizeof(afs_int32);
2850 for (; ti; ti = ti->next) {
2852 blob.in_size += (long)strlen(ti->data) + 1;
2853 if (blob.in_size > MAXSIZE) {
2854 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2855 setp > 1 ? "s" : "");
2858 strcpy(input, ti->data);
2859 input += strlen(ti->data);
2862 memcpy(space, &setp, sizeof(afs_int32));
2863 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2869 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2874 memcpy(&setp, input, sizeof(afs_int32));
2875 input += sizeof(afs_int32);
2877 fprintf(stderr,"No sysname name value was found\n");
2881 printf("Current sysname%s is", setp > 1 ? " list" : "");
2882 for (; setp > 0; --setp ) {
2883 printf(" \'%s\'", input);
2884 input += strlen(input) + 1;
2890 #ifndef AFS_NT40_ENV
2891 static char *exported_types[] = {"null", "nfs", ""};
2892 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2895 struct ViceIoctl blob;
2896 struct cmd_item *ti;
2897 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
2898 int exportcall, pwsync = 0, smounts = 0;
2902 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2907 fprintf (stderr,"Permission denied: requires root access.\n");
2912 ti = as->parms[0].items;
2913 if (strcmp(ti->data, "nfs") == 0)
2914 type = 0x71; /* NFS */
2917 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2920 ti = as->parms[1].items;
2922 if (strcmp(ti->data, "on") == 0)
2924 else if (strcmp(ti->data, "off") == 0)
2927 fprintf(stderr, "Illegal argument %s\n", ti->data);
2932 if (ti = as->parms[2].items) { /* -noconvert */
2933 if (strcmp(ti->data, "on") == 0)
2935 else if (strcmp(ti->data, "off") == 0)
2938 fprintf(stderr, "Illegal argument %s\n", ti->data);
2942 if (ti = as->parms[3].items) { /* -uidcheck */
2943 if (strcmp(ti->data, "on") == 0)
2945 else if (strcmp(ti->data, "off") == 0)
2948 fprintf(stderr, "Illegal argument %s\n", ti->data);
2952 if (ti = as->parms[4].items) { /* -submounts */
2953 if (strcmp(ti->data, "on") == 0)
2955 else if (strcmp(ti->data, "off") == 0)
2958 fprintf(stderr, "Illegal argument %s\n", ti->data);
2962 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2965 blob.in = (char *) &exportcall;
2966 blob.in_size = sizeof(afs_int32);
2967 blob.out = (char *) &exportcall;
2968 blob.out_size = sizeof(afs_int32);
2969 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2971 if (errno == ENODEV) {
2973 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
2980 if (exportcall & 1) {
2981 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
2982 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
2983 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
2984 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
2986 printf("'%s' translator is disabled\n", exported_types[type]);
2995 GetCellCmd(struct cmd_syndesc *as, void *arock)
2998 struct ViceIoctl blob;
2999 struct afsconf_cell info;
3000 struct cmd_item *ti;
3007 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3008 for(ti=as->parms[0].items; ti; ti=ti->next) {
3010 blob.out_size = sizeof(args);
3011 blob.out = (caddr_t) &args;
3012 code = GetCellName(ti->data, &info);
3017 blob.in_size = 1+(long)strlen(info.name);
3018 blob.in = info.name;
3019 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
3021 if (errno == ENOENT)
3022 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3024 Die(errno, info.name);
3028 printf("Cell %s status: ", info.name);
3034 printf("no setuid allowed");
3036 printf("setuid allowed");
3038 printf(", using old VLDB");
3044 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3047 struct ViceIoctl blob;
3048 struct afsconf_cell info;
3049 struct cmd_item *ti;
3057 /* Check arguments. */
3058 if (as->parms[1].items && as->parms[2].items) {
3059 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3063 /* figure stuff to set */
3069 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3074 fprintf (stderr,"Permission denied: requires root access.\n");
3079 if (! as->parms[1].items)
3080 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3082 /* set stat for all listed cells */
3083 for(ti=as->parms[0].items; ti; ti=ti->next) {
3085 code = GetCellName(ti->data, &info);
3090 strcpy(args.cname, info.name);
3091 blob.in_size = sizeof(args);
3092 blob.in = (caddr_t) &args;
3094 blob.out = (caddr_t) 0;
3095 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
3097 Die(errno, info.name); /* XXX added cell name to Die() call */
3105 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3107 strcpy(infop->name, cellNamep);
3112 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3117 cm_GetConfigDir(confDir, sizeof(confDir));
3119 code = ugen_ClientInit(noAuthFlag, confDir,
3120 info->name, 0, &uclient,
3121 NULL, pn, rxkad_clear,
3122 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3123 0, 0, USER_SERVICE_ID);
3128 static struct ViceIoctl gblob;
3129 static int debug = 0;
3131 * here follow some routines in suport of the setserverprefs and
3132 * getserverprefs commands. They are:
3133 * SetPrefCmd "top-level" routine
3134 * addServer adds a server to the list of servers to be poked into the
3135 * kernel. Will poke the list into the kernel if it threatens
3137 * pokeServers pokes the existing list of servers and ranks into the kernel
3138 * GetPrefCmd reads the Cache Manager's current list of server ranks
3147 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3149 ssp = (cm_SSetPref_t *)space;
3150 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3156 * returns -1 if error message printed,
3158 * errno value if error and no error message printed
3165 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3166 if (code && (errno == EINVAL)) {
3167 struct setspref *ssp;
3168 ssp = (struct setspref *)gblob.in;
3169 if (!(ssp->flags & DBservers)) {
3170 gblob.in = (void *)&(ssp->servers[0]);
3171 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3172 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
3173 return code ? errno : 0;
3176 "This cache manager does not support VL server preferences.\n");
3180 return code ? errno : 0;
3186 addServer(char *name, unsigned short rank)
3191 struct hostent *thostent;
3195 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3197 #define MAXUSHORT ((unsigned short) ~0)
3202 thostent = hostutil_GetHostByName(name);
3204 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3208 ssp = (cm_SSetPref_t *)(gblob.in);
3210 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3211 code = pokeServers();
3212 ssp->num_servers = 0;
3215 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3216 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3217 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3218 gblob.in_size += sizeof(cm_SPref_t);
3221 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3227 * returns -1 if error message printed,
3229 * errno value if error and no error message printed
3232 addServer(char *name, afs_int32 rank)
3235 struct setspref *ssp;
3237 struct hostent *thostent;
3243 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3245 #define MAXUSHORT ((unsigned short) ~0)
3249 thostent = hostutil_GetHostByName(name);
3251 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3255 ssp = (struct setspref *)(gblob.in);
3257 for (t = 0; thostent->h_addr_list[t]; t++) {
3258 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3259 code = pokeServers();
3262 ssp->num_servers = 0;
3265 sp = (struct spref *)(gblob.in + gblob.in_size);
3266 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3267 sizeof(afs_uint32));
3268 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3269 gblob.in_size += sizeof(struct spref);
3273 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3274 name, sp->rank, sp->server.s_addr);
3282 static BOOL IsWindowsNT (void)
3284 static BOOL fChecked = FALSE;
3285 static BOOL fIsWinNT = FALSE;
3289 OSVERSIONINFO Version;
3293 memset (&Version, 0x00, sizeof(Version));
3294 Version.dwOSVersionInfoSize = sizeof(Version);
3296 if (GetVersionEx (&Version))
3298 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3308 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3312 struct cmd_item *ti;
3317 ssp = (cm_SSetPref_t *)space;
3319 ssp->num_servers = 0;
3320 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3323 gblob.out_size = MAXSIZE;
3326 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3332 ti = as->parms[2].items; /* -file */
3334 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3335 if (!(infd = fopen(ti->data,"r" ))) {
3337 Die(errno,ti->data);
3340 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3341 code = addServer (name, (unsigned short) rank);
3345 ti = as->parms[3].items; /* -stdin */
3347 while ( scanf("%79s%ld", name, &rank) != EOF) {
3348 code = addServer (name, (unsigned short) rank);
3352 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3357 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3359 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3363 code = pokeServers();
3365 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3367 ssp = (cm_SSetPref_t *)space;
3368 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3370 ssp->flags = CM_SPREF_VLONLY;
3371 ssp->num_servers = 0;
3373 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3378 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3380 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3385 if (as->parms[1].items) {
3387 printf("now poking vlservers\n");
3388 code = pokeServers();
3398 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3402 struct cmd_item *ti;
3405 struct setspref *ssp;
3406 int error = 0; /* -1 means error message printed,
3407 * >0 means errno value for unprinted message */
3409 ssp = (struct setspref *)space;
3411 ssp->num_servers = 0;
3412 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3415 gblob.out_size = MAXSIZE;
3419 fprintf(stderr, "Permission denied: requires root access.\n");
3423 ti = as->parms[2].items; /* -file */
3426 fprintf(stderr, "opening file %s\n", ti->data);
3427 if (!(infd = fopen(ti->data, "r"))) {
3431 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3432 code = addServer(name, (unsigned short)rank);
3439 ti = as->parms[3].items; /* -stdin */
3441 while (scanf("%79s%ld", name, &rank) != EOF) {
3442 code = addServer(name, (unsigned short)rank);
3448 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3453 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3457 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3461 code = pokeServers();
3465 printf("now working on vlservers, code=%d\n", code);
3467 ssp = (struct setspref *)space;
3468 ssp->flags = DBservers;
3469 ssp->num_servers = 0;
3470 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3473 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3478 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3482 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3487 if (as->parms[1].items) {
3489 printf("now poking vlservers\n");
3490 code = pokeServers();
3498 return error ? 1 : 0;
3504 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3507 struct cmd_item *ti;
3508 char *name, tbuffer[20];
3513 struct ViceIoctl blob;
3514 struct cm_SPrefRequest *in;
3515 struct cm_SPrefInfo *out;
3519 ti = as->parms[0].items; /* -file */
3521 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3522 if (!(outfd = freopen(ti->data,"w",stdout))) {
3523 Die(errno,ti->data);
3528 ti = as->parms[1].items; /* -numeric */
3530 ti = as->parms[2].items; /* -vlservers */
3531 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3532 /* ti = as->parms[3].items; -cell */
3534 in = (struct cm_SPrefRequest *)space;
3538 blob.in_size=sizeof(struct cm_SPrefRequest);
3539 blob.in = (char *)in;
3541 blob.out_size = MAXSIZE;
3543 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3544 in->flags = vlservers;
3546 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3548 perror("getserverprefs pioctl");
3552 out = (struct cm_SPrefInfo *) blob.out;
3554 for (i=0;i<out->num_servers;i++) {
3556 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3559 addr = ntohl(out->servers[i].host.s_addr);
3560 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3561 (addr>>8) & 0xff, addr & 0xff);
3564 printf ("%-50s %5u\n",name,out->servers[i].rank);
3567 in->offset = out->next_offset;
3569 } while (!code && out->next_offset > 0);
3575 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3578 struct cmd_item *ti;
3579 char *name, tbuffer[20];
3580 afs_int32 rank, addr;
3584 struct ViceIoctl blob;
3585 struct sprefrequest *in;
3586 struct sprefinfo *out;
3589 ti = as->parms[0].items; /* -file */
3592 fprintf(stderr, "opening file %s\n", ti->data);
3593 if (!(outfd = freopen(ti->data, "w", stdout))) {
3599 ti = as->parms[1].items; /* -numeric */
3601 ti = as->parms[2].items; /* -vlservers */
3602 vlservers |= (ti ? DBservers : 0);
3603 /* ti = as->parms[3].items; -cell */
3605 in = (struct sprefrequest *)space;
3609 blob.in_size = sizeof(struct sprefrequest);
3610 blob.in = (char *)in;
3612 blob.out_size = MAXSIZE;
3615 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3616 in->flags = vlservers;
3618 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3620 perror("getserverprefs pioctl");
3624 out = (struct sprefinfo *)blob.out;
3626 for (i = 0; i < out->num_servers; i++) {
3628 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3630 addr = ntohl(out->servers[i].server.s_addr);
3631 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3632 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3635 printf("%-50s %5u\n", name, out->servers[i].rank);
3638 in->offset = out->next_offset;
3639 } while (out->next_offset > 0);
3646 UuidCmd(struct cmd_syndesc *asp, void *arock)
3651 struct ViceIoctl blob;
3652 char * uuidstring = NULL;
3654 if (asp->parms[0].items) {
3657 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3662 fprintf (stderr, "Permission denied: requires root access.\n");
3666 inValue = 1; /* generate new UUID */
3668 inValue = 0; /* just show the current UUID */
3671 blob.in_size = sizeof(inValue);
3672 blob.in = (char *) &inValue;
3673 blob.out_size = sizeof(outValue);
3674 blob.out = (char *) &outValue;
3676 code = pioctl(NULL, VIOC_UUIDCTL, &blob, 1);
3682 UuidToString((UUID *) &outValue, &uuidstring);
3684 printf("%sUUID: %s",
3685 ((inValue == 1)?"New ":""),
3689 RpcStringFree(&uuidstring);
3695 TraceCmd(struct cmd_syndesc *asp, void *arock)
3698 struct ViceIoctl blob;
3704 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3709 fprintf (stderr,"Permission denied: requires root access.\n");
3714 if ((asp->parms[0].items && asp->parms[1].items)) {
3715 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
3719 /* determine if we're turning this tracing on or off */
3721 if (asp->parms[0].items)
3722 inValue = 3; /* enable */
3723 else if (asp->parms[1].items)
3724 inValue = 2; /* disable */
3725 if (asp->parms[2].items)
3726 inValue |= 4; /* do reset */
3727 if (asp->parms[3].items)
3728 inValue |= 8; /* dump */
3730 blob.in_size = sizeof(long);
3731 blob.in = (char *) &inValue;
3732 blob.out_size = sizeof(long);
3733 blob.out = (char *) &outValue;
3735 code = pioctl(NULL, VIOC_TRACECTL, &blob, 1);
3742 printf("AFS tracing enabled.\n");
3744 printf("AFS tracing disabled.\n");
3749 static void sbusage(void)
3751 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
3752 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
3755 /* fs sb -kbytes 9999 -files *.o -default 64 */
3757 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3760 struct ViceIoctl blob;
3761 struct cmd_item *ti;
3762 struct sbstruct tsb, tsb2;
3770 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3775 tsb.sb_thisfile = -1;
3776 ti = as->parms[0].items; /* -kbytes */
3778 if (!as->parms[1].items) {
3779 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3783 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3784 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3785 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3791 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3792 ti = as->parms[2].items; /* -allfiles */
3794 allfiles = strtol(ti->data, &t, 10) * 1024;
3795 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3796 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3802 /* -verbose or -file only or no options */
3803 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3804 || (!as->parms[0].items && !as->parms[1].items
3805 && !as->parms[2].items))
3808 blob.in = (char *)&tsb;
3809 blob.out = (char *)&tsb2;
3810 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3811 memset(&tsb2, 0, sizeof(tsb2));
3813 /* once per -file */
3814 for (ti = as->parms[1].items; ti; ti = ti->next) {
3815 /* Do this solely to see if the file is there */
3816 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3818 Die(errno, ti->data);
3823 code = pioctl(ti->data, VIOC_STOREBEHIND, &blob, 1);
3825 Die(errno, ti->data);
3830 if (verbose && (blob.out_size == sizeof(tsb2))) {
3831 if (tsb2.sb_thisfile == -1) {
3832 fprintf(stdout, "Will store %s according to default.\n",
3836 "Will store up to %d kbytes of %s asynchronously.\n",
3837 (tsb2.sb_thisfile / 1024), ti->data);
3842 /* If no files - make at least one pioctl call, or
3843 * set the allfiles default if we need to.
3845 if (!as->parms[1].items || (allfiles != -1)) {
3846 tsb.sb_default = allfiles;
3847 code = pioctl(0, VIOC_STOREBEHIND, &blob, 1);
3849 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3854 /* Having no arguments also reports the default store asynchrony */
3855 if (verbose && (blob.out_size == sizeof(tsb2))) {
3856 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3857 (tsb2.sb_default / 1024));
3864 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3866 afs_int32 code = 0, flag;
3867 struct ViceIoctl blob;
3872 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3877 tp = as->parms[0].items->data;
3878 if (strcmp(tp, "on") == 0)
3880 else if (strcmp(tp, "off") == 0)
3883 fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3887 blob.in = (char *) &flag;
3888 blob.in_size = sizeof(flag);
3890 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3897 GetCryptCmd(struct cmd_syndesc *as, void *arock)
3899 afs_int32 code = 0, flag;
3900 struct ViceIoctl blob;
3905 blob.out_size = sizeof(flag);
3908 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3914 memcpy(&flag, tp, sizeof(afs_int32));
3915 printf("Security level is currently ");
3917 printf("crypt (data security).\n");
3925 MemDumpCmd(struct cmd_syndesc *asp, void *arock)
3928 struct ViceIoctl blob;
3933 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3937 if ((asp->parms[0].items && asp->parms[1].items)) {
3938 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
3942 /* determine if we're turning this tracing on or off */
3943 if (asp->parms[0].items)
3944 inValue = 1; /* begin */
3945 else if (asp->parms[1].items)
3946 inValue = 0; /* end */
3949 blob.in_size = sizeof(long);
3950 blob.in = (char *) &inValue;
3951 blob.out_size = sizeof(long);
3952 blob.out = (char *) &outValue;
3954 code = pioctl(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
3961 printf("AFS memdump created.\n");
3964 printf("AFS memdump failed.\n");
3970 MiniDumpCmd(struct cmd_syndesc *asp, void *arock)
3973 SERVICE_STATUS status;
3974 SC_HANDLE hManager = NULL;
3975 SC_HANDLE hService = NULL;
3978 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3982 hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
3986 hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
3990 success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
3993 CloseServiceHandle(hService);
3994 CloseServiceHandle(hManager);
3996 printf("AFS minidump generated.\n");
4002 CloseServiceHandle(hService);
4004 CloseServiceHandle(hManager);
4006 printf("AFS minidump failed.\n");
4011 CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
4013 struct cmd_item *ti;
4018 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4022 for(ti=asp->parms[0].items; ti;ti=ti->next) {
4034 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4035 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4038 REG_OPTION_NON_VOLATILE,
4039 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
4044 if ( hkCSCPolicy == NULL ) {
4045 fprintf (stderr,"Permission denied: requires Administrator access.\n");
4050 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4051 RegCloseKey(hkCSCPolicy);
4057 if (asp->parms[1].items)
4059 if (asp->parms[2].items)
4060 policy = "programs";
4061 if (asp->parms[3].items)
4062 policy = "documents";
4063 if (asp->parms[4].items)
4066 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, (DWORD)strlen(policy)+1);
4068 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
4069 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
4073 DWORD dwIndex, dwPolicies;
4074 char policyName[256];
4075 DWORD policyNameLen;
4080 /* list current csc policies */
4082 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4083 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4086 REG_OPTION_NON_VOLATILE,
4087 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_QUERY_VALUE,
4092 RegQueryInfoKey( hkCSCPolicy,
4094 NULL, /* lpcClass */
4095 NULL, /* lpReserved */
4096 NULL, /* lpcSubKeys */
4097 NULL, /* lpcMaxSubKeyLen */
4098 NULL, /* lpcMaxClassLen */
4099 &dwPolicies, /* lpcValues */
4100 NULL, /* lpcMaxValueNameLen */
4101 NULL, /* lpcMaxValueLen */
4102 NULL, /* lpcbSecurityDescriptor */
4103 NULL /* lpftLastWriteTime */
4106 printf("Current CSC policies:\n");
4107 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
4109 policyNameLen = sizeof(policyName);
4110 policyLen = sizeof(policy);
4111 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
4112 &dwType, policy, &policyLen);
4114 printf(" %s = %s\n", policyName, policy);
4118 RegCloseKey(hkCSCPolicy);
4123 /* get clients interface addresses */
4125 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4128 struct cmd_item *ti;
4130 struct ViceIoctl blob;
4131 struct sprefrequest *in;
4132 struct sprefinfo *out;
4134 in = (struct sprefrequest *)space;
4138 blob.in_size = sizeof(struct sprefrequest);
4139 blob.in = (char *)in;
4141 blob.out_size = MAXSIZE;
4144 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4145 /* returns addr in network byte order */
4146 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
4148 perror("getClientInterfaceAddr pioctl");
4154 out = (struct sprefinfo *)blob.out;
4155 for (i = 0; i < out->num_servers; i++) {
4158 addr = ntohl(out->servers[i].server.s_addr);
4159 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
4160 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
4161 printf("%-50s\n", tbuffer);
4163 in->offset = out->next_offset;
4165 } while (out->next_offset > 0);
4171 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4173 afs_int32 code, addr;
4174 struct cmd_item *ti;
4176 struct ViceIoctl blob;
4177 struct setspref *ssp;
4178 int sizeUsed = 0, i, flag;
4179 afs_int32 existingAddr[1024]; /* existing addresses on this host */
4183 ssp = (struct setspref *)space;
4184 ssp->num_servers = 0;
4187 blob.out_size = MAXSIZE;
4190 fprintf(stderr, "Permission denied: requires root access.\n");
4194 /* extract all existing interface addresses */
4195 existNu = rx_getAllAddr(existingAddr, 1024);
4199 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4200 for (ti = as->parms[0].items; ti; ti = ti->next) {
4201 if (sizeUsed >= sizeof(space)) {
4202 fprintf(stderr, "No more space\n");
4205 addr = extractAddr(ti->data, 20); /* network order */
4206 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4207 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4212 /* see if it is an address that really exists */
4213 for (flag = 0, i = 0; i < existNu; i++)
4214 if (existingAddr[i] == addr) {
4218 if (!flag) { /* this is an nonexistent address */
4219 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4223 /* copy all specified addr into ioctl buffer */
4224 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4225 printf("Adding 0x%08x\n", addr);
4227 sizeUsed += sizeof(struct spref);
4229 if (ssp->num_servers < 1) {
4230 fprintf(stderr, "No addresses specified\n");
4233 blob.in_size = sizeUsed - sizeof(struct spref);
4235 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4245 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4248 struct ViceIoctl blob;
4249 struct cmd_item *ti;
4250 char orig_name[1024]; /*Original name, may be modified */
4251 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4252 char parent_dir[1024]; /*Parent directory of true name */
4253 char *last_component; /*Last component of true name */
4254 struct stat statbuff; /*Buffer for status info */
4255 int link_chars_read; /*Num chars read in readlink() */
4256 int thru_symlink; /*Did we get to a mount point via a symlink? */
4259 for (ti = as->parms[0].items; ti; ti = ti->next) {
4262 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4265 if (lstat(orig_name, &statbuff) < 0) {
4266 /* if lstat fails, we should still try the pioctl, since it
4267 * may work (for example, lstat will fail, but pioctl will
4268 * work if the volume of offline (returning ENODEV). */
4269 statbuff.st_mode = S_IFDIR; /* lie like pros */
4273 * The lstat succeeded. If the given file is a symlink, substitute
4274 * the file name with the link name.
4276 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4279 * Read name of resolved file.
4281 link_chars_read = readlink(orig_name, true_name, 1024);
4282 if (link_chars_read <= 0) {
4284 "%s: Can't read target name for '%s' symbolic link!\n",
4291 * Add a trailing null to what was read, bump the length.
4293 true_name[link_chars_read++] = 0;
4296 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4297 * have to create a full pathname using the original name and the
4298 * relative symlink name. Find the rightmost slash in the original
4299 * name (we know there is one) and splice in the symlink value.
4301 if (true_name[0] != '/') {
4302 last_component = (char *)strrchr(orig_name, '/');
4303 strcpy(++last_component, true_name);
4304 strcpy(true_name, orig_name);
4307 strcpy(true_name, orig_name);
4310 * Find rightmost slash, if any.
4312 last_component = (char *)strrchr(true_name, '/');
4313 if (last_component) {
4315 * Found it. Designate everything before it as the parent directory,
4316 * everything after it as the final component.
4318 strncpy(parent_dir, true_name, last_component - true_name);
4319 parent_dir[last_component - true_name] = 0;
4320 last_component++; /*Skip the slash */
4323 * No slash appears in the given file name. Set parent_dir to the current
4324 * directory, and the last component as the given name.
4326 strcpy(parent_dir, ".");
4327 last_component = true_name;
4330 if (strcmp(last_component, ".") == 0
4331 || strcmp(last_component, "..") == 0) {
4333 "%s: you may not use '.' or '..' as the last component\n",
4335 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4341 blob.in = last_component;
4342 blob.in_size = strlen(last_component) + 1;
4344 memset(space, 0, MAXSIZE);
4346 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4349 if (errno == EINVAL) {
4350 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4352 Die(errno, (ti->data ? ti->data : parent_dir));
4362 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4365 afs_int32 flags = 0;
4366 struct ViceIoctl blob;
4368 if (as->parms[0].items) { /* -enable */
4369 flags |= AFSCALL_RXSTATS_ENABLE;
4371 if (as->parms[1].items) { /* -disable */
4372 flags |= AFSCALL_RXSTATS_DISABLE;
4374 if (as->parms[2].items) { /* -clear */
4375 flags |= AFSCALL_RXSTATS_CLEAR;
4378 fprintf(stderr, "You must specify at least one argument\n");
4382 blob.in = (char *)&flags;
4383 blob.in_size = sizeof(afs_int32);
4386 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4396 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4399 afs_int32 flags = 0;
4400 struct ViceIoctl blob;
4402 if (as->parms[0].items) { /* -enable */
4403 flags |= AFSCALL_RXSTATS_ENABLE;
4405 if (as->parms[1].items) { /* -disable */
4406 flags |= AFSCALL_RXSTATS_DISABLE;
4408 if (as->parms[2].items) { /* -clear */
4409 flags |= AFSCALL_RXSTATS_CLEAR;
4412 fprintf(stderr, "You must specify at least one argument\n");
4416 blob.in = (char *)&flags;
4417 blob.in_size = sizeof(afs_int32);
4420 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4430 TestVolStatCmd(struct cmd_syndesc *as, void *arock)
4433 struct VolStatTest test;
4434 struct ViceIoctl blob;
4438 memset(&test, 0, sizeof(test));
4440 if (as->parms[0].items) { /* -network */
4441 tp = as->parms[0].items->data;
4442 if (strcmp(tp, "up") == 0)
4443 test.flags |= VOLSTAT_TEST_NETWORK_UP;
4444 else if (strcmp(tp, "down") == 0)
4445 test.flags |= VOLSTAT_TEST_NETWORK_DOWN;
4447 fprintf (stderr, "%s: %s must be \"up\" or \"down\".\n", pn, tp);
4451 if (as->parms[1].items) { /* check */
4452 test.flags |= VOLSTAT_TEST_CHECK_VOLUME;
4454 if (as->parms[2].items) { /* cell */
4455 tp = as->parms[2].items->data;
4460 strncpy(test.cellname, tp, sizeof(test.cellname));
4461 test.cellname[sizeof(test.cellname)-1] = '\0';
4464 if (as->parms[3].items) { /* volume */
4465 tp = as->parms[3].items->data;
4468 test.fid.volume = n;
4470 strncpy(test.volname, tp, sizeof(test.volname));
4471 test.volname[sizeof(test.volname)-1] = '\0';
4474 if (as->parms[4].items) { /* state */
4475 tp = as->parms[4].items->data;
4476 if (strcmp(tp, "online") == 0)
4477 test.state = vl_online;
4478 else if (strcmp(tp, "busy") == 0)
4479 test.state = vl_busy;
4480 else if (strcmp(tp, "offline") == 0)
4481 test.state = vl_offline;
4482 else if (strcmp(tp, "down") == 0)
4483 test.state = vl_alldown;
4485 fprintf (stderr, "%s: %s must be \"online\", \"busy\", \"offline\" or \"down\".\n", pn, tp);
4490 if ((test.fid.cell || test.cellname[0]) && !(test.fid.volume || test.volname[0]) ||
4491 !(test.fid.cell || test.cellname[0]) && (test.fid.volume || test.volname[0])) {
4492 fprintf (stderr, "%s: both a cell and a volume must be specified.\n", pn, tp);
4496 blob.in = (char *)&test;
4497 blob.in_size = sizeof(test);
4500 code = pioctl(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
4510 #include "AFS_component_version_number.c"
4513 main(int argc, char **argv)
4516 struct cmd_syndesc *ts;
4518 #ifdef AFS_AIX32_ENV
4520 * The following signal action for AIX is necessary so that in case of a
4521 * crash (i.e. core is generated) we can include the user's data section
4522 * in the core dump. Unfortunately, by default, only a partial core is
4523 * generated which, in many cases, isn't too useful.
4525 struct sigaction nsa;
4527 sigemptyset(&nsa.sa_mask);
4528 nsa.sa_handler = SIG_DFL;
4529 nsa.sa_flags = SA_FULLDUMP;
4530 sigaction(SIGSEGV, &nsa, NULL);
4535 WSAStartup(0x0101, &WSAjunk);
4538 /* try to find volume location information */
4542 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
4543 "get client network interface addresses");
4544 cmd_CreateAlias(ts, "gc");
4546 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
4547 "set client network interface addresses");
4548 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
4549 "client network interfaces");
4550 cmd_CreateAlias(ts, "sc");
4553 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL, "set server ranks");
4554 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
4555 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
4556 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
4557 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
4558 cmd_CreateAlias(ts, "sp");
4560 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL, "get server ranks");
4561 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
4562 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4563 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
4564 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
4565 cmd_CreateAlias(ts, "gp");
4567 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
4568 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4569 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
4570 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
4571 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
4572 parm_setacl_id = ts->nParms;
4573 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
4574 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
4575 cmd_CreateAlias(ts, "sa");
4577 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL, "list access control list");
4578 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4579 parm_listacl_id = ts->nParms;
4580 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4581 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4582 cmd_CreateAlias(ts, "la");
4584 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL, "clean up access control list");
4585 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4587 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL, "copy access control list");
4588 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
4589 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
4590 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
4591 parm_copyacl_id = ts->nParms;
4592 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4593 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4595 cmd_CreateAlias(ts, "ca");
4597 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
4598 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4599 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4602 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
4603 "flush mount symlink from cache");
4604 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4607 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
4608 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4609 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
4611 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
4613 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
4614 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
4615 cmd_CreateAlias(ts, "sv");
4617 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL, "control Cache Manager messages");
4618 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
4620 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
4621 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4622 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4623 cmd_CreateAlias(ts, "lv");
4624 cmd_CreateAlias(ts, "listvol");
4626 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
4627 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4628 cmd_CreateAlias(ts, "lq");
4630 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL, "show server disk space usage");
4631 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4632 cmd_CreateAlias(ts, "df");
4634 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
4635 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4637 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
4638 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4640 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
4641 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
4642 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
4643 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
4644 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
4645 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
4651 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
4655 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
4656 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4658 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL, "check local cell's servers");
4659 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
4660 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
4661 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
4662 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
4664 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL, "check volumeID/name mappings");
4665 cmd_CreateAlias(ts, "checkbackups");
4668 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL, "set cache size");
4669 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
4670 cmd_CreateAlias(ts, "cachesize");
4672 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
4674 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL, "get cache usage info");
4676 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL, "list configured cells");
4677 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4679 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
4680 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
4681 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
4683 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
4685 cmd_CreateAlias(ts, "sq");
4687 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
4689 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
4690 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
4691 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
4693 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
4695 * Turn this on only if you wish to be able to talk to a server which is listening
4696 * on alternative ports. This is not intended for general use and may not be
4697 * supported in the cache manager. It is not a way to run two servers at the
4698 * same host, since the cache manager cannot properly distinguish those two hosts.
4700 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
4701 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
4704 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
4705 "configure new cell alias");
4706 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
4707 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
4710 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
4711 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4712 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4714 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
4715 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4716 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4718 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
4721 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
4724 #ifndef AFS_NT40_ENV
4725 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, "set cache monitor host address");
4726 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
4727 cmd_CreateAlias(ts, "mariner");
4730 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
4731 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4733 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
4734 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4735 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
4736 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
4738 ts = cmd_CreateSyntax("flushall", FlushAllCmd, NULL, "flush all data");
4740 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL, "flush all data in volume");
4741 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4743 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL, "get/set sysname (i.e. @sys) value");
4744 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
4746 #ifndef AFS_NT40_ENV
4747 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL, "enable/disable translators to AFS");
4748 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
4749 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
4750 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
4751 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
4752 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
4755 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
4756 "store to server after file close");
4757 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
4758 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
4759 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
4760 cmd_CreateAlias(ts, "sb");
4762 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL, "set cache manager encryption flag");
4763 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
4765 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL, "get cache manager encryption flag");
4767 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
4768 "Manage per process RX statistics");
4769 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4770 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4771 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4773 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
4774 "Manage per peer RX statistics");
4775 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4776 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4777 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4780 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
4781 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
4784 ts = cmd_CreateSyntax("trace", TraceCmd, NULL, "enable or disable CM tracing");
4785 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
4786 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
4787 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
4788 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
4789 cmd_CreateAlias(ts, "tr");
4791 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
4792 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
4794 ts = cmd_CreateSyntax("memdump", MemDumpCmd, NULL, "dump memory allocs in debug builds");
4795 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
4796 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
4798 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, NULL, "change client side caching policy for AFS shares");
4799 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
4800 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
4801 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
4802 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
4803 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
4805 ts = cmd_CreateSyntax("minidump", MiniDumpCmd, NULL, "Generate MiniDump of current service state");
4807 ts = cmd_CreateSyntax("test_volstat", TestVolStatCmd, NULL, (char *)CMD_HIDDEN);
4808 cmd_AddParm(ts, "-network", CMD_SINGLE, CMD_OPTIONAL, "set network state up or down");
4809 cmd_AddParm(ts, "-check", CMD_FLAG, CMD_OPTIONAL, "check state of offline volumes");
4810 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name or number");
4811 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or number");
4812 cmd_AddParm(ts, "-state", CMD_SINGLE, CMD_OPTIONAL, "new volume state: online, busy, offline, down");
4814 code = cmd_Dispatch(argc, argv);
4823 Die(int code, char *filename)
4826 if (code == EINVAL) {
4828 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
4830 fprintf(stderr,"%s: Invalid argument.\n", pn);
4832 else if (code == ENOENT) {
4834 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
4836 fprintf(stderr,"%s: no such file returned\n", pn);
4838 else if (code == EROFS)
4839 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
4840 else if (code == EACCES || code == EPERM) {
4842 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
4844 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
4846 else if (code == ENODEV) {
4847 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
4849 else if (code == ESRCH) { /* hack */
4850 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
4852 else if (code == EPIPE) { /* hack */
4853 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
4855 else if (code == EFBIG) {
4856 fprintf(stderr,"%s: Cache size too large.\n", pn);
4858 else if (code == ETIMEDOUT) {
4860 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
4862 fprintf(stderr,"%s: Connection timed out", pn);
4864 else if (code == EBUSY) {
4866 fprintf(stderr,"%s: All servers are busy on which '%s' resides\n", pn, filename);
4868 fprintf(stderr,"%s: All servers are busy\n", pn);
4870 else if (code == ENXIO) {
4872 fprintf(stderr,"%s: All volume instances are offline on which '%s' resides\n", pn, filename);
4874 fprintf(stderr,"%s: All volume instances are offline\n", pn);
4876 else if (code == ENOSYS) {
4878 fprintf(stderr,"%s: All servers are down on which '%s' resides\n", pn, filename);
4880 fprintf(stderr,"%s: All servers are down\n", pn);
4884 fprintf(stderr,"%s:'%s'", pn, filename);
4886 fprintf(stderr,"%s", pn);
4888 fprintf(stderr, ": code 0x%x\n", code);
4889 #else /* not WIN32 */
4890 fprintf(stderr,": %s\n", afs_error_message(code));
4891 #endif /* not WIN32 */