]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/search.c
Initial subordinate implementation (for chaining)
[openldap] / servers / slapd / back-bdb / search.c
index 7223daecc0208fdd88450d359a9a3b1ad5ab2d72..66fedc5e9ba823506c33a169d05163bbf47c3b15 100644 (file)
@@ -65,7 +65,6 @@ static Entry * deref_base (
        rs->sr_text = "maximum deref depth exceeded";
 
        while (BDB_IDL_N(tmp) < op->o_bd->be_max_deref_depth) {
-
                /* Remember the last entry we looked at, so we can
                 * report broken links
                 */
@@ -100,8 +99,11 @@ static Entry * deref_base (
                rs->sr_err = bdb_dn2entry( op, NULL, &ndn, &ei,
                        0, locker, &lockr );
 
-               if ( ei ) e = ei->bei_e;
-               else    e = NULL;
+               if ( ei ) {
+                       e = ei->bei_e;
+               } else {
+                       e = NULL;
+               }
 
                if (!e) {
                        rs->sr_err = LDAP_ALIAS_PROBLEM;
@@ -140,8 +142,7 @@ static int search_aliases(
        u_int32_t locker,
        ID *ids,
        ID *scopes,
-       ID *stack
-)
+       ID *stack )
 {
        struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
        ID *aliases, *curscop, *subscop, *visited, *newsubs, *oldsubs, *tmp;
@@ -198,7 +199,7 @@ static int search_aliases(
                 */
                BDB_IDL_CPY( curscop, aliases );
                rs->sr_err = bdb_dn2idl( op, e, subscop,
-                                       subscop2+BDB_IDL_DB_SIZE );
+                       subscop2+BDB_IDL_DB_SIZE );
                if (first) {
                        first = 0;
                } else {
@@ -259,7 +260,7 @@ static int search_aliases(
                /* If this is a OneLevel search, we're done; oldsubs only had one
                 * ID in it. For a Subtree search, oldsubs may be a list of scope IDs.
                 */
-               if (op->ors_scope != LDAP_SCOPE_SUBTREE) break;
+               if ( op->ors_scope == LDAP_SCOPE_ONELEVEL ) break;
 nextido:
                ido = bdb_idl_next( oldsubs, &cursoro );
                
@@ -288,14 +289,9 @@ nextido:
        return rs->sr_err;
 }
 
-static
-int is_sync_protocol( Operation *op )
-{
-       if ( op->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST )
-               return 1;
-       return 0;
-}
-       
+#define is_sync_protocol(op)   \
+       ((op)->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST)
+
 #define IS_BDB_REPLACE(type) (( type == LDAP_PSEARCH_BY_DELETE ) || \
        ( type == LDAP_PSEARCH_BY_SCOPEOUT ))
 #define IS_PSEARCH (op != sop)
@@ -930,7 +926,7 @@ dn2entry_retry:
                id != NOID && !no_sync_state_change;
                id = bdb_idl_next( candidates, &cursor ) )
        {
-               int             scopeok = 0;
+               int scopeok = 0;
 
 loop_begin:
                /* check for abandon */
@@ -1052,6 +1048,9 @@ id2entry_retry:
                        if ( ei->bei_parent->bei_id == base.e_id ) scopeok = 1;
                        break;
 
+               case LDAP_SCOPE_CHILDREN:
+                       if ( id == base.e_id ) break;
+                       /* Fall-thru */
                case LDAP_SCOPE_SUBTREE: {
                        EntryInfo *tmp;
                        for ( tmp = BEI(e); tmp->bei_parent;
@@ -1082,12 +1081,10 @@ id2entry_retry:
                        if ( !scopeok && BDB_IDL_N(scopes) ) {
                                unsigned x;
                                if ( sop->ors_scope == LDAP_SCOPE_ONELEVEL ) {
-                                       x = bdb_idl_search( scopes,
-                                               e->e_id );
-                                       if ( scopes[x] == e->e_id )
-                                               scopeok = 1;
+                                       x = bdb_idl_search( scopes, e->e_id );
+                                       if ( scopes[x] == e->e_id ) scopeok = 1;
                                } else {
-                               /* subtree, walk up the tree */
+                                       /* subtree, walk up the tree */
                                        EntryInfo *tmp = BEI(e);
                                        for (;tmp->bei_parent; tmp=tmp->bei_parent) {
                                                x = bdb_idl_search( scopes, tmp->bei_id );
@@ -1124,11 +1121,9 @@ id2entry_retry:
                        && is_entry_referral( e ) )
                {
                        BerVarray erefs = get_entry_referrals( sop, e );
-                       rs->sr_ref = referral_rewrite( erefs,
-                               &e->e_name, NULL,
-                               sop->oq_search.rs_scope == LDAP_SCOPE_SUBTREE
-                                       ? LDAP_SCOPE_SUBTREE
-                                       : LDAP_SCOPE_BASE );
+                       rs->sr_ref = referral_rewrite( erefs, &e->e_name, NULL,
+                               sop->oq_search.rs_scope == LDAP_SCOPE_ONELEVEL
+                                       ? LDAP_SCOPE_BASE : LDAP_SCOPE_SUBTREE );
 
                        send_search_reference( sop, rs );
 
@@ -1259,9 +1254,9 @@ id2entry_retry:
                                                } else {
                                                        struct berval cookie;
                                                        slap_compose_sync_cookie( sop, &cookie,
-                                                                               search_context_csn,
-                                                                               sop->o_sync_state.sid,
-                                                                               sop->o_sync_state.rid );
+                                                               search_context_csn,
+                                                               sop->o_sync_state.sid,
+                                                               sop->o_sync_state.rid );
                                                        rs->sr_err = slap_build_sync_state_ctrl( sop,
                                                                rs, e, entry_sync_state, ctrls,
                                                                num_ctrls++, 1, &cookie );
@@ -1269,17 +1264,16 @@ id2entry_retry:
                                                        rs->sr_attrs = attrs;
                                                        rs->sr_ctrls = ctrls;
                                                        result = send_search_entry( sop, rs );
-                                                       if ( cookie.bv_val )
-                                                               ch_free( cookie.bv_val );       
+                                                       if ( cookie.bv_val ) ch_free( cookie.bv_val );  
                                                        sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
-                                                                        sop->o_tmpmemctx );
+                                                                sop->o_tmpmemctx );
                                                        sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
                                                        ctrls[num_ctrls] = NULL;
                                                        rs->sr_ctrls = NULL;
                                                }
                                        } else if ( ps_type == LDAP_PSEARCH_BY_PREMODIFY ) {
                                                struct psid_entry* psid_e;
-                                               psid_e = (struct psid_entry *) ch_calloc (1,
+                                               psid_e = (struct psid_entry *) ch_calloc(1,
                                                        sizeof(struct psid_entry));
                                                psid_e->ps_op = sop;
                                                LDAP_LIST_INSERT_HEAD( &op->o_pm_list,
@@ -1298,7 +1292,6 @@ id2entry_retry:
                                        }
                                } else {
                                        if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
-
                                                if ( rc_sync == LDAP_COMPARE_TRUE ) { /* ADD */
                                                        rs->sr_err = slap_build_sync_state_ctrl( sop,
                                                                rs, e, entry_sync_state, ctrls,
@@ -1308,29 +1301,32 @@ id2entry_retry:
                                                        rs->sr_attrs = sop->oq_search.rs_attrs;
                                                        result = send_search_entry( sop, rs );
                                                        sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
-                                                                        sop->o_tmpmemctx );
+                                                                sop->o_tmpmemctx );
                                                        sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
                                                        ctrls[num_ctrls] = NULL;
                                                        rs->sr_ctrls = NULL;
                                                } else { /* PRESENT */
                                                        if ( sync_send_present_mode ) {
                                                                result = slap_build_syncUUID_set( sop,
-                                                                                                       &syncUUID_set, e );
+                                                                       &syncUUID_set, e );
                                                                if ( result <= 0 ) {
                                                                        result = -1;    
                                                                } else {
                                                                        syncUUID_set_cnt++;
-                                                                       if ( syncUUID_set_cnt == SLAP_SYNCUUID_SET_SIZE ) {
+                                                                       if ( syncUUID_set_cnt ==
+                                                                               SLAP_SYNCUUID_SET_SIZE )
+                                                                       {
                                                                                rs->sr_err = LDAP_SUCCESS;
                                                                                rs->sr_rspoid = LDAP_SYNC_INFO;
                                                                                rs->sr_ctrls = NULL;
                                                                                result = slap_send_syncinfo( sop, rs,
-                                                                                               LDAP_TAG_SYNC_ID_SET,
-                                                                                               NULL, 0, syncUUID_set, 0 );
-                                                                               if ( result != LDAP_SUCCESS )
+                                                                                       LDAP_TAG_SYNC_ID_SET,
+                                                                                       NULL, 0, syncUUID_set, 0 );
+                                                                               if ( result != LDAP_SUCCESS ) {
                                                                                        result = -1;
+                                                                               }
                                                                                ber_bvarray_free_x( syncUUID_set,
-                                                                                                               sop->o_tmpmemctx );
+                                                                                       sop->o_tmpmemctx );
                                                                                syncUUID_set = NULL;
                                                                                syncUUID_set_cnt = 0;
                                                                        }
@@ -1394,7 +1390,7 @@ loop_continue:
                rs->sr_rspoid = LDAP_SYNC_INFO;
                rs->sr_ctrls = NULL;
                slap_send_syncinfo( sop, rs, LDAP_TAG_SYNC_ID_SET,
-                                                       NULL, 0, syncUUID_set, 0 );
+                       NULL, 0, syncUUID_set, 0 );
                ber_bvarray_free_x( syncUUID_set, sop->o_tmpmemctx );
                syncUUID_set_cnt = 0;
        }
@@ -1404,10 +1400,8 @@ nochange:
                if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
                        if ( sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
                                struct berval cookie;
-                               slap_compose_sync_cookie( sop, &cookie,
-                                                                                 search_context_csn,
-                                                                                 sop->o_sync_state.sid,
-                                                                                 sop->o_sync_state.rid );
+                               slap_compose_sync_cookie( sop, &cookie, search_context_csn,
+                                       sop->o_sync_state.sid, sop->o_sync_state.rid );
 
                                if ( sync_send_present_mode ) {
                                        rs->sr_err = LDAP_SUCCESS;
@@ -1419,9 +1413,12 @@ nochange:
                                        if ( !no_sync_state_change ) {
                                                int slog_found = 0;
                                                ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
-                                               LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
+                                               LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
+                                                       o_ps_link )
+                                               {
                                                        if ( ps_list->o_sync_slog_size > 0 ) {
-                                                               if ( ps_list->o_sync_state.sid == sop->o_sync_state.sid ) {
+                                                               if ( ps_list->o_sync_state.sid ==
+                                                                       sop->o_sync_state.sid ) {
                                                                        slog_found = 1;
                                                                        break;
                                                                }
@@ -1449,10 +1446,8 @@ nochange:
                        } else {
                                /* refreshOnly mode */
                                struct berval cookie;
-                               slap_compose_sync_cookie( sop, &cookie,
-                                                                                 search_context_csn,
-                                                                                 sop->o_sync_state.sid,
-                                                                                 sop->o_sync_state.rid );
+                               slap_compose_sync_cookie( sop, &cookie, search_context_csn,
+                                       sop->o_sync_state.sid, sop->o_sync_state.rid );
 
                                if ( sync_send_present_mode ) {
                                        slap_build_sync_done_ctrl( sop, rs, ctrls,
@@ -1462,7 +1457,8 @@ nochange:
                                                int slog_found = 0;
                                                ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
                                                LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
-                                                               o_ps_link ) {
+                                                       o_ps_link )
+                                               {
                                                        if ( ps_list->o_sync_slog_size > 0 ) {
                                                                if ( ps_list->o_sync_state.sid ==
                                                                                sop->o_sync_state.sid ) {
@@ -1483,16 +1479,17 @@ nochange:
 
                                rs->sr_ctrls = ctrls;
                                rs->sr_ref = rs->sr_v2ref;
-                               rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
+                               rs->sr_err = (rs->sr_v2ref == NULL)
+                                       ? LDAP_SUCCESS : LDAP_REFERRAL;
                                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, sop->o_tmpmemctx );
+                                       sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
+                                               sop->o_tmpmemctx );
                                }
                                sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
                                ctrls[num_ctrls] = NULL;
-                               if ( cookie.bv_val )
-                                       ch_free( cookie.bv_val );       
+                               if ( cookie.bv_val ) ch_free( cookie.bv_val );  
                        }
                } else {
                        rs->sr_ctrls = NULL;
@@ -1508,10 +1505,10 @@ nochange:
 done:
        if( !IS_PSEARCH && e != NULL ) {
                /* free reader lock */
-               bdb_cache_return_entry_r ( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
+               bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
        }
 
-       LOCK_ID_FREE (bdb->bi_dbenv, locker );
+       LOCK_ID_FREEbdb->bi_dbenv, locker );
 
        ber_bvfree( search_context_csn );
 
@@ -1550,8 +1547,7 @@ static int base_candidate(
 static int oc_filter(
        Filter *f,
        int cur,
-       int *max
-)
+       int *max )
 {
        int rc = 0;
 
@@ -1559,7 +1555,7 @@ static int oc_filter(
 
        if( cur > *max ) *max = cur;
 
-       switch(f->f_choice) {
+       switch( f->f_choice ) {
        case LDAP_FILTER_PRESENT:
                if (f->f_desc == slap_schema.si_ad_objectClass) {
                        rc = 1;
@@ -1569,7 +1565,7 @@ static int oc_filter(
        case LDAP_FILTER_AND:
        case LDAP_FILTER_OR:
                cur++;
-               for (f=f->f_and; f; f=f->f_next) {
+               for ( f=f->f_and; f; f=f->f_next ) {
                        (void) oc_filter(f, cur, max);
                }
                break;
@@ -1676,7 +1672,7 @@ static int search_candidates(
        /* Dummy; we compute scope separately now */
        nf.f_choice = SLAPD_FILTER_COMPUTED;
        nf.f_result = LDAP_SUCCESS;
-       nf.f_next = xf.f_or == op->oq_search.rs_filter
+       nf.f_next = ( xf.f_or == op->oq_search.rs_filter )
                ? op->oq_search.rs_filter : &xf ;
        /* Filter depth increased again, adding dummy clause */
        depth++;
@@ -1763,7 +1759,7 @@ send_pagerequest_response(
                lastid, rs->sr_nentries, NULL );
 #else
        Debug(LDAP_DEBUG_ARGS, "send_pagerequest_response: lastid: (0x%08lx) "
-                       "nentries: (0x%081x)\n", lastid, rs->sr_nentries, NULL );
+               "nentries: (0x%081x)\n", lastid, rs->sr_nentries, NULL );
 #endif
 
        ctrl.ldctl_value.bv_val = NULL;