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