#else
#ifdef HAVE_LDAP_INITIALIZE
{
- char *uri;
+ const char *hostnames = port->hba->ldapserver;
+ char *uris = NULL;
- uri = psprintf("%s://%s:%d", scheme, port->hba->ldapserver,
- port->hba->ldapport);
- r = ldap_initialize(ldap, uri);
- pfree(uri);
+ /*
+ * We have a space-separated list of hostnames. Convert it
+ * to a space-separated list of URIs.
+ */
+ do
+ {
+ const char *hostname;
+ size_t hostname_size;
+ char *new_uris;
+
+ /* Find the leading hostname. */
+ hostname_size = strcspn(hostnames, " ");
+ hostname = pnstrdup(hostnames, hostname_size);
+
+ /* Append a URI for this hostname. */
+ new_uris = psprintf("%s%s%s://%s:%d",
+ uris ? uris : "",
+ uris ? " " : "",
+ scheme,
+ hostname,
+ port->hba->ldapport);
+
+ pfree(hostname);
+ if (uris)
+ pfree(uris);
+ uris = new_uris;
+
+ /* Step over this hostname and any spaces. */
+ hostnames += hostname_size;
+ while (*hostnames == ' ')
+ ++hostnames;
+ } while (*hostnames);
+
+ r = ldap_initialize(ldap, uris);
+ pfree(uris);
if (r != LDAP_SUCCESS)
{
ereport(LOG,
if ($ENV{with_ldap} eq 'yes')
{
- plan tests => 19;
+ plan tests => 22;
}
else
{
$ENV{"PGPASSWORD"} = 'secret1';
test_access($node, 'test1', 0, 'search+bind authentication succeeds');
+note "multiple servers";
+
+unlink($node->data_dir . '/pg_hba.conf');
+$node->append_conf('pg_hba.conf',
+ qq{local all all ldap ldapserver="$ldap_server $ldap_server" ldapport=$ldap_port ldapbasedn="$ldap_basedn"}
+);
+$node->restart;
+
+$ENV{"PGPASSWORD"} = 'wrong';
+test_access($node, 'test0', 2,
+ 'search+bind authentication fails if user not found in LDAP');
+test_access($node, 'test1', 2,
+ 'search+bind authentication fails with wrong password');
+$ENV{"PGPASSWORD"} = 'secret1';
+test_access($node, 'test1', 0, 'search+bind authentication succeeds');
+
note "LDAP URLs";
unlink($node->data_dir . '/pg_hba.conf');