Blame SOURCES/autofs-5.0.9-amd-lookup-fix-old-conf-handling.patch

6bbd11
autofs-5.0.9 - amd lookup fix old conf handling
6bbd11
6bbd11
From: Ian Kent <ikent@redhat.com>
6bbd11
6bbd11
When the configuration changed to using lower case option names
6bbd11
old configuration files with upper case names stopped working.
6bbd11
6bbd11
This is because, for configuration option lookup the hash of
6bbd11
the option string always needs to be the same case, which was
6bbd11
overlooked at the time.
6bbd11
6bbd11
Also fix a couple of other things, possible incorect return
6bbd11
from conf_update() what adding a new entry and change to using
6bbd11
isblank() instead of checking for a space only.
6bbd11
---
6bbd11
 lib/defaults.c |   27 +++++++++++++++++++++------
6bbd11
 1 file changed, 21 insertions(+), 6 deletions(-)
6bbd11
6bbd11
diff --git a/lib/defaults.c b/lib/defaults.c
6bbd11
index 3fa2216..7043dfc 100644
6bbd11
--- a/lib/defaults.c
6bbd11
+++ b/lib/defaults.c
6bbd11
@@ -43,6 +43,7 @@
6bbd11
 #define OLD_CONFIG_FILE			AUTOFS_CONF_DIR "/autofs"
6bbd11
 #define MAX_LINE_LEN			256
6bbd11
 #define MAX_SECTION_NAME		MAX_LINE_LEN
6bbd11
+#define MAX_CFG_NAME_LEN		31
6bbd11
 
6bbd11
 #define NAME_MASTER_MAP			"master_map_name"
6bbd11
 
6bbd11
@@ -661,7 +662,7 @@ static int conf_update(const char *section,
6bbd11
 	ret = CFG_FAIL;
6bbd11
 	co = conf_lookup(section, key);
6bbd11
 	if (!co)
6bbd11
-		ret = conf_add(section, key, value, flags);
6bbd11
+		return conf_add(section, key, value, flags);
6bbd11
 	else {
6bbd11
 		char *val = NULL, *tmp = NULL;
6bbd11
 		/* Environment overrides file value */
6bbd11
@@ -691,15 +692,29 @@ error:
6bbd11
 	return ret;
6bbd11
 }
6bbd11
 
6bbd11
+static u_int32_t get_hash(const char *key, unsigned int size)
6bbd11
+{
6bbd11
+	const char *pkey = key;
6bbd11
+	char lkey[MAX_CFG_NAME_LEN];
6bbd11
+	char *plkey = &lkey[0];
6bbd11
+
6bbd11
+	while (*pkey)
6bbd11
+		*plkey++ = tolower(*pkey++);
6bbd11
+	*plkey = '\0';
6bbd11
+	return hash(lkey, size);
6bbd11
+}
6bbd11
+
6bbd11
 static struct conf_option *conf_lookup(const char *section, const char *key)
6bbd11
 {
6bbd11
 	struct conf_option *co;
6bbd11
+	u_int32_t key_hash;
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
+	key_hash = get_hash(key, size);
6bbd11
+	for (co = config->hash[key_hash]; co != NULL; co = co->next) {
6bbd11
 		if (strcasecmp(section, co->section))
6bbd11
 			continue;
6bbd11
 		if (!strcasecmp(key, co->name))
6bbd11
@@ -772,7 +787,7 @@ static int parse_line(char *line, char **sec, char **res, char **value)
6bbd11
 	if (*key == '#' || (*key != '[' && !isalpha(*key)))
6bbd11
 		return 0;
6bbd11
 
6bbd11
-	while (*key && *key == ' ')
6bbd11
+	while (*key && isblank(*key))
6bbd11
 		key++;
6bbd11
 
6bbd11
 	if (!*key)
6bbd11
@@ -780,13 +795,13 @@ static int parse_line(char *line, char **sec, char **res, char **value)
6bbd11
 
6bbd11
 	if (*key == '[') {
6bbd11
 		char *tmp;
6bbd11
-		while (*key && (*key == '[' || *key == ' '))
6bbd11
+		while (*key && (*key == '[' || isblank(*key)))
6bbd11
 			key++;
6bbd11
 		tmp = strchr(key, ']');
6bbd11
 		if (!tmp)
6bbd11
 			return 0;
6bbd11
 		*tmp = ' ';
6bbd11
-		while (*tmp && *tmp == ' ') {
6bbd11
+		while (*tmp && isblank(*tmp)) {
6bbd11
 			*tmp = '\0';
6bbd11
 			tmp--;
6bbd11
 		}
6bbd11
@@ -803,7 +818,7 @@ static int parse_line(char *line, char **sec, char **res, char **value)
6bbd11
 
6bbd11
 	*val++ = '\0';
6bbd11
 
6bbd11
-	while (*(--tmp) == ' ')
6bbd11
+	while (isblank(*(--tmp)))
6bbd11
 		*tmp = '\0';
6bbd11
 
6bbd11
 	while (*val && (*val == '"' || isblank(*val)))