]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/filterindex.c
ITS#2440 unmunge init_module names
[openldap] / servers / slapd / back-ldbm / filterindex.c
index 6bf80cb99acd468ab9687692021957118747c733..79a2ee45b6ffe3d2839ae13da898cb4512406b9a 100644 (file)
@@ -1,7 +1,7 @@
 /* filterindex.c - generate the list of candidate entries from a filter */
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 
 #include "back-ldbm.h"
 
 static ID_BLOCK        *presence_candidates(
-       Backend *be,
+       Operation *op,
        AttributeDescription *desc );
 static ID_BLOCK        *equality_candidates(
-       Backend *be, AttributeAssertion *ava );
+       Operation *op, AttributeAssertion *ava );
 static ID_BLOCK        *approx_candidates(
-       Backend *be, AttributeAssertion *ava );
+       Operation *op, AttributeAssertion *ava );
 static ID_BLOCK        *substring_candidates(
-       Backend *be,
+       Operation *op,
        SubstringsAssertion *sub );
 static ID_BLOCK        *list_candidates(
-       Backend *be,
+       Operation *op,
        Filter *flist,
        int ftype );
 
 ID_BLOCK *
 filter_candidates(
-    Backend    *be,
+    Operation  *op,
     Filter     *f
 )
 {
        ID_BLOCK        *result;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY, "filter_candidates: enter\n"));
+       LDAP_LOG( FILTER, ENTRY, "filter_candidates: enter\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> filter_candidates\n", 0, 0, 0 );
 #endif
