]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/modify.c
rework op/rs structures to deal with opeartional attributes
[openldap] / servers / slapd / back-ldbm / modify.c
index 98dc91bb23cfffa3a199d5634f8229a7ab051809..3382356e5a7de10b596340eb320640c2f72ca263 100644 (file)
@@ -1,8 +1,17 @@
 /* modify.c - ldbm backend modify routine */
 /* $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 1998-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"
@@ -28,8 +37,7 @@ int ldbm_modify_internal(
     Entry      *e,
        const char **text,
        char *textbuf,
-       size_t textlen
-)
+       size_t textlen )
 {
        int rc = LDAP_SUCCESS;
        Modification    *mod;
@@ -38,12 +46,19 @@ int ldbm_modify_internal(
        Attribute       *ap;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG( BACK_LDBM, ENTRY,  "ldbm_modify_internal: %s\n", e->e_name.bv_val, 0, 0 );
+       LDAP_LOG( BACK_LDBM, ENTRY,
+               "ldbm_modify_internal: %s\n",
+               e->e_name.bv_val,
+               get_permissiveModify(op) ? " (permissive)" : "",
+               0 );
 #else
-       Debug(LDAP_DEBUG_TRACE, "ldbm_modify_internal: %s\n", e->e_name.bv_val, 0, 0);
+       Debug(LDAP_DEBUG_TRACE,
+               "ldbm_modify_internal: %s\n",
+               e->e_name.bv_val,
+               get_permissiveModify(op) ? " (permissive)" : "",
+               0 );
 #endif
 
-
        if ( !acl_check_modlist( op, e, modlist )) {
                return LDAP_INSUFFICIENT_ACCESS;
        }
@@ -57,13 +72,15 @@ int ldbm_modify_internal(
                switch ( mod->sm_op ) {
                case LDAP_MOD_ADD:
 #ifdef NEW_LOGGING
-                       LDAP_LOG( BACK_LDBM, DETAIL1, "ldbm_modify_internal: add\n", 0, 0, 0);
+                       LDAP_LOG( BACK_LDBM, DETAIL1,
+                               "ldbm_modify_internal: add\n", 0, 0, 0);
 #else
-                       Debug(LDAP_DEBUG_ARGS, "ldbm_modify_internal: add\n", 0, 0, 0);
+                       Debug(LDAP_DEBUG_ARGS,
+                               "ldbm_modify_internal: add\n", 0, 0, 0);
 #endif
 
                        rc = modify_add_values( e, mod, get_permissiveModify( op ),
-                                               text, textbuf, textlen );
+                               text, textbuf, textlen );
                        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
                                LDAP_LOG( BACK_LDBM, INFO, 
@@ -77,13 +94,15 @@ int ldbm_modify_internal(
 
                case LDAP_MOD_DELETE:
 #ifdef NEW_LOGGING
-                       LDAP_LOG( BACK_LDBM, DETAIL1, "ldbm_modify_internal: delete\n", 0,0,0);
+                       LDAP_LOG( BACK_LDBM, DETAIL1,
+                               "ldbm_modify_internal: delete\n", 0,0,0);
 #else
-                       Debug(LDAP_DEBUG_ARGS, "ldbm_modify_internal: delete\n", 0, 0, 0);
+                       Debug(LDAP_DEBUG_ARGS,
+                               "ldbm_modify_internal: delete\n", 0, 0, 0);
 #endif
 
                        rc = modify_delete_values( e, mod, get_permissiveModify( op ),
-                                                       text, textbuf, textlen );
+                               text, textbuf, textlen );
                        assert( rc != LDAP_TYPE_OR_VALUE_EXISTS );
                        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
@@ -98,13 +117,37 @@ int ldbm_modify_internal(
 
                case LDAP_MOD_REPLACE:
 #ifdef NEW_LOGGING
-                       LDAP_LOG( BACK_LDBM, DETAIL1, "ldbm_modify_internal:  replace\n",0,0,0);
+                       LDAP_LOG( BACK_LDBM, DETAIL1,
+                               "ldbm_modify_internal:  replace\n",0,0,0);
 #else
-                       Debug(LDAP_DEBUG_ARGS, "ldbm_modify_internal: replace\n", 0, 0, 0);
+                       Debug(LDAP_DEBUG_ARGS,
+                               "ldbm_modify_internal: replace\n", 0, 0, 0);
 #endif
 
                        rc = modify_replace_values( e, mod, get_permissiveModify( op ),
-                                                       text, textbuf, textlen );
+                               text, textbuf, textlen );
+                       if( rc != LDAP_SUCCESS ) {
+#ifdef NEW_LOGGING
+                               LDAP_LOG( BACK_LDBM, INFO, 
+                                       "ldbm_modify_internal: failed %d (%s)\n", rc, *text, 0 );
+#else
+                               Debug(LDAP_DEBUG_ARGS, "ldbm_modify_internal: %d %s\n",
+                                       rc, *text, 0);
+#endif
+                       }
+                       break;
+
+               case LDAP_MOD_INCREMENT:
+#ifdef NEW_LOGGING
+                       LDAP_LOG( BACK_LDBM, DETAIL1,
+                               "ldbm_modify_internal:  increment\n",0,0,0);
+#else
+                       Debug(LDAP_DEBUG_ARGS,
+                               "ldbm_modify_internal:  increment\n",0,0,0);
+#endif
+
+                       rc = modify_increment_values( e, mod, get_permissiveModify( op ),
+                               text, textbuf, textlen );
                        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
                                LDAP_LOG( BACK_LDBM, INFO, 
@@ -121,7 +164,8 @@ int ldbm_modify_internal(
                        LDAP_LOG( BACK_LDBM, DETAIL1, 
                                "ldbm_modify_internal: softadd\n", 0, 0, 0 );
 #else
-                       Debug(LDAP_DEBUG_ARGS, "ldbm_modify_internal: softadd\n", 0, 0, 0);
+                       Debug(LDAP_DEBUG_ARGS,
+                               "ldbm_modify_internal: softadd\n", 0, 0, 0);
 #endif
 
                        /* Avoid problems in index_add_mods()
@@ -130,7 +174,8 @@ int ldbm_modify_internal(
                        mod->sm_op = LDAP_MOD_ADD;
 
                        rc = modify_add_values( e, mod, get_permissiveModify( op ),
-                                               text, textbuf, textlen );
+                               text, textbuf, textlen );
+                       mod->sm_op = SLAP_MOD_SOFTADD;
                        if ( rc == LDAP_TYPE_OR_VALUE_EXISTS ) {
                                rc = LDAP_SUCCESS;
                        }
@@ -138,7 +183,7 @@ int ldbm_modify_internal(
                        if( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
                                LDAP_LOG( BACK_LDBM, INFO, 
-                                          "ldbm_modify_internal: failed %d (%s)\n", rc, *text, 0 );
+                                  "ldbm_modify_internal: failed %d (%s)\n", rc, *text, 0 );
 #else
                                Debug(LDAP_DEBUG_ARGS, "ldbm_modify_internal: %d %s\n",
                                        rc, *text, 0);
@@ -187,16 +232,7 @@ int ldbm_modify_internal(
        }
 
        /* check that the entry still obeys the schema */
