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();
57 #define MRAFS_OFFSET 9
58 #define ADDPARMOFFSET 26
60 static struct SalvageParms {
65 afs_int32 Optrootfiles;
66 afs_int32 Optsalvagedirs;
67 afs_int32 Optblockreads;
68 afs_int32 OptListResidencies;
69 afs_int32 OptSalvageRemote;
70 afs_int32 OptSalvageArchival;
71 afs_int32 OptIgnoreCheck;
72 afs_int32 OptForceOnLine;
73 afs_int32 OptUseRootDirACL;
74 afs_int32 OptTraceBadLinkCounts;
75 afs_int32 OptDontAskFS;
76 afs_int32 OptLogLevel;
78 afs_uint32 OptResidencies;
81 /* dummy routine for the audit work. It should do nothing since audits */
82 /* occur at the server level and bos is not a server. */
83 osi_audit() {return 0;}
85 /* keep those lines small */
86 static char *em(acode)
89 return "communications failure (-1)";
91 return "communications timeout (-3)";
92 else return (char *) error_message(acode);
95 /* get partition id from a name */
96 static afs_int32 GetPartitionID(aname)
102 if (tc == 0) return -1; /* unknown */
103 /* numbers go straight through */
104 if (tc >= '0' && tc <= '9') {
107 /* otherwise check for vicepa or /vicepa, or just plain "a" */
109 if (strlen(aname) <= 2) {
110 strcpy(ascii, aname);
112 else if (!strncmp(aname, "/vicep", 6)) {
113 strncpy(ascii, aname+6, 2);
115 else if (!strncmp(aname, "vicep", 5)) {
116 strncpy(ascii, aname+5, 2);
118 else return -1; /* bad partition name */
119 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab,
120 * .../vicepzz, and are numbered from 0. Do the appropriate conversion */
122 /* one char name, 0..25 */
123 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
124 return ascii[0] - 'a';
127 /* two char name, 26 .. <whatever> */
128 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
129 if (ascii[1] < 'a' || ascii[1] > 'z') return -1; /* just as bad */
130 return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
134 /* make ctime easier to use */
135 static char *DateOf(atime)
137 static char tbuffer[30];
139 tp=ctime((time_t *)&atime);
142 tbuffer[24] = 0; /* get rid of new line */
145 strcpy(tbuffer, "BAD TIME");
149 /* global stuff from main for communicating with GetConn */
150 static struct rx_securityClass *sc[3];
153 /* use the syntax descr to get a connection, authenticated appropriately.
154 * aencrypt is set if we want to encrypt the data on the wire.
156 static struct rx_connection *GetConn(as, aencrypt)
158 struct cmd_syndesc *as; {
161 register afs_int32 code;
162 register struct rx_connection *tconn;
164 register struct afsconf_dir *tdir;
166 struct ktc_principal sname;
167 struct ktc_token ttoken;
171 hostname = as->parms[0].items->data;
172 th = hostutil_GetHostByName(hostname);
174 printf("bos: can't find address for host '%s'\n", hostname);
177 bcopy(th->h_addr, &addr, sizeof(afs_int32));
179 /* get tokens for making authenticated connections */
180 localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
181 confdir = (localauth ? AFSDIR_SERVER_ETC_DIRPATH : AFSDIR_CLIENT_ETC_DIRPATH);
182 tdir = afsconf_Open (confdir);
184 struct afsconf_cell info;
187 if (as->parms[ADDPARMOFFSET].items)
188 tname = as->parms[ADDPARMOFFSET].items->data;
189 else tname = (char *) 0;
190 /* next call expands cell name abbrevs for us and handles looking up
192 code = afsconf_GetCellInfo(tdir, tname, (char *) 0, &info);
194 com_err ("bos", code, "(can't find cell '%s' in cell database)",
195 (tname? tname : "<default>"));
198 else strcpy(sname.cell, info.name);
201 printf("bos: can't open cell database (%s)\n", confdir);
204 sname.instance[0] = 0;
205 strcpy(sname.name, "afs");
206 sc[0] = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
211 if (!as->parms[ADDPARMOFFSET + 1].items) { /* not -noauth */
212 if (as->parms[ADDPARMOFFSET + 2].items) { /* -localauth */
213 code = afsconf_GetLatestKey (tdir, 0,0);
214 if (code) com_err ("bos", code, "(getting key from local KeyFile)");
217 code = afsconf_ClientAuthSecure (tdir, &sc[2], &scIndex);
219 code = afsconf_ClientAuth (tdir, &sc[2], &scIndex);
220 if (code) com_err ("bos", code, "(calling ClientAuth)");
221 else if (scIndex != 2) /* this shouldn't happen */
224 } else { /* not -localauth, check for tickets */
225 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), (char *)0);
227 /* have tickets, will travel */
228 if (ttoken.kvno >= 0 && ttoken.kvno <= 255) ;
231 "bos: funny kvno (%d) in ticket, proceeding\n",
235 if (aencrypt) encryptLevel = rxkad_crypt;
236 else encryptLevel = rxkad_clear;
237 sc[2] = (struct rx_securityClass *)
238 rxkad_NewClientSecurityObject
239 (encryptLevel, &ttoken.sessionKey,
240 ttoken.kvno, ttoken.ticketLen, ttoken.ticket);
242 } else com_err ("bos", code, "(getting tickets)");
244 if ((scIndex == 0) || (sc[scIndex] == 0)) {
245 fprintf (stderr, "bos: running unauthenticated\n");
249 tconn = rx_NewConnection (addr, htons(AFSCONF_NANNYPORT), 1,
250 sc[scIndex], scIndex);
252 fprintf (stderr, "bos: could not create rx connection\n");
255 rxs_Release (sc[scIndex]);
261 struct cmd_syndesc *as; {
262 register afs_int32 code;
263 register struct rx_connection *tconn;
267 tconn = GetConn(as, 0);
268 tp = as->parms[1].items->data;
269 if (strcmp(tp, "on")==0) flag = 0; /* auth req.: noauthflag is false */
270 else if (strcmp(tp, "off") == 0) flag = 1;
272 printf("bos: illegal authentication specifier '%s', must be 'off' or 'on'.\n", tp);
275 code = BOZO_SetNoAuthFlag(tconn, flag);
276 if (code) com_err ("bos", code, "(failed to set authentication flag)");
280 /* take a name (e.g. foo/bar, and a dir e.g. /usr/afs/bin, and construct
281 * /usr/afs/bin/bar */
282 static ComputeDestDir(aname, adir, aresult, alen)
283 char *aname, *adir, *aresult;
287 strcpy(aresult, adir);
288 tp = rindex(aname, '/');
291 strcat(aresult, "/");
292 strcat(aresult, aname);
295 /* tp points at the / character */
301 /* copy data from fd afd to rx call acall */
302 static CopyBytes(afd, acall)
304 register struct rx_call *acall; {
305 register afs_int32 code;
306 register afs_int32 len;
310 len = read(afd, tbuffer, sizeof(tbuffer));
311 if (len < 0) return errno;
312 if (len == 0) return 0; /* all done */
313 code = rx_Write(acall, tbuffer, len);
314 if (code != len) return -1;
319 register struct cmd_syndesc *as; {
320 register afs_int32 code;
321 register struct rx_connection *tconn;
322 register afs_int32 flags;
324 tconn = GetConn(as, 0);
326 if (as->parms[1].items) flags |= BOZO_PRUNEBAK;
327 if (as->parms[2].items) flags |= BOZO_PRUNEOLD;
328 if (as->parms[3].items) flags |= BOZO_PRUNECORE;
329 if (as->parms[4].items) flags |= 0xff;
330 code = BOZO_Prune(tconn, flags);
331 if (code) com_err ("bos", code, "(failed to prune server files)");
336 register struct cmd_syndesc *as; {
337 register struct rx_connection *tconn;
338 register afs_int32 code;
340 tconn = GetConn(as, 0);
341 code = BOZO_Exec(tconn, as->parms[1].items->data);
342 if (code) printf("bos: failed to execute command (%s)\n",
348 register struct cmd_syndesc *as; {
349 register afs_int32 code;
352 afs_int32 time, bakTime, oldTime;
353 register struct rx_connection *tconn;
354 register struct cmd_item *ti;
356 tconn = GetConn(as, 0);
357 if (!as->parms[1].items) {
358 printf("bos: no files to check\n");
362 /* compute dest dir or file; default MUST be canonical form of dir path */
363 if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
364 else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
366 for(ti=as->parms[1].items; ti; ti=ti->next) {
367 /* check date for each file */
368 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
369 code = BOZO_GetDates(tconn, tbuffer, &time, &bakTime, &oldTime);
371 printf("bos: failed to check date on %s (%s)\n", ti->data,
376 printf("File %s ", tbuffer);
377 if (time == 0) printf("does not exist, ");
378 else printf("dated %s, ", DateOf(time));
379 if (bakTime == 0) printf("no .BAK file, ");
380 else printf(".BAK file dated %s, ", DateOf(bakTime));
381 if (oldTime == 0) printf("no .OLD file.");
382 else printf(".OLD file dated %s.", DateOf(oldTime));
389 register struct cmd_syndesc *as; {
390 register afs_int32 code;
393 register struct cmd_item *ti;
394 register struct rx_connection *tconn;
396 tconn = GetConn(as, 0);
397 if (!as->parms[1].items) {
398 printf("bos: no files to uninstall\n");
402 /* compute dest dir or file; default MUST be canonical form of dir path */
403 if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
404 else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
406 for(ti=as->parms[1].items; ti; ti=ti->next) {
407 /* uninstall each file */
408 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
409 code = BOZO_UnInstall(tconn, tbuffer);
411 printf("bos: failed to uninstall %s (%s)\n", ti->data,
415 else printf("bos: uninstalled file %s\n", ti->data);
420 static afs_int32 GetServerGoal(aconn, aname)
422 struct rx_connection *aconn; {
425 register afs_int32 code;
426 struct bozo_status istatus;
429 code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
431 printf("bos: failed to get instance info for '%s' (%s)\n",
433 /* if we can't get the answer, assume its running */
436 if (istatus.goal == 0)
437 return BSTAT_SHUTDOWN;
443 struct cmd_syndesc *as; {
444 struct rx_connection *tconn;
445 register afs_int32 code;
446 register struct cmd_item *ti;
450 struct rx_call *tcall;
453 tconn = GetConn(as, 0);
454 if (!as->parms[1].items) {
455 printf("bos: no files to install\n");
459 /* compute dest dir or file; default MUST be canonical form of dir path */
460 if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
461 else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
463 for(ti=as->parms[1].items; ti; ti=ti->next) {
464 /* install each file */
465 fd = open(ti->data, O_RDONLY);
467 /* better to quit on error than continue for install command */
468 printf("bos: can't find file '%s', quitting\n", ti->data);
471 code = fstat(fd, &tstat);
473 printf("bos: failed to stat file %s, errno is %d\n", ti->data,
477 /* compute destination dir */
478 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
479 tcall = rx_NewCall(tconn);
480 code = StartBOZO_Install(tcall, tbuffer, tstat.st_size, (afs_int32)tstat.st_mode,
483 code = CopyBytes(fd, tcall);
485 code = rx_EndCall(tcall, code);
487 printf("bos: failed to install %s (%s)\n", ti->data, em(code));
490 else printf("bos: installed file %s\n", ti->data);
496 struct cmd_syndesc *as; {
497 register struct rx_connection *tconn;
498 register afs_int32 code;
499 register struct cmd_item *ti;
501 tconn = GetConn(as, 0);
502 if (as->parms[1].items == 0) {
503 code = BOZO_ShutdownAll(tconn);
504 if (code) printf("bos: failed to shutdown servers (%s)\n", em(code));
507 for(ti = as->parms[1].items; ti; ti=ti->next) {
508 code = BOZO_SetTStatus(tconn, ti->data, BSTAT_SHUTDOWN);
510 printf("bos: failed to shutdown instance %s (%s)\n",
514 if (as->parms[8].items) {
515 code = BOZO_WaitAll(tconn);
517 printf("bos: can't wait for processes to shutdown (%s)\n",
523 static BlockScannerCmd(as, arock)
524 struct cmd_syndesc *as;
526 register afs_int32 code;
527 struct rx_connection *tconn;
528 char BlockCommand[] = "/usr/afs/bin/scanner -block";
530 tconn = GetConn(as, 0);
531 code = BOZO_Exec(tconn, BlockCommand);
533 printf("bos: failed to block scanner from making migration requests (%s)\n",
538 static UnBlockScannerCmd(as, arock)
539 struct cmd_syndesc *as;
541 register afs_int32 code;
542 struct rx_connection *tconn;
543 char UnBlockCommand[] = "/usr/afs/bin/scanner -unblock";
545 tconn = GetConn(as, 0);
546 code = BOZO_Exec(tconn, UnBlockCommand);
548 printf("bos: failed to allow scanner daemon to make migration requests again (%s)\n",
553 static GetRestartCmd(as, arock)
554 struct cmd_syndesc *as;
556 register afs_int32 code;
557 struct ktime generalTime, newBinaryTime;
558 char messageBuffer[256];
559 struct rx_connection *tconn;
562 hostp = as->parms[0].items->data; /* host name for messages */
563 tconn = GetConn(as, 0);
565 code = BOZO_GetRestartTime(tconn, 1, &generalTime);
567 printf("bos: failed to retrieve restart information (%s)\n", em(code));
570 code = BOZO_GetRestartTime(tconn, 2, &newBinaryTime);
572 printf("bos: failed to retrieve restart information (%s)\n", em(code));
576 code = ktime_DisplayString(&generalTime, messageBuffer);
578 printf("bos: failed to decode restart time (%s)\n", em(code));
581 printf("Server %s restarts %s\n", hostp, messageBuffer);
583 code = ktime_DisplayString(&newBinaryTime, messageBuffer);
585 printf("bos: failed to decode restart time (%s)\n", em(code));
588 printf("Server %s restarts for new binaries %s\n", hostp, messageBuffer);
594 static SetRestartCmd(as, arock)
595 struct cmd_syndesc *as;
598 register afs_int32 code;
599 struct ktime restartTime;
601 struct rx_connection *tconn;
604 tconn = GetConn(as, 0);
605 if (as->parms[2].items) {count++; type = 1;}
606 if (as->parms[3].items) {count++; type = 2;}
608 printf("bos: can't specify more than one restart time at a time\n");
611 if (count == 0) type = 1; /* by default set general restart time */
613 if (code = ktime_ParsePeriodic(as->parms[1].items->data, &restartTime)) {
614 printf("bos: failed to parse '%s' as periodic restart time(%s)\n",
615 as->parms[1].items->data, em(code));
619 code = BOZO_SetRestartTime(tconn, type, &restartTime);
621 printf("bos: failed to set restart time at server (%s)\n", em(code));
628 struct cmd_syndesc *as; {
629 register struct rx_connection *tconn;
630 register afs_int32 code;
631 register struct cmd_item *ti;
633 tconn = GetConn(as, 0);
634 if (as->parms[1].items == 0) {
635 code = BOZO_StartupAll(tconn);
637 printf("bos: failed to startup servers (%s)\n", em(code));
640 for(ti = as->parms[1].items; ti; ti=ti->next) {
641 code = BOZO_SetTStatus(tconn, ti->data, BSTAT_NORMAL);
643 printf("bos: failed to start instance %s (%s)\n",
651 struct cmd_syndesc *as; {
652 register struct rx_connection *tconn;
653 register afs_int32 code;
654 register struct cmd_item *ti;
656 tconn = GetConn(as, 0);
657 if (as->parms[2].items) {
658 /* this is really a rebozo command */
659 if (as->parms[1].items) {
660 /* specified specific things to restart, can't do this at the same
662 printf("bos: can't specify both '-bos' and specific servers to restart.\n");
665 /* otherwise do a rebozo */
666 code = BOZO_ReBozo(tconn);
668 printf("bos: failed to restart bosserver (%s)\n", em(code));
671 if (as->parms[1].items == 0) {
672 if (as->parms[3].items) { /* '-all' */
673 code = BOZO_RestartAll(tconn);
674 if (code) printf("bos: failed to restart servers (%s)\n", em(code));
676 printf("bos: To restart all processes please specify '-all'\n");
679 if (as->parms[3].items) {
680 printf("bos: Can't use '-all' along with individual instances\n");
682 for(ti = as->parms[1].items; ti; ti=ti->next) {
683 code = BOZO_Restart(tconn, ti->data);
685 printf("bos: failed to restart instance %s (%s)\n", ti->data,
693 static SetCellName(as)
694 struct cmd_syndesc *as; {
695 register struct rx_connection *tconn;
696 register afs_int32 code;
698 tconn = GetConn(as, 0);
699 code = BOZO_SetCellName(tconn, as->parms[1].items->data);
700 if (code) printf("bos: failed to set cell (%s)\n", em(code));
705 register struct cmd_syndesc *as; {
706 register struct rx_connection *tconn;
707 register afs_int32 code;
708 register struct cmd_item *ti;
709 char name[MAXHOSTCHARS];
711 tconn = GetConn(as, 0);
712 for(ti = as->parms[1].items; ti; ti=ti->next) {
713 if (as->parms[2].items) {
714 if (strlen(ti->data) > MAXHOSTCHARS - 3) {
715 fprintf(stderr, "bos: host name too long\n");
719 strcpy(&name[1],ti->data);
720 strcat((char *)&name, "]");
721 code = BOZO_AddCellHost(tconn, name);
723 code = BOZO_AddCellHost(tconn, ti->data);
725 printf("bos: failed to add host %s (%s)\n", ti->data, em(code));
730 static RemoveHost(as)
731 register struct cmd_syndesc *as; {
732 register struct rx_connection *tconn;
733 register afs_int32 code;
734 register struct cmd_item *ti;
736 tconn = GetConn(as, 0);
737 for(ti=as->parms[1].items; ti; ti=ti->next) {
738 code = BOZO_DeleteCellHost(tconn, ti->data);
740 printf("bos: failed to delete host %s (%s)\n", ti->data, em(code));
746 register struct cmd_syndesc *as; {
747 register struct rx_connection *tconn;
748 register afs_int32 code;
751 register afs_int32 i;
754 tconn = GetConn(as, 0);
755 code = BOZO_GetCellName(tconn, &tp);
757 printf("bos: failed to get cell name (%s)\n", em(code));
760 printf("Cell name is %s\n", tbuffer);
762 code = BOZO_GetCellHost(tconn, i, &tp);
763 if (code == BZDOM) break;
765 printf("bos: failed to get cell host %d (%s)\n", i, em(code));
768 printf(" Host %d is %s\n", i+1, tbuffer);
774 register struct cmd_syndesc *as; {
775 register struct rx_connection *tconn;
776 register afs_int32 code;
777 struct ktc_encryptionKey tkey;
780 char cellBuffer[256];
781 char buf[BUFSIZ], ver[BUFSIZ];
783 tconn = GetConn(as, 1);
784 bzero(&tkey, sizeof(struct ktc_encryptionKey));
786 if(as->parms[1].items)
787 strcpy(buf,as->parms[1].items->data);
791 code=des_read_pw_string(buf,sizeof(buf),"input key: ",0);
792 if(code || strlen(buf)==0)
794 fprintf(stderr,"Bad key: \n");
797 code=des_read_pw_string(ver,sizeof(ver),"Retype input key: ",0);
798 if(code || strlen(ver)==0)
800 fprintf(stderr,"Bad key: \n");
803 if (strcmp (ver, buf) != 0) {
804 fprintf (stderr, "\nInput key mismatch\n");
810 temp = atoi(as->parms[2].items->data);
814 strcpy((char *)&tkey, as->parms[1].items->data);
816 strcpy((char *)&tkey, buf);
818 else { /* kerberos key */
819 if (as->parms[ADDPARMOFFSET].items) {
820 strcpy(cellBuffer, as->parms[ADDPARMOFFSET].items->data);
822 /* string to key needs upper-case cell names */
824 /* I don't believe this is true. The string to key function
825 * actually expands the cell name, then LOWER-CASES it. Perhaps it
826 * didn't use to??? */
827 ucstring(cellBuffer, cellBuffer, strlen(cellBuffer));
830 else tcell = (char *) 0; /* no cell specified, use current */
832 ka_StringToKey(as->parms[1].items->data, tcell, &tkey);
834 ka_StringToKey(buf,tcell,&tkey);
836 tconn = GetConn(as, 1);
837 code = BOZO_AddKey(tconn, temp, &tkey);
839 printf("bos: failed to set key %d (%s)\n", temp, em(code));
846 register struct cmd_syndesc *as; {
847 register struct rx_connection *tconn;
848 register afs_int32 code;
850 register struct cmd_item *ti;
852 tconn = GetConn(as, 0);
853 for(ti=as->parms[1].items; ti; ti=ti->next) {
854 temp = atoi(ti->data);
855 code = BOZO_DeleteKey(tconn, temp);
857 printf("bos: failed to delete key %d (%s)\n", temp, em(code));
865 IN register struct cmd_syndesc *as;
867 register struct rx_connection *tconn;
868 register afs_int32 code;
869 struct ktc_encryptionKey tkey;
871 struct bozo_keyInfo keyInfo;
873 register afs_int32 i;
875 tconn = GetConn(as, 1);
878 code = BOZO_ListKeys(tconn, i, &kvno, &tkey, &keyInfo);
881 /* first check if key is returned */
882 if ((!ka_KeyIsZero (&tkey, sizeof(tkey))) && (as->parms[1].items)) {
883 printf ("key %d is '", kvno);
884 ka_PrintBytes (&tkey, sizeof(tkey));
887 if (keyInfo.keyCheckSum == 0) /* shouldn't happen */
888 printf ("key version is %d\n", kvno);
890 printf ("key %d has cksum %u\n", kvno, keyInfo.keyCheckSum);
894 printf("Keys last changed on %s.\n", DateOf(keyInfo.mod_sec));
897 printf("bos: %s error encountered while listing keys\n", em(code));
899 printf("All done.\n");
904 register struct cmd_syndesc *as; {
905 register struct rx_connection *tconn;
906 register afs_int32 code;
908 register struct cmd_item *ti;
911 tconn = GetConn(as, 0);
912 for(ti=as->parms[1].items; ti; ti=ti->next) {
913 code = BOZO_AddSUser(tconn, ti->data);
915 printf("bos: failed to add user '%s' (%s)\n", ti->data, em(code));
922 static RemoveSUser(as)
923 register struct cmd_syndesc *as; {
924 register struct rx_connection *tconn;
925 register struct cmd_item *ti;
926 register afs_int32 code;
930 tconn = GetConn(as, 0);
931 for(ti=as->parms[1].items; ti; ti=ti->next) {
932 code = BOZO_DeleteSUser(tconn, ti->data);
934 printf("bos: failed to delete user '%s', ", ti->data);
936 printf("(no such user)\n");
938 printf("(%s)\n", em(code));
945 #define NPERLINE 10 /* dudes to print per line */
946 static ListSUsers(as)
947 register struct cmd_syndesc *as; {
948 register struct rx_connection *tconn;
950 register afs_int32 code;
953 int lastNL, printGreeting;
955 tconn = GetConn(as, 0);
960 code = BOZO_ListSUsers(tconn, i, &tp);
963 printGreeting = 0; /* delay until after first call succeeds */
964 printf("SUsers are: ");
966 printf("%s ", tbuffer);
967 if ((i % NPERLINE) == NPERLINE-1) {
974 /* a real error code, instead of scanned past end */
975 printf("bos: failed to retrieve super-user list (%s)\n", em(code));
978 if (lastNL == 0) printf("\n");
982 static StatServer(as)
983 register struct cmd_syndesc *as; {
984 register struct rx_connection *tconn;
985 register afs_int32 code;
987 char ibuffer[BOZO_BSSIZE];
991 /* int32p==1 is obsolete, smaller, printout */
992 int32p = (as->parms[2].items != 0? 2 : 0);
994 /* no parms does something pretty different */
995 if (as->parms[1].items) return IStatServer(as, int32p);
997 tconn = GetConn(as, 0);
999 /* for each instance */
1001 code = BOZO_EnumerateInstance(tconn, i, &tp);
1002 if (code == BZDOM) break;
1004 printf("bos: failed to contact host's bosserver (%s).\n",
1008 DoStat(ibuffer, tconn, int32p, (i==0)); /* print status line */
1013 static CreateServer(as)
1014 register struct cmd_syndesc *as; {
1015 register struct rx_connection *tconn;
1016 register afs_int32 code;
1018 register struct cmd_item *ti;
1020 char *type, *name, *notifier=NONOTIFIER;
1022 tconn = GetConn(as, 0);
1023 for(i=0;i<6;i++) parms[i] = "";
1024 for(i=0,ti=as->parms[3].items; (ti && i<6); ti=ti->next,i++) {
1025 parms[i] = ti->data;
1027 name = as->parms[1].items->data;
1028 type = as->parms[2].items->data;
1029 if (ti = as->parms[4].items) {
1030 notifier = ti->data;
1032 code = BOZO_CreateBnode(tconn, type, name, parms[0], parms[1], parms[2],
1033 parms[3], parms[4], notifier);
1035 printf("bos: failed to create new server instance %s of type '%s' (%s)\n",
1036 name, type, em(code));
1041 static DeleteServer(as)
1042 register struct cmd_syndesc *as; {
1043 register struct rx_connection *tconn;
1044 register afs_int32 code;
1045 register struct cmd_item *ti;
1048 tconn = GetConn(as, 0);
1049 for(ti=as->parms[1].items; ti; ti=ti->next) {
1050 code = BOZO_DeleteBnode(tconn, ti->data);
1053 printf("bos: can't delete running instance '%s'\n", ti->data);
1055 printf("bos: failed to delete instance '%s' (%s)\n",
1056 ti->data, em(code));
1062 static StartServer(as)
1063 register struct cmd_syndesc *as; {
1064 register struct rx_connection *tconn;
1065 register afs_int32 code;
1066 register struct cmd_item *ti;
1069 tconn = GetConn(as, 0);
1070 for(ti=as->parms[1].items; ti; ti=ti->next) {
1071 code = BOZO_SetStatus(tconn, ti->data, BSTAT_NORMAL);
1073 printf("bos: failed to start instance '%s' (%s)\n",
1074 ti->data, em(code));
1079 static StopServer(as)
1080 register struct cmd_syndesc *as; {
1081 register struct rx_connection *tconn;
1082 register afs_int32 code;
1083 register struct cmd_item *ti;
1086 tconn = GetConn(as, 0);
1087 for(ti=as->parms[1].items; ti; ti=ti->next) {
1088 code = BOZO_SetStatus(tconn, ti->data, BSTAT_SHUTDOWN);
1090 printf("bos: failed to change stop instance '%s' (%s)\n",
1091 ti->data, em(code));
1093 if (as->parms[8].items) {
1094 code = BOZO_WaitAll(tconn);
1096 printf("bos: can't wait for processes to shutdown (%s)\n",
1102 #define PARMBUFFERSSIZE 32
1104 static DoSalvage(aconn, aparm1, aparm2, aoutName, showlog,parallel,atmpDir,orphans)
1105 struct rx_connection *aconn;
1114 register afs_int32 code;
1117 char tbuffer[BOZO_BSSIZE];
1118 struct bozo_status istatus;
1119 struct rx_call *tcall;
1123 char partName[20]; /* canonical name for partition */
1124 char pbuffer[PARMBUFFERSSIZE];
1125 afs_int32 partNumber;
1126 char *notifier = NONOTIFIER;
1128 /* if a partition was specified, canonicalize the name, since
1129 the salvager has a stupid partition ID parser */
1131 partNumber = volutil_GetPartitionID(aparm1);
1132 if (partNumber < 0) {
1133 printf("bos: could not parse partition ID '%s'\n", aparm1);
1136 tp = volutil_PartitionName(partNumber);
1138 printf("bos: internal error parsing partition ID '%s'\n", aparm1);
1141 strcpy(partName, tp);
1143 else partName[0] = 0;
1145 /* open the file name */
1147 outFile = fopen(aoutName, "w");
1149 printf("bos: can't open specified SalvageLog file '%s'\n",
1153 closeIt = 1; /* close this file later */
1157 closeIt = 0; /* don't close this file later */
1160 for(code=2;code<6;code++) parms[code] = "";
1161 if (!aparm2) aparm2 = "";
1162 /* MUST pass canonical (wire-format) salvager path to bosserver */
1163 strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH, BOZO_BSSIZE);
1165 if ( (strlen(tbuffer) + 1 + strlen(partName) + 1 + strlen(aparm2) + 1) > BOZO_BSSIZE ) {
1166 printf("bos: command line too big\n");
1169 strcat(tbuffer, " ");
1170 strcat(tbuffer, partName);
1171 strcat(tbuffer, " ");
1172 strcat(tbuffer, aparm2);
1174 if ( (strlen(tbuffer) + 4 + strlen(partName) + 1) > BOZO_BSSIZE ) {
1175 printf("bos: command line too big\n");
1178 strcat (tbuffer, " -f ");
1179 strcat (tbuffer, partName);
1182 /* add the parallel option if given */
1183 if (parallel != (char *)0) {
1184 if ( (strlen(tbuffer) + 11 + strlen(parallel) + 1) > BOZO_BSSIZE ) {
1185 printf("bos: command line too big\n");
1188 strcat(tbuffer, " -parallel ");
1189 strcat(tbuffer, parallel);
1192 /* add the tmpdir option if given */
1193 if (atmpDir != (char *)0) {
1194 if ( (strlen(tbuffer) + 9 + strlen(atmpDir) + 1) > BOZO_BSSIZE ) {
1195 printf("bos: command line too big\n");
1198 strcat(tbuffer, " -tmpdir ");
1199 strcat(tbuffer, atmpDir);
1202 /* add the orphans option if given */
1203 if (orphans != (char *)0) {
1204 if ( (strlen(tbuffer) + 10 + strlen(orphans) + 1) > BOZO_BSSIZE ) {
1205 printf("bos: command line too big\n");
1208 strcat(tbuffer, " -orphans ");
1209 strcat(tbuffer, orphans);
1212 if (mrafsParm.Optdebug)
1213 strcat(tbuffer," -debug");
1214 if (mrafsParm.Optnowrite)
1215 strcat(tbuffer," -nowrite");
1216 if (mrafsParm.Optforce)
1217 strcat(tbuffer," -force");
1218 if (mrafsParm.Optoktozap)
1219 strcat(tbuffer," -oktozap");
1220 if (mrafsParm.Optrootfiles)
1221 strcat(tbuffer," -rootfiles");
1222 if (mrafsParm.Optsalvagedirs)
1223 strcat(tbuffer," -salvagedirs");
1224 if (mrafsParm.Optblockreads)
1225 strcat(tbuffer," -blockreads");
1226 if (mrafsParm.OptListResidencies)
1227 strcat(tbuffer," -ListResidencies");
1228 if (mrafsParm.OptSalvageRemote)
1229 strcat(tbuffer," -SalvageRemote");
1230 if (mrafsParm.OptSalvageArchival)
1231 strcat(tbuffer," -SalvageArchival");
1232 if (mrafsParm.OptIgnoreCheck)
1233 strcat(tbuffer," -IgnoreCheck");
1234 if (mrafsParm.OptForceOnLine)
1235 strcat(tbuffer," -ForceOnLine");
1236 if (mrafsParm.OptUseRootDirACL)
1237 strcat(tbuffer," -UseRootDirACL");
1238 if (mrafsParm.OptTraceBadLinkCounts)
1239 strcat(tbuffer," -TraceBadLinkCounts");
1240 if (mrafsParm.OptDontAskFS)
1241 strcat(tbuffer," -DontAskFS");
1242 if (mrafsParm.OptLogLevel) {
1243 sprintf(pbuffer, " -LogLevel %ld", mrafsParm.OptLogLevel);
1244 strcat(tbuffer, pbuffer);
1246 if (mrafsParm.OptRxDebug)
1247 strcat(tbuffer," -rxdebug");
1248 if (mrafsParm.OptResidencies) {
1249 sprintf(pbuffer, " -Residencies %lu", mrafsParm.OptResidencies);
1250 strcat(tbuffer, pbuffer);
1254 parms[1] = "now"; /* when to do it */
1255 code = BOZO_CreateBnode(aconn, "cron", "salvage-tmp", parms[0], parms[1],
1256 parms[2], parms[3], parms[4], notifier);
1257 if (code) goto done;
1258 /* now wait for bnode to disappear */
1262 code = BOZO_GetInstanceInfo(aconn, "salvage-tmp", &tp, &istatus);
1264 printf("bos: waiting for salvage to complete.\n");
1266 if (code != BZNOENT) {
1267 printf("bos: salvage failed (%s)\n", em(code));
1272 /* now print the log file to the output file */
1273 printf("bos: salvage completed\n");
1274 if (aoutName || showlog) {
1275 fprintf(outFile, "SalvageLog:\n");
1276 tcall = rx_NewCall(aconn);
1277 /* MUST pass canonical (wire-format) salvager log path to bosserver */
1278 code = StartBOZO_GetLog(tcall, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH);
1280 rx_EndCall(tcall, code);
1285 code = rx_Read(tcall, &buffer, 1);
1286 if (code != 1) break;
1287 putc(buffer, outFile);
1288 if (buffer == 0) break; /* the end delimeter */
1290 code = rx_EndCall(tcall, 0);
1291 /* fall through into cleanup code */
1295 if (closeIt && outFile) fclose(outFile);
1299 static GetLogCmd(as)
1300 register struct cmd_syndesc *as; {
1301 struct rx_connection *tconn;
1302 register struct rx_call *tcall;
1303 register afs_int32 code;
1307 printf("Fetching log file '%s'...\n", as->parms[1].items->data);
1308 tconn = GetConn(as, 0);
1309 tcall = rx_NewCall(tconn);
1310 code = StartBOZO_GetLog(tcall, as->parms[1].items->data);
1312 rx_EndCall(tcall, code);
1318 code = rx_Read(tcall, &buffer, 1);
1323 if (buffer == 0) break; /* the end delimeter */
1326 code = rx_EndCall(tcall, error);
1327 /* fall through into cleanup code */
1331 com_err("bos", code, "(while reading log)");
1335 static SalvageCmd(as)
1336 struct cmd_syndesc *as; {
1337 register struct rx_connection *tconn;
1338 register afs_int32 code, rc, i;
1340 char tname[BOZO_BSSIZE];
1342 extern struct ubik_client *cstruct;
1343 afs_int32 curGoal, showlog = 0, mrafs = 0;
1349 bzero(&mrafsParm, sizeof(mrafsParm));
1351 /* parm 0 is machine name, 1 is partition, 2 is volume, 3 is -all flag */
1352 tconn = GetConn(as, 0);
1354 /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
1355 /* XXX this should really be done some other way, potentially by RPC */
1357 if (code = BOZO_GetInstanceParm(tconn, "fs", 3, &tp) == 0)
1360 /* we can do a volume, a partition or the whole thing, but not mixtures
1362 if (!as->parms[1].items && as->parms[2].items) {
1363 printf("bos: must specify partition to salvage individual volume.\n");
1366 if (as->parms[5].items && as->parms[3].items) {
1367 printf("bos: can not specify both -file and -showlog.\n");
1370 if (as->parms[4].items && (as->parms[1].items || as->parms[2].items)) {
1371 printf("bos: can not specify -all with other flags.\n");
1375 /* get the output file name, if any */
1376 if (as->parms[3].items)
1377 outName = as->parms[3].items->data;
1379 outName = (char *) 0;
1381 if (as->parms[5].items)
1384 /* parallel option */
1385 parallel = (char *) 0;
1386 if (as->parms[6].items)
1387 parallel = as->parms[6].items->data;
1389 /* get the tmpdir filename if any */
1391 if (as->parms[7].items)
1392 tmpDir = as->parms[7].items->data;
1394 /* -orphans option */
1395 orphans = (char *)0;
1396 if (as->parms[8].items) {
1398 printf("Can't specify -orphans for MR-AFS fileserver\n");
1401 orphans = as->parms[8].items->data;
1405 if (as->parms[MRAFS_OFFSET].items)
1406 mrafsParm.Optdebug = 1;
1407 if (as->parms[MRAFS_OFFSET + 1].items)
1408 mrafsParm.Optnowrite = 1;
1409 if (as->parms[MRAFS_OFFSET + 2].items)
1410 mrafsParm.Optforce = 1;
1411 if (as->parms[MRAFS_OFFSET + 3].items)
1412 mrafsParm.Optoktozap = 1;
1413 if (as->parms[MRAFS_OFFSET + 4].items)
1414 mrafsParm.Optrootfiles = 1;
1415 if (as->parms[MRAFS_OFFSET + 5].items)
1416 mrafsParm.Optsalvagedirs = 1;
1417 if (as->parms[MRAFS_OFFSET + 6].items)
1418 mrafsParm.Optblockreads = 1;
1419 if (as->parms[MRAFS_OFFSET + 7].items)
1420 mrafsParm.OptListResidencies = 1;
1421 if (as->parms[MRAFS_OFFSET + 8].items)
1422 mrafsParm.OptSalvageRemote = 1;
1423 if (as->parms[MRAFS_OFFSET + 9].items)
1424 mrafsParm.OptSalvageArchival = 1;
1425 if (as->parms[MRAFS_OFFSET + 10].items)
1426 mrafsParm.OptIgnoreCheck = 1;
1427 if (as->parms[MRAFS_OFFSET + 11].items)
1428 mrafsParm.OptForceOnLine = 1;
1429 if (as->parms[MRAFS_OFFSET + 12].items)
1430 mrafsParm.OptUseRootDirACL = 1;
1431 if (as->parms[MRAFS_OFFSET + 13].items)
1432 mrafsParm.OptTraceBadLinkCounts = 1;
1433 if (as->parms[MRAFS_OFFSET + 14].items)
1434 mrafsParm.OptDontAskFS = 1;
1435 if (as->parms[MRAFS_OFFSET + 15].items)
1436 mrafsParm.OptLogLevel = atoi(as->parms[MRAFS_OFFSET + 15].items->data);
1437 if (as->parms[MRAFS_OFFSET + 16].items)
1438 mrafsParm.OptRxDebug = 1;
1439 if (as->parms[MRAFS_OFFSET + 17].items) {
1440 if (as->parms[MRAFS_OFFSET + 8].items ||
1441 as->parms[MRAFS_OFFSET + 9].items) {
1442 printf("Can't specify -Residencies with -SalvageRemote or -SalvageArchival\n");
1445 code = GetUInt32(as->parms[MRAFS_OFFSET + 17].items->data,
1446 &mrafsParm.OptResidencies);
1448 printf("bos: '%s' is not a valid residency mask.\n",
1449 as->parms[MRAFS_OFFSET + 13].items->data);
1456 for (i = 9; i < ADDPARMOFFSET; i++) {
1457 if (as->parms[i].items) {
1458 printf(" %s only possible for MR-AFS fileserver.\n",
1466 if (as->parms[4].items) {
1467 /* salvage whole enchilada */
1468 curGoal = GetServerGoal(tconn, "fs");
1469 if (curGoal == BSTAT_NORMAL) {
1470 printf("bos: shutting down fs.\n");
1471 code = BOZO_SetTStatus(tconn, "fs", BSTAT_SHUTDOWN);
1473 printf("bos: failed to stop 'fs' (%s)\n", em(code));
1476 code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1478 printf("bos: failed to wait for file server shutdown, continuing.\n");
1480 /* now do the salvage operation */
1481 printf("Starting salvage.\n");
1482 rc = DoSalvage(tconn, (char *) 0, (char *) 0, outName, showlog,parallel,tmpDir,orphans);
1483 if (rc) printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1484 if (curGoal == BSTAT_NORMAL) {
1485 printf("bos: restarting fs.\n");
1486 code = BOZO_SetTStatus(tconn, "fs", BSTAT_NORMAL);
1488 printf("bos: failed to restart 'fs' (%s)\n", em(code));
1494 else if (!as->parms[2].items) {
1495 if (!as->parms[1].items) {
1496 printf("bos: must specify -all switch to salvage all partitions.\n");
1499 if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1500 /* can't parse volume ID, so complain before shutting down
1503 printf("bos: can't interpret %s as partition ID.\n",
1504 as->parms[1].items->data);
1507 curGoal = GetServerGoal(tconn, "fs");
1508 /* salvage a whole partition (specified by parms[1]) */
1509 if (curGoal == BSTAT_NORMAL) {
1510 printf("bos: shutting down fs.\n");
1511 code = BOZO_SetTStatus(tconn, "fs", BSTAT_SHUTDOWN);
1513 printf("bos: can't stop 'fs' (%s)\n", em(code));
1516 code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1518 printf("bos: failed to wait for file server shutdown, continuing.\n");
1520 /* now do the salvage operation */
1521 printf("Starting salvage.\n");
1522 rc = DoSalvage(tconn, as->parms[1].items->data, (char *) 0,
1523 outName, showlog,parallel,tmpDir,orphans);
1524 if (rc) printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1525 if (curGoal == BSTAT_NORMAL) {
1526 printf("bos: restarting fs.\n");
1527 code = BOZO_SetTStatus(tconn, "fs", BSTAT_NORMAL);
1529 printf("bos: failed to restart 'fs' (%s)\n", em(code));
1536 /* salvage individual volume (don't shutdown fs first), just use
1537 * single-shot cron bnode. Must leave server running when using this
1538 * option, since salvager will ask file server for the volume */
1541 const char *confdir;
1544 if (as->parms[ADDPARMOFFSET].items)
1545 tmpname = as->parms[ADDPARMOFFSET].items->data;
1546 else tmpname = (char *) 0;
1548 localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
1549 confdir = (localauth ? AFSDIR_SERVER_ETC_DIRPATH : AFSDIR_CLIENT_ETC_DIRPATH);
1550 code = vsu_ClientInit(/* noauth */ 1, confdir, tmpname,
1551 /* server auth */ 0, &cstruct, (int (*)()) 0);
1553 newID = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1555 printf("bos: can't interpret %s as volume name or ID\n", as->parms[2].items->data);
1558 sprintf(tname, "%u", newID);
1561 printf("bos: can't initialize volume system client (code %d), trying anyway.\n",
1562 as->parms[2].items->data, code);
1563 strncpy(tname, as->parms[2].items->data, sizeof(tname));
1565 if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1566 /* can't parse volume ID, so complain before shutting down
1569 printf("bos: can't interpret %s as partition ID.\n",
1570 as->parms[1].items->data);
1573 printf("Starting salvage.\n");
1574 rc = DoSalvage(tconn, as->parms[1].items->data, tname, outName,
1575 showlog,parallel,tmpDir,orphans);
1577 printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1584 static IStatServer(as, int32p)
1586 register struct cmd_syndesc *as; {
1587 register struct rx_connection *tconn;
1588 register struct cmd_item *ti;
1591 tconn = GetConn(as, 0);
1592 for (ti=as->parms[1].items; ti; ti=ti->next) {
1593 DoStat(ti->data, tconn, int32p, firstTime);
1599 static DoStat (aname, aconn, aint32p, firstTime)
1601 IN register struct rx_connection *aconn;
1603 IN int firstTime; /* true iff first instance in cmd */
1607 register afs_int32 code;
1608 register afs_int32 i;
1609 struct bozo_status istatus;
1611 char *is1, *is2, *is3, *is4; /* instance strings */
1614 code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
1616 printf("bos: failed to get instance info for '%s' (%s)\n",
1620 if (firstTime && aint32p && (istatus.flags & BOZO_BADDIRACCESS))
1621 printf ("Bosserver reports inappropriate access on server directories\n");
1622 printf("Instance %s, ", aname);
1623 if (aint32p) printf("(type is %s) ", buffer);
1624 if (istatus.fileGoal == istatus.goal) {
1625 if (!istatus.goal) printf("disabled, ");
1628 if (istatus.fileGoal) printf("temporarily disabled, ");
1629 else printf("temporarily enabled, ");
1632 if (istatus.flags & BOZO_ERRORSTOP)
1633 printf("stopped for too many errors, ");
1634 if (istatus.flags & BOZO_HASCORE)
1635 printf("has core file, ");
1638 code = BOZO_GetStatus(aconn, aname, &temp, &tp);
1640 printf("bos: failed to get status for instance '%s' (%s)\n",
1643 printf("currently ", aname);
1644 if (temp == BSTAT_NORMAL) printf("running normally.\n");
1645 else if (temp == BSTAT_SHUTDOWN) printf("shutdown.\n");
1646 else if (temp == BSTAT_STARTINGUP) printf("starting up.\n");
1647 else if (temp == BSTAT_SHUTTINGDOWN) printf("shutting down.\n");
1648 if (buffer[0] != 0) {
1649 printf(" Auxiliary status is: %s.\n", buffer);
1653 /* are we done yet? */
1654 if (!aint32p) return 0;
1656 if (istatus.procStartTime)
1657 printf(" Process last started at %s (%d proc starts)\n",
1658 DateOf(istatus.procStartTime), istatus.procStarts);
1659 if (istatus.lastAnyExit) {
1660 printf(" Last exit at %s\n", DateOf(istatus.lastAnyExit));
1662 if (istatus.lastErrorExit) {
1663 is1 = is2 = is3 = is4 = (char *) 0;
1664 printf(" Last error exit at %s, ", DateOf(istatus.lastErrorExit));
1665 code = BOZO_GetInstanceStrings(aconn, aname, &is1, &is2, &is3, &is4);
1666 /* don't complain about failing call, since could simply mean
1667 * interface mismatch.
1671 /* non-null instance string */
1672 printf("by %s, ", is1);
1679 if (istatus.errorSignal) {
1680 if (istatus.errorSignal == SIGTERM)
1681 printf("due to shutdown request\n");
1683 printf("due to signal %d\n", istatus.errorSignal);
1686 printf("by exiting with code %d\n", istatus.errorCode);
1690 /* try to display all the parms */
1693 code = BOZO_GetInstanceParm(aconn, aname, i, &tp);
1695 printf(" Command %d is '%s'\n", i+1, buffer);
1698 code = BOZO_GetInstanceParm(aconn, aname, 999, &tp);
1700 /* Any type of failure is treated as not having a notifier program */
1701 printf(" Notifier is '%s'\n", buffer);
1708 #ifdef BOS_RESTRICTED_MODE
1709 static GetRestrict(as)
1710 struct cmd_syndesc *as; {
1711 register struct rx_connection *tconn;
1712 afs_int32 code, val;
1714 tconn = GetConn(as, 0);
1715 code = BOZO_GetRestrictedMode(tconn, &val);
1716 if (code) printf("bos: failed to get restricted mode (%s)\n", em(code));
1717 else printf("Restricted mode is %s\n", val ? "on" : "off");
1722 static SetRestrict(as)
1723 struct cmd_syndesc *as; {
1724 register struct rx_connection *tconn;
1725 afs_int32 code, val;
1727 tconn = GetConn(as, 0);
1728 util_GetInt32(as->parms[1].items->data, &val);
1729 code = BOZO_SetRestrictedMode(tconn, val);
1730 if (code) printf("bos: failed to set restricted mode (%s)\n", em(code));
1735 static void add_std_args (ts)
1736 register struct cmd_syndesc *ts;
1738 cmd_Seek(ts, ADDPARMOFFSET);
1739 /* + 0 */ cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1740 /* + 1 */ cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1741 "don't authenticate");
1742 /* + 2 */ cmd_AddParm (ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1743 "create tickets from KeyFile");
1746 #include "AFS_component_version_number.c"
1752 register afs_int32 code;
1753 register struct cmd_syndesc *ts;
1754 extern int afsconf_SawCell;
1756 #ifdef AFS_AIX32_ENV
1758 * The following signal action for AIX is necessary so that in case of a
1759 * crash (i.e. core is generated) we can include the user's data section
1760 * in the core dump. Unfortunately, by default, only a partial core is
1761 * generated which, in many cases, isn't too useful.
1763 struct sigaction nsa;
1765 sigemptyset(&nsa.sa_mask);
1766 nsa.sa_handler = SIG_DFL;
1767 nsa.sa_flags = SA_FULLDUMP;
1768 sigaction(SIGSEGV, &nsa, NULL);
1769 sigaction(SIGABRT, &nsa, NULL);
1775 printf("bos: could not initialize rx (%s)\n", em(code));
1779 /* To resolve a AFSCELL environment "Note: ..." problem: Because bos calls ka_Init (why?) before any
1780 * checkup on the existance of a "-cell" option on the particular bos command we don't print the
1781 * message if a cell is passed in. Luckily the rest of the programs don't call these adhoc routines
1782 * and things work fine. Note that if the "-cell" isn't passed then we're still ok since later on
1783 * the proper routine (afsconf_GetCellInfo) is going to be called to do the right thing.
1785 afsconf_SawCell = 1; /* Means don't print warning if AFSCELL is set */
1787 afsconf_SawCell = 0; /* Reset it */
1788 /* don't check error code, since fails sometimes when we're setting up a
1790 initialize_cmd_error_table();
1791 initialize_bz_error_table();
1793 ts = cmd_CreateSyntax("start", StartServer, 0, "start running a server");
1794 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1795 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1798 ts = cmd_CreateSyntax("stop", StopServer, 0, "halt a server instance");
1799 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1800 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1802 cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1803 "wait for process to stop");
1806 ts = cmd_CreateSyntax("status", StatServer, 0,
1807 "show server instance status");
1808 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1809 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL,
1810 "server process name");
1811 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "long status");
1814 ts = cmd_CreateSyntax("shutdown", Shutdown, 0, "shutdown all processes");
1815 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1816 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1818 cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1819 "wait for process to stop");
1822 ts = cmd_CreateSyntax("startup", Startup, 0, "start all processes");
1823 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1824 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1827 ts = cmd_CreateSyntax("restart", Restart, 0, "restart all processes");
1828 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1829 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1830 cmd_AddParm(ts, "-bosserver", CMD_FLAG, CMD_OPTIONAL, "restart bosserver");
1831 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "restart all processes");
1836 ts = cmd_CreateSyntax("create", CreateServer, 0,
1837 "create a new server instance");
1838 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1839 cmd_AddParm(ts, "-instance", CMD_SINGLE, 0, "server process name");
1840 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "server type");
1841 cmd_AddParm(ts, "-cmd", CMD_LIST, 0, "command lines");
1842 cmd_AddParm(ts, "-notifier", CMD_SINGLE, CMD_OPTIONAL, "Notifier program");
1845 ts = cmd_CreateSyntax("delete", DeleteServer, 0,
1846 "delete a server instance");
1847 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1848 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1851 ts = cmd_CreateSyntax("adduser", AddSUser, 0,
1852 "add users to super-user list");
1853 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1854 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
1857 ts = cmd_CreateSyntax("removeuser", RemoveSUser, 0,
1858 "remove users from super-user list");
1859 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1860 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
1863 ts = cmd_CreateSyntax("listusers", ListSUsers, 0, "list super-users");
1864 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1867 ts = cmd_CreateSyntax("addkey", AddKey, 0,
1868 "add keys to key dbase (kvno 999 is bcrypt)");
1869 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1870 cmd_AddParm(ts, "-key", CMD_SINGLE, CMD_OPTIONAL, "key");
1871 cmd_AddParm(ts, "-kvno", CMD_SINGLE, 0, "key version number");
1874 ts = cmd_CreateSyntax("removekey", RemoveKey, 0,
1875 "remove keys from key dbase");
1876 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1877 cmd_AddParm(ts, "-kvno", CMD_LIST, 0, "key version number");
1880 ts = cmd_CreateSyntax("listkeys", ListKeys, 0, "list keys");
1881 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1882 cmd_AddParm(ts, "-showkey", CMD_FLAG, CMD_OPTIONAL, "show the actual key rather than the checksum");
1885 ts = cmd_CreateSyntax("listhosts", ListHosts, 0, "get cell host list");
1886 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1888 cmd_CreateAlias(ts, "getcell");
1890 ts = cmd_CreateSyntax("setcellname", SetCellName, 0, "set cell name");
1891 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1892 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
1895 ts = cmd_CreateSyntax("addhost", AddHost, 0, "add host to cell dbase");
1896 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1897 cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
1898 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL, "vote doesn't count");
1901 ts = cmd_CreateSyntax("removehost", RemoveHost, 0,
1902 "remove host from cell dbase");
1903 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1904 cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
1907 ts = cmd_CreateSyntax("setauth", SetAuth, 0,
1908 "set authentication required flag");
1909 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1910 cmd_AddParm(ts, "-authrequired", CMD_SINGLE,
1911 0, "on or off: authentication required for admin requests");
1914 ts = cmd_CreateSyntax("install", Install, 0, "install program");
1915 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1916 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to install");
1917 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1920 ts = cmd_CreateSyntax("uninstall", UnInstall, 0, "uninstall program");
1921 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1922 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to uninstall");
1923 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1926 ts = cmd_CreateSyntax("getlog", GetLogCmd, 0, "examine log file");
1927 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1928 cmd_AddParm(ts, "-file", CMD_SINGLE, 0, "log file to examine");
1931 ts = cmd_CreateSyntax("getdate", GetDate, 0, "get dates for programs");
1932 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1933 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to check");
1934 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1937 ts = cmd_CreateSyntax("exec", Exec, 0, "execute shell command on server");
1938 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1939 cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "command to execute");
1942 ts = cmd_CreateSyntax("prune", Prune, 0, "prune server files");
1943 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1944 cmd_AddParm(ts, "-bak", CMD_FLAG, CMD_OPTIONAL, "delete .BAK files");
1945 cmd_AddParm(ts, "-old", CMD_FLAG, CMD_OPTIONAL, "delete .OLD files");
1946 cmd_AddParm(ts, "-core", CMD_FLAG, CMD_OPTIONAL, "delete core files");
1947 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "delete all junk files");
1950 ts = cmd_CreateSyntax("setrestart", SetRestartCmd, 0, "set restart times");
1951 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
1952 cmd_AddParm(ts, "-time", CMD_SINGLE,
1953 CMD_REQUIRED, "time to restart server");
1954 cmd_AddParm(ts, "-general", CMD_FLAG,
1955 CMD_OPTIONAL, "set general restart time");
1956 cmd_AddParm(ts, "-newbinary", CMD_FLAG,
1957 CMD_OPTIONAL, "set new binary restart time");
1960 ts = cmd_CreateSyntax("getrestart", GetRestartCmd, 0, "get restart times");
1961 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
1964 ts = cmd_CreateSyntax("salvage", SalvageCmd, 0,
1965 "salvage partition or volumes");
1966 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1967 cmd_AddParm(ts, "-partition", CMD_SINGLE,
1968 CMD_OPTIONAL, "salvage partition");
1969 cmd_AddParm(ts, "-volume", CMD_SINGLE,
1970 CMD_OPTIONAL, "salvage volume number or volume name");
1971 cmd_AddParm(ts, "-file", CMD_SINGLE,
1972 CMD_OPTIONAL, "salvage log output file");
1973 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "salvage whole server");
1974 cmd_AddParm(ts, "-showlog", CMD_FLAG, CMD_OPTIONAL, "display salvage log");
1975 cmd_AddParm(ts, "-parallel",CMD_SINGLE, CMD_OPTIONAL,
1976 "# of max parallel partition salvaging");
1977 cmd_AddParm(ts, "-tmpdir",CMD_SINGLE, CMD_OPTIONAL,
1978 "directory to place tmp files");
1979 cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL,
1980 "ignore | remove | attach");
1981 cmd_AddParm(ts, "-debug", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Run in Debugging mode");
1982 cmd_AddParm(ts, "-nowrite", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Run readonly/test mode");
1983 cmd_AddParm(ts, "-force", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force full salvaging");
1984 cmd_AddParm(ts, "-oktozap", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Give permission to destroy bogus file residencies/volumes - debugging flag");
1985 cmd_AddParm(ts, "-rootfiles", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Show files owned by root - debugging flag");
1986 cmd_AddParm(ts, "-salvagedirs", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force rebuild/salvage of all directories");
1987 cmd_AddParm(ts, "-blockreads", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Read smaller blocks to handle IO/bad blocks");
1988 cmd_AddParm(ts, "-ListResidencies", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Just list affected file residencies - debugging flag");
1989 cmd_AddParm(ts, "-SalvageRemote", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Salvage storage systems that are not directly attached");
1990 cmd_AddParm(ts, "-SalvageArchival", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Salvage HSM storage systems");
1991 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.");
1992 cmd_AddParm(ts, "-ForceOnLine", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force the volume to come online, even if it hasn't salvaged cleanly.");
1993 cmd_AddParm(ts, "-UseRootDirACL", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Use the root directory ACL for lost+found directory if it is created.");
1994 cmd_AddParm(ts, "-TraceBadLinkCounts", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Print out lines about volume reference count changes.");
1995 cmd_AddParm(ts, "-DontAskFS", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Don't ask fileserver to take volume offline. THIS IS VERY DANGEROUS.");
1996 cmd_AddParm(ts, "-LogLevel", CMD_SINGLE, CMD_OPTIONAL, "(MR-AFS) log level");
1997 cmd_AddParm(ts, "-rxdebug", CMD_FLAG, CMD_OPTIONAL, "(MR-AFS) Write out rx debug information.");
1998 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");
2001 ts = cmd_CreateSyntax("blockscanner", BlockScannerCmd, 0,
2002 "block scanner daemon from making migration requests");
2003 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2006 ts = cmd_CreateSyntax("unblockscanner", UnBlockScannerCmd, 0,
2007 "allow scanner daemon to make migration requests again");
2008 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2011 #ifdef BOS_RESTRICTED_MODE
2012 ts = cmd_CreateSyntax("getrestricted", GetRestrict, 0, "get restrict mode");
2013 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2016 ts = cmd_CreateSyntax("setrestricted", SetRestrict, 0, "set restrict mode");
2017 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2018 cmd_AddParm(ts, "-mode", CMD_SINGLE, 0, "mode to set");
2023 code = cmd_Dispatch(argc, argv);