static struct ldap_connection *ldap_connections = NULL;
static int ldap_conn_open(struct ldap_connection *conn);
+static void ldap_conn_close(struct ldap_connection *conn);
static int deref2str(const char *str)
{
if (ret < 0) {
i_error("LDAP: ldap_result() failed: %s",
get_ldap_error(conn));
+ /* reconnect */
+ ldap_conn_close(conn);
}
return;
}
until it's done. */
ret = ldap_simple_bind_s(conn->ld, conn->set.dn, conn->set.dnpass);
if (ret != LDAP_SUCCESS) {
- i_error("LDAP: ldap_simple_bind_s() failed: %s",
- ldap_err2string(ret));
+ if (ret == LDAP_SERVER_DOWN) {
+ i_error("LDAP: Can't connect to server: %s",
+ conn->set.hosts);
+ } else {
+ i_error("LDAP: ldap_simple_bind_s() failed: %s",
+ ldap_err2string(ret));
+ }
return FALSE;
}
password = NULL;
- entry = ldap_first_entry(conn->ld, res);
- if (entry == NULL)
- i_error("ldap(%s): unknown user", user);
- else {
+ entry = res == NULL ? NULL : ldap_first_entry(conn->ld, res);
+ if (entry == NULL) {
+ if (res != NULL)
+ i_error("ldap(%s): unknown user", user);
+ } else {
attr = ldap_first_attribute(conn->ld, entry, &ber);
while (attr != NULL) {
vals = ldap_get_values(conn->ld, entry, attr);
BerElement *ber;
char *attr, **vals;
- entry = ldap_first_entry(conn->ld, res);
+ entry = res == NULL ? NULL : ldap_first_entry(conn->ld, res);
if (entry == NULL) {
- i_error("LDAP: ldap_first_entry failed()");
+ if (res != NULL)
+ i_error("LDAP: Authenticated user not found");
urequest->userdb_callback(NULL, request->context);
return;
}