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>
28 #include <afs/afs_assert.h>
29 #include <rx/rx_globals.h>
33 #include <afs/afs_consts.h>
34 #include <afs/cellconfig.h>
35 #include <afs/ptserver.h>
36 #include <afs/ptuser.h>
37 #include <afs/volser.h>
38 #include <WINNT\afsreg.h>
45 #include "parsemode.h"
48 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
49 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
50 #define CELL_MAXNAMELEN 256
51 #define MAXHOSTCHARS 64
53 static char space[AFS_PIOCTL_MAXSIZE];
54 static char tspace[1024];
56 static struct ubik_client *uclient;
58 /* some forward references */
59 static void ZapList (struct AclEntry *alist);
61 static int PruneList (struct AclEntry **ae, int dfs);
63 static int CleanAcl(struct Acl *aa, char *fname);
65 static int SetVolCmd(struct cmd_syndesc *as, void *arock);
67 static int GetCellName(char *cellNamep, struct afsconf_cell *infop);
69 static int VLDBInit(int noAuthFlag, struct afsconf_cell *infop);
70 static int GetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
71 static int SetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
72 static int FlushMountCmd(struct cmd_syndesc *asp, void *arock);
73 static int RxStatProcCmd(struct cmd_syndesc *asp, void *arock);
74 static int RxStatPeerCmd(struct cmd_syndesc *asp, void *arock);
76 static int MemDumpCmd(struct cmd_syndesc *asp, void *arock);
77 static int CSCPolicyCmd(struct cmd_syndesc *asp, void *arock);
78 static int MiniDumpCmd(struct cmd_syndesc *asp, void *arock);
80 static char pn[] = "fs";
81 static int rxInitDone = 0;
84 * Character to use between name and rights in printed representation for
87 #define DFS_SEPARATOR ' '
89 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
92 int dfs; /* Originally true if a dfs acl; now also the type
93 * of the acl (1, 2, or 3, corresponding to object,
94 * initial dir, or initial object). */
95 sec_rgy_name_t cell; /* DFS cell name */
98 struct AclEntry *pluslist;
99 struct AclEntry *minuslist;
103 struct AclEntry *next;
109 ZapAcl (struct Acl *acl)
114 ZapList(acl->pluslist);
115 ZapList(acl->minuslist);
120 * Mods for the AFS/DFS protocol translator.
122 * DFS rights. It's ugly to put these definitions here, but they
123 * *cannot* change, because they're part of the wire protocol.
124 * In any event, the protocol translator will guarantee these
125 * assignments for AFS cache managers.
127 #define DFS_READ 0x01
128 #define DFS_WRITE 0x02
129 #define DFS_EXECUTE 0x04
130 #define DFS_CONTROL 0x08
131 #define DFS_INSERT 0x10
132 #define DFS_DELETE 0x20
134 /* the application definable ones (backwards from AFS) */
135 #define DFS_USR0 0x80000000 /* "A" bit */
136 #define DFS_USR1 0x40000000 /* "B" bit */
137 #define DFS_USR2 0x20000000 /* "C" bit */
138 #define DFS_USR3 0x10000000 /* "D" bit */
139 #define DFS_USR4 0x08000000 /* "E" bit */
140 #define DFS_USR5 0x04000000 /* "F" bit */
141 #define DFS_USR6 0x02000000 /* "G" bit */
142 #define DFS_USR7 0x01000000 /* "H" bit */
143 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
144 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
147 * Offset of -id switch in command structure for various commands.
148 * The -if switch is the next switch always.
150 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
153 * Determine whether either the -id or -if switches are present, and
154 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
156 /* int id; Offset of -id switch; -if is next switch */
158 getidf(struct cmd_syndesc *as, int id)
162 if (as->parms[id].items) {
165 if (as->parms[id + 1].items) {
170 "%s: you may specify either -id or -if, but not both switches\n",
178 PRights(afs_int32 arights, int dfs)
181 if (arights & PRSFS_READ)
183 if (arights & PRSFS_LOOKUP)
185 if (arights & PRSFS_INSERT)
187 if (arights & PRSFS_DELETE)
189 if (arights & PRSFS_WRITE)
191 if (arights & PRSFS_LOCK)
193 if (arights & PRSFS_ADMINISTER)
195 if (arights & PRSFS_USR0)
197 if (arights & PRSFS_USR1)
199 if (arights & PRSFS_USR2)
201 if (arights & PRSFS_USR3)
203 if (arights & PRSFS_USR4)
205 if (arights & PRSFS_USR5)
207 if (arights & PRSFS_USR6)
209 if (arights & PRSFS_USR7)
212 if (arights & DFS_READ)
216 if (arights & DFS_WRITE)
220 if (arights & DFS_EXECUTE)
224 if (arights & DFS_CONTROL)
228 if (arights & DFS_INSERT)
232 if (arights & DFS_DELETE)
236 if (arights & (DFS_USRALL))
238 if (arights & DFS_USR0)
240 if (arights & DFS_USR1)
242 if (arights & DFS_USR2)
244 if (arights & DFS_USR3)
246 if (arights & DFS_USR4)
248 if (arights & DFS_USR5)
250 if (arights & DFS_USR6)
252 if (arights & DFS_USR7)
258 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
262 struct ViceIoctl blob;
263 cm_ioctlQueryOptions_t options;
267 memset(&options, 0, sizeof(options));
268 options.size = sizeof(options);
269 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
271 blob.in_size = options.size; /* no variable length data */
273 blob.out_size = sizeof(cm_fid_t);
274 blob.out = (char *) &fid;
276 code = pioctl_utf8(apath, VIOCGETFID, &blob, 1);
278 if ((errno == EINVAL) || (errno == ENOENT))
285 IsFreelanceRoot(char *apath)
287 struct ViceIoctl blob;
291 blob.out_size = AFS_PIOCTL_MAXSIZE;
294 code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
296 return !cm_strnicmp_utf8N("Freelance.Local.Root",space, blob.out_size);
298 return 1; /* assume it is because it is more restrictive that way */
301 /* return a static pointer to a buffer */
306 if( FAILED(StringCbCopy(tspace, sizeof(tspace), apath))) {
307 fprintf (stderr, "tspace - not enough space");
310 tp = strrchr(tspace, '\\');
312 if (tp - tspace > 2 &&
315 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
320 fs_ExtractDriveLetter(apath, tspace);
321 if( FAILED(StringCbCat(tspace, sizeof(tspace), "."))) {
322 fprintf (stderr, "tspace - not enough space");
329 enum rtype {add, destroy, deny};
332 Convert(char *arights, int dfs, enum rtype *rtypep)
337 *rtypep = add; /* add rights, by default */
340 if (!strcmp(arights, "null")) {
344 if (!strcmp(arights,"read"))
345 return DFS_READ | DFS_EXECUTE;
346 if (!strcmp(arights, "write"))
347 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
349 if (!strcmp(arights, "all"))
350 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
351 DFS_WRITE | DFS_CONTROL;
353 if (!strcmp(arights,"read"))
354 return PRSFS_READ | PRSFS_LOOKUP;
355 if (!strcmp(arights, "write"))
356 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
357 PRSFS_WRITE | PRSFS_LOCK;
358 if (!strcmp(arights, "mail"))
359 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
360 if (!strcmp(arights, "all"))
361 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
362 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
364 if (!strcmp(arights, "none")) {
365 *rtypep = destroy; /* Remove entire entry */
369 for(; (tc = *arights) != '\0'; arights++) {
402 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
410 mode |= PRSFS_LOOKUP;
412 mode |= PRSFS_INSERT;
414 mode |= PRSFS_DELETE;
420 mode |= PRSFS_ADMINISTER;
438 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
447 static struct AclEntry *
448 FindList (struct AclEntry *alist, char *aname)
451 if (!strcasecmp(alist->name, aname))
458 /* if no parm specified in a particular slot, set parm to be "." instead */
460 SetDotDefault(struct cmd_item **aitemp)
466 return; /* already has value */
467 /* otherwise, allocate an item representing "." */
468 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
470 ti->next = (struct cmd_item *) 0;
471 ti->data = (char *) malloc(len_data);
473 if( FAILED(StringCbCopy(ti->data, len_data, "."))) {
474 fprintf (stderr, "data - not enough space");
481 ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
483 struct AclEntry *tlist;
484 tlist = (plus ? al->pluslist : al->minuslist);
485 tlist = FindList (tlist, aname);
487 /* Found the item already in the list. */
488 tlist->rights = arights;
490 al->nplus -= PruneList(&al->pluslist, al->dfs);
492 al->nminus -= PruneList(&al->minuslist, al->dfs);
495 /* Otherwise we make a new item and plug in the new data. */
496 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
498 if( FAILED(StringCbCopy(tlist->name, sizeof(tlist->name), aname))) {
499 fprintf (stderr, "name - not enough space");
502 tlist->rights = arights;
504 tlist->next = al->pluslist;
505 al->pluslist = tlist;
507 if (arights == 0 || arights == -1)
508 al->nplus -= PruneList(&al->pluslist, al->dfs);
510 tlist->next = al->minuslist;
511 al->minuslist = tlist;
514 al->nminus -= PruneList(&al->minuslist, al->dfs);
519 ZapList (struct AclEntry *alist)
521 struct AclEntry *tp, *np;
522 for (tp = alist; tp; tp = np) {
529 PruneList (struct AclEntry **ae, int dfs)
531 struct AclEntry **lp;
532 struct AclEntry *te, *ne;
536 for(te = *ae;te;te=ne) {
537 if ((!dfs && te->rights == 0) || te->rights == -1) {
551 SkipLine (char *astr)
560 * Create an empty acl, taking into account whether the acl pointed
561 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
562 * can recover from problems caused by bogus ACL's (in that case, always
563 * assume that the acl is AFS: for DFS, the user can always resort to
564 * acl_edit, but for AFS there may be no other way out).
572 tp = (struct Acl *)malloc(sizeof (struct Acl));
574 tp->nplus = tp->nminus = 0;
575 tp->pluslist = tp->minuslist = 0;
578 if (astr == NULL || sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell) <= 0) {
583 if (astr == NULL || sscanf_s(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell, sizeof(tp->cell)) <= 0) {
592 ParseAcl (char *astr, int astr_size)
594 int nplus, nminus, i, trights, ret;
597 struct AclEntry *first, *next, *last, *tl;
601 if( FAILED(StringCbLength(astr, astr_size, &len))) {
602 fprintf (stderr, "StringCbLength failure on astr");
605 if (astr == NULL || len == 0)
609 ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
611 ret = sscanf_s(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell, sizeof(ta->cell));
617 astr = SkipLine(astr);
619 ret = sscanf(astr, "%d", &ta->nminus);
621 ret = sscanf_s(astr, "%d", &ta->nminus);
627 astr = SkipLine(astr);
634 for(i=0;i<nplus;i++) {
636 ret = sscanf(astr, "%100s %d", tname, &trights);
638 ret = sscanf_s(astr, "%100s %d", tname, sizeof(tname), &trights);
642 astr = SkipLine(astr);
643 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
648 if( FAILED(StringCbCopy(tl->name, sizeof(tl->name), tname))) {
649 fprintf (stderr, "name - not enough space");
652 tl->rights = trights;
658 ta->pluslist = first;
662 for(i=0;i<nminus;i++) {
664 ret = sscanf(astr, "%100s %d", tname, &trights);
666 ret = sscanf_s(astr, "%100s %d", tname, sizeof(tname), &trights);
670 astr = SkipLine(astr);
671 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
676 if( FAILED(StringCbCopy(tl->name, sizeof(tl->name), tname))) {
677 fprintf (stderr, "name - not enough space");
680 tl->rights = trights;
686 ta->minuslist = first;
691 for (;first; first = next) {
695 first = ta->pluslist;
698 for (;first; first = next) {
707 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
709 printf("Volume status for vid = %u named %s is\n",status->Vid, name);
711 printf("Current offline message is %s\n",offmsg);
713 printf("Current message of the day is %s\n",motd);
714 printf("Current disk quota is ");
715 if (status->MaxQuota != 0)
716 printf("%d\n", status->MaxQuota);
718 printf("unlimited\n");
719 printf("Current blocks used are %d\n",status->BlocksInUse);
720 printf("The partition has %d blocks available out of %d\n",
721 status->PartBlocksAvail, status->PartMaxBlocks);
726 QuickPrintStatus(VolumeStatus *status, char *name)
728 double QuotaUsed =0.0;
729 double PartUsed =0.0;
731 printf("%-25.25s",name);
733 if (status->MaxQuota != 0) {
734 printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
735 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
737 printf(" no limit %10d", status->BlocksInUse);
739 if (QuotaUsed > 90.0){
740 printf(" %5.0f%%<<", QuotaUsed);
743 printf(" %5.0f%% ", QuotaUsed);
744 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
745 if (PartUsed > 97.0){
746 printf(" %9.0f%%<<", PartUsed);
749 printf(" %9.0f%% ", PartUsed);
751 printf(" <<WARNING\n");
758 QuickPrintSpace(VolumeStatus *status, char *name)
760 double PartUsed =0.0;
762 printf("%-25.25s",name);
764 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
766 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
767 if (PartUsed > 90.0){
768 printf(" %4.0f%%<<", PartUsed);
771 printf(" %4.0f%% ", PartUsed);
773 printf(" <<WARNING\n");
780 AclToString(struct Acl *acl)
782 static char mydata[AFS_PIOCTL_MAXSIZE];
783 char tstring[AFS_PIOCTL_MAXSIZE];
788 if( FAILED(StringCbPrintf(dfsstring, sizeof(dfsstring), " dfs:%d %s", acl->dfs, acl->cell))) {
789 fprintf (stderr, "dfsstring - cannot be populated");
795 if( FAILED(StringCbPrintf(mydata, sizeof(mydata), "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus))) {
796 fprintf (stderr, "mydata - cannot be populated");
799 for (tp = acl->pluslist;tp;tp=tp->next) {
800 if( FAILED(StringCbPrintf(tstring, sizeof(tstring), "%s %d\n", tp->name, tp->rights))) {
801 fprintf (stderr, "tstring - cannot be populated");
804 if( FAILED(StringCbCat(mydata, sizeof(mydata), tstring))) {
805 fprintf (stderr, "mydata - not enough space");
809 for (tp = acl->minuslist;tp;tp=tp->next) {
810 if( FAILED(StringCbPrintf(tstring, sizeof(tstring), "%s %d\n", tp->name, tp->rights))) {
811 fprintf (stderr, "tstring - cannot be populated");
814 if( FAILED(StringCbCat(mydata, sizeof(mydata), tstring))) {
815 fprintf (stderr, "mydata - not enough space");
822 static DWORD IsFreelance(void)
829 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
830 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
831 if (code == ERROR_SUCCESS) {
832 dummyLen = sizeof(cm_freelanceEnabled);
833 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
834 (BYTE *) &enabled, &dummyLen);
835 RegCloseKey (parmKey);
840 #define NETBIOSNAMESZ 1024
841 static const char * NetbiosName(void)
843 static char buffer[NETBIOSNAMESZ] = "AFS";
849 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
850 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
851 if (code == ERROR_SUCCESS) {
852 dummyLen = sizeof(buffer);
853 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
855 RegCloseKey (parmKey);
857 if( FAILED(StringCbCopy(buffer, sizeof(buffer), "AFS"))) {
858 fprintf (stderr, "buffer - not enough space");
865 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
867 static BOOL IsAdmin (void)
869 static BOOL fAdmin = FALSE;
870 static BOOL fTested = FALSE;
874 /* Obtain the SID for the AFS client admin group. If the group does
875 * not exist, then assume we have AFS client admin privileges.
877 PSID psidAdmin = NULL;
878 DWORD dwSize, dwSize2;
879 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
880 char *pszRefDomain = NULL;
881 SID_NAME_USE snu = SidTypeGroup;
883 dwSize = sizeof(pszAdminGroup);
885 if (!GetComputerName(pszAdminGroup, &dwSize)) {
886 /* Can't get computer name. We return false in this case.
887 Retain fAdmin and fTested. This shouldn't happen.*/
894 if( FAILED(StringCbCat(pszAdminGroup, MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2,"\\"))) {
895 fprintf (stderr, "pszAdminGroup - not enough space");
898 if( FAILED(StringCbCat(pszAdminGroup, MAX_COMPUTERNAME_LENGTH +
899 sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2, AFSCLIENT_ADMIN_GROUPNAME))) {
900 fprintf (stderr, "pszAdminGroup - not enough space");
904 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
905 /* that should always fail. */
907 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
908 /* if we can't find the group, then we allow the operation */
913 if (dwSize == 0 || dwSize2 == 0) {
919 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
921 pszRefDomain = (char *)malloc(dwSize2);
922 assert(pszRefDomain);
924 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
925 /* We can't lookup the group now even though we looked it up earlier.
926 Could this happen? */
929 /* Then open our current ProcessToken */
932 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
935 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
936 /* We'll have to allocate a chunk of memory to store the list of
937 * groups to which this user belongs; find out how much memory
941 PTOKEN_GROUPS pGroups;
943 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
945 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
948 /* Allocate that buffer, and read in the list of groups. */
949 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
951 /* Look through the list of group SIDs and see if any of them
952 * matches the AFS Client Admin group SID.
955 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
957 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
967 /* if do not have permission because we were not explicitly listed
968 * in the Admin Client Group let's see if we are the SYSTEM account
971 PTOKEN_USER pTokenUser;
972 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
973 PSID pSidLocalSystem = 0;
976 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
978 pTokenUser = (PTOKEN_USER)malloc(dwSize);
981 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
982 gle = GetLastError();
984 if (AllocateAndInitializeSid( &SIDAuth, 1,
985 SECURITY_LOCAL_SYSTEM_RID,
989 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
993 FreeSid(pSidLocalSystem);
1012 SetACLCmd(struct cmd_syndesc *as, void *arock)
1015 struct ViceIoctl blob;
1017 struct cmd_item *ti, *ui;
1021 int idf = getidf(as, parm_setacl_id);
1025 if (as->parms[2].items)
1029 plusp = !(as->parms[3].items);
1030 for(ti=as->parms[0].items; ti;ti=ti->next) {
1031 if ( IsFreelanceRoot(ti->data) ) {
1032 fprintf(stderr,"%s: ACLs cannot be set on the Freelance root.afs volume.\n", pn);
1036 blob.out_size = AFS_PIOCTL_MAXSIZE;
1038 blob.in = blob.out = space;
1039 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1041 Die(errno, ti->data);
1047 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1050 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1055 if (!plusp && ta->dfs) {
1057 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
1059 "(you may specify \"null\" to revoke all rights, however)\n");
1066 ta = EmptyAcl(space);
1068 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1071 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1076 CleanAcl(ta, ti->data);
1077 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
1081 "%s: Missing second half of user/access pair.\n", pn);
1085 rights = Convert(ui->next->data, ta->dfs, &rtype);
1086 if (rtype == destroy && !ta->dfs) {
1087 struct AclEntry *tlist;
1089 tlist = (plusp ? ta->pluslist : ta->minuslist);
1090 if (!FindList(tlist, ui->data))
1093 if (rtype == deny && !ta->dfs)
1095 if (rtype == destroy && ta->dfs)
1097 ChangeList(ta, plusp, ui->data, rights);
1099 blob.in = AclToString(ta);
1101 if( FAILED(StringCbLength(blob.in, sizeof(space), &len))) {
1102 fprintf (stderr, "StringCbLength failure on blob.in");
1105 blob.in_size = 1+(long)len;
1106 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1108 if (errno == EINVAL) {
1110 static char *fsenv = 0;
1112 fsenv = (char *)getenv("FS_EXPERT");
1114 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
1117 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1118 "\nPossible reasons for this include:\n\n",
1119 " -You may have specified an inappropriate combination of rights.\n",
1120 " For example, some DFS-supported filesystems may not allow you to\n",
1121 " drop the \"c\" right from \"user_obj\".\n\n",
1122 " -A mask_obj may be required (it is likely required by the underlying\n",
1123 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
1124 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
1125 " does not automatically create or update the mask_obj. Try setting\n",
1126 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
1127 " users or groups. You can do this with a single command, such as\n",
1128 " \"fs sa mask_obj all user:somename read\"\n\n",
1129 " -A specified user or group may not exist.\n\n",
1130 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
1131 " This is probably not allowed by the underlying file system.\n\n",
1132 " -If you add a user or group to a DFS ACL, remember that it must be\n",
1133 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
1134 " may be local requirements on the format of the user or group name.\n",
1135 " Check with your cell administrator.\n\n",
1136 " -Or numerous other possibilities. It would be great if we could be more\n",
1137 " precise about the actual problem, but for various reasons, this is\n",
1138 " impractical via this interface. If you can't figure it out, you\n",
1139 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
1140 " whatever is provided). You may get better results. Good luck!\n\n",
1141 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
1145 "%s: Invalid argument, possible reasons include:\n",
1147 fprintf(stderr,"\t-File not in AFS\n");
1149 "\t-Too many users on access control list\n");
1151 "\t-Tried to add non-existent user to access control list\n");
1154 Die(errno, ti->data);
1165 CopyACLCmd(struct cmd_syndesc *as, void *arock)
1168 struct ViceIoctl blob;
1169 struct Acl *fa, *ta = 0;
1170 struct AclEntry *tp;
1171 struct cmd_item *ti;
1173 int idf = getidf(as, parm_copyacl_id);
1177 if (as->parms[2].items)
1181 blob.out_size = AFS_PIOCTL_MAXSIZE;
1183 blob.in = blob.out = space;
1184 code = pioctl_utf8(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1186 Die(errno, as->parms[0].items->data);
1189 fa = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1192 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1193 as->parms[0].items->data);
1196 CleanAcl(fa, as->parms[0].items->data);
1197 for (ti=as->parms[1].items; ti;ti=ti->next) {
1198 blob.out_size = AFS_PIOCTL_MAXSIZE;
1200 blob.in = blob.out = space;
1201 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1203 Die(errno, ti->data);
1210 ta = EmptyAcl(space);
1212 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1215 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1220 CleanAcl(ta, ti->data);
1221 if (ta->dfs != fa->dfs) {
1223 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1229 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1231 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1236 if( FAILED(StringCbCopy(ta->cell, sizeof(ta->cell), fa->cell))) {
1237 fprintf (stderr, "cell - not enough space");
1241 for (tp = fa->pluslist;tp;tp=tp->next)
1242 ChangeList(ta, 1, tp->name, tp->rights);
1243 for (tp = fa->minuslist;tp;tp=tp->next)
1244 ChangeList(ta, 0, tp->name, tp->rights);
1245 blob.in = AclToString(ta);
1247 if( FAILED(StringCbLength(blob.in, sizeof(space), &len))) {
1248 fprintf (stderr, "StringCbLength failure on blob.in");
1251 blob.in_size = 1+(long)len;
1252 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1254 if (errno == EINVAL) {
1256 "%s: Invalid argument, possible reasons include:\n", pn);
1257 fprintf(stderr,"\t-File not in AFS\n");
1259 Die(errno, ti->data);
1270 /* pioctl_utf8() call to get the cellname of a pathname */
1272 GetCell(char *fname, char *cellname)
1275 struct ViceIoctl blob;
1278 blob.out_size = CELL_MAXNAMELEN;
1279 blob.out = cellname;
1281 code = pioctl_utf8(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1283 cellname[blob.out_size - 1] = '\0';
1287 /* Check if a username is valid: If it contains only digits (or a
1288 * negative sign), then it might be bad. We then query the ptserver
1292 BadName(char *aname, char *fname)
1294 afs_int32 tc, code, id;
1296 char cell[CELL_MAXNAMELEN];
1299 for ( nm = aname; tc = *nm; nm++) {
1300 /* all must be '-' or digit to be bad */
1301 if (tc != '-' && (tc < '0' || tc > '9'))
1305 /* Go to the PRDB and see if this all number username is valid */
1306 code = GetCell(fname, cell);
1310 cm_GetConfigDir(confDir, sizeof(confDir));
1312 pr_Initialize(1, confDir, cell);
1313 code = pr_SNameToId(aname, &id);
1316 /* 1=>Not-valid; 0=>Valid */
1317 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1321 /* clean up an access control list of its bad entries; return 1 if we made
1322 any changes to the list, and 0 otherwise */
1324 CleanAcl(struct Acl *aa, char *fname)
1326 struct AclEntry *te, **le, *ne;
1329 /* Don't correct DFS ACL's for now */
1333 /* prune out bad entries */
1334 changes = 0; /* count deleted entries */
1336 for(te = aa->pluslist; te; te=ne) {
1338 if (BadName(te->name, fname)) {
1348 le = &aa->minuslist;
1349 for(te = aa->minuslist; te; te=ne) {
1351 if (BadName(te->name, fname)) {
1365 /* clean up an acl to not have bogus entries */
1367 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1371 struct ViceIoctl blob;
1373 struct cmd_item *ti;
1374 struct AclEntry *te;
1378 SetDotDefault(&as->parms[0].items);
1379 for(ti=as->parms[0].items; ti; ti=ti->next) {
1380 blob.out_size = AFS_PIOCTL_MAXSIZE;
1383 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1385 Die(errno, ti->data);
1391 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1394 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1401 "%s: cleanacl is not supported for DFS access lists.\n",
1407 changes = CleanAcl(ta, ti->data);
1410 /* now set the acl */
1411 blob.in=AclToString(ta);
1412 if( FAILED(StringCbLength(blob.in, sizeof(space), &len))) {
1413 fprintf (stderr, "StringCbLength failure on blob.in");
1416 blob.in_size = (long)len+1;
1418 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1420 if (errno == EINVAL) {
1422 "%s: Invalid argument, possible reasons include\n",
1424 fprintf(stderr,"%s: File not in vice or\n", pn);
1426 "%s: Too many users on access control list or\n",
1429 Die(errno, ti->data);
1435 /* now list the updated acl */
1436 printf("Access list for %s is now\n", ti->data);
1437 if (ta->nplus > 0) {
1439 printf("Normal rights:\n");
1440 for(te = ta->pluslist;te;te=te->next) {
1441 printf(" %s ", te->name);
1442 PRights(te->rights, ta->dfs);
1446 if (ta->nminus > 0) {
1447 printf("Negative rights:\n");
1448 for(te = ta->minuslist;te;te=te->next) {
1449 printf(" %s ", te->name);
1450 PRights(te->rights, ta->dfs);
1457 printf("Access list for %s is fine.\n", ti->data);
1465 ListACLCmd(struct cmd_syndesc *as, void *arock)
1469 struct ViceIoctl blob;
1470 struct AclEntry *te;
1471 struct cmd_item *ti;
1472 int idf = getidf(as, parm_listacl_id);
1475 SetDotDefault(&as->parms[0].items);
1476 for(ti=as->parms[0].items; ti; ti=ti->next) {
1479 if ( IsFreelanceRoot(ti->data) ) {
1480 fprintf(stderr,"%s: ACLs are not set on the Freelance root.afs volume.\n", pn);
1485 blob.out_size = AFS_PIOCTL_MAXSIZE;
1487 blob.in = blob.out = space;
1488 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1490 Die(errno, ti->data);
1494 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1497 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1502 if (as->parms[3].items) { /* -cmd */
1503 printf("fs setacl -dir %s -acl ", ti->data);
1504 if (ta->nplus > 0) {
1505 for (te = ta->pluslist; te; te = te->next) {
1506 printf(" %s ", te->name);
1507 PRights(te->rights, ta->dfs);
1511 if (ta->nminus > 0) {
1512 printf("fs setacl -dir %s -acl ", ti->data);
1513 for (te = ta->minuslist; te; te = te->next) {
1514 printf(" %s ", te->name);
1515 PRights(te->rights, ta->dfs);
1517 printf(" -negative\n");
1522 printf("Access list for %s is\n", ti->data);
1525 printf("DFS access list for %s is\n", ti->data);
1528 printf("DFS initial directory access list of %s is\n", ti->data);
1531 printf("DFS initial file access list of %s is\n", ti->data);
1535 printf(" Default cell = %s\n", ta->cell);
1537 separator = ta->dfs? DFS_SEPARATOR : ' ';
1538 if (ta->nplus > 0) {
1540 printf("Normal rights:\n");
1541 for(te = ta->pluslist;te;te=te->next) {
1542 printf(" %s%c", te->name, separator);
1543 PRights(te->rights, ta->dfs);
1547 if (ta->nminus > 0) {
1548 printf("Negative rights:\n");
1549 for(te = ta->minuslist;te;te=te->next) {
1550 printf(" %s ", te->name);
1551 PRights(te->rights, ta->dfs);
1564 FlushAllCmd(struct cmd_syndesc *as, void *arock)
1567 struct ViceIoctl blob;
1569 blob.in_size = blob.out_size = 0;
1570 code = pioctl_utf8(NULL, VIOC_FLUSHALL, &blob, 0);
1572 fprintf(stderr, "Error flushing all ");
1579 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1582 struct ViceIoctl blob;
1583 struct cmd_item *ti;
1586 SetDotDefault(&as->parms[0].items);
1587 for(ti=as->parms[0].items; ti; ti=ti->next) {
1588 blob.in_size = blob.out_size = 0;
1589 code = pioctl_utf8(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1591 fprintf(stderr, "Error flushing volume ");
1601 FlushCmd(struct cmd_syndesc *as, void *arock)
1604 struct ViceIoctl blob;
1605 struct cmd_item *ti;
1608 cm_ioctlQueryOptions_t options;
1610 if (as->parms[1].items)
1613 for(ti=as->parms[0].items; ti; ti=ti->next) {
1615 memset(&options, 0, sizeof(options));
1616 options.size = sizeof(options);
1617 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1618 options.literal = literal;
1619 blob.in_size = options.size; /* no variable length data */
1623 code = pioctl_utf8(ti->data, VIOCFLUSH, &blob, 0);
1625 if (errno == EMFILE) {
1626 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1629 fprintf(stderr, "%s: Error flushing file ", pn);
1639 /* all this command does is repackage its args and call SetVolCmd */
1641 SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
1642 struct cmd_syndesc ts;
1644 /* copy useful stuff from our command slot; we may later have to reorder */
1646 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1648 err = memcpy_s(&ts, sizeof(ts), as, sizeof(ts)); /* copy whole thing */
1650 fprintf (stderr, "memcpy_s failure on ts");
1654 return SetVolCmd(&ts, arock);
1658 SetVolCmd(struct cmd_syndesc *as, void *arock) {
1660 struct ViceIoctl blob;
1661 struct cmd_item *ti;
1662 struct VolumeStatus *status;
1663 char *motd, *offmsg, *input, *destEnd;
1664 size_t destRemaining;
1668 SetDotDefault(&as->parms[0].items);
1669 for(ti=as->parms[0].items; ti; ti=ti->next) {
1671 destRemaining = sizeof(space);
1672 blob.out_size = AFS_PIOCTL_MAXSIZE;
1673 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1676 status = (VolumeStatus *)space;
1677 status->MinQuota = status->MaxQuota = -1;
1678 motd = offmsg = NULL;
1679 if (as->parms[1].items) {
1680 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1682 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1687 if (as->parms[2].items)
1688 motd = as->parms[2].items->data;
1689 if (as->parms[3].items)
1690 offmsg = as->parms[3].items->data;
1691 input = (char *)status + sizeof(*status);
1692 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1693 destRemaining -= sizeof(*status) + 1;
1695 if( FAILED(StringCbLength(offmsg, VMSGSIZE, &len))) {
1696 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1701 if( FAILED(StringCbCopyEx(input, destRemaining, offmsg, &destEnd, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
1702 fprintf (stderr, "input - not enough space");
1705 blob.in_size += destEnd - input;
1706 input = destEnd + 1;
1707 destRemaining -= sizeof(char);
1710 destRemaining -= sizeof(char);
1713 if( FAILED(StringCbLength(motd, VMSGSIZE, &len))) {
1714 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1718 if( FAILED(StringCbCopyEx(input, destRemaining, motd, &destEnd, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
1719 fprintf (stderr, "input - not enough space");
1722 blob.in_size += (long)(destEnd - input);
1723 input = destEnd + 1;
1724 destRemaining -= sizeof(char);
1727 destRemaining -= sizeof(char);
1729 code = pioctl_utf8(ti->data,VIOCSETVOLSTAT, &blob, 1);
1731 Die(errno, ti->data);
1738 /* values match cache manager File Types */
1740 filetypestr(afs_uint32 type)
1742 char * s = "Object";
1765 ExamineCmd(struct cmd_syndesc *as, void *arock)
1768 struct ViceIoctl blob;
1769 struct cmd_item *ti;
1770 struct VolumeStatus *status;
1771 char *name, *offmsg, *motd;
1774 cm_ioctlQueryOptions_t options;
1777 if (as->parms[1].items)
1780 SetDotDefault(&as->parms[0].items);
1781 for(ti=as->parms[0].items; ti; ti=ti->next) {
1783 afs_uint32 filetype;
1785 afs_uint32 unixModeBits;
1786 char cell[CELL_MAXNAMELEN];
1789 memset(&fid, 0, sizeof(fid));
1790 memset(&options, 0, sizeof(options));
1792 options.size = sizeof(options);
1793 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1794 options.literal = literal;
1795 blob.in_size = options.size; /* no variable length data */
1798 blob.out_size = sizeof(cm_fid_t);
1799 blob.out = (char *) &fid;
1800 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
1801 blob.out_size == sizeof(cm_fid_t)) {
1802 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1805 Die(errno, ti->data);
1810 blob.out_size = sizeof(filetype);
1811 blob.out = &filetype;
1813 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1814 if (code || blob.out_size != sizeof(filetype)) {
1815 Die(errno, ti->data);
1820 blob.out_size = CELL_MAXNAMELEN;
1823 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1825 cell[blob.out_size-1] = '\0';
1826 printf("%s %s (%u.%u.%u) contained in cell %s\n",
1827 filetypestr(filetype),
1828 ti->data, fid.volume, fid.vnode, fid.unique,
1829 code ? "unknown-cell" : cell);
1831 blob.out_size = 2 * sizeof(afs_uint32);
1832 blob.out = (char *) &owner;
1833 if (0 == pioctl_utf8(ti->data, VIOCGETOWNER, &blob, 1) &&
1834 blob.out_size == 2 * sizeof(afs_uint32)) {
1835 char oname[PR_MAXNAMELEN] = "(unknown)";
1836 char gname[PR_MAXNAMELEN] = "(unknown)";
1839 /* Go to the PRDB and see if this all number username is valid */
1840 cm_GetConfigDir(confDir, sizeof(confDir));
1842 pr_Initialize(1, confDir, cell);
1843 pr_SIdToName(owner[0], oname);
1844 pr_SIdToName(owner[1], gname);
1845 printf("Owner %s (%d) Group %s (%d)\n", oname, owner[0], gname, owner[1]);
1848 blob.out_size = sizeof(afs_uint32);
1849 blob.out = (char *) &unixModeBits;
1850 if (0 == pioctl_utf8(ti->data, VIOC_GETUNIXMODE, &blob, 1) &&
1851 blob.out_size == sizeof(afs_uint32)) {
1852 printf("UNIX mode 0%o\n", unixModeBits);
1856 blob.out_size = AFS_PIOCTL_MAXSIZE;
1857 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1859 space[blob.out_size - 1] = '\0';
1860 status = (VolumeStatus *)space;
1861 name = (char *)status + sizeof(*status);
1862 if( FAILED(StringCbLength(name, sizeof(space) - (name - space), &len))) {
1863 fprintf (stderr, "StringCbLength failure on name");
1866 offmsg = name + len + 1;
1867 if( FAILED(StringCbLength(offmsg, sizeof(space) - (offmsg - space), &len))) {
1868 fprintf (stderr, "StringCbLength failure on offmsg");
1871 motd = offmsg + len + 1;
1872 PrintStatus(status, name, motd, offmsg);
1874 Die(errno, ti->data);
1878 code = pioctl_utf8(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
1881 printf("Volume is online\n");
1884 printf("Volume is offline\n");
1887 printf("All Volume servers are down\n");
1890 printf("All volume servers are busy\n");
1893 printf("Unknown volume state\n");
1894 Die(errno, ti->data);
1902 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1905 struct ViceIoctl blob;
1906 struct cmd_item *ti;
1907 struct VolumeStatus *status;
1912 printf("%-25s%-11s%-11s%-7s%-13s\n", "Volume Name", " Quota",
1913 " Used", " %Used", " Partition");
1914 SetDotDefault(&as->parms[0].items);
1915 for(ti=as->parms[0].items; ti; ti=ti->next) {
1917 blob.out_size = AFS_PIOCTL_MAXSIZE;
1920 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1922 Die(errno, ti->data);
1926 space[blob.out_size - 1] = '\0';
1927 status = (VolumeStatus *)space;
1928 name = (char *)status + sizeof(*status);
1929 QuickPrintStatus(status, name);
1935 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1938 struct ViceIoctl blob;
1939 struct cmd_item *ti;
1945 cm_ioctlQueryOptions_t options;
1947 if (as->parms[1].items)
1950 SetDotDefault(&as->parms[0].items);
1951 for(ti=as->parms[0].items; ti; ti=ti->next) {
1953 afs_uint32 filetype;
1956 memset(&fid, 0, sizeof(fid));
1957 memset(&options, 0, sizeof(options));
1959 options.size = sizeof(options);
1960 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1961 options.literal = literal;
1962 blob.in_size = options.size; /* no variable length data */
1965 blob.out_size = sizeof(cm_fid_t);
1966 blob.out = (char *) &fid;
1967 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
1968 blob.out_size == sizeof(cm_fid_t)) {
1969 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1972 Die(errno, ti->data);
1977 blob.out_size = sizeof(filetype);
1978 blob.out = &filetype;
1980 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1981 if (code || blob.out_size != sizeof(filetype)) {
1982 Die(errno, ti->data);
1986 blob.out_size = AFS_PIOCTL_MAXSIZE;
1988 memset(space, 0, sizeof(space));
1989 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
1991 Die(errno, ti->data);
1995 hosts = (afs_int32 *) space;
1996 printf("%s %s is on host%s ",
1997 filetypestr(filetype),
1999 (hosts[0] && !hosts[1]) ? "": "s");
2000 for(j=0; j<AFS_MAXHOSTS; j++) {
2003 tp = hostutil_GetNameByINet(hosts[j]);
2013 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
2016 struct ViceIoctl blob;
2017 struct cmd_item *ti;
2019 struct VolumeStatus *status;
2022 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
2023 " used", " avail", " %used");
2024 SetDotDefault(&as->parms[0].items);
2025 for(ti=as->parms[0].items; ti; ti=ti->next) {
2027 blob.out_size = AFS_PIOCTL_MAXSIZE;
2030 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
2032 Die(errno, ti->data);
2036 space[blob.out_size - 1] = '\0';
2037 status = (VolumeStatus *)space;
2038 name = (char *)status + sizeof(*status);
2039 QuickPrintSpace(status, name);
2045 QuotaCmd(struct cmd_syndesc *as, void *arock)
2048 struct ViceIoctl blob;
2049 struct cmd_item *ti;
2051 struct VolumeStatus *status;
2054 SetDotDefault(&as->parms[0].items);
2055 for(ti=as->parms[0].items; ti; ti=ti->next) {
2057 blob.out_size = AFS_PIOCTL_MAXSIZE;
2060 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
2062 * The response is VolumeStatus, volume name, offline message, and motd
2064 if (code || blob.out_size < sizeof(*status)) {
2065 Die(errno, ti->data);
2070 status = (VolumeStatus *)space;
2071 if (status->MaxQuota)
2072 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
2075 printf("%2.0f%% of quota used.\n", quotaPct);
2081 ListMountCmd(struct cmd_syndesc *as, void *arock)
2084 struct ViceIoctl blob;
2085 struct cmd_item *ti;
2086 char orig_name[1024]; /*Original name, may be modified*/
2087 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
2088 char parent_dir[1024]; /*Parent directory of true name*/
2089 char *last_component; /*Last component of true name*/
2093 struct stat statbuff; /*Buffer for status info*/
2094 #endif /* not WIN32 */
2096 int link_chars_read; /*Num chars read in readlink()*/
2097 #endif /* not WIN32 */
2098 int thru_symlink; /*Did we get to a mount point via a symlink?*/
2101 for(ti=as->parms[0].items; ti; ti=ti->next) {
2105 if( FAILED(StringCbCopy(orig_name, sizeof(orig_name), ti->data))) {
2106 fprintf (stderr, "orig_name - not enough space");
2109 #else /* not WIN32 */
2111 if( FAILED(StringCbPrintf(orig_name, sizeof(orig_name), "%s%s",
2112 (ti->data[0] == '/') ? "" : "./",
2114 fprintf (stderr, "orig_name - cannot be populated");
2117 #endif /* not WIN32 */
2120 if (lstat(orig_name, &statbuff) < 0) {
2121 /* if lstat fails, we should still try the pioctl, since it
2122 * may work (for example, lstat will fail, but pioctl will
2123 * work if the volume of offline (returning ENODEV). */
2124 statbuff.st_mode = S_IFDIR; /* lie like pros */
2128 * The lstat succeeded. If the given file is a symlink, substitute
2129 * the file name with the link name.
2131 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
2134 * Read name of resolved file.
2136 link_chars_read = readlink(orig_name, true_name, 1024);
2137 if (link_chars_read <= 0) {
2139 "%s: Can't read target name for '%s' symbolic link!\n",
2146 * Add a trailing null to what was read, bump the length.
2148 true_name[link_chars_read++] = 0;
2151 * If the symlink is an absolute pathname, we're fine. Otherwise, we
2152 * have to create a full pathname using the original name and the
2153 * relative symlink name. Find the rightmost slash in the original
2154 * name (we know there is one) and splice in the symlink value.
2156 if (true_name[0] != '\\') {
2157 last_component = (char *) strrchr(orig_name, '\\');
2158 if( FAILED(StringCbCopy(++last_component, sizeof(orig_name) - (last_component - orig_name) * sizeof(char), true_name))) {
2159 fprintf (stderr, "last_component - not enough space");
2162 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
2163 fprintf (stderr, "true_name - not enough space");
2168 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
2169 fprintf (stderr, "true_name - not enough space");
2174 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
2175 fprintf (stderr, "true_name - not enough space");
2181 * Find rightmost slash, if any.
2184 last_component = (char *) strrchr(true_name, '\\');
2185 if (!last_component)
2187 last_component = (char *) strrchr(true_name, '/');
2188 if (last_component) {
2190 * Found it. Designate everything before it as the parent directory,
2191 * everything after it as the final component.
2193 if( FAILED(StringCchCopyN(parent_dir, sizeof(parent_dir) / sizeof(char), true_name, last_component - true_name + 1))) {
2194 fprintf (stderr, "parent_dir - not enough space");
2197 parent_dir[last_component - true_name + 1] = 0;
2198 last_component++; /*Skip the slash*/
2200 if (!InAFS(parent_dir)) {
2201 const char * nbname = NetbiosName();
2202 if( FAILED(StringCbLength(nbname, NETBIOSNAMESZ, &len))) {
2203 fprintf (stderr, "StringCbLength failure on nbname");
2206 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
2207 parent_dir[len+2] == '\\' &&
2208 parent_dir[len+3] == '\0' &&
2209 !strnicmp(nbname,&parent_dir[2],len))
2211 if( FAILED(StringCbPrintf(parent_dir, sizeof(parent_dir),"\\\\%s\\all\\", nbname))) {
2212 fprintf (stderr, "parent_dir - cannot be populated");
2220 * No slash appears in the given file name. Set parent_dir to the current
2221 * directory, and the last component as the given name.
2223 fs_ExtractDriveLetter(true_name, parent_dir);
2224 if( FAILED(StringCbCat(parent_dir, sizeof(parent_dir), "."))) {
2225 fprintf (stderr, "parent_dir - not enough space");
2228 last_component = true_name;
2229 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
2232 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
2233 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
2234 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
2239 blob.in = last_component;
2240 if( FAILED(StringCchLength(last_component, sizeof(true_name) / sizeof(char) - (last_component - true_name), &len))) {
2241 fprintf (stderr, "StringCbLength failure on last_component");
2244 blob.in_size = (long)len+1;
2245 blob.out_size = AFS_PIOCTL_MAXSIZE;
2247 memset(space, 0, AFS_PIOCTL_MAXSIZE);
2249 code = pioctl_utf8(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
2252 printf("'%s' is a %smount point for volume '%.*s'\n",
2254 (thru_symlink ? "symbolic link, leading to a " : ""),
2259 if (errno == EINVAL) {
2260 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
2262 Die(errno, (ti->data ? ti->data : parent_dir));
2271 MakeMountCmd(struct cmd_syndesc *as, void *arock)
2274 char *cellName, *volName, *tmpName;
2276 char localCellName[128];
2278 char path[1024] = "";
2279 struct afsconf_cell info;
2280 struct vldbentry vldbEntry;
2281 struct ViceIoctl blob;
2285 memset(&info, 0, sizeof(info));
2287 if (as->parms[2].items) /* cell name specified */
2288 cellName = as->parms[2].items->data;
2291 volName = as->parms[1].items->data;
2292 if( FAILED(StringCbLength(volName, VL_MAXNAMELEN, &len))) {
2293 fprintf(stderr,"%s: volume name too long (length must be <= 64 characters)\n", pn);
2297 /* Check for a cellname in the volume specification, and complain
2298 * if it doesn't match what was specified with -cell */
2299 if (tmpName = strchr(volName, ':')) {
2302 if (strcasecmp(cellName,volName)) {
2303 fprintf(stderr,"fs: cellnames do not match.\n");
2308 volName = ++tmpName;
2311 parent = Parent(as->parms[0].items->data);
2312 if (!InAFS(parent)) {
2314 const char * nbname = NetbiosName();
2315 if ( FAILED(StringCbLength(nbname, NETBIOSNAMESZ, &len))) {
2316 fprintf (stderr, "StringCbLength failure on nbname");
2319 if (parent[0] == '\\' && parent[1] == '\\' &&
2320 (parent[len+2] == '\\' && parent[len+3] == '\0' || parent[len+2] == '\0') &&
2321 !strnicmp(nbname,&parent[2],len))
2323 if( FAILED(StringCbPrintf(path, sizeof(path),"%s%sall%s", parent,
2324 parent[len+2]?"":"\\",
2325 &as->parms[0].items->data[len+2]))) {
2326 fprintf (stderr, "path - cannot be populated");
2329 parent = Parent(path);
2330 if (!InAFS(parent)) {
2331 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2337 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2342 if( FAILED(StringCbLength(path, sizeof(path), &len))) {
2343 fprintf (stderr, "StringCbLength failure on path");
2347 if( FAILED(StringCbCopy(path, sizeof(path), as->parms[0].items->data))) {
2348 fprintf (stderr, "path - not enough space");
2352 if ( IsFreelanceRoot(parent) ) {
2354 fprintf(stderr,"%s: Only AFS Client Administrators may alter the Freelance root.afs volume\n", pn);
2360 blob.out_size = sizeof(localCellName);
2361 blob.out = localCellName;
2362 code = pioctl_utf8(parent, VIOC_GET_WS_CELL, &blob, 1);
2364 localCellName[sizeof(localCellName) - 1] = '\0';
2365 cellName = localCellName;
2370 code = GetCell(parent,space);
2376 code = GetCellName(cellName?cellName:space, &info);
2380 if (!(as->parms[4].items)) {
2381 /* not fast, check which cell the mountpoint is being created in */
2383 /* not fast, check name with VLDB */
2385 code = VLDBInit(1, &info);
2387 /* make the check. Don't complain if there are problems with init */
2388 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2389 if (code == VL_NOENT) {
2390 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2391 pn, volName, cellName ? cellName : space);
2396 if (as->parms[3].items) { /* if -rw specified */
2397 if( FAILED(StringCbCopy(space, sizeof(space), "%"))) {
2398 fprintf (stderr, "space arr - not enough space");
2402 if( FAILED(StringCbCopy(space, sizeof(space), "#"))) {
2403 fprintf (stderr, "space arr - not enough space");
2408 /* cellular mount point, prepend cell prefix */
2409 if( FAILED(StringCbCat(space, sizeof(space), info.name))) {
2410 fprintf (stderr, "space arr - not enough space");
2413 if( FAILED(StringCbCat(space, sizeof(space), ":"))) {
2414 fprintf (stderr, "space arr - not enough space");
2418 if( FAILED(StringCbCat(space, sizeof(space), volName))) { /* append volume name */
2419 fprintf (stderr, "space arr - not enough space");
2422 if( FAILED(StringCbCat(space, sizeof(space), "."))) { /* stupid convention; these end with a period */
2423 fprintf (stderr, "space arr - not enough space");
2427 /* create symlink with a special pioctl for Windows NT, since it doesn't
2428 * have a symlink system call.
2431 if( FAILED(StringCbLength(space, sizeof(space), &len))) {
2432 fprintf (stderr, "StringCbLength failure on space");
2435 blob.in_size = 1 + (long)len;
2438 code = pioctl_utf8(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2439 #else /* not WIN32 */
2440 code = symlink(space, path);
2441 #endif /* not WIN32 */
2443 if (info.linkedCell)
2444 free(info.linkedCell);
2454 * Delete AFS mount points. Variables are used as follows:
2455 * tbuffer: Set to point to the null-terminated directory name of the mount point
2456 * (or ``.'' if none is provided)
2457 * tp: Set to point to the actual name of the mount point to nuke.
2460 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2462 struct ViceIoctl blob;
2463 struct cmd_item *ti;
2465 char lsbuffer[1024];
2470 for(ti=as->parms[0].items; ti; ti=ti->next) {
2472 tp = (char *) strrchr(ti->data, '\\');
2474 tp = (char *) strrchr(ti->data, '/');
2476 if( FAILED(StringCchCopyN(tbuffer, sizeof(tbuffer) / sizeof(char), ti->data, code=(afs_int32)(tp-ti->data+1)))) { /* the dir name */
2477 fprintf (stderr, "tbuffer - not enough space");
2480 tp++; /* skip the slash */
2483 if (!InAFS(tbuffer)) {
2484 const char * nbname = NetbiosName();
2485 if( FAILED(StringCbLength(nbname, NETBIOSNAMESZ, &len))) {
2486 fprintf (stderr, "StringCbLength failure on nbname");
2490 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2491 tbuffer[len+2] == '\\' &&
2492 tbuffer[len+3] == '\0' &&
2493 !strnicmp(nbname,&tbuffer[2],len))
2495 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer),"\\\\%s\\all\\", nbname))) {
2496 fprintf (stderr, "tbuffer - cannot be populated");
2503 fs_ExtractDriveLetter(ti->data, tbuffer);
2504 if( FAILED(StringCbCat(tbuffer, sizeof(tbuffer), "."))) {
2505 fprintf (stderr, "tbuffer - not enough space");
2509 fs_StripDriveLetter(tp, tp, 0);
2512 if( FAILED(StringCbLength(tp, AFS_PIOCTL_MAXSIZE, &len))) {
2513 fprintf (stderr, "StringCbLength failure on tp");
2516 blob.in_size = (long)len+1;
2517 blob.out = lsbuffer;
2518 blob.out_size = sizeof(lsbuffer);
2519 code = pioctl_utf8(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2521 if (errno == EINVAL) {
2522 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2524 Die(errno, ti->data);
2527 continue; /* don't bother trying */
2530 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2531 fprintf(stderr,"%s: Only AFS Client Administrators may alter the Freelance root.afs volume\n", pn);
2533 continue; /* skip */
2538 if( FAILED(StringCbLength(tp, AFS_PIOCTL_MAXSIZE, &len))) {
2539 fprintf (stderr, "StringCbLength failure on tp");
2542 blob.in_size = (long)len+1;
2543 code = pioctl_utf8(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2545 Die(errno, ti->data);
2556 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2559 struct ViceIoctl blob;
2563 struct afsconf_cell info;
2564 struct chservinfo checkserv;
2568 memset(&info, 0, sizeof(info));
2569 memset(&checkserv, 0, sizeof(struct chservinfo));
2570 blob.in_size=sizeof(struct chservinfo);
2571 blob.in=(caddr_t)&checkserv;
2573 blob.out_size = AFS_PIOCTL_MAXSIZE;
2575 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2577 /* prepare flags for checkservers command */
2578 temp = 2; /* default to checking local cell only */
2579 if (as->parms[2].items)
2580 temp |= 1; /* set fast flag */
2581 if (as->parms[1].items)
2582 temp &= ~2; /* turn off local cell check */
2584 checkserv.magic = 0x12345678; /* XXX */
2585 checkserv.tflags=temp;
2587 /* now copy in optional cell name, if specified */
2588 if (as->parms[0].items) {
2589 code = GetCellName(as->parms[0].items->data, &info);
2593 if( FAILED(StringCbCopy(checkserv.tbuffer, sizeof(checkserv.tbuffer), info.name))) {
2594 fprintf (stderr, "tbuffer - not enough space");
2597 if( FAILED(StringCbLength(info.name, sizeof(info.name), &len))) {
2598 fprintf (stderr, "StringCbLength failure on info.name");
2601 checkserv.tsize=(int)len+1;
2602 if (info.linkedCell)
2603 free(info.linkedCell);
2605 if( FAILED(StringCbCopy(checkserv.tbuffer, sizeof(checkserv.tbuffer),"\0"))) {
2606 fprintf (stderr, "tbuffer - not enough space");
2612 if(as->parms[3].items) {
2613 checkserv.tinterval=atol(as->parms[3].items->data);
2616 if(checkserv.tinterval<0) {
2617 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2618 checkserv.tinterval=-1;
2619 } else if(checkserv.tinterval> 600) {
2620 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2621 checkserv.tinterval=600; /* 10 min max interval */
2624 checkserv.tinterval = -1; /* don't change current interval */
2627 if ( checkserv.tinterval >= 0 ) {
2630 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2635 fprintf (stderr,"Permission denied: requires root access.\n");
2641 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
2643 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2644 printf("Must be root to change -interval\n");
2651 memcpy(&temp, space, sizeof(afs_int32));
2653 err = memcpy_s(&temp, sizeof(temp), space, sizeof(afs_int32));
2655 fprintf (stderr, "memcpy_s failure on temp");
2660 if (checkserv.tinterval >= 0) {
2661 if (checkserv.tinterval > 0)
2662 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2663 checkserv.tinterval, temp);
2665 printf("The current down server probe interval is %d secs\n", temp);
2669 printf("All servers are running.\n");
2671 printf("These servers unavailable due to network or server problems: ");
2672 for(j=0; j < AFS_MAXHOSTS; j++) {
2674 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2676 err = memcpy_s(&temp, sizeof(temp), space + j*sizeof(afs_int32), sizeof(afs_int32));
2678 fprintf (stderr, "memcpy_s failure on temp");
2685 tp = hostutil_GetNameByINet(temp);
2695 MessagesCmd(struct cmd_syndesc *as, void *arock)
2698 struct ViceIoctl blob;
2699 struct gaginfo gagflags;
2700 struct cmd_item *show;
2702 memset(&gagflags, 0, sizeof(struct gaginfo));
2703 blob.in_size = sizeof(struct gaginfo);
2704 blob.in = (caddr_t ) &gagflags;
2705 blob.out_size = AFS_PIOCTL_MAXSIZE;
2707 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2709 if (show = as->parms[0].items) {
2710 if (!strcasecmp (show->data, "user"))
2711 gagflags.showflags |= GAGUSER;
2712 else if (!strcasecmp (show->data, "console"))
2713 gagflags.showflags |= GAGCONSOLE;
2714 else if (!strcasecmp (show->data, "all"))
2715 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2716 else if (!strcasecmp (show->data, "none"))
2720 "unrecognized flag %s: must be in {user,console,all,none}\n",
2729 code = pioctl_utf8(0, VIOC_GAG, &blob, 1);
2738 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2741 struct ViceIoctl blob;
2745 code = pioctl_utf8(0, VIOCCKBACK, &blob, 1);
2750 printf("All volumeID/name mappings checked.\n");
2756 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2759 struct ViceIoctl blob;
2764 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2769 fprintf (stderr,"Permission denied: requires root access.\n");
2774 if (!as->parms[0].items && !as->parms[1].items) {
2775 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2778 if (as->parms[0].items) {
2779 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2781 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2786 blob.in = (char *) &temp;
2787 blob.in_size = sizeof(afs_int32);
2789 code = pioctl_utf8(0, VIOCSETCACHESIZE, &blob, 1);
2791 Die(errno, (char *) 0);
2795 printf("New cache size set.\n");
2800 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2803 struct ViceIoctl blob;
2804 cm_cacheParms_t parms;
2806 memset(&parms, 0, sizeof(parms));
2809 blob.out_size = sizeof(parms);
2810 blob.out = (char *) &parms;
2811 code = pioctl_utf8(0, VIOCGETCACHEPARMS, &blob, 1);
2812 if (code || blob.out_size != sizeof(parms)) {
2817 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2818 parms.parms[1], parms.parms[0]);
2819 if (parms.parms[1] > parms.parms[0])
2820 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2825 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2828 afs_int32 i, j, *lp, magic, size;
2830 afs_int32 addr, maxa = AFS_OMAXHOSTS;
2831 struct ViceIoctl blob;
2835 resolve = !(as->parms[0].items); /* -numeric */
2837 for(i=0;i<1000;i++) {
2840 memcpy(tp, &i, sizeof(afs_int32));
2842 err = memcpy_s(tp, sizeof(space), &i, sizeof(afs_int32));
2844 fprintf (stderr, "memcpy_s failure on tp");
2848 tp = (char *)(space + sizeof(afs_int32));
2849 lp = (afs_int32 *)tp;
2851 size = sizeof(afs_int32) + sizeof(afs_int32);
2852 blob.out_size = AFS_PIOCTL_MAXSIZE;
2853 blob.in_size = sizeof(afs_int32);
2856 code = pioctl_utf8(0, VIOCGETCELL, &blob, 1);
2859 break; /* done with the list */
2865 memcpy(&magic, tp, sizeof(afs_int32));
2867 err = memcpy_s(&magic, sizeof(magic), tp, sizeof(afs_int32));
2869 fprintf (stderr, "memcpy_s failure on magic");
2873 if (magic == 0x12345678) {
2874 maxa = AFS_MAXHOSTS;
2875 tp += sizeof(afs_int32);
2877 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2878 for(j=0; j < maxa && j*sizeof(afs_int32) < AFS_PIOCTL_MAXSIZE; j++) {
2879 char *name, tbuffer[20];
2881 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2883 err = memcpy_s(&addr, sizeof(addr), tp + j*sizeof(afs_int32), sizeof(afs_int32));
2885 fprintf (stderr, "memcpy_s failure on addr");
2893 name = hostutil_GetNameByINet(addr);
2896 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr >> 24) & 0xff,
2897 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff))) {
2898 fprintf (stderr, "tbuffer - cannot be populated");
2903 printf(" %s", name);
2912 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2915 char *tp, *aliasName, *realName;
2916 struct ViceIoctl blob;
2923 memcpy(tp, &i, sizeof(afs_int32));
2925 err = memcpy_s(tp, sizeof(space), &i, sizeof(afs_int32));
2927 fprintf (stderr, "memcpy_s failure on tp");
2931 blob.out_size = AFS_PIOCTL_MAXSIZE;
2932 blob.in_size = sizeof(afs_int32);
2935 code = pioctl_utf8(0, VIOC_GETALIAS, &blob, 1);
2938 break; /* done with the list */
2942 space[blob.out_size - 1] = '\0';
2945 if( FAILED(StringCbLength(aliasName, sizeof(space), &len))) {
2946 fprintf (stderr, "StringCbLength failure on aliasName");
2951 printf("Alias %s for cell %s\n", aliasName, realName);
2957 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2960 struct ViceIoctl blob;
2961 struct cmd_item *ti;
2963 struct hostent *thp;
2967 ti = as->parms[0].items;
2970 thp = hostutil_GetHostByName(ti->data);
2972 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2976 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2978 err = memcpy_s(&hostAddr, sizeof(hostAddr), thp->h_addr, sizeof(afs_int32));
2980 fprintf (stderr, "memcpy_s failure on hostAddr");
2985 hostAddr = 0; /* means don't set host */
2986 setp = 0; /* aren't setting host */
2989 /* now do operation */
2990 blob.in_size = sizeof(afs_int32);
2991 blob.out_size = sizeof(afs_int32);
2992 blob.in = (char *) &hostAddr;
2993 blob.out = (char *) &hostAddr;
2995 code = pioctl_utf8(0, VIOC_CBADDR, &blob, 1);
3005 NewCellCmd(struct cmd_syndesc *as, void *arock)
3007 afs_uint32 code, linkedstate=0, size=0, count=0, *lp;
3008 afs_uint32 usedns=0, useregistry=0;
3009 struct ViceIoctl blob;
3010 struct cmd_item *ti;
3011 char *tp, *cellname=0, *linked_cellname=0;
3012 afs_uint32 fsport = 0, vlport = 0;
3013 size_t destRemaining;
3016 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3020 /* if there is no cell specified, use old Windows behavior */
3021 if (as->parms[0].items == NULL) {
3023 blob.in = (char *) 0;
3024 blob.out_size = AFS_PIOCTL_MAXSIZE;
3027 code = pioctl_utf8((char *) 0, VIOCNEWCELL, &blob, 1);
3030 Die(errno, (char *) 0);
3034 printf("Cell servers information refreshed\n");
3037 cellname = as->parms[0].items->data;
3040 if (as->parms[2].items) {
3042 * Link the cell, for the purposes of volume location, to the specified
3045 linked_cellname = as->parms[2].items->data;
3049 if (as->parms[3].items) {
3050 code = util_GetInt32(as->parms[2].items->data, &vlport);
3052 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
3056 if (as->parms[4].items) {
3057 code = util_GetInt32(as->parms[3].items->data, &fsport);
3059 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
3064 if (as->parms[5].items) {
3068 if (as->parms[6].items) {
3072 /* Count the number of hostnames */
3073 for (ti=as->parms[1].items; ti && count < AFS_MAXHOSTS; ti=ti->next, count++);
3075 if (!usedns && count == 0) {
3076 fprintf( stderr, "fs: at least one vldb server must be specified.");
3080 if (count > AFS_MAXHOSTS) {
3081 fprintf( stderr, "fs: at most %u servers may be specified.", AFS_MAXHOSTS);
3086 * The pioctl data buffer consists of the following structure:
3089 * afs_uint32 alternative fs port
3090 * afs_uint32 alternative vl port
3091 * afs_uint32 count of vldb servers
3094 * n * char[] hostnames
3097 memset(space, 0, sizeof(space));
3099 lp = (afs_uint32 *)tp;
3103 *lp |= VIOC_NEWCELL2_FLAG_USEDNS;
3106 *lp |= VIOC_NEWCELL2_FLAG_USEREG;
3109 *lp |= VIOC_NEWCELL2_FLAG_LINKED;
3118 /* count of server names */
3121 /* Switch back to char pointer */
3124 /* Add nul-terminated cellname */
3125 destRemaining = sizeof(space) - (tp - space);
3126 if( FAILED(StringCbCopyEx( tp,
3128 as->parms[0].items->data,
3131 STRSAFE_FILL_ON_FAILURE))) {
3132 fprintf (stderr, " not enough space for cellname");
3135 /* Move beyond the terminating nul */
3137 destRemaining -= sizeof(char);
3139 /* Add nul-terminated linkname */
3140 if( FAILED(StringCbCopyEx( tp,
3142 linkedstate ? linked_cellname : "",
3145 STRSAFE_FILL_ON_FAILURE))) {
3146 fprintf (stderr, " not enough space for linked cellname");
3149 /* Move beyond the terminating nul */
3151 destRemaining -= sizeof(char);
3153 /* Add the servers */
3154 for (ti=as->parms[1].items; ti; ti=ti->next) {
3155 if( FAILED(StringCbCopyEx( tp,
3160 STRSAFE_FILL_ON_FAILURE))) {
3161 fprintf (stderr, " not enough space for server %s", ti->data);
3164 /* Move beyond the terminating nul */
3166 destRemaining -= sizeof(char);
3169 blob.in_size = (tp - space);
3173 code = pioctl_utf8(NULL, VIOCNEWCELL2, &blob, 1);
3176 Die(errno, as->parms[0].items->data);
3180 printf("Cell servers information for %s added or updated.\n",
3181 as->parms[0].items->data);
3187 NewAliasCmd(struct cmd_syndesc *as, void *arock)
3190 struct ViceIoctl blob;
3192 char *aliasName, *realName;
3193 size_t destRemaining = sizeof(space);
3195 /* Setup and do the NEWALIAS pioctl call */
3196 aliasName = as->parms[0].items->data;
3197 realName = as->parms[1].items->data;
3199 if( FAILED(StringCbCopyEx(tp, destRemaining, aliasName, &tp, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
3200 fprintf (stderr, "tp - not enough space");
3204 destRemaining -= sizeof(char);
3205 if( FAILED(StringCbCopyEx(tp, destRemaining, realName, &tp, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
3206 fprintf (stderr, "tp - not enough space");
3210 destRemaining -= sizeof(char);
3212 blob.in_size = tp - space;
3216 code = pioctl_utf8(0, VIOC_NEWALIAS, &blob, 1);
3218 if (errno == EEXIST) {
3220 "%s: cell name `%s' in use by an existing cell.\n", pn,
3232 WhichCellCmd(struct cmd_syndesc *as, void *arock)
3235 struct cmd_item *ti;
3236 struct ViceIoctl blob;
3239 cm_ioctlQueryOptions_t options;
3241 if (as->parms[1].items)
3244 SetDotDefault(&as->parms[0].items);
3245 for(ti=as->parms[0].items; ti; ti=ti->next) {
3247 afs_uint32 filetype;
3248 char cell[CELL_MAXNAMELEN];
3251 memset(&fid, 0, sizeof(fid));
3252 memset(&options, 0, sizeof(options));
3254 options.size = sizeof(options);
3255 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
3256 options.literal = literal;
3257 blob.in_size = options.size; /* no variable length data */
3260 blob.out_size = sizeof(cm_fid_t);
3261 blob.out = (char *) &fid;
3262 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
3263 blob.out_size == sizeof(cm_fid_t)) {
3264 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
3267 Die(errno, ti->data);
3272 blob.out_size = sizeof(filetype);
3273 blob.out = &filetype;
3275 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
3276 if (code || blob.out_size != sizeof(filetype)) {
3277 Die(errno, ti->data);
3281 blob.out_size = CELL_MAXNAMELEN;
3284 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
3286 if (errno == ENOENT)
3287 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
3289 Die(errno, ti->data);
3293 cell[CELL_MAXNAMELEN - 1] = '\0';
3294 printf("%s %s lives in cell '%s'\n",
3295 filetypestr(filetype),
3302 WSCellCmd(struct cmd_syndesc *as, void *arock)
3305 struct ViceIoctl blob;
3309 blob.out_size = AFS_PIOCTL_MAXSIZE;
3312 code = pioctl_utf8(NULL, VIOC_GET_WS_CELL, &blob, 1);
3318 space[AFS_PIOCTL_MAXSIZE - 1] = '\0';
3319 printf("This workstation belongs to cell '%s'\n", space);
3325 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
3327 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
3332 #ifndef AFS_NT40_ENV
3334 MonitorCmd(struct cmd_syndesc *as, void *arock)
3337 struct ViceIoctl blob;
3338 struct cmd_item *ti;
3340 struct hostent *thp;
3345 ti = as->parms[0].items;
3349 if (!strcmp(ti->data, "off")) {
3350 hostAddr = 0xffffffff;
3352 thp = hostutil_GetHostByName(ti->data);
3354 if (!strcmp(ti->data, "localhost")) {
3355 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
3356 hostAddr = htonl(0x7f000001);
3358 fprintf(stderr,"host %s not found in host table.\n", ti->data);
3363 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
3365 err = memcpy_s(&hostAddr, sizeof(hostAddr), thp->h_addr, sizeof(afs_int32));
3367 fprintf (stderr, "memcpy_s failure on hostAddr");
3374 hostAddr = 0; /* means don't set host */
3375 setp = 0; /* aren't setting host */
3378 /* now do operation */
3379 blob.in_size = sizeof(afs_int32);
3380 blob.out_size = sizeof(afs_int32);
3381 blob.in = (char *) &hostAddr;
3382 blob.out = (char *) &hostAddr;
3383 code = pioctl_utf8(0, VIOC_AFS_MARINER_HOST, &blob, 1);
3384 if (code || blob.out_size != sizeof(afs_int32)) {
3389 printf("%s: new monitor host set.\n", pn);
3391 /* now decode old address */
3392 if (hostAddr == 0xffffffff) {
3393 printf("Cache monitoring is currently disabled.\n");
3395 tp = hostutil_GetNameByINet(hostAddr);
3396 printf("Using host %s for monitor services.\n", tp);
3401 #endif /* AFS_NT40_ENV */
3404 SysNameCmd(struct cmd_syndesc *as, void *arock)
3407 struct ViceIoctl blob;
3408 struct cmd_item *ti;
3409 char *input = space;
3412 size_t destRemaining = sizeof(space);
3415 ti = as->parms[0].items;
3419 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3424 fprintf (stderr,"Permission denied: requires root access.\n");
3432 blob.out_size = AFS_PIOCTL_MAXSIZE;
3433 blob.in_size = sizeof(afs_int32);
3435 memcpy(input, &setp, sizeof(afs_int32));
3437 err = memcpy_s(input, destRemaining, &setp, sizeof(afs_int32));
3439 fprintf (stderr, "memcpy_s failure on input");
3443 input += sizeof(afs_int32);
3444 destRemaining -= sizeof(afs_int32);
3445 for (; ti; ti = ti->next) {
3447 if( FAILED(StringCbCopyEx(input, destRemaining, ti->data, &input, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
3448 fprintf(stderr, "%s: sysname%s too long.\n", pn,
3449 setp > 1 ? "s" : "");
3453 destRemaining -= sizeof(char);
3455 blob.in_size = (input - space) * sizeof(char);
3457 memcpy(space, &setp, sizeof(afs_int32));
3459 err = memcpy_s(space, sizeof(space), &setp, sizeof(afs_int32));
3461 fprintf (stderr, "memcpy_s failure on space");
3466 code = pioctl_utf8(0, VIOC_AFS_SYSNAME, &blob, 1);
3472 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
3478 memcpy(&setp, input, sizeof(afs_int32));
3480 err = memcpy_s(&setp, sizeof(setp), input, sizeof(afs_int32));
3482 fprintf (stderr, "memcpy_s failure on setp");
3486 input += sizeof(afs_int32);
3488 fprintf(stderr,"No sysname name value was found\n");
3491 space[blob.out_size - 1] = '\0';
3492 printf("Current sysname%s is", setp > 1 ? " list" : "");
3493 for (; setp > 0; --setp ) {
3494 printf(" \'%s\'", input);
3495 if( FAILED(StringCbLength(input, sizeof(space) - (input - space), &len))) {
3496 fprintf (stderr, "StringCbLength failure on input");
3505 #ifndef AFS_NT40_ENV
3506 static char *exported_types[] = {"null", "nfs", ""};
3507 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
3510 struct ViceIoctl blob;
3511 struct cmd_item *ti;
3512 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
3513 int exportcall, pwsync = 0, smounts = 0;
3517 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3522 fprintf (stderr,"Permission denied: requires root access.\n");
3527 ti = as->parms[0].items;
3528 if (strcmp(ti->data, "nfs") == 0)
3529 type = 0x71; /* NFS */
3532 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
3535 ti = as->parms[1].items;
3537 if (strcmp(ti->data, "on") == 0)
3539 else if (strcmp(ti->data, "off") == 0)
3542 fprintf(stderr, "Illegal argument %s\n", ti->data);
3547 if (ti = as->parms[2].items) { /* -noconvert */
3548 if (strcmp(ti->data, "on") == 0)
3550 else if (strcmp(ti->data, "off") == 0)
3553 fprintf(stderr, "Illegal argument %s\n", ti->data);
3557 if (ti = as->parms[3].items) { /* -uidcheck */
3558 if (strcmp(ti->data, "on") == 0)
3560 else if (strcmp(ti->data, "off") == 0)
3563 fprintf(stderr, "Illegal argument %s\n", ti->data);
3567 if (ti = as->parms[4].items) { /* -submounts */
3568 if (strcmp(ti->data, "on") == 0)
3570 else if (strcmp(ti->data, "off") == 0)
3573 fprintf(stderr, "Illegal argument %s\n", ti->data);
3577 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
3580 blob.in = (char *) &exportcall;
3581 blob.in_size = sizeof(afs_int32);
3582 blob.out = (char *) &exportcall;
3583 blob.out_size = sizeof(afs_int32);
3584 code = pioctl_utf8(0, VIOC_EXPORTAFS, &blob, 1);
3586 if (errno == ENODEV) {
3588 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
3595 if (exportcall & 1) {
3596 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
3597 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
3598 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
3599 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
3601 printf("'%s' translator is disabled\n", exported_types[type]);
3610 GetCellCmd(struct cmd_syndesc *as, void *arock)
3613 struct ViceIoctl blob;
3614 struct afsconf_cell info;
3615 struct cmd_item *ti;
3623 memset(&info, 0, sizeof(info));
3624 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3625 for(ti=as->parms[0].items; ti; ti=ti->next) {
3627 blob.out_size = sizeof(args);
3628 blob.out = (caddr_t) &args;
3629 code = GetCellName(ti->data, &info);
3634 if (info.linkedCell)
3635 free(info.linkedCell);
3636 if( FAILED(StringCbLength(info.name, sizeof(info.name), &len))) {
3637 fprintf (stderr, "StringCbLength failure on info.name");
3640 blob.in_size = 1+(long)len;
3641 blob.in = info.name;
3642 code = pioctl_utf8(0, VIOC_GETCELLSTATUS, &blob, 1);
3644 if (errno == ENOENT)
3645 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3647 Die(errno, info.name);
3651 printf("Cell %s status: ", info.name);
3657 printf("no setuid allowed");
3659 printf("setuid allowed");
3661 printf(", using old VLDB");
3667 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3670 struct ViceIoctl blob;
3671 struct afsconf_cell info;
3672 struct cmd_item *ti;
3680 memset(&info, 0, sizeof(info));
3682 /* Check arguments. */
3683 if (as->parms[1].items && as->parms[2].items) {
3684 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3688 /* figure stuff to set */
3694 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3699 fprintf (stderr,"Permission denied: requires root access.\n");
3704 if (! as->parms[1].items)
3705 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3707 /* set stat for all listed cells */
3708 for(ti=as->parms[0].items; ti; ti=ti->next) {
3710 code = GetCellName(ti->data, &info);
3715 if (info.linkedCell)
3716 free(info.linkedCell);
3717 if( FAILED(StringCbCopy(args.cname, sizeof(args.cname), info.name))) {
3718 fprintf (stderr, "cname - not enough space");
3721 blob.in_size = sizeof(args);
3722 blob.in = (caddr_t) &args;
3724 blob.out = (caddr_t) 0;
3725 code = pioctl_utf8(0, VIOC_SETCELLSTATUS, &blob, 1);
3727 Die(errno, info.name); /* XXX added cell name to Die() call */
3735 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3737 if( FAILED(StringCbCopy(infop->name, sizeof(infop->name), cellNamep))) {
3738 fprintf (stderr, "name - not enough space");
3745 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3750 cm_GetConfigDir(confDir, sizeof(confDir));
3752 code = ugen_ClientInit(noAuthFlag, confDir,
3753 info->name, 0, &uclient,
3754 NULL, pn, rxkad_clear,
3755 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3756 0, 0, USER_SERVICE_ID);
3761 static struct ViceIoctl gblob;
3762 static int debug = 0;
3764 * here follow some routines in suport of the setserverprefs and
3765 * getserverprefs commands. They are:
3766 * SetPrefCmd "top-level" routine
3767 * addServer adds a server to the list of servers to be poked into the
3768 * kernel. Will poke the list into the kernel if it threatens
3770 * pokeServers pokes the existing list of servers and ranks into the kernel
3771 * GetPrefCmd reads the Cache Manager's current list of server ranks
3780 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3782 ssp = (cm_SSetPref_t *)space;
3783 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3789 * returns -1 if error message printed,
3791 * errno value if error and no error message printed
3798 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3799 if (code && (errno == EINVAL)) {
3800 struct setspref *ssp;
3801 ssp = (struct setspref *)gblob.in;
3802 if (!(ssp->flags & DBservers)) {
3803 gblob.in = (void *)&(ssp->servers[0]);
3804 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3805 code = pioctl_utf8(0, VIOC_SETSPREFS33, &gblob, 1);
3806 return code ? errno : 0;
3809 "This cache manager does not support VL server preferences.\n");
3813 return code ? errno : 0;
3819 addServer(char *name, unsigned short rank)
3824 struct hostent *thostent;
3829 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3831 #define MAXUSHORT ((unsigned short) ~0)
3836 thostent = hostutil_GetHostByName(name);
3838 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3842 ssp = (cm_SSetPref_t *)(gblob.in);
3844 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3845 code = pokeServers();
3846 ssp->num_servers = 0;
3849 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3851 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3853 err = memcpy_s (&(sp->host.s_addr), sizeof(afs_uint32), thostent->h_addr, sizeof(afs_uint32));
3855 fprintf (stderr, "memcpy_s failure on sp->host.s_addr");
3860 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3861 gblob.in_size += sizeof(cm_SPref_t);
3864 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3870 * returns -1 if error message printed,
3872 * errno value if error and no error message printed
3875 addServer(char *name, afs_int32 rank)
3878 struct setspref *ssp;
3880 struct hostent *thostent;
3887 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3889 #define MAXUSHORT ((unsigned short) ~0)
3893 thostent = hostutil_GetHostByName(name);
3895 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3899 ssp = (struct setspref *)(gblob.in);
3901 for (t = 0; thostent->h_addr_list[t]; t++) {
3902 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3903 code = pokeServers();
3906 ssp->num_servers = 0;
3909 sp = (struct spref *)(gblob.in + gblob.in_size);
3911 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3912 sizeof(afs_uint32));
3914 err = memcpy_s(&(sp->server.s_addr), sizeof(afs_uint32), thostent->h_addr_list[t],
3915 sizeof(afs_uint32));
3917 fprintf (stderr, "memcpy_s failure on sp->server.s_addr");
3922 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3923 gblob.in_size += sizeof(struct spref);
3927 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3928 name, sp->rank, sp->server.s_addr);
3936 static BOOL IsWindowsNT (void)
3938 static BOOL fChecked = FALSE;
3939 static BOOL fIsWinNT = FALSE;
3943 OSVERSIONINFO Version;
3947 memset (&Version, 0x00, sizeof(Version));
3948 Version.dwOSVersionInfoSize = sizeof(Version);
3950 if (GetVersionEx (&Version))
3952 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3962 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3966 struct cmd_item *ti;
3971 ssp = (cm_SSetPref_t *)space;
3973 ssp->num_servers = 0;
3974 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3977 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3980 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3986 ti = as->parms[2].items; /* -file */
3988 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3989 if (!(infd = fopen(ti->data,"r" ))) {
3991 Die(errno,ti->data);
3994 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3995 code = addServer (name, (unsigned short) rank);
3998 while ( fscanf_s(infd, "%79s%ld", name, sizeof(name), &rank) != EOF) {
3999 code = addServer (name, (unsigned short) rank);
4006 ti = as->parms[3].items; /* -stdin */
4009 while ( scanf("%79s%ld", name, &rank) != EOF) {
4010 code = addServer (name, (unsigned short) rank);
4013 while ( scanf_s("%79s%ld", name, sizeof(name), &rank) != EOF) {
4014 code = addServer (name, (unsigned short) rank);
4019 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
4024 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
4026 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
4030 code = pokeServers();
4032 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
4034 ssp = (cm_SSetPref_t *)space;
4035 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
4037 ssp->flags = CM_SPREF_VLONLY;
4038 ssp->num_servers = 0;
4040 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
4045 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
4047 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
4052 if (as->parms[1].items) {
4054 printf("now poking vlservers\n");
4055 code = pokeServers();
4065 SetPrefCmd(struct cmd_syndesc *as, void *arock)
4069 struct cmd_item *ti;
4072 struct setspref *ssp;
4073 int error = 0; /* -1 means error message printed,
4074 * >0 means errno value for unprinted message */
4076 ssp = (struct setspref *)space;
4078 ssp->num_servers = 0;
4079 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
4082 gblob.out_size = AFS_PIOCTL_MAXSIZE;
4086 fprintf(stderr, "Permission denied: requires root access.\n");
4090 ti = as->parms[2].items; /* -file */
4093 fprintf(stderr, "opening file %s\n", ti->data);
4094 if (!(infd = fopen(ti->data, "r"))) {
4099 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
4100 code = addServer(name, (unsigned short)rank);
4105 while (fscanf_s(infd, "%79s%ld", name, sizeof(name), &rank) != EOF) {
4106 code = addServer(name, (unsigned short)rank);
4115 ti = as->parms[3].items; /* -stdin */
4118 while (scanf("%79s%ld", name, &rank) != EOF) {
4119 code = addServer(name, (unsigned short)rank);
4124 while (scanf_s("%79s%ld", name, sizeof(name), &rank) != EOF) {
4125 code = addServer(name, (unsigned short)rank);
4132 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
4137 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
4141 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
4145 code = pokeServers();
4149 printf("now working on vlservers, code=%d\n", code);
4151 ssp = (struct setspref *)space;
4152 ssp->flags = DBservers;
4153 ssp->num_servers = 0;
4154 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
4157 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
4162 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
4166 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
4171 if (as->parms[1].items) {
4173 printf("now poking vlservers\n");
4174 code = pokeServers();
4182 return error ? 1 : 0;
4188 GetPrefCmd(struct cmd_syndesc *as, void *arock)
4191 struct cmd_item *ti;
4192 char *name, tbuffer[20];
4197 struct ViceIoctl blob;
4198 struct cm_SPrefRequest *in;
4199 struct cm_SPrefInfo *out;
4203 ti = as->parms[0].items; /* -file */
4205 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
4206 if (!(outfd = freopen(ti->data,"w",stdout))) {
4207 Die(errno,ti->data);
4212 ti = as->parms[1].items; /* -numeric */
4214 ti = as->parms[2].items; /* -vlservers */
4215 vlservers = (ti ? CM_SPREF_VLONLY : 0);
4216 /* ti = as->parms[3].items; -cell */
4218 in = (struct cm_SPrefRequest *)space;
4222 blob.in_size=sizeof(struct cm_SPrefRequest);
4223 blob.in = (char *)in;
4225 blob.out_size = AFS_PIOCTL_MAXSIZE;
4227 in->num_servers = (AFS_PIOCTL_MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
4228 in->flags = vlservers;
4230 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
4232 perror("getserverprefs pioctl");
4236 out = (struct cm_SPrefInfo *) blob.out;
4238 for (i=0;i<out->num_servers;i++) {
4240 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
4243 addr = ntohl(out->servers[i].host.s_addr);
4244 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
4245 (addr>>8) & 0xff, addr & 0xff))) {
4246 fprintf (stderr, "tbuffer - cannot be populated");
4251 printf ("%-50s %5u\n",name,out->servers[i].rank);
4254 in->offset = out->next_offset;
4256 } while (!code && out->next_offset > 0);
4262 GetPrefCmd(struct cmd_syndesc *as, void *arock)
4265 struct cmd_item *ti;
4266 char *name, tbuffer[20];
4267 afs_int32 rank, addr;
4271 struct ViceIoctl blob;
4272 struct sprefrequest *in;
4273 struct sprefinfo *out;
4276 ti = as->parms[0].items; /* -file */
4279 fprintf(stderr, "opening file %s\n", ti->data);
4280 if (!(outfd = freopen(ti->data, "w", stdout))) {
4286 ti = as->parms[1].items; /* -numeric */
4288 ti = as->parms[2].items; /* -vlservers */
4289 vlservers |= (ti ? DBservers : 0);
4290 /* ti = as->parms[3].items; -cell */
4292 in = (struct sprefrequest *)space;
4296 blob.in_size = sizeof(struct sprefrequest);
4297 blob.in = (char *)in;
4299 blob.out_size = AFS_PIOCTL_MAXSIZE;
4302 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4303 in->flags = vlservers;
4305 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
4307 perror("getserverprefs pioctl");
4311 out = (struct sprefinfo *)blob.out;
4313 for (i = 0; i < out->num_servers; i++) {
4315 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
4317 addr = ntohl(out->servers[i].server.s_addr);
4318 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr >> 24) & 0xff,
4319 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff))) {
4320 fprintf (stderr, "tbuffer - cannot be populated");
4325 printf("%-50s %5u\n", name, out->servers[i].rank);
4328 in->offset = out->next_offset;
4329 } while (out->next_offset > 0);
4336 SmbUnicodeCmd(struct cmd_syndesc * asp, void * arock)
4342 struct ViceIoctl blob;
4344 if (asp->parms[0].items) {
4348 } else if (asp->parms[1].items) {
4354 if (inValue != 0 && !IsAdmin()) {
4355 fprintf (stderr, "Permission denied: Requires AFS Client Administrator access.\n");
4359 blob.in_size = sizeof(inValue);
4360 blob.in = (char *) &inValue;
4361 blob.out_size = sizeof(outValue);
4362 blob.out = (char *) &outValue;
4364 code = pioctl_utf8(NULL, VIOC_UNICODECTL, &blob, 1);
4370 if (outValue != 2) {
4371 printf("Unicode support is %s%s.\n",
4372 ((outValue != 0)? "enabled":"disabled"),
4373 ((inValue != 0)? " for new SMB connections":""));
4375 printf("Unicode support is absent in this installation of OpenAFS.\n");
4382 GetFidCmd(struct cmd_syndesc *as, void *arock)
4385 struct ViceIoctl blob;
4386 struct cmd_item *ti;
4389 cm_ioctlQueryOptions_t options;
4391 if (as->parms[1].items)
4394 SetDotDefault(&as->parms[0].items);
4395 for(ti=as->parms[0].items; ti; ti=ti->next) {
4397 afs_uint32 filetype;
4398 char cell[CELL_MAXNAMELEN];
4401 memset(&fid, 0, sizeof(fid));
4402 memset(&options, 0, sizeof(options));
4404 options.size = sizeof(options);
4405 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
4406 options.literal = literal;
4407 blob.in_size = options.size; /* no variable length data */
4410 blob.out_size = sizeof(cm_fid_t);
4411 blob.out = (char *) &fid;
4412 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
4413 blob.out_size == sizeof(cm_fid_t)) {
4414 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
4417 Die(errno, ti->data);
4422 blob.out_size = sizeof(filetype);
4423 blob.out = &filetype;
4425 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
4426 if (code || blob.out_size != sizeof(filetype)) {
4427 Die(errno, ti->data);
4431 blob.out_size = CELL_MAXNAMELEN;
4434 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
4436 cell[CELL_MAXNAMELEN - 1] = '\0';
4437 printf("%s %s (%u.%u.%u) contained in cell %s\n",
4438 filetypestr(filetype),
4439 ti->data, fid.volume, fid.vnode, fid.unique,
4440 code ? "unknown-cell" : cell);
4446 UuidCmd(struct cmd_syndesc *asp, void *arock)
4451 struct ViceIoctl blob;
4452 char * uuidstring = NULL;
4454 if (asp->parms[0].items) {
4457 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4462 fprintf (stderr, "Permission denied: requires root access.\n");
4466 inValue = 1; /* generate new UUID */
4468 inValue = 0; /* just show the current UUID */
4471 blob.in_size = sizeof(inValue);
4472 blob.in = (char *) &inValue;
4473 blob.out_size = sizeof(outValue);
4474 blob.out = (char *) &outValue;
4476 code = pioctl_utf8(NULL, VIOC_UUIDCTL, &blob, 1);
4477 if (code || blob.out_size != sizeof(outValue)) {
4482 UuidToString((UUID *) &outValue, &uuidstring);
4484 printf("%sUUID: %s",
4485 ((inValue == 1)?"New ":""),
4489 RpcStringFree(&uuidstring);
4495 TraceCmd(struct cmd_syndesc *asp, void *arock)
4498 struct ViceIoctl blob;
4504 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4509 fprintf (stderr,"Permission denied: requires root access.\n");
4514 if ((asp->parms[0].items && asp->parms[1].items)) {
4515 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
4519 /* determine if we're turning this tracing on or off */
4521 if (asp->parms[0].items)
4522 inValue = 3; /* enable */
4523 else if (asp->parms[1].items)
4524 inValue = 2; /* disable */
4525 if (asp->parms[2].items)
4526 inValue |= 4; /* do reset */
4527 if (asp->parms[3].items)
4528 inValue |= 8; /* dump */
4530 blob.in_size = sizeof(long);
4531 blob.in = (char *) &inValue;
4532 blob.out_size = sizeof(long);
4533 blob.out = (char *) &outValue;
4535 code = pioctl_utf8(NULL, VIOC_TRACECTL, &blob, 1);
4536 if (code || blob.out_size != sizeof(long)) {
4542 printf("AFS tracing enabled.\n");
4544 printf("AFS tracing disabled.\n");
4549 static void sbusage(void)
4551 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
4552 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
4555 /* fs sb -kbytes 9999 -files *.o -default 64 */
4557 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
4560 struct ViceIoctl blob;
4561 struct cmd_item *ti;
4562 struct sbstruct tsb, tsb2;
4570 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4575 tsb.sb_thisfile = -1;
4576 ti = as->parms[0].items; /* -kbytes */
4578 if (!as->parms[1].items) {
4579 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
4583 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
4584 if (errno == ERANGE) {
4585 fprintf(stderr, "%s: ti->data must within long int range", pn);
4588 if ((tsb.sb_thisfile < 0) || (*t != '\0')) {
4589 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
4595 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
4596 ti = as->parms[2].items; /* -allfiles */
4598 allfiles = strtol(ti->data, &t, 10) * 1024;
4599 if (errno == ERANGE) {
4600 fprintf(stderr, "%s: ti->data must within long int range", pn);
4603 if ((allfiles < 0) || (*t != '\0')) {
4604 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
4610 /* -verbose or -file only or no options */
4611 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
4612 || (!as->parms[0].items && !as->parms[1].items
4613 && !as->parms[2].items))
4616 blob.in = (char *)&tsb;
4617 blob.out = (char *)&tsb2;
4618 blob.in_size = blob.out_size = sizeof(struct sbstruct);
4619 memset(&tsb2, 0, sizeof(tsb2));
4621 /* once per -file */
4622 for (ti = as->parms[1].items; ti; ti = ti->next) {
4623 /* Do this solely to see if the file is there */
4624 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
4626 Die(errno, ti->data);
4631 code = pioctl_utf8(ti->data, VIOC_STOREBEHIND, &blob, 1);
4633 Die(errno, ti->data);
4638 if (verbose && (blob.out_size == sizeof(tsb2))) {
4639 if (tsb2.sb_thisfile == -1) {
4640 fprintf(stdout, "Will store %s according to default.\n",
4644 "Will store up to %d kbytes of %s asynchronously.\n",
4645 (tsb2.sb_thisfile / 1024), ti->data);
4650 /* If no files - make at least one pioctl call, or
4651 * set the allfiles default if we need to.
4653 if (!as->parms[1].items || (allfiles != -1)) {
4654 tsb.sb_default = allfiles;
4655 code = pioctl_utf8(0, VIOC_STOREBEHIND, &blob, 1);
4657 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
4662 /* Having no arguments also reports the default store asynchrony */
4663 if (verbose && (blob.out_size == sizeof(tsb2))) {
4664 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
4665 (tsb2.sb_default / 1024));
4672 SetCryptCmd(struct cmd_syndesc *as, void *arock)
4674 afs_int32 code = 0, flag;
4675 struct ViceIoctl blob;
4680 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4685 tp = as->parms[0].items->data;
4686 if (strcmp(tp, "on") == 0)
4688 else if (strcmp(tp, "off") == 0)
4690 else if (strcmp(tp, "auth") == 0)
4693 fprintf (stderr, "%s: %s must be \"on\", \"auth\", or \"off\".\n", pn, tp);
4697 blob.in = (char *) &flag;
4698 blob.in_size = sizeof(flag);
4700 code = pioctl_utf8(0, VIOC_SETRXKCRYPT, &blob, 1);
4707 GetCryptCmd(struct cmd_syndesc *as, void *arock)
4709 afs_int32 code = 0, flag;
4710 struct ViceIoctl blob;
4716 blob.out_size = sizeof(flag);
4719 code = pioctl_utf8(0, VIOC_GETRXKCRYPT, &blob, 1);
4721 if (code || blob.out_size != sizeof(flag))
4726 memcpy(&flag, tp, sizeof(afs_int32));
4728 err = memcpy_s(&flag, sizeof(flag), tp, sizeof(afs_int32));
4730 fprintf (stderr, "memcpy_s failure on flag");
4735 printf("Security level is currently ");
4737 printf("auth (data integrity).\n");
4739 printf("crypt (data security).\n");
4747 MemDumpCmd(struct cmd_syndesc *asp, void *arock)
4750 struct ViceIoctl blob;
4755 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4759 if ((asp->parms[0].items && asp->parms[1].items)) {
4760 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
4764 /* determine if we're turning this tracing on or off */
4765 if (asp->parms[0].items)
4766 inValue = 1; /* begin */
4767 else if (asp->parms[1].items)
4768 inValue = 0; /* end */
4771 blob.in_size = sizeof(long);
4772 blob.in = (char *) &inValue;
4773 blob.out_size = sizeof(long);
4774 blob.out = (char *) &outValue;
4776 code = pioctl_utf8(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
4777 if (code || blob.out_size != sizeof(long)) {
4783 printf("AFS memdump created.\n");
4786 printf("AFS memdump failed.\n");
4792 MiniDumpCmd(struct cmd_syndesc *asp, void *arock)
4795 SERVICE_STATUS status;
4796 SC_HANDLE hManager = NULL;
4797 SC_HANDLE hService = NULL;
4800 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4804 hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
4808 hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
4812 success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
4815 CloseServiceHandle(hService);
4816 CloseServiceHandle(hManager);
4818 printf("AFS minidump generated.\n");
4824 CloseServiceHandle(hService);
4826 CloseServiceHandle(hManager);
4828 printf("AFS minidump failed.\n");
4833 CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
4835 struct cmd_item *ti;
4841 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4845 for(ti=asp->parms[0].items; ti;ti=ti->next) {
4857 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4858 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4861 REG_OPTION_NON_VOLATILE,
4862 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
4867 if ( hkCSCPolicy == NULL ) {
4868 fprintf (stderr,"Permission denied: requires Administrator access.\n");
4873 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4874 RegCloseKey(hkCSCPolicy);
4881 if (asp->parms[1].items) {
4885 if (asp->parms[2].items) {
4886 policy = "programs";
4889 if (asp->parms[3].items) {
4890 policy = "documents";
4893 if (asp->parms[4].items) {
4897 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, (DWORD)len+1);
4899 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
4900 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
4904 DWORD dwIndex, dwPolicies;
4905 char policyName[256];
4906 DWORD policyNameLen;
4911 /* list current csc policies */
4913 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4914 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4917 REG_OPTION_NON_VOLATILE,
4918 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_QUERY_VALUE,
4923 RegQueryInfoKey( hkCSCPolicy,
4925 NULL, /* lpcClass */
4926 NULL, /* lpReserved */
4927 NULL, /* lpcSubKeys */
4928 NULL, /* lpcMaxSubKeyLen */
4929 NULL, /* lpcMaxClassLen */
4930 &dwPolicies, /* lpcValues */
4931 NULL, /* lpcMaxValueNameLen */
4932 NULL, /* lpcMaxValueLen */
4933 NULL, /* lpcbSecurityDescriptor */
4934 NULL /* lpftLastWriteTime */
4937 printf("Current CSC policies:\n");
4938 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
4940 policyNameLen = sizeof(policyName);
4941 policyLen = sizeof(policy);
4942 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
4943 &dwType, policy, &policyLen);
4945 printf(" %s = %s\n", policyName, policy);
4949 RegCloseKey(hkCSCPolicy);
4954 /* get clients interface addresses */
4956 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4959 struct cmd_item *ti;
4961 struct ViceIoctl blob;
4962 struct sprefrequest *in;
4963 struct sprefinfo *out;
4965 in = (struct sprefrequest *)space;
4969 blob.in_size = sizeof(struct sprefrequest);
4970 blob.in = (char *)in;
4972 blob.out_size = AFS_PIOCTL_MAXSIZE;
4975 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4976 /* returns addr in network byte order */
4977 code = pioctl_utf8(0, VIOC_GETCPREFS, &blob, 1);
4979 perror("getClientInterfaceAddr pioctl");
4985 out = (struct sprefinfo *)blob.out;
4986 for (i = 0; i < out->num_servers; i++) {
4989 addr = ntohl(out->servers[i].server.s_addr);
4990 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr >> 24) & 0xff,
4991 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff))) {
4992 fprintf (stderr, "tbuffer - cannot be populated");
4995 printf("%-50s\n", tbuffer);
4997 in->offset = out->next_offset;
4999 } while (out->next_offset > 0);
5005 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
5007 afs_int32 code, addr;
5008 struct cmd_item *ti;
5010 struct ViceIoctl blob;
5011 struct setspref *ssp;
5012 int sizeUsed = 0, i, flag;
5013 afs_int32 existingAddr[1024]; /* existing addresses on this host */
5017 ssp = (struct setspref *)space;
5018 ssp->num_servers = 0;
5021 blob.out_size = AFS_PIOCTL_MAXSIZE;
5024 fprintf(stderr, "Permission denied: requires root access.\n");
5028 /* extract all existing interface addresses */
5029 existNu = rx_getAllAddr(existingAddr, 1024);
5033 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
5034 for (ti = as->parms[0].items; ti; ti = ti->next) {
5035 if (sizeUsed >= sizeof(space)) {
5036 fprintf(stderr, "No more space\n");
5039 addr = extractAddr(ti->data, 20); /* network order */
5040 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
5041 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
5046 /* see if it is an address that really exists */
5047 for (flag = 0, i = 0; i < existNu; i++)
5048 if (existingAddr[i] == addr) {
5052 if (!flag) { /* this is an nonexistent address */
5053 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
5057 /* copy all specified addr into ioctl buffer */
5058 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
5059 printf("Adding 0x%08x\n", addr);
5061 sizeUsed += sizeof(struct spref);
5063 if (ssp->num_servers < 1) {
5064 fprintf(stderr, "No addresses specified\n");
5067 blob.in_size = sizeUsed - sizeof(struct spref);
5069 code = pioctl_utf8(0, VIOC_SETCPREFS, &blob, 1); /* network order */
5079 FlushMountCmd(struct cmd_syndesc *as, void *arock)
5082 struct ViceIoctl blob;
5083 struct cmd_item *ti;
5084 char orig_name[1024]; /*Original name, may be modified */
5085 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
5086 char parent_dir[1024]; /*Parent directory of true name */
5087 char *last_component; /*Last component of true name */
5088 struct stat statbuff; /*Buffer for status info */
5089 int link_chars_read; /*Num chars read in readlink() */
5090 int thru_symlink; /*Did we get to a mount point via a symlink? */
5094 for (ti = as->parms[0].items; ti; ti = ti->next) {
5097 if( FAILED(StringCbPrintf(orig_name, sizeof(orig_name), "%s%s", (ti->data[0] == '/') ? "" : "./",
5099 fprintf (stderr, "orig_name - cannot be populated");
5103 if (lstat(orig_name, &statbuff) < 0) {
5104 /* if lstat fails, we should still try the pioctl, since it
5105 * may work (for example, lstat will fail, but pioctl will
5106 * work if the volume of offline (returning ENODEV). */
5107 statbuff.st_mode = S_IFDIR; /* lie like pros */
5111 * The lstat succeeded. If the given file is a symlink, substitute
5112 * the file name with the link name.
5114 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
5117 * Read name of resolved file.
5119 link_chars_read = readlink(orig_name, true_name, 1024);
5120 if (link_chars_read <= 0) {
5122 "%s: Can't read target name for '%s' symbolic link!\n",
5129 * Add a trailing null to what was read, bump the length.
5131 true_name[link_chars_read++] = 0;
5134 * If the symlink is an absolute pathname, we're fine. Otherwise, we
5135 * have to create a full pathname using the original name and the
5136 * relative symlink name. Find the rightmost slash in the original
5137 * name (we know there is one) and splice in the symlink value.
5139 if (true_name[0] != '/') {
5140 last_component = (char *)strrchr(orig_name, '/');
5141 if( FAILED(StringCbCopy(++last_component, sizeof(orig_name) - (last_component - orig_name) * sizeof(char), true_name))) {
5142 fprintf (stderr, "last_component - not enough space");
5145 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
5146 fprintf (stderr, "true_name - not enough space");
5151 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
5152 fprintf (stderr, "true_name - not enough space");
5157 * Find rightmost slash, if any.
5159 last_component = (char *)strrchr(true_name, '/');
5160 if (last_component) {
5162 * Found it. Designate everything before it as the parent directory,
5163 * everything after it as the final component.
5165 if( FAILED(StringCchCopyN(parent_dir, sizeof(parent_dir) / sizeof(char), true_name, last_component - true_name))) {
5166 fprintf (stderr, "parent_dir - not enough space");
5169 parent_dir[last_component - true_name] = 0;
5170 last_component++; /*Skip the slash */
5173 * No slash appears in the given file name. Set parent_dir to the current
5174 * directory, and the last component as the given name.
5176 if( FAILED(StringCbCopy(parent_dir, sizeof(parent_dir), "."))) {
5177 fprintf (stderr, "parent_dir - not enough space");
5180 last_component = true_name;
5183 if (strcmp(last_component, ".") == 0
5184 || strcmp(last_component, "..") == 0) {
5186 "%s: you may not use '.' or '..' as the last component\n",
5188 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
5194 blob.in = last_component;
5195 if( FAILED(StringCbLength(last_component, sizeof(true_name) - (last_component - true_name), &len))) {
5196 fprintf (stderr, "StringCbLength failure on last_component");
5199 blob.in_size = len + 1;
5201 memset(space, 0, AFS_PIOCTL_MAXSIZE);
5203 code = pioctl_utf8(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
5206 if (errno == EINVAL) {
5207 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
5209 Die(errno, (ti->data ? ti->data : parent_dir));
5219 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
5222 afs_int32 flags = 0;
5223 struct ViceIoctl blob;
5225 if (as->parms[0].items) { /* -enable */
5226 flags |= AFSCALL_RXSTATS_ENABLE;
5228 if (as->parms[1].items) { /* -disable */
5229 flags |= AFSCALL_RXSTATS_DISABLE;
5231 if (as->parms[2].items) { /* -clear */
5232 flags |= AFSCALL_RXSTATS_CLEAR;
5235 fprintf(stderr, "You must specify at least one argument\n");
5239 blob.in = (char *)&flags;
5240 blob.in_size = sizeof(afs_int32);
5243 code = pioctl_utf8(NULL, VIOC_RXSTAT_PROC, &blob, 1);
5253 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
5256 afs_int32 flags = 0;
5257 struct ViceIoctl blob;
5259 if (as->parms[0].items) { /* -enable */
5260 flags |= AFSCALL_RXSTATS_ENABLE;
5262 if (as->parms[1].items) { /* -disable */
5263 flags |= AFSCALL_RXSTATS_DISABLE;
5265 if (as->parms[2].items) { /* -clear */
5266 flags |= AFSCALL_RXSTATS_CLEAR;
5269 fprintf(stderr, "You must specify at least one argument\n");
5273 blob.in = (char *)&flags;
5274 blob.in_size = sizeof(afs_int32);
5277 code = pioctl_utf8(NULL, VIOC_RXSTAT_PEER, &blob, 1);
5287 TestVolStatCmd(struct cmd_syndesc *as, void *arock)
5290 struct VolStatTest test;
5291 struct ViceIoctl blob;
5295 memset(&test, 0, sizeof(test));
5297 if (as->parms[0].items) { /* -network */
5298 tp = as->parms[0].items->data;
5299 if (strcmp(tp, "up") == 0)
5300 test.flags |= VOLSTAT_TEST_NETWORK_UP;
5301 else if (strcmp(tp, "down") == 0)
5302 test.flags |= VOLSTAT_TEST_NETWORK_DOWN;
5304 fprintf (stderr, "%s: %s must be \"up\" or \"down\".\n", pn, tp);
5308 if (as->parms[1].items) { /* check */
5309 test.flags |= VOLSTAT_TEST_CHECK_VOLUME;
5311 if (as->parms[2].items) { /* cell */
5312 tp = as->parms[2].items->data;
5317 if( FAILED(StringCbCopy(test.cellname, sizeof(test.cellname), tp))) {
5318 fprintf (stderr, "cellname - not enough space");
5321 test.cellname[sizeof(test.cellname)-1] = '\0';
5324 if (as->parms[3].items) { /* volume */
5325 tp = as->parms[3].items->data;
5328 test.fid.volume = n;
5330 if( FAILED(StringCbCopy(test.volname, sizeof(test.volname), tp))) {
5331 fprintf (stderr, "volname - not enough space");
5334 test.volname[sizeof(test.volname)-1] = '\0';
5337 if (as->parms[4].items) { /* state */
5338 tp = as->parms[4].items->data;
5339 if (strcmp(tp, "online") == 0)
5340 test.state = vl_online;
5341 else if (strcmp(tp, "busy") == 0)
5342 test.state = vl_busy;
5343 else if (strcmp(tp, "offline") == 0)
5344 test.state = vl_offline;
5345 else if (strcmp(tp, "down") == 0)
5346 test.state = vl_alldown;
5348 fprintf (stderr, "%s: %s must be \"online\", \"busy\", \"offline\" or \"down\".\n", pn, tp);
5353 if ((test.fid.cell || test.cellname[0]) && !(test.fid.volume || test.volname[0]) ||
5354 !(test.fid.cell || test.cellname[0]) && (test.fid.volume || test.volname[0])) {
5355 fprintf (stderr, "%s: both a cell and a volume must be specified.\n", pn, tp);
5359 blob.in = (char *)&test;
5360 blob.in_size = sizeof(test);
5363 code = pioctl_utf8(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
5373 ChOwnCmd(struct cmd_syndesc *as, void *arock)
5376 struct ViceIoctl blob;
5377 struct cmd_item *ti;
5381 cm_ioctlQueryOptions_t options;
5388 cm_GetConfigDir(confDir, sizeof(confDir));
5390 if (as->parms[2].items)
5393 ownerStr = as->parms[0].items->data;
5394 ownerId = atoi(ownerStr);
5396 SetDotDefault(&as->parms[1].items);
5397 for(ti=as->parms[1].items; ti; ti=ti->next) {
5399 afs_uint32 filetype;
5400 char cell[CELL_MAXNAMELEN];
5403 memset(&fid, 0, sizeof(fid));
5404 memset(&inData, 0, sizeof(inData));
5406 inData.options.size = sizeof(inData.options);
5407 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
5408 inData.options.literal = literal;
5409 blob.in_size = inData.options.size; /* no variable length data */
5412 blob.out_size = sizeof(cm_fid_t);
5413 blob.out = (char *) &fid;
5414 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
5415 blob.out_size == sizeof(cm_fid_t)) {
5416 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
5417 inData.options.fid = fid;
5419 Die(errno, ti->data);
5425 * if the owner was specified as a numeric value,
5426 * then we can just use it. Otherwise, we need
5427 * to know the cell of the path to determine which
5428 * ptserver to contact in order to convert the name
5429 * to a numeric value.
5432 blob.out_size = CELL_MAXNAMELEN;
5435 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
5437 Die(errno, ti->data);
5441 cell[CELL_MAXNAMELEN - 1] = '\0';
5443 * We now know the cell for the target and we need to
5444 * convert the ownerStr to the Id for this user
5446 pr_Initialize(1, confDir, cell);
5447 code = pr_SNameToId(ownerStr, &inData.owner);
5450 if (code || inData.owner == ANONYMOUSID ) {
5451 Die(ECHILD, ti->data);
5456 inData.owner = ownerId;
5459 blob.in_size = sizeof(inData);
5462 code = pioctl_utf8(ti->data, VIOC_SETOWNER, &blob, 1);
5464 Die(errno, ti->data);
5471 ChGrpCmd(struct cmd_syndesc *as, void *arock)
5474 struct ViceIoctl blob;
5475 struct cmd_item *ti;
5479 cm_ioctlQueryOptions_t options;
5486 cm_GetConfigDir(confDir, sizeof(confDir));
5488 if (as->parms[2].items)
5491 groupStr = as->parms[0].items->data;
5492 groupId = atoi(groupStr);
5494 SetDotDefault(&as->parms[1].items);
5495 for(ti=as->parms[1].items; ti; ti=ti->next) {
5497 afs_uint32 filetype;
5498 char cell[CELL_MAXNAMELEN];
5501 memset(&fid, 0, sizeof(fid));
5502 memset(&inData, 0, sizeof(inData));
5504 inData.options.size = sizeof(inData.options);
5505 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
5506 inData.options.literal = literal;
5507 blob.in_size = inData.options.size; /* no variable length data */
5510 blob.out_size = sizeof(cm_fid_t);
5511 blob.out = (char *) &fid;
5512 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
5513 blob.out_size == sizeof(cm_fid_t)) {
5514 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
5515 inData.options.fid = fid;
5517 Die(errno, ti->data);
5523 * if the group was specified as a numeric value,
5524 * then we can just use it. Otherwise, we need
5525 * to know the cell of the path to determine which
5526 * ptserver to contact in order to convert the name
5527 * to a numeric value.
5530 blob.out_size = CELL_MAXNAMELEN;
5533 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
5535 Die(errno, ti->data);
5539 cell[CELL_MAXNAMELEN - 1] = '\0';
5541 * We now know the cell for the target and we need to
5542 * convert the groupStr to the Id for this user
5544 pr_Initialize(1, confDir, cell);
5545 code = pr_SNameToId(groupStr, &inData.group);
5548 if (code || inData.group == ANONYMOUSID ) {
5549 Die(ECHILD, ti->data);
5554 inData.group = groupId;
5557 blob.in_size = sizeof(inData);
5560 code = pioctl_utf8(ti->data, VIOC_SETGROUP, &blob, 1);
5562 Die(errno, ti->data);
5571 ChModCmd(struct cmd_syndesc *as, void *arock)
5574 struct ViceIoctl blob;
5575 struct cmd_item *ti;
5579 cm_ioctlQueryOptions_t options;
5580 afs_uint32 unixModeBits;
5582 afs_uint32 unixModeBits;
5583 afs_int32 absolute = 0;
5587 cm_GetConfigDir(confDir, sizeof(confDir));
5589 if (as->parms[2].items)
5592 unixModeStr = as->parms[0].items->data;
5593 if (*unixModeStr >= '0' && *unixModeStr <= '7') {
5596 while (*unixModeStr >= '0' && *unixModeStr <= '7')
5597 unixModeBits = (unixModeBits << 3) | (*unixModeStr++ & 07);
5599 Die(EINVAL, "invalid mode");
5602 unixModeBits &= ALL_MODES;
5605 SetDotDefault(&as->parms[1].items);
5606 for(ti=as->parms[1].items; ti; ti=ti->next) {
5608 afs_uint32 filetype;
5609 char cell[CELL_MAXNAMELEN];
5612 memset(&fid, 0, sizeof(fid));
5613 memset(&inData, 0, sizeof(inData));
5615 inData.options.size = sizeof(inData.options);
5616 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
5617 inData.options.literal = literal;
5618 blob.in_size = inData.options.size; /* no variable length data */
5621 blob.out_size = sizeof(cm_fid_t);
5622 blob.out = (char *) &fid;
5623 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
5624 blob.out_size == sizeof(cm_fid_t)) {
5625 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
5626 inData.options.fid = fid;
5628 Die(errno, ti->data);
5634 * if the mode was specified as an absolute numeric,
5635 * value we can simply apply it to all of the listed
5636 * file paths. Otherwise, we must obtain the old mode
5637 * value in order to compute the new value from the
5638 * symbolic representation.
5642 blob.out_size = sizeof(afs_uint32);
5643 blob.out = (char *)&unixModeBits;
5644 if (pioctl_utf8(ti->data, VIOC_GETUNIXMODE, &blob, 1) != 0)
5646 Die(errno, ti->data);
5650 inData.unixModeBits = parsemode(unixModeStr, unixModeBits);
5652 inData.unixModeBits = unixModeBits;
5655 blob.in_size = sizeof(inData);
5658 code = pioctl_utf8(ti->data, VIOC_SETUNIXMODE, &blob, 1);
5660 Die(errno, ti->data);
5667 #include "AFS_component_version_number.c"
5671 FreeUtf8CmdLine(int argc, char ** argv)
5674 for (i=0; i < argc; i++) {
5682 MakeUtf8Cmdline(int argc, const wchar_t **wargv)
5687 argv = calloc(argc, sizeof(argv[0]));
5691 for (i=0; i < argc; i++) {
5694 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, FALSE);
5696 (argv[i] = calloc(s+1, sizeof(char))) == NULL) {
5700 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], s+1, NULL, FALSE);
5707 FreeUtf8CmdLine(argc, argv);
5714 int wmain(int argc, wchar_t **wargv)
5717 struct cmd_syndesc *ts;
5720 #ifdef AFS_AIX32_ENV
5722 * The following signal action for AIX is necessary so that in case of a
5723 * crash (i.e. core is generated) we can include the user's data section
5724 * in the core dump. Unfortunately, by default, only a partial core is
5725 * generated which, in many cases, isn't too useful.
5727 struct sigaction nsa;
5729 sigemptyset(&nsa.sa_mask);
5730 nsa.sa_handler = SIG_DFL;
5731 nsa.sa_flags = SA_FULLDUMP;
5732 sigaction(SIGSEGV, &nsa, NULL);
5737 WSAStartup(0x0101, &WSAjunk);
5740 argv = MakeUtf8Cmdline(argc, wargv);
5742 /* try to find volume location information */
5746 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
5747 "get client network interface addresses");
5748 cmd_CreateAlias(ts, "gc");
5750 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
5751 "set client network interface addresses");
5752 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
5753 "client network interfaces");
5754 cmd_CreateAlias(ts, "sc");
5757 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL, "set server ranks");
5758 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
5759 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
5760 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
5761 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
5762 cmd_CreateAlias(ts, "sp");
5764 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL, "get server ranks");
5765 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
5766 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
5767 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
5768 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
5769 cmd_CreateAlias(ts, "gp");
5771 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
5772 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5773 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
5774 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
5775 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
5776 parm_setacl_id = ts->nParms;
5777 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
5778 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
5779 cmd_CreateAlias(ts, "sa");
5781 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL, "list access control list");
5782 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5783 parm_listacl_id = ts->nParms;
5784 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
5785 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
5786 cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
5787 cmd_CreateAlias(ts, "la");
5789 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL, "clean up access control list");
5790 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5792 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL, "copy access control list");
5793 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
5794 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
5795 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
5796 parm_copyacl_id = ts->nParms;
5797 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
5798 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
5800 cmd_CreateAlias(ts, "ca");
5802 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
5803 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5804 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5807 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
5808 "flush mount symlink from cache");
5809 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5812 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
5813 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5814 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
5816 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
5818 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
5819 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
5820 cmd_CreateAlias(ts, "sv");
5822 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL, "control Cache Manager messages");
5823 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
5825 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
5826 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5827 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5828 cmd_CreateAlias(ts, "lv");
5829 cmd_CreateAlias(ts, "listvol");
5831 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
5832 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5833 cmd_CreateAlias(ts, "lq");
5835 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL, "show server disk space usage");
5836 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5837 cmd_CreateAlias(ts, "df");
5839 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
5840 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5842 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
5843 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5845 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
5846 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
5847 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
5848 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
5849 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
5850 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
5856 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
5860 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
5861 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5863 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL, "check local cell's servers");
5864 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
5865 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
5866 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
5867 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
5869 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL, "check volumeID/name mappings");
5870 cmd_CreateAlias(ts, "checkbackups");
5873 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL, "set cache size");
5874 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
5875 cmd_CreateAlias(ts, "cachesize");
5877 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
5879 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL, "get cache usage info");
5881 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL, "list configured cells");
5882 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
5884 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
5885 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
5886 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
5888 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
5890 cmd_CreateAlias(ts, "sq");
5892 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
5893 cmd_AddParm(ts, "-name", CMD_SINGLE, CMD_OPTIONAL, "cell name");
5894 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL, "primary servers");
5895 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
5898 * Turn this on only if you wish to be able to talk to a server which is listening
5899 * on alternative ports. This is not intended for general use and may not be
5900 * supported in the cache manager. It is not a way to run two servers at the
5901 * same host, since the cache manager cannot properly distinguish those two hosts.
5903 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
5904 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
5905 cmd_AddParm(ts, "-registry", CMD_FLAG, CMD_OPTIONAL, "add cell info to registry cellservdb");
5906 cmd_AddParm(ts, "-dns", CMD_FLAG, CMD_OPTIONAL, "force use of dns");
5909 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
5910 "configure new cell alias");
5911 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
5912 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
5915 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
5916 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5917 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5919 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
5920 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5921 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5923 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
5926 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
5929 #ifndef AFS_NT40_ENV
5930 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, "set cache monitor host address");
5931 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
5932 cmd_CreateAlias(ts, "mariner");
5935 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
5936 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
5938 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
5939 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
5940 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
5941 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
5943 ts = cmd_CreateSyntax("flushall", FlushAllCmd, NULL, "flush all data");
5945 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL, "flush all data in volume");
5946 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5948 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL, "get/set sysname (i.e. @sys) value");
5949 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
5951 #ifndef AFS_NT40_ENV
5952 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL, "enable/disable translators to AFS");
5953 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
5954 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
5955 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
5956 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
5957 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
5960 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
5961 "store to server after file close");
5962 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
5963 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
5964 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
5965 cmd_CreateAlias(ts, "sb");
5967 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL, "set cache manager encryption flag");
5968 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
5970 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL, "get cache manager encryption flag");
5972 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
5973 "Manage per process RX statistics");
5974 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
5975 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
5976 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
5978 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
5979 "Manage per peer RX statistics");
5980 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
5981 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
5982 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
5985 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
5986 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
5989 ts = cmd_CreateSyntax("trace", TraceCmd, NULL, "enable or disable CM tracing");
5990 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
5991 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
5992 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
5993 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
5994 cmd_CreateAlias(ts, "tr");
5996 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
5997 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
5999 ts = cmd_CreateSyntax("memdump", MemDumpCmd, NULL, "dump memory allocs in debug builds");
6000 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
6001 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
6003 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, NULL, "change client side caching policy for AFS shares");
6004 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
6005 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
6006 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
6007 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
6008 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
6010 ts = cmd_CreateSyntax("minidump", MiniDumpCmd, NULL, "Generate MiniDump of current service state");
6012 ts = cmd_CreateSyntax("test_volstat", TestVolStatCmd, NULL, (char *)CMD_HIDDEN);
6013 cmd_AddParm(ts, "-network", CMD_SINGLE, CMD_OPTIONAL, "set network state up or down");
6014 cmd_AddParm(ts, "-check", CMD_FLAG, CMD_OPTIONAL, "check state of offline volumes");
6015 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name or number");
6016 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or number");
6017 cmd_AddParm(ts, "-state", CMD_SINGLE, CMD_OPTIONAL, "new volume state: online, busy, offline, down");
6019 ts = cmd_CreateSyntax("smbunicode", SmbUnicodeCmd, NULL, "enable or disable Unicode on new SMB connections");
6020 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable Unicode on new connections");
6021 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable Unicode on new connections");
6023 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL, "get file id for object(s) in afs");
6024 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
6025 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
6027 ts = cmd_CreateSyntax("chown", ChOwnCmd, NULL, "set owner for object(s) in afs");
6028 cmd_AddParm(ts, "-owner", CMD_SINGLE, 0, "user name or id");
6029 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
6030 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
6032 ts = cmd_CreateSyntax("chgrp", ChGrpCmd, NULL, "set owner for object(s) in afs");
6033 cmd_AddParm(ts, "-group", CMD_SINGLE, 0, "user/group name or id");
6034 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
6035 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
6037 ts = cmd_CreateSyntax("chmod", ChModCmd, NULL, "set UNIX mode for object(s) in afs");
6038 cmd_AddParm(ts, "-mode", CMD_SINGLE, 0, "UNIX mode bits");
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 code = cmd_Dispatch(argc, argv);
6047 FreeUtf8CmdLine(argc, argv);
6053 Die(int code, char *filename)
6056 if (code == EINVAL) {
6058 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
6060 fprintf(stderr,"%s: Invalid argument.\n", pn);
6062 else if (code == ENOENT) {
6064 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
6066 fprintf(stderr,"%s: no such file returned\n", pn);
6068 else if (code == EROFS)
6069 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
6070 else if (code == EACCES || code == EPERM) {
6072 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
6074 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
6076 else if (code == ENODEV) {
6077 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
6079 else if (code == ESRCH) { /* hack */
6080 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
6082 else if (code == EPIPE) { /* hack */
6083 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
6085 else if (code == EFBIG) {
6086 fprintf(stderr,"%s: Cache size too large.\n", pn);
6088 else if (code == ETIMEDOUT) {
6090 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
6092 fprintf(stderr,"%s: Connection timed out", pn);
6094 else if (code == EBUSY) {
6096 fprintf(stderr,"%s: All servers are busy on which '%s' resides\n", pn, filename);
6098 fprintf(stderr,"%s: All servers are busy\n", pn);
6100 else if (code == ENXIO) {
6102 fprintf(stderr,"%s: All volume instances are offline on which '%s' resides\n", pn, filename);
6104 fprintf(stderr,"%s: All volume instances are offline\n", pn);
6106 else if (code == ENOSYS) {
6108 fprintf(stderr,"%s: All servers are down on which '%s' resides\n", pn, filename);
6110 fprintf(stderr,"%s: All servers are down\n", pn);
6112 else if (code == ECHILD) { /* hack */
6114 fprintf(stderr,"%s: Invalid owner specified for '%s'\n", pn, filename);
6116 fprintf(stderr,"%s: Invalid owner specified\n", pn);
6120 fprintf(stderr,"%s:'%s'", pn, filename);
6122 fprintf(stderr,"%s", pn);
6124 fprintf(stderr, ": code 0x%x\n", code);
6125 #else /* not WIN32 */
6126 fprintf(stderr,": %s\n", afs_error_message(code));
6127 #endif /* not WIN32 */