Skip to content

Commit f8d03ea

Browse files
committed
Remove unnecessary unbind in LDAP search+bind mode
Comments in src/backend/libpq/auth.c say: (after successfully finding the final DN to check the user-supplied password against) /* Unbind and disconnect from the LDAP server */ and later /* * Need to re-initialize the LDAP connection, so that we can bind to * it with a different username. */ But the protocol actually permits multiple subsequent authentications ("binds") over a single connection. So, it seems like the whole connection re-initialization thing was just a confusion and can be safely removed, thus saving quite a few network round-trips, especially for the case of ldaps/starttls. Author: Anatoly Zaretsky <anatoly.zaretsky@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/CALbq6kmJ-1+58df4B51ctPfTOSyPbY8Qi2=ct8oR=i4TamkUoQ@mail.gmail.com
1 parent 89333db commit f8d03ea

File tree

2 files changed

+3
-28
lines changed

2 files changed

+3
-28
lines changed

doc/src/sgml/client-auth.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,13 +1775,13 @@ omicron bryanh guest1
17751775
do an exact match of the attribute specified in
17761776
<replaceable>ldapsearchattribute</replaceable>.
17771777
Once the user has been found in
1778-
this search, the server disconnects and re-binds to the directory as
1778+
this search, the server re-binds to the directory as
17791779
this user, using the password specified by the client, to verify that the
17801780
login is correct. This mode is the same as that used by LDAP authentication
17811781
schemes in other software, such as Apache <literal>mod_authnz_ldap</literal> and <literal>pam_ldap</literal>.
17821782
This method allows for significantly more flexibility
17831783
in where the user objects are located in the directory, but will cause
1784-
two separate connections to the LDAP server to be made.
1784+
two additional requests to the LDAP server to be made.
17851785
</para>
17861786

17871787
<para>
@@ -2008,7 +2008,7 @@ host ... ldap ldapserver=ldap.example.net ldapbasedn="dc=example, dc=net" ldapse
20082008
the LDAP server, perform a search for <literal>(uid=someuser)</literal>
20092009
under the specified base DN. If an entry is found, it will then attempt to
20102010
bind using that found information and the password supplied by the client.
2011-
If that second connection succeeds, the database access is granted.
2011+
If that second bind succeeds, the database access is granted.
20122012
</para>
20132013

20142014
<para>

src/backend/libpq/auth.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,31 +2611,6 @@ CheckLDAPAuth(Port *port)
26112611
pfree(filter);
26122612
ldap_memfree(dn);
26132613
ldap_msgfree(search_message);
2614-
2615-
/* Unbind and disconnect from the LDAP server */
2616-
r = ldap_unbind_s(ldap);
2617-
if (r != LDAP_SUCCESS)
2618-
{
2619-
ereport(LOG,
2620-
(errmsg("could not unbind after searching for user \"%s\" on server \"%s\"",
2621-
fulluser, server_name)));
2622-
pfree(passwd);
2623-
pfree(fulluser);
2624-
return STATUS_ERROR;
2625-
}
2626-
2627-
/*
2628-
* Need to re-initialize the LDAP connection, so that we can bind to
2629-
* it with a different username.
2630-
*/
2631-
if (InitializeLDAPConnection(port, &ldap) == STATUS_ERROR)
2632-
{
2633-
pfree(passwd);
2634-
pfree(fulluser);
2635-
2636-
/* Error message already sent */
2637-
return STATUS_ERROR;
2638-
}
26392614
}
26402615
else
26412616
fulluser = psprintf("%s%s%s",

0 commit comments

Comments
 (0)