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