Blame SOURCES/autofs-5.0.9-amd-lookup-add-search_path-handling.patch

6bbd11
autofs-5.0.9 - amd lookup add search_path handling
6bbd11
6bbd11
From: Ian Kent <raven@themaw.net>
6bbd11
6bbd11
6bbd11
---
6bbd11
 daemon/lookup.c                |   75 +++++++++++++++++++++++++++++++----------
6bbd11
 include/master.h               |    1 
6bbd11
 lib/master.c                   |    6 +++
6bbd11
 man/autofs.conf.5.in           |    5 ++
6bbd11
 modules/parse_amd.c            |    4 +-
6bbd11
 redhat/autofs.conf.default.in  |    9 +---
6bbd11
 samples/autofs.conf.default.in |    9 +---
6bbd11
 7 files changed, 79 insertions(+), 30 deletions(-)
6bbd11
6bbd11
--- autofs-5.0.7.orig/daemon/lookup.c
6bbd11
+++ autofs-5.0.7/daemon/lookup.c
6bbd11
@@ -100,25 +100,64 @@ static int do_read_master(struct master
6bbd11
 	return status;
6bbd11
 }
6bbd11
 
6bbd11
-static char *find_map_path(struct map_source *map)
6bbd11
+static char *find_map_path(struct autofs_point *ap, struct map_source *map)
6bbd11
 {
6bbd11
+	const char *mname = map->argv[0];
6bbd11
+	unsigned int mlen = strlen(mname);
6bbd11
+	char *tok, *ptr = NULL;
6bbd11
+	char *path = NULL;
6bbd11
+	char *search_path;
6bbd11
 	struct stat st;
6bbd11
-	char *path;
6bbd11
 
6bbd11
-	path = malloc(strlen(AUTOFS_MAP_DIR) + strlen(map->argv[0]) + 2);
6bbd11
-	if (!path)
6bbd11
+	/*
6bbd11
+	 * This is different to the way it is in amd.
6bbd11
+	 * autofs will always try to locate maps in AUTOFS_MAP_DIR
6bbd11
+	 * but amd has no default and will not find a file map that
6bbd11
+	 * isn't a full path when no search_path is configured, either
6bbd11
+	 * in the mount point or global configuration.
6bbd11
+	 */
6bbd11
+	search_path = strdup(AUTOFS_MAP_DIR);
6bbd11
+	if (map->flags & MAP_FLAG_FORMAT_AMD) {
6bbd11
+		struct autofs_point *pap = ap;
6bbd11
+		char *tmp;
6bbd11
+		/*
6bbd11
+		 * Make sure we get search_path from the root of the
6bbd11
+		 * mount tree, if one is present in the configuration.
6bbd11
+		 * Again different from amd, which ignores the submount
6bbd11
+		 * case.
6bbd11
+		 */
6bbd11
+		while (pap->parent)
6bbd11
+			pap = pap->parent;
6bbd11
+		tmp = conf_amd_get_search_path(pap->path);
6bbd11
+		if (tmp) {
6bbd11
+			if (search_path)
6bbd11
+				free(search_path);
6bbd11
+			search_path = tmp;
6bbd11
+		}
6bbd11
+	}
6bbd11
+	if (!search_path)
6bbd11
 		return NULL;
6bbd11
 
6bbd11
-	strcpy(path, AUTOFS_MAP_DIR);
6bbd11
-	strcat(path, "/");
6bbd11
-	strcat(path, map->argv[0]);
6bbd11
-
6bbd11
-	if (!stat(path, &st))
6bbd11
-		return path;
6bbd11
-
6bbd11
-	free(path);
6bbd11
+	tok = strtok_r(search_path, ":", &ptr);
6bbd11
+	while (tok) {
6bbd11
+		char *this = malloc(strlen(tok) + mlen + 2);
6bbd11
+		if (!this) {
6bbd11
+			free(search_path);
6bbd11
+			return NULL;
6bbd11
+		}
6bbd11
+		strcpy(this, tok);
6bbd11
+		strcat(this, "/");
6bbd11
+		strcat(this, mname);
6bbd11
+		if (!stat(this, &st)) {
6bbd11
+			path = this;
6bbd11
+			break;
6bbd11
+		}
6bbd11
+		free(this);
6bbd11
+		tok = strtok_r(NULL, ":", &ptr);
6bbd11
+	}
6bbd11
 
6bbd11
-	return NULL;
6bbd11
+	free(search_path);
6bbd11
+	return path;
6bbd11
 }
6bbd11
 
