Blame SOURCES/autofs-5.1.1-make-open_lookup-return-nss-status.patch

4d476f
autofs-5.1.1 - make open_lookup() return nss status
4d476f
4d476f
From: Ian Kent <raven@themaw.net>
4d476f
4d476f
In order to distinguish between source unavailable and map not found
4d476f
when opening nsswitch sources that have non-default actions open_lookup()
4d476f
needs to return distinct results for these two cases.
4d476f
4d476f
Signed-off-by: Ian Kent <raven@themaw.net>
4d476f
---
4d476f
 daemon/lookup.c        |   21 +++++++++++----------
4d476f
 daemon/module.c        |   22 +++++++++++++---------
4d476f
 include/automount.h    |    4 ++--
4d476f
 modules/lookup_multi.c |   20 +++++++++++++-------
4d476f
 modules/parse_amd.c    |    6 ++++--
4d476f
 5 files changed, 43 insertions(+), 30 deletions(-)
4d476f
4d476f
diff --git a/daemon/lookup.c b/daemon/lookup.c
4d476f
index 53455a1..0579f98 100644
4d476f
--- a/daemon/lookup.c
4d476f
+++ b/daemon/lookup.c
4d476f
@@ -44,9 +44,9 @@ static int do_read_master(struct master *master, char *type, time_t age)
4d476f
 	argv[0] = master->name;
4d476f
 	argv[1] = NULL;
4d476f
 
4d476f
-	lookup = open_lookup(type, "", NULL, argc, argv);
4d476f
-	if (!lookup)
4d476f
-		return NSS_STATUS_UNAVAIL;
4d476f
+	status = open_lookup(type, "", NULL, argc, argv, &lookup);
4d476f
+	if (status != NSS_STATUS_SUCCESS)
4d476f
+		return status;
4d476f
 
4d476f
 	status = lookup->lookup_read_master(master, age, lookup->context);
4d476f
 
