1 /* search.c - search operation */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2003 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, csnfeq, csnfand, csnfge;
390 AttributeAssertion aa_ge, aa_eq, aa_le;
392 struct berval *search_context_csn = NULL;
394 LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
396 AttributeName uuid_attr[2];
398 int entry_sync_state = -1;
399 AttributeName null_attr;
400 int no_sync_state_change = 0;
401 struct slap_limits_set *limit = NULL;
404 u_int32_t locker = 0;
408 int sync_send_present_mode = 1;
414 BerVarray syncUUID_set = NULL;
415 int syncUUID_set_cnt = 0;
418 LDAP_LOG( OPERATION, ENTRY, "bdb_search\n", 0, 0, 0 );
420 Debug( LDAP_DEBUG_TRACE, "=> bdb_search\n",
423 attrs = sop->oq_search.rs_attrs;
425 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST ) {
426 struct slap_session_entry *sent;
427 if ( sop->o_sync_state.sid >= 0 ) {
428 LDAP_LIST_FOREACH( sent, &bdb->bi_session_list, se_link ) {
429 if ( sent->se_id == sop->o_sync_state.sid ) {
430 sop->o_sync_slog_size = sent->se_size;
437 /* psearch needs to be registered before refresh begins */
438 /* psearch and refresh transmission is serialized in send_ldap_ber() */
439 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
440 ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
441 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
442 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 ) {
445 ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
446 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
447 if ( ps_list->o_sync_slog_size >= 0 ) {
448 if ( ps_list->o_sync_state.sid == sop->o_sync_state.sid ) {
456 if ( ps_list->o_sync_slog_omitcsn.bv_len != 0 ) {
457 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
458 if ( sop->o_sync_state.ctxcsn &&
459 sop->o_sync_state.ctxcsn->bv_val != NULL ) {
460 value_match( &match, slap_schema.si_ad_entryCSN, mr,
461 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
462 sop->o_sync_state.ctxcsn,
463 &ps_list->o_sync_slog_omitcsn,
469 sync_send_present_mode = 0;
472 sync_send_present_mode = 0;
474 } else if ( sop->o_sync_slog_size >= 0 ) {
475 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
477 sop->o_sync_state.sid = -1;
479 ldap_pvt_thread_rdwr_wunlock( &bdb->bi_pslist_rwlock );
482 null_attr.an_desc = NULL;
483 null_attr.an_oc = NULL;
484 null_attr.an_name.bv_len = 0;
485 null_attr.an_name.bv_val = NULL;
487 for( num_ctrls = 0; num_ctrls < SLAP_MAX_RESPONSE_CONTROLS; num_ctrls++ ) {
488 ctrls[num_ctrls] = NULL;
492 if ( IS_PSEARCH && IS_BDB_REPLACE(ps_type)) {
494 attrs[0].an_desc = NULL;
495 attrs[0].an_oc = NULL;
496 attrs[0].an_name.bv_len = 0;
497 attrs[0].an_name.bv_val = NULL;
500 manageDSAit = get_manageDSAit( sop );
502 /* Sync control overrides manageDSAit */
504 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
505 if ( manageDSAit == SLAP_NO_CONTROL )
506 manageDSAit = SLAP_CRITICAL_CONTROL;
507 } else if ( IS_PSEARCH ) {
508 if ( manageDSAit == SLAP_NO_CONTROL )
509 manageDSAit = SLAP_CRITICAL_CONTROL;
512 rs->sr_err = LOCK_ID (bdb->bi_dbenv, &locker );
518 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
522 if ( sop->o_req_ndn.bv_len == 0 ) {
523 /* DIT root special case */
524 e = (Entry *) &slap_entry_root;
525 rs->sr_err = LDAP_SUCCESS;
528 /* get entry with reader lock */
529 rs->sr_err = bdb_dn2entry( op, NULL, &sop->o_req_ndn, &ei,
535 matched = ei->bei_e; break;
537 e = ei->bei_e; break;
539 send_ldap_error( sop, rs, LDAP_BUSY, "ldap server busy" );
540 LOCK_ID_FREE (bdb->bi_dbenv, locker );
542 case DB_LOCK_DEADLOCK:
543 case DB_LOCK_NOTGRANTED:
546 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
547 LOCK_ID_FREE (bdb->bi_dbenv, locker );
551 if ( e && (op->ors_deref & LDAP_DEREF_FINDING) && is_entry_alias(e) ) {
552 BDB_IDL_ZERO(candidates);
553 e = deref_base( op, rs, e, &matched, locker, &lock,
558 struct berval matched_dn = { 0, NULL };
560 if ( matched != NULL ) {
562 ber_dupbv( &matched_dn, &matched->e_name );
564 erefs = is_entry_referral( matched )
565 ? get_entry_referrals( op, matched )
568 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
573 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
574 &sop->o_req_dn, sop->oq_search.rs_scope );
575 ber_bvarray_free( erefs );
579 rs->sr_ref = referral_rewrite( default_referral,
580 NULL, &sop->o_req_dn, sop->oq_search.rs_scope );
583 rs->sr_err = LDAP_REFERRAL;
584 rs->sr_matched = matched_dn.bv_val;
585 send_ldap_result( sop, rs );
587 LOCK_ID_FREE (bdb->bi_dbenv, locker );
589 ber_bvarray_free( rs->sr_ref );
592 if ( matched_dn.bv_val ) {
593 ber_memfree( matched_dn.bv_val );
594 rs->sr_matched = NULL;
599 if (!manageDSAit && e != &slap_entry_root && is_entry_referral( e ) ) {
600 /* entry is a referral, don't allow add */
601 struct berval matched_dn;
604 ber_dupbv( &matched_dn, &e->e_name );
605 erefs = get_entry_referrals( op, e );
607 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
611 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
612 &sop->o_req_dn, sop->oq_search.rs_scope );
613 ber_bvarray_free( erefs );
617 LDAP_LOG ( OPERATION, RESULTS,
618 "bdb_search: entry is referral\n", 0, 0, 0 );
620 Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
624 if (!rs->sr_ref) rs->sr_text = "bad_referral object";
625 rs->sr_err = LDAP_REFERRAL;
626 rs->sr_matched = matched_dn.bv_val;
627 send_ldap_result( sop, rs );
629 LOCK_ID_FREE (bdb->bi_dbenv, locker );
630 ber_bvarray_free( rs->sr_ref );
632 ber_memfree( matched_dn.bv_val );
633 rs->sr_matched = NULL;
637 if ( get_assert( op ) &&
638 ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
640 rs->sr_err = LDAP_ASSERTION_FAILED;
641 send_ldap_result( sop, rs );
645 /* if not root, get appropriate limits */
646 if ( be_isroot( op->o_bd, &sop->o_ndn ) ) {
649 ( void ) get_limits( op->o_bd, &sop->o_ndn, &limit );
652 /* The time/size limits come first because they require very little
653 * effort, so there's no chance the candidates are selected and then
654 * the request is not honored only because of time/size constraints */
656 /* if no time limit requested, use soft limit (unless root!) */
658 if ( sop->oq_search.rs_tlimit == 0 ) {
659 sop->oq_search.rs_tlimit = -1; /* allow root to set no limit */
662 if ( sop->oq_search.rs_slimit == 0 ) {
663 sop->oq_search.rs_slimit = -1;
667 /* if no limit is required, use soft limit */
668 if ( sop->oq_search.rs_tlimit <= 0 ) {
669 sop->oq_search.rs_tlimit = limit->lms_t_soft;
671 /* if requested limit higher than hard limit, abort */
672 } else if ( sop->oq_search.rs_tlimit > limit->lms_t_hard ) {
673 /* no hard limit means use soft instead */
674 if ( limit->lms_t_hard == 0
675 && limit->lms_t_soft > -1
676 && sop->oq_search.rs_tlimit > limit->lms_t_soft ) {
677 sop->oq_search.rs_tlimit = limit->lms_t_soft;
679 /* positive hard limit means abort */
680 } else if ( limit->lms_t_hard > 0 ) {
681 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
682 send_ldap_result( sop, rs );
683 rs->sr_err = LDAP_SUCCESS;
687 /* negative hard limit means no limit */
690 /* if no limit is required, use soft limit */
691 if ( sop->oq_search.rs_slimit <= 0 ) {
692 if ( get_pagedresults(sop) && limit->lms_s_pr != 0 ) {
693 sop->oq_search.rs_slimit = limit->lms_s_pr;
695 sop->oq_search.rs_slimit = limit->lms_s_soft;
698 /* if requested limit higher than hard limit, abort */
699 } else if ( sop->oq_search.rs_slimit > limit->lms_s_hard ) {
700 /* no hard limit means use soft instead */
701 if ( limit->lms_s_hard == 0
702 && limit->lms_s_soft > -1
703 && sop->oq_search.rs_slimit > limit->lms_s_soft ) {
704 sop->oq_search.rs_slimit = limit->lms_s_soft;
706 /* positive hard limit means abort */
707 } else if ( limit->lms_s_hard > 0 ) {
708 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
709 send_ldap_result( sop, rs );
710 rs->sr_err = LDAP_SUCCESS;
714 /* negative hard limit means no limit */
718 /* compute it anyway; root does not use it */
719 stoptime = op->o_time + sop->oq_search.rs_tlimit;
721 /* need normalized dn below */
722 ber_dupbv( &realbase, &e->e_nname );
724 /* Copy info to base, must free entry before accessing the database
725 * in search_candidates, to avoid deadlocks.
727 base.e_private = e->e_private;
728 base.e_nname = realbase;
731 if ( e != &slap_entry_root ) {
732 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
737 rs->sr_err = bdb_get_commit_csn( sop, rs, &search_context_csn, locker, &ctxcsn_lock );
739 if ( rs->sr_err != LDAP_SUCCESS ) {
740 send_ldap_error( sop, rs, rs->sr_err, "error in csn management in search" );
744 if ( sop->o_sync_mode != SLAP_SYNC_NONE && sop->o_sync_state.ctxcsn &&
745 sop->o_sync_state.ctxcsn->bv_val &&
746 ber_bvcmp( &sop->o_sync_state.ctxcsn[0], search_context_csn ) == 0 )
748 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
752 search_context_csn = ber_dupbv( NULL, &op->o_sync_csn );
755 /* select candidates */
756 if ( sop->oq_search.rs_scope == LDAP_SCOPE_BASE ) {
757 rs->sr_err = base_candidate( op->o_bd, &base, candidates );
760 BDB_IDL_ZERO( candidates );
761 BDB_IDL_ZERO( scopes );
762 rs->sr_err = search_candidates( op, sop, rs, &base, locker, candidates, scopes );
766 if ( sop->o_sync_mode != SLAP_SYNC_NONE ) {
767 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
771 /* start cursor at beginning of candidates.
775 if ( !BDB_IDL_IS_RANGE( candidates ) ) {
776 cursor = bdb_idl_search( candidates, ps_e->e_id );
777 if ( candidates[cursor] != ps_e->e_id ) {
778 rs->sr_err = LDAP_SUCCESS;
782 if ( ps_e->e_id < BDB_IDL_RANGE_FIRST(candidates)
783 || ps_e->e_id > BDB_IDL_RANGE_LAST(candidates)){
784 rs->sr_err = LDAP_SUCCESS;
789 candidates[1] = ps_e->e_id;
792 if ( candidates[0] == 0 ) {
794 LDAP_LOG ( OPERATION, RESULTS,
795 "bdb_search: no candidates\n", 0, 0, 0 );
797 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
801 rs->sr_err = LDAP_SUCCESS;
803 send_ldap_result( sop, rs );
807 /* if not root and candidates exceed to-be-checked entries, abort */
808 if ( !isroot && limit->lms_s_unchecked != -1 ) {
809 if ( BDB_IDL_N(candidates) > (unsigned) limit->lms_s_unchecked ) {
810 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
811 send_ldap_result( sop, rs );
812 rs->sr_err = LDAP_SUCCESS;
817 if ( isroot || !limit->lms_s_pr_hide ) {
818 tentries = BDB_IDL_N(candidates);
821 if ( get_pagedresults(sop) ) {
822 if ( sop->o_pagedresults_state.ps_cookie == 0 ) {
825 if ( sop->o_pagedresults_size == 0 ) {
826 rs->sr_err = LDAP_SUCCESS;
827 rs->sr_text = "search abandoned by pagedResult size=0";
828 send_ldap_result( sop, rs );
831 for ( id = bdb_idl_first( candidates, &cursor );
832 id != NOID && id <= (ID)( sop->o_pagedresults_state.ps_cookie );
833 id = bdb_idl_next( candidates, &cursor ) );
835 if ( cursor == NOID ) {
837 LDAP_LOG ( OPERATION, RESULTS,
838 "bdb_search: no paged results candidates\n",
841 Debug( LDAP_DEBUG_TRACE,
842 "bdb_search: no paged results candidates\n",
845 send_pagerequest_response( sop, rs, lastid, 0 );
847 rs->sr_err = LDAP_OTHER;
853 if ( (sop->o_sync_mode & SLAP_SYNC_REFRESH) || IS_PSEARCH )
857 cookief.f_choice = LDAP_FILTER_AND;
858 cookief.f_and = &csnfnot;
859 cookief.f_next = NULL;
861 csnfnot.f_choice = LDAP_FILTER_NOT;
862 csnfnot.f_not = &csnfeq;
863 csnfnot.f_next = &csnfand;
865 csnfeq.f_choice = LDAP_FILTER_EQUALITY;
866 csnfeq.f_ava = &aa_eq;
867 csnfeq.f_av_desc = slap_schema.si_ad_entryCSN;
868 if ( sop->o_sync_state.ctxcsn != NULL ) {
869 csnfeq.f_av_value = *sop->o_sync_state.ctxcsn;
871 csnfeq.f_av_value = slap_empty_bv;
874 csnfand.f_choice = LDAP_FILTER_AND;
875 csnfand.f_and = &csnfge;
876 csnfand.f_next = NULL;
878 csnfge.f_choice = LDAP_FILTER_GE;
879 csnfge.f_ava = &aa_ge;
880 csnfge.f_av_desc = slap_schema.si_ad_entryCSN;
881 if ( sop->o_sync_state.ctxcsn != NULL ) {
882 csnfge.f_av_value = *sop->o_sync_state.ctxcsn;
884 csnfge.f_av_value = slap_empty_bv;
887 if ( search_context_csn && !IS_PSEARCH ) {
888 csnfge.f_next = &contextcsnand;
890 contextcsnand.f_choice = LDAP_FILTER_AND;
891 contextcsnand.f_and = &contextcsnle;
892 contextcsnand.f_next = NULL;
894 contextcsnle.f_choice = LDAP_FILTER_LE;
895 contextcsnle.f_ava = &aa_le;
896 contextcsnle.f_av_desc = slap_schema.si_ad_entryCSN;
897 contextcsnle.f_av_value = *search_context_csn;
898 contextcsnle.f_next = sop->oq_search.rs_filter;
900 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
901 if ( sop->o_sync_state.ctxcsn &&
902 sop->o_sync_state.ctxcsn->bv_val != NULL ) {
903 value_match( &match, slap_schema.si_ad_entryCSN, mr,
904 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
905 &sop->o_sync_state.ctxcsn[0], search_context_csn,
910 no_sync_state_change = ( match >= 0 );
912 csnfge.f_next = sop->oq_search.rs_filter;
916 for ( id = bdb_idl_first( candidates, &cursor );
917 id != NOID && !no_sync_state_change;
918 id = bdb_idl_next( candidates, &cursor ) )
923 /* check for abandon */
924 if ( sop->o_abandon ) {
926 bdb_drop_psearch( sop, sop->o_msgid );
928 rs->sr_err = LDAP_SUCCESS;
932 #ifdef LDAP_EXOP_X_CANCEL
933 if ( sop->o_cancel ) {
934 assert( sop->o_cancel == SLAP_CANCEL_REQ );
935 rs->sr_err = LDAP_CANCELLED;
936 send_ldap_result( sop, rs );
937 sop->o_cancel = SLAP_CANCEL_ACK;
938 rs->sr_err = LDAP_SUCCESS;
943 /* check time limit */
944 if ( sop->oq_search.rs_tlimit != -1 && slap_get_time() > stoptime ) {
945 rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
946 rs->sr_ref = rs->sr_v2ref;
947 send_ldap_result( sop, rs );
948 rs->sr_err = LDAP_SUCCESS;
955 /* get the entry with reader lock */
957 rs->sr_err = bdb_cache_find_id( op, NULL,
958 id, &ei, 0, locker, &lock );
960 if (rs->sr_err == LDAP_BUSY) {
961 rs->sr_text = "ldap server busy";
962 send_ldap_result( sop, rs );
965 } else if ( rs->sr_err == DB_LOCK_DEADLOCK
966 || rs->sr_err == DB_LOCK_NOTGRANTED )
971 if ( ei && rs->sr_err == LDAP_SUCCESS ) {
978 if( !BDB_IDL_IS_RANGE(candidates) ) {
979 /* only complain for non-range IDLs */
981 LDAP_LOG ( OPERATION, RESULTS,
982 "bdb_search: candidate %ld not found\n",
985 Debug( LDAP_DEBUG_TRACE,
986 "bdb_search: candidate %ld not found\n",
998 #ifdef BDB_SUBENTRIES
999 /* FIXME: send all but syncrepl
1000 if ( !is_sync_protocol( sop ) ) {
1002 if ( is_entry_subentry( e ) ) {
1003 if( sop->oq_search.rs_scope != LDAP_SCOPE_BASE ) {
1004 if(!get_subentries_visibility( sop )) {
1005 /* only subentries are visible */
1009 } else if ( get_subentries( sop ) &&
1010 !get_subentries_visibility( sop ))
1012 /* only subentries are visible */
1016 } else if ( get_subentries_visibility( sop )) {
1017 /* only subentries are visible */
1025 /* Does this candidate actually satisfy the search scope?
1027 * Note that we don't lock access to the bei_parent pointer.
1028 * Since only leaf nodes can be deleted, the parent of any
1029 * node will always be a valid node. Also since we have
1030 * a Read lock on the data, it cannot be renamed out of the
1031 * scope while we are looking at it, and unless we're using
1032 * BDB_HIER, its parents cannot be moved either.
1034 switch( sop->ors_scope ) {
1035 case LDAP_SCOPE_BASE:
1036 /* This is always true, yes? */
1037 if ( id == base.e_id )
1040 case LDAP_SCOPE_ONELEVEL:
1041 if ( ei->bei_parent->bei_id == base.e_id )
1044 case LDAP_SCOPE_SUBTREE:
1046 for ( tmp = BEI(e); tmp->bei_parent;
1047 tmp = tmp->bei_parent ) {
1048 if ( tmp->bei_id == base.e_id ) {
1057 /* aliases were already dereferenced in candidate list */
1058 if ( sop->ors_deref & LDAP_DEREF_SEARCHING ) {
1059 /* but if the search base is an alias, and we didn't
1060 * deref it when finding, return it.
1062 if ( is_entry_alias(e) &&
1063 ((sop->ors_deref & LDAP_DEREF_FINDING)
1064 || !bvmatch(&e->e_nname, &op->o_req_ndn)))
1069 /* scopes is only non-empty for onelevel or subtree */
1070 if ( !scopeok && BDB_IDL_N(scopes) ) {
1072 if ( sop->ors_scope == LDAP_SCOPE_ONELEVEL ) {
1073 x = bdb_idl_search( scopes,
1075 if ( scopes[x] == e->e_id )
1078 /* subtree, walk up the tree */
1079 EntryInfo *tmp = BEI(e);
1080 for (;tmp->bei_parent;
1081 tmp=tmp->bei_parent) {
1083 scopes, tmp->bei_id );
1084 if ( scopes[x] == tmp->bei_id ) {
1094 /* Not in scope, ignore it */
1097 LDAP_LOG ( OPERATION, RESULTS,
1098 "bdb_search: %ld scope not okay\n",
1101 Debug( LDAP_DEBUG_TRACE,
1102 "bdb_search: %ld scope not okay\n",
1109 * if it's a referral, add it to the list of referrals. only do
1110 * this for non-base searches, and don't check the filter
1111 * explicitly here since it's only a candidate anyway.
1113 if ( !manageDSAit && sop->oq_search.rs_scope != LDAP_SCOPE_BASE
1114 && is_entry_referral( e ) )
1116 BerVarray erefs = get_entry_referrals( sop, e );
1117 rs->sr_ref = referral_rewrite( erefs,
1119 sop->oq_search.rs_scope == LDAP_SCOPE_SUBTREE
1120 ? LDAP_SCOPE_SUBTREE
1121 : LDAP_SCOPE_BASE );
1123 send_search_reference( sop, rs );
1125 ber_bvarray_free( rs->sr_ref );
1126 ber_bvarray_free( erefs );
1132 if ( !manageDSAit && is_entry_glue( e )) {
1136 /* if it matches the filter and scope, send it */
1138 if (ps_type != LDAP_PSEARCH_BY_SCOPEOUT) {
1139 rs->sr_err = test_filter( sop, rs->sr_entry, &cookief );
1141 rs->sr_err = LDAP_COMPARE_TRUE;
1144 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1145 rc_sync = test_filter( sop, rs->sr_entry, &cookief );
1146 rs->sr_err = test_filter( sop, rs->sr_entry, &contextcsnand );
1147 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1148 if ( rc_sync == LDAP_COMPARE_TRUE ) {
1149 if ( no_sync_state_change ) {
1151 LDAP_LOG ( OPERATION, RESULTS,
1152 "bdb_search: error in context csn management\n",
1155 Debug( LDAP_DEBUG_TRACE,
1156 "bdb_search: error in context csn management\n",
1160 entry_sync_state = LDAP_SYNC_ADD;
1162 if ( no_sync_state_change ) {
1165 entry_sync_state = LDAP_SYNC_PRESENT;
1169 rs->sr_err = test_filter( sop,
1170 rs->sr_entry, sop->oq_search.rs_filter );
1174 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1175 /* check size limit */
1176 if ( --sop->oq_search.rs_slimit == -1 &&
1177 sop->o_sync_slog_size == -1 ) {
1179 bdb_cache_return_entry_r( bdb->bi_dbenv,
1180 &bdb->bi_cache, e, &lock );
1183 rs->sr_entry = NULL;
1184 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
1185 rs->sr_ref = rs->sr_v2ref;
1186 send_ldap_result( sop, rs );
1187 rs->sr_err = LDAP_SUCCESS;
1191 if ( get_pagedresults(sop) ) {
1192 if ( rs->sr_nentries >= sop->o_pagedresults_size ) {
1193 send_pagerequest_response( sop, rs,
1204 #if 0 /* noop is masked SLAP_CTRL_UPDATE */
1210 int premodify_found = 0;
1211 int entry_sync_state;
1213 if ( ps_type == LDAP_PSEARCH_BY_ADD ||
1214 ps_type == LDAP_PSEARCH_BY_DELETE ||
1215 ps_type == LDAP_PSEARCH_BY_MODIFY ||
1216 ps_type == LDAP_PSEARCH_BY_SCOPEOUT )
1218 if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1219 struct psid_entry* psid_e;
1220 LDAP_LIST_FOREACH( psid_e,
1221 &op->o_pm_list, ps_link)
1223 if( psid_e->ps_op == sop ) {
1224 premodify_found = 1;
1225 LDAP_LIST_REMOVE(psid_e, ps_link);
1229 if (psid_e != NULL) free (psid_e);
1231 if ( ps_type == LDAP_PSEARCH_BY_ADD ) {
1232 entry_sync_state = LDAP_SYNC_ADD;
1233 } else if ( ps_type == LDAP_PSEARCH_BY_DELETE ) {
1234 entry_sync_state = LDAP_SYNC_DELETE;
1235 } else if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1236 if ( premodify_found ) {
1237 entry_sync_state = LDAP_SYNC_MODIFY;
1239 entry_sync_state = LDAP_SYNC_ADD;
1241 } else if ( ps_type == LDAP_PSEARCH_BY_SCOPEOUT ) {
1242 entry_sync_state = LDAP_SYNC_DELETE;
1244 rs->sr_err = LDAP_OTHER;
1247 if ( sop->o_sync_slog_size != -1 ) {
1248 if ( entry_sync_state == LDAP_SYNC_DELETE ) {
1249 result = slap_add_session_log( op, sop, e );
1254 struct berval cookie;
1255 slap_compose_sync_cookie( sop, &cookie,
1257 sop->o_sync_state.sid,
1258 sop->o_sync_state.rid );
1259 rs->sr_err = slap_build_sync_state_ctrl( sop,
1260 rs, e, entry_sync_state, ctrls,
1261 num_ctrls++, 1, &cookie );
1262 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1263 rs->sr_attrs = attrs;
1264 rs->sr_ctrls = ctrls;
1265 result = send_search_entry( sop, rs );
1266 if ( cookie.bv_val )
1267 ch_free( cookie.bv_val );
1268 sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
1270 sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1271 ctrls[num_ctrls] = NULL;
1272 rs->sr_ctrls = NULL;
1274 } else if ( ps_type == LDAP_PSEARCH_BY_PREMODIFY ) {
1275 struct psid_entry* psid_e;
1276 psid_e = (struct psid_entry *) ch_calloc (1,
1277 sizeof(struct psid_entry));
1278 psid_e->ps_op = sop;
1279 LDAP_LIST_INSERT_HEAD( &op->o_pm_list,
1284 LDAP_LOG ( OPERATION, RESULTS,
1285 "bdb_search: invalid ps_type (%d) \n",
1288 Debug( LDAP_DEBUG_TRACE,
1289 "bdb_search: invalid ps_type (%d) \n",
1294 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1296 if ( rc_sync == LDAP_COMPARE_TRUE ) { /* ADD */
1297 rs->sr_err = slap_build_sync_state_ctrl( sop,
1298 rs, e, entry_sync_state, ctrls,
1299 num_ctrls++, 0, NULL );
1300 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1301 rs->sr_ctrls = ctrls;
1302 rs->sr_attrs = sop->oq_search.rs_attrs;
1303 result = send_search_entry( sop, rs );
1304 sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
1306 sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1307 ctrls[num_ctrls] = NULL;
1308 rs->sr_ctrls = NULL;
1309 } else { /* PRESENT */
1310 if ( sync_send_present_mode ) {
1311 result = slap_build_syncUUID_set( sop,
1313 if ( result <= 0 ) {
1317 if ( syncUUID_set_cnt == SLAP_SYNCUUID_SET_SIZE ) {
1318 rs->sr_err = LDAP_SUCCESS;
1319 rs->sr_rspoid = LDAP_SYNC_INFO;
1320 rs->sr_ctrls = NULL;
1321 result = slap_send_syncinfo( sop, rs,
1322 LDAP_TAG_SYNC_ID_SET,
1323 NULL, 0, syncUUID_set, 0 );
1324 if ( result != LDAP_SUCCESS )
1326 ber_bvarray_free_x( syncUUID_set,
1328 syncUUID_set = NULL;
1329 syncUUID_set_cnt = 0;
1337 rs->sr_attrs = sop->oq_search.rs_attrs;
1338 rs->sr_ctrls = NULL;
1339 result = send_search_entry( sop, rs );
1344 case 0: /* entry sent ok */
1346 case 1: /* entry not sent */
1348 case -1: /* connection closed */
1350 bdb_cache_return_entry_r(bdb->bi_dbenv,
1351 &bdb->bi_cache, e, &lock);
1353 rs->sr_entry = NULL;
1354 rs->sr_err = LDAP_OTHER;
1360 LDAP_LOG ( OPERATION, RESULTS,
1361 "bdb_search: %ld does not match filter\n", (long) id, 0, 0);
1363 Debug( LDAP_DEBUG_TRACE,
1364 "bdb_search: %ld does not match filter\n",
1371 /* free reader lock */
1373 bdb_cache_return_entry_r( bdb->bi_dbenv,
1374 &bdb->bi_cache, e , &lock );
1375 if ( sop->o_nocaching ) {
1376 bdb_cache_delete_entry( bdb, ei, locker, &lock );
1380 rs->sr_entry = NULL;
1383 ldap_pvt_thread_yield();
1386 if ( syncUUID_set_cnt > 0 ) {
1387 rs->sr_err = LDAP_SUCCESS;
1388 rs->sr_rspoid = LDAP_SYNC_INFO;
1389 rs->sr_ctrls = NULL;
1390 slap_send_syncinfo( sop, rs, LDAP_TAG_SYNC_ID_SET,
1391 NULL, 0, syncUUID_set, 0 );
1392 ber_bvarray_free_x( syncUUID_set, sop->o_tmpmemctx );
1393 syncUUID_set_cnt = 0;
1398 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1399 if ( sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
1400 struct berval cookie;
1401 slap_compose_sync_cookie( sop, &cookie,
1403 sop->o_sync_state.sid,
1404 sop->o_sync_state.rid );
1406 if ( sync_send_present_mode ) {
1407 rs->sr_err = LDAP_SUCCESS;
1408 rs->sr_rspoid = LDAP_SYNC_INFO;
1409 rs->sr_ctrls = NULL;
1410 slap_send_syncinfo( sop, rs,
1411 LDAP_TAG_SYNC_REFRESH_PRESENT, &cookie, 1, NULL, 0 );
1413 if ( !no_sync_state_change ) {
1415 ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
1416 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
1417 if ( ps_list->o_sync_slog_size > 0 ) {
1418 if ( ps_list->o_sync_state.sid == sop->o_sync_state.sid ) {
1426 rs->sr_err = LDAP_SUCCESS;
1427 rs->sr_rspoid = NULL;
1428 rs->sr_ctrls = NULL;
1429 slap_send_session_log( op, ps_list, rs );
1431 ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
1433 rs->sr_err = LDAP_SUCCESS;
1434 rs->sr_rspoid = LDAP_SYNC_INFO;
1435 rs->sr_ctrls = NULL;
1436 slap_send_syncinfo( sop, rs,
1437 LDAP_TAG_SYNC_REFRESH_DELETE, &cookie, 1, NULL, 0 );
1440 if ( cookie.bv_val ) {
1441 ch_free( cookie.bv_val );
1444 /* refreshOnly mode */
1445 struct berval cookie;
1446 slap_compose_sync_cookie( sop, &cookie,
1448 sop->o_sync_state.sid,
1449 sop->o_sync_state.rid );
1451 if ( sync_send_present_mode ) {
1452 slap_build_sync_done_ctrl( sop, rs, ctrls,
1453 num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_PRESENTS );
1455 if ( !no_sync_state_change ) {
1457 ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
1458 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
1460 if ( ps_list->o_sync_slog_size > 0 ) {
1461 if ( ps_list->o_sync_state.sid ==
1462 sop->o_sync_state.sid ) {
1470 slap_send_session_log( op, ps_list, rs );
1472 ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
1474 slap_build_sync_done_ctrl( sop, rs, ctrls,
1475 num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_DELETES );
1478 rs->sr_ctrls = ctrls;
1479 rs->sr_ref = rs->sr_v2ref;
1480 rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
1481 rs->sr_rspoid = NULL;
1482 send_ldap_result( sop, rs );
1483 if ( ctrls[num_ctrls-1]->ldctl_value.bv_val != NULL ) {
1484 sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val, sop->o_tmpmemctx );
1486 sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1487 ctrls[num_ctrls] = NULL;
1488 if ( cookie.bv_val )
1489 ch_free( cookie.bv_val );
1492 rs->sr_ctrls = NULL;
1493 rs->sr_ref = rs->sr_v2ref;
1494 rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
1495 rs->sr_rspoid = NULL;
1496 send_ldap_result( sop, rs );
1500 rs->sr_err = LDAP_SUCCESS;
1503 if( !IS_PSEARCH && e != NULL ) {
1504 /* free reader lock */
1505 bdb_cache_return_entry_r ( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
1508 LOCK_ID_FREE (bdb->bi_dbenv, locker );
1510 ber_bvfree( search_context_csn );
1512 if( rs->sr_v2ref ) {
1513 ber_bvarray_free( rs->sr_v2ref );
1514 rs->sr_v2ref = NULL;
1516 if( realbase.bv_val ) ch_free( realbase.bv_val );
1522 static int base_candidate(
1528 LDAP_LOG ( OPERATION, ENTRY,
1529 "base_candidate: base: \"%s\" (0x%08lx)\n",
1530 e->e_nname.bv_val, (long) e->e_id, 0);
1532 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
1533 e->e_nname.bv_val, (long) e->e_id, 0);
1541 /* Look for "objectClass Present" in this filter.
1542 * Also count depth of filter tree while we're at it.
1544 static int oc_filter(
1554 if( cur > *max ) *max = cur;
1556 switch(f->f_choice) {
1557 case LDAP_FILTER_PRESENT:
1558 if (f->f_desc == slap_schema.si_ad_objectClass) {
1563 case LDAP_FILTER_AND:
1564 case LDAP_FILTER_OR:
1566 for (f=f->f_and; f; f=f->f_next) {
1567 (void) oc_filter(f, cur, max);
1577 static void search_stack_free( void *key, void *data )
1579 ber_memfree_x(data, NULL);
1582 static void *search_stack(
1586 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1589 if ( op->o_threadctx ) {
1590 ldap_pvt_thread_pool_getkey( op->o_threadctx, search_stack,
1593 ret = bdb->bi_search_stack;
1597 ret = ch_malloc( bdb->bi_search_stack_depth * BDB_IDL_UM_SIZE
1599 if ( op->o_threadctx ) {
1600 ldap_pvt_thread_pool_setkey( op->o_threadctx, search_stack,
1601 ret, search_stack_free );
1603 bdb->bi_search_stack = ret;
1609 static int search_candidates(
1618 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1620 Filter f, rf, xf, nf;
1622 AttributeAssertion aa_ref;
1623 #ifdef BDB_SUBENTRIES
1625 AttributeAssertion aa_subentry;
1629 * This routine takes as input a filter (user-filter)
1630 * and rewrites it as follows:
1631 * (&(scope=DN)[(objectClass=subentry)]
1632 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
1636 LDAP_LOG ( OPERATION, ENTRY,
1637 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1638 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope);
1640 Debug(LDAP_DEBUG_TRACE,
1641 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1642 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope );
1645 xf.f_or = op->oq_search.rs_filter;
1646 xf.f_choice = LDAP_FILTER_OR;
1649 /* If the user's filter uses objectClass=*,
1650 * these clauses are redundant.
1652 if (!oc_filter(op->oq_search.rs_filter, 1, &depth)
1653 && !get_subentries_visibility(op)
1654 && !is_sync_protocol(op) )
1656 if( !get_manageDSAit(op) && !get_domainScope(op) ) {
1657 /* match referral objects */
1658 struct berval bv_ref = { sizeof("referral")-1, "referral" };
1659 rf.f_choice = LDAP_FILTER_EQUALITY;
1661 rf.f_av_desc = slap_schema.si_ad_objectClass;
1662 rf.f_av_value = bv_ref;
1663 rf.f_next = xf.f_or;
1670 f.f_choice = LDAP_FILTER_AND;
1672 /* Dummy; we compute scope separately now */
1673 nf.f_choice = SLAPD_FILTER_COMPUTED;
1674 nf.f_result = LDAP_SUCCESS;
1675 nf.f_next = xf.f_or == op->oq_search.rs_filter
1676 ? op->oq_search.rs_filter : &xf ;
1677 /* Filter depth increased again, adding dummy clause */
1680 #ifdef BDB_SUBENTRIES
1681 if( get_subentries_visibility( op ) ) {
1682 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1683 sf.f_choice = LDAP_FILTER_EQUALITY;
1684 sf.f_ava = &aa_subentry;
1685 sf.f_av_desc = slap_schema.si_ad_objectClass;
1686 sf.f_av_value = bv_subentry;
1687 sf.f_next = nf.f_next;
1692 /* Allocate IDL stack, plus 1 more for former tmp */
1693 if ( depth+1 > bdb->bi_search_stack_depth ) {
1694 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1696 stack = search_stack( stackop );
1699 if( op->ors_deref & LDAP_DEREF_SEARCHING ) {
1700 rc = search_aliases( op, rs, e, locker, ids, scopes, stack );
1702 rc = bdb_dn2idl( op, e, ids, stack );
1705 if ( rc == LDAP_SUCCESS ) {
1706 rc = bdb_filter_candidates( op, &f, ids,
1707 stack, stack+BDB_IDL_UM_SIZE );
1710 if ( depth+1 > bdb->bi_search_stack_depth ) {
1716 LDAP_LOG ( OPERATION, DETAIL1,
1717 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1719 Debug(LDAP_DEBUG_TRACE,
1720 "bdb_search_candidates: failed (rc=%d)\n",
1726 LDAP_LOG ( OPERATION, DETAIL1,
1727 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1728 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1729 (long) BDB_IDL_LAST(ids));
1731 Debug(LDAP_DEBUG_TRACE,
1732 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1734 (long) BDB_IDL_FIRST(ids),
1735 (long) BDB_IDL_LAST(ids) );
1743 send_pagerequest_response(
1749 LDAPControl ctrl, *ctrls[2];
1750 BerElementBuffer berbuf;
1751 BerElement *ber = (BerElement *)&berbuf;
1752 struct berval cookie = { 0, NULL };
1753 PagedResultsCookie respcookie;
1756 LDAP_LOG ( OPERATION, ENTRY,
1757 "send_pagerequest_response: lastid: (0x%08lx) "
1758 "nentries: (0x%081x)\n",
1759 lastid, rs->sr_nentries, NULL );
1761 Debug(LDAP_DEBUG_ARGS, "send_pagerequest_response: lastid: (0x%08lx) "
1762 "nentries: (0x%081x)\n", lastid, rs->sr_nentries, NULL );
1765 ctrl.ldctl_value.bv_val = NULL;
1769 ber_init2( ber, NULL, LBER_USE_DER );
1771 respcookie = ( PagedResultsCookie )lastid;
1772 op->o_conn->c_pagedresults_state.ps_cookie = respcookie;
1773 cookie.bv_len = sizeof( respcookie );
1774 cookie.bv_val = (char *)&respcookie;
1777 * FIXME: we should consider sending an estimate of the entries
1778 * left, after appropriate security check is done
1780 ber_printf( ber, "{iO}", tentries, &cookie );
1782 if ( ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 ) == -1 ) {
1786 ctrls[0]->ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
1787 ctrls[0]->ldctl_iscritical = 0;
1789 rs->sr_ctrls = ctrls;
1790 rs->sr_err = LDAP_SUCCESS;
1791 send_ldap_result( op, rs );
1794 (void) ber_free_buf( ber );