Blame SOURCES/0089-sysdb-invalidate-also-autofs-entries.patch

8d3578
From 58f3d546954d7c2298a0b57865f7d5ad51f69aec Mon Sep 17 00:00:00 2001
8d3578
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
8d3578
Date: Thu, 5 Sep 2019 11:32:11 +0200
8d3578
Subject: [PATCH 89/90] sysdb: invalidate also autofs entries
8d3578
MIME-Version: 1.0
8d3578
Content-Type: text/plain; charset=UTF-8
8d3578
Content-Transfer-Encoding: 8bit
8d3578
8d3578
Autofs entries got data expiration attribute so we must
8d3578
make sure it is invalidated as well.
8d3578
8d3578
Resolves:
8d3578
https://pagure.io/SSSD/sssd/issue/2607
8d3578
8d3578
Reviewed-by: Tomáš Halman <thalman@redhat.com>
8d3578
---
8d3578
 src/db/sysdb_autofs.c | 131 ++++++++++++++++++++++++++++++++++++++++++
8d3578
 src/db/sysdb_autofs.h |   4 ++
8d3578
 2 files changed, 135 insertions(+)
8d3578
8d3578
diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c
8d3578
index 11841d50d..413b00722 100644
8d3578
--- a/src/db/sysdb_autofs.c
8d3578
+++ b/src/db/sysdb_autofs.c
8d3578
@@ -530,6 +530,37 @@ done:
8d3578
     return ret;
8d3578
 }
8d3578
 
8d3578
+errno_t
8d3578
+sysdb_set_autofsentry_attr(struct sss_domain_info *domain,
8d3578
+                           const char *mapname,
8d3578
+                           const char *key,
8d3578
+                           const char *value,
8d3578
+                           struct sysdb_attrs *attrs,
8d3578
+                           int mod_op)
8d3578
+{
8d3578
+    TALLOC_CTX *tmp_ctx;
8d3578
+    struct ldb_dn *dn;
8d3578
+    errno_t ret;
8d3578
+
8d3578
+    tmp_ctx = talloc_new(NULL);
8d3578
+    if (tmp_ctx == NULL) {
8d3578
+        DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory!\n");
8d3578
+        return ENOMEM;
8d3578
+    }
8d3578
+
8d3578
+    dn = sysdb_autofsentry_dn(tmp_ctx, domain, mapname, key, value);
8d3578
+    if (dn == NULL) {
8d3578
+        ret = ENOMEM;
8d3578
+        goto done;
8d3578
+    }
8d3578
+
8d3578
+    ret = sysdb_set_entry_attr(domain->sysdb, dn, attrs, mod_op);
8d3578
+
8d3578
+done:
8d3578
+    talloc_free(tmp_ctx);
8d3578
+    return ret;
8d3578
+}
8d3578
+
8d3578
 errno_t
8d3578
 sysdb_set_autofsmap_attr(struct sss_domain_info *domain,
8d3578
                          const char *name,
8d3578
@@ -558,6 +589,99 @@ done:
8d3578
     return ret;
8d3578
 }
8d3578
 
