Skip to content

Commit

Permalink
auth: Fix default SASL bind for LDAP
Browse files Browse the repository at this point in the history
User may configure Dovecot to use SASL bind as default bind method.  This can
be the case when ldapi:/// (or ldaps:///) with SASL EXTERNAL is used.
Currently, Dovecot returns LDAP connection to wrong bind state after first
successful auth bind, LDAP simple bind always used to rebind.  This may broke
setup when ACL in LDAP configured not to allow search/bind for such simple
bind.
  • Loading branch information
matwey authored and sirainen committed Oct 13, 2016
1 parent aae4595 commit 79d9a65
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/auth/db-ldap.c
Expand Up @@ -1027,7 +1027,7 @@ static int db_ldap_bind_sasl(struct ldap_connection *conn)
}
#endif

static int db_ldap_bind(struct ldap_connection *conn)
static int db_ldap_bind_simple(struct ldap_connection *conn)
{
int msgid;

Expand Down Expand Up @@ -1056,6 +1056,19 @@ static int db_ldap_bind(struct ldap_connection *conn)
return 0;
}

static int db_ldap_bind(struct ldap_connection *conn)
{
if (conn->set.sasl_bind) {
if (db_ldap_bind_sasl(conn) < 0)
return -1;
} else {
if (db_ldap_bind_simple(conn) < 0)
return -1;
}

return 0;
}

static void db_ldap_get_fd(struct ldap_connection *conn)
{
int ret;
Expand Down Expand Up @@ -1228,13 +1241,9 @@ int db_ldap_connect(struct ldap_connection *conn)
#endif
}

if (conn->set.sasl_bind) {
if (db_ldap_bind_sasl(conn) < 0)
return -1;
} else {
if (db_ldap_bind(conn) < 0)
return -1;
}
if (db_ldap_bind(conn) < 0)
return -1;

if (debug) {
if (gettimeofday(&end, NULL) == 0) {
int msecs = timeval_diff_msecs(&end, &start);
Expand Down

0 comments on commit 79d9a65

Please sign in to comment.