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

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