xref: /netbsd-src/usr.sbin/autofs/common.h (revision 607f1423e01ca5ba53236308ebd4e3c7abcd1537)
1*607f1423Smrg /*	$NetBSD: common.h,v 1.2 2019/02/03 12:03:22 mrg Exp $	*/
2b985414bSchristos 
3b985414bSchristos /*-
4b985414bSchristos  * Copyright (c) 2017 The NetBSD Foundation, Inc.
5b985414bSchristos  * Copyright (c) 2016 The DragonFly Project
6b985414bSchristos  * Copyright (c) 2014 The FreeBSD Foundation
7b985414bSchristos  * All rights reserved.
8b985414bSchristos  *
9b985414bSchristos  * This code is derived from software contributed to The NetBSD Foundation
10b985414bSchristos  * by Tomohiro Kusumi <kusumi.tomohiro@gmail.com>.
11b985414bSchristos  *
12b985414bSchristos  * This software was developed by Edward Tomasz Napierala under sponsorship
13b985414bSchristos  * from the FreeBSD Foundation.
14b985414bSchristos  *
15b985414bSchristos  * Redistribution and use in source and binary forms, with or without
16b985414bSchristos  * modification, are permitted provided that the following conditions
17b985414bSchristos  * are met:
18b985414bSchristos  * 1. Redistributions of source code must retain the above copyright
19b985414bSchristos  *    notice, this list of conditions and the following disclaimer.
20b985414bSchristos  * 2. Redistributions in binary form must reproduce the above copyright
21b985414bSchristos  *    notice, this list of conditions and the following disclaimer in the
22b985414bSchristos  *    documentation and/or other materials provided with the distribution.
23b985414bSchristos  *
24b985414bSchristos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25b985414bSchristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26b985414bSchristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27b985414bSchristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28b985414bSchristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29b985414bSchristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30b985414bSchristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31b985414bSchristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32b985414bSchristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33b985414bSchristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34b985414bSchristos  * SUCH DAMAGE.
35b985414bSchristos  *
36b985414bSchristos  * $FreeBSD$
37b985414bSchristos  */
38b985414bSchristos 
39b985414bSchristos #ifndef AUTOMOUNTD_H
40b985414bSchristos #define	AUTOMOUNTD_H
41b985414bSchristos 
42b985414bSchristos #include <sys/types.h>
43b985414bSchristos #include <sys/queue.h>
44b985414bSchristos #include <stdio.h>
45b985414bSchristos #include <stdbool.h>
46b985414bSchristos 
47b985414bSchristos #define	AUTO_MASTER_PATH	"/etc/auto_master"
48b985414bSchristos #define	AUTO_MAP_PREFIX		"/etc"
49b985414bSchristos #define	AUTO_SPECIAL_PREFIX	"/etc/autofs"
50b985414bSchristos #define	AUTO_INCLUDE_PATH	AUTO_SPECIAL_PREFIX "/include"
51b985414bSchristos 
52b985414bSchristos struct node {
53b985414bSchristos 	TAILQ_ENTRY(node)	n_next;
54b985414bSchristos 	TAILQ_HEAD(nodehead, node)	n_children;
55b985414bSchristos 	struct node		*n_parent;
56b985414bSchristos 	char			*n_key;
57b985414bSchristos 	char			*n_options;
58b985414bSchristos 	char			*n_location;
59b985414bSchristos 	char			*n_map;
60b985414bSchristos 	const char		*n_config_file;
61b985414bSchristos 	int			n_config_line;
62b985414bSchristos };
63b985414bSchristos 
64b985414bSchristos struct defined_value {
65b985414bSchristos 	TAILQ_ENTRY(defined_value)	d_next;
66b985414bSchristos 	char				*d_name;
67b985414bSchristos 	char				*d_value;
68b985414bSchristos };
69b985414bSchristos 
70b985414bSchristos void	log_init(int);
71b985414bSchristos void	log_set_peer_name(const char *);
72b985414bSchristos void	log_set_peer_addr(const char *);
73*607f1423Smrg void	log_err(int, const char *, ...) __printflike(2, 3) __dead;
74*607f1423Smrg void	log_errx(int, const char *, ...) __printflike(2, 3) __dead;
75b985414bSchristos void	log_warn(const char *, ...) __printflike(1, 2);
76b985414bSchristos void	log_warnx(const char *, ...) __printflike(1, 2);
77b985414bSchristos void	log_debugx(const char *, ...) __printflike(1, 2);
78b985414bSchristos 
79b985414bSchristos char	*checked_strdup(const char *);
80b985414bSchristos char	*concat(const char *, char, const char *);
81b985414bSchristos void	create_directory(const char *);
82b985414bSchristos 
83b985414bSchristos struct node *node_new_root(void);
84b985414bSchristos struct node *node_new(struct node *, char *, char *, char *, const char *,
85b985414bSchristos     int);
86b985414bSchristos struct node *node_new_map(struct node *, char *, char *, char *,
87b985414bSchristos     const char *, int);
88b985414bSchristos struct node *node_find(struct node *, const char *mountpoint);
89b985414bSchristos bool	node_is_direct_map(const struct node *);
90b985414bSchristos bool	node_has_wildcards(const struct node *);
91b985414bSchristos char	*node_path(const struct node *);
92b985414bSchristos char	*node_options(const struct node *);
93b985414bSchristos void	node_expand_ampersand(struct node *, const char *);
94b985414bSchristos void	node_expand_wildcard(struct node *, const char *);
95b985414bSchristos int	node_expand_defined(struct node *);
96b985414bSchristos void	node_expand_indirect_maps(struct node *);
97b985414bSchristos void	node_print(const struct node *, const char *);
98b985414bSchristos void	parse_master(struct node *, const char *);
99b985414bSchristos void	parse_map(struct node *, const char *, const char *, bool *);
100b985414bSchristos char	*defined_expand(const char *);
101b985414bSchristos void	defined_init(void);
102b985414bSchristos void	defined_parse_and_add(char *);
103b985414bSchristos void	lesser_daemon(void);
104b985414bSchristos 
105b985414bSchristos int	main_automount(int, char **);
106b985414bSchristos int	main_automountd(int, char **);
107b985414bSchristos int	main_autounmountd(int, char **);
108b985414bSchristos 
109b985414bSchristos FILE	*auto_popen(const char *, ...);
110b985414bSchristos int	auto_pclose(FILE *);
111b985414bSchristos 
112b985414bSchristos /*
113b985414bSchristos  * lex(1) stuff.
114b985414bSchristos  */
115b985414bSchristos extern int lineno;
116b985414bSchristos 
117b985414bSchristos #define	STR	1
118b985414bSchristos #define	NEWLINE	2
119b985414bSchristos 
120b985414bSchristos #endif /* !AUTOMOUNTD_H */
121