Ensure we never wait past absolute entime to do a get_cached_ldap_connect().
authorJeremy Allison <jra@samba.org>
Sat, 20 Aug 2011 16:37:04 +0000 (09:37 -0700)
committerJeremy Allison <jra@samba.org>
Sat, 20 Aug 2011 18:09:37 +0000 (20:09 +0200)
Autobuild-User: Jeremy Allison <jra@samba.org>
Autobuild-Date: Sat Aug 20 20:09:37 CEST 2011 on sn-devel-104

source3/lib/smbldap.c

index bdf54fc00845c239a7c3581a20b5884c4ca7ebd8..b333f3063d0a73c8c86afeb7cc862c56fecdaf11 100644 (file)
@@ -1407,16 +1407,23 @@ static void get_ldap_errs(struct smbldap_state *ldap_state, char **pp_ld_error,
                        LDAP_OPT_ERROR_STRING, pp_ld_error);
 }
 
-static int get_cached_ldap_connect(struct smbldap_state *ldap_state)
+static int get_cached_ldap_connect(struct smbldap_state *ldap_state, time_t abs_endtime)
 {
        int attempts = 0;
 
        while (1) {
                int rc;
+               time_t now;
 
-               rc = smbldap_open(ldap_state);
+               now = time_mono(NULL);
+               ldap_state->last_use = now;
+
+               if (abs_endtime && now > abs_endtime) {
+                       smbldap_close(ldap_state);
+                       return LDAP_TIMEOUT;
+               }
 
-               ldap_state->last_use = time_mono(NULL);
+               rc = smbldap_open(ldap_state);
 
                if (rc == LDAP_SUCCESS) {
                        return LDAP_SUCCESS;
@@ -1511,7 +1518,7 @@ static int smbldap_search_ext(struct smbldap_state *ldap_state,
                char *ld_error = NULL;
                int ld_errno;
 
-               rc = get_cached_ldap_connect(ldap_state);
+               rc = get_cached_ldap_connect(ldap_state, abs_endtime);
                if (rc != LDAP_SUCCESS) {
                        break;
                }
@@ -1665,7 +1672,7 @@ int smbldap_modify(struct smbldap_state *ldap_state, const char *dn, LDAPMod *at
                char *ld_error = NULL;
                int ld_errno;
 
-               rc = get_cached_ldap_connect(ldap_state);
+               rc = get_cached_ldap_connect(ldap_state, abs_endtime);
                if (rc != LDAP_SUCCESS) {
                        break;
                }
@@ -1715,7 +1722,7 @@ int smbldap_add(struct smbldap_state *ldap_state, const char *dn, LDAPMod *attrs
                char *ld_error = NULL;
                int ld_errno;
 
-               rc = get_cached_ldap_connect(ldap_state);
+               rc = get_cached_ldap_connect(ldap_state, abs_endtime);
                if (rc != LDAP_SUCCESS) {
                        break;
                }
@@ -1765,7 +1772,7 @@ int smbldap_delete(struct smbldap_state *ldap_state, const char *dn)
                char *ld_error = NULL;
                int ld_errno;
 
-               rc = get_cached_ldap_connect(ldap_state);
+               rc = get_cached_ldap_connect(ldap_state, abs_endtime);
                if (rc != LDAP_SUCCESS) {
                        break;
                }
@@ -1811,7 +1818,7 @@ int smbldap_extended_operation(struct smbldap_state *ldap_state,
                char *ld_error = NULL;
                int ld_errno;
 
-               rc = get_cached_ldap_connect(ldap_state);
+               rc = get_cached_ldap_connect(ldap_state, abs_endtime);
                if (rc != LDAP_SUCCESS) {
                        break;
                }