From 92a655da8633ab99c2a3fa75b3a55ffd8b4ef430 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Aug 2011 18:43:51 -0700 Subject: 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. --- source3/libads/ldap.c | 55 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'source3/libads/ldap.c') 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; -- cgit