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