Move string manipulation functions out of util
[openafs.git] / src / bozo / bos.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
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
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12 #include <afs/stds.h>
13
14 #include <afs/procmgmt.h>
15 #include <roken.h>
16 #include <afs/opr.h>
17
18 #include <hcrypto/ui.h>
19
20 #include "bnode.h"
21 #include <afs/afsutil.h>
22 #include <afs/cellconfig.h>
23 #include <rx/rx.h>
24 #include <sys/stat.h>
25 #include <rx/xdr.h>
26 #include <afs/auth.h>
27 #include <afs/cellconfig.h>
28 #include <afs/cmd.h>
29 #include <afs/com_err.h>
30 #include <ubik.h>
31 #include <afs/ktime.h>
32 #include <afs/kautils.h>
33 #include <afs/volser.h>
34
35 static int IStatServer(struct cmd_syndesc *as, int int32p);
36 static int DoStat(char *aname, struct rx_connection *aconn,
37                   int aint32p, int firstTime);
38
39 #include "bosint.h"
40 #include "bosprototypes.h"
41
42 /* command offsets for bos salvage command */
43 #define MRAFS_OFFSET  10
44 #define ADDPARMOFFSET 27
45
46 /* MR-AFS salvage parameters */
47 struct MRAFSSalvageParms {
48     afs_int32 Optdebug;
49     afs_int32 Optnowrite;
50     afs_int32 Optforce;
51     afs_int32 Optoktozap;
52     afs_int32 Optrootfiles;
53     afs_int32 Optsalvagedirs;
54     afs_int32 Optblockreads;
55     afs_int32 OptListResidencies;
56     afs_int32 OptSalvageRemote;
57     afs_int32 OptSalvageArchival;
58     afs_int32 OptIgnoreCheck;
59     afs_int32 OptForceOnLine;
60     afs_int32 OptUseRootDirACL;
61     afs_int32 OptTraceBadLinkCounts;
62     afs_int32 OptDontAskFS;
63     afs_int32 OptLogLevel;
64     afs_int32 OptRxDebug;
65     afs_uint32 OptResidencies;
66 };
67
68 /* dummy routine for the audit work.  It should do nothing since audits */
69 /* occur at the server level and bos is not a server. */
70 int osi_audit(void )
71 {
72     return 0;
73 }
74
75 /* keep those lines small */
76 static char *
77 em(afs_int32 acode)
78 {
79     if (acode == -1)
80         return "communications failure (-1)";
81     else if (acode == -3)
82         return "communications timeout (-3)";
83     else
84         return (char *)afs_error_message(acode);
85 }
86
87 /* get partition id from a name */
88 /* XXX - unused code - could be removed? */
89 #if 0
90 static afs_int32
91 GetPartitionID(char *aname)
92 {
93     char tc;
94     char ascii[3];
95
96     tc = *aname;
97     if (tc == 0)
98         return -1;              /* unknown */
99     /* numbers go straight through */
100     if (tc >= '0' && tc <= '9') {
101         return atoi(aname);
102     }
103     /* otherwise check for vicepa or /vicepa, or just plain "a" */
104     ascii[2] = 0;
105     if (strlen(aname) <= 2) {
106         strcpy(ascii, aname);
107     } else if (!strncmp(aname, "/vicep", 6)) {
108         strncpy(ascii, aname + 6, 2);
109     } else if (!strncmp(aname, "vicep", 5)) {
110         strncpy(ascii, aname + 5, 2);
111     } else
112         return -1;              /* bad partition name */
113     /* now partitions are named /vicepa ... /vicepz, /vicepaa, /vicepab,
114      * .../vicepzz, and are numbered from 0.  Do the appropriate conversion */
115     if (ascii[1] == 0) {
116         /* one char name, 0..25 */
117         if (ascii[0] < 'a' || ascii[0] > 'z')
118             return -1;          /* wrongo */
119         return ascii[0] - 'a';
120     } else {
121         /* two char name, 26 .. <whatever> */
122         if (ascii[0] < 'a' || ascii[0] > 'z')
123             return -1;          /* wrongo */
124         if (ascii[1] < 'a' || ascii[1] > 'z')
125             return -1;          /* just as bad */
126         return (ascii[0] - 'a') * 26 + (ascii[1] - 'a') + 26;
127     }
128 }
129 #endif
130
131 /* make ctime easier to use */
132 static char *
133 DateOf(afs_int32 atime)
134 {
135     static char tbuffer[30];
136     char *tp;
137     time_t t = (time_t) atime;
138     tp = ctime(&t);
139     if (tp) {
140         strcpy(tbuffer, tp);
141         tbuffer[24] = 0;        /* get rid of new line */
142     } else
143         strcpy(tbuffer, "BAD TIME");
144     return tbuffer;
145 }
146
147
148 /* use the syntax descr to get a connection, authenticated appropriately.
149  * aencrypt is set if we want to encrypt the data on the wire.
150  */
151 static struct rx_connection *
152 GetConn(struct cmd_syndesc *as, int aencrypt)
153 {
154     struct hostent *th;
155     char *hostname;
156     char *cellname = NULL;
157     const char *confdir;
158     afs_int32 code;
159     struct rx_connection *tconn;
160     afs_int32 addr;
161     struct afsconf_dir *tdir = NULL;
162     afsconf_secflags secFlags;
163     struct rx_securityClass *sc;
164     afs_int32 scIndex;
165
166     hostname = as->parms[0].items->data;
167     th = hostutil_GetHostByName(hostname);
168     if (!th) {
169         printf("bos: can't find address for host '%s'\n", hostname);
170         exit(1);
171     }
172     memcpy(&addr, th->h_addr, sizeof(afs_int32));
173
174     secFlags = AFSCONF_SECOPTS_FALLBACK_NULL;
175
176     if (as->parms[ADDPARMOFFSET + 2].items) { /* -localauth */
177         secFlags |= AFSCONF_SECOPTS_LOCALAUTH;
178         confdir = AFSDIR_SERVER_ETC_DIRPATH;
179     } else {
180         confdir = AFSDIR_CLIENT_ETC_DIRPATH;
181     }
182
183     if (as->parms[ADDPARMOFFSET + 1].items) { /* -noauth */
184         secFlags |= AFSCONF_SECOPTS_NOAUTH;
185     } else {
186         /* If we're running with -noauth, we don't need a configuration
187          * directory */
188         tdir = afsconf_Open(confdir);
189         if (tdir == NULL) {
190             printf("bos: can't open cell database (%s)\n", confdir);
191             exit(1);
192         }
193     }
194
195     if (as->parms[ADDPARMOFFSET].items) /* -cell */
196         cellname = as->parms[ADDPARMOFFSET].items->data;
197
198     code = afsconf_PickClientSecObj(tdir, secFlags, NULL, cellname,
199                                     &sc, &scIndex, NULL);
200     if (code) {
201         afs_com_err("bos", code, "(configuring connection security)");
202         exit(1);
203     }
204
205     if (scIndex == RX_SECIDX_NULL)
206         fprintf(stderr, "bos: running unauthenticated\n");
207
208     tconn =
209         rx_NewConnection(addr, htons(AFSCONF_NANNYPORT), 1, sc, scIndex);
210     if (!tconn) {
211         fprintf(stderr, "bos: could not create rx connection\n");
212         exit(1);
213     }
214     rxs_Release(sc);
215
216     return tconn;
217 }
218
219 static int
220 SetAuth(struct cmd_syndesc *as, void *arock)
221 {
222     afs_int32 code;
223     struct rx_connection *tconn;
224     afs_int32 flag;
225     char *tp;
226
227     tconn = GetConn(as, 0);
228     tp = as->parms[1].items->data;
229     if (strcmp(tp, "on") == 0)
230         flag = 0;               /* auth req.: noauthflag is false */
231     else if (strcmp(tp, "off") == 0)
232         flag = 1;
233     else {
234         printf
235             ("bos: illegal authentication specifier '%s', must be 'off' or 'on'.\n",
236              tp);
237         return 1;
238     }
239     code = BOZO_SetNoAuthFlag(tconn, flag);
240     if (code)
241         afs_com_err("bos", code, "(failed to set authentication flag)");
242     return 0;
243 }
244
245 /* take a name (e.g. foo/bar, and a dir e.g. /usr/afs/bin, and construct
246  * /usr/afs/bin/bar */
247 static int
248 ComputeDestDir(char *aname, char *adir, char *aresult, afs_int32 alen)
249 {
250     char *tp;
251
252     strcpy(aresult, adir);
253     tp = strrchr(aname, '/');
254     if (!tp) {
255         /* no '/' in name */
256         strcat(aresult, "/");
257         strcat(aresult, aname);
258     } else {
259         /* tp points at the / character */
260         strcat(aresult, tp);
261     }
262     return 0;
263 }
264
265 /* copy data from fd afd to rx call acall */
266 static int
267 CopyBytes(int afd, struct rx_call *acall)
268 {
269     afs_int32 code;
270     afs_int32 len;
271     char tbuffer[256];
272
273     while (1) {
274         len = read(afd, tbuffer, sizeof(tbuffer));
275         if (len < 0)
276             return errno;
277         if (len == 0)
278             return 0;           /* all done */
279         code = rx_Write(acall, tbuffer, len);
280         if (code != len)
281             return -1;
282     }
283 }
284
285 static int
286 Prune(struct cmd_syndesc *as, void *arock)
287 {
288     afs_int32 code;
289     struct rx_connection *tconn;
290     afs_int32 flags;
291
292     tconn = GetConn(as, 0);
293     flags = 0;
294     if (as->parms[1].items)
295         flags |= BOZO_PRUNEBAK;
296     if (as->parms[2].items)
297         flags |= BOZO_PRUNEOLD;
298     if (as->parms[3].items)
299         flags |= BOZO_PRUNECORE;
300     if (as->parms[4].items)
301         flags |= 0xff;
302     code = BOZO_Prune(tconn, flags);
303     if (code)
304         afs_com_err("bos", code, "(failed to prune server files)");
305     return code;
306 }
307
308 static int
309 Exec(struct cmd_syndesc *as, void *arock)
310 {
311     struct rx_connection *tconn;
312     afs_int32 code;
313
314     tconn = GetConn(as, 0);
315     code = BOZO_Exec(tconn, as->parms[1].items->data);
316     if (code)
317         printf("bos: failed to execute command (%s)\n", em(code));
318     return code;
319 }
320
321 static int
322 GetDate(struct cmd_syndesc *as, void *arock)
323 {
324     afs_int32 code;
325     char tbuffer[256];
326     char destDir[256];
327     afs_int32 time, bakTime, oldTime;
328     struct rx_connection *tconn;
329     struct cmd_item *ti;
330
331     tconn = GetConn(as, 0);
332     if (!as->parms[1].items) {
333         printf("bos: no files to check\n");
334         return 1;
335     }
336
337     /* compute dest dir or file; default MUST be canonical form of dir path */
338     if (as->parms[2].items)
339         strcpy(destDir, as->parms[2].items->data);
340     else
341         strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
342
343     for (ti = as->parms[1].items; ti; ti = ti->next) {
344         /* check date for each file */
345         ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
346         code = BOZO_GetDates(tconn, tbuffer, &time, &bakTime, &oldTime);
347         if (code) {
348             printf("bos: failed to check date on %s (%s)\n", ti->data,
349                    em(code));
350             return 1;
351         } else {
352             printf("File %s ", tbuffer);
353             if (time == 0)
354                 printf("does not exist, ");
355             else
356                 printf("dated %s, ", DateOf(time));
357             if (bakTime == 0)
358                 printf("no .BAK file, ");
359             else
360                 printf(".BAK file dated %s, ", DateOf(bakTime));
361             if (oldTime == 0)
362                 printf("no .OLD file.");
363             else
364                 printf(".OLD file dated %s.", DateOf(oldTime));
365             printf("\n");
366         }
367     }
368     return 0;
369 }
370
371 static int
372 UnInstall(struct cmd_syndesc *as, void *arock)
373 {
374     afs_int32 code;
375     char tbuffer[256];
376     char destDir[256];
377     struct cmd_item *ti;
378     struct rx_connection *tconn;
379
380     tconn = GetConn(as, 0);
381     if (!as->parms[1].items) {
382         printf("bos: no files to uninstall\n");
383         return 1;
384     }
385
386     /* compute dest dir or file; default MUST be canonical form of dir path */
387     if (as->parms[2].items)
388         strcpy(destDir, as->parms[2].items->data);
389     else
390         strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
391
392     for (ti = as->parms[1].items; ti; ti = ti->next) {
393         /* uninstall each file */
394         ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
395         code = BOZO_UnInstall(tconn, tbuffer);
396         if (code) {
397             printf("bos: failed to uninstall %s (%s)\n", ti->data, em(code));
398             return 1;
399         } else
400             printf("bos: uninstalled file %s\n", ti->data);
401     }
402     return 0;
403 }
404
405 static afs_int32
406 GetServerGoal(struct rx_connection *aconn, char *aname)
407 {
408     char buffer[500];
409     char *tp;
410     afs_int32 code;
411     struct bozo_status istatus;
412
413     tp = buffer;
414     code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
415     if (code) {
416         printf("bos: failed to get instance info for '%s' (%s)\n", aname,
417                em(code));
418         /* if we can't get the answer, assume its running */
419         return BSTAT_NORMAL;
420     }
421     if (istatus.goal == 0)
422         return BSTAT_SHUTDOWN;
423     else
424         return BSTAT_NORMAL;
425 }
426
427 static int
428 Install(struct cmd_syndesc *as, void *arock)
429 {
430     struct rx_connection *tconn;
431     afs_int32 code;
432     struct cmd_item *ti;
433     struct stat tstat;
434     char tbuffer[256];
435     int fd;
436     struct rx_call *tcall;
437     char destDir[256];
438
439     tconn = GetConn(as, 0);
440     if (!as->parms[1].items) {
441         printf("bos: no files to install\n");
442         return 1;
443     }
444
445     /* compute dest dir or file; default MUST be canonical form of dir path */
446     if (as->parms[2].items)
447         strcpy(destDir, as->parms[2].items->data);
448     else
449         strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
450
451     for (ti = as->parms[1].items; ti; ti = ti->next) {
452         /* install each file */
453         fd = open(ti->data, O_RDONLY);
454         if (fd < 0) {
455             /* better to quit on error than continue for install command */
456             printf("bos: can't find file '%s', quitting\n", ti->data);
457             return 1;
458         }
459         code = fstat(fd, &tstat);
460         if (code) {
461             printf("bos: failed to stat file %s, errno is %d\n", ti->data,
462                    errno);
463             return 1;
464         }
465         /* compute destination dir */
466         ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
467         tcall = rx_NewCall(tconn);
468         code =
469             StartBOZO_Install(tcall, tbuffer, tstat.st_size,
470                               (afs_int32) tstat.st_mode, tstat.st_mtime);
471         if (code == 0) {
472             code = CopyBytes(fd, tcall);
473         }
474         code = rx_EndCall(tcall, code);
475         if (code) {
476             printf("bos: failed to install %s (%s)\n", ti->data, em(code));
477             return 1;
478         } else
479             printf("bos: installed file %s\n", ti->data);
480     }
481     return 0;
482 }
483
484 static int
485 Shutdown(struct cmd_syndesc *as, void *arock)
486 {
487     struct rx_connection *tconn;
488     afs_int32 code;
489     struct cmd_item *ti;
490
491     tconn = GetConn(as, 0);
492     if (as->parms[1].items == 0) {
493         code = BOZO_ShutdownAll(tconn);
494         if (code)
495             printf("bos: failed to shutdown servers (%s)\n", em(code));
496     } else {
497         for (ti = as->parms[1].items; ti; ti = ti->next) {
498             code = BOZO_SetTStatus(tconn, ti->data, BSTAT_SHUTDOWN);
499             if (code)
500                 printf("bos: failed to shutdown instance %s (%s)\n", ti->data,
501                        em(code));
502         }
503     }
504     if (as->parms[8].items) {
505         code = BOZO_WaitAll(tconn);
506         if (code)
507             printf("bos: can't wait for processes to shutdown (%s)\n",
508                    em(code));
509     }
510     return 0;
511 }
512
513 static int
514 BlockScannerCmd(struct cmd_syndesc *as, void *arock)
515 {
516     afs_int32 code;
517     struct rx_connection *tconn;
518     char BlockCommand[] = "/usr/afs/bin/scanner -block";
519
520     tconn = GetConn(as, 0);
521     code = BOZO_Exec(tconn, BlockCommand);
522     if (code)
523         printf
524             ("bos: failed to block scanner from making migration requests (%s)\n",
525              em(code));
526     return 0;
527 }
528
529 static int
530 UnBlockScannerCmd(struct cmd_syndesc *as, void *arock)
531 {
532     afs_int32 code;
533     struct rx_connection *tconn;
534     char UnBlockCommand[] = "/usr/afs/bin/scanner -unblock";
535
536     tconn = GetConn(as, 0);
537     code = BOZO_Exec(tconn, UnBlockCommand);
538     if (code)
539         printf
540             ("bos: failed to allow scanner daemon to make migration requests again (%s)\n",
541              em(code));
542     return 0;
543 }
544
545 static int
546 GetRestartCmd(struct cmd_syndesc *as, void *arock)
547 {
548     afs_int32 code;
549     struct ktime generalTime, newBinaryTime;
550     char messageBuffer[256];
551     struct rx_connection *tconn;
552     char *hostp;
553
554     hostp = as->parms[0].items->data;   /* host name for messages */
555     tconn = GetConn(as, 0);
556
557     code = BOZO_GetRestartTime(tconn, 1, (struct bozo_netKTime *) &generalTime);
558     if (code) {
559         printf("bos: failed to retrieve restart information (%s)\n",
560                em(code));
561         return code;
562     }
563     code = BOZO_GetRestartTime(tconn, 2, (struct bozo_netKTime *) &newBinaryTime);
564     if (code) {
565         printf("bos: failed to retrieve restart information (%s)\n",
566                em(code));
567         return code;
568     }
569
570     code = ktime_DisplayString(&generalTime, messageBuffer);
571     if (code) {
572         printf("bos: failed to decode restart time (%s)\n", em(code));
573         return code;
574     }
575     printf("Server %s restarts %s\n", hostp, messageBuffer);
576
577     code = ktime_DisplayString(&newBinaryTime, messageBuffer);
578     if (code) {
579         printf("bos: failed to decode restart time (%s)\n", em(code));
580         return code;
581     }
582     printf("Server %s restarts for new binaries %s\n", hostp, messageBuffer);
583
584     /* all done now */
585     return 0;
586 }
587
588 static int
589 SetRestartCmd(struct cmd_syndesc *as, void *arock)
590 {
591     afs_int32 count = 0;
592     afs_int32 code;
593     struct ktime restartTime;
594     afs_int32 type = 0 ;
595     struct rx_connection *tconn;
596
597     count = 0;
598     tconn = GetConn(as, 0);
599     if (as->parms[2].items) {
600         count++;
601         type = 1;
602     }
603     if (as->parms[3].items) {
604         count++;
605         type = 2;
606     }
607     if (count > 1) {
608         printf("bos: can't specify more than one restart time at a time\n");
609         return -1;
610     }
611     if (count == 0)
612         type = 1;               /* by default set general restart time */
613
614     if ((code = ktime_ParsePeriodic(as->parms[1].items->data, &restartTime))) {
615         printf("bos: failed to parse '%s' as periodic restart time(%s)\n",
616                as->parms[1].items->data, em(code));
617         return code;
618     }
619
620     code = BOZO_SetRestartTime(tconn, type, (struct bozo_netKTime *) &restartTime);
621     if (code) {
622         printf("bos: failed to set restart time at server (%s)\n", em(code));
623         return code;
624     }
625     return 0;
626 }
627
628 static int
629 Startup(struct cmd_syndesc *as, void *arock)
630 {
631     struct rx_connection *tconn;
632     afs_int32 code;
633     struct cmd_item *ti;
634
635     tconn = GetConn(as, 0);
636     if (as->parms[1].items == 0) {
637         code = BOZO_StartupAll(tconn);
638         if (code)
639             printf("bos: failed to startup servers (%s)\n", em(code));
640     } else {
641         for (ti = as->parms[1].items; ti; ti = ti->next) {
642             code = BOZO_SetTStatus(tconn, ti->data, BSTAT_NORMAL);
643             if (code)
644                 printf("bos: failed to start instance %s (%s)\n", ti->data,
645                        em(code));
646         }
647     }
648     return 0;
649 }
650
651 static int
652 Restart(struct cmd_syndesc *as, void *arock)
653 {
654     struct rx_connection *tconn;
655     afs_int32 code;
656     struct cmd_item *ti;
657
658     tconn = GetConn(as, 0);
659     if (as->parms[2].items) {
660         /* this is really a rebozo command */
661         if (as->parms[1].items) {
662             /* specified specific things to restart, can't do this at the same
663              * time */
664             printf
665                 ("bos: can't specify both '-bos' and specific servers to restart.\n");
666             return 1;
667         }
668         /* otherwise do a rebozo */
669         code = BOZO_ReBozo(tconn);
670         if (code)
671             printf("bos: failed to restart bosserver (%s)\n", em(code));
672         return code;
673     }
674     if (as->parms[1].items == 0) {
675         if (as->parms[3].items) {       /* '-all' */
676             code = BOZO_RestartAll(tconn);
677             if (code)
678                 printf("bos: failed to restart servers (%s)\n", em(code));
679         } else
680             printf("bos: To restart all processes please specify '-all'\n");
681     } else {
682         if (as->parms[3].items) {
683             printf("bos: Can't use '-all' along with individual instances\n");
684         } else {
685             for (ti = as->parms[1].items; ti; ti = ti->next) {
686                 code = BOZO_Restart(tconn, ti->data);
687                 if (code)
688                     printf("bos: failed to restart instance %s (%s)\n",
689                            ti->data, em(code));
690             }
691         }
692     }
693     return 0;
694 }
695
696 static int
697 SetCellName(struct cmd_syndesc *as, void *arock)
698 {
699     struct rx_connection *tconn;
700     afs_int32 code;
701
702     tconn = GetConn(as, 0);
703     code = BOZO_SetCellName(tconn, as->parms[1].items->data);
704     if (code)
705         printf("bos: failed to set cell (%s)\n", em(code));
706     return 0;
707 }
708
709 static int
710 AddHost(struct cmd_syndesc *as, void *arock)
711 {
712     struct rx_connection *tconn;
713     afs_int32 code;
714     struct cmd_item *ti;
715     char name[MAXHOSTCHARS];
716
717     tconn = GetConn(as, 0);
718     for (ti = as->parms[1].items; ti; ti = ti->next) {
719         if (as->parms[2].items) {
720             if (strlen(ti->data) > MAXHOSTCHARS - 3) {
721                 fprintf(stderr, "bos: host name too long\n");
722                 return E2BIG;
723             }
724             name[0] = '[';
725             strcpy(&name[1], ti->data);
726             strcat((char *)&name, "]");
727             code = BOZO_AddCellHost(tconn, name);
728         } else
729             code = BOZO_AddCellHost(tconn, ti->data);
730         if (code)
731             printf("bos: failed to add host %s (%s)\n", ti->data, em(code));
732     }
733     return 0;
734 }
735
736 static int
737 RemoveHost(struct cmd_syndesc *as, void *arock)
738 {
739     struct rx_connection *tconn;
740     afs_int32 code;
741     struct cmd_item *ti;
742
743     tconn = GetConn(as, 0);
744     for (ti = as->parms[1].items; ti; ti = ti->next) {
745         code = BOZO_DeleteCellHost(tconn, ti->data);
746         if (code)
747             printf("bos: failed to delete host %s (%s)\n", ti->data,
748                    em(code));
749     }
750     return 0;
751 }
752
753 static int
754 ListHosts(struct cmd_syndesc *as, void *arock)
755 {
756     struct rx_connection *tconn;
757     afs_int32 code;
758     char tbuffer[256];
759     char *tp;
760     afs_int32 i;
761
762     tp = tbuffer;
763     tconn = GetConn(as, 0);
764     code = BOZO_GetCellName(tconn, &tp);
765     if (code) {
766         printf("bos: failed to get cell name (%s)\n", em(code));
767         exit(1);
768     }
769     printf("Cell name is %s\n", tbuffer);
770     for (i = 0;; i++) {
771         code = BOZO_GetCellHost(tconn, i, &tp);
772         if (code == BZDOM)
773             break;
774         if (code != 0) {
775             printf("bos: failed to get cell host %d (%s)\n", i, em(code));
776             exit(1);
777         }
778         printf("    Host %d is %s\n", i + 1, tbuffer);
779     }
780     return 0;
781 }
782
783 static int
784 AddKey(struct cmd_syndesc *as, void *arock)
785 {
786     struct rx_connection *tconn;
787     afs_int32 code;
788     struct ktc_encryptionKey tkey;
789     afs_int32 temp;
790     char *tcell;
791     char cellBuffer[256];
792     char buf[BUFSIZ], ver[BUFSIZ];
793
794     tconn = GetConn(as, 1);
795     memset(&tkey, 0, sizeof(struct ktc_encryptionKey));
796
797     if (as->parms[1].items)
798         strcpy(buf, as->parms[1].items->data);
799     else {
800         /* prompt for key */
801         code = UI_UTIL_read_pw_string(buf, sizeof(buf), "input key: ", 0);
802         if (code || strlen(buf) == 0) {
803             fprintf(stderr, "Bad key: \n");
804             exit(1);
805         }
806         code = UI_UTIL_read_pw_string(ver, sizeof(ver), "Retype input key: ", 0);
807         if (code || strlen(ver) == 0) {
808             fprintf(stderr, "Bad key: \n");
809             exit(1);
810         }
811         if (strcmp(ver, buf) != 0) {
812             fprintf(stderr, "\nInput key mismatch\n");
813             exit(1);
814         }
815
816     }
817
818     temp = atoi(as->parms[2].items->data);
819     if (temp == 999) {
820         /* bcrypt key */
821 /*
822         strcpy((char *)&tkey, as->parms[1].items->data);
823 */
824         strcpy((char *)&tkey, buf);
825     } else {                    /* kerberos key */
826         if (as->parms[ADDPARMOFFSET].items) {
827             strcpy(cellBuffer, as->parms[ADDPARMOFFSET].items->data);
828
829             /* string to key needs upper-case cell names */
830
831             /* I don't believe this is true.  The string to key function
832              * actually expands the cell name, then LOWER-CASES it.  Perhaps it
833              * didn't use to??? */
834             ucstring(cellBuffer, cellBuffer, strlen(cellBuffer));
835             tcell = cellBuffer;
836         } else
837             tcell = NULL;       /* no cell specified, use current */
838 /*
839         ka_StringToKey(as->parms[1].items->data, tcell, &tkey);
840 */
841         ka_StringToKey(buf, tcell, &tkey);
842     }
843     tconn = GetConn(as, 1);
844     code = BOZO_AddKey(tconn, temp, ktc_to_bozoptr(&tkey));
845     if (code) {
846         printf("bos: failed to set key %d (%s)\n", temp, em(code));
847         exit(1);
848     }
849     return 0;
850 }
851
852 static int
853 RemoveKey(struct cmd_syndesc *as, void *arock)
854 {
855     struct rx_connection *tconn;
856     afs_int32 code;
857     afs_int32 temp;
858     struct cmd_item *ti;
859
860     tconn = GetConn(as, 0);
861     for (ti = as->parms[1].items; ti; ti = ti->next) {
862         temp = atoi(ti->data);
863         code = BOZO_DeleteKey(tconn, temp);
864         if (code) {
865             printf("bos: failed to delete key %d (%s)\n", temp, em(code));
866             exit(1);
867         }
868     }
869     return 0;
870 }
871
872 static int
873 ListKeys(struct cmd_syndesc *as, void *arock)
874 {
875     struct rx_connection *tconn;
876     afs_int32 code;
877     struct ktc_encryptionKey tkey;
878     afs_int32 kvno;
879     struct bozo_keyInfo keyInfo;
880     int everWorked;
881     afs_int32 i;
882
883     tconn = GetConn(as, 1);
884     everWorked = 0;
885     for (i = 0;; i++) {
886         code = BOZO_ListKeys(tconn, i, &kvno, ktc_to_bozoptr(&tkey), &keyInfo);
887         if (code)
888             break;
889         everWorked = 1;
890         /* first check if key is returned */
891         if ((!ka_KeyIsZero(ktc_to_charptr(&tkey), sizeof(tkey))) && (as->parms[1].items)) {
892             printf("key %d is '", kvno);
893             ka_PrintBytes(ktc_to_charptr(&tkey), sizeof(tkey));
894             printf("'\n");
895         } else {
896             if (keyInfo.keyCheckSum == 0)       /* shouldn't happen */
897                 printf("key version is %d\n", kvno);
898             else
899                 printf("key %d has cksum %u\n", kvno, keyInfo.keyCheckSum);
900         }
901     }
902     if (everWorked) {
903         printf("Keys last changed on %s.\n", DateOf(keyInfo.mod_sec));
904     }
905     if (code != BZDOM)
906         printf("bos: %s error encountered while listing keys\n", em(code));
907     else
908         printf("All done.\n");
909     return 0;
910 }
911
912 static int
913 AddSUser(struct cmd_syndesc *as, void *arock)
914 {
915     struct rx_connection *tconn;
916     afs_int32 code;
917     int failed;
918     struct cmd_item *ti;
919
920     failed = 0;
921     tconn = GetConn(as, 0);
922     for (ti = as->parms[1].items; ti; ti = ti->next) {
923         code = BOZO_AddSUser(tconn, ti->data);
924         if (code) {
925             printf("bos: failed to add user '%s' (%s)\n", ti->data, em(code));
926             failed = 1;
927         }
928     }
929     return failed;
930 }
931
932 static int
933 RemoveSUser(struct cmd_syndesc *as, void *arock)
934 {
935     struct rx_connection *tconn;
936     struct cmd_item *ti;
937     afs_int32 code;
938     int failed;
939
940     failed = 0;
941     tconn = GetConn(as, 0);
942     for (ti = as->parms[1].items; ti; ti = ti->next) {
943         code = BOZO_DeleteSUser(tconn, ti->data);
944         if (code) {
945             printf("bos: failed to delete user '%s', ", ti->data);
946             if (code == ENOENT)
947                 printf("(no such user)\n");
948             else
949                 printf("(%s)\n", em(code));
950             failed = 1;
951         }
952     }
953     return failed;
954 }
955
956 #define NPERLINE    10          /* dudes to print per line */
957 static int
958 ListSUsers(struct cmd_syndesc *as, void *arock)
959 {
960     struct rx_connection *tconn;
961     int i;
962     afs_int32 code;
963     char tbuffer[256];
964     char *tp;
965     int lastNL, printGreeting;
966
967     tconn = GetConn(as, 0);
968     lastNL = 0;
969     printGreeting = 1;
970     for (i = 0;; i++) {
971         tp = tbuffer;
972         code = BOZO_ListSUsers(tconn, i, &tp);
973         if (code)
974             break;
975         if (printGreeting) {
976             printGreeting = 0;  /* delay until after first call succeeds */
977             printf("SUsers are: ");
978         }
979         printf("%s ", tbuffer);
980         if ((i % NPERLINE) == NPERLINE - 1) {
981             printf("\n");
982             lastNL = 1;
983         } else
984             lastNL = 0;
985     }
986     if (code != 1) {
987         /* a real error code, instead of scanned past end */
988         printf("bos: failed to retrieve super-user list (%s)\n", em(code));
989         return code;
990     }
991     if (lastNL == 0)
992         printf("\n");
993     return 0;
994 }
995
996 static int
997 StatServer(struct cmd_syndesc *as, void *arock)
998 {
999     struct rx_connection *tconn;
1000     afs_int32 code;
1001     int i;
1002     char ibuffer[BOZO_BSSIZE];
1003     char *tp;
1004     int int32p;
1005
1006     /* int32p==1 is obsolete, smaller, printout */
1007     int32p = (as->parms[2].items != 0 ? 2 : 0);
1008
1009     /* no parms does something pretty different */
1010     if (as->parms[1].items)
1011         return IStatServer(as, int32p);
1012
1013     tconn = GetConn(as, 0);
1014     for (i = 0;; i++) {
1015         /* for each instance */
1016         tp = ibuffer;
1017         code = BOZO_EnumerateInstance(tconn, i, &tp);
1018         if (code == BZDOM)
1019             break;
1020         if (code) {
1021             printf("bos: failed to contact host's bosserver (%s).\n",
1022                    em(code));
1023             break;
1024         }
1025         DoStat(ibuffer, tconn, int32p, (i == 0));       /* print status line */
1026     }
1027     return 0;
1028 }
1029
1030 static int
1031 CreateServer(struct cmd_syndesc *as, void *arock)
1032 {
1033     struct rx_connection *tconn;
1034     afs_int32 code;
1035     char *parms[6];
1036     struct cmd_item *ti;
1037     int i;
1038     char *type, *name, *notifier = NONOTIFIER;
1039
1040     tconn = GetConn(as, 0);
1041     for (i = 0; i < 6; i++)
1042         parms[i] = "";
1043     for (i = 0, ti = as->parms[3].items; (ti && i < 6); ti = ti->next, i++) {
1044         parms[i] = ti->data;
1045     }
1046     name = as->parms[1].items->data;
1047     type = as->parms[2].items->data;
1048     if ((ti = as->parms[4].items)) {
1049         notifier = ti->data;
1050     }
1051     code =
1052         BOZO_CreateBnode(tconn, type, name, parms[0], parms[1], parms[2],
1053                          parms[3], parms[4], notifier);
1054     if (code) {
1055         printf
1056             ("bos: failed to create new server instance %s of type '%s' (%s)\n",
1057              name, type, em(code));
1058     }
1059     return code;
1060 }
1061
1062 static int
1063 DeleteServer(struct cmd_syndesc *as, void *arock)
1064 {
1065     struct rx_connection *tconn;
1066     afs_int32 code;
1067     struct cmd_item *ti;
1068
1069     code = 0;
1070     tconn = GetConn(as, 0);
1071     for (ti = as->parms[1].items; ti; ti = ti->next) {
1072         code = BOZO_DeleteBnode(tconn, ti->data);
1073         if (code) {
1074             if (code == BZBUSY)
1075                 printf("bos: can't delete running instance '%s'\n", ti->data);
1076             else
1077                 printf("bos: failed to delete instance '%s' (%s)\n", ti->data,
1078                        em(code));
1079         }
1080     }
1081     return code;
1082 }
1083
1084 static int
1085 StartServer(struct cmd_syndesc *as, void *arock)
1086 {
1087     struct rx_connection *tconn;
1088     afs_int32 code;
1089     struct cmd_item *ti;
1090
1091     code = 0;
1092     tconn = GetConn(as, 0);
1093     for (ti = as->parms[1].items; ti; ti = ti->next) {
1094         code = BOZO_SetStatus(tconn, ti->data, BSTAT_NORMAL);
1095         if (code)
1096             printf("bos: failed to start instance '%s' (%s)\n", ti->data,
1097                    em(code));
1098     }
1099     return code;
1100 }
1101
1102 static int
1103 StopServer(struct cmd_syndesc *as, void *arock)
1104 {
1105     struct rx_connection *tconn;
1106     afs_int32 code;
1107     struct cmd_item *ti;
1108
1109     code = 0;
1110     tconn = GetConn(as, 0);
1111     for (ti = as->parms[1].items; ti; ti = ti->next) {
1112         code = BOZO_SetStatus(tconn, ti->data, BSTAT_SHUTDOWN);
1113         if (code)
1114             printf("bos: failed to change stop instance '%s' (%s)\n",
1115                    ti->data, em(code));
1116     }
1117     if (as->parms[8].items) {
1118         code = BOZO_WaitAll(tconn);
1119         if (code)
1120             printf("bos: can't wait for processes to shutdown (%s)\n",
1121                    em(code));
1122     }
1123     return code;
1124 }
1125
1126 #define PARMBUFFERSSIZE 32
1127
1128 static afs_int32
1129 DoSalvage(struct rx_connection * aconn, char * aparm1, char * aparm2,
1130           char * aoutName, afs_int32 showlog, char * parallel,
1131           char * atmpDir, char * orphans, int dafs,
1132           struct MRAFSSalvageParms * mrafsParm)
1133 {
1134     afs_int32 code;
1135     char *parms[6];
1136     char buffer;
1137     char tbuffer[BOZO_BSSIZE];
1138     struct bozo_status istatus;
1139     struct rx_call *tcall;
1140     char *tp;
1141     FILE *outFile;
1142     int closeIt;
1143     char partName[20];          /* canonical name for partition */
1144     char pbuffer[PARMBUFFERSSIZE];
1145     afs_int32 partNumber;
1146     char *notifier = NONOTIFIER;
1147
1148     /* if a partition was specified, canonicalize the name, since
1149      * the salvager has a stupid partition ID parser */
1150     if (aparm1) {
1151         partNumber = volutil_GetPartitionID(aparm1);
1152         if (partNumber < 0) {
1153             printf("bos: could not parse partition ID '%s'\n", aparm1);
1154             return EINVAL;
1155         }
1156         tp = volutil_PartitionName(partNumber);
1157         if (!tp) {
1158             printf("bos: internal error parsing partition ID '%s'\n", aparm1);
1159             return EINVAL;
1160         }
1161         strcpy(partName, tp);
1162     } else
1163         partName[0] = 0;
1164
1165     /* open the file name */
1166     if (aoutName) {
1167         outFile = fopen(aoutName, "w");
1168         if (!outFile) {
1169             printf("bos: can't open specified SalvageLog file '%s'\n",
1170                    aoutName);
1171             return ENOENT;
1172         }
1173         closeIt = 1;            /* close this file later */
1174     } else {
1175         outFile = stdout;
1176         closeIt = 0;            /* don't close this file later */
1177     }
1178
1179     for (code = 2; code < 6; code++)
1180         parms[code] = "";
1181     if (!aparm2)
1182         aparm2 = "";
1183
1184     /* MUST pass canonical (wire-format) salvager path to bosserver */
1185     if (*aparm2 != 0) {
1186         /* single volume salvage */
1187         if (dafs) {
1188             /* for DAFS, we call the salvagserver binary with special options.
1189              * in this mode, it simply uses SALVSYNC to tell the currently
1190              * running salvageserver to offline and salvage the volume in question */
1191             strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALSRV_FILEPATH, BOZO_BSSIZE);
1192
1193             if ((strlen(tbuffer) + 9 + strlen(partName) + 1 + strlen(aparm2) +
1194                  1) > BOZO_BSSIZE) {
1195                 printf("bos: command line too big\n");
1196                 return (E2BIG);
1197             }
1198
1199             strcat(tbuffer, " -client ");
1200             strcat(tbuffer, partName);
1201             strcat(tbuffer, " ");
1202             strcat(tbuffer, aparm2);
1203         } else {
1204             strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH, BOZO_BSSIZE);
1205
1206             if ((strlen(tbuffer) + 1 + strlen(partName) + 1 + strlen(aparm2) +
1207                  1) > BOZO_BSSIZE) {
1208                 printf("bos: command line too big\n");
1209                 return (E2BIG);
1210             }
1211
1212             strcat(tbuffer, " ");
1213             strcat(tbuffer, partName);
1214             strcat(tbuffer, " ");
1215             strcat(tbuffer, aparm2);
1216         }
1217     } else {
1218         /* partition salvage */
1219         strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH, BOZO_BSSIZE);
1220         if ((strlen(tbuffer) + 4 + strlen(partName) + 1) > BOZO_BSSIZE) {
1221             printf("bos: command line too big\n");
1222             return (E2BIG);
1223         }
1224         strcat(tbuffer, " -force ");
1225         strcat(tbuffer, partName);
1226     }
1227
1228     /* For DAFS, specifying a single volume does not result in a standard
1229      * salvager call.  Instead, it simply results in a SALVSYNC call to the
1230      * online salvager daemon.  This interface does not give us the same rich
1231      * set of call flags.  Thus, we skip these steps for DAFS single-volume
1232      * calls */
1233     if (!dafs || (*aparm2 == 0)) {
1234         /* add the parallel option if given */
1235         if (parallel != NULL) {
1236             if ((strlen(tbuffer) + 11 + strlen(parallel) + 1) > BOZO_BSSIZE) {
1237                 printf("bos: command line too big\n");
1238                 return (E2BIG);
1239             }
1240             strcat(tbuffer, " -parallel ");
1241             strcat(tbuffer, parallel);
1242         }
1243
1244         /* add the tmpdir option if given */
1245         if (atmpDir != NULL) {
1246             if ((strlen(tbuffer) + 9 + strlen(atmpDir) + 1) > BOZO_BSSIZE) {
1247                 printf("bos: command line too big\n");
1248                 return (E2BIG);
1249             }
1250             strcat(tbuffer, " -tmpdir ");
1251             strcat(tbuffer, atmpDir);
1252         }
1253
1254         /* add the orphans option if given */
1255         if (orphans != NULL) {
1256             if ((strlen(tbuffer) + 10 + strlen(orphans) + 1) > BOZO_BSSIZE) {
1257                 printf("bos: command line too big\n");
1258                 return (E2BIG);
1259             }
1260             strcat(tbuffer, " -orphans ");
1261             strcat(tbuffer, orphans);
1262         }
1263
1264         if (mrafsParm->Optdebug)
1265             strcat(tbuffer, " -debug");
1266         if (mrafsParm->Optnowrite)
1267             strcat(tbuffer, " -nowrite");
1268         if (mrafsParm->Optforce)
1269             strcat(tbuffer, " -force");
1270         if (mrafsParm->Optoktozap)
1271             strcat(tbuffer, " -oktozap");
1272         if (mrafsParm->Optrootfiles)
1273             strcat(tbuffer, " -rootfiles");
1274         if (mrafsParm->Optsalvagedirs)
1275             strcat(tbuffer, " -salvagedirs");
1276         if (mrafsParm->Optblockreads)
1277             strcat(tbuffer, " -blockreads");
1278         if (mrafsParm->OptListResidencies)
1279             strcat(tbuffer, " -ListResidencies");
1280         if (mrafsParm->OptSalvageRemote)
1281             strcat(tbuffer, " -SalvageRemote");
1282         if (mrafsParm->OptSalvageArchival)
1283             strcat(tbuffer, " -SalvageArchival");
1284         if (mrafsParm->OptIgnoreCheck)
1285             strcat(tbuffer, " -IgnoreCheck");
1286         if (mrafsParm->OptForceOnLine)
1287             strcat(tbuffer, " -ForceOnLine");
1288         if (mrafsParm->OptUseRootDirACL)
1289             strcat(tbuffer, " -UseRootDirACL");
1290         if (mrafsParm->OptTraceBadLinkCounts)
1291             strcat(tbuffer, " -TraceBadLinkCounts");
1292         if (mrafsParm->OptDontAskFS)
1293             strcat(tbuffer, " -DontAskFS");
1294         if (mrafsParm->OptLogLevel) {
1295             sprintf(pbuffer, " -LogLevel %ld", afs_printable_int32_ld(mrafsParm->OptLogLevel));
1296             strcat(tbuffer, pbuffer);
1297         }
1298         if (mrafsParm->OptRxDebug)
1299             strcat(tbuffer, " -rxdebug");
1300         if (mrafsParm->OptResidencies) {
1301             sprintf(pbuffer, " -Residencies %lu",
1302                     afs_printable_uint32_lu(mrafsParm->OptResidencies));
1303             strcat(tbuffer, pbuffer);
1304         }
1305     }
1306
1307     parms[0] = tbuffer;
1308     parms[1] = "now";           /* when to do it */
1309     code =
1310         BOZO_CreateBnode(aconn, "cron", "salvage-tmp", parms[0], parms[1],
1311                          parms[2], parms[3], parms[4], notifier);
1312     if (code) {
1313         printf("bos: failed to start 'salvager' (%s)\n", em(code));
1314         goto done;
1315     }
1316     /* now wait for bnode to disappear */
1317     while (1) {
1318         IOMGR_Sleep(5);
1319         tp = tbuffer;
1320         code = BOZO_GetInstanceInfo(aconn, "salvage-tmp", &tp, &istatus);
1321         if (code)
1322             break;
1323         printf("bos: waiting for salvage to complete.\n");
1324     }
1325     if (code != BZNOENT) {
1326         printf("bos: salvage failed (%s)\n", em(code));
1327         goto done;
1328     }
1329     code = 0;
1330
1331     /* now print the log file to the output file */
1332     printf("bos: salvage completed\n");
1333     if (aoutName || showlog) {
1334         fprintf(outFile, "SalvageLog:\n");
1335         tcall = rx_NewCall(aconn);
1336         /* MUST pass canonical (wire-format) salvager log path to bosserver */
1337         code =
1338             StartBOZO_GetLog(tcall, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH);
1339         if (code) {
1340             rx_EndCall(tcall, code);
1341             goto done;
1342         }
1343         /* copy data */
1344         while (1) {
1345             code = rx_Read(tcall, &buffer, 1);
1346             if (code != 1)
1347                 break;
1348             putc(buffer, outFile);
1349             if (buffer == 0)
1350                 break;          /* the end delimeter */
1351         }
1352         code = rx_EndCall(tcall, 0);
1353         /* fall through into cleanup code */
1354     }
1355
1356   done:
1357     if (closeIt && outFile)
1358         fclose(outFile);
1359     return code;
1360 }
1361
1362 static int
1363 GetLogCmd(struct cmd_syndesc *as, void *arock)
1364 {
1365     struct rx_connection *tconn;
1366     struct rx_call *tcall;
1367     afs_int32 code;
1368     char buffer;
1369     int error;
1370
1371     printf("Fetching log file '%s'...\n", as->parms[1].items->data);
1372     tconn = GetConn(as, 0);
1373     tcall = rx_NewCall(tconn);
1374     code = StartBOZO_GetLog(tcall, as->parms[1].items->data);
1375     if (code) {
1376         rx_EndCall(tcall, code);
1377         goto done;
1378     }
1379     /* copy data */
1380     error = 0;
1381     while (1) {
1382         code = rx_Read(tcall, &buffer, 1);
1383         if (code != 1) {
1384             error = EIO;
1385             break;
1386         }
1387         if (buffer == 0)
1388             break;              /* the end delimeter */
1389         putchar(buffer);
1390     }
1391     code = rx_EndCall(tcall, error);
1392     /* fall through into cleanup code */
1393
1394   done:
1395     if (code)
1396         afs_com_err("bos", code, "(while reading log)");
1397     return code;
1398 }
1399
1400 static int
1401 IsDAFS(struct rx_connection *aconn)
1402 {
1403     char buffer[BOZO_BSSIZE];
1404     char *tp;
1405     struct bozo_status istatus;
1406     afs_int32 code;
1407
1408     tp = &buffer[0];
1409
1410     code = BOZO_GetInstanceInfo(aconn, "dafs", &tp, &istatus);
1411     if (code) {
1412         /* no dafs bnode; cannot be dafs */
1413         return 0;
1414     }
1415     if (istatus.goal) {
1416         /* dafs bnode is running; we must be dafs */
1417         return 1;
1418     }
1419
1420     /* At this point, either we have neither a dafs nor fs bnode running, or
1421      * we have an fs bnode running but the dafs bnode is stopped.
1422      *
1423      * If an fs bnode is running, we are obviously not DAFS. If an fs bnode
1424      * is not running and a dafs bnode is not running... it's not certain if
1425      * we are DAFS or not DAFS. Just return 0 in that case; it shouldn't much
1426      * matter what we return, anyway */
1427     return 0;
1428 }
1429
1430 static int
1431 SalvageCmd(struct cmd_syndesc *as, void *arock)
1432 {
1433     struct rx_connection *tconn;
1434     afs_int32 code, rc, i;
1435     char *outName;
1436     char tname[BOZO_BSSIZE];
1437     afs_int32 newID;
1438     extern struct ubik_client *cstruct;
1439     afs_int32 curGoal, showlog = 0, dafs = 0, mrafs = 0;
1440     char *parallel;
1441     char *tmpDir;
1442     char *orphans;
1443     char *tp;
1444     char * serviceName;
1445     struct MRAFSSalvageParms mrafsParm;
1446
1447     memset(&mrafsParm, 0, sizeof(mrafsParm));
1448
1449     /* parm 0 is machine name, 1 is partition, 2 is volume, 3 is -all flag */
1450     tconn = GetConn(as, 0);
1451
1452     tp = &tname[0];
1453
1454     /* find out whether fileserver is running demand attach fs */
1455     if (IsDAFS(tconn)) {
1456         dafs = 1;
1457         serviceName = "dafs";
1458         /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
1459         /* XXX this should really be done some other way, potentially by RPC */
1460         if ((code = BOZO_GetInstanceParm(tconn, serviceName, 4, &tp) == 0))
1461             mrafs = 1;
1462     } else {
1463         serviceName = "fs";
1464         /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
1465         /* XXX this should really be done some other way, potentially by RPC */
1466         if ((code = BOZO_GetInstanceParm(tconn, serviceName, 3, &tp) == 0))
1467             mrafs = 1;
1468     }
1469
1470     /* we can do a volume, a partition or the whole thing, but not mixtures
1471      * thereof */
1472     if (!as->parms[1].items && as->parms[2].items) {
1473         printf("bos: must specify partition to salvage individual volume.\n");
1474         return -1;
1475     }
1476     if (as->parms[5].items && as->parms[3].items) {
1477         printf("bos: can not specify both -file and -showlog.\n");
1478         return -1;
1479     }
1480     if (as->parms[4].items && (as->parms[1].items || as->parms[2].items)) {
1481         printf("bos: can not specify -all with other flags.\n");
1482         return -1;
1483     }
1484
1485     /* get the output file name, if any */
1486     if (as->parms[3].items)
1487         outName = as->parms[3].items->data;
1488     else
1489         outName = NULL;
1490
1491     if (as->parms[5].items)
1492         showlog = 1;
1493
1494     /* parallel option */
1495     parallel = NULL;
1496     if (as->parms[6].items)
1497         parallel = as->parms[6].items->data;
1498
1499     /* get the tmpdir filename if any */
1500     tmpDir = NULL;
1501     if (as->parms[7].items)
1502         tmpDir = as->parms[7].items->data;
1503
1504     /* -orphans option */
1505     orphans = NULL;
1506     if (as->parms[8].items) {
1507         if (mrafs) {
1508             printf("Can't specify -orphans for MR-AFS fileserver\n");
1509             return EINVAL;
1510         }
1511         orphans = as->parms[8].items->data;
1512     }
1513
1514     if (dafs) {
1515         if (!as->parms[9].items) { /* -forceDAFS flag */
1516             printf("This is a demand attach fileserver.  Are you sure you want to proceed with a manual salvage?\n");
1517             printf("must specify -forceDAFS flag in order to proceed.\n");
1518             return EINVAL;
1519         }
1520     }
1521
1522     if (mrafs) {
1523         if (as->parms[MRAFS_OFFSET].items)
1524             mrafsParm.Optdebug = 1;
1525         if (as->parms[MRAFS_OFFSET + 1].items)
1526             mrafsParm.Optnowrite = 1;
1527         if (as->parms[MRAFS_OFFSET + 2].items)
1528             mrafsParm.Optforce = 1;
1529         if (as->parms[MRAFS_OFFSET + 3].items)
1530             mrafsParm.Optoktozap = 1;
1531         if (as->parms[MRAFS_OFFSET + 4].items)
1532             mrafsParm.Optrootfiles = 1;
1533         if (as->parms[MRAFS_OFFSET + 5].items)
1534             mrafsParm.Optsalvagedirs = 1;
1535         if (as->parms[MRAFS_OFFSET + 6].items)
1536             mrafsParm.Optblockreads = 1;
1537         if (as->parms[MRAFS_OFFSET + 7].items)
1538             mrafsParm.OptListResidencies = 1;
1539         if (as->parms[MRAFS_OFFSET + 8].items)
1540             mrafsParm.OptSalvageRemote = 1;
1541         if (as->parms[MRAFS_OFFSET + 9].items)
1542             mrafsParm.OptSalvageArchival = 1;
1543         if (as->parms[MRAFS_OFFSET + 10].items)
1544             mrafsParm.OptIgnoreCheck = 1;
1545         if (as->parms[MRAFS_OFFSET + 11].items)
1546             mrafsParm.OptForceOnLine = 1;
1547         if (as->parms[MRAFS_OFFSET + 12].items)
1548             mrafsParm.OptUseRootDirACL = 1;
1549         if (as->parms[MRAFS_OFFSET + 13].items)
1550             mrafsParm.OptTraceBadLinkCounts = 1;
1551         if (as->parms[MRAFS_OFFSET + 14].items)
1552             mrafsParm.OptDontAskFS = 1;
1553         if (as->parms[MRAFS_OFFSET + 15].items)
1554             mrafsParm.OptLogLevel =
1555                 atoi(as->parms[MRAFS_OFFSET + 15].items->data);
1556         if (as->parms[MRAFS_OFFSET + 16].items)
1557             mrafsParm.OptRxDebug = 1;
1558         if (as->parms[MRAFS_OFFSET + 17].items) {
1559             if (as->parms[MRAFS_OFFSET + 8].items
1560                 || as->parms[MRAFS_OFFSET + 9].items) {
1561                 printf
1562                     ("Can't specify -Residencies with -SalvageRemote or -SalvageArchival\n");
1563                 return EINVAL;
1564             }
1565             code =
1566                 util_GetUInt32(as->parms[MRAFS_OFFSET + 17].items->data,
1567                                &mrafsParm.OptResidencies);
1568             if (code) {
1569                 printf("bos: '%s' is not a valid residency mask.\n",
1570                        as->parms[MRAFS_OFFSET + 17].items->data);
1571                 return code;
1572             }
1573         }
1574     } else {
1575         int stop = 0;
1576
1577         for (i = MRAFS_OFFSET; i < ADDPARMOFFSET; i++) {
1578             if (as->parms[i].items) {
1579                 printf(" %s only possible for MR-AFS fileserver.\n",
1580                        as->parms[i].name);
1581                 stop = 1;
1582             }
1583         }
1584         if (stop)
1585             exit(1);
1586     }
1587
1588     if (as->parms[4].items) {
1589         /* salvage whole enchilada */
1590         curGoal = GetServerGoal(tconn, serviceName);
1591         if (curGoal == BSTAT_NORMAL) {
1592             printf("bos: shutting down '%s'.\n", serviceName);
1593             code = BOZO_SetTStatus(tconn, serviceName, BSTAT_SHUTDOWN);
1594             if (code) {
1595                 printf("bos: failed to stop '%s' (%s)\n", serviceName, em(code));
1596                 return code;
1597             }
1598             code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1599             if (code)
1600                 printf
1601                     ("bos: failed to wait for file server shutdown, continuing.\n");
1602         }
1603         /* now do the salvage operation */
1604         printf("Starting salvage.\n");
1605         rc = DoSalvage(tconn, NULL, NULL, outName, showlog, parallel, tmpDir,
1606                        orphans, dafs, &mrafsParm);
1607         if (curGoal == BSTAT_NORMAL) {
1608             printf("bos: restarting %s.\n", serviceName);
1609             code = BOZO_SetTStatus(tconn, serviceName, BSTAT_NORMAL);
1610             if (code) {
1611                 printf("bos: failed to restart '%s' (%s)\n", serviceName, em(code));
1612                 return code;
1613             }
1614         }
1615         if (rc)
1616             return rc;
1617     } else if (!as->parms[2].items) {
1618         if (!as->parms[1].items) {
1619             printf
1620                 ("bos: must specify -all switch to salvage all partitions.\n");
1621             return -1;
1622         }
1623         if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1624             /* can't parse volume ID, so complain before shutting down
1625              * file server.
1626              */
1627             printf("bos: can't interpret %s as partition ID.\n",
1628                    as->parms[1].items->data);
1629             return -1;
1630         }
1631         curGoal = GetServerGoal(tconn, serviceName);
1632         /* salvage a whole partition (specified by parms[1]) */
1633         if (curGoal == BSTAT_NORMAL) {
1634             printf("bos: shutting down '%s'.\n", serviceName);
1635             code = BOZO_SetTStatus(tconn, serviceName, BSTAT_SHUTDOWN);
1636             if (code) {
1637                 printf("bos: can't stop '%s' (%s)\n", serviceName, em(code));
1638                 return code;
1639             }
1640             code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1641             if (code)
1642                 printf
1643                     ("bos: failed to wait for file server shutdown, continuing.\n");
1644         }
1645         /* now do the salvage operation */
1646         printf("Starting salvage.\n");
1647         rc = DoSalvage(tconn, as->parms[1].items->data, NULL, outName,
1648                        showlog, parallel, tmpDir, orphans, dafs, &mrafsParm);
1649         if (curGoal == BSTAT_NORMAL) {
1650             printf("bos: restarting '%s'.\n", serviceName);
1651             code = BOZO_SetTStatus(tconn, serviceName, BSTAT_NORMAL);
1652             if (code) {
1653                 printf("bos: failed to restart '%s' (%s)\n", serviceName, em(code));
1654                 return code;
1655             }
1656         }
1657         if (rc)
1658             return rc;
1659     } else {
1660         /* salvage individual volume (don't shutdown fs first), just use
1661          * single-shot cron bnode.  Must leave server running when using this
1662          * option, since salvager will ask file server for the volume */
1663         char *tmpname;
1664         afs_int32 err;
1665         const char *confdir;
1666         int localauth;
1667
1668         if (as->parms[ADDPARMOFFSET].items)
1669             tmpname = as->parms[ADDPARMOFFSET].items->data;
1670         else
1671             tmpname = NULL;
1672
1673         localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
1674         confdir =
1675             (localauth ? AFSDIR_SERVER_ETC_DIRPATH :
1676              AFSDIR_CLIENT_ETC_DIRPATH);
1677         code = vsu_ClientInit( /* noauth */ 1, confdir, tmpname,
1678                               /* server auth */ 0, &cstruct, (int (*)())0);
1679         if (code == 0) {
1680             newID = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1681             if (newID == 0) {
1682                 printf("bos: can't interpret %s as volume name or ID\n",
1683                        as->parms[2].items->data);
1684                 return -1;
1685             }
1686             sprintf(tname, "%u", newID);
1687         } else {
1688             printf
1689                 ("bos: can't initialize volume system client (code %d), trying anyway.\n",
1690                  code);
1691             strncpy(tname, as->parms[2].items->data, sizeof(tname));
1692         }
1693         if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1694             /* can't parse volume ID, so complain before shutting down
1695              * file server.
1696              */
1697             printf("bos: can't interpret %s as partition ID.\n",
1698                    as->parms[1].items->data);
1699             return -1;
1700         }
1701         printf("Starting salvage.\n");
1702         rc = DoSalvage(tconn, as->parms[1].items->data, tname, outName,
1703                        showlog, parallel, tmpDir, orphans, dafs, &mrafsParm);
1704         if (rc)
1705             return rc;
1706     }
1707     return 0;
1708 }
1709
1710 static int
1711 IStatServer(struct cmd_syndesc *as, int int32p)
1712 {
1713     struct rx_connection *tconn;
1714     struct cmd_item *ti;
1715     int firstTime = 1;
1716
1717     tconn = GetConn(as, 0);
1718     for (ti = as->parms[1].items; ti; ti = ti->next) {
1719         DoStat(ti->data, tconn, int32p, firstTime);
1720         firstTime = 0;
1721     }
1722     return 0;
1723 }
1724
1725 static int
1726 DoStat(IN char *aname,
1727        IN struct rx_connection *aconn,
1728        IN int aint32p,
1729        IN int firstTime)        /* true iff first instance in cmd */
1730 {
1731     afs_int32 temp;
1732     char buffer[500];
1733     afs_int32 code;
1734     afs_int32 i;
1735     struct bozo_status istatus;
1736     char *tp;
1737     char *is1, *is2, *is3, *is4;        /* instance strings */
1738
1739     tp = buffer;
1740     code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
1741     if (code) {
1742         printf("bos: failed to get instance info for '%s' (%s)\n", aname,
1743                em(code));
1744         return -1;
1745     }
1746     if (firstTime && aint32p && (istatus.flags & BOZO_BADDIRACCESS))
1747         printf
1748             ("Bosserver reports inappropriate access on server directories\n");
1749     printf("Instance %s, ", aname);
1750     if (aint32p)
1751         printf("(type is %s) ", buffer);
1752     if (istatus.fileGoal == istatus.goal) {
1753         if (!istatus.goal)
1754             printf("disabled, ");
1755     } else {
1756         if (istatus.fileGoal)
1757             printf("temporarily disabled, ");
1758         else
1759             printf("temporarily enabled, ");
1760     }
1761
1762     if (istatus.flags & BOZO_ERRORSTOP)
1763         printf("stopped for too many errors, ");
1764     if (istatus.flags & BOZO_HASCORE)
1765         printf("has core file, ");
1766
1767     tp = buffer;
1768     code = BOZO_GetStatus(aconn, aname, &temp, &tp);
1769     if (code)
1770         printf("bos: failed to get status for instance '%s' (%s)\n", aname,
1771                em(code));
1772     else {
1773         printf("currently ");
1774         if (temp == BSTAT_NORMAL)
1775             printf("running normally.\n");
1776         else if (temp == BSTAT_SHUTDOWN)
1777             printf("shutdown.\n");
1778         else if (temp == BSTAT_STARTINGUP)
1779             printf("starting up.\n");
1780         else if (temp == BSTAT_SHUTTINGDOWN)
1781             printf("shutting down.\n");
1782         if (buffer[0] != 0) {
1783             printf("    Auxiliary status is: %s.\n", buffer);
1784         }
1785     }
1786
1787     /* are we done yet? */
1788     if (!aint32p)
1789         return 0;
1790
1791     if (istatus.procStartTime)
1792         printf("    Process last started at %s (%d proc starts)\n",
1793                DateOf(istatus.procStartTime), istatus.procStarts);
1794     if (istatus.lastAnyExit) {
1795         printf("    Last exit at %s\n", DateOf(istatus.lastAnyExit));
1796     }
1797     if (istatus.lastErrorExit) {
1798         is1 = is2 = is3 = is4 = NULL;
1799         printf("    Last error exit at %s, ", DateOf(istatus.lastErrorExit));
1800         code = BOZO_GetInstanceStrings(aconn, aname, &is1, &is2, &is3, &is4);
1801         /* don't complain about failing call, since could simply mean
1802          * interface mismatch.
1803          */
1804         if (code == 0) {
1805             if (*is1 != 0) {
1806                 /* non-null instance string */
1807                 printf("by %s, ", is1);
1808             }
1809             free(is1);
1810             free(is2);
1811             free(is3);
1812             free(is4);
1813         }
1814         if (istatus.errorSignal) {
1815             if (istatus.errorSignal == SIGTERM)
1816                 printf("due to shutdown request\n");
1817             else
1818                 printf("due to signal %d\n", istatus.errorSignal);
1819         } else
1820             printf("by exiting with code %d\n", istatus.errorCode);
1821     }
1822
1823     if (aint32p > 1) {
1824         /* try to display all the parms */
1825         for (i = 0;; i++) {
1826             tp = buffer;
1827             code = BOZO_GetInstanceParm(aconn, aname, i, &tp);
1828             if (code)
1829                 break;
1830             printf("    Command %d is '%s'\n", i + 1, buffer);
1831         }
1832         tp = buffer;
1833         code = BOZO_GetInstanceParm(aconn, aname, 999, &tp);
1834         if (!code) {
1835             /* Any type of failure is treated as not having a notifier program */
1836             printf("    Notifier  is '%s'\n", buffer);
1837         }
1838         printf("\n");
1839     }
1840     return 0;
1841 }
1842
1843 static int
1844 GetRestrict(struct cmd_syndesc *as, void *arock)
1845 {
1846     struct rx_connection *tconn;
1847     afs_int32 code, val;
1848
1849     tconn = GetConn(as, 0);
1850     code = BOZO_GetRestrictedMode(tconn, &val);
1851     if (code)
1852         printf("bos: failed to get restricted mode (%s)\n", em(code));
1853     else
1854         printf("Restricted mode is %s\n", val ? "on" : "off");
1855
1856     return 0;
1857 }
1858
1859 static int
1860 SetRestrict(struct cmd_syndesc *as, void *arock)
1861 {
1862     struct rx_connection *tconn;
1863     afs_int32 code, val;
1864
1865     tconn = GetConn(as, 0);
1866     util_GetInt32(as->parms[1].items->data, &val);
1867     code = BOZO_SetRestrictedMode(tconn, val);
1868     if (code)
1869         printf("bos: failed to set restricted mode (%s)\n", em(code));
1870     return 0;
1871 }
1872
1873 static void
1874 add_std_args(struct cmd_syndesc *ts)
1875 {
1876     cmd_Seek(ts, ADDPARMOFFSET);
1877     /* + 0 */ cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1878     /* + 1 */ cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1879                           "don't authenticate");
1880     /* + 2 */ cmd_AddParm(ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1881                           "create tickets from KeyFile");
1882 }
1883
1884 #include "AFS_component_version_number.c"
1885
1886 int
1887 main(int argc, char **argv)
1888 {
1889     afs_int32 code;
1890     struct cmd_syndesc *ts;
1891     extern int afsconf_SawCell;
1892
1893 #ifdef  AFS_AIX32_ENV
1894     /*
1895      * The following signal action for AIX is necessary so that in case of a
1896      * crash (i.e. core is generated) we can include the user's data section
1897      * in the core dump. Unfortunately, by default, only a partial core is
1898      * generated which, in many cases, isn't too useful.
1899      */
1900     struct sigaction nsa;
1901
1902     sigemptyset(&nsa.sa_mask);
1903     nsa.sa_handler = SIG_DFL;
1904     nsa.sa_flags = SA_FULLDUMP;
1905     sigaction(SIGSEGV, &nsa, NULL);
1906     sigaction(SIGABRT, &nsa, NULL);
1907 #endif
1908
1909     /* start up rx */
1910     code = rx_Init(0);
1911     if (code) {
1912         printf("bos: could not initialize rx (%s)\n", em(code));
1913         exit(1);
1914     }
1915
1916     /* To resolve a AFSCELL environment "Note: ..." problem: Because bos calls ka_Init (why?) before any
1917      * checkup on the existance of a "-cell" option on the particular bos command we don't print the
1918      * message if a cell is passed in. Luckily the rest of the programs don't call these adhoc routines
1919      * and things work fine. Note that if the "-cell" isn't passed then we're still ok since later on
1920      * the proper routine (afsconf_GetCellInfo) is going to be called to do the right thing.
1921      */
1922     afsconf_SawCell = 1;        /* Means don't print warning if AFSCELL is set */
1923     ka_Init(0);
1924     afsconf_SawCell = 0;        /* Reset it */
1925     /* don't check error code, since fails sometimes when we're setting up a
1926      * system */
1927     initialize_CMD_error_table();
1928     initialize_BZ_error_table();
1929
1930     ts = cmd_CreateSyntax("start", StartServer, NULL, "start running a server");
1931     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1932     cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1933     add_std_args(ts);
1934
1935     ts = cmd_CreateSyntax("stop", StopServer, NULL, "halt a server instance");
1936     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1937     cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1938     cmd_Seek(ts, 8);
1939     cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1940                 "wait for process to stop");
1941     add_std_args(ts);
1942
1943     ts = cmd_CreateSyntax("status", StatServer, NULL,
1944                           "show server instance status");
1945     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1946     cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL,
1947                 "server process name");
1948     cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "long status");
1949     add_std_args(ts);
1950
1951     ts = cmd_CreateSyntax("shutdown", Shutdown, NULL, "shutdown all processes");
1952     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1953     cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1954     cmd_Seek(ts, 8);
1955     cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1956                 "wait for process to stop");
1957     add_std_args(ts);
1958
1959     ts = cmd_CreateSyntax("startup", Startup, NULL, "start all processes");
1960     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1961     cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1962     add_std_args(ts);
1963
1964     ts = cmd_CreateSyntax("restart", Restart, NULL, "restart processes");
1965     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1966     cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1967     cmd_AddParm(ts, "-bosserver", CMD_FLAG, CMD_OPTIONAL,
1968                 "restart bosserver");
1969     cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "restart all processes");
1970     add_std_args(ts);
1971
1972 #ifndef OPBOS
1973
1974     ts = cmd_CreateSyntax("create", CreateServer, NULL,
1975                           "create a new server instance");
1976     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1977     cmd_AddParm(ts, "-instance", CMD_SINGLE, 0, "server process name");
1978     cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "server type");
1979     cmd_AddParm(ts, "-cmd", CMD_LIST, 0, "command lines");
1980     cmd_AddParm(ts, "-notifier", CMD_SINGLE, CMD_OPTIONAL,
1981                 "Notifier program");
1982     add_std_args(ts);
1983
1984     ts = cmd_CreateSyntax("delete", DeleteServer, NULL,
1985                           "delete a server instance");
1986     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1987     cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1988     add_std_args(ts);
1989
1990     ts = cmd_CreateSyntax("adduser", AddSUser, NULL,
1991                           "add users to super-user list");
1992     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1993     cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
1994     add_std_args(ts);
1995
1996     ts = cmd_CreateSyntax("removeuser", RemoveSUser, NULL,
1997                           "remove users from super-user list");
1998     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1999     cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
2000     add_std_args(ts);
2001
2002     ts = cmd_CreateSyntax("listusers", ListSUsers, NULL, "list super-users");
2003     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2004     add_std_args(ts);
2005
2006     ts = cmd_CreateSyntax("addkey", AddKey, NULL,
2007                           "add keys to key dbase (kvno 999 is bcrypt)");
2008     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2009     cmd_AddParm(ts, "-key", CMD_SINGLE, CMD_OPTIONAL, "key");
2010     cmd_AddParm(ts, "-kvno", CMD_SINGLE, 0, "key version number");
2011     add_std_args(ts);
2012
2013     ts = cmd_CreateSyntax("removekey", RemoveKey, NULL,
2014                           "remove keys from key dbase");
2015     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2016     cmd_AddParm(ts, "-kvno", CMD_LIST, 0, "key version number");
2017     add_std_args(ts);
2018
2019     ts = cmd_CreateSyntax("listkeys", ListKeys, NULL, "list keys");
2020     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2021     cmd_AddParm(ts, "-showkey", CMD_FLAG, CMD_OPTIONAL,
2022                 "show the actual key rather than the checksum");
2023     add_std_args(ts);
2024
2025     ts = cmd_CreateSyntax("listhosts", ListHosts, NULL, "get cell host list");
2026     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2027     add_std_args(ts);
2028     cmd_CreateAlias(ts, "getcell");
2029
2030     ts = cmd_CreateSyntax("setcellname", SetCellName, NULL, "set cell name");
2031     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2032     cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
2033     add_std_args(ts);
2034
2035     ts = cmd_CreateSyntax("addhost", AddHost, NULL, "add host to cell dbase");
2036     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2037     cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
2038     cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL, "vote doesn't count");
2039     add_std_args(ts);
2040
2041     ts = cmd_CreateSyntax("removehost", RemoveHost, NULL,
2042                           "remove host from cell dbase");
2043     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2044     cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
2045     add_std_args(ts);
2046
2047     ts = cmd_CreateSyntax("setauth", SetAuth, NULL,
2048                           "set authentication required flag");
2049     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2050     cmd_AddParm(ts, "-authrequired", CMD_SINGLE, 0,
2051                 "on or off: authentication required for admin requests");
2052     add_std_args(ts);
2053
2054     ts = cmd_CreateSyntax("install", Install, NULL, "install program");
2055     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2056     cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to install");
2057     cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
2058     add_std_args(ts);
2059
2060     ts = cmd_CreateSyntax("uninstall", UnInstall, NULL, "uninstall program");
2061     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2062     cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to uninstall");
2063     cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
2064     add_std_args(ts);
2065
2066     ts = cmd_CreateSyntax("getlog", GetLogCmd, NULL, "examine log file");
2067     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2068     cmd_AddParm(ts, "-file", CMD_SINGLE, 0, "log file to examine");
2069     add_std_args(ts);
2070
2071     ts = cmd_CreateSyntax("getdate", GetDate, NULL, "get dates for programs");
2072     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2073     cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to check");
2074     cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
2075     add_std_args(ts);
2076
2077     ts = cmd_CreateSyntax("exec", Exec, NULL, "execute shell command on server");
2078     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2079     cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "command to execute");
2080     add_std_args(ts);
2081
2082     ts = cmd_CreateSyntax("prune", Prune, NULL, "prune server files");
2083     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2084     cmd_AddParm(ts, "-bak", CMD_FLAG, CMD_OPTIONAL, "delete .BAK files");
2085     cmd_AddParm(ts, "-old", CMD_FLAG, CMD_OPTIONAL, "delete .OLD files");
2086     cmd_AddParm(ts, "-core", CMD_FLAG, CMD_OPTIONAL, "delete core files");
2087     cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "delete all junk files");
2088     add_std_args(ts);
2089
2090     ts = cmd_CreateSyntax("setrestart", SetRestartCmd, NULL,
2091                           "set restart times");
2092     cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2093     cmd_AddParm(ts, "-time", CMD_SINGLE, CMD_REQUIRED,
2094                 "time to restart server");
2095     cmd_AddParm(ts, "-general", CMD_FLAG, CMD_OPTIONAL,
2096                 "set general restart time");
2097     cmd_AddParm(ts, "-newbinary", CMD_FLAG, CMD_OPTIONAL,
2098                 "set new binary restart time");
2099     add_std_args(ts);
2100     cmd_CreateAlias(ts, "setr");
2101
2102     ts = cmd_CreateSyntax("getrestart", GetRestartCmd, NULL,
2103                           "get restart times");
2104     cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2105     add_std_args(ts);
2106     cmd_CreateAlias(ts, "getr");
2107
2108     ts = cmd_CreateSyntax("salvage", SalvageCmd, NULL,
2109                           "salvage partition or volumes");
2110     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2111     cmd_AddParm(ts, "-partition", CMD_SINGLE, CMD_OPTIONAL,
2112                 "salvage partition");
2113     cmd_AddParm(ts, "-volume", CMD_SINGLE, CMD_OPTIONAL,
2114                 "salvage volume number or volume name");
2115     cmd_AddParm(ts, "-file", CMD_SINGLE, CMD_OPTIONAL,
2116                 "salvage log output file");
2117     cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "salvage whole server");
2118     cmd_AddParm(ts, "-showlog", CMD_FLAG, CMD_OPTIONAL,
2119                 "display salvage log");
2120     cmd_AddParm(ts, "-parallel", CMD_SINGLE, CMD_OPTIONAL,
2121                 "# of max parallel partition salvaging");
2122     cmd_AddParm(ts, "-tmpdir", CMD_SINGLE, CMD_OPTIONAL,
2123                 "directory to place tmp files");
2124     cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL,
2125                 "ignore | remove | attach");
2126     cmd_AddParm(ts, "-forceDAFS", CMD_FLAG, CMD_OPTIONAL,
2127                 "(DAFS) force salvage of demand attach fileserver");
2128     cmd_AddParm(ts, "-debug", CMD_FLAG, CMD_OPTIONAL,
2129                 "(MR-AFS) Run in Debugging mode");
2130     cmd_AddParm(ts, "-nowrite", CMD_FLAG, CMD_OPTIONAL,
2131                 "(MR-AFS) Run readonly/test mode");
2132     cmd_AddParm(ts, "-force", CMD_FLAG, CMD_OPTIONAL,
2133                 "(MR-AFS) Force full salvaging");
2134     cmd_AddParm(ts, "-oktozap", CMD_FLAG, CMD_OPTIONAL,
2135                 "(MR-AFS) Give permission to destroy bogus file residencies/volumes - debugging flag");
2136     cmd_AddParm(ts, "-rootfiles", CMD_FLAG, CMD_OPTIONAL,
2137                 "(MR-AFS) Show files owned by root - debugging flag");
2138     cmd_AddParm(ts, "-salvagedirs", CMD_FLAG, CMD_OPTIONAL,
2139                 "(MR-AFS) Force rebuild/salvage of all directories");
2140     cmd_AddParm(ts, "-blockreads", CMD_FLAG, CMD_OPTIONAL,
2141                 "(MR-AFS) Read smaller blocks to handle IO/bad blocks");
2142     cmd_AddParm(ts, "-ListResidencies", CMD_FLAG, CMD_OPTIONAL,
2143                 "(MR-AFS) Just list affected file residencies - debugging flag");
2144     cmd_AddParm(ts, "-SalvageRemote", CMD_FLAG, CMD_OPTIONAL,
2145                 "(MR-AFS) Salvage storage systems that are not directly attached");
2146     cmd_AddParm(ts, "-SalvageArchival", CMD_FLAG, CMD_OPTIONAL,
2147                 "(MR-AFS) Salvage HSM storage systems");
2148     cmd_AddParm(ts, "-IgnoreCheck", CMD_FLAG, CMD_OPTIONAL,
2149                 "(MR-AFS) Don't perform VLDB safety check when deleting unreferenced files.  Only a good idea in single server cell.");
2150     cmd_AddParm(ts, "-ForceOnLine", CMD_FLAG, CMD_OPTIONAL,
2151                 "(MR-AFS) Force the volume to come online, even if it hasn't salvaged cleanly.");
2152     cmd_AddParm(ts, "-UseRootDirACL", CMD_FLAG, CMD_OPTIONAL,
2153                 "(MR-AFS) Use the root directory ACL for lost+found directory if it is created.");
2154     cmd_AddParm(ts, "-TraceBadLinkCounts", CMD_FLAG, CMD_OPTIONAL,
2155                 "(MR-AFS) Print out lines about volume reference count changes.");
2156     cmd_AddParm(ts, "-DontAskFS", CMD_FLAG, CMD_OPTIONAL,
2157                 "(MR-AFS) Don't ask fileserver to take volume offline.  THIS IS VERY DANGEROUS.");
2158     cmd_AddParm(ts, "-LogLevel", CMD_SINGLE, CMD_OPTIONAL,
2159                 "(MR-AFS) log level");
2160     cmd_AddParm(ts, "-rxdebug", CMD_FLAG, CMD_OPTIONAL,
2161                 "(MR-AFS) Write out rx debug information.");
2162     cmd_AddParm(ts, "-Residencies", CMD_SINGLE, CMD_OPTIONAL,
2163                 "(MR-AFS) Numeric mask of residencies to be included in the salvage.  Do not use with -SalvageRemote or -SalvageArchival");
2164     add_std_args(ts);
2165
2166     ts = cmd_CreateSyntax("blockscanner", BlockScannerCmd, NULL,
2167                           "block scanner daemon from making migration requests");
2168     cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2169     add_std_args(ts);
2170
2171     ts = cmd_CreateSyntax("unblockscanner", UnBlockScannerCmd, NULL,
2172                           "allow scanner daemon to make migration requests again");
2173     cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2174     add_std_args(ts);
2175
2176     ts = cmd_CreateSyntax("getrestricted", GetRestrict, NULL,
2177                           "get restrict mode");
2178     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2179     add_std_args(ts);
2180
2181     ts = cmd_CreateSyntax("setrestricted", SetRestrict, NULL,
2182                           "set restrict mode");
2183     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2184     cmd_AddParm(ts, "-mode", CMD_SINGLE, 0, "mode to set");
2185     add_std_args(ts);
2186 #endif
2187
2188     code = cmd_Dispatch(argc, argv);
2189     rx_Finalize();
2190     exit(code);
2191 }