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(
42 struct berval *filterstr,
46 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
48 const char *text = NULL;
51 ID candidates[BDB_IDL_UM_SIZE];
53 BerVarray v2refs = NULL;
54 Entry *matched = NULL;
55 struct berval realbase = { 0, NULL };
59 #ifdef LDAP_CLIENT_UPDATE
60 Filter lcupf, csnfnot, csnfeq, csnfand, csnfge;
61 AttributeAssertion aa_ge, aa_eq;
63 struct berval entrycsn_bv = { 0, NULL };
64 struct berval latest_entrycsn_bv = { 0, NULL };
65 #endif /* LDAP_CLIENT_UPDATE */
67 struct slap_limits_set *limit = NULL;
70 #ifdef SLAP_X_FILTER_HASSUBORDINATES
71 int filter_hasSubordinates = 0;
72 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
78 LDAP_LOG ( OPERATION, ENTRY, "bdb_back_search\n", 0, 0, 0 );
80 Debug( LDAP_DEBUG_TRACE, "=> bdb_back_search\n",
84 manageDSAit = get_manageDSAit( op );
86 rc = LOCK_ID (bdb->bi_dbenv, &locker );
91 send_ldap_result( conn, op, rc=LDAP_OTHER,
92 NULL, "internal error", NULL, NULL );
96 if ( nbase->bv_len == 0 ) {
97 /* DIT root special case */
98 e = (Entry *) &slap_entry_root;
102 /* get entry with reader lock */
103 if ( deref & LDAP_DEREF_FINDING ) {
104 e = deref_dn_r( be, nbase-, &err, &matched, &text );
110 rc = bdb_dn2entry_r( be, NULL, nbase, &e, &matched, 0, locker, &lock );
119 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
121 if (matched != NULL) {
122 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
124 send_ldap_result( conn, op, LDAP_BUSY,
125 NULL, "ldap server busy", NULL, NULL );
126 LOCK_ID_FREE (bdb->bi_dbenv, locker );
128 case DB_LOCK_DEADLOCK:
129 case DB_LOCK_NOTGRANTED:
133 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
135 if (matched != NULL) {
136 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
138 send_ldap_result( conn, op, rc=LDAP_OTHER,
139 NULL, "internal error", NULL, NULL );
140 LOCK_ID_FREE (bdb->bi_dbenv, locker );
145 struct berval matched_dn = { 0, NULL };
146 BerVarray refs = NULL;
148 if ( matched != NULL ) {
150 ber_dupbv( &matched_dn, &matched->e_name );
152 erefs = is_entry_referral( matched )
153 ? get_entry_referrals( be, conn, op, matched )
156 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
160 refs = referral_rewrite( erefs, &matched_dn,
162 ber_bvarray_free( erefs );
166 refs = referral_rewrite( default_referral,
170 send_ldap_result( conn, op, rc=LDAP_REFERRAL ,
171 matched_dn.bv_val, text, refs, NULL );
173 LOCK_ID_FREE (bdb->bi_dbenv, locker );
174 if ( refs ) ber_bvarray_free( refs );
175 if ( matched_dn.bv_val ) ber_memfree( matched_dn.bv_val );
179 if (!manageDSAit && e != &slap_entry_root && is_entry_referral( e ) ) {
180 /* entry is a referral, don't allow add */
181 struct berval matched_dn;
182 BerVarray erefs, refs;
184 ber_dupbv( &matched_dn, &e->e_name );
185 erefs = get_entry_referrals( be, conn, op, e );
188 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
192 refs = referral_rewrite( erefs, &matched_dn,
194 ber_bvarray_free( erefs );
198 LDAP_LOG ( OPERATION, RESULTS,
199 "bdb_search: entry is referral\n", 0, 0, 0 );
201 Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
205 send_ldap_result( conn, op, LDAP_REFERRAL,
207 refs ? NULL : "bad referral object",
210 LOCK_ID_FREE (bdb->bi_dbenv, locker );
211 ber_bvarray_free( refs );
212 ber_memfree( matched_dn.bv_val );
216 /* if not root, get appropriate limits */
217 if ( be_isroot( be, &op->o_ndn ) ) {
220 ( void ) get_limits( be, &op->o_ndn, &limit );
223 /* The time/size limits come first because they require very little
224 * effort, so there's no chance the candidates are selected and then
225 * the request is not honored only because of time/size constraints */
227 /* if no time limit requested, use soft limit (unless root!) */
230 tlimit = -1; /* allow root to set no limit */
238 /* if no limit is required, use soft limit */
240 tlimit = limit->lms_t_soft;
242 /* if requested limit higher than hard limit, abort */
243 } else if ( tlimit > limit->lms_t_hard ) {
244 /* no hard limit means use soft instead */
245 if ( limit->lms_t_hard == 0 && tlimit > limit->lms_t_soft ) {
246 tlimit = limit->lms_t_soft;
248 /* positive hard limit means abort */
249 } else if ( limit->lms_t_hard > 0 ) {
250 send_search_result( conn, op,
251 LDAP_UNWILLING_TO_PERFORM,
252 NULL, NULL, NULL, NULL, 0 );
257 /* negative hard limit means no limit */
260 /* if no limit is required, use soft limit */
262 slimit = limit->lms_s_soft;
264 /* if requested limit higher than hard limit, abort */
265 } else if ( slimit > limit->lms_s_hard ) {
266 /* no hard limit means use soft instead */
267 if ( limit->lms_s_hard == 0 && slimit > limit->lms_s_soft ) {
268 slimit = limit->lms_s_soft;
270 /* positive hard limit means abort */
271 } else if ( limit->lms_s_hard > 0 ) {
272 send_search_result( conn, op,
273 LDAP_UNWILLING_TO_PERFORM,
274 NULL, NULL, NULL, NULL, 0 );
279 /* negative hard limit means no limit */
283 /* compute it anyway; root does not use it */
284 stoptime = op->o_time + tlimit;
286 /* select candidates */
287 if ( scope == LDAP_SCOPE_BASE ) {
288 rc = base_candidate( be, e, candidates );
291 BDB_IDL_ALL( bdb, candidates );
292 rc = search_candidates( be, op, e, filter,
293 scope, deref, candidates );
296 /* need normalized dn below */
297 ber_dupbv( &realbase, &e->e_nname );
299 /* start cursor at beginning of candidates.
303 if ( e != &slap_entry_root ) {
304 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
308 if ( candidates[0] == 0 ) {
310 LDAP_LOG ( OPERATION, RESULTS,
311 "bdb_search: no candidates\n", 0, 0, 0 );
313 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
317 send_search_result( conn, op,
319 NULL, NULL, NULL, NULL, 0 );
325 /* if not root and candidates exceed to-be-checked entries, abort */
326 if ( !isroot && limit->lms_s_unchecked != -1 ) {
327 if ( BDB_IDL_N(candidates) > (unsigned) limit->lms_s_unchecked ) {
328 send_search_result( conn, op,
329 LDAP_ADMINLIMIT_EXCEEDED,
330 NULL, NULL, NULL, NULL, 0 );
336 #ifdef SLAP_X_FILTER_HASSUBORDINATES
338 * is hasSubordinates used in the filter ?
339 * FIXME: we may compute this directly when parsing the filter
341 filter_hasSubordinates = filter_has_subordinates( filter );
342 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
344 #ifdef LDAP_CLIENT_UPDATE
345 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
346 lcupf.f_choice = LDAP_FILTER_AND;
347 lcupf.f_and = &csnfnot;
350 csnfnot.f_choice = LDAP_FILTER_NOT;
351 csnfnot.f_not = &csnfeq;
352 csnfnot.f_next = &csnfand;
354 csnfeq.f_choice = LDAP_FILTER_EQUALITY;
355 csnfeq.f_ava = &aa_eq;
356 csnfeq.f_av_desc = slap_schema.si_ad_entryCSN;
357 ber_dupbv( &csnfeq.f_av_value, &op->o_clientupdate_state );
359 csnfand.f_choice = LDAP_FILTER_AND;
360 csnfand.f_and = &csnfge;
361 csnfand.f_next = NULL;
363 csnfge.f_choice = LDAP_FILTER_GE;
364 csnfge.f_ava = &aa_ge;
365 csnfge.f_av_desc = slap_schema.si_ad_entryCSN;
366 ber_dupbv( &csnfge.f_av_value, &op->o_clientupdate_state );
367 csnfge.f_next = filter;
369 #endif /* LDAP_CLIENT_UPDATE */
371 for ( id = bdb_idl_first( candidates, &cursor );
373 id = bdb_idl_next( candidates, &cursor ) )
376 #ifdef SLAP_X_FILTER_HASSUBORDINATES
377 Attribute *hasSubordinates = NULL;
378 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
380 /* check for abandon */
381 if ( op->o_abandon ) {
386 /* check time limit */
387 if ( tlimit != -1 && slap_get_time() > stoptime ) {
388 send_search_result( conn, op, rc = LDAP_TIMELIMIT_EXCEEDED,
389 NULL, NULL, v2refs, NULL, nentries );
394 /* get the entry with reader lock */
395 rc = bdb_id2entry_r( be, NULL, id, &e, locker, &lock );
397 if (rc == LDAP_BUSY) {
398 send_ldap_result( conn, op, rc=LDAP_BUSY,
399 NULL, "ldap server busy", NULL, NULL );
402 } else if ( rc == DB_LOCK_DEADLOCK || rc == DB_LOCK_NOTGRANTED ) {
407 if( !BDB_IDL_IS_RANGE(candidates) ) {
408 /* only complain for non-range IDLs */
410 LDAP_LOG ( OPERATION, RESULTS,
411 "bdb_search: candidate %ld not found\n", (long) id, 0, 0);
413 Debug( LDAP_DEBUG_TRACE,
414 "bdb_search: candidate %ld not found\n",
422 #ifdef BDB_SUBENTRIES
423 if ( is_entry_subentry( e ) ) {
424 if( scope != LDAP_SCOPE_BASE ) {
425 if(!get_subentries_visibility( op )) {
426 /* only subentries are visible */
430 } else if ( get_subentries( op ) &&
431 !get_subentries_visibility( op ))
433 /* only subentries are visible */
437 } else if ( get_subentries_visibility( op )) {
438 /* only subentries are visible */
444 if ( deref & LDAP_DEREF_SEARCHING && is_entry_alias( e ) ) {
449 e = deref_entry_r( be, e, &err, &matched, &text );
456 if( e->e_id == id ) {
461 /* need to skip alias which deref into scope */
462 if( scope & LDAP_SCOPE_ONELEVEL ) {
465 dnParent( &e->e_nname, &pdn ):
466 if ( ber_bvcmp( pdn, &realbase ) ) {
470 } else if ( dnIsSuffix( &e->e_nname, &realbase ) ) {
471 /* alias is within scope */
473 LDAP_LOG ( OPERATION, RESULTS,
474 "bdb_search: \"%s\" in subtree\n", e->edn, 0, 0);
476 Debug( LDAP_DEBUG_TRACE,
477 "bdb_search: \"%s\" in subtree\n",
488 * if it's a referral, add it to the list of referrals. only do
489 * this for non-base searches, and don't check the filter
490 * explicitly here since it's only a candidate anyway.
492 if ( !manageDSAit && scope != LDAP_SCOPE_BASE &&
493 is_entry_referral( e ) )
498 if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
499 if ( !be_issuffix( be, &e->e_nname ) ) {
500 dnParent( &e->e_nname, &dn );
501 scopeok = dn_match( &dn, &realbase );
503 scopeok = (realbase.bv_len == 0);
506 } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
507 scopeok = dnIsSuffix( &e->e_nname, &realbase );
514 BerVarray erefs = get_entry_referrals(
516 BerVarray refs = referral_rewrite( erefs,
518 scope == LDAP_SCOPE_SUBTREE
522 send_search_reference( be, conn, op,
523 e, refs, NULL, &v2refs );
525 ber_bvarray_free( refs );
529 LDAP_LOG(OPERATION, DETAIL2,
530 "bdb_search: candidate referral %ld scope not okay\n",
533 Debug( LDAP_DEBUG_TRACE,
534 "bdb_search: candidate referral %ld scope not okay\n",
542 #ifdef SLAP_X_FILTER_HASSUBORDINATES
544 * if hasSubordinates is used in the filter,
545 * append it to the entry's attributes
547 if ( filter_hasSubordinates ) {
550 rc = bdb_hasSubordinates( be, conn, op, e, &hs);
551 if ( rc != LDAP_SUCCESS ) {
555 hasSubordinates = slap_operational_hasSubordinate(
556 hs == LDAP_COMPARE_TRUE );
558 if ( hasSubordinates == NULL ) {
562 hasSubordinates->a_next = e->e_attrs;
563 e->e_attrs = hasSubordinates;
565 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
567 /* if it matches the filter and scope, send it */
568 #ifdef LDAP_CLIENT_UPDATE
569 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
570 rc = test_filter( be, conn, op, e, &lcupf );
572 #endif /* LDAP_CLIENT_UPDATE */
574 rc = test_filter( be, conn, op, e, filter );
577 #ifdef SLAP_X_FILTER_HASSUBORDINATES
578 if ( hasSubordinates ) {
580 * FIXME: this is fairly inefficient, because
581 * if hasSubordinates is among the required
582 * attrs, it will be added again later;
583 * maybe we should leave it and check
584 * check later if it's already present,
587 e->e_attrs = e->e_attrs->a_next;
588 attr_free( hasSubordinates );
590 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
592 if ( rc == LDAP_COMPARE_TRUE ) {
596 if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
597 if ( be_issuffix( be, &e->e_nname ) ) {
598 scopeok = (realbase.bv_len == 0);
600 dnParent( &e->e_nname, &dn );
601 scopeok = dn_match( &dn, &realbase );
604 } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
605 scopeok = dnIsSuffix( &e->e_nname, &realbase );
612 /* check size limit */
613 if ( --slimit == -1 ) {
614 bdb_cache_return_entry_r( bdb->bi_dbenv,
615 &bdb->bi_cache, e, &lock );
617 send_search_result( conn, op,
618 rc = LDAP_SIZELIMIT_EXCEEDED, NULL, NULL,
619 v2refs, NULL, nentries );
626 #if 0 /* noop is masked SLAP_CTRL_UPDATE */
632 #ifdef LDAP_CLIENT_UPDATE
633 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
637 const char *text = NULL;
638 LDAPControl *ctrls[2];
641 BerElement *ber = ber_alloc_t( LBER_USE_DER );
645 LDAP_LOG ( OPERATION, RESULTS,
646 "bdb_search: ber_alloc_t failed\n",
649 Debug( LDAP_DEBUG_TRACE,
650 "bdb_search: ber_alloc_t failed\n",
653 send_ldap_result( conn, op, rc=LDAP_OTHER,
654 NULL, "internal error", NULL, NULL );
660 ctrls[0] = ch_malloc ( sizeof ( LDAPControl ) );
663 if ( entry_count % op->o_clientupdate_interval == 0 ) {
665 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
666 AttributeDescription *desc = a->a_desc;
667 if ( desc == slap_schema.si_ad_entryCSN ) {
668 ber_dupbv( &entrycsn_bv, &a->a_vals[0] );
669 if ( latest_entrycsn_bv.bv_val == NULL ) {
670 ber_dupbv( &latest_entrycsn_bv, &entrycsn_bv );
672 res = value_match( &ret, desc,
673 desc->ad_type->sat_ordering,
674 SLAP_MR_ASSERTION_SYNTAX_MATCH,
675 &entrycsn_bv, &latest_entrycsn_bv, &text );
676 if ( res != LDAP_SUCCESS ) {
679 LDAP_LOG ( OPERATION, RESULTS,
680 "bdb_search: value_match failed\n",
683 Debug( LDAP_DEBUG_TRACE,
684 "bdb_search: value_match failed\n",
690 ch_free( latest_entrycsn_bv.bv_val );
691 latest_entrycsn_bv.bv_val = NULL;
692 ber_dupbv( &latest_entrycsn_bv,
701 SLAP_LCUP_STATE_UPDATE_FALSE,
702 SLAP_LCUP_ENTRY_DELETED_FALSE,
703 LCUP_COOKIE_OID, &entrycsn_bv );
705 ch_free( entrycsn_bv.bv_val );
706 entrycsn_bv.bv_val = NULL;
709 /* Do not send cookie */
712 SLAP_LCUP_STATE_UPDATE_FALSE,
713 SLAP_LCUP_ENTRY_DELETED_FALSE );
716 ctrls[0]->ldctl_oid = LDAP_CONTROL_ENTRY_UPDATE;
717 ctrls[0]->ldctl_iscritical = op->o_clientupdate;
718 ret = ber_flatten( ber, &bv );
722 LDAP_LOG ( OPERATION, RESULTS,
723 "bdb_search: ber_flatten failed\n",
726 Debug( LDAP_DEBUG_TRACE,
727 "bdb_search: ber_flatten failed\n",
730 send_ldap_result( conn, op, rc=LDAP_OTHER,
731 NULL, "internal error", NULL, NULL );
735 ber_dupbv( &ctrls[0]->ldctl_value, bv );
737 result = send_search_entry( be, conn, op,
738 e, attrs, attrsonly, ctrls);
740 ch_free( ctrls[0]->ldctl_value.bv_val );
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 BerElement *ber = ber_alloc_t( LBER_USE_DER );
807 LDAP_LOG ( OPERATION, RESULTS,
808 "bdb_search: ber_alloc_t failed\n", 0, 0, 0 );
810 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_alloc_t failed\n",
813 send_ldap_result( conn, op, rc=LDAP_OTHER,
814 NULL, "internal error", NULL, NULL );
818 ctrls[0] = ch_malloc ( sizeof ( LDAPControl ) );
821 ber_printf( ber, "{sO", LCUP_COOKIE_OID, &latest_entrycsn_bv );
822 ber_printf( ber, "N}" );
824 ctrls[0]->ldctl_oid = LDAP_CONTROL_CLIENT_UPDATE_DONE;
825 ctrls[0]->ldctl_iscritical = op->o_clientupdate;
826 ret = ber_flatten( ber, &bv );
830 LDAP_LOG ( OPERATION, RESULTS,
831 "bdb_search: ber_flatten failed\n", 0, 0, 0 );
833 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_flatten failed\n",
836 send_ldap_result( conn, op, rc=LDAP_OTHER,
837 NULL, "internal error", NULL, NULL );
841 ber_dupbv( &ctrls[0]->ldctl_value, bv );
843 send_search_result( conn, op,
844 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
845 NULL, NULL, v2refs, ctrls, nentries );
847 ch_free( latest_entrycsn_bv.bv_val );
848 latest_entrycsn_bv.bv_val = NULL;
849 ch_free( ctrls[0]->ldctl_value.bv_val );
854 #endif /* LDAP_CLIENT_UPDATE */
856 send_search_result( conn, op,
857 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
858 NULL, NULL, v2refs, NULL, nentries );
865 /* free reader lock */
866 bdb_cache_return_entry_r ( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
869 #ifdef LDAP_CLIENT_UDATE
870 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
871 if ( csnfeq.f_ava != NULL && csnfeq.f_av_value.bv_val != NULL ) {
872 ch_free( csnfeq.f_av_value.bv_val );
875 if ( csnfge.f_ava != NULL && csnfge.f_av_value.bv_val != NULL ) {
876 ch_free( csnfge.f_av_value.bv_val );
879 #endif /* LDAP_CLIENT_UPDATE */
881 LOCK_ID_FREE (bdb->bi_dbenv, locker );
883 if( v2refs ) ber_bvarray_free( v2refs );
884 if( realbase.bv_val ) ch_free( realbase.bv_val );
890 static int base_candidate(
896 LDAP_LOG ( OPERATION, ENTRY,
897 "base_candidate: base: \"%s\" (0x%08lx)\n", e->e_dn, (long) e->e_id, 0);
899 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
900 e->e_dn, (long) e->e_id, 0);
908 /* Look for "objectClass Present" in this filter.
909 * Also count depth of filter tree while we're at it.
911 static int oc_filter(
919 if( cur > *max ) *max = cur;
921 switch(f->f_choice) {
922 case LDAP_FILTER_PRESENT:
923 if (f->f_desc == slap_schema.si_ad_objectClass) {
928 case LDAP_FILTER_AND:
931 for (f=f->f_and; f; f=f->f_next) {
932 (void) oc_filter(f, cur, max);
942 static int search_candidates(
952 Filter f, scopef, rf, xf;
954 AttributeAssertion aa_ref;
955 #ifdef BDB_SUBENTRIES
957 AttributeAssertion aa_subentry;
961 AttributeAssertion aa_alias;
965 * This routine takes as input a filter (user-filter)
966 * and rewrites it as follows:
967 * (&(scope=DN)[(objectClass=subentry)]
968 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
972 LDAP_LOG ( OPERATION, ENTRY,
973 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
974 e->e_dn, (long) e->e_id, scope);
976 Debug(LDAP_DEBUG_TRACE,
977 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
978 e->e_dn, (long) e->e_id, scope );
982 xf.f_choice = LDAP_FILTER_OR;
985 /* If the user's filter uses objectClass=*,
986 * these clauses are redundant.
988 if (!oc_filter(filter, 1, &depth) && !get_subentries_visibility(op) ) {
989 if( !get_manageDSAit(op) ) { /* match referrals */
990 struct berval bv_ref = { sizeof("REFERRAL")-1, "REFERRAL" };
991 rf.f_choice = LDAP_FILTER_EQUALITY;
993 rf.f_av_desc = slap_schema.si_ad_objectClass;
994 rf.f_av_value = bv_ref;
1000 if( deref & LDAP_DEREF_SEARCHING ) { /* match aliases */
1001 struct berval bv_alias = { sizeof("ALIAS")-1, "ALIAS" };
1002 af.f_choice = LDAP_FILTER_EQUALITY;
1003 af.f_ava = &aa_alias;
1004 af.f_av_desc = slap_schema.si_ad_objectClass;
1005 af.f_av_value = bv_alias;
1006 af.f_next = xf.f_or;
1010 /* We added one of these clauses, filter depth increased */
1011 if( xf.f_or != filter ) depth++;
1015 f.f_choice = LDAP_FILTER_AND;
1017 scopef.f_choice = scope == LDAP_SCOPE_SUBTREE
1018 ? SLAPD_FILTER_DN_SUBTREE
1019 : SLAPD_FILTER_DN_ONE;
1020 scopef.f_dn = &e->e_nname;
1021 scopef.f_next = xf.f_or == filter ? filter : &xf ;
1022 /* Filter depth increased again, adding scope clause */
1025 #ifdef BDB_SUBENTRIES
1026 if( get_subentries_visibility( op ) ) {
1027 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1028 sf.f_choice = LDAP_FILTER_EQUALITY;
1029 sf.f_ava = &aa_subentry;
1030 sf.f_av_desc = slap_schema.si_ad_objectClass;
1031 sf.f_av_value = bv_subentry;
1032 sf.f_next = scopef.f_next;
1033 scopef.f_next = &sf;
1037 /* Allocate IDL stack, plus 1 more for former tmp */
1038 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1040 rc = bdb_filter_candidates( be, &f, ids, stack, stack+BDB_IDL_UM_SIZE );
1046 LDAP_LOG ( OPERATION, DETAIL1,
1047 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1049 Debug(LDAP_DEBUG_TRACE,
1050 "bdb_search_candidates: failed (rc=%d)\n",
1056 LDAP_LOG ( OPERATION, DETAIL1,
1057 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1058 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1059 (long) BDB_IDL_LAST(ids));
1061 Debug(LDAP_DEBUG_TRACE,
1062 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1064 (long) BDB_IDL_FIRST(ids),
1065 (long) BDB_IDL_LAST(ids) );