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