]> 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 271a92d40dd603f9dfd70767761f64db26063226..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:
@@ -147,20 +161,18 @@ static int indexer(
        AttributeDescription *ad,
        struct berval *atname,
        BerVarray vals,
-       BerVarray xvals,
        ID id,
        int opid,
        slap_mask_t mask )
 {
-       int rc, i, j;
+       int rc, i;
        const char *text;
        DB *db;
-       struct berval *keys, *xkeys = NULL;
-       void *mark;
+       struct berval *keys;
 
        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
@@ -175,13 +187,7 @@ static int indexer(
                return LDAP_OTHER;
        }
 
-       mark = sl_mark(op->o_tmpmemctx);
-
-       /* For a delete op, make sure we're deleting the entire
-        * attribute (xvals == NULL) before changing the presence
-        * index. xvals is only non-NULL when deleting part of an attribute.
-        */
-       if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) && xvals == NULL ) {
+       if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
                rc = bdb_key_change( op->o_bd, db, txn, &presence_key, id, opid );
                if( rc ) {
                        goto done;
@@ -197,39 +203,14 @@ static int indexer(
                        atname, vals, &keys, op->o_tmpmemctx );
 
                if( rc == LDAP_SUCCESS && keys != NULL ) {
-                       /* xvals is only provided on deletes. Generate the keys for
-                        * xvals, representing all of the keys that will exist in
-                        * the index when we're done. If we find a delete key that
-                        * is in the xkeys, nullify the delete on that key.
-                        */
-                       if( xvals ) {
-                               rc = ad->ad_type->sat_equality->smr_indexer(
-                                       LDAP_FILTER_EQUALITY, mask,
-                                       ad->ad_type->sat_syntax,
-                                       ad->ad_type->sat_equality,
-                                       atname, xvals, &xkeys,
-                                       op->o_tmpmemctx );
-
-                               for( i=0; keys[i].bv_val; i++ ) {
-                                       for( j=0; xkeys[j].bv_val != NULL; j++ ) {
-                                               if( bvmatch( &keys[i], &xkeys[j] ) ) {
-                                                       keys[i].bv_len = 0;
-                                               }
-                                       }
-                               }
-                       }
                        for( i=0; keys[i].bv_val != NULL; i++ ) {
-                               /* ignore nullified keys */
-                               if( keys[i].bv_len == 0 ) continue;
                                rc = bdb_key_change( op->o_bd, db, txn, &keys[i], id, opid );
-                               if( rc ) break;
-                       }
-                       if( xkeys ) {
-                               ber_bvarray_free_x( xkeys, op->o_tmpmemctx );
-                               xkeys = NULL;
+                               if( rc ) {
+                                       ber_bvarray_free_x( keys, op->o_tmpmemctx );
+                                       goto done;
+                               }
                        }
                        ber_bvarray_free_x( keys, op->o_tmpmemctx );
-                       if( rc ) goto done;
                }
                rc = LDAP_SUCCESS;
        }
@@ -243,44 +224,14 @@ static int indexer(
                        atname, vals, &keys, op->o_tmpmemctx );
 
                if( rc == LDAP_SUCCESS && keys != NULL ) {
-                       /* nullify duplicate keys */
-                       for( i=0; keys[i].bv_val; i++ ) {
-                               if( !keys[i].bv_len ) continue;
-                               for( j=i+1; keys[j].bv_val; j++ ) {
-                                       if( bvmatch( &keys[i], &keys[j] ) ) {
-                                               keys[j].bv_len = 0;
-                                               break;
-                                       }
-                               }
-                       }
-                       if( xvals ) {
-                               rc = ad->ad_type->sat_equality->smr_indexer(
-                                       LDAP_FILTER_APPROX, mask,
-                                       ad->ad_type->sat_syntax,
-                                       ad->ad_type->sat_approx,
-                                       atname, xvals, &xkeys,
-                                       op->o_tmpmemctx );
-
-                               for( i=0; keys[i].bv_val; i++ ) {
-                                       for( j=0; xkeys[j].bv_val != NULL; j++ ) {
-                                               if( bvmatch( &keys[i], &xkeys[j] ) ) {
-                                                       keys[i].bv_len = 0;
-                                               }
-                                       }
-                               }
-                       }
                        for( i=0; keys[i].bv_val != NULL; i++ ) {
-                               /* ignore nullified keys */
-                               if( keys[i].bv_len == 0 ) continue;
                                rc = bdb_key_change( op->o_bd, db, txn, &keys[i], id, opid );
-                               if( rc ) break;
-                       }
-                       if( xkeys ) {
-                               ber_bvarray_free_x( xkeys, op->o_tmpmemctx );
-                               xkeys = NULL;
+                               if( rc ) {
+                                       ber_bvarray_free_x( keys, op->o_tmpmemctx );
+                                       goto done;
+                               }
                        }
                        ber_bvarray_free_x( keys, op->o_tmpmemctx );
-                       if( rc ) goto done;
                }
 
                rc = LDAP_SUCCESS;
@@ -295,51 +246,20 @@ static int indexer(
                        atname, vals, &keys, op->o_tmpmemctx );
 
                if( rc == LDAP_SUCCESS && keys != NULL ) {
-                       /* nullify duplicate keys */
-                       for( i=0; keys[i].bv_val; i++ ) {
-                               if( !keys[i].bv_len ) continue;
-                               for( j=i+1; keys[j].bv_val; j++ ) {
-                                       if( bvmatch( &keys[i], &keys[j] ) ) {
-                                               keys[j].bv_len = 0;
-                                               break;
-                                       }
-                               }
-                       }
-                       if( xvals ) {
-                               rc = ad->ad_type->sat_equality->smr_indexer(
-                                       LDAP_FILTER_SUBSTRINGS, mask,
-                                       ad->ad_type->sat_syntax,
-                                       ad->ad_type->sat_substr,
-                                       atname, xvals, &xkeys,
-                                       op->o_tmpmemctx );
-
-                               for( i=0; keys[i].bv_val; i++ ) {
-                                       for( j=0; xkeys[j].bv_val != NULL; j++ ) {
-                                               if( bvmatch( &keys[i], &xkeys[j] ) ) {
-                                                       keys[i].bv_len = 0;
-                                               }
-                                       }
-                               }
-                       }
                        for( i=0; keys[i].bv_val != NULL; i++ ) {
-                               /* ignore nullified keys */
-                               if ( keys[i].bv_len == 0 ) continue;
                                bdb_key_change( op->o_bd, db, txn, &keys[i], id, opid );
-                               if( rc ) break;
-                       }
-                       if( xkeys ) {
-                               ber_bvarray_free_x( xkeys, op->o_tmpmemctx );
-                               xkeys = NULL;
+                               if( rc ) {
+                                       ber_bvarray_free_x( keys, op->o_tmpmemctx );
+                                       goto done;
+                               }
                        }
                        ber_bvarray_free_x( keys, op->o_tmpmemctx );
-                       if( rc ) goto done;
                }
 
                rc = LDAP_SUCCESS;
        }
 
 done:
