xref: /titanic_41/usr/src/cmd/fs.d/autofs/automount.h (revision e4b86885570d77af552e9cf94f142f4d744fb8c8)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_AUTOMOUNT_H
27 #define	_AUTOMOUNT_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <fslib.h>		/* needed for mntlist_t declaration */
32 #include <thread.h>
33 #include <sys/mntent.h>		/*    "    "  MNTTYPE_* declarations */
34 #include <synch.h>		/* needed for mutex_t declaration */
35 #include <sys/types.h>
36 #include <rpc/rpc.h>
37 #include <sys/fs/autofs.h>
38 #include <netinet/in.h>		/* needed for sockaddr_in declaration */
39 #include <door.h>
40 
41 #ifdef MALLOC_DEBUG
42 #include <debug_alloc.h>
43 #endif
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #ifndef _REENTRANT
50 #define	fork1			vfork
51 #define	rpc_control(a, b)	1
52 #endif
53 
54 #define	DOMOUNT_USER	1
55 #define	DOMOUNT_KERNEL	2
56 
57 /*
58  * Solaris autofs configuration file location
59  */
60 #define	AUTOFSADMIN	"/etc/default/autofs"
61 
62 #define	MXHOSTNAMELEN	64
63 #define	MAXNETNAMELEN   255
64 #define	MAXFILENAMELEN  255
65 #define	LINESZ		4096
66 #define	MAXADDRLEN	128		/* max autofs address length */
67 #define	MAXOPTSLEN	1024
68 
69 #define	AUTOFS_MOUNT_TIMEOUT	600	/* default min time mount will */
70 					/* remain mounted (in seconds) */
71 #define	AUTOFS_RPC_TIMEOUT	60	/* secs autofs will wait for */
72 					/* automountd's reply before */
73 					/* retransmitting */
74 /* stack ops */
75 #define	ERASE		0
76 #define	PUSH		1
77 #define	POP		2
78 #define	INIT		3
79 #define	STACKSIZ	30
80 
81 #define	DIST_SELF	1
82 #define	DIST_MYSUB	2
83 #define	DIST_MYNET	3
84 #define	DIST_OTHER	4
85 
86 #define	MAXIFS		32
87 
88 /*
89  * Retry operation related definitions.
90  */
91 #define	RET_OK		0
92 #define	RET_RETRY	32
93 #define	RET_ERR		33
94 #define	INITDELAY	5
95 #define	DELAY_BACKOFF	2
96 #define	MAXDELAY	120
97 #define	ARGV_MAX	16
98 #define	VFS_PATH	"/usr/lib/fs"
99 #define	DELAY(delay) { \
100 	(void) sleep(delay); \
101 	delay *= DELAY_BACKOFF; \
102 	if (delay > MAXDELAY) \
103 		delay = MAXDELAY; \
104 }
105 
106 struct mapline {
107 	char linebuf[LINESZ];
108 	char lineqbuf[LINESZ];
109 };
110 
111 /*
112  * Structure describing a host/filesystem/dir tuple in a NIS map entry
113  */
114 struct mapfs {
115 	struct mapfs *mfs_next;	/* next in entry */
116 	int 	mfs_ignore;	/* ignore this entry */
117 	char	*mfs_host;	/* host name */
118 	char	*mfs_dir;	/* dir to mount */
119 	int	mfs_penalty;	/* mount penalty for this host */
120 	int	mfs_distance;	/* distance hint */
121 	struct nfs_args *mfs_args;	/* nfs_args */
122 	struct netconfig *mfs_nconf;
123 	rpcvers_t	mfs_version;	/* NFS version */
124 
125 #define	MFS_ALLOC_DIR		0x1	/* mfs_dir now points to different */
126 					/* buffer */
127 
128 #define	MFS_URL			0x2	/* is NFS url listed in this tuple. */
129 #define	MFS_FH_VIA_WEBNFS	0x4	/* got file handle during ping phase */
130 
131 	uint_t	mfs_flags;
132 	uint_t	mfs_port;	/* port# in NFS url */
133 };
134 
135 /*
136  * NIS entry - lookup of name in DIR gets us this
137  */
138 struct mapent {
139 	char	*map_fstype;	/* file system type e.g. "nfs" */
140 	char	*map_mounter;	/* base fs e.g. "cachefs" */
141 	char	*map_root;	/* path to mount root */
142 	char	*map_mntpnt;	/* path from mount root */
143 	char	*map_mntopts;	/* mount options */
144 	char    *map_fsw;	/* mount fs information */
145 	char    *map_fswq;	/* quoted mountfs information */
146 	int	map_mntlevel;	/* mapentry hierarchy level */
147 	bool_t	map_modified;	/* flags modified mapentries */
148 	bool_t	map_faked;	/* flags faked mapentries */
149 	int	map_err;	/* flags any bad entries in the map */
150 	struct mapfs *map_fs;	/* list of replicas for nfs */
151 	struct mapent *map_next;
152 };
153 
154 
155 /*
156  * Descriptor for each directory served by the automounter
157  */
158 struct autodir {
159 	char	*dir_name;		/* mount point */
160 	char	*dir_map;		/* name of map for dir */
161 	char	*dir_opts;		/* default mount options */
162 	int 	dir_direct;		/* direct mountpoint ? */
163 	int 	dir_remount;		/* a remount */
164 	struct autodir *dir_next;	/* next entry */
165 	struct autodir *dir_prev;	/* prev entry */
166 };
167 
168 /*
169  * This structure is used to build an array of
170  * hostnames with associated penalties to be
171  * passed to the nfs_cast procedure
172  */
173 struct host_names {
174 	char *host;
175 	int  penalty;
176 };
177 
178 /*
179  * structure used to build list of contents for a map on
180  * a readdir request
181  */
182 struct dir_entry {
183 	char		*name;		/* name of entry */
184 	ino_t		nodeid;
185 	off_t		offset;
186 	struct dir_entry *next;
187 	struct dir_entry *left;		/* left element in binary tree */
188 	struct dir_entry *right;	/* right element in binary tree */
189 };
190 
191 /*
192  * offset index table
193  */
194 struct off_tbl {
195 	off_t			offset;
196 	struct dir_entry	*first;
197 	struct off_tbl		*next;
198 };
199 
200 #ifndef NO_RDDIR_CACHE
201 /*
202  * directory cache for 'map'
203  */
204 struct autofs_rddir_cache {
205 	char			*map;
206 	struct off_tbl		*offtp;
207 	ulong_t			bucket_size;
208 	time_t			ttl;
209 	struct dir_entry	*entp;
210 	mutex_t			lock;		/* protects 'in_use' field */
211 	int			in_use;		/* # threads referencing it */
212 	rwlock_t		rwlock;		/* protects 'full' and 'next' */
213 	int			full;		/* full == 1 when cache full */
214 	struct autofs_rddir_cache	*next;
215 };
216 
217 #define	RDDIR_CACHE_TIME	300		/* in seconds */
218 
219 #endif /* NO_RDDIR_CACHE */
220 
221 /*
222  * structure used to maintain address list for localhost
223  */
224 
225 struct myaddrs {
226 	struct sockaddr_in sin;
227 	struct myaddrs *myaddrs_next;
228 };
229 
230 /*
231  * structure used to pass commands to the door servers
232  */
233 
234 typedef struct command {
235 	char file[MAXPATHLEN];
236 	char argv[ARGV_MAX][MAXOPTSLEN];
237 	char key[MAXOPTSLEN];
238 	int console;
239 } command_t;
240 
241 /*
242  * globally visible door_server file descriptor
243  */
244 int did_exec_map;
245 int did_fork_exec;
246 
247 extern time_t timenow;	/* set at start of processing of each RPC call */
248 extern char self[];
249 extern int verbose;
250 extern int trace;
251 extern int automountd_nobrowse;
252 extern struct autodir *dir_head;
253 extern struct autodir *dir_tail;
254 extern struct mntlist *current_mounts;
255 struct mounta;			/* defined in sys/vfs.h */
256 extern struct myaddrs *myaddrs_head;
257 
258 extern rwlock_t	cache_lock;
259 extern rwlock_t portmap_cache_lock;
260 extern rwlock_t autofs_rddir_cache_lock;
261 
262 extern mutex_t cleanup_lock;
263 extern cond_t cleanup_start_cv;
264 extern cond_t cleanup_done_cv;
265 
266 /*
267  * mnttab handling routines
268  */
269 extern void free_mapent(struct mapent *);
270 extern struct mntlist *getmntlist(void);
271 extern dev_t get_devid(struct extmnttab *);
272 
273 /*
274  * utilities
275  */
276 extern struct mapent *parse_entry(char *, char *, char *, struct mapline *,
277 				char *, uint_t, bool_t);
278 extern int macro_expand(char *, char *, char *, int);
279 extern void unquote(char *, char *);
280 extern void unbracket(char **);
281 extern void trim(char *);
282 extern char *get_line(FILE *, char *, char *, int);
283 extern int getword(char *, char *, char **, char **, char, int);
284 extern int get_retry(char *);
285 extern int str_opt(struct mnttab *, char *, char **);
286 extern void put_automountd_env(void);
287 extern void dirinit(char *, char *, char *, int, char **, char ***);
288 extern void pr_msg(const char *, ...);
289 extern void trace_prt(int, char *, ...);
290 extern void free_autofs_args(autofs_args *);
291 extern void free_nfs_args(struct nfs_args *);
292 extern void free_mounta(struct mounta *);
293 
294 extern int nopt(struct mnttab *, char *, int *);
295 extern int set_versrange(rpcvers_t, rpcvers_t *, rpcvers_t *);
296 extern enum clnt_stat pingnfs(char *, int, rpcvers_t *, rpcvers_t,
297 	ushort_t, bool_t, char *, char *);
298 
299 extern void *autofs_get_buffer(size_t);
300 extern int self_check(char *);
301 extern int do_mount1(char *, char *, char *, char *, char *, uint_t, uid_t,
302 	action_list **, int);
303 extern int do_lookup1(char *, char *, char *, char *, char *, uint_t, uid_t,
304 	autofs_action_t *, struct linka *);
305 extern int do_unmount1(umntrequest *);
306 extern int do_readdir(autofs_rddirargs *, autofs_rddirres *);
307 extern int nfsunmount(struct mnttab *);
308 extern int loopbackmount(char *, char *, char *, int);
309 extern int mount_nfs(struct mapent *, char *, char *, int, uid_t,
310 	action_list **);
311 extern int mount_autofs(struct mapent *, char *, action_list *,
312 	char *rootp, char *subdir, char *key);
313 extern int mount_generic(char *, char *, char *, char *, int);
314 extern enum clnt_stat nfs_cast(struct mapfs *, struct mapfs **, int);
315 
316 extern bool_t hasrestrictopt(char *);
317 
318 #ifndef NO_RDDIR_CACHE
319 /*
320  * readdir handling routines
321  */
322 extern char *auto_rddir_malloc(unsigned);
323 extern char *auto_rddir_strdup(const char *);
324 extern struct dir_entry *btree_lookup(struct dir_entry *, char *);
325 extern void btree_enter(struct dir_entry **, struct dir_entry *);
326 extern int add_dir_entry(char *, struct dir_entry **, struct dir_entry **);
327 extern void cache_cleanup(void);
328 extern int autofs_rddir_cache_lookup(char *, struct autofs_rddir_cache **);
329 extern struct dir_entry *rddir_entry_lookup(char *, struct dir_entry *);
330 #endif /* NO_RDDIR_CACHE */
331 
332 /*
333  * generic interface to specific name service functions
334  */
335 extern void ns_setup(char **, char ***);
336 extern int getmapent(char *, char *, struct mapline *, char **, char ***,
337 			bool_t *, bool_t);
338 extern int getmapkeys(char *, struct dir_entry **, int *, int *, char **,
339 			char ***, uid_t);
340 extern int loadmaster_map(char *, char *, char **, char ***);
341 extern int loaddirect_map(char *, char *, char *, char **, char ***);
342 
343 /*
344  * these name service specific functions should not be
345  * accessed directly, use the generic functions.
346  */
347 extern void init_files(char **, char ***);
348 extern int getmapent_files(char *, char *, struct mapline *, char **, char ***,
349 				bool_t *, bool_t);
350 extern int loadmaster_files(char *, char *, char **, char ***);
351 extern int loaddirect_files(char *, char *, char *, char **, char ***);
352 extern int getmapkeys_files(char *, struct dir_entry **, int *, int *,
353 	char **, char ***);
354 extern int stack_op(int, char *, char **, char ***);
355 
356 extern void init_nisplus(char **, char ***);
357 extern int getmapent_nisplus(char *, char *, struct mapline *, char **,
358 				char ***, bool_t *, bool_t);
359 extern int loadmaster_nisplus(char *, char *, char **, char ***);
360 extern int loaddirect_nisplus(char *, char *, char *, char **, char ***);
361 extern int getmapkeys_nisplus(char *, struct dir_entry **, int *, int *,
362 	char **, char ***);
363 
364 extern void init_nis(char **, char ***);
365 extern int getmapent_nis(char *, char *, struct mapline *, char **, char ***,
366 				bool_t *, bool_t);
367 extern int loadmaster_nis(char *, char *, char **, char ***);
368 extern int loaddirect_nis(char *, char *, char *, char **, char ***);
369 extern int getmapkeys_nis(char *, struct dir_entry **, int *, int *,
370 	char **, char ***);
371 
372 extern void init_ldap(char **, char ***);
373 extern int getmapent_ldap(char *, char *, struct mapline *, char **, char ***,
374 				bool_t *, bool_t);
375 extern int loadmaster_ldap(char *, char *, char **, char ***);
376 extern int loaddirect_ldap(char *, char *, char *, char **, char ***);
377 extern int getmapkeys_ldap(char *, struct dir_entry **, int *, int *,
378 	char **, char ***);
379 
380 
381 /*
382  * end of name service specific functions
383  */
384 
385 /*
386  * not defined in any header file
387  */
388 extern bool_t xdr_uid_t(XDR *, uid_t *);
389 extern int __clnt_bindresvport(CLIENT *);
390 extern int getnetmaskbynet(const struct in_addr, struct in_addr *);
391 
392 /*
393  * Hidden rpc functions
394  */
395 extern int __nis_reset_state();
396 extern int __rpc_negotiate_uid(int);
397 
398 /*
399  * door_server functions to handle fork activity within the automounter
400  */
401 void automountd_do_fork_exec(void *, char *, size_t, door_desc_t *, uint_t);
402 void automountd_do_exec_map(void *, char *, size_t, door_desc_t *, uint_t);
403 
404 #ifdef __cplusplus
405 }
406 #endif
407 
408 #endif	/* _AUTOMOUNT_H */
409