Blame SOURCES/autofs-5.1.3-fix-amd-defaults-map-entry-handling.patch

cef8f8
autofs-5.1.3 - fix amd defaults map entry handling
cef8f8
cef8f8
From: Ian Kent <raven@themaw.net>
cef8f8
cef8f8
When parsing an amd map entry the map entry defaults were not being
cef8f8
handled properly.
cef8f8
cef8f8
A "-" in the map entry requires a reset to defaults, which wasn't being
cef8f8
done.
cef8f8
cef8f8
A "-<map options>" in the map entry requires merging the <map options>
cef8f8
with the current defaults map entry, which was also not being done
cef8f8
properly.
cef8f8
cef8f8
Signed-off-by: Ian Kent <raven@themaw.net>
cef8f8
---
cef8f8
 CHANGELOG           |    1 
cef8f8
 modules/parse_amd.c |  109 +++++++++++++++++++++++++++++++++-------------------
cef8f8
 2 files changed, 72 insertions(+), 38 deletions(-)
cef8f8
cef8f8
--- autofs-5.0.7.orig/CHANGELOG
cef8f8
+++ autofs-5.0.7/CHANGELOG
cef8f8
@@ -272,6 +272,7 @@
cef8f8
 - add missing MODPREFIX to logging in amd parser.
cef8f8
 - fix symlink false negative in umount_multi().
cef8f8
 - remove expand_selectors() on amd parser entry.
cef8f8
+- fix amd defaults map entry handling.
cef8f8
 
cef8f8
 25/07/2012 autofs-5.0.7
cef8f8
 =======================
cef8f8
--- autofs-5.0.7.orig/modules/parse_amd.c
cef8f8
+++ autofs-5.0.7/modules/parse_amd.c
cef8f8
@@ -1832,45 +1832,24 @@ out:
cef8f8
 	return make_default_entry(ap, sv);
cef8f8
 }
cef8f8
 
