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 CELL_MAXNAMELEN 256
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, void *arock);
54 static int SetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
55 static int FlushMountCmd(struct cmd_syndesc *asp, void *arock);
56 static int RxStatProcCmd(struct cmd_syndesc *asp, void *arock);
57 static int RxStatPeerCmd(struct cmd_syndesc *asp, void *arock);
59 extern struct cmd_syndesc *cmd_CreateSyntax();
61 static int MemDumpCmd(struct cmd_syndesc *asp, void *arock);
62 static int CSCPolicyCmd(struct cmd_syndesc *asp, void *arock);
63 static int MiniDumpCmd(struct cmd_syndesc *asp, void *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_utf8(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_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
274 return !cm_stricmp_utf8N("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 if (astr == NULL || sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell) <= 0) {
546 ParseAcl (char *astr)
548 int nplus, nminus, i, trights, ret;
550 struct AclEntry *first, *next, *last, *tl;
554 if (astr == NULL || strlen(astr) == 0)
557 ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
562 astr = SkipLine(astr);
563 ret = sscanf(astr, "%d", &ta->nminus);
568 astr = SkipLine(astr);
575 for(i=0;i<nplus;i++) {
576 ret = sscanf(astr, "%100s %d", tname, &trights);
579 astr = SkipLine(astr);
580 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
585 strcpy(tl->name, tname);
586 tl->rights = trights;
592 ta->pluslist = first;
596 for(i=0;i<nminus;i++) {
597 ret = sscanf(astr, "%100s %d", tname, &trights);
600 astr = SkipLine(astr);
601 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
606 strcpy(tl->name, tname);
607 tl->rights = trights;
613 ta->minuslist = first;
618 for (;first; first = next) {
622 first = ta->pluslist;
625 for (;first; first = next) {
634 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
636 printf("Volume status for vid = %u named %s is\n",status->Vid, name);
638 printf("Current offline message is %s\n",offmsg);
640 printf("Current message of the day is %s\n",motd);
641 printf("Current disk quota is ");
642 if (status->MaxQuota != 0)
643 printf("%d\n", status->MaxQuota);
645 printf("unlimited\n");
646 printf("Current blocks used are %d\n",status->BlocksInUse);
647 printf("The partition has %d blocks available out of %d\n",
648 status->PartBlocksAvail, status->PartMaxBlocks);
653 QuickPrintStatus(VolumeStatus *status, char *name)
655 double QuotaUsed =0.0;
656 double PartUsed =0.0;
658 printf("%-25.25s",name);
660 if (status->MaxQuota != 0) {
661 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
662 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
664 printf("no limit%10d", status->BlocksInUse);
666 if (QuotaUsed > 90.0){
667 printf(" %5.0f%%<<", QuotaUsed);
670 printf(" %5.0f%% ", QuotaUsed);
671 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
672 if (PartUsed > 97.0){
673 printf(" %9.0f%%<<", PartUsed);
676 printf(" %9.0f%% ", PartUsed);
678 printf(" <<WARNING\n");
685 QuickPrintSpace(VolumeStatus *status, char *name)
687 double PartUsed =0.0;
689 printf("%-25.25s",name);
691 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
693 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
694 if (PartUsed > 90.0){
695 printf(" %4.0f%%<<", PartUsed);
698 printf(" %4.0f%% ", PartUsed);
700 printf(" <<WARNING\n");
707 AclToString(struct Acl *acl)
709 static char mydata[MAXSIZE];
710 char tstring[MAXSIZE];
715 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
718 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
719 for (tp = acl->pluslist;tp;tp=tp->next) {
720 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
721 strcat(mydata, tstring);
723 for (tp = acl->minuslist;tp;tp=tp->next) {
724 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
725 strcat(mydata, tstring);
730 static DWORD IsFreelance(void)
737 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
738 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
739 if (code == ERROR_SUCCESS) {
740 dummyLen = sizeof(cm_freelanceEnabled);
741 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
742 (BYTE *) &enabled, &dummyLen);
743 RegCloseKey (parmKey);
748 static const char * NetbiosName(void)
750 static char buffer[1024] = "AFS";
756 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
757 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
758 if (code == ERROR_SUCCESS) {
759 dummyLen = sizeof(buffer);
760 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
762 RegCloseKey (parmKey);
764 strcpy(buffer, "AFS");
769 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
771 static BOOL IsAdmin (void)
773 static BOOL fAdmin = FALSE;
774 static BOOL fTested = FALSE;
778 /* Obtain the SID for the AFS client admin group. If the group does
779 * not exist, then assume we have AFS client admin privileges.
781 PSID psidAdmin = NULL;
782 DWORD dwSize, dwSize2;
783 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
784 char *pszRefDomain = NULL;
785 SID_NAME_USE snu = SidTypeGroup;
787 dwSize = sizeof(pszAdminGroup);
789 if (!GetComputerName(pszAdminGroup, &dwSize)) {
790 /* Can't get computer name. We return false in this case.
791 Retain fAdmin and fTested. This shouldn't happen.*/
798 strcat(pszAdminGroup,"\\");
799 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
801 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
802 /* that should always fail. */
804 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
805 /* if we can't find the group, then we allow the operation */
810 if (dwSize == 0 || dwSize2 == 0) {
816 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
818 pszRefDomain = (char *)malloc(dwSize2);
819 assert(pszRefDomain);
821 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
822 /* We can't lookup the group now even though we looked it up earlier.
823 Could this happen? */
826 /* Then open our current ProcessToken */
829 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
832 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
833 /* We'll have to allocate a chunk of memory to store the list of
834 * groups to which this user belongs; find out how much memory
838 PTOKEN_GROUPS pGroups;
840 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
842 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
845 /* Allocate that buffer, and read in the list of groups. */
846 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
848 /* Look through the list of group SIDs and see if any of them
849 * matches the AFS Client Admin group SID.
852 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
854 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
864 /* if do not have permission because we were not explicitly listed
865 * in the Admin Client Group let's see if we are the SYSTEM account
868 PTOKEN_USER pTokenUser;
869 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
870 PSID pSidLocalSystem = 0;
873 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
875 pTokenUser = (PTOKEN_USER)malloc(dwSize);
878 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
879 gle = GetLastError();
881 if (AllocateAndInitializeSid( &SIDAuth, 1,
882 SECURITY_LOCAL_SYSTEM_RID,
886 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
890 FreeSid(pSidLocalSystem);
909 SetACLCmd(struct cmd_syndesc *as, void *arock)
912 struct ViceIoctl blob;
914 struct cmd_item *ti, *ui;
918 int idf = getidf(as, parm_setacl_id);
922 if (as->parms[2].items)
926 plusp = !(as->parms[3].items);
927 for(ti=as->parms[0].items; ti;ti=ti->next) {
928 blob.out_size = MAXSIZE;
930 blob.in = blob.out = space;
931 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
933 Die(errno, ti->data);
939 ta = ParseAcl(space);
942 "fs: %s: invalid acl data returned from VIOCGETAL\n",
947 if (!plusp && ta->dfs) {
949 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
951 "(you may specify \"null\" to revoke all rights, however)\n");
958 ta = EmptyAcl(space);
960 ta = ParseAcl(space);
963 "fs: %s: invalid acl data returned from VIOCGETAL\n",
968 CleanAcl(ta, ti->data);
969 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
973 "%s: Missing second half of user/access pair.\n", pn);
977 rights = Convert(ui->next->data, ta->dfs, &rtype);
978 if (rtype == destroy && !ta->dfs) {
979 struct AclEntry *tlist;
981 tlist = (plusp ? ta->pluslist : ta->minuslist);
982 if (!FindList(tlist, ui->data))
985 if (rtype == deny && !ta->dfs)
987 if (rtype == destroy && ta->dfs)
989 ChangeList(ta, plusp, ui->data, rights);
991 blob.in = AclToString(ta);
993 blob.in_size = 1+(long)strlen(blob.in);
994 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
996 if (errno == EINVAL) {
998 static char *fsenv = 0;
1000 fsenv = (char *)getenv("FS_EXPERT");
1002 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
1005 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1006 "\nPossible reasons for this include:\n\n",
1007 " -You may have specified an inappropriate combination of rights.\n",
1008 " For example, some DFS-supported filesystems may not allow you to\n",
1009 " drop the \"c\" right from \"user_obj\".\n\n",
1010 " -A mask_obj may be required (it is likely required by the underlying\n",
1011 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
1012 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
1013 " does not automatically create or update the mask_obj. Try setting\n",
1014 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
1015 " users or groups. You can do this with a single command, such as\n",
1016 " \"fs sa mask_obj all user:somename read\"\n\n",
1017 " -A specified user or group may not exist.\n\n",
1018 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
1019 " This is probably not allowed by the underlying file system.\n\n",
1020 " -If you add a user or group to a DFS ACL, remember that it must be\n",
1021 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
1022 " may be local requirements on the format of the user or group name.\n",
1023 " Check with your cell administrator.\n\n",
1024 " -Or numerous other possibilities. It would be great if we could be more\n",
1025 " precise about the actual problem, but for various reasons, this is\n",
1026 " impractical via this interface. If you can't figure it out, you\n",
1027 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
1028 " whatever is provided). You may get better results. Good luck!\n\n",
1029 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
1033 "%s: Invalid argument, possible reasons include:\n",
1035 fprintf(stderr,"\t-File not in AFS\n");
1037 "\t-Too many users on access control list\n");
1039 "\t-Tried to add non-existent user to access control list\n");
1042 Die(errno, ti->data);
1053 CopyACLCmd(struct cmd_syndesc *as, void *arock)
1056 struct ViceIoctl blob;
1057 struct Acl *fa, *ta = 0;
1058 struct AclEntry *tp;
1059 struct cmd_item *ti;
1061 int idf = getidf(as, parm_copyacl_id);
1064 if (as->parms[2].items)
1068 blob.out_size = MAXSIZE;
1070 blob.in = blob.out = space;
1071 code = pioctl_utf8(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1073 Die(errno, as->parms[0].items->data);
1076 fa = ParseAcl(space);
1079 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1080 as->parms[0].items->data);
1083 CleanAcl(fa, as->parms[0].items->data);
1084 for (ti=as->parms[1].items; ti;ti=ti->next) {
1085 blob.out_size = MAXSIZE;
1087 blob.in = blob.out = space;
1088 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1090 Die(errno, ti->data);
1097 ta = EmptyAcl(space);
1099 ta = ParseAcl(space);
1102 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1107 CleanAcl(ta, ti->data);
1108 if (ta->dfs != fa->dfs) {
1110 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1116 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1118 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1123 strcpy(ta->cell, fa->cell);
1125 for (tp = fa->pluslist;tp;tp=tp->next)
1126 ChangeList(ta, 1, tp->name, tp->rights);
1127 for (tp = fa->minuslist;tp;tp=tp->next)
1128 ChangeList(ta, 0, tp->name, tp->rights);
1129 blob.in = AclToString(ta);
1131 blob.in_size = 1+(long)strlen(blob.in);
1132 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1134 if (errno == EINVAL) {
1136 "%s: Invalid argument, possible reasons include:\n", pn);
1137 fprintf(stderr,"\t-File not in AFS\n");
1139 Die(errno, ti->data);
1150 /* pioctl_utf8() call to get the cellname of a pathname */
1152 GetCell(char *fname, char *cellname)
1155 struct ViceIoctl blob;
1158 blob.out_size = CELL_MAXNAMELEN;
1159 blob.out = cellname;
1161 code = pioctl_utf8(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1165 /* Check if a username is valid: If it contains only digits (or a
1166 * negative sign), then it might be bad. We then query the ptserver
1170 BadName(char *aname, char *fname)
1172 afs_int32 tc, code, id;
1174 char cell[CELL_MAXNAMELEN];
1177 for ( nm = aname; tc = *nm; nm++) {
1178 /* all must be '-' or digit to be bad */
1179 if (tc != '-' && (tc < '0' || tc > '9'))
1183 /* Go to the PRDB and see if this all number username is valid */
1184 code = GetCell(fname, cell);
1188 cm_GetConfigDir(confDir, sizeof(confDir));
1190 pr_Initialize(1, confDir, cell);
1191 code = pr_SNameToId(aname, &id);
1194 /* 1=>Not-valid; 0=>Valid */
1195 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1199 /* clean up an access control list of its bad entries; return 1 if we made
1200 any changes to the list, and 0 otherwise */
1202 CleanAcl(struct Acl *aa, char *fname)
1204 struct AclEntry *te, **le, *ne;
1207 /* Don't correct DFS ACL's for now */
1211 /* prune out bad entries */
1212 changes = 0; /* count deleted entries */
1214 for(te = aa->pluslist; te; te=ne) {
1216 if (BadName(te->name, fname)) {
1226 le = &aa->minuslist;
1227 for(te = aa->minuslist; te; te=ne) {
1229 if (BadName(te->name, fname)) {
1243 /* clean up an acl to not have bogus entries */
1245 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1249 struct ViceIoctl blob;
1251 struct cmd_item *ti;
1252 struct AclEntry *te;
1255 SetDotDefault(&as->parms[0].items);
1256 for(ti=as->parms[0].items; ti; ti=ti->next) {
1257 blob.out_size = MAXSIZE;
1260 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1262 Die(errno, ti->data);
1268 ta = ParseAcl(space);
1271 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1278 "%s: cleanacl is not supported for DFS access lists.\n",
1284 changes = CleanAcl(ta, ti->data);
1287 /* now set the acl */
1288 blob.in=AclToString(ta);
1289 blob.in_size = (long)strlen(blob.in)+1;
1291 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1293 if (errno == EINVAL) {
1295 "%s: Invalid argument, possible reasons include\n",
1297 fprintf(stderr,"%s: File not in vice or\n", pn);
1299 "%s: Too many users on access control list or\n",
1302 Die(errno, ti->data);
1308 /* now list the updated acl */
1309 printf("Access list for %s is now\n", ti->data);
1310 if (ta->nplus > 0) {
1312 printf("Normal rights:\n");
1313 for(te = ta->pluslist;te;te=te->next) {
1314 printf(" %s ", te->name);
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);
1330 printf("Access list for %s is fine.\n", ti->data);
1338 ListACLCmd(struct cmd_syndesc *as, void *arock)
1342 struct ViceIoctl blob;
1343 struct AclEntry *te;
1344 struct cmd_item *ti;
1345 int idf = getidf(as, parm_listacl_id);
1348 SetDotDefault(&as->parms[0].items);
1349 for(ti=as->parms[0].items; ti; ti=ti->next) {
1351 blob.out_size = MAXSIZE;
1353 blob.in = blob.out = space;
1354 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1356 Die(errno, ti->data);
1360 ta = ParseAcl(space);
1363 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1370 printf("Access list for %s is\n", ti->data);
1373 printf("DFS access list for %s is\n", ti->data);
1376 printf("DFS initial directory access list of %s is\n", ti->data);
1379 printf("DFS initial file access list of %s is\n", ti->data);
1383 printf(" Default cell = %s\n", ta->cell);
1385 separator = ta->dfs? DFS_SEPARATOR : ' ';
1386 if (ta->nplus > 0) {
1388 printf("Normal rights:\n");
1389 for(te = ta->pluslist;te;te=te->next) {
1390 printf(" %s%c", te->name, separator);
1391 PRights(te->rights, ta->dfs);
1395 if (ta->nminus > 0) {
1396 printf("Negative rights:\n");
1397 for(te = ta->minuslist;te;te=te->next) {
1398 printf(" %s ", te->name);
1399 PRights(te->rights, ta->dfs);
1411 FlushAllCmd(struct cmd_syndesc *as, void *arock)
1414 struct ViceIoctl blob;
1416 blob.in_size = blob.out_size = 0;
1417 code = pioctl_utf8(NULL, VIOC_FLUSHALL, &blob, 0);
1419 fprintf(stderr, "Error flushing all ");
1426 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1429 struct ViceIoctl blob;
1430 struct cmd_item *ti;
1433 SetDotDefault(&as->parms[0].items);
1434 for(ti=as->parms[0].items; ti; ti=ti->next) {
1435 blob.in_size = blob.out_size = 0;
1436 code = pioctl_utf8(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1438 fprintf(stderr, "Error flushing volume ");
1448 FlushCmd(struct cmd_syndesc *as, void *arock)
1451 struct ViceIoctl blob;
1452 struct cmd_item *ti;
1455 cm_ioctlQueryOptions_t options;
1457 if (as->parms[1].items)
1460 for(ti=as->parms[0].items; ti; ti=ti->next) {
1462 memset(&options, 0, sizeof(options));
1463 options.size = sizeof(options);
1464 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1465 options.literal = literal;
1466 blob.in_size = options.size; /* no variable length data */
1470 code = pioctl_utf8(ti->data, VIOCFLUSH, &blob, 0);
1472 if (errno == EMFILE) {
1473 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1476 fprintf(stderr, "%s: Error flushing file ", pn);
1486 /* all this command does is repackage its args and call SetVolCmd */
1488 SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
1489 struct cmd_syndesc ts;
1491 /* copy useful stuff from our command slot; we may later have to reorder */
1492 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1493 return SetVolCmd(&ts, arock);
1497 SetVolCmd(struct cmd_syndesc *as, void *arock) {
1499 struct ViceIoctl blob;
1500 struct cmd_item *ti;
1501 struct VolumeStatus *status;
1502 char *motd, *offmsg, *input;
1505 SetDotDefault(&as->parms[0].items);
1506 for(ti=as->parms[0].items; ti; ti=ti->next) {
1508 blob.out_size = MAXSIZE;
1509 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1512 status = (VolumeStatus *)space;
1513 status->MinQuota = status->MaxQuota = -1;
1514 motd = offmsg = NULL;
1515 if (as->parms[1].items) {
1516 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1518 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1523 if (as->parms[2].items)
1524 motd = as->parms[2].items->data;
1525 if (as->parms[3].items)
1526 offmsg = as->parms[3].items->data;
1527 input = (char *)status + sizeof(*status);
1528 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1530 if (strlen(offmsg) >= VMSGSIZE) {
1531 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1536 strcpy(input,offmsg);
1537 blob.in_size += (long)strlen(offmsg);
1538 input += strlen(offmsg) + 1;
1542 if (strlen(motd) >= VMSGSIZE) {
1543 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1548 blob.in_size += (long)strlen(motd);
1549 input += strlen(motd) + 1;
1552 code = pioctl_utf8(ti->data,VIOCSETVOLSTAT, &blob, 1);
1554 Die(errno, ti->data);
1561 /* values match cache manager File Types */
1563 filetypestr(afs_uint32 type)
1565 char * s = "Object";
1588 ExamineCmd(struct cmd_syndesc *as, void *arock)
1591 struct ViceIoctl blob;
1592 struct cmd_item *ti;
1593 struct VolumeStatus *status;
1594 char *name, *offmsg, *motd;
1597 cm_ioctlQueryOptions_t options;
1599 if (as->parms[1].items)
1602 SetDotDefault(&as->parms[0].items);
1603 for(ti=as->parms[0].items; ti; ti=ti->next) {
1605 afs_uint32 filetype;
1606 afs_uint32 owner[2];
1607 char cell[CELL_MAXNAMELEN];
1610 memset(&fid, 0, sizeof(fid));
1611 memset(&options, 0, sizeof(options));
1613 options.size = sizeof(options);
1614 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1615 options.literal = literal;
1616 blob.in_size = options.size; /* no variable length data */
1619 blob.out_size = sizeof(cm_fid_t);
1620 blob.out = (char *) &fid;
1621 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
1622 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1625 Die(errno, ti->data);
1630 blob.out_size = sizeof(filetype);
1631 blob.out = &filetype;
1633 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1635 blob.out_size = CELL_MAXNAMELEN;
1638 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1639 printf("%s %s (%u.%u.%u) contained in cell %s\n",
1640 filetypestr(filetype),
1641 ti->data, fid.volume, fid.vnode, fid.unique,
1642 code ? "unknown-cell" : cell);
1644 blob.out_size = 2 * sizeof(afs_uint32);
1645 blob.out = (char *) &owner;
1646 if (0 == pioctl_utf8(ti->data, VIOCGETOWNER, &blob, 1)) {
1647 char oname[PR_MAXNAMELEN] = "(unknown)";
1650 /* Go to the PRDB and see if this all number username is valid */
1651 cm_GetConfigDir(confDir, sizeof(confDir));
1653 pr_Initialize(1, confDir, cell);
1654 pr_SIdToName(owner[0], oname);
1655 printf("Owner %s (%u) Group %u\n", oname, owner[0], owner[1]);
1659 blob.out_size = MAXSIZE;
1660 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1662 status = (VolumeStatus *)space;
1663 name = (char *)status + sizeof(*status);
1664 offmsg = name + strlen(name) + 1;
1665 motd = offmsg + strlen(offmsg) + 1;
1667 PrintStatus(status, name, motd, offmsg);
1669 Die(errno, ti->data);
1673 code = pioctl_utf8(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
1676 printf("Volume is online\n");
1679 printf("Volume is offline\n");
1682 printf("All Volume servers are down\n");
1685 printf("All volume servers are busy\n");
1688 printf("Unknown volume state\n");
1689 Die(errno, ti->data);
1697 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1700 struct ViceIoctl blob;
1701 struct cmd_item *ti;
1702 struct VolumeStatus *status;
1707 printf("%-25s%-10s%-10s%-7s%-13s\n",
1708 "Volume Name", " Quota", " Used", " %Used", " Partition");
1709 SetDotDefault(&as->parms[0].items);
1710 for(ti=as->parms[0].items; ti; ti=ti->next) {
1712 blob.out_size = MAXSIZE;
1715 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1717 Die(errno, ti->data);
1721 status = (VolumeStatus *)space;
1722 name = (char *)status + sizeof(*status);
1723 QuickPrintStatus(status, name);
1729 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1732 struct ViceIoctl blob;
1733 struct cmd_item *ti;
1739 cm_ioctlQueryOptions_t options;
1741 if (as->parms[1].items)
1744 SetDotDefault(&as->parms[0].items);
1745 for(ti=as->parms[0].items; ti; ti=ti->next) {
1747 afs_uint32 filetype;
1750 memset(&fid, 0, sizeof(fid));
1751 memset(&options, 0, sizeof(options));
1753 options.size = sizeof(options);
1754 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1755 options.literal = literal;
1756 blob.in_size = options.size; /* no variable length data */
1759 blob.out_size = sizeof(cm_fid_t);
1760 blob.out = (char *) &fid;
1761 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
1762 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1765 Die(errno, ti->data);
1770 blob.out_size = sizeof(filetype);
1771 blob.out = &filetype;
1773 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1775 blob.out_size = MAXSIZE;
1777 memset(space, 0, sizeof(space));
1778 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
1780 Die(errno, ti->data);
1784 hosts = (afs_int32 *) space;
1785 printf("%s %s is on host%s ",
1786 filetypestr(filetype),
1788 (hosts[0] && !hosts[1]) ? "": "s");
1789 for(j=0; j<MAXHOSTS; j++) {
1792 tp = hostutil_GetNameByINet(hosts[j]);
1802 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1805 struct ViceIoctl blob;
1806 struct cmd_item *ti;
1808 struct VolumeStatus *status;
1811 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1812 " used", " avail", " %used");
1813 SetDotDefault(&as->parms[0].items);
1814 for(ti=as->parms[0].items; ti; ti=ti->next) {
1816 blob.out_size = MAXSIZE;
1819 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1821 Die(errno, ti->data);
1825 status = (VolumeStatus *)space;
1826 name = (char *)status + sizeof(*status);
1827 QuickPrintSpace(status, name);
1833 QuotaCmd(struct cmd_syndesc *as, void *arock)
1836 struct ViceIoctl blob;
1837 struct cmd_item *ti;
1839 struct VolumeStatus *status;
1842 SetDotDefault(&as->parms[0].items);
1843 for(ti=as->parms[0].items; ti; ti=ti->next) {
1845 blob.out_size = MAXSIZE;
1848 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1850 Die(errno, ti->data);
1854 status = (VolumeStatus *)space;
1855 if (status->MaxQuota)
1856 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1859 printf("%2.0f%% of quota used.\n", quotaPct);
1865 ListMountCmd(struct cmd_syndesc *as, void *arock)
1868 struct ViceIoctl blob;
1869 struct cmd_item *ti;
1870 char orig_name[1024]; /*Original name, may be modified*/
1871 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1872 char parent_dir[1024]; /*Parent directory of true name*/
1873 char *last_component; /*Last component of true name*/
1875 struct stat statbuff; /*Buffer for status info*/
1876 #endif /* not WIN32 */
1878 int link_chars_read; /*Num chars read in readlink()*/
1879 #endif /* not WIN32 */
1880 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1883 for(ti=as->parms[0].items; ti; ti=ti->next) {
1887 strcpy(orig_name, ti->data);
1888 #else /* not WIN32 */
1889 sprintf(orig_name, "%s%s",
1890 (ti->data[0] == '/') ? "" : "./",
1892 #endif /* not WIN32 */
1895 if (lstat(orig_name, &statbuff) < 0) {
1896 /* if lstat fails, we should still try the pioctl, since it
1897 * may work (for example, lstat will fail, but pioctl will
1898 * work if the volume of offline (returning ENODEV). */
1899 statbuff.st_mode = S_IFDIR; /* lie like pros */
1903 * The lstat succeeded. If the given file is a symlink, substitute
1904 * the file name with the link name.
1906 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1909 * Read name of resolved file.
1911 link_chars_read = readlink(orig_name, true_name, 1024);
1912 if (link_chars_read <= 0) {
1914 "%s: Can't read target name for '%s' symbolic link!\n",
1921 * Add a trailing null to what was read, bump the length.
1923 true_name[link_chars_read++] = 0;
1926 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1927 * have to create a full pathname using the original name and the
1928 * relative symlink name. Find the rightmost slash in the original
1929 * name (we know there is one) and splice in the symlink value.
1931 if (true_name[0] != '\\') {
1932 last_component = (char *) strrchr(orig_name, '\\');
1933 strcpy(++last_component, true_name);
1934 strcpy(true_name, orig_name);
1937 strcpy(true_name, orig_name);
1939 strcpy(true_name, orig_name);
1943 * Find rightmost slash, if any.
1946 last_component = (char *) strrchr(true_name, '\\');
1947 if (!last_component)
1949 last_component = (char *) strrchr(true_name, '/');
1950 if (last_component) {
1952 * Found it. Designate everything before it as the parent directory,
1953 * everything after it as the final component.
1955 strncpy(parent_dir, true_name, last_component - true_name + 1);
1956 parent_dir[last_component - true_name + 1] = 0;
1957 last_component++; /*Skip the slash*/
1959 if (!InAFS(parent_dir)) {
1960 const char * nbname = NetbiosName();
1961 int len = (int)strlen(nbname);
1963 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
1964 parent_dir[len+2] == '\\' &&
1965 parent_dir[len+3] == '\0' &&
1966 !strnicmp(nbname,&parent_dir[2],len))
1968 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
1974 * No slash appears in the given file name. Set parent_dir to the current
1975 * directory, and the last component as the given name.
1977 fs_ExtractDriveLetter(true_name, parent_dir);
1978 strcat(parent_dir, ".");
1979 last_component = true_name;
1980 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1983 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1984 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
1985 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
1990 blob.in = last_component;
1991 blob.in_size = (long)strlen(last_component)+1;
1992 blob.out_size = MAXSIZE;
1994 memset(space, 0, MAXSIZE);
1996 code = pioctl_utf8(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1999 printf("'%s' is a %smount point for volume '%s'\n",
2001 (thru_symlink ? "symbolic link, leading to a " : ""),
2005 if (errno == EINVAL) {
2006 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
2008 Die(errno, (ti->data ? ti->data : parent_dir));
2017 MakeMountCmd(struct cmd_syndesc *as, void *arock)
2020 char *cellName, *volName, *tmpName;
2022 char localCellName[128];
2024 char path[1024] = "";
2025 struct afsconf_cell info;
2026 struct vldbentry vldbEntry;
2027 struct ViceIoctl blob;
2030 if (as->parms[2].items) /* cell name specified */
2031 cellName = as->parms[2].items->data;
2034 volName = as->parms[1].items->data;
2036 if (strlen(volName) >= 64) {
2037 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
2041 /* Check for a cellname in the volume specification, and complain
2042 * if it doesn't match what was specified with -cell */
2043 if (tmpName = strchr(volName, ':')) {
2046 if (strcasecmp(cellName,volName)) {
2047 fprintf(stderr,"fs: cellnames do not match.\n");
2052 volName = ++tmpName;
2055 parent = Parent(as->parms[0].items->data);
2056 if (!InAFS(parent)) {
2058 const char * nbname = NetbiosName();
2059 int len = (int)strlen(nbname);
2061 if (parent[0] == '\\' && parent[1] == '\\' &&
2062 parent[len+2] == '\\' &&
2063 parent[len+3] == '\0' &&
2064 !strnicmp(nbname,&parent[2],len))
2066 sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
2067 parent = Parent(path);
2068 if (!InAFS(parent)) {
2069 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2075 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2080 if ( strlen(path) == 0 )
2081 strcpy(path, as->parms[0].items->data);
2083 if ( IsFreelanceRoot(parent) ) {
2085 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2091 blob.out_size = sizeof(localCellName);
2092 blob.out = localCellName;
2093 code = pioctl_utf8(parent, VIOC_GET_WS_CELL, &blob, 1);
2095 cellName = localCellName;
2099 code = GetCell(parent,space);
2105 code = GetCellName(cellName?cellName:space, &info);
2109 if (!(as->parms[4].items)) {
2110 /* not fast, check which cell the mountpoint is being created in */
2112 /* not fast, check name with VLDB */
2114 code = VLDBInit(1, &info);
2116 /* make the check. Don't complain if there are problems with init */
2117 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2118 if (code == VL_NOENT) {
2119 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2120 pn, volName, cellName ? cellName : space);
2125 if (as->parms[3].items) /* if -rw specified */
2130 /* cellular mount point, prepend cell prefix */
2131 strcat(space, info.name);
2134 strcat(space, volName); /* append volume name */
2135 strcat(space, "."); /* stupid convention; these end with a period */
2137 /* create symlink with a special pioctl for Windows NT, since it doesn't
2138 * have a symlink system call.
2141 blob.in_size = 1 + (long)strlen(space);
2144 code = pioctl_utf8(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2145 #else /* not WIN32 */
2146 code = symlink(space, path);
2147 #endif /* not WIN32 */
2156 * Delete AFS mount points. Variables are used as follows:
2157 * tbuffer: Set to point to the null-terminated directory name of the mount point
2158 * (or ``.'' if none is provided)
2159 * tp: Set to point to the actual name of the mount point to nuke.
2162 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2164 struct ViceIoctl blob;
2165 struct cmd_item *ti;
2167 char lsbuffer[1024];
2171 for(ti=as->parms[0].items; ti; ti=ti->next) {
2173 tp = (char *) strrchr(ti->data, '\\');
2175 tp = (char *) strrchr(ti->data, '/');
2177 strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1)); /* the dir name */
2179 tp++; /* skip the slash */
2182 if (!InAFS(tbuffer)) {
2183 const char * nbname = NetbiosName();
2184 int len = (int)strlen(nbname);
2186 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2187 tbuffer[len+2] == '\\' &&
2188 tbuffer[len+3] == '\0' &&
2189 !strnicmp(nbname,&tbuffer[2],len))
2191 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
2196 fs_ExtractDriveLetter(ti->data, tbuffer);
2197 strcat(tbuffer, ".");
2199 fs_StripDriveLetter(tp, tp, 0);
2202 blob.in_size = (long)strlen(tp)+1;
2203 blob.out = lsbuffer;
2204 blob.out_size = sizeof(lsbuffer);
2205 code = pioctl_utf8(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2207 if (errno == EINVAL) {
2208 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2210 Die(errno, ti->data);
2213 continue; /* don't bother trying */
2216 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2217 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2219 continue; /* skip */
2224 blob.in_size = (long)strlen(tp)+1;
2225 code = pioctl_utf8(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2227 Die(errno, ti->data);
2238 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2241 struct ViceIoctl blob;
2245 struct afsconf_cell info;
2246 struct chservinfo checkserv;
2248 memset(&checkserv, 0, sizeof(struct chservinfo));
2249 blob.in_size=sizeof(struct chservinfo);
2250 blob.in=(caddr_t)&checkserv;
2252 blob.out_size = MAXSIZE;
2254 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2256 /* prepare flags for checkservers command */
2257 temp = 2; /* default to checking local cell only */
2258 if (as->parms[2].items)
2259 temp |= 1; /* set fast flag */
2260 if (as->parms[1].items)
2261 temp &= ~2; /* turn off local cell check */
2263 checkserv.magic = 0x12345678; /* XXX */
2264 checkserv.tflags=temp;
2266 /* now copy in optional cell name, if specified */
2267 if (as->parms[0].items) {
2268 code = GetCellName(as->parms[0].items->data, &info);
2272 strcpy(checkserv.tbuffer,info.name);
2273 checkserv.tsize=(int)strlen(info.name)+1;
2275 strcpy(checkserv.tbuffer,"\0");
2279 if(as->parms[3].items) {
2280 checkserv.tinterval=atol(as->parms[3].items->data);
2283 if(checkserv.tinterval<0) {
2284 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2285 checkserv.tinterval=-1;
2286 } else if(checkserv.tinterval> 600) {
2287 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2288 checkserv.tinterval=600; /* 10 min max interval */
2291 checkserv.tinterval = -1; /* don't change current interval */
2294 if ( checkserv.tinterval >= 0 ) {
2297 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2302 fprintf (stderr,"Permission denied: requires root access.\n");
2308 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
2310 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2311 printf("Must be root to change -interval\n");
2317 memcpy(&temp, space, sizeof(afs_int32));
2318 if (checkserv.tinterval >= 0) {
2319 if (checkserv.tinterval > 0)
2320 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2321 checkserv.tinterval, temp);
2323 printf("The current down server probe interval is %d secs\n", temp);
2327 printf("All servers are running.\n");
2329 printf("These servers unavailable due to network or server problems: ");
2330 for(j=0; j < MAXHOSTS; j++) {
2331 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2334 tp = hostutil_GetNameByINet(temp);
2344 MessagesCmd(struct cmd_syndesc *as, void *arock)
2347 struct ViceIoctl blob;
2348 struct gaginfo gagflags;
2349 struct cmd_item *show;
2351 memset(&gagflags, 0, sizeof(struct gaginfo));
2352 blob.in_size = sizeof(struct gaginfo);
2353 blob.in = (caddr_t ) &gagflags;
2354 blob.out_size = MAXSIZE;
2356 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2358 if (show = as->parms[0].items) {
2359 if (!strcasecmp (show->data, "user"))
2360 gagflags.showflags |= GAGUSER;
2361 else if (!strcasecmp (show->data, "console"))
2362 gagflags.showflags |= GAGCONSOLE;
2363 else if (!strcasecmp (show->data, "all"))
2364 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2365 else if (!strcasecmp (show->data, "none"))
2369 "unrecognized flag %s: must be in {user,console,all,none}\n",
2378 code = pioctl_utf8(0, VIOC_GAG, &blob, 1);
2387 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2390 struct ViceIoctl blob;
2394 code = pioctl_utf8(0, VIOCCKBACK, &blob, 1);
2399 printf("All volumeID/name mappings checked.\n");
2405 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2408 struct ViceIoctl blob;
2413 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2418 fprintf (stderr,"Permission denied: requires root access.\n");
2423 if (!as->parms[0].items && !as->parms[1].items) {
2424 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2427 if (as->parms[0].items) {
2428 code = util_GetInt32(as->parms[0].items->data, &temp);
2430 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2435 blob.in = (char *) &temp;
2436 blob.in_size = sizeof(afs_int32);
2438 code = pioctl_utf8(0, VIOCSETCACHESIZE, &blob, 1);
2440 Die(errno, (char *) 0);
2444 printf("New cache size set.\n");
2449 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2452 struct ViceIoctl blob;
2453 cm_cacheParms_t parms;
2455 memset(&parms, 0, sizeof(parms));
2458 blob.out_size = sizeof(parms);
2459 blob.out = (char *) &parms;
2460 code = pioctl_utf8(0, VIOCGETCACHEPARMS, &blob, 1);
2466 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2467 parms.parms[1], parms.parms[0]);
2468 if (parms.parms[1] > parms.parms[0])
2469 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2474 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2477 afs_int32 i, j, *lp, magic, size;
2479 afs_int32 addr, maxa = OMAXHOSTS;
2480 struct ViceIoctl blob;
2483 resolve = !(as->parms[0].items); /* -numeric */
2485 for(i=0;i<1000;i++) {
2487 memcpy(tp, &i, sizeof(afs_int32));
2488 tp = (char *)(space + sizeof(afs_int32));
2489 lp = (afs_int32 *)tp;
2491 size = sizeof(afs_int32) + sizeof(afs_int32);
2492 blob.out_size = MAXSIZE;
2493 blob.in_size = sizeof(afs_int32);
2496 code = pioctl_utf8(0, VIOCGETCELL, &blob, 1);
2499 break; /* done with the list */
2504 memcpy(&magic, tp, sizeof(afs_int32));
2505 if (magic == 0x12345678) {
2507 tp += sizeof(afs_int32);
2509 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2510 for(j=0; j < maxa; j++) {
2511 char *name, tbuffer[20];
2513 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2518 name = hostutil_GetNameByINet(addr);
2521 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2522 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2525 printf(" %s", name);
2534 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2537 char *tp, *aliasName, *realName;
2538 struct ViceIoctl blob;
2542 memcpy(tp, &i, sizeof(afs_int32));
2543 blob.out_size = MAXSIZE;
2544 blob.in_size = sizeof(afs_int32);
2547 code = pioctl_utf8(0, VIOC_GETALIAS, &blob, 1);
2550 break; /* done with the list */
2556 tp += strlen(aliasName) + 1;
2558 printf("Alias %s for cell %s\n", aliasName, realName);
2564 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2567 struct ViceIoctl blob;
2568 struct cmd_item *ti;
2570 struct hostent *thp;
2574 ti = as->parms[0].items;
2577 thp = hostutil_GetHostByName(ti->data);
2579 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2582 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2584 hostAddr = 0; /* means don't set host */
2585 setp = 0; /* aren't setting host */
2588 /* now do operation */
2589 blob.in_size = sizeof(afs_int32);
2590 blob.out_size = sizeof(afs_int32);
2591 blob.in = (char *) &hostAddr;
2592 blob.out = (char *) &hostAddr;
2594 code = pioctl_utf8(0, VIOC_CBADDR, &blob, 1);
2604 NewCellCmd(struct cmd_syndesc *as, void *arock)
2607 afs_int32 code, linkedstate=0, size=0, *lp;
2608 struct ViceIoctl blob;
2609 struct cmd_item *ti;
2610 char *tp, *cellname=0;
2611 struct hostent *thp;
2612 afs_int32 fsport = 0, vlport = 0;
2614 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
2616 lp = (afs_int32 *)tp;
2618 tp += sizeof(afs_int32);
2619 for(ti=as->parms[1].items; ti; ti=ti->next) {
2620 thp = hostutil_GetHostByName(ti->data);
2622 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2626 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2627 tp += sizeof(afs_int32);
2630 if (as->parms[2].items) {
2632 * Link the cell, for the purposes of volume location, to the specified
2635 cellname = as->parms[2].items->data;
2638 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2639 if (as->parms[3].items) {
2640 code = util_GetInt32(as->parms[3].items->data, &vlport);
2642 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2646 if (as->parms[4].items) {
2647 code = util_GetInt32(as->parms[4].items->data, &fsport);
2649 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2654 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
2655 lp = (afs_int32 *)tp;
2659 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2660 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2661 tp = (char *)(space + size);
2663 strcpy(tp, cellname);
2664 size += strlen(cellname) + 1;
2666 blob.in_size = size;
2669 code = pioctl_utf8(0, VIOCNEWCELL, &blob, 1);
2675 struct ViceIoctl blob;
2678 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2683 blob.in = (char *) 0;
2684 blob.out_size = MAXSIZE;
2687 code = pioctl_utf8((char *) 0, VIOCNEWCELL, &blob, 1);
2690 Die(errno, (char *) 0);
2694 printf("Cell servers information refreshed\n");
2701 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2704 struct ViceIoctl blob;
2706 char *aliasName, *realName;
2708 /* Setup and do the NEWALIAS pioctl call */
2709 aliasName = as->parms[0].items->data;
2710 realName = as->parms[1].items->data;
2712 strcpy(tp, aliasName);
2713 tp += strlen(aliasName) + 1;
2714 strcpy(tp, realName);
2715 tp += strlen(realName) + 1;
2717 blob.in_size = tp - space;
2721 code = pioctl_utf8(0, VIOC_NEWALIAS, &blob, 1);
2723 if (errno == EEXIST) {
2725 "%s: cell name `%s' in use by an existing cell.\n", pn,
2737 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2740 struct cmd_item *ti;
2741 struct ViceIoctl blob;
2744 cm_ioctlQueryOptions_t options;
2746 if (as->parms[1].items)
2749 SetDotDefault(&as->parms[0].items);
2750 for(ti=as->parms[0].items; ti; ti=ti->next) {
2752 afs_uint32 filetype;
2753 char cell[CELL_MAXNAMELEN];
2756 memset(&fid, 0, sizeof(fid));
2757 memset(&options, 0, sizeof(options));
2759 options.size = sizeof(options);
2760 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
2761 options.literal = literal;
2762 blob.in_size = options.size; /* no variable length data */
2765 blob.out_size = sizeof(cm_fid_t);
2766 blob.out = (char *) &fid;
2767 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
2768 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
2771 Die(errno, ti->data);
2776 blob.out_size = sizeof(filetype);
2777 blob.out = &filetype;
2779 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
2781 blob.out_size = CELL_MAXNAMELEN;
2784 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
2786 if (errno == ENOENT)
2787 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2789 Die(errno, ti->data);
2793 printf("%s %s lives in cell '%s'\n",
2794 filetypestr(filetype),
2801 WSCellCmd(struct cmd_syndesc *as, void *arock)
2804 struct ViceIoctl blob;
2808 blob.out_size = MAXSIZE;
2811 code = pioctl_utf8(NULL, VIOC_GET_WS_CELL, &blob, 1);
2818 printf("This workstation belongs to cell '%s'\n", space);
2824 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
2826 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2831 #ifndef AFS_NT40_ENV
2833 MonitorCmd(struct cmd_syndesc *as, void *arock)
2836 struct ViceIoctl blob;
2837 struct cmd_item *ti;
2839 struct hostent *thp;
2843 ti = as->parms[0].items;
2847 if (!strcmp(ti->data, "off")) {
2848 hostAddr = 0xffffffff;
2850 thp = hostutil_GetHostByName(ti->data);
2852 if (!strcmp(ti->data, "localhost")) {
2853 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2854 hostAddr = htonl(0x7f000001);
2856 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2860 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2864 hostAddr = 0; /* means don't set host */
2865 setp = 0; /* aren't setting host */
2868 /* now do operation */
2869 blob.in_size = sizeof(afs_int32);
2870 blob.out_size = sizeof(afs_int32);
2871 blob.in = (char *) &hostAddr;
2872 blob.out = (char *) &hostAddr;
2873 code = pioctl_utf8(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2879 printf("%s: new monitor host set.\n", pn);
2881 /* now decode old address */
2882 if (hostAddr == 0xffffffff) {
2883 printf("Cache monitoring is currently disabled.\n");
2885 tp = hostutil_GetNameByINet(hostAddr);
2886 printf("Using host %s for monitor services.\n", tp);
2891 #endif /* AFS_NT40_ENV */
2894 SysNameCmd(struct cmd_syndesc *as, void *arock)
2897 struct ViceIoctl blob;
2898 struct cmd_item *ti;
2899 char *input = space;
2902 ti = as->parms[0].items;
2906 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2911 fprintf (stderr,"Permission denied: requires root access.\n");
2919 blob.out_size = MAXSIZE;
2920 blob.in_size = sizeof(afs_int32);
2921 memcpy(input, &setp, sizeof(afs_int32));
2922 input += sizeof(afs_int32);
2923 for (; ti; ti = ti->next) {
2925 blob.in_size += (long)strlen(ti->data) + 1;
2926 if (blob.in_size > MAXSIZE) {
2927 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2928 setp > 1 ? "s" : "");
2931 strcpy(input, ti->data);
2932 input += strlen(ti->data);
2935 memcpy(space, &setp, sizeof(afs_int32));
2936 code = pioctl_utf8(0, VIOC_AFS_SYSNAME, &blob, 1);
2942 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2947 memcpy(&setp, input, sizeof(afs_int32));
2948 input += sizeof(afs_int32);
2950 fprintf(stderr,"No sysname name value was found\n");
2954 printf("Current sysname%s is", setp > 1 ? " list" : "");
2955 for (; setp > 0; --setp ) {
2956 printf(" \'%s\'", input);
2957 input += strlen(input) + 1;
2963 #ifndef AFS_NT40_ENV
2964 static char *exported_types[] = {"null", "nfs", ""};
2965 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2968 struct ViceIoctl blob;
2969 struct cmd_item *ti;
2970 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
2971 int exportcall, pwsync = 0, smounts = 0;
2975 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2980 fprintf (stderr,"Permission denied: requires root access.\n");
2985 ti = as->parms[0].items;
2986 if (strcmp(ti->data, "nfs") == 0)
2987 type = 0x71; /* NFS */
2990 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2993 ti = as->parms[1].items;
2995 if (strcmp(ti->data, "on") == 0)
2997 else if (strcmp(ti->data, "off") == 0)
3000 fprintf(stderr, "Illegal argument %s\n", ti->data);
3005 if (ti = as->parms[2].items) { /* -noconvert */
3006 if (strcmp(ti->data, "on") == 0)
3008 else if (strcmp(ti->data, "off") == 0)
3011 fprintf(stderr, "Illegal argument %s\n", ti->data);
3015 if (ti = as->parms[3].items) { /* -uidcheck */
3016 if (strcmp(ti->data, "on") == 0)
3018 else if (strcmp(ti->data, "off") == 0)
3021 fprintf(stderr, "Illegal argument %s\n", ti->data);
3025 if (ti = as->parms[4].items) { /* -submounts */
3026 if (strcmp(ti->data, "on") == 0)
3028 else if (strcmp(ti->data, "off") == 0)
3031 fprintf(stderr, "Illegal argument %s\n", ti->data);
3035 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
3038 blob.in = (char *) &exportcall;
3039 blob.in_size = sizeof(afs_int32);
3040 blob.out = (char *) &exportcall;
3041 blob.out_size = sizeof(afs_int32);
3042 code = pioctl_utf8(0, VIOC_EXPORTAFS, &blob, 1);
3044 if (errno == ENODEV) {
3046 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
3053 if (exportcall & 1) {
3054 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
3055 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
3056 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
3057 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
3059 printf("'%s' translator is disabled\n", exported_types[type]);
3068 GetCellCmd(struct cmd_syndesc *as, void *arock)
3071 struct ViceIoctl blob;
3072 struct afsconf_cell info;
3073 struct cmd_item *ti;
3080 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3081 for(ti=as->parms[0].items; ti; ti=ti->next) {
3083 blob.out_size = sizeof(args);
3084 blob.out = (caddr_t) &args;
3085 code = GetCellName(ti->data, &info);
3090 blob.in_size = 1+(long)strlen(info.name);
3091 blob.in = info.name;
3092 code = pioctl_utf8(0, VIOC_GETCELLSTATUS, &blob, 1);
3094 if (errno == ENOENT)
3095 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3097 Die(errno, info.name);
3101 printf("Cell %s status: ", info.name);
3107 printf("no setuid allowed");
3109 printf("setuid allowed");
3111 printf(", using old VLDB");
3117 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3120 struct ViceIoctl blob;
3121 struct afsconf_cell info;
3122 struct cmd_item *ti;
3130 /* Check arguments. */
3131 if (as->parms[1].items && as->parms[2].items) {
3132 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3136 /* figure stuff to set */
3142 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3147 fprintf (stderr,"Permission denied: requires root access.\n");
3152 if (! as->parms[1].items)
3153 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3155 /* set stat for all listed cells */
3156 for(ti=as->parms[0].items; ti; ti=ti->next) {
3158 code = GetCellName(ti->data, &info);
3163 strcpy(args.cname, info.name);
3164 blob.in_size = sizeof(args);
3165 blob.in = (caddr_t) &args;
3167 blob.out = (caddr_t) 0;
3168 code = pioctl_utf8(0, VIOC_SETCELLSTATUS, &blob, 1);
3170 Die(errno, info.name); /* XXX added cell name to Die() call */
3178 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3180 strcpy(infop->name, cellNamep);
3185 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3190 cm_GetConfigDir(confDir, sizeof(confDir));
3192 code = ugen_ClientInit(noAuthFlag, confDir,
3193 info->name, 0, &uclient,
3194 NULL, pn, rxkad_clear,
3195 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3196 0, 0, USER_SERVICE_ID);
3201 static struct ViceIoctl gblob;
3202 static int debug = 0;
3204 * here follow some routines in suport of the setserverprefs and
3205 * getserverprefs commands. They are:
3206 * SetPrefCmd "top-level" routine
3207 * addServer adds a server to the list of servers to be poked into the
3208 * kernel. Will poke the list into the kernel if it threatens
3210 * pokeServers pokes the existing list of servers and ranks into the kernel
3211 * GetPrefCmd reads the Cache Manager's current list of server ranks
3220 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3222 ssp = (cm_SSetPref_t *)space;
3223 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3229 * returns -1 if error message printed,
3231 * errno value if error and no error message printed
3238 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3239 if (code && (errno == EINVAL)) {
3240 struct setspref *ssp;
3241 ssp = (struct setspref *)gblob.in;
3242 if (!(ssp->flags & DBservers)) {
3243 gblob.in = (void *)&(ssp->servers[0]);
3244 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3245 code = pioctl_utf8(0, VIOC_SETSPREFS33, &gblob, 1);
3246 return code ? errno : 0;
3249 "This cache manager does not support VL server preferences.\n");
3253 return code ? errno : 0;
3259 addServer(char *name, unsigned short rank)
3264 struct hostent *thostent;
3268 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3270 #define MAXUSHORT ((unsigned short) ~0)
3275 thostent = hostutil_GetHostByName(name);
3277 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3281 ssp = (cm_SSetPref_t *)(gblob.in);
3283 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3284 code = pokeServers();
3285 ssp->num_servers = 0;
3288 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3289 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3290 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3291 gblob.in_size += sizeof(cm_SPref_t);
3294 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3300 * returns -1 if error message printed,
3302 * errno value if error and no error message printed
3305 addServer(char *name, afs_int32 rank)
3308 struct setspref *ssp;
3310 struct hostent *thostent;
3316 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3318 #define MAXUSHORT ((unsigned short) ~0)
3322 thostent = hostutil_GetHostByName(name);
3324 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3328 ssp = (struct setspref *)(gblob.in);
3330 for (t = 0; thostent->h_addr_list[t]; t++) {
3331 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3332 code = pokeServers();
3335 ssp->num_servers = 0;
3338 sp = (struct spref *)(gblob.in + gblob.in_size);
3339 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3340 sizeof(afs_uint32));
3341 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3342 gblob.in_size += sizeof(struct spref);
3346 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3347 name, sp->rank, sp->server.s_addr);
3355 static BOOL IsWindowsNT (void)
3357 static BOOL fChecked = FALSE;
3358 static BOOL fIsWinNT = FALSE;
3362 OSVERSIONINFO Version;
3366 memset (&Version, 0x00, sizeof(Version));
3367 Version.dwOSVersionInfoSize = sizeof(Version);
3369 if (GetVersionEx (&Version))
3371 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3381 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3385 struct cmd_item *ti;
3390 ssp = (cm_SSetPref_t *)space;
3392 ssp->num_servers = 0;
3393 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3396 gblob.out_size = MAXSIZE;
3399 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3405 ti = as->parms[2].items; /* -file */
3407 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3408 if (!(infd = fopen(ti->data,"r" ))) {
3410 Die(errno,ti->data);
3413 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3414 code = addServer (name, (unsigned short) rank);
3418 ti = as->parms[3].items; /* -stdin */
3420 while ( scanf("%79s%ld", name, &rank) != EOF) {
3421 code = addServer (name, (unsigned short) rank);
3425 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3430 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3432 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3436 code = pokeServers();
3438 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3440 ssp = (cm_SSetPref_t *)space;
3441 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3443 ssp->flags = CM_SPREF_VLONLY;
3444 ssp->num_servers = 0;
3446 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3451 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3453 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3458 if (as->parms[1].items) {
3460 printf("now poking vlservers\n");
3461 code = pokeServers();
3471 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3475 struct cmd_item *ti;
3478 struct setspref *ssp;
3479 int error = 0; /* -1 means error message printed,
3480 * >0 means errno value for unprinted message */
3482 ssp = (struct setspref *)space;
3484 ssp->num_servers = 0;
3485 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3488 gblob.out_size = MAXSIZE;
3492 fprintf(stderr, "Permission denied: requires root access.\n");
3496 ti = as->parms[2].items; /* -file */
3499 fprintf(stderr, "opening file %s\n", ti->data);
3500 if (!(infd = fopen(ti->data, "r"))) {
3504 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3505 code = addServer(name, (unsigned short)rank);
3512 ti = as->parms[3].items; /* -stdin */
3514 while (scanf("%79s%ld", name, &rank) != EOF) {
3515 code = addServer(name, (unsigned short)rank);
3521 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3526 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3530 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3534 code = pokeServers();
3538 printf("now working on vlservers, code=%d\n", code);
3540 ssp = (struct setspref *)space;
3541 ssp->flags = DBservers;
3542 ssp->num_servers = 0;
3543 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3546 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3551 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3555 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3560 if (as->parms[1].items) {
3562 printf("now poking vlservers\n");
3563 code = pokeServers();
3571 return error ? 1 : 0;
3577 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3580 struct cmd_item *ti;
3581 char *name, tbuffer[20];
3586 struct ViceIoctl blob;
3587 struct cm_SPrefRequest *in;
3588 struct cm_SPrefInfo *out;
3592 ti = as->parms[0].items; /* -file */
3594 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3595 if (!(outfd = freopen(ti->data,"w",stdout))) {
3596 Die(errno,ti->data);
3601 ti = as->parms[1].items; /* -numeric */
3603 ti = as->parms[2].items; /* -vlservers */
3604 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3605 /* ti = as->parms[3].items; -cell */
3607 in = (struct cm_SPrefRequest *)space;
3611 blob.in_size=sizeof(struct cm_SPrefRequest);
3612 blob.in = (char *)in;
3614 blob.out_size = MAXSIZE;
3616 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3617 in->flags = vlservers;
3619 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3621 perror("getserverprefs pioctl");
3625 out = (struct cm_SPrefInfo *) blob.out;
3627 for (i=0;i<out->num_servers;i++) {
3629 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3632 addr = ntohl(out->servers[i].host.s_addr);
3633 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3634 (addr>>8) & 0xff, addr & 0xff);
3637 printf ("%-50s %5u\n",name,out->servers[i].rank);
3640 in->offset = out->next_offset;
3642 } while (!code && out->next_offset > 0);
3648 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3651 struct cmd_item *ti;
3652 char *name, tbuffer[20];
3653 afs_int32 rank, addr;
3657 struct ViceIoctl blob;
3658 struct sprefrequest *in;
3659 struct sprefinfo *out;
3662 ti = as->parms[0].items; /* -file */
3665 fprintf(stderr, "opening file %s\n", ti->data);
3666 if (!(outfd = freopen(ti->data, "w", stdout))) {
3672 ti = as->parms[1].items; /* -numeric */
3674 ti = as->parms[2].items; /* -vlservers */
3675 vlservers |= (ti ? DBservers : 0);
3676 /* ti = as->parms[3].items; -cell */
3678 in = (struct sprefrequest *)space;
3682 blob.in_size = sizeof(struct sprefrequest);
3683 blob.in = (char *)in;
3685 blob.out_size = MAXSIZE;
3688 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3689 in->flags = vlservers;
3691 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3693 perror("getserverprefs pioctl");
3697 out = (struct sprefinfo *)blob.out;
3699 for (i = 0; i < out->num_servers; i++) {
3701 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3703 addr = ntohl(out->servers[i].server.s_addr);
3704 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3705 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3708 printf("%-50s %5u\n", name, out->servers[i].rank);
3711 in->offset = out->next_offset;
3712 } while (out->next_offset > 0);
3719 SmbUnicodeCmd(struct cmd_syndesc * asp, void * arock)
3725 struct ViceIoctl blob;
3727 if (asp->parms[0].items) {
3731 } else if (asp->parms[1].items) {
3737 if (inValue != 0 && !IsAdmin()) {
3738 fprintf (stderr, "Permission denied: Requires AFS Client Administrator access.\n");
3742 blob.in_size = sizeof(inValue);
3743 blob.in = (char *) &inValue;
3744 blob.out_size = sizeof(outValue);
3745 blob.out = (char *) &outValue;
3747 code = pioctl_utf8(NULL, VIOC_UNICODECTL, &blob, 1);
3753 if (outValue != 2) {
3754 printf("Unicode support is %s%s.\n",
3755 ((outValue != 0)? "enabled":"disabled"),
3756 ((inValue != 0)? " for new SMB connections":""));
3758 printf("Unicode support is absent in this installation of OpenAFS.\n");
3765 UuidCmd(struct cmd_syndesc *asp, void *arock)
3770 struct ViceIoctl blob;
3771 char * uuidstring = NULL;
3773 if (asp->parms[0].items) {
3776 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3781 fprintf (stderr, "Permission denied: requires root access.\n");
3785 inValue = 1; /* generate new UUID */
3787 inValue = 0; /* just show the current UUID */
3790 blob.in_size = sizeof(inValue);
3791 blob.in = (char *) &inValue;
3792 blob.out_size = sizeof(outValue);
3793 blob.out = (char *) &outValue;
3795 code = pioctl_utf8(NULL, VIOC_UUIDCTL, &blob, 1);
3801 UuidToString((UUID *) &outValue, &uuidstring);
3803 printf("%sUUID: %s",
3804 ((inValue == 1)?"New ":""),
3808 RpcStringFree(&uuidstring);
3814 TraceCmd(struct cmd_syndesc *asp, void *arock)
3817 struct ViceIoctl blob;
3823 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3828 fprintf (stderr,"Permission denied: requires root access.\n");
3833 if ((asp->parms[0].items && asp->parms[1].items)) {
3834 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
3838 /* determine if we're turning this tracing on or off */
3840 if (asp->parms[0].items)
3841 inValue = 3; /* enable */
3842 else if (asp->parms[1].items)
3843 inValue = 2; /* disable */
3844 if (asp->parms[2].items)
3845 inValue |= 4; /* do reset */
3846 if (asp->parms[3].items)
3847 inValue |= 8; /* dump */
3849 blob.in_size = sizeof(long);
3850 blob.in = (char *) &inValue;
3851 blob.out_size = sizeof(long);
3852 blob.out = (char *) &outValue;
3854 code = pioctl_utf8(NULL, VIOC_TRACECTL, &blob, 1);
3861 printf("AFS tracing enabled.\n");
3863 printf("AFS tracing disabled.\n");
3868 static void sbusage(void)
3870 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
3871 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
3874 /* fs sb -kbytes 9999 -files *.o -default 64 */
3876 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
3879 struct ViceIoctl blob;
3880 struct cmd_item *ti;
3881 struct sbstruct tsb, tsb2;
3889 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3894 tsb.sb_thisfile = -1;
3895 ti = as->parms[0].items; /* -kbytes */
3897 if (!as->parms[1].items) {
3898 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
3902 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
3903 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
3904 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3910 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
3911 ti = as->parms[2].items; /* -allfiles */
3913 allfiles = strtol(ti->data, &t, 10) * 1024;
3914 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
3915 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
3921 /* -verbose or -file only or no options */
3922 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
3923 || (!as->parms[0].items && !as->parms[1].items
3924 && !as->parms[2].items))
3927 blob.in = (char *)&tsb;
3928 blob.out = (char *)&tsb2;
3929 blob.in_size = blob.out_size = sizeof(struct sbstruct);
3930 memset(&tsb2, 0, sizeof(tsb2));
3932 /* once per -file */
3933 for (ti = as->parms[1].items; ti; ti = ti->next) {
3934 /* Do this solely to see if the file is there */
3935 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
3937 Die(errno, ti->data);
3942 code = pioctl_utf8(ti->data, VIOC_STOREBEHIND, &blob, 1);
3944 Die(errno, ti->data);
3949 if (verbose && (blob.out_size == sizeof(tsb2))) {
3950 if (tsb2.sb_thisfile == -1) {
3951 fprintf(stdout, "Will store %s according to default.\n",
3955 "Will store up to %d kbytes of %s asynchronously.\n",
3956 (tsb2.sb_thisfile / 1024), ti->data);
3961 /* If no files - make at least one pioctl call, or
3962 * set the allfiles default if we need to.
3964 if (!as->parms[1].items || (allfiles != -1)) {
3965 tsb.sb_default = allfiles;
3966 code = pioctl_utf8(0, VIOC_STOREBEHIND, &blob, 1);
3968 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
3973 /* Having no arguments also reports the default store asynchrony */
3974 if (verbose && (blob.out_size == sizeof(tsb2))) {
3975 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
3976 (tsb2.sb_default / 1024));
3983 SetCryptCmd(struct cmd_syndesc *as, void *arock)
3985 afs_int32 code = 0, flag;
3986 struct ViceIoctl blob;
3991 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3996 tp = as->parms[0].items->data;
3997 if (strcmp(tp, "on") == 0)
3999 else if (strcmp(tp, "off") == 0)
4001 else if (strcmp(tp, "auth") == 0)
4004 fprintf (stderr, "%s: %s must be \"on\", \"auth\", or \"off\".\n", pn, tp);
4008 blob.in = (char *) &flag;
4009 blob.in_size = sizeof(flag);
4011 code = pioctl_utf8(0, VIOC_SETRXKCRYPT, &blob, 1);
4018 GetCryptCmd(struct cmd_syndesc *as, void *arock)
4020 afs_int32 code = 0, flag;
4021 struct ViceIoctl blob;
4026 blob.out_size = sizeof(flag);
4029 code = pioctl_utf8(0, VIOC_GETRXKCRYPT, &blob, 1);
4035 memcpy(&flag, tp, sizeof(afs_int32));
4036 printf("Security level is currently ");
4038 printf("auth (data integrity).\n");
4040 printf("crypt (data security).\n");
4048 MemDumpCmd(struct cmd_syndesc *asp, void *arock)
4051 struct ViceIoctl blob;
4056 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4060 if ((asp->parms[0].items && asp->parms[1].items)) {
4061 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
4065 /* determine if we're turning this tracing on or off */
4066 if (asp->parms[0].items)
4067 inValue = 1; /* begin */
4068 else if (asp->parms[1].items)
4069 inValue = 0; /* end */
4072 blob.in_size = sizeof(long);
4073 blob.in = (char *) &inValue;
4074 blob.out_size = sizeof(long);
4075 blob.out = (char *) &outValue;
4077 code = pioctl_utf8(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
4084 printf("AFS memdump created.\n");
4087 printf("AFS memdump failed.\n");
4093 MiniDumpCmd(struct cmd_syndesc *asp, void *arock)
4096 SERVICE_STATUS status;
4097 SC_HANDLE hManager = NULL;
4098 SC_HANDLE hService = NULL;
4101 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4105 hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
4109 hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
4113 success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
4116 CloseServiceHandle(hService);
4117 CloseServiceHandle(hManager);
4119 printf("AFS minidump generated.\n");
4125 CloseServiceHandle(hService);
4127 CloseServiceHandle(hManager);
4129 printf("AFS minidump failed.\n");
4134 CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
4136 struct cmd_item *ti;
4141 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4145 for(ti=asp->parms[0].items; ti;ti=ti->next) {
4157 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4158 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4161 REG_OPTION_NON_VOLATILE,
4162 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
4167 if ( hkCSCPolicy == NULL ) {
4168 fprintf (stderr,"Permission denied: requires Administrator access.\n");
4173 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4174 RegCloseKey(hkCSCPolicy);
4180 if (asp->parms[1].items)
4182 if (asp->parms[2].items)
4183 policy = "programs";
4184 if (asp->parms[3].items)
4185 policy = "documents";
4186 if (asp->parms[4].items)
4189 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, (DWORD)strlen(policy)+1);
4191 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
4192 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
4196 DWORD dwIndex, dwPolicies;
4197 char policyName[256];
4198 DWORD policyNameLen;
4203 /* list current csc policies */
4205 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4206 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4209 REG_OPTION_NON_VOLATILE,
4210 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_QUERY_VALUE,
4215 RegQueryInfoKey( hkCSCPolicy,
4217 NULL, /* lpcClass */
4218 NULL, /* lpReserved */
4219 NULL, /* lpcSubKeys */
4220 NULL, /* lpcMaxSubKeyLen */
4221 NULL, /* lpcMaxClassLen */
4222 &dwPolicies, /* lpcValues */
4223 NULL, /* lpcMaxValueNameLen */
4224 NULL, /* lpcMaxValueLen */
4225 NULL, /* lpcbSecurityDescriptor */
4226 NULL /* lpftLastWriteTime */
4229 printf("Current CSC policies:\n");
4230 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
4232 policyNameLen = sizeof(policyName);
4233 policyLen = sizeof(policy);
4234 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
4235 &dwType, policy, &policyLen);
4237 printf(" %s = %s\n", policyName, policy);
4241 RegCloseKey(hkCSCPolicy);
4246 /* get clients interface addresses */
4248 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4251 struct cmd_item *ti;
4253 struct ViceIoctl blob;
4254 struct sprefrequest *in;
4255 struct sprefinfo *out;
4257 in = (struct sprefrequest *)space;
4261 blob.in_size = sizeof(struct sprefrequest);
4262 blob.in = (char *)in;
4264 blob.out_size = MAXSIZE;
4267 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4268 /* returns addr in network byte order */
4269 code = pioctl_utf8(0, VIOC_GETCPREFS, &blob, 1);
4271 perror("getClientInterfaceAddr pioctl");
4277 out = (struct sprefinfo *)blob.out;
4278 for (i = 0; i < out->num_servers; i++) {
4281 addr = ntohl(out->servers[i].server.s_addr);
4282 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
4283 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
4284 printf("%-50s\n", tbuffer);
4286 in->offset = out->next_offset;
4288 } while (out->next_offset > 0);
4294 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4296 afs_int32 code, addr;
4297 struct cmd_item *ti;
4299 struct ViceIoctl blob;
4300 struct setspref *ssp;
4301 int sizeUsed = 0, i, flag;
4302 afs_int32 existingAddr[1024]; /* existing addresses on this host */
4306 ssp = (struct setspref *)space;
4307 ssp->num_servers = 0;
4310 blob.out_size = MAXSIZE;
4313 fprintf(stderr, "Permission denied: requires root access.\n");
4317 /* extract all existing interface addresses */
4318 existNu = rx_getAllAddr(existingAddr, 1024);
4322 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4323 for (ti = as->parms[0].items; ti; ti = ti->next) {
4324 if (sizeUsed >= sizeof(space)) {
4325 fprintf(stderr, "No more space\n");
4328 addr = extractAddr(ti->data, 20); /* network order */
4329 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4330 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4335 /* see if it is an address that really exists */
4336 for (flag = 0, i = 0; i < existNu; i++)
4337 if (existingAddr[i] == addr) {
4341 if (!flag) { /* this is an nonexistent address */
4342 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4346 /* copy all specified addr into ioctl buffer */
4347 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4348 printf("Adding 0x%08x\n", addr);
4350 sizeUsed += sizeof(struct spref);
4352 if (ssp->num_servers < 1) {
4353 fprintf(stderr, "No addresses specified\n");
4356 blob.in_size = sizeUsed - sizeof(struct spref);
4358 code = pioctl_utf8(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4368 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4371 struct ViceIoctl blob;
4372 struct cmd_item *ti;
4373 char orig_name[1024]; /*Original name, may be modified */
4374 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4375 char parent_dir[1024]; /*Parent directory of true name */
4376 char *last_component; /*Last component of true name */
4377 struct stat statbuff; /*Buffer for status info */
4378 int link_chars_read; /*Num chars read in readlink() */
4379 int thru_symlink; /*Did we get to a mount point via a symlink? */
4382 for (ti = as->parms[0].items; ti; ti = ti->next) {
4385 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4388 if (lstat(orig_name, &statbuff) < 0) {
4389 /* if lstat fails, we should still try the pioctl, since it
4390 * may work (for example, lstat will fail, but pioctl will
4391 * work if the volume of offline (returning ENODEV). */
4392 statbuff.st_mode = S_IFDIR; /* lie like pros */
4396 * The lstat succeeded. If the given file is a symlink, substitute
4397 * the file name with the link name.
4399 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4402 * Read name of resolved file.
4404 link_chars_read = readlink(orig_name, true_name, 1024);
4405 if (link_chars_read <= 0) {
4407 "%s: Can't read target name for '%s' symbolic link!\n",
4414 * Add a trailing null to what was read, bump the length.
4416 true_name[link_chars_read++] = 0;
4419 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4420 * have to create a full pathname using the original name and the
4421 * relative symlink name. Find the rightmost slash in the original
4422 * name (we know there is one) and splice in the symlink value.
4424 if (true_name[0] != '/') {
4425 last_component = (char *)strrchr(orig_name, '/');
4426 strcpy(++last_component, true_name);
4427 strcpy(true_name, orig_name);
4430 strcpy(true_name, orig_name);
4433 * Find rightmost slash, if any.
4435 last_component = (char *)strrchr(true_name, '/');
4436 if (last_component) {
4438 * Found it. Designate everything before it as the parent directory,
4439 * everything after it as the final component.
4441 strncpy(parent_dir, true_name, last_component - true_name);
4442 parent_dir[last_component - true_name] = 0;
4443 last_component++; /*Skip the slash */
4446 * No slash appears in the given file name. Set parent_dir to the current
4447 * directory, and the last component as the given name.
4449 strcpy(parent_dir, ".");
4450 last_component = true_name;
4453 if (strcmp(last_component, ".") == 0
4454 || strcmp(last_component, "..") == 0) {
4456 "%s: you may not use '.' or '..' as the last component\n",
4458 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4464 blob.in = last_component;
4465 blob.in_size = strlen(last_component) + 1;
4467 memset(space, 0, MAXSIZE);
4469 code = pioctl_utf8(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4472 if (errno == EINVAL) {
4473 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4475 Die(errno, (ti->data ? ti->data : parent_dir));
4485 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4488 afs_int32 flags = 0;
4489 struct ViceIoctl blob;
4491 if (as->parms[0].items) { /* -enable */
4492 flags |= AFSCALL_RXSTATS_ENABLE;
4494 if (as->parms[1].items) { /* -disable */
4495 flags |= AFSCALL_RXSTATS_DISABLE;
4497 if (as->parms[2].items) { /* -clear */
4498 flags |= AFSCALL_RXSTATS_CLEAR;
4501 fprintf(stderr, "You must specify at least one argument\n");
4505 blob.in = (char *)&flags;
4506 blob.in_size = sizeof(afs_int32);
4509 code = pioctl_utf8(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4519 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4522 afs_int32 flags = 0;
4523 struct ViceIoctl blob;
4525 if (as->parms[0].items) { /* -enable */
4526 flags |= AFSCALL_RXSTATS_ENABLE;
4528 if (as->parms[1].items) { /* -disable */
4529 flags |= AFSCALL_RXSTATS_DISABLE;
4531 if (as->parms[2].items) { /* -clear */
4532 flags |= AFSCALL_RXSTATS_CLEAR;
4535 fprintf(stderr, "You must specify at least one argument\n");
4539 blob.in = (char *)&flags;
4540 blob.in_size = sizeof(afs_int32);
4543 code = pioctl_utf8(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4553 TestVolStatCmd(struct cmd_syndesc *as, void *arock)
4556 struct VolStatTest test;
4557 struct ViceIoctl blob;
4561 memset(&test, 0, sizeof(test));
4563 if (as->parms[0].items) { /* -network */
4564 tp = as->parms[0].items->data;
4565 if (strcmp(tp, "up") == 0)
4566 test.flags |= VOLSTAT_TEST_NETWORK_UP;
4567 else if (strcmp(tp, "down") == 0)
4568 test.flags |= VOLSTAT_TEST_NETWORK_DOWN;
4570 fprintf (stderr, "%s: %s must be \"up\" or \"down\".\n", pn, tp);
4574 if (as->parms[1].items) { /* check */
4575 test.flags |= VOLSTAT_TEST_CHECK_VOLUME;
4577 if (as->parms[2].items) { /* cell */
4578 tp = as->parms[2].items->data;
4583 strncpy(test.cellname, tp, sizeof(test.cellname));
4584 test.cellname[sizeof(test.cellname)-1] = '\0';
4587 if (as->parms[3].items) { /* volume */
4588 tp = as->parms[3].items->data;
4591 test.fid.volume = n;
4593 strncpy(test.volname, tp, sizeof(test.volname));
4594 test.volname[sizeof(test.volname)-1] = '\0';
4597 if (as->parms[4].items) { /* state */
4598 tp = as->parms[4].items->data;
4599 if (strcmp(tp, "online") == 0)
4600 test.state = vl_online;
4601 else if (strcmp(tp, "busy") == 0)
4602 test.state = vl_busy;
4603 else if (strcmp(tp, "offline") == 0)
4604 test.state = vl_offline;
4605 else if (strcmp(tp, "down") == 0)
4606 test.state = vl_alldown;
4608 fprintf (stderr, "%s: %s must be \"online\", \"busy\", \"offline\" or \"down\".\n", pn, tp);
4613 if ((test.fid.cell || test.cellname[0]) && !(test.fid.volume || test.volname[0]) ||
4614 !(test.fid.cell || test.cellname[0]) && (test.fid.volume || test.volname[0])) {
4615 fprintf (stderr, "%s: both a cell and a volume must be specified.\n", pn, tp);
4619 blob.in = (char *)&test;
4620 blob.in_size = sizeof(test);
4623 code = pioctl_utf8(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
4633 #include "AFS_component_version_number.c"
4637 FreeUtf8CmdLine(int argc, char ** argv)
4640 for (i=0; i < argc; i++) {
4648 MakeUtf8Cmdline(int argc, const wchar_t **wargv)
4653 argv = calloc(argc, sizeof(argv[0]));
4657 for (i=0; i < argc; i++) {
4660 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, FALSE);
4662 (argv[i] = calloc(s+1, sizeof(char))) == NULL) {
4666 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], s+1, NULL, FALSE);
4673 FreeUtf8CmdLine(argc, argv);
4680 int wmain(int argc, wchar_t **wargv)
4683 struct cmd_syndesc *ts;
4686 #ifdef AFS_AIX32_ENV
4688 * The following signal action for AIX is necessary so that in case of a
4689 * crash (i.e. core is generated) we can include the user's data section
4690 * in the core dump. Unfortunately, by default, only a partial core is
4691 * generated which, in many cases, isn't too useful.
4693 struct sigaction nsa;
4695 sigemptyset(&nsa.sa_mask);
4696 nsa.sa_handler = SIG_DFL;
4697 nsa.sa_flags = SA_FULLDUMP;
4698 sigaction(SIGSEGV, &nsa, NULL);
4703 WSAStartup(0x0101, &WSAjunk);
4706 argv = MakeUtf8Cmdline(argc, wargv);
4708 /* try to find volume location information */
4712 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
4713 "get client network interface addresses");
4714 cmd_CreateAlias(ts, "gc");
4716 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
4717 "set client network interface addresses");
4718 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
4719 "client network interfaces");
4720 cmd_CreateAlias(ts, "sc");
4723 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL, "set server ranks");
4724 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
4725 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
4726 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
4727 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
4728 cmd_CreateAlias(ts, "sp");
4730 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL, "get server ranks");
4731 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
4732 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4733 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
4734 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
4735 cmd_CreateAlias(ts, "gp");
4737 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
4738 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4739 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
4740 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
4741 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
4742 parm_setacl_id = ts->nParms;
4743 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
4744 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
4745 cmd_CreateAlias(ts, "sa");
4747 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL, "list access control list");
4748 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4749 parm_listacl_id = ts->nParms;
4750 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4751 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4752 cmd_CreateAlias(ts, "la");
4754 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL, "clean up access control list");
4755 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4757 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL, "copy access control list");
4758 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
4759 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
4760 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
4761 parm_copyacl_id = ts->nParms;
4762 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
4763 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
4765 cmd_CreateAlias(ts, "ca");
4767 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
4768 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4769 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4772 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
4773 "flush mount symlink from cache");
4774 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4777 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
4778 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4779 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
4781 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
4783 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
4784 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
4785 cmd_CreateAlias(ts, "sv");
4787 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL, "control Cache Manager messages");
4788 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
4790 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
4791 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4792 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4793 cmd_CreateAlias(ts, "lv");
4794 cmd_CreateAlias(ts, "listvol");
4796 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
4797 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4798 cmd_CreateAlias(ts, "lq");
4800 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL, "show server disk space usage");
4801 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4802 cmd_CreateAlias(ts, "df");
4804 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
4805 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4807 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
4808 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4810 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
4811 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
4812 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
4813 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
4814 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
4815 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
4821 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
4825 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
4826 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
4828 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL, "check local cell's servers");
4829 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
4830 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
4831 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
4832 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
4834 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL, "check volumeID/name mappings");
4835 cmd_CreateAlias(ts, "checkbackups");
4838 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL, "set cache size");
4839 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
4840 cmd_CreateAlias(ts, "cachesize");
4842 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
4844 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL, "get cache usage info");
4846 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL, "list configured cells");
4847 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
4849 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
4850 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
4851 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
4853 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
4855 cmd_CreateAlias(ts, "sq");
4857 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
4859 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
4860 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
4861 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
4863 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
4865 * Turn this on only if you wish to be able to talk to a server which is listening
4866 * on alternative ports. This is not intended for general use and may not be
4867 * supported in the cache manager. It is not a way to run two servers at the
4868 * same host, since the cache manager cannot properly distinguish those two hosts.
4870 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
4871 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
4874 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
4875 "configure new cell alias");
4876 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
4877 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
4880 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
4881 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4882 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4884 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
4885 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4886 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
4888 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
4891 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
4894 #ifndef AFS_NT40_ENV
4895 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, "set cache monitor host address");
4896 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
4897 cmd_CreateAlias(ts, "mariner");
4900 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
4901 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4903 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
4904 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
4905 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
4906 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
4908 ts = cmd_CreateSyntax("flushall", FlushAllCmd, NULL, "flush all data");
4910 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL, "flush all data in volume");
4911 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
4913 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL, "get/set sysname (i.e. @sys) value");
4914 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
4916 #ifndef AFS_NT40_ENV
4917 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL, "enable/disable translators to AFS");
4918 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
4919 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
4920 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
4921 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
4922 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
4925 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
4926 "store to server after file close");
4927 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
4928 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
4929 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
4930 cmd_CreateAlias(ts, "sb");
4932 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL, "set cache manager encryption flag");
4933 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
4935 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL, "get cache manager encryption flag");
4937 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
4938 "Manage per process RX statistics");
4939 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4940 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4941 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4943 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
4944 "Manage per peer RX statistics");
4945 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
4946 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
4947 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
4950 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
4951 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
4954 ts = cmd_CreateSyntax("trace", TraceCmd, NULL, "enable or disable CM tracing");
4955 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
4956 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
4957 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
4958 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
4959 cmd_CreateAlias(ts, "tr");
4961 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
4962 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
4964 ts = cmd_CreateSyntax("memdump", MemDumpCmd, NULL, "dump memory allocs in debug builds");
4965 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
4966 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
4968 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, NULL, "change client side caching policy for AFS shares");
4969 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
4970 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
4971 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
4972 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
4973 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
4975 ts = cmd_CreateSyntax("minidump", MiniDumpCmd, NULL, "Generate MiniDump of current service state");
4977 ts = cmd_CreateSyntax("test_volstat", TestVolStatCmd, NULL, (char *)CMD_HIDDEN);
4978 cmd_AddParm(ts, "-network", CMD_SINGLE, CMD_OPTIONAL, "set network state up or down");
4979 cmd_AddParm(ts, "-check", CMD_FLAG, CMD_OPTIONAL, "check state of offline volumes");
4980 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name or number");
4981 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or number");
4982 cmd_AddParm(ts, "-state", CMD_SINGLE, CMD_OPTIONAL, "new volume state: online, busy, offline, down");
4984 ts = cmd_CreateSyntax("smbunicode", SmbUnicodeCmd, NULL, "enable or disable Unicode on new SMB connections");
4985 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable Unicode on new connections");
4986 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable Unicode on new connections");
4988 code = cmd_Dispatch(argc, argv);
4993 FreeUtf8CmdLine(argc, argv);
4999 Die(int code, char *filename)
5002 if (code == EINVAL) {
5004 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
5006 fprintf(stderr,"%s: Invalid argument.\n", pn);
5008 else if (code == ENOENT) {
5010 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
5012 fprintf(stderr,"%s: no such file returned\n", pn);
5014 else if (code == EROFS)
5015 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
5016 else if (code == EACCES || code == EPERM) {
5018 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
5020 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
5022 else if (code == ENODEV) {
5023 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
5025 else if (code == ESRCH) { /* hack */
5026 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
5028 else if (code == EPIPE) { /* hack */
5029 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
5031 else if (code == EFBIG) {
5032 fprintf(stderr,"%s: Cache size too large.\n", pn);
5034 else if (code == ETIMEDOUT) {
5036 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
5038 fprintf(stderr,"%s: Connection timed out", pn);
5040 else if (code == EBUSY) {
5042 fprintf(stderr,"%s: All servers are busy on which '%s' resides\n", pn, filename);
5044 fprintf(stderr,"%s: All servers are busy\n", pn);
5046 else if (code == ENXIO) {
5048 fprintf(stderr,"%s: All volume instances are offline on which '%s' resides\n", pn, filename);
5050 fprintf(stderr,"%s: All volume instances are offline\n", pn);
5052 else if (code == ENOSYS) {
5054 fprintf(stderr,"%s: All servers are down on which '%s' resides\n", pn, filename);
5056 fprintf(stderr,"%s: All servers are down\n", pn);
5060 fprintf(stderr,"%s:'%s'", pn, filename);
5062 fprintf(stderr,"%s", pn);
5064 fprintf(stderr, ": code 0x%x\n", code);
5065 #else /* not WIN32 */
5066 fprintf(stderr,": %s\n", afs_error_message(code));
5067 #endif /* not WIN32 */