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>
16 #include <afs/afs_args.h>
18 #include <sys/ioctl.h>
19 #include <sys/socket.h>
23 #include <netinet/in.h>
27 #include <afs/venus.h>
42 #include "afs/prs_fs.h"
43 #include <afs/afsint.h>
45 #include <afs/cellconfig.h>
48 #include <rx/rx_globals.h>
49 #include <afs/vldbint.h>
50 #include <afs/volser.h>
51 #include <afs/vlserver.h>
53 #include <afs/afsutil.h>
56 #include <afs/ptclient.h>
61 #define MAXCELLHOSTS 8
64 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
65 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
67 static char space[MAXSIZE];
68 static char tspace[1024];
69 static struct ubik_client *uclient;
71 static int GetClientAddrsCmd(), SetClientAddrsCmd(), FlushMountCmd();
72 static int RxStatProcCmd(), RxStatPeerCmd();
74 extern char *hostutil_GetNameByINet();
75 extern struct hostent *hostutil_GetHostByName();
78 extern struct cmd_syndesc *cmd_CreateSyntax();
79 static char pn[] = "fs";
80 static int rxInitDone = 0;
82 static void ZapList();
83 static int PruneList();
91 * Character to use between name and rights in printed representation for
94 #define DFS_SEPARATOR ' '
96 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
99 int dfs; /* Originally true if a dfs acl; now also the type
100 * of the acl (1, 2, or 3, corresponding to object,
101 * initial dir, or initial object). */
102 sec_rgy_name_t cell; /* DFS cell name */
105 struct AclEntry *pluslist;
106 struct AclEntry *minuslist;
110 struct AclEntry *next;
121 ZapList(acl->pluslist);
122 ZapList(acl->minuslist);
135 if (t >= 'A' && t <= 'Z')
137 if (u >= 'A' && u <= 'Z')
147 * Mods for the AFS/DFS protocol translator.
149 * DFS rights. It's ugly to put these definitions here, but they
150 * *cannot* change, because they're part of the wire protocol.
151 * In any event, the protocol translator will guarantee these
152 * assignments for AFS cache managers.
154 #define DFS_READ 0x01
155 #define DFS_WRITE 0x02
156 #define DFS_EXECUTE 0x04
157 #define DFS_CONTROL 0x08
158 #define DFS_INSERT 0x10
159 #define DFS_DELETE 0x20
161 /* the application definable ones (backwards from AFS) */
162 #define DFS_USR0 0x80000000 /* "A" bit */
163 #define DFS_USR1 0x40000000 /* "B" bit */
164 #define DFS_USR2 0x20000000 /* "C" bit */
165 #define DFS_USR3 0x10000000 /* "D" bit */
166 #define DFS_USR4 0x08000000 /* "E" bit */
167 #define DFS_USR5 0x04000000 /* "F" bit */
168 #define DFS_USR6 0x02000000 /* "G" bit */
169 #define DFS_USR7 0x01000000 /* "H" bit */
170 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
171 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
174 * Offset of -id switch in command structure for various commands.
175 * The -if switch is the next switch always.
177 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
180 * Determine whether either the -id or -if switches are present, and
181 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
183 /* int id; Offset of -id switch; -if is next switch */
185 getidf(struct cmd_syndesc *as, int id)
189 if (as->parms[id].items) {
192 if (as->parms[id + 1].items) {
197 "%s: you may specify either -id or -if, but not both switches\n",
205 PRights(afs_int32 arights, int dfs)
208 if (arights & PRSFS_READ)
210 if (arights & PRSFS_LOOKUP)
212 if (arights & PRSFS_INSERT)
214 if (arights & PRSFS_DELETE)
216 if (arights & PRSFS_WRITE)
218 if (arights & PRSFS_LOCK)
220 if (arights & PRSFS_ADMINISTER)
222 if (arights & PRSFS_USR0)
224 if (arights & PRSFS_USR1)
226 if (arights & PRSFS_USR2)
228 if (arights & PRSFS_USR3)
230 if (arights & PRSFS_USR4)
232 if (arights & PRSFS_USR5)
234 if (arights & PRSFS_USR6)
236 if (arights & PRSFS_USR7)
239 if (arights & DFS_READ)
243 if (arights & DFS_WRITE)
247 if (arights & DFS_EXECUTE)
251 if (arights & DFS_CONTROL)
255 if (arights & DFS_INSERT)
259 if (arights & DFS_DELETE)
263 if (arights & (DFS_USRALL))
265 if (arights & DFS_USR0)
267 if (arights & DFS_USR1)
269 if (arights & DFS_USR2)
271 if (arights & DFS_USR3)
273 if (arights & DFS_USR4)
275 if (arights & DFS_USR5)
277 if (arights & DFS_USR6)
279 if (arights & DFS_USR7)
284 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
288 struct ViceIoctl blob;
292 blob.out_size = MAXSIZE;
295 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
297 if ((errno == EINVAL) || (errno == ENOENT))
303 /* return a static pointer to a buffer */
308 strcpy(tspace, apath);
309 tp = strrchr(tspace, '/');
317 enum rtype { add, destroy, deny };
320 Convert(char *arights, int dfs, enum rtype *rtypep)
326 *rtypep = add; /* add rights, by default */
329 if (!strcmp(arights, "null")) {
333 if (!strcmp(arights, "read"))
334 return DFS_READ | DFS_EXECUTE;
335 if (!strcmp(arights, "write"))
336 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
338 if (!strcmp(arights, "all"))
339 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
340 DFS_WRITE | DFS_CONTROL;
342 if (!strcmp(arights, "read"))
343 return PRSFS_READ | PRSFS_LOOKUP;
344 if (!strcmp(arights, "write"))
345 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
346 PRSFS_WRITE | PRSFS_LOCK;
347 if (!strcmp(arights, "mail"))
348 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
349 if (!strcmp(arights, "all"))
350 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
351 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
353 if (!strcmp(arights, "none")) {
354 *rtypep = destroy; /* Remove entire entry */
357 len = strlen(arights);
359 for (i = 0; i < len; i++) {
393 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
401 mode |= PRSFS_LOOKUP;
403 mode |= PRSFS_INSERT;
405 mode |= PRSFS_DELETE;
411 mode |= PRSFS_ADMINISTER;
429 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
438 static struct AclEntry *
439 FindList(struct AclEntry *alist, char *aname)
442 if (!foldcmp(alist->name, aname))
449 /* if no parm specified in a particular slot, set parm to be "." instead */
451 SetDotDefault(struct cmd_item **aitemp)
455 return; /* already has value */
456 /* otherwise, allocate an item representing "." */
457 ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
459 ti->next = (struct cmd_item *)0;
460 ti->data = (char *)malloc(2);
462 strcpy(ti->data, ".");
467 ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
469 struct AclEntry *tlist;
470 tlist = (plus ? al->pluslist : al->minuslist);
471 tlist = FindList(tlist, aname);
473 /* Found the item already in the list. */
474 tlist->rights = arights;
476 al->nplus -= PruneList(&al->pluslist, al->dfs);
478 al->nminus -= PruneList(&al->minuslist, al->dfs);
481 /* Otherwise we make a new item and plug in the new data. */
482 tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry));
484 strcpy(tlist->name, aname);
485 tlist->rights = arights;
487 tlist->next = al->pluslist;
488 al->pluslist = tlist;
490 if (arights == 0 || arights == -1)
491 al->nplus -= PruneList(&al->pluslist, al->dfs);
493 tlist->next = al->minuslist;
494 al->minuslist = tlist;
497 al->nminus -= PruneList(&al->minuslist, al->dfs);
502 ZapList(struct AclEntry *alist)
504 struct AclEntry *tp, *np;
505 for (tp = alist; tp; tp = np) {
512 PruneList(struct AclEntry **ae, int dfs)
514 struct AclEntry **lp;
515 struct AclEntry *te, *ne;
519 for (te = *ae; te; te = ne) {
520 if ((!dfs && te->rights == 0) || te->rights == -1) {
536 while (*astr != '\n')
543 * Create an empty acl, taking into account whether the acl pointed
544 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
545 * can recover from problems caused by bogus ACL's (in that case, always
546 * assume that the acl is AFS: for DFS, the user can always resort to
547 * acl_edit, but for AFS there may be no other way out).
555 tp = (struct Acl *)malloc(sizeof(struct Acl));
557 tp->nplus = tp->nminus = 0;
558 tp->pluslist = tp->minuslist = 0;
560 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
567 int nplus, nminus, i, trights;
569 struct AclEntry *first, *last, *tl;
572 ta = (struct Acl *)malloc(sizeof(struct Acl));
575 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
576 astr = SkipLine(astr);
577 sscanf(astr, "%d", &ta->nminus);
578 astr = SkipLine(astr);
585 for (i = 0; i < nplus; i++) {
586 sscanf(astr, "%100s %d", tname, &trights);
587 astr = SkipLine(astr);
588 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
592 strcpy(tl->name, tname);
593 tl->rights = trights;
599 ta->pluslist = first;
603 for (i = 0; i < nminus; i++) {
604 sscanf(astr, "%100s %d", tname, &trights);
605 astr = SkipLine(astr);
606 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
610 strcpy(tl->name, tname);
611 tl->rights = trights;
617 ta->minuslist = first;
623 PrintStatus(VolumeStatus * status, char *name, char *offmsg)
625 printf("Volume status for vid = %u named %s\n", status->Vid, name);
627 printf("Current offline message is %s\n", offmsg);
628 printf("Current disk quota is ");
629 if (status->MaxQuota != 0)
630 printf("%d\n", status->MaxQuota);
632 printf("unlimited\n");
633 printf("Current blocks used are %d\n", status->BlocksInUse);
634 printf("The partition has %d blocks available out of %d\n\n",
635 status->PartBlocksAvail, status->PartMaxBlocks);
640 QuickPrintStatus(VolumeStatus * status, char *name)
642 double QuotaUsed = 0.0;
643 double PartUsed = 0.0;
645 printf("%-25.25s", name);
647 if (status->MaxQuota != 0) {
648 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
650 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
652 printf(" no limit%10d", status->BlocksInUse);
654 if (QuotaUsed > 90.0) {
655 printf("%5.0f%%<<", QuotaUsed);
658 printf("%5.0f%% ", QuotaUsed);
661 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
663 if (PartUsed > 97.0) {
664 printf("%9.0f%%<<", PartUsed);
667 printf("%9.0f%% ", PartUsed);
669 printf(" <<WARNING\n");
676 QuickPrintSpace(VolumeStatus * status, char *name)
678 double PartUsed = 0.0;
680 printf("%-25.25s", name);
682 printf("%10d%10d%10d", status->PartMaxBlocks,
683 status->PartMaxBlocks - status->PartBlocksAvail,
684 status->PartBlocksAvail);
688 ((((double)status->PartBlocksAvail) / status->PartMaxBlocks) *
690 if (PartUsed > 90.0) {
691 printf(" %4.0f%%<<", PartUsed);
694 printf(" %4.0f%% ", PartUsed);
696 printf(" <<WARNING\n");
703 AclToString(struct Acl *acl)
705 static char mydata[MAXSIZE];
706 char tstring[MAXSIZE];
711 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
714 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
715 for (tp = acl->pluslist; tp; tp = tp->next) {
716 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
717 strcat(mydata, tstring);
719 for (tp = acl->minuslist; tp; tp = tp->next) {
720 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
721 strcat(mydata, tstring);
727 SetACLCmd(struct cmd_syndesc *as)
730 struct ViceIoctl blob;
732 struct cmd_item *ti, *ui;
736 int idf = getidf(as, parm_setacl_id);
739 if (as->parms[2].items)
743 plusp = !(as->parms[3].items);
744 for (ti = as->parms[0].items; ti; ti = ti->next) {
745 blob.out_size = MAXSIZE;
747 blob.in = blob.out = space;
748 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
750 Die(errno, ti->data);
757 ta = ParseAcl(space);
758 if (!plusp && ta->dfs) {
760 "%s: %s: you may not use the -negative switch with DFS acl's.\n%s",
762 "(you may specify \"null\" to revoke all rights, however)\n");
770 ta = EmptyAcl(space);
772 ta = ParseAcl(space);
773 CleanAcl(ta, ti->data);
774 for (ui = as->parms[1].items; ui; ui = ui->next->next) {
778 "%s: Missing second half of user/access pair.\n", pn);
782 rights = Convert(ui->next->data, ta->dfs, &rtype);
783 if (rtype == destroy && !ta->dfs) {
784 struct AclEntry *tlist;
786 tlist = (plusp ? ta->pluslist : ta->minuslist);
787 if (!FindList(tlist, ui->data))
790 if (rtype == deny && !ta->dfs)
792 if (rtype == destroy && ta->dfs)
794 ChangeList(ta, plusp, ui->data, rights);
796 blob.in = AclToString(ta);
798 blob.in_size = 1 + strlen(blob.in);
799 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
801 if (errno == EINVAL) {
803 static char *fsenv = 0;
805 fsenv = (char *)getenv("FS_EXPERT");
808 "%s: \"Invalid argument\" was returned when you tried to store a DFS access list.\n",
812 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
813 "\nPossible reasons for this include:\n\n",
814 " -You may have specified an inappropriate combination of rights.\n",
815 " For example, some DFS-supported filesystems may not allow you to\n",
816 " drop the \"c\" right from \"user_obj\".\n\n",
817 " -A mask_obj may be required (it is likely required by the underlying\n",
818 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
819 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
820 " does not automatically create or update the mask_obj. Try setting\n",
821 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
822 " users or groups. You can do this with a single command, such as\n",
823 " \"fs sa mask_obj all user:somename read\"\n\n",
824 " -A specified user or group may not exist.\n\n",
825 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
826 " This is probably not allowed by the underlying file system.\n\n",
827 " -If you add a user or group to a DFS ACL, remember that it must be\n",
828 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
829 " may be local requirements on the format of the user or group name.\n",
830 " Check with your cell administrator.\n\n",
831 " -Or numerous other possibilities. It would be great if we could be more\n",
832 " precise about the actual problem, but for various reasons, this is\n",
833 " impractical via this interface. If you can't figure it out, you\n",
834 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
835 " whatever is provided). You may get better results. Good luck!\n\n",
836 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
840 "%s: Invalid argument, possible reasons include:\n",
842 fprintf(stderr, "\t-File not in AFS\n");
844 "\t-Too many users on access control list\n");
846 "\t-Tried to add non-existent user to access control list\n");
849 Die(errno, ti->data);
861 CopyACLCmd(struct cmd_syndesc *as)
864 struct ViceIoctl blob;
865 struct Acl *fa, *ta = 0;
867 struct cmd_item *ti, *ui;
871 int idf = getidf(as, parm_copyacl_id);
874 if (as->parms[2].items)
878 blob.out_size = MAXSIZE;
880 blob.in = blob.out = space;
881 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
883 Die(errno, as->parms[0].items->data);
886 fa = ParseAcl(space);
887 CleanAcl(fa, as->parms[0].items->data);
888 for (ti = as->parms[1].items; ti; ti = ti->next) {
889 blob.out_size = MAXSIZE;
891 blob.in = blob.out = space;
892 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
894 Die(errno, ti->data);
902 ta = EmptyAcl(space);
904 ta = ParseAcl(space);
905 CleanAcl(ta, ti->data);
906 if (ta->dfs != fa->dfs) {
908 "%s: incompatible file system types: acl not copied to %s; aborted\n",
914 if (!clear && strcmp(ta->cell, fa->cell) != 0) {
916 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
921 strcpy(ta->cell, fa->cell);
923 for (tp = fa->pluslist; tp; tp = tp->next)
924 ChangeList(ta, 1, tp->name, tp->rights);
925 for (tp = fa->minuslist; tp; tp = tp->next)
926 ChangeList(ta, 0, tp->name, tp->rights);
927 blob.in = AclToString(ta);
929 blob.in_size = 1 + strlen(blob.in);
930 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
932 if (errno == EINVAL) {
934 "%s: Invalid argument, possible reasons include:\n",
936 fprintf(stderr, "\t-File not in AFS\n");
938 Die(errno, ti->data);
949 /* pioctl() call to get the cellname of a pathname */
951 GetCell(char *fname, char *cellname)
954 struct ViceIoctl blob;
957 blob.out_size = MAXCELLCHARS;
960 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
961 return code ? errno : 0;
964 /* Check if a username is valid: If it contains only digits (or a
965 * negative sign), then it might be bad. We then query the ptserver
969 BadName(char *aname, char *fname)
971 afs_int32 tc, code, id;
973 char cell[MAXCELLCHARS];
975 for (nm = aname; tc = *nm; nm++) {
976 /* all must be '-' or digit to be bad */
977 if (tc != '-' && (tc < '0' || tc > '9'))
981 /* Go to the PRDB and see if this all number username is valid */
982 code = GetCell(fname, cell);
986 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
987 code = pr_SNameToId(aname, &id);
990 /* 1=>Not-valid; 0=>Valid */
991 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
995 /* clean up an access control list of its bad entries; return 1 if we made
996 any changes to the list, and 0 otherwise */
998 CleanAcl(struct Acl *aa, char *fname)
1000 struct AclEntry *te, **le, *ne;
1003 /* Don't correct DFS ACL's for now */
1007 /* prune out bad entries */
1008 changes = 0; /* count deleted entries */
1010 for (te = aa->pluslist; te; te = ne) {
1012 if (BadName(te->name, fname)) {
1022 le = &aa->minuslist;
1023 for (te = aa->minuslist; te; te = ne) {
1025 if (BadName(te->name, fname)) {
1039 /* clean up an acl to not have bogus entries */
1041 CleanACLCmd(struct cmd_syndesc *as)
1045 struct ViceIoctl blob;
1047 struct cmd_item *ti;
1048 struct AclEntry *te;
1051 SetDotDefault(&as->parms[0].items);
1052 for (ti = as->parms[0].items; ti; ti = ti->next) {
1053 blob.out_size = MAXSIZE;
1056 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1058 Die(errno, ti->data);
1065 ta = ParseAcl(space);
1068 "%s: cleanacl is not supported for DFS access lists.\n",
1074 changes = CleanAcl(ta, ti->data);
1077 /* now set the acl */
1078 blob.in = AclToString(ta);
1079 blob.in_size = strlen(blob.in) + 1;
1081 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1083 if (errno == EINVAL) {
1085 "%s: Invalid argument, possible reasons include\n",
1087 fprintf(stderr, "%s: File not in vice or\n", pn);
1089 "%s: Too many users on access control list or\n",
1092 Die(errno, ti->data);
1098 /* now list the updated acl */
1099 printf("Access list for %s is now\n", ti->data);
1100 if (ta->nplus > 0) {
1102 printf("Normal rights:\n");
1103 for (te = ta->pluslist; te; te = te->next) {
1104 printf(" %s ", te->name);
1105 PRights(te->rights, ta->dfs);
1109 if (ta->nminus > 0) {
1110 printf("Negative rights:\n");
1111 for (te = ta->minuslist; te; te = te->next) {
1112 printf(" %s ", te->name);
1113 PRights(te->rights, ta->dfs);
1120 printf("Access list for %s is fine.\n", ti->data);
1128 ListACLCmd(struct cmd_syndesc *as)
1132 struct ViceIoctl blob;
1133 struct AclEntry *te;
1134 struct cmd_item *ti;
1135 int idf = getidf(as, parm_listacl_id);
1138 SetDotDefault(&as->parms[0].items);
1139 for (ti = as->parms[0].items; ti; ti = ti->next) {
1140 blob.out_size = MAXSIZE;
1142 blob.in = blob.out = space;
1143 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1145 Die(errno, ti->data);
1149 ta = ParseAcl(space);
1152 printf("Access list for %s is\n", ti->data);
1155 printf("DFS access list for %s is\n", ti->data);
1158 printf("DFS initial directory access list of %s is\n", ti->data);
1161 printf("DFS initial file access list of %s is\n", ti->data);
1165 printf(" Default cell = %s\n", ta->cell);
1167 if (ta->nplus > 0) {
1169 printf("Normal rights:\n");
1170 for (te = ta->pluslist; te; te = te->next) {
1171 printf(" %s ", te->name);
1172 PRights(te->rights, ta->dfs);
1176 if (ta->nminus > 0) {
1177 printf("Negative rights:\n");
1178 for (te = ta->minuslist; te; te = te->next) {
1179 printf(" %s ", te->name);
1180 PRights(te->rights, ta->dfs);
1192 FlushVolumeCmd(struct cmd_syndesc *as)
1195 struct ViceIoctl blob;
1196 struct cmd_item *ti;
1199 SetDotDefault(&as->parms[0].items);
1200 for (ti = as->parms[0].items; ti; ti = ti->next) {
1201 blob.in_size = blob.out_size = 0;
1202 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1204 fprintf(stderr, "Error flushing volume ");
1214 FlushCmd(struct cmd_syndesc *as)
1217 struct ViceIoctl blob;
1218 struct cmd_item *ti;
1221 for (ti = as->parms[0].items; ti; ti = ti->next) {
1222 blob.in_size = blob.out_size = 0;
1223 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1225 if (errno == EMFILE) {
1226 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1229 fprintf(stderr, "%s: Error flushing file ", pn);
1239 /* all this command does is repackage its args and call SetVolCmd */
1241 SetQuotaCmd(struct cmd_syndesc *as)
1243 struct cmd_syndesc ts;
1245 /* copy useful stuff from our command slot; we may later have to reorder */
1246 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1247 return SetVolCmd(&ts);
1251 SetVolCmd(struct cmd_syndesc *as)
1254 struct ViceIoctl blob;
1255 struct cmd_item *ti;
1256 struct VolumeStatus *status;
1257 char *offmsg, *input;
1260 SetDotDefault(&as->parms[0].items);
1261 for (ti = as->parms[0].items; ti; ti = ti->next) {
1263 blob.out_size = MAXSIZE;
1264 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1267 status = (VolumeStatus *) space;
1268 status->MinQuota = status->MaxQuota = -1;
1270 if (as->parms[1].items) {
1271 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1273 fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
1278 if (as->parms[2].items)
1279 offmsg = as->parms[2].items->data;
1280 input = (char *)status + sizeof(*status);
1281 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1283 if (strlen(offmsg) >= VMSGSIZE) {
1285 "%s: message must be shorter than %d characters\n",
1290 strcpy(input, offmsg);
1291 blob.in_size += strlen(offmsg);
1292 input += strlen(offmsg) + 1;
1295 *(input++) = '\0'; /* Pad for old style volume "motd" */
1296 code = pioctl(ti->data, VIOCSETVOLSTAT, &blob, 1);
1298 Die(errno, ti->data);
1306 * Why is VenusFid declared in the kernel-only section of afs.h,
1307 * if it's the exported interface of the cache manager?
1315 ExamineCmd(struct cmd_syndesc *as)
1318 struct ViceIoctl blob;
1319 struct cmd_item *ti;
1320 struct VolumeStatus *status;
1321 char *name, *offmsg;
1324 SetDotDefault(&as->parms[0].items);
1325 for (ti = as->parms[0].items; ti; ti = ti->next) {
1326 struct VenusFid vfid;
1329 blob.out_size = MAXSIZE;
1332 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1334 Die(errno, ti->data);
1338 status = (VolumeStatus *) space;
1339 name = (char *)status + sizeof(*status);
1340 offmsg = name + strlen(name) + 1;
1342 blob.out_size = sizeof(struct VenusFid);
1343 blob.out = (char *) &vfid;
1344 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1345 printf("File %s (%u.%u.%u) contained in volume %u\n",
1346 ti->data, vfid.Fid.Volume, vfid.Fid.Vnode, vfid.Fid.Unique,
1350 PrintStatus(status, name, offmsg);
1356 ListQuotaCmd(struct cmd_syndesc *as)
1359 struct ViceIoctl blob;
1360 struct cmd_item *ti;
1361 struct VolumeStatus *status;
1365 printf("%-25s%-10s%-10s%-7s%-11s\n", "Volume Name", " Quota",
1366 " Used", " %Used", " Partition");
1367 SetDotDefault(&as->parms[0].items);
1368 for (ti = as->parms[0].items; ti; ti = ti->next) {
1370 blob.out_size = MAXSIZE;
1373 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1375 Die(errno, ti->data);
1379 status = (VolumeStatus *) space;
1380 name = (char *)status + sizeof(*status);
1381 QuickPrintStatus(status, name);
1387 WhereIsCmd(struct cmd_syndesc *as)
1390 struct ViceIoctl blob;
1391 struct cmd_item *ti;
1397 SetDotDefault(&as->parms[0].items);
1398 for (ti = as->parms[0].items; ti; ti = ti->next) {
1400 blob.out_size = MAXSIZE;
1403 memset(space, 0, sizeof(space));
1404 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1406 Die(errno, ti->data);
1410 hosts = (afs_int32 *) space;
1411 printf("File %s is on host%s ", ti->data,
1412 (hosts[0] && !hosts[1]) ? "" : "s");
1413 for (j = 0; j < MAXHOSTS; j++) {
1416 tp = hostutil_GetNameByINet(hosts[j]);
1426 DiskFreeCmd(struct cmd_syndesc *as)
1429 struct ViceIoctl blob;
1430 struct cmd_item *ti;
1432 struct VolumeStatus *status;
1435 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1436 " used", " avail", " %used");
1437 SetDotDefault(&as->parms[0].items);
1438 for (ti = as->parms[0].items; ti; ti = ti->next) {
1440 blob.out_size = MAXSIZE;
1443 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1445 Die(errno, ti->data);
1449 status = (VolumeStatus *) space;
1450 name = (char *)status + sizeof(*status);
1451 QuickPrintSpace(status, name);
1457 QuotaCmd(struct cmd_syndesc *as)
1460 struct ViceIoctl blob;
1461 struct cmd_item *ti;
1463 struct VolumeStatus *status;
1466 SetDotDefault(&as->parms[0].items);
1467 for (ti = as->parms[0].items; ti; ti = ti->next) {
1469 blob.out_size = MAXSIZE;
1472 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1474 Die(errno, ti->data);
1478 status = (VolumeStatus *) space;
1479 if (status->MaxQuota)
1481 ((((double)status->BlocksInUse) / status->MaxQuota) * 100.0);
1484 printf("%2.0f%% of quota used.\n", quotaPct);
1490 ListMountCmd(struct cmd_syndesc *as)
1493 struct ViceIoctl blob;
1494 struct cmd_item *ti;
1495 char orig_name[1024]; /*Original name, may be modified */
1496 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
1497 char parent_dir[1024]; /*Parent directory of true name */
1498 char *last_component; /*Last component of true name */
1499 struct stat statbuff; /*Buffer for status info */
1500 int link_chars_read; /*Num chars read in readlink() */
1501 int thru_symlink; /*Did we get to a mount point via a symlink? */
1504 for (ti = as->parms[0].items; ti; ti = ti->next) {
1507 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
1510 if (lstat(orig_name, &statbuff) < 0) {
1511 /* if lstat fails, we should still try the pioctl, since it
1512 * may work (for example, lstat will fail, but pioctl will
1513 * work if the volume of offline (returning ENODEV). */
1514 statbuff.st_mode = S_IFDIR; /* lie like pros */
1518 * The lstat succeeded. If the given file is a symlink, substitute
1519 * the file name with the link name.
1521 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1524 * Read name of resolved file.
1526 link_chars_read = readlink(orig_name, true_name, 1024);
1527 if (link_chars_read <= 0) {
1529 "%s: Can't read target name for '%s' symbolic link!\n",
1536 * Add a trailing null to what was read, bump the length.
1538 true_name[link_chars_read++] = 0;
1541 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1542 * have to create a full pathname using the original name and the
1543 * relative symlink name. Find the rightmost slash in the original
1544 * name (we know there is one) and splice in the symlink value.
1546 if (true_name[0] != '/') {
1547 last_component = (char *)strrchr(orig_name, '/');
1548 strcpy(++last_component, true_name);
1549 strcpy(true_name, orig_name);
1552 strcpy(true_name, orig_name);
1555 * Find rightmost slash, if any.
1557 last_component = (char *)strrchr(true_name, '/');
1558 if (last_component) {
1560 * Found it. Designate everything before it as the parent directory,
1561 * everything after it as the final component.
1563 strncpy(parent_dir, true_name, last_component - true_name);
1564 parent_dir[last_component - true_name] = 0;
1565 last_component++; /*Skip the slash */
1568 * No slash appears in the given file name. Set parent_dir to the current
1569 * directory, and the last component as the given name.
1571 strcpy(parent_dir, ".");
1572 last_component = true_name;
1575 if (strcmp(last_component, ".") == 0
1576 || strcmp(last_component, "..") == 0) {
1578 "%s: you may not use '.' or '..' as the last component\n",
1580 fprintf(stderr, "%s: of a name in the 'fs lsmount' command.\n",
1586 blob.in = last_component;
1587 blob.in_size = strlen(last_component) + 1;
1588 blob.out_size = MAXSIZE;
1590 memset(space, 0, MAXSIZE);
1592 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1595 printf("'%s' is a %smount point for volume '%s'\n", ti->data,
1596 (thru_symlink ? "symbolic link, leading to a " : ""),
1599 if (errno == EINVAL) {
1600 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
1602 Die(errno, (ti->data ? ti->data : parent_dir));
1611 MakeMountCmd(struct cmd_syndesc *as)
1614 char *cellName, *volName, *tmpName;
1615 struct afsconf_cell info;
1616 struct vldbentry vldbEntry;
1617 struct ViceIoctl blob;
1623 if (as->parms[5].items && !as->parms[2].items) {
1624 fprintf(stderr, "%s: must provide cell when creating cellular mount point.\n", pn);
1629 if (as->parms[2].items) /* cell name specified */
1630 cellName = as->parms[2].items->data;
1633 volName = as->parms[1].items->data;
1635 if (strlen(volName) >= 64) {
1637 "%s: volume name too long (length must be < 64 characters)\n",
1642 /* Check for a cellname in the volume specification, and complain
1643 * if it doesn't match what was specified with -cell */
1644 if (tmpName = strchr(volName, ':')) {
1647 if (strcasecmp(cellName, volName)) {
1648 fprintf(stderr, "%s: cellnames do not match.\n", pn);
1653 volName = ++tmpName;
1656 if (!InAFS(Parent(as->parms[0].items->data))) {
1658 "%s: mount points must be created within the AFS file system\n",
1665 blob.out_size = MAXSIZE;
1668 pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME,
1672 code = GetCellName(cellName ? cellName : space, &info);
1676 if (!(as->parms[4].items)) {
1677 /* not fast, check which cell the mountpoint is being created in */
1678 /* not fast, check name with VLDB */
1679 code = VLDBInit(1, &info);
1681 /* make the check. Don't complain if there are problems with init */
1683 ubik_Call(VL_GetEntryByNameO, uclient, 0, volName,
1685 if (code == VL_NOENT) {
1687 "%s: warning, volume %s does not exist in cell %s.\n",
1688 pn, volName, cellName ? cellName : space);
1693 if (as->parms[3].items) /* if -rw specified */
1698 /* cellular mount point, prepend cell prefix */
1699 strcat(space, info.name);
1702 strcat(space, volName); /* append volume name */
1703 strcat(space, "."); /* stupid convention; these end with a period */
1704 code = symlink(space, as->parms[0].items->data);
1706 Die(errno, as->parms[0].items->data);
1713 * Delete AFS mount points. Variables are used as follows:
1714 * tbuffer: Set to point to the null-terminated directory name of the mount point
1715 * (or ``.'' if none is provided)
1716 * tp: Set to point to the actual name of the mount point to nuke.
1719 RemoveMountCmd(struct cmd_syndesc *as)
1722 struct ViceIoctl blob;
1723 struct cmd_item *ti;
1725 char lsbuffer[1024];
1729 for (ti = as->parms[0].items; ti; ti = ti->next) {
1731 tp = (char *)strrchr(ti->data, '/');
1733 strncpy(tbuffer, ti->data, code = tp - ti->data); /* the dir name */
1735 tp++; /* skip the slash */
1737 strcpy(tbuffer, ".");
1741 blob.in_size = strlen(tp) + 1;
1742 blob.out = lsbuffer;
1743 blob.out_size = sizeof(lsbuffer);
1744 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1746 if (errno == EINVAL) {
1747 fprintf(stderr, "%s: '%s' is not a mount point.\n", pn,
1750 Die(errno, ti->data);
1753 continue; /* don't bother trying */
1757 blob.in_size = strlen(tp) + 1;
1758 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1760 Die(errno, ti->data);
1771 CheckServersCmd(struct cmd_syndesc *as)
1774 struct ViceIoctl blob;
1780 struct afsconf_cell info;
1781 struct chservinfo checkserv;
1783 memset(&checkserv, 0, sizeof(struct chservinfo));
1784 blob.in_size = sizeof(struct chservinfo);
1785 blob.in = (caddr_t) & checkserv;
1787 blob.out_size = MAXSIZE;
1789 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1791 /* prepare flags for checkservers command */
1792 temp = 2; /* default to checking local cell only */
1793 if (as->parms[2].items)
1794 temp |= 1; /* set fast flag */
1795 if (as->parms[1].items)
1796 temp &= ~2; /* turn off local cell check */
1798 checkserv.magic = 0x12345678; /* XXX */
1799 checkserv.tflags = temp;
1801 /* now copy in optional cell name, if specified */
1802 if (as->parms[0].items) {
1803 code = GetCellName(as->parms[0].items->data, &info);
1807 strcpy(checkserv.tbuffer, info.name);
1808 checkserv.tsize = strlen(info.name) + 1;
1810 strcpy(checkserv.tbuffer, "\0");
1811 checkserv.tsize = 0;
1814 if (as->parms[3].items) {
1815 checkserv.tinterval = atol(as->parms[3].items->data);
1818 if (checkserv.tinterval < 0) {
1820 ("Warning: The negative -interval is ignored; treated as an inquiry\n");
1821 checkserv.tinterval = 0;
1822 } else if (checkserv.tinterval > 600) {
1824 ("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1825 checkserv.tinterval = 600; /* 10 min max interval */
1828 checkserv.tinterval = -1; /* don't change current interval */
1831 code = pioctl(0, VIOCCKSERV, &blob, 1);
1833 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1834 printf("Must be root to change -interval\n");
1840 memcpy(&temp, space, sizeof(afs_int32));
1841 if (checkserv.tinterval >= 0) {
1842 if (checkserv.tinterval > 0)
1844 ("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1845 checkserv.tinterval, temp);
1847 printf("The current down server probe interval is %d secs\n",
1852 printf("All servers are running.\n");
1855 ("These servers unavailable due to network or server problems: ");
1857 memcpy(&temp, space + j * sizeof(afs_int32), sizeof(afs_int32));
1860 tp = hostutil_GetNameByINet(temp);
1870 MessagesCmd(struct cmd_syndesc *as)
1873 struct ViceIoctl blob;
1876 struct gaginfo gagflags;
1877 struct cmd_item *show;
1879 memset(&gagflags, 0, sizeof(struct gaginfo));
1880 blob.in_size = sizeof(struct gaginfo);
1881 blob.in = (caddr_t) & gagflags;
1882 blob.out_size = MAXSIZE;
1884 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1886 if (show = as->parms[0].items) {
1887 if (!strcasecmp(show->data, "user"))
1888 gagflags.showflags |= GAGUSER;
1889 else if (!strcasecmp(show->data, "console"))
1890 gagflags.showflags |= GAGCONSOLE;
1891 else if (!strcasecmp(show->data, "all"))
1892 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1893 else if (!strcasecmp(show->data, "none"))
1897 "unrecognized flag %s: must be in {user,console,all,none}\n",
1906 code = pioctl(0, VIOC_GAG, &blob, 1);
1916 CheckVolumesCmd(struct cmd_syndesc *as)
1919 struct ViceIoctl blob;
1923 code = pioctl(0, VIOCCKBACK, &blob, 1);
1929 printf("All volumeID/name mappings checked.\n");
1934 SetCacheSizeCmd(struct cmd_syndesc *as)
1937 struct ViceIoctl blob;
1940 if (!as->parms[0].items && !as->parms[1].items) {
1941 fprintf(stderr, "%s: syntax error in setcachesize cmd.\n", pn);
1944 if (as->parms[0].items) {
1945 code = util_GetInt32(as->parms[0].items->data, &temp);
1947 fprintf(stderr, "%s: bad integer specified for cache size.\n",
1953 blob.in = (char *)&temp;
1954 blob.in_size = sizeof(afs_int32);
1956 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
1958 if (errno == EROFS) {
1960 ("'fs setcache' not allowed on memory cache based cache managers.\n");
1967 printf("New cache size set.\n");
1971 #define MAXGCSIZE 16
1973 GetCacheParmsCmd(struct cmd_syndesc *as)
1976 struct ViceIoctl blob;
1977 afs_int32 parms[MAXGCSIZE];
1979 memset(parms, '\0', sizeof parms); /* avoid Purify UMR error */
1982 blob.out_size = sizeof(parms);
1983 blob.out = (char *)parms;
1984 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
1989 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
1990 parms[1], parms[0]);
1991 if (parms[1] > parms[0])
1993 ("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
1998 ListCellsCmd(struct cmd_syndesc *as)
2004 struct ViceIoctl blob;
2007 resolve = !(as->parms[0].items); /* -numeric */
2011 memcpy(tp, &i, sizeof(afs_int32));
2012 blob.out_size = MAXSIZE;
2013 blob.in_size = sizeof(afs_int32);
2016 code = pioctl(0, VIOCGETCELL, &blob, 1);
2019 break; /* done with the list */
2024 printf("Cell %s on hosts", tp + MAXCELLHOSTS * sizeof(afs_int32));
2025 for (j = 0; j < MAXCELLHOSTS; j++) {
2027 char *name, tbuffer[20];
2029 memcpy(&addr, tp + j * sizeof(afs_int32), sizeof(afs_int32));
2034 name = hostutil_GetNameByINet(addr);
2037 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2038 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2041 printf(" %s", name);
2049 ListAliasesCmd(struct cmd_syndesc *as)
2052 char *tp, *aliasName, *realName;
2053 struct ViceIoctl blob;
2057 memcpy(tp, &i, sizeof(afs_int32));
2058 blob.out_size = MAXSIZE;
2059 blob.in_size = sizeof(afs_int32);
2062 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2065 break; /* done with the list */
2071 tp += strlen(aliasName) + 1;
2073 printf("Alias %s for cell %s\n", aliasName, realName);
2079 CallBackRxConnCmd(struct cmd_syndesc *as)
2082 struct ViceIoctl blob;
2083 struct cmd_item *ti;
2085 struct hostent *thp;
2089 ti = as->parms[0].items;
2092 thp = hostutil_GetHostByName(ti->data);
2094 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2097 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2099 hostAddr = 0; /* means don't set host */
2100 setp = 0; /* aren't setting host */
2103 /* now do operation */
2104 blob.in_size = sizeof(afs_int32);
2105 blob.out_size = sizeof(afs_int32);
2106 blob.in = (char *) &hostAddr;
2107 blob.out = (char *) &hostAddr;
2109 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2118 NewCellCmd(struct cmd_syndesc *as)
2120 afs_int32 code, linkedstate = 0, size = 0, *lp;
2121 struct ViceIoctl blob;
2122 struct cmd_item *ti;
2123 char *tp, *cellname = 0;
2124 struct hostent *thp;
2125 afs_int32 fsport = 0, vlport = 0;
2126 afs_int32 magic, scount; /* Number of servers to pass in pioctl call */
2129 * With the NEWCELL pioctl call, 3.4 clients take an array of
2130 * MAXHOSTS (13) servers while 3.5 clients take an array of
2131 * MAXCELLHOSTS (8) servers. To determine which we are talking to,
2132 * do a GETCELL pioctl and pass it a magic number. If an array of
2133 * 8 comes back, its a 3.5 client. If not, its a 3.4 client.
2134 * If we get back EDOM, there are no cells in the kernel yet,
2135 * and we'll assume a 3.5 client.
2138 lp = (afs_int32 *) tp;
2139 *lp++ = 0; /* first cell entry */
2140 *lp = 0x12345678; /* magic */
2141 blob.out_size = MAXSIZE;
2142 blob.in_size = sizeof(afs_int32) + sizeof(afs_int32);
2145 code = pioctl(0, VIOCGETCELL, &blob, 1);
2146 if (code < 0 && errno != EDOM) {
2150 if (code < 1 && errno == EDOM) {
2154 cellname = tp + MAXCELLHOSTS * sizeof(afs_int32);
2155 scount = ((cellname[0] != '\0') ? MAXCELLHOSTS : MAXHOSTS);
2158 /* Now setup and do the NEWCELL pioctl call */
2159 memset(space, 0, (scount + 1) * sizeof(afs_int32));
2161 lp = (afs_int32 *) tp;
2163 tp += sizeof(afs_int32);
2164 for (ti = as->parms[1].items; ti; ti = ti->next) {
2165 thp = hostutil_GetHostByName(ti->data);
2168 "%s: Host %s not found in host table, skipping it.\n", pn,
2171 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2172 tp += sizeof(afs_int32);
2175 if (as->parms[2].items) {
2177 * Link the cell, for the purposes of volume location, to the specified
2180 cellname = as->parms[2].items->data;
2183 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2184 if (as->parms[3].items) {
2185 code = util_GetInt32(as->parms[3].items->data, &vlport);
2188 "%s: bad integer specified for the fileserver port.\n",
2193 if (as->parms[4].items) {
2194 code = util_GetInt32(as->parms[4].items->data, &fsport);
2197 "%s: bad integer specified for the vldb server port.\n",
2203 tp = (char *)(space + (scount + 1) * sizeof(afs_int32));
2204 lp = (afs_int32 *) tp;
2208 strcpy(space + ((scount + 4) * sizeof(afs_int32)),
2209 as->parms[0].items->data);
2210 size = ((scount + 4) * sizeof(afs_int32))
2211 + strlen(as->parms[0].items->data)
2212 + 1 /* for null */ ;
2213 tp = (char *)(space + size);
2215 strcpy(tp, cellname);
2216 size += strlen(cellname) + 1;
2218 blob.in_size = size;
2221 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2230 NewAliasCmd(struct cmd_syndesc *as)
2233 struct ViceIoctl blob;
2235 char *aliasName, *realName;
2237 /* Now setup and do the NEWCELL pioctl call */
2238 aliasName = as->parms[0].items->data;
2239 realName = as->parms[1].items->data;
2241 strcpy(tp, aliasName);
2242 tp += strlen(aliasName) + 1;
2243 strcpy(tp, realName);
2244 tp += strlen(realName) + 1;
2246 blob.in_size = tp - space;
2250 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2252 if (errno == EEXIST) {
2254 "%s: cell name `%s' in use by an existing cell.\n", pn,
2265 WhichCellCmd(struct cmd_syndesc *as)
2268 struct cmd_item *ti;
2270 char cell[MAXCELLCHARS];
2272 SetDotDefault(&as->parms[0].items);
2273 for (ti = as->parms[0].items; ti; ti = ti->next) {
2274 code = GetCell(ti->data, cell);
2276 if (errno == ENOENT)
2277 fprintf(stderr, "%s: no such cell as '%s'\n", pn, ti->data);
2279 Die(errno, ti->data);
2284 printf("File %s lives in cell '%s'\n", ti->data, cell);
2290 WSCellCmd(struct cmd_syndesc *as)
2293 struct ViceIoctl blob;
2297 blob.out_size = MAXSIZE;
2300 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2306 printf("This workstation belongs to cell '%s'\n", space);
2311 static PrimaryCellCmd(as)
2312 struct cmd_syndesc *as;
2314 fprintf(stderr, "This command is obsolete, as is the concept of a primary token.\n");
2320 MonitorCmd(struct cmd_syndesc *as)
2323 struct ViceIoctl blob;
2324 struct cmd_item *ti;
2326 struct hostent *thp;
2330 ti = as->parms[0].items;
2334 if (!strcmp(ti->data, "off"))
2335 hostAddr = 0xffffffff;
2337 thp = hostutil_GetHostByName(ti->data);
2339 if (!strcmp(ti->data, "localhost")) {
2341 "localhost not in host table, assuming 127.0.0.1\n");
2342 hostAddr = htonl(0x7f000001);
2344 fprintf(stderr, "host %s not found in host table.\n",
2349 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2352 hostAddr = 0; /* means don't set host */
2353 setp = 0; /* aren't setting host */
2356 /* now do operation */
2357 blob.in_size = sizeof(afs_int32);
2358 blob.out_size = sizeof(afs_int32);
2359 blob.in = (char *)&hostAddr;
2360 blob.out = (char *)&hostAddr;
2361 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2367 printf("%s: new monitor host set.\n", pn);
2369 /* now decode old address */
2370 if (hostAddr == 0xffffffff) {
2371 printf("Cache monitoring is currently disabled.\n");
2373 tp = hostutil_GetNameByINet(hostAddr);
2374 printf("Using host %s for monitor services.\n", tp);
2381 SysNameCmd(struct cmd_syndesc *as)
2384 struct ViceIoctl blob;
2385 struct cmd_item *ti;
2386 char *input = space;
2389 ti = as->parms[0].items;
2392 blob.out_size = MAXSIZE;
2393 blob.in_size = sizeof(afs_int32);
2394 input += sizeof(afs_int32);
2395 for (; ti; ti = ti->next) {
2397 blob.in_size += strlen(ti->data) + 1;
2398 if (blob.in_size > MAXSIZE) {
2399 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2400 setp > 1 ? "s" : "");
2403 strcpy(input, ti->data);
2404 input += strlen(ti->data);
2407 memcpy(space, &setp, sizeof(afs_int32));
2408 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2414 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2418 memcpy(&setp, input, sizeof(afs_int32));
2419 input += sizeof(afs_int32);
2421 fprintf(stderr, "No sysname name value was found\n");
2424 printf("Current sysname%s is", setp > 1 ? " list" : "");
2425 for (; setp > 0; --setp) {
2426 printf(" \'%s\'", input);
2427 input += strlen(input) + 1;
2433 static char *exported_types[] = { "null", "nfs", "" };
2435 ExportAfsCmd(struct cmd_syndesc *as)
2438 struct ViceIoctl blob;
2439 struct cmd_item *ti;
2440 int export = 0, type = 0, mode = 0, exp = 0, exportcall, pwsync =
2443 ti = as->parms[0].items;
2444 if (strcmp(ti->data, "nfs") == 0)
2445 type = 0x71; /* NFS */
2448 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n",
2452 ti = as->parms[1].items;
2454 if (strcmp(ti->data, "on") == 0)
2456 else if (strcmp(ti->data, "off") == 0)
2459 fprintf(stderr, "Illegal argument %s\n", ti->data);
2464 if (ti = as->parms[2].items) { /* -noconvert */
2465 if (strcmp(ti->data, "on") == 0)
2467 else if (strcmp(ti->data, "off") == 0)
2470 fprintf(stderr, "Illegal argument %s\n", ti->data);
2474 if (ti = as->parms[3].items) { /* -uidcheck */
2475 if (strcmp(ti->data, "on") == 0)
2477 else if (strcmp(ti->data, "off") == 0)
2480 fprintf(stderr, "Illegal argument %s\n", ti->data);
2484 if (ti = as->parms[4].items) { /* -submounts */
2485 if (strcmp(ti->data, "on") == 0)
2487 else if (strcmp(ti->data, "off") == 0)
2490 fprintf(stderr, "Illegal argument %s\n", ti->data);
2495 (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2498 blob.in = (char *)&exportcall;
2499 blob.in_size = sizeof(afs_int32);
2500 blob.out = (char *)&exportcall;
2501 blob.out_size = sizeof(afs_int32);
2502 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2504 if (errno == ENODEV) {
2506 "Sorry, the %s-exporter type is currently not supported on this AFS client\n",
2507 exported_types[type]);
2514 if (exportcall & 1) {
2515 printf("'%s' translator is enabled with the following options:\n",
2516 exported_types[type]);
2517 printf("\tRunning in %s mode\n",
2518 (exportcall & 2 ? "strict unix" :
2519 "convert owner mode bits to world/other"));
2520 printf("\tRunning in %s mode\n",
2521 (exportcall & 4 ? "strict 'passwd sync'" :
2522 "no 'passwd sync'"));
2524 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" :
2525 "Only mounts to /afs allowed"));
2527 printf("'%s' translator is disabled\n", exported_types[type]);
2534 GetCellCmd(struct cmd_syndesc *as)
2537 struct ViceIoctl blob;
2538 struct afsconf_cell info;
2539 struct cmd_item *ti;
2546 memset(&args, '\0', sizeof args); /* avoid Purify UMR error */
2547 for (ti = as->parms[0].items; ti; ti = ti->next) {
2549 blob.out_size = sizeof(args);
2550 blob.out = (caddr_t) & args;
2551 code = GetCellName(ti->data, &info);
2556 blob.in_size = 1 + strlen(info.name);
2557 blob.in = info.name;
2558 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2560 if (errno == ENOENT)
2561 fprintf(stderr, "%s: the cell named '%s' does not exist\n",
2564 Die(errno, info.name);
2568 printf("Cell %s status: ", info.name);
2574 printf("no setuid allowed");
2576 printf("setuid allowed");
2578 printf(", using old VLDB");
2585 SetCellCmd(struct cmd_syndesc *as)
2588 struct ViceIoctl blob;
2589 struct afsconf_cell info;
2590 struct cmd_item *ti;
2598 /* Check arguments. */
2599 if (as->parms[1].items && as->parms[2].items) {
2600 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2604 /* figure stuff to set */
2608 if (!as->parms[1].items)
2609 args.stat |= 2; /* default to -nosuid */
2611 /* set stat for all listed cells */
2612 for (ti = as->parms[0].items; ti; ti = ti->next) {
2614 code = GetCellName(ti->data, &info);
2619 strcpy(args.cname, info.name);
2620 blob.in_size = sizeof(args);
2621 blob.in = (caddr_t) & args;
2623 blob.out = (caddr_t) 0;
2624 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2626 Die(errno, info.name); /* XXX added cell name to Die() call */
2634 GetCellName(char *cellName, struct afsconf_cell *info)
2636 struct afsconf_dir *tdir;
2639 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_DIRPATH);
2642 "Could not process files in configuration directory (%s).\n",
2643 AFSDIR_CLIENT_ETC_DIRPATH);
2647 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2649 fprintf(stderr, "%s: cell %s not in %s\n", pn, cellName,
2650 AFSDIR_CLIENT_CELLSERVDB_FILEPATH);
2659 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2662 struct ktc_principal sname;
2663 struct ktc_token ttoken;
2665 struct rx_securityClass *sc;
2666 struct rx_connection *serverconns[VLDB_MAXSERVERS];
2671 fprintf(stderr, "%s: could not initialize rx.\n", pn);
2675 rx_SetRxDeadTime(50);
2676 if (!noAuthFlag) { /* we don't need tickets for null */
2677 strcpy(sname.cell, info->name);
2678 sname.instance[0] = 0;
2679 strcpy(sname.name, "afs");
2680 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
2683 "%s: Could not get afs tokens, running unauthenticated.\n",
2688 if (ttoken.kvno >= 0 && ttoken.kvno <= 255)
2689 scIndex = 2; /* kerberos */
2691 fprintf(stderr, "%s: funny kvno (%d) in ticket, proceeding\n",
2697 scIndex = 0; /* don't authenticate */
2700 sc = rxnull_NewClientSecurityObject();
2706 sc = (struct rx_securityClass *)
2707 rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
2708 ttoken.kvno, ttoken.ticketLen,
2712 if (info->numServers > VLDB_MAXSERVERS) {
2713 fprintf(stderr, "%s: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n", pn,
2714 info->numServers, VLDB_MAXSERVERS);
2717 memset(serverconns, 0, sizeof(serverconns));
2718 for (i = 0; i < info->numServers; i++)
2720 rx_NewConnection(info->hostAddr[i].sin_addr.s_addr,
2721 info->hostAddr[i].sin_port, USER_SERVICE_ID, sc,
2724 code = ubik_ClientInit(serverconns, &uclient);
2727 fprintf(stderr, "%s: ubik client init failed.\n", pn);
2733 static struct ViceIoctl gblob;
2734 static int debug = 0;
2736 * here follow some routines in suport of the setserverprefs and
2737 * getserverprefs commands. They are:
2738 * SetPrefCmd "top-level" routine
2739 * addServer adds a server to the list of servers to be poked into the
2740 * kernel. Will poke the list into the kernel if it threatens
2742 * pokeServers pokes the existing list of servers and ranks into the kernel
2743 * GetPrefCmd reads the Cache Manager's current list of server ranks
2747 * returns -1 if error message printed,
2749 * errno value if error and no error message printed
2756 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2757 if (code && (errno == EINVAL)) {
2758 struct setspref *ssp;
2759 ssp = (struct setspref *)gblob.in;
2760 if (!(ssp->flags & DBservers)) {
2761 gblob.in = (void *)&(ssp->servers[0]);
2762 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
2763 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
2764 return code ? errno : 0;
2767 "This cache manager does not support VL server preferences.\n");
2771 return code ? errno : 0;
2775 * returns -1 if error message printed,
2777 * errno value if error and no error message printed
2780 addServer(char *name, afs_int32 rank)
2783 struct setspref *ssp;
2785 struct hostent *thostent;
2791 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2793 #define MAXUSHORT ((unsigned short) ~0)
2797 thostent = hostutil_GetHostByName(name);
2799 fprintf(stderr, "%s: couldn't resolve name.\n", name);
2803 ssp = (struct setspref *)(gblob.in);
2805 for (t = 0; thostent->h_addr_list[t]; t++) {
2806 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
2807 code = pokeServers();
2810 ssp->num_servers = 0;
2813 sp = (struct spref *)(gblob.in + gblob.in_size);
2814 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
2815 sizeof(afs_uint32));
2816 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2817 gblob.in_size += sizeof(struct spref);
2821 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
2822 name, sp->rank, sp->server.s_addr);
2830 SetPrefCmd(struct cmd_syndesc *as)
2834 struct cmd_item *ti;
2837 struct setspref *ssp;
2838 int error = 0; /* -1 means error message printed,
2839 * >0 means errno value for unprinted message */
2841 ssp = (struct setspref *)space;
2843 ssp->num_servers = 0;
2844 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2847 gblob.out_size = MAXSIZE;
2851 fprintf(stderr, "Permission denied: requires root access.\n");
2855 ti = as->parms[2].items; /* -file */
2858 fprintf(stderr, "opening file %s\n", ti->data);
2859 if (!(infd = fopen(ti->data, "r"))) {
2863 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2864 code = addServer(name, (unsigned short)rank);
2871 ti = as->parms[3].items; /* -stdin */
2873 while (scanf("%79s%ld", name, &rank) != EOF) {
2874 code = addServer(name, (unsigned short)rank);
2880 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
2885 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
2889 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
2893 code = pokeServers();
2897 printf("now working on vlservers, code=%d\n", code);
2899 ssp = (struct setspref *)space;
2900 ssp->flags = DBservers;
2901 ssp->num_servers = 0;
2902 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2905 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
2910 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
2914 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
2919 if (as->parms[1].items) {
2921 printf("now poking vlservers\n");
2922 code = pokeServers();
2930 return error ? 1 : 0;
2936 GetPrefCmd(struct cmd_syndesc *as)
2939 struct cmd_item *ti;
2940 char *name, tbuffer[20];
2941 afs_int32 rank, addr;
2945 struct ViceIoctl blob;
2946 struct sprefrequest *in;
2947 struct sprefinfo *out;
2950 ti = as->parms[0].items; /* -file */
2953 fprintf(stderr, "opening file %s\n", ti->data);
2954 if (!(outfd = freopen(ti->data, "w", stdout))) {
2960 ti = as->parms[1].items; /* -numeric */
2962 ti = as->parms[2].items; /* -vlservers */
2963 vlservers |= (ti ? DBservers : 0);
2964 /* ti = as->parms[3].items; -cell */
2966 in = (struct sprefrequest *)space;
2970 blob.in_size = sizeof(struct sprefrequest);
2971 blob.in = (char *)in;
2973 blob.out_size = MAXSIZE;
2976 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
2977 in->flags = vlservers;
2979 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
2981 perror("getserverprefs pioctl");
2985 out = (struct sprefinfo *)blob.out;
2987 for (i = 0; i < out->num_servers; i++) {
2989 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
2991 addr = ntohl(out->servers[i].server.s_addr);
2992 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2993 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2996 printf("%-50s %5u\n", name, out->servers[i].rank);
2999 in->offset = out->next_offset;
3000 } while (out->next_offset > 0);
3006 StoreBehindCmd(struct cmd_syndesc *as)
3009 struct ViceIoctl blob;
3010 struct cmd_item *ti;
3011 struct sbstruct tsb, tsb2;
3017 tsb.sb_thisfile = -1;
3018 ti = as->parms[0].items; /* -kbytes */
3020 if (!as->parms[1].items) {
3021 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3025 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3026 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3027 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3033 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3034 ti = as->parms[2].items; /* -allfiles */
3036 allfiles = strtol(ti->data, &t, 10) * 1024;
3037 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3038 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3044 /* -verbose or -file only or no options */
3045 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3046 || (!as->parms[0].items && !as->parms[1].items
3047 && !as->parms[2].items))
3050 blob.in = (char *)&tsb;
3051 blob.out = (char *)&tsb2;
3052 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3053 memset(&tsb2, 0, sizeof(tsb2));
3055 /* once per -file */
3056 for (ti = as->parms[1].items; ti; ti = ti->next) {
3057 /* Do this solely to see if the file is there */
3058 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3060 Die(errno, ti->data);
3065 code = pioctl(ti->data, VIOC_STORBEHIND, &blob, 1);
3067 Die(errno, ti->data);
3072 if (verbose && (blob.out_size == sizeof(tsb2))) {
3073 if (tsb2.sb_thisfile == -1) {
3074 fprintf(stdout, "Will store %s according to default.\n",
3078 "Will store up to %d kbytes of %s asynchronously.\n",
3079 (tsb2.sb_thisfile / 1024), ti->data);
3084 /* If no files - make at least one pioctl call, or
3085 * set the allfiles default if we need to.
3087 if (!as->parms[1].items || (allfiles != -1)) {
3088 tsb.sb_default = allfiles;
3089 code = pioctl(0, VIOC_STORBEHIND, &blob, 1);
3091 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3096 /* Having no arguments also reports the default store asynchrony */
3097 if (verbose && (blob.out_size == sizeof(tsb2))) {
3098 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3099 (tsb2.sb_default / 1024));
3107 SetCryptCmd(struct cmd_syndesc *as)
3109 afs_int32 code = 0, flag;
3110 struct ViceIoctl blob;
3113 tp = as->parms[0].items->data;
3114 if (strcmp(tp, "on") == 0)
3116 else if (strcmp(tp, "off") == 0)
3119 fprintf(stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3123 blob.in = (char *)&flag;
3124 blob.in_size = sizeof(flag);
3126 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3134 GetCryptCmd(struct cmd_syndesc *as)
3136 afs_int32 code = 0, flag;
3137 struct ViceIoctl blob;
3142 blob.out_size = sizeof(flag);
3145 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3151 memcpy(&flag, tp, sizeof(afs_int32));
3152 printf("Security level is currently ");
3154 printf("crypt (data security).\n");
3161 #include "AFS_component_version_number.c"
3164 main(int argc, char **argv)
3167 struct cmd_syndesc *ts;
3169 #ifdef AFS_AIX32_ENV
3171 * The following signal action for AIX is necessary so that in case of a
3172 * crash (i.e. core is generated) we can include the user's data section
3173 * in the core dump. Unfortunately, by default, only a partial core is
3174 * generated which, in many cases, isn't too useful.
3176 struct sigaction nsa;
3178 sigemptyset(&nsa.sa_mask);
3179 nsa.sa_handler = SIG_DFL;
3180 nsa.sa_flags = SA_FULLDUMP;
3181 sigaction(SIGSEGV, &nsa, NULL);
3184 /* try to find volume location information */
3185 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0,
3186 "get client network interface addresses");
3187 cmd_CreateAlias(ts, "gc");
3189 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0,
3190 "set client network interface addresses");
3191 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3192 "client network interfaces");
3193 cmd_CreateAlias(ts, "sc");
3195 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0,
3196 "set server ranks");
3197 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3198 "fileserver names and ranks");
3199 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
3200 "VL server names and ranks");
3201 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3202 "input from named file");
3203 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3204 cmd_CreateAlias(ts, "sp");
3206 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0,
3207 "get server ranks");
3208 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
3209 "output to named file");
3210 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3211 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3212 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3213 cmd_CreateAlias(ts, "gp");
3215 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
3216 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3217 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3218 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3219 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL,
3220 "apply to negative rights");
3221 parm_setacl_id = ts->nParms;
3222 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL,
3223 "initial directory acl (DFS only)");
3224 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL,
3225 "initial file acl (DFS only)");
3226 cmd_CreateAlias(ts, "sa");
3228 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0,
3229 "list access control list");
3230 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3231 parm_listacl_id = ts->nParms;
3232 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3233 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3234 cmd_CreateAlias(ts, "la");
3236 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0,
3237 "clean up access control list");
3238 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3240 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0,
3241 "copy access control list");
3242 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0,
3243 "source directory (or DFS file)");
3244 cmd_AddParm(ts, "-todir", CMD_LIST, 0,
3245 "destination directory (or DFS file)");
3246 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL,
3247 "first clear dest access list");
3248 parm_copyacl_id = ts->nParms;
3249 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3250 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3252 cmd_CreateAlias(ts, "ca");
3254 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
3255 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3256 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0,
3257 "flush mount symlink from cache");
3258 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3260 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
3261 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3262 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL,
3263 "disk space quota in 1K units");
3265 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL,
3266 "disk space guaranteed");
3267 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3269 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL,
3271 cmd_CreateAlias(ts, "sv");
3273 ts = cmd_CreateSyntax("messages", MessagesCmd, 0,
3274 "control Cache Manager messages");
3275 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL,
3276 "[user|console|all|none]");
3278 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display file/volume status");
3279 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3280 cmd_CreateAlias(ts, "lv");
3281 cmd_CreateAlias(ts, "listvol");
3283 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
3284 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3285 cmd_CreateAlias(ts, "lq");
3287 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0,
3288 "show server disk space usage");
3289 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3290 cmd_CreateAlias(ts, "df");
3292 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
3293 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3295 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
3296 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3298 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
3299 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3300 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3301 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3302 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3303 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3304 "don't check name with VLDB");
3310 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3314 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
3315 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3317 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0,
3318 "check local cell's servers");
3319 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3320 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3321 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL,
3322 "just list, don't check");
3323 cmd_AddParm(ts, "-interval", CMD_SINGLE, CMD_OPTIONAL,
3324 "seconds between probes");
3326 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, 0,
3327 "check volumeID/name mappings");
3328 cmd_CreateAlias(ts, "checkbackups");
3331 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0,
3333 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL,
3334 "size in 1K byte blocks (0 => reset)");
3335 cmd_CreateAlias(ts, "cachesize");
3337 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL,
3338 "reset size back to boot value");
3340 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0,
3341 "get cache usage info");
3343 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0,
3344 "list configured cells");
3345 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3347 ts = cmd_CreateSyntax("listaliases", ListAliasesCmd, 0,
3348 "list configured cell aliases");
3350 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
3351 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3352 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3354 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3356 cmd_CreateAlias(ts, "sq");
3358 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
3359 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3360 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3361 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL,
3362 "linked cell name");
3364 ts = cmd_CreateSyntax("newalias", NewAliasCmd, 0,
3365 "configure new cell alias");
3366 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
3367 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
3369 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3371 * Turn this on only if you wish to be able to talk to a server which is listening
3372 * on alternative ports. This is not intended for general use and may not be
3373 * supported in the cache manager. It is not a way to run two servers at the
3374 * same host, since the cache manager cannot properly distinguish those two hosts.
3376 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL,
3377 "cell's fileserver port");
3378 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL,
3379 "cell's vldb server port");
3382 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
3383 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3385 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
3386 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3388 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
3391 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
3394 /* set cache monitor host address */
3395 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, (char *)CMD_HIDDEN);
3396 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL,
3397 "host name or 'off'");
3398 cmd_CreateAlias(ts, "mariner");
3400 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
3401 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3403 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
3404 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3405 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3406 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL,
3407 "disallow setuid programs");
3409 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0,
3410 "flush all data in volume");
3411 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3413 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0,
3414 "get/set sysname (i.e. @sys) value");
3415 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3417 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0,
3418 "enable/disable translators to AFS");
3419 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3420 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL,
3421 "start/stop translator (on | off)");
3422 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL,
3423 "convert from afs to unix mode (on | off)");
3424 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL,
3425 "run on strict 'uid check' mode (on | off)");
3426 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL,
3427 "allow nfs mounts to subdirs of /afs/.. (on | off)");
3430 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
3431 "store to server after file close");
3432 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL,
3433 "asynchrony for specified names");
3434 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3435 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL,
3436 "new default (KB)");
3437 cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "show status");
3438 cmd_CreateAlias(ts, "sb");
3440 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0,
3441 "set cache manager encryption flag");
3442 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3444 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0,
3445 "set cache manager encryption flag");
3447 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
3448 "Manage per process RX statistics");
3449 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3450 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3451 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3453 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0,
3454 "Manage per peer RX statistics");
3455 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
3456 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
3457 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
3459 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, 0, "configure callback connection address");
3460 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
3462 code = cmd_Dispatch(argc, argv);
3470 Die(int errnum, char *filename)
3476 "%s: Invalid argument; it is possible that %s is not in AFS.\n",
3479 fprintf(stderr, "%s: Invalid argument.\n", pn);
3483 fprintf(stderr, "%s: File '%s' doesn't exist\n", pn, filename);
3485 fprintf(stderr, "%s: no such file returned\n", pn);
3489 "%s: You can not change a backup or readonly volume\n", pn);
3495 "%s: You don't have the required access rights on '%s'\n",
3499 "%s: You do not have the required rights to do this operation\n",
3504 fprintf(stderr, "%s:'%s'", pn, filename);
3506 fprintf(stderr, "%s", pn);
3507 fprintf(stderr, ": %s\n", error_message(errnum));
3512 /* get clients interface addresses */
3514 GetClientAddrsCmd(struct cmd_syndesc *as)
3517 struct cmd_item *ti;
3519 struct ViceIoctl blob;
3520 struct sprefrequest *in;
3521 struct sprefinfo *out;
3523 in = (struct sprefrequest *)space;
3527 blob.in_size = sizeof(struct sprefrequest);
3528 blob.in = (char *)in;
3530 blob.out_size = MAXSIZE;
3533 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3534 /* returns addr in network byte order */
3535 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
3537 perror("getClientInterfaceAddr pioctl");
3543 out = (struct sprefinfo *)blob.out;
3544 for (i = 0; i < out->num_servers; i++) {
3547 addr = ntohl(out->servers[i].server.s_addr);
3548 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3549 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3550 printf("%-50s\n", tbuffer);
3552 in->offset = out->next_offset;
3554 } while (out->next_offset > 0);
3560 SetClientAddrsCmd(struct cmd_syndesc *as)
3562 afs_int32 code, addr;
3563 struct cmd_item *ti;
3565 struct ViceIoctl blob;
3566 struct setspref *ssp;
3567 int sizeUsed = 0, i, flag;
3568 afs_int32 existingAddr[1024]; /* existing addresses on this host */
3572 ssp = (struct setspref *)space;
3573 ssp->num_servers = 0;
3576 blob.out_size = MAXSIZE;
3579 fprintf(stderr, "Permission denied: requires root access.\n");
3583 /* extract all existing interface addresses */
3584 existNu = rx_getAllAddr(existingAddr, 1024);
3588 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
3589 for (ti = as->parms[0].items; ti; ti = ti->next) {
3590 if (sizeUsed >= sizeof(space)) {
3591 fprintf(stderr, "No more space\n");
3594 addr = extractAddr(ti->data, 20); /* network order */
3595 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
3596 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
3601 /* see if it is an address that really exists */
3602 for (flag = 0, i = 0; i < existNu; i++)
3603 if (existingAddr[i] == addr) {
3607 if (!flag) { /* this is an nonexistent address */
3608 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
3612 /* copy all specified addr into ioctl buffer */
3613 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
3614 printf("Adding 0x%08x\n", addr);
3616 sizeUsed += sizeof(struct spref);
3618 if (ssp->num_servers < 1) {
3619 fprintf(stderr, "No addresses specified\n");
3622 blob.in_size = sizeUsed - sizeof(struct spref);
3624 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
3634 FlushMountCmd(struct cmd_syndesc *as)
3637 struct ViceIoctl blob;
3638 struct cmd_item *ti;
3639 char orig_name[1024]; /*Original name, may be modified */
3640 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
3641 char parent_dir[1024]; /*Parent directory of true name */
3642 char *last_component; /*Last component of true name */
3643 struct stat statbuff; /*Buffer for status info */
3644 int link_chars_read; /*Num chars read in readlink() */
3645 int thru_symlink; /*Did we get to a mount point via a symlink? */
3648 for (ti = as->parms[0].items; ti; ti = ti->next) {
3651 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
3654 if (lstat(orig_name, &statbuff) < 0) {
3655 /* if lstat fails, we should still try the pioctl, since it
3656 * may work (for example, lstat will fail, but pioctl will
3657 * work if the volume of offline (returning ENODEV). */
3658 statbuff.st_mode = S_IFDIR; /* lie like pros */
3662 * The lstat succeeded. If the given file is a symlink, substitute
3663 * the file name with the link name.
3665 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
3668 * Read name of resolved file.
3670 link_chars_read = readlink(orig_name, true_name, 1024);
3671 if (link_chars_read <= 0) {
3673 "%s: Can't read target name for '%s' symbolic link!\n",
3680 * Add a trailing null to what was read, bump the length.
3682 true_name[link_chars_read++] = 0;
3685 * If the symlink is an absolute pathname, we're fine. Otherwise, we
3686 * have to create a full pathname using the original name and the
3687 * relative symlink name. Find the rightmost slash in the original
3688 * name (we know there is one) and splice in the symlink value.
3690 if (true_name[0] != '/') {
3691 last_component = (char *)strrchr(orig_name, '/');
3692 strcpy(++last_component, true_name);
3693 strcpy(true_name, orig_name);
3696 strcpy(true_name, orig_name);
3699 * Find rightmost slash, if any.
3701 last_component = (char *)strrchr(true_name, '/');
3702 if (last_component) {
3704 * Found it. Designate everything before it as the parent directory,
3705 * everything after it as the final component.
3707 strncpy(parent_dir, true_name, last_component - true_name);
3708 parent_dir[last_component - true_name] = 0;
3709 last_component++; /*Skip the slash */
3712 * No slash appears in the given file name. Set parent_dir to the current
3713 * directory, and the last component as the given name.
3715 strcpy(parent_dir, ".");
3716 last_component = true_name;
3719 if (strcmp(last_component, ".") == 0
3720 || strcmp(last_component, "..") == 0) {
3722 "%s: you may not use '.' or '..' as the last component\n",
3724 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
3730 blob.in = last_component;
3731 blob.in_size = strlen(last_component) + 1;
3733 memset(space, 0, MAXSIZE);
3735 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
3738 if (errno == EINVAL) {
3739 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
3741 Die(errno, (ti->data ? ti->data : parent_dir));
3750 RxStatProcCmd(struct cmd_syndesc *as)
3753 afs_int32 flags = 0;
3754 struct ViceIoctl blob;
3755 struct cmd_item *ti;
3757 if (as->parms[0].items) { /* -enable */
3758 flags |= AFSCALL_RXSTATS_ENABLE;
3760 if (as->parms[1].items) { /* -disable */
3761 flags |= AFSCALL_RXSTATS_DISABLE;
3763 if (as->parms[2].items) { /* -clear */
3764 flags |= AFSCALL_RXSTATS_CLEAR;
3767 fprintf(stderr, "You must specify at least one argument\n");
3771 blob.in = (char *)&flags;
3772 blob.in_size = sizeof(afs_int32);
3775 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
3785 RxStatPeerCmd(struct cmd_syndesc *as)
3788 afs_int32 flags = 0;
3789 struct ViceIoctl blob;
3790 struct cmd_item *ti;
3792 if (as->parms[0].items) { /* -enable */
3793 flags |= AFSCALL_RXSTATS_ENABLE;
3795 if (as->parms[1].items) { /* -disable */
3796 flags |= AFSCALL_RXSTATS_DISABLE;
3798 if (as->parms[2].items) { /* -clear */
3799 flags |= AFSCALL_RXSTATS_CLEAR;
3802 fprintf(stderr, "You must specify at least one argument\n");
3806 blob.in = (char *)&flags;
3807 blob.in_size = sizeof(afs_int32);
3810 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);