2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
18 #include <sys/types.h>
25 #include <netinet/in.h>
27 #include <sys/socket.h>
29 #endif /* AFS_NT40_ENV */
31 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
35 #include <afs/afsutil.h>
36 #include <afs/cellconfig.h>
42 #include <afs/cellconfig.h>
45 #include <afs/com_err.h>
47 #include <afs/ktime.h>
51 extern char *volutil_PartitionName();
52 extern struct rx_call *rx_NewCall();
53 extern char *volutil_PartitionName();
54 extern struct hostent *hostutil_GetHostByName();
61 #define MRAFS_OFFSET 9
62 #define ADDPARMOFFSET 26
64 static struct SalvageParms {
69 afs_int32 Optrootfiles;
70 afs_int32 Optsalvagedirs;
71 afs_int32 Optblockreads;
72 afs_int32 OptListResidencies;
73 afs_int32 OptSalvageRemote;
74 afs_int32 OptSalvageArchival;
75 afs_int32 OptIgnoreCheck;
76 afs_int32 OptForceOnLine;
77 afs_int32 OptUseRootDirACL;
78 afs_int32 OptTraceBadLinkCounts;
79 afs_int32 OptDontAskFS;
80 afs_int32 OptLogLevel;
82 afs_uint32 OptResidencies;
85 /* dummy routine for the audit work. It should do nothing since audits */
86 /* occur at the server level and bos is not a server. */
87 osi_audit() {return 0;}
89 /* keep those lines small */
90 static char *em(acode)
93 return "communications failure (-1)";
95 return "communications timeout (-3)";
96 else return (char *) error_message(acode);
99 /* get partition id from a name */
100 static afs_int32 GetPartitionID(aname)
106 if (tc == 0) return -1; /* unknown */
107 /* numbers go straight through */
108 if (tc >= '0' && tc <= '9') {
111 /* otherwise check for vicepa or /vicepa, or just plain "a" */
113 if (strlen(aname) <= 2) {
114 strcpy(ascii, aname);
116 else if (!strncmp(aname, "/vicep", 6)) {
117 strncpy(ascii, aname+6, 2);
119 else if (!strncmp(aname, "vicep", 5)) {
120 strncpy(ascii, aname+5, 2);
122 else return -1; /* bad partition name */
123 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab,
124 * .../vicepzz, and are numbered from 0. Do the appropriate conversion */
126 /* one char name, 0..25 */
127 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
128 return ascii[0] - 'a';
131 /* two char name, 26 .. <whatever> */
132 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
133 if (ascii[1] < 'a' || ascii[1] > 'z') return -1; /* just as bad */
134 return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
138 /* make ctime easier to use */
139 static char *DateOf(atime)
141 static char tbuffer[30];
143 tp=ctime((time_t *)&atime);
146 tbuffer[24] = 0; /* get rid of new line */
149 strcpy(tbuffer, "BAD TIME");
153 /* global stuff from main for communicating with GetConn */
154 static struct rx_securityClass *sc[3];
157 /* use the syntax descr to get a connection, authenticated appropriately.
158 * aencrypt is set if we want to encrypt the data on the wire.
160 static struct rx_connection *GetConn(as, aencrypt)
162 struct cmd_syndesc *as; {
165 register afs_int32 code;
166 register struct rx_connection *tconn;
168 register struct afsconf_dir *tdir;
170 struct ktc_principal sname;
171 struct ktc_token ttoken;
175 hostname = as->parms[0].items->data;
176 th = hostutil_GetHostByName(hostname);
178 printf("bos: can't find address for host '%s'\n", hostname);
181 memcpy(&addr, th->h_addr, sizeof(afs_int32));
183 /* get tokens for making authenticated connections */
184 localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
185 confdir = (localauth ? AFSDIR_SERVER_ETC_DIRPATH : AFSDIR_CLIENT_ETC_DIRPATH);
186 tdir = afsconf_Open (confdir);
188 struct afsconf_cell info;
191 if (as->parms[ADDPARMOFFSET].items)
192 tname = as->parms[ADDPARMOFFSET].items->data;
193 else tname = (char *) 0;
194 /* next call expands cell name abbrevs for us and handles looking up
196 code = afsconf_GetCellInfo(tdir, tname, (char *) 0, &info);
198 com_err ("bos", code, "(can't find cell '%s' in cell database)",
199 (tname? tname : "<default>"));
202 else strcpy(sname.cell, info.name);
205 printf("bos: can't open cell database (%s)\n", confdir);
208 sname.instance[0] = 0;
209 strcpy(sname.name, "afs");
210 sc[0] = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
215 if (!as->parms[ADDPARMOFFSET + 1].items) { /* not -noauth */
216 if (as->parms[ADDPARMOFFSET + 2].items) { /* -localauth */
217 code = afsconf_GetLatestKey (tdir, 0,0);
218 if (code) com_err ("bos", code, "(getting key from local KeyFile)");
221 code = afsconf_ClientAuthSecure (tdir, &sc[2], &scIndex);
223 code = afsconf_ClientAuth (tdir, &sc[2], &scIndex);
224 if (code) com_err ("bos", code, "(calling ClientAuth)");
225 else if (scIndex != 2) /* this shouldn't happen */
228 } else { /* not -localauth, check for tickets */
229 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), (char *)0);
231 /* have tickets, will travel */
232 if (ttoken.kvno >= 0 && ttoken.kvno <= 255) ;
235 "bos: funny kvno (%d) in ticket, proceeding\n",
239 if (aencrypt) encryptLevel = rxkad_crypt;
240 else encryptLevel = rxkad_clear;
241 sc[2] = (struct rx_securityClass *)
242 rxkad_NewClientSecurityObject
243 (encryptLevel, &ttoken.sessionKey,
244 ttoken.kvno, ttoken.ticketLen, ttoken.ticket);
246 } else com_err ("bos", code, "(getting tickets)");
248 if ((scIndex == 0) || (sc[scIndex] == 0)) {
249 fprintf (stderr, "bos: running unauthenticated\n");
253 tconn = rx_NewConnection (addr, htons(AFSCONF_NANNYPORT), 1,
254 sc[scIndex], scIndex);
256 fprintf (stderr, "bos: could not create rx connection\n");
259 rxs_Release (sc[scIndex]);
265 struct cmd_syndesc *as; {
266 register afs_int32 code;
267 register struct rx_connection *tconn;
271 tconn = GetConn(as, 0);
272 tp = as->parms[1].items->data;
273 if (strcmp(tp, "on")==0) flag = 0; /* auth req.: noauthflag is false */
274 else if (strcmp(tp, "off") == 0) flag = 1;
276 printf("bos: illegal authentication specifier '%s', must be 'off' or 'on'.\n", tp);
279 code = BOZO_SetNoAuthFlag(tconn, flag);
280 if (code) com_err ("bos", code, "(failed to set authentication flag)");
284 /* take a name (e.g. foo/bar, and a dir e.g. /usr/afs/bin, and construct
285 * /usr/afs/bin/bar */
286 static ComputeDestDir(aname, adir, aresult, alen)
287 char *aname, *adir, *aresult;
291 strcpy(aresult, adir);
292 tp = strrchr(aname, '/');
295 strcat(aresult, "/");
296 strcat(aresult, aname);
299 /* tp points at the / character */
305 /* copy data from fd afd to rx call acall */
306 static CopyBytes(afd, acall)
308 register struct rx_call *acall; {
309 register afs_int32 code;
310 register afs_int32 len;
314 len = read(afd, tbuffer, sizeof(tbuffer));
315 if (len < 0) return errno;
316 if (len == 0) return 0; /* all done */
317 code = rx_Write(acall, tbuffer, len);
318 if (code != len) return -1;
323 register struct cmd_syndesc *as; {
324 register afs_int32 code;
325 register struct rx_connection *tconn;
326 register afs_int32 flags;
328 tconn = GetConn(as, 0);
330 if (as->parms[1].items) flags |= BOZO_PRUNEBAK;
331 if (as->parms[2].items) flags |= BOZO_PRUNEOLD;
332 if (as->parms[3].items) flags |= BOZO_PRUNECORE;
333 if (as->parms[4].items) flags |= 0xff;
334 code = BOZO_Prune(tconn, flags);
335 if (code) com_err ("bos", code, "(failed to prune server files)");
340 register struct cmd_syndesc *as; {
341 register struct rx_connection *tconn;
342 register afs_int32 code;
344 tconn = GetConn(as, 0);
345 code = BOZO_Exec(tconn, as->parms[1].items->data);
346 if (code) printf("bos: failed to execute command (%s)\n",
352 register struct cmd_syndesc *as; {
353 register afs_int32 code;
356 afs_int32 time, bakTime, oldTime;
357 register struct rx_connection *tconn;
358 register struct cmd_item *ti;
360 tconn = GetConn(as, 0);
361 if (!as->parms[1].items) {
362 printf("bos: no files to check\n");
366 /* compute dest dir or file; default MUST be canonical form of dir path */
367 if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
368 else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
370 for(ti=as->parms[1].items; ti; ti=ti->next) {
371 /* check date for each file */
372 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
373 code = BOZO_GetDates(tconn, tbuffer, &time, &bakTime, &oldTime);
375 printf("bos: failed to check date on %s (%s)\n", ti->data,
380 printf("File %s ", tbuffer);
381 if (time == 0) printf("does not exist, ");
382 else printf("dated %s, ", DateOf(time));
383 if (bakTime == 0) printf("no .BAK file, ");
384 else printf(".BAK file dated %s, ", DateOf(bakTime));
385 if (oldTime == 0) printf("no .OLD file.");
386 else printf(".OLD file dated %s.", DateOf(oldTime));
393 register struct cmd_syndesc *as; {
394 register afs_int32 code;
397 register struct cmd_item *ti;
398 register struct rx_connection *tconn;
400 tconn = GetConn(as, 0);
401 if (!as->parms[1].items) {
402 printf("bos: no files to uninstall\n");
406 /* compute dest dir or file; default MUST be canonical form of dir path */
407 if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
408 else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
410 for(ti=as->parms[1].items; ti; ti=ti->next) {
411 /* uninstall each file */
412 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
413 code = BOZO_UnInstall(tconn, tbuffer);
415 printf("bos: failed to uninstall %s (%s)\n", ti->data,
419 else printf("bos: uninstalled file %s\n", ti->data);
424 static afs_int32 GetServerGoal(aconn, aname)
426 struct rx_connection *aconn; {
429 register afs_int32 code;
430 struct bozo_status istatus;
433 code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
435 printf("bos: failed to get instance info for '%s' (%s)\n",
437 /* if we can't get the answer, assume its running */
440 if (istatus.goal == 0)
441 return BSTAT_SHUTDOWN;
447 struct cmd_syndesc *as; {
448 struct rx_connection *tconn;
449 register afs_int32 code;
450 register struct cmd_item *ti;
454 struct rx_call *tcall;
457 tconn = GetConn(as, 0);
458 if (!as->parms[1].items) {
459 printf("bos: no files to install\n");
463 /* compute dest dir or file; default MUST be canonical form of dir path */
464 if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
465 else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
467 for(ti=as->parms[1].items; ti; ti=ti->next) {
468 /* install each file */
469 fd = open(ti->data, O_RDONLY);
471 /* better to quit on error than continue for install command */
472 printf("bos: can't find file '%s', quitting\n", ti->data);
475 code = fstat(fd, &tstat);
477 printf("bos: failed to stat file %s, errno is %d\n", ti->data,
481 /* compute destination dir */
482 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
483 tcall = rx_NewCall(tconn);
484 code = StartBOZO_Install(tcall, tbuffer, tstat.st_size, (afs_int32)tstat.st_mode,
487 code = CopyBytes(fd, tcall);
489 code = rx_EndCall(tcall, code);
491 printf("bos: failed to install %s (%s)\n", ti->data, em(code));
494 else printf("bos: installed file %s\n", ti->data);
500 struct cmd_syndesc *as; {
501 register struct rx_connection *tconn;
502 register afs_int32 code;
503 register struct cmd_item *ti;
505 tconn = GetConn(as, 0);
506 if (as->parms[1].items == 0) {
507 code = BOZO_ShutdownAll(tconn);
508 if (code) printf("bos: failed to shutdown servers (%s)\n", em(code));
511 for(ti = as->parms[1].items; ti; ti=ti->next) {
512 code = BOZO_SetTStatus(tconn, ti->data, BSTAT_SHUTDOWN);
514 printf("bos: failed to shutdown instance %s (%s)\n",
518 if (as->parms[8].items) {
519 code = BOZO_WaitAll(tconn);
521 printf("bos: can't wait for processes to shutdown (%s)\n",
527 static BlockScannerCmd(as, arock)
528 struct cmd_syndesc *as;
530 register afs_int32 code;
531 struct rx_connection *tconn;
532 char BlockCommand[] = "/usr/afs/bin/scanner -block";
534 tconn = GetConn(as, 0);
535 code = BOZO_Exec(tconn, BlockCommand);
537 printf("bos: failed to block scanner from making migration requests (%s)\n",
542 static UnBlockScannerCmd(as, arock)
543 struct cmd_syndesc *as;
545 register afs_int32 code;
546 struct rx_connection *tconn;
547 char UnBlockCommand[] = "/usr/afs/bin/scanner -unblock";
549 tconn = GetConn(as, 0);
550 code = BOZO_Exec(tconn, UnBlockCommand);
552 printf("bos: failed to allow scanner daemon to make migration requests again (%s)\n",
557 static GetRestartCmd(as, arock)
558 struct cmd_syndesc *as;
560 register afs_int32 code;
561 struct ktime generalTime, newBinaryTime;
562 char messageBuffer[256];
563 struct rx_connection *tconn;
566 hostp = as->parms[0].items->data; /* host name for messages */
567 tconn = GetConn(as, 0);
569 code = BOZO_GetRestartTime(tconn, 1, &generalTime);
571 printf("bos: failed to retrieve restart information (%s)\n", em(code));
574 code = BOZO_GetRestartTime(tconn, 2, &newBinaryTime);
576 printf("bos: failed to retrieve restart information (%s)\n", em(code));
580 code = ktime_DisplayString(&generalTime, messageBuffer);
582 printf("bos: failed to decode restart time (%s)\n", em(code));
585 printf("Server %s restarts %s\n", hostp, messageBuffer);
587 code = ktime_DisplayString(&newBinaryTime, messageBuffer);
589 printf("bos: failed to decode restart time (%s)\n", em(code));
592 printf("Server %s restarts for new binaries %s\n", hostp, messageBuffer);
598 static SetRestartCmd(as, arock)
599 struct cmd_syndesc *as;
602 register afs_int32 code;
603 struct ktime restartTime;
605 struct rx_connection *tconn;
608 tconn = GetConn(as, 0);
609 if (as->parms[2].items) {count++; type = 1;}
610 if (as->parms[3].items) {count++; type = 2;}
612 printf("bos: can't specify more than one restart time at a time\n");
615 if (count == 0) type = 1; /* by default set general restart time */
617 if (code = ktime_ParsePeriodic(as->parms[1].items->data, &restartTime)) {
618 printf("bos: failed to parse '%s' as periodic restart time(%s)\n",
619 as->parms[1].items->data, em(code));
623 code = BOZO_SetRestartTime(tconn, type, &restartTime);
625 printf("bos: failed to set restart time at server (%s)\n", em(code));
632 struct cmd_syndesc *as; {
633 register struct rx_connection *tconn;
634 register afs_int32 code;
635 register struct cmd_item *ti;
637 tconn = GetConn(as, 0);
638 if (as->parms[1].items == 0) {
639 code = BOZO_StartupAll(tconn);
641 printf("bos: failed to startup servers (%s)\n", em(code));
644 for(ti = as->parms[1].items; ti; ti=ti->next) {
645 code = BOZO_SetTStatus(tconn, ti->data, BSTAT_NORMAL);
647 printf("bos: failed to start instance %s (%s)\n",
655 struct cmd_syndesc *as; {
656 register struct rx_connection *tconn;
657 register afs_int32 code;
658 register struct cmd_item *ti;
660 tconn = GetConn(as, 0);
661 if (as->parms[2].items) {
662 /* this is really a rebozo command */
663 if (as->parms[1].items) {
664 /* specified specific things to restart, can't do this at the same
666 printf("bos: can't specify both '-bos' and specific servers to restart.\n");
669 /* otherwise do a rebozo */
670 code = BOZO_ReBozo(tconn);
672 printf("bos: failed to restart bosserver (%s)\n", em(code));
675 if (as->parms[1].items == 0) {
676 if (as->parms[3].items) { /* '-all' */
677 code = BOZO_RestartAll(tconn);
678 if (code) printf("bos: failed to restart servers (%s)\n", em(code));
680 printf("bos: To restart all processes please specify '-all'\n");
683 if (as->parms[3].items) {
684 printf("bos: Can't use '-all' along with individual instances\n");
686 for(ti = as->parms[1].items; ti; ti=ti->next) {
687 code = BOZO_Restart(tconn, ti->data);
689 printf("bos: failed to restart instance %s (%s)\n", ti->data,
697 static SetCellName(as)
698 struct cmd_syndesc *as; {
699 register struct rx_connection *tconn;
700 register afs_int32 code;
702 tconn = GetConn(as, 0);
703 code = BOZO_SetCellName(tconn, as->parms[1].items->data);
704 if (code) printf("bos: failed to set cell (%s)\n", em(code));
709 register struct cmd_syndesc *as; {
710 register struct rx_connection *tconn;
711 register afs_int32 code;
712 register struct cmd_item *ti;
713 char name[MAXHOSTCHARS];
715 tconn = GetConn(as, 0);
716 for(ti = as->parms[1].items; ti; ti=ti->next) {
717 if (as->parms[2].items) {
718 if (strlen(ti->data) > MAXHOSTCHARS - 3) {
719 fprintf(stderr, "bos: host name too long\n");
723 strcpy(&name[1],ti->data);
724 strcat((char *)&name, "]");
725 code = BOZO_AddCellHost(tconn, name);
727 code = BOZO_AddCellHost(tconn, ti->data);
729 printf("bos: failed to add host %s (%s)\n", ti->data, em(code));
734 static RemoveHost(as)
735 register struct cmd_syndesc *as; {
736 register struct rx_connection *tconn;
737 register afs_int32 code;
738 register struct cmd_item *ti;
740 tconn = GetConn(as, 0);
741 for(ti=as->parms[1].items; ti; ti=ti->next) {
742 code = BOZO_DeleteCellHost(tconn, ti->data);
744 printf("bos: failed to delete host %s (%s)\n", ti->data, em(code));
750 register struct cmd_syndesc *as; {
751 register struct rx_connection *tconn;
752 register afs_int32 code;
755 register afs_int32 i;
758 tconn = GetConn(as, 0);
759 code = BOZO_GetCellName(tconn, &tp);
761 printf("bos: failed to get cell name (%s)\n", em(code));
764 printf("Cell name is %s\n", tbuffer);
766 code = BOZO_GetCellHost(tconn, i, &tp);
767 if (code == BZDOM) break;
769 printf("bos: failed to get cell host %d (%s)\n", i, em(code));
772 printf(" Host %d is %s\n", i+1, tbuffer);
778 register struct cmd_syndesc *as; {
779 register struct rx_connection *tconn;
780 register afs_int32 code;
781 struct ktc_encryptionKey tkey;
784 char cellBuffer[256];
785 char buf[BUFSIZ], ver[BUFSIZ];
787 tconn = GetConn(as, 1);
788 memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
790 if(as->parms[1].items)
791 strcpy(buf,as->parms[1].items->data);
795 code=des_read_pw_string(buf,sizeof(buf),"input key: ",0);
796 if(code || strlen(buf)==0)
798 fprintf(stderr,"Bad key: \n");
801 code=des_read_pw_string(ver,sizeof(ver),"Retype input key: ",0);
802 if(code || strlen(ver)==0)
804 fprintf(stderr,"Bad key: \n");
807 if (strcmp (ver, buf) != 0) {
808 fprintf (stderr, "\nInput key mismatch\n");
814 temp = atoi(as->parms[2].items->data);
818 strcpy((char *)&tkey, as->parms[1].items->data);
820 strcpy((char *)&tkey, buf);
822 else { /* kerberos key */
823 if (as->parms[ADDPARMOFFSET].items) {
824 strcpy(cellBuffer, as->parms[ADDPARMOFFSET].items->data);
826 /* string to key needs upper-case cell names */
828 /* I don't believe this is true. The string to key function
829 * actually expands the cell name, then LOWER-CASES it. Perhaps it
830 * didn't use to??? */
831 ucstring(cellBuffer, cellBuffer, strlen(cellBuffer));
834 else tcell = (char *) 0; /* no cell specified, use current */
836 ka_StringToKey(as->parms[1].items->data, tcell, &tkey);
838 ka_StringToKey(buf,tcell,&tkey);
840 tconn = GetConn(as, 1);
841 code = BOZO_AddKey(tconn, temp, &tkey);
843 printf("bos: failed to set key %d (%s)\n", temp, em(code));
850 register struct cmd_syndesc *as; {
851 register struct rx_connection *tconn;
852 register afs_int32 code;
854 register struct cmd_item *ti;
856 tconn = GetConn(as, 0);
857 for(ti=as->parms[1].items; ti; ti=ti->next) {
858 temp = atoi(ti->data);
859 code = BOZO_DeleteKey(tconn, temp);
861 printf("bos: failed to delete key %d (%s)\n", temp, em(code));
869 IN register struct cmd_syndesc *as;
871 register struct rx_connection *tconn;
872 register afs_int32 code;
873 struct ktc_encryptionKey tkey;
875 struct bozo_keyInfo keyInfo;
877 register afs_int32 i;
879 tconn = GetConn(as, 1);
882 code = BOZO_ListKeys(tconn, i, &kvno, &tkey, &keyInfo);
885 /* first check if key is returned */
886 if ((!ka_KeyIsZero (&tkey, sizeof(tkey))) && (as->parms[1].items)) {
887 printf ("key %d is '", kvno);
888 ka_PrintBytes (&tkey, sizeof(tkey));
891 if (keyInfo.keyCheckSum == 0) /* shouldn't happen */
892 printf ("key version is %d\n", kvno);
894 printf ("key %d has cksum %u\n", kvno, keyInfo.keyCheckSum);
898 printf("Keys last changed on %s.\n", DateOf(keyInfo.mod_sec));
901 printf("bos: %s error encountered while listing keys\n", em(code));
903 printf("All done.\n");
908 register struct cmd_syndesc *as; {
909 register struct rx_connection *tconn;
910 register afs_int32 code;
912 register struct cmd_item *ti;
915 tconn = GetConn(as, 0);
916 for(ti=as->parms[1].items; ti; ti=ti->next) {
917 code = BOZO_AddSUser(tconn, ti->data);
919 printf("bos: failed to add user '%s' (%s)\n", ti->data, em(code));
926 static RemoveSUser(as)
927 register struct cmd_syndesc *as; {
928 register struct rx_connection *tconn;
929 register struct cmd_item *ti;
930 register afs_int32 code;
934 tconn = GetConn(as, 0);
935 for(ti=as->parms[1].items; ti; ti=ti->next) {
936 code = BOZO_DeleteSUser(tconn, ti->data);
938 printf("bos: failed to delete user '%s', ", ti->data);
940 printf("(no such user)\n");
942 printf("(%s)\n", em(code));
949 #define NPERLINE 10 /* dudes to print per line */
950 static ListSUsers(as)
951 register struct cmd_syndesc *as; {
952 register struct rx_connection *tconn;
954 register afs_int32 code;
957 int lastNL, printGreeting;
959 tconn = GetConn(as, 0);
964 code = BOZO_ListSUsers(tconn, i, &tp);
967 printGreeting = 0; /* delay until after first call succeeds */
968 printf("SUsers are: ");
970 printf("%s ", tbuffer);
971 if ((i % NPERLINE) == NPERLINE-1) {
978 /* a real error code, instead of scanned past end */
979 printf("bos: failed to retrieve super-user list (%s)\n", em(code));
982 if (lastNL == 0) printf("\n");
986 static StatServer(as)
987 register struct cmd_syndesc *as; {
988 register struct rx_connection *tconn;
989 register afs_int32 code;
991 char ibuffer[BOZO_BSSIZE];
995 /* int32p==1 is obsolete, smaller, printout */
996 int32p = (as->parms[2].items != 0? 2 : 0);
998 /* no parms does something pretty different */
999 if (as->parms[1].items) return IStatServer(as, int32p);
1001 tconn = GetConn(as, 0);
1003 /* for each instance */
1005 code = BOZO_EnumerateInstance(tconn, i, &tp);
1006 if (code == BZDOM) break;
1008 printf("bos: failed to contact host's bosserver (%s).\n",
1012 DoStat(ibuffer, tconn, int32p, (i==0)); /* print status line */
1017 static CreateServer(as)
1018 register struct cmd_syndesc *as; {
1019 register struct rx_connection *tconn;
1020 register afs_int32 code;
1022 register struct cmd_item *ti;
1024 char *type, *name, *notifier=NONOTIFIER;
1026 tconn = GetConn(as, 0);
1027 for(i=0;i<6;i++) parms[i] = "";
1028 for(i=0,ti=as->parms[3].items; (ti && i<6); ti=ti->next,i++) {
1029 parms[i] = ti->data;
1031 name = as->parms[1].items->data;
1032 type = as->parms[2].items->data;
1033 if (ti = as->parms[4].items) {
1034 notifier = ti->data;
1036 code = BOZO_CreateBnode(tconn, type, name, parms[0], parms[1], parms[2],
1037 parms[3], parms[4], notifier);
1039 printf("bos: failed to create new server instance %s of type '%s' (%s)\n",
1040 name, type, em(code));
1045 static DeleteServer(as)
1046 register struct cmd_syndesc *as; {
1047 register struct rx_connection *tconn;
1048 register afs_int32 code;
1049 register struct cmd_item *ti;
1052 tconn = GetConn(as, 0);
1053 for(ti=as->parms[1].items; ti; ti=ti->next) {
1054 code = BOZO_DeleteBnode(tconn, ti->data);
1057 printf("bos: can't delete running instance '%s'\n", ti->data);
1059 printf("bos: failed to delete instance '%s' (%s)\n",
1060 ti->data, em(code));
1066 static StartServer(as)
1067 register struct cmd_syndesc *as; {
1068 register struct rx_connection *tconn;
1069 register afs_int32 code;
1070 register struct cmd_item *ti;
1073 tconn = GetConn(as, 0);
1074 for(ti=as->parms[1].items; ti; ti=ti->next) {
1075 code = BOZO_SetStatus(tconn, ti->data, BSTAT_NORMAL);
1077 printf("bos: failed to start instance '%s' (%s)\n",
1078 ti->data, em(code));
1083 static StopServer(as)
1084 register struct cmd_syndesc *as; {
1085 register struct rx_connection *tconn;
1086 register afs_int32 code;
1087 register struct cmd_item *ti;
1090 tconn = GetConn(as, 0);
1091 for(ti=as->parms[1].items; ti; ti=ti->next) {
1092 code = BOZO_SetStatus(tconn, ti->data, BSTAT_SHUTDOWN);
1094 printf("bos: failed to change stop instance '%s' (%s)\n",
1095 ti->data, em(code));
1097 if (as->parms[8].items) {
1098 code = BOZO_WaitAll(tconn);
1100 printf("bos: can't wait for processes to shutdown (%s)\n",
1106 #define PARMBUFFERSSIZE 32
1108 static DoSalvage(aconn, aparm1, aparm2, aoutName, showlog,parallel,atmpDir,orphans)
1109 struct rx_connection *aconn;
1118 register afs_int32 code;
1121 char tbuffer[BOZO_BSSIZE];
1122 struct bozo_status istatus;
1123 struct rx_call *tcall;
1127 char partName[20]; /* canonical name for partition */
1128 char pbuffer[PARMBUFFERSSIZE];
1129 afs_int32 partNumber;
1130 char *notifier = NONOTIFIER;
1132 /* if a partition was specified, canonicalize the name, since
1133 the salvager has a stupid partition ID parser */
1135 partNumber = volutil_GetPartitionID(aparm1);
1136 if (partNumber < 0) {
1137 printf("bos: could not parse partition ID '%s'\n", aparm1);
1140 tp = volutil_PartitionName(partNumber);
1142 printf("bos: internal error parsing partition ID '%s'\n", aparm1);
1145 strcpy(partName, tp);
1147 else partName[0] = 0;
1149 /* open the file name */
1151 outFile = fopen(aoutName, "w");
1153 printf("bos: can't open specified SalvageLog file '%s'\n",
1157 closeIt = 1; /* close this file later */
1161 closeIt = 0; /* don't close this file later */
1164 for(code=2;code<6;code++) parms[code] = "";
1165 if (!aparm2) aparm2 = "";
1166 /* MUST pass canonical (wire-format) salvager path to bosserver */
1167 strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH, BOZO_BSSIZE);
1169 if ( (strlen(tbuffer) + 1 + strlen(partName) + 1 + strlen(aparm2) + 1) > BOZO_BSSIZE ) {
1170 printf("bos: command line too big\n");
1173 strcat(tbuffer, " ");
1174 strcat(tbuffer, partName);
1175 strcat(tbuffer, " ");
1176 strcat(tbuffer, aparm2);
1178 if ( (strlen(tbuffer) + 4 + strlen(partName) + 1) > BOZO_BSSIZE ) {
1179 printf("bos: command line too big\n");
1182 strcat (tbuffer, " -f ");
1183 strcat (tbuffer, partName);
1186 /* add the parallel option if given */
1187 if (parallel != (char *)0) {
1188 if ( (strlen(tbuffer) + 11 + strlen(parallel) + 1) > BOZO_BSSIZE ) {
1189 printf("bos: command line too big\n");
1192 strcat(tbuffer, " -parallel ");
1193 strcat(tbuffer, parallel);
1196 /* add the tmpdir option if given */
1197 if (atmpDir != (char *)0) {
1198 if ( (strlen(tbuffer) + 9 + strlen(atmpDir) + 1) > BOZO_BSSIZE ) {
1199 printf("bos: command line too big\n");
1202 strcat(tbuffer, " -tmpdir ");
1203 strcat(tbuffer, atmpDir);
1206 /* add the orphans option if given */
1207 if (orphans != (char *)0) {
1208 if ( (strlen(tbuffer) + 10 + strlen(orphans) + 1) > BOZO_BSSIZE ) {
1209 printf("bos: command line too big\n");
1212 strcat(tbuffer, " -orphans ");
1213 strcat(tbuffer, orphans);
1216 if (mrafsParm.Optdebug)
1217 strcat(tbuffer," -debug");
1218 if (mrafsParm.Optnowrite)
1219 strcat(tbuffer," -nowrite");
1220 if (mrafsParm.Optforce)
1221 strcat(tbuffer," -force");
1222 if (mrafsParm.Optoktozap)
1223 strcat(tbuffer," -oktozap");
1224 if (mrafsParm.Optrootfiles)
1225 strcat(tbuffer," -rootfiles");
1226 if (mrafsParm.Optsalvagedirs)
1227 strcat(tbuffer," -salvagedirs");
1228 if (mrafsParm.Optblockreads)
1229 strcat(tbuffer," -blockreads");
1230 if (mrafsParm.OptListResidencies)
1231 strcat(tbuffer," -ListResidencies");
1232 if (mrafsParm.OptSalvageRemote)
1233 strcat(tbuffer," -SalvageRemote");
1234 if (mrafsParm.OptSalvageArchival)
1235 strcat(tbuffer," -SalvageArchival");
1236 if (mrafsParm.OptIgnoreCheck)
1237 strcat(tbuffer," -IgnoreCheck");
1238 if (mrafsParm.OptForceOnLine)
1239 strcat(tbuffer," -ForceOnLine");
1240 if (mrafsParm.OptUseRootDirACL)
1241 strcat(tbuffer," -UseRootDirACL");
1242 if (mrafsParm.OptTraceBadLinkCounts)
1243 strcat(tbuffer," -TraceBadLinkCounts");
1244 if (mrafsParm.OptDontAskFS)
1245 strcat(tbuffer," -DontAskFS");
1246 if (mrafsParm.OptLogLevel) {
1247 sprintf(pbuffer, " -LogLevel %ld", mrafsParm.OptLogLevel);
1248 strcat(tbuffer, pbuffer);
1250 if (mrafsParm.OptRxDebug)
1251 strcat(tbuffer," -rxdebug");
1252 if (mrafsParm.OptResidencies) {
1253 sprintf(pbuffer, " -Residencies %lu", mrafsParm.OptResidencies);
1254 strcat(tbuffer, pbuffer);
1258 parms[1] = "now"; /* when to do it */
1259 code = BOZO_CreateBnode(aconn, "cron", "salvage-tmp", parms[0], parms[1],
1260 parms[2], parms[3], parms[4], notifier);
1261 if (code) goto done;
1262 /* now wait for bnode to disappear */
1266 code = BOZO_GetInstanceInfo(aconn, "salvage-tmp", &tp, &istatus);
1268 printf("bos: waiting for salvage to complete.\n");
1270 if (code != BZNOENT) {
1271 printf("bos: salvage failed (%s)\n", em(code));
1276 /* now print the log file to the output file */
1277 printf("bos: salvage completed\n");
1278 if (aoutName || showlog) {
1279 fprintf(outFile, "SalvageLog:\n");
1280 tcall = rx_NewCall(aconn);
1281 /* MUST pass canonical (wire-format) salvager log path to bosserver */
1282 code = StartBOZO_GetLog(tcall, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH);
1284 rx_EndCall(tcall, code);
1289 code = rx_Read(tcall, &buffer, 1);
1290 if (code != 1) break;
1291 putc(buffer, outFile);
1292 if (buffer == 0) break; /* the end delimeter */
1294 code = rx_EndCall(tcall, 0);
1295 /* fall through into cleanup code */
1299 if (closeIt && outFile) fclose(outFile);
1303 static GetLogCmd(as)
1304 register struct cmd_syndesc *as; {
1305 struct rx_connection *tconn;
1306 register struct rx_call *tcall;
1307 register afs_int32 code;
1311 printf("Fetching log file '%s'...\n", as->parms[1].items->data);
1312 tconn = GetConn(as, 0);
1313 tcall = rx_NewCall(tconn);
1314 code = StartBOZO_GetLog(tcall, as->parms[1].items->data);
1316 rx_EndCall(tcall, code);
1322 code = rx_Read(tcall, &buffer, 1);
1327 if (buffer == 0) break; /* the end delimeter */
1330 code = rx_EndCall(tcall, error);
1331 /* fall through into cleanup code */
1335 com_err("bos", code, "(while reading log)");
1339 static SalvageCmd(as)
1340 struct cmd_syndesc *as; {
1341 register struct rx_connection *tconn;
1342 register afs_int32 code, rc, i;
1344 char tname[BOZO_BSSIZE];
1346 extern struct ubik_client *cstruct;
1347 afs_int32 curGoal, showlog = 0, mrafs = 0;
1353 memset(&mrafsParm, 0, sizeof(mrafsParm));
1355 /* parm 0 is machine name, 1 is partition, 2 is volume, 3 is -all flag */
1356 tconn = GetConn(as, 0);
1358 /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
1359 /* XXX this should really be done some other way, potentially by RPC */
1361 if (code = BOZO_GetInstanceParm(tconn, "fs", 3, &tp) == 0)
1364 /* we can do a volume, a partition or the whole thing, but not mixtures
1366 if (!as->parms[1].items && as->parms[2].items) {
1367 printf("bos: must specify partition to salvage individual volume.\n");
1370 if (as->parms[5].items && as->parms[3].items) {
1371 printf("bos: can not specify both -file and -showlog.\n");
1374 if (as->parms[4].items && (as->parms[1].items || as->parms[2].items)) {
1375 printf("bos: can not specify -all with other flags.\n");
1379 /* get the output file name, if any */
1380 if (as->parms[3].items)
1381 outName = as->parms[3].items->data;
1383 outName = (char *) 0;
1385 if (as->parms[5].items)
1388 /* parallel option */
1389 parallel = (char *) 0;
1390 if (as->parms[6].items)
1391 parallel = as->parms[6].items->data;
1393 /* get the tmpdir filename if any */
1395 if (as->parms[7].items)
1396 tmpDir = as->parms[7].items->data;
1398 /* -orphans option */
1399 orphans = (char *)0;
1400 if (as->parms[8].items) {
1402 printf("Can't specify -orphans for MR-AFS fileserver\n");
1405 orphans = as->parms[8].items->data;
1409 if (as->parms[MRAFS_OFFSET].items)
1410 mrafsParm.Optdebug = 1;
1411 if (as->parms[MRAFS_OFFSET + 1].items)
1412 mrafsParm.Optnowrite = 1;
1413 if (as->parms[MRAFS_OFFSET + 2].items)
1414 mrafsParm.Optforce = 1;
1415 if (as->parms[MRAFS_OFFSET + 3].items)
1416 mrafsParm.Optoktozap = 1;
1417 if (as->parms[MRAFS_OFFSET + 4].items)
1418 mrafsParm.Optrootfiles = 1;
1419 if (as->parms[MRAFS_OFFSET + 5].items)
1420 mrafsParm.Optsalvagedirs = 1;
1421 if (as->parms[MRAFS_OFFSET + 6].items)
1422 mrafsParm.Optblockreads = 1;
1423 if (as->parms[MRAFS_OFFSET + 7].items)
1424 mrafsParm.OptListResidencies = 1;
1425 if (as->parms[MRAFS_OFFSET + 8].items)
1426 mrafsParm.OptSalvageRemote = 1;
1427 if (as->parms[MRAFS_OFFSET + 9].items)
1428 mrafsParm.OptSalvageArchival = 1;
1429 if (as->parms[MRAFS_OFFSET + 10].items)
1430 mrafsParm.OptIgnoreCheck = 1;
1431 if (as->parms[MRAFS_OFFSET + 11].items)
1432 mrafsParm.OptForceOnLine = 1;
1433 if (as->parms[MRAFS_OFFSET + 12].items)
1434 mrafsParm.OptUseRootDirACL = 1;
1435 if (as->parms[MRAFS_OFFSET + 13].items)
1436 mrafsParm.OptTraceBadLinkCounts = 1;
1437 if (as->parms[MRAFS_OFFSET + 14].items)
1438 mrafsParm.OptDontAskFS = 1;
1439 if (as->parms[MRAFS_OFFSET + 15].items)
1440 mrafsParm.OptLogLevel = atoi(as->parms[MRAFS_OFFSET + 15].items->data);
1441 if (as->parms[MRAFS_OFFSET + 16].items)
1442 mrafsParm.OptRxDebug = 1;
1443 if (as->parms[MRAFS_OFFSET + 17].items) {
1444 if (as->parms[MRAFS_OFFSET + 8].items ||
1445 as->parms[MRAFS_OFFSET + 9].items) {
1446 printf("Can't specify -Residencies with -SalvageRemote or -SalvageArchival\n");
1449 code = GetUInt32(as->parms[MRAFS_OFFSET + 17].items->data,
1450 &mrafsParm.OptResidencies);
1452 printf("bos: '%s' is not a valid residency mask.\n",
1453 as->parms[MRAFS_OFFSET + 13].items->data);
1460 for (i = 9; i < ADDPARMOFFSET; i++) {
1461 if (as->parms[i].items) {
1462 printf(" %s only possible for MR-AFS fileserver.\n",
1470 if (as->parms[4].items) {
1471 /* salvage whole enchilada */
1472 curGoal = GetServerGoal(tconn, "fs");
1473 if (curGoal == BSTAT_NORMAL) {
1474 printf("bos: shutting down fs.\n");
1475 code = BOZO_SetTStatus(tconn, "fs", BSTAT_SHUTDOWN);
1477 printf("bos: failed to stop 'fs' (%s)\n", em(code));
1480 code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1482 printf("bos: failed to wait for file server shutdown, continuing.\n");
1484 /* now do the salvage operation */
1485 printf("Starting salvage.\n");
1486 rc = DoSalvage(tconn, (char *) 0, (char *) 0, outName, showlog,parallel,tmpDir,orphans);
1487 if (rc) printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1488 if (curGoal == BSTAT_NORMAL) {
1489 printf("bos: restarting fs.\n");
1490 code = BOZO_SetTStatus(tconn, "fs", BSTAT_NORMAL);
1492 printf("bos: failed to restart 'fs' (%s)\n", em(code));
1498 else if (!as->parms[2].items) {
1499 if (!as->parms[1].items) {
1500 printf("bos: must specify -all switch to salvage all partitions.\n");
1503 if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1504 /* can't parse volume ID, so complain before shutting down
1507 printf("bos: can't interpret %s as partition ID.\n",
1508 as->parms[1].items->data);
1511 curGoal = GetServerGoal(tconn, "fs");
1512 /* salvage a whole partition (specified by parms[1]) */
1513 if (curGoal == BSTAT_NORMAL) {
1514 printf("bos: shutting down fs.\n");
1515 code = BOZO_SetTStatus(tconn, "fs", BSTAT_SHUTDOWN);
1517 printf("bos: can't stop 'fs' (%s)\n", em(code));
1520 code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1522 printf("bos: failed to wait for file server shutdown, continuing.\n");
1524 /* now do the salvage operation */
1525 printf("Starting salvage.\n");
1526 rc = DoSalvage(tconn, as->parms[1].items->data, (char *) 0,
1527 outName, showlog,parallel,tmpDir,orphans);
1528 if (rc) printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1529 if (curGoal == BSTAT_NORMAL) {
1530 printf("bos: restarting fs.\n");
1531 code = BOZO_SetTStatus(tconn, "fs", BSTAT_NORMAL);
1533 printf("bos: failed to restart 'fs' (%s)\n", em(code));
1540 /* salvage individual volume (don't shutdown fs first), just use
1541 * single-shot cron bnode. Must leave server running when using this
1542 * option, since salvager will ask file server for the volume */
1545 const char *confdir;
1548 if (as->parms[ADDPARMOFFSET].items)
1549 tmpname = as->parms[ADDPARMOFFSET].items->data;
1550 else tmpname = (char *) 0;
1552 localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
1553 confdir = (localauth ? AFSDIR_SERVER_ETC_DIRPATH : AFSDIR_CLIENT_ETC_DIRPATH);
1554 code = vsu_ClientInit(/* noauth */ 1, confdir, tmpname,
1555 /* server auth */ 0, &cstruct, (int (*)()) 0);
1557 newID = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1559 printf("bos: can't interpret %s as volume name or ID\n", as->parms[2].items->data);
1562 sprintf(tname, "%u", newID);
1565 printf("bos: can't initialize volume system client (code %d), trying anyway.\n",
1566 as->parms[2].items->data, code);
1567 strncpy(tname, as->parms[2].items->data, sizeof(tname));
1569 if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1570 /* can't parse volume ID, so complain before shutting down
1573 printf("bos: can't interpret %s as partition ID.\n",
1574 as->parms[1].items->data);
1577 printf("Starting salvage.\n");
1578 rc = DoSalvage(tconn, as->parms[1].items->data, tname, outName,
1579 showlog,parallel,tmpDir,orphans);
1581 printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1588 static IStatServer(as, int32p)
1590 register struct cmd_syndesc *as; {
1591 register struct rx_connection *tconn;
1592 register struct cmd_item *ti;
1595 tconn = GetConn(as, 0);
1596 for (ti=as->parms[1].items; ti; ti=ti->next) {
1597 DoStat(ti->data, tconn, int32p, firstTime);
1603 static DoStat (aname, aconn, aint32p, firstTime)
1605 IN register struct rx_connection *aconn;
1607 IN int firstTime; /* true iff first instance in cmd */
1611 register afs_int32 code;
1612 register afs_int32 i;
1613 struct bozo_status istatus;
1615 char *is1, *is2, *is3, *is4; /* instance strings */
1618 code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
1620 printf("bos: failed to get instance info for '%s' (%s)\n",
1624 if (firstTime && aint32p && (istatus.flags & BOZO_BADDIRACCESS))
1625 printf ("Bosserver reports inappropriate access on server directories\n");
1626 printf("Instance %s, ", aname);
1627 if (aint32p) printf("(type is %s) ", buffer);
1628 if (istatus.fileGoal == istatus.goal) {
1629 if (!istatus.goal) printf("disabled, ");
1632 if (istatus.fileGoal) printf("temporarily disabled, ");
1633 else printf("temporarily enabled, ");
1636 if (istatus.flags & BOZO_ERRORSTOP)
1637 printf("stopped for too many errors, ");
1638 if (istatus.flags & BOZO_HASCORE)
1639 printf("has core file, ");
1642 code = BOZO_GetStatus(aconn, aname, &temp, &tp);
1644 printf("bos: failed to get status for instance '%s' (%s)\n",
1647 printf("currently ", aname);
1648 if (temp == BSTAT_NORMAL) printf("running normally.\n");
1649 else if (temp == BSTAT_SHUTDOWN) printf("shutdown.\n");
1650 else if (temp == BSTAT_STARTINGUP) printf("starting up.\n");
1651 else if (temp == BSTAT_SHUTTINGDOWN) printf("shutting down.\n");
1652 if (buffer[0] != 0) {
1653 printf(" Auxiliary status is: %s.\n", buffer);
1657 /* are we done yet? */
1658 if (!aint32p) return 0;
1660 if (istatus.procStartTime)
1661 printf(" Process last started at %s (%d proc starts)\n",
1662 DateOf(istatus.procStartTime), istatus.procStarts);
1663 if (istatus.lastAnyExit) {
1664 printf(" Last exit at %s\n", DateOf(istatus.lastAnyExit));
1666 if (istatus.lastErrorExit) {
1667 is1 = is2 = is3 = is4 = (char *) 0;
1668 printf(" Last error exit at %s, ", DateOf(istatus.lastErrorExit));
1669 code = BOZO_GetInstanceStrings(aconn, aname, &is1, &is2, &is3, &is4);
1670 /* don't complain about failing call, since could simply mean
1671 * interface mismatch.
1675 /* non-null instance string */
1676 printf("by %s, ", is1);
1683 if (istatus.errorSignal) {
1684 if (istatus.errorSignal == SIGTERM)
1685 printf("due to shutdown request\n");
1687 printf("due to signal %d\n", istatus.errorSignal);
1690 printf("by exiting with code %d\n", istatus.errorCode);
1694 /* try to display all the parms */
1697 code = BOZO_GetInstanceParm(aconn, aname, i, &tp);
1699 printf(" Command %d is '%s'\n", i+1, buffer);
1702 code = BOZO_GetInstanceParm(aconn, aname, 999, &tp);
1704 /* Any type of failure is treated as not having a notifier program */
1705 printf(" Notifier is '%s'\n", buffer);
1712 #ifdef BOS_RESTRICTED_MODE
1713 static GetRestrict(as)
1714 struct cmd_syndesc *as; {
1715 register struct rx_connection *tconn;
1716 afs_int32 code, val;
1718 tconn = GetConn(as, 0);
1719 code = BOZO_GetRestrictedMode(tconn, &val);
1720 if (code) printf("bos: failed to get restricted mode (%s)\n", em(code));
1721 else printf("Restricted mode is %s\n", val ? "on" : "off");
1726 static SetRestrict(as)
1727 struct cmd_syndesc *as; {
1728 register struct rx_connection *tconn;
1729 afs_int32 code, val;
1731 tconn = GetConn(as, 0);
1732 util_GetInt32(as->parms[1].items->data, &val);
1733 code = BOZO_SetRestrictedMode(tconn, val);
1734 if (code) printf("bos: failed to set restricted mode (%s)\n", em(code));
1739 static void add_std_args (ts)
1740 register struct cmd_syndesc *ts;
1742 cmd_Seek(ts, ADDPARMOFFSET);
1743 /* + 0 */ cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1744 /* + 1 */ cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1745 "don't authenticate");
1746 /* + 2 */ cmd_AddParm (ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1747 "create tickets from KeyFile");
1750 #include "AFS_component_version_number.c"
1756 register afs_int32 code;
1757 register struct cmd_syndesc *ts;
1758 extern int afsconf_SawCell;
1760 #ifdef AFS_AIX32_ENV
1762 * The following signal action for AIX is necessary so that in case of a
1763 * crash (i.e. core is generated) we can include the user's data section
1764 * in the core dump. Unfortunately, by default, only a partial core is
1765 * generated which, in many cases, isn't too useful.
1767 struct sigaction nsa;
1769 sigemptyset(&nsa.sa_mask);
1770 nsa.sa_handler = SIG_DFL;
1771 nsa.sa_flags = SA_FULLDUMP;
1772 sigaction(SIGSEGV, &nsa, NULL);
1773 sigaction(SIGABRT, &nsa, NULL);
1779 printf("bos: could not initialize rx (%s)\n", em(code));
1783 /* To resolve a AFSCELL environment "Note: ..." problem: Because bos calls ka_Init (why?) before any
1784 * checkup on the existance of a "-cell" option on the particular bos command we don't print the
1785 * message if a cell is passed in. Luckily the rest of the programs don't call these adhoc routines
1786 * and things work fine. Note that if the "-cell" isn't passed then we're still ok since later on
1787 * the proper routine (afsconf_GetCellInfo) is going to be called to do the right thing.
1789 afsconf_SawCell = 1; /* Means don't print warning if AFSCELL is set */
1791 afsconf_SawCell = 0; /* Reset it */
1792 /* don't check error code, since fails sometimes when we're setting up a
1794 initialize_cmd_error_table();
1795 initialize_bz_error_table();
1797 ts = cmd_CreateSyntax("start", StartServer, 0, "start running a server");
1798 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1799 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1802 ts = cmd_CreateSyntax("stop", StopServer, 0, "halt a server instance");
1803 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1804 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1806 cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1807 "wait for process to stop");
1810 ts = cmd_CreateSyntax("status", StatServer, 0,
1811 "show server instance status");
1812 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1813 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL,
1814 "server process name");
1815 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "long status");
1818 ts = cmd_CreateSyntax("shutdown", Shutdown, 0, "shutdown all processes");
1819 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1820 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1822 cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1823 "wait for process to stop");
1826 ts = cmd_CreateSyntax("startup", Startup, 0, "start all processes");
1827 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1828 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1831 ts = cmd_CreateSyntax("restart", Restart, 0, "restart all processes");
1832 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1833 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1834 cmd_AddParm(ts, "-bosserver", CMD_FLAG, CMD_OPTIONAL, "restart bosserver");
1835 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "restart all processes");
1840 ts = cmd_CreateSyntax("create", CreateServer, 0,
1841 "create a new server instance");
1842 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1843 cmd_AddParm(ts, "-instance", CMD_SINGLE, 0, "server process name");
1844 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "server type");
1845 cmd_AddParm(ts, "-cmd", CMD_LIST, 0, "command lines");
1846 cmd_AddParm(ts, "-notifier", CMD_SINGLE, CMD_OPTIONAL, "Notifier program");
1849 ts = cmd_CreateSyntax("delete", DeleteServer, 0,
1850 "delete a server instance");
1851 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1852 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1855 ts = cmd_CreateSyntax("adduser", AddSUser, 0,
1856 "add users to super-user list");
1857 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1858 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
1861 ts = cmd_CreateSyntax("removeuser", RemoveSUser, 0,
1862 "remove users from super-user list");
1863 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1864 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
1867 ts = cmd_CreateSyntax("listusers", ListSUsers, 0, "list super-users");
1868 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1871 ts = cmd_CreateSyntax("addkey", AddKey, 0,
1872 "add keys to key dbase (kvno 999 is bcrypt)");
1873 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1874 cmd_AddParm(ts, "-key", CMD_SINGLE, CMD_OPTIONAL, "key");
1875 cmd_AddParm(ts, "-kvno", CMD_SINGLE, 0, "key version number");
1878 ts = cmd_CreateSyntax("removekey", RemoveKey, 0,
1879 "remove keys from key dbase");
1880 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1881 cmd_AddParm(ts, "-kvno", CMD_LIST, 0, "key version number");
1884 ts = cmd_CreateSyntax("listkeys", ListKeys, 0, "list keys");
1885 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1886 cmd_AddParm(ts, "-showkey", CMD_FLAG, CMD_OPTIONAL, "show the actual key rather than the checksum");
1889 ts = cmd_CreateSyntax("listhosts", ListHosts, 0, "get cell host list");
1890 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1892 cmd_CreateAlias(ts, "getcell");
1894 ts = cmd_CreateSyntax("setcellname", SetCellName, 0, "set cell name");
1895 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1896 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
1899 ts = cmd_CreateSyntax("addhost", AddHost, 0, "add host to cell dbase");
1900 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1901 cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
1902 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL, "vote doesn't count");
1905 ts = cmd_CreateSyntax("removehost", RemoveHost, 0,
1906 "remove host from cell dbase");
1907 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1908 cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
1911 ts = cmd_CreateSyntax("setauth", SetAuth, 0,
1912 "set authentication required flag");
1913 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1914 cmd_AddParm(ts, "-authrequired", CMD_SINGLE,
1915 0, "on or off: authentication required for admin requests");
1918 ts = cmd_CreateSyntax("install", Install, 0, "install program");
1919 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1920 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to install");
1921 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1924 ts = cmd_CreateSyntax("uninstall", UnInstall, 0, "uninstall program");
1925 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1926 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to uninstall");
1927 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1930 ts = cmd_CreateSyntax("getlog", GetLogCmd, 0, "examine log file");
1931 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1932 cmd_AddParm(ts, "-file", CMD_SINGLE, 0, "log file to examine");
1935 ts = cmd_CreateSyntax("getdate", GetDate, 0, "get dates for programs");
1936 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1937 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to check");
1938 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1941 ts = cmd_CreateSyntax("exec", Exec, 0, "execute shell command on server");
1942 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1943 cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "command to execute");
1946 ts = cmd_CreateSyntax("prune", Prune, 0, "prune server files");
1947 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1948 cmd_AddParm(ts, "-bak", CMD_FLAG, CMD_OPTIONAL, "delete .BAK files");
1949 cmd_AddParm(ts, "-old", CMD_FLAG, CMD_OPTIONAL, "delete .OLD files");
1950 cmd_AddParm(ts, "-core", CMD_FLAG, CMD_OPTIONAL, "delete core files");
1951 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "delete all junk files");
1954 ts = cmd_CreateSyntax("setrestart", SetRestartCmd, 0, "set restart times");
1955 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
1956 cmd_AddParm(ts, "-time", CMD_SINGLE,
1957 CMD_REQUIRED, "time to restart server");
1958 cmd_AddParm(ts, "-general", CMD_FLAG,
1959 CMD_OPTIONAL, "set general restart time");
1960 cmd_AddParm(ts, "-newbinary", CMD_FLAG,
1961 CMD_OPTIONAL, "set new binary restart time");
1964 ts = cmd_CreateSyntax("getrestart", GetRestartCmd, 0, "get restart times");
1965 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
1968 ts = cmd_CreateSyntax("salvage", SalvageCmd, 0,
1969 "salvage partition or volumes");
1970 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1971 cmd_AddParm(ts, "-partition", CMD_SINGLE,
1972 CMD_OPTIONAL, "salvage partition");
1973 cmd_AddParm(ts, "-volume", CMD_SINGLE,
1974 CMD_OPTIONAL, "salvage volume number or volume name");
1975 cmd_AddParm(ts, "-file", CMD_SINGLE,
1976 CMD_OPTIONAL, "salvage log output file");
1977 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "salvage whole server");
1978 cmd_AddParm(ts, "-showlog", CMD_FLAG, CMD_OPTIONAL, "display salvage log");
1979 cmd_AddParm(ts, "-parallel",CMD_SINGLE, CMD_OPTIONAL,
1980 "# of max parallel partition salvaging");
1981 cmd_AddParm(ts, "-tmpdir",CMD_SINGLE, CMD_OPTIONAL,
1982 "directory to place tmp files");
1983 cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL,
1984 "ignore | remove | attach");
1985 cmd_AddParm(ts, "-debug", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Run in Debugging mode");
1986 cmd_AddParm(ts, "-nowrite", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Run readonly/test mode");
1987 cmd_AddParm(ts, "-force", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force full salvaging");
1988 cmd_AddParm(ts, "-oktozap", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Give permission to destroy bogus file residencies/volumes - debugging flag");
1989 cmd_AddParm(ts, "-rootfiles", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Show files owned by root - debugging flag");
1990 cmd_AddParm(ts, "-salvagedirs", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force rebuild/salvage of all directories");
1991 cmd_AddParm(ts, "-blockreads", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Read smaller blocks to handle IO/bad blocks");
1992 cmd_AddParm(ts, "-ListResidencies", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Just list affected file residencies - debugging flag");
1993 cmd_AddParm(ts, "-SalvageRemote", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Salvage storage systems that are not directly attached");
1994 cmd_AddParm(ts, "-SalvageArchival", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Salvage HSM storage systems");
1995 cmd_AddParm(ts, "-IgnoreCheck", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Don't perform VLDB safety check when deleting unreferenced files. Only a good idea in single server cell.");
1996 cmd_AddParm(ts, "-ForceOnLine", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force the volume to come online, even if it hasn't salvaged cleanly.");
1997 cmd_AddParm(ts, "-UseRootDirACL", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Use the root directory ACL for lost+found directory if it is created.");
1998 cmd_AddParm(ts, "-TraceBadLinkCounts", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Print out lines about volume reference count changes.");
1999 cmd_AddParm(ts, "-DontAskFS", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Don't ask fileserver to take volume offline. THIS IS VERY DANGEROUS.");
2000 cmd_AddParm(ts, "-LogLevel", CMD_SINGLE, CMD_OPTIONAL, "(MR-AFS) log level");
2001 cmd_AddParm(ts, "-rxdebug", CMD_FLAG, CMD_OPTIONAL, "(MR-AFS) Write out rx debug information.");
2002 cmd_AddParm(ts, "-Residencies", CMD_SINGLE, CMD_OPTIONAL, "(MR-AFS) Numeric mask of residencies to be included in the salvage. Do not use with -SalvageRemote or -SalvageArchival");
2005 ts = cmd_CreateSyntax("blockscanner", BlockScannerCmd, 0,
2006 "block scanner daemon from making migration requests");
2007 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2010 ts = cmd_CreateSyntax("unblockscanner", UnBlockScannerCmd, 0,
2011 "allow scanner daemon to make migration requests again");
2012 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2015 #ifdef BOS_RESTRICTED_MODE
2016 ts = cmd_CreateSyntax("getrestricted", GetRestrict, 0, "get restrict mode");
2017 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2020 ts = cmd_CreateSyntax("setrestricted", SetRestrict, 0, "set restrict mode");
2021 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2022 cmd_AddParm(ts, "-mode", CMD_SINGLE, 0, "mode to set");
2027 code = cmd_Dispatch(argc, argv);