summaryrefslogtreecommitdiff
path: root/source3/lib/smbldap.c
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2003-12-25 22:42:15 +0000
committerVolker Lendecke <vlendec@samba.org>2003-12-25 22:42:15 +0000
commit3a1b189a9f3d2dab1fcadc5277546baa2f88cdfa (patch)
tree3e48bfc05937942da22e92990aedd70d010434d9 /source3/lib/smbldap.c
parent38d0c9698fd60ed46432bc30a110b820eb9aebb6 (diff)
downloadsamba-3a1b189a9f3d2dab1fcadc5277546baa2f88cdfa.tar.gz
samba-3a1b189a9f3d2dab1fcadc5277546baa2f88cdfa.tar.bz2
samba-3a1b189a9f3d2dab1fcadc5277546baa2f88cdfa.zip
This is metze's LDAP rebind sleep patch:
When smb.conf tells us to write to a read-only LDAP replica and we are redirected by the LDAP server, the replication might take some seconds, especially over slow links. This patch delays the next read after a rebind for 'ldap rebind sleep' milliseconds. Metze, thanks for your patience. Volker (This used to be commit 63ffa770b67d700f138d19b4982da152f57674fc)
Diffstat (limited to 'source3/lib/smbldap.c')
-rw-r--r--source3/lib/smbldap.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c
index da409dce04..d1117046c3 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -661,6 +661,9 @@ static int rebindproc_with_state (LDAP * ld, char **whop, char **credp,
}
*methodp = LDAP_AUTH_SIMPLE;
}
+
+ gettimeofday(&(ldap_state->last_rebind),NULL);
+
return 0;
}
#endif /*defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000)*/
@@ -687,6 +690,8 @@ static int rebindproc_connect_with_state (LDAP *ldap_struct,
rc = ldap_simple_bind_s(ldap_struct, ldap_state->bind_dn, ldap_state->bind_secret);
+ gettimeofday(&(ldap_state->last_rebind),NULL);
+
return rc;
}
#endif /*defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000)*/
@@ -909,6 +914,29 @@ int smbldap_search(struct smbldap_state *ldap_state,
SMB_ASSERT(ldap_state);
+ if (ldap_state->last_rebind.tv_sec > 0) {
+ struct timeval tval;
+ int tdiff = 0;
+ int sleep_time = 0;
+
+ ZERO_STRUCT(tval);
+
+ gettimeofday(&tval,NULL);
+
+ tdiff = 1000000 *(tval.tv_sec - ldap_state->last_rebind.tv_sec) +
+ (tval.tv_usec - ldap_state->last_rebind.tv_usec);
+
+ sleep_time = ((1000*lp_ldap_rebind_sleep())-tdiff)/1000;
+
+ if (sleep_time > 0) {
+ /* we wait for the LDAP replication */
+ DEBUG(5,("smbldap_search: waiting %d milliseconds for LDAP replication.\n",sleep_time));
+ msleep(sleep_time);
+ DEBUG(5,("smbldap_search: go on!\n"));
+ ZERO_STRUCT(ldap_state->last_rebind);
+ }
+ }
+
if (push_utf8_allocate(&utf8_filter, filter) == (size_t)-1) {
return LDAP_NO_MEMORY;
}