- be = gi->n[i].be;
- if (scope == LDAP_SCOPE_ONELEVEL &&
- dn_match(&gi->n[i].pdn, ndn)) {
- rc = be->be_search (be, conn, op,
- &be->be_suffix[0], &be->be_nsuffix[0],
- LDAP_SCOPE_BASE, deref,
- s2limit, t2limit, filter, filterstr,
- attrs, attrsonly);
-
- } else if (scope == LDAP_SCOPE_SUBTREE &&
- dnIsSuffix(&be->be_nsuffix[0], ndn)) {
- rc = be->be_search (be, conn, op,
- &be->be_suffix[0], &be->be_nsuffix[0],
- scope, deref,
- s2limit, t2limit, filter, filterstr,
- attrs, attrsonly);
-
- } else if (dnIsSuffix(ndn, &be->be_nsuffix[0])) {
- rc = be->be_search (be, conn, op, dn, ndn,
- scope, deref,
- s2limit, t2limit, filter, filterstr,
- attrs, attrsonly);
+ op->o_bd = btmp;
+
+ assert( op->o_bd->be_suffix != NULL );
+ assert( op->o_bd->be_nsuffix != NULL );
+
+ if (scope0 == LDAP_SCOPE_ONELEVEL &&
+ dn_match(pdn, &ndn))
+ {
+ struct berval mdn, mndn;
+ op->ors_scope = LDAP_SCOPE_BASE;
+ mdn = op->o_req_dn = op->o_bd->be_suffix[0];
+ mndn = op->o_req_ndn = op->o_bd->be_nsuffix[0];
+ rs->sr_err = op->o_bd->be_search(op, rs);
+ if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
+ gs.err = LDAP_SUCCESS;
+ }
+ op->ors_scope = LDAP_SCOPE_ONELEVEL;
+ if ( op->o_req_dn.bv_val == mdn.bv_val )
+ op->o_req_dn = dn;
+ if ( op->o_req_ndn.bv_val == mndn.bv_val )
+ op->o_req_ndn = ndn;
+
+ } else if (scope0 == LDAP_SCOPE_SUBTREE &&
+ dn_match(&op->o_bd->be_nsuffix[0], &ndn))
+ {
+ rs->sr_err = glue_sub_search( op, rs, b0, on );
+
+ } else if (scope0 == LDAP_SCOPE_SUBTREE &&
+ dnIsSuffix(&op->o_bd->be_nsuffix[0], &ndn))
+ {
+ struct berval mdn, mndn;
+ mdn = op->o_req_dn = op->o_bd->be_suffix[0];
+ mndn = op->o_req_ndn = op->o_bd->be_nsuffix[0];
+ rs->sr_err = glue_sub_search( op, rs, b0, on );
+ if ( rs->sr_err == LDAP_NO_SUCH_OBJECT ) {
+ gs.err = LDAP_SUCCESS;
+ }
+ if ( op->o_req_dn.bv_val == mdn.bv_val )
+ op->o_req_dn = dn;
+ if ( op->o_req_ndn.bv_val == mndn.bv_val )
+ op->o_req_ndn = ndn;
+
+ } else if (dnIsSuffix(&ndn, &op->o_bd->be_nsuffix[0])) {
+ rs->sr_err = glue_sub_search( op, rs, b0, on );
+ }
+
+ switch ( gs.err ) {
+
+ /*
+ * Add errors that should result in dropping
+ * the search
+ */
+ case LDAP_SIZELIMIT_EXCEEDED:
+ case LDAP_TIMELIMIT_EXCEEDED:
+ case LDAP_ADMINLIMIT_EXCEEDED:
+ case LDAP_NO_SUCH_OBJECT:
+#ifdef LDAP_CONTROL_X_CHAINING_BEHAVIOR
+ case LDAP_X_CANNOT_CHAIN:
+#endif /* LDAP_CONTROL_X_CHAINING_BEHAVIOR */
+ goto end_of_loop;
+
+ case LDAP_SUCCESS:
+ if ( get_pagedresults( op ) > SLAP_CONTROL_IGNORED ) {
+ PagedResultsState *ps = op->o_pagedresults_state;
+
+ /* Assume this backend can be forgotten now */
+ op->o_conn->c_pagedresults_state.ps_be = NULL;
+
+ /* If we have a full page, exit the loop. We may
+ * need to remember this backend so we can continue
+ * from here on a subsequent request.
+ */
+ if ( rs->sr_nentries >= ps->ps_size ) {
+ /* Don't bother to remember the first backend.
+ * Only remember the last one if there's more state left.
+ */
+ if ( op->o_bd != b0 &&
+ ( op->o_conn->c_pagedresults_state.ps_cookie ||
+ op->o_bd != gi->gi_n[0].gn_be ))
+ op->o_conn->c_pagedresults_state.ps_be = op->o_bd;
+ goto end_of_loop;
+ }
+
+ /* This backend has run out of entries, but more responses
+ * can fit in the page. Fake a reset of the state so the
+ * next backend will start up properly. Only back-[bh]db
+ * and back-sql look at this state info.
+ */
+ if ( ps->ps_cookieval.bv_len == sizeof( PagedResultsCookie )) {
+ ps->ps_cookie = 0;
+ memset( ps->ps_cookieval.bv_val, 0,
+ sizeof( PagedResultsCookie ));
+ }
+ }
+
+ default:
+ break;