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 #ifdef LDAP_CLIENT_UPDATE
85 if ( op->o_clientupdate_type & SLAP_LCUP_PERSIST ) {
86 bdb_add_psearch_spec( be, conn, op, base, base, scope,
87 deref, slimit, tlimit, filter, filterstr, attrs, attrsonly );
93 manageDSAit = get_manageDSAit( op );
95 rc = LOCK_ID (bdb->bi_dbenv, &locker );
100 send_ldap_result( conn, op, rc=LDAP_OTHER,
101 NULL, "internal error", NULL, NULL );
105 if ( nbase->bv_len == 0 ) {
106 /* DIT root special case */
107 e = (Entry *) &slap_entry_root;
111 /* get entry with reader lock */
112 if ( deref & LDAP_DEREF_FINDING ) {
113 e = deref_dn_r( be, nbase-, &err, &matched, &text );
119 rc = bdb_dn2entry_r( be, NULL, nbase, &e, &matched, 0, locker, &lock );
128 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
130 if (matched != NULL) {
131 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
133 send_ldap_result( conn, op, LDAP_BUSY,
134 NULL, "ldap server busy", NULL, NULL );
135 LOCK_ID_FREE (bdb->bi_dbenv, locker );
137 case DB_LOCK_DEADLOCK:
138 case DB_LOCK_NOTGRANTED:
142 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
144 if (matched != NULL) {
145 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
147 send_ldap_result( conn, op, rc=LDAP_OTHER,
148 NULL, "internal error", NULL, NULL );
149 LOCK_ID_FREE (bdb->bi_dbenv, locker );
154 struct berval matched_dn = { 0, NULL };
155 BerVarray refs = NULL;
157 if ( matched != NULL ) {
159 ber_dupbv( &matched_dn, &matched->e_name );
161 erefs = is_entry_referral( matched )
162 ? get_entry_referrals( be, conn, op, matched )
165 bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, matched, &lock);
169 refs = referral_rewrite( erefs, &matched_dn,
171 ber_bvarray_free( erefs );
175 refs = referral_rewrite( default_referral,
179 send_ldap_result( conn, op, rc=LDAP_REFERRAL ,
180 matched_dn.bv_val, text, refs, NULL );
182 LOCK_ID_FREE (bdb->bi_dbenv, locker );
183 if ( refs ) ber_bvarray_free( refs );
184 if ( matched_dn.bv_val ) ber_memfree( matched_dn.bv_val );
188 if (!manageDSAit && e != &slap_entry_root && is_entry_referral( e ) ) {
189 /* entry is a referral, don't allow add */
190 struct berval matched_dn;
191 BerVarray erefs, refs;
193 ber_dupbv( &matched_dn, &e->e_name );
194 erefs = get_entry_referrals( be, conn, op, e );
197 bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
201 refs = referral_rewrite( erefs, &matched_dn,
203 ber_bvarray_free( erefs );
207 LDAP_LOG ( OPERATION, RESULTS,
208 "bdb_search: entry is referral\n", 0, 0, 0 );
210 Debug( LDAP_DEBUG_TRACE, "bdb_search: entry is referral\n",
214 send_ldap_result( conn, op, LDAP_REFERRAL,
216 refs ? NULL : "bad referral object",
219 LOCK_ID_FREE (bdb->bi_dbenv, locker );
220 ber_bvarray_free( refs );
221 ber_memfree( matched_dn.bv_val );
225 /* if not root, get appropriate limits */
226 if ( be_isroot( be, &op->o_ndn ) ) {
229 ( void ) get_limits( be, &op->o_ndn, &limit );
232 /* The time/size limits come first because they require very little
233 * effort, so there's no chance the candidates are selected and then
234 * the request is not honored only because of time/size constraints */
236 /* if no time limit requested, use soft limit (unless root!) */
239 tlimit = -1; /* allow root to set no limit */
247 /* if no limit is required, use soft limit */
249 tlimit = limit->lms_t_soft;
251 /* if requested limit higher than hard limit, abort */
252 } else if ( tlimit > limit->lms_t_hard ) {
253 /* no hard limit means use soft instead */
254 if ( limit->lms_t_hard == 0 && tlimit > limit->lms_t_soft ) {
255 tlimit = limit->lms_t_soft;
257 /* positive hard limit means abort */
258 } else if ( limit->lms_t_hard > 0 ) {
259 send_search_result( conn, op,
260 LDAP_UNWILLING_TO_PERFORM,
261 NULL, NULL, NULL, NULL, 0 );
266 /* negative hard limit means no limit */
269 /* if no limit is required, use soft limit */
271 slimit = limit->lms_s_soft;
273 /* if requested limit higher than hard limit, abort */
274 } else if ( slimit > limit->lms_s_hard ) {
275 /* no hard limit means use soft instead */
276 if ( limit->lms_s_hard == 0 && slimit > limit->lms_s_soft ) {
277 slimit = limit->lms_s_soft;
279 /* positive hard limit means abort */
280 } else if ( limit->lms_s_hard > 0 ) {
281 send_search_result( conn, op,
282 LDAP_UNWILLING_TO_PERFORM,
283 NULL, NULL, NULL, NULL, 0 );
288 /* negative hard limit means no limit */
292 /* compute it anyway; root does not use it */
293 stoptime = op->o_time + tlimit;
295 /* select candidates */
296 if ( scope == LDAP_SCOPE_BASE ) {
297 rc = base_candidate( be, e, candidates );
300 BDB_IDL_ALL( bdb, candidates );
301 rc = search_candidates( be, op, e, filter,
302 scope, deref, candidates );
305 /* need normalized dn below */
306 ber_dupbv( &realbase, &e->e_nname );
308 /* start cursor at beginning of candidates.
312 if ( e != &slap_entry_root ) {
313 bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
317 if ( candidates[0] == 0 ) {
319 LDAP_LOG ( OPERATION, RESULTS,
320 "bdb_search: no candidates\n", 0, 0, 0 );
322 Debug( LDAP_DEBUG_TRACE, "bdb_search: no candidates\n",
326 send_search_result( conn, op,
328 NULL, NULL, NULL, NULL, 0 );
334 /* if not root and candidates exceed to-be-checked entries, abort */
335 if ( !isroot && limit->lms_s_unchecked != -1 ) {
336 if ( BDB_IDL_N(candidates) > (unsigned) limit->lms_s_unchecked ) {
337 send_search_result( conn, op,
338 LDAP_ADMINLIMIT_EXCEEDED,
339 NULL, NULL, NULL, NULL, 0 );
345 #ifdef SLAP_X_FILTER_HASSUBORDINATES
347 * is hasSubordinates used in the filter ?
348 * FIXME: we may compute this directly when parsing the filter
350 filter_hasSubordinates = filter_has_subordinates( filter );
351 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
353 #ifdef LDAP_CLIENT_UPDATE
354 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
355 lcupf.f_choice = LDAP_FILTER_AND;
356 lcupf.f_and = &csnfnot;
359 csnfnot.f_choice = LDAP_FILTER_NOT;
360 csnfnot.f_not = &csnfeq;
361 csnfnot.f_next = &csnfand;
363 csnfeq.f_choice = LDAP_FILTER_EQUALITY;
364 csnfeq.f_ava = &aa_eq;
365 csnfeq.f_av_desc = slap_schema.si_ad_entryCSN;
366 ber_dupbv( &csnfeq.f_av_value, &op->o_clientupdate_state );
368 csnfand.f_choice = LDAP_FILTER_AND;
369 csnfand.f_and = &csnfge;
370 csnfand.f_next = NULL;
372 csnfge.f_choice = LDAP_FILTER_GE;
373 csnfge.f_ava = &aa_ge;
374 csnfge.f_av_desc = slap_schema.si_ad_entryCSN;
375 ber_dupbv( &csnfge.f_av_value, &op->o_clientupdate_state );
376 csnfge.f_next = filter;
378 #endif /* LDAP_CLIENT_UPDATE */
380 for ( id = bdb_idl_first( candidates, &cursor );
382 id = bdb_idl_next( candidates, &cursor ) )
385 #ifdef SLAP_X_FILTER_HASSUBORDINATES
386 Attribute *hasSubordinates = NULL;
387 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
389 /* check for abandon */
390 if ( op->o_abandon ) {
395 /* check time limit */
396 if ( tlimit != -1 && slap_get_time() > stoptime ) {
397 send_search_result( conn, op, rc = LDAP_TIMELIMIT_EXCEEDED,
398 NULL, NULL, v2refs, NULL, nentries );
403 /* get the entry with reader lock */
404 rc = bdb_id2entry_r( be, NULL, id, &e, locker, &lock );
406 if (rc == LDAP_BUSY) {
407 send_ldap_result( conn, op, rc=LDAP_BUSY,
408 NULL, "ldap server busy", NULL, NULL );
411 } else if ( rc == DB_LOCK_DEADLOCK || rc == DB_LOCK_NOTGRANTED ) {
416 if( !BDB_IDL_IS_RANGE(candidates) ) {
417 /* only complain for non-range IDLs */
419 LDAP_LOG ( OPERATION, RESULTS,
420 "bdb_search: candidate %ld not found\n", (long) id, 0, 0);
422 Debug( LDAP_DEBUG_TRACE,
423 "bdb_search: candidate %ld not found\n",
431 #ifdef BDB_SUBENTRIES
432 if ( is_entry_subentry( e ) ) {
433 if( scope != LDAP_SCOPE_BASE ) {
434 if(!get_subentries_visibility( op )) {
435 /* only subentries are visible */
439 } else if ( get_subentries( op ) &&
440 !get_subentries_visibility( op ))
442 /* only subentries are visible */
446 } else if ( get_subentries_visibility( op )) {
447 /* only subentries are visible */
453 if ( deref & LDAP_DEREF_SEARCHING && is_entry_alias( e ) ) {
458 e = deref_entry_r( be, e, &err, &matched, &text );
465 if( e->e_id == id ) {
470 /* need to skip alias which deref into scope */
471 if( scope & LDAP_SCOPE_ONELEVEL ) {
474 dnParent( &e->e_nname, &pdn ):
475 if ( ber_bvcmp( pdn, &realbase ) ) {
479 } else if ( dnIsSuffix( &e->e_nname, &realbase ) ) {
480 /* alias is within scope */
482 LDAP_LOG ( OPERATION, RESULTS,
483 "bdb_search: \"%s\" in subtree\n", e->edn, 0, 0);
485 Debug( LDAP_DEBUG_TRACE,
486 "bdb_search: \"%s\" in subtree\n",
497 * if it's a referral, add it to the list of referrals. only do
498 * this for non-base searches, and don't check the filter
499 * explicitly here since it's only a candidate anyway.
501 if ( !manageDSAit && scope != LDAP_SCOPE_BASE &&
502 is_entry_referral( e ) )
507 if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
508 if ( !be_issuffix( be, &e->e_nname ) ) {
509 dnParent( &e->e_nname, &dn );
510 scopeok = dn_match( &dn, &realbase );
512 scopeok = (realbase.bv_len == 0);
515 } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
516 scopeok = dnIsSuffix( &e->e_nname, &realbase );
523 BerVarray erefs = get_entry_referrals(
525 BerVarray refs = referral_rewrite( erefs,
527 scope == LDAP_SCOPE_SUBTREE
531 send_search_reference( be, conn, op,
532 e, refs, NULL, &v2refs );
534 ber_bvarray_free( refs );
538 LDAP_LOG(OPERATION, DETAIL2,
539 "bdb_search: candidate referral %ld scope not okay\n",
542 Debug( LDAP_DEBUG_TRACE,
543 "bdb_search: candidate referral %ld scope not okay\n",
551 #ifdef SLAP_X_FILTER_HASSUBORDINATES
553 * if hasSubordinates is used in the filter,
554 * append it to the entry's attributes
556 if ( filter_hasSubordinates ) {
559 rc = bdb_hasSubordinates( be, conn, op, e, &hs);
560 if ( rc != LDAP_SUCCESS ) {
564 hasSubordinates = slap_operational_hasSubordinate(
565 hs == LDAP_COMPARE_TRUE );
567 if ( hasSubordinates == NULL ) {
571 hasSubordinates->a_next = e->e_attrs;
572 e->e_attrs = hasSubordinates;
574 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
576 /* if it matches the filter and scope, send it */
577 #ifdef LDAP_CLIENT_UPDATE
578 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
579 rc = test_filter( be, conn, op, e, &lcupf );
581 #endif /* LDAP_CLIENT_UPDATE */
583 rc = test_filter( be, conn, op, e, filter );
586 #ifdef SLAP_X_FILTER_HASSUBORDINATES
587 if ( hasSubordinates ) {
589 * FIXME: this is fairly inefficient, because
590 * if hasSubordinates is among the required
591 * attrs, it will be added again later;
592 * maybe we should leave it and check
593 * check later if it's already present,
596 e->e_attrs = e->e_attrs->a_next;
597 attr_free( hasSubordinates );
599 #endif /* SLAP_X_FILTER_HASSUBORDINATES */
601 if ( rc == LDAP_COMPARE_TRUE ) {
605 if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
606 if ( be_issuffix( be, &e->e_nname ) ) {
607 scopeok = (realbase.bv_len == 0);
609 dnParent( &e->e_nname, &dn );
610 scopeok = dn_match( &dn, &realbase );
613 } else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
614 scopeok = dnIsSuffix( &e->e_nname, &realbase );
621 /* check size limit */
622 if ( --slimit == -1 ) {
623 bdb_cache_return_entry_r( bdb->bi_dbenv,
624 &bdb->bi_cache, e, &lock );
626 send_search_result( conn, op,
627 rc = LDAP_SIZELIMIT_EXCEEDED, NULL, NULL,
628 v2refs, NULL, nentries );
635 #if 0 /* noop is masked SLAP_CTRL_UPDATE */
641 #ifdef LDAP_CLIENT_UPDATE
642 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
646 const char *text = NULL;
647 LDAPControl *ctrls[2];
650 BerElement *ber = ber_alloc_t( LBER_USE_DER );
654 LDAP_LOG ( OPERATION, RESULTS,
655 "bdb_search: ber_alloc_t failed\n",
658 Debug( LDAP_DEBUG_TRACE,
659 "bdb_search: ber_alloc_t failed\n",
662 send_ldap_result( conn, op, rc=LDAP_OTHER,
663 NULL, "internal error", NULL, NULL );
669 ctrls[0] = ch_malloc ( sizeof ( LDAPControl ) );
672 if ( entry_count % op->o_clientupdate_interval == 0 ) {
674 for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
675 AttributeDescription *desc = a->a_desc;
676 if ( desc == slap_schema.si_ad_entryCSN ) {
677 ber_dupbv( &entrycsn_bv, &a->a_vals[0] );
678 if ( latest_entrycsn_bv.bv_val == NULL ) {
679 ber_dupbv( &latest_entrycsn_bv, &entrycsn_bv );
681 res = value_match( &ret, desc,
682 desc->ad_type->sat_ordering,
683 SLAP_MR_ASSERTION_SYNTAX_MATCH,
684 &entrycsn_bv, &latest_entrycsn_bv, &text );
685 if ( res != LDAP_SUCCESS ) {
688 LDAP_LOG ( OPERATION, RESULTS,
689 "bdb_search: value_match failed\n",
692 Debug( LDAP_DEBUG_TRACE,
693 "bdb_search: value_match failed\n",
699 ch_free( latest_entrycsn_bv.bv_val );
700 latest_entrycsn_bv.bv_val = NULL;
701 ber_dupbv( &latest_entrycsn_bv,
710 SLAP_LCUP_STATE_UPDATE_FALSE,
711 SLAP_LCUP_ENTRY_DELETED_FALSE,
712 LCUP_COOKIE_OID, &entrycsn_bv );
714 ch_free( entrycsn_bv.bv_val );
715 entrycsn_bv.bv_val = NULL;
718 /* Do not send cookie */
721 SLAP_LCUP_STATE_UPDATE_FALSE,
722 SLAP_LCUP_ENTRY_DELETED_FALSE );
725 ctrls[0]->ldctl_oid = LDAP_CONTROL_ENTRY_UPDATE;
726 ctrls[0]->ldctl_iscritical = op->o_clientupdate;
727 ret = ber_flatten( ber, &bv );
731 LDAP_LOG ( OPERATION, RESULTS,
732 "bdb_search: ber_flatten failed\n",
735 Debug( LDAP_DEBUG_TRACE,
736 "bdb_search: ber_flatten failed\n",
739 send_ldap_result( conn, op, rc=LDAP_OTHER,
740 NULL, "internal error", NULL, NULL );
744 ber_dupbv( &ctrls[0]->ldctl_value, bv );
746 result = send_search_entry( be, conn, op,
747 e, attrs, attrsonly, ctrls);
749 ch_free( ctrls[0]->ldctl_value.bv_val );
754 #endif /* LDAP_CLIENT_UPDATE */
756 result = send_search_entry( be, conn, op,
757 e, attrs, attrsonly, NULL);
762 case 0: /* entry sent ok */
765 case 1: /* entry not sent */
767 case -1: /* connection closed */
768 bdb_cache_return_entry_r(bdb->bi_dbenv,
769 &bdb->bi_cache, e, &lock);
777 LDAP_LOG ( OPERATION, RESULTS,
778 "bdb_search: %ld scope not okay\n", (long) id, 0, 0);
780 Debug( LDAP_DEBUG_TRACE,
781 "bdb_search: %ld scope not okay\n",
787 LDAP_LOG ( OPERATION, RESULTS,
788 "bdb_search: %ld does match filter\n", (long) id, 0, 0);
790 Debug( LDAP_DEBUG_TRACE,
791 "bdb_search: %ld does match filter\n",
798 /* free reader lock */
799 bdb_cache_return_entry_r( bdb->bi_dbenv,
800 &bdb->bi_cache, e , &lock);
804 ldap_pvt_thread_yield();
807 #ifdef LDAP_CLIENT_UPDATE
808 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
810 LDAPControl *ctrls[2];
811 BerElement *ber = ber_alloc_t( LBER_USE_DER );
816 LDAP_LOG ( OPERATION, RESULTS,
817 "bdb_search: ber_alloc_t failed\n", 0, 0, 0 );
819 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_alloc_t failed\n",
822 send_ldap_result( conn, op, rc=LDAP_OTHER,
823 NULL, "internal error", NULL, NULL );
827 ctrls[0] = ch_malloc ( sizeof ( LDAPControl ) );
830 ber_printf( ber, "{sO", LCUP_COOKIE_OID, &latest_entrycsn_bv );
831 ber_printf( ber, "N}" );
833 ctrls[0]->ldctl_oid = LDAP_CONTROL_CLIENT_UPDATE_DONE;
834 ctrls[0]->ldctl_iscritical = op->o_clientupdate;
835 ret = ber_flatten( ber, &bv );
839 LDAP_LOG ( OPERATION, RESULTS,
840 "bdb_search: ber_flatten failed\n", 0, 0, 0 );
842 Debug( LDAP_DEBUG_TRACE, "bdb_search: ber_flatten failed\n",
845 send_ldap_result( conn, op, rc=LDAP_OTHER,
846 NULL, "internal error", NULL, NULL );
850 ber_dupbv( &ctrls[0]->ldctl_value, bv );
852 send_search_result( conn, op,
853 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
854 NULL, NULL, v2refs, ctrls, nentries );
856 ch_free( latest_entrycsn_bv.bv_val );
857 latest_entrycsn_bv.bv_val = NULL;
858 ch_free( ctrls[0]->ldctl_value.bv_val );
863 #endif /* LDAP_CLIENT_UPDATE */
865 send_search_result( conn, op,
866 v2refs == NULL ? LDAP_SUCCESS : LDAP_REFERRAL,
867 NULL, NULL, v2refs, NULL, nentries );
874 /* free reader lock */
875 bdb_cache_return_entry_r ( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
878 #ifdef LDAP_CLIENT_UPDATE
879 if ( op->o_clientupdate_type & SLAP_LCUP_SYNC ) {
880 if ( csnfeq.f_ava != NULL && csnfeq.f_av_value.bv_val != NULL ) {
881 ch_free( csnfeq.f_av_value.bv_val );
884 if ( csnfge.f_ava != NULL && csnfge.f_av_value.bv_val != NULL ) {
885 ch_free( csnfge.f_av_value.bv_val );
888 #endif /* LDAP_CLIENT_UPDATE */
890 LOCK_ID_FREE (bdb->bi_dbenv, locker );
892 if( v2refs ) ber_bvarray_free( v2refs );
893 if( realbase.bv_val ) ch_free( realbase.bv_val );
899 static int base_candidate(
905 LDAP_LOG ( OPERATION, ENTRY,
906 "base_candidate: base: \"%s\" (0x%08lx)\n", e->e_dn, (long) e->e_id, 0);
908 Debug(LDAP_DEBUG_ARGS, "base_candidates: base: \"%s\" (0x%08lx)\n",
909 e->e_dn, (long) e->e_id, 0);
917 /* Look for "objectClass Present" in this filter.
918 * Also count depth of filter tree while we're at it.
920 static int oc_filter(
928 if( cur > *max ) *max = cur;
930 switch(f->f_choice) {
931 case LDAP_FILTER_PRESENT:
932 if (f->f_desc == slap_schema.si_ad_objectClass) {
937 case LDAP_FILTER_AND:
940 for (f=f->f_and; f; f=f->f_next) {
941 (void) oc_filter(f, cur, max);
951 static int search_candidates(
961 Filter f, scopef, rf, xf;
963 AttributeAssertion aa_ref;
964 #ifdef BDB_SUBENTRIES
966 AttributeAssertion aa_subentry;
970 AttributeAssertion aa_alias;
974 * This routine takes as input a filter (user-filter)
975 * and rewrites it as follows:
976 * (&(scope=DN)[(objectClass=subentry)]
977 * (|[(objectClass=referral)(objectClass=alias)](user-filter))
981 LDAP_LOG ( OPERATION, ENTRY,
982 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
983 e->e_dn, (long) e->e_id, scope);
985 Debug(LDAP_DEBUG_TRACE,
986 "search_candidates: base=\"%s\" (0x%08lx) scope=%d\n",
987 e->e_dn, (long) e->e_id, scope );
991 xf.f_choice = LDAP_FILTER_OR;
994 /* If the user's filter uses objectClass=*,
995 * these clauses are redundant.
997 if (!oc_filter(filter, 1, &depth) && !get_subentries_visibility(op) ) {
998 if( !get_manageDSAit(op) ) { /* match referrals */
999 struct berval bv_ref = { sizeof("REFERRAL")-1, "REFERRAL" };
1000 rf.f_choice = LDAP_FILTER_EQUALITY;
1002 rf.f_av_desc = slap_schema.si_ad_objectClass;
1003 rf.f_av_value = bv_ref;
1004 rf.f_next = xf.f_or;
1009 if( deref & LDAP_DEREF_SEARCHING ) { /* match aliases */
1010 struct berval bv_alias = { sizeof("ALIAS")-1, "ALIAS" };
1011 af.f_choice = LDAP_FILTER_EQUALITY;
1012 af.f_ava = &aa_alias;
1013 af.f_av_desc = slap_schema.si_ad_objectClass;
1014 af.f_av_value = bv_alias;
1015 af.f_next = xf.f_or;
1019 /* We added one of these clauses, filter depth increased */
1020 if( xf.f_or != filter ) depth++;
1024 f.f_choice = LDAP_FILTER_AND;
1026 scopef.f_choice = scope == LDAP_SCOPE_SUBTREE
1027 ? SLAPD_FILTER_DN_SUBTREE
1028 : SLAPD_FILTER_DN_ONE;
1029 scopef.f_dn = &e->e_nname;
1030 scopef.f_next = xf.f_or == filter ? filter : &xf ;
1031 /* Filter depth increased again, adding scope clause */
1034 #ifdef BDB_SUBENTRIES
1035 if( get_subentries_visibility( op ) ) {
1036 struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
1037 sf.f_choice = LDAP_FILTER_EQUALITY;
1038 sf.f_ava = &aa_subentry;
1039 sf.f_av_desc = slap_schema.si_ad_objectClass;
1040 sf.f_av_value = bv_subentry;
1041 sf.f_next = scopef.f_next;
1042 scopef.f_next = &sf;
1046 /* Allocate IDL stack, plus 1 more for former tmp */
1047 stack = ch_malloc( (depth + 1) * BDB_IDL_UM_SIZE * sizeof( ID ) );
1049 rc = bdb_filter_candidates( be, &f, ids, stack, stack+BDB_IDL_UM_SIZE );
1055 LDAP_LOG ( OPERATION, DETAIL1,
1056 "bdb_search_candidates: failed (rc=%d)\n", rc, 0, 0 );
1058 Debug(LDAP_DEBUG_TRACE,
1059 "bdb_search_candidates: failed (rc=%d)\n",
1065 LDAP_LOG ( OPERATION, DETAIL1,
1066 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1067 (long) ids[0], (long) BDB_IDL_FIRST(ids),
1068 (long) BDB_IDL_LAST(ids));
1070 Debug(LDAP_DEBUG_TRACE,
1071 "bdb_search_candidates: id=%ld first=%ld last=%ld\n",
1073 (long) BDB_IDL_FIRST(ids),
1074 (long) BDB_IDL_LAST(ids) );