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