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);
64 extern afs_int32 VL_GetEntryByNameO();
66 static char pn[] = "fs";
67 static int rxInitDone = 0;
70 char name[MAXCELLCHARS];
73 struct sockaddr_in hostAddr[MAXCELLHOSTS];
74 char hostName[MAXCELLHOSTS][MAXHOSTCHARS];
80 * Character to use between name and rights in printed representation for
83 #define DFS_SEPARATOR ' '
85 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
88 int dfs; /* Originally true if a dfs acl; now also the type
89 * of the acl (1, 2, or 3, corresponding to object,
90 * initial dir, or initial object). */
91 sec_rgy_name_t cell; /* DFS cell name */
94 struct AclEntry *pluslist;
95 struct AclEntry *minuslist;
99 struct AclEntry *next;
105 ZapAcl (struct Acl *acl)
110 ZapList(acl->pluslist);
111 ZapList(acl->minuslist);
116 * Mods for the AFS/DFS protocol translator.
118 * DFS rights. It's ugly to put these definitions here, but they
119 * *cannot* change, because they're part of the wire protocol.
120 * In any event, the protocol translator will guarantee these
121 * assignments for AFS cache managers.
123 #define DFS_READ 0x01
124 #define DFS_WRITE 0x02
125 #define DFS_EXECUTE 0x04
126 #define DFS_CONTROL 0x08
127 #define DFS_INSERT 0x10
128 #define DFS_DELETE 0x20
130 /* the application definable ones (backwards from AFS) */
131 #define DFS_USR0 0x80000000 /* "A" bit */
132 #define DFS_USR1 0x40000000 /* "B" bit */
133 #define DFS_USR2 0x20000000 /* "C" bit */
134 #define DFS_USR3 0x10000000 /* "D" bit */
135 #define DFS_USR4 0x08000000 /* "E" bit */
136 #define DFS_USR5 0x04000000 /* "F" bit */
137 #define DFS_USR6 0x02000000 /* "G" bit */
138 #define DFS_USR7 0x01000000 /* "H" bit */
139 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
140 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
143 * Offset of -id switch in command structure for various commands.
144 * The -if switch is the next switch always.
146 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
149 * Determine whether either the -id or -if switches are present, and
150 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
152 /* int id; Offset of -id switch; -if is next switch */
154 getidf(struct cmd_syndesc *as, int id)
158 if (as->parms[id].items) {
161 if (as->parms[id + 1].items) {
166 "%s: you may specify either -id or -if, but not both switches\n",
174 PRights(afs_int32 arights, int dfs)
177 if (arights & PRSFS_READ)
179 if (arights & PRSFS_LOOKUP)
181 if (arights & PRSFS_INSERT)
183 if (arights & PRSFS_DELETE)
185 if (arights & PRSFS_WRITE)
187 if (arights & PRSFS_LOCK)
189 if (arights & PRSFS_ADMINISTER)
191 if (arights & PRSFS_USR0)
193 if (arights & PRSFS_USR1)
195 if (arights & PRSFS_USR2)
197 if (arights & PRSFS_USR3)
199 if (arights & PRSFS_USR4)
201 if (arights & PRSFS_USR5)
203 if (arights & PRSFS_USR6)
205 if (arights & PRSFS_USR7)
208 if (arights & DFS_READ)
212 if (arights & DFS_WRITE)
216 if (arights & DFS_EXECUTE)
220 if (arights & DFS_CONTROL)
224 if (arights & DFS_INSERT)
228 if (arights & DFS_DELETE)
232 if (arights & (DFS_USRALL))
234 if (arights & DFS_USR0)
236 if (arights & DFS_USR1)
238 if (arights & DFS_USR2)
240 if (arights & DFS_USR3)
242 if (arights & DFS_USR4)
244 if (arights & DFS_USR5)
246 if (arights & DFS_USR6)
248 if (arights & DFS_USR7)
254 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
258 struct ViceIoctl blob;
262 blob.out_size = MAXSIZE;
265 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
267 if ((errno == EINVAL) || (errno == ENOENT))
273 /* return a static pointer to a buffer */
278 strcpy(tspace, apath);
279 tp = strrchr(tspace, '\\');
281 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
284 fs_ExtractDriveLetter(apath, tspace);
290 enum rtype {add, destroy, deny};
293 Convert(char *arights, int dfs, enum rtype *rtypep)
299 *rtypep = add; /* add rights, by default */
302 if (!strcmp(arights, "null")) {
306 if (!strcmp(arights,"read"))
307 return DFS_READ | DFS_EXECUTE;
308 if (!strcmp(arights, "write"))
309 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
311 if (!strcmp(arights, "all"))
312 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
313 DFS_WRITE | DFS_CONTROL;
315 if (!strcmp(arights,"read"))
316 return PRSFS_READ | PRSFS_LOOKUP;
317 if (!strcmp(arights, "write"))
318 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
319 PRSFS_WRITE | PRSFS_LOCK;
320 if (!strcmp(arights, "mail"))
321 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
322 if (!strcmp(arights, "all"))
323 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
324 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
326 if (!strcmp(arights, "none")) {
327 *rtypep = destroy; /* Remove entire entry */
330 len = strlen(arights);
366 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
374 mode |= PRSFS_LOOKUP;
376 mode |= PRSFS_INSERT;
378 mode |= PRSFS_DELETE;
384 mode |= PRSFS_ADMINISTER;
402 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
411 static struct AclEntry *
412 FindList (struct AclEntry *alist, char *aname)
415 if (!strcasecmp(alist->name, aname))
422 /* if no parm specified in a particular slot, set parm to be "." instead */
424 SetDotDefault(struct cmd_item **aitemp)
428 return; /* already has value */
429 /* otherwise, allocate an item representing "." */
430 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
432 ti->next = (struct cmd_item *) 0;
433 ti->data = (char *) malloc(2);
435 strcpy(ti->data, ".");
440 ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
442 struct AclEntry *tlist;
443 tlist = (plus ? al->pluslist : al->minuslist);
444 tlist = FindList (tlist, aname);
446 /* Found the item already in the list. */
447 tlist->rights = arights;
449 al->nplus -= PruneList(&al->pluslist, al->dfs);
451 al->nminus -= PruneList(&al->minuslist, al->dfs);
454 /* Otherwise we make a new item and plug in the new data. */
455 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
457 strcpy(tlist->name, aname);
458 tlist->rights = arights;
460 tlist->next = al->pluslist;
461 al->pluslist = tlist;
463 if (arights == 0 || arights == -1)
464 al->nplus -= PruneList(&al->pluslist, al->dfs);
466 tlist->next = al->minuslist;
467 al->minuslist = tlist;
470 al->nminus -= PruneList(&al->minuslist, al->dfs);
475 ZapList (struct AclEntry *alist)
477 struct AclEntry *tp, *np;
478 for (tp = alist; tp; tp = np) {
485 PruneList (struct AclEntry **ae, int dfs)
487 struct AclEntry **lp;
488 struct AclEntry *te, *ne;
492 for(te = *ae;te;te=ne) {
493 if ((!dfs && te->rights == 0) || te->rights == -1) {
507 SkipLine (char *astr)
516 * Create an empty acl, taking into account whether the acl pointed
517 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
518 * can recover from problems caused by bogus ACL's (in that case, always
519 * assume that the acl is AFS: for DFS, the user can always resort to
520 * acl_edit, but for AFS there may be no other way out).
528 tp = (struct Acl *)malloc(sizeof (struct Acl));
530 tp->nplus = tp->nminus = 0;
531 tp->pluslist = tp->minuslist = 0;
533 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
538 ParseAcl (char *astr)
540 int nplus, nminus, i, trights;
542 struct AclEntry *first, *last, *tl;
545 ta = (struct Acl *) malloc (sizeof (struct Acl));
548 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
549 astr = SkipLine(astr);
550 sscanf(astr, "%d", &ta->nminus);
551 astr = SkipLine(astr);
558 for(i=0;i<nplus;i++) {
559 sscanf(astr, "%100s %d", tname, &trights);
560 astr = SkipLine(astr);
561 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
565 strcpy(tl->name, tname);
566 tl->rights = trights;
572 ta->pluslist = first;
576 for(i=0;i<nminus;i++) {
577 sscanf(astr, "%100s %d", tname, &trights);
578 astr = SkipLine(astr);
579 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
583 strcpy(tl->name, tname);
584 tl->rights = trights;
590 ta->minuslist = first;
596 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
598 printf("Volume status for vid = %u named %s\n",status->Vid, name);
600 printf("Current offline message is %s\n",offmsg);
602 printf("Current message of the day is %s\n",motd);
603 printf("Current disk quota is ");
604 if (status->MaxQuota != 0)
605 printf("%d\n", status->MaxQuota);
607 printf("unlimited\n");
608 printf("Current blocks used are %d\n",status->BlocksInUse);
609 printf("The partition has %d blocks available out of %d\n\n",
610 status->PartBlocksAvail, status->PartMaxBlocks);
615 QuickPrintStatus(VolumeStatus *status, char *name)
617 double QuotaUsed =0.0;
618 double PartUsed =0.0;
620 printf("%-25.25s",name);
622 if (status->MaxQuota != 0) {
623 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
624 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
626 printf("no limit%10d", status->BlocksInUse);
628 if (QuotaUsed > 90.0){
629 printf(" %5.0f%%<<", QuotaUsed);
632 printf(" %5.0f%% ", QuotaUsed);
633 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
634 if (PartUsed > 97.0){
635 printf(" %9.0f%%<<", PartUsed);
638 printf(" %9.0f%% ", PartUsed);
640 printf(" <<WARNING\n");
647 QuickPrintSpace(VolumeStatus *status, char *name)
649 double PartUsed =0.0;
651 printf("%-25.25s",name);
653 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
655 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
656 if (PartUsed > 90.0){
657 printf(" %4.0f%%<<", PartUsed);
660 printf(" %4.0f%% ", PartUsed);
662 printf(" <<WARNING\n");
669 AclToString(struct Acl *acl)
671 static char mydata[MAXSIZE];
672 char tstring[MAXSIZE];
677 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
680 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
681 for (tp = acl->pluslist;tp;tp=tp->next) {
682 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
683 strcat(mydata, tstring);
685 for (tp = acl->minuslist;tp;tp=tp->next) {
686 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
687 strcat(mydata, tstring);
692 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
696 static BOOL fAdmin = FALSE;
697 static BOOL fTested = FALSE;
701 /* Obtain the SID for the AFS client admin group. If the group does
702 * not exist, then assume we have AFS client admin privileges.
704 PSID psidAdmin = NULL;
705 DWORD dwSize, dwSize2;
706 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
707 char *pszRefDomain = NULL;
708 SID_NAME_USE snu = SidTypeGroup;
710 dwSize = sizeof(pszAdminGroup);
712 if (!GetComputerName(pszAdminGroup, &dwSize)) {
713 /* Can't get computer name. We return false in this case.
714 Retain fAdmin and fTested. This shouldn't happen.*/
721 strcat(pszAdminGroup,"\\");
722 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
724 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
725 /* that should always fail. */
727 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
728 /* if we can't find the group, then we allow the operation */
733 if (dwSize == 0 || dwSize2 == 0) {
739 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
741 pszRefDomain = (char *)malloc(dwSize2);
742 assert(pszRefDomain);
744 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
745 /* We can't lookup the group now even though we looked it up earlier.
746 Could this happen? */
749 /* Then open our current ProcessToken */
752 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
755 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
756 /* We'll have to allocate a chunk of memory to store the list of
757 * groups to which this user belongs; find out how much memory
761 PTOKEN_GROUPS pGroups;
763 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
765 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
768 /* Allocate that buffer, and read in the list of groups. */
769 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
771 /* Look through the list of group SIDs and see if any of them
772 * matches the AFS Client Admin group SID.
775 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
777 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
787 /* if do not have permission because we were not explicitly listed
788 * in the Admin Client Group let's see if we are the SYSTEM account
791 PTOKEN_USER pTokenUser;
792 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
793 PSID pSidLocalSystem = 0;
796 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
798 pTokenUser = (PTOKEN_USER)malloc(dwSize);
801 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
802 gle = GetLastError();
804 if (AllocateAndInitializeSid( &SIDAuth, 1,
805 SECURITY_LOCAL_SYSTEM_RID,
809 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
813 FreeSid(pSidLocalSystem);
832 SetACLCmd(struct cmd_syndesc *as, char *arock)
835 struct ViceIoctl blob;
837 struct cmd_item *ti, *ui;
841 int idf = getidf(as, parm_setacl_id);
845 if (as->parms[2].items)
849 plusp = !(as->parms[3].items);
850 for(ti=as->parms[0].items; ti;ti=ti->next) {
851 blob.out_size = MAXSIZE;
853 blob.in = blob.out = space;
854 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
856 Die(errno, ti->data);
862 ta = ParseAcl(space);
863 if (!plusp && ta->dfs) {
865 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
867 "(you may specify \"null\" to revoke all rights, however)\n");
874 ta = EmptyAcl(space);
876 ta = ParseAcl(space);
877 CleanAcl(ta, ti->data);
878 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
882 "%s: Missing second half of user/access pair.\n", pn);
886 rights = Convert(ui->next->data, ta->dfs, &rtype);
887 if (rtype == destroy && !ta->dfs) {
888 struct AclEntry *tlist;
890 tlist = (plusp ? ta->pluslist : ta->minuslist);
891 if (!FindList(tlist, ui->data))
894 if (rtype == deny && !ta->dfs)
896 if (rtype == destroy && ta->dfs)
898 ChangeList(ta, plusp, ui->data, rights);
900 blob.in = AclToString(ta);
902 blob.in_size = 1+strlen(blob.in);
903 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
905 if (errno == EINVAL) {
907 static char *fsenv = 0;
909 fsenv = (char *)getenv("FS_EXPERT");
911 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
914 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
915 "\nPossible reasons for this include:\n\n",
916 " -You may have specified an inappropriate combination of rights.\n",
917 " For example, some DFS-supported filesystems may not allow you to\n",
918 " drop the \"c\" right from \"user_obj\".\n\n",
919 " -A mask_obj may be required (it is likely required by the underlying\n",
920 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
921 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
922 " does not automatically create or update the mask_obj. Try setting\n",
923 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
924 " users or groups. You can do this with a single command, such as\n",
925 " \"fs sa mask_obj all user:somename read\"\n\n",
926 " -A specified user or group may not exist.\n\n",
927 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
928 " This is probably not allowed by the underlying file system.\n\n",
929 " -If you add a user or group to a DFS ACL, remember that it must be\n",
930 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
931 " may be local requirements on the format of the user or group name.\n",
932 " Check with your cell administrator.\n\n",
933 " -Or numerous other possibilities. It would be great if we could be more\n",
934 " precise about the actual problem, but for various reasons, this is\n",
935 " impractical via this interface. If you can't figure it out, you\n",
936 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
937 " whatever is provided). You may get better results. Good luck!\n\n",
938 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
942 "%s: Invalid argument, possible reasons include:\n",
944 fprintf(stderr,"\t-File not in AFS\n");
946 "\t-Too many users on access control list\n");
948 "\t-Tried to add non-existent user to access control list\n");
951 Die(errno, ti->data);
962 CopyACLCmd(struct cmd_syndesc *as, char *arock)
965 struct ViceIoctl blob;
966 struct Acl *fa, *ta = 0;
970 int idf = getidf(as, parm_copyacl_id);
973 if (as->parms[2].items)
977 blob.out_size = MAXSIZE;
979 blob.in = blob.out = space;
980 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
982 Die(errno, as->parms[0].items->data);
985 fa = ParseAcl(space);
986 CleanAcl(fa, as->parms[0].items->data);
987 for (ti=as->parms[1].items; ti;ti=ti->next) {
988 blob.out_size = MAXSIZE;
990 blob.in = blob.out = space;
991 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
993 Die(errno, ti->data);
1000 ta = EmptyAcl(space);
1002 ta = ParseAcl(space);
1003 CleanAcl(ta, ti->data);
1004 if (ta->dfs != fa->dfs) {
1006 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1012 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1014 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1019 strcpy(ta->cell, fa->cell);
1021 for (tp = fa->pluslist;tp;tp=tp->next)
1022 ChangeList(ta, 1, tp->name, tp->rights);
1023 for (tp = fa->minuslist;tp;tp=tp->next)
1024 ChangeList(ta, 0, tp->name, tp->rights);
1025 blob.in = AclToString(ta);
1027 blob.in_size = 1+strlen(blob.in);
1028 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1030 if (errno == EINVAL) {
1032 "%s: Invalid argument, possible reasons include:\n", pn);
1033 fprintf(stderr,"\t-File not in AFS\n");
1035 Die(errno, ti->data);
1046 /* pioctl() call to get the cellname of a pathname */
1048 GetCell(char *fname, char *cellname)
1051 struct ViceIoctl blob;
1054 blob.out_size = MAXCELLCHARS;
1055 blob.out = cellname;
1057 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1058 return code ? errno : 0;
1061 /* Check if a username is valid: If it contains only digits (or a
1062 * negative sign), then it might be bad. We then query the ptserver
1066 BadName(char *aname, char *fname)
1068 afs_int32 tc, code, id;
1070 char cell[MAXCELLCHARS];
1072 for ( nm = aname; tc = *nm; nm++) {
1073 /* all must be '-' or digit to be bad */
1074 if (tc != '-' && (tc < '0' || tc > '9'))
1078 /* Go to the PRDB and see if this all number username is valid */
1079 code = GetCell(fname, cell);
1083 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
1084 code = pr_SNameToId(aname, &id);
1087 /* 1=>Not-valid; 0=>Valid */
1088 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1092 /* clean up an access control list of its bad entries; return 1 if we made
1093 any changes to the list, and 0 otherwise */
1095 CleanAcl(struct Acl *aa, char *fname)
1097 struct AclEntry *te, **le, *ne;
1100 /* Don't correct DFS ACL's for now */
1104 /* prune out bad entries */
1105 changes = 0; /* count deleted entries */
1107 for(te = aa->pluslist; te; te=ne) {
1109 if (BadName(te->name, fname)) {
1119 le = &aa->minuslist;
1120 for(te = aa->minuslist; te; te=ne) {
1122 if (BadName(te->name, fname)) {
1136 /* clean up an acl to not have bogus entries */
1138 CleanACLCmd(struct cmd_syndesc *as, char *arock)
1142 struct ViceIoctl blob;
1144 struct cmd_item *ti;
1145 struct AclEntry *te;
1148 SetDotDefault(&as->parms[0].items);
1149 for(ti=as->parms[0].items; ti; ti=ti->next) {
1150 blob.out_size = MAXSIZE;
1153 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1155 Die(errno, ti->data);
1161 ta = ParseAcl(space);
1165 "%s: cleanacl is not supported for DFS access lists.\n",
1171 changes = CleanAcl(ta, ti->data);
1174 /* now set the acl */
1175 blob.in=AclToString(ta);
1176 blob.in_size = strlen(blob.in)+1;
1178 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1180 if (errno == EINVAL) {
1182 "%s: Invalid argument, possible reasons include\n",
1184 fprintf(stderr,"%s: File not in vice or\n", pn);
1186 "%s: Too many users on access control list or\n",
1189 Die(errno, ti->data);
1195 /* now list the updated acl */
1196 printf("Access list for %s is now\n", ti->data);
1197 if (ta->nplus > 0) {
1199 printf("Normal rights:\n");
1200 for(te = ta->pluslist;te;te=te->next) {
1201 printf(" %s ", te->name);
1202 PRights(te->rights, ta->dfs);
1206 if (ta->nminus > 0) {
1207 printf("Negative rights:\n");
1208 for(te = ta->minuslist;te;te=te->next) {
1209 printf(" %s ", te->name);
1210 PRights(te->rights, ta->dfs);
1217 printf("Access list for %s is fine.\n", ti->data);
1225 ListACLCmd(struct cmd_syndesc *as, char *arock)
1229 struct ViceIoctl blob;
1230 struct AclEntry *te;
1231 struct cmd_item *ti;
1232 int idf = getidf(as, parm_listacl_id);
1235 SetDotDefault(&as->parms[0].items);
1236 for(ti=as->parms[0].items; ti; ti=ti->next) {
1238 blob.out_size = MAXSIZE;
1240 blob.in = blob.out = space;
1241 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1243 Die(errno, ti->data);
1247 ta = ParseAcl(space);
1250 printf("Access list for %s is\n", ti->data);
1253 printf("DFS access list for %s is\n", ti->data);
1256 printf("DFS initial directory access list of %s is\n", ti->data);
1259 printf("DFS initial file access list of %s is\n", ti->data);
1263 printf(" Default cell = %s\n", ta->cell);
1265 separator = ta->dfs? DFS_SEPARATOR : ' ';
1266 if (ta->nplus > 0) {
1268 printf("Normal rights:\n");
1269 for(te = ta->pluslist;te;te=te->next) {
1270 printf(" %s%c", te->name, separator);
1271 PRights(te->rights, ta->dfs);
1275 if (ta->nminus > 0) {
1276 printf("Negative rights:\n");
1277 for(te = ta->minuslist;te;te=te->next) {
1278 printf(" %s ", te->name);
1279 PRights(te->rights, ta->dfs);
1291 FlushVolumeCmd(struct cmd_syndesc *as, char *arock)
1294 struct ViceIoctl blob;
1295 struct cmd_item *ti;
1298 SetDotDefault(&as->parms[0].items);
1299 for(ti=as->parms[0].items; ti; ti=ti->next) {
1300 blob.in_size = blob.out_size = 0;
1301 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1303 fprintf(stderr, "Error flushing volume ");
1313 FlushCmd(struct cmd_syndesc *as, char *arock)
1316 struct ViceIoctl blob;
1317 struct cmd_item *ti;
1321 for(ti=as->parms[0].items; ti; ti=ti->next) {
1322 blob.in_size = blob.out_size = 0;
1323 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1325 if (errno == EMFILE) {
1326 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1329 fprintf(stderr, "%s: Error flushing file ", pn);
1339 /* all this command does is repackage its args and call SetVolCmd */
1341 SetQuotaCmd(struct cmd_syndesc *as, char *arock) {
1342 struct cmd_syndesc ts;
1344 /* copy useful stuff from our command slot; we may later have to reorder */
1345 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1346 return SetVolCmd(&ts, arock);
1350 SetVolCmd(struct cmd_syndesc *as, char *arock) {
1352 struct ViceIoctl blob;
1353 struct cmd_item *ti;
1354 struct VolumeStatus *status;
1355 char *motd, *offmsg, *input;
1358 SetDotDefault(&as->parms[0].items);
1359 for(ti=as->parms[0].items; ti; ti=ti->next) {
1361 blob.out_size = MAXSIZE;
1362 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1365 status = (VolumeStatus *)space;
1366 status->MinQuota = status->MaxQuota = -1;
1367 motd = offmsg = NULL;
1368 if (as->parms[1].items) {
1369 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1371 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1376 if (as->parms[2].items)
1377 motd = as->parms[2].items->data;
1378 if (as->parms[3].items)
1379 offmsg = as->parms[3].items->data;
1380 input = (char *)status + sizeof(*status);
1381 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1383 if (strlen(offmsg) >= VMSGSIZE) {
1384 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1389 strcpy(input,offmsg);
1390 blob.in_size += strlen(offmsg);
1391 input += strlen(offmsg) + 1;
1395 if (strlen(motd) >= VMSGSIZE) {
1396 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1401 blob.in_size += strlen(motd);
1402 input += strlen(motd) + 1;
1405 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1415 * Why is VenusFid declared in the kernel-only section of afs.h,
1416 * if it's the exported interface of the (UNIX) cache manager?
1425 ExamineCmd(struct cmd_syndesc *as, char *arock)
1428 struct ViceIoctl blob;
1429 struct cmd_item *ti;
1430 struct VolumeStatus *status;
1431 char *name, *offmsg, *motd;
1434 SetDotDefault(&as->parms[0].items);
1435 for(ti=as->parms[0].items; ti; ti=ti->next) {
1437 struct VenusFid vfid;
1440 blob.out_size = MAXSIZE;
1443 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1445 Die(errno, ti->data);
1449 status = (VolumeStatus *)space;
1450 name = (char *)status + sizeof(*status);
1451 offmsg = name + strlen(name) + 1;
1452 motd = offmsg + strlen(offmsg) + 1;
1455 blob.out_size = sizeof(struct VenusFid);
1456 blob.out = (char *) &vfid;
1457 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1458 printf("File %s (%u.%u.%u) contained in volume %u\n",
1459 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1463 PrintStatus(status, name, motd, offmsg);
1469 ListQuotaCmd(struct cmd_syndesc *as, char *arock)
1472 struct ViceIoctl blob;
1473 struct cmd_item *ti;
1474 struct VolumeStatus *status;
1479 printf("%-25s%-10s%-10s%-7s%-13s\n",
1480 "Volume Name", " Quota", " Used", " %Used", " Partition");
1481 SetDotDefault(&as->parms[0].items);
1482 for(ti=as->parms[0].items; ti; ti=ti->next) {
1484 blob.out_size = MAXSIZE;
1487 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1489 Die(errno, ti->data);
1493 status = (VolumeStatus *)space;
1494 name = (char *)status + sizeof(*status);
1495 QuickPrintStatus(status, name);
1501 WhereIsCmd(struct cmd_syndesc *as, char *arock)
1504 struct ViceIoctl blob;
1505 struct cmd_item *ti;
1511 SetDotDefault(&as->parms[0].items);
1512 for(ti=as->parms[0].items; ti; ti=ti->next) {
1514 blob.out_size = MAXSIZE;
1517 memset(space, 0, sizeof(space));
1518 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1520 Die(errno, ti->data);
1524 hosts = (afs_int32 *) space;
1525 printf("File %s is on host%s ", ti->data,
1526 (hosts[0] && !hosts[1]) ? "": "s");
1527 for(j=0; j<MAXHOSTS; j++) {
1530 tp = hostutil_GetNameByINet(hosts[j]);
1540 DiskFreeCmd(struct cmd_syndesc *as, char *arock)
1543 struct ViceIoctl blob;
1544 struct cmd_item *ti;
1546 struct VolumeStatus *status;
1549 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1550 " used", " avail", " %used");
1551 SetDotDefault(&as->parms[0].items);
1552 for(ti=as->parms[0].items; ti; ti=ti->next) {
1554 blob.out_size = MAXSIZE;
1557 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1559 Die(errno, ti->data);
1563 status = (VolumeStatus *)space;
1564 name = (char *)status + sizeof(*status);
1565 QuickPrintSpace(status, name);
1571 QuotaCmd(struct cmd_syndesc *as, char *arock)
1574 struct ViceIoctl blob;
1575 struct cmd_item *ti;
1577 struct VolumeStatus *status;
1580 SetDotDefault(&as->parms[0].items);
1581 for(ti=as->parms[0].items; ti; ti=ti->next) {
1583 blob.out_size = MAXSIZE;
1586 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1588 Die(errno, ti->data);
1592 status = (VolumeStatus *)space;
1593 if (status->MaxQuota)
1594 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1597 printf("%2.0f%% of quota used.\n", quotaPct);
1603 ListMountCmd(struct cmd_syndesc *as, char *arock)
1606 struct ViceIoctl blob;
1607 struct cmd_item *ti;
1608 char orig_name[1024]; /*Original name, may be modified*/
1609 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1610 char parent_dir[1024]; /*Parent directory of true name*/
1611 char *last_component; /*Last component of true name*/
1613 struct stat statbuff; /*Buffer for status info*/
1614 #endif /* not WIN32 */
1616 int link_chars_read; /*Num chars read in readlink()*/
1617 #endif /* not WIN32 */
1618 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1621 for(ti=as->parms[0].items; ti; ti=ti->next) {
1625 strcpy(orig_name, ti->data);
1626 #else /* not WIN32 */
1627 sprintf(orig_name, "%s%s",
1628 (ti->data[0] == '/') ? "" : "./",
1630 #endif /* not WIN32 */
1633 if (lstat(orig_name, &statbuff) < 0) {
1634 /* if lstat fails, we should still try the pioctl, since it
1635 * may work (for example, lstat will fail, but pioctl will
1636 * work if the volume of offline (returning ENODEV). */
1637 statbuff.st_mode = S_IFDIR; /* lie like pros */
1641 * The lstat succeeded. If the given file is a symlink, substitute
1642 * the file name with the link name.
1644 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1647 * Read name of resolved file.
1649 link_chars_read = readlink(orig_name, true_name, 1024);
1650 if (link_chars_read <= 0) {
1652 "%s: Can't read target name for '%s' symbolic link!\n",
1659 * Add a trailing null to what was read, bump the length.
1661 true_name[link_chars_read++] = 0;
1664 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1665 * have to create a full pathname using the original name and the
1666 * relative symlink name. Find the rightmost slash in the original
1667 * name (we know there is one) and splice in the symlink value.
1669 if (true_name[0] != '\\') {
1670 last_component = (char *) strrchr(orig_name, '\\');
1671 strcpy(++last_component, true_name);
1672 strcpy(true_name, orig_name);
1675 strcpy(true_name, orig_name);
1677 strcpy(true_name, orig_name);
1681 * Find rightmost slash, if any.
1684 last_component = (char *) strrchr(true_name, '\\');
1685 if (!last_component)
1687 last_component = (char *) strrchr(true_name, '/');
1688 if (last_component) {
1690 * Found it. Designate everything before it as the parent directory,
1691 * everything after it as the final component.
1693 strncpy(parent_dir, true_name, last_component - true_name + 1);
1694 parent_dir[last_component - true_name + 1] = 0;
1695 last_component++; /*Skip the slash*/
1698 * No slash appears in the given file name. Set parent_dir to the current
1699 * directory, and the last component as the given name.
1701 fs_ExtractDriveLetter(true_name, parent_dir);
1702 strcat(parent_dir, ".");
1703 last_component = true_name;
1704 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1707 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1708 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
1709 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
1714 blob.in = last_component;
1715 blob.in_size = strlen(last_component)+1;
1716 blob.out_size = MAXSIZE;
1718 memset(space, 0, MAXSIZE);
1720 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1723 printf("'%s' is a %smount point for volume '%s'\n",
1725 (thru_symlink ? "symbolic link, leading to a " : ""),
1729 if (errno == EINVAL) {
1730 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
1732 Die(errno, (ti->data ? ti->data : parent_dir));
1741 MakeMountCmd(struct cmd_syndesc *as, char *arock)
1744 char *cellName, *volName, *tmpName;
1746 char localCellName[1000];
1747 #else /* not WIN32 */
1748 struct afsconf_cell info;
1749 struct vldbentry vldbEntry;
1750 #endif /* not WIN32 */
1751 struct ViceIoctl blob;
1757 if (as->parms[5].items && !as->parms[2].items) {
1758 fprintf(stderr,"%s: must provide cell when creating cellular mount point.\n", pn);
1763 if (as->parms[2].items) /* cell name specified */
1764 cellName = as->parms[2].items->data;
1767 volName = as->parms[1].items->data;
1769 if (strlen(volName) >= 64) {
1770 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
1774 /* Check for a cellname in the volume specification, and complain
1775 * if it doesn't match what was specified with -cell */
1776 if (tmpName = strchr(volName, ':')) {
1779 if (strcasecmp(cellName,volName)) {
1780 fprintf(stderr,"fs: cellnames do not match.\n");
1785 volName = ++tmpName;
1788 if (!InAFS(Parent(as->parms[0].items->data))) {
1789 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
1795 blob.out_size = MAXSIZE;
1797 code = pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME, &blob, 1);
1801 strcpy(localCellName, (cellName? cellName : space));
1802 #else /* not win32 */
1803 code = GetCellName(cellName?cellName:space, &info);
1807 if (!(as->parms[4].items)) {
1808 /* not fast, check which cell the mountpoint is being created in */
1810 /* not fast, check name with VLDB */
1812 code = VLDBInit(1, &info);
1814 /* make the check. Don't complain if there are problems with init */
1815 code = ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, &vldbEntry);
1816 if (code == VL_NOENT) {
1817 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
1818 pn, volName, cellName ? cellName : space);
1822 #endif /* not WIN32 */
1824 if (as->parms[3].items) /* if -rw specified */
1829 /* cellular mount point, prepend cell prefix */
1831 strcat(space, localCellName);
1832 #else /* not WIN32 */
1833 strcat(space, info.name);
1834 #endif /* not WIN32 */
1837 strcat(space, volName); /* append volume name */
1838 strcat(space, "."); /* stupid convention; these end with a period */
1840 /* create symlink with a special pioctl for Windows NT, since it doesn't
1841 * have a symlink system call.
1844 blob.in_size = 1 + strlen(space);
1847 code = pioctl(as->parms[0].items->data, VIOC_AFS_CREATE_MT_PT, &blob, 0);
1848 #else /* not WIN32 */
1849 code = symlink(space, as->parms[0].items->data);
1850 #endif /* not WIN32 */
1852 Die(errno, as->parms[0].items->data);
1859 * Delete AFS mount points. Variables are used as follows:
1860 * tbuffer: Set to point to the null-terminated directory name of the mount point
1861 * (or ``.'' if none is provided)
1862 * tp: Set to point to the actual name of the mount point to nuke.
1865 RemoveMountCmd(struct cmd_syndesc *as, char *arock) {
1867 struct ViceIoctl blob;
1868 struct cmd_item *ti;
1870 char lsbuffer[1024];
1874 for(ti=as->parms[0].items; ti; ti=ti->next) {
1876 tp = (char *) strrchr(ti->data, '\\');
1878 tp = (char *) strrchr(ti->data, '/');
1880 strncpy(tbuffer, ti->data, code=tp-ti->data+1); /* the dir name */
1882 tp++; /* skip the slash */
1884 fs_ExtractDriveLetter(ti->data, tbuffer);
1885 strcat(tbuffer, ".");
1887 fs_StripDriveLetter(tp, tp, 0);
1890 blob.in_size = strlen(tp)+1;
1891 blob.out = lsbuffer;
1892 blob.out_size = sizeof(lsbuffer);
1893 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1895 if (errno == EINVAL) {
1896 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
1898 Die(errno, ti->data);
1901 continue; /* don't bother trying */
1905 blob.in_size = strlen(tp)+1;
1906 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1908 Die(errno, ti->data);
1919 CheckServersCmd(struct cmd_syndesc *as, char *arock)
1922 struct ViceIoctl blob;
1926 struct afsconf_cell info;
1927 struct chservinfo checkserv;
1929 memset(&checkserv, 0, sizeof(struct chservinfo));
1930 blob.in_size=sizeof(struct chservinfo);
1931 blob.in=(caddr_t)&checkserv;
1933 blob.out_size = MAXSIZE;
1935 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1937 /* prepare flags for checkservers command */
1938 temp = 2; /* default to checking local cell only */
1939 if (as->parms[2].items)
1940 temp |= 1; /* set fast flag */
1941 if (as->parms[1].items)
1942 temp &= ~2; /* turn off local cell check */
1944 checkserv.magic = 0x12345678; /* XXX */
1945 checkserv.tflags=temp;
1947 /* now copy in optional cell name, if specified */
1948 if (as->parms[0].items) {
1949 code = GetCellName(as->parms[0].items->data, &info);
1953 strcpy(checkserv.tbuffer,info.name);
1954 checkserv.tsize=strlen(info.name)+1;
1956 strcpy(checkserv.tbuffer,"\0");
1960 if(as->parms[3].items) {
1961 checkserv.tinterval=atol(as->parms[3].items->data);
1964 if(checkserv.tinterval<0) {
1965 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
1966 checkserv.tinterval=0;
1967 } else if(checkserv.tinterval> 600) {
1968 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1969 checkserv.tinterval=600; /* 10 min max interval */
1972 checkserv.tinterval = -1; /* don't change current interval */
1975 if ( checkserv.tinterval != 0 ) {
1978 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
1983 fprintf (stderr,"Permission denied: requires root access.\n");
1989 code = pioctl(0, VIOCCKSERV, &blob, 1);
1991 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1992 printf("Must be root to change -interval\n");
1998 memcpy(&temp, space, sizeof(afs_int32));
1999 if (checkserv.tinterval >= 0) {
2000 if (checkserv.tinterval > 0)
2001 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2002 checkserv.tinterval, temp);
2004 printf("The current down server probe interval is %d secs\n", temp);
2008 printf("All servers are running.\n");
2010 printf("These servers unavailable due to network or server problems: ");
2011 for(j=0; j < MAXHOSTS; j++) {
2012 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2015 tp = hostutil_GetNameByINet(temp);
2025 MessagesCmd(struct cmd_syndesc *as, char *arock)
2028 struct ViceIoctl blob;
2029 struct gaginfo gagflags;
2030 struct cmd_item *show;
2032 memset(&gagflags, 0, sizeof(struct gaginfo));
2033 blob.in_size = sizeof(struct gaginfo);
2034 blob.in = (caddr_t ) &gagflags;
2035 blob.out_size = MAXSIZE;
2037 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2039 if (show = as->parms[0].items) {
2040 if (!strcasecmp (show->data, "user"))
2041 gagflags.showflags |= GAGUSER;
2042 else if (!strcasecmp (show->data, "console"))
2043 gagflags.showflags |= GAGCONSOLE;
2044 else if (!strcasecmp (show->data, "all"))
2045 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2046 else if (!strcasecmp (show->data, "none"))
2050 "unrecognized flag %s: must be in {user,console,all,none}\n",
2059 code = pioctl(0, VIOC_GAG, &blob, 1);
2068 CheckVolumesCmd(struct cmd_syndesc *as, char *arock)
2071 struct ViceIoctl blob;
2075 code = pioctl(0, VIOCCKBACK, &blob, 1);
2080 printf("All volumeID/name mappings checked.\n");
2086 SetCacheSizeCmd(struct cmd_syndesc *as, char *arock)
2089 struct ViceIoctl blob;
2094 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2099 fprintf (stderr,"Permission denied: requires root access.\n");
2104 if (!as->parms[0].items && !as->parms[1].items) {
2105 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2108 if (as->parms[0].items) {
2109 code = util_GetInt32(as->parms[0].items->data, &temp);
2111 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2116 blob.in = (char *) &temp;
2117 blob.in_size = sizeof(afs_int32);
2119 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2121 Die(errno, (char *) 0);
2125 printf("New cache size set.\n");
2129 #define MAXGCSIZE 16
2131 GetCacheParmsCmd(struct cmd_syndesc *as, char *arock)
2134 struct ViceIoctl blob;
2135 afs_int32 parms[MAXGCSIZE];
2137 memset(parms, 0, sizeof(parms));
2140 blob.out_size = sizeof(parms);
2141 blob.out = (char *) parms;
2142 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2148 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2149 parms[1], parms[0]);
2150 if (parms[1] > parms[0])
2151 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2156 ListCellsCmd(struct cmd_syndesc *as, char *arock)
2159 afs_int32 i, j, *lp, magic, size;
2161 afs_int32 addr, maxa = OMAXHOSTS;
2162 struct ViceIoctl blob;
2165 resolve = !(as->parms[0].items); /* -numeric */
2167 for(i=0;i<1000;i++) {
2169 memcpy(tp, &i, sizeof(afs_int32));
2170 tp = (char *)(space + sizeof(afs_int32));
2171 lp = (afs_int32 *)tp;
2173 size = sizeof(afs_int32) + sizeof(afs_int32);
2174 blob.out_size = MAXSIZE;
2175 blob.in_size = sizeof(afs_int32);
2178 code = pioctl(0, VIOCGETCELL, &blob, 1);
2181 break; /* done with the list */
2186 memcpy(&magic, tp, sizeof(afs_int32));
2187 if (magic == 0x12345678) {
2189 tp += sizeof(afs_int32);
2191 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2192 for(j=0; j < maxa; j++) {
2193 char *name, tbuffer[20];
2195 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2200 name = hostutil_GetNameByINet(addr);
2203 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2204 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2207 printf(" %s", name);
2216 ListAliasesCmd(struct cmd_syndesc *as, char *arock)
2219 char *tp, *aliasName, *realName;
2220 struct ViceIoctl blob;
2224 memcpy(tp, &i, sizeof(afs_int32));
2225 blob.out_size = MAXSIZE;
2226 blob.in_size = sizeof(afs_int32);
2229 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2232 break; /* done with the list */
2238 tp += strlen(aliasName) + 1;
2240 printf("Alias %s for cell %s\n", aliasName, realName);
2246 CallBackRxConnCmd(struct cmd_syndesc *as, char *arock)
2249 struct ViceIoctl blob;
2250 struct cmd_item *ti;
2252 struct hostent *thp;
2256 ti = as->parms[0].items;
2259 thp = hostutil_GetHostByName(ti->data);
2261 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2264 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2266 hostAddr = 0; /* means don't set host */
2267 setp = 0; /* aren't setting host */
2270 /* now do operation */
2271 blob.in_size = sizeof(afs_int32);
2272 blob.out_size = sizeof(afs_int32);
2273 blob.in = (char *) &hostAddr;
2274 blob.out = (char *) &hostAddr;
2276 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2286 NewCellCmd(struct cmd_syndesc *as, char *arock)
2289 afs_int32 code, linkedstate=0, size=0, *lp;
2290 struct ViceIoctl blob;
2291 struct cmd_item *ti;
2292 char *tp, *cellname=0;
2293 struct hostent *thp;
2294 afs_int32 fsport = 0, vlport = 0;
2296 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
2298 lp = (afs_int32 *)tp;
2300 tp += sizeof(afs_int32);
2301 for(ti=as->parms[1].items; ti; ti=ti->next) {
2302 thp = hostutil_GetHostByName(ti->data);
2304 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2308 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2309 tp += sizeof(afs_int32);
2312 if (as->parms[2].items) {
2314 * Link the cell, for the purposes of volume location, to the specified
2317 cellname = as->parms[2].items->data;
2320 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2321 if (as->parms[3].items) {
2322 code = util_GetInt32(as->parms[3].items->data, &vlport);
2324 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2328 if (as->parms[4].items) {
2329 code = util_GetInt32(as->parms[4].items->data, &fsport);
2331 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2336 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
2337 lp = (afs_int32 *)tp;
2341 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2342 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2343 tp = (char *)(space + size);
2345 strcpy(tp, cellname);
2346 size += strlen(cellname) + 1;
2348 blob.in_size = size;
2351 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2357 struct ViceIoctl blob;
2360 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2365 blob.in = (char *) 0;
2366 blob.out_size = MAXSIZE;
2369 code = pioctl((char *) 0, VIOCNEWCELL, &blob, 1);
2372 Die(errno, (char *) 0);
2376 printf("Cell servers information refreshed\n");
2383 NewAliasCmd(struct cmd_syndesc *as, char *arock)
2386 struct ViceIoctl blob;
2388 char *aliasName, *realName;
2390 /* Setup and do the NEWALIAS pioctl call */
2391 aliasName = as->parms[0].items->data;
2392 realName = as->parms[1].items->data;
2394 strcpy(tp, aliasName);
2395 tp += strlen(aliasName) + 1;
2396 strcpy(tp, realName);
2397 tp += strlen(realName) + 1;
2399 blob.in_size = tp - space;
2403 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2405 if (errno == EEXIST) {
2407 "%s: cell name `%s' in use by an existing cell.\n", pn,
2419 WhichCellCmd(struct cmd_syndesc *as, char *arock)
2422 struct cmd_item *ti;
2424 char cell[MAXCELLCHARS]="";
2426 SetDotDefault(&as->parms[0].items);
2427 for(ti=as->parms[0].items; ti; ti=ti->next) {
2428 code = GetCell(ti->data, cell);
2430 if (errno == ENOENT)
2431 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2433 Die(errno, ti->data);
2437 printf("File %s lives in cell '%s'\n", ti->data, cell);
2443 WSCellCmd(struct cmd_syndesc *as, char *arock)
2446 struct ViceIoctl blob;
2450 blob.out_size = MAXSIZE;
2453 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2460 printf("This workstation belongs to cell '%s'\n", space);
2466 PrimaryCellCmd(struct cmd_syndesc *as, char *arock)
2468 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2474 MonitorCmd(struct cmd_syndesc *as, char *arock)
2477 struct ViceIoctl blob;
2478 struct cmd_item *ti;
2480 struct hostent *thp;
2484 ti = as->parms[0].items;
2488 if (!strcmp(ti->data, "off")) {
2489 hostAddr = 0xffffffff;
2491 thp = hostutil_GetHostByName(ti->data);
2493 if (!strcmp(ti->data, "localhost")) {
2494 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2495 hostAddr = htonl(0x7f000001);
2497 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2501 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2505 hostAddr = 0; /* means don't set host */
2506 setp = 0; /* aren't setting host */
2509 /* now do operation */
2510 blob.in_size = sizeof(afs_int32);
2511 blob.out_size = sizeof(afs_int32);
2512 blob.in = (char *) &hostAddr;
2513 blob.out = (char *) &hostAddr;
2514 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2520 printf("%s: new monitor host set.\n", pn);
2522 /* now decode old address */
2523 if (hostAddr == 0xffffffff) {
2524 printf("Cache monitoring is currently disabled.\n");
2526 tp = hostutil_GetNameByINet(hostAddr);
2527 printf("Using host %s for monitor services.\n", tp);
2534 SysNameCmd(struct cmd_syndesc *as, char *arock)
2537 struct ViceIoctl blob;
2538 struct cmd_item *ti;
2539 char *input = space;
2542 ti = as->parms[0].items;
2546 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2551 fprintf (stderr,"Permission denied: requires root access.\n");
2559 blob.out_size = MAXSIZE;
2560 blob.in_size = sizeof(afs_int32);
2561 memcpy(input, &setp, sizeof(afs_int32));
2562 input += sizeof(afs_int32);
2563 for (; ti; ti = ti->next) {
2565 blob.in_size += strlen(ti->data) + 1;
2566 if (blob.in_size > MAXSIZE) {
2567 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2568 setp > 1 ? "s" : "");
2571 strcpy(input, ti->data);
2572 input += strlen(ti->data);
2575 memcpy(space, &setp, sizeof(afs_int32));
2576 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2582 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2587 memcpy(&setp, input, sizeof(afs_int32));
2588 input += sizeof(afs_int32);
2590 fprintf(stderr,"No sysname name value was found\n");
2594 printf("Current sysname%s is", setp > 1 ? " list" : "");
2595 for (; setp > 0; --setp ) {
2596 printf(" \'%s\'", input);
2597 input += strlen(input) + 1;
2603 static char *exported_types[] = {"null", "nfs", ""};
2604 static int ExportAfsCmd(struct cmd_syndesc *as, char *arock)
2607 struct ViceIoctl blob;
2608 struct cmd_item *ti;
2609 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
2610 int exportcall, pwsync = 0, smounts = 0;
2614 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2619 fprintf (stderr,"Permission denied: requires root access.\n");
2624 ti = as->parms[0].items;
2625 if (strcmp(ti->data, "nfs") == 0)
2626 type = 0x71; /* NFS */
2629 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2632 ti = as->parms[1].items;
2634 if (strcmp(ti->data, "on") == 0)
2636 else if (strcmp(ti->data, "off") == 0)
2639 fprintf(stderr, "Illegal argument %s\n", ti->data);
2644 if (ti = as->parms[2].items) { /* -noconvert */
2645 if (strcmp(ti->data, "on") == 0)
2647 else if (strcmp(ti->data, "off") == 0)
2650 fprintf(stderr, "Illegal argument %s\n", ti->data);
2654 if (ti = as->parms[3].items) { /* -uidcheck */
2655 if (strcmp(ti->data, "on") == 0)
2657 else if (strcmp(ti->data, "off") == 0)
2660 fprintf(stderr, "Illegal argument %s\n", ti->data);
2664 if (ti = as->parms[4].items) { /* -submounts */
2665 if (strcmp(ti->data, "on") == 0)
2667 else if (strcmp(ti->data, "off") == 0)
2670 fprintf(stderr, "Illegal argument %s\n", ti->data);
2674 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2677 blob.in = (char *) &exportcall;
2678 blob.in_size = sizeof(afs_int32);
2679 blob.out = (char *) &exportcall;
2680 blob.out_size = sizeof(afs_int32);
2681 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2683 if (errno == ENODEV) {
2685 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
2692 if (exportcall & 1) {
2693 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
2694 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
2695 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
2696 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
2698 printf("'%s' translator is disabled\n", exported_types[type]);
2707 GetCellCmd(struct cmd_syndesc *as, char *arock)
2710 struct ViceIoctl blob;
2711 struct afsconf_cell info;
2712 struct cmd_item *ti;
2719 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
2720 for(ti=as->parms[0].items; ti; ti=ti->next) {
2722 blob.out_size = sizeof(args);
2723 blob.out = (caddr_t) &args;
2724 code = GetCellName(ti->data, &info);
2729 blob.in_size = 1+strlen(info.name);
2730 blob.in = info.name;
2731 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2733 if (errno == ENOENT)
2734 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
2736 Die(errno, info.name);
2740 printf("Cell %s status: ", info.name);
2746 printf("no setuid allowed");
2748 printf("setuid allowed");
2750 printf(", using old VLDB");
2756 static int SetCellCmd(struct cmd_syndesc *as, char *arock)
2759 struct ViceIoctl blob;
2760 struct afsconf_cell info;
2761 struct cmd_item *ti;
2769 /* Check arguments. */
2770 if (as->parms[1].items && as->parms[2].items) {
2771 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2775 /* figure stuff to set */
2781 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2786 fprintf (stderr,"Permission denied: requires root access.\n");
2791 if (! as->parms[1].items)
2792 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
2794 /* set stat for all listed cells */
2795 for(ti=as->parms[0].items; ti; ti=ti->next) {
2797 code = GetCellName(ti->data, &info);
2802 strcpy(args.cname, info.name);
2803 blob.in_size = sizeof(args);
2804 blob.in = (caddr_t) &args;
2806 blob.out = (caddr_t) 0;
2807 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2809 Die(errno, info.name); /* XXX added cell name to Die() call */
2818 GetCellName(char *cellNamep, struct afsconf_cell *infop)
2820 strcpy(infop->name, cellNamep);
2825 VLDBInit(int noAuthFlag, struct afsconf_cell *infop)
2829 #else /* not WIN32 */
2831 GetCellName(char *cellName, struct afsconf_cell *info)
2833 struct afsconf_dir *tdir;
2836 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_CLIENTNAME);
2839 "Could not process files in configuration directory (%s).\n",
2840 AFSDIR_CLIENT_ETC_CLIENTNAME);
2844 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2846 fprintf(stderr,"fs: cell %s not in %s/CellServDB\n", cellName,
2847 AFSDIR_CLIENT_ETC_CLIENTNAME);
2856 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2860 code = ugen_ClientInit(noAuthFlag, AFSDIR_CLIENT_ETC_DIRPATH,
2861 info->name, 0, &uclient,
2862 NULL, pn, rxkad_clear,
2863 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
2864 0, 0, USER_SERVICE_ID);
2868 #endif /* not WIN32 */
2870 static struct ViceIoctl gblob;
2871 static int debug = 0;
2873 * here follow some routines in suport of the setserverprefs and
2874 * getserverprefs commands. They are:
2875 * SetPrefCmd "top-level" routine
2876 * addServer adds a server to the list of servers to be poked into the
2877 * kernel. Will poke the list into the kernel if it threatens
2879 * pokeServers pokes the existing list of servers and ranks into the kernel
2880 * GetPrefCmd reads the Cache Manager's current list of server ranks
2889 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2891 ssp = (cm_SSetPref_t *)space;
2892 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2898 * returns -1 if error message printed,
2900 * errno value if error and no error message printed
2907 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2908 if (code && (errno == EINVAL)) {
2909 struct setspref *ssp;
2910 ssp = (struct setspref *)gblob.in;
2911 if (!(ssp->flags & DBservers)) {
2912 gblob.in = (void *)&(ssp->servers[0]);
2913 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2914 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2915 return code ? errno : 0;
2918 "This cache manager does not support VL server preferences.\n");
2922 return code ? errno : 0;
2928 addServer(char *name, unsigned short rank)
2933 struct hostent *thostent;
2937 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2939 #define MAXUSHORT ((unsigned short) ~0)
2944 thostent = hostutil_GetHostByName(name);
2946 fprintf (stderr, "%s: couldn't resolve name.\n", name);
2950 ssp = (cm_SSetPref_t *)(gblob.in);
2952 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
2953 code = pokeServers();
2954 ssp->num_servers = 0;
2957 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
2958 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
2959 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2960 gblob.in_size += sizeof(cm_SPref_t);
2963 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
2969 * returns -1 if error message printed,
2971 * errno value if error and no error message printed
2974 addServer(char *name, afs_int32 rank)
2977 struct setspref *ssp;
2979 struct hostent *thostent;
2985 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2987 #define MAXUSHORT ((unsigned short) ~0)
2991 thostent = hostutil_GetHostByName(name);
2993 fprintf(stderr, "%s: couldn't resolve name.\n", name);
2997 ssp = (struct setspref *)(gblob.in);
2999 for (t = 0; thostent->h_addr_list[t]; t++) {
3000 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3001 code = pokeServers();
3004 ssp->num_servers = 0;
3007 sp = (struct spref *)(gblob.in + gblob.in_size);
3008 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3009 sizeof(afs_uint32));
3010 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3011 gblob.in_size += sizeof(struct spref);
3015 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3016 name, sp->rank, sp->server.s_addr);
3024 static BOOL IsWindowsNT (void)
3026 static BOOL fChecked = FALSE;
3027 static BOOL fIsWinNT = FALSE;
3031 OSVERSIONINFO Version;
3035 memset (&Version, 0x00, sizeof(Version));
3036 Version.dwOSVersionInfoSize = sizeof(Version);
3038 if (GetVersionEx (&Version))
3040 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3050 SetPrefCmd(struct cmd_syndesc *as, char * arock)
3054 struct cmd_item *ti;
3059 ssp = (cm_SSetPref_t *)space;
3061 ssp->num_servers = 0;
3062 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
3065 gblob.out_size = MAXSIZE;
3068 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3074 ti = as->parms[2].items; /* -file */
3076 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3077 if (!(infd = fopen(ti->data,"r" ))) {
3079 Die(errno,ti->data);
3082 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3083 code = addServer (name, (unsigned short) rank);
3087 ti = as->parms[3].items; /* -stdin */
3089 while ( scanf("%79s%ld", name, &rank) != EOF) {
3090 code = addServer (name, (unsigned short) rank);
3094 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3099 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3101 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3105 code = pokeServers();
3107 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3109 ssp = (cm_SSetPref_t *)space;
3110 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
3112 ssp->flags = CM_SPREF_VLONLY;
3113 ssp->num_servers = 0;
3115 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3120 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3122 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3127 if (as->parms[1].items) {
3129 printf("now poking vlservers\n");
3130 code = pokeServers();
3140 SetPrefCmd(struct cmd_syndesc *as, char *arock)
3144 struct cmd_item *ti;
3147 struct setspref *ssp;
3148 int error = 0; /* -1 means error message printed,
3149 * >0 means errno value for unprinted message */
3151 ssp = (struct setspref *)space;
3153 ssp->num_servers = 0;
3154 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3157 gblob.out_size = MAXSIZE;
3161 fprintf(stderr, "Permission denied: requires root access.\n");
3165 ti = as->parms[2].items; /* -file */
3168 fprintf(stderr, "opening file %s\n", ti->data);
3169 if (!(infd = fopen(ti->data, "r"))) {
3173 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3174 code = addServer(name, (unsigned short)rank);
3181 ti = as->parms[3].items; /* -stdin */
3183 while (scanf("%79s%ld", name, &rank) != EOF) {
3184 code = addServer(name, (unsigned short)rank);
3190 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3195 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3199 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3203 code = pokeServers();
3207 printf("now working on vlservers, code=%d\n", code);
3209 ssp = (struct setspref *)space;
3210 ssp->flags = DBservers;
3211 ssp->num_servers = 0;
3212 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3215 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3220 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3224 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3229 if (as->parms[1].items) {
3231 printf("now poking vlservers\n");
3232 code = pokeServers();
3240 return error ? 1 : 0;
3246 GetPrefCmd(struct cmd_syndesc *as, char *arock)
3249 struct cmd_item *ti;
3250 char *name, tbuffer[20];
3255 struct ViceIoctl blob;
3256 struct cm_SPrefRequest *in;
3257 struct cm_SPrefInfo *out;
3261 ti = as->parms[0].items; /* -file */
3263 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3264 if (!(outfd = freopen(ti->data,"w",stdout))) {
3265 Die(errno,ti->data);
3270 ti = as->parms[1].items; /* -numeric */
3272 ti = as->parms[2].items; /* -vlservers */
3273 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3274 /* ti = as->parms[3].items; -cell */
3276 in = (struct cm_SPrefRequest *)space;
3280 blob.in_size=sizeof(struct cm_SPrefRequest);
3281 blob.in = (char *)in;
3283 blob.out_size = MAXSIZE;
3285 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3286 in->flags = vlservers;
3288 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3290 perror("getserverprefs pioctl");
3294 out = (struct cm_SPrefInfo *) blob.out;
3296 for (i=0;i<out->num_servers;i++) {
3298 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3301 addr = ntohl(out->servers[i].host.s_addr);
3302 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3303 (addr>>8) & 0xff, addr & 0xff);
3306 printf ("%-50s %5u\n",name,out->servers[i].rank);
3309 in->offset = out->next_offset;
3311 } while (!code && out->next_offset > 0);
3317 GetPrefCmd(struct cmd_syndesc *as, char *arock)
3320 struct cmd_item *ti;
3321 char *name, tbuffer[20];
3322 afs_int32 rank, addr;
3326 struct ViceIoctl blob;
3327 struct sprefrequest *in;
3328 struct sprefinfo *out;
3331 ti = as->parms[0].items; /* -file */
3334 fprintf(stderr, "opening file %s\n", ti->data);
3335 if (!(outfd = freopen(ti->data, "w", stdout))) {
3341 ti = as->parms[1].items; /* -numeric */
3343 ti = as->parms[2].items; /* -vlservers */
3344 vlservers |= (ti ? DBservers : 0);
3345 /* ti = as->parms[3].items; -cell */
3347 in = (struct sprefrequest *)space;
3351 blob.in_size = sizeof(struct sprefrequest);
3352 blob.in = (char *)in;
3354 blob.out_size = MAXSIZE;
3357 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3358 in->flags = vlservers;
3360 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3362 perror("getserverprefs pioctl");
3366 out = (struct sprefinfo *)blob.out;
3368 for (i = 0; i < out->num_servers; i++) {
3370 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3372 addr = ntohl(out->servers[i].server.s_addr);
3373 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3374 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3377 printf("%-50s %5u\n", name, out->servers[i].rank);
3380 in->offset = out->next_offset;
3381 } while (out->next_offset > 0);
3388 TraceCmd(struct cmd_syndesc *asp, char *arock)
3391 struct ViceIoctl blob;
3397 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3402 fprintf (stderr,"Permission denied: requires root access.\n");
3407 if ((asp->parms[0].items && asp->parms[1].items)) {
3408 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
3412 /* determine if we're turning this tracing on or off */
3414 if (asp->parms[0].items)
3415 inValue = 3; /* enable */
3416 else if (asp->parms[1].items)
3417 inValue = 2; /* disable */
3418 if (asp->parms[2].items)
3419 inValue |= 4; /* do reset */
3420 if (asp->parms[3].items)
3421 inValue |= 8; /* dump */
3423 blob.in_size = sizeof(long);
3424 blob.in = (char *) &inValue;
3425 blob.out_size = sizeof(long);
3426 blob.out = (char *) &outValue;
3428 code = pioctl(NULL, VIOC_TRACECTL, &blob, 1);
3435 printf("AFS tracing enabled.\n");
3437 printf("AFS tracing disabled.\n");
3442 static void sbusage(void)
3444 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
3445 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
3448 /* fs sb -kbytes 9999 -files *.o -default 64 */
3450 StoreBehindCmd(struct cmd_syndesc *as, char *arock)
3453 struct ViceIoctl blob;
3454 struct cmd_item *ti;
3455 struct sbstruct tsb, tsb2;
3463 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3468 tsb.sb_thisfile = -1;
3469 ti = as->parms[0].items; /* -kbytes */
3471 if (!as->parms[1].items) {
3472 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3476 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3477 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3478 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3484 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3485 ti = as->parms[2].items; /* -allfiles */
3487 allfiles = strtol(ti->data, &t, 10) * 1024;
3488 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3489 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3495 /* -verbose or -file only or no options */
3496 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3497 || (!as->parms[0].items && !as->parms[1].items
3498 && !as->parms[2].items))
3501 blob.in = (char *)&tsb;
3502 blob.out = (char *)&tsb2;
3503 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3504 memset(&tsb2, 0, sizeof(tsb2));
3506 /* once per -file */
3507 for (ti = as->parms[1].items; ti; ti = ti->next) {
3508 /* Do this solely to see if the file is there */
3509 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3511 Die(errno, ti->data);
3516 code = pioctl(ti->data, VIOC_STOREBEHIND, &blob, 1);
3518 Die(errno, ti->data);
3523 if (verbose && (blob.out_size == sizeof(tsb2))) {
3524 if (tsb2.sb_thisfile == -1) {
3525 fprintf(stdout, "Will store %s according to default.\n",
3529 "Will store up to %d kbytes of %s asynchronously.\n",
3530 (tsb2.sb_thisfile / 1024), ti->data);
3535 /* If no files - make at least one pioctl call, or
3536 * set the allfiles default if we need to.
3538 if (!as->parms[1].items || (allfiles != -1)) {
3539 tsb.sb_default = allfiles;
3540 code = pioctl(0, VIOC_STOREBEHIND, &blob, 1);
3542 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3547 /* Having no arguments also reports the default store asynchrony */
3548 if (verbose && (blob.out_size == sizeof(tsb2))) {
3549 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3550 (tsb2.sb_default / 1024));
3557 SetCryptCmd(struct cmd_syndesc *as, char *arock)
3559 afs_int32 code = 0, flag;
3560 struct ViceIoctl blob;
3565 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3570 tp = as->parms[0].items->data;
3571 if (strcmp(tp, "on") == 0)
3573 else if (strcmp(tp, "off") == 0)
3576 fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3580 blob.in = (char *) &flag;
3581 blob.in_size = sizeof(flag);
3583 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3590 GetCryptCmd(struct cmd_syndesc *as, char *arock)
3592 afs_int32 code = 0, flag;
3593 struct ViceIoctl blob;
3598 blob.out_size = sizeof(flag);
3601 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3607 memcpy(&flag, tp, sizeof(afs_int32));
3608 printf("Security level is currently ");
3610 printf("crypt (data security).\n");
3618 MemDumpCmd(struct cmd_syndesc *asp, char *arock)
3621 struct ViceIoctl blob;
3625 if ((asp->parms[0].items && asp->parms[1].items)) {
3626 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
3630 /* determine if we're turning this tracing on or off */
3632 if (asp->parms[0].items)
3633 inValue = 1; /* begin */
3634 else if (asp->parms[1].items)
3635 inValue = 0; /* end */
3637 blob.in_size = sizeof(long);
3638 blob.in = (char *) &inValue;
3639 blob.out_size = sizeof(long);
3640 blob.out = (char *) &outValue;
3642 code = pioctl(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
3648 if (outValue) printf("AFS memdump begin.\n");
3649 else printf("AFS memdump end.\n");
3655 CSCPolicyCmd(struct cmd_syndesc *asp, char *arock)
3657 struct cmd_item *ti;
3661 for(ti=asp->parms[0].items; ti;ti=ti->next) {
3673 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
3674 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
3677 REG_OPTION_NON_VOLATILE,
3683 if ( hkCSCPolicy == NULL ) {
3684 fprintf (stderr,"Permission denied: requires Administrator access.\n");
3689 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3690 RegCloseKey(hkCSCPolicy);
3696 if (asp->parms[1].items)
3698 if (asp->parms[2].items)
3699 policy = "programs";
3700 if (asp->parms[3].items)
3701 policy = "documents";
3702 if (asp->parms[4].items)
3705 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, strlen(policy)+1);
3707 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
3708 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
3712 DWORD dwIndex, dwPolicies;
3713 char policyName[256];
3714 DWORD policyNameLen;
3719 /* list current csc policies */
3721 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
3722 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
3725 REG_OPTION_NON_VOLATILE,
3726 KEY_READ|KEY_QUERY_VALUE,
3731 RegQueryInfoKey( hkCSCPolicy,
3733 NULL, /* lpcClass */
3734 NULL, /* lpReserved */
3735 NULL, /* lpcSubKeys */
3736 NULL, /* lpcMaxSubKeyLen */
3737 NULL, /* lpcMaxClassLen */
3738 &dwPolicies, /* lpcValues */
3739 NULL, /* lpcMaxValueNameLen */
3740 NULL, /* lpcMaxValueLen */
3741 NULL, /* lpcbSecurityDescriptor */
3742 NULL /* lpftLastWriteTime */
3745 printf("Current CSC policies:\n");
3746 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
3748 policyNameLen = sizeof(policyName);
3749 policyLen = sizeof(policy);
3750 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
3751 &dwType, policy, &policyLen);
3753 printf(" %s = %s\n", policyName, policy);
3757 RegCloseKey(hkCSCPolicy);
3762 /* get clients interface addresses */
3764 GetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
3767 struct cmd_item *ti;
3769 struct ViceIoctl blob;
3770 struct sprefrequest *in;
3771 struct sprefinfo *out;
3773 in = (struct sprefrequest *)space;
3777 blob.in_size = sizeof(struct sprefrequest);
3778 blob.in = (char *)in;
3780 blob.out_size = MAXSIZE;
3783 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3784 /* returns addr in network byte order */
3785 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3787 perror("getClientInterfaceAddr pioctl");
3793 out = (struct sprefinfo *)blob.out;
3794 for (i = 0; i < out->num_servers; i++) {
3797 addr = ntohl(out->servers[i].server.s_addr);
3798 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3799 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3800 printf("%-50s\n", tbuffer);
3802 in->offset = out->next_offset;
3804 } while (out->next_offset > 0);
3810 SetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
3812 afs_int32 code, addr;
3813 struct cmd_item *ti;
3815 struct ViceIoctl blob;
3816 struct setspref *ssp;
3817 int sizeUsed = 0, i, flag;
3818 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3822 ssp = (struct setspref *)space;
3823 ssp->num_servers = 0;
3826 blob.out_size = MAXSIZE;
3829 fprintf(stderr, "Permission denied: requires root access.\n");
3833 /* extract all existing interface addresses */
3834 existNu = rx_getAllAddr(existingAddr, 1024);
3838 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3839 for (ti = as->parms[0].items; ti; ti = ti->next) {
3840 if (sizeUsed >= sizeof(space)) {
3841 fprintf(stderr, "No more space\n");
3844 addr = extractAddr(ti->data, 20); /* network order */
3845 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3846 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
3851 /* see if it is an address that really exists */
3852 for (flag = 0, i = 0; i < existNu; i++)
3853 if (existingAddr[i] == addr) {
3857 if (!flag) { /* this is an nonexistent address */
3858 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3862 /* copy all specified addr into ioctl buffer */
3863 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3864 printf("Adding 0x%08x\n", addr);
3866 sizeUsed += sizeof(struct spref);
3868 if (ssp->num_servers < 1) {
3869 fprintf(stderr, "No addresses specified\n");
3872 blob.in_size = sizeUsed - sizeof(struct spref);
3874 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3884 FlushMountCmd(struct cmd_syndesc *as, char *arock)
3887 struct ViceIoctl blob;
3888 struct cmd_item *ti;
3889 char orig_name[1024]; /*Original name, may be modified */
3890 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
3891 char parent_dir[1024]; /*Parent directory of true name */
3892 char *last_component; /*Last component of true name */
3893 struct stat statbuff; /*Buffer for status info */
3894 int link_chars_read; /*Num chars read in readlink() */
3895 int thru_symlink; /*Did we get to a mount point via a symlink? */
3898 for (ti = as->parms[0].items; ti; ti = ti->next) {
3901 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
3904 if (lstat(orig_name, &statbuff) < 0) {
3905 /* if lstat fails, we should still try the pioctl, since it
3906 * may work (for example, lstat will fail, but pioctl will
3907 * work if the volume of offline (returning ENODEV). */
3908 statbuff.st_mode = S_IFDIR; /* lie like pros */
3912 * The lstat succeeded. If the given file is a symlink, substitute
3913 * the file name with the link name.
3915 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
3918 * Read name of resolved file.
3920 link_chars_read = readlink(orig_name, true_name, 1024);
3921 if (link_chars_read <= 0) {
3923 "%s: Can't read target name for '%s' symbolic link!\n",
3930 * Add a trailing null to what was read, bump the length.
3932 true_name[link_chars_read++] = 0;
3935 * If the symlink is an absolute pathname, we're fine. Otherwise, we
3936 * have to create a full pathname using the original name and the
3937 * relative symlink name. Find the rightmost slash in the original
3938 * name (we know there is one) and splice in the symlink value.
3940 if (true_name[0] != '/') {
3941 last_component = (char *)strrchr(orig_name, '/');
3942 strcpy(++last_component, true_name);
3943 strcpy(true_name, orig_name);
3946 strcpy(true_name, orig_name);
3949 * Find rightmost slash, if any.
3951 last_component = (char *)strrchr(true_name, '/');
3952 if (last_component) {
3954 * Found it. Designate everything before it as the parent directory,
3955 * everything after it as the final component.
3957 strncpy(parent_dir, true_name, last_component - true_name);
3958 parent_dir[last_component - true_name] = 0;
3959 last_component++; /*Skip the slash */
3962 * No slash appears in the given file name. Set parent_dir to the current
3963 * directory, and the last component as the given name.
3965 strcpy(parent_dir, ".");
3966 last_component = true_name;
3969 if (strcmp(last_component, ".") == 0
3970 || strcmp(last_component, "..") == 0) {
3972 "%s: you may not use '.' or '..' as the last component\n",
3974 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
3980 blob.in = last_component;
3981 blob.in_size = strlen(last_component) + 1;
3983 memset(space, 0, MAXSIZE);
3985 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
3988 if (errno == EINVAL) {
3989 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
3991 Die(errno, (ti->data ? ti->data : parent_dir));
4000 RxStatProcCmd(struct cmd_syndesc *as, char *arock)
4003 afs_int32 flags = 0;
4004 struct ViceIoctl blob;
4005 struct cmd_item *ti;
4007 if (as->parms[0].items) { /* -enable */
4008 flags |= AFSCALL_RXSTATS_ENABLE;
4010 if (as->parms[1].items) { /* -disable */
4011 flags |= AFSCALL_RXSTATS_DISABLE;
4013 if (as->parms[2].items) { /* -clear */
4014 flags |= AFSCALL_RXSTATS_CLEAR;
4017 fprintf(stderr, "You must specify at least one argument\n");
4021 blob.in = (char *)&flags;
4022 blob.in_size = sizeof(afs_int32);
4025 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4035 RxStatPeerCmd(struct cmd_syndesc *as, char *arock)
4038 afs_int32 flags = 0;
4039 struct ViceIoctl blob;
4040 struct cmd_item *ti;
4042 if (as->parms[0].items) { /* -enable */
4043 flags |= AFSCALL_RXSTATS_ENABLE;
4045 if (as->parms[1].items) { /* -disable */
4046 flags |= AFSCALL_RXSTATS_DISABLE;
4048 if (as->parms[2].items) { /* -clear */
4049 flags |= AFSCALL_RXSTATS_CLEAR;
4052 fprintf(stderr, "You must specify at least one argument\n");
4056 blob.in = (char *)&flags;
4057 blob.in_size = sizeof(afs_int32);
4060 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4071 #include "AFS_component_version_number.c"
4074 main(int argc, char **argv)
4077 struct cmd_syndesc *ts;
4079 #ifdef AFS_AIX32_ENV
4081 * The following signal action for AIX is necessary so that in case of a
4082 * crash (i.e. core is generated) we can include the user's data section
4083 * in the core dump. Unfortunately, by default, only a partial core is
4084 * generated which, in many cases, isn't too useful.
4086 struct sigaction nsa;
4088 sigemptyset(&nsa.sa_mask);
4089 nsa.sa_handler = SIG_DFL;
4090 nsa.sa_flags = SA_FULLDUMP;
4091 sigaction(SIGSEGV, &nsa, NULL);
4096 WSAStartup(0x0101, &WSAjunk);
4099 /* try to find volume location information */
4103 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0,
4104 "get client network interface addresses");
4105 cmd_CreateAlias(ts, "gc");
4107 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0,
4108 "set client network interface addresses");
4109 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
4110 "client network interfaces");
4111 cmd_CreateAlias(ts, "sc");
4114 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks");
4115 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
4116 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
4117 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
4118 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
4119 cmd_CreateAlias(ts, "sp");
4121 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks");
4122 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
4123 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4124 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
4125 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
4126 cmd_CreateAlias(ts, "gp");
4128 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
4129 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4130 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
4131 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
4132 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
4133 parm_setacl_id = ts->nParms;
4134 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
4135 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
4136 cmd_CreateAlias(ts, "sa");
4138 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list");
4139 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4140 parm_listacl_id = ts->nParms;
4141 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4142 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4143 cmd_CreateAlias(ts, "la");
4145 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list");
4146 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4148 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list");
4149 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
4150 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
4151 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
4152 parm_copyacl_id = ts->nParms;
4153 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4154 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4156 cmd_CreateAlias(ts, "ca");
4158 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
4159 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4162 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0,
4163 "flush mount symlink from cache");
4164 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4167 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
4168 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4169 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
4171 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
4173 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
4174 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
4175 cmd_CreateAlias(ts, "sv");
4177 ts = cmd_CreateSyntax("messages", MessagesCmd, 0, "control Cache Manager messages");
4178 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
4180 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display file/volume status");
4181 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4182 cmd_CreateAlias(ts, "lv");
4183 cmd_CreateAlias(ts, "listvol");
4185 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
4186 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4187 cmd_CreateAlias(ts, "lq");
4189 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage");
4190 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4191 cmd_CreateAlias(ts, "df");
4193 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
4194 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4196 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
4197 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4199 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
4200 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
4201 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
4202 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
4203 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
4204 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
4210 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
4214 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
4215 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4217 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers");
4218 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
4219 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
4220 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
4221 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
4223 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings");
4224 cmd_CreateAlias(ts, "checkbackups");
4227 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size");
4228 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
4229 cmd_CreateAlias(ts, "cachesize");
4231 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
4233 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info");
4235 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells");
4236 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4238 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
4239 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
4240 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
4242 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
4244 cmd_CreateAlias(ts, "sq");
4246 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
4248 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
4249 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
4250 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
4252 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
4254 * Turn this on only if you wish to be able to talk to a server which is listening
4255 * on alternative ports. This is not intended for general use and may not be
4256 * supported in the cache manager. It is not a way to run two servers at the
4257 * same host, since the cache manager cannot properly distinguish those two hosts.
4259 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
4260 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
4263 ts = cmd_CreateSyntax("newalias", NewAliasCmd, 0,
4264 "configure new cell alias");
4265 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
4266 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
4269 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
4270 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4272 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
4273 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4275 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
4278 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
4281 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, "set cache monitor host address");
4282 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
4283 cmd_CreateAlias(ts, "mariner");
4286 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
4287 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4289 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
4290 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4291 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
4292 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
4294 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume");
4295 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4297 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value");
4298 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
4300 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS");
4301 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
4302 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
4303 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
4304 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
4305 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
4308 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
4309 "store to server after file close");
4310 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
4311 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
4312 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
4313 cmd_CreateAlias(ts, "sb");
4315 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag");
4316 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
4318 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "get cache manager encryption flag");
4321 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
4322 "Manage per process RX statistics");
4323 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4324 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4325 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4327 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0,
4328 "Manage per peer RX statistics");
4329 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4330 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4331 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4333 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, 0, "configure callback connection address");
4334 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
4337 ts = cmd_CreateSyntax("trace", TraceCmd, 0, "enable or disable CM tracing");
4338 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
4339 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
4340 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
4341 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
4342 cmd_CreateAlias(ts, "tr");
4344 ts = cmd_CreateSyntax("memdump", MemDumpCmd, 0, "dump memory allocs in debug builds");
4345 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
4346 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
4348 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, 0, "change client side caching policy for AFS shares");
4349 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
4350 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
4351 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
4352 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
4353 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
4355 code = cmd_Dispatch(argc, argv);
4360 #endif /* not WIN32 */
4366 Die(int code, char *filename)
4369 if (code == EINVAL) {
4371 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
4373 fprintf(stderr,"%s: Invalid argument.\n", pn);
4375 else if (code == ENOENT) {
4377 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
4379 fprintf(stderr,"%s: no such file returned\n", pn);
4381 else if (code == EROFS)
4382 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
4383 else if (code == EACCES || code == EPERM) {
4385 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
4387 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
4389 else if (code == ENODEV) {
4390 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
4392 else if (code == ESRCH) {
4393 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
4395 else if (code == EPIPE) {
4396 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
4398 else if (code == EFBIG) {
4399 fprintf(stderr,"%s: Cache size too large.\n", pn);
4401 else if (code == ETIMEDOUT) {
4403 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
4405 fprintf(stderr,"%s: Connection timed out", pn);
4409 fprintf(stderr,"%s:'%s'", pn, filename);
4411 fprintf(stderr,"%s", pn);
4413 fprintf(stderr, ": code 0x%x\n", code);
4414 #else /* not WIN32 */
4415 fprintf(stderr,": %s\n", error_message(code));
4416 #endif /* not WIN32 */