8d3578
+errno_t
8d3578
+sysdb_invalidate_autofs_entries(struct sss_domain_info *domain,
8d3578
+                                const char *mapname)
8d3578
+{
8d3578
+    TALLOC_CTX *tmp_ctx;
8d3578
+    bool in_transaction = false;
8d3578
+    struct ldb_message **entries;
8d3578
+    struct sysdb_attrs *attrs;
8d3578
+    const char *value;
8d3578
+    const char *key;
8d3578
+    size_t count;
8d3578
+    errno_t ret;
8d3578
+    size_t i;
8d3578
+    int sret;
8d3578
+
8d3578
+    tmp_ctx = talloc_new(NULL);
8d3578
+    if (tmp_ctx == NULL) {
8d3578
+        DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory!\n");
8d3578
+        return ENOMEM;
8d3578
+    }
8d3578
+
8d3578
+    ret = sysdb_autofs_entries_by_map(tmp_ctx, domain, mapname,
8d3578
+                                      &count, &entries);
8d3578
+    if (ret == ENOENT) {
8d3578
+        ret = EOK;
8d3578
+        goto done;
8d3578
+    } else if (ret != EOK) {
8d3578
+        goto done;
8d3578
+    }
8d3578
+
8d3578
+    attrs = sysdb_new_attrs(tmp_ctx);
8d3578
+    if (attrs == NULL) {
8d3578
+        ret = ENOMEM;
8d3578
+        goto done;
8d3578
+    }
8d3578
+
8d3578
+    ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE, 1);
8d3578
+    if (ret != EOK) {
8d3578
+        goto done;
8d3578
+    }
8d3578
+
8d3578
+    ret = sysdb_transaction_start(domain->sysdb);
8d3578
+    if (ret != EOK) {
8d3578
+        DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
8d3578
+        goto done;
8d3578
+    }
8d3578
+    in_transaction = true;
8d3578
+
8d3578
+    for (i = 0; i < count; i++) {
8d3578
+        key = ldb_msg_find_attr_as_string(entries[i], SYSDB_AUTOFS_ENTRY_KEY,
8d3578
+                                          NULL);
8d3578
+        if (key == NULL) {
8d3578
+            DEBUG(SSSDBG_MINOR_FAILURE, "An entry with no key?\n");
8d3578
+            continue;
8d3578
+        }
8d3578
+
8d3578
+        value = ldb_msg_find_attr_as_string(entries[i],
8d3578
+                                            SYSDB_AUTOFS_ENTRY_VALUE,
8d3578
+                                            NULL);
8d3578
+        if (value == NULL) {
8d3578
+            DEBUG(SSSDBG_MINOR_FAILURE, "An entry with no value?\n");
8d3578
+            continue;
8d3578
+        }
8d3578
+
8d3578
+        ret = sysdb_set_autofsentry_attr(domain, mapname, key, value,
8d3578
+                                         attrs, SYSDB_MOD_REP);
8d3578
+        if (ret != EOK) {
8d3578
+            DEBUG(SSSDBG_MINOR_FAILURE, "Could not expire entry %s\n", key);
8d3578
+            continue;
8d3578
+        }
8d3578
+    }
8d3578
+
8d3578
+    ret = sysdb_transaction_commit(domain->sysdb);
8d3578
+    if (ret != EOK) {
8d3578
+        DEBUG(SSSDBG_OP_FAILURE, "Could not commit transaction\n");
8d3578
+        goto done;
8d3578
+    }
8d3578
+    in_transaction = false;
8d3578
+
8d3578
+    ret = EOK;
8d3578
+
8d3578
+done:
8d3578
+    if (in_transaction) {
8d3578
+        sret = sysdb_transaction_cancel(domain->sysdb);
8d3578
+        if (sret != EOK) {
8d3578
+            DEBUG(SSSDBG_OP_FAILURE, "Could not cancel transaction\n");
8d3578
+        }
8d3578
+    }
8d3578
+
8d3578
+    talloc_free(tmp_ctx);
8d3578
+    return ret;
8d3578
+}
8d3578
+
8d3578
 errno_t
8d3578
 sysdb_invalidate_autofs_maps(struct sss_domain_info *domain)
8d3578
 {
8d3578
@@ -634,6 +758,13 @@ sysdb_invalidate_autofs_maps(struct sss_domain_info *domain)
8d3578
             DEBUG(SSSDBG_MINOR_FAILURE, "Could not expire map %s\n", name);
8d3578
             continue;
8d3578
         }
8d3578
+
8d3578
+        ret =  sysdb_invalidate_autofs_entries(domain, name);
8d3578
+        if (ret != EOK) {
8d3578
+            DEBUG(SSSDBG_MINOR_FAILURE, "Could not expire map entries %s\n",
8d3578
+                  name);
8d3578
+            continue;
8d3578
+        }
8d3578
     }
8d3578
 
8d3578
     ret = sysdb_transaction_commit(domain->sysdb);
8d3578
diff --git a/src/db/sysdb_autofs.h b/src/db/sysdb_autofs.h
8d3578
index 3775e2a17..37489f2e8 100644
8d3578
--- a/src/db/sysdb_autofs.h
8d3578
+++ b/src/db/sysdb_autofs.h
8d3578
@@ -93,6 +93,10 @@ sysdb_set_autofsmap_attr(struct sss_domain_info *domain,
8d3578
                          struct sysdb_attrs *attrs,
8d3578
                          int mod_op);
8d3578
 
8d3578
+errno_t
8d3578
+sysdb_invalidate_autofs_entries(struct sss_domain_info *domain,
8d3578
+                                const char *mapname);
8d3578
+
8d3578
 errno_t
8d3578
 sysdb_invalidate_autofs_maps(struct sss_domain_info *domain);
8d3578
 
8d3578
-- 
8d3578
2.20.1
8d3578