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 <afsconfig.h>
11 #include <afs/param.h>
15 #include <afs/afs_args.h>
17 #include <sys/ioctl.h>
18 #include <sys/socket.h>
22 #include <netinet/in.h>
26 #include <afs/venus.h>
32 #include "afs/prs_fs.h"
33 #include <afs/afsint.h>
35 #include <afs/cellconfig.h>
38 #include <rx/rx_globals.h>
39 #include <afs/vldbint.h>
40 #include <afs/volser.h>
41 #include <afs/vlserver.h>
44 #include <afs/afsutil.h>
47 #include <afs/ptclient.h>
52 #define MAXCELLHOSTS 8
55 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
56 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
58 static char space[MAXSIZE];
59 static char tspace[1024];
60 static struct ubik_client *uclient;
62 static int GetClientAddrsCmd(), SetClientAddrsCmd(), FlushMountCmd();
63 static int RxStatProcCmd(), RxStatPeerCmd();
65 extern char *hostutil_GetNameByINet();
66 extern struct hostent *hostutil_GetHostByName();
67 extern afs_int32 VL_GetEntryByNameO();
70 extern struct cmd_syndesc *cmd_CreateSyntax();
71 static char pn[] = "fs";
72 static int rxInitDone = 0;
74 static void ZapList();
75 static int PruneList();
83 * Character to use between name and rights in printed representation for
86 #define DFS_SEPARATOR ' '
88 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
91 int dfs; /* Originally true if a dfs acl; now also the type
92 of the acl (1, 2, or 3, corresponding to object,
93 initial dir, or initial object). */
94 sec_rgy_name_t cell; /* DFS cell name */
97 struct AclEntry *pluslist;
98 struct AclEntry *minuslist;
102 struct AclEntry *next;
107 static void ZapAcl(acl)
111 ZapList(acl->pluslist);
112 ZapList(acl->minuslist);
124 if (t >= 'A' && t <= 'Z') t += 0x20;
125 if (u >= 'A' && u <= 'Z') u += 0x20;
126 if (t != u) return 1;
127 if (t == 0) return 0;
132 * Mods for the AFS/DFS protocol translator.
134 * DFS rights. It's ugly to put these definitions here, but they
135 * *cannot* change, because they're part of the wire protocol.
136 * In any event, the protocol translator will guarantee these
137 * assignments for AFS cache managers.
139 #define DFS_READ 0x01
140 #define DFS_WRITE 0x02
141 #define DFS_EXECUTE 0x04
142 #define DFS_CONTROL 0x08
143 #define DFS_INSERT 0x10
144 #define DFS_DELETE 0x20
146 /* the application definable ones (backwards from AFS) */
147 #define DFS_USR0 0x80000000 /* "A" bit */
148 #define DFS_USR1 0x40000000 /* "B" bit */
149 #define DFS_USR2 0x20000000 /* "C" bit */
150 #define DFS_USR3 0x10000000 /* "D" bit */
151 #define DFS_USR4 0x08000000 /* "E" bit */
152 #define DFS_USR5 0x04000000 /* "F" bit */
153 #define DFS_USR6 0x02000000 /* "G" bit */
154 #define DFS_USR7 0x01000000 /* "H" bit */
155 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
156 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
159 * Offset of -id switch in command structure for various commands.
160 * The -if switch is the next switch always.
162 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
165 * Determine whether either the -id or -if switches are present, and
166 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
168 static int getidf(as, id)
169 struct cmd_syndesc *as;
170 int id; /* Offset of -id switch; -if is next switch */
174 if (as->parms[id].items) {
177 if (as->parms[id + 1].items) {
183 "%s: you may specify either -id or -if, but not both switches\n",
190 static int PRights(arights, dfs)
195 if (arights & PRSFS_READ) printf("r");
196 if (arights & PRSFS_LOOKUP) printf("l");
197 if (arights & PRSFS_INSERT) printf("i");
198 if (arights & PRSFS_DELETE) printf("d");
199 if (arights & PRSFS_WRITE) printf("w");
200 if (arights & PRSFS_LOCK) printf("k");
201 if (arights & PRSFS_ADMINISTER) printf("a");
202 if (arights & PRSFS_USR0) printf("A");
203 if (arights & PRSFS_USR1) printf("B");
204 if (arights & PRSFS_USR2) printf("C");
205 if (arights & PRSFS_USR3) printf("D");
206 if (arights & PRSFS_USR4) printf("E");
207 if (arights & PRSFS_USR5) printf("F");
208 if (arights & PRSFS_USR6) printf("G");
209 if (arights & PRSFS_USR7) printf("H");
211 if (arights & DFS_READ) printf("r"); else printf("-");
212 if (arights & DFS_WRITE) printf("w"); else printf("-");
213 if (arights & DFS_EXECUTE) printf("x"); else printf("-");
214 if (arights & DFS_CONTROL) printf("c"); else printf("-");
215 if (arights & DFS_INSERT) printf("i"); else printf("-");
216 if (arights & DFS_DELETE) printf("d"); else printf("-");
217 if (arights & (DFS_USRALL)) printf("+");
218 if (arights & DFS_USR0) printf("A");
219 if (arights & DFS_USR1) printf("B");
220 if (arights & DFS_USR2) printf("C");
221 if (arights & DFS_USR3) printf("D");
222 if (arights & DFS_USR4) printf("E");
223 if (arights & DFS_USR5) printf("F");
224 if (arights & DFS_USR6) printf("G");
225 if (arights & DFS_USR7) printf("H");
229 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
230 static int InAFS(apath)
233 struct ViceIoctl blob;
237 blob.out_size = MAXSIZE;
240 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
242 if ((errno == EINVAL) || (errno == ENOENT)) return 0;
247 /* return a static pointer to a buffer */
248 static char *Parent(apath)
252 strcpy(tspace, apath);
253 tp = rindex(tspace, '/');
257 else strcpy(tspace, ".");
261 enum rtype {add, destroy, deny};
263 static afs_int32 Convert(arights, dfs, rtypep)
272 *rtypep = add; /* add rights, by default */
275 if (!strcmp(arights, "null")) {
279 if (!strcmp(arights,"read")) return DFS_READ | DFS_EXECUTE;
280 if (!strcmp(arights, "write")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE;
281 if (!strcmp(arights, "all")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE | DFS_CONTROL;
283 if (!strcmp(arights,"read")) return PRSFS_READ | PRSFS_LOOKUP;
284 if (!strcmp(arights, "write")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK;
285 if (!strcmp(arights, "mail")) return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
286 if (!strcmp(arights, "all")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
288 if (!strcmp(arights, "none")) {
289 *rtypep = destroy; /* Remove entire entry */
292 len = strlen(arights);
297 if (tc == '-') continue;
298 else if (tc == 'r') mode |= DFS_READ;
299 else if (tc == 'w') mode |= DFS_WRITE;
300 else if (tc == 'x') mode |= DFS_EXECUTE;
301 else if (tc == 'c') mode |= DFS_CONTROL;
302 else if (tc == 'i') mode |= DFS_INSERT;
303 else if (tc == 'd') mode |= DFS_DELETE;
304 else if (tc == 'A') mode |= DFS_USR0;
305 else if (tc == 'B') mode |= DFS_USR1;
306 else if (tc == 'C') mode |= DFS_USR2;
307 else if (tc == 'D') mode |= DFS_USR3;
308 else if (tc == 'E') mode |= DFS_USR4;
309 else if (tc == 'F') mode |= DFS_USR5;
310 else if (tc == 'G') mode |= DFS_USR6;
311 else if (tc == 'H') mode |= DFS_USR7;
313 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n", pn, tc);
317 if (tc == 'r') mode |= PRSFS_READ;
318 else if (tc == 'l') mode |= PRSFS_LOOKUP;
319 else if (tc == 'i') mode |= PRSFS_INSERT;
320 else if (tc == 'd') mode |= PRSFS_DELETE;
321 else if (tc == 'w') mode |= PRSFS_WRITE;
322 else if (tc == 'k') mode |= PRSFS_LOCK;
323 else if (tc == 'a') mode |= PRSFS_ADMINISTER;
324 else if (tc == 'A') mode |= PRSFS_USR0;
325 else if (tc == 'B') mode |= PRSFS_USR1;
326 else if (tc == 'C') mode |= PRSFS_USR2;
327 else if (tc == 'D') mode |= PRSFS_USR3;
328 else if (tc == 'E') mode |= PRSFS_USR4;
329 else if (tc == 'F') mode |= PRSFS_USR5;
330 else if (tc == 'G') mode |= PRSFS_USR6;
331 else if (tc == 'H') mode |= PRSFS_USR7;
333 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn, tc);
341 static struct AclEntry *FindList(alist, aname)
342 struct AclEntry *alist;
346 if (!foldcmp(alist->name, aname)) return alist;
352 /* if no parm specified in a particular slot, set parm to be "." instead */
353 static void SetDotDefault(aitemp)
354 struct cmd_item **aitemp;
357 if (*aitemp) return; /* already has value */
358 /* otherwise, allocate an item representing "." */
359 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
361 ti->next = (struct cmd_item *) 0;
362 ti->data = (char *) malloc(2);
364 strcpy(ti->data, ".");
368 static void ChangeList(al, plus, aname, arights)
374 struct AclEntry *tlist;
375 tlist = (plus ? al->pluslist : al->minuslist);
376 tlist = FindList (tlist, aname);
378 /* Found the item already in the list. */
379 tlist->rights = arights;
381 al->nplus -= PruneList(&al->pluslist, al->dfs);
383 al->nminus -= PruneList(&al->minuslist, al->dfs);
386 /* Otherwise we make a new item and plug in the new data. */
387 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
389 strcpy(tlist->name, aname);
390 tlist->rights = arights;
392 tlist->next = al->pluslist;
393 al->pluslist = tlist;
395 if (arights == 0 || arights == -1)
396 al->nplus -= PruneList(&al->pluslist, al->dfs);
399 tlist->next = al->minuslist;
400 al->minuslist = tlist;
402 if (arights == 0) al->nminus -= PruneList(&al->minuslist, al->dfs);
406 static void ZapList(alist)
407 struct AclEntry *alist;
409 struct AclEntry *tp, *np;
410 for (tp = alist; tp; tp = np) {
416 static int PruneList(ae, dfs)
417 struct AclEntry **ae;
420 struct AclEntry **lp;
421 struct AclEntry *te, *ne;
425 for(te = *ae;te;te=ne) {
426 if ((!dfs && te->rights == 0) || te->rights == -1) {
440 static char *SkipLine(astr)
443 while (*astr !='\n') astr++;
449 * Create an empty acl, taking into account whether the acl pointed
450 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
451 * can recover from problems caused by bogus ACL's (in that case, always
452 * assume that the acl is AFS: for DFS, the user can always resort to
453 * acl_edit, but for AFS there may be no other way out).
455 static struct Acl *EmptyAcl(astr)
461 tp = (struct Acl *)malloc(sizeof (struct Acl));
463 tp->nplus = tp->nminus = 0;
464 tp->pluslist = tp->minuslist = 0;
466 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
470 static struct Acl *ParseAcl(astr)
473 int nplus, nminus, i, trights;
475 struct AclEntry *first, *last, *tl;
478 ta = (struct Acl *) malloc (sizeof (struct Acl));
481 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
482 astr = SkipLine(astr);
483 sscanf(astr, "%d", &ta->nminus);
484 astr = SkipLine(astr);
491 for(i=0;i<nplus;i++) {
492 sscanf(astr, "%100s %d", tname, &trights);
493 astr = SkipLine(astr);
494 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
496 if (!first) first = tl;
497 strcpy(tl->name, tname);
498 tl->rights = trights;
500 if (last) last->next = tl;
503 ta->pluslist = first;
507 for(i=0;i<nminus;i++) {
508 sscanf(astr, "%100s %d", tname, &trights);
509 astr = SkipLine(astr);
510 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
512 if (!first) first = tl;
513 strcpy(tl->name, tname);
514 tl->rights = trights;
516 if (last) last->next = tl;
519 ta->minuslist = first;
524 static PrintStatus(status, name, offmsg)
525 VolumeStatus *status;
529 printf("Volume status for vid = %u named %s\n",status->Vid, name);
531 printf("Current offline message is %s\n",offmsg);
532 printf("Current disk quota is ");
533 if (status->MaxQuota != 0) printf("%d\n", status->MaxQuota);
534 else printf("unlimited\n");
535 printf("Current blocks used are %d\n",status->BlocksInUse);
536 printf("The partition has %d blocks available out of %d\n\n",status->PartBlocksAvail, status->PartMaxBlocks);
539 static QuickPrintStatus(status, name)
540 VolumeStatus *status;
543 double QuotaUsed =0.0;
544 double PartUsed =0.0;
546 printf("%-25.25s",name);
548 if (status->MaxQuota != 0) {
549 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
550 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
552 printf(" no limit%10d", status->BlocksInUse);
554 if (QuotaUsed > 90.0) {
555 printf("%5.0f%%<<", QuotaUsed);
558 else printf("%5.0f%% ", QuotaUsed);
559 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
560 if (PartUsed > 97.0) {
561 printf("%9.0f%%<<", PartUsed);
564 else printf("%9.0f%% ", PartUsed);
566 printf(" <<WARNING\n");
571 static QuickPrintSpace(status, name)
572 VolumeStatus *status;
575 double PartUsed =0.0;
577 printf("%-25.25s",name);
579 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
581 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
582 if (PartUsed > 90.0){
583 printf(" %4.0f%%<<", PartUsed);
586 else printf(" %4.0f%% ", PartUsed);
588 printf(" <<WARNING\n");
593 static char *AclToString(acl)
596 static char mydata[MAXSIZE];
597 char tstring[MAXSIZE];
601 if (acl->dfs) sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
602 else dfsstring[0] = '\0';
603 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
604 for(tp = acl->pluslist;tp;tp=tp->next) {
605 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
606 strcat(mydata, tstring);
608 for(tp = acl->minuslist;tp;tp=tp->next) {
609 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
610 strcat(mydata, tstring);
616 struct cmd_syndesc *as;
619 struct ViceIoctl blob;
621 struct cmd_item *ti, *ui;
625 int idf = getidf(as, parm_setacl_id);
628 if (as->parms[2].items) clear=1;
630 plusp = !(as->parms[3].items);
631 for(ti=as->parms[0].items; ti;ti=ti->next) {
632 blob.out_size = MAXSIZE;
634 blob.in = blob.out = space;
635 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
637 Die(errno, ti->data);
643 ta = ParseAcl(space);
644 if (!plusp && ta->dfs) {
646 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
648 "(you may specify \"null\" to revoke all rights, however)\n");
654 if (clear) ta = EmptyAcl(space);
655 else ta = ParseAcl(space);
656 CleanAcl(ta, ti->data);
657 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
660 fprintf(stderr, "%s: Missing second half of user/access pair.\n", pn);
664 rights = Convert(ui->next->data, ta->dfs, &rtype);
665 if (rtype == destroy && !ta->dfs) {
666 struct AclEntry *tlist;
668 tlist = (plusp ? ta->pluslist : ta->minuslist);
669 if (!FindList(tlist, ui->data))
672 if (rtype == deny && !ta->dfs) plusp = 0;
673 if (rtype == destroy && ta->dfs) rights = -1;
674 ChangeList(ta, plusp, ui->data, rights);
676 blob.in = AclToString(ta);
678 blob.in_size = 1+strlen(blob.in);
679 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
681 if (errno == EINVAL) {
683 static char *fsenv = 0;
685 fsenv = (char *)getenv("FS_EXPERT");
687 fprintf(stderr, "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n", pn);
690 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
691 "\nPossible reasons for this include:\n\n",
692 " -You may have specified an inappropriate combination of rights.\n",
693 " For example, some DFS-supported filesystems may not allow you to\n",
694 " drop the \"c\" right from \"user_obj\".\n\n",
695 " -A mask_obj may be required (it is likely required by the underlying\n",
696 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
697 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
698 " does not automatically create or update the mask_obj. Try setting\n",
699 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
700 " users or groups. You can do this with a single command, such as\n",
701 " \"fs sa mask_obj all user:somename read\"\n\n",
702 " -A specified user or group may not exist.\n\n",
703 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
704 " This is probably not allowed by the underlying file system.\n\n",
705 " -If you add a user or group to a DFS ACL, remember that it must be\n",
706 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
707 " may be local requirements on the format of the user or group name.\n",
708 " Check with your cell administrator.\n\n",
709 " -Or numerous other possibilities. It would be great if we could be more\n",
710 " precise about the actual problem, but for various reasons, this is\n",
711 " impractical via this interface. If you can't figure it out, you\n",
712 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
713 " whatever is provided). You may get better results. Good luck!\n\n",
714 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
717 fprintf(stderr, "%s: Invalid argument, possible reasons include:\n", pn);
718 fprintf(stderr, "\t-File not in AFS\n");
719 fprintf(stderr, "\t-Too many users on access control list\n");
720 fprintf(stderr, "\t-Tried to add non-existent user to access control list\n");
724 Die(errno, ti->data);
734 static CopyACLCmd(as)
735 struct cmd_syndesc *as;
738 struct ViceIoctl blob;
739 struct Acl *fa, *ta = 0;
741 struct cmd_item *ti, *ui;
745 int idf = getidf(as, parm_copyacl_id);
748 if (as->parms[2].items) clear=1;
750 blob.out_size = MAXSIZE;
752 blob.in = blob.out = space;
753 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
755 Die(errno, as->parms[0].items->data);
758 fa = ParseAcl(space);
759 CleanAcl(fa, as->parms[0].items->data);
760 for (ti=as->parms[1].items; ti;ti=ti->next) {
761 blob.out_size = MAXSIZE;
763 blob.in = blob.out = space;
764 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
766 Die(errno, ti->data);
772 if (clear) ta = EmptyAcl(space);
773 else ta = ParseAcl(space);
774 CleanAcl(ta, ti->data);
775 if (ta->dfs != fa->dfs) {
776 fprintf(stderr, "%s: incompatible file system types: acl not copied to %s; aborted\n", pn, ti->data);
781 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
782 fprintf(stderr, "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", pn, ti->data);
786 strcpy(ta->cell, fa->cell);
788 for (tp = fa->pluslist;tp;tp=tp->next)
789 ChangeList(ta, 1, tp->name, tp->rights);
790 for (tp = fa->minuslist;tp;tp=tp->next)
791 ChangeList(ta, 0, tp->name, tp->rights);
792 blob.in = AclToString(ta);
794 blob.in_size = 1+strlen(blob.in);
795 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
797 if (errno == EINVAL) {
798 fprintf(stderr, "%s: Invalid argument, possible reasons include:\n", pn);
799 fprintf(stderr, "\t-File not in AFS\n");
802 Die(errno, ti->data);
812 /* pioctl() call to get the cellname of a pathname */
813 static afs_int32 GetCell(fname, cellname)
814 char *fname, *cellname;
817 struct ViceIoctl blob;
820 blob.out_size = MAXCELLCHARS;
823 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
824 return code ? errno : 0;
827 /* Check if a username is valid: If it contains only digits (or a
828 * negative sign), then it might be bad. We then query the ptserver
831 static BadName(aname, fname)
834 afs_int32 tc, code, id;
836 char cell[MAXCELLCHARS];
838 for (nm=aname; tc=*nm; nm++) {
839 /* all must be '-' or digit to be bad */
840 if (tc != '-' && (tc < '0' || tc > '9')) return 0;
843 /* Go to the PRDB and see if this all number username is valid */
844 code = GetCell(fname, cell);
847 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
848 code = pr_SNameToId(aname, &id);
851 /* 1=>Not-valid; 0=>Valid */
852 return ((!code && (id==ANONYMOUSID)) ? 1 : 0);
856 /* clean up an access control list of its bad entries; return 1 if we made
857 any changes to the list, and 0 otherwise */
858 static CleanAcl(aa, fname)
860 char *fname; /* The file name */
862 struct AclEntry *te, **le, *ne;
865 /* Don't correct DFS ACL's for now */
869 /* prune out bad entries */
870 changes = 0; /* count deleted entries */
872 for(te = aa->pluslist; te; te=ne) {
874 if (BadName(te->name,fname)) {
886 for(te = aa->minuslist; te; te=ne) {
888 if (BadName(te->name,fname)) {
903 /* clean up an acl to not have bogus entries */
904 static CleanACLCmd(as)
905 struct cmd_syndesc *as;
909 struct ViceIoctl blob;
915 SetDotDefault(&as->parms[0].items);
916 for(ti=as->parms[0].items; ti; ti=ti->next) {
917 blob.out_size = MAXSIZE;
920 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
922 Die(errno, ti->data);
928 ta = ParseAcl(space);
931 "%s: cleanacl is not supported for DFS access lists.\n",
937 changes = CleanAcl(ta, ti->data);
940 /* now set the acl */
941 blob.in=AclToString(ta);
942 blob.in_size = strlen(blob.in)+1;
944 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
946 if (errno == EINVAL) {
947 fprintf(stderr, "%s: Invalid argument, possible reasons include\n", pn);
948 fprintf(stderr, "%s: File not in vice or\n", pn);
949 fprintf(stderr, "%s: Too many users on access control list or\n", pn);
952 Die(errno, ti->data);
958 /* now list the updated acl */
959 printf("Access list for %s is now\n", ti->data);
961 if (!ta->dfs) printf("Normal rights:\n");
962 for(te = ta->pluslist;te;te=te->next) {
963 printf(" %s ", te->name);
964 PRights(te->rights, ta->dfs);
968 if (ta->nminus > 0) {
969 printf("Negative rights:\n");
970 for(te = ta->minuslist;te;te=te->next) {
971 printf(" %s ", te->name);
972 PRights(te->rights, ta->dfs);
976 if (ti->next) printf("\n");
979 printf("Access list for %s is fine.\n", ti->data);
985 static ListACLCmd(as)
986 struct cmd_syndesc *as;
990 struct ViceIoctl blob;
993 int idf = getidf(as, parm_listacl_id);
996 SetDotDefault(&as->parms[0].items);
997 for(ti=as->parms[0].items; ti; ti=ti->next) {
998 blob.out_size = MAXSIZE;
1000 blob.in = blob.out = space;
1001 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1003 Die(errno, ti->data);
1007 ta = ParseAcl(space);
1010 printf("Access list for %s is\n", ti->data);
1013 printf("DFS access list for %s is\n", ti->data);
1016 printf("DFS initial directory access list of %s is\n", ti->data);
1019 printf("DFS initial file access list of %s is\n", ti->data);
1023 printf(" Default cell = %s\n", ta->cell);
1025 if (ta->nplus > 0) {
1026 if (!ta->dfs) printf("Normal rights:\n");
1027 for(te = ta->pluslist;te;te=te->next) {
1028 printf(" %s ", te->name);
1029 PRights(te->rights, ta->dfs);
1033 if (ta->nminus > 0) {
1034 printf("Negative rights:\n");
1035 for(te = ta->minuslist;te;te=te->next) {
1036 printf(" %s ", te->name);
1037 PRights(te->rights, ta->dfs);
1041 if (ti->next) printf("\n");
1047 static FlushVolumeCmd(as)
1048 struct cmd_syndesc *as;
1051 struct ViceIoctl blob;
1052 struct cmd_item *ti;
1055 SetDotDefault(&as->parms[0].items);
1056 for(ti=as->parms[0].items; ti; ti=ti->next) {
1057 blob.in_size = blob.out_size = 0;
1058 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1060 fprintf(stderr, "Error flushing volume ");
1070 struct cmd_syndesc *as;
1073 struct ViceIoctl blob;
1074 struct cmd_item *ti;
1077 for(ti=as->parms[0].items; ti; ti=ti->next) {
1078 blob.in_size = blob.out_size = 0;
1079 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1081 if (errno == EMFILE) {
1082 fprintf(stderr, "%s: Can't flush active file %s\n", pn, ti->data);
1085 fprintf(stderr, "%s: Error flushing file ", pn);
1095 /* all this command does is repackage its args and call SetVolCmd */
1096 static SetQuotaCmd(as)
1097 struct cmd_syndesc *as;
1099 struct cmd_syndesc ts;
1101 /* copy useful stuff from our command slot; we may later have to reorder */
1102 bcopy(as, &ts, sizeof(ts)); /* copy whole thing */
1103 return SetVolCmd(&ts);
1106 static SetVolCmd(as)
1107 struct cmd_syndesc *as;
1110 struct ViceIoctl blob;
1111 struct cmd_item *ti;
1112 struct VolumeStatus *status;
1113 char *offmsg, *input;
1116 SetDotDefault(&as->parms[0].items);
1117 for(ti=as->parms[0].items; ti; ti=ti->next) {
1119 blob.out_size = MAXSIZE;
1120 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1123 status = (VolumeStatus *)space;
1124 status->MinQuota = status->MaxQuota = -1;
1125 offmsg = (char *) 0;
1126 if (as->parms[1].items) {
1127 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1129 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1134 if (as->parms[2].items) offmsg = as->parms[2].items->data;
1135 input = (char *)status + sizeof(*status);
1136 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1138 if (strlen(offmsg) >= VMSGSIZE) {
1139 fprintf(stderr, "%s: message must be shorter than %d characters\n",
1144 strcpy(input,offmsg);
1145 blob.in_size += strlen(offmsg);
1146 input += strlen(offmsg) + 1;
1148 else *(input++) = '\0';
1149 *(input++) = '\0'; /* Pad for old style volume "motd" */
1150 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1152 Die(errno, ti->data);
1159 static ExamineCmd(as)
1160 struct cmd_syndesc *as;
1163 struct ViceIoctl blob;
1164 struct cmd_item *ti;
1165 struct VolumeStatus *status;
1166 char *name, *offmsg;
1169 SetDotDefault(&as->parms[0].items);
1170 for(ti=as->parms[0].items; ti; ti=ti->next) {
1172 blob.out_size = MAXSIZE;
1175 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1177 Die(errno, ti->data);
1181 status = (VolumeStatus *)space;
1182 name = (char *)status + sizeof(*status);
1183 offmsg = name + strlen(name) + 1;
1184 PrintStatus(status, name, offmsg);
1189 static ListQuotaCmd(as)
1190 struct cmd_syndesc *as;
1193 struct ViceIoctl blob;
1194 struct cmd_item *ti;
1195 struct VolumeStatus *status;
1199 printf("%-25s%-10s%-10s%-7s%-11s\n",
1200 "Volume Name"," Quota", " Used", " %Used", " Partition");
1201 SetDotDefault(&as->parms[0].items);
1202 for(ti=as->parms[0].items; ti; ti=ti->next) {
1204 blob.out_size = MAXSIZE;
1207 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1209 Die(errno, ti->data);
1213 status = (VolumeStatus *)space;
1214 name = (char *)status + sizeof(*status);
1215 QuickPrintStatus(status, name);
1220 static WhereIsCmd(as)
1221 struct cmd_syndesc *as;
1224 struct ViceIoctl blob;
1225 struct cmd_item *ti;
1231 SetDotDefault(&as->parms[0].items);
1232 for(ti=as->parms[0].items; ti; ti=ti->next) {
1234 blob.out_size = MAXSIZE;
1237 bzero(space, sizeof(space));
1238 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1240 Die(errno, ti->data);
1244 hosts = (afs_int32 *) space;
1245 printf("File %s is on host%s ", ti->data, (hosts[0] && !hosts[1]) ? "": "s");
1246 for(j=0; j<MAXHOSTS; j++) {
1247 if (hosts[j] == 0) break;
1248 tp = hostutil_GetNameByINet(hosts[j]);
1257 static DiskFreeCmd(as)
1258 struct cmd_syndesc *as;
1261 struct ViceIoctl blob;
1262 struct cmd_item *ti;
1264 struct VolumeStatus *status;
1267 printf("%-25s%-10s%-10s%-10s%-6s\n",
1268 "Volume Name"," kbytes", " used", " avail", " %used");
1269 SetDotDefault(&as->parms[0].items);
1270 for(ti=as->parms[0].items; ti; ti=ti->next) {
1272 blob.out_size = MAXSIZE;
1275 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1277 Die(errno, ti->data);
1281 status = (VolumeStatus *)space;
1282 name = (char *)status + sizeof(*status);
1283 QuickPrintSpace(status, name);
1289 struct cmd_syndesc *as;
1292 struct ViceIoctl blob;
1293 struct cmd_item *ti;
1295 struct VolumeStatus *status;
1298 SetDotDefault(&as->parms[0].items);
1299 for(ti=as->parms[0].items; ti; ti=ti->next) {
1301 blob.out_size = MAXSIZE;
1304 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1306 Die(errno, ti->data);
1310 status = (VolumeStatus *)space;
1311 if (status->MaxQuota) quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1312 else quotaPct = 0.0;
1313 printf("%2.0f%% of quota used.\n", quotaPct);
1318 static ListMountCmd(as)
1319 struct cmd_syndesc *as;
1322 struct ViceIoctl blob;
1323 struct cmd_item *ti;
1324 char orig_name[1024]; /*Original name, may be modified*/
1325 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1326 char parent_dir[1024]; /*Parent directory of true name*/
1327 char *last_component; /*Last component of true name*/
1328 struct stat statbuff; /*Buffer for status info*/
1329 int link_chars_read; /*Num chars read in readlink()*/
1330 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1333 for(ti=as->parms[0].items; ti; ti=ti->next) {
1336 sprintf(orig_name, "%s%s",
1337 (ti->data[0] == '/') ? "" : "./",
1340 if (lstat(orig_name, &statbuff) < 0) {
1341 /* if lstat fails, we should still try the pioctl, since it
1342 may work (for example, lstat will fail, but pioctl will
1343 work if the volume of offline (returning ENODEV). */
1344 statbuff.st_mode = S_IFDIR; /* lie like pros */
1348 * The lstat succeeded. If the given file is a symlink, substitute
1349 * the file name with the link name.
1351 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1354 * Read name of resolved file.
1356 link_chars_read = readlink(orig_name, true_name, 1024);
1357 if (link_chars_read <= 0) {
1358 fprintf(stderr, "%s: Can't read target name for '%s' symbolic link!\n",
1365 * Add a trailing null to what was read, bump the length.
1367 true_name[link_chars_read++] = 0;
1370 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1371 * have to create a full pathname using the original name and the
1372 * relative symlink name. Find the rightmost slash in the original
1373 * name (we know there is one) and splice in the symlink value.
1375 if (true_name[0] != '/') {
1376 last_component = (char *) rindex(orig_name, '/');
1377 strcpy(++last_component, true_name);
1378 strcpy(true_name, orig_name);
1382 strcpy(true_name, orig_name);
1385 * Find rightmost slash, if any.
1387 last_component = (char *) rindex(true_name, '/');
1388 if (last_component) {
1390 * Found it. Designate everything before it as the parent directory,
1391 * everything after it as the final component.
1393 strncpy(parent_dir, true_name, last_component - true_name);
1394 parent_dir[last_component - true_name] = 0;
1395 last_component++; /*Skip the slash*/
1399 * No slash appears in the given file name. Set parent_dir to the current
1400 * directory, and the last component as the given name.
1402 strcpy(parent_dir, ".");
1403 last_component = true_name;
1406 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1407 fprintf(stderr, "%s: you may not use '.' or '..' as the last component\n", pn);
1408 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n", pn);
1413 blob.in = last_component;
1414 blob.in_size = strlen(last_component)+1;
1415 blob.out_size = MAXSIZE;
1417 bzero(space, MAXSIZE);
1419 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1422 printf("'%s' is a %smount point for volume '%s'\n",
1424 (thru_symlink ? "symbolic link, leading to a " : ""),
1428 if (errno == EINVAL) {
1429 fprintf(stderr, "'%s' is not a mount point.\n",
1433 Die(errno, (ti->data ? ti->data : parent_dir));
1441 static MakeMountCmd(as)
1442 struct cmd_syndesc *as;
1445 char *cellName, *volName, *tmpName;
1446 struct afsconf_cell info;
1447 struct vldbentry vldbEntry;
1448 struct ViceIoctl blob;
1454 if (as->parms[5].items && !as->parms[2].items) {
1455 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1460 if (as->parms[2].items) /* cell name specified */
1461 cellName = as->parms[2].items->data;
1463 cellName = (char *) 0;
1464 volName = as->parms[1].items->data;
1466 if (strlen(volName) >= 64) {
1467 fprintf(stderr, "%s: volume name too long (length must be < 64 characters)\n", pn);
1471 /* Check for a cellname in the volume specification, and complain
1472 * if it doesn't match what was specified with -cell */
1473 if (tmpName = index(volName, ':')) {
1476 if (strcasecmp(cellName,volName)) {
1477 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1482 volName = ++tmpName;
1485 if (!InAFS(Parent(as->parms[0].items->data))) {
1486 fprintf(stderr, "%s: mount points must be created within the AFS file system\n", pn);
1492 blob.out_size = MAXSIZE;
1494 code = pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME, &blob, 1);
1497 code = GetCellName(cellName?cellName:space, &info);
1501 if (!(as->parms[4].items)) {
1502 /* not fast, check which cell the mountpoint is being created in */
1503 /* not fast, check name with VLDB */
1504 code = VLDBInit(1, &info);
1506 /* make the check. Don't complain if there are problems with init */
1507 code = ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, &vldbEntry);
1508 if (code == VL_NOENT) {
1509 fprintf(stderr, "%s: warning, volume %s does not exist in cell %s.\n",
1510 pn, volName, cellName ? cellName : space);
1515 if (as->parms[3].items) /* if -rw specified */
1520 /* cellular mount point, prepend cell prefix */
1521 strcat(space, info.name);
1524 strcat(space, volName); /* append volume name */
1525 strcat(space, "."); /* stupid convention; these end with a period */
1526 code = symlink(space, as->parms[0].items->data);
1528 Die(errno, as->parms[0].items->data);
1535 * Delete AFS mount points. Variables are used as follows:
1536 * tbuffer: Set to point to the null-terminated directory name of the mount point
1537 * (or ``.'' if none is provided)
1538 * tp: Set to point to the actual name of the mount point to nuke.
1540 static RemoveMountCmd(as)
1541 struct cmd_syndesc *as;
1544 struct ViceIoctl blob;
1545 struct cmd_item *ti;
1547 char lsbuffer[1024];
1551 for(ti=as->parms[0].items; ti; ti=ti->next) {
1553 tp = (char *) rindex(ti->data, '/');
1555 strncpy(tbuffer, ti->data, code=tp-ti->data); /* the dir name */
1557 tp++; /* skip the slash */
1560 strcpy(tbuffer, ".");
1564 blob.in_size = strlen(tp)+1;
1565 blob.out = lsbuffer;
1566 blob.out_size = sizeof(lsbuffer);
1567 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1569 if (errno == EINVAL) {
1570 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn, ti->data);
1573 Die(errno, ti->data);
1576 continue; /* don't bother trying */
1580 blob.in_size = strlen(tp)+1;
1581 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1583 Die(errno, ti->data);
1593 static CheckServersCmd(as)
1594 struct cmd_syndesc *as;
1597 struct ViceIoctl blob;
1603 struct afsconf_cell info;
1604 struct chservinfo checkserv;
1606 bzero(&checkserv,sizeof(struct chservinfo));
1607 blob.in_size=sizeof(struct chservinfo);
1608 blob.in=(caddr_t)&checkserv;
1610 blob.out_size = MAXSIZE;
1612 bzero(space, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1614 /* prepare flags for checkservers command */
1615 temp = 2; /* default to checking local cell only */
1616 if (as->parms[2].items) temp |= 1; /* set fast flag */
1617 if (as->parms[1].items) temp &= ~2; /* turn off local cell check */
1619 checkserv.magic = 0x12345678; /* XXX */
1620 checkserv.tflags=temp;
1622 /* now copy in optional cell name, if specified */
1623 if (as->parms[0].items) {
1624 code = GetCellName(as->parms[0].items->data, &info);
1628 strcpy(checkserv.tbuffer,info.name);
1629 checkserv.tsize=strlen(info.name)+1;
1632 strcpy(checkserv.tbuffer,"\0");
1636 if(as->parms[3].items) {
1637 checkserv.tinterval=atol(as->parms[3].items->data);
1640 if(checkserv.tinterval<0) {
1641 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
1642 checkserv.tinterval=0;
1644 else if(checkserv.tinterval> 600) {
1645 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1646 checkserv.tinterval=600; /* 10 min max interval */
1650 checkserv.tinterval = -1; /* don't change current interval */
1653 code = pioctl(0, VIOCCKSERV, &blob, 1);
1655 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1656 printf("Must be root to change -interval\n");
1662 bcopy(space, &temp, sizeof(afs_int32));
1663 if (checkserv.tinterval >= 0) {
1664 if (checkserv.tinterval > 0)
1665 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1666 checkserv.tinterval, temp);
1668 printf("The current down server probe interval is %d secs\n", temp);
1672 printf("All servers are running.\n");
1675 printf("These servers unavailable due to network or server problems: ");
1677 bcopy(space + j*sizeof(afs_int32), &temp, sizeof(afs_int32));
1678 if (temp == 0) break;
1679 tp = hostutil_GetNameByINet(temp);
1688 static MessagesCmd(as)
1689 struct cmd_syndesc *as;
1692 struct ViceIoctl blob;
1695 struct gaginfo gagflags;
1696 struct cmd_item *show;
1698 bzero (&gagflags, sizeof(struct gaginfo));
1699 blob.in_size = sizeof(struct gaginfo);
1700 blob.in = (caddr_t) &gagflags;
1701 blob.out_size = MAXSIZE;
1703 bzero(space, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1705 if (show = as->parms[0].items) {
1706 if (!strcasecmp (show->data, "user"))
1707 gagflags.showflags |= GAGUSER;
1708 else if (!strcasecmp (show->data, "console"))
1709 gagflags.showflags |= GAGCONSOLE;
1710 else if (!strcasecmp (show->data, "all"))
1711 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1712 else if (!strcasecmp (show->data, "none"))
1716 "unrecognized flag %s: must be in {user,console,all,none}\n",
1725 code = pioctl(0, VIOC_GAG, &blob, 1);
1734 static CheckVolumesCmd(as)
1735 struct cmd_syndesc *as;
1738 struct ViceIoctl blob;
1742 code = pioctl(0, VIOCCKBACK, &blob, 1);
1748 printf("All volumeID/name mappings checked.\n");
1752 static SetCacheSizeCmd(as)
1753 struct cmd_syndesc *as;
1756 struct ViceIoctl blob;
1759 if (!as->parms[0].items && !as->parms[1].items) {
1760 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
1763 if (as->parms[0].items) {
1764 code = util_GetInt32(as->parms[0].items->data, &temp);
1766 fprintf(stderr, "%s: bad integer specified for cache size.\n", pn);
1772 blob.in = (char *) &temp;
1773 blob.in_size = sizeof(afs_int32);
1775 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
1777 if (errno == EROFS) {
1778 printf("'fs setcache' not allowed on memory cache based cache managers.\n");
1781 Die(errno, (char *) 0);
1786 printf("New cache size set.\n");
1790 #define MAXGCSIZE 16
1791 static GetCacheParmsCmd(as)
1792 struct cmd_syndesc *as;
1795 struct ViceIoctl blob;
1796 afs_int32 parms[MAXGCSIZE];
1798 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
1799 blob.in = (char *) 0;
1801 blob.out_size = sizeof(parms);
1802 blob.out = (char *) parms;
1803 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
1805 Die(errno, (char *) 0);
1808 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
1809 parms[1], parms[0]);
1810 if (parms[1] > parms[0])
1811 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
1815 static ListCellsCmd(as)
1816 struct cmd_syndesc *as;
1822 struct ViceIoctl blob;
1825 resolve = !(as->parms[0].items); /* -numeric */
1829 bcopy(&i, tp, sizeof(afs_int32));
1830 blob.out_size = MAXSIZE;
1831 blob.in_size = sizeof(afs_int32);
1834 code = pioctl(0, VIOCGETCELL, &blob, 1);
1836 if (errno == EDOM) break; /* done with the list */
1841 printf("Cell %s on hosts", tp+MAXCELLHOSTS*sizeof(afs_int32));
1842 for(j=0; j < MAXCELLHOSTS; j++) {
1844 char *name, tbuffer[20];
1846 bcopy(tp + j*sizeof(afs_int32), &addr, sizeof(afs_int32));
1847 if (addr == 0) break;
1850 name = hostutil_GetNameByINet(addr);
1854 sprintf(tbuffer, "%d.%d.%d.%d",
1855 (addr>>24) & 0xff, (addr>>16) & 0xff,
1856 (addr>>8) & 0xff, addr & 0xff);
1859 printf(" %s", name);
1866 static NewCellCmd(as)
1867 struct cmd_syndesc *as;
1869 afs_int32 code, linkedstate=0, size=0, *lp;
1870 struct ViceIoctl blob;
1871 struct cmd_item *ti;
1872 char *tp, *cellname=0;
1873 struct hostent *thp;
1874 afs_int32 fsport = 0, vlport = 0;
1875 afs_int32 magic, scount; /* Number of servers to pass in pioctl call */
1878 * With the NEWCELL pioctl call, 3.4 clients take an array of
1879 * MAXHOSTS (13) servers while 3.5 clients take an array of
1880 * MAXCELLHOSTS (8) servers. To determine which we are talking to,
1881 * do a GETCELL pioctl and pass it a magic number. If an array of
1882 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
1885 lp = (afs_int32 *)tp;
1886 *lp++ = 0; /* first cell entry */
1887 *lp = 0x12345678; /* magic */
1888 blob.out_size = MAXSIZE;
1889 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
1892 code = pioctl(0, VIOCGETCELL, &blob, 1);
1898 cellname = tp + MAXCELLHOSTS*sizeof(afs_int32);
1899 scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
1901 /* Now setup and do the NEWCELL pioctl call */
1902 bzero(space, (scount+1) * sizeof(afs_int32));
1904 lp = (afs_int32 *)tp;
1906 tp += sizeof(afs_int32);
1907 for(ti=as->parms[1].items; ti; ti=ti->next) {
1908 thp = hostutil_GetHostByName(ti->data);
1910 fprintf(stderr, "%s: Host %s not found in host table, skipping it.\n",
1914 bcopy(thp->h_addr, tp, sizeof(afs_int32));
1915 tp += sizeof(afs_int32);
1918 if (as->parms[2].items) {
1920 * Link the cell, for the purposes of volume location, to the specified
1923 cellname = as->parms[2].items->data;
1926 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
1927 if (as->parms[3].items) {
1928 code = util_GetInt32(as->parms[3].items->data, &vlport);
1930 fprintf(stderr, "%s: bad integer specified for the fileserver port.\n", pn);
1934 if (as->parms[4].items) {
1935 code = util_GetInt32(as->parms[4].items->data, &fsport);
1937 fprintf(stderr, "%s: bad integer specified for the vldb server port.\n", pn);
1942 tp = (char *)(space + (scount+1) *sizeof(afs_int32));
1943 lp = (afs_int32 *)tp;
1947 strcpy(space + ((scount+4) * sizeof(afs_int32)), as->parms[0].items->data);
1948 size = ((scount+4) * sizeof(afs_int32))
1949 + strlen(as->parms[0].items->data)
1951 tp = (char *)(space + size);
1953 strcpy(tp, cellname);
1954 size += strlen(cellname) + 1;
1956 blob.in_size = size;
1959 code = pioctl(0, VIOCNEWCELL, &blob, 1);
1967 static WhichCellCmd(as)
1968 struct cmd_syndesc *as;
1971 struct cmd_item *ti;
1973 char cell[MAXCELLCHARS];
1975 SetDotDefault(&as->parms[0].items);
1976 for (ti=as->parms[0].items; ti; ti=ti->next) {
1977 code = GetCell(ti->data, cell);
1979 if (errno == ENOENT)
1980 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
1982 Die(errno, ti->data);
1987 printf("File %s lives in cell '%s'\n", ti->data, cell);
1992 static WSCellCmd(as)
1993 struct cmd_syndesc *as;
1996 struct ViceIoctl blob;
1999 blob.in = (char *) 0;
2000 blob.out_size = MAXSIZE;
2003 code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1);
2005 Die(errno, (char *) 0);
2009 printf("This workstation belongs to cell '%s'\n", space);
2014 static PrimaryCellCmd(as)
2015 struct cmd_syndesc *as;
2017 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2022 static MonitorCmd(as)
2023 struct cmd_syndesc *as;
2026 struct ViceIoctl blob;
2027 struct cmd_item *ti;
2029 struct hostent *thp;
2033 ti = as->parms[0].items;
2037 if (!strcmp(ti->data, "off"))
2038 hostAddr = 0xffffffff;
2040 thp = hostutil_GetHostByName(ti->data);
2042 if (!strcmp(ti->data, "localhost")) {
2043 fprintf(stderr, "localhost not in host table, assuming 127.0.0.1\n");
2044 hostAddr = htonl(0x7f000001);
2047 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2051 else bcopy(thp->h_addr, &hostAddr, sizeof(afs_int32));
2055 hostAddr = 0; /* means don't set host */
2056 setp = 0; /* aren't setting host */
2059 /* now do operation */
2060 blob.in_size = sizeof(afs_int32);
2061 blob.out_size = sizeof(afs_int32);
2062 blob.in = (char *) &hostAddr;
2063 blob.out = (char *) &hostAddr;
2064 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2070 printf("%s: new monitor host set.\n", pn);
2073 /* now decode old address */
2074 if (hostAddr == 0xffffffff) {
2075 printf("Cache monitoring is currently disabled.\n");
2078 tp = hostutil_GetNameByINet(hostAddr);
2079 printf("Using host %s for monitor services.\n", tp);
2085 static SysNameCmd(as)
2086 struct cmd_syndesc *as;
2089 struct ViceIoctl blob;
2090 struct cmd_item *ti;
2091 char *input = space;
2094 ti = as->parms[0].items;
2097 blob.out_size = MAXSIZE;
2098 blob.in_size = sizeof(afs_int32);
2099 input += sizeof(afs_int32);
2100 for(; ti; ti=ti->next) {
2102 blob.in_size += strlen(ti->data) + 1;
2103 if (blob.in_size > MAXSIZE) {
2104 fprintf(stderr, "%s: sysname%s too long.\n", pn, setp > 1 ? "s" : "");
2107 strcpy(input, ti->data);
2108 input += strlen(ti->data);
2111 bcopy(&setp, space, sizeof(afs_int32));
2112 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2118 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2122 bcopy(input, &setp, sizeof(afs_int32));
2123 input += sizeof(afs_int32);
2125 fprintf(stderr, "No sysname name value was found\n");
2128 printf("Current sysname%s is:", setp>1 ? " list" : "");
2129 for(;setp>0;--setp) {
2130 printf(" \'%s\'", input);
2131 input += strlen(input) + 1;
2137 static char *exported_types[] = {"null", "nfs", ""};
2138 static ExportAfsCmd(as)
2139 struct cmd_syndesc *as;
2142 struct ViceIoctl blob;
2143 struct cmd_item *ti;
2144 int export=0, type=0, mode = 0, exp = 0, exportcall, pwsync=0, smounts=0;
2146 ti = as->parms[0].items;
2147 if (strcmp(ti->data, "nfs") == 0) type = 0x71; /* NFS */
2149 fprintf(stderr, "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2152 ti = as->parms[1].items;
2154 if (strcmp(ti->data, "on") == 0) export = 3;
2155 else if (strcmp(ti->data, "off") == 0) export = 2;
2157 fprintf(stderr, "Illegal argument %s\n", ti->data);
2162 if (ti = as->parms[2].items) { /* -noconvert */
2163 if (strcmp(ti->data, "on") == 0) mode = 2;
2164 else if (strcmp(ti->data, "off") == 0) mode = 3;
2166 fprintf(stderr, "Illegal argument %s\n", ti->data);
2170 if (ti = as->parms[3].items) { /* -uidcheck */
2171 if (strcmp(ti->data, "on") == 0) pwsync = 3;
2172 else if (strcmp(ti->data, "off") == 0) pwsync = 2;
2174 fprintf(stderr, "Illegal argument %s\n", ti->data);
2178 if (ti = as->parms[4].items) { /* -submounts */
2179 if (strcmp(ti->data, "on") == 0) smounts = 3;
2180 else if (strcmp(ti->data, "off") == 0) smounts = 2;
2182 fprintf(stderr, "Illegal argument %s\n", ti->data);
2186 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2189 blob.in = (char *) &exportcall;
2190 blob.in_size = sizeof(afs_int32);
2191 blob.out = (char *) &exportcall;
2192 blob.out_size = sizeof(afs_int32);
2193 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2195 if (errno == ENODEV) {
2196 fprintf(stderr, "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
2204 if (exportcall & 1) {
2205 printf("'%s' translator is enabled with the following options:\n",
2206 exported_types[type]);
2207 printf("\tRunning in %s mode\n",
2208 (exportcall & 2 ? "strict unix"
2209 : "convert owner mode bits to world/other"));
2210 printf("\tRunning in %s mode\n",
2211 (exportcall & 4 ? "strict 'passwd sync'"
2212 : "no 'passwd sync'"));
2214 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs"
2215 : "Only mounts to /afs allowed"));
2218 printf("'%s' translator is disabled\n", exported_types[type]);
2224 static GetCellCmd(as)
2225 struct cmd_syndesc *as;
2228 struct ViceIoctl blob;
2229 struct afsconf_cell info;
2230 struct cmd_item *ti;
2237 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2238 for(ti=as->parms[0].items; ti; ti=ti->next) {
2240 blob.out_size = sizeof(args);
2241 blob.out = (caddr_t) &args;
2242 code = GetCellName(ti->data, &info);
2247 blob.in_size = 1+strlen(info.name);
2248 blob.in = info.name;
2249 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2251 if (errno == ENOENT)
2252 fprintf(stderr, "%s: the cell named '%s' does not exist\n", pn, info.name);
2254 Die(errno, info.name);
2258 printf("Cell %s status: ", info.name);
2260 if (args.stat & 1) printf("primary ");
2262 if (args.stat & 2) printf("no setuid allowed");
2263 else printf("setuid allowed");
2264 if (args.stat & 4) printf(", using old VLDB");
2270 static SetCellCmd(as)
2271 struct cmd_syndesc *as;
2274 struct ViceIoctl blob;
2275 struct afsconf_cell info;
2276 struct cmd_item *ti;
2284 /* Check arguments. */
2285 if (as->parms[1].items && as->parms[2].items) {
2286 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2290 /* figure stuff to set */
2294 if (! as->parms[1].items) args.stat |= 2; /* default to -nosuid */
2296 /* set stat for all listed cells */
2297 for(ti=as->parms[0].items; ti; ti=ti->next) {
2299 code = GetCellName(ti->data, &info);
2304 strcpy(args.cname, info.name);
2305 blob.in_size = sizeof(args);
2306 blob.in = (caddr_t) &args;
2308 blob.out = (caddr_t) 0;
2309 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2311 Die(errno, info.name); /* XXX added cell name to Die() call */
2318 static GetCellName(cellName, info)
2320 struct afsconf_cell *info;
2322 struct afsconf_dir *tdir;
2325 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2327 fprintf(stderr, "Could not process files in configuration directory (%s).\n",
2328 AFSDIR_CLIENT_ETC_DIRPATH);
2332 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2334 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2335 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2343 static VLDBInit(noAuthFlag, info)
2345 struct afsconf_cell *info;
2348 struct ktc_principal sname;
2349 struct ktc_token ttoken;
2351 struct rx_securityClass *sc;
2352 struct rx_connection *serverconns[VLDB_MAXSERVERS];
2357 fprintf(stderr, "%s: could not initialize rx.\n", pn);
2361 rx_SetRxDeadTime(50);
2362 if (!noAuthFlag) { /* we don't need tickets for null */
2363 strcpy(sname.cell, info->name);
2364 sname.instance[0] = 0;
2365 strcpy(sname.name, "afs");
2366 code = ktc_GetToken(&sname,&ttoken, sizeof(ttoken), (char *)0);
2368 fprintf(stderr, "%s: Could not get afs tokens, running unauthenticated.\n", pn);
2373 if (ttoken.kvno >= 0 && ttoken.kvno <= 255) scIndex = 2; /* kerberos */
2375 fprintf(stderr, "%s: funny kvno (%d) in ticket, proceeding\n",
2381 else scIndex = 0; /* don't authenticate */
2384 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
2390 sc = (struct rx_securityClass *)
2391 rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
2392 ttoken.kvno, ttoken.ticketLen,
2396 if (info->numServers > VLDB_MAXSERVERS) {
2397 fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
2398 pn, info->numServers, VLDB_MAXSERVERS);
2401 bzero(serverconns, sizeof(serverconns));
2402 for (i = 0;i<info->numServers;i++)
2403 serverconns[i] = rx_NewConnection(info->hostAddr[i].sin_addr.s_addr,
2404 info->hostAddr[i].sin_port, USER_SERVICE_ID,
2407 code = ubik_ClientInit(serverconns, &uclient);
2410 fprintf(stderr, "%s: ubik client init failed.\n", pn);
2416 static struct ViceIoctl gblob;
2417 static int debug = 0;
2419 * here follow some routines in suport of the setserverprefs and
2420 * getserverprefs commands. They are:
2421 * SetPrefCmd "top-level" routine
2422 * addServer adds a server to the list of servers to be poked into the
2423 * kernel. Will poke the list into the kernel if it threatens
2425 * pokeServers pokes the existing list of servers and ranks into the kernel
2426 * GetPrefCmd reads the Cache Manager's current list of server ranks
2430 * returns -1 if error message printed,
2432 * errno value if error and no error message printed
2434 static pokeServers()
2438 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2439 if (code && (errno == EINVAL)) {
2440 struct setspref *ssp;
2441 ssp = (struct setspref *)gblob.in;
2442 if (!(ssp->flags & DBservers)) {
2443 gblob.in = (void *) &(ssp->servers[0]);
2444 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2445 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2446 return code ? errno : 0;
2449 "This cache manager does not support VL server preferences.\n");
2453 return code ? errno : 0;
2457 * returns -1 if error message printed,
2459 * errno value if error and no error message printed
2461 static addServer(name, rank)
2466 struct setspref *ssp;
2468 struct hostent *thostent;
2474 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2476 #define MAXUSHORT ((unsigned short) ~0)
2480 thostent = hostutil_GetHostByName(name);
2482 fprintf(stderr, "%s: couldn't resolve name.\n", name);
2486 ssp = (struct setspref *)(gblob.in);
2488 for (t = 0; thostent->h_addr_list[t]; t++) {
2489 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
2490 code = pokeServers();
2491 if (code) error = code;
2492 ssp->num_servers = 0;
2495 sp = (struct spref *) (gblob.in + gblob.in_size);
2496 bcopy (thostent->h_addr_list[t], &(sp->server.s_addr), sizeof(afs_uint32));
2497 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2498 gblob.in_size += sizeof(struct spref);
2502 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
2503 name,sp->rank,sp->server.s_addr);
2510 static SetPrefCmd(as)
2511 struct cmd_syndesc *as;
2515 struct cmd_item *ti;
2518 struct setspref *ssp;
2519 int error = 0; /* -1 means error message printed,
2520 * >0 means errno value for unprinted message */
2522 ssp = (struct setspref *)space;
2524 ssp->num_servers = 0;
2525 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2528 gblob.out_size = MAXSIZE;
2532 fprintf(stderr, "Permission denied: requires root access.\n");
2536 ti = as->parms[2].items; /* -file */
2538 if (debug) fprintf(stderr, "opening file %s\n",ti->data);
2539 if (!(infd = fopen(ti->data,"r"))) {
2544 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2545 code = addServer(name, (unsigned short) rank);
2546 if (code) error = code;
2551 ti = as->parms[3].items; /* -stdin */
2553 while (scanf("%79s%ld", name, &rank) != EOF) {
2554 code = addServer(name, (unsigned short) rank);
2555 if (code) error = code;
2559 for (ti = as->parms[0].items;ti;ti=ti->next) { /* list of servers, ranks */
2564 code = addServer(ti->data, (unsigned short) atol(ti->next->data));
2565 if (code) error = code;
2567 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
2571 code = pokeServers();
2572 if (code) error = code;
2574 printf("now working on vlservers, code=%d\n",code);
2576 ssp = (struct setspref *)space;
2577 ssp->flags = DBservers;
2578 ssp->num_servers = 0;
2579 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2582 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
2587 code = addServer(ti->data, (unsigned short) atol(ti->next->data));
2588 if (code) error = code;
2590 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
2595 if (as->parms[1].items) {
2597 printf("now poking vlservers\n");
2598 code = pokeServers();
2599 if (code) error = code;
2605 return error ? 1 : 0;
2610 static GetPrefCmd(as)
2611 struct cmd_syndesc *as;
2614 struct cmd_item *ti;
2615 char *name, tbuffer[20];
2616 afs_int32 rank,addr;
2620 struct ViceIoctl blob;
2621 struct sprefrequest *in;
2622 struct sprefinfo *out;
2625 ti = as->parms[0].items; /* -file */
2627 if (debug) fprintf(stderr, "opening file %s\n",ti->data);
2628 if (!(outfd = freopen(ti->data,"w",stdout))) {
2634 ti = as->parms[1].items; /* -numeric */
2636 ti = as->parms[2].items; /* -vlservers */
2637 vlservers |= (ti ? DBservers : 0);
2638 /* ti = as->parms[3].items; -cell */
2640 in = (struct sprefrequest *)space;
2644 blob.in_size=sizeof(struct sprefrequest);
2645 blob.in = (char *)in;
2647 blob.out_size = MAXSIZE;
2649 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct spref);
2650 in->flags = vlservers;
2652 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
2654 perror("getserverprefs pioctl");
2658 out = (struct sprefinfo *) blob.out;
2660 for (i=0;i<out->num_servers;i++) {
2662 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
2665 addr = ntohl(out->servers[i].server.s_addr);
2666 sprintf(tbuffer, "%d.%d.%d.%d",
2667 (addr>>24) & 0xff, (addr>>16) & 0xff,
2668 (addr>>8) & 0xff, addr & 0xff);
2671 printf("%-50s %5u\n",name,out->servers[i].rank);
2674 in->offset = out->next_offset;
2675 } while (out->next_offset > 0);
2680 static StoreBehindCmd(as)
2681 struct cmd_syndesc *as;
2684 struct ViceIoctl blob;
2685 struct cmd_item *ti;
2686 struct sbstruct tsb, tsb2;
2692 tsb.sb_thisfile = -1;
2693 ti=as->parms[0].items; /* -kbytes */
2695 if (!as->parms[1].items) {
2696 fprintf(stderr, "%s: you must specify -files with -kbytes.\n", pn);
2699 tsb.sb_thisfile = strtol(ti->data,&t,10) * 1024;
2700 if ((tsb.sb_thisfile < 0) || (t != ti->data+strlen(ti->data))) {
2701 fprintf(stderr, "%s: %s must be 0 or a positive number.\n",
2707 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
2708 ti=as->parms[2].items; /* -allfiles */
2710 allfiles = strtol(ti->data,&t,10) * 1024;
2711 if ((allfiles < 0) || (t != ti->data+strlen(ti->data))) {
2712 fprintf(stderr, "%s: %s must be 0 or a positive number.\n",
2718 /* -verbose or -file only or no options */
2719 if (as->parms[3].items ||
2720 (as->parms[1].items && !as->parms[0].items) ||
2721 (!as->parms[0].items && !as->parms[1].items && !as->parms[2].items))
2724 blob.in = (char *)&tsb;
2725 blob.out = (char *)&tsb2;
2726 blob.in_size = blob.out_size = sizeof(struct sbstruct);
2727 bzero (&tsb2, sizeof(tsb2));
2729 /* once per -file */
2730 for (ti=as->parms[1].items; ti; ti=ti->next) {
2731 /* Do this solely to see if the file is there */
2732 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
2734 Die(errno, ti->data);
2739 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
2741 Die(errno, ti->data);
2746 if (verbose && (blob.out_size == sizeof(tsb2))) {
2747 if (tsb2.sb_thisfile == -1) {
2748 fprintf(stdout, "Will store %s according to default.\n",
2753 "Will store up to %d kbytes of %s asynchronously.\n",
2754 (tsb2.sb_thisfile/1024), ti->data);
2759 /* If no files - make at least one pioctl call, or
2760 * set the allfiles default if we need to.
2762 if (!as->parms[1].items || (allfiles != -1)) {
2763 tsb.sb_default = allfiles;
2764 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
2766 Die(errno, ((allfiles == -1)?0:"-allfiles"));
2771 /* Having no arguments also reports the default store asynchrony */
2772 if (verbose && (blob.out_size == sizeof(tsb2))) {
2773 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
2774 (tsb2.sb_default/1024));
2781 static afs_int32 SetCryptCmd(as)
2782 struct cmd_syndesc *as;
2784 afs_int32 code = 0, flag;
2785 struct ViceIoctl blob;
2788 tp = as->parms[0].items->data;
2789 if (strcmp(tp, "on") == 0)
2791 else if (strcmp(tp, "off") == 0)
2794 fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
2798 blob.in = (char *) &flag;
2799 blob.in_size = sizeof(flag);
2801 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
2803 Die(errno, (char *) 0);
2808 static afs_int32 GetCryptCmd(as)
2809 struct cmd_syndesc *as;
2811 afs_int32 code = 0, flag;
2812 struct ViceIoctl blob;
2815 blob.in = (char *) 0;
2817 blob.out_size = sizeof(flag);
2820 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
2822 if (code) Die(errno, (char *) 0);
2825 bcopy(tp, &flag, sizeof(afs_int32));
2826 printf("Security level is currently ");
2828 printf("crypt (data security).\n");
2835 #include "AFS_component_version_number.c"
2842 struct cmd_syndesc *ts;
2844 #ifdef AFS_AIX32_ENV
2846 * The following signal action for AIX is necessary so that in case of a
2847 * crash (i.e. core is generated) we can include the user's data section
2848 * in the core dump. Unfortunately, by default, only a partial core is
2849 * generated which, in many cases, isn't too useful.
2851 struct sigaction nsa;
2853 sigemptyset(&nsa.sa_mask);
2854 nsa.sa_handler = SIG_DFL;
2855 nsa.sa_flags = SA_FULLDUMP;
2856 sigaction(SIGSEGV, &nsa, NULL);
2859 /* try to find volume location information */
2860 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0, "get client network interface addresses");
2861 cmd_CreateAlias(ts, "gc");
2863 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0, "set client network interface addresses");
2864 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "client network interfaces");
2865 cmd_CreateAlias(ts, "sc");
2867 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks");
2868 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
2869 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
2870 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
2871 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
2872 cmd_CreateAlias(ts, "sp");
2874 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks");
2875 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
2876 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
2877 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
2878 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
2879 cmd_CreateAlias(ts, "gp");
2881 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
2882 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2883 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
2884 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
2885 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
2886 parm_setacl_id = ts->nParms;
2887 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
2888 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
2889 cmd_CreateAlias(ts, "sa");
2891 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list");
2892 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2893 parm_listacl_id = ts->nParms;
2894 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
2895 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
2896 cmd_CreateAlias(ts, "la");
2898 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list");
2899 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2901 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list");
2902 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
2903 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
2904 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
2905 parm_copyacl_id = ts->nParms;
2906 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
2907 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
2909 cmd_CreateAlias(ts, "ca");
2911 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
2912 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2913 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0, "flush mount symlink from cache");
2914 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2916 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
2917 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2918 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
2920 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
2921 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
2923 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
2924 cmd_CreateAlias(ts, "sv");
2926 ts = cmd_CreateSyntax("messages", MessagesCmd, 0, "control Cache Manager messages");
2927 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
2929 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display volume status");
2930 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2931 cmd_CreateAlias(ts, "lv");
2932 cmd_CreateAlias(ts, "listvol");
2934 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
2935 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2936 cmd_CreateAlias(ts, "lq");
2938 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage");
2939 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2940 cmd_CreateAlias(ts, "df");
2942 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
2943 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2945 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
2946 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2948 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
2949 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
2950 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
2951 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
2952 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
2953 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
2959 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
2963 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
2964 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2966 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers");
2967 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
2968 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
2969 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
2970 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
2972 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings");
2973 cmd_CreateAlias(ts, "checkbackups");
2976 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size");
2977 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
2978 cmd_CreateAlias(ts, "cachesize");
2980 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
2982 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info");
2984 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells");
2985 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
2987 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
2988 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
2989 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
2991 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
2993 cmd_CreateAlias(ts, "sq");
2995 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
2996 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
2997 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
2998 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
3000 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3002 * Turn this on only if you wish to be able to talk to a server which is listening
3003 * on alternative ports. This is not intended for general use and may not be
3004 * supported in the cache manager. It is not a way to run two servers at the
3005 * same host, since the cache manager cannot properly distinguish those two hosts.
3007 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
3008 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
3011 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
3012 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3014 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
3015 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3017 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
3020 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
3023 /* set cache monitor host address */
3024 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, (char *) CMD_HIDDEN);
3025 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
3026 cmd_CreateAlias(ts, "mariner");
3028 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
3029 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3031 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
3032 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3033 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3034 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
3036 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume");
3037 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3039 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value");
3040 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3042 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS");
3043 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3044 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator (on | off)");
3045 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode (on | off)");
3046 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode (on | off)");
3047 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. (on | off)");
3050 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
3051 "store to server after file close");
3052 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
3053 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3054 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
3055 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3056 cmd_CreateAlias(ts, "sb");
3058 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag");
3059 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3061 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "set cache manager encryption flag");
3063 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
3064 "Manage per process RX statistics");
3065 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL,
3067 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL,
3068 "Disable RX stats");
3069 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3072 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0,
3073 "Manage per peer RX statistics");
3074 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL,
3076 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL,
3077 "Disable RX stats");
3078 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3081 code = cmd_Dispatch(argc, argv);
3082 if (rxInitDone) rx_Finalize();
3087 static void Die(errnum, filename)
3094 fprintf(stderr, "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3097 fprintf(stderr, "%s: Invalid argument.\n", pn);
3101 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3103 fprintf(stderr, "%s: no such file returned\n", pn);
3106 fprintf(stderr, "%s: You can not change a backup or readonly volume\n", pn);
3111 fprintf(stderr, "%s: You don't have the required access rights on '%s'\n",
3114 fprintf(stderr, "%s: You do not have the required rights to do this operation\n",
3119 fprintf(stderr, "%s:'%s'", pn, filename);
3121 fprintf(stderr, "%s", pn);
3122 fprintf(stderr, ": %s\n", error_message(errnum));
3127 /* get clients interface addresses */
3129 GetClientAddrsCmd(as)
3130 struct cmd_syndesc *as;
3133 struct cmd_item *ti;
3135 struct ViceIoctl blob;
3136 struct sprefrequest *in;
3137 struct sprefinfo *out;
3139 in = (struct sprefrequest *)space;
3144 blob.in_size=sizeof(struct sprefrequest);
3145 blob.in = (char *)in;
3147 blob.out_size = MAXSIZE;
3149 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct spref);
3150 /* returns addr in network byte order */
3151 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3153 perror("getClientInterfaceAddr pioctl");
3159 out = (struct sprefinfo *) blob.out;
3160 for (i=0; i < out->num_servers; i++) {
3163 addr = ntohl(out->servers[i].server.s_addr);
3164 sprintf(tbuffer, "%d.%d.%d.%d",
3165 (addr>>24) & 0xff, (addr>>16) & 0xff,
3166 (addr>>8) & 0xff, addr & 0xff);
3167 printf ("%-50s\n", tbuffer);
3169 in->offset = out->next_offset;
3171 } while (out->next_offset > 0);
3177 SetClientAddrsCmd(as)
3178 struct cmd_syndesc *as;
3180 afs_int32 code, addr;
3181 struct cmd_item *ti;
3183 struct ViceIoctl blob;
3184 struct setspref *ssp;
3185 int sizeUsed = 0, i, flag;
3186 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3190 ssp = (struct setspref *)space;
3191 ssp->num_servers = 0;
3194 blob.out_size = MAXSIZE;
3197 fprintf(stderr, "Permission denied: requires root access.\n");
3201 /* extract all existing interface addresses */
3202 existNu = rx_getAllAddr(existingAddr,1024);
3206 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3207 for (ti = as->parms[0].items;ti;ti=ti->next) {
3208 if (sizeUsed >= sizeof(space)) {
3209 fprintf(stderr, "No more space\n");
3212 addr = extractAddr(ti->data, 20); /* network order */
3213 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3214 fprintf(stderr, "Error in specifying address: %s..ignoring\n", ti->data);
3218 /* see if it is an address that really exists */
3219 for (flag = 0, i=0; i < existNu; i++)
3220 if (existingAddr[i] == addr) {
3224 if (!flag) { /* this is an nonexistent address */
3225 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3229 /* copy all specified addr into ioctl buffer */
3230 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3231 printf("Adding 0x%08x\n", addr);
3233 sizeUsed += sizeof(struct spref);
3235 if (ssp->num_servers < 1) {
3236 fprintf(stderr, "No addresses specified\n");
3239 blob.in_size = sizeUsed - sizeof(struct spref);
3241 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3252 struct cmd_syndesc *as;
3255 struct ViceIoctl blob;
3256 struct cmd_item *ti;
3257 char orig_name[1024]; /*Original name, may be modified*/
3258 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
3259 char parent_dir[1024]; /*Parent directory of true name*/
3260 char *last_component; /*Last component of true name*/
3261 struct stat statbuff; /*Buffer for status info*/
3262 int link_chars_read; /*Num chars read in readlink()*/
3263 int thru_symlink; /*Did we get to a mount point via a symlink?*/
3266 for(ti=as->parms[0].items; ti; ti=ti->next) {
3269 sprintf(orig_name, "%s%s",
3270 (ti->data[0] == '/') ? "" : "./",
3273 if (lstat(orig_name, &statbuff) < 0) {
3274 /* if lstat fails, we should still try the pioctl, since it
3275 may work (for example, lstat will fail, but pioctl will
3276 work if the volume of offline (returning ENODEV). */
3277 statbuff.st_mode = S_IFDIR; /* lie like pros */
3281 * The lstat succeeded. If the given file is a symlink, substitute
3282 * the file name with the link name.
3284 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
3287 * Read name of resolved file.
3289 link_chars_read = readlink(orig_name, true_name, 1024);
3290 if (link_chars_read <= 0) {
3291 fprintf(stderr, "%s: Can't read target name for '%s' symbolic link!\n",
3298 * Add a trailing null to what was read, bump the length.
3300 true_name[link_chars_read++] = 0;
3303 * If the symlink is an absolute pathname, we're fine. Otherwise, we
3304 * have to create a full pathname using the original name and the
3305 * relative symlink name. Find the rightmost slash in the original
3306 * name (we know there is one) and splice in the symlink value.
3308 if (true_name[0] != '/') {
3309 last_component = (char *) rindex(orig_name, '/');
3310 strcpy(++last_component, true_name);
3311 strcpy(true_name, orig_name);
3315 strcpy(true_name, orig_name);
3318 * Find rightmost slash, if any.
3320 last_component = (char *) rindex(true_name, '/');
3321 if (last_component) {
3323 * Found it. Designate everything before it as the parent directory,
3324 * everything after it as the final component.
3326 strncpy(parent_dir, true_name, last_component - true_name);
3327 parent_dir[last_component - true_name] = 0;
3328 last_component++; /*Skip the slash*/
3332 * No slash appears in the given file name. Set parent_dir to the current
3333 * directory, and the last component as the given name.
3335 strcpy(parent_dir, ".");
3336 last_component = true_name;
3339 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
3340 fprintf(stderr, "%s: you may not use '.' or '..' as the last component\n", pn);
3341 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n", pn);
3346 blob.in = last_component;
3347 blob.in_size = strlen(last_component)+1;
3349 bzero(space, MAXSIZE);
3351 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
3354 if (errno == EINVAL) {
3355 fprintf(stderr, "'%s' is not a mount point.\n",
3359 Die(errno, (ti->data ? ti->data : parent_dir));
3369 struct cmd_syndesc *as;
3372 afs_int32 flags = 0;
3373 struct ViceIoctl blob;
3374 struct cmd_item *ti;
3376 if (as->parms[0].items) { /* -enable*/
3377 flags |= AFSCALL_RXSTATS_ENABLE;
3379 if (as->parms[1].items) { /* -disable*/
3380 flags |= AFSCALL_RXSTATS_DISABLE;
3382 if (as->parms[2].items) { /* -clear*/
3383 flags |= AFSCALL_RXSTATS_CLEAR;
3386 fprintf(stderr, "You must specify at least one argument\n");
3390 blob.in = (char *)&flags;
3391 blob.in_size = sizeof(afs_int32);
3394 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
3405 struct cmd_syndesc *as;
3408 afs_int32 flags = 0;
3409 struct ViceIoctl blob;
3410 struct cmd_item *ti;
3412 if (as->parms[0].items) { /* -enable*/
3413 flags |= AFSCALL_RXSTATS_ENABLE;
3415 if (as->parms[1].items) { /* -disable*/
3416 flags |= AFSCALL_RXSTATS_DISABLE;
3418 if (as->parms[2].items) { /* -clear*/
3419 flags |= AFSCALL_RXSTATS_CLEAR;
3422 fprintf(stderr, "You must specify at least one argument\n");
3426 blob.in = (char *)&flags;
3427 blob.in_size = sizeof(afs_int32);
3430 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);