Blame SOURCES/autofs-5.0.9-amd-lookup-fix-host-mount-lookup.patch

304803
autofs-5.0.9 - amd lookup fix host mount lookup
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
The amd host mount type is implemented by using the autofs internal
304803
hosts map module and the autofs sun parser.
304803
304803
When using the amd mount type host we need to avoid calling back
304803
into the lookup module of the amd map (as an amd format lookup)
304803
since the lookup keys for mounts in the tree might not match
304803
correctly.  In any case it's a call into a lookup module that
304803
isn't needed.
304803
---
304803
 daemon/lookup.c     |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
304803
 modules/parse_amd.c |   34 +++++++++++++++++++++++----
304803
 2 files changed, 94 insertions(+), 5 deletions(-)
304803
304803
--- autofs-5.0.7.orig/daemon/lookup.c
304803
+++ autofs-5.0.7/daemon/lookup.c
304803
@@ -795,6 +795,62 @@ int do_lookup_mount(struct autofs_point
304803
 	return status;
304803
 }
304803
 
304803
+static int lookup_amd_instance(struct autofs_point *ap,
304803
+			       struct map_source *map,
304803
+			       const char *name, int name_len)
304803
+{
304803
+	struct map_source *instance;
304803
+	struct amd_entry *entry;
304803
+	const char *argv[2];
304803
+	const char **pargv = NULL;
304803
+	int argc = 0;
304803
+	struct mapent *me;
304803
+	char *m_key;
304803
+
304803
+	me = cache_lookup_distinct(map->mc, name);
304803
+	if (!me || !me->multi) {
304803
+		error(ap->logopt, "expected multi mount entry not found");
304803
+		return NSS_STATUS_UNKNOWN;
304803
+	}
304803
+
304803
+	m_key = malloc(strlen(ap->path) + strlen(me->multi->key) + 1);
304803
+	if (!m_key) {
304803
+		error(ap->logopt, "failed to allocate storage for search key");
304803
+		return NSS_STATUS_UNKNOWN;
304803
+	}
304803
+
304803
+	strcpy(m_key, ap->path);
304803
+	strcat(m_key, "/");
304803
+	strcat(m_key, me->multi->key);
304803
+	entry = master_find_amdmount(ap, m_key);
304803
+	if (!entry) {
304803
+		error(ap->logopt, "expected amd mount entry not found");
304803
+		free(m_key);
304803
+		return NSS_STATUS_UNKNOWN;
304803
+	}
304803
+	free(m_key);
304803
+
304803
+	if (strcmp(entry->type, "host")) {
304803
+		error(ap->logopt, "unexpected map type %s", entry->type);
304803
+		return NSS_STATUS_UNKNOWN;
304803
+	}
304803
+
304803
+	if (entry->opts) {
304803
+		argv[0] = entry->opts;
304803
+		argv[1] = NULL;
304803
+		pargv = argv;
304803
+		argc = 1;
304803
+	}
304803
+
304803
+	instance = master_find_source_instance(map, "hosts", "sun", argc, pargv);
304803
+	if (!instance) {
304803
+		error(ap->logopt, "expected hosts map instance not found");
304803
+		return NSS_STATUS_UNKNOWN;
304803
+	}
304803
+
304803
+	return do_lookup_mount(ap, instance, name, name_len);
304803
+}
304803
+
304803
 static int lookup_name_file_source_instance(struct autofs_point *ap, struct map_source *map, const char *name, int name_len)
304803
 {
304803
 	struct map_source *instance;
304803
@@ -804,6 +860,9 @@ static int lookup_name_file_source_insta
304803
 	struct stat st;
304803
 	char *type, *format;
304803
 
304803
+	if (*name == '/' && map->flags & MAP_FLAG_FORMAT_AMD)
304803
+		return lookup_amd_instance(ap, map, name, name_len);
304803
+
304803
 	if (stat(map->argv[0], &st) == -1) {
304803
 		debug(ap->logopt, "file map not found");
304803
 		return NSS_STATUS_NOTFOUND;
304803
@@ -839,6 +898,9 @@ static int lookup_name_source_instance(s
304803
 	const char *format;
304803
 	time_t age = time(NULL);
304803
 
304803
+	if (*name == '/' && map->flags & MAP_FLAG_FORMAT_AMD)
304803
+		return lookup_amd_instance(ap, map, name, name_len);
304803
+
304803
 	format = map->format;
304803
 
304803
 	instance = master_find_source_instance(map, type, format, 0, NULL);
304803
@@ -867,6 +929,9 @@ static int do_name_lookup_mount(struct a
304803
 		return NSS_STATUS_UNKNOWN;
304803
 	}
304803
 
304803
+	if (*name == '/' && map->flags & MAP_FLAG_FORMAT_AMD)
304803
+		return lookup_amd_instance(ap, map, name, name_len);
304803
+
304803
 	/*
304803
 	 * This is only called when map->type != NULL.
304803
 	 * We only need to look for a map if source type is
304803
--- autofs-5.0.7.orig/modules/parse_amd.c
304803
+++ autofs-5.0.7/modules/parse_amd.c
304803
@@ -1073,29 +1073,53 @@ static int do_host_mount(struct autofs_p
304803
 			 unsigned int flags)
304803
 {
304803
 	struct lookup_mod *lookup;
304803
+	struct map_source *instance;
304803
 	struct mapent *me;
304803
 	const char *argv[2];
304803
+	const char **pargv = NULL;
304803
+	int argc = 0;
304803
 	int ret = 1;
304803
 
304803
-	argv[0] = entry->opts;
304803
-	argv[1] = NULL;
304803
+	if (entry->opts) {
304803
+		argv[0] = entry->opts;
304803
+		argv[1] = NULL;
304803
+		pargv = argv;
304803
+		argc = 1;
304803
+	}
304803
 
304803
-	lookup = open_lookup("hosts", MODPREFIX, NULL, 1, argv);
304803
+	instance_mutex_lock();
304803
+	lookup = open_lookup("hosts", MODPREFIX, NULL, argc, pargv);
304803
 	if (!lookup) {
304803
 		debug(ap->logopt, "open lookup module hosts failed");
304803
+		instance_mutex_unlock();
304803
 		goto out;
304803
 	}
304803
 
304803
+	instance = master_find_source_instance(source, "hosts", "sun", argc, pargv);
304803
+	if (!instance) {
304803
+		instance = master_add_source_instance(source,
304803
+				 "hosts", "sun", time(NULL), argc, pargv);
304803
+		if (!instance) {
304803
+			error(ap->logopt, MODPREFIX
304803
+			     "failed to create source instance for hosts map");
304803
+			instance_mutex_unlock();
304803
+			close_lookup(lookup);
304803
+			goto out;
304803
+		}
304803
+	}
304803
+	instance->lookup = lookup;
304803
+	instance_mutex_unlock();
304803
+
304803
+	cache_writelock(source->mc);
304803
 	me = cache_lookup_distinct(source->mc, name);
304803
 	if (me)
304803
 		cache_push_mapent(me, NULL);
304803
+	cache_unlock(source->mc);
304803
 
304803
 	master_source_current_wait(ap->entry);
304803
 	ap->entry->current = source;
304803
 
304803
 	ret = lookup->lookup_mount(ap, name, strlen(name), lookup->context);
304803
-
304803
-	close_lookup(lookup);
304803
 out:
304803
 	return ret;
304803
 }