Skip to content

Commit c3fb580

Browse files
committed
Replace loading of ldap_start_tls_sA() by direct function call
This change impacts the backend-side code in charge of starting a LDAP TLS session. It is a bit sad that it is not possible to unify the WIN32 and non-WIN32 code paths, but the different number of arguments for both discard this possibility. This is similar to 47bd0b3, where this replaces the last function loading that seems worth it, any others being either environment or version-dependent. Reported-by: Thomas Munro Reviewed-by: Thomas Munro Discussion: https://postgr.es/m/Yx0rxpNgDh8tN4XA@paquier.xyz
1 parent 857808a commit c3fb580

File tree

1 file changed

+1
-50
lines changed

1 file changed

+1
-50
lines changed

src/backend/libpq/auth.c

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,6 @@ static int CheckBSDAuth(Port *port, char *user);
135135
#else
136136
#include <winldap.h>
137137

138-
/* Correct header from the Platform SDK */
139-
typedef
140-
ULONG (*__ldap_start_tls_sA) (IN PLDAP ExternalHandle,
141-
OUT PULONG ServerReturnValue,
142-
OUT LDAPMessage **result,
143-
IN PLDAPControlA * ServerControls,
144-
IN PLDAPControlA * ClientControls
145-
);
146138
#endif
147139

148140
static int CheckLDAPAuth(Port *port);
@@ -2348,48 +2340,7 @@ InitializeLDAPConnection(Port *port, LDAP **ldap)
23482340
#ifndef WIN32
23492341
if ((r = ldap_start_tls_s(*ldap, NULL, NULL)) != LDAP_SUCCESS)
23502342
#else
2351-
static __ldap_start_tls_sA _ldap_start_tls_sA = NULL;
2352-
2353-
if (_ldap_start_tls_sA == NULL)
2354-
{
2355-
/*
2356-
* Need to load this function dynamically because it may not exist
2357-
* on Windows, and causes a load error for the whole exe if
2358-
* referenced.
2359-
*/
2360-
HANDLE ldaphandle;
2361-
2362-
ldaphandle = LoadLibrary("WLDAP32.DLL");
2363-
if (ldaphandle == NULL)
2364-
{
2365-
/*
2366-
* should never happen since we import other files from
2367-
* wldap32, but check anyway
2368-
*/
2369-
ereport(LOG,
2370-
(errmsg("could not load library \"%s\": error code %lu",
2371-
"WLDAP32.DLL", GetLastError())));
2372-
ldap_unbind(*ldap);
2373-
return STATUS_ERROR;
2374-
}
2375-
_ldap_start_tls_sA = (__ldap_start_tls_sA) (pg_funcptr_t) GetProcAddress(ldaphandle, "ldap_start_tls_sA");
2376-
if (_ldap_start_tls_sA == NULL)
2377-
{
2378-
ereport(LOG,
2379-
(errmsg("could not load function _ldap_start_tls_sA in wldap32.dll"),
2380-
errdetail("LDAP over SSL is not supported on this platform.")));
2381-
ldap_unbind(*ldap);
2382-
FreeLibrary(ldaphandle);
2383-
return STATUS_ERROR;
2384-
}
2385-
2386-
/*
2387-
* Leak LDAP handle on purpose, because we need the library to
2388-
* stay open. This is ok because it will only ever be leaked once
2389-
* per process and is automatically cleaned up on process exit.
2390-
*/
2391-
}
2392-
if ((r = _ldap_start_tls_sA(*ldap, NULL, NULL, NULL, NULL)) != LDAP_SUCCESS)
2343+
if ((r = ldap_start_tls_s(*ldap, NULL, NULL, NULL, NULL)) != LDAP_SUCCESS)
23932344
#endif
23942345
{
23952346
ereport(LOG,

0 commit comments

Comments
 (0)