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, "bdb_search: no candidates\n", 0, 0, 0 );
312 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
316 send_search_result( conn, op,
318 NULL, NULL, NULL, NULL, 0 );
324 /* if not root and candidates exceed to-be-checked entries, abort */
325 if ( !isroot && limit->lms_s_unchecked != -1 ) {
326 if ( BDB_IDL_N(candidates) > (unsigned) limit->lms_s_unchecked ) {
327 send_search_result( conn, op,
328 LDAP_ADMINLIMIT_EXCEEDED,
329 NULL, NULL, NULL, NULL, 0 );
335 #ifdef SLAP_X_FILTER_HASSUBORDINATES
337 * is hasSubordinates used in the filter ?
338 * FIXME: we may compute this directly when parsing the filter
340 filter_hasSubordinates = filter_has_subordinates( filter );
341 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
343 #ifdef LDAP_CLIENT_UPDATE
344 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
345 lcupf.f_choice = LDAP_FILTER_AND;
346 lcupf.f_and = &csnfnot;
349 csnfnot.f_choice = LDAP_FILTER_NOT;
350 csnfnot.f_not = &csnfeq;
351 csnfnot.f_next = &csnfand;
353 csnfeq.f_choice = LDAP_FILTER_EQUALITY;
354 csnfeq.f_ava = &aa_eq;
355 csnfeq.f_av_desc = slap_schema.si_ad_entryCSN;
356 ber_dupbv( &csnfeq.f_av_value, &op->o_clientupdate_state );
358 csnfand.f_choice = LDAP_FILTER_AND;
359 csnfand.f_and = &csnfge;
360 csnfand.f_next = NULL;
362 csnfge.f_choice = LDAP_FILTER_GE;
363 csnfge.f_ava = &aa_ge;
364 csnfge.f_av_desc = slap_schema.si_ad_entryCSN;
365 ber_dupbv( &csnfge.f_av_value, &op->o_clientupdate_state );
366 csnfge.f_next = filter;
368 #endif /* LDAP_CLIENT_UPDATE */
370 for ( id = bdb_idl_first( candidates, &cursor );
372 id = bdb_idl_next( candidates, &cursor ) )
375 #ifdef SLAP_X_FILTER_HASSUBORDINATES
376 Attribute *hasSubordinates = NULL;
377 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
379 /* check for abandon */
380 if ( op->o_abandon ) {
385 /* check time limit */
386 if ( tlimit != -1 && slap_get_time() > stoptime ) {
387 send_search_result( conn, op, rc = LDAP_TIMELIMIT_EXCEEDED,
388 NULL, NULL, v2refs, NULL, nentries );
393 /* get the entry with reader lock */
394 rc = bdb_id2entry_r( be, NULL, id, &e, locker, &lock );
396 if (rc == LDAP_BUSY) {
397 send_ldap_result( conn, op, rc=LDAP_BUSY,
398 NULL, "ldap server busy", NULL, NULL );
401 } else if ( rc == DB_LOCK_DEADLOCK || rc == DB_LOCK_NOTGRANTED ) {
406 if( !BDB_IDL_IS_RANGE(candidates) ) {
407 /* only complain for non-range IDLs */
409 LDAP_LOG ( OPERATION, RESULTS,
410 "bdb_search: candidate %ld not found\n", (long) id, 0, 0);
412 Debug( LDAP_DEBUG_TRACE,
413 "bdb_search: candidate %ld not found\n",
421 #ifdef BDB_SUBENTRIES
422 if ( is_entry_subentry( e ) ) {
423 if( scope != LDAP_SCOPE_BASE ) {
424 if(!get_subentries_visibility( op )) {
425 /* only subentries are visible */
429 } else if ( get_subentries( op ) &&
430 !get_subentries_visibility( op ))
432 /* only subentries are visible */
436 } else if ( get_subentries_visibility( op )) {
437 /* only subentries are visible */
443 if ( deref & LDAP_DEREF_SEARCHING && is_entry_alias( e ) ) {
448 e = deref_entry_r( be, e, &err, &matched, &text );
455 if( e->e_id == id ) {
460 /* need to skip alias which deref into scope */
461 if( scope & LDAP_SCOPE_ONELEVEL ) {
464 dnParent( &e->e_nname, &pdn ):
465 if ( ber_bvcmp( pdn, &realbase ) ) {
469 } else if ( dnIsSuffix( &e->e_nname, &realbase ) ) {
470 /* alias is within scope */
472 LDAP_LOG ( OPERATION, RESULTS,
473 "bdb_search: \"%s\" in subtree\n", e->edn, 0, 0);
475 Debug( LDAP_DEBUG_TRACE,
476 "bdb_search: \"%s\" in subtree\n",
487 * if it's a referral, add it to the list of referrals. only do
488 * this for non-base searches, and don't check the filter
489 * explicitly here since it's only a candidate anyway.
491 if ( !manageDSAit && scope != LDAP_SCOPE_BASE &&
492 is_entry_referral( e ) )
497 if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
498 if ( !be_issuffix( be, &e->e_nname ) ) {
499 dnParent( &e->e_nname, &dn );
500 scopeok = dn_match( &dn, &realbase );
502 scopeok = (realbase.bv_len == 0);
505 } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
506 scopeok = dnIsSuffix( &e->e_nname, &realbase );
513 BerVarray erefs = get_entry_referrals(
515 BerVarray refs = referral_rewrite( erefs,
517 scope == LDAP_SCOPE_SUBTREE
521 send_search_reference( be, conn, op,
522 e, refs, NULL, &v2refs );
524 ber_bvarray_free( refs );
528 LDAP_LOG(OPERATION, DETAIL2,
529 "bdb_search: candidate referral %ld scope not okay\n",
532 Debug( LDAP_DEBUG_TRACE,
533 "bdb_search: candidate referral %ld scope not okay\n",
541 #ifdef SLAP_X_FILTER_HASSUBORDINATES
543 * if hasSubordinates is used in the filter,
544 * append it to the entry's attributes
546 if ( filter_hasSubordinates ) {
549 rc = bdb_hasSubordinates( be, conn, op, e, &hs);
550 if ( rc != LDAP_SUCCESS ) {
554 hasSubordinates = slap_operational_hasSubordinate(
555 hs == LDAP_COMPARE_TRUE );
557 if ( hasSubordinates == NULL ) {
561 hasSubordinates->a_next = e->e_attrs;
562 e->e_attrs = hasSubordinates;
564 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
566 /* if it matches the filter and scope, send it */
567 #ifdef LDAP_CLIENT_UPDATE
568 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
569 rc = test_filter( be, conn, op, e, &lcupf );
571 #endif /* LDAP_CLIENT_UPDATE */
573 rc = test_filter( be, conn, op, e, filter );
576 #ifdef SLAP_X_FILTER_HASSUBORDINATES
577 if ( hasSubordinates ) {
579 * FIXME: this is fairly inefficient, because
580 * if hasSubordinates is among the required
581 * attrs, it will be added again later;
582 * maybe we should leave it and check
583 * check later if it's already present,
586 e->e_attrs = e->e_attrs->a_next;
587 attr_free( hasSubordinates );
589 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
591 if ( rc == LDAP_COMPARE_TRUE ) {
595 if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
596 if ( be_issuffix( be, &e->e_nname ) ) {
597 scopeok = (realbase.bv_len == 0);
599 dnParent( &e->e_nname, &dn );
600 scopeok = dn_match( &dn, &realbase );
603 } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
604 scopeok = dnIsSuffix( &e->e_nname, &realbase );
611 /* check size limit */
612 if ( --slimit == -1 ) {
613 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
615 send_search_result( conn, op,
616 rc = LDAP_SIZELIMIT_EXCEEDED, NULL, NULL,
617 v2refs, NULL, nentries );
624 #if 0 /* noop is masked SLAP_CTRL_UPDATE */
629 #ifdef LDAP_CLIENT_UPDATE
630 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
634 const char *text = NULL;
635 LDAPControl *ctrls[2];
638 BerElement *ber = ber_alloc_t( LBER_USE_DER );
642 LDAP_LOG ( OPERATION, RESULTS,
643 "bdb_search: ber_alloc_t failed\n", 0, 0, 0 );
645 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_alloc_t failed\n",
648 send_ldap_result( conn, op, rc=LDAP_OTHER,
649 NULL, "internal error", NULL, NULL );
655 ctrls[0] = ch_malloc ( sizeof ( LDAPControl ) );
658 if ( entry_count % op->o_clientupdate_interval == 0 ) {
660 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
661 AttributeDescription *desc = a->a_desc;
662 if ( !strcmp( desc->ad_cname.bv_val, "entryCSN" ) ) {
663 ber_dupbv( &entrycsn_bv, &a->a_vals[0] );
664 if ( latest_entrycsn_bv.bv_val == NULL ) {
665 ber_dupbv( &latest_entrycsn_bv, &entrycsn_bv );
667 res = value_match( &ret, desc, desc->ad_type->sat_ordering, SLAP_MR_ASSERTION_SYNTAX_MATCH, &entrycsn_bv, &latest_entrycsn_bv, &text );
668 if ( res != LDAP_SUCCESS ) {
671 LDAP_LOG ( OPERATION, RESULTS,
672 "bdb_search: value_match failed\n", 0, 0, 0 );
674 Debug( LDAP_DEBUG_TRACE, "bdb_search: value_match failed\n",
680 ch_free( latest_entrycsn_bv.bv_val );
681 latest_entrycsn_bv.bv_val = NULL;
682 ber_dupbv( &latest_entrycsn_bv, &entrycsn_bv );
688 ber_printf( ber, "{{b}" /*}*/, SLAP_LCUP_STATE_UPDATE_FALSE );
689 ber_printf( ber, "{b}", SLAP_LCUP_ENTRY_DELETED_FALSE );
690 ber_printf( ber, "{sO" /*}*/, LCUP_COOKIE_OID, &entrycsn_bv );
691 ber_printf( ber, /*{{*/ "N}N}" );
693 ch_free( entrycsn_bv.bv_val );
694 entrycsn_bv.bv_val = NULL;
696 /* Do not send cookie */
697 ber_printf( ber, "{{b}" /*}*/, SLAP_LCUP_STATE_UPDATE_FALSE );
698 ber_printf( ber, /*{*/ "{b}N}", SLAP_LCUP_ENTRY_DELETED_FALSE );
701 ctrls[0]->ldctl_oid = LDAP_CONTROL_ENTRY_UPDATE;
702 ctrls[0]->ldctl_iscritical = op->o_clientupdate;
703 ret = ber_flatten( ber, &bv );
707 LDAP_LOG ( OPERATION, RESULTS,
708 "bdb_search: ber_flatten failed\n", 0, 0, 0 );
710 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_flatten failed\n",
713 send_ldap_result( conn, op, rc=LDAP_OTHER,
714 NULL, "internal error", NULL, NULL );
718 ber_dupbv( &ctrls[0]->ldctl_value, bv );
720 result = send_search_entry( be, conn, op,
721 e, attrs, attrsonly, ctrls);
723 ch_free( ctrls[0]->ldctl_value.bv_val );
728 #endif /* LDAP_CLIENT_UPDATE */
729 result = send_search_entry( be, conn, op,
730 e, attrs, attrsonly, NULL);
731 #ifdef LDAP_CLIENT_UPDATE
733 #endif /* LDAP_CLIENT_UPDATE */
739 case 0: /* entry sent ok */
742 case 1: /* entry not sent */
744 case -1: /* connection closed */
745 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
753 LDAP_LOG ( OPERATION, RESULTS,
754 "bdb_search: %ld scope not okay\n", (long) id, 0, 0);
756 Debug( LDAP_DEBUG_TRACE,
757 "bdb_search: %ld scope not okay\n",
763 LDAP_LOG ( OPERATION, RESULTS,
764 "bdb_search: %ld does match filter\n", (long) id, 0, 0);
766 Debug( LDAP_DEBUG_TRACE,
767 "bdb_search: %ld does match filter\n",
774 /* free reader lock */
775 bdb_cache_return_entry_r( bdb->bi_dbenv,
776 &bdb->bi_cache, e , &lock);
780 ldap_pvt_thread_yield();
782 #ifdef LDAP_CLIENT_UPDATE
783 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
785 LDAPControl *ctrls[2];
786 BerElement *ber = ber_alloc_t( LBER_USE_DER );
791 LDAP_LOG ( OPERATION, RESULTS,
792 "bdb_search: ber_alloc_t failed\n", 0, 0, 0 );
794 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_alloc_t failed\n",
797 send_ldap_result( conn, op, rc=LDAP_OTHER,
798 NULL, "internal error", NULL, NULL );
802 ctrls[0] = ch_malloc ( sizeof ( LDAPControl ) );
805 ber_printf( ber, "{sO", LCUP_COOKIE_OID, &latest_entrycsn_bv );
806 ber_printf( ber, "N}" );
808 ctrls[0]->ldctl_oid = LDAP_CONTROL_CLIENT_UPDATE_DONE;
809 ctrls[0]->ldctl_iscritical = op->o_clientupdate;
810 ret = ber_flatten( ber, &bv );
814 LDAP_LOG ( OPERATION, RESULTS,
815 "bdb_search: ber_flatten failed\n", 0, 0, 0 );
817 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_flatten failed\n",
820 send_ldap_result( conn, op, rc=LDAP_OTHER,
821 NULL, "internal error", NULL, NULL );
825 ber_dupbv( &ctrls[0]->ldctl_value, bv );
827 send_search_result( conn, op,
828 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
829 NULL, NULL, v2refs, ctrls, nentries );
831 ch_free( latest_entrycsn_bv.bv_val );
832 latest_entrycsn_bv.bv_val = NULL;
833 ch_free( ctrls[0]->ldctl_value.bv_val );
838 #endif /* LDAP_CLIENT_UPDATE */
839 send_search_result( conn, op,
840 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
841 NULL, NULL, v2refs, NULL, nentries );
842 #ifdef LDAP_CLIENT_UPDATE
844 #endif /* LDAP_CLIENT_UPDATE */
850 /* free reader lock */
851 bdb_cache_return_entry_r ( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
854 if ( csnfeq.f_av_value.bv_val != NULL ) {
855 ch_free( csnfeq.f_av_value.bv_val );
858 if ( csnfge.f_av_value.bv_val != NULL ) {
859 ch_free( csnfge.f_av_value.bv_val );
862 LOCK_ID_FREE (bdb->bi_dbenv, locker );
864 if( v2refs ) ber_bvarray_free( v2refs );
865 if( realbase.bv_val ) ch_free( realbase.bv_val );
871 static int base_candidate(
877 LDAP_LOG ( OPERATION, ENTRY,
878 "base_candidate: base: \"%s\" (0x%08lx)\n", e->e_dn, (long) e->e_id, 0);
880 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
881 e->e_dn, (long) e->e_id, 0);
889 /* Look for "objectClass Present" in this filter.
890 * Also count depth of filter tree while we're at it.
892 static int oc_filter(
900 if( cur > *max ) *max = cur;
902 switch(f->f_choice) {
903 case LDAP_FILTER_PRESENT:
904 if (f->f_desc == slap_schema.si_ad_objectClass) {
909 case LDAP_FILTER_AND:
912 for (f=f->f_and; f; f=f->f_next) {
913 (void) oc_filter(f, cur, max);
923 static int search_candidates(
933 Filter f, scopef, rf, xf;
935 AttributeAssertion aa_ref;
936 #ifdef BDB_SUBENTRIES
938 AttributeAssertion aa_subentry;
942 AttributeAssertion aa_alias;
946 * This routine takes as input a filter (user-filter)
947 * and rewrites it as follows:
948 * (&(scope=DN)[(objectClass=subentry)]
949 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
953 LDAP_LOG ( OPERATION, ENTRY,
954 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
955 e->e_dn, (long) e->e_id, scope);
957 Debug(LDAP_DEBUG_TRACE,
958 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
959 e->e_dn, (long) e->e_id, scope );
963 xf.f_choice = LDAP_FILTER_OR;
966 /* If the user's filter uses objectClass=*,
967 * these clauses are redundant.
969 if (!oc_filter(filter, 1, &depth) && !get_subentries_visibility(op) ) {
970 if( !get_manageDSAit(op) ) { /* match referrals */
971 struct berval bv_ref = { sizeof("REFERRAL")-1, "REFERRAL" };
972 rf.f_choice = LDAP_FILTER_EQUALITY;
974 rf.f_av_desc = slap_schema.si_ad_objectClass;
975 rf.f_av_value = bv_ref;
981 if( deref & LDAP_DEREF_SEARCHING ) { /* match aliases */
982 struct berval bv_alias = { sizeof("ALIAS")-1, "ALIAS" };
983 af.f_choice = LDAP_FILTER_EQUALITY;
984 af.f_ava = &aa_alias;
985 af.f_av_desc = slap_schema.si_ad_objectClass;
986 af.f_av_value = bv_alias;
991 /* We added one of these clauses, filter depth increased */
992 if( xf.f_or != filter ) depth++;
996 f.f_choice = LDAP_FILTER_AND;
998 scopef.f_choice = scope == LDAP_SCOPE_SUBTREE
999 ? SLAPD_FILTER_DN_SUBTREE
1000 : SLAPD_FILTER_DN_ONE;
1001 scopef.f_dn = &e->e_nname;
1002 scopef.f_next = xf.f_or == filter ? filter : &xf ;
1003 /* Filter depth increased again, adding scope clause */
1006 #ifdef BDB_SUBENTRIES
1007 if( get_subentries_visibility( op ) ) {
1008 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1009 sf.f_choice = LDAP_FILTER_EQUALITY;
1010 sf.f_ava = &aa_subentry;
1011 sf.f_av_desc = slap_schema.si_ad_objectClass;
1012 sf.f_av_value = bv_subentry;
1013 sf.f_next = scopef.f_next;
1014 scopef.f_next = &sf;
1018 /* Allocate IDL stack, plus 1 more for former tmp */
1019 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1021 rc = bdb_filter_candidates( be, &f, ids, stack, stack+BDB_IDL_UM_SIZE );
1027 LDAP_LOG ( OPERATION, DETAIL1,
1028 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1030 Debug(LDAP_DEBUG_TRACE,
1031 "bdb_search_candidates: failed (rc=%d)\n",
1037 LDAP_LOG ( OPERATION, DETAIL1,
1038 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1039 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1040 (long) BDB_IDL_LAST(ids));
1042 Debug(LDAP_DEBUG_TRACE,
1043 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1045 (long) BDB_IDL_FIRST(ids),
1046 (long) BDB_IDL_LAST(ids) );