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