]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/index.c
normalize authcDN (ITS#3246); don't touch databases when running slapadd in dryryn...
[openldap] / servers / slapd / back-bdb / index.c
index 25f6f0099eca691e8287372804faca5b8b30deb7..e1f09f6fdc9becf71b4a457e5fba1e38dea59e6c 100644 (file)
@@ -1,8 +1,17 @@
 /* index.c - routines for dealing with attribute indexes */
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 2000-2004 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
 
 #include "portable.h"
@@ -97,7 +106,7 @@ int bdb_index_param(
                return LDAP_INAPPROPRIATE_MATCHING;
        }
 
-       rc = bdb_db_cache( be, NULL, prefixp->bv_val, &db );
+       rc = bdb_db_cache( be, prefixp->bv_val, &db );
 
        if( rc != LDAP_SUCCESS ) {
                return rc;
@@ -112,9 +121,14 @@ int bdb_index_param(
                break;
 
        case LDAP_FILTER_APPROX:
-               if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) {
-                       goto done;
+               if ( desc->ad_type->sat_approx ) {
+                       if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) {
+                               goto done;
+                       }
+                       break;
                }
+
+               /* Use EQUALITY rule and index for approximate match */
                /* fall thru */
 
        case LDAP_FILTER_EQUALITY:
@@ -144,6 +158,7 @@ done:
 static int indexer(
        Operation *op,
        DB_TXN *txn,
+       AttributeDescription *ad,
        struct berval *atname,
        BerVarray vals,
        ID id,
@@ -153,13 +168,11 @@ static int indexer(
        int rc, i;
        const char *text;
        DB *db;
-       AttributeDescription *ad = NULL;
        struct berval *keys;
-       void *mark;
 
        assert( mask );
 
-       rc = bdb_db_cache( op->o_bd, txn, atname->bv_val, &db );
+       rc = bdb_db_cache( op->o_bd, atname->bv_val, &db );
        
        if ( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
@@ -174,11 +187,6 @@ static int indexer(
                return LDAP_OTHER;
        }
 
-       rc = slap_bv2ad( atname, &ad, &text );
-       if( rc != LDAP_SUCCESS ) return rc;
-
-       mark = sl_mark(op->o_tmpmemctx);
-
        if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
                rc = bdb_key_change( op->o_bd, db, txn, &presence_key, id, opid );
                if( rc ) {
@@ -198,7 +206,7 @@ static int indexer(
                        for( i=0; keys[i].bv_val != NULL; i++ ) {
                                rc = bdb_key_change( op->o_bd, db, txn, &keys[i], id, opid );
                                if( rc ) {
-                                       ber_bvarray_free( keys );
+                                       ber_bvarray_free_x( keys, op->o_tmpmemctx );
                                        goto done;
                                }
                        }
@@ -219,7 +227,7 @@ static int indexer(
                        for( i=0; keys[i].bv_val != NULL; i++ ) {
                                rc = bdb_key_change( op->o_bd, db, txn, &keys[i], id, opid );
                                if( rc ) {
-                                       ber_bvarray_free( keys );
+                                       ber_bvarray_free_x( keys, op->o_tmpmemctx );
                                        goto done;
                                }
                        }
@@ -241,7 +249,7 @@ static int indexer(
                        for( i=0; keys[i].bv_val != NULL; i++ ) {
                                bdb_key_change( op->o_bd, db, txn, &keys[i], id, opid );
                                if( rc ) {
-                                       ber_bvarray_free( keys );
+                                       ber_bvarray_free_x( keys, op->o_tmpmemctx );
                                        goto done;
                                }
                        }
@@ -252,13 +260,13 @@ static int indexer(
        }
 
 done:
-       sl_release( mark, op->o_tmpmemctx );
        return rc;
 }
 
 static int index_at_values(
        Operation *op,
        DB_TXN *txn,
+       AttributeDescription *ad,
        AttributeType *type,
        struct berval *tags,
        BerVarray vals,
@@ -270,7 +278,7 @@ static int index_at_values(
 
        if( type->sat_sup ) {
                /* recurse */
-               rc = index_at_values( op, txn,
+               rc = index_at_values( op, txn, NULL,
                        type->sat_sup, tags,
                        vals, id, opid );
 
@@ -280,10 +288,11 @@ static int index_at_values(
        /* If this type has no AD, we've never used it before */
        if( type->sat_ad ) {
                bdb_attr_mask( op->o_bd->be_private, type->sat_ad, &mask );
+               ad = type->sat_ad;
        }
 
        if( mask ) {
-               rc = indexer( op, txn, &type->sat_cname,
+               rc = indexer( op, txn, ad, &type->sat_cname,
                        vals, id, opid,
                        mask );
 
@@ -301,7 +310,7 @@ static int index_at_values(
                }
 
                if( mask ) {
-                       rc = indexer( op, txn, &desc->ad_cname,
+                       rc = indexer( op, txn, desc, &desc->ad_cname,
                                vals, id, opid,
                                mask );
 
@@ -324,7 +333,7 @@ int bdb_index_values(
 {
        int rc;
 
-       rc = index_at_values( op, txn,
+       rc = index_at_values( op, txn, desc,
                desc->ad_type, &desc->ad_tags,
                vals, id, opid );