]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/search.c
ITS#4088 force cursors to use same locker
[openldap] / servers / slapd / back-bdb / search.c
index 9b863f1217b92b2022445a0fae075ed1b4b73986..3151d3d6aa3f9e8d4e7198d25532dc1b9f392658 100644 (file)
@@ -43,9 +43,6 @@ static void send_paged_response(
        ID  *lastid,
        int tentries );
 
-static int bdb_pfid_cmp( const void *v_id1, const void *v_id2 );
-static ID* bdb_id_dup( Operation *op, ID *id );
-
 /* Dereference aliases for a single alias entry. Return the final
  * dereferenced entry on success, NULL on any failure.
  */
@@ -67,12 +64,17 @@ static Entry * deref_base (
        rs->sr_err = LDAP_ALIAS_DEREF_PROBLEM;
        rs->sr_text = "maximum deref depth exceeded";
 
-       while (BDB_IDL_N(tmp) < op->o_bd->be_max_deref_depth) {
+       for (;;) {
                /* Remember the last entry we looked at, so we can
                 * report broken links
                 */
                *matched = e;
 
+               if (BDB_IDL_N(tmp) >= op->o_bd->be_max_deref_depth) {
+                       e = NULL;
+                       break;
+               }
+
                /* If this is part of a subtree or onelevel search,
                 * have we seen this ID before? If so, quit.
                 */
@@ -153,7 +155,11 @@ static int search_aliases(
        Entry *matched, *a;
        EntryInfo *ei;
        struct berval bv_alias = BER_BVC( "alias" );
-       AttributeAssertion aa_alias;
+#ifdef LDAP_COMP_MATCH
+       AttributeAssertion aa_alias = { NULL, BER_BVNULL, NULL };
+#else
+       AttributeAssertion aa_alias = { NULL, BER_BVNULL };
+#endif
        Filter  af;
        DB_LOCK locka, lockr;
        int first = 1;
@@ -313,7 +319,9 @@ bdb_search( Operation *op, SlapReply *rs )
        Entry           *matched = NULL;
        EntryInfo       *ei, ei_root = {0};
        struct berval   realbase = BER_BVNULL;
+#ifdef SLAP_ACL_HONOR_DISCLOSE
        slap_mask_t     mask;
+#endif
        int             manageDSAit;
        int             tentries = 0;
        ID              lastid = NOID;
@@ -357,6 +365,9 @@ bdb_search( Operation *op, SlapReply *rs )
                ei = &ei_root;
                rs->sr_err = LDAP_SUCCESS;
        } else {
+               if ( op->ors_deref & LDAP_DEREF_FINDING ) {
+                       BDB_IDL_ZERO(candidates);
+               }
 dn2entry_retry:
                /* get entry with reader lock */
                rs->sr_err = bdb_dn2entry( op, ltid, &op->o_req_ndn, &ei,
@@ -385,10 +396,26 @@ dn2entry_retry:
                return rs->sr_err;
        }
 
-       if ( e && (op->ors_deref & LDAP_DEREF_FINDING) && is_entry_alias(e) ) {
-               BDB_IDL_ZERO(candidates);
-               e = deref_base( op, rs, e, &matched, locker, &lock,
-                       candidates, NULL );
+       if ( op->ors_deref & LDAP_DEREF_FINDING ) {
+               if ( matched && is_entry_alias( matched )) {
+                       struct berval stub;
+
+                       stub.bv_val = op->o_req_ndn.bv_val;
+                       stub.bv_len = op->o_req_ndn.bv_len - matched->e_nname.bv_len - 1;
+                       e = deref_base( op, rs, matched, &matched, locker, &lock,
+                               candidates, NULL );
+                       if ( e ) {
+                               build_new_dn( &op->o_req_ndn, &e->e_nname, &stub,
+                                       op->o_tmpmemctx );
+                               bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
+                                       e, &lock);
+                               matched = NULL;
+                               goto dn2entry_retry;
+                       }
+               } else if ( e && is_entry_alias( e )) {
+                       e = deref_base( op, rs, e, &matched, locker, &lock,
+                               candidates, NULL );
+               }
        }
 
        if ( e == NULL ) {
@@ -414,7 +441,8 @@ dn2entry_retry:
                                erefs = is_entry_referral( matched )
                                        ? get_entry_referrals( op, matched )
                                        : NULL;
-                               rs->sr_err = LDAP_REFERRAL;
+                               if ( rs->sr_err == DB_NOTFOUND )
+                                       rs->sr_err = LDAP_REFERRAL;
                                rs->sr_matched = matched_dn.bv_val;
                        }
 
@@ -474,7 +502,7 @@ dn2entry_retry:
                        bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
                }
                send_ldap_result( op, rs );
-               return 1;
+               return rs->sr_err;
        }
 #endif /* SLAP_ACL_HONOR_DISCLOSE */
 
@@ -637,19 +665,16 @@ dn2entry_retry:
                goto loop_begin;
        }
 
-loop_start:
-
        for ( id = bdb_idl_first( candidates, &cursor );
                  id != NOID ; id = bdb_idl_next( candidates, &cursor ) )
        {
-               int scopeok = 0;
-               ID* idhole = NULL;
+               int scopeok;
 
 loop_begin:
 
                /* check for abandon */
                if ( op->o_abandon ) {
-                       rs->sr_err = LDAP_SUCCESS;
+                       rs->sr_err = SLAPD_ABANDON;
                        goto done;
                }
 
@@ -733,6 +758,7 @@ fetch_entry_retry:
                 * scope while we are looking at it, and unless we're using
                 * BDB_HIER, its parents cannot be moved either.
                 */
+               scopeok = 0;
                switch( op->ors_scope ) {
                case LDAP_SCOPE_BASE:
                        /* This is always true, yes? */
@@ -832,7 +858,7 @@ fetch_entry_retry:
 
                if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
                        /* check size limit */
-                       if ( --op->ors_slimit == -1) {
+                       if ( --op->ors_slimit == -1 ) {
 #ifdef SLAP_ZONE_ALLOC
                                slap_zn_runlock(bdb->bi_cache.c_zctx, e);
 #endif
@@ -849,6 +875,12 @@ fetch_entry_retry:
 
                        if ( get_pagedresults(op) > SLAP_CONTROL_IGNORED ) {
                                if ( rs->sr_nentries >= ((PagedResultsState *)op->o_pagedresults_state)->ps_size ) {
+#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;
                                        send_paged_response( op, rs, &lastid, tentries );
                                        goto done;
                                }
@@ -955,7 +987,7 @@ static int oc_filter(
 {
        int rc = 0;
 
-       assert( f );
+       assert( f != NULL );
 
        if( cur > *max ) *max = cur;
 
@@ -1022,10 +1054,18 @@ static int search_candidates(
        int rc, depth = 1;
        Filter          f, rf, xf, nf;
        ID              *stack;
-       AttributeAssertion aa_ref;
+#ifdef LDAP_COMP_MATCH
+       AttributeAssertion aa_ref = { NULL, BER_BVNULL, NULL };
+#else
+       AttributeAssertion aa_ref = { NULL, BER_BVNULL };
+#endif
 #ifdef BDB_SUBENTRIES
        Filter  sf;
-       AttributeAssertion aa_subentry;
+#ifdef LDAP_COMP_MATCH
+       AttributeAssertion aa_subentry = { NULL, BER_BVNULL, NULL };
+#else
+       AttributeAssertion aa_subentry = { NULL, BER_BVNULL };
+#endif
 #endif
 
        /*
@@ -1255,7 +1295,8 @@ send_paged_response(
 
        op->o_conn->c_pagedresults_state.ps_cookie = respcookie;
        op->o_conn->c_pagedresults_state.ps_count =
-               ((PagedResultsState *)op->o_pagedresults_state)->ps_count + rs->sr_nentries;
+               ((PagedResultsState *)op->o_pagedresults_state)->ps_count +
+               rs->sr_nentries;
 
        /* return size of 0 -- no estimate */
        ber_printf( ber, "{iO}", 0, &cookie ); 
@@ -1276,18 +1317,3 @@ done:
        (void) ber_free_buf( ber );
 }
 
-static int
-bdb_pfid_cmp( const void *v_id1, const void *v_id2 )
-{
-    const ID *p1 = v_id1, *p2 = v_id2;
-       return *p1 - *p2;
-}
-
-static ID*
-bdb_id_dup( Operation *op, ID *id )
-{
-       ID *new;
-       new = ch_malloc( sizeof(ID) );
-       *new = *id;
-       return new;
-}