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