2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afs/param.h>
22 #include <rx/rx_globals.h>
26 #include <afs/cellconfig.h>
27 #include <afs/ptserver.h>
28 #include <afs/ptuser.h>
29 #include <afs/volser.h>
30 #include <WINNT\afsreg.h>
40 #define MAXCELLHOSTS 8
43 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
44 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
45 #define MAXCELLCHARS 64
46 #define MAXHOSTCHARS 64
48 static char space[MAXSIZE];
49 static char tspace[1024];
51 static struct ubik_client *uclient;
53 static int GetClientAddrsCmd(struct cmd_syndesc *asp, char *arock);
54 static int SetClientAddrsCmd(struct cmd_syndesc *asp, char *arock);
55 static int FlushMountCmd(struct cmd_syndesc *asp, char *arock);
56 static int RxStatProcCmd(struct cmd_syndesc *asp, char *arock);
57 static int RxStatPeerCmd(struct cmd_syndesc *asp, char *arock);
59 extern struct cmd_syndesc *cmd_CreateSyntax();
61 static int MemDumpCmd(struct cmd_syndesc *asp, char *arock);
62 static int CSCPolicyCmd(struct cmd_syndesc *asp, char *arock);
63 static int MiniDumpCmd(struct cmd_syndesc *asp, char *arock);
65 static char pn[] = "fs";
66 static int rxInitDone = 0;
69 * Character to use between name and rights in printed representation for
72 #define DFS_SEPARATOR ' '
74 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
77 int dfs; /* Originally true if a dfs acl; now also the type
78 * of the acl (1, 2, or 3, corresponding to object,
79 * initial dir, or initial object). */
80 sec_rgy_name_t cell; /* DFS cell name */
83 struct AclEntry *pluslist;
84 struct AclEntry *minuslist;
88 struct AclEntry *next;
94 ZapAcl (struct Acl *acl)
99 ZapList(acl->pluslist);
100 ZapList(acl->minuslist);
105 * Mods for the AFS/DFS protocol translator.
107 * DFS rights. It's ugly to put these definitions here, but they
108 * *cannot* change, because they're part of the wire protocol.
109 * In any event, the protocol translator will guarantee these
110 * assignments for AFS cache managers.
112 #define DFS_READ 0x01
113 #define DFS_WRITE 0x02
114 #define DFS_EXECUTE 0x04
115 #define DFS_CONTROL 0x08
116 #define DFS_INSERT 0x10
117 #define DFS_DELETE 0x20
119 /* the application definable ones (backwards from AFS) */
120 #define DFS_USR0 0x80000000 /* "A" bit */
121 #define DFS_USR1 0x40000000 /* "B" bit */
122 #define DFS_USR2 0x20000000 /* "C" bit */
123 #define DFS_USR3 0x10000000 /* "D" bit */
124 #define DFS_USR4 0x08000000 /* "E" bit */
125 #define DFS_USR5 0x04000000 /* "F" bit */
126 #define DFS_USR6 0x02000000 /* "G" bit */
127 #define DFS_USR7 0x01000000 /* "H" bit */
128 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
129 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
132 * Offset of -id switch in command structure for various commands.
133 * The -if switch is the next switch always.
135 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
138 * Determine whether either the -id or -if switches are present, and
139 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
141 /* int id; Offset of -id switch; -if is next switch */
143 getidf(struct cmd_syndesc *as, int id)
147 if (as->parms[id].items) {
150 if (as->parms[id + 1].items) {
155 "%s: you may specify either -id or -if, but not both switches\n",
163 PRights(afs_int32 arights, int dfs)
166 if (arights & PRSFS_READ)
168 if (arights & PRSFS_LOOKUP)
170 if (arights & PRSFS_INSERT)
172 if (arights & PRSFS_DELETE)
174 if (arights & PRSFS_WRITE)
176 if (arights & PRSFS_LOCK)
178 if (arights & PRSFS_ADMINISTER)
180 if (arights & PRSFS_USR0)
182 if (arights & PRSFS_USR1)
184 if (arights & PRSFS_USR2)
186 if (arights & PRSFS_USR3)
188 if (arights & PRSFS_USR4)
190 if (arights & PRSFS_USR5)
192 if (arights & PRSFS_USR6)
194 if (arights & PRSFS_USR7)
197 if (arights & DFS_READ)
201 if (arights & DFS_WRITE)
205 if (arights & DFS_EXECUTE)
209 if (arights & DFS_CONTROL)
213 if (arights & DFS_INSERT)
217 if (arights & DFS_DELETE)
221 if (arights & (DFS_USRALL))
223 if (arights & DFS_USR0)
225 if (arights & DFS_USR1)
227 if (arights & DFS_USR2)
229 if (arights & DFS_USR3)
231 if (arights & DFS_USR4)
233 if (arights & DFS_USR5)
235 if (arights & DFS_USR6)
237 if (arights & DFS_USR7)
243 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
247 struct ViceIoctl blob;
251 blob.out_size = MAXSIZE;
254 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
256 if ((errno == EINVAL) || (errno == ENOENT))
263 IsFreelanceRoot(char *apath)
265 struct ViceIoctl blob;
269 blob.out_size = MAXSIZE;
272 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
274 return !strcmp("Freelance.Local.Root",space);
275 return 1; /* assume it is because it is more restrictive that way */
278 /* return a static pointer to a buffer */
283 strcpy(tspace, apath);
284 tp = strrchr(tspace, '\\');
286 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
289 fs_ExtractDriveLetter(apath, tspace);
295 enum rtype {add, destroy, deny};
298 Convert(char *arights, int dfs, enum rtype *rtypep)
304 *rtypep = add; /* add rights, by default */
307 if (!strcmp(arights, "null")) {
311 if (!strcmp(arights,"read"))
312 return DFS_READ | DFS_EXECUTE;
313 if (!strcmp(arights, "write"))
314 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
316 if (!strcmp(arights, "all"))
317 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
318 DFS_WRITE | DFS_CONTROL;
320 if (!strcmp(arights,"read"))
321 return PRSFS_READ | PRSFS_LOOKUP;
322 if (!strcmp(arights, "write"))
323 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
324 PRSFS_WRITE | PRSFS_LOCK;
325 if (!strcmp(arights, "mail"))
326 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
327 if (!strcmp(arights, "all"))
328 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
329 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
331 if (!strcmp(arights, "none")) {
332 *rtypep = destroy; /* Remove entire entry */
335 len = (int)strlen(arights);
371 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
379 mode |= PRSFS_LOOKUP;
381 mode |= PRSFS_INSERT;
383 mode |= PRSFS_DELETE;
389 mode |= PRSFS_ADMINISTER;
407 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
416 static struct AclEntry *
417 FindList (struct AclEntry *alist, char *aname)
420 if (!strcasecmp(alist->name, aname))
427 /* if no parm specified in a particular slot, set parm to be "." instead */
429 SetDotDefault(struct cmd_item **aitemp)
433 return; /* already has value */
434 /* otherwise, allocate an item representing "." */
435 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
437 ti->next = (struct cmd_item *) 0;
438 ti->data = (char *) malloc(2);
440 strcpy(ti->data, ".");
445 ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
447 struct AclEntry *tlist;
448 tlist = (plus ? al->pluslist : al->minuslist);
449 tlist = FindList (tlist, aname);
451 /* Found the item already in the list. */
452 tlist->rights = arights;
454 al->nplus -= PruneList(&al->pluslist, al->dfs);
456 al->nminus -= PruneList(&al->minuslist, al->dfs);
459 /* Otherwise we make a new item and plug in the new data. */
460 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
462 strcpy(tlist->name, aname);
463 tlist->rights = arights;
465 tlist->next = al->pluslist;
466 al->pluslist = tlist;
468 if (arights == 0 || arights == -1)
469 al->nplus -= PruneList(&al->pluslist, al->dfs);
471 tlist->next = al->minuslist;
472 al->minuslist = tlist;
475 al->nminus -= PruneList(&al->minuslist, al->dfs);
480 ZapList (struct AclEntry *alist)
482 struct AclEntry *tp, *np;
483 for (tp = alist; tp; tp = np) {
490 PruneList (struct AclEntry **ae, int dfs)
492 struct AclEntry **lp;
493 struct AclEntry *te, *ne;
497 for(te = *ae;te;te=ne) {
498 if ((!dfs && te->rights == 0) || te->rights == -1) {
512 SkipLine (char *astr)
521 * Create an empty acl, taking into account whether the acl pointed
522 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
523 * can recover from problems caused by bogus ACL's (in that case, always
524 * assume that the acl is AFS: for DFS, the user can always resort to
525 * acl_edit, but for AFS there may be no other way out).
533 tp = (struct Acl *)malloc(sizeof (struct Acl));
535 tp->nplus = tp->nminus = 0;
536 tp->pluslist = tp->minuslist = 0;
538 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
543 ParseAcl (char *astr)
545 int nplus, nminus, i, trights;
547 struct AclEntry *first, *last, *tl;
550 ta = (struct Acl *) malloc (sizeof (struct Acl));
553 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
554 astr = SkipLine(astr);
555 sscanf(astr, "%d", &ta->nminus);
556 astr = SkipLine(astr);
563 for(i=0;i<nplus;i++) {
564 sscanf(astr, "%100s %d", tname, &trights);
565 astr = SkipLine(astr);
566 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
570 strcpy(tl->name, tname);
571 tl->rights = trights;
577 ta->pluslist = first;
581 for(i=0;i<nminus;i++) {
582 sscanf(astr, "%100s %d", tname, &trights);
583 astr = SkipLine(astr);
584 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
588 strcpy(tl->name, tname);
589 tl->rights = trights;
595 ta->minuslist = first;
601 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
603 printf("Volume status for vid = %u named %s\n",status->Vid, name);
605 printf("Current offline message is %s\n",offmsg);
607 printf("Current message of the day is %s\n",motd);
608 printf("Current disk quota is ");
609 if (status->MaxQuota != 0)
610 printf("%d\n", status->MaxQuota);
612 printf("unlimited\n");
613 printf("Current blocks used are %d\n",status->BlocksInUse);
614 printf("The partition has %d blocks available out of %d\n\n",
615 status->PartBlocksAvail, status->PartMaxBlocks);
620 QuickPrintStatus(VolumeStatus *status, char *name)
622 double QuotaUsed =0.0;
623 double PartUsed =0.0;
625 printf("%-25.25s",name);
627 if (status->MaxQuota != 0) {
628 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
629 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
631 printf("no limit%10d", status->BlocksInUse);
633 if (QuotaUsed > 90.0){
634 printf(" %5.0f%%<<", QuotaUsed);
637 printf(" %5.0f%% ", QuotaUsed);
638 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
639 if (PartUsed > 97.0){
640 printf(" %9.0f%%<<", PartUsed);
643 printf(" %9.0f%% ", PartUsed);
645 printf(" <<WARNING\n");
652 QuickPrintSpace(VolumeStatus *status, char *name)
654 double PartUsed =0.0;
656 printf("%-25.25s",name);
658 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
660 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
661 if (PartUsed > 90.0){
662 printf(" %4.0f%%<<", PartUsed);
665 printf(" %4.0f%% ", PartUsed);
667 printf(" <<WARNING\n");
674 AclToString(struct Acl *acl)
676 static char mydata[MAXSIZE];
677 char tstring[MAXSIZE];
682 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
685 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
686 for (tp = acl->pluslist;tp;tp=tp->next) {
687 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
688 strcat(mydata, tstring);
690 for (tp = acl->minuslist;tp;tp=tp->next) {
691 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
692 strcat(mydata, tstring);
697 static DWORD IsFreelance(void)
704 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
705 0, KEY_QUERY_VALUE, &parmKey);
706 if (code == ERROR_SUCCESS) {
707 dummyLen = sizeof(cm_freelanceEnabled);
708 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
709 (BYTE *) &enabled, &dummyLen);
710 RegCloseKey (parmKey);
715 static const char * NetbiosName(void)
717 static char buffer[1024] = "AFS";
723 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
724 0, KEY_QUERY_VALUE, &parmKey);
725 if (code == ERROR_SUCCESS) {
726 dummyLen = sizeof(buffer);
727 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
729 RegCloseKey (parmKey);
731 strcpy(buffer, "AFS");
736 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
738 static BOOL IsAdmin (void)
740 static BOOL fAdmin = FALSE;
741 static BOOL fTested = FALSE;
745 /* Obtain the SID for the AFS client admin group. If the group does
746 * not exist, then assume we have AFS client admin privileges.
748 PSID psidAdmin = NULL;
749 DWORD dwSize, dwSize2;
750 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
751 char *pszRefDomain = NULL;
752 SID_NAME_USE snu = SidTypeGroup;
754 dwSize = sizeof(pszAdminGroup);
756 if (!GetComputerName(pszAdminGroup, &dwSize)) {
757 /* Can't get computer name. We return false in this case.
758 Retain fAdmin and fTested. This shouldn't happen.*/
765 strcat(pszAdminGroup,"\\");
766 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
768 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
769 /* that should always fail. */
771 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
772 /* if we can't find the group, then we allow the operation */
777 if (dwSize == 0 || dwSize2 == 0) {
783 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
785 pszRefDomain = (char *)malloc(dwSize2);
786 assert(pszRefDomain);
788 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
789 /* We can't lookup the group now even though we looked it up earlier.
790 Could this happen? */
793 /* Then open our current ProcessToken */
796 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
799 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
800 /* We'll have to allocate a chunk of memory to store the list of
801 * groups to which this user belongs; find out how much memory
805 PTOKEN_GROUPS pGroups;
807 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
809 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
812 /* Allocate that buffer, and read in the list of groups. */
813 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
815 /* Look through the list of group SIDs and see if any of them
816 * matches the AFS Client Admin group SID.
819 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
821 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
831 /* if do not have permission because we were not explicitly listed
832 * in the Admin Client Group let's see if we are the SYSTEM account
835 PTOKEN_USER pTokenUser;
836 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
837 PSID pSidLocalSystem = 0;
840 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
842 pTokenUser = (PTOKEN_USER)malloc(dwSize);
845 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
846 gle = GetLastError();
848 if (AllocateAndInitializeSid( &SIDAuth, 1,
849 SECURITY_LOCAL_SYSTEM_RID,
853 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
857 FreeSid(pSidLocalSystem);
876 SetACLCmd(struct cmd_syndesc *as, char *arock)
879 struct ViceIoctl blob;
881 struct cmd_item *ti, *ui;
885 int idf = getidf(as, parm_setacl_id);
889 if (as->parms[2].items)
893 plusp = !(as->parms[3].items);
894 for(ti=as->parms[0].items; ti;ti=ti->next) {
895 blob.out_size = MAXSIZE;
897 blob.in = blob.out = space;
898 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
900 Die(errno, ti->data);
906 ta = ParseAcl(space);
907 if (!plusp && ta->dfs) {
909 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
911 "(you may specify \"null\" to revoke all rights, however)\n");
918 ta = EmptyAcl(space);
920 ta = ParseAcl(space);
921 CleanAcl(ta, ti->data);
922 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
926 "%s: Missing second half of user/access pair.\n", pn);
930 rights = Convert(ui->next->data, ta->dfs, &rtype);
931 if (rtype == destroy && !ta->dfs) {
932 struct AclEntry *tlist;
934 tlist = (plusp ? ta->pluslist : ta->minuslist);
935 if (!FindList(tlist, ui->data))
938 if (rtype == deny && !ta->dfs)
940 if (rtype == destroy && ta->dfs)
942 ChangeList(ta, plusp, ui->data, rights);
944 blob.in = AclToString(ta);
946 blob.in_size = 1+(long)strlen(blob.in);
947 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
949 if (errno == EINVAL) {
951 static char *fsenv = 0;
953 fsenv = (char *)getenv("FS_EXPERT");
955 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
958 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
959 "\nPossible reasons for this include:\n\n",
960 " -You may have specified an inappropriate combination of rights.\n",
961 " For example, some DFS-supported filesystems may not allow you to\n",
962 " drop the \"c\" right from \"user_obj\".\n\n",
963 " -A mask_obj may be required (it is likely required by the underlying\n",
964 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
965 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
966 " does not automatically create or update the mask_obj. Try setting\n",
967 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
968 " users or groups. You can do this with a single command, such as\n",
969 " \"fs sa mask_obj all user:somename read\"\n\n",
970 " -A specified user or group may not exist.\n\n",
971 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
972 " This is probably not allowed by the underlying file system.\n\n",
973 " -If you add a user or group to a DFS ACL, remember that it must be\n",
974 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
975 " may be local requirements on the format of the user or group name.\n",
976 " Check with your cell administrator.\n\n",
977 " -Or numerous other possibilities. It would be great if we could be more\n",
978 " precise about the actual problem, but for various reasons, this is\n",
979 " impractical via this interface. If you can't figure it out, you\n",
980 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
981 " whatever is provided). You may get better results. Good luck!\n\n",
982 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
986 "%s: Invalid argument, possible reasons include:\n",
988 fprintf(stderr,"\t-File not in AFS\n");
990 "\t-Too many users on access control list\n");
992 "\t-Tried to add non-existent user to access control list\n");
995 Die(errno, ti->data);
1006 CopyACLCmd(struct cmd_syndesc *as, char *arock)
1009 struct ViceIoctl blob;
1010 struct Acl *fa, *ta = 0;
1011 struct AclEntry *tp;
1012 struct cmd_item *ti;
1014 int idf = getidf(as, parm_copyacl_id);
1017 if (as->parms[2].items)
1021 blob.out_size = MAXSIZE;
1023 blob.in = blob.out = space;
1024 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1026 Die(errno, as->parms[0].items->data);
1029 fa = ParseAcl(space);
1030 CleanAcl(fa, as->parms[0].items->data);
1031 for (ti=as->parms[1].items; ti;ti=ti->next) {
1032 blob.out_size = MAXSIZE;
1034 blob.in = blob.out = space;
1035 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1037 Die(errno, ti->data);
1044 ta = EmptyAcl(space);
1046 ta = ParseAcl(space);
1047 CleanAcl(ta, ti->data);
1048 if (ta->dfs != fa->dfs) {
1050 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1056 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1058 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1063 strcpy(ta->cell, fa->cell);
1065 for (tp = fa->pluslist;tp;tp=tp->next)
1066 ChangeList(ta, 1, tp->name, tp->rights);
1067 for (tp = fa->minuslist;tp;tp=tp->next)
1068 ChangeList(ta, 0, tp->name, tp->rights);
1069 blob.in = AclToString(ta);
1071 blob.in_size = 1+(long)strlen(blob.in);
1072 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1074 if (errno == EINVAL) {
1076 "%s: Invalid argument, possible reasons include:\n", pn);
1077 fprintf(stderr,"\t-File not in AFS\n");
1079 Die(errno, ti->data);
1090 /* pioctl() call to get the cellname of a pathname */
1092 GetCell(char *fname, char *cellname)
1095 struct ViceIoctl blob;
1098 blob.out_size = MAXCELLCHARS;
1099 blob.out = cellname;
1101 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1102 return code ? errno : 0;
1105 /* Check if a username is valid: If it contains only digits (or a
1106 * negative sign), then it might be bad. We then query the ptserver
1110 BadName(char *aname, char *fname)
1112 afs_int32 tc, code, id;
1114 char cell[MAXCELLCHARS];
1116 for ( nm = aname; tc = *nm; nm++) {
1117 /* all must be '-' or digit to be bad */
1118 if (tc != '-' && (tc < '0' || tc > '9'))
1122 /* Go to the PRDB and see if this all number username is valid */
1123 code = GetCell(fname, cell);
1127 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
1128 code = pr_SNameToId(aname, &id);
1131 /* 1=>Not-valid; 0=>Valid */
1132 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1136 /* clean up an access control list of its bad entries; return 1 if we made
1137 any changes to the list, and 0 otherwise */
1139 CleanAcl(struct Acl *aa, char *fname)
1141 struct AclEntry *te, **le, *ne;
1144 /* Don't correct DFS ACL's for now */
1148 /* prune out bad entries */
1149 changes = 0; /* count deleted entries */
1151 for(te = aa->pluslist; te; te=ne) {
1153 if (BadName(te->name, fname)) {
1163 le = &aa->minuslist;
1164 for(te = aa->minuslist; te; te=ne) {
1166 if (BadName(te->name, fname)) {
1180 /* clean up an acl to not have bogus entries */
1182 CleanACLCmd(struct cmd_syndesc *as, char *arock)
1186 struct ViceIoctl blob;
1188 struct cmd_item *ti;
1189 struct AclEntry *te;
1192 SetDotDefault(&as->parms[0].items);
1193 for(ti=as->parms[0].items; ti; ti=ti->next) {
1194 blob.out_size = MAXSIZE;
1197 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1199 Die(errno, ti->data);
1205 ta = ParseAcl(space);
1209 "%s: cleanacl is not supported for DFS access lists.\n",
1215 changes = CleanAcl(ta, ti->data);
1218 /* now set the acl */
1219 blob.in=AclToString(ta);
1220 blob.in_size = (long)strlen(blob.in)+1;
1222 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1224 if (errno == EINVAL) {
1226 "%s: Invalid argument, possible reasons include\n",
1228 fprintf(stderr,"%s: File not in vice or\n", pn);
1230 "%s: Too many users on access control list or\n",
1233 Die(errno, ti->data);
1239 /* now list the updated acl */
1240 printf("Access list for %s is now\n", ti->data);
1241 if (ta->nplus > 0) {
1243 printf("Normal rights:\n");
1244 for(te = ta->pluslist;te;te=te->next) {
1245 printf(" %s ", te->name);
1246 PRights(te->rights, ta->dfs);
1250 if (ta->nminus > 0) {
1251 printf("Negative rights:\n");
1252 for(te = ta->minuslist;te;te=te->next) {
1253 printf(" %s ", te->name);
1254 PRights(te->rights, ta->dfs);
1261 printf("Access list for %s is fine.\n", ti->data);
1269 ListACLCmd(struct cmd_syndesc *as, char *arock)
1273 struct ViceIoctl blob;
1274 struct AclEntry *te;
1275 struct cmd_item *ti;
1276 int idf = getidf(as, parm_listacl_id);
1279 SetDotDefault(&as->parms[0].items);
1280 for(ti=as->parms[0].items; ti; ti=ti->next) {
1282 blob.out_size = MAXSIZE;
1284 blob.in = blob.out = space;
1285 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1287 Die(errno, ti->data);
1291 ta = ParseAcl(space);
1294 printf("Access list for %s is\n", ti->data);
1297 printf("DFS access list for %s is\n", ti->data);
1300 printf("DFS initial directory access list of %s is\n", ti->data);
1303 printf("DFS initial file access list of %s is\n", ti->data);
1307 printf(" Default cell = %s\n", ta->cell);
1309 separator = ta->dfs? DFS_SEPARATOR : ' ';
1310 if (ta->nplus > 0) {
1312 printf("Normal rights:\n");
1313 for(te = ta->pluslist;te;te=te->next) {
1314 printf(" %s%c", te->name, separator);
1315 PRights(te->rights, ta->dfs);
1319 if (ta->nminus > 0) {
1320 printf("Negative rights:\n");
1321 for(te = ta->minuslist;te;te=te->next) {
1322 printf(" %s ", te->name);
1323 PRights(te->rights, ta->dfs);
1335 FlushAllCmd(struct cmd_syndesc *as, char *arock)
1338 struct ViceIoctl blob;
1340 blob.in_size = blob.out_size = 0;
1341 code = pioctl(NULL, VIOC_FLUSHALL, &blob, 0);
1343 fprintf(stderr, "Error flushing all ");
1350 FlushVolumeCmd(struct cmd_syndesc *as, char *arock)
1353 struct ViceIoctl blob;
1354 struct cmd_item *ti;
1357 SetDotDefault(&as->parms[0].items);
1358 for(ti=as->parms[0].items; ti; ti=ti->next) {
1359 blob.in_size = blob.out_size = 0;
1360 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1362 fprintf(stderr, "Error flushing volume ");
1372 FlushCmd(struct cmd_syndesc *as, char *arock)
1375 struct ViceIoctl blob;
1376 struct cmd_item *ti;
1380 for(ti=as->parms[0].items; ti; ti=ti->next) {
1381 blob.in_size = blob.out_size = 0;
1382 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1384 if (errno == EMFILE) {
1385 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1388 fprintf(stderr, "%s: Error flushing file ", pn);
1398 /* all this command does is repackage its args and call SetVolCmd */
1400 SetQuotaCmd(struct cmd_syndesc *as, char *arock) {
1401 struct cmd_syndesc ts;
1403 /* copy useful stuff from our command slot; we may later have to reorder */
1404 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1405 return SetVolCmd(&ts, arock);
1409 SetVolCmd(struct cmd_syndesc *as, char *arock) {
1411 struct ViceIoctl blob;
1412 struct cmd_item *ti;
1413 struct VolumeStatus *status;
1414 char *motd, *offmsg, *input;
1417 SetDotDefault(&as->parms[0].items);
1418 for(ti=as->parms[0].items; ti; ti=ti->next) {
1420 blob.out_size = MAXSIZE;
1421 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1424 status = (VolumeStatus *)space;
1425 status->MinQuota = status->MaxQuota = -1;
1426 motd = offmsg = NULL;
1427 if (as->parms[1].items) {
1428 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1430 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1435 if (as->parms[2].items)
1436 motd = as->parms[2].items->data;
1437 if (as->parms[3].items)
1438 offmsg = as->parms[3].items->data;
1439 input = (char *)status + sizeof(*status);
1440 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1442 if (strlen(offmsg) >= VMSGSIZE) {
1443 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1448 strcpy(input,offmsg);
1449 blob.in_size += (long)strlen(offmsg);
1450 input += strlen(offmsg) + 1;
1454 if (strlen(motd) >= VMSGSIZE) {
1455 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1460 blob.in_size += (long)strlen(motd);
1461 input += strlen(motd) + 1;
1464 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1466 Die(errno, ti->data);
1475 * Why is VenusFid declared in the kernel-only section of afs.h,
1476 * if it's the exported interface of the (UNIX) cache manager?
1485 ExamineCmd(struct cmd_syndesc *as, char *arock)
1488 struct ViceIoctl blob;
1489 struct cmd_item *ti;
1490 struct VolumeStatus *status;
1491 char *name, *offmsg, *motd;
1494 SetDotDefault(&as->parms[0].items);
1495 for(ti=as->parms[0].items; ti; ti=ti->next) {
1497 afs_uint32 owner[2];
1498 char cell[MAXCELLCHARS];
1500 code = GetCell(ti->data, cell);
1502 Die(errno, ti->data);
1510 blob.out_size = sizeof(cm_fid_t);
1511 blob.out = (char *) &fid;
1512 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1513 printf("File %s (%u.%u.%u) contained in cell %s\n",
1514 ti->data, fid.volume, fid.vnode, fid.unique,
1518 blob.out_size = 2 * sizeof(afs_uint32);
1519 blob.out = (char *) &owner;
1520 if (0 == pioctl(ti->data, VIOCGETOWNER, &blob, 1)) {
1521 char oname[PR_MAXNAMELEN] = "(unknown)";
1523 /* Go to the PRDB and see if this all number username is valid */
1524 pr_Initialize(1, AFSDIR_CLIENT_ETC_DIRPATH, cell);
1525 pr_SIdToName(owner[0], oname);
1526 printf("Owner %s (%u) Group %u\n", oname, owner[0], owner[1]);
1530 blob.out_size = MAXSIZE;
1531 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1533 Die(errno, ti->data);
1537 status = (VolumeStatus *)space;
1538 name = (char *)status + sizeof(*status);
1539 offmsg = name + strlen(name) + 1;
1540 motd = offmsg + strlen(offmsg) + 1;
1542 PrintStatus(status, name, motd, offmsg);
1548 ListQuotaCmd(struct cmd_syndesc *as, char *arock)
1551 struct ViceIoctl blob;
1552 struct cmd_item *ti;
1553 struct VolumeStatus *status;
1558 printf("%-25s%-10s%-10s%-7s%-13s\n",
1559 "Volume Name", " Quota", " Used", " %Used", " Partition");
1560 SetDotDefault(&as->parms[0].items);
1561 for(ti=as->parms[0].items; ti; ti=ti->next) {
1563 blob.out_size = MAXSIZE;
1566 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1568 Die(errno, ti->data);
1572 status = (VolumeStatus *)space;
1573 name = (char *)status + sizeof(*status);
1574 QuickPrintStatus(status, name);
1580 WhereIsCmd(struct cmd_syndesc *as, char *arock)
1583 struct ViceIoctl blob;
1584 struct cmd_item *ti;
1590 SetDotDefault(&as->parms[0].items);
1591 for(ti=as->parms[0].items; ti; ti=ti->next) {
1593 blob.out_size = MAXSIZE;
1596 memset(space, 0, sizeof(space));
1597 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1599 Die(errno, ti->data);
1603 hosts = (afs_int32 *) space;
1604 printf("File %s is on host%s ", ti->data,
1605 (hosts[0] && !hosts[1]) ? "": "s");
1606 for(j=0; j<MAXHOSTS; j++) {
1609 tp = hostutil_GetNameByINet(hosts[j]);
1619 DiskFreeCmd(struct cmd_syndesc *as, char *arock)
1622 struct ViceIoctl blob;
1623 struct cmd_item *ti;
1625 struct VolumeStatus *status;
1628 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1629 " used", " avail", " %used");
1630 SetDotDefault(&as->parms[0].items);
1631 for(ti=as->parms[0].items; ti; ti=ti->next) {
1633 blob.out_size = MAXSIZE;
1636 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1638 Die(errno, ti->data);
1642 status = (VolumeStatus *)space;
1643 name = (char *)status + sizeof(*status);
1644 QuickPrintSpace(status, name);
1650 QuotaCmd(struct cmd_syndesc *as, char *arock)
1653 struct ViceIoctl blob;
1654 struct cmd_item *ti;
1656 struct VolumeStatus *status;
1659 SetDotDefault(&as->parms[0].items);
1660 for(ti=as->parms[0].items; ti; ti=ti->next) {
1662 blob.out_size = MAXSIZE;
1665 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1667 Die(errno, ti->data);
1671 status = (VolumeStatus *)space;
1672 if (status->MaxQuota)
1673 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1676 printf("%2.0f%% of quota used.\n", quotaPct);
1682 ListMountCmd(struct cmd_syndesc *as, char *arock)
1685 struct ViceIoctl blob;
1686 struct cmd_item *ti;
1687 char orig_name[1024]; /*Original name, may be modified*/
1688 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1689 char parent_dir[1024]; /*Parent directory of true name*/
1690 char *last_component; /*Last component of true name*/
1692 struct stat statbuff; /*Buffer for status info*/
1693 #endif /* not WIN32 */
1695 int link_chars_read; /*Num chars read in readlink()*/
1696 #endif /* not WIN32 */
1697 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1700 for(ti=as->parms[0].items; ti; ti=ti->next) {
1704 strcpy(orig_name, ti->data);
1705 #else /* not WIN32 */
1706 sprintf(orig_name, "%s%s",
1707 (ti->data[0] == '/') ? "" : "./",
1709 #endif /* not WIN32 */
1712 if (lstat(orig_name, &statbuff) < 0) {
1713 /* if lstat fails, we should still try the pioctl, since it
1714 * may work (for example, lstat will fail, but pioctl will
1715 * work if the volume of offline (returning ENODEV). */
1716 statbuff.st_mode = S_IFDIR; /* lie like pros */
1720 * The lstat succeeded. If the given file is a symlink, substitute
1721 * the file name with the link name.
1723 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1726 * Read name of resolved file.
1728 link_chars_read = readlink(orig_name, true_name, 1024);
1729 if (link_chars_read <= 0) {
1731 "%s: Can't read target name for '%s' symbolic link!\n",
1738 * Add a trailing null to what was read, bump the length.
1740 true_name[link_chars_read++] = 0;
1743 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1744 * have to create a full pathname using the original name and the
1745 * relative symlink name. Find the rightmost slash in the original
1746 * name (we know there is one) and splice in the symlink value.
1748 if (true_name[0] != '\\') {
1749 last_component = (char *) strrchr(orig_name, '\\');
1750 strcpy(++last_component, true_name);
1751 strcpy(true_name, orig_name);
1754 strcpy(true_name, orig_name);
1756 strcpy(true_name, orig_name);
1760 * Find rightmost slash, if any.
1763 last_component = (char *) strrchr(true_name, '\\');
1764 if (!last_component)
1766 last_component = (char *) strrchr(true_name, '/');
1767 if (last_component) {
1769 * Found it. Designate everything before it as the parent directory,
1770 * everything after it as the final component.
1772 strncpy(parent_dir, true_name, last_component - true_name + 1);
1773 parent_dir[last_component - true_name + 1] = 0;
1774 last_component++; /*Skip the slash*/
1776 if (!InAFS(parent_dir)) {
1777 const char * nbname = NetbiosName();
1778 int len = (int)strlen(nbname);
1780 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
1781 parent_dir[len+2] == '\\' &&
1782 parent_dir[len+3] == '\0' &&
1783 !strnicmp(nbname,&parent_dir[2],len))
1785 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
1791 * No slash appears in the given file name. Set parent_dir to the current
1792 * directory, and the last component as the given name.
1794 fs_ExtractDriveLetter(true_name, parent_dir);
1795 strcat(parent_dir, ".");
1796 last_component = true_name;
1797 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1800 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1801 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
1802 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
1807 blob.in = last_component;
1808 blob.in_size = (long)strlen(last_component)+1;
1809 blob.out_size = MAXSIZE;
1811 memset(space, 0, MAXSIZE);
1813 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1816 printf("'%s' is a %smount point for volume '%s'\n",
1818 (thru_symlink ? "symbolic link, leading to a " : ""),
1822 if (errno == EINVAL) {
1823 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
1825 Die(errno, (ti->data ? ti->data : parent_dir));
1834 MakeMountCmd(struct cmd_syndesc *as, char *arock)
1837 char *cellName, *volName, *tmpName;
1839 char localCellName[128];
1841 char path[1024] = "";
1842 struct afsconf_cell info;
1843 struct vldbentry vldbEntry;
1844 struct ViceIoctl blob;
1847 if (as->parms[2].items) /* cell name specified */
1848 cellName = as->parms[2].items->data;
1851 volName = as->parms[1].items->data;
1853 if (strlen(volName) >= 64) {
1854 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
1858 /* Check for a cellname in the volume specification, and complain
1859 * if it doesn't match what was specified with -cell */
1860 if (tmpName = strchr(volName, ':')) {
1863 if (strcasecmp(cellName,volName)) {
1864 fprintf(stderr,"fs: cellnames do not match.\n");
1869 volName = ++tmpName;
1872 parent = Parent(as->parms[0].items->data);
1873 if (!InAFS(parent)) {
1875 const char * nbname = NetbiosName();
1876 int len = (int)strlen(nbname);
1878 if (parent[0] == '\\' && parent[1] == '\\' &&
1879 parent[len+2] == '\\' &&
1880 parent[len+3] == '\0' &&
1881 !strnicmp(nbname,&parent[2],len))
1883 sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
1884 parent = Parent(path);
1885 if (!InAFS(parent)) {
1886 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
1892 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
1897 if ( strlen(path) == 0 )
1898 strcpy(path, as->parms[0].items->data);
1900 if ( IsFreelanceRoot(parent) ) {
1902 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
1908 blob.out_size = sizeof(localCellName);
1909 blob.out = localCellName;
1910 code = pioctl(parent, VIOC_GET_WS_CELL, &blob, 1);
1912 cellName = localCellName;
1916 GetCell(parent,space);
1919 code = GetCellName(cellName?cellName:space, &info);
1923 if (!(as->parms[4].items)) {
1924 /* not fast, check which cell the mountpoint is being created in */
1926 /* not fast, check name with VLDB */
1928 code = VLDBInit(1, &info);
1930 /* make the check. Don't complain if there are problems with init */
1931 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
1932 if (code == VL_NOENT) {
1933 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
1934 pn, volName, cellName ? cellName : space);
1939 if (as->parms[3].items) /* if -rw specified */
1944 /* cellular mount point, prepend cell prefix */
1945 strcat(space, info.name);
1948 strcat(space, volName); /* append volume name */
1949 strcat(space, "."); /* stupid convention; these end with a period */
1951 /* create symlink with a special pioctl for Windows NT, since it doesn't
1952 * have a symlink system call.
1955 blob.in_size = 1 + (long)strlen(space);
1958 code = pioctl(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
1959 #else /* not WIN32 */
1960 code = symlink(space, path);
1961 #endif /* not WIN32 */
1970 * Delete AFS mount points. Variables are used as follows:
1971 * tbuffer: Set to point to the null-terminated directory name of the mount point
1972 * (or ``.'' if none is provided)
1973 * tp: Set to point to the actual name of the mount point to nuke.
1976 RemoveMountCmd(struct cmd_syndesc *as, char *arock) {
1978 struct ViceIoctl blob;
1979 struct cmd_item *ti;
1981 char lsbuffer[1024];
1985 for(ti=as->parms[0].items; ti; ti=ti->next) {
1987 tp = (char *) strrchr(ti->data, '\\');
1989 tp = (char *) strrchr(ti->data, '/');
1991 strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1)); /* the dir name */
1993 tp++; /* skip the slash */
1996 if (!InAFS(tbuffer)) {
1997 const char * nbname = NetbiosName();
1998 int len = (int)strlen(nbname);
2000 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2001 tbuffer[len+2] == '\\' &&
2002 tbuffer[len+3] == '\0' &&
2003 !strnicmp(nbname,&tbuffer[2],len))
2005 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
2010 fs_ExtractDriveLetter(ti->data, tbuffer);
2011 strcat(tbuffer, ".");
2013 fs_StripDriveLetter(tp, tp, 0);
2016 blob.in_size = (long)strlen(tp)+1;
2017 blob.out = lsbuffer;
2018 blob.out_size = sizeof(lsbuffer);
2019 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2021 if (errno == EINVAL) {
2022 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2024 Die(errno, ti->data);
2027 continue; /* don't bother trying */
2030 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2031 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2033 continue; /* skip */
2038 blob.in_size = (long)strlen(tp)+1;
2039 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2041 Die(errno, ti->data);
2052 CheckServersCmd(struct cmd_syndesc *as, char *arock)
2055 struct ViceIoctl blob;
2059 struct afsconf_cell info;
2060 struct chservinfo checkserv;
2062 memset(&checkserv, 0, sizeof(struct chservinfo));
2063 blob.in_size=sizeof(struct chservinfo);
2064 blob.in=(caddr_t)&checkserv;
2066 blob.out_size = MAXSIZE;
2068 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2070 /* prepare flags for checkservers command */
2071 temp = 2; /* default to checking local cell only */
2072 if (as->parms[2].items)
2073 temp |= 1; /* set fast flag */
2074 if (as->parms[1].items)
2075 temp &= ~2; /* turn off local cell check */
2077 checkserv.magic = 0x12345678; /* XXX */
2078 checkserv.tflags=temp;
2080 /* now copy in optional cell name, if specified */
2081 if (as->parms[0].items) {
2082 code = GetCellName(as->parms[0].items->data, &info);
2086 strcpy(checkserv.tbuffer,info.name);
2087 checkserv.tsize=(int)strlen(info.name)+1;
2089 strcpy(checkserv.tbuffer,"\0");
2093 if(as->parms[3].items) {
2094 checkserv.tinterval=atol(as->parms[3].items->data);
2097 if(checkserv.tinterval<0) {
2098 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2099 checkserv.tinterval=-1;
2100 } else if(checkserv.tinterval> 600) {
2101 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2102 checkserv.tinterval=600; /* 10 min max interval */
2105 checkserv.tinterval = -1; /* don't change current interval */
2108 if ( checkserv.tinterval >= 0 ) {
2111 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2116 fprintf (stderr,"Permission denied: requires root access.\n");
2122 code = pioctl(0, VIOCCKSERV, &blob, 1);
2124 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2125 printf("Must be root to change -interval\n");
2131 memcpy(&temp, space, sizeof(afs_int32));
2132 if (checkserv.tinterval >= 0) {
2133 if (checkserv.tinterval > 0)
2134 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2135 checkserv.tinterval, temp);
2137 printf("The current down server probe interval is %d secs\n", temp);
2141 printf("All servers are running.\n");
2143 printf("These servers unavailable due to network or server problems: ");
2144 for(j=0; j < MAXHOSTS; j++) {
2145 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2148 tp = hostutil_GetNameByINet(temp);
2158 MessagesCmd(struct cmd_syndesc *as, char *arock)
2161 struct ViceIoctl blob;
2162 struct gaginfo gagflags;
2163 struct cmd_item *show;
2165 memset(&gagflags, 0, sizeof(struct gaginfo));
2166 blob.in_size = sizeof(struct gaginfo);
2167 blob.in = (caddr_t ) &gagflags;
2168 blob.out_size = MAXSIZE;
2170 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2172 if (show = as->parms[0].items) {
2173 if (!strcasecmp (show->data, "user"))
2174 gagflags.showflags |= GAGUSER;
2175 else if (!strcasecmp (show->data, "console"))
2176 gagflags.showflags |= GAGCONSOLE;
2177 else if (!strcasecmp (show->data, "all"))
2178 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2179 else if (!strcasecmp (show->data, "none"))
2183 "unrecognized flag %s: must be in {user,console,all,none}\n",
2192 code = pioctl(0, VIOC_GAG, &blob, 1);
2201 CheckVolumesCmd(struct cmd_syndesc *as, char *arock)
2204 struct ViceIoctl blob;
2208 code = pioctl(0, VIOCCKBACK, &blob, 1);
2213 printf("All volumeID/name mappings checked.\n");
2219 SetCacheSizeCmd(struct cmd_syndesc *as, char *arock)
2222 struct ViceIoctl blob;
2227 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2232 fprintf (stderr,"Permission denied: requires root access.\n");
2237 if (!as->parms[0].items && !as->parms[1].items) {
2238 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2241 if (as->parms[0].items) {
2242 code = util_GetInt32(as->parms[0].items->data, &temp);
2244 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2249 blob.in = (char *) &temp;
2250 blob.in_size = sizeof(afs_int32);
2252 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2254 Die(errno, (char *) 0);
2258 printf("New cache size set.\n");
2262 #define MAXGCSIZE 16
2264 GetCacheParmsCmd(struct cmd_syndesc *as, char *arock)
2267 struct ViceIoctl blob;
2268 afs_uint64 parms[MAXGCSIZE];
2270 memset(parms, 0, sizeof(parms));
2273 blob.out_size = sizeof(parms);
2274 blob.out = (char *) parms;
2275 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2281 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
2282 parms[1], parms[0]);
2283 if (parms[1] > parms[0])
2284 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2289 ListCellsCmd(struct cmd_syndesc *as, char *arock)
2292 afs_int32 i, j, *lp, magic, size;
2294 afs_int32 addr, maxa = OMAXHOSTS;
2295 struct ViceIoctl blob;
2298 resolve = !(as->parms[0].items); /* -numeric */
2300 for(i=0;i<1000;i++) {
2302 memcpy(tp, &i, sizeof(afs_int32));
2303 tp = (char *)(space + sizeof(afs_int32));
2304 lp = (afs_int32 *)tp;
2306 size = sizeof(afs_int32) + sizeof(afs_int32);
2307 blob.out_size = MAXSIZE;
2308 blob.in_size = sizeof(afs_int32);
2311 code = pioctl(0, VIOCGETCELL, &blob, 1);
2314 break; /* done with the list */
2319 memcpy(&magic, tp, sizeof(afs_int32));
2320 if (magic == 0x12345678) {
2322 tp += sizeof(afs_int32);
2324 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2325 for(j=0; j < maxa; j++) {
2326 char *name, tbuffer[20];
2328 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2333 name = hostutil_GetNameByINet(addr);
2336 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2337 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2340 printf(" %s", name);
2349 ListAliasesCmd(struct cmd_syndesc *as, char *arock)
2352 char *tp, *aliasName, *realName;
2353 struct ViceIoctl blob;
2357 memcpy(tp, &i, sizeof(afs_int32));
2358 blob.out_size = MAXSIZE;
2359 blob.in_size = sizeof(afs_int32);
2362 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2365 break; /* done with the list */
2371 tp += strlen(aliasName) + 1;
2373 printf("Alias %s for cell %s\n", aliasName, realName);
2379 CallBackRxConnCmd(struct cmd_syndesc *as, char *arock)
2382 struct ViceIoctl blob;
2383 struct cmd_item *ti;
2385 struct hostent *thp;
2389 ti = as->parms[0].items;
2392 thp = hostutil_GetHostByName(ti->data);
2394 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2397 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2399 hostAddr = 0; /* means don't set host */
2400 setp = 0; /* aren't setting host */
2403 /* now do operation */
2404 blob.in_size = sizeof(afs_int32);
2405 blob.out_size = sizeof(afs_int32);
2406 blob.in = (char *) &hostAddr;
2407 blob.out = (char *) &hostAddr;
2409 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2419 NewCellCmd(struct cmd_syndesc *as, char *arock)
2422 afs_int32 code, linkedstate=0, size=0, *lp;
2423 struct ViceIoctl blob;
2424 struct cmd_item *ti;
2425 char *tp, *cellname=0;
2426 struct hostent *thp;
2427 afs_int32 fsport = 0, vlport = 0;
2429 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
2431 lp = (afs_int32 *)tp;
2433 tp += sizeof(afs_int32);
2434 for(ti=as->parms[1].items; ti; ti=ti->next) {
2435 thp = hostutil_GetHostByName(ti->data);
2437 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2441 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2442 tp += sizeof(afs_int32);
2445 if (as->parms[2].items) {
2447 * Link the cell, for the purposes of volume location, to the specified
2450 cellname = as->parms[2].items->data;
2453 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2454 if (as->parms[3].items) {
2455 code = util_GetInt32(as->parms[3].items->data, &vlport);
2457 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2461 if (as->parms[4].items) {
2462 code = util_GetInt32(as->parms[4].items->data, &fsport);
2464 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2469 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
2470 lp = (afs_int32 *)tp;
2474 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2475 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2476 tp = (char *)(space + size);
2478 strcpy(tp, cellname);
2479 size += strlen(cellname) + 1;
2481 blob.in_size = size;
2484 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2490 struct ViceIoctl blob;
2493 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2498 blob.in = (char *) 0;
2499 blob.out_size = MAXSIZE;
2502 code = pioctl((char *) 0, VIOCNEWCELL, &blob, 1);
2505 Die(errno, (char *) 0);
2509 printf("Cell servers information refreshed\n");
2516 NewAliasCmd(struct cmd_syndesc *as, char *arock)
2519 struct ViceIoctl blob;
2521 char *aliasName, *realName;
2523 /* Setup and do the NEWALIAS pioctl call */
2524 aliasName = as->parms[0].items->data;
2525 realName = as->parms[1].items->data;
2527 strcpy(tp, aliasName);
2528 tp += strlen(aliasName) + 1;
2529 strcpy(tp, realName);
2530 tp += strlen(realName) + 1;
2532 blob.in_size = tp - space;
2536 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2538 if (errno == EEXIST) {
2540 "%s: cell name `%s' in use by an existing cell.\n", pn,
2552 WhichCellCmd(struct cmd_syndesc *as, char *arock)
2555 struct cmd_item *ti;
2557 char cell[MAXCELLCHARS]="";
2559 SetDotDefault(&as->parms[0].items);
2560 for(ti=as->parms[0].items; ti; ti=ti->next) {
2561 code = GetCell(ti->data, cell);
2563 if (errno == ENOENT)
2564 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2566 Die(errno, ti->data);
2570 printf("File %s lives in cell '%s'\n", ti->data, cell);
2576 WSCellCmd(struct cmd_syndesc *as, char *arock)
2579 struct ViceIoctl blob;
2583 blob.out_size = MAXSIZE;
2586 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2593 printf("This workstation belongs to cell '%s'\n", space);
2599 PrimaryCellCmd(struct cmd_syndesc *as, char *arock)
2601 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2607 MonitorCmd(struct cmd_syndesc *as, char *arock)
2610 struct ViceIoctl blob;
2611 struct cmd_item *ti;
2613 struct hostent *thp;
2617 ti = as->parms[0].items;
2621 if (!strcmp(ti->data, "off")) {
2622 hostAddr = 0xffffffff;
2624 thp = hostutil_GetHostByName(ti->data);
2626 if (!strcmp(ti->data, "localhost")) {
2627 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2628 hostAddr = htonl(0x7f000001);
2630 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2634 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2638 hostAddr = 0; /* means don't set host */
2639 setp = 0; /* aren't setting host */
2642 /* now do operation */
2643 blob.in_size = sizeof(afs_int32);
2644 blob.out_size = sizeof(afs_int32);
2645 blob.in = (char *) &hostAddr;
2646 blob.out = (char *) &hostAddr;
2647 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2653 printf("%s: new monitor host set.\n", pn);
2655 /* now decode old address */
2656 if (hostAddr == 0xffffffff) {
2657 printf("Cache monitoring is currently disabled.\n");
2659 tp = hostutil_GetNameByINet(hostAddr);
2660 printf("Using host %s for monitor services.\n", tp);
2667 SysNameCmd(struct cmd_syndesc *as, char *arock)
2670 struct ViceIoctl blob;
2671 struct cmd_item *ti;
2672 char *input = space;
2675 ti = as->parms[0].items;
2679 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2684 fprintf (stderr,"Permission denied: requires root access.\n");
2692 blob.out_size = MAXSIZE;
2693 blob.in_size = sizeof(afs_int32);
2694 memcpy(input, &setp, sizeof(afs_int32));
2695 input += sizeof(afs_int32);
2696 for (; ti; ti = ti->next) {
2698 blob.in_size += (long)strlen(ti->data) + 1;
2699 if (blob.in_size > MAXSIZE) {
2700 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2701 setp > 1 ? "s" : "");
2704 strcpy(input, ti->data);
2705 input += strlen(ti->data);
2708 memcpy(space, &setp, sizeof(afs_int32));
2709 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2715 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2720 memcpy(&setp, input, sizeof(afs_int32));
2721 input += sizeof(afs_int32);
2723 fprintf(stderr,"No sysname name value was found\n");
2727 printf("Current sysname%s is", setp > 1 ? " list" : "");
2728 for (; setp > 0; --setp ) {
2729 printf(" \'%s\'", input);
2730 input += strlen(input) + 1;
2736 static char *exported_types[] = {"null", "nfs", ""};
2737 static int ExportAfsCmd(struct cmd_syndesc *as, char *arock)
2740 struct ViceIoctl blob;
2741 struct cmd_item *ti;
2742 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
2743 int exportcall, pwsync = 0, smounts = 0;
2747 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2752 fprintf (stderr,"Permission denied: requires root access.\n");
2757 ti = as->parms[0].items;
2758 if (strcmp(ti->data, "nfs") == 0)
2759 type = 0x71; /* NFS */
2762 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2765 ti = as->parms[1].items;
2767 if (strcmp(ti->data, "on") == 0)
2769 else if (strcmp(ti->data, "off") == 0)
2772 fprintf(stderr, "Illegal argument %s\n", ti->data);
2777 if (ti = as->parms[2].items) { /* -noconvert */
2778 if (strcmp(ti->data, "on") == 0)
2780 else if (strcmp(ti->data, "off") == 0)
2783 fprintf(stderr, "Illegal argument %s\n", ti->data);
2787 if (ti = as->parms[3].items) { /* -uidcheck */
2788 if (strcmp(ti->data, "on") == 0)
2790 else if (strcmp(ti->data, "off") == 0)
2793 fprintf(stderr, "Illegal argument %s\n", ti->data);
2797 if (ti = as->parms[4].items) { /* -submounts */
2798 if (strcmp(ti->data, "on") == 0)
2800 else if (strcmp(ti->data, "off") == 0)
2803 fprintf(stderr, "Illegal argument %s\n", ti->data);
2807 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2810 blob.in = (char *) &exportcall;
2811 blob.in_size = sizeof(afs_int32);
2812 blob.out = (char *) &exportcall;
2813 blob.out_size = sizeof(afs_int32);
2814 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2816 if (errno == ENODEV) {
2818 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
2825 if (exportcall & 1) {
2826 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
2827 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
2828 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
2829 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
2831 printf("'%s' translator is disabled\n", exported_types[type]);
2840 GetCellCmd(struct cmd_syndesc *as, char *arock)
2843 struct ViceIoctl blob;
2844 struct afsconf_cell info;
2845 struct cmd_item *ti;
2852 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
2853 for(ti=as->parms[0].items; ti; ti=ti->next) {
2855 blob.out_size = sizeof(args);
2856 blob.out = (caddr_t) &args;
2857 code = GetCellName(ti->data, &info);
2862 blob.in_size = 1+(long)strlen(info.name);
2863 blob.in = info.name;
2864 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2866 if (errno == ENOENT)
2867 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
2869 Die(errno, info.name);
2873 printf("Cell %s status: ", info.name);
2879 printf("no setuid allowed");
2881 printf("setuid allowed");
2883 printf(", using old VLDB");
2889 static int SetCellCmd(struct cmd_syndesc *as, char *arock)
2892 struct ViceIoctl blob;
2893 struct afsconf_cell info;
2894 struct cmd_item *ti;
2902 /* Check arguments. */
2903 if (as->parms[1].items && as->parms[2].items) {
2904 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
2908 /* figure stuff to set */
2914 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2919 fprintf (stderr,"Permission denied: requires root access.\n");
2924 if (! as->parms[1].items)
2925 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
2927 /* set stat for all listed cells */
2928 for(ti=as->parms[0].items; ti; ti=ti->next) {
2930 code = GetCellName(ti->data, &info);
2935 strcpy(args.cname, info.name);
2936 blob.in_size = sizeof(args);
2937 blob.in = (caddr_t) &args;
2939 blob.out = (caddr_t) 0;
2940 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2942 Die(errno, info.name); /* XXX added cell name to Die() call */
2951 GetCellName(char *cellNamep, struct afsconf_cell *infop)
2953 strcpy(infop->name, cellNamep);
2958 GetCellName(char *cellName, struct afsconf_cell *info)
2960 struct afsconf_dir *tdir;
2963 tdir = afsconf_Open(AFSDIR_CLIENT_ETC_CLIENTNAME);
2966 "Could not process files in configuration directory (%s).\n",
2967 AFSDIR_CLIENT_ETC_CLIENTNAME);
2971 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2973 fprintf(stderr,"fs: cell %s not in %s/CellServDB\n", cellName,
2974 AFSDIR_CLIENT_ETC_CLIENTNAME);
2980 #endif /* not WIN32 */
2983 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
2987 code = ugen_ClientInit(noAuthFlag, AFSDIR_CLIENT_ETC_DIRPATH,
2988 info->name, 0, &uclient,
2989 NULL, pn, rxkad_clear,
2990 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
2991 0, 0, USER_SERVICE_ID);
2996 static struct ViceIoctl gblob;
2997 static int debug = 0;
2999 * here follow some routines in suport of the setserverprefs and
3000 * getserverprefs commands. They are:
3001 * SetPrefCmd "top-level" routine
3002 * addServer adds a server to the list of servers to be poked into the
3003 * kernel. Will poke the list into the kernel if it threatens
3005 * pokeServers pokes the existing list of servers and ranks into the kernel
3006 * GetPrefCmd reads the Cache Manager's current list of server ranks
3015 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3017 ssp = (cm_SSetPref_t *)space;
3018 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3024 * returns -1 if error message printed,
3026 * errno value if error and no error message printed
3033 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3034 if (code && (errno == EINVAL)) {
3035 struct setspref *ssp;
3036 ssp = (struct setspref *)gblob.in;
3037 if (!(ssp->flags & DBservers)) {
3038 gblob.in = (void *)&(ssp->servers[0]);
3039 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3040 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
3041 return code ? errno : 0;
3044 "This cache manager does not support VL server preferences.\n");
3048 return code ? errno : 0;
3054 addServer(char *name, unsigned short rank)
3059 struct hostent *thostent;
3063 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3065 #define MAXUSHORT ((unsigned short) ~0)
3070 thostent = hostutil_GetHostByName(name);
3072 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3076 ssp = (cm_SSetPref_t *)(gblob.in);
3078 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3079 code = pokeServers();
3080 ssp->num_servers = 0;
3083 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3084 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3085 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3086 gblob.in_size += sizeof(cm_SPref_t);
3089 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3095 * returns -1 if error message printed,
3097 * errno value if error and no error message printed
3100 addServer(char *name, afs_int32 rank)
3103 struct setspref *ssp;
3105 struct hostent *thostent;
3111 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3113 #define MAXUSHORT ((unsigned short) ~0)
3117 thostent = hostutil_GetHostByName(name);
3119 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3123 ssp = (struct setspref *)(gblob.in);
3125 for (t = 0; thostent->h_addr_list[t]; t++) {
3126 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3127 code = pokeServers();
3130 ssp->num_servers = 0;
3133 sp = (struct spref *)(gblob.in + gblob.in_size);
3134 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3135 sizeof(afs_uint32));
3136 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3137 gblob.in_size += sizeof(struct spref);
3141 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3142 name, sp->rank, sp->server.s_addr);
3150 static BOOL IsWindowsNT (void)
3152 static BOOL fChecked = FALSE;
3153 static BOOL fIsWinNT = FALSE;
3157 OSVERSIONINFO Version;
3161 memset (&Version, 0x00, sizeof(Version));
3162 Version.dwOSVersionInfoSize = sizeof(Version);
3164 if (GetVersionEx (&Version))
3166 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3176 SetPrefCmd(struct cmd_syndesc *as, char * arock)
3180 struct cmd_item *ti;
3185 ssp = (cm_SSetPref_t *)space;
3187 ssp->num_servers = 0;
3188 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3191 gblob.out_size = MAXSIZE;
3194 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3200 ti = as->parms[2].items; /* -file */
3202 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3203 if (!(infd = fopen(ti->data,"r" ))) {
3205 Die(errno,ti->data);
3208 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3209 code = addServer (name, (unsigned short) rank);
3213 ti = as->parms[3].items; /* -stdin */
3215 while ( scanf("%79s%ld", name, &rank) != EOF) {
3216 code = addServer (name, (unsigned short) rank);
3220 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3225 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3227 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3231 code = pokeServers();
3233 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3235 ssp = (cm_SSetPref_t *)space;
3236 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3238 ssp->flags = CM_SPREF_VLONLY;
3239 ssp->num_servers = 0;
3241 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3246 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3248 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3253 if (as->parms[1].items) {
3255 printf("now poking vlservers\n");
3256 code = pokeServers();
3266 SetPrefCmd(struct cmd_syndesc *as, char *arock)
3270 struct cmd_item *ti;
3273 struct setspref *ssp;
3274 int error = 0; /* -1 means error message printed,
3275 * >0 means errno value for unprinted message */
3277 ssp = (struct setspref *)space;
3279 ssp->num_servers = 0;
3280 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3283 gblob.out_size = MAXSIZE;
3287 fprintf(stderr, "Permission denied: requires root access.\n");
3291 ti = as->parms[2].items; /* -file */
3294 fprintf(stderr, "opening file %s\n", ti->data);
3295 if (!(infd = fopen(ti->data, "r"))) {
3299 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3300 code = addServer(name, (unsigned short)rank);
3307 ti = as->parms[3].items; /* -stdin */
3309 while (scanf("%79s%ld", name, &rank) != EOF) {
3310 code = addServer(name, (unsigned short)rank);
3316 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3321 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3325 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3329 code = pokeServers();
3333 printf("now working on vlservers, code=%d\n", code);
3335 ssp = (struct setspref *)space;
3336 ssp->flags = DBservers;
3337 ssp->num_servers = 0;
3338 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3341 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3346 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3350 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3355 if (as->parms[1].items) {
3357 printf("now poking vlservers\n");
3358 code = pokeServers();
3366 return error ? 1 : 0;
3372 GetPrefCmd(struct cmd_syndesc *as, char *arock)
3375 struct cmd_item *ti;
3376 char *name, tbuffer[20];
3381 struct ViceIoctl blob;
3382 struct cm_SPrefRequest *in;
3383 struct cm_SPrefInfo *out;
3387 ti = as->parms[0].items; /* -file */
3389 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3390 if (!(outfd = freopen(ti->data,"w",stdout))) {
3391 Die(errno,ti->data);
3396 ti = as->parms[1].items; /* -numeric */
3398 ti = as->parms[2].items; /* -vlservers */
3399 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3400 /* ti = as->parms[3].items; -cell */
3402 in = (struct cm_SPrefRequest *)space;
3406 blob.in_size=sizeof(struct cm_SPrefRequest);
3407 blob.in = (char *)in;
3409 blob.out_size = MAXSIZE;
3411 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3412 in->flags = vlservers;
3414 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3416 perror("getserverprefs pioctl");
3420 out = (struct cm_SPrefInfo *) blob.out;
3422 for (i=0;i<out->num_servers;i++) {
3424 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3427 addr = ntohl(out->servers[i].host.s_addr);
3428 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3429 (addr>>8) & 0xff, addr & 0xff);
3432 printf ("%-50s %5u\n",name,out->servers[i].rank);
3435 in->offset = out->next_offset;
3437 } while (!code && out->next_offset > 0);
3443 GetPrefCmd(struct cmd_syndesc *as, char *arock)
3446 struct cmd_item *ti;
3447 char *name, tbuffer[20];
3448 afs_int32 rank, addr;
3452 struct ViceIoctl blob;
3453 struct sprefrequest *in;
3454 struct sprefinfo *out;
3457 ti = as->parms[0].items; /* -file */
3460 fprintf(stderr, "opening file %s\n", ti->data);
3461 if (!(outfd = freopen(ti->data, "w", stdout))) {
3467 ti = as->parms[1].items; /* -numeric */
3469 ti = as->parms[2].items; /* -vlservers */
3470 vlservers |= (ti ? DBservers : 0);
3471 /* ti = as->parms[3].items; -cell */
3473 in = (struct sprefrequest *)space;
3477 blob.in_size = sizeof(struct sprefrequest);
3478 blob.in = (char *)in;
3480 blob.out_size = MAXSIZE;
3483 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3484 in->flags = vlservers;
3486 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3488 perror("getserverprefs pioctl");
3492 out = (struct sprefinfo *)blob.out;
3494 for (i = 0; i < out->num_servers; i++) {
3496 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3498 addr = ntohl(out->servers[i].server.s_addr);
3499 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3500 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3503 printf("%-50s %5u\n", name, out->servers[i].rank);
3506 in->offset = out->next_offset;
3507 } while (out->next_offset > 0);
3514 UuidCmd(struct cmd_syndesc *asp, char *arock)
3519 struct ViceIoctl blob;
3520 char * uuidstring = NULL;
3524 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3529 fprintf (stderr, "Permission denied: requires root access.\n");
3534 if (asp->parms[0].items) {
3535 inValue = 1; /* generate new UUID */
3537 inValue = 0; /* just show the current UUID */
3540 blob.in_size = sizeof(inValue);
3541 blob.in = (char *) &inValue;
3542 blob.out_size = sizeof(outValue);
3543 blob.out = (char *) &outValue;
3545 code = pioctl(NULL, VIOC_UUIDCTL, &blob, 1);
3551 UuidToString((UUID *) &outValue, &uuidstring);
3553 printf("%sUUID: %s",
3554 ((inValue == 1)?"New ":""),
3558 RpcStringFree(&uuidstring);
3564 TraceCmd(struct cmd_syndesc *asp, char *arock)
3567 struct ViceIoctl blob;
3573 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3578 fprintf (stderr,"Permission denied: requires root access.\n");
3583 if ((asp->parms[0].items && asp->parms[1].items)) {
3584 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
3588 /* determine if we're turning this tracing on or off */
3590 if (asp->parms[0].items)
3591 inValue = 3; /* enable */
3592 else if (asp->parms[1].items)
3593 inValue = 2; /* disable */
3594 if (asp->parms[2].items)
3595 inValue |= 4; /* do reset */
3596 if (asp->parms[3].items)
3597 inValue |= 8; /* dump */
3599 blob.in_size = sizeof(long);
3600 blob.in = (char *) &inValue;
3601 blob.out_size = sizeof(long);
3602 blob.out = (char *) &outValue;
3604 code = pioctl(NULL, VIOC_TRACECTL, &blob, 1);
3611 printf("AFS tracing enabled.\n");
3613 printf("AFS tracing disabled.\n");
3618 static void sbusage(void)
3620 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
3621 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
3624 /* fs sb -kbytes 9999 -files *.o -default 64 */
3626 StoreBehindCmd(struct cmd_syndesc *as, char *arock)
3629 struct ViceIoctl blob;
3630 struct cmd_item *ti;
3631 struct sbstruct tsb, tsb2;
3639 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3644 tsb.sb_thisfile = -1;
3645 ti = as->parms[0].items; /* -kbytes */
3647 if (!as->parms[1].items) {
3648 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3652 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3653 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3654 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3660 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3661 ti = as->parms[2].items; /* -allfiles */
3663 allfiles = strtol(ti->data, &t, 10) * 1024;
3664 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3665 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3671 /* -verbose or -file only or no options */
3672 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3673 || (!as->parms[0].items && !as->parms[1].items
3674 && !as->parms[2].items))
3677 blob.in = (char *)&tsb;
3678 blob.out = (char *)&tsb2;
3679 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3680 memset(&tsb2, 0, sizeof(tsb2));
3682 /* once per -file */
3683 for (ti = as->parms[1].items; ti; ti = ti->next) {
3684 /* Do this solely to see if the file is there */
3685 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
3687 Die(errno, ti->data);
3692 code = pioctl(ti->data, VIOC_STOREBEHIND, &blob, 1);
3694 Die(errno, ti->data);
3699 if (verbose && (blob.out_size == sizeof(tsb2))) {
3700 if (tsb2.sb_thisfile == -1) {
3701 fprintf(stdout, "Will store %s according to default.\n",
3705 "Will store up to %d kbytes of %s asynchronously.\n",
3706 (tsb2.sb_thisfile / 1024), ti->data);
3711 /* If no files - make at least one pioctl call, or
3712 * set the allfiles default if we need to.
3714 if (!as->parms[1].items || (allfiles != -1)) {
3715 tsb.sb_default = allfiles;
3716 code = pioctl(0, VIOC_STOREBEHIND, &blob, 1);
3718 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3723 /* Having no arguments also reports the default store asynchrony */
3724 if (verbose && (blob.out_size == sizeof(tsb2))) {
3725 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3726 (tsb2.sb_default / 1024));
3733 SetCryptCmd(struct cmd_syndesc *as, char *arock)
3735 afs_int32 code = 0, flag;
3736 struct ViceIoctl blob;
3741 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3746 tp = as->parms[0].items->data;
3747 if (strcmp(tp, "on") == 0)
3749 else if (strcmp(tp, "off") == 0)
3752 fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
3756 blob.in = (char *) &flag;
3757 blob.in_size = sizeof(flag);
3759 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
3766 GetCryptCmd(struct cmd_syndesc *as, char *arock)
3768 afs_int32 code = 0, flag;
3769 struct ViceIoctl blob;
3774 blob.out_size = sizeof(flag);
3777 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
3783 memcpy(&flag, tp, sizeof(afs_int32));
3784 printf("Security level is currently ");
3786 printf("crypt (data security).\n");
3794 MemDumpCmd(struct cmd_syndesc *asp, char *arock)
3797 struct ViceIoctl blob;
3802 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3806 if ((asp->parms[0].items && asp->parms[1].items)) {
3807 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
3811 /* determine if we're turning this tracing on or off */
3812 if (asp->parms[0].items)
3813 inValue = 1; /* begin */
3814 else if (asp->parms[1].items)
3815 inValue = 0; /* end */
3818 blob.in_size = sizeof(long);
3819 blob.in = (char *) &inValue;
3820 blob.out_size = sizeof(long);
3821 blob.out = (char *) &outValue;
3823 code = pioctl(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
3830 printf("AFS memdump created.\n");
3833 printf("AFS memdump failed.\n");
3839 MiniDumpCmd(struct cmd_syndesc *asp, char *arock)
3842 SERVICE_STATUS status;
3843 SC_HANDLE hManager = NULL;
3844 SC_HANDLE hService = NULL;
3847 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3851 hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
3855 hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
3859 success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
3862 CloseServiceHandle(hService);
3863 CloseServiceHandle(hManager);
3865 printf("AFS minidump generated.\n");
3871 CloseServiceHandle(hService);
3873 CloseServiceHandle(hManager);
3875 printf("AFS minidump failed.\n");
3880 CSCPolicyCmd(struct cmd_syndesc *asp, char *arock)
3882 struct cmd_item *ti;
3887 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3891 for(ti=asp->parms[0].items; ti;ti=ti->next) {
3903 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
3904 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
3907 REG_OPTION_NON_VOLATILE,
3913 if ( hkCSCPolicy == NULL ) {
3914 fprintf (stderr,"Permission denied: requires Administrator access.\n");
3919 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3920 RegCloseKey(hkCSCPolicy);
3926 if (asp->parms[1].items)
3928 if (asp->parms[2].items)
3929 policy = "programs";
3930 if (asp->parms[3].items)
3931 policy = "documents";
3932 if (asp->parms[4].items)
3935 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, (DWORD)strlen(policy)+1);
3937 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
3938 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
3942 DWORD dwIndex, dwPolicies;
3943 char policyName[256];
3944 DWORD policyNameLen;
3949 /* list current csc policies */
3951 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
3952 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
3955 REG_OPTION_NON_VOLATILE,
3956 KEY_READ|KEY_QUERY_VALUE,
3961 RegQueryInfoKey( hkCSCPolicy,
3963 NULL, /* lpcClass */
3964 NULL, /* lpReserved */
3965 NULL, /* lpcSubKeys */
3966 NULL, /* lpcMaxSubKeyLen */
3967 NULL, /* lpcMaxClassLen */
3968 &dwPolicies, /* lpcValues */
3969 NULL, /* lpcMaxValueNameLen */
3970 NULL, /* lpcMaxValueLen */
3971 NULL, /* lpcbSecurityDescriptor */
3972 NULL /* lpftLastWriteTime */
3975 printf("Current CSC policies:\n");
3976 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
3978 policyNameLen = sizeof(policyName);
3979 policyLen = sizeof(policy);
3980 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
3981 &dwType, policy, &policyLen);
3983 printf(" %s = %s\n", policyName, policy);
3987 RegCloseKey(hkCSCPolicy);
3992 /* get clients interface addresses */
3994 GetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
3997 struct cmd_item *ti;
3999 struct ViceIoctl blob;
4000 struct sprefrequest *in;
4001 struct sprefinfo *out;
4003 in = (struct sprefrequest *)space;
4007 blob.in_size = sizeof(struct sprefrequest);
4008 blob.in = (char *)in;
4010 blob.out_size = MAXSIZE;
4013 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4014 /* returns addr in network byte order */
4015 code = pioctl(0, VIOC_GETCPREFS, &blob, 1);
4017 perror("getClientInterfaceAddr pioctl");
4023 out = (struct sprefinfo *)blob.out;
4024 for (i = 0; i < out->num_servers; i++) {
4027 addr = ntohl(out->servers[i].server.s_addr);
4028 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
4029 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
4030 printf("%-50s\n", tbuffer);
4032 in->offset = out->next_offset;
4034 } while (out->next_offset > 0);
4040 SetClientAddrsCmd(struct cmd_syndesc *as, char *arock)
4042 afs_int32 code, addr;
4043 struct cmd_item *ti;
4045 struct ViceIoctl blob;
4046 struct setspref *ssp;
4047 int sizeUsed = 0, i, flag;
4048 afs_int32 existingAddr[1024]; /* existing addresses on this host */
4052 ssp = (struct setspref *)space;
4053 ssp->num_servers = 0;
4056 blob.out_size = MAXSIZE;
4059 fprintf(stderr, "Permission denied: requires root access.\n");
4063 /* extract all existing interface addresses */
4064 existNu = rx_getAllAddr(existingAddr, 1024);
4068 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4069 for (ti = as->parms[0].items; ti; ti = ti->next) {
4070 if (sizeUsed >= sizeof(space)) {
4071 fprintf(stderr, "No more space\n");
4074 addr = extractAddr(ti->data, 20); /* network order */
4075 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4076 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4081 /* see if it is an address that really exists */
4082 for (flag = 0, i = 0; i < existNu; i++)
4083 if (existingAddr[i] == addr) {
4087 if (!flag) { /* this is an nonexistent address */
4088 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4092 /* copy all specified addr into ioctl buffer */
4093 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4094 printf("Adding 0x%08x\n", addr);
4096 sizeUsed += sizeof(struct spref);
4098 if (ssp->num_servers < 1) {
4099 fprintf(stderr, "No addresses specified\n");
4102 blob.in_size = sizeUsed - sizeof(struct spref);
4104 code = pioctl(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4114 FlushMountCmd(struct cmd_syndesc *as, char *arock)
4117 struct ViceIoctl blob;
4118 struct cmd_item *ti;
4119 char orig_name[1024]; /*Original name, may be modified */
4120 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4121 char parent_dir[1024]; /*Parent directory of true name */
4122 char *last_component; /*Last component of true name */
4123 struct stat statbuff; /*Buffer for status info */
4124 int link_chars_read; /*Num chars read in readlink() */
4125 int thru_symlink; /*Did we get to a mount point via a symlink? */
4128 for (ti = as->parms[0].items; ti; ti = ti->next) {
4131 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4134 if (lstat(orig_name, &statbuff) < 0) {
4135 /* if lstat fails, we should still try the pioctl, since it
4136 * may work (for example, lstat will fail, but pioctl will
4137 * work if the volume of offline (returning ENODEV). */
4138 statbuff.st_mode = S_IFDIR; /* lie like pros */
4142 * The lstat succeeded. If the given file is a symlink, substitute
4143 * the file name with the link name.
4145 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4148 * Read name of resolved file.
4150 link_chars_read = readlink(orig_name, true_name, 1024);
4151 if (link_chars_read <= 0) {
4153 "%s: Can't read target name for '%s' symbolic link!\n",
4160 * Add a trailing null to what was read, bump the length.
4162 true_name[link_chars_read++] = 0;
4165 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4166 * have to create a full pathname using the original name and the
4167 * relative symlink name. Find the rightmost slash in the original
4168 * name (we know there is one) and splice in the symlink value.
4170 if (true_name[0] != '/') {
4171 last_component = (char *)strrchr(orig_name, '/');
4172 strcpy(++last_component, true_name);
4173 strcpy(true_name, orig_name);
4176 strcpy(true_name, orig_name);
4179 * Find rightmost slash, if any.
4181 last_component = (char *)strrchr(true_name, '/');
4182 if (last_component) {
4184 * Found it. Designate everything before it as the parent directory,
4185 * everything after it as the final component.
4187 strncpy(parent_dir, true_name, last_component - true_name);
4188 parent_dir[last_component - true_name] = 0;
4189 last_component++; /*Skip the slash */
4192 * No slash appears in the given file name. Set parent_dir to the current
4193 * directory, and the last component as the given name.
4195 strcpy(parent_dir, ".");
4196 last_component = true_name;
4199 if (strcmp(last_component, ".") == 0
4200 || strcmp(last_component, "..") == 0) {
4202 "%s: you may not use '.' or '..' as the last component\n",
4204 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4210 blob.in = last_component;
4211 blob.in_size = strlen(last_component) + 1;
4213 memset(space, 0, MAXSIZE);
4215 code = pioctl(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4218 if (errno == EINVAL) {
4219 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4221 Die(errno, (ti->data ? ti->data : parent_dir));
4231 RxStatProcCmd(struct cmd_syndesc *as, char *arock)
4234 afs_int32 flags = 0;
4235 struct ViceIoctl blob;
4237 if (as->parms[0].items) { /* -enable */
4238 flags |= AFSCALL_RXSTATS_ENABLE;
4240 if (as->parms[1].items) { /* -disable */
4241 flags |= AFSCALL_RXSTATS_DISABLE;
4243 if (as->parms[2].items) { /* -clear */
4244 flags |= AFSCALL_RXSTATS_CLEAR;
4247 fprintf(stderr, "You must specify at least one argument\n");
4251 blob.in = (char *)&flags;
4252 blob.in_size = sizeof(afs_int32);
4255 code = pioctl(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4265 RxStatPeerCmd(struct cmd_syndesc *as, char *arock)
4268 afs_int32 flags = 0;
4269 struct ViceIoctl blob;
4271 if (as->parms[0].items) { /* -enable */
4272 flags |= AFSCALL_RXSTATS_ENABLE;
4274 if (as->parms[1].items) { /* -disable */
4275 flags |= AFSCALL_RXSTATS_DISABLE;
4277 if (as->parms[2].items) { /* -clear */
4278 flags |= AFSCALL_RXSTATS_CLEAR;
4281 fprintf(stderr, "You must specify at least one argument\n");
4285 blob.in = (char *)&flags;
4286 blob.in_size = sizeof(afs_int32);
4289 code = pioctl(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4299 #include "AFS_component_version_number.c"
4302 main(int argc, char **argv)
4305 struct cmd_syndesc *ts;
4307 #ifdef AFS_AIX32_ENV
4309 * The following signal action for AIX is necessary so that in case of a
4310 * crash (i.e. core is generated) we can include the user's data section
4311 * in the core dump. Unfortunately, by default, only a partial core is
4312 * generated which, in many cases, isn't too useful.
4314 struct sigaction nsa;
4316 sigemptyset(&nsa.sa_mask);
4317 nsa.sa_handler = SIG_DFL;
4318 nsa.sa_flags = SA_FULLDUMP;
4319 sigaction(SIGSEGV, &nsa, NULL);
4324 WSAStartup(0x0101, &WSAjunk);
4327 /* try to find volume location information */
4331 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, 0,
4332 "get client network interface addresses");
4333 cmd_CreateAlias(ts, "gc");
4335 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, 0,
4336 "set client network interface addresses");
4337 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
4338 "client network interfaces");
4339 cmd_CreateAlias(ts, "sc");
4342 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks");
4343 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
4344 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
4345 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
4346 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
4347 cmd_CreateAlias(ts, "sp");
4349 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks");
4350 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
4351 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4352 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
4353 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
4354 cmd_CreateAlias(ts, "gp");
4356 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
4357 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4358 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
4359 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
4360 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
4361 parm_setacl_id = ts->nParms;
4362 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
4363 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
4364 cmd_CreateAlias(ts, "sa");
4366 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list");
4367 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4368 parm_listacl_id = ts->nParms;
4369 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4370 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4371 cmd_CreateAlias(ts, "la");
4373 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list");
4374 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4376 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list");
4377 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
4378 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
4379 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
4380 parm_copyacl_id = ts->nParms;
4381 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4382 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4384 cmd_CreateAlias(ts, "ca");
4386 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
4387 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4390 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, 0,
4391 "flush mount symlink from cache");
4392 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4395 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
4396 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4397 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
4399 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
4401 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
4402 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
4403 cmd_CreateAlias(ts, "sv");
4405 ts = cmd_CreateSyntax("messages", MessagesCmd, 0, "control Cache Manager messages");
4406 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
4408 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display file/volume status");
4409 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4410 cmd_CreateAlias(ts, "lv");
4411 cmd_CreateAlias(ts, "listvol");
4413 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
4414 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4415 cmd_CreateAlias(ts, "lq");
4417 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage");
4418 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4419 cmd_CreateAlias(ts, "df");
4421 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
4422 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4424 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
4425 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4427 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
4428 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
4429 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
4430 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
4431 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
4432 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
4438 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
4442 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
4443 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4445 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers");
4446 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
4447 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
4448 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
4449 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
4451 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings");
4452 cmd_CreateAlias(ts, "checkbackups");
4455 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size");
4456 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
4457 cmd_CreateAlias(ts, "cachesize");
4459 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
4461 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info");
4463 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells");
4464 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4466 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
4467 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
4468 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
4470 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
4472 cmd_CreateAlias(ts, "sq");
4474 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
4476 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
4477 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
4478 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
4480 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
4482 * Turn this on only if you wish to be able to talk to a server which is listening
4483 * on alternative ports. This is not intended for general use and may not be
4484 * supported in the cache manager. It is not a way to run two servers at the
4485 * same host, since the cache manager cannot properly distinguish those two hosts.
4487 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
4488 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
4491 ts = cmd_CreateSyntax("newalias", NewAliasCmd, 0,
4492 "configure new cell alias");
4493 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
4494 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
4497 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
4498 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4500 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
4501 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4503 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
4506 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
4509 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, "set cache monitor host address");
4510 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
4511 cmd_CreateAlias(ts, "mariner");
4514 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
4515 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4517 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
4518 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4519 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
4520 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
4522 ts = cmd_CreateSyntax("flushall", FlushAllCmd, 0, "flush all data");
4524 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume");
4525 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4527 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value");
4528 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
4530 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS");
4531 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
4532 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
4533 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
4534 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
4535 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
4538 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
4539 "store to server after file close");
4540 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
4541 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
4542 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
4543 cmd_CreateAlias(ts, "sb");
4545 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag");
4546 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
4548 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "get cache manager encryption flag");
4550 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, 0,
4551 "Manage per process RX statistics");
4552 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4553 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4554 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4556 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, 0,
4557 "Manage per peer RX statistics");
4558 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4559 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4560 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4563 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, 0, "configure callback connection address");
4564 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
4567 ts = cmd_CreateSyntax("trace", TraceCmd, 0, "enable or disable CM tracing");
4568 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
4569 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
4570 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
4571 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
4572 cmd_CreateAlias(ts, "tr");
4574 ts = cmd_CreateSyntax("uuid", UuidCmd, 0, "manage the UUID for the cache manager");
4575 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
4577 ts = cmd_CreateSyntax("memdump", MemDumpCmd, 0, "dump memory allocs in debug builds");
4578 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
4579 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
4581 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, 0, "change client side caching policy for AFS shares");
4582 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
4583 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
4584 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
4585 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
4586 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
4588 ts = cmd_CreateSyntax("minidump", MiniDumpCmd, 0, "Generate MiniDump of current service state");
4590 code = cmd_Dispatch(argc, argv);
4599 Die(int code, char *filename)
4602 if (code == EINVAL) {
4604 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
4606 fprintf(stderr,"%s: Invalid argument.\n", pn);
4608 else if (code == ENOENT) {
4610 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
4612 fprintf(stderr,"%s: no such file returned\n", pn);
4614 else if (code == EROFS)
4615 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
4616 else if (code == EACCES || code == EPERM) {
4618 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
4620 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
4622 else if (code == ENODEV) {
4623 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
4625 else if (code == ESRCH) {
4626 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
4628 else if (code == EPIPE) {
4629 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
4631 else if (code == EFBIG) {
4632 fprintf(stderr,"%s: Cache size too large.\n", pn);
4634 else if (code == ETIMEDOUT) {
4636 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
4638 fprintf(stderr,"%s: Connection timed out", pn);
4642 fprintf(stderr,"%s:'%s'", pn, filename);
4644 fprintf(stderr,"%s", pn);
4646 fprintf(stderr, ": code 0x%x\n", code);
4647 #else /* not WIN32 */
4648 fprintf(stderr,": %s\n", afs_error_message(code));
4649 #endif /* not WIN32 */