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/cellconfig.h>
28 #include <afs/ptserver.h>
29 #include <afs/ptuser.h>
30 #include <afs/volser.h>
31 #include <WINNT\afsreg.h>
41 #define MAXCELLHOSTS 8
44 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
45 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
46 #define CELL_MAXNAMELEN 256
47 #define MAXHOSTCHARS 64
49 static char space[MAXSIZE];
50 static char tspace[1024];
52 static struct ubik_client *uclient;
54 static int GetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
55 static int SetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
56 static int FlushMountCmd(struct cmd_syndesc *asp, void *arock);
57 static int RxStatProcCmd(struct cmd_syndesc *asp, void *arock);
58 static int RxStatPeerCmd(struct cmd_syndesc *asp, void *arock);
60 extern struct cmd_syndesc *cmd_CreateSyntax();
62 static int MemDumpCmd(struct cmd_syndesc *asp, void *arock);
63 static int CSCPolicyCmd(struct cmd_syndesc *asp, void *arock);
64 static int MiniDumpCmd(struct cmd_syndesc *asp, void *arock);
66 static char pn[] = "fs";
67 static int rxInitDone = 0;
70 * Character to use between name and rights in printed representation for
73 #define DFS_SEPARATOR ' '
75 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
78 int dfs; /* Originally true if a dfs acl; now also the type
79 * of the acl (1, 2, or 3, corresponding to object,
80 * initial dir, or initial object). */
81 sec_rgy_name_t cell; /* DFS cell name */
84 struct AclEntry *pluslist;
85 struct AclEntry *minuslist;
89 struct AclEntry *next;
95 ZapAcl (struct Acl *acl)
100 ZapList(acl->pluslist);
101 ZapList(acl->minuslist);
106 * Mods for the AFS/DFS protocol translator.
108 * DFS rights. It's ugly to put these definitions here, but they
109 * *cannot* change, because they're part of the wire protocol.
110 * In any event, the protocol translator will guarantee these
111 * assignments for AFS cache managers.
113 #define DFS_READ 0x01
114 #define DFS_WRITE 0x02
115 #define DFS_EXECUTE 0x04
116 #define DFS_CONTROL 0x08
117 #define DFS_INSERT 0x10
118 #define DFS_DELETE 0x20
120 /* the application definable ones (backwards from AFS) */
121 #define DFS_USR0 0x80000000 /* "A" bit */
122 #define DFS_USR1 0x40000000 /* "B" bit */
123 #define DFS_USR2 0x20000000 /* "C" bit */
124 #define DFS_USR3 0x10000000 /* "D" bit */
125 #define DFS_USR4 0x08000000 /* "E" bit */
126 #define DFS_USR5 0x04000000 /* "F" bit */
127 #define DFS_USR6 0x02000000 /* "G" bit */
128 #define DFS_USR7 0x01000000 /* "H" bit */
129 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
130 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
133 * Offset of -id switch in command structure for various commands.
134 * The -if switch is the next switch always.
136 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
139 * Determine whether either the -id or -if switches are present, and
140 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
142 /* int id; Offset of -id switch; -if is next switch */
144 getidf(struct cmd_syndesc *as, int id)
148 if (as->parms[id].items) {
151 if (as->parms[id + 1].items) {
156 "%s: you may specify either -id or -if, but not both switches\n",
164 PRights(afs_int32 arights, int dfs)
167 if (arights & PRSFS_READ)
169 if (arights & PRSFS_LOOKUP)
171 if (arights & PRSFS_INSERT)
173 if (arights & PRSFS_DELETE)
175 if (arights & PRSFS_WRITE)
177 if (arights & PRSFS_LOCK)
179 if (arights & PRSFS_ADMINISTER)
181 if (arights & PRSFS_USR0)
183 if (arights & PRSFS_USR1)
185 if (arights & PRSFS_USR2)
187 if (arights & PRSFS_USR3)
189 if (arights & PRSFS_USR4)
191 if (arights & PRSFS_USR5)
193 if (arights & PRSFS_USR6)
195 if (arights & PRSFS_USR7)
198 if (arights & DFS_READ)
202 if (arights & DFS_WRITE)
206 if (arights & DFS_EXECUTE)
210 if (arights & DFS_CONTROL)
214 if (arights & DFS_INSERT)
218 if (arights & DFS_DELETE)
222 if (arights & (DFS_USRALL))
224 if (arights & DFS_USR0)
226 if (arights & DFS_USR1)
228 if (arights & DFS_USR2)
230 if (arights & DFS_USR3)
232 if (arights & DFS_USR4)
234 if (arights & DFS_USR5)
236 if (arights & DFS_USR6)
238 if (arights & DFS_USR7)
244 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
248 struct ViceIoctl blob;
249 cm_ioctlQueryOptions_t options;
253 memset(&options, 0, sizeof(options));
254 options.size = sizeof(options);
255 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
257 blob.in_size = options.size; /* no variable length data */
259 blob.out_size = sizeof(cm_fid_t);
260 blob.out = (char *) &fid;
262 code = pioctl_utf8(apath, VIOCGETFID, &blob, 1);
264 if ((errno == EINVAL) || (errno == ENOENT))
271 IsFreelanceRoot(char *apath)
273 struct ViceIoctl blob;
277 blob.out_size = MAXSIZE;
280 code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
282 return !cm_stricmp_utf8N("Freelance.Local.Root",space);
283 return 1; /* assume it is because it is more restrictive that way */
286 /* return a static pointer to a buffer */
291 strcpy(tspace, apath);
292 tp = strrchr(tspace, '\\');
294 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
297 fs_ExtractDriveLetter(apath, tspace);
303 enum rtype {add, destroy, deny};
306 Convert(char *arights, int dfs, enum rtype *rtypep)
312 *rtypep = add; /* add rights, by default */
315 if (!strcmp(arights, "null")) {
319 if (!strcmp(arights,"read"))
320 return DFS_READ | DFS_EXECUTE;
321 if (!strcmp(arights, "write"))
322 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
324 if (!strcmp(arights, "all"))
325 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
326 DFS_WRITE | DFS_CONTROL;
328 if (!strcmp(arights,"read"))
329 return PRSFS_READ | PRSFS_LOOKUP;
330 if (!strcmp(arights, "write"))
331 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
332 PRSFS_WRITE | PRSFS_LOCK;
333 if (!strcmp(arights, "mail"))
334 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
335 if (!strcmp(arights, "all"))
336 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
337 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
339 if (!strcmp(arights, "none")) {
340 *rtypep = destroy; /* Remove entire entry */
343 len = (int)strlen(arights);
379 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
387 mode |= PRSFS_LOOKUP;
389 mode |= PRSFS_INSERT;
391 mode |= PRSFS_DELETE;
397 mode |= PRSFS_ADMINISTER;
415 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
424 static struct AclEntry *
425 FindList (struct AclEntry *alist, char *aname)
428 if (!strcasecmp(alist->name, aname))
435 /* if no parm specified in a particular slot, set parm to be "." instead */
437 SetDotDefault(struct cmd_item **aitemp)
441 return; /* already has value */
442 /* otherwise, allocate an item representing "." */
443 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
445 ti->next = (struct cmd_item *) 0;
446 ti->data = (char *) malloc(2);
448 strcpy(ti->data, ".");
453 ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
455 struct AclEntry *tlist;
456 tlist = (plus ? al->pluslist : al->minuslist);
457 tlist = FindList (tlist, aname);
459 /* Found the item already in the list. */
460 tlist->rights = arights;
462 al->nplus -= PruneList(&al->pluslist, al->dfs);
464 al->nminus -= PruneList(&al->minuslist, al->dfs);
467 /* Otherwise we make a new item and plug in the new data. */
468 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
470 strcpy(tlist->name, aname);
471 tlist->rights = arights;
473 tlist->next = al->pluslist;
474 al->pluslist = tlist;
476 if (arights == 0 || arights == -1)
477 al->nplus -= PruneList(&al->pluslist, al->dfs);
479 tlist->next = al->minuslist;
480 al->minuslist = tlist;
483 al->nminus -= PruneList(&al->minuslist, al->dfs);
488 ZapList (struct AclEntry *alist)
490 struct AclEntry *tp, *np;
491 for (tp = alist; tp; tp = np) {
498 PruneList (struct AclEntry **ae, int dfs)
500 struct AclEntry **lp;
501 struct AclEntry *te, *ne;
505 for(te = *ae;te;te=ne) {
506 if ((!dfs && te->rights == 0) || te->rights == -1) {
520 SkipLine (char *astr)
529 * Create an empty acl, taking into account whether the acl pointed
530 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
531 * can recover from problems caused by bogus ACL's (in that case, always
532 * assume that the acl is AFS: for DFS, the user can always resort to
533 * acl_edit, but for AFS there may be no other way out).
541 tp = (struct Acl *)malloc(sizeof (struct Acl));
543 tp->nplus = tp->nminus = 0;
544 tp->pluslist = tp->minuslist = 0;
546 if (astr == NULL || sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell) <= 0) {
554 ParseAcl (char *astr)
556 int nplus, nminus, i, trights, ret;
558 struct AclEntry *first, *next, *last, *tl;
562 if (astr == NULL || strlen(astr) == 0)
565 ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
570 astr = SkipLine(astr);
571 ret = sscanf(astr, "%d", &ta->nminus);
576 astr = SkipLine(astr);
583 for(i=0;i<nplus;i++) {
584 ret = sscanf(astr, "%100s %d", tname, &trights);
587 astr = SkipLine(astr);
588 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
593 strcpy(tl->name, tname);
594 tl->rights = trights;
600 ta->pluslist = first;
604 for(i=0;i<nminus;i++) {
605 ret = sscanf(astr, "%100s %d", tname, &trights);
608 astr = SkipLine(astr);
609 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
614 strcpy(tl->name, tname);
615 tl->rights = trights;
621 ta->minuslist = first;
626 for (;first; first = next) {
630 first = ta->pluslist;
633 for (;first; first = next) {
642 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
644 printf("Volume status for vid = %u named %s is\n",status->Vid, name);
646 printf("Current offline message is %s\n",offmsg);
648 printf("Current message of the day is %s\n",motd);
649 printf("Current disk quota is ");
650 if (status->MaxQuota != 0)
651 printf("%d\n", status->MaxQuota);
653 printf("unlimited\n");
654 printf("Current blocks used are %d\n",status->BlocksInUse);
655 printf("The partition has %d blocks available out of %d\n",
656 status->PartBlocksAvail, status->PartMaxBlocks);
661 QuickPrintStatus(VolumeStatus *status, char *name)
663 double QuotaUsed =0.0;
664 double PartUsed =0.0;
666 printf("%-25.25s",name);
668 if (status->MaxQuota != 0) {
669 printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
670 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
672 printf(" no limit %10d", status->BlocksInUse);
674 if (QuotaUsed > 90.0){
675 printf(" %5.0f%%<<", QuotaUsed);
678 printf(" %5.0f%% ", QuotaUsed);
679 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
680 if (PartUsed > 97.0){
681 printf(" %9.0f%%<<", PartUsed);
684 printf(" %9.0f%% ", PartUsed);
686 printf(" <<WARNING\n");
693 QuickPrintSpace(VolumeStatus *status, char *name)
695 double PartUsed =0.0;
697 printf("%-25.25s",name);
699 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
701 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
702 if (PartUsed > 90.0){
703 printf(" %4.0f%%<<", PartUsed);
706 printf(" %4.0f%% ", PartUsed);
708 printf(" <<WARNING\n");
715 AclToString(struct Acl *acl)
717 static char mydata[MAXSIZE];
718 char tstring[MAXSIZE];
723 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
726 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
727 for (tp = acl->pluslist;tp;tp=tp->next) {
728 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
729 strcat(mydata, tstring);
731 for (tp = acl->minuslist;tp;tp=tp->next) {
732 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
733 strcat(mydata, tstring);
738 static DWORD IsFreelance(void)
745 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
746 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
747 if (code == ERROR_SUCCESS) {
748 dummyLen = sizeof(cm_freelanceEnabled);
749 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
750 (BYTE *) &enabled, &dummyLen);
751 RegCloseKey (parmKey);
756 static const char * NetbiosName(void)
758 static char buffer[1024] = "AFS";
764 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
765 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
766 if (code == ERROR_SUCCESS) {
767 dummyLen = sizeof(buffer);
768 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
770 RegCloseKey (parmKey);
772 strcpy(buffer, "AFS");
777 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
779 static BOOL IsAdmin (void)
781 static BOOL fAdmin = FALSE;
782 static BOOL fTested = FALSE;
786 /* Obtain the SID for the AFS client admin group. If the group does
787 * not exist, then assume we have AFS client admin privileges.
789 PSID psidAdmin = NULL;
790 DWORD dwSize, dwSize2;
791 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
792 char *pszRefDomain = NULL;
793 SID_NAME_USE snu = SidTypeGroup;
795 dwSize = sizeof(pszAdminGroup);
797 if (!GetComputerName(pszAdminGroup, &dwSize)) {
798 /* Can't get computer name. We return false in this case.
799 Retain fAdmin and fTested. This shouldn't happen.*/
806 strcat(pszAdminGroup,"\\");
807 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
809 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
810 /* that should always fail. */
812 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
813 /* if we can't find the group, then we allow the operation */
818 if (dwSize == 0 || dwSize2 == 0) {
824 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
826 pszRefDomain = (char *)malloc(dwSize2);
827 assert(pszRefDomain);
829 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
830 /* We can't lookup the group now even though we looked it up earlier.
831 Could this happen? */
834 /* Then open our current ProcessToken */
837 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
840 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
841 /* We'll have to allocate a chunk of memory to store the list of
842 * groups to which this user belongs; find out how much memory
846 PTOKEN_GROUPS pGroups;
848 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
850 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
853 /* Allocate that buffer, and read in the list of groups. */
854 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
856 /* Look through the list of group SIDs and see if any of them
857 * matches the AFS Client Admin group SID.
860 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
862 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
872 /* if do not have permission because we were not explicitly listed
873 * in the Admin Client Group let's see if we are the SYSTEM account
876 PTOKEN_USER pTokenUser;
877 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
878 PSID pSidLocalSystem = 0;
881 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
883 pTokenUser = (PTOKEN_USER)malloc(dwSize);
886 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
887 gle = GetLastError();
889 if (AllocateAndInitializeSid( &SIDAuth, 1,
890 SECURITY_LOCAL_SYSTEM_RID,
894 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
898 FreeSid(pSidLocalSystem);
917 SetACLCmd(struct cmd_syndesc *as, void *arock)
920 struct ViceIoctl blob;
922 struct cmd_item *ti, *ui;
926 int idf = getidf(as, parm_setacl_id);
930 if (as->parms[2].items)
934 plusp = !(as->parms[3].items);
935 for(ti=as->parms[0].items; ti;ti=ti->next) {
936 blob.out_size = MAXSIZE;
938 blob.in = blob.out = space;
939 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
941 Die(errno, ti->data);
947 ta = ParseAcl(space);
950 "fs: %s: invalid acl data returned from VIOCGETAL\n",
955 if (!plusp && ta->dfs) {
957 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
959 "(you may specify \"null\" to revoke all rights, however)\n");
966 ta = EmptyAcl(space);
968 ta = ParseAcl(space);
971 "fs: %s: invalid acl data returned from VIOCGETAL\n",
976 CleanAcl(ta, ti->data);
977 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
981 "%s: Missing second half of user/access pair.\n", pn);
985 rights = Convert(ui->next->data, ta->dfs, &rtype);
986 if (rtype == destroy && !ta->dfs) {
987 struct AclEntry *tlist;
989 tlist = (plusp ? ta->pluslist : ta->minuslist);
990 if (!FindList(tlist, ui->data))
993 if (rtype == deny && !ta->dfs)
995 if (rtype == destroy && ta->dfs)
997 ChangeList(ta, plusp, ui->data, rights);
999 blob.in = AclToString(ta);
1001 blob.in_size = 1+(long)strlen(blob.in);
1002 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1004 if (errno == EINVAL) {
1006 static char *fsenv = 0;
1008 fsenv = (char *)getenv("FS_EXPERT");
1010 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
1013 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1014 "\nPossible reasons for this include:\n\n",
1015 " -You may have specified an inappropriate combination of rights.\n",
1016 " For example, some DFS-supported filesystems may not allow you to\n",
1017 " drop the \"c\" right from \"user_obj\".\n\n",
1018 " -A mask_obj may be required (it is likely required by the underlying\n",
1019 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
1020 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
1021 " does not automatically create or update the mask_obj. Try setting\n",
1022 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
1023 " users or groups. You can do this with a single command, such as\n",
1024 " \"fs sa mask_obj all user:somename read\"\n\n",
1025 " -A specified user or group may not exist.\n\n",
1026 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
1027 " This is probably not allowed by the underlying file system.\n\n",
1028 " -If you add a user or group to a DFS ACL, remember that it must be\n",
1029 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
1030 " may be local requirements on the format of the user or group name.\n",
1031 " Check with your cell administrator.\n\n",
1032 " -Or numerous other possibilities. It would be great if we could be more\n",
1033 " precise about the actual problem, but for various reasons, this is\n",
1034 " impractical via this interface. If you can't figure it out, you\n",
1035 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
1036 " whatever is provided). You may get better results. Good luck!\n\n",
1037 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
1041 "%s: Invalid argument, possible reasons include:\n",
1043 fprintf(stderr,"\t-File not in AFS\n");
1045 "\t-Too many users on access control list\n");
1047 "\t-Tried to add non-existent user to access control list\n");
1050 Die(errno, ti->data);
1061 CopyACLCmd(struct cmd_syndesc *as, void *arock)
1064 struct ViceIoctl blob;
1065 struct Acl *fa, *ta = 0;
1066 struct AclEntry *tp;
1067 struct cmd_item *ti;
1069 int idf = getidf(as, parm_copyacl_id);
1072 if (as->parms[2].items)
1076 blob.out_size = MAXSIZE;
1078 blob.in = blob.out = space;
1079 code = pioctl_utf8(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1081 Die(errno, as->parms[0].items->data);
1084 fa = ParseAcl(space);
1087 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1088 as->parms[0].items->data);
1091 CleanAcl(fa, as->parms[0].items->data);
1092 for (ti=as->parms[1].items; ti;ti=ti->next) {
1093 blob.out_size = MAXSIZE;
1095 blob.in = blob.out = space;
1096 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1098 Die(errno, ti->data);
1105 ta = EmptyAcl(space);
1107 ta = ParseAcl(space);
1110 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1115 CleanAcl(ta, ti->data);
1116 if (ta->dfs != fa->dfs) {
1118 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1124 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1126 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1131 strcpy(ta->cell, fa->cell);
1133 for (tp = fa->pluslist;tp;tp=tp->next)
1134 ChangeList(ta, 1, tp->name, tp->rights);
1135 for (tp = fa->minuslist;tp;tp=tp->next)
1136 ChangeList(ta, 0, tp->name, tp->rights);
1137 blob.in = AclToString(ta);
1139 blob.in_size = 1+(long)strlen(blob.in);
1140 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1142 if (errno == EINVAL) {
1144 "%s: Invalid argument, possible reasons include:\n", pn);
1145 fprintf(stderr,"\t-File not in AFS\n");
1147 Die(errno, ti->data);
1158 /* pioctl_utf8() call to get the cellname of a pathname */
1160 GetCell(char *fname, char *cellname)
1163 struct ViceIoctl blob;
1166 blob.out_size = CELL_MAXNAMELEN;
1167 blob.out = cellname;
1169 code = pioctl_utf8(fname, VIOC_FILE_CELL_NAME, &blob, 1);
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 = 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 = 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",
1378 printf("Access list for %s is\n", ti->data);
1381 printf("DFS access list for %s is\n", ti->data);
1384 printf("DFS initial directory access list of %s is\n", ti->data);
1387 printf("DFS initial file access list of %s is\n", ti->data);
1391 printf(" Default cell = %s\n", ta->cell);
1393 separator = ta->dfs? DFS_SEPARATOR : ' ';
1394 if (ta->nplus > 0) {
1396 printf("Normal rights:\n");
1397 for(te = ta->pluslist;te;te=te->next) {
1398 printf(" %s%c", te->name, separator);
1399 PRights(te->rights, ta->dfs);
1403 if (ta->nminus > 0) {
1404 printf("Negative rights:\n");
1405 for(te = ta->minuslist;te;te=te->next) {
1406 printf(" %s ", te->name);
1407 PRights(te->rights, ta->dfs);
1419 FlushAllCmd(struct cmd_syndesc *as, void *arock)
1422 struct ViceIoctl blob;
1424 blob.in_size = blob.out_size = 0;
1425 code = pioctl_utf8(NULL, VIOC_FLUSHALL, &blob, 0);
1427 fprintf(stderr, "Error flushing all ");
1434 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1437 struct ViceIoctl blob;
1438 struct cmd_item *ti;
1441 SetDotDefault(&as->parms[0].items);
1442 for(ti=as->parms[0].items; ti; ti=ti->next) {
1443 blob.in_size = blob.out_size = 0;
1444 code = pioctl_utf8(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1446 fprintf(stderr, "Error flushing volume ");
1456 FlushCmd(struct cmd_syndesc *as, void *arock)
1459 struct ViceIoctl blob;
1460 struct cmd_item *ti;
1463 cm_ioctlQueryOptions_t options;
1465 if (as->parms[1].items)
1468 for(ti=as->parms[0].items; ti; ti=ti->next) {
1470 memset(&options, 0, sizeof(options));
1471 options.size = sizeof(options);
1472 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1473 options.literal = literal;
1474 blob.in_size = options.size; /* no variable length data */
1478 code = pioctl_utf8(ti->data, VIOCFLUSH, &blob, 0);
1480 if (errno == EMFILE) {
1481 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1484 fprintf(stderr, "%s: Error flushing file ", pn);
1494 /* all this command does is repackage its args and call SetVolCmd */
1496 SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
1497 struct cmd_syndesc ts;
1499 /* copy useful stuff from our command slot; we may later have to reorder */
1500 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1501 return SetVolCmd(&ts, arock);
1505 SetVolCmd(struct cmd_syndesc *as, void *arock) {
1507 struct ViceIoctl blob;
1508 struct cmd_item *ti;
1509 struct VolumeStatus *status;
1510 char *motd, *offmsg, *input;
1513 SetDotDefault(&as->parms[0].items);
1514 for(ti=as->parms[0].items; ti; ti=ti->next) {
1516 blob.out_size = MAXSIZE;
1517 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1520 status = (VolumeStatus *)space;
1521 status->MinQuota = status->MaxQuota = -1;
1522 motd = offmsg = NULL;
1523 if (as->parms[1].items) {
1524 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1526 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1531 if (as->parms[2].items)
1532 motd = as->parms[2].items->data;
1533 if (as->parms[3].items)
1534 offmsg = as->parms[3].items->data;
1535 input = (char *)status + sizeof(*status);
1536 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1538 if (strlen(offmsg) >= VMSGSIZE) {
1539 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1544 strcpy(input,offmsg);
1545 blob.in_size += (long)strlen(offmsg);
1546 input += strlen(offmsg) + 1;
1550 if (strlen(motd) >= VMSGSIZE) {
1551 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1556 blob.in_size += (long)strlen(motd);
1557 input += strlen(motd) + 1;
1560 code = pioctl_utf8(ti->data,VIOCSETVOLSTAT, &blob, 1);
1562 Die(errno, ti->data);
1569 /* values match cache manager File Types */
1571 filetypestr(afs_uint32 type)
1573 char * s = "Object";
1596 ExamineCmd(struct cmd_syndesc *as, void *arock)
1599 struct ViceIoctl blob;
1600 struct cmd_item *ti;
1601 struct VolumeStatus *status;
1602 char *name, *offmsg, *motd;
1605 cm_ioctlQueryOptions_t options;
1607 if (as->parms[1].items)
1610 SetDotDefault(&as->parms[0].items);
1611 for(ti=as->parms[0].items; ti; ti=ti->next) {
1613 afs_uint32 filetype;
1614 afs_uint32 owner[2];
1615 char cell[CELL_MAXNAMELEN];
1618 memset(&fid, 0, sizeof(fid));
1619 memset(&options, 0, sizeof(options));
1621 options.size = sizeof(options);
1622 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1623 options.literal = literal;
1624 blob.in_size = options.size; /* no variable length data */
1627 blob.out_size = sizeof(cm_fid_t);
1628 blob.out = (char *) &fid;
1629 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
1630 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1633 Die(errno, ti->data);
1638 blob.out_size = sizeof(filetype);
1639 blob.out = &filetype;
1641 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1643 blob.out_size = CELL_MAXNAMELEN;
1646 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1647 printf("%s %s (%u.%u.%u) contained in cell %s\n",
1648 filetypestr(filetype),
1649 ti->data, fid.volume, fid.vnode, fid.unique,
1650 code ? "unknown-cell" : cell);
1652 blob.out_size = 2 * sizeof(afs_uint32);
1653 blob.out = (char *) &owner;
1654 if (0 == pioctl_utf8(ti->data, VIOCGETOWNER, &blob, 1)) {
1655 char oname[PR_MAXNAMELEN] = "(unknown)";
1656 char gname[PR_MAXNAMELEN] = "(unknown)";
1659 /* Go to the PRDB and see if this all number username is valid */
1660 cm_GetConfigDir(confDir, sizeof(confDir));
1662 pr_Initialize(1, confDir, cell);
1663 pr_SIdToName(owner[0], oname);
1664 pr_SIdToName(owner[1], gname);
1665 printf("Owner %s (%u) Group %s (%u)\n", oname, owner[0], gname, owner[1]);
1669 blob.out_size = MAXSIZE;
1670 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1672 status = (VolumeStatus *)space;
1673 name = (char *)status + sizeof(*status);
1674 offmsg = name + strlen(name) + 1;
1675 motd = offmsg + strlen(offmsg) + 1;
1677 PrintStatus(status, name, motd, offmsg);
1679 Die(errno, ti->data);
1683 code = pioctl_utf8(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
1686 printf("Volume is online\n");
1689 printf("Volume is offline\n");
1692 printf("All Volume servers are down\n");
1695 printf("All volume servers are busy\n");
1698 printf("Unknown volume state\n");
1699 Die(errno, ti->data);
1707 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1710 struct ViceIoctl blob;
1711 struct cmd_item *ti;
1712 struct VolumeStatus *status;
1717 printf("%-25s%-11s%-11s%-7s%-13s\n", "Volume Name", " Quota",
1718 " Used", " %Used", " Partition");
1719 SetDotDefault(&as->parms[0].items);
1720 for(ti=as->parms[0].items; ti; ti=ti->next) {
1722 blob.out_size = MAXSIZE;
1725 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1727 Die(errno, ti->data);
1731 status = (VolumeStatus *)space;
1732 name = (char *)status + sizeof(*status);
1733 QuickPrintStatus(status, name);
1739 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1742 struct ViceIoctl blob;
1743 struct cmd_item *ti;
1749 cm_ioctlQueryOptions_t options;
1751 if (as->parms[1].items)
1754 SetDotDefault(&as->parms[0].items);
1755 for(ti=as->parms[0].items; ti; ti=ti->next) {
1757 afs_uint32 filetype;
1760 memset(&fid, 0, sizeof(fid));
1761 memset(&options, 0, sizeof(options));
1763 options.size = sizeof(options);
1764 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1765 options.literal = literal;
1766 blob.in_size = options.size; /* no variable length data */
1769 blob.out_size = sizeof(cm_fid_t);
1770 blob.out = (char *) &fid;
1771 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
1772 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1775 Die(errno, ti->data);
1780 blob.out_size = sizeof(filetype);
1781 blob.out = &filetype;
1783 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1785 blob.out_size = MAXSIZE;
1787 memset(space, 0, sizeof(space));
1788 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
1790 Die(errno, ti->data);
1794 hosts = (afs_int32 *) space;
1795 printf("%s %s is on host%s ",
1796 filetypestr(filetype),
1798 (hosts[0] && !hosts[1]) ? "": "s");
1799 for(j=0; j<MAXHOSTS; j++) {
1802 tp = hostutil_GetNameByINet(hosts[j]);
1812 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1815 struct ViceIoctl blob;
1816 struct cmd_item *ti;
1818 struct VolumeStatus *status;
1821 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1822 " used", " avail", " %used");
1823 SetDotDefault(&as->parms[0].items);
1824 for(ti=as->parms[0].items; ti; ti=ti->next) {
1826 blob.out_size = MAXSIZE;
1829 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1831 Die(errno, ti->data);
1835 status = (VolumeStatus *)space;
1836 name = (char *)status + sizeof(*status);
1837 QuickPrintSpace(status, name);
1843 QuotaCmd(struct cmd_syndesc *as, void *arock)
1846 struct ViceIoctl blob;
1847 struct cmd_item *ti;
1849 struct VolumeStatus *status;
1852 SetDotDefault(&as->parms[0].items);
1853 for(ti=as->parms[0].items; ti; ti=ti->next) {
1855 blob.out_size = MAXSIZE;
1858 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1860 Die(errno, ti->data);
1864 status = (VolumeStatus *)space;
1865 if (status->MaxQuota)
1866 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1869 printf("%2.0f%% of quota used.\n", quotaPct);
1875 ListMountCmd(struct cmd_syndesc *as, void *arock)
1878 struct ViceIoctl blob;
1879 struct cmd_item *ti;
1880 char orig_name[1024]; /*Original name, may be modified*/
1881 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1882 char parent_dir[1024]; /*Parent directory of true name*/
1883 char *last_component; /*Last component of true name*/
1885 struct stat statbuff; /*Buffer for status info*/
1886 #endif /* not WIN32 */
1888 int link_chars_read; /*Num chars read in readlink()*/
1889 #endif /* not WIN32 */
1890 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1893 for(ti=as->parms[0].items; ti; ti=ti->next) {
1897 strcpy(orig_name, ti->data);
1898 #else /* not WIN32 */
1899 sprintf(orig_name, "%s%s",
1900 (ti->data[0] == '/') ? "" : "./",
1902 #endif /* not WIN32 */
1905 if (lstat(orig_name, &statbuff) < 0) {
1906 /* if lstat fails, we should still try the pioctl, since it
1907 * may work (for example, lstat will fail, but pioctl will
1908 * work if the volume of offline (returning ENODEV). */
1909 statbuff.st_mode = S_IFDIR; /* lie like pros */
1913 * The lstat succeeded. If the given file is a symlink, substitute
1914 * the file name with the link name.
1916 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1919 * Read name of resolved file.
1921 link_chars_read = readlink(orig_name, true_name, 1024);
1922 if (link_chars_read <= 0) {
1924 "%s: Can't read target name for '%s' symbolic link!\n",
1931 * Add a trailing null to what was read, bump the length.
1933 true_name[link_chars_read++] = 0;
1936 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1937 * have to create a full pathname using the original name and the
1938 * relative symlink name. Find the rightmost slash in the original
1939 * name (we know there is one) and splice in the symlink value.
1941 if (true_name[0] != '\\') {
1942 last_component = (char *) strrchr(orig_name, '\\');
1943 strcpy(++last_component, true_name);
1944 strcpy(true_name, orig_name);
1947 strcpy(true_name, orig_name);
1949 strcpy(true_name, orig_name);
1953 * Find rightmost slash, if any.
1956 last_component = (char *) strrchr(true_name, '\\');
1957 if (!last_component)
1959 last_component = (char *) strrchr(true_name, '/');
1960 if (last_component) {
1962 * Found it. Designate everything before it as the parent directory,
1963 * everything after it as the final component.
1965 strncpy(parent_dir, true_name, last_component - true_name + 1);
1966 parent_dir[last_component - true_name + 1] = 0;
1967 last_component++; /*Skip the slash*/
1969 if (!InAFS(parent_dir)) {
1970 const char * nbname = NetbiosName();
1971 int len = (int)strlen(nbname);
1973 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
1974 parent_dir[len+2] == '\\' &&
1975 parent_dir[len+3] == '\0' &&
1976 !strnicmp(nbname,&parent_dir[2],len))
1978 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
1984 * No slash appears in the given file name. Set parent_dir to the current
1985 * directory, and the last component as the given name.
1987 fs_ExtractDriveLetter(true_name, parent_dir);
1988 strcat(parent_dir, ".");
1989 last_component = true_name;
1990 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1993 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1994 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
1995 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
2000 blob.in = last_component;
2001 blob.in_size = (long)strlen(last_component)+1;
2002 blob.out_size = MAXSIZE;
2004 memset(space, 0, MAXSIZE);
2006 code = pioctl_utf8(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
2009 printf("'%s' is a %smount point for volume '%s'\n",
2011 (thru_symlink ? "symbolic link, leading to a " : ""),
2015 if (errno == EINVAL) {
2016 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
2018 Die(errno, (ti->data ? ti->data : parent_dir));
2027 MakeMountCmd(struct cmd_syndesc *as, void *arock)
2030 char *cellName, *volName, *tmpName;
2032 char localCellName[128];
2034 char path[1024] = "";
2035 struct afsconf_cell info;
2036 struct vldbentry vldbEntry;
2037 struct ViceIoctl blob;
2040 memset(&info, 0, sizeof(info));
2042 if (as->parms[2].items) /* cell name specified */
2043 cellName = as->parms[2].items->data;
2046 volName = as->parms[1].items->data;
2048 if (strlen(volName) >= 64) {
2049 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
2053 /* Check for a cellname in the volume specification, and complain
2054 * if it doesn't match what was specified with -cell */
2055 if (tmpName = strchr(volName, ':')) {
2058 if (strcasecmp(cellName,volName)) {
2059 fprintf(stderr,"fs: cellnames do not match.\n");
2064 volName = ++tmpName;
2067 parent = Parent(as->parms[0].items->data);
2068 if (!InAFS(parent)) {
2070 const char * nbname = NetbiosName();
2071 int len = (int)strlen(nbname);
2073 if (parent[0] == '\\' && parent[1] == '\\' &&
2074 parent[len+2] == '\\' &&
2075 parent[len+3] == '\0' &&
2076 !strnicmp(nbname,&parent[2],len))
2078 sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
2079 parent = Parent(path);
2080 if (!InAFS(parent)) {
2081 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2087 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2092 if ( strlen(path) == 0 )
2093 strcpy(path, as->parms[0].items->data);
2095 if ( IsFreelanceRoot(parent) ) {
2097 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2103 blob.out_size = sizeof(localCellName);
2104 blob.out = localCellName;
2105 code = pioctl_utf8(parent, VIOC_GET_WS_CELL, &blob, 1);
2107 cellName = localCellName;
2111 code = GetCell(parent,space);
2117 code = GetCellName(cellName?cellName:space, &info);
2121 if (!(as->parms[4].items)) {
2122 /* not fast, check which cell the mountpoint is being created in */
2124 /* not fast, check name with VLDB */
2126 code = VLDBInit(1, &info);
2128 /* make the check. Don't complain if there are problems with init */
2129 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2130 if (code == VL_NOENT) {
2131 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2132 pn, volName, cellName ? cellName : space);
2137 if (as->parms[3].items) /* if -rw specified */
2142 /* cellular mount point, prepend cell prefix */
2143 strcat(space, info.name);
2146 strcat(space, volName); /* append volume name */
2147 strcat(space, "."); /* stupid convention; these end with a period */
2149 /* create symlink with a special pioctl for Windows NT, since it doesn't
2150 * have a symlink system call.
2153 blob.in_size = 1 + (long)strlen(space);
2156 code = pioctl_utf8(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2157 #else /* not WIN32 */
2158 code = symlink(space, path);
2159 #endif /* not WIN32 */
2161 if (info.linkedCell)
2162 free(info.linkedCell);
2172 * Delete AFS mount points. Variables are used as follows:
2173 * tbuffer: Set to point to the null-terminated directory name of the mount point
2174 * (or ``.'' if none is provided)
2175 * tp: Set to point to the actual name of the mount point to nuke.
2178 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2180 struct ViceIoctl blob;
2181 struct cmd_item *ti;
2183 char lsbuffer[1024];
2187 for(ti=as->parms[0].items; ti; ti=ti->next) {
2189 tp = (char *) strrchr(ti->data, '\\');
2191 tp = (char *) strrchr(ti->data, '/');
2193 strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1)); /* the dir name */
2195 tp++; /* skip the slash */
2198 if (!InAFS(tbuffer)) {
2199 const char * nbname = NetbiosName();
2200 int len = (int)strlen(nbname);
2202 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2203 tbuffer[len+2] == '\\' &&
2204 tbuffer[len+3] == '\0' &&
2205 !strnicmp(nbname,&tbuffer[2],len))
2207 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
2212 fs_ExtractDriveLetter(ti->data, tbuffer);
2213 strcat(tbuffer, ".");
2215 fs_StripDriveLetter(tp, tp, 0);
2218 blob.in_size = (long)strlen(tp)+1;
2219 blob.out = lsbuffer;
2220 blob.out_size = sizeof(lsbuffer);
2221 code = pioctl_utf8(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2223 if (errno == EINVAL) {
2224 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2226 Die(errno, ti->data);
2229 continue; /* don't bother trying */
2232 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2233 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2235 continue; /* skip */
2240 blob.in_size = (long)strlen(tp)+1;
2241 code = pioctl_utf8(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2243 Die(errno, ti->data);
2254 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2257 struct ViceIoctl blob;
2261 struct afsconf_cell info;
2262 struct chservinfo checkserv;
2264 memset(&info, 0, sizeof(info));
2265 memset(&checkserv, 0, sizeof(struct chservinfo));
2266 blob.in_size=sizeof(struct chservinfo);
2267 blob.in=(caddr_t)&checkserv;
2269 blob.out_size = MAXSIZE;
2271 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2273 /* prepare flags for checkservers command */
2274 temp = 2; /* default to checking local cell only */
2275 if (as->parms[2].items)
2276 temp |= 1; /* set fast flag */
2277 if (as->parms[1].items)
2278 temp &= ~2; /* turn off local cell check */
2280 checkserv.magic = 0x12345678; /* XXX */
2281 checkserv.tflags=temp;
2283 /* now copy in optional cell name, if specified */
2284 if (as->parms[0].items) {
2285 code = GetCellName(as->parms[0].items->data, &info);
2289 strcpy(checkserv.tbuffer,info.name);
2290 checkserv.tsize=(int)strlen(info.name)+1;
2291 if (info.linkedCell)
2292 free(info.linkedCell);
2294 strcpy(checkserv.tbuffer,"\0");
2298 if(as->parms[3].items) {
2299 checkserv.tinterval=atol(as->parms[3].items->data);
2302 if(checkserv.tinterval<0) {
2303 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2304 checkserv.tinterval=-1;
2305 } else if(checkserv.tinterval> 600) {
2306 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2307 checkserv.tinterval=600; /* 10 min max interval */
2310 checkserv.tinterval = -1; /* don't change current interval */
2313 if ( checkserv.tinterval >= 0 ) {
2316 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2321 fprintf (stderr,"Permission denied: requires root access.\n");
2327 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
2329 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2330 printf("Must be root to change -interval\n");
2336 memcpy(&temp, space, sizeof(afs_int32));
2337 if (checkserv.tinterval >= 0) {
2338 if (checkserv.tinterval > 0)
2339 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2340 checkserv.tinterval, temp);
2342 printf("The current down server probe interval is %d secs\n", temp);
2346 printf("All servers are running.\n");
2348 printf("These servers unavailable due to network or server problems: ");
2349 for(j=0; j < MAXHOSTS; j++) {
2350 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2353 tp = hostutil_GetNameByINet(temp);
2363 MessagesCmd(struct cmd_syndesc *as, void *arock)
2366 struct ViceIoctl blob;
2367 struct gaginfo gagflags;
2368 struct cmd_item *show;
2370 memset(&gagflags, 0, sizeof(struct gaginfo));
2371 blob.in_size = sizeof(struct gaginfo);
2372 blob.in = (caddr_t ) &gagflags;
2373 blob.out_size = MAXSIZE;
2375 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2377 if (show = as->parms[0].items) {
2378 if (!strcasecmp (show->data, "user"))
2379 gagflags.showflags |= GAGUSER;
2380 else if (!strcasecmp (show->data, "console"))
2381 gagflags.showflags |= GAGCONSOLE;
2382 else if (!strcasecmp (show->data, "all"))
2383 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2384 else if (!strcasecmp (show->data, "none"))
2388 "unrecognized flag %s: must be in {user,console,all,none}\n",
2397 code = pioctl_utf8(0, VIOC_GAG, &blob, 1);
2406 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2409 struct ViceIoctl blob;
2413 code = pioctl_utf8(0, VIOCCKBACK, &blob, 1);
2418 printf("All volumeID/name mappings checked.\n");
2424 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2427 struct ViceIoctl blob;
2432 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2437 fprintf (stderr,"Permission denied: requires root access.\n");
2442 if (!as->parms[0].items && !as->parms[1].items) {
2443 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2446 if (as->parms[0].items) {
2447 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2449 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2454 blob.in = (char *) &temp;
2455 blob.in_size = sizeof(afs_int32);
2457 code = pioctl_utf8(0, VIOCSETCACHESIZE, &blob, 1);
2459 Die(errno, (char *) 0);
2463 printf("New cache size set.\n");
2468 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2471 struct ViceIoctl blob;
2472 cm_cacheParms_t parms;
2474 memset(&parms, 0, sizeof(parms));
2477 blob.out_size = sizeof(parms);
2478 blob.out = (char *) &parms;
2479 code = pioctl_utf8(0, VIOCGETCACHEPARMS, &blob, 1);
2485 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2486 parms.parms[1], parms.parms[0]);
2487 if (parms.parms[1] > parms.parms[0])
2488 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2493 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2496 afs_int32 i, j, *lp, magic, size;
2498 afs_int32 addr, maxa = OMAXHOSTS;
2499 struct ViceIoctl blob;
2502 resolve = !(as->parms[0].items); /* -numeric */
2504 for(i=0;i<1000;i++) {
2506 memcpy(tp, &i, sizeof(afs_int32));
2507 tp = (char *)(space + sizeof(afs_int32));
2508 lp = (afs_int32 *)tp;
2510 size = sizeof(afs_int32) + sizeof(afs_int32);
2511 blob.out_size = MAXSIZE;
2512 blob.in_size = sizeof(afs_int32);
2515 code = pioctl_utf8(0, VIOCGETCELL, &blob, 1);
2518 break; /* done with the list */
2523 memcpy(&magic, tp, sizeof(afs_int32));
2524 if (magic == 0x12345678) {
2526 tp += sizeof(afs_int32);
2528 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2529 for(j=0; j < maxa; j++) {
2530 char *name, tbuffer[20];
2532 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2537 name = hostutil_GetNameByINet(addr);
2540 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2541 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2544 printf(" %s", name);
2553 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2556 char *tp, *aliasName, *realName;
2557 struct ViceIoctl blob;
2561 memcpy(tp, &i, sizeof(afs_int32));
2562 blob.out_size = MAXSIZE;
2563 blob.in_size = sizeof(afs_int32);
2566 code = pioctl_utf8(0, VIOC_GETALIAS, &blob, 1);
2569 break; /* done with the list */
2575 tp += strlen(aliasName) + 1;
2577 printf("Alias %s for cell %s\n", aliasName, realName);
2583 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2586 struct ViceIoctl blob;
2587 struct cmd_item *ti;
2589 struct hostent *thp;
2593 ti = as->parms[0].items;
2596 thp = hostutil_GetHostByName(ti->data);
2598 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2601 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2603 hostAddr = 0; /* means don't set host */
2604 setp = 0; /* aren't setting host */
2607 /* now do operation */
2608 blob.in_size = sizeof(afs_int32);
2609 blob.out_size = sizeof(afs_int32);
2610 blob.in = (char *) &hostAddr;
2611 blob.out = (char *) &hostAddr;
2613 code = pioctl_utf8(0, VIOC_CBADDR, &blob, 1);
2623 NewCellCmd(struct cmd_syndesc *as, void *arock)
2626 afs_int32 code, linkedstate=0, size=0, *lp;
2627 struct ViceIoctl blob;
2628 struct cmd_item *ti;
2629 char *tp, *cellname=0;
2630 struct hostent *thp;
2631 afs_int32 fsport = 0, vlport = 0;
2633 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
2635 lp = (afs_int32 *)tp;
2637 tp += sizeof(afs_int32);
2638 for(ti=as->parms[1].items; ti; ti=ti->next) {
2639 thp = hostutil_GetHostByName(ti->data);
2641 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2645 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2646 tp += sizeof(afs_int32);
2649 if (as->parms[2].items) {
2651 * Link the cell, for the purposes of volume location, to the specified
2654 cellname = as->parms[2].items->data;
2657 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2658 if (as->parms[3].items) {
2659 code = util_GetInt32(as->parms[3].items->data, &vlport);
2661 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2665 if (as->parms[4].items) {
2666 code = util_GetInt32(as->parms[4].items->data, &fsport);
2668 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2673 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
2674 lp = (afs_int32 *)tp;
2678 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2679 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2680 tp = (char *)(space + size);
2682 strcpy(tp, cellname);
2683 size += strlen(cellname) + 1;
2685 blob.in_size = size;
2688 code = pioctl_utf8(0, VIOCNEWCELL, &blob, 1);
2694 struct ViceIoctl blob;
2697 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2702 blob.in = (char *) 0;
2703 blob.out_size = MAXSIZE;
2706 code = pioctl_utf8((char *) 0, VIOCNEWCELL, &blob, 1);
2709 Die(errno, (char *) 0);
2713 printf("Cell servers information refreshed\n");
2720 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2723 struct ViceIoctl blob;
2725 char *aliasName, *realName;
2727 /* Setup and do the NEWALIAS pioctl call */
2728 aliasName = as->parms[0].items->data;
2729 realName = as->parms[1].items->data;
2731 strcpy(tp, aliasName);
2732 tp += strlen(aliasName) + 1;
2733 strcpy(tp, realName);
2734 tp += strlen(realName) + 1;
2736 blob.in_size = tp - space;
2740 code = pioctl_utf8(0, VIOC_NEWALIAS, &blob, 1);
2742 if (errno == EEXIST) {
2744 "%s: cell name `%s' in use by an existing cell.\n", pn,
2756 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2759 struct cmd_item *ti;
2760 struct ViceIoctl blob;
2763 cm_ioctlQueryOptions_t options;
2765 if (as->parms[1].items)
2768 SetDotDefault(&as->parms[0].items);
2769 for(ti=as->parms[0].items; ti; ti=ti->next) {
2771 afs_uint32 filetype;
2772 char cell[CELL_MAXNAMELEN];
2775 memset(&fid, 0, sizeof(fid));
2776 memset(&options, 0, sizeof(options));
2778 options.size = sizeof(options);
2779 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
2780 options.literal = literal;
2781 blob.in_size = options.size; /* no variable length data */
2784 blob.out_size = sizeof(cm_fid_t);
2785 blob.out = (char *) &fid;
2786 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
2787 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
2790 Die(errno, ti->data);
2795 blob.out_size = sizeof(filetype);
2796 blob.out = &filetype;
2798 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
2800 blob.out_size = CELL_MAXNAMELEN;
2803 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
2805 if (errno == ENOENT)
2806 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2808 Die(errno, ti->data);
2812 printf("%s %s lives in cell '%s'\n",
2813 filetypestr(filetype),
2820 WSCellCmd(struct cmd_syndesc *as, void *arock)
2823 struct ViceIoctl blob;
2827 blob.out_size = MAXSIZE;
2830 code = pioctl_utf8(NULL, VIOC_GET_WS_CELL, &blob, 1);
2837 printf("This workstation belongs to cell '%s'\n", space);
2843 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
2845 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2850 #ifndef AFS_NT40_ENV
2852 MonitorCmd(struct cmd_syndesc *as, void *arock)
2855 struct ViceIoctl blob;
2856 struct cmd_item *ti;
2858 struct hostent *thp;
2862 ti = as->parms[0].items;
2866 if (!strcmp(ti->data, "off")) {
2867 hostAddr = 0xffffffff;
2869 thp = hostutil_GetHostByName(ti->data);
2871 if (!strcmp(ti->data, "localhost")) {
2872 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2873 hostAddr = htonl(0x7f000001);
2875 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2879 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2883 hostAddr = 0; /* means don't set host */
2884 setp = 0; /* aren't setting host */
2887 /* now do operation */
2888 blob.in_size = sizeof(afs_int32);
2889 blob.out_size = sizeof(afs_int32);
2890 blob.in = (char *) &hostAddr;
2891 blob.out = (char *) &hostAddr;
2892 code = pioctl_utf8(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2898 printf("%s: new monitor host set.\n", pn);
2900 /* now decode old address */
2901 if (hostAddr == 0xffffffff) {
2902 printf("Cache monitoring is currently disabled.\n");
2904 tp = hostutil_GetNameByINet(hostAddr);
2905 printf("Using host %s for monitor services.\n", tp);
2910 #endif /* AFS_NT40_ENV */
2913 SysNameCmd(struct cmd_syndesc *as, void *arock)
2916 struct ViceIoctl blob;
2917 struct cmd_item *ti;
2918 char *input = space;
2921 ti = as->parms[0].items;
2925 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2930 fprintf (stderr,"Permission denied: requires root access.\n");
2938 blob.out_size = MAXSIZE;
2939 blob.in_size = sizeof(afs_int32);
2940 memcpy(input, &setp, sizeof(afs_int32));
2941 input += sizeof(afs_int32);
2942 for (; ti; ti = ti->next) {
2944 blob.in_size += (long)strlen(ti->data) + 1;
2945 if (blob.in_size > MAXSIZE) {
2946 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2947 setp > 1 ? "s" : "");
2950 strcpy(input, ti->data);
2951 input += strlen(ti->data);
2954 memcpy(space, &setp, sizeof(afs_int32));
2955 code = pioctl_utf8(0, VIOC_AFS_SYSNAME, &blob, 1);
2961 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2966 memcpy(&setp, input, sizeof(afs_int32));
2967 input += sizeof(afs_int32);
2969 fprintf(stderr,"No sysname name value was found\n");
2973 printf("Current sysname%s is", setp > 1 ? " list" : "");
2974 for (; setp > 0; --setp ) {
2975 printf(" \'%s\'", input);
2976 input += strlen(input) + 1;
2982 #ifndef AFS_NT40_ENV
2983 static char *exported_types[] = {"null", "nfs", ""};
2984 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2987 struct ViceIoctl blob;
2988 struct cmd_item *ti;
2989 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
2990 int exportcall, pwsync = 0, smounts = 0;
2994 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2999 fprintf (stderr,"Permission denied: requires root access.\n");
3004 ti = as->parms[0].items;
3005 if (strcmp(ti->data, "nfs") == 0)
3006 type = 0x71; /* NFS */
3009 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
3012 ti = as->parms[1].items;
3014 if (strcmp(ti->data, "on") == 0)
3016 else if (strcmp(ti->data, "off") == 0)
3019 fprintf(stderr, "Illegal argument %s\n", ti->data);
3024 if (ti = as->parms[2].items) { /* -noconvert */
3025 if (strcmp(ti->data, "on") == 0)
3027 else if (strcmp(ti->data, "off") == 0)
3030 fprintf(stderr, "Illegal argument %s\n", ti->data);
3034 if (ti = as->parms[3].items) { /* -uidcheck */
3035 if (strcmp(ti->data, "on") == 0)
3037 else if (strcmp(ti->data, "off") == 0)
3040 fprintf(stderr, "Illegal argument %s\n", ti->data);
3044 if (ti = as->parms[4].items) { /* -submounts */
3045 if (strcmp(ti->data, "on") == 0)
3047 else if (strcmp(ti->data, "off") == 0)
3050 fprintf(stderr, "Illegal argument %s\n", ti->data);
3054 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
3057 blob.in = (char *) &exportcall;
3058 blob.in_size = sizeof(afs_int32);
3059 blob.out = (char *) &exportcall;
3060 blob.out_size = sizeof(afs_int32);
3061 code = pioctl_utf8(0, VIOC_EXPORTAFS, &blob, 1);
3063 if (errno == ENODEV) {
3065 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
3072 if (exportcall & 1) {
3073 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
3074 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
3075 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
3076 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
3078 printf("'%s' translator is disabled\n", exported_types[type]);
3087 GetCellCmd(struct cmd_syndesc *as, void *arock)
3090 struct ViceIoctl blob;
3091 struct afsconf_cell info;
3092 struct cmd_item *ti;
3099 memset(&info, 0, sizeof(info));
3100 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3101 for(ti=as->parms[0].items; ti; ti=ti->next) {
3103 blob.out_size = sizeof(args);
3104 blob.out = (caddr_t) &args;
3105 code = GetCellName(ti->data, &info);
3110 if (info.linkedCell)
3111 free(info.linkedCell);
3112 blob.in_size = 1+(long)strlen(info.name);
3113 blob.in = info.name;
3114 code = pioctl_utf8(0, VIOC_GETCELLSTATUS, &blob, 1);
3116 if (errno == ENOENT)
3117 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3119 Die(errno, info.name);
3123 printf("Cell %s status: ", info.name);
3129 printf("no setuid allowed");
3131 printf("setuid allowed");
3133 printf(", using old VLDB");
3139 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3142 struct ViceIoctl blob;
3143 struct afsconf_cell info;
3144 struct cmd_item *ti;
3152 memset(&info, 0, sizeof(info));
3154 /* Check arguments. */
3155 if (as->parms[1].items && as->parms[2].items) {
3156 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3160 /* figure stuff to set */
3166 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3171 fprintf (stderr,"Permission denied: requires root access.\n");
3176 if (! as->parms[1].items)
3177 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3179 /* set stat for all listed cells */
3180 for(ti=as->parms[0].items; ti; ti=ti->next) {
3182 code = GetCellName(ti->data, &info);
3187 if (info.linkedCell)
3188 free(info.linkedCell);
3189 strcpy(args.cname, info.name);
3190 blob.in_size = sizeof(args);
3191 blob.in = (caddr_t) &args;
3193 blob.out = (caddr_t) 0;
3194 code = pioctl_utf8(0, VIOC_SETCELLSTATUS, &blob, 1);
3196 Die(errno, info.name); /* XXX added cell name to Die() call */
3204 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3206 strcpy(infop->name, cellNamep);
3211 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3216 cm_GetConfigDir(confDir, sizeof(confDir));
3218 code = ugen_ClientInit(noAuthFlag, confDir,
3219 info->name, 0, &uclient,
3220 NULL, pn, rxkad_clear,
3221 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3222 0, 0, USER_SERVICE_ID);
3227 static struct ViceIoctl gblob;
3228 static int debug = 0;
3230 * here follow some routines in suport of the setserverprefs and
3231 * getserverprefs commands. They are:
3232 * SetPrefCmd "top-level" routine
3233 * addServer adds a server to the list of servers to be poked into the
3234 * kernel. Will poke the list into the kernel if it threatens
3236 * pokeServers pokes the existing list of servers and ranks into the kernel
3237 * GetPrefCmd reads the Cache Manager's current list of server ranks
3246 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3248 ssp = (cm_SSetPref_t *)space;
3249 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3255 * returns -1 if error message printed,
3257 * errno value if error and no error message printed
3264 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3265 if (code && (errno == EINVAL)) {
3266 struct setspref *ssp;
3267 ssp = (struct setspref *)gblob.in;
3268 if (!(ssp->flags & DBservers)) {
3269 gblob.in = (void *)&(ssp->servers[0]);
3270 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3271 code = pioctl_utf8(0, VIOC_SETSPREFS33, &gblob, 1);
3272 return code ? errno : 0;
3275 "This cache manager does not support VL server preferences.\n");
3279 return code ? errno : 0;
3285 addServer(char *name, unsigned short rank)
3290 struct hostent *thostent;
3294 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3296 #define MAXUSHORT ((unsigned short) ~0)
3301 thostent = hostutil_GetHostByName(name);
3303 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3307 ssp = (cm_SSetPref_t *)(gblob.in);
3309 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3310 code = pokeServers();
3311 ssp->num_servers = 0;
3314 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3315 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3316 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3317 gblob.in_size += sizeof(cm_SPref_t);
3320 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3326 * returns -1 if error message printed,
3328 * errno value if error and no error message printed
3331 addServer(char *name, afs_int32 rank)
3334 struct setspref *ssp;
3336 struct hostent *thostent;
3342 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3344 #define MAXUSHORT ((unsigned short) ~0)
3348 thostent = hostutil_GetHostByName(name);
3350 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3354 ssp = (struct setspref *)(gblob.in);
3356 for (t = 0; thostent->h_addr_list[t]; t++) {
3357 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3358 code = pokeServers();
3361 ssp->num_servers = 0;
3364 sp = (struct spref *)(gblob.in + gblob.in_size);
3365 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3366 sizeof(afs_uint32));
3367 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3368 gblob.in_size += sizeof(struct spref);
3372 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3373 name, sp->rank, sp->server.s_addr);
3381 static BOOL IsWindowsNT (void)
3383 static BOOL fChecked = FALSE;
3384 static BOOL fIsWinNT = FALSE;
3388 OSVERSIONINFO Version;
3392 memset (&Version, 0x00, sizeof(Version));
3393 Version.dwOSVersionInfoSize = sizeof(Version);
3395 if (GetVersionEx (&Version))
3397 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3407 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3411 struct cmd_item *ti;
3416 ssp = (cm_SSetPref_t *)space;
3418 ssp->num_servers = 0;
3419 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3422 gblob.out_size = MAXSIZE;
3425 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3431 ti = as->parms[2].items; /* -file */
3433 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3434 if (!(infd = fopen(ti->data,"r" ))) {
3436 Die(errno,ti->data);
3439 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3440 code = addServer (name, (unsigned short) rank);
3444 ti = as->parms[3].items; /* -stdin */
3446 while ( scanf("%79s%ld", name, &rank) != EOF) {
3447 code = addServer (name, (unsigned short) rank);
3451 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3456 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3458 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3462 code = pokeServers();
3464 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3466 ssp = (cm_SSetPref_t *)space;
3467 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3469 ssp->flags = CM_SPREF_VLONLY;
3470 ssp->num_servers = 0;
3472 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3477 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3479 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3484 if (as->parms[1].items) {
3486 printf("now poking vlservers\n");
3487 code = pokeServers();
3497 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3501 struct cmd_item *ti;
3504 struct setspref *ssp;
3505 int error = 0; /* -1 means error message printed,
3506 * >0 means errno value for unprinted message */
3508 ssp = (struct setspref *)space;
3510 ssp->num_servers = 0;
3511 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3514 gblob.out_size = MAXSIZE;
3518 fprintf(stderr, "Permission denied: requires root access.\n");
3522 ti = as->parms[2].items; /* -file */
3525 fprintf(stderr, "opening file %s\n", ti->data);
3526 if (!(infd = fopen(ti->data, "r"))) {
3530 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3531 code = addServer(name, (unsigned short)rank);
3538 ti = as->parms[3].items; /* -stdin */
3540 while (scanf("%79s%ld", name, &rank) != EOF) {
3541 code = addServer(name, (unsigned short)rank);
3547 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3552 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3556 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3560 code = pokeServers();
3564 printf("now working on vlservers, code=%d\n", code);
3566 ssp = (struct setspref *)space;
3567 ssp->flags = DBservers;
3568 ssp->num_servers = 0;
3569 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3572 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3577 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3581 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3586 if (as->parms[1].items) {
3588 printf("now poking vlservers\n");
3589 code = pokeServers();
3597 return error ? 1 : 0;
3603 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3606 struct cmd_item *ti;
3607 char *name, tbuffer[20];
3612 struct ViceIoctl blob;
3613 struct cm_SPrefRequest *in;
3614 struct cm_SPrefInfo *out;
3618 ti = as->parms[0].items; /* -file */
3620 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3621 if (!(outfd = freopen(ti->data,"w",stdout))) {
3622 Die(errno,ti->data);
3627 ti = as->parms[1].items; /* -numeric */
3629 ti = as->parms[2].items; /* -vlservers */
3630 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3631 /* ti = as->parms[3].items; -cell */
3633 in = (struct cm_SPrefRequest *)space;
3637 blob.in_size=sizeof(struct cm_SPrefRequest);
3638 blob.in = (char *)in;
3640 blob.out_size = MAXSIZE;
3642 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3643 in->flags = vlservers;
3645 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3647 perror("getserverprefs pioctl");
3651 out = (struct cm_SPrefInfo *) blob.out;
3653 for (i=0;i<out->num_servers;i++) {
3655 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3658 addr = ntohl(out->servers[i].host.s_addr);
3659 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3660 (addr>>8) & 0xff, addr & 0xff);
3663 printf ("%-50s %5u\n",name,out->servers[i].rank);
3666 in->offset = out->next_offset;
3668 } while (!code && out->next_offset > 0);
3674 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3677 struct cmd_item *ti;
3678 char *name, tbuffer[20];
3679 afs_int32 rank, addr;
3683 struct ViceIoctl blob;
3684 struct sprefrequest *in;
3685 struct sprefinfo *out;
3688 ti = as->parms[0].items; /* -file */
3691 fprintf(stderr, "opening file %s\n", ti->data);
3692 if (!(outfd = freopen(ti->data, "w", stdout))) {
3698 ti = as->parms[1].items; /* -numeric */
3700 ti = as->parms[2].items; /* -vlservers */
3701 vlservers |= (ti ? DBservers : 0);