-#ifndef LDAP_CACHING
        rc = entry_schema_check( op->o_bd, e, save_attrs, text, textbuf, textlen );
-#else /* LDAP_CACHING */
-       if ( !op->o_caching_on ) {
-               rc = entry_schema_check( op->o_bd, e, save_attrs,
-                               text, textbuf, textlen );
-       } else {
-               rc = LDAP_SUCCESS; 
-       }
-#endif /* LDAP_CACHING */
 
        if ( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
@@ -222,12 +258,8 @@ int ldbm_modify_internal(
        /* start with deleting the old index entries */
        for ( ap = save_attrs; ap != NULL; ap = ap->a_next ) {
                if ( ap->a_flags & SLAP_ATTR_IXDEL ) {
-                       rc = index_values( op->o_bd, ap->a_desc,
-#ifdef SLAP_NVALUES
+                       rc = index_values( op, ap->a_desc,
                                ap->a_nvals,
-#else
-                               ap->a_vals,
-#endif
                                e->e_id, SLAP_INDEX_DELETE_OP );
                        if ( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
@@ -236,8 +268,8 @@ int ldbm_modify_internal(
                                        0, 0, 0 );
 #else
                                Debug( LDAP_DEBUG_ANY,
-                                      "Attribute index delete failure",
-                                      0, 0, 0 );
+                                       "ldbm_modify_internal: Attribute index delete failure\n",
+                                       0, 0, 0 );
 #endif
                                goto exit;
                        }
@@ -248,12 +280,8 @@ int ldbm_modify_internal(
        /* add the new index entries */
        for ( ap = e->e_attrs; ap != NULL; ap = ap->a_next ) {
                if ( ap->a_flags & SLAP_ATTR_IXADD ) {
-                       rc = index_values( op->o_bd, ap->a_desc,
-#ifdef SLAP_NVALUES
+                       rc = index_values( op, ap->a_desc,
                                ap->a_nvals,
-#else
-                               ap->a_vals,
-#endif
                                e->e_id, SLAP_INDEX_ADD_OP );
                        if ( rc != LDAP_SUCCESS ) {
 #ifdef NEW_LOGGING
@@ -262,8 +290,8 @@ int ldbm_modify_internal(
                                        0, 0, 0 );
 #else
                                Debug( LDAP_DEBUG_ANY,
-                                      "Attribute index add failure",
-                                      0, 0, 0 );
+                                       "ldbm_modify_internal: Attribute index add failure\n",
+                                       0, 0, 0 );
 #endif
                                goto exit;
                        }
@@ -307,7 +335,10 @@ ldbm_back_modify(
        ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
 
        /* acquire and lock entry */
-       if ( (e = dn2entry_w( op->o_bd, &op->o_req_ndn, &matched )) == NULL ) {
+       e = dn2entry_w( op->o_bd, &op->o_req_ndn, &matched );
+
+       /* FIXME: dn2entry() should return non-glue entry */
+       if (( e == NULL ) || ( !manageDSAit && e && is_entry_glue( e ))) {
                if ( matched != NULL ) {
                        rs->sr_matched = ch_strdup( matched->e_dn );
                        rs->sr_ref = is_entry_referral( matched )
@@ -315,8 +346,19 @@ ldbm_back_modify(
                                : NULL;
                        cache_return_entry_r( &li->li_cache, matched );
                } else {
-                       rs->sr_ref = referral_rewrite( default_referral,
-                               NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
+                       BerVarray deref = NULL;
+                       if ( !LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
+                               syncinfo_t *si;
+                               LDAP_STAILQ_FOREACH( si, &op->o_bd->be_syncinfo, si_next ) {
+                                       struct berval tmpbv;
+                                       ber_dupbv( &tmpbv, &si->si_provideruri_bv[0] );
+                                       ber_bvarray_add( &deref, &tmpbv );
+                               }
+                       } else {
+                               deref = default_referral;
+                       }
+                       rs->sr_ref = referral_rewrite( deref, NULL, &op->o_req_dn,
+                                                       LDAP_SCOPE_DEFAULT );
                }
 
                ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
@@ -326,14 +368,12 @@ ldbm_back_modify(
                if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
                free( (char *)rs->sr_matched );
 
-               return( -1 );
+               rs->sr_ref = NULL;
+               rs->sr_matched = NULL;
+               return rs->sr_err;
        }
 
-#ifndef LDAP_CACHING
        if ( !manageDSAit && is_entry_referral( e ) )
-#else /* LDAP_CACHING */
-       if ( !op->o_caching_on && !manageDSAit && is_entry_referral( e ) )
-#endif /* LDAP_CACHING */
        {
                /* parent is a referral, don't allow add */
                /* parent is an alias, don't allow add */
@@ -352,7 +392,8 @@ ldbm_back_modify(
                send_ldap_result( op, rs );
 
                if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
-
+               rs->sr_ref = NULL;
+               rs->sr_matched = NULL;
                goto error_return;
        }
        
@@ -372,18 +413,22 @@ ldbm_back_modify(
        if ( id2entry_add( op->o_bd, e ) != 0 ) {
                send_ldap_error( op, rs, LDAP_OTHER,
                        "id2entry failure" );
+               rs->sr_err = LDAP_OTHER;
                goto error_return;
        }
 
+       rs->sr_text = NULL;
        send_ldap_error( op, rs, LDAP_SUCCESS,
                NULL );
 
        cache_return_entry_w( &li->li_cache, e );
        ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
-       return( 0 );
+
+       return LDAP_SUCCESS;
 
 error_return:;
        cache_return_entry_w( &li->li_cache, e );
        ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
-       return( -1 );
+       rs->sr_text = NULL;
+       return rs->sr_err;
 }