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

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