From d01ddb06d15f336d403430021822c1385a4bc819 Mon Sep 17 00:00:00 2001 From: Pavel Březina Date: Sep 16 2019 08:33:30 +0000 Subject: sysdb: store enumeration expiration time in autofs map 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 --- diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c index f518645..dc1ea55 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 0cbe6dd..7170334 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 7872838..453e95f 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 2aad80f..fc84e09 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -6502,7 +6502,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); }