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 MAXCELLCHARS 64
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(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(apath, VIOC_FILE_CELL_NAME, &blob, 1);
274 return !stricmp("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;
619 for (;first; first = next) {
623 first = ta->pluslist;
626 for (;first; first = next) {
635 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
637 printf("Volume status for vid = %u named %s is\n",status->Vid, name);
639 printf("Current offline message is %s\n",offmsg);
641 printf("Current message of the day is %s\n",motd);
642 printf("Current disk quota is ");
643 if (status->MaxQuota != 0)
644 printf("%d\n", status->MaxQuota);
646 printf("unlimited\n");
647 printf("Current blocks used are %d\n",status->BlocksInUse);
648 printf("The partition has %d blocks available out of %d\n",
649 status->PartBlocksAvail, status->PartMaxBlocks);
654 QuickPrintStatus(VolumeStatus *status, char *name)
656 double QuotaUsed =0.0;
657 double PartUsed =0.0;
659 printf("%-25.25s",name);
661 if (status->MaxQuota != 0) {
662 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
663 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
665 printf("no limit%10d", status->BlocksInUse);
667 if (QuotaUsed > 90.0){
668 printf(" %5.0f%%<<", QuotaUsed);
671 printf(" %5.0f%% ", QuotaUsed);
672 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
673 if (PartUsed > 97.0){
674 printf(" %9.0f%%<<", PartUsed);
677 printf(" %9.0f%% ", PartUsed);
679 printf(" <<WARNING\n");
686 QuickPrintSpace(VolumeStatus *status, char *name)
688 double PartUsed =0.0;
690 printf("%-25.25s",name);
692 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
694 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
695 if (PartUsed > 90.0){
696 printf(" %4.0f%%<<", PartUsed);
699 printf(" %4.0f%% ", PartUsed);
701 printf(" <<WARNING\n");
708 AclToString(struct Acl *acl)
710 static char mydata[MAXSIZE];
711 char tstring[MAXSIZE];
716 sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
719 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
720 for (tp = acl->pluslist;tp;tp=tp->next) {
721 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
722 strcat(mydata, tstring);
724 for (tp = acl->minuslist;tp;tp=tp->next) {
725 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
726 strcat(mydata, tstring);
731 static DWORD IsFreelance(void)
738 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
739 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
740 if (code == ERROR_SUCCESS) {
741 dummyLen = sizeof(cm_freelanceEnabled);
742 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
743 (BYTE *) &enabled, &dummyLen);
744 RegCloseKey (parmKey);
749 static const char * NetbiosName(void)
751 static char buffer[1024] = "AFS";
757 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
758 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
759 if (code == ERROR_SUCCESS) {
760 dummyLen = sizeof(buffer);
761 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
763 RegCloseKey (parmKey);
765 strcpy(buffer, "AFS");
770 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
772 static BOOL IsAdmin (void)
774 static BOOL fAdmin = FALSE;
775 static BOOL fTested = FALSE;
779 /* Obtain the SID for the AFS client admin group. If the group does
780 * not exist, then assume we have AFS client admin privileges.
782 PSID psidAdmin = NULL;
783 DWORD dwSize, dwSize2;
784 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
785 char *pszRefDomain = NULL;
786 SID_NAME_USE snu = SidTypeGroup;
788 dwSize = sizeof(pszAdminGroup);
790 if (!GetComputerName(pszAdminGroup, &dwSize)) {
791 /* Can't get computer name. We return false in this case.
792 Retain fAdmin and fTested. This shouldn't happen.*/
799 strcat(pszAdminGroup,"\\");
800 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
802 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
803 /* that should always fail. */
805 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
806 /* if we can't find the group, then we allow the operation */
811 if (dwSize == 0 || dwSize2 == 0) {
817 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
819 pszRefDomain = (char *)malloc(dwSize2);
820 assert(pszRefDomain);
822 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
823 /* We can't lookup the group now even though we looked it up earlier.
824 Could this happen? */
827 /* Then open our current ProcessToken */
830 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
833 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
834 /* We'll have to allocate a chunk of memory to store the list of
835 * groups to which this user belongs; find out how much memory
839 PTOKEN_GROUPS pGroups;
841 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
843 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
846 /* Allocate that buffer, and read in the list of groups. */
847 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
849 /* Look through the list of group SIDs and see if any of them
850 * matches the AFS Client Admin group SID.
853 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
855 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
865 /* if do not have permission because we were not explicitly listed
866 * in the Admin Client Group let's see if we are the SYSTEM account
869 PTOKEN_USER pTokenUser;
870 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
871 PSID pSidLocalSystem = 0;
874 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
876 pTokenUser = (PTOKEN_USER)malloc(dwSize);
879 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
880 gle = GetLastError();
882 if (AllocateAndInitializeSid( &SIDAuth, 1,
883 SECURITY_LOCAL_SYSTEM_RID,
887 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
891 FreeSid(pSidLocalSystem);
910 SetACLCmd(struct cmd_syndesc *as, void *arock)
913 struct ViceIoctl blob;
915 struct cmd_item *ti, *ui;
919 int idf = getidf(as, parm_setacl_id);
923 if (as->parms[2].items)
927 plusp = !(as->parms[3].items);
928 for(ti=as->parms[0].items; ti;ti=ti->next) {
929 blob.out_size = MAXSIZE;
931 blob.in = blob.out = space;
932 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
934 Die(errno, ti->data);
940 ta = ParseAcl(space);
943 "fs: %s: invalid acl data returned from VIOCGETAL\n",
948 if (!plusp && ta->dfs) {
950 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
952 "(you may specify \"null\" to revoke all rights, however)\n");
959 ta = EmptyAcl(space);
961 ta = ParseAcl(space);
964 "fs: %s: invalid acl data returned from VIOCGETAL\n",
969 CleanAcl(ta, ti->data);
970 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
974 "%s: Missing second half of user/access pair.\n", pn);
978 rights = Convert(ui->next->data, ta->dfs, &rtype);
979 if (rtype == destroy && !ta->dfs) {
980 struct AclEntry *tlist;
982 tlist = (plusp ? ta->pluslist : ta->minuslist);
983 if (!FindList(tlist, ui->data))
986 if (rtype == deny && !ta->dfs)
988 if (rtype == destroy && ta->dfs)
990 ChangeList(ta, plusp, ui->data, rights);
992 blob.in = AclToString(ta);
994 blob.in_size = 1+(long)strlen(blob.in);
995 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
997 if (errno == EINVAL) {
999 static char *fsenv = 0;
1001 fsenv = (char *)getenv("FS_EXPERT");
1003 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
1006 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1007 "\nPossible reasons for this include:\n\n",
1008 " -You may have specified an inappropriate combination of rights.\n",
1009 " For example, some DFS-supported filesystems may not allow you to\n",
1010 " drop the \"c\" right from \"user_obj\".\n\n",
1011 " -A mask_obj may be required (it is likely required by the underlying\n",
1012 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
1013 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
1014 " does not automatically create or update the mask_obj. Try setting\n",
1015 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
1016 " users or groups. You can do this with a single command, such as\n",
1017 " \"fs sa mask_obj all user:somename read\"\n\n",
1018 " -A specified user or group may not exist.\n\n",
1019 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
1020 " This is probably not allowed by the underlying file system.\n\n",
1021 " -If you add a user or group to a DFS ACL, remember that it must be\n",
1022 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
1023 " may be local requirements on the format of the user or group name.\n",
1024 " Check with your cell administrator.\n\n",
1025 " -Or numerous other possibilities. It would be great if we could be more\n",
1026 " precise about the actual problem, but for various reasons, this is\n",
1027 " impractical via this interface. If you can't figure it out, you\n",
1028 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
1029 " whatever is provided). You may get better results. Good luck!\n\n",
1030 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
1034 "%s: Invalid argument, possible reasons include:\n",
1036 fprintf(stderr,"\t-File not in AFS\n");
1038 "\t-Too many users on access control list\n");
1040 "\t-Tried to add non-existent user to access control list\n");
1043 Die(errno, ti->data);
1054 CopyACLCmd(struct cmd_syndesc *as, void *arock)
1057 struct ViceIoctl blob;
1058 struct Acl *fa, *ta = 0;
1059 struct AclEntry *tp;
1060 struct cmd_item *ti;
1062 int idf = getidf(as, parm_copyacl_id);
1065 if (as->parms[2].items)
1069 blob.out_size = MAXSIZE;
1071 blob.in = blob.out = space;
1072 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1074 Die(errno, as->parms[0].items->data);
1077 fa = ParseAcl(space);
1080 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1081 as->parms[0].items->data);
1084 CleanAcl(fa, as->parms[0].items->data);
1085 for (ti=as->parms[1].items; ti;ti=ti->next) {
1086 blob.out_size = MAXSIZE;
1088 blob.in = blob.out = space;
1089 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1091 Die(errno, ti->data);
1098 ta = EmptyAcl(space);
1100 ta = ParseAcl(space);
1103 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1108 CleanAcl(ta, ti->data);
1109 if (ta->dfs != fa->dfs) {
1111 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1117 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1119 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1124 strcpy(ta->cell, fa->cell);
1126 for (tp = fa->pluslist;tp;tp=tp->next)
1127 ChangeList(ta, 1, tp->name, tp->rights);
1128 for (tp = fa->minuslist;tp;tp=tp->next)
1129 ChangeList(ta, 0, tp->name, tp->rights);
1130 blob.in = AclToString(ta);
1132 blob.in_size = 1+(long)strlen(blob.in);
1133 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1135 if (errno == EINVAL) {
1137 "%s: Invalid argument, possible reasons include:\n", pn);
1138 fprintf(stderr,"\t-File not in AFS\n");
1140 Die(errno, ti->data);
1151 /* pioctl() call to get the cellname of a pathname */
1153 GetCell(char *fname, char *cellname)
1156 struct ViceIoctl blob;
1159 blob.out_size = MAXCELLCHARS;
1160 blob.out = cellname;
1162 code = pioctl(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1166 /* Check if a username is valid: If it contains only digits (or a
1167 * negative sign), then it might be bad. We then query the ptserver
1171 BadName(char *aname, char *fname)
1173 afs_int32 tc, code, id;
1175 char cell[MAXCELLCHARS];
1178 for ( nm = aname; tc = *nm; nm++) {
1179 /* all must be '-' or digit to be bad */
1180 if (tc != '-' && (tc < '0' || tc > '9'))
1184 /* Go to the PRDB and see if this all number username is valid */
1185 code = GetCell(fname, cell);
1189 cm_GetConfigDir(confDir, sizeof(confDir));
1191 pr_Initialize(1, confDir, cell);
1192 code = pr_SNameToId(aname, &id);
1195 /* 1=>Not-valid; 0=>Valid */
1196 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1200 /* clean up an access control list of its bad entries; return 1 if we made
1201 any changes to the list, and 0 otherwise */
1203 CleanAcl(struct Acl *aa, char *fname)
1205 struct AclEntry *te, **le, *ne;
1208 /* Don't correct DFS ACL's for now */
1212 /* prune out bad entries */
1213 changes = 0; /* count deleted entries */
1215 for(te = aa->pluslist; te; te=ne) {
1217 if (BadName(te->name, fname)) {
1227 le = &aa->minuslist;
1228 for(te = aa->minuslist; te; te=ne) {
1230 if (BadName(te->name, fname)) {
1244 /* clean up an acl to not have bogus entries */
1246 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1250 struct ViceIoctl blob;
1252 struct cmd_item *ti;
1253 struct AclEntry *te;
1256 SetDotDefault(&as->parms[0].items);
1257 for(ti=as->parms[0].items; ti; ti=ti->next) {
1258 blob.out_size = MAXSIZE;
1261 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1263 Die(errno, ti->data);
1269 ta = ParseAcl(space);
1272 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1279 "%s: cleanacl is not supported for DFS access lists.\n",
1285 changes = CleanAcl(ta, ti->data);
1288 /* now set the acl */
1289 blob.in=AclToString(ta);
1290 blob.in_size = (long)strlen(blob.in)+1;
1292 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
1294 if (errno == EINVAL) {
1296 "%s: Invalid argument, possible reasons include\n",
1298 fprintf(stderr,"%s: File not in vice or\n", pn);
1300 "%s: Too many users on access control list or\n",
1303 Die(errno, ti->data);
1309 /* now list the updated acl */
1310 printf("Access list for %s is now\n", ti->data);
1311 if (ta->nplus > 0) {
1313 printf("Normal rights:\n");
1314 for(te = ta->pluslist;te;te=te->next) {
1315 printf(" %s ", te->name);
1316 PRights(te->rights, ta->dfs);
1320 if (ta->nminus > 0) {
1321 printf("Negative rights:\n");
1322 for(te = ta->minuslist;te;te=te->next) {
1323 printf(" %s ", te->name);
1324 PRights(te->rights, ta->dfs);
1331 printf("Access list for %s is fine.\n", ti->data);
1339 ListACLCmd(struct cmd_syndesc *as, void *arock)
1343 struct ViceIoctl blob;
1344 struct AclEntry *te;
1345 struct cmd_item *ti;
1346 int idf = getidf(as, parm_listacl_id);
1349 SetDotDefault(&as->parms[0].items);
1350 for(ti=as->parms[0].items; ti; ti=ti->next) {
1352 blob.out_size = MAXSIZE;
1354 blob.in = blob.out = space;
1355 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1357 Die(errno, ti->data);
1361 ta = ParseAcl(space);
1364 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1371 printf("Access list for %s is\n", ti->data);
1374 printf("DFS access list for %s is\n", ti->data);
1377 printf("DFS initial directory access list of %s is\n", ti->data);
1380 printf("DFS initial file access list of %s is\n", ti->data);
1384 printf(" Default cell = %s\n", ta->cell);
1386 separator = ta->dfs? DFS_SEPARATOR : ' ';
1387 if (ta->nplus > 0) {
1389 printf("Normal rights:\n");
1390 for(te = ta->pluslist;te;te=te->next) {
1391 printf(" %s%c", te->name, separator);
1392 PRights(te->rights, ta->dfs);
1396 if (ta->nminus > 0) {
1397 printf("Negative rights:\n");
1398 for(te = ta->minuslist;te;te=te->next) {
1399 printf(" %s ", te->name);
1400 PRights(te->rights, ta->dfs);
1412 FlushAllCmd(struct cmd_syndesc *as, void *arock)
1415 struct ViceIoctl blob;
1417 blob.in_size = blob.out_size = 0;
1418 code = pioctl(NULL, VIOC_FLUSHALL, &blob, 0);
1420 fprintf(stderr, "Error flushing all ");
1427 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1430 struct ViceIoctl blob;
1431 struct cmd_item *ti;
1434 SetDotDefault(&as->parms[0].items);
1435 for(ti=as->parms[0].items; ti; ti=ti->next) {
1436 blob.in_size = blob.out_size = 0;
1437 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1439 fprintf(stderr, "Error flushing volume ");
1449 FlushCmd(struct cmd_syndesc *as, void *arock)
1452 struct ViceIoctl blob;
1453 struct cmd_item *ti;
1456 cm_ioctlQueryOptions_t options;
1458 if (as->parms[1].items)
1461 for(ti=as->parms[0].items; ti; ti=ti->next) {
1463 memset(&options, 0, sizeof(options));
1464 options.size = sizeof(options);
1465 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1466 options.literal = literal;
1467 blob.in_size = options.size; /* no variable length data */
1471 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1473 if (errno == EMFILE) {
1474 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1477 fprintf(stderr, "%s: Error flushing file ", pn);
1487 /* all this command does is repackage its args and call SetVolCmd */
1489 SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
1490 struct cmd_syndesc ts;
1492 /* copy useful stuff from our command slot; we may later have to reorder */
1493 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1494 return SetVolCmd(&ts, arock);
1498 SetVolCmd(struct cmd_syndesc *as, void *arock) {
1500 struct ViceIoctl blob;
1501 struct cmd_item *ti;
1502 struct VolumeStatus *status;
1503 char *motd, *offmsg, *input;
1506 SetDotDefault(&as->parms[0].items);
1507 for(ti=as->parms[0].items; ti; ti=ti->next) {
1509 blob.out_size = MAXSIZE;
1510 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1513 status = (VolumeStatus *)space;
1514 status->MinQuota = status->MaxQuota = -1;
1515 motd = offmsg = NULL;
1516 if (as->parms[1].items) {
1517 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1519 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1524 if (as->parms[2].items)
1525 motd = as->parms[2].items->data;
1526 if (as->parms[3].items)
1527 offmsg = as->parms[3].items->data;
1528 input = (char *)status + sizeof(*status);
1529 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1531 if (strlen(offmsg) >= VMSGSIZE) {
1532 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1537 strcpy(input,offmsg);
1538 blob.in_size += (long)strlen(offmsg);
1539 input += strlen(offmsg) + 1;
1543 if (strlen(motd) >= VMSGSIZE) {
1544 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1549 blob.in_size += (long)strlen(motd);
1550 input += strlen(motd) + 1;
1553 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1555 Die(errno, ti->data);
1562 /* values match cache manager File Types */
1564 filetypestr(afs_uint32 type)
1566 char * s = "Object";
1589 ExamineCmd(struct cmd_syndesc *as, void *arock)
1592 struct ViceIoctl blob;
1593 struct cmd_item *ti;
1594 struct VolumeStatus *status;
1595 char *name, *offmsg, *motd;
1598 cm_ioctlQueryOptions_t options;
1600 if (as->parms[1].items)
1603 SetDotDefault(&as->parms[0].items);
1604 for(ti=as->parms[0].items; ti; ti=ti->next) {
1606 afs_uint32 filetype;
1607 afs_uint32 owner[2];
1608 char cell[MAXCELLCHARS];
1611 memset(&fid, 0, sizeof(fid));
1612 memset(&options, 0, sizeof(options));
1614 options.size = sizeof(options);
1615 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1616 options.literal = literal;
1617 blob.in_size = options.size; /* no variable length data */
1620 blob.out_size = sizeof(cm_fid_t);
1621 blob.out = (char *) &fid;
1622 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1623 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1626 Die(errno, ti->data);
1631 blob.out_size = sizeof(filetype);
1632 blob.out = &filetype;
1634 code = pioctl(ti->data, VIOC_GETFILETYPE, &blob, 1);
1636 blob.out_size = MAXCELLCHARS;
1639 code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1640 printf("%s %s (%u.%u.%u) contained in cell %s\n",
1641 filetypestr(filetype),
1642 ti->data, fid.volume, fid.vnode, fid.unique,
1643 code ? "unknown-cell" : cell);
1645 blob.out_size = 2 * sizeof(afs_uint32);
1646 blob.out = (char *) &owner;
1647 if (0 == pioctl(ti->data, VIOCGETOWNER, &blob, 1)) {
1648 char oname[PR_MAXNAMELEN] = "(unknown)";
1651 /* Go to the PRDB and see if this all number username is valid */
1652 cm_GetConfigDir(confDir, sizeof(confDir));
1654 pr_Initialize(1, confDir, cell);
1655 pr_SIdToName(owner[0], oname);
1656 printf("Owner %s (%u) Group %u\n", oname, owner[0], owner[1]);
1660 blob.out_size = MAXSIZE;
1661 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1663 status = (VolumeStatus *)space;
1664 name = (char *)status + sizeof(*status);
1665 offmsg = name + strlen(name) + 1;
1666 motd = offmsg + strlen(offmsg) + 1;
1668 PrintStatus(status, name, motd, offmsg);
1670 Die(errno, ti->data);
1674 code = pioctl(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
1677 printf("Volume is online\n");
1680 printf("Volume is offline\n");
1683 printf("All Volume servers are down\n");
1686 printf("All volume servers are busy\n");
1689 printf("Unknown volume state\n");
1690 Die(errno, ti->data);
1698 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1701 struct ViceIoctl blob;
1702 struct cmd_item *ti;
1703 struct VolumeStatus *status;
1708 printf("%-25s%-10s%-10s%-7s%-13s\n",
1709 "Volume Name", " Quota", " Used", " %Used", " Partition");
1710 SetDotDefault(&as->parms[0].items);
1711 for(ti=as->parms[0].items; ti; ti=ti->next) {
1713 blob.out_size = MAXSIZE;
1716 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1718 Die(errno, ti->data);
1722 status = (VolumeStatus *)space;
1723 name = (char *)status + sizeof(*status);
1724 QuickPrintStatus(status, name);
1730 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1733 struct ViceIoctl blob;
1734 struct cmd_item *ti;
1740 cm_ioctlQueryOptions_t options;
1742 if (as->parms[1].items)
1745 SetDotDefault(&as->parms[0].items);
1746 for(ti=as->parms[0].items; ti; ti=ti->next) {
1748 afs_uint32 filetype;
1751 memset(&fid, 0, sizeof(fid));
1752 memset(&options, 0, sizeof(options));
1754 options.size = sizeof(options);
1755 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1756 options.literal = literal;
1757 blob.in_size = options.size; /* no variable length data */
1760 blob.out_size = sizeof(cm_fid_t);
1761 blob.out = (char *) &fid;
1762 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
1763 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1766 Die(errno, ti->data);
1771 blob.out_size = sizeof(filetype);
1772 blob.out = &filetype;
1774 code = pioctl(ti->data, VIOC_GETFILETYPE, &blob, 1);
1776 blob.out_size = MAXSIZE;
1778 memset(space, 0, sizeof(space));
1779 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1781 Die(errno, ti->data);
1785 hosts = (afs_int32 *) space;
1786 printf("%s %s is on host%s ",
1787 filetypestr(filetype),
1789 (hosts[0] && !hosts[1]) ? "": "s");
1790 for(j=0; j<MAXHOSTS; j++) {
1793 tp = hostutil_GetNameByINet(hosts[j]);
1803 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1806 struct ViceIoctl blob;
1807 struct cmd_item *ti;
1809 struct VolumeStatus *status;
1812 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1813 " used", " avail", " %used");
1814 SetDotDefault(&as->parms[0].items);
1815 for(ti=as->parms[0].items; ti; ti=ti->next) {
1817 blob.out_size = MAXSIZE;
1820 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1822 Die(errno, ti->data);
1826 status = (VolumeStatus *)space;
1827 name = (char *)status + sizeof(*status);
1828 QuickPrintSpace(status, name);
1834 QuotaCmd(struct cmd_syndesc *as, void *arock)
1837 struct ViceIoctl blob;
1838 struct cmd_item *ti;
1840 struct VolumeStatus *status;
1843 SetDotDefault(&as->parms[0].items);
1844 for(ti=as->parms[0].items; ti; ti=ti->next) {
1846 blob.out_size = MAXSIZE;
1849 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1851 Die(errno, ti->data);
1855 status = (VolumeStatus *)space;
1856 if (status->MaxQuota)
1857 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1860 printf("%2.0f%% of quota used.\n", quotaPct);
1866 ListMountCmd(struct cmd_syndesc *as, void *arock)
1869 struct ViceIoctl blob;
1870 struct cmd_item *ti;
1871 char orig_name[1024]; /*Original name, may be modified*/
1872 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1873 char parent_dir[1024]; /*Parent directory of true name*/
1874 char *last_component; /*Last component of true name*/
1876 struct stat statbuff; /*Buffer for status info*/
1877 #endif /* not WIN32 */
1879 int link_chars_read; /*Num chars read in readlink()*/
1880 #endif /* not WIN32 */
1881 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1884 for(ti=as->parms[0].items; ti; ti=ti->next) {
1888 strcpy(orig_name, ti->data);
1889 #else /* not WIN32 */
1890 sprintf(orig_name, "%s%s",
1891 (ti->data[0] == '/') ? "" : "./",
1893 #endif /* not WIN32 */
1896 if (lstat(orig_name, &statbuff) < 0) {
1897 /* if lstat fails, we should still try the pioctl, since it
1898 * may work (for example, lstat will fail, but pioctl will
1899 * work if the volume of offline (returning ENODEV). */
1900 statbuff.st_mode = S_IFDIR; /* lie like pros */
1904 * The lstat succeeded. If the given file is a symlink, substitute
1905 * the file name with the link name.
1907 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1910 * Read name of resolved file.
1912 link_chars_read = readlink(orig_name, true_name, 1024);
1913 if (link_chars_read <= 0) {
1915 "%s: Can't read target name for '%s' symbolic link!\n",
1922 * Add a trailing null to what was read, bump the length.
1924 true_name[link_chars_read++] = 0;
1927 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1928 * have to create a full pathname using the original name and the
1929 * relative symlink name. Find the rightmost slash in the original
1930 * name (we know there is one) and splice in the symlink value.
1932 if (true_name[0] != '\\') {
1933 last_component = (char *) strrchr(orig_name, '\\');
1934 strcpy(++last_component, true_name);
1935 strcpy(true_name, orig_name);
1938 strcpy(true_name, orig_name);
1940 strcpy(true_name, orig_name);
1944 * Find rightmost slash, if any.
1947 last_component = (char *) strrchr(true_name, '\\');
1948 if (!last_component)
1950 last_component = (char *) strrchr(true_name, '/');
1951 if (last_component) {
1953 * Found it. Designate everything before it as the parent directory,
1954 * everything after it as the final component.
1956 strncpy(parent_dir, true_name, last_component - true_name + 1);
1957 parent_dir[last_component - true_name + 1] = 0;
1958 last_component++; /*Skip the slash*/
1960 if (!InAFS(parent_dir)) {
1961 const char * nbname = NetbiosName();
1962 int len = (int)strlen(nbname);
1964 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
1965 parent_dir[len+2] == '\\' &&
1966 parent_dir[len+3] == '\0' &&
1967 !strnicmp(nbname,&parent_dir[2],len))
1969 sprintf(parent_dir,"\\\\%s\\all\\", nbname);
1975 * No slash appears in the given file name. Set parent_dir to the current
1976 * directory, and the last component as the given name.
1978 fs_ExtractDriveLetter(true_name, parent_dir);
1979 strcat(parent_dir, ".");
1980 last_component = true_name;
1981 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1984 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1985 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
1986 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
1991 blob.in = last_component;
1992 blob.in_size = (long)strlen(last_component)+1;
1993 blob.out_size = MAXSIZE;
1995 memset(space, 0, MAXSIZE);
1997 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
2000 printf("'%s' is a %smount point for volume '%s'\n",
2002 (thru_symlink ? "symbolic link, leading to a " : ""),
2006 if (errno == EINVAL) {
2007 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
2009 Die(errno, (ti->data ? ti->data : parent_dir));
2018 MakeMountCmd(struct cmd_syndesc *as, void *arock)
2021 char *cellName, *volName, *tmpName;
2023 char localCellName[128];
2025 char path[1024] = "";
2026 struct afsconf_cell info;
2027 struct vldbentry vldbEntry;
2028 struct ViceIoctl blob;
2031 if (as->parms[2].items) /* cell name specified */
2032 cellName = as->parms[2].items->data;
2035 volName = as->parms[1].items->data;
2037 if (strlen(volName) >= 64) {
2038 fprintf(stderr,"%s: volume name too long (length must be < 64 characters)\n", pn);
2042 /* Check for a cellname in the volume specification, and complain
2043 * if it doesn't match what was specified with -cell */
2044 if (tmpName = strchr(volName, ':')) {
2047 if (strcasecmp(cellName,volName)) {
2048 fprintf(stderr,"fs: cellnames do not match.\n");
2053 volName = ++tmpName;
2056 parent = Parent(as->parms[0].items->data);
2057 if (!InAFS(parent)) {
2059 const char * nbname = NetbiosName();
2060 int len = (int)strlen(nbname);
2062 if (parent[0] == '\\' && parent[1] == '\\' &&
2063 parent[len+2] == '\\' &&
2064 parent[len+3] == '\0' &&
2065 !strnicmp(nbname,&parent[2],len))
2067 sprintf(path,"%sall\\%s", parent, &as->parms[0].items->data[strlen(parent)]);
2068 parent = Parent(path);
2069 if (!InAFS(parent)) {
2070 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2076 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2081 if ( strlen(path) == 0 )
2082 strcpy(path, as->parms[0].items->data);
2084 if ( IsFreelanceRoot(parent) ) {
2086 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2092 blob.out_size = sizeof(localCellName);
2093 blob.out = localCellName;
2094 code = pioctl(parent, VIOC_GET_WS_CELL, &blob, 1);
2096 cellName = localCellName;
2100 code = GetCell(parent,space);
2106 code = GetCellName(cellName?cellName:space, &info);
2110 if (!(as->parms[4].items)) {
2111 /* not fast, check which cell the mountpoint is being created in */
2113 /* not fast, check name with VLDB */
2115 code = VLDBInit(1, &info);
2117 /* make the check. Don't complain if there are problems with init */
2118 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2119 if (code == VL_NOENT) {
2120 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2121 pn, volName, cellName ? cellName : space);
2126 if (as->parms[3].items) /* if -rw specified */
2131 /* cellular mount point, prepend cell prefix */
2132 strcat(space, info.name);
2135 strcat(space, volName); /* append volume name */
2136 strcat(space, "."); /* stupid convention; these end with a period */
2138 /* create symlink with a special pioctl for Windows NT, since it doesn't
2139 * have a symlink system call.
2142 blob.in_size = 1 + (long)strlen(space);
2145 code = pioctl(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2146 #else /* not WIN32 */
2147 code = symlink(space, path);
2148 #endif /* not WIN32 */
2157 * Delete AFS mount points. Variables are used as follows:
2158 * tbuffer: Set to point to the null-terminated directory name of the mount point
2159 * (or ``.'' if none is provided)
2160 * tp: Set to point to the actual name of the mount point to nuke.
2163 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2165 struct ViceIoctl blob;
2166 struct cmd_item *ti;
2168 char lsbuffer[1024];
2172 for(ti=as->parms[0].items; ti; ti=ti->next) {
2174 tp = (char *) strrchr(ti->data, '\\');
2176 tp = (char *) strrchr(ti->data, '/');
2178 strncpy(tbuffer, ti->data, code=(afs_int32)(tp-ti->data+1)); /* the dir name */
2180 tp++; /* skip the slash */
2183 if (!InAFS(tbuffer)) {
2184 const char * nbname = NetbiosName();
2185 int len = (int)strlen(nbname);
2187 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2188 tbuffer[len+2] == '\\' &&
2189 tbuffer[len+3] == '\0' &&
2190 !strnicmp(nbname,&tbuffer[2],len))
2192 sprintf(tbuffer,"\\\\%s\\all\\", nbname);
2197 fs_ExtractDriveLetter(ti->data, tbuffer);
2198 strcat(tbuffer, ".");
2200 fs_StripDriveLetter(tp, tp, 0);
2203 blob.in_size = (long)strlen(tp)+1;
2204 blob.out = lsbuffer;
2205 blob.out_size = sizeof(lsbuffer);
2206 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2208 if (errno == EINVAL) {
2209 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2211 Die(errno, ti->data);
2214 continue; /* don't bother trying */
2217 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2218 fprintf(stderr,"%s: Only AFS Client Administrators may alter the root.afs volume\n", pn);
2220 continue; /* skip */
2225 blob.in_size = (long)strlen(tp)+1;
2226 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2228 Die(errno, ti->data);
2239 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2242 struct ViceIoctl blob;
2246 struct afsconf_cell info;
2247 struct chservinfo checkserv;
2249 memset(&checkserv, 0, sizeof(struct chservinfo));
2250 blob.in_size=sizeof(struct chservinfo);
2251 blob.in=(caddr_t)&checkserv;
2253 blob.out_size = MAXSIZE;
2255 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2257 /* prepare flags for checkservers command */
2258 temp = 2; /* default to checking local cell only */
2259 if (as->parms[2].items)
2260 temp |= 1; /* set fast flag */
2261 if (as->parms[1].items)
2262 temp &= ~2; /* turn off local cell check */
2264 checkserv.magic = 0x12345678; /* XXX */
2265 checkserv.tflags=temp;
2267 /* now copy in optional cell name, if specified */
2268 if (as->parms[0].items) {
2269 code = GetCellName(as->parms[0].items->data, &info);
2273 strcpy(checkserv.tbuffer,info.name);
2274 checkserv.tsize=(int)strlen(info.name)+1;
2276 strcpy(checkserv.tbuffer,"\0");
2280 if(as->parms[3].items) {
2281 checkserv.tinterval=atol(as->parms[3].items->data);
2284 if(checkserv.tinterval<0) {
2285 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2286 checkserv.tinterval=-1;
2287 } else if(checkserv.tinterval> 600) {
2288 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2289 checkserv.tinterval=600; /* 10 min max interval */
2292 checkserv.tinterval = -1; /* don't change current interval */
2295 if ( checkserv.tinterval >= 0 ) {
2298 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2303 fprintf (stderr,"Permission denied: requires root access.\n");
2309 code = pioctl(0, VIOCCKSERV, &blob, 1);
2311 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2312 printf("Must be root to change -interval\n");
2318 memcpy(&temp, space, sizeof(afs_int32));
2319 if (checkserv.tinterval >= 0) {
2320 if (checkserv.tinterval > 0)
2321 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2322 checkserv.tinterval, temp);
2324 printf("The current down server probe interval is %d secs\n", temp);
2328 printf("All servers are running.\n");
2330 printf("These servers unavailable due to network or server problems: ");
2331 for(j=0; j < MAXHOSTS; j++) {
2332 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2335 tp = hostutil_GetNameByINet(temp);
2345 MessagesCmd(struct cmd_syndesc *as, void *arock)
2348 struct ViceIoctl blob;
2349 struct gaginfo gagflags;
2350 struct cmd_item *show;
2352 memset(&gagflags, 0, sizeof(struct gaginfo));
2353 blob.in_size = sizeof(struct gaginfo);
2354 blob.in = (caddr_t ) &gagflags;
2355 blob.out_size = MAXSIZE;
2357 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2359 if (show = as->parms[0].items) {
2360 if (!strcasecmp (show->data, "user"))
2361 gagflags.showflags |= GAGUSER;
2362 else if (!strcasecmp (show->data, "console"))
2363 gagflags.showflags |= GAGCONSOLE;
2364 else if (!strcasecmp (show->data, "all"))
2365 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2366 else if (!strcasecmp (show->data, "none"))
2370 "unrecognized flag %s: must be in {user,console,all,none}\n",
2379 code = pioctl(0, VIOC_GAG, &blob, 1);
2388 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2391 struct ViceIoctl blob;
2395 code = pioctl(0, VIOCCKBACK, &blob, 1);
2400 printf("All volumeID/name mappings checked.\n");
2406 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2409 struct ViceIoctl blob;
2414 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2419 fprintf (stderr,"Permission denied: requires root access.\n");
2424 if (!as->parms[0].items && !as->parms[1].items) {
2425 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2428 if (as->parms[0].items) {
2429 code = util_GetInt32(as->parms[0].items->data, &temp);
2431 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2436 blob.in = (char *) &temp;
2437 blob.in_size = sizeof(afs_int32);
2439 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
2441 Die(errno, (char *) 0);
2445 printf("New cache size set.\n");
2450 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2453 struct ViceIoctl blob;
2454 cm_cacheParms_t parms;
2456 memset(&parms, 0, sizeof(parms));
2459 blob.out_size = sizeof(parms);
2460 blob.out = (char *) &parms;
2461 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
2467 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2468 parms.parms[1], parms.parms[0]);
2469 if (parms.parms[1] > parms.parms[0])
2470 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2475 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2478 afs_int32 i, j, *lp, magic, size;
2480 afs_int32 addr, maxa = OMAXHOSTS;
2481 struct ViceIoctl blob;
2484 resolve = !(as->parms[0].items); /* -numeric */
2486 for(i=0;i<1000;i++) {
2488 memcpy(tp, &i, sizeof(afs_int32));
2489 tp = (char *)(space + sizeof(afs_int32));
2490 lp = (afs_int32 *)tp;
2492 size = sizeof(afs_int32) + sizeof(afs_int32);
2493 blob.out_size = MAXSIZE;
2494 blob.in_size = sizeof(afs_int32);
2497 code = pioctl(0, VIOCGETCELL, &blob, 1);
2500 break; /* done with the list */
2505 memcpy(&magic, tp, sizeof(afs_int32));
2506 if (magic == 0x12345678) {
2508 tp += sizeof(afs_int32);
2510 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2511 for(j=0; j < maxa; j++) {
2512 char *name, tbuffer[20];
2514 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2519 name = hostutil_GetNameByINet(addr);
2522 sprintf(tbuffer, "%d.%d.%d.%d", (addr >> 24) & 0xff,
2523 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff);
2526 printf(" %s", name);
2535 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2538 char *tp, *aliasName, *realName;
2539 struct ViceIoctl blob;
2543 memcpy(tp, &i, sizeof(afs_int32));
2544 blob.out_size = MAXSIZE;
2545 blob.in_size = sizeof(afs_int32);
2548 code = pioctl(0, VIOC_GETALIAS, &blob, 1);
2551 break; /* done with the list */
2557 tp += strlen(aliasName) + 1;
2559 printf("Alias %s for cell %s\n", aliasName, realName);
2565 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2568 struct ViceIoctl blob;
2569 struct cmd_item *ti;
2571 struct hostent *thp;
2575 ti = as->parms[0].items;
2578 thp = hostutil_GetHostByName(ti->data);
2580 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2583 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2585 hostAddr = 0; /* means don't set host */
2586 setp = 0; /* aren't setting host */
2589 /* now do operation */
2590 blob.in_size = sizeof(afs_int32);
2591 blob.out_size = sizeof(afs_int32);
2592 blob.in = (char *) &hostAddr;
2593 blob.out = (char *) &hostAddr;
2595 code = pioctl(0, VIOC_CBADDR, &blob, 1);
2605 NewCellCmd(struct cmd_syndesc *as, void *arock)
2608 afs_int32 code, linkedstate=0, size=0, *lp;
2609 struct ViceIoctl blob;
2610 struct cmd_item *ti;
2611 char *tp, *cellname=0;
2612 struct hostent *thp;
2613 afs_int32 fsport = 0, vlport = 0;
2615 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
2617 lp = (afs_int32 *)tp;
2619 tp += sizeof(afs_int32);
2620 for(ti=as->parms[1].items; ti; ti=ti->next) {
2621 thp = hostutil_GetHostByName(ti->data);
2623 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
2627 memcpy(tp, thp->h_addr, sizeof(afs_int32));
2628 tp += sizeof(afs_int32);
2631 if (as->parms[2].items) {
2633 * Link the cell, for the purposes of volume location, to the specified
2636 cellname = as->parms[2].items->data;
2639 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
2640 if (as->parms[3].items) {
2641 code = util_GetInt32(as->parms[3].items->data, &vlport);
2643 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2647 if (as->parms[4].items) {
2648 code = util_GetInt32(as->parms[4].items->data, &fsport);
2650 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2655 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
2656 lp = (afs_int32 *)tp;
2660 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2661 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2662 tp = (char *)(space + size);
2664 strcpy(tp, cellname);
2665 size += strlen(cellname) + 1;
2667 blob.in_size = size;
2670 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2676 struct ViceIoctl blob;
2679 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2684 blob.in = (char *) 0;
2685 blob.out_size = MAXSIZE;
2688 code = pioctl((char *) 0, VIOCNEWCELL, &blob, 1);
2691 Die(errno, (char *) 0);
2695 printf("Cell servers information refreshed\n");
2702 NewAliasCmd(struct cmd_syndesc *as, void *arock)
2705 struct ViceIoctl blob;
2707 char *aliasName, *realName;
2709 /* Setup and do the NEWALIAS pioctl call */
2710 aliasName = as->parms[0].items->data;
2711 realName = as->parms[1].items->data;
2713 strcpy(tp, aliasName);
2714 tp += strlen(aliasName) + 1;
2715 strcpy(tp, realName);
2716 tp += strlen(realName) + 1;
2718 blob.in_size = tp - space;
2722 code = pioctl(0, VIOC_NEWALIAS, &blob, 1);
2724 if (errno == EEXIST) {
2726 "%s: cell name `%s' in use by an existing cell.\n", pn,
2738 WhichCellCmd(struct cmd_syndesc *as, void *arock)
2741 struct cmd_item *ti;
2742 struct ViceIoctl blob;
2745 cm_ioctlQueryOptions_t options;
2747 if (as->parms[1].items)
2750 SetDotDefault(&as->parms[0].items);
2751 for(ti=as->parms[0].items; ti; ti=ti->next) {
2753 afs_uint32 filetype;
2754 char cell[MAXCELLCHARS];
2757 memset(&fid, 0, sizeof(fid));
2758 memset(&options, 0, sizeof(options));
2760 options.size = sizeof(options);
2761 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
2762 options.literal = literal;
2763 blob.in_size = options.size; /* no variable length data */
2766 blob.out_size = sizeof(cm_fid_t);
2767 blob.out = (char *) &fid;
2768 if (0 == pioctl(ti->data, VIOCGETFID, &blob, 1)) {
2769 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
2772 Die(errno, ti->data);
2777 blob.out_size = sizeof(filetype);
2778 blob.out = &filetype;
2780 code = pioctl(ti->data, VIOC_GETFILETYPE, &blob, 1);
2782 blob.out_size = MAXCELLCHARS;
2785 code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
2787 if (errno == ENOENT)
2788 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2790 Die(errno, ti->data);
2794 printf("%s %s lives in cell '%s'\n",
2795 filetypestr(filetype),
2802 WSCellCmd(struct cmd_syndesc *as, void *arock)
2805 struct ViceIoctl blob;
2809 blob.out_size = MAXSIZE;
2812 code = pioctl(NULL, VIOC_GET_WS_CELL, &blob, 1);
2819 printf("This workstation belongs to cell '%s'\n", space);
2825 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
2827 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2832 #ifndef AFS_NT40_ENV
2834 MonitorCmd(struct cmd_syndesc *as, void *arock)
2837 struct ViceIoctl blob;
2838 struct cmd_item *ti;
2840 struct hostent *thp;
2844 ti = as->parms[0].items;
2848 if (!strcmp(ti->data, "off")) {
2849 hostAddr = 0xffffffff;
2851 thp = hostutil_GetHostByName(ti->data);
2853 if (!strcmp(ti->data, "localhost")) {
2854 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2855 hostAddr = htonl(0x7f000001);
2857 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2861 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2865 hostAddr = 0; /* means don't set host */
2866 setp = 0; /* aren't setting host */
2869 /* now do operation */
2870 blob.in_size = sizeof(afs_int32);
2871 blob.out_size = sizeof(afs_int32);
2872 blob.in = (char *) &hostAddr;
2873 blob.out = (char *) &hostAddr;
2874 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2880 printf("%s: new monitor host set.\n", pn);
2882 /* now decode old address */
2883 if (hostAddr == 0xffffffff) {
2884 printf("Cache monitoring is currently disabled.\n");
2886 tp = hostutil_GetNameByINet(hostAddr);
2887 printf("Using host %s for monitor services.\n", tp);
2892 #endif /* AFS_NT40_ENV */
2895 SysNameCmd(struct cmd_syndesc *as, void *arock)
2898 struct ViceIoctl blob;
2899 struct cmd_item *ti;
2900 char *input = space;
2903 ti = as->parms[0].items;
2907 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2912 fprintf (stderr,"Permission denied: requires root access.\n");
2920 blob.out_size = MAXSIZE;
2921 blob.in_size = sizeof(afs_int32);
2922 memcpy(input, &setp, sizeof(afs_int32));
2923 input += sizeof(afs_int32);
2924 for (; ti; ti = ti->next) {
2926 blob.in_size += (long)strlen(ti->data) + 1;
2927 if (blob.in_size > MAXSIZE) {
2928 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2929 setp > 1 ? "s" : "");
2932 strcpy(input, ti->data);
2933 input += strlen(ti->data);
2936 memcpy(space, &setp, sizeof(afs_int32));
2937 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2943 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
2948 memcpy(&setp, input, sizeof(afs_int32));
2949 input += sizeof(afs_int32);
2951 fprintf(stderr,"No sysname name value was found\n");
2955 printf("Current sysname%s is", setp > 1 ? " list" : "");
2956 for (; setp > 0; --setp ) {
2957 printf(" \'%s\'", input);
2958 input += strlen(input) + 1;
2964 #ifndef AFS_NT40_ENV
2965 static char *exported_types[] = {"null", "nfs", ""};
2966 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
2969 struct ViceIoctl blob;
2970 struct cmd_item *ti;
2971 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
2972 int exportcall, pwsync = 0, smounts = 0;
2976 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2981 fprintf (stderr,"Permission denied: requires root access.\n");
2986 ti = as->parms[0].items;
2987 if (strcmp(ti->data, "nfs") == 0)
2988 type = 0x71; /* NFS */
2991 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2994 ti = as->parms[1].items;
2996 if (strcmp(ti->data, "on") == 0)
2998 else if (strcmp(ti->data, "off") == 0)
3001 fprintf(stderr, "Illegal argument %s\n", ti->data);
3006 if (ti = as->parms[2].items) { /* -noconvert */
3007 if (strcmp(ti->data, "on") == 0)
3009 else if (strcmp(ti->data, "off") == 0)
3012 fprintf(stderr, "Illegal argument %s\n", ti->data);
3016 if (ti = as->parms[3].items) { /* -uidcheck */
3017 if (strcmp(ti->data, "on") == 0)
3019 else if (strcmp(ti->data, "off") == 0)
3022 fprintf(stderr, "Illegal argument %s\n", ti->data);
3026 if (ti = as->parms[4].items) { /* -submounts */
3027 if (strcmp(ti->data, "on") == 0)
3029 else if (strcmp(ti->data, "off") == 0)
3032 fprintf(stderr, "Illegal argument %s\n", ti->data);
3036 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
3039 blob.in = (char *) &exportcall;
3040 blob.in_size = sizeof(afs_int32);
3041 blob.out = (char *) &exportcall;
3042 blob.out_size = sizeof(afs_int32);
3043 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
3045 if (errno == ENODEV) {
3047 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
3054 if (exportcall & 1) {
3055 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
3056 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
3057 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
3058 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
3060 printf("'%s' translator is disabled\n", exported_types[type]);
3069 GetCellCmd(struct cmd_syndesc *as, void *arock)
3072 struct ViceIoctl blob;
3073 struct afsconf_cell info;
3074 struct cmd_item *ti;
3081 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3082 for(ti=as->parms[0].items; ti; ti=ti->next) {
3084 blob.out_size = sizeof(args);
3085 blob.out = (caddr_t) &args;
3086 code = GetCellName(ti->data, &info);
3091 blob.in_size = 1+(long)strlen(info.name);
3092 blob.in = info.name;
3093 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
3095 if (errno == ENOENT)
3096 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3098 Die(errno, info.name);
3102 printf("Cell %s status: ", info.name);
3108 printf("no setuid allowed");
3110 printf("setuid allowed");
3112 printf(", using old VLDB");
3118 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3121 struct ViceIoctl blob;
3122 struct afsconf_cell info;
3123 struct cmd_item *ti;
3131 /* Check arguments. */
3132 if (as->parms[1].items && as->parms[2].items) {
3133 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3137 /* figure stuff to set */
3143 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3148 fprintf (stderr,"Permission denied: requires root access.\n");
3153 if (! as->parms[1].items)
3154 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3156 /* set stat for all listed cells */
3157 for(ti=as->parms[0].items; ti; ti=ti->next) {
3159 code = GetCellName(ti->data, &info);
3164 strcpy(args.cname, info.name);
3165 blob.in_size = sizeof(args);
3166 blob.in = (caddr_t) &args;
3168 blob.out = (caddr_t) 0;
3169 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
3171 Die(errno, info.name); /* XXX added cell name to Die() call */
3179 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3181 strcpy(infop->name, cellNamep);
3186 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3191 cm_GetConfigDir(confDir, sizeof(confDir));
3193 code = ugen_ClientInit(noAuthFlag, confDir,
3194 info->name, 0, &uclient,
3195 NULL, pn, rxkad_clear,
3196 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3197 0, 0, USER_SERVICE_ID);
3202 static struct ViceIoctl gblob;
3203 static int debug = 0;
3205 * here follow some routines in suport of the setserverprefs and
3206 * getserverprefs commands. They are:
3207 * SetPrefCmd "top-level" routine
3208 * addServer adds a server to the list of servers to be poked into the
3209 * kernel. Will poke the list into the kernel if it threatens
3211 * pokeServers pokes the existing list of servers and ranks into the kernel
3212 * GetPrefCmd reads the Cache Manager's current list of server ranks
3221 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3223 ssp = (cm_SSetPref_t *)space;
3224 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3230 * returns -1 if error message printed,
3232 * errno value if error and no error message printed
3239 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
3240 if (code && (errno == EINVAL)) {
3241 struct setspref *ssp;
3242 ssp = (struct setspref *)gblob.in;
3243 if (!(ssp->flags & DBservers)) {
3244 gblob.in = (void *)&(ssp->servers[0]);
3245 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3246 code = pioctl(0, VIOC_SETSPREFS33, &gblob, 1);
3247 return code ? errno : 0;
3250 "This cache manager does not support VL server preferences.\n");
3254 return code ? errno : 0;
3260 addServer(char *name, unsigned short rank)
3265 struct hostent *thostent;
3269 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3271 #define MAXUSHORT ((unsigned short) ~0)
3276 thostent = hostutil_GetHostByName(name);
3278 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3282 ssp = (cm_SSetPref_t *)(gblob.in);
3284 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3285 code = pokeServers();
3286 ssp->num_servers = 0;
3289 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3290 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3291 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3292 gblob.in_size += sizeof(cm_SPref_t);
3295 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3301 * returns -1 if error message printed,
3303 * errno value if error and no error message printed
3306 addServer(char *name, afs_int32 rank)
3309 struct setspref *ssp;
3311 struct hostent *thostent;
3317 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3319 #define MAXUSHORT ((unsigned short) ~0)
3323 thostent = hostutil_GetHostByName(name);
3325 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3329 ssp = (struct setspref *)(gblob.in);
3331 for (t = 0; thostent->h_addr_list[t]; t++) {
3332 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3333 code = pokeServers();
3336 ssp->num_servers = 0;
3339 sp = (struct spref *)(gblob.in + gblob.in_size);
3340 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3341 sizeof(afs_uint32));
3342 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3343 gblob.in_size += sizeof(struct spref);
3347 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3348 name, sp->rank, sp->server.s_addr);
3356 static BOOL IsWindowsNT (void)
3358 static BOOL fChecked = FALSE;
3359 static BOOL fIsWinNT = FALSE;
3363 OSVERSIONINFO Version;
3367 memset (&Version, 0x00, sizeof(Version));
3368 Version.dwOSVersionInfoSize = sizeof(Version);
3370 if (GetVersionEx (&Version))
3372 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3382 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3386 struct cmd_item *ti;
3391 ssp = (cm_SSetPref_t *)space;
3393 ssp->num_servers = 0;
3394 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3397 gblob.out_size = MAXSIZE;
3400 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3406 ti = as->parms[2].items; /* -file */
3408 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3409 if (!(infd = fopen(ti->data,"r" ))) {
3411 Die(errno,ti->data);
3414 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3415 code = addServer (name, (unsigned short) rank);
3419 ti = as->parms[3].items; /* -stdin */
3421 while ( scanf("%79s%ld", name, &rank) != EOF) {
3422 code = addServer (name, (unsigned short) rank);
3426 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3431 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3433 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3437 code = pokeServers();
3439 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3441 ssp = (cm_SSetPref_t *)space;
3442 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3444 ssp->flags = CM_SPREF_VLONLY;
3445 ssp->num_servers = 0;
3447 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3452 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3454 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3459 if (as->parms[1].items) {
3461 printf("now poking vlservers\n");
3462 code = pokeServers();
3472 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3476 struct cmd_item *ti;
3479 struct setspref *ssp;
3480 int error = 0; /* -1 means error message printed,
3481 * >0 means errno value for unprinted message */
3483 ssp = (struct setspref *)space;
3485 ssp->num_servers = 0;
3486 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3489 gblob.out_size = MAXSIZE;
3493 fprintf(stderr, "Permission denied: requires root access.\n");
3497 ti = as->parms[2].items; /* -file */
3500 fprintf(stderr, "opening file %s\n", ti->data);
3501 if (!(infd = fopen(ti->data, "r"))) {
3505 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3506 code = addServer(name, (unsigned short)rank);
3513 ti = as->parms[3].items; /* -stdin */
3515 while (scanf("%79s%ld", name, &rank) != EOF) {
3516 code = addServer(name, (unsigned short)rank);
3522 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
3527 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3531 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3535 code = pokeServers();
3539 printf("now working on vlservers, code=%d\n", code);
3541 ssp = (struct setspref *)space;
3542 ssp->flags = DBservers;
3543 ssp->num_servers = 0;
3544 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3547 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
3552 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
3556 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3561 if (as->parms[1].items) {
3563 printf("now poking vlservers\n");
3564 code = pokeServers();
3572 return error ? 1 : 0;
3578 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3581 struct cmd_item *ti;
3582 char *name, tbuffer[20];
3587 struct ViceIoctl blob;
3588 struct cm_SPrefRequest *in;
3589 struct cm_SPrefInfo *out;
3593 ti = as->parms[0].items; /* -file */
3595 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3596 if (!(outfd = freopen(ti->data,"w",stdout))) {
3597 Die(errno,ti->data);
3602 ti = as->parms[1].items; /* -numeric */
3604 ti = as->parms[2].items; /* -vlservers */
3605 vlservers = (ti ? CM_SPREF_VLONLY : 0);
3606 /* ti = as->parms[3].items; -cell */
3608 in = (struct cm_SPrefRequest *)space;
3612 blob.in_size=sizeof(struct cm_SPrefRequest);
3613 blob.in = (char *)in;
3615 blob.out_size = MAXSIZE;
3617 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
3618 in->flags = vlservers;
3620 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3622 perror("getserverprefs pioctl");
3626 out = (struct cm_SPrefInfo *) blob.out;
3628 for (i=0;i<out->num_servers;i++) {
3630 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
3633 addr = ntohl(out->servers[i].host.s_addr);
3634 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
3635 (addr>>8) & 0xff, addr & 0xff);
3638 printf ("%-50s %5u\n",name,out->servers[i].rank);
3641 in->offset = out->next_offset;
3643 } while (!code && out->next_offset > 0);
3649 GetPrefCmd(struct cmd_syndesc *as, void *arock)
3652 struct cmd_item *ti;
3653 char *name, tbuffer[20];
3654 afs_int32 rank, addr;
3658 struct ViceIoctl blob;
3659 struct sprefrequest *in;
3660 struct sprefinfo *out;
3663 ti = as->parms[0].items; /* -file */
3666 fprintf(stderr, "opening file %s\n", ti->data);
3667 if (!(outfd = freopen(ti->data, "w", stdout))) {
3673 ti = as->parms[1].items; /* -numeric */
3675 ti = as->parms[2].items; /* -vlservers */
3676 vlservers |= (ti ? DBservers : 0);
3677 /* ti = as->parms[3].items; -cell */
3679 in = (struct sprefrequest *)space;
3683 blob.in_size = sizeof(struct sprefrequest);
3684 blob.in = (char *)in;
3686 blob.out_size = MAXSIZE;
3689 (MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
3690 in->flags = vlservers;
3692 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
3694 perror("getserverprefs pioctl");
3698 out = (struct sprefinfo *)blob.out;
3700 for (i = 0; i < out->num_servers; i++) {
3702 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);