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

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