1 | /* |
---|
2 | * $Id: attach.h,v 1.25 1998-04-08 21:53:04 cfields Exp $ |
---|
3 | * |
---|
4 | * Copyright (c) 1988,1991 by the Massachusetts Institute of Technology. |
---|
5 | * |
---|
6 | * For redistribution rights, see "mit-copyright.h" |
---|
7 | */ |
---|
8 | |
---|
9 | #include "config.h" |
---|
10 | |
---|
11 | #include <stdio.h> |
---|
12 | #include <stdlib.h> |
---|
13 | #include <ctype.h> |
---|
14 | #include <errno.h> |
---|
15 | #ifdef _AIX |
---|
16 | #undef geterrno |
---|
17 | #endif |
---|
18 | #include <netdb.h> |
---|
19 | #include <string.h> |
---|
20 | |
---|
21 | #include <sys/types.h> |
---|
22 | #include <sys/file.h> |
---|
23 | #include <sys/param.h> |
---|
24 | #include <sys/socket.h> |
---|
25 | #include <sys/time.h> |
---|
26 | |
---|
27 | #include <netinet/in.h> |
---|
28 | |
---|
29 | #include "stringlist.h" |
---|
30 | |
---|
31 | #ifdef NFS |
---|
32 | #include <rpc/rpc.h> |
---|
33 | #ifndef i386 |
---|
34 | #ifndef sgi |
---|
35 | #include <nfs/nfs.h> |
---|
36 | #else |
---|
37 | #include <sys/fs/nfs.h> |
---|
38 | #endif /* sgi */ |
---|
39 | #else |
---|
40 | #include <rpc/nfs.h> |
---|
41 | #endif |
---|
42 | #ifdef NeXT |
---|
43 | #include <nfs/nfs_mount.h> /* Newer versions of NFS (?) */ |
---|
44 | #endif /* NeXT */ |
---|
45 | #ifdef _AUX_SOURCE |
---|
46 | #include <nfs/mount.h> |
---|
47 | #endif |
---|
48 | #ifdef SOLARIS |
---|
49 | #include <nfs/mount.h> |
---|
50 | #include <sys/fs/ufs_mount.h> |
---|
51 | #endif |
---|
52 | #ifdef sgi |
---|
53 | #include <sys/fs/nfs_clnt.h> |
---|
54 | #include <sys/mount.h> |
---|
55 | #endif |
---|
56 | #endif /* NFS */ |
---|
57 | |
---|
58 | #ifdef ultrix |
---|
59 | #include <ufs/ufs_mount.h> |
---|
60 | #ifdef NFS |
---|
61 | #include <nfs/nfs_gfs.h> |
---|
62 | #endif /* NFS */ |
---|
63 | #define KERNEL |
---|
64 | /* AACK! this @#OU@#)($(#) file defines and initializes an array which |
---|
65 | loses on multiple includes, but it's surrounded by #ifdef KERNEL. */ |
---|
66 | #include <sys/fs_types.h> |
---|
67 | #undef KERNEL |
---|
68 | #endif /* ultrix */ |
---|
69 | |
---|
70 | #include <sys/mount.h> |
---|
71 | #ifdef _AIX |
---|
72 | #include <sys/vmount.h> |
---|
73 | #define M_RDONLY MNT_READONLY |
---|
74 | #endif |
---|
75 | |
---|
76 | #if defined(_AUX_SOURCE) || defined(NeXT) || defined(_AIX) || defined(sgi) |
---|
77 | #define vfork fork |
---|
78 | #endif |
---|
79 | |
---|
80 | /* |
---|
81 | * If MOUNT_CMD or UMOUNT_CMD are defined, it will run the program |
---|
82 | * specified rather than trying to use in-line code. |
---|
83 | */ |
---|
84 | #if defined(_IBMR2) |
---|
85 | #define MOUNT_CMD "/etc/mount" |
---|
86 | #endif |
---|
87 | #if defined(SOLARIS) |
---|
88 | #define MOUNT_CMD "/etc/fs/nfs/mount" |
---|
89 | #define UMOUNT_CMD "/usr/sbin/umount" |
---|
90 | #endif |
---|
91 | #if defined(sgi) |
---|
92 | #define MOUNT_CMD "/sbin/mount" |
---|
93 | #define UMOUNT_CMD "/sbin/umount" |
---|
94 | #endif |
---|
95 | |
---|
96 | #define MAXOWNERS 64 |
---|
97 | #define MAXHOSTS 64 |
---|
98 | |
---|
99 | /* |
---|
100 | * We don't really want to deal with malloc'ing and free'ing stuff |
---|
101 | * in this structure... |
---|
102 | */ |
---|
103 | |
---|
104 | struct _attachtab { |
---|
105 | struct _attachtab *next, *prev; |
---|
106 | char version[3]; |
---|
107 | char explicit; |
---|
108 | char status; |
---|
109 | char mode; |
---|
110 | struct _fstypes *fs; |
---|
111 | struct in_addr hostaddr[MAXHOSTS]; |
---|
112 | int rmdir; |
---|
113 | int drivenum; |
---|
114 | int flags; |
---|
115 | int nowners; |
---|
116 | uid_t owners[MAXOWNERS]; |
---|
117 | char hesiodname[BUFSIZ]; |
---|
118 | char host[BUFSIZ]; |
---|
119 | char hostdir[MAXPATHLEN]; |
---|
120 | char mntpt[MAXPATHLEN]; |
---|
121 | int preference; |
---|
122 | }; |
---|
123 | |
---|
124 | /* |
---|
125 | * Attach flags defines |
---|
126 | * |
---|
127 | * FLAG_NOSETUID --- this filesystem was mounted nosetuid (no meaning |
---|
128 | * for afs filesystems) |
---|
129 | * FLAG_LOCKED --- this filesystem is passed over by detach -a, and |
---|
130 | * you must be the owner of the filesystem to detach it. |
---|
131 | * FLAG_ANYONE --- anyone can detach this filesystem (not yet implemented) |
---|
132 | * FLAG_PERMANENT --- when this filesytem is detached, don't do |
---|
133 | * actually unmount it; just deauthenticate, if necessary. attach |
---|
134 | * sets this flag if it finds the filesystem already mounted but |
---|
135 | * not in attachtab. |
---|
136 | */ |
---|
137 | #define FLAG_NOSETUID 1 |
---|
138 | #define FLAG_LOCKED 2 |
---|
139 | #define FLAG_ANYONE 4 |
---|
140 | #define FLAG_PERMANENT 8 |
---|
141 | |
---|
142 | #define ATTACH_VERSION "A1" |
---|
143 | |
---|
144 | #define ATTACHTABMODE 644 |
---|
145 | |
---|
146 | #define STATUS_ATTACHED '+' |
---|
147 | #define STATUS_ATTACHING '*' |
---|
148 | #define STATUS_DETACHING '-' |
---|
149 | |
---|
150 | #define TYPE_NFS 001 |
---|
151 | #define TYPE_RVD 002 |
---|
152 | #define TYPE_UFS 004 |
---|
153 | #define TYPE_ERR 010 |
---|
154 | #define TYPE_AFS 020 |
---|
155 | #define TYPE_MUL 040 |
---|
156 | #define ALL_TYPES 067 |
---|
157 | |
---|
158 | /* |
---|
159 | * Attach configuration defines |
---|
160 | */ |
---|
161 | #define MAXFILTAB 100 |
---|
162 | #define MAXTRUIDTAB 100 |
---|
163 | |
---|
164 | /* |
---|
165 | * Type table |
---|
166 | */ |
---|
167 | |
---|
168 | struct _fstypes { |
---|
169 | char *name; |
---|
170 | int type; |
---|
171 | int mount_type; |
---|
172 | int flags; |
---|
173 | char *good_flags; |
---|
174 | int (*attach)(); |
---|
175 | int (*detach)(); |
---|
176 | char ** (*explicit)(); |
---|
177 | int (*flush)(); |
---|
178 | }; |
---|
179 | |
---|
180 | /* |
---|
181 | * Flags for _fstypes.flags |
---|
182 | */ |
---|
183 | #define AT_FS_MNTPT 1 |
---|
184 | #define AT_FS_REMOTE 2 |
---|
185 | #define AT_FS_PARENTMNTPT 4 |
---|
186 | #define AT_FS_MNTPT_CANON 8 |
---|
187 | |
---|
188 | extern struct _fstypes fstypes[]; |
---|
189 | |
---|
190 | /* |
---|
191 | * Mount options |
---|
192 | */ |
---|
193 | #ifndef M_RDONLY |
---|
194 | #define M_RDONLY 0x01 /* mount fs read-only */ |
---|
195 | #endif |
---|
196 | #ifndef M_NOSUID |
---|
197 | #define M_NOSUID 0x02 /* mount fs without setuid perms */ |
---|
198 | #endif |
---|
199 | |
---|
200 | /* |
---|
201 | * Mount option table |
---|
202 | */ |
---|
203 | struct mntopts { |
---|
204 | int type; /* File system type */ |
---|
205 | int flags; /* Mount flags */ |
---|
206 | #ifdef NFS |
---|
207 | int nfs_port; /* Valid only for NFS, port for rpc.mountd */ |
---|
208 | #endif |
---|
209 | union tsa { |
---|
210 | #ifdef UFS |
---|
211 | struct ufs_args ufs; |
---|
212 | #endif |
---|
213 | #ifdef NFS |
---|
214 | struct nfs_args nfs; |
---|
215 | #endif |
---|
216 | } tsa; |
---|
217 | }; |
---|
218 | |
---|
219 | /* |
---|
220 | * Command option lists |
---|
221 | */ |
---|
222 | |
---|
223 | struct command_list { |
---|
224 | char *large; |
---|
225 | char *small; |
---|
226 | }; |
---|
227 | |
---|
228 | /* |
---|
229 | * RVD defines |
---|
230 | */ |
---|
231 | |
---|
232 | #define RVD_ATTACH_TIMEOUT 30 |
---|
233 | |
---|
234 | /* |
---|
235 | * RPC caching |
---|
236 | */ |
---|
237 | |
---|
238 | #define RPC_MAXCACHE 10 |
---|
239 | |
---|
240 | struct cache_ent { |
---|
241 | struct in_addr addr; |
---|
242 | CLIENT *handle; |
---|
243 | struct sockaddr_in sin; |
---|
244 | int fd; |
---|
245 | int error; |
---|
246 | }; |
---|
247 | |
---|
248 | /* |
---|
249 | * Calls to RPC.MOUNTD |
---|
250 | */ |
---|
251 | |
---|
252 | #ifndef MOUNTPROC_KUIDMAP |
---|
253 | #define MOUNTPROC_KUIDMAP 7 |
---|
254 | #define MOUNTPROC_KUIDUMAP 8 |
---|
255 | #define MOUNTPROC_KUIDPURGE 9 |
---|
256 | #define MOUNTPROC_KUIDUPURGE 10 |
---|
257 | #endif |
---|
258 | |
---|
259 | /* |
---|
260 | * Command names |
---|
261 | */ |
---|
262 | |
---|
263 | #define ATTACH_CMD "attach" |
---|
264 | #define DETACH_CMD "detach" |
---|
265 | #define NFSID_CMD "nfsid" |
---|
266 | #define FSID_CMD "fsid" |
---|
267 | #ifdef ZEPHYR |
---|
268 | #define ZINIT_CMD "zinit" |
---|
269 | #endif /* ZEPHYR */ |
---|
270 | #define ADD_CMD "add" |
---|
271 | #define RUN_CMD "attachandrun" |
---|
272 | |
---|
273 | /* |
---|
274 | * Generic defines |
---|
275 | */ |
---|
276 | |
---|
277 | #define SUCCESS 0 |
---|
278 | #define FAILURE 1 |
---|
279 | |
---|
280 | /* |
---|
281 | * Error status defininitions |
---|
282 | */ |
---|
283 | |
---|
284 | #define ERR_NONE 0 /* No error */ |
---|
285 | #define ERR_BADARGS 1 /* Bad arguments */ |
---|
286 | #define ERR_SOMETHING 2 /* Something wrong - > 1 args */ |
---|
287 | #define ERR_FATAL 3 /* Internal failure */ |
---|
288 | #define ERR_INTERRUPT 4 /* Program externally aborted */ |
---|
289 | #define ERR_BADCONF 5 /* Bad configuration file */ |
---|
290 | #define ERR_BADFSDSC 6 /* Bad filesystem description */ |
---|
291 | #define ERR_BADFSFLAG 7 /* Bad filsys flag */ |
---|
292 | |
---|
293 | #define ERR_KERBEROS 10 /* Kerberos failure */ |
---|
294 | #define ERR_HOST 11 /* General host communication failure */ |
---|
295 | #define ERR_AUTHFAIL 12 /* Authentication failure */ |
---|
296 | #define ERR_NOPORTS 13 /* Out of reserved ports */ |
---|
297 | |
---|
298 | #define ERR_NFSIDNOTATTACHED 20 /* Filesystem with -f not attached */ |
---|
299 | #define ERR_NFSIDBADHOST 21 /* Can't resolve hostname */ |
---|
300 | #define ERR_NFSIDPERM 22 /* unauthorized nfsid -p */ |
---|
301 | |
---|
302 | #define ERR_ATTACHBADFILSYS 20 /* Bad filesystem name */ |
---|
303 | #define ERR_ATTACHINUSE 21 /* Filesystem in use by another proc */ |
---|
304 | #define ERR_ATTACHNEEDPW 22 /* RVD spinup needs a password */ |
---|
305 | #define ERR_ATTACHFSCK 23 /* FSCK returned error on RVD */ |
---|
306 | #define ERR_ATTACHNOTALLOWED 24 /* User not allowed to do operation */ |
---|
307 | #define ERR_ATTACHBADMNTPT 25 /* User not allowed to mount a */ |
---|
308 | /* filesystem here */ |
---|
309 | #define ERR_ATTACHNOFILSYS 26 /* The remote filesystem doesn't exist */ |
---|
310 | #define ERR_ATTACHDIRINUSE 27 /* Some other filesystem is using the */ |
---|
311 | /* mountpoint directory */ |
---|
312 | |
---|
313 | #define ERR_DETACHNOTATTACHED 20 /* Filesystem not attached */ |
---|
314 | #define ERR_DETACHINUSE 21 /* Filesystem in use by another proc */ |
---|
315 | #define ERR_DETACHNOTALLOWED 22 /* User not allowed to do operations */ |
---|
316 | |
---|
317 | #define ERR_ZINITZLOSING 20 /* Random zephyr lossage */ |
---|
318 | |
---|
319 | /* |
---|
320 | * Zephyr definitions |
---|
321 | */ |
---|
322 | |
---|
323 | #ifdef ZEPHYR |
---|
324 | #define ZEPHYR_CLASS "filsrv" |
---|
325 | #define ZEPHYR_MAXSUBS 100 /* 50 filesystems... */ |
---|
326 | #define ZEPHYR_TIMEOUT 60 /* 1 minute timeout */ |
---|
327 | #endif /* ZEPHYR */ |
---|
328 | |
---|
329 | /* AFS */ |
---|
330 | #ifdef AFS |
---|
331 | #ifdef __STDC__ |
---|
332 | extern int afs_auth(const char *, const char *), afs_auth_to_cell(const char *); |
---|
333 | extern int afs_zinit(const char *, const char *); |
---|
334 | #else |
---|
335 | extern int afs_auth(), afs_auth_to_cell(); |
---|
336 | #endif |
---|
337 | #endif |
---|
338 | |
---|
339 | /* |
---|
340 | * Externals |
---|
341 | */ |
---|
342 | |
---|
343 | extern char *errstr(); /* convert errno to string */ |
---|
344 | |
---|
345 | AUTH *spoofunix_create_default(); |
---|
346 | CLIENT *rpc_create(); |
---|
347 | extern int errno; |
---|
348 | extern unsigned long rvderrno; |
---|
349 | extern struct _attachtab *build_hesiod_line(); |
---|
350 | extern char **conf_filsys_resolve(); |
---|
351 | extern struct _fstypes *get_fs(); |
---|
352 | extern char *filsys_options(); |
---|
353 | extern char *stropt(), *struid(), *path_canon(); |
---|
354 | extern struct _attachtab *attachtab_lookup(), *attachtab_lookup_mntpt(); |
---|
355 | |
---|
356 | extern int verbose, debug_flag, map_anyway, do_nfsid, print_path, explicit; |
---|
357 | extern int owner_check, owner_list, override, keep_mount; |
---|
358 | extern int error_status, force, lock_filesystem, lookup, euid, clean_detach; |
---|
359 | extern int exp_mntpt, exp_allow; |
---|
360 | #ifdef ZEPHYR |
---|
361 | extern int use_zephyr; |
---|
362 | #endif /* ZEPHYR */ |
---|
363 | extern char override_mode, *mount_options, *filsys_type; |
---|
364 | extern char *mntpt; |
---|
365 | extern int override_suid, default_suid, skip_fsck, nfs_root_hack; |
---|
366 | extern char *spoofhost, *attachtab_fn, *mtab_fn, *nfs_mount_dir; |
---|
367 | #ifdef AFS |
---|
368 | extern char *aklog_fn, *afs_mount_dir; |
---|
369 | #endif |
---|
370 | extern char *fsck_fn; |
---|
371 | |
---|
372 | extern char *ownerlist(); |
---|
373 | extern void add_an_owner(); |
---|
374 | extern int is_an_owner(), real_uid, effective_uid, owner_uid; |
---|
375 | |
---|
376 | extern char internal_getopt(); |
---|
377 | extern void mark_in_use(), add_options(), check_root_privs(); |
---|
378 | |
---|
379 | extern char exp_hesline[BUFSIZ]; /* Place to store explicit */ |
---|
380 | extern char *exp_hesptr[2]; /* ``hesiod'' entry */ |
---|
381 | extern char *abort_msg; |
---|
382 | |
---|
383 | /* High C 2.1 can optimize small bcopys such as are used to copy 4 |
---|
384 | byte IP addrs */ |
---|
385 | #ifdef __HIGHC__ |
---|
386 | #define bcopy(src, dest, cnt) memcpy(dest, src, cnt) |
---|
387 | extern char *memcpy(); |
---|
388 | #endif |
---|
389 | #ifdef __STDC__ |
---|
390 | #ifdef NFS |
---|
391 | extern int nfsid(const char *, struct in_addr, int, int, const char *, int, int); |
---|
392 | extern AUTH *spoofunix_create_default(char *, int); |
---|
393 | #endif |
---|
394 | extern int attach(const char *, string_list **mpl), detach(const char *); |
---|
395 | extern void detach_all(void), detach_host(const char *); |
---|
396 | extern int read_config_file(const char *); |
---|
397 | extern int parse_username(const char *); |
---|
398 | extern int trusted_user(int); |
---|
399 | extern void lock_attachtab(void), unlock_attachtab(void); |
---|
400 | extern void lint_attachtab(void), get_attachtab(void), free_attachtab(void); |
---|
401 | #ifdef ZEPHYR |
---|
402 | extern int zephyr_sub(int), zephyr_unsub(int); |
---|
403 | extern void zephyr_addsub(const char *); |
---|
404 | #endif |
---|
405 | extern int addcmd(int, char **); |
---|
406 | #else |
---|
407 | #ifdef NFS |
---|
408 | extern int nfsid(); |
---|
409 | extern AUTH *spoofunix_create_default(); |
---|
410 | #endif |
---|
411 | extern int attach(), detach(); |
---|
412 | extern void detach_all(), detach_host(); |
---|
413 | extern int read_config_file(), parse_username(), trusted_user(); |
---|
414 | extern void lock_attachtab(), unlock_attachtab(); |
---|
415 | extern void get_attachtab(), free_attachtab(); |
---|
416 | #ifdef ZEPHYR |
---|
417 | extern int zephyr_sub(), zephyr_unsub(); |
---|
418 | extern void zephyr_addsub(); |
---|
419 | #endif |
---|
420 | extern int addcmd(); |
---|
421 | #endif |
---|
422 | |
---|
423 | extern char *progname; |
---|
424 | |
---|
425 | /* |
---|
426 | * Instead of ifdef-ing all const declarations, make one global definition. |
---|
427 | * The AIX PS/2 compiler understands "const", but does not define __STDC__. |
---|
428 | */ |
---|
429 | #if !defined(__STDC__) && !(defined(AIX) && defined(i386)) |
---|
430 | #define const |
---|
431 | #endif |
---|