1 /* search.c - search operation */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
26 static int base_candidate(
31 static int search_candidates(
32 Operation *stackop, /* op with the current threadctx/slab cache */
33 Operation *sop, /* search op */
40 static void send_pagerequest_response(
46 /* Dereference aliases for a single alias entry. Return the final
47 * dereferenced entry on success, NULL on any failure.
49 static Entry * deref_base (
59 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
64 rs->sr_err = LDAP_ALIAS_DEREF_PROBLEM;
65 rs->sr_text = "maximum deref depth exceeded";
67 while (BDB_IDL_N(tmp) < op->o_bd->be_max_deref_depth) {
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 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 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 /* For persistent searches, op is the currently executing operation,
365 * sop is the persistent search. For regular searches, sop = op.
368 bdb_do_search( Operation *op, SlapReply *rs, Operation *sop,
369 Entry *ps_e, int ps_type )
371 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
374 ID candidates[BDB_IDL_UM_SIZE];
375 ID scopes[BDB_IDL_DB_SIZE];
376 Entry *e = NULL, base, e_root = {0};
377 Entry *matched = NULL;
378 EntryInfo *ei, ei_root = {0};
379 struct berval realbase = BER_BVNULL;
383 AttributeName *attrs;
385 Filter contextcsnand, contextcsnle, cookief, csnfnot,
386 csnfeq, csnfand, csnfge;
387 AttributeAssertion aa_ge, aa_eq, aa_le;
388 struct berval *search_context_csn = NULL;
390 LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
392 AttributeName uuid_attr[2];
394 int entry_sync_state = -1;
395 AttributeName null_attr;
396 int no_sync_state_change = 0;
398 u_int32_t locker = 0;
402 int sync_send_present_mode = 1;
408 BerVarray syncUUID_set = NULL;
409 int syncUUID_set_cnt = 0;
412 LDAP_LOG( OPERATION, ENTRY, "bdb_search\n", 0, 0, 0 );
414 Debug( LDAP_DEBUG_TRACE, "=> bdb_search\n",
417 attrs = sop->oq_search.rs_attrs;
419 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST ) {
420 struct slap_session_entry *sent;
421 if ( sop->o_sync_state.sid >= 0 ) {
422 LDAP_LIST_FOREACH( sent, &bdb->bi_session_list, se_link ) {
423 if ( sent->se_id == sop->o_sync_state.sid ) {
424 sop->o_sync_slog_size = sent->se_size;
431 /* psearch needs to be registered before refresh begins */
432 /* psearch and refresh transmission is serialized in send_ldap_ber() */
433 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
434 ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
435 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
436 ldap_pvt_thread_rdwr_wunlock( &bdb->bi_pslist_rwlock );
438 } else if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH_AND_PERSIST
439 && sop->o_sync_slog_size >= 0 )
441 ldap_pvt_thread_rdwr_wlock( &bdb->bi_pslist_rwlock );
442 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
443 if ( ps_list->o_sync_slog_size >= 0 ) {
444 if ( ps_list->o_sync_state.sid == sop->o_sync_state.sid ) {
452 if ( ps_list->o_sync_slog_omitcsn.bv_len != 0 ) {
453 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
454 if ( sop->o_sync_state.ctxcsn &&
455 sop->o_sync_state.ctxcsn->bv_val != NULL )
457 value_match( &match, slap_schema.si_ad_entryCSN, mr,
458 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
459 sop->o_sync_state.ctxcsn,
460 &ps_list->o_sync_slog_omitcsn,
466 sync_send_present_mode = 0;
469 sync_send_present_mode = 0;
471 } else if ( sop->o_sync_slog_size >= 0 ) {
472 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
474 sop->o_sync_state.sid = -1;
476 ldap_pvt_thread_rdwr_wunlock( &bdb->bi_pslist_rwlock );
479 null_attr.an_desc = NULL;
480 null_attr.an_oc = NULL;
481 null_attr.an_oc_exclude = 0;
482 null_attr.an_name.bv_len = 0;
483 null_attr.an_name.bv_val = NULL;
485 for( num_ctrls = 0; num_ctrls < SLAP_MAX_RESPONSE_CONTROLS; num_ctrls++ ) {
486 ctrls[num_ctrls] = NULL;
490 if ( IS_PSEARCH && IS_BDB_REPLACE(ps_type)) {
492 attrs[0].an_desc = NULL;
493 attrs[0].an_oc = NULL;
494 attrs[0].an_oc_exclude = 0;
495 attrs[0].an_name.bv_len = 0;
496 attrs[0].an_name.bv_val = NULL;
499 manageDSAit = get_manageDSAit( sop );
501 /* Sync control overrides manageDSAit */
502 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
503 if ( manageDSAit == SLAP_NO_CONTROL ) {
504 manageDSAit = SLAP_CRITICAL_CONTROL;
506 } else if ( IS_PSEARCH ) {
507 if ( manageDSAit == SLAP_NO_CONTROL ) {
508 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 ei_root.bei_e = &e_root;
525 ei_root.bei_parent = &ei_root;
526 e_root.e_private = &ei_root;
529 rs->sr_err = LDAP_SUCCESS;
532 /* get entry with reader lock */
533 rs->sr_err = bdb_dn2entry( op, NULL, &sop->o_req_ndn, &ei,
545 send_ldap_error( sop, rs, LDAP_BUSY, "ldap server busy" );
546 LOCK_ID_FREE (bdb->bi_dbenv, locker );
548 case DB_LOCK_DEADLOCK:
549 case DB_LOCK_NOTGRANTED:
552 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
553 LOCK_ID_FREE (bdb->bi_dbenv, locker );
557 if ( e && (op->ors_deref & LDAP_DEREF_FINDING) && is_entry_alias(e) ) {
558 BDB_IDL_ZERO(candidates);
559 e = deref_base( op, rs, e, &matched, locker, &lock,
564 struct berval matched_dn = BER_BVNULL;
566 if ( matched != NULL ) {
568 ber_dupbv( &matched_dn, &matched->e_name );
570 erefs = is_entry_referral( matched )
571 ? get_entry_referrals( op, matched )
574 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
579 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
580 &sop->o_req_dn, sop->oq_search.rs_scope );
581 ber_bvarray_free( erefs );
585 rs->sr_ref = referral_rewrite( default_referral,
586 NULL, &sop->o_req_dn, sop->oq_search.rs_scope );
589 rs->sr_err = LDAP_REFERRAL;
590 rs->sr_matched = matched_dn.bv_val;
591 send_ldap_result( sop, rs );
593 LOCK_ID_FREE (bdb->bi_dbenv, locker );
595 ber_bvarray_free( rs->sr_ref );
598 if ( matched_dn.bv_val ) {
599 ber_memfree( matched_dn.bv_val );
600 rs->sr_matched = NULL;
605 if ( !manageDSAit && e != &e_root && is_entry_referral( e ) ) {
606 /* entry is a referral, don't allow add */
607 struct berval matched_dn;
610 ber_dupbv( &matched_dn, &e->e_name );
611 erefs = get_entry_referrals( op, e );
613 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
617 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
618 &sop->o_req_dn, sop->oq_search.rs_scope );
619 ber_bvarray_free( erefs );
623 LDAP_LOG ( OPERATION, RESULTS,
624 "bdb_search: entry is referral\n", 0, 0, 0 );
626 Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
630 if (!rs->sr_ref) rs->sr_text = "bad_referral object";
631 rs->sr_err = LDAP_REFERRAL;
632 rs->sr_matched = matched_dn.bv_val;
633 send_ldap_result( sop, rs );
635 LOCK_ID_FREE (bdb->bi_dbenv, locker );
636 ber_bvarray_free( rs->sr_ref );
638 ber_memfree( matched_dn.bv_val );
639 rs->sr_matched = NULL;
643 if ( get_assert( op ) &&
644 ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
646 rs->sr_err = LDAP_ASSERTION_FAILED;
647 send_ldap_result( sop, rs );
651 /* compute it anyway; root does not use it */
652 stoptime = op->o_time + sop->ors_tlimit;
654 /* need normalized dn below */
655 ber_dupbv( &realbase, &e->e_nname );
657 /* Copy info to base, must free entry before accessing the database
658 * in search_candidates, to avoid deadlocks.
660 base.e_private = e->e_private;
661 base.e_nname = realbase;
664 if ( e != &e_root ) {
665 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
670 rs->sr_err = bdb_get_commit_csn( sop, rs, &search_context_csn,
671 locker, &ctxcsn_lock );
673 if ( rs->sr_err != LDAP_SUCCESS ) {
674 send_ldap_error( sop, rs, rs->sr_err,
675 "error in csn management in search" );
679 if ( sop->o_sync_mode != SLAP_SYNC_NONE &&
680 sop->o_sync_state.ctxcsn &&
681 sop->o_sync_state.ctxcsn->bv_val &&
682 ber_bvcmp( &sop->o_sync_state.ctxcsn[0], search_context_csn ) == 0 )
684 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
688 search_context_csn = ber_dupbv( NULL, &op->o_sync_csn );
691 /* select candidates */
692 if ( sop->oq_search.rs_scope == LDAP_SCOPE_BASE ) {
693 rs->sr_err = base_candidate( op->o_bd, &base, candidates );
696 BDB_IDL_ZERO( candidates );
697 BDB_IDL_ZERO( scopes );
698 rs->sr_err = search_candidates( op, sop, rs, &base,
699 locker, candidates, scopes );
702 if ( !IS_PSEARCH && sop->o_sync_mode != SLAP_SYNC_NONE ) {
703 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
706 /* start cursor at beginning of candidates.
710 if ( !BDB_IDL_IS_RANGE( candidates ) ) {
711 cursor = bdb_idl_search( candidates, ps_e->e_id );
712 if ( candidates[cursor] != ps_e->e_id ) {
713 rs->sr_err = LDAP_SUCCESS;
716 } else if ( ps_e->e_id < BDB_IDL_RANGE_FIRST( candidates ) ||
717 ps_e->e_id > BDB_IDL_RANGE_LAST( candidates ))
719 rs->sr_err = LDAP_SUCCESS;
723 candidates[1] = ps_e->e_id;
726 if ( candidates[0] == 0 ) {
728 LDAP_LOG ( OPERATION, RESULTS,
729 "bdb_search: no candidates\n", 0, 0, 0 );
731 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
738 /* if not root and candidates exceed to-be-checked entries, abort */
739 if ( sop->ors_limit /* isroot == TRUE */
740 && sop->ors_limit->lms_s_unchecked != -1
741 && BDB_IDL_N(candidates) > (unsigned) sop->ors_limit->lms_s_unchecked )
743 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
744 send_ldap_result( sop, rs );
745 rs->sr_err = LDAP_SUCCESS;
749 if ( sop->ors_limit == NULL /* isroot == FALSE */
750 || !sop->ors_limit->lms_s_pr_hide ) {
751 tentries = BDB_IDL_N(candidates);
754 if ( get_pagedresults(sop) ) {
755 if ( sop->o_pagedresults_state.ps_cookie == 0 ) {
759 if ( sop->o_pagedresults_size == 0 ) {
760 rs->sr_err = LDAP_SUCCESS;
761 rs->sr_text = "search abandoned by pagedResult size=0";
762 send_ldap_result( sop, rs );
765 for ( id = bdb_idl_first( candidates, &cursor );
766 id != NOID && id <= (ID)( sop->o_pagedresults_state.ps_cookie );
767 id = bdb_idl_next( candidates, &cursor ) ) /* empty */;
769 if ( cursor == NOID ) {
771 LDAP_LOG ( OPERATION, RESULTS,
772 "bdb_search: no paged results candidates\n",
775 Debug( LDAP_DEBUG_TRACE,
776 "bdb_search: no paged results candidates\n",
779 send_pagerequest_response( sop, rs, lastid, 0 );
781 rs->sr_err = LDAP_OTHER;
787 if (( sop->o_sync_mode & SLAP_SYNC_REFRESH ) || IS_PSEARCH ) {
790 cookief.f_choice = LDAP_FILTER_AND;
791 cookief.f_and = &csnfnot;
792 cookief.f_next = NULL;
794 csnfnot.f_choice = LDAP_FILTER_NOT;
795 csnfnot.f_not = &csnfeq;
796 csnfnot.f_next = &csnfand;
798 csnfeq.f_choice = LDAP_FILTER_EQUALITY;
799 csnfeq.f_ava = &aa_eq;
800 csnfeq.f_av_desc = slap_schema.si_ad_entryCSN;
801 if ( sop->o_sync_state.ctxcsn != NULL ) {
802 csnfeq.f_av_value = *sop->o_sync_state.ctxcsn;
804 csnfeq.f_av_value = slap_empty_bv;
807 csnfand.f_choice = LDAP_FILTER_AND;
808 csnfand.f_and = &csnfge;
809 csnfand.f_next = NULL;
811 csnfge.f_choice = LDAP_FILTER_GE;
812 csnfge.f_ava = &aa_ge;
813 csnfge.f_av_desc = slap_schema.si_ad_entryCSN;
814 if ( sop->o_sync_state.ctxcsn != NULL ) {
815 csnfge.f_av_value = *sop->o_sync_state.ctxcsn;
817 csnfge.f_av_value = slap_empty_bv;
820 if ( search_context_csn && !IS_PSEARCH ) {
821 csnfge.f_next = &contextcsnand;
823 contextcsnand.f_choice = LDAP_FILTER_AND;
824 contextcsnand.f_and = &contextcsnle;
825 contextcsnand.f_next = NULL;
827 contextcsnle.f_choice = LDAP_FILTER_LE;
828 contextcsnle.f_ava = &aa_le;
829 contextcsnle.f_av_desc = slap_schema.si_ad_entryCSN;
830 contextcsnle.f_av_value = *search_context_csn;
831 contextcsnle.f_next = sop->oq_search.rs_filter;
833 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
834 if ( sop->o_sync_state.ctxcsn &&
835 sop->o_sync_state.ctxcsn->bv_val != NULL )
837 value_match( &match, slap_schema.si_ad_entryCSN, mr,
838 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
839 &sop->o_sync_state.ctxcsn[0], search_context_csn,
844 no_sync_state_change = ( match >= 0 );
846 csnfge.f_next = sop->oq_search.rs_filter;
850 for ( id = bdb_idl_first( candidates, &cursor );
851 id != NOID && !no_sync_state_change;
852 id = bdb_idl_next( candidates, &cursor ) )
857 /* check for abandon */
858 if ( sop->o_abandon ) {
860 bdb_drop_psearch( sop, sop->o_msgid );
862 rs->sr_err = LDAP_SUCCESS;
866 if ( sop->o_cancel ) {
867 assert( sop->o_cancel == SLAP_CANCEL_REQ );
868 rs->sr_err = LDAP_CANCELLED;
869 send_ldap_result( sop, rs );
870 sop->o_cancel = SLAP_CANCEL_ACK;
871 rs->sr_err = LDAP_SUCCESS;
875 /* check time limit */
876 if ( sop->ors_tlimit != -1 && slap_get_time() > stoptime ) {
877 rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
878 rs->sr_ref = rs->sr_v2ref;
879 send_ldap_result( sop, rs );
880 rs->sr_err = LDAP_SUCCESS;
886 /* get the entry with reader lock */
888 rs->sr_err = bdb_cache_find_id( op, NULL,
889 id, &ei, 0, locker, &lock );
891 if (rs->sr_err == LDAP_BUSY) {
892 rs->sr_text = "ldap server busy";
893 send_ldap_result( sop, rs );
896 } else if ( rs->sr_err == DB_LOCK_DEADLOCK
897 || rs->sr_err == DB_LOCK_NOTGRANTED )
902 if ( ei && rs->sr_err == LDAP_SUCCESS ) {
909 if( !BDB_IDL_IS_RANGE(candidates) ) {
910 /* only complain for non-range IDLs */
912 LDAP_LOG ( OPERATION, RESULTS,
913 "bdb_search: candidate %ld not found\n",
916 Debug( LDAP_DEBUG_TRACE,
917 "bdb_search: candidate %ld not found\n",
930 #ifdef BDB_SUBENTRIES
931 /* FIXME: send all but syncrepl */
933 if ( !is_sync_protocol( sop ) )
936 if ( is_entry_subentry( e ) ) {
937 if( sop->oq_search.rs_scope != LDAP_SCOPE_BASE ) {
938 if(!get_subentries_visibility( sop )) {
939 /* only subentries are visible */
943 } else if ( get_subentries( sop ) &&
944 !get_subentries_visibility( sop ))
946 /* only subentries are visible */
950 } else if ( get_subentries_visibility( sop )) {
951 /* only subentries are visible */
955 #endif /* BDB_SUBENTRIES */
957 /* Does this candidate actually satisfy the search scope?
959 * Note that we don't lock access to the bei_parent pointer.
960 * Since only leaf nodes can be deleted, the parent of any
961 * node will always be a valid node. Also since we have
962 * a Read lock on the data, it cannot be renamed out of the
963 * scope while we are looking at it, and unless we're using
964 * BDB_HIER, its parents cannot be moved either.
966 switch( sop->ors_scope ) {
967 case LDAP_SCOPE_BASE:
968 /* This is always true, yes? */
969 if ( id == base.e_id ) scopeok = 1;
972 case LDAP_SCOPE_ONELEVEL:
973 if ( ei->bei_parent->bei_id == base.e_id ) scopeok = 1;
976 #ifdef LDAP_SCOPE_CHILDREN
977 case LDAP_SCOPE_CHILDREN:
978 if ( id == base.e_id ) break;
981 case LDAP_SCOPE_SUBTREE: {
983 for (tmp = BEI(e); tmp->bei_parent;
984 tmp = tmp->bei_parent ) {
985 if ( tmp->bei_id == base.e_id ) {
994 /* aliases were already dereferenced in candidate list */
995 if ( sop->ors_deref & LDAP_DEREF_SEARCHING ) {
996 /* but if the search base is an alias, and we didn't
997 * deref it when finding, return it.
999 if ( is_entry_alias(e) &&
1000 ((sop->ors_deref & LDAP_DEREF_FINDING) ||
1001 !bvmatch(&e->e_nname, &op->o_req_ndn)))
1006 /* scopes is only non-empty for onelevel or subtree */
1007 if ( !scopeok && BDB_IDL_N(scopes) ) {
1009 if ( sop->ors_scope == LDAP_SCOPE_ONELEVEL ) {
1010 x = bdb_idl_search( scopes, e->e_id );
1011 if ( scopes[x] == e->e_id ) scopeok = 1;
1013 /* subtree, walk up the tree */
1014 EntryInfo *tmp = BEI(e);
1015 for (;tmp->bei_parent; tmp=tmp->bei_parent) {
1016 x = bdb_idl_search( scopes, tmp->bei_id );
1017 if ( scopes[x] == tmp->bei_id ) {
1027 /* Not in scope, ignore it */
1030 LDAP_LOG ( OPERATION, RESULTS,
1031 "bdb_search: %ld scope not okay\n",
1034 Debug( LDAP_DEBUG_TRACE,
1035 "bdb_search: %ld scope not okay\n",
1042 * if it's a referral, add it to the list of referrals. only do
1043 * this for non-base searches, and don't check the filter
1044 * explicitly here since it's only a candidate anyway.
1046 if ( !manageDSAit && sop->oq_search.rs_scope != LDAP_SCOPE_BASE
1047 && is_entry_referral( e ) )
1049 BerVarray erefs = get_entry_referrals( sop, e );
1050 rs->sr_ref = referral_rewrite( erefs, &e->e_name, NULL,
1051 sop->oq_search.rs_scope == LDAP_SCOPE_ONELEVEL
1052 ? LDAP_SCOPE_BASE : LDAP_SCOPE_SUBTREE );
1054 send_search_reference( sop, rs );
1056 ber_bvarray_free( rs->sr_ref );
1057 ber_bvarray_free( erefs );
1063 if ( !manageDSAit && is_entry_glue( e )) {
1067 /* if it matches the filter and scope, send it */
1069 if (ps_type != LDAP_PSEARCH_BY_SCOPEOUT) {
1070 rs->sr_err = test_filter( sop, rs->sr_entry, &cookief );
1072 rs->sr_err = LDAP_COMPARE_TRUE;
1075 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1076 rc_sync = test_filter( sop, rs->sr_entry, &cookief );
1077 rs->sr_err = test_filter( sop, rs->sr_entry, &contextcsnand );
1078 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1079 if ( rc_sync == LDAP_COMPARE_TRUE ) {
1080 if ( no_sync_state_change ) {
1082 LDAP_LOG ( OPERATION, RESULTS,
1083 "bdb_search: error in context csn management\n",
1086 Debug( LDAP_DEBUG_TRACE,
1087 "bdb_search: error in context csn management\n",
1091 entry_sync_state = LDAP_SYNC_ADD;
1093 if ( no_sync_state_change ) {
1096 entry_sync_state = LDAP_SYNC_PRESENT;
1100 rs->sr_err = test_filter( sop,
1101 rs->sr_entry, sop->oq_search.rs_filter );
1105 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1106 /* check size limit */
1107 if ( --sop->ors_slimit == -1 &&
1108 sop->o_sync_slog_size == -1 )
1111 bdb_cache_return_entry_r( bdb->bi_dbenv,
1112 &bdb->bi_cache, e, &lock );
1115 rs->sr_entry = NULL;
1116 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
1117 rs->sr_ref = rs->sr_v2ref;
1118 send_ldap_result( sop, rs );
1119 rs->sr_err = LDAP_SUCCESS;
1123 if ( get_pagedresults(sop) ) {
1124 if ( sop->ors_limit /* isroot == TRUE */
1125 && sop->ors_limit->lms_s_pr_total > 0
1126 && sop->ors_limit->lms_s_pr_total <= rs->sr_nentries + sop->o_pagedresults_state.ps_count ) {
1128 bdb_cache_return_entry_r( bdb->bi_dbenv,
1129 &bdb->bi_cache, e, &lock );
1132 rs->sr_entry = NULL;
1133 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
1134 rs->sr_ref = rs->sr_v2ref;
1135 send_ldap_result( sop, rs );
1136 rs->sr_err = LDAP_SUCCESS;
1140 if ( rs->sr_nentries >= sop->o_pagedresults_size ) {
1141 send_pagerequest_response( sop, rs,
1153 int premodify_found = 0;
1154 int entry_sync_state;
1156 if ( ps_type == LDAP_PSEARCH_BY_ADD ||
1157 ps_type == LDAP_PSEARCH_BY_DELETE ||
1158 ps_type == LDAP_PSEARCH_BY_MODIFY ||
1159 ps_type == LDAP_PSEARCH_BY_SCOPEOUT )
1161 if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1162 struct psid_entry* psid_e;
1163 LDAP_LIST_FOREACH( psid_e,
1164 &op->o_pm_list, ps_link)
1166 if( psid_e->ps_op == sop ) {
1167 premodify_found = 1;
1168 LDAP_LIST_REMOVE(psid_e, ps_link);
1172 if (psid_e != NULL) free (psid_e);
1174 if ( ps_type == LDAP_PSEARCH_BY_ADD ) {
1175 entry_sync_state = LDAP_SYNC_ADD;
1176 } else if ( ps_type == LDAP_PSEARCH_BY_DELETE ) {
1177 entry_sync_state = LDAP_SYNC_DELETE;
1178 } else if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1179 if ( premodify_found ) {
1180 entry_sync_state = LDAP_SYNC_MODIFY;
1182 entry_sync_state = LDAP_SYNC_ADD;
1184 } else if ( ps_type == LDAP_PSEARCH_BY_SCOPEOUT ) {
1185 entry_sync_state = LDAP_SYNC_DELETE;
1187 rs->sr_err = LDAP_OTHER;
1190 if ( sop->o_sync_slog_size != -1 ) {
1191 if ( entry_sync_state == LDAP_SYNC_DELETE ) {
1192 result = slap_add_session_log( op, sop, e );
1197 struct berval cookie;
1198 slap_compose_sync_cookie( sop, &cookie,
1200 sop->o_sync_state.sid,
1201 sop->o_sync_state.rid );
1202 rs->sr_err = slap_build_sync_state_ctrl( sop,
1203 rs, e, entry_sync_state, ctrls,
1204 num_ctrls++, 1, &cookie );
1205 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1206 rs->sr_attrs = attrs;
1207 rs->sr_ctrls = ctrls;
1209 result = send_search_entry( sop, rs );
1210 if ( cookie.bv_val ) ch_free( cookie.bv_val );
1211 sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
1213 sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1214 ctrls[num_ctrls] = NULL;
1215 rs->sr_ctrls = NULL;
1217 } else if ( ps_type == LDAP_PSEARCH_BY_PREMODIFY ) {
1218 struct psid_entry* psid_e;
1219 psid_e = (struct psid_entry *) ch_calloc(1,
1220 sizeof(struct psid_entry));
1221 psid_e->ps_op = sop;
1222 LDAP_LIST_INSERT_HEAD( &op->o_pm_list,
1227 LDAP_LOG ( OPERATION, RESULTS,
1228 "bdb_search: invalid ps_type (%d) \n",
1231 Debug( LDAP_DEBUG_TRACE,
1232 "bdb_search: invalid ps_type (%d) \n",
1237 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1238 if ( rc_sync == LDAP_COMPARE_TRUE ) { /* ADD */
1239 rs->sr_err = slap_build_sync_state_ctrl( sop,
1240 rs, e, entry_sync_state, ctrls,
1241 num_ctrls++, 0, NULL );
1242 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1243 rs->sr_ctrls = ctrls;
1244 rs->sr_attrs = sop->oq_search.rs_attrs;
1246 result = send_search_entry( sop, rs );
1247 sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
1249 sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1250 ctrls[num_ctrls] = NULL;
1251 rs->sr_ctrls = NULL;
1252 } else { /* PRESENT */
1253 if ( sync_send_present_mode ) {
1254 result = slap_build_syncUUID_set( sop,
1256 if ( result <= 0 ) {
1260 if ( syncUUID_set_cnt ==
1261 SLAP_SYNCUUID_SET_SIZE )
1263 rs->sr_err = LDAP_SUCCESS;
1264 rs->sr_rspoid = LDAP_SYNC_INFO;
1265 rs->sr_ctrls = NULL;
1266 result = slap_send_syncinfo( sop, rs,
1267 LDAP_TAG_SYNC_ID_SET,
1268 NULL, 0, syncUUID_set, 0 );
1269 if ( result != LDAP_SUCCESS ) {
1272 ber_bvarray_free_x( syncUUID_set,
1274 syncUUID_set = NULL;
1275 syncUUID_set_cnt = 0;
1283 rs->sr_attrs = sop->oq_search.rs_attrs;
1284 rs->sr_ctrls = NULL;
1286 rs->sr_err = LDAP_SUCCESS;
1287 result = send_search_entry( sop, rs );
1292 case 0: /* entry sent ok */
1294 case 1: /* entry not sent */
1296 case -1: /* connection closed */
1298 bdb_cache_return_entry_r(bdb->bi_dbenv,
1299 &bdb->bi_cache, e, &lock);
1301 rs->sr_entry = NULL;
1302 rs->sr_err = LDAP_OTHER;
1308 LDAP_LOG ( OPERATION, RESULTS,
1309 "bdb_search: %ld does not match filter\n", (long) id, 0, 0);
1311 Debug( LDAP_DEBUG_TRACE,
1312 "bdb_search: %ld does not match filter\n",
1319 /* free reader lock */
1321 bdb_cache_return_entry_r( bdb->bi_dbenv,
1322 &bdb->bi_cache, e , &lock );
1323 if ( sop->o_nocaching ) {
1324 bdb_cache_delete_entry( bdb, ei, locker, &lock );
1328 rs->sr_entry = NULL;
1331 ldap_pvt_thread_yield();
1334 if ( syncUUID_set_cnt > 0 ) {
1335 rs->sr_err = LDAP_SUCCESS;
1336 rs->sr_rspoid = LDAP_SYNC_INFO;
1337 rs->sr_ctrls = NULL;
1338 slap_send_syncinfo( sop, rs, LDAP_TAG_SYNC_ID_SET,
1339 NULL, 0, syncUUID_set, 0 );
1340 ber_bvarray_free_x( syncUUID_set, sop->o_tmpmemctx );
1341 syncUUID_set_cnt = 0;
1346 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1347 if ( sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
1348 struct berval cookie;
1349 slap_compose_sync_cookie( sop, &cookie, search_context_csn,
1350 sop->o_sync_state.sid, sop->o_sync_state.rid );
1352 if ( sync_send_present_mode ) {
1353 rs->sr_err = LDAP_SUCCESS;
1354 rs->sr_rspoid = LDAP_SYNC_INFO;
1355 rs->sr_ctrls = NULL;
1356 slap_send_syncinfo( sop, rs,
1357 LDAP_TAG_SYNC_REFRESH_PRESENT, &cookie, 1, NULL, 0 );
1359 if ( !no_sync_state_change ) {
1361 ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
1362 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
1365 if ( ps_list->o_sync_slog_size > 0 ) {
1366 if ( ps_list->o_sync_state.sid ==
1367 sop->o_sync_state.sid ) {
1375 rs->sr_err = LDAP_SUCCESS;
1376 rs->sr_rspoid = NULL;
1377 rs->sr_ctrls = NULL;
1378 slap_send_session_log( op, ps_list, rs );
1380 ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
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_DELETE, &cookie, 1, NULL, 0 );
1389 if ( cookie.bv_val ) {
1390 ch_free( cookie.bv_val );
1393 /* refreshOnly mode */
1394 struct berval cookie;
1395 slap_compose_sync_cookie( sop, &cookie, search_context_csn,
1396 sop->o_sync_state.sid, sop->o_sync_state.rid );
1398 if ( sync_send_present_mode ) {
1399 slap_build_sync_done_ctrl( sop, rs, ctrls,
1400 num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_PRESENTS );
1402 if ( !no_sync_state_change ) {
1404 ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
1405 LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list,
1408 if ( ps_list->o_sync_slog_size > 0 ) {
1409 if ( ps_list->o_sync_state.sid ==
1410 sop->o_sync_state.sid ) {
1418 slap_send_session_log( op, ps_list, rs );
1420 ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
1422 slap_build_sync_done_ctrl( sop, rs, ctrls,
1423 num_ctrls++, 1, &cookie, LDAP_SYNC_REFRESH_DELETES );
1426 rs->sr_ctrls = ctrls;
1427 rs->sr_ref = rs->sr_v2ref;
1428 rs->sr_err = (rs->sr_v2ref == NULL)
1429 ? LDAP_SUCCESS : LDAP_REFERRAL;
1430 rs->sr_rspoid = NULL;
1431 send_ldap_result( sop, rs );
1432 if ( ctrls[num_ctrls-1]->ldctl_value.bv_val != NULL ) {
1433 sl_free( ctrls[num_ctrls-1]->ldctl_value.bv_val,
1436 sl_free( ctrls[--num_ctrls], sop->o_tmpmemctx );
1437 ctrls[num_ctrls] = NULL;
1438 if ( cookie.bv_val ) ch_free( cookie.bv_val );
1441 rs->sr_ctrls = NULL;
1442 rs->sr_ref = rs->sr_v2ref;
1443 rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
1444 rs->sr_rspoid = NULL;
1445 send_ldap_result( sop, rs );
1449 rs->sr_err = LDAP_SUCCESS;
1452 if( !IS_PSEARCH && e != NULL ) {
1453 /* free reader lock */
1454 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
1457 LOCK_ID_FREE( bdb->bi_dbenv, locker );
1459 ber_bvfree( search_context_csn );
1461 if( rs->sr_v2ref ) {
1462 ber_bvarray_free( rs->sr_v2ref );
1463 rs->sr_v2ref = NULL;
1465 if( realbase.bv_val ) ch_free( realbase.bv_val );
1471 static int base_candidate(
1477 LDAP_LOG ( OPERATION, ENTRY,
1478 "base_candidate: base: \"%s\" (0x%08lx)\n",
1479 e->e_nname.bv_val, (long) e->e_id, 0);
1481 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
1482 e->e_nname.bv_val, (long) e->e_id, 0);
1490 /* Look for "objectClass Present" in this filter.
1491 * Also count depth of filter tree while we're at it.
1493 static int oc_filter(
1502 if( cur > *max ) *max = cur;
1504 switch( f->f_choice ) {
1505 case LDAP_FILTER_PRESENT:
1506 if (f->f_desc == slap_schema.si_ad_objectClass) {
1511 case LDAP_FILTER_AND:
1512 case LDAP_FILTER_OR:
1514 for ( f=f->f_and; f; f=f->f_next ) {
1515 (void) oc_filter(f, cur, max);
1525 static void search_stack_free( void *key, void *data )
1527 ber_memfree_x(data, NULL);
1530 static void *search_stack( Operation *op )
1532 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1535 if ( op->o_threadctx ) {
1536 ldap_pvt_thread_pool_getkey( op->o_threadctx, search_stack,
1539 ret = bdb->bi_search_stack;
1543 ret = ch_malloc( bdb->bi_search_stack_depth * BDB_IDL_UM_SIZE
1545 if ( op->o_threadctx ) {
1546 ldap_pvt_thread_pool_setkey( op->o_threadctx, search_stack,
1547 ret, search_stack_free );
1549 bdb->bi_search_stack = ret;
1555 static int search_candidates(
1564 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1566 Filter f, rf, xf, nf;
1568 AttributeAssertion aa_ref;
1569 #ifdef BDB_SUBENTRIES
1571 AttributeAssertion aa_subentry;
1575 * This routine takes as input a filter (user-filter)
1576 * and rewrites it as follows:
1577 * (&(scope=DN)[(objectClass=subentry)]
1578 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
1582 LDAP_LOG ( OPERATION, ENTRY,
1583 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1584 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope);
1586 Debug(LDAP_DEBUG_TRACE,
1587 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1588 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope );
1591 xf.f_or = op->oq_search.rs_filter;
1592 xf.f_choice = LDAP_FILTER_OR;
1595 /* If the user's filter uses objectClass=*,
1596 * these clauses are redundant.
1598 if (!oc_filter(op->oq_search.rs_filter, 1, &depth)
1599 && !get_subentries_visibility(op)
1600 && !is_sync_protocol(op) )
1602 if( !get_manageDSAit(op) && !get_domainScope(op) ) {
1603 /* match referral objects */
1604 struct berval bv_ref = { sizeof("referral")-1, "referral" };
1605 rf.f_choice = LDAP_FILTER_EQUALITY;
1607 rf.f_av_desc = slap_schema.si_ad_objectClass;
1608 rf.f_av_value = bv_ref;
1609 rf.f_next = xf.f_or;
1616 f.f_choice = LDAP_FILTER_AND;
1618 /* Dummy; we compute scope separately now */
1619 nf.f_choice = SLAPD_FILTER_COMPUTED;
1620 nf.f_result = LDAP_SUCCESS;
1621 nf.f_next = ( xf.f_or == op->oq_search.rs_filter )
1622 ? op->oq_search.rs_filter : &xf ;
1623 /* Filter depth increased again, adding dummy clause */
1626 #ifdef BDB_SUBENTRIES
1627 if( get_subentries_visibility( op ) ) {
1628 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1629 sf.f_choice = LDAP_FILTER_EQUALITY;
1630 sf.f_ava = &aa_subentry;
1631 sf.f_av_desc = slap_schema.si_ad_objectClass;
1632 sf.f_av_value = bv_subentry;
1633 sf.f_next = nf.f_next;
1638 /* Allocate IDL stack, plus 1 more for former tmp */
1639 if ( depth+1 > bdb->bi_search_stack_depth ) {
1640 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1642 stack = search_stack( stackop );
1645 if( op->ors_deref & LDAP_DEREF_SEARCHING ) {
1646 rc = search_aliases( op, rs, e, locker, ids, scopes, stack );
1648 rc = bdb_dn2idl( op, e, ids, stack );
1651 if ( rc == LDAP_SUCCESS ) {
1652 rc = bdb_filter_candidates( op, &f, ids,
1653 stack, stack+BDB_IDL_UM_SIZE );
1656 if ( depth+1 > bdb->bi_search_stack_depth ) {
1662 LDAP_LOG ( OPERATION, DETAIL1,
1663 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1665 Debug(LDAP_DEBUG_TRACE,
1666 "bdb_search_candidates: failed (rc=%d)\n",
1672 LDAP_LOG ( OPERATION, DETAIL1,
1673 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1674 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1675 (long) BDB_IDL_LAST(ids));
1677 Debug(LDAP_DEBUG_TRACE,
1678 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1680 (long) BDB_IDL_FIRST(ids),
1681 (long) BDB_IDL_LAST(ids) );
1689 send_pagerequest_response(
1695 LDAPControl ctrl, *ctrls[2];
1696 BerElementBuffer berbuf;
1697 BerElement *ber = (BerElement *)&berbuf;
1698 struct berval cookie = BER_BVNULL;
1699 PagedResultsCookie respcookie;
1702 LDAP_LOG ( OPERATION, ENTRY,
1703 "send_pagerequest_response: lastid: (0x%08lx) "
1704 "nentries: (0x%081x)\n",
1705 lastid, rs->sr_nentries, NULL );
1707 Debug(LDAP_DEBUG_ARGS, "send_pagerequest_response: lastid: (0x%08lx) "
1708 "nentries: (0x%081x)\n", lastid, rs->sr_nentries, NULL );
1711 ctrl.ldctl_value.bv_val = NULL;
1715 ber_init2( ber, NULL, LBER_USE_DER );
1717 respcookie = ( PagedResultsCookie )lastid;
1718 op->o_conn->c_pagedresults_state.ps_cookie = respcookie;
1719 op->o_conn->c_pagedresults_state.ps_count = op->o_pagedresults_state.ps_count + rs->sr_nentries;
1720 cookie.bv_len = sizeof( respcookie );
1721 cookie.bv_val = (char *)&respcookie;
1724 * FIXME: we should consider sending an estimate of the entries
1725 * left, after appropriate security check is done
1727 ber_printf( ber, "{iO}", tentries, &cookie );
1729 if ( ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 ) == -1 ) {
1733 ctrls[0]->ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
1734 ctrls[0]->ldctl_iscritical = 0;
1736 rs->sr_ctrls = ctrls;
1737 rs->sr_err = LDAP_SUCCESS;
1738 send_ldap_result( op, rs );
1741 (void) ber_free_buf( ber );