Blame SOURCES/autofs-5.0.8-fix-map-source-with-type-lookup.patch

306fa1
autofs-5.0.8 - fix map source with type lookup
306fa1
306fa1
From: Ian Kent <raven@themaw.net>
306fa1
306fa1
If the map source type is specified the map name must be a full
306fa1
path.
306fa1
306fa1
But we should be able to give a plain map name and expect autofs
306fa1
to look in the compiled in maps directory.
306fa1
---
306fa1
 CHANGELOG       |    1 
306fa1
 daemon/lookup.c |  111 +++++++++++++++++++++++++++++++++++++++++++++++++-------
306fa1
 2 files changed, 99 insertions(+), 13 deletions(-)
306fa1
306fa1
--- autofs-5.0.7.orig/CHANGELOG
306fa1
+++ autofs-5.0.7/CHANGELOG
306fa1
@@ -94,6 +94,7 @@
306fa1
 - add negative cache lookup to hesiod lookup.
306fa1
 - fix external env configure.
306fa1
 - make autofs(5) consistent with auto.master(5).
306fa1
+- fix map source with type lookup.
306fa1
 
306fa1
 25/07/2012 autofs-5.0.7
306fa1
 =======================
306fa1
--- autofs-5.0.7.orig/daemon/lookup.c
306fa1
+++ autofs-5.0.7/daemon/lookup.c
306fa1
@@ -100,6 +100,27 @@ static int do_read_master(struct master
306fa1
 	return status;
306fa1
 }
306fa1
 
306fa1
+static char *find_map_path(struct map_source *map)
306fa1
+{
306fa1
+	struct stat st;
306fa1
+	char *path;
306fa1
+
306fa1
+	path = malloc(strlen(AUTOFS_MAP_DIR) + strlen(map->argv[0]) + 2);
306fa1
+	if (!path)
306fa1
+		return NULL;
306fa1
+
306fa1
+	strcpy(path, AUTOFS_MAP_DIR);
306fa1
+	strcat(path, "/");
306fa1
+	strcat(path, map->argv[0]);
306fa1
+
306fa1
+	if (!stat(path, &st))
306fa1
+		return path;
306fa1
+
306fa1
+	free(path);
306fa1
+
306fa1
+	return NULL;
306fa1
+}
306fa1
+
306fa1
 static int read_master_map(struct master *master, char *type, time_t age)
306fa1
 {
306fa1
 	unsigned int logopt = master->logopt;
306fa1
@@ -392,6 +413,42 @@ static void argv_cleanup(void *arg)
306fa1
 	return;
306fa1
 }
306fa1
 
306fa1
+static int lookup_map_read_map(struct autofs_point *ap,
306fa1
+			       struct map_source *map, time_t age)
306fa1
+{
306fa1
+	char *path;
306fa1
+
306fa1
+	if (!map->argv[0])
306fa1
+		return NSS_STATUS_UNKNOWN;
306fa1
+
306fa1
+	/*
306fa1
+	 * This is only called when map->type != NULL.
306fa1
+	 * We only need to look for a map if source type is
306fa1
+	 * file and the map name doesn't begin with a "/".
306fa1
+	 */
306fa1
+	if (strncmp(map->type, "file", 4))
306fa1
+		return do_read_map(ap, map, age);
306fa1
+
306fa1
+	if (map->argv[0][0] == '/')
306fa1
+		return do_read_map(ap, map, age);
306fa1
+
306fa1
+	path = find_map_path(map);
306fa1
+	if (!path)
306fa1
+		return NSS_STATUS_UNKNOWN;
306fa1
+
306fa1
+	if (map->argc >= 1) {
306fa1
+		if (map->argv[0])
306fa1
+			free((char *) map->argv[0]);
306fa1
+		map->argv[0] = path;
306fa1
+	} else {
306fa1
+		error(ap->logopt, "invalid arguments for autofs_point");
306fa1
+		free(path);
306fa1
+		return NSS_STATUS_UNKNOWN;
306fa1
+	}
306fa1
+
306fa1
+	return do_read_map(ap, map, age);
306fa1
+}
306fa1
+
306fa1
 static enum nsswitch_status read_map_source(struct nss_source *this,
306fa1
 		struct autofs_point *ap, struct map_source *map, time_t age)
