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