|
|
304803 |
autofs-5.1.1 - implement reinit in sss lookup module
|
|
|
304803 |
|
|
|
304803 |
From: Ian Kent <raven@themaw.net>
|
|
|
304803 |
|
|
|
304803 |
Refactor the sss lookup module to add an implementation for the newly
|
|
|
304803 |
added reinit entry point.
|
|
|
304803 |
|
|
|
304803 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
304803 |
---
|
|
|
304803 |
modules/lookup_sss.c | 130 +++++++++++++++++++++++++++++++++++++-------------
|
|
|
304803 |
1 file changed, 95 insertions(+), 35 deletions(-)
|
|
|
304803 |
|
|
|
304803 |
diff --git a/modules/lookup_sss.c b/modules/lookup_sss.c
|
|
|
304803 |
index c58a272..2f32e94 100644
|
|
|
304803 |
--- a/modules/lookup_sss.c
|
|
|
304803 |
+++ b/modules/lookup_sss.c
|
|
|
304803 |
@@ -56,39 +56,16 @@ struct lookup_context {
|
|
|
304803 |
|
|
|
304803 |
int lookup_version = AUTOFS_LOOKUP_VERSION; /* Required by protocol */
|
|
|
304803 |
|
|
|
304803 |
-int lookup_init(const char *mapfmt,
|
|
|
304803 |
- int argc, const char *const *argv, void **context)
|
|
|
304803 |
+static int open_sss_lib(struct lookup_context *ctxt)
|
|
|
304803 |
{
|
|
|
304803 |
- struct lookup_context *ctxt;
|
|
|
304803 |
- char buf[MAX_ERR_BUF];
|
|
|
304803 |
char dlbuf[PATH_MAX];
|
|
|
304803 |
char *estr;
|
|
|
304803 |
void *dh;
|
|
|
304803 |
size_t size;
|
|
|
304803 |
|
|
|
304803 |
- *context = NULL;
|
|
|
304803 |
-
|
|
|
304803 |
- ctxt = malloc(sizeof(struct lookup_context));
|
|
|
304803 |
- if (!ctxt) {
|
|
|
304803 |
- estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
304803 |
- logerr(MODPREFIX "malloc: %s", estr);
|
|
|
304803 |
- return 1;
|
|
|
304803 |
- }
|
|
|
304803 |
-
|
|
|
304803 |
- if (argc < 1) {
|
|
|
304803 |
- free(ctxt);
|
|
|
304803 |
- logerr(MODPREFIX "No map name");
|
|
|
304803 |
- return 1;
|
|
|
304803 |
- }
|
|
|
304803 |
- ctxt->mapname = argv[0];
|
|
|
304803 |
-
|
|
|
304803 |
- if (!mapfmt)
|
|
|
304803 |
- mapfmt = MAPFMT_DEFAULT;
|
|
|
304803 |
-
|
|
|
304803 |
size = snprintf(dlbuf, sizeof(dlbuf),
|
|
|
304803 |
"%s/%s.so", SSS_LIB_DIR, SSS_SO_NAME);
|
|
|
304803 |
if (size >= sizeof(dlbuf)) {
|
|
|
304803 |
- free(ctxt);
|
|
|
304803 |
logmsg(MODPREFIX "sss library path too long");
|
|
|
304803 |
return 1;
|
|
|
304803 |
}
|
|
|
304803 |
@@ -96,7 +73,6 @@ int lookup_init(const char *mapfmt,
|
|
|
304803 |
dh = dlopen(dlbuf, RTLD_LAZY);
|
|
|
304803 |
if (!dh) {
|
|
|
304803 |
logerr(MODPREFIX "failed to open %s: %s", dlbuf, dlerror());
|
|
|
304803 |
- free(ctxt);
|
|
|
304803 |
return 1;
|
|
|
304803 |
}
|
|
|
304803 |
ctxt->dlhandle = dh;
|
|
|
304803 |
@@ -117,15 +93,6 @@ int lookup_init(const char *mapfmt,
|
|
|
304803 |
if (!ctxt->setautomntent)
|
|
|
304803 |
goto lib_names_fail;
|
|
|
304803 |
|
|
|
304803 |
- ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
|
|
|
304803 |
- if (!ctxt->parse) {
|
|
|
304803 |
- logmsg(MODPREFIX "failed to open parse context");
|
|
|
304803 |
- dlclose(dh);
|
|
|
304803 |
- free(ctxt);
|
|
|
304803 |
- return 1;
|
|
|
304803 |
- }
|
|
|
304803 |
- *context = ctxt;
|
|
|
304803 |
-
|
|
|
304803 |
return 0;
|
|
|
304803 |
|
|
|
304803 |
lib_names_fail:
|
|
|
304803 |
@@ -134,13 +101,106 @@ lib_names_fail:
|
|
|
304803 |
else
|
|
|
304803 |
logerr(MODPREFIX "dlsym: %s", estr);
|
|
|
304803 |
dlclose(dh);
|
|
|
304803 |
- free(ctxt);
|
|
|
304803 |
+
|
|
|
304803 |
return 1;
|
|
|
304803 |
}
|
|
|
304803 |
|
|
|
304803 |
+static int do_init(const char *mapfmt,
|
|
|
304803 |
+ int argc, const char *const *argv,
|
|
|
304803 |
+ struct lookup_context *ctxt, unsigned int reinit)
|
|
|
304803 |
+{
|
|
|
304803 |
+ int ret = 0;
|
|
|
304803 |
+
|
|
|
304803 |
+ if (argc < 1) {
|
|
|
304803 |
+ logerr(MODPREFIX "No map name");
|
|
|
304803 |
+ ret = 1;
|
|
|
304803 |
+ goto out;
|
|
|
304803 |
+ }
|
|
|
304803 |
+ ctxt->mapname = argv[0];
|
|
|
304803 |
+
|
|
|
304803 |
+ if (!mapfmt)
|
|
|
304803 |
+ mapfmt = MAPFMT_DEFAULT;
|
|
|
304803 |
+
|
|
|
304803 |
+ if (!reinit) {
|
|
|
304803 |
+ ret = open_sss_lib(ctxt);
|
|
|
304803 |
+ if (ret)
|
|
|
304803 |
+ goto out;
|
|
|
304803 |
+ }
|
|
|
304803 |
+
|
|
|
304803 |
+ if (reinit) {
|
|
|
304803 |
+ ret = reinit_parse(ctxt->parse, mapfmt, MODPREFIX, argc - 1, argv + 1);
|
|
|
304803 |
+ if (ret)
|
|
|
304803 |
+ logmsg(MODPREFIX "failed to reinit parse context");
|
|
|
304803 |
+ } else {
|
|
|
304803 |
+ ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
|
|
|
304803 |
+ if (!ctxt->parse) {
|
|
|
304803 |
+ logmsg(MODPREFIX "failed to open parse context");
|
|
|
304803 |
+ dlclose(ctxt->dlhandle);
|
|
|
304803 |
+ ret = 1;
|
|
|
304803 |
+ }
|
|
|
304803 |
+ }
|
|
|
304803 |
+out:
|
|
|
304803 |
+ return ret;
|
|
|
304803 |
+}
|
|
|
304803 |
+
|
|
|
304803 |
+int lookup_init(const char *mapfmt,
|
|
|
304803 |
+ int argc, const char *const *argv, void **context)
|
|
|
304803 |
+{
|
|
|
304803 |
+ struct lookup_context *ctxt;
|
|
|
304803 |
+ char buf[MAX_ERR_BUF];
|
|
|
304803 |
+ char *estr;
|
|
|
304803 |
+
|
|
|
304803 |
+ *context = NULL;
|
|
|
304803 |
+
|
|
|
304803 |
+ ctxt = malloc(sizeof(struct lookup_context));
|
|
|
304803 |
+ if (!ctxt) {
|
|
|
304803 |
+ estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
304803 |
+ logerr(MODPREFIX "malloc: %s", estr);
|
|
|
304803 |
+ return 1;
|
|
|
304803 |
+ }
|
|
|
304803 |
+
|
|
|
304803 |
+ if (do_init(mapfmt, argc, argv, ctxt, 0)) {
|
|
|
304803 |
+ free(ctxt);
|
|
|
304803 |
+ return 1;
|
|
|
304803 |
+ }
|
|
|
304803 |
+
|
|
|
304803 |
+ *context = ctxt;
|
|
|
304803 |
+
|
|
|
304803 |
+ return 0;
|
|
|
304803 |
+}
|
|
|
304803 |
+
|
|
|
304803 |
int lookup_reinit(const char *mapfmt,
|
|
|
304803 |
int argc, const char *const *argv, void **context)
|
|
|
304803 |
{
|
|
|
304803 |
+ struct lookup_context *ctxt = (struct lookup_context *) *context;
|
|
|
304803 |
+ struct lookup_context *new;
|
|
|
304803 |
+ char buf[MAX_ERR_BUF];
|
|
|
304803 |
+ int ret;
|
|
|
304803 |
+
|
|
|
304803 |
+ new = malloc(sizeof(struct lookup_context));
|
|
|
304803 |
+ if (!new) {
|
|
|
304803 |
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
304803 |
+ logerr(MODPREFIX "malloc: %s", estr);
|
|
|
304803 |
+ return 1;
|
|
|
304803 |
+ }
|
|
|
304803 |
+
|
|
|
304803 |
+ new->parse = ctxt->parse;
|
|
|
304803 |
+ ret = do_init(mapfmt, argc, argv, new, 1);
|
|
|
304803 |
+ if (ret) {
|
|
|
304803 |
+ free(new);
|
|
|
304803 |
+ return 1;
|
|
|
304803 |
+ }
|
|
|
304803 |
+
|
|
|
304803 |
+ new->dlhandle = ctxt->dlhandle;
|
|
|
304803 |
+ new->setautomntent = ctxt->setautomntent;
|
|
|
304803 |
+ new->getautomntent_r = ctxt->getautomntent_r;
|
|
|
304803 |
+ new->getautomntbyname_r = ctxt->getautomntbyname_r;
|
|
|
304803 |
+ new->endautomntent = ctxt->endautomntent;
|
|
|
304803 |
+
|
|
|
304803 |
+ *context = new;
|
|
|
304803 |
+
|
|
|
304803 |
+ free(ctxt);
|
|
|
304803 |
+
|
|
|
304803 |
return 0;
|
|
|
304803 |
}
|
|
|
304803 |
|