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>
21 #include <rx/rx_globals.h>
36 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
37 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
39 static char space[MAXSIZE];
40 static char tspace[1024];
43 static struct ubik_client *uclient;
44 #endif /* not WIN32 */
46 static MemDumpCmd(struct cmd_syndesc *asp);
47 static CSCPolicyCmd(struct cmd_syndesc *asp);
49 extern afs_int32 VL_GetEntryByNameO();
51 static char pn[] = "fs";
52 static int rxInitDone = 0;
56 #define MAXCELLCHARS 64
57 #define MAXHOSTCHARS 64
58 #define MAXHOSTSPERCELL 8
61 char name[MAXCELLCHARS];
64 struct sockaddr_in hostAddr[MAXHOSTSPERCELL];
65 char hostName[MAXHOSTSPERCELL][MAXHOSTCHARS];
71 * Character to use between name and rights in printed representation for
74 #define DFS_SEPARATOR ' '
76 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
79 int dfs; /* Originally true if a dfs acl; now also the type
80 of the acl (1, 2, or 3, corresponding to object,
81 initial dir, or initial object). */
82 sec_rgy_name_t cell; /* DFS cell name */
85 struct AclEntry *pluslist;
86 struct AclEntry *minuslist;
90 struct AclEntry *next;
97 ZapList(acl->pluslist);
98 ZapList(acl->minuslist);
109 if (t >= 'A' && t <= 'Z') t += 0x20;
110 if (u >= 'A' && u <= 'Z') u += 0x20;
111 if (t != u) return 1;
112 if (t == 0) return 0;
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 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.
154 struct cmd_syndesc *as;
155 int id; /* Offset of -id switch; -if is next switch */
159 if (as->parms[id].items) {
162 if (as->parms[id + 1].items) {
168 "%s: you may specify either -id or -if, but not both switches\n",
175 void PRights (arights, dfs)
176 register afs_int32 arights;
180 if (arights & PRSFS_READ) printf("r");
181 if (arights & PRSFS_LOOKUP) printf("l");
182 if (arights & PRSFS_INSERT) printf("i");
183 if (arights & PRSFS_DELETE) printf("d");
184 if (arights & PRSFS_WRITE) printf("w");
185 if (arights & PRSFS_LOCK) printf("k");
186 if (arights & PRSFS_ADMINISTER) printf("a");
187 if (arights & PRSFS_USR0) printf("A");
188 if (arights & PRSFS_USR1) printf("B");
189 if (arights & PRSFS_USR2) printf("C");
190 if (arights & PRSFS_USR3) printf("D");
191 if (arights & PRSFS_USR4) printf("E");
192 if (arights & PRSFS_USR5) printf("F");
193 if (arights & PRSFS_USR6) printf("G");
194 if (arights & PRSFS_USR7) printf("H");
196 if (arights & DFS_READ) printf("r"); else printf("-");
197 if (arights & DFS_WRITE) printf("w"); else printf("-");
198 if (arights & DFS_EXECUTE) printf("x"); else printf("-");
199 if (arights & DFS_CONTROL) printf("c"); else printf("-");
200 if (arights & DFS_INSERT) printf("i"); else printf("-");
201 if (arights & DFS_DELETE) printf("d"); else printf("-");
202 if (arights & (DFS_USRALL)) printf("+");
203 if (arights & DFS_USR0) printf("A");
204 if (arights & DFS_USR1) printf("B");
205 if (arights & DFS_USR2) printf("C");
206 if (arights & DFS_USR3) printf("D");
207 if (arights & DFS_USR4) printf("E");
208 if (arights & DFS_USR5) printf("F");
209 if (arights & DFS_USR6) printf("G");
210 if (arights & DFS_USR7) printf("H");
214 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
215 static int InAFS(apath)
216 register char *apath; {
217 struct ViceIoctl blob;
218 register afs_int32 code;
221 blob.out_size = MAXSIZE;
224 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
226 if ((errno == EINVAL) || (errno == ENOENT)) return 0;
231 /* return a static pointer to a buffer */
232 static char *Parent(apath)
235 strcpy(tspace, apath);
236 tp = strrchr(tspace, '\\');
238 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
241 fs_ExtractDriveLetter(apath, tspace);
247 enum rtype {add, destroy, deny};
249 afs_int32 Convert(arights, dfs, rtypep)
250 register char *arights;
258 *rtypep = add; /* add rights, by default */
261 if (!strcmp(arights, "null")) {
265 if (!strcmp(arights,"read")) return DFS_READ | DFS_EXECUTE;
266 if (!strcmp(arights, "write")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE;
267 if (!strcmp(arights, "all")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE | DFS_CONTROL;
269 if (!strcmp(arights,"read")) return PRSFS_READ | PRSFS_LOOKUP;
270 if (!strcmp(arights, "write")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK;
271 if (!strcmp(arights, "mail")) return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
272 if (!strcmp(arights, "all")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
274 if (!strcmp(arights, "none")) {
275 *rtypep = destroy; /* Remove entire entry */
278 len = strlen(arights);
283 if (tc == '-') continue;
284 else if (tc == 'r') mode |= DFS_READ;
285 else if (tc == 'w') mode |= DFS_WRITE;
286 else if (tc == 'x') mode |= DFS_EXECUTE;
287 else if (tc == 'c') mode |= DFS_CONTROL;
288 else if (tc == 'i') mode |= DFS_INSERT;
289 else if (tc == 'd') mode |= DFS_DELETE;
290 else if (tc == 'A') mode |= DFS_USR0;
291 else if (tc == 'B') mode |= DFS_USR1;
292 else if (tc == 'C') mode |= DFS_USR2;
293 else if (tc == 'D') mode |= DFS_USR3;
294 else if (tc == 'E') mode |= DFS_USR4;
295 else if (tc == 'F') mode |= DFS_USR5;
296 else if (tc == 'G') mode |= DFS_USR6;
297 else if (tc == 'H') mode |= DFS_USR7;
299 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n", pn, tc);
303 if (tc == 'r') mode |= PRSFS_READ;
304 else if (tc == 'l') mode |= PRSFS_LOOKUP;
305 else if (tc == 'i') mode |= PRSFS_INSERT;
306 else if (tc == 'd') mode |= PRSFS_DELETE;
307 else if (tc == 'w') mode |= PRSFS_WRITE;
308 else if (tc == 'k') mode |= PRSFS_LOCK;
309 else if (tc == 'a') mode |= PRSFS_ADMINISTER;
310 else if (tc == 'A') mode |= PRSFS_USR0;
311 else if (tc == 'B') mode |= PRSFS_USR1;
312 else if (tc == 'C') mode |= PRSFS_USR2;
313 else if (tc == 'D') mode |= PRSFS_USR3;
314 else if (tc == 'E') mode |= PRSFS_USR4;
315 else if (tc == 'F') mode |= PRSFS_USR5;
316 else if (tc == 'G') mode |= PRSFS_USR6;
317 else if (tc == 'H') mode |= PRSFS_USR7;
319 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn, tc);
327 struct AclEntry *FindList (alist, aname)
329 register struct AclEntry *alist; {
331 if (!foldcmp(alist->name, aname)) return alist;
337 /* if no parm specified in a particular slot, set parm to be "." instead */
338 static void SetDotDefault(aitemp)
339 struct cmd_item **aitemp; {
340 register struct cmd_item *ti;
341 if (*aitemp) return; /* already has value */
342 /* otherwise, allocate an item representing "." */
343 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
344 ti->next = (struct cmd_item *) 0;
345 ti->data = (char *) malloc(2);
346 strcpy(ti->data, ".");
350 void ChangeList (al, plus, aname, arights)
353 afs_int32 arights, plus; {
354 struct AclEntry *tlist;
355 tlist = (plus ? al->pluslist : al->minuslist);
356 tlist = FindList (tlist, aname);
358 /* Found the item already in the list. */
359 tlist->rights = arights;
361 al->nplus -= PruneList(&al->pluslist, al->dfs);
363 al->nminus -= PruneList(&al->minuslist, al->dfs);
366 /* Otherwise we make a new item and plug in the new data. */
367 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
368 strcpy(tlist->name, aname);
369 tlist->rights = arights;
371 tlist->next = al->pluslist;
372 al->pluslist = tlist;
374 if (arights == 0 || arights == -1)
375 al->nplus -= PruneList(&al->pluslist, al->dfs);
378 tlist->next = al->minuslist;
379 al->minuslist = tlist;
381 if (arights == 0) al->nminus -= PruneList(&al->minuslist, al->dfs);
386 struct AclEntry *alist; {
387 register struct AclEntry *tp, *np;
388 for (tp = alist; tp; tp = np) {
394 int PruneList (ae, dfs)
395 struct AclEntry **ae;
398 struct AclEntry **lp;
399 struct AclEntry *te, *ne;
403 for(te = *ae;te;te=ne) {
404 if ((!dfs && te->rights == 0) || te->rights == -1) {
418 char *SkipLine (astr)
419 register char *astr; {
420 while (*astr !='\n') astr++;
426 * Create an empty acl, taking into account whether the acl pointed
427 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
428 * can recover from problems caused by bogus ACL's (in that case, always
429 * assume that the acl is AFS: for DFS, the user can always resort to
430 * acl_edit, but for AFS there may be no other way out).
432 struct Acl *EmptyAcl(astr)
435 register struct Acl *tp;
438 tp = (struct Acl *)malloc(sizeof (struct Acl));
439 tp->nplus = tp->nminus = 0;
440 tp->pluslist = tp->minuslist = 0;
442 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
446 struct Acl *ParseAcl (astr)
448 int nplus, nminus, i, trights;
450 struct AclEntry *first, *last, *tl;
453 ta = (struct Acl *) malloc (sizeof (struct Acl));
455 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
456 astr = SkipLine(astr);
457 sscanf(astr, "%d", &ta->nminus);
458 astr = SkipLine(astr);
465 for(i=0;i<nplus;i++) {
466 sscanf(astr, "%100s %d", tname, &trights);
467 astr = SkipLine(astr);
468 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
469 if (!first) first = tl;
470 strcpy(tl->name, tname);
471 tl->rights = trights;
473 if (last) last->next = tl;
476 ta->pluslist = first;
480 for(i=0;i<nminus;i++) {
481 sscanf(astr, "%100s %d", tname, &trights);
482 astr = SkipLine(astr);
483 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
484 if (!first) first = tl;
485 strcpy(tl->name, tname);
486 tl->rights = trights;
488 if (last) last->next = tl;
491 ta->minuslist = first;
496 void PrintStatus(status, name, motd, offmsg)
497 VolumeStatus *status;
501 printf("Volume status for vid = %u named %s\n",status->Vid, name);
503 printf("Current offline message is %s\n",offmsg);
505 printf("Current message of the day is %s\n",motd);
506 printf("Current disk quota is ");
507 if (status->MaxQuota != 0) printf("%d\n", status->MaxQuota);
508 else printf("unlimited\n");
509 printf("Current blocks used are %d\n",status->BlocksInUse);
510 printf("The partition has %d blocks available out of %d\n\n",status->PartBlocksAvail, status->PartMaxBlocks);
513 void QuickPrintStatus(status, name)
514 VolumeStatus *status;
516 double QuotaUsed =0.0;
517 double PartUsed =0.0;
519 printf("%-25.25s",name);
521 if (status->MaxQuota != 0) {
522 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
523 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
525 printf("no limit%10d", status->BlocksInUse);
527 if (QuotaUsed > 90.0){
528 printf(" %5.0f%%<<", QuotaUsed);
531 else printf(" %5.0f%% ", QuotaUsed);
532 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
533 if (PartUsed > 97.0){
534 printf(" %9.0f%%<<", PartUsed);
537 else printf(" %9.0f%% ", PartUsed);
539 printf("\t<<WARNING\n");
544 void QuickPrintSpace(status, name)
545 VolumeStatus *status;
547 double PartUsed =0.0;
549 printf("%-25.25s",name);
551 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
553 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
554 if (PartUsed > 90.0){
555 printf(" %4.0f%%<<", PartUsed);
558 else printf(" %4.0f%% ", PartUsed);
560 printf("\t<<WARNING\n");
565 char *AclToString(acl)
567 static char mydata[MAXSIZE];
568 char tstring[MAXSIZE];
572 if (acl->dfs) sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
573 else dfsstring[0] = '\0';
574 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
575 for(tp = acl->pluslist;tp;tp=tp->next) {
576 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
577 strcat(mydata, tstring);
579 for(tp = acl->minuslist;tp;tp=tp->next) {
580 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
581 strcat(mydata, tstring);
588 static BOOL fAdmin = FALSE;
589 static BOOL fTested = FALSE;
593 /* Obtain the SID for BUILTIN\Administrators. If this is Windows NT,
594 * expect this call to succeed; if it does not, we can presume that
595 * it's not NT and therefore the user always has administrative
598 PSID psidAdmin = NULL;
599 SID_IDENTIFIER_AUTHORITY auth = SECURITY_NT_AUTHORITY;
603 if (!AllocateAndInitializeSid (&auth, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &psidAdmin))
607 /* Then open our current ProcessToken */
610 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
612 /* We'll have to allocate a chunk of memory to store the list of
613 * groups to which this user belongs; find out how much memory
617 PTOKEN_GROUPS pGroups;
619 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
621 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
623 /* Allocate that buffer, and read in the list of groups. */
624 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
626 /* Look through the list of group SIDs and see if any of them
627 * matches the Administrator group SID.
630 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
632 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid))
650 struct cmd_syndesc *as; {
651 register afs_int32 code;
652 struct ViceIoctl blob;
654 register struct cmd_item *ti, *ui;
658 int idf = getidf(as, parm_setacl_id);
660 if (as->parms[2].items) clear=1;
662 plusp = !(as->parms[3].items);
663 for(ti=as->parms[0].items; ti;ti=ti->next) {
664 blob.out_size = MAXSIZE;
666 blob.in = blob.out = space;
667 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
669 Die(errno, ti->data);
672 ta = ParseAcl(space);
673 if (!plusp && ta->dfs) {
675 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
677 "(you may specify \"null\" to revoke all rights, however)\n");
680 if (clear) ta = EmptyAcl(space);
681 else ta = ParseAcl(space);
683 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
686 fprintf(stderr,"%s: Missing second half of user/access pair.\n", pn);
689 rights = Convert(ui->next->data, ta->dfs, &rtype);
690 if (rtype == destroy && !ta->dfs) {
691 if (!FindList(ta->pluslist, ui->data)) {
692 fprintf(stderr,"%s: Invalid arg (%s doesn't exist in the current acl)\n", pn, ui->data);
696 if (rtype == deny && !ta->dfs) plusp = 0;
697 if (rtype == destroy && ta->dfs) rights = -1;
698 ChangeList(ta, plusp, ui->data, rights);
700 blob.in = AclToString(ta);
702 blob.in_size = 1+strlen(blob.in);
703 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
705 if (errno == EINVAL) {
707 static char *fsenv = 0;
709 fsenv = (char *)getenv("FS_EXPERT");
711 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
714 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
715 "\nPossible reasons for this include:\n\n",
716 " -You may have specified an inappropriate combination of rights.\n",
717 " For example, some DFS-supported filesystems may not allow you to\n",
718 " drop the \"c\" right from \"user_obj\".\n\n",
719 " -A mask_obj may be required (it is likely required by the underlying\n",
720 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
721 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
722 " does not automatically create or update the mask_obj. Try setting\n",
723 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
724 " users or groups. You can do this with a single command, such as\n",
725 " \"fs sa mask_obj all user:somename read\"\n\n",
726 " -A specified user or group may not exist.\n\n",
727 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
728 " This is probably not allowed by the underlying file system.\n\n",
729 " -If you add a user or group to a DFS ACL, remember that it must be\n",
730 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
731 " may be local requirements on the format of the user or group name.\n",
732 " Check with your cell administrator.\n\n",
733 " -Or numerous other possibilities. It would be great if we could be more\n",
734 " precise about the actual problem, but for various reasons, this is\n",
735 " impractical via this interface. If you can't figure it out, you\n",
736 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
737 " whatever is provided). You may get better results. Good luck!\n\n",
738 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
741 fprintf(stderr,"%s: Invalid argument, possible reasons include:\n", pn);
742 fprintf(stderr,"\t-File not in AFS\n");
743 fprintf(stderr,"\t-Too many users on access control list\n");
744 fprintf(stderr,"\t-Tried to add non-existent user to access control list\n");
749 Die(errno, ti->data);
758 static CopyACLCmd(as)
759 struct cmd_syndesc *as; {
760 register afs_int32 code;
761 struct ViceIoctl blob;
764 register struct cmd_item *ti;
766 int idf = getidf(as, parm_copyacl_id);
768 if (as->parms[2].items) clear=1;
770 blob.out_size = MAXSIZE;
772 blob.in = blob.out = space;
773 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
775 Die(errno, as->parms[0].items->data);
778 fa = ParseAcl(space);
780 for (ti=as->parms[1].items; ti;ti=ti->next) {
781 blob.out_size = MAXSIZE;
783 blob.in = blob.out = space;
784 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
786 Die(errno, ti->data);
789 if (clear) ta = EmptyAcl(space);
790 else ta = ParseAcl(space);
792 if (ta->dfs != fa->dfs) {
793 fprintf(stderr, "fs: incompatible file system types: acl not copied to %s; aborted\n", ti->data);
797 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
798 fprintf(stderr, "fs: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", ti->data);
801 strcpy(ta->cell, fa->cell);
803 for (tp = fa->pluslist;tp;tp=tp->next)
804 ChangeList(ta, 1, tp->name, tp->rights);
805 for (tp = fa->minuslist;tp;tp=tp->next)
806 ChangeList(ta, 0, tp->name, tp->rights);
807 blob.in = AclToString(ta);
809 blob.in_size = 1+strlen(blob.in);
810 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
812 if (errno == EINVAL) {
813 fprintf(stderr,"%s: Invalid argument, possible reasons include:\n", pn);
814 fprintf(stderr,"\t-File not in AFS\n");
818 Die(errno, ti->data);
830 /* tell if a name is 23 or -45 (digits or minus digits), which are bad names we must prune */
831 static BadName(aname)
832 register char *aname; {
834 while(tc = *aname++) {
835 /* all must be '-' or digit to be bad */
836 if (tc != '-' && (tc < '0' || tc > '9')) return 0;
842 /* clean up an access control list of its bad entries; return 1 if we made
843 any changes to the list, and 0 otherwise */
846 register struct AclEntry *te, **le, *ne;
849 /* Don't correct DFS ACL's for now */
853 /* prune out bad entries */
854 changes = 0; /* count deleted entries */
856 for(te = aa->pluslist; te; te=ne) {
858 if (BadName(te->name)) {
870 for(te = aa->minuslist; te; te=ne) {
872 if (BadName(te->name)) {
887 /* clean up an acl to not have bogus entries */
888 static CleanACLCmd(as)
889 register struct cmd_syndesc *as; {
890 register afs_int32 code;
891 register struct Acl *ta;
892 struct ViceIoctl blob;
894 register struct cmd_item *ti;
895 register struct AclEntry *te;
897 SetDotDefault(&as->parms[0].items);
898 for(ti=as->parms[0].items; ti; ti=ti->next) {
899 blob.out_size = MAXSIZE;
902 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
904 Die(errno, ti->data);
907 ta = ParseAcl(space);
911 "%s: cleanacl is not supported for DFS access lists.\n",
916 changes = CleanAcl(ta);
919 /* now set the acl */
920 blob.in=AclToString(ta);
921 blob.in_size = strlen(blob.in)+1;
923 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
925 if (errno == EINVAL) {
926 fprintf(stderr,"%s: Invalid argument, possible reasons include\n", pn);
927 fprintf(stderr,"%s: File not in vice or\n", pn);
928 fprintf(stderr,"%s: Too many users on access control list or\n", pn);
932 Die(errno, ti->data);
937 /* now list the updated acl */
938 printf("Access list for %s is now\n", ti->data);
940 if (!ta->dfs) printf("Normal rights:\n");
941 for(te = ta->pluslist;te;te=te->next) {
942 printf(" %s ", te->name);
943 PRights(te->rights, ta->dfs);
947 if (ta->nminus > 0) {
948 printf("Negative rights:\n");
949 for(te = ta->minuslist;te;te=te->next) {
950 printf(" %s ", te->name);
951 PRights(te->rights, ta->dfs);
955 if (ti->next) printf("\n");
958 printf("Access list for %s is fine.\n", ti->data);
963 static ListACLCmd(as)
964 register struct cmd_syndesc *as; {
965 register afs_int32 code;
966 register struct Acl *ta;
967 struct ViceIoctl blob;
969 register struct cmd_item *ti;
970 int idf = getidf(as, parm_listacl_id);
972 SetDotDefault(&as->parms[0].items);
973 for(ti=as->parms[0].items; ti; ti=ti->next) {
975 blob.out_size = MAXSIZE;
977 blob.in = blob.out = space;
978 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
980 Die(errno, ti->data);
983 ta = ParseAcl(space);
986 printf("Access list for %s is\n", ti->data);
989 printf("DFS access list for %s is\n", ti->data);
992 printf("DFS initial directory access list of %s is\n", ti->data);
995 printf("DFS initial file access list of %s is\n", ti->data);
999 printf(" Default cell = %s\n", ta->cell);
1001 separator = ta->dfs? DFS_SEPARATOR : ' ';
1002 if (ta->nplus > 0) {
1003 if (!ta->dfs) printf("Normal rights:\n");
1004 for(te = ta->pluslist;te;te=te->next) {
1005 printf(" %s%c", te->name, separator);
1006 PRights(te->rights, ta->dfs);
1010 if (ta->nminus > 0) {
1011 printf("Negative rights:\n");
1012 for(te = ta->minuslist;te;te=te->next) {
1013 printf(" %s ", te->name);
1014 PRights(te->rights, ta->dfs);
1018 if (ti->next) printf("\n");
1023 static FlushVolumeCmd(as)
1024 register struct cmd_syndesc *as; {
1025 register afs_int32 code;
1026 struct ViceIoctl blob;
1027 register struct cmd_item *ti;
1029 for(ti=as->parms[0].items; ti; ti=ti->next) {
1030 blob.in_size = blob.out_size = 0;
1031 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1033 fprintf(stderr, "Error flushing volume\n");
1034 Die(errno,ti->data);
1042 register struct cmd_syndesc *as; {
1043 register afs_int32 code;
1044 struct ViceIoctl blob;
1046 register struct cmd_item *ti;
1049 for(ti=as->parms[0].items; ti; ti=ti->next) {
1050 blob.in_size = blob.out_size = 0;
1051 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1054 if (errno == EMFILE) {
1055 fprintf(stderr,"%s: Can't flush active file %s\n", pn, ti->data);
1059 fprintf(stderr, "Error flushing file\n");
1060 Die(errno,ti->data);
1068 /* all this command does is repackage its args and call SetVolCmd */
1069 static SetQuotaCmd(as)
1070 register struct cmd_syndesc *as; {
1071 struct cmd_syndesc ts;
1073 /* copy useful stuff from our command slot; we may later have to reorder */
1074 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1075 return SetVolCmd(&ts);
1078 static SetVolCmd(as)
1079 register struct cmd_syndesc *as; {
1080 register afs_int32 code;
1081 struct ViceIoctl blob;
1082 register struct cmd_item *ti;
1083 struct VolumeStatus *status;
1084 char *motd, *offmsg, *input;
1086 SetDotDefault(&as->parms[0].items);
1087 for(ti=as->parms[0].items; ti; ti=ti->next) {
1089 blob.out_size = MAXSIZE;
1090 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1093 status = (VolumeStatus *)space;
1094 status->MinQuota = status->MaxQuota = -1;
1095 motd = offmsg = (char *) 0;
1096 if (as->parms[1].items) {
1097 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1099 fprintf(stderr,"fs: bad integer specified for quota.\n");
1103 if (as->parms[2].items) motd = as->parms[2].items->data;
1104 if (as->parms[3].items) offmsg = as->parms[3].items->data;
1105 input = (char *)status + sizeof(*status);
1106 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1108 if (strlen(offmsg) >= VMSGSIZE) {
1109 fprintf(stderr,"fs: message must be shorter than %d characters\n",
1113 strcpy(input,offmsg);
1114 blob.in_size += strlen(offmsg);
1115 input += strlen(offmsg) + 1;
1117 else *(input++) = '\0';
1119 if (strlen(motd) >= VMSGSIZE) {
1120 fprintf(stderr,"fs: message must be shorter than %d characters\n",
1125 blob.in_size += strlen(motd);
1126 input += strlen(motd) + 1;
1128 else *(input++) = '\0';
1129 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1131 Die(errno, ti->data);
1138 static ExamineCmd(as)
1139 register struct cmd_syndesc *as; {
1140 register afs_int32 code;
1141 struct ViceIoctl blob;
1142 register struct cmd_item *ti;
1143 struct VolumeStatus *status;
1144 char *name, *offmsg, *motd;
1148 SetDotDefault(&as->parms[0].items);
1149 for(ti=as->parms[0].items; ti; ti=ti->next) {
1151 blob.out_size = MAXSIZE;
1154 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1156 Die(errno, ti->data);
1160 status = (VolumeStatus *)space;
1161 name = (char *)status + sizeof(*status);
1162 offmsg = name + strlen(name) + 1;
1163 motd = offmsg + strlen(offmsg) + 1;
1164 PrintStatus(status, name, motd, offmsg);
1169 static ListQuotaCmd(as)
1170 register struct cmd_syndesc *as; {
1171 register afs_int32 code;
1172 struct ViceIoctl blob;
1173 register struct cmd_item *ti;
1174 struct VolumeStatus *status;
1177 printf("%-25s%-10s%-10s%-7s%-13s\n",
1178 "Volume Name", " Quota", " Used", " %Used", " Partition");
1179 SetDotDefault(&as->parms[0].items);
1180 for(ti=as->parms[0].items; ti; ti=ti->next) {
1182 blob.out_size = MAXSIZE;
1185 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1187 Die(errno, ti->data);
1190 status = (VolumeStatus *)space;
1191 name = (char *)status + sizeof(*status);
1192 QuickPrintStatus(status, name);
1197 static WhereIsCmd(as)
1198 register struct cmd_syndesc *as; {
1199 register afs_int32 code;
1200 struct ViceIoctl blob;
1201 register struct cmd_item *ti;
1206 SetDotDefault(&as->parms[0].items);
1207 for(ti=as->parms[0].items; ti; ti=ti->next) {
1209 blob.out_size = MAXSIZE;
1212 memset(space, 0, sizeof(space));
1213 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1215 Die(errno, ti->data);
1218 hosts = (afs_int32 *) space;
1219 printf("File %s is on host%s ", ti->data, (hosts[0] && !hosts[1]) ? "": "s");
1220 for(j=0; j<MAXHOSTS; j++) {
1221 if (hosts[j] == 0) break;
1222 tp = hostutil_GetNameByINet(hosts[j]);
1231 static DiskFreeCmd(as)
1232 register struct cmd_syndesc *as; {
1233 register afs_int32 code;
1234 struct ViceIoctl blob;
1235 register struct cmd_item *ti;
1237 struct VolumeStatus *status;
1239 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1240 " used", " avail", " %used");
1241 SetDotDefault(&as->parms[0].items);
1242 for(ti=as->parms[0].items; ti; ti=ti->next) {
1244 blob.out_size = MAXSIZE;
1247 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1249 Die(errno, ti->data);
1252 status = (VolumeStatus *)space;
1253 name = (char *)status + sizeof(*status);
1254 QuickPrintSpace(status, name);
1260 register struct cmd_syndesc *as; {
1261 register afs_int32 code;
1262 struct ViceIoctl blob;
1263 register struct cmd_item *ti;
1265 struct VolumeStatus *status;
1267 SetDotDefault(&as->parms[0].items);
1268 for(ti=as->parms[0].items; ti; ti=ti->next) {
1270 blob.out_size = MAXSIZE;
1273 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1275 Die(errno, ti->data);
1278 status = (VolumeStatus *)space;
1279 if (status->MaxQuota) quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1280 else quotaPct = 0.0;
1281 printf("%2.0f%% of quota used.\n", quotaPct);
1286 static ListMountCmd(as)
1287 register struct cmd_syndesc *as; {
1288 register afs_int32 code;
1289 struct ViceIoctl blob;
1291 register struct cmd_item *ti;
1292 char orig_name[1024]; /*Original name, may be modified*/
1293 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1294 char parent_dir[1024]; /*Parent directory of true name*/
1295 register char *last_component; /*Last component of true name*/
1297 struct stat statbuff; /*Buffer for status info*/
1298 #endif /* not WIN32 */
1300 int link_chars_read; /*Num chars read in readlink()*/
1301 #endif /* not WIN32 */
1302 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1305 for(ti=as->parms[0].items; ti; ti=ti->next) {
1309 strcpy(orig_name, ti->data);
1310 #else /* not WIN32 */
1311 sprintf(orig_name, "%s%s",
1312 (ti->data[0] == '/') ? "" : "./",
1314 #endif /* not WIN32 */
1317 if (lstat(orig_name, &statbuff) < 0) {
1318 /* if lstat fails, we should still try the pioctl, since it
1319 may work (for example, lstat will fail, but pioctl will
1320 work if the volume of offline (returning ENODEV). */
1321 statbuff.st_mode = S_IFDIR; /* lie like pros */
1325 * The lstat succeeded. If the given file is a symlink, substitute
1326 * the file name with the link name.
1328 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1331 * Read name of resolved file.
1333 link_chars_read = readlink(orig_name, true_name, 1024);
1334 if (link_chars_read <= 0) {
1335 fprintf(stderr,"%s: Can't read target name for '%s' symbolic link!\n",
1341 * Add a trailing null to what was read, bump the length.
1343 true_name[link_chars_read++] = 0;
1346 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1347 * have to create a full pathname using the original name and the
1348 * relative symlink name. Find the rightmost slash in the original
1349 * name (we know there is one) and splice in the symlink value.
1351 if (true_name[0] != '\\') {
1352 last_component = (char *) strrchr(orig_name, '\\');
1353 strcpy(++last_component, true_name);
1354 strcpy(true_name, orig_name);
1358 strcpy(true_name, orig_name);
1360 strcpy(true_name, orig_name);
1364 * Find rightmost slash, if any.
1366 last_component = (char *) strrchr(true_name, '\\');
1367 if (!last_component)
1368 last_component = (char *) strrchr(true_name, '/');
1369 if (last_component) {
1371 * Found it. Designate everything before it as the parent directory,
1372 * everything after it as the final component.
1374 strncpy(parent_dir, true_name, last_component - true_name + 1);
1375 parent_dir[last_component - true_name + 1] = 0;
1376 last_component++; /*Skip the slash*/
1380 * No slash appears in the given file name. Set parent_dir to the current
1381 * directory, and the last component as the given name.
1383 fs_ExtractDriveLetter(true_name, parent_dir);
1384 strcat(parent_dir, ".");
1385 last_component = true_name;
1386 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1389 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1390 fprintf(stderr,"fs: you may not use '.' or '..' as the last component\n");
1391 fprintf(stderr,"fs: of a name in the 'fs lsmount' command.\n");
1396 blob.in = last_component;
1397 blob.in_size = strlen(last_component)+1;
1398 blob.out_size = MAXSIZE;
1400 memset(space, 0, MAXSIZE);
1402 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1405 printf("'%s' is a %smount point for volume '%s'\n",
1407 (thru_symlink ? "symbolic link, leading to a " : ""),
1412 if (errno == EINVAL)
1413 fprintf(stderr,"'%s' is not a mount point.\n",
1416 Die(errno, (ti->data ? ti->data : parent_dir));
1423 static MakeMountCmd(as)
1424 register struct cmd_syndesc *as; {
1425 register afs_int32 code;
1426 register char *cellName, *volName, *tmpName;
1428 char localCellName[1000];
1429 #else /* not WIN32 */
1430 struct afsconf_cell info;
1431 struct vldbentry vldbEntry;
1432 #endif /* not WIN32 */
1433 struct ViceIoctl blob;
1439 if (as->parms[5].items && !as->parms[2].items) {
1440 fprintf(stderr,"fs: must provide cell when creating cellular mount point.\n");
1445 if (as->parms[2].items) /* cell name specified */
1446 cellName = as->parms[2].items->data;
1448 cellName = (char *) 0;
1449 volName = as->parms[1].items->data;
1451 if (strlen(volName) >= 64) {
1452 fprintf(stderr,"fs: volume name too long (length must be < 64 characters)\n");
1456 /* Check for a cellname in the volume specification, and complain
1457 * if it doesn't match what was specified with -cell */
1458 if (tmpName = strchr(volName, ':')) {
1461 if (foldcmp(cellName,volName)) {
1462 fprintf(stderr,"fs: cellnames do not match.\n");
1467 volName = ++tmpName;
1470 if (!InAFS(Parent(as->parms[0].items->data))) {
1471 fprintf(stderr,"fs: mount points must be created within the AFS file system\n");
1477 blob.out_size = MAXSIZE;
1479 code = pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME, &blob, 1);
1483 strcpy(localCellName, (cellName? cellName : space));
1484 #else /* not win32 */
1485 code = GetCellName(cellName?cellName:space, &info);
1489 if (!(as->parms[4].items)) {
1490 /* not fast, check which cell the mountpoint is being created in */
1492 /* not fast, check name with VLDB */
1494 code = VLDBInit(1, &info);
1496 /* make the check. Don't complain if there are problems with init */
1497 code = ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, &vldbEntry);
1498 if (code == VL_NOENT) {
1499 fprintf(stderr,"fs: warning, volume %s does not exist in cell %s.\n",
1500 volName, cellName ? cellName : space);
1504 #endif /* not WIN32 */
1506 if (as->parms[3].items) /* if -rw specified */
1511 /* cellular mount point, prepend cell prefix */
1513 strcat(space, localCellName);
1514 #else /* not WIN32 */
1515 strcat(space, info.name);
1516 #endif /* not WIN32 */
1519 strcat(space, volName); /* append volume name */
1520 strcat(space, "."); /* stupid convention; these end with a period */
1522 /* create symlink with a special pioctl for Windows NT, since it doesn't
1523 * have a symlink system call.
1526 blob.in_size = 1 + strlen(space);
1529 code = pioctl(as->parms[0].items->data, VIOC_AFS_CREATE_MT_PT, &blob, 0);
1530 #else /* not WIN32 */
1531 code = symlink(space, as->parms[0].items->data);
1532 #endif /* not WIN32 */
1534 Die(errno, as->parms[0].items->data);
1541 * Delete AFS mount points. Variables are used as follows:
1542 * tbuffer: Set to point to the null-terminated directory name of the mount point
1543 * (or ``.'' if none is provided)
1544 * tp: Set to point to the actual name of the mount point to nuke.
1546 static RemoveMountCmd(as)
1547 register struct cmd_syndesc *as; {
1548 register afs_int32 code=0;
1549 struct ViceIoctl blob;
1550 register struct cmd_item *ti;
1552 char lsbuffer[1024];
1555 for(ti=as->parms[0].items; ti; ti=ti->next) {
1557 tp = (char *) strrchr(ti->data, '\\');
1559 tp = (char *) strrchr(ti->data, '/');
1561 strncpy(tbuffer, ti->data, code=tp-ti->data+1); /* the dir name */
1563 tp++; /* skip the slash */
1566 fs_ExtractDriveLetter(ti->data, tbuffer);
1567 strcat(tbuffer, ".");
1569 fs_StripDriveLetter(tp, tp, 0);
1572 blob.in_size = strlen(tp)+1;
1573 blob.out = lsbuffer;
1574 blob.out_size = sizeof(lsbuffer);
1575 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1577 if (errno == EINVAL)
1578 fprintf(stderr,"fs: '%s' is not a mount point.\n", ti->data);
1580 Die(errno, ti->data);
1582 continue; /* don't bother trying */
1586 blob.in_size = strlen(tp)+1;
1587 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1589 Die(errno, ti->data);
1599 static CheckServersCmd(as)
1600 register struct cmd_syndesc *as; {
1601 register afs_int32 code;
1602 struct ViceIoctl blob;
1603 register afs_int32 j;
1606 struct afsconf_cell info;
1607 struct chservinfo checkserv;
1609 memset(&checkserv, 0, sizeof(struct chservinfo));
1610 blob.in_size=sizeof(struct chservinfo);
1611 blob.in=(caddr_t)&checkserv;
1613 blob.out_size = MAXSIZE;
1615 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1617 /* prepare flags for checkservers command */
1618 temp = 2; /* default to checking local cell only */
1619 if (as->parms[2].items) temp |= 1; /* set fast flag */
1620 if (as->parms[1].items) temp &= ~2; /* turn off local cell check */
1622 checkserv.magic = 0x12345678; /* XXX */
1623 checkserv.tflags=temp;
1625 /* now copy in optional cell name, if specified */
1626 if (as->parms[0].items) {
1627 code = GetCellName(as->parms[0].items->data, &info);
1631 strcpy(checkserv.tbuffer,info.name);
1632 checkserv.tsize=strlen(info.name)+1;
1636 strcpy(checkserv.tbuffer,"\0");
1640 if(as->parms[3].items)
1642 checkserv.tinterval=atol(as->parms[3].items->data);
1645 if(checkserv.tinterval<0) {
1646 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
1647 checkserv.tinterval=0;
1648 } else if(checkserv.tinterval> 600) {
1649 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1650 checkserv.tinterval=600; /* 10 min max interval */
1654 checkserv.tinterval = -1; /* don't change current interval */
1657 if ( checkserv.tinterval != 0 ) {
1660 fprintf (stderr,"Permission denied: requires Administrator access.\n");
1665 fprintf (stderr,"Permission denied: requires root access.\n");
1671 code = pioctl(0, VIOCCKSERV, &blob, 1);
1673 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1674 printf("Must be root to change -interval\n");
1680 memcpy(&temp, space, sizeof(afs_int32));
1681 if (checkserv.tinterval >= 0) {
1682 if (checkserv.tinterval > 0)
1683 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1684 checkserv.tinterval, temp);
1686 printf("The current down server probe interval is %d secs\n", temp);
1690 printf("All servers are running.\n");
1693 printf("These servers unavailable due to network or server problems: ");
1694 for(j=0; j < MAXHOSTS; j++) {
1695 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
1696 if (temp == 0) break;
1697 tp = hostutil_GetNameByINet(temp);
1707 register struct cmd_syndesc *as; {
1708 register afs_int32 code=0;
1709 struct ViceIoctl blob;
1710 struct gaginfo gagflags;
1711 struct cmd_item *show;
1713 memset(&gagflags, 0, sizeof(struct gaginfo));
1714 blob.in_size = sizeof(struct gaginfo);
1715 blob.in = (caddr_t ) &gagflags;
1716 blob.out_size = MAXSIZE;
1718 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1720 if (show = as->parms[0].items)
1721 if (!foldcmp (show->data, "user"))
1722 gagflags.showflags |= GAGUSER;
1723 else if (!foldcmp (show->data, "console"))
1724 gagflags.showflags |= GAGCONSOLE;
1725 else if (!foldcmp (show->data, "all"))
1726 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1727 else if (!foldcmp (show->data, "none"))
1731 "unrecognized flag %s: must be in {user,console,all,none}\n",
1739 code = pioctl(0, VIOC_GAG, &blob, 1);
1747 static CheckVolumesCmd(as)
1748 register struct cmd_syndesc *as; {
1749 register afs_int32 code;
1750 struct ViceIoctl blob;
1754 code = pioctl(0, VIOCCKBACK, &blob, 1);
1759 else printf("All volumeID/name mappings checked.\n");
1764 static SetCacheSizeCmd(as)
1765 register struct cmd_syndesc *as; {
1766 register afs_int32 code;
1767 struct ViceIoctl blob;
1772 fprintf (stderr,"Permission denied: requires Administrator access.\n");
1777 fprintf (stderr,"Permission denied: requires root access.\n");
1782 if (!as->parms[0].items && !as->parms[1].items) {
1783 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
1786 if (as->parms[0].items) {
1787 code = util_GetInt32(as->parms[0].items->data, &temp);
1789 fprintf(stderr,"fs: bad integer specified for cache size.\n");
1795 blob.in = (char *) &temp;
1796 blob.in_size = sizeof(afs_int32);
1798 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
1800 Die(errno, (char *) 0);
1802 printf("New cache size set.\n");
1806 #define MAXGCSIZE 16
1807 static GetCacheParmsCmd(as)
1808 register struct cmd_syndesc *as; {
1809 register afs_int32 code;
1810 struct ViceIoctl blob;
1811 afs_int32 parms[MAXGCSIZE];
1813 blob.in = (char *) 0;
1815 blob.out_size = sizeof(parms);
1816 blob.out = (char *) parms;
1817 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
1819 Die(errno, (char *) 0);
1821 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
1822 parms[1], parms[0]);
1823 if (parms[1] > parms[0])
1824 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
1829 static ListCellsCmd(as)
1830 register struct cmd_syndesc *as; {
1831 register afs_int32 code;
1832 afs_int32 i, j, *lp, magic, size;
1834 afs_int32 clear, maxa = OMAXHOSTS;
1835 struct ViceIoctl blob;
1837 for(i=0;i<1000;i++) {
1839 memcpy(tp, &i, sizeof(afs_int32));
1840 tp = (char *)(space + sizeof(afs_int32));
1841 lp = (afs_int32 *)tp;
1843 size = sizeof(afs_int32) + sizeof(afs_int32);
1844 blob.out_size = MAXSIZE;
1845 blob.in_size = sizeof(afs_int32);
1848 code = pioctl(0, VIOCGETCELL, &blob, 1);
1850 if (errno == EDOM) break; /* done with the list */
1857 memcpy(&magic, tp, sizeof(afs_int32));
1858 if (magic == 0x12345678) {
1860 tp += sizeof(afs_int32);
1862 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
1863 for(j=0; j < maxa; j++) {
1864 memcpy(&clear, tp + j*sizeof(afs_int32), sizeof(afs_int32));
1865 if (clear == 0) break;
1866 tcp = hostutil_GetNameByINet(clear);
1874 static NewCellCmd(as)
1875 register struct cmd_syndesc *as; {
1877 register afs_int32 code, linkedstate=0, size=0, *lp;
1878 struct ViceIoctl blob;
1879 register struct cmd_item *ti;
1880 register char *tp, *cellname=0;
1881 register struct hostent *thp;
1882 afs_int32 fsport = 0, vlport = 0;
1886 fprintf (stderr,"Permission denied: requires Administrator access.\n");
1891 fprintf (stderr,"Permission denied: requires root access.\n");
1896 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
1898 lp = (afs_int32 *)tp;
1900 tp += sizeof(afs_int32);
1901 for(ti=as->parms[1].items; ti; ti=ti->next) {
1902 thp = hostutil_GetHostByName(ti->data);
1904 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
1908 memcpy(tp, thp->h_addr, sizeof(afs_int32));
1909 tp += sizeof(afs_int32);
1912 if (as->parms[2].items) {
1914 * Link the cell, for the purposes of volume location, to the specified
1917 cellname = as->parms[2].items->data;
1920 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
1921 if (as->parms[3].items) {
1922 code = util_GetInt32(as->parms[3].items->data, &vlport);
1924 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
1928 if (as->parms[4].items) {
1929 code = util_GetInt32(as->parms[4].items->data, &fsport);
1931 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
1936 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
1937 lp = (afs_int32 *)tp;
1941 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
1942 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
1943 tp = (char *)(space + size);
1945 strcpy(tp, cellname);
1946 size += strlen(cellname) + 1;
1948 blob.in_size = size;
1951 code = pioctl(0, VIOCNEWCELL, &blob, 1);
1956 register afs_int32 code;
1957 struct ViceIoctl blob;
1960 blob.in = (char *) 0;
1961 blob.out_size = MAXSIZE;
1964 code = pioctl((char *) 0, VIOCNEWCELL, &blob, 1);
1967 Die(errno, (char *) 0);
1970 printf("Cell servers information refreshed\n");
1975 static WhichCellCmd(as)
1976 register struct cmd_syndesc *as; {
1977 register afs_int32 code;
1978 struct ViceIoctl blob;
1979 register struct cmd_item *ti;
1982 error = 0; /* no error occurred */
1983 SetDotDefault(&as->parms[0].items);
1984 for(ti=as->parms[0].items; ti; ti=ti->next) {
1987 blob.out_size = MAXSIZE;
1990 code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1992 if (errno == ENOENT)
1993 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
1995 Die(errno, ti->data);
2000 printf("File %s lives in cell '%s'\n", ti->data, space);
2005 static WSCellCmd(as)
2006 register struct cmd_syndesc *as; {
2007 register afs_int32 code;
2008 struct ViceIoctl blob;
2011 blob.in = (char *) 0;
2012 blob.out_size = MAXSIZE;
2015 code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1);
2018 Die(errno, (char *) 0);
2021 printf("This workstation belongs to cell '%s'\n", space);
2025 static PrimaryCellCmd(as)
2026 register struct cmd_syndesc *as; {
2028 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2033 static MonitorCmd(as)
2034 register struct cmd_syndesc *as; {
2035 register afs_int32 code;
2036 struct ViceIoctl blob;
2037 register struct cmd_item *ti;
2039 register struct hostent *thp;
2043 ti = as->parms[0].items;
2047 if (!strcmp(ti->data, "off"))
2048 hostAddr = 0xffffffff;
2050 thp = hostutil_GetHostByName(ti->data);
2052 if (!strcmp(ti->data, "localhost")) {
2053 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2054 hostAddr = htonl(0x7f000001);
2057 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2061 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2065 hostAddr = 0; /* means don't set host */
2066 setp = 0; /* aren't setting host */
2069 /* now do operation */
2070 blob.in_size = sizeof(afs_int32);
2071 blob.out_size = sizeof(afs_int32);
2072 blob.in = (char *) &hostAddr;
2073 blob.out = (char *) &hostAddr;
2074 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2080 printf("%s: new monitor host set.\n", pn);
2083 /* now decode old address */
2084 if (hostAddr == 0xffffffff) {
2085 printf("Cache monitoring is currently disabled.\n");
2088 tp = hostutil_GetNameByINet(hostAddr);
2089 printf("Using host %s for monitor services.\n", tp);
2095 static SysNameCmd(as)
2096 register struct cmd_syndesc *as; {
2097 register afs_int32 code;
2098 struct ViceIoctl blob;
2099 struct cmd_item *ti;
2100 char *input = space;
2103 ti = as->parms[0].items;
2107 fprintf (stderr,"Permission denied: requires Administrator access.\n");
2112 fprintf (stderr,"Permission denied: requires root access.\n");
2120 blob.out_size = MAXSIZE;
2121 blob.in_size = sizeof(afs_int32);
2122 memcpy(input, &setp, sizeof(afs_int32));
2123 input += sizeof(afs_int32);
2124 for (; ti; ti = ti->next) {
2126 blob.in_size += strlen(ti->data) + 1;
2127 if (blob.in_size > MAXSIZE) {
2128 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2129 setp > 1 ? "s" : "");
2132 strcpy(input, ti->data);
2133 input += strlen(ti->data);
2136 memcpy(space, &setp, sizeof(afs_int32));
2137 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2143 printf("%s: new sysname%s set.\n", pn, setp > 1 ? "s" : "");
2148 memcpy(&setp, input, sizeof(afs_int32));
2149 input += sizeof(afs_int32);
2151 fprintf(stderr,"No sysname name value was found\n");
2155 printf("Current sysname%s", setp > 1 ? "s are" : " is");
2156 for (; setp > 0; --setp ) {
2157 printf(" \'%s\'", input);
2158 input += strlen(input) + 1;
2164 char *exported_types[] = {"null", "nfs", ""};
2165 static ExportAfsCmd(as)
2166 register struct cmd_syndesc *as; {
2167 register afs_int32 code;
2168 struct ViceIoctl blob;
2169 register struct cmd_item *ti;
2170 int export=0, type=0, mode = 0, exp = 0, gstat = 0, exportcall, pwsync=0, smounts=0;
2174 fprintf (stderr,"Permission denied: requires Administrator access.\n");
2179 fprintf (stderr,"Permission denied: requires root access.\n");
2184 ti = as->parms[0].items;
2185 if (strcmp(ti->data, "nfs") == 0) type = 0x71; /* NFS */
2187 fprintf(stderr,"Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2190 ti = as->parms[1].items;
2192 if (strcmp(ti->data, "on") == 0) export = 3;
2193 else if (strcmp(ti->data, "off") == 0) export = 2;
2195 printf("Illegal argument %s\n", ti->data);
2200 if (ti = as->parms[2].items) { /* -noconvert */
2201 if (strcmp(ti->data, "on") == 0) mode = 2;
2202 else if (strcmp(ti->data, "off") == 0) mode = 3;
2204 printf("Illegal argument %s\n", ti->data);
2208 if (ti = as->parms[3].items) { /* -uidcheck */
2209 if (strcmp(ti->data, "on") == 0) pwsync = 3;
2210 else if (strcmp(ti->data, "off") == 0) pwsync = 2;
2212 printf("Illegal argument %s\n", ti->data);
2216 if (ti = as->parms[4].items) { /* -submounts */
2217 if (strcmp(ti->data, "on") == 0) smounts = 3;
2218 else if (strcmp(ti->data, "off") == 0) smounts = 2;
2220 printf("Illegal argument %s\n", ti->data);
2224 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2227 blob.in = (char *) &exportcall;
2228 blob.in_size = sizeof(afs_int32);
2229 blob.out = (char *) &exportcall;
2230 blob.out_size = sizeof(afs_int32);
2231 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2233 if (errno == ENODEV) {
2234 fprintf(stderr,"Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
2241 if (exportcall & 1) {
2242 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
2243 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
2244 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
2245 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
2247 printf("'%s' translator is disabled\n", exported_types[type]);
2255 static GetCellCmd(as)
2256 register struct cmd_syndesc *as; {
2257 register afs_int32 code;
2258 struct ViceIoctl blob;
2259 struct afsconf_cell info;
2260 register struct cmd_item *ti;
2266 for(ti=as->parms[0].items; ti; ti=ti->next) {
2268 blob.out_size = sizeof(args);
2269 blob.out = (caddr_t) &args;
2270 code = GetCellName(ti->data, &info);
2274 blob.in_size = 1+strlen(info.name);
2275 blob.in = info.name;
2276 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2278 if (errno == ENOENT)
2279 fprintf(stderr,"fs: the cell named '%s' does not exist\n", info.name);
2281 Die(errno, info.name);
2284 printf("Cell %s status: ", info.name);
2286 if (args.stat & 1) printf("primary ");
2288 if (args.stat & 2) printf("no setuid allowed");
2289 else printf("setuid allowed");
2290 if (args.stat & 4) printf(", using old VLDB");
2296 static SetCellCmd(as)
2297 register struct cmd_syndesc *as; {
2298 register afs_int32 code;
2299 struct ViceIoctl blob;
2300 struct afsconf_cell info;
2301 register struct cmd_item *ti;
2308 /* figure stuff to set */
2314 fprintf (stderr,"Permission denied: requires Administrator access.\n");
2319 fprintf (stderr,"Permission denied: requires root access.\n");
2324 if (! as->parms[1].items) args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
2326 /* set stat for all listed cells */
2327 for(ti=as->parms[0].items; ti; ti=ti->next) {
2329 code = GetCellName(ti->data, &info);
2333 strcpy(args.cname, info.name);
2334 blob.in_size = sizeof(args);
2335 blob.in = (caddr_t) &args;
2337 blob.out = (caddr_t) 0;
2338 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2348 static GetCellName(char *cellNamep, struct afsconf_cell *infop)
2350 strcpy(infop->name, cellNamep);
2354 static VLDBInit(int noAuthFlag, struct afsconf_cell *infop)
2359 #else /* not WIN32 */
2361 static GetCellName(cellName, info)
2363 struct afsconf_cell *info;
2365 struct afsconf_dir *tdir;
2368 tdir = afsconf_Open(AFSCONF_CLIENTNAME);
2370 fprintf(stderr,"Could not process files in configuration directory (%s).\n",AFSCONF_CLIENTNAME);
2374 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2376 fprintf(stderr,"fs: cell %s not in %s/CellServDB\n", cellName, AFSCONF_CLIENTNAME);
2384 static VLDBInit(noAuthFlag, info)
2386 struct afsconf_cell *info;
2388 struct ktc_principal sname;
2389 struct ktc_token ttoken;
2391 struct rx_securityClass *sc;
2392 struct rx_connection *serverconns[VLDB_MAXSERVERS];
2397 fprintf(stderr,"fs: could not initialize rx.\n");
2401 rx_SetRxDeadTime(50);
2402 if (!noAuthFlag) { /* we don't need tickets for null */
2403 strcpy(sname.cell, info->name);
2404 sname.instance[0] = 0;
2405 strcpy(sname.name, "afs");
2406 code = ktc_GetToken(&sname,&ttoken, sizeof(ttoken), (char *)0);
2408 fprintf(stderr,"fs: Could not get afs tokens, running unauthenticated.\n");
2413 if (ttoken.kvno >= 0 && ttoken.kvno <= 255) scIndex = 2; /* kerberos */
2415 fprintf (stderr, "fs: funny kvno (%d) in ticket, proceeding\n",
2421 else scIndex = 0; /* don't authenticate */
2424 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
2430 sc = (struct rx_securityClass *)
2431 rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
2432 ttoken.kvno, ttoken.ticketLen,
2436 if (info->numServers > VLDB_MAXSERVERS) {
2437 fprintf(stderr, "fs: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
2438 info->numServers, VLDB_MAXSERVERS);
2441 memset(serverconns, 0, sizeof(serverconns));
2442 for (i = 0;i<info->numServers;i++)
2443 serverconns[i] = rx_NewConnection(info->hostAddr[i].sin_addr.s_addr,
2444 info->hostAddr[i].sin_port, USER_SERVICE_ID,
2448 rxs_Release(sc); /* Decrement the initial refCount */
2449 code = ubik_ClientInit(serverconns, &uclient);
2452 fprintf(stderr,"fs: ubik client init failed.\n");
2457 #endif /* not WIN32 */
2459 static struct ViceIoctl gblob;
2460 static int debug = 0;
2462 * here follow some routines in suport of the setserverprefs and
2463 * getserverprefs commands. They are:
2464 * SetPrefCmd "top-level" routine
2465 * addServer adds a server to the list of servers to be poked into the
2466 * kernel. Will poke the list into the kernel if it threatens
2468 * pokeServers pokes the existing list of servers and ranks into the kernel
2469 * GetPrefCmd reads the Cache Manager's current list of server ranks
2472 static pokeServers()
2477 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2479 ssp = (cm_SSetPref_t *)space;
2480 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2485 static addServer(name, rank)
2487 unsigned short rank;
2492 struct hostent *thostent;
2496 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2498 #define MAXUSHORT ((unsigned short) ~0)
2503 thostent = hostutil_GetHostByName(name);
2505 fprintf (stderr, "%s: couldn't resolve name.\n", name);
2509 ssp = (cm_SSetPref_t *)(gblob.in);
2511 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
2512 code = pokeServers();
2513 ssp->num_servers = 0;
2516 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
2517 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
2518 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2519 gblob.in_size += sizeof(cm_SPref_t);
2522 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
2527 static BOOL IsWindowsNT (void)
2529 static BOOL fChecked = FALSE;
2530 static BOOL fIsWinNT = FALSE;
2534 OSVERSIONINFO Version;
2538 memset (&Version, 0x00, sizeof(Version));
2539 Version.dwOSVersionInfoSize = sizeof(Version);
2541 if (GetVersionEx (&Version))
2543 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
2551 static SetPrefCmd(as)
2552 register struct cmd_syndesc *as; {
2555 struct cmd_item *ti;
2560 ssp = (cm_SSetPref_t *)space;
2562 ssp->num_servers = 0;
2563 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2566 gblob.out_size = MAXSIZE;
2570 fprintf (stderr,"Permission denied: requires Administrator access.\n");
2575 fprintf (stderr,"Permission denied: requires root access.\n");
2582 ti = as->parms[2].items; /* -file */
2584 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
2585 if (!(infd = fopen(ti->data,"r" ))) {
2587 Die(errno,ti->data);
2590 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2591 code = addServer (name, (unsigned short) rank);
2595 ti = as->parms[3].items; /* -stdin */
2597 while ( scanf("%79s%ld", name, &rank) != EOF) {
2598 code = addServer (name, (unsigned short) rank);
2602 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
2607 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
2609 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
2613 code = pokeServers();
2615 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
2617 ssp = (cm_SSetPref_t *)space;
2618 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2620 ssp->flags = CM_SPREF_VLONLY;
2621 ssp->num_servers = 0;
2623 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
2628 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
2630 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
2635 if (as->parms[1].items) {
2637 printf("now poking vlservers\n");
2638 code = pokeServers();
2648 static GetPrefCmd(as)
2649 register struct cmd_syndesc *as; {
2651 struct cmd_item *ti;
2652 char *name, tbuffer[20];
2657 struct ViceIoctl blob;
2658 struct cm_SPrefRequest *in;
2659 struct cm_SPrefInfo *out;
2663 ti = as->parms[0].items; /* -file */
2665 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
2666 if (!(outfd = freopen(ti->data,"w",stdout))) {
2667 Die(errno,ti->data);
2672 ti = as->parms[1].items; /* -numeric */
2674 ti = as->parms[2].items; /* -vlservers */
2675 vlservers = (ti ? CM_SPREF_VLONLY : 0);
2676 /* ti = as->parms[3].items; -cell */
2678 in = (struct cm_SPrefRequest *)space;
2682 blob.in_size=sizeof(struct cm_SPrefRequest);
2683 blob.in = (char *)in;
2685 blob.out_size = MAXSIZE;
2687 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
2688 in->flags = vlservers;
2690 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
2692 perror("getserverprefs pioctl");
2696 out = (struct cm_SPrefInfo *) blob.out;
2698 for (i=0;i<out->num_servers;i++) {
2700 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
2703 addr = ntohl(out->servers[i].host.s_addr);
2704 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
2705 (addr>>8) & 0xff, addr & 0xff);
2708 printf ("%-50s %5u\n",name,out->servers[i].rank);
2711 in->offset = out->next_offset;
2713 } while (!code && out->next_offset > 0);
2718 static TraceCmd(struct cmd_syndesc *asp)
2721 struct ViceIoctl blob;
2727 fprintf (stderr,"Permission denied: requires Administrator access.\n");
2732 fprintf (stderr,"Permission denied: requires root access.\n");
2737 if ((asp->parms[0].items && asp->parms[1].items)) {
2738 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
2742 /* determine if we're turning this tracing on or off */
2744 if (asp->parms[0].items)
2745 inValue = 3; /* enable */
2746 else if (asp->parms[1].items) inValue = 2; /* disable */
2747 if (asp->parms[2].items) inValue |= 4; /* do reset */
2748 if (asp->parms[3].items) inValue |= 8; /* dump */
2750 blob.in_size = sizeof(long);
2751 blob.in = (char *) &inValue;
2752 blob.out_size = sizeof(long);
2753 blob.out = (char *) &outValue;
2755 code = pioctl(NULL, VIOC_TRACECTL, &blob, 1);
2761 if (outValue) printf("AFS tracing enabled.\n");
2762 else printf("AFS tracing disabled.\n");
2767 static void sbusage()
2769 fprintf(stderr, "example usage: fs storebehind -files *.o -kb 99999 -default 0\n");
2770 fprintf(stderr, " fs sb 50000 *.[ao] -default 10\n");
2773 static StoreBehindCmd(as) /* fs sb -kbytes 9999 -files *.o -default 64 */
2774 struct cmd_syndesc *as; {
2776 struct ViceIoctl blob;
2777 struct cmd_item *ti;
2778 struct sbstruct tsb;
2783 fprintf (stderr,"Permission denied: requires Administrator access.\n");
2788 fprintf (stderr,"Permission denied: requires root access.\n");
2793 if ((as->parms[0].items && as->parms[1].items) ||
2794 (!as->parms[0].items && !as->parms[1].items)) /* same as logical xor */
2801 ti=as->parms[2].items;
2802 if (ti && ti->data) {
2803 kb = atoi (ti->data);
2806 tsb.sb_default = kb;
2808 ti=as->parms[1].items;
2809 if (ti && ti->data) {
2810 kb = atoi (ti->data);
2813 tsb.sb_thisfile = kb;
2815 ti=as->parms[0].items;
2820 blob.in_size = sizeof(tsb);
2821 blob.out_size = sizeof(tsb);
2822 fprintf (stderr, "storbehind %s %d %d\n", (ti?ti->data:0),
2823 tsb.sb_thisfile, tsb.sb_default);
2824 code = pioctl((ti ? ti->data : 0) , VIOC_STOREBEHIND, &blob, 1);
2826 Die(errno, (ti ? ti->data : 0));
2829 if (blob.out_size == sizeof(tsb)) {
2830 fprintf (stderr, "storbehind %s is now %d (default %d)\n", (ti?ti->data:0),
2831 tsb.sb_thisfile, tsb.sb_default);
2833 ti = (ti ? ti->next : ti);
2839 static afs_int32 SetCryptCmd(as)
2840 struct cmd_syndesc *as;
2842 afs_int32 code = 0, flag;
2843 struct ViceIoctl blob;
2848 fprintf (stderr,"Permission denied: requires Administrator access.\n");
2853 fprintf (stderr,"Permission denied: requires root access.\n");
2858 tp = as->parms[0].items->data;
2859 if (strcmp(tp, "on") == 0)
2861 else if (strcmp(tp, "off") == 0)
2864 fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
2868 blob.in = (char *) &flag;
2869 blob.in_size = sizeof(flag);
2871 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
2873 Die(code, (char *) 0);
2877 static afs_int32 GetCryptCmd(as)
2878 struct cmd_syndesc *as;
2880 afs_int32 code = 0, flag;
2881 struct ViceIoctl blob;
2884 blob.in = (char *) 0;
2886 blob.out_size = sizeof(flag);
2889 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
2891 if (code) Die(code, (char *) 0);
2894 memcpy(&flag, tp, sizeof(afs_int32));
2895 printf("Security level is currently ");
2897 printf("crypt (data security).\n");
2907 register afs_int32 code;
2908 register struct cmd_syndesc *ts;
2910 #ifdef AFS_AIX32_ENV
2912 * The following signal action for AIX is necessary so that in case of a
2913 * crash (i.e. core is generated) we can include the user's data section
2914 * in the core dump. Unfortunately, by default, only a partial core is
2915 * generated which, in many cases, isn't too useful.
2917 struct sigaction nsa;
2919 sigemptyset(&nsa.sa_mask);
2920 nsa.sa_handler = SIG_DFL;
2921 nsa.sa_flags = SA_FULLDUMP;
2922 sigaction(SIGSEGV, &nsa, NULL);
2927 WSAStartup(0x0101, &WSAjunk);
2930 /* try to find volume location information */
2935 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks");
2936 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
2937 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
2938 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
2939 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
2940 cmd_CreateAlias(ts, "sp");
2942 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks");
2943 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
2944 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
2945 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
2946 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
2947 cmd_CreateAlias(ts, "gp");
2949 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
2950 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2951 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
2952 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
2953 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
2954 parm_setacl_id = ts->nParms;
2955 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
2956 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
2957 cmd_CreateAlias(ts, "sa");
2959 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list");
2960 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2961 parm_listacl_id = ts->nParms;
2962 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
2963 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
2964 cmd_CreateAlias(ts, "la");
2966 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list");
2967 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2969 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list");
2970 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
2971 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
2972 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
2973 parm_copyacl_id = ts->nParms;
2974 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
2975 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
2977 cmd_CreateAlias(ts, "ca");
2979 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
2980 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2982 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
2983 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2984 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
2986 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
2988 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
2989 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
2990 cmd_CreateAlias(ts, "sv");
2992 ts = cmd_CreateSyntax("messages", GagCmd, 0, "control Cache Manager messages");
2993 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
2995 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display volume status");
2996 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2997 cmd_CreateAlias(ts, "lv");
2998 cmd_CreateAlias(ts, "listvol");
3000 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
3001 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3002 cmd_CreateAlias(ts, "lq");
3004 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage");
3005 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3006 cmd_CreateAlias(ts, "df");
3008 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
3009 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3011 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
3012 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3014 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
3015 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3016 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3017 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3018 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3019 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
3025 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3029 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
3030 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3032 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers");
3033 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3034 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3035 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
3036 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
3038 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings");
3039 cmd_CreateAlias(ts, "checkbackups");
3042 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size");
3043 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
3044 cmd_CreateAlias(ts, "cachesize");
3046 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
3048 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info");
3050 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells");
3052 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
3053 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3054 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3056 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3058 cmd_CreateAlias(ts, "sq");
3060 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
3062 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3063 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3064 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
3067 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3069 * Turn this on only if you wish to be able to talk to a server which is listening
3070 * on alternative ports. This is not intended for general use and may not be
3071 * supported in the cache manager. It is not a way to run two servers at the
3072 * same host, since the cache manager cannot properly distinguish those two hosts.
3074 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
3075 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
3078 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
3079 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3081 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
3082 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3084 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
3087 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
3090 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, "set cache monitor host address");
3091 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
3092 cmd_CreateAlias(ts, "mariner");
3095 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
3096 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3098 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
3099 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3100 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3101 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
3103 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume");
3104 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3106 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value");
3107 cmd_AddParm(ts, "-newsys", CMD_SINGLE, CMD_OPTIONAL, "new sysname");
3109 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS");
3110 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3111 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
3112 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
3113 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
3114 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
3117 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
3118 "store to server after file close");
3119 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
3120 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3121 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
3122 cmd_CreateAlias(ts, "sb");
3124 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag");
3125 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3127 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "get cache manager encryption flag");
3129 ts = cmd_CreateSyntax("trace", TraceCmd, 0, "enable or disable CM tracing");
3130 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
3131 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
3132 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
3133 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
3134 cmd_CreateAlias(ts, "tr");
3136 ts = cmd_CreateSyntax("memdump", MemDumpCmd, 0, "dump memory allocs in debug builds");
3137 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
3138 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
3140 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, 0, "change client side caching policy for AFS shares");
3141 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
3142 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
3143 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
3144 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
3145 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
3147 code = cmd_Dispatch(argc, argv);
3150 if (rxInitDone) rx_Finalize();
3151 #endif /* not WIN32 */
3156 void Die(code, filename)
3161 if (code == EINVAL) {
3163 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
3164 else fprintf(stderr,"%s: Invalid argument.\n", pn);
3166 else if (code == ENOENT) {
3167 if (filename) fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
3168 else fprintf(stderr,"%s: no such file returned\n", pn);
3170 else if (code == EROFS) fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
3171 else if (code == EACCES || code == EPERM) {
3172 if (filename) fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
3173 else fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
3175 else if (code == ENODEV) {
3176 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
3178 else if (code == ESRCH) {
3179 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
3181 else if (code == EPIPE) {
3182 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
3184 else if (code == EFBIG) {
3185 fprintf(stderr,"%s: Cache size too large.\n", pn);
3187 else if (code == ETIMEDOUT) {
3189 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
3191 fprintf(stderr,"%s: Connection timed out", pn);
3194 if (filename) fprintf(stderr,"%s:'%s'", pn, filename);
3195 else fprintf(stderr,"%s", pn);
3197 fprintf(stderr, ": code 0x%x\n", code);
3198 #else /* not WIN32 */
3199 fprintf(stderr,": %s\n", error_message(code));
3200 #endif /* not WIN32 */
3204 static MemDumpCmd(struct cmd_syndesc *asp)
3207 struct ViceIoctl blob;
3211 if ((asp->parms[0].items && asp->parms[1].items)) {
3212 fprintf(stderr, "fs trace: must use at most one of '-begin' or '-end'\n");
3216 /* determine if we're turning this tracing on or off */
3218 if (asp->parms[0].items)
3219 inValue = 1; /* begin */
3220 else if (asp->parms[1].items)
3221 inValue = 0; /* end */
3223 blob.in_size = sizeof(long);
3224 blob.in = (char *) &inValue;
3225 blob.out_size = sizeof(long);
3226 blob.out = (char *) &outValue;
3228 code = pioctl(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
3234 if (outValue) printf("AFS memdump begin.\n");
3235 else printf("AFS memdump end.\n");
3240 static CSCPolicyCmd(struct cmd_syndesc *asp)
3242 struct cmd_item *ti;
3247 for(ti=asp->parms[0].items; ti;ti=ti->next) {
3259 fprintf (stderr,"Permission denied: requires Administrator access.\n");
3264 fprintf (stderr,"Permission denied: requires root access.\n");
3271 if (asp->parms[1].items)
3273 if (asp->parms[2].items)
3274 policy = "programs";
3275 if (asp->parms[3].items)
3276 policy = "documents";
3277 if (asp->parms[4].items)
3280 strcpy(sbmtpath, "afsdsbmt.ini");
3281 WritePrivateProfileString("CSC Policy", share, policy, sbmtpath);
3283 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
3284 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
3288 char policies[1024];
3289 DWORD len = sizeof(policies);
3291 /* list current csc policies */
3292 strcpy(sbmtpath, "afsdsbmt.ini");
3294 GetPrivateProfileSection("CSC Policy", policies, len, sbmtpath);
3296 printf("Current CSC policies:\n");
3300 printf(" %s\n", policy);
3301 policy += strlen(policy) + 1;