]> git.sur5r.net Git - openldap/commitdiff
check sizelimit in frontend (ITS#4213)
authorPierangelo Masarati <ando@openldap.org>
Fri, 25 Nov 2005 00:28:33 +0000 (00:28 +0000)
committerPierangelo Masarati <ando@openldap.org>
Fri, 25 Nov 2005 00:28:33 +0000 (00:28 +0000)
servers/slapd/back-bdb/search.c
servers/slapd/back-ldap/search.c
servers/slapd/back-ldbm/search.c
servers/slapd/back-meta/search.c
servers/slapd/back-monitor/search.c
servers/slapd/back-perl/search.c
servers/slapd/back-sql/search.c
servers/slapd/overlays/retcode.c
servers/slapd/result.c
servers/slapd/slap.h

index 3151d3d6aa3f9e8d4e7198d25532dc1b9f392658..9b7a94f2f2ab2b2410c1462948ca329b3fc81192 100644 (file)
@@ -858,21 +858,6 @@ fetch_entry_retry:
 
                if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
                        /* check size limit */
-                       if ( --op->ors_slimit == -1 ) {
-#ifdef SLAP_ZONE_ALLOC
-                               slap_zn_runlock(bdb->bi_cache.c_zctx, e);
-#endif
-                               bdb_cache_return_entry_r( bdb->bi_dbenv,
-                                               &bdb->bi_cache, e, &lock );
-                               e = NULL;
-                               rs->sr_entry = NULL;
-                               rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
-                               rs->sr_ref = rs->sr_v2ref;
-                               send_ldap_result( op, rs );
-                               rs->sr_err = LDAP_SUCCESS;
-                               goto done;
-                       }
-
                        if ( get_pagedresults(op) > SLAP_CONTROL_IGNORED ) {
                                if ( rs->sr_nentries >= ((PagedResultsState *)op->o_pagedresults_state)->ps_size ) {
 #ifdef SLAP_ZONE_ALLOC
@@ -897,12 +882,12 @@ fetch_entry_retry:
                                rs->sr_err = LDAP_SUCCESS;
                                result = send_search_entry( op, rs );
 
-                               switch (result) {
+                               switch ( result ) {
                                case 0:         /* entry sent ok */
                                        break;
                                case 1:         /* entry not sent */
                                        break;
-                               case -1:        /* connection closed */
+                               default:
 #ifdef SLAP_ZONE_ALLOC
                                        slap_zn_runlock(bdb->bi_cache.c_zctx, e);
 #endif
@@ -910,7 +895,17 @@ fetch_entry_retry:
                                                &bdb->bi_cache, e, &lock);
                                        e = NULL;
                                        rs->sr_entry = NULL;
-                                       rs->sr_err = LDAP_OTHER;
+                                       switch ( result ) {
+                                       case SLAPD_SEND_SIZELIMIT:
+                                               rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
+                                               rs->sr_ref = rs->sr_v2ref;
+                                               send_ldap_result( op, rs );
+                                               rs->sr_err = LDAP_SUCCESS;
+                                               break;
+                                       case -1:        /* connection closed */
+                                               rs->sr_err = LDAP_OTHER;
+                                               break;
+                                       }
                                        goto done;
                                }
                        }
index e1a88800860ed110c88f5ffa43f288d2cc833e3c..eb70948b443f353c8d0a94ed78c1fddb2269bd8d 100644 (file)
@@ -311,6 +311,9 @@ retry:
                        }
                        ldap_msgfree( res );
                        if ( abort ) {
+                               if ( abort == SLAPD_SEND_SIZELIMIT ) {
+                                       rc = rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
+                               }
                                ldap_abandon_ext( lc->lc_ld, msgid, NULL, NULL );
                                goto finish;
                        }
index 47e7886ee1a945c131ec298c6c3fd7f866b90fb2..75aa5347f783a463b8bd5e99d275c146e862a794 100644 (file)
@@ -430,21 +430,11 @@ searchit:
                        }
 
                        if ( scopeok ) {
-                               /* check size limit */
-                               if ( --op->ors_slimit == -1 ) {
-                                       cache_return_entry_r( &li->li_cache, e );
-                                       rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
-                                       rs->sr_entry = NULL;
-                                       send_ldap_result( op, rs );
-                                       rc = LDAP_SUCCESS;
-                                       goto done;
-                               }
-
                                if (e) {
                                        rs->sr_flags = 0;
                                        result = send_search_entry( op, rs );
 
-                                       switch (result) {
+                                       switch ( result ) {
                                        case 0:         /* entry sent ok */
                                                break;
                                        case 1:         /* entry not sent */
@@ -453,6 +443,13 @@ searchit:
                                                cache_return_entry_r( &li->li_cache, e );
                                                rc = LDAP_SUCCESS;
                                                goto done;
+                                       case SLAPD_SEND_SIZELIMIT:
+                                               cache_return_entry_r( &li->li_cache, e );
+                                               rc = rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
+                                               rs->sr_entry = NULL;
+                                               send_ldap_result( op, rs );
+                                               rc = LDAP_SUCCESS;
+                                               goto done;
                                        }
                                }
 
index 2f9fb3649704a5c56314a8d49ba17dc2283f8fd8..ae6e5c26160a904033076d5173b64d22332b7441 100644 (file)
@@ -451,29 +451,30 @@ really_bad:;
                                        candidates[ i ].sr_type = REP_RESULT;
                                }
 
-                               if ( --op->ors_slimit == -1 ) {
-                                       ldap_msgfree( res );
-                                       res = NULL;
+                               is_ok++;
+
+                               e = ldap_first_entry( msc->msc_ld, res );
+                               savepriv = op->o_private;
+                               op->o_private = (void *)i;
+                               rc = meta_send_entry( op, rs, mc, i, e );
+                               ldap_msgfree( res );
+                               res = NULL;
 
+                               switch ( rc ) {
+                               case SLAPD_SEND_SIZELIMIT:
                                        rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
                                        savepriv = op->o_private;
                                        op->o_private = (void *)i;
                                        send_ldap_result( op, rs );
                                        op->o_private = savepriv;
                                        goto finish;
-                               }
 
-                               is_ok++;
-
-                               e = ldap_first_entry( msc->msc_ld, res );
-                               savepriv = op->o_private;
-                               op->o_private = (void *)i;
-                               meta_send_entry( op, rs, mc, i, e );
+                               case -1:
+                                       rs->sr_err = LDAP_OTHER;
+                                       goto finish;
+                               }
                                op->o_private = savepriv;
 
-                               ldap_msgfree( res );
-                               res = NULL;
-
                                gotit = 1;
 
 #if 0
@@ -1155,7 +1156,21 @@ next_attr:;
        rs->sr_entry = &ent;
        rs->sr_attrs = op->ors_attrs;
        rs->sr_flags = 0;
-       send_search_entry( op, rs );
+       switch ( send_search_entry( op, rs ) ) {
+       case 0:
+       case 1:
+               rc = LDAP_SUCCESS;
+               break;
+       case -1:
+               rc = LDAP_OTHER;
+               break;
+       case SLAPD_SEND_SIZELIMIT:
+               rc = LDAP_SIZELIMIT_EXCEEDED;
+               break;
+       default:
+               /* trap other values when added... */
+               assert( 0 );
+       }
        rs->sr_entry = NULL;
        rs->sr_attrs = NULL;
        
@@ -1169,6 +1184,6 @@ next_attr:;
        }
        entry_clean( &ent );
 
