Improve some LDAP authentication error messages

This commit is contained in:
Peter Eisentraut 2012-10-02 23:25:05 -04:00
parent ce75457949
commit 6bd176095b

View File

@ -2161,6 +2161,7 @@ CheckLDAPAuth(Port *port)
char *attributes[2]; char *attributes[2];
char *dn; char *dn;
char *c; char *c;
int count;
/* /*
* Disallow any characters that we would otherwise need to escape, * Disallow any characters that we would otherwise need to escape,
@ -2223,17 +2224,21 @@ CheckLDAPAuth(Port *port)
return STATUS_ERROR; return STATUS_ERROR;
} }
if (ldap_count_entries(ldap, search_message) != 1) count = ldap_count_entries(ldap, search_message);
if (count != 1)
{ {
if (ldap_count_entries(ldap, search_message) == 0) if (count == 0)
ereport(LOG, ereport(LOG,
(errmsg("LDAP search failed for filter \"%s\" on server \"%s\": no such user", (errmsg("LDAP user \"%s\" does not exist", port->user_name),
filter, port->hba->ldapserver))); errdetail("LDAP search for filter \"%s\" on server \"%s\" returned no entries.",
filter, port->hba->ldapserver)));
else else
ereport(LOG, ereport(LOG,
(errmsg("LDAP search failed for filter \"%s\" on server \"%s\": user is not unique (%ld matches)", (errmsg("LDAP user \"%s\" is not unique", port->user_name),
filter, port->hba->ldapserver, errdetail_plural("LDAP search for filter \"%s\" on server \"%s\" returned %d entry.",
(long) ldap_count_entries(ldap, search_message)))); "LDAP search for filter \"%s\" on server \"%s\" returned %d entries.",
count,
filter, port->hba->ldapserver, count)));
pfree(filter); pfree(filter);
ldap_msgfree(search_message); ldap_msgfree(search_message);