Blame SOURCES/0068-sysdb-add-expiration-time-to-autofs-entries.patch

5fca41
From ccf14f490985b96bd6f5871b55c1398024e34af0 Mon Sep 17 00:00:00 2001
5fca41
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
5fca41
Date: Tue, 13 Aug 2019 12:21:47 +0200
5fca41
Subject: [PATCH 68/90] sysdb: add expiration time to autofs entries
5fca41
MIME-Version: 1.0
5fca41
Content-Type: text/plain; charset=UTF-8
5fca41
Content-Transfer-Encoding: 8bit
5fca41
5fca41
This will be later used to expire single entries during
5fca41
`get entry by name` operation.
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                  | 13 ++++++++++++-
5fca41
 src/db/sysdb_autofs.h                  |  4 +++-
5fca41
 src/db/sysdb_upgrade.c                 |  2 +-
5fca41
 src/providers/ldap/sdap_async_autofs.c | 11 ++++++++---
5fca41
 src/tests/sysdb-tests.c                |  4 ++--
5fca41
 5 files changed, 26 insertions(+), 8 deletions(-)
5fca41
5fca41
diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c
5fca41
index 89803a778..c92a51658 100644
5fca41
--- a/src/db/sysdb_autofs.c
5fca41
+++ b/src/db/sysdb_autofs.c
5fca41
@@ -248,7 +248,9 @@ sysdb_save_autofsentry(struct sss_domain_info *domain,
5fca41
                        const char *map,
5fca41
                        const char *key,
5fca41
                        const char *value,
5fca41
-                       struct sysdb_attrs *attrs)
5fca41
+                       struct sysdb_attrs *attrs,
5fca41
+                       int cache_timeout,
5fca41
+                       time_t now)
5fca41
 {
5fca41
     errno_t ret;
5fca41
     TALLOC_CTX *tmp_ctx;
5fca41
@@ -307,6 +309,15 @@ sysdb_save_autofsentry(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
+    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
     dn = sysdb_autofsentry_dn(tmp_ctx, domain, map, key, value);
5fca41
     if (!dn) {
5fca41
         ret = ENOMEM;
5fca41
diff --git a/src/db/sysdb_autofs.h b/src/db/sysdb_autofs.h
5fca41
index d1ef8412e..a3aba726c 100644
5fca41
--- a/src/db/sysdb_autofs.h
5fca41
+++ b/src/db/sysdb_autofs.h
5fca41
@@ -58,7 +58,9 @@ sysdb_save_autofsentry(struct sss_domain_info *domain,
5fca41
                        const char *map,
5fca41
                        const char *key,
5fca41
                        const char *value,
5fca41
-                       struct sysdb_attrs *attrs);
5fca41
+                       struct sysdb_attrs *attrs,
5fca41
+                       int cache_timeout,
5fca41
+                       time_t now);
5fca41
 errno_t
5fca41
 sysdb_del_autofsentry(struct sss_domain_info *domain,
5fca41
                       const char *entry_dn);
5fca41
diff --git a/src/db/sysdb_upgrade.c b/src/db/sysdb_upgrade.c
5fca41
index f6a481147..392d04b07 100644
5fca41
--- a/src/db/sysdb_upgrade.c
5fca41
+++ b/src/db/sysdb_upgrade.c
5fca41
@@ -1255,7 +1255,7 @@ int sysdb_upgrade_11(struct sysdb_ctx *sysdb, struct sss_domain_info *domain,
5fca41
 
5fca41
                 ret = sysdb_save_autofsentry(domain,
5fca41
                                              (const char *) val->data,
5fca41
-                                             key, value, NULL);
5fca41
+                                             key, value, NULL, 0, 0);
5fca41
                 if (ret != EOK) {
5fca41
                     DEBUG(SSSDBG_OP_FAILURE,
5fca41
                           "Cannot save autofs entry [%s]-[%s] into map %s\n",
5fca41
diff --git a/src/providers/ldap/sdap_async_autofs.c b/src/providers/ldap/sdap_async_autofs.c
5fca41
index 8d1742ad1..787283872 100644
5fca41
--- a/src/providers/ldap/sdap_async_autofs.c
5fca41
+++ b/src/providers/ldap/sdap_async_autofs.c
5fca41
@@ -86,7 +86,8 @@ static errno_t
5fca41
 add_autofs_entry(struct sss_domain_info *domain,
5fca41
                  const char *map,
5fca41
                  struct sdap_options *opts,
5fca41
-                 struct sysdb_attrs *entry)
5fca41
+                 struct sysdb_attrs *entry,
5fca41
+                 time_t now)
5fca41
 {
5fca41
     const char *key;
5fca41
     const char *value;
5fca41
@@ -103,7 +104,8 @@ add_autofs_entry(struct sss_domain_info *domain,
5fca41
         return EINVAL;
5fca41
     }
5fca41
 
5fca41
-    return sysdb_save_autofsentry(domain, map, key, value, NULL);
5fca41
+    return sysdb_save_autofsentry(domain, map, key, value, NULL,
5fca41
+                                  domain->autofsmap_timeout, now);
5fca41
 }
5fca41
 
5fca41
 static errno_t
5fca41
@@ -119,11 +121,14 @@ save_autofs_entries(struct sss_domain_info *domain,
5fca41
     int hret;
5fca41
     errno_t ret;
5fca41
     struct sysdb_attrs *entry;
5fca41
+    time_t now;
5fca41
 
5fca41
     if (!add_dn_list) {
5fca41
         return EOK;
5fca41
     }
5fca41
 
5fca41
+    now = time(NULL);
5fca41
+
5fca41
     for (i=0; add_dn_list[i]; i++) {
5fca41
         key.type = HASH_KEY_STRING;
5fca41
         key.str = (char *) add_dn_list[i];
5fca41
@@ -144,7 +149,7 @@ save_autofs_entries(struct sss_domain_info *domain,
5fca41
 
5fca41
         DEBUG(SSSDBG_TRACE_FUNC,
5fca41
               "Saving autofs entry [%s]\n", add_dn_list[i]);
5fca41
-        ret = add_autofs_entry(domain, map, opts, entry);
5fca41
+        ret = add_autofs_entry(domain, map, opts, entry, now);
5fca41
         if (ret) {
5fca41
             DEBUG(SSSDBG_MINOR_FAILURE,
5fca41
                   "Cannot save entry [%s] to cache\n", add_dn_list[i]);
5fca41
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
5fca41
index 832d60466..23f2bd383 100644
5fca41
--- a/src/tests/sysdb-tests.c
5fca41
+++ b/src/tests/sysdb-tests.c
5fca41
@@ -6466,7 +6466,7 @@ START_TEST(test_autofs_store_entry_in_map)
5fca41
 
5fca41
         ret = sysdb_save_autofsentry(test_ctx->domain,
5fca41
                                      autofsmapname, autofskey,
5fca41
-                                     autofsval, NULL);
5fca41
+                                     autofsval, NULL, 0, 0);
5fca41
         fail_if(ret != EOK, "Could not save autofs entry %s", autofskey);
5fca41
     }
5fca41
 
5fca41
@@ -6521,7 +6521,7 @@ START_TEST(test_autofs_key_duplicate)
5fca41
 
5fca41
     ret = sysdb_save_autofsentry(test_ctx->domain,
5fca41
                                  autofsmapname, autofskey,
5fca41
-                                 autofsval, NULL);
5fca41
+                                 autofsval, NULL, 0, 0);
5fca41
     fail_if(ret != EOK, "Could not save autofs entry %s", autofskey);
5fca41
     talloc_free(test_ctx);
5fca41
 }
5fca41
-- 
5fca41
2.20.1
5fca41