4d476f
@@ -300,10 +300,11 @@ static int do_read_map(struct autofs_point *ap, struct map_source *map, time_t a
4d476f
 	struct lookup_mod *lookup;
4d476f
 	int status;
4d476f
 
4d476f
-	lookup = open_lookup(map->type, "", map->format, map->argc, map->argv);
4d476f
-	if (!lookup) {
4d476f
+	status = open_lookup(map->type, "", map->format,
4d476f
+			     map->argc, map->argv, &lookup);
4d476f
+	if (status != NSS_STATUS_SUCCESS) {
4d476f
 		debug(ap->logopt, "lookup module %s failed", map->type);
4d476f
-		return NSS_STATUS_UNAVAIL;
4d476f
+		return status;
4d476f
 	}
4d476f
 
4d476f
 	master_source_writelock(ap->entry);
4d476f
@@ -737,12 +738,12 @@ int do_lookup_mount(struct autofs_point *ap, struct map_source *map, const char
4d476f
 	int status;
4d476f
 
4d476f
 	if (!map->lookup) {
4d476f
-		lookup = open_lookup(map->type, "",
4d476f
-				     map->format, map->argc, map->argv);
4d476f
-		if (!lookup) {
4d476f
+		status = open_lookup(map->type, "",
4d476f
+				     map->format, map->argc, map->argv, &lookup);
4d476f
+		if (status != NSS_STATUS_SUCCESS) {
4d476f
 			debug(ap->logopt,
4d476f
 			      "lookup module %s failed", map->type);
4d476f
-			return NSS_STATUS_UNAVAIL;
4d476f
+			return status;
4d476f
 		}
4d476f
 		map->lookup = lookup;
4d476f
 	}
4d476f
diff --git a/daemon/module.c b/daemon/module.c
4d476f
index 466d8d7..9028aaa 100644
4d476f
--- a/daemon/module.c
4d476f
+++ b/daemon/module.c
4d476f
@@ -17,6 +17,7 @@
4d476f
 #include <string.h>
4d476f
 #include <stdlib.h>
4d476f
 #include "automount.h"
4d476f
+#include "nsswitch.h"
4d476f
 
4d476f
 int load_autofs4_module(void)
4d476f
 {
4d476f
@@ -53,8 +54,8 @@ int load_autofs4_module(void)
4d476f
 	return 1;
4d476f
 }
4d476f
 
4d476f
-struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
4d476f
-			       const char *mapfmt, int argc, const char *const *argv)
4d476f
+int open_lookup(const char *name, const char *err_prefix, const char *mapfmt,
4d476f
+		int argc, const char *const *argv, struct lookup_mod **lookup)
4d476f
 {
4d476f
 	struct lookup_mod *mod;
4d476f
 	char buf[MAX_ERR_BUF];
4d476f
@@ -63,6 +64,7 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
4d476f
 	void *dh;
4d476f
 	int *ver;
4d476f
 
4d476f
+	*lookup = NULL;
4d476f
 
4d476f
 	mod = malloc(sizeof(struct lookup_mod));
4d476f
 	if (!mod) {
4d476f
@@ -70,7 +72,7 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
4d476f
 			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
4d476f
 			logerr("%s%s", err_prefix, estr);
4d476f
 		}
4d476f
-		return NULL;
4d476f
+		return NSS_STATUS_UNAVAIL;
4d476f
 	}
4d476f
 
4d476f
 	size = snprintf(fnbuf, sizeof(fnbuf),
4d476f
@@ -81,7 +83,7 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
4d476f
 			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
4d476f
 			logerr("%s%s", err_prefix, estr);
4d476f
 		}
4d476f
-		return NULL;
4d476f
+		return NSS_STATUS_UNAVAIL;
4d476f
 	}
4d476f
 
4d476f
 	if (!(dh = dlopen(fnbuf, RTLD_NOW))) {
4d476f
@@ -89,7 +91,7 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
4d476f
 			logerr("%scannot open lookup module %s (%s)",
4d476f
 			       err_prefix, name, dlerror());
4d476f
 		free(mod);
4d476f
-		return NULL;
4d476f
+		return NSS_STATUS_UNAVAIL;
4d476f
 	}
4d476f
 
4d476f
 	if (!(ver = (int *) dlsym(dh, "lookup_version"))
4d476f
@@ -99,7 +101,7 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
4d476f
 			     err_prefix, name);
4d476f
 		dlclose(dh);
4d476f
 		free(mod);
4d476f
-		return NULL;
4d476f
+		return NSS_STATUS_UNAVAIL;
4d476f
 	}
4d476f
 
4d476f
 	if (!(mod->lookup_init = (lookup_init_t) dlsym(dh, "lookup_init")) ||
4d476f
@@ -111,16 +113,18 @@ struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
4d476f
 			logerr("%slookup module %s corrupt", err_prefix, name);
4d476f
 		dlclose(dh);
4d476f
 		free(mod);
4d476f
-		return NULL;
4d476f
+		return NSS_STATUS_UNAVAIL;
4d476f
 	}
4d476f
 
4d476f
 	if (mod->lookup_init(mapfmt, argc, argv, &mod->context)) {
4d476f
 		dlclose(dh);
4d476f
 		free(mod);
4d476f
-		return NULL;
4d476f
+		return NSS_STATUS_NOTFOUND;
4d476f
 	}
4d476f
 	mod->dlhandle = dh;
4d476f
-	return mod;
4d476f
+	*lookup = mod;
4d476f
+
4d476f
+	return NSS_STATUS_SUCCESS;
4d476f
 }
4d476f
 
4d476f
 int close_lookup(struct lookup_mod *mod)
4d476f
diff --git a/include/automount.h b/include/automount.h
4d476f
index 447aba1..d614c10 100644
4d476f
--- a/include/automount.h
4d476f
+++ b/include/automount.h
4d476f
@@ -302,8 +302,8 @@ struct lookup_mod {
4d476f
 	void *context;
4d476f
 };
4d476f
 
4d476f
-struct lookup_mod *open_lookup(const char *name, const char *err_prefix,
4d476f
-			       const char *mapfmt, int argc, const char *const *argv);
4d476f
+int open_lookup(const char *name, const char *err_prefix, const char *mapfmt,
4d476f
+		int argc, const char *const *argv, struct lookup_mod **lookup);
4d476f
 int close_lookup(struct lookup_mod *);
4d476f
 
4d476f
 /* parse module */
