|
|
306fa1 |
autofs-5.1.1 - implement reinit in hesiod lookup module
|
|
|
306fa1 |
|
|
|
306fa1 |
From: Ian Kent <raven@themaw.net>
|
|
|
306fa1 |
|
|
|
306fa1 |
Refactor the hesiod lookup module to add an implementation for the newly
|
|
|
306fa1 |
added reinit entry point.
|
|
|
306fa1 |
|
|
|
306fa1 |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
306fa1 |
---
|
|
|
306fa1 |
modules/lookup_hesiod.c | 96 ++++++++++++++++++++++++++++++++++++-----------
|
|
|
306fa1 |
1 file changed, 74 insertions(+), 22 deletions(-)
|
|
|
306fa1 |
|
|
|
306fa1 |
diff --git a/modules/lookup_hesiod.c b/modules/lookup_hesiod.c
|
|
|
306fa1 |
index de5ec08..c0f7f51 100644
|
|
|
306fa1 |
--- a/modules/lookup_hesiod.c
|
|
|
306fa1 |
+++ b/modules/lookup_hesiod.c
|
|
|
306fa1 |
@@ -37,24 +37,12 @@ static pthread_mutex_t hesiod_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
306fa1 |
|
|
|
306fa1 |
int lookup_version = AUTOFS_LOOKUP_VERSION; /* Required by protocol */
|
|
|
306fa1 |
|
|
|
306fa1 |
-/* This initializes a context (persistent non-global data) for queries to
|
|
|
306fa1 |
- this module. */
|
|
|
306fa1 |
-int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
- int argc, const char *const *argv, void **context)
|
|
|
306fa1 |
+static int do_init(const char *mapfmt,
|
|
|
306fa1 |
+ int argc, const char *const *argv,
|
|
|
306fa1 |
+ struct lookup_context *ctxt, unsigned int reinit)
|
|
|
306fa1 |
{
|
|
|
306fa1 |
- struct lookup_context *ctxt = NULL;
|
|
|
306fa1 |
char buf[MAX_ERR_BUF];
|
|
|
306fa1 |
-
|
|
|
306fa1 |
- *context = NULL;
|
|
|
306fa1 |
-
|
|
|
306fa1 |
- /* If we can't build a context, bail. */
|
|
|
306fa1 |
- ctxt = malloc(sizeof(struct lookup_context));
|
|
|
306fa1 |
- if (!ctxt) {
|
|
|
306fa1 |
- char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
306fa1 |
- logerr(MODPREFIX "malloc: %s", estr);
|
|
|
306fa1 |
- return 1;
|
|
|
306fa1 |
- }
|
|
|
306fa1 |
- memset(ctxt, 0, sizeof(struct lookup_context));
|
|
|
306fa1 |
+ int ret = 0;
|
|
|
306fa1 |
|
|
|
306fa1 |
/* Initialize the resolver. */
|
|
|
306fa1 |
res_init();
|
|
|
306fa1 |
@@ -63,7 +51,6 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
if (hesiod_init(&(ctxt->hesiod_context)) != 0) {
|
|
|
306fa1 |
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
306fa1 |
logerr(MODPREFIX "hesiod_init(): %s", estr);
|
|
|
306fa1 |
- free(ctxt);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
@@ -75,9 +62,9 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
/* amd formated hesiod maps have a map name */
|
|
|
306fa1 |
const char *mapname = argv[0];
|
|
|
306fa1 |
if (strncmp(mapname, AMD_MAP_PREFIX, AMD_MAP_PREFIX_LEN)) {
|
|
|
306fa1 |
+ hesiod_end(ctxt->hesiod_context);
|
|
|
306fa1 |
logerr(MODPREFIX
|
|
|
306fa1 |
"incorrect prefix for hesiod map %s", mapname);
|
|
|
306fa1 |
- free(ctxt);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
ctxt->mapname = mapname;
|
|
|
306fa1 |
@@ -85,13 +72,52 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
argv++;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
- /* Open the parser, if we can. */
|
|
|
306fa1 |
- ctxt->parser = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
|
|
|
306fa1 |
- if (!ctxt->parser) {
|
|
|
306fa1 |
- logerr(MODPREFIX "failed to open parse context");
|
|
|
306fa1 |
+ if (reinit) {
|
|
|
306fa1 |
+ ret = reinit_parse(ctxt->parser, mapfmt,
|
|
|
306fa1 |
+ MODPREFIX, argc - 1, argv - 1);
|
|
|
306fa1 |
+ if (ret)
|
|
|
306fa1 |
+ logerr(MODPREFIX "failed to reinit parse context");
|
|
|
306fa1 |
+ } else {
|
|
|
306fa1 |
+ ctxt->parser = open_parse(mapfmt,
|
|
|
306fa1 |
+ MODPREFIX, argc - 1, argv + 1);
|
|
|
306fa1 |
+ if (!ctxt->parser) {
|
|
|
306fa1 |
+ logerr(MODPREFIX "failed to open parse context");
|
|
|
306fa1 |
+ ret = 1;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ if (ret)
|
|
|
306fa1 |
+ hesiod_end(ctxt->hesiod_context);
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ return ret;
|
|
|
306fa1 |
+}
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+/* This initializes a context (persistent non-global data) for queries to
|
|
|
306fa1 |
+ this module. */
|
|
|
306fa1 |
+int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
+ int argc, const char *const *argv, void **context)
|
|
|
306fa1 |
+{
|
|
|
306fa1 |
+ struct lookup_context *ctxt;
|
|
|
306fa1 |
+ char buf[MAX_ERR_BUF];
|
|
|
306fa1 |
+ int ret;
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ *context = NULL;
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ /* If we can't build a context, bail. */
|
|
|
306fa1 |
+ ctxt = malloc(sizeof(struct lookup_context));
|
|
|
306fa1 |
+ if (!ctxt) {
|
|
|
306fa1 |
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
306fa1 |
+ logerr(MODPREFIX "malloc: %s", estr);
|
|
|
306fa1 |
+ return 1;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
+ memset(ctxt, 0, sizeof(struct lookup_context));
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ ret = do_init(mapfmt, argc, argv, ctxt, 0);
|
|
|
306fa1 |
+ if (ret) {
|
|
|
306fa1 |
free(ctxt);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
+
|
|
|
306fa1 |
*context = ctxt;
|
|
|
306fa1 |
|
|
|
306fa1 |
return 0;
|
|
|
306fa1 |
@@ -100,6 +126,32 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
int lookup_reinit(const char *mapfmt,
|
|
|
306fa1 |
int argc, const char *const *argv, void **context)
|
|
|
306fa1 |
{
|
|
|
306fa1 |
+ struct lookup_context *ctxt = (struct lookup_context *) *context;
|
|
|
306fa1 |
+ struct lookup_context *new;
|
|
|
306fa1 |
+ char buf[MAX_ERR_BUF];
|
|
|
306fa1 |
+ int ret;
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ /* If we can't build a context, bail. */
|
|
|
306fa1 |
+ new = malloc(sizeof(struct lookup_context));
|
|
|
306fa1 |
+ if (!new) {
|
|
|
306fa1 |
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
306fa1 |
+ logerr(MODPREFIX "malloc: %s", estr);
|
|
|
306fa1 |
+ return 1;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
+ memset(new, 0, sizeof(struct lookup_context));
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ new->parser = ctxt->parser;
|
|
|
306fa1 |
+ ret = do_init(mapfmt, argc, argv, new, 1);
|
|
|
306fa1 |
+ if (ret) {
|
|
|
306fa1 |
+ free(new);
|
|
|
306fa1 |
+ return 1;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ *context = new;
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ hesiod_end(ctxt->hesiod_context);
|
|
|
306fa1 |
+ free(ctxt);
|
|
|
306fa1 |
+
|
|
|
306fa1 |
return 0;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|