cef8f8
-int parse_mount(struct autofs_point *ap, const char *name,
cef8f8
-		int name_len, const char *mapent, void *context)
cef8f8
+static struct amd_entry *setup_defaults(struct autofs_point *ap,
cef8f8
+					const char *name, int name_len,
cef8f8
+					struct map_source *source,
cef8f8
+					struct substvar **sv)
cef8f8
 {
cef8f8
-	struct parse_context *ctxt = (struct parse_context *) context;
cef8f8
-	unsigned int flags = conf_amd_get_flags(ap->path);
cef8f8
-	struct substvar *sv = NULL;
cef8f8
-	struct map_source *source;
cef8f8
+	struct amd_entry *defaults_entry;
cef8f8
 	struct mapent_cache *mc;
cef8f8
 	struct mapent *me;
cef8f8
-	unsigned int at_least_one;
cef8f8
-	struct list_head entries, *p, *head;
cef8f8
-	struct amd_entry *defaults_entry;
cef8f8
-	struct amd_entry *cur_defaults;
cef8f8
+	struct substvar *nsv;
cef8f8
 	char *defaults;
cef8f8
-	int len, rv = 1;
cef8f8
-	int cur_state;
cef8f8
-	int ret;
cef8f8
-
cef8f8
-	source = ap->entry->current;
cef8f8
-	ap->entry->current = NULL;
cef8f8
-	master_source_current_signal(ap->entry);
cef8f8
 
cef8f8
 	mc = source->mc;
cef8f8
+	defaults = NULL;
cef8f8
+	defaults_entry = NULL;
cef8f8
 
cef8f8
-	if (!mapent) {
cef8f8
-		warn(ap->logopt, MODPREFIX "error: empty map entry");
cef8f8
-		return 1;
cef8f8
-	}
cef8f8
-
cef8f8
-	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
cef8f8
-
cef8f8
-	sv = add_lookup_vars(ap, name, name_len, source, sv);
cef8f8
-	if (!sv) {
cef8f8
-		macro_free_table(sv);
cef8f8
-		pthread_setcancelstate(cur_state, NULL);
cef8f8
-		return 1;
cef8f8
-	}
cef8f8
-
cef8f8
-	pthread_setcancelstate(cur_state, NULL);
cef8f8
+	nsv = add_lookup_vars(ap, name, name_len, source, NULL);
cef8f8
+	if (!nsv)
cef8f8
+		goto done;
cef8f8
 
cef8f8
 	defaults = conf_amd_get_map_defaults(ap->path);
cef8f8
 	if (defaults) {
cef8f8
@@ -1885,22 +1864,63 @@ int parse_mount(struct autofs_point *ap,
cef8f8
 			char buf[MAX_ERR_BUF];
cef8f8
 			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
cef8f8
 			error(ap->logopt, MODPREFIX "malloc: %s", estr);
cef8f8
+			macro_free_table(nsv);
cef8f8
+			nsv = NULL;
cef8f8
+			goto done;
cef8f8
 		}
cef8f8
 	}
cef8f8
 
cef8f8
-	defaults_entry = get_defaults_entry(ap, defaults, sv);
cef8f8
+	defaults_entry = get_defaults_entry(ap, defaults, nsv);
cef8f8
 	if (!defaults_entry) {
cef8f8
 		error(ap->logopt, MODPREFIX "failed to get a defaults entry");
cef8f8
-		if (defaults)
cef8f8
-			free(defaults);
cef8f8
-		macro_free_table(sv);
cef8f8
-		return 1;
cef8f8
+		macro_free_table(nsv);
cef8f8
+		nsv = NULL;
cef8f8
 	}
cef8f8
+done:
cef8f8
 	if (defaults)
cef8f8
 		free(defaults);
cef8f8
+	if (*sv)
cef8f8
+		macro_free_table(*sv);
cef8f8
+	*sv = nsv;
cef8f8
+
cef8f8
+	return defaults_entry;
cef8f8
+}
cef8f8
+
cef8f8
+int parse_mount(struct autofs_point *ap, const char *name,
cef8f8
+		int name_len, const char *mapent, void *context)
cef8f8
+{
cef8f8
+	struct parse_context *ctxt = (struct parse_context *) context;
cef8f8
+	unsigned int flags = conf_amd_get_flags(ap->path);
cef8f8
+	struct substvar *sv = NULL;
cef8f8
+	struct map_source *source;
cef8f8
+	unsigned int at_least_one;
cef8f8
+	struct list_head entries, *p, *head;
cef8f8
+	struct amd_entry *defaults_entry;
cef8f8
+	struct amd_entry *cur_defaults;
cef8f8
+	int rv = 1;
cef8f8
+	int cur_state;
cef8f8
+	int ret;
cef8f8
+
cef8f8
+	source = ap->entry->current;
cef8f8
+	ap->entry->current = NULL;
cef8f8
+	master_source_current_signal(ap->entry);
cef8f8
+
cef8f8
+	if (!mapent) {
cef8f8
+		warn(ap->logopt, MODPREFIX "error: empty map entry");
cef8f8
+		return 1;
cef8f8
+	}
cef8f8
 
cef8f8
 	INIT_LIST_HEAD(&entries);
cef8f8
 
cef8f8
+	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
cef8f8
+
cef8f8
+	defaults_entry = setup_defaults(ap, name, name_len, source, &sv;;
cef8f8
+	if (!defaults_entry) {
cef8f8
+		error(ap->logopt, MODPREFIX
cef8f8
+		      "failed to setup defaults entry");
cef8f8
+		goto done;
cef8f8
+	}
cef8f8
+
cef8f8
 	ret = amd_parse_list(ap, mapent, &entries, &sv;;
cef8f8
 	if (ret) {
cef8f8
 		error(ap->logopt,
cef8f8
@@ -1931,9 +1951,20 @@ int parse_mount(struct autofs_point *ap,
cef8f8
 			free_amd_entry(cur_defaults);
cef8f8
 			list_del_init(&this->list);
cef8f8
 			cur_defaults = this;
cef8f8
+			update_with_defaults(defaults_entry, cur_defaults, sv);
cef8f8
 			continue;
cef8f8
 		} else if (this->flags & AMD_DEFAULTS_RESET) {
cef8f8
-			struct amd_entry *new;
cef8f8
+			struct amd_entry *nd, *new;
cef8f8
+			struct substvar *nsv = NULL;
cef8f8
+
cef8f8
+			nd = setup_defaults(ap, name, name_len, source, &nsv;;
cef8f8
+			if (nd) {
cef8f8
+				free_amd_entry(defaults_entry);
cef8f8
+				defaults_entry = nd;
cef8f8
+				macro_free_table(sv);
cef8f8
+				sv = nsv;
cef8f8
+			}
cef8f8
+
cef8f8
 			new = dup_defaults_entry(defaults_entry);
cef8f8
 			if (new) {
cef8f8
 				free_amd_entry(cur_defaults);
cef8f8
@@ -1999,6 +2030,8 @@ done:
cef8f8
 	free_amd_entry(defaults_entry);
cef8f8
 	macro_free_table(sv);
cef8f8
 
cef8f8
+	pthread_setcancelstate(cur_state, NULL);
cef8f8
+
cef8f8
 	return rv;
cef8f8
 }
cef8f8