- if ( scope == LDAP_SCOPE_SUBTREE ) {
- lf = (Filter *) ch_malloc( sizeof(Filter) );
- lf->f_next = NULL;
- lf->f_choice = LDAP_FILTER_AND;
-#ifndef SLAPD_SCHEMA_NOT_COMPAT
- lf->f_and = (Filter *) ch_malloc( sizeof(Filter) );
-
- lf->f_and->f_choice = SLAPD_FILTER_DN_SUBTREE;
- lf->f_and->f_dn = e->e_ndn;
-
- lf->f_and->f_next = f;
-#endif
- f = lf;
-
- } else if ( scope == LDAP_SCOPE_ONELEVEL ) {
- lf = (Filter *) ch_malloc( sizeof(Filter) );
- lf->f_next = NULL;
- lf->f_choice = LDAP_FILTER_AND;
-#ifndef SLAPD_SCHEMA_NOT_COMPAT
- lf->f_and = (Filter *) ch_malloc( sizeof(Filter) );
-
- lf->f_and->f_choice = SLAPD_FILTER_DN_ONE;
- lf->f_and->f_dn = e->e_ndn;
-
- lf->f_and->f_next = f;
-#endif
- f = lf;
-
- } else {
- lf = NULL;
- }
-
- candidates = filter_candidates( be, f );
-
- /* free up filter additions we allocated above */
- if( lf != NULL ) {
-#ifndef SLAPD_SCHEMA_NOT_COMPAT
- free( lf->f_and );
-#endif
- free( lf );
- }
-
- if( af != NULL ) {
-#ifndef SLAPD_SCHEMA_NOT_COMPAT
- af->f_or->f_next = NULL;
-#endif
- filter_free( af );
- }
-
- if( rf != NULL ) {
-#ifndef SLAPD_SCHEMA_NOT_COMPAT
- rf->f_or->f_next = NULL;
-#endif
- filter_free( rf );
+ f.f_next = NULL;
+ f.f_choice = LDAP_FILTER_AND;
+ f.f_and = &fand;
+ fand.f_choice = scope == LDAP_SCOPE_ONELEVEL
+ ? SLAPD_FILTER_DN_ONE
+ : SLAPD_FILTER_DN_SUBTREE;
+ fand.f_dn = &e->e_nname;
+ fand.f_next = xf.f_or == filter ? filter : &xf ;
+
+ if ( get_subentries_visibility( op )) {
+ struct berval bv_subentry = { sizeof("SUBENTRY")-1, "SUBENTRY" };
+ sf.f_choice = LDAP_FILTER_EQUALITY;
+ sf.f_ava = &aa_subentry;
+ sf.f_av_desc = slap_schema.si_ad_objectClass;
+ sf.f_av_value = bv_subentry;
+ sf.f_next = fand.f_next;
+ fand.f_next = &sf;