source: trunk/athena/lib/locker/locker.h @ 17985

Revision 17985, 7.4 KB checked in by ghudson, 22 years ago (diff)
Add support for local copies of lockers, and new -M option to turn it off.
Line 
1/* $Id: locker.h,v 1.5 2002-10-17 05:20:07 ghudson Exp $ */
2
3/* Copyright 1998 by the Massachusetts Institute of Technology.
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for any purpose and without
7 * fee is hereby granted, provided that the above copyright
8 * notice appear in all copies and that both that copyright
9 * notice and this permission notice appear in supporting
10 * documentation, and that the name of M.I.T. not be used in
11 * advertising or publicity pertaining to distribution of the
12 * software without specific, written prior permission.
13 * M.I.T. makes no representations about the suitability of
14 * this software for any purpose.  It is provided "as is"
15 * without express or implied warranty.
16 */
17
18#include <sys/types.h>
19#include <netinet/in.h>
20#include <stdarg.h>
21#include <stddef.h>
22#include <stdio.h>
23
24#define LOCKER_SUCCESS          0       /* Success */
25
26/* Strictly internal errors */
27#define LOCKER_EFILE            -1      /* from locker__read_line */
28#define LOCKER_EOF              1       /* from locker__read_line */
29#define LOCKER_ENOENT           2       /* No such file or directory. */
30
31/* Exported errors */
32#define LOCKER_EATTACHTAB       3       /* Error reading attachtab. */
33#define LOCKER_EHESIOD          4       /* Unexpected Hesiod error. */
34#define LOCKER_ENOMEM           5       /* Out of memory. */
35#define LOCKER_EPARSE           6       /* Could not parse fs description. */
36#define LOCKER_EPERM            7       /* Permission denied. */       
37#define LOCKER_EUNKNOWN         8       /* Unknown locker. */
38
39#define LOCKER_EALREADY         9       /* Locker is already attached. */
40#define LOCKER_ENOTATTACHED     10      /* Locker is not attached. */
41
42#define LOCKER_EATTACH          11      /* Could not attach locker. */
43#define LOCKER_EATTACHCONF      12      /* Error reading attach.conf. */
44#define LOCKER_EAUTH            13      /* Could not authenticate. */
45#define LOCKER_EBADPATH         14      /* Unsafe path for mountpoint. */
46#define LOCKER_EDETACH          15      /* Could not detach locker. */
47#define LOCKER_EINUSE           16      /* Locker in use: not detached. */
48#define LOCKER_EMOUNTPOINT      17      /* Couldn't build mountpoint. */
49#define LOCKER_EMOUNTPOINTBUSY  18      /* Another locker is mounted there. */
50#define LOCKER_EZEPHYR          19      /* Zephyr-related error. */
51
52#define LOCKER_ATTACH_SUCCESS(stat) (stat == LOCKER_SUCCESS || stat == LOCKER_EALREADY)
53#define LOCKER_DETACH_SUCCESS(stat) (stat == LOCKER_SUCCESS || stat == LOCKER_ENOTATTACHED)
54#define LOCKER_LOOKUP_FAILURE(stat) (stat >= LOCKER_ENOENT && stat <= LOCKER_EUNKNOWN)
55
56/* Global context */
57typedef struct locker_context *locker_context;
58typedef int (*locker_error_fun)(void *, char *, va_list);
59
60struct locker_ops;
61
62/* The attachtab directory and entries */
63
64typedef struct locker_attachent {
65  /* Data from Hesiod (or other source) */
66  char *name, *mountpoint;
67  struct locker_ops *fs;
68  struct in_addr hostaddr;
69  char *hostdir;
70  int mode;
71
72  /* Additional data kept in the attachtab file for attached lockers */
73  int flags;
74  int nowners;
75  uid_t *owners;
76
77  /* Is the locker attached? */
78  int attached;
79  /* If the mountpoint doesn't exist, where do we start building it from? */
80  char *buildfrom;
81
82  /* Filesystem state */
83  FILE *mountpoint_file;
84  int dirlockfd;
85
86  /* Chaining for MUL lockers */
87  struct locker_attachent *next;
88} locker_attachent;
89
90/* struct locker_ops contains the pointers to filesystem-specific code
91 * and data. */
92struct locker_ops {
93  char *name;
94  int flags;
95  int (*parse)(locker_context context, char *name, char *desc,
96               char *mountpoint, locker_attachent **atp);
97  int (*attach)(locker_context context, locker_attachent *at,
98                char *mountoptions);
99  int (*detach)(locker_context context, locker_attachent *at);
100  int (*auth)(locker_context context, locker_attachent *at,
101              int mode, int op);
102  int (*zsubs)(locker_context context, locker_attachent *at);
103
104  /* Set by locker_init. */
105  long id;
106};
107
108/* locker_ops flags */
109#define LOCKER_FS_NEEDS_MOUNTDIR        (1 << 0)
110
111/* Attachent flags */
112#define LOCKER_FLAG_LOCKED              (1 << 0)
113#define LOCKER_FLAG_KEEP                (1 << 1)
114#define LOCKER_FLAG_NOSUID              (1 << 2)
115#define LOCKER_FLAG_NAMEFILE            (1 << 3)
116
117/* Attach / Detach options */
118#define LOCKER_ATTACH_OPT_OVERRIDE              (1 << 0)
119#define LOCKER_ATTACH_OPT_LOCK                  (1 << 1)
120#define LOCKER_ATTACH_OPT_ALLOW_SETUID          (1 << 2)
121#define LOCKER_ATTACH_OPT_ZEPHYR                (1 << 3)
122#define LOCKER_ATTACH_OPT_REAUTH                (1 << 4)
123#define LOCKER_ATTACH_OPT_MASTER                (1 << 5)
124
125#define LOCKER_ATTACH_DEFAULT_OPTIONS ( LOCKER_ATTACH_OPT_REAUTH | LOCKER_ATTACH_OPT_ZEPHYR )
126
127#define LOCKER_DETACH_OPT_OVERRIDE              (1 << 0)
128#define LOCKER_DETACH_OPT_UNLOCK                (1 << 1)
129#define LOCKER_DETACH_OPT_UNZEPHYR              (1 << 2)
130#define LOCKER_DETACH_OPT_UNAUTH                (1 << 3)
131#define LOCKER_DETACH_OPT_OWNERCHECK            (1 << 4)
132#define LOCKER_DETACH_OPT_CLEAN                 (1 << 5)
133
134#define LOCKER_DETACH_DEFAULT_OPTIONS ( LOCKER_DETACH_OPT_UNAUTH | LOCKER_DETACH_OPT_UNZEPHYR )
135
136/* Authentication modes */
137#define LOCKER_AUTH_DEFAULT 0
138#define LOCKER_AUTH_NONE 'n'
139#define LOCKER_AUTH_READONLY 'r'
140#define LOCKER_AUTH_READWRITE 'w'
141#define LOCKER_AUTH_MAYBE_READWRITE 'm'
142
143/* Authentication ops. These numbers cannot be changed: they
144 * correspond to the corresponding RPC mount call procedure numbers.
145 */
146enum { LOCKER_AUTH_AUTHENTICATE = 7, LOCKER_AUTH_UNAUTHENTICATE = 8,
147       LOCKER_AUTH_PURGE = 9, LOCKER_AUTH_PURGEUSER = 10 };
148
149/* Zephyr ops */
150enum { LOCKER_ZEPHYR_SUBSCRIBE, LOCKER_ZEPHYR_UNSUBSCRIBE };
151
152
153/* Callback function */
154typedef int (*locker_callback)(locker_context, locker_attachent *, void *);
155
156
157/* Context operations */
158int locker_init(locker_context *context, uid_t user,
159                locker_error_fun errfun, void *errdata);
160void locker_end(locker_context context);
161
162/* Attachtab operations */
163int locker_read_attachent(locker_context context, char *name,
164                          locker_attachent **atp);
165int locker_iterate_attachtab(locker_context context,
166                             locker_callback test, void *testarg,
167                             locker_callback act, void *actarg);
168void locker_free_attachent(locker_context context, locker_attachent *at);
169
170int locker_check_owner(locker_context context, locker_attachent *at,
171                       void *ownerp);
172int locker_check_host(locker_context context, locker_attachent *at,
173                       void *addrp);
174int locker_convert_attachtab(locker_context context, char *oattachtab);
175
176/* Attaching lockers */
177int locker_attach(locker_context context, char *filesystem,
178                  char *mountpoint, int auth, int options,
179                  char *mountoptions, locker_attachent **atp);
180int locker_attach_explicit(locker_context context, char *type,
181                           char *desc, char *mountpoint, int auth, int options,
182                           char *mountoptions, locker_attachent **atp);
183
184int locker_attach_attachent(locker_context context, locker_attachent *at,
185                            int auth, int options, char *mountoptions);
186
187/* Detaching lockers */
188int locker_detach(locker_context context, char *filesystem,
189                  char *mountpoint, int options, locker_attachent **atp);
190int locker_detach_explicit(locker_context context, char *type,
191                           char *desc, char *mountpoint, int options,
192                           locker_attachent **atp);
193
194int locker_detach_attachent(locker_context context, locker_attachent *at,
195                            int options);
196
197/* Other locker ops */
198int locker_auth(locker_context context, char *filesystem, int op);
199int locker_auth_to_cell(locker_context context, char *name, char *cell,
200                        int op);
201int locker_auth_to_host(locker_context context, char *name, char *host,
202                        int op);
203
204int locker_zsubs(locker_context context, char *filesystem);
205
206/* Lookup */
207int locker_lookup_filsys(locker_context context, char *name, char ***descs,
208                          void **cleanup);
209void locker_free_filesys(locker_context context, char **descs, void *cleanup);
210
211/* Zephyr */
212int locker_do_zsubs(locker_context context, int op);
Note: See TracBrowser for help on using the repository browser.