2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
18 #include <sys/types.h>
25 #include <netinet/in.h>
27 #include <sys/socket.h>
29 #endif /* AFS_NT40_ENV */
31 #include <afs/procmgmt.h> /* signal(), kill(), wait(), etc. */
35 #include <afs/afsutil.h>
36 #include <afs/cellconfig.h>
42 #include <afs/cellconfig.h>
45 #include <afs/com_err.h>
47 #include <afs/ktime.h>
51 extern char *volutil_PartitionName();
52 extern struct rx_call *rx_NewCall();
53 extern char *volutil_PartitionName();
54 extern struct hostent *hostutil_GetHostByName();
61 #define MRAFS_OFFSET 9
62 #define ADDPARMOFFSET 26
64 static struct SalvageParms {
69 afs_int32 Optrootfiles;
70 afs_int32 Optsalvagedirs;
71 afs_int32 Optblockreads;
72 afs_int32 OptListResidencies;
73 afs_int32 OptSalvageRemote;
74 afs_int32 OptSalvageArchival;
75 afs_int32 OptIgnoreCheck;
76 afs_int32 OptForceOnLine;
77 afs_int32 OptUseRootDirACL;
78 afs_int32 OptTraceBadLinkCounts;
79 afs_int32 OptDontAskFS;
80 afs_int32 OptLogLevel;
82 afs_uint32 OptResidencies;
85 /* dummy routine for the audit work. It should do nothing since audits */
86 /* occur at the server level and bos is not a server. */
87 osi_audit() {return 0;}
89 /* keep those lines small */
90 static char *em(acode)
93 return "communications failure (-1)";
95 return "communications timeout (-3)";
96 else return (char *) error_message(acode);
99 /* get partition id from a name */
100 static afs_int32 GetPartitionID(aname)
106 if (tc == 0) return -1; /* unknown */
107 /* numbers go straight through */
108 if (tc >= '0' && tc <= '9') {
111 /* otherwise check for vicepa or /vicepa, or just plain "a" */
113 if (strlen(aname) <= 2) {
114 strcpy(ascii, aname);
116 else if (!strncmp(aname, "/vicep", 6)) {
117 strncpy(ascii, aname+6, 2);
119 else if (!strncmp(aname, "vicep", 5)) {
120 strncpy(ascii, aname+5, 2);
122 else return -1; /* bad partition name */
123 /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab,
124 * .../vicepzz, and are numbered from 0. Do the appropriate conversion */
126 /* one char name, 0..25 */
127 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
128 return ascii[0] - 'a';
131 /* two char name, 26 .. <whatever> */
132 if (ascii[0] < 'a' || ascii[0] > 'z') return -1; /* wrongo */
133 if (ascii[1] < 'a' || ascii[1] > 'z') return -1; /* just as bad */
134 return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
138 /* make ctime easier to use */
139 static char *DateOf(atime)
141 static char tbuffer[30];
143 tp=ctime((time_t *)&atime);
146 tbuffer[24] = 0; /* get rid of new line */
149 strcpy(tbuffer, "BAD TIME");
153 /* global stuff from main for communicating with GetConn */
154 static struct rx_securityClass *sc[3];
157 /* use the syntax descr to get a connection, authenticated appropriately.
158 * aencrypt is set if we want to encrypt the data on the wire.
160 static struct rx_connection *GetConn(as, aencrypt)
162 struct cmd_syndesc *as; {
165 register afs_int32 code;
166 register struct rx_connection *tconn;
168 register struct afsconf_dir *tdir;
170 struct ktc_principal sname;
171 struct ktc_token ttoken;
175 hostname = as->parms[0].items->data;
176 th = hostutil_GetHostByName(hostname);
178 printf("bos: can't find address for host '%s'\n", hostname);
181 memcpy(&addr, th->h_addr, sizeof(afs_int32));
183 /* get tokens for making authenticated connections */
184 localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
185 confdir = (localauth ? AFSDIR_SERVER_ETC_DIRPATH : AFSDIR_CLIENT_ETC_DIRPATH);
186 tdir = afsconf_Open (confdir);
188 struct afsconf_cell info;
191 if (as->parms[ADDPARMOFFSET].items)
192 tname = as->parms[ADDPARMOFFSET].items->data;
193 else tname = (char *) 0;
194 /* next call expands cell name abbrevs for us and handles looking up
196 code = afsconf_GetCellInfo(tdir, tname, (char *) 0, &info);
198 com_err ("bos", code, "(can't find cell '%s' in cell database)",
199 (tname? tname : "<default>"));
202 else strcpy(sname.cell, info.name);
205 printf("bos: can't open cell database (%s)\n", confdir);
208 sname.instance[0] = 0;
209 strcpy(sname.name, "afs");
210 sc[0] = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
215 if (!as->parms[ADDPARMOFFSET + 1].items) { /* not -noauth */
216 if (as->parms[ADDPARMOFFSET + 2].items) { /* -localauth */
217 code = afsconf_GetLatestKey (tdir, 0,0);
218 if (code) com_err ("bos", code, "(getting key from local KeyFile)");
221 code = afsconf_ClientAuthSecure (tdir, &sc[2], &scIndex);
223 code = afsconf_ClientAuth (tdir, &sc[2], &scIndex);
224 if (code) com_err ("bos", code, "(calling ClientAuth)");
225 else if (scIndex != 2) /* this shouldn't happen */
228 } else { /* not -localauth, check for tickets */
229 code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), (char *)0);
231 /* have tickets, will travel */
232 if (ttoken.kvno >= 0 && ttoken.kvno <= 255) ;
235 "bos: funny kvno (%d) in ticket, proceeding\n",
239 if (aencrypt) encryptLevel = rxkad_crypt;
240 else encryptLevel = rxkad_clear;
241 sc[2] = (struct rx_securityClass *)
242 rxkad_NewClientSecurityObject
243 (encryptLevel, &ttoken.sessionKey,
244 ttoken.kvno, ttoken.ticketLen, ttoken.ticket);
246 } else com_err ("bos", code, "(getting tickets)");
248 if ((scIndex == 0) || (sc[scIndex] == 0)) {
249 fprintf (stderr, "bos: running unauthenticated\n");
253 tconn = rx_NewConnection (addr, htons(AFSCONF_NANNYPORT), 1,
254 sc[scIndex], scIndex);
256 fprintf (stderr, "bos: could not create rx connection\n");
259 rxs_Release (sc[scIndex]);
265 struct cmd_syndesc *as; {
266 register afs_int32 code;
267 register struct rx_connection *tconn;
271 tconn = GetConn(as, 0);
272 tp = as->parms[1].items->data;
273 if (strcmp(tp, "on")==0) flag = 0; /* auth req.: noauthflag is false */
274 else if (strcmp(tp, "off") == 0) flag = 1;
276 printf("bos: illegal authentication specifier '%s', must be 'off' or 'on'.\n", tp);
279 code = BOZO_SetNoAuthFlag(tconn, flag);
280 if (code) com_err ("bos", code, "(failed to set authentication flag)");
284 /* take a name (e.g. foo/bar, and a dir e.g. /usr/afs/bin, and construct
285 * /usr/afs/bin/bar */
286 static ComputeDestDir(aname, adir, aresult, alen)
287 char *aname, *adir, *aresult;
291 strcpy(aresult, adir);
292 tp = strrchr(aname, '/');
295 strcat(aresult, "/");
296 strcat(aresult, aname);
299 /* tp points at the / character */
305 /* copy data from fd afd to rx call acall */
306 static CopyBytes(afd, acall)
308 register struct rx_call *acall; {
309 register afs_int32 code;
310 register afs_int32 len;
314 len = read(afd, tbuffer, sizeof(tbuffer));
315 if (len < 0) return errno;
316 if (len == 0) return 0; /* all done */
317 code = rx_Write(acall, tbuffer, len);
318 if (code != len) return -1;
323 register struct cmd_syndesc *as; {
324 register afs_int32 code;
325 register struct rx_connection *tconn;
326 register afs_int32 flags;
328 tconn = GetConn(as, 0);
330 if (as->parms[1].items) flags |= BOZO_PRUNEBAK;
331 if (as->parms[2].items) flags |= BOZO_PRUNEOLD;
332 if (as->parms[3].items) flags |= BOZO_PRUNECORE;
333 if (as->parms[4].items) flags |= 0xff;
334 code = BOZO_Prune(tconn, flags);
335 if (code) com_err ("bos", code, "(failed to prune server files)");
340 register struct cmd_syndesc *as; {
341 register struct rx_connection *tconn;
342 register afs_int32 code;
344 tconn = GetConn(as, 0);
345 code = BOZO_Exec(tconn, as->parms[1].items->data);
346 if (code) printf("bos: failed to execute command (%s)\n",
352 register struct cmd_syndesc *as; {
353 register afs_int32 code;
356 afs_int32 time, bakTime, oldTime;
357 register struct rx_connection *tconn;
358 register struct cmd_item *ti;
360 tconn = GetConn(as, 0);
361 if (!as->parms[1].items) {
362 printf("bos: no files to check\n");
366 /* compute dest dir or file; default MUST be canonical form of dir path */
367 if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
368 else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
370 for(ti=as->parms[1].items; ti; ti=ti->next) {
371 /* check date for each file */
372 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
373 code = BOZO_GetDates(tconn, tbuffer, &time, &bakTime, &oldTime);
375 printf("bos: failed to check date on %s (%s)\n", ti->data,
380 printf("File %s ", tbuffer);
381 if (time == 0) printf("does not exist, ");
382 else printf("dated %s, ", DateOf(time));
383 if (bakTime == 0) printf("no .BAK file, ");
384 else printf(".BAK file dated %s, ", DateOf(bakTime));
385 if (oldTime == 0) printf("no .OLD file.");
386 else printf(".OLD file dated %s.", DateOf(oldTime));
394 register struct cmd_syndesc *as; {
395 register afs_int32 code;
398 register struct cmd_item *ti;
399 register struct rx_connection *tconn;
401 tconn = GetConn(as, 0);
402 if (!as->parms[1].items) {
403 printf("bos: no files to uninstall\n");
407 /* compute dest dir or file; default MUST be canonical form of dir path */
408 if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
409 else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
411 for(ti=as->parms[1].items; ti; ti=ti->next) {
412 /* uninstall each file */
413 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
414 code = BOZO_UnInstall(tconn, tbuffer);
416 printf("bos: failed to uninstall %s (%s)\n", ti->data,
420 else printf("bos: uninstalled file %s\n", ti->data);
425 static afs_int32 GetServerGoal(aconn, aname)
427 struct rx_connection *aconn; {
430 register afs_int32 code;
431 struct bozo_status istatus;
434 code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
436 printf("bos: failed to get instance info for '%s' (%s)\n",
438 /* if we can't get the answer, assume its running */
441 if (istatus.goal == 0)
442 return BSTAT_SHUTDOWN;
448 struct cmd_syndesc *as; {
449 struct rx_connection *tconn;
450 register afs_int32 code;
451 register struct cmd_item *ti;
455 struct rx_call *tcall;
458 tconn = GetConn(as, 0);
459 if (!as->parms[1].items) {
460 printf("bos: no files to install\n");
464 /* compute dest dir or file; default MUST be canonical form of dir path */
465 if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
466 else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
468 for(ti=as->parms[1].items; ti; ti=ti->next) {
469 /* install each file */
470 fd = open(ti->data, O_RDONLY);
472 /* better to quit on error than continue for install command */
473 printf("bos: can't find file '%s', quitting\n", ti->data);
476 code = fstat(fd, &tstat);
478 printf("bos: failed to stat file %s, errno is %d\n", ti->data,
482 /* compute destination dir */
483 ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
484 tcall = rx_NewCall(tconn);
485 code = StartBOZO_Install(tcall, tbuffer, tstat.st_size, (afs_int32)tstat.st_mode,
488 code = CopyBytes(fd, tcall);
490 code = rx_EndCall(tcall, code);
492 printf("bos: failed to install %s (%s)\n", ti->data, em(code));
495 else printf("bos: installed file %s\n", ti->data);
501 struct cmd_syndesc *as; {
502 register struct rx_connection *tconn;
503 register afs_int32 code;
504 register struct cmd_item *ti;
506 tconn = GetConn(as, 0);
507 if (as->parms[1].items == 0) {
508 code = BOZO_ShutdownAll(tconn);
509 if (code) printf("bos: failed to shutdown servers (%s)\n", em(code));
512 for(ti = as->parms[1].items; ti; ti=ti->next) {
513 code = BOZO_SetTStatus(tconn, ti->data, BSTAT_SHUTDOWN);
515 printf("bos: failed to shutdown instance %s (%s)\n",
519 if (as->parms[8].items) {
520 code = BOZO_WaitAll(tconn);
522 printf("bos: can't wait for processes to shutdown (%s)\n",
528 static BlockScannerCmd(as, arock)
529 struct cmd_syndesc *as;
531 register afs_int32 code;
532 struct rx_connection *tconn;
533 char BlockCommand[] = "/usr/afs/bin/scanner -block";
535 tconn = GetConn(as, 0);
536 code = BOZO_Exec(tconn, BlockCommand);
538 printf("bos: failed to block scanner from making migration requests (%s)\n",
543 static UnBlockScannerCmd(as, arock)
544 struct cmd_syndesc *as;
546 register afs_int32 code;
547 struct rx_connection *tconn;
548 char UnBlockCommand[] = "/usr/afs/bin/scanner -unblock";
550 tconn = GetConn(as, 0);
551 code = BOZO_Exec(tconn, UnBlockCommand);
553 printf("bos: failed to allow scanner daemon to make migration requests again (%s)\n",
558 static GetRestartCmd(as, arock)
559 struct cmd_syndesc *as;
561 register afs_int32 code;
562 struct ktime generalTime, newBinaryTime;
563 char messageBuffer[256];
564 struct rx_connection *tconn;
567 hostp = as->parms[0].items->data; /* host name for messages */
568 tconn = GetConn(as, 0);
570 code = BOZO_GetRestartTime(tconn, 1, &generalTime);
572 printf("bos: failed to retrieve restart information (%s)\n", em(code));
575 code = BOZO_GetRestartTime(tconn, 2, &newBinaryTime);
577 printf("bos: failed to retrieve restart information (%s)\n", em(code));
581 code = ktime_DisplayString(&generalTime, messageBuffer);
583 printf("bos: failed to decode restart time (%s)\n", em(code));
586 printf("Server %s restarts %s\n", hostp, messageBuffer);
588 code = ktime_DisplayString(&newBinaryTime, messageBuffer);
590 printf("bos: failed to decode restart time (%s)\n", em(code));
593 printf("Server %s restarts for new binaries %s\n", hostp, messageBuffer);
599 static SetRestartCmd(as, arock)
600 struct cmd_syndesc *as;
603 register afs_int32 code;
604 struct ktime restartTime;
606 struct rx_connection *tconn;
609 tconn = GetConn(as, 0);
610 if (as->parms[2].items) {count++; type = 1;}
611 if (as->parms[3].items) {count++; type = 2;}
613 printf("bos: can't specify more than one restart time at a time\n");
616 if (count == 0) type = 1; /* by default set general restart time */
618 if (code = ktime_ParsePeriodic(as->parms[1].items->data, &restartTime)) {
619 printf("bos: failed to parse '%s' as periodic restart time(%s)\n",
620 as->parms[1].items->data, em(code));
624 code = BOZO_SetRestartTime(tconn, type, &restartTime);
626 printf("bos: failed to set restart time at server (%s)\n", em(code));
633 struct cmd_syndesc *as; {
634 register struct rx_connection *tconn;
635 register afs_int32 code;
636 register struct cmd_item *ti;
638 tconn = GetConn(as, 0);
639 if (as->parms[1].items == 0) {
640 code = BOZO_StartupAll(tconn);
642 printf("bos: failed to startup servers (%s)\n", em(code));
645 for(ti = as->parms[1].items; ti; ti=ti->next) {
646 code = BOZO_SetTStatus(tconn, ti->data, BSTAT_NORMAL);
648 printf("bos: failed to start instance %s (%s)\n",
656 struct cmd_syndesc *as; {
657 register struct rx_connection *tconn;
658 register afs_int32 code;
659 register struct cmd_item *ti;
661 tconn = GetConn(as, 0);
662 if (as->parms[2].items) {
663 /* this is really a rebozo command */
664 if (as->parms[1].items) {
665 /* specified specific things to restart, can't do this at the same
667 printf("bos: can't specify both '-bos' and specific servers to restart.\n");
670 /* otherwise do a rebozo */
671 code = BOZO_ReBozo(tconn);
673 printf("bos: failed to restart bosserver (%s)\n", em(code));
676 if (as->parms[1].items == 0) {
677 if (as->parms[3].items) { /* '-all' */
678 code = BOZO_RestartAll(tconn);
679 if (code) printf("bos: failed to restart servers (%s)\n", em(code));
681 printf("bos: To restart all processes please specify '-all'\n");
684 if (as->parms[3].items) {
685 printf("bos: Can't use '-all' along with individual instances\n");
687 for(ti = as->parms[1].items; ti; ti=ti->next) {
688 code = BOZO_Restart(tconn, ti->data);
690 printf("bos: failed to restart instance %s (%s)\n", ti->data,
698 static SetCellName(as)
699 struct cmd_syndesc *as; {
700 register struct rx_connection *tconn;
701 register afs_int32 code;
703 tconn = GetConn(as, 0);
704 code = BOZO_SetCellName(tconn, as->parms[1].items->data);
705 if (code) printf("bos: failed to set cell (%s)\n", em(code));
710 register struct cmd_syndesc *as; {
711 register struct rx_connection *tconn;
712 register afs_int32 code;
713 register struct cmd_item *ti;
714 char name[MAXHOSTCHARS];
716 tconn = GetConn(as, 0);
717 for(ti = as->parms[1].items; ti; ti=ti->next) {
718 if (as->parms[2].items) {
719 if (strlen(ti->data) > MAXHOSTCHARS - 3) {
720 fprintf(stderr, "bos: host name too long\n");
724 strcpy(&name[1],ti->data);
725 strcat((char *)&name, "]");
726 code = BOZO_AddCellHost(tconn, name);
728 code = BOZO_AddCellHost(tconn, ti->data);
730 printf("bos: failed to add host %s (%s)\n", ti->data, em(code));
735 static RemoveHost(as)
736 register struct cmd_syndesc *as; {
737 register struct rx_connection *tconn;
738 register afs_int32 code;
739 register struct cmd_item *ti;
741 tconn = GetConn(as, 0);
742 for(ti=as->parms[1].items; ti; ti=ti->next) {
743 code = BOZO_DeleteCellHost(tconn, ti->data);
745 printf("bos: failed to delete host %s (%s)\n", ti->data, em(code));
751 register struct cmd_syndesc *as; {
752 register struct rx_connection *tconn;
753 register afs_int32 code;
756 register afs_int32 i;
759 tconn = GetConn(as, 0);
760 code = BOZO_GetCellName(tconn, &tp);
762 printf("bos: failed to get cell name (%s)\n", em(code));
765 printf("Cell name is %s\n", tbuffer);
767 code = BOZO_GetCellHost(tconn, i, &tp);
768 if (code == BZDOM) break;
770 printf("bos: failed to get cell host %d (%s)\n", i, em(code));
773 printf(" Host %d is %s\n", i+1, tbuffer);
779 register struct cmd_syndesc *as; {
780 register struct rx_connection *tconn;
781 register afs_int32 code;
782 struct ktc_encryptionKey tkey;
785 char cellBuffer[256];
786 char buf[BUFSIZ], ver[BUFSIZ];
788 tconn = GetConn(as, 1);
789 memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
791 if(as->parms[1].items)
792 strcpy(buf,as->parms[1].items->data);
796 code=des_read_pw_string(buf,sizeof(buf),"input key: ",0);
797 if(code || strlen(buf)==0)
799 fprintf(stderr,"Bad key: \n");
802 code=des_read_pw_string(ver,sizeof(ver),"Retype input key: ",0);
803 if(code || strlen(ver)==0)
805 fprintf(stderr,"Bad key: \n");
808 if (strcmp (ver, buf) != 0) {
809 fprintf (stderr, "\nInput key mismatch\n");
815 temp = atoi(as->parms[2].items->data);
819 strcpy((char *)&tkey, as->parms[1].items->data);
821 strcpy((char *)&tkey, buf);
823 else { /* kerberos key */
824 if (as->parms[ADDPARMOFFSET].items) {
825 strcpy(cellBuffer, as->parms[ADDPARMOFFSET].items->data);
827 /* string to key needs upper-case cell names */
829 /* I don't believe this is true. The string to key function
830 * actually expands the cell name, then LOWER-CASES it. Perhaps it
831 * didn't use to??? */
832 ucstring(cellBuffer, cellBuffer, strlen(cellBuffer));
835 else tcell = (char *) 0; /* no cell specified, use current */
837 ka_StringToKey(as->parms[1].items->data, tcell, &tkey);
839 ka_StringToKey(buf,tcell,&tkey);
841 tconn = GetConn(as, 1);
842 code = BOZO_AddKey(tconn, temp, &tkey);
844 printf("bos: failed to set key %d (%s)\n", temp, em(code));
851 register struct cmd_syndesc *as; {
852 register struct rx_connection *tconn;
853 register afs_int32 code;
855 register struct cmd_item *ti;
857 tconn = GetConn(as, 0);
858 for(ti=as->parms[1].items; ti; ti=ti->next) {
859 temp = atoi(ti->data);
860 code = BOZO_DeleteKey(tconn, temp);
862 printf("bos: failed to delete key %d (%s)\n", temp, em(code));
870 IN register struct cmd_syndesc *as;
872 register struct rx_connection *tconn;
873 register afs_int32 code;
874 struct ktc_encryptionKey tkey;
876 struct bozo_keyInfo keyInfo;
878 register afs_int32 i;
880 tconn = GetConn(as, 1);
883 code = BOZO_ListKeys(tconn, i, &kvno, &tkey, &keyInfo);
886 /* first check if key is returned */
887 if ((!ka_KeyIsZero (&tkey, sizeof(tkey))) && (as->parms[1].items)) {
888 printf ("key %d is '", kvno);
889 ka_PrintBytes (&tkey, sizeof(tkey));
892 if (keyInfo.keyCheckSum == 0) /* shouldn't happen */
893 printf ("key version is %d\n", kvno);
895 printf ("key %d has cksum %u\n", kvno, keyInfo.keyCheckSum);
899 printf("Keys last changed on %s.\n", DateOf(keyInfo.mod_sec));
902 printf("bos: %s error encountered while listing keys\n", em(code));
904 printf("All done.\n");
909 register struct cmd_syndesc *as; {
910 register struct rx_connection *tconn;
911 register afs_int32 code;
913 register struct cmd_item *ti;
916 tconn = GetConn(as, 0);
917 for(ti=as->parms[1].items; ti; ti=ti->next) {
918 code = BOZO_AddSUser(tconn, ti->data);
920 printf("bos: failed to add user '%s' (%s)\n", ti->data, em(code));
927 static RemoveSUser(as)
928 register struct cmd_syndesc *as; {
929 register struct rx_connection *tconn;
930 register struct cmd_item *ti;
931 register afs_int32 code;
935 tconn = GetConn(as, 0);
936 for(ti=as->parms[1].items; ti; ti=ti->next) {
937 code = BOZO_DeleteSUser(tconn, ti->data);
939 printf("bos: failed to delete user '%s', ", ti->data);
941 printf("(no such user)\n");
943 printf("(%s)\n", em(code));
950 #define NPERLINE 10 /* dudes to print per line */
951 static ListSUsers(as)
952 register struct cmd_syndesc *as; {
953 register struct rx_connection *tconn;
955 register afs_int32 code;
958 int lastNL, printGreeting;
960 tconn = GetConn(as, 0);
965 code = BOZO_ListSUsers(tconn, i, &tp);
968 printGreeting = 0; /* delay until after first call succeeds */
969 printf("SUsers are: ");
971 printf("%s ", tbuffer);
972 if ((i % NPERLINE) == NPERLINE-1) {
979 /* a real error code, instead of scanned past end */
980 printf("bos: failed to retrieve super-user list (%s)\n", em(code));
983 if (lastNL == 0) printf("\n");
987 static StatServer(as)
988 register struct cmd_syndesc *as; {
989 register struct rx_connection *tconn;
990 register afs_int32 code;
992 char ibuffer[BOZO_BSSIZE];
996 /* int32p==1 is obsolete, smaller, printout */
997 int32p = (as->parms[2].items != 0? 2 : 0);
999 /* no parms does something pretty different */
1000 if (as->parms[1].items) return IStatServer(as, int32p);
1002 tconn = GetConn(as, 0);
1004 /* for each instance */
1006 code = BOZO_EnumerateInstance(tconn, i, &tp);
1007 if (code == BZDOM) break;
1009 printf("bos: failed to contact host's bosserver (%s).\n",
1013 DoStat(ibuffer, tconn, int32p, (i==0)); /* print status line */
1018 static CreateServer(as)
1019 register struct cmd_syndesc *as; {
1020 register struct rx_connection *tconn;
1021 register afs_int32 code;
1023 register struct cmd_item *ti;
1025 char *type, *name, *notifier=NONOTIFIER;
1027 tconn = GetConn(as, 0);
1028 for(i=0;i<6;i++) parms[i] = "";
1029 for(i=0,ti=as->parms[3].items; (ti && i<6); ti=ti->next,i++) {
1030 parms[i] = ti->data;
1032 name = as->parms[1].items->data;
1033 type = as->parms[2].items->data;
1034 if (ti = as->parms[4].items) {
1035 notifier = ti->data;
1037 code = BOZO_CreateBnode(tconn, type, name, parms[0], parms[1], parms[2],
1038 parms[3], parms[4], notifier);
1040 printf("bos: failed to create new server instance %s of type '%s' (%s)\n",
1041 name, type, em(code));
1046 static DeleteServer(as)
1047 register struct cmd_syndesc *as; {
1048 register struct rx_connection *tconn;
1049 register afs_int32 code;
1050 register struct cmd_item *ti;
1053 tconn = GetConn(as, 0);
1054 for(ti=as->parms[1].items; ti; ti=ti->next) {
1055 code = BOZO_DeleteBnode(tconn, ti->data);
1058 printf("bos: can't delete running instance '%s'\n", ti->data);
1060 printf("bos: failed to delete instance '%s' (%s)\n",
1061 ti->data, em(code));
1067 static StartServer(as)
1068 register struct cmd_syndesc *as; {
1069 register struct rx_connection *tconn;
1070 register afs_int32 code;
1071 register struct cmd_item *ti;
1074 tconn = GetConn(as, 0);
1075 for(ti=as->parms[1].items; ti; ti=ti->next) {
1076 code = BOZO_SetStatus(tconn, ti->data, BSTAT_NORMAL);
1078 printf("bos: failed to start instance '%s' (%s)\n",
1079 ti->data, em(code));
1084 static StopServer(as)
1085 register struct cmd_syndesc *as; {
1086 register struct rx_connection *tconn;
1087 register afs_int32 code;
1088 register struct cmd_item *ti;
1091 tconn = GetConn(as, 0);
1092 for(ti=as->parms[1].items; ti; ti=ti->next) {
1093 code = BOZO_SetStatus(tconn, ti->data, BSTAT_SHUTDOWN);
1095 printf("bos: failed to change stop instance '%s' (%s)\n",
1096 ti->data, em(code));
1098 if (as->parms[8].items) {
1099 code = BOZO_WaitAll(tconn);
1101 printf("bos: can't wait for processes to shutdown (%s)\n",
1107 #define PARMBUFFERSSIZE 32
1109 static DoSalvage(aconn, aparm1, aparm2, aoutName, showlog,parallel,atmpDir,orphans)
1110 struct rx_connection *aconn;
1119 register afs_int32 code;
1122 char tbuffer[BOZO_BSSIZE];
1123 struct bozo_status istatus;
1124 struct rx_call *tcall;
1128 char partName[20]; /* canonical name for partition */
1129 char pbuffer[PARMBUFFERSSIZE];
1130 afs_int32 partNumber;
1131 char *notifier = NONOTIFIER;
1133 /* if a partition was specified, canonicalize the name, since
1134 the salvager has a stupid partition ID parser */
1136 partNumber = volutil_GetPartitionID(aparm1);
1137 if (partNumber < 0) {
1138 printf("bos: could not parse partition ID '%s'\n", aparm1);
1141 tp = volutil_PartitionName(partNumber);
1143 printf("bos: internal error parsing partition ID '%s'\n", aparm1);
1146 strcpy(partName, tp);
1148 else partName[0] = 0;
1150 /* open the file name */
1152 outFile = fopen(aoutName, "w");
1154 printf("bos: can't open specified SalvageLog file '%s'\n",
1158 closeIt = 1; /* close this file later */
1162 closeIt = 0; /* don't close this file later */
1165 for(code=2;code<6;code++) parms[code] = "";
1166 if (!aparm2) aparm2 = "";
1167 /* MUST pass canonical (wire-format) salvager path to bosserver */
1168 strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH, BOZO_BSSIZE);
1170 if ( (strlen(tbuffer) + 1 + strlen(partName) + 1 + strlen(aparm2) + 1) > BOZO_BSSIZE ) {
1171 printf("bos: command line too big\n");
1174 strcat(tbuffer, " ");
1175 strcat(tbuffer, partName);
1176 strcat(tbuffer, " ");
1177 strcat(tbuffer, aparm2);
1179 if ( (strlen(tbuffer) + 4 + strlen(partName) + 1) > BOZO_BSSIZE ) {
1180 printf("bos: command line too big\n");
1183 strcat (tbuffer, " -f ");
1184 strcat (tbuffer, partName);
1187 /* add the parallel option if given */
1188 if (parallel != (char *)0) {
1189 if ( (strlen(tbuffer) + 11 + strlen(parallel) + 1) > BOZO_BSSIZE ) {
1190 printf("bos: command line too big\n");
1193 strcat(tbuffer, " -parallel ");
1194 strcat(tbuffer, parallel);
1197 /* add the tmpdir option if given */
1198 if (atmpDir != (char *)0) {
1199 if ( (strlen(tbuffer) + 9 + strlen(atmpDir) + 1) > BOZO_BSSIZE ) {
1200 printf("bos: command line too big\n");
1203 strcat(tbuffer, " -tmpdir ");
1204 strcat(tbuffer, atmpDir);
1207 /* add the orphans option if given */
1208 if (orphans != (char *)0) {
1209 if ( (strlen(tbuffer) + 10 + strlen(orphans) + 1) > BOZO_BSSIZE ) {
1210 printf("bos: command line too big\n");
1213 strcat(tbuffer, " -orphans ");
1214 strcat(tbuffer, orphans);
1217 if (mrafsParm.Optdebug)
1218 strcat(tbuffer," -debug");
1219 if (mrafsParm.Optnowrite)
1220 strcat(tbuffer," -nowrite");
1221 if (mrafsParm.Optforce)
1222 strcat(tbuffer," -force");
1223 if (mrafsParm.Optoktozap)
1224 strcat(tbuffer," -oktozap");
1225 if (mrafsParm.Optrootfiles)
1226 strcat(tbuffer," -rootfiles");
1227 if (mrafsParm.Optsalvagedirs)
1228 strcat(tbuffer," -salvagedirs");
1229 if (mrafsParm.Optblockreads)
1230 strcat(tbuffer," -blockreads");
1231 if (mrafsParm.OptListResidencies)
1232 strcat(tbuffer," -ListResidencies");
1233 if (mrafsParm.OptSalvageRemote)
1234 strcat(tbuffer," -SalvageRemote");
1235 if (mrafsParm.OptSalvageArchival)
1236 strcat(tbuffer," -SalvageArchival");
1237 if (mrafsParm.OptIgnoreCheck)
1238 strcat(tbuffer," -IgnoreCheck");
1239 if (mrafsParm.OptForceOnLine)
1240 strcat(tbuffer," -ForceOnLine");
1241 if (mrafsParm.OptUseRootDirACL)
1242 strcat(tbuffer," -UseRootDirACL");
1243 if (mrafsParm.OptTraceBadLinkCounts)
1244 strcat(tbuffer," -TraceBadLinkCounts");
1245 if (mrafsParm.OptDontAskFS)
1246 strcat(tbuffer," -DontAskFS");
1247 if (mrafsParm.OptLogLevel) {
1248 sprintf(pbuffer, " -LogLevel %ld", mrafsParm.OptLogLevel);
1249 strcat(tbuffer, pbuffer);
1251 if (mrafsParm.OptRxDebug)
1252 strcat(tbuffer," -rxdebug");
1253 if (mrafsParm.OptResidencies) {
1254 sprintf(pbuffer, " -Residencies %lu", mrafsParm.OptResidencies);
1255 strcat(tbuffer, pbuffer);
1259 parms[1] = "now"; /* when to do it */
1260 code = BOZO_CreateBnode(aconn, "cron", "salvage-tmp", parms[0], parms[1],
1261 parms[2], parms[3], parms[4], notifier);
1262 if (code) goto done;
1263 /* now wait for bnode to disappear */
1267 code = BOZO_GetInstanceInfo(aconn, "salvage-tmp", &tp, &istatus);
1269 printf("bos: waiting for salvage to complete.\n");
1271 if (code != BZNOENT) {
1272 printf("bos: salvage failed (%s)\n", em(code));
1277 /* now print the log file to the output file */
1278 printf("bos: salvage completed\n");
1279 if (aoutName || showlog) {
1280 fprintf(outFile, "SalvageLog:\n");
1281 tcall = rx_NewCall(aconn);
1282 /* MUST pass canonical (wire-format) salvager log path to bosserver */
1283 code = StartBOZO_GetLog(tcall, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH);
1285 rx_EndCall(tcall, code);
1290 code = rx_Read(tcall, &buffer, 1);
1291 if (code != 1) break;
1292 putc(buffer, outFile);
1293 if (buffer == 0) break; /* the end delimeter */
1295 code = rx_EndCall(tcall, 0);
1296 /* fall through into cleanup code */
1300 if (closeIt && outFile) fclose(outFile);
1304 static GetLogCmd(as)
1305 register struct cmd_syndesc *as; {
1306 struct rx_connection *tconn;
1307 register struct rx_call *tcall;
1308 register afs_int32 code;
1312 printf("Fetching log file '%s'...\n", as->parms[1].items->data);
1313 tconn = GetConn(as, 0);
1314 tcall = rx_NewCall(tconn);
1315 code = StartBOZO_GetLog(tcall, as->parms[1].items->data);
1317 rx_EndCall(tcall, code);
1323 code = rx_Read(tcall, &buffer, 1);
1328 if (buffer == 0) break; /* the end delimeter */
1331 code = rx_EndCall(tcall, error);
1332 /* fall through into cleanup code */
1336 com_err("bos", code, "(while reading log)");
1340 static SalvageCmd(as)
1341 struct cmd_syndesc *as; {
1342 register struct rx_connection *tconn;
1343 register afs_int32 code, rc, i;
1345 char tname[BOZO_BSSIZE];
1347 extern struct ubik_client *cstruct;
1348 afs_int32 curGoal, showlog = 0, mrafs = 0;
1354 memset(&mrafsParm, 0, sizeof(mrafsParm));
1356 /* parm 0 is machine name, 1 is partition, 2 is volume, 3 is -all flag */
1357 tconn = GetConn(as, 0);
1359 /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
1360 /* XXX this should really be done some other way, potentially by RPC */
1362 if (code = BOZO_GetInstanceParm(tconn, "fs", 3, &tp) == 0)
1365 /* we can do a volume, a partition or the whole thing, but not mixtures
1367 if (!as->parms[1].items && as->parms[2].items) {
1368 printf("bos: must specify partition to salvage individual volume.\n");
1371 if (as->parms[5].items && as->parms[3].items) {
1372 printf("bos: can not specify both -file and -showlog.\n");
1375 if (as->parms[4].items && (as->parms[1].items || as->parms[2].items)) {
1376 printf("bos: can not specify -all with other flags.\n");
1380 /* get the output file name, if any */
1381 if (as->parms[3].items)
1382 outName = as->parms[3].items->data;
1384 outName = (char *) 0;
1386 if (as->parms[5].items)
1389 /* parallel option */
1390 parallel = (char *) 0;
1391 if (as->parms[6].items)
1392 parallel = as->parms[6].items->data;
1394 /* get the tmpdir filename if any */
1396 if (as->parms[7].items)
1397 tmpDir = as->parms[7].items->data;
1399 /* -orphans option */
1400 orphans = (char *)0;
1401 if (as->parms[8].items) {
1403 printf("Can't specify -orphans for MR-AFS fileserver\n");
1406 orphans = as->parms[8].items->data;
1410 if (as->parms[MRAFS_OFFSET].items)
1411 mrafsParm.Optdebug = 1;
1412 if (as->parms[MRAFS_OFFSET + 1].items)
1413 mrafsParm.Optnowrite = 1;
1414 if (as->parms[MRAFS_OFFSET + 2].items)
1415 mrafsParm.Optforce = 1;
1416 if (as->parms[MRAFS_OFFSET + 3].items)
1417 mrafsParm.Optoktozap = 1;
1418 if (as->parms[MRAFS_OFFSET + 4].items)
1419 mrafsParm.Optrootfiles = 1;
1420 if (as->parms[MRAFS_OFFSET + 5].items)
1421 mrafsParm.Optsalvagedirs = 1;
1422 if (as->parms[MRAFS_OFFSET + 6].items)
1423 mrafsParm.Optblockreads = 1;
1424 if (as->parms[MRAFS_OFFSET + 7].items)
1425 mrafsParm.OptListResidencies = 1;
1426 if (as->parms[MRAFS_OFFSET + 8].items)
1427 mrafsParm.OptSalvageRemote = 1;
1428 if (as->parms[MRAFS_OFFSET + 9].items)
1429 mrafsParm.OptSalvageArchival = 1;
1430 if (as->parms[MRAFS_OFFSET + 10].items)
1431 mrafsParm.OptIgnoreCheck = 1;
1432 if (as->parms[MRAFS_OFFSET + 11].items)
1433 mrafsParm.OptForceOnLine = 1;
1434 if (as->parms[MRAFS_OFFSET + 12].items)
1435 mrafsParm.OptUseRootDirACL = 1;
1436 if (as->parms[MRAFS_OFFSET + 13].items)
1437 mrafsParm.OptTraceBadLinkCounts = 1;
1438 if (as->parms[MRAFS_OFFSET + 14].items)
1439 mrafsParm.OptDontAskFS = 1;
1440 if (as->parms[MRAFS_OFFSET + 15].items)
1441 mrafsParm.OptLogLevel = atoi(as->parms[MRAFS_OFFSET + 15].items->data);
1442 if (as->parms[MRAFS_OFFSET + 16].items)
1443 mrafsParm.OptRxDebug = 1;
1444 if (as->parms[MRAFS_OFFSET + 17].items) {
1445 if (as->parms[MRAFS_OFFSET + 8].items ||
1446 as->parms[MRAFS_OFFSET + 9].items) {
1447 printf("Can't specify -Residencies with -SalvageRemote or -SalvageArchival\n");
1450 code = GetUInt32(as->parms[MRAFS_OFFSET + 17].items->data,
1451 &mrafsParm.OptResidencies);
1453 printf("bos: '%s' is not a valid residency mask.\n",
1454 as->parms[MRAFS_OFFSET + 13].items->data);
1461 for (i = 9; i < ADDPARMOFFSET; i++) {
1462 if (as->parms[i].items) {
1463 printf(" %s only possible for MR-AFS fileserver.\n",
1471 if (as->parms[4].items) {
1472 /* salvage whole enchilada */
1473 curGoal = GetServerGoal(tconn, "fs");
1474 if (curGoal == BSTAT_NORMAL) {
1475 printf("bos: shutting down fs.\n");
1476 code = BOZO_SetTStatus(tconn, "fs", BSTAT_SHUTDOWN);
1478 printf("bos: failed to stop 'fs' (%s)\n", em(code));
1481 code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1483 printf("bos: failed to wait for file server shutdown, continuing.\n");
1485 /* now do the salvage operation */
1486 printf("Starting salvage.\n");
1487 rc = DoSalvage(tconn, (char *) 0, (char *) 0, outName, showlog,parallel,tmpDir,orphans);
1488 if (rc) printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1489 if (curGoal == BSTAT_NORMAL) {
1490 printf("bos: restarting fs.\n");
1491 code = BOZO_SetTStatus(tconn, "fs", BSTAT_NORMAL);
1493 printf("bos: failed to restart 'fs' (%s)\n", em(code));
1499 else if (!as->parms[2].items) {
1500 if (!as->parms[1].items) {
1501 printf("bos: must specify -all switch to salvage all partitions.\n");
1504 if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1505 /* can't parse volume ID, so complain before shutting down
1508 printf("bos: can't interpret %s as partition ID.\n",
1509 as->parms[1].items->data);
1512 curGoal = GetServerGoal(tconn, "fs");
1513 /* salvage a whole partition (specified by parms[1]) */
1514 if (curGoal == BSTAT_NORMAL) {
1515 printf("bos: shutting down fs.\n");
1516 code = BOZO_SetTStatus(tconn, "fs", BSTAT_SHUTDOWN);
1518 printf("bos: can't stop 'fs' (%s)\n", em(code));
1521 code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1523 printf("bos: failed to wait for file server shutdown, continuing.\n");
1525 /* now do the salvage operation */
1526 printf("Starting salvage.\n");
1527 rc = DoSalvage(tconn, as->parms[1].items->data, (char *) 0,
1528 outName, showlog,parallel,tmpDir,orphans);
1529 if (rc) printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1530 if (curGoal == BSTAT_NORMAL) {
1531 printf("bos: restarting fs.\n");
1532 code = BOZO_SetTStatus(tconn, "fs", BSTAT_NORMAL);
1534 printf("bos: failed to restart 'fs' (%s)\n", em(code));
1541 /* salvage individual volume (don't shutdown fs first), just use
1542 * single-shot cron bnode. Must leave server running when using this
1543 * option, since salvager will ask file server for the volume */
1546 const char *confdir;
1549 if (as->parms[ADDPARMOFFSET].items)
1550 tmpname = as->parms[ADDPARMOFFSET].items->data;
1551 else tmpname = (char *) 0;
1553 localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
1554 confdir = (localauth ? AFSDIR_SERVER_ETC_DIRPATH : AFSDIR_CLIENT_ETC_DIRPATH);
1555 code = vsu_ClientInit(/* noauth */ 1, confdir, tmpname,
1556 /* server auth */ 0, &cstruct, (int (*)()) 0);
1558 newID = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1560 printf("bos: can't interpret %s as volume name or ID\n", as->parms[2].items->data);
1563 sprintf(tname, "%u", newID);
1566 printf("bos: can't initialize volume system client (code %d), trying anyway.\n",
1567 as->parms[2].items->data, code);
1568 strncpy(tname, as->parms[2].items->data, sizeof(tname));
1570 if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1571 /* can't parse volume ID, so complain before shutting down
1574 printf("bos: can't interpret %s as partition ID.\n",
1575 as->parms[1].items->data);
1578 printf("Starting salvage.\n");
1579 rc = DoSalvage(tconn, as->parms[1].items->data, tname, outName,
1580 showlog,parallel,tmpDir,orphans);
1582 printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1589 static IStatServer(as, int32p)
1591 register struct cmd_syndesc *as; {
1592 register struct rx_connection *tconn;
1593 register struct cmd_item *ti;
1596 tconn = GetConn(as, 0);
1597 for (ti=as->parms[1].items; ti; ti=ti->next) {
1598 DoStat(ti->data, tconn, int32p, firstTime);
1604 static DoStat (aname, aconn, aint32p, firstTime)
1606 IN register struct rx_connection *aconn;
1608 IN int firstTime; /* true iff first instance in cmd */
1612 register afs_int32 code;
1613 register afs_int32 i;
1614 struct bozo_status istatus;
1616 char *is1, *is2, *is3, *is4; /* instance strings */
1619 code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
1621 printf("bos: failed to get instance info for '%s' (%s)\n",
1625 if (firstTime && aint32p && (istatus.flags & BOZO_BADDIRACCESS))
1626 printf ("Bosserver reports inappropriate access on server directories\n");
1627 printf("Instance %s, ", aname);
1628 if (aint32p) printf("(type is %s) ", buffer);
1629 if (istatus.fileGoal == istatus.goal) {
1630 if (!istatus.goal) printf("disabled, ");
1633 if (istatus.fileGoal) printf("temporarily disabled, ");
1634 else printf("temporarily enabled, ");
1637 if (istatus.flags & BOZO_ERRORSTOP)
1638 printf("stopped for too many errors, ");
1639 if (istatus.flags & BOZO_HASCORE)
1640 printf("has core file, ");
1643 code = BOZO_GetStatus(aconn, aname, &temp, &tp);
1645 printf("bos: failed to get status for instance '%s' (%s)\n",
1648 printf("currently ", aname);
1649 if (temp == BSTAT_NORMAL) printf("running normally.\n");
1650 else if (temp == BSTAT_SHUTDOWN) printf("shutdown.\n");
1651 else if (temp == BSTAT_STARTINGUP) printf("starting up.\n");
1652 else if (temp == BSTAT_SHUTTINGDOWN) printf("shutting down.\n");
1653 if (buffer[0] != 0) {
1654 printf(" Auxiliary status is: %s.\n", buffer);
1658 /* are we done yet? */
1659 if (!aint32p) return 0;
1661 if (istatus.procStartTime)
1662 printf(" Process last started at %s (%d proc starts)\n",
1663 DateOf(istatus.procStartTime), istatus.procStarts);
1664 if (istatus.lastAnyExit) {
1665 printf(" Last exit at %s\n", DateOf(istatus.lastAnyExit));
1667 if (istatus.lastErrorExit) {
1668 is1 = is2 = is3 = is4 = (char *) 0;
1669 printf(" Last error exit at %s, ", DateOf(istatus.lastErrorExit));
1670 code = BOZO_GetInstanceStrings(aconn, aname, &is1, &is2, &is3, &is4);
1671 /* don't complain about failing call, since could simply mean
1672 * interface mismatch.
1676 /* non-null instance string */
1677 printf("by %s, ", is1);
1684 if (istatus.errorSignal) {
1685 if (istatus.errorSignal == SIGTERM)
1686 printf("due to shutdown request\n");
1688 printf("due to signal %d\n", istatus.errorSignal);
1691 printf("by exiting with code %d\n", istatus.errorCode);
1695 /* try to display all the parms */
1698 code = BOZO_GetInstanceParm(aconn, aname, i, &tp);
1700 printf(" Command %d is '%s'\n", i+1, buffer);
1703 code = BOZO_GetInstanceParm(aconn, aname, 999, &tp);
1705 /* Any type of failure is treated as not having a notifier program */
1706 printf(" Notifier is '%s'\n", buffer);
1713 #ifdef BOS_RESTRICTED_MODE
1714 static GetRestrict(as)
1715 struct cmd_syndesc *as; {
1716 register struct rx_connection *tconn;
1717 afs_int32 code, val;
1719 tconn = GetConn(as, 0);
1720 code = BOZO_GetRestrictedMode(tconn, &val);
1721 if (code) printf("bos: failed to get restricted mode (%s)\n", em(code));
1722 else printf("Restricted mode is %s\n", val ? "on" : "off");
1727 static SetRestrict(as)
1728 struct cmd_syndesc *as; {
1729 register struct rx_connection *tconn;
1730 afs_int32 code, val;
1732 tconn = GetConn(as, 0);
1733 util_GetInt32(as->parms[1].items->data, &val);
1734 code = BOZO_SetRestrictedMode(tconn, val);
1735 if (code) printf("bos: failed to set restricted mode (%s)\n", em(code));
1740 static void add_std_args (ts)
1741 register struct cmd_syndesc *ts;
1743 cmd_Seek(ts, ADDPARMOFFSET);
1744 /* + 0 */ cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1745 /* + 1 */ cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1746 "don't authenticate");
1747 /* + 2 */ cmd_AddParm (ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1748 "create tickets from KeyFile");
1751 #include "AFS_component_version_number.c"
1757 register afs_int32 code;
1758 register struct cmd_syndesc *ts;
1759 extern int afsconf_SawCell;
1761 #ifdef AFS_AIX32_ENV
1763 * The following signal action for AIX is necessary so that in case of a
1764 * crash (i.e. core is generated) we can include the user's data section
1765 * in the core dump. Unfortunately, by default, only a partial core is
1766 * generated which, in many cases, isn't too useful.
1768 struct sigaction nsa;
1770 sigemptyset(&nsa.sa_mask);
1771 nsa.sa_handler = SIG_DFL;
1772 nsa.sa_flags = SA_FULLDUMP;
1773 sigaction(SIGSEGV, &nsa, NULL);
1774 sigaction(SIGABRT, &nsa, NULL);
1780 printf("bos: could not initialize rx (%s)\n", em(code));
1784 /* To resolve a AFSCELL environment "Note: ..." problem: Because bos calls ka_Init (why?) before any
1785 * checkup on the existance of a "-cell" option on the particular bos command we don't print the
1786 * message if a cell is passed in. Luckily the rest of the programs don't call these adhoc routines
1787 * and things work fine. Note that if the "-cell" isn't passed then we're still ok since later on
1788 * the proper routine (afsconf_GetCellInfo) is going to be called to do the right thing.
1790 afsconf_SawCell = 1; /* Means don't print warning if AFSCELL is set */
1792 afsconf_SawCell = 0; /* Reset it */
1793 /* don't check error code, since fails sometimes when we're setting up a
1795 initialize_CMD_error_table();
1796 initialize_BZ_error_table();
1798 ts = cmd_CreateSyntax("start", StartServer, 0, "start running a server");
1799 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1800 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1803 ts = cmd_CreateSyntax("stop", StopServer, 0, "halt a server instance");
1804 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1805 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1807 cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1808 "wait for process to stop");
1811 ts = cmd_CreateSyntax("status", StatServer, 0,
1812 "show server instance status");
1813 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1814 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL,
1815 "server process name");
1816 cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "long status");
1819 ts = cmd_CreateSyntax("shutdown", Shutdown, 0, "shutdown all processes");
1820 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1821 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1823 cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1824 "wait for process to stop");
1827 ts = cmd_CreateSyntax("startup", Startup, 0, "start all processes");
1828 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1829 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1832 ts = cmd_CreateSyntax("restart", Restart, 0, "restart all processes");
1833 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1834 cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1835 cmd_AddParm(ts, "-bosserver", CMD_FLAG, CMD_OPTIONAL, "restart bosserver");
1836 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "restart all processes");
1841 ts = cmd_CreateSyntax("create", CreateServer, 0,
1842 "create a new server instance");
1843 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1844 cmd_AddParm(ts, "-instance", CMD_SINGLE, 0, "server process name");
1845 cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "server type");
1846 cmd_AddParm(ts, "-cmd", CMD_LIST, 0, "command lines");
1847 cmd_AddParm(ts, "-notifier", CMD_SINGLE, CMD_OPTIONAL, "Notifier program");
1850 ts = cmd_CreateSyntax("delete", DeleteServer, 0,
1851 "delete a server instance");
1852 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1853 cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1856 ts = cmd_CreateSyntax("adduser", AddSUser, 0,
1857 "add users to super-user list");
1858 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1859 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
1862 ts = cmd_CreateSyntax("removeuser", RemoveSUser, 0,
1863 "remove users from super-user list");
1864 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1865 cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
1868 ts = cmd_CreateSyntax("listusers", ListSUsers, 0, "list super-users");
1869 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1872 ts = cmd_CreateSyntax("addkey", AddKey, 0,
1873 "add keys to key dbase (kvno 999 is bcrypt)");
1874 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1875 cmd_AddParm(ts, "-key", CMD_SINGLE, CMD_OPTIONAL, "key");
1876 cmd_AddParm(ts, "-kvno", CMD_SINGLE, 0, "key version number");
1879 ts = cmd_CreateSyntax("removekey", RemoveKey, 0,
1880 "remove keys from key dbase");
1881 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1882 cmd_AddParm(ts, "-kvno", CMD_LIST, 0, "key version number");
1885 ts = cmd_CreateSyntax("listkeys", ListKeys, 0, "list keys");
1886 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1887 cmd_AddParm(ts, "-showkey", CMD_FLAG, CMD_OPTIONAL, "show the actual key rather than the checksum");
1890 ts = cmd_CreateSyntax("listhosts", ListHosts, 0, "get cell host list");
1891 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1893 cmd_CreateAlias(ts, "getcell");
1895 ts = cmd_CreateSyntax("setcellname", SetCellName, 0, "set cell name");
1896 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1897 cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
1900 ts = cmd_CreateSyntax("addhost", AddHost, 0, "add host to cell dbase");
1901 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1902 cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
1903 cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL, "vote doesn't count");
1906 ts = cmd_CreateSyntax("removehost", RemoveHost, 0,
1907 "remove host from cell dbase");
1908 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1909 cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
1912 ts = cmd_CreateSyntax("setauth", SetAuth, 0,
1913 "set authentication required flag");
1914 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1915 cmd_AddParm(ts, "-authrequired", CMD_SINGLE,
1916 0, "on or off: authentication required for admin requests");
1919 ts = cmd_CreateSyntax("install", Install, 0, "install program");
1920 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1921 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to install");
1922 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1925 ts = cmd_CreateSyntax("uninstall", UnInstall, 0, "uninstall program");
1926 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1927 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to uninstall");
1928 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1931 ts = cmd_CreateSyntax("getlog", GetLogCmd, 0, "examine log file");
1932 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1933 cmd_AddParm(ts, "-file", CMD_SINGLE, 0, "log file to examine");
1936 ts = cmd_CreateSyntax("getdate", GetDate, 0, "get dates for programs");
1937 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1938 cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to check");
1939 cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1942 ts = cmd_CreateSyntax("exec", Exec, 0, "execute shell command on server");
1943 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1944 cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "command to execute");
1947 ts = cmd_CreateSyntax("prune", Prune, 0, "prune server files");
1948 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1949 cmd_AddParm(ts, "-bak", CMD_FLAG, CMD_OPTIONAL, "delete .BAK files");
1950 cmd_AddParm(ts, "-old", CMD_FLAG, CMD_OPTIONAL, "delete .OLD files");
1951 cmd_AddParm(ts, "-core", CMD_FLAG, CMD_OPTIONAL, "delete core files");
1952 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "delete all junk files");
1955 ts = cmd_CreateSyntax("setrestart", SetRestartCmd, 0, "set restart times");
1956 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
1957 cmd_AddParm(ts, "-time", CMD_SINGLE,
1958 CMD_REQUIRED, "time to restart server");
1959 cmd_AddParm(ts, "-general", CMD_FLAG,
1960 CMD_OPTIONAL, "set general restart time");
1961 cmd_AddParm(ts, "-newbinary", CMD_FLAG,
1962 CMD_OPTIONAL, "set new binary restart time");
1965 ts = cmd_CreateSyntax("getrestart", GetRestartCmd, 0, "get restart times");
1966 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
1969 ts = cmd_CreateSyntax("salvage", SalvageCmd, 0,
1970 "salvage partition or volumes");
1971 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1972 cmd_AddParm(ts, "-partition", CMD_SINGLE,
1973 CMD_OPTIONAL, "salvage partition");
1974 cmd_AddParm(ts, "-volume", CMD_SINGLE,
1975 CMD_OPTIONAL, "salvage volume number or volume name");
1976 cmd_AddParm(ts, "-file", CMD_SINGLE,
1977 CMD_OPTIONAL, "salvage log output file");
1978 cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "salvage whole server");
1979 cmd_AddParm(ts, "-showlog", CMD_FLAG, CMD_OPTIONAL, "display salvage log");
1980 cmd_AddParm(ts, "-parallel",CMD_SINGLE, CMD_OPTIONAL,
1981 "# of max parallel partition salvaging");
1982 cmd_AddParm(ts, "-tmpdir",CMD_SINGLE, CMD_OPTIONAL,
1983 "directory to place tmp files");
1984 cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL,
1985 "ignore | remove | attach");
1986 cmd_AddParm(ts, "-debug", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Run in Debugging mode");
1987 cmd_AddParm(ts, "-nowrite", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Run readonly/test mode");
1988 cmd_AddParm(ts, "-force", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force full salvaging");
1989 cmd_AddParm(ts, "-oktozap", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Give permission to destroy bogus file residencies/volumes - debugging flag");
1990 cmd_AddParm(ts, "-rootfiles", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Show files owned by root - debugging flag");
1991 cmd_AddParm(ts, "-salvagedirs", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force rebuild/salvage of all directories");
1992 cmd_AddParm(ts, "-blockreads", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Read smaller blocks to handle IO/bad blocks");
1993 cmd_AddParm(ts, "-ListResidencies", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Just list affected file residencies - debugging flag");
1994 cmd_AddParm(ts, "-SalvageRemote", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Salvage storage systems that are not directly attached");
1995 cmd_AddParm(ts, "-SalvageArchival", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Salvage HSM storage systems");
1996 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.");
1997 cmd_AddParm(ts, "-ForceOnLine", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force the volume to come online, even if it hasn't salvaged cleanly.");
1998 cmd_AddParm(ts, "-UseRootDirACL", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Use the root directory ACL for lost+found directory if it is created.");
1999 cmd_AddParm(ts, "-TraceBadLinkCounts", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Print out lines about volume reference count changes.");
2000 cmd_AddParm(ts, "-DontAskFS", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Don't ask fileserver to take volume offline. THIS IS VERY DANGEROUS.");
2001 cmd_AddParm(ts, "-LogLevel", CMD_SINGLE, CMD_OPTIONAL, "(MR-AFS) log level");
2002 cmd_AddParm(ts, "-rxdebug", CMD_FLAG, CMD_OPTIONAL, "(MR-AFS) Write out rx debug information.");
2003 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");
2006 ts = cmd_CreateSyntax("blockscanner", BlockScannerCmd, 0,
2007 "block scanner daemon from making migration requests");
2008 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2011 ts = cmd_CreateSyntax("unblockscanner", UnBlockScannerCmd, 0,
2012 "allow scanner daemon to make migration requests again");
2013 cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2016 #ifdef BOS_RESTRICTED_MODE
2017 ts = cmd_CreateSyntax("getrestricted", GetRestrict, 0, "get restrict mode");
2018 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2021 ts = cmd_CreateSyntax("setrestricted", SetRestrict, 0, "set restrict mode");
2022 cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2023 cmd_AddParm(ts, "-mode", CMD_SINGLE, 0, "mode to set");
2028 code = cmd_Dispatch(argc, argv);