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