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

Revision 12783, 7.4 KB checked in by danw, 26 years ago (diff)
record zephyr subscriptions, but don't actually make any libzephyr calls unless the caller explicitly asks for the subscription list to be processed.
Line 
1/* $Id: locker.h,v 1.4 1999-03-29 17:33:22 danw 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
124#define LOCKER_ATTACH_DEFAULT_OPTIONS ( LOCKER_ATTACH_OPT_REAUTH | LOCKER_ATTACH_OPT_ZEPHYR )
125
126#define LOCKER_DETACH_OPT_OVERRIDE              (1 << 0)
127#define LOCKER_DETACH_OPT_UNLOCK                (1 << 1)
128#define LOCKER_DETACH_OPT_UNZEPHYR              (1 << 2)
129#define LOCKER_DETACH_OPT_UNAUTH                (1 << 3)
130#define LOCKER_DETACH_OPT_OWNERCHECK            (1 << 4)
131#define LOCKER_DETACH_OPT_CLEAN                 (1 << 5)
132
133#define LOCKER_DETACH_DEFAULT_OPTIONS ( LOCKER_DETACH_OPT_UNAUTH | LOCKER_DETACH_OPT_UNZEPHYR )
134
135/* Authentication modes */
136#define LOCKER_AUTH_DEFAULT 0
137#define LOCKER_AUTH_NONE 'n'
138#define LOCKER_AUTH_READONLY 'r'
139#define LOCKER_AUTH_READWRITE 'w'
140#define LOCKER_AUTH_MAYBE_READWRITE 'm'
141
142/* Authentication ops. These numbers cannot be changed: they
143 * correspond to the corresponding RPC mount call procedure numbers.
144 */
145enum { LOCKER_AUTH_AUTHENTICATE = 7, LOCKER_AUTH_UNAUTHENTICATE = 8,
146       LOCKER_AUTH_PURGE = 9, LOCKER_AUTH_PURGEUSER = 10 };
147
148/* Zephyr ops */
149enum { LOCKER_ZEPHYR_SUBSCRIBE, LOCKER_ZEPHYR_UNSUBSCRIBE };
150
151
152/* Callback function */
153typedef int (*locker_callback)(locker_context, locker_attachent *, void *);
154
155
156/* Context operations */
157int locker_init(locker_context *context, uid_t user,
158                locker_error_fun errfun, void *errdata);
159void locker_end(locker_context context);
160
161/* Attachtab operations */
162int locker_read_attachent(locker_context context, char *name,
163                          locker_attachent **atp);
164int locker_iterate_attachtab(locker_context context,
165                             locker_callback test, void *testarg,
166                             locker_callback act, void *actarg);
167void locker_free_attachent(locker_context context, locker_attachent *at);
168
169int locker_check_owner(locker_context context, locker_attachent *at,
170                       void *ownerp);
171int locker_check_host(locker_context context, locker_attachent *at,
172                       void *addrp);
173int locker_convert_attachtab(locker_context context, char *oattachtab);
174
175/* Attaching lockers */
176int locker_attach(locker_context context, char *filesystem,
177                  char *mountpoint, int auth, int options,
178                  char *mountoptions, locker_attachent **atp);
179int locker_attach_explicit(locker_context context, char *type,
180                           char *desc, char *mountpoint, int auth, int options,
181                           char *mountoptions, locker_attachent **atp);
182
183int locker_attach_attachent(locker_context context, locker_attachent *at,
184                            int auth, int options, char *mountoptions);
185
186/* Detaching lockers */
187int locker_detach(locker_context context, char *filesystem,
188                  char *mountpoint, int options, locker_attachent **atp);
189int locker_detach_explicit(locker_context context, char *type,
190                           char *desc, char *mountpoint, int options,
191                           locker_attachent **atp);
192
193int locker_detach_attachent(locker_context context, locker_attachent *at,
194                            int options);
195
196/* Other locker ops */
197int locker_auth(locker_context context, char *filesystem, int op);
198int locker_auth_to_cell(locker_context context, char *name, char *cell,
199                        int op);
200int locker_auth_to_host(locker_context context, char *name, char *host,
201                        int op);
202
203int locker_zsubs(locker_context context, char *filesystem);
204
205/* Lookup */
206int locker_lookup_filsys(locker_context context, char *name, char ***descs,
207                          void **cleanup);
208void locker_free_filesys(locker_context context, char **descs, void *cleanup);
209
210/* Zephyr */
211int locker_do_zsubs(locker_context context, int op);
Note: See TracBrowser for help on using the repository browser.