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