Blame SOURCES/0071-sysdb-store-enumeration-expiration-time-in-autofs-ma.patch

5fca41
From 11ffb775d725172a4247a9826cadecb872c7d0dc Mon Sep 17 00:00:00 2001
5fca41
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
5fca41
Date: Wed, 14 Aug 2019 12:29:56 +0200
5fca41
Subject: [PATCH 71/90] sysdb: store enumeration expiration time in autofs map
5fca41
MIME-Version: 1.0
5fca41
Content-Type: text/plain; charset=UTF-8
5fca41
Content-Transfer-Encoding: 8bit
5fca41
5fca41
We need to distinguish between 'object expired' when we need
5fca41
to obtain only the map entry and 'enumeration expired' when
5fca41
we need to enumerated the map entry.
5fca41
5fca41
Resolves:
5fca41
https://pagure.io/SSSD/sssd/issue/2607
5fca41
5fca41
Reviewed-by: Tomáš Halman <thalman@redhat.com>
5fca41
---
5fca41
 src/db/sysdb_autofs.c                  | 22 ++++++++++++++++++----
5fca41
 src/db/sysdb_autofs.h                  |  3 ++-
5fca41
 src/providers/ldap/sdap_async_autofs.c |  7 ++++---
5fca41
 src/tests/sysdb-tests.c                |  2 +-
5fca41
 4 files changed, 25 insertions(+), 9 deletions(-)
5fca41
5fca41
diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c
5fca41
index f5186451e..dc1ea5586 100644
5fca41
--- a/src/db/sysdb_autofs.c
5fca41
+++ b/src/db/sysdb_autofs.c
5fca41
@@ -101,8 +101,10 @@ sysdb_save_autofsmap(struct sss_domain_info *domain,
5fca41
                      const char *autofsmapname,
5fca41
                      struct sysdb_attrs *attrs,
5fca41
                      int cache_timeout,
5fca41
-                     time_t now)
5fca41
+                     time_t now,
5fca41
+                     bool enumerated)
5fca41
 {
5fca41
+    time_t expiration = cache_timeout ? now + cache_timeout : 0;
5fca41
     errno_t ret;
5fca41
     TALLOC_CTX *tmp_ctx;
5fca41
 
5fca41
@@ -150,15 +152,22 @@ sysdb_save_autofsmap(struct sss_domain_info *domain,
5fca41
         goto done;
5fca41
     }
5fca41
 
5fca41
-    ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE,
5fca41
-                                 ((cache_timeout) ?
5fca41
-                                  (now + cache_timeout) : 0));
5fca41
+    ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE, expiration);
5fca41
     if (ret) {
5fca41
         DEBUG(SSSDBG_OP_FAILURE, "Could not set sysdb cache expire [%d]: %s\n",
5fca41
               ret, strerror(ret));
5fca41
         goto done;
5fca41
     }
5fca41
 
5fca41
+    if (enumerated) {
5fca41
+        ret = sysdb_attrs_add_time_t(attrs, SYSDB_ENUM_EXPIRE, expiration);
5fca41
+        if (ret) {
5fca41
+            DEBUG(SSSDBG_OP_FAILURE, "Could not set sysdb enum expire [%d]: %s\n",
5fca41
+                  ret, strerror(ret));
5fca41
+            goto done;
5fca41
+        }
5fca41
+    }
5fca41
+
5fca41
     ret = sysdb_store_custom(domain, name, AUTOFS_MAP_SUBDIR, attrs);
