1*8bae5d40Schristos /* $NetBSD: conf.c,v 1.1.1.3 2015/01/17 16:34:15 christos Exp $ */
2a53f50b9Schristos
3a53f50b9Schristos /*
4*8bae5d40Schristos * Copyright (c) 1997-2014 Erez Zadok
5a53f50b9Schristos * Copyright (c) 1990 Jan-Simon Pendry
6a53f50b9Schristos * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
7a53f50b9Schristos * Copyright (c) 1990 The Regents of the University of California.
8a53f50b9Schristos * All rights reserved.
9a53f50b9Schristos *
10a53f50b9Schristos * This code is derived from software contributed to Berkeley by
11a53f50b9Schristos * Jan-Simon Pendry at Imperial College, London.
12a53f50b9Schristos *
13a53f50b9Schristos * Redistribution and use in source and binary forms, with or without
14a53f50b9Schristos * modification, are permitted provided that the following conditions
15a53f50b9Schristos * are met:
16a53f50b9Schristos * 1. Redistributions of source code must retain the above copyright
17a53f50b9Schristos * notice, this list of conditions and the following disclaimer.
18a53f50b9Schristos * 2. Redistributions in binary form must reproduce the above copyright
19a53f50b9Schristos * notice, this list of conditions and the following disclaimer in the
20a53f50b9Schristos * documentation and/or other materials provided with the distribution.
21*8bae5d40Schristos * 3. Neither the name of the University nor the names of its contributors
22a53f50b9Schristos * may be used to endorse or promote products derived from this software
23a53f50b9Schristos * without specific prior written permission.
24a53f50b9Schristos *
25a53f50b9Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26a53f50b9Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27a53f50b9Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28a53f50b9Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29a53f50b9Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30a53f50b9Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31a53f50b9Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32a53f50b9Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33a53f50b9Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34a53f50b9Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35a53f50b9Schristos * SUCH DAMAGE.
36a53f50b9Schristos *
37a53f50b9Schristos *
38a53f50b9Schristos * File: am-utils/amd/conf.c
39a53f50b9Schristos *
40a53f50b9Schristos */
41a53f50b9Schristos
42a53f50b9Schristos /*
43a53f50b9Schristos * Functions to handle the configuration file.
44a53f50b9Schristos */
45a53f50b9Schristos
46a53f50b9Schristos #ifdef HAVE_CONFIG_H
47a53f50b9Schristos # include <config.h>
48a53f50b9Schristos #endif /* HAVE_CONFIG_H */
49a53f50b9Schristos #include <am_defs.h>
50a53f50b9Schristos #include <amd.h>
51a53f50b9Schristos
52a53f50b9Schristos
53a53f50b9Schristos /*
54a53f50b9Schristos * MACROS:
55a53f50b9Schristos */
56a53f50b9Schristos /* Turn on to show some info about maps being configured */
57a53f50b9Schristos /* #define DEBUG_CONF */
58a53f50b9Schristos
59a53f50b9Schristos /*
60a53f50b9Schristos * TYPEDEFS:
61a53f50b9Schristos */
62a53f50b9Schristos typedef int (*OptFuncPtr)(const char *);
63a53f50b9Schristos
64a53f50b9Schristos /*
65a53f50b9Schristos * STRUCTURES:
66a53f50b9Schristos */
67a53f50b9Schristos struct _func_map {
68a53f50b9Schristos char *name;
69a53f50b9Schristos OptFuncPtr func;
70a53f50b9Schristos };
71a53f50b9Schristos
72a53f50b9Schristos /*
73a53f50b9Schristos * FORWARD DECLARATIONS:
74a53f50b9Schristos */
75a53f50b9Schristos static int gopt_arch(const char *val);
76a53f50b9Schristos static int gopt_auto_attrcache(const char *val);
77a53f50b9Schristos static int gopt_auto_dir(const char *val);
78*8bae5d40Schristos static int gopt_auto_nfs_version(const char *val);
79a53f50b9Schristos static int gopt_autofs_use_lofs(const char *val);
80a53f50b9Schristos static int gopt_browsable_dirs(const char *val);
81a53f50b9Schristos static int gopt_cache_duration(const char *val);
82a53f50b9Schristos static int gopt_cluster(const char *val);
83a53f50b9Schristos static int gopt_debug_mtab_file(const char *val);
84a53f50b9Schristos static int gopt_debug_options(const char *val);
85a53f50b9Schristos static int gopt_dismount_interval(const char *val);
86a53f50b9Schristos static int gopt_domain_strip(const char *val);
87a53f50b9Schristos static int gopt_exec_map_timeout(const char *val);
88a53f50b9Schristos static int gopt_forced_unmounts(const char *val);
89a53f50b9Schristos static int gopt_full_os(const char *val);
90a53f50b9Schristos static int gopt_fully_qualified_hosts(const char *val);
91a53f50b9Schristos static int gopt_hesiod_base(const char *val);
92a53f50b9Schristos static int gopt_karch(const char *val);
93a53f50b9Schristos static int gopt_ldap_base(const char *val);
94a53f50b9Schristos static int gopt_ldap_cache_maxmem(const char *val);
95a53f50b9Schristos static int gopt_ldap_cache_seconds(const char *val);
96a53f50b9Schristos static int gopt_ldap_hostports(const char *val);
97a53f50b9Schristos static int gopt_ldap_proto_version(const char *val);
98a53f50b9Schristos static int gopt_local_domain(const char *val);
99a53f50b9Schristos static int gopt_localhost_address(const char *val);
100a53f50b9Schristos static int gopt_log_file(const char *val);
101a53f50b9Schristos static int gopt_log_options(const char *val);
102a53f50b9Schristos static int gopt_map_defaults(const char *val);
103a53f50b9Schristos static int gopt_map_options(const char *val);
104a53f50b9Schristos static int gopt_map_reload_interval(const char *val);
105a53f50b9Schristos static int gopt_map_type(const char *val);
106a53f50b9Schristos static int gopt_mount_type(const char *val);
107a53f50b9Schristos static int gopt_pid_file(const char *val);
108a53f50b9Schristos static int gopt_portmap_program(const char *val);
109a53f50b9Schristos static int gopt_preferred_amq_port(const char *val);
110a53f50b9Schristos static int gopt_nfs_allow_any_interface(const char *val);
111a53f50b9Schristos static int gopt_nfs_allow_insecure_port(const char *val);
112a53f50b9Schristos static int gopt_nfs_proto(const char *val);
113a53f50b9Schristos static int gopt_nfs_retransmit_counter(const char *val);
114a53f50b9Schristos static int gopt_nfs_retransmit_counter_udp(const char *val);
115a53f50b9Schristos static int gopt_nfs_retransmit_counter_tcp(const char *val);
116a53f50b9Schristos static int gopt_nfs_retransmit_counter_toplvl(const char *val);
117a53f50b9Schristos static int gopt_nfs_retry_interval(const char *val);
118a53f50b9Schristos static int gopt_nfs_retry_interval_udp(const char *val);
119a53f50b9Schristos static int gopt_nfs_retry_interval_tcp(const char *val);
120a53f50b9Schristos static int gopt_nfs_retry_interval_toplvl(const char *val);
121a53f50b9Schristos static int gopt_nfs_vers(const char *val);
122*8bae5d40Schristos static int gopt_nfs_vers_ping(const char *val);
123a53f50b9Schristos static int gopt_nis_domain(const char *val);
124a53f50b9Schristos static int gopt_normalize_hostnames(const char *val);
125a53f50b9Schristos static int gopt_normalize_slashes(const char *val);
126a53f50b9Schristos static int gopt_os(const char *val);
127a53f50b9Schristos static int gopt_osver(const char *val);
128a53f50b9Schristos static int gopt_plock(const char *val);
129a53f50b9Schristos static int gopt_print_pid(const char *val);
130a53f50b9Schristos static int gopt_print_version(const char *val);
131a53f50b9Schristos static int gopt_restart_mounts(const char *val);
132a53f50b9Schristos static int gopt_search_path(const char *val);
133a53f50b9Schristos static int gopt_selectors_in_defaults(const char *val);
134a53f50b9Schristos static int gopt_show_statfs_entries(const char *val);
135a53f50b9Schristos static int gopt_sun_map_syntax(const char *val);
136a53f50b9Schristos static int gopt_truncate_log(const char *val);
137a53f50b9Schristos static int gopt_unmount_on_exit(const char *val);
138a53f50b9Schristos static int gopt_use_tcpwrappers(const char *val);
139a53f50b9Schristos static int gopt_vendor(const char *val);
140a53f50b9Schristos static int process_global_option(const char *key, const char *val);
141a53f50b9Schristos static int process_one_regular_map(const cf_map_t *cfm);
142a53f50b9Schristos static int process_regular_option(const char *section, const char *key, const char *val, cf_map_t *cfm);
143a53f50b9Schristos static int ropt_browsable_dirs(const char *val, cf_map_t *cfm);
144a53f50b9Schristos static int ropt_map_name(const char *val, cf_map_t *cfm);
145a53f50b9Schristos static int ropt_map_defaults(const char *val, cf_map_t *cfm);
146a53f50b9Schristos static int ropt_map_options(const char *val, cf_map_t *cfm);
147a53f50b9Schristos static int ropt_map_type(const char *val, cf_map_t *cfm);
148a53f50b9Schristos static int ropt_mount_type(const char *val, cf_map_t *cfm);
149a53f50b9Schristos static int ropt_search_path(const char *val, cf_map_t *cfm);
150a53f50b9Schristos static int ropt_sun_map_syntax(const char *val, cf_map_t *cfm);
151a53f50b9Schristos static int ropt_tag(const char *val, cf_map_t *cfm);
152a53f50b9Schristos static void init_cf_map(cf_map_t *cfm);
153a53f50b9Schristos
154a53f50b9Schristos
155a53f50b9Schristos /*
156a53f50b9Schristos * STATIC VARIABLES:
157a53f50b9Schristos */
158a53f50b9Schristos static cf_map_t *head_map, *cur_map;
159a53f50b9Schristos
160a53f50b9Schristos static struct _func_map glob_functable[] = {
161a53f50b9Schristos {"arch", gopt_arch},
162a53f50b9Schristos {"auto_attrcache", gopt_auto_attrcache},
163a53f50b9Schristos {"auto_dir", gopt_auto_dir},
164*8bae5d40Schristos {"auto_nfs_version", gopt_auto_nfs_version},
165a53f50b9Schristos {"autofs_use_lofs", gopt_autofs_use_lofs},
166a53f50b9Schristos {"browsable_dirs", gopt_browsable_dirs},
167a53f50b9Schristos {"cache_duration", gopt_cache_duration},
168a53f50b9Schristos {"cluster", gopt_cluster},
169a53f50b9Schristos {"debug_mtab_file", gopt_debug_mtab_file},
170a53f50b9Schristos {"debug_options", gopt_debug_options},
171a53f50b9Schristos {"dismount_interval", gopt_dismount_interval},
172a53f50b9Schristos {"domain_strip", gopt_domain_strip},
173a53f50b9Schristos {"exec_map_timeout", gopt_exec_map_timeout},
174a53f50b9Schristos {"forced_unmounts", gopt_forced_unmounts},
175a53f50b9Schristos {"fully_qualified_hosts", gopt_fully_qualified_hosts},
176a53f50b9Schristos {"full_os", gopt_full_os},
177a53f50b9Schristos {"hesiod_base", gopt_hesiod_base},
178a53f50b9Schristos {"karch", gopt_karch},
179a53f50b9Schristos {"ldap_base", gopt_ldap_base},
180a53f50b9Schristos {"ldap_cache_maxmem", gopt_ldap_cache_maxmem},
181a53f50b9Schristos {"ldap_cache_seconds", gopt_ldap_cache_seconds},
182a53f50b9Schristos {"ldap_hostports", gopt_ldap_hostports},
183a53f50b9Schristos {"ldap_proto_version", gopt_ldap_proto_version},
184a53f50b9Schristos {"local_domain", gopt_local_domain},
185a53f50b9Schristos {"localhost_address", gopt_localhost_address},
186a53f50b9Schristos {"log_file", gopt_log_file},
187a53f50b9Schristos {"log_options", gopt_log_options},
188a53f50b9Schristos {"map_defaults", gopt_map_defaults},
189a53f50b9Schristos {"map_options", gopt_map_options},
190a53f50b9Schristos {"map_reload_interval", gopt_map_reload_interval},
191a53f50b9Schristos {"map_type", gopt_map_type},
192a53f50b9Schristos {"mount_type", gopt_mount_type},
193a53f50b9Schristos {"pid_file", gopt_pid_file},
194a53f50b9Schristos {"portmap_program", gopt_portmap_program},
195a53f50b9Schristos {"preferred_amq_port", gopt_preferred_amq_port},
196a53f50b9Schristos {"nfs_allow_any_interface", gopt_nfs_allow_any_interface},
197a53f50b9Schristos {"nfs_allow_insecure_port", gopt_nfs_allow_insecure_port},
198a53f50b9Schristos {"nfs_proto", gopt_nfs_proto},
199a53f50b9Schristos {"nfs_retransmit_counter", gopt_nfs_retransmit_counter},
200a53f50b9Schristos {"nfs_retransmit_counter_udp", gopt_nfs_retransmit_counter_udp},
201a53f50b9Schristos {"nfs_retransmit_counter_tcp", gopt_nfs_retransmit_counter_tcp},
202a53f50b9Schristos {"nfs_retransmit_counter_toplvl", gopt_nfs_retransmit_counter_toplvl},
203a53f50b9Schristos {"nfs_retry_interval", gopt_nfs_retry_interval},
204a53f50b9Schristos {"nfs_retry_interval_udp", gopt_nfs_retry_interval_udp},
205a53f50b9Schristos {"nfs_retry_interval_tcp", gopt_nfs_retry_interval_tcp},
206a53f50b9Schristos {"nfs_retry_interval_toplvl", gopt_nfs_retry_interval_toplvl},
207a53f50b9Schristos {"nfs_vers", gopt_nfs_vers},
208*8bae5d40Schristos {"nfs_vers_ping", gopt_nfs_vers_ping},
209a53f50b9Schristos {"nis_domain", gopt_nis_domain},
210a53f50b9Schristos {"normalize_hostnames", gopt_normalize_hostnames},
211a53f50b9Schristos {"normalize_slashes", gopt_normalize_slashes},
212a53f50b9Schristos {"os", gopt_os},
213a53f50b9Schristos {"osver", gopt_osver},
214a53f50b9Schristos {"plock", gopt_plock},
215a53f50b9Schristos {"print_pid", gopt_print_pid},
216a53f50b9Schristos {"print_version", gopt_print_version},
217a53f50b9Schristos {"restart_mounts", gopt_restart_mounts},
218a53f50b9Schristos {"search_path", gopt_search_path},
219a53f50b9Schristos {"selectors_on_default", gopt_selectors_in_defaults},
220a53f50b9Schristos {"selectors_in_defaults", gopt_selectors_in_defaults},
221a53f50b9Schristos {"show_statfs_entries", gopt_show_statfs_entries},
222a53f50b9Schristos {"sun_map_syntax", gopt_sun_map_syntax},
223a53f50b9Schristos {"truncate_log", gopt_truncate_log},
224a53f50b9Schristos {"unmount_on_exit", gopt_unmount_on_exit},
225a53f50b9Schristos {"use_tcpwrappers", gopt_use_tcpwrappers},
226a53f50b9Schristos {"vendor", gopt_vendor},
227a53f50b9Schristos {NULL, NULL}
228a53f50b9Schristos };
229a53f50b9Schristos
230a53f50b9Schristos
231a53f50b9Schristos /*
232a53f50b9Schristos * Initialize a map from [global] defaults.
233a53f50b9Schristos */
234a53f50b9Schristos static void
init_cf_map(cf_map_t * cfm)235a53f50b9Schristos init_cf_map(cf_map_t *cfm)
236a53f50b9Schristos {
237a53f50b9Schristos if (!cfm)
238a53f50b9Schristos return;
239a53f50b9Schristos
240a53f50b9Schristos /*
241a53f50b9Schristos * Initialize a regular map's flags and other variables from the
242a53f50b9Schristos * global ones, so that they are applied to all maps. Of course, each map
243a53f50b9Schristos * can then override the flags individually.
244a53f50b9Schristos *
245a53f50b9Schristos * NOTES:
246a53f50b9Schristos * (1): Will only work for maps that appear after [global].
247a53f50b9Schristos * (2): I'm assigning pointers directly from the global map.
248a53f50b9Schristos */
249a53f50b9Schristos
250a53f50b9Schristos /* initialize map_type from [global] */
251a53f50b9Schristos cfm->cfm_type = gopt.map_type;
252a53f50b9Schristos
253a53f50b9Schristos /* initialize map_defaults from [global] */
254a53f50b9Schristos cfm->cfm_defaults = gopt.map_defaults;
255a53f50b9Schristos
256a53f50b9Schristos /* initialize map_opts from [global] */
257a53f50b9Schristos cfm->cfm_opts = gopt.map_options;
258a53f50b9Schristos
259a53f50b9Schristos /* initialize search_path from [global] */
260a53f50b9Schristos cfm->cfm_search_path = gopt.search_path;
261a53f50b9Schristos
262a53f50b9Schristos /*
263a53f50b9Schristos * Initialize flags that are common both to [global] and a local map
264a53f50b9Schristos * (that is, they could be inherited from the global section).
265a53f50b9Schristos */
266a53f50b9Schristos cfm->cfm_flags = gopt.flags & (CFM_BROWSABLE_DIRS |
267a53f50b9Schristos CFM_BROWSABLE_DIRS_FULL |
268a53f50b9Schristos CFM_MOUNT_TYPE_AUTOFS |
269a53f50b9Schristos CFM_SELECTORS_IN_DEFAULTS |
270a53f50b9Schristos CFM_SUN_MAP_SYNTAX );
271a53f50b9Schristos }
272a53f50b9Schristos
273a53f50b9Schristos
274a53f50b9Schristos /*
275a53f50b9Schristos * Process configuration file options (called from YACC parser).
276a53f50b9Schristos * Return 0 if OK, 1 otherwise.
277a53f50b9Schristos */
278a53f50b9Schristos int
set_conf_kv(const char * section,const char * key,const char * val)279a53f50b9Schristos set_conf_kv(const char *section, const char *key, const char *val)
280a53f50b9Schristos {
281a53f50b9Schristos int ret;
282a53f50b9Schristos
283a53f50b9Schristos #ifdef DEBUG_CONF
284a53f50b9Schristos fprintf(stderr, "set_conf_kv: section=%s, key=%s, val=%s\n",
285a53f50b9Schristos section, key, val);
286a53f50b9Schristos #endif /* DEBUG_CONF */
287a53f50b9Schristos
288a53f50b9Schristos /*
289a53f50b9Schristos * If global section, process kv pairs one at a time.
290a53f50b9Schristos */
291a53f50b9Schristos if (STREQ(section, "global")) {
292a53f50b9Schristos /*
293a53f50b9Schristos * Check if a regular map was configured before "global",
294a53f50b9Schristos * and warn about it.
295a53f50b9Schristos */
296a53f50b9Schristos if (cur_map && cur_map->cfm_dir) {
297a53f50b9Schristos static short printed_this_error;
298a53f50b9Schristos if (!printed_this_error) {
299a53f50b9Schristos fprintf(stderr, "found regular map \"%s\" before global one.\n",
300a53f50b9Schristos cur_map->cfm_dir);
301a53f50b9Schristos printed_this_error = 1;
302a53f50b9Schristos }
303a53f50b9Schristos }
304a53f50b9Schristos
305a53f50b9Schristos /* process the global option first */
306a53f50b9Schristos ret = process_global_option(key, val);
307a53f50b9Schristos
308a53f50b9Schristos /* return status from the processing of the global option */
309a53f50b9Schristos return ret;
310a53f50b9Schristos }
311a53f50b9Schristos
312a53f50b9Schristos /*
313a53f50b9Schristos * Otherwise we found a non-global option: store it after some testing.
314a53f50b9Schristos */
315a53f50b9Schristos
316a53f50b9Schristos /* initialize (static) global list head and current map pointer */
317a53f50b9Schristos if (!head_map && !cur_map) {
318a53f50b9Schristos cur_map = CALLOC(cf_map_t);
319a53f50b9Schristos if (!cur_map) {
320a53f50b9Schristos perror("calloc");
321a53f50b9Schristos exit(1);
322a53f50b9Schristos }
323a53f50b9Schristos /* initialize first head map from global defaults */
324a53f50b9Schristos init_cf_map(cur_map);
325a53f50b9Schristos head_map = cur_map;
326a53f50b9Schristos }
327a53f50b9Schristos
328a53f50b9Schristos /* check if we found a new map, then allocate and initialize it */
329a53f50b9Schristos if (cur_map->cfm_dir && !STREQ(cur_map->cfm_dir, section)) {
330a53f50b9Schristos /* allocate new map struct */
331a53f50b9Schristos cf_map_t *tmp_map = CALLOC(cf_map_t);
332a53f50b9Schristos if (!tmp_map) {
333a53f50b9Schristos perror("calloc");
334a53f50b9Schristos exit(1);
335a53f50b9Schristos }
336a53f50b9Schristos /* initialize it from global defaults */
337a53f50b9Schristos init_cf_map(tmp_map);
338a53f50b9Schristos /* append it to end of linked list */
339a53f50b9Schristos cur_map->cfm_next = tmp_map;
340a53f50b9Schristos cur_map = tmp_map;
341a53f50b9Schristos }
342a53f50b9Schristos
343a53f50b9Schristos /* now process a single entry of a regular map */
344a53f50b9Schristos return process_regular_option(section, key, val, cur_map);
345a53f50b9Schristos }
346a53f50b9Schristos
347a53f50b9Schristos
348a53f50b9Schristos /*
349a53f50b9Schristos * Process global section of configuration file options.
350a53f50b9Schristos * Return 0 upon success, 1 otherwise.
351a53f50b9Schristos */
352a53f50b9Schristos static int
process_global_option(const char * key,const char * val)353a53f50b9Schristos process_global_option(const char *key, const char *val)
354a53f50b9Schristos {
355a53f50b9Schristos struct _func_map *gfp;
356a53f50b9Schristos
357a53f50b9Schristos /* ensure that val is valid */
358a53f50b9Schristos if (!val || val[0] == '\0')
359a53f50b9Schristos return 1;
360a53f50b9Schristos
361a53f50b9Schristos /*
362a53f50b9Schristos * search for global function.
363a53f50b9Schristos */
364a53f50b9Schristos for (gfp = glob_functable; gfp->name; gfp++)
365a53f50b9Schristos if (FSTREQ(gfp->name, key))
366a53f50b9Schristos return (gfp->func)(val);
367a53f50b9Schristos
368a53f50b9Schristos fprintf(stderr, "conf: unknown global key: \"%s\"\n", key);
369a53f50b9Schristos return 1; /* failed to match any command */
370a53f50b9Schristos }
371a53f50b9Schristos
372a53f50b9Schristos
373a53f50b9Schristos static int
gopt_arch(const char * val)374a53f50b9Schristos gopt_arch(const char *val)
375a53f50b9Schristos {
376*8bae5d40Schristos gopt.arch = xstrdup(val);
377a53f50b9Schristos return 0;
378a53f50b9Schristos }
379a53f50b9Schristos
380a53f50b9Schristos
381a53f50b9Schristos static int
gopt_auto_attrcache(const char * val)382a53f50b9Schristos gopt_auto_attrcache(const char *val)
383a53f50b9Schristos {
384a53f50b9Schristos gopt.auto_attrcache = atoi(val);
385a53f50b9Schristos if (gopt.auto_attrcache < 0) {
386a53f50b9Schristos fprintf(stderr, "conf: bad attrcache value: \"%s\"\n", val);
387a53f50b9Schristos return 1;
388a53f50b9Schristos }
389a53f50b9Schristos return 0;
390a53f50b9Schristos }
391a53f50b9Schristos
392a53f50b9Schristos
393a53f50b9Schristos static int
gopt_auto_dir(const char * val)394a53f50b9Schristos gopt_auto_dir(const char *val)
395a53f50b9Schristos {
396*8bae5d40Schristos gopt.auto_dir = xstrdup(val);
397a53f50b9Schristos return 0;
398a53f50b9Schristos }
399a53f50b9Schristos
400*8bae5d40Schristos static int
gopt_auto_nfs_version(const char * val)401*8bae5d40Schristos gopt_auto_nfs_version(const char *val)
402*8bae5d40Schristos {
403*8bae5d40Schristos if (strcmp(val, "2") == 0)
404*8bae5d40Schristos nfs_dispatcher = nfs_program_2;
405*8bae5d40Schristos else if (strcmp(val, "3") == 0)
406*8bae5d40Schristos nfs_dispatcher = nfs_program_3;
407*8bae5d40Schristos else {
408*8bae5d40Schristos fprintf(stderr, "conf: bad auto nfs version : \"%s\"\n", val);
409*8bae5d40Schristos return 1;
410*8bae5d40Schristos }
411*8bae5d40Schristos return 0;
412*8bae5d40Schristos }
413a53f50b9Schristos
414a53f50b9Schristos static int
gopt_autofs_use_lofs(const char * val)415a53f50b9Schristos gopt_autofs_use_lofs(const char *val)
416a53f50b9Schristos {
417a53f50b9Schristos if (STREQ(val, "yes")) {
418a53f50b9Schristos gopt.flags |= CFM_AUTOFS_USE_LOFS;
419a53f50b9Schristos return 0;
420a53f50b9Schristos } else if (STREQ(val, "no")) {
421a53f50b9Schristos gopt.flags &= ~CFM_AUTOFS_USE_LOFS;
422a53f50b9Schristos return 0;
423a53f50b9Schristos }
424a53f50b9Schristos
425a53f50b9Schristos fprintf(stderr, "conf: unknown value to autofs_use_lofs \"%s\"\n", val);
426a53f50b9Schristos return 1; /* unknown value */
427a53f50b9Schristos }
428a53f50b9Schristos
429a53f50b9Schristos
430a53f50b9Schristos static int
gopt_browsable_dirs(const char * val)431a53f50b9Schristos gopt_browsable_dirs(const char *val)
432a53f50b9Schristos {
433a53f50b9Schristos if (STREQ(val, "full")) {
434a53f50b9Schristos gopt.flags |= CFM_BROWSABLE_DIRS_FULL;
435a53f50b9Schristos return 0;
436a53f50b9Schristos } else if (STREQ(val, "yes")) {
437a53f50b9Schristos gopt.flags |= CFM_BROWSABLE_DIRS;
438a53f50b9Schristos return 0;
439a53f50b9Schristos } else if (STREQ(val, "no")) {
440a53f50b9Schristos gopt.flags &= ~CFM_BROWSABLE_DIRS;
441a53f50b9Schristos return 0;
442a53f50b9Schristos }
443a53f50b9Schristos
444a53f50b9Schristos fprintf(stderr, "conf: unknown value to browsable_dirs \"%s\"\n", val);
445a53f50b9Schristos return 1; /* unknown value */
446a53f50b9Schristos }
447a53f50b9Schristos
448a53f50b9Schristos
449a53f50b9Schristos static int
gopt_cache_duration(const char * val)450a53f50b9Schristos gopt_cache_duration(const char *val)
451a53f50b9Schristos {
452a53f50b9Schristos gopt.am_timeo = atoi(val);
453a53f50b9Schristos if (gopt.am_timeo <= 0)
454a53f50b9Schristos gopt.am_timeo = AM_TTL;
455a53f50b9Schristos return 0;
456a53f50b9Schristos }
457a53f50b9Schristos
458a53f50b9Schristos
459a53f50b9Schristos static int
gopt_cluster(const char * val)460a53f50b9Schristos gopt_cluster(const char *val)
461a53f50b9Schristos {
462*8bae5d40Schristos gopt.cluster = xstrdup(val);
463a53f50b9Schristos return 0;
464a53f50b9Schristos }
465a53f50b9Schristos
466a53f50b9Schristos
467a53f50b9Schristos static int
gopt_debug_mtab_file(const char * val)468a53f50b9Schristos gopt_debug_mtab_file(const char *val)
469a53f50b9Schristos {
470*8bae5d40Schristos gopt.debug_mtab_file = xstrdup(val);
471a53f50b9Schristos return 0;
472a53f50b9Schristos }
473a53f50b9Schristos
474a53f50b9Schristos
475a53f50b9Schristos static int
gopt_debug_options(const char * val)476a53f50b9Schristos gopt_debug_options(const char *val)
477a53f50b9Schristos {
478a53f50b9Schristos #ifdef DEBUG
479a53f50b9Schristos usage += debug_option((char *)val);
480a53f50b9Schristos return 0;
481a53f50b9Schristos #else /* not DEBUG */
482a53f50b9Schristos fprintf(stderr, "%s: not compiled with DEBUG option -- sorry.\n",
483a53f50b9Schristos am_get_progname());
484a53f50b9Schristos return 1;
485a53f50b9Schristos #endif /* not DEBUG */
486a53f50b9Schristos }
487a53f50b9Schristos
488a53f50b9Schristos
489a53f50b9Schristos static int
gopt_dismount_interval(const char * val)490a53f50b9Schristos gopt_dismount_interval(const char *val)
491a53f50b9Schristos {
492a53f50b9Schristos gopt.am_timeo_w = atoi(val);
493a53f50b9Schristos if (gopt.am_timeo_w <= 0)
494a53f50b9Schristos gopt.am_timeo_w = AM_TTL_W;
495a53f50b9Schristos return 0;
496a53f50b9Schristos }
497a53f50b9Schristos
498a53f50b9Schristos
499a53f50b9Schristos static int
gopt_domain_strip(const char * val)500a53f50b9Schristos gopt_domain_strip(const char *val)
501a53f50b9Schristos {
502a53f50b9Schristos if (STREQ(val, "yes")) {
503a53f50b9Schristos gopt.flags |= CFM_DOMAIN_STRIP;
504a53f50b9Schristos return 0;
505a53f50b9Schristos } else if (STREQ(val, "no")) {
506a53f50b9Schristos gopt.flags &= ~CFM_DOMAIN_STRIP;
507a53f50b9Schristos return 0;
508a53f50b9Schristos }
509a53f50b9Schristos
510a53f50b9Schristos fprintf(stderr, "conf: unknown value to domain_strip \"%s\"\n", val);
511a53f50b9Schristos return 1; /* unknown value */
512a53f50b9Schristos }
513a53f50b9Schristos
514a53f50b9Schristos
515a53f50b9Schristos static int
gopt_exec_map_timeout(const char * val)516a53f50b9Schristos gopt_exec_map_timeout(const char *val)
517a53f50b9Schristos {
518a53f50b9Schristos gopt.exec_map_timeout = atoi(val);
519a53f50b9Schristos if (gopt.exec_map_timeout <= 0)
520a53f50b9Schristos gopt.exec_map_timeout = AMFS_EXEC_MAP_TIMEOUT; /* default exec map timeout */
521a53f50b9Schristos return 0;
522a53f50b9Schristos }
523a53f50b9Schristos
524a53f50b9Schristos
525a53f50b9Schristos static int
gopt_forced_unmounts(const char * val)526a53f50b9Schristos gopt_forced_unmounts(const char *val)
527a53f50b9Schristos {
528a53f50b9Schristos if (STREQ(val, "yes")) {
529a53f50b9Schristos #if !defined(MNT2_GEN_OPT_DETACH) && !defined(MNT2_GEN_OPT_FORCE)
530a53f50b9Schristos fprintf(stderr, "conf: forced_unmounts unsupported on this system.\n");
531a53f50b9Schristos return 1;
532a53f50b9Schristos #else /* defined(MNT2_GEN_OPT_DETACH) || defined(MNT2_GEN_OPT_FORCE) */
533a53f50b9Schristos # ifdef __linux__
534a53f50b9Schristos /*
535a53f50b9Schristos * HACK ALERT: Linux has had MNT_FORCE since 2.2, but it hasn't gotten
536a53f50b9Schristos * stable until 2.4. And it had MNT_DETACH since 2.4, but it hasn't
537a53f50b9Schristos * gotten stable since 2.6. So alert users if they're trying to use a
538a53f50b9Schristos * feature that may not work well on their older kernel.
539a53f50b9Schristos */
540a53f50b9Schristos {
541a53f50b9Schristos struct utsname un;
542a53f50b9Schristos if (uname(&un) >= 0) {
543a53f50b9Schristos # ifdef MNT2_GEN_OPT_FORCE
544a53f50b9Schristos if (strcmp(un.release, "2.4.0") < 0)
545a53f50b9Schristos fprintf(stderr, "warning: forced-unmounts (MNT_FORCE) may not work well before 2.4.0\n");
546a53f50b9Schristos # endif /* MNT2_GEN_OPT_FORCE */
547a53f50b9Schristos # ifdef MNT2_GEN_OPT_DETACH
548a53f50b9Schristos if (strcmp(un.release, "2.6.0") < 0)
549a53f50b9Schristos fprintf(stderr, "warning: lazy-unmounts (MNT_DETACH) may not work well before 2.6.0\n");
550a53f50b9Schristos # endif /* MNT2_GEN_OPT_DETACH */
551a53f50b9Schristos }
552a53f50b9Schristos }
553a53f50b9Schristos # endif /* __linux__ */
554a53f50b9Schristos gopt.flags |= CFM_FORCED_UNMOUNTS;
555a53f50b9Schristos return 0;
556a53f50b9Schristos #endif /* defined(MNT2_GEN_OPT_DETACH) || defined(MNT2_GEN_OPT_FORCE) */
557a53f50b9Schristos } else if (STREQ(val, "no")) {
558a53f50b9Schristos gopt.flags &= ~CFM_FORCED_UNMOUNTS;
559a53f50b9Schristos return 0;
560a53f50b9Schristos }
561a53f50b9Schristos
562a53f50b9Schristos fprintf(stderr, "conf: unknown value to unmount_on_exit \"%s\"\n", val);
563a53f50b9Schristos return 1; /* unknown value */
564a53f50b9Schristos }
565a53f50b9Schristos
566a53f50b9Schristos
567a53f50b9Schristos static int
gopt_full_os(const char * val)568a53f50b9Schristos gopt_full_os(const char *val)
569a53f50b9Schristos {
570*8bae5d40Schristos gopt.op_sys_full = xstrdup(val);
571a53f50b9Schristos return 0;
572a53f50b9Schristos }
573a53f50b9Schristos
574a53f50b9Schristos
575a53f50b9Schristos static int
gopt_fully_qualified_hosts(const char * val)576a53f50b9Schristos gopt_fully_qualified_hosts(const char *val)
577a53f50b9Schristos {
578a53f50b9Schristos if (STREQ(val, "yes")) {
579a53f50b9Schristos gopt.flags |= CFM_FULLY_QUALIFIED_HOSTS;
580a53f50b9Schristos return 0;
581a53f50b9Schristos } else if (STREQ(val, "no")) {
582a53f50b9Schristos gopt.flags &= ~CFM_FULLY_QUALIFIED_HOSTS;
583a53f50b9Schristos return 0;
584a53f50b9Schristos }
585a53f50b9Schristos
586a53f50b9Schristos fprintf(stderr, "conf: unknown value to fully_qualified_hosts \"%s\"\n", val);
587a53f50b9Schristos return 1; /* unknown value */
588a53f50b9Schristos }
589a53f50b9Schristos
590a53f50b9Schristos
591a53f50b9Schristos static int
gopt_hesiod_base(const char * val)592a53f50b9Schristos gopt_hesiod_base(const char *val)
593a53f50b9Schristos {
594a53f50b9Schristos #ifdef HAVE_MAP_HESIOD
595*8bae5d40Schristos gopt.hesiod_base = xstrdup(val);
596a53f50b9Schristos return 0;
597a53f50b9Schristos #else /* not HAVE_MAP_HESIOD */
598a53f50b9Schristos fprintf(stderr, "conf: hesiod_base option ignored. No Hesiod support available.\n");
599a53f50b9Schristos return 1;
600a53f50b9Schristos #endif /* not HAVE_MAP_HESIOD */
601a53f50b9Schristos }
602a53f50b9Schristos
603a53f50b9Schristos
604a53f50b9Schristos static int
gopt_karch(const char * val)605a53f50b9Schristos gopt_karch(const char *val)
606a53f50b9Schristos {
607*8bae5d40Schristos gopt.karch = xstrdup(val);
608a53f50b9Schristos return 0;
609a53f50b9Schristos }
610a53f50b9Schristos
611a53f50b9Schristos
612a53f50b9Schristos static int
gopt_pid_file(const char * val)613a53f50b9Schristos gopt_pid_file(const char *val)
614a53f50b9Schristos {
615*8bae5d40Schristos gopt.pid_file = xstrdup(val);
616a53f50b9Schristos return 0;
617a53f50b9Schristos }
618a53f50b9Schristos
619a53f50b9Schristos
620a53f50b9Schristos static int
gopt_local_domain(const char * val)621a53f50b9Schristos gopt_local_domain(const char *val)
622a53f50b9Schristos {
623*8bae5d40Schristos gopt.sub_domain = xstrdup(val);
624a53f50b9Schristos return 0;
625a53f50b9Schristos }
626a53f50b9Schristos
627a53f50b9Schristos
628a53f50b9Schristos static int
gopt_localhost_address(const char * val)629a53f50b9Schristos gopt_localhost_address(const char *val)
630a53f50b9Schristos {
631*8bae5d40Schristos gopt.localhost_address = xstrdup(val);
632a53f50b9Schristos return 0;
633a53f50b9Schristos }
634a53f50b9Schristos
635a53f50b9Schristos
636a53f50b9Schristos static int
gopt_ldap_base(const char * val)637a53f50b9Schristos gopt_ldap_base(const char *val)
638a53f50b9Schristos {
639a53f50b9Schristos #ifdef HAVE_MAP_LDAP
640*8bae5d40Schristos gopt.ldap_base = xstrdup(val);
641a53f50b9Schristos return 0;
642a53f50b9Schristos #else /* not HAVE_MAP_LDAP */
643a53f50b9Schristos fprintf(stderr, "conf: ldap_base option ignored. No LDAP support available.\n");
644a53f50b9Schristos return 1;
645a53f50b9Schristos #endif /* not HAVE_MAP_LDAP */
646a53f50b9Schristos }
647a53f50b9Schristos
648a53f50b9Schristos
649a53f50b9Schristos static int
gopt_ldap_cache_seconds(const char * val)650a53f50b9Schristos gopt_ldap_cache_seconds(const char *val)
651a53f50b9Schristos {
652a53f50b9Schristos #ifdef HAVE_MAP_LDAP
653a53f50b9Schristos char *end;
654a53f50b9Schristos
655a53f50b9Schristos gopt.ldap_cache_seconds = strtol((char *)val, &end, 10);
656a53f50b9Schristos if (end == val) {
657a53f50b9Schristos fprintf(stderr, "conf: bad LDAP cache (seconds) option: %s\n",val);
658a53f50b9Schristos return 1;
659a53f50b9Schristos }
660a53f50b9Schristos return 0;
661a53f50b9Schristos #else /* not HAVE_MAP_LDAP */
662a53f50b9Schristos fprintf(stderr, "conf: ldap_cache_seconds option ignored. No LDAP support available.\n");
663a53f50b9Schristos return 1;
664a53f50b9Schristos #endif /* not HAVE_MAP_LDAP */
665a53f50b9Schristos }
666a53f50b9Schristos
667a53f50b9Schristos
668a53f50b9Schristos static int
gopt_ldap_cache_maxmem(const char * val)669a53f50b9Schristos gopt_ldap_cache_maxmem(const char *val)
670a53f50b9Schristos {
671a53f50b9Schristos #ifdef HAVE_MAP_LDAP
672a53f50b9Schristos char *end;
673a53f50b9Schristos
674a53f50b9Schristos gopt.ldap_cache_maxmem = strtol((char *)val, &end, 10);
675a53f50b9Schristos if (end == val) {
676a53f50b9Schristos fprintf(stderr, "conf: bad LDAP cache (maxmem) option: %s\n",val);
677a53f50b9Schristos return 1;
678a53f50b9Schristos }
679a53f50b9Schristos return 0;
680a53f50b9Schristos #else /* not HAVE_MAP_LDAP */
681a53f50b9Schristos fprintf(stderr, "conf: ldap_cache_maxmem option ignored. No LDAP support available.\n");
682a53f50b9Schristos return 1;
683a53f50b9Schristos #endif /* not HAVE_MAP_LDAP */
684a53f50b9Schristos }
685a53f50b9Schristos
686a53f50b9Schristos
687a53f50b9Schristos static int
gopt_ldap_hostports(const char * val)688a53f50b9Schristos gopt_ldap_hostports(const char *val)
689a53f50b9Schristos {
690a53f50b9Schristos #ifdef HAVE_MAP_LDAP
691*8bae5d40Schristos gopt.ldap_hostports = xstrdup(val);
692a53f50b9Schristos return 0;
693a53f50b9Schristos #else /* not HAVE_MAP_LDAP */
694a53f50b9Schristos fprintf(stderr, "conf: ldap_hostports option ignored. No LDAP support available.\n");
695a53f50b9Schristos return 1;
696a53f50b9Schristos #endif /* not HAVE_MAP_LDAP */
697a53f50b9Schristos
698a53f50b9Schristos }
699a53f50b9Schristos
700a53f50b9Schristos
701a53f50b9Schristos static int
gopt_ldap_proto_version(const char * val)702a53f50b9Schristos gopt_ldap_proto_version(const char *val)
703a53f50b9Schristos {
704a53f50b9Schristos #ifdef HAVE_MAP_LDAP
705a53f50b9Schristos char *end;
706a53f50b9Schristos
707a53f50b9Schristos gopt.ldap_proto_version = strtol((char *)val, &end, 10);
708a53f50b9Schristos if (end == val) {
709a53f50b9Schristos fprintf(stderr, "conf: bad ldap_proto_version option: %s\n",val);
710a53f50b9Schristos return 1;
711a53f50b9Schristos }
712a53f50b9Schristos
713a53f50b9Schristos if (gopt.ldap_proto_version < 0 || gopt.ldap_proto_version > LDAP_VERSION_MAX) {
714a53f50b9Schristos fprintf(stderr, "conf: bad ldap_proto_version option value: %s\n",val);
715a53f50b9Schristos return 1;
716a53f50b9Schristos }
717a53f50b9Schristos switch (gopt.ldap_proto_version) {
718a53f50b9Schristos /* XXX: what about LDAP_VERSION1? */
719a53f50b9Schristos case LDAP_VERSION2:
720a53f50b9Schristos #ifdef LDAP_VERSION3
721a53f50b9Schristos case LDAP_VERSION3:
722a53f50b9Schristos #endif /* LDAP_VERSION3 */
723a53f50b9Schristos #ifdef LDAP_VERSION4
724a53f50b9Schristos case LDAP_VERSION4:
725a53f50b9Schristos #endif /* LDAP_VERSION4 */
726a53f50b9Schristos break;
727a53f50b9Schristos default:
728a53f50b9Schristos fprintf(stderr, "conf: unsupported ldap_proto_version option value: %s\n",val);
729a53f50b9Schristos return 1;
730a53f50b9Schristos }
731a53f50b9Schristos return 0;
732a53f50b9Schristos #else /* not HAVE_MAP_LDAP */
733a53f50b9Schristos fprintf(stderr, "conf: ldap_proto_version option ignored. No LDAP support available.\n");
734a53f50b9Schristos return 1;
735a53f50b9Schristos #endif /* not HAVE_MAP_LDAP */
736a53f50b9Schristos }
737a53f50b9Schristos
738a53f50b9Schristos
739a53f50b9Schristos static int
gopt_log_file(const char * val)740a53f50b9Schristos gopt_log_file(const char *val)
741a53f50b9Schristos {
742*8bae5d40Schristos gopt.logfile = xstrdup(val);
743a53f50b9Schristos return 0;
744a53f50b9Schristos }
745a53f50b9Schristos
746a53f50b9Schristos
747a53f50b9Schristos static int
gopt_log_options(const char * val)748a53f50b9Schristos gopt_log_options(const char *val)
749a53f50b9Schristos {
750a53f50b9Schristos usage += switch_option((char *)val);
751a53f50b9Schristos return 0;
752a53f50b9Schristos }
753a53f50b9Schristos
754a53f50b9Schristos
755a53f50b9Schristos static int
gopt_map_defaults(const char * val)756a53f50b9Schristos gopt_map_defaults(const char *val)
757a53f50b9Schristos {
758*8bae5d40Schristos gopt.map_defaults = xstrdup(val);
759a53f50b9Schristos return 0;
760a53f50b9Schristos }
761a53f50b9Schristos
762a53f50b9Schristos
763a53f50b9Schristos static int
gopt_map_options(const char * val)764a53f50b9Schristos gopt_map_options(const char *val)
765a53f50b9Schristos {
766*8bae5d40Schristos gopt.map_options = xstrdup(val);
767a53f50b9Schristos return 0;
768a53f50b9Schristos }
769a53f50b9Schristos
770a53f50b9Schristos
771a53f50b9Schristos static int
gopt_map_reload_interval(const char * val)772a53f50b9Schristos gopt_map_reload_interval(const char *val)
773a53f50b9Schristos {
774a53f50b9Schristos gopt.map_reload_interval = atoi(val);
775a53f50b9Schristos if (gopt.map_reload_interval <= 0)
776a53f50b9Schristos gopt.map_reload_interval = ONE_HOUR;
777a53f50b9Schristos return 0;
778a53f50b9Schristos }
779a53f50b9Schristos
780a53f50b9Schristos
781a53f50b9Schristos static int
gopt_map_type(const char * val)782a53f50b9Schristos gopt_map_type(const char *val)
783a53f50b9Schristos {
784a53f50b9Schristos /* check if map type exist */
785a53f50b9Schristos if (!mapc_type_exists(val)) {
786a53f50b9Schristos fprintf(stderr, "conf: no such map type \"%s\"\n", val);
787a53f50b9Schristos return 1;
788a53f50b9Schristos }
789*8bae5d40Schristos gopt.map_type = xstrdup(val);
790a53f50b9Schristos return 0;
791a53f50b9Schristos }
792a53f50b9Schristos
793a53f50b9Schristos
794a53f50b9Schristos static int
gopt_mount_type(const char * val)795a53f50b9Schristos gopt_mount_type(const char *val)
796a53f50b9Schristos {
797a53f50b9Schristos if (STREQ(val, "autofs")) {
798a53f50b9Schristos #ifdef HAVE_FS_AUTOFS
799a53f50b9Schristos gopt.flags |= CFM_MOUNT_TYPE_AUTOFS;
800a53f50b9Schristos amd_use_autofs++;
801a53f50b9Schristos return 0;
802a53f50b9Schristos #else /* not HAVE_FS_AUTOFS */
803a53f50b9Schristos fprintf(stderr, "conf: no autofs support available\n");
804a53f50b9Schristos return 1;
805a53f50b9Schristos #endif /* not HAVE_FS_AUTOFS */
806a53f50b9Schristos } else if (STREQ(val, "nfs")) {
807a53f50b9Schristos gopt.flags &= ~CFM_MOUNT_TYPE_AUTOFS;
808a53f50b9Schristos return 0;
809a53f50b9Schristos }
810a53f50b9Schristos
811a53f50b9Schristos fprintf(stderr, "conf: unknown value to mount_type \"%s\"\n", val);
812a53f50b9Schristos return 1; /* unknown value */
813a53f50b9Schristos }
814a53f50b9Schristos
815a53f50b9Schristos
816a53f50b9Schristos static int
gopt_portmap_program(const char * val)817a53f50b9Schristos gopt_portmap_program(const char *val)
818a53f50b9Schristos {
819a53f50b9Schristos gopt.portmap_program = atol(val);
820a53f50b9Schristos /*
821a53f50b9Schristos * allow alternate program numbers to be no more than 10 offset from
822a53f50b9Schristos * official amd program number (300019).
823a53f50b9Schristos */
824a53f50b9Schristos if (gopt.portmap_program < AMQ_PROGRAM ||
825a53f50b9Schristos gopt.portmap_program > AMQ_PROGRAM + 10) {
826a53f50b9Schristos gopt.portmap_program = AMQ_PROGRAM;
827a53f50b9Schristos set_amd_program_number(gopt.portmap_program);
828a53f50b9Schristos fprintf(stderr, "conf: illegal amd program number \"%s\"\n", val);
829a53f50b9Schristos return 1;
830a53f50b9Schristos }
831a53f50b9Schristos
832a53f50b9Schristos set_amd_program_number(gopt.portmap_program);
833a53f50b9Schristos return 0; /* all is OK */
834a53f50b9Schristos }
835a53f50b9Schristos
836a53f50b9Schristos
837a53f50b9Schristos static int
gopt_preferred_amq_port(const char * val)838a53f50b9Schristos gopt_preferred_amq_port(const char *val)
839a53f50b9Schristos {
840a53f50b9Schristos gopt.preferred_amq_port = atoi(val);
841a53f50b9Schristos
842a53f50b9Schristos /*
843a53f50b9Schristos * No need to check value: preferred_amq_port is an unsigned short and 0
844a53f50b9Schristos * is a valid number, meaning "any port".
845a53f50b9Schristos */
846a53f50b9Schristos return 0; /* all is OK */
847a53f50b9Schristos }
848a53f50b9Schristos
849a53f50b9Schristos
850a53f50b9Schristos static int
gopt_nfs_allow_any_interface(const char * val)851a53f50b9Schristos gopt_nfs_allow_any_interface(const char *val)
852a53f50b9Schristos {
853a53f50b9Schristos if (STREQ(val, "yes")) {
854a53f50b9Schristos gopt.flags |= CFM_NFS_ANY_INTERFACE;
855a53f50b9Schristos return 0;
856a53f50b9Schristos } else if (STREQ(val, "no")) {
857a53f50b9Schristos gopt.flags &= ~CFM_NFS_ANY_INTERFACE;
858a53f50b9Schristos return 0;
859a53f50b9Schristos }
860a53f50b9Schristos
861a53f50b9Schristos fprintf(stderr, "conf: unknown value to nfs_allow_insecure_port \"%s\"\n", val);
862a53f50b9Schristos return 1; /* unknown value */
863a53f50b9Schristos }
864a53f50b9Schristos
865a53f50b9Schristos
866a53f50b9Schristos static int
gopt_nfs_allow_insecure_port(const char * val)867a53f50b9Schristos gopt_nfs_allow_insecure_port(const char *val)
868a53f50b9Schristos {
869a53f50b9Schristos if (STREQ(val, "yes")) {
870a53f50b9Schristos gopt.flags |= CFM_NFS_INSECURE_PORT;
871a53f50b9Schristos return 0;
872a53f50b9Schristos } else if (STREQ(val, "no")) {
873a53f50b9Schristos gopt.flags &= ~CFM_NFS_INSECURE_PORT;
874a53f50b9Schristos return 0;
875a53f50b9Schristos }
876a53f50b9Schristos
877a53f50b9Schristos fprintf(stderr, "conf: unknown value to nfs_allow_insecure_port \"%s\"\n", val);
878a53f50b9Schristos return 1; /* unknown value */
879a53f50b9Schristos }
880a53f50b9Schristos
881a53f50b9Schristos
882a53f50b9Schristos static int
gopt_nfs_proto(const char * val)883a53f50b9Schristos gopt_nfs_proto(const char *val)
884a53f50b9Schristos {
885a53f50b9Schristos if (STREQ(val, "udp") || STREQ(val, "tcp")) {
886*8bae5d40Schristos gopt.nfs_proto = xstrdup(val);
887a53f50b9Schristos return 0;
888a53f50b9Schristos }
889a53f50b9Schristos fprintf(stderr, "conf: illegal nfs_proto \"%s\"\n", val);
890a53f50b9Schristos return 1;
891a53f50b9Schristos }
892a53f50b9Schristos
893a53f50b9Schristos
894a53f50b9Schristos static int
gopt_nfs_retransmit_counter(const char * val)895a53f50b9Schristos gopt_nfs_retransmit_counter(const char *val)
896a53f50b9Schristos {
897a53f50b9Schristos int i;
898a53f50b9Schristos
899a53f50b9Schristos for (i=0; i<AMU_TYPE_MAX; ++i)
900a53f50b9Schristos gopt.amfs_auto_retrans[i] = atoi(val);
901a53f50b9Schristos return 0;
902a53f50b9Schristos }
903a53f50b9Schristos
904a53f50b9Schristos
905a53f50b9Schristos static int
gopt_nfs_retransmit_counter_udp(const char * val)906a53f50b9Schristos gopt_nfs_retransmit_counter_udp(const char *val)
907a53f50b9Schristos {
908a53f50b9Schristos gopt.amfs_auto_retrans[AMU_TYPE_UDP] = atoi(val);
909a53f50b9Schristos return 0;
910a53f50b9Schristos }
911a53f50b9Schristos
912a53f50b9Schristos
913a53f50b9Schristos static int
gopt_nfs_retransmit_counter_tcp(const char * val)914a53f50b9Schristos gopt_nfs_retransmit_counter_tcp(const char *val)
915a53f50b9Schristos {
916a53f50b9Schristos gopt.amfs_auto_retrans[AMU_TYPE_TCP] = atoi(val);
917a53f50b9Schristos return 0;
918a53f50b9Schristos }
919a53f50b9Schristos
920a53f50b9Schristos
921a53f50b9Schristos static int
gopt_nfs_retransmit_counter_toplvl(const char * val)922a53f50b9Schristos gopt_nfs_retransmit_counter_toplvl(const char *val)
923a53f50b9Schristos {
924a53f50b9Schristos gopt.amfs_auto_retrans[AMU_TYPE_TOPLVL] = atoi(val);
925a53f50b9Schristos return 0;
926a53f50b9Schristos }
927a53f50b9Schristos
928a53f50b9Schristos
929a53f50b9Schristos static int
gopt_nfs_retry_interval(const char * val)930a53f50b9Schristos gopt_nfs_retry_interval(const char *val)
931a53f50b9Schristos {
932a53f50b9Schristos int i;
933a53f50b9Schristos
934a53f50b9Schristos for (i=0; i<AMU_TYPE_MAX; ++i)
935a53f50b9Schristos gopt.amfs_auto_timeo[i] = atoi(val);
936a53f50b9Schristos return 0;
937a53f50b9Schristos }
938a53f50b9Schristos
939a53f50b9Schristos
940a53f50b9Schristos static int
gopt_nfs_retry_interval_udp(const char * val)941a53f50b9Schristos gopt_nfs_retry_interval_udp(const char *val)
942a53f50b9Schristos {
943a53f50b9Schristos gopt.amfs_auto_timeo[AMU_TYPE_UDP] = atoi(val);
944a53f50b9Schristos return 0;
945a53f50b9Schristos }
946a53f50b9Schristos
947a53f50b9Schristos
948a53f50b9Schristos static int
gopt_nfs_retry_interval_tcp(const char * val)949a53f50b9Schristos gopt_nfs_retry_interval_tcp(const char *val)
950a53f50b9Schristos {
951a53f50b9Schristos gopt.amfs_auto_timeo[AMU_TYPE_TCP] = atoi(val);
952a53f50b9Schristos return 0;
953a53f50b9Schristos }
954a53f50b9Schristos
955a53f50b9Schristos
956a53f50b9Schristos static int
gopt_nfs_retry_interval_toplvl(const char * val)957a53f50b9Schristos gopt_nfs_retry_interval_toplvl(const char *val)
958a53f50b9Schristos {
959a53f50b9Schristos gopt.amfs_auto_timeo[AMU_TYPE_TOPLVL] = atoi(val);
960a53f50b9Schristos return 0;
961a53f50b9Schristos }
962a53f50b9Schristos
963a53f50b9Schristos
964a53f50b9Schristos static int
gopt_nfs_vers(const char * val)965a53f50b9Schristos gopt_nfs_vers(const char *val)
966a53f50b9Schristos {
967a53f50b9Schristos int i = atoi(val);
968a53f50b9Schristos
969*8bae5d40Schristos if (i == 2 || i == 3 || i == 4) {
970a53f50b9Schristos gopt.nfs_vers = i;
971a53f50b9Schristos return 0;
972a53f50b9Schristos }
973a53f50b9Schristos fprintf(stderr, "conf: illegal nfs_vers \"%s\"\n", val);
974a53f50b9Schristos return 1;
975a53f50b9Schristos }
976a53f50b9Schristos
977a53f50b9Schristos
978a53f50b9Schristos static int
gopt_nfs_vers_ping(const char * val)979*8bae5d40Schristos gopt_nfs_vers_ping(const char *val)
980*8bae5d40Schristos {
981*8bae5d40Schristos int i = atoi(val);
982*8bae5d40Schristos
983*8bae5d40Schristos if (i == 2 || i == 3 || i == 4) {
984*8bae5d40Schristos gopt.nfs_vers_ping = i;
985*8bae5d40Schristos return 0;
986*8bae5d40Schristos }
987*8bae5d40Schristos fprintf(stderr, "conf: illegal nfs_vers_ping \"%s\"\n", val);
988*8bae5d40Schristos return 1;
989*8bae5d40Schristos }
990*8bae5d40Schristos
991*8bae5d40Schristos static int
gopt_nis_domain(const char * val)992a53f50b9Schristos gopt_nis_domain(const char *val)
993a53f50b9Schristos {
994a53f50b9Schristos #ifdef HAVE_MAP_NIS
995*8bae5d40Schristos gopt.nis_domain = xstrdup(val);
996a53f50b9Schristos return 0;
997a53f50b9Schristos #else /* not HAVE_MAP_NIS */
998a53f50b9Schristos fprintf(stderr, "conf: nis_domain option ignored. No NIS support available.\n");
999a53f50b9Schristos return 1;
1000a53f50b9Schristos #endif /* not HAVE_MAP_NIS */
1001a53f50b9Schristos }
1002a53f50b9Schristos
1003a53f50b9Schristos
1004a53f50b9Schristos static int
gopt_normalize_hostnames(const char * val)1005a53f50b9Schristos gopt_normalize_hostnames(const char *val)
1006a53f50b9Schristos {
1007a53f50b9Schristos if (STREQ(val, "yes")) {
1008a53f50b9Schristos gopt.flags |= CFM_NORMALIZE_HOSTNAMES;
1009a53f50b9Schristos return 0;
1010a53f50b9Schristos } else if (STREQ(val, "no")) {
1011a53f50b9Schristos gopt.flags &= ~CFM_NORMALIZE_HOSTNAMES;
1012a53f50b9Schristos return 0;
1013a53f50b9Schristos }
1014a53f50b9Schristos
1015a53f50b9Schristos fprintf(stderr, "conf: unknown value to normalize_hostnames \"%s\"\n", val);
1016a53f50b9Schristos return 1; /* unknown value */
1017a53f50b9Schristos }
1018a53f50b9Schristos
1019a53f50b9Schristos
1020a53f50b9Schristos static int
gopt_normalize_slashes(const char * val)1021a53f50b9Schristos gopt_normalize_slashes(const char *val)
1022a53f50b9Schristos {
1023a53f50b9Schristos if (STREQ(val, "yes")) {
1024a53f50b9Schristos gopt.flags |= CFM_NORMALIZE_SLASHES;
1025a53f50b9Schristos return 0;
1026a53f50b9Schristos } else if (STREQ(val, "no")) {
1027a53f50b9Schristos gopt.flags &= ~CFM_NORMALIZE_SLASHES;
1028a53f50b9Schristos return 0;
1029a53f50b9Schristos }
1030a53f50b9Schristos
1031a53f50b9Schristos fprintf(stderr, "conf: unknown value to normalize_slashes \"%s\"\n", val);
1032a53f50b9Schristos return 1; /* unknown value */
1033a53f50b9Schristos }
1034a53f50b9Schristos
1035a53f50b9Schristos
1036a53f50b9Schristos static int
gopt_os(const char * val)1037a53f50b9Schristos gopt_os(const char *val)
1038a53f50b9Schristos {
1039*8bae5d40Schristos gopt.op_sys = xstrdup(val);
1040a53f50b9Schristos return 0;
1041a53f50b9Schristos }
1042a53f50b9Schristos
1043a53f50b9Schristos
1044a53f50b9Schristos static int
gopt_osver(const char * val)1045a53f50b9Schristos gopt_osver(const char *val)
1046a53f50b9Schristos {
1047*8bae5d40Schristos gopt.op_sys_ver = xstrdup(val);
1048a53f50b9Schristos return 0;
1049a53f50b9Schristos }
1050a53f50b9Schristos
1051a53f50b9Schristos
1052a53f50b9Schristos static int
gopt_plock(const char * val)1053a53f50b9Schristos gopt_plock(const char *val)
1054a53f50b9Schristos {
1055a53f50b9Schristos if (STREQ(val, "yes")) {
1056a53f50b9Schristos gopt.flags |= CFM_PROCESS_LOCK;
1057a53f50b9Schristos return 0;
1058a53f50b9Schristos } else if (STREQ(val, "no")) {
1059a53f50b9Schristos gopt.flags &= ~CFM_PROCESS_LOCK;
1060a53f50b9Schristos return 0;
1061a53f50b9Schristos }
1062a53f50b9Schristos
1063a53f50b9Schristos fprintf(stderr, "conf: unknown value to plock \"%s\"\n", val);
1064a53f50b9Schristos return 1; /* unknown value */
1065a53f50b9Schristos }
1066a53f50b9Schristos
1067a53f50b9Schristos
1068a53f50b9Schristos static int
gopt_print_pid(const char * val)1069a53f50b9Schristos gopt_print_pid(const char *val)
1070a53f50b9Schristos {
1071a53f50b9Schristos if (STREQ(val, "yes")) {
1072a53f50b9Schristos gopt.flags |= CFM_PRINT_PID;
1073a53f50b9Schristos return 0;
1074a53f50b9Schristos } else if (STREQ(val, "no")) {
1075a53f50b9Schristos gopt.flags &= ~CFM_PRINT_PID;
1076a53f50b9Schristos return 0;
1077a53f50b9Schristos }
1078a53f50b9Schristos
1079a53f50b9Schristos fprintf(stderr, "conf: unknown value to print_pid \"%s\"\n", val);
1080a53f50b9Schristos return 1; /* unknown value */
1081a53f50b9Schristos }
1082a53f50b9Schristos
1083a53f50b9Schristos
1084a53f50b9Schristos static int
gopt_print_version(const char * val)1085a53f50b9Schristos gopt_print_version(const char *val)
1086a53f50b9Schristos {
1087a53f50b9Schristos if (STREQ(val, "yes")) {
1088a53f50b9Schristos char *vers = get_version_string();
1089a53f50b9Schristos fputs(vers, stderr);
1090a53f50b9Schristos XFREE(vers);
1091a53f50b9Schristos return 0;
1092a53f50b9Schristos } else if (STREQ(val, "no")) {
1093a53f50b9Schristos return 0;
1094a53f50b9Schristos }
1095a53f50b9Schristos
1096a53f50b9Schristos fprintf(stderr, "conf: unknown value to print_version \"%s\"\n", val);
1097a53f50b9Schristos return 1; /* unknown value */
1098a53f50b9Schristos }
1099a53f50b9Schristos
1100a53f50b9Schristos
1101a53f50b9Schristos static int
gopt_restart_mounts(const char * val)1102a53f50b9Schristos gopt_restart_mounts(const char *val)
1103a53f50b9Schristos {
1104a53f50b9Schristos if (STREQ(val, "yes")) {
1105a53f50b9Schristos gopt.flags |= CFM_RESTART_EXISTING_MOUNTS;
1106a53f50b9Schristos return 0;
1107a53f50b9Schristos } else if (STREQ(val, "no")) {
1108a53f50b9Schristos gopt.flags &= ~CFM_RESTART_EXISTING_MOUNTS;
1109a53f50b9Schristos return 0;
1110a53f50b9Schristos }
1111a53f50b9Schristos
1112a53f50b9Schristos fprintf(stderr, "conf: unknown value to restart_mounts \"%s\"\n", val);
1113a53f50b9Schristos return 1; /* unknown value */
1114a53f50b9Schristos }
1115a53f50b9Schristos
1116a53f50b9Schristos
1117a53f50b9Schristos static int
gopt_search_path(const char * val)1118a53f50b9Schristos gopt_search_path(const char *val)
1119a53f50b9Schristos {
1120*8bae5d40Schristos gopt.search_path = xstrdup(val);
1121a53f50b9Schristos return 0;
1122a53f50b9Schristos }
1123a53f50b9Schristos
1124a53f50b9Schristos
1125a53f50b9Schristos static int
gopt_selectors_in_defaults(const char * val)1126a53f50b9Schristos gopt_selectors_in_defaults(const char *val)
1127a53f50b9Schristos {
1128a53f50b9Schristos if (STREQ(val, "yes")) {
1129a53f50b9Schristos gopt.flags |= CFM_SELECTORS_IN_DEFAULTS;
1130a53f50b9Schristos return 0;
1131a53f50b9Schristos } else if (STREQ(val, "no")) {
1132a53f50b9Schristos gopt.flags &= ~CFM_SELECTORS_IN_DEFAULTS;
1133a53f50b9Schristos return 0;
1134a53f50b9Schristos }
1135a53f50b9Schristos
1136a53f50b9Schristos fprintf(stderr, "conf: unknown value to enable_default_selectors \"%s\"\n", val);
1137a53f50b9Schristos return 1; /* unknown value */
1138a53f50b9Schristos }
1139a53f50b9Schristos
1140a53f50b9Schristos
1141a53f50b9Schristos static int
gopt_show_statfs_entries(const char * val)1142a53f50b9Schristos gopt_show_statfs_entries(const char *val)
1143a53f50b9Schristos {
1144a53f50b9Schristos if (STREQ(val, "yes")) {
1145a53f50b9Schristos gopt.flags |= CFM_SHOW_STATFS_ENTRIES;
1146a53f50b9Schristos return 0;
1147a53f50b9Schristos } else if (STREQ(val, "no")) {
1148a53f50b9Schristos gopt.flags &= ~CFM_SHOW_STATFS_ENTRIES;
1149a53f50b9Schristos return 0;
1150a53f50b9Schristos }
1151a53f50b9Schristos
1152a53f50b9Schristos fprintf(stderr, "conf: unknown value to show_statfs_entries \"%s\"\n", val);
1153a53f50b9Schristos return 1; /* unknown value */
1154a53f50b9Schristos }
1155a53f50b9Schristos
1156a53f50b9Schristos
1157a53f50b9Schristos static int
gopt_sun_map_syntax(const char * val)1158a53f50b9Schristos gopt_sun_map_syntax(const char *val)
1159a53f50b9Schristos {
1160a53f50b9Schristos if (STREQ(val, "yes")) {
1161a53f50b9Schristos gopt.flags |= CFM_SUN_MAP_SYNTAX;
1162a53f50b9Schristos return 0;
1163a53f50b9Schristos } else if (STREQ(val, "no")) {
1164a53f50b9Schristos gopt.flags &= ~CFM_SUN_MAP_SYNTAX;
1165a53f50b9Schristos return 0;
1166a53f50b9Schristos }
1167a53f50b9Schristos
1168a53f50b9Schristos fprintf(stderr, "conf: unknown value to sun_map_syntax \"%s\"\n", val);
1169a53f50b9Schristos return 1; /* unknown value */
1170a53f50b9Schristos }
1171a53f50b9Schristos
1172a53f50b9Schristos
1173a53f50b9Schristos static int
gopt_truncate_log(const char * val)1174a53f50b9Schristos gopt_truncate_log(const char *val)
1175a53f50b9Schristos {
1176a53f50b9Schristos if (STREQ(val, "yes")) {
1177a53f50b9Schristos gopt.flags |= CFM_TRUNCATE_LOG;
1178a53f50b9Schristos return 0;
1179a53f50b9Schristos } else if (STREQ(val, "no")) {
1180a53f50b9Schristos gopt.flags &= ~CFM_TRUNCATE_LOG;
1181a53f50b9Schristos return 0;
1182a53f50b9Schristos }
1183a53f50b9Schristos
1184a53f50b9Schristos fprintf(stderr, "conf: unknown value to truncate_log \"%s\"\n", val);
1185a53f50b9Schristos return 1; /* unknown value */
1186a53f50b9Schristos }
1187a53f50b9Schristos
1188a53f50b9Schristos
1189a53f50b9Schristos static int
gopt_unmount_on_exit(const char * val)1190a53f50b9Schristos gopt_unmount_on_exit(const char *val)
1191a53f50b9Schristos {
1192a53f50b9Schristos if (STREQ(val, "yes")) {
1193a53f50b9Schristos gopt.flags |= CFM_UNMOUNT_ON_EXIT;
1194a53f50b9Schristos return 0;
1195a53f50b9Schristos } else if (STREQ(val, "no")) {
1196a53f50b9Schristos gopt.flags &= ~CFM_UNMOUNT_ON_EXIT;
1197a53f50b9Schristos return 0;
1198a53f50b9Schristos }
1199a53f50b9Schristos
1200a53f50b9Schristos fprintf(stderr, "conf: unknown value to unmount_on_exit \"%s\"\n", val);
1201a53f50b9Schristos return 1; /* unknown value */
1202a53f50b9Schristos }
1203a53f50b9Schristos
1204a53f50b9Schristos
1205a53f50b9Schristos static int
gopt_use_tcpwrappers(const char * val)1206a53f50b9Schristos gopt_use_tcpwrappers(const char *val)
1207a53f50b9Schristos {
1208a53f50b9Schristos #if defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP)
1209a53f50b9Schristos if (STREQ(val, "yes")) {
1210a53f50b9Schristos gopt.flags |= CFM_USE_TCPWRAPPERS;
1211a53f50b9Schristos return 0;
1212a53f50b9Schristos } else if (STREQ(val, "no")) {
1213a53f50b9Schristos gopt.flags &= ~CFM_USE_TCPWRAPPERS;
1214a53f50b9Schristos return 0;
1215a53f50b9Schristos }
1216a53f50b9Schristos #else /* not defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP) */
1217a53f50b9Schristos fprintf(stderr, "conf: no tcpd/libwrap support available\n");
1218a53f50b9Schristos return 1;
1219a53f50b9Schristos #endif /* not defined(HAVE_TCPD_H) && defined(HAVE_LIBWRAP) */
1220a53f50b9Schristos
1221a53f50b9Schristos fprintf(stderr, "conf: unknown value to use_tcpwrappers \"%s\"\n", val);
1222a53f50b9Schristos return 1; /* unknown value */
1223a53f50b9Schristos }
1224a53f50b9Schristos
1225a53f50b9Schristos
1226a53f50b9Schristos static int
gopt_vendor(const char * val)1227a53f50b9Schristos gopt_vendor(const char *val)
1228a53f50b9Schristos {
1229*8bae5d40Schristos gopt.op_sys_vendor = xstrdup(val);
1230a53f50b9Schristos return 0;
1231a53f50b9Schristos }
1232a53f50b9Schristos
1233a53f50b9Schristos
1234a53f50b9Schristos /*
1235a53f50b9Schristos * Collect one entry for a regular map
1236a53f50b9Schristos */
1237a53f50b9Schristos static int
process_regular_option(const char * section,const char * key,const char * val,cf_map_t * cfm)1238a53f50b9Schristos process_regular_option(const char *section, const char *key, const char *val, cf_map_t *cfm)
1239a53f50b9Schristos {
1240a53f50b9Schristos /* ensure that val is valid */
1241a53f50b9Schristos if (!section || section[0] == '\0' ||
1242a53f50b9Schristos !key || key[0] == '\0' ||
1243a53f50b9Schristos !val || val[0] == '\0' ||
1244a53f50b9Schristos !cfm) {
1245a53f50b9Schristos fprintf(stderr, "conf: process_regular_option: null entries\n");
1246a53f50b9Schristos return 1;
1247a53f50b9Schristos }
1248a53f50b9Schristos
1249a53f50b9Schristos /* check if initializing a new map */
1250a53f50b9Schristos if (!cfm->cfm_dir)
1251*8bae5d40Schristos cfm->cfm_dir = xstrdup(section);
1252a53f50b9Schristos
1253a53f50b9Schristos /* check for each possible field */
1254a53f50b9Schristos if (STREQ(key, "browsable_dirs"))
1255a53f50b9Schristos return ropt_browsable_dirs(val, cfm);
1256a53f50b9Schristos
1257a53f50b9Schristos if (STREQ(key, "map_name"))
1258a53f50b9Schristos return ropt_map_name(val, cfm);
1259a53f50b9Schristos
1260a53f50b9Schristos if (STREQ(key, "map_defaults"))
1261a53f50b9Schristos return ropt_map_defaults(val, cfm);
1262a53f50b9Schristos
1263a53f50b9Schristos if (STREQ(key, "map_options"))
1264a53f50b9Schristos return ropt_map_options(val, cfm);
1265a53f50b9Schristos
1266a53f50b9Schristos if (STREQ(key, "map_type"))
1267a53f50b9Schristos return ropt_map_type(val, cfm);
1268a53f50b9Schristos
1269a53f50b9Schristos if (STREQ(key, "mount_type"))
1270a53f50b9Schristos return ropt_mount_type(val, cfm);
1271a53f50b9Schristos
1272a53f50b9Schristos if (STREQ(key, "search_path"))
1273a53f50b9Schristos return ropt_search_path(val, cfm);
1274a53f50b9Schristos
1275a53f50b9Schristos if (STREQ(key, "sun_map_syntax"))
1276a53f50b9Schristos return ropt_sun_map_syntax(val, cfm);
1277a53f50b9Schristos
1278a53f50b9Schristos if (STREQ(key, "tag"))
1279a53f50b9Schristos return ropt_tag(val, cfm);
1280a53f50b9Schristos
1281a53f50b9Schristos fprintf(stderr, "conf: unknown regular key \"%s\" for section \"%s\"\n",
1282a53f50b9Schristos key, section);
1283a53f50b9Schristos return 1; /* failed to match any command */
1284a53f50b9Schristos }
1285a53f50b9Schristos
1286a53f50b9Schristos
1287a53f50b9Schristos static int
ropt_browsable_dirs(const char * val,cf_map_t * cfm)1288a53f50b9Schristos ropt_browsable_dirs(const char *val, cf_map_t *cfm)
1289a53f50b9Schristos {
1290a53f50b9Schristos if (STREQ(val, "full")) {
1291a53f50b9Schristos cfm->cfm_flags |= CFM_BROWSABLE_DIRS_FULL;
1292a53f50b9Schristos return 0;
1293a53f50b9Schristos } else if (STREQ(val, "yes")) {
1294a53f50b9Schristos cfm->cfm_flags |= CFM_BROWSABLE_DIRS;
1295a53f50b9Schristos return 0;
1296a53f50b9Schristos } else if (STREQ(val, "no")) {
1297a53f50b9Schristos cfm->cfm_flags &= ~CFM_BROWSABLE_DIRS;
1298a53f50b9Schristos return 0;
1299a53f50b9Schristos }
1300a53f50b9Schristos
1301a53f50b9Schristos fprintf(stderr, "conf: unknown value to browsable_dirs \"%s\"\n", val);
1302a53f50b9Schristos return 1; /* unknown value */
1303a53f50b9Schristos }
1304a53f50b9Schristos
1305a53f50b9Schristos
1306a53f50b9Schristos static int
ropt_map_name(const char * val,cf_map_t * cfm)1307a53f50b9Schristos ropt_map_name(const char *val, cf_map_t *cfm)
1308a53f50b9Schristos {
1309*8bae5d40Schristos cfm->cfm_name = xstrdup(val);
1310a53f50b9Schristos return 0;
1311a53f50b9Schristos }
1312a53f50b9Schristos
1313a53f50b9Schristos
1314a53f50b9Schristos static int
ropt_map_defaults(const char * val,cf_map_t * cfm)1315a53f50b9Schristos ropt_map_defaults(const char *val, cf_map_t *cfm)
1316a53f50b9Schristos {
1317*8bae5d40Schristos cfm->cfm_defaults = xstrdup(val);
1318a53f50b9Schristos return 0;
1319a53f50b9Schristos }
1320a53f50b9Schristos
1321a53f50b9Schristos
1322a53f50b9Schristos static int
ropt_map_options(const char * val,cf_map_t * cfm)1323a53f50b9Schristos ropt_map_options(const char *val, cf_map_t *cfm)
1324a53f50b9Schristos {
1325*8bae5d40Schristos cfm->cfm_opts = xstrdup(val);
1326a53f50b9Schristos return 0;
1327a53f50b9Schristos }
1328a53f50b9Schristos
1329a53f50b9Schristos
1330a53f50b9Schristos static int
ropt_map_type(const char * val,cf_map_t * cfm)1331a53f50b9Schristos ropt_map_type(const char *val, cf_map_t *cfm)
1332a53f50b9Schristos {
1333a53f50b9Schristos /* check if map type exist */
1334a53f50b9Schristos if (!mapc_type_exists(val)) {
1335a53f50b9Schristos fprintf(stderr, "conf: no such map type \"%s\"\n", val);
1336a53f50b9Schristos return 1;
1337a53f50b9Schristos }
1338*8bae5d40Schristos cfm->cfm_type = xstrdup(val);
1339a53f50b9Schristos return 0;
1340a53f50b9Schristos }
1341a53f50b9Schristos
1342a53f50b9Schristos
1343a53f50b9Schristos static int
ropt_mount_type(const char * val,cf_map_t * cfm)1344a53f50b9Schristos ropt_mount_type(const char *val, cf_map_t *cfm)
1345a53f50b9Schristos {
1346a53f50b9Schristos if (STREQ(val, "autofs")) {
1347a53f50b9Schristos #ifdef HAVE_FS_AUTOFS
1348a53f50b9Schristos cfm->cfm_flags |= CFM_MOUNT_TYPE_AUTOFS;
1349a53f50b9Schristos amd_use_autofs++;
1350a53f50b9Schristos return 0;
1351a53f50b9Schristos #else /* not HAVE_FS_AUTOFS */
1352a53f50b9Schristos fprintf(stderr, "conf: no autofs support available\n");
1353a53f50b9Schristos return 1;
1354a53f50b9Schristos #endif /* not HAVE_FS_AUTOFS */
1355a53f50b9Schristos } else if (STREQ(val, "nfs")) {
1356a53f50b9Schristos cfm->cfm_flags &= ~CFM_MOUNT_TYPE_AUTOFS;
1357a53f50b9Schristos return 0;
1358a53f50b9Schristos }
1359a53f50b9Schristos
1360a53f50b9Schristos fprintf(stderr, "conf: unknown value to mount_type \"%s\"\n", val);
1361a53f50b9Schristos return 1; /* unknown value */
1362a53f50b9Schristos }
1363a53f50b9Schristos
1364a53f50b9Schristos
1365a53f50b9Schristos static int
ropt_search_path(const char * val,cf_map_t * cfm)1366a53f50b9Schristos ropt_search_path(const char *val, cf_map_t *cfm)
1367a53f50b9Schristos {
1368*8bae5d40Schristos cfm->cfm_search_path = xstrdup(val);
1369a53f50b9Schristos return 0;
1370a53f50b9Schristos }
1371a53f50b9Schristos
1372a53f50b9Schristos
1373a53f50b9Schristos static int
ropt_sun_map_syntax(const char * val,cf_map_t * cfm)1374a53f50b9Schristos ropt_sun_map_syntax(const char *val, cf_map_t *cfm)
1375a53f50b9Schristos {
1376a53f50b9Schristos if (STREQ(val, "yes")) {
1377a53f50b9Schristos cfm->cfm_flags |= CFM_SUN_MAP_SYNTAX;
1378a53f50b9Schristos return 0;
1379a53f50b9Schristos
1380a53f50b9Schristos } else if (STREQ(val, "no")) {
1381a53f50b9Schristos cfm->cfm_flags &= ~CFM_SUN_MAP_SYNTAX;
1382a53f50b9Schristos return 0;
1383a53f50b9Schristos }
1384a53f50b9Schristos
1385a53f50b9Schristos fprintf(stderr, "conf: unknown value to sun_map_syntax \"%s\"\n", val);
1386a53f50b9Schristos return 1; /* unknown value */
1387a53f50b9Schristos }
1388a53f50b9Schristos
1389a53f50b9Schristos
1390a53f50b9Schristos static int
ropt_tag(const char * val,cf_map_t * cfm)1391a53f50b9Schristos ropt_tag(const char *val, cf_map_t *cfm)
1392a53f50b9Schristos {
1393*8bae5d40Schristos cfm->cfm_tag = xstrdup(val);
1394a53f50b9Schristos return 0;
1395a53f50b9Schristos }
1396a53f50b9Schristos
1397a53f50b9Schristos
1398a53f50b9Schristos /*
1399a53f50b9Schristos * Process one collected map.
1400a53f50b9Schristos */
1401a53f50b9Schristos static int
process_one_regular_map(const cf_map_t * cfm)1402a53f50b9Schristos process_one_regular_map(const cf_map_t *cfm)
1403a53f50b9Schristos {
1404a53f50b9Schristos if (!cfm->cfm_name) {
1405a53f50b9Schristos fprintf(stderr, "conf: map_name must be defined for map \"%s\"\n", cfm->cfm_dir);
1406a53f50b9Schristos return 1;
1407a53f50b9Schristos }
1408a53f50b9Schristos /*
1409a53f50b9Schristos * If map has no tag defined, process the map.
1410a53f50b9Schristos * If no conf_tag was set in amd -T, process all untagged entries.
1411a53f50b9Schristos * If a tag is defined, then process it only if it matches the map tag.
1412a53f50b9Schristos */
1413a53f50b9Schristos if (!cfm->cfm_tag ||
1414a53f50b9Schristos (conf_tag && STREQ(cfm->cfm_tag, conf_tag))) {
1415a53f50b9Schristos #ifdef DEBUG_CONF
1416a53f50b9Schristos fprintf(stderr, "processing map %s (flags=0x%x)...\n",
1417a53f50b9Schristos cfm->cfm_dir, cfm->cfm_flags);
1418a53f50b9Schristos #endif /* DEBUG_CONF */
1419a53f50b9Schristos root_newmap(cfm->cfm_dir,
1420a53f50b9Schristos cfm->cfm_opts ? cfm->cfm_opts : "",
1421a53f50b9Schristos cfm->cfm_name,
1422a53f50b9Schristos cfm);
1423a53f50b9Schristos } else {
1424a53f50b9Schristos fprintf(stderr, "skipping map %s...\n", cfm->cfm_dir);
1425a53f50b9Schristos }
1426a53f50b9Schristos
1427a53f50b9Schristos return 0;
1428a53f50b9Schristos }
1429a53f50b9Schristos
1430a53f50b9Schristos
1431a53f50b9Schristos /*
1432a53f50b9Schristos * Process all regular maps in conf file (if any)
1433a53f50b9Schristos */
1434a53f50b9Schristos int
process_all_regular_maps(void)1435a53f50b9Schristos process_all_regular_maps(void)
1436a53f50b9Schristos {
1437a53f50b9Schristos cf_map_t *tmp_map = head_map;
1438a53f50b9Schristos
1439a53f50b9Schristos /*
1440a53f50b9Schristos * If the amd.conf file only has a [global] section (pretty useless
1441a53f50b9Schristos * IMHO), there's nothing to process
1442a53f50b9Schristos */
1443a53f50b9Schristos if (!tmp_map)
1444a53f50b9Schristos return 0;
1445a53f50b9Schristos
1446a53f50b9Schristos while (tmp_map) {
1447a53f50b9Schristos if (process_one_regular_map(tmp_map) != 0)
1448a53f50b9Schristos return 1;
1449a53f50b9Schristos tmp_map = tmp_map->cfm_next;
1450a53f50b9Schristos }
1451a53f50b9Schristos return 0;
1452a53f50b9Schristos }
1453a53f50b9Schristos
1454a53f50b9Schristos
1455a53f50b9Schristos /*
1456a53f50b9Schristos * Find a cf_map_t for a given map name.
1457a53f50b9Schristos * Return NULL if not found.
1458a53f50b9Schristos */
1459a53f50b9Schristos cf_map_t *
find_cf_map(const char * name)1460a53f50b9Schristos find_cf_map(const char *name)
1461a53f50b9Schristos {
1462a53f50b9Schristos
1463a53f50b9Schristos cf_map_t *tmp_map = head_map;
1464a53f50b9Schristos
1465a53f50b9Schristos if (!tmp_map || !name)
1466a53f50b9Schristos return NULL;
1467a53f50b9Schristos
1468a53f50b9Schristos while (tmp_map) {
1469a53f50b9Schristos if (STREQ(tmp_map->cfm_dir, name)) {
1470a53f50b9Schristos return tmp_map;
1471a53f50b9Schristos }
1472a53f50b9Schristos tmp_map = tmp_map->cfm_next;
1473a53f50b9Schristos }
1474a53f50b9Schristos return NULL;
1475a53f50b9Schristos }
1476