]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/search.c
ITS#3092: Rename sl_free() and friends to slap_sl_free()
[openldap] / servers / slapd / back-bdb / search.c
index 69beb1a52768beaf4f1df62d4dbabd84cf830933..6261501258fd0e8ed3e3be6cab1742f8d5589630 100644 (file)
@@ -330,7 +330,7 @@ bdb_abandon( Operation *op, SlapReply *rs )
        ps = bdb_drop_psearch( op, op->oq_abandon.rs_msgid );
        if ( ps ) {
                if ( ps->o_tmpmemctx ) {
-                       sl_mem_destroy( NULL, ps->o_tmpmemctx );
+                       slap_sl_mem_destroy( NULL, ps->o_tmpmemctx );
                }
                slap_op_free ( ps );
                return LDAP_SUCCESS;
@@ -348,7 +348,7 @@ bdb_cancel( Operation *op, SlapReply *rs )
                rs->sr_err = LDAP_CANCELLED;
                send_ldap_result( ps, rs );
                if ( ps->o_tmpmemctx ) {
-                       sl_mem_destroy( NULL, ps->o_tmpmemctx );
+                       slap_sl_mem_destroy( NULL, ps->o_tmpmemctx );
                }
                slap_op_free ( ps );
                return LDAP_SUCCESS;
@@ -373,20 +373,19 @@ bdb_do_search( Operation *op, SlapReply *rs, Operation *sop,
        ID              id, cursor;
        ID              candidates[BDB_IDL_UM_SIZE];
        ID              scopes[BDB_IDL_DB_SIZE];
-       Entry           *e = NULL, base;
-       Entry   *matched = NULL;
-       EntryInfo       *ei;
-       struct berval   realbase = { 0, NULL };
+       Entry           *e = NULL, base, e_root = {0};
+       Entry           *matched = NULL;
+       EntryInfo       *ei, ei_root = {0};
+       struct berval   realbase = BER_BVNULL;
        int             manageDSAit;
        int             tentries = 0;
        ID              lastid = NOID;
        AttributeName   *attrs;
 
-       Filter contextcsnand, contextcsnle, cookief, csnfnot,
-               csnfeq, csnfand, csnfge;
+       Filter          contextcsnand, contextcsnle, cookief, csnfnot,
+                       csnfeq, csnfand, csnfge;
        AttributeAssertion aa_ge, aa_eq, aa_le;
-       int             entry_count = 0;
-       struct berval *search_context_csn = NULL;
+       struct berval   *search_context_csn = NULL;
        DB_LOCK         ctxcsn_lock;
        LDAPControl     *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
        int             num_ctrls = 0;
@@ -395,8 +394,6 @@ bdb_do_search( Operation *op, SlapReply *rs, Operation *sop,
        int             entry_sync_state = -1;
        AttributeName   null_attr;
        int             no_sync_state_change = 0;
-       struct slap_limits_set *limit = NULL;
-       int isroot = 0;
 
        u_int32_t       locker = 0;
        DB_LOCK         lock;
@@ -524,7 +521,11 @@ bdb_do_search( Operation *op, SlapReply *rs, Operation *sop,
 
        if ( sop->o_req_ndn.bv_len == 0 ) {
                /* DIT root special case */
-               e = (Entry *) &slap_entry_root;
+               ei_root.bei_e = &e_root;
+               ei_root.bei_parent = &ei_root;
+               e_root.e_private = &ei_root;
+               e_root.e_id = 1;
+               ei = &ei_root;
                rs->sr_err = LDAP_SUCCESS;
        } else {
 dn2entry_retry:
@@ -560,7 +561,7 @@ dn2entry_retry:
        }
 
        if ( e == NULL ) {
-               struct berval matched_dn = { 0, NULL };
+               struct berval matched_dn = BER_BVNULL;
 
                if ( matched != NULL ) {
                        BerVarray erefs;
@@ -601,7 +602,7 @@ dn2entry_retry:
                return rs->sr_err;
        }
 
-       if ( !manageDSAit && e != &slap_entry_root && is_entry_referral( e ) ) {
+       if ( !manageDSAit && e != &e_root && is_entry_referral( e ) ) {
                /* entry is a referral, don't allow add */
                struct berval matched_dn;
                BerVarray erefs;
@@ -647,82 +648,8 @@ dn2entry_retry:
                return 1;
        }
 
-       /* if not root, get appropriate limits */
-       if ( be_isroot( op->o_bd, &sop->o_ndn ) ) {
-               isroot = 1;
-       } else {
-               ( void ) get_limits( op->o_bd, &sop->o_ndn, &limit );
-       }
-
-       /* The time/size limits come first because they require very little
-        * effort, so there's no chance the candidates are selected and then 
-        * the request is not honored only because of time/size constraints
-        */
-
-       /* if no time limit requested, use soft limit (unless root!) */
-       if ( isroot ) {
-               if ( sop->oq_search.rs_tlimit == 0 ) {
-                       sop->oq_search.rs_tlimit = -1;  /* allow root to set no limit */
-               }
-
-               if ( sop->oq_search.rs_slimit == 0 ) {
-                       sop->oq_search.rs_slimit = -1;
-               }
-
-       } else {
-               /* if no limit is required, use soft limit */
-               if ( sop->oq_search.rs_tlimit <= 0 ) {
-                       sop->oq_search.rs_tlimit = limit->lms_t_soft;
-
-               /* if requested limit higher than hard limit, abort */
-               } else if ( sop->oq_search.rs_tlimit > limit->lms_t_hard ) {
-                       /* no hard limit means use soft instead */
-                       if ( limit->lms_t_hard == 0
-                                       && limit->lms_t_soft > -1
-                                       && sop->oq_search.rs_tlimit > limit->lms_t_soft ) {
-                               sop->oq_search.rs_tlimit = limit->lms_t_soft;
-
-                       /* positive hard limit means abort */
-                       } else if ( limit->lms_t_hard > 0 ) {
-                               rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
-                               send_ldap_result( sop, rs );
-                               rs->sr_err = LDAP_SUCCESS;
-                               goto done;
-                       }
-               
-                       /* negative hard limit means no limit */
-               }
-               
-               /* if no limit is required, use soft limit */
-               if ( sop->oq_search.rs_slimit <= 0 ) {
-                       if ( get_pagedresults(sop) && limit->lms_s_pr != 0 ) {
-                               sop->oq_search.rs_slimit = limit->lms_s_pr;
-                       } else {
-                               sop->oq_search.rs_slimit = limit->lms_s_soft;
-                       }
-
-               /* if requested limit higher than hard limit, abort */
-               } else if ( sop->oq_search.rs_slimit > limit->lms_s_hard ) {
-                       /* no hard limit means use soft instead */
-                       if ( limit->lms_s_hard == 0
-                                       && limit->lms_s_soft > -1
-                                       && sop->oq_search.rs_slimit > limit->lms_s_soft ) {
-                               sop->oq_search.rs_slimit = limit->lms_s_soft;
-
-                       /* positive hard limit means abort */
-                       } else if ( limit->lms_s_hard > 0 ) {
-                               rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
-                               send_ldap_result( sop, rs );
-                               rs->sr_err = LDAP_SUCCESS;      
-                               goto done;
-                       }
-                       
-                       /* negative hard limit means no limit */
-               }
-       }
-
        /* compute it anyway; root does not use it */
-       stoptime = op->o_time + sop->oq_search.rs_tlimit;
+       stoptime = op->o_time + sop->ors_tlimit;
 
        /* need normalized dn below */
        ber_dupbv( &realbase, &e->e_nname );
@@ -734,7 +661,7 @@ dn2entry_retry:
        base.e_nname = realbase;
        base.e_id = e->e_id;
 
-       if ( e != &slap_entry_root ) {
+       if ( e != &e_root ) {
                bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
        }
        e = NULL;
@@ -805,29 +732,29 @@ dn2entry_retry:
                        0, 0, 0 );
 #endif
 
-               rs->sr_err = LDAP_SUCCESS;
-               rs->sr_entry = NULL;
-               send_ldap_result( sop, rs );
-               goto done;
+               goto nochange;
        }
 
        /* if not root and candidates exceed to-be-checked entries, abort */
-       if ( !isroot && limit->lms_s_unchecked != -1 ) {
-               if ( BDB_IDL_N(candidates) > (unsigned) limit->lms_s_unchecked ) {
-                       rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
-                       send_ldap_result( sop, rs );
-                       rs->sr_err = LDAP_SUCCESS;
-                       goto done;
-               }
+       if ( sop->ors_limit     /* isroot == TRUE */
+                       && sop->ors_limit->lms_s_unchecked != -1
+                       && BDB_IDL_N(candidates) > (unsigned) sop->ors_limit->lms_s_unchecked )
+       {
+               rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
+               send_ldap_result( sop, rs );
+               rs->sr_err = LDAP_SUCCESS;
+               goto done;
        }
 
-       if ( isroot || !limit->lms_s_pr_hide ) {
+       if ( sop->ors_limit == NULL     /* isroot == FALSE */
+                       || !sop->ors_limit->lms_s_pr_hide ) {
                tentries = BDB_IDL_N(candidates);
        }
 
        if ( get_pagedresults(sop) ) {
-               if ( sop->o_pagedresults_state.ps_cookie == 0 ) {
-                       id = 0;
+               if ( (ID)( sop->o_pagedresults_state.ps_cookie ) == 0 ) {
+                       id = bdb_idl_first( candidates, &cursor );
+
                } else {
                        if ( sop->o_pagedresults_size == 0 ) {
                                rs->sr_err = LDAP_SUCCESS;
@@ -946,7 +873,7 @@ loop_begin:
                }
 
                /* check time limit */
-               if ( sop->oq_search.rs_tlimit != -1 && slap_get_time() > stoptime ) {
+               if ( sop->ors_tlimit != -1 && slap_get_time() > stoptime ) {
                        rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
                        rs->sr_ref = rs->sr_v2ref;
                        send_ldap_result( sop, rs );
@@ -1046,9 +973,11 @@ id2entry_retry:
                        if ( ei->bei_parent->bei_id == base.e_id ) scopeok = 1;
                        break;
 
+#ifdef LDAP_SCOPE_CHILDREN
                case LDAP_SCOPE_CHILDREN:
                        if ( id == base.e_id ) break;
                        /* Fall-thru */
+#endif
                case LDAP_SCOPE_SUBTREE: {
                        EntryInfo *tmp;
                        for (tmp = BEI(e); tmp->bei_parent;
@@ -1175,8 +1104,8 @@ id2entry_retry:
 
                if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
                        /* check size limit */
-            if ( --sop->oq_search.rs_slimit == -1 &&
-                               sop->o_sync_slog_size == -1 )
+                       if ( --sop->ors_slimit == -1 &&
+                                       sop->o_sync_slog_size == -1 )
                        {
                                if (!IS_PSEARCH) {
                                        bdb_cache_return_entry_r( bdb->bi_dbenv,
@@ -1260,11 +1189,12 @@ id2entry_retry:
                                                        if ( rs->sr_err != LDAP_SUCCESS ) goto done;
                                                        rs->sr_attrs = attrs;
                                                        rs->sr_ctrls = ctrls;
+                                                       rs->sr_flags = 0;
                                                        result = send_search_entry( sop, rs );
                                                        if ( cookie.bv_val ) ch_free( cookie.bv_val );  
-                                                       sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
+                                                       slap_sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
                                                                 sop->o_tmpmemctx );
-                                                       sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
+                                                       slap_sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
                                                        ctrls[num_ctrls] = NULL;
                                                        rs->sr_ctrls = NULL;
                                                }
@@ -1296,10 +1226,11 @@ id2entry_retry:
                                                        if ( rs->sr_err != LDAP_SUCCESS ) goto done;
                                                        rs->sr_ctrls = ctrls;
                                                        rs->sr_attrs = sop->oq_search.rs_attrs;
+                                                       rs->sr_flags = 0;
                                                        result = send_search_entry( sop, rs );
-                                                       sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
+                                                       slap_sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
                                                                 sop->o_tmpmemctx );
-                                                       sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
+                                                       slap_sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
                                                        ctrls[num_ctrls] = NULL;
                                                        rs->sr_ctrls = NULL;
                                                } else { /* PRESENT */
@@ -1335,6 +1266,8 @@ id2entry_retry:
                                        } else {
                                                rs->sr_attrs = sop->oq_search.rs_attrs;
                                                rs->sr_ctrls = NULL;
+                                               rs->sr_flags = 0;
+                                               rs->sr_err = LDAP_SUCCESS;
                                                result = send_search_entry( sop, rs );
                                        }
                                }
@@ -1481,10 +1414,10 @@ nochange:
                                rs->sr_rspoid = NULL;
                                send_ldap_result( sop, rs );
                                if ( ctrls[num_ctrls-1]->ldctl_value.bv_val != NULL ) {
-                                       sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
+                                       slap_sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
                                                sop->o_tmpmemctx );
                                }
-                               sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
+                               slap_sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
                                ctrls[num_ctrls] = NULL;
                                if ( cookie.bv_val ) ch_free( cookie.bv_val );  
                        }
@@ -1746,7 +1679,7 @@ send_pagerequest_response(
        LDAPControl     ctrl, *ctrls[2];
        BerElementBuffer berbuf;
        BerElement      *ber = (BerElement *)&berbuf;
-       struct berval   cookie = { 0, NULL };
+       struct berval   cookie = BER_BVNULL;
        PagedResultsCookie respcookie;
 
 #ifdef NEW_LOGGING
@@ -1767,6 +1700,7 @@ send_pagerequest_response(
 
        respcookie = ( PagedResultsCookie )lastid;
        op->o_conn->c_pagedresults_state.ps_cookie = respcookie;
+       op->o_conn->c_pagedresults_state.ps_count = op->o_pagedresults_state.ps_count + rs->sr_nentries;
        cookie.bv_len = sizeof( respcookie );
        cookie.bv_val = (char *)&respcookie;
 
@@ -1789,4 +1723,5 @@ send_pagerequest_response(
 
 done:
        (void) ber_free_buf( ber );
-}                      
+}
+