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 #ifdef LDAP_CONTROL_PAGEDRESULTS
30 static void send_pagerequest_response(
35 #endif /* LDAP_CONTROL_PAGEDRESULTS */
49 struct berval *filterstr,
53 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
55 const char *text = NULL;
58 ID candidates[BDB_IDL_UM_SIZE];
60 BerVarray v2refs = NULL;
61 Entry *matched = NULL;
62 struct berval realbase = { 0, NULL };
65 #ifdef LDAP_CONTROL_PAGEDRESULTS
68 #endif /* LDAP_CONTROL_PAGEDRESULTS */
70 #ifdef LDAP_CLIENT_UPDATE
71 Filter lcupf, csnfnot, csnfeq, csnfand, csnfge;
72 AttributeAssertion aa_ge, aa_eq;
74 struct berval entrycsn_bv = { 0, NULL };
75 struct berval latest_entrycsn_bv = { 0, NULL };
76 #endif /* LDAP_CLIENT_UPDATE */
78 struct slap_limits_set *limit = NULL;
85 LDAP_LOG ( OPERATION, ENTRY, "bdb_back_search\n", 0, 0, 0 );
87 Debug( LDAP_DEBUG_TRACE, "=> bdb_back_search\n",
91 #ifdef LDAP_CLIENT_UPDATE
92 if ( op->o_clientupdate_type & SLAP_LCUP_PERSIST ) {
93 bdb_add_psearch_spec( be, conn, op, base, base, scope,
94 deref, slimit, tlimit, filter, filterstr, attrs, attrsonly );
100 manageDSAit = get_manageDSAit( op );
102 #ifdef LDAP_CONTROL_PAGEDRESULTS
103 pagedresults = get_pagedresults( op );
104 #endif /* LDAP_CONTROL_PAGEDRESULTS */
106 rc = LOCK_ID (bdb->bi_dbenv, &locker );
111 send_ldap_result( conn, op, rc=LDAP_OTHER,
112 NULL, "internal error", NULL, NULL );
116 if ( nbase->bv_len == 0 ) {
117 /* DIT root special case */
118 e = (Entry *) &slap_entry_root;
122 /* get entry with reader lock */
123 if ( deref & LDAP_DEREF_FINDING ) {
124 e = deref_dn_r( be, nbase-, &err, &matched, &text );
130 rc = bdb_dn2entry_r( be, NULL, nbase, &e, &matched, 0, locker, &lock );
139 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
141 if (matched != NULL) {
142 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
144 send_ldap_result( conn, op, LDAP_BUSY,
145 NULL, "ldap server busy", NULL, NULL );
146 LOCK_ID_FREE (bdb->bi_dbenv, locker );
148 case DB_LOCK_DEADLOCK:
149 case DB_LOCK_NOTGRANTED:
153 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
155 if (matched != NULL) {
156 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
158 send_ldap_result( conn, op, rc=LDAP_OTHER,
159 NULL, "internal error", NULL, NULL );
160 LOCK_ID_FREE (bdb->bi_dbenv, locker );
165 struct berval matched_dn = { 0, NULL };
166 BerVarray refs = NULL;
168 if ( matched != NULL ) {
170 ber_dupbv( &matched_dn, &matched->e_name );
172 erefs = is_entry_referral( matched )
173 ? get_entry_referrals( be, conn, op, matched )
176 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
180 refs = referral_rewrite( erefs, &matched_dn,
182 ber_bvarray_free( erefs );
186 refs = referral_rewrite( default_referral,
190 send_ldap_result( conn, op, rc=LDAP_REFERRAL ,
191 matched_dn.bv_val, text, refs, NULL );
193 LOCK_ID_FREE (bdb->bi_dbenv, locker );
194 if ( refs ) ber_bvarray_free( refs );
195 if ( matched_dn.bv_val ) ber_memfree( matched_dn.bv_val );
199 if (!manageDSAit && e != &slap_entry_root && is_entry_referral( e ) ) {
200 /* entry is a referral, don't allow add */
201 struct berval matched_dn;
202 BerVarray erefs, refs;
204 ber_dupbv( &matched_dn, &e->e_name );
205 erefs = get_entry_referrals( be, conn, op, e );
208 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
212 refs = referral_rewrite( erefs, &matched_dn,
214 ber_bvarray_free( erefs );
218 LDAP_LOG ( OPERATION, RESULTS,
219 "bdb_search: entry is referral\n", 0, 0, 0 );
221 Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
225 send_ldap_result( conn, op, LDAP_REFERRAL,
227 refs ? NULL : "bad referral object",
230 LOCK_ID_FREE (bdb->bi_dbenv, locker );
231 ber_bvarray_free( refs );
232 ber_memfree( matched_dn.bv_val );
236 /* if not root, get appropriate limits */
237 if ( be_isroot( be, &op->o_ndn ) ) {
240 ( void ) get_limits( be, &op->o_ndn, &limit );
243 /* The time/size limits come first because they require very little
244 * effort, so there's no chance the candidates are selected and then
245 * the request is not honored only because of time/size constraints */
247 /* if no time limit requested, use soft limit (unless root!) */
250 tlimit = -1; /* allow root to set no limit */
258 /* if no limit is required, use soft limit */
260 tlimit = limit->lms_t_soft;
262 /* if requested limit higher than hard limit, abort */
263 } else if ( tlimit > limit->lms_t_hard ) {
264 /* no hard limit means use soft instead */
265 if ( limit->lms_t_hard == 0 && tlimit > limit->lms_t_soft ) {
266 tlimit = limit->lms_t_soft;
268 /* positive hard limit means abort */
269 } else if ( limit->lms_t_hard > 0 ) {
270 send_search_result( conn, op,
271 LDAP_UNWILLING_TO_PERFORM,
272 NULL, NULL, NULL, NULL, 0 );
277 /* negative hard limit means no limit */
280 /* if no limit is required, use soft limit */
282 slimit = limit->lms_s_soft;
284 /* if requested limit higher than hard limit, abort */
285 } else if ( slimit > limit->lms_s_hard ) {
286 /* no hard limit means use soft instead */
287 if ( limit->lms_s_hard == 0 && slimit > limit->lms_s_soft ) {
288 slimit = limit->lms_s_soft;
290 /* positive hard limit means abort */
291 } else if ( limit->lms_s_hard > 0 ) {
292 send_search_result( conn, op,
293 LDAP_UNWILLING_TO_PERFORM,
294 NULL, NULL, NULL, NULL, 0 );
299 /* negative hard limit means no limit */
303 /* compute it anyway; root does not use it */
304 stoptime = op->o_time + tlimit;
306 /* select candidates */
307 if ( scope == LDAP_SCOPE_BASE ) {
308 rc = base_candidate( be, e, candidates );
311 BDB_IDL_ALL( bdb, candidates );
312 rc = search_candidates( be, op, e, filter,
313 scope, deref, candidates );
316 /* need normalized dn below */
317 ber_dupbv( &realbase, &e->e_nname );
319 /* start cursor at beginning of candidates.
323 if ( e != &slap_entry_root ) {
324 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
328 if ( candidates[0] == 0 ) {
330 LDAP_LOG ( OPERATION, RESULTS,
331 "bdb_search: no candidates\n", 0, 0, 0 );
333 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
337 send_search_result( conn, op,
339 NULL, NULL, NULL, NULL, 0 );
345 /* if not root and candidates exceed to-be-checked entries, abort */
346 if ( !isroot && limit->lms_s_unchecked != -1 ) {
347 if ( BDB_IDL_N(candidates) > (unsigned) limit->lms_s_unchecked ) {
348 send_search_result( conn, op,
349 LDAP_ADMINLIMIT_EXCEEDED,
350 NULL, NULL, NULL, NULL, 0 );
356 #ifdef LDAP_CONTROL_PAGEDRESULTS
357 if ( pagedresults ) {
358 if ( op->o_pagedresults_state.ps_cookie == 0 ) {
361 for ( id = bdb_idl_first( candidates, &cursor );
362 id != NOID && id <= (ID)( op->o_pagedresults_state.ps_cookie );
363 id = bdb_idl_next( candidates, &cursor ) );
365 if ( cursor == NOID ) {
367 LDAP_LOG ( OPERATION, RESULTS,
368 "bdb_search: no paged results candidates\n",
371 Debug( LDAP_DEBUG_TRACE,
372 "bdb_search: no paged results candidates\n",
375 send_pagerequest_response( conn, op, lastid, 0 );
382 #endif /* LDAP_CONTROL_PAGEDRESULTS */
384 #ifdef LDAP_CLIENT_UPDATE
385 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
386 lcupf.f_choice = LDAP_FILTER_AND;
387 lcupf.f_and = &csnfnot;
390 csnfnot.f_choice = LDAP_FILTER_NOT;
391 csnfnot.f_not = &csnfeq;
392 csnfnot.f_next = &csnfand;
394 csnfeq.f_choice = LDAP_FILTER_EQUALITY;
395 csnfeq.f_ava = &aa_eq;
396 csnfeq.f_av_desc = slap_schema.si_ad_entryCSN;
397 ber_dupbv( &csnfeq.f_av_value, &op->o_clientupdate_state );
399 csnfand.f_choice = LDAP_FILTER_AND;
400 csnfand.f_and = &csnfge;
401 csnfand.f_next = NULL;
403 csnfge.f_choice = LDAP_FILTER_GE;
404 csnfge.f_ava = &aa_ge;
405 csnfge.f_av_desc = slap_schema.si_ad_entryCSN;
406 ber_dupbv( &csnfge.f_av_value, &op->o_clientupdate_state );
407 csnfge.f_next = filter;
409 #endif /* LDAP_CLIENT_UPDATE */
411 for ( id = bdb_idl_first( candidates, &cursor );
413 id = bdb_idl_next( candidates, &cursor ) )
418 #ifdef LDAP_CONTROL_PAGEDRESULTS
420 #endif /* LDAP_CONTROL_PAGEDRESULTS */
422 /* check for abandon */
423 if ( op->o_abandon ) {
428 /* check time limit */
429 if ( tlimit != -1 && slap_get_time() > stoptime ) {
430 send_search_result( conn, op, rc = LDAP_TIMELIMIT_EXCEEDED,
431 NULL, NULL, v2refs, NULL, nentries );
436 /* get the entry with reader lock */
437 rc = bdb_id2entry_r( be, NULL, id, &e, locker, &lock );
439 if (rc == LDAP_BUSY) {
440 send_ldap_result( conn, op, rc=LDAP_BUSY,
441 NULL, "ldap server busy", NULL, NULL );
444 } else if ( rc == DB_LOCK_DEADLOCK || rc == DB_LOCK_NOTGRANTED ) {
449 if( !BDB_IDL_IS_RANGE(candidates) ) {
450 /* only complain for non-range IDLs */
452 LDAP_LOG ( OPERATION, RESULTS,
453 "bdb_search: candidate %ld not found\n", (long) id, 0, 0);
455 Debug( LDAP_DEBUG_TRACE,
456 "bdb_search: candidate %ld not found\n",
464 #ifdef BDB_SUBENTRIES
465 if ( is_entry_subentry( e ) ) {
466 if( scope != LDAP_SCOPE_BASE ) {
467 if(!get_subentries_visibility( op )) {
468 /* only subentries are visible */
472 } else if ( get_subentries( op ) &&
473 !get_subentries_visibility( op ))
475 /* only subentries are visible */
479 } else if ( get_subentries_visibility( op )) {
480 /* only subentries are visible */
486 if ( deref & LDAP_DEREF_SEARCHING && is_entry_alias( e ) ) {
491 e = deref_entry_r( be, e, &err, &matched, &text );
498 if( e->e_id == id ) {
503 /* need to skip alias which deref into scope */
504 if( scope & LDAP_SCOPE_ONELEVEL ) {
507 dnParent( &e->e_nname, &pdn ):
508 if ( ber_bvcmp( pdn, &realbase ) ) {
512 } else if ( dnIsSuffix( &e->e_nname, &realbase ) ) {
513 /* alias is within scope */
515 LDAP_LOG ( OPERATION, RESULTS,
516 "bdb_search: \"%s\" in subtree\n", e->edn, 0, 0);
518 Debug( LDAP_DEBUG_TRACE,
519 "bdb_search: \"%s\" in subtree\n",
530 * if it's a referral, add it to the list of referrals. only do
531 * this for non-base searches, and don't check the filter
532 * explicitly here since it's only a candidate anyway.
534 if ( !manageDSAit && scope != LDAP_SCOPE_BASE &&
535 is_entry_referral( e ) )
540 if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
541 if ( !be_issuffix( be, &e->e_nname ) ) {
542 dnParent( &e->e_nname, &dn );
543 scopeok = dn_match( &dn, &realbase );
545 scopeok = (realbase.bv_len == 0);
548 } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
549 scopeok = dnIsSuffix( &e->e_nname, &realbase );
556 BerVarray erefs = get_entry_referrals(
558 BerVarray refs = referral_rewrite( erefs,
560 scope == LDAP_SCOPE_SUBTREE
564 send_search_reference( be, conn, op,
565 e, refs, NULL, &v2refs );
567 ber_bvarray_free( refs );
571 LDAP_LOG(OPERATION, DETAIL2,
572 "bdb_search: candidate referral %ld scope not okay\n",
575 Debug( LDAP_DEBUG_TRACE,
576 "bdb_search: candidate referral %ld scope not okay\n",
584 /* if it matches the filter and scope, send it */
585 #ifdef LDAP_CLIENT_UPDATE
586 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
587 rc = test_filter( be, conn, op, e, &lcupf );
589 #endif /* LDAP_CLIENT_UPDATE */
591 rc = test_filter( be, conn, op, e, filter );
594 if ( rc == LDAP_COMPARE_TRUE ) {
598 if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
599 if ( be_issuffix( be, &e->e_nname ) ) {
600 scopeok = (realbase.bv_len == 0);
602 dnParent( &e->e_nname, &dn );
603 scopeok = dn_match( &dn, &realbase );
606 } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
607 scopeok = dnIsSuffix( &e->e_nname, &realbase );
614 /* check size limit */
615 if ( --slimit == -1 ) {
616 bdb_cache_return_entry_r( bdb->bi_dbenv,
617 &bdb->bi_cache, e, &lock );
619 send_search_result( conn, op,
620 rc = LDAP_SIZELIMIT_EXCEEDED, NULL, NULL,
621 v2refs, NULL, nentries );
624 #ifdef LDAP_CONTROL_PAGEDRESULTS
625 if ( pagedresults ) {
626 if ( nentries >= op->o_pagedresults_size ) {
627 send_pagerequest_response( conn, op, lastid, nentries );
632 #endif /* LDAP_CONTROL_PAGEDRESULTS */
637 #if 0 /* noop is masked SLAP_CTRL_UPDATE */
643 #ifdef LDAP_CLIENT_UPDATE
644 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
648 const char *text = NULL;
649 LDAPControl *ctrls[2];
652 BerElement *ber = ber_alloc_t( LBER_USE_DER );
656 LDAP_LOG ( OPERATION, RESULTS,
657 "bdb_search: ber_alloc_t failed\n",
660 Debug( LDAP_DEBUG_TRACE,
661 "bdb_search: ber_alloc_t failed\n",
664 send_ldap_result( conn, op, rc=LDAP_OTHER,
665 NULL, "internal error", NULL, NULL );
671 ctrls[0] = ch_malloc ( sizeof ( LDAPControl ) );
674 if ( entry_count % op->o_clientupdate_interval == 0 ) {
676 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
677 AttributeDescription *desc = a->a_desc;
678 if ( desc == slap_schema.si_ad_entryCSN ) {
679 ber_dupbv( &entrycsn_bv, &a->a_vals[0] );
680 if ( latest_entrycsn_bv.bv_val == NULL ) {
681 ber_dupbv( &latest_entrycsn_bv, &entrycsn_bv );
683 res = value_match( &ret, desc,
684 desc->ad_type->sat_ordering,
685 SLAP_MR_ASSERTION_SYNTAX_MATCH,
686 &entrycsn_bv, &latest_entrycsn_bv, &text );
687 if ( res != LDAP_SUCCESS ) {
690 LDAP_LOG ( OPERATION, RESULTS,
691 "bdb_search: value_match failed\n",
694 Debug( LDAP_DEBUG_TRACE,
695 "bdb_search: value_match failed\n",
701 ch_free( latest_entrycsn_bv.bv_val );
702 latest_entrycsn_bv.bv_val = NULL;
703 ber_dupbv( &latest_entrycsn_bv,
712 SLAP_LCUP_STATE_UPDATE_FALSE,
713 SLAP_LCUP_ENTRY_DELETED_FALSE,
714 LCUP_COOKIE_OID, &entrycsn_bv );
716 ch_free( entrycsn_bv.bv_val );
717 entrycsn_bv.bv_val = NULL;
720 /* Do not send cookie */
723 SLAP_LCUP_STATE_UPDATE_FALSE,
724 SLAP_LCUP_ENTRY_DELETED_FALSE );
727 ctrls[0]->ldctl_oid = LDAP_CONTROL_ENTRY_UPDATE;
728 ctrls[0]->ldctl_iscritical = op->o_clientupdate;
729 ret = ber_flatten( ber, &bv );
733 LDAP_LOG ( OPERATION, RESULTS,
734 "bdb_search: ber_flatten failed\n",
737 Debug( LDAP_DEBUG_TRACE,
738 "bdb_search: ber_flatten failed\n",
741 send_ldap_result( conn, op, rc=LDAP_OTHER,
742 NULL, "internal error", NULL, NULL );
746 ber_dupbv( &ctrls[0]->ldctl_value, bv );
748 result = send_search_entry( be, conn, op,
749 e, attrs, attrsonly, ctrls);
751 ch_free( ctrls[0]->ldctl_value.bv_val );
756 #endif /* LDAP_CLIENT_UPDATE */
758 result = send_search_entry( be, conn, op,
759 e, attrs, attrsonly, NULL);
764 case 0: /* entry sent ok */
767 case 1: /* entry not sent */
769 case -1: /* connection closed */
770 bdb_cache_return_entry_r(bdb->bi_dbenv,
771 &bdb->bi_cache, e, &lock);
779 LDAP_LOG ( OPERATION, RESULTS,
780 "bdb_search: %ld scope not okay\n", (long) id, 0, 0);
782 Debug( LDAP_DEBUG_TRACE,
783 "bdb_search: %ld scope not okay\n",
789 LDAP_LOG ( OPERATION, RESULTS,
790 "bdb_search: %ld does match filter\n", (long) id, 0, 0);
792 Debug( LDAP_DEBUG_TRACE,
793 "bdb_search: %ld does match filter\n",
800 /* free reader lock */
801 bdb_cache_return_entry_r( bdb->bi_dbenv,
802 &bdb->bi_cache, e , &lock);
806 ldap_pvt_thread_yield();
809 #ifdef LDAP_CLIENT_UPDATE
810 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
812 LDAPControl *ctrls[2];
813 BerElement *ber = ber_alloc_t( LBER_USE_DER );
818 LDAP_LOG ( OPERATION, RESULTS,
819 "bdb_search: ber_alloc_t failed\n", 0, 0, 0 );
821 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_alloc_t failed\n",
824 send_ldap_result( conn, op, rc=LDAP_OTHER,
825 NULL, "internal error", NULL, NULL );
829 ctrls[0] = ch_malloc ( sizeof ( LDAPControl ) );
832 ber_printf( ber, "{sO", LCUP_COOKIE_OID, &latest_entrycsn_bv );
833 ber_printf( ber, "N}" );
835 ctrls[0]->ldctl_oid = LDAP_CONTROL_CLIENT_UPDATE_DONE;
836 ctrls[0]->ldctl_iscritical = op->o_clientupdate;
837 ret = ber_flatten( ber, &bv );
841 LDAP_LOG ( OPERATION, RESULTS,
842 "bdb_search: ber_flatten failed\n", 0, 0, 0 );
844 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_flatten failed\n",
847 send_ldap_result( conn, op, rc=LDAP_OTHER,
848 NULL, "internal error", NULL, NULL );
852 ber_dupbv( &ctrls[0]->ldctl_value, bv );
854 send_search_result( conn, op,
855 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
856 NULL, NULL, v2refs, ctrls, nentries );
858 ch_free( latest_entrycsn_bv.bv_val );
859 latest_entrycsn_bv.bv_val = NULL;
860 ch_free( ctrls[0]->ldctl_value.bv_val );
865 #endif /* LDAP_CLIENT_UPDATE */
867 send_search_result( conn, op,
868 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
869 NULL, NULL, v2refs, NULL, nentries );
876 /* free reader lock */
877 bdb_cache_return_entry_r ( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
880 #ifdef LDAP_CLIENT_UPDATE
881 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
882 if ( csnfeq.f_ava != NULL && csnfeq.f_av_value.bv_val != NULL ) {
883 ch_free( csnfeq.f_av_value.bv_val );
886 if ( csnfge.f_ava != NULL && csnfge.f_av_value.bv_val != NULL ) {
887 ch_free( csnfge.f_av_value.bv_val );
890 #endif /* LDAP_CLIENT_UPDATE */
892 LOCK_ID_FREE (bdb->bi_dbenv, locker );
894 if( v2refs ) ber_bvarray_free( v2refs );
895 if( realbase.bv_val ) ch_free( realbase.bv_val );
901 static int base_candidate(
907 LDAP_LOG ( OPERATION, ENTRY,
908 "base_candidate: base: \"%s\" (0x%08lx)\n", e->e_dn, (long) e->e_id, 0);
910 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
911 e->e_dn, (long) e->e_id, 0);
919 /* Look for "objectClass Present" in this filter.
920 * Also count depth of filter tree while we're at it.
922 static int oc_filter(
930 if( cur > *max ) *max = cur;
932 switch(f->f_choice) {
933 case LDAP_FILTER_PRESENT:
934 if (f->f_desc == slap_schema.si_ad_objectClass) {
939 case LDAP_FILTER_AND:
942 for (f=f->f_and; f; f=f->f_next) {
943 (void) oc_filter(f, cur, max);
953 static int search_candidates(
963 Filter f, scopef, rf, xf;
965 AttributeAssertion aa_ref;
966 #ifdef BDB_SUBENTRIES
968 AttributeAssertion aa_subentry;
972 AttributeAssertion aa_alias;
976 * This routine takes as input a filter (user-filter)
977 * and rewrites it as follows:
978 * (&(scope=DN)[(objectClass=subentry)]
979 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
983 LDAP_LOG ( OPERATION, ENTRY,
984 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
985 e->e_dn, (long) e->e_id, scope);
987 Debug(LDAP_DEBUG_TRACE,
988 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
989 e->e_dn, (long) e->e_id, scope );
993 xf.f_choice = LDAP_FILTER_OR;
996 /* If the user's filter uses objectClass=*,
997 * these clauses are redundant.
999 if (!oc_filter(filter, 1, &depth) && !get_subentries_visibility(op) ) {
1000 if( !get_manageDSAit(op) ) { /* match referrals */
1001 struct berval bv_ref = { sizeof("referral")-1, "referral" };
1002 rf.f_choice = LDAP_FILTER_EQUALITY;
1004 rf.f_av_desc = slap_schema.si_ad_objectClass;
1005 rf.f_av_value = bv_ref;
1006 rf.f_next = xf.f_or;
1011 if( deref & LDAP_DEREF_SEARCHING ) { /* match aliases */
1012 struct berval bv_alias = { sizeof("alias")-1, "alias" };
1013 af.f_choice = LDAP_FILTER_EQUALITY;
1014 af.f_ava = &aa_alias;
1015 af.f_av_desc = slap_schema.si_ad_objectClass;
1016 af.f_av_value = bv_alias;
1017 af.f_next = xf.f_or;
1021 /* We added one of these clauses, filter depth increased */
1022 if( xf.f_or != filter ) depth++;
1026 f.f_choice = LDAP_FILTER_AND;
1028 scopef.f_choice = scope == LDAP_SCOPE_SUBTREE
1029 ? SLAPD_FILTER_DN_SUBTREE
1030 : SLAPD_FILTER_DN_ONE;
1031 scopef.f_dn = &e->e_nname;
1032 scopef.f_next = xf.f_or == filter ? filter : &xf ;
1033 /* Filter depth increased again, adding scope clause */
1036 #ifdef BDB_SUBENTRIES
1037 if( get_subentries_visibility( op ) ) {
1038 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1039 sf.f_choice = LDAP_FILTER_EQUALITY;
1040 sf.f_ava = &aa_subentry;
1041 sf.f_av_desc = slap_schema.si_ad_objectClass;
1042 sf.f_av_value = bv_subentry;
1043 sf.f_next = scopef.f_next;
1044 scopef.f_next = &sf;
1048 /* Allocate IDL stack, plus 1 more for former tmp */
1049 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1051 rc = bdb_filter_candidates( be, &f, ids, stack, stack+BDB_IDL_UM_SIZE );
1057 LDAP_LOG ( OPERATION, DETAIL1,
1058 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1060 Debug(LDAP_DEBUG_TRACE,
1061 "bdb_search_candidates: failed (rc=%d)\n",
1067 LDAP_LOG ( OPERATION, DETAIL1,
1068 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1069 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1070 (long) BDB_IDL_LAST(ids));
1072 Debug(LDAP_DEBUG_TRACE,
1073 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1075 (long) BDB_IDL_FIRST(ids),
1076 (long) BDB_IDL_LAST(ids) );
1083 #ifdef LDAP_CONTROL_PAGEDRESULTS
1085 send_pagerequest_response(
1091 LDAPControl ctrl, *ctrls[2];
1093 struct berval *bvalp, cookie = { 0, NULL };
1094 PagedResultsCookie respcookie;
1097 LDAP_LOG ( OPERATION, ENTRY,
1098 "send_pagerequest_response: lastid: (0x%08lx) "
1099 "nentries: (0x%081x)\n",
1102 Debug(LDAP_DEBUG_ARGS, "send_pagerequest_response: lastid: (0x%08lx) "
1103 "nentries: (0x%081x)\n", lastid, nentries, NULL );
1106 ctrl.ldctl_value.bv_val = NULL;
1110 if (( ber = ber_alloc_t(LBER_USE_DER)) == NULL ) {
1114 respcookie = ( PagedResultsCookie )lastid;
1115 conn->c_pagedresults_state.ps_cookie = respcookie;
1116 cookie.bv_len = sizeof( respcookie );
1118 cookie.bv_val = ber_memalloc( sizeof( respcookie ) );
1119 AC_MEMCPY( cookie.bv_val, &respcookie, sizeof( respcookie ) );
1121 cookie.bv_val = (char *)&respcookie;
1124 conn->c_pagedresults_state.ps_cookie = cookie.bv_val;
1127 ber_printf( ber, "{iO}", 0, &cookie );
1129 ber_memfree( cookie.bv_val );
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 if ( ctrls[0]->ldctl_value.bv_val ) {
1146 ch_free( ctrls[0]->ldctl_value.bv_val );
1149 #endif /* LDAP_CONTROL_PAGEDRESULTS */