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

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