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>
11 #include <afs/afs_args.h>
13 #include <sys/ioctl.h>
14 #include <sys/socket.h>
18 #include <netinet/in.h>
22 #include <afs/venus.h>
28 #include "afs/prs_fs.h"
29 #include <afs/afsint.h>
31 #include <afs/cellconfig.h>
34 #include <rx/rx_globals.h>
35 #include <afs/vldbint.h>
36 #include <afs/volser.h>
37 #include <afs/vlserver.h>
40 #include <afs/afsutil.h>
43 #include <afs/ptclient.h>
48 #define MAXCELLHOSTS 8
51 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
52 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
54 static char space[MAXSIZE];
55 static char tspace[1024];
56 static struct ubik_client *uclient;
58 static int GetClientAddrsCmd(), SetClientAddrsCmd(), FlushMountCmd();
59 static int RxStatProcCmd(), RxStatPeerCmd();
61 extern char *hostutil_GetNameByINet();
62 extern struct hostent *hostutil_GetHostByName();
63 extern afs_int32 VL_GetEntryByNameO();
66 extern struct cmd_syndesc *cmd_CreateSyntax();
67 static char pn[] = "fs";
68 static int rxInitDone = 0;
70 static void ZapList();
71 static int PruneList();
79 * Character to use between name and rights in printed representation for
82 #define DFS_SEPARATOR ' '
84 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
87 int dfs; /* Originally true if a dfs acl; now also the type
88 of the acl (1, 2, or 3, corresponding to object,
89 initial dir, or initial object). */
90 sec_rgy_name_t cell; /* DFS cell name */
93 struct AclEntry *pluslist;
94 struct AclEntry *minuslist;
98 struct AclEntry *next;
103 static void ZapAcl(acl)
107 ZapList(acl->pluslist);
108 ZapList(acl->minuslist);
120 if (t >= 'A' && t <= 'Z') t += 0x20;
121 if (u >= 'A' && u <= 'Z') u += 0x20;
122 if (t != u) return 1;
123 if (t == 0) return 0;
128 * Mods for the AFS/DFS protocol translator.
130 * DFS rights. It's ugly to put these definitions here, but they
131 * *cannot* change, because they're part of the wire protocol.
132 * In any event, the protocol translator will guarantee these
133 * assignments for AFS cache managers.
135 #define DFS_READ 0x01
136 #define DFS_WRITE 0x02
137 #define DFS_EXECUTE 0x04
138 #define DFS_CONTROL 0x08
139 #define DFS_INSERT 0x10
140 #define DFS_DELETE 0x20
142 /* the application definable ones (backwards from AFS) */
143 #define DFS_USR0 0x80000000 /* "A" bit */
144 #define DFS_USR1 0x40000000 /* "B" bit */
145 #define DFS_USR2 0x20000000 /* "C" bit */
146 #define DFS_USR3 0x10000000 /* "D" bit */
147 #define DFS_USR4 0x08000000 /* "E" bit */
148 #define DFS_USR5 0x04000000 /* "F" bit */
149 #define DFS_USR6 0x02000000 /* "G" bit */
150 #define DFS_USR7 0x01000000 /* "H" bit */
151 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
152 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
155 * Offset of -id switch in command structure for various commands.
156 * The -if switch is the next switch always.
158 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
161 * Determine whether either the -id or -if switches are present, and
162 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
164 static int getidf(as, id)
165 struct cmd_syndesc *as;
166 int id; /* Offset of -id switch; -if is next switch */
170 if (as->parms[id].items) {
173 if (as->parms[id + 1].items) {
179 "%s: you may specify either -id or -if, but not both switches\n",
186 static int PRights(arights, dfs)
191 if (arights & PRSFS_READ) printf("r");
192 if (arights & PRSFS_LOOKUP) printf("l");
193 if (arights & PRSFS_INSERT) printf("i");
194 if (arights & PRSFS_DELETE) printf("d");
195 if (arights & PRSFS_WRITE) printf("w");
196 if (arights & PRSFS_LOCK) printf("k");
197 if (arights & PRSFS_ADMINISTER) printf("a");
198 if (arights & PRSFS_USR0) printf("A");
199 if (arights & PRSFS_USR1) printf("B");
200 if (arights & PRSFS_USR2) printf("C");
201 if (arights & PRSFS_USR3) printf("D");
202 if (arights & PRSFS_USR4) printf("E");
203 if (arights & PRSFS_USR5) printf("F");
204 if (arights & PRSFS_USR6) printf("G");
205 if (arights & PRSFS_USR7) printf("H");
207 if (arights & DFS_READ) printf("r"); else printf("-");
208 if (arights & DFS_WRITE) printf("w"); else printf("-");
209 if (arights & DFS_EXECUTE) printf("x"); else printf("-");
210 if (arights & DFS_CONTROL) printf("c"); else printf("-");
211 if (arights & DFS_INSERT) printf("i"); else printf("-");
212 if (arights & DFS_DELETE) printf("d"); else printf("-");
213 if (arights & (DFS_USRALL)) printf("+");
214 if (arights & DFS_USR0) printf("A");
215 if (arights & DFS_USR1) printf("B");
216 if (arights & DFS_USR2) printf("C");
217 if (arights & DFS_USR3) printf("D");
218 if (arights & DFS_USR4) printf("E");
219 if (arights & DFS_USR5) printf("F");
220 if (arights & DFS_USR6) printf("G");
221 if (arights & DFS_USR7) printf("H");
225 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
226 static int InAFS(apath)
229 struct ViceIoctl blob;
233 blob.out_size = MAXSIZE;
236 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
238 if ((errno == EINVAL) || (errno == ENOENT)) return 0;
243 /* return a static pointer to a buffer */
244 static char *Parent(apath)
248 strcpy(tspace, apath);
249 tp = rindex(tspace, '/');
253 else strcpy(tspace, ".");
257 enum rtype {add, destroy, deny};
259 static afs_int32 Convert(arights, dfs, rtypep)
268 *rtypep = add; /* add rights, by default */
271 if (!strcmp(arights, "null")) {
275 if (!strcmp(arights,"read")) return DFS_READ | DFS_EXECUTE;
276 if (!strcmp(arights, "write")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE;
277 if (!strcmp(arights, "all")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE | DFS_CONTROL;
279 if (!strcmp(arights,"read")) return PRSFS_READ | PRSFS_LOOKUP;
280 if (!strcmp(arights, "write")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK;
281 if (!strcmp(arights, "mail")) return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
282 if (!strcmp(arights, "all")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
284 if (!strcmp(arights, "none")) {
285 *rtypep = destroy; /* Remove entire entry */
288 len = strlen(arights);
293 if (tc == '-') continue;
294 else if (tc == 'r') mode |= DFS_READ;
295 else if (tc == 'w') mode |= DFS_WRITE;
296 else if (tc == 'x') mode |= DFS_EXECUTE;
297 else if (tc == 'c') mode |= DFS_CONTROL;
298 else if (tc == 'i') mode |= DFS_INSERT;
299 else if (tc == 'd') mode |= DFS_DELETE;
300 else if (tc == 'A') mode |= DFS_USR0;
301 else if (tc == 'B') mode |= DFS_USR1;
302 else if (tc == 'C') mode |= DFS_USR2;
303 else if (tc == 'D') mode |= DFS_USR3;
304 else if (tc == 'E') mode |= DFS_USR4;
305 else if (tc == 'F') mode |= DFS_USR5;
306 else if (tc == 'G') mode |= DFS_USR6;
307 else if (tc == 'H') mode |= DFS_USR7;
309 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n", pn, tc);
313 if (tc == 'r') mode |= PRSFS_READ;
314 else if (tc == 'l') mode |= PRSFS_LOOKUP;
315 else if (tc == 'i') mode |= PRSFS_INSERT;
316 else if (tc == 'd') mode |= PRSFS_DELETE;
317 else if (tc == 'w') mode |= PRSFS_WRITE;
318 else if (tc == 'k') mode |= PRSFS_LOCK;
319 else if (tc == 'a') mode |= PRSFS_ADMINISTER;
320 else if (tc == 'A') mode |= PRSFS_USR0;
321 else if (tc == 'B') mode |= PRSFS_USR1;
322 else if (tc == 'C') mode |= PRSFS_USR2;
323 else if (tc == 'D') mode |= PRSFS_USR3;
324 else if (tc == 'E') mode |= PRSFS_USR4;
325 else if (tc == 'F') mode |= PRSFS_USR5;
326 else if (tc == 'G') mode |= PRSFS_USR6;
327 else if (tc == 'H') mode |= PRSFS_USR7;
329 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn, tc);
337 static struct AclEntry *FindList(alist, aname)
338 struct AclEntry *alist;
342 if (!foldcmp(alist->name, aname)) return alist;
348 /* if no parm specified in a particular slot, set parm to be "." instead */
349 static void SetDotDefault(aitemp)
350 struct cmd_item **aitemp;
353 if (*aitemp) return; /* already has value */
354 /* otherwise, allocate an item representing "." */
355 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
357 ti->next = (struct cmd_item *) 0;
358 ti->data = (char *) malloc(2);
360 strcpy(ti->data, ".");
364 static void ChangeList(al, plus, aname, arights)
370 struct AclEntry *tlist;
371 tlist = (plus ? al->pluslist : al->minuslist);
372 tlist = FindList (tlist, aname);
374 /* Found the item already in the list. */
375 tlist->rights = arights;
377 al->nplus -= PruneList(&al->pluslist, al->dfs);
379 al->nminus -= PruneList(&al->minuslist, al->dfs);
382 /* Otherwise we make a new item and plug in the new data. */
383 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
385 strcpy(tlist->name, aname);
386 tlist->rights = arights;
388 tlist->next = al->pluslist;
389 al->pluslist = tlist;
391 if (arights == 0 || arights == -1)
392 al->nplus -= PruneList(&al->pluslist, al->dfs);
395 tlist->next = al->minuslist;
396 al->minuslist = tlist;
398 if (arights == 0) al->nminus -= PruneList(&al->minuslist, al->dfs);
402 static void ZapList(alist)
403 struct AclEntry *alist;
405 struct AclEntry *tp, *np;
406 for (tp = alist; tp; tp = np) {
412 static int PruneList(ae, dfs)
413 struct AclEntry **ae;
416 struct AclEntry **lp;
417 struct AclEntry *te, *ne;
421 for(te = *ae;te;te=ne) {
422 if ((!dfs && te->rights == 0) || te->rights == -1) {
436 static char *SkipLine(astr)
439 while (*astr !='\n') astr++;
445 * Create an empty acl, taking into account whether the acl pointed
446 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
447 * can recover from problems caused by bogus ACL's (in that case, always
448 * assume that the acl is AFS: for DFS, the user can always resort to
449 * acl_edit, but for AFS there may be no other way out).
451 static struct Acl *EmptyAcl(astr)
457 tp = (struct Acl *)malloc(sizeof (struct Acl));
459 tp->nplus = tp->nminus = 0;
460 tp->pluslist = tp->minuslist = 0;
462 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
466 static struct Acl *ParseAcl(astr)
469 int nplus, nminus, i, trights;
471 struct AclEntry *first, *last, *tl;
474 ta = (struct Acl *) malloc (sizeof (struct Acl));
477 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
478 astr = SkipLine(astr);
479 sscanf(astr, "%d", &ta->nminus);
480 astr = SkipLine(astr);
487 for(i=0;i<nplus;i++) {
488 sscanf(astr, "%100s %d", tname, &trights);
489 astr = SkipLine(astr);
490 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
492 if (!first) first = tl;
493 strcpy(tl->name, tname);
494 tl->rights = trights;
496 if (last) last->next = tl;
499 ta->pluslist = first;
503 for(i=0;i<nminus;i++) {
504 sscanf(astr, "%100s %d", tname, &trights);
505 astr = SkipLine(astr);
506 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
508 if (!first) first = tl;
509 strcpy(tl->name, tname);
510 tl->rights = trights;
512 if (last) last->next = tl;
515 ta->minuslist = first;
520 static PrintStatus(status, name, offmsg)
521 VolumeStatus *status;
525 printf("Volume status for vid = %u named %s\n",status->Vid, name);
527 printf("Current offline message is %s\n",offmsg);
528 printf("Current disk quota is ");
529 if (status->MaxQuota != 0) printf("%d\n", status->MaxQuota);
530 else printf("unlimited\n");
531 printf("Current blocks used are %d\n",status->BlocksInUse);
532 printf("The partition has %d blocks available out of %d\n\n",status->PartBlocksAvail, status->PartMaxBlocks);
535 static QuickPrintStatus(status, name)
536 VolumeStatus *status;
539 double QuotaUsed =0.0;
540 double PartUsed =0.0;
542 printf("%-25.25s",name);
544 if (status->MaxQuota != 0) {
545 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
546 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
548 printf(" no limit%10d", status->BlocksInUse);
550 if (QuotaUsed > 90.0) {
551 printf("%5.0f%%<<", QuotaUsed);
554 else printf("%5.0f%% ", QuotaUsed);
555 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
556 if (PartUsed > 97.0) {
557 printf("%9.0f%%<<", PartUsed);
560 else printf("%9.0f%% ", PartUsed);
562 printf(" <<WARNING\n");
567 static QuickPrintSpace(status, name)
568 VolumeStatus *status;
571 double PartUsed =0.0;
573 printf("%-25.25s",name);
575 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
577 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
578 if (PartUsed > 90.0){
579 printf(" %4.0f%%<<", PartUsed);
582 else printf(" %4.0f%% ", PartUsed);
584 printf(" <<WARNING\n");
589 static char *AclToString(acl)
592 static char mydata[MAXSIZE];
593 char tstring[MAXSIZE];
597 if (acl->dfs) sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
598 else dfsstring[0] = '\0';
599 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
600 for(tp = acl->pluslist;tp;tp=tp->next) {
601 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
602 strcat(mydata, tstring);
604 for(tp = acl->minuslist;tp;tp=tp->next) {
605 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
606 strcat(mydata, tstring);
612 struct cmd_syndesc *as;
615 struct ViceIoctl blob;
617 struct cmd_item *ti, *ui;
621 int idf = getidf(as, parm_setacl_id);
624 if (as->parms[2].items) clear=1;
626 plusp = !(as->parms[3].items);
627 for(ti=as->parms[0].items; ti;ti=ti->next) {
628 blob.out_size = MAXSIZE;
630 blob.in = blob.out = space;
631 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
633 Die(errno, ti->data);
639 ta = ParseAcl(space);
640 if (!plusp && ta->dfs) {
642 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
644 "(you may specify \"null\" to revoke all rights, however)\n");
650 if (clear) ta = EmptyAcl(space);
651 else ta = ParseAcl(space);
652 CleanAcl(ta, ti->data);
653 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
656 fprintf(stderr, "%s: Missing second half of user/access pair.\n", pn);
660 rights = Convert(ui->next->data, ta->dfs, &rtype);
661 if (rtype == destroy && !ta->dfs) {
662 struct AclEntry *tlist;
664 tlist = (plusp ? ta->pluslist : ta->minuslist);
665 if (!FindList(tlist, ui->data))
668 if (rtype == deny && !ta->dfs) plusp = 0;
669 if (rtype == destroy && ta->dfs) rights = -1;
670 ChangeList(ta, plusp, ui->data, rights);
672 blob.in = AclToString(ta);
674 blob.in_size = 1+strlen(blob.in);
675 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
677 if (errno == EINVAL) {
679 static char *fsenv = 0;
681 fsenv = (char *)getenv("FS_EXPERT");
683 fprintf(stderr, "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n", pn);
686 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
687 "\nPossible reasons for this include:\n\n",
688 " -You may have specified an inappropriate combination of rights.\n",
689 " For example, some DFS-supported filesystems may not allow you to\n",
690 " drop the \"c\" right from \"user_obj\".\n\n",
691 " -A mask_obj may be required (it is likely required by the underlying\n",
692 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
693 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
694 " does not automatically create or update the mask_obj. Try setting\n",
695 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
696 " users or groups. You can do this with a single command, such as\n",
697 " \"fs sa mask_obj all user:somename read\"\n\n",
698 " -A specified user or group may not exist.\n\n",
699 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
700 " This is probably not allowed by the underlying file system.\n\n",
701 " -If you add a user or group to a DFS ACL, remember that it must be\n",
702 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
703 " may be local requirements on the format of the user or group name.\n",
704 " Check with your cell administrator.\n\n",
705 " -Or numerous other possibilities. It would be great if we could be more\n",
706 " precise about the actual problem, but for various reasons, this is\n",
707 " impractical via this interface. If you can't figure it out, you\n",
708 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
709 " whatever is provided). You may get better results. Good luck!\n\n",
710 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
713 fprintf(stderr, "%s: Invalid argument, possible reasons include:\n", pn);
714 fprintf(stderr, "\t-File not in AFS\n");
715 fprintf(stderr, "\t-Too many users on access control list\n");
716 fprintf(stderr, "\t-Tried to add non-existent user to access control list\n");
720 Die(errno, ti->data);
730 static CopyACLCmd(as)
731 struct cmd_syndesc *as;
734 struct ViceIoctl blob;
735 struct Acl *fa, *ta = 0;
737 struct cmd_item *ti, *ui;
741 int idf = getidf(as, parm_copyacl_id);
744 if (as->parms[2].items) clear=1;
746 blob.out_size = MAXSIZE;
748 blob.in = blob.out = space;
749 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
751 Die(errno, as->parms[0].items->data);
754 fa = ParseAcl(space);
755 CleanAcl(fa, as->parms[0].items->data);
756 for (ti=as->parms[1].items; ti;ti=ti->next) {
757 blob.out_size = MAXSIZE;
759 blob.in = blob.out = space;
760 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
762 Die(errno, ti->data);
768 if (clear) ta = EmptyAcl(space);
769 else ta = ParseAcl(space);
770 CleanAcl(ta, ti->data);
771 if (ta->dfs != fa->dfs) {
772 fprintf(stderr, "%s: incompatible file system types: acl not copied to %s; aborted\n", pn, ti->data);
777 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
778 fprintf(stderr, "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", pn, ti->data);
782 strcpy(ta->cell, fa->cell);
784 for (tp = fa->pluslist;tp;tp=tp->next)
785 ChangeList(ta, 1, tp->name, tp->rights);
786 for (tp = fa->minuslist;tp;tp=tp->next)
787 ChangeList(ta, 0, tp->name, tp->rights);
788 blob.in = AclToString(ta);
790 blob.in_size = 1+strlen(blob.in);
791 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
793 if (errno == EINVAL) {
794 fprintf(stderr, "%s: Invalid argument, possible reasons include:\n", pn);
795 fprintf(stderr, "\t-File not in AFS\n");
798 Die(errno, ti->data);
808 /* pioctl() call to get the cellname of a pathname */
809 static afs_int32 GetCell(fname, cellname)
810 char *fname, *cellname;
813 struct ViceIoctl blob;
816 blob.out_size = MAXCELLCHARS;
819 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
820 return code ? errno : 0;
823 /* Check if a username is valid: If it contains only digits (or a
824 * negative sign), then it might be bad. We then query the ptserver
827 static BadName(aname, fname)
830 afs_int32 tc, code, id;
832 char cell[MAXCELLCHARS];
834 for (nm=aname; tc=*nm; nm++) {
835 /* all must be '-' or digit to be bad */
836 if (tc != '-' && (tc < '0' || tc > '9')) return 0;
839 /* Go to the PRDB and see if this all number username is valid */
840 code = GetCell(fname, cell);
843 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
844 code = pr_SNameToId(aname, &id);
847 /* 1=>Not-valid; 0=>Valid */
848 return ((!code && (id==ANONYMOUSID)) ? 1 : 0);
852 /* clean up an access control list of its bad entries; return 1 if we made
853 any changes to the list, and 0 otherwise */
854 static CleanAcl(aa, fname)
856 char *fname; /* The file name */
858 struct AclEntry *te, **le, *ne;
861 /* Don't correct DFS ACL's for now */
865 /* prune out bad entries */
866 changes = 0; /* count deleted entries */
868 for(te = aa->pluslist; te; te=ne) {
870 if (BadName(te->name,fname)) {
882 for(te = aa->minuslist; te; te=ne) {
884 if (BadName(te->name,fname)) {
899 /* clean up an acl to not have bogus entries */
900 static CleanACLCmd(as)
901 struct cmd_syndesc *as;
905 struct ViceIoctl blob;
911 SetDotDefault(&as->parms[0].items);
912 for(ti=as->parms[0].items; ti; ti=ti->next) {
913 blob.out_size = MAXSIZE;
916 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
918 Die(errno, ti->data);
924 ta = ParseAcl(space);
927 "%s: cleanacl is not supported for DFS access lists.\n",
933 changes = CleanAcl(ta, ti->data);
936 /* now set the acl */
937 blob.in=AclToString(ta);
938 blob.in_size = strlen(blob.in)+1;
940 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
942 if (errno == EINVAL) {
943 fprintf(stderr, "%s: Invalid argument, possible reasons include\n", pn);
944 fprintf(stderr, "%s: File not in vice or\n", pn);
945 fprintf(stderr, "%s: Too many users on access control list or\n", pn);
948 Die(errno, ti->data);
954 /* now list the updated acl */
955 printf("Access list for %s is now\n", ti->data);
957 if (!ta->dfs) printf("Normal rights:\n");
958 for(te = ta->pluslist;te;te=te->next) {
959 printf(" %s ", te->name);
960 PRights(te->rights, ta->dfs);
964 if (ta->nminus > 0) {
965 printf("Negative rights:\n");
966 for(te = ta->minuslist;te;te=te->next) {
967 printf(" %s ", te->name);
968 PRights(te->rights, ta->dfs);
972 if (ti->next) printf("\n");
975 printf("Access list for %s is fine.\n", ti->data);
981 static ListACLCmd(as)
982 struct cmd_syndesc *as;
986 struct ViceIoctl blob;
989 int idf = getidf(as, parm_listacl_id);
992 SetDotDefault(&as->parms[0].items);
993 for(ti=as->parms[0].items; ti; ti=ti->next) {
994 blob.out_size = MAXSIZE;
996 blob.in = blob.out = space;
997 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
999 Die(errno, ti->data);
1003 ta = ParseAcl(space);
1006 printf("Access list for %s is\n", ti->data);
1009 printf("DFS access list for %s is\n", ti->data);
1012 printf("DFS initial directory access list of %s is\n", ti->data);
1015 printf("DFS initial file access list of %s is\n", ti->data);
1019 printf(" Default cell = %s\n", ta->cell);
1021 if (ta->nplus > 0) {
1022 if (!ta->dfs) printf("Normal rights:\n");
1023 for(te = ta->pluslist;te;te=te->next) {
1024 printf(" %s ", te->name);
1025 PRights(te->rights, ta->dfs);
1029 if (ta->nminus > 0) {
1030 printf("Negative rights:\n");
1031 for(te = ta->minuslist;te;te=te->next) {
1032 printf(" %s ", te->name);
1033 PRights(te->rights, ta->dfs);
1037 if (ti->next) printf("\n");
1043 static FlushVolumeCmd(as)
1044 struct cmd_syndesc *as;
1047 struct ViceIoctl blob;
1048 struct cmd_item *ti;
1051 SetDotDefault(&as->parms[0].items);
1052 for(ti=as->parms[0].items; ti; ti=ti->next) {
1053 blob.in_size = blob.out_size = 0;
1054 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1056 fprintf(stderr, "Error flushing volume ");
1066 struct cmd_syndesc *as;
1069 struct ViceIoctl blob;
1070 struct cmd_item *ti;
1073 for(ti=as->parms[0].items; ti; ti=ti->next) {
1074 blob.in_size = blob.out_size = 0;
1075 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1077 if (errno == EMFILE) {
1078 fprintf(stderr, "%s: Can't flush active file %s\n", pn, ti->data);
1081 fprintf(stderr, "%s: Error flushing file ", pn);
1091 /* all this command does is repackage its args and call SetVolCmd */
1092 static SetQuotaCmd(as)
1093 struct cmd_syndesc *as;
1095 struct cmd_syndesc ts;
1097 /* copy useful stuff from our command slot; we may later have to reorder */
1098 bcopy(as, &ts, sizeof(ts)); /* copy whole thing */
1099 return SetVolCmd(&ts);
1102 static SetVolCmd(as)
1103 struct cmd_syndesc *as;
1106 struct ViceIoctl blob;
1107 struct cmd_item *ti;
1108 struct VolumeStatus *status;
1109 char *offmsg, *input;
1112 SetDotDefault(&as->parms[0].items);
1113 for(ti=as->parms[0].items; ti; ti=ti->next) {
1115 blob.out_size = MAXSIZE;
1116 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1119 status = (VolumeStatus *)space;
1120 status->MinQuota = status->MaxQuota = -1;
1121 offmsg = (char *) 0;
1122 if (as->parms[1].items) {
1123 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1125 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1130 if (as->parms[2].items) offmsg = as->parms[2].items->data;
1131 input = (char *)status + sizeof(*status);
1132 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1134 if (strlen(offmsg) >= VMSGSIZE) {
1135 fprintf(stderr, "%s: message must be shorter than %d characters\n",
1140 strcpy(input,offmsg);
1141 blob.in_size += strlen(offmsg);
1142 input += strlen(offmsg) + 1;
1144 else *(input++) = '\0';
1145 *(input++) = '\0'; /* Pad for old style volume "motd" */
1146 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1148 Die(errno, ti->data);
1155 static ExamineCmd(as)
1156 struct cmd_syndesc *as;
1159 struct ViceIoctl blob;
1160 struct cmd_item *ti;
1161 struct VolumeStatus *status;
1162 char *name, *offmsg;
1165 SetDotDefault(&as->parms[0].items);
1166 for(ti=as->parms[0].items; ti; ti=ti->next) {
1168 blob.out_size = MAXSIZE;
1171 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1173 Die(errno, ti->data);
1177 status = (VolumeStatus *)space;
1178 name = (char *)status + sizeof(*status);
1179 offmsg = name + strlen(name) + 1;
1180 PrintStatus(status, name, offmsg);
1185 static ListQuotaCmd(as)
1186 struct cmd_syndesc *as;
1189 struct ViceIoctl blob;
1190 struct cmd_item *ti;
1191 struct VolumeStatus *status;
1195 printf("%-25s%-10s%-10s%-7s%-11s\n",
1196 "Volume Name"," Quota", " Used", " %Used", " Partition");
1197 SetDotDefault(&as->parms[0].items);
1198 for(ti=as->parms[0].items; ti; ti=ti->next) {
1200 blob.out_size = MAXSIZE;
1203 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1205 Die(errno, ti->data);
1209 status = (VolumeStatus *)space;
1210 name = (char *)status + sizeof(*status);
1211 QuickPrintStatus(status, name);
1216 static WhereIsCmd(as)
1217 struct cmd_syndesc *as;
1220 struct ViceIoctl blob;
1221 struct cmd_item *ti;
1227 SetDotDefault(&as->parms[0].items);
1228 for(ti=as->parms[0].items; ti; ti=ti->next) {
1230 blob.out_size = MAXSIZE;
1233 bzero(space, sizeof(space));
1234 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1236 Die(errno, ti->data);
1240 hosts = (afs_int32 *) space;
1241 printf("File %s is on host%s ", ti->data, (hosts[0] && !hosts[1]) ? "": "s");
1242 for(j=0; j<MAXHOSTS; j++) {
1243 if (hosts[j] == 0) break;
1244 tp = hostutil_GetNameByINet(hosts[j]);
1253 static DiskFreeCmd(as)
1254 struct cmd_syndesc *as;
1257 struct ViceIoctl blob;
1258 struct cmd_item *ti;
1260 struct VolumeStatus *status;
1263 printf("%-25s%-10s%-10s%-10s%-6s\n",
1264 "Volume Name"," kbytes", " used", " avail", " %used");
1265 SetDotDefault(&as->parms[0].items);
1266 for(ti=as->parms[0].items; ti; ti=ti->next) {
1268 blob.out_size = MAXSIZE;
1271 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1273 Die(errno, ti->data);
1277 status = (VolumeStatus *)space;
1278 name = (char *)status + sizeof(*status);
1279 QuickPrintSpace(status, name);
1285 struct cmd_syndesc *as;
1288 struct ViceIoctl blob;
1289 struct cmd_item *ti;
1291 struct VolumeStatus *status;
1294 SetDotDefault(&as->parms[0].items);
1295 for(ti=as->parms[0].items; ti; ti=ti->next) {
1297 blob.out_size = MAXSIZE;
1300 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1302 Die(errno, ti->data);
1306 status = (VolumeStatus *)space;
1307 if (status->MaxQuota) quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1308 else quotaPct = 0.0;
1309 printf("%2.0f%% of quota used.\n", quotaPct);
1314 static ListMountCmd(as)
1315 struct cmd_syndesc *as;
1318 struct ViceIoctl blob;
1319 struct cmd_item *ti;
1320 char orig_name[1024]; /*Original name, may be modified*/
1321 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1322 char parent_dir[1024]; /*Parent directory of true name*/
1323 char *last_component; /*Last component of true name*/
1324 struct stat statbuff; /*Buffer for status info*/
1325 int link_chars_read; /*Num chars read in readlink()*/
1326 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1329 for(ti=as->parms[0].items; ti; ti=ti->next) {
1332 sprintf(orig_name, "%s%s",
1333 (ti->data[0] == '/') ? "" : "./",
1336 if (lstat(orig_name, &statbuff) < 0) {
1337 /* if lstat fails, we should still try the pioctl, since it
1338 may work (for example, lstat will fail, but pioctl will
1339 work if the volume of offline (returning ENODEV). */
1340 statbuff.st_mode = S_IFDIR; /* lie like pros */
1344 * The lstat succeeded. If the given file is a symlink, substitute
1345 * the file name with the link name.
1347 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1350 * Read name of resolved file.
1352 link_chars_read = readlink(orig_name, true_name, 1024);
1353 if (link_chars_read <= 0) {
1354 fprintf(stderr, "%s: Can't read target name for '%s' symbolic link!\n",
1361 * Add a trailing null to what was read, bump the length.
1363 true_name[link_chars_read++] = 0;
1366 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1367 * have to create a full pathname using the original name and the
1368 * relative symlink name. Find the rightmost slash in the original
1369 * name (we know there is one) and splice in the symlink value.
1371 if (true_name[0] != '/') {
1372 last_component = (char *) rindex(orig_name, '/');
1373 strcpy(++last_component, true_name);
1374 strcpy(true_name, orig_name);
1378 strcpy(true_name, orig_name);
1381 * Find rightmost slash, if any.
1383 last_component = (char *) rindex(true_name, '/');
1384 if (last_component) {
1386 * Found it. Designate everything before it as the parent directory,
1387 * everything after it as the final component.
1389 strncpy(parent_dir, true_name, last_component - true_name);
1390 parent_dir[last_component - true_name] = 0;
1391 last_component++; /*Skip the slash*/
1395 * No slash appears in the given file name. Set parent_dir to the current
1396 * directory, and the last component as the given name.
1398 strcpy(parent_dir, ".");
1399 last_component = true_name;
1402 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1403 fprintf(stderr, "%s: you may not use '.' or '..' as the last component\n", pn);
1404 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n", pn);
1409 blob.in = last_component;
1410 blob.in_size = strlen(last_component)+1;
1411 blob.out_size = MAXSIZE;
1413 bzero(space, MAXSIZE);
1415 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1418 printf("'%s' is a %smount point for volume '%s'\n",
1420 (thru_symlink ? "symbolic link, leading to a " : ""),
1424 if (errno == EINVAL) {
1425 fprintf(stderr, "'%s' is not a mount point.\n",
1429 Die(errno, (ti->data ? ti->data : parent_dir));
1437 static MakeMountCmd(as)
1438 struct cmd_syndesc *as;
1441 char *cellName, *volName, *tmpName;
1442 struct afsconf_cell info;
1443 struct vldbentry vldbEntry;
1444 struct ViceIoctl blob;
1450 if (as->parms[5].items && !as->parms[2].items) {
1451 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1456 if (as->parms[2].items) /* cell name specified */
1457 cellName = as->parms[2].items->data;
1459 cellName = (char *) 0;
1460 volName = as->parms[1].items->data;
1462 if (strlen(volName) >= 64) {
1463 fprintf(stderr, "%s: volume name too long (length must be < 64 characters)\n", pn);
1467 /* Check for a cellname in the volume specification, and complain
1468 * if it doesn't match what was specified with -cell */
1469 if (tmpName = index(volName, ':')) {
1472 if (strcasecmp(cellName,volName)) {
1473 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1478 volName = ++tmpName;
1481 if (!InAFS(Parent(as->parms[0].items->data))) {
1482 fprintf(stderr, "%s: mount points must be created within the AFS file system\n", pn);
1488 blob.out_size = MAXSIZE;
1490 code = pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME, &blob, 1);
1493 code = GetCellName(cellName?cellName:space, &info);
1497 if (!(as->parms[4].items)) {
1498 /* not fast, check which cell the mountpoint is being created in */
1499 /* not fast, check name with VLDB */
1500 code = VLDBInit(1, &info);
1502 /* make the check. Don't complain if there are problems with init */
1503 code = ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, &vldbEntry);
1504 if (code == VL_NOENT) {
1505 fprintf(stderr, "%s: warning, volume %s does not exist in cell %s.\n",
1506 pn, volName, cellName ? cellName : space);
1511 if (as->parms[3].items) /* if -rw specified */
1516 /* cellular mount point, prepend cell prefix */
1517 strcat(space, info.name);
1520 strcat(space, volName); /* append volume name */
1521 strcat(space, "."); /* stupid convention; these end with a period */
1522 code = symlink(space, as->parms[0].items->data);
1524 Die(errno, as->parms[0].items->data);
1531 * Delete AFS mount points. Variables are used as follows:
1532 * tbuffer: Set to point to the null-terminated directory name of the mount point
1533 * (or ``.'' if none is provided)
1534 * tp: Set to point to the actual name of the mount point to nuke.
1536 static RemoveMountCmd(as)
1537 struct cmd_syndesc *as;
1540 struct ViceIoctl blob;
1541 struct cmd_item *ti;
1543 char lsbuffer[1024];
1547 for(ti=as->parms[0].items; ti; ti=ti->next) {
1549 tp = (char *) rindex(ti->data, '/');
1551 strncpy(tbuffer, ti->data, code=tp-ti->data); /* the dir name */
1553 tp++; /* skip the slash */
1556 strcpy(tbuffer, ".");
1560 blob.in_size = strlen(tp)+1;
1561 blob.out = lsbuffer;
1562 blob.out_size = sizeof(lsbuffer);
1563 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1565 if (errno == EINVAL) {
1566 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn, ti->data);
1569 Die(errno, ti->data);
1572 continue; /* don't bother trying */
1576 blob.in_size = strlen(tp)+1;
1577 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1579 Die(errno, ti->data);
1589 static CheckServersCmd(as)
1590 struct cmd_syndesc *as;
1593 struct ViceIoctl blob;
1599 struct afsconf_cell info;
1600 struct chservinfo checkserv;
1602 bzero(&checkserv,sizeof(struct chservinfo));
1603 blob.in_size=sizeof(struct chservinfo);
1604 blob.in=(caddr_t)&checkserv;
1606 blob.out_size = MAXSIZE;
1608 bzero(space, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1610 /* prepare flags for checkservers command */
1611 temp = 2; /* default to checking local cell only */
1612 if (as->parms[2].items) temp |= 1; /* set fast flag */
1613 if (as->parms[1].items) temp &= ~2; /* turn off local cell check */
1615 checkserv.magic = 0x12345678; /* XXX */
1616 checkserv.tflags=temp;
1618 /* now copy in optional cell name, if specified */
1619 if (as->parms[0].items) {
1620 code = GetCellName(as->parms[0].items->data, &info);
1624 strcpy(checkserv.tbuffer,info.name);
1625 checkserv.tsize=strlen(info.name)+1;
1628 strcpy(checkserv.tbuffer,"\0");
1632 if(as->parms[3].items) {
1633 checkserv.tinterval=atol(as->parms[3].items->data);
1636 if(checkserv.tinterval<0) {
1637 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
1638 checkserv.tinterval=0;
1640 else if(checkserv.tinterval> 600) {
1641 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1642 checkserv.tinterval=600; /* 10 min max interval */
1646 checkserv.tinterval = -1; /* don't change current interval */
1649 code = pioctl(0, VIOCCKSERV, &blob, 1);
1651 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1652 printf("Must be root to change -interval\n");
1658 bcopy(space, &temp, sizeof(afs_int32));
1659 if (checkserv.tinterval >= 0) {
1660 if (checkserv.tinterval > 0)
1661 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1662 checkserv.tinterval, temp);
1664 printf("The current down server probe interval is %d secs\n", temp);
1668 printf("All servers are running.\n");
1671 printf("These servers unavailable due to network or server problems: ");
1673 bcopy(space + j*sizeof(afs_int32), &temp, sizeof(afs_int32));
1674 if (temp == 0) break;
1675 tp = hostutil_GetNameByINet(temp);
1684 static MessagesCmd(as)
1685 struct cmd_syndesc *as;
1688 struct ViceIoctl blob;
1691 struct gaginfo gagflags;
1692 struct cmd_item *show;
1694 bzero (&gagflags, sizeof(struct gaginfo));
1695 blob.in_size = sizeof(struct gaginfo);
1696 blob.in = (caddr_t) &gagflags;
1697 blob.out_size = MAXSIZE;
1699 bzero(space, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1701 if (show = as->parms[0].items) {
1702 if (!strcasecmp (show->data, "user"))
1703 gagflags.showflags |= GAGUSER;
1704 else if (!strcasecmp (show->data, "console"))
1705 gagflags.showflags |= GAGCONSOLE;
1706 else if (!strcasecmp (show->data, "all"))
1707 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1708 else if (!strcasecmp (show->data, "none"))
1712 "unrecognized flag %s: must be in {user,console,all,none}\n",
1721 code = pioctl(0, VIOC_GAG, &blob, 1);
1730 static CheckVolumesCmd(as)
1731 struct cmd_syndesc *as;
1734 struct ViceIoctl blob;
1738 code = pioctl(0, VIOCCKBACK, &blob, 1);
1744 printf("All volumeID/name mappings checked.\n");
1748 static SetCacheSizeCmd(as)
1749 struct cmd_syndesc *as;
1752 struct ViceIoctl blob;
1755 if (!as->parms[0].items && !as->parms[1].items) {
1756 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
1759 if (as->parms[0].items) {
1760 code = util_GetInt32(as->parms[0].items->data, &temp);
1762 fprintf(stderr, "%s: bad integer specified for cache size.\n", pn);
1768 blob.in = (char *) &temp;
1769 blob.in_size = sizeof(afs_int32);
1771 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
1773 if (errno == EROFS) {
1774 printf("'fs setcache' not allowed on memory cache based cache managers.\n");
1777 Die(errno, (char *) 0);
1782 printf("New cache size set.\n");
1786 #define MAXGCSIZE 16
1787 static GetCacheParmsCmd(as)
1788 struct cmd_syndesc *as;
1791 struct ViceIoctl blob;
1792 afs_int32 parms[MAXGCSIZE];
1794 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
1795 blob.in = (char *) 0;
1797 blob.out_size = sizeof(parms);
1798 blob.out = (char *) parms;
1799 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
1801 Die(errno, (char *) 0);
1804 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
1805 parms[1], parms[0]);
1806 if (parms[1] > parms[0])
1807 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
1811 static ListCellsCmd(as)
1812 struct cmd_syndesc *as;
1818 struct ViceIoctl blob;
1821 resolve = !(as->parms[0].items); /* -numeric */
1825 bcopy(&i, tp, sizeof(afs_int32));
1826 blob.out_size = MAXSIZE;
1827 blob.in_size = sizeof(afs_int32);
1830 code = pioctl(0, VIOCGETCELL, &blob, 1);
1832 if (errno == EDOM) break; /* done with the list */
1837 printf("Cell %s on hosts", tp+MAXCELLHOSTS*sizeof(afs_int32));
1838 for(j=0; j < MAXCELLHOSTS; j++) {
1840 char *name, tbuffer[20];
1842 bcopy(tp + j*sizeof(afs_int32), &addr, sizeof(afs_int32));
1843 if (addr == 0) break;
1846 name = hostutil_GetNameByINet(addr);
1850 sprintf(tbuffer, "%d.%d.%d.%d",
1851 (addr>>24) & 0xff, (addr>>16) & 0xff,
1852 (addr>>8) & 0xff, addr & 0xff);
1855 printf(" %s", name);
1862 static NewCellCmd(as)
1863 struct cmd_syndesc *as;
1865 afs_int32 code, linkedstate=0, size=0, *lp;
1866 struct ViceIoctl blob;
1867 struct cmd_item *ti;
1868 char *tp, *cellname=0;
1869 struct hostent *thp;
1870 afs_int32 fsport = 0, vlport = 0;
1871 afs_int32 magic, scount; /* Number of servers to pass in pioctl call */
1874 * With the NEWCELL pioctl call, 3.4 clients take an array of
1875 * MAXHOSTS (13) servers while 3.5 clients take an array of
1876 * MAXCELLHOSTS (8) servers. To determine which we are talking to,
1877 * do a GETCELL pioctl and pass it a magic number. If an array of
1878 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
1881 lp = (afs_int32 *)tp;
1882 *lp++ = 0; /* first cell entry */
1883 *lp = 0x12345678; /* magic */
1884 blob.out_size = MAXSIZE;
1885 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
1888 code = pioctl(0, VIOCGETCELL, &blob, 1);
1894 cellname = tp + MAXCELLHOSTS*sizeof(afs_int32);
1895 scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
1897 /* Now setup and do the NEWCELL pioctl call */
1898 bzero(space, (scount+1) * sizeof(afs_int32));
1900 lp = (afs_int32 *)tp;
1902 tp += sizeof(afs_int32);
1903 for(ti=as->parms[1].items; ti; ti=ti->next) {
1904 thp = hostutil_GetHostByName(ti->data);
1906 fprintf(stderr, "%s: Host %s not found in host table, skipping it.\n",
1910 bcopy(thp->h_addr, tp, sizeof(afs_int32));
1911 tp += sizeof(afs_int32);
1914 if (as->parms[2].items) {
1916 * Link the cell, for the purposes of volume location, to the specified
1919 cellname = as->parms[2].items->data;
1922 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
1923 if (as->parms[3].items) {
1924 code = util_GetInt32(as->parms[3].items->data, &vlport);
1926 fprintf(stderr, "%s: bad integer specified for the fileserver port.\n", pn);
1930 if (as->parms[4].items) {
1931 code = util_GetInt32(as->parms[4].items->data, &fsport);
1933 fprintf(stderr, "%s: bad integer specified for the vldb server port.\n", pn);
1938 tp = (char *)(space + (scount+1) *sizeof(afs_int32));
1939 lp = (afs_int32 *)tp;
1943 strcpy(space + ((scount+4) * sizeof(afs_int32)), as->parms[0].items->data);
1944 size = ((scount+4) * sizeof(afs_int32))
1945 + strlen(as->parms[0].items->data)
1947 tp = (char *)(space + size);
1949 strcpy(tp, cellname);
1950 size += strlen(cellname) + 1;
1952 blob.in_size = size;
1955 code = pioctl(0, VIOCNEWCELL, &blob, 1);
1963 static WhichCellCmd(as)
1964 struct cmd_syndesc *as;
1967 struct cmd_item *ti;
1969 char cell[MAXCELLCHARS];
1971 SetDotDefault(&as->parms[0].items);
1972 for (ti=as->parms[0].items; ti; ti=ti->next) {
1973 code = GetCell(ti->data, cell);
1975 if (errno == ENOENT)
1976 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
1978 Die(errno, ti->data);
1983 printf("File %s lives in cell '%s'\n", ti->data, cell);
1988 static WSCellCmd(as)
1989 struct cmd_syndesc *as;
1992 struct ViceIoctl blob;
1995 blob.in = (char *) 0;
1996 blob.out_size = MAXSIZE;
1999 code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1);
2001 Die(errno, (char *) 0);
2005 printf("This workstation belongs to cell '%s'\n", space);
2010 static PrimaryCellCmd(as)
2011 struct cmd_syndesc *as;
2013 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2018 static MonitorCmd(as)
2019 struct cmd_syndesc *as;
2022 struct ViceIoctl blob;
2023 struct cmd_item *ti;
2025 struct hostent *thp;
2029 ti = as->parms[0].items;
2033 if (!strcmp(ti->data, "off"))
2034 hostAddr = 0xffffffff;
2036 thp = hostutil_GetHostByName(ti->data);
2038 if (!strcmp(ti->data, "localhost")) {
2039 fprintf(stderr, "localhost not in host table, assuming 127.0.0.1\n");
2040 hostAddr = htonl(0x7f000001);
2043 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2047 else bcopy(thp->h_addr, &hostAddr, sizeof(afs_int32));
2051 hostAddr = 0; /* means don't set host */
2052 setp = 0; /* aren't setting host */
2055 /* now do operation */
2056 blob.in_size = sizeof(afs_int32);
2057 blob.out_size = sizeof(afs_int32);
2058 blob.in = (char *) &hostAddr;
2059 blob.out = (char *) &hostAddr;
2060 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2066 printf("%s: new monitor host set.\n", pn);
2069 /* now decode old address */
2070 if (hostAddr == 0xffffffff) {
2071 printf("Cache monitoring is currently disabled.\n");
2074 tp = hostutil_GetNameByINet(hostAddr);
2075 printf("Using host %s for monitor services.\n", tp);
2081 static SysNameCmd(as)
2082 struct cmd_syndesc *as;
2085 struct ViceIoctl blob;
2086 struct cmd_item *ti;
2087 char *input = space;
2090 ti = as->parms[0].items;
2093 blob.out_size = MAXSIZE;
2094 blob.in_size = sizeof(afs_int32);
2095 input += sizeof(afs_int32);
2096 for(; ti; ti=ti->next) {
2098 blob.in_size += strlen(ti->data) + 1;
2099 if (blob.in_size > MAXSIZE) {
2100 fprintf(stderr, "%s: sysname%s too long.\n", pn, setp > 1 ? "s" : "");
2103 strcpy(input, ti->data);
2104 input += strlen(ti->data);
2107 bcopy(&setp, space, sizeof(afs_int32));
2108 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2114 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2118 bcopy(input, &setp, sizeof(afs_int32));
2119 input += sizeof(afs_int32);
2121 fprintf(stderr, "No sysname name value was found\n");
2124 printf("Current sysname%s is:", setp>1 ? " list" : "");
2125 for(;setp>0;--setp) {
2126 printf(" %s", input);
2127 input += strlen(input) + 1;
2133 static char *exported_types[] = {"null", "nfs", ""};
2134 static ExportAfsCmd(as)
2135 struct cmd_syndesc *as;
2138 struct ViceIoctl blob;
2139 struct cmd_item *ti;
2140 int export=0, type=0, mode = 0, exp = 0, exportcall, pwsync=0, smounts=0;
2142 ti = as->parms[0].items;
2143 if (strcmp(ti->data, "nfs") == 0) type = 0x71; /* NFS */
2145 fprintf(stderr, "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2148 ti = as->parms[1].items;
2150 if (strcmp(ti->data, "on") == 0) export = 3;
2151 else if (strcmp(ti->data, "off") == 0) export = 2;
2153 fprintf(stderr, "Illegal argument %s\n", ti->data);
2158 if (ti = as->parms[2].items) { /* -noconvert */
2159 if (strcmp(ti->data, "on") == 0) mode = 2;
2160 else if (strcmp(ti->data, "off") == 0) mode = 3;
2162 fprintf(stderr, "Illegal argument %s\n", ti->data);
2166 if (ti = as->parms[3].items) { /* -uidcheck */
2167 if (strcmp(ti->data, "on") == 0) pwsync = 3;
2168 else if (strcmp(ti->data, "off") == 0) pwsync = 2;
2170 fprintf(stderr, "Illegal argument %s\n", ti->data);
2174 if (ti = as->parms[4].items) { /* -submounts */
2175 if (strcmp(ti->data, "on") == 0) smounts = 3;
2176 else if (strcmp(ti->data, "off") == 0) smounts = 2;
2178 fprintf(stderr, "Illegal argument %s\n", ti->data);
2182 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2185 blob.in = (char *) &exportcall;
2186 blob.in_size = sizeof(afs_int32);
2187 blob.out = (char *) &exportcall;
2188 blob.out_size = sizeof(afs_int32);
2189 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2191 if (errno == ENODEV) {
2192 fprintf(stderr, "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
2200 if (exportcall & 1) {
2201 printf("'%s' translator is enabled with the following options:\n",
2202 exported_types[type]);
2203 printf("\tRunning in %s mode\n",
2204 (exportcall & 2 ? "strict unix"
2205 : "convert owner mode bits to world/other"));
2206 printf("\tRunning in %s mode\n",
2207 (exportcall & 4 ? "strict 'passwd sync'"
2208 : "no 'passwd sync'"));
2210 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs"
2211 : "Only mounts to /afs allowed"));
2214 printf("'%s' translator is disabled\n", exported_types[type]);
2220 static GetCellCmd(as)
2221 struct cmd_syndesc *as;
2224 struct ViceIoctl blob;
2225 struct afsconf_cell info;
2226 struct cmd_item *ti;
2233 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2234 for(ti=as->parms[0].items; ti; ti=ti->next) {
2236 blob.out_size = sizeof(args);
2237 blob.out = (caddr_t) &args;
2238 code = GetCellName(ti->data, &info);
2243 blob.in_size = 1+strlen(info.name);
2244 blob.in = info.name;
2245 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2247 if (errno == ENOENT)
2248 fprintf(stderr, "%s: the cell named '%s' does not exist\n", pn, info.name);
2250 Die(errno, info.name);
2254 printf("Cell %s status: ", info.name);
2256 if (args.stat & 1) printf("primary ");
2258 if (args.stat & 2) printf("no setuid allowed");
2259 else printf("setuid allowed");
2260 if (args.stat & 4) printf(", using old VLDB");
2266 static SetCellCmd(as)
2267 struct cmd_syndesc *as;
2270 struct ViceIoctl blob;
2271 struct afsconf_cell info;
2272 struct cmd_item *ti;
2280 /* Check arguments. */
2281 if (as->parms[1].items && as->parms[2].items) {
2282 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2286 /* figure stuff to set */
2290 if (! as->parms[1].items) args.stat |= 2; /* default to -nosuid */
2292 /* set stat for all listed cells */
2293 for(ti=as->parms[0].items; ti; ti=ti->next) {
2295 code = GetCellName(ti->data, &info);
2300 strcpy(args.cname, info.name);
2301 blob.in_size = sizeof(args);
2302 blob.in = (caddr_t) &args;
2304 blob.out = (caddr_t) 0;
2305 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2307 Die(errno, info.name); /* XXX added cell name to Die() call */
2314 static GetCellName(cellName, info)
2316 struct afsconf_cell *info;
2318 struct afsconf_dir *tdir;
2321 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2323 fprintf(stderr, "Could not process files in configuration directory (%s).\n",
2324 AFSDIR_CLIENT_ETC_DIRPATH);
2328 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2330 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2331 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2339 static VLDBInit(noAuthFlag, info)
2341 struct afsconf_cell *info;
2344 struct ktc_principal sname;
2345 struct ktc_token ttoken;
2347 struct rx_securityClass *sc;
2348 struct rx_connection *serverconns[VLDB_MAXSERVERS];
2353 fprintf(stderr, "%s: could not initialize rx.\n", pn);
2357 rx_SetRxDeadTime(50);
2358 if (!noAuthFlag) { /* we don't need tickets for null */
2359 strcpy(sname.cell, info->name);
2360 sname.instance[0] = 0;
2361 strcpy(sname.name, "afs");
2362 code = ktc_GetToken(&sname,&ttoken, sizeof(ttoken), (char *)0);
2364 fprintf(stderr, "%s: Could not get afs tokens, running unauthenticated.\n", pn);
2369 if (ttoken.kvno >= 0 && ttoken.kvno <= 255) scIndex = 2; /* kerberos */
2371 fprintf(stderr, "%s: funny kvno (%d) in ticket, proceeding\n",
2377 else scIndex = 0; /* don't authenticate */
2380 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
2386 sc = (struct rx_securityClass *)
2387 rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
2388 ttoken.kvno, ttoken.ticketLen,
2392 if (info->numServers > VLDB_MAXSERVERS) {
2393 fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
2394 pn, info->numServers, VLDB_MAXSERVERS);
2397 bzero(serverconns, sizeof(serverconns));
2398 for (i = 0;i<info->numServers;i++)
2399 serverconns[i] = rx_NewConnection(info->hostAddr[i].sin_addr.s_addr,
2400 info->hostAddr[i].sin_port, USER_SERVICE_ID,
2403 code = ubik_ClientInit(serverconns, &uclient);
2406 fprintf(stderr, "%s: ubik client init failed.\n", pn);
2412 static struct ViceIoctl gblob;
2413 static int debug = 0;
2415 * here follow some routines in suport of the setserverprefs and
2416 * getserverprefs commands. They are:
2417 * SetPrefCmd "top-level" routine
2418 * addServer adds a server to the list of servers to be poked into the
2419 * kernel. Will poke the list into the kernel if it threatens
2421 * pokeServers pokes the existing list of servers and ranks into the kernel
2422 * GetPrefCmd reads the Cache Manager's current list of server ranks
2426 * returns -1 if error message printed,
2428 * errno value if error and no error message printed
2430 static pokeServers()
2434 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2435 if (code && (errno == EINVAL)) {
2436 struct setspref *ssp;
2437 ssp = (struct setspref *)gblob.in;
2438 if (!(ssp->flags & DBservers)) {
2439 gblob.in = (void *) &(ssp->servers[0]);
2440 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2441 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2442 return code ? errno : 0;
2445 "This cache manager does not support VL server preferences.\n");
2449 return code ? errno : 0;
2453 * returns -1 if error message printed,
2455 * errno value if error and no error message printed
2457 static addServer(name, rank)
2462 struct setspref *ssp;
2464 struct hostent *thostent;
2470 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2472 #define MAXUSHORT ((unsigned short) ~0)
2476 thostent = hostutil_GetHostByName(name);
2478 fprintf(stderr, "%s: couldn't resolve name.\n", name);
2482 ssp = (struct setspref *)(gblob.in);
2484 for (t = 0; thostent->h_addr_list[t]; t++) {
2485 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
2486 code = pokeServers();
2487 if (code) error = code;
2488 ssp->num_servers = 0;
2491 sp = (struct spref *) (gblob.in + gblob.in_size);
2492 bcopy (thostent->h_addr_list[t], &(sp->server.s_addr), sizeof(afs_uint32));
2493 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2494 gblob.in_size += sizeof(struct spref);
2498 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
2499 name,sp->rank,sp->server.s_addr);
2506 static SetPrefCmd(as)
2507 struct cmd_syndesc *as;
2511 struct cmd_item *ti;
2514 struct setspref *ssp;
2515 int error = 0; /* -1 means error message printed,
2516 * >0 means errno value for unprinted message */
2518 ssp = (struct setspref *)space;
2520 ssp->num_servers = 0;
2521 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2524 gblob.out_size = MAXSIZE;
2528 fprintf(stderr, "Permission denied: requires root access.\n");
2532 ti = as->parms[2].items; /* -file */
2534 if (debug) fprintf(stderr, "opening file %s\n",ti->data);
2535 if (!(infd = fopen(ti->data,"r"))) {
2540 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2541 code = addServer(name, (unsigned short) rank);
2542 if (code) error = code;
2547 ti = as->parms[3].items; /* -stdin */
2549 while (scanf("%79s%ld", name, &rank) != EOF) {
2550 code = addServer(name, (unsigned short) rank);
2551 if (code) error = code;
2555 for (ti = as->parms[0].items;ti;ti=ti->next) { /* list of servers, ranks */
2560 code = addServer(ti->data, (unsigned short) atol(ti->next->data));
2561 if (code) error = code;
2563 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
2567 code = pokeServers();
2568 if (code) error = code;
2570 printf("now working on vlservers, code=%d\n",code);
2572 ssp = (struct setspref *)space;
2573 ssp->flags = DBservers;
2574 ssp->num_servers = 0;
2575 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2578 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
2583 code = addServer(ti->data, (unsigned short) atol(ti->next->data));
2584 if (code) error = code;
2586 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
2591 if (as->parms[1].items) {
2593 printf("now poking vlservers\n");
2594 code = pokeServers();
2595 if (code) error = code;
2601 return error ? 1 : 0;
2606 static GetPrefCmd(as)
2607 struct cmd_syndesc *as;
2610 struct cmd_item *ti;
2611 char *name, tbuffer[20];
2612 afs_int32 rank,addr;
2616 struct ViceIoctl blob;
2617 struct sprefrequest *in;
2618 struct sprefinfo *out;
2621 ti = as->parms[0].items; /* -file */
2623 if (debug) fprintf(stderr, "opening file %s\n",ti->data);
2624 if (!(outfd = freopen(ti->data,"w",stdout))) {
2630 ti = as->parms[1].items; /* -numeric */
2632 ti = as->parms[2].items; /* -vlservers */
2633 vlservers |= (ti ? DBservers : 0);
2634 /* ti = as->parms[3].items; -cell */
2636 in = (struct sprefrequest *)space;
2640 blob.in_size=sizeof(struct sprefrequest);
2641 blob.in = (char *)in;
2643 blob.out_size = MAXSIZE;
2645 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct spref);
2646 in->flags = vlservers;
2648 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
2650 perror("getserverprefs pioctl");
2654 out = (struct sprefinfo *) blob.out;
2656 for (i=0;i<out->num_servers;i++) {
2658 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
2661 addr = ntohl(out->servers[i].server.s_addr);
2662 sprintf(tbuffer, "%d.%d.%d.%d",
2663 (addr>>24) & 0xff, (addr>>16) & 0xff,
2664 (addr>>8) & 0xff, addr & 0xff);
2667 printf("%-50s %5u\n",name,out->servers[i].rank);
2670 in->offset = out->next_offset;
2671 } while (out->next_offset > 0);
2676 static StoreBehindCmd(as)
2677 struct cmd_syndesc *as;
2680 struct ViceIoctl blob;
2681 struct cmd_item *ti;
2682 struct sbstruct tsb, tsb2;
2688 tsb.sb_thisfile = -1;
2689 ti=as->parms[0].items; /* -kbytes */
2691 if (!as->parms[1].items) {
2692 fprintf(stderr, "%s: you must specify -files with -kbytes.\n", pn);
2695 tsb.sb_thisfile = strtol(ti->data,&t,10) * 1024;
2696 if ((tsb.sb_thisfile < 0) || (t != ti->data+strlen(ti->data))) {
2697 fprintf(stderr, "%s: %s must be 0 or a positive number.\n",
2703 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
2704 ti=as->parms[2].items; /* -allfiles */
2706 allfiles = strtol(ti->data,&t,10) * 1024;
2707 if ((allfiles < 0) || (t != ti->data+strlen(ti->data))) {
2708 fprintf(stderr, "%s: %s must be 0 or a positive number.\n",
2714 /* -verbose or -file only or no options */
2715 if (as->parms[3].items ||
2716 (as->parms[1].items && !as->parms[0].items) ||
2717 (!as->parms[0].items && !as->parms[1].items && !as->parms[2].items))
2720 blob.in = (char *)&tsb;
2721 blob.out = (char *)&tsb2;
2722 blob.in_size = blob.out_size = sizeof(struct sbstruct);
2723 bzero (&tsb2, sizeof(tsb2));
2725 /* once per -file */
2726 for (ti=as->parms[1].items; ti; ti=ti->next) {
2727 /* Do this solely to see if the file is there */
2728 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
2730 Die(errno, ti->data);
2735 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
2737 Die(errno, ti->data);
2742 if (verbose && (blob.out_size == sizeof(tsb2))) {
2743 if (tsb2.sb_thisfile == -1) {
2744 fprintf(stdout, "Will store %s according to default.\n",
2749 "Will store up to %d kbytes of %s asynchronously.\n",
2750 (tsb2.sb_thisfile/1024), ti->data);
2755 /* If no files - make at least one pioctl call, or
2756 * set the allfiles default if we need to.
2758 if (!as->parms[1].items || (allfiles != -1)) {
2759 tsb.sb_default = allfiles;
2760 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
2762 Die(errno, ((allfiles == -1)?0:"-allfiles"));
2767 /* Having no arguments also reports the default store asynchrony */
2768 if (verbose && (blob.out_size == sizeof(tsb2))) {
2769 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
2770 (tsb2.sb_default/1024));
2777 static afs_int32 SetCryptCmd(as)
2778 struct cmd_syndesc *as;
2780 afs_int32 code = 0, flag;
2781 struct ViceIoctl blob;
2784 tp = as->parms[0].items->data;
2785 if (strcmp(tp, "on") == 0)
2787 else if (strcmp(tp, "off") == 0)
2790 fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
2794 blob.in = (char *) &flag;
2795 blob.in_size = sizeof(flag);
2797 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
2799 Die(errno, (char *) 0);
2804 static afs_int32 GetCryptCmd(as)
2805 struct cmd_syndesc *as;
2807 afs_int32 code = 0, flag;
2808 struct ViceIoctl blob;
2811 blob.in = (char *) 0;
2813 blob.out_size = sizeof(flag);
2816 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
2818 if (code) Die(errno, (char *) 0);
2821 bcopy(tp, &flag, sizeof(afs_int32));
2822 printf("Security level is currently ");
2824 printf("crypt (data security).\n");
2831 #include "AFS_component_version_number.c"
2838 struct cmd_syndesc *ts;
2840 #ifdef AFS_AIX32_ENV
2842 * The following signal action for AIX is necessary so that in case of a
2843 * crash (i.e. core is generated) we can include the user's data section
2844 * in the core dump. Unfortunately, by default, only a partial core is
2845 * generated which, in many cases, isn't too useful.
2847 struct sigaction nsa;
2849 sigemptyset(&nsa.sa_mask);
2850 nsa.sa_handler = SIG_DFL;
2851 nsa.sa_flags = SA_FULLDUMP;
2852 sigaction(SIGSEGV, &nsa, NULL);
2855 /* try to find volume location information */
2856 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0, "get client network interface addresses");
2857 cmd_CreateAlias(ts, "gc");
2859 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0, "set client network interface addresses");
2860 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "client network interfaces");
2861 cmd_CreateAlias(ts, "sc");
2863 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks");
2864 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
2865 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
2866 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
2867 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
2868 cmd_CreateAlias(ts, "sp");
2870 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks");
2871 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
2872 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
2873 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
2874 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
2875 cmd_CreateAlias(ts, "gp");
2877 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
2878 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2879 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
2880 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
2881 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
2882 parm_setacl_id = ts->nParms;
2883 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
2884 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
2885 cmd_CreateAlias(ts, "sa");
2887 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list");
2888 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2889 parm_listacl_id = ts->nParms;
2890 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
2891 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
2892 cmd_CreateAlias(ts, "la");
2894 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list");
2895 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2897 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list");
2898 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
2899 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
2900 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
2901 parm_copyacl_id = ts->nParms;
2902 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
2903 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
2905 cmd_CreateAlias(ts, "ca");
2907 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
2908 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2909 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0, "flush mount symlink from cache");
2910 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2912 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
2913 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2914 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
2916 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
2917 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
2919 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
2920 cmd_CreateAlias(ts, "sv");
2922 ts = cmd_CreateSyntax("messages", MessagesCmd, 0, "control Cache Manager messages");
2923 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
2925 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display volume status");
2926 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2927 cmd_CreateAlias(ts, "lv");
2928 cmd_CreateAlias(ts, "listvol");
2930 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
2931 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2932 cmd_CreateAlias(ts, "lq");
2934 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage");
2935 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2936 cmd_CreateAlias(ts, "df");
2938 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
2939 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2941 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
2942 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2944 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
2945 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
2946 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
2947 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
2948 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
2949 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
2955 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
2959 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
2960 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2962 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers");
2963 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
2964 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
2965 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
2966 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
2968 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings");
2969 cmd_CreateAlias(ts, "checkbackups");
2972 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size");
2973 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
2974 cmd_CreateAlias(ts, "cachesize");
2976 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
2978 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info");
2980 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells");
2981 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
2983 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
2984 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
2985 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
2987 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
2989 cmd_CreateAlias(ts, "sq");
2991 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
2992 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
2993 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
2994 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
2996 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2998 * Turn this on only if you wish to be able to talk to a server which is listening
2999 * on alternative ports. This is not intended for general use and may not be
3000 * supported in the cache manager. It is not a way to run two servers at the
3001 * same host, since the cache manager cannot properly distinguish those two hosts.
3003 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
3004 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
3007 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
3008 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3010 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
3011 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3013 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
3016 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
3019 /* set cache monitor host address */
3020 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, (char *) CMD_HIDDEN);
3021 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
3022 cmd_CreateAlias(ts, "mariner");
3024 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
3025 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3027 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
3028 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3029 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3030 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
3032 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume");
3033 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3035 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value");
3036 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3038 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS");
3039 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3040 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator (on | off)");
3041 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode (on | off)");
3042 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode (on | off)");
3043 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. (on | off)");
3046 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
3047 "store to server after file close");
3048 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
3049 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3050 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
3051 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3052 cmd_CreateAlias(ts, "sb");
3054 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag");
3055 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3057 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "set cache manager encryption flag");
3059 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
3060 "Manage per process RX statistics");
3061 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL,
3063 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL,
3064 "Disable RX stats");
3065 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3068 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0,
3069 "Manage per peer RX statistics");
3070 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL,
3072 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL,
3073 "Disable RX stats");
3074 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3077 code = cmd_Dispatch(argc, argv);
3078 if (rxInitDone) rx_Finalize();
3083 static void Die(errnum, filename)
3090 fprintf(stderr, "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3093 fprintf(stderr, "%s: Invalid argument.\n", pn);
3097 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3099 fprintf(stderr, "%s: no such file returned\n", pn);
3102 fprintf(stderr, "%s: You can not change a backup or readonly volume\n", pn);
3107 fprintf(stderr, "%s: You don't have the required access rights on '%s'\n",
3110 fprintf(stderr, "%s: You do not have the required rights to do this operation\n",
3115 fprintf(stderr, "%s:'%s'", pn, filename);
3117 fprintf(stderr, "%s", pn);
3118 fprintf(stderr, ": %s\n", error_message(errnum));
3123 /* get clients interface addresses */
3125 GetClientAddrsCmd(as)
3126 struct cmd_syndesc *as;
3129 struct cmd_item *ti;
3131 struct ViceIoctl blob;
3132 struct sprefrequest *in;
3133 struct sprefinfo *out;
3135 in = (struct sprefrequest *)space;
3140 blob.in_size=sizeof(struct sprefrequest);
3141 blob.in = (char *)in;
3143 blob.out_size = MAXSIZE;
3145 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct spref);
3146 /* returns addr in network byte order */
3147 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3149 perror("getClientInterfaceAddr pioctl");
3155 out = (struct sprefinfo *) blob.out;
3156 for (i=0; i < out->num_servers; i++) {
3159 addr = ntohl(out->servers[i].server.s_addr);
3160 sprintf(tbuffer, "%d.%d.%d.%d",
3161 (addr>>24) & 0xff, (addr>>16) & 0xff,
3162 (addr>>8) & 0xff, addr & 0xff);
3163 printf ("%-50s\n", tbuffer);
3165 in->offset = out->next_offset;
3167 } while (out->next_offset > 0);
3173 SetClientAddrsCmd(as)
3174 struct cmd_syndesc *as;
3176 afs_int32 code, addr;
3177 struct cmd_item *ti;
3179 struct ViceIoctl blob;
3180 struct setspref *ssp;
3181 int sizeUsed = 0, i, flag;
3182 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3186 ssp = (struct setspref *)space;
3187 ssp->num_servers = 0;
3190 blob.out_size = MAXSIZE;
3193 fprintf(stderr, "Permission denied: requires root access.\n");
3197 /* extract all existing interface addresses */
3198 existNu = rx_getAllAddr(existingAddr,1024);
3202 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3203 for (ti = as->parms[0].items;ti;ti=ti->next) {
3204 if (sizeUsed >= sizeof(space)) {
3205 fprintf(stderr, "No more space\n");
3208 addr = extractAddr(ti->data, 20); /* network order */
3209 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3210 fprintf(stderr, "Error in specifying address: %s..ignoring\n", ti->data);
3214 /* see if it is an address that really exists */
3215 for (flag = 0, i=0; i < existNu; i++)
3216 if (existingAddr[i] == addr) {
3220 if (!flag) { /* this is an nonexistent address */
3221 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3225 /* copy all specified addr into ioctl buffer */
3226 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3227 printf("Adding 0x%08x\n", addr);
3229 sizeUsed += sizeof(struct spref);
3231 if (ssp->num_servers < 1) {
3232 fprintf(stderr, "No addresses specified\n");
3235 blob.in_size = sizeUsed - sizeof(struct spref);
3237 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3248 struct cmd_syndesc *as;
3251 struct ViceIoctl blob;
3252 struct cmd_item *ti;
3253 char orig_name[1024]; /*Original name, may be modified*/
3254 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
3255 char parent_dir[1024]; /*Parent directory of true name*/
3256 char *last_component; /*Last component of true name*/
3257 struct stat statbuff; /*Buffer for status info*/
3258 int link_chars_read; /*Num chars read in readlink()*/
3259 int thru_symlink; /*Did we get to a mount point via a symlink?*/
3262 for(ti=as->parms[0].items; ti; ti=ti->next) {
3265 sprintf(orig_name, "%s%s",
3266 (ti->data[0] == '/') ? "" : "./",
3269 if (lstat(orig_name, &statbuff) < 0) {
3270 /* if lstat fails, we should still try the pioctl, since it
3271 may work (for example, lstat will fail, but pioctl will
3272 work if the volume of offline (returning ENODEV). */
3273 statbuff.st_mode = S_IFDIR; /* lie like pros */
3277 * The lstat succeeded. If the given file is a symlink, substitute
3278 * the file name with the link name.
3280 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
3283 * Read name of resolved file.
3285 link_chars_read = readlink(orig_name, true_name, 1024);
3286 if (link_chars_read <= 0) {
3287 fprintf(stderr, "%s: Can't read target name for '%s' symbolic link!\n",
3294 * Add a trailing null to what was read, bump the length.
3296 true_name[link_chars_read++] = 0;
3299 * If the symlink is an absolute pathname, we're fine. Otherwise, we
3300 * have to create a full pathname using the original name and the
3301 * relative symlink name. Find the rightmost slash in the original
3302 * name (we know there is one) and splice in the symlink value.
3304 if (true_name[0] != '/') {
3305 last_component = (char *) rindex(orig_name, '/');
3306 strcpy(++last_component, true_name);
3307 strcpy(true_name, orig_name);
3311 strcpy(true_name, orig_name);
3314 * Find rightmost slash, if any.
3316 last_component = (char *) rindex(true_name, '/');
3317 if (last_component) {
3319 * Found it. Designate everything before it as the parent directory,
3320 * everything after it as the final component.
3322 strncpy(parent_dir, true_name, last_component - true_name);
3323 parent_dir[last_component - true_name] = 0;
3324 last_component++; /*Skip the slash*/
3328 * No slash appears in the given file name. Set parent_dir to the current
3329 * directory, and the last component as the given name.
3331 strcpy(parent_dir, ".");
3332 last_component = true_name;
3335 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
3336 fprintf(stderr, "%s: you may not use '.' or '..' as the last component\n", pn);
3337 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n", pn);
3342 blob.in = last_component;
3343 blob.in_size = strlen(last_component)+1;
3345 bzero(space, MAXSIZE);
3347 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
3350 if (errno == EINVAL) {
3351 fprintf(stderr, "'%s' is not a mount point.\n",
3355 Die(errno, (ti->data ? ti->data : parent_dir));
3365 struct cmd_syndesc *as;
3368 afs_int32 flags = 0;
3369 struct ViceIoctl blob;
3370 struct cmd_item *ti;
3372 if (as->parms[0].items) { /* -enable*/
3373 flags |= AFSCALL_RXSTATS_ENABLE;
3375 if (as->parms[1].items) { /* -disable*/
3376 flags |= AFSCALL_RXSTATS_DISABLE;
3378 if (as->parms[2].items) { /* -clear*/
3379 flags |= AFSCALL_RXSTATS_CLEAR;
3382 fprintf(stderr, "You must specify at least one argument\n");
3386 blob.in = (char *)&flags;
3387 blob.in_size = sizeof(afs_int32);
3390 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
3401 struct cmd_syndesc *as;
3404 afs_int32 flags = 0;
3405 struct ViceIoctl blob;
3406 struct cmd_item *ti;
3408 if (as->parms[0].items) { /* -enable*/
3409 flags |= AFSCALL_RXSTATS_ENABLE;
3411 if (as->parms[1].items) { /* -disable*/
3412 flags |= AFSCALL_RXSTATS_DISABLE;
3414 if (as->parms[2].items) { /* -clear*/
3415 flags |= AFSCALL_RXSTATS_CLEAR;
3418 fprintf(stderr, "You must specify at least one argument\n");
3422 blob.in = (char *)&flags;
3423 blob.in_size = sizeof(afs_int32);
3426 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);