1 /* Copyright (C) 1990 Transarc Corporation - All rights reserved */
3 * (C) COPYRIGHT IBM CORPORATION 1987
4 * LICENSED MATERIALS - PROPERTY OF IBM
8 #include <afs/afs_args.h>
10 #include <sys/ioctl.h>
11 #include <sys/socket.h>
15 #include <netinet/in.h>
19 #include <afs/venus.h>
25 #include "afs/prs_fs.h"
26 #include <afs/afsint.h>
28 #include <afs/cellconfig.h>
31 #include <rx/rx_globals.h>
32 #include <afs/vldbint.h>
33 #include <afs/volser.h>
34 #include <afs/vlserver.h>
37 #include <afs/afsutil.h>
40 #include <afs/ptclient.h>
45 #define MAXCELLHOSTS 8
48 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
49 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
51 static char space[MAXSIZE];
52 static char tspace[1024];
53 static struct ubik_client *uclient;
55 static int GetClientAddrsCmd(), SetClientAddrsCmd(), FlushMountCmd();
56 static int RxStatProcCmd(), RxStatPeerCmd();
58 extern char *hostutil_GetNameByINet();
59 extern struct hostent *hostutil_GetHostByName();
60 extern afs_int32 VL_GetEntryByNameO();
63 extern struct cmd_syndesc *cmd_CreateSyntax();
64 static char pn[] = "fs";
65 static int rxInitDone = 0;
67 static void ZapList();
68 static int PruneList();
76 * Character to use between name and rights in printed representation for
79 #define DFS_SEPARATOR ' '
81 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
84 int dfs; /* Originally true if a dfs acl; now also the type
85 of the acl (1, 2, or 3, corresponding to object,
86 initial dir, or initial object). */
87 sec_rgy_name_t cell; /* DFS cell name */
90 struct AclEntry *pluslist;
91 struct AclEntry *minuslist;
95 struct AclEntry *next;
100 static void ZapAcl(acl)
104 ZapList(acl->pluslist);
105 ZapList(acl->minuslist);
117 if (t >= 'A' && t <= 'Z') t += 0x20;
118 if (u >= 'A' && u <= 'Z') u += 0x20;
119 if (t != u) return 1;
120 if (t == 0) return 0;
125 * Mods for the AFS/DFS protocol translator.
127 * DFS rights. It's ugly to put these definitions here, but they
128 * *cannot* change, because they're part of the wire protocol.
129 * In any event, the protocol translator will guarantee these
130 * assignments for AFS cache managers.
132 #define DFS_READ 0x01
133 #define DFS_WRITE 0x02
134 #define DFS_EXECUTE 0x04
135 #define DFS_CONTROL 0x08
136 #define DFS_INSERT 0x10
137 #define DFS_DELETE 0x20
139 /* the application definable ones (backwards from AFS) */
140 #define DFS_USR0 0x80000000 /* "A" bit */
141 #define DFS_USR1 0x40000000 /* "B" bit */
142 #define DFS_USR2 0x20000000 /* "C" bit */
143 #define DFS_USR3 0x10000000 /* "D" bit */
144 #define DFS_USR4 0x08000000 /* "E" bit */
145 #define DFS_USR5 0x04000000 /* "F" bit */
146 #define DFS_USR6 0x02000000 /* "G" bit */
147 #define DFS_USR7 0x01000000 /* "H" bit */
148 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
149 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
152 * Offset of -id switch in command structure for various commands.
153 * The -if switch is the next switch always.
155 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
158 * Determine whether either the -id or -if switches are present, and
159 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
161 static int getidf(as, id)
162 struct cmd_syndesc *as;
163 int id; /* Offset of -id switch; -if is next switch */
167 if (as->parms[id].items) {
170 if (as->parms[id + 1].items) {
176 "%s: you may specify either -id or -if, but not both switches\n",
183 static int PRights(arights, dfs)
188 if (arights & PRSFS_READ) printf("r");
189 if (arights & PRSFS_LOOKUP) printf("l");
190 if (arights & PRSFS_INSERT) printf("i");
191 if (arights & PRSFS_DELETE) printf("d");
192 if (arights & PRSFS_WRITE) printf("w");
193 if (arights & PRSFS_LOCK) printf("k");
194 if (arights & PRSFS_ADMINISTER) printf("a");
195 if (arights & PRSFS_USR0) printf("A");
196 if (arights & PRSFS_USR1) printf("B");
197 if (arights & PRSFS_USR2) printf("C");
198 if (arights & PRSFS_USR3) printf("D");
199 if (arights & PRSFS_USR4) printf("E");
200 if (arights & PRSFS_USR5) printf("F");
201 if (arights & PRSFS_USR6) printf("G");
202 if (arights & PRSFS_USR7) printf("H");
204 if (arights & DFS_READ) printf("r"); else printf("-");
205 if (arights & DFS_WRITE) printf("w"); else printf("-");
206 if (arights & DFS_EXECUTE) printf("x"); else printf("-");
207 if (arights & DFS_CONTROL) printf("c"); else printf("-");
208 if (arights & DFS_INSERT) printf("i"); else printf("-");
209 if (arights & DFS_DELETE) printf("d"); else printf("-");
210 if (arights & (DFS_USRALL)) printf("+");
211 if (arights & DFS_USR0) printf("A");
212 if (arights & DFS_USR1) printf("B");
213 if (arights & DFS_USR2) printf("C");
214 if (arights & DFS_USR3) printf("D");
215 if (arights & DFS_USR4) printf("E");
216 if (arights & DFS_USR5) printf("F");
217 if (arights & DFS_USR6) printf("G");
218 if (arights & DFS_USR7) printf("H");
222 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
223 static int InAFS(apath)
226 struct ViceIoctl blob;
230 blob.out_size = MAXSIZE;
233 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
235 if ((errno == EINVAL) || (errno == ENOENT)) return 0;
240 /* return a static pointer to a buffer */
241 static char *Parent(apath)
245 strcpy(tspace, apath);
246 tp = rindex(tspace, '/');
250 else strcpy(tspace, ".");
254 enum rtype {add, destroy, deny};
256 static afs_int32 Convert(arights, dfs, rtypep)
265 *rtypep = add; /* add rights, by default */
268 if (!strcmp(arights, "null")) {
272 if (!strcmp(arights,"read")) return DFS_READ | DFS_EXECUTE;
273 if (!strcmp(arights, "write")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE;
274 if (!strcmp(arights, "all")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE | DFS_CONTROL;
276 if (!strcmp(arights,"read")) return PRSFS_READ | PRSFS_LOOKUP;
277 if (!strcmp(arights, "write")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK;
278 if (!strcmp(arights, "mail")) return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
279 if (!strcmp(arights, "all")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
281 if (!strcmp(arights, "none")) {
282 *rtypep = destroy; /* Remove entire entry */
285 len = strlen(arights);
290 if (tc == '-') continue;
291 else if (tc == 'r') mode |= DFS_READ;
292 else if (tc == 'w') mode |= DFS_WRITE;
293 else if (tc == 'x') mode |= DFS_EXECUTE;
294 else if (tc == 'c') mode |= DFS_CONTROL;
295 else if (tc == 'i') mode |= DFS_INSERT;
296 else if (tc == 'd') mode |= DFS_DELETE;
297 else if (tc == 'A') mode |= DFS_USR0;
298 else if (tc == 'B') mode |= DFS_USR1;
299 else if (tc == 'C') mode |= DFS_USR2;
300 else if (tc == 'D') mode |= DFS_USR3;
301 else if (tc == 'E') mode |= DFS_USR4;
302 else if (tc == 'F') mode |= DFS_USR5;
303 else if (tc == 'G') mode |= DFS_USR6;
304 else if (tc == 'H') mode |= DFS_USR7;
306 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n", pn, tc);
310 if (tc == 'r') mode |= PRSFS_READ;
311 else if (tc == 'l') mode |= PRSFS_LOOKUP;
312 else if (tc == 'i') mode |= PRSFS_INSERT;
313 else if (tc == 'd') mode |= PRSFS_DELETE;
314 else if (tc == 'w') mode |= PRSFS_WRITE;
315 else if (tc == 'k') mode |= PRSFS_LOCK;
316 else if (tc == 'a') mode |= PRSFS_ADMINISTER;
317 else if (tc == 'A') mode |= PRSFS_USR0;
318 else if (tc == 'B') mode |= PRSFS_USR1;
319 else if (tc == 'C') mode |= PRSFS_USR2;
320 else if (tc == 'D') mode |= PRSFS_USR3;
321 else if (tc == 'E') mode |= PRSFS_USR4;
322 else if (tc == 'F') mode |= PRSFS_USR5;
323 else if (tc == 'G') mode |= PRSFS_USR6;
324 else if (tc == 'H') mode |= PRSFS_USR7;
326 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn, tc);
334 static struct AclEntry *FindList(alist, aname)
335 struct AclEntry *alist;
339 if (!foldcmp(alist->name, aname)) return alist;
345 /* if no parm specified in a particular slot, set parm to be "." instead */
346 static void SetDotDefault(aitemp)
347 struct cmd_item **aitemp;
350 if (*aitemp) return; /* already has value */
351 /* otherwise, allocate an item representing "." */
352 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
354 ti->next = (struct cmd_item *) 0;
355 ti->data = (char *) malloc(2);
357 strcpy(ti->data, ".");
361 static void ChangeList(al, plus, aname, arights)
367 struct AclEntry *tlist;
368 tlist = (plus ? al->pluslist : al->minuslist);
369 tlist = FindList (tlist, aname);
371 /* Found the item already in the list. */
372 tlist->rights = arights;
374 al->nplus -= PruneList(&al->pluslist, al->dfs);
376 al->nminus -= PruneList(&al->minuslist, al->dfs);
379 /* Otherwise we make a new item and plug in the new data. */
380 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
382 strcpy(tlist->name, aname);
383 tlist->rights = arights;
385 tlist->next = al->pluslist;
386 al->pluslist = tlist;
388 if (arights == 0 || arights == -1)
389 al->nplus -= PruneList(&al->pluslist, al->dfs);
392 tlist->next = al->minuslist;
393 al->minuslist = tlist;
395 if (arights == 0) al->nminus -= PruneList(&al->minuslist, al->dfs);
399 static void ZapList(alist)
400 struct AclEntry *alist;
402 struct AclEntry *tp, *np;
403 for (tp = alist; tp; tp = np) {
409 static int PruneList(ae, dfs)
410 struct AclEntry **ae;
413 struct AclEntry **lp;
414 struct AclEntry *te, *ne;
418 for(te = *ae;te;te=ne) {
419 if ((!dfs && te->rights == 0) || te->rights == -1) {
433 static char *SkipLine(astr)
436 while (*astr !='\n') astr++;
442 * Create an empty acl, taking into account whether the acl pointed
443 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
444 * can recover from problems caused by bogus ACL's (in that case, always
445 * assume that the acl is AFS: for DFS, the user can always resort to
446 * acl_edit, but for AFS there may be no other way out).
448 static struct Acl *EmptyAcl(astr)
454 tp = (struct Acl *)malloc(sizeof (struct Acl));
456 tp->nplus = tp->nminus = 0;
457 tp->pluslist = tp->minuslist = 0;
459 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
463 static struct Acl *ParseAcl(astr)
466 int nplus, nminus, i, trights;
468 struct AclEntry *first, *last, *tl;
471 ta = (struct Acl *) malloc (sizeof (struct Acl));
474 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
475 astr = SkipLine(astr);
476 sscanf(astr, "%d", &ta->nminus);
477 astr = SkipLine(astr);
484 for(i=0;i<nplus;i++) {
485 sscanf(astr, "%100s %d", tname, &trights);
486 astr = SkipLine(astr);
487 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
489 if (!first) first = tl;
490 strcpy(tl->name, tname);
491 tl->rights = trights;
493 if (last) last->next = tl;
496 ta->pluslist = first;
500 for(i=0;i<nminus;i++) {
501 sscanf(astr, "%100s %d", tname, &trights);
502 astr = SkipLine(astr);
503 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
505 if (!first) first = tl;
506 strcpy(tl->name, tname);
507 tl->rights = trights;
509 if (last) last->next = tl;
512 ta->minuslist = first;
517 static PrintStatus(status, name, offmsg)
518 VolumeStatus *status;
522 printf("Volume status for vid = %u named %s\n",status->Vid, name);
524 printf("Current offline message is %s\n",offmsg);
525 printf("Current disk quota is ");
526 if (status->MaxQuota != 0) printf("%d\n", status->MaxQuota);
527 else printf("unlimited\n");
528 printf("Current blocks used are %d\n",status->BlocksInUse);
529 printf("The partition has %d blocks available out of %d\n\n",status->PartBlocksAvail, status->PartMaxBlocks);
532 static QuickPrintStatus(status, name)
533 VolumeStatus *status;
536 double QuotaUsed =0.0;
537 double PartUsed =0.0;
539 printf("%-25.25s",name);
541 if (status->MaxQuota != 0) {
542 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
543 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
545 printf(" no limit%10d", status->BlocksInUse);
547 if (QuotaUsed > 90.0) {
548 printf("%5.0f%%<<", QuotaUsed);
551 else printf("%5.0f%% ", QuotaUsed);
552 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
553 if (PartUsed > 97.0) {
554 printf("%9.0f%%<<", PartUsed);
557 else printf("%9.0f%% ", PartUsed);
559 printf(" <<WARNING\n");
564 static QuickPrintSpace(status, name)
565 VolumeStatus *status;
568 double PartUsed =0.0;
570 printf("%-25.25s",name);
572 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
574 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
575 if (PartUsed > 90.0){
576 printf(" %4.0f%%<<", PartUsed);
579 else printf(" %4.0f%% ", PartUsed);
581 printf(" <<WARNING\n");
586 static char *AclToString(acl)
589 static char mydata[MAXSIZE];
590 char tstring[MAXSIZE];
594 if (acl->dfs) sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
595 else dfsstring[0] = '\0';
596 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
597 for(tp = acl->pluslist;tp;tp=tp->next) {
598 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
599 strcat(mydata, tstring);
601 for(tp = acl->minuslist;tp;tp=tp->next) {
602 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
603 strcat(mydata, tstring);
609 struct cmd_syndesc *as;
612 struct ViceIoctl blob;
614 struct cmd_item *ti, *ui;
618 int idf = getidf(as, parm_setacl_id);
621 if (as->parms[2].items) clear=1;
623 plusp = !(as->parms[3].items);
624 for(ti=as->parms[0].items; ti;ti=ti->next) {
625 blob.out_size = MAXSIZE;
627 blob.in = blob.out = space;
628 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
630 Die(errno, ti->data);
636 ta = ParseAcl(space);
637 if (!plusp && ta->dfs) {
639 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
641 "(you may specify \"null\" to revoke all rights, however)\n");
647 if (clear) ta = EmptyAcl(space);
648 else ta = ParseAcl(space);
649 CleanAcl(ta, ti->data);
650 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
653 fprintf(stderr, "%s: Missing second half of user/access pair.\n", pn);
657 rights = Convert(ui->next->data, ta->dfs, &rtype);
658 if (rtype == destroy && !ta->dfs) {
659 struct AclEntry *tlist;
661 tlist = (plusp ? ta->pluslist : ta->minuslist);
662 if (!FindList(tlist, ui->data))
665 if (rtype == deny && !ta->dfs) plusp = 0;
666 if (rtype == destroy && ta->dfs) rights = -1;
667 ChangeList(ta, plusp, ui->data, rights);
669 blob.in = AclToString(ta);
671 blob.in_size = 1+strlen(blob.in);
672 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
674 if (errno == EINVAL) {
676 static char *fsenv = 0;
678 fsenv = (char *)getenv("FS_EXPERT");
680 fprintf(stderr, "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n", pn);
683 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
684 "\nPossible reasons for this include:\n\n",
685 " -You may have specified an inappropriate combination of rights.\n",
686 " For example, some DFS-supported filesystems may not allow you to\n",
687 " drop the \"c\" right from \"user_obj\".\n\n",
688 " -A mask_obj may be required (it is likely required by the underlying\n",
689 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
690 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
691 " does not automatically create or update the mask_obj. Try setting\n",
692 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
693 " users or groups. You can do this with a single command, such as\n",
694 " \"fs sa mask_obj all user:somename read\"\n\n",
695 " -A specified user or group may not exist.\n\n",
696 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
697 " This is probably not allowed by the underlying file system.\n\n",
698 " -If you add a user or group to a DFS ACL, remember that it must be\n",
699 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
700 " may be local requirements on the format of the user or group name.\n",
701 " Check with your cell administrator.\n\n",
702 " -Or numerous other possibilities. It would be great if we could be more\n",
703 " precise about the actual problem, but for various reasons, this is\n",
704 " impractical via this interface. If you can't figure it out, you\n",
705 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
706 " whatever is provided). You may get better results. Good luck!\n\n",
707 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
710 fprintf(stderr, "%s: Invalid argument, possible reasons include:\n", pn);
711 fprintf(stderr, "\t-File not in AFS\n");
712 fprintf(stderr, "\t-Too many users on access control list\n");
713 fprintf(stderr, "\t-Tried to add non-existent user to access control list\n");
717 Die(errno, ti->data);
727 static CopyACLCmd(as)
728 struct cmd_syndesc *as;
731 struct ViceIoctl blob;
732 struct Acl *fa, *ta = 0;
734 struct cmd_item *ti, *ui;
738 int idf = getidf(as, parm_copyacl_id);
741 if (as->parms[2].items) clear=1;
743 blob.out_size = MAXSIZE;
745 blob.in = blob.out = space;
746 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
748 Die(errno, as->parms[0].items->data);
751 fa = ParseAcl(space);
752 CleanAcl(fa, as->parms[0].items->data);
753 for (ti=as->parms[1].items; ti;ti=ti->next) {
754 blob.out_size = MAXSIZE;
756 blob.in = blob.out = space;
757 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
759 Die(errno, ti->data);
765 if (clear) ta = EmptyAcl(space);
766 else ta = ParseAcl(space);
767 CleanAcl(ta, ti->data);
768 if (ta->dfs != fa->dfs) {
769 fprintf(stderr, "%s: incompatible file system types: acl not copied to %s; aborted\n", pn, ti->data);
774 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
775 fprintf(stderr, "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", pn, ti->data);
779 strcpy(ta->cell, fa->cell);
781 for (tp = fa->pluslist;tp;tp=tp->next)
782 ChangeList(ta, 1, tp->name, tp->rights);
783 for (tp = fa->minuslist;tp;tp=tp->next)
784 ChangeList(ta, 0, tp->name, tp->rights);
785 blob.in = AclToString(ta);
787 blob.in_size = 1+strlen(blob.in);
788 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
790 if (errno == EINVAL) {
791 fprintf(stderr, "%s: Invalid argument, possible reasons include:\n", pn);
792 fprintf(stderr, "\t-File not in AFS\n");
795 Die(errno, ti->data);
805 /* pioctl() call to get the cellname of a pathname */
806 static afs_int32 GetCell(fname, cellname)
807 char *fname, *cellname;
810 struct ViceIoctl blob;
813 blob.out_size = MAXCELLCHARS;
816 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
820 /* Check if a username is valid: If it contains only digits (or a
821 * negative sign), then it might be bad. We then query the ptserver
824 static BadName(aname, fname)
827 afs_int32 tc, code, id;
829 char cell[MAXCELLCHARS];
831 for (nm=aname; tc=*nm; nm++) {
832 /* all must be '-' or digit to be bad */
833 if (tc != '-' && (tc < '0' || tc > '9')) return 0;
836 /* Go to the PRDB and see if this all number username is valid */
837 code = GetCell(fname, cell);
840 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
841 code = pr_SNameToId(aname, &id);
844 /* 1=>Not-valid; 0=>Valid */
845 return ((!code && (id==ANONYMOUSID)) ? 1 : 0);
849 /* clean up an access control list of its bad entries; return 1 if we made
850 any changes to the list, and 0 otherwise */
851 static CleanAcl(aa, fname)
853 char *fname; /* The file name */
855 struct AclEntry *te, **le, *ne;
858 /* Don't correct DFS ACL's for now */
862 /* prune out bad entries */
863 changes = 0; /* count deleted entries */
865 for(te = aa->pluslist; te; te=ne) {
867 if (BadName(te->name,fname)) {
879 for(te = aa->minuslist; te; te=ne) {
881 if (BadName(te->name,fname)) {
896 /* clean up an acl to not have bogus entries */
897 static CleanACLCmd(as)
898 struct cmd_syndesc *as;
902 struct ViceIoctl blob;
908 SetDotDefault(&as->parms[0].items);
909 for(ti=as->parms[0].items; ti; ti=ti->next) {
910 blob.out_size = MAXSIZE;
913 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
915 Die(errno, ti->data);
921 ta = ParseAcl(space);
924 "%s: cleanacl is not supported for DFS access lists.\n",
930 changes = CleanAcl(ta, ti->data);
933 /* now set the acl */
934 blob.in=AclToString(ta);
935 blob.in_size = strlen(blob.in)+1;
937 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
939 if (errno == EINVAL) {
940 fprintf(stderr, "%s: Invalid argument, possible reasons include\n", pn);
941 fprintf(stderr, "%s: File not in vice or\n", pn);
942 fprintf(stderr, "%s: Too many users on access control list or\n", pn);
945 Die(errno, ti->data);
951 /* now list the updated acl */
952 printf("Access list for %s is now\n", ti->data);
954 if (!ta->dfs) printf("Normal rights:\n");
955 for(te = ta->pluslist;te;te=te->next) {
956 printf(" %s ", te->name);
957 PRights(te->rights, ta->dfs);
961 if (ta->nminus > 0) {
962 printf("Negative rights:\n");
963 for(te = ta->minuslist;te;te=te->next) {
964 printf(" %s ", te->name);
965 PRights(te->rights, ta->dfs);
969 if (ti->next) printf("\n");
972 printf("Access list for %s is fine.\n", ti->data);
978 static ListACLCmd(as)
979 struct cmd_syndesc *as;
983 struct ViceIoctl blob;
986 int idf = getidf(as, parm_listacl_id);
989 SetDotDefault(&as->parms[0].items);
990 for(ti=as->parms[0].items; ti; ti=ti->next) {
991 blob.out_size = MAXSIZE;
993 blob.in = blob.out = space;
994 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
996 Die(errno, ti->data);
1000 ta = ParseAcl(space);
1003 printf("Access list for %s is\n", ti->data);
1006 printf("DFS access list for %s is\n", ti->data);
1009 printf("DFS initial directory access list of %s is\n", ti->data);
1012 printf("DFS initial file access list of %s is\n", ti->data);
1016 printf(" Default cell = %s\n", ta->cell);
1018 if (ta->nplus > 0) {
1019 if (!ta->dfs) printf("Normal rights:\n");
1020 for(te = ta->pluslist;te;te=te->next) {
1021 printf(" %s ", te->name);
1022 PRights(te->rights, ta->dfs);
1026 if (ta->nminus > 0) {
1027 printf("Negative rights:\n");
1028 for(te = ta->minuslist;te;te=te->next) {
1029 printf(" %s ", te->name);
1030 PRights(te->rights, ta->dfs);
1034 if (ti->next) printf("\n");
1040 static FlushVolumeCmd(as)
1041 struct cmd_syndesc *as;
1044 struct ViceIoctl blob;
1045 struct cmd_item *ti;
1048 SetDotDefault(&as->parms[0].items);
1049 for(ti=as->parms[0].items; ti; ti=ti->next) {
1050 blob.in_size = blob.out_size = 0;
1051 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1053 fprintf(stderr, "Error flushing volume ");
1063 struct cmd_syndesc *as;
1066 struct ViceIoctl blob;
1067 struct cmd_item *ti;
1070 for(ti=as->parms[0].items; ti; ti=ti->next) {
1071 blob.in_size = blob.out_size = 0;
1072 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1074 if (errno == EMFILE) {
1075 fprintf(stderr, "%s: Can't flush active file %s\n", pn, ti->data);
1078 fprintf(stderr, "%s: Error flushing file ", pn);
1088 /* all this command does is repackage its args and call SetVolCmd */
1089 static SetQuotaCmd(as)
1090 struct cmd_syndesc *as;
1092 struct cmd_syndesc ts;
1094 /* copy useful stuff from our command slot; we may later have to reorder */
1095 bcopy(as, &ts, sizeof(ts)); /* copy whole thing */
1096 return SetVolCmd(&ts);
1099 static SetVolCmd(as)
1100 struct cmd_syndesc *as;
1103 struct ViceIoctl blob;
1104 struct cmd_item *ti;
1105 struct VolumeStatus *status;
1106 char *offmsg, *input;
1109 SetDotDefault(&as->parms[0].items);
1110 for(ti=as->parms[0].items; ti; ti=ti->next) {
1112 blob.out_size = MAXSIZE;
1113 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1116 status = (VolumeStatus *)space;
1117 status->MinQuota = status->MaxQuota = -1;
1118 offmsg = (char *) 0;
1119 if (as->parms[1].items) {
1120 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1122 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1127 if (as->parms[2].items) offmsg = as->parms[2].items->data;
1128 input = (char *)status + sizeof(*status);
1129 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1131 if (strlen(offmsg) >= VMSGSIZE) {
1132 fprintf(stderr, "%s: message must be shorter than %d characters\n",
1137 strcpy(input,offmsg);
1138 blob.in_size += strlen(offmsg);
1139 input += strlen(offmsg) + 1;
1141 else *(input++) = '\0';
1142 *(input++) = '\0'; /* Pad for old style volume "motd" */
1143 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1145 Die(errno, ti->data);
1152 static ExamineCmd(as)
1153 struct cmd_syndesc *as;
1156 struct ViceIoctl blob;
1157 struct cmd_item *ti;
1158 struct VolumeStatus *status;
1159 char *name, *offmsg;
1162 SetDotDefault(&as->parms[0].items);
1163 for(ti=as->parms[0].items; ti; ti=ti->next) {
1165 blob.out_size = MAXSIZE;
1168 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1170 Die(errno, ti->data);
1174 status = (VolumeStatus *)space;
1175 name = (char *)status + sizeof(*status);
1176 offmsg = name + strlen(name) + 1;
1177 PrintStatus(status, name, offmsg);
1182 static ListQuotaCmd(as)
1183 struct cmd_syndesc *as;
1186 struct ViceIoctl blob;
1187 struct cmd_item *ti;
1188 struct VolumeStatus *status;
1192 printf("%-25s%-10s%-10s%-7s%-11s\n",
1193 "Volume Name"," Quota", " Used", " %Used", " Partition");
1194 SetDotDefault(&as->parms[0].items);
1195 for(ti=as->parms[0].items; ti; ti=ti->next) {
1197 blob.out_size = MAXSIZE;
1200 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1202 Die(errno, ti->data);
1206 status = (VolumeStatus *)space;
1207 name = (char *)status + sizeof(*status);
1208 QuickPrintStatus(status, name);
1213 static WhereIsCmd(as)
1214 struct cmd_syndesc *as;
1217 struct ViceIoctl blob;
1218 struct cmd_item *ti;
1224 SetDotDefault(&as->parms[0].items);
1225 for(ti=as->parms[0].items; ti; ti=ti->next) {
1227 blob.out_size = MAXSIZE;
1230 bzero(space, sizeof(space));
1231 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1233 Die(errno, ti->data);
1237 hosts = (afs_int32 *) space;
1238 printf("File %s is on host%s ", ti->data, (hosts[0] && !hosts[1]) ? "": "s");
1239 for(j=0; j<MAXHOSTS; j++) {
1240 if (hosts[j] == 0) break;
1241 tp = hostutil_GetNameByINet(hosts[j]);
1250 static DiskFreeCmd(as)
1251 struct cmd_syndesc *as;
1254 struct ViceIoctl blob;
1255 struct cmd_item *ti;
1257 struct VolumeStatus *status;
1260 printf("%-25s%-10s%-10s%-10s%-6s\n",
1261 "Volume Name"," kbytes", " used", " avail", " %used");
1262 SetDotDefault(&as->parms[0].items);
1263 for(ti=as->parms[0].items; ti; ti=ti->next) {
1265 blob.out_size = MAXSIZE;
1268 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1270 Die(errno, ti->data);
1274 status = (VolumeStatus *)space;
1275 name = (char *)status + sizeof(*status);
1276 QuickPrintSpace(status, name);
1282 struct cmd_syndesc *as;
1285 struct ViceIoctl blob;
1286 struct cmd_item *ti;
1288 struct VolumeStatus *status;
1291 SetDotDefault(&as->parms[0].items);
1292 for(ti=as->parms[0].items; ti; ti=ti->next) {
1294 blob.out_size = MAXSIZE;
1297 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1299 Die(errno, ti->data);
1303 status = (VolumeStatus *)space;
1304 if (status->MaxQuota) quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1305 else quotaPct = 0.0;
1306 printf("%2.0f%% of quota used.\n", quotaPct);
1311 static ListMountCmd(as)
1312 struct cmd_syndesc *as;
1315 struct ViceIoctl blob;
1316 struct cmd_item *ti;
1317 char orig_name[1024]; /*Original name, may be modified*/
1318 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1319 char parent_dir[1024]; /*Parent directory of true name*/
1320 char *last_component; /*Last component of true name*/
1321 struct stat statbuff; /*Buffer for status info*/
1322 int link_chars_read; /*Num chars read in readlink()*/
1323 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1326 for(ti=as->parms[0].items; ti; ti=ti->next) {
1329 sprintf(orig_name, "%s%s",
1330 (ti->data[0] == '/') ? "" : "./",
1333 if (lstat(orig_name, &statbuff) < 0) {
1334 /* if lstat fails, we should still try the pioctl, since it
1335 may work (for example, lstat will fail, but pioctl will
1336 work if the volume of offline (returning ENODEV). */
1337 statbuff.st_mode = S_IFDIR; /* lie like pros */
1341 * The lstat succeeded. If the given file is a symlink, substitute
1342 * the file name with the link name.
1344 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1347 * Read name of resolved file.
1349 link_chars_read = readlink(orig_name, true_name, 1024);
1350 if (link_chars_read <= 0) {
1351 fprintf(stderr, "%s: Can't read target name for '%s' symbolic link!\n",
1358 * Add a trailing null to what was read, bump the length.
1360 true_name[link_chars_read++] = 0;
1363 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1364 * have to create a full pathname using the original name and the
1365 * relative symlink name. Find the rightmost slash in the original
1366 * name (we know there is one) and splice in the symlink value.
1368 if (true_name[0] != '/') {
1369 last_component = (char *) rindex(orig_name, '/');
1370 strcpy(++last_component, true_name);
1371 strcpy(true_name, orig_name);
1375 strcpy(true_name, orig_name);
1378 * Find rightmost slash, if any.
1380 last_component = (char *) rindex(true_name, '/');
1381 if (last_component) {
1383 * Found it. Designate everything before it as the parent directory,
1384 * everything after it as the final component.
1386 strncpy(parent_dir, true_name, last_component - true_name);
1387 parent_dir[last_component - true_name] = 0;
1388 last_component++; /*Skip the slash*/
1392 * No slash appears in the given file name. Set parent_dir to the current
1393 * directory, and the last component as the given name.
1395 strcpy(parent_dir, ".");
1396 last_component = true_name;
1399 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1400 fprintf(stderr, "%s: you may not use '.' or '..' as the last component\n", pn);
1401 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n", pn);
1406 blob.in = last_component;
1407 blob.in_size = strlen(last_component)+1;
1408 blob.out_size = MAXSIZE;
1410 bzero(space, MAXSIZE);
1412 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1415 printf("'%s' is a %smount point for volume '%s'\n",
1417 (thru_symlink ? "symbolic link, leading to a " : ""),
1421 if (errno == EINVAL) {
1422 fprintf(stderr, "'%s' is not a mount point.\n",
1426 Die(errno, (ti->data ? ti->data : parent_dir));
1434 static MakeMountCmd(as)
1435 struct cmd_syndesc *as;
1438 char *cellName, *volName, *tmpName;
1439 struct afsconf_cell info;
1440 struct vldbentry vldbEntry;
1441 struct ViceIoctl blob;
1447 if (as->parms[5].items && !as->parms[2].items) {
1448 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1453 if (as->parms[2].items) /* cell name specified */
1454 cellName = as->parms[2].items->data;
1456 cellName = (char *) 0;
1457 volName = as->parms[1].items->data;
1459 if (strlen(volName) >= 64) {
1460 fprintf(stderr, "%s: volume name too long (length must be < 64 characters)\n", pn);
1464 /* Check for a cellname in the volume specification, and complain
1465 * if it doesn't match what was specified with -cell */
1466 if (tmpName = index(volName, ':')) {
1469 if (strcasecmp(cellName,volName)) {
1470 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1475 volName = ++tmpName;
1478 if (!InAFS(Parent(as->parms[0].items->data))) {
1479 fprintf(stderr, "%s: mount points must be created within the AFS file system\n", pn);
1485 blob.out_size = MAXSIZE;
1487 code = pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME, &blob, 1);
1490 code = GetCellName(cellName?cellName:space, &info);
1494 if (!(as->parms[4].items)) {
1495 /* not fast, check which cell the mountpoint is being created in */
1496 /* not fast, check name with VLDB */
1497 code = VLDBInit(1, &info);
1499 /* make the check. Don't complain if there are problems with init */
1500 code = ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, &vldbEntry);
1501 if (code == VL_NOENT) {
1502 fprintf(stderr, "%s: warning, volume %s does not exist in cell %s.\n",
1503 pn, volName, cellName ? cellName : space);
1508 if (as->parms[3].items) /* if -rw specified */
1513 /* cellular mount point, prepend cell prefix */
1514 strcat(space, info.name);
1517 strcat(space, volName); /* append volume name */
1518 strcat(space, "."); /* stupid convention; these end with a period */
1519 code = symlink(space, as->parms[0].items->data);
1521 Die(errno, as->parms[0].items->data);
1528 * Delete AFS mount points. Variables are used as follows:
1529 * tbuffer: Set to point to the null-terminated directory name of the mount point
1530 * (or ``.'' if none is provided)
1531 * tp: Set to point to the actual name of the mount point to nuke.
1533 static RemoveMountCmd(as)
1534 struct cmd_syndesc *as;
1537 struct ViceIoctl blob;
1538 struct cmd_item *ti;
1540 char lsbuffer[1024];
1544 for(ti=as->parms[0].items; ti; ti=ti->next) {
1546 tp = (char *) rindex(ti->data, '/');
1548 strncpy(tbuffer, ti->data, code=tp-ti->data); /* the dir name */
1550 tp++; /* skip the slash */
1553 strcpy(tbuffer, ".");
1557 blob.in_size = strlen(tp)+1;
1558 blob.out = lsbuffer;
1559 blob.out_size = sizeof(lsbuffer);
1560 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1562 if (errno == EINVAL) {
1563 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn, ti->data);
1566 Die(errno, ti->data);
1569 continue; /* don't bother trying */
1573 blob.in_size = strlen(tp)+1;
1574 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1576 Die(errno, ti->data);
1586 static CheckServersCmd(as)
1587 struct cmd_syndesc *as;
1590 struct ViceIoctl blob;
1596 struct afsconf_cell info;
1597 struct chservinfo checkserv;
1599 bzero(&checkserv,sizeof(struct chservinfo));
1600 blob.in_size=sizeof(struct chservinfo);
1601 blob.in=(caddr_t)&checkserv;
1603 blob.out_size = MAXSIZE;
1605 bzero(space, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1607 /* prepare flags for checkservers command */
1608 temp = 2; /* default to checking local cell only */
1609 if (as->parms[2].items) temp |= 1; /* set fast flag */
1610 if (as->parms[1].items) temp &= ~2; /* turn off local cell check */
1612 checkserv.magic = 0x12345678; /* XXX */
1613 checkserv.tflags=temp;
1615 /* now copy in optional cell name, if specified */
1616 if (as->parms[0].items) {
1617 code = GetCellName(as->parms[0].items->data, &info);
1621 strcpy(checkserv.tbuffer,info.name);
1622 checkserv.tsize=strlen(info.name)+1;
1625 strcpy(checkserv.tbuffer,"\0");
1629 if(as->parms[3].items) {
1630 checkserv.tinterval=atol(as->parms[3].items->data);
1633 if(checkserv.tinterval<0) {
1634 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
1635 checkserv.tinterval=0;
1637 else if(checkserv.tinterval> 600) {
1638 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1639 checkserv.tinterval=600; /* 10 min max interval */
1643 checkserv.tinterval = -1; /* don't change current interval */
1646 code = pioctl(0, VIOCCKSERV, &blob, 1);
1648 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1649 printf("Must be root to change -interval\n");
1655 bcopy(space, &temp, sizeof(afs_int32));
1656 if (checkserv.tinterval >= 0) {
1657 if (checkserv.tinterval > 0)
1658 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1659 checkserv.tinterval, temp);
1661 printf("The current down server probe interval is %d secs\n", temp);
1665 printf("All servers are running.\n");
1668 printf("These servers unavailable due to network or server problems: ");
1670 bcopy(space + j*sizeof(afs_int32), &temp, sizeof(afs_int32));
1671 if (temp == 0) break;
1672 tp = hostutil_GetNameByINet(temp);
1681 static MessagesCmd(as)
1682 struct cmd_syndesc *as;
1685 struct ViceIoctl blob;
1688 struct gaginfo gagflags;
1689 struct cmd_item *show;
1691 bzero (&gagflags, sizeof(struct gaginfo));
1692 blob.in_size = sizeof(struct gaginfo);
1693 blob.in = (caddr_t) &gagflags;
1694 blob.out_size = MAXSIZE;
1696 bzero(space, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1698 if (show = as->parms[0].items) {
1699 if (!strcasecmp (show->data, "user"))
1700 gagflags.showflags |= GAGUSER;
1701 else if (!strcasecmp (show->data, "console"))
1702 gagflags.showflags |= GAGCONSOLE;
1703 else if (!strcasecmp (show->data, "all"))
1704 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1705 else if (!strcasecmp (show->data, "none"))
1709 "unrecognized flag %s: must be in {user,console,all,none}\n",
1718 code = pioctl(0, VIOC_GAG, &blob, 1);
1727 static CheckVolumesCmd(as)
1728 struct cmd_syndesc *as;
1731 struct ViceIoctl blob;
1735 code = pioctl(0, VIOCCKBACK, &blob, 1);
1741 printf("All volumeID/name mappings checked.\n");
1745 static SetCacheSizeCmd(as)
1746 struct cmd_syndesc *as;
1749 struct ViceIoctl blob;
1752 if (!as->parms[0].items && !as->parms[1].items) {
1753 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
1756 if (as->parms[0].items) {
1757 code = util_GetInt32(as->parms[0].items->data, &temp);
1759 fprintf(stderr, "%s: bad integer specified for cache size.\n", pn);
1765 blob.in = (char *) &temp;
1766 blob.in_size = sizeof(afs_int32);
1768 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
1770 if (errno == EROFS) {
1771 printf("'fs setcache' not allowed on memory cache based cache managers.\n");
1774 Die(errno, (char *) 0);
1779 printf("New cache size set.\n");
1783 #define MAXGCSIZE 16
1784 static GetCacheParmsCmd(as)
1785 struct cmd_syndesc *as;
1788 struct ViceIoctl blob;
1789 afs_int32 parms[MAXGCSIZE];
1791 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
1792 blob.in = (char *) 0;
1794 blob.out_size = sizeof(parms);
1795 blob.out = (char *) parms;
1796 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
1798 Die(errno, (char *) 0);
1801 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
1802 parms[1], parms[0]);
1803 if (parms[1] > parms[0])
1804 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
1808 static ListCellsCmd(as)
1809 struct cmd_syndesc *as;
1815 struct ViceIoctl blob;
1818 resolve = !(as->parms[0].items); /* -numeric */
1822 bcopy(&i, tp, sizeof(afs_int32));
1823 blob.out_size = MAXSIZE;
1824 blob.in_size = sizeof(afs_int32);
1827 code = pioctl(0, VIOCGETCELL, &blob, 1);
1829 if (errno == EDOM) break; /* done with the list */
1834 printf("Cell %s on hosts", tp+MAXCELLHOSTS*sizeof(afs_int32));
1835 for(j=0; j < MAXCELLHOSTS; j++) {
1837 char *name, tbuffer[20];
1839 bcopy(tp + j*sizeof(afs_int32), &addr, sizeof(afs_int32));
1840 if (addr == 0) break;
1843 name = hostutil_GetNameByINet(addr);
1847 sprintf(tbuffer, "%d.%d.%d.%d",
1848 (addr>>24) & 0xff, (addr>>16) & 0xff,
1849 (addr>>8) & 0xff, addr & 0xff);
1852 printf(" %s", name);
1859 static NewCellCmd(as)
1860 struct cmd_syndesc *as;
1862 afs_int32 code, linkedstate=0, size=0, *lp;
1863 struct ViceIoctl blob;
1864 struct cmd_item *ti;
1865 char *tp, *cellname=0;
1866 struct hostent *thp;
1867 afs_int32 fsport = 0, vlport = 0;
1868 afs_int32 magic, scount; /* Number of servers to pass in pioctl call */
1871 * With the NEWCELL pioctl call, 3.4 clients take an array of
1872 * MAXHOSTS (13) servers while 3.5 clients take an array of
1873 * MAXCELLHOSTS (8) servers. To determine which we are talking to,
1874 * do a GETCELL pioctl and pass it a magic number. If an array of
1875 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
1878 lp = (afs_int32 *)tp;
1879 *lp++ = 0; /* first cell entry */
1880 *lp = 0x12345678; /* magic */
1881 blob.out_size = MAXSIZE;
1882 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
1885 code = pioctl(0, VIOCGETCELL, &blob, 1);
1891 cellname = tp + MAXCELLHOSTS*sizeof(afs_int32);
1892 scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
1894 /* Now setup and do the NEWCELL pioctl call */
1895 bzero(space, (scount+1) * sizeof(afs_int32));
1897 lp = (afs_int32 *)tp;
1899 tp += sizeof(afs_int32);
1900 for(ti=as->parms[1].items; ti; ti=ti->next) {
1901 thp = hostutil_GetHostByName(ti->data);
1903 fprintf(stderr, "%s: Host %s not found in host table, skipping it.\n",
1907 bcopy(thp->h_addr, tp, sizeof(afs_int32));
1908 tp += sizeof(afs_int32);
1911 if (as->parms[2].items) {
1913 * Link the cell, for the purposes of volume location, to the specified
1916 cellname = as->parms[2].items->data;
1919 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
1920 if (as->parms[3].items) {
1921 code = util_GetInt32(as->parms[3].items->data, &vlport);
1923 fprintf(stderr, "%s: bad integer specified for the fileserver port.\n", pn);
1927 if (as->parms[4].items) {
1928 code = util_GetInt32(as->parms[4].items->data, &fsport);
1930 fprintf(stderr, "%s: bad integer specified for the vldb server port.\n", pn);
1935 tp = (char *)(space + (scount+1) *sizeof(afs_int32));
1936 lp = (afs_int32 *)tp;
1940 strcpy(space + ((scount+4) * sizeof(afs_int32)), as->parms[0].items->data);
1941 size = ((scount+4) * sizeof(afs_int32))
1942 + strlen(as->parms[0].items->data)
1944 tp = (char *)(space + size);
1946 strcpy(tp, cellname);
1947 size += strlen(cellname) + 1;
1949 blob.in_size = size;
1952 code = pioctl(0, VIOCNEWCELL, &blob, 1);
1960 static WhichCellCmd(as)
1961 struct cmd_syndesc *as;
1964 struct cmd_item *ti;
1966 char cell[MAXCELLCHARS];
1968 SetDotDefault(&as->parms[0].items);
1969 for (ti=as->parms[0].items; ti; ti=ti->next) {
1970 code = GetCell(ti->data, cell);
1972 if (errno == ENOENT)
1973 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
1975 Die(code, ti->data);
1980 printf("File %s lives in cell '%s'\n", ti->data, cell);
1985 static WSCellCmd(as)
1986 struct cmd_syndesc *as;
1989 struct ViceIoctl blob;
1992 blob.in = (char *) 0;
1993 blob.out_size = MAXSIZE;
1996 code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1);
1998 Die(errno, (char *) 0);
2002 printf("This workstation belongs to cell '%s'\n", space);
2007 static PrimaryCellCmd(as)
2008 struct cmd_syndesc *as;
2010 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2015 static MonitorCmd(as)
2016 struct cmd_syndesc *as;
2019 struct ViceIoctl blob;
2020 struct cmd_item *ti;
2022 struct hostent *thp;
2026 ti = as->parms[0].items;
2030 if (!strcmp(ti->data, "off"))
2031 hostAddr = 0xffffffff;
2033 thp = hostutil_GetHostByName(ti->data);
2035 if (!strcmp(ti->data, "localhost")) {
2036 fprintf(stderr, "localhost not in host table, assuming 127.0.0.1\n");
2037 hostAddr = htonl(0x7f000001);
2040 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2044 else bcopy(thp->h_addr, &hostAddr, sizeof(afs_int32));
2048 hostAddr = 0; /* means don't set host */
2049 setp = 0; /* aren't setting host */
2052 /* now do operation */
2053 blob.in_size = sizeof(afs_int32);
2054 blob.out_size = sizeof(afs_int32);
2055 blob.in = (char *) &hostAddr;
2056 blob.out = (char *) &hostAddr;
2057 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2063 printf("%s: new monitor host set.\n", pn);
2066 /* now decode old address */
2067 if (hostAddr == 0xffffffff) {
2068 printf("Cache monitoring is currently disabled.\n");
2071 tp = hostutil_GetNameByINet(hostAddr);
2072 printf("Using host %s for monitor services.\n", tp);
2078 static SysNameCmd(as)
2079 struct cmd_syndesc *as;
2082 struct ViceIoctl blob;
2083 struct cmd_item *ti;
2084 char *input = space;
2087 ti = as->parms[0].items;
2091 blob.out_size = MAXSIZE;
2092 blob.in_size = sizeof(afs_int32);
2093 bcopy(&setp, input, sizeof(afs_int32));
2094 input += sizeof(afs_int32);
2096 strcpy(input, ti->data);
2097 blob.in_size += strlen(ti->data) + 1;
2098 input += strlen(ti->data);
2101 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2107 printf("%s: new sysname set.\n", pn);
2111 bcopy(input, &setp, sizeof(afs_int32));
2112 input += sizeof(afs_int32);
2114 fprintf(stderr, "No sysname name value was found\n");
2117 printf("Current sysname is '%s'\n", input);
2121 static char *exported_types[] = {"null", "nfs", ""};
2122 static ExportAfsCmd(as)
2123 struct cmd_syndesc *as;
2126 struct ViceIoctl blob;
2127 struct cmd_item *ti;
2128 int export=0, type=0, mode = 0, exp = 0, exportcall, pwsync=0, smounts=0;
2130 ti = as->parms[0].items;
2131 if (strcmp(ti->data, "nfs") == 0) type = 0x71; /* NFS */
2133 fprintf(stderr, "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2136 ti = as->parms[1].items;
2138 if (strcmp(ti->data, "on") == 0) export = 3;
2139 else if (strcmp(ti->data, "off") == 0) export = 2;
2141 fprintf(stderr, "Illegal argument %s\n", ti->data);
2146 if (ti = as->parms[2].items) { /* -noconvert */
2147 if (strcmp(ti->data, "on") == 0) mode = 2;
2148 else if (strcmp(ti->data, "off") == 0) mode = 3;
2150 fprintf(stderr, "Illegal argument %s\n", ti->data);
2154 if (ti = as->parms[3].items) { /* -uidcheck */
2155 if (strcmp(ti->data, "on") == 0) pwsync = 3;
2156 else if (strcmp(ti->data, "off") == 0) pwsync = 2;
2158 fprintf(stderr, "Illegal argument %s\n", ti->data);
2162 if (ti = as->parms[4].items) { /* -submounts */
2163 if (strcmp(ti->data, "on") == 0) smounts = 3;
2164 else if (strcmp(ti->data, "off") == 0) smounts = 2;
2166 fprintf(stderr, "Illegal argument %s\n", ti->data);
2170 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2173 blob.in = (char *) &exportcall;
2174 blob.in_size = sizeof(afs_int32);
2175 blob.out = (char *) &exportcall;
2176 blob.out_size = sizeof(afs_int32);
2177 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2179 if (errno == ENODEV) {
2180 fprintf(stderr, "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
2188 if (exportcall & 1) {
2189 printf("'%s' translator is enabled with the following options:\n",
2190 exported_types[type]);
2191 printf("\tRunning in %s mode\n",
2192 (exportcall & 2 ? "strict unix"
2193 : "convert owner mode bits to world/other"));
2194 printf("\tRunning in %s mode\n",
2195 (exportcall & 4 ? "strict 'passwd sync'"
2196 : "no 'passwd sync'"));
2198 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs"
2199 : "Only mounts to /afs allowed"));
2202 printf("'%s' translator is disabled\n", exported_types[type]);
2208 static GetCellCmd(as)
2209 struct cmd_syndesc *as;
2212 struct ViceIoctl blob;
2213 struct afsconf_cell info;
2214 struct cmd_item *ti;
2221 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2222 for(ti=as->parms[0].items; ti; ti=ti->next) {
2224 blob.out_size = sizeof(args);
2225 blob.out = (caddr_t) &args;
2226 code = GetCellName(ti->data, &info);
2231 blob.in_size = 1+strlen(info.name);
2232 blob.in = info.name;
2233 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2235 if (errno == ENOENT)
2236 fprintf(stderr, "%s: the cell named '%s' does not exist\n", pn, info.name);
2238 Die(errno, info.name);
2242 printf("Cell %s status: ", info.name);
2244 if (args.stat & 1) printf("primary ");
2246 if (args.stat & 2) printf("no setuid allowed");
2247 else printf("setuid allowed");
2248 if (args.stat & 4) printf(", using old VLDB");
2254 static SetCellCmd(as)
2255 struct cmd_syndesc *as;
2258 struct ViceIoctl blob;
2259 struct afsconf_cell info;
2260 struct cmd_item *ti;
2268 /* Check arguments. */
2269 if (as->parms[1].items && as->parms[2].items) {
2270 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2274 /* figure stuff to set */
2278 if (! as->parms[1].items) args.stat |= 2; /* default to -nosuid */
2280 /* set stat for all listed cells */
2281 for(ti=as->parms[0].items; ti; ti=ti->next) {
2283 code = GetCellName(ti->data, &info);
2288 strcpy(args.cname, info.name);
2289 blob.in_size = sizeof(args);
2290 blob.in = (caddr_t) &args;
2292 blob.out = (caddr_t) 0;
2293 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2295 Die(errno, info.name); /* XXX added cell name to Die() call */
2302 static GetCellName(cellName, info)
2304 struct afsconf_cell *info;
2306 struct afsconf_dir *tdir;
2309 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2311 fprintf(stderr, "Could not process files in configuration directory (%s).\n",
2312 AFSDIR_CLIENT_ETC_DIRPATH);
2316 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2318 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2319 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2327 static VLDBInit(noAuthFlag, info)
2329 struct afsconf_cell *info;
2332 struct ktc_principal sname;
2333 struct ktc_token ttoken;
2335 struct rx_securityClass *sc;
2336 struct rx_connection *serverconns[VLDB_MAXSERVERS];
2341 fprintf(stderr, "%s: could not initialize rx.\n", pn);
2345 rx_SetRxDeadTime(50);
2346 if (!noAuthFlag) { /* we don't need tickets for null */
2347 strcpy(sname.cell, info->name);
2348 sname.instance[0] = 0;
2349 strcpy(sname.name, "afs");
2350 code = ktc_GetToken(&sname,&ttoken, sizeof(ttoken), (char *)0);
2352 fprintf(stderr, "%s: Could not get afs tokens, running unauthenticated.\n", pn);
2357 if (ttoken.kvno >= 0 && ttoken.kvno <= 255) scIndex = 2; /* kerberos */
2359 fprintf(stderr, "%s: funny kvno (%d) in ticket, proceeding\n",
2365 else scIndex = 0; /* don't authenticate */
2368 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
2374 sc = (struct rx_securityClass *)
2375 rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
2376 ttoken.kvno, ttoken.ticketLen,
2380 if (info->numServers > VLDB_MAXSERVERS) {
2381 fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
2382 pn, info->numServers, VLDB_MAXSERVERS);
2385 bzero(serverconns, sizeof(serverconns));
2386 for (i = 0;i<info->numServers;i++)
2387 serverconns[i] = rx_NewConnection(info->hostAddr[i].sin_addr.s_addr,
2388 info->hostAddr[i].sin_port, USER_SERVICE_ID,
2391 code = ubik_ClientInit(serverconns, &uclient);
2394 fprintf(stderr, "%s: ubik client init failed.\n", pn);
2400 static struct ViceIoctl gblob;
2401 static int debug = 0;
2403 * here follow some routines in suport of the setserverprefs and
2404 * getserverprefs commands. They are:
2405 * SetPrefCmd "top-level" routine
2406 * addServer adds a server to the list of servers to be poked into the
2407 * kernel. Will poke the list into the kernel if it threatens
2409 * pokeServers pokes the existing list of servers and ranks into the kernel
2410 * GetPrefCmd reads the Cache Manager's current list of server ranks
2414 * returns -1 if error message printed,
2416 * errno value if error and no error message printed
2418 static pokeServers()
2422 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2423 if (code && (errno == EINVAL)) {
2424 struct setspref *ssp;
2425 ssp = (struct setspref *)gblob.in;
2426 if (!(ssp->flags & DBservers)) {
2427 gblob.in = (void *) &(ssp->servers[0]);
2428 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2429 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2430 return code ? errno : 0;
2433 "This cache manager does not support VL server preferences.\n");
2437 return code ? errno : 0;
2441 * returns -1 if error message printed,
2443 * errno value if error and no error message printed
2445 static addServer(name, rank)
2450 struct setspref *ssp;
2452 struct hostent *thostent;
2458 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2460 #define MAXUSHORT ((unsigned short) ~0)
2464 thostent = hostutil_GetHostByName(name);
2466 fprintf(stderr, "%s: couldn't resolve name.\n", name);
2470 ssp = (struct setspref *)(gblob.in);
2472 for (t = 0; thostent->h_addr_list[t]; t++) {
2473 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
2474 code = pokeServers();
2475 if (code) error = code;
2476 ssp->num_servers = 0;
2479 sp = (struct spref *) (gblob.in + gblob.in_size);
2480 bcopy (thostent->h_addr_list[t], &(sp->server.s_addr), sizeof(afs_uint32));
2481 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2482 gblob.in_size += sizeof(struct spref);
2486 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
2487 name,sp->rank,sp->server.s_addr);
2494 static SetPrefCmd(as)
2495 struct cmd_syndesc *as;
2499 struct cmd_item *ti;
2502 struct setspref *ssp;
2503 int error = 0; /* -1 means error message printed,
2504 * >0 means errno value for unprinted message */
2506 ssp = (struct setspref *)space;
2508 ssp->num_servers = 0;
2509 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2512 gblob.out_size = MAXSIZE;
2516 fprintf(stderr, "Permission denied: requires root access.\n");
2520 ti = as->parms[2].items; /* -file */
2522 if (debug) fprintf(stderr, "opening file %s\n",ti->data);
2523 if (!(infd = fopen(ti->data,"r"))) {
2528 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2529 code = addServer(name, (unsigned short) rank);
2530 if (code) error = code;
2535 ti = as->parms[3].items; /* -stdin */
2537 while (scanf("%79s%ld", name, &rank) != EOF) {
2538 code = addServer(name, (unsigned short) rank);
2539 if (code) error = code;
2543 for (ti = as->parms[0].items;ti;ti=ti->next) { /* list of servers, ranks */
2548 code = addServer(ti->data, (unsigned short) atol(ti->next->data));
2549 if (code) error = code;
2551 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
2555 code = pokeServers();
2556 if (code) error = code;
2558 printf("now working on vlservers, code=%d\n",code);
2560 ssp = (struct setspref *)space;
2561 ssp->flags = DBservers;
2562 ssp->num_servers = 0;
2563 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2566 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
2571 code = addServer(ti->data, (unsigned short) atol(ti->next->data));
2572 if (code) error = code;
2574 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
2579 if (as->parms[1].items) {
2581 printf("now poking vlservers\n");
2582 code = pokeServers();
2583 if (code) error = code;
2589 return error ? 1 : 0;
2594 static GetPrefCmd(as)
2595 struct cmd_syndesc *as;
2598 struct cmd_item *ti;
2599 char *name, tbuffer[20];
2600 afs_int32 rank,addr;
2604 struct ViceIoctl blob;
2605 struct sprefrequest *in;
2606 struct sprefinfo *out;
2609 ti = as->parms[0].items; /* -file */
2611 if (debug) fprintf(stderr, "opening file %s\n",ti->data);
2612 if (!(outfd = freopen(ti->data,"w",stdout))) {
2618 ti = as->parms[1].items; /* -numeric */
2620 ti = as->parms[2].items; /* -vlservers */
2621 vlservers |= (ti ? DBservers : 0);
2622 /* ti = as->parms[3].items; -cell */
2624 in = (struct sprefrequest *)space;
2628 blob.in_size=sizeof(struct sprefrequest);
2629 blob.in = (char *)in;
2631 blob.out_size = MAXSIZE;
2633 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct spref);
2634 in->flags = vlservers;
2636 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
2638 perror("getserverprefs pioctl");
2642 out = (struct sprefinfo *) blob.out;
2644 for (i=0;i<out->num_servers;i++) {
2646 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
2649 addr = ntohl(out->servers[i].server.s_addr);
2650 sprintf(tbuffer, "%d.%d.%d.%d",
2651 (addr>>24) & 0xff, (addr>>16) & 0xff,
2652 (addr>>8) & 0xff, addr & 0xff);
2655 printf("%-50s %5u\n",name,out->servers[i].rank);
2658 in->offset = out->next_offset;
2659 } while (out->next_offset > 0);
2664 static StoreBehindCmd(as)
2665 struct cmd_syndesc *as;
2668 struct ViceIoctl blob;
2669 struct cmd_item *ti;
2670 struct sbstruct tsb, tsb2;
2676 tsb.sb_thisfile = -1;
2677 ti=as->parms[0].items; /* -kbytes */
2679 if (!as->parms[1].items) {
2680 fprintf(stderr, "%s: you must specify -files with -kbytes.\n", pn);
2683 tsb.sb_thisfile = strtol(ti->data,&t,10) * 1024;
2684 if ((tsb.sb_thisfile < 0) || (t != ti->data+strlen(ti->data))) {
2685 fprintf(stderr, "%s: %s must be 0 or a positive number.\n",
2691 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
2692 ti=as->parms[2].items; /* -allfiles */
2694 allfiles = strtol(ti->data,&t,10) * 1024;
2695 if ((allfiles < 0) || (t != ti->data+strlen(ti->data))) {
2696 fprintf(stderr, "%s: %s must be 0 or a positive number.\n",
2702 /* -verbose or -file only or no options */
2703 if (as->parms[3].items ||
2704 (as->parms[1].items && !as->parms[0].items) ||
2705 (!as->parms[0].items && !as->parms[1].items && !as->parms[2].items))
2708 blob.in = (char *)&tsb;
2709 blob.out = (char *)&tsb2;
2710 blob.in_size = blob.out_size = sizeof(struct sbstruct);
2711 bzero (&tsb2, sizeof(tsb2));
2713 /* once per -file */
2714 for (ti=as->parms[1].items; ti; ti=ti->next) {
2715 /* Do this solely to see if the file is there */
2716 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
2718 Die(errno, ti->data);
2723 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
2725 Die(errno, ti->data);
2730 if (verbose && (blob.out_size == sizeof(tsb2))) {
2731 if (tsb2.sb_thisfile == -1) {
2732 fprintf(stdout, "Will store %s according to default.\n",
2737 "Will store up to %d kbytes of %s asynchronously.\n",
2738 (tsb2.sb_thisfile/1024), ti->data);
2743 /* If no files - make at least one pioctl call, or
2744 * set the allfiles default if we need to.
2746 if (!as->parms[1].items || (allfiles != -1)) {
2747 tsb.sb_default = allfiles;
2748 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
2750 Die(errno, ((allfiles == -1)?0:"-allfiles"));
2755 /* Having no arguments also reports the default store asynchrony */
2756 if (verbose && (blob.out_size == sizeof(tsb2))) {
2757 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
2758 (tsb2.sb_default/1024));
2764 #include "AFS_component_version_number.c"
2771 struct cmd_syndesc *ts;
2773 #ifdef AFS_AIX32_ENV
2775 * The following signal action for AIX is necessary so that in case of a
2776 * crash (i.e. core is generated) we can include the user's data section
2777 * in the core dump. Unfortunately, by default, only a partial core is
2778 * generated which, in many cases, isn't too useful.
2780 struct sigaction nsa;
2782 sigemptyset(&nsa.sa_mask);
2783 nsa.sa_handler = SIG_DFL;
2784 nsa.sa_flags = SA_FULLDUMP;
2785 sigaction(SIGSEGV, &nsa, NULL);
2788 /* try to find volume location information */
2789 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0, "get client network interface addresses");
2790 cmd_CreateAlias(ts, "gc");
2792 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0, "set client network interface addresses");
2793 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "client network interfaces");
2794 cmd_CreateAlias(ts, "sc");
2796 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks");
2797 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
2798 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
2799 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
2800 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
2801 cmd_CreateAlias(ts, "sp");
2803 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks");
2804 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
2805 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
2806 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
2807 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
2808 cmd_CreateAlias(ts, "gp");
2810 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
2811 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2812 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
2813 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
2814 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
2815 parm_setacl_id = ts->nParms;
2816 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
2817 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
2818 cmd_CreateAlias(ts, "sa");
2820 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list");
2821 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2822 parm_listacl_id = ts->nParms;
2823 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
2824 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
2825 cmd_CreateAlias(ts, "la");
2827 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list");
2828 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2830 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list");
2831 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
2832 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
2833 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
2834 parm_copyacl_id = ts->nParms;
2835 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
2836 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
2838 cmd_CreateAlias(ts, "ca");
2840 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
2841 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2842 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0, "flush mount symlink from cache");
2843 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2845 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
2846 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2847 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
2849 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
2850 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
2852 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
2853 cmd_CreateAlias(ts, "sv");
2855 ts = cmd_CreateSyntax("messages", MessagesCmd, 0, "control Cache Manager messages");
2856 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
2858 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display volume status");
2859 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2860 cmd_CreateAlias(ts, "lv");
2861 cmd_CreateAlias(ts, "listvol");
2863 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
2864 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2865 cmd_CreateAlias(ts, "lq");
2867 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage");
2868 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2869 cmd_CreateAlias(ts, "df");
2871 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
2872 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2874 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
2875 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2877 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
2878 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
2879 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
2880 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
2881 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
2882 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
2888 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
2892 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
2893 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
2895 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers");
2896 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
2897 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
2898 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
2899 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
2901 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings");
2902 cmd_CreateAlias(ts, "checkbackups");
2905 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size");
2906 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
2907 cmd_CreateAlias(ts, "cachesize");
2909 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
2911 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info");
2913 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells");
2914 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
2916 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
2917 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
2918 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
2920 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
2922 cmd_CreateAlias(ts, "sq");
2924 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
2925 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
2926 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
2927 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
2929 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2931 * Turn this on only if you wish to be able to talk to a server which is listening
2932 * on alternative ports. This is not intended for general use and may not be
2933 * supported in the cache manager. It is not a way to run two servers at the
2934 * same host, since the cache manager cannot properly distinguish those two hosts.
2936 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
2937 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
2940 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
2941 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2943 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
2944 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2946 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
2949 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
2952 /* set cache monitor host address */
2953 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, (char *) CMD_HIDDEN);
2954 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
2955 cmd_CreateAlias(ts, "mariner");
2957 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
2958 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
2960 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
2961 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
2962 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
2963 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
2965 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume");
2966 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
2968 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value");
2969 cmd_AddParm(ts, "-newsys", CMD_SINGLE, CMD_OPTIONAL, "new sysname");
2971 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS");
2972 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
2973 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator (on | off)");
2974 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode (on | off)");
2975 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode (on | off)");
2976 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. (on | off)");
2979 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
2980 "store to server after file close");
2981 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
2982 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
2983 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
2984 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
2985 cmd_CreateAlias(ts, "sb");
2987 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
2988 "Manage per process RX statistics");
2989 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL,
2991 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL,
2992 "Disable RX stats");
2993 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
2996 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0,
2997 "Manage per peer RX statistics");
2998 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL,
3000 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL,
3001 "Disable RX stats");
3002 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3005 code = cmd_Dispatch(argc, argv);
3006 if (rxInitDone) rx_Finalize();
3011 static void Die(errnum, filename)
3018 fprintf(stderr, "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3021 fprintf(stderr, "%s: Invalid argument.\n", pn);
3025 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3027 fprintf(stderr, "%s: no such file returned\n", pn);
3030 fprintf(stderr, "%s: You can not change a backup or readonly volume\n", pn);
3035 fprintf(stderr, "%s: You don't have the required access rights on '%s'\n",
3038 fprintf(stderr, "%s: You do not have the required rights to do this operation\n",
3043 fprintf(stderr, "%s:'%s'", pn, filename);
3045 fprintf(stderr, "%s", pn);
3046 fprintf(stderr, ": %s\n", error_message(errnum));
3051 /* get clients interface addresses */
3053 GetClientAddrsCmd(as)
3054 struct cmd_syndesc *as;
3057 struct cmd_item *ti;
3059 struct ViceIoctl blob;
3060 struct sprefrequest *in;
3061 struct sprefinfo *out;
3063 in = (struct sprefrequest *)space;
3068 blob.in_size=sizeof(struct sprefrequest);
3069 blob.in = (char *)in;
3071 blob.out_size = MAXSIZE;
3073 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct spref);
3074 /* returns addr in network byte order */
3075 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3077 perror("getClientInterfaceAddr pioctl");
3083 out = (struct sprefinfo *) blob.out;
3084 for (i=0; i < out->num_servers; i++) {
3087 addr = ntohl(out->servers[i].server.s_addr);
3088 sprintf(tbuffer, "%d.%d.%d.%d",
3089 (addr>>24) & 0xff, (addr>>16) & 0xff,
3090 (addr>>8) & 0xff, addr & 0xff);
3091 printf ("%-50s\n", tbuffer);
3093 in->offset = out->next_offset;
3095 } while (out->next_offset > 0);
3101 SetClientAddrsCmd(as)
3102 struct cmd_syndesc *as;
3104 afs_int32 code, addr;
3105 struct cmd_item *ti;
3107 struct ViceIoctl blob;
3108 struct setspref *ssp;
3109 int sizeUsed = 0, i, flag;
3110 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3114 ssp = (struct setspref *)space;
3115 ssp->num_servers = 0;
3118 blob.out_size = MAXSIZE;
3121 fprintf(stderr, "Permission denied: requires root access.\n");
3125 /* extract all existing interface addresses */
3126 existNu = rx_getAllAddr(existingAddr,1024);
3130 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3131 for (ti = as->parms[0].items;ti;ti=ti->next) {
3132 if (sizeUsed >= sizeof(space)) {
3133 fprintf(stderr, "No more space\n");
3136 addr = extractAddr(ti->data, 20); /* network order */
3137 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3138 fprintf(stderr, "Error in specifying address: %s..ignoring\n", ti->data);
3142 /* see if it is an address that really exists */
3143 for (flag = 0, i=0; i < existNu; i++)
3144 if (existingAddr[i] == addr) {
3148 if (!flag) { /* this is an nonexistent address */
3149 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3153 /* copy all specified addr into ioctl buffer */
3154 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3155 printf("Adding 0x%08x\n", addr);
3157 sizeUsed += sizeof(struct spref);
3159 if (ssp->num_servers < 1) {
3160 fprintf(stderr, "No addresses specified\n");
3163 blob.in_size = sizeUsed - sizeof(struct spref);
3165 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3176 struct cmd_syndesc *as;
3179 struct ViceIoctl blob;
3180 struct cmd_item *ti;
3181 char orig_name[1024]; /*Original name, may be modified*/
3182 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
3183 char parent_dir[1024]; /*Parent directory of true name*/
3184 char *last_component; /*Last component of true name*/
3185 struct stat statbuff; /*Buffer for status info*/
3186 int link_chars_read; /*Num chars read in readlink()*/
3187 int thru_symlink; /*Did we get to a mount point via a symlink?*/
3190 for(ti=as->parms[0].items; ti; ti=ti->next) {
3193 sprintf(orig_name, "%s%s",
3194 (ti->data[0] == '/') ? "" : "./",
3197 if (lstat(orig_name, &statbuff) < 0) {
3198 /* if lstat fails, we should still try the pioctl, since it
3199 may work (for example, lstat will fail, but pioctl will
3200 work if the volume of offline (returning ENODEV). */
3201 statbuff.st_mode = S_IFDIR; /* lie like pros */
3205 * The lstat succeeded. If the given file is a symlink, substitute
3206 * the file name with the link name.
3208 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
3211 * Read name of resolved file.
3213 link_chars_read = readlink(orig_name, true_name, 1024);
3214 if (link_chars_read <= 0) {
3215 fprintf(stderr, "%s: Can't read target name for '%s' symbolic link!\n",
3222 * Add a trailing null to what was read, bump the length.
3224 true_name[link_chars_read++] = 0;
3227 * If the symlink is an absolute pathname, we're fine. Otherwise, we
3228 * have to create a full pathname using the original name and the
3229 * relative symlink name. Find the rightmost slash in the original
3230 * name (we know there is one) and splice in the symlink value.
3232 if (true_name[0] != '/') {
3233 last_component = (char *) rindex(orig_name, '/');
3234 strcpy(++last_component, true_name);
3235 strcpy(true_name, orig_name);
3239 strcpy(true_name, orig_name);
3242 * Find rightmost slash, if any.
3244 last_component = (char *) rindex(true_name, '/');
3245 if (last_component) {
3247 * Found it. Designate everything before it as the parent directory,
3248 * everything after it as the final component.
3250 strncpy(parent_dir, true_name, last_component - true_name);
3251 parent_dir[last_component - true_name] = 0;
3252 last_component++; /*Skip the slash*/
3256 * No slash appears in the given file name. Set parent_dir to the current
3257 * directory, and the last component as the given name.
3259 strcpy(parent_dir, ".");
3260 last_component = true_name;
3263 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
3264 fprintf(stderr, "%s: you may not use '.' or '..' as the last component\n", pn);
3265 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n", pn);
3270 blob.in = last_component;
3271 blob.in_size = strlen(last_component)+1;
3273 bzero(space, MAXSIZE);
3275 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
3278 if (errno == EINVAL) {
3279 fprintf(stderr, "'%s' is not a mount point.\n",
3283 Die(errno, (ti->data ? ti->data : parent_dir));
3293 struct cmd_syndesc *as;
3296 afs_int32 flags = 0;
3297 struct ViceIoctl blob;
3298 struct cmd_item *ti;
3300 if (as->parms[0].items) { /* -enable*/
3301 flags |= AFSCALL_RXSTATS_ENABLE;
3303 if (as->parms[1].items) { /* -disable*/
3304 flags |= AFSCALL_RXSTATS_DISABLE;
3306 if (as->parms[2].items) { /* -clear*/
3307 flags |= AFSCALL_RXSTATS_CLEAR;
3310 fprintf(stderr, "You must specify at least one argument\n");
3314 blob.in = (char *)&flags;
3315 blob.in_size = sizeof(afs_int32);
3318 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
3329 struct cmd_syndesc *as;
3332 afs_int32 flags = 0;
3333 struct ViceIoctl blob;
3334 struct cmd_item *ti;
3336 if (as->parms[0].items) { /* -enable*/
3337 flags |= AFSCALL_RXSTATS_ENABLE;
3339 if (as->parms[1].items) { /* -disable*/
3340 flags |= AFSCALL_RXSTATS_DISABLE;
3342 if (as->parms[2].items) { /* -clear*/
3343 flags |= AFSCALL_RXSTATS_CLEAR;
3346 fprintf(stderr, "You must specify at least one argument\n");
3350 blob.in = (char *)&flags;
3351 blob.in_size = sizeof(afs_int32);
3354 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);