2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afs/param.h>
12 #include <afs/com_err.h>
24 #include <rx/rx_globals.h>
28 #include <afs/afs_consts.h>
29 #include <afs/cellconfig.h>
30 #include <afs/ptserver.h>
31 #include <afs/ptuser.h>
32 #include <afs/volser.h>
33 #include <WINNT\afsreg.h>
42 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
43 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
44 #define CELL_MAXNAMELEN 256
45 #define MAXHOSTCHARS 64
47 static char space[AFS_PIOCTL_MAXSIZE];
48 static char tspace[1024];
50 static struct ubik_client *uclient;
52 static int GetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
53 static int SetClientAddrsCmd(struct cmd_syndesc *asp, void *arock);
54 static int FlushMountCmd(struct cmd_syndesc *asp, void *arock);
55 static int RxStatProcCmd(struct cmd_syndesc *asp, void *arock);
56 static int RxStatPeerCmd(struct cmd_syndesc *asp, void *arock);
58 extern struct cmd_syndesc *cmd_CreateSyntax();
60 static int MemDumpCmd(struct cmd_syndesc *asp, void *arock);
61 static int CSCPolicyCmd(struct cmd_syndesc *asp, void *arock);
62 static int MiniDumpCmd(struct cmd_syndesc *asp, void *arock);
64 static char pn[] = "fs";
65 static int rxInitDone = 0;
68 * Character to use between name and rights in printed representation for
71 #define DFS_SEPARATOR ' '
73 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
76 int dfs; /* Originally true if a dfs acl; now also the type
77 * of the acl (1, 2, or 3, corresponding to object,
78 * initial dir, or initial object). */
79 sec_rgy_name_t cell; /* DFS cell name */
82 struct AclEntry *pluslist;
83 struct AclEntry *minuslist;
87 struct AclEntry *next;
93 ZapAcl (struct Acl *acl)
98 ZapList(acl->pluslist);
99 ZapList(acl->minuslist);
104 * Mods for the AFS/DFS protocol translator.
106 * DFS rights. It's ugly to put these definitions here, but they
107 * *cannot* change, because they're part of the wire protocol.
108 * In any event, the protocol translator will guarantee these
109 * assignments for AFS cache managers.
111 #define DFS_READ 0x01
112 #define DFS_WRITE 0x02
113 #define DFS_EXECUTE 0x04
114 #define DFS_CONTROL 0x08
115 #define DFS_INSERT 0x10
116 #define DFS_DELETE 0x20
118 /* the application definable ones (backwards from AFS) */
119 #define DFS_USR0 0x80000000 /* "A" bit */
120 #define DFS_USR1 0x40000000 /* "B" bit */
121 #define DFS_USR2 0x20000000 /* "C" bit */
122 #define DFS_USR3 0x10000000 /* "D" bit */
123 #define DFS_USR4 0x08000000 /* "E" bit */
124 #define DFS_USR5 0x04000000 /* "F" bit */
125 #define DFS_USR6 0x02000000 /* "G" bit */
126 #define DFS_USR7 0x01000000 /* "H" bit */
127 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
128 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
131 * Offset of -id switch in command structure for various commands.
132 * The -if switch is the next switch always.
134 static int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
137 * Determine whether either the -id or -if switches are present, and
138 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
140 /* int id; Offset of -id switch; -if is next switch */
142 getidf(struct cmd_syndesc *as, int id)
146 if (as->parms[id].items) {
149 if (as->parms[id + 1].items) {
154 "%s: you may specify either -id or -if, but not both switches\n",
162 PRights(afs_int32 arights, int dfs)
165 if (arights & PRSFS_READ)
167 if (arights & PRSFS_LOOKUP)
169 if (arights & PRSFS_INSERT)
171 if (arights & PRSFS_DELETE)
173 if (arights & PRSFS_WRITE)
175 if (arights & PRSFS_LOCK)
177 if (arights & PRSFS_ADMINISTER)
179 if (arights & PRSFS_USR0)
181 if (arights & PRSFS_USR1)
183 if (arights & PRSFS_USR2)
185 if (arights & PRSFS_USR3)
187 if (arights & PRSFS_USR4)
189 if (arights & PRSFS_USR5)
191 if (arights & PRSFS_USR6)
193 if (arights & PRSFS_USR7)
196 if (arights & DFS_READ)
200 if (arights & DFS_WRITE)
204 if (arights & DFS_EXECUTE)
208 if (arights & DFS_CONTROL)
212 if (arights & DFS_INSERT)
216 if (arights & DFS_DELETE)
220 if (arights & (DFS_USRALL))
222 if (arights & DFS_USR0)
224 if (arights & DFS_USR1)
226 if (arights & DFS_USR2)
228 if (arights & DFS_USR3)
230 if (arights & DFS_USR4)
232 if (arights & DFS_USR5)
234 if (arights & DFS_USR6)
236 if (arights & DFS_USR7)
242 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
246 struct ViceIoctl blob;
247 cm_ioctlQueryOptions_t options;
251 memset(&options, 0, sizeof(options));
252 options.size = sizeof(options);
253 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
255 blob.in_size = options.size; /* no variable length data */
257 blob.out_size = sizeof(cm_fid_t);
258 blob.out = (char *) &fid;
260 code = pioctl_utf8(apath, VIOCGETFID, &blob, 1);
262 if ((errno == EINVAL) || (errno == ENOENT))
269 IsFreelanceRoot(char *apath)
271 struct ViceIoctl blob;
275 blob.out_size = AFS_PIOCTL_MAXSIZE;
278 code = pioctl_utf8(apath, VIOC_FILE_CELL_NAME, &blob, 1);
280 return !cm_strnicmp_utf8N("Freelance.Local.Root",space, blob.out_size);
282 return 1; /* assume it is because it is more restrictive that way */
285 /* return a static pointer to a buffer */
290 if( FAILED(StringCbCopy(tspace, sizeof(tspace), apath))) {
291 fprintf (stderr, "tspace - not enough space");
294 tp = strrchr(tspace, '\\');
296 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
299 fs_ExtractDriveLetter(apath, tspace);
300 if( FAILED(StringCbCat(tspace, sizeof(tspace), "."))) {
301 fprintf (stderr, "tspace - not enough space");
308 enum rtype {add, destroy, deny};
311 Convert(char *arights, int dfs, enum rtype *rtypep)
316 *rtypep = add; /* add rights, by default */
319 if (!strcmp(arights, "null")) {
323 if (!strcmp(arights,"read"))
324 return DFS_READ | DFS_EXECUTE;
325 if (!strcmp(arights, "write"))
326 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
328 if (!strcmp(arights, "all"))
329 return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE |
330 DFS_WRITE | DFS_CONTROL;
332 if (!strcmp(arights,"read"))
333 return PRSFS_READ | PRSFS_LOOKUP;
334 if (!strcmp(arights, "write"))
335 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
336 PRSFS_WRITE | PRSFS_LOCK;
337 if (!strcmp(arights, "mail"))
338 return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
339 if (!strcmp(arights, "all"))
340 return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE |
341 PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
343 if (!strcmp(arights, "none")) {
344 *rtypep = destroy; /* Remove entire entry */
348 for(; (tc = *arights) != '\0'; arights++) {
381 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n",
389 mode |= PRSFS_LOOKUP;
391 mode |= PRSFS_INSERT;
393 mode |= PRSFS_DELETE;
399 mode |= PRSFS_ADMINISTER;
417 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn,
426 static struct AclEntry *
427 FindList (struct AclEntry *alist, char *aname)
430 if (!strcasecmp(alist->name, aname))
437 /* if no parm specified in a particular slot, set parm to be "." instead */
439 SetDotDefault(struct cmd_item **aitemp)
445 return; /* already has value */
446 /* otherwise, allocate an item representing "." */
447 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
449 ti->next = (struct cmd_item *) 0;
450 ti->data = (char *) malloc(len_data);
452 if( FAILED(StringCbCopy(ti->data, len_data, "."))) {
453 fprintf (stderr, "data - not enough space");
460 ChangeList (struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights)
462 struct AclEntry *tlist;
463 tlist = (plus ? al->pluslist : al->minuslist);
464 tlist = FindList (tlist, aname);
466 /* Found the item already in the list. */
467 tlist->rights = arights;
469 al->nplus -= PruneList(&al->pluslist, al->dfs);
471 al->nminus -= PruneList(&al->minuslist, al->dfs);
474 /* Otherwise we make a new item and plug in the new data. */
475 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
477 if( FAILED(StringCbCopy(tlist->name, sizeof(tlist->name), aname))) {
478 fprintf (stderr, "name - not enough space");
481 tlist->rights = arights;
483 tlist->next = al->pluslist;
484 al->pluslist = tlist;
486 if (arights == 0 || arights == -1)
487 al->nplus -= PruneList(&al->pluslist, al->dfs);
489 tlist->next = al->minuslist;
490 al->minuslist = tlist;
493 al->nminus -= PruneList(&al->minuslist, al->dfs);
498 ZapList (struct AclEntry *alist)
500 struct AclEntry *tp, *np;
501 for (tp = alist; tp; tp = np) {
508 PruneList (struct AclEntry **ae, int dfs)
510 struct AclEntry **lp;
511 struct AclEntry *te, *ne;
515 for(te = *ae;te;te=ne) {
516 if ((!dfs && te->rights == 0) || te->rights == -1) {
530 SkipLine (char *astr)
539 * Create an empty acl, taking into account whether the acl pointed
540 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
541 * can recover from problems caused by bogus ACL's (in that case, always
542 * assume that the acl is AFS: for DFS, the user can always resort to
543 * acl_edit, but for AFS there may be no other way out).
551 tp = (struct Acl *)malloc(sizeof (struct Acl));
553 tp->nplus = tp->nminus = 0;
554 tp->pluslist = tp->minuslist = 0;
557 if (astr == NULL || sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell) <= 0) {
562 if (astr == NULL || sscanf_s(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell, sizeof(tp->cell)) <= 0) {
571 ParseAcl (char *astr, int astr_size)
573 int nplus, nminus, i, trights, ret;
576 struct AclEntry *first, *next, *last, *tl;
580 if( FAILED(StringCbLength(astr, astr_size, &len))) {
581 fprintf (stderr, "StringCbLength failure on astr");
584 if (astr == NULL || len == 0)
588 ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
590 ret = sscanf_s(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell, sizeof(ta->cell));
596 astr = SkipLine(astr);
598 ret = sscanf(astr, "%d", &ta->nminus);
600 ret = sscanf_s(astr, "%d", &ta->nminus);
606 astr = SkipLine(astr);
613 for(i=0;i<nplus;i++) {
615 ret = sscanf(astr, "%100s %d", tname, &trights);
617 ret = sscanf_s(astr, "%100s %d", tname, sizeof(tname), &trights);
621 astr = SkipLine(astr);
622 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
627 if( FAILED(StringCbCopy(tl->name, sizeof(tl->name), tname))) {
628 fprintf (stderr, "name - not enough space");
631 tl->rights = trights;
637 ta->pluslist = first;
641 for(i=0;i<nminus;i++) {
643 ret = sscanf(astr, "%100s %d", tname, &trights);
645 ret = sscanf_s(astr, "%100s %d", tname, sizeof(tname), &trights);
649 astr = SkipLine(astr);
650 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
655 if( FAILED(StringCbCopy(tl->name, sizeof(tl->name), tname))) {
656 fprintf (stderr, "name - not enough space");
659 tl->rights = trights;
665 ta->minuslist = first;
670 for (;first; first = next) {
674 first = ta->pluslist;
677 for (;first; first = next) {
686 PrintStatus(VolumeStatus *status, char *name, char *motd, char *offmsg)
688 printf("Volume status for vid = %u named %s is\n",status->Vid, name);
690 printf("Current offline message is %s\n",offmsg);
692 printf("Current message of the day is %s\n",motd);
693 printf("Current disk quota is ");
694 if (status->MaxQuota != 0)
695 printf("%d\n", status->MaxQuota);
697 printf("unlimited\n");
698 printf("Current blocks used are %d\n",status->BlocksInUse);
699 printf("The partition has %d blocks available out of %d\n",
700 status->PartBlocksAvail, status->PartMaxBlocks);
705 QuickPrintStatus(VolumeStatus *status, char *name)
707 double QuotaUsed =0.0;
708 double PartUsed =0.0;
710 printf("%-25.25s",name);
712 if (status->MaxQuota != 0) {
713 printf(" %10d %10d", status->MaxQuota, status->BlocksInUse);
714 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
716 printf(" no limit %10d", status->BlocksInUse);
718 if (QuotaUsed > 90.0){
719 printf(" %5.0f%%<<", QuotaUsed);
722 printf(" %5.0f%% ", QuotaUsed);
723 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
724 if (PartUsed > 97.0){
725 printf(" %9.0f%%<<", PartUsed);
728 printf(" %9.0f%% ", PartUsed);
730 printf(" <<WARNING\n");
737 QuickPrintSpace(VolumeStatus *status, char *name)
739 double PartUsed =0.0;
741 printf("%-25.25s",name);
743 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
745 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
746 if (PartUsed > 90.0){
747 printf(" %4.0f%%<<", PartUsed);
750 printf(" %4.0f%% ", PartUsed);
752 printf(" <<WARNING\n");
759 AclToString(struct Acl *acl)
761 static char mydata[AFS_PIOCTL_MAXSIZE];
762 char tstring[AFS_PIOCTL_MAXSIZE];
767 if( FAILED(StringCbPrintf(dfsstring, sizeof(dfsstring), " dfs:%d %s", acl->dfs, acl->cell))) {
768 fprintf (stderr, "dfsstring - cannot be populated");
774 if( FAILED(StringCbPrintf(mydata, sizeof(mydata), "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus))) {
775 fprintf (stderr, "mydata - cannot be populated");
778 for (tp = acl->pluslist;tp;tp=tp->next) {
779 if( FAILED(StringCbPrintf(tstring, sizeof(tstring), "%s %d\n", tp->name, tp->rights))) {
780 fprintf (stderr, "tstring - cannot be populated");
783 if( FAILED(StringCbCat(mydata, sizeof(mydata), tstring))) {
784 fprintf (stderr, "mydata - not enough space");
788 for (tp = acl->minuslist;tp;tp=tp->next) {
789 if( FAILED(StringCbPrintf(tstring, sizeof(tstring), "%s %d\n", tp->name, tp->rights))) {
790 fprintf (stderr, "tstring - cannot be populated");
793 if( FAILED(StringCbCat(mydata, sizeof(mydata), tstring))) {
794 fprintf (stderr, "mydata - not enough space");
801 static DWORD IsFreelance(void)
808 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
809 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
810 if (code == ERROR_SUCCESS) {
811 dummyLen = sizeof(cm_freelanceEnabled);
812 code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
813 (BYTE *) &enabled, &dummyLen);
814 RegCloseKey (parmKey);
819 #define NETBIOSNAMESZ 1024
820 static const char * NetbiosName(void)
822 static char buffer[NETBIOSNAMESZ] = "AFS";
828 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
829 0, (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &parmKey);
830 if (code == ERROR_SUCCESS) {
831 dummyLen = sizeof(buffer);
832 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
834 RegCloseKey (parmKey);
836 if( FAILED(StringCbCopy(buffer, sizeof(buffer), "AFS"))) {
837 fprintf (stderr, "buffer - not enough space");
844 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
846 static BOOL IsAdmin (void)
848 static BOOL fAdmin = FALSE;
849 static BOOL fTested = FALSE;
853 /* Obtain the SID for the AFS client admin group. If the group does
854 * not exist, then assume we have AFS client admin privileges.
856 PSID psidAdmin = NULL;
857 DWORD dwSize, dwSize2;
858 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
859 char *pszRefDomain = NULL;
860 SID_NAME_USE snu = SidTypeGroup;
862 dwSize = sizeof(pszAdminGroup);
864 if (!GetComputerName(pszAdminGroup, &dwSize)) {
865 /* Can't get computer name. We return false in this case.
866 Retain fAdmin and fTested. This shouldn't happen.*/
873 if( FAILED(StringCbCat(pszAdminGroup, MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2,"\\"))) {
874 fprintf (stderr, "pszAdminGroup - not enough space");
877 if( FAILED(StringCbCat(pszAdminGroup, MAX_COMPUTERNAME_LENGTH +
878 sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2, AFSCLIENT_ADMIN_GROUPNAME))) {
879 fprintf (stderr, "pszAdminGroup - not enough space");
883 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
884 /* that should always fail. */
886 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
887 /* if we can't find the group, then we allow the operation */
892 if (dwSize == 0 || dwSize2 == 0) {
898 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
900 pszRefDomain = (char *)malloc(dwSize2);
901 assert(pszRefDomain);
903 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
904 /* We can't lookup the group now even though we looked it up earlier.
905 Could this happen? */
908 /* Then open our current ProcessToken */
911 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
914 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
915 /* We'll have to allocate a chunk of memory to store the list of
916 * groups to which this user belongs; find out how much memory
920 PTOKEN_GROUPS pGroups;
922 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
924 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
927 /* Allocate that buffer, and read in the list of groups. */
928 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
930 /* Look through the list of group SIDs and see if any of them
931 * matches the AFS Client Admin group SID.
934 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
936 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
946 /* if do not have permission because we were not explicitly listed
947 * in the Admin Client Group let's see if we are the SYSTEM account
950 PTOKEN_USER pTokenUser;
951 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
952 PSID pSidLocalSystem = 0;
955 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
957 pTokenUser = (PTOKEN_USER)malloc(dwSize);
960 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
961 gle = GetLastError();
963 if (AllocateAndInitializeSid( &SIDAuth, 1,
964 SECURITY_LOCAL_SYSTEM_RID,
968 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
972 FreeSid(pSidLocalSystem);
991 SetACLCmd(struct cmd_syndesc *as, void *arock)
994 struct ViceIoctl blob;
996 struct cmd_item *ti, *ui;
1000 int idf = getidf(as, parm_setacl_id);
1004 if (as->parms[2].items)
1008 plusp = !(as->parms[3].items);
1009 for(ti=as->parms[0].items; ti;ti=ti->next) {
1010 if ( IsFreelanceRoot(ti->data) ) {
1011 fprintf(stderr,"%s: ACLs cannot be set on the Freelance root.afs volume.\n", pn);
1015 blob.out_size = AFS_PIOCTL_MAXSIZE;
1017 blob.in = blob.out = space;
1018 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1020 Die(errno, ti->data);
1026 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1029 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1034 if (!plusp && ta->dfs) {
1036 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
1038 "(you may specify \"null\" to revoke all rights, however)\n");
1045 ta = EmptyAcl(space);
1047 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1050 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1055 CleanAcl(ta, ti->data);
1056 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
1060 "%s: Missing second half of user/access pair.\n", pn);
1064 rights = Convert(ui->next->data, ta->dfs, &rtype);
1065 if (rtype == destroy && !ta->dfs) {
1066 struct AclEntry *tlist;
1068 tlist = (plusp ? ta->pluslist : ta->minuslist);
1069 if (!FindList(tlist, ui->data))
1072 if (rtype == deny && !ta->dfs)
1074 if (rtype == destroy && ta->dfs)
1076 ChangeList(ta, plusp, ui->data, rights);
1078 blob.in = AclToString(ta);
1080 if( FAILED(StringCbLength(blob.in, sizeof(space), &len))) {
1081 fprintf (stderr, "StringCbLength failure on blob.in");
1084 blob.in_size = 1+(long)len;
1085 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1087 if (errno == EINVAL) {
1089 static char *fsenv = 0;
1091 fsenv = (char *)getenv("FS_EXPERT");
1093 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
1096 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
1097 "\nPossible reasons for this include:\n\n",
1098 " -You may have specified an inappropriate combination of rights.\n",
1099 " For example, some DFS-supported filesystems may not allow you to\n",
1100 " drop the \"c\" right from \"user_obj\".\n\n",
1101 " -A mask_obj may be required (it is likely required by the underlying\n",
1102 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
1103 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
1104 " does not automatically create or update the mask_obj. Try setting\n",
1105 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
1106 " users or groups. You can do this with a single command, such as\n",
1107 " \"fs sa mask_obj all user:somename read\"\n\n",
1108 " -A specified user or group may not exist.\n\n",
1109 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
1110 " This is probably not allowed by the underlying file system.\n\n",
1111 " -If you add a user or group to a DFS ACL, remember that it must be\n",
1112 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
1113 " may be local requirements on the format of the user or group name.\n",
1114 " Check with your cell administrator.\n\n",
1115 " -Or numerous other possibilities. It would be great if we could be more\n",
1116 " precise about the actual problem, but for various reasons, this is\n",
1117 " impractical via this interface. If you can't figure it out, you\n",
1118 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
1119 " whatever is provided). You may get better results. Good luck!\n\n",
1120 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
1124 "%s: Invalid argument, possible reasons include:\n",
1126 fprintf(stderr,"\t-File not in AFS\n");
1128 "\t-Too many users on access control list\n");
1130 "\t-Tried to add non-existent user to access control list\n");
1133 Die(errno, ti->data);
1144 CopyACLCmd(struct cmd_syndesc *as, void *arock)
1147 struct ViceIoctl blob;
1148 struct Acl *fa, *ta = 0;
1149 struct AclEntry *tp;
1150 struct cmd_item *ti;
1152 int idf = getidf(as, parm_copyacl_id);
1156 if (as->parms[2].items)
1160 blob.out_size = AFS_PIOCTL_MAXSIZE;
1162 blob.in = blob.out = space;
1163 code = pioctl_utf8(as->parms[0].items->data, VIOCGETAL, &blob, 1);
1165 Die(errno, as->parms[0].items->data);
1168 fa = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1171 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1172 as->parms[0].items->data);
1175 CleanAcl(fa, as->parms[0].items->data);
1176 for (ti=as->parms[1].items; ti;ti=ti->next) {
1177 blob.out_size = AFS_PIOCTL_MAXSIZE;
1179 blob.in = blob.out = space;
1180 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1182 Die(errno, ti->data);
1189 ta = EmptyAcl(space);
1191 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1194 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1199 CleanAcl(ta, ti->data);
1200 if (ta->dfs != fa->dfs) {
1202 "%s: incompatible file system types: acl not copied to %s; aborted\n",
1208 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
1210 "%s: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n",
1215 if( FAILED(StringCbCopy(ta->cell, sizeof(ta->cell), fa->cell))) {
1216 fprintf (stderr, "cell - not enough space");
1220 for (tp = fa->pluslist;tp;tp=tp->next)
1221 ChangeList(ta, 1, tp->name, tp->rights);
1222 for (tp = fa->minuslist;tp;tp=tp->next)
1223 ChangeList(ta, 0, tp->name, tp->rights);
1224 blob.in = AclToString(ta);
1226 if( FAILED(StringCbLength(blob.in, sizeof(space), &len))) {
1227 fprintf (stderr, "StringCbLength failure on blob.in");
1230 blob.in_size = 1+(long)len;
1231 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1233 if (errno == EINVAL) {
1235 "%s: Invalid argument, possible reasons include:\n", pn);
1236 fprintf(stderr,"\t-File not in AFS\n");
1238 Die(errno, ti->data);
1249 /* pioctl_utf8() call to get the cellname of a pathname */
1251 GetCell(char *fname, char *cellname)
1254 struct ViceIoctl blob;
1257 blob.out_size = CELL_MAXNAMELEN;
1258 blob.out = cellname;
1260 code = pioctl_utf8(fname, VIOC_FILE_CELL_NAME, &blob, 1);
1262 cellname[blob.out_size - 1] = '\0';
1266 /* Check if a username is valid: If it contains only digits (or a
1267 * negative sign), then it might be bad. We then query the ptserver
1271 BadName(char *aname, char *fname)
1273 afs_int32 tc, code, id;
1275 char cell[CELL_MAXNAMELEN];
1278 for ( nm = aname; tc = *nm; nm++) {
1279 /* all must be '-' or digit to be bad */
1280 if (tc != '-' && (tc < '0' || tc > '9'))
1284 /* Go to the PRDB and see if this all number username is valid */
1285 code = GetCell(fname, cell);
1289 cm_GetConfigDir(confDir, sizeof(confDir));
1291 pr_Initialize(1, confDir, cell);
1292 code = pr_SNameToId(aname, &id);
1295 /* 1=>Not-valid; 0=>Valid */
1296 return ((!code && (id == ANONYMOUSID)) ? 1 : 0);
1300 /* clean up an access control list of its bad entries; return 1 if we made
1301 any changes to the list, and 0 otherwise */
1303 CleanAcl(struct Acl *aa, char *fname)
1305 struct AclEntry *te, **le, *ne;
1308 /* Don't correct DFS ACL's for now */
1312 /* prune out bad entries */
1313 changes = 0; /* count deleted entries */
1315 for(te = aa->pluslist; te; te=ne) {
1317 if (BadName(te->name, fname)) {
1327 le = &aa->minuslist;
1328 for(te = aa->minuslist; te; te=ne) {
1330 if (BadName(te->name, fname)) {
1344 /* clean up an acl to not have bogus entries */
1346 CleanACLCmd(struct cmd_syndesc *as, void *arock)
1350 struct ViceIoctl blob;
1352 struct cmd_item *ti;
1353 struct AclEntry *te;
1357 SetDotDefault(&as->parms[0].items);
1358 for(ti=as->parms[0].items; ti; ti=ti->next) {
1359 blob.out_size = AFS_PIOCTL_MAXSIZE;
1362 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1364 Die(errno, ti->data);
1370 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1373 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1380 "%s: cleanacl is not supported for DFS access lists.\n",
1386 changes = CleanAcl(ta, ti->data);
1389 /* now set the acl */
1390 blob.in=AclToString(ta);
1391 if( FAILED(StringCbLength(blob.in, sizeof(space), &len))) {
1392 fprintf (stderr, "StringCbLength failure on blob.in");
1395 blob.in_size = (long)len+1;
1397 code = pioctl_utf8(ti->data, VIOCSETAL, &blob, 1);
1399 if (errno == EINVAL) {
1401 "%s: Invalid argument, possible reasons include\n",
1403 fprintf(stderr,"%s: File not in vice or\n", pn);
1405 "%s: Too many users on access control list or\n",
1408 Die(errno, ti->data);
1414 /* now list the updated acl */
1415 printf("Access list for %s is now\n", ti->data);
1416 if (ta->nplus > 0) {
1418 printf("Normal rights:\n");
1419 for(te = ta->pluslist;te;te=te->next) {
1420 printf(" %s ", te->name);
1421 PRights(te->rights, ta->dfs);
1425 if (ta->nminus > 0) {
1426 printf("Negative rights:\n");
1427 for(te = ta->minuslist;te;te=te->next) {
1428 printf(" %s ", te->name);
1429 PRights(te->rights, ta->dfs);
1436 printf("Access list for %s is fine.\n", ti->data);
1444 ListACLCmd(struct cmd_syndesc *as, void *arock)
1448 struct ViceIoctl blob;
1449 struct AclEntry *te;
1450 struct cmd_item *ti;
1451 int idf = getidf(as, parm_listacl_id);
1454 SetDotDefault(&as->parms[0].items);
1455 for(ti=as->parms[0].items; ti; ti=ti->next) {
1458 if ( IsFreelanceRoot(ti->data) ) {
1459 fprintf(stderr,"%s: ACLs are not set on the Freelance root.afs volume.\n", pn);
1464 blob.out_size = AFS_PIOCTL_MAXSIZE;
1466 blob.in = blob.out = space;
1467 code = pioctl_utf8(ti->data, VIOCGETAL, &blob, 1);
1469 Die(errno, ti->data);
1473 ta = ParseAcl(space, AFS_PIOCTL_MAXSIZE);
1476 "fs: %s: invalid acl data returned from VIOCGETAL\n",
1481 if (as->parms[3].items) { /* -cmd */
1482 printf("fs setacl -dir %s -acl ", ti->data);
1483 if (ta->nplus > 0) {
1484 for (te = ta->pluslist; te; te = te->next) {
1485 printf(" %s ", te->name);
1486 PRights(te->rights, ta->dfs);
1490 if (ta->nminus > 0) {
1491 printf("fs setacl -dir %s -acl ", ti->data);
1492 for (te = ta->minuslist; te; te = te->next) {
1493 printf(" %s ", te->name);
1494 PRights(te->rights, ta->dfs);
1496 printf(" -negative\n");
1501 printf("Access list for %s is\n", ti->data);
1504 printf("DFS access list for %s is\n", ti->data);
1507 printf("DFS initial directory access list of %s is\n", ti->data);
1510 printf("DFS initial file access list of %s is\n", ti->data);
1514 printf(" Default cell = %s\n", ta->cell);
1516 separator = ta->dfs? DFS_SEPARATOR : ' ';
1517 if (ta->nplus > 0) {
1519 printf("Normal rights:\n");
1520 for(te = ta->pluslist;te;te=te->next) {
1521 printf(" %s%c", te->name, separator);
1522 PRights(te->rights, ta->dfs);
1526 if (ta->nminus > 0) {
1527 printf("Negative rights:\n");
1528 for(te = ta->minuslist;te;te=te->next) {
1529 printf(" %s ", te->name);
1530 PRights(te->rights, ta->dfs);
1543 FlushAllCmd(struct cmd_syndesc *as, void *arock)
1546 struct ViceIoctl blob;
1548 blob.in_size = blob.out_size = 0;
1549 code = pioctl_utf8(NULL, VIOC_FLUSHALL, &blob, 0);
1551 fprintf(stderr, "Error flushing all ");
1558 FlushVolumeCmd(struct cmd_syndesc *as, void *arock)
1561 struct ViceIoctl blob;
1562 struct cmd_item *ti;
1565 SetDotDefault(&as->parms[0].items);
1566 for(ti=as->parms[0].items; ti; ti=ti->next) {
1567 blob.in_size = blob.out_size = 0;
1568 code = pioctl_utf8(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1570 fprintf(stderr, "Error flushing volume ");
1580 FlushCmd(struct cmd_syndesc *as, void *arock)
1583 struct ViceIoctl blob;
1584 struct cmd_item *ti;
1587 cm_ioctlQueryOptions_t options;
1589 if (as->parms[1].items)
1592 for(ti=as->parms[0].items; ti; ti=ti->next) {
1594 memset(&options, 0, sizeof(options));
1595 options.size = sizeof(options);
1596 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1597 options.literal = literal;
1598 blob.in_size = options.size; /* no variable length data */
1602 code = pioctl_utf8(ti->data, VIOCFLUSH, &blob, 0);
1604 if (errno == EMFILE) {
1605 fprintf(stderr, "%s: Can't flush active file %s\n", pn,
1608 fprintf(stderr, "%s: Error flushing file ", pn);
1618 /* all this command does is repackage its args and call SetVolCmd */
1620 SetQuotaCmd(struct cmd_syndesc *as, void *arock) {
1621 struct cmd_syndesc ts;
1623 /* copy useful stuff from our command slot; we may later have to reorder */
1625 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1627 err = memcpy_s(&ts, sizeof(ts), as, sizeof(ts)); /* copy whole thing */
1629 fprintf (stderr, "memcpy_s failure on ts");
1633 return SetVolCmd(&ts, arock);
1637 SetVolCmd(struct cmd_syndesc *as, void *arock) {
1639 struct ViceIoctl blob;
1640 struct cmd_item *ti;
1641 struct VolumeStatus *status;
1642 char *motd, *offmsg, *input, *destEnd;
1643 size_t destRemaining;
1647 SetDotDefault(&as->parms[0].items);
1648 for(ti=as->parms[0].items; ti; ti=ti->next) {
1650 destRemaining = sizeof(space);
1651 blob.out_size = AFS_PIOCTL_MAXSIZE;
1652 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1655 status = (VolumeStatus *)space;
1656 status->MinQuota = status->MaxQuota = -1;
1657 motd = offmsg = NULL;
1658 if (as->parms[1].items) {
1659 code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
1661 fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
1666 if (as->parms[2].items)
1667 motd = as->parms[2].items->data;
1668 if (as->parms[3].items)
1669 offmsg = as->parms[3].items->data;
1670 input = (char *)status + sizeof(*status);
1671 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1672 destRemaining -= sizeof(*status) + 1;
1674 if( FAILED(StringCbLength(offmsg, VMSGSIZE, &len))) {
1675 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1680 if( FAILED(StringCbCopyEx(input, destRemaining, offmsg, &destEnd, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
1681 fprintf (stderr, "input - not enough space");
1684 blob.in_size += destEnd - input;
1685 input = destEnd + 1;
1686 destRemaining -= sizeof(char);
1689 destRemaining -= sizeof(char);
1692 if( FAILED(StringCbLength(motd, VMSGSIZE, &len))) {
1693 fprintf(stderr,"%s: message must be shorter than %d characters\n",
1697 if( FAILED(StringCbCopyEx(input, destRemaining, motd, &destEnd, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
1698 fprintf (stderr, "input - not enough space");
1701 blob.in_size += (long)(destEnd - input);
1702 input = destEnd + 1;
1703 destRemaining -= sizeof(char);
1706 destRemaining -= sizeof(char);
1708 code = pioctl_utf8(ti->data,VIOCSETVOLSTAT, &blob, 1);
1710 Die(errno, ti->data);
1717 /* values match cache manager File Types */
1719 filetypestr(afs_uint32 type)
1721 char * s = "Object";
1744 ExamineCmd(struct cmd_syndesc *as, void *arock)
1747 struct ViceIoctl blob;
1748 struct cmd_item *ti;
1749 struct VolumeStatus *status;
1750 char *name, *offmsg, *motd;
1753 cm_ioctlQueryOptions_t options;
1756 if (as->parms[1].items)
1759 SetDotDefault(&as->parms[0].items);
1760 for(ti=as->parms[0].items; ti; ti=ti->next) {
1762 afs_uint32 filetype;
1764 char cell[CELL_MAXNAMELEN];
1767 memset(&fid, 0, sizeof(fid));
1768 memset(&options, 0, sizeof(options));
1770 options.size = sizeof(options);
1771 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1772 options.literal = literal;
1773 blob.in_size = options.size; /* no variable length data */
1776 blob.out_size = sizeof(cm_fid_t);
1777 blob.out = (char *) &fid;
1778 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
1779 blob.out_size == sizeof(cm_fid_t)) {
1780 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1783 Die(errno, ti->data);
1788 blob.out_size = sizeof(filetype);
1789 blob.out = &filetype;
1791 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1792 if (code || blob.out_size != sizeof(filetype)) {
1793 Die(errno, ti->data);
1798 blob.out_size = CELL_MAXNAMELEN;
1801 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
1803 cell[blob.out_size-1] = '\0';
1804 printf("%s %s (%u.%u.%u) contained in cell %s\n",
1805 filetypestr(filetype),
1806 ti->data, fid.volume, fid.vnode, fid.unique,
1807 code ? "unknown-cell" : cell);
1809 blob.out_size = 2 * sizeof(afs_uint32);
1810 blob.out = (char *) &owner;
1811 if (0 == pioctl_utf8(ti->data, VIOCGETOWNER, &blob, 1) &&
1812 blob.out_size == 2 * sizeof(afs_uint32)) {
1813 char oname[PR_MAXNAMELEN] = "(unknown)";
1814 char gname[PR_MAXNAMELEN] = "(unknown)";
1817 /* Go to the PRDB and see if this all number username is valid */
1818 cm_GetConfigDir(confDir, sizeof(confDir));
1820 pr_Initialize(1, confDir, cell);
1821 pr_SIdToName(owner[0], oname);
1822 pr_SIdToName(owner[1], gname);
1823 printf("Owner %s (%d) Group %s (%d)\n", oname, owner[0], gname, owner[1]);
1827 blob.out_size = AFS_PIOCTL_MAXSIZE;
1828 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1830 space[blob.out_size - 1] = '\0';
1831 status = (VolumeStatus *)space;
1832 name = (char *)status + sizeof(*status);
1833 if( FAILED(StringCbLength(name, sizeof(space) - (name - space), &len))) {
1834 fprintf (stderr, "StringCbLength failure on name");
1837 offmsg = name + len + 1;
1838 if( FAILED(StringCbLength(offmsg, sizeof(space) - (offmsg - space), &len))) {
1839 fprintf (stderr, "StringCbLength failure on offmsg");
1842 motd = offmsg + len + 1;
1843 PrintStatus(status, name, motd, offmsg);
1845 Die(errno, ti->data);
1849 code = pioctl_utf8(ti->data, VIOC_PATH_AVAILABILITY, &blob, 1);
1852 printf("Volume is online\n");
1855 printf("Volume is offline\n");
1858 printf("All Volume servers are down\n");
1861 printf("All volume servers are busy\n");
1864 printf("Unknown volume state\n");
1865 Die(errno, ti->data);
1873 ListQuotaCmd(struct cmd_syndesc *as, void *arock)
1876 struct ViceIoctl blob;
1877 struct cmd_item *ti;
1878 struct VolumeStatus *status;
1883 printf("%-25s%-11s%-11s%-7s%-13s\n", "Volume Name", " Quota",
1884 " Used", " %Used", " Partition");
1885 SetDotDefault(&as->parms[0].items);
1886 for(ti=as->parms[0].items; ti; ti=ti->next) {
1888 blob.out_size = AFS_PIOCTL_MAXSIZE;
1891 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
1893 Die(errno, ti->data);
1897 space[blob.out_size - 1] = '\0';
1898 status = (VolumeStatus *)space;
1899 name = (char *)status + sizeof(*status);
1900 QuickPrintStatus(status, name);
1906 WhereIsCmd(struct cmd_syndesc *as, void *arock)
1909 struct ViceIoctl blob;
1910 struct cmd_item *ti;
1916 cm_ioctlQueryOptions_t options;
1918 if (as->parms[1].items)
1921 SetDotDefault(&as->parms[0].items);
1922 for(ti=as->parms[0].items; ti; ti=ti->next) {
1924 afs_uint32 filetype;
1927 memset(&fid, 0, sizeof(fid));
1928 memset(&options, 0, sizeof(options));
1930 options.size = sizeof(options);
1931 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
1932 options.literal = literal;
1933 blob.in_size = options.size; /* no variable length data */
1936 blob.out_size = sizeof(cm_fid_t);
1937 blob.out = (char *) &fid;
1938 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
1939 blob.out_size == sizeof(cm_fid_t)) {
1940 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
1943 Die(errno, ti->data);
1948 blob.out_size = sizeof(filetype);
1949 blob.out = &filetype;
1951 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
1952 if (code || blob.out_size != sizeof(filetype)) {
1953 Die(errno, ti->data);
1957 blob.out_size = AFS_PIOCTL_MAXSIZE;
1959 memset(space, 0, sizeof(space));
1960 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
1962 Die(errno, ti->data);
1966 hosts = (afs_int32 *) space;
1967 printf("%s %s is on host%s ",
1968 filetypestr(filetype),
1970 (hosts[0] && !hosts[1]) ? "": "s");
1971 for(j=0; j<AFS_MAXHOSTS; j++) {
1974 tp = hostutil_GetNameByINet(hosts[j]);
1984 DiskFreeCmd(struct cmd_syndesc *as, void *arock)
1987 struct ViceIoctl blob;
1988 struct cmd_item *ti;
1990 struct VolumeStatus *status;
1993 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1994 " used", " avail", " %used");
1995 SetDotDefault(&as->parms[0].items);
1996 for(ti=as->parms[0].items; ti; ti=ti->next) {
1998 blob.out_size = AFS_PIOCTL_MAXSIZE;
2001 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
2003 Die(errno, ti->data);
2007 space[blob.out_size - 1] = '\0';
2008 status = (VolumeStatus *)space;
2009 name = (char *)status + sizeof(*status);
2010 QuickPrintSpace(status, name);
2016 QuotaCmd(struct cmd_syndesc *as, void *arock)
2019 struct ViceIoctl blob;
2020 struct cmd_item *ti;
2022 struct VolumeStatus *status;
2025 SetDotDefault(&as->parms[0].items);
2026 for(ti=as->parms[0].items; ti; ti=ti->next) {
2028 blob.out_size = AFS_PIOCTL_MAXSIZE;
2031 code = pioctl_utf8(ti->data, VIOCGETVOLSTAT, &blob, 1);
2033 * The response is VolumeStatus, volume name, offline message, and motd
2035 if (code || blob.out_size < sizeof(*status)) {
2036 Die(errno, ti->data);
2041 status = (VolumeStatus *)space;
2042 if (status->MaxQuota)
2043 quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
2046 printf("%2.0f%% of quota used.\n", quotaPct);
2052 ListMountCmd(struct cmd_syndesc *as, void *arock)
2055 struct ViceIoctl blob;
2056 struct cmd_item *ti;
2057 char orig_name[1024]; /*Original name, may be modified*/
2058 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
2059 char parent_dir[1024]; /*Parent directory of true name*/
2060 char *last_component; /*Last component of true name*/
2064 struct stat statbuff; /*Buffer for status info*/
2065 #endif /* not WIN32 */
2067 int link_chars_read; /*Num chars read in readlink()*/
2068 #endif /* not WIN32 */
2069 int thru_symlink; /*Did we get to a mount point via a symlink?*/
2072 for(ti=as->parms[0].items; ti; ti=ti->next) {
2076 if( FAILED(StringCbCopy(orig_name, sizeof(orig_name), ti->data))) {
2077 fprintf (stderr, "orig_name - not enough space");
2080 #else /* not WIN32 */
2082 if( FAILED(StringCbPrintf(orig_name, sizeof(orig_name), "%s%s",
2083 (ti->data[0] == '/') ? "" : "./",
2085 fprintf (stderr, "orig_name - cannot be populated");
2088 #endif /* not WIN32 */
2091 if (lstat(orig_name, &statbuff) < 0) {
2092 /* if lstat fails, we should still try the pioctl, since it
2093 * may work (for example, lstat will fail, but pioctl will
2094 * work if the volume of offline (returning ENODEV). */
2095 statbuff.st_mode = S_IFDIR; /* lie like pros */
2099 * The lstat succeeded. If the given file is a symlink, substitute
2100 * the file name with the link name.
2102 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
2105 * Read name of resolved file.
2107 link_chars_read = readlink(orig_name, true_name, 1024);
2108 if (link_chars_read <= 0) {
2110 "%s: Can't read target name for '%s' symbolic link!\n",
2117 * Add a trailing null to what was read, bump the length.
2119 true_name[link_chars_read++] = 0;
2122 * If the symlink is an absolute pathname, we're fine. Otherwise, we
2123 * have to create a full pathname using the original name and the
2124 * relative symlink name. Find the rightmost slash in the original
2125 * name (we know there is one) and splice in the symlink value.
2127 if (true_name[0] != '\\') {
2128 last_component = (char *) strrchr(orig_name, '\\');
2129 if( FAILED(StringCbCopy(++last_component, sizeof(orig_name) - (last_component - orig_name) * sizeof(char), true_name))) {
2130 fprintf (stderr, "last_component - not enough space");
2133 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
2134 fprintf (stderr, "true_name - not enough space");
2139 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
2140 fprintf (stderr, "true_name - not enough space");
2145 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
2146 fprintf (stderr, "true_name - not enough space");
2152 * Find rightmost slash, if any.
2155 last_component = (char *) strrchr(true_name, '\\');
2156 if (!last_component)
2158 last_component = (char *) strrchr(true_name, '/');
2159 if (last_component) {
2161 * Found it. Designate everything before it as the parent directory,
2162 * everything after it as the final component.
2164 if( FAILED(StringCchCopyN(parent_dir, sizeof(parent_dir) / sizeof(char), true_name, last_component - true_name + 1))) {
2165 fprintf (stderr, "parent_dir - not enough space");
2168 parent_dir[last_component - true_name + 1] = 0;
2169 last_component++; /*Skip the slash*/
2171 if (!InAFS(parent_dir)) {
2172 const char * nbname = NetbiosName();
2173 if( FAILED(StringCbLength(nbname, NETBIOSNAMESZ, &len))) {
2174 fprintf (stderr, "StringCbLength failure on nbname");
2177 if (parent_dir[0] == '\\' && parent_dir[1] == '\\' &&
2178 parent_dir[len+2] == '\\' &&
2179 parent_dir[len+3] == '\0' &&
2180 !strnicmp(nbname,&parent_dir[2],len))
2182 if( FAILED(StringCbPrintf(parent_dir, sizeof(parent_dir),"\\\\%s\\all\\", nbname))) {
2183 fprintf (stderr, "parent_dir - cannot be populated");
2191 * No slash appears in the given file name. Set parent_dir to the current
2192 * directory, and the last component as the given name.
2194 fs_ExtractDriveLetter(true_name, parent_dir);
2195 if( FAILED(StringCbCat(parent_dir, sizeof(parent_dir), "."))) {
2196 fprintf (stderr, "parent_dir - not enough space");
2199 last_component = true_name;
2200 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
2203 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
2204 fprintf(stderr,"%s: you may not use '.' or '..' as the last component\n",pn);
2205 fprintf(stderr,"%s: of a name in the 'fs lsmount' command.\n",pn);
2210 blob.in = last_component;
2211 if( FAILED(StringCchLength(last_component, sizeof(true_name) / sizeof(char) - (last_component - true_name), &len))) {
2212 fprintf (stderr, "StringCbLength failure on last_component");
2215 blob.in_size = (long)len+1;
2216 blob.out_size = AFS_PIOCTL_MAXSIZE;
2218 memset(space, 0, AFS_PIOCTL_MAXSIZE);
2220 code = pioctl_utf8(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
2223 printf("'%s' is a %smount point for volume '%.*s'\n",
2225 (thru_symlink ? "symbolic link, leading to a " : ""),
2230 if (errno == EINVAL) {
2231 fprintf(stderr,"'%s' is not a mount point.\n", ti->data);
2233 Die(errno, (ti->data ? ti->data : parent_dir));
2242 MakeMountCmd(struct cmd_syndesc *as, void *arock)
2245 char *cellName, *volName, *tmpName;
2247 char localCellName[128];
2249 char path[1024] = "";
2250 struct afsconf_cell info;
2251 struct vldbentry vldbEntry;
2252 struct ViceIoctl blob;
2256 memset(&info, 0, sizeof(info));
2258 if (as->parms[2].items) /* cell name specified */
2259 cellName = as->parms[2].items->data;
2262 volName = as->parms[1].items->data;
2263 if( FAILED(StringCbLength(volName, VL_MAXNAMELEN, &len))) {
2264 fprintf(stderr,"%s: volume name too long (length must be <= 64 characters)\n", pn);
2268 /* Check for a cellname in the volume specification, and complain
2269 * if it doesn't match what was specified with -cell */
2270 if (tmpName = strchr(volName, ':')) {
2273 if (strcasecmp(cellName,volName)) {
2274 fprintf(stderr,"fs: cellnames do not match.\n");
2279 volName = ++tmpName;
2282 parent = Parent(as->parms[0].items->data);
2283 if (!InAFS(parent)) {
2285 const char * nbname = NetbiosName();
2286 if ( FAILED(StringCbLength(nbname, NETBIOSNAMESZ, &len))) {
2287 fprintf (stderr, "StringCbLength failure on nbname");
2290 if (parent[0] == '\\' && parent[1] == '\\' &&
2291 parent[len+2] == '\\' &&
2292 parent[len+3] == '\0' &&
2293 !strnicmp(nbname,&parent[2],len))
2295 if( FAILED(StringCbPrintf(path, sizeof(path),"%sall\\%s", parent, &as->parms[0].items->data[len+2]))) {
2296 fprintf (stderr, "path - cannot be populated");
2299 parent = Parent(path);
2300 if (!InAFS(parent)) {
2301 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2307 fprintf(stderr,"%s: mount points must be created within the AFS file system\n", pn);
2312 if( FAILED(StringCbLength(path, sizeof(path), &len))) {
2313 fprintf (stderr, "StringCbLength failure on path");
2317 if( FAILED(StringCbCopy(path, sizeof(path), as->parms[0].items->data))) {
2318 fprintf (stderr, "path - not enough space");
2322 if ( IsFreelanceRoot(parent) ) {
2324 fprintf(stderr,"%s: Only AFS Client Administrators may alter the Freelance root.afs volume\n", pn);
2330 blob.out_size = sizeof(localCellName);
2331 blob.out = localCellName;
2332 code = pioctl_utf8(parent, VIOC_GET_WS_CELL, &blob, 1);
2334 localCellName[sizeof(localCellName) - 1] = '\0';
2335 cellName = localCellName;
2340 code = GetCell(parent,space);
2346 code = GetCellName(cellName?cellName:space, &info);
2350 if (!(as->parms[4].items)) {
2351 /* not fast, check which cell the mountpoint is being created in */
2353 /* not fast, check name with VLDB */
2355 code = VLDBInit(1, &info);
2357 /* make the check. Don't complain if there are problems with init */
2358 code = ubik_VL_GetEntryByNameO(uclient, 0, volName, &vldbEntry);
2359 if (code == VL_NOENT) {
2360 fprintf(stderr,"%s: warning, volume %s does not exist in cell %s.\n",
2361 pn, volName, cellName ? cellName : space);
2366 if (as->parms[3].items) { /* if -rw specified */
2367 if( FAILED(StringCbCopy(space, sizeof(space), "%"))) {
2368 fprintf (stderr, "space arr - not enough space");
2372 if( FAILED(StringCbCopy(space, sizeof(space), "#"))) {
2373 fprintf (stderr, "space arr - not enough space");
2378 /* cellular mount point, prepend cell prefix */
2379 if( FAILED(StringCbCat(space, sizeof(space), info.name))) {
2380 fprintf (stderr, "space arr - not enough space");
2383 if( FAILED(StringCbCat(space, sizeof(space), ":"))) {
2384 fprintf (stderr, "space arr - not enough space");
2388 if( FAILED(StringCbCat(space, sizeof(space), volName))) { /* append volume name */
2389 fprintf (stderr, "space arr - not enough space");
2392 if( FAILED(StringCbCat(space, sizeof(space), "."))) { /* stupid convention; these end with a period */
2393 fprintf (stderr, "space arr - not enough space");
2397 /* create symlink with a special pioctl for Windows NT, since it doesn't
2398 * have a symlink system call.
2401 if( FAILED(StringCbLength(space, sizeof(space), &len))) {
2402 fprintf (stderr, "StringCbLength failure on space");
2405 blob.in_size = 1 + (long)len;
2408 code = pioctl_utf8(path, VIOC_AFS_CREATE_MT_PT, &blob, 0);
2409 #else /* not WIN32 */
2410 code = symlink(space, path);
2411 #endif /* not WIN32 */
2413 if (info.linkedCell)
2414 free(info.linkedCell);
2424 * Delete AFS mount points. Variables are used as follows:
2425 * tbuffer: Set to point to the null-terminated directory name of the mount point
2426 * (or ``.'' if none is provided)
2427 * tp: Set to point to the actual name of the mount point to nuke.
2430 RemoveMountCmd(struct cmd_syndesc *as, void *arock) {
2432 struct ViceIoctl blob;
2433 struct cmd_item *ti;
2435 char lsbuffer[1024];
2440 for(ti=as->parms[0].items; ti; ti=ti->next) {
2442 tp = (char *) strrchr(ti->data, '\\');
2444 tp = (char *) strrchr(ti->data, '/');
2446 if( FAILED(StringCchCopyN(tbuffer, sizeof(tbuffer) / sizeof(char), ti->data, code=(afs_int32)(tp-ti->data+1)))) { /* the dir name */
2447 fprintf (stderr, "tbuffer - not enough space");
2450 tp++; /* skip the slash */
2453 if (!InAFS(tbuffer)) {
2454 const char * nbname = NetbiosName();
2455 if( FAILED(StringCbLength(nbname, NETBIOSNAMESZ, &len))) {
2456 fprintf (stderr, "StringCbLength failure on nbname");
2460 if (tbuffer[0] == '\\' && tbuffer[1] == '\\' &&
2461 tbuffer[len+2] == '\\' &&
2462 tbuffer[len+3] == '\0' &&
2463 !strnicmp(nbname,&tbuffer[2],len))
2465 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer),"\\\\%s\\all\\", nbname))) {
2466 fprintf (stderr, "tbuffer - cannot be populated");
2473 fs_ExtractDriveLetter(ti->data, tbuffer);
2474 if( FAILED(StringCbCat(tbuffer, sizeof(tbuffer), "."))) {
2475 fprintf (stderr, "tbuffer - not enough space");
2479 fs_StripDriveLetter(tp, tp, 0);
2482 if( FAILED(StringCbLength(tp, AFS_PIOCTL_MAXSIZE, &len))) {
2483 fprintf (stderr, "StringCbLength failure on tp");
2486 blob.in_size = (long)len+1;
2487 blob.out = lsbuffer;
2488 blob.out_size = sizeof(lsbuffer);
2489 code = pioctl_utf8(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
2491 if (errno == EINVAL) {
2492 fprintf(stderr,"%s: '%s' is not a mount point.\n", pn, ti->data);
2494 Die(errno, ti->data);
2497 continue; /* don't bother trying */
2500 if ( IsFreelanceRoot(tbuffer) && !IsAdmin() ) {
2501 fprintf(stderr,"%s: Only AFS Client Administrators may alter the Freelance root.afs volume\n", pn);
2503 continue; /* skip */
2508 if( FAILED(StringCbLength(tp, AFS_PIOCTL_MAXSIZE, &len))) {
2509 fprintf (stderr, "StringCbLength failure on tp");
2512 blob.in_size = (long)len+1;
2513 code = pioctl_utf8(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
2515 Die(errno, ti->data);
2526 CheckServersCmd(struct cmd_syndesc *as, void *arock)
2529 struct ViceIoctl blob;
2533 struct afsconf_cell info;
2534 struct chservinfo checkserv;
2538 memset(&info, 0, sizeof(info));
2539 memset(&checkserv, 0, sizeof(struct chservinfo));
2540 blob.in_size=sizeof(struct chservinfo);
2541 blob.in=(caddr_t)&checkserv;
2543 blob.out_size = AFS_PIOCTL_MAXSIZE;
2545 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2547 /* prepare flags for checkservers command */
2548 temp = 2; /* default to checking local cell only */
2549 if (as->parms[2].items)
2550 temp |= 1; /* set fast flag */
2551 if (as->parms[1].items)
2552 temp &= ~2; /* turn off local cell check */
2554 checkserv.magic = 0x12345678; /* XXX */
2555 checkserv.tflags=temp;
2557 /* now copy in optional cell name, if specified */
2558 if (as->parms[0].items) {
2559 code = GetCellName(as->parms[0].items->data, &info);
2563 if( FAILED(StringCbCopy(checkserv.tbuffer, sizeof(checkserv.tbuffer), info.name))) {
2564 fprintf (stderr, "tbuffer - not enough space");
2567 if( FAILED(StringCbLength(info.name, sizeof(info.name), &len))) {
2568 fprintf (stderr, "StringCbLength failure on info.name");
2571 checkserv.tsize=(int)len+1;
2572 if (info.linkedCell)
2573 free(info.linkedCell);
2575 if( FAILED(StringCbCopy(checkserv.tbuffer, sizeof(checkserv.tbuffer),"\0"))) {
2576 fprintf (stderr, "tbuffer - not enough space");
2582 if(as->parms[3].items) {
2583 checkserv.tinterval=atol(as->parms[3].items->data);
2586 if(checkserv.tinterval<0) {
2587 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
2588 checkserv.tinterval=-1;
2589 } else if(checkserv.tinterval> 600) {
2590 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
2591 checkserv.tinterval=600; /* 10 min max interval */
2594 checkserv.tinterval = -1; /* don't change current interval */
2597 if ( checkserv.tinterval >= 0 ) {
2600 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2605 fprintf (stderr,"Permission denied: requires root access.\n");
2611 code = pioctl_utf8(0, VIOCCKSERV, &blob, 1);
2613 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
2614 printf("Must be root to change -interval\n");
2621 memcpy(&temp, space, sizeof(afs_int32));
2623 err = memcpy_s(&temp, sizeof(temp), space, sizeof(afs_int32));
2625 fprintf (stderr, "memcpy_s failure on temp");
2630 if (checkserv.tinterval >= 0) {
2631 if (checkserv.tinterval > 0)
2632 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
2633 checkserv.tinterval, temp);
2635 printf("The current down server probe interval is %d secs\n", temp);
2639 printf("All servers are running.\n");
2641 printf("These servers unavailable due to network or server problems: ");
2642 for(j=0; j < AFS_MAXHOSTS; j++) {
2644 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
2646 err = memcpy_s(&temp, sizeof(temp), space + j*sizeof(afs_int32), sizeof(afs_int32));
2648 fprintf (stderr, "memcpy_s failure on temp");
2655 tp = hostutil_GetNameByINet(temp);
2665 MessagesCmd(struct cmd_syndesc *as, void *arock)
2668 struct ViceIoctl blob;
2669 struct gaginfo gagflags;
2670 struct cmd_item *show;
2672 memset(&gagflags, 0, sizeof(struct gaginfo));
2673 blob.in_size = sizeof(struct gaginfo);
2674 blob.in = (caddr_t ) &gagflags;
2675 blob.out_size = AFS_PIOCTL_MAXSIZE;
2677 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
2679 if (show = as->parms[0].items) {
2680 if (!strcasecmp (show->data, "user"))
2681 gagflags.showflags |= GAGUSER;
2682 else if (!strcasecmp (show->data, "console"))
2683 gagflags.showflags |= GAGCONSOLE;
2684 else if (!strcasecmp (show->data, "all"))
2685 gagflags.showflags |= GAGCONSOLE | GAGUSER;
2686 else if (!strcasecmp (show->data, "none"))
2690 "unrecognized flag %s: must be in {user,console,all,none}\n",
2699 code = pioctl_utf8(0, VIOC_GAG, &blob, 1);
2708 CheckVolumesCmd(struct cmd_syndesc *as, void *arock)
2711 struct ViceIoctl blob;
2715 code = pioctl_utf8(0, VIOCCKBACK, &blob, 1);
2720 printf("All volumeID/name mappings checked.\n");
2726 SetCacheSizeCmd(struct cmd_syndesc *as, void *arock)
2729 struct ViceIoctl blob;
2734 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2739 fprintf (stderr,"Permission denied: requires root access.\n");
2744 if (!as->parms[0].items && !as->parms[1].items) {
2745 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
2748 if (as->parms[0].items) {
2749 code = util_GetHumanInt32(as->parms[0].items->data, &temp);
2751 fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
2756 blob.in = (char *) &temp;
2757 blob.in_size = sizeof(afs_int32);
2759 code = pioctl_utf8(0, VIOCSETCACHESIZE, &blob, 1);
2761 Die(errno, (char *) 0);
2765 printf("New cache size set.\n");
2770 GetCacheParmsCmd(struct cmd_syndesc *as, void *arock)
2773 struct ViceIoctl blob;
2774 cm_cacheParms_t parms;
2776 memset(&parms, 0, sizeof(parms));
2779 blob.out_size = sizeof(parms);
2780 blob.out = (char *) &parms;
2781 code = pioctl_utf8(0, VIOCGETCACHEPARMS, &blob, 1);
2782 if (code || blob.out_size != sizeof(parms)) {
2787 printf("AFS using %I64u of the cache's available %I64u 1K byte blocks.\n",
2788 parms.parms[1], parms.parms[0]);
2789 if (parms.parms[1] > parms.parms[0])
2790 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
2795 ListCellsCmd(struct cmd_syndesc *as, void *arock)
2798 afs_int32 i, j, *lp, magic, size;
2800 afs_int32 addr, maxa = AFS_OMAXHOSTS;
2801 struct ViceIoctl blob;
2805 resolve = !(as->parms[0].items); /* -numeric */
2807 for(i=0;i<1000;i++) {
2810 memcpy(tp, &i, sizeof(afs_int32));
2812 err = memcpy_s(tp, sizeof(space), &i, sizeof(afs_int32));
2814 fprintf (stderr, "memcpy_s failure on tp");
2818 tp = (char *)(space + sizeof(afs_int32));
2819 lp = (afs_int32 *)tp;
2821 size = sizeof(afs_int32) + sizeof(afs_int32);
2822 blob.out_size = AFS_PIOCTL_MAXSIZE;
2823 blob.in_size = sizeof(afs_int32);
2826 code = pioctl_utf8(0, VIOCGETCELL, &blob, 1);
2829 break; /* done with the list */
2835 memcpy(&magic, tp, sizeof(afs_int32));
2837 err = memcpy_s(&magic, sizeof(magic), tp, sizeof(afs_int32));
2839 fprintf (stderr, "memcpy_s failure on magic");
2843 if (magic == 0x12345678) {
2844 maxa = AFS_MAXHOSTS;
2845 tp += sizeof(afs_int32);
2847 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
2848 for(j=0; j < maxa && j*sizeof(afs_int32) < AFS_PIOCTL_MAXSIZE; j++) {
2849 char *name, tbuffer[20];
2851 memcpy(&addr, tp + j*sizeof(afs_int32), sizeof(afs_int32));
2853 err = memcpy_s(&addr, sizeof(addr), tp + j*sizeof(afs_int32), sizeof(afs_int32));
2855 fprintf (stderr, "memcpy_s failure on addr");
2863 name = hostutil_GetNameByINet(addr);
2866 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr >> 24) & 0xff,
2867 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff))) {
2868 fprintf (stderr, "tbuffer - cannot be populated");
2873 printf(" %s", name);
2882 ListAliasesCmd(struct cmd_syndesc *as, void *arock)
2885 char *tp, *aliasName, *realName;
2886 struct ViceIoctl blob;
2893 memcpy(tp, &i, sizeof(afs_int32));
2895 err = memcpy_s(tp, sizeof(space), &i, sizeof(afs_int32));
2897 fprintf (stderr, "memcpy_s failure on tp");
2901 blob.out_size = AFS_PIOCTL_MAXSIZE;
2902 blob.in_size = sizeof(afs_int32);
2905 code = pioctl_utf8(0, VIOC_GETALIAS, &blob, 1);
2908 break; /* done with the list */
2912 space[blob.out_size - 1] = '\0';
2915 if( FAILED(StringCbLength(aliasName, sizeof(space), &len))) {
2916 fprintf (stderr, "StringCbLength failure on aliasName");
2921 printf("Alias %s for cell %s\n", aliasName, realName);
2927 CallBackRxConnCmd(struct cmd_syndesc *as, void *arock)
2930 struct ViceIoctl blob;
2931 struct cmd_item *ti;
2933 struct hostent *thp;
2937 ti = as->parms[0].items;
2940 thp = hostutil_GetHostByName(ti->data);
2942 fprintf(stderr, "host %s not found in host table.\n", ti->data);
2946 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2948 err = memcpy_s(&hostAddr, sizeof(hostAddr), thp->h_addr, sizeof(afs_int32));
2950 fprintf (stderr, "memcpy_s failure on hostAddr");
2955 hostAddr = 0; /* means don't set host */
2956 setp = 0; /* aren't setting host */
2959 /* now do operation */
2960 blob.in_size = sizeof(afs_int32);
2961 blob.out_size = sizeof(afs_int32);
2962 blob.in = (char *) &hostAddr;
2963 blob.out = (char *) &hostAddr;
2965 code = pioctl_utf8(0, VIOC_CBADDR, &blob, 1);
2975 NewCellCmd(struct cmd_syndesc *as, void *arock)
2978 afs_int32 code, linkedstate=0, size=0, *lp;
2979 struct ViceIoctl blob;
2980 struct cmd_item *ti;
2981 char *destEnd, *tp, *cellname=0;
2982 struct hostent *thp;
2983 afs_int32 fsport = 0, vlport = 0;
2985 size_t destRemaining;
2987 memset(space, 0, AFS_MAXHOSTS * sizeof(afs_int32));
2989 lp = (afs_int32 *)tp;
2991 tp += sizeof(afs_int32);
2992 for(ti=as->parms[1].items; ti; ti=ti->next) {
2993 thp = hostutil_GetHostByName(ti->data);
2995 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
3000 memcpy(tp, thp->h_addr, sizeof(afs_int32));
3002 err = memcpy_s(tp, sizeof(space) - (tp - space) * sizeof(char), thp->h_addr, sizeof(afs_int32));
3004 fprintf (stderr, "memcpy_s failure on tp");
3008 tp += sizeof(afs_int32);
3011 if (as->parms[2].items) {
3013 * Link the cell, for the purposes of volume location, to the specified
3016 cellname = as->parms[2].items->data;
3019 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3020 if (as->parms[3].items) {
3021 code = util_GetInt32(as->parms[3].items->data, &vlport);
3023 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
3027 if (as->parms[4].items) {
3028 code = util_GetInt32(as->parms[4].items->data, &fsport);
3030 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
3035 tp = (char *)(space + (AFS_MAXHOSTS+1) *sizeof(afs_int32));
3036 lp = (afs_int32 *)tp;
3040 if( FAILED(StringCbCopyEx(space + ((AFS_MAXHOSTS+4) * sizeof(afs_int32)), sizeof(space) - (AFS_MAXHOSTS+4) * sizeof(afs_int32)
3041 , as->parms[0].items->data, &tp, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
3042 fprintf (stderr, "var - not enough space");
3045 tp++; /* for null */
3046 destRemaining -= sizeof(char);
3048 if( FAILED(StringCbCopyEx(tp, sizeof(space) - size, cellname, &destEnd, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
3049 fprintf (tp, "space arr - not enough space");
3052 size += destEnd - tp + 1;
3054 blob.in_size = size;
3057 code = pioctl_utf8(0, VIOCNEWCELL, &blob, 1);
3063 struct ViceIoctl blob;
3066 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3071 blob.in = (char *) 0;
3072 blob.out_size = AFS_PIOCTL_MAXSIZE;
3075 code = pioctl_utf8((char *) 0, VIOCNEWCELL, &blob, 1);
3078 Die(errno, (char *) 0);
3082 printf("Cell servers information refreshed\n");
3089 NewAliasCmd(struct cmd_syndesc *as, void *arock)
3092 struct ViceIoctl blob;
3094 char *aliasName, *realName;
3095 size_t destRemaining = sizeof(space);
3097 /* Setup and do the NEWALIAS pioctl call */
3098 aliasName = as->parms[0].items->data;
3099 realName = as->parms[1].items->data;
3101 if( FAILED(StringCbCopyEx(tp, destRemaining, aliasName, &tp, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
3102 fprintf (stderr, "tp - not enough space");
3106 destRemaining -= sizeof(char);
3107 if( FAILED(StringCbCopyEx(tp, destRemaining, realName, &tp, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
3108 fprintf (stderr, "tp - not enough space");
3112 destRemaining -= sizeof(char);
3114 blob.in_size = tp - space;
3118 code = pioctl_utf8(0, VIOC_NEWALIAS, &blob, 1);
3120 if (errno == EEXIST) {
3122 "%s: cell name `%s' in use by an existing cell.\n", pn,
3134 WhichCellCmd(struct cmd_syndesc *as, void *arock)
3137 struct cmd_item *ti;
3138 struct ViceIoctl blob;
3141 cm_ioctlQueryOptions_t options;
3143 if (as->parms[1].items)
3146 SetDotDefault(&as->parms[0].items);
3147 for(ti=as->parms[0].items; ti; ti=ti->next) {
3149 afs_uint32 filetype;
3150 char cell[CELL_MAXNAMELEN];
3153 memset(&fid, 0, sizeof(fid));
3154 memset(&options, 0, sizeof(options));
3156 options.size = sizeof(options);
3157 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
3158 options.literal = literal;
3159 blob.in_size = options.size; /* no variable length data */
3162 blob.out_size = sizeof(cm_fid_t);
3163 blob.out = (char *) &fid;
3164 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
3165 blob.out_size == sizeof(cm_fid_t)) {
3166 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
3169 Die(errno, ti->data);
3174 blob.out_size = sizeof(filetype);
3175 blob.out = &filetype;
3177 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
3178 if (code || blob.out_size != sizeof(filetype)) {
3179 Die(errno, ti->data);
3183 blob.out_size = CELL_MAXNAMELEN;
3186 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
3188 if (errno == ENOENT)
3189 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
3191 Die(errno, ti->data);
3195 cell[CELL_MAXNAMELEN - 1] = '\0';
3196 printf("%s %s lives in cell '%s'\n",
3197 filetypestr(filetype),
3204 WSCellCmd(struct cmd_syndesc *as, void *arock)
3207 struct ViceIoctl blob;
3211 blob.out_size = AFS_PIOCTL_MAXSIZE;
3214 code = pioctl_utf8(NULL, VIOC_GET_WS_CELL, &blob, 1);
3220 space[AFS_PIOCTL_MAXSIZE - 1] = '\0';
3221 printf("This workstation belongs to cell '%s'\n", space);
3227 PrimaryCellCmd(struct cmd_syndesc *as, void *arock)
3229 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
3234 #ifndef AFS_NT40_ENV
3236 MonitorCmd(struct cmd_syndesc *as, void *arock)
3239 struct ViceIoctl blob;
3240 struct cmd_item *ti;
3242 struct hostent *thp;
3247 ti = as->parms[0].items;
3251 if (!strcmp(ti->data, "off")) {
3252 hostAddr = 0xffffffff;
3254 thp = hostutil_GetHostByName(ti->data);
3256 if (!strcmp(ti->data, "localhost")) {
3257 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
3258 hostAddr = htonl(0x7f000001);
3260 fprintf(stderr,"host %s not found in host table.\n", ti->data);
3265 memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
3267 err = memcpy_s(&hostAddr, sizeof(hostAddr), thp->h_addr, sizeof(afs_int32));
3269 fprintf (stderr, "memcpy_s failure on hostAddr");
3276 hostAddr = 0; /* means don't set host */
3277 setp = 0; /* aren't setting host */
3280 /* now do operation */
3281 blob.in_size = sizeof(afs_int32);
3282 blob.out_size = sizeof(afs_int32);
3283 blob.in = (char *) &hostAddr;
3284 blob.out = (char *) &hostAddr;
3285 code = pioctl_utf8(0, VIOC_AFS_MARINER_HOST, &blob, 1);
3286 if (code || blob.out_size != sizeof(afs_int32)) {
3291 printf("%s: new monitor host set.\n", pn);
3293 /* now decode old address */
3294 if (hostAddr == 0xffffffff) {
3295 printf("Cache monitoring is currently disabled.\n");
3297 tp = hostutil_GetNameByINet(hostAddr);
3298 printf("Using host %s for monitor services.\n", tp);
3303 #endif /* AFS_NT40_ENV */
3306 SysNameCmd(struct cmd_syndesc *as, void *arock)
3309 struct ViceIoctl blob;
3310 struct cmd_item *ti;
3311 char *input = space;
3314 size_t destRemaining = sizeof(space);
3317 ti = as->parms[0].items;
3321 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3326 fprintf (stderr,"Permission denied: requires root access.\n");
3334 blob.out_size = AFS_PIOCTL_MAXSIZE;
3335 blob.in_size = sizeof(afs_int32);
3337 memcpy(input, &setp, sizeof(afs_int32));
3339 err = memcpy_s(input, destRemaining, &setp, sizeof(afs_int32));
3341 fprintf (stderr, "memcpy_s failure on input");
3345 input += sizeof(afs_int32);
3346 destRemaining -= sizeof(afs_int32);
3347 for (; ti; ti = ti->next) {
3349 if( FAILED(StringCbCopyEx(input, destRemaining, ti->data, &input, &destRemaining, STRSAFE_FILL_ON_FAILURE))) {
3350 fprintf(stderr, "%s: sysname%s too long.\n", pn,
3351 setp > 1 ? "s" : "");
3355 destRemaining -= sizeof(char);
3357 blob.in_size = (input - space) * sizeof(char);
3359 memcpy(space, &setp, sizeof(afs_int32));
3361 err = memcpy_s(space, sizeof(space), &setp, sizeof(afs_int32));
3363 fprintf (stderr, "memcpy_s failure on space");
3368 code = pioctl_utf8(0, VIOC_AFS_SYSNAME, &blob, 1);
3374 printf("%s: new sysname%s set.\n", pn, setp > 1 ? " list" : "");
3380 memcpy(&setp, input, sizeof(afs_int32));
3382 err = memcpy_s(&setp, sizeof(setp), input, sizeof(afs_int32));
3384 fprintf (stderr, "memcpy_s failure on setp");
3388 input += sizeof(afs_int32);
3390 fprintf(stderr,"No sysname name value was found\n");
3393 space[blob.out_size - 1] = '\0';
3394 printf("Current sysname%s is", setp > 1 ? " list" : "");
3395 for (; setp > 0; --setp ) {
3396 printf(" \'%s\'", input);
3397 if( FAILED(StringCbLength(input, sizeof(space) - (input - space), &len))) {
3398 fprintf (stderr, "StringCbLength failure on input");
3407 #ifndef AFS_NT40_ENV
3408 static char *exported_types[] = {"null", "nfs", ""};
3409 static int ExportAfsCmd(struct cmd_syndesc *as, void *arock)
3412 struct ViceIoctl blob;
3413 struct cmd_item *ti;
3414 int export = 0, type = 0, mode = 0, exp = 0, gstat = 0;
3415 int exportcall, pwsync = 0, smounts = 0;
3419 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3424 fprintf (stderr,"Permission denied: requires root access.\n");
3429 ti = as->parms[0].items;
3430 if (strcmp(ti->data, "nfs") == 0)
3431 type = 0x71; /* NFS */
3434 "Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
3437 ti = as->parms[1].items;
3439 if (strcmp(ti->data, "on") == 0)
3441 else if (strcmp(ti->data, "off") == 0)
3444 fprintf(stderr, "Illegal argument %s\n", ti->data);
3449 if (ti = as->parms[2].items) { /* -noconvert */
3450 if (strcmp(ti->data, "on") == 0)
3452 else if (strcmp(ti->data, "off") == 0)
3455 fprintf(stderr, "Illegal argument %s\n", ti->data);
3459 if (ti = as->parms[3].items) { /* -uidcheck */
3460 if (strcmp(ti->data, "on") == 0)
3462 else if (strcmp(ti->data, "off") == 0)
3465 fprintf(stderr, "Illegal argument %s\n", ti->data);
3469 if (ti = as->parms[4].items) { /* -submounts */
3470 if (strcmp(ti->data, "on") == 0)
3472 else if (strcmp(ti->data, "off") == 0)
3475 fprintf(stderr, "Illegal argument %s\n", ti->data);
3479 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
3482 blob.in = (char *) &exportcall;
3483 blob.in_size = sizeof(afs_int32);
3484 blob.out = (char *) &exportcall;
3485 blob.out_size = sizeof(afs_int32);
3486 code = pioctl_utf8(0, VIOC_EXPORTAFS, &blob, 1);
3488 if (errno == ENODEV) {
3490 "Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
3497 if (exportcall & 1) {
3498 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
3499 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
3500 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
3501 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
3503 printf("'%s' translator is disabled\n", exported_types[type]);
3512 GetCellCmd(struct cmd_syndesc *as, void *arock)
3515 struct ViceIoctl blob;
3516 struct afsconf_cell info;
3517 struct cmd_item *ti;
3525 memset(&info, 0, sizeof(info));
3526 memset(&args, 0, sizeof(args)); /* avoid Purify UMR error */
3527 for(ti=as->parms[0].items; ti; ti=ti->next) {
3529 blob.out_size = sizeof(args);
3530 blob.out = (caddr_t) &args;
3531 code = GetCellName(ti->data, &info);
3536 if (info.linkedCell)
3537 free(info.linkedCell);
3538 if( FAILED(StringCbLength(info.name, sizeof(info.name), &len))) {
3539 fprintf (stderr, "StringCbLength failure on info.name");
3542 blob.in_size = 1+(long)len;
3543 blob.in = info.name;
3544 code = pioctl_utf8(0, VIOC_GETCELLSTATUS, &blob, 1);
3546 if (errno == ENOENT)
3547 fprintf(stderr,"%s: the cell named '%s' does not exist\n", pn, info.name);
3549 Die(errno, info.name);
3553 printf("Cell %s status: ", info.name);
3559 printf("no setuid allowed");
3561 printf("setuid allowed");
3563 printf(", using old VLDB");
3569 static int SetCellCmd(struct cmd_syndesc *as, void *arock)
3572 struct ViceIoctl blob;
3573 struct afsconf_cell info;
3574 struct cmd_item *ti;
3582 memset(&info, 0, sizeof(info));
3584 /* Check arguments. */
3585 if (as->parms[1].items && as->parms[2].items) {
3586 fprintf(stderr, "Cannot specify both -suid and -nosuid.\n");
3590 /* figure stuff to set */
3596 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3601 fprintf (stderr,"Permission denied: requires root access.\n");
3606 if (! as->parms[1].items)
3607 args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
3609 /* set stat for all listed cells */
3610 for(ti=as->parms[0].items; ti; ti=ti->next) {
3612 code = GetCellName(ti->data, &info);
3617 if (info.linkedCell)
3618 free(info.linkedCell);
3619 if( FAILED(StringCbCopy(args.cname, sizeof(args.cname), info.name))) {
3620 fprintf (stderr, "cname - not enough space");
3623 blob.in_size = sizeof(args);
3624 blob.in = (caddr_t) &args;
3626 blob.out = (caddr_t) 0;
3627 code = pioctl_utf8(0, VIOC_SETCELLSTATUS, &blob, 1);
3629 Die(errno, info.name); /* XXX added cell name to Die() call */
3637 GetCellName(char *cellNamep, struct afsconf_cell *infop)
3639 if( FAILED(StringCbCopy(infop->name, sizeof(infop->name), cellNamep))) {
3640 fprintf (stderr, "name - not enough space");
3647 VLDBInit(int noAuthFlag, struct afsconf_cell *info)
3652 cm_GetConfigDir(confDir, sizeof(confDir));
3654 code = ugen_ClientInit(noAuthFlag, confDir,
3655 info->name, 0, &uclient,
3656 NULL, pn, rxkad_clear,
3657 VLDB_MAXSERVERS, AFSCONF_VLDBSERVICE, 50,
3658 0, 0, USER_SERVICE_ID);
3663 static struct ViceIoctl gblob;
3664 static int debug = 0;
3666 * here follow some routines in suport of the setserverprefs and
3667 * getserverprefs commands. They are:
3668 * SetPrefCmd "top-level" routine
3669 * addServer adds a server to the list of servers to be poked into the
3670 * kernel. Will poke the list into the kernel if it threatens
3672 * pokeServers pokes the existing list of servers and ranks into the kernel
3673 * GetPrefCmd reads the Cache Manager's current list of server ranks
3682 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3684 ssp = (cm_SSetPref_t *)space;
3685 gblob.in_size = (long)(((char *)&(ssp->servers[0])) - (char *)ssp);
3691 * returns -1 if error message printed,
3693 * errno value if error and no error message printed
3700 code = pioctl_utf8(0, VIOC_SETSPREFS, &gblob, 1);
3701 if (code && (errno == EINVAL)) {
3702 struct setspref *ssp;
3703 ssp = (struct setspref *)gblob.in;
3704 if (!(ssp->flags & DBservers)) {
3705 gblob.in = (void *)&(ssp->servers[0]);
3706 gblob.in_size -= ((char *)&(ssp->servers[0])) - (char *)ssp;
3707 code = pioctl_utf8(0, VIOC_SETSPREFS33, &gblob, 1);
3708 return code ? errno : 0;
3711 "This cache manager does not support VL server preferences.\n");
3715 return code ? errno : 0;
3721 addServer(char *name, unsigned short rank)
3726 struct hostent *thostent;
3731 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3733 #define MAXUSHORT ((unsigned short) ~0)
3738 thostent = hostutil_GetHostByName(name);
3740 fprintf (stderr, "%s: couldn't resolve name.\n", name);
3744 ssp = (cm_SSetPref_t *)(gblob.in);
3746 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
3747 code = pokeServers();
3748 ssp->num_servers = 0;
3751 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
3753 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
3755 err = memcpy_s (&(sp->host.s_addr), sizeof(afs_uint32), thostent->h_addr, sizeof(afs_uint32));
3757 fprintf (stderr, "memcpy_s failure on sp->host.s_addr");
3762 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3763 gblob.in_size += sizeof(cm_SPref_t);
3766 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
3772 * returns -1 if error message printed,
3774 * errno value if error and no error message printed
3777 addServer(char *name, afs_int32 rank)
3780 struct setspref *ssp;
3782 struct hostent *thostent;
3789 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
3791 #define MAXUSHORT ((unsigned short) ~0)
3795 thostent = hostutil_GetHostByName(name);
3797 fprintf(stderr, "%s: couldn't resolve name.\n", name);
3801 ssp = (struct setspref *)(gblob.in);
3803 for (t = 0; thostent->h_addr_list[t]; t++) {
3804 if (gblob.in_size > MAXINSIZE - sizeof(struct spref)) {
3805 code = pokeServers();
3808 ssp->num_servers = 0;
3811 sp = (struct spref *)(gblob.in + gblob.in_size);
3813 memcpy(&(sp->server.s_addr), thostent->h_addr_list[t],
3814 sizeof(afs_uint32));
3816 err = memcpy_s(&(sp->server.s_addr), sizeof(afs_uint32), thostent->h_addr_list[t],
3817 sizeof(afs_uint32));
3819 fprintf (stderr, "memcpy_s failure on sp->server.s_addr");
3824 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
3825 gblob.in_size += sizeof(struct spref);
3829 fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",
3830 name, sp->rank, sp->server.s_addr);
3838 static BOOL IsWindowsNT (void)
3840 static BOOL fChecked = FALSE;
3841 static BOOL fIsWinNT = FALSE;
3845 OSVERSIONINFO Version;
3849 memset (&Version, 0x00, sizeof(Version));
3850 Version.dwOSVersionInfoSize = sizeof(Version);
3852 if (GetVersionEx (&Version))
3854 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3864 SetPrefCmd(struct cmd_syndesc *as, void * arock)
3868 struct cmd_item *ti;
3873 ssp = (cm_SSetPref_t *)space;
3875 ssp->num_servers = 0;
3876 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3879 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3882 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3888 ti = as->parms[2].items; /* -file */
3890 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
3891 if (!(infd = fopen(ti->data,"r" ))) {
3893 Die(errno,ti->data);
3896 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
3897 code = addServer (name, (unsigned short) rank);
3900 while ( fscanf_s(infd, "%79s%ld", name, sizeof(name), &rank) != EOF) {
3901 code = addServer (name, (unsigned short) rank);
3908 ti = as->parms[3].items; /* -stdin */
3911 while ( scanf("%79s%ld", name, &rank) != EOF) {
3912 code = addServer (name, (unsigned short) rank);
3915 while ( scanf_s("%79s%ld", name, sizeof(name), &rank) != EOF) {
3916 code = addServer (name, (unsigned short) rank);
3921 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
3926 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3928 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
3932 code = pokeServers();
3934 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
3936 ssp = (cm_SSetPref_t *)space;
3937 gblob.in_size = (long)(((char*)&(ssp->servers[0])) - (char *)ssp);
3939 ssp->flags = CM_SPREF_VLONLY;
3940 ssp->num_servers = 0;
3942 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
3947 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
3949 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
3954 if (as->parms[1].items) {
3956 printf("now poking vlservers\n");
3957 code = pokeServers();
3967 SetPrefCmd(struct cmd_syndesc *as, void *arock)
3971 struct cmd_item *ti;
3974 struct setspref *ssp;
3975 int error = 0; /* -1 means error message printed,
3976 * >0 means errno value for unprinted message */
3978 ssp = (struct setspref *)space;
3980 ssp->num_servers = 0;
3981 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
3984 gblob.out_size = AFS_PIOCTL_MAXSIZE;
3988 fprintf(stderr, "Permission denied: requires root access.\n");
3992 ti = as->parms[2].items; /* -file */
3995 fprintf(stderr, "opening file %s\n", ti->data);
3996 if (!(infd = fopen(ti->data, "r"))) {
4001 while (fscanf(infd, "%79s%ld", name, &rank) != EOF) {
4002 code = addServer(name, (unsigned short)rank);
4007 while (fscanf_s(infd, "%79s%ld", name, sizeof(name), &rank) != EOF) {
4008 code = addServer(name, (unsigned short)rank);
4017 ti = as->parms[3].items; /* -stdin */
4020 while (scanf("%79s%ld", name, &rank) != EOF) {
4021 code = addServer(name, (unsigned short)rank);
4026 while (scanf_s("%79s%ld", name, sizeof(name), &rank) != EOF) {
4027 code = addServer(name, (unsigned short)rank);
4034 for (ti = as->parms[0].items; ti; ti = ti->next) { /* list of servers, ranks */
4039 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
4043 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
4047 code = pokeServers();
4051 printf("now working on vlservers, code=%d\n", code);
4053 ssp = (struct setspref *)space;
4054 ssp->flags = DBservers;
4055 ssp->num_servers = 0;
4056 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
4059 for (ti = as->parms[1].items; ti; ti = ti->next) { /* list of dbservers, ranks */
4064 code = addServer(ti->data, (unsigned short)atol(ti->next->data));
4068 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
4073 if (as->parms[1].items) {
4075 printf("now poking vlservers\n");
4076 code = pokeServers();
4084 return error ? 1 : 0;
4090 GetPrefCmd(struct cmd_syndesc *as, void *arock)
4093 struct cmd_item *ti;
4094 char *name, tbuffer[20];
4099 struct ViceIoctl blob;
4100 struct cm_SPrefRequest *in;
4101 struct cm_SPrefInfo *out;
4105 ti = as->parms[0].items; /* -file */
4107 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
4108 if (!(outfd = freopen(ti->data,"w",stdout))) {
4109 Die(errno,ti->data);
4114 ti = as->parms[1].items; /* -numeric */
4116 ti = as->parms[2].items; /* -vlservers */
4117 vlservers = (ti ? CM_SPREF_VLONLY : 0);
4118 /* ti = as->parms[3].items; -cell */
4120 in = (struct cm_SPrefRequest *)space;
4124 blob.in_size=sizeof(struct cm_SPrefRequest);
4125 blob.in = (char *)in;
4127 blob.out_size = AFS_PIOCTL_MAXSIZE;
4129 in->num_servers = (AFS_PIOCTL_MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
4130 in->flags = vlservers;
4132 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
4134 perror("getserverprefs pioctl");
4138 out = (struct cm_SPrefInfo *) blob.out;
4140 for (i=0;i<out->num_servers;i++) {
4142 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
4145 addr = ntohl(out->servers[i].host.s_addr);
4146 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
4147 (addr>>8) & 0xff, addr & 0xff))) {
4148 fprintf (stderr, "tbuffer - cannot be populated");
4153 printf ("%-50s %5u\n",name,out->servers[i].rank);
4156 in->offset = out->next_offset;
4158 } while (!code && out->next_offset > 0);
4164 GetPrefCmd(struct cmd_syndesc *as, void *arock)
4167 struct cmd_item *ti;
4168 char *name, tbuffer[20];
4169 afs_int32 rank, addr;
4173 struct ViceIoctl blob;
4174 struct sprefrequest *in;
4175 struct sprefinfo *out;
4178 ti = as->parms[0].items; /* -file */
4181 fprintf(stderr, "opening file %s\n", ti->data);
4182 if (!(outfd = freopen(ti->data, "w", stdout))) {
4188 ti = as->parms[1].items; /* -numeric */
4190 ti = as->parms[2].items; /* -vlservers */
4191 vlservers |= (ti ? DBservers : 0);
4192 /* ti = as->parms[3].items; -cell */
4194 in = (struct sprefrequest *)space;
4198 blob.in_size = sizeof(struct sprefrequest);
4199 blob.in = (char *)in;
4201 blob.out_size = AFS_PIOCTL_MAXSIZE;
4204 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4205 in->flags = vlservers;
4207 code = pioctl_utf8(0, VIOC_GETSPREFS, &blob, 1);
4209 perror("getserverprefs pioctl");
4213 out = (struct sprefinfo *)blob.out;
4215 for (i = 0; i < out->num_servers; i++) {
4217 name = hostutil_GetNameByINet(out->servers[i].server.s_addr);
4219 addr = ntohl(out->servers[i].server.s_addr);
4220 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr >> 24) & 0xff,
4221 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff))) {
4222 fprintf (stderr, "tbuffer - cannot be populated");
4227 printf("%-50s %5u\n", name, out->servers[i].rank);
4230 in->offset = out->next_offset;
4231 } while (out->next_offset > 0);
4238 SmbUnicodeCmd(struct cmd_syndesc * asp, void * arock)
4244 struct ViceIoctl blob;
4246 if (asp->parms[0].items) {
4250 } else if (asp->parms[1].items) {
4256 if (inValue != 0 && !IsAdmin()) {
4257 fprintf (stderr, "Permission denied: Requires AFS Client Administrator access.\n");
4261 blob.in_size = sizeof(inValue);
4262 blob.in = (char *) &inValue;
4263 blob.out_size = sizeof(outValue);
4264 blob.out = (char *) &outValue;
4266 code = pioctl_utf8(NULL, VIOC_UNICODECTL, &blob, 1);
4272 if (outValue != 2) {
4273 printf("Unicode support is %s%s.\n",
4274 ((outValue != 0)? "enabled":"disabled"),
4275 ((inValue != 0)? " for new SMB connections":""));
4277 printf("Unicode support is absent in this installation of OpenAFS.\n");
4284 GetFidCmd(struct cmd_syndesc *as, void *arock)
4287 struct ViceIoctl blob;
4288 struct cmd_item *ti;
4291 cm_ioctlQueryOptions_t options;
4293 if (as->parms[1].items)
4296 SetDotDefault(&as->parms[0].items);
4297 for(ti=as->parms[0].items; ti; ti=ti->next) {
4299 afs_uint32 filetype;
4300 char cell[CELL_MAXNAMELEN];
4303 memset(&fid, 0, sizeof(fid));
4304 memset(&options, 0, sizeof(options));
4306 options.size = sizeof(options);
4307 options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
4308 options.literal = literal;
4309 blob.in_size = options.size; /* no variable length data */
4312 blob.out_size = sizeof(cm_fid_t);
4313 blob.out = (char *) &fid;
4314 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
4315 blob.out_size == sizeof(cm_fid_t)) {
4316 options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
4319 Die(errno, ti->data);
4324 blob.out_size = sizeof(filetype);
4325 blob.out = &filetype;
4327 code = pioctl_utf8(ti->data, VIOC_GETFILETYPE, &blob, 1);
4328 if (code || blob.out_size != sizeof(filetype)) {
4329 Die(errno, ti->data);
4333 blob.out_size = CELL_MAXNAMELEN;
4336 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
4338 cell[CELL_MAXNAMELEN - 1] = '\0';
4339 printf("%s %s (%u.%u.%u) contained in cell %s\n",
4340 filetypestr(filetype),
4341 ti->data, fid.volume, fid.vnode, fid.unique,
4342 code ? "unknown-cell" : cell);
4348 UuidCmd(struct cmd_syndesc *asp, void *arock)
4353 struct ViceIoctl blob;
4354 char * uuidstring = NULL;
4356 if (asp->parms[0].items) {
4359 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4364 fprintf (stderr, "Permission denied: requires root access.\n");
4368 inValue = 1; /* generate new UUID */
4370 inValue = 0; /* just show the current UUID */
4373 blob.in_size = sizeof(inValue);
4374 blob.in = (char *) &inValue;
4375 blob.out_size = sizeof(outValue);
4376 blob.out = (char *) &outValue;
4378 code = pioctl_utf8(NULL, VIOC_UUIDCTL, &blob, 1);
4379 if (code || blob.out_size != sizeof(outValue)) {
4384 UuidToString((UUID *) &outValue, &uuidstring);
4386 printf("%sUUID: %s",
4387 ((inValue == 1)?"New ":""),
4391 RpcStringFree(&uuidstring);
4397 TraceCmd(struct cmd_syndesc *asp, void *arock)
4400 struct ViceIoctl blob;
4406 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4411 fprintf (stderr,"Permission denied: requires root access.\n");
4416 if ((asp->parms[0].items && asp->parms[1].items)) {
4417 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
4421 /* determine if we're turning this tracing on or off */
4423 if (asp->parms[0].items)
4424 inValue = 3; /* enable */
4425 else if (asp->parms[1].items)
4426 inValue = 2; /* disable */
4427 if (asp->parms[2].items)
4428 inValue |= 4; /* do reset */
4429 if (asp->parms[3].items)
4430 inValue |= 8; /* dump */
4432 blob.in_size = sizeof(long);
4433 blob.in = (char *) &inValue;
4434 blob.out_size = sizeof(long);
4435 blob.out = (char *) &outValue;
4437 code = pioctl_utf8(NULL, VIOC_TRACECTL, &blob, 1);
4438 if (code || blob.out_size != sizeof(long)) {
4444 printf("AFS tracing enabled.\n");
4446 printf("AFS tracing disabled.\n");
4451 static void sbusage(void)
4453 fprintf(stderr, "example usage: %s storebehind -files *.o -kb 99999 -default 0\n", pn);
4454 fprintf(stderr, " %s sb 50000 *.[ao] -default 10\n", pn);
4457 /* fs sb -kbytes 9999 -files *.o -default 64 */
4459 StoreBehindCmd(struct cmd_syndesc *as, void *arock)
4462 struct ViceIoctl blob;
4463 struct cmd_item *ti;
4464 struct sbstruct tsb, tsb2;
4472 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4477 tsb.sb_thisfile = -1;
4478 ti = as->parms[0].items; /* -kbytes */
4480 if (!as->parms[1].items) {
4481 fprintf(stderr, "%s: you must specify -files with -kbytes.\n",
4485 tsb.sb_thisfile = strtol(ti->data, &t, 10) * 1024;
4486 if (errno == ERANGE) {
4487 fprintf(stderr, "%s: ti->data must within long int range", pn);
4490 if ((tsb.sb_thisfile < 0) || (*t != '\0')) {
4491 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
4497 allfiles = tsb.sb_default = -1; /* Don't set allfiles yet */
4498 ti = as->parms[2].items; /* -allfiles */
4500 allfiles = strtol(ti->data, &t, 10) * 1024;
4501 if (errno == ERANGE) {
4502 fprintf(stderr, "%s: ti->data must within long int range", pn);
4505 if ((allfiles < 0) || (*t != '\0')) {
4506 fprintf(stderr, "%s: %s must be 0 or a positive number.\n", pn,
4512 /* -verbose or -file only or no options */
4513 if (as->parms[3].items || (as->parms[1].items && !as->parms[0].items)
4514 || (!as->parms[0].items && !as->parms[1].items
4515 && !as->parms[2].items))
4518 blob.in = (char *)&tsb;
4519 blob.out = (char *)&tsb2;
4520 blob.in_size = blob.out_size = sizeof(struct sbstruct);
4521 memset(&tsb2, 0, sizeof(tsb2));
4523 /* once per -file */
4524 for (ti = as->parms[1].items; ti; ti = ti->next) {
4525 /* Do this solely to see if the file is there */
4526 code = pioctl_utf8(ti->data, VIOCWHEREIS, &blob, 1);
4528 Die(errno, ti->data);
4533 code = pioctl_utf8(ti->data, VIOC_STOREBEHIND, &blob, 1);
4535 Die(errno, ti->data);
4540 if (verbose && (blob.out_size == sizeof(tsb2))) {
4541 if (tsb2.sb_thisfile == -1) {
4542 fprintf(stdout, "Will store %s according to default.\n",
4546 "Will store up to %d kbytes of %s asynchronously.\n",
4547 (tsb2.sb_thisfile / 1024), ti->data);
4552 /* If no files - make at least one pioctl call, or
4553 * set the allfiles default if we need to.
4555 if (!as->parms[1].items || (allfiles != -1)) {
4556 tsb.sb_default = allfiles;
4557 code = pioctl_utf8(0, VIOC_STOREBEHIND, &blob, 1);
4559 Die(errno, ((allfiles == -1) ? 0 : "-allfiles"));
4564 /* Having no arguments also reports the default store asynchrony */
4565 if (verbose && (blob.out_size == sizeof(tsb2))) {
4566 fprintf(stdout, "Default store asynchrony is %d kbytes.\n",
4567 (tsb2.sb_default / 1024));
4574 SetCryptCmd(struct cmd_syndesc *as, void *arock)
4576 afs_int32 code = 0, flag;
4577 struct ViceIoctl blob;
4582 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4587 tp = as->parms[0].items->data;
4588 if (strcmp(tp, "on") == 0)
4590 else if (strcmp(tp, "off") == 0)
4592 else if (strcmp(tp, "auth") == 0)
4595 fprintf (stderr, "%s: %s must be \"on\", \"auth\", or \"off\".\n", pn, tp);
4599 blob.in = (char *) &flag;
4600 blob.in_size = sizeof(flag);
4602 code = pioctl_utf8(0, VIOC_SETRXKCRYPT, &blob, 1);
4609 GetCryptCmd(struct cmd_syndesc *as, void *arock)
4611 afs_int32 code = 0, flag;
4612 struct ViceIoctl blob;
4618 blob.out_size = sizeof(flag);
4621 code = pioctl_utf8(0, VIOC_GETRXKCRYPT, &blob, 1);
4623 if (code || blob.out_size != sizeof(flag))
4628 memcpy(&flag, tp, sizeof(afs_int32));
4630 err = memcpy_s(&flag, sizeof(flag), tp, sizeof(afs_int32));
4632 fprintf (stderr, "memcpy_s failure on flag");
4637 printf("Security level is currently ");
4639 printf("auth (data integrity).\n");
4641 printf("crypt (data security).\n");
4649 MemDumpCmd(struct cmd_syndesc *asp, void *arock)
4652 struct ViceIoctl blob;
4657 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4661 if ((asp->parms[0].items && asp->parms[1].items)) {
4662 fprintf(stderr, "%s trace: must use at most one of '-begin' or '-end'\n", pn);
4666 /* determine if we're turning this tracing on or off */
4667 if (asp->parms[0].items)
4668 inValue = 1; /* begin */
4669 else if (asp->parms[1].items)
4670 inValue = 0; /* end */
4673 blob.in_size = sizeof(long);
4674 blob.in = (char *) &inValue;
4675 blob.out_size = sizeof(long);
4676 blob.out = (char *) &outValue;
4678 code = pioctl_utf8(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
4679 if (code || blob.out_size != sizeof(long)) {
4685 printf("AFS memdump created.\n");
4688 printf("AFS memdump failed.\n");
4694 MiniDumpCmd(struct cmd_syndesc *asp, void *arock)
4697 SERVICE_STATUS status;
4698 SC_HANDLE hManager = NULL;
4699 SC_HANDLE hService = NULL;
4702 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4706 hManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
4710 hService = OpenService(hManager, "TransarcAFSDaemon", SERVICE_USER_DEFINED_CONTROL);
4714 success = ControlService(hService, SERVICE_CONTROL_CUSTOM_DUMP, &status);
4717 CloseServiceHandle(hService);
4718 CloseServiceHandle(hManager);
4720 printf("AFS minidump generated.\n");
4726 CloseServiceHandle(hService);
4728 CloseServiceHandle(hManager);
4730 printf("AFS minidump failed.\n");
4735 CSCPolicyCmd(struct cmd_syndesc *asp, void *arock)
4737 struct cmd_item *ti;
4743 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4747 for(ti=asp->parms[0].items; ti;ti=ti->next) {
4759 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4760 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4763 REG_OPTION_NON_VOLATILE,
4764 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
4769 if ( hkCSCPolicy == NULL ) {
4770 fprintf (stderr,"Permission denied: requires Administrator access.\n");
4775 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
4776 RegCloseKey(hkCSCPolicy);
4783 if (asp->parms[1].items) {
4787 if (asp->parms[2].items) {
4788 policy = "programs";
4791 if (asp->parms[3].items) {
4792 policy = "documents";
4795 if (asp->parms[4].items) {
4799 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, (DWORD)len+1);
4801 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
4802 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
4806 DWORD dwIndex, dwPolicies;
4807 char policyName[256];
4808 DWORD policyNameLen;
4813 /* list current csc policies */
4815 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
4816 AFSREG_CLT_OPENAFS_SUBKEY "\\CSCPolicy",
4819 REG_OPTION_NON_VOLATILE,
4820 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_QUERY_VALUE,
4825 RegQueryInfoKey( hkCSCPolicy,
4827 NULL, /* lpcClass */
4828 NULL, /* lpReserved */
4829 NULL, /* lpcSubKeys */
4830 NULL, /* lpcMaxSubKeyLen */
4831 NULL, /* lpcMaxClassLen */
4832 &dwPolicies, /* lpcValues */
4833 NULL, /* lpcMaxValueNameLen */
4834 NULL, /* lpcMaxValueLen */
4835 NULL, /* lpcbSecurityDescriptor */
4836 NULL /* lpftLastWriteTime */
4839 printf("Current CSC policies:\n");
4840 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
4842 policyNameLen = sizeof(policyName);
4843 policyLen = sizeof(policy);
4844 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
4845 &dwType, policy, &policyLen);
4847 printf(" %s = %s\n", policyName, policy);
4851 RegCloseKey(hkCSCPolicy);
4856 /* get clients interface addresses */
4858 GetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4861 struct cmd_item *ti;
4863 struct ViceIoctl blob;
4864 struct sprefrequest *in;
4865 struct sprefinfo *out;
4867 in = (struct sprefrequest *)space;
4871 blob.in_size = sizeof(struct sprefrequest);
4872 blob.in = (char *)in;
4874 blob.out_size = AFS_PIOCTL_MAXSIZE;
4877 (AFS_PIOCTL_MAXSIZE - 2 * sizeof(short)) / sizeof(struct spref);
4878 /* returns addr in network byte order */
4879 code = pioctl_utf8(0, VIOC_GETCPREFS, &blob, 1);
4881 perror("getClientInterfaceAddr pioctl");
4887 out = (struct sprefinfo *)blob.out;
4888 for (i = 0; i < out->num_servers; i++) {
4891 addr = ntohl(out->servers[i].server.s_addr);
4892 if( FAILED(StringCbPrintf(tbuffer, sizeof(tbuffer), "%d.%d.%d.%d", (addr >> 24) & 0xff,
4893 (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff))) {
4894 fprintf (stderr, "tbuffer - cannot be populated");
4897 printf("%-50s\n", tbuffer);
4899 in->offset = out->next_offset;
4901 } while (out->next_offset > 0);
4907 SetClientAddrsCmd(struct cmd_syndesc *as, void *arock)
4909 afs_int32 code, addr;
4910 struct cmd_item *ti;
4912 struct ViceIoctl blob;
4913 struct setspref *ssp;
4914 int sizeUsed = 0, i, flag;
4915 afs_int32 existingAddr[1024]; /* existing addresses on this host */
4919 ssp = (struct setspref *)space;
4920 ssp->num_servers = 0;
4923 blob.out_size = AFS_PIOCTL_MAXSIZE;
4926 fprintf(stderr, "Permission denied: requires root access.\n");
4930 /* extract all existing interface addresses */
4931 existNu = rx_getAllAddr(existingAddr, 1024);
4935 sizeUsed = sizeof(struct setspref); /* space used in ioctl buffer */
4936 for (ti = as->parms[0].items; ti; ti = ti->next) {
4937 if (sizeUsed >= sizeof(space)) {
4938 fprintf(stderr, "No more space\n");
4941 addr = extractAddr(ti->data, 20); /* network order */
4942 if ((addr == AFS_IPINVALID) || (addr == AFS_IPINVALIDIGNORE)) {
4943 fprintf(stderr, "Error in specifying address: %s..ignoring\n",
4948 /* see if it is an address that really exists */
4949 for (flag = 0, i = 0; i < existNu; i++)
4950 if (existingAddr[i] == addr) {
4954 if (!flag) { /* this is an nonexistent address */
4955 fprintf(stderr, "Nonexistent address: 0x%08x..ignoring\n", addr);
4959 /* copy all specified addr into ioctl buffer */
4960 (ssp->servers[ssp->num_servers]).server.s_addr = addr;
4961 printf("Adding 0x%08x\n", addr);
4963 sizeUsed += sizeof(struct spref);
4965 if (ssp->num_servers < 1) {
4966 fprintf(stderr, "No addresses specified\n");
4969 blob.in_size = sizeUsed - sizeof(struct spref);
4971 code = pioctl_utf8(0, VIOC_SETCPREFS, &blob, 1); /* network order */
4981 FlushMountCmd(struct cmd_syndesc *as, void *arock)
4984 struct ViceIoctl blob;
4985 struct cmd_item *ti;
4986 char orig_name[1024]; /*Original name, may be modified */
4987 char true_name[1024]; /*``True'' dirname (e.g., symlink target) */
4988 char parent_dir[1024]; /*Parent directory of true name */
4989 char *last_component; /*Last component of true name */
4990 struct stat statbuff; /*Buffer for status info */
4991 int link_chars_read; /*Num chars read in readlink() */
4992 int thru_symlink; /*Did we get to a mount point via a symlink? */
4996 for (ti = as->parms[0].items; ti; ti = ti->next) {
4999 if( FAILED(StringCbPrintf(orig_name, sizeof(orig_name), "%s%s", (ti->data[0] == '/') ? "" : "./",
5001 fprintf (stderr, "orig_name - cannot be populated");
5005 if (lstat(orig_name, &statbuff) < 0) {
5006 /* if lstat fails, we should still try the pioctl, since it
5007 * may work (for example, lstat will fail, but pioctl will
5008 * work if the volume of offline (returning ENODEV). */
5009 statbuff.st_mode = S_IFDIR; /* lie like pros */
5013 * The lstat succeeded. If the given file is a symlink, substitute
5014 * the file name with the link name.
5016 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
5019 * Read name of resolved file.
5021 link_chars_read = readlink(orig_name, true_name, 1024);
5022 if (link_chars_read <= 0) {
5024 "%s: Can't read target name for '%s' symbolic link!\n",
5031 * Add a trailing null to what was read, bump the length.
5033 true_name[link_chars_read++] = 0;
5036 * If the symlink is an absolute pathname, we're fine. Otherwise, we
5037 * have to create a full pathname using the original name and the
5038 * relative symlink name. Find the rightmost slash in the original
5039 * name (we know there is one) and splice in the symlink value.
5041 if (true_name[0] != '/') {
5042 last_component = (char *)strrchr(orig_name, '/');
5043 if( FAILED(StringCbCopy(++last_component, sizeof(orig_name) - (last_component - orig_name) * sizeof(char), true_name))) {
5044 fprintf (stderr, "last_component - not enough space");
5047 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
5048 fprintf (stderr, "true_name - not enough space");
5053 if( FAILED(StringCbCopy(true_name, sizeof(true_name), orig_name))) {
5054 fprintf (stderr, "true_name - not enough space");
5059 * Find rightmost slash, if any.
5061 last_component = (char *)strrchr(true_name, '/');
5062 if (last_component) {
5064 * Found it. Designate everything before it as the parent directory,
5065 * everything after it as the final component.
5067 if( FAILED(StringCchCopyN(parent_dir, sizeof(parent_dir) / sizeof(char), true_name, last_component - true_name))) {
5068 fprintf (stderr, "parent_dir - not enough space");
5071 parent_dir[last_component - true_name] = 0;
5072 last_component++; /*Skip the slash */
5075 * No slash appears in the given file name. Set parent_dir to the current
5076 * directory, and the last component as the given name.
5078 if( FAILED(StringCbCopy(parent_dir, sizeof(parent_dir), "."))) {
5079 fprintf (stderr, "parent_dir - not enough space");
5082 last_component = true_name;
5085 if (strcmp(last_component, ".") == 0
5086 || strcmp(last_component, "..") == 0) {
5088 "%s: you may not use '.' or '..' as the last component\n",
5090 fprintf(stderr, "%s: of a name in the 'fs flushmount' command.\n",
5096 blob.in = last_component;
5097 if( FAILED(StringCbLength(last_component, sizeof(true_name) - (last_component - true_name), &len))) {
5098 fprintf (stderr, "StringCbLength failure on last_component");
5101 blob.in_size = len + 1;
5103 memset(space, 0, AFS_PIOCTL_MAXSIZE);
5105 code = pioctl_utf8(parent_dir, VIOC_AFS_FLUSHMOUNT, &blob, 1);
5108 if (errno == EINVAL) {
5109 fprintf(stderr, "'%s' is not a mount point.\n", ti->data);
5111 Die(errno, (ti->data ? ti->data : parent_dir));
5121 RxStatProcCmd(struct cmd_syndesc *as, void *arock)
5124 afs_int32 flags = 0;
5125 struct ViceIoctl blob;
5127 if (as->parms[0].items) { /* -enable */
5128 flags |= AFSCALL_RXSTATS_ENABLE;
5130 if (as->parms[1].items) { /* -disable */
5131 flags |= AFSCALL_RXSTATS_DISABLE;
5133 if (as->parms[2].items) { /* -clear */
5134 flags |= AFSCALL_RXSTATS_CLEAR;
5137 fprintf(stderr, "You must specify at least one argument\n");
5141 blob.in = (char *)&flags;
5142 blob.in_size = sizeof(afs_int32);
5145 code = pioctl_utf8(NULL, VIOC_RXSTAT_PROC, &blob, 1);
5155 RxStatPeerCmd(struct cmd_syndesc *as, void *arock)
5158 afs_int32 flags = 0;
5159 struct ViceIoctl blob;
5161 if (as->parms[0].items) { /* -enable */
5162 flags |= AFSCALL_RXSTATS_ENABLE;
5164 if (as->parms[1].items) { /* -disable */
5165 flags |= AFSCALL_RXSTATS_DISABLE;
5167 if (as->parms[2].items) { /* -clear */
5168 flags |= AFSCALL_RXSTATS_CLEAR;
5171 fprintf(stderr, "You must specify at least one argument\n");
5175 blob.in = (char *)&flags;
5176 blob.in_size = sizeof(afs_int32);
5179 code = pioctl_utf8(NULL, VIOC_RXSTAT_PEER, &blob, 1);
5189 TestVolStatCmd(struct cmd_syndesc *as, void *arock)
5192 struct VolStatTest test;
5193 struct ViceIoctl blob;
5197 memset(&test, 0, sizeof(test));
5199 if (as->parms[0].items) { /* -network */
5200 tp = as->parms[0].items->data;
5201 if (strcmp(tp, "up") == 0)
5202 test.flags |= VOLSTAT_TEST_NETWORK_UP;
5203 else if (strcmp(tp, "down") == 0)
5204 test.flags |= VOLSTAT_TEST_NETWORK_DOWN;
5206 fprintf (stderr, "%s: %s must be \"up\" or \"down\".\n", pn, tp);
5210 if (as->parms[1].items) { /* check */
5211 test.flags |= VOLSTAT_TEST_CHECK_VOLUME;
5213 if (as->parms[2].items) { /* cell */
5214 tp = as->parms[2].items->data;
5219 if( FAILED(StringCbCopy(test.cellname, sizeof(test.cellname), tp))) {
5220 fprintf (stderr, "cellname - not enough space");
5223 test.cellname[sizeof(test.cellname)-1] = '\0';
5226 if (as->parms[3].items) { /* volume */
5227 tp = as->parms[3].items->data;
5230 test.fid.volume = n;
5232 if( FAILED(StringCbCopy(test.volname, sizeof(test.volname), tp))) {
5233 fprintf (stderr, "volname - not enough space");
5236 test.volname[sizeof(test.volname)-1] = '\0';
5239 if (as->parms[4].items) { /* state */
5240 tp = as->parms[4].items->data;
5241 if (strcmp(tp, "online") == 0)
5242 test.state = vl_online;
5243 else if (strcmp(tp, "busy") == 0)
5244 test.state = vl_busy;
5245 else if (strcmp(tp, "offline") == 0)
5246 test.state = vl_offline;
5247 else if (strcmp(tp, "down") == 0)
5248 test.state = vl_alldown;
5250 fprintf (stderr, "%s: %s must be \"online\", \"busy\", \"offline\" or \"down\".\n", pn, tp);
5255 if ((test.fid.cell || test.cellname[0]) && !(test.fid.volume || test.volname[0]) ||
5256 !(test.fid.cell || test.cellname[0]) && (test.fid.volume || test.volname[0])) {
5257 fprintf (stderr, "%s: both a cell and a volume must be specified.\n", pn, tp);
5261 blob.in = (char *)&test;
5262 blob.in_size = sizeof(test);
5265 code = pioctl_utf8(NULL, VIOC_VOLSTAT_TEST, &blob, 1);
5275 ChOwnCmd(struct cmd_syndesc *as, void *arock)
5278 struct ViceIoctl blob;
5279 struct cmd_item *ti;
5283 cm_ioctlQueryOptions_t options;
5290 cm_GetConfigDir(confDir, sizeof(confDir));
5292 if (as->parms[2].items)
5295 ownerStr = as->parms[0].items->data;
5296 ownerId = atoi(ownerStr);
5298 SetDotDefault(&as->parms[1].items);
5299 for(ti=as->parms[1].items; ti; ti=ti->next) {
5301 afs_uint32 filetype;
5302 char cell[CELL_MAXNAMELEN];
5305 memset(&fid, 0, sizeof(fid));
5306 memset(&inData, 0, sizeof(inData));
5308 inData.options.size = sizeof(inData.options);
5309 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_LITERAL;
5310 inData.options.literal = literal;
5311 blob.in_size = inData.options.size; /* no variable length data */
5314 blob.out_size = sizeof(cm_fid_t);
5315 blob.out = (char *) &fid;
5316 if (0 == pioctl_utf8(ti->data, VIOCGETFID, &blob, 1) &&
5317 blob.out_size == sizeof(cm_fid_t)) {
5318 inData.options.field_flags |= CM_IOCTL_QOPTS_FIELD_FID;
5319 inData.options.fid = fid;
5321 Die(errno, ti->data);
5327 * if the owner was specified as a numeric value,
5328 * then we can just use it. Otherwise, we need
5329 * to know the cell of the path to determine which
5330 * ptserver to contact in order to convert the name
5331 * to a numeric value.
5334 blob.out_size = CELL_MAXNAMELEN;
5337 code = pioctl_utf8(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
5339 Die(errno, ti->data);
5343 cell[CELL_MAXNAMELEN - 1] = '\0';
5345 * We now know the cell for the target and we need to
5346 * convert the ownerStr to the Id for this user
5348 pr_Initialize(1, confDir, cell);
5349 code = pr_SNameToId(ownerStr, &inData.owner);
5352 if (code || inData.owner == ANONYMOUSID ) {
5353 Die(ECHILD, ti->data);
5358 inData.owner = ownerId;
5361 blob.in_size = sizeof(inData);
5364 code = pioctl_utf8(ti->data, VIOC_SETOWNER, &blob, 1);
5366 Die(errno, ti->data);
5373 ChGrpCmd(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 groupStr = as->parms[0].items->data;
5394 groupId = atoi(groupStr);
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 group 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 groupStr to the Id for this user
5446 pr_Initialize(1, confDir, cell);
5447 code = pr_SNameToId(groupStr, &inData.group);
5450 if (code || inData.group == ANONYMOUSID ) {
5451 Die(ECHILD, ti->data);
5456 inData.group = groupId;
5459 blob.in_size = sizeof(inData);
5462 code = pioctl_utf8(ti->data, VIOC_SETGROUP, &blob, 1);
5464 Die(errno, ti->data);
5471 #include "AFS_component_version_number.c"
5475 FreeUtf8CmdLine(int argc, char ** argv)
5478 for (i=0; i < argc; i++) {
5486 MakeUtf8Cmdline(int argc, const wchar_t **wargv)
5491 argv = calloc(argc, sizeof(argv[0]));
5495 for (i=0; i < argc; i++) {
5498 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, NULL, 0, NULL, FALSE);
5500 (argv[i] = calloc(s+1, sizeof(char))) == NULL) {
5504 s = WideCharToMultiByte(CP_UTF8, 0, wargv[i], -1, argv[i], s+1, NULL, FALSE);
5511 FreeUtf8CmdLine(argc, argv);
5518 int wmain(int argc, wchar_t **wargv)
5521 struct cmd_syndesc *ts;
5524 #ifdef AFS_AIX32_ENV
5526 * The following signal action for AIX is necessary so that in case of a
5527 * crash (i.e. core is generated) we can include the user's data section
5528 * in the core dump. Unfortunately, by default, only a partial core is
5529 * generated which, in many cases, isn't too useful.
5531 struct sigaction nsa;
5533 sigemptyset(&nsa.sa_mask);
5534 nsa.sa_handler = SIG_DFL;
5535 nsa.sa_flags = SA_FULLDUMP;
5536 sigaction(SIGSEGV, &nsa, NULL);
5541 WSAStartup(0x0101, &WSAjunk);
5544 argv = MakeUtf8Cmdline(argc, wargv);
5546 /* try to find volume location information */
5550 ts = cmd_CreateSyntax("getclientaddrs", GetClientAddrsCmd, NULL,
5551 "get client network interface addresses");
5552 cmd_CreateAlias(ts, "gc");
5554 ts = cmd_CreateSyntax("setclientaddrs", SetClientAddrsCmd, NULL,
5555 "set client network interface addresses");
5556 cmd_AddParm(ts, "-address", CMD_LIST, CMD_OPTIONAL | CMD_EXPANDS,
5557 "client network interfaces");
5558 cmd_CreateAlias(ts, "sc");
5561 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, NULL, "set server ranks");
5562 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
5563 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
5564 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
5565 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
5566 cmd_CreateAlias(ts, "sp");
5568 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, NULL, "get server ranks");
5569 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
5570 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
5571 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
5572 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
5573 cmd_CreateAlias(ts, "gp");
5575 ts = cmd_CreateSyntax("setacl", SetACLCmd, NULL, "set access control list");
5576 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5577 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
5578 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
5579 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
5580 parm_setacl_id = ts->nParms;
5581 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
5582 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
5583 cmd_CreateAlias(ts, "sa");
5585 ts = cmd_CreateSyntax("listacl", ListACLCmd, NULL, "list access control list");
5586 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5587 parm_listacl_id = ts->nParms;
5588 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
5589 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
5590 cmd_AddParm(ts, "-cmd", CMD_FLAG, CMD_OPTIONAL, "output as 'fs setacl' command");
5591 cmd_CreateAlias(ts, "la");
5593 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, NULL, "clean up access control list");
5594 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5596 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, NULL, "copy access control list");
5597 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
5598 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
5599 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
5600 parm_copyacl_id = ts->nParms;
5601 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
5602 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
5604 cmd_CreateAlias(ts, "ca");
5606 ts = cmd_CreateSyntax("flush", FlushCmd, NULL, "flush file from cache");
5607 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5608 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5611 ts = cmd_CreateSyntax("flushmount", FlushMountCmd, NULL,
5612 "flush mount symlink from cache");
5613 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5616 ts = cmd_CreateSyntax("setvol", SetVolCmd, NULL, "set volume status");
5617 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5618 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
5620 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
5622 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
5623 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
5624 cmd_CreateAlias(ts, "sv");
5626 ts = cmd_CreateSyntax("messages", MessagesCmd, NULL, "control Cache Manager messages");
5627 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
5629 ts = cmd_CreateSyntax("examine", ExamineCmd, NULL, "display file/volume status");
5630 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5631 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5632 cmd_CreateAlias(ts, "lv");
5633 cmd_CreateAlias(ts, "listvol");
5635 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, NULL, "list volume quota");
5636 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5637 cmd_CreateAlias(ts, "lq");
5639 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, NULL, "show server disk space usage");
5640 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5641 cmd_CreateAlias(ts, "df");
5643 ts = cmd_CreateSyntax("quota", QuotaCmd, NULL, "show volume quota usage");
5644 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5646 ts = cmd_CreateSyntax("lsmount", ListMountCmd, NULL, "list mount point");
5647 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5649 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, NULL, "make mount point");
5650 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
5651 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
5652 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
5653 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
5654 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
5660 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
5664 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, NULL, "remove mount point");
5665 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
5667 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, NULL, "check local cell's servers");
5668 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
5669 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
5670 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
5671 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
5673 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd, NULL, "check volumeID/name mappings");
5674 cmd_CreateAlias(ts, "checkbackups");
5677 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, NULL, "set cache size");
5678 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
5679 cmd_CreateAlias(ts, "cachesize");
5681 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
5683 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, NULL, "get cache usage info");
5685 ts = cmd_CreateSyntax("listcells", ListCellsCmd, NULL, "list configured cells");
5686 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
5688 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, NULL, "set volume quota");
5689 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
5690 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
5692 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
5694 cmd_CreateAlias(ts, "sq");
5696 ts = cmd_CreateSyntax("newcell", NewCellCmd, NULL, "configure new cell");
5698 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
5699 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
5700 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
5702 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
5704 * Turn this on only if you wish to be able to talk to a server which is listening
5705 * on alternative ports. This is not intended for general use and may not be
5706 * supported in the cache manager. It is not a way to run two servers at the
5707 * same host, since the cache manager cannot properly distinguish those two hosts.
5709 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
5710 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
5713 ts = cmd_CreateSyntax("newalias", NewAliasCmd, NULL,
5714 "configure new cell alias");
5715 cmd_AddParm(ts, "-alias", CMD_SINGLE, 0, "alias name");
5716 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "real name of cell");
5719 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, NULL, "list file's cell");
5720 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5721 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5723 ts = cmd_CreateSyntax("whereis", WhereIsCmd, NULL, "list file's location");
5724 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5725 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5727 ts = cmd_CreateSyntax("wscell", WSCellCmd, NULL, "list workstation's cell");
5730 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
5733 #ifndef AFS_NT40_ENV
5734 ts = cmd_CreateSyntax("monitor", MonitorCmd, NULL, "set cache monitor host address");
5735 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
5736 cmd_CreateAlias(ts, "mariner");
5739 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, NULL, "get cell status");
5740 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
5742 ts = cmd_CreateSyntax("setcell", SetCellCmd, NULL, "set cell status");
5743 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
5744 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
5745 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
5747 ts = cmd_CreateSyntax("flushall", FlushAllCmd, NULL, "flush all data");
5749 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, NULL, "flush all data in volume");
5750 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5752 ts = cmd_CreateSyntax("sysname", SysNameCmd, NULL, "get/set sysname (i.e. @sys) value");
5753 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
5755 #ifndef AFS_NT40_ENV
5756 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, NULL, "enable/disable translators to AFS");
5757 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
5758 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
5759 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
5760 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
5761 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
5764 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, NULL,
5765 "store to server after file close");
5766 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
5767 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
5768 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
5769 cmd_CreateAlias(ts, "sb");
5771 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, NULL, "set cache manager encryption flag");
5772 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
5774 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, NULL, "get cache manager encryption flag");
5776 ts = cmd_CreateSyntax("rxstatproc", RxStatProcCmd, NULL,
5777 "Manage per process RX statistics");
5778 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
5779 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
5780 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
5782 ts = cmd_CreateSyntax("rxstatpeer", RxStatPeerCmd, NULL,
5783 "Manage per peer RX statistics");
5784 cmd_AddParm(ts, "-enable", CMD_FLAG, CMD_OPTIONAL, "Enable RX stats");
5785 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "Disable RX stats");
5786 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "Clear RX stats");
5789 ts = cmd_CreateSyntax("setcbaddr", CallBackRxConnCmd, NULL, "configure callback connection address");
5790 cmd_AddParm(ts, "-addr", CMD_SINGLE, CMD_OPTIONAL, "host name or address");
5793 ts = cmd_CreateSyntax("trace", TraceCmd, NULL, "enable or disable CM tracing");
5794 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
5795 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
5796 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
5797 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
5798 cmd_CreateAlias(ts, "tr");
5800 ts = cmd_CreateSyntax("uuid", UuidCmd, NULL, "manage the UUID for the cache manager");
5801 cmd_AddParm(ts, "-generate", CMD_FLAG, CMD_OPTIONAL, "generate a new UUID");
5803 ts = cmd_CreateSyntax("memdump", MemDumpCmd, NULL, "dump memory allocs in debug builds");
5804 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
5805 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
5807 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, NULL, "change client side caching policy for AFS shares");
5808 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
5809 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
5810 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
5811 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
5812 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
5814 ts = cmd_CreateSyntax("minidump", MiniDumpCmd, NULL, "Generate MiniDump of current service state");
5816 ts = cmd_CreateSyntax("test_volstat", TestVolStatCmd, NULL, (char *)CMD_HIDDEN);
5817 cmd_AddParm(ts, "-network", CMD_SINGLE, CMD_OPTIONAL, "set network state up or down");
5818 cmd_AddParm(ts, "-check", CMD_FLAG, CMD_OPTIONAL, "check state of offline volumes");
5819 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name or number");
5820 cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL, "volume name or number");
5821 cmd_AddParm(ts, "-state", CMD_SINGLE, CMD_OPTIONAL, "new volume state: online, busy, offline, down");
5823 ts = cmd_CreateSyntax("smbunicode", SmbUnicodeCmd, NULL, "enable or disable Unicode on new SMB connections");
5824 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable Unicode on new connections");
5825 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable Unicode on new connections");
5827 ts = cmd_CreateSyntax("getfid", GetFidCmd, NULL, "get file id for object(s) in afs");
5828 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5829 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5831 ts = cmd_CreateSyntax("chown", ChOwnCmd, NULL, "set owner for object(s) in afs");
5832 cmd_AddParm(ts, "-owner", CMD_SINGLE, 0, "user name or id");
5833 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5834 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5836 ts = cmd_CreateSyntax("chgrp", ChGrpCmd, NULL, "set owner for object(s) in afs");
5837 cmd_AddParm(ts, "-group", CMD_SINGLE, 0, "user/group name or id");
5838 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
5839 cmd_AddParm(ts, "-literal", CMD_FLAG, CMD_OPTIONAL, "literal evaluation of mountpoints and symlinks");
5841 code = cmd_Dispatch(argc, argv);
5846 FreeUtf8CmdLine(argc, argv);
5852 Die(int code, char *filename)
5855 if (code == EINVAL) {
5857 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
5859 fprintf(stderr,"%s: Invalid argument.\n", pn);
5861 else if (code == ENOENT) {
5863 fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
5865 fprintf(stderr,"%s: no such file returned\n", pn);
5867 else if (code == EROFS)
5868 fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
5869 else if (code == EACCES || code == EPERM) {
5871 fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
5873 fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
5875 else if (code == ENODEV) {
5876 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
5878 else if (code == ESRCH) { /* hack */
5879 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
5881 else if (code == EPIPE) { /* hack */
5882 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
5884 else if (code == EFBIG) {
5885 fprintf(stderr,"%s: Cache size too large.\n", pn);
5887 else if (code == ETIMEDOUT) {
5889 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
5891 fprintf(stderr,"%s: Connection timed out", pn);
5893 else if (code == EBUSY) {
5895 fprintf(stderr,"%s: All servers are busy on which '%s' resides\n", pn, filename);
5897 fprintf(stderr,"%s: All servers are busy\n", pn);
5899 else if (code == ENXIO) {
5901 fprintf(stderr,"%s: All volume instances are offline on which '%s' resides\n", pn, filename);
5903 fprintf(stderr,"%s: All volume instances are offline\n", pn);
5905 else if (code == ENOSYS) {
5907 fprintf(stderr,"%s: All servers are down on which '%s' resides\n", pn, filename);
5909 fprintf(stderr,"%s: All servers are down\n", pn);
5911 else if (code == ECHILD) { /* hack */
5913 fprintf(stderr,"%s: Invalid owner specified for '%s'\n", pn, filename);
5915 fprintf(stderr,"%s: Invalid owner specified\n", pn);
5919 fprintf(stderr,"%s:'%s'", pn, filename);
5921 fprintf(stderr,"%s", pn);
5923 fprintf(stderr, ": code 0x%x\n", code);
5924 #else /* not WIN32 */
5925 fprintf(stderr,": %s\n", afs_error_message(code));
5926 #endif /* not WIN32 */