5fca41
     if (ret != EOK) {
5fca41
         DEBUG(SSSDBG_OP_FAILURE, "sysdb_store_custom failed [%d]: %s\n",
5fca41
@@ -569,6 +578,11 @@ sysdb_invalidate_autofs_maps(struct sss_domain_info *domain)
5fca41
         goto done;
5fca41
     }
5fca41
 
5fca41
+    ret = sysdb_attrs_add_time_t(sys_attrs, SYSDB_ENUM_EXPIRE, 1);
5fca41
+    if (ret != EOK) {
5fca41
+        goto done;
5fca41
+    }
5fca41
+
5fca41
     ret = sysdb_transaction_start(domain->sysdb);
5fca41
     if (ret != EOK) {
5fca41
         DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
5fca41
diff --git a/src/db/sysdb_autofs.h b/src/db/sysdb_autofs.h
5fca41
index 0cbe6ddbf..7170334c6 100644
5fca41
--- a/src/db/sysdb_autofs.h
5fca41
+++ b/src/db/sysdb_autofs.h
5fca41
@@ -41,7 +41,8 @@ sysdb_save_autofsmap(struct sss_domain_info *domain,
5fca41
                      const char *autofsmapname,
5fca41
                      struct sysdb_attrs *attrs,
5fca41
                      int cache_timeout,
5fca41
-                     time_t now);
5fca41
+                     time_t now,
5fca41
+                     bool enumerated);
5fca41
 
5fca41
 errno_t
5fca41
 sysdb_get_map_byname(TALLOC_CTX *mem_ctx,
5fca41
diff --git a/src/providers/ldap/sdap_async_autofs.c b/src/providers/ldap/sdap_async_autofs.c
5fca41
index 787283872..453e95f7b 100644
5fca41
--- a/src/providers/ldap/sdap_async_autofs.c
5fca41
+++ b/src/providers/ldap/sdap_async_autofs.c
5fca41
@@ -189,7 +189,8 @@ del_autofs_entries(struct sss_domain_info *dom,
5fca41
 static errno_t
5fca41
 save_autofs_map(struct sss_domain_info *dom,
5fca41
                 struct sdap_options *opts,
5fca41
-                struct sysdb_attrs *map)
5fca41
+                struct sysdb_attrs *map,
5fca41
+                bool enumerated)
5fca41
 {
5fca41
     const char *mapname;
5fca41
     errno_t ret;
5fca41
@@ -201,7 +202,7 @@ save_autofs_map(struct sss_domain_info *dom,
5fca41
     now = time(NULL);
5fca41
 
5fca41
     ret = sysdb_save_autofsmap(dom, mapname, mapname,
5fca41
-                               NULL, dom->autofsmap_timeout, now);
5fca41
+                               NULL, dom->autofsmap_timeout, now, enumerated);
5fca41
     if (ret != EOK) {
5fca41
         return ret;
5fca41
     }
5fca41
@@ -898,7 +899,7 @@ sdap_autofs_setautomntent_save(struct tevent_req *req)
5fca41
     in_transaction = true;
5fca41
 
5fca41
     /* Save the map itself */
5fca41
-    ret = save_autofs_map(state->dom, state->opts, state->map);
5fca41
+    ret = save_autofs_map(state->dom, state->opts, state->map, true);
5fca41
     if (ret != EOK) {
5fca41
         DEBUG(SSSDBG_OP_FAILURE,
5fca41
              "Cannot save autofs map entry [%d]: %s\n",
5fca41
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
5fca41
index 23f2bd383..108ef8943 100644
5fca41
--- a/src/tests/sysdb-tests.c
5fca41
+++ b/src/tests/sysdb-tests.c
5fca41
@@ -6374,7 +6374,7 @@ START_TEST(test_autofs_create_map)
5fca41
     fail_if(autofsmapname == NULL, "Out of memory\n");
5fca41
 
5fca41
     ret = sysdb_save_autofsmap(test_ctx->domain, autofsmapname,
5fca41
-                               autofsmapname, NULL, 0, 0);
5fca41
+                               autofsmapname, NULL, 0, 0, false);
5fca41
     fail_if(ret != EOK, "Could not store autofs map %s", autofsmapname);
5fca41
     talloc_free(test_ctx);
5fca41
 }
5fca41
-- 
5fca41
2.20.1
5fca41