Blame SOURCES/autofs-5.0.9-amd-lookup-rework-config-handling.patch

6bbd11
autofs-5.0.9 - amd lookup rework config handling
6bbd11
6bbd11
From: Ian Kent <ikent@redhat.com>
6bbd11
6bbd11
Re-work the autofs configuration sub-system to use sections.
6bbd11
Initially this means we have an anonomous section (for backward
6bbd11
compatibility) and an "autofs" section for the autofs global
6bbd11
configuration.
6bbd11
---
6bbd11
 daemon/automount.c  |    1 
6bbd11
 include/automount.h |   18 +
6bbd11
 include/defaults.h  |   27 +-
6bbd11
 lib/cache.c         |   19 -
6bbd11
 lib/defaults.c      |  836 +++++++++++++++++++++++++++++++++++++--------------
6bbd11
 5 files changed, 644 insertions(+), 257 deletions(-)
6bbd11
6bbd11
diff --git a/daemon/automount.c b/daemon/automount.c
6bbd11
index 0dd6477..fd5a19b 100644
6bbd11
--- a/daemon/automount.c
6bbd11
+++ b/daemon/automount.c
6bbd11
@@ -2339,6 +2339,7 @@ int main(int argc, char *argv[])
6bbd11
 		unlink(pid_file);
6bbd11
 		pid_file = NULL;
6bbd11
 	}
6bbd11
+	defaults_conf_release();
6bbd11
 	closelog();
6bbd11
 	release_flag_file();
6bbd11
 	macro_free_global_table();
6bbd11
diff --git a/include/automount.h b/include/automount.h
6bbd11
index 1aabfa4..6da1926 100644
6bbd11
--- a/include/automount.h
6bbd11
+++ b/include/automount.h
6bbd11
@@ -136,6 +136,24 @@ struct autofs_point;
6bbd11
 #define UMOUNT_RETRIES		8
6bbd11
 #define EXPIRE_RETRIES		3
6bbd11
 
6bbd11
+static u_int32_t inline hash(const char *key, unsigned int size)
6bbd11
+{
6bbd11
+	u_int32_t hashval;
6bbd11
+	char *s = (char *) key;
6bbd11
+
6bbd11
+	for (hashval = 0; *s != '\0';) {
6bbd11
+		hashval += (unsigned char) *s++;
6bbd11
+		hashval += (hashval << 10);
6bbd11
+		hashval ^= (hashval >> 6);
6bbd11
+	}
6bbd11
+
6bbd11
+	hashval += (hashval << 3);
6bbd11
+	hashval ^= (hashval >> 11);
6bbd11
+	hashval += (hashval << 15);
6bbd11
+
6bbd11
+	return hashval % size;
6bbd11
+}
6bbd11
+
6bbd11
 struct mapent_cache {
6bbd11
 	pthread_rwlock_t rwlock;
6bbd11
 	unsigned int size;
6bbd11
diff --git a/include/defaults.h b/include/defaults.h
6bbd11
index 871e14b..3bfcd49 100644
6bbd11
--- a/include/defaults.h
6bbd11
+++ b/include/defaults.h
6bbd11
@@ -2,7 +2,9 @@
6bbd11
  *
6bbd11
  *  defaults.h - system initialization defaults.
6bbd11
  *
6bbd11
- *   Copyright 2006 Ian Kent <raven@themaw.net>
6bbd11
+ *   Copyright 2013 Red Hat, Inc.
6bbd11
+ *   Copyright 2006, 2013 Ian Kent <raven@themaw.net>
6bbd11
+ *   All rights reserved.
6bbd11
  *
6bbd11
  *   This program is free software; you can redistribute it and/or modify
6bbd11
  *   it under the terms of the GNU General Public License as published by
6bbd11
@@ -22,15 +24,15 @@
6bbd11
 
6bbd11
 #define DEFAULT_MASTER_MAP_NAME	"auto.master"
6bbd11
 
6bbd11
-#define DEFAULT_TIMEOUT			600
6bbd11
-#define DEFAULT_NEGATIVE_TIMEOUT	60
6bbd11
-#define DEFAULT_MOUNT_WAIT		-1
6bbd11
-#define DEFAULT_UMOUNT_WAIT		12
6bbd11
-#define DEFAULT_BROWSE_MODE		1
6bbd11
-#define DEFAULT_LOGGING			0
6bbd11
+#define DEFAULT_TIMEOUT			"600"
6bbd11
+#define DEFAULT_NEGATIVE_TIMEOUT	"60"
6bbd11
+#define DEFAULT_MOUNT_WAIT		"-1"
6bbd11
+#define DEFAULT_UMOUNT_WAIT		"12"
6bbd11
+#define DEFAULT_BROWSE_MODE		"1"
6bbd11
+#define DEFAULT_LOGGING			"none"
6bbd11
 
6bbd11
-#define DEFAULT_LDAP_TIMEOUT		-1
6bbd11
-#define DEFAULT_LDAP_NETWORK_TIMEOUT	8
6bbd11
+#define DEFAULT_LDAP_TIMEOUT		"-1"
6bbd11
+#define DEFAULT_LDAP_NETWORK_TIMEOUT	"8"
6bbd11
 
6bbd11
 #define DEFAULT_MAP_OBJ_CLASS		"nisMap"
6bbd11
 #define DEFAULT_ENTRY_OBJ_CLASS		"nisObject"
6bbd11
@@ -38,11 +40,11 @@
6bbd11
 #define DEFAULT_ENTRY_ATTR		"cn"
6bbd11
 #define DEFAULT_VALUE_ATTR		"nisMapEntry"
6bbd11
 
6bbd11
-#define DEFAULT_NFS_MOUNT_PROTOCOL	3
6bbd11
-#define DEFAULT_APPEND_OPTIONS		1
6bbd11
+#define DEFAULT_MOUNT_NFS_DEFAULT_PROTOCOL	"3"
6bbd11
+#define DEFAULT_APPEND_OPTIONS		"1"
6bbd11
 #define DEFAULT_AUTH_CONF_FILE		AUTOFS_MAP_DIR "/autofs_ldap_auth.conf"
6bbd11
 
6bbd11
-#define DEFAULT_MAP_HASH_TABLE_SIZE	1024
6bbd11
+#define DEFAULT_MAP_HASH_TABLE_SIZE	"1024"
6bbd11
 
6bbd11
 #ifdef WITH_LDAP
6bbd11
 struct ldap_schema;
6bbd11
@@ -56,6 +58,7 @@ struct ldap_schema *defaults_get_schema(void);
6bbd11
 #endif
6bbd11
 
6bbd11
 unsigned int defaults_read_config(unsigned int);
6bbd11
+void defaults_conf_release(void);
6bbd11
 const char *defaults_get_master_map(void);
6bbd11
 int defaults_master_set(void);
6bbd11
 unsigned int defaults_get_timeout(void);
6bbd11
diff --git a/lib/cache.c b/lib/cache.c
6bbd11
index f2efcd3..9af1709 100644
6bbd11
--- a/lib/cache.c
6bbd11
+++ b/lib/cache.c
6bbd11
@@ -20,7 +20,6 @@
6bbd11
 #include <ctype.h>
6bbd11
 #include <stdio.h>
6bbd11
 #include <sys/param.h>
6bbd11
-#include <sys/types.h>
6bbd11
 #include <sys/stat.h>
6bbd11
 
6bbd11
 #include "automount.h"
6bbd11
@@ -362,24 +361,6 @@ struct mapent_cache *cache_init_null_cache(struct master *master)
6bbd11
 	return mc;
6bbd11
 }
