|
|
b2d430 |
From ba87a54746b417ad32362f3c6e565c7af8d21afa Mon Sep 17 00:00:00 2001
|
|
|
b2d430 |
From: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
b2d430 |
Date: Wed, 3 Aug 2016 14:23:39 +0200
|
|
|
b2d430 |
Subject: [PATCH 70/74] SYSDB: Fix setting dataExpireTimestamp if sysdb is
|
|
|
b2d430 |
supposed to set the current time
|
|
|
b2d430 |
MIME-Version: 1.0
|
|
|
b2d430 |
Content-Type: text/plain; charset=UTF-8
|
|
|
b2d430 |
Content-Transfer-Encoding: 8bit
|
|
|
b2d430 |
|
|
|
b2d430 |
sysdb is already able to retrieve the current timestamp if the caller
|
|
|
b2d430 |
doesn't specify it. However, for the timestamp cache this came too late
|
|
|
b2d430 |
and the timestamp cache used zero as the 'now' time.
|
|
|
b2d430 |
|
|
|
b2d430 |
Resolves:
|
|
|
b2d430 |
https://fedorahosted.org/sssd/ticket/3064
|
|
|
b2d430 |
|
|
|
b2d430 |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
b2d430 |
---
|
|
|
b2d430 |
src/db/sysdb_ops.c | 20 ++++----
|
|
|
b2d430 |
src/tests/cmocka/test_sysdb_ts_cache.c | 83 ++++++++++++++++++++++++++++++++++
|
|
|
b2d430 |
2 files changed, 93 insertions(+), 10 deletions(-)
|
|
|
b2d430 |
|
|
|
b2d430 |
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
|
|
|
b2d430 |
index 342e16fb20e2c418745b137162425509ca1fd0cb..67006c155098b9fde00a01d424014852c383a325 100644
|
|
|
b2d430 |
--- a/src/db/sysdb_ops.c
|
|
|
b2d430 |
+++ b/src/db/sysdb_ops.c
|
|
|
b2d430 |
@@ -2465,6 +2465,11 @@ int sysdb_store_user(struct sss_domain_info *domain,
|
|
|
b2d430 |
errno_t sret = EOK;
|
|
|
b2d430 |
bool in_transaction = false;
|
|
|
b2d430 |
|
|
|
b2d430 |
+ /* get transaction timestamp */
|
|
|
b2d430 |
+ if (now == 0) {
|
|
|
b2d430 |
+ now = time(NULL);
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
ret = sysdb_check_and_update_ts_usr(domain, name, attrs,
|
|
|
b2d430 |
cache_timeout, now);
|
|
|
b2d430 |
if (ret == EOK) {
|
|
|
b2d430 |
@@ -2508,11 +2513,6 @@ int sysdb_store_user(struct sss_domain_info *domain,
|
|
|
b2d430 |
DEBUG(SSSDBG_TRACE_LIBS, "User %s does not exist.\n", name);
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
- /* get transaction timestamp */
|
|
|
b2d430 |
- if (!now) {
|
|
|
b2d430 |
- now = time(NULL);
|
|
|
b2d430 |
- }
|
|
|
b2d430 |
-
|
|
|
b2d430 |
if (ret == ENOENT) {
|
|
|
b2d430 |
/* the user doesn't exist, turn into adding a user */
|
|
|
b2d430 |
ret = sysdb_store_new_user(domain, name, uid, gid, gecos, homedir,
|
|
|
b2d430 |
@@ -2700,6 +2700,11 @@ int sysdb_store_group(struct sss_domain_info *domain,
|
|
|
b2d430 |
errno_t sret = EOK;
|
|
|
b2d430 |
bool in_transaction = false;
|
|
|
b2d430 |
|
|
|
b2d430 |
+ /* get transaction timestamp */
|
|
|
b2d430 |
+ if (!now) {
|
|
|
b2d430 |
+ now = time(NULL);
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
ret = sysdb_check_and_update_ts_grp(domain, name, attrs,
|
|
|
b2d430 |
cache_timeout, now);
|
|
|
b2d430 |
if (ret == EOK) {
|
|
|
b2d430 |
@@ -2741,11 +2746,6 @@ int sysdb_store_group(struct sss_domain_info *domain,
|
|
|
b2d430 |
}
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
- /* get transaction timestamp */
|
|
|
b2d430 |
- if (!now) {
|
|
|
b2d430 |
- now = time(NULL);
|
|
|
b2d430 |
- }
|
|
|
b2d430 |
-
|
|
|
b2d430 |
if (new_group) {
|
|
|
b2d430 |
ret = sysdb_store_new_group(domain, name, gid, attrs,
|
|
|
b2d430 |
cache_timeout, now);
|
|
|
b2d430 |
diff --git a/src/tests/cmocka/test_sysdb_ts_cache.c b/src/tests/cmocka/test_sysdb_ts_cache.c
|
|
|
b2d430 |
index d5492299647f54e379ea3f305ccc1501c7f6c79f..aa857e7e4823d2d8ba1e1a794b3e2474876e9ab0 100644
|
|
|
b2d430 |
--- a/src/tests/cmocka/test_sysdb_ts_cache.c
|
|
|
b2d430 |
+++ b/src/tests/cmocka/test_sysdb_ts_cache.c
|
|
|
b2d430 |
@@ -1348,6 +1348,86 @@ static void test_user_byupn(void **state)
|
|
|
b2d430 |
talloc_free(res);
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
+static void test_sysdb_zero_now(void **state)
|
|
|
b2d430 |
+{
|
|
|
b2d430 |
+ int ret;
|
|
|
b2d430 |
+ struct sysdb_ts_test_ctx *test_ctx = talloc_get_type_abort(*state,
|
|
|
b2d430 |
+ struct sysdb_ts_test_ctx);
|
|
|
b2d430 |
+ struct ldb_result *res = NULL;
|
|
|
b2d430 |
+ uint64_t cache_expire_sysdb;
|
|
|
b2d430 |
+ uint64_t cache_expire_ts;
|
|
|
b2d430 |
+ struct sysdb_attrs *attrs = NULL;
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ /* Nothing must be stored in either cache at the beginning of the test */
|
|
|
b2d430 |
+ res = sysdb_getpwnam_res(test_ctx, test_ctx->tctx->dom, TEST_USER_NAME);
|
|
|
b2d430 |
+ assert_int_equal(res->count, 0);
|
|
|
b2d430 |
+ talloc_free(res);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ res = sysdb_getgrnam_res(test_ctx, test_ctx->tctx->dom, TEST_GROUP_NAME);
|
|
|
b2d430 |
+ assert_int_equal(res->count, 0);
|
|
|
b2d430 |
+ talloc_free(res);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
|
|
|
b2d430 |
+ assert_non_null(attrs);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
|
|
|
b2d430 |
+ TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
|
|
|
b2d430 |
+ "/home/"TEST_USER_NAME, "/bin/bash", NULL,
|
|
|
b2d430 |
+ attrs, NULL, TEST_CACHE_TIMEOUT,
|
|
|
b2d430 |
+ 0);
|
|
|
b2d430 |
+ talloc_zfree(attrs);
|
|
|
b2d430 |
+ assert_int_equal(ret, EOK);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
|
|
|
b2d430 |
+ assert_non_null(attrs);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ ret = sysdb_store_group(test_ctx->tctx->dom,
|
|
|
b2d430 |
+ TEST_GROUP_NAME,
|
|
|
b2d430 |
+ TEST_GROUP_GID,
|
|
|
b2d430 |
+ attrs,
|
|
|
b2d430 |
+ TEST_CACHE_TIMEOUT,
|
|
|
b2d430 |
+ 0);
|
|
|
b2d430 |
+ talloc_zfree(attrs);
|
|
|
b2d430 |
+ assert_int_equal(ret, EOK);
|
|
|
b2d430 |
+ talloc_zfree(attrs);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
|
|
|
b2d430 |
+ assert_non_null(attrs);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ ret = sysdb_store_user(test_ctx->tctx->dom, TEST_USER_NAME, NULL,
|
|
|
b2d430 |
+ TEST_USER_UID, TEST_USER_GID, TEST_USER_NAME,
|
|
|
b2d430 |
+ "/home/"TEST_USER_NAME, "/bin/bash", NULL,
|
|
|
b2d430 |
+ attrs, NULL, TEST_CACHE_TIMEOUT,
|
|
|
b2d430 |
+ 0);
|
|
|
b2d430 |
+ talloc_zfree(attrs);
|
|
|
b2d430 |
+ assert_int_equal(ret, EOK);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ attrs = create_modstamp_attrs(test_ctx, TEST_MODSTAMP_1);
|
|
|
b2d430 |
+ assert_non_null(attrs);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ ret = sysdb_store_group(test_ctx->tctx->dom,
|
|
|
b2d430 |
+ TEST_GROUP_NAME,
|
|
|
b2d430 |
+ TEST_GROUP_GID,
|
|
|
b2d430 |
+ attrs,
|
|
|
b2d430 |
+ TEST_CACHE_TIMEOUT,
|
|
|
b2d430 |
+ 0);
|
|
|
b2d430 |
+ talloc_zfree(attrs);
|
|
|
b2d430 |
+ assert_int_equal(ret, EOK);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ /* Even though we passed zero as the timestamp, the timestamp cache should
|
|
|
b2d430 |
+ * have used the current time instead
|
|
|
b2d430 |
+ */
|
|
|
b2d430 |
+ get_pw_timestamp_attrs(test_ctx, TEST_USER_NAME,
|
|
|
b2d430 |
+ &cache_expire_sysdb, &cache_expire_ts);
|
|
|
b2d430 |
+ assert_true(cache_expire_sysdb > TEST_CACHE_TIMEOUT);
|
|
|
b2d430 |
+ assert_true(cache_expire_ts > TEST_CACHE_TIMEOUT);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ get_gr_timestamp_attrs(test_ctx, TEST_GROUP_NAME,
|
|
|
b2d430 |
+ &cache_expire_sysdb, &cache_expire_ts);
|
|
|
b2d430 |
+ assert_true(cache_expire_sysdb > TEST_CACHE_TIMEOUT);
|
|
|
b2d430 |
+ assert_true(cache_expire_ts > TEST_CACHE_TIMEOUT);
|
|
|
b2d430 |
+}
|
|
|
b2d430 |
+
|
|
|
b2d430 |
int main(int argc, const char *argv[])
|
|
|
b2d430 |
{
|
|
|
b2d430 |
int rv;
|
|
|
b2d430 |
@@ -1396,6 +1476,9 @@ int main(int argc, const char *argv[])
|
|
|
b2d430 |
cmocka_unit_test_setup_teardown(test_user_byupn,
|
|
|
b2d430 |
test_sysdb_ts_setup,
|
|
|
b2d430 |
test_sysdb_ts_teardown),
|
|
|
b2d430 |
+ cmocka_unit_test_setup_teardown(test_sysdb_zero_now,
|
|
|
b2d430 |
+ test_sysdb_ts_setup,
|
|
|
b2d430 |
+ test_sysdb_ts_teardown),
|
|
|
b2d430 |
};
|
|
|
b2d430 |
|
|
|
b2d430 |
/* Set debug level to invalid value so we can deside if -d 0 was used. */
|
|
|
b2d430 |
--
|
|
|
b2d430 |
2.4.11
|
|
|
b2d430 |
|