char prefix[128];
char suffix[128];
LDAP *ldap;
- int ssl = 0;
+ bool ssl = false;
int r;
int ldapversion = LDAP_VERSION3;
int ldapport = LDAP_PORT;
- char fulluser[128];
+ char fulluser[NAMEDATALEN + 256 + 1];
if (!port->auth_arg || port->auth_arg[0] == '\0')
{
"ldaps://%127[^:]:%i/%127[^;];%127[^;];%127s",
server, &ldapport, basedn, prefix, suffix);
if (r >= 3)
- ssl = 1;
+ ssl = true;
}
if (r < 3)
{
"ldaps://%127[^/]/%127[^;];%127[^;];%127s",
server, basedn, prefix, suffix);
if (r >= 2)
- ssl = 1;
+ ssl = true;
}
if (r < 2)
{
if ((r = ldap_set_option(ldap, LDAP_OPT_PROTOCOL_VERSION, &ldapversion)) != LDAP_SUCCESS)
{
+ ldap_unbind(ldap);
ereport(LOG,
- (errmsg("could not set LDAP protocol version: error code %d", r)));
+ (errmsg("could not set LDAP protocol version: error code %d", r)));
return STATUS_ERROR;
}
* should never happen since we import other files from
* wldap32, but check anyway
*/
+ ldap_unbind(ldap);
ereport(LOG,
(errmsg("could not load wldap32.dll")));
return STATUS_ERROR;
_ldap_start_tls_sA = (__ldap_start_tls_sA) GetProcAddress(ldaphandle, "ldap_start_tls_sA");
if (_ldap_start_tls_sA == NULL)
{
+ ldap_unbind(ldap);
ereport(LOG,
(errmsg("could not load function _ldap_start_tls_sA in wldap32.dll"),
errdetail("LDAP over SSL is not supported on this platform.")));
}
/*
- * Leak ldaphandle on purpose, because we need the library to stay
+ * Leak LDAP handle on purpose, because we need the library to stay
* open. This is ok because it will only ever be leaked once per
* process and is automatically cleaned up on process exit.
*/
if ((r = _ldap_start_tls_sA(ldap, NULL, NULL, NULL, NULL)) != LDAP_SUCCESS)
#endif
{
+ ldap_unbind(ldap);
ereport(LOG,
- (errmsg("could not start LDAP TLS session: error code %d", r)));
+ (errmsg("could not start LDAP TLS session: error code %d", r)));
return STATUS_ERROR;
}
}
- snprintf(fulluser, sizeof(fulluser) - 1, "%s%s%s",
+ snprintf(fulluser, sizeof(fulluser), "%s%s%s",
prefix, port->user_name, suffix);
fulluser[sizeof(fulluser) - 1] = '\0';