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

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