From: Howard Chu Date: Fri, 11 Jan 2013 11:15:59 +0000 (-0800) Subject: ITS#7473 check DN scope before fetching id2e X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fb0b0688b0457150b9748dc3beee93cb548bb205;p=openldap ITS#7473 check DN scope before fetching id2e This is only a 10% gain, but still worth having for now. --- diff --git a/servers/slapd/back-mdb/dn2id.c b/servers/slapd/back-mdb/dn2id.c index c26e577894..b1aec3b594 100644 --- a/servers/slapd/back-mdb/dn2id.c +++ b/servers/slapd/back-mdb/dn2id.c @@ -616,7 +616,7 @@ mdb_idscopes( key.mv_data = &id; rc = mdb_cursor_get( isc->mc, &key, &data, MDB_SET ); if ( rc ) - break; + return rc; /* save RDN info */ } @@ -649,5 +649,5 @@ mdb_idscopes( if ( op->ors_scope == LDAP_SCOPE_ONELEVEL ) break; } - return MDB_NOTFOUND; + return MDB_SUCCESS; } diff --git a/servers/slapd/back-mdb/search.c b/servers/slapd/back-mdb/search.c index 580aa8972d..d129b9c1c2 100644 --- a/servers/slapd/back-mdb/search.c +++ b/servers/slapd/back-mdb/search.c @@ -634,42 +634,6 @@ loop_begin: goto done; } - if ( id == base->e_id ) { - e = base; - } else { - - /* get the entry */ - rs->sr_err = mdb_id2edata( op, mci, id, &edata ); - if ( rs->sr_err == MDB_NOTFOUND ) { - if( !MDB_IDL_IS_RANGE(candidates) ) { - /* only complain for non-range IDLs */ - Debug( LDAP_DEBUG_TRACE, - LDAP_XSTRING(mdb_search) - ": candidate %ld not found\n", - (long) id, 0, 0 ); - } else { - /* get the next ID from the DB */ - rs->sr_err = mdb_get_nextid( mci, &cursor ); - if ( rs->sr_err == MDB_NOTFOUND ) { - break; - } - if ( rs->sr_err ) { - rs->sr_err = LDAP_OTHER; - rs->sr_text = "internal error in get_nextid"; - send_ldap_result( op, rs ); - goto done; - } - cursor--; - } - - goto loop_continue; - } else if ( rs->sr_err ) { - rs->sr_err = LDAP_OTHER; - rs->sr_text = "internal error in mdb_id2edata"; - send_ldap_result( op, rs ); - goto done; - } - } /* Does this candidate actually satisfy the search scope? */ @@ -694,7 +658,15 @@ loop_begin: /* Fall-thru */ case LDAP_SCOPE_ONELEVEL: isc.id = id; - if ( mdb_idscopes( op, &isc ) == MDB_SUCCESS ) scopeok = 1; + isc.nscope = 0; + rs->sr_err = mdb_idscopes( op, &isc ); + if ( rs->sr_err == MDB_SUCCESS ) { + if ( isc.nscope ) + scopeok = 1; + } else { + if ( rs->sr_err == MDB_NOTFOUND ) + goto notfound; + } break; } @@ -708,7 +680,43 @@ loop_begin: goto loop_continue; } - if ( id != base->e_id ) { + if ( id == base->e_id ) { + e = base; + } else { + + /* get the entry */ + rs->sr_err = mdb_id2edata( op, mci, id, &edata ); + if ( rs->sr_err == MDB_NOTFOUND ) { +notfound: + if( !MDB_IDL_IS_RANGE(candidates) ) { + /* only complain for non-range IDLs */ + Debug( LDAP_DEBUG_TRACE, + LDAP_XSTRING(mdb_search) + ": candidate %ld not found\n", + (long) id, 0, 0 ); + } else { + /* get the next ID from the DB */ + rs->sr_err = mdb_get_nextid( mci, &cursor ); + if ( rs->sr_err == MDB_NOTFOUND ) { + break; + } + if ( rs->sr_err ) { + rs->sr_err = LDAP_OTHER; + rs->sr_text = "internal error in get_nextid"; + send_ldap_result( op, rs ); + goto done; + } + cursor--; + } + + goto loop_continue; + } else if ( rs->sr_err ) { + rs->sr_err = LDAP_OTHER; + rs->sr_text = "internal error in mdb_id2edata"; + send_ldap_result( op, rs ); + goto done; + } + rs->sr_err = mdb_entry_decode( op, &edata, &e ); if ( rs->sr_err ) { rs->sr_err = LDAP_OTHER;