Blob Blame History Raw
From ca8cdbde6285d14181372f1ce8e5f6faf72e1d80 Mon Sep 17 00:00:00 2001
From: Tomas Halman <thalman@redhat.com>
Date: Mon, 16 Nov 2020 17:28:19 +0100
Subject: [PATCH 59/60] CACHE: Create timestamp if missing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In some cases, object is stored in cache but the corresponding
record in timestamp cache is missing (for example when timestamp
cache file is deleted). The timestamp is never created in such
case.

With this patch we create new timestamp object if update doesn't
work for this particular reason (missing object).

Resolves: https://github.com/SSSD/sssd/issues/5121

Reviewed-by: Pavel Březina <pbrezina@redhat.com>
(cherry picked from commit 37761b42f570e9019f9dd850912a29385e80a14c)
---
 src/db/sysdb_ops.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index d4ad69e39..0e0a95961 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -1371,9 +1371,17 @@ int sysdb_set_entry_attr(struct sysdb_ctx *sysdb,
 
     if (ret == EOK && is_ts_ldb_dn(entry_dn)) {
         tret = sysdb_set_ts_entry_attr(sysdb, entry_dn, attrs, mod_op);
+        if (tret == ENOENT && mod_op == SYSDB_MOD_REP) {
+            /* Update failed because TS does non exist. Create missing TS */
+            tret = sysdb_set_ts_entry_attr(sysdb, entry_dn, attrs,
+                                           SYSDB_MOD_ADD);
+            DEBUG(SSSDBG_TRACE_FUNC,
+                  "The TS value for %s does not exist, trying to create it\n",
+                  ldb_dn_get_linearized(entry_dn));
+        }
         if (tret != EOK) {
             DEBUG(SSSDBG_MINOR_FAILURE,
-                "Cannot set ts attrs for %s\n", ldb_dn_get_linearized(entry_dn));
+                "Cannot set TS attrs for %s\n", ldb_dn_get_linearized(entry_dn));
             /* Not fatal */
         } else {
             state_mask |= SSS_SYSDB_TS_CACHE;
-- 
2.21.3