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

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