- 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 );
+ }