6bbd11
 static int read_master_map(struct master *master, char *type, time_t age)
6bbd11
@@ -435,7 +474,7 @@ static int lookup_map_read_map(struct au
6bbd11
 	if (map->argv[0][0] == '/')
6bbd11
 		return do_read_map(ap, map, age);
6bbd11
 
6bbd11
-	path = find_map_path(map);
6bbd11
+	path = find_map_path(ap, map);
6bbd11
 	if (!path)
6bbd11
 		return NSS_STATUS_UNKNOWN;
6bbd11
 
6bbd11
@@ -479,6 +518,7 @@ static enum nsswitch_status read_map_sou
6bbd11
 	tmap.flags = map->flags;
6bbd11
 	tmap.type = this->source;
6bbd11
 	tmap.format = map->format;
6bbd11
+	tmap.name = map->name;
6bbd11
 	tmap.lookup = map->lookup;
6bbd11
 	tmap.mc = map->mc;
6bbd11
 	tmap.instance = map->instance;
6bbd11
@@ -489,7 +529,7 @@ static enum nsswitch_status read_map_sou
6bbd11
 	tmap.argc = 0;
6bbd11
 	tmap.argv = NULL;
6bbd11
 
6bbd11
-	path = find_map_path(map);
6bbd11
+	path = find_map_path(ap, map);
6bbd11
 	if (!path)
6bbd11
 		return NSS_STATUS_UNKNOWN;
6bbd11
 
6bbd11
@@ -838,7 +878,7 @@ static int do_name_lookup_mount(struct a
6bbd11
 	if (map->argv[0][0] == '/')
6bbd11
 		return do_lookup_mount(ap, map, name, name_len);
6bbd11
 
6bbd11
-	path = find_map_path(map);
6bbd11
+	path = find_map_path(ap, map);
6bbd11
 	if (!path)
6bbd11
 		return NSS_STATUS_UNKNOWN;
6bbd11
 
6bbd11
@@ -883,6 +923,7 @@ static enum nsswitch_status lookup_map_n
6bbd11
 	tmap.flags = map->flags;
6bbd11
 	tmap.type = this->source;
6bbd11
 	tmap.format = map->format;
6bbd11
+	tmap.name = map->name;
6bbd11
 	tmap.mc = map->mc;
6bbd11
 	tmap.instance = map->instance;
6bbd11
 	tmap.exp_timeout = map->exp_timeout;
6bbd11
@@ -891,7 +932,7 @@ static enum nsswitch_status lookup_map_n
6bbd11
 	tmap.argc = 0;
6bbd11
 	tmap.argv = NULL;
6bbd11
 
6bbd11
-	path = find_map_path(map);
6bbd11
+	path = find_map_path(ap, map);
6bbd11
 	if (!path)
6bbd11
 		return NSS_STATUS_UNKNOWN;
6bbd11
 
6bbd11
--- autofs-5.0.7.orig/include/master.h
6bbd11
+++ autofs-5.0.7/include/master.h
6bbd11
@@ -26,6 +26,7 @@ struct map_source {
6bbd11
 	unsigned int flags;
6bbd11
 	char *type;
6bbd11
 	char *format;
6bbd11
+	char *name;
6bbd11
 	time_t exp_timeout;		/* Timeout for expiring mounts */
6bbd11
 	time_t age;
6bbd11
 	unsigned int master_line;
6bbd11
--- autofs-5.0.7.orig/lib/master.c
6bbd11
+++ autofs-5.0.7/lib/master.c
6bbd11
@@ -211,6 +211,8 @@ master_add_map_source(struct master_mape
6bbd11
 	}
6bbd11
 	source->argc = argc;
6bbd11
 	source->argv = tmpargv;
6bbd11
+	if (source->argv[0])
6bbd11
+		source->name = strdup(source->argv[0]);
6bbd11
 
6bbd11
 	master_source_writelock(entry);
6bbd11
 
6bbd11
@@ -333,6 +335,8 @@ static void __master_free_map_source(str
6bbd11
 		free(source->type);
6bbd11
 	if (source->format)
6bbd11
 		free(source->format);
6bbd11
+	if (source->name)
6bbd11
+		free(source->name);
6bbd11
 	if (free_cache && source->mc)
6bbd11
 		cache_release(source);
6bbd11
 	if (source->lookup) {
6bbd11
@@ -468,6 +472,8 @@ master_add_source_instance(struct map_so
6bbd11
 	}
6bbd11
 	new->argc = argc;
6bbd11
 	new->argv = tmpargv;
6bbd11
+	if (source->name)
6bbd11
+		new->name = strdup(source->name);
6bbd11
 
6bbd11
 	status = pthread_mutex_lock(&instance_mutex);
6bbd11
 	if (status)
6bbd11
--- autofs-5.0.7.orig/man/autofs.conf.5.in
6bbd11
+++ autofs-5.0.7/man/autofs.conf.5.in
6bbd11
@@ -327,6 +327,11 @@ and can be used to provide different def
6bbd11
 without having to modify centrally managed maps. It is empty by
6bbd11
 default.
6bbd11
 .TP
6bbd11
+.B search_path
6bbd11
+.br
6bbd11
+Colon seperated paths to search for maps that are not specified
6bbd11
+as a full path.
6bbd11
+.TP
6bbd11
 .B dismount_interval
6bbd11
 .br
6bbd11
 Is equivalent to the autofs timeout option. It is only possible
6bbd11
--- autofs-5.0.7.orig/modules/parse_amd.c
6bbd11
+++ autofs-5.0.7/modules/parse_amd.c
6bbd11
@@ -198,7 +198,9 @@ static struct substvar *add_lookup_vars(
6bbd11
 		break;
6bbd11
 	}
6bbd11
 
6bbd11
-	if (source->argv[0][0])
6bbd11
+	if (source->name)
6bbd11
+		list = macro_addvar(list, "map", 3, source->name);
6bbd11
+	else if (source->argv[0][0])
6bbd11
 		list = macro_addvar(list, "map", 3, source->argv[0]);
6bbd11
 
6bbd11
 	tsv = pthread_getspecific(key_thread_stdenv_vars);
6bbd11
--- autofs-5.0.7.orig/redhat/autofs.conf.default.in
6bbd11
+++ autofs-5.0.7/redhat/autofs.conf.default.in
6bbd11
@@ -221,12 +221,6 @@ mount_nfs_default_protocol = 4
6bbd11
 #
6bbd11
 # A number of configuration options are not yet implemented:
6bbd11
 #
6bbd11
-# search_path - always a little frustrating, the compiled in
6bbd11
-#	map location should be used to locate maps but isn't
6bbd11
-#	in some cases. This requires work within autofs itself
6bbd11
-#	and that will (obviously) include implementing this
6bbd11
-#	configuration option for the amd map parser as well.
6bbd11
-#
6bbd11
 # fully_qualified_hosts - not yet implemented.
6bbd11
 #
6bbd11
 # unmount_on_exit - since autofs always tries to re-connect
6bbd11
@@ -269,6 +263,9 @@ mount_nfs_default_protocol = 4
6bbd11
 #	machines without having to modify centrally managed maps.
6bbd11
 #	It is empty by default.
6bbd11
 #
6bbd11
+# search_path - colon seperated paths to search for maps that
6bbd11
+#	are not specified as a full path.
6bbd11
+#
6bbd11
 # dismount_interval - is equivalent to the autofs timeout option. It
6bbd11
 #	is only possible to use this with type "auto" mounts due
6bbd11
 #	to the way the autofs kernel module performs expiry. It
6bbd11
--- autofs-5.0.7.orig/samples/autofs.conf.default.in
6bbd11
+++ autofs-5.0.7/samples/autofs.conf.default.in
6bbd11
@@ -220,12 +220,6 @@ browse_mode = no
6bbd11
 #
6bbd11
 # A number of configuration options are not yet implemented:
6bbd11
 #
6bbd11
-# search_path - always a little frustrating, the compiled in
6bbd11
-#	map location should be used to locate maps but isn't
6bbd11
-#	in some cases. This requires work within autofs itself
6bbd11
-#	and that will (obviously) include implementing this
6bbd11
-#	configuration option for the amd map parser as well.
6bbd11
-#
6bbd11
 # fully_qualified_hosts - not yet implemented.
6bbd11
 #
6bbd11
 # unmount_on_exit - since autofs always tries to re-connect
6bbd11
@@ -268,6 +262,9 @@ browse_mode = no
6bbd11
 #	machines without having to modify centrally managed maps.
6bbd11
 #	It is empty by default.
6bbd11
 #
6bbd11
+# search_path - colon seperated paths to search for maps that
6bbd11
+#	are not specified as a full path.
6bbd11
+#
6bbd11
 # dismount_interval - is equivalent to the autofs timeout option. It
6bbd11
 #	is only possible to use this with type "auto" mounts due
6bbd11
 #	to the way the autofs kernel module performs expiry. It