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_pagerequest_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) {
69 /* Remember the last entry we looked at, so we can
74 /* If this is part of a subtree or onelevel search,
75 * have we seen this ID before? If so, quit.
77 if ( visited && bdb_idl_insert( visited, e->e_id ) ) {
82 /* If we've seen this ID during this deref iteration,
85 if ( bdb_idl_insert( tmp, e->e_id ) ) {
86 rs->sr_err = LDAP_ALIAS_PROBLEM;
87 rs->sr_text = "circular alias";
92 /* If there was a problem getting the aliasedObjectName,
93 * get_alias_dn will have set the error status.
95 if ( get_alias_dn(e, &ndn, &rs->sr_err, &rs->sr_text) ) {
100 rs->sr_err = bdb_dn2entry( op, NULL, &ndn, &ei,
103 if ( ei ) e = ei->bei_e;
107 rs->sr_err = LDAP_ALIAS_PROBLEM;
108 rs->sr_text = "aliasedObject not found";
112 /* Free the previous entry, continue to work with the
113 * one we just retrieved.
115 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
119 /* We found a regular entry. Return this to the caller. The
120 * entry is still locked for Read.
122 if (!is_entry_alias(e)) {
123 rs->sr_err = LDAP_SUCCESS;
131 /* Look for and dereference all aliases within the search scope. Adds
132 * the dereferenced entries to the "ids" list. Requires "stack" to be
133 * able to hold 8 levels of DB_SIZE IDLs. Of course we're hardcoded to
134 * require a minimum of 8 UM_SIZE IDLs so this is never a problem.
136 static int search_aliases(
146 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
147 ID *aliases, *curscop, *subscop, *visited, *newsubs, *oldsubs, *tmp;
148 ID cursora, ida, cursoro, ido, *subscop2;
151 struct berval bv_alias = { sizeof("alias")-1, "alias" };
152 AttributeAssertion aa_alias;
154 DB_LOCK locka, lockr;
157 aliases = stack; /* IDL of all aliases in the database */
158 curscop = aliases + BDB_IDL_DB_SIZE; /* Aliases in the current scope */
159 subscop = curscop + BDB_IDL_DB_SIZE; /* The current scope */
160 visited = subscop + BDB_IDL_DB_SIZE; /* IDs we've seen in this search */
161 newsubs = visited + BDB_IDL_DB_SIZE; /* New subtrees we've added */
162 oldsubs = newsubs + BDB_IDL_DB_SIZE; /* Subtrees added previously */
163 tmp = oldsubs + BDB_IDL_DB_SIZE; /* Scratch space for deref_base() */
165 /* A copy of subscop, because subscop gets clobbered by
166 * the bdb_idl_union/intersection routines
168 subscop2 = tmp + BDB_IDL_DB_SIZE;
170 af.f_choice = LDAP_FILTER_EQUALITY;
171 af.f_ava = &aa_alias;
172 af.f_av_desc = slap_schema.si_ad_objectClass;
173 af.f_av_value = bv_alias;
176 /* Find all aliases in database */
177 BDB_IDL_ZERO( aliases );
178 rs->sr_err = bdb_filter_candidates( op, &af, aliases,
180 if (rs->sr_err != LDAP_SUCCESS) {
184 oldsubs[1] = e->e_id;
187 BDB_IDL_ZERO( visited );
188 BDB_IDL_ZERO( newsubs );
191 ido = bdb_idl_first( oldsubs, &cursoro );
194 /* Set curscop to only the aliases in the current scope. Start with
195 * all the aliases, obtain the IDL for the current scope, and then
196 * get the intersection of these two IDLs. Add the current scope
197 * to the cumulative list of candidates.
199 BDB_IDL_CPY( curscop, aliases );
200 rs->sr_err = bdb_dn2idl( op, e, subscop,
201 subscop2+BDB_IDL_DB_SIZE );
205 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, e, &locka);
207 BDB_IDL_CPY(subscop2, subscop);
208 rs->sr_err = bdb_idl_intersection(curscop, subscop);
209 bdb_idl_union( ids, subscop2 );
211 /* Dereference all of the aliases in the current scope. */
213 for (ida = bdb_idl_first(curscop, &cursora); ida != NOID;
214 ida = bdb_idl_next(curscop, &cursora))
217 rs->sr_err = bdb_cache_find_id(op, NULL,
218 ida, &ei, 0, locker, &lockr );
219 if (rs->sr_err != LDAP_SUCCESS) {
224 /* This should only happen if the curscop IDL has maxed out and
225 * turned into a range that spans IDs indiscriminately
227 if (!is_entry_alias(a)) {
228 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
233 /* Actually dereference the alias */
235 a = deref_base( op, rs, a, &matched, locker, &lockr,
238 /* If the target was not already in our current candidates,
239 * make note of it in the newsubs list. Also
240 * set it in the scopes list so that bdb_search
243 if (bdb_idl_insert(ids, a->e_id) == 0) {
244 bdb_idl_insert(newsubs, a->e_id);
245 bdb_idl_insert(scopes, a->e_id);
247 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
250 } else if (matched) {
251 /* Alias could not be dereferenced, or it deref'd to
252 * an ID we've already seen. Ignore it.
254 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
259 /* If this is a OneLevel search, we're done; oldsubs only had one
260 * ID in it. For a Subtree search, oldsubs may be a list of scope IDs.
262 if (op->ors_scope != LDAP_SCOPE_SUBTREE) break;
264 ido = bdb_idl_next( oldsubs, &cursoro );
266 /* If we're done processing the old scopes, did we add any new
267 * scopes in this iteration? If so, go back and do those now.
270 if (BDB_IDL_IS_ZERO(newsubs)) break;
271 BDB_IDL_CPY(oldsubs, newsubs);
272 BDB_IDL_ZERO(newsubs);
274 ido = bdb_idl_first( oldsubs, &cursoro );
277 /* Find the entry corresponding to the next scope. If it can't
278 * be found, ignore it and move on. This should never happen;
279 * we should never see the ID of an entry that doesn't exist.
280 * Set the name so that the scope's IDL can be retrieved.
283 rs->sr_err = bdb_cache_find_id(op, NULL, ido, &ei,
285 if ( rs->sr_err != LDAP_SUCCESS ) goto nextido;
292 int is_sync_protocol( Operation *op )
294 if ( op->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST )
299 #define IS_BDB_REPLACE(type) (( type == LDAP_PSEARCH_BY_DELETE ) || \
300 ( type == LDAP_PSEARCH_BY_SCOPEOUT ))
301 #define IS_PSEARCH (op != sop)
304 bdb_drop_psearch( Operation *op, ber_int_t msgid )
307 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
309 LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
310 if ( ps_list->o_connid == op->o_connid ) {
311 if ( ps_list->o_msgid == msgid ) {
312 ps_list->o_abandon = 1;
313 LDAP_LIST_REMOVE( ps_list, o_ps_link );
314 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
315 LDAP_STAILQ_REMOVE( &op->o_conn->c_ops, ps_list,
317 LDAP_STAILQ_NEXT( ps_list, o_next ) = NULL;
318 op->o_conn->c_n_ops_executing--;
319 op->o_conn->c_n_ops_completed++;
320 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
330 bdb_abandon( Operation *op, SlapReply *rs )
334 ps = bdb_drop_psearch( op, op->oq_abandon.rs_msgid );
336 if ( ps->o_tmpmemctx ) {
337 sl_mem_destroy( NULL, ps->o_tmpmemctx );
342 return LDAP_UNAVAILABLE;
346 bdb_cancel( Operation *op, SlapReply *rs )
350 ps = bdb_drop_psearch( op, op->oq_cancel.rs_msgid );
352 rs->sr_err = LDAP_CANCELLED;
353 send_ldap_result( ps, rs );
354 if ( ps->o_tmpmemctx ) {
355 sl_mem_destroy( NULL, ps->o_tmpmemctx );
360 return LDAP_UNAVAILABLE;
363 int bdb_search( Operation *op, SlapReply *rs )
365 return bdb_do_search( op, rs, op, NULL, 0 );
368 /* For persistent searches, op is the currently executing operation,
369 * sop is the persistent search. For regular searches, sop = op.
372 bdb_do_search( Operation *op, SlapReply *rs, Operation *sop,
373 Entry *ps_e, int ps_type )
375 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
378 ID candidates[BDB_IDL_UM_SIZE];
379 ID scopes[BDB_IDL_DB_SIZE];
380 Entry *e = NULL, base;
381 Entry *matched = NULL;
383 struct berval realbase = { 0, NULL };
387 AttributeName *attrs;
389 Filter contextcsnand, contextcsnle, cookief, csnfnot,
390 csnfeq, csnfand, csnfge;
391 AttributeAssertion aa_ge, aa_eq, aa_le;
393 struct berval *search_context_csn = NULL;
395 LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
397 AttributeName uuid_attr[2];
399 int entry_sync_state = -1;
400 AttributeName null_attr;
401 int no_sync_state_change = 0;
403 u_int32_t locker = 0;
407 int sync_send_present_mode = 1;
413 BerVarray syncUUID_set = NULL;
414 int syncUUID_set_cnt = 0;
417 LDAP_LOG( OPERATION, ENTRY, "bdb_search\n", 0, 0, 0 );
419 Debug( LDAP_DEBUG_TRACE, "=> bdb_search\n",
422 attrs = sop->oq_search.rs_attrs;
424 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST ) {
425 struct slap_session_entry *sent;
426 if ( sop->o_sync_state.sid >= 0 ) {
427 LDAP_LIST_FOREACH( sent, &bdb->bi_session_list, se_link ) {
428 if ( sent->se_id == sop->o_sync_state.sid ) {
429 sop->o_sync_slog_size = sent->se_size;
436 /* psearch needs to be registered before refresh begins */
437 /* psearch and refresh transmission is serialized in send_ldap_ber() */
438 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
439 ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
440 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
441 ldap_pvt_thread_rdwr_wunlock( &bdb->bi_pslist_rwlock );
443 } else if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST
444 && sop->o_sync_slog_size >= 0 )
446 ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
447 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
448 if ( ps_list->o_sync_slog_size >= 0 ) {
449 if ( ps_list->o_sync_state.sid == sop->o_sync_state.sid ) {
457 if ( ps_list->o_sync_slog_omitcsn.bv_len != 0 ) {
458 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
459 if ( sop->o_sync_state.ctxcsn &&
460 sop->o_sync_state.ctxcsn->bv_val != NULL )
462 value_match( &match, slap_schema.si_ad_entryCSN, mr,
463 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
464 sop->o_sync_state.ctxcsn,
465 &ps_list->o_sync_slog_omitcsn,
471 sync_send_present_mode = 0;
474 sync_send_present_mode = 0;
476 } else if ( sop->o_sync_slog_size >= 0 ) {
477 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
479 sop->o_sync_state.sid = -1;
481 ldap_pvt_thread_rdwr_wunlock( &bdb->bi_pslist_rwlock );
484 null_attr.an_desc = NULL;
485 null_attr.an_oc = NULL;
486 null_attr.an_oc_exclude = 0;
487 null_attr.an_name.bv_len = 0;
488 null_attr.an_name.bv_val = NULL;
490 for( num_ctrls = 0; num_ctrls < SLAP_MAX_RESPONSE_CONTROLS; num_ctrls++ ) {
491 ctrls[num_ctrls] = NULL;
495 if ( IS_PSEARCH && IS_BDB_REPLACE(ps_type)) {
497 attrs[0].an_desc = NULL;
498 attrs[0].an_oc = NULL;
499 attrs[0].an_oc_exclude = 0;
500 attrs[0].an_name.bv_len = 0;
501 attrs[0].an_name.bv_val = NULL;
504 manageDSAit = get_manageDSAit( sop );
506 /* Sync control overrides manageDSAit */
507 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
508 if ( manageDSAit == SLAP_NO_CONTROL ) {
509 manageDSAit = SLAP_CRITICAL_CONTROL;
511 } else if ( IS_PSEARCH ) {
512 if ( manageDSAit == SLAP_NO_CONTROL ) {
513 manageDSAit = SLAP_CRITICAL_CONTROL;
517 rs->sr_err = LOCK_ID( bdb->bi_dbenv, &locker );
523 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
527 if ( sop->o_req_ndn.bv_len == 0 ) {
528 /* DIT root special case */
529 e = (Entry *) &slap_entry_root;
530 rs->sr_err = LDAP_SUCCESS;
533 /* get entry with reader lock */
534 rs->sr_err = bdb_dn2entry( op, NULL, &sop->o_req_ndn, &ei,
546 send_ldap_error( sop, rs, LDAP_BUSY, "ldap server busy" );
547 LOCK_ID_FREE (bdb->bi_dbenv, locker );
549 case DB_LOCK_DEADLOCK:
550 case DB_LOCK_NOTGRANTED:
553 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
554 LOCK_ID_FREE (bdb->bi_dbenv, locker );
558 if ( e && (op->ors_deref & LDAP_DEREF_FINDING) && is_entry_alias(e) ) {
559 BDB_IDL_ZERO(candidates);
560 e = deref_base( op, rs, e, &matched, locker, &lock,
565 struct berval matched_dn = { 0, NULL };
567 if ( matched != NULL ) {
569 ber_dupbv( &matched_dn, &matched->e_name );
571 erefs = is_entry_referral( matched )
572 ? get_entry_referrals( op, matched )
575 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
580 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
581 &sop->o_req_dn, sop->oq_search.rs_scope );
582 ber_bvarray_free( erefs );
586 rs->sr_ref = referral_rewrite( default_referral,
587 NULL, &sop->o_req_dn, sop->oq_search.rs_scope );
590 rs->sr_err = LDAP_REFERRAL;
591 rs->sr_matched = matched_dn.bv_val;
592 send_ldap_result( sop, rs );
594 LOCK_ID_FREE (bdb->bi_dbenv, locker );
596 ber_bvarray_free( rs->sr_ref );
599 if ( matched_dn.bv_val ) {
600 ber_memfree( matched_dn.bv_val );
601 rs->sr_matched = NULL;
606 if ( !manageDSAit && e != &slap_entry_root && is_entry_referral( e ) ) {
607 /* entry is a referral, don't allow add */
608 struct berval matched_dn;
611 ber_dupbv( &matched_dn, &e->e_name );
612 erefs = get_entry_referrals( op, e );
614 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
618 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
619 &sop->o_req_dn, sop->oq_search.rs_scope );
620 ber_bvarray_free( erefs );
624 LDAP_LOG ( OPERATION, RESULTS,
625 "bdb_search: entry is referral\n", 0, 0, 0 );
627 Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
631 if (!rs->sr_ref) rs->sr_text = "bad_referral object";
632 rs->sr_err = LDAP_REFERRAL;
633 rs->sr_matched = matched_dn.bv_val;
634 send_ldap_result( sop, rs );
636 LOCK_ID_FREE (bdb->bi_dbenv, locker );
637 ber_bvarray_free( rs->sr_ref );
639 ber_memfree( matched_dn.bv_val );
640 rs->sr_matched = NULL;
644 if ( get_assert( op ) &&
645 ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
647 rs->sr_err = LDAP_ASSERTION_FAILED;
648 send_ldap_result( sop, rs );
652 /* compute it anyway; root does not use it */
653 stoptime = op->o_time + sop->ors_tlimit;
655 /* need normalized dn below */
656 ber_dupbv( &realbase, &e->e_nname );
658 /* Copy info to base, must free entry before accessing the database
659 * in search_candidates, to avoid deadlocks.
661 base.e_private = e->e_private;
662 base.e_nname = realbase;
665 if ( e != &slap_entry_root ) {
666 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
671 rs->sr_err = bdb_get_commit_csn( sop, rs, &search_context_csn,
672 locker, &ctxcsn_lock );
674 if ( rs->sr_err != LDAP_SUCCESS ) {
675 send_ldap_error( sop, rs, rs->sr_err,
676 "error in csn management in search" );
680 if ( sop->o_sync_mode != SLAP_SYNC_NONE &&
681 sop->o_sync_state.ctxcsn &&
682 sop->o_sync_state.ctxcsn->bv_val &&
683 ber_bvcmp( &sop->o_sync_state.ctxcsn[0], search_context_csn ) == 0 )
685 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
689 search_context_csn = ber_dupbv( NULL, &op->o_sync_csn );
692 /* select candidates */
693 if ( sop->oq_search.rs_scope == LDAP_SCOPE_BASE ) {
694 rs->sr_err = base_candidate( op->o_bd, &base, candidates );
697 BDB_IDL_ZERO( candidates );
698 BDB_IDL_ZERO( scopes );
699 rs->sr_err = search_candidates( op, sop, rs, &base,
700 locker, candidates, scopes );
703 if ( !IS_PSEARCH && sop->o_sync_mode != SLAP_SYNC_NONE ) {
704 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
707 /* start cursor at beginning of candidates.
711 if ( !BDB_IDL_IS_RANGE( candidates ) ) {
712 cursor = bdb_idl_search( candidates, ps_e->e_id );
713 if ( candidates[cursor] != ps_e->e_id ) {
714 rs->sr_err = LDAP_SUCCESS;
717 } else if ( ps_e->e_id < BDB_IDL_RANGE_FIRST( candidates ) ||
718 ps_e->e_id > BDB_IDL_RANGE_LAST( candidates ))
720 rs->sr_err = LDAP_SUCCESS;
724 candidates[1] = ps_e->e_id;
727 if ( candidates[0] == 0 ) {
729 LDAP_LOG ( OPERATION, RESULTS,
730 "bdb_search: no candidates\n", 0, 0, 0 );
732 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
739 /* if not root and candidates exceed to-be-checked entries, abort */
740 if ( sop->ors_limit /* isroot == TRUE */
741 && sop->ors_limit->lms_s_unchecked != -1
742 && BDB_IDL_N(candidates) > (unsigned) sop->ors_limit->lms_s_unchecked )
744 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
745 send_ldap_result( sop, rs );
746 rs->sr_err = LDAP_SUCCESS;
750 if ( sop->ors_limit == NULL /* isroot == FALSE */
751 || !sop->ors_limit->lms_s_pr_hide ) {
752 tentries = BDB_IDL_N(candidates);
755 if ( get_pagedresults(sop) ) {
756 if ( sop->o_pagedresults_state.ps_cookie == 0 ) {
759 if ( sop->o_pagedresults_size == 0 ) {
760 rs->sr_err = LDAP_SUCCESS;
761 rs->sr_text = "search abandoned by pagedResult size=0";
762 send_ldap_result( sop, rs );
765 for ( id = bdb_idl_first( candidates, &cursor );
766 id != NOID && id <= (ID)( sop->o_pagedresults_state.ps_cookie );
767 id = bdb_idl_next( candidates, &cursor ) ) /* empty */;
769 if ( cursor == NOID ) {
771 LDAP_LOG ( OPERATION, RESULTS,
772 "bdb_search: no paged results candidates\n",
775 Debug( LDAP_DEBUG_TRACE,
776 "bdb_search: no paged results candidates\n",
779 send_pagerequest_response( sop, rs, lastid, 0 );
781 rs->sr_err = LDAP_OTHER;
787 if (( sop->o_sync_mode & SLAP_SYNC_REFRESH ) || IS_PSEARCH ) {
790 cookief.f_choice = LDAP_FILTER_AND;
791 cookief.f_and = &csnfnot;
792 cookief.f_next = NULL;
794 csnfnot.f_choice = LDAP_FILTER_NOT;
795 csnfnot.f_not = &csnfeq;
796 csnfnot.f_next = &csnfand;
798 csnfeq.f_choice = LDAP_FILTER_EQUALITY;
799 csnfeq.f_ava = &aa_eq;
800 csnfeq.f_av_desc = slap_schema.si_ad_entryCSN;
801 if ( sop->o_sync_state.ctxcsn != NULL ) {
802 csnfeq.f_av_value = *sop->o_sync_state.ctxcsn;
804 csnfeq.f_av_value = slap_empty_bv;
807 csnfand.f_choice = LDAP_FILTER_AND;
808 csnfand.f_and = &csnfge;
809 csnfand.f_next = NULL;
811 csnfge.f_choice = LDAP_FILTER_GE;
812 csnfge.f_ava = &aa_ge;
813 csnfge.f_av_desc = slap_schema.si_ad_entryCSN;
814 if ( sop->o_sync_state.ctxcsn != NULL ) {
815 csnfge.f_av_value = *sop->o_sync_state.ctxcsn;
817 csnfge.f_av_value = slap_empty_bv;
820 if ( search_context_csn && !IS_PSEARCH ) {
821 csnfge.f_next = &contextcsnand;
823 contextcsnand.f_choice = LDAP_FILTER_AND;
824 contextcsnand.f_and = &contextcsnle;
825 contextcsnand.f_next = NULL;
827 contextcsnle.f_choice = LDAP_FILTER_LE;
828 contextcsnle.f_ava = &aa_le;
829 contextcsnle.f_av_desc = slap_schema.si_ad_entryCSN;
830 contextcsnle.f_av_value = *search_context_csn;
831 contextcsnle.f_next = sop->oq_search.rs_filter;
833 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
834 if ( sop->o_sync_state.ctxcsn &&
835 sop->o_sync_state.ctxcsn->bv_val != NULL )
837 value_match( &match, slap_schema.si_ad_entryCSN, mr,
838 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
839 &sop->o_sync_state.ctxcsn[0], search_context_csn,
844 no_sync_state_change = ( match >= 0 );
846 csnfge.f_next = sop->oq_search.rs_filter;
850 for ( id = bdb_idl_first( candidates, &cursor );
851 id != NOID && !no_sync_state_change;
852 id = bdb_idl_next( candidates, &cursor ) )
857 /* check for abandon */
858 if ( sop->o_abandon ) {
860 bdb_drop_psearch( sop, sop->o_msgid );
862 rs->sr_err = LDAP_SUCCESS;
866 if ( sop->o_cancel ) {
867 assert( sop->o_cancel == SLAP_CANCEL_REQ );
868 rs->sr_err = LDAP_CANCELLED;
869 send_ldap_result( sop, rs );
870 sop->o_cancel = SLAP_CANCEL_ACK;
871 rs->sr_err = LDAP_SUCCESS;
875 /* check time limit */
876 if ( sop->ors_tlimit != -1 && slap_get_time() > stoptime ) {
877 rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
878 rs->sr_ref = rs->sr_v2ref;
879 send_ldap_result( sop, rs );
880 rs->sr_err = LDAP_SUCCESS;
886 /* get the entry with reader lock */
888 rs->sr_err = bdb_cache_find_id( op, NULL,
889 id, &ei, 0, locker, &lock );
891 if (rs->sr_err == LDAP_BUSY) {
892 rs->sr_text = "ldap server busy";
893 send_ldap_result( sop, rs );
896 } else if ( rs->sr_err == DB_LOCK_DEADLOCK
897 || rs->sr_err == DB_LOCK_NOTGRANTED )
902 if ( ei && rs->sr_err == LDAP_SUCCESS ) {
909 if( !BDB_IDL_IS_RANGE(candidates) ) {
910 /* only complain for non-range IDLs */
912 LDAP_LOG ( OPERATION, RESULTS,
913 "bdb_search: candidate %ld not found\n",
916 Debug( LDAP_DEBUG_TRACE,
917 "bdb_search: candidate %ld not found\n",
930 #ifdef BDB_SUBENTRIES
931 /* FIXME: send all but syncrepl */
933 if ( !is_sync_protocol( sop ) )
936 if ( is_entry_subentry( e ) ) {
937 if( sop->oq_search.rs_scope != LDAP_SCOPE_BASE ) {
938 if(!get_subentries_visibility( sop )) {
939 /* only subentries are visible */
943 } else if ( get_subentries( sop ) &&
944 !get_subentries_visibility( sop ))
946 /* only subentries are visible */
950 } else if ( get_subentries_visibility( sop )) {
951 /* only subentries are visible */
955 #endif /* BDB_SUBENTRIES */
957 /* Does this candidate actually satisfy the search scope?
959 * Note that we don't lock access to the bei_parent pointer.
960 * Since only leaf nodes can be deleted, the parent of any
961 * node will always be a valid node. Also since we have
962 * a Read lock on the data, it cannot be renamed out of the
963 * scope while we are looking at it, and unless we're using
964 * BDB_HIER, its parents cannot be moved either.
966 switch( sop->ors_scope ) {
967 case LDAP_SCOPE_BASE:
968 /* This is always true, yes? */
969 if ( id == base.e_id ) scopeok = 1;
972 case LDAP_SCOPE_ONELEVEL:
973 if ( ei->bei_parent->bei_id == base.e_id ) scopeok = 1;
976 case LDAP_SCOPE_SUBTREE: {
978 for (tmp = BEI(e); tmp->bei_parent;
979 tmp = tmp->bei_parent ) {
980 if ( tmp->bei_id == base.e_id ) {
989 /* aliases were already dereferenced in candidate list */
990 if ( sop->ors_deref & LDAP_DEREF_SEARCHING ) {
991 /* but if the search base is an alias, and we didn't
992 * deref it when finding, return it.
994 if ( is_entry_alias(e) &&
995 ((sop->ors_deref & LDAP_DEREF_FINDING) ||
996 !bvmatch(&e->e_nname, &op->o_req_ndn)))
1001 /* scopes is only non-empty for onelevel or subtree */
1002 if ( !scopeok && BDB_IDL_N(scopes) ) {
1004 if ( sop->ors_scope == LDAP_SCOPE_ONELEVEL ) {
1005 x = bdb_idl_search( scopes,
1007 if ( scopes[x] == e->e_id )
1010 /* subtree, walk up the tree */
1011 EntryInfo *tmp = BEI(e);
1012 for (;tmp->bei_parent; tmp=tmp->bei_parent) {
1013 x = bdb_idl_search( scopes, tmp->bei_id );
1014 if ( scopes[x] == tmp->bei_id ) {
1024 /* Not in scope, ignore it */
1027 LDAP_LOG ( OPERATION, RESULTS,
1028 "bdb_search: %ld scope not okay\n",
1031 Debug( LDAP_DEBUG_TRACE,
1032 "bdb_search: %ld scope not okay\n",
1039 * if it's a referral, add it to the list of referrals. only do
1040 * this for non-base searches, and don't check the filter
1041 * explicitly here since it's only a candidate anyway.
1043 if ( !manageDSAit && sop->oq_search.rs_scope != LDAP_SCOPE_BASE
1044 && is_entry_referral( e ) )
1046 BerVarray erefs = get_entry_referrals( sop, e );
1047 rs->sr_ref = referral_rewrite( erefs,
1049 sop->oq_search.rs_scope == LDAP_SCOPE_SUBTREE
1050 ? LDAP_SCOPE_SUBTREE
1051 : LDAP_SCOPE_BASE );
1053 send_search_reference( sop, rs );
1055 ber_bvarray_free( rs->sr_ref );
1056 ber_bvarray_free( erefs );
1062 if ( !manageDSAit && is_entry_glue( e )) {
1066 /* if it matches the filter and scope, send it */
1068 if (ps_type != LDAP_PSEARCH_BY_SCOPEOUT) {
1069 rs->sr_err = test_filter( sop, rs->sr_entry, &cookief );
1071 rs->sr_err = LDAP_COMPARE_TRUE;
1074 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1075 rc_sync = test_filter( sop, rs->sr_entry, &cookief );
1076 rs->sr_err = test_filter( sop, rs->sr_entry, &contextcsnand );
1077 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1078 if ( rc_sync == LDAP_COMPARE_TRUE ) {
1079 if ( no_sync_state_change ) {
1081 LDAP_LOG ( OPERATION, RESULTS,
1082 "bdb_search: error in context csn management\n",
1085 Debug( LDAP_DEBUG_TRACE,
1086 "bdb_search: error in context csn management\n",
1090 entry_sync_state = LDAP_SYNC_ADD;
1092 if ( no_sync_state_change ) {
1095 entry_sync_state = LDAP_SYNC_PRESENT;
1099 rs->sr_err = test_filter( sop,
1100 rs->sr_entry, sop->oq_search.rs_filter );
1104 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1105 /* check size limit */
1106 if ( --sop->ors_slimit == -1 &&
1107 sop->o_sync_slog_size == -1 )
1110 bdb_cache_return_entry_r( bdb->bi_dbenv,
1111 &bdb->bi_cache, e, &lock );
1114 rs->sr_entry = NULL;
1115 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
1116 rs->sr_ref = rs->sr_v2ref;
1117 send_ldap_result( sop, rs );
1118 rs->sr_err = LDAP_SUCCESS;
1122 if ( get_pagedresults(sop) ) {
1123 if ( rs->sr_nentries >= sop->o_pagedresults_size ) {
1124 send_pagerequest_response( sop, rs,
1136 int premodify_found = 0;
1137 int entry_sync_state;
1139 if ( ps_type == LDAP_PSEARCH_BY_ADD ||
1140 ps_type == LDAP_PSEARCH_BY_DELETE ||
1141 ps_type == LDAP_PSEARCH_BY_MODIFY ||
1142 ps_type == LDAP_PSEARCH_BY_SCOPEOUT )
1144 if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1145 struct psid_entry* psid_e;
1146 LDAP_LIST_FOREACH( psid_e,
1147 &op->o_pm_list, ps_link)
1149 if( psid_e->ps_op == sop ) {
1150 premodify_found = 1;
1151 LDAP_LIST_REMOVE(psid_e, ps_link);
1155 if (psid_e != NULL) free (psid_e);
1157 if ( ps_type == LDAP_PSEARCH_BY_ADD ) {
1158 entry_sync_state = LDAP_SYNC_ADD;
1159 } else if ( ps_type == LDAP_PSEARCH_BY_DELETE ) {
1160 entry_sync_state = LDAP_SYNC_DELETE;
1161 } else if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1162 if ( premodify_found ) {
1163 entry_sync_state = LDAP_SYNC_MODIFY;
1165 entry_sync_state = LDAP_SYNC_ADD;
1167 } else if ( ps_type == LDAP_PSEARCH_BY_SCOPEOUT ) {
1168 entry_sync_state = LDAP_SYNC_DELETE;
1170 rs->sr_err = LDAP_OTHER;
1173 if ( sop->o_sync_slog_size != -1 ) {
1174 if ( entry_sync_state == LDAP_SYNC_DELETE ) {
1175 result = slap_add_session_log( op, sop, e );
1180 struct berval cookie;
1181 slap_compose_sync_cookie( sop, &cookie,
1183 sop->o_sync_state.sid,
1184 sop->o_sync_state.rid );
1185 rs->sr_err = slap_build_sync_state_ctrl( sop,
1186 rs, e, entry_sync_state, ctrls,
1187 num_ctrls++, 1, &cookie );
1188 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1189 rs->sr_attrs = attrs;
1190 rs->sr_ctrls = ctrls;
1191 result = send_search_entry( sop, rs );
1192 if ( cookie.bv_val )
1193 ch_free( cookie.bv_val );
1194 sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
1196 sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1197 ctrls[num_ctrls] = NULL;
1198 rs->sr_ctrls = NULL;
1200 } else if ( ps_type == LDAP_PSEARCH_BY_PREMODIFY ) {
1201 struct psid_entry* psid_e;
1202 psid_e = (struct psid_entry *) ch_calloc (1,
1203 sizeof(struct psid_entry));
1204 psid_e->ps_op = sop;
1205 LDAP_LIST_INSERT_HEAD( &op->o_pm_list,
1210 LDAP_LOG ( OPERATION, RESULTS,
1211 "bdb_search: invalid ps_type (%d) \n",
1214 Debug( LDAP_DEBUG_TRACE,
1215 "bdb_search: invalid ps_type (%d) \n",
1220 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1222 if ( rc_sync == LDAP_COMPARE_TRUE ) { /* ADD */
1223 rs->sr_err = slap_build_sync_state_ctrl( sop,
1224 rs, e, entry_sync_state, ctrls,
1225 num_ctrls++, 0, NULL );
1226 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1227 rs->sr_ctrls = ctrls;
1228 rs->sr_attrs = sop->oq_search.rs_attrs;
1229 result = send_search_entry( sop, rs );
1230 sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
1232 sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1233 ctrls[num_ctrls] = NULL;
1234 rs->sr_ctrls = NULL;
1235 } else { /* PRESENT */
1236 if ( sync_send_present_mode ) {
1237 result = slap_build_syncUUID_set( sop,
1239 if ( result <= 0 ) {
1243 if ( syncUUID_set_cnt == SLAP_SYNCUUID_SET_SIZE ) {
1244 rs->sr_err = LDAP_SUCCESS;
1245 rs->sr_rspoid = LDAP_SYNC_INFO;
1246 rs->sr_ctrls = NULL;
1247 result = slap_send_syncinfo( sop, rs,
1248 LDAP_TAG_SYNC_ID_SET,
1249 NULL, 0, syncUUID_set, 0 );
1250 if ( result != LDAP_SUCCESS )
1252 ber_bvarray_free_x( syncUUID_set,
1254 syncUUID_set = NULL;
1255 syncUUID_set_cnt = 0;
1263 rs->sr_attrs = sop->oq_search.rs_attrs;
1264 rs->sr_ctrls = NULL;
1265 result = send_search_entry( sop, rs );
1270 case 0: /* entry sent ok */
1272 case 1: /* entry not sent */
1274 case -1: /* connection closed */
1276 bdb_cache_return_entry_r(bdb->bi_dbenv,
1277 &bdb->bi_cache, e, &lock);
1279 rs->sr_entry = NULL;
1280 rs->sr_err = LDAP_OTHER;
1286 LDAP_LOG ( OPERATION, RESULTS,
1287 "bdb_search: %ld does not match filter\n", (long) id, 0, 0);
1289 Debug( LDAP_DEBUG_TRACE,
1290 "bdb_search: %ld does not match filter\n",
1297 /* free reader lock */
1299 bdb_cache_return_entry_r( bdb->bi_dbenv,
1300 &bdb->bi_cache, e , &lock );
1301 if ( sop->o_nocaching ) {
1302 bdb_cache_delete_entry( bdb, ei, locker, &lock );
1306 rs->sr_entry = NULL;
1309 ldap_pvt_thread_yield();
1312 if ( syncUUID_set_cnt > 0 ) {
1313 rs->sr_err = LDAP_SUCCESS;
1314 rs->sr_rspoid = LDAP_SYNC_INFO;
1315 rs->sr_ctrls = NULL;
1316 slap_send_syncinfo( sop, rs, LDAP_TAG_SYNC_ID_SET,
1317 NULL, 0, syncUUID_set, 0 );
1318 ber_bvarray_free_x( syncUUID_set, sop->o_tmpmemctx );
1319 syncUUID_set_cnt = 0;
1324 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1325 if ( sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
1326 struct berval cookie;
1327 slap_compose_sync_cookie( sop, &cookie,
1329 sop->o_sync_state.sid,
1330 sop->o_sync_state.rid );
1332 if ( sync_send_present_mode ) {
1333 rs->sr_err = LDAP_SUCCESS;
1334 rs->sr_rspoid = LDAP_SYNC_INFO;
1335 rs->sr_ctrls = NULL;
1336 slap_send_syncinfo( sop, rs,
1337 LDAP_TAG_SYNC_REFRESH_PRESENT, &cookie, 1, NULL, 0 );
1339 if ( !no_sync_state_change ) {
1341 ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
1342 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
1343 if ( ps_list->o_sync_slog_size > 0 ) {
1344 if ( ps_list->o_sync_state.sid == sop->o_sync_state.sid ) {
1352 rs->sr_err = LDAP_SUCCESS;
1353 rs->sr_rspoid = NULL;
1354 rs->sr_ctrls = NULL;
1355 slap_send_session_log( op, ps_list, rs );
1357 ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
1359 rs->sr_err = LDAP_SUCCESS;
1360 rs->sr_rspoid = LDAP_SYNC_INFO;
1361 rs->sr_ctrls = NULL;
1362 slap_send_syncinfo( sop, rs,
1363 LDAP_TAG_SYNC_REFRESH_DELETE, &cookie, 1, NULL, 0 );
1366 if ( cookie.bv_val ) {
1367 ch_free( cookie.bv_val );
1370 /* refreshOnly mode */
1371 struct berval cookie;
1372 slap_compose_sync_cookie( sop, &cookie,
1374 sop->o_sync_state.sid,
1375 sop->o_sync_state.rid );
1377 if ( sync_send_present_mode ) {
1378 slap_build_sync_done_ctrl( sop, rs, ctrls,
1379 num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_PRESENTS );
1381 if ( !no_sync_state_change ) {
1383 ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
1384 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
1386 if ( ps_list->o_sync_slog_size > 0 ) {
1387 if ( ps_list->o_sync_state.sid ==
1388 sop->o_sync_state.sid ) {
1396 slap_send_session_log( op, ps_list, rs );
1398 ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
1400 slap_build_sync_done_ctrl( sop, rs, ctrls,
1401 num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_DELETES );
1404 rs->sr_ctrls = ctrls;
1405 rs->sr_ref = rs->sr_v2ref;
1406 rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
1407 rs->sr_rspoid = NULL;
1408 send_ldap_result( sop, rs );
1409 if ( ctrls[num_ctrls-1]->ldctl_value.bv_val != NULL ) {
1410 sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val, sop->o_tmpmemctx );
1412 sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1413 ctrls[num_ctrls] = NULL;
1414 if ( cookie.bv_val )
1415 ch_free( cookie.bv_val );
1418 rs->sr_ctrls = NULL;
1419 rs->sr_ref = rs->sr_v2ref;
1420 rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
1421 rs->sr_rspoid = NULL;
1422 send_ldap_result( sop, rs );
1426 rs->sr_err = LDAP_SUCCESS;
1429 if( !IS_PSEARCH && e != NULL ) {
1430 /* free reader lock */
1431 bdb_cache_return_entry_r ( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
1434 LOCK_ID_FREE (bdb->bi_dbenv, locker );
1436 ber_bvfree( search_context_csn );
1438 if( rs->sr_v2ref ) {
1439 ber_bvarray_free( rs->sr_v2ref );
1440 rs->sr_v2ref = NULL;
1442 if( realbase.bv_val ) ch_free( realbase.bv_val );
1448 static int base_candidate(
1454 LDAP_LOG ( OPERATION, ENTRY,
1455 "base_candidate: base: \"%s\" (0x%08lx)\n",
1456 e->e_nname.bv_val, (long) e->e_id, 0);
1458 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
1459 e->e_nname.bv_val, (long) e->e_id, 0);
1467 /* Look for "objectClass Present" in this filter.
1468 * Also count depth of filter tree while we're at it.
1470 static int oc_filter(
1480 if( cur > *max ) *max = cur;
1482 switch(f->f_choice) {
1483 case LDAP_FILTER_PRESENT:
1484 if (f->f_desc == slap_schema.si_ad_objectClass) {
1489 case LDAP_FILTER_AND:
1490 case LDAP_FILTER_OR:
1492 for (f=f->f_and; f; f=f->f_next) {
1493 (void) oc_filter(f, cur, max);
1503 static void search_stack_free( void *key, void *data )
1505 ber_memfree_x(data, NULL);
1508 static void *search_stack( Operation *op )
1510 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1513 if ( op->o_threadctx ) {
1514 ldap_pvt_thread_pool_getkey( op->o_threadctx, search_stack,
1517 ret = bdb->bi_search_stack;
1521 ret = ch_malloc( bdb->bi_search_stack_depth * BDB_IDL_UM_SIZE
1523 if ( op->o_threadctx ) {
1524 ldap_pvt_thread_pool_setkey( op->o_threadctx, search_stack,
1525 ret, search_stack_free );
1527 bdb->bi_search_stack = ret;
1533 static int search_candidates(
1542 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1544 Filter f, rf, xf, nf;
1546 AttributeAssertion aa_ref;
1547 #ifdef BDB_SUBENTRIES
1549 AttributeAssertion aa_subentry;
1553 * This routine takes as input a filter (user-filter)
1554 * and rewrites it as follows:
1555 * (&(scope=DN)[(objectClass=subentry)]
1556 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
1560 LDAP_LOG ( OPERATION, ENTRY,
1561 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1562 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope);
1564 Debug(LDAP_DEBUG_TRACE,
1565 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1566 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope );
1569 xf.f_or = op->oq_search.rs_filter;
1570 xf.f_choice = LDAP_FILTER_OR;
1573 /* If the user's filter uses objectClass=*,
1574 * these clauses are redundant.
1576 if (!oc_filter(op->oq_search.rs_filter, 1, &depth)
1577 && !get_subentries_visibility(op)
1578 && !is_sync_protocol(op) )
1580 if( !get_manageDSAit(op) && !get_domainScope(op) ) {
1581 /* match referral objects */
1582 struct berval bv_ref = { sizeof("referral")-1, "referral" };
1583 rf.f_choice = LDAP_FILTER_EQUALITY;
1585 rf.f_av_desc = slap_schema.si_ad_objectClass;
1586 rf.f_av_value = bv_ref;
1587 rf.f_next = xf.f_or;
1594 f.f_choice = LDAP_FILTER_AND;
1596 /* Dummy; we compute scope separately now */
1597 nf.f_choice = SLAPD_FILTER_COMPUTED;
1598 nf.f_result = LDAP_SUCCESS;
1599 nf.f_next = xf.f_or == op->oq_search.rs_filter
1600 ? op->oq_search.rs_filter : &xf ;
1601 /* Filter depth increased again, adding dummy clause */
1604 #ifdef BDB_SUBENTRIES
1605 if( get_subentries_visibility( op ) ) {
1606 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1607 sf.f_choice = LDAP_FILTER_EQUALITY;
1608 sf.f_ava = &aa_subentry;
1609 sf.f_av_desc = slap_schema.si_ad_objectClass;
1610 sf.f_av_value = bv_subentry;
1611 sf.f_next = nf.f_next;
1616 /* Allocate IDL stack, plus 1 more for former tmp */
1617 if ( depth+1 > bdb->bi_search_stack_depth ) {
1618 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1620 stack = search_stack( stackop );
1623 if( op->ors_deref & LDAP_DEREF_SEARCHING ) {
1624 rc = search_aliases( op, rs, e, locker, ids, scopes, stack );
1626 rc = bdb_dn2idl( op, e, ids, stack );
1629 if ( rc == LDAP_SUCCESS ) {
1630 rc = bdb_filter_candidates( op, &f, ids,
1631 stack, stack+BDB_IDL_UM_SIZE );
1634 if ( depth+1 > bdb->bi_search_stack_depth ) {
1640 LDAP_LOG ( OPERATION, DETAIL1,
1641 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1643 Debug(LDAP_DEBUG_TRACE,
1644 "bdb_search_candidates: failed (rc=%d)\n",
1650 LDAP_LOG ( OPERATION, DETAIL1,
1651 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1652 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1653 (long) BDB_IDL_LAST(ids));
1655 Debug(LDAP_DEBUG_TRACE,
1656 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1658 (long) BDB_IDL_FIRST(ids),
1659 (long) BDB_IDL_LAST(ids) );
1667 send_pagerequest_response(
1673 LDAPControl ctrl, *ctrls[2];
1674 BerElementBuffer berbuf;
1675 BerElement *ber = (BerElement *)&berbuf;
1676 struct berval cookie = { 0, NULL };
1677 PagedResultsCookie respcookie;
1680 LDAP_LOG ( OPERATION, ENTRY,
1681 "send_pagerequest_response: lastid: (0x%08lx) "
1682 "nentries: (0x%081x)\n",
1683 lastid, rs->sr_nentries, NULL );
1685 Debug(LDAP_DEBUG_ARGS, "send_pagerequest_response: lastid: (0x%08lx) "
1686 "nentries: (0x%081x)\n", lastid, rs->sr_nentries, NULL );
1689 ctrl.ldctl_value.bv_val = NULL;
1693 ber_init2( ber, NULL, LBER_USE_DER );
1695 respcookie = ( PagedResultsCookie )lastid;
1696 op->o_conn->c_pagedresults_state.ps_cookie = respcookie;
1697 cookie.bv_len = sizeof( respcookie );
1698 cookie.bv_val = (char *)&respcookie;
1701 * FIXME: we should consider sending an estimate of the entries
1702 * left, after appropriate security check is done
1704 ber_printf( ber, "{iO}", tentries, &cookie );
1706 if ( ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 ) == -1 ) {
1710 ctrls[0]->ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
1711 ctrls[0]->ldctl_iscritical = 0;
1713 rs->sr_ctrls = ctrls;
1714 rs->sr_err = LDAP_SUCCESS;
1715 send_ldap_result( op, rs );
1718 (void) ber_free_buf( ber );