source: trunk/athena/bin/attach/main.c @ 7150

Revision 7150, 20.0 KB checked in by miki, 30 years ago (diff)
replaced index with strchr; for POSIX replaced bcopy with memmove
Line 
1/*
2 * $Id: main.c,v 1.32 1994-03-25 15:54:51 miki Exp $
3 *
4 * Copyright (c) 1988,1992 by the Massachusetts Institute of Technology.
5 */
6
7static char *rcsid_main_c = "$Id: main.c,v 1.32 1994-03-25 15:54:51 miki Exp $";
8
9#include "attach.h"
10#include <signal.h>
11#include <string.h>
12
13int verbose = 1, debug_flag = 0, map_anyway = 1, do_nfsid = 1;
14int print_path = 0, explicit = 0, owner_check = 0, override = 0;
15int 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 */
19int real_uid, effective_uid, owner_uid;
20
21int lock_filesystem = 0;
22int nfs_root_hack = 1;          /* By default, translate for the */
23                                /* default mountpoint / as /root */
24
25int keep_mount = 0;             /* By default, let mounted filesystems */
26                                /* that are not in attachtab get */
27                                /* unmounted when that filesystem gets */
28                                /* detached. */
29int error_status = ERR_NONE;
30int force = 0;
31#ifdef ZEPHYR
32int use_zephyr = 1;
33#endif /* ZEPHYR */
34char    override_mode, *mount_options, *filsys_type;
35char    *mntpt;
36int     override_suid, default_suid, skip_fsck, lookup;
37char    *spoofhost, *attachtab_fn = NULL, *mtab_fn = NULL;
38char    *fsck_fn = NULL, *aklog_fn = NULL;
39char    *nfs_mount_dir = NULL, *afs_mount_dir = NULL;
40char    *progname;
41
42#ifdef NFS
43int     nfs_attach(), nfs_detach();
44char    **nfs_explicit();
45#endif
46#ifdef RVD
47int     rvd_attach(), rvd_detach();
48char    **rvd_explicit();
49#endif
50#ifdef AFS
51int     afs_attach(), afs_detach();
52char    **afs_explicit();
53#endif
54#ifdef UFS
55int ufs_attach(), ufs_detach();
56#endif
57int err_attach(), null_detach();
58char    **ufs_explicit();
59int mul_attach(), mul_detach();
60
61struct _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
93main(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 = strrchr(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 */
186fsidcmd(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#ifdef POSIX
416                memmove(&addr, hent->h_addr_list[0], 4);
417#else
418                bcopy(hent->h_addr_list[0], &addr, 4);
419#endif
420                if ((nfsid(hostname, addr,
421                           op, 1, "nfsid", 0, owner_uid) == SUCCESS) && verbose)
422                    printf("%s: %s %s\n", progname, hostname, ops);
423            }
424        }
425    }
426
427    if (gotname == 1)
428        return (error_status);
429    if (gotname > 1)
430        return (error_status ? ERR_SOMETHING : ERR_NONE);
431
432    fprintf(stderr, "Usage: nfsid [options] [host host ...] or [filsys filsys ...]\n");
433    return (ERR_BADARGS);
434}
435#endif
436
437fsid_filsys(atp, op, ops, filsys, uid)
438struct _attachtab *atp;
439int op;
440char *ops;
441char *filsys;
442int uid;
443{
444        char mul_buf[BUFSIZ], *cp;
445       
446        if (atp->fs->type == TYPE_MUL) {
447                strcpy(mul_buf, atp->hostdir);
448                cp = strtok(mul_buf, ",");
449                while (cp) {
450                        atp = attachtab_lookup(cp);
451                        if (atp)
452                                fsid_filsys(atp,op,ops,atp->hesiodname,uid);
453                        cp = strtok(NULL, ",");
454                }
455#ifdef NFS
456        } else if (atp->fs->type == TYPE_NFS) {
457                if ((nfsid(atp->host, atp->hostaddr[0], op, 1,
458                           filsys, 0, owner_uid) == SUCCESS) &&
459                    verbose)
460                        printf("%s: %s %s\n", progname, filsys, ops);
461#endif
462#ifdef AFS
463        } else if (atp->fs->type == TYPE_AFS) {
464                if (op == MOUNTPROC_KUIDMAP &&
465                    (afs_auth(atp->hesiodname, atp->hostdir) == SUCCESS)
466                    && verbose)
467                        printf("%s: %s %s\n", progname, filsys, ops);
468#endif
469        }
470}
471
472attachcmd(argc, argv)
473    int argc;
474    char *argv[];
475{
476    int gotname, i;
477    int print_host = 0;
478
479    static struct command_list options[] = {
480        { "-verbose", "-v" },
481        { "-quiet", "-q" },
482        { "-force", "-f" },
483        { "-printpath", "-p" },
484        { "-lookup", "-l" },
485        { "-debug", "-d" },
486        { "-map", "-y" },
487        { "-nomap", "-n" },
488        { "-remap", "-g" },
489        { "-noremap", "-a" },
490#ifdef ZEPHYR
491        { "-zephyr", "-z" },
492        { "-nozephyr", "-h" },
493#endif /* ZEPHYR */
494        { "-readonly", "-r" },
495        { "-write", "-w" },
496        { "-mountpoint", "-m" },
497        { "-noexplicit", "-x" },
498        { "-explicit", "-e" },
499        { "-type", "-t" },
500        { "-mountoptions", "-o" },
501        { "-spoofhost", "-s" },
502        { "-nosetuid", "-N" },
503        { "-setuid", "-S" },
504        { "-nosuid", "-N" },
505        { "-suid", "-S" },
506        { "-override", "-O" },
507        { "-skipfsck", "-F" },
508        { "-lock", "-L" },
509        { "-user", "-U" },
510        { "-host", "-H" },
511        { 0, 0 }};
512
513    read_config_file(ATTACHCONFFILE);
514
515    check_root_privs(progname);
516    default_suid = 0;
517   
518    gotname = 0;
519
520    verbose = 1;
521    explicit = 0;
522    force = 0;
523    lookup = 0;
524    mntpt = (char *)NULL;
525    override_mode = '\0';
526    override_suid = -1;         /* -1 means use default */
527    mount_options = "";
528    error_status = ERR_NONE;
529    map_anyway = 1;
530
531    if (argc == 1)
532        return (attach_print(0));
533   
534    for (i=1;i<argc;i++) {
535        if (*argv[i] == '-') {
536            switch (internal_getopt(argv[i], options)) {
537            case 'v':
538                verbose = 1;
539                print_path = 0;
540                break;
541            case 'l':
542                lookup = 1;
543                break;
544            case 'q':
545                verbose = 0;
546                break;
547            case 'd':
548                debug_flag = 1;
549                break;
550            case 'y':
551                do_nfsid = 1;
552                break;
553            case 'n':
554                do_nfsid = 0;
555                map_anyway = 0;
556                break;
557            case 'p':
558                print_path = 1;
559                verbose = 0;
560                break;
561            case 'm':
562                if (i == argc-1) {
563                        fprintf(stderr, "%s: No mount point specified\n",
564                                progname);
565                        return (ERR_BADARGS);
566                }
567                if (exp_mntpt || trusted_user(real_uid)) {
568                        mntpt = argv[++i];
569                } else {
570                        fprintf(stderr,
571                "%s: You are not allowed to use the -mountpoint option\n",
572                                progname);
573                        i++;
574                }
575                break;
576            case 'r':
577                override_mode = 'r';
578                break;
579            case 'w':
580                override_mode = 'w';
581                break;
582            case 'f':
583                force = 1;
584                break;
585            case 'g':
586                map_anyway = 1;
587                break;
588            case 'a':
589                map_anyway = 0;
590                break;
591#ifdef ZEPHYR
592            case 'z':
593                use_zephyr = 1;
594                break;
595            case 'h':
596                use_zephyr = 0;
597                break;
598#endif /* ZEPHYR */
599            case 'x':
600                explicit = 0;
601                break;
602            case 'e':
603                if (exp_allow || trusted_user(real_uid))
604                        explicit = 1;
605                else
606                        fprintf(stderr,
607                "%s: You are not allowed to use the -explicit option\n", progname);
608                break;
609            case 't':
610                if (i == argc-1) {
611                    fprintf(stderr, "%s: No filesystem type specified\n", progname);
612                    return (ERR_BADARGS);
613                }
614                filsys_type = argv[++i];
615                break;
616            case 'o':
617                if (i == argc-1) {
618                    fprintf(stderr, "%s: No mount options specified\n", progname);
619                    return (ERR_BADARGS);
620                }
621                mount_options = argv[++i];
622                break;
623            case 's':
624                if (i == argc-1) {
625                    fprintf(stderr, "%s: No spoof host specified\n", progname);
626                    return (ERR_BADARGS);
627                }
628                spoofhost = argv[++i];
629                break;
630            case 'N':
631                override_suid = 0;
632                break;
633            case 'S':
634                if (trusted_user(real_uid))
635                        override_suid = 1;
636                else {
637                        fprintf(stderr,
638
639                "%s: You are not authorized to the -setuid option\n", progname);
640                }
641                break;
642            case 'O':
643                if (trusted_user(real_uid))
644                        override = 1;
645                else {
646                        fprintf(stderr,
647                "%s: You are not authorized to use -override option\n", progname);
648                }
649                break;
650            case 'L':
651                if (trusted_user(real_uid))
652                        lock_filesystem = 1;
653                else {
654                        fprintf(stderr,
655                "%s: You are not authorized to use -lock option\n", progname);
656                }
657                break;
658            case 'F':
659                skip_fsck = 1;
660                break;
661            case 'U':
662                ++i;
663                if (trusted_user(real_uid)) {
664                        if (argv[i])
665                                owner_uid = parse_username(argv[i]);
666                } else {
667                        fprintf(stderr,
668                "You are not authorized to use the -user option\n", progname);
669                }
670                break;
671            case 'H':
672                print_host++;
673                break;
674            default:
675                fprintf(stderr, "%s: Unknown switch %s\n", progname, argv[i]);
676                return (ERR_BADARGS);           
677            }
678            continue;
679        }
680        gotname++;
681
682        if (print_host)
683                attach_print(argv[i]);
684        else if (attach(argv[i]) == SUCCESS)
685                error_status = 0;
686
687        override_mode = '\0';
688        override_suid = -1;
689        override = 0;
690        lock_filesystem = 0;
691        mntpt = (char *)NULL;
692    }
693
694    /* Flush Zephyr subscriptions */
695#ifdef ZEPHYR
696    zephyr_sub(0);
697#endif /* ZEPHYR */
698
699    if (gotname == 1)
700        return (error_status);
701    if (gotname > 1)
702        return (error_status ? ERR_SOMETHING : ERR_NONE);
703
704    fprintf(stderr,
705            "Usage: attach [options] filesystem [options] filesystem ...\n");
706    return (ERR_BADARGS);
707}
708
709detachcmd(argc, argv)
710    int argc;
711    char *argv[];
712{
713    int gotname, i;
714    int dohost;
715    static struct command_list options[] = {
716        { "-verbose", "-v" },
717        { "-quiet", "-q" },
718        { "-all", "-a" },
719        { "-debug", "-d" },
720        { "-unmap", "-y" },
721        { "-nomap", "-n" },
722#ifdef ZEPHYR
723        { "-zephyr", "-z" },
724        { "-nozephyr", "-h" },
725#endif /* ZEPHYR */
726        { "-type", "-t" },
727        { "-explicit", "-e" },
728        { "-noexplicit", "-x" },
729        { "-force", "-f" },
730        { "-spoofhost", "-s" },
731        { "-override", "-O" },
732        { "-host", "-H" },
733        { "-user", "-U" },
734        { "-clean", "-C" },
735        { "-lint", "-L" },
736        { 0, 0}};
737
738    check_root_privs(progname);
739    read_config_file(ATTACHCONFFILE);
740   
741    gotname = 0;
742
743    verbose = 1;
744    explicit = 0;
745    force = 0;
746    override = 0;
747    dohost = 0;
748    error_status = ERR_NONE;
749    filsys_type = NULL;
750   
751    for (i=1;i<argc;i++) {
752        if (*argv[i] == '-') {
753            switch (internal_getopt(argv[i], options)) {
754            case 'v':
755                verbose = 1;
756                break;
757            case 'q':
758                verbose = 0;
759                break;
760            case 'd':
761                debug_flag = 1;
762                break;
763            case 'y':
764                do_nfsid = 1;
765                break;
766            case 'n':
767                do_nfsid = 0;
768                break;
769#ifdef ZEPHYR
770            case 'z':
771                use_zephyr = 1;
772                break;
773            case 'h':
774                use_zephyr = 0;
775                break;
776#endif /* ZEPHYR */
777            case 'H':
778                dohost = 1;
779                break;
780            case 'f':
781                force = 1;
782                break;
783            case 'x':
784                explicit = 0;
785                break;
786            case 'e':
787                explicit = 1;
788                break;
789            case 't':
790                if (i == argc-1) {
791                    fprintf(stderr, "%s: No filesystem type specified\n",
792                            progname);
793                    return (ERR_BADARGS);
794                }
795                filsys_type = argv[++i];
796                break;
797            case 'a':
798                detach_all();
799                gotname = 2;
800                break;
801            case 's':
802                if (i == argc-1) {
803                    fprintf(stderr, "%s: No spoof host specified\n", progname);
804                    return (ERR_BADARGS);
805                }
806                spoofhost = argv[++i];
807                break;
808            case 'O':
809                if (trusted_user(real_uid))
810                        override = 1;
811                else {
812                        fprintf(stderr,
813                "%s: You are not authorized to use -override option\n", progname);
814                }
815                break;
816            case 'U':
817                ++i;
818                if (trusted_user(real_uid)) {
819                        if (!argv[i]) {
820                                fprintf(stderr, "%s: Username required with -U.\n",
821                                        progname);
822                                return (ERR_BADARGS);
823                        }
824                        owner_uid = parse_username(argv[i]);
825                } else {
826                        fprintf(stderr,
827                "%s: You are not authorized to use the -user option\n", progname);
828                }
829                break;
830        case 'C':
831                clean_detach = 1;
832                break;
833        case 'L':
834                if (!trusted_user(real_uid)) {
835                    fprintf(stderr,
836                            "%s: You are not authorized to use the -lint option\n",
837                            progname);
838                    return(ERR_BADARGS);
839                } else {
840                    lint_attachtab();
841                    gotname = 1;
842                }
843                break;
844        default:
845                fprintf(stderr, "%s: Unknown switch %s\n", progname, argv[i]);
846                return (ERR_BADARGS);
847            }
848            continue;
849        }
850        gotname++;
851        if (dohost)
852                detach_host(argv[i]);
853        else
854                detach(argv[i]);
855        dohost = 0;
856    }
857
858    /* Flush Zephyr unsubscriptions */
859#ifdef ZEPHYR
860    zephyr_unsub(0);
861#endif /* ZEPHYR */
862   
863    if (gotname == 1)
864        return (error_status);
865    if (gotname > 1)
866        return (error_status ? ERR_SOMETHING : ERR_NONE);
867
868    fprintf(stderr,
869            "Usage: detach [options] filesystem [options] filesystem ...\n");
870    return (ERR_BADARGS);
871}
872
873#ifdef ZEPHYR
874zinitcmd(argc, argv)
875        int     argc;
876        char    **argv;
877{
878        extern struct _attachtab *attachtab_first;
879        char instbfr[BUFSIZ];
880        struct _attachtab *p;
881        int     i;
882#define USER_ONLY       0
883#define ROOT_TOO        1
884#define ALL_USERS       2
885        int     who = ROOT_TOO;
886
887        static struct command_list options[] = {
888                { "-verbose", "-v" },
889                { "-quiet", "-q" },
890                { "-all", "-a"},
891                { "-me", "-m"},
892                { "-debug", "-d" },
893                { 0, 0}};
894
895        read_config_file(ATTACHCONFFILE);
896        for (i=1;i<argc;i++) {
897                if (*argv[i] == '-') {
898                        switch (internal_getopt(argv[i], options)) {
899                        case 'v':
900                                verbose = 1;
901                                break;
902                        case 'q':
903                                verbose = 0;
904                                break;
905                        case 'd':
906                                debug_flag = 1;
907                                break;
908                        case 'm':
909                                who = USER_ONLY;
910                                break;
911                        case 'a':
912                                who = ALL_USERS;
913                                break;
914                        }
915                }
916        }
917
918        lock_attachtab();
919        get_attachtab();
920        unlock_attachtab();
921
922        for (p = attachtab_first; p; p = p->next ) {
923                if (p->status == STATUS_ATTACHING)
924                        /*
925                         * If it is being attached, someone else will
926                         * deal with the zephyr subscriptions.
927                         * (Also, all the information won't be here yet.)
928                         */
929                        continue;
930                if(who != ALL_USERS && !wants_to_subscribe(p, real_uid, who))
931                        continue;
932#ifdef AFS
933                if (p->fs->type == TYPE_AFS)
934                        afs_zinit(p->hesiodname, p->hostdir);
935                else
936#endif
937                if (p->fs->flags & AT_FS_REMOTE) {
938                        sprintf(instbfr, "%s:%s", p->host, p->hostdir);
939                        zephyr_addsub(instbfr);
940                        zephyr_addsub(p->host);
941                }
942        }
943        free_attachtab();
944        return((zephyr_sub(1) == FAILURE) ? error_status : 0);
945}
946#endif /* ZEPHYR */
Note: See TracBrowser for help on using the repository browser.