]> git.sur5r.net Git - openldap/commitdiff
ITS#8360 fix ad info after failed txn
authorHoward Chu <hyc@openldap.org>
Tue, 26 Jan 2016 13:28:17 +0000 (13:28 +0000)
committerHoward Chu <hyc@openldap.org>
Tue, 26 Jan 2016 13:33:24 +0000 (13:33 +0000)
If an add or modify op referenced a previously unused attrtype,
the mi_ads/mi_numads would be incremented to include it. If the
op fails to commit, these additions must also be reverted.

servers/slapd/back-mdb/add.c
servers/slapd/back-mdb/modify.c
servers/slapd/back-mdb/tools.c

index 0f5480d86bd859706da9e48ba612056eb92eccad..afc6ba00a4ff976f6d4cfd75e09566194110bbcc 100644 (file)
@@ -37,6 +37,7 @@ mdb_add(Operation *op, SlapReply *rs )
        ID eid, pid = 0;
        mdb_op_info opinfo = {{{ 0 }}}, *moi = &opinfo;
        int subentry;
+       int numads = mdb->mi_numads;
 
        int             success;
 
@@ -368,6 +369,7 @@ mdb_add(Operation *op, SlapReply *rs )
                LDAP_SLIST_REMOVE( &op->o_extra, &opinfo.moi_oe, OpExtra, oe_next );
                opinfo.moi_oe.oe_key = NULL;
                if ( op->o_noop ) {
+                       mdb->mi_numads = numads;
                        mdb_txn_abort( txn );
                        rs->sr_err = LDAP_X_NO_OPERATION;
                        txn = NULL;
@@ -377,6 +379,7 @@ mdb_add(Operation *op, SlapReply *rs )
                rs->sr_err = mdb_txn_commit( txn );
                txn = NULL;
                if ( rs->sr_err != 0 ) {
+                       mdb->mi_numads = numads;
                        rs->sr_text = "txn_commit failed";
                        Debug( LDAP_DEBUG_ANY,
                                LDAP_XSTRING(mdb_add) ": %s : %s (%d)\n",
@@ -400,6 +403,7 @@ return_results:
 
        if( moi == &opinfo ) {
                if( txn != NULL ) {
+                       mdb->mi_numads = numads;
                        mdb_txn_abort( txn );
                }
                if ( opinfo.moi_oe.oe_key ) {
index 35682cefe8845fc70feb065fac23c440b95be3c5..6e2c3df3501234bff3059aa8725e3f4aed5b44f3 100644 (file)
@@ -458,6 +458,7 @@ mdb_modify( Operation *op, SlapReply *rs )
        LDAPControl **postread_ctrl = NULL;
        LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
        int num_ctrls = 0;
+       int numads = mdb->mi_numads;
 
        Debug( LDAP_DEBUG_ARGS, LDAP_XSTRING(mdb_modify) ": %s\n",
                op->o_req_dn.bv_val, 0, 0 );
@@ -635,12 +636,15 @@ mdb_modify( Operation *op, SlapReply *rs )
                LDAP_SLIST_REMOVE( &op->o_extra, &opinfo.moi_oe, OpExtra, oe_next );
                opinfo.moi_oe.oe_key = NULL;
                if( op->o_noop ) {
+                       mdb->mi_numads = numads;
                        mdb_txn_abort( txn );
                        rs->sr_err = LDAP_X_NO_OPERATION;
                        txn = NULL;
                        goto return_results;
                } else {
                        rs->sr_err = mdb_txn_commit( txn );
+                       if ( rs->sr_err )
+                               mdb->mi_numads = numads;
                        txn = NULL;
                }
        }
@@ -683,6 +687,7 @@ done:
 
        if( moi == &opinfo ) {
                if( txn != NULL ) {
+                       mdb->mi_numads = numads;
                        mdb_txn_abort( txn );
                }
                if ( opinfo.moi_oe.oe_key ) {
index c805444063c56a9d95e16cf6576050b403765137..e63b6ad64ff3dbf56b91ff7654b41a5aebf95ed8 100644 (file)
@@ -745,6 +745,7 @@ done:
                        mdb_tool_txn = NULL;
                        idcursor = NULL;
                        if( rc != 0 ) {
+                               mdb->mi_numads = 0;
                                snprintf( text->bv_val, text->bv_len,
                                                "txn_commit failed: %s (%d)",
                                                mdb_strerror(rc), rc );
@@ -1015,6 +1016,7 @@ done:
        if( rc == 0 ) {
                rc = mdb_txn_commit( mdb_tool_txn );
                if( rc != 0 ) {
+                       mdb->mi_numads = 0;
                        snprintf( text->bv_val, text->bv_len,
                                        "txn_commit failed: %s (%d)",
                                        mdb_strerror(rc), rc );