1 /* search.c - search operation */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
26 static int base_candidate(
31 static int search_candidates(
32 Operation *stackop, /* op with the current threadctx/slab cache */
33 Operation *sop, /* search op */
40 static void send_paged_response(
46 /* Dereference aliases for a single alias entry. Return the final
47 * dereferenced entry on success, NULL on any failure.
49 static Entry * deref_base (
59 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
64 rs->sr_err = LDAP_ALIAS_DEREF_PROBLEM;
65 rs->sr_text = "maximum deref depth exceeded";
67 while (BDB_IDL_N(tmp) < op->o_bd->be_max_deref_depth) {
68 /* Remember the last entry we looked at, so we can
73 /* If this is part of a subtree or onelevel search,
74 * have we seen this ID before? If so, quit.
76 if ( visited && bdb_idl_insert( visited, e->e_id ) ) {
81 /* If we've seen this ID during this deref iteration,
84 if ( bdb_idl_insert( tmp, e->e_id ) ) {
85 rs->sr_err = LDAP_ALIAS_PROBLEM;
86 rs->sr_text = "circular alias";
91 /* If there was a problem getting the aliasedObjectName,
92 * get_alias_dn will have set the error status.
94 if ( get_alias_dn(e, &ndn, &rs->sr_err, &rs->sr_text) ) {
99 rs->sr_err = bdb_dn2entry( op, NULL, &ndn, &ei,
109 rs->sr_err = LDAP_ALIAS_PROBLEM;
110 rs->sr_text = "aliasedObject not found";
114 /* Free the previous entry, continue to work with the
115 * one we just retrieved.
117 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
121 /* We found a regular entry. Return this to the caller. The
122 * entry is still locked for Read.
124 if (!is_entry_alias(e)) {
125 rs->sr_err = LDAP_SUCCESS;
133 /* Look for and dereference all aliases within the search scope. Adds
134 * the dereferenced entries to the "ids" list. Requires "stack" to be
135 * able to hold 8 levels of DB_SIZE IDLs. Of course we're hardcoded to
136 * require a minimum of 8 UM_SIZE IDLs so this is never a problem.
138 static int search_aliases(
147 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
148 ID *aliases, *curscop, *subscop, *visited, *newsubs, *oldsubs, *tmp;
149 ID cursora, ida, cursoro, ido, *subscop2;
152 struct berval bv_alias = { sizeof("alias")-1, "alias" };
153 AttributeAssertion aa_alias;
155 DB_LOCK locka, lockr;
158 aliases = stack; /* IDL of all aliases in the database */
159 curscop = aliases + BDB_IDL_DB_SIZE; /* Aliases in the current scope */
160 subscop = curscop + BDB_IDL_DB_SIZE; /* The current scope */
161 visited = subscop + BDB_IDL_DB_SIZE; /* IDs we've seen in this search */
162 newsubs = visited + BDB_IDL_DB_SIZE; /* New subtrees we've added */
163 oldsubs = newsubs + BDB_IDL_DB_SIZE; /* Subtrees added previously */
164 tmp = oldsubs + BDB_IDL_DB_SIZE; /* Scratch space for deref_base() */
166 /* A copy of subscop, because subscop gets clobbered by
167 * the bdb_idl_union/intersection routines
169 subscop2 = tmp + BDB_IDL_DB_SIZE;
171 af.f_choice = LDAP_FILTER_EQUALITY;
172 af.f_ava = &aa_alias;
173 af.f_av_desc = slap_schema.si_ad_objectClass;
174 af.f_av_value = bv_alias;
177 /* Find all aliases in database */
178 BDB_IDL_ZERO( aliases );
179 rs->sr_err = bdb_filter_candidates( op, &af, aliases,
181 if (rs->sr_err != LDAP_SUCCESS) {
185 oldsubs[1] = e->e_id;
188 BDB_IDL_ZERO( visited );
189 BDB_IDL_ZERO( newsubs );
192 ido = bdb_idl_first( oldsubs, &cursoro );
195 /* Set curscop to only the aliases in the current scope. Start with
196 * all the aliases, obtain the IDL for the current scope, and then
197 * get the intersection of these two IDLs. Add the current scope
198 * to the cumulative list of candidates.
200 BDB_IDL_CPY( curscop, aliases );
201 rs->sr_err = bdb_dn2idl( op, e, subscop,
202 subscop2+BDB_IDL_DB_SIZE );
206 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, e, &locka);
208 BDB_IDL_CPY(subscop2, subscop);
209 rs->sr_err = bdb_idl_intersection(curscop, subscop);
210 bdb_idl_union( ids, subscop2 );
212 /* Dereference all of the aliases in the current scope. */
214 for (ida = bdb_idl_first(curscop, &cursora); ida != NOID;
215 ida = bdb_idl_next(curscop, &cursora))
218 rs->sr_err = bdb_cache_find_id(op, NULL,
219 ida, &ei, 0, locker, &lockr );
220 if (rs->sr_err != LDAP_SUCCESS) {
225 /* This should only happen if the curscop IDL has maxed out and
226 * turned into a range that spans IDs indiscriminately
228 if (!is_entry_alias(a)) {
229 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
234 /* Actually dereference the alias */
236 a = deref_base( op, rs, a, &matched, locker, &lockr,
239 /* If the target was not already in our current candidates,
240 * make note of it in the newsubs list. Also
241 * set it in the scopes list so that bdb_search
244 if (bdb_idl_insert(ids, a->e_id) == 0) {
245 bdb_idl_insert(newsubs, a->e_id);
246 bdb_idl_insert(scopes, a->e_id);
248 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
251 } else if (matched) {
252 /* Alias could not be dereferenced, or it deref'd to
253 * an ID we've already seen. Ignore it.
255 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
260 /* If this is a OneLevel search, we're done; oldsubs only had one
261 * ID in it. For a Subtree search, oldsubs may be a list of scope IDs.
263 if ( op->ors_scope == LDAP_SCOPE_ONELEVEL ) break;
265 ido = bdb_idl_next( oldsubs, &cursoro );
267 /* If we're done processing the old scopes, did we add any new
268 * scopes in this iteration? If so, go back and do those now.
271 if (BDB_IDL_IS_ZERO(newsubs)) break;
272 BDB_IDL_CPY(oldsubs, newsubs);
273 BDB_IDL_ZERO(newsubs);
275 ido = bdb_idl_first( oldsubs, &cursoro );
278 /* Find the entry corresponding to the next scope. If it can't
279 * be found, ignore it and move on. This should never happen;
280 * we should never see the ID of an entry that doesn't exist.
281 * Set the name so that the scope's IDL can be retrieved.
284 rs->sr_err = bdb_cache_find_id(op, NULL, ido, &ei,
286 if ( rs->sr_err != LDAP_SUCCESS ) goto nextido;
292 #define is_sync_protocol(op) \
293 ((op)->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST)
295 #define IS_BDB_REPLACE(type) (( type == LDAP_PSEARCH_BY_DELETE ) || \
296 ( type == LDAP_PSEARCH_BY_SCOPEOUT ))
297 #define IS_PSEARCH (op != sop)
300 bdb_drop_psearch( Operation *op, ber_int_t msgid )
303 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
305 LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
306 if ( ps_list->o_connid == op->o_connid ) {
307 if ( ps_list->o_msgid == msgid ) {
308 ps_list->o_abandon = 1;
309 LDAP_LIST_REMOVE( ps_list, o_ps_link );
310 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
311 LDAP_STAILQ_REMOVE( &op->o_conn->c_ops, ps_list,
313 LDAP_STAILQ_NEXT( ps_list, o_next ) = NULL;
314 op->o_conn->c_n_ops_executing--;
315 op->o_conn->c_n_ops_completed++;
316 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
326 bdb_abandon( Operation *op, SlapReply *rs )
330 ps = bdb_drop_psearch( op, op->oq_abandon.rs_msgid );
332 if ( ps->o_tmpmemctx ) {
333 slap_sl_mem_destroy( NULL, ps->o_tmpmemctx );
338 return LDAP_UNAVAILABLE;
342 bdb_cancel( Operation *op, SlapReply *rs )
346 ps = bdb_drop_psearch( op, op->oq_cancel.rs_msgid );
348 rs->sr_err = LDAP_CANCELLED;
349 send_ldap_result( ps, rs );
350 if ( ps->o_tmpmemctx ) {
351 slap_sl_mem_destroy( NULL, ps->o_tmpmemctx );
356 return LDAP_UNAVAILABLE;
359 int bdb_search( Operation *op, SlapReply *rs )
361 return bdb_do_search( op, rs, op, NULL, 0 );
364 int bdb_psearch( Operation *op, SlapReply *rs, Operation *sop,
365 Entry *ps_e, int ps_type )
369 sop->o_private = op->o_private;
370 rc = bdb_do_search( op, rs, sop, ps_e, ps_type );
371 sop->o_private = NULL;
376 /* For persistent searches, op is the currently executing operation,
377 * sop is the persistent search. For regular searches, sop = op.
380 bdb_do_search( Operation *op, SlapReply *rs, Operation *sop,
381 Entry *ps_e, int ps_type )
383 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
386 ID candidates[BDB_IDL_UM_SIZE];
387 ID scopes[BDB_IDL_DB_SIZE];
388 Entry *e = NULL, base, e_root = {0};
389 Entry *matched = NULL;
390 EntryInfo *ei, ei_root = {0};
391 struct berval realbase = BER_BVNULL;
395 AttributeName *attrs;
397 Filter contextcsnand, contextcsnle, cookief, csnfnot,
398 csnfeq, csnfand, csnfge;
399 AttributeAssertion aa_ge, aa_eq, aa_le;
400 struct berval *search_context_csn = NULL;
402 LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
404 AttributeName uuid_attr[2];
406 int entry_sync_state = -1;
407 AttributeName null_attr;
408 int no_sync_state_change = 0;
410 u_int32_t locker = 0;
414 int sync_send_present_mode = 1;
420 BerVarray syncUUID_set = NULL;
421 int syncUUID_set_cnt = 0;
423 struct bdb_op_info *opinfo = NULL;
427 LDAP_LOG( OPERATION, ENTRY, "bdb_search\n", 0, 0, 0 );
429 Debug( LDAP_DEBUG_TRACE, "=> bdb_search\n", 0, 0, 0);
431 attrs = sop->oq_search.rs_attrs;
433 opinfo = (struct bdb_op_info *) op->o_private;
435 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST ) {
436 struct slap_session_entry *sent;
437 if ( sop->o_sync_state.sid >= 0 ) {
438 LDAP_LIST_FOREACH( sent, &bdb->bi_session_list, se_link ) {
439 if ( sent->se_id == sop->o_sync_state.sid ) {
440 sop->o_sync_slog_size = sent->se_size;
447 /* psearch needs to be registered before refresh begins */
448 /* psearch and refresh transmission is serialized in send_ldap_ber() */
449 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
450 ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
451 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
452 ldap_pvt_thread_rdwr_wunlock( &bdb->bi_pslist_rwlock );
454 } else if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST
455 && sop->o_sync_slog_size >= 0 )
457 ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
458 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
459 if ( ps_list->o_sync_slog_size >= 0 ) {
460 if ( ps_list->o_sync_state.sid == sop->o_sync_state.sid ) {
468 if ( ps_list->o_sync_slog_omitcsn.bv_len != 0 ) {
469 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
470 if ( sop->o_sync_state.ctxcsn &&
471 sop->o_sync_state.ctxcsn->bv_val != NULL )
473 value_match( &match, slap_schema.si_ad_entryCSN, mr,
474 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
475 sop->o_sync_state.ctxcsn,
476 &ps_list->o_sync_slog_omitcsn,
482 sync_send_present_mode = 0;
485 sync_send_present_mode = 0;
487 } else if ( sop->o_sync_slog_size >= 0 ) {
488 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
490 sop->o_sync_state.sid = -1;
492 ldap_pvt_thread_rdwr_wunlock( &bdb->bi_pslist_rwlock );
495 null_attr.an_desc = NULL;
496 null_attr.an_oc = NULL;
497 null_attr.an_oc_exclude = 0;
498 null_attr.an_name.bv_len = 0;
499 null_attr.an_name.bv_val = NULL;
501 for( num_ctrls = 0; num_ctrls < SLAP_MAX_RESPONSE_CONTROLS; num_ctrls++ ) {
502 ctrls[num_ctrls] = NULL;
506 if ( IS_PSEARCH && IS_BDB_REPLACE(ps_type)) {
508 attrs[0].an_desc = NULL;
509 attrs[0].an_oc = NULL;
510 attrs[0].an_oc_exclude = 0;
511 attrs[0].an_name.bv_len = 0;
512 attrs[0].an_name.bv_val = NULL;
515 manageDSAit = get_manageDSAit( sop );
517 /* Sync control overrides manageDSAit */
518 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
519 if ( manageDSAit == SLAP_NO_CONTROL ) {
520 manageDSAit = SLAP_CRITICAL_CONTROL;
522 } else if ( IS_PSEARCH ) {
523 if ( manageDSAit == SLAP_NO_CONTROL ) {
524 manageDSAit = SLAP_CRITICAL_CONTROL;
529 ltid = opinfo->boi_txn;
530 locker = TXN_ID( ltid );
532 rs->sr_err = LOCK_ID( bdb->bi_dbenv, &locker );
538 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
543 if ( sop->o_req_ndn.bv_len == 0 ) {
544 /* DIT root special case */
545 ei_root.bei_e = &e_root;
546 ei_root.bei_parent = &ei_root;
547 e_root.e_private = &ei_root;
549 e_root.e_nname.bv_val="";
550 e_root.e_name.bv_val="";
552 rs->sr_err = LDAP_SUCCESS;
555 /* get entry with reader lock */
556 rs->sr_err = bdb_dn2entry( op, ltid, &sop->o_req_ndn, &ei,
568 send_ldap_error( sop, rs, LDAP_BUSY, "ldap server busy" );
570 LOCK_ID_FREE (bdb->bi_dbenv, locker );
572 case DB_LOCK_DEADLOCK:
573 case DB_LOCK_NOTGRANTED:
576 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
578 LOCK_ID_FREE (bdb->bi_dbenv, locker );
582 if ( e && (op->ors_deref & LDAP_DEREF_FINDING) && is_entry_alias(e) ) {
583 BDB_IDL_ZERO(candidates);
584 e = deref_base( op, rs, e, &matched, locker, &lock,
589 struct berval matched_dn = BER_BVNULL;
591 if ( matched != NULL ) {
593 ber_dupbv( &matched_dn, &matched->e_name );
595 erefs = is_entry_referral( matched )
596 ? get_entry_referrals( op, matched )
599 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
604 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
605 &sop->o_req_dn, sop->oq_search.rs_scope );
606 ber_bvarray_free( erefs );
610 rs->sr_ref = referral_rewrite( default_referral,
611 NULL, &sop->o_req_dn, sop->oq_search.rs_scope );
614 rs->sr_err = LDAP_REFERRAL;
615 rs->sr_matched = matched_dn.bv_val;
616 send_ldap_result( sop, rs );
619 LOCK_ID_FREE (bdb->bi_dbenv, locker );
621 ber_bvarray_free( rs->sr_ref );
624 if ( matched_dn.bv_val ) {
625 ber_memfree( matched_dn.bv_val );
626 rs->sr_matched = NULL;
631 if ( !manageDSAit && e != &e_root && is_entry_referral( e ) ) {
632 /* entry is a referral, don't allow add */
633 struct berval matched_dn;
636 ber_dupbv( &matched_dn, &e->e_name );
637 erefs = get_entry_referrals( op, e );
639 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
643 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
644 &sop->o_req_dn, sop->oq_search.rs_scope );
645 ber_bvarray_free( erefs );
649 LDAP_LOG ( OPERATION, RESULTS,
650 "bdb_search: entry is referral\n", 0, 0, 0 );
652 Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
656 if (!rs->sr_ref) rs->sr_text = "bad_referral object";
657 rs->sr_err = LDAP_REFERRAL;
658 rs->sr_matched = matched_dn.bv_val;
659 send_ldap_result( sop, rs );
662 LOCK_ID_FREE (bdb->bi_dbenv, locker );
663 ber_bvarray_free( rs->sr_ref );
665 ber_memfree( matched_dn.bv_val );
666 rs->sr_matched = NULL;
670 if ( get_assert( op ) &&
671 ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
673 rs->sr_err = LDAP_ASSERTION_FAILED;
674 send_ldap_result( sop, rs );
678 /* compute it anyway; root does not use it */
679 stoptime = op->o_time + sop->ors_tlimit;
681 /* need normalized dn below */
682 ber_dupbv( &realbase, &e->e_nname );
684 /* Copy info to base, must free entry before accessing the database
685 * in search_candidates, to avoid deadlocks.
687 base.e_private = e->e_private;
688 base.e_nname = realbase;
691 if ( e != &e_root ) {
692 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
697 rs->sr_err = bdb_get_commit_csn( sop, rs, &search_context_csn,
698 locker, &ctxcsn_lock );
700 if ( rs->sr_err != LDAP_SUCCESS ) {
701 send_ldap_error( sop, rs, rs->sr_err,
702 "error in csn management in search" );
706 if ( sop->o_sync_mode != SLAP_SYNC_NONE &&
707 sop->o_sync_state.ctxcsn &&
708 sop->o_sync_state.ctxcsn->bv_val &&
709 ber_bvcmp( &sop->o_sync_state.ctxcsn[0], search_context_csn ) == 0 )
711 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
715 search_context_csn = ber_dupbv( NULL, &op->o_sync_csn );
718 /* select candidates */
719 if ( sop->oq_search.rs_scope == LDAP_SCOPE_BASE ) {
720 rs->sr_err = base_candidate( op->o_bd, &base, candidates );
723 BDB_IDL_ZERO( candidates );
724 BDB_IDL_ZERO( scopes );
725 rs->sr_err = search_candidates( op, sop, rs, &base,
726 locker, candidates, scopes );
729 if ( !IS_PSEARCH && sop->o_sync_mode != SLAP_SYNC_NONE ) {
730 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
733 /* start cursor at beginning of candidates.
737 if ( !BDB_IDL_IS_RANGE( candidates ) ) {
738 cursor = bdb_idl_search( candidates, ps_e->e_id );
739 if ( candidates[cursor] != ps_e->e_id ) {
740 rs->sr_err = LDAP_SUCCESS;
743 } else if ( ps_e->e_id < BDB_IDL_RANGE_FIRST( candidates ) ||
744 ps_e->e_id > BDB_IDL_RANGE_LAST( candidates ))
746 rs->sr_err = LDAP_SUCCESS;
750 candidates[1] = ps_e->e_id;
753 if ( candidates[0] == 0 ) {
755 LDAP_LOG ( OPERATION, RESULTS,
756 "bdb_search: no candidates\n", 0, 0, 0 );
758 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
765 /* if not root and candidates exceed to-be-checked entries, abort */
766 if ( sop->ors_limit /* isroot == TRUE */ &&
767 sop->ors_limit->lms_s_unchecked != -1 &&
768 BDB_IDL_N(candidates) > (unsigned) sop->ors_limit->lms_s_unchecked )
770 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
771 send_ldap_result( sop, rs );
772 rs->sr_err = LDAP_SUCCESS;
776 if ( sop->ors_limit == NULL /* isroot == FALSE */ ||
777 !sop->ors_limit->lms_s_pr_hide )
779 tentries = BDB_IDL_N(candidates);
782 if ( get_pagedresults(sop) > SLAP_NO_CONTROL ) {
783 if ( (ID)( sop->o_pagedresults_state.ps_cookie ) == 0 ) {
784 id = bdb_idl_first( candidates, &cursor );
787 if ( sop->o_pagedresults_size == 0 ) {
788 rs->sr_err = LDAP_SUCCESS;
789 rs->sr_text = "search abandoned by pagedResult size=0";
790 send_ldap_result( sop, rs );
793 for ( id = bdb_idl_first( candidates, &cursor );
795 id <= (ID)( sop->o_pagedresults_state.ps_cookie );
796 id = bdb_idl_next( candidates, &cursor ) )
802 if ( cursor == NOID ) {
804 LDAP_LOG ( OPERATION, RESULTS,
805 "bdb_search: no paged results candidates\n",
808 Debug( LDAP_DEBUG_TRACE,
809 "bdb_search: no paged results candidates\n",
812 send_paged_response( sop, rs, &lastid, 0 );
814 rs->sr_err = LDAP_OTHER;
820 if (( sop->o_sync_mode & SLAP_SYNC_REFRESH ) || IS_PSEARCH ) {
823 cookief.f_choice = LDAP_FILTER_AND;
824 cookief.f_and = &csnfnot;
825 cookief.f_next = NULL;
827 csnfnot.f_choice = LDAP_FILTER_NOT;
828 csnfnot.f_not = &csnfeq;
829 csnfnot.f_next = &csnfand;
831 csnfeq.f_choice = LDAP_FILTER_EQUALITY;
832 csnfeq.f_ava = &aa_eq;
833 csnfeq.f_av_desc = slap_schema.si_ad_entryCSN;
834 if ( sop->o_sync_state.ctxcsn != NULL ) {
835 csnfeq.f_av_value = *sop->o_sync_state.ctxcsn;
837 csnfeq.f_av_value = slap_empty_bv;
840 csnfand.f_choice = LDAP_FILTER_AND;
841 csnfand.f_and = &csnfge;
842 csnfand.f_next = NULL;
844 csnfge.f_choice = LDAP_FILTER_GE;
845 csnfge.f_ava = &aa_ge;
846 csnfge.f_av_desc = slap_schema.si_ad_entryCSN;
847 if ( sop->o_sync_state.ctxcsn != NULL ) {
848 csnfge.f_av_value = *sop->o_sync_state.ctxcsn;
850 csnfge.f_av_value = slap_empty_bv;
853 if ( search_context_csn && !IS_PSEARCH ) {
854 csnfge.f_next = &contextcsnand;
856 contextcsnand.f_choice = LDAP_FILTER_AND;
857 contextcsnand.f_and = &contextcsnle;
858 contextcsnand.f_next = NULL;
860 contextcsnle.f_choice = LDAP_FILTER_LE;
861 contextcsnle.f_ava = &aa_le;
862 contextcsnle.f_av_desc = slap_schema.si_ad_entryCSN;
863 contextcsnle.f_av_value = *search_context_csn;
864 contextcsnle.f_next = sop->oq_search.rs_filter;
866 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
867 if ( sop->o_sync_state.ctxcsn &&
868 sop->o_sync_state.ctxcsn->bv_val != NULL )
870 value_match( &match, slap_schema.si_ad_entryCSN, mr,
871 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
872 &sop->o_sync_state.ctxcsn[0], search_context_csn,
877 no_sync_state_change = ( match >= 0 );
879 csnfge.f_next = sop->oq_search.rs_filter;
883 for ( id = bdb_idl_first( candidates, &cursor );
884 id != NOID && !no_sync_state_change;
885 id = bdb_idl_next( candidates, &cursor ) )
890 /* check for abandon */
891 if ( sop->o_abandon ) {
893 bdb_drop_psearch( sop, sop->o_msgid );
895 rs->sr_err = LDAP_SUCCESS;
899 if ( sop->o_cancel ) {
900 assert( sop->o_cancel == SLAP_CANCEL_REQ );
901 rs->sr_err = LDAP_CANCELLED;
902 send_ldap_result( sop, rs );
903 sop->o_cancel = SLAP_CANCEL_ACK;
904 rs->sr_err = LDAP_SUCCESS;
908 /* check time limit */
909 if ( sop->ors_tlimit != SLAP_NO_LIMIT
910 && slap_get_time() > stoptime )
912 rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
913 rs->sr_ref = rs->sr_v2ref;
914 send_ldap_result( sop, rs );
915 rs->sr_err = LDAP_SUCCESS;
921 /* get the entry with reader lock */
923 rs->sr_err = bdb_cache_find_id( op, ltid,
924 id, &ei, 0, locker, &lock );
926 if (rs->sr_err == LDAP_BUSY) {
927 rs->sr_text = "ldap server busy";
928 send_ldap_result( sop, rs );
931 } else if ( rs->sr_err == DB_LOCK_DEADLOCK
932 || rs->sr_err == DB_LOCK_NOTGRANTED )
937 if ( ei && rs->sr_err == LDAP_SUCCESS ) {
944 if( !BDB_IDL_IS_RANGE(candidates) ) {
945 /* only complain for non-range IDLs */
947 LDAP_LOG ( OPERATION, RESULTS,
948 "bdb_search: candidate %ld not found\n",
951 Debug( LDAP_DEBUG_TRACE,
952 "bdb_search: candidate %ld not found\n",
965 #ifdef BDB_SUBENTRIES
966 /* FIXME: send all but syncrepl */
968 if ( !is_sync_protocol( sop ) )
971 if ( is_entry_subentry( e ) ) {
972 if( sop->oq_search.rs_scope != LDAP_SCOPE_BASE ) {
973 if(!get_subentries_visibility( sop )) {
974 /* only subentries are visible */
978 } else if ( get_subentries( sop ) &&
979 !get_subentries_visibility( sop ))
981 /* only subentries are visible */
985 } else if ( get_subentries_visibility( sop )) {
986 /* only subentries are visible */
990 #endif /* BDB_SUBENTRIES */
992 /* Does this candidate actually satisfy the search scope?
994 * Note that we don't lock access to the bei_parent pointer.
995 * Since only leaf nodes can be deleted, the parent of any
996 * node will always be a valid node. Also since we have
997 * a Read lock on the data, it cannot be renamed out of the
998 * scope while we are looking at it, and unless we're using
999 * BDB_HIER, its parents cannot be moved either.
1001 switch( sop->ors_scope ) {
1002 case LDAP_SCOPE_BASE:
1003 /* This is always true, yes? */
1004 if ( id == base.e_id ) scopeok = 1;
1007 case LDAP_SCOPE_ONELEVEL:
1008 if ( ei->bei_parent->bei_id == base.e_id ) scopeok = 1;
1011 #ifdef LDAP_SCOPE_CHILDREN
1012 case LDAP_SCOPE_CHILDREN:
1013 if ( id == base.e_id ) break;
1016 case LDAP_SCOPE_SUBTREE: {
1018 for (tmp = BEI(e); tmp;
1019 tmp = tmp->bei_parent ) {
1020 if ( tmp->bei_id == base.e_id ) {
1029 /* aliases were already dereferenced in candidate list */
1030 if ( sop->ors_deref & LDAP_DEREF_SEARCHING ) {
1031 /* but if the search base is an alias, and we didn't
1032 * deref it when finding, return it.
1034 if ( is_entry_alias(e) &&
1035 ((sop->ors_deref & LDAP_DEREF_FINDING) ||
1036 !bvmatch(&e->e_nname, &op->o_req_ndn)))
1041 /* scopes is only non-empty for onelevel or subtree */
1042 if ( !scopeok && BDB_IDL_N(scopes) ) {
1044 if ( sop->ors_scope == LDAP_SCOPE_ONELEVEL ) {
1045 x = bdb_idl_search( scopes, e->e_id );
1046 if ( scopes[x] == e->e_id ) scopeok = 1;
1048 /* subtree, walk up the tree */
1049 EntryInfo *tmp = BEI(e);
1050 for (;tmp->bei_parent; tmp=tmp->bei_parent) {
1051 x = bdb_idl_search( scopes, tmp->bei_id );
1052 if ( scopes[x] == tmp->bei_id ) {
1062 /* Not in scope, ignore it */
1065 LDAP_LOG ( OPERATION, RESULTS,
1066 "bdb_search: %ld scope not okay\n",
1069 Debug( LDAP_DEBUG_TRACE,
1070 "bdb_search: %ld scope not okay\n",
1077 * if it's a referral, add it to the list of referrals. only do
1078 * this for non-base searches, and don't check the filter
1079 * explicitly here since it's only a candidate anyway.
1081 if ( !manageDSAit && sop->oq_search.rs_scope != LDAP_SCOPE_BASE
1082 && is_entry_referral( e ) )
1084 BerVarray erefs = get_entry_referrals( sop, e );
1085 rs->sr_ref = referral_rewrite( erefs, &e->e_name, NULL,
1086 sop->oq_search.rs_scope == LDAP_SCOPE_ONELEVEL
1087 ? LDAP_SCOPE_BASE : LDAP_SCOPE_SUBTREE );
1089 send_search_reference( sop, rs );
1091 ber_bvarray_free( rs->sr_ref );
1092 ber_bvarray_free( erefs );
1098 if ( !manageDSAit && is_entry_glue( e )) {
1102 /* if it matches the filter and scope, send it */
1104 if (ps_type != LDAP_PSEARCH_BY_SCOPEOUT) {
1105 rs->sr_err = test_filter( sop, rs->sr_entry, &cookief );
1107 rs->sr_err = LDAP_COMPARE_TRUE;
1111 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1112 rc_sync = test_filter( sop, rs->sr_entry, &cookief );
1113 rs->sr_err = test_filter( sop, rs->sr_entry, &contextcsnand );
1114 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1115 if ( rc_sync == LDAP_COMPARE_TRUE ) {
1116 if ( no_sync_state_change ) {
1118 LDAP_LOG ( OPERATION, RESULTS,
1119 "bdb_search: error in context csn management\n",
1122 Debug( LDAP_DEBUG_TRACE,
1123 "bdb_search: error in context csn management\n",
1127 entry_sync_state = LDAP_SYNC_ADD;
1130 if ( no_sync_state_change ) {
1133 entry_sync_state = LDAP_SYNC_PRESENT;
1138 rs->sr_err = test_filter( sop,
1139 rs->sr_entry, sop->oq_search.rs_filter );
1143 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1144 /* check size limit */
1145 if ( --sop->ors_slimit == -1 &&
1146 sop->o_sync_slog_size == -1 )
1149 bdb_cache_return_entry_r( bdb->bi_dbenv,
1150 &bdb->bi_cache, e, &lock );
1153 rs->sr_entry = NULL;
1154 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
1155 rs->sr_ref = rs->sr_v2ref;
1156 send_ldap_result( sop, rs );
1157 rs->sr_err = LDAP_SUCCESS;
1161 if ( get_pagedresults(sop) > SLAP_NO_CONTROL ) {
1162 if ( rs->sr_nentries >= sop->o_pagedresults_size ) {
1163 send_paged_response( sop, rs, &lastid, tentries );
1174 int premodify_found = 0;
1175 int entry_sync_state;
1177 if ( ps_type == LDAP_PSEARCH_BY_ADD ||
1178 ps_type == LDAP_PSEARCH_BY_DELETE ||
1179 ps_type == LDAP_PSEARCH_BY_MODIFY ||
1180 ps_type == LDAP_PSEARCH_BY_SCOPEOUT )
1182 if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1183 struct psid_entry* psid_e;
1184 LDAP_LIST_FOREACH( psid_e,
1185 &op->o_pm_list, ps_link)
1187 if( psid_e->ps_op == sop ) {
1188 premodify_found = 1;
1189 LDAP_LIST_REMOVE(psid_e, ps_link);
1193 if (psid_e != NULL) free (psid_e);
1196 if ( ps_type == LDAP_PSEARCH_BY_ADD ) {
1197 entry_sync_state = LDAP_SYNC_ADD;
1198 } else if ( ps_type == LDAP_PSEARCH_BY_DELETE ) {
1199 entry_sync_state = LDAP_SYNC_DELETE;
1200 } else if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1201 if ( premodify_found ) {
1202 entry_sync_state = LDAP_SYNC_MODIFY;
1204 entry_sync_state = LDAP_SYNC_ADD;
1206 } else if ( ps_type == LDAP_PSEARCH_BY_SCOPEOUT ) {
1207 entry_sync_state = LDAP_SYNC_DELETE;
1209 rs->sr_err = LDAP_OTHER;
1213 if ( sop->o_sync_slog_size != -1 ) {
1214 if ( entry_sync_state == LDAP_SYNC_DELETE ) {
1215 result = slap_add_session_log( op, sop, e );
1220 struct berval cookie;
1221 slap_compose_sync_cookie( sop, &cookie,
1223 sop->o_sync_state.sid,
1224 sop->o_sync_state.rid );
1225 rs->sr_err = slap_build_sync_state_ctrl( sop,
1226 rs, e, entry_sync_state, ctrls,
1227 num_ctrls++, 1, &cookie );
1228 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1229 rs->sr_attrs = attrs;
1230 rs->sr_ctrls = ctrls;
1232 result = send_search_entry( sop, rs );
1233 if ( cookie.bv_val ) ch_free( cookie.bv_val );
1235 ctrls[num_ctrls-1]->ldctl_value.bv_val,
1237 slap_sl_free( ctrls[--num_ctrls],
1239 ctrls[num_ctrls] = NULL;
1240 rs->sr_ctrls = NULL;
1243 } else if ( ps_type == LDAP_PSEARCH_BY_PREMODIFY ) {
1244 struct psid_entry* psid_e;
1245 psid_e = (struct psid_entry *) ch_calloc(1,
1246 sizeof(struct psid_entry));
1247 psid_e->ps_op = sop;
1248 LDAP_LIST_INSERT_HEAD( &op->o_pm_list,
1253 LDAP_LOG ( OPERATION, RESULTS,
1254 "bdb_search: invalid ps_type (%d) \n",
1257 Debug( LDAP_DEBUG_TRACE,
1258 "bdb_search: invalid ps_type (%d) \n",
1264 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1265 if ( rc_sync == LDAP_COMPARE_TRUE ) { /* ADD */
1266 rs->sr_err = slap_build_sync_state_ctrl( sop,
1267 rs, e, entry_sync_state, ctrls,
1268 num_ctrls++, 0, NULL );
1269 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1270 rs->sr_ctrls = ctrls;
1271 rs->sr_attrs = sop->oq_search.rs_attrs;
1273 result = send_search_entry( sop, rs );
1275 ctrls[num_ctrls-1]->ldctl_value.bv_val,
1277 slap_sl_free( ctrls[--num_ctrls],
1279 ctrls[num_ctrls] = NULL;
1280 rs->sr_ctrls = NULL;
1282 } else { /* PRESENT */
1283 if ( sync_send_present_mode ) {
1284 result = slap_build_syncUUID_set( sop,
1286 if ( result <= 0 ) {
1290 if ( syncUUID_set_cnt ==
1291 SLAP_SYNCUUID_SET_SIZE )
1293 rs->sr_err = LDAP_SUCCESS;
1294 rs->sr_rspoid = LDAP_SYNC_INFO;
1295 rs->sr_ctrls = NULL;
1296 result = slap_send_syncinfo( sop, rs,
1297 LDAP_TAG_SYNC_ID_SET,
1298 NULL, 0, syncUUID_set, 0 );
1299 if ( result != LDAP_SUCCESS ) {
1302 ber_bvarray_free_x( syncUUID_set,
1304 syncUUID_set = NULL;
1305 syncUUID_set_cnt = 0;
1315 rs->sr_attrs = sop->oq_search.rs_attrs;
1316 rs->sr_ctrls = NULL;
1318 rs->sr_err = LDAP_SUCCESS;
1319 result = send_search_entry( sop, rs );
1324 case 0: /* entry sent ok */
1326 case 1: /* entry not sent */
1328 case -1: /* connection closed */
1330 bdb_cache_return_entry_r(bdb->bi_dbenv,
1331 &bdb->bi_cache, e, &lock);
1334 rs->sr_entry = NULL;
1335 rs->sr_err = LDAP_OTHER;
1342 LDAP_LOG ( OPERATION, RESULTS,
1343 "bdb_search: %ld does not match filter\n", (long) id, 0, 0);
1345 Debug( LDAP_DEBUG_TRACE,
1346 "bdb_search: %ld does not match filter\n",
1353 /* free reader lock */
1355 bdb_cache_return_entry_r( bdb->bi_dbenv,
1356 &bdb->bi_cache, e , &lock );
1357 if ( sop->o_nocaching ) {
1358 bdb_cache_delete_entry( bdb, ei, locker, &lock );
1362 rs->sr_entry = NULL;
1365 ldap_pvt_thread_yield();
1368 if ( syncUUID_set_cnt > 0 ) {
1369 rs->sr_err = LDAP_SUCCESS;
1370 rs->sr_rspoid = LDAP_SYNC_INFO;
1371 rs->sr_ctrls = NULL;
1372 slap_send_syncinfo( sop, rs, LDAP_TAG_SYNC_ID_SET,
1373 NULL, 0, syncUUID_set, 0 );
1374 ber_bvarray_free_x( syncUUID_set, sop->o_tmpmemctx );
1375 syncUUID_set_cnt = 0;
1380 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1381 if ( sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
1382 struct berval cookie;
1383 slap_compose_sync_cookie( sop, &cookie, search_context_csn,
1384 sop->o_sync_state.sid, sop->o_sync_state.rid );
1386 if ( sync_send_present_mode ) {
1387 rs->sr_err = LDAP_SUCCESS;
1388 rs->sr_rspoid = LDAP_SYNC_INFO;
1389 rs->sr_ctrls = NULL;
1390 slap_send_syncinfo( sop, rs,
1391 LDAP_TAG_SYNC_REFRESH_PRESENT, &cookie, 1, NULL, 0 );
1394 if ( !no_sync_state_change ) {
1396 ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
1397 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
1400 if ( ps_list->o_sync_slog_size > 0 ) {
1401 if ( ps_list->o_sync_state.sid ==
1402 sop->o_sync_state.sid )
1411 rs->sr_err = LDAP_SUCCESS;
1412 rs->sr_rspoid = NULL;
1413 rs->sr_ctrls = NULL;
1414 slap_send_session_log( op, ps_list, rs );
1416 ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
1419 rs->sr_err = LDAP_SUCCESS;
1420 rs->sr_rspoid = LDAP_SYNC_INFO;
1421 rs->sr_ctrls = NULL;
1422 slap_send_syncinfo( sop, rs,
1423 LDAP_TAG_SYNC_REFRESH_DELETE, &cookie, 1, NULL, 0 );
1426 if ( cookie.bv_val ) ch_free( cookie.bv_val );
1429 /* refreshOnly mode */
1430 struct berval cookie;
1431 slap_compose_sync_cookie( sop, &cookie, search_context_csn,
1432 sop->o_sync_state.sid, sop->o_sync_state.rid );
1434 if ( sync_send_present_mode ) {
1435 slap_build_sync_done_ctrl( sop, rs, ctrls,
1436 num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_PRESENTS );
1439 if ( !no_sync_state_change ) {
1441 ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
1442 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
1445 if ( ps_list->o_sync_slog_size > 0 ) {
1446 if ( ps_list->o_sync_state.sid ==
1447 sop->o_sync_state.sid ) {
1455 slap_send_session_log( op, ps_list, rs );
1457 ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
1460 slap_build_sync_done_ctrl( sop, rs, ctrls,
1461 num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_DELETES );
1464 rs->sr_ctrls = ctrls;
1465 rs->sr_ref = rs->sr_v2ref;
1466 rs->sr_err = (rs->sr_v2ref == NULL)
1467 ? LDAP_SUCCESS : LDAP_REFERRAL;
1468 rs->sr_rspoid = NULL;
1469 send_ldap_result( sop, rs );
1470 if ( ctrls[num_ctrls-1]->ldctl_value.bv_val != NULL ) {
1471 slap_sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
1474 slap_sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1475 ctrls[num_ctrls] = NULL;
1476 if ( cookie.bv_val ) ch_free( cookie.bv_val );
1480 rs->sr_ctrls = NULL;
1481 rs->sr_ref = rs->sr_v2ref;
1482 rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
1483 rs->sr_rspoid = NULL;
1484 if ( get_pagedresults(sop) > SLAP_NO_CONTROL ) {
1485 send_paged_response( sop, rs, NULL, 0 );
1487 send_ldap_result( sop, rs );
1492 rs->sr_err = LDAP_SUCCESS;
1495 if( !IS_PSEARCH && e != NULL ) {
1496 /* free reader lock */
1497 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
1501 LOCK_ID_FREE( bdb->bi_dbenv, locker );
1503 ber_bvfree( search_context_csn );
1505 if( rs->sr_v2ref ) {
1506 ber_bvarray_free( rs->sr_v2ref );
1507 rs->sr_v2ref = NULL;
1509 if( realbase.bv_val ) ch_free( realbase.bv_val );
1515 static int base_candidate(
1521 LDAP_LOG ( OPERATION, ENTRY,
1522 "base_candidate: base: \"%s\" (0x%08lx)\n",
1523 e->e_nname.bv_val, (long) e->e_id, 0);
1525 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
1526 e->e_nname.bv_val, (long) e->e_id, 0);
1534 /* Look for "objectClass Present" in this filter.
1535 * Also count depth of filter tree while we're at it.
1537 static int oc_filter(
1546 if( cur > *max ) *max = cur;
1548 switch( f->f_choice ) {
1549 case LDAP_FILTER_PRESENT:
1550 if (f->f_desc == slap_schema.si_ad_objectClass) {
1555 case LDAP_FILTER_AND:
1556 case LDAP_FILTER_OR:
1558 for ( f=f->f_and; f; f=f->f_next ) {
1559 (void) oc_filter(f, cur, max);
1569 static void search_stack_free( void *key, void *data )
1571 ber_memfree_x(data, NULL);
1574 static void *search_stack( Operation *op )
1576 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1579 if ( op->o_threadctx ) {
1580 ldap_pvt_thread_pool_getkey( op->o_threadctx, search_stack,
1583 ret = bdb->bi_search_stack;
1587 ret = ch_malloc( bdb->bi_search_stack_depth * BDB_IDL_UM_SIZE
1589 if ( op->o_threadctx ) {
1590 ldap_pvt_thread_pool_setkey( op->o_threadctx, search_stack,
1591 ret, search_stack_free );
1593 bdb->bi_search_stack = ret;
1599 static int search_candidates(
1608 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1610 Filter f, rf, xf, nf;
1612 AttributeAssertion aa_ref;
1613 #ifdef BDB_SUBENTRIES
1615 AttributeAssertion aa_subentry;
1619 * This routine takes as input a filter (user-filter)
1620 * and rewrites it as follows:
1621 * (&(scope=DN)[(objectClass=subentry)]
1622 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
1626 LDAP_LOG ( OPERATION, ENTRY,
1627 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1628 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope);
1630 Debug(LDAP_DEBUG_TRACE,
1631 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1632 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope );
1635 xf.f_or = op->oq_search.rs_filter;
1636 xf.f_choice = LDAP_FILTER_OR;
1639 /* If the user's filter uses objectClass=*,
1640 * these clauses are redundant.
1642 if (!oc_filter(op->oq_search.rs_filter, 1, &depth)
1643 && !get_subentries_visibility(op)
1644 && !is_sync_protocol(op) )
1646 if( !get_manageDSAit(op) && !get_domainScope(op) ) {
1647 /* match referral objects */
1648 struct berval bv_ref = { sizeof("referral")-1, "referral" };
1649 rf.f_choice = LDAP_FILTER_EQUALITY;
1651 rf.f_av_desc = slap_schema.si_ad_objectClass;
1652 rf.f_av_value = bv_ref;
1653 rf.f_next = xf.f_or;
1660 f.f_choice = LDAP_FILTER_AND;
1662 /* Dummy; we compute scope separately now */
1663 nf.f_choice = SLAPD_FILTER_COMPUTED;
1664 nf.f_result = LDAP_SUCCESS;
1665 nf.f_next = ( xf.f_or == op->oq_search.rs_filter )
1666 ? op->oq_search.rs_filter : &xf ;
1667 /* Filter depth increased again, adding dummy clause */
1670 #ifdef BDB_SUBENTRIES
1671 if( get_subentries_visibility( op ) ) {
1672 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1673 sf.f_choice = LDAP_FILTER_EQUALITY;
1674 sf.f_ava = &aa_subentry;
1675 sf.f_av_desc = slap_schema.si_ad_objectClass;
1676 sf.f_av_value = bv_subentry;
1677 sf.f_next = nf.f_next;
1682 /* Allocate IDL stack, plus 1 more for former tmp */
1683 if ( depth+1 > bdb->bi_search_stack_depth ) {
1684 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1686 stack = search_stack( stackop );
1689 if( op->ors_deref & LDAP_DEREF_SEARCHING ) {
1690 rc = search_aliases( op, rs, e, locker, ids, scopes, stack );
1692 rc = bdb_dn2idl( op, e, ids, stack );
1695 if ( rc == LDAP_SUCCESS ) {
1696 rc = bdb_filter_candidates( op, &f, ids,
1697 stack, stack+BDB_IDL_UM_SIZE );
1700 if ( depth+1 > bdb->bi_search_stack_depth ) {
1706 LDAP_LOG ( OPERATION, DETAIL1,
1707 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1709 Debug(LDAP_DEBUG_TRACE,
1710 "bdb_search_candidates: failed (rc=%d)\n",
1716 LDAP_LOG ( OPERATION, DETAIL1,
1717 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1718 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1719 (long) BDB_IDL_LAST(ids));
1721 Debug(LDAP_DEBUG_TRACE,
1722 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1724 (long) BDB_IDL_FIRST(ids),
1725 (long) BDB_IDL_LAST(ids) );
1733 send_paged_response(
1739 LDAPControl ctrl, *ctrls[2];
1740 BerElementBuffer berbuf;
1741 BerElement *ber = (BerElement *)&berbuf;
1742 PagedResultsCookie respcookie;
1743 struct berval cookie;
1746 LDAP_LOG ( OPERATION, ENTRY,
1747 "send_paged_response: lastid=0x%08lx nentries=%d\n",
1748 lastid ? *lastid : 0, rs->sr_nentries, NULL );
1750 Debug(LDAP_DEBUG_ARGS,
1751 "send_paged_response: lastid=0x%08lx nentries=%d\n",
1752 lastid ? *lastid : 0, rs->sr_nentries, NULL );
1755 ctrl.ldctl_value.bv_val = NULL;
1759 ber_init2( ber, NULL, LBER_USE_DER );
1762 respcookie = ( PagedResultsCookie )(*lastid);
1763 cookie.bv_len = sizeof( respcookie );
1764 cookie.bv_val = (char *)&respcookie;
1767 respcookie = ( PagedResultsCookie )0;
1772 op->o_conn->c_pagedresults_state.ps_cookie = respcookie;
1773 op->o_conn->c_pagedresults_state.ps_count =
1774 op->o_pagedresults_state.ps_count + rs->sr_nentries;
1776 /* return size of 0 -- no estimate */
1777 ber_printf( ber, "{iO}", 0, &cookie );
1779 if ( ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 ) == -1 ) {
1783 ctrls[0]->ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
1784 ctrls[0]->ldctl_iscritical = 0;
1786 rs->sr_ctrls = ctrls;
1787 rs->sr_err = LDAP_SUCCESS;
1788 send_ldap_result( op, rs );
1789 rs->sr_ctrls = NULL;
1792 (void) ber_free_buf( ber );