1 /* search.c - search operation */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
17 static int base_candidate(
22 static int search_candidates(
23 Operation *stackop, /* op with the current threadctx/slab cache */
24 Operation *sop, /* search op */
31 static void send_pagerequest_response(
37 /* Dereference aliases for a single alias entry. Return the final
38 * dereferenced entry on success, NULL on any failure.
40 static Entry * deref_base (
50 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
55 rs->sr_err = LDAP_ALIAS_DEREF_PROBLEM;
56 rs->sr_text = "maximum deref depth exceeded";
58 while (BDB_IDL_N(tmp) < op->o_bd->be_max_deref_depth) {
60 /* Remember the last entry we looked at, so we can
65 /* If this is part of a subtree or onelevel search,
66 * have we seen this ID before? If so, quit.
68 if ( visited && bdb_idl_insert( visited, e->e_id ) ) {
73 /* If we've seen this ID during this deref iteration,
76 if ( bdb_idl_insert( tmp, e->e_id ) ) {
77 rs->sr_err = LDAP_ALIAS_PROBLEM;
78 rs->sr_text = "circular alias";
83 /* If there was a problem getting the aliasedObjectName,
84 * get_alias_dn will have set the error status.
86 if ( get_alias_dn(e, &ndn, &rs->sr_err, &rs->sr_text) ) {
91 rs->sr_err = bdb_dn2entry( op, NULL, &ndn, &ei,
94 if ( ei ) e = ei->bei_e;
98 rs->sr_err = LDAP_ALIAS_PROBLEM;
99 rs->sr_text = "aliasedObject not found";
103 /* Free the previous entry, continue to work with the
104 * one we just retrieved.
106 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
110 /* We found a regular entry. Return this to the caller. The
111 * entry is still locked for Read.
113 if (!is_entry_alias(e)) {
114 rs->sr_err = LDAP_SUCCESS;
122 /* Look for and dereference all aliases within the search scope. Adds
123 * the dereferenced entries to the "ids" list. Requires "stack" to be
124 * able to hold 8 levels of DB_SIZE IDLs. Of course we're hardcoded to
125 * require a minimum of 8 UM_SIZE IDLs so this is never a problem.
127 static int search_aliases(
137 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
138 ID *aliases, *curscop, *subscop, *visited, *newsubs, *oldsubs, *tmp;
139 ID cursora, ida, cursoro, ido, *subscop2;
142 struct berval bv_alias = { sizeof("alias")-1, "alias" };
143 AttributeAssertion aa_alias;
145 DB_LOCK locka, lockr;
148 aliases = stack; /* IDL of all aliases in the database */
149 curscop = aliases + BDB_IDL_DB_SIZE; /* Aliases in the current scope */
150 subscop = curscop + BDB_IDL_DB_SIZE; /* The current scope */
151 visited = subscop + BDB_IDL_DB_SIZE; /* IDs we've seen in this search */
152 newsubs = visited + BDB_IDL_DB_SIZE; /* New subtrees we've added */
153 oldsubs = newsubs + BDB_IDL_DB_SIZE; /* Subtrees added previously */
154 tmp = oldsubs + BDB_IDL_DB_SIZE; /* Scratch space for deref_base() */
156 /* A copy of subscop, because subscop gets clobbered by
157 * the bdb_idl_union/intersection routines
159 subscop2 = tmp + BDB_IDL_DB_SIZE;
161 af.f_choice = LDAP_FILTER_EQUALITY;
162 af.f_ava = &aa_alias;
163 af.f_av_desc = slap_schema.si_ad_objectClass;
164 af.f_av_value = bv_alias;
167 /* Find all aliases in database */
168 BDB_IDL_ZERO( aliases );
169 rs->sr_err = bdb_filter_candidates( op, &af, aliases,
171 if (rs->sr_err != LDAP_SUCCESS) {
175 oldsubs[1] = e->e_id;
178 BDB_IDL_ZERO( visited );
179 BDB_IDL_ZERO( newsubs );
182 ido = bdb_idl_first( oldsubs, &cursoro );
185 /* Set curscop to only the aliases in the current scope. Start with
186 * all the aliases, obtain the IDL for the current scope, and then
187 * get the intersection of these two IDLs. Add the current scope
188 * to the cumulative list of candidates.
190 BDB_IDL_CPY( curscop, aliases );
191 rs->sr_err = bdb_dn2idl( op, e, subscop,
192 subscop2+BDB_IDL_DB_SIZE );
196 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, e, &locka);
198 BDB_IDL_CPY(subscop2, subscop);
199 rs->sr_err = bdb_idl_intersection(curscop, subscop);
200 bdb_idl_union( ids, subscop2 );
202 /* Dereference all of the aliases in the current scope. */
204 for (ida = bdb_idl_first(curscop, &cursora); ida != NOID;
205 ida = bdb_idl_next(curscop, &cursora))
208 rs->sr_err = bdb_cache_find_id(op, NULL,
209 ida, &ei, 0, locker, &lockr );
210 if (rs->sr_err != LDAP_SUCCESS) {
215 /* This should only happen if the curscop IDL has maxed out and
216 * turned into a range that spans IDs indiscriminately
218 if (!is_entry_alias(a)) {
219 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
224 /* Actually dereference the alias */
226 a = deref_base( op, rs, a, &matched, locker, &lockr,
229 /* If the target was not already in our current candidates,
230 * make note of it in the newsubs list. Also
231 * set it in the scopes list so that bdb_search
234 if (bdb_idl_insert(ids, a->e_id) == 0) {
235 bdb_idl_insert(newsubs, a->e_id);
236 bdb_idl_insert(scopes, a->e_id);
238 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
241 } else if (matched) {
242 /* Alias could not be dereferenced, or it deref'd to
243 * an ID we've already seen. Ignore it.
245 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
250 /* If this is a OneLevel search, we're done; oldsubs only had one
251 * ID in it. For a Subtree search, oldsubs may be a list of scope IDs.
253 if (op->ors_scope != LDAP_SCOPE_SUBTREE) break;
255 ido = bdb_idl_next( oldsubs, &cursoro );
257 /* If we're done processing the old scopes, did we add any new
258 * scopes in this iteration? If so, go back and do those now.
261 if (BDB_IDL_IS_ZERO(newsubs)) break;
262 BDB_IDL_CPY(oldsubs, newsubs);
263 BDB_IDL_ZERO(newsubs);
265 ido = bdb_idl_first( oldsubs, &cursoro );
268 /* Find the entry corresponding to the next scope. If it can't
269 * be found, ignore it and move on. This should never happen;
270 * we should never see the ID of an entry that doesn't exist.
271 * Set the name so that the scope's IDL can be retrieved.
274 rs->sr_err = bdb_cache_find_id(op, NULL, ido, &ei,
276 if (rs->sr_err != LDAP_SUCCESS) goto nextido;
283 int is_sync_protocol( Operation *op )
285 if ( op->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST )
290 #define IS_BDB_REPLACE(type) (( type == LDAP_PSEARCH_BY_DELETE ) || \
291 ( type == LDAP_PSEARCH_BY_SCOPEOUT ))
292 #define IS_PSEARCH (op != sop)
295 bdb_drop_psearch( Operation *op, ber_int_t msgid )
298 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
300 LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
301 if ( ps_list->o_connid == op->o_connid ) {
302 if ( ps_list->o_msgid == msgid ) {
303 ps_list->o_abandon = 1;
304 LDAP_LIST_REMOVE( ps_list, o_ps_link );
305 ldap_pvt_thread_mutex_lock( &op->o_conn->c_mutex );
306 LDAP_STAILQ_REMOVE( &op->o_conn->c_ops, ps_list,
308 LDAP_STAILQ_NEXT( ps_list, o_next ) = NULL;
309 op->o_conn->c_n_ops_executing--;
310 op->o_conn->c_n_ops_completed++;
311 ldap_pvt_thread_mutex_unlock( &op->o_conn->c_mutex );
321 bdb_abandon( Operation *op, SlapReply *rs )
325 ps = bdb_drop_psearch( op, op->oq_abandon.rs_msgid );
327 if ( ps->o_tmpmemctx ) {
328 sl_mem_destroy( NULL, ps->o_tmpmemctx );
333 return LDAP_UNAVAILABLE;
337 bdb_cancel( Operation *op, SlapReply *rs )
341 ps = bdb_drop_psearch( op, op->oq_cancel.rs_msgid );
343 rs->sr_err = LDAP_CANCELLED;
344 send_ldap_result( ps, rs );
345 if ( ps->o_tmpmemctx ) {
346 sl_mem_destroy( NULL, ps->o_tmpmemctx );
351 return LDAP_UNAVAILABLE;
354 int bdb_search( Operation *op, SlapReply *rs )
356 return bdb_do_search( op, rs, op, NULL, 0 );
359 /* For persistent searches, op is the currently executing operation,
360 * sop is the persistent search. For regular searches, sop = op.
363 bdb_do_search( Operation *op, SlapReply *rs, Operation *sop,
364 Entry *ps_e, int ps_type )
366 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
369 ID candidates[BDB_IDL_UM_SIZE];
370 ID scopes[BDB_IDL_DB_SIZE];
371 Entry *e = NULL, base;
372 Entry *matched = NULL;
374 struct berval realbase = { 0, NULL };
378 AttributeName *attrs;
380 Filter contextcsnand, contextcsnle, cookief, csnfnot, csnfeq, csnfand, csnfge;
381 AttributeAssertion aa_ge, aa_eq, aa_le;
383 struct berval *search_context_csn = NULL;
385 LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
387 AttributeName uuid_attr[2];
389 int entry_sync_state = -1;
390 AttributeName null_attr;
391 int no_sync_state_change = 0;
392 struct slap_limits_set *limit = NULL;
395 u_int32_t locker = 0;
399 int sync_send_present_mode = 1;
405 BerVarray syncUUID_set = NULL;
406 int syncUUID_set_cnt = 0;
409 LDAP_LOG( OPERATION, ENTRY, "bdb_search\n", 0, 0, 0 );
411 Debug( LDAP_DEBUG_TRACE, "=> bdb_search\n",
414 attrs = sop->oq_search.rs_attrs;
416 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST ) {
417 struct slap_session_entry *sent;
418 if ( sop->o_sync_state.sid >= 0 ) {
419 LDAP_LIST_FOREACH( sent, &bdb->bi_session_list, se_link ) {
420 if ( sent->se_id == sop->o_sync_state.sid ) {
421 sop->o_sync_slog_size = sent->se_size;
428 /* psearch needs to be registered before refresh begins */
429 /* psearch and refresh transmission is serialized in send_ldap_ber() */
430 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
431 ldap_pvt_thread_mutex_lock( &bdb->bi_pslist_mutex );
432 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
433 ldap_pvt_thread_mutex_unlock( &bdb->bi_pslist_mutex );
434 } else if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST
435 && sop->o_sync_slog_size >= 0 ) {
436 ldap_pvt_thread_mutex_lock( &bdb->bi_pslist_mutex );
437 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
438 if ( ps_list->o_sync_slog_size >= 0 ) {
439 if ( ps_list->o_sync_state.sid == sop->o_sync_state.sid ) {
447 if ( ps_list->o_sync_slog_omitcsn.bv_len != 0 ) {
448 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
449 if ( sop->o_sync_state.ctxcsn &&
450 sop->o_sync_state.ctxcsn->bv_val != NULL ) {
451 value_match( &match, slap_schema.si_ad_entryCSN, mr,
452 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
453 sop->o_sync_state.ctxcsn,
454 &ps_list->o_sync_slog_omitcsn,
460 sync_send_present_mode = 0;
463 sync_send_present_mode = 0;
465 } else if ( sop->o_sync_slog_size >= 0 ) {
466 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
468 sop->o_sync_state.sid = -1;
470 ldap_pvt_thread_mutex_unlock( &bdb->bi_pslist_mutex );
473 null_attr.an_desc = NULL;
474 null_attr.an_oc = NULL;
475 null_attr.an_name.bv_len = 0;
476 null_attr.an_name.bv_val = NULL;
478 for( num_ctrls = 0; num_ctrls < SLAP_MAX_RESPONSE_CONTROLS; num_ctrls++ ) {
479 ctrls[num_ctrls] = NULL;
483 if ( IS_PSEARCH && IS_BDB_REPLACE(ps_type)) {
485 attrs[0].an_desc = NULL;
486 attrs[0].an_oc = NULL;
487 attrs[0].an_name.bv_len = 0;
488 attrs[0].an_name.bv_val = NULL;
491 manageDSAit = get_manageDSAit( sop );
493 /* Sync control overrides manageDSAit */
495 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
496 if ( manageDSAit == SLAP_NO_CONTROL )
497 manageDSAit = SLAP_CRITICAL_CONTROL;
498 } else if ( IS_PSEARCH ) {
499 if ( manageDSAit == SLAP_NO_CONTROL )
500 manageDSAit = SLAP_CRITICAL_CONTROL;
503 rs->sr_err = LOCK_ID (bdb->bi_dbenv, &locker );
509 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
513 if ( sop->o_req_ndn.bv_len == 0 ) {
514 /* DIT root special case */
515 e = (Entry *) &slap_entry_root;
516 rs->sr_err = LDAP_SUCCESS;
519 /* get entry with reader lock */
520 rs->sr_err = bdb_dn2entry( op, NULL, &sop->o_req_ndn, &ei,
526 matched = ei->bei_e; break;
528 e = ei->bei_e; break;
530 send_ldap_error( sop, rs, LDAP_BUSY, "ldap server busy" );
531 LOCK_ID_FREE (bdb->bi_dbenv, locker );
533 case DB_LOCK_DEADLOCK:
534 case DB_LOCK_NOTGRANTED:
537 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
538 LOCK_ID_FREE (bdb->bi_dbenv, locker );
542 if ( e && (op->ors_deref & LDAP_DEREF_FINDING) && is_entry_alias(e) ) {
543 BDB_IDL_ZERO(candidates);
544 e = deref_base( op, rs, e, &matched, locker, &lock,
549 struct berval matched_dn = { 0, NULL };
551 if ( matched != NULL ) {
553 ber_dupbv( &matched_dn, &matched->e_name );
555 erefs = is_entry_referral( matched )
556 ? get_entry_referrals( op, matched )
559 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
564 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
565 &sop->o_req_dn, sop->oq_search.rs_scope );
566 ber_bvarray_free( erefs );
570 rs->sr_ref = referral_rewrite( default_referral,
571 NULL, &sop->o_req_dn, sop->oq_search.rs_scope );
574 rs->sr_err = LDAP_REFERRAL;
575 rs->sr_matched = matched_dn.bv_val;
576 send_ldap_result( sop, rs );
578 LOCK_ID_FREE (bdb->bi_dbenv, locker );
580 ber_bvarray_free( rs->sr_ref );
583 if ( matched_dn.bv_val ) {
584 ber_memfree( matched_dn.bv_val );
585 rs->sr_matched = NULL;
590 if (!manageDSAit && e != &slap_entry_root && is_entry_referral( e ) ) {
591 /* entry is a referral, don't allow add */
592 struct berval matched_dn;
595 ber_dupbv( &matched_dn, &e->e_name );
596 erefs = get_entry_referrals( op, e );
598 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
602 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
603 &sop->o_req_dn, sop->oq_search.rs_scope );
604 ber_bvarray_free( erefs );
608 LDAP_LOG ( OPERATION, RESULTS,
609 "bdb_search: entry is referral\n", 0, 0, 0 );
611 Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
615 if (!rs->sr_ref) rs->sr_text = "bad_referral object";
616 rs->sr_err = LDAP_REFERRAL;
617 rs->sr_matched = matched_dn.bv_val;
618 send_ldap_result( sop, rs );
620 LOCK_ID_FREE (bdb->bi_dbenv, locker );
621 ber_bvarray_free( rs->sr_ref );
623 ber_memfree( matched_dn.bv_val );
624 rs->sr_matched = NULL;
628 if ( get_assert( op ) &&
629 ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
631 rs->sr_err = LDAP_ASSERTION_FAILED;
632 send_ldap_result( sop, rs );
636 /* if not root, get appropriate limits */
637 if ( be_isroot( op->o_bd, &sop->o_ndn ) ) {
640 ( void ) get_limits( op->o_bd, &sop->o_ndn, &limit );
643 /* The time/size limits come first because they require very little
644 * effort, so there's no chance the candidates are selected and then
645 * the request is not honored only because of time/size constraints */
647 /* if no time limit requested, use soft limit (unless root!) */
649 if ( sop->oq_search.rs_tlimit == 0 ) {
650 sop->oq_search.rs_tlimit = -1; /* allow root to set no limit */
653 if ( sop->oq_search.rs_slimit == 0 ) {
654 sop->oq_search.rs_slimit = -1;
658 /* if no limit is required, use soft limit */
659 if ( sop->oq_search.rs_tlimit <= 0 ) {
660 sop->oq_search.rs_tlimit = limit->lms_t_soft;
662 /* if requested limit higher than hard limit, abort */
663 } else if ( sop->oq_search.rs_tlimit > limit->lms_t_hard ) {
664 /* no hard limit means use soft instead */
665 if ( limit->lms_t_hard == 0
666 && limit->lms_t_soft > -1
667 && sop->oq_search.rs_tlimit > limit->lms_t_soft ) {
668 sop->oq_search.rs_tlimit = limit->lms_t_soft;
670 /* positive hard limit means abort */
671 } else if ( limit->lms_t_hard > 0 ) {
672 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
673 send_ldap_result( sop, rs );
674 rs->sr_err = LDAP_SUCCESS;
678 /* negative hard limit means no limit */
681 /* if no limit is required, use soft limit */
682 if ( sop->oq_search.rs_slimit <= 0 ) {
683 if ( get_pagedresults(sop) && limit->lms_s_pr != 0 ) {
684 sop->oq_search.rs_slimit = limit->lms_s_pr;
686 sop->oq_search.rs_slimit = limit->lms_s_soft;
689 /* if requested limit higher than hard limit, abort */
690 } else if ( sop->oq_search.rs_slimit > limit->lms_s_hard ) {
691 /* no hard limit means use soft instead */
692 if ( limit->lms_s_hard == 0
693 && limit->lms_s_soft > -1
694 && sop->oq_search.rs_slimit > limit->lms_s_soft ) {
695 sop->oq_search.rs_slimit = limit->lms_s_soft;
697 /* positive hard limit means abort */
698 } else if ( limit->lms_s_hard > 0 ) {
699 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
700 send_ldap_result( sop, rs );
701 rs->sr_err = LDAP_SUCCESS;
705 /* negative hard limit means no limit */
709 /* compute it anyway; root does not use it */
710 stoptime = op->o_time + sop->oq_search.rs_tlimit;
712 /* need normalized dn below */
713 ber_dupbv( &realbase, &e->e_nname );
715 /* Copy info to base, must free entry before accessing the database
716 * in search_candidates, to avoid deadlocks.
718 base.e_private = e->e_private;
719 base.e_nname = realbase;
722 if ( e != &slap_entry_root ) {
723 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
727 rs->sr_err = bdb_get_commit_csn( sop, rs, &search_context_csn, locker, &ctxcsn_lock );
729 if ( rs->sr_err != LDAP_SUCCESS ) {
730 send_ldap_error( sop, rs, rs->sr_err, "error in csn management in search" );
734 if ( sop->o_sync_mode != SLAP_SYNC_NONE && sop->o_sync_state.ctxcsn &&
735 sop->o_sync_state.ctxcsn->bv_val &&
736 ber_bvcmp( &sop->o_sync_state.ctxcsn[0], search_context_csn ) == 0 )
738 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
742 /* select candidates */
743 if ( sop->oq_search.rs_scope == LDAP_SCOPE_BASE ) {
744 rs->sr_err = base_candidate( op->o_bd, &base, candidates );
747 BDB_IDL_ZERO( candidates );
748 BDB_IDL_ZERO( scopes );
749 rs->sr_err = search_candidates( op, sop, rs, &base, locker, candidates, scopes );
752 if ( sop->o_sync_mode != SLAP_SYNC_NONE ) {
753 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
756 /* start cursor at beginning of candidates.
760 if ( !BDB_IDL_IS_RANGE( candidates ) ) {
761 cursor = bdb_idl_search( candidates, ps_e->e_id );
762 if ( candidates[cursor] != ps_e->e_id ) {
763 rs->sr_err = LDAP_SUCCESS;
767 if ( ps_e->e_id < BDB_IDL_RANGE_FIRST(candidates)
768 || ps_e->e_id > BDB_IDL_RANGE_LAST(candidates)){
769 rs->sr_err = LDAP_SUCCESS;
774 candidates[1] = ps_e->e_id;
777 if ( candidates[0] == 0 ) {
779 LDAP_LOG ( OPERATION, RESULTS,
780 "bdb_search: no candidates\n", 0, 0, 0 );
782 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
786 rs->sr_err = LDAP_SUCCESS;
788 send_ldap_result( sop, rs );
792 /* if not root and candidates exceed to-be-checked entries, abort */
793 if ( !isroot && limit->lms_s_unchecked != -1 ) {
794 if ( BDB_IDL_N(candidates) > (unsigned) limit->lms_s_unchecked ) {
795 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
796 send_ldap_result( sop, rs );
797 rs->sr_err = LDAP_SUCCESS;
802 if ( isroot || !limit->lms_s_pr_hide ) {
803 tentries = BDB_IDL_N(candidates);
806 #ifdef LDAP_CONTROL_PAGEDRESULTS
807 if ( get_pagedresults(sop) ) {
808 if ( sop->o_pagedresults_state.ps_cookie == 0 ) {
811 if ( sop->o_pagedresults_size == 0 ) {
812 rs->sr_err = LDAP_SUCCESS;
813 rs->sr_text = "search abandoned by pagedResult size=0";
814 send_ldap_result( sop, rs );
817 for ( id = bdb_idl_first( candidates, &cursor );
818 id != NOID && id <= (ID)( sop->o_pagedresults_state.ps_cookie );
819 id = bdb_idl_next( candidates, &cursor ) );
821 if ( cursor == NOID ) {
823 LDAP_LOG ( OPERATION, RESULTS,
824 "bdb_search: no paged results candidates\n",
827 Debug( LDAP_DEBUG_TRACE,
828 "bdb_search: no paged results candidates\n",
831 send_pagerequest_response( sop, rs, lastid, 0 );
833 rs->sr_err = LDAP_OTHER;
840 if ( (sop->o_sync_mode & SLAP_SYNC_REFRESH) || IS_PSEARCH )
844 cookief.f_choice = LDAP_FILTER_AND;
845 cookief.f_and = &csnfnot;
846 cookief.f_next = NULL;
848 csnfnot.f_choice = LDAP_FILTER_NOT;
849 csnfnot.f_not = &csnfeq;
850 csnfnot.f_next = &csnfand;
852 csnfeq.f_choice = LDAP_FILTER_EQUALITY;
853 csnfeq.f_ava = &aa_eq;
854 csnfeq.f_av_desc = slap_schema.si_ad_entryCSN;
855 if ( sop->o_sync_state.ctxcsn != NULL ) {
856 csnfeq.f_av_value = *sop->o_sync_state.ctxcsn;
858 csnfeq.f_av_value = slap_empty_bv;
861 csnfand.f_choice = LDAP_FILTER_AND;
862 csnfand.f_and = &csnfge;
863 csnfand.f_next = NULL;
865 csnfge.f_choice = LDAP_FILTER_GE;
866 csnfge.f_ava = &aa_ge;
867 csnfge.f_av_desc = slap_schema.si_ad_entryCSN;
868 if ( sop->o_sync_state.ctxcsn != NULL ) {
869 csnfge.f_av_value = *sop->o_sync_state.ctxcsn;
871 csnfge.f_av_value = slap_empty_bv;
874 if ( search_context_csn && !IS_PSEARCH ) {
875 csnfge.f_next = &contextcsnand;
877 contextcsnand.f_choice = LDAP_FILTER_AND;
878 contextcsnand.f_and = &contextcsnle;
879 contextcsnand.f_next = NULL;
881 contextcsnle.f_choice = LDAP_FILTER_LE;
882 contextcsnle.f_ava = &aa_le;
883 contextcsnle.f_av_desc = slap_schema.si_ad_entryCSN;
884 contextcsnle.f_av_value = *search_context_csn;
885 contextcsnle.f_next = sop->oq_search.rs_filter;
887 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
888 if ( sop->o_sync_state.ctxcsn &&
889 sop->o_sync_state.ctxcsn->bv_val != NULL ) {
890 value_match( &match, slap_schema.si_ad_entryCSN, mr,
891 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
892 &sop->o_sync_state.ctxcsn[0], search_context_csn,
897 no_sync_state_change = ( match >= 0 );
899 csnfge.f_next = sop->oq_search.rs_filter;
903 for ( id = bdb_idl_first( candidates, &cursor );
904 id != NOID && !no_sync_state_change;
905 id = bdb_idl_next( candidates, &cursor ) )
910 /* check for abandon */
911 if ( sop->o_abandon ) {
913 bdb_drop_psearch( sop, sop->o_msgid );
915 rs->sr_err = LDAP_SUCCESS;
919 #ifdef LDAP_EXOP_X_CANCEL
920 if ( sop->o_cancel ) {
921 assert( sop->o_cancel == SLAP_CANCEL_REQ );
922 rs->sr_err = LDAP_CANCELLED;
923 send_ldap_result( sop, rs );
924 sop->o_cancel = SLAP_CANCEL_ACK;
925 rs->sr_err = LDAP_SUCCESS;
930 /* check time limit */
931 if ( sop->oq_search.rs_tlimit != -1 && slap_get_time() > stoptime ) {
932 rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
933 rs->sr_ref = rs->sr_v2ref;
934 send_ldap_result( sop, rs );
935 rs->sr_err = LDAP_SUCCESS;
942 /* get the entry with reader lock */
944 rs->sr_err = bdb_cache_find_id( op, NULL,
945 id, &ei, 0, locker, &lock );
947 if (rs->sr_err == LDAP_BUSY) {
948 rs->sr_text = "ldap server busy";
949 send_ldap_result( sop, rs );
952 } else if ( rs->sr_err == DB_LOCK_DEADLOCK
953 || rs->sr_err == DB_LOCK_NOTGRANTED )
958 if ( ei && rs->sr_err == LDAP_SUCCESS ) {
965 if( !BDB_IDL_IS_RANGE(candidates) ) {
966 /* only complain for non-range IDLs */
968 LDAP_LOG ( OPERATION, RESULTS,
969 "bdb_search: candidate %ld not found\n",
972 Debug( LDAP_DEBUG_TRACE,
973 "bdb_search: candidate %ld not found\n",
985 #ifdef BDB_SUBENTRIES
986 /* FIXME: send all but syncrepl
987 if ( !is_sync_protocol( sop ) ) {
989 if ( is_entry_subentry( e ) ) {
990 if( sop->oq_search.rs_scope != LDAP_SCOPE_BASE ) {
991 if(!get_subentries_visibility( sop )) {
992 /* only subentries are visible */
996 } else if ( get_subentries( sop ) &&
997 !get_subentries_visibility( sop ))
999 /* only subentries are visible */
1003 } else if ( get_subentries_visibility( sop )) {
1004 /* only subentries are visible */
1012 /* Does this candidate actually satisfy the search scope?
1014 * Note that we don't lock access to the bei_parent pointer.
1015 * Since only leaf nodes can be deleted, the parent of any
1016 * node will always be a valid node. Also since we have
1017 * a Read lock on the data, it cannot be renamed out of the
1018 * scope while we are looking at it, and unless we're using
1019 * BDB_HIER, its parents cannot be moved either.
1021 switch( sop->ors_scope ) {
1022 case LDAP_SCOPE_BASE:
1023 /* This is always true, yes? */
1024 if ( id == base.e_id )
1027 case LDAP_SCOPE_ONELEVEL:
1028 if ( ei->bei_parent->bei_id == base.e_id )
1031 case LDAP_SCOPE_SUBTREE:
1033 for ( tmp = BEI(e); tmp->bei_parent;
1034 tmp = tmp->bei_parent ) {
1035 if ( tmp->bei_id == base.e_id ) {
1044 /* aliases were already dereferenced in candidate list */
1045 if ( sop->ors_deref & LDAP_DEREF_SEARCHING ) {
1046 /* but if the search base is an alias, and we didn't
1047 * deref it when finding, return it.
1049 if ( is_entry_alias(e) &&
1050 ((sop->ors_deref & LDAP_DEREF_FINDING)
1051 || !bvmatch(&e->e_nname, &op->o_req_ndn)))
1056 /* scopes is only non-empty for onelevel or subtree */
1057 if ( !scopeok && BDB_IDL_N(scopes) ) {
1059 if ( sop->ors_scope == LDAP_SCOPE_ONELEVEL ) {
1060 x = bdb_idl_search( scopes,
1062 if ( scopes[x] == e->e_id )
1065 /* subtree, walk up the tree */
1066 EntryInfo *tmp = BEI(e);
1067 for (;tmp->bei_parent;
1068 tmp=tmp->bei_parent) {
1070 scopes, tmp->bei_id );
1071 if ( scopes[x] == tmp->bei_id ) {
1081 /* Not in scope, ignore it */
1084 LDAP_LOG ( OPERATION, RESULTS,
1085 "bdb_search: %ld scope not okay\n",
1088 Debug( LDAP_DEBUG_TRACE,
1089 "bdb_search: %ld scope not okay\n",
1096 * if it's a referral, add it to the list of referrals. only do
1097 * this for non-base searches, and don't check the filter
1098 * explicitly here since it's only a candidate anyway.
1100 if ( !manageDSAit && sop->oq_search.rs_scope != LDAP_SCOPE_BASE
1101 && is_entry_referral( e ) )
1103 BerVarray erefs = get_entry_referrals( sop, e );
1104 rs->sr_ref = referral_rewrite( erefs,
1106 sop->oq_search.rs_scope == LDAP_SCOPE_SUBTREE
1107 ? LDAP_SCOPE_SUBTREE
1108 : LDAP_SCOPE_BASE );
1110 send_search_reference( sop, rs );
1112 ber_bvarray_free( rs->sr_ref );
1113 ber_bvarray_free( erefs );
1119 if ( !manageDSAit && is_entry_glue( e )) {
1123 /* if it matches the filter and scope, send it */
1125 if (ps_type != LDAP_PSEARCH_BY_SCOPEOUT) {
1126 rs->sr_err = test_filter( sop, rs->sr_entry, &cookief );
1128 rs->sr_err = LDAP_COMPARE_TRUE;
1131 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1132 rc_sync = test_filter( sop, rs->sr_entry, &cookief );
1133 rs->sr_err = test_filter( sop, rs->sr_entry, &contextcsnand );
1134 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1135 if ( rc_sync == LDAP_COMPARE_TRUE ) {
1136 if ( no_sync_state_change ) {
1138 LDAP_LOG ( OPERATION, RESULTS,
1139 "bdb_search: error in context csn management\n",
1142 Debug( LDAP_DEBUG_TRACE,
1143 "bdb_search: error in context csn management\n",
1147 entry_sync_state = LDAP_SYNC_ADD;
1149 if ( no_sync_state_change ) {
1152 entry_sync_state = LDAP_SYNC_PRESENT;
1156 rs->sr_err = test_filter( sop,
1157 rs->sr_entry, sop->oq_search.rs_filter );
1161 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1162 /* check size limit */
1163 if ( --sop->oq_search.rs_slimit == -1 &&
1164 sop->o_sync_slog_size == -1 ) {
1166 bdb_cache_return_entry_r( bdb->bi_dbenv,
1167 &bdb->bi_cache, e, &lock );
1170 rs->sr_entry = NULL;
1171 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
1172 rs->sr_ref = rs->sr_v2ref;
1173 send_ldap_result( sop, rs );
1174 rs->sr_err = LDAP_SUCCESS;
1178 #ifdef LDAP_CONTROL_PAGEDRESULTS
1179 if ( get_pagedresults(sop) ) {
1180 if ( rs->sr_nentries >= sop->o_pagedresults_size ) {
1181 send_pagerequest_response( sop, rs,
1193 #if 0 /* noop is masked SLAP_CTRL_UPDATE */
1199 int premodify_found = 0;
1200 int entry_sync_state;
1202 if ( ps_type == LDAP_PSEARCH_BY_ADD ||
1203 ps_type == LDAP_PSEARCH_BY_DELETE ||
1204 ps_type == LDAP_PSEARCH_BY_MODIFY ||
1205 ps_type == LDAP_PSEARCH_BY_SCOPEOUT )
1207 if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1208 struct psid_entry* psid_e;
1209 LDAP_LIST_FOREACH( psid_e,
1210 &op->o_pm_list, ps_link)
1212 if( psid_e->ps_op == sop ) {
1213 premodify_found = 1;
1214 LDAP_LIST_REMOVE(psid_e, ps_link);
1218 if (psid_e != NULL) free (psid_e);
1220 if ( ps_type == LDAP_PSEARCH_BY_ADD ) {
1221 entry_sync_state = LDAP_SYNC_ADD;
1222 } else if ( ps_type == LDAP_PSEARCH_BY_DELETE ) {
1223 entry_sync_state = LDAP_SYNC_DELETE;
1224 } else if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1225 if ( premodify_found ) {
1226 entry_sync_state = LDAP_SYNC_MODIFY;
1228 entry_sync_state = LDAP_SYNC_ADD;
1230 } else if ( ps_type == LDAP_PSEARCH_BY_SCOPEOUT ) {
1231 entry_sync_state = LDAP_SYNC_DELETE;
1233 rs->sr_err = LDAP_OTHER;
1236 if ( sop->o_sync_slog_size != -1 ) {
1237 if ( entry_sync_state == LDAP_SYNC_DELETE ) {
1238 result = slap_add_session_log( op, sop, e );
1243 struct berval cookie;
1244 slap_compose_sync_cookie( sop, &cookie,
1246 sop->o_sync_state.sid );
1247 rs->sr_err = slap_build_sync_state_ctrl( sop,
1248 rs, e, entry_sync_state, ctrls,
1249 num_ctrls++, 1, &cookie );
1250 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1251 rs->sr_attrs = attrs;
1252 rs->sr_ctrls = ctrls;
1253 result = send_search_entry( sop, rs );
1254 if ( cookie.bv_val )
1255 ch_free( cookie.bv_val );
1256 sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
1258 sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1259 ctrls[num_ctrls] = NULL;
1260 rs->sr_ctrls = NULL;
1262 } else if ( ps_type == LDAP_PSEARCH_BY_PREMODIFY ) {
1263 struct psid_entry* psid_e;
1264 psid_e = (struct psid_entry *) ch_calloc (1,
1265 sizeof(struct psid_entry));
1266 psid_e->ps_op = sop;
1267 LDAP_LIST_INSERT_HEAD( &op->o_pm_list,
1272 LDAP_LOG ( OPERATION, RESULTS,
1273 "bdb_search: invalid ps_type (%d) \n",
1276 Debug( LDAP_DEBUG_TRACE,
1277 "bdb_search: invalid ps_type (%d) \n",
1282 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1284 if ( rc_sync == LDAP_COMPARE_TRUE ) { /* ADD */
1285 rs->sr_err = slap_build_sync_state_ctrl( sop,
1286 rs, e, entry_sync_state, ctrls,
1287 num_ctrls++, 0, NULL );
1288 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1289 rs->sr_ctrls = ctrls;
1290 rs->sr_attrs = sop->oq_search.rs_attrs;
1291 result = send_search_entry( sop, rs );
1292 sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
1294 sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1295 ctrls[num_ctrls] = NULL;
1296 rs->sr_ctrls = NULL;
1297 } else { /* PRESENT */
1298 if ( sync_send_present_mode ) {
1299 result = slap_build_syncUUID_set( sop,
1301 if ( result <= 0 ) {
1305 if ( syncUUID_set_cnt == SLAP_SYNCUUID_SET_SIZE ) {
1306 rs->sr_err = LDAP_SUCCESS;
1307 rs->sr_rspoid = LDAP_SYNC_INFO;
1308 rs->sr_ctrls = NULL;
1309 result = slap_send_syncinfo( sop, rs,
1310 LDAP_TAG_SYNC_ID_SET,
1311 NULL, 0, syncUUID_set, 0 );
1312 if ( result != LDAP_SUCCESS )
1314 ber_bvarray_free_x( syncUUID_set,
1316 syncUUID_set = NULL;
1317 syncUUID_set_cnt = 0;
1325 rs->sr_attrs = sop->oq_search.rs_attrs;
1326 rs->sr_ctrls = NULL;
1327 result = send_search_entry( sop, rs );
1332 case 0: /* entry sent ok */
1334 case 1: /* entry not sent */
1336 case -1: /* connection closed */
1338 bdb_cache_return_entry_r(bdb->bi_dbenv,
1339 &bdb->bi_cache, e, &lock);
1341 rs->sr_entry = NULL;
1342 rs->sr_err = LDAP_OTHER;
1348 LDAP_LOG ( OPERATION, RESULTS,
1349 "bdb_search: %ld does not match filter\n", (long) id, 0, 0);
1351 Debug( LDAP_DEBUG_TRACE,
1352 "bdb_search: %ld does not match filter\n",
1359 /* free reader lock */
1361 bdb_cache_return_entry_r( bdb->bi_dbenv,
1362 &bdb->bi_cache, e , &lock );
1363 if ( sop->o_nocaching ) {
1364 bdb_cache_delete_entry( bdb, ei, locker, &lock );
1368 rs->sr_entry = NULL;
1371 ldap_pvt_thread_yield();
1374 if ( syncUUID_set_cnt > 0 ) {
1375 rs->sr_err = LDAP_SUCCESS;
1376 rs->sr_rspoid = LDAP_SYNC_INFO;
1377 rs->sr_ctrls = NULL;
1378 slap_send_syncinfo( sop, rs, LDAP_TAG_SYNC_ID_SET,
1379 NULL, 0, syncUUID_set, 0 );
1380 ber_bvarray_free_x( syncUUID_set, sop->o_tmpmemctx );
1381 syncUUID_set_cnt = 0;
1386 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1387 if ( sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
1388 struct berval cookie;
1389 slap_compose_sync_cookie( sop, &cookie,
1391 sop->o_sync_state.sid );
1393 if ( sync_send_present_mode ) {
1394 rs->sr_err = LDAP_SUCCESS;
1395 rs->sr_rspoid = LDAP_SYNC_INFO;
1396 rs->sr_ctrls = NULL;
1397 slap_send_syncinfo( sop, rs,
1398 LDAP_TAG_SYNC_REFRESH_PRESENT, &cookie, 1, NULL, 0 );
1400 if ( !no_sync_state_change ) {
1402 ldap_pvt_thread_mutex_lock( &bdb->bi_pslist_mutex );
1403 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
1404 if ( ps_list->o_sync_slog_size > 0 ) {
1405 if ( ps_list->o_sync_state.sid == sop->o_sync_state.sid ) {
1413 rs->sr_err = LDAP_SUCCESS;
1414 rs->sr_rspoid = NULL;
1415 rs->sr_ctrls = NULL;
1416 slap_send_session_log( op, ps_list, rs );
1418 ldap_pvt_thread_mutex_unlock( &bdb->bi_pslist_mutex );
1420 rs->sr_err = LDAP_SUCCESS;
1421 rs->sr_rspoid = LDAP_SYNC_INFO;
1422 rs->sr_ctrls = NULL;
1423 slap_send_syncinfo( sop, rs,
1424 LDAP_TAG_SYNC_REFRESH_DELETE, &cookie, 1, NULL, 0 );
1427 if ( cookie.bv_val ) {
1428 ch_free( cookie.bv_val );
1431 /* refreshOnly mode */
1432 struct berval cookie;
1433 slap_compose_sync_cookie( sop, &cookie,
1435 sop->o_sync_state.sid );
1437 if ( sync_send_present_mode ) {
1438 slap_build_sync_done_ctrl( sop, rs, ctrls,
1439 num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_PRESENTS );
1441 if ( !no_sync_state_change ) {
1443 ldap_pvt_thread_mutex_lock( &bdb->bi_pslist_mutex );
1444 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
1446 if ( ps_list->o_sync_slog_size > 0 ) {
1447 if ( ps_list->o_sync_state.sid ==
1448 sop->o_sync_state.sid ) {
1456 slap_send_session_log( op, ps_list, rs );
1458 ldap_pvt_thread_mutex_unlock( &bdb->bi_pslist_mutex );
1460 slap_build_sync_done_ctrl( sop, rs, ctrls,
1461 num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_DELETES );
1464 rs->sr_ctrls = ctrls;
1465 rs->sr_ref = rs->sr_v2ref;
1466 rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
1467 rs->sr_rspoid = NULL;
1468 send_ldap_result( sop, rs );
1469 if ( ctrls[num_ctrls-1]->ldctl_value.bv_val != NULL ) {
1470 sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val, sop->o_tmpmemctx );
1472 sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1473 ctrls[num_ctrls] = NULL;
1474 if ( cookie.bv_val )
1475 ch_free( cookie.bv_val );
1478 rs->sr_ctrls = NULL;
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 );
1486 rs->sr_err = LDAP_SUCCESS;
1489 if( !IS_PSEARCH && e != NULL ) {
1490 /* free reader lock */
1491 bdb_cache_return_entry_r ( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
1494 LOCK_ID_FREE (bdb->bi_dbenv, locker );
1496 ber_bvfree( search_context_csn );
1498 if( rs->sr_v2ref ) {
1499 ber_bvarray_free( rs->sr_v2ref );
1500 rs->sr_v2ref = NULL;
1502 if( realbase.bv_val ) ch_free( realbase.bv_val );
1508 static int base_candidate(
1514 LDAP_LOG ( OPERATION, ENTRY,
1515 "base_candidate: base: \"%s\" (0x%08lx)\n",
1516 e->e_nname.bv_val, (long) e->e_id, 0);
1518 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
1519 e->e_nname.bv_val, (long) e->e_id, 0);
1527 /* Look for "objectClass Present" in this filter.
1528 * Also count depth of filter tree while we're at it.
1530 static int oc_filter(
1538 if( cur > *max ) *max = cur;
1540 switch(f->f_choice) {
1541 case LDAP_FILTER_PRESENT:
1542 if (f->f_desc == slap_schema.si_ad_objectClass) {
1547 case LDAP_FILTER_AND:
1548 case LDAP_FILTER_OR:
1550 for (f=f->f_and; f; f=f->f_next) {
1551 (void) oc_filter(f, cur, max);
1561 static void search_stack_free( void *key, void *data )
1563 ber_memfree_x(data, NULL);
1566 static void *search_stack(
1570 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1573 if ( op->o_threadctx ) {
1574 ldap_pvt_thread_pool_getkey( op->o_threadctx, search_stack,
1577 ret = bdb->bi_search_stack;
1581 ret = ch_malloc( bdb->bi_search_stack_depth * BDB_IDL_UM_SIZE
1583 if ( op->o_threadctx ) {
1584 ldap_pvt_thread_pool_setkey( op->o_threadctx, search_stack,
1585 ret, search_stack_free );
1587 bdb->bi_search_stack = ret;
1593 static int search_candidates(
1602 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1604 Filter f, rf, xf, nf;
1606 AttributeAssertion aa_ref;
1607 #ifdef BDB_SUBENTRIES
1609 AttributeAssertion aa_subentry;
1613 * This routine takes as input a filter (user-filter)
1614 * and rewrites it as follows:
1615 * (&(scope=DN)[(objectClass=subentry)]
1616 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
1620 LDAP_LOG ( OPERATION, ENTRY,
1621 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1622 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope);
1624 Debug(LDAP_DEBUG_TRACE,
1625 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1626 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope );
1629 xf.f_or = op->oq_search.rs_filter;
1630 xf.f_choice = LDAP_FILTER_OR;
1633 /* If the user's filter uses objectClass=*,
1634 * these clauses are redundant.
1636 if (!oc_filter(op->oq_search.rs_filter, 1, &depth)
1637 && !get_subentries_visibility(op)
1638 && !is_sync_protocol(op) )
1640 if( !get_manageDSAit(op) && !get_domainScope(op) ) {
1641 /* match referral objects */
1642 struct berval bv_ref = { sizeof("referral")-1, "referral" };
1643 rf.f_choice = LDAP_FILTER_EQUALITY;
1645 rf.f_av_desc = slap_schema.si_ad_objectClass;
1646 rf.f_av_value = bv_ref;
1647 rf.f_next = xf.f_or;
1654 f.f_choice = LDAP_FILTER_AND;
1656 /* Dummy; we compute scope separately now */
1657 nf.f_choice = SLAPD_FILTER_COMPUTED;
1658 nf.f_result = LDAP_SUCCESS;
1659 nf.f_next = xf.f_or == op->oq_search.rs_filter
1660 ? op->oq_search.rs_filter : &xf ;
1661 /* Filter depth increased again, adding dummy clause */
1664 #ifdef BDB_SUBENTRIES
1665 if( get_subentries_visibility( op ) ) {
1666 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1667 sf.f_choice = LDAP_FILTER_EQUALITY;
1668 sf.f_ava = &aa_subentry;
1669 sf.f_av_desc = slap_schema.si_ad_objectClass;
1670 sf.f_av_value = bv_subentry;
1671 sf.f_next = nf.f_next;
1676 /* Allocate IDL stack, plus 1 more for former tmp */
1677 if ( depth+1 > bdb->bi_search_stack_depth ) {
1678 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1680 stack = search_stack( stackop );
1683 if( op->ors_deref & LDAP_DEREF_SEARCHING ) {
1684 rc = search_aliases( op, rs, e, locker, ids, scopes, stack );
1686 rc = bdb_dn2idl( op, e, ids, stack );
1689 if ( rc == LDAP_SUCCESS ) {
1690 rc = bdb_filter_candidates( op, &f, ids,
1691 stack, stack+BDB_IDL_UM_SIZE );
1694 if ( depth+1 > bdb->bi_search_stack_depth ) {
1700 LDAP_LOG ( OPERATION, DETAIL1,
1701 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1703 Debug(LDAP_DEBUG_TRACE,
1704 "bdb_search_candidates: failed (rc=%d)\n",
1710 LDAP_LOG ( OPERATION, DETAIL1,
1711 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1712 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1713 (long) BDB_IDL_LAST(ids));
1715 Debug(LDAP_DEBUG_TRACE,
1716 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1718 (long) BDB_IDL_FIRST(ids),
1719 (long) BDB_IDL_LAST(ids) );
1726 #ifdef LDAP_CONTROL_PAGEDRESULTS
1728 send_pagerequest_response(
1734 LDAPControl ctrl, *ctrls[2];
1735 BerElementBuffer berbuf;
1736 BerElement *ber = (BerElement *)&berbuf;
1737 struct berval cookie = { 0, NULL };
1738 PagedResultsCookie respcookie;
1741 LDAP_LOG ( OPERATION, ENTRY,
1742 "send_pagerequest_response: lastid: (0x%08lx) "
1743 "nentries: (0x%081x)\n",
1744 lastid, rs->sr_nentries, NULL );
1746 Debug(LDAP_DEBUG_ARGS, "send_pagerequest_response: lastid: (0x%08lx) "
1747 "nentries: (0x%081x)\n", lastid, rs->sr_nentries, NULL );
1750 ctrl.ldctl_value.bv_val = NULL;
1754 ber_init2( ber, NULL, LBER_USE_DER );
1756 respcookie = ( PagedResultsCookie )lastid;
1757 op->o_conn->c_pagedresults_state.ps_cookie = respcookie;
1758 cookie.bv_len = sizeof( respcookie );
1759 cookie.bv_val = (char *)&respcookie;
1762 * FIXME: we should consider sending an estimate of the entries
1763 * left, after appropriate security check is done
1765 ber_printf( ber, "{iO}", tentries, &cookie );
1767 if ( ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 ) == -1 ) {
1771 ctrls[0]->ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
1772 ctrls[0]->ldctl_iscritical = 0;
1774 rs->sr_ctrls = ctrls;
1775 rs->sr_err = LDAP_SUCCESS;
1776 send_ldap_result( op, rs );
1779 (void) ber_free_buf( ber );