File 0001-auth-Introduce-db_ldap_bind_sasl-function.patch of Package dovecot22.3550

From 372b7c40bf035413dd3b9677f8f50f692b3602f0 Mon Sep 17 00:00:00 2001
From: "Matwey V. Kornilov" <matwey.kornilov@gmail.com>
Date: Wed, 21 Sep 2016 10:50:02 +0300
Subject: [PATCH 1/2] auth: Introduce db_ldap_bind_sasl() function

Do refactoring in db_ldap_connect() before fixing the SASL bind issue in the next commit.
---
 src/auth/db-ldap.c | 55 ++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 35 insertions(+), 20 deletions(-)

Index: dovecot-2.2.13/src/auth/db-ldap.c
===================================================================
--- dovecot-2.2.13.orig/src/auth/db-ldap.c
+++ dovecot-2.2.13/src/auth/db-ldap.c
@@ -988,6 +988,40 @@ static void ldap_connection_timeout(stru
 	db_ldap_conn_close(conn);
 }
 
+#ifdef HAVE_LDAP_SASL
+static int db_ldap_bind_sasl(struct ldap_connection *conn)
+{
+	struct db_ldap_sasl_bind_context context;
+	int ret;
+
+	memset(&context, 0, sizeof(context));
+	context.authcid = conn->set.dn;
+	context.passwd = conn->set.dnpass;
+	context.realm = conn->set.sasl_realm;
+	context.authzid = conn->set.sasl_authz_id;
+
+	/* There doesn't seem to be a way to do SASL binding
+	   asynchronously.. */
+	ret = ldap_sasl_interactive_bind_s(conn->ld, NULL,
+					   conn->set.sasl_mech,
+					   NULL, NULL, LDAP_SASL_QUIET,
+					   sasl_interact, &context);
+	if (db_ldap_connect_finish(conn, ret) < 0)
+		return -1;
+	
+	conn->conn_state = LDAP_CONN_STATE_BOUND_DEFAULT;
+
+	return 0;
+}
+#else
+static int db_ldap_bind_sasl(struct ldap_connection *conn)
+{
+	i_unreached(); /* already checked at init */
+
+	return -1;
+}
+#endif
+
 static int db_ldap_bind(struct ldap_connection *conn)
 {
 	int msgid;
@@ -1171,27 +1205,8 @@ int db_ldap_connect(struct ldap_connecti
 	}
 
 	if (conn->set.sasl_bind) {
-#ifdef HAVE_LDAP_SASL
-		struct db_ldap_sasl_bind_context context;
-
-		memset(&context, 0, sizeof(context));
-		context.authcid = conn->set.dn;
-		context.passwd = conn->set.dnpass;
-		context.realm = conn->set.sasl_realm;
-		context.authzid = conn->set.sasl_authz_id;
-
-		/* There doesn't seem to be a way to do SASL binding
-		   asynchronously.. */
-		ret = ldap_sasl_interactive_bind_s(conn->ld, NULL,
-						   conn->set.sasl_mech,
-						   NULL, NULL, LDAP_SASL_QUIET,
-						   sasl_interact, &context);
-		if (db_ldap_connect_finish(conn, ret) < 0)
+		if (db_ldap_bind_sasl(conn) < 0)
 			return -1;
-#else
-		i_fatal("LDAP: sasl_bind=yes but no SASL support compiled in");
-#endif
-		conn->conn_state = LDAP_CONN_STATE_BOUND_DEFAULT;
 	} else {
 		if (db_ldap_bind(conn) < 0)
 			return -1;
openSUSE Build Service is sponsored by