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 <afsconfig.h>
11 #include <afs/param.h>
15 #include <afs/com_err.h>
27 #include <afs/afs_assert.h>
28 #include <rx/rx_globals.h>
32 #include <afs/afs_consts.h>
33 #include <afs/cellconfig.h>
34 #include <afs/ptserver.h>
35 #include <afs/ptuser.h>
36 #include <afs/volser.h>
37 #include <WINNT\afsreg.h>
46 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
47 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
48 #define CELL_MAXNAMELEN 256
49 #define MAXHOSTCHARS 64
51 static char space[AFS_PIOCTL_MAXSIZE];
52 static char tspace[1024];
54 static struct ubik_client *uclient;
56 static int GetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
57 static int SetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
58 static int FlushMountCmd(struct cmd_syndesc *asp, void *arock);
59 static int RxStatProcCmd(struct cmd_syndesc *asp, void *arock);
60 static int RxStatPeerCmd(struct cmd_syndesc *asp, void *arock);
62 extern struct cmd_syndesc *cmd_CreateSyntax();
64 static int MemDumpCmd(struct cmd_syndesc *asp, void *arock);
65 static int CSCPolicyCmd(struct cmd_syndesc *asp, void *arock);
66 static int MiniDumpCmd(struct cmd_syndesc *asp, void *arock);
68 static char pn[] = "fs";
69 static int rxInitDone = 0;
72 * Character to use between name and rights in printed representation for
75 #define DFS_SEPARATOR ' '
77 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
80 int dfs; /* Originally true if a dfs acl; now also the type
81 * of the acl (1, 2, or 3, corresponding to object,
82 * initial dir, or initial object). */
83 sec_rgy_name_t cell; /* DFS cell name */
86 struct AclEntry *pluslist;
87 struct AclEntry *minuslist;
91 struct AclEntry *next;
97 ZapAcl (struct Acl *acl)
102 ZapList(acl->pluslist);
103 ZapList(acl->minuslist);
108 * Mods for the AFS/DFS protocol translator.
110 * DFS rights. It's ugly to put these definitions here, but they
111 * *cannot* change, because they're part of the wire protocol.
112 * In any event, the protocol translator will guarantee these
113 * assignments for AFS cache managers.
115 #define DFS_READ 0x01
116 #define DFS_WRITE 0x02
117 #define DFS_EXECUTE 0x04
118 #define DFS_CONTROL 0x08
119 #define DFS_INSERT 0x10
120 #define DFS_DELETE 0x20
122 /* the application definable ones (backwards from AFS) */
123 #define DFS_USR0 0x80000000 /* "A" bit */
124 #define DFS_USR1 0x40000000 /* "B" bit */
125 #define DFS_USR2 0x20000000 /* "C" bit */
126 #define DFS_USR3 0x10000000 /* "D" bit */
127 #define DFS_USR4 0x08000000 /* "E" bit */
128 #define DFS_USR5 0x04000000 /* "F" bit */
129 #define DFS_USR6 0x02000000 /* "G" bit */
130 #define DFS_USR7 0x01000000 /* "H" bit */
131 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
132 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
135 * Offset of -id switch in command structure for various commands.
136 * The -if switch is the next switch always.
138 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
141 * Determine whether either the -id or -if switches are present, and
142 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
144 /* int id; Offset of -id switch; -if is next switch */
146 getidf(struct cmd_syndesc *as, int id)
150 if (as->parms[id].items) {
153 if (as->parms[id + 1].items) {
158 "%s: you may specify either -id or -if, but not both switches\n",
166 PRights(afs_int32 arights, int dfs)
169 if (arights & PRSFS_READ)
171 if (arights & PRSFS_LOOKUP)
173 if (arights & PRSFS_INSERT)
175 if (arights & PRSFS_DELETE)
177 if (arights & PRSFS_WRITE)
179 if (arights & PRSFS_LOCK)
181 if (arights & PRSFS_ADMINISTER)
183 if (arights & PRSFS_USR0)
185 if (arights & PRSFS_USR1)
187 if (arights & PRSFS_USR2)
189 if (arights & PRSFS_USR3)
191 if (arights & PRSFS_USR4)
193 if (arights & PRSFS_USR5)
195 if (arights & PRSFS_USR6)
197 if (arights & PRSFS_USR7)
200 if (arights & DFS_READ)
204 if (arights & DFS_WRITE)
208 if (arights & DFS_EXECUTE)
212 if (arights & DFS_CONTROL)
216 if (arights & DFS_INSERT)
220 if (arights & DFS_DELETE)
224 if (arights & (DFS_USRALL))
226 if (arights & DFS_USR0)
228 if (arights & DFS_USR1)
230 if (arights & DFS_USR2)
232 if (arights & DFS_USR3)
234 if (arights & DFS_USR4)
236 if (arights & DFS_USR5)
238 if (arights & DFS_USR6)
240 if (arights & DFS_USR7)
246 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
250 struct ViceIoctl blob;
251 cm_ioctlQueryOptions_t options;
255 memset(&options, 0, sizeof(options));
256 options.size = sizeof(options);
257 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
259 blob.in_size = options.size; /* no variable length data */
261 blob.out_size = sizeof(cm_fid_t);
262 blob.out = (char *) &fid;
264 code = pioctl_utf8(apath, VIOCGETFID, &blob, 1);
266 if ((errno == EINVAL) || (errno == ENOENT))
273 IsFreelanceRoot(char *apath)
275 struct ViceIoctl blob;
279 blob.out_size = AFS_PIOCTL_MAXSIZE;
282 code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
284 return !cm_strnicmp_utf8N("Freelance.Local.Root",space, blob.out_size);
286 return 1; /* assume it is because it is more restrictive that way */
289 /* return a static pointer to a buffer */
294 if( FAILED(StringCbCopy(tspace, sizeof(tspace), apath))) {
295 fprintf (stderr, "tspace - not enough space");
298 tp = strrchr(tspace, '\\');
300 if (tp - tspace > 2 &&
303 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
308 fs_ExtractDriveLetter(apath, tspace);
309 if( FAILED(StringCbCat(tspace, sizeof(tspace), "."))) {
310 fprintf (stderr, "tspace - not enough space");
317 enum rtype {add, destroy, deny};
320 Convert(char *arights, int dfs, enum rtype *rtypep)
325 *rtypep = add; /* add rights, by default */
328 if (!strcmp(arights, "null")) {
332 if (!strcmp(arights,"read"))
333 return DFS_READ | DFS_EXECUTE;
334 if (!strcmp(arights, "write"))
335 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
337 if (!strcmp(arights, "all"))
338 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
339 DFS_WRITE | DFS_CONTROL;
341 if (!strcmp(arights,"read"))
342 return PRSFS_READ | PRSFS_LOOKUP;
343 if (!strcmp(arights, "write"))
344 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
345 PRSFS_WRITE | PRSFS_LOCK;
346 if (!strcmp(arights, "mail"))
347 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
348 if (!strcmp(arights, "all"))
349 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
350 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
352 if (!strcmp(arights, "none")) {
353 *rtypep = destroy; /* Remove entire entry */
357 for(; (tc = *arights) != '\0'; arights++) {
390 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
398 mode |= PRSFS_LOOKUP;
400 mode |= PRSFS_INSERT;
402 mode |= PRSFS_DELETE;
408 mode |= PRSFS_ADMINISTER;
426 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
435 static struct AclEntry *
436 FindList (struct AclEntry *alist, char *aname)
439 if (!strcasecmp(alist->name, aname))
446 /* if no parm specified in a particular slot, set parm to be "." instead */
448 SetDotDefault(struct cmd_item **aitemp)
454 return; /* already has value */
455 /* otherwise, allocate an item representing "." */
456 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
458 ti->next = (struct cmd_item *) 0;
459 ti->data = (char *) malloc(len_data);
461 if( FAILED(StringCbCopy(ti->data, len_data, "."))) {
462 fprintf (stderr, "data - not enough space");
469 ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
471 struct AclEntry *tlist;
472 tlist = (plus ? al->pluslist : al->minuslist);
473 tlist = FindList (tlist, aname);
475 /* Found the item already in the list. */
476 tlist->rights = arights;
478 al->nplus -= PruneList(&al->pluslist, al->dfs);
480 al->nminus -= PruneList(&al->minuslist, al->dfs);
483 /* Otherwise we make a new item and plug in the new data. */
484 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
486 if( FAILED(StringCbCopy(tlist->name, sizeof(tlist->name), aname))) {
487 fprintf (stderr, "name - not enough space");
490 tlist->rights = arights;
492 tlist->next = al->pluslist;
493 al->pluslist = tlist;
495 if (arights == 0 || arights == -1)
496 al->nplus -= PruneList(&al->pluslist, al->dfs);
498 tlist->next = al->minuslist;
499 al->minuslist = tlist;
502 al->nminus -= PruneList(&al->minuslist, al->dfs);
507 ZapList (struct AclEntry *alist)
509 struct AclEntry *tp, *np;
510 for (tp = alist; tp; tp = np) {
517 PruneList (struct AclEntry **ae, int dfs)
519 struct AclEntry **lp;
520 struct AclEntry *te, *ne;
524 for(te = *ae;te;te=ne) {
525 if ((!dfs && te->rights == 0) || te->rights == -1) {
539 SkipLine (char *astr)
548 * Create an empty acl, taking into account whether the acl pointed
549 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
550 * can recover from problems caused by bogus ACL's (in that case, always
551 * assume that the acl is AFS: for DFS, the user can always resort to
552 * acl_edit, but for AFS there may be no other way out).
560 tp = (struct Acl *)malloc(sizeof (struct Acl));
562 tp->nplus = tp->nminus = 0;
563 tp->pluslist = tp->minuslist = 0;
566 if (astr == NULL || sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell) <= 0) {
571 if (astr == NULL || sscanf_s(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell, sizeof(tp->cell)) <= 0) {
580 ParseAcl (char *astr, int astr_size)
582 int nplus, nminus, i, trights, ret;
585 struct AclEntry *first, *next, *last, *tl;
589 if( FAILED(StringCbLength(astr, astr_size, &len))) {
590 fprintf (stderr, "StringCbLength failure on astr");
593 if (astr == NULL || len == 0)
597 ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
599 ret = sscanf_s(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell, sizeof(ta->cell));
605 astr = SkipLine(astr);
607 ret = sscanf(astr, "%d", &ta->nminus);
609 ret = sscanf_s(astr, "%d", &ta->nminus);
615 astr = SkipLine(astr);
622 for(i=0;i<nplus;i++) {
624 ret = sscanf(astr, "%100s %d", tname, &trights);
626 ret = sscanf_s(astr, "%100s %d", tname, sizeof(tname), &trights);
630 astr = SkipLine(astr);
631 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
636 if( FAILED(StringCbCopy(tl->name, sizeof(tl->name), tname))) {
637 fprintf (stderr, "name - not enough space");
640 tl->rights = trights;
646 ta->pluslist = first;
650 for(i=0;i<nminus;i++) {
652 ret = sscanf(astr, "%100s %d", tname, &trights);
654 ret = sscanf_s(astr, "%100s %d", tname, sizeof(tname), &trights);
658 astr = SkipLine(astr);
659 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
664 if( FAILED(StringCbCopy(tl->name, sizeof(tl->name), tname))) {
665 fprintf (stderr, "name - not enough space");
668 tl->rights = trights;
674 ta->minuslist = first;
679 for (;first; first = next) {
683 first = ta->pluslist;
686 for (;first; first = next) {
695 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
697 printf("Volume status for vid = %u named %s is\n",status->Vid, name);
699 printf("Current offline message is %s\n",offmsg);
701 printf("Current message of the day is %s\n",motd);
702 printf("Current disk quota is ");
703 if (status->MaxQuota != 0)
704 printf("%d\n", status->MaxQuota);
706 printf("unlimited\n");
707 printf("Current blocks used are %d\n",status->BlocksInUse);
708 printf("The partition has %d blocks available out of %d\n",
709 status->PartBlocksAvail, status->PartMaxBlocks);
714 QuickPrintStatus(VolumeStatus *status, char *name)
716 double QuotaUsed =0.0;
717 double PartUsed =0.0;
719 printf("%-25.25s",name);
721 if (status->MaxQuota != 0) {
722 printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
723 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
725 printf(" no limit %10d", status->BlocksInUse);
727 if (QuotaUsed > 90.0){
728 printf(" %5.0f%%<<", QuotaUsed);
731 printf(" %5.0f%% ", QuotaUsed);
732 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
733 if (PartUsed > 97.0){
734 printf(" %9.0f%%<<", PartUsed);
737 printf(" %9.0f%% ", PartUsed);
739 printf(" <<WARNING\n");
746 QuickPrintSpace(VolumeStatus *status, char *name)
748 double PartUsed =0.0;
750 printf("%-25.25s",name);
752 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
754 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
755 if (PartUsed > 90.0){
756 printf(" %4.0f%%<<", PartUsed);
759 printf(" %4.0f%% ", PartUsed);
761 printf(" <<WARNING\n");
768 AclToString(struct Acl *acl)
770 static char mydata[AFS_PIOCTL_MAXSIZE];
771 char tstring[AFS_PIOCTL_MAXSIZE];
776 if( FAILED(StringCbPrintf(dfsstring, sizeof(dfsstring), " dfs:%d %s", acl->dfs, acl->cell))) {
777 fprintf (stderr, "dfsstring - cannot be populated");
783 if( FAILED(StringCbPrintf(mydata, sizeof(mydata), "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus))) {
784 fprintf (stderr, "mydata - cannot be populated");
787 for (tp = acl->pluslist;tp;tp=tp->next) {
788 if( FAILED(StringCbPrintf(tstring, sizeof(tstring), "%s %d\n", tp->name, tp->rights))) {
789 fprintf (stderr, "tstring - cannot be populated");
792 if( FAILED(StringCbCat(mydata, sizeof(mydata), tstring))) {
793 fprintf (stderr, "mydata - not enough space");
797 for (tp = acl->minuslist;tp;tp=tp->next) {
798 if( FAILED(StringCbPrintf(tstring, sizeof(tstring), "%s %d\n", tp->name, tp->rights))) {
799 fprintf (stderr, "tstring - cannot be populated");
802 if( FAILED(StringCbCat(mydata, sizeof(mydata), tstring))) {
803 fprintf (stderr, "mydata - not enough space");
810 static DWORD IsFreelance(void)
817 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
818 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
819 if (code == ERROR_SUCCESS) {
820 dummyLen = sizeof(cm_freelanceEnabled);
821 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
822 (BYTE *) &enabled, &dummyLen);
823 RegCloseKey (parmKey);
828 #define NETBIOSNAMESZ 1024
829 static const char * NetbiosName(void)
831 static char buffer[NETBIOSNAMESZ] = "AFS";
837 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
838 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
839 if (code == ERROR_SUCCESS) {
840 dummyLen = sizeof(buffer);
841 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
843 RegCloseKey (parmKey);
845 if( FAILED(StringCbCopy(buffer, sizeof(buffer), "AFS"))) {
846 fprintf (stderr, "buffer - not enough space");
853 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
855 static BOOL IsAdmin (void)
857 static BOOL fAdmin = FALSE;
858 static BOOL fTested = FALSE;
862 /* Obtain the SID for the AFS client admin group. If the group does
863 * not exist, then assume we have AFS client admin privileges.
865 PSID psidAdmin = NULL;
866 DWORD dwSize, dwSize2;
867 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
868 char *pszRefDomain = NULL;
869 SID_NAME_USE snu = SidTypeGroup;
871 dwSize = sizeof(pszAdminGroup);
873 if (!GetComputerName(pszAdminGroup, &dwSize)) {
874 /* Can't get computer name. We return false in this case.
875 Retain fAdmin and fTested. This shouldn't happen.*/
882 if( FAILED(StringCbCat(pszAdminGroup, MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2,"\\"))) {
883 fprintf (stderr, "pszAdminGroup - not enough space");
886 if( FAILED(StringCbCat(pszAdminGroup, MAX_COMPUTERNAME_LENGTH +
887 sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2, AFSCLIENT_ADMIN_GROUPNAME))) {
888 fprintf (stderr, "pszAdminGroup - not enough space");
892 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
893 /* that should always fail. */
895 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
896 /* if we can't find the group, then we allow the operation */
901 if (dwSize == 0 || dwSize2 == 0) {
907 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
909 pszRefDomain = (char *)malloc(dwSize2);
910 assert(pszRefDomain);
912 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
913 /* We can't lookup the group now even though we looked it up earlier.
914 Could this happen? */
917 /* Then open our current ProcessToken */
920 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
923 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
924 /* We'll have to allocate a chunk of memory to store the list of
925 * groups to which this user belongs; find out how much memory
929 PTOKEN_GROUPS pGroups;
931 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
933 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
936 /* Allocate that buffer, and read in the list of groups. */
937 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
939 /* Look through the list of group SIDs and see if any of them
940 * matches the AFS Client Admin group SID.
943 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
945 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
955 /* if do not have permission because we were not explicitly listed
956 * in the Admin Client Group let's see if we are the SYSTEM account
959 PTOKEN_USER pTokenUser;
960 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
961 PSID pSidLocalSystem = 0;
964 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
966 pTokenUser = (PTOKEN_USER)malloc(dwSize);
969 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
970 gle = GetLastError();
972 if (AllocateAndInitializeSid( &SIDAuth, 1,
973 SECURITY_LOCAL_SYSTEM_RID,
977 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
981 FreeSid(pSidLocalSystem);
1000 SetACLCmd(struct cmd_syndesc *as, void *arock)
1003 struct ViceIoctl blob;
1005 struct cmd_item *ti, *ui;
1009 int idf = getidf(as, parm_setacl_id);
1013 if (as->parms[2].items)
1017 plusp = !(as->parms[3].items);
1018 for(ti=as->parms[0].items; ti;ti=ti->next) {
1019 if ( IsFreelanceRoot(ti->data) ) {
1020 fprintf(stderr,"%s: ACLs cannot be set on the Freelance root.afs volume.\n", pn);
1024 blob.out_size = AFS_PIOCTL_MAXSIZE;
1026 blob.in = blob.out = space;
1027 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1029 Die(errno, ti->data);
1035 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1038 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1043 if (!plusp && ta->dfs) {
1045 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
1047 "(you may specify \"null\" to revoke all rights, however)\n");
1054 ta = EmptyAcl(space);
1056 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1059 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1064 CleanAcl(ta, ti->data);
1065 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
1069 "%s: Missing second half of user/access pair.\n", pn);
1073 rights = Convert(ui->next->data, ta->dfs, &rtype);
1074 if (rtype == destroy && !ta->dfs) {
1075 struct AclEntry *tlist;
1077 tlist = (plusp ? ta->pluslist : ta->minuslist);
1078 if (!FindList(tlist, ui->data))
1081 if (rtype == deny && !ta->dfs)
1083 if (rtype == destroy && ta->dfs)
1085 ChangeList(ta, plusp, ui->data, rights);
1087 blob.in = AclToString(ta);
1089 if( FAILED(StringCbLength(blob.in, sizeof(space), &len))) {
1090 fprintf (stderr, "StringCbLength failure on blob.in");
1093 blob.in_size = 1+(long)len;
1094 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1096 if (errno == EINVAL) {
1098 static char *fsenv = 0;
1100 fsenv = (char *)getenv("FS_EXPERT");
1102 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
1105 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1106 "\nPossible reasons for this include:\n\n",
1107 " -You may have specified an inappropriate combination of rights.\n",
1108 " For example, some DFS-supported filesystems may not allow you to\n",
1109 " drop the \"c\" right from \"user_obj\".\n\n",
1110 " -A mask_obj may be required (it is likely required by the underlying\n",
1111 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
1112 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
1113 " does not automatically create or update the mask_obj. Try setting\n",
1114 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
1115 " users or groups. You can do this with a single command, such as\n",
1116 " \"fs sa mask_obj all user:somename read\"\n\n",
1117 " -A specified user or group may not exist.\n\n",
1118 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
1119 " This is probably not allowed by the underlying file system.\n\n",
1120 " -If you add a user or group to a DFS ACL, remember that it must be\n",
1121 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
1122 " may be local requirements on the format of the user or group name.\n",
1123 " Check with your cell administrator.\n\n",
1124 " -Or numerous other possibilities. It would be great if we could be more\n",
1125 " precise about the actual problem, but for various reasons, this is\n",
1126 " impractical via this interface. If you can't figure it out, you\n",
1127 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
1128 " whatever is provided). You may get better results. Good luck!\n\n",
1129 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
1133 "%s: Invalid argument, possible reasons include:\n",
1135 fprintf(stderr,"\t-File not in AFS\n");
1137 "\t-Too many users on access control list\n");
1139 "\t-Tried to add non-existent user to access control list\n");
1142 Die(errno, ti->data);
1153 CopyACLCmd(struct cmd_syndesc *as, void *arock)
1156 struct ViceIoctl blob;
1157 struct Acl *fa, *ta = 0;
1158 struct AclEntry *tp;
1159 struct cmd_item *ti;
1161 int idf = getidf(as, parm_copyacl_id);
1165 if (as->parms[2].items)
1169 blob.out_size = AFS_PIOCTL_MAXSIZE;
1171 blob.in = blob.out = space;
1172 code = pioctl_utf8(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1174 Die(errno, as->parms[0].items->data);
1177 fa = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1180 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1181 as->parms[0].items->data);
1184 CleanAcl(fa, as->parms[0].items->data);
1185 for (ti=as->parms[1].items; ti;ti=ti->next) {
1186 blob.out_size = AFS_PIOCTL_MAXSIZE;
1188 blob.in = blob.out = space;
1189 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1191 Die(errno, ti->data);
1198 ta = EmptyAcl(space);
1200 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1203 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1208 CleanAcl(ta, ti->data);
1209 if (ta->dfs != fa->dfs) {
1211 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1217 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1219 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1224 if( FAILED(StringCbCopy(ta->cell, sizeof(ta->cell), fa->cell))) {
1225 fprintf (stderr, "cell - not enough space");
1229 for (tp = fa->pluslist;tp;tp=tp->next)
1230 ChangeList(ta, 1, tp->name, tp->rights);
1231 for (tp = fa->minuslist;tp;tp=tp->next)
1232 ChangeList(ta, 0, tp->name, tp->rights);
1233 blob.in = AclToString(ta);
1235 if( FAILED(StringCbLength(blob.in, sizeof(space), &len))) {
1236 fprintf (stderr, "StringCbLength failure on blob.in");
1239 blob.in_size = 1+(long)len;
1240 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1242 if (errno == EINVAL) {
1244 "%s: Invalid argument, possible reasons include:\n", pn);
1245 fprintf(stderr,"\t-File not in AFS\n");
1247 Die(errno, ti->data);
1258 /* pioctl_utf8() call to get the cellname of a pathname */
1260 GetCell(char *fname, char *cellname)
1263 struct ViceIoctl blob;
1266 blob.out_size = CELL_MAXNAMELEN;
1267 blob.out = cellname;
1269 code = pioctl_utf8(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1271 cellname[blob.out_size - 1] = '\0';
1275 /* Check if a username is valid: If it contains only digits (or a
1276 * negative sign), then it might be bad. We then query the ptserver
1280 BadName(char *aname, char *fname)
1282 afs_int32 tc, code, id;
1284 char cell[CELL_MAXNAMELEN];
1287 for ( nm = aname; tc = *nm; nm++) {
1288 /* all must be '-' or digit to be bad */
1289 if (tc != '-' && (tc < '0' || tc > '9'))
1293 /* Go to the PRDB and see if this all number username is valid */
1294 code = GetCell(fname, cell);
1298 cm_GetConfigDir(confDir, sizeof(confDir));
1300 pr_Initialize(1, confDir, cell);
1301 code = pr_SNameToId(aname, &id);
1304 /* 1=>Not-valid; 0=>Valid */
1305 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1309 /* clean up an access control list of its bad entries; return 1 if we made
1310 any changes to the list, and 0 otherwise */
1312 CleanAcl(struct Acl *aa, char *fname)
1314 struct AclEntry *te, **le, *ne;
1317 /* Don't correct DFS ACL's for now */
1321 /* prune out bad entries */
1322 changes = 0; /* count deleted entries */
1324 for(te = aa->pluslist; te; te=ne) {
1326 if (BadName(te->name, fname)) {
1336 le = &aa->minuslist;
1337 for(te = aa->minuslist; te; te=ne) {
1339 if (BadName(te->name, fname)) {
1353 /* clean up an acl to not have bogus entries */
1355 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1359 struct ViceIoctl blob;
1361 struct cmd_item *ti;
1362 struct AclEntry *te;
1366 SetDotDefault(&as->parms[0].items);
1367 for(ti=as->parms[0].items; ti; ti=ti->next) {
1368 blob.out_size = AFS_PIOCTL_MAXSIZE;
1371 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1373 Die(errno, ti->data);
1379 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1382 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1389 "%s: cleanacl is not supported for DFS access lists.\n",
1395 changes = CleanAcl(ta, ti->data);
1398 /* now set the acl */
1399 blob.in=AclToString(ta);
1400 if( FAILED(StringCbLength(blob.in, sizeof(space), &len))) {
1401 fprintf (stderr, "StringCbLength failure on blob.in");
1404 blob.in_size = (long)len+1;
1406 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1408 if (errno == EINVAL) {
1410 "%s: Invalid argument, possible reasons include\n",
1412 fprintf(stderr,"%s: File not in vice or\n", pn);
1414 "%s: Too many users on access control list or\n",
1417 Die(errno, ti->data);
1423 /* now list the updated acl */
1424 printf("Access list for %s is now\n", ti->data);
1425 if (ta->nplus > 0) {
1427 printf("Normal rights:\n");
1428 for(te = ta->pluslist;te;te=te->next) {
1429 printf(" %s ", te->name);
1430 PRights(te->rights, ta->dfs);
1434 if (ta->nminus > 0) {
1435 printf("Negative rights:\n");
1436 for(te = ta->minuslist;te;te=te->next) {
1437 printf(" %s ", te->name);
1438 PRights(te->rights, ta->dfs);
1445 printf("Access list for %s is fine.\n", ti->data);
1453 ListACLCmd(struct cmd_syndesc *as, void *arock)
1457 struct ViceIoctl blob;
1458 struct AclEntry *te;
1459 struct cmd_item *ti;
1460 int idf = getidf(as, parm_listacl_id);
1463 SetDotDefault(&as->parms[0].items);
1464 for(ti=as->parms[0].items; ti; ti=ti->next) {
1467 if ( IsFreelanceRoot(ti->data) ) {
1468 fprintf(stderr,"%s: ACLs are not set on the Freelance root.afs volume.\n", pn);
1473 blob.out_size = AFS_PIOCTL_MAXSIZE;
1475 blob.in = blob.out = space;
1476 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1478 Die(errno, ti->data);
1482 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1485 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1490 if (as->parms[3].items) { /* -cmd */
1491 printf("fs setacl -dir %s -acl ", ti->data);
1492 if (ta->nplus > 0) {
1493 for (te = ta->pluslist; te; te = te->next) {
1494 printf(" %s ", te->name);
1495 PRights(te->rights, ta->dfs);
1499 if (ta->nminus > 0) {
1500 printf("fs setacl -dir %s -acl ", ti->data);
1501 for (te = ta->minuslist; te; te = te->next) {
1502 printf(" %s ", te->name);
1503 PRights(te->rights, ta->dfs);
1505 printf(" -negative\n");
1510 printf("Access list for %s is\n", ti->data);
1513 printf("DFS access list for %s is\n", ti->data);
1516 printf("DFS initial directory access list of %s is\n", ti->data);
1519 printf("DFS initial file access list of %s is\n", ti->data);
1523 printf(" Default cell = %s\n", ta->cell);
1525 separator = ta->dfs? DFS_SEPARATOR : ' ';
1526 if (ta->nplus > 0) {
1528 printf("Normal rights:\n");
1529 for(te = ta->pluslist;te;te=te->next) {
1530 printf(" %s%c", te->name, separator);
1531 PRights(te->rights, ta->dfs);
1535 if (ta->nminus > 0) {
1536 printf("Negative rights:\n");
1537 for(te = ta->minuslist;te;te=te->next) {
1538 printf(" %s ", te->name);
1539 PRights(te->rights, ta->dfs);
1552 FlushAllCmd(struct cmd_syndesc *as, void *arock)
1555 struct ViceIoctl blob;
1557 blob.in_size = blob.out_size = 0;
1558 code = pioctl_utf8(NULL, VIOC_FLUSHALL, &blob, 0);
1560 fprintf(stderr, "Error flushing all ");
1567 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1570 struct ViceIoctl blob;
1571 struct cmd_item *ti;
1574 SetDotDefault(&as->parms[0].items);
1575 for(ti=as->parms[0].items; ti; ti=ti->next) {
1576 blob.in_size = blob.out_size = 0;
1577 code = pioctl_utf8(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1579 fprintf(stderr, "Error flushing volume ");
1589 FlushCmd(struct cmd_syndesc *as, void *arock)
1592 struct ViceIoctl blob;
1593 struct cmd_item *ti;
1596 cm_ioctlQueryOptions_t options;
1598 if (as->parms[1].items)
1601 for(ti=as->parms[0].items; ti; ti=ti->next) {
1603 memset(&options, 0, sizeof(options));
1604 options.size = sizeof(options);
1605 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1606 options.literal = literal;
1607 blob.in_size = options.size; /* no variable length data */
1611 code = pioctl_utf8(ti->data, VIOCFLUSH, &blob, 0);
1613 if (errno == EMFILE) {
1614 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1617 fprintf(stderr, "%s: Error flushing file ", pn);
1627 /* all this command does is repackage its args and call SetVolCmd */
1629 SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
1630 struct cmd_syndesc ts;
1632 /* copy useful stuff from our command slot; we may later have to reorder */
1634 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1636 err = memcpy_s(&ts, sizeof(ts), as, sizeof(ts)); /* copy whole thing */
1638 fprintf (stderr, "memcpy_s failure on ts");
1642 return SetVolCmd(&ts, arock);
1646 SetVolCmd(struct cmd_syndesc *as, void *arock) {
1648 struct ViceIoctl blob;
1649 struct cmd_item *ti;
1650 struct VolumeStatus *status;
1651 char *motd, *offmsg, *input, *destEnd;
1652 size_t destRemaining;
1656 SetDotDefault(&as->parms[0].items);
1657 for(ti=as->parms[0].items; ti; ti=ti->next) {
1659 destRemaining = sizeof(space);
1660 blob.out_size = AFS_PIOCTL_MAXSIZE;
1661 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1664 status = (VolumeStatus *)space;
1665 status->MinQuota = status->MaxQuota = -1;
1666 motd = offmsg = NULL;
1667 if (as->parms[1].items) {
1668 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1670 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1675 if (as->parms[2].items)
1676 motd = as->parms[2].items->data;
1677 if (as->parms[3].items)
1678 offmsg = as->parms[3].items->data;
1679 input = (char *)status + sizeof(*status);
1680 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1681 destRemaining -= sizeof(*status) + 1;
1683 if( FAILED(StringCbLength(offmsg, VMSGSIZE, &len))) {
1684 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1689 if( FAILED(StringCbCopyEx(input, destRemaining, offmsg, &destEnd, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
1690 fprintf (stderr, "input - not enough space");
1693 blob.in_size += destEnd - input;
1694 input = destEnd + 1;
1695 destRemaining -= sizeof(char);
1698 destRemaining -= sizeof(char);
1701 if( FAILED(StringCbLength(motd, VMSGSIZE, &len))) {
1702 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1706 if( FAILED(StringCbCopyEx(input, destRemaining, motd, &destEnd, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
1707 fprintf (stderr, "input - not enough space");
1710 blob.in_size += (long)(destEnd - input);
1711 input = destEnd + 1;
1712 destRemaining -= sizeof(char);
1715 destRemaining -= sizeof(char);
1717 code = pioctl_utf8(ti->data,VIOCSETVOLSTAT, &blob, 1);
1719 Die(errno, ti->data);
1726 /* values match cache manager File Types */
1728 filetypestr(afs_uint32 type)
1730 char * s = "Object";
1753 ExamineCmd(struct cmd_syndesc *as, void *arock)
1756 struct ViceIoctl blob;
1757 struct cmd_item *ti;
1758 struct VolumeStatus *status;
1759 char *name, *offmsg, *motd;
1762 cm_ioctlQueryOptions_t options;
1765 if (as->parms[1].items)
1768 SetDotDefault(&as->parms[0].items);
1769 for(ti=as->parms[0].items; ti; ti=ti->next) {
1771 afs_uint32 filetype;
1773 afs_uint32 unixModeBits;
1774 char cell[CELL_MAXNAMELEN];
1777 memset(&fid, 0, sizeof(fid));
1778 memset(&options, 0, sizeof(options));
1780 options.size = sizeof(options);
1781 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1782 options.literal = literal;
1783 blob.in_size = options.size; /* no variable length data */
1786 blob.out_size = sizeof(cm_fid_t);
1787 blob.out = (char *) &fid;
1788 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
1789 blob.out_size == sizeof(cm_fid_t)) {
1790 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1793 Die(errno, ti->data);
1798 blob.out_size = sizeof(filetype);
1799 blob.out = &filetype;
1801 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1802 if (code || blob.out_size != sizeof(filetype)) {
1803 Die(errno, ti->data);
1808 blob.out_size = CELL_MAXNAMELEN;
1811 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1813 cell[blob.out_size-1] = '\0';
1814 printf("%s %s (%u.%u.%u) contained in cell %s\n",
1815 filetypestr(filetype),
1816 ti->data, fid.volume, fid.vnode, fid.unique,
1817 code ? "unknown-cell" : cell);
1819 blob.out_size = 2 * sizeof(afs_uint32);
1820 blob.out = (char *) &owner;
1821 if (0 == pioctl_utf8(ti->data, VIOCGETOWNER, &blob, 1) &&
1822 blob.out_size == 2 * sizeof(afs_uint32)) {
1823 char oname[PR_MAXNAMELEN] = "(unknown)";
1824 char gname[PR_MAXNAMELEN] = "(unknown)";
1827 /* Go to the PRDB and see if this all number username is valid */
1828 cm_GetConfigDir(confDir, sizeof(confDir));
1830 pr_Initialize(1, confDir, cell);
1831 pr_SIdToName(owner[0], oname);
1832 pr_SIdToName(owner[1], gname);
1833 printf("Owner %s (%d) Group %s (%d)\n", oname, owner[0], gname, owner[1]);
1836 blob.out_size = sizeof(afs_uint32);
1837 blob.out = (char *) &unixModeBits;
1838 if (0 == pioctl_utf8(ti->data, VIOC_GETUNIXMODE, &blob, 1) &&
1839 blob.out_size == sizeof(afs_uint32)) {
1840 printf("UNIX mode 0%o\n", unixModeBits);
1844 blob.out_size = AFS_PIOCTL_MAXSIZE;
1845 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1847 space[blob.out_size - 1] = '\0';
1848 status = (VolumeStatus *)space;
1849 name = (char *)status + sizeof(*status);
1850 if( FAILED(StringCbLength(name, sizeof(space) - (name - space), &len))) {
1851 fprintf (stderr, "StringCbLength failure on name");
1854 offmsg = name + len + 1;
1855 if( FAILED(StringCbLength(offmsg, sizeof(space) - (offmsg - space), &len))) {
1856 fprintf (stderr, "StringCbLength failure on offmsg");
1859 motd = offmsg + len + 1;
1860 PrintStatus(status, name, motd, offmsg);
1862 Die(errno, ti->data);
1866 code = pioctl_utf8(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
1869 printf("Volume is online\n");
1872 printf("Volume is offline\n");
1875 printf("All Volume servers are down\n");
1878 printf("All volume servers are busy\n");
1881 printf("Unknown volume state\n");
1882 Die(errno, ti->data);
1890 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1893 struct ViceIoctl blob;
1894 struct cmd_item *ti;
1895 struct VolumeStatus *status;
1900 printf("%-25s%-11s%-11s%-7s%-13s\n", "Volume Name", " Quota",
1901 " Used", " %Used", " Partition");
1902 SetDotDefault(&as->parms[0].items);
1903 for(ti=as->parms[0].items; ti; ti=ti->next) {
1905 blob.out_size = AFS_PIOCTL_MAXSIZE;
1908 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1910 Die(errno, ti->data);
1914 space[blob.out_size - 1] = '\0';
1915 status = (VolumeStatus *)space;
1916 name = (char *)status + sizeof(*status);
1917 QuickPrintStatus(status, name);
1923 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1926 struct ViceIoctl blob;
1927 struct cmd_item *ti;
1933 cm_ioctlQueryOptions_t options;
1935 if (as->parms[1].items)
1938 SetDotDefault(&as->parms[0].items);
1939 for(ti=as->parms[0].items; ti; ti=ti->next) {
1941 afs_uint32 filetype;
1944 memset(&fid, 0, sizeof(fid));
1945 memset(&options, 0, sizeof(options));
1947 options.size = sizeof(options);
1948 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1949 options.literal = literal;
1950 blob.in_size = options.size; /* no variable length data */
1953 blob.out_size = sizeof(cm_fid_t);
1954 blob.out = (char *) &fid;
1955 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
1956 blob.out_size == sizeof(cm_fid_t)) {
1957 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1960 Die(errno, ti->data);
1965 blob.out_size = sizeof(filetype);
1966 blob.out = &filetype;
1968 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1969 if (code || blob.out_size != sizeof(filetype)) {
1970 Die(errno, ti->data);
1974 blob.out_size = AFS_PIOCTL_MAXSIZE;
1976 memset(space, 0, sizeof(space));
1977 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
1979 Die(errno, ti->data);
1983 hosts = (afs_int32 *) space;
1984 printf("%s %s is on host%s ",
1985 filetypestr(filetype),
1987 (hosts[0] && !hosts[1]) ? "": "s");
1988 for(j=0; j<AFS_MAXHOSTS; j++) {
1991 tp = hostutil_GetNameByINet(hosts[j]);
2001 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
2004 struct ViceIoctl blob;
2005 struct cmd_item *ti;
2007 struct VolumeStatus *status;
2010 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
2011 " used", " avail", " %used");
2012 SetDotDefault(&as->parms[0].items);
2013 for(ti=as->parms[0].items; ti; ti=ti->next) {
2015 blob.out_size = AFS_PIOCTL_MAXSIZE;
2018 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
2020 Die(errno, ti->data);
2024 space[blob.out_size - 1] = '\0';
2025 status = (VolumeStatus *)space;
2026 name = (char *)status + sizeof(*status);
2027 QuickPrintSpace(status, name);
2033 QuotaCmd(struct cmd_syndesc *as, void *arock)
2036 struct ViceIoctl blob;
2037 struct cmd_item *ti;
2039 struct VolumeStatus *status;
2042 SetDotDefault(&as->parms[0].items);
2043 for(ti=as->parms[0].items; ti; ti=ti->next) {
2045 blob.out_size = AFS_PIOCTL_MAXSIZE;
2048 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
2050 * The response is VolumeStatus, volume name, offline message, and motd
2052 if (code || blob.out_size < sizeof(*status)) {
2053 Die(errno, ti->data);
2058 status = (VolumeStatus *)space;
2059 if (status->MaxQuota)
2060 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
2063 printf("%2.0f%% of quota used.\n", quotaPct);
2069 ListMountCmd(struct cmd_syndesc *as, void *arock)
2072 struct ViceIoctl blob;
2073 struct cmd_item *ti;
2074 char orig_name[1024]; /*Original name, may be modified*/
2075 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
2076 char parent_dir[1024]; /*Parent directory of true name*/
2077 char *last_component; /*Last component of true name*/
2081 struct stat statbuff; /*Buffer for status info*/
2082 #endif /* not WIN32 */
2084 int link_chars_read; /*Num chars read in readlink()*/
2085 #endif /* not WIN32 */
2086 int thru_symlink; /*Did we get to a mount point via a symlink?*/
2089 for(ti=as->parms[0].items; ti; ti=ti->next) {
2093 if( FAILED(StringCbCopy(orig_name, sizeof(orig_name), ti->data))) {
2094 fprintf (stderr, "orig_name - not enough space");
2097 #else /* not WIN32 */
2099 if( FAILED(StringCbPrintf(orig_name, sizeof(orig_name), "%s%s",
2100 (ti->data[0] == '/') ? "" : "./",
2102 fprintf (stderr, "orig_name - cannot be populated");
2105 #endif /* not WIN32 */
2108 if (lstat(orig_name, &statbuff) < 0) {
2109 /* if lstat fails, we should still try the pioctl, since it
2110 * may work (for example, lstat will fail, but pioctl will
2111 * work if the volume of offline (returning ENODEV). */
2112 statbuff.st_mode = S_IFDIR; /* lie like pros */
2116 * The lstat succeeded. If the given file is a symlink, substitute
2117 * the file name with the link name.
2119 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
2122 * Read name of resolved file.
2124 link_chars_read = readlink(orig_name, true_name, 1024);
2125 if (link_chars_read <= 0) {
2127 "%s: Can't read target name for '%s' symbolic link!\n",
2134 * Add a trailing null to what was read, bump the length.
2136 true_name[link_chars_read++] = 0;
2139 * If the symlink is an absolute pathname, we're fine. Otherwise, we
2140 * have to create a full pathname using the original name and the
2141 * relative symlink name. Find the rightmost slash in the original
2142 * name (we know there is one) and splice in the symlink value.
2144 if (true_name[0] != '\\') {
2145 last_component = (char *) strrchr(orig_name, '\\');
2146 if( FAILED(StringCbCopy(++last_component, sizeof(orig_name) - (last_component - orig_name) * sizeof(char), true_name))) {
2147 fprintf (stderr, "last_component - not enough space");
2150 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
2151 fprintf (stderr, "true_name - not enough space");
2156 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
2157 fprintf (stderr, "true_name - not enough space");
2162 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
2163 fprintf (stderr, "true_name - not enough space");
2169 * Find rightmost slash, if any.
2172 last_component = (char *) strrchr(true_name, '\\');
2173 if (!last_component)
2175 last_component = (char *) strrchr(true_name, '/');
2176 if (last_component) {
2178 * Found it. Designate everything before it as the parent directory,
2179 * everything after it as the final component.
2181 if( FAILED(StringCchCopyN(parent_dir, sizeof(parent_dir) / sizeof(char), true_name, last_component - true_name + 1))) {
2182 fprintf (stderr, "parent_dir - not enough space");
2185 parent_dir[last_component - true_name + 1] = 0;
2186 last_component++; /*Skip the slash*/
2188 if (!InAFS(parent_dir)) {
2189 const char * nbname = NetbiosName();
2190 if( FAILED(StringCbLength(nbname, NETBIOSNAMESZ, &len))) {
2191 fprintf (stderr, "StringCbLength failure on nbname");
2194 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
2195 parent_dir[len+2] == '\\' &&
2196 parent_dir[len+3] == '\0' &&
2197 !strnicmp(nbname,&parent_dir[2],len))
2199 if( FAILED(StringCbPrintf(parent_dir, sizeof(parent_dir),"\\\\%s\\all\\", nbname))) {
2200 fprintf (stderr, "parent_dir - cannot be populated");
2208 * No slash appears in the given file name. Set parent_dir to the current
2209 * directory, and the last component as the given name.
2211 fs_ExtractDriveLetter(true_name, parent_dir);
2212 if( FAILED(StringCbCat(parent_dir, sizeof(parent_dir), "."))) {
2213 fprintf (stderr, "parent_dir - not enough space");
2216 last_component = true_name;
2217 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
2220 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
2221 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
2222 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
2227 blob.in = last_component;
2228 if( FAILED(StringCchLength(last_component, sizeof(true_name) / sizeof(char) - (last_component - true_name), &len))) {
2229 fprintf (stderr, "StringCbLength failure on last_component");
2232 blob.in_size = (long)len+1;
2233 blob.out_size = AFS_PIOCTL_MAXSIZE;
2235 memset(space, 0, AFS_PIOCTL_MAXSIZE);
2237 code = pioctl_utf8(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
2240 printf("'%s' is a %smount point for volume '%.*s'\n",
2242 (thru_symlink ? "symbolic link, leading to a " : ""),
2247 if (errno == EINVAL) {
2248 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
2250 Die(errno, (ti->data ? ti->data : parent_dir));
2259 MakeMountCmd(struct cmd_syndesc *as, void *arock)
2262 char *cellName, *volName, *tmpName;
2264 char localCellName[128];
2266 char path[1024] = "";
2267 struct afsconf_cell info;
2268 struct vldbentry vldbEntry;
2269 struct ViceIoctl blob;
2273 memset(&info, 0, sizeof(info));
2275 if (as->parms[2].items) /* cell name specified */
2276 cellName = as->parms[2].items->data;
2279 volName = as->parms[1].items->data;
2280 if( FAILED(StringCbLength(volName, VL_MAXNAMELEN, &len))) {
2281 fprintf(stderr,"%s: volume name too long (length must be <= 64 characters)\n", pn);
2285 /* Check for a cellname in the volume specification, and complain
2286 * if it doesn't match what was specified with -cell */
2287 if (tmpName = strchr(volName, ':')) {
2290 if (strcasecmp(cellName,volName)) {
2291 fprintf(stderr,"fs: cellnames do not match.\n");
2296 volName = ++tmpName;
2299 parent = Parent(as->parms[0].items->data);
2300 if (!InAFS(parent)) {
2302 const char * nbname = NetbiosName();
2303 if ( FAILED(StringCbLength(nbname, NETBIOSNAMESZ, &len))) {
2304 fprintf (stderr, "StringCbLength failure on nbname");
2307 if (parent[0] == '\\' && parent[1] == '\\' &&
2308 parent[len+2] == '\\' &&
2309 parent[len+3] == '\0' &&
2310 !strnicmp(nbname,&parent[2],len))
2312 if( FAILED(StringCbPrintf(path, sizeof(path),"%sall\\%s", parent, &as->parms[0].items->data[len+2]))) {
2313 fprintf (stderr, "path - cannot be populated");
2316 parent = Parent(path);
2317 if (!InAFS(parent)) {
2318 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2324 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2329 if( FAILED(StringCbLength(path, sizeof(path), &len))) {
2330 fprintf (stderr, "StringCbLength failure on path");
2334 if( FAILED(StringCbCopy(path, sizeof(path), as->parms[0].items->data))) {
2335 fprintf (stderr, "path - not enough space");
2339 if ( IsFreelanceRoot(parent) ) {
2341 fprintf(stderr,"%s: Only AFS Client Administrators may alter the Freelance root.afs volume\n", pn);
2347 blob.out_size = sizeof(localCellName);
2348 blob.out = localCellName;
2349 code = pioctl_utf8(parent, VIOC_GET_WS_CELL, &blob, 1);
2351 localCellName[sizeof(localCellName) - 1] = '\0';
2352 cellName = localCellName;
2357 code = GetCell(parent,space);
2363 code = GetCellName(cellName?cellName:space, &info);
2367 if (!(as->parms[4].items)) {
2368 /* not fast, check which cell the mountpoint is being created in */
2370 /* not fast, check name with VLDB */
2372 code = VLDBInit(1, &info);
2374 /* make the check. Don't complain if there are problems with init */
2375 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2376 if (code == VL_NOENT) {
2377 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2378 pn, volName, cellName ? cellName : space);
2383 if (as->parms[3].items) { /* if -rw specified */
2384 if( FAILED(StringCbCopy(space, sizeof(space), "%"))) {
2385 fprintf (stderr, "space arr - not enough space");
2389 if( FAILED(StringCbCopy(space, sizeof(space), "#"))) {
2390 fprintf (stderr, "space arr - not enough space");
2395 /* cellular mount point, prepend cell prefix */
2396 if( FAILED(StringCbCat(space, sizeof(space), info.name))) {
2397 fprintf (stderr, "space arr - not enough space");
2400 if( FAILED(StringCbCat(space, sizeof(space), ":"))) {
2401 fprintf (stderr, "space arr - not enough space");
2405 if( FAILED(StringCbCat(space, sizeof(space), volName))) { /* append volume name */
2406 fprintf (stderr, "space arr - not enough space");
2409 if( FAILED(StringCbCat(space, sizeof(space), "."))) { /* stupid convention; these end with a period */
2410 fprintf (stderr, "space arr - not enough space");
2414 /* create symlink with a special pioctl for Windows NT, since it doesn't
2415 * have a symlink system call.
2418 if( FAILED(StringCbLength(space, sizeof(space), &len))) {
2419 fprintf (stderr, "StringCbLength failure on space");
2422 blob.in_size = 1 + (long)len;
2425 code = pioctl_utf8(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2426 #else /* not WIN32 */
2427 code = symlink(space, path);
2428 #endif /* not WIN32 */
2430 if (info.linkedCell)
2431 free(info.linkedCell);
2441 * Delete AFS mount points. Variables are used as follows:
2442 * tbuffer: Set to point to the null-terminated directory name of the mount point
2443 * (or ``.'' if none is provided)
2444 * tp: Set to point to the actual name of the mount point to nuke.
2447 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2449 struct ViceIoctl blob;
2450 struct cmd_item *ti;
2452 char lsbuffer[1024];
2457 for(ti=as->parms[0].items; ti; ti=ti->next) {
2459 tp = (char *) strrchr(ti->data, '\\');
2461 tp = (char *) strrchr(ti->data, '/');
2463 if( FAILED(StringCchCopyN(tbuffer, sizeof(tbuffer) / sizeof(char), ti->data, code=(afs_int32)(tp-ti->data+1)))) { /* the dir name */
2464 fprintf (stderr, "tbuffer - not enough space");
2467 tp++; /* skip the slash */
2470 if (!InAFS(tbuffer)) {
2471 const char * nbname = NetbiosName();
2472 if( FAILED(StringCbLength(nbname, NETBIOSNAMESZ, &len))) {
2473 fprintf (stderr, "StringCbLength failure on nbname");
2477 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2478 tbuffer[len+2] == '\\' &&
2479 tbuffer[len+3] == '\0' &&
2480 !strnicmp(nbname,&tbuffer[2],len))
2482 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer),"\\\\%s\\all\\", nbname))) {
2483 fprintf (stderr, "tbuffer - cannot be populated");
2490 fs_ExtractDriveLetter(ti->data, tbuffer);
2491 if( FAILED(StringCbCat(tbuffer, sizeof(tbuffer), "."))) {
2492 fprintf (stderr, "tbuffer - not enough space");
2496 fs_StripDriveLetter(tp, tp, 0);
2499 if( FAILED(StringCbLength(tp, AFS_PIOCTL_MAXSIZE, &len))) {
2500 fprintf (stderr, "StringCbLength failure on tp");
2503 blob.in_size = (long)len+1;
2504 blob.out = lsbuffer;
2505 blob.out_size = sizeof(lsbuffer);
2506 code = pioctl_utf8(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2508 if (errno == EINVAL) {
2509 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2511 Die(errno, ti->data);
2514 continue; /* don't bother trying */
2517 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2518 fprintf(stderr,"%s: Only AFS Client Administrators may alter the Freelance root.afs volume\n", pn);
2520 continue; /* skip */
2525 if( FAILED(StringCbLength(tp, AFS_PIOCTL_MAXSIZE, &len))) {
2526 fprintf (stderr, "StringCbLength failure on tp");
2529 blob.in_size = (long)len+1;
2530 code = pioctl_utf8(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2532 Die(errno, ti->data);
2543 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2546 struct ViceIoctl blob;
2550 struct afsconf_cell info;
2551 struct chservinfo checkserv;
2555 memset(&info, 0, sizeof(info));
2556 memset(&checkserv, 0, sizeof(struct chservinfo));
2557 blob.in_size=sizeof(struct chservinfo);
2558 blob.in=(caddr_t)&checkserv;
2560 blob.out_size = AFS_PIOCTL_MAXSIZE;
2562 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2564 /* prepare flags for checkservers command */
2565 temp = 2; /* default to checking local cell only */
2566 if (as->parms[2].items)
2567 temp |= 1; /* set fast flag */
2568 if (as->parms[1].items)
2569 temp &= ~2; /* turn off local cell check */
2571 checkserv.magic = 0x12345678; /* XXX */
2572 checkserv.tflags=temp;
2574 /* now copy in optional cell name, if specified */
2575 if (as->parms[0].items) {
2576 code = GetCellName(as->parms[0].items->data, &info);
2580 if( FAILED(StringCbCopy(checkserv.tbuffer, sizeof(checkserv.tbuffer), info.name))) {
2581 fprintf (stderr, "tbuffer - not enough space");
2584 if( FAILED(StringCbLength(info.name, sizeof(info.name), &len))) {
2585 fprintf (stderr, "StringCbLength failure on info.name");
2588 checkserv.tsize=(int)len+1;
2589 if (info.linkedCell)
2590 free(info.linkedCell);
2592 if( FAILED(StringCbCopy(checkserv.tbuffer, sizeof(checkserv.tbuffer),"\0"))) {
2593 fprintf (stderr, "tbuffer - not enough space");
2599 if(as->parms[3].items) {
2600 checkserv.tinterval=atol(as->parms[3].items->data);
2603 if(checkserv.tinterval<0) {
2604 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2605 checkserv.tinterval=-1;
2606 } else if(checkserv.tinterval> 600) {
2607 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2608 checkserv.tinterval=600; /* 10 min max interval */
2611 checkserv.tinterval = -1; /* don't change current interval */
2614 if ( checkserv.tinterval >= 0 ) {
2617 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2622 fprintf (stderr,"Permission denied: requires root access.\n");
2628 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
2630 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2631 printf("Must be root to change -interval\n");
2638 memcpy(&temp, space, sizeof(afs_int32));
2640 err = memcpy_s(&temp, sizeof(temp), space, sizeof(afs_int32));
2642 fprintf (stderr, "memcpy_s failure on temp");
2647 if (checkserv.tinterval >= 0) {
2648 if (checkserv.tinterval > 0)
2649 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2650 checkserv.tinterval, temp);
2652 printf("The current down server probe interval is %d secs\n", temp);
2656 printf("All servers are running.\n");
2658 printf("These servers unavailable due to network or server problems: ");
2659 for(j=0; j < AFS_MAXHOSTS; j++) {
2661 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2663 err = memcpy_s(&temp, sizeof(temp), space + j*sizeof(afs_int32), sizeof(afs_int32));
2665 fprintf (stderr, "memcpy_s failure on temp");
2672 tp = hostutil_GetNameByINet(temp);
2682 MessagesCmd(struct cmd_syndesc *as, void *arock)
2685 struct ViceIoctl blob;
2686 struct gaginfo gagflags;
2687 struct cmd_item *show;
2689 memset(&gagflags, 0, sizeof(struct gaginfo));
2690 blob.in_size = sizeof(struct gaginfo);
2691 blob.in = (caddr_t ) &gagflags;
2692 blob.out_size = AFS_PIOCTL_MAXSIZE;
2694 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2696 if (show = as->parms[0].items) {
2697 if (!strcasecmp (show->data, "user"))
2698 gagflags.showflags |= GAGUSER;
2699 else if (!strcasecmp (show->data, "console"))
2700 gagflags.showflags |= GAGCONSOLE;
2701 else if (!strcasecmp (show->data, "all"))
2702 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2703 else if (!strcasecmp (show->data, "none"))
2707 "unrecognized flag %s: must be in {user,console,all,none}\n",
2716 code = pioctl_utf8(0, VIOC_GAG, &blob, 1);
2725 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2728 struct ViceIoctl blob;
2732 code = pioctl_utf8(0, VIOCCKBACK, &blob, 1);
2737 printf("All volumeID/name mappings checked.\n");
2743 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2746 struct ViceIoctl blob;
2751 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2756 fprintf (stderr,"Permission denied: requires root access.\n");
2761 if (!as->parms[0].items && !as->parms[1].items) {
2762 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2765 if (as->parms[0].items) {
2766 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2768 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2773 blob.in = (char *) &temp;
2774 blob.in_size = sizeof(afs_int32);
2776 code = pioctl_utf8(0, VIOCSETCACHESIZE, &blob, 1);
2778 Die(errno, (char *) 0);
2782 printf("New cache size set.\n");
2787 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2790 struct ViceIoctl blob;
2791 cm_cacheParms_t parms;
2793 memset(&parms, 0, sizeof(parms));
2796 blob.out_size = sizeof(parms);
2797 blob.out = (char *) &parms;
2798 code = pioctl_utf8(0, VIOCGETCACHEPARMS, &blob, 1);
2799 if (code || blob.out_size != sizeof(parms)) {
2804 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2805 parms.parms[1], parms.parms[0]);
2806 if (parms.parms[1] > parms.parms[0])
2807 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2812 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2815 afs_int32 i, j, *lp, magic, size;
2817 afs_int32 addr, maxa = AFS_OMAXHOSTS;
2818 struct ViceIoctl blob;
2822 resolve = !(as->parms[0].items); /* -numeric */
2824 for(i=0;i<1000;i++) {
2827 memcpy(tp, &i, sizeof(afs_int32));
2829 err = memcpy_s(tp, sizeof(space), &i, sizeof(afs_int32));
2831 fprintf (stderr, "memcpy_s failure on tp");
2835 tp = (char *)(space + sizeof(afs_int32));
2836 lp = (afs_int32 *)tp;
2838 size = sizeof(afs_int32) + sizeof(afs_int32);
2839 blob.out_size = AFS_PIOCTL_MAXSIZE;
2840 blob.in_size = sizeof(afs_int32);
2843 code = pioctl_utf8(0, VIOCGETCELL, &blob, 1);
2846 break; /* done with the list */
2852 memcpy(&magic, tp, sizeof(afs_int32));
2854 err = memcpy_s(&magic, sizeof(magic), tp, sizeof(afs_int32));
2856 fprintf (stderr, "memcpy_s failure on magic");
2860 if (magic == 0x12345678) {
2861 maxa = AFS_MAXHOSTS;
2862 tp += sizeof(afs_int32);
2864 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2865 for(j=0; j < maxa && j*sizeof(afs_int32) < AFS_PIOCTL_MAXSIZE; j++) {
2866 char *name, tbuffer[20];
2868 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2870 err = memcpy_s(&addr, sizeof(addr), tp + j*sizeof(afs_int32), sizeof(afs_int32));
2872 fprintf (stderr, "memcpy_s failure on addr");
2880 name = hostutil_GetNameByINet(addr);
2883 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr >> 24) & 0xff,
2884 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff))) {
2885 fprintf (stderr, "tbuffer - cannot be populated");
2890 printf(" %s", name);
2899 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2902 char *tp, *aliasName, *realName;
2903 struct ViceIoctl blob;
2910 memcpy(tp, &i, sizeof(afs_int32));
2912 err = memcpy_s(tp, sizeof(space), &i, sizeof(afs_int32));
2914 fprintf (stderr, "memcpy_s failure on tp");
2918 blob.out_size = AFS_PIOCTL_MAXSIZE;
2919 blob.in_size = sizeof(afs_int32);
2922 code = pioctl_utf8(0, VIOC_GETALIAS, &blob, 1);
2925 break; /* done with the list */
2929 space[blob.out_size - 1] = '\0';
2932 if( FAILED(StringCbLength(aliasName, sizeof(space), &len))) {
2933 fprintf (stderr, "StringCbLength failure on aliasName");
2938 printf("Alias %s for cell %s\n", aliasName, realName);
2944 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2947 struct ViceIoctl blob;
2948 struct cmd_item *ti;
2950 struct hostent *thp;
2954 ti = as->parms[0].items;
2957 thp = hostutil_GetHostByName(ti->data);
2959 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2963 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2965 err = memcpy_s(&hostAddr, sizeof(hostAddr), thp->h_addr, sizeof(afs_int32));
2967 fprintf (stderr, "memcpy_s failure on hostAddr");
2972 hostAddr = 0; /* means don't set host */
2973 setp = 0; /* aren't setting host */
2976 /* now do operation */
2977 blob.in_size = sizeof(afs_int32);
2978 blob.out_size = sizeof(afs_int32);
2979 blob.in = (char *) &hostAddr;
2980 blob.out = (char *) &hostAddr;
2982 code = pioctl_utf8(0, VIOC_CBADDR, &blob, 1);
2992 NewCellCmd(struct cmd_syndesc *as, void *arock)
2994 afs_uint32 code, linkedstate=0, size=0, count=0, *lp;
2995 afs_uint32 usedns=0, useregistry=0;
2996 struct ViceIoctl blob;
2997 struct cmd_item *ti;
2998 char *tp, *cellname=0, *linked_cellname=0;
2999 afs_uint32 fsport = 0, vlport = 0;
3000 size_t destRemaining;
3003 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3007 /* if there is no cell specified, use old Windows behavior */
3008 if (as->parms[0].items == NULL) {
3010 blob.in = (char *) 0;
3011 blob.out_size = AFS_PIOCTL_MAXSIZE;
3014 code = pioctl_utf8((char *) 0, VIOCNEWCELL, &blob, 1);
3017 Die(errno, (char *) 0);
3021 printf("Cell servers information refreshed\n");
3024 cellname = as->parms[0].items->data;
3027 if (as->parms[2].items) {
3029 * Link the cell, for the purposes of volume location, to the specified
3032 linked_cellname = as->parms[2].items->data;
3036 if (as->parms[3].items) {
3037 code = util_GetInt32(as->parms[2].items->data, &vlport);
3039 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
3043 if (as->parms[4].items) {
3044 code = util_GetInt32(as->parms[3].items->data, &fsport);
3046 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
3051 if (as->parms[5].items) {
3055 if (as->parms[6].items) {
3059 /* Count the number of hostnames */
3060 for (ti=as->parms[1].items; ti && count < AFS_MAXHOSTS; ti=ti->next, count++);
3062 if (!usedns && count == 0) {
3063 fprintf( stderr, "fs: at least one vldb server must be specified.");
3067 if (count > AFS_MAXHOSTS) {
3068 fprintf( stderr, "fs: at most %u servers may be specified.", AFS_MAXHOSTS);
3073 * The pioctl data buffer consists of the following structure:
3076 * afs_uint32 alternative fs port
3077 * afs_uint32 alternative vl port
3078 * afs_uint32 count of vldb servers
3081 * n * char[] hostnames
3084 memset(space, 0, sizeof(space));
3086 lp = (afs_uint32 *)tp;
3090 *lp |= VIOC_NEWCELL2_FLAG_USEDNS;
3093 *lp |= VIOC_NEWCELL2_FLAG_USEREG;
3096 *lp |= VIOC_NEWCELL2_FLAG_LINKED;
3105 /* count of server names */
3108 /* Switch back to char pointer */
3111 /* Add nul-terminated cellname */
3112 destRemaining = sizeof(space) - (tp - space);
3113 if( FAILED(StringCbCopyEx( tp,
3115 as->parms[0].items->data,
3118 STRSAFE_FILL_ON_FAILURE))) {
3119 fprintf (stderr, " not enough space for cellname");
3122 /* Move beyond the terminating nul */
3124 destRemaining -= sizeof(char);
3126 /* Add nul-terminated linkname */
3127 if( FAILED(StringCbCopyEx( tp,
3129 linkedstate ? linked_cellname : "",
3132 STRSAFE_FILL_ON_FAILURE))) {
3133 fprintf (stderr, " not enough space for linked cellname");
3136 /* Move beyond the terminating nul */
3138 destRemaining -= sizeof(char);
3140 /* Add the servers */
3141 for (ti=as->parms[1].items; ti; ti=ti->next) {
3142 if( FAILED(StringCbCopyEx( tp,
3147 STRSAFE_FILL_ON_FAILURE))) {
3148 fprintf (stderr, " not enough space for server %s", ti->data);
3151 /* Move beyond the terminating nul */
3153 destRemaining -= sizeof(char);
3156 blob.in_size = (tp - space);
3160 code = pioctl_utf8(NULL, VIOCNEWCELL2, &blob, 1);
3163 Die(errno, as->parms[0].items->data);
3167 printf("Cell servers information for %s added or updated.\n",
3168 as->parms[0].items->data);
3174 NewAliasCmd(struct cmd_syndesc *as, void *arock)
3177 struct ViceIoctl blob;
3179 char *aliasName, *realName;
3180 size_t destRemaining = sizeof(space);
3182 /* Setup and do the NEWALIAS pioctl call */
3183 aliasName = as->parms[0].items->data;
3184 realName = as->parms[1].items->data;
3186 if( FAILED(StringCbCopyEx(tp, destRemaining, aliasName, &tp, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
3187 fprintf (stderr, "tp - not enough space");
3191 destRemaining -= sizeof(char);
3192 if( FAILED(StringCbCopyEx(tp, destRemaining, realName, &tp, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
3193 fprintf (stderr, "tp - not enough space");
3197 destRemaining -= sizeof(char);
3199 blob.in_size = tp - space;
3203 code = pioctl_utf8(0, VIOC_NEWALIAS, &blob, 1);
3205 if (errno == EEXIST) {
3207 "%s: cell name `%s' in use by an existing cell.\n", pn,
3219 WhichCellCmd(struct cmd_syndesc *as, void *arock)
3222 struct cmd_item *ti;
3223 struct ViceIoctl blob;
3226 cm_ioctlQueryOptions_t options;
3228 if (as->parms[1].items)
3231 SetDotDefault(&as->parms[0].items);
3232 for(ti=as->parms[0].items; ti; ti=ti->next) {
3234 afs_uint32 filetype;
3235 char cell[CELL_MAXNAMELEN];
3238 memset(&fid, 0, sizeof(fid));
3239 memset(&options, 0, sizeof(options));
3241 options.size = sizeof(options);
3242 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
3243 options.literal = literal;
3244 blob.in_size = options.size; /* no variable length data */
3247 blob.out_size = sizeof(cm_fid_t);
3248 blob.out = (char *) &fid;
3249 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
3250 blob.out_size == sizeof(cm_fid_t)) {
3251 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
3254 Die(errno, ti->data);
3259 blob.out_size = sizeof(filetype);
3260 blob.out = &filetype;
3262 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
3263 if (code || blob.out_size != sizeof(filetype)) {
3264 Die(errno, ti->data);
3268 blob.out_size = CELL_MAXNAMELEN;
3271 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
3273 if (errno == ENOENT)
3274 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
3276 Die(errno, ti->data);
3280 cell[CELL_MAXNAMELEN - 1] = '\0';
3281 printf("%s %s lives in cell '%s'\n",
3282 filetypestr(filetype),
3289 WSCellCmd(struct cmd_syndesc *as, void *arock)
3292 struct ViceIoctl blob;
3296 blob.out_size = AFS_PIOCTL_MAXSIZE;
3299 code = pioctl_utf8(NULL, VIOC_GET_WS_CELL, &blob, 1);
3305 space[AFS_PIOCTL_MAXSIZE - 1] = '\0';
3306 printf("This workstation belongs to cell '%s'\n", space);
3312 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
3314 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
3319 #ifndef AFS_NT40_ENV
3321 MonitorCmd(struct cmd_syndesc *as, void *arock)
3324 struct ViceIoctl blob;
3325 struct cmd_item *ti;
3327 struct hostent *thp;
3332 ti = as->parms[0].items;
3336 if (!strcmp(ti->data, "off")) {
3337 hostAddr = 0xffffffff;
3339 thp = hostutil_GetHostByName(ti->data);
3341 if (!strcmp(ti->data, "localhost")) {
3342 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
3343 hostAddr = htonl(0x7f000001);
3345 fprintf(stderr,"host %s not found in host table.\n", ti->data);
3350 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
3352 err = memcpy_s(&hostAddr, sizeof(hostAddr), thp->h_addr, sizeof(afs_int32));
3354 fprintf (stderr, "memcpy_s failure on hostAddr");
3361 hostAddr = 0; /* means don't set host */
3362 setp = 0; /* aren't setting host */
3365 /* now do operation */
3366 blob.in_size = sizeof(afs_int32);
3367 blob.out_size = sizeof(afs_int32);
3368 blob.in = (char *) &hostAddr;
3369 blob.out = (char *) &hostAddr;
3370 code = pioctl_utf8(0, VIOC_AFS_MARINER_HOST, &blob, 1);
3371 if (code || blob.out_size != sizeof(afs_int32)) {
3376 printf("%s: new monitor host set.\n", pn);
3378 /* now decode old address */
3379 if (hostAddr == 0xffffffff) {
3380 printf("Cache monitoring is currently disabled.\n");
3382 tp = hostutil_GetNameByINet(hostAddr);
3383 printf("Using host %s for monitor services.\n", tp);
3388 #endif /* AFS_NT40_ENV */
3391 SysNameCmd(struct cmd_syndesc *as, void *arock)
3394 struct ViceIoctl blob;
3395 struct cmd_item *ti;
3396 char *input = space;
3399 size_t destRemaining = sizeof(space);
3402 ti = as->parms[0].items;
3406 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3411 fprintf (stderr,"Permission denied: requires root access.\n");
3419 blob.out_size = AFS_PIOCTL_MAXSIZE;
3420 blob.in_size = sizeof(afs_int32);
3422 memcpy(input, &setp, sizeof(afs_int32));
3424 err = memcpy_s(input, destRemaining, &setp, sizeof(afs_int32));
3426 fprintf (stderr, "memcpy_s failure on input");
3430 input += sizeof(afs_int32);
3431 destRemaining -= sizeof(afs_int32);
3432 for (; ti; ti = ti->next) {
3434 if( FAILED(StringCbCopyEx(input, destRemaining, ti->data, &input, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
3435 fprintf(stderr, "%s: sysname%s too long.\n", pn,
3436 setp > 1 ? "s" : "");
3440 destRemaining -= sizeof(char);
3442 blob.in_size = (input - space) * sizeof(char);
3444 memcpy(space, &setp, sizeof(afs_int32));
3446 err = memcpy_s(space, sizeof(space), &setp, sizeof(afs_int32));
3448 fprintf (stderr, "memcpy_s failure on space");
3453 code = pioctl_utf8(0, VIOC_AFS_SYSNAME, &blob, 1);
3459 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
3465 memcpy(&setp, input, sizeof(afs_int32));
3467 err = memcpy_s(&setp, sizeof(setp), input, sizeof(afs_int32));
3469 fprintf (stderr, "memcpy_s failure on setp");
3473 input += sizeof(afs_int32);
3475 fprintf(stderr,"No sysname name value was found\n");
3478 space[blob.out_size - 1] = '\0';
3479 printf("Current sysname%s is", setp > 1 ? " list" : "");
3480 for (; setp > 0; --setp ) {
3481 printf(" \'%s\'", input);
3482 if( FAILED(StringCbLength(input, sizeof(space) - (input - space), &len))) {
3483 fprintf (stderr, "StringCbLength failure on input");
3492 #ifndef AFS_NT40_ENV
3493 static char *exported_types[] = {"null", "nfs", ""};
3494 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
3497 struct ViceIoctl blob;
3498 struct cmd_item *ti;
3499 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
3500 int exportcall, pwsync = 0, smounts = 0;
3504 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3509 fprintf (stderr,"Permission denied: requires root access.\n");
3514 ti = as->parms[0].items;
3515 if (strcmp(ti->data, "nfs") == 0)
3516 type = 0x71; /* NFS */
3519 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
3522 ti = as->parms[1].items;
3524 if (strcmp(ti->data, "on") == 0)
3526 else if (strcmp(ti->data, "off") == 0)
3529 fprintf(stderr, "Illegal argument %s\n", ti->data);
3534 if (ti = as->parms[2].items) { /* -noconvert */
3535 if (strcmp(ti->data, "on") == 0)
3537 else if (strcmp(ti->data, "off") == 0)
3540 fprintf(stderr, "Illegal argument %s\n", ti->data);
3544 if (ti = as->parms[3].items) { /* -uidcheck */
3545 if (strcmp(ti->data, "on") == 0)
3547 else if (strcmp(ti->data, "off") == 0)
3550 fprintf(stderr, "Illegal argument %s\n", ti->data);
3554 if (ti = as->parms[4].items) { /* -submounts */
3555 if (strcmp(ti->data, "on") == 0)
3557 else if (strcmp(ti->data, "off") == 0)
3560 fprintf(stderr, "Illegal argument %s\n", ti->data);
3564 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
3567 blob.in = (char *) &exportcall;
3568 blob.in_size = sizeof(afs_int32);
3569 blob.out = (char *) &exportcall;
3570 blob.out_size = sizeof(afs_int32);
3571 code = pioctl_utf8(0, VIOC_EXPORTAFS, &blob, 1);
3573 if (errno == ENODEV) {
3575 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
3582 if (exportcall & 1) {
3583 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
3584 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
3585 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
3586 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
3588 printf("'%s' translator is disabled\n", exported_types[type]);
3597 GetCellCmd(struct cmd_syndesc *as, void *arock)
3600 struct ViceIoctl blob;
3601 struct afsconf_cell info;
3602 struct cmd_item *ti;
3610 memset(&info, 0, sizeof(info));
3611 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3612 for(ti=as->parms[0].items; ti; ti=ti->next) {
3614 blob.out_size = sizeof(args);
3615 blob.out = (caddr_t) &args;
3616 code = GetCellName(ti->data, &info);
3621 if (info.linkedCell)
3622 free(info.linkedCell);
3623 if( FAILED(StringCbLength(info.name, sizeof(info.name), &len))) {
3624 fprintf (stderr, "StringCbLength failure on info.name");
3627 blob.in_size = 1+(long)len;
3628 blob.in = info.name;
3629 code = pioctl_utf8(0, VIOC_GETCELLSTATUS, &blob, 1);
3631 if (errno == ENOENT)
3632 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3634 Die(errno, info.name);
3638 printf("Cell %s status: ", info.name);
3644 printf("no setuid allowed");
3646 printf("setuid allowed");
3648 printf(", using old VLDB");
3654 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3657 struct ViceIoctl blob;
3658 struct afsconf_cell info;
3659 struct cmd_item *ti;
3667 memset(&info, 0, sizeof(info));
3669 /* Check arguments. */
3670 if (as->parms[1].items && as->parms[2].items) {
3671 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3675 /* figure stuff to set */
3681 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3686 fprintf (stderr,"Permission denied: requires root access.\n");
3691 if (! as->parms[1].items)
3692 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3694 /* set stat for all listed cells */
3695 for(ti=as->parms[0].items; ti; ti=ti->next) {
3697 code = GetCellName(ti->data, &info);
3702 if (info.linkedCell)
3703 free(info.linkedCell);
3704 if( FAILED(StringCbCopy(args.cname, sizeof(args.cname), info.name))) {
3705 fprintf (stderr, "cname - not enough space");
3708 blob.in_size = sizeof(args);
3709 blob.in = (caddr_t) &args;
3711 blob.out = (caddr_t) 0;
3712 code = pioctl_utf8(0, VIOC_SETCELLSTATUS, &blob, 1);
3714 Die(errno, info.name); /* XXX added cell name to Die() call */
3722 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3724 if( FAILED(StringCbCopy(infop->name, sizeof(infop->name), cellNamep))) {
3725 fprintf (stderr, "name - not enough space");
3732 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3737 cm_GetConfigDir(confDir, sizeof(confDir));
3739 code = ugen_ClientInit(noAuthFlag, confDir,
3740 info->name, 0, &uclient,
3741 NULL, pn, rxkad_clear,
3742 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3743 0, 0, USER_SERVICE_ID);
3748 static struct ViceIoctl gblob;
3749 static int debug = 0;
3751 * here follow some routines in suport of the setserverprefs and
3752 * getserverprefs commands. They are:
3753 * SetPrefCmd "top-level" routine
3754 * addServer adds a server to the list of servers to be poked into the
3755 * kernel. Will poke the list into the kernel if it threatens
3757 * pokeServers pokes the existing list of servers and ranks into the kernel
3758 * GetPrefCmd reads the Cache Manager's current list of server ranks
3767 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3769 ssp = (cm_SSetPref_t *)space;
3770 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3776 * returns -1 if error message printed,
3778 * errno value if error and no error message printed
3785 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3786 if (code && (errno == EINVAL)) {
3787 struct setspref *ssp;
3788 ssp = (struct setspref *)gblob.in;
3789 if (!(ssp->flags & DBservers)) {
3790 gblob.in = (void *)&(ssp->servers[0]);
3791 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3792 code = pioctl_utf8(0, VIOC_SETSPREFS33, &gblob, 1);
3793 return code ? errno : 0;
3796 "This cache manager does not support VL server preferences.\n");
3800 return code ? errno : 0;
3806 addServer(char *name, unsigned short rank)
3811 struct hostent *thostent;
3816 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3818 #define MAXUSHORT ((unsigned short) ~0)
3823 thostent = hostutil_GetHostByName(name);
3825 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3829 ssp = (cm_SSetPref_t *)(gblob.in);
3831 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3832 code = pokeServers();
3833 ssp->num_servers = 0;
3836 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3838 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3840 err = memcpy_s (&(sp->host.s_addr), sizeof(afs_uint32), thostent->h_addr, sizeof(afs_uint32));
3842 fprintf (stderr, "memcpy_s failure on sp->host.s_addr");
3847 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3848 gblob.in_size += sizeof(cm_SPref_t);
3851 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3857 * returns -1 if error message printed,
3859 * errno value if error and no error message printed
3862 addServer(char *name, afs_int32 rank)
3865 struct setspref *ssp;
3867 struct hostent *thostent;
3874 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3876 #define MAXUSHORT ((unsigned short) ~0)
3880 thostent = hostutil_GetHostByName(name);
3882 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3886 ssp = (struct setspref *)(gblob.in);
3888 for (t = 0; thostent->h_addr_list[t]; t++) {
3889 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3890 code = pokeServers();
3893 ssp->num_servers = 0;
3896 sp = (struct spref *)(gblob.in + gblob.in_size);
3898 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3899 sizeof(afs_uint32));
3901 err = memcpy_s(&(sp->server.s_addr), sizeof(afs_uint32), thostent->h_addr_list[t],
3902 sizeof(afs_uint32));
3904 fprintf (stderr, "memcpy_s failure on sp->server.s_addr");
3909 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3910 gblob.in_size += sizeof(struct spref);
3914 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3915 name, sp->rank, sp->server.s_addr);
3923 static BOOL IsWindowsNT (void)
3925 static BOOL fChecked = FALSE;
3926 static BOOL fIsWinNT = FALSE;
3930 OSVERSIONINFO Version;
3934 memset (&Version, 0x00, sizeof(Version));
3935 Version.dwOSVersionInfoSize = sizeof(Version);
3937 if (GetVersionEx (&Version))
3939 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3949 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3953 struct cmd_item *ti;
3958 ssp = (cm_SSetPref_t *)space;
3960 ssp->num_servers = 0;
3961 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3964 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3967 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3973 ti = as->parms[2].items; /* -file */
3975 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3976 if (!(infd = fopen(ti->data,"r" ))) {
3978 Die(errno,ti->data);
3981 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3982 code = addServer (name, (unsigned short) rank);
3985 while ( fscanf_s(infd, "%79s%ld", name, sizeof(name), &rank) != EOF) {
3986 code = addServer (name, (unsigned short) rank);
3993 ti = as->parms[3].items; /* -stdin */
3996 while ( scanf("%79s%ld", name, &rank) != EOF) {
3997 code = addServer (name, (unsigned short) rank);
4000 while ( scanf_s("%79s%ld", name, sizeof(name), &rank) != EOF) {
4001 code = addServer (name, (unsigned short) rank);
4006 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
4011 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
4013 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
4017 code = pokeServers();
4019 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
4021 ssp = (cm_SSetPref_t *)space;
4022 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
4024 ssp->flags = CM_SPREF_VLONLY;
4025 ssp->num_servers = 0;
4027 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
4032 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
4034 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
4039 if (as->parms[1].items) {
4041 printf("now poking vlservers\n");
4042 code = pokeServers();
4052 SetPrefCmd(struct cmd_syndesc *as, void *arock)
4056 struct cmd_item *ti;
4059 struct setspref *ssp;
4060 int error = 0; /* -1 means error message printed,
4061 * >0 means errno value for unprinted message */
4063 ssp = (struct setspref *)space;
4065 ssp->num_servers = 0;
4066 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
4069 gblob.out_size = AFS_PIOCTL_MAXSIZE;
4073 fprintf(stderr, "Permission denied: requires root access.\n");
4077 ti = as->parms[2].items; /* -file */
4080 fprintf(stderr, "opening file %s\n", ti->data);
4081 if (!(infd = fopen(ti->data, "r"))) {
4086 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
4087 code = addServer(name, (unsigned short)rank);
4092 while (fscanf_s(infd, "%79s%ld", name, sizeof(name), &rank) != EOF) {
4093 code = addServer(name, (unsigned short)rank);
4102 ti = as->parms[3].items; /* -stdin */
4105 while (scanf("%79s%ld", name, &rank) != EOF) {
4106 code = addServer(name, (unsigned short)rank);
4111 while (scanf_s("%79s%ld", name, sizeof(name), &rank) != EOF) {
4112 code = addServer(name, (unsigned short)rank);
4119 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
4124 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
4128 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
4132 code = pokeServers();
4136 printf("now working on vlservers, code=%d\n", code);
4138 ssp = (struct setspref *)space;
4139 ssp->flags = DBservers;
4140 ssp->num_servers = 0;
4141 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
4144 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
4149 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
4153 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
4158 if (as->parms[1].items) {
4160 printf("now poking vlservers\n");
4161 code = pokeServers();
4169 return error ? 1 : 0;
4175 GetPrefCmd(struct cmd_syndesc *as, void *arock)
4178 struct cmd_item *ti;
4179 char *name, tbuffer[20];
4184 struct ViceIoctl blob;
4185 struct cm_SPrefRequest *in;
4186 struct cm_SPrefInfo *out;
4190 ti = as->parms[0].items; /* -file */
4192 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
4193 if (!(outfd = freopen(ti->data,"w",stdout))) {
4194 Die(errno,ti->data);
4199 ti = as->parms[1].items; /* -numeric */
4201 ti = as->parms[2].items; /* -vlservers */
4202 vlservers = (ti ? CM_SPREF_VLONLY : 0);
4203 /* ti = as->parms[3].items; -cell */
4205 in = (struct cm_SPrefRequest *)space;
4209 blob.in_size=sizeof(struct cm_SPrefRequest);
4210 blob.in = (char *)in;
4212 blob.out_size = AFS_PIOCTL_MAXSIZE;
4214 in->num_servers = (AFS_PIOCTL_MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
4215 in->flags = vlservers;
4217 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
4219 perror("getserverprefs pioctl");
4223 out = (struct cm_SPrefInfo *) blob.out;
4225 for (i=0;i<out->num_servers;i++) {
4227 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
4230 addr = ntohl(out->servers[i].host.s_addr);
4231 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
4232 (addr>>8) & 0xff, addr & 0xff))) {
4233 fprintf (stderr, "tbuffer - cannot be populated");
4238 printf ("%-50s %5u\n",name,out->servers[i].rank);
4241 in->offset = out->next_offset;
4243 } while (!code && out->next_offset > 0);
4249 GetPrefCmd(struct cmd_syndesc *as, void *arock)
4252 struct cmd_item *ti;
4253 char *name, tbuffer[20];
4254 afs_int32 rank, addr;
4258 struct ViceIoctl blob;
4259 struct sprefrequest *in;
4260 struct sprefinfo *out;
4263 ti = as->parms[0].items; /* -file */
4266 fprintf(stderr, "opening file %s\n", ti->data);
4267 if (!(outfd = freopen(ti->data, "w", stdout))) {
4273 ti = as->parms[1].items; /* -numeric */
4275 ti = as->parms[2].items; /* -vlservers */
4276 vlservers |= (ti ? DBservers : 0);
4277 /* ti = as->parms[3].items; -cell */
4279 in = (struct sprefrequest *)space;
4283 blob.in_size = sizeof(struct sprefrequest);
4284 blob.in = (char *)in;
4286 blob.out_size = AFS_PIOCTL_MAXSIZE;
4289 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4290 in->flags = vlservers;
4292 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
4294 perror("getserverprefs pioctl");
4298 out = (struct sprefinfo *)blob.out;
4300 for (i = 0; i < out->num_servers; i++) {
4302 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
4304 addr = ntohl(out->servers[i].server.s_addr);
4305 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr >> 24) & 0xff,
4306 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff))) {
4307 fprintf (stderr, "tbuffer - cannot be populated");
4312 printf("%-50s %5u\n", name, out->servers[i].rank);
4315 in->offset = out->next_offset;
4316 } while (out->next_offset > 0);
4323 SmbUnicodeCmd(struct cmd_syndesc * asp, void * arock)
4329 struct ViceIoctl blob;
4331 if (asp->parms[0].items) {
4335 } else if (asp->parms[1].items) {
4341 if (inValue != 0 && !IsAdmin()) {
4342 fprintf (stderr, "Permission denied: Requires AFS Client Administrator access.\n");
4346 blob.in_size = sizeof(inValue);
4347 blob.in = (char *) &inValue;
4348 blob.out_size = sizeof(outValue);
4349 blob.out = (char *) &outValue;
4351 code = pioctl_utf8(NULL, VIOC_UNICODECTL, &blob, 1);
4357 if (outValue != 2) {
4358 printf("Unicode support is %s%s.\n",
4359 ((outValue != 0)? "enabled":"disabled"),
4360 ((inValue != 0)? " for new SMB connections":""));
4362 printf("Unicode support is absent in this installation of OpenAFS.\n");
4369 GetFidCmd(struct cmd_syndesc *as, void *arock)
4372 struct ViceIoctl blob;
4373 struct cmd_item *ti;
4376 cm_ioctlQueryOptions_t options;
4378 if (as->parms[1].items)
4381 SetDotDefault(&as->parms[0].items);
4382 for(ti=as->parms[0].items; ti; ti=ti->next) {
4384 afs_uint32 filetype;
4385 char cell[CELL_MAXNAMELEN];
4388 memset(&fid, 0, sizeof(fid));
4389 memset(&options, 0, sizeof(options));
4391 options.size = sizeof(options);
4392 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
4393 options.literal = literal;
4394 blob.in_size = options.size; /* no variable length data */
4397 blob.out_size = sizeof(cm_fid_t);
4398 blob.out = (char *) &fid;
4399 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
4400 blob.out_size == sizeof(cm_fid_t)) {
4401 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
4404 Die(errno, ti->data);
4409 blob.out_size = sizeof(filetype);
4410 blob.out = &filetype;
4412 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
4413 if (code || blob.out_size != sizeof(filetype)) {
4414 Die(errno, ti->data);
4418 blob.out_size = CELL_MAXNAMELEN;
4421 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
4423 cell[CELL_MAXNAMELEN - 1] = '\0';
4424 printf("%s %s (%u.%u.%u) contained in cell %s\n",
4425 filetypestr(filetype),
4426 ti->data, fid.volume, fid.vnode, fid.unique,
4427 code ? "unknown-cell" : cell);
4433 UuidCmd(struct cmd_syndesc *asp, void *arock)
4438 struct ViceIoctl blob;
4439 char * uuidstring = NULL;
4441 if (asp->parms[0].items) {
4444 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4449 fprintf (stderr, "Permission denied: requires root access.\n");
4453 inValue = 1; /* generate new UUID */
4455 inValue = 0; /* just show the current UUID */
4458 blob.in_size = sizeof(inValue);
4459 blob.in = (char *) &inValue;
4460 blob.out_size = sizeof(outValue);
4461 blob.out = (char *) &outValue;
4463 code = pioctl_utf8(NULL, VIOC_UUIDCTL, &blob, 1);
4464 if (code || blob.out_size != sizeof(outValue)) {
4469 UuidToString((UUID *) &outValue, &uuidstring);
4471 printf("%sUUID: %s",
4472 ((inValue == 1)?"New ":""),
4476 RpcStringFree(&uuidstring);
4482 TraceCmd(struct cmd_syndesc *asp, void *arock)
4485 struct ViceIoctl blob;
4491 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4496 fprintf (stderr,"Permission denied: requires root access.\n");
4501 if ((asp->parms[0].items && asp->parms[1].items)) {
4502 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
4506 /* determine if we're turning this tracing on or off */
4508 if (asp->parms[0].items)
4509 inValue = 3; /* enable */
4510 else if (asp->parms[1].items)
4511 inValue = 2; /* disable */
4512 if (asp->parms[2].items)
4513 inValue |= 4; /* do reset */
4514 if (asp->parms[3].items)
4515 inValue |= 8; /* dump */
4517 blob.in_size = sizeof(long);
4518 blob.in = (char *) &inValue;
4519 blob.out_size = sizeof(long);
4520 blob.out = (char *) &outValue;
4522 code = pioctl_utf8(NULL, VIOC_TRACECTL, &blob, 1);
4523 if (code || blob.out_size != sizeof(long)) {
4529 printf("AFS tracing enabled.\n");
4531 printf("AFS tracing disabled.\n");
4536 static void sbusage(void)
4538 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
4539 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
4542 /* fs sb -kbytes 9999 -files *.o -default 64 */
4544 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
4547 struct ViceIoctl blob;
4548 struct cmd_item *ti;
4549 struct sbstruct tsb, tsb2;
4557 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4562 tsb.sb_thisfile = -1;
4563 ti = as->parms[0].items; /* -kbytes */
4565 if (!as->parms[1].items) {
4566 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
4570 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
4571 if (errno == ERANGE) {
4572 fprintf(stderr, "%s: ti->data must within long int range", pn);
4575 if ((tsb.sb_thisfile < 0) || (*t != '\0')) {
4576 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
4582 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
4583 ti = as->parms[2].items; /* -allfiles */
4585 allfiles = strtol(ti->data, &t, 10) * 1024;
4586 if (errno == ERANGE) {
4587 fprintf(stderr, "%s: ti->data must within long int range", pn);
4590 if ((allfiles < 0) || (*t != '\0')) {
4591 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
4597 /* -verbose or -file only or no options */
4598 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
4599 || (!as->parms[0].items && !as->parms[1].items
4600 && !as->parms[2].items))
4603 blob.in = (char *)&tsb;
4604 blob.out = (char *)&tsb2;
4605 blob.in_size = blob.out_size = sizeof(struct sbstruct);
4606 memset(&tsb2, 0, sizeof(tsb2));
4608 /* once per -file */
4609 for (ti = as->parms[1].items; ti; ti = ti->next) {
4610 /* Do this solely to see if the file is there */
4611 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
4613 Die(errno, ti->data);
4618 code = pioctl_utf8(ti->data, VIOC_STOREBEHIND, &blob, 1);
4620 Die(errno, ti->data);
4625 if (verbose && (blob.out_size == sizeof(tsb2))) {
4626 if (tsb2.sb_thisfile == -1) {
4627 fprintf(stdout, "Will store %s according to default.\n",
4631 "Will store up to %d kbytes of %s asynchronously.\n",
4632 (tsb2.sb_thisfile / 1024), ti->data);
4637 /* If no files - make at least one pioctl call, or
4638 * set the allfiles default if we need to.
4640 if (!as->parms[1].items || (allfiles != -1)) {
4641 tsb.sb_default = allfiles;
4642 code = pioctl_utf8(0, VIOC_STOREBEHIND, &blob, 1);
4644 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
4649 /* Having no arguments also reports the default store asynchrony */
4650 if (verbose && (blob.out_size == sizeof(tsb2))) {
4651 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
4652 (tsb2.sb_default / 1024));
4659 SetCryptCmd(struct cmd_syndesc *as, void *arock)
4661 afs_int32 code = 0, flag;
4662 struct ViceIoctl blob;
4667 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4672 tp = as->parms[0].items->data;
4673 if (strcmp(tp, "on") == 0)
4675 else if (strcmp(tp, "off") == 0)
4677 else if (strcmp(tp, "auth") == 0)
4680 fprintf (stderr, "%s: %s must be \"on\", \"auth\", or \"off\".\n", pn, tp);
4684 blob.in = (char *) &flag;
4685 blob.in_size = sizeof(flag);
4687 code = pioctl_utf8(0, VIOC_SETRXKCRYPT, &blob, 1);
4694 GetCryptCmd(struct cmd_syndesc *as, void *arock)
4696 afs_int32 code = 0, flag;
4697 struct ViceIoctl blob;
4703 blob.out_size = sizeof(flag);
4706 code = pioctl_utf8(0, VIOC_GETRXKCRYPT, &blob, 1);
4708 if (code || blob.out_size != sizeof(flag))
4713 memcpy(&flag, tp, sizeof(afs_int32));
4715 err = memcpy_s(&flag, sizeof(flag), tp, sizeof(afs_int32));
4717 fprintf (stderr, "memcpy_s failure on flag");
4722 printf("Security level is currently ");
4724 printf("auth (data integrity).\n");
4726 printf("crypt (data security).\n");
4734 MemDumpCmd(struct cmd_syndesc *asp, void *arock)
4737 struct ViceIoctl blob;
4742 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4746 if ((asp->parms[0].items && asp->parms[1].items)) {
4747 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
4751 /* determine if we're turning this tracing on or off */
4752 if (asp->parms[0].items)
4753 inValue = 1; /* begin */
4754 else if (asp->parms[1].items)
4755 inValue = 0; /* end */
4758 blob.in_size = sizeof(long);
4759 blob.in = (char *) &inValue;
4760 blob.out_size = sizeof(long);
4761 blob.out = (char *) &outValue;
4763 code = pioctl_utf8(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
4764 if (code || blob.out_size != sizeof(long)) {
4770 printf("AFS memdump created.\n");
4773 printf("AFS memdump failed.\n");
4779 MiniDumpCmd(struct cmd_syndesc *asp, void *arock)
4782 SERVICE_STATUS status;
4783 SC_HANDLE hManager = NULL;
4784 SC_HANDLE hService = NULL;
4787 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4791 hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
4795 hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
4799 success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
4802 CloseServiceHandle(hService);
4803 CloseServiceHandle(hManager);
4805 printf("AFS minidump generated.\n");
4811 CloseServiceHandle(hService);
4813 CloseServiceHandle(hManager);
4815 printf("AFS minidump failed.\n");
4820 CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
4822 struct cmd_item *ti;
4828 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4832 for(ti=asp->parms[0].items; ti;ti=ti->next) {
4844 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4845 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4848 REG_OPTION_NON_VOLATILE,
4849 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
4854 if ( hkCSCPolicy == NULL ) {
4855 fprintf (stderr,"Permission denied: requires Administrator access.\n");
4860 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4861 RegCloseKey(hkCSCPolicy);
4868 if (asp->parms[1].items) {
4872 if (asp->parms[2].items) {
4873 policy = "programs";
4876 if (asp->parms[3].items) {
4877 policy = "documents";
4880 if (asp->parms[4].items) {
4884 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, (DWORD)len+1);
4886 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
4887 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
4891 DWORD dwIndex, dwPolicies;
4892 char policyName[256];
4893 DWORD policyNameLen;
4898 /* list current csc policies */
4900 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4901 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4904 REG_OPTION_NON_VOLATILE,
4905 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_QUERY_VALUE,
4910 RegQueryInfoKey( hkCSCPolicy,
4912 NULL, /* lpcClass */
4913 NULL, /* lpReserved */
4914 NULL, /* lpcSubKeys */
4915 NULL, /* lpcMaxSubKeyLen */
4916 NULL, /* lpcMaxClassLen */
4917 &dwPolicies, /* lpcValues */
4918 NULL, /* lpcMaxValueNameLen */
4919 NULL, /* lpcMaxValueLen */
4920 NULL, /* lpcbSecurityDescriptor */
4921 NULL /* lpftLastWriteTime */
4924 printf("Current CSC policies:\n");
4925 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
4927 policyNameLen = sizeof(policyName);
4928 policyLen = sizeof(policy);
4929 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
4930 &dwType, policy, &policyLen);
4932 printf(" %s = %s\n", policyName, policy);
4936 RegCloseKey(hkCSCPolicy);
4941 /* get clients interface addresses */
4943 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4946 struct cmd_item *ti;
4948 struct ViceIoctl blob;
4949 struct sprefrequest *in;
4950 struct sprefinfo *out;
4952 in = (struct sprefrequest *)space;
4956 blob.in_size = sizeof(struct sprefrequest);
4957 blob.in = (char *)in;
4959 blob.out_size = AFS_PIOCTL_MAXSIZE;
4962 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4963 /* returns addr in network byte order */
4964 code = pioctl_utf8(0, VIOC_GETCPREFS, &blob, 1);
4966 perror("getClientInterfaceAddr pioctl");
4972 out = (struct sprefinfo *)blob.out;
4973 for (i = 0; i < out->num_servers; i++) {
4976 addr = ntohl(out->servers[i].server.s_addr);
4977 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr >> 24) & 0xff,
4978 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff))) {
4979 fprintf (stderr, "tbuffer - cannot be populated");
4982 printf("%-50s\n", tbuffer);
4984 in->offset = out->next_offset;
4986 } while (out->next_offset > 0);
4992 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4994 afs_int32 code, addr;
4995 struct cmd_item *ti;
4997 struct ViceIoctl blob;
4998 struct setspref *ssp;
4999 int sizeUsed = 0, i, flag;
5000 afs_int32 existingAddr[1024]; /* existing addresses on this host */
5004 ssp = (struct setspref *)space;
5005 ssp->num_servers = 0;
5008 blob.out_size = AFS_PIOCTL_MAXSIZE;
5011 fprintf(stderr, "Permission denied: requires root access.\n");
5015 /* extract all existing interface addresses */
5016 existNu = rx_getAllAddr(existingAddr, 1024);
5020 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
5021 for (ti = as->parms[0].items; ti; ti = ti->next) {
5022 if (sizeUsed >= sizeof(space)) {
5023 fprintf(stderr, "No more space\n");
5026 addr = extractAddr(ti->data, 20); /* network order */
5027 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
5028 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
5033 /* see if it is an address that really exists */
5034 for (flag = 0, i = 0; i < existNu; i++)
5035 if (existingAddr[i] == addr) {
5039 if (!flag) { /* this is an nonexistent address */
5040 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
5044 /* copy all specified addr into ioctl buffer */
5045 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
5046 printf("Adding 0x%08x\n", addr);
5048 sizeUsed += sizeof(struct spref);
5050 if (ssp->num_servers < 1) {
5051 fprintf(stderr, "No addresses specified\n");
5054 blob.in_size = sizeUsed - sizeof(struct spref);
5056 code = pioctl_utf8(0, VIOC_SETCPREFS, &blob, 1); /* network order */
5066 FlushMountCmd(struct cmd_syndesc *as, void *arock)
5069 struct ViceIoctl blob;
5070 struct cmd_item *ti;
5071 char orig_name[1024]; /*Original name, may be modified */
5072 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
5073 char parent_dir[1024]; /*Parent directory of true name */
5074 char *last_component; /*Last component of true name */
5075 struct stat statbuff; /*Buffer for status info */
5076 int link_chars_read; /*Num chars read in readlink() */
5077 int thru_symlink; /*Did we get to a mount point via a symlink? */
5081 for (ti = as->parms[0].items; ti; ti = ti->next) {
5084 if( FAILED(StringCbPrintf(orig_name, sizeof(orig_name), "%s%s", (ti->data[0] == '/') ? "" : "./",
5086 fprintf (stderr, "orig_name - cannot be populated");
5090 if (lstat(orig_name, &statbuff) < 0) {
5091 /* if lstat fails, we should still try the pioctl, since it
5092 * may work (for example, lstat will fail, but pioctl will
5093 * work if the volume of offline (returning ENODEV). */
5094 statbuff.st_mode = S_IFDIR; /* lie like pros */
5098 * The lstat succeeded. If the given file is a symlink, substitute
5099 * the file name with the link name.
5101 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
5104 * Read name of resolved file.
5106 link_chars_read = readlink(orig_name, true_name, 1024);
5107 if (link_chars_read <= 0) {
5109 "%s: Can't read target name for '%s' symbolic link!\n",
5116 * Add a trailing null to what was read, bump the length.
5118 true_name[link_chars_read++] = 0;
5121 * If the symlink is an absolute pathname, we're fine. Otherwise, we
5122 * have to create a full pathname using the original name and the
5123 * relative symlink name. Find the rightmost slash in the original
5124 * name (we know there is one) and splice in the symlink value.
5126 if (true_name[0] != '/') {
5127 last_component = (char *)strrchr(orig_name, '/');
5128 if( FAILED(StringCbCopy(++last_component, sizeof(orig_name) - (last_component - orig_name) * sizeof(char), true_name))) {
5129 fprintf (stderr, "last_component - not enough space");
5132 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
5133 fprintf (stderr, "true_name - not enough space");
5138 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
5139 fprintf (stderr, "true_name - not enough space");
5144 * Find rightmost slash, if any.
5146 last_component = (char *)strrchr(true_name, '/');
5147 if (last_component) {
5149 * Found it. Designate everything before it as the parent directory,
5150 * everything after it as the final component.
5152 if( FAILED(StringCchCopyN(parent_dir, sizeof(parent_dir) / sizeof(char), true_name, last_component - true_name))) {
5153 fprintf (stderr, "parent_dir - not enough space");
5156 parent_dir[last_component - true_name] = 0;
5157 last_component++; /*Skip the slash */
5160 * No slash appears in the given file name. Set parent_dir to the current
5161 * directory, and the last component as the given name.
5163 if( FAILED(StringCbCopy(parent_dir, sizeof(parent_dir), "."))) {
5164 fprintf (stderr, "parent_dir - not enough space");
5167 last_component = true_name;
5170 if (strcmp(last_component, ".") == 0
5171 || strcmp(last_component, "..") == 0) {
5173 "%s: you may not use '.' or '..' as the last component\n",
5175 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
5181 blob.in = last_component;
5182 if( FAILED(StringCbLength(last_component, sizeof(true_name) - (last_component - true_name), &len))) {
5183 fprintf (stderr, "StringCbLength failure on last_component");
5186 blob.in_size = len + 1;
5188 memset(space, 0, AFS_PIOCTL_MAXSIZE);
5190 code = pioctl_utf8(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
5193 if (errno == EINVAL) {
5194 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
5196 Die(errno, (ti->data ? ti->data : parent_dir));
5206 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
5209 afs_int32 flags = 0;
5210 struct ViceIoctl blob;
5212 if (as->parms[0].items) { /* -enable */
5213 flags |= AFSCALL_RXSTATS_ENABLE;
5215 if (as->parms[1].items) { /* -disable */
5216 flags |= AFSCALL_RXSTATS_DISABLE;
5218 if (as->parms[2].items) { /* -clear */
5219 flags |= AFSCALL_RXSTATS_CLEAR;
5222 fprintf(stderr, "You must specify at least one argument\n");
5226 blob.in = (char *)&flags;
5227 blob.in_size = sizeof(afs_int32);
5230 code = pioctl_utf8(NULL, VIOC_RXSTAT_PROC, &blob, 1);
5240 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
5243 afs_int32 flags = 0;
5244 struct ViceIoctl blob;
5246 if (as->parms[0].items) { /* -enable */
5247 flags |= AFSCALL_RXSTATS_ENABLE;
5249 if (as->parms[1].items) { /* -disable */
5250 flags |= AFSCALL_RXSTATS_DISABLE;
5252 if (as->parms[2].items) { /* -clear */
5253 flags |= AFSCALL_RXSTATS_CLEAR;
5256 fprintf(stderr, "You must specify at least one argument\n");
5260 blob.in = (char *)&flags;
5261 blob.in_size = sizeof(afs_int32);
5264 code = pioctl_utf8(NULL, VIOC_RXSTAT_PEER, &blob, 1);
5274 TestVolStatCmd(struct cmd_syndesc *as, void *arock)
5277 struct VolStatTest test;
5278 struct ViceIoctl blob;
5282 memset(&test, 0, sizeof(test));
5284 if (as->parms[0].items) { /* -network */
5285 tp = as->parms[0].items->data;
5286 if (strcmp(tp, "up") == 0)
5287 test.flags |= VOLSTAT_TEST_NETWORK_UP;
5288 else if (strcmp(tp, "down") == 0)
5289 test.flags |= VOLSTAT_TEST_NETWORK_DOWN;
5291 fprintf (stderr, "%s: %s must be \"up\" or \"down\".\n", pn, tp);
5295 if (as->parms[1].items) { /* check */
5296 test.flags |= VOLSTAT_TEST_CHECK_VOLUME;
5298 if (as->parms[2].items) { /* cell */
5299 tp = as->parms[2].items->data;
5304 if( FAILED(StringCbCopy(test.cellname, sizeof(test.cellname), tp))) {
5305 fprintf (stderr, "cellname - not enough space");
5308 test.cellname[sizeof(test.cellname)-1] = '\0';
5311 if (as->parms[3].items) { /* volume */
5312 tp = as->parms[3].items->data;
5315 test.fid.volume = n;
5317 if( FAILED(StringCbCopy(test.volname, sizeof(test.volname), tp))) {
5318 fprintf (stderr, "volname - not enough space");
5321 test.volname[sizeof(test.volname)-1] = '\0';
5324 if (as->parms[4].items) { /* state */
5325 tp = as->parms[4].items->data;
5326 if (strcmp(tp, "online") == 0)
5327 test.state = vl_online;
5328 else if (strcmp(tp, "busy") == 0)
5329 test.state = vl_busy;
5330 else if (strcmp(tp, "offline") == 0)
5331 test.state = vl_offline;
5332 else if (strcmp(tp, "down") == 0)
5333 test.state = vl_alldown;
5335 fprintf (stderr, "%s: %s must be \"online\", \"busy\", \"offline\" or \"down\".\n", pn, tp);
5340 if ((test.fid.cell || test.cellname[0]) && !(test.fid.volume || test.volname[0]) ||
5341 !(test.fid.cell || test.cellname[0]) && (test.fid.volume || test.volname[0])) {
5342 fprintf (stderr, "%s: both a cell and a volume must be specified.\n", pn, tp);
5346 blob.in = (char *)&test;
5347 blob.in_size = sizeof(test);
5350 code = pioctl_utf8(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
5360 ChOwnCmd(struct cmd_syndesc *as, void *arock)
5363 struct ViceIoctl blob;
5364 struct cmd_item *ti;
5368 cm_ioctlQueryOptions_t options;
5375 cm_GetConfigDir(confDir, sizeof(confDir));
5377 if (as->parms[2].items)
5380 ownerStr = as->parms[0].items->data;
5381 ownerId = atoi(ownerStr);
5383 SetDotDefault(&as->parms[1].items);
5384 for(ti=as->parms[1].items; ti; ti=ti->next) {
5386 afs_uint32 filetype;
5387 char cell[CELL_MAXNAMELEN];
5390 memset(&fid, 0, sizeof(fid));
5391 memset(&inData, 0, sizeof(inData));
5393 inData.options.size = sizeof(inData.options);
5394 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
5395 inData.options.literal = literal;
5396 blob.in_size = inData.options.size; /* no variable length data */
5399 blob.out_size = sizeof(cm_fid_t);
5400 blob.out = (char *) &fid;
5401 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
5402 blob.out_size == sizeof(cm_fid_t)) {
5403 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
5404 inData.options.fid = fid;
5406 Die(errno, ti->data);
5412 * if the owner was specified as a numeric value,
5413 * then we can just use it. Otherwise, we need
5414 * to know the cell of the path to determine which
5415 * ptserver to contact in order to convert the name
5416 * to a numeric value.
5419 blob.out_size = CELL_MAXNAMELEN;
5422 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
5424 Die(errno, ti->data);
5428 cell[CELL_MAXNAMELEN - 1] = '\0';
5430 * We now know the cell for the target and we need to
5431 * convert the ownerStr to the Id for this user
5433 pr_Initialize(1, confDir, cell);
5434 code = pr_SNameToId(ownerStr, &inData.owner);
5437 if (code || inData.owner == ANONYMOUSID ) {
5438 Die(ECHILD, ti->data);
5443 inData.owner = ownerId;
5446 blob.in_size = sizeof(inData);
5449 code = pioctl_utf8(ti->data, VIOC_SETOWNER, &blob, 1);
5451 Die(errno, ti->data);
5458 ChGrpCmd(struct cmd_syndesc *as, void *arock)
5461 struct ViceIoctl blob;
5462 struct cmd_item *ti;
5466 cm_ioctlQueryOptions_t options;
5473 cm_GetConfigDir(confDir, sizeof(confDir));
5475 if (as->parms[2].items)
5478 groupStr = as->parms[0].items->data;
5479 groupId = atoi(groupStr);
5481 SetDotDefault(&as->parms[1].items);
5482 for(ti=as->parms[1].items; ti; ti=ti->next) {
5484 afs_uint32 filetype;
5485 char cell[CELL_MAXNAMELEN];
5488 memset(&fid, 0, sizeof(fid));
5489 memset(&inData, 0, sizeof(inData));
5491 inData.options.size = sizeof(inData.options);
5492 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
5493 inData.options.literal = literal;
5494 blob.in_size = inData.options.size; /* no variable length data */
5497 blob.out_size = sizeof(cm_fid_t);
5498 blob.out = (char *) &fid;
5499 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
5500 blob.out_size == sizeof(cm_fid_t)) {
5501 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
5502 inData.options.fid = fid;
5504 Die(errno, ti->data);
5510 * if the group was specified as a numeric value,
5511 * then we can just use it. Otherwise, we need
5512 * to know the cell of the path to determine which
5513 * ptserver to contact in order to convert the name
5514 * to a numeric value.
5517 blob.out_size = CELL_MAXNAMELEN;
5520 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
5522 Die(errno, ti->data);
5526 cell[CELL_MAXNAMELEN - 1] = '\0';
5528 * We now know the cell for the target and we need to
5529 * convert the groupStr to the Id for this user
5531 pr_Initialize(1, confDir, cell);
5532 code = pr_SNameToId(groupStr, &inData.group);
5535 if (code || inData.group == ANONYMOUSID ) {
5536 Die(ECHILD, ti->data);
5541 inData.group = groupId;
5544 blob.in_size = sizeof(inData);
5547 code = pioctl_utf8(ti->data, VIOC_SETGROUP, &blob, 1);
5549 Die(errno, ti->data);
5556 #define USR_MODES (S_ISUID|S_IRWXU)
5557 #define GRP_MODES (S_ISGID|S_IRWXG)
5558 #define EXE_MODES (S_IXUSR|S_IXGRP|S_IXOTH)
5560 #define ALL_MODES (USR_MODES|GRP_MODES|S_IRWXO|S_ISVTX)
5562 #define ALL_MODES (USR_MODES|GRP_MODES|S_IRWXO)
5566 * parsemode() is Copyright 1991 by Vincent Archer.
5567 * You may freely redistribute this software, in source or binary
5568 * form, provided that you do not alter this copyright mention in any
5572 parsemode(char *symbolic, afs_uint32 oldmode)
5574 afs_uint32 who, mask, u_mask = 022, newmode, tmpmask;
5577 newmode = oldmode & ALL_MODES;
5580 for (; *symbolic; symbolic++) {
5581 if (*symbolic == 'a') {
5585 if (*symbolic == 'u') {
5589 if (*symbolic == 'g') {
5593 if (*symbolic == 'o') {
5599 if (!*symbolic || *symbolic == ',') {
5600 Die(EINVAL, "invalid mode");
5604 if (*symbolic == ',')
5606 switch (*symbolic) {
5608 Die(EINVAL, "invalid mode");
5613 action = *symbolic++;
5616 for (; *symbolic; symbolic++) {
5617 if (*symbolic == 'u') {
5618 tmpmask = newmode & S_IRWXU;
5619 mask |= tmpmask | (tmpmask << 3) | (tmpmask << 6);
5623 if (*symbolic == 'g') {
5624 tmpmask = newmode & S_IRWXG;
5625 mask |= tmpmask | (tmpmask >> 3) | (tmpmask << 3);
5629 if (*symbolic == 'o') {
5630 tmpmask = newmode & S_IRWXO;
5631 mask |= tmpmask | (tmpmask >> 3) | (tmpmask >> 6);
5635 if (*symbolic == 'r') {
5636 mask |= S_IRUSR | S_IRGRP | S_IROTH;
5639 if (*symbolic == 'w') {
5640 mask |= S_IWUSR | S_IWGRP | S_IWOTH;
5643 if (*symbolic == 'x') {
5647 if (*symbolic == 's') {
5648 mask |= S_ISUID | S_ISGID;
5651 if (*symbolic == 'X') {
5652 if (S_ISDIR(oldmode) || (oldmode & EXE_MODES))
5656 if (*symbolic == 't') {
5671 newmode |= who & mask;
5673 newmode |= mask & (~u_mask);
5677 newmode &= ~(who & mask);
5679 newmode &= ~mask | u_mask;
5690 ChModCmd(struct cmd_syndesc *as, void *arock)
5693 struct ViceIoctl blob;
5694 struct cmd_item *ti;
5698 cm_ioctlQueryOptions_t options;
5699 afs_uint32 unixModeBits;
5701 afs_uint32 unixModeBits;
5702 afs_int32 absolute = 0;
5706 cm_GetConfigDir(confDir, sizeof(confDir));
5708 if (as->parms[2].items)
5711 unixModeStr = as->parms[0].items->data;
5712 if (*unixModeStr >= '0' && *unixModeStr <= '7') {
5715 while (*unixModeStr >= '0' && *unixModeStr <= '7')
5716 unixModeBits = (unixModeBits << 3) | (*unixModeStr++ & 07);
5718 Die(EINVAL, "invalid mode");
5721 unixModeBits &= ALL_MODES;
5724 SetDotDefault(&as->parms[1].items);
5725 for(ti=as->parms[1].items; ti; ti=ti->next) {
5727 afs_uint32 filetype;
5728 char cell[CELL_MAXNAMELEN];
5731 memset(&fid, 0, sizeof(fid));
5732 memset(&inData, 0, sizeof(inData));
5734 inData.options.size = sizeof(inData.options);
5735 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
5736 inData.options.literal = literal;
5737 blob.in_size = inData.options.size; /* no variable length data */
5740 blob.out_size = sizeof(cm_fid_t);
5741 blob.out = (char *) &fid;
5742 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
5743 blob.out_size == sizeof(cm_fid_t)) {
5744 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
5745 inData.options.fid = fid;
5747 Die(errno, ti->data);
5753 * if the mode was specified as an absolute numeric,
5754 * value we can simply apply it to all of the listed
5755 * file paths. Otherwise, we must obtain the old mode
5756 * value in order to compute the new value from the
5757 * symbolic representation.
5761 blob.out_size = sizeof(afs_uint32);
5762 blob.out = (char *)&unixModeBits;
5763 if (pioctl_utf8(ti->data, VIOC_GETUNIXMODE, &blob, 1) != 0)
5765 Die(errno, ti->data);
5769 inData.unixModeBits = parsemode(unixModeStr, unixModeBits);
5771 inData.unixModeBits = unixModeBits;
5774 blob.in_size = sizeof(inData);
5777 code = pioctl_utf8(ti->data, VIOC_SETUNIXMODE, &blob, 1);
5779 Die(errno, ti->data);
5786 #include "AFS_component_version_number.c"
5790 FreeUtf8CmdLine(int argc, char ** argv)
5793 for (i=0; i < argc; i++) {
5801 MakeUtf8Cmdline(int argc, const wchar_t **wargv)
5806 argv = calloc(argc, sizeof(argv[0]));
5810 for (i=0; i < argc; i++) {
5813 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, FALSE);
5815 (argv[i] = calloc(s+1, sizeof(char))) == NULL) {
5819 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], s+1, NULL, FALSE);
5826 FreeUtf8CmdLine(argc, argv);
5833 int wmain(int argc, wchar_t **wargv)
5836 struct cmd_syndesc *ts;
5839 #ifdef AFS_AIX32_ENV
5841 * The following signal action for AIX is necessary so that in case of a
5842 * crash (i.e. core is generated) we can include the user's data section
5843 * in the core dump. Unfortunately, by default, only a partial core is
5844 * generated which, in many cases, isn't too useful.
5846 struct sigaction nsa;
5848 sigemptyset(&nsa.sa_mask);
5849 nsa.sa_handler = SIG_DFL;
5850 nsa.sa_flags = SA_FULLDUMP;
5851 sigaction(SIGSEGV, &nsa, NULL);
5856 WSAStartup(0x0101, &WSAjunk);
5859 argv = MakeUtf8Cmdline(argc, wargv);
5861 /* try to find volume location information */
5865 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
5866 "get client network interface addresses");
5867 cmd_CreateAlias(ts, "gc");
5869 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
5870 "set client network interface addresses");
5871 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
5872 "client network interfaces");
5873 cmd_CreateAlias(ts, "sc");
5876 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL, "set server ranks");
5877 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
5878 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
5879 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
5880 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
5881 cmd_CreateAlias(ts, "sp");
5883 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL, "get server ranks");
5884 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
5885 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
5886 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
5887 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
5888 cmd_CreateAlias(ts, "gp");
5890 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
5891 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5892 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
5893 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
5894 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
5895 parm_setacl_id = ts->nParms;
5896 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
5897 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
5898 cmd_CreateAlias(ts, "sa");
5900 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL, "list access control list");
5901 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5902 parm_listacl_id = ts->nParms;
5903 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
5904 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
5905 cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
5906 cmd_CreateAlias(ts, "la");
5908 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL, "clean up access control list");
5909 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5911 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL, "copy access control list");
5912 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
5913 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
5914 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
5915 parm_copyacl_id = ts->nParms;
5916 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
5917 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
5919 cmd_CreateAlias(ts, "ca");
5921 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
5922 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5923 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5926 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
5927 "flush mount symlink from cache");
5928 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5931 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
5932 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5933 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
5935 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
5937 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
5938 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
5939 cmd_CreateAlias(ts, "sv");
5941 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL, "control Cache Manager messages");
5942 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
5944 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
5945 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5946 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5947 cmd_CreateAlias(ts, "lv");
5948 cmd_CreateAlias(ts, "listvol");
5950 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
5951 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5952 cmd_CreateAlias(ts, "lq");
5954 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL, "show server disk space usage");
5955 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5956 cmd_CreateAlias(ts, "df");
5958 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
5959 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5961 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
5962 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5964 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
5965 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
5966 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
5967 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
5968 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
5969 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
5975 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
5979 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
5980 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5982 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL, "check local cell's servers");
5983 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
5984 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
5985 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
5986 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
5988 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL, "check volumeID/name mappings");
5989 cmd_CreateAlias(ts, "checkbackups");
5992 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL, "set cache size");
5993 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
5994 cmd_CreateAlias(ts, "cachesize");
5996 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
5998 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL, "get cache usage info");
6000 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL, "list configured cells");
6001 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
6003 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
6004 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
6005 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
6007 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
6009 cmd_CreateAlias(ts, "sq");
6011 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
6012 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "cell name");
6013 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL, "primary servers");
6014 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
6017 * Turn this on only if you wish to be able to talk to a server which is listening
6018 * on alternative ports. This is not intended for general use and may not be
6019 * supported in the cache manager. It is not a way to run two servers at the
6020 * same host, since the cache manager cannot properly distinguish those two hosts.
6022 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
6023 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
6024 cmd_AddParm(ts, "-registry", CMD_FLAG, CMD_OPTIONAL, "add cell info to registry cellservdb");
6025 cmd_AddParm(ts, "-dns", CMD_FLAG, CMD_OPTIONAL, "force use of dns");
6028 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
6029 "configure new cell alias");
6030 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
6031 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
6034 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
6035 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
6036 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
6038 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
6039 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
6040 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
6042 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
6045 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
6048 #ifndef AFS_NT40_ENV
6049 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, "set cache monitor host address");
6050 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
6051 cmd_CreateAlias(ts, "mariner");
6054 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
6055 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
6057 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
6058 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
6059 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
6060 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
6062 ts = cmd_CreateSyntax("flushall", FlushAllCmd, NULL, "flush all data");
6064 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL, "flush all data in volume");
6065 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
6067 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL, "get/set sysname (i.e. @sys) value");
6068 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
6070 #ifndef AFS_NT40_ENV
6071 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL, "enable/disable translators to AFS");
6072 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
6073 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
6074 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
6075 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
6076 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
6079 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
6080 "store to server after file close");
6081 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
6082 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
6083 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
6084 cmd_CreateAlias(ts, "sb");
6086 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL, "set cache manager encryption flag");
6087 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
6089 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL, "get cache manager encryption flag");
6091 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
6092 "Manage per process RX statistics");
6093 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
6094 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
6095 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
6097 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
6098 "Manage per peer RX statistics");
6099 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
6100 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
6101 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
6104 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
6105 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
6108 ts = cmd_CreateSyntax("trace", TraceCmd, NULL, "enable or disable CM tracing");
6109 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
6110 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
6111 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
6112 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
6113 cmd_CreateAlias(ts, "tr");
6115 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
6116 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
6118 ts = cmd_CreateSyntax("memdump", MemDumpCmd, NULL, "dump memory allocs in debug builds");
6119 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
6120 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
6122 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, NULL, "change client side caching policy for AFS shares");
6123 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
6124 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
6125 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
6126 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
6127 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
6129 ts = cmd_CreateSyntax("minidump", MiniDumpCmd, NULL, "Generate MiniDump of current service state");
6131 ts = cmd_CreateSyntax("test_volstat", TestVolStatCmd, NULL, (char *)CMD_HIDDEN);
6132 cmd_AddParm(ts, "-network", CMD_SINGLE, CMD_OPTIONAL, "set network state up or down");
6133 cmd_AddParm(ts, "-check", CMD_FLAG, CMD_OPTIONAL, "check state of offline volumes");
6134 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name or number");
6135 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or number");
6136 cmd_AddParm(ts, "-state", CMD_SINGLE, CMD_OPTIONAL, "new volume state: online, busy, offline, down");
6138 ts = cmd_CreateSyntax("smbunicode", SmbUnicodeCmd, NULL, "enable or disable Unicode on new SMB connections");
6139 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable Unicode on new connections");
6140 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable Unicode on new connections");
6142 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL, "get file id for object(s) in afs");
6143 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
6144 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
6146 ts = cmd_CreateSyntax("chown", ChOwnCmd, NULL, "set owner for object(s) in afs");
6147 cmd_AddParm(ts, "-owner", CMD_SINGLE, 0, "user name or id");
6148 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
6149 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
6151 ts = cmd_CreateSyntax("chgrp", ChGrpCmd, NULL, "set owner for object(s) in afs");
6152 cmd_AddParm(ts, "-group", CMD_SINGLE, 0, "user/group name or id");
6153 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
6154 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
6156 ts = cmd_CreateSyntax("chmod", ChModCmd, NULL, "set UNIX mode for object(s) in afs");
6157 cmd_AddParm(ts, "-mode", CMD_SINGLE, 0, "UNIX mode bits");
6158 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
6159 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
6161 code = cmd_Dispatch(argc, argv);
6166 FreeUtf8CmdLine(argc, argv);
6172 Die(int code, char *filename)
6175 if (code == EINVAL) {
6177 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
6179 fprintf(stderr,"%s: Invalid argument.\n", pn);
6181 else if (code == ENOENT) {
6183 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
6185 fprintf(stderr,"%s: no such file returned\n", pn);
6187 else if (code == EROFS)
6188 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
6189 else if (code == EACCES || code == EPERM) {
6191 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
6193 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
6195 else if (code == ENODEV) {
6196 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
6198 else if (code == ESRCH) { /* hack */
6199 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
6201 else if (code == EPIPE) { /* hack */
6202 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
6204 else if (code == EFBIG) {
6205 fprintf(stderr,"%s: Cache size too large.\n", pn);
6207 else if (code == ETIMEDOUT) {
6209 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
6211 fprintf(stderr,"%s: Connection timed out", pn);
6213 else if (code == EBUSY) {
6215 fprintf(stderr,"%s: All servers are busy on which '%s' resides\n", pn, filename);
6217 fprintf(stderr,"%s: All servers are busy\n", pn);
6219 else if (code == ENXIO) {
6221 fprintf(stderr,"%s: All volume instances are offline on which '%s' resides\n", pn, filename);
6223 fprintf(stderr,"%s: All volume instances are offline\n", pn);
6225 else if (code == ENOSYS) {
6227 fprintf(stderr,"%s: All servers are down on which '%s' resides\n", pn, filename);
6229 fprintf(stderr,"%s: All servers are down\n", pn);
6231 else if (code == ECHILD) { /* hack */
6233 fprintf(stderr,"%s: Invalid owner specified for '%s'\n", pn, filename);
6235 fprintf(stderr,"%s: Invalid owner specified\n", pn);
6239 fprintf(stderr,"%s:'%s'", pn, filename);
6241 fprintf(stderr,"%s", pn);
6243 fprintf(stderr, ": code 0x%x\n", code);
6244 #else /* not WIN32 */
6245 fprintf(stderr,": %s\n", afs_error_message(code));
6246 #endif /* not WIN32 */