936dba36db6d7e3adeb83dc6ab4fd3dca7baf0df
[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     bcopy(th->h_addr, &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 = rindex(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 }
391
392 static UnInstall(as)
393 register struct cmd_syndesc *as; {
394     register afs_int32 code;
395     char tbuffer[256];
396     char destDir[256];
397     register struct cmd_item *ti;
398     register struct rx_connection *tconn;
399
400     tconn = GetConn(as, 0);
401     if (!as->parms[1].items) {
402         printf("bos: no files to uninstall\n");
403         return 1;
404     }
405
406     /* compute dest dir or file; default MUST be canonical form of dir path */
407     if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
408     else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
409
410     for(ti=as->parms[1].items; ti; ti=ti->next) {
411         /* uninstall each file */
412         ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
413         code = BOZO_UnInstall(tconn, tbuffer);
414         if (code) {
415             printf("bos: failed to uninstall %s (%s)\n", ti->data,
416                    em(code));
417             return 1;
418         }
419         else printf("bos: uninstalled file %s\n", ti->data);
420     }
421     return 0;
422 }
423
424 static afs_int32 GetServerGoal(aconn, aname)
425 char *aname;
426 struct rx_connection *aconn; {
427     char buffer[500];
428     char *tp;
429     register afs_int32 code;
430     struct bozo_status istatus;
431
432     tp = buffer;
433     code = BOZO_GetInstanceInfo(aconn, aname, &tp, &istatus);
434     if (code) {
435         printf("bos: failed to get instance info for '%s' (%s)\n",
436                aname, em(code));
437         /* if we can't get the answer, assume its running */
438         return BSTAT_NORMAL; 
439     }
440     if (istatus.goal == 0)
441         return BSTAT_SHUTDOWN;
442     else
443         return BSTAT_NORMAL;
444 }
445
446 static Install(as)
447 struct cmd_syndesc *as; {
448     struct rx_connection *tconn;
449     register afs_int32 code;
450     register struct cmd_item *ti;
451     struct stat tstat;
452     char tbuffer[256];
453     int fd;
454     struct rx_call *tcall;
455     char destDir[256];
456
457     tconn = GetConn(as, 0);
458     if (!as->parms[1].items) {
459         printf("bos: no files to install\n");
460         return 1;
461     }
462
463     /* compute dest dir or file; default MUST be canonical form of dir path */
464     if (as->parms[2].items) strcpy(destDir, as->parms[2].items->data);
465     else strcpy(destDir, AFSDIR_CANONICAL_SERVER_BIN_DIRPATH);
466
467     for(ti=as->parms[1].items; ti; ti=ti->next) {
468         /* install each file */
469         fd = open(ti->data, O_RDONLY);
470         if (fd < 0) {
471             /* better to quit on error than continue for install command */
472             printf("bos: can't find file '%s', quitting\n", ti->data);
473             return 1;
474         }
475         code = fstat(fd, &tstat);
476         if (code) {
477             printf("bos: failed to stat file %s, errno is %d\n", ti->data,
478                    errno);
479             return 1;
480         }
481         /* compute destination dir */
482         ComputeDestDir(ti->data, destDir, tbuffer, sizeof(tbuffer));
483         tcall = rx_NewCall(tconn);
484         code = StartBOZO_Install(tcall, tbuffer, tstat.st_size, (afs_int32)tstat.st_mode,
485                                  tstat.st_mtime);
486         if (code == 0) {
487             code = CopyBytes(fd, tcall);
488         }
489         code = rx_EndCall(tcall, code);
490         if (code) {
491             printf("bos: failed to install %s (%s)\n", ti->data, em(code));
492             return 1;
493         }
494         else printf("bos: installed file %s\n", ti->data);
495     }
496     return 0;
497 }
498
499 static Shutdown(as)
500 struct cmd_syndesc *as; {
501     register struct rx_connection *tconn;
502     register afs_int32 code;
503     register struct cmd_item *ti;
504     
505     tconn = GetConn(as, 0);
506     if (as->parms[1].items == 0) {
507         code = BOZO_ShutdownAll(tconn);
508         if (code) printf("bos: failed to shutdown servers (%s)\n", em(code));
509     }
510     else {
511         for(ti = as->parms[1].items; ti; ti=ti->next) {
512             code = BOZO_SetTStatus(tconn, ti->data, BSTAT_SHUTDOWN);
513             if (code)
514                 printf("bos: failed to shutdown instance %s (%s)\n",
515                        ti->data, em(code));
516         }
517     }
518     if (as->parms[8].items) {
519         code = BOZO_WaitAll(tconn);
520         if (code)
521             printf("bos: can't wait for processes to shutdown (%s)\n",
522                    em(code));
523     }
524     return 0;
525 }
526
527 static BlockScannerCmd(as, arock)
528 struct cmd_syndesc *as;
529 char *arock; {
530     register afs_int32 code;
531     struct rx_connection *tconn;
532     char BlockCommand[] = "/usr/afs/bin/scanner -block";
533
534     tconn = GetConn(as, 0);
535     code = BOZO_Exec(tconn, BlockCommand);
536     if (code)
537         printf("bos: failed to block scanner from making migration requests (%s)\n",
538                em(code));
539     return 0;
540 }
541
542 static UnBlockScannerCmd(as, arock)
543 struct cmd_syndesc *as;
544 char *arock; {
545     register afs_int32 code;
546     struct rx_connection *tconn;
547     char UnBlockCommand[] = "/usr/afs/bin/scanner -unblock";
548
549     tconn = GetConn(as, 0);
550     code = BOZO_Exec(tconn, UnBlockCommand);
551     if (code)
552         printf("bos: failed to allow scanner daemon to make migration requests again (%s)\n",
553                em(code));
554     return 0;
555 }                      
556
557 static GetRestartCmd(as, arock)
558 struct cmd_syndesc *as;
559 char *arock; {
560     register afs_int32 code;
561     struct ktime generalTime, newBinaryTime;
562     char messageBuffer[256];
563     struct rx_connection *tconn;
564     char *hostp;
565
566     hostp = as->parms[0].items->data;   /* host name for messages */
567     tconn = GetConn(as, 0);
568
569     code = BOZO_GetRestartTime(tconn, 1, &generalTime);
570     if (code) {
571         printf("bos: failed to retrieve restart information (%s)\n", em(code));
572         return code;
573     }
574     code = BOZO_GetRestartTime(tconn, 2, &newBinaryTime);
575     if (code) {
576         printf("bos: failed to retrieve restart information (%s)\n", em(code));
577         return code;
578     }
579
580     code = ktime_DisplayString(&generalTime, messageBuffer);
581     if (code) {
582         printf("bos: failed to decode restart time (%s)\n", em(code));
583         return code;
584     }
585     printf("Server %s restarts %s\n", hostp, messageBuffer);
586
587     code = ktime_DisplayString(&newBinaryTime, messageBuffer);
588     if (code) {
589         printf("bos: failed to decode restart time (%s)\n", em(code));
590         return code;
591     }
592     printf("Server %s restarts for new binaries %s\n", hostp, messageBuffer);
593
594     /* all done now */
595     return 0;
596 }
597
598 static SetRestartCmd(as, arock)
599 struct cmd_syndesc *as;
600 char *arock; {
601     afs_int32 count;
602     register afs_int32 code;
603     struct ktime restartTime;
604     afs_int32 type;
605     struct rx_connection *tconn;
606
607     count = 0;
608     tconn = GetConn(as, 0);
609     if (as->parms[2].items) {count++; type = 1;}
610     if (as->parms[3].items) {count++; type = 2;}
611     if (count > 1) {
612         printf("bos: can't specify more than one restart time at a time\n");
613         return -1;
614     }
615     if (count == 0) type = 1;   /* by default set general restart time */
616
617     if (code = ktime_ParsePeriodic(as->parms[1].items->data, &restartTime)) {
618         printf("bos: failed to parse '%s' as periodic restart time(%s)\n",
619                as->parms[1].items->data, em(code));
620         return code;
621     }
622
623     code = BOZO_SetRestartTime(tconn, type, &restartTime);
624     if (code) {
625         printf("bos: failed to set restart time at server (%s)\n", em(code));
626         return code;
627     }
628     return 0;
629 }
630
631 static Startup(as)
632 struct cmd_syndesc *as; {
633     register struct rx_connection *tconn;
634     register afs_int32 code;
635     register struct cmd_item *ti;
636     
637     tconn = GetConn(as, 0);
638     if (as->parms[1].items == 0) {
639         code = BOZO_StartupAll(tconn);
640         if (code)
641             printf("bos: failed to startup servers (%s)\n", em(code));
642     }
643     else {
644         for(ti = as->parms[1].items; ti; ti=ti->next) {
645             code = BOZO_SetTStatus(tconn, ti->data, BSTAT_NORMAL);
646             if (code)
647                 printf("bos: failed to start instance %s (%s)\n",
648                        ti->data, em(code));
649         }
650     }
651     return 0;
652 }
653
654 static Restart(as)
655 struct cmd_syndesc *as; {
656     register struct rx_connection *tconn;
657     register afs_int32 code;
658     register struct cmd_item *ti;
659     
660     tconn = GetConn(as, 0);
661     if (as->parms[2].items) {
662         /* this is really a rebozo command */
663         if (as->parms[1].items) {
664             /* specified specific things to restart, can't do this at the same
665              * time */
666             printf("bos: can't specify both '-bos' and specific servers to restart.\n");
667             return 1;
668         }
669         /* otherwise do a rebozo */
670         code = BOZO_ReBozo(tconn);
671         if (code)
672             printf("bos: failed to restart bosserver (%s)\n", em(code));
673         return code;
674     }
675     if (as->parms[1].items == 0) {
676         if (as->parms[3].items) {               /* '-all' */
677             code = BOZO_RestartAll(tconn);
678             if (code) printf("bos: failed to restart servers (%s)\n", em(code));
679         } else
680             printf("bos: To restart all processes please specify '-all'\n");
681     }
682     else {
683         if (as->parms[3].items) {
684             printf("bos: Can't use '-all' along with individual instances\n");
685         } else {
686             for(ti = as->parms[1].items; ti; ti=ti->next) {
687                 code = BOZO_Restart(tconn, ti->data);
688                 if (code)
689                     printf("bos: failed to restart instance %s (%s)\n", ti->data,
690                            em(code));
691             }
692         }
693     }
694     return 0;
695 }
696
697 static SetCellName(as)
698 struct cmd_syndesc *as; {
699     register struct rx_connection *tconn;
700     register afs_int32 code;
701     
702     tconn = GetConn(as, 0);
703     code = BOZO_SetCellName(tconn, as->parms[1].items->data);
704     if (code) printf("bos: failed to set cell (%s)\n", em(code));
705     return 0;
706 }
707
708 static AddHost(as)
709 register struct cmd_syndesc *as; {
710     register struct rx_connection *tconn;
711     register afs_int32 code;
712     register struct cmd_item *ti;
713     char name[MAXHOSTCHARS];
714     
715     tconn = GetConn(as, 0);
716     for(ti = as->parms[1].items; ti; ti=ti->next) {
717         if (as->parms[2].items) {
718            if (strlen(ti->data) > MAXHOSTCHARS - 3) {
719                fprintf(stderr, "bos: host name too long\n");
720                return E2BIG;
721            }
722             name[0] = '[';
723             strcpy(&name[1],ti->data);
724             strcat((char *)&name, "]");
725             code = BOZO_AddCellHost(tconn, name);
726         } else 
727            code = BOZO_AddCellHost(tconn, ti->data);
728         if (code)
729             printf("bos: failed to add host %s (%s)\n", ti->data, em(code));
730     }
731     return 0;
732 }
733
734 static RemoveHost(as)
735 register struct cmd_syndesc *as; {
736     register struct rx_connection *tconn;
737     register afs_int32 code;
738     register struct cmd_item *ti;
739     
740     tconn = GetConn(as, 0);
741     for(ti=as->parms[1].items; ti; ti=ti->next) {
742         code = BOZO_DeleteCellHost(tconn, ti->data);
743         if (code)
744             printf("bos: failed to delete host %s (%s)\n", ti->data, em(code));
745     }
746     return 0;
747 }
748
749 static ListHosts(as)
750 register struct cmd_syndesc *as; {
751     register struct rx_connection *tconn;
752     register afs_int32 code;
753     char tbuffer[256];
754     char *tp;
755     register afs_int32 i;
756
757     tp = tbuffer;
758     tconn = GetConn(as, 0);
759     code = BOZO_GetCellName(tconn, &tp);
760     if (code) {
761         printf("bos: failed to get cell name (%s)\n", em(code));
762         exit(1);
763     }
764     printf("Cell name is %s\n", tbuffer);
765     for(i=0;;i++) {
766         code = BOZO_GetCellHost(tconn, i, &tp);
767         if (code == BZDOM) break;
768         if (code != 0) {
769             printf("bos: failed to get cell host %d (%s)\n", i, em(code));
770             exit(1);
771         }
772         printf("    Host %d is %s\n", i+1, tbuffer);
773     }
774     return 0;
775 }
776
777 static AddKey(as)
778 register struct cmd_syndesc *as; {
779     register struct rx_connection *tconn;
780     register afs_int32 code;
781     struct ktc_encryptionKey tkey;
782     afs_int32 temp;
783     char *tcell;
784     char cellBuffer[256];
785     char buf[BUFSIZ], ver[BUFSIZ];
786     
787     tconn = GetConn(as, 1);
788     bzero(&tkey, sizeof(struct ktc_encryptionKey));
789
790         if(as->parms[1].items)
791                 strcpy(buf,as->parms[1].items->data);
792         else
793         {
794                 /* prompt for key */
795                 code=des_read_pw_string(buf,sizeof(buf),"input key: ",0);
796                 if(code || strlen(buf)==0)
797                 {
798                         fprintf(stderr,"Bad key: \n");
799                         exit(1);
800                 }
801                 code=des_read_pw_string(ver,sizeof(ver),"Retype input key: ",0);
802                 if(code || strlen(ver)==0)
803                 {
804                         fprintf(stderr,"Bad key: \n");
805                         exit(1);
806                 }
807                 if (strcmp (ver, buf) != 0) {
808                     fprintf (stderr, "\nInput key mismatch\n");
809                     exit(1);
810                 }
811
812         }
813
814     temp = atoi(as->parms[2].items->data);
815     if (temp == 999) {
816         /* bcrypt key */
817 /*
818         strcpy((char *)&tkey, as->parms[1].items->data);
819 */
820         strcpy((char *)&tkey, buf);
821     }
822     else {    /* kerberos key */
823         if (as->parms[ADDPARMOFFSET].items) {
824             strcpy(cellBuffer, as->parms[ADDPARMOFFSET].items->data);
825
826             /* string to key needs upper-case cell names */
827
828             /* I don't believe this is true.  The string to key function
829              * actually expands the cell name, then LOWER-CASES it.  Perhaps it
830              * didn't use to??? */
831             ucstring(cellBuffer, cellBuffer, strlen(cellBuffer));
832             tcell = cellBuffer;
833         }
834         else tcell = (char *) 0;    /* no cell specified, use current */
835 /*
836         ka_StringToKey(as->parms[1].items->data, tcell, &tkey);
837 */
838         ka_StringToKey(buf,tcell,&tkey);
839     }
840     tconn = GetConn(as, 1);
841     code = BOZO_AddKey(tconn, temp, &tkey);
842     if (code) {
843         printf("bos: failed to set key %d (%s)\n", temp, em(code));
844         exit(1);
845     }
846     return 0;
847 }
848
849 static RemoveKey(as)
850 register struct cmd_syndesc *as; {
851     register struct rx_connection *tconn;
852     register afs_int32 code;
853     afs_int32 temp;
854     register struct cmd_item *ti;
855     
856     tconn = GetConn(as, 0);
857     for(ti=as->parms[1].items; ti; ti=ti->next) {
858         temp = atoi(ti->data);
859         code = BOZO_DeleteKey(tconn, temp);
860         if (code) {
861             printf("bos: failed to delete key %d (%s)\n", temp, em(code));
862             exit(1);
863         }
864     }
865     return 0;
866 }
867
868 static ListKeys(as)
869   IN register struct cmd_syndesc *as;
870 {
871     register struct rx_connection *tconn;
872     register afs_int32 code;
873     struct ktc_encryptionKey tkey;
874     afs_int32 kvno;
875     struct bozo_keyInfo keyInfo;
876     int everWorked;
877     register afs_int32 i;
878     
879     tconn = GetConn(as, 1);
880     everWorked = 0;
881     for(i=0;;i++) {
882         code = BOZO_ListKeys(tconn, i, &kvno, &tkey, &keyInfo);
883         if (code) break;
884         everWorked = 1;
885         /* first check if key is returned */
886         if ((!ka_KeyIsZero (&tkey, sizeof(tkey))) && (as->parms[1].items)) {
887             printf ("key %d is '", kvno);
888             ka_PrintBytes (&tkey, sizeof(tkey));
889             printf ("'\n");
890         } else {
891             if (keyInfo.keyCheckSum == 0) /* shouldn't happen */
892                 printf ("key version is %d\n", kvno);
893             else
894                 printf ("key %d has cksum %u\n", kvno, keyInfo.keyCheckSum);
895         }
896     }
897     if (everWorked) {
898         printf("Keys last changed on %s.\n", DateOf(keyInfo.mod_sec));
899     }
900     if (code != BZDOM)
901         printf("bos: %s error encountered while listing keys\n", em(code));
902     else
903         printf("All done.\n");
904     return 0;
905 }
906
907 static AddSUser(as)
908 register struct cmd_syndesc *as; {
909     register struct rx_connection *tconn;
910     register afs_int32 code;
911     int failed;
912     register struct cmd_item *ti;
913
914     failed = 0;
915     tconn = GetConn(as, 0);
916     for(ti=as->parms[1].items; ti; ti=ti->next) {
917         code = BOZO_AddSUser(tconn, ti->data);
918         if (code) {
919             printf("bos: failed to add user '%s' (%s)\n", ti->data, em(code));
920             failed = 1;
921         }
922     }
923     return failed;
924 }
925
926 static RemoveSUser(as)
927 register struct cmd_syndesc *as; {
928     register struct rx_connection *tconn;
929     register struct cmd_item *ti;
930     register afs_int32 code;
931     int failed;
932
933     failed = 0;
934     tconn = GetConn(as, 0);
935     for(ti=as->parms[1].items; ti; ti=ti->next) {
936         code = BOZO_DeleteSUser(tconn, ti->data);
937         if (code) {
938             printf("bos: failed to delete user '%s', ", ti->data);
939             if (code == ENOENT)
940                 printf("(no such user)\n");
941             else
942                 printf("(%s)\n", em(code));
943             failed = 1;
944         }
945     }
946     return failed;
947 }
948
949 #define NPERLINE    10      /* dudes to print per line */
950 static ListSUsers(as)
951 register struct cmd_syndesc *as; {
952     register struct rx_connection *tconn;
953     register int i;
954     register afs_int32 code;
955     char tbuffer[256];
956     char *tp;
957     int lastNL, printGreeting;
958     
959     tconn = GetConn(as, 0);
960     lastNL = 0;
961     printGreeting = 1;
962     for(i=0;;i++) {
963         tp = tbuffer;
964         code = BOZO_ListSUsers(tconn, i, &tp);
965         if (code) break;
966         if (printGreeting) {
967             printGreeting = 0;  /* delay until after first call succeeds */
968             printf("SUsers are: ");
969         }
970         printf("%s ", tbuffer);
971         if ((i % NPERLINE) == NPERLINE-1) {
972             printf("\n");
973             lastNL = 1;
974         }
975         else lastNL = 0;
976     }
977     if (code != 1) {
978         /* a real error code, instead of scanned past end */
979         printf("bos: failed to retrieve super-user list (%s)\n", em(code));
980         return code;
981     }
982     if (lastNL == 0) printf("\n");
983     return 0;
984 }
985
986 static StatServer(as)
987 register struct cmd_syndesc *as; {
988     register struct rx_connection *tconn;
989     register afs_int32 code;
990     register int i;
991     char ibuffer[BOZO_BSSIZE];
992     char *tp;
993     int int32p;
994     
995     /* int32p==1 is obsolete, smaller, printout */
996     int32p = (as->parms[2].items != 0? 2 : 0);
997
998     /* no parms does something pretty different */
999     if (as->parms[1].items) return IStatServer(as, int32p);
1000
1001     tconn = GetConn(as, 0);
1002     for(i=0;;i++) {
1003         /* for each instance */
1004         tp = ibuffer;
1005         code = BOZO_EnumerateInstance(tconn, i, &tp);
1006         if (code == BZDOM) break;
1007         if (code) {
1008             printf("bos: failed to contact host's bosserver (%s).\n",
1009                    em(code));
1010             break;
1011         }
1012         DoStat(ibuffer, tconn, int32p, (i==0)); /* print status line */
1013     }
1014     return 0;
1015 }
1016
1017 static CreateServer(as)
1018 register struct cmd_syndesc *as; {
1019     register struct rx_connection *tconn;
1020     register afs_int32 code;
1021     char *parms[6];
1022     register struct cmd_item *ti;
1023     register int i;
1024     char *type, *name, *notifier=NONOTIFIER;
1025
1026     tconn = GetConn(as, 0);
1027     for(i=0;i<6;i++) parms[i] = "";
1028     for(i=0,ti=as->parms[3].items; (ti && i<6); ti=ti->next,i++) {
1029         parms[i] = ti->data;
1030     }
1031     name = as->parms[1].items->data;
1032     type = as->parms[2].items->data;
1033     if (ti = as->parms[4].items) {
1034         notifier = ti->data;
1035     }
1036     code = BOZO_CreateBnode(tconn, type, name, parms[0], parms[1], parms[2],
1037                             parms[3], parms[4], notifier);
1038     if (code) {
1039         printf("bos: failed to create new server instance %s of type '%s' (%s)\n", 
1040                name, type, em(code));
1041     }
1042     return code;
1043 }
1044
1045 static DeleteServer(as)
1046 register struct cmd_syndesc *as; {
1047     register struct rx_connection *tconn;
1048     register afs_int32 code;
1049     register struct cmd_item *ti;
1050
1051     code = 0;
1052     tconn = GetConn(as, 0);
1053     for(ti=as->parms[1].items; ti; ti=ti->next) {
1054         code = BOZO_DeleteBnode(tconn, ti->data);
1055         if (code) {
1056             if (code == BZBUSY)
1057                 printf("bos: can't delete running instance '%s'\n", ti->data);
1058             else
1059                 printf("bos: failed to delete instance '%s' (%s)\n",
1060                        ti->data, em(code));
1061         }
1062     }
1063     return code;
1064 }
1065
1066 static StartServer(as)
1067 register struct cmd_syndesc *as; {
1068     register struct rx_connection *tconn;
1069     register afs_int32 code;
1070     register struct cmd_item *ti;
1071
1072     code = 0;
1073     tconn = GetConn(as, 0);
1074     for(ti=as->parms[1].items; ti; ti=ti->next) {
1075         code = BOZO_SetStatus(tconn, ti->data, BSTAT_NORMAL);
1076         if (code)
1077             printf("bos: failed to start instance '%s' (%s)\n",
1078                    ti->data, em(code));
1079     }
1080     return code;
1081 }
1082
1083 static StopServer(as)
1084 register struct cmd_syndesc *as; {
1085     register struct rx_connection *tconn;
1086     register afs_int32 code;
1087     register struct cmd_item *ti;
1088
1089     code = 0;
1090     tconn = GetConn(as, 0);
1091     for(ti=as->parms[1].items; ti; ti=ti->next) {
1092         code = BOZO_SetStatus(tconn, ti->data, BSTAT_SHUTDOWN);
1093         if (code)
1094             printf("bos: failed to change stop instance '%s' (%s)\n",
1095                    ti->data, em(code));
1096     }
1097     if (as->parms[8].items) {
1098         code = BOZO_WaitAll(tconn);
1099         if (code)
1100             printf("bos: can't wait for processes to shutdown (%s)\n",
1101                    em(code));
1102     }
1103     return code;
1104 }
1105
1106 #define PARMBUFFERSSIZE 32
1107
1108 static DoSalvage(aconn, aparm1, aparm2, aoutName, showlog,parallel,atmpDir,orphans)
1109 struct rx_connection *aconn;
1110 char *aoutName;
1111 char *aparm1;
1112 char *aparm2; 
1113 afs_int32 showlog;
1114 char *parallel;
1115 char *atmpDir;
1116 char *orphans;
1117 {
1118     register afs_int32 code;
1119     char *parms[6];
1120     char buffer;
1121     char tbuffer[BOZO_BSSIZE];
1122     struct bozo_status istatus;
1123     struct rx_call *tcall;
1124     char *tp;
1125     FILE *outFile;
1126     int closeIt;
1127     char partName[20];  /* canonical name for partition */
1128     char pbuffer[PARMBUFFERSSIZE];
1129     afs_int32 partNumber;
1130     char *notifier = NONOTIFIER;
1131
1132     /* if a partition was specified, canonicalize the name, since
1133        the salvager has a stupid partition ID parser */
1134     if (aparm1) {
1135         partNumber = volutil_GetPartitionID(aparm1);
1136         if (partNumber < 0) {
1137             printf("bos: could not parse partition ID '%s'\n", aparm1);
1138             return EINVAL;
1139         }
1140         tp = volutil_PartitionName(partNumber);
1141         if (!tp) {
1142             printf("bos: internal error parsing partition ID '%s'\n", aparm1);
1143             return EINVAL;
1144         }
1145         strcpy(partName, tp);
1146     }
1147     else partName[0] = 0;
1148
1149     /* open the file name */
1150     if (aoutName) {
1151         outFile = fopen(aoutName, "w");
1152         if (!outFile) {
1153             printf("bos: can't open specified SalvageLog file '%s'\n",
1154                    aoutName);
1155             return ENOENT;
1156         }
1157         closeIt = 1;    /* close this file later */
1158     }
1159     else {
1160         outFile = stdout;
1161         closeIt = 0;    /* don't close this file later */
1162     }
1163
1164     for(code=2;code<6;code++) parms[code] = "";
1165     if (!aparm2) aparm2 = "";
1166     /* MUST pass canonical (wire-format) salvager path to bosserver */
1167     strncpy(tbuffer, AFSDIR_CANONICAL_SERVER_SALVAGER_FILEPATH, BOZO_BSSIZE);
1168     if (*aparm2 != 0) {
1169         if ( (strlen(tbuffer) + 1 + strlen(partName) + 1 + strlen(aparm2) + 1) > BOZO_BSSIZE ) {
1170            printf("bos: command line too big\n");
1171            return(E2BIG);
1172         }
1173         strcat(tbuffer, " ");
1174         strcat(tbuffer, partName);
1175         strcat(tbuffer, " ");
1176         strcat(tbuffer, aparm2);
1177     } else {
1178         if ( (strlen(tbuffer) + 4 + strlen(partName) + 1) > BOZO_BSSIZE ) {
1179            printf("bos: command line too big\n");
1180            return(E2BIG);
1181         }
1182         strcat (tbuffer, " -f ");
1183         strcat (tbuffer, partName);
1184     }
1185
1186     /* add the parallel option if given */
1187     if (parallel != (char *)0) {
1188         if ( (strlen(tbuffer) + 11 + strlen(parallel) + 1) > BOZO_BSSIZE ) {
1189            printf("bos: command line too big\n");
1190            return(E2BIG);
1191         }
1192         strcat(tbuffer, " -parallel ");
1193         strcat(tbuffer, parallel);
1194     }
1195
1196     /* add the tmpdir option if given */
1197     if (atmpDir != (char *)0) {
1198         if ( (strlen(tbuffer) + 9 + strlen(atmpDir) + 1) > BOZO_BSSIZE ) {
1199            printf("bos: command line too big\n");
1200            return(E2BIG);
1201         }
1202         strcat(tbuffer, " -tmpdir ");
1203         strcat(tbuffer, atmpDir);
1204     }
1205
1206     /* add the orphans option if given */
1207     if (orphans != (char *)0) {
1208         if ( (strlen(tbuffer) + 10 + strlen(orphans) + 1) > BOZO_BSSIZE ) {
1209            printf("bos: command line too big\n");
1210            return(E2BIG);
1211         }
1212         strcat(tbuffer, " -orphans ");
1213         strcat(tbuffer, orphans);
1214     }
1215
1216     if (mrafsParm.Optdebug)
1217         strcat(tbuffer," -debug");
1218     if (mrafsParm.Optnowrite)
1219         strcat(tbuffer," -nowrite");
1220     if (mrafsParm.Optforce)
1221         strcat(tbuffer," -force");
1222     if (mrafsParm.Optoktozap)
1223         strcat(tbuffer," -oktozap");
1224     if (mrafsParm.Optrootfiles)
1225         strcat(tbuffer," -rootfiles");
1226     if (mrafsParm.Optsalvagedirs)
1227         strcat(tbuffer," -salvagedirs");
1228     if (mrafsParm.Optblockreads)
1229         strcat(tbuffer," -blockreads");
1230     if (mrafsParm.OptListResidencies)
1231         strcat(tbuffer," -ListResidencies");
1232     if (mrafsParm.OptSalvageRemote)
1233         strcat(tbuffer," -SalvageRemote");
1234     if (mrafsParm.OptSalvageArchival)
1235         strcat(tbuffer," -SalvageArchival");
1236     if (mrafsParm.OptIgnoreCheck)
1237         strcat(tbuffer," -IgnoreCheck");
1238     if (mrafsParm.OptForceOnLine)
1239         strcat(tbuffer," -ForceOnLine");
1240     if (mrafsParm.OptUseRootDirACL)
1241         strcat(tbuffer," -UseRootDirACL");
1242     if (mrafsParm.OptTraceBadLinkCounts)
1243         strcat(tbuffer," -TraceBadLinkCounts");
1244     if (mrafsParm.OptDontAskFS)
1245         strcat(tbuffer," -DontAskFS");
1246     if (mrafsParm.OptLogLevel) {
1247         sprintf(pbuffer, " -LogLevel %ld", mrafsParm.OptLogLevel);
1248         strcat(tbuffer, pbuffer);
1249     }
1250     if (mrafsParm.OptRxDebug)
1251         strcat(tbuffer," -rxdebug");
1252     if (mrafsParm.OptResidencies) {
1253         sprintf(pbuffer, " -Residencies %lu", mrafsParm.OptResidencies);
1254         strcat(tbuffer, pbuffer);
1255     } 
1256
1257     parms[0] = tbuffer;
1258     parms[1] = "now";       /* when to do it */
1259     code = BOZO_CreateBnode(aconn, "cron", "salvage-tmp", parms[0], parms[1],
1260                             parms[2], parms[3], parms[4], notifier);
1261     if (code) goto done;
1262     /* now wait for bnode to disappear */
1263     while (1) {
1264         IOMGR_Sleep(5);
1265         tp = tbuffer;
1266         code = BOZO_GetInstanceInfo(aconn, "salvage-tmp", &tp, &istatus);
1267         if (code) break;
1268         printf("bos: waiting for salvage to complete.\n");
1269     }
1270     if (code != BZNOENT) {
1271         printf("bos: salvage failed (%s)\n", em(code));
1272         goto done;
1273     }
1274     code = 0;
1275
1276     /* now print the log file to the output file */
1277     printf("bos: salvage completed\n");
1278     if (aoutName || showlog) {
1279         fprintf(outFile, "SalvageLog:\n");
1280         tcall = rx_NewCall(aconn);
1281         /* MUST pass canonical (wire-format) salvager log path to bosserver */
1282         code = StartBOZO_GetLog(tcall, AFSDIR_CANONICAL_SERVER_SLVGLOG_FILEPATH);
1283         if (code) {
1284             rx_EndCall(tcall, code);
1285             goto done;
1286         }
1287         /* copy data */
1288         while(1) {
1289             code = rx_Read(tcall, &buffer, 1);
1290             if (code != 1) break;
1291             putc(buffer, outFile);
1292             if (buffer == 0) break;     /* the end delimeter */
1293         }
1294         code = rx_EndCall(tcall, 0);
1295         /* fall through into cleanup code */
1296     }
1297
1298   done:
1299     if (closeIt && outFile) fclose(outFile);
1300     return code;
1301 }
1302
1303 static GetLogCmd(as)
1304 register struct cmd_syndesc *as; {
1305     struct rx_connection *tconn;
1306     register struct rx_call *tcall;
1307     register afs_int32 code;
1308     char buffer;
1309     int error;
1310
1311     printf("Fetching log file '%s'...\n", as->parms[1].items->data);
1312     tconn = GetConn(as, 0);
1313     tcall = rx_NewCall(tconn);
1314     code = StartBOZO_GetLog(tcall, as->parms[1].items->data);
1315     if (code) {
1316         rx_EndCall(tcall, code);
1317         goto done;
1318     }
1319     /* copy data */
1320     error = 0;
1321     while(1) {
1322         code = rx_Read(tcall, &buffer, 1);
1323         if (code != 1) {
1324             error = EIO;
1325             break;
1326         }
1327         if (buffer == 0) break; /* the end delimeter */
1328         putchar(buffer);
1329     }
1330     code = rx_EndCall(tcall, error);
1331     /* fall through into cleanup code */
1332
1333   done:
1334     if (code)
1335         com_err("bos", code, "(while reading log)");
1336     return code;
1337 }
1338
1339 static SalvageCmd(as)
1340 struct cmd_syndesc *as; {
1341     register struct rx_connection *tconn;
1342     register afs_int32 code, rc, i;
1343     char *outName;
1344     char tname[BOZO_BSSIZE];
1345     afs_int32 newID;
1346     extern struct ubik_client *cstruct;
1347     afs_int32 curGoal, showlog = 0, mrafs = 0;
1348     char *parallel;
1349     char *tmpDir;
1350     char *orphans;
1351     char *tp;
1352
1353     bzero(&mrafsParm, sizeof(mrafsParm));
1354     
1355     /* parm 0 is machine name, 1 is partition, 2 is volume, 3 is -all flag */
1356     tconn = GetConn(as, 0);
1357
1358     /* Find out whether fileserver is running MR-AFS (has a scanner instance) */
1359     /* XXX this should really be done some other way, potentially by RPC */
1360     tp = &tname;
1361     if (code = BOZO_GetInstanceParm(tconn, "fs", 3, &tp) == 0)
1362        mrafs = 1;
1363
1364     /* we can do a volume, a partition or the whole thing, but not mixtures
1365      * thereof */
1366     if (!as->parms[1].items && as->parms[2].items) {
1367         printf("bos: must specify partition to salvage individual volume.\n");
1368         return -1;
1369     }
1370     if (as->parms[5].items && as->parms[3].items) {
1371         printf("bos: can not specify both -file and -showlog.\n");
1372         return -1;
1373     }
1374     if (as->parms[4].items && (as->parms[1].items || as->parms[2].items)) {
1375         printf("bos: can not specify -all with other flags.\n");
1376         return -1;
1377     }
1378
1379     /* get the output file name, if any */
1380     if (as->parms[3].items)
1381         outName = as->parms[3].items->data;
1382     else
1383         outName = (char *) 0;
1384
1385     if (as->parms[5].items)
1386         showlog = 1;
1387
1388     /* parallel option */
1389     parallel = (char *) 0;
1390     if (as->parms[6].items)
1391         parallel = as->parms[6].items->data;
1392
1393     /* get the tmpdir filename if any */
1394     tmpDir = (char *)0;
1395     if (as->parms[7].items)
1396         tmpDir = as->parms[7].items->data;
1397
1398     /* -orphans option */
1399     orphans = (char *)0;
1400     if (as->parms[8].items) {
1401         if (mrafs) {
1402             printf("Can't specify -orphans for MR-AFS fileserver\n");
1403             return EINVAL;
1404         }
1405         orphans = as->parms[8].items->data;
1406     }
1407     
1408     if (mrafs) {
1409         if (as->parms[MRAFS_OFFSET].items)
1410             mrafsParm.Optdebug = 1;
1411         if (as->parms[MRAFS_OFFSET + 1].items)
1412             mrafsParm.Optnowrite = 1;
1413         if (as->parms[MRAFS_OFFSET + 2].items)
1414             mrafsParm.Optforce = 1;
1415         if (as->parms[MRAFS_OFFSET + 3].items)
1416             mrafsParm.Optoktozap = 1;
1417         if (as->parms[MRAFS_OFFSET + 4].items)
1418             mrafsParm.Optrootfiles = 1;
1419         if (as->parms[MRAFS_OFFSET + 5].items)
1420             mrafsParm.Optsalvagedirs = 1;
1421         if (as->parms[MRAFS_OFFSET + 6].items)
1422             mrafsParm.Optblockreads = 1;
1423         if (as->parms[MRAFS_OFFSET + 7].items)
1424             mrafsParm.OptListResidencies = 1;
1425         if (as->parms[MRAFS_OFFSET + 8].items)
1426             mrafsParm.OptSalvageRemote = 1;
1427         if (as->parms[MRAFS_OFFSET + 9].items)
1428             mrafsParm.OptSalvageArchival = 1;
1429         if (as->parms[MRAFS_OFFSET + 10].items)
1430             mrafsParm.OptIgnoreCheck = 1;
1431         if (as->parms[MRAFS_OFFSET + 11].items)
1432             mrafsParm.OptForceOnLine = 1;
1433         if (as->parms[MRAFS_OFFSET + 12].items)
1434             mrafsParm.OptUseRootDirACL = 1;
1435         if (as->parms[MRAFS_OFFSET + 13].items)
1436             mrafsParm.OptTraceBadLinkCounts = 1;
1437         if (as->parms[MRAFS_OFFSET + 14].items)
1438             mrafsParm.OptDontAskFS = 1;
1439         if (as->parms[MRAFS_OFFSET + 15].items)
1440             mrafsParm.OptLogLevel = atoi(as->parms[MRAFS_OFFSET + 15].items->data);
1441         if (as->parms[MRAFS_OFFSET + 16].items)
1442             mrafsParm.OptRxDebug = 1;
1443         if (as->parms[MRAFS_OFFSET + 17].items) {                             
1444            if (as->parms[MRAFS_OFFSET + 8].items || 
1445                as->parms[MRAFS_OFFSET + 9].items) {
1446                 printf("Can't specify -Residencies with -SalvageRemote or -SalvageArchival\n");
1447                 return EINVAL;
1448             }
1449             code = GetUInt32(as->parms[MRAFS_OFFSET + 17].items->data, 
1450                                        &mrafsParm.OptResidencies);
1451             if (code) {
1452                 printf("bos: '%s' is not a valid residency mask.\n",
1453                        as->parms[MRAFS_OFFSET + 13].items->data);
1454                 return code;
1455             }
1456         }
1457     } else {
1458        int stop = 0;
1459
1460        for (i = 9; i < ADDPARMOFFSET; i++) {
1461            if (as->parms[i].items) {
1462                printf(" %s only possible for MR-AFS fileserver.\n",
1463                        as->parms[i].name);
1464                stop = 1;
1465            }
1466        }
1467        if (stop) exit(1);
1468     }
1469
1470     if (as->parms[4].items) {
1471         /* salvage whole enchilada */
1472         curGoal = GetServerGoal(tconn, "fs");
1473         if (curGoal == BSTAT_NORMAL) {
1474             printf("bos: shutting down fs.\n");
1475             code = BOZO_SetTStatus(tconn, "fs", BSTAT_SHUTDOWN);
1476             if (code) {
1477                 printf("bos: failed to stop 'fs' (%s)\n", em(code));
1478                 return code;
1479             }
1480             code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1481             if (code)
1482                 printf("bos: failed to wait for file server shutdown, continuing.\n");
1483         }
1484         /* now do the salvage operation */
1485         printf("Starting salvage.\n");
1486         rc = DoSalvage(tconn, (char *) 0, (char *) 0, outName, showlog,parallel,tmpDir,orphans);
1487         if (rc) printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1488         if (curGoal == BSTAT_NORMAL) {
1489             printf("bos: restarting fs.\n");
1490             code = BOZO_SetTStatus(tconn, "fs", BSTAT_NORMAL);
1491             if (code) {
1492                 printf("bos: failed to restart 'fs' (%s)\n", em(code));
1493                 return code;
1494             }
1495         }
1496         if (rc) return rc;
1497     }
1498     else if (!as->parms[2].items) {
1499         if (!as->parms[1].items) {
1500             printf("bos: must specify -all switch to salvage all partitions.\n");
1501             return -1;
1502         }
1503         if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1504             /* can't parse volume ID, so complain before shutting down
1505              * file server.
1506              */
1507             printf("bos: can't interpret %s as partition ID.\n",
1508                    as->parms[1].items->data);
1509             return -1;
1510         }
1511         curGoal = GetServerGoal(tconn, "fs");
1512         /* salvage a whole partition (specified by parms[1]) */
1513         if (curGoal == BSTAT_NORMAL) {
1514             printf("bos: shutting down fs.\n");
1515             code = BOZO_SetTStatus(tconn, "fs", BSTAT_SHUTDOWN);
1516             if (code) {
1517                 printf("bos: can't stop 'fs' (%s)\n", em(code));
1518                 return code;
1519             }
1520             code = BOZO_WaitAll(tconn); /* wait for shutdown to complete */
1521             if (code)
1522                 printf("bos: failed to wait for file server shutdown, continuing.\n");
1523         }
1524         /* now do the salvage operation */
1525         printf("Starting salvage.\n");
1526         rc = DoSalvage(tconn, as->parms[1].items->data, (char *) 0,
1527                        outName, showlog,parallel,tmpDir,orphans);
1528         if (rc) printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1529         if (curGoal == BSTAT_NORMAL) {
1530             printf("bos: restarting fs.\n");
1531             code = BOZO_SetTStatus(tconn, "fs", BSTAT_NORMAL);
1532             if (code) {
1533                 printf("bos: failed to restart 'fs' (%s)\n", em(code));
1534                 return code;
1535             }
1536         }
1537         if (rc) return rc;
1538     }
1539     else {
1540         /* salvage individual volume (don't shutdown fs first), just use
1541          * single-shot cron bnode.  Must leave server running when using this
1542          * option, since salvager will ask file server for the volume */
1543         char *tmpname;
1544         afs_int32 err;
1545         const char *confdir;
1546         int localauth;
1547
1548         if (as->parms[ADDPARMOFFSET].items) 
1549             tmpname = as->parms[ADDPARMOFFSET].items->data;
1550         else tmpname = (char *) 0;
1551
1552         localauth = (as->parms[ADDPARMOFFSET + 2].items != 0);
1553         confdir = (localauth ? AFSDIR_SERVER_ETC_DIRPATH : AFSDIR_CLIENT_ETC_DIRPATH);
1554         code = vsu_ClientInit(/* noauth */ 1, confdir, tmpname,
1555                               /* server auth */ 0, &cstruct, (int (*)()) 0);
1556         if (code == 0) {
1557             newID = vsu_GetVolumeID(as->parms[2].items->data, cstruct, &err);
1558             if (newID == 0) {
1559                 printf("bos: can't interpret %s as volume name or ID\n", as->parms[2].items->data);
1560                 return -1;
1561             }
1562             sprintf(tname, "%u", newID);
1563         }
1564         else {
1565             printf("bos: can't initialize volume system client (code %d), trying anyway.\n",
1566                    as->parms[2].items->data, code);
1567             strncpy(tname, as->parms[2].items->data, sizeof(tname));
1568         }
1569         if (volutil_GetPartitionID(as->parms[1].items->data) < 0) {
1570             /* can't parse volume ID, so complain before shutting down
1571              * file server.
1572              */
1573             printf("bos: can't interpret %s as partition ID.\n",
1574                    as->parms[1].items->data);
1575             return -1;
1576         }
1577         printf("Starting salvage.\n");
1578         rc = DoSalvage(tconn, as->parms[1].items->data, tname, outName,
1579                        showlog,parallel,tmpDir,orphans);
1580         if (rc) {
1581            printf("bos: failed to start 'salvager' (%s)\n", em(rc));
1582            return rc;
1583         }
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 = (char *) 0;
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 all 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 }