Blame 0021-NSS-Adjust-netgroup-setnetgrent-cache-lifetime-if-mi.patch

bb567c5
From d0801ecbac1300978fc864ae394e6ff43dda2781 Mon Sep 17 00:00:00 2001
bb567c5
From: Jakub Hrozek <jhrozek@redhat.com>
bb567c5
Date: Mon, 5 Mar 2018 21:00:30 +0100
bb567c5
Subject: [PATCH] NSS: Adjust netgroup setnetgrent cache lifetime if midpoint
bb567c5
 refresh is used
bb567c5
MIME-Version: 1.0
bb567c5
Content-Type: text/plain; charset=UTF-8
bb567c5
Content-Transfer-Encoding: 8bit
bb567c5
bb567c5
This is a minor regression compared to the state of the code before we
bb567c5
converted the responders to cache_req. The NSS responder keeps a has
bb567c5
table of netgroup objects in memory for either the lifetime of the
bb567c5
netgroup, or, in case midpoint refresh is used, up to the midpoint
bb567c5
refresh time. The case with the midpoint refresh was removed in the
bb567c5
cache_req enabled code, which means that even if the netgroup was
bb567c5
updated in the cache with the background refresh task, the object was
bb567c5
never read from cache, but always still returned from the in-memory
bb567c5
enumeration hash.
bb567c5
bb567c5
Resolves:
bb567c5
https://pagure.io/SSSD/sssd/issue/3550
bb567c5
bb567c5
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
bb567c5
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
bb567c5
(cherry picked from commit f22528922c065f37ca928f95fd86ed2ea79e0d51)
bb567c5
---
bb567c5
 src/responder/nss/nss_enum.c | 13 ++++++++++++-
bb567c5
 1 file changed, 12 insertions(+), 1 deletion(-)
bb567c5
bb567c5
diff --git a/src/responder/nss/nss_enum.c b/src/responder/nss/nss_enum.c
bb567c5
index da844fbce..031db9f2e 100644
bb567c5
--- a/src/responder/nss/nss_enum.c
bb567c5
+++ b/src/responder/nss/nss_enum.c
bb567c5
@@ -280,7 +280,18 @@ nss_setnetgrent_set_timeout(struct tevent_context *ev,
bb567c5
     struct timeval tv;
bb567c5
     uint32_t timeout;
bb567c5
 
bb567c5
-    timeout = enum_ctx->result[0]->domain->netgroup_timeout;
bb567c5
+    if (nss_ctx->cache_refresh_percent) {
bb567c5
+        timeout = enum_ctx->result[0]->domain->netgroup_timeout *
bb567c5
+            (nss_ctx->cache_refresh_percent / 100.0);
bb567c5
+    } else {
bb567c5
+        timeout = enum_ctx->result[0]->domain->netgroup_timeout;
bb567c5
+    }
bb567c5
+
bb567c5
+    /* In order to not trash the cache between setnetgrent()/getnetgrent()
bb567c5
+     * calls with too low timeout values, we only allow 10 seconds as
bb567c5
+     * the minimal timeout
bb567c5
+     */
bb567c5
+    if (timeout < 10) timeout = 10;
bb567c5
 
bb567c5
     tv = tevent_timeval_current_ofs(timeout, 0);
bb567c5
     te = tevent_add_timer(ev, enum_ctx, tv, nss_setnetgrent_timeout, enum_ctx);
bb567c5
-- 
bb567c5
2.14.3
bb567c5