1 | /* |
---|
2 | * $Id: main.c,v 1.31 1992-12-22 17:48:00 probe Exp $ |
---|
3 | * |
---|
4 | * Copyright (c) 1988,1992 by the Massachusetts Institute of Technology. |
---|
5 | */ |
---|
6 | |
---|
7 | static char *rcsid_main_c = "$Id: main.c,v 1.31 1992-12-22 17:48:00 probe Exp $"; |
---|
8 | |
---|
9 | #include "attach.h" |
---|
10 | #include <signal.h> |
---|
11 | #include <string.h> |
---|
12 | |
---|
13 | int verbose = 1, debug_flag = 0, map_anyway = 1, do_nfsid = 1; |
---|
14 | int print_path = 0, explicit = 0, owner_check = 0, override = 0; |
---|
15 | int owner_list = 1, clean_detach = 0, exp_allow = 1, exp_mntpt = 1; |
---|
16 | |
---|
17 | /* real userid of proces, effective userid of process, userid used |
---|
18 | for attachtab manipulation */ |
---|
19 | int real_uid, effective_uid, owner_uid; |
---|
20 | |
---|
21 | int lock_filesystem = 0; |
---|
22 | int nfs_root_hack = 1; /* By default, translate for the */ |
---|
23 | /* default mountpoint / as /root */ |
---|
24 | |
---|
25 | int keep_mount = 0; /* By default, let mounted filesystems */ |
---|
26 | /* that are not in attachtab get */ |
---|
27 | /* unmounted when that filesystem gets */ |
---|
28 | /* detached. */ |
---|
29 | int error_status = ERR_NONE; |
---|
30 | int force = 0; |
---|
31 | #ifdef ZEPHYR |
---|
32 | int use_zephyr = 1; |
---|
33 | #endif /* ZEPHYR */ |
---|
34 | char override_mode, *mount_options, *filsys_type; |
---|
35 | char *mntpt; |
---|
36 | int override_suid, default_suid, skip_fsck, lookup; |
---|
37 | char *spoofhost, *attachtab_fn = NULL, *mtab_fn = NULL; |
---|
38 | char *fsck_fn = NULL, *aklog_fn = NULL; |
---|
39 | char *nfs_mount_dir = NULL, *afs_mount_dir = NULL; |
---|
40 | char *progname; |
---|
41 | |
---|
42 | #ifdef NFS |
---|
43 | int nfs_attach(), nfs_detach(); |
---|
44 | char **nfs_explicit(); |
---|
45 | #endif |
---|
46 | #ifdef RVD |
---|
47 | int rvd_attach(), rvd_detach(); |
---|
48 | char **rvd_explicit(); |
---|
49 | #endif |
---|
50 | #ifdef AFS |
---|
51 | int afs_attach(), afs_detach(); |
---|
52 | char **afs_explicit(); |
---|
53 | #endif |
---|
54 | #ifdef UFS |
---|
55 | int ufs_attach(), ufs_detach(); |
---|
56 | #endif |
---|
57 | int err_attach(), null_detach(); |
---|
58 | char **ufs_explicit(); |
---|
59 | int mul_attach(), mul_detach(); |
---|
60 | |
---|
61 | struct _fstypes fstypes[] = { |
---|
62 | { "---", 0, -1, 0, (char *) 0, 0, null_detach, 0 }, /* The null type */ |
---|
63 | #ifdef NFS |
---|
64 | { "NFS", TYPE_NFS, MOUNT_NFS, |
---|
65 | AT_FS_MNTPT | AT_FS_REMOTE | AT_FS_MNTPT_CANON, |
---|
66 | "rwnm", nfs_attach, nfs_detach, nfs_explicit }, |
---|
67 | #endif |
---|
68 | #ifdef RVD |
---|
69 | { "RVD", TYPE_RVD, MOUNT_UFS, |
---|
70 | AT_FS_MNTPT | AT_FS_REMOTE | AT_FS_MNTPT_CANON, |
---|
71 | "rw", rvd_attach, rvd_detach, rvd_explicit }, |
---|
72 | #endif |
---|
73 | #ifdef UFS |
---|
74 | { "UFS", TYPE_UFS, MOUNT_UFS, |
---|
75 | AT_FS_MNTPT | AT_FS_MNTPT_CANON, |
---|
76 | "rw", ufs_attach, ufs_detach, ufs_explicit }, |
---|
77 | #endif |
---|
78 | #ifdef AFS |
---|
79 | { "AFS", TYPE_AFS, -1, |
---|
80 | AT_FS_MNTPT | AT_FS_PARENTMNTPT, |
---|
81 | "nrw", afs_attach, afs_detach, afs_explicit }, |
---|
82 | #endif |
---|
83 | { "ERR", TYPE_ERR, -1, 0, (char *) 0, err_attach, 0, 0 }, |
---|
84 | { "MUL", TYPE_MUL, -1, 0, "-", mul_attach, mul_detach, 0 }, |
---|
85 | { 0, -1, 0, 0, (char *) 0, 0, 0, 0 } |
---|
86 | }; |
---|
87 | |
---|
88 | /* |
---|
89 | * Primary entry point -- look at argv[0] to figure out who we are and |
---|
90 | * dispatch to the proper handler accordingly. |
---|
91 | */ |
---|
92 | |
---|
93 | main(argc, argv) |
---|
94 | int argc; |
---|
95 | char *argv[]; |
---|
96 | { |
---|
97 | char *ptr; |
---|
98 | extern sig_catch sig_trap(); |
---|
99 | #ifdef POSIX |
---|
100 | struct sigaction sig; |
---|
101 | #endif |
---|
102 | |
---|
103 | /* Stop overriding my explicit file modes! */ |
---|
104 | umask(022); |
---|
105 | |
---|
106 | /* Install signal handlers */ |
---|
107 | #ifdef POSIX |
---|
108 | sig.sa_handler = sig_trap; |
---|
109 | sigemptyset(&sig.sa_mask); |
---|
110 | sig.sa_flags = 0; |
---|
111 | sigaction(SIGTERM, &sig, NULL); |
---|
112 | sigaction(SIGINT, &sig, NULL); |
---|
113 | sigaction(SIGHUP, &sig, NULL); |
---|
114 | #else |
---|
115 | (void) signal (SIGTERM, sig_trap); |
---|
116 | (void) signal (SIGINT, sig_trap); |
---|
117 | (void) signal (SIGHUP, sig_trap); |
---|
118 | #endif |
---|
119 | |
---|
120 | real_uid = owner_uid = getuid(); |
---|
121 | effective_uid = geteuid(); |
---|
122 | |
---|
123 | progname = argv[0]; |
---|
124 | ptr = rindex(progname, '/'); |
---|
125 | if (ptr) |
---|
126 | progname = ptr+1; |
---|
127 | |
---|
128 | attachtab_fn = strdup(ATTACHTAB); |
---|
129 | mtab_fn = strdup(MTAB); |
---|
130 | #ifdef AFS |
---|
131 | aklog_fn = strdup(AKLOG_FULLNAME); |
---|
132 | afs_mount_dir = strdup(AFS_MOUNT_DIR); |
---|
133 | #endif |
---|
134 | fsck_fn = strdup(FSCK_FULLNAME); |
---|
135 | |
---|
136 | /* |
---|
137 | * User can explicitly specify attach, detach, or nfsid by using the |
---|
138 | * -P option as the first command option. |
---|
139 | */ |
---|
140 | |
---|
141 | if (argv[1] && !strncmp(argv[1], "-P", 2)) { |
---|
142 | progname = argv[1]+2; |
---|
143 | if (*progname) { |
---|
144 | argv += 1; |
---|
145 | argc -= 1; |
---|
146 | } else { |
---|
147 | if (progname = argv[2]) { |
---|
148 | argv += 2; |
---|
149 | argc -= 2; |
---|
150 | } else { |
---|
151 | fprintf(stderr, |
---|
152 | "Must specify attach, detach nfsid, fsid, or zinit!\n"); |
---|
153 | exit(ERR_BADARGS); |
---|
154 | } |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | if (!strcmp(progname, ATTACH_CMD)) |
---|
159 | exit(attachcmd(argc, argv)); |
---|
160 | if (!strcmp(progname, DETACH_CMD)) |
---|
161 | exit(detachcmd(argc, argv)); |
---|
162 | #ifdef KERBEROS |
---|
163 | #ifdef NFS |
---|
164 | if (!strcmp(progname, NFSID_CMD)) |
---|
165 | { |
---|
166 | filsys_type = "NFS"; |
---|
167 | exit(fsidcmd(argc, argv)); |
---|
168 | } |
---|
169 | #endif |
---|
170 | if (!strcmp(progname, FSID_CMD)) |
---|
171 | exit(fsidcmd(argc, argv)); |
---|
172 | #endif |
---|
173 | #ifdef ZEPHYR |
---|
174 | if (!strcmp(progname, ZINIT_CMD)) |
---|
175 | exit(zinitcmd(argc, argv)); |
---|
176 | #endif |
---|
177 | |
---|
178 | fprintf(stderr, "Not invoked with attach, detach, nfsid, fsid, or zinit!\n"); |
---|
179 | exit(ERR_BADARGS); |
---|
180 | } |
---|
181 | |
---|
182 | #ifdef KERBEROS |
---|
183 | /* |
---|
184 | * Command handler for nfsid. |
---|
185 | */ |
---|
186 | fsidcmd(argc, argv) |
---|
187 | int argc; |
---|
188 | char *argv[]; |
---|
189 | { |
---|
190 | extern struct _attachtab *attachtab_first; |
---|
191 | int gotname, i, op, filsysp, hostp; |
---|
192 | #ifdef AFS |
---|
193 | int cell_sw; |
---|
194 | #endif |
---|
195 | char *ops; |
---|
196 | struct hostent *hent; |
---|
197 | char hostname[BUFSIZ]; |
---|
198 | register struct _attachtab *atp; |
---|
199 | struct in_addr addr; |
---|
200 | static struct command_list options[] = { |
---|
201 | { "-verbose", "-v" }, |
---|
202 | { "-quiet", "-q" }, |
---|
203 | { "-debug", "-d" }, |
---|
204 | { "-map", "-m" }, |
---|
205 | { "-unmap", "-u" }, |
---|
206 | { "-purge", "-p" }, |
---|
207 | { "-purgeuser", "-r" }, |
---|
208 | { "-spoofhost", "-s" }, |
---|
209 | { "-filsys", "-f" }, |
---|
210 | { "-host", "-h" }, |
---|
211 | #ifdef AFS |
---|
212 | { "-cell", "-c" }, |
---|
213 | #endif |
---|
214 | { "-user", "-U" }, |
---|
215 | { "-all", "-a" }, |
---|
216 | { 0, 0 }}; |
---|
217 | |
---|
218 | check_root_privs(progname); |
---|
219 | read_config_file(ATTACHCONFFILE); |
---|
220 | |
---|
221 | gotname = 0; |
---|
222 | filsysp = 1; |
---|
223 | hostp = 0; |
---|
224 | verbose = 1; |
---|
225 | #ifdef AFS |
---|
226 | cell_sw = 0; |
---|
227 | #endif |
---|
228 | error_status = ERR_NONE; |
---|
229 | |
---|
230 | op = MOUNTPROC_KUIDMAP; |
---|
231 | ops = "mapped"; |
---|
232 | |
---|
233 | #ifdef ATHENA_COMPAT73 |
---|
234 | if (filsys_type && !strcmp(filsys_type, "NFS")) { |
---|
235 | hostp = 1; |
---|
236 | filsysp = 0; |
---|
237 | } else { |
---|
238 | hostp = filsysp = 1; |
---|
239 | } |
---|
240 | #endif |
---|
241 | |
---|
242 | for (i=1;i<argc;i++) { |
---|
243 | if (*argv[i] == '-') { |
---|
244 | switch (internal_getopt(argv[i], options)) { |
---|
245 | case 'v': |
---|
246 | verbose = 1; |
---|
247 | break; |
---|
248 | case 'q': |
---|
249 | verbose = 0; |
---|
250 | break; |
---|
251 | case 'd': |
---|
252 | debug_flag = 1; |
---|
253 | break; |
---|
254 | case 'm': |
---|
255 | op = MOUNTPROC_KUIDMAP; |
---|
256 | ops = "mapped"; |
---|
257 | break; |
---|
258 | case 'u': |
---|
259 | op = MOUNTPROC_KUIDUMAP; |
---|
260 | ops = "unmapped"; |
---|
261 | break; |
---|
262 | case 'r': |
---|
263 | op = MOUNTPROC_KUIDUPURGE; |
---|
264 | ops = "mappings user-purged"; |
---|
265 | break; |
---|
266 | case 'p': |
---|
267 | if (!trusted_user(real_uid)) { |
---|
268 | fprintf(stderr, |
---|
269 | "%s: nfsid purge is a privileged operation\n", |
---|
270 | progname); |
---|
271 | return ERR_NFSIDPERM; |
---|
272 | } |
---|
273 | op = MOUNTPROC_KUIDPURGE; |
---|
274 | ops = "mappings purged"; |
---|
275 | break; |
---|
276 | #ifdef AFS |
---|
277 | case 'c': |
---|
278 | filsysp = 0; |
---|
279 | cell_sw = 1; |
---|
280 | break; |
---|
281 | #endif |
---|
282 | case 'f': |
---|
283 | filsysp = 1; |
---|
284 | hostp = 0; |
---|
285 | break; |
---|
286 | case 'h': |
---|
287 | filsysp = 0; |
---|
288 | hostp = 1; |
---|
289 | break; |
---|
290 | case 'U': |
---|
291 | ++i; |
---|
292 | if (trusted_user(real_uid)) { |
---|
293 | if (!argv[i]) { |
---|
294 | fprintf(stderr, "%s: Username required with -U.\n", |
---|
295 | progname); |
---|
296 | return ERR_BADARGS; |
---|
297 | } |
---|
298 | owner_uid = parse_username(argv[i]); |
---|
299 | } else { |
---|
300 | fprintf(stderr, |
---|
301 | "%s: You are not authorized to use the -user option\n", progname); |
---|
302 | } |
---|
303 | break; |
---|
304 | case 's': |
---|
305 | if (i == argc-1) { |
---|
306 | fprintf(stderr, "%s: No spoof host specified\n", progname); |
---|
307 | return (ERR_BADARGS); |
---|
308 | } |
---|
309 | spoofhost = argv[++i]; |
---|
310 | break; |
---|
311 | case 'a': |
---|
312 | /* |
---|
313 | * Read the attachtab one entry at a time, and perform the |
---|
314 | * operation on each host found therein. Note this |
---|
315 | * will even include hosts that are associated with |
---|
316 | * filesystems in the process of being attached or |
---|
317 | * detached. Assume that the -a option implies more |
---|
318 | * than one file for the exit status computation. |
---|
319 | */ |
---|
320 | lock_attachtab(); |
---|
321 | get_attachtab(); |
---|
322 | unlock_attachtab(); |
---|
323 | atp = attachtab_first; |
---|
324 | while (atp) { |
---|
325 | if (atp->fs->type == TYPE_MUL) { |
---|
326 | /* Do nothing |
---|
327 | * Type MUL filesystems are authenticated |
---|
328 | * by their individual parts. |
---|
329 | */ |
---|
330 | } else if ((op == MOUNTPROC_KUIDMAP || |
---|
331 | op == MOUNTPROC_KUIDUMAP) && |
---|
332 | !is_an_owner(atp,owner_uid)) { |
---|
333 | /* Do nothing |
---|
334 | * Only map/unmap to filesystems that the |
---|
335 | * user has attached. |
---|
336 | * |
---|
337 | * Purges apply to ALL attached filesystems. |
---|
338 | */ |
---|
339 | } else if (atp->fs->type == TYPE_NFS) { |
---|
340 | if ((op == MOUNTPROC_KUIDMAP || |
---|
341 | op == MOUNTPROC_KUIDUMAP) && |
---|
342 | atp->mode == 'n') { |
---|
343 | /* Do nothing */ |
---|
344 | } else if (nfsid(atp->host, atp->hostaddr[0], |
---|
345 | op, 1, atp->hesiodname, 0, |
---|
346 | owner_uid) == SUCCESS && |
---|
347 | verbose) |
---|
348 | printf("%s: %s %s\n", progname, |
---|
349 | atp->hesiodname, ops); |
---|
350 | #ifdef AFS |
---|
351 | } else if (atp->fs->type == TYPE_AFS && |
---|
352 | op == MOUNTPROC_KUIDMAP) { |
---|
353 | /* We only support map operations on AFS */ |
---|
354 | if (atp->mode != 'n' && |
---|
355 | (afs_auth(atp->hesiodname, atp->hostdir) |
---|
356 | == SUCCESS) && verbose) |
---|
357 | printf("%s: %s %s\n", progname, |
---|
358 | atp->hesiodname, ops); |
---|
359 | #endif |
---|
360 | } else |
---|
361 | if (verbose) |
---|
362 | printf("%s: %s ignored (operation not supported on %s)\n", |
---|
363 | progname, atp->hesiodname, |
---|
364 | atp->fs->name); |
---|
365 | atp = atp->next; |
---|
366 | } |
---|
367 | free_attachtab(); |
---|
368 | gotname = 2; |
---|
369 | break; |
---|
370 | default: |
---|
371 | fprintf(stderr, "%s: Unknown switch %s\n", progname, argv[i]); |
---|
372 | return (ERR_BADARGS); |
---|
373 | } |
---|
374 | continue; |
---|
375 | } |
---|
376 | gotname++; |
---|
377 | |
---|
378 | #ifdef AFS |
---|
379 | if (cell_sw) { |
---|
380 | afs_auth_to_cell(argv[i]); |
---|
381 | continue; |
---|
382 | } |
---|
383 | #endif |
---|
384 | |
---|
385 | if (filsysp) { |
---|
386 | lock_attachtab(); |
---|
387 | get_attachtab(); |
---|
388 | unlock_attachtab(); |
---|
389 | /* |
---|
390 | * Lookup the specified filsys name and perform an nfsid |
---|
391 | * on the host associated with it. |
---|
392 | */ |
---|
393 | if (atp = attachtab_lookup(argv[i])) { |
---|
394 | if (atp->fs->type == TYPE_MUL) |
---|
395 | gotname = 2; |
---|
396 | fsid_filsys(atp, op, ops, argv[i], owner_uid); |
---|
397 | continue; |
---|
398 | } else if (!hostp) { |
---|
399 | error_status = ERR_NFSIDNOTATTACHED; |
---|
400 | fprintf(stderr, "%s: %s not attached\n", progname, argv[i]); |
---|
401 | } |
---|
402 | } |
---|
403 | |
---|
404 | if (hostp) { |
---|
405 | /* |
---|
406 | * Perform an nfsid on the specified host. |
---|
407 | */ |
---|
408 | hent = gethostbyname(argv[i]); |
---|
409 | if (!hent) { |
---|
410 | fprintf(stderr, "%s: Can't resolve %s\n", progname, argv[i]); |
---|
411 | error_status = ERR_NFSIDBADHOST; |
---|
412 | } |
---|
413 | else { |
---|
414 | strcpy(hostname, hent->h_name); |
---|
415 | bcopy(hent->h_addr_list[0], &addr, 4); |
---|
416 | if ((nfsid(hostname, addr, |
---|
417 | op, 1, "nfsid", 0, owner_uid) == SUCCESS) && verbose) |
---|
418 | printf("%s: %s %s\n", progname, hostname, ops); |
---|
419 | } |
---|
420 | } |
---|
421 | } |
---|
422 | |
---|
423 | if (gotname == 1) |
---|
424 | return (error_status); |
---|
425 | if (gotname > 1) |
---|
426 | return (error_status ? ERR_SOMETHING : ERR_NONE); |
---|
427 | |
---|
428 | fprintf(stderr, "Usage: nfsid [options] [host host ...] or [filsys filsys ...]\n"); |
---|
429 | return (ERR_BADARGS); |
---|
430 | } |
---|
431 | #endif |
---|
432 | |
---|
433 | fsid_filsys(atp, op, ops, filsys, uid) |
---|
434 | struct _attachtab *atp; |
---|
435 | int op; |
---|
436 | char *ops; |
---|
437 | char *filsys; |
---|
438 | int uid; |
---|
439 | { |
---|
440 | char mul_buf[BUFSIZ], *cp; |
---|
441 | |
---|
442 | if (atp->fs->type == TYPE_MUL) { |
---|
443 | strcpy(mul_buf, atp->hostdir); |
---|
444 | cp = strtok(mul_buf, ","); |
---|
445 | while (cp) { |
---|
446 | atp = attachtab_lookup(cp); |
---|
447 | if (atp) |
---|
448 | fsid_filsys(atp,op,ops,atp->hesiodname,uid); |
---|
449 | cp = strtok(NULL, ","); |
---|
450 | } |
---|
451 | #ifdef NFS |
---|
452 | } else if (atp->fs->type == TYPE_NFS) { |
---|
453 | if ((nfsid(atp->host, atp->hostaddr[0], op, 1, |
---|
454 | filsys, 0, owner_uid) == SUCCESS) && |
---|
455 | verbose) |
---|
456 | printf("%s: %s %s\n", progname, filsys, ops); |
---|
457 | #endif |
---|
458 | #ifdef AFS |
---|
459 | } else if (atp->fs->type == TYPE_AFS) { |
---|
460 | if (op == MOUNTPROC_KUIDMAP && |
---|
461 | (afs_auth(atp->hesiodname, atp->hostdir) == SUCCESS) |
---|
462 | && verbose) |
---|
463 | printf("%s: %s %s\n", progname, filsys, ops); |
---|
464 | #endif |
---|
465 | } |
---|
466 | } |
---|
467 | |
---|
468 | attachcmd(argc, argv) |
---|
469 | int argc; |
---|
470 | char *argv[]; |
---|
471 | { |
---|
472 | int gotname, i; |
---|
473 | int print_host = 0; |
---|
474 | |
---|
475 | static struct command_list options[] = { |
---|
476 | { "-verbose", "-v" }, |
---|
477 | { "-quiet", "-q" }, |
---|
478 | { "-force", "-f" }, |
---|
479 | { "-printpath", "-p" }, |
---|
480 | { "-lookup", "-l" }, |
---|
481 | { "-debug", "-d" }, |
---|
482 | { "-map", "-y" }, |
---|
483 | { "-nomap", "-n" }, |
---|
484 | { "-remap", "-g" }, |
---|
485 | { "-noremap", "-a" }, |
---|
486 | #ifdef ZEPHYR |
---|
487 | { "-zephyr", "-z" }, |
---|
488 | { "-nozephyr", "-h" }, |
---|
489 | #endif /* ZEPHYR */ |
---|
490 | { "-readonly", "-r" }, |
---|
491 | { "-write", "-w" }, |
---|
492 | { "-mountpoint", "-m" }, |
---|
493 | { "-noexplicit", "-x" }, |
---|
494 | { "-explicit", "-e" }, |
---|
495 | { "-type", "-t" }, |
---|
496 | { "-mountoptions", "-o" }, |
---|
497 | { "-spoofhost", "-s" }, |
---|
498 | { "-nosetuid", "-N" }, |
---|
499 | { "-setuid", "-S" }, |
---|
500 | { "-nosuid", "-N" }, |
---|
501 | { "-suid", "-S" }, |
---|
502 | { "-override", "-O" }, |
---|
503 | { "-skipfsck", "-F" }, |
---|
504 | { "-lock", "-L" }, |
---|
505 | { "-user", "-U" }, |
---|
506 | { "-host", "-H" }, |
---|
507 | { 0, 0 }}; |
---|
508 | |
---|
509 | read_config_file(ATTACHCONFFILE); |
---|
510 | |
---|
511 | check_root_privs(progname); |
---|
512 | default_suid = 0; |
---|
513 | |
---|
514 | gotname = 0; |
---|
515 | |
---|
516 | verbose = 1; |
---|
517 | explicit = 0; |
---|
518 | force = 0; |
---|
519 | lookup = 0; |
---|
520 | mntpt = (char *)NULL; |
---|
521 | override_mode = '\0'; |
---|
522 | override_suid = -1; /* -1 means use default */ |
---|
523 | mount_options = ""; |
---|
524 | error_status = ERR_NONE; |
---|
525 | map_anyway = 1; |
---|
526 | |
---|
527 | if (argc == 1) |
---|
528 | return (attach_print(0)); |
---|
529 | |
---|
530 | for (i=1;i<argc;i++) { |
---|
531 | if (*argv[i] == '-') { |
---|
532 | switch (internal_getopt(argv[i], options)) { |
---|
533 | case 'v': |
---|
534 | verbose = 1; |
---|
535 | print_path = 0; |
---|
536 | break; |
---|
537 | case 'l': |
---|
538 | lookup = 1; |
---|
539 | break; |
---|
540 | case 'q': |
---|
541 | verbose = 0; |
---|
542 | break; |
---|
543 | case 'd': |
---|
544 | debug_flag = 1; |
---|
545 | break; |
---|
546 | case 'y': |
---|
547 | do_nfsid = 1; |
---|
548 | break; |
---|
549 | case 'n': |
---|
550 | do_nfsid = 0; |
---|
551 | map_anyway = 0; |
---|
552 | break; |
---|
553 | case 'p': |
---|
554 | print_path = 1; |
---|
555 | verbose = 0; |
---|
556 | break; |
---|
557 | case 'm': |
---|
558 | if (i == argc-1) { |
---|
559 | fprintf(stderr, "%s: No mount point specified\n", |
---|
560 | progname); |
---|
561 | return (ERR_BADARGS); |
---|
562 | } |
---|
563 | if (exp_mntpt || trusted_user(real_uid)) { |
---|
564 | mntpt = argv[++i]; |
---|
565 | } else { |
---|
566 | fprintf(stderr, |
---|
567 | "%s: You are not allowed to use the -mountpoint option\n", |
---|
568 | progname); |
---|
569 | i++; |
---|
570 | } |
---|
571 | break; |
---|
572 | case 'r': |
---|
573 | override_mode = 'r'; |
---|
574 | break; |
---|
575 | case 'w': |
---|
576 | override_mode = 'w'; |
---|
577 | break; |
---|
578 | case 'f': |
---|
579 | force = 1; |
---|
580 | break; |
---|
581 | case 'g': |
---|
582 | map_anyway = 1; |
---|
583 | break; |
---|
584 | case 'a': |
---|
585 | map_anyway = 0; |
---|
586 | break; |
---|
587 | #ifdef ZEPHYR |
---|
588 | case 'z': |
---|
589 | use_zephyr = 1; |
---|
590 | break; |
---|
591 | case 'h': |
---|
592 | use_zephyr = 0; |
---|
593 | break; |
---|
594 | #endif /* ZEPHYR */ |
---|
595 | case 'x': |
---|
596 | explicit = 0; |
---|
597 | break; |
---|
598 | case 'e': |
---|
599 | if (exp_allow || trusted_user(real_uid)) |
---|
600 | explicit = 1; |
---|
601 | else |
---|
602 | fprintf(stderr, |
---|
603 | "%s: You are not allowed to use the -explicit option\n", progname); |
---|
604 | break; |
---|
605 | case 't': |
---|
606 | if (i == argc-1) { |
---|
607 | fprintf(stderr, "%s: No filesystem type specified\n", progname); |
---|
608 | return (ERR_BADARGS); |
---|
609 | } |
---|
610 | filsys_type = argv[++i]; |
---|
611 | break; |
---|
612 | case 'o': |
---|
613 | if (i == argc-1) { |
---|
614 | fprintf(stderr, "%s: No mount options specified\n", progname); |
---|
615 | return (ERR_BADARGS); |
---|
616 | } |
---|
617 | mount_options = argv[++i]; |
---|
618 | break; |
---|
619 | case 's': |
---|
620 | if (i == argc-1) { |
---|
621 | fprintf(stderr, "%s: No spoof host specified\n", progname); |
---|
622 | return (ERR_BADARGS); |
---|
623 | } |
---|
624 | spoofhost = argv[++i]; |
---|
625 | break; |
---|
626 | case 'N': |
---|
627 | override_suid = 0; |
---|
628 | break; |
---|
629 | case 'S': |
---|
630 | if (trusted_user(real_uid)) |
---|
631 | override_suid = 1; |
---|
632 | else { |
---|
633 | fprintf(stderr, |
---|
634 | |
---|
635 | "%s: You are not authorized to the -setuid option\n", progname); |
---|
636 | } |
---|
637 | break; |
---|
638 | case 'O': |
---|
639 | if (trusted_user(real_uid)) |
---|
640 | override = 1; |
---|
641 | else { |
---|
642 | fprintf(stderr, |
---|
643 | "%s: You are not authorized to use -override option\n", progname); |
---|
644 | } |
---|
645 | break; |
---|
646 | case 'L': |
---|
647 | if (trusted_user(real_uid)) |
---|
648 | lock_filesystem = 1; |
---|
649 | else { |
---|
650 | fprintf(stderr, |
---|
651 | "%s: You are not authorized to use -lock option\n", progname); |
---|
652 | } |
---|
653 | break; |
---|
654 | case 'F': |
---|
655 | skip_fsck = 1; |
---|
656 | break; |
---|
657 | case 'U': |
---|
658 | ++i; |
---|
659 | if (trusted_user(real_uid)) { |
---|
660 | if (argv[i]) |
---|
661 | owner_uid = parse_username(argv[i]); |
---|
662 | } else { |
---|
663 | fprintf(stderr, |
---|
664 | "You are not authorized to use the -user option\n", progname); |
---|
665 | } |
---|
666 | break; |
---|
667 | case 'H': |
---|
668 | print_host++; |
---|
669 | break; |
---|
670 | default: |
---|
671 | fprintf(stderr, "%s: Unknown switch %s\n", progname, argv[i]); |
---|
672 | return (ERR_BADARGS); |
---|
673 | } |
---|
674 | continue; |
---|
675 | } |
---|
676 | gotname++; |
---|
677 | |
---|
678 | if (print_host) |
---|
679 | attach_print(argv[i]); |
---|
680 | else if (attach(argv[i]) == SUCCESS) |
---|
681 | error_status = 0; |
---|
682 | |
---|
683 | override_mode = '\0'; |
---|
684 | override_suid = -1; |
---|
685 | override = 0; |
---|
686 | lock_filesystem = 0; |
---|
687 | mntpt = (char *)NULL; |
---|
688 | } |
---|
689 | |
---|
690 | /* Flush Zephyr subscriptions */ |
---|
691 | #ifdef ZEPHYR |
---|
692 | zephyr_sub(0); |
---|
693 | #endif /* ZEPHYR */ |
---|
694 | |
---|
695 | if (gotname == 1) |
---|
696 | return (error_status); |
---|
697 | if (gotname > 1) |
---|
698 | return (error_status ? ERR_SOMETHING : ERR_NONE); |
---|
699 | |
---|
700 | fprintf(stderr, |
---|
701 | "Usage: attach [options] filesystem [options] filesystem ...\n"); |
---|
702 | return (ERR_BADARGS); |
---|
703 | } |
---|
704 | |
---|
705 | detachcmd(argc, argv) |
---|
706 | int argc; |
---|
707 | char *argv[]; |
---|
708 | { |
---|
709 | int gotname, i; |
---|
710 | int dohost; |
---|
711 | static struct command_list options[] = { |
---|
712 | { "-verbose", "-v" }, |
---|
713 | { "-quiet", "-q" }, |
---|
714 | { "-all", "-a" }, |
---|
715 | { "-debug", "-d" }, |
---|
716 | { "-unmap", "-y" }, |
---|
717 | { "-nomap", "-n" }, |
---|
718 | #ifdef ZEPHYR |
---|
719 | { "-zephyr", "-z" }, |
---|
720 | { "-nozephyr", "-h" }, |
---|
721 | #endif /* ZEPHYR */ |
---|
722 | { "-type", "-t" }, |
---|
723 | { "-explicit", "-e" }, |
---|
724 | { "-noexplicit", "-x" }, |
---|
725 | { "-force", "-f" }, |
---|
726 | { "-spoofhost", "-s" }, |
---|
727 | { "-override", "-O" }, |
---|
728 | { "-host", "-H" }, |
---|
729 | { "-user", "-U" }, |
---|
730 | { "-clean", "-C" }, |
---|
731 | { "-lint", "-L" }, |
---|
732 | { 0, 0}}; |
---|
733 | |
---|
734 | check_root_privs(progname); |
---|
735 | read_config_file(ATTACHCONFFILE); |
---|
736 | |
---|
737 | gotname = 0; |
---|
738 | |
---|
739 | verbose = 1; |
---|
740 | explicit = 0; |
---|
741 | force = 0; |
---|
742 | override = 0; |
---|
743 | dohost = 0; |
---|
744 | error_status = ERR_NONE; |
---|
745 | filsys_type = NULL; |
---|
746 | |
---|
747 | for (i=1;i<argc;i++) { |
---|
748 | if (*argv[i] == '-') { |
---|
749 | switch (internal_getopt(argv[i], options)) { |
---|
750 | case 'v': |
---|
751 | verbose = 1; |
---|
752 | break; |
---|
753 | case 'q': |
---|
754 | verbose = 0; |
---|
755 | break; |
---|
756 | case 'd': |
---|
757 | debug_flag = 1; |
---|
758 | break; |
---|
759 | case 'y': |
---|
760 | do_nfsid = 1; |
---|
761 | break; |
---|
762 | case 'n': |
---|
763 | do_nfsid = 0; |
---|
764 | break; |
---|
765 | #ifdef ZEPHYR |
---|
766 | case 'z': |
---|
767 | use_zephyr = 1; |
---|
768 | break; |
---|
769 | case 'h': |
---|
770 | use_zephyr = 0; |
---|
771 | break; |
---|
772 | #endif /* ZEPHYR */ |
---|
773 | case 'H': |
---|
774 | dohost = 1; |
---|
775 | break; |
---|
776 | case 'f': |
---|
777 | force = 1; |
---|
778 | break; |
---|
779 | case 'x': |
---|
780 | explicit = 0; |
---|
781 | break; |
---|
782 | case 'e': |
---|
783 | explicit = 1; |
---|
784 | break; |
---|
785 | case 't': |
---|
786 | if (i == argc-1) { |
---|
787 | fprintf(stderr, "%s: No filesystem type specified\n", |
---|
788 | progname); |
---|
789 | return (ERR_BADARGS); |
---|
790 | } |
---|
791 | filsys_type = argv[++i]; |
---|
792 | break; |
---|
793 | case 'a': |
---|
794 | detach_all(); |
---|
795 | gotname = 2; |
---|
796 | break; |
---|
797 | case 's': |
---|
798 | if (i == argc-1) { |
---|
799 | fprintf(stderr, "%s: No spoof host specified\n", progname); |
---|
800 | return (ERR_BADARGS); |
---|
801 | } |
---|
802 | spoofhost = argv[++i]; |
---|
803 | break; |
---|
804 | case 'O': |
---|
805 | if (trusted_user(real_uid)) |
---|
806 | override = 1; |
---|
807 | else { |
---|
808 | fprintf(stderr, |
---|
809 | "%s: You are not authorized to use -override option\n", progname); |
---|
810 | } |
---|
811 | break; |
---|
812 | case 'U': |
---|
813 | ++i; |
---|
814 | if (trusted_user(real_uid)) { |
---|
815 | if (!argv[i]) { |
---|
816 | fprintf(stderr, "%s: Username required with -U.\n", |
---|
817 | progname); |
---|
818 | return (ERR_BADARGS); |
---|
819 | } |
---|
820 | owner_uid = parse_username(argv[i]); |
---|
821 | } else { |
---|
822 | fprintf(stderr, |
---|
823 | "%s: You are not authorized to use the -user option\n", progname); |
---|
824 | } |
---|
825 | break; |
---|
826 | case 'C': |
---|
827 | clean_detach = 1; |
---|
828 | break; |
---|
829 | case 'L': |
---|
830 | if (!trusted_user(real_uid)) { |
---|
831 | fprintf(stderr, |
---|
832 | "%s: You are not authorized to use the -lint option\n", |
---|
833 | progname); |
---|
834 | return(ERR_BADARGS); |
---|
835 | } else { |
---|
836 | lint_attachtab(); |
---|
837 | gotname = 1; |
---|
838 | } |
---|
839 | break; |
---|
840 | default: |
---|
841 | fprintf(stderr, "%s: Unknown switch %s\n", progname, argv[i]); |
---|
842 | return (ERR_BADARGS); |
---|
843 | } |
---|
844 | continue; |
---|
845 | } |
---|
846 | gotname++; |
---|
847 | if (dohost) |
---|
848 | detach_host(argv[i]); |
---|
849 | else |
---|
850 | detach(argv[i]); |
---|
851 | dohost = 0; |
---|
852 | } |
---|
853 | |
---|
854 | /* Flush Zephyr unsubscriptions */ |
---|
855 | #ifdef ZEPHYR |
---|
856 | zephyr_unsub(0); |
---|
857 | #endif /* ZEPHYR */ |
---|
858 | |
---|
859 | if (gotname == 1) |
---|
860 | return (error_status); |
---|
861 | if (gotname > 1) |
---|
862 | return (error_status ? ERR_SOMETHING : ERR_NONE); |
---|
863 | |
---|
864 | fprintf(stderr, |
---|
865 | "Usage: detach [options] filesystem [options] filesystem ...\n"); |
---|
866 | return (ERR_BADARGS); |
---|
867 | } |
---|
868 | |
---|
869 | #ifdef ZEPHYR |
---|
870 | zinitcmd(argc, argv) |
---|
871 | int argc; |
---|
872 | char **argv; |
---|
873 | { |
---|
874 | extern struct _attachtab *attachtab_first; |
---|
875 | char instbfr[BUFSIZ]; |
---|
876 | struct _attachtab *p; |
---|
877 | int i; |
---|
878 | #define USER_ONLY 0 |
---|
879 | #define ROOT_TOO 1 |
---|
880 | #define ALL_USERS 2 |
---|
881 | int who = ROOT_TOO; |
---|
882 | |
---|
883 | static struct command_list options[] = { |
---|
884 | { "-verbose", "-v" }, |
---|
885 | { "-quiet", "-q" }, |
---|
886 | { "-all", "-a"}, |
---|
887 | { "-me", "-m"}, |
---|
888 | { "-debug", "-d" }, |
---|
889 | { 0, 0}}; |
---|
890 | |
---|
891 | read_config_file(ATTACHCONFFILE); |
---|
892 | for (i=1;i<argc;i++) { |
---|
893 | if (*argv[i] == '-') { |
---|
894 | switch (internal_getopt(argv[i], options)) { |
---|
895 | case 'v': |
---|
896 | verbose = 1; |
---|
897 | break; |
---|
898 | case 'q': |
---|
899 | verbose = 0; |
---|
900 | break; |
---|
901 | case 'd': |
---|
902 | debug_flag = 1; |
---|
903 | break; |
---|
904 | case 'm': |
---|
905 | who = USER_ONLY; |
---|
906 | break; |
---|
907 | case 'a': |
---|
908 | who = ALL_USERS; |
---|
909 | break; |
---|
910 | } |
---|
911 | } |
---|
912 | } |
---|
913 | |
---|
914 | lock_attachtab(); |
---|
915 | get_attachtab(); |
---|
916 | unlock_attachtab(); |
---|
917 | |
---|
918 | for (p = attachtab_first; p; p = p->next ) { |
---|
919 | if (p->status == STATUS_ATTACHING) |
---|
920 | /* |
---|
921 | * If it is being attached, someone else will |
---|
922 | * deal with the zephyr subscriptions. |
---|
923 | * (Also, all the information won't be here yet.) |
---|
924 | */ |
---|
925 | continue; |
---|
926 | if(who != ALL_USERS && !wants_to_subscribe(p, real_uid, who)) |
---|
927 | continue; |
---|
928 | #ifdef AFS |
---|
929 | if (p->fs->type == TYPE_AFS) |
---|
930 | afs_zinit(p->hesiodname, p->hostdir); |
---|
931 | else |
---|
932 | #endif |
---|
933 | if (p->fs->flags & AT_FS_REMOTE) { |
---|
934 | sprintf(instbfr, "%s:%s", p->host, p->hostdir); |
---|
935 | zephyr_addsub(instbfr); |
---|
936 | zephyr_addsub(p->host); |
---|
937 | } |
---|
938 | } |
---|
939 | free_attachtab(); |
---|
940 | return((zephyr_sub(1) == FAILURE) ? error_status : 0); |
---|
941 | } |
---|
942 | #endif /* ZEPHYR */ |
---|