]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/modrdn.c
Remove broken MSVC build from REL_ENG branch.
[openldap] / servers / slapd / back-bdb / modrdn.c
index 80d41518d51d9ce9c2c05540357c18aedd1fe5e4..50f0ad614326e48e2a7bf1598a14f487fc8030ac 100644 (file)
@@ -1,8 +1,17 @@
 /* modrdn.c - bdb backend modrdn 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 2000-2003 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"
@@ -92,7 +101,6 @@ retry:       /* transaction retry */
 #else
                Debug( LDAP_DEBUG_TRACE, "==>bdb_modrdn: retrying...\n", 0, 0, 0 );
 #endif
-
                pm_list = LDAP_LIST_FIRST(&op->o_pm_list);
                while ( pm_list != NULL ) {
                        LDAP_LIST_REMOVE ( pm_list, ps_link );
@@ -110,8 +118,8 @@ retry:      /* transaction retry */
                        rs->sr_text = "internal error";
                        goto return_results;
                }
-               bdb_trans_backoff( ++num_retries );
                ldap_pvt_thread_yield();
+               bdb_trans_backoff( ++num_retries );
        }
 
        /* begin transaction */
@@ -174,9 +182,19 @@ retry:     /* transaction retry */
                        e = NULL;
 
                } else {
-                       BerVarray deref = op->o_bd->syncinfo ?
-                                                         op->o_bd->syncinfo->provideruri_bv : default_referral;
-                       rs->sr_ref = referral_rewrite( deref, 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 );
                }
 
                rs->sr_err = LDAP_REFERRAL;
@@ -665,7 +683,7 @@ retry:      /* transaction retry */
        }
 
        /* Build target dn and make sure target entry doesn't exist already. */
-       if (!new_dn.bv_val) build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn ); 
+       if (!new_dn.bv_val) build_new_dn( &new_dn, new_parent_dn, &op->oq_modrdn.rs_newrdn, NULL ); 
 
        if (!new_ndn.bv_val) {
                struct berval bv = {0, NULL};
@@ -684,7 +702,7 @@ retry:      /* transaction retry */
 
        /* Shortcut the search */
        nei = neip ? neip : eip;
-       rs->sr_err = bdb_cache_find_ndn ( op, ltid, &new_ndn, &nei, locker );
+       rs->sr_err = bdb_cache_find_ndn ( op, ltid, &new_ndn, &nei );
        if ( nei ) bdb_cache_entryinfo_unlock( nei );
        switch( rs->sr_err ) {
        case DB_LOCK_DEADLOCK:
@@ -864,10 +882,12 @@ retry:    /* transaction retry */
                goto return_results;
        }
 
-       if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
+       if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop && !op->o_no_psearch ) {
+               ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
                LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
                        bdb_psearch( op, rs, ps_list, e, LDAP_PSEARCH_BY_PREMODIFY );
                }
+               ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
        }
 
        /* modify entry */
@@ -940,8 +960,9 @@ retry:      /* transaction retry */
                goto return_results;
        }
 
-       if ( !op->o_bd->syncinfo ) {
-               rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei, &ctxcsn_e, &ctxcsn_added, locker );
+       if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
+               rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei,
+                       &ctxcsn_e, &ctxcsn_added, locker );
                switch ( rc ) {
                case BDB_CSN_ABORT :
                        goto return_results;
@@ -961,22 +982,38 @@ retry:    /* transaction retry */
        } else {
                char gid[DB_XIDDATASIZE];
 
+               memset( gid, 0, sizeof(gid) );
                snprintf( gid, sizeof( gid ), "%s-%08lx-%08lx",
                        bdb_uuid.bv_val, (long) op->o_connid, (long) op->o_opid );
 
                if(( rs->sr_err=TXN_PREPARE( ltid, gid )) != 0 ) {
                        rs->sr_text = "txn_prepare failed";
                } else {
-                       struct berval ctx_nrdn;
-
                        bdb_cache_modrdn( save, &op->orr_nnewrdn, e, neip,
                                bdb->bi_dbenv, locker, &lock );
 
-                       if ( !op->o_bd->syncinfo ) {
+                       if ( LDAP_STAILQ_EMPTY( &op->o_bd->be_syncinfo )) {
                                if ( ctxcsn_added ) {
-                                       ctx_nrdn.bv_val = "cn=ldapsync";
-                                       ctx_nrdn.bv_len = strlen( ctx_nrdn.bv_val );
-                                       bdb_cache_add( bdb, suffix_ei, ctxcsn_e, &ctx_nrdn, locker );
+                                       bdb_cache_add( bdb, suffix_ei, ctxcsn_e,
+                                               (struct berval *)&slap_ldapsync_cn_bv, locker );
+                               }
+                       }
+
+                       if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
+                               /* Loop through in-scope entries for each psearch spec */
+                               ldap_pvt_thread_rdwr_rlock( &bdb->bi_pslist_rwlock );
+                               LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
+                                       bdb_psearch( op, rs, ps_list, e, LDAP_PSEARCH_BY_MODIFY );
+                               }
+                               ldap_pvt_thread_rdwr_runlock( &bdb->bi_pslist_rwlock );
+                               pm_list = LDAP_LIST_FIRST(&op->o_pm_list);
+                               while ( pm_list != NULL ) {
+                                       bdb_psearch(op, rs, pm_list->ps_op,
+                                                               e, LDAP_PSEARCH_BY_SCOPEOUT);
+                                       pm_prev = pm_list;
+                                       LDAP_LIST_REMOVE ( pm_list, ps_link );
+                                       pm_list = LDAP_LIST_NEXT ( pm_list, ps_link );
+                                       ch_free( pm_prev );
                                }
                        }
 
@@ -1019,22 +1056,6 @@ retry:   /* transaction retry */
 return_results:
        send_ldap_result( op, rs );
 
-       if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
-               /* Loop through in-scope entries for each psearch spec */
-               LDAP_LIST_FOREACH ( ps_list, &bdb->bi_psearch_list, o_ps_link ) {
-                       bdb_psearch( op, rs, ps_list, e, LDAP_PSEARCH_BY_MODIFY );
-               }
-               pm_list = LDAP_LIST_FIRST(&op->o_pm_list);
-               while ( pm_list != NULL ) {
-                       bdb_psearch(op, rs, pm_list->ps_op,
-                                               e, LDAP_PSEARCH_BY_SCOPEOUT);
-                       pm_prev = pm_list;
-                       LDAP_LIST_REMOVE ( pm_list, ps_link );
-                       pm_list = LDAP_LIST_NEXT ( pm_list, ps_link );
-                       ch_free( pm_prev );
-               }
-       }
-
        if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
                ldap_pvt_thread_yield();
                TXN_CHECKPOINT( bdb->bi_dbenv,
@@ -1056,9 +1077,15 @@ done:
                Modifications *tmp;
                for (; mod; mod=tmp ) {
                        tmp = mod->sml_next;
+                       /* slap_modrdn2mods does things one way,
+                        * slap_mods_opattrs does it differently
+                        */
+                       if ( mod->sml_op != SLAP_MOD_SOFTADD &&
+                               mod->sml_op != LDAP_MOD_DELETE ) break;
                        if ( mod->sml_nvalues ) free( mod->sml_nvalues[0].bv_val );
                        free( mod );
                }
+               slap_mods_free( mod );
        }
 
        /* LDAP v3 Support */