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