]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldif/ldif.c
ITS#4384 rework entryCSN handling, retrieve from incoming request
[openldap] / servers / slapd / back-ldif / ldif.c
index cb2854f60049ff730dea8137c2ace01ffef58451..8293c52fa149481a68747cad01dc486699bfa984 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2005 The OpenLDAP Foundation.
+ * Copyright 2005-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -819,8 +819,7 @@ static int ldif_back_add(Operation *op, SlapReply *rs) {
 
 send_res:
        send_ldap_result(op, rs);
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_graduate_commit_csn( op );
+       slap_graduate_commit_csn( op );
        return 0;
 }
 
@@ -831,8 +830,7 @@ static int ldif_back_modify(Operation *op, SlapReply *rs) {
        Entry * entry = NULL;
        int spew_res;
 
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_mods_opattrs( op, &op->orm_modlist, 1 );
+       slap_mods_opattrs( op, &op->orm_modlist, 1 );
 
        ldap_pvt_thread_mutex_lock(&ni->li_mutex);
        dn2path(&op->o_req_ndn, &op->o_bd->be_nsuffix[0], &ni->li_base_path,
@@ -866,8 +864,7 @@ static int ldif_back_modify(Operation *op, SlapReply *rs) {
        rs->sr_text = NULL;
        ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
        send_ldap_result(op, rs);
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_graduate_commit_csn( op );
+       slap_graduate_commit_csn( op );
        return 0;
 }
 
@@ -876,7 +873,7 @@ static int ldif_back_delete(Operation *op, SlapReply *rs) {
        struct berval path = BER_BVNULL;
        int res = 0;
 
-       if ( !SLAP_SHADOW( op->o_bd )) {
+       if ( BER_BVISEMPTY( &op->o_csn )) {
                struct berval csn;
                char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
 
@@ -909,8 +906,7 @@ static int ldif_back_delete(Operation *op, SlapReply *rs) {
        SLAP_FREE(path.bv_val);
        ldap_pvt_thread_mutex_unlock(&ni->li_mutex);
        send_ldap_result(op, rs);
-       if ( !SLAP_SHADOW( op->o_bd ))
-               slap_graduate_commit_csn( op );
+       slap_graduate_commit_csn( op );
        return 0;
 }
 
@@ -973,70 +969,40 @@ ldif_back_modrdn(Operation *op, SlapReply *rs)
        struct berval new_dn = BER_BVNULL, new_ndn = BER_BVNULL;
        struct berval p_dn;
        Entry * entry = NULL;
-       LDAPRDN new_rdn = NULL;
-       LDAPRDN old_rdn = NULL;
-       Modifications * mods = NULL;
        int res;
 
+       slap_mods_opattrs( op, &op->orr_modlist, 1 );
+
        ldap_pvt_thread_mutex_lock( &ni->li_mutex );
        ldap_pvt_thread_mutex_lock( &entry2str_mutex );
        entry = (Entry *) get_entry( op, &ni->li_base_path );
 
        /* build the mods to the entry */
        if ( entry != NULL ) {
-               if ( ldap_bv2rdn( &op->oq_modrdn.rs_newrdn, &new_rdn,
-                       (char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP ) )
-               {
-                       rs->sr_err = LDAP_INVALID_DN_SYNTAX;
-               } else if ( op->oq_modrdn.rs_deleteoldrdn &&
-                       ldap_bv2rdn(&op->o_req_dn, &old_rdn, (char **)&rs->sr_text,
-                       LDAP_DN_FORMAT_LDAP ) )
-               {
-                       rs->sr_err = LDAP_OTHER;
+               /* build new dn, and new ndn for the entry */
+               if ( op->oq_modrdn.rs_newSup != NULL ) {
+                       /* new superior */
+                       p_dn = *op->oq_modrdn.rs_newSup;
                } else {
-                       /* got both rdns successfully, ready to build mods */
-                       if ( slap_modrdn2mods( op, rs, entry, old_rdn, new_rdn, &mods )
-                               != LDAP_SUCCESS )
-                       {
-                               rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
-                       } else {
-                               /* built mods successfully */
-
-                               /* build new dn, and new ndn for the entry */
-                               if ( op->oq_modrdn.rs_newSup != NULL ) {
-                                       /* new superior */
-                                       p_dn = *op->oq_modrdn.rs_newSup;
-                               } else {
-                                       p_dn = slap_empty_bv;
-                               }
-                               dnParent( &entry->e_name, &p_dn );
-                               build_new_dn( &new_dn, &p_dn, &op->oq_modrdn.rs_newrdn, NULL ); 
-                               dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn, NULL );
-                               ber_memfree_x( entry->e_name.bv_val, NULL );
-                               ber_memfree_x( entry->e_nname.bv_val, NULL );
-                               entry->e_name = new_dn;
-                               entry->e_nname = new_ndn;
-
-                               /* perform the modifications */
-                               res = apply_modify_to_entry( entry, mods, op, rs );
-                               slap_modrdn2mods_free( mods );
-                               if ( res == LDAP_SUCCESS ) {
-                                       rs->sr_err = move_entry( entry, &op->o_req_ndn,
-                                                               &new_ndn,
-                                                               &op->o_bd->be_nsuffix[0],
-                                                               &ni->li_base_path );
-                               } else {
-                                       rs->sr_err = res;
-                               }
-                       }
-               }
-
-               if ( new_rdn != NULL ) {
-                       ldap_rdnfree( new_rdn );
+                       p_dn = slap_empty_bv;
                }
-
-               if ( old_rdn != NULL ) {
-                       ldap_rdnfree( old_rdn );
+               dnParent( &entry->e_name, &p_dn );
+               build_new_dn( &new_dn, &p_dn, &op->oq_modrdn.rs_newrdn, NULL ); 
+               dnNormalize( 0, NULL, NULL, &new_dn, &new_ndn, NULL );
+               ber_memfree_x( entry->e_name.bv_val, NULL );
+               ber_memfree_x( entry->e_nname.bv_val, NULL );
+               entry->e_name = new_dn;
+               entry->e_nname = new_ndn;
+
+               /* perform the modifications */
+               res = apply_modify_to_entry( entry, op->orr_modlist, op, rs );
+               if ( res == LDAP_SUCCESS ) {
+                       rs->sr_err = move_entry( entry, &op->o_req_ndn,
+                                               &new_ndn,
+                                               &op->o_bd->be_nsuffix[0],
+                                               &ni->li_base_path );
+               } else {
+                       rs->sr_err = res;
                }
        } else {
                /* entry was null */
@@ -1050,6 +1016,7 @@ ldif_back_modrdn(Operation *op, SlapReply *rs)
        ldap_pvt_thread_mutex_unlock( &ni->li_mutex );
        ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
        send_ldap_result( op, rs );
+       slap_graduate_commit_csn( op );
        return 0;
 }