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

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