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 )
367 sop->o_private = op->o_private;
368 bdb_do_search( op, rs, sop, ps_e, ps_type );
369 sop->o_private = NULL;
372 /* For persistent searches, op is the currently executing operation,
373 * sop is the persistent search. For regular searches, sop = op.
376 bdb_do_search( Operation *op, SlapReply *rs, Operation *sop,
377 Entry *ps_e, int ps_type )
379 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
382 ID candidates[BDB_IDL_UM_SIZE];
383 ID scopes[BDB_IDL_DB_SIZE];
384 Entry *e = NULL, base, e_root = {0};
385 Entry *matched = NULL;
386 EntryInfo *ei, ei_root = {0};
387 struct berval realbase = BER_BVNULL;
391 AttributeName *attrs;
393 Filter contextcsnand, contextcsnle, cookief, csnfnot,
394 csnfeq, csnfand, csnfge;
395 AttributeAssertion aa_ge, aa_eq, aa_le;
396 struct berval *search_context_csn = NULL;
398 LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
400 AttributeName uuid_attr[2];
402 int entry_sync_state = -1;
403 AttributeName null_attr;
404 int no_sync_state_change = 0;
406 u_int32_t locker = 0;
410 int sync_send_present_mode = 1;
416 BerVarray syncUUID_set = NULL;
417 int syncUUID_set_cnt = 0;
419 struct bdb_op_info *opinfo = NULL;
422 LDAP_LOG( OPERATION, ENTRY, "bdb_search\n", 0, 0, 0 );
424 Debug( LDAP_DEBUG_TRACE, "=> bdb_search\n",
427 attrs = sop->oq_search.rs_attrs;
429 opinfo = (struct bdb_op_info *) op->o_private;
431 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST ) {
432 struct slap_session_entry *sent;
433 if ( sop->o_sync_state.sid >= 0 ) {
434 LDAP_LIST_FOREACH( sent, &bdb->bi_session_list, se_link ) {
435 if ( sent->se_id == sop->o_sync_state.sid ) {
436 sop->o_sync_slog_size = sent->se_size;
443 /* psearch needs to be registered before refresh begins */
444 /* psearch and refresh transmission is serialized in send_ldap_ber() */
445 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
446 ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
447 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
448 ldap_pvt_thread_rdwr_wunlock( &bdb->bi_pslist_rwlock );
450 } else if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST
451 && sop->o_sync_slog_size >= 0 )
453 ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
454 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
455 if ( ps_list->o_sync_slog_size >= 0 ) {
456 if ( ps_list->o_sync_state.sid == sop->o_sync_state.sid ) {
464 if ( ps_list->o_sync_slog_omitcsn.bv_len != 0 ) {
465 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
466 if ( sop->o_sync_state.ctxcsn &&
467 sop->o_sync_state.ctxcsn->bv_val != NULL )
469 value_match( &match, slap_schema.si_ad_entryCSN, mr,
470 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
471 sop->o_sync_state.ctxcsn,
472 &ps_list->o_sync_slog_omitcsn,
478 sync_send_present_mode = 0;
481 sync_send_present_mode = 0;
483 } else if ( sop->o_sync_slog_size >= 0 ) {
484 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
486 sop->o_sync_state.sid = -1;
488 ldap_pvt_thread_rdwr_wunlock( &bdb->bi_pslist_rwlock );
491 null_attr.an_desc = NULL;
492 null_attr.an_oc = NULL;
493 null_attr.an_oc_exclude = 0;
494 null_attr.an_name.bv_len = 0;
495 null_attr.an_name.bv_val = NULL;
497 for( num_ctrls = 0; num_ctrls < SLAP_MAX_RESPONSE_CONTROLS; num_ctrls++ ) {
498 ctrls[num_ctrls] = NULL;
502 if ( IS_PSEARCH && IS_BDB_REPLACE(ps_type)) {
504 attrs[0].an_desc = NULL;
505 attrs[0].an_oc = NULL;
506 attrs[0].an_oc_exclude = 0;
507 attrs[0].an_name.bv_len = 0;
508 attrs[0].an_name.bv_val = NULL;
511 manageDSAit = get_manageDSAit( sop );
513 /* Sync control overrides manageDSAit */
514 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
515 if ( manageDSAit == SLAP_NO_CONTROL ) {
516 manageDSAit = SLAP_CRITICAL_CONTROL;
518 } else if ( IS_PSEARCH ) {
519 if ( manageDSAit == SLAP_NO_CONTROL ) {
520 manageDSAit = SLAP_CRITICAL_CONTROL;
525 locker = TXN_ID( opinfo->boi_txn );
527 rs->sr_err = LOCK_ID( bdb->bi_dbenv, &locker );
533 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
538 if ( sop->o_req_ndn.bv_len == 0 ) {
539 /* DIT root special case */
540 ei_root.bei_e = &e_root;
541 ei_root.bei_parent = &ei_root;
542 e_root.e_private = &ei_root;
544 e_root.e_nname.bv_val="";
545 e_root.e_name.bv_val="";
547 rs->sr_err = LDAP_SUCCESS;
550 /* get entry with reader lock */
551 rs->sr_err = bdb_dn2entry( op, NULL, &sop->o_req_ndn, &ei,
563 send_ldap_error( sop, rs, LDAP_BUSY, "ldap server busy" );
565 LOCK_ID_FREE (bdb->bi_dbenv, locker );
567 case DB_LOCK_DEADLOCK:
568 case DB_LOCK_NOTGRANTED:
571 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
573 LOCK_ID_FREE (bdb->bi_dbenv, locker );
577 if ( e && (op->ors_deref & LDAP_DEREF_FINDING) && is_entry_alias(e) ) {
578 BDB_IDL_ZERO(candidates);
579 e = deref_base( op, rs, e, &matched, locker, &lock,
584 struct berval matched_dn = BER_BVNULL;
586 if ( matched != NULL ) {
588 ber_dupbv( &matched_dn, &matched->e_name );
590 erefs = is_entry_referral( matched )
591 ? get_entry_referrals( op, matched )
594 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
599 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
600 &sop->o_req_dn, sop->oq_search.rs_scope );
601 ber_bvarray_free( erefs );
605 rs->sr_ref = referral_rewrite( default_referral,
606 NULL, &sop->o_req_dn, sop->oq_search.rs_scope );
609 rs->sr_err = LDAP_REFERRAL;
610 rs->sr_matched = matched_dn.bv_val;
611 send_ldap_result( sop, rs );
614 LOCK_ID_FREE (bdb->bi_dbenv, locker );
616 ber_bvarray_free( rs->sr_ref );
619 if ( matched_dn.bv_val ) {
620 ber_memfree( matched_dn.bv_val );
621 rs->sr_matched = NULL;
626 if ( !manageDSAit && e != &e_root && is_entry_referral( e ) ) {
627 /* entry is a referral, don't allow add */
628 struct berval matched_dn;
631 ber_dupbv( &matched_dn, &e->e_name );
632 erefs = get_entry_referrals( op, e );
634 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
638 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
639 &sop->o_req_dn, sop->oq_search.rs_scope );
640 ber_bvarray_free( erefs );
644 LDAP_LOG ( OPERATION, RESULTS,
645 "bdb_search: entry is referral\n", 0, 0, 0 );
647 Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
651 if (!rs->sr_ref) rs->sr_text = "bad_referral object";
652 rs->sr_err = LDAP_REFERRAL;
653 rs->sr_matched = matched_dn.bv_val;
654 send_ldap_result( sop, rs );
657 LOCK_ID_FREE (bdb->bi_dbenv, locker );
658 ber_bvarray_free( rs->sr_ref );
660 ber_memfree( matched_dn.bv_val );
661 rs->sr_matched = NULL;
665 if ( get_assert( op ) &&
666 ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
668 rs->sr_err = LDAP_ASSERTION_FAILED;
669 send_ldap_result( sop, rs );
673 /* compute it anyway; root does not use it */
674 stoptime = op->o_time + sop->ors_tlimit;
676 /* need normalized dn below */
677 ber_dupbv( &realbase, &e->e_nname );
679 /* Copy info to base, must free entry before accessing the database
680 * in search_candidates, to avoid deadlocks.
682 base.e_private = e->e_private;
683 base.e_nname = realbase;
686 if ( e != &e_root ) {
687 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
692 rs->sr_err = bdb_get_commit_csn( sop, rs, &search_context_csn,
693 locker, &ctxcsn_lock );
695 if ( rs->sr_err != LDAP_SUCCESS ) {
696 send_ldap_error( sop, rs, rs->sr_err,
697 "error in csn management in search" );
701 if ( sop->o_sync_mode != SLAP_SYNC_NONE &&
702 sop->o_sync_state.ctxcsn &&
703 sop->o_sync_state.ctxcsn->bv_val &&
704 ber_bvcmp( &sop->o_sync_state.ctxcsn[0], search_context_csn ) == 0 )
706 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
710 search_context_csn = ber_dupbv( NULL, &op->o_sync_csn );
713 /* select candidates */
714 if ( sop->oq_search.rs_scope == LDAP_SCOPE_BASE ) {
715 rs->sr_err = base_candidate( op->o_bd, &base, candidates );
718 BDB_IDL_ZERO( candidates );
719 BDB_IDL_ZERO( scopes );
720 rs->sr_err = search_candidates( op, sop, rs, &base,
721 locker, candidates, scopes );
724 if ( !IS_PSEARCH && sop->o_sync_mode != SLAP_SYNC_NONE ) {
725 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
728 /* start cursor at beginning of candidates.
732 if ( !BDB_IDL_IS_RANGE( candidates ) ) {
733 cursor = bdb_idl_search( candidates, ps_e->e_id );
734 if ( candidates[cursor] != ps_e->e_id ) {
735 rs->sr_err = LDAP_SUCCESS;
738 } else if ( ps_e->e_id < BDB_IDL_RANGE_FIRST( candidates ) ||
739 ps_e->e_id > BDB_IDL_RANGE_LAST( candidates ))
741 rs->sr_err = LDAP_SUCCESS;
745 candidates[1] = ps_e->e_id;
748 if ( candidates[0] == 0 ) {
750 LDAP_LOG ( OPERATION, RESULTS,
751 "bdb_search: no candidates\n", 0, 0, 0 );
753 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
760 /* if not root and candidates exceed to-be-checked entries, abort */
761 if ( sop->ors_limit /* isroot == TRUE */ &&
762 sop->ors_limit->lms_s_unchecked != -1 &&
763 BDB_IDL_N(candidates) > (unsigned) sop->ors_limit->lms_s_unchecked )
765 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
766 send_ldap_result( sop, rs );
767 rs->sr_err = LDAP_SUCCESS;
771 if ( sop->ors_limit == NULL /* isroot == FALSE */ ||
772 !sop->ors_limit->lms_s_pr_hide )
774 tentries = BDB_IDL_N(candidates);
777 if ( get_pagedresults(sop) > SLAP_NO_CONTROL ) {
778 if ( (ID)( sop->o_pagedresults_state.ps_cookie ) == 0 ) {
779 id = bdb_idl_first( candidates, &cursor );
782 if ( sop->o_pagedresults_size == 0 ) {
783 rs->sr_err = LDAP_SUCCESS;
784 rs->sr_text = "search abandoned by pagedResult size=0";
785 send_ldap_result( sop, rs );
788 for ( id = bdb_idl_first( candidates, &cursor );
790 id <= (ID)( sop->o_pagedresults_state.ps_cookie );
791 id = bdb_idl_next( candidates, &cursor ) )
797 if ( cursor == NOID ) {
799 LDAP_LOG ( OPERATION, RESULTS,
800 "bdb_search: no paged results candidates\n",
803 Debug( LDAP_DEBUG_TRACE,
804 "bdb_search: no paged results candidates\n",
807 send_paged_response( sop, rs, &lastid, 0 );
809 rs->sr_err = LDAP_OTHER;
815 if (( sop->o_sync_mode & SLAP_SYNC_REFRESH ) || IS_PSEARCH ) {
818 cookief.f_choice = LDAP_FILTER_AND;
819 cookief.f_and = &csnfnot;
820 cookief.f_next = NULL;
822 csnfnot.f_choice = LDAP_FILTER_NOT;
823 csnfnot.f_not = &csnfeq;
824 csnfnot.f_next = &csnfand;
826 csnfeq.f_choice = LDAP_FILTER_EQUALITY;
827 csnfeq.f_ava = &aa_eq;
828 csnfeq.f_av_desc = slap_schema.si_ad_entryCSN;
829 if ( sop->o_sync_state.ctxcsn != NULL ) {
830 csnfeq.f_av_value = *sop->o_sync_state.ctxcsn;
832 csnfeq.f_av_value = slap_empty_bv;
835 csnfand.f_choice = LDAP_FILTER_AND;
836 csnfand.f_and = &csnfge;
837 csnfand.f_next = NULL;
839 csnfge.f_choice = LDAP_FILTER_GE;
840 csnfge.f_ava = &aa_ge;
841 csnfge.f_av_desc = slap_schema.si_ad_entryCSN;
842 if ( sop->o_sync_state.ctxcsn != NULL ) {
843 csnfge.f_av_value = *sop->o_sync_state.ctxcsn;
845 csnfge.f_av_value = slap_empty_bv;
848 if ( search_context_csn && !IS_PSEARCH ) {
849 csnfge.f_next = &contextcsnand;
851 contextcsnand.f_choice = LDAP_FILTER_AND;
852 contextcsnand.f_and = &contextcsnle;
853 contextcsnand.f_next = NULL;
855 contextcsnle.f_choice = LDAP_FILTER_LE;
856 contextcsnle.f_ava = &aa_le;
857 contextcsnle.f_av_desc = slap_schema.si_ad_entryCSN;
858 contextcsnle.f_av_value = *search_context_csn;
859 contextcsnle.f_next = sop->oq_search.rs_filter;
861 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
862 if ( sop->o_sync_state.ctxcsn &&
863 sop->o_sync_state.ctxcsn->bv_val != NULL )
865 value_match( &match, slap_schema.si_ad_entryCSN, mr,
866 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
867 &sop->o_sync_state.ctxcsn[0], search_context_csn,
872 no_sync_state_change = ( match >= 0 );
874 csnfge.f_next = sop->oq_search.rs_filter;
878 for ( id = bdb_idl_first( candidates, &cursor );
879 id != NOID && !no_sync_state_change;
880 id = bdb_idl_next( candidates, &cursor ) )
885 /* check for abandon */
886 if ( sop->o_abandon ) {
888 bdb_drop_psearch( sop, sop->o_msgid );
890 rs->sr_err = LDAP_SUCCESS;
894 if ( sop->o_cancel ) {
895 assert( sop->o_cancel == SLAP_CANCEL_REQ );
896 rs->sr_err = LDAP_CANCELLED;
897 send_ldap_result( sop, rs );
898 sop->o_cancel = SLAP_CANCEL_ACK;
899 rs->sr_err = LDAP_SUCCESS;
903 /* check time limit */
904 if ( sop->ors_tlimit != SLAP_NO_LIMIT
905 && slap_get_time() > stoptime )
907 rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
908 rs->sr_ref = rs->sr_v2ref;
909 send_ldap_result( sop, rs );
910 rs->sr_err = LDAP_SUCCESS;
916 /* get the entry with reader lock */
918 rs->sr_err = bdb_cache_find_id( op, NULL,
919 id, &ei, 0, locker, &lock );
921 if (rs->sr_err == LDAP_BUSY) {
922 rs->sr_text = "ldap server busy";
923 send_ldap_result( sop, rs );
926 } else if ( rs->sr_err == DB_LOCK_DEADLOCK
927 || rs->sr_err == DB_LOCK_NOTGRANTED )
932 if ( ei && rs->sr_err == LDAP_SUCCESS ) {
939 if( !BDB_IDL_IS_RANGE(candidates) ) {
940 /* only complain for non-range IDLs */
942 LDAP_LOG ( OPERATION, RESULTS,
943 "bdb_search: candidate %ld not found\n",
946 Debug( LDAP_DEBUG_TRACE,
947 "bdb_search: candidate %ld not found\n",
960 #ifdef BDB_SUBENTRIES
961 /* FIXME: send all but syncrepl */
963 if ( !is_sync_protocol( sop ) )
966 if ( is_entry_subentry( e ) ) {
967 if( sop->oq_search.rs_scope != LDAP_SCOPE_BASE ) {
968 if(!get_subentries_visibility( sop )) {
969 /* only subentries are visible */
973 } else if ( get_subentries( sop ) &&
974 !get_subentries_visibility( sop ))
976 /* only subentries are visible */
980 } else if ( get_subentries_visibility( sop )) {
981 /* only subentries are visible */
985 #endif /* BDB_SUBENTRIES */
987 /* Does this candidate actually satisfy the search scope?
989 * Note that we don't lock access to the bei_parent pointer.
990 * Since only leaf nodes can be deleted, the parent of any
991 * node will always be a valid node. Also since we have
992 * a Read lock on the data, it cannot be renamed out of the
993 * scope while we are looking at it, and unless we're using
994 * BDB_HIER, its parents cannot be moved either.
996 switch( sop->ors_scope ) {
997 case LDAP_SCOPE_BASE:
998 /* This is always true, yes? */
999 if ( id == base.e_id ) scopeok = 1;
1002 case LDAP_SCOPE_ONELEVEL:
1003 if ( ei->bei_parent->bei_id == base.e_id ) scopeok = 1;
1006 #ifdef LDAP_SCOPE_CHILDREN
1007 case LDAP_SCOPE_CHILDREN:
1008 if ( id == base.e_id ) break;
1011 case LDAP_SCOPE_SUBTREE: {
1013 for (tmp = BEI(e); tmp;
1014 tmp = tmp->bei_parent ) {
1015 if ( tmp->bei_id == base.e_id ) {
1024 /* aliases were already dereferenced in candidate list */
1025 if ( sop->ors_deref & LDAP_DEREF_SEARCHING ) {
1026 /* but if the search base is an alias, and we didn't
1027 * deref it when finding, return it.
1029 if ( is_entry_alias(e) &&
1030 ((sop->ors_deref & LDAP_DEREF_FINDING) ||
1031 !bvmatch(&e->e_nname, &op->o_req_ndn)))
1036 /* scopes is only non-empty for onelevel or subtree */
1037 if ( !scopeok && BDB_IDL_N(scopes) ) {
1039 if ( sop->ors_scope == LDAP_SCOPE_ONELEVEL ) {
1040 x = bdb_idl_search( scopes, e->e_id );
1041 if ( scopes[x] == e->e_id ) scopeok = 1;
1043 /* subtree, walk up the tree */
1044 EntryInfo *tmp = BEI(e);
1045 for (;tmp->bei_parent; tmp=tmp->bei_parent) {
1046 x = bdb_idl_search( scopes, tmp->bei_id );
1047 if ( scopes[x] == tmp->bei_id ) {
1057 /* Not in scope, ignore it */
1060 LDAP_LOG ( OPERATION, RESULTS,
1061 "bdb_search: %ld scope not okay\n",
1064 Debug( LDAP_DEBUG_TRACE,
1065 "bdb_search: %ld scope not okay\n",
1072 * if it's a referral, add it to the list of referrals. only do
1073 * this for non-base searches, and don't check the filter
1074 * explicitly here since it's only a candidate anyway.
1076 if ( !manageDSAit && sop->oq_search.rs_scope != LDAP_SCOPE_BASE
1077 && is_entry_referral( e ) )
1079 BerVarray erefs = get_entry_referrals( sop, e );
1080 rs->sr_ref = referral_rewrite( erefs, &e->e_name, NULL,
1081 sop->oq_search.rs_scope == LDAP_SCOPE_ONELEVEL
1082 ? LDAP_SCOPE_BASE : LDAP_SCOPE_SUBTREE );
1084 send_search_reference( sop, rs );
1086 ber_bvarray_free( rs->sr_ref );
1087 ber_bvarray_free( erefs );
1093 if ( !manageDSAit && is_entry_glue( e )) {
1097 /* if it matches the filter and scope, send it */
1099 if (ps_type != LDAP_PSEARCH_BY_SCOPEOUT) {
1100 rs->sr_err = test_filter( sop, rs->sr_entry, &cookief );
1102 rs->sr_err = LDAP_COMPARE_TRUE;
1106 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1107 rc_sync = test_filter( sop, rs->sr_entry, &cookief );
1108 rs->sr_err = test_filter( sop, rs->sr_entry, &contextcsnand );
1109 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1110 if ( rc_sync == LDAP_COMPARE_TRUE ) {
1111 if ( no_sync_state_change ) {
1113 LDAP_LOG ( OPERATION, RESULTS,
1114 "bdb_search: error in context csn management\n",
1117 Debug( LDAP_DEBUG_TRACE,
1118 "bdb_search: error in context csn management\n",
1122 entry_sync_state = LDAP_SYNC_ADD;
1125 if ( no_sync_state_change ) {
1128 entry_sync_state = LDAP_SYNC_PRESENT;
1133 rs->sr_err = test_filter( sop,
1134 rs->sr_entry, sop->oq_search.rs_filter );
1138 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1139 /* check size limit */
1140 if ( --sop->ors_slimit == -1 &&
1141 sop->o_sync_slog_size == -1 )
1144 bdb_cache_return_entry_r( bdb->bi_dbenv,
1145 &bdb->bi_cache, e, &lock );
1148 rs->sr_entry = NULL;
1149 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
1150 rs->sr_ref = rs->sr_v2ref;
1151 send_ldap_result( sop, rs );
1152 rs->sr_err = LDAP_SUCCESS;
1156 if ( get_pagedresults(sop) > SLAP_NO_CONTROL ) {
1157 if ( rs->sr_nentries >= sop->o_pagedresults_size ) {
1158 send_paged_response( sop, rs, &lastid, tentries );
1169 int premodify_found = 0;
1170 int entry_sync_state;
1172 if ( ps_type == LDAP_PSEARCH_BY_ADD ||
1173 ps_type == LDAP_PSEARCH_BY_DELETE ||
1174 ps_type == LDAP_PSEARCH_BY_MODIFY ||
1175 ps_type == LDAP_PSEARCH_BY_SCOPEOUT )
1177 if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1178 struct psid_entry* psid_e;
1179 LDAP_LIST_FOREACH( psid_e,
1180 &op->o_pm_list, ps_link)
1182 if( psid_e->ps_op == sop ) {
1183 premodify_found = 1;
1184 LDAP_LIST_REMOVE(psid_e, ps_link);
1188 if (psid_e != NULL) free (psid_e);
1191 if ( ps_type == LDAP_PSEARCH_BY_ADD ) {
1192 entry_sync_state = LDAP_SYNC_ADD;
1193 } else if ( ps_type == LDAP_PSEARCH_BY_DELETE ) {
1194 entry_sync_state = LDAP_SYNC_DELETE;
1195 } else if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1196 if ( premodify_found ) {
1197 entry_sync_state = LDAP_SYNC_MODIFY;
1199 entry_sync_state = LDAP_SYNC_ADD;
1201 } else if ( ps_type == LDAP_PSEARCH_BY_SCOPEOUT ) {
1202 entry_sync_state = LDAP_SYNC_DELETE;
1204 rs->sr_err = LDAP_OTHER;
1208 if ( sop->o_sync_slog_size != -1 ) {
1209 if ( entry_sync_state == LDAP_SYNC_DELETE ) {
1210 result = slap_add_session_log( op, sop, e );
1215 struct berval cookie;
1216 slap_compose_sync_cookie( sop, &cookie,
1218 sop->o_sync_state.sid,
1219 sop->o_sync_state.rid );
1220 rs->sr_err = slap_build_sync_state_ctrl( sop,
1221 rs, e, entry_sync_state, ctrls,
1222 num_ctrls++, 1, &cookie );
1223 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1224 rs->sr_attrs = attrs;
1225 rs->sr_ctrls = ctrls;
1227 result = send_search_entry( sop, rs );
1228 if ( cookie.bv_val ) ch_free( cookie.bv_val );
1230 ctrls[num_ctrls-1]->ldctl_value.bv_val,
1232 slap_sl_free( ctrls[--num_ctrls],
1234 ctrls[num_ctrls] = NULL;
1235 rs->sr_ctrls = NULL;
1238 } else if ( ps_type == LDAP_PSEARCH_BY_PREMODIFY ) {
1239 struct psid_entry* psid_e;
1240 psid_e = (struct psid_entry *) ch_calloc(1,
1241 sizeof(struct psid_entry));
1242 psid_e->ps_op = sop;
1243 LDAP_LIST_INSERT_HEAD( &op->o_pm_list,
1248 LDAP_LOG ( OPERATION, RESULTS,
1249 "bdb_search: invalid ps_type (%d) \n",
1252 Debug( LDAP_DEBUG_TRACE,
1253 "bdb_search: invalid ps_type (%d) \n",
1259 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1260 if ( rc_sync == LDAP_COMPARE_TRUE ) { /* ADD */
1261 rs->sr_err = slap_build_sync_state_ctrl( sop,
1262 rs, e, entry_sync_state, ctrls,
1263 num_ctrls++, 0, NULL );
1264 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1265 rs->sr_ctrls = ctrls;
1266 rs->sr_attrs = sop->oq_search.rs_attrs;
1268 result = send_search_entry( sop, rs );
1270 ctrls[num_ctrls-1]->ldctl_value.bv_val,
1272 slap_sl_free( ctrls[--num_ctrls],
1274 ctrls[num_ctrls] = NULL;
1275 rs->sr_ctrls = NULL;
1277 } else { /* PRESENT */
1278 if ( sync_send_present_mode ) {
1279 result = slap_build_syncUUID_set( sop,
1281 if ( result <= 0 ) {
1285 if ( syncUUID_set_cnt ==
1286 SLAP_SYNCUUID_SET_SIZE )
1288 rs->sr_err = LDAP_SUCCESS;
1289 rs->sr_rspoid = LDAP_SYNC_INFO;
1290 rs->sr_ctrls = NULL;
1291 result = slap_send_syncinfo( sop, rs,
1292 LDAP_TAG_SYNC_ID_SET,
1293 NULL, 0, syncUUID_set, 0 );
1294 if ( result != LDAP_SUCCESS ) {
1297 ber_bvarray_free_x( syncUUID_set,
1299 syncUUID_set = NULL;
1300 syncUUID_set_cnt = 0;
1310 rs->sr_attrs = sop->oq_search.rs_attrs;
1311 rs->sr_ctrls = NULL;
1313 rs->sr_err = LDAP_SUCCESS;
1314 result = send_search_entry( sop, rs );
1319 case 0: /* entry sent ok */
1321 case 1: /* entry not sent */
1323 case -1: /* connection closed */
1325 bdb_cache_return_entry_r(bdb->bi_dbenv,
1326 &bdb->bi_cache, e, &lock);
1329 rs->sr_entry = NULL;
1330 rs->sr_err = LDAP_OTHER;
1337 LDAP_LOG ( OPERATION, RESULTS,
1338 "bdb_search: %ld does not match filter\n", (long) id, 0, 0);
1340 Debug( LDAP_DEBUG_TRACE,
1341 "bdb_search: %ld does not match filter\n",
1348 /* free reader lock */
1350 bdb_cache_return_entry_r( bdb->bi_dbenv,
1351 &bdb->bi_cache, e , &lock );
1352 if ( sop->o_nocaching ) {
1353 bdb_cache_delete_entry( bdb, ei, locker, &lock );
1357 rs->sr_entry = NULL;
1360 ldap_pvt_thread_yield();
1363 if ( syncUUID_set_cnt > 0 ) {
1364 rs->sr_err = LDAP_SUCCESS;
1365 rs->sr_rspoid = LDAP_SYNC_INFO;
1366 rs->sr_ctrls = NULL;
1367 slap_send_syncinfo( sop, rs, LDAP_TAG_SYNC_ID_SET,
1368 NULL, 0, syncUUID_set, 0 );
1369 ber_bvarray_free_x( syncUUID_set, sop->o_tmpmemctx );
1370 syncUUID_set_cnt = 0;
1375 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1376 if ( sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
1377 struct berval cookie;
1378 slap_compose_sync_cookie( sop, &cookie, search_context_csn,
1379 sop->o_sync_state.sid, sop->o_sync_state.rid );
1381 if ( sync_send_present_mode ) {
1382 rs->sr_err = LDAP_SUCCESS;
1383 rs->sr_rspoid = LDAP_SYNC_INFO;
1384 rs->sr_ctrls = NULL;
1385 slap_send_syncinfo( sop, rs,
1386 LDAP_TAG_SYNC_REFRESH_PRESENT, &cookie, 1, NULL, 0 );
1389 if ( !no_sync_state_change ) {
1391 ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
1392 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
1395 if ( ps_list->o_sync_slog_size > 0 ) {
1396 if ( ps_list->o_sync_state.sid ==
1397 sop->o_sync_state.sid )
1406 rs->sr_err = LDAP_SUCCESS;
1407 rs->sr_rspoid = NULL;
1408 rs->sr_ctrls = NULL;
1409 slap_send_session_log( op, ps_list, rs );
1411 ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
1414 rs->sr_err = LDAP_SUCCESS;
1415 rs->sr_rspoid = LDAP_SYNC_INFO;
1416 rs->sr_ctrls = NULL;
1417 slap_send_syncinfo( sop, rs,
1418 LDAP_TAG_SYNC_REFRESH_DELETE, &cookie, 1, NULL, 0 );
1421 if ( cookie.bv_val ) ch_free( cookie.bv_val );
1424 /* refreshOnly mode */
1425 struct berval cookie;
1426 slap_compose_sync_cookie( sop, &cookie, search_context_csn,
1427 sop->o_sync_state.sid, sop->o_sync_state.rid );
1429 if ( sync_send_present_mode ) {
1430 slap_build_sync_done_ctrl( sop, rs, ctrls,
1431 num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_PRESENTS );
1434 if ( !no_sync_state_change ) {
1436 ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
1437 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
1440 if ( ps_list->o_sync_slog_size > 0 ) {
1441 if ( ps_list->o_sync_state.sid ==
1442 sop->o_sync_state.sid ) {
1450 slap_send_session_log( op, ps_list, rs );
1452 ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
1455 slap_build_sync_done_ctrl( sop, rs, ctrls,
1456 num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_DELETES );
1459 rs->sr_ctrls = ctrls;
1460 rs->sr_ref = rs->sr_v2ref;
1461 rs->sr_err = (rs->sr_v2ref == NULL)
1462 ? LDAP_SUCCESS : LDAP_REFERRAL;
1463 rs->sr_rspoid = NULL;
1464 send_ldap_result( sop, rs );
1465 if ( ctrls[num_ctrls-1]->ldctl_value.bv_val != NULL ) {
1466 slap_sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
1469 slap_sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1470 ctrls[num_ctrls] = NULL;
1471 if ( cookie.bv_val ) ch_free( cookie.bv_val );
1475 rs->sr_ctrls = NULL;
1476 rs->sr_ref = rs->sr_v2ref;
1477 rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
1478 rs->sr_rspoid = NULL;
1479 if ( get_pagedresults(sop) > SLAP_NO_CONTROL ) {
1480 send_paged_response( sop, rs, NULL, 0 );
1482 send_ldap_result( sop, rs );
1487 rs->sr_err = LDAP_SUCCESS;
1490 if( !IS_PSEARCH && e != NULL ) {
1491 /* free reader lock */
1492 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
1496 LOCK_ID_FREE( bdb->bi_dbenv, locker );
1498 ber_bvfree( search_context_csn );
1500 if( rs->sr_v2ref ) {
1501 ber_bvarray_free( rs->sr_v2ref );
1502 rs->sr_v2ref = NULL;
1504 if( realbase.bv_val ) ch_free( realbase.bv_val );
1510 static int base_candidate(
1516 LDAP_LOG ( OPERATION, ENTRY,
1517 "base_candidate: base: \"%s\" (0x%08lx)\n",
1518 e->e_nname.bv_val, (long) e->e_id, 0);
1520 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
1521 e->e_nname.bv_val, (long) e->e_id, 0);
1529 /* Look for "objectClass Present" in this filter.
1530 * Also count depth of filter tree while we're at it.
1532 static int oc_filter(
1541 if( cur > *max ) *max = cur;
1543 switch( f->f_choice ) {
1544 case LDAP_FILTER_PRESENT:
1545 if (f->f_desc == slap_schema.si_ad_objectClass) {
1550 case LDAP_FILTER_AND:
1551 case LDAP_FILTER_OR:
1553 for ( f=f->f_and; f; f=f->f_next ) {
1554 (void) oc_filter(f, cur, max);
1564 static void search_stack_free( void *key, void *data )
1566 ber_memfree_x(data, NULL);
1569 static void *search_stack( Operation *op )
1571 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1574 if ( op->o_threadctx ) {
1575 ldap_pvt_thread_pool_getkey( op->o_threadctx, search_stack,
1578 ret = bdb->bi_search_stack;
1582 ret = ch_malloc( bdb->bi_search_stack_depth * BDB_IDL_UM_SIZE
1584 if ( op->o_threadctx ) {
1585 ldap_pvt_thread_pool_setkey( op->o_threadctx, search_stack,
1586 ret, search_stack_free );
1588 bdb->bi_search_stack = ret;
1594 static int search_candidates(
1603 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1605 Filter f, rf, xf, nf;
1607 AttributeAssertion aa_ref;
1608 #ifdef BDB_SUBENTRIES
1610 AttributeAssertion aa_subentry;
1614 * This routine takes as input a filter (user-filter)
1615 * and rewrites it as follows:
1616 * (&(scope=DN)[(objectClass=subentry)]
1617 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
1621 LDAP_LOG ( OPERATION, ENTRY,
1622 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1623 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope);
1625 Debug(LDAP_DEBUG_TRACE,
1626 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1627 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope );
1630 xf.f_or = op->oq_search.rs_filter;
1631 xf.f_choice = LDAP_FILTER_OR;
1634 /* If the user's filter uses objectClass=*,
1635 * these clauses are redundant.
1637 if (!oc_filter(op->oq_search.rs_filter, 1, &depth)
1638 && !get_subentries_visibility(op)
1639 && !is_sync_protocol(op) )
1641 if( !get_manageDSAit(op) && !get_domainScope(op) ) {
1642 /* match referral objects */
1643 struct berval bv_ref = { sizeof("referral")-1, "referral" };
1644 rf.f_choice = LDAP_FILTER_EQUALITY;
1646 rf.f_av_desc = slap_schema.si_ad_objectClass;
1647 rf.f_av_value = bv_ref;
1648 rf.f_next = xf.f_or;
1655 f.f_choice = LDAP_FILTER_AND;
1657 /* Dummy; we compute scope separately now */
1658 nf.f_choice = SLAPD_FILTER_COMPUTED;
1659 nf.f_result = LDAP_SUCCESS;
1660 nf.f_next = ( xf.f_or == op->oq_search.rs_filter )
1661 ? op->oq_search.rs_filter : &xf ;
1662 /* Filter depth increased again, adding dummy clause */
1665 #ifdef BDB_SUBENTRIES
1666 if( get_subentries_visibility( op ) ) {
1667 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1668 sf.f_choice = LDAP_FILTER_EQUALITY;
1669 sf.f_ava = &aa_subentry;
1670 sf.f_av_desc = slap_schema.si_ad_objectClass;
1671 sf.f_av_value = bv_subentry;
1672 sf.f_next = nf.f_next;
1677 /* Allocate IDL stack, plus 1 more for former tmp */
1678 if ( depth+1 > bdb->bi_search_stack_depth ) {
1679 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1681 stack = search_stack( stackop );
1684 if( op->ors_deref & LDAP_DEREF_SEARCHING ) {
1685 rc = search_aliases( op, rs, e, locker, ids, scopes, stack );
1687 rc = bdb_dn2idl( op, e, ids, stack );
1690 if ( rc == LDAP_SUCCESS ) {
1691 rc = bdb_filter_candidates( op, &f, ids,
1692 stack, stack+BDB_IDL_UM_SIZE );
1695 if ( depth+1 > bdb->bi_search_stack_depth ) {
1701 LDAP_LOG ( OPERATION, DETAIL1,
1702 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1704 Debug(LDAP_DEBUG_TRACE,
1705 "bdb_search_candidates: failed (rc=%d)\n",
1711 LDAP_LOG ( OPERATION, DETAIL1,
1712 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1713 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1714 (long) BDB_IDL_LAST(ids));
1716 Debug(LDAP_DEBUG_TRACE,
1717 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1719 (long) BDB_IDL_FIRST(ids),
1720 (long) BDB_IDL_LAST(ids) );
1728 send_paged_response(
1734 LDAPControl ctrl, *ctrls[2];
1735 BerElementBuffer berbuf;
1736 BerElement *ber = (BerElement *)&berbuf;
1737 PagedResultsCookie respcookie;
1738 struct berval cookie;
1741 LDAP_LOG ( OPERATION, ENTRY,
1742 "send_paged_response: lastid=0x%08lx nentries=%d\n",
1743 lastid ? *lastid : 0, rs->sr_nentries, NULL );
1745 Debug(LDAP_DEBUG_ARGS,
1746 "send_paged_response: lastid=0x%08lx nentries=%d\n",
1747 lastid ? *lastid : 0, rs->sr_nentries, NULL );
1750 ctrl.ldctl_value.bv_val = NULL;
1754 ber_init2( ber, NULL, LBER_USE_DER );
1757 respcookie = ( PagedResultsCookie )(*lastid);
1758 cookie.bv_len = sizeof( respcookie );
1759 cookie.bv_val = (char *)&respcookie;
1762 respcookie = ( PagedResultsCookie )0;
1767 op->o_conn->c_pagedresults_state.ps_cookie = respcookie;
1768 op->o_conn->c_pagedresults_state.ps_count =
1769 op->o_pagedresults_state.ps_count + rs->sr_nentries;
1771 /* return size of 0 -- no estimate */
1772 ber_printf( ber, "{iO}", 0, &cookie );
1774 if ( ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 ) == -1 ) {
1778 ctrls[0]->ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
1779 ctrls[0]->ldctl_iscritical = 0;
1781 rs->sr_ctrls = ctrls;
1782 rs->sr_err = LDAP_SUCCESS;
1783 send_ldap_result( op, rs );
1784 rs->sr_ctrls = NULL;
1787 (void) ber_free_buf( ber );