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

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