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