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 );
319 bdb_abandon( Operation *op, SlapReply *rs )
323 ps = bdb_drop_psearch( op, op->oq_abandon.rs_msgid );
325 if ( ps->o_tmpmemctx ) {
326 sl_mem_destroy( NULL, ps->o_tmpmemctx );
331 return LDAP_UNAVAILABLE;
335 bdb_cancel( Operation *op, SlapReply *rs )
339 ps = bdb_drop_psearch( op, op->oq_cancel.rs_msgid );
341 rs->sr_err = LDAP_CANCELLED;
342 send_ldap_result( ps, rs );
343 if ( ps->o_tmpmemctx ) {
344 sl_mem_destroy( NULL, ps->o_tmpmemctx );
349 return LDAP_UNAVAILABLE;
352 int bdb_search( Operation *op, SlapReply *rs )
354 return bdb_do_search( op, rs, op, NULL, 0 );
357 /* For persistent searches, op is the currently executing operation,
358 * sop is the persistent search. For regular searches, sop = op.
361 bdb_do_search( Operation *op, SlapReply *rs, Operation *sop,
362 Entry *ps_e, int ps_type )
364 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
367 ID candidates[BDB_IDL_UM_SIZE];
368 ID scopes[BDB_IDL_DB_SIZE];
369 Entry *e = NULL, base;
370 Entry *matched = NULL;
372 struct berval realbase = { 0, NULL };
376 AttributeName *attrs;
378 Filter contextcsnand, contextcsnle, cookief, csnfnot, csnfeq, csnfand, csnfge;
379 Filter omitcsnf, omitcsnfle;
380 AttributeAssertion aa_ge, aa_eq, aa_le;
382 struct berval *search_context_csn = NULL;
384 LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
386 AttributeName uuid_attr[2];
388 int entry_sync_state = -1;
389 AttributeName null_attr;
390 int no_sync_state_change = 0;
391 struct slap_limits_set *limit = NULL;
394 u_int32_t locker = 0;
398 LDAP_LOG( OPERATION, ENTRY, "bdb_back_search\n", 0, 0, 0 );
400 Debug( LDAP_DEBUG_TRACE, "=> bdb_back_search\n",
403 attrs = sop->oq_search.rs_attrs;
405 /* psearch needs to be registered before refresh begins */
406 /* psearch and refresh transmission is serialized in send_ldap_ber() */
407 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
408 LDAP_LIST_INSERT_HEAD( &bdb->bi_psearch_list, sop, o_ps_link );
410 null_attr.an_desc = NULL;
411 null_attr.an_oc = NULL;
412 null_attr.an_name.bv_len = 0;
413 null_attr.an_name.bv_val = NULL;
415 for( num_ctrls = 0; num_ctrls < SLAP_MAX_RESPONSE_CONTROLS; num_ctrls++ ) {
416 ctrls[num_ctrls] = NULL;
420 if ( IS_PSEARCH && IS_BDB_REPLACE(ps_type)) {
422 attrs[0].an_desc = NULL;
423 attrs[0].an_oc = NULL;
424 attrs[0].an_name.bv_len = 0;
425 attrs[0].an_name.bv_val = NULL;
428 manageDSAit = get_manageDSAit( sop );
430 /* Sync control overrides manageDSAit */
432 if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
433 if ( manageDSAit == SLAP_NO_CONTROL )
434 manageDSAit = SLAP_CRITICAL_CONTROL;
435 } else if ( IS_PSEARCH ) {
436 if ( manageDSAit == SLAP_NO_CONTROL )
437 manageDSAit = SLAP_CRITICAL_CONTROL;
440 rs->sr_err = LOCK_ID (bdb->bi_dbenv, &locker );
446 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
450 if ( sop->o_req_ndn.bv_len == 0 ) {
451 /* DIT root special case */
452 e = (Entry *) &slap_entry_root;
453 rs->sr_err = LDAP_SUCCESS;
456 /* get entry with reader lock */
457 rs->sr_err = bdb_dn2entry( op, NULL, &sop->o_req_ndn, &ei,
463 matched = ei->bei_e; break;
465 e = ei->bei_e; break;
467 send_ldap_error( sop, rs, LDAP_BUSY, "ldap server busy" );
468 LOCK_ID_FREE (bdb->bi_dbenv, locker );
470 case DB_LOCK_DEADLOCK:
471 case DB_LOCK_NOTGRANTED:
474 send_ldap_error( sop, rs, LDAP_OTHER, "internal error" );
475 LOCK_ID_FREE (bdb->bi_dbenv, locker );
479 if ( e && (op->ors_deref & LDAP_DEREF_FINDING) && is_entry_alias(e) ) {
480 BDB_IDL_ZERO(candidates);
481 e = deref_base( op, rs, e, &matched, locker, &lock,
486 struct berval matched_dn = { 0, NULL };
488 if ( matched != NULL ) {
490 ber_dupbv( &matched_dn, &matched->e_name );
492 erefs = is_entry_referral( matched )
493 ? get_entry_referrals( op, matched )
496 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
501 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
502 &sop->o_req_dn, sop->oq_search.rs_scope );
503 ber_bvarray_free( erefs );
507 rs->sr_ref = referral_rewrite( default_referral,
508 NULL, &sop->o_req_dn, sop->oq_search.rs_scope );
511 rs->sr_err = LDAP_REFERRAL;
512 rs->sr_matched = matched_dn.bv_val;
513 send_ldap_result( sop, rs );
515 LOCK_ID_FREE (bdb->bi_dbenv, locker );
517 ber_bvarray_free( rs->sr_ref );
520 if ( matched_dn.bv_val ) {
521 ber_memfree( matched_dn.bv_val );
522 rs->sr_matched = NULL;
527 if (!manageDSAit && e != &slap_entry_root && is_entry_referral( e ) ) {
528 /* entry is a referral, don't allow add */
529 struct berval matched_dn;
532 ber_dupbv( &matched_dn, &e->e_name );
533 erefs = get_entry_referrals( op, e );
535 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
539 rs->sr_ref = referral_rewrite( erefs, &matched_dn,
540 &sop->o_req_dn, sop->oq_search.rs_scope );
541 ber_bvarray_free( erefs );
545 LDAP_LOG ( OPERATION, RESULTS,
546 "bdb_search: entry is referral\n", 0, 0, 0 );
548 Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
552 if (!rs->sr_ref) rs->sr_text = "bad_referral object";
553 rs->sr_err = LDAP_REFERRAL;
554 rs->sr_matched = matched_dn.bv_val;
555 send_ldap_result( sop, rs );
557 LOCK_ID_FREE (bdb->bi_dbenv, locker );
558 ber_bvarray_free( rs->sr_ref );
560 ber_memfree( matched_dn.bv_val );
561 rs->sr_matched = NULL;
565 if ( get_assert( op ) &&
566 ( test_filter( op, e, get_assertion( op )) != LDAP_COMPARE_TRUE ))
568 rs->sr_err = LDAP_ASSERTION_FAILED;
569 send_ldap_result( sop, rs );
573 /* if not root, get appropriate limits */
574 if ( be_isroot( op->o_bd, &sop->o_ndn ) ) {
577 ( void ) get_limits( op->o_bd, &sop->o_ndn, &limit );
580 /* The time/size limits come first because they require very little
581 * effort, so there's no chance the candidates are selected and then
582 * the request is not honored only because of time/size constraints */
584 /* if no time limit requested, use soft limit (unless root!) */
586 if ( sop->oq_search.rs_tlimit == 0 ) {
587 sop->oq_search.rs_tlimit = -1; /* allow root to set no limit */
590 if ( sop->oq_search.rs_slimit == 0 ) {
591 sop->oq_search.rs_slimit = -1;
595 /* if no limit is required, use soft limit */
596 if ( sop->oq_search.rs_tlimit <= 0 ) {
597 sop->oq_search.rs_tlimit = limit->lms_t_soft;
599 /* if requested limit higher than hard limit, abort */
600 } else if ( sop->oq_search.rs_tlimit > limit->lms_t_hard ) {
601 /* no hard limit means use soft instead */
602 if ( limit->lms_t_hard == 0
603 && limit->lms_t_soft > -1
604 && sop->oq_search.rs_tlimit > limit->lms_t_soft ) {
605 sop->oq_search.rs_tlimit = limit->lms_t_soft;
607 /* positive hard limit means abort */
608 } else if ( limit->lms_t_hard > 0 ) {
609 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
610 send_ldap_result( sop, rs );
611 rs->sr_err = LDAP_SUCCESS;
615 /* negative hard limit means no limit */
618 /* if no limit is required, use soft limit */
619 if ( sop->oq_search.rs_slimit <= 0 ) {
620 if ( get_pagedresults(sop) && limit->lms_s_pr != 0 ) {
621 sop->oq_search.rs_slimit = limit->lms_s_pr;
623 sop->oq_search.rs_slimit = limit->lms_s_soft;
626 /* if requested limit higher than hard limit, abort */
627 } else if ( sop->oq_search.rs_slimit > limit->lms_s_hard ) {
628 /* no hard limit means use soft instead */
629 if ( limit->lms_s_hard == 0
630 && limit->lms_s_soft > -1
631 && sop->oq_search.rs_slimit > limit->lms_s_soft ) {
632 sop->oq_search.rs_slimit = limit->lms_s_soft;
634 /* positive hard limit means abort */
635 } else if ( limit->lms_s_hard > 0 ) {
636 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
637 send_ldap_result( sop, rs );
638 rs->sr_err = LDAP_SUCCESS;
642 /* negative hard limit means no limit */
646 /* compute it anyway; root does not use it */
647 stoptime = op->o_time + sop->oq_search.rs_tlimit;
649 /* need normalized dn below */
650 ber_dupbv( &realbase, &e->e_nname );
652 /* Copy info to base, must free entry before accessing the database
653 * in search_candidates, to avoid deadlocks.
655 base.e_private = e->e_private;
656 base.e_nname = realbase;
659 if ( e != &slap_entry_root ) {
660 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
664 rs->sr_err = bdb_get_commit_csn( sop, rs, &search_context_csn, locker, &ctxcsn_lock );
666 if ( rs->sr_err != LDAP_SUCCESS ) {
667 send_ldap_error( sop, rs, rs->sr_err, "error in csn management in search" );
671 /* select candidates */
672 if ( sop->oq_search.rs_scope == LDAP_SCOPE_BASE ) {
673 rs->sr_err = base_candidate( op->o_bd, &base, candidates );
676 BDB_IDL_ZERO( candidates );
677 BDB_IDL_ZERO( scopes );
678 rs->sr_err = search_candidates( op, sop, rs, &base, locker, candidates, scopes );
681 if ( sop->o_sync_mode != SLAP_SYNC_NONE ) {
682 bdb_cache_entry_db_unlock( bdb->bi_dbenv, &ctxcsn_lock );
685 /* start cursor at beginning of candidates.
689 if ( !BDB_IDL_IS_RANGE( candidates ) ) {
690 cursor = bdb_idl_search( candidates, ps_e->e_id );
691 if ( candidates[cursor] != ps_e->e_id ) {
692 rs->sr_err = LDAP_SUCCESS;
696 if ( ps_e->e_id < BDB_IDL_RANGE_FIRST(candidates)
697 || ps_e->e_id > BDB_IDL_RANGE_LAST(candidates)){
698 rs->sr_err = LDAP_SUCCESS;
703 candidates[1] = ps_e->e_id;
706 if ( candidates[0] == 0 ) {
708 LDAP_LOG ( OPERATION, RESULTS,
709 "bdb_search: no candidates\n", 0, 0, 0 );
711 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
715 rs->sr_err = LDAP_SUCCESS;
717 send_ldap_result( sop, rs );
721 /* if not root and candidates exceed to-be-checked entries, abort */
722 if ( !isroot && limit->lms_s_unchecked != -1 ) {
723 if ( BDB_IDL_N(candidates) > (unsigned) limit->lms_s_unchecked ) {
724 rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
725 send_ldap_result( sop, rs );
726 rs->sr_err = LDAP_SUCCESS;
731 if ( isroot || !limit->lms_s_pr_hide ) {
732 tentries = BDB_IDL_N(candidates);
735 #ifdef LDAP_CONTROL_PAGEDRESULTS
736 if ( get_pagedresults(sop) ) {
737 if ( sop->o_pagedresults_state.ps_cookie == 0 ) {
740 if ( sop->o_pagedresults_size == 0 ) {
741 rs->sr_err = LDAP_SUCCESS;
742 rs->sr_text = "search abandoned by pagedResult size=0";
743 send_ldap_result( sop, rs );
746 for ( id = bdb_idl_first( candidates, &cursor );
747 id != NOID && id <= (ID)( sop->o_pagedresults_state.ps_cookie );
748 id = bdb_idl_next( candidates, &cursor ) );
750 if ( cursor == NOID ) {
752 LDAP_LOG ( OPERATION, RESULTS,
753 "bdb_search: no paged results candidates\n",
756 Debug( LDAP_DEBUG_TRACE,
757 "bdb_search: no paged results candidates\n",
760 send_pagerequest_response( sop, rs, lastid, 0 );
762 rs->sr_err = LDAP_OTHER;
769 if ( (sop->o_sync_mode & SLAP_SYNC_REFRESH) || IS_PSEARCH )
775 cookief.f_choice = LDAP_FILTER_AND;
776 cookief.f_and = &csnfnot;
777 cookief.f_next = NULL;
779 csnfnot.f_choice = LDAP_FILTER_NOT;
780 csnfnot.f_not = &csnfeq;
781 csnfnot.f_next = &csnfand;
783 csnfeq.f_choice = LDAP_FILTER_EQUALITY;
784 csnfeq.f_ava = &aa_eq;
785 csnfeq.f_av_desc = slap_schema.si_ad_entryCSN;
786 csnfeq.f_av_value = sop->o_sync_state;
788 csnfand.f_choice = LDAP_FILTER_AND;
789 csnfand.f_and = &csnfge;
790 csnfand.f_next = NULL;
792 csnfge.f_choice = LDAP_FILTER_GE;
793 csnfge.f_ava = &aa_ge;
794 csnfge.f_av_desc = slap_schema.si_ad_entryCSN;
795 csnfge.f_av_value = sop->o_sync_state;
797 if ( search_context_csn && !IS_PSEARCH ) {
798 csnfge.f_next = &contextcsnand;
800 contextcsnand.f_choice = LDAP_FILTER_AND;
801 contextcsnand.f_and = &contextcsnle;
802 contextcsnand.f_next = NULL;
804 contextcsnle.f_choice = LDAP_FILTER_LE;
805 contextcsnle.f_ava = &aa_le;
806 contextcsnle.f_av_desc = slap_schema.si_ad_entryCSN;
807 contextcsnle.f_av_value = *search_context_csn;
808 contextcsnle.f_next = sop->oq_search.rs_filter;
810 mr = slap_schema.si_ad_entryCSN->ad_type->sat_ordering;
811 if ( sop->o_sync_state.bv_len != 0 ) {
812 value_match( &match, slap_schema.si_ad_entryCSN, mr,
813 SLAP_MR_VALUE_OF_ATTRIBUTE_SYNTAX,
814 &sop->o_sync_state, search_context_csn, &text );
818 no_sync_state_change = !match;
820 csnfge.f_next = sop->oq_search.rs_filter;
824 for ( id = bdb_idl_first( candidates, &cursor );
826 id = bdb_idl_next( candidates, &cursor ) )
831 /* check for abandon */
832 if ( sop->o_abandon ) {
834 bdb_drop_psearch( sop, sop->o_msgid );
836 rs->sr_err = LDAP_SUCCESS;
840 #ifdef LDAP_EXOP_X_CANCEL
841 if ( sop->o_cancel ) {
842 assert( sop->o_cancel == SLAP_CANCEL_REQ );
843 rs->sr_err = LDAP_CANCELLED;
844 send_ldap_result( sop, rs );
845 sop->o_cancel = SLAP_CANCEL_ACK;
846 rs->sr_err = LDAP_SUCCESS;
851 /* check time limit */
852 if ( sop->oq_search.rs_tlimit != -1 && slap_get_time() > stoptime ) {
853 rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
854 rs->sr_ref = rs->sr_v2ref;
855 send_ldap_result( sop, rs );
856 rs->sr_err = LDAP_SUCCESS;
863 /* get the entry with reader lock */
865 rs->sr_err = bdb_cache_find_id( op, NULL,
866 id, &ei, 0, locker, &lock );
868 if (rs->sr_err == LDAP_BUSY) {
869 rs->sr_text = "ldap server busy";
870 send_ldap_result( sop, rs );
873 } else if ( rs->sr_err == DB_LOCK_DEADLOCK
874 || rs->sr_err == DB_LOCK_NOTGRANTED )
879 if ( ei && rs->sr_err == LDAP_SUCCESS ) {
886 if( !BDB_IDL_IS_RANGE(candidates) ) {
887 /* only complain for non-range IDLs */
889 LDAP_LOG ( OPERATION, RESULTS,
890 "bdb_search: candidate %ld not found\n",
893 Debug( LDAP_DEBUG_TRACE,
894 "bdb_search: candidate %ld not found\n",
906 #ifdef BDB_SUBENTRIES
907 /* FIXME: send all but syncrepl
908 if ( !is_sync_protocol( sop ) ) {
910 if ( is_entry_subentry( e ) ) {
911 if( sop->oq_search.rs_scope != LDAP_SCOPE_BASE ) {
912 if(!get_subentries_visibility( sop )) {
913 /* only subentries are visible */
917 } else if ( get_subentries( sop ) &&
918 !get_subentries_visibility( sop ))
920 /* only subentries are visible */
924 } else if ( get_subentries_visibility( sop )) {
925 /* only subentries are visible */
933 /* Does this candidate actually satisfy the search scope?
935 * Note that we don't lock access to the bei_parent pointer.
936 * Since only leaf nodes can be deleted, the parent of any
937 * node will always be a valid node. Also since we have
938 * a Read lock on the data, it cannot be renamed out of the
939 * scope while we are looking at it, and unless we're using
940 * BDB_HIER, its parents cannot be moved either.
942 switch( sop->ors_scope ) {
943 case LDAP_SCOPE_BASE:
944 /* This is always true, yes? */
945 if ( id == base.e_id )
948 case LDAP_SCOPE_ONELEVEL:
949 if ( ei->bei_parent->bei_id == base.e_id )
952 case LDAP_SCOPE_SUBTREE:
954 for ( tmp = BEI(e); tmp->bei_parent;
955 tmp = tmp->bei_parent ) {
956 if ( tmp->bei_id == base.e_id ) {
965 /* aliases were already dereferenced in candidate list */
966 if ( sop->ors_deref & LDAP_DEREF_SEARCHING ) {
967 /* but if the search base is an alias, and we didn't
968 * deref it when finding, return it.
970 if ( is_entry_alias(e) &&
971 ((sop->ors_deref & LDAP_DEREF_FINDING)
972 || !bvmatch(&e->e_nname, &op->o_req_ndn)))
977 /* scopes is only non-empty for onelevel or subtree */
978 if ( !scopeok && BDB_IDL_N(scopes) ) {
980 if ( sop->ors_scope == LDAP_SCOPE_ONELEVEL ) {
981 x = bdb_idl_search( scopes,
983 if ( scopes[x] == e->e_id )
986 /* subtree, walk up the tree */
987 EntryInfo *tmp = BEI(e);
988 for (;tmp->bei_parent;
989 tmp=tmp->bei_parent) {
991 scopes, tmp->bei_id );
992 if ( scopes[x] == tmp->bei_id ) {
1002 /* Not in scope, ignore it */
1005 LDAP_LOG ( OPERATION, RESULTS,
1006 "bdb_search: %ld scope not okay\n",
1009 Debug( LDAP_DEBUG_TRACE,
1010 "bdb_search: %ld scope not okay\n",
1017 * if it's a referral, add it to the list of referrals. only do
1018 * this for non-base searches, and don't check the filter
1019 * explicitly here since it's only a candidate anyway.
1021 if ( !manageDSAit && sop->oq_search.rs_scope != LDAP_SCOPE_BASE
1022 && is_entry_referral( e ) )
1024 BerVarray erefs = get_entry_referrals( sop, e );
1025 rs->sr_ref = referral_rewrite( erefs,
1027 sop->oq_search.rs_scope == LDAP_SCOPE_SUBTREE
1028 ? LDAP_SCOPE_SUBTREE
1029 : LDAP_SCOPE_BASE );
1031 send_search_reference( sop, rs );
1033 ber_bvarray_free( rs->sr_ref );
1034 ber_bvarray_free( erefs );
1040 if ( !manageDSAit && is_entry_glue( e )) {
1044 /* if it matches the filter and scope, send it */
1046 if (ps_type != LDAP_PSEARCH_BY_SCOPEOUT) {
1047 rs->sr_err = test_filter( sop, rs->sr_entry, &cookief );
1049 rs->sr_err = LDAP_COMPARE_TRUE;
1052 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1053 rc_sync = test_filter( sop, rs->sr_entry, &cookief );
1054 rs->sr_err = test_filter( sop,
1055 rs->sr_entry, &contextcsnand );
1056 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1057 if ( rc_sync == LDAP_COMPARE_TRUE ) {
1058 if ( no_sync_state_change ) {
1060 LDAP_LOG ( OPERATION, RESULTS,
1061 "bdb_search: error in context csn management\n",
1064 Debug( LDAP_DEBUG_TRACE,
1065 "bdb_search: error in context csn management\n",
1069 entry_sync_state = LDAP_SYNC_ADD;
1071 if ( no_sync_state_change ) {
1074 entry_sync_state = LDAP_SYNC_PRESENT;
1078 rs->sr_err = test_filter( sop,
1079 rs->sr_entry, sop->oq_search.rs_filter );
1083 if ( rs->sr_err == LDAP_COMPARE_TRUE ) {
1084 /* check size limit */
1085 if ( --sop->oq_search.rs_slimit == -1 ) {
1087 bdb_cache_return_entry_r( bdb->bi_dbenv,
1088 &bdb->bi_cache, e, &lock );
1091 rs->sr_entry = NULL;
1092 rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
1093 rs->sr_ref = rs->sr_v2ref;
1094 send_ldap_result( sop, rs );
1095 rs->sr_err = LDAP_SUCCESS;
1099 #ifdef LDAP_CONTROL_PAGEDRESULTS
1100 if ( get_pagedresults(sop) ) {
1101 if ( rs->sr_nentries >= sop->o_pagedresults_size ) {
1102 send_pagerequest_response( sop, rs,
1114 #if 0 /* noop is masked SLAP_CTRL_UPDATE */
1120 int premodify_found = 0;
1121 int entry_sync_state;
1123 if ( ps_type == LDAP_PSEARCH_BY_ADD ||
1124 ps_type == LDAP_PSEARCH_BY_DELETE ||
1125 ps_type == LDAP_PSEARCH_BY_MODIFY ||
1126 ps_type == LDAP_PSEARCH_BY_SCOPEOUT )
1128 if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1129 struct psid_entry* psid_e;
1130 LDAP_LIST_FOREACH( psid_e,
1131 &op->o_pm_list, ps_link)
1133 if( psid_e->ps_op == sop ) {
1134 premodify_found = 1;
1135 LDAP_LIST_REMOVE(psid_e, ps_link);
1139 if (psid_e != NULL) free (psid_e);
1141 if ( ps_type == LDAP_PSEARCH_BY_ADD ) {
1142 entry_sync_state = LDAP_SYNC_ADD;
1143 } else if ( ps_type == LDAP_PSEARCH_BY_DELETE ) {
1144 entry_sync_state = LDAP_SYNC_DELETE;
1145 } else if ( ps_type == LDAP_PSEARCH_BY_MODIFY ) {
1146 if ( premodify_found ) {
1147 entry_sync_state = LDAP_SYNC_MODIFY;
1149 entry_sync_state = LDAP_SYNC_ADD;
1151 } else if ( ps_type == LDAP_PSEARCH_BY_SCOPEOUT )
1152 entry_sync_state = LDAP_SYNC_DELETE;
1154 rs->sr_err = LDAP_OTHER;
1157 rs->sr_err = bdb_build_sync_state_ctrl( sop,
1158 rs, e, entry_sync_state, ctrls,
1159 num_ctrls++, 1, search_context_csn );
1160 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1161 rs->sr_attrs = attrs;
1162 rs->sr_ctrls = ctrls;
1163 result = send_search_entry( sop, rs );
1164 ch_free( ctrls[num_ctrls-1]->ldctl_value.bv_val );
1165 ch_free( ctrls[--num_ctrls] );
1166 ctrls[num_ctrls] = NULL;
1167 rs->sr_ctrls = NULL;
1169 } else if ( ps_type == LDAP_PSEARCH_BY_PREMODIFY ) {
1170 struct psid_entry* psid_e;
1171 psid_e = (struct psid_entry *) calloc (1,
1172 sizeof(struct psid_entry));
1173 psid_e->ps_op = sop;
1174 LDAP_LIST_INSERT_HEAD( &op->o_pm_list,
1178 printf("Error !\n");
1181 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1182 rs->sr_err = bdb_build_sync_state_ctrl( sop,
1183 rs, e, entry_sync_state, ctrls,
1184 num_ctrls++, 0, search_context_csn );
1185 if ( rs->sr_err != LDAP_SUCCESS ) goto done;
1187 rs->sr_ctrls = ctrls;
1188 if ( rc_sync == LDAP_COMPARE_TRUE ) { /* ADD */
1189 rs->sr_attrs = sop->oq_search.rs_attrs;
1190 } else { /* PRESENT */
1191 rs->sr_attrs = &null_attr;
1193 result = send_search_entry( sop, rs );
1194 ch_free( ctrls[num_ctrls-1]->ldctl_value.bv_val );
1195 ch_free( ctrls[--num_ctrls] );
1196 ctrls[num_ctrls] = NULL;
1197 rs->sr_ctrls = NULL;
1199 rs->sr_attrs = sop->oq_search.rs_attrs;
1200 rs->sr_ctrls = NULL;
1201 result = send_search_entry( sop, rs );
1206 case 0: /* entry sent ok */
1208 case 1: /* entry not sent */
1210 case -1: /* connection closed */
1212 bdb_cache_return_entry_r(bdb->bi_dbenv,
1213 &bdb->bi_cache, e, &lock);
1215 rs->sr_entry = NULL;
1216 rs->sr_err = LDAP_OTHER;
1222 LDAP_LOG ( OPERATION, RESULTS,
1223 "bdb_search: %ld does not match filter\n", (long) id, 0, 0);
1225 Debug( LDAP_DEBUG_TRACE,
1226 "bdb_search: %ld does not match filter\n",
1233 /* free reader lock */
1235 bdb_cache_return_entry_r( bdb->bi_dbenv,
1236 &bdb->bi_cache, e , &lock );
1237 if ( sop->o_nocaching ) {
1238 bdb_cache_delete_entry( bdb, ei, locker, &lock );
1242 rs->sr_entry = NULL;
1245 ldap_pvt_thread_yield();
1249 if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) {
1250 rs->sr_err = LDAP_SUCCESS;
1251 rs->sr_rspoid = LDAP_SYNC_INFO;
1252 rs->sr_ctrls = NULL;
1253 bdb_send_ldap_intermediate( sop, rs,
1254 LDAP_SYNC_STATE_MODE_DONE, search_context_csn );
1256 /* If changelog is supported, this is where to process it */
1258 if ( sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
1259 /* refreshAndPersist mode */
1260 bdb_send_ldap_intermediate( sop, rs,
1261 LDAP_SYNC_LOG_MODE_DONE, search_context_csn );
1263 /* refreshOnly mode */
1264 bdb_build_sync_done_ctrl( sop, rs, ctrls,
1265 num_ctrls++, 1, search_context_csn );
1266 rs->sr_ctrls = ctrls;
1267 rs->sr_ref = rs->sr_v2ref;
1268 rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
1269 send_ldap_result( sop, rs );
1270 if ( ctrls[num_ctrls-1]->ldctl_value.bv_val != NULL ) {
1271 ch_free( ctrls[num_ctrls-1]->ldctl_value.bv_val );
1273 ch_free( ctrls[--num_ctrls] );
1274 ctrls[num_ctrls] = NULL;
1277 rs->sr_ctrls = NULL;
1278 rs->sr_ref = rs->sr_v2ref;
1279 rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS : LDAP_REFERRAL;
1280 send_ldap_result( sop, rs );
1284 rs->sr_err = LDAP_SUCCESS;
1287 if( !IS_PSEARCH && e != NULL ) {
1288 /* free reader lock */
1289 bdb_cache_return_entry_r ( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
1292 LOCK_ID_FREE (bdb->bi_dbenv, locker );
1294 ber_bvfree( search_context_csn );
1296 if( rs->sr_v2ref ) {
1297 ber_bvarray_free( rs->sr_v2ref );
1298 rs->sr_v2ref = NULL;
1300 if( realbase.bv_val ) ch_free( realbase.bv_val );
1306 static int base_candidate(
1312 LDAP_LOG ( OPERATION, ENTRY,
1313 "base_candidate: base: \"%s\" (0x%08lx)\n",
1314 e->e_nname.bv_val, (long) e->e_id, 0);
1316 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
1317 e->e_nname.bv_val, (long) e->e_id, 0);
1325 /* Look for "objectClass Present" in this filter.
1326 * Also count depth of filter tree while we're at it.
1328 static int oc_filter(
1336 if( cur > *max ) *max = cur;
1338 switch(f->f_choice) {
1339 case LDAP_FILTER_PRESENT:
1340 if (f->f_desc == slap_schema.si_ad_objectClass) {
1345 case LDAP_FILTER_AND:
1346 case LDAP_FILTER_OR:
1348 for (f=f->f_and; f; f=f->f_next) {
1349 (void) oc_filter(f, cur, max);
1359 static void search_stack_free( void *key, void *data )
1361 ber_memfree_x(data, NULL);
1364 static void *search_stack(
1368 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1371 if ( op->o_threadctx ) {
1372 ldap_pvt_thread_pool_getkey( op->o_threadctx, search_stack,
1375 ret = bdb->bi_search_stack;
1379 ret = ch_malloc( bdb->bi_search_stack_depth * BDB_IDL_UM_SIZE
1381 if ( op->o_threadctx ) {
1382 ldap_pvt_thread_pool_setkey( op->o_threadctx, search_stack,
1383 ret, search_stack_free );
1385 bdb->bi_search_stack = ret;
1391 static int search_candidates(
1400 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
1402 Filter f, rf, xf, nf;
1404 AttributeAssertion aa_ref;
1405 #ifdef BDB_SUBENTRIES
1407 AttributeAssertion aa_subentry;
1411 * This routine takes as input a filter (user-filter)
1412 * and rewrites it as follows:
1413 * (&(scope=DN)[(objectClass=subentry)]
1414 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
1418 LDAP_LOG ( OPERATION, ENTRY,
1419 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1420 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope);
1422 Debug(LDAP_DEBUG_TRACE,
1423 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
1424 e->e_nname.bv_val, (long) e->e_id, op->oq_search.rs_scope );
1427 xf.f_or = op->oq_search.rs_filter;
1428 xf.f_choice = LDAP_FILTER_OR;
1431 /* If the user's filter uses objectClass=*,
1432 * these clauses are redundant.
1434 if (!oc_filter(op->oq_search.rs_filter, 1, &depth)
1435 && !get_subentries_visibility(op)
1436 && !is_sync_protocol(op) )
1438 if( !get_manageDSAit(op) && !get_domainScope(op) ) {
1439 /* match referral objects */
1440 struct berval bv_ref = { sizeof("referral")-1, "referral" };
1441 rf.f_choice = LDAP_FILTER_EQUALITY;
1443 rf.f_av_desc = slap_schema.si_ad_objectClass;
1444 rf.f_av_value = bv_ref;
1445 rf.f_next = xf.f_or;
1452 f.f_choice = LDAP_FILTER_AND;
1454 /* Dummy; we compute scope separately now */
1455 nf.f_choice = SLAPD_FILTER_COMPUTED;
1456 nf.f_result = LDAP_SUCCESS;
1457 nf.f_next = xf.f_or == op->oq_search.rs_filter
1458 ? op->oq_search.rs_filter : &xf ;
1459 /* Filter depth increased again, adding dummy clause */
1462 #ifdef BDB_SUBENTRIES
1463 if( get_subentries_visibility( op ) ) {
1464 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1465 sf.f_choice = LDAP_FILTER_EQUALITY;
1466 sf.f_ava = &aa_subentry;
1467 sf.f_av_desc = slap_schema.si_ad_objectClass;
1468 sf.f_av_value = bv_subentry;
1469 sf.f_next = nf.f_next;
1474 /* Allocate IDL stack, plus 1 more for former tmp */
1475 if ( depth+1 > bdb->bi_search_stack_depth ) {
1476 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1478 stack = search_stack( stackop );
1481 if( op->ors_deref & LDAP_DEREF_SEARCHING ) {
1482 rc = search_aliases( op, rs, e, locker, ids, scopes, stack );
1484 rc = bdb_dn2idl( op, e, ids, stack );
1487 if ( rc == LDAP_SUCCESS ) {
1488 rc = bdb_filter_candidates( op, &f, ids,
1489 stack, stack+BDB_IDL_UM_SIZE );
1492 if ( depth+1 > bdb->bi_search_stack_depth ) {
1498 LDAP_LOG ( OPERATION, DETAIL1,
1499 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1501 Debug(LDAP_DEBUG_TRACE,
1502 "bdb_search_candidates: failed (rc=%d)\n",
1508 LDAP_LOG ( OPERATION, DETAIL1,
1509 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1510 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1511 (long) BDB_IDL_LAST(ids));
1513 Debug(LDAP_DEBUG_TRACE,
1514 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1516 (long) BDB_IDL_FIRST(ids),
1517 (long) BDB_IDL_LAST(ids) );
1524 #ifdef LDAP_CONTROL_PAGEDRESULTS
1526 send_pagerequest_response(
1532 LDAPControl ctrl, *ctrls[2];
1533 BerElementBuffer berbuf;
1534 BerElement *ber = (BerElement *)&berbuf;
1535 struct berval cookie = { 0, NULL };
1536 PagedResultsCookie respcookie;
1539 LDAP_LOG ( OPERATION, ENTRY,
1540 "send_pagerequest_response: lastid: (0x%08lx) "
1541 "nentries: (0x%081x)\n",
1542 lastid, rs->sr_nentries, NULL );
1544 Debug(LDAP_DEBUG_ARGS, "send_pagerequest_response: lastid: (0x%08lx) "
1545 "nentries: (0x%081x)\n", lastid, rs->sr_nentries, NULL );
1548 ctrl.ldctl_value.bv_val = NULL;
1552 ber_init2( ber, NULL, LBER_USE_DER );
1554 respcookie = ( PagedResultsCookie )lastid;
1555 op->o_conn->c_pagedresults_state.ps_cookie = respcookie;
1556 cookie.bv_len = sizeof( respcookie );
1557 cookie.bv_val = (char *)&respcookie;
1560 * FIXME: we should consider sending an estimate of the entries
1561 * left, after appropriate security check is done
1563 ber_printf( ber, "{iO}", tentries, &cookie );
1565 if ( ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 ) == -1 ) {
1569 ctrls[0]->ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
1570 ctrls[0]->ldctl_iscritical = 0;
1572 rs->sr_ctrls = ctrls;
1573 rs->sr_err = LDAP_SUCCESS;
1574 send_ldap_result( op, rs );
1577 (void) ber_free_buf( ber );
1582 bdb_build_sync_state_ctrl(
1586 int entry_sync_state,
1587 LDAPControl **ctrls,
1595 const char *text = NULL;
1597 BerElementBuffer berbuf;
1598 BerElement *ber = (BerElement *)&berbuf;
1600 struct berval entryuuid_bv = { 0, NULL };
1602 ber_init2( ber, 0, LBER_USE_DER );
1604 ctrls[num_ctrls] = ch_malloc ( sizeof ( LDAPControl ) );
1606 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
1607 AttributeDescription *desc = a->a_desc;
1608 if ( desc == slap_schema.si_ad_entryUUID ) {
1609 ber_dupbv( &entryuuid_bv, &a->a_vals[0] );
1613 if ( send_cookie && csn ) {
1614 ber_printf( ber, "{eOON}",
1615 entry_sync_state, &entryuuid_bv, csn );
1617 ber_printf( ber, "{eON}",
1618 entry_sync_state, &entryuuid_bv );
1621 ch_free( entryuuid_bv.bv_val );
1622 entryuuid_bv.bv_val = NULL;
1624 ctrls[num_ctrls]->ldctl_oid = LDAP_CONTROL_SYNC_STATE;
1625 ctrls[num_ctrls]->ldctl_iscritical = op->o_sync;
1626 ret = ber_flatten2( ber, &ctrls[num_ctrls]->ldctl_value, 1 );
1628 ber_free_buf( ber );
1632 LDAP_LOG ( OPERATION, RESULTS,
1633 "bdb_build_sync_ctrl: ber_flatten2 failed\n",
1636 Debug( LDAP_DEBUG_TRACE,
1637 "bdb_build_sync_ctrl: ber_flatten2 failed\n",
1640 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
1644 return LDAP_SUCCESS;
1648 bdb_build_sync_done_ctrl(
1651 LDAPControl **ctrls,
1654 struct berval *csn )
1657 BerElementBuffer berbuf;
1658 BerElement *ber = (BerElement *)&berbuf;
1660 ber_init2( ber, NULL, LBER_USE_DER );
1662 ctrls[num_ctrls] = ch_malloc ( sizeof ( LDAPControl ) );
1664 if ( send_cookie && csn ) {
1665 ber_printf( ber, "{ON}", csn );
1667 ber_printf( ber, "{N}" );
1670 ctrls[num_ctrls]->ldctl_oid = LDAP_CONTROL_SYNC_DONE;
1671 ctrls[num_ctrls]->ldctl_iscritical = op->o_sync;
1672 ret = ber_flatten2( ber, &ctrls[num_ctrls]->ldctl_value, 1 );
1674 ber_free_buf( ber );
1678 LDAP_LOG ( OPERATION, RESULTS,
1679 "bdb_build_sync_done_ctrl: ber_flatten2 failed\n",
1682 Debug( LDAP_DEBUG_TRACE,
1683 "bdb_build_sync_done_ctrl: ber_flatten2 failed\n",
1686 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
1690 return LDAP_SUCCESS;
1694 bdb_send_ldap_intermediate(
1698 struct berval *cookie )
1700 BerElementBuffer berbuf;
1701 BerElement *ber = (BerElement *)&berbuf;
1702 struct berval rspdata;
1706 ber_init2( ber, NULL, LBER_USE_DER );
1708 if ( cookie == NULL ) {
1709 ber_printf( ber, "{eN}", state );
1711 ber_printf( ber, "{eON}", state, cookie );
1714 ret = ber_flatten2( ber, &rspdata, 0 );
1718 LDAP_LOG ( OPERATION, RESULTS,
1719 "bdb_send_ldap_intermediate: ber_flatten2 failed\n",
1722 Debug( LDAP_DEBUG_TRACE,
1723 "bdb_send_ldap_intermediate: ber_flatten2 failed\n",
1726 send_ldap_error( op, rs, LDAP_OTHER, "internal error" );
1730 rs->sr_rspdata = &rspdata;
1731 send_ldap_intermediate( op, rs );
1732 rs->sr_rspdata = NULL;
1733 ber_free_buf( ber );
1735 return LDAP_SUCCESS;