From 0174b30db0670232bf126d153a9ec01e958afffe Mon Sep 17 00:00:00 2001
From: William Brown <firstyear@redhat.com>
Date: Mon, 4 Apr 2016 09:31:46 +1000
Subject: [PATCH] Ticket 48342 - Prevent transaction abort if a transaction has
 not begun

Bug Description:  Transactions may have been aborted if they had not begun yet
due to a logic issue in dna_update_config_event. Additionally, it was possible
for an operation to fail and the transaction to not be aborted, and for the
transaction to fail to start and the delete to proceed anyway!

Fix Description:  Re-arrange and correct the logic around the transaction
in dna_update_config_event. Given this code is always called during startup, we
do not have the same be-txn issues as other areas of dna. This should fix the
transaction logic.

https://fedorahosted.org/389/ticket/48342

Author: wibrown

Review by: ???
---
 ldap/servers/plugins/dna/dna.c | 44 +++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
index cac0051..2908443 100644
--- a/ldap/servers/plugins/dna/dna.c
+++ b/ldap/servers/plugins/dna/dna.c
@@ -1603,35 +1603,35 @@ dna_update_config_event(time_t event_time, void *arg)
                     slapi_pblock_set(dna_pb, SLAPI_BACKEND, be);
                     /* We need to start transaction to avoid the deadlock */
                     rc = slapi_back_transaction_begin(dna_pb);
-                    if (rc) {
-                        slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
-                                  "dna_update_config_event: failed to start transaction\n");
-                    }
-                }
+                    if (rc == 0) {
 
-                /* First delete the existing shared config entry.  This
-                 * will allow the entry to be updated for things like
-                 * port number changes, etc. */
-                slapi_delete_internal_set_pb(pb, config_entry->shared_cfg_dn,
-                                             NULL, NULL, getPluginID(), 0);
+                        /* First delete the existing shared config entry.  This
+                         * will allow the entry to be updated for things like
+                         * port number changes, etc. */
+                        slapi_delete_internal_set_pb(pb, config_entry->shared_cfg_dn,
+                                                     NULL, NULL, getPluginID(), 0);
 
-                /* We don't care about the results */
-                slapi_delete_internal_pb(pb);
+                        /* We don't care about the results */
+                        slapi_delete_internal_pb(pb);
 
-                /* Now force the entry to be recreated */
-                dna_update_shared_config(config_entry);
+                        /* Now force the entry to be recreated */
+                        rc = dna_update_shared_config(config_entry);
 
-                if (dna_pb) {
-                    if (0 == rc) {
-                        slapi_back_transaction_commit(dna_pb);
-                    } else {
-                        if (slapi_back_transaction_abort(dna_pb) != 0) {
-                            slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM, "dna_update_config_event: failed to abort transaction!\n");
+                        if (0 == rc) {
+                            slapi_back_transaction_commit(dna_pb);
+                        } else {
+                            if (slapi_back_transaction_abort(dna_pb) != 0) {
+                                slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM, "dna_update_config_event: failed to abort transaction!\n");
+                            }
                         }
+                        slapi_pblock_destroy(dna_pb);
+                        slapi_pblock_init(pb);
+                    } else {
+                        slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
+                                  "dna_update_config_event: failed to start transaction\n");
                     }
-                    slapi_pblock_destroy(dna_pb);
                 }
-                slapi_pblock_init(pb);
+
             }
 
             list = PR_NEXT_LINK(list);
-- 
2.5.5

