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