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>
14 #include <sys/types.h>
21 #include <netinet/in.h>
23 #include <sys/socket.h>
25 #endif /* AFS_NT40_ENV */
27 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
31 #include <afs/afsutil.h>
32 #include <afs/cellconfig.h>
38 #include <afs/cellconfig.h>
41 #include <afs/com_err.h>
43 #include <afs/ktime.h>
47 extern char *volutil_PartitionName();
48 extern struct rx_call *rx_NewCall();
49 extern char *volutil_PartitionName();
50 extern struct hostent *hostutil_GetHostByName();
56 #include "../permit_xprt.h"
58 #define MRAFS_OFFSET 9
59 #define ADDPARMOFFSET 26
61 static struct SalvageParms {
66 afs_int32 Optrootfiles;
67 afs_int32 Optsalvagedirs;
68 afs_int32 Optblockreads;
69 afs_int32 OptListResidencies;
70 afs_int32 OptSalvageRemote;
71 afs_int32 OptSalvageArchival;
72 afs_int32 OptIgnoreCheck;
73 afs_int32 OptForceOnLine;
74 afs_int32 OptUseRootDirACL;
75 afs_int32 OptTraceBadLinkCounts;
76 afs_int32 OptDontAskFS;
77 afs_int32 OptLogLevel;
79 afs_uint32 OptResidencies;
82 /* dummy routine for the audit work. It should do nothing since audits */
83 /* occur at the server level and bos is not a server. */
84 osi_audit() {return 0;}
86 /* keep those lines small */
87 static char *em(acode)
90 return "communications failure (-1)";
92 return "communications timeout (-3)";
93 else return (char *) error_message(acode);
96 /* get partition id from a name */
97 static afs_int32 GetPartitionID(aname)
103 if (tc == 0) return -1; /* unknown */
104 /* numbers go straight through */
105 if (tc >= '0' && tc <= '9') {
108 /* otherwise check for vicepa or /vicepa, or just plain "a" */
110 if (strlen(aname) <= 2) {
111 strcpy(ascii, aname);
113 else if (!strncmp(aname, "/vicep", 6)) {
114 strncpy(ascii, aname+6, 2);
116 else if (!strncmp(aname, "vicep", 5)) {
117 strncpy(ascii, aname+5, 2);
119 else return -1; /* bad partition name */
120 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab,
121 * .../vicepzz, and are numbered from 0. Do the appropriate conversion */
123 /* one char name, 0..25 */
124 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
125 return ascii[0] - 'a';
128 /* two char name, 26 .. <whatever> */
129 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
130 if (ascii[1] < 'a' || ascii[1] > 'z') return -1; /* just as bad */
131 return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
135 /* make ctime easier to use */
136 static char *DateOf(atime)
138 static char tbuffer[30];
140 tp=ctime((time_t *)&atime);
143 tbuffer[24] = 0; /* get rid of new line */
146 strcpy(tbuffer, "BAD TIME");
150 /* global stuff from main for communicating with GetConn */
151 static struct rx_securityClass *sc[3];
154 /* use the syntax descr to get a connection, authenticated appropriately.
155 * aencrypt is set if we want to encrypt the data on the wire.
157 static struct rx_connection *GetConn(as, aencrypt)
159 struct cmd_syndesc *as; {
162 register afs_int32 code;
163 register struct rx_connection *tconn;
165 register struct afsconf_dir *tdir;
167 struct ktc_principal sname;
168 struct ktc_token ttoken;
172 hostname = as->parms[0].items->data;
173 th = hostutil_GetHostByName(hostname);
175 printf("bos: can't find address for host '%s'\n", hostname);
178 bcopy(th->h_addr, &addr, sizeof(afs_int32));
180 /* get tokens for making authenticated connections */
181 localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
182 confdir = (localauth ? AFSDIR_SERVER_ETC_DIRPATH : AFSDIR_CLIENT_ETC_DIRPATH);
183 tdir = afsconf_Open (confdir);
185 struct afsconf_cell info;
188 if (as->parms[ADDPARMOFFSET].items)
189 tname = as->parms[ADDPARMOFFSET].items->data;
190 else tname = (char *) 0;
191 /* next call expands cell name abbrevs for us and handles looking up
193 code = afsconf_GetCellInfo(tdir, tname, (char *) 0, &info);
195 com_err ("bos", code, "(can't find cell '%s' in cell database)",
196 (tname? tname : "<default>"));
199 else strcpy(sname.cell, info.name);
202 printf("bos: can't open cell database (%s)\n", confdir);
205 sname.instance[0] = 0;
206 strcpy(sname.name, "afs");
207 sc[0] = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
212 if (!as->parms[ADDPARMOFFSET + 1].items) { /* not -noauth */
213 if (as->parms[ADDPARMOFFSET + 2].items) { /* -localauth */
214 code = afsconf_GetLatestKey (tdir, 0,0);
215 if (code) com_err ("bos", code, "(getting key from local KeyFile)");
218 code = afsconf_ClientAuthSecure (tdir, &sc[2], &scIndex);
220 code = afsconf_ClientAuth (tdir, &sc[2], &scIndex);
221 if (code) com_err ("bos", code, "(calling ClientAuth)");
222 else if (scIndex != 2) /* this shouldn't happen */
225 } else { /* not -localauth, check for tickets */
226 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), (char *)0);
228 /* have tickets, will travel */
229 if (ttoken.kvno >= 0 && ttoken.kvno <= 255) ;
232 "bos: funny kvno (%d) in ticket, proceeding\n",
236 if (aencrypt) encryptLevel = rxkad_crypt;
237 else encryptLevel = rxkad_clear;
238 sc[2] = (struct rx_securityClass *)
239 rxkad_NewClientSecurityObject
240 (encryptLevel, &ttoken.sessionKey,
241 ttoken.kvno, ttoken.ticketLen, ttoken.ticket);
243 } else com_err ("bos", code, "(getting tickets)");
245 if ((scIndex == 0) || (sc[scIndex] == 0)) {
246 fprintf (stderr, "bos: running unauthenticated\n");
250 tconn = rx_NewConnection (addr, htons(AFSCONF_NANNYPORT), 1,
251 sc[scIndex], scIndex);
253 fprintf (stderr, "bos: could not create rx connection\n");
256 rxs_Release (sc[scIndex]);
262 struct cmd_syndesc *as; {
263 register afs_int32 code;
264 register struct rx_connection *tconn;
268 tconn = GetConn(as, 0);
269 tp = as->parms[1].items->data;
270 if (strcmp(tp, "on")==0) flag = 0; /* auth req.: noauthflag is false */
271 else if (strcmp(tp, "off") == 0) flag = 1;
273 printf("bos: illegal authentication specifier '%s', must be 'off' or 'on'.\n", tp);
276 code = BOZO_SetNoAuthFlag(tconn, flag);
277 if (code) com_err ("bos", code, "(failed to set authentication flag)");
281 /* take a name (e.g. foo/bar, and a dir e.g. /usr/afs/bin, and construct
282 * /usr/afs/bin/bar */
283 static ComputeDestDir(aname, adir, aresult, alen)
284 char *aname, *adir, *aresult;
288 strcpy(aresult, adir);
289 tp = rindex(aname, '/');
292 strcat(aresult, "/");
293 strcat(aresult, aname);
296 /* tp points at the / character */
302 /* copy data from fd afd to rx call acall */
303 static CopyBytes(afd, acall)
305 register struct rx_call *acall; {
306 register afs_int32 code;
307 register afs_int32 len;
311 len = read(afd, tbuffer, sizeof(tbuffer));
312 if (len < 0) return errno;
313 if (len == 0) return 0; /* all done */
314 code = rx_Write(acall, tbuffer, len);
315 if (code != len) return -1;
320 register struct cmd_syndesc *as; {
321 register afs_int32 code;
322 register struct rx_connection *tconn;
323 register afs_int32 flags;
325 tconn = GetConn(as, 0);
327 if (as->parms[1].items) flags |= BOZO_PRUNEBAK;
328 if (as->parms[2].items) flags |= BOZO_PRUNEOLD;
329 if (as->parms[3].items) flags |= BOZO_PRUNECORE;
330 if (as->parms[4].items) flags |= 0xff;
331 code = BOZO_Prune(tconn, flags);
332 if (code) com_err ("bos", code, "(failed to prune server files)");
337 register struct cmd_syndesc *as; {
338 register struct rx_connection *tconn;
339 register afs_int32 code;
341 tconn = GetConn(as, 0);
342 code = BOZO_Exec(tconn, as->parms[1].items->data);
343 if (code) printf("bos: failed to execute command (%s)\n",
349 register struct cmd_syndesc *as; {
350 register afs_int32 code;
353 afs_int32 time, bakTime, oldTime;
354 register struct rx_connection *tconn;
355 register struct cmd_item *ti;
357 tconn = GetConn(as, 0);
358 if (!as->parms[1].items) {
359 printf("bos: no files to check\n");
363 /* compute dest dir or file; default MUST be canonical form of dir path */
364 if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
365 else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
367 for(ti=as->parms[1].items; ti; ti=ti->next) {
368 /* check date for each file */
369 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
370 code = BOZO_GetDates(tconn, tbuffer, &time, &bakTime, &oldTime);
372 printf("bos: failed to check date on %s (%s)\n", ti->data,
377 printf("File %s ", tbuffer);
378 if (time == 0) printf("does not exist, ");
379 else printf("dated %s, ", DateOf(time));
380 if (bakTime == 0) printf("no .BAK file, ");
381 else printf(".BAK file dated %s, ", DateOf(bakTime));
382 if (oldTime == 0) printf("no .OLD file.");
383 else printf(".OLD file dated %s.", DateOf(oldTime));
390 register struct cmd_syndesc *as; {
391 register afs_int32 code;
394 register struct cmd_item *ti;
395 register struct rx_connection *tconn;
397 tconn = GetConn(as, 0);
398 if (!as->parms[1].items) {
399 printf("bos: no files to uninstall\n");
403 /* compute dest dir or file; default MUST be canonical form of dir path */
404 if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
405 else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
407 for(ti=as->parms[1].items; ti; ti=ti->next) {
408 /* uninstall each file */
409 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
410 code = BOZO_UnInstall(tconn, tbuffer);
412 printf("bos: failed to uninstall %s (%s)\n", ti->data,
416 else printf("bos: uninstalled file %s\n", ti->data);
421 static afs_int32 GetServerGoal(aconn, aname)
423 struct rx_connection *aconn; {
426 register afs_int32 code;
427 struct bozo_status istatus;
430 code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
432 printf("bos: failed to get instance info for '%s' (%s)\n",
434 /* if we can't get the answer, assume its running */
437 if (istatus.goal == 0)
438 return BSTAT_SHUTDOWN;
444 struct cmd_syndesc *as; {
445 struct rx_connection *tconn;
446 register afs_int32 code;
447 register struct cmd_item *ti;
451 struct rx_call *tcall;
454 tconn = GetConn(as, 0);
455 if (!as->parms[1].items) {
456 printf("bos: no files to install\n");
460 /* compute dest dir or file; default MUST be canonical form of dir path */
461 if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
462 else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
464 for(ti=as->parms[1].items; ti; ti=ti->next) {
465 /* install each file */
466 fd = open(ti->data, O_RDONLY);
468 /* better to quit on error than continue for install command */
469 printf("bos: can't find file '%s', quitting\n", ti->data);
472 code = fstat(fd, &tstat);
474 printf("bos: failed to stat file %s, errno is %d\n", ti->data,
478 /* compute destination dir */
479 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
480 tcall = rx_NewCall(tconn);
481 code = StartBOZO_Install(tcall, tbuffer, tstat.st_size, (afs_int32)tstat.st_mode,
484 code = CopyBytes(fd, tcall);
486 code = rx_EndCall(tcall, code);
488 printf("bos: failed to install %s (%s)\n", ti->data, em(code));
491 else printf("bos: installed file %s\n", ti->data);
497 struct cmd_syndesc *as; {
498 register struct rx_connection *tconn;
499 register afs_int32 code;
500 register struct cmd_item *ti;
502 tconn = GetConn(as, 0);
503 if (as->parms[1].items == 0) {
504 code = BOZO_ShutdownAll(tconn);
505 if (code) printf("bos: failed to shutdown servers (%s)\n", em(code));
508 for(ti = as->parms[1].items; ti; ti=ti->next) {
509 code = BOZO_SetTStatus(tconn, ti->data, BSTAT_SHUTDOWN);
511 printf("bos: failed to shutdown instance %s (%s)\n",
515 if (as->parms[8].items) {
516 code = BOZO_WaitAll(tconn);
518 printf("bos: can't wait for processes to shutdown (%s)\n",
524 static BlockScannerCmd(as, arock)
525 struct cmd_syndesc *as;
527 register afs_int32 code;
528 struct rx_connection *tconn;
529 char BlockCommand[] = "/usr/afs/bin/scanner -block";
531 tconn = GetConn(as, 0);
532 code = BOZO_Exec(tconn, BlockCommand);
534 printf("bos: failed to block scanner from making migration requests (%s)\n",
539 static UnBlockScannerCmd(as, arock)
540 struct cmd_syndesc *as;
542 register afs_int32 code;
543 struct rx_connection *tconn;
544 char UnBlockCommand[] = "/usr/afs/bin/scanner -unblock";
546 tconn = GetConn(as, 0);
547 code = BOZO_Exec(tconn, UnBlockCommand);
549 printf("bos: failed to allow scanner daemon to make migration requests again (%s)\n",
554 static GetRestartCmd(as, arock)
555 struct cmd_syndesc *as;
557 register afs_int32 code;
558 struct ktime generalTime, newBinaryTime;
559 char messageBuffer[256];
560 struct rx_connection *tconn;
563 hostp = as->parms[0].items->data; /* host name for messages */
564 tconn = GetConn(as, 0);
566 code = BOZO_GetRestartTime(tconn, 1, &generalTime);
568 printf("bos: failed to retrieve restart information (%s)\n", em(code));
571 code = BOZO_GetRestartTime(tconn, 2, &newBinaryTime);
573 printf("bos: failed to retrieve restart information (%s)\n", em(code));
577 code = ktime_DisplayString(&generalTime, messageBuffer);
579 printf("bos: failed to decode restart time (%s)\n", em(code));
582 printf("Server %s restarts %s\n", hostp, messageBuffer);
584 code = ktime_DisplayString(&newBinaryTime, messageBuffer);
586 printf("bos: failed to decode restart time (%s)\n", em(code));
589 printf("Server %s restarts for new binaries %s\n", hostp, messageBuffer);
595 static SetRestartCmd(as, arock)
596 struct cmd_syndesc *as;
599 register afs_int32 code;
600 struct ktime restartTime;
602 struct rx_connection *tconn;
605 tconn = GetConn(as, 0);
606 if (as->parms[2].items) {count++; type = 1;}
607 if (as->parms[3].items) {count++; type = 2;}
609 printf("bos: can't specify more than one restart time at a time\n");
612 if (count == 0) type = 1; /* by default set general restart time */
614 if (code = ktime_ParsePeriodic(as->parms[1].items->data, &restartTime)) {
615 printf("bos: failed to parse '%s' as periodic restart time(%s)\n",
616 as->parms[1].items->data, em(code));
620 code = BOZO_SetRestartTime(tconn, type, &restartTime);
622 printf("bos: failed to set restart time at server (%s)\n", em(code));
629 struct cmd_syndesc *as; {
630 register struct rx_connection *tconn;
631 register afs_int32 code;
632 register struct cmd_item *ti;
634 tconn = GetConn(as, 0);
635 if (as->parms[1].items == 0) {
636 code = BOZO_StartupAll(tconn);
638 printf("bos: failed to startup servers (%s)\n", em(code));
641 for(ti = as->parms[1].items; ti; ti=ti->next) {
642 code = BOZO_SetTStatus(tconn, ti->data, BSTAT_NORMAL);
644 printf("bos: failed to start instance %s (%s)\n",
652 struct cmd_syndesc *as; {
653 register struct rx_connection *tconn;
654 register afs_int32 code;
655 register struct cmd_item *ti;
657 tconn = GetConn(as, 0);
658 if (as->parms[2].items) {
659 /* this is really a rebozo command */
660 if (as->parms[1].items) {
661 /* specified specific things to restart, can't do this at the same
663 printf("bos: can't specify both '-bos' and specific servers to restart.\n");
666 /* otherwise do a rebozo */
667 code = BOZO_ReBozo(tconn);
669 printf("bos: failed to restart bosserver (%s)\n", em(code));
672 if (as->parms[1].items == 0) {
673 if (as->parms[3].items) { /* '-all' */
674 code = BOZO_RestartAll(tconn);
675 if (code) printf("bos: failed to restart servers (%s)\n", em(code));
677 printf("bos: To restart all processes please specify '-all'\n");
680 if (as->parms[3].items) {
681 printf("bos: Can't use '-all' along with individual instances\n");
683 for(ti = as->parms[1].items; ti; ti=ti->next) {
684 code = BOZO_Restart(tconn, ti->data);
686 printf("bos: failed to restart instance %s (%s)\n", ti->data,
694 static SetCellName(as)
695 struct cmd_syndesc *as; {
696 register struct rx_connection *tconn;
697 register afs_int32 code;
699 tconn = GetConn(as, 0);
700 code = BOZO_SetCellName(tconn, as->parms[1].items->data);
701 if (code) printf("bos: failed to set cell (%s)\n", em(code));
706 register struct cmd_syndesc *as; {
707 register struct rx_connection *tconn;
708 register afs_int32 code;
709 register struct cmd_item *ti;
711 tconn = GetConn(as, 0);
712 for(ti = as->parms[1].items; ti; ti=ti->next) {
713 code = BOZO_AddCellHost(tconn, ti->data);
715 printf("bos: failed to add host %s (%s)\n", ti->data, em(code));
720 static RemoveHost(as)
721 register struct cmd_syndesc *as; {
722 register struct rx_connection *tconn;
723 register afs_int32 code;
724 register struct cmd_item *ti;
726 tconn = GetConn(as, 0);
727 for(ti=as->parms[1].items; ti; ti=ti->next) {
728 code = BOZO_DeleteCellHost(tconn, ti->data);
730 printf("bos: failed to delete host %s (%s)\n", ti->data, em(code));
736 register struct cmd_syndesc *as; {
737 register struct rx_connection *tconn;
738 register afs_int32 code;
741 register afs_int32 i;
744 tconn = GetConn(as, 0);
745 code = BOZO_GetCellName(tconn, &tp);
747 printf("bos: failed to get cell name (%s)\n", em(code));
750 printf("Cell name is %s\n", tbuffer);
752 code = BOZO_GetCellHost(tconn, i, &tp);
753 if (code == BZDOM) break;
755 printf("bos: failed to get cell host %d (%s)\n", i, em(code));
758 printf(" Host %d is %s\n", i+1, tbuffer);
764 register struct cmd_syndesc *as; {
765 register struct rx_connection *tconn;
766 register afs_int32 code;
767 struct ktc_encryptionKey tkey;
770 char cellBuffer[256];
771 char buf[BUFSIZ], ver[BUFSIZ];
773 tconn = GetConn(as, 1);
774 bzero(&tkey, sizeof(struct ktc_encryptionKey));
776 if(as->parms[1].items)
777 strcpy(buf,as->parms[1].items->data);
781 code=des_read_pw_string(buf,sizeof(buf),"input key: ",0);
782 if(code || strlen(buf)==0)
784 fprintf(stderr,"Bad key: \n");
787 code=des_read_pw_string(ver,sizeof(ver),"Retype input key: ",0);
788 if(code || strlen(ver)==0)
790 fprintf(stderr,"Bad key: \n");
793 if (strcmp (ver, buf) != 0) {
794 fprintf (stderr, "\nInput key mismatch\n");
800 temp = atoi(as->parms[2].items->data);
804 strcpy((char *)&tkey, as->parms[1].items->data);
806 strcpy((char *)&tkey, buf);
808 else { /* kerberos key */
809 if (as->parms[ADDPARMOFFSET].items) {
810 strcpy(cellBuffer, as->parms[ADDPARMOFFSET].items->data);
812 /* string to key needs upper-case cell names */
814 /* I don't believe this is true. The string to key function
815 * actually expands the cell name, then LOWER-CASES it. Perhaps it
816 * didn't use to??? */
817 ucstring(cellBuffer, cellBuffer, strlen(cellBuffer));
820 else tcell = (char *) 0; /* no cell specified, use current */
822 ka_StringToKey(as->parms[1].items->data, tcell, &tkey);
824 ka_StringToKey(buf,tcell,&tkey);
826 tconn = GetConn(as, 1);
827 code = BOZO_AddKey(tconn, temp, &tkey);
829 printf("bos: failed to set key %d (%s)\n", temp, em(code));
836 register struct cmd_syndesc *as; {
837 register struct rx_connection *tconn;
838 register afs_int32 code;
840 register struct cmd_item *ti;
842 tconn = GetConn(as, 0);
843 for(ti=as->parms[1].items; ti; ti=ti->next) {
844 temp = atoi(ti->data);
845 code = BOZO_DeleteKey(tconn, temp);
847 printf("bos: failed to delete key %d (%s)\n", temp, em(code));
855 IN register struct cmd_syndesc *as;
857 register struct rx_connection *tconn;
858 register afs_int32 code;
859 struct ktc_encryptionKey tkey;
861 struct bozo_keyInfo keyInfo;
863 register afs_int32 i;
865 tconn = GetConn(as, 1);
868 code = BOZO_ListKeys(tconn, i, &kvno, &tkey, &keyInfo);
871 /* first check if key is returned */
872 if ((!ka_KeyIsZero (&tkey, sizeof(tkey))) && (as->parms[1].items)) {
873 printf ("key %d is '", kvno);
874 ka_PrintBytes (&tkey, sizeof(tkey));
877 if (keyInfo.keyCheckSum == 0) /* shouldn't happen */
878 printf ("key version is %d\n", kvno);
880 printf ("key %d has cksum %u\n", kvno, keyInfo.keyCheckSum);
884 printf("Keys last changed on %s.\n", DateOf(keyInfo.mod_sec));
887 printf("bos: %s error encountered while listing keys\n", em(code));
889 printf("All done.\n");
894 register struct cmd_syndesc *as; {
895 register struct rx_connection *tconn;
896 register afs_int32 code;
898 register struct cmd_item *ti;
901 tconn = GetConn(as, 0);
902 for(ti=as->parms[1].items; ti; ti=ti->next) {
903 code = BOZO_AddSUser(tconn, ti->data);
905 printf("bos: failed to add user '%s' (%s)\n", ti->data, em(code));
912 static RemoveSUser(as)
913 register struct cmd_syndesc *as; {
914 register struct rx_connection *tconn;
915 register struct cmd_item *ti;
916 register afs_int32 code;
920 tconn = GetConn(as, 0);
921 for(ti=as->parms[1].items; ti; ti=ti->next) {
922 code = BOZO_DeleteSUser(tconn, ti->data);
924 printf("bos: failed to delete user '%s', ", ti->data);
926 printf("(no such user)\n");
928 printf("(%s)\n", em(code));
935 #define NPERLINE 10 /* dudes to print per line */
936 static ListSUsers(as)
937 register struct cmd_syndesc *as; {
938 register struct rx_connection *tconn;
940 register afs_int32 code;
943 int lastNL, printGreeting;
945 tconn = GetConn(as, 0);
950 code = BOZO_ListSUsers(tconn, i, &tp);
953 printGreeting = 0; /* delay until after first call succeeds */
954 printf("SUsers are: ");
956 printf("%s ", tbuffer);
957 if ((i % NPERLINE) == NPERLINE-1) {
964 /* a real error code, instead of scanned past end */
965 printf("bos: failed to retrieve super-user list (%s)\n", em(code));
968 if (lastNL == 0) printf("\n");
972 static StatServer(as)
973 register struct cmd_syndesc *as; {
974 register struct rx_connection *tconn;
975 register afs_int32 code;
977 char ibuffer[BOZO_BSSIZE];
981 /* int32p==1 is obsolete, smaller, printout */
982 int32p = (as->parms[2].items != 0? 2 : 0);
984 /* no parms does something pretty different */
985 if (as->parms[1].items) return IStatServer(as, int32p);
987 tconn = GetConn(as, 0);
989 /* for each instance */
991 code = BOZO_EnumerateInstance(tconn, i, &tp);
992 if (code == BZDOM) break;
994 printf("bos: failed to contact host's bosserver (%s).\n",
998 DoStat(ibuffer, tconn, int32p, (i==0)); /* print status line */
1003 static CreateServer(as)
1004 register struct cmd_syndesc *as; {
1005 register struct rx_connection *tconn;
1006 register afs_int32 code;
1008 register struct cmd_item *ti;
1010 char *type, *name, *notifier=NONOTIFIER;
1012 tconn = GetConn(as, 0);
1013 for(i=0;i<6;i++) parms[i] = "";
1014 for(i=0,ti=as->parms[3].items; (ti && i<6); ti=ti->next,i++) {
1015 parms[i] = ti->data;
1017 name = as->parms[1].items->data;
1018 type = as->parms[2].items->data;
1019 if (ti = as->parms[4].items) {
1020 notifier = ti->data;
1022 code = BOZO_CreateBnode(tconn, type, name, parms[0], parms[1], parms[2],
1023 parms[3], parms[4], notifier);
1025 printf("bos: failed to create new server instance %s of type '%s' (%s)\n",
1026 name, type, em(code));
1031 static DeleteServer(as)
1032 register struct cmd_syndesc *as; {
1033 register struct rx_connection *tconn;
1034 register afs_int32 code;
1035 register struct cmd_item *ti;
1038 tconn = GetConn(as, 0);
1039 for(ti=as->parms[1].items; ti; ti=ti->next) {
1040 code = BOZO_DeleteBnode(tconn, ti->data);
1043 printf("bos: can't delete running instance '%s'\n", ti->data);
1045 printf("bos: failed to delete instance '%s' (%s)\n",
1046 ti->data, em(code));
1052 static StartServer(as)
1053 register struct cmd_syndesc *as; {
1054 register struct rx_connection *tconn;
1055 register afs_int32 code;
1056 register struct cmd_item *ti;
1059 tconn = GetConn(as, 0);
1060 for(ti=as->parms[1].items; ti; ti=ti->next) {
1061 code = BOZO_SetStatus(tconn, ti->data, BSTAT_NORMAL);
1063 printf("bos: failed to start instance '%s' (%s)\n",
1064 ti->data, em(code));
1069 static StopServer(as)
1070 register struct cmd_syndesc *as; {
1071 register struct rx_connection *tconn;
1072 register afs_int32 code;
1073 register struct cmd_item *ti;
1076 tconn = GetConn(as, 0);
1077 for(ti=as->parms[1].items; ti; ti=ti->next) {
1078 code = BOZO_SetStatus(tconn, ti->data, BSTAT_SHUTDOWN);
1080 printf("bos: failed to change stop instance '%s' (%s)\n",
1081 ti->data, em(code));
1083 if (as->parms[8].items) {
1084 code = BOZO_WaitAll(tconn);
1086 printf("bos: can't wait for processes to shutdown (%s)\n",
1092 #define PARMBUFFERSSIZE 32
1094 static DoSalvage(aconn, aparm1, aparm2, aoutName, showlog,parallel,atmpDir,orphans)
1095 struct rx_connection *aconn;
1104 register afs_int32 code;
1107 char tbuffer[BOZO_BSSIZE];
1108 struct bozo_status istatus;
1109 struct rx_call *tcall;
1113 char partName[20]; /* canonical name for partition */
1114 char pbuffer[PARMBUFFERSSIZE];
1115 afs_int32 partNumber;
1116 char *notifier = NONOTIFIER;
1118 /* if a partition was specified, canonicalize the name, since
1119 the salvager has a stupid partition ID parser */
1121 partNumber = volutil_GetPartitionID(aparm1);
1122 if (partNumber < 0) {
1123 printf("bos: could not parse partition ID '%s'\n", aparm1);
1126 tp = volutil_PartitionName(partNumber);
1128 printf("bos: internal error parsing partition ID '%s'\n", aparm1);
1131 strcpy(partName, tp);
1133 else partName[0] = 0;
1135 /* open the file name */
1137 outFile = fopen(aoutName, "w");
1139 printf("bos: can't open specified SalvageLog file '%s'\n",
1143 closeIt = 1; /* close this file later */
1147 closeIt = 0; /* don't close this file later */
1150 for(code=2;code<6;code++) parms[code] = "";
1151 if (!aparm2) aparm2 = "";
1152 /* MUST pass canonical (wire-format) salvager path to bosserver */
1153 strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH, BOZO_BSSIZE);
1155 if ( (strlen(tbuffer) + 1 + strlen(partName) + 1 + strlen(aparm2) + 1) > BOZO_BSSIZE ) {
1156 printf("bos: command line too big\n");
1159 strcat(tbuffer, " ");
1160 strcat(tbuffer, partName);
1161 strcat(tbuffer, " ");
1162 strcat(tbuffer, aparm2);
1164 if ( (strlen(tbuffer) + 4 + strlen(partName) + 1) > BOZO_BSSIZE ) {
1165 printf("bos: command line too big\n");
1168 strcat (tbuffer, " -f ");
1169 strcat (tbuffer, partName);
1172 /* add the parallel option if given */
1173 if (parallel != (char *)0) {
1174 if ( (strlen(tbuffer) + 11 + strlen(parallel) + 1) > BOZO_BSSIZE ) {
1175 printf("bos: command line too big\n");
1178 strcat(tbuffer, " -parallel ");
1179 strcat(tbuffer, parallel);
1182 /* add the tmpdir option if given */
1183 if (atmpDir != (char *)0) {
1184 if ( (strlen(tbuffer) + 9 + strlen(atmpDir) + 1) > BOZO_BSSIZE ) {
1185 printf("bos: command line too big\n");
1188 strcat(tbuffer, " -tmpdir ");
1189 strcat(tbuffer, atmpDir);
1192 /* add the orphans option if given */
1193 if (orphans != (char *)0) {
1194 if ( (strlen(tbuffer) + 10 + strlen(orphans) + 1) > BOZO_BSSIZE ) {
1195 printf("bos: command line too big\n");
1198 strcat(tbuffer, " -orphans ");
1199 strcat(tbuffer, orphans);
1202 if (mrafsParm.Optdebug)
1203 strcat(tbuffer," -debug");
1204 if (mrafsParm.Optnowrite)
1205 strcat(tbuffer," -nowrite");
1206 if (mrafsParm.Optforce)
1207 strcat(tbuffer," -force");
1208 if (mrafsParm.Optoktozap)
1209 strcat(tbuffer," -oktozap");
1210 if (mrafsParm.Optrootfiles)
1211 strcat(tbuffer," -rootfiles");
1212 if (mrafsParm.Optsalvagedirs)
1213 strcat(tbuffer," -salvagedirs");
1214 if (mrafsParm.Optblockreads)
1215 strcat(tbuffer," -blockreads");
1216 if (mrafsParm.OptListResidencies)
1217 strcat(tbuffer," -ListResidencies");
1218 if (mrafsParm.OptSalvageRemote)
1219 strcat(tbuffer," -SalvageRemote");
1220 if (mrafsParm.OptSalvageArchival)
1221 strcat(tbuffer," -SalvageArchival");
1222 if (mrafsParm.OptIgnoreCheck)
1223 strcat(tbuffer," -IgnoreCheck");
1224 if (mrafsParm.OptForceOnLine)
1225 strcat(tbuffer," -ForceOnLine");
1226 if (mrafsParm.OptUseRootDirACL)
1227 strcat(tbuffer," -UseRootDirACL");
1228 if (mrafsParm.OptTraceBadLinkCounts)
1229 strcat(tbuffer," -TraceBadLinkCounts");
1230 if (mrafsParm.OptDontAskFS)
1231 strcat(tbuffer," -DontAskFS");
1232 if (mrafsParm.OptLogLevel) {
1233 sprintf(pbuffer, " -LogLevel %ld", mrafsParm.OptLogLevel);
1234 strcat(tbuffer, pbuffer);
1236 if (mrafsParm.OptRxDebug)
1237 strcat(tbuffer," -rxdebug");
1238 if (mrafsParm.OptResidencies) {
1239 sprintf(pbuffer, " -Residencies %lu", mrafsParm.OptResidencies);
1240 strcat(tbuffer, pbuffer);
1244 parms[1] = "now"; /* when to do it */
1245 code = BOZO_CreateBnode(aconn, "cron", "salvage-tmp", parms[0], parms[1],
1246 parms[2], parms[3], parms[4], notifier);
1247 if (code) goto done;
1248 /* now wait for bnode to disappear */
1252 code = BOZO_GetInstanceInfo(aconn, "salvage-tmp", &tp, &istatus);
1254 printf("bos: waiting for salvage to complete.\n");
1256 if (code != BZNOENT) {
1257 printf("bos: salvage failed (%s)\n", em(code));
1262 /* now print the log file to the output file */
1263 printf("bos: salvage completed\n");
1264 if (aoutName || showlog) {
1265 fprintf(outFile, "SalvageLog:\n");
1266 tcall = rx_NewCall(aconn);
1267 /* MUST pass canonical (wire-format) salvager log path to bosserver */
1268 code = StartBOZO_GetLog(tcall, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH);
1270 rx_EndCall(tcall, code);
1275 code = rx_Read(tcall, &buffer, 1);
1276 if (code != 1) break;
1277 putc(buffer, outFile);
1278 if (buffer == 0) break; /* the end delimeter */
1280 code = rx_EndCall(tcall, 0);
1281 /* fall through into cleanup code */
1285 if (closeIt && outFile) fclose(outFile);
1289 static GetLogCmd(as)
1290 register struct cmd_syndesc *as; {
1291 struct rx_connection *tconn;
1292 register struct rx_call *tcall;
1293 register afs_int32 code;
1297 printf("Fetching log file '%s'...\n", as->parms[1].items->data);
1298 tconn = GetConn(as, 0);
1299 tcall = rx_NewCall(tconn);
1300 code = StartBOZO_GetLog(tcall, as->parms[1].items->data);
1302 rx_EndCall(tcall, code);
1308 code = rx_Read(tcall, &buffer, 1);
1313 if (buffer == 0) break; /* the end delimeter */
1316 code = rx_EndCall(tcall, error);
1317 /* fall through into cleanup code */
1321 com_err("bos", code, "(while reading log)");
1325 static SalvageCmd(as)
1326 struct cmd_syndesc *as; {
1327 register struct rx_connection *tconn;
1328 register afs_int32 code, rc, i;
1330 char tname[BOZO_BSSIZE];
1332 extern struct ubik_client *cstruct;
1333 afs_int32 curGoal, showlog = 0, mrafs = 0;
1339 bzero(&mrafsParm, sizeof(mrafsParm));
1341 /* parm 0 is machine name, 1 is partition, 2 is volume, 3 is -all flag */
1342 tconn = GetConn(as, 0);
1344 /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
1345 /* XXX this should really be done some other way, potentially by RPC */
1347 if (code = BOZO_GetInstanceParm(tconn, "fs", 3, &tp) == 0)
1350 /* we can do a volume, a partition or the whole thing, but not mixtures
1352 if (!as->parms[1].items && as->parms[2].items) {
1353 printf("bos: must specify partition to salvage individual volume.\n");
1356 if (as->parms[5].items && as->parms[3].items) {
1357 printf("bos: can not specify both -file and -showlog.\n");
1360 if (as->parms[4].items && (as->parms[1].items || as->parms[2].items)) {
1361 printf("bos: can not specify -all with other flags.\n");
1365 /* get the output file name, if any */
1366 if (as->parms[3].items)
1367 outName = as->parms[3].items->data;
1369 outName = (char *) 0;
1371 if (as->parms[5].items)
1374 /* parallel option */
1375 parallel = (char *) 0;
1376 if (as->parms[6].items)
1377 parallel = as->parms[6].items->data;
1379 /* get the tmpdir filename if any */
1381 if (as->parms[7].items)
1382 tmpDir = as->parms[7].items->data;
1384 /* -orphans option */
1385 orphans = (char *)0;
1386 if (as->parms[8].items) {
1388 printf("Can't specify -orphans for MR-AFS fileserver\n");
1391 orphans = as->parms[8].items->data;
1395 if (as->parms[MRAFS_OFFSET].items)
1396 mrafsParm.Optdebug = 1;
1397 if (as->parms[MRAFS_OFFSET + 1].items)
1398 mrafsParm.Optnowrite = 1;
1399 if (as->parms[MRAFS_OFFSET + 2].items)
1400 mrafsParm.Optforce = 1;
1401 if (as->parms[MRAFS_OFFSET + 3].items)
1402 mrafsParm.Optoktozap = 1;
1403 if (as->parms[MRAFS_OFFSET + 4].items)
1404 mrafsParm.Optrootfiles = 1;
1405 if (as->parms[MRAFS_OFFSET + 5].items)
1406 mrafsParm.Optsalvagedirs = 1;
1407 if (as->parms[MRAFS_OFFSET + 6].items)
1408 mrafsParm.Optblockreads = 1;
1409 if (as->parms[MRAFS_OFFSET + 7].items)
1410 mrafsParm.OptListResidencies = 1;
1411 if (as->parms[MRAFS_OFFSET + 8].items)
1412 mrafsParm.OptSalvageRemote = 1;
1413 if (as->parms[MRAFS_OFFSET + 9].items)
1414 mrafsParm.OptSalvageArchival = 1;
1415 if (as->parms[MRAFS_OFFSET + 10].items)
1416 mrafsParm.OptIgnoreCheck = 1;
1417 if (as->parms[MRAFS_OFFSET + 11].items)
1418 mrafsParm.OptForceOnLine = 1;
1419 if (as->parms[MRAFS_OFFSET + 12].items)
1420 mrafsParm.OptUseRootDirACL = 1;
1421 if (as->parms[MRAFS_OFFSET + 13].items)
1422 mrafsParm.OptTraceBadLinkCounts = 1;
1423 if (as->parms[MRAFS_OFFSET + 14].items)
1424 mrafsParm.OptDontAskFS = 1;
1425 if (as->parms[MRAFS_OFFSET + 15].items)
1426 mrafsParm.OptLogLevel = atoi(as->parms[MRAFS_OFFSET + 15].items->dta);
1427 if (as->parms[MRAFS_OFFSET + 16].items)
1428 mrafsParm.OptRxDebug = 1;
1429 if (as->parms[MRAFS_OFFSET + 17].items) {
1430 if (as->parms[MRAFS_OFFSET + 8].items ||
1431 as->parms[MRAFS_OFFSET + 9].items) {
1432 printf("Can't specify -Residencies with -SalvageRemote or -SalvageArchival\n");
1435 code = GetUInt32(as->parms[MRAFS_OFFSET + 17].items->data,
1436 &mrafsParm.OptResidencies);
1438 printf("bos: '%s' is not a valid residency mask.\n",
1439 as->parms[MRAFS_OFFSET + 13].items->data);
1446 for (i = 9; i < ADDPARMOFFSET; i++) {
1447 if (as->parms[i].items) {
1448 printf(" %s only possible for MR-AFS fileserver.\n",
1456 if (as->parms[4].items) {
1457 /* salvage whole enchilada */
1458 curGoal = GetServerGoal(tconn, "fs");
1459 if (curGoal == BSTAT_NORMAL) {
1460 printf("bos: shutting down fs.\n");
1461 code = BOZO_SetTStatus(tconn, "fs", BSTAT_SHUTDOWN);
1463 printf("bos: failed to stop 'fs' (%s)\n", em(code));
1466 code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1468 printf("bos: failed to wait for file server shutdown, continuing.\n");
1470 /* now do the salvage operation */
1471 printf("Starting salvage.\n");
1472 rc = DoSalvage(tconn, (char *) 0, (char *) 0, outName, showlog,parallel,tmpDir,orphans);
1473 if (rc) printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1474 if (curGoal == BSTAT_NORMAL) {
1475 printf("bos: restarting fs.\n");
1476 code = BOZO_SetTStatus(tconn, "fs", BSTAT_NORMAL);
1478 printf("bos: failed to restart 'fs' (%s)\n", em(code));
1484 else if (!as->parms[2].items) {
1485 if (!as->parms[1].items) {
1486 printf("bos: must specify -all switch to salvage all partitions.\n");
1489 if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1490 /* can't parse volume ID, so complain before shutting down
1493 printf("bos: can't interpret %s as partition ID.\n",
1494 as->parms[1].items->data);
1497 curGoal = GetServerGoal(tconn, "fs");
1498 /* salvage a whole partition (specified by parms[1]) */
1499 if (curGoal == BSTAT_NORMAL) {
1500 printf("bos: shutting down fs.\n");
1501 code = BOZO_SetTStatus(tconn, "fs", BSTAT_SHUTDOWN);
1503 printf("bos: can't stop 'fs' (%s)\n", em(code));
1506 code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1508 printf("bos: failed to wait for file server shutdown, continuing.\n");
1510 /* now do the salvage operation */
1511 printf("Starting salvage.\n");
1512 rc = DoSalvage(tconn, as->parms[1].items->data, (char *) 0,
1513 outName, showlog,parallel,tmpDir,orphans);
1514 if (rc) printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1515 if (curGoal == BSTAT_NORMAL) {
1516 printf("bos: restarting fs.\n");
1517 code = BOZO_SetTStatus(tconn, "fs", BSTAT_NORMAL);
1519 printf("bos: failed to restart 'fs' (%s)\n", em(code));
1526 /* salvage individual volume (don't shutdown fs first), just use
1527 * single-shot cron bnode. Must leave server running when using this
1528 * option, since salvager will ask file server for the volume */
1531 const char *confdir;
1534 if (as->parms[ADDPARMOFFSET].items)
1535 tmpname = as->parms[ADDPARMOFFSET].items->data;
1536 else tmpname = (char *) 0;
1538 localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
1539 confdir = (localauth ? AFSDIR_SERVER_ETC_DIRPATH : AFSDIR_CLIENT_ETC_DIRPATH);
1540 code = vsu_ClientInit(/* noauth */ 1, confdir, tmpname,
1541 /* server auth */ 0, &cstruct, (int (*)()) 0);
1543 newID = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1545 printf("bos: can't interpret %s as volume name or ID\n", as->parms[2].items->data);
1548 sprintf(tname, "%u", newID);
1551 printf("bos: can't initialize volume system client (code %d), trying anyway.\n",
1552 as->parms[2].items->data, code);
1553 strncpy(tname, as->parms[2].items->data, sizeof(tname));
1555 if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1556 /* can't parse volume ID, so complain before shutting down
1559 printf("bos: can't interpret %s as partition ID.\n",
1560 as->parms[1].items->data);
1563 printf("Starting salvage.\n");
1564 rc = DoSalvage(tconn, as->parms[1].items->data, tname, outName,
1565 showlog,parallel,tmpDir,orphans);
1567 printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1574 static IStatServer(as, int32p)
1576 register struct cmd_syndesc *as; {
1577 register struct rx_connection *tconn;
1578 register struct cmd_item *ti;
1581 tconn = GetConn(as, 0);
1582 for (ti=as->parms[1].items; ti; ti=ti->next) {
1583 DoStat(ti->data, tconn, int32p, firstTime);
1589 static DoStat (aname, aconn, aint32p, firstTime)
1591 IN register struct rx_connection *aconn;
1593 IN int firstTime; /* true iff first instance in cmd */
1597 register afs_int32 code;
1598 register afs_int32 i;
1599 struct bozo_status istatus;
1601 char *is1, *is2, *is3, *is4; /* instance strings */
1604 code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
1606 printf("bos: failed to get instance info for '%s' (%s)\n",
1610 if (firstTime && aint32p && (istatus.flags & BOZO_BADDIRACCESS))
1611 printf ("Bosserver reports inappropriate access on server directories\n");
1612 printf("Instance %s, ", aname);
1613 if (aint32p) printf("(type is %s) ", buffer);
1614 if (istatus.fileGoal == istatus.goal) {
1615 if (!istatus.goal) printf("disabled, ");
1618 if (istatus.fileGoal) printf("temporarily disabled, ");
1619 else printf("temporarily enabled, ");
1622 if (istatus.flags & BOZO_ERRORSTOP)
1623 printf("stopped for too many errors, ");
1624 if (istatus.flags & BOZO_HASCORE)
1625 printf("has core file, ");
1628 code = BOZO_GetStatus(aconn, aname, &temp, &tp);
1630 printf("bos: failed to get status for instance '%s' (%s)\n",
1633 printf("currently ", aname);
1634 if (temp == BSTAT_NORMAL) printf("running normally.\n");
1635 else if (temp == BSTAT_SHUTDOWN) printf("shutdown.\n");
1636 else if (temp == BSTAT_STARTINGUP) printf("starting up.\n");
1637 else if (temp == BSTAT_SHUTTINGDOWN) printf("shutting down.\n");
1638 if (buffer[0] != 0) {
1639 printf(" Auxiliary status is: %s.\n", buffer);
1643 /* are we done yet? */
1644 if (!aint32p) return 0;
1646 if (istatus.procStartTime)
1647 printf(" Process last started at %s (%d proc starts)\n",
1648 DateOf(istatus.procStartTime), istatus.procStarts);
1649 if (istatus.lastAnyExit) {
1650 printf(" Last exit at %s\n", DateOf(istatus.lastAnyExit));
1652 if (istatus.lastErrorExit) {
1653 is1 = is2 = is3 = is4 = (char *) 0;
1654 printf(" Last error exit at %s, ", DateOf(istatus.lastErrorExit));
1655 code = BOZO_GetInstanceStrings(aconn, aname, &is1, &is2, &is3, &is4);
1656 /* don't complain about failing call, since could simply mean
1657 * interface mismatch.
1661 /* non-null instance string */
1662 printf("by %s, ", is1);
1669 if (istatus.errorSignal) {
1670 if (istatus.errorSignal == SIGTERM)
1671 printf("due to shutdown request\n");
1673 printf("due to signal %d\n", istatus.errorSignal);
1676 printf("by exiting with code %d\n", istatus.errorCode);
1680 /* try to display all the parms */
1683 code = BOZO_GetInstanceParm(aconn, aname, i, &tp);
1685 printf(" Command %d is '%s'\n", i+1, buffer);
1688 code = BOZO_GetInstanceParm(aconn, aname, 999, &tp);
1690 /* Any type of failure is treated as not having a notifier program */
1691 printf(" Notifier is '%s'\n", buffer);
1698 #ifdef BOS_RESTRICTED_MODE
1699 static GetRestrict(as)
1700 struct cmd_syndesc *as; {
1701 register struct rx_connection *tconn;
1702 afs_int32 code, val;
1704 tconn = GetConn(as, 0);
1705 code = BOZO_GetRestrictedMode(tconn, &val);
1706 if (code) printf("bos: failed to get restricted mode (%s)\n", em(code));
1707 else printf("Restricted mode is %s\n", val ? "on" : "off");
1712 static SetRestrict(as)
1713 struct cmd_syndesc *as; {
1714 register struct rx_connection *tconn;
1715 afs_int32 code, val;
1717 tconn = GetConn(as, 0);
1718 util_GetInt32(as->parms[1].items->data, &val);
1719 code = BOZO_SetRestrictedMode(tconn, val);
1720 if (code) printf("bos: failed to set restricted mode (%s)\n", em(code));
1725 static void add_std_args (ts)
1726 register struct cmd_syndesc *ts;
1728 cmd_Seek(ts, ADDPARMOFFSET);
1729 /* + 0 */ cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1730 /* + 1 */ cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1731 "don't authenticate");
1732 /* + 2 */ cmd_AddParm (ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1733 "create tickets from KeyFile");
1736 #include "AFS_component_version_number.c"
1742 register afs_int32 code;
1743 register struct cmd_syndesc *ts;
1744 extern int afsconf_SawCell;
1746 #ifdef AFS_AIX32_ENV
1748 * The following signal action for AIX is necessary so that in case of a
1749 * crash (i.e. core is generated) we can include the user's data section
1750 * in the core dump. Unfortunately, by default, only a partial core is
1751 * generated which, in many cases, isn't too useful.
1753 struct sigaction nsa;
1755 sigemptyset(&nsa.sa_mask);
1756 nsa.sa_handler = SIG_DFL;
1757 nsa.sa_flags = SA_FULLDUMP;
1758 sigaction(SIGSEGV, &nsa, NULL);
1759 sigaction(SIGABRT, &nsa, NULL);
1765 printf("bos: could not initialize rx (%s)\n", em(code));
1769 /* To resolve a AFSCELL environment "Note: ..." problem: Because bos calls ka_Init (why?) before any
1770 * checkup on the existance of a "-cell" option on the particular bos command we don't print the
1771 * message if a cell is passed in. Luckily the rest of the programs don't call these adhoc routines
1772 * and things work fine. Note that if the "-cell" isn't passed then we're still ok since later on
1773 * the proper routine (afsconf_GetCellInfo) is going to be called to do the right thing.
1775 afsconf_SawCell = 1; /* Means don't print warning if AFSCELL is set */
1777 afsconf_SawCell = 0; /* Reset it */
1778 /* don't check error code, since fails sometimes when we're setting up a
1780 initialize_cmd_error_table();
1781 initialize_bz_error_table();
1783 ts = cmd_CreateSyntax("start", StartServer, 0, "start running a server");
1784 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1785 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1788 ts = cmd_CreateSyntax("stop", StopServer, 0, "halt a server instance");
1789 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1790 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1792 cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1793 "wait for process to stop");
1796 ts = cmd_CreateSyntax("status", StatServer, 0,
1797 "show server instance status");
1798 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1799 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL,
1800 "server process name");
1801 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "long status");
1804 ts = cmd_CreateSyntax("shutdown", Shutdown, 0, "shutdown all processes");
1805 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1806 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1808 cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1809 "wait for process to stop");
1812 ts = cmd_CreateSyntax("startup", Startup, 0, "start all processes");
1813 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1814 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1817 ts = cmd_CreateSyntax("restart", Restart, 0, "restart all processes");
1818 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1819 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1820 cmd_AddParm(ts, "-bosserver", CMD_FLAG, CMD_OPTIONAL, "restart bosserver");
1821 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "restart all processes");
1826 ts = cmd_CreateSyntax("create", CreateServer, 0,
1827 "create a new server instance");
1828 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1829 cmd_AddParm(ts, "-instance", CMD_SINGLE, 0, "server process name");
1830 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "server type");
1831 cmd_AddParm(ts, "-cmd", CMD_LIST, 0, "command lines");
1832 cmd_AddParm(ts, "-notifier", CMD_SINGLE, CMD_OPTIONAL, "Notifier program");
1835 ts = cmd_CreateSyntax("delete", DeleteServer, 0,
1836 "delete a server instance");
1837 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1838 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1841 ts = cmd_CreateSyntax("adduser", AddSUser, 0,
1842 "add users to super-user list");
1843 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1844 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
1847 ts = cmd_CreateSyntax("removeuser", RemoveSUser, 0,
1848 "remove users from super-user list");
1849 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1850 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
1853 ts = cmd_CreateSyntax("listusers", ListSUsers, 0, "list super-users");
1854 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1857 ts = cmd_CreateSyntax("addkey", AddKey, 0,
1858 "add keys to key dbase (kvno 999 is bcrypt)");
1859 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1860 cmd_AddParm(ts, "-key", CMD_SINGLE, CMD_OPTIONAL, "key");
1861 cmd_AddParm(ts, "-kvno", CMD_SINGLE, 0, "key version number");
1864 ts = cmd_CreateSyntax("removekey", RemoveKey, 0,
1865 "remove keys from key dbase");
1866 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1867 cmd_AddParm(ts, "-kvno", CMD_LIST, 0, "key version number");
1870 ts = cmd_CreateSyntax("listkeys", ListKeys, 0, "list keys");
1871 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1872 cmd_AddParm(ts, "-showkey", CMD_FLAG, CMD_OPTIONAL, "show the actual key rather than the checksum");
1875 ts = cmd_CreateSyntax("listhosts", ListHosts, 0, "get cell host list");
1876 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1878 cmd_CreateAlias(ts, "getcell");
1880 ts = cmd_CreateSyntax("setcellname", SetCellName, 0, "set cell name");
1881 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1882 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
1885 ts = cmd_CreateSyntax("addhost", AddHost, 0, "add host to cell dbase");
1886 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1887 cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
1890 ts = cmd_CreateSyntax("removehost", RemoveHost, 0,
1891 "remove host from cell dbase");
1892 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1893 cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
1896 ts = cmd_CreateSyntax("setauth", SetAuth, 0,
1897 "set authentication required flag");
1898 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1899 cmd_AddParm(ts, "-authrequired", CMD_SINGLE,
1900 0, "on or off: authentication required for admin requests");
1903 ts = cmd_CreateSyntax("install", Install, 0, "install program");
1904 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1905 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to install");
1906 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1909 ts = cmd_CreateSyntax("uninstall", UnInstall, 0, "uninstall program");
1910 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1911 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to uninstall");
1912 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1915 ts = cmd_CreateSyntax("getlog", GetLogCmd, 0, "examine log file");
1916 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1917 cmd_AddParm(ts, "-file", CMD_SINGLE, 0, "log file to examine");
1920 ts = cmd_CreateSyntax("getdate", GetDate, 0, "get dates for programs");
1921 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1922 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to check");
1923 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1926 ts = cmd_CreateSyntax("exec", Exec, 0, "execute shell command on server");
1927 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1928 cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "command to execute");
1931 ts = cmd_CreateSyntax("prune", Prune, 0, "prune server files");
1932 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1933 cmd_AddParm(ts, "-bak", CMD_FLAG, CMD_OPTIONAL, "delete .BAK files");
1934 cmd_AddParm(ts, "-old", CMD_FLAG, CMD_OPTIONAL, "delete .OLD files");
1935 cmd_AddParm(ts, "-core", CMD_FLAG, CMD_OPTIONAL, "delete core files");
1936 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "delete all junk files");
1939 ts = cmd_CreateSyntax("setrestart", SetRestartCmd, 0, "set restart times");
1940 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
1941 cmd_AddParm(ts, "-time", CMD_SINGLE,
1942 CMD_REQUIRED, "time to restart server");
1943 cmd_AddParm(ts, "-general", CMD_FLAG,
1944 CMD_OPTIONAL, "set general restart time");
1945 cmd_AddParm(ts, "-newbinary", CMD_FLAG,
1946 CMD_OPTIONAL, "set new binary restart time");
1949 ts = cmd_CreateSyntax("getrestart", GetRestartCmd, 0, "get restart times");
1950 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
1953 ts = cmd_CreateSyntax("salvage", SalvageCmd, 0,
1954 "salvage partition or volumes");
1955 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1956 cmd_AddParm(ts, "-partition", CMD_SINGLE,
1957 CMD_OPTIONAL, "salvage partition");
1958 cmd_AddParm(ts, "-volume", CMD_SINGLE,
1959 CMD_OPTIONAL, "salvage volume number or volume name");
1960 cmd_AddParm(ts, "-file", CMD_SINGLE,
1961 CMD_OPTIONAL, "salvage log output file");
1962 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "salvage whole server");
1963 cmd_AddParm(ts, "-showlog", CMD_FLAG, CMD_OPTIONAL, "display salvage log");
1964 cmd_AddParm(ts, "-parallel",CMD_SINGLE, CMD_OPTIONAL,
1965 "# of max parallel partition salvaging");
1966 cmd_AddParm(ts, "-tmpdir",CMD_SINGLE, CMD_OPTIONAL,
1967 "directory to place tmp files");
1968 cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL,
1969 "ignore | remove | attach");
1970 cmd_AddParm(ts, "-debug", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Run in Debugging mode");
1971 cmd_AddParm(ts, "-nowrite", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Run readonly/test mode");
1972 cmd_AddParm(ts, "-force", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force full salvaging");
1973 cmd_AddParm(ts, "-oktozap", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Give permission to destroy bogus file residencies/volumes - debugging flag");
1974 cmd_AddParm(ts, "-rootfiles", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Show files owned by root - debugging flag");
1975 cmd_AddParm(ts, "-salvagedirs", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force rebuild/salvage of all directories");
1976 cmd_AddParm(ts, "-blockreads", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Read smaller blocks to handle IO/bad blocks");
1977 cmd_AddParm(ts, "-ListResidencies", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Just list affected file residencies - debugging flag");
1978 cmd_AddParm(ts, "-SalvageRemote", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Salvage storage systems that are not directly attached");
1979 cmd_AddParm(ts, "-SalvageArchival", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Salvage HSM storage systems");
1980 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.");
1981 cmd_AddParm(ts, "-ForceOnLine", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force the volume to come online, even if it hasn't salvaged cleanly.");
1982 cmd_AddParm(ts, "-UseRootDirACL", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Use the root directory ACL for lost+found directory if it is created.");
1983 cmd_AddParm(ts, "-TraceBadLinkCounts", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Print out lines about volume reference count changes.");
1984 cmd_AddParm(ts, "-DontAskFS", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Don't ask fileserver to take volume offline. THIS IS VERY DANGEROUS.");
1985 cmd_AddParm(ts, "-LogLevel", CMD_SINGLE, CMD_OPTIONAL, "(MR-AFS) log level");
1986 cmd_AddParm(ts, "-rxdebug", CMD_FLAG, CMD_OPTIONAL, "(MR-AFS) Write out rx debug information.");
1987 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");
1990 ts = cmd_CreateSyntax("blockscanner", BlockScannerCmd, 0,
1991 "block scanner daemon from making migration requests");
1992 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
1995 ts = cmd_CreateSyntax("unblockscanner", UnBlockScannerCmd, 0,
1996 "allow scanner daemon to make migration requests again");
1997 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2000 #ifdef BOS_RESTRICTED_MODE
2001 ts = cmd_CreateSyntax("getrestricted", GetRestrict, 0, "get restrict mode");
2002 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2005 ts = cmd_CreateSyntax("setrestricted", SetRestrict, 0, "set restrict mode");
2006 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2007 cmd_AddParm(ts, "-mode", CMD_SINGLE, 0, "mode to set");
2012 code = cmd_Dispatch(argc, argv);