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

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