2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afs/param.h>
22 #include <rx/rx_globals.h>
26 #include <afs/cellconfig.h>
27 #include <afs/ptserver.h>
28 #include <afs/ptuser.h>
29 #include <afs/volser.h>
30 #include <WINNT\afsreg.h>
40 #define MAXCELLHOSTS 8
43 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
44 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
45 #define CELL_MAXNAMELEN 256
46 #define MAXHOSTCHARS 64
48 static char space[MAXSIZE];
49 static char tspace[1024];
51 static struct ubik_client *uclient;
53 static int GetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
54 static int SetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
55 static int FlushMountCmd(struct cmd_syndesc *asp, void *arock);
56 static int RxStatProcCmd(struct cmd_syndesc *asp, void *arock);
57 static int RxStatPeerCmd(struct cmd_syndesc *asp, void *arock);
59 extern struct cmd_syndesc *cmd_CreateSyntax();
61 static int MemDumpCmd(struct cmd_syndesc *asp, void *arock);
62 static int CSCPolicyCmd(struct cmd_syndesc *asp, void *arock);
63 static int MiniDumpCmd(struct cmd_syndesc *asp, void *arock);
65 static char pn[] = "fs";
66 static int rxInitDone = 0;
69 * Character to use between name and rights in printed representation for
72 #define DFS_SEPARATOR ' '
74 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
77 int dfs; /* Originally true if a dfs acl; now also the type
78 * of the acl (1, 2, or 3, corresponding to object,
79 * initial dir, or initial object). */
80 sec_rgy_name_t cell; /* DFS cell name */
83 struct AclEntry *pluslist;
84 struct AclEntry *minuslist;
88 struct AclEntry *next;
94 ZapAcl (struct Acl *acl)
99 ZapList(acl->pluslist);
100 ZapList(acl->minuslist);
105 * Mods for the AFS/DFS protocol translator.
107 * DFS rights. It's ugly to put these definitions here, but they
108 * *cannot* change, because they're part of the wire protocol.
109 * In any event, the protocol translator will guarantee these
110 * assignments for AFS cache managers.
112 #define DFS_READ 0x01
113 #define DFS_WRITE 0x02
114 #define DFS_EXECUTE 0x04
115 #define DFS_CONTROL 0x08
116 #define DFS_INSERT 0x10
117 #define DFS_DELETE 0x20
119 /* the application definable ones (backwards from AFS) */
120 #define DFS_USR0 0x80000000 /* "A" bit */
121 #define DFS_USR1 0x40000000 /* "B" bit */
122 #define DFS_USR2 0x20000000 /* "C" bit */
123 #define DFS_USR3 0x10000000 /* "D" bit */
124 #define DFS_USR4 0x08000000 /* "E" bit */
125 #define DFS_USR5 0x04000000 /* "F" bit */
126 #define DFS_USR6 0x02000000 /* "G" bit */
127 #define DFS_USR7 0x01000000 /* "H" bit */
128 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
129 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
132 * Offset of -id switch in command structure for various commands.
133 * The -if switch is the next switch always.
135 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
138 * Determine whether either the -id or -if switches are present, and
139 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
141 /* int id; Offset of -id switch; -if is next switch */
143 getidf(struct cmd_syndesc *as, int id)
147 if (as->parms[id].items) {
150 if (as->parms[id + 1].items) {
155 "%s: you may specify either -id or -if, but not both switches\n",
163 PRights(afs_int32 arights, int dfs)
166 if (arights & PRSFS_READ)
168 if (arights & PRSFS_LOOKUP)
170 if (arights & PRSFS_INSERT)
172 if (arights & PRSFS_DELETE)
174 if (arights & PRSFS_WRITE)
176 if (arights & PRSFS_LOCK)
178 if (arights & PRSFS_ADMINISTER)
180 if (arights & PRSFS_USR0)
182 if (arights & PRSFS_USR1)
184 if (arights & PRSFS_USR2)
186 if (arights & PRSFS_USR3)
188 if (arights & PRSFS_USR4)
190 if (arights & PRSFS_USR5)
192 if (arights & PRSFS_USR6)
194 if (arights & PRSFS_USR7)
197 if (arights & DFS_READ)
201 if (arights & DFS_WRITE)
205 if (arights & DFS_EXECUTE)
209 if (arights & DFS_CONTROL)
213 if (arights & DFS_INSERT)
217 if (arights & DFS_DELETE)
221 if (arights & (DFS_USRALL))
223 if (arights & DFS_USR0)
225 if (arights & DFS_USR1)
227 if (arights & DFS_USR2)
229 if (arights & DFS_USR3)
231 if (arights & DFS_USR4)
233 if (arights & DFS_USR5)
235 if (arights & DFS_USR6)
237 if (arights & DFS_USR7)
243 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
247 struct ViceIoctl blob;
251 blob.out_size = MAXSIZE;
254 code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
256 if ((errno == EINVAL) || (errno == ENOENT))
263 IsFreelanceRoot(char *apath)
265 struct ViceIoctl blob;
269 blob.out_size = MAXSIZE;
272 code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
274 return !cm_stricmp_utf8N("Freelance.Local.Root",space);
275 return 1; /* assume it is because it is more restrictive that way */
278 /* return a static pointer to a buffer */
283 strcpy(tspace, apath);
284 tp = strrchr(tspace, '\\');
286 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
289 fs_ExtractDriveLetter(apath, tspace);
295 enum rtype {add, destroy, deny};
298 Convert(char *arights, int dfs, enum rtype *rtypep)
304 *rtypep = add; /* add rights, by default */
307 if (!strcmp(arights, "null")) {
311 if (!strcmp(arights,"read"))
312 return DFS_READ | DFS_EXECUTE;
313 if (!strcmp(arights, "write"))
314 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
316 if (!strcmp(arights, "all"))
317 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
318 DFS_WRITE | DFS_CONTROL;
320 if (!strcmp(arights,"read"))
321 return PRSFS_READ | PRSFS_LOOKUP;
322 if (!strcmp(arights, "write"))
323 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
324 PRSFS_WRITE | PRSFS_LOCK;
325 if (!strcmp(arights, "mail"))
326 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
327 if (!strcmp(arights, "all"))
328 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
329 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
331 if (!strcmp(arights, "none")) {
332 *rtypep = destroy; /* Remove entire entry */
335 len = (int)strlen(arights);
371 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
379 mode |= PRSFS_LOOKUP;
381 mode |= PRSFS_INSERT;
383 mode |= PRSFS_DELETE;
389 mode |= PRSFS_ADMINISTER;
407 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
416 static struct AclEntry *
417 FindList (struct AclEntry *alist, char *aname)
420 if (!strcasecmp(alist->name, aname))
427 /* if no parm specified in a particular slot, set parm to be "." instead */
429 SetDotDefault(struct cmd_item **aitemp)
433 return; /* already has value */
434 /* otherwise, allocate an item representing "." */
435 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
437 ti->next = (struct cmd_item *) 0;
438 ti->data = (char *) malloc(2);
440 strcpy(ti->data, ".");
445 ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
447 struct AclEntry *tlist;
448 tlist = (plus ? al->pluslist : al->minuslist);
449 tlist = FindList (tlist, aname);
451 /* Found the item already in the list. */
452 tlist->rights = arights;
454 al->nplus -= PruneList(&al->pluslist, al->dfs);
456 al->nminus -= PruneList(&al->minuslist, al->dfs);
459 /* Otherwise we make a new item and plug in the new data. */
460 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
462 strcpy(tlist->name, aname);
463 tlist->rights = arights;
465 tlist->next = al->pluslist;
466 al->pluslist = tlist;
468 if (arights == 0 || arights == -1)
469 al->nplus -= PruneList(&al->pluslist, al->dfs);
471 tlist->next = al->minuslist;
472 al->minuslist = tlist;
475 al->nminus -= PruneList(&al->minuslist, al->dfs);
480 ZapList (struct AclEntry *alist)
482 struct AclEntry *tp, *np;
483 for (tp = alist; tp; tp = np) {
490 PruneList (struct AclEntry **ae, int dfs)
492 struct AclEntry **lp;
493 struct AclEntry *te, *ne;
497 for(te = *ae;te;te=ne) {
498 if ((!dfs && te->rights == 0) || te->rights == -1) {
512 SkipLine (char *astr)
521 * Create an empty acl, taking into account whether the acl pointed
522 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
523 * can recover from problems caused by bogus ACL's (in that case, always
524 * assume that the acl is AFS: for DFS, the user can always resort to
525 * acl_edit, but for AFS there may be no other way out).
533 tp = (struct Acl *)malloc(sizeof (struct Acl));
535 tp->nplus = tp->nminus = 0;
536 tp->pluslist = tp->minuslist = 0;
538 if (astr == NULL || sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell) <= 0) {
546 ParseAcl (char *astr)
548 int nplus, nminus, i, trights, ret;
550 struct AclEntry *first, *next, *last, *tl;
554 if (astr == NULL || strlen(astr) == 0)
557 ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
562 astr = SkipLine(astr);
563 ret = sscanf(astr, "%d", &ta->nminus);
568 astr = SkipLine(astr);
575 for(i=0;i<nplus;i++) {
576 ret = sscanf(astr, "%100s %d", tname, &trights);
579 astr = SkipLine(astr);
580 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
585 strcpy(tl->name, tname);
586 tl->rights = trights;
592 ta->pluslist = first;
596 for(i=0;i<nminus;i++) {
597 ret = sscanf(astr, "%100s %d", tname, &trights);
600 astr = SkipLine(astr);
601 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
606 strcpy(tl->name, tname);
607 tl->rights = trights;
613 ta->minuslist = first;
618 for (;first; first = next) {
622 first = ta->pluslist;
625 for (;first; first = next) {
634 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
636 printf("Volume status for vid = %u named %s is\n",status->Vid, name);
638 printf("Current offline message is %s\n",offmsg);
640 printf("Current message of the day is %s\n",motd);
641 printf("Current disk quota is ");
642 if (status->MaxQuota != 0)
643 printf("%d\n", status->MaxQuota);
645 printf("unlimited\n");
646 printf("Current blocks used are %d\n",status->BlocksInUse);
647 printf("The partition has %d blocks available out of %d\n",
648 status->PartBlocksAvail, status->PartMaxBlocks);
653 QuickPrintStatus(VolumeStatus *status, char *name)
655 double QuotaUsed =0.0;
656 double PartUsed =0.0;
658 printf("%-25.25s",name);
660 if (status->MaxQuota != 0) {
661 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
662 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
664 printf("no limit%10d", status->BlocksInUse);
666 if (QuotaUsed > 90.0){
667 printf(" %5.0f%%<<", QuotaUsed);
670 printf(" %5.0f%% ", QuotaUsed);
671 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
672 if (PartUsed > 97.0){
673 printf(" %9.0f%%<<", PartUsed);
676 printf(" %9.0f%% ", PartUsed);
678 printf(" <<WARNING\n");
685 QuickPrintSpace(VolumeStatus *status, char *name)
687 double PartUsed =0.0;
689 printf("%-25.25s",name);
691 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
693 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
694 if (PartUsed > 90.0){
695 printf(" %4.0f%%<<", PartUsed);
698 printf(" %4.0f%% ", PartUsed);
700 printf(" <<WARNING\n");
707 AclToString(struct Acl *acl)
709 static char mydata[MAXSIZE];
710 char tstring[MAXSIZE];
715 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
718 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
719 for (tp = acl->pluslist;tp;tp=tp->next) {
720 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
721 strcat(mydata, tstring);
723 for (tp = acl->minuslist;tp;tp=tp->next) {
724 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
725 strcat(mydata, tstring);
730 static DWORD IsFreelance(void)
737 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
738 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
739 if (code == ERROR_SUCCESS) {
740 dummyLen = sizeof(cm_freelanceEnabled);
741 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
742 (BYTE *) &enabled, &dummyLen);
743 RegCloseKey (parmKey);
748 static const char * NetbiosName(void)
750 static char buffer[1024] = "AFS";
756 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
757 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
758 if (code == ERROR_SUCCESS) {
759 dummyLen = sizeof(buffer);
760 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
762 RegCloseKey (parmKey);
764 strcpy(buffer, "AFS");
769 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
771 static BOOL IsAdmin (void)
773 static BOOL fAdmin = FALSE;
774 static BOOL fTested = FALSE;
778 /* Obtain the SID for the AFS client admin group. If the group does
779 * not exist, then assume we have AFS client admin privileges.
781 PSID psidAdmin = NULL;
782 DWORD dwSize, dwSize2;
783 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
784 char *pszRefDomain = NULL;
785 SID_NAME_USE snu = SidTypeGroup;
787 dwSize = sizeof(pszAdminGroup);
789 if (!GetComputerName(pszAdminGroup, &dwSize)) {
790 /* Can't get computer name. We return false in this case.
791 Retain fAdmin and fTested. This shouldn't happen.*/
798 strcat(pszAdminGroup,"\\");
799 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
801 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
802 /* that should always fail. */
804 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
805 /* if we can't find the group, then we allow the operation */
810 if (dwSize == 0 || dwSize2 == 0) {
816 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
818 pszRefDomain = (char *)malloc(dwSize2);
819 assert(pszRefDomain);
821 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
822 /* We can't lookup the group now even though we looked it up earlier.
823 Could this happen? */
826 /* Then open our current ProcessToken */
829 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
832 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
833 /* We'll have to allocate a chunk of memory to store the list of
834 * groups to which this user belongs; find out how much memory
838 PTOKEN_GROUPS pGroups;
840 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
842 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
845 /* Allocate that buffer, and read in the list of groups. */
846 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
848 /* Look through the list of group SIDs and see if any of them
849 * matches the AFS Client Admin group SID.
852 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
854 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
864 /* if do not have permission because we were not explicitly listed
865 * in the Admin Client Group let's see if we are the SYSTEM account
868 PTOKEN_USER pTokenUser;
869 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
870 PSID pSidLocalSystem = 0;
873 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
875 pTokenUser = (PTOKEN_USER)malloc(dwSize);
878 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
879 gle = GetLastError();
881 if (AllocateAndInitializeSid( &SIDAuth, 1,
882 SECURITY_LOCAL_SYSTEM_RID,
886 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
890 FreeSid(pSidLocalSystem);
909 SetACLCmd(struct cmd_syndesc *as, void *arock)
912 struct ViceIoctl blob;
914 struct cmd_item *ti, *ui;
918 int idf = getidf(as, parm_setacl_id);
922 if (as->parms[2].items)
926 plusp = !(as->parms[3].items);
927 for(ti=as->parms[0].items; ti;ti=ti->next) {
928 blob.out_size = MAXSIZE;
930 blob.in = blob.out = space;
931 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
933 Die(errno, ti->data);
939 ta = ParseAcl(space);
942 "fs: %s: invalid acl data returned from VIOCGETAL\n",
947 if (!plusp && ta->dfs) {
949 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
951 "(you may specify \"null\" to revoke all rights, however)\n");
958 ta = EmptyAcl(space);
960 ta = ParseAcl(space);
963 "fs: %s: invalid acl data returned from VIOCGETAL\n",
968 CleanAcl(ta, ti->data);
969 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
973 "%s: Missing second half of user/access pair.\n", pn);
977 rights = Convert(ui->next->data, ta->dfs, &rtype);
978 if (rtype == destroy && !ta->dfs) {
979 struct AclEntry *tlist;
981 tlist = (plusp ? ta->pluslist : ta->minuslist);
982 if (!FindList(tlist, ui->data))
985 if (rtype == deny && !ta->dfs)
987 if (rtype == destroy && ta->dfs)
989 ChangeList(ta, plusp, ui->data, rights);
991 blob.in = AclToString(ta);
993 blob.in_size = 1+(long)strlen(blob.in);
994 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
996 if (errno == EINVAL) {
998 static char *fsenv = 0;
1000 fsenv = (char *)getenv("FS_EXPERT");
1002 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
1005 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1006 "\nPossible reasons for this include:\n\n",
1007 " -You may have specified an inappropriate combination of rights.\n",
1008 " For example, some DFS-supported filesystems may not allow you to\n",
1009 " drop the \"c\" right from \"user_obj\".\n\n",
1010 " -A mask_obj may be required (it is likely required by the underlying\n",
1011 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
1012 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
1013 " does not automatically create or update the mask_obj. Try setting\n",
1014 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
1015 " users or groups. You can do this with a single command, such as\n",
1016 " \"fs sa mask_obj all user:somename read\"\n\n",
1017 " -A specified user or group may not exist.\n\n",
1018 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
1019 " This is probably not allowed by the underlying file system.\n\n",
1020 " -If you add a user or group to a DFS ACL, remember that it must be\n",
1021 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
1022 " may be local requirements on the format of the user or group name.\n",
1023 " Check with your cell administrator.\n\n",
1024 " -Or numerous other possibilities. It would be great if we could be more\n",
1025 " precise about the actual problem, but for various reasons, this is\n",
1026 " impractical via this interface. If you can't figure it out, you\n",
1027 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
1028 " whatever is provided). You may get better results. Good luck!\n\n",
1029 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
1033 "%s: Invalid argument, possible reasons include:\n",
1035 fprintf(stderr,"\t-File not in AFS\n");
1037 "\t-Too many users on access control list\n");
1039 "\t-Tried to add non-existent user to access control list\n");
1042 Die(errno, ti->data);
1053 CopyACLCmd(struct cmd_syndesc *as, void *arock)
1056 struct ViceIoctl blob;
1057 struct Acl *fa, *ta = 0;
1058 struct AclEntry *tp;
1059 struct cmd_item *ti;
1061 int idf = getidf(as, parm_copyacl_id);
1064 if (as->parms[2].items)
1068 blob.out_size = MAXSIZE;
1070 blob.in = blob.out = space;
1071 code = pioctl_utf8(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1073 Die(errno, as->parms[0].items->data);
1076 fa = ParseAcl(space);
1079 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1080 as->parms[0].items->data);
1083 CleanAcl(fa, as->parms[0].items->data);
1084 for (ti=as->parms[1].items; ti;ti=ti->next) {
1085 blob.out_size = MAXSIZE;
1087 blob.in = blob.out = space;
1088 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1090 Die(errno, ti->data);
1097 ta = EmptyAcl(space);
1099 ta = ParseAcl(space);
1102 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1107 CleanAcl(ta, ti->data);
1108 if (ta->dfs != fa->dfs) {
1110 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1116 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1118 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1123 strcpy(ta->cell, fa->cell);
1125 for (tp = fa->pluslist;tp;tp=tp->next)
1126 ChangeList(ta, 1, tp->name, tp->rights);
1127 for (tp = fa->minuslist;tp;tp=tp->next)
1128 ChangeList(ta, 0, tp->name, tp->rights);
1129 blob.in = AclToString(ta);
1131 blob.in_size = 1+(long)strlen(blob.in);
1132 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1134 if (errno == EINVAL) {
1136 "%s: Invalid argument, possible reasons include:\n", pn);
1137 fprintf(stderr,"\t-File not in AFS\n");
1139 Die(errno, ti->data);
1150 /* pioctl_utf8() call to get the cellname of a pathname */
1152 GetCell(char *fname, char *cellname)
1155 struct ViceIoctl blob;
1158 blob.out_size = CELL_MAXNAMELEN;
1159 blob.out = cellname;
1161 code = pioctl_utf8(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1165 /* Check if a username is valid: If it contains only digits (or a
1166 * negative sign), then it might be bad. We then query the ptserver
1170 BadName(char *aname, char *fname)
1172 afs_int32 tc, code, id;
1174 char cell[CELL_MAXNAMELEN];
1177 for ( nm = aname; tc = *nm; nm++) {
1178 /* all must be '-' or digit to be bad */
1179 if (tc != '-' && (tc < '0' || tc > '9'))
1183 /* Go to the PRDB and see if this all number username is valid */
1184 code = GetCell(fname, cell);
1188 cm_GetConfigDir(confDir, sizeof(confDir));
1190 pr_Initialize(1, confDir, cell);
1191 code = pr_SNameToId(aname, &id);
1194 /* 1=>Not-valid; 0=>Valid */
1195 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1199 /* clean up an access control list of its bad entries; return 1 if we made
1200 any changes to the list, and 0 otherwise */
1202 CleanAcl(struct Acl *aa, char *fname)
1204 struct AclEntry *te, **le, *ne;
1207 /* Don't correct DFS ACL's for now */
1211 /* prune out bad entries */
1212 changes = 0; /* count deleted entries */
1214 for(te = aa->pluslist; te; te=ne) {
1216 if (BadName(te->name, fname)) {
1226 le = &aa->minuslist;
1227 for(te = aa->minuslist; te; te=ne) {
1229 if (BadName(te->name, fname)) {
1243 /* clean up an acl to not have bogus entries */
1245 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1249 struct ViceIoctl blob;
1251 struct cmd_item *ti;
1252 struct AclEntry *te;
1255 SetDotDefault(&as->parms[0].items);
1256 for(ti=as->parms[0].items; ti; ti=ti->next) {
1257 blob.out_size = MAXSIZE;
1260 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1262 Die(errno, ti->data);
1268 ta = ParseAcl(space);
1271 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1278 "%s: cleanacl is not supported for DFS access lists.\n",
1284 changes = CleanAcl(ta, ti->data);
1287 /* now set the acl */
1288 blob.in=AclToString(ta);
1289 blob.in_size = (long)strlen(blob.in)+1;
1291 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1293 if (errno == EINVAL) {
1295 "%s: Invalid argument, possible reasons include\n",
1297 fprintf(stderr,"%s: File not in vice or\n", pn);
1299 "%s: Too many users on access control list or\n",
1302 Die(errno, ti->data);
1308 /* now list the updated acl */
1309 printf("Access list for %s is now\n", ti->data);
1310 if (ta->nplus > 0) {
1312 printf("Normal rights:\n");
1313 for(te = ta->pluslist;te;te=te->next) {
1314 printf(" %s ", te->name);
1315 PRights(te->rights, ta->dfs);
1319 if (ta->nminus > 0) {
1320 printf("Negative rights:\n");
1321 for(te = ta->minuslist;te;te=te->next) {
1322 printf(" %s ", te->name);
1323 PRights(te->rights, ta->dfs);
1330 printf("Access list for %s is fine.\n", ti->data);
1338 ListACLCmd(struct cmd_syndesc *as, void *arock)
1342 struct ViceIoctl blob;
1343 struct AclEntry *te;
1344 struct cmd_item *ti;
1345 int idf = getidf(as, parm_listacl_id);
1348 SetDotDefault(&as->parms[0].items);
1349 for(ti=as->parms[0].items; ti; ti=ti->next) {
1351 blob.out_size = MAXSIZE;
1353 blob.in = blob.out = space;
1354 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1356 Die(errno, ti->data);
1360 ta = ParseAcl(space);
1363 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1370 printf("Access list for %s is\n", ti->data);
1373 printf("DFS access list for %s is\n", ti->data);
1376 printf("DFS initial directory access list of %s is\n", ti->data);
1379 printf("DFS initial file access list of %s is\n", ti->data);
1383 printf(" Default cell = %s\n", ta->cell);
1385 separator = ta->dfs? DFS_SEPARATOR : ' ';
1386 if (ta->nplus > 0) {
1388 printf("Normal rights:\n");
1389 for(te = ta->pluslist;te;te=te->next) {
1390 printf(" %s%c", te->name, separator);
1391 PRights(te->rights, ta->dfs);
1395 if (ta->nminus > 0) {
1396 printf("Negative rights:\n");
1397 for(te = ta->minuslist;te;te=te->next) {
1398 printf(" %s ", te->name);
1399 PRights(te->rights, ta->dfs);
1411 FlushAllCmd(struct cmd_syndesc *as, void *arock)
1414 struct ViceIoctl blob;
1416 blob.in_size = blob.out_size = 0;
1417 code = pioctl_utf8(NULL, VIOC_FLUSHALL, &blob, 0);
1419 fprintf(stderr, "Error flushing all ");
1426 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1429 struct ViceIoctl blob;
1430 struct cmd_item *ti;
1433 SetDotDefault(&as->parms[0].items);
1434 for(ti=as->parms[0].items; ti; ti=ti->next) {
1435 blob.in_size = blob.out_size = 0;
1436 code = pioctl_utf8(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1438 fprintf(stderr, "Error flushing volume ");
1448 FlushCmd(struct cmd_syndesc *as, void *arock)
1451 struct ViceIoctl blob;
1452 struct cmd_item *ti;
1455 cm_ioctlQueryOptions_t options;
1457 if (as->parms[1].items)
1460 for(ti=as->parms[0].items; ti; ti=ti->next) {
1462 memset(&options, 0, sizeof(options));
1463 options.size = sizeof(options);
1464 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1465 options.literal = literal;
1466 blob.in_size = options.size; /* no variable length data */
1470 code = pioctl_utf8(ti->data, VIOCFLUSH, &blob, 0);
1472 if (errno == EMFILE) {
1473 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1476 fprintf(stderr, "%s: Error flushing file ", pn);
1486 /* all this command does is repackage its args and call SetVolCmd */
1488 SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
1489 struct cmd_syndesc ts;
1491 /* copy useful stuff from our command slot; we may later have to reorder */
1492 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1493 return SetVolCmd(&ts, arock);
1497 SetVolCmd(struct cmd_syndesc *as, void *arock) {
1499 struct ViceIoctl blob;
1500 struct cmd_item *ti;
1501 struct VolumeStatus *status;
1502 char *motd, *offmsg, *input;
1505 SetDotDefault(&as->parms[0].items);
1506 for(ti=as->parms[0].items; ti; ti=ti->next) {
1508 blob.out_size = MAXSIZE;
1509 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1512 status = (VolumeStatus *)space;
1513 status->MinQuota = status->MaxQuota = -1;
1514 motd = offmsg = NULL;
1515 if (as->parms[1].items) {
1516 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1518 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1523 if (as->parms[2].items)
1524 motd = as->parms[2].items->data;
1525 if (as->parms[3].items)
1526 offmsg = as->parms[3].items->data;
1527 input = (char *)status + sizeof(*status);
1528 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1530 if (strlen(offmsg) >= VMSGSIZE) {
1531 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1536 strcpy(input,offmsg);
1537 blob.in_size += (long)strlen(offmsg);
1538 input += strlen(offmsg) + 1;
1542 if (strlen(motd) >= VMSGSIZE) {
1543 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1548 blob.in_size += (long)strlen(motd);
1549 input += strlen(motd) + 1;
1552 code = pioctl_utf8(ti->data,VIOCSETVOLSTAT, &blob, 1);
1554 Die(errno, ti->data);
1561 /* values match cache manager File Types */
1563 filetypestr(afs_uint32 type)
1565 char * s = "Object";
1588 ExamineCmd(struct cmd_syndesc *as, void *arock)
1591 struct ViceIoctl blob;
1592 struct cmd_item *ti;
1593 struct VolumeStatus *status;
1594 char *name, *offmsg, *motd;
1597 cm_ioctlQueryOptions_t options;
1599 if (as->parms[1].items)
1602 SetDotDefault(&as->parms[0].items);
1603 for(ti=as->parms[0].items; ti; ti=ti->next) {
1605 afs_uint32 filetype;
1606 afs_uint32 owner[2];
1607 char cell[CELL_MAXNAMELEN];
1610 memset(&fid, 0, sizeof(fid));
1611 memset(&options, 0, sizeof(options));
1613 options.size = sizeof(options);
1614 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1615 options.literal = literal;
1616 blob.in_size = options.size; /* no variable length data */
1619 blob.out_size = sizeof(cm_fid_t);
1620 blob.out = (char *) &fid;
1621 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
1622 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1625 Die(errno, ti->data);
1630 blob.out_size = sizeof(filetype);
1631 blob.out = &filetype;
1633 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1635 blob.out_size = CELL_MAXNAMELEN;
1638 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1639 printf("%s %s (%u.%u.%u) contained in cell %s\n",
1640 filetypestr(filetype),
1641 ti->data, fid.volume, fid.vnode, fid.unique,
1642 code ? "unknown-cell" : cell);
1644 blob.out_size = 2 * sizeof(afs_uint32);
1645 blob.out = (char *) &owner;
1646 if (0 == pioctl_utf8(ti->data, VIOCGETOWNER, &blob, 1)) {
1647 char oname[PR_MAXNAMELEN] = "(unknown)";
1650 /* Go to the PRDB and see if this all number username is valid */
1651 cm_GetConfigDir(confDir, sizeof(confDir));
1653 pr_Initialize(1, confDir, cell);
1654 pr_SIdToName(owner[0], oname);
1655 printf("Owner %s (%u) Group %u\n", oname, owner[0], owner[1]);
1659 blob.out_size = MAXSIZE;
1660 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1662 status = (VolumeStatus *)space;
1663 name = (char *)status + sizeof(*status);
1664 offmsg = name + strlen(name) + 1;
1665 motd = offmsg + strlen(offmsg) + 1;
1667 PrintStatus(status, name, motd, offmsg);
1669 Die(errno, ti->data);
1673 code = pioctl_utf8(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
1676 printf("Volume is online\n");
1679 printf("Volume is offline\n");
1682 printf("All Volume servers are down\n");
1685 printf("All volume servers are busy\n");
1688 printf("Unknown volume state\n");
1689 Die(errno, ti->data);
1697 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1700 struct ViceIoctl blob;
1701 struct cmd_item *ti;
1702 struct VolumeStatus *status;
1707 printf("%-25s%-10s%-10s%-7s%-13s\n",
1708 "Volume Name", " Quota", " Used", " %Used", " Partition");
1709 SetDotDefault(&as->parms[0].items);
1710 for(ti=as->parms[0].items; ti; ti=ti->next) {
1712 blob.out_size = MAXSIZE;
1715 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1717 Die(errno, ti->data);
1721 status = (VolumeStatus *)space;
1722 name = (char *)status + sizeof(*status);
1723 QuickPrintStatus(status, name);
1729 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1732 struct ViceIoctl blob;
1733 struct cmd_item *ti;
1739 cm_ioctlQueryOptions_t options;
1741 if (as->parms[1].items)
1744 SetDotDefault(&as->parms[0].items);
1745 for(ti=as->parms[0].items; ti; ti=ti->next) {
1747 afs_uint32 filetype;
1750 memset(&fid, 0, sizeof(fid));
1751 memset(&options, 0, sizeof(options));
1753 options.size = sizeof(options);
1754 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1755 options.literal = literal;
1756 blob.in_size = options.size; /* no variable length data */
1759 blob.out_size = sizeof(cm_fid_t);
1760 blob.out = (char *) &fid;
1761 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
1762 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1765 Die(errno, ti->data);
1770 blob.out_size = sizeof(filetype);
1771 blob.out = &filetype;
1773 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1775 blob.out_size = MAXSIZE;
1777 memset(space, 0, sizeof(space));
1778 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
1780 Die(errno, ti->data);
1784 hosts = (afs_int32 *) space;
1785 printf("%s %s is on host%s ",
1786 filetypestr(filetype),
1788 (hosts[0] && !hosts[1]) ? "": "s");
1789 for(j=0; j<MAXHOSTS; j++) {
1792 tp = hostutil_GetNameByINet(hosts[j]);
1802 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1805 struct ViceIoctl blob;
1806 struct cmd_item *ti;
1808 struct VolumeStatus *status;
1811 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1812 " used", " avail", " %used");
1813 SetDotDefault(&as->parms[0].items);
1814 for(ti=as->parms[0].items; ti; ti=ti->next) {
1816 blob.out_size = MAXSIZE;
1819 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1821 Die(errno, ti->data);
1825 status = (VolumeStatus *)space;
1826 name = (char *)status + sizeof(*status);
1827 QuickPrintSpace(status, name);
1833 QuotaCmd(struct cmd_syndesc *as, void *arock)
1836 struct ViceIoctl blob;
1837 struct cmd_item *ti;
1839 struct VolumeStatus *status;
1842 SetDotDefault(&as->parms[0].items);
1843 for(ti=as->parms[0].items; ti; ti=ti->next) {
1845 blob.out_size = MAXSIZE;
1848 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1850 Die(errno, ti->data);
1854 status = (VolumeStatus *)space;
1855 if (status->MaxQuota)
1856 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1859 printf("%2.0f%% of quota used.\n", quotaPct);
1865 ListMountCmd(struct cmd_syndesc *as, void *arock)
1868 struct ViceIoctl blob;
1869 struct cmd_item *ti;
1870 char orig_name[1024]; /*Original name, may be modified*/
1871 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1872 char parent_dir[1024]; /*Parent directory of true name*/
1873 char *last_component; /*Last component of true name*/
1875 struct stat statbuff; /*Buffer for status info*/
1876 #endif /* not WIN32 */
1878 int link_chars_read; /*Num chars read in readlink()*/
1879 #endif /* not WIN32 */
1880 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1883 for(ti=as->parms[0].items; ti; ti=ti->next) {
1887 strcpy(orig_name, ti->data);
1888 #else /* not WIN32 */
1889 sprintf(orig_name, "%s%s",
1890 (ti->data[0] == '/') ? "" : "./",
1892 #endif /* not WIN32 */
1895 if (lstat(orig_name, &statbuff) < 0) {
1896 /* if lstat fails, we should still try the pioctl, since it
1897 * may work (for example, lstat will fail, but pioctl will
1898 * work if the volume of offline (returning ENODEV). */
1899 statbuff.st_mode = S_IFDIR; /* lie like pros */
1903 * The lstat succeeded. If the given file is a symlink, substitute
1904 * the file name with the link name.
1906 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1909 * Read name of resolved file.
1911 link_chars_read = readlink(orig_name, true_name, 1024);
1912 if (link_chars_read <= 0) {
1914 "%s: Can't read target name for '%s' symbolic link!\n",
1921 * Add a trailing null to what was read, bump the length.
1923 true_name[link_chars_read++] = 0;
1926 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1927 * have to create a full pathname using the original name and the
1928 * relative symlink name. Find the rightmost slash in the original
1929 * name (we know there is one) and splice in the symlink value.
1931 if (true_name[0] != '\\') {
1932 last_component = (char *) strrchr(orig_name, '\\');
1933 strcpy(++last_component, true_name);
1934 strcpy(true_name, orig_name);
1937 strcpy(true_name, orig_name);
1939 strcpy(true_name, orig_name);
1943 * Find rightmost slash, if any.
1946 last_component = (char *) strrchr(true_name, '\\');
1947 if (!last_component)
1949 last_component = (char *) strrchr(true_name, '/');
1950 if (last_component) {
1952 * Found it. Designate everything before it as the parent directory,
1953 * everything after it as the final component.
1955 strncpy(parent_dir, true_name, last_component - true_name + 1);
1956 parent_dir[last_component - true_name + 1] = 0;
1957 last_component++; /*Skip the slash*/
1959 if (!InAFS(parent_dir)) {
1960 const char * nbname = NetbiosName();
1961 int len = (int)strlen(nbname);
1963 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
1964 parent_dir[len+2] == '\\' &&
1965 parent_dir[len+3] == '\0' &&
1966 !strnicmp(nbname,&parent_dir[2],len))
1968 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
1974 * No slash appears in the given file name. Set parent_dir to the current
1975 * directory, and the last component as the given name.
1977 fs_ExtractDriveLetter(true_name, parent_dir);
1978 strcat(parent_dir, ".");
1979 last_component = true_name;
1980 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1983 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1984 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
1985 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
1990 blob.in = last_component;
1991 blob.in_size = (long)strlen(last_component)+1;
1992 blob.out_size = MAXSIZE;
1994 memset(space, 0, MAXSIZE);
1996 code = pioctl_utf8(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1999 printf("'%s' is a %smount point for volume '%s'\n",
2001 (thru_symlink ? "symbolic link, leading to a " : ""),
2005 if (errno == EINVAL) {
2006 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
2008 Die(errno, (ti->data ? ti->data : parent_dir));
2017 MakeMountCmd(struct cmd_syndesc *as, void *arock)
2020 char *cellName, *volName, *tmpName;
2022 char localCellName[128];
2024 char path[1024] = "";
2025 struct afsconf_cell info;
2026 struct vldbentry vldbEntry;
2027 struct ViceIoctl blob;
2030 if (as->parms[2].items) /* cell name specified */
2031 cellName = as->parms[2].items->data;
2034 volName = as->parms[1].items->data;
2036 if (strlen(volName) >= 64) {
2037 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
2041 /* Check for a cellname in the volume specification, and complain
2042 * if it doesn't match what was specified with -cell */
2043 if (tmpName = strchr(volName, ':')) {
2046 if (strcasecmp(cellName,volName)) {
2047 fprintf(stderr,"fs: cellnames do not match.\n");
2052 volName = ++tmpName;
2055 parent = Parent(as->parms[0].items->data);
2056 if (!InAFS(parent)) {
2058 const char * nbname = NetbiosName();
2059 int len = (int)strlen(nbname);
2061 if (parent[0] == '\\' && parent[1] == '\\' &&
2062 parent[len+2] == '\\' &&
2063 parent[len+3] == '\0' &&
2064 !strnicmp(nbname,&parent[2],len))
2066 sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
2067 parent = Parent(path);
2068 if (!InAFS(parent)) {
2069 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2075 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2080 if ( strlen(path) == 0 )
2081 strcpy(path, as->parms[0].items->data);
2083 if ( IsFreelanceRoot(parent) ) {
2085 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2091 blob.out_size = sizeof(localCellName);
2092 blob.out = localCellName;
2093 code = pioctl_utf8(parent, VIOC_GET_WS_CELL, &blob, 1);
2095 cellName = localCellName;
2099 code = GetCell(parent,space);
2105 code = GetCellName(cellName?cellName:space, &info);
2109 if (!(as->parms[4].items)) {
2110 /* not fast, check which cell the mountpoint is being created in */
2112 /* not fast, check name with VLDB */
2114 code = VLDBInit(1, &info);
2116 /* make the check. Don't complain if there are problems with init */
2117 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2118 if (code == VL_NOENT) {
2119 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2120 pn, volName, cellName ? cellName : space);
2125 if (as->parms[3].items) /* if -rw specified */
2130 /* cellular mount point, prepend cell prefix */
2131 strcat(space, info.name);
2134 strcat(space, volName); /* append volume name */
2135 strcat(space, "."); /* stupid convention; these end with a period */
2137 /* create symlink with a special pioctl for Windows NT, since it doesn't
2138 * have a symlink system call.
2141 blob.in_size = 1 + (long)strlen(space);
2144 code = pioctl_utf8(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2145 #else /* not WIN32 */
2146 code = symlink(space, path);
2147 #endif /* not WIN32 */
2156 * Delete AFS mount points. Variables are used as follows:
2157 * tbuffer: Set to point to the null-terminated directory name of the mount point
2158 * (or ``.'' if none is provided)
2159 * tp: Set to point to the actual name of the mount point to nuke.
2162 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2164 struct ViceIoctl blob;
2165 struct cmd_item *ti;
2167 char lsbuffer[1024];
2171 for(ti=as->parms[0].items; ti; ti=ti->next) {
2173 tp = (char *) strrchr(ti->data, '\\');
2175 tp = (char *) strrchr(ti->data, '/');
2177 strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1)); /* the dir name */
2179 tp++; /* skip the slash */
2182 if (!InAFS(tbuffer)) {
2183 const char * nbname = NetbiosName();
2184 int len = (int)strlen(nbname);
2186 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2187 tbuffer[len+2] == '\\' &&
2188 tbuffer[len+3] == '\0' &&
2189 !strnicmp(nbname,&tbuffer[2],len))
2191 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
2196 fs_ExtractDriveLetter(ti->data, tbuffer);
2197 strcat(tbuffer, ".");
2199 fs_StripDriveLetter(tp, tp, 0);
2202 blob.in_size = (long)strlen(tp)+1;
2203 blob.out = lsbuffer;
2204 blob.out_size = sizeof(lsbuffer);
2205 code = pioctl_utf8(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2207 if (errno == EINVAL) {
2208 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2210 Die(errno, ti->data);
2213 continue; /* don't bother trying */
2216 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2217 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2219 continue; /* skip */
2224 blob.in_size = (long)strlen(tp)+1;
2225 code = pioctl_utf8(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2227 Die(errno, ti->data);
2238 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2241 struct ViceIoctl blob;
2245 struct afsconf_cell info;
2246 struct chservinfo checkserv;
2248 memset(&checkserv, 0, sizeof(struct chservinfo));
2249 blob.in_size=sizeof(struct chservinfo);
2250 blob.in=(caddr_t)&checkserv;
2252 blob.out_size = MAXSIZE;
2254 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2256 /* prepare flags for checkservers command */
2257 temp = 2; /* default to checking local cell only */
2258 if (as->parms[2].items)
2259 temp |= 1; /* set fast flag */
2260 if (as->parms[1].items)
2261 temp &= ~2; /* turn off local cell check */
2263 checkserv.magic = 0x12345678; /* XXX */
2264 checkserv.tflags=temp;
2266 /* now copy in optional cell name, if specified */
2267 if (as->parms[0].items) {
2268 code = GetCellName(as->parms[0].items->data, &info);
2272 strcpy(checkserv.tbuffer,info.name);
2273 checkserv.tsize=(int)strlen(info.name)+1;
2275 strcpy(checkserv.tbuffer,"\0");
2279 if(as->parms[3].items) {
2280 checkserv.tinterval=atol(as->parms[3].items->data);
2283 if(checkserv.tinterval<0) {
2284 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2285 checkserv.tinterval=-1;
2286 } else if(checkserv.tinterval> 600) {
2287 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2288 checkserv.tinterval=600; /* 10 min max interval */
2291 checkserv.tinterval = -1; /* don't change current interval */
2294 if ( checkserv.tinterval >= 0 ) {
2297 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2302 fprintf (stderr,"Permission denied: requires root access.\n");
2308 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
2310 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2311 printf("Must be root to change -interval\n");
2317 memcpy(&temp, space, sizeof(afs_int32));
2318 if (checkserv.tinterval >= 0) {
2319 if (checkserv.tinterval > 0)
2320 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2321 checkserv.tinterval, temp);
2323 printf("The current down server probe interval is %d secs\n", temp);
2327 printf("All servers are running.\n");
2329 printf("These servers unavailable due to network or server problems: ");
2330 for(j=0; j < MAXHOSTS; j++) {
2331 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2334 tp = hostutil_GetNameByINet(temp);
2344 MessagesCmd(struct cmd_syndesc *as, void *arock)
2347 struct ViceIoctl blob;
2348 struct gaginfo gagflags;
2349 struct cmd_item *show;
2351 memset(&gagflags, 0, sizeof(struct gaginfo));
2352 blob.in_size = sizeof(struct gaginfo);
2353 blob.in = (caddr_t ) &gagflags;
2354 blob.out_size = MAXSIZE;
2356 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2358 if (show = as->parms[0].items) {
2359 if (!strcasecmp (show->data, "user"))
2360 gagflags.showflags |= GAGUSER;
2361 else if (!strcasecmp (show->data, "console"))
2362 gagflags.showflags |= GAGCONSOLE;
2363 else if (!strcasecmp (show->data, "all"))
2364 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2365 else if (!strcasecmp (show->data, "none"))
2369 "unrecognized flag %s: must be in {user,console,all,none}\n",
2378 code = pioctl_utf8(0, VIOC_GAG, &blob, 1);
2387 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2390 struct ViceIoctl blob;
2394 code = pioctl_utf8(0, VIOCCKBACK, &blob, 1);
2399 printf("All volumeID/name mappings checked.\n");
2405 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2408 struct ViceIoctl blob;
2413 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2418 fprintf (stderr,"Permission denied: requires root access.\n");
2423 if (!as->parms[0].items && !as->parms[1].items) {
2424 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2427 if (as->parms[0].items) {
2428 code = util_GetInt32(as->parms[0].items->data, &temp);
2430 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2435 blob.in = (char *) &temp;
2436 blob.in_size = sizeof(afs_int32);
2438 code = pioctl_utf8(0, VIOCSETCACHESIZE, &blob, 1);
2440 Die(errno, (char *) 0);
2444 printf("New cache size set.\n");
2449 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2452 struct ViceIoctl blob;
2453 cm_cacheParms_t parms;
2455 memset(&parms, 0, sizeof(parms));
2458 blob.out_size = sizeof(parms);
2459 blob.out = (char *) &parms;
2460 code = pioctl_utf8(0, VIOCGETCACHEPARMS, &blob, 1);
2466 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2467 parms.parms[1], parms.parms[0]);
2468 if (parms.parms[1] > parms.parms[0])
2469 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2474 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2477 afs_int32 i, j, *lp, magic, size;
2479 afs_int32 addr, maxa = OMAXHOSTS;
2480 struct ViceIoctl blob;
2483 resolve = !(as->parms[0].items); /* -numeric */
2485 for(i=0;i<1000;i++) {
2487 memcpy(tp, &i, sizeof(afs_int32));
2488 tp = (char *)(space + sizeof(afs_int32));
2489 lp = (afs_int32 *)tp;
2491 size = sizeof(afs_int32) + sizeof(afs_int32);
2492 blob.out_size = MAXSIZE;
2493 blob.in_size = sizeof(afs_int32);
2496 code = pioctl_utf8(0, VIOCGETCELL, &blob, 1);
2499 break; /* done with the list */
2504 memcpy(&magic, tp, sizeof(afs_int32));
2505 if (magic == 0x12345678) {
2507 tp += sizeof(afs_int32);
2509 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2510 for(j=0; j < maxa; j++) {
2511 char *name, tbuffer[20];
2513 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2518 name = hostutil_GetNameByINet(addr);
2521 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2522 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2525 printf(" %s", name);
2534 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2537 char *tp, *aliasName, *realName;
2538 struct ViceIoctl blob;
2542 memcpy(tp, &i, sizeof(afs_int32));
2543 blob.out_size = MAXSIZE;
2544 blob.in_size = sizeof(afs_int32);
2547 code = pioctl_utf8(0, VIOC_GETALIAS, &blob, 1);
2550 break; /* done with the list */
2556 tp += strlen(aliasName) + 1;
2558 printf("Alias %s for cell %s\n", aliasName, realName);
2564 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2567 struct ViceIoctl blob;
2568 struct cmd_item *ti;
2570 struct hostent *thp;
2574 ti = as->parms[0].items;
2577 thp = hostutil_GetHostByName(ti->data);
2579 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2582 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2584 hostAddr = 0; /* means don't set host */
2585 setp = 0; /* aren't setting host */
2588 /* now do operation */
2589 blob.in_size = sizeof(afs_int32);
2590 blob.out_size = sizeof(afs_int32);
2591 blob.in = (char *) &hostAddr;
2592 blob.out = (char *) &hostAddr;
2594 code = pioctl_utf8(0, VIOC_CBADDR, &blob, 1);
2604 NewCellCmd(struct cmd_syndesc *as, void *arock)
2607 afs_int32 code, linkedstate=0, size=0, *lp;
2608 struct ViceIoctl blob;
2609 struct cmd_item *ti;
2610 char *tp, *cellname=0;
2611 struct hostent *thp;
2612 afs_int32 fsport = 0, vlport = 0;
2614 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
2616 lp = (afs_int32 *)tp;
2618 tp += sizeof(afs_int32);
2619 for(ti=as->parms[1].items; ti; ti=ti->next) {
2620 thp = hostutil_GetHostByName(ti->data);
2622 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2626 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2627 tp += sizeof(afs_int32);
2630 if (as->parms[2].items) {
2632 * Link the cell, for the purposes of volume location, to the specified
2635 cellname = as->parms[2].items->data;
2638 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2639 if (as->parms[3].items) {
2640 code = util_GetInt32(as->parms[3].items->data, &vlport);
2642 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2646 if (as->parms[4].items) {
2647 code = util_GetInt32(as->parms[4].items->data, &fsport);
2649 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2654 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
2655 lp = (afs_int32 *)tp;
2659 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2660 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2661 tp = (char *)(space + size);
2663 strcpy(tp, cellname);
2664 size += strlen(cellname) + 1;
2666 blob.in_size = size;
2669 code = pioctl_utf8(0, VIOCNEWCELL, &blob, 1);
2675 struct ViceIoctl blob;
2678 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2683 blob.in = (char *) 0;
2684 blob.out_size = MAXSIZE;
2687 code = pioctl_utf8((char *) 0, VIOCNEWCELL, &blob, 1);
2690 Die(errno, (char *) 0);
2694 printf("Cell servers information refreshed\n");
2701 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2704 struct ViceIoctl blob;
2706 char *aliasName, *realName;
2708 /* Setup and do the NEWALIAS pioctl call */
2709 aliasName = as->parms[0].items->data;
2710 realName = as->parms[1].items->data;
2712 strcpy(tp, aliasName);
2713 tp += strlen(aliasName) + 1;
2714 strcpy(tp, realName);
2715 tp += strlen(realName) + 1;
2717 blob.in_size = tp - space;
2721 code = pioctl_utf8(0, VIOC_NEWALIAS, &blob, 1);
2723 if (errno == EEXIST) {
2725 "%s: cell name `%s' in use by an existing cell.\n", pn,
2737 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2740 struct cmd_item *ti;
2741 struct ViceIoctl blob;
2744 cm_ioctlQueryOptions_t options;
2746 if (as->parms[1].items)
2749 SetDotDefault(&as->parms[0].items);
2750 for(ti=as->parms[0].items; ti; ti=ti->next) {
2752 afs_uint32 filetype;
2753 char cell[CELL_MAXNAMELEN];
2756 memset(&fid, 0, sizeof(fid));
2757 memset(&options, 0, sizeof(options));
2759 options.size = sizeof(options);
2760 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
2761 options.literal = literal;
2762 blob.in_size = options.size; /* no variable length data */
2765 blob.out_size = sizeof(cm_fid_t);
2766 blob.out = (char *) &fid;
2767 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1)) {
2768 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
2771 Die(errno, ti->data);
2776 blob.out_size = sizeof(filetype);
2777 blob.out = &filetype;
2779 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
2781 blob.out_size = CELL_MAXNAMELEN;
2784 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
2786 if (errno == ENOENT)
2787 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2789 Die(errno, ti->data);
2793 printf("%s %s lives in cell '%s'\n",
2794 filetypestr(filetype),
2801 WSCellCmd(struct cmd_syndesc *as, void *arock)
2804 struct ViceIoctl blob;
2808 blob.out_size = MAXSIZE;
2811 code = pioctl_utf8(NULL, VIOC_GET_WS_CELL, &blob, 1);
2818 printf("This workstation belongs to cell '%s'\n", space);
2824 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
2826 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2831 #ifndef AFS_NT40_ENV
2833 MonitorCmd(struct cmd_syndesc *as, void *arock)
2836 struct ViceIoctl blob;
2837 struct cmd_item *ti;
2839 struct hostent *thp;
2843 ti = as->parms[0].items;
2847 if (!strcmp(ti->data, "off")) {
2848 hostAddr = 0xffffffff;
2850 thp = hostutil_GetHostByName(ti->data);
2852 if (!strcmp(ti->data, "localhost")) {
2853 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2854 hostAddr = htonl(0x7f000001);
2856 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2860 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2864 hostAddr = 0; /* means don't set host */
2865 setp = 0; /* aren't setting host */
2868 /* now do operation */
2869 blob.in_size = sizeof(afs_int32);
2870 blob.out_size = sizeof(afs_int32);
2871 blob.in = (char *) &hostAddr;
2872 blob.out = (char *) &hostAddr;
2873 code = pioctl_utf8(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2879 printf("%s: new monitor host set.\n", pn);
2881 /* now decode old address */
2882 if (hostAddr == 0xffffffff) {
2883 printf("Cache monitoring is currently disabled.\n");
2885 tp = hostutil_GetNameByINet(hostAddr);
2886 printf("Using host %s for monitor services.\n", tp);
2891 #endif /* AFS_NT40_ENV */
2894 SysNameCmd(struct cmd_syndesc *as, void *arock)
2897 struct ViceIoctl blob;
2898 struct cmd_item *ti;
2899 char *input = space;
2902 ti = as->parms[0].items;
2906 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2911 fprintf (stderr,"Permission denied: requires root access.\n");
2919 blob.out_size = MAXSIZE;
2920 blob.in_size = sizeof(afs_int32);
2921 memcpy(input, &setp, sizeof(afs_int32));
2922 input += sizeof(afs_int32);
2923 for (; ti; ti = ti->next) {
2925 blob.in_size += (long)strlen(ti->data) + 1;
2926 if (blob.in_size > MAXSIZE) {
2927 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2928 setp > 1 ? "s" : "");
2931 strcpy(input, ti->data);
2932 input += strlen(ti->data);
2935 memcpy(space, &setp, sizeof(afs_int32));
2936 code = pioctl_utf8(0, VIOC_AFS_SYSNAME, &blob, 1);
2942 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2947 memcpy(&setp, input, sizeof(afs_int32));
2948 input += sizeof(afs_int32);
2950 fprintf(stderr,"No sysname name value was found\n");
2954 printf("Current sysname%s is", setp > 1 ? " list" : "");
2955 for (; setp > 0; --setp ) {
2956 printf(" \'%s\'", input);
2957 input += strlen(input) + 1;
2963 #ifndef AFS_NT40_ENV
2964 static char *exported_types[] = {"null", "nfs", ""};
2965 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2968 struct ViceIoctl blob;
2969 struct cmd_item *ti;
2970 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
2971 int exportcall, pwsync = 0, smounts = 0;
2975 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2980 fprintf (stderr,"Permission denied: requires root access.\n");
2985 ti = as->parms[0].items;
2986 if (strcmp(ti->data, "nfs") == 0)
2987 type = 0x71; /* NFS */
2990 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2993 ti = as->parms[1].items;
2995 if (strcmp(ti->data, "on") == 0)
2997 else if (strcmp(ti->data, "off") == 0)
3000 fprintf(stderr, "Illegal argument %s\n", ti->data);
3005 if (ti = as->parms[2].items) { /* -noconvert */
3006 if (strcmp(ti->data, "on") == 0)
3008 else if (strcmp(ti->data, "off") == 0)
3011 fprintf(stderr, "Illegal argument %s\n", ti->data);
3015 if (ti = as->parms[3].items) { /* -uidcheck */
3016 if (strcmp(ti->data, "on") == 0)
3018 else if (strcmp(ti->data, "off") == 0)
3021 fprintf(stderr, "Illegal argument %s\n", ti->data);
3025 if (ti = as->parms[4].items) { /* -submounts */
3026 if (strcmp(ti->data, "on") == 0)
3028 else if (strcmp(ti->data, "off") == 0)
3031 fprintf(stderr, "Illegal argument %s\n", ti->data);
3035 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
3038 blob.in = (char *) &exportcall;
3039 blob.in_size = sizeof(afs_int32);
3040 blob.out = (char *) &exportcall;
3041 blob.out_size = sizeof(afs_int32);
3042 code = pioctl_utf8(0, VIOC_EXPORTAFS, &blob, 1);
3044 if (errno == ENODEV) {
3046 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
3053 if (exportcall & 1) {
3054 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
3055 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
3056 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
3057 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
3059 printf("'%s' translator is disabled\n", exported_types[type]);
3068 GetCellCmd(struct cmd_syndesc *as, void *arock)
3071 struct ViceIoctl blob;
3072 struct afsconf_cell info;
3073 struct cmd_item *ti;
3080 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3081 for(ti=as->parms[0].items; ti; ti=ti->next) {
3083 blob.out_size = sizeof(args);
3084 blob.out = (caddr_t) &args;
3085 code = GetCellName(ti->data, &info);
3090 blob.in_size = 1+(long)strlen(info.name);
3091 blob.in = info.name;
3092 code = pioctl_utf8(0, VIOC_GETCELLSTATUS, &blob, 1);
3094 if (errno == ENOENT)
3095 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3097 Die(errno, info.name);
3101 printf("Cell %s status: ", info.name);
3107 printf("no setuid allowed");
3109 printf("setuid allowed");
3111 printf(", using old VLDB");
3117 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3120 struct ViceIoctl blob;
3121 struct afsconf_cell info;
3122 struct cmd_item *ti;
3130 /* Check arguments. */
3131 if (as->parms[1].items && as->parms[2].items) {
3132 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3136 /* figure stuff to set */
3142 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3147 fprintf (stderr,"Permission denied: requires root access.\n");
3152 if (! as->parms[1].items)
3153 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3155 /* set stat for all listed cells */
3156 for(ti=as->parms[0].items; ti; ti=ti->next) {
3158 code = GetCellName(ti->data, &info);
3163 strcpy(args.cname, info.name);
3164 blob.in_size = sizeof(args);
3165 blob.in = (caddr_t) &args;
3167 blob.out = (caddr_t) 0;
3168 code = pioctl_utf8(0, VIOC_SETCELLSTATUS, &blob, 1);
3170 Die(errno, info.name); /* XXX added cell name to Die() call */
3178 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3180 strcpy(infop->name, cellNamep);
3185 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3190 cm_GetConfigDir(confDir, sizeof(confDir));
3192 code = ugen_ClientInit(noAuthFlag, confDir,
3193 info->name, 0, &uclient,
3194 NULL, pn, rxkad_clear,
3195 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3196 0, 0, USER_SERVICE_ID);
3201 static struct ViceIoctl gblob;
3202 static int debug = 0;
3204 * here follow some routines in suport of the setserverprefs and
3205 * getserverprefs commands. They are:
3206 * SetPrefCmd "top-level" routine
3207 * addServer adds a server to the list of servers to be poked into the
3208 * kernel. Will poke the list into the kernel if it threatens
3210 * pokeServers pokes the existing list of servers and ranks into the kernel
3211 * GetPrefCmd reads the Cache Manager's current list of server ranks
3220 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3222 ssp = (cm_SSetPref_t *)space;
3223 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3229 * returns -1 if error message printed,
3231 * errno value if error and no error message printed
3238 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3239 if (code && (errno == EINVAL)) {
3240 struct setspref *ssp;
3241 ssp = (struct setspref *)gblob.in;
3242 if (!(ssp->flags & DBservers)) {
3243 gblob.in = (void *)&(ssp->servers[0]);
3244 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3245 code = pioctl_utf8(0, VIOC_SETSPREFS33, &gblob, 1);
3246 return code ? errno : 0;
3249 "This cache manager does not support VL server preferences.\n");
3253 return code ? errno : 0;
3259 addServer(char *name, unsigned short rank)
3264 struct hostent *thostent;
3268 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3270 #define MAXUSHORT ((unsigned short) ~0)
3275 thostent = hostutil_GetHostByName(name);
3277 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3281 ssp = (cm_SSetPref_t *)(gblob.in);
3283 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3284 code = pokeServers();
3285 ssp->num_servers = 0;
3288 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3289 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3290 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3291 gblob.in_size += sizeof(cm_SPref_t);
3294 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3300 * returns -1 if error message printed,
3302 * errno value if error and no error message printed
3305 addServer(char *name, afs_int32 rank)
3308 struct setspref *ssp;
3310 struct hostent *thostent;
3316 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3318 #define MAXUSHORT ((unsigned short) ~0)
3322 thostent = hostutil_GetHostByName(name);
3324 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3328 ssp = (struct setspref *)(gblob.in);
3330 for (t = 0; thostent->h_addr_list[t]; t++) {
3331 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3332 code = pokeServers();
3335 ssp->num_servers = 0;
3338 sp = (struct spref *)(gblob.in + gblob.in_size);
3339 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3340 sizeof(afs_uint32));
3341 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3342 gblob.in_size += sizeof(struct spref);
3346 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3347 name, sp->rank, sp->server.s_addr);
3355 static BOOL IsWindowsNT (void)
3357 static BOOL fChecked = FALSE;
3358 static BOOL fIsWinNT = FALSE;
3362 OSVERSIONINFO Version;
3366 memset (&Version, 0x00, sizeof(Version));
3367 Version.dwOSVersionInfoSize = sizeof(Version);
3369 if (GetVersionEx (&Version))
3371 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3381 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3385 struct cmd_item *ti;
3390 ssp = (cm_SSetPref_t *)space;
3392 ssp->num_servers = 0;
3393 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3396 gblob.out_size = MAXSIZE;
3399 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3405 ti = as->parms[2].items; /* -file */
3407 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3408 if (!(infd = fopen(ti->data,"r" ))) {
3410 Die(errno,ti->data);
3413 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3414 code = addServer (name, (unsigned short) rank);
3418 ti = as->parms[3].items; /* -stdin */
3420 while ( scanf("%79s%ld", name, &rank) != EOF) {
3421 code = addServer (name, (unsigned short) rank);
3425 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3430 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3432 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3436 code = pokeServers();
3438 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3440 ssp = (cm_SSetPref_t *)space;
3441 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3443 ssp->flags = CM_SPREF_VLONLY;
3444 ssp->num_servers = 0;
3446 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3451 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3453 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3458 if (as->parms[1].items) {
3460 printf("now poking vlservers\n");
3461 code = pokeServers();
3471 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3475 struct cmd_item *ti;
3478 struct setspref *ssp;
3479 int error = 0; /* -1 means error message printed,
3480 * >0 means errno value for unprinted message */
3482 ssp = (struct setspref *)space;
3484 ssp->num_servers = 0;
3485 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3488 gblob.out_size = MAXSIZE;
3492 fprintf(stderr, "Permission denied: requires root access.\n");
3496 ti = as->parms[2].items; /* -file */
3499 fprintf(stderr, "opening file %s\n", ti->data);
3500 if (!(infd = fopen(ti->data, "r"))) {
3504 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3505 code = addServer(name, (unsigned short)rank);
3512 ti = as->parms[3].items; /* -stdin */
3514 while (scanf("%79s%ld", name, &rank) != EOF) {
3515 code = addServer(name, (unsigned short)rank);
3521 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3526 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3530 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3534 code = pokeServers();
3538 printf("now working on vlservers, code=%d\n", code);
3540 ssp = (struct setspref *)space;
3541 ssp->flags = DBservers;
3542 ssp->num_servers = 0;
3543 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3546 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3551 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3555 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3560 if (as->parms[1].items) {
3562 printf("now poking vlservers\n");
3563 code = pokeServers();
3571 return error ? 1 : 0;
3577 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3580 struct cmd_item *ti;
3581 char *name, tbuffer[20];
3586 struct ViceIoctl blob;
3587 struct cm_SPrefRequest *in;
3588 struct cm_SPrefInfo *out;
3592 ti = as->parms[0].items; /* -file */
3594 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3595 if (!(outfd = freopen(ti->data,"w",stdout))) {
3596 Die(errno,ti->data);
3601 ti = as->parms[1].items; /* -numeric */
3603 ti = as->parms[2].items; /* -vlservers */
3604 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3605 /* ti = as->parms[3].items; -cell */
3607 in = (struct cm_SPrefRequest *)space;
3611 blob.in_size=sizeof(struct cm_SPrefRequest);
3612 blob.in = (char *)in;
3614 blob.out_size = MAXSIZE;
3616 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3617 in->flags = vlservers;
3619 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3621 perror("getserverprefs pioctl");
3625 out = (struct cm_SPrefInfo *) blob.out;
3627 for (i=0;i<out->num_servers;i++) {
3629 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3632 addr = ntohl(out->servers[i].host.s_addr);
3633 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3634 (addr>>8) & 0xff, addr & 0xff);
3637 printf ("%-50s %5u\n",name,out->servers[i].rank);
3640 in->offset = out->next_offset;
3642 } while (!code && out->next_offset > 0);
3648 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3651 struct cmd_item *ti;
3652 char *name, tbuffer[20];
3653 afs_int32 rank, addr;
3657 struct ViceIoctl blob;
3658 struct sprefrequest *in;
3659 struct sprefinfo *out;
3662 ti = as->parms[0].items; /* -file */
3665 fprintf(stderr, "opening file %s\n", ti->data);
3666 if (!(outfd = freopen(ti->data, "w", stdout))) {
3672 ti = as->parms[1].items; /* -numeric */
3674 ti = as->parms[2].items; /* -vlservers */
3675 vlservers |= (ti ? DBservers : 0);
3676 /* ti = as->parms[3].items; -cell */
3678 in = (struct sprefrequest *)space;
3682 blob.in_size = sizeof(struct sprefrequest);
3683 blob.in = (char *)in;
3685 blob.out_size = MAXSIZE;
3688 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3689 in->flags = vlservers;
3691 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
3693 perror("getserverprefs pioctl");
3697 out = (struct sprefinfo *)blob.out;
3699 for (i = 0; i < out->num_servers; i++) {
3701 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);