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/ptserver.h>
27 #include <afs/ptuser.h>
28 #include <WINNT\afsreg.h>
38 #define MAXCELLHOSTS 8
41 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
42 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
43 #define MAXCELLCHARS 64
44 #define MAXHOSTCHARS 64
46 static char space[MAXSIZE];
47 static char tspace[1024];
50 static struct ubik_client *uclient;
51 #endif /* not WIN32 */
53 static int GetClientAddrsCmd(struct cmd_syndesc *asp, char *arock);
54 static int SetClientAddrsCmd(struct cmd_syndesc *asp, char *arock);
55 static int FlushMountCmd(struct cmd_syndesc *asp, char *arock);
56 static int RxStatProcCmd(struct cmd_syndesc *asp, char *arock);
57 static int RxStatPeerCmd(struct cmd_syndesc *asp, char *arock);
59 extern struct cmd_syndesc *cmd_CreateSyntax();
61 static int MemDumpCmd(struct cmd_syndesc *asp, char *arock);
62 static int CSCPolicyCmd(struct cmd_syndesc *asp, char *arock);
63 static int MiniDumpCmd(struct cmd_syndesc *asp, char *arock);
65 extern afs_int32 VL_GetEntryByNameO();
67 static char pn[] = "fs";
68 static int rxInitDone = 0;
71 char name[MAXCELLCHARS];
74 struct sockaddr_in hostAddr[MAXCELLHOSTS];
75 char hostName[MAXCELLHOSTS][MAXHOSTCHARS];
81 * Character to use between name and rights in printed representation for
84 #define DFS_SEPARATOR ' '
86 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
89 int dfs; /* Originally true if a dfs acl; now also the type
90 * of the acl (1, 2, or 3, corresponding to object,
91 * initial dir, or initial object). */
92 sec_rgy_name_t cell; /* DFS cell name */
95 struct AclEntry *pluslist;
96 struct AclEntry *minuslist;
100 struct AclEntry *next;
106 ZapAcl (struct Acl *acl)
111 ZapList(acl->pluslist);
112 ZapList(acl->minuslist);
117 * Mods for the AFS/DFS protocol translator.
119 * DFS rights. It's ugly to put these definitions here, but they
120 * *cannot* change, because they're part of the wire protocol.
121 * In any event, the protocol translator will guarantee these
122 * assignments for AFS cache managers.
124 #define DFS_READ 0x01
125 #define DFS_WRITE 0x02
126 #define DFS_EXECUTE 0x04
127 #define DFS_CONTROL 0x08
128 #define DFS_INSERT 0x10
129 #define DFS_DELETE 0x20
131 /* the application definable ones (backwards from AFS) */
132 #define DFS_USR0 0x80000000 /* "A" bit */
133 #define DFS_USR1 0x40000000 /* "B" bit */
134 #define DFS_USR2 0x20000000 /* "C" bit */
135 #define DFS_USR3 0x10000000 /* "D" bit */
136 #define DFS_USR4 0x08000000 /* "E" bit */
137 #define DFS_USR5 0x04000000 /* "F" bit */
138 #define DFS_USR6 0x02000000 /* "G" bit */
139 #define DFS_USR7 0x01000000 /* "H" bit */
140 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
141 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
144 * Offset of -id switch in command structure for various commands.
145 * The -if switch is the next switch always.
147 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
150 * Determine whether either the -id or -if switches are present, and
151 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
153 /* int id; Offset of -id switch; -if is next switch */
155 getidf(struct cmd_syndesc *as, int id)
159 if (as->parms[id].items) {
162 if (as->parms[id + 1].items) {
167 "%s: you may specify either -id or -if, but not both switches\n",
175 PRights(afs_int32 arights, int dfs)
178 if (arights & PRSFS_READ)
180 if (arights & PRSFS_LOOKUP)
182 if (arights & PRSFS_INSERT)
184 if (arights & PRSFS_DELETE)
186 if (arights & PRSFS_WRITE)
188 if (arights & PRSFS_LOCK)
190 if (arights & PRSFS_ADMINISTER)
192 if (arights & PRSFS_USR0)
194 if (arights & PRSFS_USR1)
196 if (arights & PRSFS_USR2)
198 if (arights & PRSFS_USR3)
200 if (arights & PRSFS_USR4)
202 if (arights & PRSFS_USR5)
204 if (arights & PRSFS_USR6)
206 if (arights & PRSFS_USR7)
209 if (arights & DFS_READ)
213 if (arights & DFS_WRITE)
217 if (arights & DFS_EXECUTE)
221 if (arights & DFS_CONTROL)
225 if (arights & DFS_INSERT)
229 if (arights & DFS_DELETE)
233 if (arights & (DFS_USRALL))
235 if (arights & DFS_USR0)
237 if (arights & DFS_USR1)
239 if (arights & DFS_USR2)
241 if (arights & DFS_USR3)
243 if (arights & DFS_USR4)
245 if (arights & DFS_USR5)
247 if (arights & DFS_USR6)
249 if (arights & DFS_USR7)
255 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
259 struct ViceIoctl blob;
263 blob.out_size = MAXSIZE;
266 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
268 if ((errno == EINVAL) || (errno == ENOENT))
275 IsFreelanceRoot(char *apath)
277 struct ViceIoctl blob;
281 blob.out_size = MAXSIZE;
284 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
286 return !strcmp("Freelance.Local.Root",space);
287 return 1; /* assume it is because it is more restrictive that way */
290 /* return a static pointer to a buffer */
295 strcpy(tspace, apath);
296 tp = strrchr(tspace, '\\');
298 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
301 fs_ExtractDriveLetter(apath, tspace);
307 enum rtype {add, destroy, deny};
310 Convert(char *arights, int dfs, enum rtype *rtypep)
316 *rtypep = add; /* add rights, by default */
319 if (!strcmp(arights, "null")) {
323 if (!strcmp(arights,"read"))
324 return DFS_READ | DFS_EXECUTE;
325 if (!strcmp(arights, "write"))
326 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
328 if (!strcmp(arights, "all"))
329 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
330 DFS_WRITE | DFS_CONTROL;
332 if (!strcmp(arights,"read"))
333 return PRSFS_READ | PRSFS_LOOKUP;
334 if (!strcmp(arights, "write"))
335 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
336 PRSFS_WRITE | PRSFS_LOCK;
337 if (!strcmp(arights, "mail"))
338 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
339 if (!strcmp(arights, "all"))
340 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
341 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
343 if (!strcmp(arights, "none")) {
344 *rtypep = destroy; /* Remove entire entry */
347 len = strlen(arights);
383 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
391 mode |= PRSFS_LOOKUP;
393 mode |= PRSFS_INSERT;
395 mode |= PRSFS_DELETE;
401 mode |= PRSFS_ADMINISTER;
419 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
428 static struct AclEntry *
429 FindList (struct AclEntry *alist, char *aname)
432 if (!strcasecmp(alist->name, aname))
439 /* if no parm specified in a particular slot, set parm to be "." instead */
441 SetDotDefault(struct cmd_item **aitemp)
445 return; /* already has value */
446 /* otherwise, allocate an item representing "." */
447 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
449 ti->next = (struct cmd_item *) 0;
450 ti->data = (char *) malloc(2);
452 strcpy(ti->data, ".");
457 ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
459 struct AclEntry *tlist;
460 tlist = (plus ? al->pluslist : al->minuslist);
461 tlist = FindList (tlist, aname);
463 /* Found the item already in the list. */
464 tlist->rights = arights;
466 al->nplus -= PruneList(&al->pluslist, al->dfs);
468 al->nminus -= PruneList(&al->minuslist, al->dfs);
471 /* Otherwise we make a new item and plug in the new data. */
472 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
474 strcpy(tlist->name, aname);
475 tlist->rights = arights;
477 tlist->next = al->pluslist;
478 al->pluslist = tlist;
480 if (arights == 0 || arights == -1)
481 al->nplus -= PruneList(&al->pluslist, al->dfs);
483 tlist->next = al->minuslist;
484 al->minuslist = tlist;
487 al->nminus -= PruneList(&al->minuslist, al->dfs);
492 ZapList (struct AclEntry *alist)
494 struct AclEntry *tp, *np;
495 for (tp = alist; tp; tp = np) {
502 PruneList (struct AclEntry **ae, int dfs)
504 struct AclEntry **lp;
505 struct AclEntry *te, *ne;
509 for(te = *ae;te;te=ne) {
510 if ((!dfs && te->rights == 0) || te->rights == -1) {
524 SkipLine (char *astr)
533 * Create an empty acl, taking into account whether the acl pointed
534 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
535 * can recover from problems caused by bogus ACL's (in that case, always
536 * assume that the acl is AFS: for DFS, the user can always resort to
537 * acl_edit, but for AFS there may be no other way out).
545 tp = (struct Acl *)malloc(sizeof (struct Acl));
547 tp->nplus = tp->nminus = 0;
548 tp->pluslist = tp->minuslist = 0;
550 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
555 ParseAcl (char *astr)
557 int nplus, nminus, i, trights;
559 struct AclEntry *first, *last, *tl;
562 ta = (struct Acl *) malloc (sizeof (struct Acl));
565 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
566 astr = SkipLine(astr);
567 sscanf(astr, "%d", &ta->nminus);
568 astr = SkipLine(astr);
575 for(i=0;i<nplus;i++) {
576 sscanf(astr, "%100s %d", tname, &trights);
577 astr = SkipLine(astr);
578 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
582 strcpy(tl->name, tname);
583 tl->rights = trights;
589 ta->pluslist = first;
593 for(i=0;i<nminus;i++) {
594 sscanf(astr, "%100s %d", tname, &trights);
595 astr = SkipLine(astr);
596 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
600 strcpy(tl->name, tname);
601 tl->rights = trights;
607 ta->minuslist = first;
613 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
615 printf("Volume status for vid = %u named %s\n",status->Vid, name);
617 printf("Current offline message is %s\n",offmsg);
619 printf("Current message of the day is %s\n",motd);
620 printf("Current disk quota is ");
621 if (status->MaxQuota != 0)
622 printf("%d\n", status->MaxQuota);
624 printf("unlimited\n");
625 printf("Current blocks used are %d\n",status->BlocksInUse);
626 printf("The partition has %d blocks available out of %d\n\n",
627 status->PartBlocksAvail, status->PartMaxBlocks);
632 QuickPrintStatus(VolumeStatus *status, char *name)
634 double QuotaUsed =0.0;
635 double PartUsed =0.0;
637 printf("%-25.25s",name);
639 if (status->MaxQuota != 0) {
640 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
641 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
643 printf("no limit%10d", status->BlocksInUse);
645 if (QuotaUsed > 90.0){
646 printf(" %5.0f%%<<", QuotaUsed);
649 printf(" %5.0f%% ", QuotaUsed);
650 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
651 if (PartUsed > 97.0){
652 printf(" %9.0f%%<<", PartUsed);
655 printf(" %9.0f%% ", PartUsed);
657 printf(" <<WARNING\n");
664 QuickPrintSpace(VolumeStatus *status, char *name)
666 double PartUsed =0.0;
668 printf("%-25.25s",name);
670 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
672 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
673 if (PartUsed > 90.0){
674 printf(" %4.0f%%<<", PartUsed);
677 printf(" %4.0f%% ", PartUsed);
679 printf(" <<WARNING\n");
686 AclToString(struct Acl *acl)
688 static char mydata[MAXSIZE];
689 char tstring[MAXSIZE];
694 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
697 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
698 for (tp = acl->pluslist;tp;tp=tp->next) {
699 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
700 strcat(mydata, tstring);
702 for (tp = acl->minuslist;tp;tp=tp->next) {
703 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
704 strcat(mydata, tstring);
709 static DWORD IsFreelance(void)
716 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
717 0, KEY_QUERY_VALUE, &parmKey);
718 if (code == ERROR_SUCCESS) {
719 dummyLen = sizeof(cm_freelanceEnabled);
720 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
721 (BYTE *) &enabled, &dummyLen);
722 RegCloseKey (parmKey);
727 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
729 static BOOL IsAdmin (void)
731 static BOOL fAdmin = FALSE;
732 static BOOL fTested = FALSE;
736 /* Obtain the SID for the AFS client admin group. If the group does
737 * not exist, then assume we have AFS client admin privileges.
739 PSID psidAdmin = NULL;
740 DWORD dwSize, dwSize2;
741 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
742 char *pszRefDomain = NULL;
743 SID_NAME_USE snu = SidTypeGroup;
745 dwSize = sizeof(pszAdminGroup);
747 if (!GetComputerName(pszAdminGroup, &dwSize)) {
748 /* Can't get computer name. We return false in this case.
749 Retain fAdmin and fTested. This shouldn't happen.*/
756 strcat(pszAdminGroup,"\\");
757 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
759 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
760 /* that should always fail. */
762 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
763 /* if we can't find the group, then we allow the operation */
768 if (dwSize == 0 || dwSize2 == 0) {
774 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
776 pszRefDomain = (char *)malloc(dwSize2);
777 assert(pszRefDomain);
779 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
780 /* We can't lookup the group now even though we looked it up earlier.
781 Could this happen? */
784 /* Then open our current ProcessToken */
787 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
790 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
791 /* We'll have to allocate a chunk of memory to store the list of
792 * groups to which this user belongs; find out how much memory
796 PTOKEN_GROUPS pGroups;
798 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
800 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
803 /* Allocate that buffer, and read in the list of groups. */
804 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
806 /* Look through the list of group SIDs and see if any of them
807 * matches the AFS Client Admin group SID.
810 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
812 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
822 /* if do not have permission because we were not explicitly listed
823 * in the Admin Client Group let's see if we are the SYSTEM account
826 PTOKEN_USER pTokenUser;
827 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
828 PSID pSidLocalSystem = 0;
831 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
833 pTokenUser = (PTOKEN_USER)malloc(dwSize);
836 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
837 gle = GetLastError();
839 if (AllocateAndInitializeSid( &SIDAuth, 1,
840 SECURITY_LOCAL_SYSTEM_RID,
844 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
848 FreeSid(pSidLocalSystem);
867 SetACLCmd(struct cmd_syndesc *as, char *arock)
870 struct ViceIoctl blob;
872 struct cmd_item *ti, *ui;
876 int idf = getidf(as, parm_setacl_id);
880 if (as->parms[2].items)
884 plusp = !(as->parms[3].items);
885 for(ti=as->parms[0].items; ti;ti=ti->next) {
886 blob.out_size = MAXSIZE;
888 blob.in = blob.out = space;
889 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
891 Die(errno, ti->data);
897 ta = ParseAcl(space);
898 if (!plusp && ta->dfs) {
900 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
902 "(you may specify \"null\" to revoke all rights, however)\n");
909 ta = EmptyAcl(space);
911 ta = ParseAcl(space);
912 CleanAcl(ta, ti->data);
913 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
917 "%s: Missing second half of user/access pair.\n", pn);
921 rights = Convert(ui->next->data, ta->dfs, &rtype);
922 if (rtype == destroy && !ta->dfs) {
923 struct AclEntry *tlist;
925 tlist = (plusp ? ta->pluslist : ta->minuslist);
926 if (!FindList(tlist, ui->data))
929 if (rtype == deny && !ta->dfs)
931 if (rtype == destroy && ta->dfs)
933 ChangeList(ta, plusp, ui->data, rights);
935 blob.in = AclToString(ta);
937 blob.in_size = 1+strlen(blob.in);
938 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
940 if (errno == EINVAL) {
942 static char *fsenv = 0;
944 fsenv = (char *)getenv("FS_EXPERT");
946 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
949 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
950 "\nPossible reasons for this include:\n\n",
951 " -You may have specified an inappropriate combination of rights.\n",
952 " For example, some DFS-supported filesystems may not allow you to\n",
953 " drop the \"c\" right from \"user_obj\".\n\n",
954 " -A mask_obj may be required (it is likely required by the underlying\n",
955 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
956 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
957 " does not automatically create or update the mask_obj. Try setting\n",
958 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
959 " users or groups. You can do this with a single command, such as\n",
960 " \"fs sa mask_obj all user:somename read\"\n\n",
961 " -A specified user or group may not exist.\n\n",
962 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
963 " This is probably not allowed by the underlying file system.\n\n",
964 " -If you add a user or group to a DFS ACL, remember that it must be\n",
965 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
966 " may be local requirements on the format of the user or group name.\n",
967 " Check with your cell administrator.\n\n",
968 " -Or numerous other possibilities. It would be great if we could be more\n",
969 " precise about the actual problem, but for various reasons, this is\n",
970 " impractical via this interface. If you can't figure it out, you\n",
971 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
972 " whatever is provided). You may get better results. Good luck!\n\n",
973 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
977 "%s: Invalid argument, possible reasons include:\n",
979 fprintf(stderr,"\t-File not in AFS\n");
981 "\t-Too many users on access control list\n");
983 "\t-Tried to add non-existent user to access control list\n");
986 Die(errno, ti->data);
997 CopyACLCmd(struct cmd_syndesc *as, char *arock)
1000 struct ViceIoctl blob;
1001 struct Acl *fa, *ta = 0;
1002 struct AclEntry *tp;
1003 struct cmd_item *ti;
1005 int idf = getidf(as, parm_copyacl_id);
1008 if (as->parms[2].items)
1012 blob.out_size = MAXSIZE;
1014 blob.in = blob.out = space;
1015 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1017 Die(errno, as->parms[0].items->data);
1020 fa = ParseAcl(space);
1021 CleanAcl(fa, as->parms[0].items->data);
1022 for (ti=as->parms[1].items; ti;ti=ti->next) {
1023 blob.out_size = MAXSIZE;
1025 blob.in = blob.out = space;
1026 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1028 Die(errno, ti->data);
1035 ta = EmptyAcl(space);
1037 ta = ParseAcl(space);
1038 CleanAcl(ta, ti->data);
1039 if (ta->dfs != fa->dfs) {
1041 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1047 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1049 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1054 strcpy(ta->cell, fa->cell);
1056 for (tp = fa->pluslist;tp;tp=tp->next)
1057 ChangeList(ta, 1, tp->name, tp->rights);
1058 for (tp = fa->minuslist;tp;tp=tp->next)
1059 ChangeList(ta, 0, tp->name, tp->rights);
1060 blob.in = AclToString(ta);
1062 blob.in_size = 1+strlen(blob.in);
1063 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1065 if (errno == EINVAL) {
1067 "%s: Invalid argument, possible reasons include:\n", pn);
1068 fprintf(stderr,"\t-File not in AFS\n");
1070 Die(errno, ti->data);
1081 /* pioctl() call to get the cellname of a pathname */
1083 GetCell(char *fname, char *cellname)
1086 struct ViceIoctl blob;
1089 blob.out_size = MAXCELLCHARS;
1090 blob.out = cellname;
1092 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1093 return code ? errno : 0;
1096 /* Check if a username is valid: If it contains only digits (or a
1097 * negative sign), then it might be bad. We then query the ptserver
1101 BadName(char *aname, char *fname)
1103 afs_int32 tc, code, id;
1105 char cell[MAXCELLCHARS];
1107 for ( nm = aname; tc = *nm; nm++) {
1108 /* all must be '-' or digit to be bad */
1109 if (tc != '-' && (tc < '0' || tc > '9'))
1113 /* Go to the PRDB and see if this all number username is valid */
1114 code = GetCell(fname, cell);
1118 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
1119 code = pr_SNameToId(aname, &id);
1122 /* 1=>Not-valid; 0=>Valid */
1123 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1127 /* clean up an access control list of its bad entries; return 1 if we made
1128 any changes to the list, and 0 otherwise */
1130 CleanAcl(struct Acl *aa, char *fname)
1132 struct AclEntry *te, **le, *ne;
1135 /* Don't correct DFS ACL's for now */
1139 /* prune out bad entries */
1140 changes = 0; /* count deleted entries */
1142 for(te = aa->pluslist; te; te=ne) {
1144 if (BadName(te->name, fname)) {
1154 le = &aa->minuslist;
1155 for(te = aa->minuslist; te; te=ne) {
1157 if (BadName(te->name, fname)) {
1171 /* clean up an acl to not have bogus entries */
1173 CleanACLCmd(struct cmd_syndesc *as, char *arock)
1177 struct ViceIoctl blob;
1179 struct cmd_item *ti;
1180 struct AclEntry *te;
1183 SetDotDefault(&as->parms[0].items);
1184 for(ti=as->parms[0].items; ti; ti=ti->next) {
1185 blob.out_size = MAXSIZE;
1188 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1190 Die(errno, ti->data);
1196 ta = ParseAcl(space);
1200 "%s: cleanacl is not supported for DFS access lists.\n",
1206 changes = CleanAcl(ta, ti->data);
1209 /* now set the acl */
1210 blob.in=AclToString(ta);
1211 blob.in_size = strlen(blob.in)+1;
1213 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1215 if (errno == EINVAL) {
1217 "%s: Invalid argument, possible reasons include\n",
1219 fprintf(stderr,"%s: File not in vice or\n", pn);
1221 "%s: Too many users on access control list or\n",
1224 Die(errno, ti->data);
1230 /* now list the updated acl */
1231 printf("Access list for %s is now\n", ti->data);
1232 if (ta->nplus > 0) {
1234 printf("Normal rights:\n");
1235 for(te = ta->pluslist;te;te=te->next) {
1236 printf(" %s ", te->name);
1237 PRights(te->rights, ta->dfs);
1241 if (ta->nminus > 0) {
1242 printf("Negative rights:\n");
1243 for(te = ta->minuslist;te;te=te->next) {
1244 printf(" %s ", te->name);
1245 PRights(te->rights, ta->dfs);
1252 printf("Access list for %s is fine.\n", ti->data);
1260 ListACLCmd(struct cmd_syndesc *as, char *arock)
1264 struct ViceIoctl blob;
1265 struct AclEntry *te;
1266 struct cmd_item *ti;
1267 int idf = getidf(as, parm_listacl_id);
1270 SetDotDefault(&as->parms[0].items);
1271 for(ti=as->parms[0].items; ti; ti=ti->next) {
1273 blob.out_size = MAXSIZE;
1275 blob.in = blob.out = space;
1276 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1278 Die(errno, ti->data);
1282 ta = ParseAcl(space);
1285 printf("Access list for %s is\n", ti->data);
1288 printf("DFS access list for %s is\n", ti->data);
1291 printf("DFS initial directory access list of %s is\n", ti->data);
1294 printf("DFS initial file access list of %s is\n", ti->data);
1298 printf(" Default cell = %s\n", ta->cell);
1300 separator = ta->dfs? DFS_SEPARATOR : ' ';
1301 if (ta->nplus > 0) {
1303 printf("Normal rights:\n");
1304 for(te = ta->pluslist;te;te=te->next) {
1305 printf(" %s%c", te->name, separator);
1306 PRights(te->rights, ta->dfs);
1310 if (ta->nminus > 0) {
1311 printf("Negative rights:\n");
1312 for(te = ta->minuslist;te;te=te->next) {
1313 printf(" %s ", te->name);
1314 PRights(te->rights, ta->dfs);
1326 FlushVolumeCmd(struct cmd_syndesc *as, char *arock)
1329 struct ViceIoctl blob;
1330 struct cmd_item *ti;
1333 SetDotDefault(&as->parms[0].items);
1334 for(ti=as->parms[0].items; ti; ti=ti->next) {
1335 blob.in_size = blob.out_size = 0;
1336 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1338 fprintf(stderr, "Error flushing volume ");
1348 FlushCmd(struct cmd_syndesc *as, char *arock)
1351 struct ViceIoctl blob;
1352 struct cmd_item *ti;
1356 for(ti=as->parms[0].items; ti; ti=ti->next) {
1357 blob.in_size = blob.out_size = 0;
1358 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1360 if (errno == EMFILE) {
1361 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1364 fprintf(stderr, "%s: Error flushing file ", pn);
1374 /* all this command does is repackage its args and call SetVolCmd */
1376 SetQuotaCmd(struct cmd_syndesc *as, char *arock) {
1377 struct cmd_syndesc ts;
1379 /* copy useful stuff from our command slot; we may later have to reorder */
1380 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1381 return SetVolCmd(&ts, arock);
1385 SetVolCmd(struct cmd_syndesc *as, char *arock) {
1387 struct ViceIoctl blob;
1388 struct cmd_item *ti;
1389 struct VolumeStatus *status;
1390 char *motd, *offmsg, *input;
1393 SetDotDefault(&as->parms[0].items);
1394 for(ti=as->parms[0].items; ti; ti=ti->next) {
1396 blob.out_size = MAXSIZE;
1397 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1400 status = (VolumeStatus *)space;
1401 status->MinQuota = status->MaxQuota = -1;
1402 motd = offmsg = NULL;
1403 if (as->parms[1].items) {
1404 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1406 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1411 if (as->parms[2].items)
1412 motd = as->parms[2].items->data;
1413 if (as->parms[3].items)
1414 offmsg = as->parms[3].items->data;
1415 input = (char *)status + sizeof(*status);
1416 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1418 if (strlen(offmsg) >= VMSGSIZE) {
1419 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1424 strcpy(input,offmsg);
1425 blob.in_size += strlen(offmsg);
1426 input += strlen(offmsg) + 1;
1430 if (strlen(motd) >= VMSGSIZE) {
1431 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1436 blob.in_size += strlen(motd);
1437 input += strlen(motd) + 1;
1440 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1450 * Why is VenusFid declared in the kernel-only section of afs.h,
1451 * if it's the exported interface of the (UNIX) cache manager?
1460 ExamineCmd(struct cmd_syndesc *as, char *arock)
1463 struct ViceIoctl blob;
1464 struct cmd_item *ti;
1465 struct VolumeStatus *status;
1466 char *name, *offmsg, *motd;
1469 SetDotDefault(&as->parms[0].items);
1470 for(ti=as->parms[0].items; ti; ti=ti->next) {
1472 struct VenusFid vfid;
1475 blob.out_size = MAXSIZE;
1478 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1480 Die(errno, ti->data);
1484 status = (VolumeStatus *)space;
1485 name = (char *)status + sizeof(*status);
1486 offmsg = name + strlen(name) + 1;
1487 motd = offmsg + strlen(offmsg) + 1;
1490 blob.out_size = sizeof(struct VenusFid);
1491 blob.out = (char *) &vfid;
1492 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1493 printf("File %s (%u.%u.%u) contained in volume %u\n",
1494 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1498 PrintStatus(status, name, motd, offmsg);
1504 ListQuotaCmd(struct cmd_syndesc *as, char *arock)
1507 struct ViceIoctl blob;
1508 struct cmd_item *ti;
1509 struct VolumeStatus *status;
1514 printf("%-25s%-10s%-10s%-7s%-13s\n",
1515 "Volume Name", " Quota", " Used", " %Used", " Partition");
1516 SetDotDefault(&as->parms[0].items);
1517 for(ti=as->parms[0].items; ti; ti=ti->next) {
1519 blob.out_size = MAXSIZE;
1522 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1524 Die(errno, ti->data);
1528 status = (VolumeStatus *)space;
1529 name = (char *)status + sizeof(*status);
1530 QuickPrintStatus(status, name);
1536 WhereIsCmd(struct cmd_syndesc *as, char *arock)
1539 struct ViceIoctl blob;
1540 struct cmd_item *ti;
1546 SetDotDefault(&as->parms[0].items);
1547 for(ti=as->parms[0].items; ti; ti=ti->next) {
1549 blob.out_size = MAXSIZE;
1552 memset(space, 0, sizeof(space));
1553 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1555 Die(errno, ti->data);
1559 hosts = (afs_int32 *) space;
1560 printf("File %s is on host%s ", ti->data,
1561 (hosts[0] && !hosts[1]) ? "": "s");
1562 for(j=0; j<MAXHOSTS; j++) {
1565 tp = hostutil_GetNameByINet(hosts[j]);
1575 DiskFreeCmd(struct cmd_syndesc *as, char *arock)
1578 struct ViceIoctl blob;
1579 struct cmd_item *ti;
1581 struct VolumeStatus *status;
1584 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1585 " used", " avail", " %used");
1586 SetDotDefault(&as->parms[0].items);
1587 for(ti=as->parms[0].items; ti; ti=ti->next) {
1589 blob.out_size = MAXSIZE;
1592 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1594 Die(errno, ti->data);
1598 status = (VolumeStatus *)space;
1599 name = (char *)status + sizeof(*status);
1600 QuickPrintSpace(status, name);
1606 QuotaCmd(struct cmd_syndesc *as, char *arock)
1609 struct ViceIoctl blob;
1610 struct cmd_item *ti;
1612 struct VolumeStatus *status;
1615 SetDotDefault(&as->parms[0].items);
1616 for(ti=as->parms[0].items; ti; ti=ti->next) {
1618 blob.out_size = MAXSIZE;
1621 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1623 Die(errno, ti->data);
1627 status = (VolumeStatus *)space;
1628 if (status->MaxQuota)
1629 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1632 printf("%2.0f%% of quota used.\n", quotaPct);
1638 ListMountCmd(struct cmd_syndesc *as, char *arock)
1641 struct ViceIoctl blob;
1642 struct cmd_item *ti;
1643 char orig_name[1024]; /*Original name, may be modified*/
1644 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1645 char parent_dir[1024]; /*Parent directory of true name*/
1646 char *last_component; /*Last component of true name*/
1648 struct stat statbuff; /*Buffer for status info*/
1649 #endif /* not WIN32 */
1651 int link_chars_read; /*Num chars read in readlink()*/
1652 #endif /* not WIN32 */
1653 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1656 for(ti=as->parms[0].items; ti; ti=ti->next) {
1660 strcpy(orig_name, ti->data);
1661 #else /* not WIN32 */
1662 sprintf(orig_name, "%s%s",
1663 (ti->data[0] == '/') ? "" : "./",
1665 #endif /* not WIN32 */
1668 if (lstat(orig_name, &statbuff) < 0) {
1669 /* if lstat fails, we should still try the pioctl, since it
1670 * may work (for example, lstat will fail, but pioctl will
1671 * work if the volume of offline (returning ENODEV). */
1672 statbuff.st_mode = S_IFDIR; /* lie like pros */
1676 * The lstat succeeded. If the given file is a symlink, substitute
1677 * the file name with the link name.
1679 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1682 * Read name of resolved file.
1684 link_chars_read = readlink(orig_name, true_name, 1024);
1685 if (link_chars_read <= 0) {
1687 "%s: Can't read target name for '%s' symbolic link!\n",
1694 * Add a trailing null to what was read, bump the length.
1696 true_name[link_chars_read++] = 0;
1699 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1700 * have to create a full pathname using the original name and the
1701 * relative symlink name. Find the rightmost slash in the original
1702 * name (we know there is one) and splice in the symlink value.
1704 if (true_name[0] != '\\') {
1705 last_component = (char *) strrchr(orig_name, '\\');
1706 strcpy(++last_component, true_name);
1707 strcpy(true_name, orig_name);
1710 strcpy(true_name, orig_name);
1712 strcpy(true_name, orig_name);
1716 * Find rightmost slash, if any.
1719 last_component = (char *) strrchr(true_name, '\\');
1720 if (!last_component)
1722 last_component = (char *) strrchr(true_name, '/');
1723 if (last_component) {
1725 * Found it. Designate everything before it as the parent directory,
1726 * everything after it as the final component.
1728 strncpy(parent_dir, true_name, last_component - true_name + 1);
1729 parent_dir[last_component - true_name + 1] = 0;
1730 last_component++; /*Skip the slash*/
1733 * No slash appears in the given file name. Set parent_dir to the current
1734 * directory, and the last component as the given name.
1736 fs_ExtractDriveLetter(true_name, parent_dir);
1737 strcat(parent_dir, ".");
1738 last_component = true_name;
1739 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1742 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1743 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
1744 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
1749 blob.in = last_component;
1750 blob.in_size = strlen(last_component)+1;
1751 blob.out_size = MAXSIZE;
1753 memset(space, 0, MAXSIZE);
1755 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1758 printf("'%s' is a %smount point for volume '%s'\n",
1760 (thru_symlink ? "symbolic link, leading to a " : ""),
1764 if (errno == EINVAL) {
1765 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
1767 Die(errno, (ti->data ? ti->data : parent_dir));
1776 MakeMountCmd(struct cmd_syndesc *as, char *arock)
1779 char *cellName, *volName, *tmpName;
1781 char localCellName[1000];
1782 #else /* not WIN32 */
1783 struct afsconf_cell info;
1784 struct vldbentry vldbEntry;
1785 #endif /* not WIN32 */
1786 struct ViceIoctl blob;
1793 if (as->parms[5].items && !as->parms[2].items) {
1794 fprintf(stderr,"%s: must provide cell when creating cellular mount point.\n", pn);
1799 if (as->parms[2].items) /* cell name specified */
1800 cellName = as->parms[2].items->data;
1803 volName = as->parms[1].items->data;
1805 if (strlen(volName) >= 64) {
1806 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
1810 /* Check for a cellname in the volume specification, and complain
1811 * if it doesn't match what was specified with -cell */
1812 if (tmpName = strchr(volName, ':')) {
1815 if (strcasecmp(cellName,volName)) {
1816 fprintf(stderr,"fs: cellnames do not match.\n");
1821 volName = ++tmpName;
1824 parent = Parent(as->parms[0].items->data);
1825 if (!InAFS(parent)) {
1826 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
1830 if ( IsFreelanceRoot(parent) && !IsAdmin() ) {
1831 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
1837 blob.out_size = MAXSIZE;
1839 code = pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME, &blob, 1);
1843 strcpy(localCellName, (cellName? cellName : space));
1844 #else /* not win32 */
1845 code = GetCellName(cellName?cellName:space, &info);
1849 if (!(as->parms[4].items)) {
1850 /* not fast, check which cell the mountpoint is being created in */
1852 /* not fast, check name with VLDB */
1854 code = VLDBInit(1, &info);
1856 /* make the check. Don't complain if there are problems with init */
1857 code = ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, &vldbEntry);
1858 if (code == VL_NOENT) {
1859 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
1860 pn, volName, cellName ? cellName : space);
1864 #endif /* not WIN32 */
1866 if (as->parms[3].items) /* if -rw specified */
1871 /* cellular mount point, prepend cell prefix */
1873 strcat(space, localCellName);
1874 #else /* not WIN32 */
1875 strcat(space, info.name);
1876 #endif /* not WIN32 */
1879 strcat(space, volName); /* append volume name */
1880 strcat(space, "."); /* stupid convention; these end with a period */
1882 /* create symlink with a special pioctl for Windows NT, since it doesn't
1883 * have a symlink system call.
1886 blob.in_size = 1 + strlen(space);
1889 code = pioctl(as->parms[0].items->data, VIOC_AFS_CREATE_MT_PT, &blob, 0);
1890 #else /* not WIN32 */
1891 code = symlink(space, as->parms[0].items->data);
1892 #endif /* not WIN32 */
1894 Die(errno, as->parms[0].items->data);
1901 * Delete AFS mount points. Variables are used as follows:
1902 * tbuffer: Set to point to the null-terminated directory name of the mount point
1903 * (or ``.'' if none is provided)
1904 * tp: Set to point to the actual name of the mount point to nuke.
1907 RemoveMountCmd(struct cmd_syndesc *as, char *arock) {
1909 struct ViceIoctl blob;
1910 struct cmd_item *ti;
1912 char lsbuffer[1024];
1916 for(ti=as->parms[0].items; ti; ti=ti->next) {
1918 tp = (char *) strrchr(ti->data, '\\');
1920 tp = (char *) strrchr(ti->data, '/');
1922 strncpy(tbuffer, ti->data, code=tp-ti->data+1); /* the dir name */
1924 tp++; /* skip the slash */
1926 fs_ExtractDriveLetter(ti->data, tbuffer);
1927 strcat(tbuffer, ".");
1929 fs_StripDriveLetter(tp, tp, 0);
1932 blob.in_size = strlen(tp)+1;
1933 blob.out = lsbuffer;
1934 blob.out_size = sizeof(lsbuffer);
1935 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1937 if (errno == EINVAL) {
1938 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
1940 Die(errno, ti->data);
1943 continue; /* don't bother trying */
1946 if ( IsFreelanceRoot(Parent(ti->data)) && !IsAdmin() ) {
1947 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
1949 continue; /* skip */
1954 blob.in_size = strlen(tp)+1;
1955 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1957 Die(errno, ti->data);
1968 CheckServersCmd(struct cmd_syndesc *as, char *arock)
1971 struct ViceIoctl blob;
1975 struct afsconf_cell info;
1976 struct chservinfo checkserv;
1978 memset(&checkserv, 0, sizeof(struct chservinfo));
1979 blob.in_size=sizeof(struct chservinfo);
1980 blob.in=(caddr_t)&checkserv;
1982 blob.out_size = MAXSIZE;
1984 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1986 /* prepare flags for checkservers command */
1987 temp = 2; /* default to checking local cell only */
1988 if (as->parms[2].items)
1989 temp |= 1; /* set fast flag */
1990 if (as->parms[1].items)
1991 temp &= ~2; /* turn off local cell check */
1993 checkserv.magic = 0x12345678; /* XXX */
1994 checkserv.tflags=temp;
1996 /* now copy in optional cell name, if specified */
1997 if (as->parms[0].items) {
1998 code = GetCellName(as->parms[0].items->data, &info);
2002 strcpy(checkserv.tbuffer,info.name);
2003 checkserv.tsize=strlen(info.name)+1;
2005 strcpy(checkserv.tbuffer,"\0");
2009 if(as->parms[3].items) {
2010 checkserv.tinterval=atol(as->parms[3].items->data);
2013 if(checkserv.tinterval<0) {
2014 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2015 checkserv.tinterval=0;
2016 } else if(checkserv.tinterval> 600) {
2017 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2018 checkserv.tinterval=600; /* 10 min max interval */
2021 checkserv.tinterval = -1; /* don't change current interval */
2024 if ( checkserv.tinterval != 0 ) {
2027 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2032 fprintf (stderr,"Permission denied: requires root access.\n");
2038 code = pioctl(0, VIOCCKSERV, &blob, 1);
2040 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2041 printf("Must be root to change -interval\n");
2047 memcpy(&temp, space, sizeof(afs_int32));
2048 if (checkserv.tinterval >= 0) {
2049 if (checkserv.tinterval > 0)
2050 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2051 checkserv.tinterval, temp);
2053 printf("The current down server probe interval is %d secs\n", temp);
2057 printf("All servers are running.\n");
2059 printf("These servers unavailable due to network or server problems: ");
2060 for(j=0; j < MAXHOSTS; j++) {
2061 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2064 tp = hostutil_GetNameByINet(temp);
2074 MessagesCmd(struct cmd_syndesc *as, char *arock)
2077 struct ViceIoctl blob;
2078 struct gaginfo gagflags;
2079 struct cmd_item *show;
2081 memset(&gagflags, 0, sizeof(struct gaginfo));
2082 blob.in_size = sizeof(struct gaginfo);
2083 blob.in = (caddr_t ) &gagflags;
2084 blob.out_size = MAXSIZE;
2086 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2088 if (show = as->parms[0].items) {
2089 if (!strcasecmp (show->data, "user"))
2090 gagflags.showflags |= GAGUSER;
2091 else if (!strcasecmp (show->data, "console"))
2092 gagflags.showflags |= GAGCONSOLE;
2093 else if (!strcasecmp (show->data, "all"))
2094 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2095 else if (!strcasecmp (show->data, "none"))
2099 "unrecognized flag %s: must be in {user,console,all,none}\n",
2108 code = pioctl(0, VIOC_GAG, &blob, 1);
2117 CheckVolumesCmd(struct cmd_syndesc *as, char *arock)
2120 struct ViceIoctl blob;
2124 code = pioctl(0, VIOCCKBACK, &blob, 1);
2129 printf("All volumeID/name mappings checked.\n");
2135 SetCacheSizeCmd(struct cmd_syndesc *as, char *arock)
2138 struct ViceIoctl blob;
2143 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2148 fprintf (stderr,"Permission denied: requires root access.\n");
2153 if (!as->parms[0].items && !as->parms[1].items) {
2154 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2157 if (as->parms[0].items) {
2158 code = util_GetInt32(as->parms[0].items->data, &temp);
2160 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2165 blob.in = (char *) &temp;
2166 blob.in_size = sizeof(afs_int32);
2168 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2170 Die(errno, (char *) 0);
2174 printf("New cache size set.\n");
2178 #define MAXGCSIZE 16
2180 GetCacheParmsCmd(struct cmd_syndesc *as, char *arock)
2183 struct ViceIoctl blob;
2184 afs_int32 parms[MAXGCSIZE];
2186 memset(parms, 0, sizeof(parms));
2189 blob.out_size = sizeof(parms);
2190 blob.out = (char *) parms;
2191 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2197 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2198 parms[1], parms[0]);
2199 if (parms[1] > parms[0])
2200 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2205 ListCellsCmd(struct cmd_syndesc *as, char *arock)
2208 afs_int32 i, j, *lp, magic, size;
2210 afs_int32 addr, maxa = OMAXHOSTS;
2211 struct ViceIoctl blob;
2214 resolve = !(as->parms[0].items); /* -numeric */
2216 for(i=0;i<1000;i++) {
2218 memcpy(tp, &i, sizeof(afs_int32));
2219 tp = (char *)(space + sizeof(afs_int32));
2220 lp = (afs_int32 *)tp;
2222 size = sizeof(afs_int32) + sizeof(afs_int32);
2223 blob.out_size = MAXSIZE;
2224 blob.in_size = sizeof(afs_int32);
2227 code = pioctl(0, VIOCGETCELL, &blob, 1);
2230 break; /* done with the list */
2235 memcpy(&magic, tp, sizeof(afs_int32));
2236 if (magic == 0x12345678) {
2238 tp += sizeof(afs_int32);
2240 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2241 for(j=0; j < maxa; j++) {
2242 char *name, tbuffer[20];
2244 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2249 name = hostutil_GetNameByINet(addr);
2252 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2253 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2256 printf(" %s", name);
2265 ListAliasesCmd(struct cmd_syndesc *as, char *arock)
2268 char *tp, *aliasName, *realName;
2269 struct ViceIoctl blob;
2273 memcpy(tp, &i, sizeof(afs_int32));
2274 blob.out_size = MAXSIZE;
2275 blob.in_size = sizeof(afs_int32);
2278 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2281 break; /* done with the list */
2287 tp += strlen(aliasName) + 1;
2289 printf("Alias %s for cell %s\n", aliasName, realName);
2295 CallBackRxConnCmd(struct cmd_syndesc *as, char *arock)
2298 struct ViceIoctl blob;
2299 struct cmd_item *ti;
2301 struct hostent *thp;
2305 ti = as->parms[0].items;
2308 thp = hostutil_GetHostByName(ti->data);
2310 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2313 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2315 hostAddr = 0; /* means don't set host */
2316 setp = 0; /* aren't setting host */
2319 /* now do operation */
2320 blob.in_size = sizeof(afs_int32);
2321 blob.out_size = sizeof(afs_int32);
2322 blob.in = (char *) &hostAddr;
2323 blob.out = (char *) &hostAddr;
2325 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2335 NewCellCmd(struct cmd_syndesc *as, char *arock)
2338 afs_int32 code, linkedstate=0, size=0, *lp;
2339 struct ViceIoctl blob;
2340 struct cmd_item *ti;
2341 char *tp, *cellname=0;
2342 struct hostent *thp;
2343 afs_int32 fsport = 0, vlport = 0;
2345 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
2347 lp = (afs_int32 *)tp;
2349 tp += sizeof(afs_int32);
2350 for(ti=as->parms[1].items; ti; ti=ti->next) {
2351 thp = hostutil_GetHostByName(ti->data);
2353 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2357 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2358 tp += sizeof(afs_int32);
2361 if (as->parms[2].items) {
2363 * Link the cell, for the purposes of volume location, to the specified
2366 cellname = as->parms[2].items->data;
2369 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2370 if (as->parms[3].items) {
2371 code = util_GetInt32(as->parms[3].items->data, &vlport);
2373 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2377 if (as->parms[4].items) {
2378 code = util_GetInt32(as->parms[4].items->data, &fsport);
2380 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2385 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
2386 lp = (afs_int32 *)tp;
2390 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2391 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2392 tp = (char *)(space + size);
2394 strcpy(tp, cellname);
2395 size += strlen(cellname) + 1;
2397 blob.in_size = size;
2400 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2406 struct ViceIoctl blob;
2409 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2414 blob.in = (char *) 0;
2415 blob.out_size = MAXSIZE;
2418 code = pioctl((char *) 0, VIOCNEWCELL, &blob, 1);
2421 Die(errno, (char *) 0);
2425 printf("Cell servers information refreshed\n");
2432 NewAliasCmd(struct cmd_syndesc *as, char *arock)
2435 struct ViceIoctl blob;
2437 char *aliasName, *realName;
2439 /* Setup and do the NEWALIAS pioctl call */
2440 aliasName = as->parms[0].items->data;
2441 realName = as->parms[1].items->data;
2443 strcpy(tp, aliasName);
2444 tp += strlen(aliasName) + 1;
2445 strcpy(tp, realName);
2446 tp += strlen(realName) + 1;
2448 blob.in_size = tp - space;
2452 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2454 if (errno == EEXIST) {
2456 "%s: cell name `%s' in use by an existing cell.\n", pn,
2468 WhichCellCmd(struct cmd_syndesc *as, char *arock)
2471 struct cmd_item *ti;
2473 char cell[MAXCELLCHARS]="";
2475 SetDotDefault(&as->parms[0].items);
2476 for(ti=as->parms[0].items; ti; ti=ti->next) {
2477 code = GetCell(ti->data, cell);
2479 if (errno == ENOENT)
2480 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2482 Die(errno, ti->data);
2486 printf("File %s lives in cell '%s'\n", ti->data, cell);
2492 WSCellCmd(struct cmd_syndesc *as, char *arock)
2495 struct ViceIoctl blob;
2499 blob.out_size = MAXSIZE;
2502 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2509 printf("This workstation belongs to cell '%s'\n", space);
2515 PrimaryCellCmd(struct cmd_syndesc *as, char *arock)
2517 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2523 MonitorCmd(struct cmd_syndesc *as, char *arock)
2526 struct ViceIoctl blob;
2527 struct cmd_item *ti;
2529 struct hostent *thp;
2533 ti = as->parms[0].items;
2537 if (!strcmp(ti->data, "off")) {
2538 hostAddr = 0xffffffff;
2540 thp = hostutil_GetHostByName(ti->data);
2542 if (!strcmp(ti->data, "localhost")) {
2543 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2544 hostAddr = htonl(0x7f000001);
2546 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2550 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2554 hostAddr = 0; /* means don't set host */
2555 setp = 0; /* aren't setting host */
2558 /* now do operation */
2559 blob.in_size = sizeof(afs_int32);
2560 blob.out_size = sizeof(afs_int32);
2561 blob.in = (char *) &hostAddr;
2562 blob.out = (char *) &hostAddr;
2563 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2569 printf("%s: new monitor host set.\n", pn);
2571 /* now decode old address */
2572 if (hostAddr == 0xffffffff) {
2573 printf("Cache monitoring is currently disabled.\n");
2575 tp = hostutil_GetNameByINet(hostAddr);
2576 printf("Using host %s for monitor services.\n", tp);
2583 SysNameCmd(struct cmd_syndesc *as, char *arock)
2586 struct ViceIoctl blob;
2587 struct cmd_item *ti;
2588 char *input = space;
2591 ti = as->parms[0].items;
2595 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2600 fprintf (stderr,"Permission denied: requires root access.\n");
2608 blob.out_size = MAXSIZE;
2609 blob.in_size = sizeof(afs_int32);
2610 memcpy(input, &setp, sizeof(afs_int32));
2611 input += sizeof(afs_int32);
2612 for (; ti; ti = ti->next) {
2614 blob.in_size += strlen(ti->data) + 1;
2615 if (blob.in_size > MAXSIZE) {
2616 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2617 setp > 1 ? "s" : "");
2620 strcpy(input, ti->data);
2621 input += strlen(ti->data);
2624 memcpy(space, &setp, sizeof(afs_int32));
2625 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2631 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2636 memcpy(&setp, input, sizeof(afs_int32));
2637 input += sizeof(afs_int32);
2639 fprintf(stderr,"No sysname name value was found\n");
2643 printf("Current sysname%s is", setp > 1 ? " list" : "");
2644 for (; setp > 0; --setp ) {
2645 printf(" \'%s\'", input);
2646 input += strlen(input) + 1;
2652 static char *exported_types[] = {"null", "nfs", ""};
2653 static int ExportAfsCmd(struct cmd_syndesc *as, char *arock)
2656 struct ViceIoctl blob;
2657 struct cmd_item *ti;
2658 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
2659 int exportcall, pwsync = 0, smounts = 0;
2663 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2668 fprintf (stderr,"Permission denied: requires root access.\n");
2673 ti = as->parms[0].items;
2674 if (strcmp(ti->data, "nfs") == 0)
2675 type = 0x71; /* NFS */
2678 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2681 ti = as->parms[1].items;
2683 if (strcmp(ti->data, "on") == 0)
2685 else if (strcmp(ti->data, "off") == 0)
2688 fprintf(stderr, "Illegal argument %s\n", ti->data);
2693 if (ti = as->parms[2].items) { /* -noconvert */
2694 if (strcmp(ti->data, "on") == 0)
2696 else if (strcmp(ti->data, "off") == 0)
2699 fprintf(stderr, "Illegal argument %s\n", ti->data);
2703 if (ti = as->parms[3].items) { /* -uidcheck */
2704 if (strcmp(ti->data, "on") == 0)
2706 else if (strcmp(ti->data, "off") == 0)
2709 fprintf(stderr, "Illegal argument %s\n", ti->data);
2713 if (ti = as->parms[4].items) { /* -submounts */
2714 if (strcmp(ti->data, "on") == 0)
2716 else if (strcmp(ti->data, "off") == 0)
2719 fprintf(stderr, "Illegal argument %s\n", ti->data);
2723 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2726 blob.in = (char *) &exportcall;
2727 blob.in_size = sizeof(afs_int32);
2728 blob.out = (char *) &exportcall;
2729 blob.out_size = sizeof(afs_int32);
2730 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2732 if (errno == ENODEV) {
2734 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
2741 if (exportcall & 1) {
2742 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
2743 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
2744 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
2745 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
2747 printf("'%s' translator is disabled\n", exported_types[type]);
2756 GetCellCmd(struct cmd_syndesc *as, char *arock)
2759 struct ViceIoctl blob;
2760 struct afsconf_cell info;
2761 struct cmd_item *ti;
2768 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
2769 for(ti=as->parms[0].items; ti; ti=ti->next) {
2771 blob.out_size = sizeof(args);
2772 blob.out = (caddr_t) &args;
2773 code = GetCellName(ti->data, &info);
2778 blob.in_size = 1+strlen(info.name);
2779 blob.in = info.name;
2780 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2782 if (errno == ENOENT)
2783 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
2785 Die(errno, info.name);
2789 printf("Cell %s status: ", info.name);
2795 printf("no setuid allowed");
2797 printf("setuid allowed");
2799 printf(", using old VLDB");
2805 static int SetCellCmd(struct cmd_syndesc *as, char *arock)
2808 struct ViceIoctl blob;
2809 struct afsconf_cell info;
2810 struct cmd_item *ti;
2818 /* Check arguments. */
2819 if (as->parms[1].items && as->parms[2].items) {
2820 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2824 /* figure stuff to set */
2830 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2835 fprintf (stderr,"Permission denied: requires root access.\n");
2840 if (! as->parms[1].items)
2841 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
2843 /* set stat for all listed cells */
2844 for(ti=as->parms[0].items; ti; ti=ti->next) {
2846 code = GetCellName(ti->data, &info);
2851 strcpy(args.cname, info.name);
2852 blob.in_size = sizeof(args);
2853 blob.in = (caddr_t) &args;
2855 blob.out = (caddr_t) 0;
2856 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2858 Die(errno, info.name); /* XXX added cell name to Die() call */
2867 GetCellName(char *cellNamep, struct afsconf_cell *infop)
2869 strcpy(infop->name, cellNamep);
2874 VLDBInit(int noAuthFlag, struct afsconf_cell *infop)
2878 #else /* not WIN32 */
2880 GetCellName(char *cellName, struct afsconf_cell *info)
2882 struct afsconf_dir *tdir;
2885 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_CLIENTNAME);
2888 "Could not process files in configuration directory (%s).\n",
2889 AFSDIR_CLIENT_ETC_CLIENTNAME);
2893 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2895 fprintf(stderr,"fs: cell %s not in %s/CellServDB\n", cellName,
2896 AFSDIR_CLIENT_ETC_CLIENTNAME);
2905 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2909 code = ugen_ClientInit(noAuthFlag, AFSDIR_CLIENT_ETC_DIRPATH,
2910 info->name, 0, &uclient,
2911 NULL, pn, rxkad_clear,
2912 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
2913 0, 0, USER_SERVICE_ID);
2917 #endif /* not WIN32 */
2919 static struct ViceIoctl gblob;
2920 static int debug = 0;
2922 * here follow some routines in suport of the setserverprefs and
2923 * getserverprefs commands. They are:
2924 * SetPrefCmd "top-level" routine
2925 * addServer adds a server to the list of servers to be poked into the
2926 * kernel. Will poke the list into the kernel if it threatens
2928 * pokeServers pokes the existing list of servers and ranks into the kernel
2929 * GetPrefCmd reads the Cache Manager's current list of server ranks
2938 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2940 ssp = (cm_SSetPref_t *)space;
2941 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2947 * returns -1 if error message printed,
2949 * errno value if error and no error message printed
2956 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2957 if (code && (errno == EINVAL)) {
2958 struct setspref *ssp;
2959 ssp = (struct setspref *)gblob.in;
2960 if (!(ssp->flags & DBservers)) {
2961 gblob.in = (void *)&(ssp->servers[0]);
2962 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2963 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2964 return code ? errno : 0;
2967 "This cache manager does not support VL server preferences.\n");
2971 return code ? errno : 0;
2977 addServer(char *name, unsigned short rank)
2982 struct hostent *thostent;
2986 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2988 #define MAXUSHORT ((unsigned short) ~0)
2993 thostent = hostutil_GetHostByName(name);
2995 fprintf (stderr, "%s: couldn't resolve name.\n", name);
2999 ssp = (cm_SSetPref_t *)(gblob.in);
3001 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3002 code = pokeServers();
3003 ssp->num_servers = 0;
3006 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3007 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3008 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3009 gblob.in_size += sizeof(cm_SPref_t);
3012 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3018 * returns -1 if error message printed,
3020 * errno value if error and no error message printed
3023 addServer(char *name, afs_int32 rank)
3026 struct setspref *ssp;
3028 struct hostent *thostent;
3034 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3036 #define MAXUSHORT ((unsigned short) ~0)
3040 thostent = hostutil_GetHostByName(name);
3042 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3046 ssp = (struct setspref *)(gblob.in);
3048 for (t = 0; thostent->h_addr_list[t]; t++) {
3049 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3050 code = pokeServers();
3053 ssp->num_servers = 0;
3056 sp = (struct spref *)(gblob.in + gblob.in_size);
3057 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3058 sizeof(afs_uint32));
3059 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3060 gblob.in_size += sizeof(struct spref);
3064 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3065 name, sp->rank, sp->server.s_addr);
3073 static BOOL IsWindowsNT (void)
3075 static BOOL fChecked = FALSE;
3076 static BOOL fIsWinNT = FALSE;
3080 OSVERSIONINFO Version;
3084 memset (&Version, 0x00, sizeof(Version));
3085 Version.dwOSVersionInfoSize = sizeof(Version);
3087 if (GetVersionEx (&Version))
3089 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3099 SetPrefCmd(struct cmd_syndesc *as, char * arock)
3103 struct cmd_item *ti;
3108 ssp = (cm_SSetPref_t *)space;
3110 ssp->num_servers = 0;
3111 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
3114 gblob.out_size = MAXSIZE;
3117 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3123 ti = as->parms[2].items; /* -file */
3125 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3126 if (!(infd = fopen(ti->data,"r" ))) {
3128 Die(errno,ti->data);
3131 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3132 code = addServer (name, (unsigned short) rank);
3136 ti = as->parms[3].items; /* -stdin */
3138 while ( scanf("%79s%ld", name, &rank) != EOF) {
3139 code = addServer (name, (unsigned short) rank);
3143 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3148 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3150 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3154 code = pokeServers();
3156 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3158 ssp = (cm_SSetPref_t *)space;
3159 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
3161 ssp->flags = CM_SPREF_VLONLY;
3162 ssp->num_servers = 0;
3164 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3169 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3171 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3176 if (as->parms[1].items) {
3178 printf("now poking vlservers\n");
3179 code = pokeServers();
3189 SetPrefCmd(struct cmd_syndesc *as, char *arock)
3193 struct cmd_item *ti;
3196 struct setspref *ssp;
3197 int error = 0; /* -1 means error message printed,
3198 * >0 means errno value for unprinted message */
3200 ssp = (struct setspref *)space;
3202 ssp->num_servers = 0;
3203 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3206 gblob.out_size = MAXSIZE;
3210 fprintf(stderr, "Permission denied: requires root access.\n");
3214 ti = as->parms[2].items; /* -file */
3217 fprintf(stderr, "opening file %s\n", ti->data);
3218 if (!(infd = fopen(ti->data, "r"))) {
3222 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3223 code = addServer(name, (unsigned short)rank);
3230 ti = as->parms[3].items; /* -stdin */
3232 while (scanf("%79s%ld", name, &rank) != EOF) {
3233 code = addServer(name, (unsigned short)rank);
3239 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3244 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3248 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3252 code = pokeServers();
3256 printf("now working on vlservers, code=%d\n", code);
3258 ssp = (struct setspref *)space;
3259 ssp->flags = DBservers;
3260 ssp->num_servers = 0;
3261 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3264 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3269 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3273 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3278 if (as->parms[1].items) {
3280 printf("now poking vlservers\n");
3281 code = pokeServers();
3289 return error ? 1 : 0;
3295 GetPrefCmd(struct cmd_syndesc *as, char *arock)
3298 struct cmd_item *ti;
3299 char *name, tbuffer[20];
3304 struct ViceIoctl blob;
3305 struct cm_SPrefRequest *in;
3306 struct cm_SPrefInfo *out;
3310 ti = as->parms[0].items; /* -file */
3312 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3313 if (!(outfd = freopen(ti->data,"w",stdout))) {
3314 Die(errno,ti->data);
3319 ti = as->parms[1].items; /* -numeric */
3321 ti = as->parms[2].items; /* -vlservers */
3322 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3323 /* ti = as->parms[3].items; -cell */
3325 in = (struct cm_SPrefRequest *)space;
3329 blob.in_size=sizeof(struct cm_SPrefRequest);
3330 blob.in = (char *)in;
3332 blob.out_size = MAXSIZE;
3334 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3335 in->flags = vlservers;
3337 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3339 perror("getserverprefs pioctl");
3343 out = (struct cm_SPrefInfo *) blob.out;
3345 for (i=0;i<out->num_servers;i++) {
3347 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3350 addr = ntohl(out->servers[i].host.s_addr);
3351 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3352 (addr>>8) & 0xff, addr & 0xff);
3355 printf ("%-50s %5u\n",name,out->servers[i].rank);
3358 in->offset = out->next_offset;
3360 } while (!code && out->next_offset > 0);
3366 GetPrefCmd(struct cmd_syndesc *as, char *arock)
3369 struct cmd_item *ti;
3370 char *name, tbuffer[20];
3371 afs_int32 rank, addr;
3375 struct ViceIoctl blob;
3376 struct sprefrequest *in;
3377 struct sprefinfo *out;
3380 ti = as->parms[0].items; /* -file */
3383 fprintf(stderr, "opening file %s\n", ti->data);
3384 if (!(outfd = freopen(ti->data, "w", stdout))) {
3390 ti = as->parms[1].items; /* -numeric */
3392 ti = as->parms[2].items; /* -vlservers */
3393 vlservers |= (ti ? DBservers : 0);
3394 /* ti = as->parms[3].items; -cell */
3396 in = (struct sprefrequest *)space;
3400 blob.in_size = sizeof(struct sprefrequest);
3401 blob.in = (char *)in;
3403 blob.out_size = MAXSIZE;
3406 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3407 in->flags = vlservers;
3409 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3411 perror("getserverprefs pioctl");
3415 out = (struct sprefinfo *)blob.out;
3417 for (i = 0; i < out->num_servers; i++) {
3419 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3421 addr = ntohl(out->servers[i].server.s_addr);
3422 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3423 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3426 printf("%-50s %5u\n", name, out->servers[i].rank);
3429 in->offset = out->next_offset;
3430 } while (out->next_offset > 0);
3437 TraceCmd(struct cmd_syndesc *asp, char *arock)
3440 struct ViceIoctl blob;
3446 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3451 fprintf (stderr,"Permission denied: requires root access.\n");
3456 if ((asp->parms[0].items && asp->parms[1].items)) {
3457 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
3461 /* determine if we're turning this tracing on or off */
3463 if (asp->parms[0].items)
3464 inValue = 3; /* enable */
3465 else if (asp->parms[1].items)
3466 inValue = 2; /* disable */
3467 if (asp->parms[2].items)
3468 inValue |= 4; /* do reset */
3469 if (asp->parms[3].items)
3470 inValue |= 8; /* dump */
3472 blob.in_size = sizeof(long);
3473 blob.in = (char *) &inValue;
3474 blob.out_size = sizeof(long);
3475 blob.out = (char *) &outValue;
3477 code = pioctl(NULL, VIOC_TRACECTL, &blob, 1);
3484 printf("AFS tracing enabled.\n");
3486 printf("AFS tracing disabled.\n");
3491 static void sbusage(void)
3493 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
3494 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
3497 /* fs sb -kbytes 9999 -files *.o -default 64 */
3499 StoreBehindCmd(struct cmd_syndesc *as, char *arock)
3502 struct ViceIoctl blob;
3503 struct cmd_item *ti;
3504 struct sbstruct tsb, tsb2;
3512 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3517 tsb.sb_thisfile = -1;
3518 ti = as->parms[0].items; /* -kbytes */
3520 if (!as->parms[1].items) {
3521 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3525 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3526 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3527 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3533 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3534 ti = as->parms[2].items; /* -allfiles */
3536 allfiles = strtol(ti->data, &t, 10) * 1024;
3537 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3538 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3544 /* -verbose or -file only or no options */
3545 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3546 || (!as->parms[0].items && !as->parms[1].items
3547 && !as->parms[2].items))
3550 blob.in = (char *)&tsb;
3551 blob.out = (char *)&tsb2;
3552 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3553 memset(&tsb2, 0, sizeof(tsb2));
3555 /* once per -file */
3556 for (ti = as->parms[1].items; ti; ti = ti->next) {
3557 /* Do this solely to see if the file is there */
3558 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3560 Die(errno, ti->data);
3565 code = pioctl(ti->data, VIOC_STOREBEHIND, &blob, 1);
3567 Die(errno, ti->data);
3572 if (verbose && (blob.out_size == sizeof(tsb2))) {
3573 if (tsb2.sb_thisfile == -1) {
3574 fprintf(stdout, "Will store %s according to default.\n",
3578 "Will store up to %d kbytes of %s asynchronously.\n",
3579 (tsb2.sb_thisfile / 1024), ti->data);
3584 /* If no files - make at least one pioctl call, or
3585 * set the allfiles default if we need to.
3587 if (!as->parms[1].items || (allfiles != -1)) {
3588 tsb.sb_default = allfiles;
3589 code = pioctl(0, VIOC_STOREBEHIND, &blob, 1);
3591 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3596 /* Having no arguments also reports the default store asynchrony */
3597 if (verbose && (blob.out_size == sizeof(tsb2))) {
3598 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3599 (tsb2.sb_default / 1024));
3606 SetCryptCmd(struct cmd_syndesc *as, char *arock)
3608 afs_int32 code = 0, flag;
3609 struct ViceIoctl blob;
3614 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3619 tp = as->parms[0].items->data;
3620 if (strcmp(tp, "on") == 0)
3622 else if (strcmp(tp, "off") == 0)
3625 fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3629 blob.in = (char *) &flag;
3630 blob.in_size = sizeof(flag);
3632 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3639 GetCryptCmd(struct cmd_syndesc *as, char *arock)
3641 afs_int32 code = 0, flag;
3642 struct ViceIoctl blob;
3647 blob.out_size = sizeof(flag);
3650 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3656 memcpy(&flag, tp, sizeof(afs_int32));
3657 printf("Security level is currently ");
3659 printf("crypt (data security).\n");
3667 MemDumpCmd(struct cmd_syndesc *asp, char *arock)
3670 struct ViceIoctl blob;
3675 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3679 if ((asp->parms[0].items && asp->parms[1].items)) {
3680 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
3684 /* determine if we're turning this tracing on or off */
3685 if (asp->parms[0].items)
3686 inValue = 1; /* begin */
3687 else if (asp->parms[1].items)
3688 inValue = 0; /* end */
3691 blob.in_size = sizeof(long);
3692 blob.in = (char *) &inValue;
3693 blob.out_size = sizeof(long);
3694 blob.out = (char *) &outValue;
3696 code = pioctl(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
3703 printf("AFS memdump created.\n");
3706 printf("AFS memdump failed.\n");
3712 MiniDumpCmd(struct cmd_syndesc *asp, char *arock)
3716 SERVICE_STATUS status;
3717 SC_HANDLE hManager = NULL;
3718 SC_HANDLE hService = NULL;
3721 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3725 hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
3729 hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
3733 success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
3736 CloseServiceHandle(hService);
3737 CloseServiceHandle(hManager);
3739 printf("AFS minidump generated.\n");
3745 CloseServiceHandle(hService);
3747 CloseServiceHandle(hManager);
3749 printf("AFS minidump failed.\n");
3754 CSCPolicyCmd(struct cmd_syndesc *asp, char *arock)
3756 struct cmd_item *ti;
3761 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3765 for(ti=asp->parms[0].items; ti;ti=ti->next) {
3777 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
3778 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
3781 REG_OPTION_NON_VOLATILE,
3787 if ( hkCSCPolicy == NULL ) {
3788 fprintf (stderr,"Permission denied: requires Administrator access.\n");
3793 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3794 RegCloseKey(hkCSCPolicy);
3800 if (asp->parms[1].items)
3802 if (asp->parms[2].items)
3803 policy = "programs";
3804 if (asp->parms[3].items)
3805 policy = "documents";
3806 if (asp->parms[4].items)
3809 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, strlen(policy)+1);
3811 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
3812 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
3816 DWORD dwIndex, dwPolicies;
3817 char policyName[256];
3818 DWORD policyNameLen;
3823 /* list current csc policies */
3825 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
3826 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
3829 REG_OPTION_NON_VOLATILE,
3830 KEY_READ|KEY_QUERY_VALUE,
3835 RegQueryInfoKey( hkCSCPolicy,
3837 NULL, /* lpcClass */
3838 NULL, /* lpReserved */
3839 NULL, /* lpcSubKeys */
3840 NULL, /* lpcMaxSubKeyLen */
3841 NULL, /* lpcMaxClassLen */
3842 &dwPolicies, /* lpcValues */
3843 NULL, /* lpcMaxValueNameLen */
3844 NULL, /* lpcMaxValueLen */
3845 NULL, /* lpcbSecurityDescriptor */
3846 NULL /* lpftLastWriteTime */
3849 printf("Current CSC policies:\n");
3850 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
3852 policyNameLen = sizeof(policyName);
3853 policyLen = sizeof(policy);
3854 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
3855 &dwType, policy, &policyLen);
3857 printf(" %s = %s\n", policyName, policy);
3861 RegCloseKey(hkCSCPolicy);
3866 /* get clients interface addresses */
3868 GetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
3871 struct cmd_item *ti;
3873 struct ViceIoctl blob;
3874 struct sprefrequest *in;
3875 struct sprefinfo *out;
3877 in = (struct sprefrequest *)space;
3881 blob.in_size = sizeof(struct sprefrequest);
3882 blob.in = (char *)in;
3884 blob.out_size = MAXSIZE;
3887 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3888 /* returns addr in network byte order */
3889 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3891 perror("getClientInterfaceAddr pioctl");
3897 out = (struct sprefinfo *)blob.out;
3898 for (i = 0; i < out->num_servers; i++) {
3901 addr = ntohl(out->servers[i].server.s_addr);
3902 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3903 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3904 printf("%-50s\n", tbuffer);
3906 in->offset = out->next_offset;
3908 } while (out->next_offset > 0);
3914 SetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
3916 afs_int32 code, addr;
3917 struct cmd_item *ti;
3919 struct ViceIoctl blob;
3920 struct setspref *ssp;
3921 int sizeUsed = 0, i, flag;
3922 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3926 ssp = (struct setspref *)space;
3927 ssp->num_servers = 0;
3930 blob.out_size = MAXSIZE;
3933 fprintf(stderr, "Permission denied: requires root access.\n");
3937 /* extract all existing interface addresses */
3938 existNu = rx_getAllAddr(existingAddr, 1024);
3942 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3943 for (ti = as->parms[0].items; ti; ti = ti->next) {
3944 if (sizeUsed >= sizeof(space)) {
3945 fprintf(stderr, "No more space\n");
3948 addr = extractAddr(ti->data, 20); /* network order */
3949 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3950 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
3955 /* see if it is an address that really exists */
3956 for (flag = 0, i = 0; i < existNu; i++)
3957 if (existingAddr[i] == addr) {
3961 if (!flag) { /* this is an nonexistent address */
3962 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3966 /* copy all specified addr into ioctl buffer */
3967 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3968 printf("Adding 0x%08x\n", addr);
3970 sizeUsed += sizeof(struct spref);
3972 if (ssp->num_servers < 1) {
3973 fprintf(stderr, "No addresses specified\n");
3976 blob.in_size = sizeUsed - sizeof(struct spref);
3978 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3988 FlushMountCmd(struct cmd_syndesc *as, char *arock)
3991 struct ViceIoctl blob;
3992 struct cmd_item *ti;
3993 char orig_name[1024]; /*Original name, may be modified */
3994 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
3995 char parent_dir[1024]; /*Parent directory of true name */
3996 char *last_component; /*Last component of true name */
3997 struct stat statbuff; /*Buffer for status info */
3998 int link_chars_read; /*Num chars read in readlink() */
3999 int thru_symlink; /*Did we get to a mount point via a symlink? */
4002 for (ti = as->parms[0].items; ti; ti = ti->next) {
4005 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4008 if (lstat(orig_name, &statbuff) < 0) {
4009 /* if lstat fails, we should still try the pioctl, since it
4010 * may work (for example, lstat will fail, but pioctl will
4011 * work if the volume of offline (returning ENODEV). */
4012 statbuff.st_mode = S_IFDIR; /* lie like pros */
4016 * The lstat succeeded. If the given file is a symlink, substitute
4017 * the file name with the link name.
4019 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4022 * Read name of resolved file.
4024 link_chars_read = readlink(orig_name, true_name, 1024);
4025 if (link_chars_read <= 0) {
4027 "%s: Can't read target name for '%s' symbolic link!\n",
4034 * Add a trailing null to what was read, bump the length.
4036 true_name[link_chars_read++] = 0;
4039 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4040 * have to create a full pathname using the original name and the
4041 * relative symlink name. Find the rightmost slash in the original
4042 * name (we know there is one) and splice in the symlink value.
4044 if (true_name[0] != '/') {
4045 last_component = (char *)strrchr(orig_name, '/');
4046 strcpy(++last_component, true_name);
4047 strcpy(true_name, orig_name);
4050 strcpy(true_name, orig_name);
4053 * Find rightmost slash, if any.
4055 last_component = (char *)strrchr(true_name, '/');
4056 if (last_component) {
4058 * Found it. Designate everything before it as the parent directory,
4059 * everything after it as the final component.
4061 strncpy(parent_dir, true_name, last_component - true_name);
4062 parent_dir[last_component - true_name] = 0;
4063 last_component++; /*Skip the slash */
4066 * No slash appears in the given file name. Set parent_dir to the current
4067 * directory, and the last component as the given name.
4069 strcpy(parent_dir, ".");
4070 last_component = true_name;
4073 if (strcmp(last_component, ".") == 0
4074 || strcmp(last_component, "..") == 0) {
4076 "%s: you may not use '.' or '..' as the last component\n",
4078 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4084 blob.in = last_component;
4085 blob.in_size = strlen(last_component) + 1;
4087 memset(space, 0, MAXSIZE);
4089 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4092 if (errno == EINVAL) {
4093 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4095 Die(errno, (ti->data ? ti->data : parent_dir));
4104 RxStatProcCmd(struct cmd_syndesc *as, char *arock)
4107 afs_int32 flags = 0;
4108 struct ViceIoctl blob;
4109 struct cmd_item *ti;
4111 if (as->parms[0].items) { /* -enable */
4112 flags |= AFSCALL_RXSTATS_ENABLE;
4114 if (as->parms[1].items) { /* -disable */
4115 flags |= AFSCALL_RXSTATS_DISABLE;
4117 if (as->parms[2].items) { /* -clear */
4118 flags |= AFSCALL_RXSTATS_CLEAR;
4121 fprintf(stderr, "You must specify at least one argument\n");
4125 blob.in = (char *)&flags;
4126 blob.in_size = sizeof(afs_int32);
4129 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4139 RxStatPeerCmd(struct cmd_syndesc *as, char *arock)
4142 afs_int32 flags = 0;
4143 struct ViceIoctl blob;
4144 struct cmd_item *ti;
4146 if (as->parms[0].items) { /* -enable */
4147 flags |= AFSCALL_RXSTATS_ENABLE;
4149 if (as->parms[1].items) { /* -disable */
4150 flags |= AFSCALL_RXSTATS_DISABLE;
4152 if (as->parms[2].items) { /* -clear */
4153 flags |= AFSCALL_RXSTATS_CLEAR;
4156 fprintf(stderr, "You must specify at least one argument\n");
4160 blob.in = (char *)&flags;
4161 blob.in_size = sizeof(afs_int32);
4164 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4175 #include "AFS_component_version_number.c"
4178 main(int argc, char **argv)
4181 struct cmd_syndesc *ts;
4183 #ifdef AFS_AIX32_ENV
4185 * The following signal action for AIX is necessary so that in case of a
4186 * crash (i.e. core is generated) we can include the user's data section
4187 * in the core dump. Unfortunately, by default, only a partial core is
4188 * generated which, in many cases, isn't too useful.
4190 struct sigaction nsa;
4192 sigemptyset(&nsa.sa_mask);
4193 nsa.sa_handler = SIG_DFL;
4194 nsa.sa_flags = SA_FULLDUMP;
4195 sigaction(SIGSEGV, &nsa, NULL);
4200 WSAStartup(0x0101, &WSAjunk);
4203 /* try to find volume location information */
4207 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0,
4208 "get client network interface addresses");
4209 cmd_CreateAlias(ts, "gc");
4211 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0,
4212 "set client network interface addresses");
4213 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
4214 "client network interfaces");
4215 cmd_CreateAlias(ts, "sc");
4218 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks");
4219 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
4220 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
4221 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
4222 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
4223 cmd_CreateAlias(ts, "sp");
4225 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks");
4226 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
4227 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4228 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
4229 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
4230 cmd_CreateAlias(ts, "gp");
4232 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
4233 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4234 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
4235 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
4236 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
4237 parm_setacl_id = ts->nParms;
4238 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
4239 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
4240 cmd_CreateAlias(ts, "sa");
4242 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list");
4243 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4244 parm_listacl_id = ts->nParms;
4245 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4246 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4247 cmd_CreateAlias(ts, "la");
4249 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list");
4250 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4252 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list");
4253 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
4254 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
4255 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
4256 parm_copyacl_id = ts->nParms;
4257 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4258 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4260 cmd_CreateAlias(ts, "ca");
4262 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
4263 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4266 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0,
4267 "flush mount symlink from cache");
4268 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4271 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
4272 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4273 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
4275 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
4277 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
4278 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
4279 cmd_CreateAlias(ts, "sv");
4281 ts = cmd_CreateSyntax("messages", MessagesCmd, 0, "control Cache Manager messages");
4282 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
4284 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display file/volume status");
4285 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4286 cmd_CreateAlias(ts, "lv");
4287 cmd_CreateAlias(ts, "listvol");
4289 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
4290 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4291 cmd_CreateAlias(ts, "lq");
4293 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage");
4294 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4295 cmd_CreateAlias(ts, "df");
4297 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
4298 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4300 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
4301 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4303 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
4304 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
4305 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
4306 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
4307 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
4308 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
4314 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
4318 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
4319 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4321 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers");
4322 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
4323 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
4324 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
4325 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
4327 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings");
4328 cmd_CreateAlias(ts, "checkbackups");
4331 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size");
4332 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
4333 cmd_CreateAlias(ts, "cachesize");
4335 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
4337 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info");
4339 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells");
4340 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4342 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
4343 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
4344 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
4346 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
4348 cmd_CreateAlias(ts, "sq");
4350 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
4352 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
4353 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
4354 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
4356 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
4358 * Turn this on only if you wish to be able to talk to a server which is listening
4359 * on alternative ports. This is not intended for general use and may not be
4360 * supported in the cache manager. It is not a way to run two servers at the
4361 * same host, since the cache manager cannot properly distinguish those two hosts.
4363 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
4364 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
4367 ts = cmd_CreateSyntax("newalias", NewAliasCmd, 0,
4368 "configure new cell alias");
4369 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
4370 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
4373 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
4374 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4376 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
4377 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4379 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
4382 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
4385 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, "set cache monitor host address");
4386 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
4387 cmd_CreateAlias(ts, "mariner");
4390 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
4391 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4393 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
4394 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4395 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
4396 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
4398 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume");
4399 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4401 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value");
4402 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
4404 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS");
4405 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
4406 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
4407 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
4408 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
4409 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
4412 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
4413 "store to server after file close");
4414 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
4415 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
4416 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
4417 cmd_CreateAlias(ts, "sb");
4419 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag");
4420 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
4422 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "get cache manager encryption flag");
4425 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
4426 "Manage per process RX statistics");
4427 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4428 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4429 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4431 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0,
4432 "Manage per peer RX statistics");
4433 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4434 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4435 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4437 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, 0, "configure callback connection address");
4438 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
4441 ts = cmd_CreateSyntax("trace", TraceCmd, 0, "enable or disable CM tracing");
4442 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
4443 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
4444 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
4445 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
4446 cmd_CreateAlias(ts, "tr");
4448 ts = cmd_CreateSyntax("memdump", MemDumpCmd, 0, "dump memory allocs in debug builds");
4449 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
4450 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
4452 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, 0, "change client side caching policy for AFS shares");
4453 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
4454 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
4455 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
4456 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
4457 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
4459 ts = cmd_CreateSyntax("minidump", MiniDumpCmd, 0, "Generate MiniDump of current service state");
4461 code = cmd_Dispatch(argc, argv);
4466 #endif /* not WIN32 */
4472 Die(int code, char *filename)
4475 if (code == EINVAL) {
4477 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
4479 fprintf(stderr,"%s: Invalid argument.\n", pn);
4481 else if (code == ENOENT) {
4483 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
4485 fprintf(stderr,"%s: no such file returned\n", pn);
4487 else if (code == EROFS)
4488 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
4489 else if (code == EACCES || code == EPERM) {
4491 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
4493 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
4495 else if (code == ENODEV) {
4496 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
4498 else if (code == ESRCH) {
4499 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
4501 else if (code == EPIPE) {
4502 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
4504 else if (code == EFBIG) {
4505 fprintf(stderr,"%s: Cache size too large.\n", pn);
4507 else if (code == ETIMEDOUT) {
4509 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
4511 fprintf(stderr,"%s: Connection timed out", pn);
4515 fprintf(stderr,"%s:'%s'", pn, filename);
4517 fprintf(stderr,"%s", pn);
4519 fprintf(stderr, ": code 0x%x\n", code);
4520 #else /* not WIN32 */
4521 fprintf(stderr,": %s\n", error_message(code));
4522 #endif /* not WIN32 */