From: Howard Chu Date: Thu, 22 Sep 2005 21:12:04 +0000 (+0000) Subject: ITS#4030 fix alias deref for Finding, fix alias error code propagation. X-Git-Tag: OPENLDAP_REL_ENG_2_2_MP~398 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=dd21d3a29f801f327bf891e9e15dc51b89983753;p=openldap ITS#4030 fix alias deref for Finding, fix alias error code propagation. --- diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index f05b725b26..3151d3d6aa 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -64,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. */ @@ -360,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, @@ -388,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 ) { @@ -417,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; }