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>
21 #include <rx/rx_globals.h>
36 #define MAXINSIZE 1300 /* pioctl complains if data is larger than this */
37 #define VMSGSIZE 128 /* size of msg buf in volume hdr */
39 static char space[MAXSIZE];
40 static char tspace[1024];
43 static struct ubik_client *uclient;
44 #endif /* not WIN32 */
46 static MemDumpCmd(struct cmd_syndesc *asp);
47 static CSCPolicyCmd(struct cmd_syndesc *asp);
49 extern afs_int32 VL_GetEntryByNameO();
51 static char pn[] = "fs";
52 static int rxInitDone = 0;
56 #define MAXCELLCHARS 64
57 #define MAXHOSTCHARS 64
58 #define MAXHOSTSPERCELL 8
61 char name[MAXCELLCHARS];
64 struct sockaddr_in hostAddr[MAXHOSTSPERCELL];
65 char hostName[MAXHOSTSPERCELL][MAXHOSTCHARS];
71 * Character to use between name and rights in printed representation for
74 #define DFS_SEPARATOR ' '
76 typedef char sec_rgy_name_t[1025]; /* A DCE definition */
79 int dfs; /* Originally true if a dfs acl; now also the type
80 of the acl (1, 2, or 3, corresponding to object,
81 initial dir, or initial object). */
82 sec_rgy_name_t cell; /* DFS cell name */
85 struct AclEntry *pluslist;
86 struct AclEntry *minuslist;
90 struct AclEntry *next;
97 ZapList(acl->pluslist);
98 ZapList(acl->minuslist);
109 if (t >= 'A' && t <= 'Z') t += 0x20;
110 if (u >= 'A' && u <= 'Z') u += 0x20;
111 if (t != u) return 1;
112 if (t == 0) return 0;
117 * Mods for the AFS/DFS protocol translator.
119 * DFS rights. It's ugly to put these definitions here, but they
120 * *cannot* change, because they're part of the wire protocol.
121 * In any event, the protocol translator will guarantee these
122 * assignments for AFS cache managers.
124 #define DFS_READ 0x01
125 #define DFS_WRITE 0x02
126 #define DFS_EXECUTE 0x04
127 #define DFS_CONTROL 0x08
128 #define DFS_INSERT 0x10
129 #define DFS_DELETE 0x20
131 /* the application definable ones (backwards from AFS) */
132 #define DFS_USR0 0x80000000 /* "A" bit */
133 #define DFS_USR1 0x40000000 /* "B" bit */
134 #define DFS_USR2 0x20000000 /* "C" bit */
135 #define DFS_USR3 0x10000000 /* "D" bit */
136 #define DFS_USR4 0x08000000 /* "E" bit */
137 #define DFS_USR5 0x04000000 /* "F" bit */
138 #define DFS_USR6 0x02000000 /* "G" bit */
139 #define DFS_USR7 0x01000000 /* "H" bit */
140 #define DFS_USRALL (DFS_USR0 | DFS_USR1 | DFS_USR2 | DFS_USR3 |\
141 DFS_USR4 | DFS_USR5 | DFS_USR6 | DFS_USR7)
144 * Offset of -id switch in command structure for various commands.
145 * The -if switch is the next switch always.
147 int parm_setacl_id, parm_copyacl_id, parm_listacl_id;
150 * Determine whether either the -id or -if switches are present, and
151 * return 0, 1 or 2, as appropriate. Abort if both switches are present.
154 struct cmd_syndesc *as;
155 int id; /* Offset of -id switch; -if is next switch */
159 if (as->parms[id].items) {
162 if (as->parms[id + 1].items) {
168 "%s: you may specify either -id or -if, but not both switches\n",
175 void PRights (arights, dfs)
176 register afs_int32 arights;
180 if (arights & PRSFS_READ) printf("r");
181 if (arights & PRSFS_LOOKUP) printf("l");
182 if (arights & PRSFS_INSERT) printf("i");
183 if (arights & PRSFS_DELETE) printf("d");
184 if (arights & PRSFS_WRITE) printf("w");
185 if (arights & PRSFS_LOCK) printf("k");
186 if (arights & PRSFS_ADMINISTER) printf("a");
187 if (arights & PRSFS_USR0) printf("A");
188 if (arights & PRSFS_USR1) printf("B");
189 if (arights & PRSFS_USR2) printf("C");
190 if (arights & PRSFS_USR3) printf("D");
191 if (arights & PRSFS_USR4) printf("E");
192 if (arights & PRSFS_USR5) printf("F");
193 if (arights & PRSFS_USR6) printf("G");
194 if (arights & PRSFS_USR7) printf("H");
196 if (arights & DFS_READ) printf("r"); else printf("-");
197 if (arights & DFS_WRITE) printf("w"); else printf("-");
198 if (arights & DFS_EXECUTE) printf("x"); else printf("-");
199 if (arights & DFS_CONTROL) printf("c"); else printf("-");
200 if (arights & DFS_INSERT) printf("i"); else printf("-");
201 if (arights & DFS_DELETE) printf("d"); else printf("-");
202 if (arights & (DFS_USRALL)) printf("+");
203 if (arights & DFS_USR0) printf("A");
204 if (arights & DFS_USR1) printf("B");
205 if (arights & DFS_USR2) printf("C");
206 if (arights & DFS_USR3) printf("D");
207 if (arights & DFS_USR4) printf("E");
208 if (arights & DFS_USR5) printf("F");
209 if (arights & DFS_USR6) printf("G");
210 if (arights & DFS_USR7) printf("H");
214 /* this function returns TRUE (1) if the file is in AFS, otherwise false (0) */
215 static int InAFS(apath)
216 register char *apath; {
217 struct ViceIoctl blob;
218 register afs_int32 code;
221 blob.out_size = MAXSIZE;
224 code = pioctl(apath, VIOC_FILE_CELL_NAME, &blob, 1);
226 if ((errno == EINVAL) || (errno == ENOENT)) return 0;
231 /* return a static pointer to a buffer */
232 static char *Parent(apath)
235 strcpy(tspace, apath);
236 tp = strrchr(tspace, '\\');
238 *(tp+1) = 0; /* lv trailing slash so Parent("k:\foo") is "k:\" not "k:" */
241 fs_ExtractDriveLetter(apath, tspace);
247 enum rtype {add, destroy, deny};
249 afs_int32 Convert(arights, dfs, rtypep)
250 register char *arights;
258 *rtypep = add; /* add rights, by default */
261 if (!strcmp(arights, "null")) {
265 if (!strcmp(arights,"read")) return DFS_READ | DFS_EXECUTE;
266 if (!strcmp(arights, "write")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE;
267 if (!strcmp(arights, "all")) return DFS_READ | DFS_EXECUTE | DFS_INSERT | DFS_DELETE | DFS_WRITE | DFS_CONTROL;
269 if (!strcmp(arights,"read")) return PRSFS_READ | PRSFS_LOOKUP;
270 if (!strcmp(arights, "write")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK;
271 if (!strcmp(arights, "mail")) return PRSFS_INSERT | PRSFS_LOCK | PRSFS_LOOKUP;
272 if (!strcmp(arights, "all")) return PRSFS_READ | PRSFS_LOOKUP | PRSFS_INSERT | PRSFS_DELETE | PRSFS_WRITE | PRSFS_LOCK | PRSFS_ADMINISTER;
274 if (!strcmp(arights, "none")) {
275 *rtypep = destroy; /* Remove entire entry */
278 len = strlen(arights);
283 if (tc == '-') continue;
284 else if (tc == 'r') mode |= DFS_READ;
285 else if (tc == 'w') mode |= DFS_WRITE;
286 else if (tc == 'x') mode |= DFS_EXECUTE;
287 else if (tc == 'c') mode |= DFS_CONTROL;
288 else if (tc == 'i') mode |= DFS_INSERT;
289 else if (tc == 'd') mode |= DFS_DELETE;
290 else if (tc == 'A') mode |= DFS_USR0;
291 else if (tc == 'B') mode |= DFS_USR1;
292 else if (tc == 'C') mode |= DFS_USR2;
293 else if (tc == 'D') mode |= DFS_USR3;
294 else if (tc == 'E') mode |= DFS_USR4;
295 else if (tc == 'F') mode |= DFS_USR5;
296 else if (tc == 'G') mode |= DFS_USR6;
297 else if (tc == 'H') mode |= DFS_USR7;
299 fprintf(stderr, "%s: illegal DFS rights character '%c'.\n", pn, tc);
303 if (tc == 'r') mode |= PRSFS_READ;
304 else if (tc == 'l') mode |= PRSFS_LOOKUP;
305 else if (tc == 'i') mode |= PRSFS_INSERT;
306 else if (tc == 'd') mode |= PRSFS_DELETE;
307 else if (tc == 'w') mode |= PRSFS_WRITE;
308 else if (tc == 'k') mode |= PRSFS_LOCK;
309 else if (tc == 'a') mode |= PRSFS_ADMINISTER;
310 else if (tc == 'A') mode |= PRSFS_USR0;
311 else if (tc == 'B') mode |= PRSFS_USR1;
312 else if (tc == 'C') mode |= PRSFS_USR2;
313 else if (tc == 'D') mode |= PRSFS_USR3;
314 else if (tc == 'E') mode |= PRSFS_USR4;
315 else if (tc == 'F') mode |= PRSFS_USR5;
316 else if (tc == 'G') mode |= PRSFS_USR6;
317 else if (tc == 'H') mode |= PRSFS_USR7;
319 fprintf(stderr, "%s: illegal rights character '%c'.\n", pn, tc);
327 struct AclEntry *FindList (alist, aname)
329 register struct AclEntry *alist; {
331 if (!foldcmp(alist->name, aname)) return alist;
337 /* if no parm specified in a particular slot, set parm to be "." instead */
338 static void SetDotDefault(aitemp)
339 struct cmd_item **aitemp; {
340 register struct cmd_item *ti;
341 if (*aitemp) return; /* already has value */
342 /* otherwise, allocate an item representing "." */
343 ti = (struct cmd_item *) malloc(sizeof(struct cmd_item));
344 ti->next = (struct cmd_item *) 0;
345 ti->data = (char *) malloc(2);
346 strcpy(ti->data, ".");
350 void ChangeList (al, plus, aname, arights)
353 afs_int32 arights, plus; {
354 struct AclEntry *tlist;
355 tlist = (plus ? al->pluslist : al->minuslist);
356 tlist = FindList (tlist, aname);
358 /* Found the item already in the list. */
359 tlist->rights = arights;
361 al->nplus -= PruneList(&al->pluslist, al->dfs);
363 al->nminus -= PruneList(&al->minuslist, al->dfs);
366 /* Otherwise we make a new item and plug in the new data. */
367 tlist = (struct AclEntry *) malloc(sizeof (struct AclEntry));
368 strcpy(tlist->name, aname);
369 tlist->rights = arights;
371 tlist->next = al->pluslist;
372 al->pluslist = tlist;
374 if (arights == 0 || arights == -1)
375 al->nplus -= PruneList(&al->pluslist, al->dfs);
378 tlist->next = al->minuslist;
379 al->minuslist = tlist;
381 if (arights == 0) al->nminus -= PruneList(&al->minuslist, al->dfs);
386 struct AclEntry *alist; {
387 register struct AclEntry *tp, *np;
388 for (tp = alist; tp; tp = np) {
394 int PruneList (ae, dfs)
395 struct AclEntry **ae;
398 struct AclEntry **lp;
399 struct AclEntry *te, *ne;
403 for(te = *ae;te;te=ne) {
404 if ((!dfs && te->rights == 0) || te->rights == -1) {
418 char *SkipLine (astr)
419 register char *astr; {
420 while (*astr !='\n') astr++;
426 * Create an empty acl, taking into account whether the acl pointed
427 * to by astr is an AFS or DFS acl. Only parse this minimally, so we
428 * can recover from problems caused by bogus ACL's (in that case, always
429 * assume that the acl is AFS: for DFS, the user can always resort to
430 * acl_edit, but for AFS there may be no other way out).
432 struct Acl *EmptyAcl(astr)
435 register struct Acl *tp;
438 tp = (struct Acl *)malloc(sizeof (struct Acl));
439 tp->nplus = tp->nminus = 0;
440 tp->pluslist = tp->minuslist = 0;
442 sscanf(astr, "%d dfs:%d %s", &junk, &tp->dfs, tp->cell);
446 struct Acl *ParseAcl (astr)
448 int nplus, nminus, i, trights;
450 struct AclEntry *first, *last, *tl;
453 ta = (struct Acl *) malloc (sizeof (struct Acl));
455 sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell);
456 astr = SkipLine(astr);
457 sscanf(astr, "%d", &ta->nminus);
458 astr = SkipLine(astr);
465 for(i=0;i<nplus;i++) {
466 sscanf(astr, "%100s %d", tname, &trights);
467 astr = SkipLine(astr);
468 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
469 if (!first) first = tl;
470 strcpy(tl->name, tname);
471 tl->rights = trights;
473 if (last) last->next = tl;
476 ta->pluslist = first;
480 for(i=0;i<nminus;i++) {
481 sscanf(astr, "%100s %d", tname, &trights);
482 astr = SkipLine(astr);
483 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
484 if (!first) first = tl;
485 strcpy(tl->name, tname);
486 tl->rights = trights;
488 if (last) last->next = tl;
491 ta->minuslist = first;
496 void PrintStatus(status, name, motd, offmsg)
497 VolumeStatus *status;
501 printf("Volume status for vid = %u named %s\n",status->Vid, name);
503 printf("Current offline message is %s\n",offmsg);
505 printf("Current message of the day is %s\n",motd);
506 printf("Current disk quota is ");
507 if (status->MaxQuota != 0) printf("%d\n", status->MaxQuota);
508 else printf("unlimited\n");
509 printf("Current blocks used are %d\n",status->BlocksInUse);
510 printf("The partition has %d blocks available out of %d\n\n",status->PartBlocksAvail, status->PartMaxBlocks);
513 void QuickPrintStatus(status, name)
514 VolumeStatus *status;
516 double QuotaUsed =0.0;
517 double PartUsed =0.0;
519 printf("%-25.25s",name);
521 if (status->MaxQuota != 0) {
522 printf("%10d%10d", status->MaxQuota, status->BlocksInUse);
523 QuotaUsed = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
525 printf("no limit%10d", status->BlocksInUse);
527 if (QuotaUsed > 90.0){
528 printf(" %5.0f%%<<", QuotaUsed);
531 else printf(" %5.0f%% ", QuotaUsed);
532 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
533 if (PartUsed > 97.0){
534 printf(" %9.0f%%<<", PartUsed);
537 else printf(" %9.0f%% ", PartUsed);
539 printf("\t<<WARNING\n");
544 void QuickPrintSpace(status, name)
545 VolumeStatus *status;
547 double PartUsed =0.0;
549 printf("%-25.25s",name);
551 printf("%10d%10d%10d", status->PartMaxBlocks, status->PartMaxBlocks - status->PartBlocksAvail, status->PartBlocksAvail);
553 PartUsed = (100.0 - ((((double)status->PartBlocksAvail)/status->PartMaxBlocks) * 100.0));
554 if (PartUsed > 90.0){
555 printf(" %4.0f%%<<", PartUsed);
558 else printf(" %4.0f%% ", PartUsed);
560 printf("\t<<WARNING\n");
565 char *AclToString(acl)
567 static char mydata[MAXSIZE];
568 char tstring[MAXSIZE];
572 if (acl->dfs) sprintf(dfsstring, " dfs:%d %s", acl->dfs, acl->cell);
573 else dfsstring[0] = '\0';
574 sprintf(mydata, "%d%s\n%d\n", acl->nplus, dfsstring, acl->nminus);
575 for(tp = acl->pluslist;tp;tp=tp->next) {
576 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
577 strcat(mydata, tstring);
579 for(tp = acl->minuslist;tp;tp=tp->next) {
580 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
581 strcat(mydata, tstring);
586 #define AFSCLIENT_ADMIN_GROUPNAME "AFS Client Admins"
590 static BOOL fAdmin = FALSE;
591 static BOOL fTested = FALSE;
595 /* Obtain the SID for the AFS client admin group. If the group does
596 * not exist, then assume we have AFS client admin privileges.
598 PSID psidAdmin = NULL;
599 DWORD dwSize, dwSize2;
600 char pszAdminGroup[ MAX_COMPUTERNAME_LENGTH + sizeof(AFSCLIENT_ADMIN_GROUPNAME) + 2 ];
601 char *pszRefDomain = NULL;
602 SID_NAME_USE snu = SidTypeGroup;
604 dwSize = sizeof(pszAdminGroup);
606 if (!GetComputerName(pszAdminGroup, &dwSize)) {
607 /* Can't get computer name. We return false in this case.
608 Retain fAdmin and fTested. This shouldn't happen.*/
615 strcat(pszAdminGroup,"\\");
616 strcat(pszAdminGroup, AFSCLIENT_ADMIN_GROUPNAME);
618 LookupAccountName(NULL, pszAdminGroup, NULL, &dwSize, NULL, &dwSize2, &snu);
619 /* that should always fail. */
621 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
622 /* if we can't find the group, then we allow the operation */
627 if (dwSize == 0 || dwSize2 == 0) {
633 psidAdmin = (PSID)malloc(dwSize); memset(psidAdmin,0,dwSize);
634 pszRefDomain = (char *)malloc(dwSize2);
636 if (!LookupAccountName(NULL, pszAdminGroup, psidAdmin, &dwSize, pszRefDomain, &dwSize2, &snu)) {
637 /* We can't lookup the group now even though we looked it up earlier.
638 Could this happen? */
641 /* Then open our current ProcessToken */
644 if (OpenProcessToken (GetCurrentProcess(), TOKEN_QUERY, &hToken))
647 if (!CheckTokenMembership(hToken, psidAdmin, &fAdmin)) {
648 /* We'll have to allocate a chunk of memory to store the list of
649 * groups to which this user belongs; find out how much memory
653 PTOKEN_GROUPS pGroups;
655 GetTokenInformation (hToken, TokenGroups, NULL, dwSize, &dwSize);
657 pGroups = (PTOKEN_GROUPS)malloc(dwSize);
659 /* Allocate that buffer, and read in the list of groups. */
660 if (GetTokenInformation (hToken, TokenGroups, pGroups, dwSize, &dwSize))
662 /* Look through the list of group SIDs and see if any of them
663 * matches the AFS Client Admin group SID.
666 for (; (!fAdmin) && (iGroup < pGroups->GroupCount); ++iGroup)
668 if (EqualSid (psidAdmin, pGroups->Groups[ iGroup ].Sid)) {
678 /* if do not have permission because we were not explicitly listed
679 * in the Admin Client Group let's see if we are the SYSTEM account
682 PTOKEN_USER pTokenUser;
683 SID_IDENTIFIER_AUTHORITY SIDAuth = SECURITY_NT_AUTHORITY;
684 PSID pSidLocalSystem = 0;
687 GetTokenInformation(hToken, TokenUser, NULL, 0, &dwSize);
689 pTokenUser = (PTOKEN_USER)malloc(dwSize);
691 if (!GetTokenInformation(hToken, TokenUser, pTokenUser, dwSize, &dwSize))
692 gle = GetLastError();
694 if (AllocateAndInitializeSid( &SIDAuth, 1,
695 SECURITY_LOCAL_SYSTEM_RID,
699 if (EqualSid(pTokenUser->User.Sid, pSidLocalSystem)) {
703 FreeSid(pSidLocalSystem);
722 struct cmd_syndesc *as; {
723 register afs_int32 code;
724 struct ViceIoctl blob;
726 register struct cmd_item *ti, *ui;
730 int idf = getidf(as, parm_setacl_id);
732 if (as->parms[2].items) clear=1;
734 plusp = !(as->parms[3].items);
735 for(ti=as->parms[0].items; ti;ti=ti->next) {
736 blob.out_size = MAXSIZE;
738 blob.in = blob.out = space;
739 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
741 Die(errno, ti->data);
744 ta = ParseAcl(space);
745 if (!plusp && ta->dfs) {
747 "fs: %s: you may not use the -negative switch with DFS acl's.\n%s",
749 "(you may specify \"null\" to revoke all rights, however)\n");
752 if (clear) ta = EmptyAcl(space);
753 else ta = ParseAcl(space);
755 for(ui=as->parms[1].items; ui; ui=ui->next->next) {
758 fprintf(stderr,"%s: Missing second half of user/access pair.\n", pn);
761 rights = Convert(ui->next->data, ta->dfs, &rtype);
762 if (rtype == destroy && !ta->dfs) {
763 if (!FindList(ta->pluslist, ui->data)) {
764 fprintf(stderr,"%s: Invalid arg (%s doesn't exist in the current acl)\n", pn, ui->data);
768 if (rtype == deny && !ta->dfs) plusp = 0;
769 if (rtype == destroy && ta->dfs) rights = -1;
770 ChangeList(ta, plusp, ui->data, rights);
772 blob.in = AclToString(ta);
774 blob.in_size = 1+strlen(blob.in);
775 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
777 if (errno == EINVAL) {
779 static char *fsenv = 0;
781 fsenv = (char *)getenv("FS_EXPERT");
783 fprintf(stderr, "fs: \"Invalid argument\" was returned when you tried to store a DFS access list.\n");
786 "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
787 "\nPossible reasons for this include:\n\n",
788 " -You may have specified an inappropriate combination of rights.\n",
789 " For example, some DFS-supported filesystems may not allow you to\n",
790 " drop the \"c\" right from \"user_obj\".\n\n",
791 " -A mask_obj may be required (it is likely required by the underlying\n",
792 " filesystem if you try to set anything other than the basic \"user_obj\"\n",
793 " \"mask_obj\", or \"group_obj\" entries). Unlike acl_edit, the fs command\n",
794 " does not automatically create or update the mask_obj. Try setting\n",
795 " the rights \"mask_obj all\" with \"fs sa\" before adding any explicit\n",
796 " users or groups. You can do this with a single command, such as\n",
797 " \"fs sa mask_obj all user:somename read\"\n\n",
798 " -A specified user or group may not exist.\n\n",
799 " -You may have tried to delete \"user_obj\", \"group_obj\", or \"other_obj\".\n",
800 " This is probably not allowed by the underlying file system.\n\n",
801 " -If you add a user or group to a DFS ACL, remember that it must be\n",
802 " fully specified as \"user:username\" or \"group:groupname\". In addition, there\n",
803 " may be local requirements on the format of the user or group name.\n",
804 " Check with your cell administrator.\n\n",
805 " -Or numerous other possibilities. It would be great if we could be more\n",
806 " precise about the actual problem, but for various reasons, this is\n",
807 " impractical via this interface. If you can't figure it out, you\n",
808 " might try logging into a DCE-equipped machine and use acl_edit (or\n",
809 " whatever is provided). You may get better results. Good luck!\n\n",
810 " (You may inhibit this message by setting \"FS_EXPERT\" in your environment)\n");
813 fprintf(stderr,"%s: Invalid argument, possible reasons include:\n", pn);
814 fprintf(stderr,"\t-File not in AFS\n");
815 fprintf(stderr,"\t-Too many users on access control list\n");
816 fprintf(stderr,"\t-Tried to add non-existent user to access control list\n");
821 Die(errno, ti->data);
830 static CopyACLCmd(as)
831 struct cmd_syndesc *as; {
832 register afs_int32 code;
833 struct ViceIoctl blob;
836 register struct cmd_item *ti;
838 int idf = getidf(as, parm_copyacl_id);
840 if (as->parms[2].items) clear=1;
842 blob.out_size = MAXSIZE;
844 blob.in = blob.out = space;
845 code = pioctl(as->parms[0].items->data, VIOCGETAL, &blob, 1);
847 Die(errno, as->parms[0].items->data);
850 fa = ParseAcl(space);
852 for (ti=as->parms[1].items; ti;ti=ti->next) {
853 blob.out_size = MAXSIZE;
855 blob.in = blob.out = space;
856 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
858 Die(errno, ti->data);
861 if (clear) ta = EmptyAcl(space);
862 else ta = ParseAcl(space);
864 if (ta->dfs != fa->dfs) {
865 fprintf(stderr, "fs: incompatible file system types: acl not copied to %s; aborted\n", ti->data);
869 if (! clear && strcmp(ta->cell, fa->cell) != 0) {
870 fprintf(stderr, "fs: default DCE cell differs for file %s: use \"-clear\" switch; acl not merged\n", ti->data);
873 strcpy(ta->cell, fa->cell);
875 for (tp = fa->pluslist;tp;tp=tp->next)
876 ChangeList(ta, 1, tp->name, tp->rights);
877 for (tp = fa->minuslist;tp;tp=tp->next)
878 ChangeList(ta, 0, tp->name, tp->rights);
879 blob.in = AclToString(ta);
881 blob.in_size = 1+strlen(blob.in);
882 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
884 if (errno == EINVAL) {
885 fprintf(stderr,"%s: Invalid argument, possible reasons include:\n", pn);
886 fprintf(stderr,"\t-File not in AFS\n");
890 Die(errno, ti->data);
902 /* tell if a name is 23 or -45 (digits or minus digits), which are bad names we must prune */
903 static BadName(aname)
904 register char *aname; {
906 while(tc = *aname++) {
907 /* all must be '-' or digit to be bad */
908 if (tc != '-' && (tc < '0' || tc > '9')) return 0;
914 /* clean up an access control list of its bad entries; return 1 if we made
915 any changes to the list, and 0 otherwise */
918 register struct AclEntry *te, **le, *ne;
921 /* Don't correct DFS ACL's for now */
925 /* prune out bad entries */
926 changes = 0; /* count deleted entries */
928 for(te = aa->pluslist; te; te=ne) {
930 if (BadName(te->name)) {
942 for(te = aa->minuslist; te; te=ne) {
944 if (BadName(te->name)) {
959 /* clean up an acl to not have bogus entries */
960 static CleanACLCmd(as)
961 register struct cmd_syndesc *as; {
962 register afs_int32 code;
963 register struct Acl *ta;
964 struct ViceIoctl blob;
966 register struct cmd_item *ti;
967 register struct AclEntry *te;
969 SetDotDefault(&as->parms[0].items);
970 for(ti=as->parms[0].items; ti; ti=ti->next) {
971 blob.out_size = MAXSIZE;
974 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
976 Die(errno, ti->data);
979 ta = ParseAcl(space);
983 "%s: cleanacl is not supported for DFS access lists.\n",
988 changes = CleanAcl(ta);
991 /* now set the acl */
992 blob.in=AclToString(ta);
993 blob.in_size = strlen(blob.in)+1;
995 code = pioctl(ti->data, VIOCSETAL, &blob, 1);
997 if (errno == EINVAL) {
998 fprintf(stderr,"%s: Invalid argument, possible reasons include\n", pn);
999 fprintf(stderr,"%s: File not in vice or\n", pn);
1000 fprintf(stderr,"%s: Too many users on access control list or\n", pn);
1004 Die(errno, ti->data);
1009 /* now list the updated acl */
1010 printf("Access list for %s is now\n", ti->data);
1011 if (ta->nplus > 0) {
1012 if (!ta->dfs) printf("Normal rights:\n");
1013 for(te = ta->pluslist;te;te=te->next) {
1014 printf(" %s ", te->name);
1015 PRights(te->rights, ta->dfs);
1019 if (ta->nminus > 0) {
1020 printf("Negative rights:\n");
1021 for(te = ta->minuslist;te;te=te->next) {
1022 printf(" %s ", te->name);
1023 PRights(te->rights, ta->dfs);
1027 if (ti->next) printf("\n");
1030 printf("Access list for %s is fine.\n", ti->data);
1035 static ListACLCmd(as)
1036 register struct cmd_syndesc *as; {
1037 register afs_int32 code;
1038 register struct Acl *ta;
1039 struct ViceIoctl blob;
1040 struct AclEntry *te;
1041 register struct cmd_item *ti;
1042 int idf = getidf(as, parm_listacl_id);
1044 SetDotDefault(&as->parms[0].items);
1045 for(ti=as->parms[0].items; ti; ti=ti->next) {
1047 blob.out_size = MAXSIZE;
1049 blob.in = blob.out = space;
1050 code = pioctl(ti->data, VIOCGETAL, &blob, 1);
1052 Die(errno, ti->data);
1055 ta = ParseAcl(space);
1058 printf("Access list for %s is\n", ti->data);
1061 printf("DFS access list for %s is\n", ti->data);
1064 printf("DFS initial directory access list of %s is\n", ti->data);
1067 printf("DFS initial file access list of %s is\n", ti->data);
1071 printf(" Default cell = %s\n", ta->cell);
1073 separator = ta->dfs? DFS_SEPARATOR : ' ';
1074 if (ta->nplus > 0) {
1075 if (!ta->dfs) printf("Normal rights:\n");
1076 for(te = ta->pluslist;te;te=te->next) {
1077 printf(" %s%c", te->name, separator);
1078 PRights(te->rights, ta->dfs);
1082 if (ta->nminus > 0) {
1083 printf("Negative rights:\n");
1084 for(te = ta->minuslist;te;te=te->next) {
1085 printf(" %s ", te->name);
1086 PRights(te->rights, ta->dfs);
1090 if (ti->next) printf("\n");
1095 static FlushVolumeCmd(as)
1096 register struct cmd_syndesc *as; {
1097 register afs_int32 code;
1098 struct ViceIoctl blob;
1099 register struct cmd_item *ti;
1101 for(ti=as->parms[0].items; ti; ti=ti->next) {
1102 blob.in_size = blob.out_size = 0;
1103 code = pioctl(ti->data, VIOC_FLUSHVOLUME, &blob, 0);
1105 fprintf(stderr, "Error flushing volume\n");
1106 Die(errno,ti->data);
1114 register struct cmd_syndesc *as; {
1115 register afs_int32 code;
1116 struct ViceIoctl blob;
1118 register struct cmd_item *ti;
1121 for(ti=as->parms[0].items; ti; ti=ti->next) {
1122 blob.in_size = blob.out_size = 0;
1123 code = pioctl(ti->data, VIOCFLUSH, &blob, 0);
1126 if (errno == EMFILE) {
1127 fprintf(stderr,"%s: Can't flush active file %s\n", pn, ti->data);
1131 fprintf(stderr, "Error flushing file\n");
1132 Die(errno,ti->data);
1140 /* all this command does is repackage its args and call SetVolCmd */
1141 static SetQuotaCmd(as)
1142 register struct cmd_syndesc *as; {
1143 struct cmd_syndesc ts;
1145 /* copy useful stuff from our command slot; we may later have to reorder */
1146 memcpy(&ts, as, sizeof(ts)); /* copy whole thing */
1147 return SetVolCmd(&ts);
1150 static SetVolCmd(as)
1151 register struct cmd_syndesc *as; {
1152 register afs_int32 code;
1153 struct ViceIoctl blob;
1154 register struct cmd_item *ti;
1155 struct VolumeStatus *status;
1156 char *motd, *offmsg, *input;
1158 SetDotDefault(&as->parms[0].items);
1159 for(ti=as->parms[0].items; ti; ti=ti->next) {
1161 blob.out_size = MAXSIZE;
1162 blob.in_size = sizeof(*status) + 3; /* for the three terminating nulls */
1165 status = (VolumeStatus *)space;
1166 status->MinQuota = status->MaxQuota = -1;
1167 motd = offmsg = (char *) 0;
1168 if (as->parms[1].items) {
1169 code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
1171 fprintf(stderr,"fs: bad integer specified for quota.\n");
1175 if (as->parms[2].items) motd = as->parms[2].items->data;
1176 if (as->parms[3].items) offmsg = as->parms[3].items->data;
1177 input = (char *)status + sizeof(*status);
1178 *(input++) = '\0'; /* never set name: this call doesn't change vldb */
1180 if (strlen(offmsg) >= VMSGSIZE) {
1181 fprintf(stderr,"fs: message must be shorter than %d characters\n",
1185 strcpy(input,offmsg);
1186 blob.in_size += strlen(offmsg);
1187 input += strlen(offmsg) + 1;
1189 else *(input++) = '\0';
1191 if (strlen(motd) >= VMSGSIZE) {
1192 fprintf(stderr,"fs: message must be shorter than %d characters\n",
1197 blob.in_size += strlen(motd);
1198 input += strlen(motd) + 1;
1200 else *(input++) = '\0';
1201 code = pioctl(ti->data,VIOCSETVOLSTAT, &blob, 1);
1203 Die(errno, ti->data);
1210 static ExamineCmd(as)
1211 register struct cmd_syndesc *as; {
1212 register afs_int32 code;
1213 struct ViceIoctl blob;
1214 register struct cmd_item *ti;
1215 struct VolumeStatus *status;
1216 char *name, *offmsg, *motd;
1220 SetDotDefault(&as->parms[0].items);
1221 for(ti=as->parms[0].items; ti; ti=ti->next) {
1223 blob.out_size = MAXSIZE;
1226 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1228 Die(errno, ti->data);
1232 status = (VolumeStatus *)space;
1233 name = (char *)status + sizeof(*status);
1234 offmsg = name + strlen(name) + 1;
1235 motd = offmsg + strlen(offmsg) + 1;
1236 PrintStatus(status, name, motd, offmsg);
1241 static ListQuotaCmd(as)
1242 register struct cmd_syndesc *as; {
1243 register afs_int32 code;
1244 struct ViceIoctl blob;
1245 register struct cmd_item *ti;
1246 struct VolumeStatus *status;
1249 printf("%-25s%-10s%-10s%-7s%-13s\n",
1250 "Volume Name", " Quota", " Used", " %Used", " Partition");
1251 SetDotDefault(&as->parms[0].items);
1252 for(ti=as->parms[0].items; ti; ti=ti->next) {
1254 blob.out_size = MAXSIZE;
1257 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1259 Die(errno, ti->data);
1262 status = (VolumeStatus *)space;
1263 name = (char *)status + sizeof(*status);
1264 QuickPrintStatus(status, name);
1269 static WhereIsCmd(as)
1270 register struct cmd_syndesc *as; {
1271 register afs_int32 code;
1272 struct ViceIoctl blob;
1273 register struct cmd_item *ti;
1278 SetDotDefault(&as->parms[0].items);
1279 for(ti=as->parms[0].items; ti; ti=ti->next) {
1281 blob.out_size = MAXSIZE;
1284 memset(space, 0, sizeof(space));
1285 code = pioctl(ti->data, VIOCWHEREIS, &blob, 1);
1287 Die(errno, ti->data);
1290 hosts = (afs_int32 *) space;
1291 printf("File %s is on host%s ", ti->data, (hosts[0] && !hosts[1]) ? "": "s");
1292 for(j=0; j<MAXHOSTS; j++) {
1293 if (hosts[j] == 0) break;
1294 tp = hostutil_GetNameByINet(hosts[j]);
1303 static DiskFreeCmd(as)
1304 register struct cmd_syndesc *as; {
1305 register afs_int32 code;
1306 struct ViceIoctl blob;
1307 register struct cmd_item *ti;
1309 struct VolumeStatus *status;
1311 printf("%-25s%-10s%-10s%-10s%-6s\n", "Volume Name", " kbytes",
1312 " used", " avail", " %used");
1313 SetDotDefault(&as->parms[0].items);
1314 for(ti=as->parms[0].items; ti; ti=ti->next) {
1316 blob.out_size = MAXSIZE;
1319 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1321 Die(errno, ti->data);
1324 status = (VolumeStatus *)space;
1325 name = (char *)status + sizeof(*status);
1326 QuickPrintSpace(status, name);
1332 register struct cmd_syndesc *as; {
1333 register afs_int32 code;
1334 struct ViceIoctl blob;
1335 register struct cmd_item *ti;
1337 struct VolumeStatus *status;
1339 SetDotDefault(&as->parms[0].items);
1340 for(ti=as->parms[0].items; ti; ti=ti->next) {
1342 blob.out_size = MAXSIZE;
1345 code = pioctl(ti->data, VIOCGETVOLSTAT, &blob, 1);
1347 Die(errno, ti->data);
1350 status = (VolumeStatus *)space;
1351 if (status->MaxQuota) quotaPct = ((((double)status->BlocksInUse)/status->MaxQuota) * 100.0);
1352 else quotaPct = 0.0;
1353 printf("%2.0f%% of quota used.\n", quotaPct);
1358 static ListMountCmd(as)
1359 register struct cmd_syndesc *as; {
1360 register afs_int32 code;
1361 struct ViceIoctl blob;
1363 register struct cmd_item *ti;
1364 char orig_name[1024]; /*Original name, may be modified*/
1365 char true_name[1024]; /*``True'' dirname (e.g., symlink target)*/
1366 char parent_dir[1024]; /*Parent directory of true name*/
1367 register char *last_component; /*Last component of true name*/
1369 struct stat statbuff; /*Buffer for status info*/
1370 #endif /* not WIN32 */
1372 int link_chars_read; /*Num chars read in readlink()*/
1373 #endif /* not WIN32 */
1374 int thru_symlink; /*Did we get to a mount point via a symlink?*/
1377 for(ti=as->parms[0].items; ti; ti=ti->next) {
1381 strcpy(orig_name, ti->data);
1382 #else /* not WIN32 */
1383 sprintf(orig_name, "%s%s",
1384 (ti->data[0] == '/') ? "" : "./",
1386 #endif /* not WIN32 */
1389 if (lstat(orig_name, &statbuff) < 0) {
1390 /* if lstat fails, we should still try the pioctl, since it
1391 may work (for example, lstat will fail, but pioctl will
1392 work if the volume of offline (returning ENODEV). */
1393 statbuff.st_mode = S_IFDIR; /* lie like pros */
1397 * The lstat succeeded. If the given file is a symlink, substitute
1398 * the file name with the link name.
1400 if ((statbuff.st_mode & S_IFMT) == S_IFLNK) {
1403 * Read name of resolved file.
1405 link_chars_read = readlink(orig_name, true_name, 1024);
1406 if (link_chars_read <= 0) {
1407 fprintf(stderr,"%s: Can't read target name for '%s' symbolic link!\n",
1413 * Add a trailing null to what was read, bump the length.
1415 true_name[link_chars_read++] = 0;
1418 * If the symlink is an absolute pathname, we're fine. Otherwise, we
1419 * have to create a full pathname using the original name and the
1420 * relative symlink name. Find the rightmost slash in the original
1421 * name (we know there is one) and splice in the symlink value.
1423 if (true_name[0] != '\\') {
1424 last_component = (char *) strrchr(orig_name, '\\');
1425 strcpy(++last_component, true_name);
1426 strcpy(true_name, orig_name);
1430 strcpy(true_name, orig_name);
1432 strcpy(true_name, orig_name);
1436 * Find rightmost slash, if any.
1438 last_component = (char *) strrchr(true_name, '\\');
1439 if (!last_component)
1440 last_component = (char *) strrchr(true_name, '/');
1441 if (last_component) {
1443 * Found it. Designate everything before it as the parent directory,
1444 * everything after it as the final component.
1446 strncpy(parent_dir, true_name, last_component - true_name + 1);
1447 parent_dir[last_component - true_name + 1] = 0;
1448 last_component++; /*Skip the slash*/
1452 * No slash appears in the given file name. Set parent_dir to the current
1453 * directory, and the last component as the given name.
1455 fs_ExtractDriveLetter(true_name, parent_dir);
1456 strcat(parent_dir, ".");
1457 last_component = true_name;
1458 fs_StripDriveLetter(true_name, true_name, sizeof(true_name));
1461 if (strcmp(last_component, ".") == 0 || strcmp(last_component, "..") == 0) {
1462 fprintf(stderr,"fs: you may not use '.' or '..' as the last component\n");
1463 fprintf(stderr,"fs: of a name in the 'fs lsmount' command.\n");
1468 blob.in = last_component;
1469 blob.in_size = strlen(last_component)+1;
1470 blob.out_size = MAXSIZE;
1472 memset(space, 0, MAXSIZE);
1474 code = pioctl(parent_dir, VIOC_AFS_STAT_MT_PT, &blob, 1);
1477 printf("'%s' is a %smount point for volume '%s'\n",
1479 (thru_symlink ? "symbolic link, leading to a " : ""),
1484 if (errno == EINVAL)
1485 fprintf(stderr,"'%s' is not a mount point.\n",
1488 Die(errno, (ti->data ? ti->data : parent_dir));
1495 static MakeMountCmd(as)
1496 register struct cmd_syndesc *as; {
1497 register afs_int32 code;
1498 register char *cellName, *volName, *tmpName;
1500 char localCellName[1000];
1501 #else /* not WIN32 */
1502 struct afsconf_cell info;
1503 struct vldbentry vldbEntry;
1504 #endif /* not WIN32 */
1505 struct ViceIoctl blob;
1511 if (as->parms[5].items && !as->parms[2].items) {
1512 fprintf(stderr,"fs: must provide cell when creating cellular mount point.\n");
1517 if (as->parms[2].items) /* cell name specified */
1518 cellName = as->parms[2].items->data;
1520 cellName = (char *) 0;
1521 volName = as->parms[1].items->data;
1523 if (strlen(volName) >= 64) {
1524 fprintf(stderr,"fs: volume name too long (length must be < 64 characters)\n");
1528 /* Check for a cellname in the volume specification, and complain
1529 * if it doesn't match what was specified with -cell */
1530 if (tmpName = strchr(volName, ':')) {
1533 if (foldcmp(cellName,volName)) {
1534 fprintf(stderr,"fs: cellnames do not match.\n");
1539 volName = ++tmpName;
1542 if (!InAFS(Parent(as->parms[0].items->data))) {
1543 fprintf(stderr,"fs: mount points must be created within the AFS file system\n");
1549 blob.out_size = MAXSIZE;
1551 code = pioctl(Parent(as->parms[0].items->data), VIOC_FILE_CELL_NAME, &blob, 1);
1555 strcpy(localCellName, (cellName? cellName : space));
1556 #else /* not win32 */
1557 code = GetCellName(cellName?cellName:space, &info);
1561 if (!(as->parms[4].items)) {
1562 /* not fast, check which cell the mountpoint is being created in */
1564 /* not fast, check name with VLDB */
1566 code = VLDBInit(1, &info);
1568 /* make the check. Don't complain if there are problems with init */
1569 code = ubik_Call(VL_GetEntryByNameO, uclient, 0, volName, &vldbEntry);
1570 if (code == VL_NOENT) {
1571 fprintf(stderr,"fs: warning, volume %s does not exist in cell %s.\n",
1572 volName, cellName ? cellName : space);
1576 #endif /* not WIN32 */
1578 if (as->parms[3].items) /* if -rw specified */
1583 /* cellular mount point, prepend cell prefix */
1585 strcat(space, localCellName);
1586 #else /* not WIN32 */
1587 strcat(space, info.name);
1588 #endif /* not WIN32 */
1591 strcat(space, volName); /* append volume name */
1592 strcat(space, "."); /* stupid convention; these end with a period */
1594 /* create symlink with a special pioctl for Windows NT, since it doesn't
1595 * have a symlink system call.
1598 blob.in_size = 1 + strlen(space);
1601 code = pioctl(as->parms[0].items->data, VIOC_AFS_CREATE_MT_PT, &blob, 0);
1602 #else /* not WIN32 */
1603 code = symlink(space, as->parms[0].items->data);
1604 #endif /* not WIN32 */
1606 Die(errno, as->parms[0].items->data);
1613 * Delete AFS mount points. Variables are used as follows:
1614 * tbuffer: Set to point to the null-terminated directory name of the mount point
1615 * (or ``.'' if none is provided)
1616 * tp: Set to point to the actual name of the mount point to nuke.
1618 static RemoveMountCmd(as)
1619 register struct cmd_syndesc *as; {
1620 register afs_int32 code=0;
1621 struct ViceIoctl blob;
1622 register struct cmd_item *ti;
1624 char lsbuffer[1024];
1627 for(ti=as->parms[0].items; ti; ti=ti->next) {
1629 tp = (char *) strrchr(ti->data, '\\');
1631 tp = (char *) strrchr(ti->data, '/');
1633 strncpy(tbuffer, ti->data, code=tp-ti->data+1); /* the dir name */
1635 tp++; /* skip the slash */
1638 fs_ExtractDriveLetter(ti->data, tbuffer);
1639 strcat(tbuffer, ".");
1641 fs_StripDriveLetter(tp, tp, 0);
1644 blob.in_size = strlen(tp)+1;
1645 blob.out = lsbuffer;
1646 blob.out_size = sizeof(lsbuffer);
1647 code = pioctl(tbuffer, VIOC_AFS_STAT_MT_PT, &blob, 0);
1649 if (errno == EINVAL)
1650 fprintf(stderr,"fs: '%s' is not a mount point.\n", ti->data);
1652 Die(errno, ti->data);
1654 continue; /* don't bother trying */
1658 blob.in_size = strlen(tp)+1;
1659 code = pioctl(tbuffer, VIOC_AFS_DELETE_MT_PT, &blob, 0);
1661 Die(errno, ti->data);
1671 static CheckServersCmd(as)
1672 register struct cmd_syndesc *as; {
1673 register afs_int32 code;
1674 struct ViceIoctl blob;
1675 register afs_int32 j;
1678 struct afsconf_cell info;
1679 struct chservinfo checkserv;
1681 memset(&checkserv, 0, sizeof(struct chservinfo));
1682 blob.in_size=sizeof(struct chservinfo);
1683 blob.in=(caddr_t)&checkserv;
1685 blob.out_size = MAXSIZE;
1687 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1689 /* prepare flags for checkservers command */
1690 temp = 2; /* default to checking local cell only */
1691 if (as->parms[2].items) temp |= 1; /* set fast flag */
1692 if (as->parms[1].items) temp &= ~2; /* turn off local cell check */
1694 checkserv.magic = 0x12345678; /* XXX */
1695 checkserv.tflags=temp;
1697 /* now copy in optional cell name, if specified */
1698 if (as->parms[0].items) {
1699 code = GetCellName(as->parms[0].items->data, &info);
1703 strcpy(checkserv.tbuffer,info.name);
1704 checkserv.tsize=strlen(info.name)+1;
1708 strcpy(checkserv.tbuffer,"\0");
1712 if(as->parms[3].items)
1714 checkserv.tinterval=atol(as->parms[3].items->data);
1717 if(checkserv.tinterval<0) {
1718 printf("Warning: The negative -interval is ignored; treated as an inquiry\n");
1719 checkserv.tinterval=0;
1720 } else if(checkserv.tinterval> 600) {
1721 printf("Warning: The maximum -interval value is 10 mins (600 secs)\n");
1722 checkserv.tinterval=600; /* 10 min max interval */
1726 checkserv.tinterval = -1; /* don't change current interval */
1729 if ( checkserv.tinterval != 0 ) {
1732 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
1737 fprintf (stderr,"Permission denied: requires root access.\n");
1743 code = pioctl(0, VIOCCKSERV, &blob, 1);
1745 if ((errno == EACCES) && (checkserv.tinterval > 0)) {
1746 printf("Must be root to change -interval\n");
1752 memcpy(&temp, space, sizeof(afs_int32));
1753 if (checkserv.tinterval >= 0) {
1754 if (checkserv.tinterval > 0)
1755 printf("The new down server probe interval (%d secs) is now in effect (old interval was %d secs)\n",
1756 checkserv.tinterval, temp);
1758 printf("The current down server probe interval is %d secs\n", temp);
1762 printf("All servers are running.\n");
1765 printf("These servers unavailable due to network or server problems: ");
1766 for(j=0; j < MAXHOSTS; j++) {
1767 memcpy(&temp, space + j*sizeof(afs_int32), sizeof(afs_int32));
1768 if (temp == 0) break;
1769 tp = hostutil_GetNameByINet(temp);
1779 register struct cmd_syndesc *as; {
1780 register afs_int32 code=0;
1781 struct ViceIoctl blob;
1782 struct gaginfo gagflags;
1783 struct cmd_item *show;
1785 memset(&gagflags, 0, sizeof(struct gaginfo));
1786 blob.in_size = sizeof(struct gaginfo);
1787 blob.in = (caddr_t ) &gagflags;
1788 blob.out_size = MAXSIZE;
1790 memset(space, 0, sizeof(afs_int32)); /* so we assure zero when nothing is copied back */
1792 if (show = as->parms[0].items)
1793 if (!foldcmp (show->data, "user"))
1794 gagflags.showflags |= GAGUSER;
1795 else if (!foldcmp (show->data, "console"))
1796 gagflags.showflags |= GAGCONSOLE;
1797 else if (!foldcmp (show->data, "all"))
1798 gagflags.showflags |= GAGCONSOLE | GAGUSER;
1799 else if (!foldcmp (show->data, "none"))
1803 "unrecognized flag %s: must be in {user,console,all,none}\n",
1811 code = pioctl(0, VIOC_GAG, &blob, 1);
1819 static CheckVolumesCmd(as)
1820 register struct cmd_syndesc *as; {
1821 register afs_int32 code;
1822 struct ViceIoctl blob;
1826 code = pioctl(0, VIOCCKBACK, &blob, 1);
1831 else printf("All volumeID/name mappings checked.\n");
1836 static SetCacheSizeCmd(as)
1837 register struct cmd_syndesc *as; {
1838 register afs_int32 code;
1839 struct ViceIoctl blob;
1844 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
1849 fprintf (stderr,"Permission denied: requires root access.\n");
1854 if (!as->parms[0].items && !as->parms[1].items) {
1855 fprintf(stderr,"%s: syntax error in set cache size cmd.\n", pn);
1858 if (as->parms[0].items) {
1859 code = util_GetInt32(as->parms[0].items->data, &temp);
1861 fprintf(stderr,"fs: bad integer specified for cache size.\n");
1867 blob.in = (char *) &temp;
1868 blob.in_size = sizeof(afs_int32);
1870 code = pioctl(0, VIOCSETCACHESIZE, &blob, 1);
1872 Die(errno, (char *) 0);
1874 printf("New cache size set.\n");
1878 #define MAXGCSIZE 16
1879 static GetCacheParmsCmd(as)
1880 register struct cmd_syndesc *as; {
1881 register afs_int32 code;
1882 struct ViceIoctl blob;
1883 afs_int32 parms[MAXGCSIZE];
1885 blob.in = (char *) 0;
1887 blob.out_size = sizeof(parms);
1888 blob.out = (char *) parms;
1889 code = pioctl(0, VIOCGETCACHEPARMS, &blob, 1);
1891 Die(errno, (char *) 0);
1893 printf("AFS using %d of the cache's available %d 1K byte blocks.\n",
1894 parms[1], parms[0]);
1895 if (parms[1] > parms[0])
1896 printf("[Cache guideline temporarily deliberately exceeded; it will be adjusted down but you may wish to increase the cache size.]\n");
1901 static ListCellsCmd(as)
1902 register struct cmd_syndesc *as; {
1903 register afs_int32 code;
1904 afs_int32 i, j, *lp, magic, size;
1906 afs_int32 clear, maxa = OMAXHOSTS;
1907 struct ViceIoctl blob;
1909 for(i=0;i<1000;i++) {
1911 memcpy(tp, &i, sizeof(afs_int32));
1912 tp = (char *)(space + sizeof(afs_int32));
1913 lp = (afs_int32 *)tp;
1915 size = sizeof(afs_int32) + sizeof(afs_int32);
1916 blob.out_size = MAXSIZE;
1917 blob.in_size = sizeof(afs_int32);
1920 code = pioctl(0, VIOCGETCELL, &blob, 1);
1922 if (errno == EDOM) break; /* done with the list */
1929 memcpy(&magic, tp, sizeof(afs_int32));
1930 if (magic == 0x12345678) {
1932 tp += sizeof(afs_int32);
1934 printf("Cell %s on hosts", tp+maxa*sizeof(afs_int32));
1935 for(j=0; j < maxa; j++) {
1936 memcpy(&clear, tp + j*sizeof(afs_int32), sizeof(afs_int32));
1937 if (clear == 0) break;
1938 tcp = hostutil_GetNameByINet(clear);
1946 static NewCellCmd(as)
1947 register struct cmd_syndesc *as; {
1949 register afs_int32 code, linkedstate=0, size=0, *lp;
1950 struct ViceIoctl blob;
1951 register struct cmd_item *ti;
1952 register char *tp, *cellname=0;
1953 register struct hostent *thp;
1954 afs_int32 fsport = 0, vlport = 0;
1958 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
1963 fprintf (stderr,"Permission denied: requires root access.\n");
1968 memset(space, 0, MAXHOSTS * sizeof(afs_int32));
1970 lp = (afs_int32 *)tp;
1972 tp += sizeof(afs_int32);
1973 for(ti=as->parms[1].items; ti; ti=ti->next) {
1974 thp = hostutil_GetHostByName(ti->data);
1976 fprintf(stderr,"%s: Host %s not found in host table, skipping it.\n",
1980 memcpy(tp, thp->h_addr, sizeof(afs_int32));
1981 tp += sizeof(afs_int32);
1984 if (as->parms[2].items) {
1986 * Link the cell, for the purposes of volume location, to the specified
1989 cellname = as->parms[2].items->data;
1992 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
1993 if (as->parms[3].items) {
1994 code = util_GetInt32(as->parms[3].items->data, &vlport);
1996 fprintf(stderr,"fs: bad integer specified for the fileserver port.\n");
2000 if (as->parms[4].items) {
2001 code = util_GetInt32(as->parms[4].items->data, &fsport);
2003 fprintf(stderr,"fs: bad integer specified for the vldb server port.\n");
2008 tp = (char *)(space + (MAXHOSTS+1) *sizeof(afs_int32));
2009 lp = (afs_int32 *)tp;
2013 strcpy(space + ((MAXHOSTS+4) * sizeof(afs_int32)), as->parms[0].items->data);
2014 size = ((MAXHOSTS+4) * sizeof(afs_int32)) + strlen(as->parms[0].items->data) + 1 /* for null */;
2015 tp = (char *)(space + size);
2017 strcpy(tp, cellname);
2018 size += strlen(cellname) + 1;
2020 blob.in_size = size;
2023 code = pioctl(0, VIOCNEWCELL, &blob, 1);
2028 register afs_int32 code;
2029 struct ViceIoctl blob;
2032 blob.in = (char *) 0;
2033 blob.out_size = MAXSIZE;
2036 code = pioctl((char *) 0, VIOCNEWCELL, &blob, 1);
2039 Die(errno, (char *) 0);
2042 printf("Cell servers information refreshed\n");
2047 static WhichCellCmd(as)
2048 register struct cmd_syndesc *as; {
2049 register afs_int32 code;
2050 struct ViceIoctl blob;
2051 register struct cmd_item *ti;
2054 error = 0; /* no error occurred */
2055 SetDotDefault(&as->parms[0].items);
2056 for(ti=as->parms[0].items; ti; ti=ti->next) {
2059 blob.out_size = MAXSIZE;
2062 code = pioctl(ti->data, VIOC_FILE_CELL_NAME, &blob, 1);
2064 if (errno == ENOENT)
2065 fprintf(stderr,"%s: no such cell as '%s'\n", pn, ti->data);
2067 Die(errno, ti->data);
2072 printf("File %s lives in cell '%s'\n", ti->data, space);
2077 static WSCellCmd(as)
2078 register struct cmd_syndesc *as; {
2079 register afs_int32 code;
2080 struct ViceIoctl blob;
2083 blob.in = (char *) 0;
2084 blob.out_size = MAXSIZE;
2087 code = pioctl((char *) 0, VIOC_GET_WS_CELL, &blob, 1);
2090 Die(errno, (char *) 0);
2093 printf("This workstation belongs to cell '%s'\n", space);
2097 static PrimaryCellCmd(as)
2098 register struct cmd_syndesc *as; {
2100 fprintf(stderr,"This command is obsolete, as is the concept of a primary token.\n");
2105 static MonitorCmd(as)
2106 register struct cmd_syndesc *as; {
2107 register afs_int32 code;
2108 struct ViceIoctl blob;
2109 register struct cmd_item *ti;
2111 register struct hostent *thp;
2115 ti = as->parms[0].items;
2119 if (!strcmp(ti->data, "off"))
2120 hostAddr = 0xffffffff;
2122 thp = hostutil_GetHostByName(ti->data);
2124 if (!strcmp(ti->data, "localhost")) {
2125 fprintf(stderr,"localhost not in host table, assuming 127.0.0.1\n");
2126 hostAddr = htonl(0x7f000001);
2129 fprintf(stderr,"host %s not found in host table.\n", ti->data);
2133 else memcpy(&hostAddr, thp->h_addr, sizeof(afs_int32));
2137 hostAddr = 0; /* means don't set host */
2138 setp = 0; /* aren't setting host */
2141 /* now do operation */
2142 blob.in_size = sizeof(afs_int32);
2143 blob.out_size = sizeof(afs_int32);
2144 blob.in = (char *) &hostAddr;
2145 blob.out = (char *) &hostAddr;
2146 code = pioctl(0, VIOC_AFS_MARINER_HOST, &blob, 1);
2152 printf("%s: new monitor host set.\n", pn);
2155 /* now decode old address */
2156 if (hostAddr == 0xffffffff) {
2157 printf("Cache monitoring is currently disabled.\n");
2160 tp = hostutil_GetNameByINet(hostAddr);
2161 printf("Using host %s for monitor services.\n", tp);
2167 static SysNameCmd(as)
2168 register struct cmd_syndesc *as; {
2169 register afs_int32 code;
2170 struct ViceIoctl blob;
2171 struct cmd_item *ti;
2172 char *input = space;
2175 ti = as->parms[0].items;
2179 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2184 fprintf (stderr,"Permission denied: requires root access.\n");
2192 blob.out_size = MAXSIZE;
2193 blob.in_size = sizeof(afs_int32);
2194 memcpy(input, &setp, sizeof(afs_int32));
2195 input += sizeof(afs_int32);
2196 for (; ti; ti = ti->next) {
2198 blob.in_size += strlen(ti->data) + 1;
2199 if (blob.in_size > MAXSIZE) {
2200 fprintf(stderr, "%s: sysname%s too long.\n", pn,
2201 setp > 1 ? "s" : "");
2204 strcpy(input, ti->data);
2205 input += strlen(ti->data);
2208 memcpy(space, &setp, sizeof(afs_int32));
2209 code = pioctl(0, VIOC_AFS_SYSNAME, &blob, 1);
2215 printf("%s: new sysname%s set.\n", pn, setp > 1 ? "s" : "");
2220 memcpy(&setp, input, sizeof(afs_int32));
2221 input += sizeof(afs_int32);
2223 fprintf(stderr,"No sysname name value was found\n");
2227 printf("Current sysname%s", setp > 1 ? "s are" : " is");
2228 for (; setp > 0; --setp ) {
2229 printf(" \'%s\'", input);
2230 input += strlen(input) + 1;
2236 char *exported_types[] = {"null", "nfs", ""};
2237 static ExportAfsCmd(as)
2238 register struct cmd_syndesc *as; {
2239 register afs_int32 code;
2240 struct ViceIoctl blob;
2241 register struct cmd_item *ti;
2242 int export=0, type=0, mode = 0, exp = 0, gstat = 0, exportcall, pwsync=0, smounts=0;
2246 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2251 fprintf (stderr,"Permission denied: requires root access.\n");
2256 ti = as->parms[0].items;
2257 if (strcmp(ti->data, "nfs") == 0) type = 0x71; /* NFS */
2259 fprintf(stderr,"Invalid exporter type, '%s', Only the 'nfs' exporter is currently supported\n", ti->data);
2262 ti = as->parms[1].items;
2264 if (strcmp(ti->data, "on") == 0) export = 3;
2265 else if (strcmp(ti->data, "off") == 0) export = 2;
2267 printf("Illegal argument %s\n", ti->data);
2272 if (ti = as->parms[2].items) { /* -noconvert */
2273 if (strcmp(ti->data, "on") == 0) mode = 2;
2274 else if (strcmp(ti->data, "off") == 0) mode = 3;
2276 printf("Illegal argument %s\n", ti->data);
2280 if (ti = as->parms[3].items) { /* -uidcheck */
2281 if (strcmp(ti->data, "on") == 0) pwsync = 3;
2282 else if (strcmp(ti->data, "off") == 0) pwsync = 2;
2284 printf("Illegal argument %s\n", ti->data);
2288 if (ti = as->parms[4].items) { /* -submounts */
2289 if (strcmp(ti->data, "on") == 0) smounts = 3;
2290 else if (strcmp(ti->data, "off") == 0) smounts = 2;
2292 printf("Illegal argument %s\n", ti->data);
2296 exportcall = (type << 24) | (mode << 6) | (pwsync << 4) | (smounts << 2) | export;
2299 blob.in = (char *) &exportcall;
2300 blob.in_size = sizeof(afs_int32);
2301 blob.out = (char *) &exportcall;
2302 blob.out_size = sizeof(afs_int32);
2303 code = pioctl(0, VIOC_EXPORTAFS, &blob, 1);
2305 if (errno == ENODEV) {
2306 fprintf(stderr,"Sorry, the %s-exporter type is currently not supported on this AFS client\n", exported_types[type]);
2313 if (exportcall & 1) {
2314 printf("'%s' translator is enabled with the following options:\n\tRunning in %s mode\n\tRunning in %s mode\n\t%s\n",
2315 exported_types[type], (exportcall & 2 ? "strict unix" : "convert owner mode bits to world/other"),
2316 (exportcall & 4 ? "strict 'passwd sync'" : "no 'passwd sync'"),
2317 (exportcall & 8 ? "Allow mounts of /afs/.. subdirs" : "Only mounts to /afs allowed"));
2319 printf("'%s' translator is disabled\n", exported_types[type]);
2327 static GetCellCmd(as)
2328 register struct cmd_syndesc *as; {
2329 register afs_int32 code;
2330 struct ViceIoctl blob;
2331 struct afsconf_cell info;
2332 register struct cmd_item *ti;
2338 for(ti=as->parms[0].items; ti; ti=ti->next) {
2340 blob.out_size = sizeof(args);
2341 blob.out = (caddr_t) &args;
2342 code = GetCellName(ti->data, &info);
2346 blob.in_size = 1+strlen(info.name);
2347 blob.in = info.name;
2348 code = pioctl(0, VIOC_GETCELLSTATUS, &blob, 1);
2350 if (errno == ENOENT)
2351 fprintf(stderr,"fs: the cell named '%s' does not exist\n", info.name);
2353 Die(errno, info.name);
2356 printf("Cell %s status: ", info.name);
2358 if (args.stat & 1) printf("primary ");
2360 if (args.stat & 2) printf("no setuid allowed");
2361 else printf("setuid allowed");
2362 if (args.stat & 4) printf(", using old VLDB");
2368 static SetCellCmd(as)
2369 register struct cmd_syndesc *as; {
2370 register afs_int32 code;
2371 struct ViceIoctl blob;
2372 struct afsconf_cell info;
2373 register struct cmd_item *ti;
2380 /* figure stuff to set */
2386 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2391 fprintf (stderr,"Permission denied: requires root access.\n");
2396 if (! as->parms[1].items) args.stat |= CM_SETCELLFLAG_SUID; /* default to -nosuid */
2398 /* set stat for all listed cells */
2399 for(ti=as->parms[0].items; ti; ti=ti->next) {
2401 code = GetCellName(ti->data, &info);
2405 strcpy(args.cname, info.name);
2406 blob.in_size = sizeof(args);
2407 blob.in = (caddr_t) &args;
2409 blob.out = (caddr_t) 0;
2410 code = pioctl(0, VIOC_SETCELLSTATUS, &blob, 1);
2420 static GetCellName(char *cellNamep, struct afsconf_cell *infop)
2422 strcpy(infop->name, cellNamep);
2426 static VLDBInit(int noAuthFlag, struct afsconf_cell *infop)
2431 #else /* not WIN32 */
2433 static GetCellName(cellName, info)
2435 struct afsconf_cell *info;
2437 struct afsconf_dir *tdir;
2440 tdir = afsconf_Open(AFSCONF_CLIENTNAME);
2442 fprintf(stderr,"Could not process files in configuration directory (%s).\n",AFSCONF_CLIENTNAME);
2446 code = afsconf_GetCellInfo(tdir, cellName, AFSCONF_VLDBSERVICE, info);
2448 fprintf(stderr,"fs: cell %s not in %s/CellServDB\n", cellName, AFSCONF_CLIENTNAME);
2456 static VLDBInit(noAuthFlag, info)
2458 struct afsconf_cell *info;
2460 struct ktc_principal sname;
2461 struct ktc_token ttoken;
2463 struct rx_securityClass *sc;
2464 struct rx_connection *serverconns[VLDB_MAXSERVERS];
2469 fprintf(stderr,"fs: could not initialize rx.\n");
2473 rx_SetRxDeadTime(50);
2474 if (!noAuthFlag) { /* we don't need tickets for null */
2475 strcpy(sname.cell, info->name);
2476 sname.instance[0] = 0;
2477 strcpy(sname.name, "afs");
2478 code = ktc_GetToken(&sname,&ttoken, sizeof(ttoken), (char *)0);
2480 fprintf(stderr,"fs: Could not get afs tokens, running unauthenticated.\n");
2485 if (ttoken.kvno >= 0 && ttoken.kvno <= 256) scIndex = 2; /* kerberos */
2487 fprintf (stderr, "fs: funny kvno (%d) in ticket, proceeding\n",
2493 else scIndex = 0; /* don't authenticate */
2496 sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
2502 sc = (struct rx_securityClass *)
2503 rxkad_NewClientSecurityObject(rxkad_clear, &ttoken.sessionKey,
2504 ttoken.kvno, ttoken.ticketLen,
2508 if (info->numServers > VLDB_MAXSERVERS) {
2509 fprintf(stderr, "fs: info.numServers=%d (> VLDB_MAXSERVERS=%d)\n",
2510 info->numServers, VLDB_MAXSERVERS);
2513 memset(serverconns, 0, sizeof(serverconns));
2514 for (i = 0;i<info->numServers;i++)
2515 serverconns[i] = rx_NewConnection(info->hostAddr[i].sin_addr.s_addr,
2516 info->hostAddr[i].sin_port, USER_SERVICE_ID,
2520 rxs_Release(sc); /* Decrement the initial refCount */
2521 code = ubik_ClientInit(serverconns, &uclient);
2524 fprintf(stderr,"fs: ubik client init failed.\n");
2529 #endif /* not WIN32 */
2531 static struct ViceIoctl gblob;
2532 static int debug = 0;
2534 * here follow some routines in suport of the setserverprefs and
2535 * getserverprefs commands. They are:
2536 * SetPrefCmd "top-level" routine
2537 * addServer adds a server to the list of servers to be poked into the
2538 * kernel. Will poke the list into the kernel if it threatens
2540 * pokeServers pokes the existing list of servers and ranks into the kernel
2541 * GetPrefCmd reads the Cache Manager's current list of server ranks
2544 static pokeServers()
2549 code = pioctl(0, VIOC_SETSPREFS, &gblob, 1);
2551 ssp = (cm_SSetPref_t *)space;
2552 gblob.in_size = ((char *)&(ssp->servers[0])) - (char *)ssp;
2557 static addServer(name, rank)
2559 unsigned short rank;
2564 struct hostent *thostent;
2568 #define MAXUSHORT ((unsigned short) 2*MAXSHORT+1) /* assumes two's complement binary system */
2570 #define MAXUSHORT ((unsigned short) ~0)
2575 thostent = hostutil_GetHostByName(name);
2577 fprintf (stderr, "%s: couldn't resolve name.\n", name);
2581 ssp = (cm_SSetPref_t *)(gblob.in);
2583 if (gblob.in_size > MAXINSIZE - sizeof(cm_SPref_t)) {
2584 code = pokeServers();
2585 ssp->num_servers = 0;
2588 sp = (cm_SPref_t *)((char*)gblob.in + gblob.in_size);
2589 memcpy (&(sp->host.s_addr), thostent->h_addr, sizeof(afs_uint32));
2590 sp->rank = (rank > MAXUSHORT ? MAXUSHORT : rank);
2591 gblob.in_size += sizeof(cm_SPref_t);
2594 if (debug) fprintf(stderr, "adding server %s, rank %d, ip addr 0x%lx\n",name,sp->rank,sp->host.s_addr);
2599 static BOOL IsWindowsNT (void)
2601 static BOOL fChecked = FALSE;
2602 static BOOL fIsWinNT = FALSE;
2606 OSVERSIONINFO Version;
2610 memset (&Version, 0x00, sizeof(Version));
2611 Version.dwOSVersionInfoSize = sizeof(Version);
2613 if (GetVersionEx (&Version))
2615 if (Version.dwPlatformId == VER_PLATFORM_WIN32_NT)
2623 static SetPrefCmd(as)
2624 register struct cmd_syndesc *as; {
2627 struct cmd_item *ti;
2632 ssp = (cm_SSetPref_t *)space;
2634 ssp->num_servers = 0;
2635 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2638 gblob.out_size = MAXSIZE;
2642 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2647 fprintf (stderr,"Permission denied: requires root access.\n");
2654 ti = as->parms[2].items; /* -file */
2656 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
2657 if (!(infd = fopen(ti->data,"r" ))) {
2659 Die(errno,ti->data);
2662 while ( fscanf(infd, "%79s%ld", name, &rank) != EOF) {
2663 code = addServer (name, (unsigned short) rank);
2667 ti = as->parms[3].items; /* -stdin */
2669 while ( scanf("%79s%ld", name, &rank) != EOF) {
2670 code = addServer (name, (unsigned short) rank);
2674 for (ti = as->parms[0].items;ti;ti=ti->next) {/*list of servers, ranks */
2679 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
2681 printf("set fs prefs %s %s\n", ti->data, ti->next->data);
2685 code = pokeServers();
2687 printf("now working on vlservers, code=%d, errno=%d\n",code,errno);
2689 ssp = (cm_SSetPref_t *)space;
2690 gblob.in_size = ((char*)&(ssp->servers[0])) - (char *)ssp;
2692 ssp->flags = CM_SPREF_VLONLY;
2693 ssp->num_servers = 0;
2695 for (ti = as->parms[1].items;ti;ti=ti->next) { /* list of dbservers, ranks */
2700 code = addServer (ti->data, (unsigned short) atol(ti->next->data));
2702 printf("set vl prefs %s %s\n", ti->data, ti->next->data);
2707 if (as->parms[1].items) {
2709 printf("now poking vlservers\n");
2710 code = pokeServers();
2720 static GetPrefCmd(as)
2721 register struct cmd_syndesc *as; {
2723 struct cmd_item *ti;
2724 char *name, tbuffer[20];
2729 struct ViceIoctl blob;
2730 struct cm_SPrefRequest *in;
2731 struct cm_SPrefInfo *out;
2735 ti = as->parms[0].items; /* -file */
2737 if (debug) fprintf(stderr,"opening file %s\n",ti->data);
2738 if (!(outfd = freopen(ti->data,"w",stdout))) {
2739 Die(errno,ti->data);
2744 ti = as->parms[1].items; /* -numeric */
2746 ti = as->parms[2].items; /* -vlservers */
2747 vlservers = (ti ? CM_SPREF_VLONLY : 0);
2748 /* ti = as->parms[3].items; -cell */
2750 in = (struct cm_SPrefRequest *)space;
2754 blob.in_size=sizeof(struct cm_SPrefRequest);
2755 blob.in = (char *)in;
2757 blob.out_size = MAXSIZE;
2759 in->num_servers = (MAXSIZE - 2*sizeof(short))/sizeof(struct cm_SPref);
2760 in->flags = vlservers;
2762 code = pioctl(0, VIOC_GETSPREFS, &blob, 1);
2764 perror("getserverprefs pioctl");
2768 out = (struct cm_SPrefInfo *) blob.out;
2770 for (i=0;i<out->num_servers;i++) {
2772 name = hostutil_GetNameByINet(out->servers[i].host.s_addr);
2775 addr = ntohl(out->servers[i].host.s_addr);
2776 sprintf(tbuffer, "%d.%d.%d.%d", (addr>>24) & 0xff, (addr>>16) & 0xff,
2777 (addr>>8) & 0xff, addr & 0xff);
2780 printf ("%-50s %5u\n",name,out->servers[i].rank);
2783 in->offset = out->next_offset;
2785 } while (!code && out->next_offset > 0);
2790 static TraceCmd(struct cmd_syndesc *asp)
2793 struct ViceIoctl blob;
2799 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2804 fprintf (stderr,"Permission denied: requires root access.\n");
2809 if ((asp->parms[0].items && asp->parms[1].items)) {
2810 fprintf(stderr, "fs trace: must use at most one of '-off' or '-on'\n");
2814 /* determine if we're turning this tracing on or off */
2816 if (asp->parms[0].items)
2817 inValue = 3; /* enable */
2818 else if (asp->parms[1].items) inValue = 2; /* disable */
2819 if (asp->parms[2].items) inValue |= 4; /* do reset */
2820 if (asp->parms[3].items) inValue |= 8; /* dump */
2822 blob.in_size = sizeof(long);
2823 blob.in = (char *) &inValue;
2824 blob.out_size = sizeof(long);
2825 blob.out = (char *) &outValue;
2827 code = pioctl(NULL, VIOC_TRACECTL, &blob, 1);
2833 if (outValue) printf("AFS tracing enabled.\n");
2834 else printf("AFS tracing disabled.\n");
2839 static void sbusage()
2841 fprintf(stderr, "example usage: fs storebehind -files *.o -kb 99999 -default 0\n");
2842 fprintf(stderr, " fs sb 50000 *.[ao] -default 10\n");
2845 static StoreBehindCmd(as) /* fs sb -kbytes 9999 -files *.o -default 64 */
2846 struct cmd_syndesc *as; {
2848 struct ViceIoctl blob;
2849 struct cmd_item *ti;
2850 struct sbstruct tsb;
2855 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2860 fprintf (stderr,"Permission denied: requires root access.\n");
2865 if ((as->parms[0].items && as->parms[1].items) ||
2866 (!as->parms[0].items && !as->parms[1].items)) /* same as logical xor */
2873 ti=as->parms[2].items;
2874 if (ti && ti->data) {
2875 kb = atoi (ti->data);
2878 tsb.sb_default = kb;
2880 ti=as->parms[1].items;
2881 if (ti && ti->data) {
2882 kb = atoi (ti->data);
2885 tsb.sb_thisfile = kb;
2887 ti=as->parms[0].items;
2892 blob.in_size = sizeof(tsb);
2893 blob.out_size = sizeof(tsb);
2894 fprintf (stderr, "storbehind %s %d %d\n", (ti?ti->data:0),
2895 tsb.sb_thisfile, tsb.sb_default);
2896 code = pioctl((ti ? ti->data : 0) , VIOC_STOREBEHIND, &blob, 1);
2898 Die(errno, (ti ? ti->data : 0));
2901 if (blob.out_size == sizeof(tsb)) {
2902 fprintf (stderr, "storbehind %s is now %d (default %d)\n", (ti?ti->data:0),
2903 tsb.sb_thisfile, tsb.sb_default);
2905 ti = (ti ? ti->next : ti);
2911 static afs_int32 SetCryptCmd(as)
2912 struct cmd_syndesc *as;
2914 afs_int32 code = 0, flag;
2915 struct ViceIoctl blob;
2920 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
2925 fprintf (stderr,"Permission denied: requires root access.\n");
2930 tp = as->parms[0].items->data;
2931 if (strcmp(tp, "on") == 0)
2933 else if (strcmp(tp, "off") == 0)
2936 fprintf (stderr, "%s: %s must be \"on\" or \"off\".\n", pn, tp);
2940 blob.in = (char *) &flag;
2941 blob.in_size = sizeof(flag);
2943 code = pioctl(0, VIOC_SETRXKCRYPT, &blob, 1);
2945 Die(code, (char *) 0);
2949 static afs_int32 GetCryptCmd(as)
2950 struct cmd_syndesc *as;
2952 afs_int32 code = 0, flag;
2953 struct ViceIoctl blob;
2956 blob.in = (char *) 0;
2958 blob.out_size = sizeof(flag);
2961 code = pioctl(0, VIOC_GETRXKCRYPT, &blob, 1);
2963 if (code) Die(code, (char *) 0);
2966 memcpy(&flag, tp, sizeof(afs_int32));
2967 printf("Security level is currently ");
2969 printf("crypt (data security).\n");
2979 register afs_int32 code;
2980 register struct cmd_syndesc *ts;
2982 #ifdef AFS_AIX32_ENV
2984 * The following signal action for AIX is necessary so that in case of a
2985 * crash (i.e. core is generated) we can include the user's data section
2986 * in the core dump. Unfortunately, by default, only a partial core is
2987 * generated which, in many cases, isn't too useful.
2989 struct sigaction nsa;
2991 sigemptyset(&nsa.sa_mask);
2992 nsa.sa_handler = SIG_DFL;
2993 nsa.sa_flags = SA_FULLDUMP;
2994 sigaction(SIGSEGV, &nsa, NULL);
2999 WSAStartup(0x0101, &WSAjunk);
3002 /* try to find volume location information */
3007 ts = cmd_CreateSyntax("setserverprefs", SetPrefCmd, 0, "set server ranks");
3008 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "fileserver names and ranks");
3009 cmd_AddParm(ts, "-vlservers", CMD_LIST, CMD_OPTIONAL|CMD_EXPANDS, "VL server names and ranks");
3010 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "input from named file");
3011 cmd_AddParm(ts, "-stdin", CMD_FLAG, CMD_OPTIONAL, "input from stdin");
3012 cmd_CreateAlias(ts, "sp");
3014 ts = cmd_CreateSyntax("getserverprefs", GetPrefCmd, 0, "get server ranks");
3015 cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL, "output to named file");
3016 cmd_AddParm(ts, "-numeric", CMD_FLAG, CMD_OPTIONAL, "addresses only");
3017 cmd_AddParm(ts, "-vlservers", CMD_FLAG, CMD_OPTIONAL, "VL servers");
3018 /* cmd_AddParm(ts, "-cell", CMD_FLAG, CMD_OPTIONAL, "cellname"); */
3019 cmd_CreateAlias(ts, "gp");
3021 ts = cmd_CreateSyntax("setacl", SetACLCmd, 0, "set access control list");
3022 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3023 cmd_AddParm(ts, "-acl", CMD_LIST, 0, "access list entries");
3024 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "clear access list");
3025 cmd_AddParm(ts, "-negative", CMD_FLAG, CMD_OPTIONAL, "apply to negative rights");
3026 parm_setacl_id = ts->nParms;
3027 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl (DFS only)");
3028 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl (DFS only)");
3029 cmd_CreateAlias(ts, "sa");
3031 ts = cmd_CreateSyntax("listacl", ListACLCmd, 0, "list access control list");
3032 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3033 parm_listacl_id = ts->nParms;
3034 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3035 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3036 cmd_CreateAlias(ts, "la");
3038 ts = cmd_CreateSyntax("cleanacl", CleanACLCmd, 0, "clean up access control list");
3039 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3041 ts = cmd_CreateSyntax("copyacl", CopyACLCmd, 0, "copy access control list");
3042 cmd_AddParm(ts, "-fromdir", CMD_SINGLE, 0, "source directory (or DFS file)");
3043 cmd_AddParm(ts, "-todir", CMD_LIST, 0, "destination directory (or DFS file)");
3044 cmd_AddParm(ts, "-clear", CMD_FLAG, CMD_OPTIONAL, "first clear dest access list");
3045 parm_copyacl_id = ts->nParms;
3046 cmd_AddParm(ts, "-id", CMD_FLAG, CMD_OPTIONAL, "initial directory acl");
3047 cmd_AddParm(ts, "-if", CMD_FLAG, CMD_OPTIONAL, "initial file acl");
3049 cmd_CreateAlias(ts, "ca");
3051 ts = cmd_CreateSyntax("flush", FlushCmd, 0, "flush file from cache");
3052 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3054 ts = cmd_CreateSyntax("setvol", SetVolCmd, 0, "set volume status");
3055 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3056 cmd_AddParm(ts, "-max", CMD_SINGLE, CMD_OPTIONAL, "disk space quota in 1K units");
3058 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "disk space guaranteed");
3060 cmd_AddParm(ts, "-motd", CMD_SINGLE, CMD_OPTIONAL, "message of the day");
3061 cmd_AddParm(ts, "-offlinemsg", CMD_SINGLE, CMD_OPTIONAL, "offline message");
3062 cmd_CreateAlias(ts, "sv");
3064 ts = cmd_CreateSyntax("messages", GagCmd, 0, "control Cache Manager messages");
3065 cmd_AddParm(ts, "-show", CMD_SINGLE, CMD_OPTIONAL, "[user|console|all|none]");
3067 ts = cmd_CreateSyntax("examine", ExamineCmd, 0, "display volume status");
3068 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3069 cmd_CreateAlias(ts, "lv");
3070 cmd_CreateAlias(ts, "listvol");
3072 ts = cmd_CreateSyntax("listquota", ListQuotaCmd, 0, "list volume quota");
3073 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3074 cmd_CreateAlias(ts, "lq");
3076 ts = cmd_CreateSyntax("diskfree", DiskFreeCmd, 0, "show server disk space usage");
3077 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3078 cmd_CreateAlias(ts, "df");
3080 ts = cmd_CreateSyntax("quota", QuotaCmd, 0, "show volume quota usage");
3081 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3083 ts = cmd_CreateSyntax("lsmount", ListMountCmd, 0, "list mount point");
3084 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3086 ts = cmd_CreateSyntax("mkmount", MakeMountCmd, 0, "make mount point");
3087 cmd_AddParm(ts, "-dir", CMD_SINGLE, 0, "directory");
3088 cmd_AddParm(ts, "-vol", CMD_SINGLE, 0, "volume name");
3089 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
3090 cmd_AddParm(ts, "-rw", CMD_FLAG, CMD_OPTIONAL, "force r/w volume");
3091 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "don't check name with VLDB");
3097 cmd_AddParm(ts, "-root", CMD_FLAG, CMD_OPTIONAL, "create cellular mount point");
3101 ts = cmd_CreateSyntax("rmmount", RemoveMountCmd, 0, "remove mount point");
3102 cmd_AddParm(ts, "-dir", CMD_LIST, 0, "directory");
3104 ts = cmd_CreateSyntax("checkservers", CheckServersCmd, 0, "check local cell's servers");
3105 cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell to check");
3106 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "check all cells");
3107 cmd_AddParm(ts, "-fast", CMD_FLAG, CMD_OPTIONAL, "just list, don't check");
3108 cmd_AddParm(ts,"-interval",CMD_SINGLE,CMD_OPTIONAL,"seconds between probes");
3110 ts = cmd_CreateSyntax("checkvolumes", CheckVolumesCmd,0, "check volumeID/name mappings");
3111 cmd_CreateAlias(ts, "checkbackups");
3114 ts = cmd_CreateSyntax("setcachesize", SetCacheSizeCmd, 0, "set cache size");
3115 cmd_AddParm(ts, "-blocks", CMD_SINGLE, CMD_OPTIONAL, "size in 1K byte blocks (0 => reset)");
3116 cmd_CreateAlias(ts, "cachesize");
3118 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset size back to boot value");
3120 ts = cmd_CreateSyntax("getcacheparms", GetCacheParmsCmd, 0, "get cache usage info");
3122 ts = cmd_CreateSyntax("listcells", ListCellsCmd, 0, "list configured cells");
3124 ts = cmd_CreateSyntax("setquota", SetQuotaCmd, 0, "set volume quota");
3125 cmd_AddParm(ts, "-path", CMD_SINGLE, CMD_OPTIONAL, "dir/file path");
3126 cmd_AddParm(ts, "-max", CMD_SINGLE, 0, "max quota in kbytes");
3128 cmd_AddParm(ts, "-min", CMD_SINGLE, CMD_OPTIONAL, "min quota in kbytes");
3130 cmd_CreateAlias(ts, "sq");
3132 ts = cmd_CreateSyntax("newcell", NewCellCmd, 0, "configure new cell");
3134 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
3135 cmd_AddParm(ts, "-servers", CMD_LIST, CMD_REQUIRED, "primary servers");
3136 cmd_AddParm(ts, "-linkedcell", CMD_SINGLE, CMD_OPTIONAL, "linked cell name");
3139 #ifdef FS_ENABLE_SERVER_DEBUG_PORTS
3141 * Turn this on only if you wish to be able to talk to a server which is listening
3142 * on alternative ports. This is not intended for general use and may not be
3143 * supported in the cache manager. It is not a way to run two servers at the
3144 * same host, since the cache manager cannot properly distinguish those two hosts.
3146 cmd_AddParm(ts, "-fsport", CMD_SINGLE, CMD_OPTIONAL, "cell's fileserver port");
3147 cmd_AddParm(ts, "-vlport", CMD_SINGLE, CMD_OPTIONAL, "cell's vldb server port");
3150 ts = cmd_CreateSyntax("whichcell", WhichCellCmd, 0, "list file's cell");
3151 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3153 ts = cmd_CreateSyntax("whereis", WhereIsCmd, 0, "list file's location");
3154 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3156 ts = cmd_CreateSyntax("wscell", WSCellCmd, 0, "list workstation's cell");
3159 ts = cmd_CreateSyntax("primarycell", PrimaryCellCmd, 0, "obsolete (listed primary cell)");
3162 ts = cmd_CreateSyntax("monitor", MonitorCmd, 0, "set cache monitor host address");
3163 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_OPTIONAL, "host name or 'off'");
3164 cmd_CreateAlias(ts, "mariner");
3167 ts = cmd_CreateSyntax("getcellstatus", GetCellCmd, 0, "get cell status");
3168 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3170 ts = cmd_CreateSyntax("setcell", SetCellCmd, 0, "set cell status");
3171 cmd_AddParm(ts, "-cell", CMD_LIST, 0, "cell name");
3172 cmd_AddParm(ts, "-suid", CMD_FLAG, CMD_OPTIONAL, "allow setuid programs");
3173 cmd_AddParm(ts, "-nosuid", CMD_FLAG, CMD_OPTIONAL, "disallow setuid programs");
3175 ts = cmd_CreateSyntax("flushvolume", FlushVolumeCmd, 0, "flush all data in volume");
3176 cmd_AddParm(ts, "-path", CMD_LIST, CMD_OPTIONAL, "dir/file path");
3178 ts = cmd_CreateSyntax("sysname", SysNameCmd, 0, "get/set sysname (i.e. @sys) value");
3179 cmd_AddParm(ts, "-newsys", CMD_LIST, CMD_OPTIONAL, "new sysname");
3181 ts = cmd_CreateSyntax("exportafs", ExportAfsCmd, 0, "enable/disable translators to AFS");
3182 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "exporter name");
3183 cmd_AddParm(ts, "-start", CMD_SINGLE, CMD_OPTIONAL, "start/stop translator ('on' or 'off')");
3184 cmd_AddParm(ts, "-convert", CMD_SINGLE, CMD_OPTIONAL, "convert from afs to unix mode ('on or 'off')");
3185 cmd_AddParm(ts, "-uidcheck", CMD_SINGLE, CMD_OPTIONAL, "run on strict 'uid check' mode ('on' or 'off')");
3186 cmd_AddParm(ts, "-submounts", CMD_SINGLE, CMD_OPTIONAL, "allow nfs mounts to subdirs of /afs/.. ('on' or 'off')");
3189 ts = cmd_CreateSyntax("storebehind", StoreBehindCmd, 0,
3190 "store to server after file close");
3191 cmd_AddParm(ts, "-kbytes", CMD_SINGLE, CMD_OPTIONAL, "asynchrony for specified names");
3192 cmd_AddParm(ts, "-files", CMD_LIST, CMD_OPTIONAL, "specific pathnames");
3193 cmd_AddParm(ts, "-allfiles", CMD_SINGLE, CMD_OPTIONAL, "new default (KB)");
3194 cmd_CreateAlias(ts, "sb");
3196 ts = cmd_CreateSyntax("setcrypt", SetCryptCmd, 0, "set cache manager encryption flag");
3197 cmd_AddParm(ts, "-crypt", CMD_SINGLE, 0, "on or off");
3199 ts = cmd_CreateSyntax("getcrypt", GetCryptCmd, 0, "get cache manager encryption flag");
3201 ts = cmd_CreateSyntax("trace", TraceCmd, 0, "enable or disable CM tracing");
3202 cmd_AddParm(ts, "-on", CMD_FLAG, CMD_OPTIONAL, "enable tracing");
3203 cmd_AddParm(ts, "-off", CMD_FLAG, CMD_OPTIONAL, "disable tracing");
3204 cmd_AddParm(ts, "-reset", CMD_FLAG, CMD_OPTIONAL, "reset log contents");
3205 cmd_AddParm(ts, "-dump", CMD_FLAG, CMD_OPTIONAL, "dump log contents");
3206 cmd_CreateAlias(ts, "tr");
3208 ts = cmd_CreateSyntax("memdump", MemDumpCmd, 0, "dump memory allocs in debug builds");
3209 cmd_AddParm(ts, "-begin", CMD_FLAG, CMD_OPTIONAL, "set a memory checkpoint");
3210 cmd_AddParm(ts, "-end", CMD_FLAG, CMD_OPTIONAL, "dump memory allocs");
3212 ts = cmd_CreateSyntax("cscpolicy", CSCPolicyCmd, 0, "change client side caching policy for AFS shares");
3213 cmd_AddParm(ts, "-share", CMD_SINGLE, CMD_OPTIONAL, "AFS share");
3214 cmd_AddParm(ts, "-manual", CMD_FLAG, CMD_OPTIONAL, "manual caching of documents");
3215 cmd_AddParm(ts, "-programs", CMD_FLAG, CMD_OPTIONAL, "automatic caching of programs and documents");
3216 cmd_AddParm(ts, "-documents", CMD_FLAG, CMD_OPTIONAL, "automatic caching of documents");
3217 cmd_AddParm(ts, "-disable", CMD_FLAG, CMD_OPTIONAL, "disable caching");
3219 code = cmd_Dispatch(argc, argv);
3222 if (rxInitDone) rx_Finalize();
3223 #endif /* not WIN32 */
3228 void Die(code, filename)
3233 if (code == EINVAL) {
3235 fprintf(stderr,"%s: Invalid argument; it is possible that %s is not in AFS.\n", pn, filename);
3236 else fprintf(stderr,"%s: Invalid argument.\n", pn);
3238 else if (code == ENOENT) {
3239 if (filename) fprintf(stderr,"%s: File '%s' doesn't exist\n", pn, filename);
3240 else fprintf(stderr,"%s: no such file returned\n", pn);
3242 else if (code == EROFS) fprintf(stderr,"%s: You can not change a backup or readonly volume\n", pn);
3243 else if (code == EACCES || code == EPERM) {
3244 if (filename) fprintf(stderr,"%s: You don't have the required access rights on '%s'\n", pn, filename);
3245 else fprintf(stderr,"%s: You do not have the required rights to do this operation\n", pn);
3247 else if (code == ENODEV) {
3248 fprintf(stderr,"%s: AFS service may not have started.\n", pn);
3250 else if (code == ESRCH) {
3251 fprintf(stderr,"%s: Cell name not recognized.\n", pn);
3253 else if (code == EPIPE) {
3254 fprintf(stderr,"%s: Volume name or ID not recognized.\n", pn);
3256 else if (code == EFBIG) {
3257 fprintf(stderr,"%s: Cache size too large.\n", pn);
3259 else if (code == ETIMEDOUT) {
3261 fprintf(stderr,"%s:'%s': Connection timed out", pn, filename);
3263 fprintf(stderr,"%s: Connection timed out", pn);
3266 if (filename) fprintf(stderr,"%s:'%s'", pn, filename);
3267 else fprintf(stderr,"%s", pn);
3269 fprintf(stderr, ": code 0x%x\n", code);
3270 #else /* not WIN32 */
3271 fprintf(stderr,": %s\n", error_message(code));
3272 #endif /* not WIN32 */
3276 static MemDumpCmd(struct cmd_syndesc *asp)
3279 struct ViceIoctl blob;
3283 if ((asp->parms[0].items && asp->parms[1].items)) {
3284 fprintf(stderr, "fs trace: must use at most one of '-begin' or '-end'\n");
3288 /* determine if we're turning this tracing on or off */
3290 if (asp->parms[0].items)
3291 inValue = 1; /* begin */
3292 else if (asp->parms[1].items)
3293 inValue = 0; /* end */
3295 blob.in_size = sizeof(long);
3296 blob.in = (char *) &inValue;
3297 blob.out_size = sizeof(long);
3298 blob.out = (char *) &outValue;
3300 code = pioctl(NULL, VIOC_TRACEMEMDUMP, &blob, 1);
3306 if (outValue) printf("AFS memdump begin.\n");
3307 else printf("AFS memdump end.\n");
3312 static CSCPolicyCmd(struct cmd_syndesc *asp)
3314 struct cmd_item *ti;
3318 for(ti=asp->parms[0].items; ti;ti=ti->next) {
3330 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
3331 "SOFTWARE\\OpenAFS\\Client\\CSCPolicy",
3334 REG_OPTION_NON_VOLATILE,
3340 if ( hkCSCPolicy == NULL ) {
3341 fprintf (stderr,"Permission denied: requires Administrator access.\n");
3346 fprintf (stderr,"Permission denied: requires AFS Client Administrator access.\n");
3347 RegCloseKey(hkCSCPolicy);
3353 if (asp->parms[1].items)
3355 if (asp->parms[2].items)
3356 policy = "programs";
3357 if (asp->parms[3].items)
3358 policy = "documents";
3359 if (asp->parms[4].items)
3362 RegSetValueEx( hkCSCPolicy, share, 0, REG_SZ, policy, strlen(policy)+1);
3364 printf("CSC policy on share \"%s\" changed to \"%s\".\n\n", share, policy);
3365 printf("Close all applications that accessed files on this share or restart AFS Client for the change to take effect.\n");
3369 DWORD dwIndex, dwPolicies;
3370 char policyName[256];
3371 DWORD policyNameLen;
3376 /* list current csc policies */
3378 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
3379 "SOFTWARE\\OpenAFS\\Client\\CSCPolicy",
3382 REG_OPTION_NON_VOLATILE,
3383 KEY_READ|KEY_QUERY_VALUE,
3388 RegQueryInfoKey( hkCSCPolicy,
3390 NULL, /* lpcClass */
3391 NULL, /* lpReserved */
3392 NULL, /* lpcSubKeys */
3393 NULL, /* lpcMaxSubKeyLen */
3394 NULL, /* lpcMaxClassLen */
3395 &dwPolicies, /* lpcValues */
3396 NULL, /* lpcMaxValueNameLen */
3397 NULL, /* lpcMaxValueLen */
3398 NULL, /* lpcbSecurityDescriptor */
3399 NULL /* lpftLastWriteTime */
3402 printf("Current CSC policies:\n");
3403 for ( dwIndex = 0; dwIndex < dwPolicies; dwIndex ++ ) {
3405 policyNameLen = sizeof(policyName);
3406 policyLen = sizeof(policy);
3407 RegEnumValue( hkCSCPolicy, dwIndex, policyName, &policyNameLen, NULL,
3408 &dwType, policy, &policyLen);
3410 printf(" %s = %s\n", policyName, policy);
3414 RegCloseKey(hkCSCPolicy);