Blame SOURCES/autofs-5.1.1-fix-error-handling-on-ldap-bind-fail.patch

304803
autofs-5.1.1 - fix error handling on ldap bind fail
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
When calling unbind_ldap_connection() if a sasl connection is
304803
being used then autofs_sasl_unbind() should be called and not
304803
ldap_unbind_ext(), otherwise the ldap connection release code
304803
could be called twice.
304803
304803
So, in unbind_ldap_connection() check if a sasl connection is in
304803
use and unbind it if it is otherwise call ldap_unbind_ext() to
304803
release the ldap connection.
304803
304803
Signed-off-by: Ian Kent <raven@themaw.net>
304803
---
304803
 CHANGELOG             |    1 +
304803
 modules/lookup_ldap.c |   17 ++++++++++-------
304803
 2 files changed, 11 insertions(+), 7 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -191,6 +191,7 @@
304803
 - fix rwlock unlock crash.
304803
 - fix handle_mounts() termination condition check.
304803
 - fix config old name lookup.
304803
+- fix error handling on ldap bind fail.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/modules/lookup_ldap.c
304803
+++ autofs-5.0.7/modules/lookup_ldap.c
304803
@@ -216,15 +216,18 @@ int bind_ldap_simple(unsigned logopt, LD
304803
 
304803
 int __unbind_ldap_connection(unsigned logopt, LDAP *ldap, struct lookup_context *ctxt)
304803
 {
304803
-	int rv;
304803
+	int rv = LDAP_SUCCESS;
304803
 
304803
 	if (ctxt->use_tls == LDAP_TLS_RELEASE)
304803
 		ctxt->use_tls = LDAP_TLS_INIT;
304803
 #ifdef WITH_SASL
304803
-	autofs_sasl_unbind(ctxt);
304803
-#endif
304803
-
304803
+	if (ctxt->auth_required & LDAP_NEED_AUTH)
304803
+		autofs_sasl_unbind(ctxt);
304803
+	else
304803
+		rv = ldap_unbind_ext(ldap, NULL, NULL);
304803
+#else
304803
 	rv = ldap_unbind_ext(ldap, NULL, NULL);
304803
+#endif
304803
 	if (rv != LDAP_SUCCESS)
304803
 		error(logopt, "unbind failed: %s", ldap_err2string(rv));
304803
 
304803
@@ -302,7 +305,7 @@ LDAP *__init_ldap_connection(unsigned lo
304803
 
304803
 		rv = ldap_start_tls_s(ldap, NULL, NULL);
304803
 		if (rv != LDAP_SUCCESS) {
304803
-			__unbind_ldap_connection(logopt, ldap, ctxt);
304803
+			ldap_unbind_ext(ldap, NULL, NULL);
304803
 			if (ctxt->tls_required) {
304803
 				error(logopt, MODPREFIX
304803
 				      "TLS required but START_TLS failed: %s",
304803
@@ -576,14 +579,13 @@ static int do_bind(unsigned logopt, LDAP
304803
 	char *host = NULL, *nhost;
304803
 	int rv;
304803
 
304803
+	ldapinit_mutex_lock();
304803
 #ifdef WITH_SASL
304803
 	debug(logopt, MODPREFIX "auth_required: %d, sasl_mech %s",
304803
 	      ctxt->auth_required, ctxt->sasl_mech);
304803
 
304803
 	if (ctxt->auth_required & LDAP_NEED_AUTH) {
304803
-		ldapinit_mutex_lock();
304803
 		rv = autofs_sasl_bind(logopt, ldap, ctxt);
304803
-		ldapinit_mutex_unlock();
304803
 		debug(logopt, MODPREFIX "autofs_sasl_bind returned %d", rv);
304803
 	} else {
304803
 		rv = bind_ldap_simple(logopt, ldap, uri, ctxt);
304803
@@ -593,6 +595,7 @@ static int do_bind(unsigned logopt, LDAP
304803
 	rv = bind_ldap_simple(logopt, ldap, uri, ctxt);
304803
 	debug(logopt, MODPREFIX "ldap simple bind returned %d", rv);
304803
 #endif
304803
+	ldapinit_mutex_unlock();
304803
 
304803
 	if (rv != 0)
304803
 		return 0;