source: trunk/athena/bin/attach/fsid.c @ 13600

Revision 13600, 5.0 KB checked in by danw, 25 years ago (diff)
actually implement -v
Line 
1/* Copyright 1998 by the Massachusetts Institute of Technology.
2 *
3 * Permission to use, copy, modify, and distribute this
4 * software and its documentation for any purpose and without
5 * fee is hereby granted, provided that the above copyright
6 * notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting
8 * documentation, and that the name of M.I.T. not be used in
9 * advertising or publicity pertaining to distribution of the
10 * software without specific, written prior permission.
11 * M.I.T. makes no representations about the suitability of
12 * this software for any purpose.  It is provided "as is"
13 * without express or implied warranty.
14 */
15
16/* This is fsid, which is used to authenticate/unauthenticate to
17 * lockers.
18 */
19
20static const char rcsid[] = "$Id: fsid.c,v 1.7 1999-09-19 23:51:03 danw Exp $";
21
22#include <netdb.h>
23#include <stdlib.h>
24#include <string.h>
25#include <unistd.h>
26
27#include <locker.h>
28#include "attach.h"
29#include "agetopt.h"
30
31static void usage(void);
32static int fsid_attachent(locker_context context, locker_attachent *at,
33                          void *opp);
34static char *opped(int op);
35
36static struct agetopt_option fsid_options[] = {
37  { "all", 'a', 0 },
38  { "cell", 'c', 0 },
39  { "debug", 'd', 0 },
40  { "filsys", 'f', 0 },
41  { "host", 'h', 0 },
42  { "map", 'm', 0 },
43  { "purge", 'p', 0 },
44  { "quiet", 'q', 0 },
45  { "purgeuser", 'r', 0 },
46  { "user", 'U', 1 },
47  { "verbose", 'v', 0 },
48  { "unmap", 'u', 0 },
49  { 0, 0, 0 }
50};
51
52static int verbose = 1;
53
54enum { FSID_WHATEVER, FSID_FILESYSTEM, FSID_HOST, FSID_CELL };
55
56int fsid_main(int argc, char **argv)
57{
58  locker_context context;
59  int mode = FSID_WHATEVER, op = LOCKER_AUTH_AUTHENTICATE;
60  struct hostent *h;
61  int status, estatus = 0, opt, gotname = 0;
62  uid_t uid = getuid();
63
64  if (locker_init(&context, uid, NULL, NULL))
65    exit(1);
66
67  while (optind < argc)
68    {
69      while ((opt = attach_getopt(argc, argv, fsid_options)) != -1)
70        {
71          switch (opt)
72            {
73            case 'a':
74              if (op == LOCKER_AUTH_PURGE ||
75                  op == LOCKER_AUTH_PURGEUSER)
76                {
77                  locker_iterate_attachtab(context, NULL, NULL,
78                                           fsid_attachent, &op);
79                }
80              else
81                {
82                  locker_iterate_attachtab(context, locker_check_owner, &uid,
83                                           fsid_attachent, &op);
84                }
85              gotname++;
86              break;
87
88            case 'c':
89              mode = FSID_CELL;
90              break;
91
92            case 'f':
93              mode = FSID_FILESYSTEM;
94              break;
95
96            case 'h':
97              mode = FSID_HOST;
98              break;
99
100            case 'm':
101              op = LOCKER_AUTH_AUTHENTICATE;
102              break;
103
104            case 'p':
105              op = LOCKER_AUTH_PURGE;
106              break;
107
108            case 'q':
109              verbose = 0;
110              break;
111
112            case 'r':
113              op = LOCKER_AUTH_PURGEUSER;
114              break;
115
116            case 'u':
117              op = LOCKER_AUTH_UNAUTHENTICATE;
118              break;
119
120            case 'v':
121              verbose = 1;
122              break;
123
124            case 'd':
125            case 'U':
126              fprintf(stderr, "%s: The '%c' flag is no longer supported.\n",
127                      whoami, opt);
128              break;
129
130            default:
131              usage();
132            }
133        }
134
135      while (optind < argc && argv[optind][0] != '-')
136        {
137          gotname++;
138          switch (mode)
139            {
140            case FSID_WHATEVER:
141            case FSID_HOST:
142              h = gethostbyname(argv[optind]);
143              if (h)
144                {
145                  status = locker_auth_to_host(context, whoami,
146                                               argv[optind], op);
147                  if (status != LOCKER_SUCCESS)
148                    estatus = 2;
149                  break;
150                }
151              else if (mode == FSID_HOST)
152                {
153                  fprintf(stderr, "%s: Could not resolve hostname \"%s\".\n",
154                          whoami, argv[optind]);
155                  estatus = 2;
156                }
157              /* else if (mode == FSID_WHATEVER), fall through */
158
159            case FSID_FILESYSTEM:
160              status = locker_auth(context, argv[optind], op);
161              if (status != LOCKER_SUCCESS)
162                estatus = 2;
163              break;
164
165            case FSID_CELL:
166              status = locker_auth_to_cell(context, whoami, argv[optind], op);
167              if (status != LOCKER_SUCCESS)
168                estatus = 2;
169              break;
170            }
171
172          if (verbose && status == LOCKER_SUCCESS)
173            printf("%s: %s %s\n", whoami, argv[optind], opped(op));
174
175          optind++;
176        }
177    }
178
179  if (!gotname)
180    usage();
181  locker_end(context);
182  exit(estatus);
183}
184
185static int fsid_attachent(locker_context context, locker_attachent *at,
186                          void *opp)
187{
188  int status;
189
190  status = at->fs->auth(context, at, LOCKER_AUTH_DEFAULT, *(int *)opp);
191  if (verbose && status == LOCKER_SUCCESS)
192    printf("%s: %s %s\n", whoami, at->name, opped(*(int *)opp));
193  return 0;
194}
195
196static char *opped(int op)
197{
198  switch (op)
199    {
200    case LOCKER_AUTH_AUTHENTICATE:
201      return "mapped";
202    case LOCKER_AUTH_UNAUTHENTICATE:
203      return "unmapped";
204    case LOCKER_AUTH_PURGE:
205      return "purged";
206    case LOCKER_AUTH_PURGEUSER:
207      return "user-purged";
208    default:
209      return "(unknown)";
210    }
211}
212
213static void usage(void)
214{
215  fprintf(stderr, "Usage: fsid [-q | -v] [-m | -p | -r | -u] [ filesystem | host ] ...\n");
216  fprintf(stderr, "       fsid [-q | -v] [-m | -p | -r | -u] -f filesystem ...\n");
217  fprintf(stderr, "       fsid [-q | -v] [-m | -p | -r | -u] -h host ...\n");
218  fprintf(stderr, "       fsid [-q | -v] [-m      |      -u] -c cell ...\n");
219  fprintf(stderr, "       fsid [-q | -v] [-m | -p | -r | -u] -a\n");
220  exit(1);
221}
Note: See TracBrowser for help on using the repository browser.