]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/attr.c
return structuralObjectClass errors
[openldap] / servers / slapd / back-bdb / attr.c
index bad6c11d2b2b7d5518e2f396e378fc26fab8a359..15a28a91ba2bf6b9363365a168195811061c4a00 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2005 The OpenLDAP Foundation.
+ * Copyright 2000-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #include "back-bdb.h"
 #include "lutil.h"
 
-unsigned
-bdb_attr_slot( struct bdb_info *bdb, AttributeDescription *ad )
+/* Find the ad, return -1 if not found,
+ * set point for insertion if ins is non-NULL
+ */
+int
+bdb_attr_slot( struct bdb_info *bdb, AttributeDescription *ad, unsigned *ins )
 {
        unsigned base = 0, cursor = 0;
        unsigned n = bdb->bi_nattrs;
-       int val;
+       int val = 0;
        
        while ( 0 < n ) {
                int pivot = n >> 1;
@@ -46,18 +49,22 @@ bdb_attr_slot( struct bdb_info *bdb, AttributeDescription *ad )
                        return cursor;
                }
        }
-       if ( val > 0 )
-               ++cursor;
-       return cursor;
+       if ( ins ) {
+               if ( val > 0 )
+                       ++cursor;
+               *ins = cursor;
+       }
+       return -1;
 }
 
 static int
 ainfo_insert( struct bdb_info *bdb, AttrInfo *a )
 {
-       unsigned x = bdb_attr_slot( bdb, a->ai_desc );
+       unsigned x;
+       int i = bdb_attr_slot( bdb, a->ai_desc, &x );
 
        /* Is it a dup? */
-       if ( x < bdb->bi_nattrs && bdb->bi_attrs[x]->ai_desc == a->ai_desc )
+       if ( i >= 0 )
                return -1;
 
        bdb->bi_attrs = ch_realloc( bdb->bi_attrs, ( bdb->bi_nattrs+1 ) * 
@@ -75,9 +82,8 @@ bdb_attr_mask(
        struct bdb_info *bdb,
        AttributeDescription *desc )
 {
-       unsigned i = bdb_attr_slot( bdb, desc );
-       return ( i < bdb->bi_nattrs && bdb->bi_attrs[i]->ai_desc == desc ) ?
-               bdb->bi_attrs[i] : NULL;
+       int i = bdb_attr_slot( bdb, desc, NULL );
+       return i < 0 ? NULL : bdb->bi_attrs[i];
 }
 
 int
@@ -88,7 +94,7 @@ bdb_attr_index_config(
        int                     argc,
        char            **argv )
 {
-       int rc;
+       int rc = 0;
        int     i;
        slap_mask_t mask;
        char **attrs;
@@ -110,7 +116,8 @@ bdb_attr_index_config(
                        fprintf( stderr, "%s: line %d: "
                                "no indexes specified: %s\n",
                                fname, lineno, argv[1] );
-                       return LDAP_PARAM_ERROR;
+                       rc = LDAP_PARAM_ERROR;
+                       goto done;
                }
        }
 
@@ -128,7 +135,8 @@ bdb_attr_index_config(
                                fprintf( stderr, "%s: line %d: "
                                        "index type \"%s\" undefined\n",
                                        fname, lineno, indexes[i] );
-                               return LDAP_PARAM_ERROR;
+                               rc = LDAP_PARAM_ERROR;
+                               goto done;
                        }
 
                        mask |= index;
@@ -139,7 +147,8 @@ bdb_attr_index_config(
                fprintf( stderr, "%s: line %d: "
                        "no indexes selected\n",
                        fname, lineno );
-               return LDAP_PARAM_ERROR;
+               rc = LDAP_PARAM_ERROR;
+               goto done;
        }
 
        for ( i = 0; attrs[i] != NULL; i++ ) {
@@ -163,7 +172,7 @@ bdb_attr_index_config(
                                fprintf( stderr, "%s: line %d: "
                                        "index component reference\"%s\" undefined\n",
                                        fname, lineno, attrs[i] );
-                               return rc;
+                               goto done;
                        }
                        cr->cr_indexmask = mask;
                        /*
@@ -173,11 +182,6 @@ bdb_attr_index_config(
                } else {
                        cr = NULL;
                }
-#endif
-               a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
-
-#ifdef LDAP_COMP_MATCH
-               a->ai_cr = NULL;
 #endif
                ad = NULL;
                rc = slap_str2ad( attrs[i], &ad, &text );
@@ -186,14 +190,15 @@ bdb_attr_index_config(
                        fprintf( stderr, "%s: line %d: "
                                "index attribute \"%s\" undefined\n",
                                fname, lineno, attrs[i] );
-                       return rc;
+                       goto done;
                }
 
                if( slap_ad_is_binary( ad ) ) {
                        fprintf( stderr, "%s: line %d: "
                                "index of attribute \"%s\" disallowed\n",
                                fname, lineno, attrs[i] );
-                       return LDAP_UNWILLING_TO_PERFORM;
+                       rc = LDAP_UNWILLING_TO_PERFORM;
+                       goto done;
                }
 
                if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) && !(
@@ -204,7 +209,8 @@ bdb_attr_index_config(
                        fprintf( stderr, "%s: line %d: "
                                "approx index of attribute \"%s\" disallowed\n",
                                fname, lineno, attrs[i] );
-                       return LDAP_INAPPROPRIATE_MATCHING;
+                       rc = LDAP_INAPPROPRIATE_MATCHING;
+                       goto done;
                }
 
                if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) && !(
@@ -215,7 +221,8 @@ bdb_attr_index_config(
                        fprintf( stderr, "%s: line %d: "
                                "equality index of attribute \"%s\" disallowed\n",
                                fname, lineno, attrs[i] );
-                       return LDAP_INAPPROPRIATE_MATCHING;
+                       rc = LDAP_INAPPROPRIATE_MATCHING;
+                       goto done;
                }
 
                if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) && !(
@@ -226,12 +233,18 @@ bdb_attr_index_config(
                        fprintf( stderr, "%s: line %d: "
                                "substr index of attribute \"%s\" disallowed\n",
                                fname, lineno, attrs[i] );
-                       return LDAP_INAPPROPRIATE_MATCHING;
+                       rc = LDAP_INAPPROPRIATE_MATCHING;
+                       goto done;
                }
 
                Debug( LDAP_DEBUG_CONFIG, "index %s 0x%04lx\n",
                        ad->ad_cname.bv_val, mask, 0 ); 
 
+               a = (AttrInfo *) ch_malloc( sizeof(AttrInfo) );
+
+#ifdef LDAP_COMP_MATCH
+               a->ai_cr = NULL;
+#endif
                a->ai_desc = ad;
 
                if ( bdb->bi_flags & BDB_IS_OPEN ) {
@@ -254,14 +267,16 @@ bdb_attr_index_config(
                                rc = insert_component_reference( cr, &a_cr->ai_cr );
                                if ( rc != LDAP_SUCCESS) {
                                        fprintf( stderr, " error during inserting component reference in %s ", attrs[i]);
-                                       return LDAP_PARAM_ERROR;
+                                       rc = LDAP_PARAM_ERROR;
+                                       goto done;
                                }
                                continue;
                        } else {
                                rc = insert_component_reference( cr, &a->ai_cr );
                                if ( rc != LDAP_SUCCESS) {
                                        fprintf( stderr, " error during inserting component reference in %s ", attrs[i]);
-                                       return LDAP_PARAM_ERROR;
+                                       rc = LDAP_PARAM_ERROR;
+                                       goto done;
                                }
                        }
                }
@@ -279,18 +294,20 @@ bdb_attr_index_config(
                                ch_free( a );
                                continue;
                        }
-                       fprintf( stderr, "%s: line %d: duplicate index definition "
-                               "for attr \"%s\"" SLAPD_CONF_UNKNOWN_IGNORED ".\n",
+                       fprintf( stderr,
+                               "%s: line %d: duplicate index definition for attr \"%s\".\n",
                                fname, lineno, attrs[i] );
 
-                       return LDAP_PARAM_ERROR;
+                       rc = LDAP_PARAM_ERROR;
+                       goto done;
                }
        }
 
+done:
        ldap_charray_free( attrs );
        if ( indexes != NULL ) ldap_charray_free( indexes );
 
-       return LDAP_SUCCESS;
+       return rc;
 }
 
 static int
@@ -352,10 +369,10 @@ bdb_attr_index_destroy( struct bdb_info *bdb )
 
 void bdb_attr_index_free( struct bdb_info *bdb, AttributeDescription *ad )
 {
-       unsigned i;
+       int i;
 
-       i = bdb_attr_slot( bdb, ad );
-       if ( i < bdb->bi_nattrs && bdb->bi_attrs[i]->ai_desc == ad ) {
+       i = bdb_attr_slot( bdb, ad, NULL );
+       if ( i >= 0 ) {
                bdb_attr_info_free( bdb->bi_attrs[i] );
                bdb->bi_nattrs--;
                for (; i<bdb->bi_nattrs; i++)