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

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