4d476f
diff --git a/modules/lookup_multi.c b/modules/lookup_multi.c
4d476f
index ffb236c..55035e4 100644
4d476f
--- a/modules/lookup_multi.c
4d476f
+++ b/modules/lookup_multi.c
4d476f
@@ -50,8 +50,10 @@ static struct lookup_mod *nss_open_lookup(const char *format, int argc, const ch
4d476f
 	if (!argv || !argv[0])
4d476f
 		return NULL;
4d476f
 
4d476f
-	if (*argv[0] == '/')
4d476f
-		return open_lookup("file", MODPREFIX, format, argc, argv);
4d476f
+	if (*argv[0] == '/') {
4d476f
+		open_lookup("file", MODPREFIX, format, argc, argv, &mod);
4d476f
+		return mod;
4d476f
+	}
4d476f
 
4d476f
 	if (!strncmp(argv[0], "file", 4) ||
4d476f
 	    !strncmp(argv[0], "yp", 2) ||
4d476f
@@ -65,7 +67,8 @@ static struct lookup_mod *nss_open_lookup(const char *format, int argc, const ch
4d476f
 			fmt++;
4d476f
 		else
4d476f
 			fmt = format;
4d476f
-		return open_lookup(argv[0], MODPREFIX, fmt, argc -1, argv + 1);
4d476f
+		open_lookup(argv[0], MODPREFIX, fmt, argc - 1, argv + 1, &mod);
4d476f
+		return mod;
4d476f
 	}
4d476f
 
4d476f
 	INIT_LIST_HEAD(&nsslist);
4d476f
@@ -80,6 +83,7 @@ static struct lookup_mod *nss_open_lookup(const char *format, int argc, const ch
4d476f
 	head = &nsslist;
4d476f
 	list_for_each(p, head) {
4d476f
 		struct nss_source *this;
4d476f
+		int status;
4d476f
 
4d476f
 		this = list_entry(p, struct nss_source, list);
4d476f
 
4d476f
@@ -113,8 +117,9 @@ static struct lookup_mod *nss_open_lookup(const char *format, int argc, const ch
4d476f
 			save_argv0 = (char *) argv[0];
4d476f
 			argv[0] = path;
4d476f
 
4d476f
-			mod = open_lookup(type, MODPREFIX, format, argc, argv);
4d476f
-			if (mod) {
4d476f
+			status = open_lookup(type, MODPREFIX,
4d476f
+					     format, argc, argv, &mod);
4d476f
+			if (status == NSS_STATUS_SUCCESS) {
4d476f
 				free_sources(&nsslist);
4d476f
 				free(save_argv0);
4d476f
 				return mod;
4d476f
@@ -124,8 +129,9 @@ static struct lookup_mod *nss_open_lookup(const char *format, int argc, const ch
4d476f
 			free(path);
4d476f
 		}
4d476f
 
4d476f
-		mod = open_lookup(this->source, MODPREFIX, format, argc, argv);
4d476f
-		if (mod) {
4d476f
+		status = open_lookup(this->source, MODPREFIX,
4d476f
+				     format, argc, argv, &mod);
4d476f
+		if (status == NSS_STATUS_SUCCESS) {
4d476f
 			free_sources(&nsslist);
4d476f
 			return mod;
4d476f
 		}
4d476f
diff --git a/modules/parse_amd.c b/modules/parse_amd.c
4d476f
index 899be40..2e3d21f 100644
4d476f
--- a/modules/parse_amd.c
4d476f
+++ b/modules/parse_amd.c
4d476f
@@ -31,6 +31,7 @@
4d476f
 
4d476f
 #define MODULE_PARSE
4d476f
 #include "automount.h"
4d476f
+#include "nsswitch.h"
4d476f
 
4d476f
 #define MODPREFIX "parse(amd): "
4d476f
 
4d476f
@@ -1129,6 +1130,7 @@ static int do_host_mount(struct autofs_point *ap, const char *name,
4d476f
 	struct mapent *me;
4d476f
 	const char *argv[2];
4d476f
 	const char **pargv = NULL;
4d476f
+	int status;
4d476f
 	int argc = 0;
4d476f
 	int ret = 1;
4d476f
 
4d476f
@@ -1170,8 +1172,8 @@ static int do_host_mount(struct autofs_point *ap, const char *name,
4d476f
 	}
4d476f
 
4d476f
 	instance_mutex_lock();
4d476f
-	lookup = open_lookup("hosts", MODPREFIX, NULL, argc, pargv);
4d476f
-	if (!lookup) {
4d476f
+	status = open_lookup("hosts", MODPREFIX, NULL, argc, pargv, &lookup);
4d476f
+	if (status != NSS_STATUS_SUCCESS) {
4d476f
 		debug(ap->logopt, "open lookup module hosts failed");
4d476f
 		instance_mutex_unlock();
4d476f
 		goto out;