comerr-behave-like-the-rest-of-the-world-20010918
[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 = (char *) 0;
194         /* next call expands cell name abbrevs for us and handles looking up
195          * local cell */
196         code = afsconf_GetCellInfo(tdir, tname, (char *) 0, &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] = (struct rx_securityClass *) 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), (char *)0);
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 = (char *) 0;    /* 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 != (char *)0) {
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 != (char *)0) {
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 != (char *)0) {
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) goto done;
1263     /* now wait for bnode to disappear */
1264     while (1) {
1265         IOMGR_Sleep(5);
1266         tp = tbuffer;
1267         code = BOZO_GetInstanceInfo(aconn, "salvage-tmp", &tp, &istatus);
1268         if (code) break;
1269         printf("bos: waiting for salvage to complete.\n");
1270     }
1271     if (code != BZNOENT) {
1272         printf("bos: salvage failed (%s)\n", em(code));
1273         goto done;
1274     }
1275     code = 0;
1276
1277     /* now print the log file to the output file */
1278     printf("bos: salvage completed\n");
1279     if (aoutName || showlog) {
1280         fprintf(outFile, "SalvageLog:\n");
1281         tcall = rx_NewCall(aconn);
1282         /* MUST pass canonical (wire-format) salvager log path to bosserver */
1283         code = StartBOZO_GetLog(tcall, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH);
1284         if (code) {
1285             rx_EndCall(tcall, code);
1286             goto done;
1287         }
1288         /* copy data */
1289         while(1) {
1290             code = rx_Read(tcall, &buffer, 1);
1291             if (code != 1) break;
1292             putc(buffer, outFile);
1293             if (buffer == 0) break;     /* the end delimeter */
1294         }
1295         code = rx_EndCall(tcall, 0);
1296         /* fall through into cleanup code */
1297     }
1298
1299   done:
1300     if (closeIt && outFile) fclose(outFile);
1301     return code;
1302 }
1303
1304 static GetLogCmd(as)
1305 register struct cmd_syndesc *as; {
1306     struct rx_connection *tconn;
1307     register struct rx_call *tcall;
1308     register afs_int32 code;
1309     char buffer;
1310     int error;
1311
1312     printf("Fetching log file '%s'...\n", as->parms[1].items->data);
1313     tconn = GetConn(as, 0);
1314     tcall = rx_NewCall(tconn);
1315     code = StartBOZO_GetLog(tcall, as->parms[1].items->data);
1316     if (code) {
1317         rx_EndCall(tcall, code);
1318         goto done;
1319     }
1320     /* copy data */
1321     error = 0;
1322     while(1) {
1323         code = rx_Read(tcall, &buffer, 1);
1324         if (code != 1) {
1325             error = EIO;
1326             break;
1327         }
1328         if (buffer == 0) break; /* the end delimeter */
1329         putchar(buffer);
1330     }
1331     code = rx_EndCall(tcall, error);
1332     /* fall through into cleanup code */
1333
1334   done:
1335     if (code)
1336         com_err("bos", code, "(while reading log)");
1337     return code;
1338 }
1339
1340 static SalvageCmd(as)
1341 struct cmd_syndesc *as; {
1342     register struct rx_connection *tconn;
1343     register afs_int32 code, rc, i;
1344     char *outName;
1345     char tname[BOZO_BSSIZE];
1346     afs_int32 newID;
1347     extern struct ubik_client *cstruct;
1348     afs_int32 curGoal, showlog = 0, mrafs = 0;
1349     char *parallel;
1350     char *tmpDir;
1351     char *orphans;
1352     char *tp;
1353
1354     memset(&mrafsParm, 0, sizeof(mrafsParm));
1355     
1356     /* parm 0 is machine name, 1 is partition, 2 is volume, 3 is -all flag */
1357     tconn = GetConn(as, 0);
1358
1359     /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
1360     /* XXX this should really be done some other way, potentially by RPC */
1361     tp = &tname;
1362     if (code = BOZO_GetInstanceParm(tconn, "fs", 3, &tp) == 0)
1363        mrafs = 1;
1364
1365     /* we can do a volume, a partition or the whole thing, but not mixtures
1366      * thereof */
1367     if (!as->parms[1].items && as->parms[2].items) {
1368         printf("bos: must specify partition to salvage individual volume.\n");
1369         return -1;
1370     }
1371     if (as->parms[5].items && as->parms[3].items) {
1372         printf("bos: can not specify both -file and -showlog.\n");
1373         return -1;
1374     }
1375     if (as->parms[4].items && (as->parms[1].items || as->parms[2].items)) {
1376         printf("bos: can not specify -all with other flags.\n");
1377         return -1;
1378     }
1379
1380     /* get the output file name, if any */
1381     if (as->parms[3].items)
1382         outName = as->parms[3].items->data;
1383     else
1384         outName = (char *) 0;
1385
1386     if (as->parms[5].items)
1387         showlog = 1;
1388
1389     /* parallel option */
1390     parallel = (char *) 0;
1391     if (as->parms[6].items)
1392         parallel = as->parms[6].items->data;
1393
1394     /* get the tmpdir filename if any */
1395     tmpDir = (char *)0;
1396     if (as->parms[7].items)
1397         tmpDir = as->parms[7].items->data;
1398
1399     /* -orphans option */
1400     orphans = (char *)0;
1401     if (as->parms[8].items) {
1402         if (mrafs) {
1403             printf("Can't specify -orphans for MR-AFS fileserver\n");
1404             return EINVAL;
1405         }
1406         orphans = as->parms[8].items->data;
1407     }
1408     
1409     if (mrafs) {
1410         if (as->parms[MRAFS_OFFSET].items)
1411             mrafsParm.Optdebug = 1;
1412         if (as->parms[MRAFS_OFFSET + 1].items)
1413             mrafsParm.Optnowrite = 1;
1414         if (as->parms[MRAFS_OFFSET + 2].items)
1415             mrafsParm.Optforce = 1;
1416         if (as->parms[MRAFS_OFFSET + 3].items)
1417             mrafsParm.Optoktozap = 1;
1418         if (as->parms[MRAFS_OFFSET + 4].items)
1419             mrafsParm.Optrootfiles = 1;
1420         if (as->parms[MRAFS_OFFSET + 5].items)
1421             mrafsParm.Optsalvagedirs = 1;
1422         if (as->parms[MRAFS_OFFSET + 6].items)
1423             mrafsParm.Optblockreads = 1;
1424         if (as->parms[MRAFS_OFFSET + 7].items)
1425             mrafsParm.OptListResidencies = 1;
1426         if (as->parms[MRAFS_OFFSET + 8].items)
1427             mrafsParm.OptSalvageRemote = 1;
1428         if (as->parms[MRAFS_OFFSET + 9].items)
1429             mrafsParm.OptSalvageArchival = 1;
1430         if (as->parms[MRAFS_OFFSET + 10].items)
1431             mrafsParm.OptIgnoreCheck = 1;
1432         if (as->parms[MRAFS_OFFSET + 11].items)
1433             mrafsParm.OptForceOnLine = 1;
1434         if (as->parms[MRAFS_OFFSET + 12].items)
1435             mrafsParm.OptUseRootDirACL = 1;
1436         if (as->parms[MRAFS_OFFSET + 13].items)
1437             mrafsParm.OptTraceBadLinkCounts = 1;
1438         if (as->parms[MRAFS_OFFSET + 14].items)
1439             mrafsParm.OptDontAskFS = 1;
1440         if (as->parms[MRAFS_OFFSET + 15].items)
1441             mrafsParm.OptLogLevel = atoi(as->parms[MRAFS_OFFSET + 15].items->data);
1442         if (as->parms[MRAFS_OFFSET + 16].items)
1443             mrafsParm.OptRxDebug = 1;
1444         if (as->parms[MRAFS_OFFSET + 17].items) {                             
1445            if (as->parms[MRAFS_OFFSET + 8].items || 
1446                as->parms[MRAFS_OFFSET + 9].items) {
1447                 printf("Can't specify -Residencies with -SalvageRemote or -SalvageArchival\n");
1448                 return EINVAL;
1449             }
1450             code = GetUInt32(as->parms[MRAFS_OFFSET + 17].items->data, 
1451                                        &mrafsParm.OptResidencies);
1452             if (code) {
1453                 printf("bos: '%s' is not a valid residency mask.\n",
1454                        as->parms[MRAFS_OFFSET + 13].items->data);
1455                 return code;
1456             }
1457         }
1458     } else {
1459        int stop = 0;
1460
1461        for (i = 9; i < ADDPARMOFFSET; i++) {
1462            if (as->parms[i].items) {
1463                printf(" %s only possible for MR-AFS fileserver.\n",
1464                        as->parms[i].name);
1465                stop = 1;
1466            }
1467        }
1468        if (stop) exit(1);
1469     }
1470
1471     if (as->parms[4].items) {
1472         /* salvage whole enchilada */
1473         curGoal = GetServerGoal(tconn, "fs");
1474         if (curGoal == BSTAT_NORMAL) {
1475             printf("bos: shutting down fs.\n");
1476             code = BOZO_SetTStatus(tconn, "fs", BSTAT_SHUTDOWN);
1477             if (code) {
1478                 printf("bos: failed to stop 'fs' (%s)\n", em(code));
1479                 return code;
1480             }
1481             code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1482             if (code)
1483                 printf("bos: failed to wait for file server shutdown, continuing.\n");
1484         }
1485         /* now do the salvage operation */
1486         printf("Starting salvage.\n");
1487         rc = DoSalvage(tconn, (char *) 0, (char *) 0, outName, showlog,parallel,tmpDir,orphans);
1488         if (rc) printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1489         if (curGoal == BSTAT_NORMAL) {
1490             printf("bos: restarting fs.\n");
1491             code = BOZO_SetTStatus(tconn, "fs", BSTAT_NORMAL);
1492             if (code) {
1493                 printf("bos: failed to restart 'fs' (%s)\n", em(code));
1494                 return code;
1495             }
1496         }
1497         if (rc) return rc;
1498     }
1499     else if (!as->parms[2].items) {
1500         if (!as->parms[1].items) {
1501             printf("bos: must specify -all switch to salvage all partitions.\n");
1502             return -1;
1503         }
1504         if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1505             /* can't parse volume ID, so complain before shutting down
1506              * file server.
1507              */
1508             printf("bos: can't interpret %s as partition ID.\n",
1509                    as->parms[1].items->data);
1510             return -1;
1511         }
1512         curGoal = GetServerGoal(tconn, "fs");
1513         /* salvage a whole partition (specified by parms[1]) */
1514         if (curGoal == BSTAT_NORMAL) {
1515             printf("bos: shutting down fs.\n");
1516             code = BOZO_SetTStatus(tconn, "fs", BSTAT_SHUTDOWN);
1517             if (code) {
1518                 printf("bos: can't stop 'fs' (%s)\n", em(code));
1519                 return code;
1520             }
1521             code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1522             if (code)
1523                 printf("bos: failed to wait for file server shutdown, continuing.\n");
1524         }
1525         /* now do the salvage operation */
1526         printf("Starting salvage.\n");
1527         rc = DoSalvage(tconn, as->parms[1].items->data, (char *) 0,
1528                        outName, showlog,parallel,tmpDir,orphans);
1529         if (rc) printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1530         if (curGoal == BSTAT_NORMAL) {
1531             printf("bos: restarting fs.\n");
1532             code = BOZO_SetTStatus(tconn, "fs", BSTAT_NORMAL);
1533             if (code) {
1534                 printf("bos: failed to restart 'fs' (%s)\n", em(code));
1535                 return code;
1536             }
1537         }
1538         if (rc) return rc;
1539     }
1540     else {
1541         /* salvage individual volume (don't shutdown fs first), just use
1542          * single-shot cron bnode.  Must leave server running when using this
1543          * option, since salvager will ask file server for the volume */
1544         char *tmpname;
1545         afs_int32 err;
1546         const char *confdir;
1547         int localauth;
1548
1549         if (as->parms[ADDPARMOFFSET].items) 
1550             tmpname = as->parms[ADDPARMOFFSET].items->data;
1551         else tmpname = (char *) 0;
1552
1553         localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
1554         confdir = (localauth ? AFSDIR_SERVER_ETC_DIRPATH : AFSDIR_CLIENT_ETC_DIRPATH);
1555         code = vsu_ClientInit(/* noauth */ 1, confdir, tmpname,
1556                               /* server auth */ 0, &cstruct, (int (*)()) 0);
1557         if (code == 0) {
1558             newID = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1559             if (newID == 0) {
1560                 printf("bos: can't interpret %s as volume name or ID\n", as->parms[2].items->data);
1561                 return -1;
1562             }
1563             sprintf(tname, "%u", newID);
1564         }
1565         else {
1566             printf("bos: can't initialize volume system client (code %d), trying anyway.\n",
1567                    as->parms[2].items->data, code);
1568             strncpy(tname, as->parms[2].items->data, sizeof(tname));
1569         }
1570         if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1571             /* can't parse volume ID, so complain before shutting down
1572              * file server.
1573              */
1574             printf("bos: can't interpret %s as partition ID.\n",
1575                    as->parms[1].items->data);
1576             return -1;
1577         }
1578         printf("Starting salvage.\n");
1579         rc = DoSalvage(tconn, as->parms[1].items->data, tname, outName,
1580                        showlog,parallel,tmpDir,orphans);
1581         if (rc) {
1582            printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1583            return rc;
1584         }
1585     }
1586     return 0;
1587 }
1588
1589 static IStatServer(as, int32p)
1590 int int32p;
1591 register struct cmd_syndesc *as; {
1592     register struct rx_connection *tconn;
1593     register struct cmd_item *ti;
1594     int firstTime = 1;
1595
1596     tconn = GetConn(as, 0);
1597     for (ti=as->parms[1].items; ti; ti=ti->next) {
1598         DoStat(ti->data, tconn, int32p, firstTime);
1599         firstTime = 0;
1600     }
1601     return 0;
1602 }
1603
1604 static DoStat (aname, aconn, aint32p, firstTime)
1605   IN char *aname;
1606   IN register struct rx_connection *aconn;
1607   IN int aint32p;
1608   IN int firstTime;                     /* true iff first instance in cmd */
1609 {
1610     afs_int32 temp;
1611     char buffer[500];
1612     register afs_int32 code;
1613     register afs_int32 i;
1614     struct bozo_status istatus;
1615     char *tp;
1616     char *is1, *is2, *is3, *is4;        /* instance strings */
1617
1618     tp = buffer;
1619     code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
1620     if (code) {
1621         printf("bos: failed to get instance info for '%s' (%s)\n",
1622                aname, em(code));
1623         return -1;
1624     }
1625     if (firstTime && aint32p && (istatus.flags & BOZO_BADDIRACCESS))
1626         printf ("Bosserver reports inappropriate access on server directories\n");
1627     printf("Instance %s, ", aname);
1628     if (aint32p) printf("(type is %s) ", buffer);
1629     if (istatus.fileGoal == istatus.goal) {
1630         if (!istatus.goal) printf("disabled, ");
1631     }
1632     else {
1633         if (istatus.fileGoal) printf("temporarily disabled, ");
1634         else printf("temporarily enabled, ");
1635     }
1636
1637     if (istatus.flags & BOZO_ERRORSTOP)
1638         printf("stopped for too many errors, ");
1639     if (istatus.flags & BOZO_HASCORE)
1640         printf("has core file, ");
1641
1642     tp = buffer;
1643     code = BOZO_GetStatus(aconn, aname, &temp, &tp);
1644     if (code)
1645         printf("bos: failed to get status for instance '%s' (%s)\n",
1646                aname, em(code));
1647     else {
1648         printf("currently ", aname);
1649         if (temp == BSTAT_NORMAL) printf("running normally.\n");
1650         else if (temp == BSTAT_SHUTDOWN) printf("shutdown.\n");
1651         else if (temp == BSTAT_STARTINGUP) printf("starting up.\n");
1652         else if (temp == BSTAT_SHUTTINGDOWN) printf("shutting down.\n");
1653         if (buffer[0] != 0) {
1654             printf("    Auxiliary status is: %s.\n", buffer);
1655         }
1656     }
1657
1658     /* are we done yet? */
1659     if (!aint32p) return 0;
1660
1661     if (istatus.procStartTime)
1662         printf("    Process last started at %s (%d proc starts)\n",
1663                DateOf(istatus.procStartTime), istatus.procStarts);
1664     if (istatus.lastAnyExit) {
1665         printf("    Last exit at %s\n", DateOf(istatus.lastAnyExit));
1666     }
1667     if (istatus.lastErrorExit) {
1668         is1 = is2 = is3 = is4 = (char *) 0;
1669         printf("    Last error exit at %s, ", DateOf(istatus.lastErrorExit));
1670         code = BOZO_GetInstanceStrings(aconn, aname, &is1, &is2, &is3, &is4);
1671         /* don't complain about failing call, since could simply mean
1672          * interface mismatch.
1673          */
1674         if (code == 0) {
1675             if (*is1 != 0) {
1676                 /* non-null instance string */
1677                 printf("by %s, ", is1);
1678             }
1679             free(is1);
1680             free(is2);
1681             free(is3);
1682             free(is4);
1683         }
1684         if (istatus.errorSignal) {
1685             if (istatus.errorSignal == SIGTERM)
1686                 printf("due to shutdown request\n");
1687             else
1688                 printf("due to signal %d\n", istatus.errorSignal);
1689         }
1690         else
1691             printf("by exiting with code %d\n", istatus.errorCode);
1692     }
1693     
1694     if (aint32p > 1) {
1695         /* try to display all the parms */
1696         for(i=0;;i++) {
1697             tp = buffer;
1698             code = BOZO_GetInstanceParm(aconn, aname, i, &tp);
1699             if (code) break;
1700             printf("    Command %d is '%s'\n", i+1, buffer);
1701         }
1702         tp = buffer;
1703         code = BOZO_GetInstanceParm(aconn, aname, 999, &tp);
1704         if (!code) {
1705             /* Any type of failure is treated as not having a notifier program */
1706             printf("    Notifier  is '%s'\n", buffer);
1707         }
1708         printf("\n");
1709     }
1710     return 0;
1711 }
1712
1713 #ifdef BOS_RESTRICTED_MODE
1714 static GetRestrict(as)
1715 struct cmd_syndesc *as; {
1716     register struct rx_connection *tconn;
1717     afs_int32 code, val;
1718     
1719     tconn = GetConn(as, 0);
1720     code = BOZO_GetRestrictedMode(tconn, &val);
1721     if (code) printf("bos: failed to get restricted mode (%s)\n", em(code));
1722     else printf("Restricted mode is %s\n", val ? "on" : "off");
1723     
1724     return 0;
1725 }
1726
1727 static SetRestrict(as)
1728 struct cmd_syndesc *as; {
1729     register struct rx_connection *tconn;
1730     afs_int32 code, val;
1731     
1732     tconn = GetConn(as, 0);
1733     util_GetInt32(as->parms[1].items->data, &val);
1734     code = BOZO_SetRestrictedMode(tconn, val);
1735     if (code) printf("bos: failed to set restricted mode (%s)\n", em(code));
1736     return 0;
1737 }
1738 #endif
1739
1740 static void add_std_args (ts)
1741   register struct cmd_syndesc *ts;
1742 {
1743     cmd_Seek(ts, ADDPARMOFFSET);
1744     /* + 0 */ cmd_AddParm(ts, "-cell", CMD_SINGLE, CMD_OPTIONAL, "cell name");
1745     /* + 1 */ cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD_OPTIONAL,
1746                          "don't authenticate");
1747     /* + 2 */ cmd_AddParm (ts, "-localauth", CMD_FLAG, CMD_OPTIONAL,
1748                            "create tickets from KeyFile");
1749 }
1750   
1751 #include "AFS_component_version_number.c"
1752
1753 main(argc, argv)
1754   int argc;
1755   char **argv;
1756 {
1757     register afs_int32 code;
1758     register struct cmd_syndesc *ts;
1759     extern int afsconf_SawCell;
1760
1761 #ifdef  AFS_AIX32_ENV
1762     /*
1763      * The following signal action for AIX is necessary so that in case of a 
1764      * crash (i.e. core is generated) we can include the user's data section 
1765      * in the core dump. Unfortunately, by default, only a partial core is
1766      * generated which, in many cases, isn't too useful.
1767      */
1768     struct sigaction nsa;
1769     
1770     sigemptyset(&nsa.sa_mask);
1771     nsa.sa_handler = SIG_DFL;
1772     nsa.sa_flags = SA_FULLDUMP;
1773     sigaction(SIGSEGV, &nsa, NULL);
1774     sigaction(SIGABRT, &nsa, NULL);
1775 #endif
1776
1777     /* start up rx */
1778     code = rx_Init(0);
1779     if (code) {
1780         printf("bos: could not initialize rx (%s)\n", em(code));
1781         exit(1);
1782     }
1783
1784     /* To resolve a AFSCELL environment "Note: ..." problem: Because bos calls ka_Init (why?) before any
1785      * checkup on the existance of a "-cell" option on the particular bos command we don't print the
1786      * message if a cell is passed in. Luckily the rest of the programs don't call these adhoc routines
1787      * and things work fine. Note that if the "-cell" isn't passed then we're still ok since later on
1788      * the proper routine (afsconf_GetCellInfo) is going to be called to do the right thing.
1789      */
1790     afsconf_SawCell = 1;        /* Means don't print warning if AFSCELL is set */
1791     ka_Init(0);
1792     afsconf_SawCell = 0;        /* Reset it */
1793     /* don't check error code, since fails sometimes when we're setting up a
1794      * system */
1795     initialize_CMD_error_table();
1796     initialize_BZ_error_table();
1797
1798     ts = cmd_CreateSyntax("start", StartServer, 0, "start running a server");
1799     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1800     cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1801     add_std_args (ts);
1802
1803     ts = cmd_CreateSyntax("stop", StopServer, 0, "halt a server instance");
1804     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1805     cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1806     cmd_Seek(ts, 8);
1807     cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1808                 "wait for process to stop");
1809     add_std_args (ts);
1810     
1811     ts = cmd_CreateSyntax("status", StatServer, 0,
1812                           "show server instance status");
1813     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1814     cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL,
1815                 "server process name");
1816     cmd_AddParm(ts, "-long", CMD_FLAG, CMD_OPTIONAL, "long status");
1817     add_std_args (ts);
1818
1819     ts = cmd_CreateSyntax("shutdown", Shutdown, 0, "shutdown all processes");
1820     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1821     cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1822     cmd_Seek(ts, 8);
1823     cmd_AddParm(ts, "-wait", CMD_FLAG, CMD_OPTIONAL,
1824                 "wait for process to stop");
1825     add_std_args (ts);
1826
1827     ts = cmd_CreateSyntax("startup", Startup, 0, "start all processes");
1828     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1829     cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1830     add_std_args (ts);
1831
1832     ts = cmd_CreateSyntax("restart", Restart, 0, "restart all processes");
1833     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1834     cmd_AddParm(ts, "-instance", CMD_LIST, CMD_OPTIONAL, "instances");
1835     cmd_AddParm(ts, "-bosserver", CMD_FLAG, CMD_OPTIONAL, "restart bosserver");
1836     cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "restart all processes");
1837     add_std_args (ts);
1838
1839 #ifndef OPBOS
1840
1841     ts = cmd_CreateSyntax("create", CreateServer, 0,
1842                           "create a new server instance");
1843     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1844     cmd_AddParm(ts, "-instance", CMD_SINGLE, 0, "server process name");
1845     cmd_AddParm(ts, "-type", CMD_SINGLE, 0, "server type");
1846     cmd_AddParm(ts, "-cmd", CMD_LIST, 0, "command lines");
1847     cmd_AddParm(ts, "-notifier", CMD_SINGLE, CMD_OPTIONAL, "Notifier program");
1848     add_std_args (ts);
1849
1850     ts = cmd_CreateSyntax("delete", DeleteServer, 0,
1851                           "delete a server instance");
1852     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1853     cmd_AddParm(ts, "-instance", CMD_LIST, 0, "server process name");
1854     add_std_args (ts);
1855     
1856     ts = cmd_CreateSyntax("adduser", AddSUser, 0,
1857                           "add users to super-user list");
1858     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1859     cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
1860     add_std_args (ts);
1861
1862     ts = cmd_CreateSyntax("removeuser", RemoveSUser, 0,
1863                           "remove users from super-user list");
1864     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1865     cmd_AddParm(ts, "-user", CMD_LIST, 0, "user names");
1866     add_std_args (ts);
1867
1868     ts = cmd_CreateSyntax("listusers", ListSUsers, 0, "list super-users");
1869     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1870     add_std_args (ts);
1871
1872     ts = cmd_CreateSyntax("addkey", AddKey, 0,
1873                            "add keys to key dbase (kvno 999 is bcrypt)");
1874     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1875     cmd_AddParm(ts, "-key", CMD_SINGLE, CMD_OPTIONAL, "key");
1876     cmd_AddParm(ts, "-kvno", CMD_SINGLE, 0, "key version number");
1877     add_std_args (ts);
1878
1879     ts = cmd_CreateSyntax("removekey", RemoveKey, 0,
1880                           "remove keys from key dbase");
1881     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1882     cmd_AddParm(ts, "-kvno", CMD_LIST, 0, "key version number");
1883     add_std_args (ts);
1884
1885     ts = cmd_CreateSyntax("listkeys", ListKeys, 0, "list keys");
1886     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1887     cmd_AddParm(ts, "-showkey", CMD_FLAG, CMD_OPTIONAL, "show the actual key rather than the checksum");
1888     add_std_args (ts);
1889
1890     ts = cmd_CreateSyntax("listhosts", ListHosts, 0, "get cell host list");
1891     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1892     add_std_args (ts);
1893     cmd_CreateAlias(ts, "getcell");
1894
1895     ts = cmd_CreateSyntax("setcellname", SetCellName, 0, "set cell name");
1896     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1897     cmd_AddParm(ts, "-name", CMD_SINGLE, 0, "cell name");
1898     add_std_args (ts);
1899
1900     ts = cmd_CreateSyntax("addhost", AddHost, 0, "add host to cell dbase");
1901     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1902     cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
1903     cmd_AddParm(ts, "-clone", CMD_FLAG, CMD_OPTIONAL, "vote doesn't count");
1904     add_std_args (ts);
1905
1906     ts = cmd_CreateSyntax("removehost", RemoveHost, 0,
1907                           "remove host from cell dbase");
1908     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1909     cmd_AddParm(ts, "-host", CMD_LIST, 0, "host name");
1910     add_std_args (ts);
1911
1912     ts = cmd_CreateSyntax("setauth", SetAuth, 0,
1913                           "set authentication required flag");
1914     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1915     cmd_AddParm(ts, "-authrequired", CMD_SINGLE,
1916                 0, "on or off: authentication required for admin requests");
1917     add_std_args (ts);
1918     
1919     ts = cmd_CreateSyntax("install", Install, 0, "install program");
1920     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1921     cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to install");
1922     cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1923     add_std_args (ts);
1924
1925     ts = cmd_CreateSyntax("uninstall", UnInstall, 0, "uninstall program");
1926     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1927     cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to uninstall");
1928     cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1929     add_std_args (ts);
1930
1931     ts = cmd_CreateSyntax("getlog", GetLogCmd, 0, "examine log file");
1932     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1933     cmd_AddParm(ts, "-file", CMD_SINGLE, 0, "log file to examine");
1934     add_std_args (ts);
1935
1936     ts = cmd_CreateSyntax("getdate", GetDate, 0, "get dates for programs");
1937     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1938     cmd_AddParm(ts, "-file", CMD_LIST, 0, "files to check");
1939     cmd_AddParm(ts, "-dir", CMD_SINGLE, CMD_OPTIONAL, "destination dir");
1940     add_std_args (ts);
1941
1942     ts = cmd_CreateSyntax("exec", Exec, 0, "execute shell command on server");
1943     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1944     cmd_AddParm(ts, "-cmd", CMD_SINGLE, 0, "command to execute");
1945     add_std_args (ts);
1946
1947     ts = cmd_CreateSyntax("prune", Prune, 0, "prune server files");
1948     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1949     cmd_AddParm(ts, "-bak", CMD_FLAG, CMD_OPTIONAL, "delete .BAK files");
1950     cmd_AddParm(ts, "-old", CMD_FLAG, CMD_OPTIONAL, "delete .OLD files");
1951     cmd_AddParm(ts, "-core", CMD_FLAG, CMD_OPTIONAL, "delete core files");
1952     cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "delete all junk files");
1953     add_std_args (ts);
1954
1955     ts = cmd_CreateSyntax("setrestart", SetRestartCmd, 0, "set restart times");
1956     cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
1957     cmd_AddParm(ts, "-time", CMD_SINGLE,
1958                 CMD_REQUIRED, "time to restart server");
1959     cmd_AddParm(ts, "-general", CMD_FLAG,
1960                 CMD_OPTIONAL, "set general restart time");
1961     cmd_AddParm(ts, "-newbinary", CMD_FLAG,
1962                 CMD_OPTIONAL, "set new binary restart time");
1963     add_std_args (ts);
1964
1965     ts = cmd_CreateSyntax("getrestart", GetRestartCmd, 0, "get restart times");
1966     cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
1967     add_std_args (ts);
1968
1969     ts = cmd_CreateSyntax("salvage", SalvageCmd, 0,
1970                           "salvage partition or volumes");
1971     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
1972     cmd_AddParm(ts, "-partition", CMD_SINGLE,
1973                 CMD_OPTIONAL, "salvage partition");
1974     cmd_AddParm(ts, "-volume", CMD_SINGLE,
1975                 CMD_OPTIONAL, "salvage volume number or volume name");
1976     cmd_AddParm(ts, "-file", CMD_SINGLE,
1977                 CMD_OPTIONAL, "salvage log output file");
1978     cmd_AddParm(ts, "-all", CMD_FLAG, CMD_OPTIONAL, "salvage whole server");
1979     cmd_AddParm(ts, "-showlog", CMD_FLAG, CMD_OPTIONAL, "display salvage log");
1980     cmd_AddParm(ts, "-parallel",CMD_SINGLE, CMD_OPTIONAL, 
1981                 "# of max parallel partition salvaging");
1982     cmd_AddParm(ts, "-tmpdir",CMD_SINGLE, CMD_OPTIONAL, 
1983                 "directory to place tmp files");
1984     cmd_AddParm(ts, "-orphans", CMD_SINGLE, CMD_OPTIONAL, 
1985                 "ignore | remove | attach");
1986     cmd_AddParm(ts, "-debug", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Run in Debugging mode");
1987     cmd_AddParm(ts, "-nowrite", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Run readonly/test mode");
1988     cmd_AddParm(ts, "-force", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force full salvaging");
1989     cmd_AddParm(ts, "-oktozap", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Give permission to destroy bogus file residencies/volumes - debugging flag");
1990     cmd_AddParm(ts, "-rootfiles", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Show files owned by root - debugging flag");
1991     cmd_AddParm(ts, "-salvagedirs", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force rebuild/salvage of all directories");
1992     cmd_AddParm(ts, "-blockreads", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Read smaller blocks to handle IO/bad blocks");
1993     cmd_AddParm(ts, "-ListResidencies", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Just list affected file residencies - debugging flag");
1994     cmd_AddParm(ts, "-SalvageRemote", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Salvage storage systems that are not directly attached");
1995     cmd_AddParm(ts, "-SalvageArchival", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Salvage HSM storage systems");
1996     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.");
1997     cmd_AddParm(ts, "-ForceOnLine", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Force the volume to come online, even if it hasn't salvaged cleanly.");
1998     cmd_AddParm(ts, "-UseRootDirACL", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Use the root directory ACL for lost+found directory if it is created.");
1999     cmd_AddParm(ts, "-TraceBadLinkCounts", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Print out lines about volume reference count changes.");
2000     cmd_AddParm(ts, "-DontAskFS", CMD_FLAG,CMD_OPTIONAL, "(MR-AFS) Don't ask fileserver to take volume offline.  THIS IS VERY DANGEROUS.");
2001     cmd_AddParm(ts, "-LogLevel", CMD_SINGLE, CMD_OPTIONAL, "(MR-AFS) log level");
2002     cmd_AddParm(ts, "-rxdebug", CMD_FLAG, CMD_OPTIONAL, "(MR-AFS) Write out rx debug information.");
2003     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");
2004     add_std_args (ts);
2005
2006     ts = cmd_CreateSyntax("blockscanner", BlockScannerCmd, 0,
2007                           "block scanner daemon from making migration requests");
2008     cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2009     add_std_args (ts);
2010
2011     ts = cmd_CreateSyntax("unblockscanner", UnBlockScannerCmd, 0,
2012                           "allow scanner daemon to make migration requests again");
2013     cmd_AddParm(ts, "-server", CMD_SINGLE, CMD_REQUIRED, "machine name");
2014     add_std_args (ts); 
2015
2016 #ifdef BOS_RESTRICTED_MODE
2017     ts = cmd_CreateSyntax("getrestricted", GetRestrict, 0, "get restrict mode");
2018     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2019     add_std_args (ts);
2020
2021     ts = cmd_CreateSyntax("setrestricted", SetRestrict, 0, "set restrict mode");
2022     cmd_AddParm(ts, "-server", CMD_SINGLE, 0, "machine name");
2023     cmd_AddParm(ts, "-mode", CMD_SINGLE, 0, "mode to set");
2024     add_std_args (ts);
2025 #endif
2026 #endif
2027
2028     code = cmd_Dispatch(argc, argv);
2029     rx_Finalize();
2030     exit(code);
2031 }