1 /* search.c - search operation */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
17 static int base_candidate(
21 static int search_candidates(
29 static void send_pagerequest_response(
48 struct berval *filterstr,
52 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
54 const char *text = NULL;
57 ID candidates[BDB_IDL_UM_SIZE];
59 BerVarray v2refs = NULL;
60 Entry *matched = NULL;
61 struct berval realbase = { 0, NULL };
68 #ifdef LDAP_CLIENT_UPDATE
69 Filter lcupf, csnfnot, csnfeq, csnfand, csnfge;
70 AttributeAssertion aa_ge, aa_eq;
72 struct berval entrycsn_bv = { 0, NULL };
73 struct berval latest_entrycsn_bv = { 0, NULL };
74 #endif /* LDAP_CLIENT_UPDATE */
76 struct slap_limits_set *limit = NULL;
83 LDAP_LOG ( OPERATION, ENTRY, "bdb_back_search\n", 0, 0, 0 );
85 Debug( LDAP_DEBUG_TRACE, "=> bdb_back_search\n",
89 #ifdef LDAP_CLIENT_UPDATE
90 if ( op->o_clientupdate_type & SLAP_LCUP_PERSIST ) {
91 bdb_add_psearch_spec( be, conn, op, base, base, scope,
92 deref, slimit, tlimit, filter, filterstr, attrs, attrsonly );
98 manageDSAit = get_manageDSAit( op );
99 pagedresults = get_pagedresults( op );
101 rc = LOCK_ID (bdb->bi_dbenv, &locker );
106 send_ldap_result( conn, op, rc=LDAP_OTHER,
107 NULL, "internal error", NULL, NULL );
111 if ( nbase->bv_len == 0 ) {
112 /* DIT root special case */
113 e = (Entry *) &slap_entry_root;
117 /* get entry with reader lock */
118 if ( deref & LDAP_DEREF_FINDING ) {
119 e = deref_dn_r( be, nbase-, &err, &matched, &text );
125 rc = bdb_dn2entry_r( be, NULL, nbase, &e, &matched, 0, locker, &lock );
134 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
136 if (matched != NULL) {
137 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
139 send_ldap_result( conn, op, LDAP_BUSY,
140 NULL, "ldap server busy", NULL, NULL );
141 LOCK_ID_FREE (bdb->bi_dbenv, locker );
143 case DB_LOCK_DEADLOCK:
144 case DB_LOCK_NOTGRANTED:
148 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
150 if (matched != NULL) {
151 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
153 send_ldap_result( conn, op, rc=LDAP_OTHER,
154 NULL, "internal error", NULL, NULL );
155 LOCK_ID_FREE (bdb->bi_dbenv, locker );
160 struct berval matched_dn = { 0, NULL };
161 BerVarray refs = NULL;
163 if ( matched != NULL ) {
165 ber_dupbv( &matched_dn, &matched->e_name );
167 erefs = is_entry_referral( matched )
168 ? get_entry_referrals( be, conn, op, matched )
171 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
175 refs = referral_rewrite( erefs, &matched_dn,
177 ber_bvarray_free( erefs );
181 refs = referral_rewrite( default_referral,
185 send_ldap_result( conn, op, rc=LDAP_REFERRAL ,
186 matched_dn.bv_val, text, refs, NULL );
188 LOCK_ID_FREE (bdb->bi_dbenv, locker );
189 if ( refs ) ber_bvarray_free( refs );
190 if ( matched_dn.bv_val ) ber_memfree( matched_dn.bv_val );
194 if (!manageDSAit && e != &slap_entry_root && is_entry_referral( e ) ) {
195 /* entry is a referral, don't allow add */
196 struct berval matched_dn;
197 BerVarray erefs, refs;
199 ber_dupbv( &matched_dn, &e->e_name );
200 erefs = get_entry_referrals( be, conn, op, e );
203 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
207 refs = referral_rewrite( erefs, &matched_dn,
209 ber_bvarray_free( erefs );
213 LDAP_LOG ( OPERATION, RESULTS,
214 "bdb_search: entry is referral\n", 0, 0, 0 );
216 Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
220 send_ldap_result( conn, op, LDAP_REFERRAL,
222 refs ? NULL : "bad referral object",
225 LOCK_ID_FREE (bdb->bi_dbenv, locker );
226 ber_bvarray_free( refs );
227 ber_memfree( matched_dn.bv_val );
231 /* if not root, get appropriate limits */
232 if ( be_isroot( be, &op->o_ndn ) ) {
235 ( void ) get_limits( be, &op->o_ndn, &limit );
238 /* The time/size limits come first because they require very little
239 * effort, so there's no chance the candidates are selected and then
240 * the request is not honored only because of time/size constraints */
242 /* if no time limit requested, use soft limit (unless root!) */
245 tlimit = -1; /* allow root to set no limit */
253 /* if no limit is required, use soft limit */
255 tlimit = limit->lms_t_soft;
257 /* if requested limit higher than hard limit, abort */
258 } else if ( tlimit > limit->lms_t_hard ) {
259 /* no hard limit means use soft instead */
260 if ( limit->lms_t_hard == 0
261 && limit->lms_t_soft > -1
262 && tlimit > limit->lms_t_soft ) {
263 tlimit = limit->lms_t_soft;
265 /* positive hard limit means abort */
266 } else if ( limit->lms_t_hard > 0 ) {
267 send_search_result( conn, op,
268 LDAP_ADMINLIMIT_EXCEEDED,
269 NULL, NULL, NULL, NULL, 0 );
274 /* negative hard limit means no limit */
277 /* if no limit is required, use soft limit */
279 if ( pagedresults && limit->lms_s_pr != 0 ) {
280 slimit = limit->lms_s_pr;
282 slimit = limit->lms_s_soft;
285 /* if requested limit higher than hard limit, abort */
286 } else if ( slimit > limit->lms_s_hard ) {
287 /* no hard limit means use soft instead */
288 if ( limit->lms_s_hard == 0
289 && limit->lms_s_soft > -1
290 && slimit > limit->lms_s_soft ) {
291 slimit = limit->lms_s_soft;
293 /* positive hard limit means abort */
294 } else if ( limit->lms_s_hard > 0 ) {
295 send_search_result( conn, op,
296 LDAP_ADMINLIMIT_EXCEEDED,
297 NULL, NULL, NULL, NULL, 0 );
302 /* negative hard limit means no limit */
306 /* compute it anyway; root does not use it */
307 stoptime = op->o_time + tlimit;
309 /* select candidates */
310 if ( scope == LDAP_SCOPE_BASE ) {
311 rc = base_candidate( be, e, candidates );
314 BDB_IDL_ALL( bdb, candidates );
315 rc = search_candidates( be, op, e, filter,
316 scope, deref, candidates );
319 /* need normalized dn below */
320 ber_dupbv( &realbase, &e->e_nname );
322 /* start cursor at beginning of candidates.
326 if ( e != &slap_entry_root ) {
327 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
331 if ( candidates[0] == 0 ) {
333 LDAP_LOG ( OPERATION, RESULTS,
334 "bdb_search: no candidates\n", 0, 0, 0 );
336 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
340 send_search_result( conn, op,
342 NULL, NULL, NULL, NULL, 0 );
348 /* if not root and candidates exceed to-be-checked entries, abort */
349 if ( !isroot && limit->lms_s_unchecked != -1 ) {
350 if ( BDB_IDL_N(candidates) > (unsigned) limit->lms_s_unchecked ) {
351 send_search_result( conn, op,
352 LDAP_ADMINLIMIT_EXCEEDED,
353 NULL, NULL, NULL, NULL, 0 );
359 if ( isroot || !limit->lms_s_pr_hide ) {
360 tentries = BDB_IDL_N(candidates);
363 if ( pagedresults ) {
364 if ( op->o_pagedresults_state.ps_cookie == 0 ) {
367 if ( op->o_pagedresults_size == 0 ) {
368 send_search_result( conn, op, LDAP_SUCCESS,
369 NULL, "search abandoned by pagedResult size=0",
373 for ( id = bdb_idl_first( candidates, &cursor );
374 id != NOID && id <= (ID)( op->o_pagedresults_state.ps_cookie );
375 id = bdb_idl_next( candidates, &cursor ) );
377 if ( cursor == NOID ) {
379 LDAP_LOG ( OPERATION, RESULTS,
380 "bdb_search: no paged results candidates\n",
383 Debug( LDAP_DEBUG_TRACE,
384 "bdb_search: no paged results candidates\n",
387 send_pagerequest_response( conn, op, lastid, 0, 0 );
395 #ifdef LDAP_CLIENT_UPDATE
396 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
397 lcupf.f_choice = LDAP_FILTER_AND;
398 lcupf.f_and = &csnfnot;
401 csnfnot.f_choice = LDAP_FILTER_NOT;
402 csnfnot.f_not = &csnfeq;
403 csnfnot.f_next = &csnfand;
405 csnfeq.f_choice = LDAP_FILTER_EQUALITY;
406 csnfeq.f_ava = &aa_eq;
407 csnfeq.f_av_desc = slap_schema.si_ad_entryCSN;
408 ber_dupbv( &csnfeq.f_av_value, &op->o_clientupdate_state );
410 csnfand.f_choice = LDAP_FILTER_AND;
411 csnfand.f_and = &csnfge;
412 csnfand.f_next = NULL;
414 csnfge.f_choice = LDAP_FILTER_GE;
415 csnfge.f_ava = &aa_ge;
416 csnfge.f_av_desc = slap_schema.si_ad_entryCSN;
417 ber_dupbv( &csnfge.f_av_value, &op->o_clientupdate_state );
418 csnfge.f_next = filter;
420 #endif /* LDAP_CLIENT_UPDATE */
422 for ( id = bdb_idl_first( candidates, &cursor );
424 id = bdb_idl_next( candidates, &cursor ) )
430 /* check for abandon */
431 if ( op->o_abandon ) {
436 /* check time limit */
437 if ( tlimit != -1 && slap_get_time() > stoptime ) {
438 send_search_result( conn, op, rc = LDAP_TIMELIMIT_EXCEEDED,
439 NULL, NULL, v2refs, NULL, nentries );
444 /* get the entry with reader lock */
445 rc = bdb_id2entry_r( be, NULL, id, &e, locker, &lock );
447 if (rc == LDAP_BUSY) {
448 send_ldap_result( conn, op, rc=LDAP_BUSY,
449 NULL, "ldap server busy", NULL, NULL );
452 } else if ( rc == DB_LOCK_DEADLOCK || rc == DB_LOCK_NOTGRANTED ) {
457 if( !BDB_IDL_IS_RANGE(candidates) ) {
458 /* only complain for non-range IDLs */
460 LDAP_LOG ( OPERATION, RESULTS,
461 "bdb_search: candidate %ld not found\n", (long) id, 0, 0);
463 Debug( LDAP_DEBUG_TRACE,
464 "bdb_search: candidate %ld not found\n",
472 #ifdef BDB_SUBENTRIES
473 if ( is_entry_subentry( e ) ) {
474 if( scope != LDAP_SCOPE_BASE ) {
475 if(!get_subentries_visibility( op )) {
476 /* only subentries are visible */
480 } else if ( get_subentries( op ) &&
481 !get_subentries_visibility( op ))
483 /* only subentries are visible */
487 } else if ( get_subentries_visibility( op )) {
488 /* only subentries are visible */
494 if ( deref & LDAP_DEREF_SEARCHING && is_entry_alias( e ) ) {
499 e = deref_entry_r( be, e, &err, &matched, &text );
506 if( e->e_id == id ) {
511 /* need to skip alias which deref into scope */
512 if( scope & LDAP_SCOPE_ONELEVEL ) {
515 dnParent( &e->e_nname, &pdn ):
516 if ( ber_bvcmp( pdn, &realbase ) ) {
520 } else if ( dnIsSuffix( &e->e_nname, &realbase ) ) {
521 /* alias is within scope */
523 LDAP_LOG ( OPERATION, RESULTS,
524 "bdb_search: \"%s\" in subtree\n", e->edn, 0, 0);
526 Debug( LDAP_DEBUG_TRACE,
527 "bdb_search: \"%s\" in subtree\n",
538 * if it's a referral, add it to the list of referrals. only do
539 * this for non-base searches, and don't check the filter
540 * explicitly here since it's only a candidate anyway.
542 if ( !manageDSAit && scope != LDAP_SCOPE_BASE &&
543 is_entry_referral( e ) )
548 if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
549 if ( !be_issuffix( be, &e->e_nname ) ) {
550 dnParent( &e->e_nname, &dn );
551 scopeok = dn_match( &dn, &realbase );
553 scopeok = (realbase.bv_len == 0);
556 } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
557 scopeok = dnIsSuffix( &e->e_nname, &realbase );
564 BerVarray erefs = get_entry_referrals(
566 BerVarray refs = referral_rewrite( erefs,
568 scope == LDAP_SCOPE_SUBTREE
572 send_search_reference( be, conn, op,
573 e, refs, NULL, &v2refs );
575 ber_bvarray_free( refs );
579 LDAP_LOG(OPERATION, DETAIL2,
580 "bdb_search: candidate referral %ld scope not okay\n",
583 Debug( LDAP_DEBUG_TRACE,
584 "bdb_search: candidate referral %ld scope not okay\n",
592 /* if it matches the filter and scope, send it */
593 #ifdef LDAP_CLIENT_UPDATE
594 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
595 rc = test_filter( be, conn, op, e, &lcupf );
597 #endif /* LDAP_CLIENT_UPDATE */
599 rc = test_filter( be, conn, op, e, filter );
602 if ( rc == LDAP_COMPARE_TRUE ) {
606 if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
607 if ( be_issuffix( be, &e->e_nname ) ) {
608 scopeok = (realbase.bv_len == 0);
610 dnParent( &e->e_nname, &dn );
611 scopeok = dn_match( &dn, &realbase );
614 } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
615 scopeok = dnIsSuffix( &e->e_nname, &realbase );
622 /* check size limit */
623 if ( --slimit == -1 ) {
624 bdb_cache_return_entry_r( bdb->bi_dbenv,
625 &bdb->bi_cache, e, &lock );
627 send_search_result( conn, op,
628 rc = LDAP_SIZELIMIT_EXCEEDED, NULL, NULL,
629 v2refs, NULL, nentries );
633 if ( pagedresults ) {
634 if ( nentries >= op->o_pagedresults_size ) {
635 send_pagerequest_response( conn, op, lastid, nentries, tentries );
644 #if 0 /* noop is masked SLAP_CTRL_UPDATE */
650 #ifdef LDAP_CLIENT_UPDATE
651 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
655 const char *text = NULL;
656 LDAPControl *ctrls[2];
657 char berbuf[LBER_ELEMENT_SIZEOF];
658 BerElement *ber = (BerElement *)berbuf;
660 ber_init2( ber, 0, LBER_USE_DER );
664 ctrls[0] = ch_malloc ( sizeof ( LDAPControl ) );
667 if ( entry_count % op->o_clientupdate_interval == 0 ) {
669 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
670 AttributeDescription *desc = a->a_desc;
671 if ( desc == slap_schema.si_ad_entryCSN ) {
672 ber_dupbv( &entrycsn_bv, &a->a_vals[0] );
673 if ( latest_entrycsn_bv.bv_val == NULL ) {
674 ber_dupbv( &latest_entrycsn_bv, &entrycsn_bv );
676 res = value_match( &ret, desc,
677 desc->ad_type->sat_ordering,
678 SLAP_MR_ASSERTION_SYNTAX_MATCH,
679 &entrycsn_bv, &latest_entrycsn_bv, &text );
680 if ( res != LDAP_SUCCESS ) {
683 LDAP_LOG ( OPERATION, RESULTS,
684 "bdb_search: value_match failed\n",
687 Debug( LDAP_DEBUG_TRACE,
688 "bdb_search: value_match failed\n",
694 ch_free( latest_entrycsn_bv.bv_val );
695 latest_entrycsn_bv.bv_val = NULL;
696 ber_dupbv( &latest_entrycsn_bv,
705 SLAP_LCUP_STATE_UPDATE_FALSE,
706 SLAP_LCUP_ENTRY_DELETED_FALSE,
707 LCUP_COOKIE_OID, &entrycsn_bv );
709 ch_free( entrycsn_bv.bv_val );
710 entrycsn_bv.bv_val = NULL;
713 /* Do not send cookie */
716 SLAP_LCUP_STATE_UPDATE_FALSE,
717 SLAP_LCUP_ENTRY_DELETED_FALSE );
720 ctrls[0]->ldctl_oid = LDAP_CONTROL_ENTRY_UPDATE;
721 ctrls[0]->ldctl_iscritical = op->o_clientupdate;
722 ret = ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 );
726 LDAP_LOG ( OPERATION, RESULTS,
727 "bdb_search: ber_flatten2 failed\n",
730 Debug( LDAP_DEBUG_TRACE,
731 "bdb_search: ber_flatten2 failed\n",
734 send_ldap_result( conn, op, rc=LDAP_OTHER,
735 NULL, "internal error", NULL, NULL );
739 result = send_search_entry( be, conn, op,
740 e, attrs, attrsonly, ctrls);
745 #endif /* LDAP_CLIENT_UPDATE */
747 result = send_search_entry( be, conn, op,
748 e, attrs, attrsonly, NULL);
753 case 0: /* entry sent ok */
756 case 1: /* entry not sent */
758 case -1: /* connection closed */
759 bdb_cache_return_entry_r(bdb->bi_dbenv,
760 &bdb->bi_cache, e, &lock);
768 LDAP_LOG ( OPERATION, RESULTS,
769 "bdb_search: %ld scope not okay\n", (long) id, 0, 0);
771 Debug( LDAP_DEBUG_TRACE,
772 "bdb_search: %ld scope not okay\n",
778 LDAP_LOG ( OPERATION, RESULTS,
779 "bdb_search: %ld does match filter\n", (long) id, 0, 0);
781 Debug( LDAP_DEBUG_TRACE,
782 "bdb_search: %ld does match filter\n",
789 /* free reader lock */
790 bdb_cache_return_entry_r( bdb->bi_dbenv,
791 &bdb->bi_cache, e , &lock);
795 ldap_pvt_thread_yield();
798 #ifdef LDAP_CLIENT_UPDATE
799 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
801 LDAPControl *ctrls[2];
802 char berbuf[LBER_ELEMENT_SIZEOF];
803 BerElement *ber = (BerElement *)berbuf;
805 ber_init2( ber, NULL, LBER_USE_DER );
807 ctrls[0] = ch_malloc ( sizeof ( LDAPControl ) );
810 ber_printf( ber, "{sO", LCUP_COOKIE_OID, &latest_entrycsn_bv );
811 ber_printf( ber, "N}" );
813 ctrls[0]->ldctl_oid = LDAP_CONTROL_CLIENT_UPDATE_DONE;
814 ctrls[0]->ldctl_iscritical = op->o_clientupdate;
815 ret = ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 );
820 LDAP_LOG ( OPERATION, RESULTS,
821 "bdb_search: ber_flatten2 failed\n", 0, 0, 0 );
823 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_flatten2 failed\n",
826 send_ldap_result( conn, op, rc=LDAP_OTHER,
827 NULL, "internal error", NULL, NULL );
831 send_search_result( conn, op,
832 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
833 NULL, NULL, v2refs, ctrls, nentries );
835 ch_free( latest_entrycsn_bv.bv_val );
836 latest_entrycsn_bv.bv_val = NULL;
840 #endif /* LDAP_CLIENT_UPDATE */
842 send_search_result( conn, op,
843 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
844 NULL, NULL, v2refs, NULL, nentries );
851 /* free reader lock */
852 bdb_cache_return_entry_r ( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
855 #ifdef LDAP_CLIENT_UPDATE
856 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
857 if ( csnfeq.f_ava != NULL && csnfeq.f_av_value.bv_val != NULL ) {
858 ch_free( csnfeq.f_av_value.bv_val );
861 if ( csnfge.f_ava != NULL && csnfge.f_av_value.bv_val != NULL ) {
862 ch_free( csnfge.f_av_value.bv_val );
865 #endif /* LDAP_CLIENT_UPDATE */
867 LOCK_ID_FREE (bdb->bi_dbenv, locker );
869 if( v2refs ) ber_bvarray_free( v2refs );
870 if( realbase.bv_val ) ch_free( realbase.bv_val );
876 static int base_candidate(
882 LDAP_LOG ( OPERATION, ENTRY,
883 "base_candidate: base: \"%s\" (0x%08lx)\n", e->e_dn, (long) e->e_id, 0);
885 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
886 e->e_dn, (long) e->e_id, 0);
894 /* Look for "objectClass Present" in this filter.
895 * Also count depth of filter tree while we're at it.
897 static int oc_filter(
905 if( cur > *max ) *max = cur;
907 switch(f->f_choice) {
908 case LDAP_FILTER_PRESENT:
909 if (f->f_desc == slap_schema.si_ad_objectClass) {
914 case LDAP_FILTER_AND:
917 for (f=f->f_and; f; f=f->f_next) {
918 (void) oc_filter(f, cur, max);
928 static void search_stack_free( void *key, void *data)
933 static void *search_stack(
938 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
941 if ( op->o_threadctx ) {
942 ldap_pvt_thread_pool_getkey( op->o_threadctx, search_stack,
945 ret = bdb->bi_search_stack;
949 ret = ch_malloc( bdb->bi_search_stack_depth * BDB_IDL_UM_SIZE * sizeof( ID ) );
950 if ( op->o_threadctx ) {
951 ldap_pvt_thread_pool_setkey( op->o_threadctx, search_stack,
952 ret, search_stack_free );
954 bdb->bi_search_stack = ret;
960 static int search_candidates(
969 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
971 Filter f, scopef, rf, xf;
973 AttributeAssertion aa_ref;
974 #ifdef BDB_SUBENTRIES
976 AttributeAssertion aa_subentry;
980 AttributeAssertion aa_alias;
984 * This routine takes as input a filter (user-filter)
985 * and rewrites it as follows:
986 * (&(scope=DN)[(objectClass=subentry)]
987 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
991 LDAP_LOG ( OPERATION, ENTRY,
992 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
993 e->e_dn, (long) e->e_id, scope);
995 Debug(LDAP_DEBUG_TRACE,
996 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
997 e->e_dn, (long) e->e_id, scope );
1001 xf.f_choice = LDAP_FILTER_OR;
1004 /* If the user's filter uses objectClass=*,
1005 * these clauses are redundant.
1007 if (!oc_filter(filter, 1, &depth) && !get_subentries_visibility(op) ) {
1008 if( !get_manageDSAit(op) ) { /* match referrals */
1009 struct berval bv_ref = { sizeof("referral")-1, "referral" };
1010 rf.f_choice = LDAP_FILTER_EQUALITY;
1012 rf.f_av_desc = slap_schema.si_ad_objectClass;
1013 rf.f_av_value = bv_ref;
1014 rf.f_next = xf.f_or;
1019 if( deref & LDAP_DEREF_SEARCHING ) { /* match aliases */
1020 struct berval bv_alias = { sizeof("alias")-1, "alias" };
1021 af.f_choice = LDAP_FILTER_EQUALITY;
1022 af.f_ava = &aa_alias;
1023 af.f_av_desc = slap_schema.si_ad_objectClass;
1024 af.f_av_value = bv_alias;
1025 af.f_next = xf.f_or;
1029 /* We added one of these clauses, filter depth increased */
1030 if( xf.f_or != filter ) depth++;
1034 f.f_choice = LDAP_FILTER_AND;
1036 scopef.f_choice = scope == LDAP_SCOPE_SUBTREE
1037 ? SLAPD_FILTER_DN_SUBTREE
1038 : SLAPD_FILTER_DN_ONE;
1039 scopef.f_dn = &e->e_nname;
1040 scopef.f_next = xf.f_or == filter ? filter : &xf ;
1041 /* Filter depth increased again, adding scope clause */
1044 #ifdef BDB_SUBENTRIES
1045 if( get_subentries_visibility( op ) ) {
1046 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1047 sf.f_choice = LDAP_FILTER_EQUALITY;
1048 sf.f_ava = &aa_subentry;
1049 sf.f_av_desc = slap_schema.si_ad_objectClass;
1050 sf.f_av_value = bv_subentry;
1051 sf.f_next = scopef.f_next;
1052 scopef.f_next = &sf;
1056 /* Allocate IDL stack, plus 1 more for former tmp */
1057 if ( depth+1 > bdb->bi_search_stack_depth ) {
1058 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1060 stack = search_stack( be, op );
1063 rc = bdb_filter_candidates( be, &f, ids, stack, stack+BDB_IDL_UM_SIZE );
1065 if ( depth+1 > bdb->bi_search_stack_depth ) {
1071 LDAP_LOG ( OPERATION, DETAIL1,
1072 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1074 Debug(LDAP_DEBUG_TRACE,
1075 "bdb_search_candidates: failed (rc=%d)\n",
1081 LDAP_LOG ( OPERATION, DETAIL1,
1082 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1083 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1084 (long) BDB_IDL_LAST(ids));
1086 Debug(LDAP_DEBUG_TRACE,
1087 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1089 (long) BDB_IDL_FIRST(ids),
1090 (long) BDB_IDL_LAST(ids) );
1098 send_pagerequest_response(
1105 LDAPControl ctrl, *ctrls[2];
1106 char berbuf[LBER_ELEMENT_SIZEOF];
1107 BerElement *ber = (BerElement *)berbuf;
1108 struct berval cookie = { 0, NULL };
1109 PagedResultsCookie respcookie;
1112 LDAP_LOG ( OPERATION, ENTRY,
1113 "send_pagerequest_response: lastid: (0x%08lx) "
1114 "nentries: (0x%081x)\n",
1115 lastid, nentries, NULL );
1117 Debug(LDAP_DEBUG_ARGS, "send_pagerequest_response: lastid: (0x%08lx) "
1118 "nentries: (0x%081x)\n", lastid, nentries, NULL );
1121 ctrl.ldctl_value.bv_val = NULL;
1125 ber_init2( ber, NULL, LBER_USE_DER );
1127 respcookie = ( PagedResultsCookie )lastid;
1128 conn->c_pagedresults_state.ps_cookie = respcookie;
1129 cookie.bv_len = sizeof( respcookie );
1130 cookie.bv_val = (char *)&respcookie;
1133 * FIXME: we should consider sending an estimate of the entries
1134 * left, after appropriate security check is done
1136 ber_printf( ber, "{iO}", tentries, &cookie );
1138 if ( ber_flatten2( ber, &ctrls[0]->ldctl_value, 0 ) == LBER_ERROR ) {
1142 ctrls[0]->ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
1143 ctrls[0]->ldctl_iscritical = 0;
1145 send_search_result( conn, op,
1147 NULL, NULL, NULL, ctrls, nentries );
1150 (void) ber_free_buf( ber );