-       return LDAP_SUCCESS;
+       return rc;
 }
 
index 591287d06cfc73777e2d4fe2c93b4bb44d903eb2..ab5c475c078404f5ca7be2e3c528d8c1aa708cdb 100644 (file)
@@ -113,7 +113,7 @@ monitor_send_children(
                if ( rc == LDAP_COMPARE_TRUE ) {
                        rs->sr_entry = e;
                        rs->sr_flags = 0;
-                       send_search_entry( op, rs );
+                       rc = send_search_entry( op, rs );
                        rs->sr_entry = NULL;
                }
 
index 33d48225538bfc1264cd6ba772b0315cdc97e6fd..565402172c73e4dc106af49259a8da2ce964b6c8 100644 (file)
@@ -84,10 +84,18 @@ perl_back_search(
                                                send_entry = 1;
 
                                        if (send_entry) {
+                                               int     rc;
+
                                                rs->sr_entry = e;
                                                rs->sr_attrs = op->ors_attrs;
                                                rs->sr_flags = REP_ENTRY_MODIFIABLE;
-                                               send_search_entry( op, rs );
+                                               rc = send_search_entry( op, rs );
+                                               switch ( rc ) {
+                                               case SLAPD_SEND_SIZELIMIT:
+                                                       rs->sr_entry = NULL;
+                                                       rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
+                                                       goto done2;
+                                               }
                                        }
 
                                        entry_free( e );
@@ -106,8 +114,7 @@ perl_back_search(
 
                rs->sr_err = POPi;
 
-
-
+done:;
                PUTBACK; FREETMPS; LEAVE;
        }
 
index 1f49f18b3ba59193abef54dff35b3c7f1812bf9c..7c001fbb2f80ad6c85570745ea0281e60ecbf11c 100644 (file)
@@ -2320,11 +2320,6 @@ backsql_search( Operation *op, SlapReply *rs )
 
                if ( test_filter( op, e, op->ors_filter ) == LDAP_COMPARE_TRUE )
                {
-                       if ( --op->ors_slimit == -1 ) {
-                               rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
-                               goto send_results;
-                       }
-
                        rs->sr_attrs = op->ors_attrs;
                        rs->sr_operational_attrs = NULL;
                        rs->sr_entry = e;
@@ -2335,7 +2330,8 @@ backsql_search( Operation *op, SlapReply *rs )
                        rs->sr_attrs = NULL;
                        rs->sr_operational_attrs = NULL;
 
-                       if ( sres == -1 ) {
+                       switch ( sres ) {
+                       case -1:
                                /*
                                 * FIXME: send_search_entry failed;
                                 * better stop
@@ -2343,6 +2339,10 @@ backsql_search( Operation *op, SlapReply *rs )
                                Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
                                        "connection lost\n", 0, 0, 0 );
                                goto end_of_search;
+
+                       case SLAPD_SEND_SIZELIMIT:
+                               rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
+                               goto send_results;
                        }
                }
 
index 845370a8123df3ab4ad5bd3112d26f907bb3c551..773ef0a37bb80e39d87e490d66f0b28cbbf072a8 100644 (file)
@@ -146,6 +146,10 @@ retcode_send_onelevel( Operation *op, SlapReply *rs )
                                rs->sr_entry = NULL;
                                rs->sr_err = LDAP_OTHER;
                                goto done;
+                       case SLAPD_SEND_SIZELIMIT:
+                               rs->sr_entry = NULL;
+                               rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
+                               goto done;
                        }
                }
                rs->sr_err = LDAP_SUCCESS;
index cb9e25ad7010cefb35d8cc36e86cef8c41814044..5b085af13821e5338034bb4f16640e588f3d7789 100644 (file)
@@ -662,6 +662,15 @@ slap_send_ldap_intermediate( Operation *op, SlapReply *rs )
        }
 }
 
+/*
+ * returns:
+ *
+ *  0                  entry sent
+ *  1                  entry not sent (other)
+ * -1                  entry not sent (connection closed)
+ * SLAPD_SEND_SIZELIMIT        entry not sent (caller must send sizelimitExceeded)
+ */
+
 int
 slap_send_search_entry( Operation *op, SlapReply *rs )
 {
@@ -1116,6 +1125,15 @@ slap_send_search_entry( Operation *op, SlapReply *rs )
        }
 
        if ( op->o_res_ber == NULL ) {
+               if ( --op->ors_slimit == -1 ) {
+                       rc = SLAPD_SEND_SIZELIMIT;
+                       ber_free_buf( ber );
+                       /* putback, so dumb backends that don't 
+                        * check sizelimit won't at least return
+                        * more than expected... */
+                       op->ors_slimit++;
+                       goto error_return;
+               }
                bytes = send_ldap_ber( op->o_conn, ber );
                ber_free_buf( ber );
 
index 5e59c0b2f993b8c23cb28cb44f0ff5be70adbed7..b6fc42d06abb6bb2fe46242d0363972a1c974af7 100644 (file)
@@ -153,6 +153,9 @@ LDAP_BEGIN_DECL
 /* unknown config file directive */
 #define SLAP_CONF_UNKNOWN (-1026)
 
+/* pseudo error code indicating caller should send sizelimitExceeded */
+#define SLAPD_SEND_SIZELIMIT (-1027)
+
 /* We assume "C" locale, that is US-ASCII */
 #define ASCII_SPACE(c) ( (c) == ' ' )
 #define ASCII_LOWER(c) ( (c) >= 'a' && (c) <= 'z' )
@@ -2252,8 +2255,8 @@ typedef struct slap_overinfo {
 } slap_overinfo;
 
 /* Should successive callbacks in a chain be processed? */
-#define        SLAP_CB_FREEME          0x4000
-#define        SLAP_CB_CONTINUE        0x8000
+#define        SLAP_CB_FREEME          0x04000
+#define        SLAP_CB_CONTINUE        0x08000
 
 /*
  * Paged Results state