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