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;
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 (%d) Group %s (%d)\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);
1895 * The response is VolumeStatus, volume name, offline message, and motd
1897 if (code || blob.out_size < sizeof(*status)) {
1898 Die(errno, ti->data);
1903 status = (VolumeStatus *)space;
1904 if (status->MaxQuota)
1905 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1908 printf("%2.0f%% of quota used.\n", quotaPct);
1914 ListMountCmd(struct cmd_syndesc *as, void *arock)
1917 struct ViceIoctl blob;
1918 struct cmd_item *ti;
1919 char orig_name[1024]; /*Original name, may be modified*/
1920 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1921 char parent_dir[1024]; /*Parent directory of true name*/
1922 char *last_component; /*Last component of true name*/
1924 struct stat statbuff; /*Buffer for status info*/
1925 #endif /* not WIN32 */
1927 int link_chars_read; /*Num chars read in readlink()*/
1928 #endif /* not WIN32 */
1929 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1932 for(ti=as->parms[0].items; ti; ti=ti->next) {
1936 strcpy(orig_name, ti->data);
1937 #else /* not WIN32 */
1938 sprintf(orig_name, "%s%s",
1939 (ti->data[0] == '/') ? "" : "./",
1941 #endif /* not WIN32 */
1944 if (lstat(orig_name, &statbuff) < 0) {
1945 /* if lstat fails, we should still try the pioctl, since it
1946 * may work (for example, lstat will fail, but pioctl will
1947 * work if the volume of offline (returning ENODEV). */
1948 statbuff.st_mode = S_IFDIR; /* lie like pros */
1952 * The lstat succeeded. If the given file is a symlink, substitute
1953 * the file name with the link name.
1955 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1958 * Read name of resolved file.
1960 link_chars_read = readlink(orig_name, true_name, 1024);
1961 if (link_chars_read <= 0) {
1963 "%s: Can't read target name for '%s' symbolic link!\n",
1970 * Add a trailing null to what was read, bump the length.
1972 true_name[link_chars_read++] = 0;
1975 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1976 * have to create a full pathname using the original name and the
1977 * relative symlink name. Find the rightmost slash in the original
1978 * name (we know there is one) and splice in the symlink value.
1980 if (true_name[0] != '\\') {
1981 last_component = (char *) strrchr(orig_name, '\\');
1982 strcpy(++last_component, true_name);
1983 strcpy(true_name, orig_name);
1986 strcpy(true_name, orig_name);
1988 strcpy(true_name, orig_name);
1992 * Find rightmost slash, if any.
1995 last_component = (char *) strrchr(true_name, '\\');
1996 if (!last_component)
1998 last_component = (char *) strrchr(true_name, '/');
1999 if (last_component) {
2001 * Found it. Designate everything before it as the parent directory,
2002 * everything after it as the final component.
2004 strncpy(parent_dir, true_name, last_component - true_name + 1);
2005 parent_dir[last_component - true_name + 1] = 0;
2006 last_component++; /*Skip the slash*/
2008 if (!InAFS(parent_dir)) {
2009 const char * nbname = NetbiosName();
2010 int len = (int)strlen(nbname);
2012 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
2013 parent_dir[len+2] == '\\' &&
2014 parent_dir[len+3] == '\0' &&
2015 !strnicmp(nbname,&parent_dir[2],len))
2017 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
2023 * No slash appears in the given file name. Set parent_dir to the current
2024 * directory, and the last component as the given name.
2026 fs_ExtractDriveLetter(true_name, parent_dir);
2027 strcat(parent_dir, ".");
2028 last_component = true_name;
2029 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
2032 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
2033 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
2034 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
2039 blob.in = last_component;
2040 blob.in_size = (long)strlen(last_component)+1;
2041 blob.out_size = AFS_PIOCTL_MAXSIZE;
2043 memset(space, 0, AFS_PIOCTL_MAXSIZE);
2045 code = pioctl_utf8(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
2048 printf("'%s' is a %smount point for volume '%.*s'\n",
2050 (thru_symlink ? "symbolic link, leading to a " : ""),
2055 if (errno == EINVAL) {
2056 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
2058 Die(errno, (ti->data ? ti->data : parent_dir));
2067 MakeMountCmd(struct cmd_syndesc *as, void *arock)
2070 char *cellName, *volName, *tmpName;
2072 char localCellName[128];
2074 char path[1024] = "";
2075 struct afsconf_cell info;
2076 struct vldbentry vldbEntry;
2077 struct ViceIoctl blob;
2080 memset(&info, 0, sizeof(info));
2082 if (as->parms[2].items) /* cell name specified */
2083 cellName = as->parms[2].items->data;
2086 volName = as->parms[1].items->data;
2088 if (strlen(volName) >= 64) {
2089 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
2093 /* Check for a cellname in the volume specification, and complain
2094 * if it doesn't match what was specified with -cell */
2095 if (tmpName = strchr(volName, ':')) {
2098 if (strcasecmp(cellName,volName)) {
2099 fprintf(stderr,"fs: cellnames do not match.\n");
2104 volName = ++tmpName;
2107 parent = Parent(as->parms[0].items->data);
2108 if (!InAFS(parent)) {
2110 const char * nbname = NetbiosName();
2111 int len = (int)strlen(nbname);
2113 if (parent[0] == '\\' && parent[1] == '\\' &&
2114 parent[len+2] == '\\' &&
2115 parent[len+3] == '\0' &&
2116 !strnicmp(nbname,&parent[2],len))
2118 sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
2119 parent = Parent(path);
2120 if (!InAFS(parent)) {
2121 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2127 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2132 if ( strlen(path) == 0 )
2133 strcpy(path, as->parms[0].items->data);
2135 if ( IsFreelanceRoot(parent) ) {
2137 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2143 blob.out_size = sizeof(localCellName);
2144 blob.out = localCellName;
2145 code = pioctl_utf8(parent, VIOC_GET_WS_CELL, &blob, 1);
2147 localCellName[sizeof(localCellName) - 1] = '\0';
2148 cellName = localCellName;
2153 code = GetCell(parent,space);
2159 code = GetCellName(cellName?cellName:space, &info);
2163 if (!(as->parms[4].items)) {
2164 /* not fast, check which cell the mountpoint is being created in */
2166 /* not fast, check name with VLDB */
2168 code = VLDBInit(1, &info);
2170 /* make the check. Don't complain if there are problems with init */
2171 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2172 if (code == VL_NOENT) {
2173 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2174 pn, volName, cellName ? cellName : space);
2179 if (as->parms[3].items) /* if -rw specified */
2184 /* cellular mount point, prepend cell prefix */
2185 strcat(space, info.name);
2188 strcat(space, volName); /* append volume name */
2189 strcat(space, "."); /* stupid convention; these end with a period */
2191 /* create symlink with a special pioctl for Windows NT, since it doesn't
2192 * have a symlink system call.
2195 blob.in_size = 1 + (long)strlen(space);
2198 code = pioctl_utf8(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2199 #else /* not WIN32 */
2200 code = symlink(space, path);
2201 #endif /* not WIN32 */
2203 if (info.linkedCell)
2204 free(info.linkedCell);
2214 * Delete AFS mount points. Variables are used as follows:
2215 * tbuffer: Set to point to the null-terminated directory name of the mount point
2216 * (or ``.'' if none is provided)
2217 * tp: Set to point to the actual name of the mount point to nuke.
2220 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2222 struct ViceIoctl blob;
2223 struct cmd_item *ti;
2225 char lsbuffer[1024];
2229 for(ti=as->parms[0].items; ti; ti=ti->next) {
2231 tp = (char *) strrchr(ti->data, '\\');
2233 tp = (char *) strrchr(ti->data, '/');
2235 strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1)); /* the dir name */
2237 tp++; /* skip the slash */
2240 if (!InAFS(tbuffer)) {
2241 const char * nbname = NetbiosName();
2242 int len = (int)strlen(nbname);
2244 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2245 tbuffer[len+2] == '\\' &&
2246 tbuffer[len+3] == '\0' &&
2247 !strnicmp(nbname,&tbuffer[2],len))
2249 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
2254 fs_ExtractDriveLetter(ti->data, tbuffer);
2255 strcat(tbuffer, ".");
2257 fs_StripDriveLetter(tp, tp, 0);
2260 blob.in_size = (long)strlen(tp)+1;
2261 blob.out = lsbuffer;
2262 blob.out_size = sizeof(lsbuffer);
2263 code = pioctl_utf8(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2265 if (errno == EINVAL) {
2266 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2268 Die(errno, ti->data);
2271 continue; /* don't bother trying */
2274 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2275 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2277 continue; /* skip */
2282 blob.in_size = (long)strlen(tp)+1;
2283 code = pioctl_utf8(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2285 Die(errno, ti->data);
2296 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2299 struct ViceIoctl blob;
2303 struct afsconf_cell info;
2304 struct chservinfo checkserv;
2306 memset(&info, 0, sizeof(info));
2307 memset(&checkserv, 0, sizeof(struct chservinfo));
2308 blob.in_size=sizeof(struct chservinfo);
2309 blob.in=(caddr_t)&checkserv;
2311 blob.out_size = AFS_PIOCTL_MAXSIZE;
2313 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2315 /* prepare flags for checkservers command */
2316 temp = 2; /* default to checking local cell only */
2317 if (as->parms[2].items)
2318 temp |= 1; /* set fast flag */
2319 if (as->parms[1].items)
2320 temp &= ~2; /* turn off local cell check */
2322 checkserv.magic = 0x12345678; /* XXX */
2323 checkserv.tflags=temp;
2325 /* now copy in optional cell name, if specified */
2326 if (as->parms[0].items) {
2327 code = GetCellName(as->parms[0].items->data, &info);
2331 strcpy(checkserv.tbuffer,info.name);
2332 checkserv.tsize=(int)strlen(info.name)+1;
2333 if (info.linkedCell)
2334 free(info.linkedCell);
2336 strcpy(checkserv.tbuffer,"\0");
2340 if(as->parms[3].items) {
2341 checkserv.tinterval=atol(as->parms[3].items->data);
2344 if(checkserv.tinterval<0) {
2345 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2346 checkserv.tinterval=-1;
2347 } else if(checkserv.tinterval> 600) {
2348 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2349 checkserv.tinterval=600; /* 10 min max interval */
2352 checkserv.tinterval = -1; /* don't change current interval */
2355 if ( checkserv.tinterval >= 0 ) {
2358 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2363 fprintf (stderr,"Permission denied: requires root access.\n");
2369 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
2371 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2372 printf("Must be root to change -interval\n");
2378 memcpy(&temp, space, sizeof(afs_int32));
2379 if (checkserv.tinterval >= 0) {
2380 if (checkserv.tinterval > 0)
2381 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2382 checkserv.tinterval, temp);
2384 printf("The current down server probe interval is %d secs\n", temp);
2388 printf("All servers are running.\n");
2390 printf("These servers unavailable due to network or server problems: ");
2391 for(j=0; j < AFS_MAXHOSTS; j++) {
2392 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2395 tp = hostutil_GetNameByINet(temp);
2405 MessagesCmd(struct cmd_syndesc *as, void *arock)
2408 struct ViceIoctl blob;
2409 struct gaginfo gagflags;
2410 struct cmd_item *show;
2412 memset(&gagflags, 0, sizeof(struct gaginfo));
2413 blob.in_size = sizeof(struct gaginfo);
2414 blob.in = (caddr_t ) &gagflags;
2415 blob.out_size = AFS_PIOCTL_MAXSIZE;
2417 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2419 if (show = as->parms[0].items) {
2420 if (!strcasecmp (show->data, "user"))
2421 gagflags.showflags |= GAGUSER;
2422 else if (!strcasecmp (show->data, "console"))
2423 gagflags.showflags |= GAGCONSOLE;
2424 else if (!strcasecmp (show->data, "all"))
2425 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2426 else if (!strcasecmp (show->data, "none"))
2430 "unrecognized flag %s: must be in {user,console,all,none}\n",
2439 code = pioctl_utf8(0, VIOC_GAG, &blob, 1);
2448 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2451 struct ViceIoctl blob;
2455 code = pioctl_utf8(0, VIOCCKBACK, &blob, 1);
2460 printf("All volumeID/name mappings checked.\n");
2466 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2469 struct ViceIoctl blob;
2474 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2479 fprintf (stderr,"Permission denied: requires root access.\n");
2484 if (!as->parms[0].items && !as->parms[1].items) {
2485 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2488 if (as->parms[0].items) {
2489 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2491 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2496 blob.in = (char *) &temp;
2497 blob.in_size = sizeof(afs_int32);
2499 code = pioctl_utf8(0, VIOCSETCACHESIZE, &blob, 1);
2501 Die(errno, (char *) 0);
2505 printf("New cache size set.\n");
2510 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2513 struct ViceIoctl blob;
2514 cm_cacheParms_t parms;
2516 memset(&parms, 0, sizeof(parms));
2519 blob.out_size = sizeof(parms);
2520 blob.out = (char *) &parms;
2521 code = pioctl_utf8(0, VIOCGETCACHEPARMS, &blob, 1);
2522 if (code || blob.out_size != sizeof(parms)) {
2527 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2528 parms.parms[1], parms.parms[0]);
2529 if (parms.parms[1] > parms.parms[0])
2530 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2535 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2538 afs_int32 i, j, *lp, magic, size;
2540 afs_int32 addr, maxa = AFS_OMAXHOSTS;
2541 struct ViceIoctl blob;
2544 resolve = !(as->parms[0].items); /* -numeric */
2546 for(i=0;i<1000;i++) {
2548 memcpy(tp, &i, sizeof(afs_int32));
2549 tp = (char *)(space + sizeof(afs_int32));
2550 lp = (afs_int32 *)tp;
2552 size = sizeof(afs_int32) + sizeof(afs_int32);
2553 blob.out_size = AFS_PIOCTL_MAXSIZE;
2554 blob.in_size = sizeof(afs_int32);
2557 code = pioctl_utf8(0, VIOCGETCELL, &blob, 1);
2560 break; /* done with the list */
2565 memcpy(&magic, tp, sizeof(afs_int32));
2566 if (magic == 0x12345678) {
2567 maxa = AFS_MAXHOSTS;
2568 tp += sizeof(afs_int32);
2570 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2571 for(j=0; j < maxa && j*sizeof(afs_int32) < AFS_PIOCTL_MAXSIZE; j++) {
2572 char *name, tbuffer[20];
2574 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2579 name = hostutil_GetNameByINet(addr);
2582 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2583 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2586 printf(" %s", name);
2595 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2598 char *tp, *aliasName, *realName;
2599 struct ViceIoctl blob;
2603 memcpy(tp, &i, sizeof(afs_int32));
2604 blob.out_size = AFS_PIOCTL_MAXSIZE;
2605 blob.in_size = sizeof(afs_int32);
2608 code = pioctl_utf8(0, VIOC_GETALIAS, &blob, 1);
2611 break; /* done with the list */
2615 space[blob.out_size - 1] = '\0';
2618 tp += strlen(aliasName) + 1;
2620 printf("Alias %s for cell %s\n", aliasName, realName);
2626 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2629 struct ViceIoctl blob;
2630 struct cmd_item *ti;
2632 struct hostent *thp;
2636 ti = as->parms[0].items;
2639 thp = hostutil_GetHostByName(ti->data);
2641 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2644 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2646 hostAddr = 0; /* means don't set host */
2647 setp = 0; /* aren't setting host */
2650 /* now do operation */
2651 blob.in_size = sizeof(afs_int32);
2652 blob.out_size = sizeof(afs_int32);
2653 blob.in = (char *) &hostAddr;
2654 blob.out = (char *) &hostAddr;
2656 code = pioctl_utf8(0, VIOC_CBADDR, &blob, 1);
2666 NewCellCmd(struct cmd_syndesc *as, void *arock)
2669 afs_int32 code, linkedstate=0, size=0, *lp;
2670 struct ViceIoctl blob;
2671 struct cmd_item *ti;
2672 char *tp, *cellname=0;
2673 struct hostent *thp;
2674 afs_int32 fsport = 0, vlport = 0;
2676 memset(space, 0, AFS_MAXHOSTS * sizeof(afs_int32));
2678 lp = (afs_int32 *)tp;
2680 tp += sizeof(afs_int32);
2681 for(ti=as->parms[1].items; ti; ti=ti->next) {
2682 thp = hostutil_GetHostByName(ti->data);
2684 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2688 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2689 tp += sizeof(afs_int32);
2692 if (as->parms[2].items) {
2694 * Link the cell, for the purposes of volume location, to the specified
2697 cellname = as->parms[2].items->data;
2700 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2701 if (as->parms[3].items) {
2702 code = util_GetInt32(as->parms[3].items->data, &vlport);
2704 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2708 if (as->parms[4].items) {
2709 code = util_GetInt32(as->parms[4].items->data, &fsport);
2711 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2716 tp = (char *)(space + (AFS_MAXHOSTS+1) *sizeof(afs_int32));
2717 lp = (afs_int32 *)tp;
2721 strcpy(space + ((AFS_MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2722 size = ((AFS_MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2723 tp = (char *)(space + size);
2725 strcpy(tp, cellname);
2726 size += strlen(cellname) + 1;
2728 blob.in_size = size;
2731 code = pioctl_utf8(0, VIOCNEWCELL, &blob, 1);
2737 struct ViceIoctl blob;
2740 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2745 blob.in = (char *) 0;
2746 blob.out_size = AFS_PIOCTL_MAXSIZE;
2749 code = pioctl_utf8((char *) 0, VIOCNEWCELL, &blob, 1);
2752 Die(errno, (char *) 0);
2756 printf("Cell servers information refreshed\n");
2763 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2766 struct ViceIoctl blob;
2768 char *aliasName, *realName;
2770 /* Setup and do the NEWALIAS pioctl call */
2771 aliasName = as->parms[0].items->data;
2772 realName = as->parms[1].items->data;
2774 strcpy(tp, aliasName);
2775 tp += strlen(aliasName) + 1;
2776 strcpy(tp, realName);
2777 tp += strlen(realName) + 1;
2779 blob.in_size = tp - space;
2783 code = pioctl_utf8(0, VIOC_NEWALIAS, &blob, 1);
2785 if (errno == EEXIST) {
2787 "%s: cell name `%s' in use by an existing cell.\n", pn,
2799 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2802 struct cmd_item *ti;
2803 struct ViceIoctl blob;
2806 cm_ioctlQueryOptions_t options;
2808 if (as->parms[1].items)
2811 SetDotDefault(&as->parms[0].items);
2812 for(ti=as->parms[0].items; ti; ti=ti->next) {
2814 afs_uint32 filetype;
2815 char cell[CELL_MAXNAMELEN];
2818 memset(&fid, 0, sizeof(fid));
2819 memset(&options, 0, sizeof(options));
2821 options.size = sizeof(options);
2822 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
2823 options.literal = literal;
2824 blob.in_size = options.size; /* no variable length data */
2827 blob.out_size = sizeof(cm_fid_t);
2828 blob.out = (char *) &fid;
2829 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
2830 blob.out_size == sizeof(cm_fid_t)) {
2831 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
2834 Die(errno, ti->data);
2839 blob.out_size = sizeof(filetype);
2840 blob.out = &filetype;
2842 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
2843 if (code || blob.out_size != sizeof(filetype)) {
2844 Die(errno, ti->data);
2848 blob.out_size = CELL_MAXNAMELEN;
2851 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
2853 if (errno == ENOENT)
2854 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2856 Die(errno, ti->data);
2860 cell[CELL_MAXNAMELEN - 1] = '\0';
2861 printf("%s %s lives in cell '%s'\n",
2862 filetypestr(filetype),
2869 WSCellCmd(struct cmd_syndesc *as, void *arock)
2872 struct ViceIoctl blob;
2876 blob.out_size = AFS_PIOCTL_MAXSIZE;
2879 code = pioctl_utf8(NULL, VIOC_GET_WS_CELL, &blob, 1);
2885 space[AFS_PIOCTL_MAXSIZE - 1] = '\0';
2886 printf("This workstation belongs to cell '%s'\n", space);
2892 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
2894 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2899 #ifndef AFS_NT40_ENV
2901 MonitorCmd(struct cmd_syndesc *as, void *arock)
2904 struct ViceIoctl blob;
2905 struct cmd_item *ti;
2907 struct hostent *thp;
2911 ti = as->parms[0].items;
2915 if (!strcmp(ti->data, "off")) {
2916 hostAddr = 0xffffffff;
2918 thp = hostutil_GetHostByName(ti->data);
2920 if (!strcmp(ti->data, "localhost")) {
2921 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2922 hostAddr = htonl(0x7f000001);
2924 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2928 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2932 hostAddr = 0; /* means don't set host */
2933 setp = 0; /* aren't setting host */
2936 /* now do operation */
2937 blob.in_size = sizeof(afs_int32);
2938 blob.out_size = sizeof(afs_int32);
2939 blob.in = (char *) &hostAddr;
2940 blob.out = (char *) &hostAddr;
2941 code = pioctl_utf8(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2942 if (code || blob.out_size != sizeof(afs_int32)) {
2947 printf("%s: new monitor host set.\n", pn);
2949 /* now decode old address */
2950 if (hostAddr == 0xffffffff) {
2951 printf("Cache monitoring is currently disabled.\n");
2953 tp = hostutil_GetNameByINet(hostAddr);
2954 printf("Using host %s for monitor services.\n", tp);
2959 #endif /* AFS_NT40_ENV */
2962 SysNameCmd(struct cmd_syndesc *as, void *arock)
2965 struct ViceIoctl blob;
2966 struct cmd_item *ti;
2967 char *input = space;
2970 ti = as->parms[0].items;
2974 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2979 fprintf (stderr,"Permission denied: requires root access.\n");
2987 blob.out_size = AFS_PIOCTL_MAXSIZE;
2988 blob.in_size = sizeof(afs_int32);
2989 memcpy(input, &setp, sizeof(afs_int32));
2990 input += sizeof(afs_int32);
2991 for (; ti; ti = ti->next) {
2993 blob.in_size += (long)strlen(ti->data) + 1;
2994 if (blob.in_size > AFS_PIOCTL_MAXSIZE) {
2995 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2996 setp > 1 ? "s" : "");
2999 strcpy(input, ti->data);
3000 input += strlen(ti->data);
3003 memcpy(space, &setp, sizeof(afs_int32));
3004 code = pioctl_utf8(0, VIOC_AFS_SYSNAME, &blob, 1);
3010 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
3015 memcpy(&setp, input, sizeof(afs_int32));
3016 input += sizeof(afs_int32);
3018 fprintf(stderr,"No sysname name value was found\n");
3021 space[blob.out_size - 1] = '\0';
3022 printf("Current sysname%s is", setp > 1 ? " list" : "");
3023 for (; setp > 0; --setp ) {
3024 printf(" \'%s\'", input);
3025 input += strlen(input) + 1;
3031 #ifndef AFS_NT40_ENV
3032 static char *exported_types[] = {"null", "nfs", ""};
3033 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
3036 struct ViceIoctl blob;
3037 struct cmd_item *ti;
3038 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
3039 int exportcall, pwsync = 0, smounts = 0;
3043 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3048 fprintf (stderr,"Permission denied: requires root access.\n");
3053 ti = as->parms[0].items;
3054 if (strcmp(ti->data, "nfs") == 0)
3055 type = 0x71; /* NFS */
3058 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
3061 ti = as->parms[1].items;
3063 if (strcmp(ti->data, "on") == 0)
3065 else if (strcmp(ti->data, "off") == 0)
3068 fprintf(stderr, "Illegal argument %s\n", ti->data);
3073 if (ti = as->parms[2].items) { /* -noconvert */
3074 if (strcmp(ti->data, "on") == 0)
3076 else if (strcmp(ti->data, "off") == 0)
3079 fprintf(stderr, "Illegal argument %s\n", ti->data);
3083 if (ti = as->parms[3].items) { /* -uidcheck */
3084 if (strcmp(ti->data, "on") == 0)
3086 else if (strcmp(ti->data, "off") == 0)
3089 fprintf(stderr, "Illegal argument %s\n", ti->data);
3093 if (ti = as->parms[4].items) { /* -submounts */
3094 if (strcmp(ti->data, "on") == 0)
3096 else if (strcmp(ti->data, "off") == 0)
3099 fprintf(stderr, "Illegal argument %s\n", ti->data);
3103 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
3106 blob.in = (char *) &exportcall;
3107 blob.in_size = sizeof(afs_int32);
3108 blob.out = (char *) &exportcall;
3109 blob.out_size = sizeof(afs_int32);
3110 code = pioctl_utf8(0, VIOC_EXPORTAFS, &blob, 1);
3112 if (errno == ENODEV) {
3114 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
3121 if (exportcall & 1) {
3122 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
3123 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
3124 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
3125 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
3127 printf("'%s' translator is disabled\n", exported_types[type]);
3136 GetCellCmd(struct cmd_syndesc *as, void *arock)
3139 struct ViceIoctl blob;
3140 struct afsconf_cell info;
3141 struct cmd_item *ti;
3148 memset(&info, 0, sizeof(info));
3149 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3150 for(ti=as->parms[0].items; ti; ti=ti->next) {
3152 blob.out_size = sizeof(args);
3153 blob.out = (caddr_t) &args;
3154 code = GetCellName(ti->data, &info);
3159 if (info.linkedCell)
3160 free(info.linkedCell);
3161 blob.in_size = 1+(long)strlen(info.name);
3162 blob.in = info.name;
3163 code = pioctl_utf8(0, VIOC_GETCELLSTATUS, &blob, 1);
3165 if (errno == ENOENT)
3166 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3168 Die(errno, info.name);
3172 printf("Cell %s status: ", info.name);
3178 printf("no setuid allowed");
3180 printf("setuid allowed");
3182 printf(", using old VLDB");
3188 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3191 struct ViceIoctl blob;
3192 struct afsconf_cell info;
3193 struct cmd_item *ti;
3201 memset(&info, 0, sizeof(info));
3203 /* Check arguments. */
3204 if (as->parms[1].items && as->parms[2].items) {
3205 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3209 /* figure stuff to set */
3215 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3220 fprintf (stderr,"Permission denied: requires root access.\n");
3225 if (! as->parms[1].items)
3226 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3228 /* set stat for all listed cells */
3229 for(ti=as->parms[0].items; ti; ti=ti->next) {
3231 code = GetCellName(ti->data, &info);
3236 if (info.linkedCell)
3237 free(info.linkedCell);
3238 strcpy(args.cname, info.name);
3239 blob.in_size = sizeof(args);
3240 blob.in = (caddr_t) &args;
3242 blob.out = (caddr_t) 0;
3243 code = pioctl_utf8(0, VIOC_SETCELLSTATUS, &blob, 1);
3245 Die(errno, info.name); /* XXX added cell name to Die() call */
3253 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3255 strcpy(infop->name, cellNamep);
3260 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3265 cm_GetConfigDir(confDir, sizeof(confDir));
3267 code = ugen_ClientInit(noAuthFlag, confDir,
3268 info->name, 0, &uclient,
3269 NULL, pn, rxkad_clear,
3270 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3271 0, 0, USER_SERVICE_ID);
3276 static struct ViceIoctl gblob;
3277 static int debug = 0;
3279 * here follow some routines in suport of the setserverprefs and
3280 * getserverprefs commands. They are:
3281 * SetPrefCmd "top-level" routine
3282 * addServer adds a server to the list of servers to be poked into the
3283 * kernel. Will poke the list into the kernel if it threatens
3285 * pokeServers pokes the existing list of servers and ranks into the kernel
3286 * GetPrefCmd reads the Cache Manager's current list of server ranks
3295 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3297 ssp = (cm_SSetPref_t *)space;
3298 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3304 * returns -1 if error message printed,
3306 * errno value if error and no error message printed
3313 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3314 if (code && (errno == EINVAL)) {
3315 struct setspref *ssp;
3316 ssp = (struct setspref *)gblob.in;
3317 if (!(ssp->flags & DBservers)) {
3318 gblob.in = (void *)&(ssp->servers[0]);
3319 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3320 code = pioctl_utf8(0, VIOC_SETSPREFS33, &gblob, 1);
3321 return code ? errno : 0;
3324 "This cache manager does not support VL server preferences.\n");
3328 return code ? errno : 0;
3334 addServer(char *name, unsigned short rank)
3339 struct hostent *thostent;
3343 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3345 #define MAXUSHORT ((unsigned short) ~0)
3350 thostent = hostutil_GetHostByName(name);
3352 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3356 ssp = (cm_SSetPref_t *)(gblob.in);
3358 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3359 code = pokeServers();
3360 ssp->num_servers = 0;
3363 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3364 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3365 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3366 gblob.in_size += sizeof(cm_SPref_t);
3369 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3375 * returns -1 if error message printed,
3377 * errno value if error and no error message printed
3380 addServer(char *name, afs_int32 rank)
3383 struct setspref *ssp;
3385 struct hostent *thostent;
3391 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3393 #define MAXUSHORT ((unsigned short) ~0)
3397 thostent = hostutil_GetHostByName(name);
3399 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3403 ssp = (struct setspref *)(gblob.in);
3405 for (t = 0; thostent->h_addr_list[t]; t++) {
3406 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3407 code = pokeServers();
3410 ssp->num_servers = 0;
3413 sp = (struct spref *)(gblob.in + gblob.in_size);
3414 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3415 sizeof(afs_uint32));
3416 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3417 gblob.in_size += sizeof(struct spref);
3421 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3422 name, sp->rank, sp->server.s_addr);
3430 static BOOL IsWindowsNT (void)
3432 static BOOL fChecked = FALSE;
3433 static BOOL fIsWinNT = FALSE;
3437 OSVERSIONINFO Version;
3441 memset (&Version, 0x00, sizeof(Version));
3442 Version.dwOSVersionInfoSize = sizeof(Version);
3444 if (GetVersionEx (&Version))
3446 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3456 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3460 struct cmd_item *ti;
3465 ssp = (cm_SSetPref_t *)space;
3467 ssp->num_servers = 0;
3468 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3471 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3474 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3480 ti = as->parms[2].items; /* -file */
3482 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3483 if (!(infd = fopen(ti->data,"r" ))) {
3485 Die(errno,ti->data);
3488 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3489 code = addServer (name, (unsigned short) rank);
3493 ti = as->parms[3].items; /* -stdin */
3495 while ( scanf("%79s%ld", name, &rank) != EOF) {
3496 code = addServer (name, (unsigned short) rank);
3500 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3505 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3507 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3511 code = pokeServers();
3513 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3515 ssp = (cm_SSetPref_t *)space;
3516 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3518 ssp->flags = CM_SPREF_VLONLY;
3519 ssp->num_servers = 0;
3521 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3526 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3528 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3533 if (as->parms[1].items) {
3535 printf("now poking vlservers\n");
3536 code = pokeServers();
3546 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3550 struct cmd_item *ti;
3553 struct setspref *ssp;
3554 int error = 0; /* -1 means error message printed,
3555 * >0 means errno value for unprinted message */
3557 ssp = (struct setspref *)space;
3559 ssp->num_servers = 0;
3560 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3563 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3567 fprintf(stderr, "Permission denied: requires root access.\n");
3571 ti = as->parms[2].items; /* -file */
3574 fprintf(stderr, "opening file %s\n", ti->data);
3575 if (!(infd = fopen(ti->data, "r"))) {
3579 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3580 code = addServer(name, (unsigned short)rank);
3587 ti = as->parms[3].items; /* -stdin */
3589 while (scanf("%79s%ld", name, &rank) != EOF) {
3590 code = addServer(name, (unsigned short)rank);
3596 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3601 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3605 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3609 code = pokeServers();
3613 printf("now working on vlservers, code=%d\n", code);
3615 ssp = (struct setspref *)space;
3616 ssp->flags = DBservers;
3617 ssp->num_servers = 0;
3618 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3621 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3626 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3630 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3635 if (as->parms[1].items) {
3637 printf("now poking vlservers\n");
3638 code = pokeServers();
3646 return error ? 1 : 0;
3652 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3655 struct cmd_item *ti;
3656 char *name, tbuffer[20];
3661 struct ViceIoctl blob;
3662 struct cm_SPrefRequest *in;
3663 struct cm_SPrefInfo *out;
3667 ti = as->parms[0].items; /* -file */
3669 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3670 if (!(outfd = freopen(ti->data,"w",stdout))) {
3671 Die(errno,ti->data);
3676 ti = as->parms[1].items; /* -numeric */
3678 ti = as->parms[2].items; /* -vlservers */
3679 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3680 /* ti = as->parms[3].items; -cell */
3682 in = (struct cm_SPrefRequest *)space;
3686 blob.in_size=sizeof(struct cm_SPrefRequest);
3687 blob.in = (char *)in;
3689 blob.out_size = AFS_PIOCTL_MAXSIZE;
3691 in->num_servers = (AFS_PIOCTL_MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3692 in->flags = vlservers;
3694 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3696 perror("getserverprefs pioctl");
3700 out = (struct cm_SPrefInfo *) blob.out;
3702 for (i=0;i<out->num_servers;i++) {
3704 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3707 addr = ntohl(out->servers[i].host.s_addr);
3708 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3709 (addr>>8) & 0xff, addr & 0xff);
3712 printf ("%-50s %5u\n",name,out->servers[i].rank);
3715 in->offset = out->next_offset;
3717 } while (!code && out->next_offset > 0);
3723 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3726 struct cmd_item *ti;
3727 char *name, tbuffer[20];
3728 afs_int32 rank, addr;
3732 struct ViceIoctl blob;
3733 struct sprefrequest *in;
3734 struct sprefinfo *out;
3737 ti = as->parms[0].items; /* -file */
3740 fprintf(stderr, "opening file %s\n", ti->data);
3741 if (!(outfd = freopen(ti->data, "w", stdout))) {
3747 ti = as->parms[1].items; /* -numeric */
3749 ti = as->parms[2].items; /* -vlservers */
3750 vlservers |= (ti ? DBservers : 0);
3751 /* ti = as->parms[3].items; -cell */
3753 in = (struct sprefrequest *)space;
3757 blob.in_size = sizeof(struct sprefrequest);
3758 blob.in = (char *)in;
3760 blob.out_size = AFS_PIOCTL_MAXSIZE;
3763 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3764 in->flags = vlservers;
3766 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3768 perror("getserverprefs pioctl");
3772 out = (struct sprefinfo *)blob.out;
3774 for (i = 0; i < out->num_servers; i++) {
3776 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
3778 addr = ntohl(out->servers[i].server.s_addr);
3779 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
3780 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
3783 printf("%-50s %5u\n", name, out->servers[i].rank);
3786 in->offset = out->next_offset;
3787 } while (out->next_offset > 0);
3794 SmbUnicodeCmd(struct cmd_syndesc * asp, void * arock)
3800 struct ViceIoctl blob;
3802 if (asp->parms[0].items) {
3806 } else if (asp->parms[1].items) {
3812 if (inValue != 0 && !IsAdmin()) {
3813 fprintf (stderr, "Permission denied: Requires AFS Client Administrator access.\n");
3817 blob.in_size = sizeof(inValue);
3818 blob.in = (char *) &inValue;
3819 blob.out_size = sizeof(outValue);
3820 blob.out = (char *) &outValue;
3822 code = pioctl_utf8(NULL, VIOC_UNICODECTL, &blob, 1);
3828 if (outValue != 2) {
3829 printf("Unicode support is %s%s.\n",
3830 ((outValue != 0)? "enabled":"disabled"),
3831 ((inValue != 0)? " for new SMB connections":""));
3833 printf("Unicode support is absent in this installation of OpenAFS.\n");
3840 GetFidCmd(struct cmd_syndesc *as, void *arock)
3843 struct ViceIoctl blob;
3844 struct cmd_item *ti;
3847 cm_ioctlQueryOptions_t options;
3849 if (as->parms[1].items)
3852 SetDotDefault(&as->parms[0].items);
3853 for(ti=as->parms[0].items; ti; ti=ti->next) {
3855 afs_uint32 filetype;
3856 char cell[CELL_MAXNAMELEN];
3859 memset(&fid, 0, sizeof(fid));
3860 memset(&options, 0, sizeof(options));
3862 options.size = sizeof(options);
3863 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
3864 options.literal = literal;
3865 blob.in_size = options.size; /* no variable length data */
3868 blob.out_size = sizeof(cm_fid_t);
3869 blob.out = (char *) &fid;
3870 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
3871 blob.out_size == sizeof(cm_fid_t)) {
3872 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
3875 Die(errno, ti->data);
3880 blob.out_size = sizeof(filetype);
3881 blob.out = &filetype;
3883 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
3884 if (code || blob.out_size != sizeof(filetype)) {
3885 Die(errno, ti->data);
3889 blob.out_size = CELL_MAXNAMELEN;
3892 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
3894 cell[CELL_MAXNAMELEN - 1] = '\0';
3895 printf("%s %s (%u.%u.%u) contained in cell %s\n",
3896 filetypestr(filetype),
3897 ti->data, fid.volume, fid.vnode, fid.unique,
3898 code ? "unknown-cell" : cell);
3904 UuidCmd(struct cmd_syndesc *asp, void *arock)
3909 struct ViceIoctl blob;
3910 char * uuidstring = NULL;
3912 if (asp->parms[0].items) {
3915 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3920 fprintf (stderr, "Permission denied: requires root access.\n");
3924 inValue = 1; /* generate new UUID */
3926 inValue = 0; /* just show the current UUID */
3929 blob.in_size = sizeof(inValue);
3930 blob.in = (char *) &inValue;
3931 blob.out_size = sizeof(outValue);
3932 blob.out = (char *) &outValue;
3934 code = pioctl_utf8(NULL, VIOC_UUIDCTL, &blob, 1);
3935 if (code || blob.out_size != sizeof(outValue)) {
3940 UuidToString((UUID *) &outValue, &uuidstring);
3942 printf("%sUUID: %s",
3943 ((inValue == 1)?"New ":""),
3947 RpcStringFree(&uuidstring);
3953 TraceCmd(struct cmd_syndesc *asp, void *arock)
3956 struct ViceIoctl blob;
3962 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3967 fprintf (stderr,"Permission denied: requires root access.\n");
3972 if ((asp->parms[0].items && asp->parms[1].items)) {
3973 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
3977 /* determine if we're turning this tracing on or off */
3979 if (asp->parms[0].items)
3980 inValue = 3; /* enable */
3981 else if (asp->parms[1].items)
3982 inValue = 2; /* disable */
3983 if (asp->parms[2].items)
3984 inValue |= 4; /* do reset */
3985 if (asp->parms[3].items)
3986 inValue |= 8; /* dump */
3988 blob.in_size = sizeof(long);
3989 blob.in = (char *) &inValue;
3990 blob.out_size = sizeof(long);
3991 blob.out = (char *) &outValue;
3993 code = pioctl_utf8(NULL, VIOC_TRACECTL, &blob, 1);
3994 if (code || blob.out_size != sizeof(long)) {
4000 printf("AFS tracing enabled.\n");
4002 printf("AFS tracing disabled.\n");
4007 static void sbusage(void)
4009 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
4010 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
4013 /* fs sb -kbytes 9999 -files *.o -default 64 */
4015 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
4018 struct ViceIoctl blob;
4019 struct cmd_item *ti;
4020 struct sbstruct tsb, tsb2;
4028 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4033 tsb.sb_thisfile = -1;
4034 ti = as->parms[0].items; /* -kbytes */
4036 if (!as->parms[1].items) {
4037 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
4041 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
4042 if ((tsb.sb_thisfile < 0) || (t != ti->data + strlen(ti->data))) {
4043 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
4049 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
4050 ti = as->parms[2].items; /* -allfiles */
4052 allfiles = strtol(ti->data, &t, 10) * 1024;
4053 if ((allfiles < 0) || (t != ti->data + strlen(ti->data))) {
4054 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
4060 /* -verbose or -file only or no options */
4061 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
4062 || (!as->parms[0].items && !as->parms[1].items
4063 && !as->parms[2].items))
4066 blob.in = (char *)&tsb;
4067 blob.out = (char *)&tsb2;
4068 blob.in_size = blob.out_size = sizeof(struct sbstruct);
4069 memset(&tsb2, 0, sizeof(tsb2));
4071 /* once per -file */
4072 for (ti = as->parms[1].items; ti; ti = ti->next) {
4073 /* Do this solely to see if the file is there */
4074 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
4076 Die(errno, ti->data);
4081 code = pioctl_utf8(ti->data, VIOC_STOREBEHIND, &blob, 1);
4083 Die(errno, ti->data);
4088 if (verbose && (blob.out_size == sizeof(tsb2))) {
4089 if (tsb2.sb_thisfile == -1) {
4090 fprintf(stdout, "Will store %s according to default.\n",
4094 "Will store up to %d kbytes of %s asynchronously.\n",
4095 (tsb2.sb_thisfile / 1024), ti->data);
4100 /* If no files - make at least one pioctl call, or
4101 * set the allfiles default if we need to.
4103 if (!as->parms[1].items || (allfiles != -1)) {
4104 tsb.sb_default = allfiles;
4105 code = pioctl_utf8(0, VIOC_STOREBEHIND, &blob, 1);
4107 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
4112 /* Having no arguments also reports the default store asynchrony */
4113 if (verbose && (blob.out_size == sizeof(tsb2))) {
4114 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
4115 (tsb2.sb_default / 1024));
4122 SetCryptCmd(struct cmd_syndesc *as, void *arock)
4124 afs_int32 code = 0, flag;
4125 struct ViceIoctl blob;
4130 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4135 tp = as->parms[0].items->data;
4136 if (strcmp(tp, "on") == 0)
4138 else if (strcmp(tp, "off") == 0)
4140 else if (strcmp(tp, "auth") == 0)
4143 fprintf (stderr, "%s: %s must be \"on\", \"auth\", or \"off\".\n", pn, tp);
4147 blob.in = (char *) &flag;
4148 blob.in_size = sizeof(flag);
4150 code = pioctl_utf8(0, VIOC_SETRXKCRYPT, &blob, 1);
4157 GetCryptCmd(struct cmd_syndesc *as, void *arock)
4159 afs_int32 code = 0, flag;
4160 struct ViceIoctl blob;
4165 blob.out_size = sizeof(flag);
4168 code = pioctl_utf8(0, VIOC_GETRXKCRYPT, &blob, 1);
4170 if (code || blob.out_size != sizeof(flag))
4174 memcpy(&flag, tp, sizeof(afs_int32));
4175 printf("Security level is currently ");
4177 printf("auth (data integrity).\n");
4179 printf("crypt (data security).\n");
4187 MemDumpCmd(struct cmd_syndesc *asp, void *arock)
4190 struct ViceIoctl blob;
4195 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4199 if ((asp->parms[0].items && asp->parms[1].items)) {
4200 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
4204 /* determine if we're turning this tracing on or off */
4205 if (asp->parms[0].items)
4206 inValue = 1; /* begin */
4207 else if (asp->parms[1].items)
4208 inValue = 0; /* end */
4211 blob.in_size = sizeof(long);
4212 blob.in = (char *) &inValue;
4213 blob.out_size = sizeof(long);
4214 blob.out = (char *) &outValue;
4216 code = pioctl_utf8(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
4217 if (code || blob.out_size != sizeof(long)) {
4223 printf("AFS memdump created.\n");
4226 printf("AFS memdump failed.\n");
4232 MiniDumpCmd(struct cmd_syndesc *asp, void *arock)
4235 SERVICE_STATUS status;
4236 SC_HANDLE hManager = NULL;
4237 SC_HANDLE hService = NULL;
4240 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4244 hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
4248 hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
4252 success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
4255 CloseServiceHandle(hService);
4256 CloseServiceHandle(hManager);
4258 printf("AFS minidump generated.\n");
4264 CloseServiceHandle(hService);
4266 CloseServiceHandle(hManager);
4268 printf("AFS minidump failed.\n");
4273 CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
4275 struct cmd_item *ti;
4280 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4284 for(ti=asp->parms[0].items; ti;ti=ti->next) {
4296 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4297 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4300 REG_OPTION_NON_VOLATILE,
4301 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
4306 if ( hkCSCPolicy == NULL ) {
4307 fprintf (stderr,"Permission denied: requires Administrator access.\n");
4312 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4313 RegCloseKey(hkCSCPolicy);
4319 if (asp->parms[1].items)
4321 if (asp->parms[2].items)
4322 policy = "programs";
4323 if (asp->parms[3].items)
4324 policy = "documents";
4325 if (asp->parms[4].items)
4328 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, (DWORD)strlen(policy)+1);
4330 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
4331 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
4335 DWORD dwIndex, dwPolicies;
4336 char policyName[256];
4337 DWORD policyNameLen;
4342 /* list current csc policies */
4344 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4345 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4348 REG_OPTION_NON_VOLATILE,
4349 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_QUERY_VALUE,
4354 RegQueryInfoKey( hkCSCPolicy,
4356 NULL, /* lpcClass */
4357 NULL, /* lpReserved */
4358 NULL, /* lpcSubKeys */
4359 NULL, /* lpcMaxSubKeyLen */
4360 NULL, /* lpcMaxClassLen */
4361 &dwPolicies, /* lpcValues */
4362 NULL, /* lpcMaxValueNameLen */
4363 NULL, /* lpcMaxValueLen */
4364 NULL, /* lpcbSecurityDescriptor */
4365 NULL /* lpftLastWriteTime */
4368 printf("Current CSC policies:\n");
4369 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
4371 policyNameLen = sizeof(policyName);
4372 policyLen = sizeof(policy);
4373 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
4374 &dwType, policy, &policyLen);
4376 printf(" %s = %s\n", policyName, policy);
4380 RegCloseKey(hkCSCPolicy);
4385 /* get clients interface addresses */
4387 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4390 struct cmd_item *ti;
4392 struct ViceIoctl blob;
4393 struct sprefrequest *in;
4394 struct sprefinfo *out;
4396 in = (struct sprefrequest *)space;
4400 blob.in_size = sizeof(struct sprefrequest);
4401 blob.in = (char *)in;
4403 blob.out_size = AFS_PIOCTL_MAXSIZE;
4406 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4407 /* returns addr in network byte order */
4408 code = pioctl_utf8(0, VIOC_GETCPREFS, &blob, 1);
4410 perror("getClientInterfaceAddr pioctl");
4416 out = (struct sprefinfo *)blob.out;
4417 for (i = 0; i < out->num_servers; i++) {
4420 addr = ntohl(out->servers[i].server.s_addr);
4421 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
4422 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
4423 printf("%-50s\n", tbuffer);
4425 in->offset = out->next_offset;
4427 } while (out->next_offset > 0);
4433 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4435 afs_int32 code, addr;
4436 struct cmd_item *ti;
4438 struct ViceIoctl blob;
4439 struct setspref *ssp;
4440 int sizeUsed = 0, i, flag;
4441 afs_int32 existingAddr[1024]; /* existing addresses on this host */
4445 ssp = (struct setspref *)space;
4446 ssp->num_servers = 0;
4449 blob.out_size = AFS_PIOCTL_MAXSIZE;
4452 fprintf(stderr, "Permission denied: requires root access.\n");
4456 /* extract all existing interface addresses */
4457 existNu = rx_getAllAddr(existingAddr, 1024);
4461 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4462 for (ti = as->parms[0].items; ti; ti = ti->next) {
4463 if (sizeUsed >= sizeof(space)) {
4464 fprintf(stderr, "No more space\n");
4467 addr = extractAddr(ti->data, 20); /* network order */
4468 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4469 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4474 /* see if it is an address that really exists */
4475 for (flag = 0, i = 0; i < existNu; i++)
4476 if (existingAddr[i] == addr) {
4480 if (!flag) { /* this is an nonexistent address */
4481 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4485 /* copy all specified addr into ioctl buffer */
4486 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4487 printf("Adding 0x%08x\n", addr);
4489 sizeUsed += sizeof(struct spref);
4491 if (ssp->num_servers < 1) {
4492 fprintf(stderr, "No addresses specified\n");
4495 blob.in_size = sizeUsed - sizeof(struct spref);
4497 code = pioctl_utf8(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4507 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4510 struct ViceIoctl blob;
4511 struct cmd_item *ti;
4512 char orig_name[1024]; /*Original name, may be modified */
4513 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4514 char parent_dir[1024]; /*Parent directory of true name */
4515 char *last_component; /*Last component of true name */
4516 struct stat statbuff; /*Buffer for status info */
4517 int link_chars_read; /*Num chars read in readlink() */
4518 int thru_symlink; /*Did we get to a mount point via a symlink? */
4521 for (ti = as->parms[0].items; ti; ti = ti->next) {
4524 sprintf(orig_name, "%s%s", (ti->data[0] == '/') ? "" : "./",
4527 if (lstat(orig_name, &statbuff) < 0) {
4528 /* if lstat fails, we should still try the pioctl, since it
4529 * may work (for example, lstat will fail, but pioctl will
4530 * work if the volume of offline (returning ENODEV). */
4531 statbuff.st_mode = S_IFDIR; /* lie like pros */
4535 * The lstat succeeded. If the given file is a symlink, substitute
4536 * the file name with the link name.
4538 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
4541 * Read name of resolved file.
4543 link_chars_read = readlink(orig_name, true_name, 1024);
4544 if (link_chars_read <= 0) {
4546 "%s: Can't read target name for '%s' symbolic link!\n",
4553 * Add a trailing null to what was read, bump the length.
4555 true_name[link_chars_read++] = 0;
4558 * If the symlink is an absolute pathname, we're fine. Otherwise, we
4559 * have to create a full pathname using the original name and the
4560 * relative symlink name. Find the rightmost slash in the original
4561 * name (we know there is one) and splice in the symlink value.
4563 if (true_name[0] != '/') {
4564 last_component = (char *)strrchr(orig_name, '/');
4565 strcpy(++last_component, true_name);
4566 strcpy(true_name, orig_name);
4569 strcpy(true_name, orig_name);
4572 * Find rightmost slash, if any.
4574 last_component = (char *)strrchr(true_name, '/');
4575 if (last_component) {
4577 * Found it. Designate everything before it as the parent directory,
4578 * everything after it as the final component.
4580 strncpy(parent_dir, true_name, last_component - true_name);
4581 parent_dir[last_component - true_name] = 0;
4582 last_component++; /*Skip the slash */
4585 * No slash appears in the given file name. Set parent_dir to the current
4586 * directory, and the last component as the given name.
4588 strcpy(parent_dir, ".");
4589 last_component = true_name;
4592 if (strcmp(last_component, ".") == 0
4593 || strcmp(last_component, "..") == 0) {
4595 "%s: you may not use '.' or '..' as the last component\n",
4597 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
4603 blob.in = last_component;
4604 blob.in_size = strlen(last_component) + 1;
4606 memset(space, 0, AFS_PIOCTL_MAXSIZE);
4608 code = pioctl_utf8(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
4611 if (errno == EINVAL) {
4612 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
4614 Die(errno, (ti->data ? ti->data : parent_dir));
4624 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
4627 afs_int32 flags = 0;
4628 struct ViceIoctl blob;
4630 if (as->parms[0].items) { /* -enable */
4631 flags |= AFSCALL_RXSTATS_ENABLE;
4633 if (as->parms[1].items) { /* -disable */
4634 flags |= AFSCALL_RXSTATS_DISABLE;
4636 if (as->parms[2].items) { /* -clear */
4637 flags |= AFSCALL_RXSTATS_CLEAR;
4640 fprintf(stderr, "You must specify at least one argument\n");
4644 blob.in = (char *)&flags;
4645 blob.in_size = sizeof(afs_int32);
4648 code = pioctl_utf8(NULL, VIOC_RXSTAT_PROC, &blob, 1);
4658 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
4661 afs_int32 flags = 0;
4662 struct ViceIoctl blob;
4664 if (as->parms[0].items) { /* -enable */
4665 flags |= AFSCALL_RXSTATS_ENABLE;
4667 if (as->parms[1].items) { /* -disable */
4668 flags |= AFSCALL_RXSTATS_DISABLE;
4670 if (as->parms[2].items) { /* -clear */
4671 flags |= AFSCALL_RXSTATS_CLEAR;
4674 fprintf(stderr, "You must specify at least one argument\n");
4678 blob.in = (char *)&flags;
4679 blob.in_size = sizeof(afs_int32);
4682 code = pioctl_utf8(NULL, VIOC_RXSTAT_PEER, &blob, 1);
4692 TestVolStatCmd(struct cmd_syndesc *as, void *arock)
4695 struct VolStatTest test;
4696 struct ViceIoctl blob;
4700 memset(&test, 0, sizeof(test));
4702 if (as->parms[0].items) { /* -network */
4703 tp = as->parms[0].items->data;
4704 if (strcmp(tp, "up") == 0)
4705 test.flags |= VOLSTAT_TEST_NETWORK_UP;
4706 else if (strcmp(tp, "down") == 0)
4707 test.flags |= VOLSTAT_TEST_NETWORK_DOWN;
4709 fprintf (stderr, "%s: %s must be \"up\" or \"down\".\n", pn, tp);
4713 if (as->parms[1].items) { /* check */
4714 test.flags |= VOLSTAT_TEST_CHECK_VOLUME;
4716 if (as->parms[2].items) { /* cell */
4717 tp = as->parms[2].items->data;
4722 strncpy(test.cellname, tp, sizeof(test.cellname));
4723 test.cellname[sizeof(test.cellname)-1] = '\0';
4726 if (as->parms[3].items) { /* volume */
4727 tp = as->parms[3].items->data;
4730 test.fid.volume = n;
4732 strncpy(test.volname, tp, sizeof(test.volname));
4733 test.volname[sizeof(test.volname)-1] = '\0';
4736 if (as->parms[4].items) { /* state */
4737 tp = as->parms[4].items->data;
4738 if (strcmp(tp, "online") == 0)
4739 test.state = vl_online;
4740 else if (strcmp(tp, "busy") == 0)
4741 test.state = vl_busy;
4742 else if (strcmp(tp, "offline") == 0)
4743 test.state = vl_offline;
4744 else if (strcmp(tp, "down") == 0)
4745 test.state = vl_alldown;
4747 fprintf (stderr, "%s: %s must be \"online\", \"busy\", \"offline\" or \"down\".\n", pn, tp);
4752 if ((test.fid.cell || test.cellname[0]) && !(test.fid.volume || test.volname[0]) ||
4753 !(test.fid.cell || test.cellname[0]) && (test.fid.volume || test.volname[0])) {
4754 fprintf (stderr, "%s: both a cell and a volume must be specified.\n", pn, tp);
4758 blob.in = (char *)&test;
4759 blob.in_size = sizeof(test);
4762 code = pioctl_utf8(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
4772 ChOwnCmd(struct cmd_syndesc *as, void *arock)
4775 struct ViceIoctl blob;
4776 struct cmd_item *ti;
4780 cm_ioctlQueryOptions_t options;
4787 cm_GetConfigDir(confDir, sizeof(confDir));
4789 if (as->parms[2].items)
4792 ownerStr = as->parms[0].items->data;
4793 ownerId = atoi(ownerStr);
4795 SetDotDefault(&as->parms[1].items);
4796 for(ti=as->parms[1].items; ti; ti=ti->next) {
4798 afs_uint32 filetype;
4799 char cell[CELL_MAXNAMELEN];
4802 memset(&fid, 0, sizeof(fid));
4803 memset(&inData, 0, sizeof(inData));
4805 inData.options.size = sizeof(inData.options);
4806 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
4807 inData.options.literal = literal;
4808 blob.in_size = inData.options.size; /* no variable length data */
4811 blob.out_size = sizeof(cm_fid_t);
4812 blob.out = (char *) &fid;
4813 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
4814 blob.out_size == sizeof(cm_fid_t)) {
4815 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
4816 inData.options.fid = fid;
4818 Die(errno, ti->data);
4824 * if the owner was specified as a numeric value,
4825 * then we can just use it. Otherwise, we need
4826 * to know the cell of the path to determine which
4827 * ptserver to contact in order to convert the name
4828 * to a numeric value.
4831 blob.out_size = CELL_MAXNAMELEN;
4834 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
4836 Die(errno, ti->data);
4840 cell[CELL_MAXNAMELEN - 1] = '\0';
4842 * We now know the cell for the target and we need to
4843 * convert the ownerStr to the Id for this user
4845 pr_Initialize(1, confDir, cell);
4846 code = pr_SNameToId(ownerStr, &inData.owner);
4849 if (code || inData.owner == ANONYMOUSID ) {
4850 Die(ECHILD, ti->data);
4855 inData.owner = ownerId;
4858 blob.in_size = sizeof(inData);
4861 code = pioctl_utf8(ti->data, VIOC_SETOWNER, &blob, 1);
4863 Die(errno, ti->data);
4870 ChGrpCmd(struct cmd_syndesc *as, void *arock)
4873 struct ViceIoctl blob;
4874 struct cmd_item *ti;
4878 cm_ioctlQueryOptions_t options;
4885 cm_GetConfigDir(confDir, sizeof(confDir));
4887 if (as->parms[2].items)
4890 groupStr = as->parms[0].items->data;
4891 groupId = atoi(groupStr);
4893 SetDotDefault(&as->parms[1].items);
4894 for(ti=as->parms[1].items; ti; ti=ti->next) {
4896 afs_uint32 filetype;
4897 char cell[CELL_MAXNAMELEN];
4900 memset(&fid, 0, sizeof(fid));
4901 memset(&inData, 0, sizeof(inData));
4903 inData.options.size = sizeof(inData.options);
4904 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
4905 inData.options.literal = literal;
4906 blob.in_size = inData.options.size; /* no variable length data */
4909 blob.out_size = sizeof(cm_fid_t);
4910 blob.out = (char *) &fid;
4911 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
4912 blob.out_size == sizeof(cm_fid_t)) {
4913 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
4914 inData.options.fid = fid;
4916 Die(errno, ti->data);
4922 * if the group was specified as a numeric value,
4923 * then we can just use it. Otherwise, we need
4924 * to know the cell of the path to determine which
4925 * ptserver to contact in order to convert the name
4926 * to a numeric value.
4929 blob.out_size = CELL_MAXNAMELEN;
4932 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
4934 Die(errno, ti->data);
4938 cell[CELL_MAXNAMELEN - 1] = '\0';
4940 * We now know the cell for the target and we need to
4941 * convert the groupStr to the Id for this user
4943 pr_Initialize(1, confDir, cell);
4944 code = pr_SNameToId(groupStr, &inData.group);
4947 if (code || inData.group == ANONYMOUSID ) {
4948 Die(ECHILD, ti->data);
4953 inData.group = groupId;
4956 blob.in_size = sizeof(inData);
4959 code = pioctl_utf8(ti->data, VIOC_SETGROUP, &blob, 1);
4961 Die(errno, ti->data);
4968 #include "AFS_component_version_number.c"
4972 FreeUtf8CmdLine(int argc, char ** argv)
4975 for (i=0; i < argc; i++) {
4983 MakeUtf8Cmdline(int argc, const wchar_t **wargv)
4988 argv = calloc(argc, sizeof(argv[0]));
4992 for (i=0; i < argc; i++) {
4995 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, FALSE);
4997 (argv[i] = calloc(s+1, sizeof(char))) == NULL) {
5001 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], s+1, NULL, FALSE);
5008 FreeUtf8CmdLine(argc, argv);
5015 int wmain(int argc, wchar_t **wargv)
5018 struct cmd_syndesc *ts;
5021 #ifdef AFS_AIX32_ENV
5023 * The following signal action for AIX is necessary so that in case of a
5024 * crash (i.e. core is generated) we can include the user's data section
5025 * in the core dump. Unfortunately, by default, only a partial core is
5026 * generated which, in many cases, isn't too useful.
5028 struct sigaction nsa;
5030 sigemptyset(&nsa.sa_mask);
5031 nsa.sa_handler = SIG_DFL;
5032 nsa.sa_flags = SA_FULLDUMP;
5033 sigaction(SIGSEGV, &nsa, NULL);
5038 WSAStartup(0x0101, &WSAjunk);
5041 argv = MakeUtf8Cmdline(argc, wargv);
5043 /* try to find volume location information */
5047 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
5048 "get client network interface addresses");
5049 cmd_CreateAlias(ts, "gc");
5051 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
5052 "set client network interface addresses");
5053 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
5054 "client network interfaces");
5055 cmd_CreateAlias(ts, "sc");
5058 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL, "set server ranks");
5059 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
5060 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
5061 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
5062 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
5063 cmd_CreateAlias(ts, "sp");
5065 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL, "get server ranks");
5066 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
5067 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
5068 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
5069 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
5070 cmd_CreateAlias(ts, "gp");
5072 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
5073 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5074 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
5075 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
5076 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
5077 parm_setacl_id = ts->nParms;
5078 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
5079 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
5080 cmd_CreateAlias(ts, "sa");
5082 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL, "list access control list");
5083 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5084 parm_listacl_id = ts->nParms;
5085 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
5086 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
5087 cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
5088 cmd_CreateAlias(ts, "la");
5090 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL, "clean up access control list");
5091 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5093 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL, "copy access control list");
5094 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
5095 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
5096 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
5097 parm_copyacl_id = ts->nParms;
5098 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
5099 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
5101 cmd_CreateAlias(ts, "ca");
5103 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
5104 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5105 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5108 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
5109 "flush mount symlink from cache");
5110 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5113 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
5114 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5115 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
5117 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
5119 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
5120 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
5121 cmd_CreateAlias(ts, "sv");
5123 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL, "control Cache Manager messages");
5124 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
5126 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
5127 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5128 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5129 cmd_CreateAlias(ts, "lv");
5130 cmd_CreateAlias(ts, "listvol");
5132 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
5133 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5134 cmd_CreateAlias(ts, "lq");
5136 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL, "show server disk space usage");
5137 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5138 cmd_CreateAlias(ts, "df");
5140 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
5141 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5143 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
5144 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5146 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
5147 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
5148 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
5149 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
5150 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
5151 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
5157 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
5161 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
5162 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5164 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL, "check local cell's servers");
5165 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
5166 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
5167 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
5168 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
5170 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL, "check volumeID/name mappings");
5171 cmd_CreateAlias(ts, "checkbackups");
5174 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL, "set cache size");
5175 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
5176 cmd_CreateAlias(ts, "cachesize");
5178 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
5180 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL, "get cache usage info");
5182 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL, "list configured cells");
5183 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
5185 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
5186 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
5187 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
5189 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
5191 cmd_CreateAlias(ts, "sq");
5193 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
5195 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
5196 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
5197 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
5199 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
5201 * Turn this on only if you wish to be able to talk to a server which is listening
5202 * on alternative ports. This is not intended for general use and may not be
5203 * supported in the cache manager. It is not a way to run two servers at the
5204 * same host, since the cache manager cannot properly distinguish those two hosts.
5206 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
5207 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
5210 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
5211 "configure new cell alias");
5212 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
5213 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
5216 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
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("whereis", WhereIsCmd, NULL, "list file's location");
5221 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5222 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5224 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
5227 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
5230 #ifndef AFS_NT40_ENV
5231 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, "set cache monitor host address");
5232 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
5233 cmd_CreateAlias(ts, "mariner");
5236 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
5237 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
5239 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
5240 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
5241 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
5242 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
5244 ts = cmd_CreateSyntax("flushall", FlushAllCmd, NULL, "flush all data");
5246 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL, "flush all data in volume");
5247 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5249 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL, "get/set sysname (i.e. @sys) value");
5250 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
5252 #ifndef AFS_NT40_ENV
5253 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL, "enable/disable translators to AFS");
5254 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
5255 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
5256 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
5257 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
5258 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
5261 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
5262 "store to server after file close");
5263 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
5264 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
5265 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
5266 cmd_CreateAlias(ts, "sb");
5268 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL, "set cache manager encryption flag");
5269 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
5271 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL, "get cache manager encryption flag");
5273 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
5274 "Manage per process RX statistics");
5275 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
5276 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
5277 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
5279 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
5280 "Manage per peer RX statistics");
5281 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
5282 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
5283 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
5286 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
5287 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
5290 ts = cmd_CreateSyntax("trace", TraceCmd, NULL, "enable or disable CM tracing");
5291 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
5292 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
5293 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
5294 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
5295 cmd_CreateAlias(ts, "tr");
5297 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
5298 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
5300 ts = cmd_CreateSyntax("memdump", MemDumpCmd, NULL, "dump memory allocs in debug builds");
5301 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
5302 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
5304 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, NULL, "change client side caching policy for AFS shares");
5305 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
5306 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
5307 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
5308 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
5309 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
5311 ts = cmd_CreateSyntax("minidump", MiniDumpCmd, NULL, "Generate MiniDump of current service state");
5313 ts = cmd_CreateSyntax("test_volstat", TestVolStatCmd, NULL, (char *)CMD_HIDDEN);
5314 cmd_AddParm(ts, "-network", CMD_SINGLE, CMD_OPTIONAL, "set network state up or down");
5315 cmd_AddParm(ts, "-check", CMD_FLAG, CMD_OPTIONAL, "check state of offline volumes");
5316 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name or number");
5317 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or number");
5318 cmd_AddParm(ts, "-state", CMD_SINGLE, CMD_OPTIONAL, "new volume state: online, busy, offline, down");
5320 ts = cmd_CreateSyntax("smbunicode", SmbUnicodeCmd, NULL, "enable or disable Unicode on new SMB connections");
5321 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable Unicode on new connections");
5322 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable Unicode on new connections");
5324 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL, "get file id for object(s) in afs");
5325 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5326 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5328 ts = cmd_CreateSyntax("chown", ChOwnCmd, NULL, "set owner for object(s) in afs");
5329 cmd_AddParm(ts, "-owner", CMD_SINGLE, 0, "user name or id");
5330 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5331 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5333 ts = cmd_CreateSyntax("chgrp", ChGrpCmd, NULL, "set owner for object(s) in afs");
5334 cmd_AddParm(ts, "-group", CMD_SINGLE, 0, "user/group name or id");
5335 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5336 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5338 code = cmd_Dispatch(argc, argv);
5343 FreeUtf8CmdLine(argc, argv);
5349 Die(int code, char *filename)
5352 if (code == EINVAL) {
5354 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
5356 fprintf(stderr,"%s: Invalid argument.\n", pn);
5358 else if (code == ENOENT) {
5360 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
5362 fprintf(stderr,"%s: no such file returned\n", pn);
5364 else if (code == EROFS)
5365 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
5366 else if (code == EACCES || code == EPERM) {
5368 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
5370 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
5372 else if (code == ENODEV) {
5373 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
5375 else if (code == ESRCH) { /* hack */
5376 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
5378 else if (code == EPIPE) { /* hack */
5379 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
5381 else if (code == EFBIG) {
5382 fprintf(stderr,"%s: Cache size too large.\n", pn);
5384 else if (code == ETIMEDOUT) {
5386 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
5388 fprintf(stderr,"%s: Connection timed out", pn);
5390 else if (code == EBUSY) {
5392 fprintf(stderr,"%s: All servers are busy on which '%s' resides\n", pn, filename);
5394 fprintf(stderr,"%s: All servers are busy\n", pn);
5396 else if (code == ENXIO) {
5398 fprintf(stderr,"%s: All volume instances are offline on which '%s' resides\n", pn, filename);
5400 fprintf(stderr,"%s: All volume instances are offline\n", pn);
5402 else if (code == ENOSYS) {
5404 fprintf(stderr,"%s: All servers are down on which '%s' resides\n", pn, filename);
5406 fprintf(stderr,"%s: All servers are down\n", pn);
5408 else if (code == ECHILD) { /* hack */
5410 fprintf(stderr,"%s: Invalid owner specified for '%s'\n", pn, filename);
5412 fprintf(stderr,"%s: Invalid owner specified\n", pn);
5416 fprintf(stderr,"%s:'%s'", pn, filename);
5418 fprintf(stderr,"%s", pn);
5420 fprintf(stderr, ": code 0x%x\n", code);
5421 #else /* not WIN32 */
5422 fprintf(stderr,": %s\n", afs_error_message(code));
5423 #endif /* not WIN32 */