]> git.sur5r.net Git - openldap/commitdiff
honor TIMEOUT when appropriate (ITS#7009); also honor timelimit (was broken)
authorPierangelo Masarati <ando@OpenLDAP.org>
Wed, 10 Aug 2011 20:39:16 +0000 (22:39 +0200)
committerQuanah Gibson-Mount <quanah@openldap.org>
Wed, 5 Oct 2011 23:45:49 +0000 (16:45 -0700)
clients/tools/ldapsearch.c

index 1689f61c1582377300a08f54cfdd8811228c6005..271a1bec726df0848daae9887105a960e1d79ce5 100644 (file)
@@ -1394,6 +1394,8 @@ static int dosearch(
        struct berval           *retdata = NULL;
        int                     nresponses_psearch = -1;
        int                     cancel_msgid = -1;
+       struct timeval tv, *tvp = NULL;
+       struct timeval tv_timelimit, *tv_timelimitp = NULL;
 
        if( filtpatt != NULL ) {
                size_t max_fsize = strlen( filtpatt ) + strlen( value ) + 1, outlen;
@@ -1429,8 +1431,14 @@ static int dosearch(
                return LDAP_SUCCESS;
        }
 
+       if ( timelimit > 0 ) {
+               tv_timelimit.tv_sec = timelimit;
+               tv_timelimit.tv_usec = 0;
+               tv_timelimitp = &tv_timelimit;
+       }
+
        rc = ldap_search_ext( ld, base, scope, filter, attrs, attrsonly,
-               sctrls, cctrls, timeout, sizelimit, &msgid );
+               sctrls, cctrls, tv_timelimitp, sizelimit, &msgid );
 
        if ( filtpatt != NULL ) {
                free( filter );
@@ -1446,9 +1454,16 @@ static int dosearch(
 
        res = NULL;
 
+       if ( timelimit > 0 ) {
+               /* disable timeout */
+               tv.tv_sec = -1;
+               tv.tv_usec = 0;
+               tvp = &tv;
+       }
+
        while ((rc = ldap_result( ld, LDAP_RES_ANY,
                sortattr ? LDAP_MSG_ALL : LDAP_MSG_ONE,
-               NULL, &res )) > 0 )
+               tvp, &res )) > 0 )
        {
                rc = tool_check_abandon( ld, msgid );
                if ( rc ) {
@@ -1544,7 +1559,11 @@ static int dosearch(
        }
 
 done:
-       if ( rc == -1 ) {
+       if ( tvp == NULL && rc == 0 ) {
+               ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void *)&rc );
+       }
+
+       if ( rc != 0 ) {
                tool_perror( "ldap_result", rc, NULL, NULL, NULL, NULL );
                return( rc );
        }