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.
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.
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]
23 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
27 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
34 #include <fslib.h> /* needed for mntlist_t declaration */
36 #include <sys/mntent.h> /* " " MNTTYPE_* declarations */
37 #include <synch.h> /* needed for mutex_t declaration */
38 #include <sys/types.h>
40 #include <sys/fs/autofs.h>
41 #include <netinet/in.h> /* needed for sockaddr_in declaration */
45 #include <debug_alloc.h>
52 #define DOMOUNT_USER 1
53 #define DOMOUNT_KERNEL 2
56 * Solaris autofs configuration file location
58 #define AUTOFSADMIN "/etc/default/autofs"
60 #define MXHOSTNAMELEN 64
61 #define MAXNETNAMELEN 255
62 #define MAXFILENAMELEN 255
64 #define MAXADDRLEN 128 /* max autofs address length */
65 #define MAXOPTSLEN 1024
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 */
87 * Retry operation related definitions.
93 #define DELAY_BACKOFF 2
96 #define VFS_PATH "/usr/lib/fs"
97 #define DELAY(delay) { \
98 (void) sleep(delay); \
99 delay *= DELAY_BACKOFF; \
100 if (delay > MAXDELAY) \
105 char linebuf
[LINESZ
];
106 char lineqbuf
[LINESZ
];
110 * Structure describing a host/filesystem/dir tuple in a NIS map entry
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 */
123 #define MFS_ALLOC_DIR 0x1 /* mfs_dir now points to different */
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 */
130 uint_t mfs_port
; /* port# in NFS url */
134 * NIS entry - lookup of name in DIR gets us this
137 char *map_fstype
; /* file system type e.g. "nfs" */
138 char *map_mounter
; /* base fs */
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
;
154 * Descriptor for each directory served by the automounter
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 */
167 * This structure is used to build an array of
168 * hostnames with associated penalties to be
169 * passed to the nfs_cast procedure
177 * structure used to build list of contents for a map on
181 char *name
; /* name of entry */
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 */
194 struct dir_entry
*first
;
195 struct off_tbl
*next
;
198 #ifndef NO_RDDIR_CACHE
200 * directory cache for 'map'
202 struct autofs_rddir_cache
{
204 struct off_tbl
*offtp
;
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
;
215 #define RDDIR_CACHE_TIME 300 /* in seconds */
217 #endif /* NO_RDDIR_CACHE */
220 * structure used to maintain address list for localhost
224 struct sockaddr_in sin
;
225 struct myaddrs
*myaddrs_next
;
229 * structure used to pass commands to the door servers
232 typedef struct command
{
233 char file
[MAXPATHLEN
];
234 char argv
[ARGV_MAX
][MAXOPTSLEN
];
235 char key
[MAXOPTSLEN
];
240 * globally visible door_server file descriptor
245 extern time_t timenow
; /* set at start of processing of each RPC call */
249 extern int automountd_nobrowse
;
250 extern struct autodir
*dir_head
;
251 extern struct autodir
*dir_tail
;
252 extern struct mntlist
*current_mounts
;
253 struct mounta
; /* defined in sys/vfs.h */
254 extern struct myaddrs
*myaddrs_head
;
256 extern rwlock_t cache_lock
;
257 extern rwlock_t portmap_cache_lock
;
258 extern rwlock_t autofs_rddir_cache_lock
;
260 extern mutex_t cleanup_lock
;
261 extern cond_t cleanup_start_cv
;
262 extern cond_t cleanup_done_cv
;
265 * mnttab handling routines
267 extern void free_mapent(struct mapent
*);
268 extern struct mntlist
*getmntlist(void);
269 extern dev_t
get_devid(struct extmnttab
*);
274 extern struct mapent
*parse_entry(char *, char *, char *, struct mapline
*,
275 char *, uint_t
, bool_t
);
276 extern int macro_expand(char *, char *, char *, int);
277 extern void unquote(char *, char *);
278 extern void unbracket(char **);
279 extern void trim(char *);
280 extern char *get_line(FILE *, char *, char *, int);
281 extern int getword(char *, char *, char **, char **, char, int);
282 extern int get_retry(char *);
283 extern int str_opt(struct mnttab
*, char *, char **);
284 extern void put_automountd_env(void);
285 extern void dirinit(char *, char *, char *, int, char **, char ***);
286 extern void pr_msg(const char *, ...);
287 extern void trace_prt(int, char *, ...);
288 extern void free_autofs_args(autofs_args
*);
289 extern void free_nfs_args(struct nfs_args
*);
290 extern void free_mounta(struct mounta
*);
292 extern int nopt(struct mnttab
*, char *, int *);
293 extern int set_versrange(rpcvers_t
, rpcvers_t
*, rpcvers_t
*);
294 extern enum clnt_stat
pingnfs(char *, int, rpcvers_t
*, rpcvers_t
,
295 ushort_t
, bool_t
, char *, char *);
297 extern void *autofs_get_buffer(size_t);
298 extern int self_check(char *);
299 extern int do_mount1(char *, char *, char *, char *, char *, uint_t
, uid_t
,
300 action_list
**, int);
301 extern int do_lookup1(char *, char *, char *, char *, char *, uint_t
, uid_t
,
302 autofs_action_t
*, struct linka
*);
303 extern int do_unmount1(umntrequest
*);
304 extern int do_readdir(autofs_rddirargs
*, autofs_rddirres
*);
305 extern int nfsunmount(struct mnttab
*);
306 extern int loopbackmount(char *, char *, char *, int);
307 extern int mount_nfs(struct mapent
*, char *, char *, int, uid_t
,
309 extern int mount_autofs(struct mapent
*, char *, action_list
*,
310 char *rootp
, char *subdir
, char *key
);
311 extern int mount_generic(char *, char *, char *, char *, int);
312 extern enum clnt_stat
nfs_cast(struct mapfs
*, struct mapfs
**, int);
314 extern bool_t
hasrestrictopt(char *);
316 #ifndef NO_RDDIR_CACHE
318 * readdir handling routines
320 extern char *auto_rddir_malloc(unsigned);
321 extern char *auto_rddir_strdup(const char *);
322 extern struct dir_entry
*btree_lookup(struct dir_entry
*, char *);
323 extern void btree_enter(struct dir_entry
**, struct dir_entry
*);
324 extern int add_dir_entry(char *, struct dir_entry
**, struct dir_entry
**);
325 extern void cache_cleanup(void);
326 extern int autofs_rddir_cache_lookup(char *, struct autofs_rddir_cache
**);
327 extern struct dir_entry
*rddir_entry_lookup(char *, struct dir_entry
*);
328 #endif /* NO_RDDIR_CACHE */
331 * generic interface to specific name service functions
333 extern void ns_setup(char **, char ***);
334 extern int getmapent(char *, char *, struct mapline
*, char **, char ***,
336 extern int getmapkeys(char *, struct dir_entry
**, int *, int *, char **,
338 extern int loadmaster_map(char *, char *, char **, char ***);
339 extern int loaddirect_map(char *, char *, char *, char **, char ***);
342 * these name service specific functions should not be
343 * accessed directly, use the generic functions.
345 extern void init_files(char **, char ***);
346 extern int getmapent_files(char *, char *, struct mapline
*, char **, char ***,
348 extern int loadmaster_files(char *, char *, char **, char ***);
349 extern int loaddirect_files(char *, char *, char *, char **, char ***);
350 extern int getmapkeys_files(char *, struct dir_entry
**, int *, int *,
352 extern int stack_op(int, char *, char **, char ***);
354 extern void init_nis(char **, char ***);
355 extern int getmapent_nis(char *, char *, struct mapline
*, char **, char ***,
357 extern int loadmaster_nis(char *, char *, char **, char ***);
358 extern int loaddirect_nis(char *, char *, char *, char **, char ***);
359 extern int getmapkeys_nis(char *, struct dir_entry
**, int *, int *,
362 extern void init_ldap(char **, char ***);
363 extern int getmapent_ldap(char *, char *, struct mapline
*, char **, char ***,
365 extern int loadmaster_ldap(char *, char *, char **, char ***);
366 extern int loaddirect_ldap(char *, char *, char *, char **, char ***);
367 extern int getmapkeys_ldap(char *, struct dir_entry
**, int *, int *,
372 * end of name service specific functions
376 * not defined in any header file
378 extern int __clnt_bindresvport(CLIENT
*);
379 extern int getnetmaskbynet(const struct in_addr
, struct in_addr
*);
382 * Hidden rpc functions
384 extern int __nis_reset_state();
385 extern int __rpc_negotiate_uid(int);
388 * door_server functions to handle fork activity within the automounter
390 void automountd_do_fork_exec(void *, char *, size_t, door_desc_t
*, uint_t
);
391 void automountd_do_exec_map(void *, char *, size_t, door_desc_t
*, uint_t
);
397 #endif /* _AUTOMOUNT_H */