File 0030-CACHE-Create-timestamp-if-missing.patch of Package sssd.27548

From 0e6ea027aeadaaec8ad2117e2ef715063d98340f Mon Sep 17 00:00:00 2001
From: Tomas Halman <thalman@redhat.com>
Date: Mon, 16 Nov 2020 17:28:19 +0100
Subject: [PATCH] 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 1537abf02..7427c8b2e 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -1299,9 +1299,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.31.1

openSUSE Build Service is sponsored by