@@ -47,16 +47,32 @@ filter_candidates(
 
        result = NULL;
        switch ( f->f_choice ) {
+       case SLAPD_FILTER_COMPUTED:
+               switch( f->f_result ) {
+               case SLAPD_COMPARE_UNDEFINED:
+               /* This technically is not the same as FALSE, but it
+                * certainly will produce no matches.
+                */
+               /* FALLTHRU */
+               case LDAP_COMPARE_FALSE:
+                       result = NULL;
+                       break;
+               case LDAP_COMPARE_TRUE:
+                       result = idl_allids( op->o_bd );
+                       break;
+               }
+               break;
+
        case SLAPD_FILTER_DN_ONE:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  DN ONE (%s)\n", f->f_dn ));
+               LDAP_LOG( FILTER, DETAIL1, 
+                          "filter_candidates:  DN ONE (%s)\n", f->f_dn, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tDN ONE\n", 0, 0, 0 );
 #endif
 
                /* an error is treated as an empty list */
-               if ( dn2idl( be, f->f_dn, DN_ONE_PREFIX, &result ) != 0
+               if ( dn2idl( op->o_bd, f->f_dn, DN_ONE_PREFIX, &result ) != 0
                                && result != NULL ) {
                        idl_free( result );
                        result = NULL;
@@ -65,14 +81,14 @@ filter_candidates(
 
        case SLAPD_FILTER_DN_SUBTREE:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  DN SUBTREE (%s)\n", f->f_dn ));
+               LDAP_LOG( FILTER, DETAIL1, 
+                          "filter_candidates:  DN SUBTREE (%s)\n", f->f_dn, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tDN SUBTREE\n", 0, 0, 0 );
 #endif
 
                /* an error is treated as an empty list */
-               if ( dn2idl( be, f->f_dn, DN_SUBTREE_PREFIX, &result ) != 0
+               if ( dn2idl( op->o_bd, f->f_dn, DN_SUBTREE_PREFIX, &result ) != 0
                                && result != NULL ) {
                        idl_free( result );
                        result = NULL;
@@ -81,100 +97,96 @@ filter_candidates(
 
        case LDAP_FILTER_PRESENT:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  Present (%s)\n", f->f_desc->ad_cname.bv_val ));
+               LDAP_LOG( FILTER, DETAIL1, 
+                       "filter_candidates:  Present (%s)\n", 
+                       f->f_desc->ad_cname.bv_val, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tPRESENT\n", 0, 0, 0 );
 #endif
 
-               result = presence_candidates( be, f->f_desc );
+               result = presence_candidates( op, f->f_desc );
                break;
 
        case LDAP_FILTER_EQUALITY:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
+               LDAP_LOG( FILTER, DETAIL1, 
                           "filter_candidates:  EQUALITY (%s),(%s)\n",
                           f->f_ava->aa_desc->ad_cname.bv_val,
-                          f->f_ava->aa_value.bv_val ));
+                          f->f_ava->aa_value.bv_val, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 );
 #endif
 
-               result = equality_candidates( be, f->f_ava );
+               result = equality_candidates( op, f->f_ava );
                break;
 
        case LDAP_FILTER_APPROX:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
+               LDAP_LOG( FILTER, DETAIL1, 
                           "filter_candidates:  APPROX (%s), (%s)\n",
                           f->f_ava->aa_desc->ad_cname.bv_val,
-                          f->f_ava->aa_value.bv_val ));
+                          f->f_ava->aa_value.bv_val, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tAPPROX\n", 0, 0, 0 );
 #endif
 
-               result = approx_candidates( be, f->f_ava );
+               result = approx_candidates( op, f->f_ava );
                break;
 
        case LDAP_FILTER_SUBSTRINGS:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  SUBSTRINGS\n"));
+               LDAP_LOG( FILTER, DETAIL1,
+                          "filter_candidates:  SUBSTRINGS\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tSUBSTRINGS\n", 0, 0, 0 );
 #endif
 
-               result = substring_candidates( be, f->f_sub );
+               result = substring_candidates( op, f->f_sub );
                break;
 
        case LDAP_FILTER_GE:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  GE\n"));
+               LDAP_LOG( FILTER, DETAIL1, "filter_candidates:  GE\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tGE\n", 0, 0, 0 );
 #endif
 
-               result = presence_candidates( be, f->f_desc );
+               result = presence_candidates( op, f->f_ava->aa_desc );
                break;
 
        case LDAP_FILTER_LE:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  LE\n" ));
+               LDAP_LOG( FILTER, DETAIL1, "filter_candidates:  LE\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tLE\n", 0, 0, 0 );
 #endif
 
-               result = presence_candidates( be, f->f_desc );
+               result = presence_candidates( op, f->f_ava->aa_desc );
                break;
 
        case LDAP_FILTER_AND:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  AND\n" ));
+               LDAP_LOG( FILTER, DETAIL1, "filter_candidates:  AND\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tAND\n", 0, 0, 0 );
 #endif
 
-               result = list_candidates( be, f->f_and, LDAP_FILTER_AND );
+               result = list_candidates( op, f->f_and, LDAP_FILTER_AND );
                break;
 
        case LDAP_FILTER_OR:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  OR\n" ));
+               LDAP_LOG( FILTER, DETAIL1, "filter_candidates:  OR\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tOR\n", 0, 0, 0 );
 #endif
 
-               result = list_candidates( be, f->f_or, LDAP_FILTER_OR );
+               result = list_candidates( op, f->f_or, LDAP_FILTER_OR );
                break;
 
        case LDAP_FILTER_NOT:
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                          "filter_candidates:  NOT\n" ));
+               LDAP_LOG( FILTER, DETAIL1, "filter_candidates:  NOT\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_FILTER, "\tNOT\n", 0, 0, 0 );
 #endif
@@ -185,14 +197,25 @@ filter_candidates(
                 * list could result in matching entries be excluded from
                 * the returned candidate list.
                 */
-               result = idl_allids( be );
+               result = idl_allids( op->o_bd );
+               break;
+       default:
+#ifdef NEW_LOGGING
+               LDAP_LOG( FILTER, DETAIL1, "filter_candidates:  UNKNOWN\n", 0, 0, 0 );
+#else
+               Debug( LDAP_DEBUG_FILTER, "\tUNKNOWN\n", 0, 0, 0 );
+#endif
+               /* unknown filters must not return NULL, to allow
+                * extended filter processing to be done later.
+                */
+               result = idl_allids( op->o_bd );
                break;
        }
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "filter_candidates: return %ld\n",
-                  result ? ID_BLOCK_NIDS(result) : 0 ));
+       LDAP_LOG( FILTER, ENTRY, 
+               "filter_candidates: return %ld\n", 
+               result ? ID_BLOCK_NIDS(result) : 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= filter_candidates %ld\n",
            result ? ID_BLOCK_NIDS(result) : 0, 0, 0 );
@@ -203,7 +226,7 @@ filter_candidates(
 
 static ID_BLOCK *
 presence_candidates(
-    Backend    *be,
+    Operation *op,
        AttributeDescription *desc
 )
 {
@@ -212,29 +235,27 @@ presence_candidates(
        int rc;
        char *dbname;
        slap_mask_t mask;
-       struct berval prefix = {0};
+       struct berval prefix = {0, NULL};
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "presence_candidates: enter\n" ));
+       LDAP_LOG( FILTER, ENTRY, "presence_candidates: enter\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> presence_candidates\n", 0, 0, 0 );
 #endif
 
-       idl = idl_allids( be );
+       idl = idl_allids( op->o_bd );
 
        if( desc == slap_schema.si_ad_objectClass ) {
                return idl;
        }
 
-       rc = index_param( be, desc, LDAP_FILTER_PRESENT,
+       rc = index_param( op->o_bd, desc, LDAP_FILTER_PRESENT,
                &dbname, &mask, &prefix );
 
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
-                          "presence_candidates: index_param returned %d\n",
-                          rc ));
+               LDAP_LOG( FILTER, INFO, 
+                          "presence_candidates: index_param returned %d\n", rc, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= presence_candidates: index_param returned=%d\n",
@@ -247,8 +268,7 @@ presence_candidates(
        if( dbname == NULL ) {
                /* not indexed */
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
-                          "presence_candidates: not indexed\n" ));
+               LDAP_LOG( FILTER, INFO, "presence_candidates: not indexed\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= presense_candidates: not indexed\n",
@@ -258,13 +278,13 @@ presence_candidates(
                return idl;
        }
 
-       db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
+       db = ldbm_cache_open( op->o_bd, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
        
        if ( db == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
+               LDAP_LOG( FILTER, INFO, 
                           "presence_candidates: db open failed (%s%s)\n",
-                          dbname, LDBM_SUFFIX ));
+                          dbname, LDBM_SUFFIX, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                    "<= presense_candidates db open failed (%s%s)\n",
@@ -278,12 +298,12 @@ presence_candidates(
                idl_free( idl );
                idl = NULL;
 
-               rc = key_read( be, db, &prefix, &idl );
+               rc = key_read( op->o_bd, db, &prefix, &idl );
 
                if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                                  "presence_candidates: key read failed (%d)\n", rc ));
+                       LDAP_LOG( FILTER, ERR, 
+                                  "presence_candidates: key read failed (%d)\n", rc, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE,
                                "<= presense_candidates key read failed (%d)\n",
@@ -293,8 +313,7 @@ presence_candidates(
 
                } else if( idl == NULL ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_DETAIL1,
-                                  "presence_candidates: NULL\n" ));
+                       LDAP_LOG( FILTER, DETAIL1, "presence_candidates: NULL\n", 0, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE,
                                "<= presense_candidates NULL\n",
@@ -304,12 +323,12 @@ presence_candidates(
                }
        }
 
-       ldbm_cache_close( be, db );
+       ldbm_cache_close( op->o_bd, db );
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "presence_candidates:  return %ld\n",
-                  idl ? ID_BLOCK_NIDS(idl) : 0 ));
+       LDAP_LOG( FILTER, ENTRY, 
+               "presence_candidates:  return %ld\n", 
+               idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= presence_candidates %ld\n",
            idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
@@ -320,7 +339,7 @@ presence_candidates(
 
 static ID_BLOCK *
 equality_candidates(
-    Backend    *be,
+    Operation *op,
        AttributeAssertion *ava
 )
 {
@@ -330,27 +349,26 @@ equality_candidates(
        int rc;
        char *dbname;
        slap_mask_t mask;
-       struct berval prefix = {0};
+       struct berval prefix = {0, NULL};
        struct berval *keys = NULL;
        MatchingRule *mr;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "equality_candidates: enter\n" ));
+       LDAP_LOG( FILTER, ENTRY, "equality_candidates: enter\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> equality_candidates\n", 0, 0, 0 );
 #endif
 
 
-       idl = idl_allids( be );
+       idl = idl_allids( op->o_bd );
 
-       rc = index_param( be, ava->aa_desc, LDAP_FILTER_EQUALITY,
+       rc = index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY,
                &dbname, &mask, &prefix );
 
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "equality_candidates:  index_param returned %d\n", rc ));
+               LDAP_LOG( FILTER, ERR, 
+                          "equality_candidates:  index_param returned %d\n", rc, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= equality_candidates: index_param returned=%d\n",
@@ -363,8 +381,7 @@ equality_candidates(
        if( dbname == NULL ) {
                /* not indexed */
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "equality_candidates: not indexed\n" ));
+               LDAP_LOG( FILTER, ERR, "equality_candidates: not indexed\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= equality_candidates: not indexed\n",
@@ -390,13 +407,13 @@ equality_candidates(
                mr,
                &prefix,
                &ava->aa_value,
-               &keys );
+               &keys, op->o_tmpmemctx );
 
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
+               LDAP_LOG( FILTER, ERR, 
                           "equality_candidates: (%s%s) MR filter failed (%d\n",
-                          dbname, LDBM_SUFFIX, rc ));
+                          dbname, LDBM_SUFFIX, rc );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= equality_candidates: (%s%s) MR filter failed (%d)\n",
@@ -408,9 +425,8 @@ equality_candidates(
 
        if( keys == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "equality_candidates: no keys (%s%s)\n",
-                          dbname, LDBM_SUFFIX ));
+               LDAP_LOG( FILTER, ERR, 
+                  "equality_candidates: no keys (%s%s)\n", dbname, LDBM_SUFFIX, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= equality_candidates: no keys (%s%s)\n",
@@ -420,13 +436,12 @@ equality_candidates(
                return idl;
        }
 
-       db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
+       db = ldbm_cache_open( op->o_bd, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
        
        if ( db == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "equality_candidates: db open failed (%s%s)\n",
-                          dbname, LDBM_SUFFIX ));
+               LDAP_LOG( FILTER, ERR, "equality_candidates: db open failed (%s%s)\n",
+                       dbname, LDBM_SUFFIX, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                    "<= equality_candidates db open failed (%s%s)\n",
@@ -440,14 +455,14 @@ equality_candidates(
                ID_BLOCK *save;
                ID_BLOCK *tmp;
 
-               rc = key_read( be, db, &keys[i], &tmp );
+               rc = key_read( op->o_bd, db, &keys[i], &tmp );
 
                if( rc != LDAP_SUCCESS ) {
                        idl_free( idl );
                        idl = NULL;
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                                  "equality_candidates: key read failed (%d)\n", rc ));
+                       LDAP_LOG( FILTER, ERR, 
+                                  "equality_candidates: key read failed (%d)\n", rc, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE,
                                "<= equality_candidates key read failed (%d)\n",
@@ -461,8 +476,7 @@ equality_candidates(
                        idl_free( idl );
                        idl = NULL;
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
-                                  "equality_candidates NULL\n" ));
+                       LDAP_LOG( FILTER, INFO, "equality_candidates NULL\n", 0, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE,
                                "<= equality_candidates NULL\n",
@@ -473,22 +487,22 @@ equality_candidates(
                }
 
                save = idl;
-               idl = idl_intersection( be, idl, tmp );
+               idl = idl_intersection( op->o_bd, idl, tmp );
                idl_free( save );
                idl_free( tmp );
 
                if( idl == NULL ) break;
        }
 
-       bvarray_free( keys );
+       ber_bvarray_free_x( keys, op->o_tmpmemctx );
 
-       ldbm_cache_close( be, db );
+       ldbm_cache_close( op->o_bd, db );
 
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "equality_candidates: return %ld\n",
-                  idl ? ID_BLOCK_NIDS(idl) : 0 ));
+       LDAP_LOG( FILTER, ENTRY, 
+                  "equality_candidates: return %ld\n", 
+                  idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= equality_candidates %ld\n",
            idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
@@ -499,7 +513,7 @@ equality_candidates(
 
 static ID_BLOCK *
 approx_candidates(
-    Backend    *be,
+    Operation *op,
        AttributeAssertion *ava
 )
 {
@@ -509,27 +523,26 @@ approx_candidates(
        int rc;
        char *dbname;
        slap_mask_t mask;
-       struct berval prefix = {0};
+       struct berval prefix = {0, NULL};
        struct berval *keys = NULL;
        MatchingRule *mr;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "approx_candidates: enter\n" ));
+       LDAP_LOG( FILTER, ENTRY, "approx_candidates: enter\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> approx_candidates\n", 0, 0, 0 );
 #endif
 
 
-       idl = idl_allids( be );
+       idl = idl_allids( op->o_bd );
 
-       rc = index_param( be, ava->aa_desc, LDAP_FILTER_APPROX,
+       rc = index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX,
                &dbname, &mask, &prefix );
 
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "approx_candidates: index_param returned %d\n", rc ));
+               LDAP_LOG( FILTER, ERR, 
+                          "approx_candidates: index_param returned %d\n", rc, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= approx_candidates: index_param returned=%d\n",
@@ -542,8 +555,7 @@ approx_candidates(
        if( dbname == NULL ) {
                /* not indexed */
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "approx_candidates: not indexed\n" ));
+               LDAP_LOG( FILTER, ERR, "approx_candidates: not indexed\n", 0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                    "<= approx_candidates: not indexed\n",
@@ -574,13 +586,13 @@ approx_candidates(
                mr,
                &prefix,
                &ava->aa_value,
-               &keys );
+               &keys, op->o_tmpmemctx );
 
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
+               LDAP_LOG( FILTER, ERR, 
                           "approx_candidates: (%s%s) MR filter failed (%d)\n",
-                          dbname, LDBM_SUFFIX, rc ));
+                          dbname, LDBM_SUFFIX, rc );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= approx_candidates: (%s%s) MR filter failed (%d)\n",
@@ -592,9 +604,9 @@ approx_candidates(
 
        if( keys == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
+               LDAP_LOG( FILTER, INFO, 
                           "approx_candidates: no keys (%s%s)\n",
-                          dbname, LDBM_SUFFIX ));
+                          dbname, LDBM_SUFFIX, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= approx_candidates: no keys (%s%s)\n",
@@ -604,13 +616,13 @@ approx_candidates(
                return idl;
        }
 
-       db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
+       db = ldbm_cache_open( op->o_bd, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
        
        if ( db == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "approx_candidates db open failed (%s%s)\n",
-                          dbname, LDBM_SUFFIX ));
+               LDAP_LOG( FILTER, ERR, 
+                       "approx_candidates db open failed (%s%s)\n", 
+                       dbname, LDBM_SUFFIX, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                    "<= approx_candidates db open failed (%s%s)\n",
@@ -624,14 +636,14 @@ approx_candidates(
                ID_BLOCK *save;
                ID_BLOCK *tmp;
 
-               rc = key_read( be, db, &keys[i], &tmp );
+               rc = key_read( op->o_bd, db, &keys[i], &tmp );
 
                if( rc != LDAP_SUCCESS ) {
                        idl_free( idl );
                        idl = NULL;
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                                  "approx_candidates: key read failed (%d)\n", rc ));
+                       LDAP_LOG( FILTER, ERR, 
+                                  "approx_candidates: key read failed (%d)\n", rc, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE, "<= approx_candidates key read failed (%d)\n",
                            rc, 0, 0 );
@@ -644,8 +656,7 @@ approx_candidates(
                        idl_free( idl );
                        idl = NULL;
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
-                                  "approx_candidates: NULL\n" ));
+                       LDAP_LOG( FILTER, INFO, "approx_candidates: NULL\n", 0, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE, "<= approx_candidates NULL\n",
                            0, 0, 0 );
@@ -655,21 +666,21 @@ approx_candidates(
                }
 
                save = idl;
-               idl = idl_intersection( be, idl, tmp );
+               idl = idl_intersection( op->o_bd, idl, tmp );
                idl_free( save );
                idl_free( tmp );
 
                if( idl == NULL ) break;
        }
 
-       bvarray_free( keys );
+       ber_bvarray_free_x( keys, op->o_tmpmemctx );
 
-       ldbm_cache_close( be, db );
+       ldbm_cache_close( op->o_bd, db );
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "approx_candidates: return %ld\n",
-                  idl ? ID_BLOCK_NIDS(idl) : 0 ));
+       LDAP_LOG( FILTER, ENTRY, 
+               "approx_candidates: return %ld\n", 
+               idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= approx_candidates %ld\n",
            idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
@@ -680,7 +691,7 @@ approx_candidates(
 
 static ID_BLOCK *
 list_candidates(
-    Backend    *be,
+    Operation *op,
     Filter     *flist,
     int                ftype
 )
@@ -689,8 +700,7 @@ list_candidates(
        Filter  *f;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "list_candidates: 0x%x\n", ftype ));
+       LDAP_LOG( FILTER, ENTRY, "list_candidates: 0x%x\n", ftype, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> list_candidates 0x%x\n", ftype, 0, 0 );
 #endif
@@ -698,11 +708,10 @@ list_candidates(
 
        idl = NULL;
        for ( f = flist; f != NULL; f = f->f_next ) {
-               if ( (tmp = filter_candidates( be, f )) == NULL &&
+               if ( (tmp = filter_candidates( op, f )) == NULL &&
                    ftype == LDAP_FILTER_AND ) {
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
-                                  "list_candidates: NULL\n" ));
+                       LDAP_LOG( FILTER, INFO, "list_candidates: NULL\n", 0, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE,
                               "<= list_candidates NULL\n", 0, 0, 0 );
@@ -716,20 +725,19 @@ list_candidates(
                if ( idl == NULL ) {
                        idl = tmp;
                } else if ( ftype == LDAP_FILTER_AND ) {
-                       idl = idl_intersection( be, idl, tmp );
+                       idl = idl_intersection( op->o_bd, idl, tmp );
                        idl_free( tmp );
                        idl_free( tmp2 );
                } else {
-                       idl = idl_union( be, idl, tmp );
+                       idl = idl_union( op->o_bd, idl, tmp );
                        idl_free( tmp );
                        idl_free( tmp2 );
                }
        }
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "list_candidates: return %ld\n",
-                  idl ? ID_BLOCK_NIDS(idl) : 0 ));
+       LDAP_LOG( FILTER, ENTRY, "list_candidates: return %ld\n",
+                  idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= list_candidates %ld\n",
            idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
@@ -740,7 +748,7 @@ list_candidates(
 
 static ID_BLOCK *
 substring_candidates(
-    Backend    *be,
+    Operation *op,
     SubstringsAssertion        *sub
 )
 {
@@ -750,27 +758,26 @@ substring_candidates(
        int rc;
        char *dbname;
        slap_mask_t mask;
-       struct berval prefix = {0};
+       struct berval prefix = {0, NULL};
        struct berval *keys = NULL;
        MatchingRule *mr;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
-                  "substrings_candidates: enter\n" ));
+       LDAP_LOG( FILTER, ENTRY, "substrings_candidates: enter\n", 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "=> substrings_candidates\n", 0, 0, 0 );
 #endif
 
 
-       idl = idl_allids( be );
+       idl = idl_allids( op->o_bd );
 
-       rc = index_param( be, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
+       rc = index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
                &dbname, &mask, &prefix );
 
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "substrings_candidates: index_param returned %d\n", rc ));
+               LDAP_LOG( FILTER, ERR, 
+                          "substrings_candidates: index_param returned %d\n", rc, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= substrings_candidates: index_param returned=%d\n",
@@ -783,8 +790,7 @@ substring_candidates(
        if( dbname == NULL ) {
                /* not indexed */
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                          "substrings_candidates: not indexed\n" ));
+               LDAP_LOG( FILTER, ERR, "substrings_candidates: not indexed\n", 0, 0, 0);
 #else
                Debug( LDAP_DEBUG_ANY,
                    "<= substrings_candidates: not indexed\n",
@@ -811,13 +817,13 @@ substring_candidates(
                mr,
                &prefix,
                sub,
-               &keys );
+               &keys, op->o_tmpmemctx );
 
        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
+               LDAP_LOG( FILTER, ERR, 
                           "substrings_candidates: (%s%s) MR filter failed (%d)\n",
-                          dbname, LDBM_SUFFIX, rc ));
+                          dbname, LDBM_SUFFIX, rc );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= substrings_candidates: (%s%s) MR filter failed (%d)\n",
@@ -829,9 +835,9 @@ substring_candidates(
 
        if( keys == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
+               LDAP_LOG( FILTER, ERR, 
                           "substrings_candidates: (0x%04lx) no keys (%s%s)\n",
-                          mask, dbname, LDBM_SUFFIX ));
+                          mask, dbname, LDBM_SUFFIX );
 #else
                Debug( LDAP_DEBUG_TRACE,
                    "<= substrings_candidates: (0x%04lx) no keys (%s%s)\n",
@@ -841,13 +847,13 @@ substring_candidates(
                return idl;
        }
 
-       db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
+       db = ldbm_cache_open( op->o_bd, dbname, LDBM_SUFFIX, LDBM_WRCREAT );
        
        if ( db == NULL ) {
 #ifdef NEW_LOGGING
-               LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
+               LDAP_LOG( FILTER, ERR, 
                           "substrings_candidates: db open failed (%s%s)\n",
-                          dbname, LDBM_SUFFIX ));
+                          dbname, LDBM_SUFFIX, 0 );
 #else
                Debug( LDAP_DEBUG_ANY,
                    "<= substrings_candidates db open failed (%s%s)\n",
@@ -861,15 +867,14 @@ substring_candidates(
                ID_BLOCK *save;
                ID_BLOCK *tmp;
 
-               rc = key_read( be, db, &keys[i], &tmp );
+               rc = key_read( op->o_bd, db, &keys[i], &tmp );
 
                if( rc != LDAP_SUCCESS ) {
                        idl_free( idl );
                        idl = NULL;
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_ERR,
-                                  "substrings_candidates: key read failed (%d)\n",
-                                  rc ));
+                       LDAP_LOG( FILTER, ERR, 
+                                  "substrings_candidates: key read failed (%d)\n", rc, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE, "<= substrings_candidates key read failed (%d)\n",
                            rc, 0, 0 );
@@ -882,8 +887,7 @@ substring_candidates(
                        idl_free( idl );
                        idl = NULL;
 #ifdef NEW_LOGGING
-                       LDAP_LOG(( "filter", LDAP_LEVEL_INFO,
-                                  "substrings_candidates: NULL\n" ));
+                       LDAP_LOG( FILTER, INFO, "substrings_candidates: NULL\n", 0, 0, 0 );
 #else
                        Debug( LDAP_DEBUG_TRACE, "<= substrings_candidates NULL\n",
                            0, 0, 0 );
@@ -893,21 +897,21 @@ substring_candidates(
                }
 
                save = idl;
-               idl = idl_intersection( be, idl, tmp );
+               idl = idl_intersection( op->o_bd, idl, tmp );
                idl_free( save );
                idl_free( tmp );
 
                if( idl == NULL ) break;
        }
 
-       bvarray_free( keys );
+       ber_bvarray_free_x( keys, op->o_tmpmemctx );
 
-       ldbm_cache_close( be, db );
+       ldbm_cache_close( op->o_bd, db );
 
 #ifdef NEW_LOGGING
-       LDAP_LOG(( "filter", LDAP_LEVEL_ENTRY,
+       LDAP_LOG( FILTER, ENTRY, 
                   "substrings_candidates: return %ld\n",
-                  idl ? ID_BLOCK_NIDS(idl) : 0 ));
+                  idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
 #else
        Debug( LDAP_DEBUG_TRACE, "<= substrings_candidates %ld\n",
            idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );