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>
12 #include <afs/com_err.h>
23 #include <rx/rx_globals.h>
27 #include <afs/afs_consts.h>
28 #include <afs/cellconfig.h>
29 #include <afs/ptserver.h>
30 #include <afs/ptuser.h>
31 #include <afs/volser.h>
32 #include <WINNT\afsreg.h>
41 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
42 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
43 #define CELL_MAXNAMELEN 256
44 #define MAXHOSTCHARS 64
46 static char space[AFS_PIOCTL_MAXSIZE];
47 static char tspace[1024];
49 static struct ubik_client *uclient;
51 static int GetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
52 static int SetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
53 static int FlushMountCmd(struct cmd_syndesc *asp, void *arock);
54 static int RxStatProcCmd(struct cmd_syndesc *asp, void *arock);
55 static int RxStatPeerCmd(struct cmd_syndesc *asp, void *arock);
57 extern struct cmd_syndesc *cmd_CreateSyntax();
59 static int MemDumpCmd(struct cmd_syndesc *asp, void *arock);
60 static int CSCPolicyCmd(struct cmd_syndesc *asp, void *arock);
61 static int MiniDumpCmd(struct cmd_syndesc *asp, void *arock);
63 static char pn[] = "fs";
64 static int rxInitDone = 0;
67 * Character to use between name and rights in printed representation for
70 #define DFS_SEPARATOR ' '
72 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
75 int dfs; /* Originally true if a dfs acl; now also the type
76 * of the acl (1, 2, or 3, corresponding to object,
77 * initial dir, or initial object). */
78 sec_rgy_name_t cell; /* DFS cell name */
81 struct AclEntry *pluslist;
82 struct AclEntry *minuslist;
86 struct AclEntry *next;
92 ZapAcl (struct Acl *acl)
97 ZapList(acl->pluslist);
98 ZapList(acl->minuslist);
103 * Mods for the AFS/DFS protocol translator.
105 * DFS rights. It's ugly to put these definitions here, but they
106 * *cannot* change, because they're part of the wire protocol.
107 * In any event, the protocol translator will guarantee these
108 * assignments for AFS cache managers.
110 #define DFS_READ 0x01
111 #define DFS_WRITE 0x02
112 #define DFS_EXECUTE 0x04
113 #define DFS_CONTROL 0x08
114 #define DFS_INSERT 0x10
115 #define DFS_DELETE 0x20
117 /* the application definable ones (backwards from AFS) */
118 #define DFS_USR0 0x80000000 /* "A" bit */
119 #define DFS_USR1 0x40000000 /* "B" bit */
120 #define DFS_USR2 0x20000000 /* "C" bit */
121 #define DFS_USR3 0x10000000 /* "D" bit */
122 #define DFS_USR4 0x08000000 /* "E" bit */
123 #define DFS_USR5 0x04000000 /* "F" bit */
124 #define DFS_USR6 0x02000000 /* "G" bit */
125 #define DFS_USR7 0x01000000 /* "H" bit */
126 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
127 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
130 * Offset of -id switch in command structure for various commands.
131 * The -if switch is the next switch always.
133 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
136 * Determine whether either the -id or -if switches are present, and
137 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
139 /* int id; Offset of -id switch; -if is next switch */
141 getidf(struct cmd_syndesc *as, int id)
145 if (as->parms[id].items) {
148 if (as->parms[id + 1].items) {
153 "%s: you may specify either -id or -if, but not both switches\n",
161 PRights(afs_int32 arights, int dfs)
164 if (arights & PRSFS_READ)
166 if (arights & PRSFS_LOOKUP)
168 if (arights & PRSFS_INSERT)
170 if (arights & PRSFS_DELETE)
172 if (arights & PRSFS_WRITE)
174 if (arights & PRSFS_LOCK)
176 if (arights & PRSFS_ADMINISTER)
178 if (arights & PRSFS_USR0)
180 if (arights & PRSFS_USR1)
182 if (arights & PRSFS_USR2)
184 if (arights & PRSFS_USR3)
186 if (arights & PRSFS_USR4)
188 if (arights & PRSFS_USR5)
190 if (arights & PRSFS_USR6)
192 if (arights & PRSFS_USR7)
195 if (arights & DFS_READ)
199 if (arights & DFS_WRITE)
203 if (arights & DFS_EXECUTE)
207 if (arights & DFS_CONTROL)
211 if (arights & DFS_INSERT)
215 if (arights & DFS_DELETE)
219 if (arights & (DFS_USRALL))
221 if (arights & DFS_USR0)
223 if (arights & DFS_USR1)
225 if (arights & DFS_USR2)
227 if (arights & DFS_USR3)
229 if (arights & DFS_USR4)
231 if (arights & DFS_USR5)
233 if (arights & DFS_USR6)
235 if (arights & DFS_USR7)
241 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
245 struct ViceIoctl blob;
246 cm_ioctlQueryOptions_t options;
250 memset(&options, 0, sizeof(options));
251 options.size = sizeof(options);
252 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
254 blob.in_size = options.size; /* no variable length data */
256 blob.out_size = sizeof(cm_fid_t);
257 blob.out = (char *) &fid;
259 code = pioctl_utf8(apath, VIOCGETFID, &blob, 1);
261 if ((errno == EINVAL) || (errno == ENOENT))
268 IsFreelanceRoot(char *apath)
270 struct ViceIoctl blob;
274 blob.out_size = AFS_PIOCTL_MAXSIZE;
277 code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
279 return !cm_strnicmp_utf8N("Freelance.Local.Root",space, blob.out_size);
281 return 1; /* assume it is because it is more restrictive that way */
284 /* return a static pointer to a buffer */
289 strcpy(tspace, apath);
290 tp = strrchr(tspace, '\\');
292 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
295 fs_ExtractDriveLetter(apath, tspace);
301 enum rtype {add, destroy, deny};
304 Convert(char *arights, int dfs, enum rtype *rtypep)
310 *rtypep = add; /* add rights, by default */
313 if (!strcmp(arights, "null")) {
317 if (!strcmp(arights,"read"))
318 return DFS_READ | DFS_EXECUTE;
319 if (!strcmp(arights, "write"))
320 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
322 if (!strcmp(arights, "all"))
323 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
324 DFS_WRITE | DFS_CONTROL;
326 if (!strcmp(arights,"read"))
327 return PRSFS_READ | PRSFS_LOOKUP;
328 if (!strcmp(arights, "write"))
329 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
330 PRSFS_WRITE | PRSFS_LOCK;
331 if (!strcmp(arights, "mail"))
332 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
333 if (!strcmp(arights, "all"))
334 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
335 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
337 if (!strcmp(arights, "none")) {
338 *rtypep = destroy; /* Remove entire entry */
341 len = (int)strlen(arights);
377 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
385 mode |= PRSFS_LOOKUP;
387 mode |= PRSFS_INSERT;
389 mode |= PRSFS_DELETE;
395 mode |= PRSFS_ADMINISTER;
413 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
422 static struct AclEntry *
423 FindList (struct AclEntry *alist, char *aname)
426 if (!strcasecmp(alist->name, aname))
433 /* if no parm specified in a particular slot, set parm to be "." instead */
435 SetDotDefault(struct cmd_item **aitemp)
439 return; /* already has value */
440 /* otherwise, allocate an item representing "." */
441 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
443 ti->next = (struct cmd_item *) 0;
444 ti->data = (char *) malloc(2);
446 strcpy(ti->data, ".");
451 ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
453 struct AclEntry *tlist;
454 tlist = (plus ? al->pluslist : al->minuslist);
455 tlist = FindList (tlist, aname);
457 /* Found the item already in the list. */
458 tlist->rights = arights;
460 al->nplus -= PruneList(&al->pluslist, al->dfs);
462 al->nminus -= PruneList(&al->minuslist, al->dfs);
465 /* Otherwise we make a new item and plug in the new data. */
466 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
468 strcpy(tlist->name, aname);
469 tlist->rights = arights;
471 tlist->next = al->pluslist;
472 al->pluslist = tlist;
474 if (arights == 0 || arights == -1)
475 al->nplus -= PruneList(&al->pluslist, al->dfs);
477 tlist->next = al->minuslist;
478 al->minuslist = tlist;
481 al->nminus -= PruneList(&al->minuslist, al->dfs);
486 ZapList (struct AclEntry *alist)
488 struct AclEntry *tp, *np;
489 for (tp = alist; tp; tp = np) {
496 PruneList (struct AclEntry **ae, int dfs)
498 struct AclEntry **lp;
499 struct AclEntry *te, *ne;
503 for(te = *ae;te;te=ne) {
504 if ((!dfs && te->rights == 0) || te->rights == -1) {
518 SkipLine (char *astr)
527 * Create an empty acl, taking into account whether the acl pointed
528 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
529 * can recover from problems caused by bogus ACL's (in that case, always
530 * assume that the acl is AFS: for DFS, the user can always resort to
531 * acl_edit, but for AFS there may be no other way out).
539 tp = (struct Acl *)malloc(sizeof (struct Acl));
541 tp->nplus = tp->nminus = 0;
542 tp->pluslist = tp->minuslist = 0;
544 if (astr == NULL || sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell) <= 0) {
552 ParseAcl (char *astr)
554 int nplus, nminus, i, trights, ret;
556 struct AclEntry *first, *next, *last, *tl;
560 if (astr == NULL || strlen(astr) == 0)
563 ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
568 astr = SkipLine(astr);
569 ret = sscanf(astr, "%d", &ta->nminus);
574 astr = SkipLine(astr);
581 for(i=0;i<nplus;i++) {
582 ret = sscanf(astr, "%100s %d", tname, &trights);
585 astr = SkipLine(astr);
586 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
591 strcpy(tl->name, tname);
592 tl->rights = trights;
598 ta->pluslist = first;
602 for(i=0;i<nminus;i++) {
603 ret = sscanf(astr, "%100s %d", tname, &trights);
606 astr = SkipLine(astr);
607 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
612 strcpy(tl->name, tname);
613 tl->rights = trights;
619 ta->minuslist = first;
624 for (;first; first = next) {
628 first = ta->pluslist;
631 for (;first; first = next) {
640 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
642 printf("Volume status for vid = %u named %s is\n",status->Vid, name);
644 printf("Current offline message is %s\n",offmsg);
646 printf("Current message of the day is %s\n",motd);
647 printf("Current disk quota is ");
648 if (status->MaxQuota != 0)
649 printf("%d\n", status->MaxQuota);
651 printf("unlimited\n");
652 printf("Current blocks used are %d\n",status->BlocksInUse);
653 printf("The partition has %d blocks available out of %d\n",
654 status->PartBlocksAvail, status->PartMaxBlocks);
659 QuickPrintStatus(VolumeStatus *status, char *name)
661 double QuotaUsed =0.0;
662 double PartUsed =0.0;
664 printf("%-25.25s",name);
666 if (status->MaxQuota != 0) {
667 printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
668 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
670 printf(" no limit %10d", status->BlocksInUse);
672 if (QuotaUsed > 90.0){
673 printf(" %5.0f%%<<", QuotaUsed);
676 printf(" %5.0f%% ", QuotaUsed);
677 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
678 if (PartUsed > 97.0){
679 printf(" %9.0f%%<<", PartUsed);
682 printf(" %9.0f%% ", PartUsed);
684 printf(" <<WARNING\n");
691 QuickPrintSpace(VolumeStatus *status, char *name)
693 double PartUsed =0.0;
695 printf("%-25.25s",name);
697 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
699 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
700 if (PartUsed > 90.0){
701 printf(" %4.0f%%<<", PartUsed);
704 printf(" %4.0f%% ", PartUsed);
706 printf(" <<WARNING\n");
713 AclToString(struct Acl *acl)
715 static char mydata[AFS_PIOCTL_MAXSIZE];
716 char tstring[AFS_PIOCTL_MAXSIZE];
721 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
724 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
725 for (tp = acl->pluslist;tp;tp=tp->next) {
726 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
727 strcat(mydata, tstring);
729 for (tp = acl->minuslist;tp;tp=tp->next) {
730 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
731 strcat(mydata, tstring);
736 static DWORD IsFreelance(void)
743 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
744 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
745 if (code == ERROR_SUCCESS) {
746 dummyLen = sizeof(cm_freelanceEnabled);
747 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
748 (BYTE *) &enabled, &dummyLen);
749 RegCloseKey (parmKey);
754 static const char * NetbiosName(void)
756 static char buffer[1024] = "AFS";
762 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
763 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
764 if (code == ERROR_SUCCESS) {
765 dummyLen = sizeof(buffer);
766 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
768 RegCloseKey (parmKey);
770 strcpy(buffer, "AFS");
775 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
777 static BOOL IsAdmin (void)
779 static BOOL fAdmin = FALSE;
780 static BOOL fTested = FALSE;
784 /* Obtain the SID for the AFS client admin group. If the group does
785 * not exist, then assume we have AFS client admin privileges.
787 PSID psidAdmin = NULL;
788 DWORD dwSize, dwSize2;
789 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
790 char *pszRefDomain = NULL;
791 SID_NAME_USE snu = SidTypeGroup;
793 dwSize = sizeof(pszAdminGroup);
795 if (!GetComputerName(pszAdminGroup, &dwSize)) {
796 /* Can't get computer name. We return false in this case.
797 Retain fAdmin and fTested. This shouldn't happen.*/
804 strcat(pszAdminGroup,"\\");
805 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
807 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
808 /* that should always fail. */
810 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
811 /* if we can't find the group, then we allow the operation */
816 if (dwSize == 0 || dwSize2 == 0) {
822 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
824 pszRefDomain = (char *)malloc(dwSize2);
825 assert(pszRefDomain);
827 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
828 /* We can't lookup the group now even though we looked it up earlier.
829 Could this happen? */
832 /* Then open our current ProcessToken */
835 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
838 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
839 /* We'll have to allocate a chunk of memory to store the list of
840 * groups to which this user belongs; find out how much memory
844 PTOKEN_GROUPS pGroups;
846 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
848 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
851 /* Allocate that buffer, and read in the list of groups. */
852 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
854 /* Look through the list of group SIDs and see if any of them
855 * matches the AFS Client Admin group SID.
858 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
860 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
870 /* if do not have permission because we were not explicitly listed
871 * in the Admin Client Group let's see if we are the SYSTEM account
874 PTOKEN_USER pTokenUser;
875 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
876 PSID pSidLocalSystem = 0;
879 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
881 pTokenUser = (PTOKEN_USER)malloc(dwSize);
884 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
885 gle = GetLastError();
887 if (AllocateAndInitializeSid( &SIDAuth, 1,
888 SECURITY_LOCAL_SYSTEM_RID,
892 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
896 FreeSid(pSidLocalSystem);
915 SetACLCmd(struct cmd_syndesc *as, void *arock)
918 struct ViceIoctl blob;
920 struct cmd_item *ti, *ui;
924 int idf = getidf(as, parm_setacl_id);
928 if (as->parms[2].items)
932 plusp = !(as->parms[3].items);
933 for(ti=as->parms[0].items; ti;ti=ti->next) {
934 blob.out_size = AFS_PIOCTL_MAXSIZE;
936 blob.in = blob.out = space;
937 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
939 Die(errno, ti->data);
945 ta = ParseAcl(space);
948 "fs: %s: invalid acl data returned from VIOCGETAL\n",
953 if (!plusp && ta->dfs) {
955 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
957 "(you may specify \"null\" to revoke all rights, however)\n");
964 ta = EmptyAcl(space);
966 ta = ParseAcl(space);
969 "fs: %s: invalid acl data returned from VIOCGETAL\n",
974 CleanAcl(ta, ti->data);
975 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
979 "%s: Missing second half of user/access pair.\n", pn);
983 rights = Convert(ui->next->data, ta->dfs, &rtype);
984 if (rtype == destroy && !ta->dfs) {
985 struct AclEntry *tlist;
987 tlist = (plusp ? ta->pluslist : ta->minuslist);
988 if (!FindList(tlist, ui->data))
991 if (rtype == deny && !ta->dfs)
993 if (rtype == destroy && ta->dfs)
995 ChangeList(ta, plusp, ui->data, rights);
997 blob.in = AclToString(ta);
999 blob.in_size = 1+(long)strlen(blob.in);
1000 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1002 if (errno == EINVAL) {
1004 static char *fsenv = 0;
1006 fsenv = (char *)getenv("FS_EXPERT");
1008 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
1011 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1012 "\nPossible reasons for this include:\n\n",
1013 " -You may have specified an inappropriate combination of rights.\n",
1014 " For example, some DFS-supported filesystems may not allow you to\n",
1015 " drop the \"c\" right from \"user_obj\".\n\n",
1016 " -A mask_obj may be required (it is likely required by the underlying\n",
1017 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
1018 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
1019 " does not automatically create or update the mask_obj. Try setting\n",
1020 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
1021 " users or groups. You can do this with a single command, such as\n",
1022 " \"fs sa mask_obj all user:somename read\"\n\n",
1023 " -A specified user or group may not exist.\n\n",
1024 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
1025 " This is probably not allowed by the underlying file system.\n\n",
1026 " -If you add a user or group to a DFS ACL, remember that it must be\n",
1027 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
1028 " may be local requirements on the format of the user or group name.\n",
1029 " Check with your cell administrator.\n\n",
1030 " -Or numerous other possibilities. It would be great if we could be more\n",
1031 " precise about the actual problem, but for various reasons, this is\n",
1032 " impractical via this interface. If you can't figure it out, you\n",
1033 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
1034 " whatever is provided). You may get better results. Good luck!\n\n",
1035 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
1039 "%s: Invalid argument, possible reasons include:\n",
1041 fprintf(stderr,"\t-File not in AFS\n");
1043 "\t-Too many users on access control list\n");
1045 "\t-Tried to add non-existent user to access control list\n");
1048 Die(errno, ti->data);
1059 CopyACLCmd(struct cmd_syndesc *as, void *arock)
1062 struct ViceIoctl blob;
1063 struct Acl *fa, *ta = 0;
1064 struct AclEntry *tp;
1065 struct cmd_item *ti;
1067 int idf = getidf(as, parm_copyacl_id);
1070 if (as->parms[2].items)
1074 blob.out_size = AFS_PIOCTL_MAXSIZE;
1076 blob.in = blob.out = space;
1077 code = pioctl_utf8(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1079 Die(errno, as->parms[0].items->data);
1082 fa = ParseAcl(space);
1085 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1086 as->parms[0].items->data);
1089 CleanAcl(fa, as->parms[0].items->data);
1090 for (ti=as->parms[1].items; ti;ti=ti->next) {
1091 blob.out_size = AFS_PIOCTL_MAXSIZE;
1093 blob.in = blob.out = space;
1094 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1096 Die(errno, ti->data);
1103 ta = EmptyAcl(space);
1105 ta = ParseAcl(space);
1108 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1113 CleanAcl(ta, ti->data);
1114 if (ta->dfs != fa->dfs) {
1116 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1122 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1124 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1129 strcpy(ta->cell, fa->cell);
1131 for (tp = fa->pluslist;tp;tp=tp->next)
1132 ChangeList(ta, 1, tp->name, tp->rights);
1133 for (tp = fa->minuslist;tp;tp=tp->next)
1134 ChangeList(ta, 0, tp->name, tp->rights);
1135 blob.in = AclToString(ta);
1137 blob.in_size = 1+(long)strlen(blob.in);
1138 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1140 if (errno == EINVAL) {
1142 "%s: Invalid argument, possible reasons include:\n", pn);
1143 fprintf(stderr,"\t-File not in AFS\n");
1145 Die(errno, ti->data);
1156 /* pioctl_utf8() call to get the cellname of a pathname */
1158 GetCell(char *fname, char *cellname)
1161 struct ViceIoctl blob;
1164 blob.out_size = CELL_MAXNAMELEN;
1165 blob.out = cellname;
1167 code = pioctl_utf8(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1169 cellname[blob.out_size - 1] = '\0';
1173 /* Check if a username is valid: If it contains only digits (or a
1174 * negative sign), then it might be bad. We then query the ptserver
1178 BadName(char *aname, char *fname)
1180 afs_int32 tc, code, id;
1182 char cell[CELL_MAXNAMELEN];
1185 for ( nm = aname; tc = *nm; nm++) {
1186 /* all must be '-' or digit to be bad */
1187 if (tc != '-' && (tc < '0' || tc > '9'))
1191 /* Go to the PRDB and see if this all number username is valid */
1192 code = GetCell(fname, cell);
1196 cm_GetConfigDir(confDir, sizeof(confDir));
1198 pr_Initialize(1, confDir, cell);
1199 code = pr_SNameToId(aname, &id);
1202 /* 1=>Not-valid; 0=>Valid */
1203 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1207 /* clean up an access control list of its bad entries; return 1 if we made
1208 any changes to the list, and 0 otherwise */
1210 CleanAcl(struct Acl *aa, char *fname)
1212 struct AclEntry *te, **le, *ne;
1215 /* Don't correct DFS ACL's for now */
1219 /* prune out bad entries */
1220 changes = 0; /* count deleted entries */
1222 for(te = aa->pluslist; te; te=ne) {
1224 if (BadName(te->name, fname)) {
1234 le = &aa->minuslist;
1235 for(te = aa->minuslist; te; te=ne) {
1237 if (BadName(te->name, fname)) {
1251 /* clean up an acl to not have bogus entries */
1253 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1257 struct ViceIoctl blob;
1259 struct cmd_item *ti;
1260 struct AclEntry *te;
1263 SetDotDefault(&as->parms[0].items);
1264 for(ti=as->parms[0].items; ti; ti=ti->next) {
1265 blob.out_size = AFS_PIOCTL_MAXSIZE;
1268 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1270 Die(errno, ti->data);
1276 ta = ParseAcl(space);
1279 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1286 "%s: cleanacl is not supported for DFS access lists.\n",
1292 changes = CleanAcl(ta, ti->data);
1295 /* now set the acl */
1296 blob.in=AclToString(ta);
1297 blob.in_size = (long)strlen(blob.in)+1;
1299 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1301 if (errno == EINVAL) {
1303 "%s: Invalid argument, possible reasons include\n",
1305 fprintf(stderr,"%s: File not in vice or\n", pn);
1307 "%s: Too many users on access control list or\n",
1310 Die(errno, ti->data);
1316 /* now list the updated acl */
1317 printf("Access list for %s is now\n", ti->data);
1318 if (ta->nplus > 0) {
1320 printf("Normal rights:\n");
1321 for(te = ta->pluslist;te;te=te->next) {
1322 printf(" %s ", te->name);
1323 PRights(te->rights, ta->dfs);
1327 if (ta->nminus > 0) {
1328 printf("Negative rights:\n");
1329 for(te = ta->minuslist;te;te=te->next) {
1330 printf(" %s ", te->name);
1331 PRights(te->rights, ta->dfs);
1338 printf("Access list for %s is fine.\n", ti->data);
1346 ListACLCmd(struct cmd_syndesc *as, void *arock)
1350 struct ViceIoctl blob;
1351 struct AclEntry *te;
1352 struct cmd_item *ti;
1353 int idf = getidf(as, parm_listacl_id);
1356 SetDotDefault(&as->parms[0].items);
1357 for(ti=as->parms[0].items; ti; ti=ti->next) {
1359 blob.out_size = AFS_PIOCTL_MAXSIZE;
1361 blob.in = blob.out = space;
1362 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1364 Die(errno, ti->data);
1368 ta = ParseAcl(space);
1371 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1376 if (as->parms[3].items) { /* -cmd */
1377 printf("fs setacl -dir %s -acl ", ti->data);
1378 if (ta->nplus > 0) {
1379 for (te = ta->pluslist; te; te = te->next) {
1380 printf(" %s ", te->name);
1381 PRights(te->rights, ta->dfs);
1385 if (ta->nminus > 0) {
1386 printf("fs setacl -dir %s -acl ", ti->data);
1387 for (te = ta->minuslist; te; te = te->next) {
1388 printf(" %s ", te->name);
1389 PRights(te->rights, ta->dfs);
1391 printf(" -negative\n");
1396 printf("Access list for %s is\n", ti->data);
1399 printf("DFS access list for %s is\n", ti->data);
1402 printf("DFS initial directory access list of %s is\n", ti->data);
1405 printf("DFS initial file access list of %s is\n", ti->data);
1409 printf(" Default cell = %s\n", ta->cell);
1411 separator = ta->dfs? DFS_SEPARATOR : ' ';
1412 if (ta->nplus > 0) {
1414 printf("Normal rights:\n");
1415 for(te = ta->pluslist;te;te=te->next) {
1416 printf(" %s%c", te->name, separator);
1417 PRights(te->rights, ta->dfs);
1421 if (ta->nminus > 0) {
1422 printf("Negative rights:\n");
1423 for(te = ta->minuslist;te;te=te->next) {
1424 printf(" %s ", te->name);
1425 PRights(te->rights, ta->dfs);
1438 FlushAllCmd(struct cmd_syndesc *as, void *arock)
1441 struct ViceIoctl blob;
1443 blob.in_size = blob.out_size = 0;
1444 code = pioctl_utf8(NULL, VIOC_FLUSHALL, &blob, 0);
1446 fprintf(stderr, "Error flushing all ");
1453 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1456 struct ViceIoctl blob;
1457 struct cmd_item *ti;
1460 SetDotDefault(&as->parms[0].items);
1461 for(ti=as->parms[0].items; ti; ti=ti->next) {
1462 blob.in_size = blob.out_size = 0;
1463 code = pioctl_utf8(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1465 fprintf(stderr, "Error flushing volume ");
1475 FlushCmd(struct cmd_syndesc *as, void *arock)
1478 struct ViceIoctl blob;
1479 struct cmd_item *ti;
1482 cm_ioctlQueryOptions_t options;
1484 if (as->parms[1].items)
1487 for(ti=as->parms[0].items; ti; ti=ti->next) {
1489 memset(&options, 0, sizeof(options));
1490 options.size = sizeof(options);
1491 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1492 options.literal = literal;
1493 blob.in_size = options.size; /* no variable length data */
1497 code = pioctl_utf8(ti->data, VIOCFLUSH, &blob, 0);
1499 if (errno == EMFILE) {
1500 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1503 fprintf(stderr, "%s: Error flushing file ", pn);
1513 /* all this command does is repackage its args and call SetVolCmd */
1515 SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
1516 struct cmd_syndesc ts;
1518 /* copy useful stuff from our command slot; we may later have to reorder */
1519 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1520 return SetVolCmd(&ts, arock);
1524 SetVolCmd(struct cmd_syndesc *as, void *arock) {
1526 struct ViceIoctl blob;
1527 struct cmd_item *ti;
1528 struct VolumeStatus *status;
1529 char *motd, *offmsg, *input;
1532 SetDotDefault(&as->parms[0].items);
1533 for(ti=as->parms[0].items; ti; ti=ti->next) {
1535 blob.out_size = AFS_PIOCTL_MAXSIZE;
1536 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1539 status = (VolumeStatus *)space;
1540 status->MinQuota = status->MaxQuota = -1;
1541 motd = offmsg = NULL;
1542 if (as->parms[1].items) {
1543 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1545 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1550 if (as->parms[2].items)
1551 motd = as->parms[2].items->data;
1552 if (as->parms[3].items)
1553 offmsg = as->parms[3].items->data;
1554 input = (char *)status + sizeof(*status);
1555 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1557 if (strlen(offmsg) >= VMSGSIZE) {
1558 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1563 strcpy(input,offmsg);
1564 blob.in_size += (long)strlen(offmsg);
1565 input += strlen(offmsg) + 1;
1569 if (strlen(motd) >= VMSGSIZE) {
1570 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1575 blob.in_size += (long)strlen(motd);
1576 input += strlen(motd) + 1;
1579 code = pioctl_utf8(ti->data,VIOCSETVOLSTAT, &blob, 1);
1581 Die(errno, ti->data);
1588 /* values match cache manager File Types */
1590 filetypestr(afs_uint32 type)
1592 char * s = "Object";
1615 ExamineCmd(struct cmd_syndesc *as, void *arock)
1618 struct ViceIoctl blob;
1619 struct cmd_item *ti;
1620 struct VolumeStatus *status;
1621 char *name, *offmsg, *motd;
1624 cm_ioctlQueryOptions_t options;
1626 if (as->parms[1].items)
1629 SetDotDefault(&as->parms[0].items);
1630 for(ti=as->parms[0].items; ti; ti=ti->next) {
1632 afs_uint32 filetype;
1633 afs_uint32 owner[2];
1634 char cell[CELL_MAXNAMELEN];
1637 memset(&fid, 0, sizeof(fid));
1638 memset(&options, 0, sizeof(options));
1640 options.size = sizeof(options);
1641 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1642 options.literal = literal;
1643 blob.in_size = options.size; /* no variable length data */
1646 blob.out_size = sizeof(cm_fid_t);
1647 blob.out = (char *) &fid;
1648 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
1649 blob.out_size == sizeof(cm_fid_t)) {
1650 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1653 Die(errno, ti->data);
1658 blob.out_size = sizeof(filetype);
1659 blob.out = &filetype;
1661 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1662 if (code || blob.out_size != sizeof(filetype)) {
1663 Die(errno, ti->data);
1668 blob.out_size = CELL_MAXNAMELEN;
1671 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1673 cell[blob.out_size-1] = '\0';
1674 printf("%s %s (%u.%u.%u) contained in cell %s\n",
1675 filetypestr(filetype),
1676 ti->data, fid.volume, fid.vnode, fid.unique,
1677 code ? "unknown-cell" : cell);
1679 blob.out_size = 2 * sizeof(afs_uint32);
1680 blob.out = (char *) &owner;
1681 if (0 == pioctl_utf8(ti->data, VIOCGETOWNER, &blob, 1) &&
1682 blob.out_size == 2 * sizeof(afs_uint32)) {
1683 char oname[PR_MAXNAMELEN] = "(unknown)";
1684 char gname[PR_MAXNAMELEN] = "(unknown)";
1687 /* Go to the PRDB and see if this all number username is valid */
1688 cm_GetConfigDir(confDir, sizeof(confDir));
1690 pr_Initialize(1, confDir, cell);
1691 pr_SIdToName(owner[0], oname);
1692 pr_SIdToName(owner[1], gname);
1693 printf("Owner %s (%u) Group %s (%u)\n", oname, owner[0], gname, owner[1]);
1697 blob.out_size = AFS_PIOCTL_MAXSIZE;
1698 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1700 space[blob.out_size - 1] = '\0';
1701 status = (VolumeStatus *)space;
1702 name = (char *)status + sizeof(*status);
1703 offmsg = name + strlen(name) + 1;
1704 motd = offmsg + strlen(offmsg) + 1;
1705 PrintStatus(status, name, motd, offmsg);
1707 Die(errno, ti->data);
1711 code = pioctl_utf8(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
1714 printf("Volume is online\n");
1717 printf("Volume is offline\n");
1720 printf("All Volume servers are down\n");
1723 printf("All volume servers are busy\n");
1726 printf("Unknown volume state\n");
1727 Die(errno, ti->data);
1735 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1738 struct ViceIoctl blob;
1739 struct cmd_item *ti;
1740 struct VolumeStatus *status;
1745 printf("%-25s%-11s%-11s%-7s%-13s\n", "Volume Name", " Quota",
1746 " Used", " %Used", " Partition");
1747 SetDotDefault(&as->parms[0].items);
1748 for(ti=as->parms[0].items; ti; ti=ti->next) {
1750 blob.out_size = AFS_PIOCTL_MAXSIZE;
1753 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1755 Die(errno, ti->data);
1759 space[blob.out_size - 1] = '\0';
1760 status = (VolumeStatus *)space;
1761 name = (char *)status + sizeof(*status);
1762 QuickPrintStatus(status, name);
1768 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1771 struct ViceIoctl blob;
1772 struct cmd_item *ti;
1778 cm_ioctlQueryOptions_t options;
1780 if (as->parms[1].items)
1783 SetDotDefault(&as->parms[0].items);
1784 for(ti=as->parms[0].items; ti; ti=ti->next) {
1786 afs_uint32 filetype;
1789 memset(&fid, 0, sizeof(fid));
1790 memset(&options, 0, sizeof(options));
1792 options.size = sizeof(options);
1793 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1794 options.literal = literal;
1795 blob.in_size = options.size; /* no variable length data */
1798 blob.out_size = sizeof(cm_fid_t);
1799 blob.out = (char *) &fid;
1800 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
1801 blob.out_size == sizeof(cm_fid_t)) {
1802 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1805 Die(errno, ti->data);
1810 blob.out_size = sizeof(filetype);
1811 blob.out = &filetype;
1813 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1814 if (code || blob.out_size != sizeof(filetype)) {
1815 Die(errno, ti->data);
1819 blob.out_size = AFS_PIOCTL_MAXSIZE;
1821 memset(space, 0, sizeof(space));
1822 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
1824 Die(errno, ti->data);
1828 hosts = (afs_int32 *) space;
1829 printf("%s %s is on host%s ",
1830 filetypestr(filetype),
1832 (hosts[0] && !hosts[1]) ? "": "s");
1833 for(j=0; j<AFS_MAXHOSTS; j++) {
1836 tp = hostutil_GetNameByINet(hosts[j]);
1846 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1849 struct ViceIoctl blob;
1850 struct cmd_item *ti;
1852 struct VolumeStatus *status;
1855 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1856 " used", " avail", " %used");
1857 SetDotDefault(&as->parms[0].items);
1858 for(ti=as->parms[0].items; ti; ti=ti->next) {
1860 blob.out_size = AFS_PIOCTL_MAXSIZE;
1863 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1865 Die(errno, ti->data);
1869 space[blob.out_size - 1] = '\0';
1870 status = (VolumeStatus *)space;
1871 name = (char *)status + sizeof(*status);
1872 QuickPrintSpace(status, name);
1878 QuotaCmd(struct cmd_syndesc *as, void *arock)
1881 struct ViceIoctl blob;
1882 struct cmd_item *ti;
1884 struct VolumeStatus *status;
1887 SetDotDefault(&as->parms[0].items);
1888 for(ti=as->parms[0].items; ti; ti=ti->next) {
1890 blob.out_size = AFS_PIOCTL_MAXSIZE;
1893 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1894 if (code || blob.out_size != sizeof(*status)) {
1895 Die(errno, ti->data);
1899 status = (VolumeStatus *)space;
1900 if (status->MaxQuota)
1901 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1904 printf("%2.0f%% of quota used.\n", quotaPct);
1910 ListMountCmd(struct cmd_syndesc *as, void *arock)
1913 struct ViceIoctl blob;
1914 struct cmd_item *ti;
1915 char orig_name[1024]; /*Original name, may be modified*/
1916 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1917 char parent_dir[1024]; /*Parent directory of true name*/
1918 char *last_component; /*Last component of true name*/
1920 struct stat statbuff; /*Buffer for status info*/
1921 #endif /* not WIN32 */
1923 int link_chars_read; /*Num chars read in readlink()*/
1924 #endif /* not WIN32 */
1925 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1928 for(ti=as->parms[0].items; ti; ti=ti->next) {
1932 strcpy(orig_name, ti->data);
1933 #else /* not WIN32 */
1934 sprintf(orig_name, "%s%s",
1935 (ti->data[0] == '/') ? "" : "./",
1937 #endif /* not WIN32 */
1940 if (lstat(orig_name, &statbuff) < 0) {
1941 /* if lstat fails, we should still try the pioctl, since it
1942 * may work (for example, lstat will fail, but pioctl will
1943 * work if the volume of offline (returning ENODEV). */
1944 statbuff.st_mode = S_IFDIR; /* lie like pros */
1948 * The lstat succeeded. If the given file is a symlink, substitute
1949 * the file name with the link name.
1951 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1954 * Read name of resolved file.
1956 link_chars_read = readlink(orig_name, true_name, 1024);
1957 if (link_chars_read <= 0) {
1959 "%s: Can't read target name for '%s' symbolic link!\n",
1966 * Add a trailing null to what was read, bump the length.
1968 true_name[link_chars_read++] = 0;
1971 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1972 * have to create a full pathname using the original name and the
1973 * relative symlink name. Find the rightmost slash in the original
1974 * name (we know there is one) and splice in the symlink value.
1976 if (true_name[0] != '\\') {
1977 last_component = (char *) strrchr(orig_name, '\\');
1978 strcpy(++last_component, true_name);
1979 strcpy(true_name, orig_name);
1982 strcpy(true_name, orig_name);
1984 strcpy(true_name, orig_name);
1988 * Find rightmost slash, if any.
1991 last_component = (char *) strrchr(true_name, '\\');
1992 if (!last_component)
1994 last_component = (char *) strrchr(true_name, '/');
1995 if (last_component) {
1997 * Found it. Designate everything before it as the parent directory,
1998 * everything after it as the final component.
2000 strncpy(parent_dir, true_name, last_component - true_name + 1);
2001 parent_dir[last_component - true_name + 1] = 0;
2002 last_component++; /*Skip the slash*/
2004 if (!InAFS(parent_dir)) {
2005 const char * nbname = NetbiosName();
2006 int len = (int)strlen(nbname);
2008 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
2009 parent_dir[len+2] == '\\' &&
2010 parent_dir[len+3] == '\0' &&
2011 !strnicmp(nbname,&parent_dir[2],len))
2013 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
2019 * No slash appears in the given file name. Set parent_dir to the current
2020 * directory, and the last component as the given name.
2022 fs_ExtractDriveLetter(true_name, parent_dir);
2023 strcat(parent_dir, ".");
2024 last_component = true_name;
2025 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
2028 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
2029 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
2030 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
2035 blob.in = last_component;
2036 blob.in_size = (long)strlen(last_component)+1;
2037 blob.out_size = AFS_PIOCTL_MAXSIZE;
2039 memset(space, 0, AFS_PIOCTL_MAXSIZE);
2041 code = pioctl_utf8(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
2044 printf("'%s' is a %smount point for volume '%.*s'\n",
2046 (thru_symlink ? "symbolic link, leading to a " : ""),
2051 if (errno == EINVAL) {
2052 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
2054 Die(errno, (ti->data ? ti->data : parent_dir));
2063 MakeMountCmd(struct cmd_syndesc *as, void *arock)
2066 char *cellName, *volName, *tmpName;
2068 char localCellName[128];
2070 char path[1024] = "";
2071 struct afsconf_cell info;
2072 struct vldbentry vldbEntry;
2073 struct ViceIoctl blob;
2076 memset(&info, 0, sizeof(info));
2078 if (as->parms[2].items) /* cell name specified */
2079 cellName = as->parms[2].items->data;
2082 volName = as->parms[1].items->data;
2084 if (strlen(volName) >= 64) {
2085 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
2089 /* Check for a cellname in the volume specification, and complain
2090 * if it doesn't match what was specified with -cell */
2091 if (tmpName = strchr(volName, ':')) {
2094 if (strcasecmp(cellName,volName)) {
2095 fprintf(stderr,"fs: cellnames do not match.\n");
2100 volName = ++tmpName;
2103 parent = Parent(as->parms[0].items->data);
2104 if (!InAFS(parent)) {
2106 const char * nbname = NetbiosName();
2107 int len = (int)strlen(nbname);
2109 if (parent[0] == '\\' && parent[1] == '\\' &&
2110 parent[len+2] == '\\' &&
2111 parent[len+3] == '\0' &&
2112 !strnicmp(nbname,&parent[2],len))
2114 sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
2115 parent = Parent(path);
2116 if (!InAFS(parent)) {
2117 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2123 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2128 if ( strlen(path) == 0 )
2129 strcpy(path, as->parms[0].items->data);
2131 if ( IsFreelanceRoot(parent) ) {
2133 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2139 blob.out_size = sizeof(localCellName);
2140 blob.out = localCellName;
2141 code = pioctl_utf8(parent, VIOC_GET_WS_CELL, &blob, 1);
2143 localCellName[sizeof(localCellName) - 1] = '\0';
2144 cellName = localCellName;
2149 code = GetCell(parent,space);
2155 code = GetCellName(cellName?cellName:space, &info);
2159 if (!(as->parms[4].items)) {
2160 /* not fast, check which cell the mountpoint is being created in */
2162 /* not fast, check name with VLDB */
2164 code = VLDBInit(1, &info);
2166 /* make the check. Don't complain if there are problems with init */
2167 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2168 if (code == VL_NOENT) {
2169 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2170 pn, volName, cellName ? cellName : space);
2175 if (as->parms[3].items) /* if -rw specified */
2180 /* cellular mount point, prepend cell prefix */
2181 strcat(space, info.name);
2184 strcat(space, volName); /* append volume name */
2185 strcat(space, "."); /* stupid convention; these end with a period */
2187 /* create symlink with a special pioctl for Windows NT, since it doesn't
2188 * have a symlink system call.
2191 blob.in_size = 1 + (long)strlen(space);
2194 code = pioctl_utf8(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2195 #else /* not WIN32 */
2196 code = symlink(space, path);
2197 #endif /* not WIN32 */
2199 if (info.linkedCell)
2200 free(info.linkedCell);
2210 * Delete AFS mount points. Variables are used as follows:
2211 * tbuffer: Set to point to the null-terminated directory name of the mount point
2212 * (or ``.'' if none is provided)
2213 * tp: Set to point to the actual name of the mount point to nuke.
2216 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2218 struct ViceIoctl blob;
2219 struct cmd_item *ti;
2221 char lsbuffer[1024];
2225 for(ti=as->parms[0].items; ti; ti=ti->next) {
2227 tp = (char *) strrchr(ti->data, '\\');
2229 tp = (char *) strrchr(ti->data, '/');
2231 strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1)); /* the dir name */
2233 tp++; /* skip the slash */
2236 if (!InAFS(tbuffer)) {
2237 const char * nbname = NetbiosName();
2238 int len = (int)strlen(nbname);
2240 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2241 tbuffer[len+2] == '\\' &&
2242 tbuffer[len+3] == '\0' &&
2243 !strnicmp(nbname,&tbuffer[2],len))
2245 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
2250 fs_ExtractDriveLetter(ti->data, tbuffer);
2251 strcat(tbuffer, ".");
2253 fs_StripDriveLetter(tp, tp, 0);
2256 blob.in_size = (long)strlen(tp)+1;
2257 blob.out = lsbuffer;
2258 blob.out_size = sizeof(lsbuffer);
2259 code = pioctl_utf8(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2261 if (errno == EINVAL) {
2262 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2264 Die(errno, ti->data);
2267 continue; /* don't bother trying */
2270 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2271 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2273 continue; /* skip */
2278 blob.in_size = (long)strlen(tp)+1;
2279 code = pioctl_utf8(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2281 Die(errno, ti->data);
2292 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2295 struct ViceIoctl blob;
2299 struct afsconf_cell info;
2300 struct chservinfo checkserv;
2302 memset(&info, 0, sizeof(info));
2303 memset(&checkserv, 0, sizeof(struct chservinfo));
2304 blob.in_size=sizeof(struct chservinfo);
2305 blob.in=(caddr_t)&checkserv;
2307 blob.out_size = AFS_PIOCTL_MAXSIZE;
2309 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2311 /* prepare flags for checkservers command */
2312 temp = 2; /* default to checking local cell only */
2313 if (as->parms[2].items)
2314 temp |= 1; /* set fast flag */
2315 if (as->parms[1].items)
2316 temp &= ~2; /* turn off local cell check */
2318 checkserv.magic = 0x12345678; /* XXX */
2319 checkserv.tflags=temp;
2321 /* now copy in optional cell name, if specified */
2322 if (as->parms[0].items) {
2323 code = GetCellName(as->parms[0].items->data, &info);
2327 strcpy(checkserv.tbuffer,info.name);
2328 checkserv.tsize=(int)strlen(info.name)+1;
2329 if (info.linkedCell)
2330 free(info.linkedCell);
2332 strcpy(checkserv.tbuffer,"\0");
2336 if(as->parms[3].items) {
2337 checkserv.tinterval=atol(as->parms[3].items->data);
2340 if(checkserv.tinterval<0) {
2341 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2342 checkserv.tinterval=-1;
2343 } else if(checkserv.tinterval> 600) {
2344 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2345 checkserv.tinterval=600; /* 10 min max interval */
2348 checkserv.tinterval = -1; /* don't change current interval */
2351 if ( checkserv.tinterval >= 0 ) {
2354 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2359 fprintf (stderr,"Permission denied: requires root access.\n");
2365 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
2367 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2368 printf("Must be root to change -interval\n");
2374 memcpy(&temp, space, sizeof(afs_int32));
2375 if (checkserv.tinterval >= 0) {
2376 if (checkserv.tinterval > 0)
2377 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2378 checkserv.tinterval, temp);
2380 printf("The current down server probe interval is %d secs\n", temp);
2384 printf("All servers are running.\n");
2386 printf("These servers unavailable due to network or server problems: ");
2387 for(j=0; j < AFS_MAXHOSTS; j++) {
2388 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2391 tp = hostutil_GetNameByINet(temp);
2401 MessagesCmd(struct cmd_syndesc *as, void *arock)
2404 struct ViceIoctl blob;
2405 struct gaginfo gagflags;
2406 struct cmd_item *show;
2408 memset(&gagflags, 0, sizeof(struct gaginfo));
2409 blob.in_size = sizeof(struct gaginfo);
2410 blob.in = (caddr_t ) &gagflags;
2411 blob.out_size = AFS_PIOCTL_MAXSIZE;
2413 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2415 if (show = as->parms[0].items) {
2416 if (!strcasecmp (show->data, "user"))
2417 gagflags.showflags |= GAGUSER;
2418 else if (!strcasecmp (show->data, "console"))
2419 gagflags.showflags |= GAGCONSOLE;
2420 else if (!strcasecmp (show->data, "all"))
2421 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2422 else if (!strcasecmp (show->data, "none"))
2426 "unrecognized flag %s: must be in {user,console,all,none}\n",
2435 code = pioctl_utf8(0, VIOC_GAG, &blob, 1);
2444 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2447 struct ViceIoctl blob;
2451 code = pioctl_utf8(0, VIOCCKBACK, &blob, 1);
2456 printf("All volumeID/name mappings checked.\n");
2462 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2465 struct ViceIoctl blob;
2470 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2475 fprintf (stderr,"Permission denied: requires root access.\n");
2480 if (!as->parms[0].items && !as->parms[1].items) {
2481 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2484 if (as->parms[0].items) {
2485 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2487 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2492 blob.in = (char *) &temp;
2493 blob.in_size = sizeof(afs_int32);
2495 code = pioctl_utf8(0, VIOCSETCACHESIZE, &blob, 1);
2497 Die(errno, (char *) 0);
2501 printf("New cache size set.\n");
2506 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2509 struct ViceIoctl blob;
2510 cm_cacheParms_t parms;
2512 memset(&parms, 0, sizeof(parms));
2515 blob.out_size = sizeof(parms);
2516 blob.out = (char *) &parms;
2517 code = pioctl_utf8(0, VIOCGETCACHEPARMS, &blob, 1);
2518 if (code || blob.out_size != sizeof(parms)) {
2523 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2524 parms.parms[1], parms.parms[0]);
2525 if (parms.parms[1] > parms.parms[0])
2526 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2531 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2534 afs_int32 i, j, *lp, magic, size;
2536 afs_int32 addr, maxa = AFS_OMAXHOSTS;
2537 struct ViceIoctl blob;
2540 resolve = !(as->parms[0].items); /* -numeric */
2542 for(i=0;i<1000;i++) {
2544 memcpy(tp, &i, sizeof(afs_int32));
2545 tp = (char *)(space + sizeof(afs_int32));
2546 lp = (afs_int32 *)tp;
2548 size = sizeof(afs_int32) + sizeof(afs_int32);
2549 blob.out_size = AFS_PIOCTL_MAXSIZE;
2550 blob.in_size = sizeof(afs_int32);
2553 code = pioctl_utf8(0, VIOCGETCELL, &blob, 1);
2556 break; /* done with the list */
2561 memcpy(&magic, tp, sizeof(afs_int32));
2562 if (magic == 0x12345678) {
2563 maxa = AFS_MAXHOSTS;
2564 tp += sizeof(afs_int32);
2566 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2567 for(j=0; j < maxa && j*sizeof(afs_int32) < AFS_PIOCTL_MAXSIZE; j++) {
2568 char *name, tbuffer[20];
2570 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2575 name = hostutil_GetNameByINet(addr);
2578 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2579 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2582 printf(" %s", name);
2591 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2594 char *tp, *aliasName, *realName;
2595 struct ViceIoctl blob;
2599 memcpy(tp, &i, sizeof(afs_int32));
2600 blob.out_size = AFS_PIOCTL_MAXSIZE;
2601 blob.in_size = sizeof(afs_int32);
2604 code = pioctl_utf8(0, VIOC_GETALIAS, &blob, 1);
2607 break; /* done with the list */
2611 space[blob.out_size - 1] = '\0';
2614 tp += strlen(aliasName) + 1;
2616 printf("Alias %s for cell %s\n", aliasName, realName);
2622 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2625 struct ViceIoctl blob;
2626 struct cmd_item *ti;
2628 struct hostent *thp;
2632 ti = as->parms[0].items;
2635 thp = hostutil_GetHostByName(ti->data);
2637 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2640 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2642 hostAddr = 0; /* means don't set host */
2643 setp = 0; /* aren't setting host */
2646 /* now do operation */
2647 blob.in_size = sizeof(afs_int32);
2648 blob.out_size = sizeof(afs_int32);
2649 blob.in = (char *) &hostAddr;
2650 blob.out = (char *) &hostAddr;
2652 code = pioctl_utf8(0, VIOC_CBADDR, &blob, 1);
2662 NewCellCmd(struct cmd_syndesc *as, void *arock)
2665 afs_int32 code, linkedstate=0, size=0, *lp;
2666 struct ViceIoctl blob;
2667 struct cmd_item *ti;
2668 char *tp, *cellname=0;
2669 struct hostent *thp;
2670 afs_int32 fsport = 0, vlport = 0;
2672 memset(space, 0, AFS_MAXHOSTS * sizeof(afs_int32));
2674 lp = (afs_int32 *)tp;
2676 tp += sizeof(afs_int32);
2677 for(ti=as->parms[1].items; ti; ti=ti->next) {
2678 thp = hostutil_GetHostByName(ti->data);
2680 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2684 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2685 tp += sizeof(afs_int32);
2688 if (as->parms[2].items) {
2690 * Link the cell, for the purposes of volume location, to the specified
2693 cellname = as->parms[2].items->data;
2696 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2697 if (as->parms[3].items) {
2698 code = util_GetInt32(as->parms[3].items->data, &vlport);
2700 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2704 if (as->parms[4].items) {
2705 code = util_GetInt32(as->parms[4].items->data, &fsport);
2707 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2712 tp = (char *)(space + (AFS_MAXHOSTS+1) *sizeof(afs_int32));
2713 lp = (afs_int32 *)tp;
2717 strcpy(space + ((AFS_MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2718 size = ((AFS_MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2719 tp = (char *)(space + size);
2721 strcpy(tp, cellname);
2722 size += strlen(cellname) + 1;
2724 blob.in_size = size;
2727 code = pioctl_utf8(0, VIOCNEWCELL, &blob, 1);
2733 struct ViceIoctl blob;
2736 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2741 blob.in = (char *) 0;
2742 blob.out_size = AFS_PIOCTL_MAXSIZE;
2745 code = pioctl_utf8((char *) 0, VIOCNEWCELL, &blob, 1);
2748 Die(errno, (char *) 0);
2752 printf("Cell servers information refreshed\n");
2759 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2762 struct ViceIoctl blob;
2764 char *aliasName, *realName;
2766 /* Setup and do the NEWALIAS pioctl call */
2767 aliasName = as->parms[0].items->data;
2768 realName = as->parms[1].items->data;
2770 strcpy(tp, aliasName);
2771 tp += strlen(aliasName) + 1;
2772 strcpy(tp, realName);
2773 tp += strlen(realName) + 1;
2775 blob.in_size = tp - space;
2779 code = pioctl_utf8(0, VIOC_NEWALIAS, &blob, 1);
2781 if (errno == EEXIST) {
2783 "%s: cell name `%s' in use by an existing cell.\n", pn,
2795 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2798 struct cmd_item *ti;
2799 struct ViceIoctl blob;
2802 cm_ioctlQueryOptions_t options;
2804 if (as->parms[1].items)
2807 SetDotDefault(&as->parms[0].items);
2808 for(ti=as->parms[0].items; ti; ti=ti->next) {
2810 afs_uint32 filetype;
2811 char cell[CELL_MAXNAMELEN];
2814 memset(&fid, 0, sizeof(fid));
2815 memset(&options, 0, sizeof(options));
2817 options.size = sizeof(options);
2818 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
2819 options.literal = literal;
2820 blob.in_size = options.size; /* no variable length data */
2823 blob.out_size = sizeof(cm_fid_t);
2824 blob.out = (char *) &fid;
2825 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
2826 blob.out_size == sizeof(cm_fid_t)) {
2827 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
2830 Die(errno, ti->data);
2835 blob.out_size = sizeof(filetype);
2836 blob.out = &filetype;
2838 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
2839 if (code || blob.out_size != sizeof(filetype)) {
2840 Die(errno, ti->data);
2844 blob.out_size = CELL_MAXNAMELEN;
2847 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
2849 if (errno == ENOENT)
2850 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2852 Die(errno, ti->data);
2856 cell[CELL_MAXNAMELEN - 1] = '\0';
2857 printf("%s %s lives in cell '%s'\n",
2858 filetypestr(filetype),
2865 WSCellCmd(struct cmd_syndesc *as, void *arock)
2868 struct ViceIoctl blob;
2872 blob.out_size = AFS_PIOCTL_MAXSIZE;
2875 code = pioctl_utf8(NULL, VIOC_GET_WS_CELL, &blob, 1);
2881 space[AFS_PIOCTL_MAXSIZE - 1] = '\0';
2882 printf("This workstation belongs to cell '%s'\n", space);
2888 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
2890 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2895 #ifndef AFS_NT40_ENV
2897 MonitorCmd(struct cmd_syndesc *as, void *arock)
2900 struct ViceIoctl blob;
2901 struct cmd_item *ti;
2903 struct hostent *thp;
2907 ti = as->parms[0].items;
2911 if (!strcmp(ti->data, "off")) {
2912 hostAddr = 0xffffffff;
2914 thp = hostutil_GetHostByName(ti->data);
2916 if (!strcmp(ti->data, "localhost")) {
2917 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2918 hostAddr = htonl(0x7f000001);
2920 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2924 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2928 hostAddr = 0; /* means don't set host */
2929 setp = 0; /* aren't setting host */
2932 /* now do operation */
2933 blob.in_size = sizeof(afs_int32);
2934 blob.out_size = sizeof(afs_int32);
2935 blob.in = (char *) &hostAddr;
2936 blob.out = (char *) &hostAddr;
2937 code = pioctl_utf8(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2938 if (code || blob.out_size != sizeof(afs_int32)) {
2943 printf("%s: new monitor host set.\n", pn);
2945 /* now decode old address */
2946 if (hostAddr == 0xffffffff) {
2947 printf("Cache monitoring is currently disabled.\n");
2949 tp = hostutil_GetNameByINet(hostAddr);
2950 printf("Using host %s for monitor services.\n", tp);
2955 #endif /* AFS_NT40_ENV */
2958 SysNameCmd(struct cmd_syndesc *as, void *arock)
2961 struct ViceIoctl blob;
2962 struct cmd_item *ti;
2963 char *input = space;
2966 ti = as->parms[0].items;
2970 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2975 fprintf (stderr,"Permission denied: requires root access.\n");
2983 blob.out_size = AFS_PIOCTL_MAXSIZE;
2984 blob.in_size = sizeof(afs_int32);
2985 memcpy(input, &setp, sizeof(afs_int32));
2986 input += sizeof(afs_int32);
2987 for (; ti; ti = ti->next) {
2989 blob.in_size += (long)strlen(ti->data) + 1;
2990 if (blob.in_size > AFS_PIOCTL_MAXSIZE) {
2991 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2992 setp > 1 ? "s" : "");
2995 strcpy(input, ti->data);
2996 input += strlen(ti->data);
2999 memcpy(space, &setp, sizeof(afs_int32));
3000 code = pioctl_utf8(0, VIOC_AFS_SYSNAME, &blob, 1);
3006 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
3011 memcpy(&setp, input, sizeof(afs_int32));
3012 input += sizeof(afs_int32);
3014 fprintf(stderr,"No sysname name value was found\n");
3017 space[blob.out_size - 1] = '\0';
3018 printf("Current sysname%s is", setp > 1 ? " list" : "");
3019 for (; setp > 0; --setp ) {
3020 printf(" \'%s\'", input);
3021 input += strlen(input) + 1;
3027 #ifndef AFS_NT40_ENV
3028 static char *exported_types[] = {"null", "nfs", ""};
3029 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
3032 struct ViceIoctl blob;
3033 struct cmd_item *ti;
3034 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
3035 int exportcall, pwsync = 0, smounts = 0;
3039 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3044 fprintf (stderr,"Permission denied: requires root access.\n");
3049 ti = as->parms[0].items;
3050 if (strcmp(ti->data, "nfs") == 0)
3051 type = 0x71; /* NFS */
3054 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
3057 ti = as->parms[1].items;
3059 if (strcmp(ti->data, "on") == 0)
3061 else if (strcmp(ti->data, "off") == 0)
3064 fprintf(stderr, "Illegal argument %s\n", ti->data);
3069 if (ti = as->parms[2].items) { /* -noconvert */
3070 if (strcmp(ti->data, "on") == 0)
3072 else if (strcmp(ti->data, "off") == 0)
3075 fprintf(stderr, "Illegal argument %s\n", ti->data);
3079 if (ti = as->parms[3].items) { /* -uidcheck */
3080 if (strcmp(ti->data, "on") == 0)
3082 else if (strcmp(ti->data, "off") == 0)
3085 fprintf(stderr, "Illegal argument %s\n", ti->data);
3089 if (ti = as->parms[4].items) { /* -submounts */
3090 if (strcmp(ti->data, "on") == 0)
3092 else if (strcmp(ti->data, "off") == 0)
3095 fprintf(stderr, "Illegal argument %s\n", ti->data);
3099 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
3102 blob.in = (char *) &exportcall;
3103 blob.in_size = sizeof(afs_int32);
3104 blob.out = (char *) &exportcall;
3105 blob.out_size = sizeof(afs_int32);
3106 code = pioctl_utf8(0, VIOC_EXPORTAFS, &blob, 1);
3108 if (errno == ENODEV) {
3110 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
3117 if (exportcall & 1) {
3118 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
3119 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
3120 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
3121 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
3123 printf("'%s' translator is disabled\n", exported_types[type]);
3132 GetCellCmd(struct cmd_syndesc *as, void *arock)
3135 struct ViceIoctl blob;
3136 struct afsconf_cell info;
3137 struct cmd_item *ti;
3144 memset(&info, 0, sizeof(info));
3145 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3146 for(ti=as->parms[0].items; ti; ti=ti->next) {
3148 blob.out_size = sizeof(args);
3149 blob.out = (caddr_t) &args;
3150 code = GetCellName(ti->data, &info);
3155 if (info.linkedCell)
3156 free(info.linkedCell);
3157 blob.in_size = 1+(long)strlen(info.name);
3158 blob.in = info.name;
3159 code = pioctl_utf8(0, VIOC_GETCELLSTATUS, &blob, 1);
3161 if (errno == ENOENT)
3162 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3164 Die(errno, info.name);
3168 printf("Cell %s status: ", info.name);
3174 printf("no setuid allowed");
3176 printf("setuid allowed");
3178 printf(", using old VLDB");
3184 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3187 struct ViceIoctl blob;
3188 struct afsconf_cell info;
3189 struct cmd_item *ti;
3197 memset(&info, 0, sizeof(info));
3199 /* Check arguments. */
3200 if (as->parms[1].items && as->parms[2].items) {
3201 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3205 /* figure stuff to set */
3211 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3216 fprintf (stderr,"Permission denied: requires root access.\n");
3221 if (! as->parms[1].items)
3222 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3224 /* set stat for all listed cells */
3225 for(ti=as->parms[0].items; ti; ti=ti->next) {
3227 code = GetCellName(ti->data, &info);
3232 if (info.linkedCell)
3233 free(info.linkedCell);
3234 strcpy(args.cname, info.name);
3235 blob.in_size = sizeof(args);
3236 blob.in = (caddr_t) &args;
3238 blob.out = (caddr_t) 0;
3239 code = pioctl_utf8(0, VIOC_SETCELLSTATUS, &blob, 1);
3241 Die(errno, info.name); /* XXX added cell name to Die() call */
3249 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3251 strcpy(infop->name, cellNamep);
3256 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3261 cm_GetConfigDir(confDir, sizeof(confDir));
3263 code = ugen_ClientInit(noAuthFlag, confDir,
3264 info->name, 0, &uclient,
3265 NULL, pn, rxkad_clear,
3266 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3267 0, 0, USER_SERVICE_ID);
3272 static struct ViceIoctl gblob;
3273 static int debug = 0;
3275 * here follow some routines in suport of the setserverprefs and
3276 * getserverprefs commands. They are:
3277 * SetPrefCmd "top-level" routine
3278 * addServer adds a server to the list of servers to be poked into the
3279 * kernel. Will poke the list into the kernel if it threatens
3281 * pokeServers pokes the existing list of servers and ranks into the kernel
3282 * GetPrefCmd reads the Cache Manager's current list of server ranks
3291 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3293 ssp = (cm_SSetPref_t *)space;
3294 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3300 * returns -1 if error message printed,
3302 * errno value if error and no error message printed
3309 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3310 if (code && (errno == EINVAL)) {
3311 struct setspref *ssp;
3312 ssp = (struct setspref *)gblob.in;
3313 if (!(ssp->flags & DBservers)) {
3314 gblob.in = (void *)&(ssp->servers[0]);
3315 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3316 code = pioctl_utf8(0, VIOC_SETSPREFS33, &gblob, 1);
3317 return code ? errno : 0;
3320 "This cache manager does not support VL server preferences.\n");
3324 return code ? errno : 0;
3330 addServer(char *name, unsigned short rank)
3335 struct hostent *thostent;
3339 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3341 #define MAXUSHORT ((unsigned short) ~0)
3346 thostent = hostutil_GetHostByName(name);
3348 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3352 ssp = (cm_SSetPref_t *)(gblob.in);
3354 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3355 code = pokeServers();
3356 ssp->num_servers = 0;
3359 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3360 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3361 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3362 gblob.in_size += sizeof(cm_SPref_t);
3365 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3371 * returns -1 if error message printed,
3373 * errno value if error and no error message printed
3376 addServer(char *name, afs_int32 rank)
3379 struct setspref *ssp;
3381 struct hostent *thostent;
3387 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3389 #define MAXUSHORT ((unsigned short) ~0)
3393 thostent = hostutil_GetHostByName(name);
3395 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3399 ssp = (struct setspref *)(gblob.in);
3401 for (t = 0; thostent->h_addr_list[t]; t++) {
3402 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3403 code = pokeServers();
3406 ssp->num_servers = 0;
3409 sp = (struct spref *)(gblob.in + gblob.in_size);
3410 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3411 sizeof(afs_uint32));
3412 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3413 gblob.in_size += sizeof(struct spref);
3417 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3418 name, sp->rank, sp->server.s_addr);
3426 static BOOL IsWindowsNT (void)
3428 static BOOL fChecked = FALSE;
3429 static BOOL fIsWinNT = FALSE;
3433 OSVERSIONINFO Version;
3437 memset (&Version, 0x00, sizeof(Version));
3438 Version.dwOSVersionInfoSize = sizeof(Version);
3440 if (GetVersionEx (&Version))
3442 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3452 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3456 struct cmd_item *ti;
3461 ssp = (cm_SSetPref_t *)space;
3463 ssp->num_servers = 0;
3464 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3467 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3470 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3476 ti = as->parms[2].items; /* -file */
3478 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3479 if (!(infd = fopen(ti->data,"r" ))) {
3481 Die(errno,ti->data);
3484 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3485 code = addServer (name, (unsigned short) rank);
3489 ti = as->parms[3].items; /* -stdin */
3491 while ( scanf("%79s%ld", name, &rank) != EOF) {
3492 code = addServer (name, (unsigned short) rank);
3496 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3501 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3503 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3507 code = pokeServers();
3509 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3511 ssp = (cm_SSetPref_t *)space;
3512 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3514 ssp->flags = CM_SPREF_VLONLY;
3515 ssp->num_servers = 0;
3517 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3522 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3524 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3529 if (as->parms[1].items) {
3531 printf("now poking vlservers\n");
3532 code = pokeServers();
3542 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3546 struct cmd_item *ti;
3549 struct setspref *ssp;
3550 int error = 0; /* -1 means error message printed,
3551 * >0 means errno value for unprinted message */
3553 ssp = (struct setspref *)space;
3555 ssp->num_servers = 0;
3556 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3559 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3563 fprintf(stderr, "Permission denied: requires root access.\n");
3567 ti = as->parms[2].items; /* -file */
3570 fprintf(stderr, "opening file %s\n", ti->data);
3571 if (!(infd = fopen(ti->data, "r"))) {
3575 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3576 code = addServer(name, (unsigned short)rank);
3583 ti = as->parms[3].items; /* -stdin */
3585 while (scanf("%79s%ld", name, &rank) != EOF) {
3586 code = addServer(name, (unsigned short)rank);
3592 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3597 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3601 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3605 code = pokeServers();
3609 printf("now working on vlservers, code=%d\n", code);
3611 ssp = (struct setspref *)space;
3612 ssp->flags = DBservers;
3613 ssp->num_servers = 0;
3614 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3617 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3622 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3626 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3631 if (as->parms[1].items) {
3633 printf("now poking vlservers\n");
3634 code = pokeServers();
3642 return error ? 1 : 0;
3648 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3651 struct cmd_item *ti;
3652 char *name, tbuffer[20];
3657 struct ViceIoctl blob;
3658 struct cm_SPrefRequest *in;
3659 struct cm_SPrefInfo *out;
3663 ti = as->parms[0].items; /* -file */
3665 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3666 if (!(outfd = freopen(ti->data,"w",stdout))) {
3667 Die(errno,ti->data);
3672 ti = as->parms[1].items; /* -numeric */
3674 ti = as->parms[2].items; /* -vlservers */
3675 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3676 /* ti = as->parms[3].items; -cell */
3678 in = (struct cm_SPrefRequest *)space;
3682 blob.in_size=sizeof(struct cm_SPrefRequest);
3683 blob.in = (char *)in;
3685 blob.out_size = AFS_PIOCTL_MAXSIZE;
3687 in->num_servers = (AFS_PIOCTL_MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3688 in->flags = vlservers;
3690 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3692 perror("getserverprefs pioctl");
3696 out = (struct cm_SPrefInfo *) blob.out;
3698 for (i=0;i<out->num_servers;i++) {
3700 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3703 addr = ntohl(out->servers[i].host.s_addr);
3704 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3705 (addr>>8) & 0xff, addr & 0xff);
3708 printf ("%-50s %5u\n",name,out->servers[i].rank);
3711 in->offset = out->next_offset;
3713 } while (!code && out->next_offset > 0);
3719 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3722 struct cmd_item *ti;
3723 char *name, tbuffer[20];
3724 afs_int32 rank, addr;
3728 struct ViceIoctl blob;
3729 struct sprefrequest *in;
3730 struct sprefinfo *out;
3733 ti = as->parms[0].items; /* -file */
3736 fprintf(stderr, "opening file %s\n", ti->data);
3737 if (!(outfd = freopen(ti->data, "w", stdout))) {
3743 ti = as->parms[1].items; /* -numeric */
3745 ti = as->parms[2].items; /* -vlservers */
3746 vlservers |= (ti ? DBservers : 0);
3747 /* ti = as->parms[3].items; -cell */
3749 in = (struct sprefrequest *)space;
3753 blob.in_size = sizeof(struct sprefrequest);
3754 blob.in = (char *)in;
3756 blob.out_size = AFS_PIOCTL_MAXSIZE;
3759 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3760 in->flags = vlservers;
3762 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3764 perror("getserverprefs pioctl");
3768 out = (struct sprefinfo *)blob.out;
3770 for (i = 0; i < out->num_servers; i++) {
3772 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3774 addr = ntohl(out->servers[i].server.s_addr);
3775 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3776 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3779 printf("%-50s %5u\n", name, out->servers[i].rank);
3782 in->offset = out->next_offset;
3783 } while (out->next_offset > 0);
3790 SmbUnicodeCmd(struct cmd_syndesc * asp, void * arock)
3796 struct ViceIoctl blob;
3798 if (asp->parms[0].items) {
3802 } else if (asp->parms[1].items) {
3808 if (inValue != 0 && !IsAdmin()) {
3809 fprintf (stderr, "Permission denied: Requires AFS Client Administrator access.\n");
3813 blob.in_size = sizeof(inValue);
3814 blob.in = (char *) &inValue;
3815 blob.out_size = sizeof(outValue);
3816 blob.out = (char *) &outValue;
3818 code = pioctl_utf8(NULL, VIOC_UNICODECTL, &blob, 1);
3824 if (outValue != 2) {
3825 printf("Unicode support is %s%s.\n",
3826 ((outValue != 0)? "enabled":"disabled"),
3827 ((inValue != 0)? " for new SMB connections":""));
3829 printf("Unicode support is absent in this installation of OpenAFS.\n");
3836 GetFidCmd(struct cmd_syndesc *as, void *arock)
3839 struct ViceIoctl blob;
3840 struct cmd_item *ti;
3843 cm_ioctlQueryOptions_t options;
3845 if (as->parms[1].items)
3848 SetDotDefault(&as->parms[0].items);
3849 for(ti=as->parms[0].items; ti; ti=ti->next) {
3851 afs_uint32 filetype;
3852 char cell[CELL_MAXNAMELEN];
3855 memset(&fid, 0, sizeof(fid));
3856 memset(&options, 0, sizeof(options));
3858 options.size = sizeof(options);
3859 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
3860 options.literal = literal;
3861 blob.in_size = options.size; /* no variable length data */
3864 blob.out_size = sizeof(cm_fid_t);
3865 blob.out = (char *) &fid;
3866 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
3867 blob.out_size == sizeof(cm_fid_t)) {
3868 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
3871 Die(errno, ti->data);
3876 blob.out_size = sizeof(filetype);
3877 blob.out = &filetype;
3879 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
3880 if (code || blob.out_size != sizeof(filetype)) {
3881 Die(errno, ti->data);
3885 blob.out_size = CELL_MAXNAMELEN;
3888 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
3890 cell[CELL_MAXNAMELEN - 1] = '\0';
3891 printf("%s %s (%u.%u.%u) contained in cell %s\n",
3892 filetypestr(filetype),
3893 ti->data, fid.volume, fid.vnode, fid.unique,
3894 code ? "unknown-cell" : cell);
3900 UuidCmd(struct cmd_syndesc *asp, void *arock)
3905 struct ViceIoctl blob;
3906 char * uuidstring = NULL;
3908 if (asp->parms[0].items) {
3911 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3916 fprintf (stderr, "Permission denied: requires root access.\n");
3920 inValue = 1; /* generate new UUID */
3922 inValue = 0; /* just show the current UUID */
3925 blob.in_size = sizeof(inValue);
3926 blob.in = (char *) &inValue;
3927 blob.out_size = sizeof(outValue);
3928 blob.out = (char *) &outValue;
3930 code = pioctl_utf8(NULL, VIOC_UUIDCTL, &blob, 1);
3931 if (code || blob.out_size != sizeof(outValue)) {
3936 UuidToString((UUID *) &outValue, &uuidstring);
3938 printf("%sUUID: %s",
3939 ((inValue == 1)?"New ":""),
3943 RpcStringFree(&uuidstring);
3949 TraceCmd(struct cmd_syndesc *asp, void *arock)
3952 struct ViceIoctl blob;
3958 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3963 fprintf (stderr,"Permission denied: requires root access.\n");
3968 if ((asp->parms[0].items && asp->parms[1].items)) {
3969 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
3973 /* determine if we're turning this tracing on or off */
3975 if (asp->parms[0].items)
3976 inValue = 3; /* enable */
3977 else if (asp->parms[1].items)
3978 inValue = 2; /* disable */
3979 if (asp->parms[2].items)
3980 inValue |= 4; /* do reset */
3981 if (asp->parms[3].items)
3982 inValue |= 8; /* dump */
3984 blob.in_size = sizeof(long);
3985 blob.in = (char *) &inValue;
3986 blob.out_size = sizeof(long);
3987 blob.out = (char *) &outValue;
3989 code = pioctl_utf8(NULL, VIOC_TRACECTL, &blob, 1);
3990 if (code || blob.out_size != sizeof(long)) {
3996 printf("AFS tracing enabled.\n");
3998 printf("AFS tracing disabled.\n");
4003 static void sbusage(void)
4005 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
4006 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
4009 /* fs sb -kbytes 9999 -files *.o -default 64 */
4011 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
4014 struct ViceIoctl blob;
4015 struct cmd_item *ti;
4016 struct sbstruct tsb, tsb2;
4024 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4029 tsb.sb_thisfile = -1;
4030 ti = as->parms[0].items; /* -kbytes */
4032 if (!as->parms[1].items) {
4033 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
4037 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
4038 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
4039 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
4045 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
4046 ti = as->parms[2].items; /* -allfiles */
4048 allfiles = strtol(ti->data, &t, 10) * 1024;
4049 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
4050 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
4056 /* -verbose or -file only or no options */
4057 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
4058 || (!as->parms[0].items && !as->parms[1].items
4059 && !as->parms[2].items))
4062 blob.in = (char *)&tsb;
4063 blob.out = (char *)&tsb2;
4064 blob.in_size = blob.out_size = sizeof(struct sbstruct);
4065 memset(&tsb2, 0, sizeof(tsb2));
4067 /* once per -file */
4068 for (ti = as->parms[1].items; ti; ti = ti->next) {
4069 /* Do this solely to see if the file is there */
4070 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
4072 Die(errno, ti->data);
4077 code = pioctl_utf8(ti->data, VIOC_STOREBEHIND, &blob, 1);
4079 Die(errno, ti->data);
4084 if (verbose && (blob.out_size == sizeof(tsb2))) {
4085 if (tsb2.sb_thisfile == -1) {
4086 fprintf(stdout, "Will store %s according to default.\n",
4090 "Will store up to %d kbytes of %s asynchronously.\n",
4091 (tsb2.sb_thisfile / 1024), ti->data);
4096 /* If no files - make at least one pioctl call, or
4097 * set the allfiles default if we need to.
4099 if (!as->parms[1].items || (allfiles != -1)) {
4100 tsb.sb_default = allfiles;
4101 code = pioctl_utf8(0, VIOC_STOREBEHIND, &blob, 1);
4103 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
4108 /* Having no arguments also reports the default store asynchrony */
4109 if (verbose && (blob.out_size == sizeof(tsb2))) {
4110 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
4111 (tsb2.sb_default / 1024));
4118 SetCryptCmd(struct cmd_syndesc *as, void *arock)
4120 afs_int32 code = 0, flag;
4121 struct ViceIoctl blob;
4126 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4131 tp = as->parms[0].items->data;
4132 if (strcmp(tp, "on") == 0)
4134 else if (strcmp(tp, "off") == 0)
4136 else if (strcmp(tp, "auth") == 0)
4139 fprintf (stderr, "%s: %s must be \"on\", \"auth\", or \"off\".\n", pn, tp);
4143 blob.in = (char *) &flag;
4144 blob.in_size = sizeof(flag);
4146 code = pioctl_utf8(0, VIOC_SETRXKCRYPT, &blob, 1);
4153 GetCryptCmd(struct cmd_syndesc *as, void *arock)
4155 afs_int32 code = 0, flag;
4156 struct ViceIoctl blob;
4161 blob.out_size = sizeof(flag);
4164 code = pioctl_utf8(0, VIOC_GETRXKCRYPT, &blob, 1);
4166 if (code || blob.out_size != sizeof(flag))
4170 memcpy(&flag, tp, sizeof(afs_int32));
4171 printf("Security level is currently ");
4173 printf("auth (data integrity).\n");
4175 printf("crypt (data security).\n");
4183 MemDumpCmd(struct cmd_syndesc *asp, void *arock)
4186 struct ViceIoctl blob;
4191 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4195 if ((asp->parms[0].items && asp->parms[1].items)) {
4196 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
4200 /* determine if we're turning this tracing on or off */
4201 if (asp->parms[0].items)
4202 inValue = 1; /* begin */
4203 else if (asp->parms[1].items)
4204 inValue = 0; /* end */
4207 blob.in_size = sizeof(long);
4208 blob.in = (char *) &inValue;
4209 blob.out_size = sizeof(long);
4210 blob.out = (char *) &outValue;
4212 code = pioctl_utf8(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
4213 if (code || blob.out_size != sizeof(long)) {
4219 printf("AFS memdump created.\n");
4222 printf("AFS memdump failed.\n");
4228 MiniDumpCmd(struct cmd_syndesc *asp, void *arock)
4231 SERVICE_STATUS status;
4232 SC_HANDLE hManager = NULL;
4233 SC_HANDLE hService = NULL;
4236 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4240 hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
4244 hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
4248 success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
4251 CloseServiceHandle(hService);
4252 CloseServiceHandle(hManager);
4254 printf("AFS minidump generated.\n");
4260 CloseServiceHandle(hService);
4262 CloseServiceHandle(hManager);
4264 printf("AFS minidump failed.\n");
4269 CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
4271 struct cmd_item *ti;
4276 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4280 for(ti=asp->parms[0].items; ti;ti=ti->next) {
4292 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4293 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4296 REG_OPTION_NON_VOLATILE,
4297 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
4302 if ( hkCSCPolicy == NULL ) {
4303 fprintf (stderr,"Permission denied: requires Administrator access.\n");
4308 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4309 RegCloseKey(hkCSCPolicy);
4315 if (asp->parms[1].items)
4317 if (asp->parms[2].items)
4318 policy = "programs";
4319 if (asp->parms[3].items)
4320 policy = "documents";
4321 if (asp->parms[4].items)
4324 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, (DWORD)strlen(policy)+1);
4326 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
4327 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
4331 DWORD dwIndex, dwPolicies;
4332 char policyName[256];
4333 DWORD policyNameLen;
4338 /* list current csc policies */
4340 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4341 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4344 REG_OPTION_NON_VOLATILE,
4345 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_QUERY_VALUE,
4350 RegQueryInfoKey( hkCSCPolicy,
4352 NULL, /* lpcClass */
4353 NULL, /* lpReserved */
4354 NULL, /* lpcSubKeys */
4355 NULL, /* lpcMaxSubKeyLen */
4356 NULL, /* lpcMaxClassLen */
4357 &dwPolicies, /* lpcValues */
4358 NULL, /* lpcMaxValueNameLen */
4359 NULL, /* lpcMaxValueLen */
4360 NULL, /* lpcbSecurityDescriptor */
4361 NULL /* lpftLastWriteTime */
4364 printf("Current CSC policies:\n");
4365 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
4367 policyNameLen = sizeof(policyName);
4368 policyLen = sizeof(policy);
4369 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
4370 &dwType, policy, &policyLen);
4372 printf(" %s = %s\n", policyName, policy);
4376 RegCloseKey(hkCSCPolicy);
4381 /* get clients interface addresses */
4383 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4386 struct cmd_item *ti;
4388 struct ViceIoctl blob;
4389 struct sprefrequest *in;
4390 struct sprefinfo *out;
4392 in = (struct sprefrequest *)space;
4396 blob.in_size = sizeof(struct sprefrequest);
4397 blob.in = (char *)in;
4399 blob.out_size = AFS_PIOCTL_MAXSIZE;
4402 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4403 /* returns addr in network byte order */
4404 code = pioctl_utf8(0, VIOC_GETCPREFS, &blob, 1);
4406 perror("getClientInterfaceAddr pioctl");
4412 out = (struct sprefinfo *)blob.out;
4413 for (i = 0; i < out->num_servers; i++) {
4416 addr = ntohl(out->servers[i].server.s_addr);
4417 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
4418 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
4419 printf("%-50s\n", tbuffer);
4421 in->offset = out->next_offset;
4423 } while (out->next_offset > 0);
4429 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4431 afs_int32 code, addr;
4432 struct cmd_item *ti;
4434 struct ViceIoctl blob;
4435 struct setspref *ssp;
4436 int sizeUsed = 0, i, flag;
4437 afs_int32 existingAddr[1024]; /* existing addresses on this host */
4441 ssp = (struct setspref *)space;
4442 ssp->num_servers = 0;
4445 blob.out_size = AFS_PIOCTL_MAXSIZE;
4448 fprintf(stderr, "Permission denied: requires root access.\n");
4452 /* extract all existing interface addresses */
4453 existNu = rx_getAllAddr(existingAddr, 1024);
4457 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4458 for (ti = as->parms[0].items; ti; ti = ti->next) {
4459 if (sizeUsed >= sizeof(space)) {
4460 fprintf(stderr, "No more space\n");
4463 addr = extractAddr(ti->data, 20); /* network order */
4464 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4465 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4470 /* see if it is an address that really exists */
4471 for (flag = 0, i = 0; i < existNu; i++)
4472 if (existingAddr[i] == addr) {
4476 if (!flag) { /* this is an nonexistent address */
4477 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4481 /* copy all specified addr into ioctl buffer */
4482 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4483 printf("Adding 0x%08x\n", addr);
4485 sizeUsed += sizeof(struct spref);
4487 if (ssp->num_servers < 1) {
4488 fprintf(stderr, "No addresses specified\n");
4491 blob.in_size = sizeUsed - sizeof(struct spref);
4493 code = pioctl_utf8(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4503 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4506 struct ViceIoctl blob;
4507 struct cmd_item *ti;
4508 char orig_name[1024]; /*Original name, may be modified */
4509 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4510 char parent_dir[1024]; /*Parent directory of true name */
4511 char *last_component; /*Last component of true name */
4512 struct stat statbuff; /*Buffer for status info */
4513 int link_chars_read; /*Num chars read in readlink() */
4514 int thru_symlink; /*Did we get to a mount point via a symlink? */
4517 for (ti = as->parms[0].items; ti; ti = ti->next) {
4520 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4523 if (lstat(orig_name, &statbuff) < 0) {
4524 /* if lstat fails, we should still try the pioctl, since it
4525 * may work (for example, lstat will fail, but pioctl will
4526 * work if the volume of offline (returning ENODEV). */
4527 statbuff.st_mode = S_IFDIR; /* lie like pros */
4531 * The lstat succeeded. If the given file is a symlink, substitute
4532 * the file name with the link name.
4534 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4537 * Read name of resolved file.
4539 link_chars_read = readlink(orig_name, true_name, 1024);
4540 if (link_chars_read <= 0) {
4542 "%s: Can't read target name for '%s' symbolic link!\n",
4549 * Add a trailing null to what was read, bump the length.
4551 true_name[link_chars_read++] = 0;
4554 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4555 * have to create a full pathname using the original name and the
4556 * relative symlink name. Find the rightmost slash in the original
4557 * name (we know there is one) and splice in the symlink value.
4559 if (true_name[0] != '/') {
4560 last_component = (char *)strrchr(orig_name, '/');
4561 strcpy(++last_component, true_name);
4562 strcpy(true_name, orig_name);
4565 strcpy(true_name, orig_name);
4568 * Find rightmost slash, if any.
4570 last_component = (char *)strrchr(true_name, '/');
4571 if (last_component) {
4573 * Found it. Designate everything before it as the parent directory,
4574 * everything after it as the final component.
4576 strncpy(parent_dir, true_name, last_component - true_name);
4577 parent_dir[last_component - true_name] = 0;
4578 last_component++; /*Skip the slash */
4581 * No slash appears in the given file name. Set parent_dir to the current
4582 * directory, and the last component as the given name.
4584 strcpy(parent_dir, ".");
4585 last_component = true_name;
4588 if (strcmp(last_component, ".") == 0
4589 || strcmp(last_component, "..") == 0) {
4591 "%s: you may not use '.' or '..' as the last component\n",
4593 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4599 blob.in = last_component;
4600 blob.in_size = strlen(last_component) + 1;
4602 memset(space, 0, AFS_PIOCTL_MAXSIZE);
4604 code = pioctl_utf8(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4607 if (errno == EINVAL) {
4608 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4610 Die(errno, (ti->data ? ti->data : parent_dir));
4620 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4623 afs_int32 flags = 0;
4624 struct ViceIoctl blob;
4626 if (as->parms[0].items) { /* -enable */
4627 flags |= AFSCALL_RXSTATS_ENABLE;
4629 if (as->parms[1].items) { /* -disable */
4630 flags |= AFSCALL_RXSTATS_DISABLE;
4632 if (as->parms[2].items) { /* -clear */
4633 flags |= AFSCALL_RXSTATS_CLEAR;
4636 fprintf(stderr, "You must specify at least one argument\n");
4640 blob.in = (char *)&flags;
4641 blob.in_size = sizeof(afs_int32);
4644 code = pioctl_utf8(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4654 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4657 afs_int32 flags = 0;
4658 struct ViceIoctl blob;
4660 if (as->parms[0].items) { /* -enable */
4661 flags |= AFSCALL_RXSTATS_ENABLE;
4663 if (as->parms[1].items) { /* -disable */
4664 flags |= AFSCALL_RXSTATS_DISABLE;
4666 if (as->parms[2].items) { /* -clear */
4667 flags |= AFSCALL_RXSTATS_CLEAR;
4670 fprintf(stderr, "You must specify at least one argument\n");
4674 blob.in = (char *)&flags;
4675 blob.in_size = sizeof(afs_int32);
4678 code = pioctl_utf8(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4688 TestVolStatCmd(struct cmd_syndesc *as, void *arock)
4691 struct VolStatTest test;
4692 struct ViceIoctl blob;
4696 memset(&test, 0, sizeof(test));
4698 if (as->parms[0].items) { /* -network */
4699 tp = as->parms[0].items->data;
4700 if (strcmp(tp, "up") == 0)
4701 test.flags |= VOLSTAT_TEST_NETWORK_UP;
4702 else if (strcmp(tp, "down") == 0)
4703 test.flags |= VOLSTAT_TEST_NETWORK_DOWN;
4705 fprintf (stderr, "%s: %s must be \"up\" or \"down\".\n", pn, tp);
4709 if (as->parms[1].items) { /* check */
4710 test.flags |= VOLSTAT_TEST_CHECK_VOLUME;
4712 if (as->parms[2].items) { /* cell */
4713 tp = as->parms[2].items->data;
4718 strncpy(test.cellname, tp, sizeof(test.cellname));
4719 test.cellname[sizeof(test.cellname)-1] = '\0';
4722 if (as->parms[3].items) { /* volume */
4723 tp = as->parms[3].items->data;
4726 test.fid.volume = n;
4728 strncpy(test.volname, tp, sizeof(test.volname));
4729 test.volname[sizeof(test.volname)-1] = '\0';
4732 if (as->parms[4].items) { /* state */
4733 tp = as->parms[4].items->data;
4734 if (strcmp(tp, "online") == 0)
4735 test.state = vl_online;
4736 else if (strcmp(tp, "busy") == 0)
4737 test.state = vl_busy;
4738 else if (strcmp(tp, "offline") == 0)
4739 test.state = vl_offline;
4740 else if (strcmp(tp, "down") == 0)
4741 test.state = vl_alldown;
4743 fprintf (stderr, "%s: %s must be \"online\", \"busy\", \"offline\" or \"down\".\n", pn, tp);
4748 if ((test.fid.cell || test.cellname[0]) && !(test.fid.volume || test.volname[0]) ||
4749 !(test.fid.cell || test.cellname[0]) && (test.fid.volume || test.volname[0])) {
4750 fprintf (stderr, "%s: both a cell and a volume must be specified.\n", pn, tp);
4754 blob.in = (char *)&test;
4755 blob.in_size = sizeof(test);
4758 code = pioctl_utf8(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
4768 ChOwnCmd(struct cmd_syndesc *as, void *arock)
4771 struct ViceIoctl blob;
4772 struct cmd_item *ti;
4776 cm_ioctlQueryOptions_t options;
4783 cm_GetConfigDir(confDir, sizeof(confDir));
4785 if (as->parms[2].items)
4788 ownerStr = as->parms[0].items->data;
4789 ownerId = atoi(ownerStr);
4791 SetDotDefault(&as->parms[1].items);
4792 for(ti=as->parms[1].items; ti; ti=ti->next) {
4794 afs_uint32 filetype;
4795 char cell[CELL_MAXNAMELEN];
4798 memset(&fid, 0, sizeof(fid));
4799 memset(&inData, 0, sizeof(inData));
4801 inData.options.size = sizeof(inData.options);
4802 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
4803 inData.options.literal = literal;
4804 blob.in_size = inData.options.size; /* no variable length data */
4807 blob.out_size = sizeof(cm_fid_t);
4808 blob.out = (char *) &fid;
4809 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
4810 blob.out_size == sizeof(cm_fid_t)) {
4811 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
4812 inData.options.fid = fid;
4814 Die(errno, ti->data);
4820 * if the owner was specified as a numeric value,
4821 * then we can just use it. Otherwise, we need
4822 * to know the cell of the path to determine which
4823 * ptserver to contact in order to convert the name
4824 * to a numeric value.
4827 blob.out_size = CELL_MAXNAMELEN;
4830 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
4832 Die(errno, ti->data);
4836 cell[CELL_MAXNAMELEN - 1] = '\0';
4838 * We now know the cell for the target and we need to
4839 * convert the ownerStr to the Id for this user
4841 pr_Initialize(1, confDir, cell);
4842 code = pr_SNameToId(ownerStr, &inData.owner);
4845 if (code || inData.owner == ANONYMOUSID ) {
4846 Die(ECHILD, ti->data);
4851 inData.owner = ownerId;
4854 blob.in_size = sizeof(inData);
4857 code = pioctl_utf8(ti->data, VIOC_SETOWNER, &blob, 1);
4859 Die(errno, ti->data);
4866 ChGrpCmd(struct cmd_syndesc *as, void *arock)
4869 struct ViceIoctl blob;
4870 struct cmd_item *ti;
4874 cm_ioctlQueryOptions_t options;
4881 cm_GetConfigDir(confDir, sizeof(confDir));
4883 if (as->parms[2].items)
4886 groupStr = as->parms[0].items->data;
4887 groupId = atoi(groupStr);
4889 SetDotDefault(&as->parms[1].items);
4890 for(ti=as->parms[1].items; ti; ti=ti->next) {
4892 afs_uint32 filetype;
4893 char cell[CELL_MAXNAMELEN];
4896 memset(&fid, 0, sizeof(fid));
4897 memset(&inData, 0, sizeof(inData));
4899 inData.options.size = sizeof(inData.options);
4900 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
4901 inData.options.literal = literal;
4902 blob.in_size = inData.options.size; /* no variable length data */
4905 blob.out_size = sizeof(cm_fid_t);
4906 blob.out = (char *) &fid;
4907 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
4908 blob.out_size == sizeof(cm_fid_t)) {
4909 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
4910 inData.options.fid = fid;
4912 Die(errno, ti->data);
4918 * if the group was specified as a numeric value,
4919 * then we can just use it. Otherwise, we need
4920 * to know the cell of the path to determine which
4921 * ptserver to contact in order to convert the name
4922 * to a numeric value.
4925 blob.out_size = CELL_MAXNAMELEN;
4928 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
4930 Die(errno, ti->data);
4934 cell[CELL_MAXNAMELEN - 1] = '\0';
4936 * We now know the cell for the target and we need to
4937 * convert the groupStr to the Id for this user
4939 pr_Initialize(1, confDir, cell);
4940 code = pr_SNameToId(groupStr, &inData.group);
4943 if (code || inData.group == ANONYMOUSID ) {
4944 Die(ECHILD, ti->data);
4949 inData.group = groupId;
4952 blob.in_size = sizeof(inData);
4955 code = pioctl_utf8(ti->data, VIOC_SETGROUP, &blob, 1);
4957 Die(errno, ti->data);
4964 #include "AFS_component_version_number.c"
4968 FreeUtf8CmdLine(int argc, char ** argv)
4971 for (i=0; i < argc; i++) {
4979 MakeUtf8Cmdline(int argc, const wchar_t **wargv)
4984 argv = calloc(argc, sizeof(argv[0]));
4988 for (i=0; i < argc; i++) {
4991 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, FALSE);
4993 (argv[i] = calloc(s+1, sizeof(char))) == NULL) {
4997 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], s+1, NULL, FALSE);
5004 FreeUtf8CmdLine(argc, argv);
5011 int wmain(int argc, wchar_t **wargv)
5014 struct cmd_syndesc *ts;
5017 #ifdef AFS_AIX32_ENV
5019 * The following signal action for AIX is necessary so that in case of a
5020 * crash (i.e. core is generated) we can include the user's data section
5021 * in the core dump. Unfortunately, by default, only a partial core is
5022 * generated which, in many cases, isn't too useful.
5024 struct sigaction nsa;
5026 sigemptyset(&nsa.sa_mask);
5027 nsa.sa_handler = SIG_DFL;
5028 nsa.sa_flags = SA_FULLDUMP;
5029 sigaction(SIGSEGV, &nsa, NULL);
5034 WSAStartup(0x0101, &WSAjunk);
5037 argv = MakeUtf8Cmdline(argc, wargv);
5039 /* try to find volume location information */
5043 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
5044 "get client network interface addresses");
5045 cmd_CreateAlias(ts, "gc");
5047 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
5048 "set client network interface addresses");
5049 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
5050 "client network interfaces");
5051 cmd_CreateAlias(ts, "sc");
5054 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL, "set server ranks");
5055 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
5056 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
5057 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
5058 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
5059 cmd_CreateAlias(ts, "sp");
5061 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL, "get server ranks");
5062 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
5063 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
5064 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
5065 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
5066 cmd_CreateAlias(ts, "gp");
5068 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
5069 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5070 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
5071 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
5072 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
5073 parm_setacl_id = ts->nParms;
5074 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
5075 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
5076 cmd_CreateAlias(ts, "sa");
5078 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL, "list access control list");
5079 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5080 parm_listacl_id = ts->nParms;
5081 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
5082 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
5083 cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
5084 cmd_CreateAlias(ts, "la");
5086 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL, "clean up access control list");
5087 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5089 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL, "copy access control list");
5090 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
5091 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
5092 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
5093 parm_copyacl_id = ts->nParms;
5094 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
5095 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
5097 cmd_CreateAlias(ts, "ca");
5099 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
5100 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5101 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5104 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
5105 "flush mount symlink from cache");
5106 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5109 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
5110 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5111 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
5113 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
5115 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
5116 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
5117 cmd_CreateAlias(ts, "sv");
5119 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL, "control Cache Manager messages");
5120 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
5122 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
5123 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5124 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5125 cmd_CreateAlias(ts, "lv");
5126 cmd_CreateAlias(ts, "listvol");
5128 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
5129 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5130 cmd_CreateAlias(ts, "lq");
5132 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL, "show server disk space usage");
5133 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5134 cmd_CreateAlias(ts, "df");
5136 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
5137 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5139 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
5140 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5142 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
5143 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
5144 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
5145 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
5146 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
5147 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
5153 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
5157 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
5158 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5160 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL, "check local cell's servers");
5161 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
5162 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
5163 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
5164 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
5166 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL, "check volumeID/name mappings");
5167 cmd_CreateAlias(ts, "checkbackups");
5170 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL, "set cache size");
5171 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
5172 cmd_CreateAlias(ts, "cachesize");
5174 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
5176 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL, "get cache usage info");
5178 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL, "list configured cells");
5179 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
5181 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
5182 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
5183 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
5185 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
5187 cmd_CreateAlias(ts, "sq");
5189 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
5191 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
5192 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
5193 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
5195 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
5197 * Turn this on only if you wish to be able to talk to a server which is listening
5198 * on alternative ports. This is not intended for general use and may not be
5199 * supported in the cache manager. It is not a way to run two servers at the
5200 * same host, since the cache manager cannot properly distinguish those two hosts.
5202 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
5203 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
5206 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
5207 "configure new cell alias");
5208 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
5209 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
5212 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
5213 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5214 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5216 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
5217 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5218 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5220 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
5223 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
5226 #ifndef AFS_NT40_ENV
5227 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, "set cache monitor host address");
5228 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
5229 cmd_CreateAlias(ts, "mariner");
5232 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
5233 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
5235 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
5236 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
5237 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
5238 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
5240 ts = cmd_CreateSyntax("flushall", FlushAllCmd, NULL, "flush all data");
5242 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL, "flush all data in volume");
5243 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5245 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL, "get/set sysname (i.e. @sys) value");
5246 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
5248 #ifndef AFS_NT40_ENV
5249 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL, "enable/disable translators to AFS");
5250 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
5251 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
5252 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
5253 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
5254 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
5257 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
5258 "store to server after file close");
5259 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
5260 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
5261 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
5262 cmd_CreateAlias(ts, "sb");
5264 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL, "set cache manager encryption flag");
5265 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
5267 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL, "get cache manager encryption flag");
5269 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
5270 "Manage per process RX statistics");
5271 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
5272 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
5273 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
5275 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
5276 "Manage per peer RX statistics");
5277 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
5278 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
5279 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
5282 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
5283 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
5286 ts = cmd_CreateSyntax("trace", TraceCmd, NULL, "enable or disable CM tracing");
5287 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
5288 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
5289 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
5290 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
5291 cmd_CreateAlias(ts, "tr");
5293 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
5294 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
5296 ts = cmd_CreateSyntax("memdump", MemDumpCmd, NULL, "dump memory allocs in debug builds");
5297 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
5298 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
5300 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, NULL, "change client side caching policy for AFS shares");
5301 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
5302 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
5303 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
5304 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
5305 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
5307 ts = cmd_CreateSyntax("minidump", MiniDumpCmd, NULL, "Generate MiniDump of current service state");
5309 ts = cmd_CreateSyntax("test_volstat", TestVolStatCmd, NULL, (char *)CMD_HIDDEN);
5310 cmd_AddParm(ts, "-network", CMD_SINGLE, CMD_OPTIONAL, "set network state up or down");
5311 cmd_AddParm(ts, "-check", CMD_FLAG, CMD_OPTIONAL, "check state of offline volumes");
5312 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name or number");
5313 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or number");
5314 cmd_AddParm(ts, "-state", CMD_SINGLE, CMD_OPTIONAL, "new volume state: online, busy, offline, down");
5316 ts = cmd_CreateSyntax("smbunicode", SmbUnicodeCmd, NULL, "enable or disable Unicode on new SMB connections");
5317 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable Unicode on new connections");
5318 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable Unicode on new connections");
5320 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL, "get file id for object(s) in afs");
5321 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5322 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5324 ts = cmd_CreateSyntax("chown", ChOwnCmd, NULL, "set owner for object(s) in afs");
5325 cmd_AddParm(ts, "-owner", CMD_SINGLE, 0, "user name or id");
5326 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5327 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5329 ts = cmd_CreateSyntax("chgrp", ChGrpCmd, NULL, "set owner for object(s) in afs");
5330 cmd_AddParm(ts, "-group", CMD_SINGLE, 0, "user/group name or id");
5331 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5332 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5334 code = cmd_Dispatch(argc, argv);
5339 FreeUtf8CmdLine(argc, argv);
5345 Die(int code, char *filename)
5348 if (code == EINVAL) {
5350 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
5352 fprintf(stderr,"%s: Invalid argument.\n", pn);
5354 else if (code == ENOENT) {
5356 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
5358 fprintf(stderr,"%s: no such file returned\n", pn);
5360 else if (code == EROFS)
5361 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
5362 else if (code == EACCES || code == EPERM) {
5364 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
5366 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
5368 else if (code == ENODEV) {
5369 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
5371 else if (code == ESRCH) { /* hack */
5372 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
5374 else if (code == EPIPE) { /* hack */
5375 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
5377 else if (code == EFBIG) {
5378 fprintf(stderr,"%s: Cache size too large.\n", pn);
5380 else if (code == ETIMEDOUT) {
5382 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
5384 fprintf(stderr,"%s: Connection timed out", pn);
5386 else if (code == EBUSY) {
5388 fprintf(stderr,"%s: All servers are busy on which '%s' resides\n", pn, filename);
5390 fprintf(stderr,"%s: All servers are busy\n", pn);
5392 else if (code == ENXIO) {
5394 fprintf(stderr,"%s: All volume instances are offline on which '%s' resides\n", pn, filename);
5396 fprintf(stderr,"%s: All volume instances are offline\n", pn);
5398 else if (code == ENOSYS) {
5400 fprintf(stderr,"%s: All servers are down on which '%s' resides\n", pn, filename);
5402 fprintf(stderr,"%s: All servers are down\n", pn);
5404 else if (code == ECHILD) { /* hack */
5406 fprintf(stderr,"%s: Invalid owner specified for '%s'\n", pn, filename);
5408 fprintf(stderr,"%s: Invalid owner specified\n", pn);
5412 fprintf(stderr,"%s:'%s'", pn, filename);
5414 fprintf(stderr,"%s", pn);
5416 fprintf(stderr, ": code 0x%x\n", code);
5417 #else /* not WIN32 */
5418 fprintf(stderr,": %s\n", afs_error_message(code));
5419 #endif /* not WIN32 */