Blame SOURCES/autofs-5.1.1-implement-reinit-in-ldap-lookup-module.patch

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