Ian Kent ff6f3e
autofs-5.1.0 - add serialization to sasl init
Ian Kent ff6f3e
Ian Kent ff6f3e
From: Ian Kent <ikent@redhat.com>
Ian Kent ff6f3e
Ian Kent ff6f3e
Attempt to resolve crash in sasl initialization. We know that the
Ian Kent ff6f3e
initial connection calls to connect to an LDAP server are not
Ian Kent ff6f3e
thread safe and it looks like the sasl code doesn't take that into
Ian Kent ff6f3e
consideration so adding serialization with a mutex is probably a
Ian Kent ff6f3e
sensible thing to do.
Ian Kent ff6f3e
---
Ian Kent ff6f3e
 CHANGELOG             |    1 +
Ian Kent ff6f3e
 modules/lookup_ldap.c |   13 +++++++++++++
Ian Kent ff6f3e
 2 files changed, 14 insertions(+)
Ian Kent ff6f3e
Ian Kent ff6f3e
diff --git a/CHANGELOG b/CHANGELOG
Ian Kent ff6f3e
index 58b94dc..92ee83b 100644
Ian Kent ff6f3e
--- a/CHANGELOG
Ian Kent ff6f3e
+++ b/CHANGELOG
Ian Kent ff6f3e
@@ -1,6 +1,7 @@
Ian Kent ff6f3e
 ??/??/2014 autofs-5.1.1
Ian Kent ff6f3e
 =======================
Ian Kent ff6f3e
 - fix compile error in defaults.c.
Ian Kent ff6f3e
+- add serialization to sasl init.
Ian Kent ff6f3e
 
Ian Kent ff6f3e
 04/06/2014 autofs-5.1.0
Ian Kent ff6f3e
 =======================
Ian Kent ff6f3e
diff --git a/modules/lookup_ldap.c b/modules/lookup_ldap.c
Ian Kent ff6f3e
index 8091ed2..aca3e05 100644
Ian Kent ff6f3e
--- a/modules/lookup_ldap.c
Ian Kent ff6f3e
+++ b/modules/lookup_ldap.c
Ian Kent ff6f3e
@@ -578,7 +578,9 @@ static int do_bind(unsigned logopt, LDAP *ldap, const char *uri, struct lookup_c
Ian Kent ff6f3e
 	      ctxt->auth_required, ctxt->sasl_mech);
Ian Kent ff6f3e
 
Ian Kent ff6f3e
 	if (ctxt->auth_required & LDAP_NEED_AUTH) {
Ian Kent ff6f3e
+		ldapinit_mutex_lock();
Ian Kent ff6f3e
 		rv = autofs_sasl_bind(logopt, ldap, ctxt);
Ian Kent ff6f3e
+		ldapinit_mutex_unlock();
Ian Kent ff6f3e
 		debug(logopt, MODPREFIX "autofs_sasl_bind returned %d", rv);
Ian Kent ff6f3e
 	} else {
Ian Kent ff6f3e
 		rv = bind_ldap_simple(logopt, ldap, uri, ctxt);
Ian Kent ff6f3e
@@ -922,7 +924,9 @@ static LDAP *do_reconnect(unsigned logopt, struct lookup_context *ctxt)
Ian Kent ff6f3e
 #ifdef WITH_SASL
Ian Kent ff6f3e
 		/* Dispose of the sasl authentication connection and try again. */
Ian Kent ff6f3e
 		if (!ldap && ctxt->auth_required & LDAP_NEED_AUTH) {
Ian Kent ff6f3e
+			ldapinit_mutex_lock();
Ian Kent ff6f3e
 			autofs_sasl_dispose(ctxt);
Ian Kent ff6f3e
+			ldapinit_mutex_unlock();
Ian Kent ff6f3e
 			ldap = connect_to_server(logopt, ctxt->server, ctxt);
Ian Kent ff6f3e
 		}
Ian Kent ff6f3e
 #endif
Ian Kent ff6f3e
@@ -958,7 +962,9 @@ static LDAP *do_reconnect(unsigned logopt, struct lookup_context *ctxt)
Ian Kent ff6f3e
 	 * current server again before trying other servers in the list.
Ian Kent ff6f3e
 	 */
Ian Kent ff6f3e
 	if (!ldap && ctxt->auth_required & LDAP_NEED_AUTH) {
Ian Kent ff6f3e
+		ldapinit_mutex_lock();
Ian Kent ff6f3e
 		autofs_sasl_dispose(ctxt);
Ian Kent ff6f3e
+		ldapinit_mutex_unlock();
Ian Kent ff6f3e
 		ldap = connect_to_server(logopt, ctxt->uri->uri, ctxt);
Ian Kent ff6f3e
 	}
Ian Kent ff6f3e
 #endif
Ian Kent ff6f3e
@@ -969,7 +975,9 @@ static LDAP *do_reconnect(unsigned logopt, struct lookup_context *ctxt)
Ian Kent ff6f3e
 
Ian Kent ff6f3e
 find_server:
Ian Kent ff6f3e
 #ifdef WITH_SASL
Ian Kent ff6f3e
+	ldapinit_mutex_lock();
Ian Kent ff6f3e
 	autofs_sasl_dispose(ctxt);
Ian Kent ff6f3e
+	ldapinit_mutex_unlock();
Ian Kent ff6f3e
 #endif
Ian Kent ff6f3e
 
Ian Kent ff6f3e
 	/* Current server failed, try the rest or dc connection */
Ian Kent ff6f3e
@@ -1742,11 +1750,14 @@ int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **co
Ian Kent ff6f3e
 
Ian Kent ff6f3e
 #ifdef WITH_SASL
Ian Kent ff6f3e
 	/* Init the sasl callbacks */
Ian Kent ff6f3e
+	ldapinit_mutex_lock();
Ian Kent ff6f3e
 	if (!autofs_sasl_client_init(LOGOPT_NONE)) {
Ian Kent ff6f3e
 		error(LOGOPT_ANY, "failed to init sasl client");
Ian Kent ff6f3e
+		ldapinit_mutex_unlock();
Ian Kent ff6f3e
 		free_context(ctxt);
Ian Kent ff6f3e
 		return 1;
Ian Kent ff6f3e
 	}
Ian Kent ff6f3e
+	ldapinit_mutex_unlock();
Ian Kent ff6f3e
 #endif
Ian Kent ff6f3e
 
Ian Kent ff6f3e
 	if (is_amd_format)
Ian Kent ff6f3e
@@ -3678,8 +3689,10 @@ int lookup_done(void *context)
Ian Kent ff6f3e
 	struct lookup_context *ctxt = (struct lookup_context *) context;
Ian Kent ff6f3e
 	int rv = close_parse(ctxt->parse);
Ian Kent ff6f3e
 #ifdef WITH_SASL
Ian Kent ff6f3e
+	ldapinit_mutex_lock();
Ian Kent ff6f3e
 	autofs_sasl_dispose(ctxt);
Ian Kent ff6f3e
 	autofs_sasl_done();
Ian Kent ff6f3e
+	ldapinit_mutex_unlock();
Ian Kent ff6f3e
 #endif
Ian Kent ff6f3e
 	free_context(ctxt);
Ian Kent ff6f3e
 	return rv;