]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/add.c
partially revert previous commit
[openldap] / servers / slapd / back-bdb / add.c
index b8554453d920ee40d8d42e49d28bf04202ee5cc4..8455a28bcabc1d19ad97db96c91c666aefcbec85 100644 (file)
@@ -51,9 +51,13 @@ bdb_add(Operation *op, SlapReply *rs )
 
        ctrls[num_ctrls] = 0;
 
+       /* add opattrs to shadow as well, only missing attrs will actually
+        * be added; helps compatibility with older OL versions */
+       slap_add_opattrs( op, &rs->sr_text, textbuf, textlen, 1 );
+
        /* check entry's schema */
-       rs->sr_err = entry_schema_check( op->o_bd, op->oq_add.rs_e,
-               NULL, &rs->sr_text, textbuf, textlen );
+       rs->sr_err = entry_schema_check( op, op->oq_add.rs_e, NULL,
+               get_manageDIT(op), &rs->sr_text, textbuf, textlen );
        if ( rs->sr_err != LDAP_SUCCESS ) {
                Debug( LDAP_DEBUG_TRACE,
                        LDAP_XSTRING(bdb_add) ": entry failed schema check: "
@@ -95,6 +99,10 @@ retry:       /* transaction retry */
                        rs->sr_text = "internal error";
                        goto return_results;
                }
+               if ( op->o_abandon ) {
+                       rs->sr_err = SLAPD_ABANDON;
+                       goto return_results;
+               }
                ldap_pvt_thread_yield();
                bdb_trans_backoff( ++num_retries );
        }
@@ -166,14 +174,8 @@ retry:     /* transaction retry */
                                "does not exist\n", 0, 0, 0 );
 
                        rs->sr_err = LDAP_REFERRAL;
-                       send_ldap_result( op, rs );
-
-                       ber_bvarray_free( rs->sr_ref );
-                       op->o_tmpfree( (char *)rs->sr_matched, op->o_tmpmemctx );
-                       rs->sr_ref = NULL;
-                       rs->sr_matched = NULL;
-
-                       goto done;
+                       rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
+                       goto return_results;
                }
 
                rs->sr_err = access_allowed( op, p,
@@ -187,8 +189,8 @@ retry:      /* transaction retry */
                        }
 
                        Debug( LDAP_DEBUG_TRACE,
-                               LDAP_XSTRING(bdb_add) ": no write access "
-                               "to parent\n", 0, 0, 0 );
+                               LDAP_XSTRING(bdb_add) ": no write access to parent\n",
+                               0, 0, 0 );
                        rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
                        rs->sr_text = "no write access to parent";
                        goto return_results;;
@@ -217,22 +219,18 @@ retry:    /* transaction retry */
 
                if ( is_entry_referral( p ) ) {
                        /* parent is a referral, don't allow add */
-                       rs->sr_matched = p->e_name.bv_val;
+                       rs->sr_matched = ber_strdup_x( p->e_name.bv_val,
+                               op->o_tmpmemctx );
                        rs->sr_ref = get_entry_referrals( op, p );
-
+                       bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
+                       p = NULL;
                        Debug( LDAP_DEBUG_TRACE,
                                LDAP_XSTRING(bdb_add) ": parent is referral\n",
                                0, 0, 0 );
 
                        rs->sr_err = LDAP_REFERRAL;
-                       send_ldap_result( op, rs );
-
-                       ber_bvarray_free( rs->sr_ref );
-                       bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
-                       rs->sr_ref = NULL;
-                       rs->sr_matched = NULL;
-                       p = NULL;
-                       goto done;
+                       rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
+                       goto return_results;
                }
 
 #ifdef BDB_SUBENTRIES
@@ -381,7 +379,8 @@ retry:      /* transaction retry */
                if (( rs->sr_err=TXN_ABORT( ltid )) != 0 ) {
                        rs->sr_text = "txn_abort (no-op) failed";
                } else {
-                       rs->sr_err = LDAP_NO_OPERATION;
+                       rs->sr_err = LDAP_X_NO_OPERATION;
+                       ltid = NULL;
                        goto return_results;
                }
 
@@ -389,12 +388,7 @@ retry:     /* transaction retry */
                struct berval nrdn;
                Entry *e = entry_dup( op->ora_e );
 
-               if (pdn.bv_len) {
-                       nrdn.bv_val = e->e_nname.bv_val;
-                       nrdn.bv_len = pdn.bv_val - op->ora_e->e_nname.bv_val - 1;
-               } else {
-                       nrdn = e->e_nname;
-               }
+               dnRdn( &e->e_nname, &nrdn );
 
                bdb_cache_add( bdb, ei, e, &nrdn, locker );
 
@@ -426,22 +420,23 @@ retry:    /* transaction retry */
 
 return_results:
        send_ldap_result( op, rs );
+       if ( !SLAP_SHADOW( op->o_bd ))
+               slap_graduate_commit_csn( op );
 
-       if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
-               ldap_pvt_thread_yield();
-               TXN_CHECKPOINT( bdb->bi_dbenv,
-                       bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
-       }
-
-done:
        if( ltid != NULL ) {
                TXN_ABORT( ltid );
-               op->o_private = NULL;
        }
+       op->o_private = NULL;
 
        if( postread_ctrl != NULL ) {
                slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, op->o_tmpmemctx );
                slap_sl_free( *postread_ctrl, op->o_tmpmemctx );
        }
+
+       if( rs->sr_err == LDAP_SUCCESS && bdb->bi_txn_cp ) {
+               ldap_pvt_thread_yield();
+               TXN_CHECKPOINT( bdb->bi_dbenv,
+                       bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
+       }
        return rs->sr_err;
 }