]> git.sur5r.net Git - openldap/commitdiff
implement search timeout when the remote server does not respond in the specified...
authorPierangelo Masarati <ando@openldap.org>
Fri, 26 Jan 2007 00:40:54 +0000 (00:40 +0000)
committerPierangelo Masarati <ando@openldap.org>
Fri, 26 Jan 2007 00:40:54 +0000 (00:40 +0000)
servers/slapd/back-ldap/config.c
servers/slapd/back-ldap/search.c

index 215555372c24f6edbda7989e3b562ef5313fc2f3..27dabf6585a2853489abf17f03d663cbab226a2f 100644 (file)
@@ -381,9 +381,7 @@ static slap_cf_aux_table timeout_table[] = {
        { BER_BVC("modrdn="),   SLAP_OP_MODRDN * sizeof( time_t ),      'u', 0, NULL },
        { BER_BVC("modify="),   SLAP_OP_MODIFY * sizeof( time_t ),      'u', 0, NULL },
        { BER_BVC("compare="),  SLAP_OP_COMPARE * sizeof( time_t ),     'u', 0, NULL },
-#if 0  /* uses timelimit instead */
        { BER_BVC("search="),   SLAP_OP_SEARCH * sizeof( time_t ),      'u', 0, NULL },
-#endif
        /* abandon makes little sense */
 #if 0  /* not implemented yet */
        { BER_BVC("extended="), SLAP_OP_EXTENDED * sizeof( time_t ),    'u', 0, NULL },
index b4774e53a76ba2adb35c2cf77b2968af83ad45fa..ea3934437a1472ba24f5e815176795500a21c4e2 100644 (file)
@@ -256,12 +256,20 @@ retry:
                }
        }
 
+       /* if needed, initialize timeout */
+       if ( li->li_timeout[ SLAP_OP_SEARCH ] ) {
+               if ( tv.tv_sec == 0 || tv.tv_sec > li->li_timeout[ SLAP_OP_SEARCH ] ) {
+                       tv.tv_sec = li->li_timeout[ SLAP_OP_SEARCH ];
+                       tv.tv_usec = 0;
+               }
+       }
+
        /* We pull apart the ber result, stuff it into a slapd entry, and
         * let send_search_entry stuff it back into ber format. Slow & ugly,
         * but this is necessary for version matching, and for ACL processing.
         */
 
-       for ( rc = 0; rc != -1; rc = ldap_result( lc->lc_ld, msgid, LDAP_MSG_ONE, &tv, &res ) )
+       for ( rc = -2; rc != -1; rc = ldap_result( lc->lc_ld, msgid, LDAP_MSG_ONE, &tv, &res ) )
        {
                /* check for abandon */
                if ( op->o_abandon || LDAP_BACK_CONN_ABANDON( lc ) ) {
@@ -273,10 +281,22 @@ retry:
                        goto finish;
                }
 
-               if ( rc == 0 ) {
-                       LDAP_BACK_TV_SET( &tv );
+               if ( rc == 0 || rc == -2 ) {
                        ldap_pvt_thread_yield();
 
+                       /* check timeout */
+                       if ( li->li_timeout[ SLAP_OP_SEARCH ] ) {
+                               if ( rc == 0 ) {
+                                       (void)ldap_back_cancel( lc, op, rs, msgid, LDAP_BACK_DONTSEND );
+                                       rs->sr_text = "Operation timed out";
+                                       rc = rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
+                                       goto finish;
+                               }
+
+                       } else {
+                               LDAP_BACK_TV_SET( &tv );
+                       }
+
                        /* check time limit */
                        if ( op->ors_tlimit != SLAP_NO_LIMIT
                                        && slap_get_time() > stoptime )
@@ -437,6 +457,14 @@ retry:
                        rc = 0;
                        break;
                }
+
+               /* if needed, restore timeout */
+               if ( li->li_timeout[ SLAP_OP_SEARCH ] ) {
+                       if ( tv.tv_sec == 0 || tv.tv_sec > li->li_timeout[ SLAP_OP_SEARCH ] ) {
+                               tv.tv_sec = li->li_timeout[ SLAP_OP_SEARCH ];
+                               tv.tv_usec = 0;
+                       }
+               }
        }
 
        if ( rc == -1 && dont_retry == 0 ) {