Blame 0003-CONFDB-Start-a-ldb-transaction-from-sss_ldb_modify_p.patch

be32b69
From d38421b5beb91de9213203bee87a3717952f52bc Mon Sep 17 00:00:00 2001
be32b69
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
be32b69
Date: Wed, 14 Mar 2018 22:55:21 +0100
be32b69
Subject: [PATCH 03/15] CONFDB: Start a ldb transaction from
be32b69
 sss_ldb_modify_permissive()
be32b69
MIME-Version: 1.0
be32b69
Content-Type: text/plain; charset=UTF-8
be32b69
Content-Transfer-Encoding: 8bit
be32b69
be32b69
The reason why confdb_expand_app_domains() always fails is because we
be32b69
try to do a ldb_request() without starting a ldb transaction.
be32b69
be32b69
When we're dealing with ldb_modify(), ldb_add(), ldb_delete() kind of
be32b69
messages, those call ldb_autotransaction_request() which will start a
be32b69
new transaction and treat it properly when doing the ldb_request(). In
be32b69
our case that we're calling ldb_request() by our own, we must ensure
be32b69
that the transaction is started and properly deal with it._
be32b69
be32b69
It's never been noticed because in the only place the function is used
be32b69
its errors are ignored.
be32b69
be32b69
Resolves:
be32b69
https://pagure.io/SSSD/sssd/issue/3660
be32b69
be32b69
Signed-off-by: Fabiano FidĂȘncio <fidencio@redhat.com>
be32b69
be32b69
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
be32b69
---
be32b69
 src/db/sysdb_ops.c | 39 ++++++++++++++++++++++++++++++++++++++-
be32b69
 1 file changed, 38 insertions(+), 1 deletion(-)
be32b69
be32b69
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
be32b69
index 15915101e..cc86a114e 100644
be32b69
--- a/src/db/sysdb_ops.c
be32b69
+++ b/src/db/sysdb_ops.c
be32b69
@@ -66,7 +66,9 @@ int sss_ldb_modify_permissive(struct ldb_context *ldb,
be32b69
                               struct ldb_message *msg)
be32b69
 {
be32b69
     struct ldb_request *req;
be32b69
-    int ret = EOK;
be32b69
+    int ret;
be32b69
+    int cancel_ret;
be32b69
+    bool in_transaction = false;
be32b69
 
be32b69
     ret = ldb_build_mod_req(&req, ldb, ldb,
be32b69
                             msg,
be32b69
@@ -84,9 +86,44 @@ int sss_ldb_modify_permissive(struct ldb_context *ldb,
be32b69
         return ret;
be32b69
     }
be32b69
 
be32b69
+    ret = ldb_transaction_start(ldb);
be32b69
+    if (ret != LDB_SUCCESS) {
be32b69
+        DEBUG(SSSDBG_CRIT_FAILURE,
be32b69
+              "Failed to start ldb transaction [%d]: %s\n",
be32b69
+              ret, sss_strerror(ret));
be32b69
+        goto done;
be32b69
+    }
be32b69
+
be32b69
+    in_transaction = true;
be32b69
+
be32b69
     ret = ldb_request(ldb, req);
be32b69
     if (ret == LDB_SUCCESS) {
be32b69
         ret = ldb_wait(req->handle, LDB_WAIT_ALL);
be32b69
+        if (ret != LDB_SUCCESS) {
be32b69
+            goto done;
be32b69
+        }
be32b69
+    }
be32b69
+
be32b69
+    ret = ldb_transaction_commit(ldb);
be32b69
+    if (ret != LDB_SUCCESS) {
be32b69
+        DEBUG(SSSDBG_CRIT_FAILURE,
be32b69
+              "Failed to commit ldb transaction [%d]: %s\n",
be32b69
+              ret, sss_strerror(ret));
be32b69
+        goto done;
be32b69
+    }
be32b69
+
be32b69
+    in_transaction = false;
be32b69
+
be32b69
+    ret = LDB_SUCCESS;
be32b69
+
be32b69
+done:
be32b69
+    if (in_transaction) {
be32b69
+        cancel_ret = ldb_transaction_cancel(ldb);
be32b69
+        if (cancel_ret != LDB_SUCCESS) {
be32b69
+            DEBUG(SSSDBG_CRIT_FAILURE,
be32b69
+                  "Failed to cancel ldb transaction [%d]: %s\n",
be32b69
+                  cancel_ret, sss_strerror(cancel_ret));
be32b69
+        }
be32b69
     }
be32b69
 
be32b69
     talloc_free(req);
be32b69
-- 
be32b69
2.14.3
be32b69