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

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