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