# define LDAP_OPT_SUCCESS LDAP_SUCCESS
#endif
+#define DB_LDAP_REQUEST_MAX_ATTEMPT_COUNT 3
+
static const char *LDAP_ESCAPE_CHARS = "*,\\#+<>;\"()= ";
struct db_ldap_result {
break;
}
- switch (request->type) {
- case LDAP_REQUEST_TYPE_BIND:
- ret = db_ldap_request_bind(conn, request);
- break;
- case LDAP_REQUEST_TYPE_SEARCH:
- ret = db_ldap_request_search(conn, request);
- break;
+ if (request->send_count >= DB_LDAP_REQUEST_MAX_ATTEMPT_COUNT) {
+ /* Enough many times retried. Server just keeps disconnecting
+ whenever attempting to send the request. */
+ ret = 0;
+ } else {
+ switch (request->type) {
+ case LDAP_REQUEST_TYPE_BIND:
+ ret = db_ldap_request_bind(conn, request);
+ break;
+ case LDAP_REQUEST_TYPE_SEARCH:
+ ret = db_ldap_request_search(conn, request);
+ break;
+ }
}
if (ret > 0) {
/* success */
i_assert(request->msgid != -1);
+ request->send_count++;
conn->pending_count++;
return TRUE;
} else if (ret < 0) {
/* timestamp when request was created */
time_t create_time;
+ /* Number of times this request has been sent to LDAP server. This
+ increases when LDAP gets disconnected and reconnect send the request
+ again. */
+ unsigned int send_count;
+
bool failed:1;
/* This is to prevent double logging the result */
bool result_logged:1;