Skip to content

Commit 5f19d13

Browse files
libpq: Set LDAP protocol version 3
Some LDAP servers reject the default version 2 protocol. So set version 3 before starting the connection. This matches how the backend LDAP code has worked all along. Co-authored-by: Andrew Jackson <andrewjackson947@gmail.com> Reviewed-by: Pavel Seleznev <pavel.seleznev@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/CAKK5BkHixcivSCA9pfd_eUp7wkLRhvQ6OtGLAYrWC%3Dk7E76LDQ%40mail.gmail.com
1 parent b227b0b commit 5f19d13

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5494,6 +5494,7 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
54945494
*entry;
54955495
struct berval **values;
54965496
LDAP_TIMEVAL time = {PGLDAP_TIMEOUT, 0};
5497+
int ldapversion = LDAP_VERSION3;
54975498

54985499
if ((url = strdup(purl)) == NULL)
54995500
{
@@ -5625,6 +5626,15 @@ ldapServiceLookup(const char *purl, PQconninfoOption *options,
56255626
return 3;
56265627
}
56275628

5629+
if ((rc = ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &ldapversion)) != LDAP_SUCCESS)
5630+
{
5631+
libpq_append_error(errorMessage, "could not set LDAP protocol version: %s",
5632+
ldap_err2string(rc));
5633+
free(url);
5634+
ldap_unbind(ld);
5635+
return 3;
5636+
}
5637+
56285638
/*
56295639
* Perform an explicit anonymous bind.
56305640
*

0 commit comments

Comments
 (0)