|
|
306fa1 |
autofs-5.1.1 - implement reinit in ldap lookup module
|
|
|
306fa1 |
|
|
|
306fa1 |
From: Ian Kent <raven@themaw.net>
|
|
|
306fa1 |
|
|
|
306fa1 |
Refactor the ldap 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_ldap.c | 109 +++++++++++++++++++++++++++++++++++--------------
|
|
|
306fa1 |
1 file changed, 77 insertions(+), 32 deletions(-)
|
|
|
306fa1 |
|
|
|
306fa1 |
diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
|
|
|
306fa1 |
index 0f5bc48..578d6c6 100644
|
|
|
306fa1 |
--- a/modules/lookup_ldap.c
|
|
|
306fa1 |
+++ b/modules/lookup_ldap.c
|
|
|
306fa1 |
@@ -1683,39 +1683,23 @@ static void validate_uris(struct list_head *list)
|
|
|
306fa1 |
return;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
-/*
|
|
|
306fa1 |
- * This initializes a context (persistent non-global data) for queries to
|
|
|
306fa1 |
- * this module. Return zero if we succeed.
|
|
|
306fa1 |
- */
|
|
|
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 |
unsigned int is_amd_format;
|
|
|
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, sizeof(buf));
|
|
|
306fa1 |
- logerr(MODPREFIX "malloc: %s", estr);
|
|
|
306fa1 |
- return 1;
|
|
|
306fa1 |
- }
|
|
|
306fa1 |
- memset(ctxt, 0, sizeof(struct lookup_context));
|
|
|
306fa1 |
-
|
|
|
306fa1 |
ret = pthread_mutex_init(&ctxt->uris_mutex, NULL);
|
|
|
306fa1 |
if (ret) {
|
|
|
306fa1 |
error(LOGOPT_ANY, MODPREFIX "failed to init uris mutex");
|
|
|
306fa1 |
- free(ctxt);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
/* If a map type isn't explicitly given, parse it like sun entries. */
|
|
|
306fa1 |
if (mapfmt == NULL)
|
|
|
306fa1 |
mapfmt = MAPFMT_DEFAULT;
|
|
|
306fa1 |
+
|
|
|
306fa1 |
is_amd_format = 0;
|
|
|
306fa1 |
if (!strcmp(mapfmt, "amd")) {
|
|
|
306fa1 |
is_amd_format = 1;
|
|
|
306fa1 |
@@ -1733,7 +1717,6 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
*/
|
|
|
306fa1 |
if (!parse_server_string(LOGOPT_NONE, argv[0], ctxt)) {
|
|
|
306fa1 |
error(LOGOPT_ANY, MODPREFIX "cannot parse server string");
|
|
|
306fa1 |
- free_context(ctxt);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
@@ -1758,7 +1741,6 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
char *tmp = conf_amd_get_ldap_base();
|
|
|
306fa1 |
if (!tmp) {
|
|
|
306fa1 |
error(LOGOPT_ANY, MODPREFIX "failed to get base dn");
|
|
|
306fa1 |
- free_context(ctxt);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
ctxt->base = tmp;
|
|
|
306fa1 |
@@ -1767,7 +1749,6 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
if (!tmp) {
|
|
|
306fa1 |
error(LOGOPT_ANY,
|
|
|
306fa1 |
MODPREFIX "failed to get ldap_hostports");
|
|
|
306fa1 |
- free_context(ctxt);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
@@ -1777,21 +1758,18 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
*/
|
|
|
306fa1 |
if (!parse_server_string(LOGOPT_NONE, tmp, ctxt)) {
|
|
|
306fa1 |
error(LOGOPT_ANY, MODPREFIX "cannot parse server string");
|
|
|
306fa1 |
- free_context(ctxt);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
free(tmp);
|
|
|
306fa1 |
|
|
|
306fa1 |
if (!ctxt->server) {
|
|
|
306fa1 |
error(LOGOPT_ANY, MODPREFIX "ldap_hostports not valid");
|
|
|
306fa1 |
- free_context(ctxt);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
tmp = strdup(argv[0]);
|
|
|
306fa1 |
if (!tmp) {
|
|
|
306fa1 |
error(LOGOPT_ANY, MODPREFIX "failed to set mapname");
|
|
|
306fa1 |
- free_context(ctxt);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
ctxt->mapname = tmp;
|
|
|
306fa1 |
@@ -1805,7 +1783,7 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
*/
|
|
|
306fa1 |
ret = parse_ldap_config(LOGOPT_NONE, ctxt);
|
|
|
306fa1 |
if (ret) {
|
|
|
306fa1 |
- free_context(ctxt);
|
|
|
306fa1 |
+ error(LOGOPT_ANY, MODPREFIX "failed to parse ldap config");
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|
|
|
306fa1 |
@@ -1815,7 +1793,6 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
if (!autofs_sasl_client_init(LOGOPT_NONE)) {
|
|
|
306fa1 |
error(LOGOPT_ANY, "failed to init sasl client");
|
|
|
306fa1 |
ldapinit_mutex_unlock();
|
|
|
306fa1 |
- free_context(ctxt);
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
ldapinit_mutex_unlock();
|
|
|
306fa1 |
@@ -1824,13 +1801,51 @@ int lookup_init(const char *mapfmt,
|
|
|
306fa1 |
if (is_amd_format)
|
|
|
306fa1 |
ctxt->timestamp = get_amd_timestamp(ctxt);
|
|
|
306fa1 |
|
|
|
306fa1 |
- /* Open the parser, if we can. */
|
|
|
306fa1 |
- ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
|
|
|
306fa1 |
- if (!ctxt->parse) {
|
|
|
306fa1 |
+ if (reinit) {
|
|
|
306fa1 |
+ ret = reinit_parse(ctxt->parse,
|
|
|
306fa1 |
+ mapfmt, MODPREFIX, argc - 1, argv + 1);
|
|
|
306fa1 |
+ if (ret)
|
|
|
306fa1 |
+ logmsg(MODPREFIX "failed to reinit parse context");
|
|
|
306fa1 |
+ } else {
|
|
|
306fa1 |
+ /* Open the parser, if we can. */
|
|
|
306fa1 |
+ ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
|
|
|
306fa1 |
+ if (!ctxt->parse) {
|
|
|
306fa1 |
+ logerr(MODPREFIX "failed to open parse context");
|
|
|
306fa1 |
+ ret = 1;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ return ret;
|
|
|
306fa1 |
+}
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+/*
|
|
|
306fa1 |
+ * This initializes a context (persistent non-global data) for queries to
|
|
|
306fa1 |
+ * this module. Return zero if we succeed.
|
|
|
306fa1 |
+ */
|
|
|
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, sizeof(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_context(ctxt);
|
|
|
306fa1 |
- logerr(MODPREFIX "failed to open parse context");
|
|
|
306fa1 |
return 1;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
+
|
|
|
306fa1 |
*context = ctxt;
|
|
|
306fa1 |
|
|
|
306fa1 |
return 0;
|
|
|
306fa1 |
@@ -1839,6 +1854,36 @@ 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, sizeof(buf));
|
|
|
306fa1 |
+ logerr(MODPREFIX "malloc: %s", estr);
|
|
|
306fa1 |
+ return 1;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
+ memset(new, 0, sizeof(struct lookup_context));
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ new->parse = ctxt->parse;
|
|
|
306fa1 |
+ ret = do_init(mapfmt, argc, argv, new, 1);
|
|
|
306fa1 |
+ if (ret) {
|
|
|
306fa1 |
+ free_context(new);
|
|
|
306fa1 |
+ return 1;
|
|
|
306fa1 |
+ }
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+ *context = new;
|
|
|
306fa1 |
+
|
|
|
306fa1 |
+#ifdef WITH_SASL
|
|
|
306fa1 |
+ ldapinit_mutex_lock();
|
|
|
306fa1 |
+ autofs_sasl_dispose(ctxt);
|
|
|
306fa1 |
+ ldapinit_mutex_unlock();
|
|
|
306fa1 |
+#endif
|
|
|
306fa1 |
+ free_context(ctxt);
|
|
|
306fa1 |
+
|
|
|
306fa1 |
return 0;
|
|
|
306fa1 |
}
|
|
|
306fa1 |
|