306fa1
 {
306fa1
@@ -428,14 +485,10 @@ static enum nsswitch_status read_map_sou
306fa1
 	tmap.argc = 0;
306fa1
 	tmap.argv = NULL;
306fa1
 
306fa1
-	path = malloc(strlen(AUTOFS_MAP_DIR) + strlen(map->argv[0]) + 2);
306fa1
+	path = find_map_path(map);
306fa1
 	if (!path)
306fa1
 		return NSS_STATUS_UNKNOWN;
306fa1
 
306fa1
-	strcpy(path, AUTOFS_MAP_DIR);
306fa1
-	strcat(path, "/");
306fa1
-	strcat(path, map->argv[0]);
306fa1
-
306fa1
 	if (map->argc >= 1) {
306fa1
 		tmap.argc = map->argc;
306fa1
 		tmap.argv = copy_argv(map->argc, map->argv);
306fa1
@@ -496,7 +549,7 @@ int lookup_nss_read_map(struct autofs_po
306fa1
 				debug(ap->logopt,
306fa1
 				      "reading map %s %s",
306fa1
 				       map->type, map->argv[0]);
306fa1
-			result = do_read_map(ap, map, age);
306fa1
+			result = lookup_map_read_map(ap, map, age);
306fa1
 			map = map->next;
306fa1
 			continue;
306fa1
 		}
306fa1
@@ -758,6 +811,43 @@ static int lookup_name_source_instance(s
306fa1
 	return do_lookup_mount(ap, instance, name, name_len);
306fa1
 }
306fa1
 
306fa1
+static int do_name_lookup_mount(struct autofs_point *ap,
306fa1
+				struct map_source *map,
306fa1
+				const char *name, int name_len)
306fa1
+{
306fa1
+	char *path;
306fa1
+
306fa1
+	if (!map->argv[0])
306fa1
+		return NSS_STATUS_UNKNOWN;
306fa1
+
306fa1
+	/*
306fa1
+	 * This is only called when map->type != NULL.
306fa1
+	 * We only need to look for a map if source type is
306fa1
+	 * file and the map name doesn't begin with a "/".
306fa1
+	 */
306fa1
+	if (strncmp(map->type, "file", 4))
306fa1
+		return do_lookup_mount(ap, map, name, name_len);
306fa1
+
306fa1
+	if (map->argv[0][0] == '/')
306fa1
+		return do_lookup_mount(ap, map, name, name_len);
306fa1
+
306fa1
+	path = find_map_path(map);
306fa1
+	if (!path)
306fa1
+		return NSS_STATUS_UNKNOWN;
306fa1
+
306fa1
+	if (map->argc >= 1) {
306fa1
+		if (map->argv[0])
306fa1
+			free((char *) map->argv[0]);
306fa1
+		map->argv[0] = path;
306fa1
+	} else {
306fa1
+		error(ap->logopt, "invalid arguments for autofs_point");
306fa1
+		free(path);
306fa1
+		return NSS_STATUS_UNKNOWN;
306fa1
+	}
306fa1
+
306fa1
+	return do_lookup_mount(ap, map, name, name_len);
306fa1
+}
306fa1
+
306fa1
 static enum nsswitch_status lookup_map_name(struct nss_source *this,
306fa1
 			struct autofs_point *ap, struct map_source *map,
306fa1
 			const char *name, int name_len)
306fa1
@@ -793,14 +883,10 @@ static enum nsswitch_status lookup_map_n
306fa1
 	tmap.argc = 0;
306fa1
 	tmap.argv = NULL;
306fa1
 
306fa1
-	path = malloc(strlen(AUTOFS_MAP_DIR) + strlen(map->argv[0]) + 2);
306fa1
+	path = find_map_path(map);
306fa1
 	if (!path)
306fa1
 		return NSS_STATUS_UNKNOWN;
306fa1
 
306fa1
-	strcpy(path, AUTOFS_MAP_DIR);
306fa1
-	strcat(path, "/");
306fa1
-	strcat(path, map->argv[0]);
306fa1
-
306fa1
 	if (map->argc >= 1) {
306fa1
 		tmap.argc = map->argc;
306fa1
 		tmap.argv = copy_argv(map->argc, map->argv);
306fa1
@@ -909,8 +995,7 @@ int lookup_nss_mount(struct autofs_point
306fa1
 		sched_yield();
306fa1
 
306fa1
 		if (map->type) {
306fa1
-			result = do_lookup_mount(ap, map, name, name_len);
306fa1
-
306fa1
+			result = do_name_lookup_mount(ap, map, name, name_len);
306fa1
 			if (result == NSS_STATUS_SUCCESS)
306fa1
 				break;
306fa1