6bbd11
 
6bbd11
-static u_int32_t hash(const char *key, unsigned int size)
6bbd11
-{
6bbd11
-	u_int32_t hashval;
6bbd11
-	char *s = (char *) key;
6bbd11
-
6bbd11
-	for (hashval = 0; *s != '\0';) {
6bbd11
-		hashval += (unsigned char) *s++;
6bbd11
-		hashval += (hashval << 10);
6bbd11
-		hashval ^= (hashval >> 6);
6bbd11
-	}
6bbd11
-
6bbd11
-	hashval += (hashval << 3);
6bbd11
-	hashval ^= (hashval >> 11);
6bbd11
-	hashval += (hashval << 15);
6bbd11
-
6bbd11
-	return hashval % size;
6bbd11
-}
6bbd11
-
6bbd11
 static u_int32_t ino_hash(dev_t dev, ino_t ino, unsigned int size)
6bbd11
 {
6bbd11
 	u_int32_t hashval;
6bbd11
diff --git a/lib/defaults.c b/lib/defaults.c
6bbd11
index 7c65387..29f3f00 100644
6bbd11
--- a/lib/defaults.c
6bbd11
+++ b/lib/defaults.c
6bbd11
@@ -2,7 +2,9 @@
6bbd11
  *
6bbd11
  *  defaults.h - system initialization defaults.
6bbd11
  *
6bbd11
- *   Copyright 2006 Ian Kent <raven@themaw.net> - All Rights Reserved
6bbd11
+ *   Copyright 2013 Red Hat, Inc.
6bbd11
+ *   Copyright 2006, 2013 Ian Kent <raven@themaw.net>
6bbd11
+ *   All rights reserved.
6bbd11
  *
6bbd11
  *   This program is free software; you can redistribute it and/or modify
6bbd11
  *   it under the terms of the GNU General Public License as published by
6bbd11
@@ -16,6 +18,7 @@
6bbd11
 #include <stdio.h>
6bbd11
 #include <ctype.h>
6bbd11
 #include <string.h>
6bbd11
+#include <sys/stat.h>
6bbd11
 
6bbd11
 #include "config.h"
6bbd11
 #include "list.h"
6bbd11
@@ -26,132 +29,450 @@
6bbd11
 #include "log.h"
6bbd11
 #include "automount.h"
6bbd11
 
6bbd11
-#define DEFAULTS_CONFIG_FILE		AUTOFS_CONF_DIR "/autofs"
6bbd11
+#define AUTOFS_GLOBAL_SECTION		"autofs"
6bbd11
+
6bbd11
+#define DEFAULT_CONFIG_FILE		AUTOFS_CONF_DIR "/autofs"
6bbd11
 #define MAX_LINE_LEN			256
6bbd11
 
6bbd11
-#define ENV_NAME_MASTER_MAP		"MASTER_MAP_NAME"
6bbd11
+#define NAME_MASTER_MAP			"master_map_name"
6bbd11
+
6bbd11
+#define NAME_TIMEOUT			"timeout"
6bbd11
+#define NAME_NEGATIVE_TIMEOUT		"negative_timeout"
6bbd11
+#define NAME_BROWSE_MODE		"browse_mode"
6bbd11
+#define NAME_LOGGING			"logging"
6bbd11
+
6bbd11
+#define NAME_LDAP_URI			"ldap_uri"
6bbd11
+#define NAME_LDAP_TIMEOUT		"ldap_timeout"
6bbd11
+#define NAME_LDAP_NETWORK_TIMEOUT	"ldap_network_timeout"
6bbd11
+
6bbd11
+#define NAME_SEARCH_BASE		"search_base"
6bbd11
 
6bbd11
-#define ENV_NAME_TIMEOUT		"TIMEOUT"
6bbd11
-#define ENV_NAME_NEGATIVE_TIMEOUT	"NEGATIVE_TIMEOUT"
6bbd11
-#define ENV_NAME_BROWSE_MODE		"BROWSE_MODE"
6bbd11
-#define ENV_NAME_LOGGING		"LOGGING"
6bbd11
+#define NAME_MAP_OBJ_CLASS		"map_object_class"
6bbd11
+#define NAME_ENTRY_OBJ_CLASS		"entry_object_class"
6bbd11
+#define NAME_MAP_ATTR			"map_attribute"
6bbd11
+#define NAME_ENTRY_ATTR			"entry_attribute"
6bbd11
+#define NAME_VALUE_ATTR			"value_attribute"
6bbd11
 
6bbd11
-#define LDAP_URI			"LDAP_URI"
6bbd11
-#define ENV_LDAP_TIMEOUT		"LDAP_TIMEOUT"
6bbd11
-#define ENV_LDAP_NETWORK_TIMEOUT	"LDAP_NETWORK_TIMEOUT"
6bbd11
+#define NAME_MOUNT_NFS_DEFAULT_PROTOCOL	"mount_nfs_default_protocol"
6bbd11
+#define NAME_APPEND_OPTIONS		"append_options"
6bbd11
+#define NAME_MOUNT_WAIT			"mount_wait"
6bbd11
+#define NAME_UMOUNT_WAIT		"umount_wait"
6bbd11
+#define NAME_AUTH_CONF_FILE		"auth_conf_file"
6bbd11
 
6bbd11
-#define SEARCH_BASE			"SEARCH_BASE"
6bbd11
+#define NAME_MAP_HASH_TABLE_SIZE	"map_hash_table_size"
6bbd11
 
6bbd11
-#define ENV_NAME_MAP_OBJ_CLASS		"MAP_OBJECT_CLASS"
6bbd11
-#define ENV_NAME_ENTRY_OBJ_CLASS	"ENTRY_OBJECT_CLASS"
6bbd11
-#define ENV_NAME_MAP_ATTR		"MAP_ATTRIBUTE"
6bbd11
-#define ENV_NAME_ENTRY_ATTR		"ENTRY_ATTRIBUTE"
6bbd11
-#define ENV_NAME_VALUE_ATTR		"VALUE_ATTRIBUTE"
6bbd11
+/* Status returns */
6bbd11
+#define CFG_OK		0x0000
6bbd11
+#define CFG_FAIL	0x0001
6bbd11
+#define CFG_EXISTS	0x0002
6bbd11
+#define CFG_NOTFOUND	0x0004
6bbd11
 
6bbd11
-#define ENV_MOUNT_NFS_DEFAULT_PROTOCOL	"MOUNT_NFS_DEFAULT_PROTOCOL"
6bbd11
-#define ENV_APPEND_OPTIONS		"APPEND_OPTIONS"
6bbd11
-#define ENV_MOUNT_WAIT			"MOUNT_WAIT"
6bbd11
-#define ENV_UMOUNT_WAIT			"UMOUNT_WAIT"
6bbd11
-#define ENV_AUTH_CONF_FILE		"AUTH_CONF_FILE"
6bbd11
+/* Config entry flags */
6bbd11
+#define CONF_ENV		0x00000001
6bbd11
 
6bbd11
-#define ENV_MAP_HASH_TABLE_SIZE		"MAP_HASH_TABLE_SIZE"
6bbd11
+#define CFG_TABLE_SIZE	128
6bbd11
 
6bbd11
 static const char *default_master_map_name = DEFAULT_MASTER_MAP_NAME;
6bbd11
 static const char *default_auth_conf_file  = DEFAULT_AUTH_CONF_FILE;
6bbd11
+static const char *autofs_gbl_sec	   = AUTOFS_GLOBAL_SECTION;
6bbd11
+
6bbd11
+struct conf_option {
6bbd11
+	char *section;
6bbd11
+	char *name;
6bbd11
+	char *value;
6bbd11
+	unsigned long flags;
6bbd11
+	struct conf_option *next;
6bbd11
+};
6bbd11
+
6bbd11
+struct conf_cache {
6bbd11
+	struct conf_option **hash;
6bbd11
+	time_t modified;
6bbd11
+};
6bbd11
+static pthread_mutex_t conf_mutex = PTHREAD_MUTEX_INITIALIZER;
6bbd11
+static struct conf_cache *config = NULL;
6bbd11
+
6bbd11
+static int conf_load_autofs_defaults(void);
6bbd11
+static int conf_update(const char *, const char *, const char *, unsigned long);
6bbd11
+static void conf_delete(const char *, const char *);
6bbd11
+static struct conf_option *conf_lookup(const char *, const char *);
6bbd11
+
6bbd11
+
6bbd11
+static void message(unsigned int to_syslog, const char *msg, ...)
6bbd11
+{
6bbd11
+	va_list ap;
6bbd11
+
6bbd11
+	va_start(ap, msg);
6bbd11
+	if (to_syslog)
6bbd11
+		vsyslog(LOG_CRIT, msg, ap);
6bbd11
+	else {
6bbd11
+		vfprintf(stderr, msg, ap);
6bbd11
+		fputc('\n', stderr);
6bbd11
+	}
6bbd11
+	va_end(ap);
6bbd11
+
6bbd11
+	return;
6bbd11
+}
6bbd11
 
6bbd11
-static char *get_env_string(const char *name)
6bbd11
+static int conf_init(void)
6bbd11
 {
6bbd11
-	char *val, *res;
6bbd11
+	struct conf_cache *cc;
6bbd11
+	unsigned int size = CFG_TABLE_SIZE;
6bbd11
+	unsigned int i;
6bbd11
+
6bbd11
+	cc = malloc(sizeof(struct conf_cache));
6bbd11
+	if (!cc)
6bbd11
+		return CFG_FAIL;
6bbd11
+	cc->modified = 0;
6bbd11
+
6bbd11
+	cc->hash = malloc(size * sizeof(struct conf_option *));
6bbd11
+	if (!cc->hash) {
6bbd11
+		free(cc);
6bbd11
+		return CFG_FAIL;
6bbd11
+	}
6bbd11
 
6bbd11
-	val = getenv(name);
6bbd11
-	if (!val)
6bbd11
-		return NULL;
6bbd11
+	for (i = 0; i < size; i++) {
6bbd11
+		cc->hash[i] = NULL;
6bbd11
+	}
6bbd11
 
6bbd11
-	res = strdup(val);
6bbd11
-	if (!res)
6bbd11
-		return NULL;
6bbd11
+	config = cc;
6bbd11
 
6bbd11
-	return res;
6bbd11
+	return CFG_OK;
6bbd11
 }
6bbd11
 
6bbd11
-static long get_env_number(const char *name)
6bbd11
+static void __conf_release(void)
6bbd11
 {
6bbd11
-	char *val;
6bbd11
-	long res = -1;
6bbd11
-
6bbd11
-	val = getenv(name);
6bbd11
-	if (!val)
6bbd11
-		return -1;
6bbd11
+	struct conf_cache *cc = config;
6bbd11
+	unsigned int size = CFG_TABLE_SIZE;
6bbd11
+	struct conf_option *co, *next;
6bbd11
+	unsigned int i;
6bbd11
+
6bbd11
+	for (i = 0; i < size; i++) {
6bbd11
+		co = cc->hash[i];
6bbd11
+		if (co == NULL)
6bbd11
+			continue;
6bbd11
+		next = co->next;
6bbd11
+		free(co->section);
6bbd11
+		free(co->name);
6bbd11
+		if (co->value)
6bbd11
+			free(co->value);
6bbd11
+		free(co);
6bbd11
+
6bbd11
+		while (next) {
6bbd11
+			co = next;
6bbd11
+			next = co->next;
6bbd11
+			free(co->section);
6bbd11
+			free(co->name);
6bbd11
+			if (co->value)
6bbd11
+				free(co->value);
6bbd11
+			free(co);
6bbd11
+		}
6bbd11
+		cc->hash[i] = NULL;
6bbd11
+	}
6bbd11
 
6bbd11
-	if (isdigit(*val))
6bbd11
-		res = atol(val);
6bbd11
+	free(cc->hash);
6bbd11
+	free(cc);
6bbd11
+	config = NULL;
6bbd11
 
6bbd11
-	if (res < 0)
6bbd11
-		return -1;
6bbd11
+	return;
6bbd11
+}
6bbd11
 
6bbd11
-	return res;
6bbd11
+void defaults_conf_release(void)
6bbd11
+{
6bbd11
+	pthread_mutex_lock(&conf_mutex);
6bbd11
+	__conf_release();
6bbd11
+	pthread_mutex_unlock(&conf_mutex);
6bbd11
+	return;
6bbd11
 }
6bbd11
 
6bbd11
-static int get_env_yesno(const char *name)
6bbd11
+static int conf_load_autofs_defaults(void)
6bbd11
 {
6bbd11
-	const char *val;
6bbd11
-	int res = -1;
6bbd11
+	struct conf_option *co;
6bbd11
+	const char *sec = autofs_gbl_sec;
6bbd11
+	int ret;
6bbd11
 
6bbd11
-	val = getenv(name);
6bbd11
-	if (!val)
6bbd11
-		return -1;
6bbd11
+	ret = conf_update(sec, NAME_MASTER_MAP,
6bbd11
+			  DEFAULT_MASTER_MAP_NAME, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_TIMEOUT,
6bbd11
+			  DEFAULT_TIMEOUT, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_NEGATIVE_TIMEOUT,
6bbd11
+			  DEFAULT_NEGATIVE_TIMEOUT, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_BROWSE_MODE,
6bbd11
+			  DEFAULT_BROWSE_MODE, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_LOGGING,
6bbd11
+			  DEFAULT_LOGGING, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_LDAP_TIMEOUT,
6bbd11
+			  DEFAULT_LDAP_TIMEOUT, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_LDAP_NETWORK_TIMEOUT,
6bbd11
+			  DEFAULT_LDAP_NETWORK_TIMEOUT, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_MAP_OBJ_CLASS,
6bbd11
+			  DEFAULT_MAP_OBJ_CLASS, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_ENTRY_OBJ_CLASS,
6bbd11
+			  DEFAULT_ENTRY_OBJ_CLASS, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_MAP_ATTR,
6bbd11
+			  DEFAULT_MAP_ATTR, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_ENTRY_ATTR,
6bbd11
+			  DEFAULT_ENTRY_ATTR, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_VALUE_ATTR,
6bbd11
+			  DEFAULT_VALUE_ATTR, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_APPEND_OPTIONS,
6bbd11
+			  DEFAULT_APPEND_OPTIONS, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_MOUNT_WAIT,
6bbd11
+			  DEFAULT_MOUNT_WAIT, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_UMOUNT_WAIT,
6bbd11
+			  DEFAULT_UMOUNT_WAIT, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_AUTH_CONF_FILE,
6bbd11
+			  DEFAULT_AUTH_CONF_FILE, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	ret = conf_update(sec, NAME_MOUNT_NFS_DEFAULT_PROTOCOL,
6bbd11
+			  DEFAULT_MOUNT_NFS_DEFAULT_PROTOCOL, CONF_ENV);
6bbd11
+	if (ret == CFG_FAIL)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	/* LDAP_URI nad SEARCH_BASE can occur multiple times */
6bbd11
+	while ((co = conf_lookup(sec, NAME_LDAP_URI)))
6bbd11
+		conf_delete(co->section, co->name);
6bbd11
+
6bbd11
+	while ((co = conf_lookup(sec, NAME_SEARCH_BASE)))
6bbd11
+		conf_delete(co->section, co->name);
6bbd11
 
6bbd11
-	if (isdigit(*val))
6bbd11
-		res = atoi(val);
6bbd11
-	else if (!strcasecmp(val, "yes"))
6bbd11
-		return 1;
6bbd11
-	else if (!strcasecmp(val, "no"))
6bbd11
-		return 0;
6bbd11
+	return 1;
6bbd11
 
6bbd11
-	return res;
6bbd11
+error:
6bbd11
+	return 0;
6bbd11
 }
6bbd11
 
6bbd11
-/*
6bbd11
- * We've changed the key names so we need to check for the
6bbd11
- * config key and it's old name for backward conpatibility.
6bbd11
-*/
6bbd11
-static int check_set_config_value(const char *res, const char *name, const char *value, unsigned to_syslog)
6bbd11
+static int conf_add(const char *section, const char *key, const char *value, unsigned long flags)
6bbd11
 {
6bbd11
-	char *old_name;
6bbd11
+	struct conf_option *co;
6bbd11
+	char *sec, *name, *val, *tmp;
6bbd11
+	unsigned int size = CFG_TABLE_SIZE;
6bbd11
+	u_int32_t index;
6bbd11
 	int ret;
6bbd11
 
6bbd11
-	if (!strcasecmp(res, name)) {
6bbd11
-		ret = setenv(name, value, 0);
6bbd11
-		if (ret) {
6bbd11
-			if (!to_syslog)
6bbd11
-				fprintf(stderr,
6bbd11
-				        "can't set config value for %s, "
6bbd11
-					"error %d\n", name, ret);
6bbd11
-			else
6bbd11
-				logmsg("can't set config value for %s, "
6bbd11
-				      "error %d", name, ret);
6bbd11
+	sec = name = val = NULL;
6bbd11
+
6bbd11
+	co = conf_lookup(section, key);
6bbd11
+	if (co) {
6bbd11
+		ret = CFG_EXISTS;
6bbd11
+		goto error;
6bbd11
+	}
6bbd11
+
6bbd11
+	ret = CFG_FAIL;
6bbd11
+
6bbd11
+	/* Environment overrides file value */
6bbd11
+	if (((flags & CFG_ENV) && (tmp = getenv(key))) || value) {
6bbd11
+		if (tmp)
6bbd11
+			val = strdup(tmp);
6bbd11
+		else
6bbd11
+			val = strdup(value);
6bbd11
+		if (!val)
6bbd11
+			goto error;
6bbd11
+	}
6bbd11
+
6bbd11
+	name = strdup(key);
6bbd11
+	if (!key)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	sec = strdup(section);
6bbd11
+	if (!sec)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	co = malloc(sizeof(struct conf_option));
6bbd11
+	if (!co)
6bbd11
+		goto error;
6bbd11
+
6bbd11
+	co->section = sec;
6bbd11
+	co->name = name;
6bbd11
+	co->value = val;
6bbd11
+	co->flags = flags;
6bbd11
+	co->next = NULL;
6bbd11
+
6bbd11
+	/* Don't change user set values in the environment */
6bbd11
+	if (flags & CONF_ENV)
6bbd11
+		setenv(name, value, 0);
6bbd11
+
6bbd11
+	index = hash(key, size);
6bbd11
+	if (!config->hash[index])
6bbd11
+		config->hash[index] = co;
6bbd11
+	else {
6bbd11
+		struct conf_option *last = NULL, *next;
6bbd11
+		next = config->hash[index];
6bbd11
+		while (next) {
6bbd11
+			last = next;
6bbd11
+			next = last->next;
6bbd11
 		}
6bbd11
-		return 1;
6bbd11
+		last->next = co;
6bbd11
 	}
6bbd11
 
6bbd11
-	old_name = alloca(strlen(name) + 9);
6bbd11
-	strcpy(old_name, "DEFAULT_");
6bbd11
-	strcat(old_name, name);
6bbd11
+	return CFG_OK;
6bbd11
+
6bbd11
+error:
6bbd11
+	if (name)
6bbd11
+		free(name);
6bbd11
+	if (val)
6bbd11
+		free(val);
6bbd11
+	if (sec)
6bbd11
+		free(sec);
6bbd11
+
6bbd11
+	return ret;
6bbd11
+}
6bbd11
 
6bbd11
-	if (!strcasecmp(res, old_name)) {
6bbd11
-		ret = setenv(name, value, 0);
6bbd11
-		if (ret) {
6bbd11
-			if (!to_syslog)
6bbd11
-				fprintf(stderr,
6bbd11
-				        "can't set config value for %s, "
6bbd11
-					"error %d\n", name, ret);
6bbd11
+static void conf_delete(const char *section, const char *key)
6bbd11
+{
6bbd11
+	struct conf_option *co, *last;
6bbd11
+	unsigned int size = CFG_TABLE_SIZE;
6bbd11
+
6bbd11
+	last = NULL;
6bbd11
+	for (co = config->hash[hash(key, size)]; co != NULL; co = co->next) {
6bbd11
+		if (strcasecmp(section, co->section))
6bbd11
+			continue;
6bbd11
+		if (!strcasecmp(key, co->name))
6bbd11
+			break;
6bbd11
+		last = co;
6bbd11
+	}
6bbd11
+
6bbd11
+	if (!co)
6bbd11
+		return;
6bbd11
+
6bbd11
+	if (last)
6bbd11
+		last->next = co->next;
6bbd11
+
6bbd11
+	free(co->section);
6bbd11
+	free(co->name);
6bbd11
+	if (co->value);
6bbd11
+		free(co->value);
6bbd11
+	free(co);
6bbd11
+}
6bbd11
+
6bbd11
+static int conf_update(const char *section,
6bbd11
+			const char *key, const char *value,
6bbd11
+			unsigned long flags)
6bbd11
+{
6bbd11
+	struct conf_option *co = NULL;
6bbd11
+	int ret;
6bbd11
+
6bbd11
+	ret = CFG_FAIL;
6bbd11
+	co = conf_lookup(section, key);
6bbd11
+	if (!co)
6bbd11
+		ret = conf_add(section, key, value, flags);
6bbd11
+	else {
6bbd11
+		char *val = NULL, *tmp;
6bbd11
+		/* Environment overrides file value */
6bbd11
+		if (((flags & CONF_ENV) && (tmp = getenv(key))) || value) {
6bbd11
+			if (tmp)
6bbd11
+				val = strdup(tmp);
6bbd11
 			else
6bbd11
-				logmsg("can't set config value for %s, "
6bbd11
-				      "error %d\n", name, ret);
6bbd11
+				val = strdup(value);
6bbd11
+			if (!val)
6bbd11
+				goto error;
6bbd11
 		}
6bbd11
-		return 1;
6bbd11
+		if (co->value)
6bbd11
+			free(co->value);
6bbd11
+		co->value = val;
6bbd11
+		if (flags)
6bbd11
+			co->flags = flags;
6bbd11
+		/* Don't change user set values in the environment */
6bbd11
+		if (flags & CONF_ENV)
6bbd11
+			setenv(key, value, 0);
6bbd11
 	}
6bbd11
-	return 0;
6bbd11
+
6bbd11
+	return CFG_OK;
6bbd11
+
6bbd11
+error:
6bbd11
+	return ret;
6bbd11
+}
6bbd11
+
6bbd11
+static struct conf_option *conf_lookup(const char *section, const char *key)
6bbd11
+{
6bbd11
+	struct conf_option *co;
6bbd11
+	unsigned int size = CFG_TABLE_SIZE;
6bbd11
+
6bbd11
+	if (!key || !section)
6bbd11
+		return NULL;
6bbd11
+
6bbd11
+	for (co = config->hash[hash(key, size)]; co != NULL; co = co->next) {
6bbd11
+		if (strcasecmp(section, co->section))
6bbd11
+			continue;
6bbd11
+		if (!strcasecmp(key, co->name))
6bbd11
+			break;
6bbd11
+		/*
6bbd11
+		 * Strip "DEFAULT_" and look for config entry for
6bbd11
+		 * backward compatibility with old style config names.
6bbd11
+		 */
6bbd11
+		if (strlen(key) <= 8)
6bbd11
+			continue;
6bbd11
+		if (!strncasecmp("DEFAULT_", key, 8) &&
6bbd11
+		    !strcasecmp(key + 8, co->name))
6bbd11
+			break;
6bbd11
+	}
6bbd11
+
6bbd11
+	return co;
6bbd11
+}
6bbd11
+
6bbd11
+/*
6bbd11
+ * We've changed the key names so we need to check for the
6bbd11
+ * config key and it's old name for backward conpatibility.
6bbd11
+*/
6bbd11
+static int check_set_config_value(const char *res, const char *value)
6bbd11
+{
6bbd11
+	const char *sec = autofs_gbl_sec;
6bbd11
+	int ret;
6bbd11
+
6bbd11
+	if (!strcasecmp(res, NAME_LDAP_URI))
6bbd11
+		ret = conf_add(sec, res, value, 0);
6bbd11
+	else if (!strcasecmp(res, NAME_SEARCH_BASE))
6bbd11
+		ret = conf_add(sec, res, value, 0);
6bbd11
+	else
6bbd11
+		ret = conf_update(sec, res, value, 0);
6bbd11
+
6bbd11
+	return ret;
6bbd11
 }
6bbd11
 
6bbd11
 static int parse_line(char *line, char **res, char **value)
6bbd11
@@ -200,6 +521,119 @@ static int parse_line(char *line, char **res, char **value)
6bbd11
 	return 1;
6bbd11
 }
6bbd11
 
6bbd11
+/*
6bbd11
+ * Read config env variables and check they have been set.
6bbd11
+ *
6bbd11
+ * This simple minded routine assumes the config file
6bbd11
+ * is valid bourne shell script without spaces around "="
6bbd11
+ * and that it has valid values.
6bbd11
+ */
6bbd11
+unsigned int defaults_read_config(unsigned int to_syslog)
6bbd11
+{
6bbd11
+	FILE *f;
6bbd11
+	char buf[MAX_LINE_LEN];
6bbd11
+	struct stat stb;
6bbd11
+	char *res;
6bbd11
+	int ret;
6bbd11
+
6bbd11
+	f = open_fopen_r(DEFAULT_CONFIG_FILE);
6bbd11
+	if (!f)
6bbd11
+		return 0;
6bbd11
+
6bbd11
+	pthread_mutex_lock(&conf_mutex);
6bbd11
+	if (config) {
6bbd11
+		if (fstat(fileno(f), &stb) != -1) {
6bbd11
+			/* Config hasn't been updated */
6bbd11
+			if (stb.st_mtime <= config->modified)
6bbd11
+				goto out;
6bbd11
+		}
6bbd11
+	} else {
6bbd11
+		if (conf_init()) {
6bbd11
+			pthread_mutex_unlock(&conf_mutex);
6bbd11
+			message(to_syslog, "failed to init config");
6bbd11
+			return 0;
6bbd11
+		}
6bbd11
+	}
6bbd11
+
6bbd11
+	/* Set configuration to defaults */
6bbd11
+	ret = conf_load_autofs_defaults();
6bbd11
+	if (!ret) {
6bbd11
+		pthread_mutex_unlock(&conf_mutex);
6bbd11
+		message(to_syslog, "failed to reset autofs default config");
6bbd11
+		return 0;
6bbd11
+	}
6bbd11
+
6bbd11
+	while ((res = fgets(buf, MAX_LINE_LEN, f))) {
6bbd11
+		char *key, *value;
6bbd11
+		if (!parse_line(res, &key, &value))
6bbd11
+			continue;
6bbd11
+		check_set_config_value(key, value);
6bbd11
+	}
6bbd11
+
6bbd11
+	if (fstat(fileno(f), &stb) != -1)
6bbd11
+		config->modified = stb.st_mtime;
6bbd11
+	else
6bbd11
+		message(to_syslog, "failed to update config modified time");
6bbd11
+
6bbd11
+	if (!feof(f) || ferror(f)) {
6bbd11
+		pthread_mutex_unlock(&conf_mutex);
6bbd11
+		message(to_syslog,
6bbd11
+			"fgets returned error %d while reading %s",
6bbd11
+			ferror(f), DEFAULT_CONFIG_FILE);
6bbd11
+		fclose(f);
6bbd11
+		return 0;
6bbd11
+	}
6bbd11
+out:
6bbd11
+	pthread_mutex_unlock(&conf_mutex);
6bbd11
+	fclose(f);
6bbd11
+	return 1;
6bbd11
+}
6bbd11
+
6bbd11
+static char *conf_get_string(const char *section, const char *name)
6bbd11
+{
6bbd11
+	struct conf_option *co;
6bbd11
+	char *val = NULL;
6bbd11
+
6bbd11
+	pthread_mutex_lock(&conf_mutex);
6bbd11
+	co = conf_lookup(section, name);
6bbd11
+	if (co && co->value)
6bbd11
+		val = strdup(co->value);
6bbd11
+	pthread_mutex_unlock(&conf_mutex);
6bbd11
+	return val;
6bbd11
+}
6bbd11
+
6bbd11
+static long conf_get_number(const char *section, const char *name)
6bbd11
+{
6bbd11
+	struct conf_option *co;
6bbd11
+	long val = -1;
6bbd11
+
6bbd11
+	pthread_mutex_lock(&conf_mutex);
6bbd11
+	co = conf_lookup(section, name);
6bbd11
+	if (co && co->value)
6bbd11
+		val = atol(co->value);
6bbd11
+	pthread_mutex_unlock(&conf_mutex);
6bbd11
+	return val;
6bbd11
+}
6bbd11
+
6bbd11
+static int conf_get_yesno(const char *section, const char *name)
6bbd11
+{
6bbd11
+	struct conf_option *co;
6bbd11
+	int val = -1;
6bbd11
+
6bbd11
+	pthread_mutex_lock(&conf_mutex);
6bbd11
+	co = conf_lookup(section, name);
6bbd11
+	if (co && co->value) {
6bbd11
+		if (isdigit(*co->value))
6bbd11
+			val = atoi(co->value);
6bbd11
+		else if (!strcasecmp(co->value, "yes"))
6bbd11
+			val = 1;
6bbd11
+		else if (!strcasecmp(co->value, "no"))
6bbd11
+			val = 0;
6bbd11
+	}
6bbd11
+	pthread_mutex_unlock(&conf_mutex);
6bbd11
+	return val;
6bbd11
+}
6bbd11
+
6bbd11
 #ifdef WITH_LDAP
6bbd11
 void defaults_free_uris(struct list_head *list)
6bbd11
 {
6bbd11
@@ -229,7 +663,7 @@ static unsigned int add_uris(char *value, struct list_head *list)
6bbd11
 	char *str, *tok, *ptr = NULL;
6bbd11
 	size_t len = strlen(value) + 1;
6bbd11
 
6bbd11
-	str = alloca(len);
6bbd11
+	str = malloc(len);
6bbd11
 	if (!str)
6bbd11
 		return 0;
6bbd11
 	strcpy(str, value);
6bbd11
@@ -253,44 +687,48 @@ static unsigned int add_uris(char *value, struct list_head *list)
6bbd11
 
6bbd11
 		tok = strtok_r(NULL, " ", &ptr);
6bbd11
 	}
6bbd11
+	free(str);
6bbd11
 
6bbd11
 	return 1;
6bbd11
 }
6bbd11
 
6bbd11
 struct list_head *defaults_get_uris(void)
6bbd11
 {
6bbd11
-	FILE *f;
6bbd11
-	char buf[MAX_LINE_LEN];
6bbd11
-	char *res;
6bbd11
+	struct conf_option *co;
6bbd11
 	struct list_head *list;
6bbd11
 
6bbd11
-	f = open_fopen_r(DEFAULTS_CONFIG_FILE);
6bbd11
-	if (!f)
6bbd11
-		return NULL;
6bbd11
-
6bbd11
 	list = malloc(sizeof(struct list_head));
6bbd11
 	if (!list) {
6bbd11
-		fclose(f);
6bbd11
 		return NULL;
6bbd11
 	}
6bbd11
 	INIT_LIST_HEAD(list);
6bbd11
 
6bbd11
-	while ((res = fgets(buf, MAX_LINE_LEN, f))) {
6bbd11
-		char *key, *value;
6bbd11
+	if (defaults_read_config(0)) {
6bbd11
+		free(list);
6bbd11
+		return NULL;
6bbd11
+	}
6bbd11
 
6bbd11
-		if (!parse_line(res, &key, &value))
6bbd11
-			continue;
6bbd11
+	pthread_mutex_lock(&conf_mutex);
6bbd11
+	co = conf_lookup(autofs_gbl_sec, NAME_LDAP_URI);
6bbd11
+	if (!co || !co->value) {
6bbd11
+		pthread_mutex_unlock(&conf_mutex);
6bbd11
+		free(list);
6bbd11
+		return NULL;
6bbd11
+	}
6bbd11
 
6bbd11
-		if (!strcasecmp(res, LDAP_URI))
6bbd11
-			add_uris(value, list);
6bbd11
+	while (co) {
6bbd11
+		if (!strcasecmp(co->name, NAME_LDAP_URI))
6bbd11
+			if (co->value)
6bbd11
+				add_uris(co->value, list);
6bbd11
+		co = co->next;
6bbd11
 	}
6bbd11
+	pthread_mutex_unlock(&conf_mutex);
6bbd11
 
6bbd11
 	if (list_empty(list)) {
6bbd11
 		free(list);
6bbd11
 		list = NULL;
6bbd11
 	}
6bbd11
 
6bbd11
-	fclose(f);
6bbd11
 	return list;
6bbd11
 }
6bbd11
 
6bbd11
@@ -390,45 +828,50 @@ void defaults_free_searchdns(struct ldap_searchdn *sdn)
6bbd11
 
6bbd11
 struct ldap_searchdn *defaults_get_searchdns(void)
6bbd11
 {
6bbd11
-	FILE *f;
6bbd11
-	char buf[MAX_LINE_LEN];
6bbd11
-	char *res;
6bbd11
+	struct conf_option *co;
6bbd11
 	struct ldap_searchdn *sdn, *last;
6bbd11
 
6bbd11
-	f = open_fopen_r(DEFAULTS_CONFIG_FILE);
6bbd11
-	if (!f)
6bbd11
+	if (defaults_read_config(0))
6bbd11
 		return NULL;
6bbd11
 
6bbd11
+	pthread_mutex_lock(&conf_mutex);
6bbd11
+	co = conf_lookup(autofs_gbl_sec, NAME_SEARCH_BASE);
6bbd11
+	if (!co || !co->value) {
6bbd11
+		pthread_mutex_unlock(&conf_mutex);
6bbd11
+		return NULL;
6bbd11
+	}
6bbd11
+
6bbd11
 	sdn = last = NULL;
6bbd11
 
6bbd11
-	while ((res = fgets(buf, MAX_LINE_LEN, f))) {
6bbd11
-		char *key, *value;
6bbd11
+	while (co) {
6bbd11
+		struct ldap_searchdn *new;
6bbd11
 
6bbd11
-		if (!parse_line(res, &key, &value))
6bbd11
+		if (!co->value || strcasecmp(co->name, NAME_SEARCH_BASE) ) {
6bbd11
+			co = co->next;
6bbd11
 			continue;
6bbd11
+		}
6bbd11
 
6bbd11
-		if (!strcasecmp(key, SEARCH_BASE)) {
6bbd11
-			struct ldap_searchdn *new = alloc_searchdn(value);
6bbd11
+		new = alloc_searchdn(co->value);
6bbd11
+		if (!new) {
6bbd11
+			pthread_mutex_unlock(&conf_mutex);
6bbd11
+			defaults_free_searchdns(sdn);
6bbd11
+			return NULL;
6bbd11
+		}
6bbd11
 
6bbd11
-			if (!new) {
6bbd11
-				defaults_free_searchdns(sdn);
6bbd11
-				fclose(f);
6bbd11
-				return NULL;
6bbd11
-			}
6bbd11
+		if (!last)
6bbd11
+			last = new;
6bbd11
+		else {
6bbd11
+			last->next = new;
6bbd11
+			last = new;
6bbd11
+		}
6bbd11
 
6bbd11
-			if (!last)
6bbd11
-				last = new;
6bbd11
-			else {
6bbd11
-				last->next = new;
6bbd11
-				last = new;
6bbd11
-			}
6bbd11
+		if (!sdn)
6bbd11
+			sdn = new;
6bbd11
 
6bbd11
-			if (!sdn)
6bbd11
-				sdn = new;
6bbd11
-		}
6bbd11
+		co = co->next;
6bbd11
 	}
6bbd11
+	pthread_mutex_unlock(&conf_mutex);
6bbd11
 
6bbd11
-	fclose(f);
6bbd11
 	return sdn;
6bbd11
 }
6bbd11
 
6bbd11
@@ -436,25 +879,26 @@ struct ldap_schema *defaults_get_schema(void)
6bbd11
 {
6bbd11
 	struct ldap_schema *schema;
6bbd11
 	char *mc, *ma, *ec, *ea, *va;
6bbd11
+	const char *sec = autofs_gbl_sec;
6bbd11
 
6bbd11
-	mc = get_env_string(ENV_NAME_MAP_OBJ_CLASS);
6bbd11
+	mc = conf_get_string(sec, NAME_MAP_OBJ_CLASS);
6bbd11
 	if (!mc)
6bbd11
 		return NULL;
6bbd11
 
6bbd11
-	ma = get_env_string(ENV_NAME_MAP_ATTR);
6bbd11
+	ma = conf_get_string(sec, NAME_MAP_ATTR);
6bbd11
 	if (!ma) {
6bbd11
 		free(mc);
6bbd11
 		return NULL;
6bbd11
 	}
6bbd11
 
6bbd11
-	ec = get_env_string(ENV_NAME_ENTRY_OBJ_CLASS);
6bbd11
+	ec = conf_get_string(sec, NAME_ENTRY_OBJ_CLASS);
6bbd11
 	if (!ec) {
6bbd11
 		free(mc);
6bbd11
 		free(ma);
6bbd11
 		return NULL;
6bbd11
 	}
6bbd11
 
6bbd11
-	ea = get_env_string(ENV_NAME_ENTRY_ATTR);
6bbd11
+	ea = conf_get_string(sec, NAME_ENTRY_ATTR);
6bbd11
 	if (!ea) {
6bbd11
 		free(mc);
6bbd11
 		free(ma);
6bbd11
@@ -462,7 +906,7 @@ struct ldap_schema *defaults_get_schema(void)
6bbd11
 		return NULL;
6bbd11
 	}
6bbd11
 
6bbd11
-	va = get_env_string(ENV_NAME_VALUE_ATTR);
6bbd11
+	va = conf_get_string(sec, NAME_VALUE_ATTR);
6bbd11
 	if (!va) {
6bbd11
 		free(mc);
6bbd11
 		free(ma);
6bbd11
@@ -491,72 +935,9 @@ struct ldap_schema *defaults_get_schema(void)
6bbd11
 }
6bbd11
 #endif
6bbd11
 
6bbd11
-/*
6bbd11
- * Read config env variables and check they have been set.
6bbd11
- *
6bbd11
- * This simple minded routine assumes the config file
6bbd11
- * is valid bourne shell script without spaces around "="
6bbd11
- * and that it has valid values.
6bbd11
- */
6bbd11
-unsigned int defaults_read_config(unsigned int to_syslog)
6bbd11
-{
6bbd11
-	FILE *f;
6bbd11
-	char buf[MAX_LINE_LEN];
6bbd11
-	char *res;
6bbd11
-
6bbd11
-	f = open_fopen_r(DEFAULTS_CONFIG_FILE);
6bbd11
-	if (!f)
6bbd11
-		return 0;
6bbd11
-
6bbd11
-	while ((res = fgets(buf, MAX_LINE_LEN, f))) {
6bbd11
-		char *key, *value;
6bbd11
-
6bbd11
-		if (!parse_line(res, &key, &value))
6bbd11
-			continue;
6bbd11
-
6bbd11
-		if (check_set_config_value(key, ENV_NAME_MASTER_MAP, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_NAME_TIMEOUT, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_NAME_NEGATIVE_TIMEOUT, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_NAME_BROWSE_MODE, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_NAME_LOGGING, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_LDAP_TIMEOUT, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_LDAP_NETWORK_TIMEOUT, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_NAME_MAP_OBJ_CLASS, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_NAME_ENTRY_OBJ_CLASS, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_NAME_MAP_ATTR, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_NAME_ENTRY_ATTR, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_NAME_VALUE_ATTR, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_APPEND_OPTIONS, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_MOUNT_WAIT, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_UMOUNT_WAIT, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_AUTH_CONF_FILE, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_MAP_HASH_TABLE_SIZE, value, to_syslog) ||
6bbd11
-		    check_set_config_value(key, ENV_MOUNT_NFS_DEFAULT_PROTOCOL, value, to_syslog))
6bbd11
-			;
6bbd11
-	}
6bbd11
-
6bbd11
-	if (!feof(f) || ferror(f)) {
6bbd11
-		if (!to_syslog) {
6bbd11
-			fprintf(stderr,
6bbd11
-				"fgets returned error %d while reading %s\n",
6bbd11
-				ferror(f), DEFAULTS_CONFIG_FILE);
6bbd11
-		} else {
6bbd11
-			logmsg("fgets returned error %d while reading %s",
6bbd11
-			      ferror(f), DEFAULTS_CONFIG_FILE);
6bbd11
-		}
6bbd11
-		fclose(f);
6bbd11
-		return 0;
6bbd11
-	}
6bbd11
-
6bbd11
-	fclose(f);
6bbd11
-	return 1;
6bbd11
-}
6bbd11
-
6bbd11
 const char *defaults_get_master_map(void)
6bbd11
 {
6bbd11
-	char *master;
6bbd11
-
6bbd11
-	master = get_env_string(ENV_NAME_MASTER_MAP);
6bbd11
+	char *master = conf_get_string(autofs_gbl_sec, NAME_MASTER_MAP);
6bbd11
 	if (!master)
6bbd11
 		return strdup(default_master_map_name);
6bbd11
 
6bbd11
@@ -565,20 +946,23 @@ const char *defaults_get_master_map(void)
6bbd11
 
6bbd11
 int defaults_master_set(void)
6bbd11
 {
6bbd11
-	char *val = getenv(ENV_NAME_MASTER_MAP);
6bbd11
-	if (!val)
6bbd11
-		return 0;
6bbd11
+	struct conf_option *co;
6bbd11
 
6bbd11
-	return 1;
6bbd11
+	pthread_mutex_lock(&conf_mutex);
6bbd11
+	co = conf_lookup(autofs_gbl_sec, NAME_MASTER_MAP);
6bbd11
+	pthread_mutex_unlock(&conf_mutex);
6bbd11
+	if (co)
6bbd11
+		return 1;
6bbd11
+	return 0;
6bbd11
 }
6bbd11
 
6bbd11
 unsigned int defaults_get_timeout(void)
6bbd11
 {
6bbd11
 	long timeout;
6bbd11
 
6bbd11
-	timeout = get_env_number(ENV_NAME_TIMEOUT);
6bbd11
+	timeout = conf_get_number(autofs_gbl_sec, NAME_TIMEOUT);
6bbd11
 	if (timeout < 0)
6bbd11
-		timeout = DEFAULT_TIMEOUT;
6bbd11
+		timeout = atol(DEFAULT_TIMEOUT);
6bbd11
 
6bbd11
 	return (unsigned int) timeout;
6bbd11
 }
6bbd11
@@ -587,9 +971,9 @@ unsigned int defaults_get_negative_timeout(void)
6bbd11
 {
6bbd11
 	long n_timeout;
6bbd11
 
6bbd11
-	n_timeout = get_env_number(ENV_NAME_NEGATIVE_TIMEOUT);
6bbd11
+	n_timeout = conf_get_number(autofs_gbl_sec, NAME_NEGATIVE_TIMEOUT);
6bbd11
 	if (n_timeout <= 0)
6bbd11
-		n_timeout = DEFAULT_NEGATIVE_TIMEOUT;
6bbd11
+		n_timeout = atol(DEFAULT_NEGATIVE_TIMEOUT);
6bbd11
 
6bbd11
 	return (unsigned int) n_timeout;
6bbd11
 }
6bbd11
@@ -598,9 +982,9 @@ unsigned int defaults_get_browse_mode(void)
6bbd11
 {
6bbd11
 	int res;
6bbd11
 
6bbd11
-	res = get_env_yesno(ENV_NAME_BROWSE_MODE);
6bbd11
+	res = conf_get_yesno(autofs_gbl_sec, NAME_BROWSE_MODE);
6bbd11
 	if (res < 0)
6bbd11
-		res = DEFAULT_BROWSE_MODE;
6bbd11
+		res = atoi(DEFAULT_BROWSE_MODE);
6bbd11
 
6bbd11
 	return res;
6bbd11
 }
6bbd11
@@ -608,14 +992,14 @@ unsigned int defaults_get_browse_mode(void)
6bbd11
 unsigned int defaults_get_logging(void)
6bbd11
 {
6bbd11
 	char *res;
6bbd11
-	unsigned int logging = DEFAULT_LOGGING;
6bbd11
+	unsigned int logging = LOGOPT_NONE;
6bbd11
 
6bbd11
-	res = get_env_string(ENV_NAME_LOGGING);
6bbd11
+	res = conf_get_string(autofs_gbl_sec, NAME_LOGGING);
6bbd11
 	if (!res)
6bbd11
 		return logging;
6bbd11
 
6bbd11
 	if (!strcasecmp(res, "none"))
6bbd11
-		logging = DEFAULT_LOGGING;
6bbd11
+		logging = LOGOPT_NONE;
6bbd11
 	else {
6bbd11
 		if (!strcasecmp(res, "verbose"))
6bbd11
 			logging |= LOGOPT_VERBOSE;
6bbd11
@@ -633,9 +1017,9 @@ unsigned int defaults_get_ldap_timeout(void)
6bbd11
 {
6bbd11
 	int res;
6bbd11
 
6bbd11
-	res = get_env_number(ENV_LDAP_TIMEOUT);
6bbd11
+	res = conf_get_number(autofs_gbl_sec, NAME_LDAP_TIMEOUT);
6bbd11
 	if (res < 0)
6bbd11
-		res = DEFAULT_LDAP_TIMEOUT;
6bbd11
+		res = atoi(DEFAULT_LDAP_TIMEOUT);
6bbd11
 
6bbd11
 	return res;
6bbd11
 }
6bbd11
@@ -644,20 +1028,20 @@ unsigned int defaults_get_ldap_network_timeout(void)
6bbd11
 {
6bbd11
 	int res;
6bbd11
 
6bbd11
-	res = get_env_number(ENV_LDAP_NETWORK_TIMEOUT);
6bbd11
+	res = conf_get_number(autofs_gbl_sec, NAME_LDAP_NETWORK_TIMEOUT);
6bbd11
 	if (res < 0)
6bbd11
-		res = DEFAULT_LDAP_NETWORK_TIMEOUT;
6bbd11
+		res = atoi(DEFAULT_LDAP_NETWORK_TIMEOUT);
6bbd11
 
6bbd11
 	return res;
6bbd11
 }
6bbd11
 
6bbd11
 unsigned int defaults_get_mount_nfs_default_proto(void)
6bbd11
 {
6bbd11
-	long proto;
6bbd11
+	int proto;
6bbd11
 
6bbd11
-	proto = get_env_number(ENV_MOUNT_NFS_DEFAULT_PROTOCOL);
6bbd11
+	proto = conf_get_number(autofs_gbl_sec, NAME_MOUNT_NFS_DEFAULT_PROTOCOL);
6bbd11
 	if (proto < 2 || proto > 4)
6bbd11
-		proto = DEFAULT_NFS_MOUNT_PROTOCOL;
6bbd11
+		proto = atoi(DEFAULT_MOUNT_NFS_DEFAULT_PROTOCOL);
6bbd11
 
6bbd11
 	return (unsigned int) proto;
6bbd11
 }
6bbd11
@@ -666,9 +1050,9 @@ unsigned int defaults_get_append_options(void)
6bbd11
 {
6bbd11
 	int res;
6bbd11
 
6bbd11
-	res = get_env_yesno(ENV_APPEND_OPTIONS);
6bbd11
+	res = conf_get_yesno(autofs_gbl_sec, NAME_APPEND_OPTIONS);
6bbd11
 	if (res < 0)
6bbd11
-		res = DEFAULT_APPEND_OPTIONS;
6bbd11
+		res = atoi(DEFAULT_APPEND_OPTIONS);
6bbd11
 
6bbd11
 	return res;
6bbd11
 }
6bbd11
@@ -677,9 +1061,9 @@ unsigned int defaults_get_mount_wait(void)
6bbd11
 {
6bbd11
 	long wait;
6bbd11
 
6bbd11
-	wait = get_env_number(ENV_MOUNT_WAIT);
6bbd11
+	wait = conf_get_number(autofs_gbl_sec, NAME_MOUNT_WAIT);
6bbd11
 	if (wait < 0)
6bbd11
-		wait = DEFAULT_MOUNT_WAIT;
6bbd11
+		wait = atoi(DEFAULT_MOUNT_WAIT);
6bbd11
 
6bbd11
 	return (unsigned int) wait;
6bbd11
 }
6bbd11
@@ -688,9 +1072,9 @@ unsigned int defaults_get_umount_wait(void)
6bbd11
 {
6bbd11
 	long wait;
6bbd11
 
6bbd11
-	wait = get_env_number(ENV_UMOUNT_WAIT);
6bbd11
+	wait = conf_get_number(autofs_gbl_sec, NAME_UMOUNT_WAIT);
6bbd11
 	if (wait < 0)
6bbd11
-		wait = DEFAULT_UMOUNT_WAIT;
6bbd11
+		wait = atoi(DEFAULT_UMOUNT_WAIT);
6bbd11
 
6bbd11
 	return (unsigned int) wait;
6bbd11
 }
6bbd11
@@ -699,7 +1083,7 @@ const char *defaults_get_auth_conf_file(void)
6bbd11
 {
6bbd11
 	char *cf;
6bbd11
 
6bbd11
-	cf = get_env_string(ENV_AUTH_CONF_FILE);
6bbd11
+	cf = conf_get_string(autofs_gbl_sec, NAME_AUTH_CONF_FILE);
6bbd11
 	if (!cf)
6bbd11
 		return strdup(default_auth_conf_file);
6bbd11
 
6bbd11
@@ -710,9 +1094,9 @@ unsigned int defaults_get_map_hash_table_size(void)
6bbd11
 {
6bbd11
 	long size;
6bbd11
 
6bbd11
-	size = get_env_number(ENV_MAP_HASH_TABLE_SIZE);
6bbd11
+	size = conf_get_number(autofs_gbl_sec, NAME_MAP_HASH_TABLE_SIZE);
6bbd11
 	if (size < 0)
6bbd11
-		size = DEFAULT_MAP_HASH_TABLE_SIZE;
6bbd11
+		size = atoi(DEFAULT_MAP_HASH_TABLE_SIZE);
6bbd11
 
6bbd11
 	return (unsigned int) size;
6bbd11
 }