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];
659 BerElement *ber = ber_alloc_t( LBER_USE_DER );
663 LDAP_LOG ( OPERATION, RESULTS,
664 "bdb_search: ber_alloc_t failed\n",
667 Debug( LDAP_DEBUG_TRACE,
668 "bdb_search: ber_alloc_t failed\n",
671 send_ldap_result( conn, op, rc=LDAP_OTHER,
672 NULL, "internal error", NULL, NULL );
678 ctrls[0] = ch_malloc ( sizeof ( LDAPControl ) );
681 if ( entry_count % op->o_clientupdate_interval == 0 ) {
683 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
684 AttributeDescription *desc = a->a_desc;
685 if ( desc == slap_schema.si_ad_entryCSN ) {
686 ber_dupbv( &entrycsn_bv, &a->a_vals[0] );
687 if ( latest_entrycsn_bv.bv_val == NULL ) {
688 ber_dupbv( &latest_entrycsn_bv, &entrycsn_bv );
690 res = value_match( &ret, desc,
691 desc->ad_type->sat_ordering,
692 SLAP_MR_ASSERTION_SYNTAX_MATCH,
693 &entrycsn_bv, &latest_entrycsn_bv, &text );
694 if ( res != LDAP_SUCCESS ) {
697 LDAP_LOG ( OPERATION, RESULTS,
698 "bdb_search: value_match failed\n",
701 Debug( LDAP_DEBUG_TRACE,
702 "bdb_search: value_match failed\n",
708 ch_free( latest_entrycsn_bv.bv_val );
709 latest_entrycsn_bv.bv_val = NULL;
710 ber_dupbv( &latest_entrycsn_bv,
719 SLAP_LCUP_STATE_UPDATE_FALSE,
720 SLAP_LCUP_ENTRY_DELETED_FALSE,
721 LCUP_COOKIE_OID, &entrycsn_bv );
723 ch_free( entrycsn_bv.bv_val );
724 entrycsn_bv.bv_val = NULL;
727 /* Do not send cookie */
730 SLAP_LCUP_STATE_UPDATE_FALSE,
731 SLAP_LCUP_ENTRY_DELETED_FALSE );
734 ctrls[0]->ldctl_oid = LDAP_CONTROL_ENTRY_UPDATE;
735 ctrls[0]->ldctl_iscritical = op->o_clientupdate;
736 ret = ber_flatten( ber, &bv );
740 LDAP_LOG ( OPERATION, RESULTS,
741 "bdb_search: ber_flatten failed\n",
744 Debug( LDAP_DEBUG_TRACE,
745 "bdb_search: ber_flatten failed\n",
748 send_ldap_result( conn, op, rc=LDAP_OTHER,
749 NULL, "internal error", NULL, NULL );
753 ber_dupbv( &ctrls[0]->ldctl_value, bv );
755 result = send_search_entry( be, conn, op,
756 e, attrs, attrsonly, ctrls);
758 ch_free( ctrls[0]->ldctl_value.bv_val );
763 #endif /* LDAP_CLIENT_UPDATE */
765 result = send_search_entry( be, conn, op,
766 e, attrs, attrsonly, NULL);
771 case 0: /* entry sent ok */
774 case 1: /* entry not sent */
776 case -1: /* connection closed */
777 bdb_cache_return_entry_r(bdb->bi_dbenv,
778 &bdb->bi_cache, e, &lock);
786 LDAP_LOG ( OPERATION, RESULTS,
787 "bdb_search: %ld scope not okay\n", (long) id, 0, 0);
789 Debug( LDAP_DEBUG_TRACE,
790 "bdb_search: %ld scope not okay\n",
796 LDAP_LOG ( OPERATION, RESULTS,
797 "bdb_search: %ld does match filter\n", (long) id, 0, 0);
799 Debug( LDAP_DEBUG_TRACE,
800 "bdb_search: %ld does match filter\n",
807 /* free reader lock */
808 bdb_cache_return_entry_r( bdb->bi_dbenv,
809 &bdb->bi_cache, e , &lock);
813 ldap_pvt_thread_yield();
816 #ifdef LDAP_CLIENT_UPDATE
817 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
819 LDAPControl *ctrls[2];
820 BerElement *ber = ber_alloc_t( LBER_USE_DER );
825 LDAP_LOG ( OPERATION, RESULTS,
826 "bdb_search: ber_alloc_t failed\n", 0, 0, 0 );
828 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_alloc_t failed\n",
831 send_ldap_result( conn, op, rc=LDAP_OTHER,
832 NULL, "internal error", NULL, NULL );
836 ctrls[0] = ch_malloc ( sizeof ( LDAPControl ) );
839 ber_printf( ber, "{sO", LCUP_COOKIE_OID, &latest_entrycsn_bv );
840 ber_printf( ber, "N}" );
842 ctrls[0]->ldctl_oid = LDAP_CONTROL_CLIENT_UPDATE_DONE;
843 ctrls[0]->ldctl_iscritical = op->o_clientupdate;
844 ret = ber_flatten( ber, &bv );
848 LDAP_LOG ( OPERATION, RESULTS,
849 "bdb_search: ber_flatten failed\n", 0, 0, 0 );
851 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_flatten failed\n",
854 send_ldap_result( conn, op, rc=LDAP_OTHER,
855 NULL, "internal error", NULL, NULL );
859 ber_dupbv( &ctrls[0]->ldctl_value, bv );
861 send_search_result( conn, op,
862 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
863 NULL, NULL, v2refs, ctrls, nentries );
865 ch_free( latest_entrycsn_bv.bv_val );
866 latest_entrycsn_bv.bv_val = NULL;
867 ch_free( ctrls[0]->ldctl_value.bv_val );
872 #endif /* LDAP_CLIENT_UPDATE */
874 send_search_result( conn, op,
875 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
876 NULL, NULL, v2refs, NULL, nentries );
883 /* free reader lock */
884 bdb_cache_return_entry_r ( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
887 #ifdef LDAP_CLIENT_UPDATE
888 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
889 if ( csnfeq.f_ava != NULL && csnfeq.f_av_value.bv_val != NULL ) {
890 ch_free( csnfeq.f_av_value.bv_val );
893 if ( csnfge.f_ava != NULL && csnfge.f_av_value.bv_val != NULL ) {
894 ch_free( csnfge.f_av_value.bv_val );
897 #endif /* LDAP_CLIENT_UPDATE */
899 LOCK_ID_FREE (bdb->bi_dbenv, locker );
901 if( v2refs ) ber_bvarray_free( v2refs );
902 if( realbase.bv_val ) ch_free( realbase.bv_val );
908 static int base_candidate(
914 LDAP_LOG ( OPERATION, ENTRY,
915 "base_candidate: base: \"%s\" (0x%08lx)\n", e->e_dn, (long) e->e_id, 0);
917 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
918 e->e_dn, (long) e->e_id, 0);
926 /* Look for "objectClass Present" in this filter.
927 * Also count depth of filter tree while we're at it.
929 static int oc_filter(
937 if( cur > *max ) *max = cur;
939 switch(f->f_choice) {
940 case LDAP_FILTER_PRESENT:
941 if (f->f_desc == slap_schema.si_ad_objectClass) {
946 case LDAP_FILTER_AND:
949 for (f=f->f_and; f; f=f->f_next) {
950 (void) oc_filter(f, cur, max);
960 static int search_candidates(
970 Filter f, scopef, rf, xf;
972 AttributeAssertion aa_ref;
973 #ifdef BDB_SUBENTRIES
975 AttributeAssertion aa_subentry;
979 AttributeAssertion aa_alias;
983 * This routine takes as input a filter (user-filter)
984 * and rewrites it as follows:
985 * (&(scope=DN)[(objectClass=subentry)]
986 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
990 LDAP_LOG ( OPERATION, ENTRY,
991 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
992 e->e_dn, (long) e->e_id, scope);
994 Debug(LDAP_DEBUG_TRACE,
995 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
996 e->e_dn, (long) e->e_id, scope );
1000 xf.f_choice = LDAP_FILTER_OR;
1003 /* If the user's filter uses objectClass=*,
1004 * these clauses are redundant.
1006 if (!oc_filter(filter, 1, &depth) && !get_subentries_visibility(op) ) {
1007 if( !get_manageDSAit(op) ) { /* match referrals */
1008 struct berval bv_ref = { sizeof("referral")-1, "referral" };
1009 rf.f_choice = LDAP_FILTER_EQUALITY;
1011 rf.f_av_desc = slap_schema.si_ad_objectClass;
1012 rf.f_av_value = bv_ref;
1013 rf.f_next = xf.f_or;
1018 if( deref & LDAP_DEREF_SEARCHING ) { /* match aliases */
1019 struct berval bv_alias = { sizeof("alias")-1, "alias" };
1020 af.f_choice = LDAP_FILTER_EQUALITY;
1021 af.f_ava = &aa_alias;
1022 af.f_av_desc = slap_schema.si_ad_objectClass;
1023 af.f_av_value = bv_alias;
1024 af.f_next = xf.f_or;
1028 /* We added one of these clauses, filter depth increased */
1029 if( xf.f_or != filter ) depth++;
1033 f.f_choice = LDAP_FILTER_AND;
1035 scopef.f_choice = scope == LDAP_SCOPE_SUBTREE
1036 ? SLAPD_FILTER_DN_SUBTREE
1037 : SLAPD_FILTER_DN_ONE;
1038 scopef.f_dn = &e->e_nname;
1039 scopef.f_next = xf.f_or == filter ? filter : &xf ;
1040 /* Filter depth increased again, adding scope clause */
1043 #ifdef BDB_SUBENTRIES
1044 if( get_subentries_visibility( op ) ) {
1045 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1046 sf.f_choice = LDAP_FILTER_EQUALITY;
1047 sf.f_ava = &aa_subentry;
1048 sf.f_av_desc = slap_schema.si_ad_objectClass;
1049 sf.f_av_value = bv_subentry;
1050 sf.f_next = scopef.f_next;
1051 scopef.f_next = &sf;
1055 /* Allocate IDL stack, plus 1 more for former tmp */
1056 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1058 rc = bdb_filter_candidates( be, &f, ids, stack, stack+BDB_IDL_UM_SIZE );
1064 LDAP_LOG ( OPERATION, DETAIL1,
1065 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1067 Debug(LDAP_DEBUG_TRACE,
1068 "bdb_search_candidates: failed (rc=%d)\n",
1074 LDAP_LOG ( OPERATION, DETAIL1,
1075 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1076 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1077 (long) BDB_IDL_LAST(ids));
1079 Debug(LDAP_DEBUG_TRACE,
1080 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1082 (long) BDB_IDL_FIRST(ids),
1083 (long) BDB_IDL_LAST(ids) );
1091 send_pagerequest_response(
1098 LDAPControl ctrl, *ctrls[2];
1100 struct berval *bvalp, cookie = { 0, NULL };
1101 PagedResultsCookie respcookie;
1104 LDAP_LOG ( OPERATION, ENTRY,
1105 "send_pagerequest_response: lastid: (0x%08lx) "
1106 "nentries: (0x%081x)\n",
1109 Debug(LDAP_DEBUG_ARGS, "send_pagerequest_response: lastid: (0x%08lx) "
1110 "nentries: (0x%081x)\n", lastid, nentries, NULL );
1113 ctrl.ldctl_value.bv_val = NULL;
1117 if (( ber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
1121 respcookie = ( PagedResultsCookie )lastid;
1122 conn->c_pagedresults_state.ps_cookie = respcookie;
1123 cookie.bv_len = sizeof( respcookie );
1124 cookie.bv_val = (char *)&respcookie;
1127 * FIXME: we should consider sending an estimate of the entries
1128 * left, after appropriate security check is done
1130 ber_printf( ber, "{iO}", tentries, &cookie );
1132 if ( ber_flatten( ber, &bvalp ) == LBER_ERROR ) {
1136 ctrls[0]->ldctl_oid = LDAP_CONTROL_PAGEDRESULTS;
1137 ctrls[0]->ldctl_value = ( *bvalp );
1138 ctrls[0]->ldctl_iscritical = 0;
1140 send_search_result( conn, op,
1142 NULL, NULL, NULL, ctrls, nentries );
1145 (void) ber_free( ber, 1 );
1146 if ( ctrls[0]->ldctl_value.bv_val ) {
1147 ch_free( ctrls[0]->ldctl_value.bv_val );