xref: /titanic_51/usr/src/cmd/fs.d/autofs/automount.h (revision b51e021de072d76292addb44467f777617c6a8c1)
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 2006 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 <ucred.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	DELAY(delay) { \
98 	(void) sleep(delay); \
99 	delay *= DELAY_BACKOFF; \
100 	if (delay > MAXDELAY) \
101 		delay = MAXDELAY; \
102 }
103 
104 struct mapline {
105 	char linebuf[LINESZ];
106 	char lineqbuf[LINESZ];
107 };
108 
109 /*
110  * Structure describing a host/filesystem/dir tuple in a NIS map entry
111  */
112 struct mapfs {
113 	struct mapfs *mfs_next;	/* next in entry */
114 	int 	mfs_ignore;	/* ignore this entry */
115 	char	*mfs_host;	/* host name */
116 	char	*mfs_dir;	/* dir to mount */
117 	int	mfs_penalty;	/* mount penalty for this host */
118 	int	mfs_distance;	/* distance hint */
119 	struct nfs_args *mfs_args;	/* nfs_args */
120 	struct netconfig *mfs_nconf;
121 	rpcvers_t	mfs_version;	/* NFS version */
122 
123 #define	MFS_ALLOC_DIR		0x1	/* mfs_dir now points to different */
124 					/* buffer */
125 
126 #define	MFS_URL			0x2	/* is NFS url listed in this tuple. */
127 #define	MFS_FH_VIA_WEBNFS	0x4	/* got file handle during ping phase */
128 
129 	uint_t	mfs_flags;
130 	uint_t	mfs_port;	/* port# in NFS url */
131 };
132 
133 /*
134  * NIS entry - lookup of name in DIR gets us this
135  */
136 struct mapent {
137 	char	*map_fstype;	/* file system type e.g. "nfs" */
138 	char	*map_mounter;	/* base fs e.g. "cachefs" */
139 	char	*map_root;	/* path to mount root */
140 	char	*map_mntpnt;	/* path from mount root */
141 	char	*map_mntopts;	/* mount options */
142 	char    *map_fsw;	/* mount fs information */
143 	char    *map_fswq;	/* quoted mountfs information */
144 	int	map_mntlevel;	/* mapentry hierarchy level */
145 	bool_t	map_modified;	/* flags modified mapentries */
146 	bool_t	map_faked;	/* flags faked mapentries */
147 	int	map_err;	/* flags any bad entries in the map */
148 	struct mapfs *map_fs;	/* list of replicas for nfs */
149 	struct mapent *map_next;
150 };
151 
152 
153 /*
154  * Descriptor for each directory served by the automounter
155  */
156 struct autodir {
157 	char	*dir_name;		/* mount point */
158 	char	*dir_map;		/* name of map for dir */
159 	char	*dir_opts;		/* default mount options */
160 	int 	dir_direct;		/* direct mountpoint ? */
161 	int 	dir_remount;		/* a remount */
162 	struct autodir *dir_next;	/* next entry */
163 	struct autodir *dir_prev;	/* prev entry */
164 };
165 
166 /*
167  * This structure is used to build an array of
168  * hostnames with associated penalties to be
169  * passed to the nfs_cast procedure
170  */
171 struct host_names {
172 	char *host;
173 	int  penalty;
174 };
175 
176 /*
177  * structure used to build list of contents for a map on
178  * a readdir request
179  */
180 struct dir_entry {
181 	char		*name;		/* name of entry */
182 	ino_t		nodeid;
183 	off_t		offset;
184 	struct dir_entry *next;
185 	struct dir_entry *left;		/* left element in binary tree */
186 	struct dir_entry *right;	/* right element in binary tree */
187 };
188 
189 /*
190  * offset index table
191  */
192 struct off_tbl {
193 	off_t			offset;
194 	struct dir_entry	*first;
195 	struct off_tbl		*next;
196 };
197 
198 #ifndef NO_RDDIR_CACHE
199 /*
200  * directory cache for 'map'
201  */
202 struct autofs_rddir_cache {
203 	char			*map;
204 	struct off_tbl		*offtp;
205 	ulong_t			bucket_size;
206 	time_t			ttl;
207 	struct dir_entry	*entp;
208 	mutex_t			lock;		/* protects 'in_use' field */
209 	int			in_use;		/* # threads referencing it */
210 	rwlock_t		rwlock;		/* protects 'full' and 'next' */
211 	int			full;		/* full == 1 when cache full */
212 	struct autofs_rddir_cache	*next;
213 };
214 
215 #define	RDDIR_CACHE_TIME	300		/* in seconds */
216 
217 #endif /* NO_RDDIR_CACHE */
218 
219 /*
220  * structure used to maintain address list for localhost
221  */
222 
223 struct myaddrs {
224 	struct sockaddr_in sin;
225 	struct myaddrs *myaddrs_next;
226 };
227 
228 extern time_t timenow;	/* set at start of processing of each RPC call */
229 extern char self[];
230 extern int verbose;
231 extern int trace;
232 extern int automountd_nobrowse;
233 extern struct autodir *dir_head;
234 extern struct autodir *dir_tail;
235 extern struct mntlist *current_mounts;
236 struct mounta;			/* defined in sys/vfs.h */
237 extern struct myaddrs *myaddrs_head;
238 
239 extern rwlock_t	cache_lock;
240 extern rwlock_t portmap_cache_lock;
241 extern rwlock_t autofs_rddir_cache_lock;
242 
243 extern mutex_t cleanup_lock;
244 extern cond_t cleanup_start_cv;
245 extern cond_t cleanup_done_cv;
246 
247 /*
248  * mnttab handling routines
249  */
250 extern void free_mapent(struct mapent *);
251 extern struct mntlist *getmntlist(void);
252 extern dev_t get_devid(struct extmnttab *);
253 
254 /*
255  * utilities
256  */
257 extern struct mapent *parse_entry(char *, char *, char *, struct mapline *,
258 				char *, uint_t, bool_t);
259 extern int macro_expand(char *, char *, char *, int);
260 extern void unquote(char *, char *);
261 extern void trim(char *);
262 extern char *get_line(FILE *, char *, char *, int);
263 extern int getword(char *, char *, char **, char **, char, int);
264 extern int get_retry(char *);
265 extern int str_opt(struct mnttab *, char *, char **);
266 extern void put_automountd_env(void);
267 extern void dirinit(char *, char *, char *, int, char **, char ***);
268 extern void pr_msg(const char *, ...);
269 extern void trace_prt(int, char *, ...);
270 extern void free_autofs_args(autofs_args *);
271 extern void free_nfs_args(struct nfs_args *);
272 extern void free_mounta(struct mounta *);
273 
274 extern int nopt(struct mnttab *, char *, int *);
275 extern int set_versrange(rpcvers_t, rpcvers_t *, rpcvers_t *);
276 extern enum clnt_stat pingnfs(char *, int, rpcvers_t *, rpcvers_t,
277 	ushort_t, bool_t, char *, char *);
278 
279 extern void *autofs_get_buffer(size_t);
280 extern int self_check(char *);
281 extern int do_mount1(char *, char *, char *, char *, char *, uint_t,
282 	action_list **, ucred_t *, int);
283 extern int do_lookup1(char *, char *, char *, char *, char *, uint_t,
284 	autofs_action_t *, struct linka *, ucred_t *);
285 extern int do_unmount1(umntrequest *);
286 extern int do_readdir(autofs_rddirargs *, autofs_rddirres *, ucred_t *);
287 extern int nfsunmount(struct mnttab *);
288 extern int loopbackmount(char *, char *, char *, int);
289 extern int mount_nfs(struct mapent *, char *, char *, int,
290 	ucred_t *, action_list **);
291 extern int mount_autofs(struct mapent *, char *, action_list *,
292 	char *rootp, char *subdir, char *key);
293 extern int mount_generic(char *, char *, char *, char *, int);
294 extern enum clnt_stat nfs_cast(struct mapfs *, struct mapfs **, int);
295 
296 extern bool_t hasrestrictopt(char *);
297 
298 #ifndef NO_RDDIR_CACHE
299 /*
300  * readdir handling routines
301  */
302 extern char *auto_rddir_malloc(unsigned);
303 extern char *auto_rddir_strdup(const char *);
304 extern struct dir_entry *btree_lookup(struct dir_entry *, char *);
305 extern void btree_enter(struct dir_entry **, struct dir_entry *);
306 extern int add_dir_entry(char *, struct dir_entry **, struct dir_entry **);
307 extern void cache_cleanup(void);
308 extern int autofs_rddir_cache_lookup(char *, struct autofs_rddir_cache **);
309 extern struct dir_entry *rddir_entry_lookup(char *, struct dir_entry *);
310 #endif /* NO_RDDIR_CACHE */
311 
312 /*
313  * generic interface to specific name service functions
314  */
315 extern void ns_setup(char **, char ***);
316 extern int getmapent(char *, char *, struct mapline *, char **, char ***,
317 			bool_t *, bool_t);
318 extern int getmapkeys(char *, struct dir_entry **, int *, int *, char **,
319 			char ***, uid_t);
320 extern int loadmaster_map(char *, char *, char **, char ***);
321 extern int loaddirect_map(char *, char *, char *, char **, char ***);
322 
323 /*
324  * these name service specific functions should not be
325  * accessed directly, use the generic functions.
326  */
327 extern void init_files(char **, char ***);
328 extern int getmapent_files(char *, char *, struct mapline *, char **, char ***,
329 				bool_t *, bool_t);
330 extern int loadmaster_files(char *, char *, char **, char ***);
331 extern int loaddirect_files(char *, char *, char *, char **, char ***);
332 extern int getmapkeys_files(char *, struct dir_entry **, int *, int *,
333 	char **, char ***);
334 extern int stack_op(int, char *, char **, char ***);
335 
336 extern void init_nisplus(char **, char ***);
337 extern int getmapent_nisplus(char *, char *, struct mapline *, char **,
338 				char ***, bool_t *, bool_t);
339 extern int loadmaster_nisplus(char *, char *, char **, char ***);
340 extern int loaddirect_nisplus(char *, char *, char *, char **, char ***);
341 extern int getmapkeys_nisplus(char *, struct dir_entry **, int *, int *,
342 	char **, char ***);
343 
344 extern void init_nis(char **, char ***);
345 extern int getmapent_nis(char *, char *, struct mapline *, char **, char ***,
346 				bool_t *, bool_t);
347 extern int loadmaster_nis(char *, char *, char **, char ***);
348 extern int loaddirect_nis(char *, char *, char *, char **, char ***);
349 extern int getmapkeys_nis(char *, struct dir_entry **, int *, int *,
350 	char **, char ***);
351 
352 extern void init_ldap(char **, char ***);
353 extern int getmapent_ldap(char *, char *, struct mapline *, char **, char ***,
354 				bool_t *, bool_t);
355 extern int loadmaster_ldap(char *, char *, char **, char ***);
356 extern int loaddirect_ldap(char *, char *, char *, char **, char ***);
357 extern int getmapkeys_ldap(char *, struct dir_entry **, int *, int *,
358 	char **, char ***);
359 
360 
361 /*
362  * end of name service specific functions
363  */
364 
365 /*
366  * not defined in any header file
367  */
368 extern bool_t xdr_uid_t(XDR *, uid_t *);
369 extern int __clnt_bindresvport(CLIENT *);
370 extern int getnetmaskbynet(const struct in_addr, struct in_addr *);
371 
372 /*
373  * Hidden rpc functions
374  */
375 extern int __nis_reset_state();
376 extern int __rpc_negotiate_uid(int);
377 
378 #ifdef __cplusplus
379 }
380 #endif
381 
382 #endif	/* _AUTOMOUNT_H */
383