summaryrefslogtreecommitdiff
path: root/source3/libads
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2011-08-19 18:43:51 -0700
committerJeremy Allison <jra@samba.org>2011-08-19 18:43:51 -0700
commit92a655da8633ab99c2a3fa75b3a55ffd8b4ef430 (patch)
treea63a77f26bbc870d783c544bd6838fca34248aab /source3/libads
parentf6e3484ba6350204cee0e0a85500b5ebb22fa4db (diff)
downloadsamba-92a655da8633ab99c2a3fa75b3a55ffd8b4ef430.tar.gz
samba-92a655da8633ab99c2a3fa75b3a55ffd8b4ef430.tar.bz2
samba-92a655da8633ab99c2a3fa75b3a55ffd8b4ef430.zip
If "ldap timeout" is non-zero, set the local search timeout to
be one second longer than the remote search timeout (which is set to the "ldap timeout" value). This allows the remote search timeout to fire in preference. Allow lp_ldap_timeout() to be zero. Don't set the any local alarm if so.
Diffstat (limited to 'source3/libads')
-rw-r--r--source3/libads/ldap.c55
1 files changed, 36 insertions, 19 deletions
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c
index 11e4261ee5..870d4bc11d 100644
--- a/source3/libads/ldap.c
+++ b/source3/libads/ldap.c
@@ -100,11 +100,13 @@ static void gotalarm_sig(int signum)
}
#endif
- /* Setup timeout */
- gotalarm = 0;
- CatchSignal(SIGALRM, gotalarm_sig);
- alarm(to);
- /* End setup timeout. */
+ if (to) {
+ /* Setup timeout */
+ gotalarm = 0;
+ CatchSignal(SIGALRM, gotalarm_sig);
+ alarm(to);
+ /* End setup timeout. */
+ }
ldp = ldap_open(server, port);
@@ -115,9 +117,11 @@ static void gotalarm_sig(int signum)
DEBUG(10, ("Connected to LDAP server '%s:%d'\n", server, port));
}
- /* Teardown timeout. */
- CatchSignal(SIGALRM, SIG_IGN);
- alarm(0);
+ if (to) {
+ /* Teardown timeout. */
+ alarm(0);
+ CatchSignal(SIGALRM, SIG_IGN);
+ }
return ldp;
}
@@ -133,26 +137,39 @@ static int ldap_search_with_timeout(LDAP *ld,
int sizelimit,
LDAPMessage **res )
{
+ int to = lp_ldap_timeout();
struct timeval timeout;
+ struct timeval *timeout_ptr = NULL;
int result;
/* Setup timeout for the ldap_search_ext_s call - local and remote. */
- timeout.tv_sec = lp_ldap_timeout();
- timeout.tv_usec = 0;
-
- /* Setup alarm timeout.... Do we need both of these ? JRA. */
gotalarm = 0;
- CatchSignal(SIGALRM, gotalarm_sig);
- alarm(lp_ldap_timeout());
- /* End setup timeout. */
+
+ if (to) {
+ timeout.tv_sec = to;
+ timeout.tv_usec = 0;
+ timeout_ptr = &timeout;
+
+ /* Setup alarm timeout. */
+ CatchSignal(SIGALRM, gotalarm_sig);
+ /* Make the alarm time one second beyond
+ the timout we're setting for the
+ remote search timeout, to allow that
+ to fire in preference. */
+ alarm(to+1);
+ /* End setup timeout. */
+ }
+
result = ldap_search_ext_s(ld, base, scope, filter, attrs,
- attrsonly, sctrls, cctrls, &timeout,
+ attrsonly, sctrls, cctrls, timeout_ptr,
sizelimit, res);
- /* Teardown timeout. */
- CatchSignal(SIGALRM, SIG_IGN);
- alarm(0);
+ if (to) {
+ /* Teardown alarm timeout. */
+ CatchSignal(SIGALRM, SIG_IGN);
+ alarm(0);
+ }
if (gotalarm != 0)
return LDAP_TIMELIMIT_EXCEEDED;