]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/modify.c
Modify ad_cmp() macro to support use as an ordering function.
[openldap] / servers / slapd / back-bdb / modify.c
index 6d9cc6c4be256d4f3e5ec9195e4ac4644864b4da..66df842a08a2cf8ebd0dbfdfa8fb2c96e8ded43f 100644 (file)
@@ -117,6 +117,11 @@ int bdb_modify_internal(
                        return err; 
                }
 
+               /* If objectClass was modified, reset the flags */
+               if ( mod->sm_desc == slap_schema.si_ad_objectClass ) {
+                       e->e_ocflags = 0;
+               }
+
                /* check if modified attribute was indexed */
                err = bdb_index_is_indexed( be, mod->sm_desc );
                if ( err == LDAP_SUCCESS ) {
@@ -212,6 +217,7 @@ retry:      /* transaction retry */
                        text = "internal error";
                        goto return_results;
                }
+               ldap_pvt_thread_yield();
        }
 
        if( bdb->bi_txn ) {
@@ -257,7 +263,7 @@ retry:      /* transaction retry */
        /* acquire and lock entry */
        if ( e == NULL ) {
                char* matched_dn = NULL;
-               BVarray refs;
+               BerVarray refs;
 
                if ( matched != NULL ) {
                        matched_dn = ch_strdup( matched->e_dn );
@@ -275,7 +281,7 @@ retry:      /* transaction retry */
                send_ldap_result( conn, op, rc = LDAP_REFERRAL,
                        matched_dn, NULL, refs, NULL );
 
-               bvarray_free( refs );
+               ber_bvarray_free( refs );
                free( matched_dn );
 
                return rc;
@@ -284,7 +290,7 @@ retry:      /* transaction retry */
        if ( !manageDSAit && is_entry_referral( e ) ) {
                /* parent is a referral, don't allow add */
                /* parent is an alias, don't allow add */
-               BVarray refs = get_entry_referrals( be,
+               BerVarray refs = get_entry_referrals( be,
                        conn, op, e );
 
                Debug( LDAP_DEBUG_TRACE,
@@ -294,7 +300,7 @@ retry:      /* transaction retry */
                send_ldap_result( conn, op, rc = LDAP_REFERRAL,
                        e->e_dn, NULL, refs, NULL );
 
-               bvarray_free( refs );
+               ber_bvarray_free( refs );
                goto done;
        }
        
@@ -379,7 +385,7 @@ add_values(
        char    *dn
 )
 {
-       int             i;
+       int             i, j;
        Attribute       *a;
 
        /* char *desc = mod->sm_desc->ad_cname.bv_val; */
@@ -388,16 +394,42 @@ add_values(
        a = attr_find( e->e_attrs, mod->sm_desc );
 
        /* check if the values we're adding already exist */
-       if ( a != NULL ) {
-               if( mr == NULL || !mr->smr_match ) {
+       if( mr == NULL || !mr->smr_match ) {
+               if ( a != NULL ) {
                        /* do not allow add of additional attribute
                                if no equality rule exists */
                        return LDAP_INAPPROPRIATE_MATCHING;
                }
 
                for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) {
-                       int rc;
-                       int j;
+                       /* test asserted values against existing values */
+                       if( a ) {
+                               for( j = 0; a->a_vals[j].bv_val != NULL; j++ ) {
+                                       int rc = ber_bvcmp( &mod->sm_bvalues[i],
+                                               &a->a_vals[j] );
+
+                                       if( rc == 0 ) {
+                                               /* value exists already */
+                                               return LDAP_TYPE_OR_VALUE_EXISTS;
+                                       }
+                               }
+                       }
+
+                       /* test asserted values against themselves */
+                       for( j = 0; j < i; j++ ) {
+                               int rc = ber_bvcmp( &mod->sm_bvalues[i],
+                                       &mod->sm_bvalues[j] );
+
+                               if( rc == 0 ) {
+                                       /* value exists already */
+                                       return LDAP_TYPE_OR_VALUE_EXISTS;
+                               }
+                       }
+               }
+
+       } else {
+               for ( i = 0; mod->sm_bvalues[i].bv_val != NULL; i++ ) {
+                       int rc, match;
                        const char *text = NULL;
                        struct berval asserted;
 
@@ -409,11 +441,23 @@ add_values(
 
                        if( rc != LDAP_SUCCESS ) return rc;
 
-                       for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) {
-                               int match;
+                       if( a ) {
+                               for ( j = 0; a->a_vals[j].bv_val != NULL; j++ ) {
+                                       int rc = value_match( &match, mod->sm_desc, mr,
+                                               SLAP_MR_VALUE_SYNTAX_MATCH,
+                                               &a->a_vals[j], &asserted, &text );
+
+                                       if( rc == LDAP_SUCCESS && match == 0 ) {
+                                               free( asserted.bv_val );
+                                               return LDAP_TYPE_OR_VALUE_EXISTS;
+                                       }
+                               }
+                       }
+
+                       for ( j = 0; j < i; j++ ) {
                                int rc = value_match( &match, mod->sm_desc, mr,
                                        SLAP_MR_VALUE_SYNTAX_MATCH,
-                                       &a->a_vals[j], &asserted, &text );
+                                       &mod->sm_bvalues[j], &asserted, &text );
 
                                if( rc == LDAP_SUCCESS && match == 0 ) {
                                        free( asserted.bv_val );
@@ -540,16 +584,10 @@ replace_values(
        char    *dn
 )
 {
-       int rc = attr_delete( &e->e_attrs, mod->sm_desc );
+       (void) attr_delete( &e->e_attrs, mod->sm_desc );
 
-       if( rc != LDAP_SUCCESS && rc != LDAP_NO_SUCH_ATTRIBUTE ) {
-               return rc;
-       }
-
-       if ( mod->sm_bvalues != NULL &&
-               attr_merge( e, mod->sm_desc, mod->sm_bvalues ) != 0 )
-       {
-               return LDAP_OTHER;
+       if ( mod->sm_bvalues ) {
+               return add_values( e, mod, dn );
        }
 
        return LDAP_SUCCESS;