-       sl_release( mark, op->o_tmpmemctx );
        return rc;
 }
 
@@ -350,7 +270,6 @@ static int index_at_values(
        AttributeType *type,
        struct berval *tags,
        BerVarray vals,
-       BerVarray xvals,
        ID id,
        int opid )
 {
@@ -361,7 +280,7 @@ static int index_at_values(
                /* recurse */
                rc = index_at_values( op, txn, NULL,
                        type->sat_sup, tags,
-                       vals, xvals, id, opid );
+                       vals, id, opid );
 
                if( rc ) return rc;
        }
@@ -374,7 +293,7 @@ static int index_at_values(
 
        if( mask ) {
                rc = indexer( op, txn, ad, &type->sat_cname,
-                       vals, xvals, id, opid,
+                       vals, id, opid,
                        mask );
 
                if( rc ) return rc;
@@ -392,7 +311,7 @@ static int index_at_values(
 
                if( mask ) {
                        rc = indexer( op, txn, desc, &desc->ad_cname,
-                               vals, xvals, id, opid,
+                               vals, id, opid,
                                mask );
 
                        if( rc ) {
@@ -409,7 +328,6 @@ int bdb_index_values(
        DB_TXN *txn,
        AttributeDescription *desc,
        BerVarray vals,
-       BerVarray xvals,
        ID id,
        int opid )
 {
@@ -417,7 +335,7 @@ int bdb_index_values(
 
        rc = index_at_values( op, txn, desc,
                desc->ad_type, &desc->ad_tags,
-               vals, xvals, id, opid );
+               vals, id, opid );
 
        return rc;
 }
@@ -444,7 +362,7 @@ bdb_index_entry(
        /* add each attribute to the indexes */
        for ( ; ap != NULL; ap = ap->a_next ) {
                rc = bdb_index_values( op, txn, ap->a_desc,
-                       ap->a_nvals, NULL, e->e_id, opid );
+                       ap->a_nvals, e->e_id, opid );
 
                if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING