Blame SOURCES/autofs-5.1.0-beta1-fix-hash-on-config-option-add-and-delete.patch

304803
autofs-5.1.0-beta1 - fix hash on confg option add and delete
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
The hash calculation needs to be the same for upper and lower case config
304803
options. The config entry add and delete functions weren't doing that.
304803
---
304803
 CHANGELOG      |    1 +
304803
 lib/defaults.c |   40 ++++++++++++++++++++++------------------
304803
 2 files changed, 23 insertions(+), 18 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -120,6 +120,7 @@
304803
 - fix expire when server not responding.
304803
 - fix ldap_uri config update.
304803
 - fix typo in conf_load_autofs_defaults().
304803
+- fix hash on confg option add and delete.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/lib/defaults.c
304803
+++ autofs-5.0.7/lib/defaults.c
304803
@@ -524,12 +524,24 @@ error:
304803
 	return 0;
304803
 }
304803
 
304803
+static u_int32_t get_hash(const char *key, unsigned int size)
304803
+{
304803
+	const char *pkey = key;
304803
+	char lkey[PATH_MAX + 1];
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 int conf_add(const char *section, const char *key, const char *value, unsigned long flags)
304803
 {
304803
 	struct conf_option *co;
304803
 	char *sec, *name, *val, *tmp;
304803
 	unsigned int size = CFG_TABLE_SIZE;
304803
-	u_int32_t index;
304803
+	u_int32_t key_hash;
304803
 	int ret = CFG_FAIL;
304803
 
304803
 	sec = name = val = tmp = NULL;
304803
@@ -568,12 +580,12 @@ static int conf_add(const char *section,
304803
 	if (flags & CONF_ENV && value)
304803
 		setenv(name, value, 0);
304803
 
304803
-	index = hash(key, size);
304803
-	if (!config->hash[index])
304803
-		config->hash[index] = co;
304803
+	key_hash = get_hash(key, size);
304803
+	if (!config->hash[key_hash])
304803
+		config->hash[key_hash] = co;
304803
 	else {
304803
 		struct conf_option *last = NULL, *next;
304803
-		next = config->hash[index];
304803
+		next = config->hash[key_hash];
304803
 		while (next) {
304803
 			last = next;
304803
 			next = last->next;
304803
@@ -598,9 +610,11 @@ static void conf_delete(const char *sect
304803
 {
304803
 	struct conf_option *co, *last;
304803
 	unsigned int size = CFG_TABLE_SIZE;
304803
+	u_int32_t key_hash;
304803
 
304803
 	last = NULL;
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
@@ -613,6 +627,8 @@ static void conf_delete(const char *sect
304803
 
304803
 	if (last)
304803
 		last->next = co->next;
304803
+	else
304803
+		config->hash[key_hash] = co->next;
304803
 
304803
 	free(co->section);
304803
 	free(co->name);
304803
@@ -661,18 +677,6 @@ 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[PATH_MAX + 1];
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_key(const char *section, const char *key)
304803
 {
304803
 	struct conf_option *co;