]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/index.c
Added bdb_attribute and bdb_group ACL support routines
[openldap] / servers / slapd / back-bdb / index.c
index f549767026bdfb4f394c092e132abd3fdb5ea630..aea035d4313b07a10dd9eba8673118cc5ee4cccd 100644 (file)
@@ -15,8 +15,6 @@
 #include "slap.h"
 #include "back-bdb.h"
 
-#if BDB_INDEX
-
 static slap_mask_t index_mask(
        Backend *be,
        AttributeDescription *desc,
@@ -26,23 +24,20 @@ static slap_mask_t index_mask(
        AttributeType *at;
        slap_mask_t mask = 0;
 
-       /* we do not support indexing of binary attributes */
-       if( slap_ad_is_binary( desc ) ) return 0;
-
-       attr_mask( be->be_private, desc->ad_cname->bv_val, &mask );
+       bdb_attr_mask( be->be_private, desc->ad_cname.bv_val, &mask );
 
        if( mask ) {
-               *atname = desc->ad_cname->bv_val;
-               *dbname = desc->ad_cname->bv_val;
+               *atname = desc->ad_cname.bv_val;
+               *dbname = desc->ad_cname.bv_val;
                return mask;
        }
 
        if( slap_ad_is_lang( desc ) ) {
                /* has language tag */
-               attr_mask( be->be_private, desc->ad_type->sat_cname, &mask );
+               bdb_attr_mask( be->be_private, desc->ad_type->sat_cname, &mask );
 
                if( mask & SLAP_INDEX_AUTO_LANG ) {
-                       *atname = desc->ad_cname->bv_val;
+                       *atname = desc->ad_cname.bv_val;
                        *dbname = desc->ad_type->sat_cname;
                        return mask;
                }
@@ -55,7 +50,7 @@ static slap_mask_t index_mask(
 
        /* see if supertype defined mask for its subtypes */
        for( at = desc->ad_type; at != NULL ; at = at->sat_sup ) {
-               attr_mask( be->be_private, at->sat_cname, &mask );
+               bdb_attr_mask( be->be_private, at->sat_cname, &mask );
 
                if( mask & SLAP_INDEX_AUTO_SUBTYPES ) {
                        *atname = desc->ad_type->sat_cname;
@@ -78,11 +73,13 @@ int bdb_index_param(
        Backend *be,
        AttributeDescription *desc,
        int ftype,
-       char **dbnamep,
+       DB **dbp,
        slap_mask_t *maskp,
        struct berval **prefixp )
 {
+       int rc;
        slap_mask_t mask;
+       DB *db;
        char *dbname;
        char *atname;
 
@@ -92,6 +89,12 @@ int bdb_index_param(
                return LDAP_INAPPROPRIATE_MATCHING;
        }
 
+       rc = bdb_db_cache( be, dbname, &db );
+
+       if( rc != LDAP_SUCCESS ) {
+               return rc;
+       }
+
        switch(ftype) {
        case LDAP_FILTER_PRESENT:
                if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
@@ -124,7 +127,7 @@ int bdb_index_param(
        return LDAP_INAPPROPRIATE_MATCHING;
 
 done:
-       *dbnamep = dbname;
+       *dbp = db;
        *prefixp = ber_bvstrdup( atname );
        *maskp = mask;
        return LDAP_SUCCESS;
@@ -149,13 +152,6 @@ static int indexer(
 
        assert( mask );
 
-       rc = slap_str2ad( atname, &ad, &text );
-
-       if( rc != LDAP_SUCCESS ) return rc;
-
-       prefix.bv_val = atname;
-       prefix.bv_len = strlen( atname );
-
        rc = bdb_db_cache( be, dbname, &db );
        
        if ( rc != LDAP_SUCCESS ) {
@@ -167,13 +163,20 @@ static int indexer(
                        "<= bdb_index_read NULL (could not open %s)\n",
                        dbname, 0, 0 );
 #endif
-
-               ad_free( ad, 1 );
                return LDAP_OTHER;
        }
 
+       rc = slap_str2ad( atname, &ad, &text );
+       if( rc != LDAP_SUCCESS ) return rc;
+
+       prefix.bv_val = atname;
+       prefix.bv_len = strlen( atname );
+
        if( IS_SLAP_INDEX( mask, SLAP_INDEX_PRESENT ) ) {
-               key_change( be, db, &prefix, id, op );
+               rc = bdb_key_change( be, db, txn, &prefix, id, op );
+               if( rc ) {
+                       goto done;
+               }
        }
 
        if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) ) {
@@ -186,10 +189,15 @@ static int indexer(
 
                if( rc == LDAP_SUCCESS && keys != NULL ) {
                        for( i=0; keys[i] != NULL; i++ ) {
-                               key_change( be, db, keys[i], id, op );
+                               rc = bdb_key_change( be, db, txn, keys[i], id, op );
+                               if( rc ) {
+                                       ber_bvecfree( keys );
+                                       goto done;
+                               }
                        }
                        ber_bvecfree( keys );
                }
+               rc = LDAP_SUCCESS;
        }
 
        if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) {
@@ -202,10 +210,16 @@ static int indexer(
 
                if( rc == LDAP_SUCCESS && keys != NULL ) {
                        for( i=0; keys[i] != NULL; i++ ) {
-                               key_change( be, db, keys[i], id, op );
+                               rc = bdb_key_change( be, db, txn, keys[i], id, op );
+                               if( rc ) {
+                                       ber_bvecfree( keys );
+                                       goto done;
+                               }
                        }
                        ber_bvecfree( keys );
                }
+
+               rc = LDAP_SUCCESS;
        }
 
        if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) ) {
@@ -218,21 +232,27 @@ static int indexer(
 
                if( rc == LDAP_SUCCESS && keys != NULL ) {
                        for( i=0; keys[i] != NULL; i++ ) {
-                               key_change( be, db, keys[i], id, op );
+                               bdb_key_change( be, db, txn, keys[i], id, op );
+                               if( rc ) {
+                                       ber_bvecfree( keys );
+                                       goto done;
+                               }
                        }
                        ber_bvecfree( keys );
                }
+
+               rc = LDAP_SUCCESS;
        }
 
-       ad_free( ad, 1 );
-       return LDAP_SUCCESS;
+done:
+       return rc;
 }
 
 static int index_at_values(
        Backend *be,
        DB_TXN *txn,
        AttributeType *type,
-       const char *lang,
+       struct berval *lang,
        struct berval **vals,
        ID id,
        int op,
@@ -250,9 +270,11 @@ static int index_at_values(
                        type->sat_sup, lang,
                        vals, id, op,
                        dbnamep, &tmpmask );
+
+               if( rc ) return rc;
        }
 
-       attr_mask( be->be_private, type->sat_cname, &mask );
+       bdb_attr_mask( be->be_private, type->sat_cname, &mask );
 
        if( mask ) {
                *dbnamep = type->sat_cname;
@@ -265,17 +287,19 @@ static int index_at_values(
                        type->sat_cname,
                        vals, id, op,
                        mask );
+
+               if( rc ) return rc;
        }
 
-       if( lang ) {
+       if( lang->bv_len ) {
                char *dbname = NULL;
                size_t tlen = strlen( type->sat_cname );
-               size_t llen = strlen( lang );
+               size_t llen = lang->bv_len;
                char *lname = ch_malloc( tlen + llen + sizeof(";") );
 
-               sprintf( lname, "%s;%s", type->sat_cname, lang );
+               sprintf( lname, "%s;%s", type->sat_cname, lang->bv_val );
 
-               attr_mask( be->be_private, lname, &tmpmask );
+               bdb_attr_mask( be->be_private, lname, &tmpmask );
 
                if( tmpmask ) {
                        dbname = lname;
@@ -288,6 +312,11 @@ static int index_at_values(
                        rc = indexer( be, txn, dbname, lname,
                                vals, id, op,
                                tmpmask );
+
+                       if( rc ) {
+                               ch_free( lname );
+                               return rc;
+                       }
                }
 
                ch_free( lname );
@@ -308,13 +337,8 @@ int bdb_index_values(
        char *dbname = NULL;
        slap_mask_t mask;
 
-       if( slap_ad_is_binary( desc ) ) {
-               /* binary attributes have no index capabilities */
-               return LDAP_SUCCESS;
-       }
-
        rc = index_at_values( be, txn,
-               desc->ad_type, desc->ad_lang,
+               desc->ad_type, &desc->ad_lang,
                vals, id, op,
                &dbname, &mask );
 
@@ -327,25 +351,24 @@ bdb_index_entry(
        DB_TXN *txn,
        int op,
        Entry   *e,
-       Attribute *ap
-)
+       Attribute *ap )
 {
        int rc;
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
-               "index_entry: %s (%s)%ld\n",
+               "index_entry: %s (%s) %ld\n",
                op == SLAP_INDEX_ADD_OP ? "add" : "del",
-               e->e_dn, e->e_id ));
+               e->e_dn, (long) e->e_id ));
 #else
        Debug( LDAP_DEBUG_TRACE, "=> index_entry_%s( %ld, \"%s\" )\n",
                op == SLAP_INDEX_ADD_OP ? "add" : "del",
-               e->e_id, e->e_dn );
+               (long) e->e_id, e->e_dn );
 #endif
 
        /* add each attribute to the indexes */
        for ( ; ap != NULL; ap = ap->a_next ) {
-               rc = index_values( be, txn,
+               rc = bdb_index_values( be, txn,
                        ap->a_desc, ap->a_vals, e->e_id, op );
 
                if( rc != LDAP_SUCCESS ) {
@@ -356,7 +379,7 @@ bdb_index_entry(
                        Debug( LDAP_DEBUG_TRACE,
                                "<= index_entry_%s( %ld, \"%s\" ) success\n",
                                op == SLAP_INDEX_ADD_OP ? "add" : "del",
-                               e->e_id, e->e_dn );
+                               (long) e->e_id, e->e_dn );
 #endif
                        return rc;
                }
@@ -364,14 +387,12 @@ bdb_index_entry(
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "index", LDAP_LEVEL_ENTRY,
-                  "index_entry: success\n" ));
+               "index_entry: success\n" ));
 #else
        Debug( LDAP_DEBUG_TRACE, "<= index_entry_%s( %ld, \"%s\" ) success\n",
                op == SLAP_INDEX_ADD_OP ? "add" : "del",
-               e->e_id, e->e_dn );
+               (long) e->e_id, e->e_dn );
 #endif
 
        return LDAP_SUCCESS;
 }
-
-#endif