>From 4709a6fdef738d7842a85c4b5a643ffc593eaed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20B=C5=99ezina?= Date: Mon, 19 Sep 2011 12:53:37 +0200 Subject: [PATCH] SysDB lastUpdate can be passed in https://fedorahosted.org/sssd/ticket/836 --- src/db/sysdb.h | 21 +++++++--- src/db/sysdb_ops.c | 59 ++++++++++++++++------------ src/providers/ldap/sdap_async_groups.c | 8 ++-- src/providers/ldap/sdap_async_initgroups.c | 2 +- src/providers/ldap/sdap_async_netgroups.c | 2 +- src/providers/ldap/sdap_async_users.c | 2 +- src/providers/proxy/proxy_id.c | 21 +++++++--- src/providers/proxy/proxy_netgroup.c | 2 +- src/tests/sysdb-tests.c | 22 +++++----- src/tools/sss_sync_ops.c | 4 +- 10 files changed, 83 insertions(+), 60 deletions(-) diff --git a/src/db/sysdb.h b/src/db/sysdb.h index ee1c868..7ec5ed9 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -468,11 +468,13 @@ int sysdb_add_user(struct sysdb_ctx *sysdb, const char *homedir, const char *shell, struct sysdb_attrs *attrs, - int cache_timeout); + int cache_timeout, + time_t now); int sysdb_add_fake_user(struct sysdb_ctx *sysdb, const char *name, - const char *original_dn); + const char *original_dn, + time_t now); /* Add group (only basic attrs and w/o checks) */ int sysdb_add_basic_group(struct sysdb_ctx *sysdb, @@ -482,12 +484,14 @@ int sysdb_add_basic_group(struct sysdb_ctx *sysdb, int sysdb_add_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid, struct sysdb_attrs *attrs, - int cache_timeout); + int cache_timeout, + time_t now); int sysdb_add_incomplete_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid, - const char *original_dn, bool posix); + const char *original_dn, bool posix, + time_t now); /* Add netgroup (only basic attrs and w/o checks) */ int sysdb_add_basic_netgroup(struct sysdb_ctx *sysdb, @@ -497,7 +501,8 @@ int sysdb_add_netgroup(struct sysdb_ctx *sysdb, const char *name, const char *description, struct sysdb_attrs *attrs, - int cache_timeout); + int cache_timeout, + time_t now); /* mod_op must be either LDB_FLAG_MOD_ADD or LDB_FLAG_MOD_DELETE */ int sysdb_mod_group_member(struct sysdb_ctx *sysdb, @@ -514,13 +519,15 @@ int sysdb_store_user(struct sysdb_ctx *sysdb, const char *shell, struct sysdb_attrs *attrs, char **remove_attrs, - uint64_t cache_timeout); + uint64_t cache_timeout, + time_t now); int sysdb_store_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid, struct sysdb_attrs *attrs, - uint64_t cache_timeout); + uint64_t cache_timeout, + time_t now); enum sysdb_member_type { SYSDB_MEMBER_USER, diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c index ee58342..cfe23db 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -811,13 +811,13 @@ int sysdb_add_user(struct sysdb_ctx *sysdb, const char *homedir, const char *shell, struct sysdb_attrs *attrs, - int cache_timeout) + int cache_timeout, + time_t now) { TALLOC_CTX *tmp_ctx; struct ldb_message *msg; struct sysdb_attrs *id_attrs; uint32_t id; - time_t now; int ret; struct sss_domain_info *domain = sysdb->domain; @@ -913,7 +913,8 @@ int sysdb_add_user(struct sysdb_ctx *sysdb, } } - now = time(NULL); + if (!now) + now = time(NULL); ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now); if (ret) goto done; @@ -939,11 +940,11 @@ done: int sysdb_add_fake_user(struct sysdb_ctx *sysdb, const char *name, - const char *original_dn) + const char *original_dn, + time_t now) { TALLOC_CTX *tmp_ctx; struct ldb_message *msg; - time_t now; int ret; tmp_ctx = talloc_new(NULL); @@ -968,7 +969,8 @@ int sysdb_add_fake_user(struct sysdb_ctx *sysdb, ret = add_string(msg, LDB_FLAG_MOD_ADD, SYSDB_NAME, name); if (ret) goto done; - now = time(NULL); + if (!now) + now = time(NULL); ret = add_ulong(msg, LDB_FLAG_MOD_ADD, SYSDB_CREATE_TIME, (unsigned long) now); @@ -1061,12 +1063,12 @@ done: int sysdb_add_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid, struct sysdb_attrs *attrs, - int cache_timeout) + int cache_timeout, + time_t now) { TALLOC_CTX *tmp_ctx; struct ldb_message *msg; uint32_t id; - time_t now; int ret; bool posix; @@ -1144,7 +1146,8 @@ int sysdb_add_group(struct sysdb_ctx *sysdb, if (ret) goto done; } - now = time(NULL); + if (!now) + now = time(NULL); ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now); if (ret) goto done; @@ -1172,10 +1175,10 @@ int sysdb_add_incomplete_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid, const char *original_dn, - bool posix) + bool posix, + time_t now) { TALLOC_CTX *tmp_ctx; - time_t now; int ret; struct sysdb_attrs *attrs; @@ -1194,7 +1197,8 @@ int sysdb_add_incomplete_group(struct sysdb_ctx *sysdb, goto done; } - now = time(NULL); + if (!now) + now = time(NULL); ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now); if (ret) goto done; @@ -1320,10 +1324,10 @@ int sysdb_add_netgroup(struct sysdb_ctx *sysdb, const char *name, const char *description, struct sysdb_attrs *attrs, - int cache_timeout) + int cache_timeout, + time_t now) { TALLOC_CTX *tmp_ctx; - time_t now; int ret; tmp_ctx = talloc_new(NULL); @@ -1350,7 +1354,8 @@ int sysdb_add_netgroup(struct sysdb_ctx *sysdb, } } - now = time(NULL); + if (!now) + now = time(NULL); ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now); if (ret) goto done; @@ -1390,11 +1395,11 @@ int sysdb_store_user(struct sysdb_ctx *sysdb, const char *shell, struct sysdb_attrs *attrs, char **remove_attrs, - uint64_t cache_timeout) + uint64_t cache_timeout, + time_t now) { TALLOC_CTX *tmp_ctx; struct ldb_message *msg; - time_t now; int ret; errno_t sret = EOK; bool in_transaction = false; @@ -1428,10 +1433,14 @@ int sysdb_store_user(struct sysdb_ctx *sysdb, goto done; } + /* get transaction timestamp */ + if (!now) + now = time(NULL); + if (ret == ENOENT) { /* users doesn't exist, turn into adding a user */ ret = sysdb_add_user(sysdb, name, uid, gid, - gecos, homedir, shell, attrs, cache_timeout); + gecos, homedir, shell, attrs, cache_timeout, now); goto done; } @@ -1466,8 +1475,6 @@ int sysdb_store_user(struct sysdb_ctx *sysdb, if (ret) goto done; } - now = time(NULL); - ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now); if (ret) goto done; @@ -1519,14 +1526,14 @@ int sysdb_store_group(struct sysdb_ctx *sysdb, const char *name, gid_t gid, struct sysdb_attrs *attrs, - uint64_t cache_timeout) + uint64_t cache_timeout, + time_t now) { TALLOC_CTX *tmp_ctx; static const char *src_attrs[] = { SYSDB_NAME, SYSDB_GIDNUM, SYSDB_ORIG_MODSTAMP, NULL }; struct ldb_message *msg; bool new_group = false; - time_t now; int ret; tmp_ctx = talloc_new(NULL); @@ -1551,12 +1558,16 @@ int sysdb_store_group(struct sysdb_ctx *sysdb, } } + /* get transaction timestamp */ + if (!now) + now = time(NULL); + /* FIXME: use the remote modification timestamp to know if the * group needs any update */ if (new_group) { /* group doesn't exist, turn into adding a group */ - ret = sysdb_add_group(sysdb, name, gid, attrs, cache_timeout); + ret = sysdb_add_group(sysdb, name, gid, attrs, cache_timeout, now); goto done; } @@ -1566,8 +1577,6 @@ int sysdb_store_group(struct sysdb_ctx *sysdb, if (ret) goto done; } - now = time(NULL); - ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now); if (ret) goto done; diff --git a/src/providers/ldap/sdap_async_groups.c b/src/providers/ldap/sdap_async_groups.c index f887651..0a8c0ae 100644 --- a/src/providers/ldap/sdap_async_groups.c +++ b/src/providers/ldap/sdap_async_groups.c @@ -199,7 +199,7 @@ sdap_store_group_with_gid(TALLOC_CTX *mem_ctx, } } - ret = sysdb_store_group(ctx, name, gid, group_attrs, cache_timeout); + ret = sysdb_store_group(ctx, name, gid, group_attrs, cache_timeout, 0); if (ret) { DEBUG(2, ("Could not store group %s\n", name)); return ret; @@ -443,7 +443,7 @@ static int sdap_save_grpmem(TALLOC_CTX *memctx, ret = sysdb_store_group(ctx, name, 0, group_attrs, dp_opt_get_int(opts->basic, - SDAP_ENTRY_CACHE_TIMEOUT)); + SDAP_ENTRY_CACHE_TIMEOUT), 0); if (ret) goto fail; return EOK; @@ -874,7 +874,7 @@ sdap_process_missing_member_2307(struct sdap_process_group_state *state, *in_transaction = true; } - ret = sysdb_add_fake_user(state->sysdb, username, NULL); + ret = sysdb_add_fake_user(state->sysdb, username, NULL, 0); if (ret != EOK) { DEBUG(1, ("Cannot store fake user entry: [%d]: %s\n", ret, strerror(ret))); @@ -1558,7 +1558,7 @@ static errno_t sdap_nested_group_populate_users(struct sysdb_ctx *sysdb, } /* If the entry does not exist add a fake user record */ - ret = sysdb_add_fake_user(sysdb, username, original_dn); + ret = sysdb_add_fake_user(sysdb, username, original_dn, 0); if (ret != EOK) { DEBUG(1, ("Cannot store fake user entry, ignoring: [%d]: %s\n", ret, strerror(ret))); diff --git a/src/providers/ldap/sdap_async_initgroups.c b/src/providers/ldap/sdap_async_initgroups.c index 2191c13..d1a367f 100644 --- a/src/providers/ldap/sdap_async_initgroups.c +++ b/src/providers/ldap/sdap_async_initgroups.c @@ -127,7 +127,7 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb, DEBUG(8, ("Adding fake group %s to sysdb\n", name)); ret = sysdb_add_incomplete_group(sysdb, name, gid, original_dn, - posix); + posix, 0); if (ret != EOK) { goto fail; } diff --git a/src/providers/ldap/sdap_async_netgroups.c b/src/providers/ldap/sdap_async_netgroups.c index ff77628..4b791c5 100644 --- a/src/providers/ldap/sdap_async_netgroups.c +++ b/src/providers/ldap/sdap_async_netgroups.c @@ -167,7 +167,7 @@ static errno_t sdap_save_netgroup(TALLOC_CTX *memctx, ret = sysdb_add_netgroup(ctx, name, NULL, netgroup_attrs, dp_opt_get_int(opts->basic, - SDAP_ENTRY_CACHE_TIMEOUT)); + SDAP_ENTRY_CACHE_TIMEOUT), 0); if (ret) goto fail; if (_timestamp) { diff --git a/src/providers/ldap/sdap_async_users.c b/src/providers/ldap/sdap_async_users.c index 82338dc..b2262b0 100644 --- a/src/providers/ldap/sdap_async_users.c +++ b/src/providers/ldap/sdap_async_users.c @@ -300,7 +300,7 @@ int sdap_save_user(TALLOC_CTX *memctx, DEBUG(6, ("Storing info for user %s\n", name)); ret = sysdb_store_user(ctx, name, pwd, uid, gid, gecos, homedir, shell, - user_attrs, missing, cache_timeout); + user_attrs, missing, cache_timeout, 0); if (ret) goto fail; if (_usn_value) { diff --git a/src/providers/proxy/proxy_id.c b/src/providers/proxy/proxy_id.c index ba45d7a..f85819d 100644 --- a/src/providers/proxy/proxy_id.c +++ b/src/providers/proxy/proxy_id.c @@ -106,7 +106,8 @@ static int get_pw_name(TALLOC_CTX *mem_ctx, pwd->pw_dir, pwd->pw_shell, NULL, NULL, - ctx->entry_cache_timeout); + ctx->entry_cache_timeout, + 0); if (ret) { goto done; } @@ -221,7 +222,8 @@ static int get_pw_uid(TALLOC_CTX *mem_ctx, pwd->pw_dir, pwd->pw_shell, NULL, NULL, - ctx->entry_cache_timeout); + ctx->entry_cache_timeout, + 0); if (ret) { goto done; } @@ -361,7 +363,8 @@ again: pwd->pw_dir, pwd->pw_shell, NULL, NULL, - ctx->entry_cache_timeout); + ctx->entry_cache_timeout, + 0); if (ret) { /* Do not fail completely on errors. * Just report the failure to save and go on */ @@ -519,7 +522,8 @@ again: grp->gr_name, grp->gr_gid, members, - ctx->entry_cache_timeout); + ctx->entry_cache_timeout, + 0); if (ret) { goto done; } @@ -670,7 +674,8 @@ again: grp->gr_name, grp->gr_gid, members, - ctx->entry_cache_timeout); + ctx->entry_cache_timeout, + 0); if (ret) { goto done; } @@ -825,7 +830,8 @@ again: grp->gr_name, grp->gr_gid, members, - ctx->entry_cache_timeout); + ctx->entry_cache_timeout, + 0); if (ret) { /* Do not fail completely on errors. * Just report the failure to save and go on */ @@ -937,7 +943,8 @@ static int get_initgr(TALLOC_CTX *mem_ctx, pwd->pw_dir, pwd->pw_shell, NULL, NULL, - ctx->entry_cache_timeout); + ctx->entry_cache_timeout, + 0); if (ret) { goto done; } diff --git a/src/providers/proxy/proxy_netgroup.c b/src/providers/proxy/proxy_netgroup.c index 5af32ac..bad0ee4 100644 --- a/src/providers/proxy/proxy_netgroup.c +++ b/src/providers/proxy/proxy_netgroup.c @@ -119,7 +119,7 @@ errno_t get_netgroup(struct proxy_id_ctx *ctx, } ret = sysdb_add_netgroup(sysdb, name, NULL, attrs, - ctx->entry_cache_timeout); + ctx->entry_cache_timeout, 0); if (ret != EOK) { DEBUG(1, ("sysdb_add_netgroup failed.\n")); goto done; diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c index c276582..9c080c9 100644 --- a/src/tests/sysdb-tests.c +++ b/src/tests/sysdb-tests.c @@ -192,7 +192,7 @@ static int test_add_user(struct test_data *data) ret = sysdb_add_user(data->ctx->sysdb, data->username, data->uid, 0, gecos, homedir, "/bin/bash", - NULL, 0); + NULL, 0, 0); return ret; } @@ -208,7 +208,7 @@ static int test_store_user(struct test_data *data) ret = sysdb_store_user(data->ctx->sysdb, data->username, "x", data->uid, 0, gecos, homedir, data->shell ? data->shell : "/bin/bash", - NULL, NULL, -1); + NULL, NULL, -1, 0); return ret; } @@ -253,7 +253,7 @@ static int test_add_group(struct test_data *data) int ret; ret = sysdb_add_group(data->ctx->sysdb, data->groupname, - data->gid, NULL, 0); + data->gid, NULL, 0, 0); return ret; } @@ -262,7 +262,7 @@ static int test_add_incomplete_group(struct test_data *data) int ret; ret = sysdb_add_incomplete_group(data->ctx->sysdb, data->groupname, - data->gid, NULL, true); + data->gid, NULL, true, 0); return ret; } @@ -271,7 +271,7 @@ static int test_store_group(struct test_data *data) int ret; ret = sysdb_store_group(data->ctx->sysdb, data->groupname, - data->gid, NULL, -1); + data->gid, NULL, -1, 0); return ret; } @@ -420,7 +420,7 @@ static int test_memberof_store_group(struct test_data *data) } ret = sysdb_store_group(data->ctx->sysdb, data->groupname, - data->gid, attrs, -1); + data->gid, attrs, -1, 0); return ret; } @@ -474,7 +474,7 @@ static int test_set_netgroup_attr(struct test_data *data) return ret; } - ret = sysdb_set_netgroup_attr(data->ctx->sysdb, + ret = sysdb_set_netgroup_attr(data->ctx->sysdb, data->netgrname, attrs, SYSDB_MOD_REP); return ret; } @@ -2701,7 +2701,7 @@ START_TEST(test_odd_characters) /* Add */ ret = sysdb_add_incomplete_group(test_ctx->sysdb, - odd_groupname, 20000, NULL, true); + odd_groupname, 20000, NULL, true, 0); fail_unless(ret == EOK, "sysdb_add_incomplete_group error [%d][%s]", ret, strerror(ret)); @@ -2784,7 +2784,7 @@ START_TEST(test_odd_characters) /* Add */ ret = sysdb_add_netgroup(test_ctx->sysdb, odd_netgroupname, "No description", - NULL, 30); + NULL, 30, 0); fail_unless(ret == EOK, "sysdb_add_netgroup error [%d][%s]", ret, strerror(ret)); @@ -2861,14 +2861,14 @@ START_TEST(test_sysdb_original_dn_case_insensitive) ret = sysdb_add_incomplete_group(test_ctx->sysdb, "case_sensitive_group1", 29000, "cn=case_sensitive_group1,cn=example,cn=com", - true); + true, 0); fail_unless(ret == EOK, "sysdb_add_incomplete_group error [%d][%s]", ret, strerror(ret)); ret = sysdb_add_incomplete_group(test_ctx->sysdb, "case_sensitive_group2", 29001, "cn=CASE_SENSITIVE_GROUP1,cn=EXAMPLE,cn=COM", - true); + true, 0); fail_unless(ret == EOK, "sysdb_add_incomplete_group error [%d][%s]", ret, strerror(ret)); diff --git a/src/tools/sss_sync_ops.c b/src/tools/sss_sync_ops.c index 49c6c58..7172270 100644 --- a/src/tools/sss_sync_ops.c +++ b/src/tools/sss_sync_ops.c @@ -472,7 +472,7 @@ int useradd(TALLOC_CTX *mem_ctx, int ret; ret = sysdb_add_user(sysdb, data->name, data->uid, data->gid, - data->gecos, data->home, data->shell, NULL, 0); + data->gecos, data->home, data->shell, NULL, 0, 0); if (ret) { goto done; } @@ -537,7 +537,7 @@ int groupadd(TALLOC_CTX *mem_ctx, { int ret; - ret = sysdb_add_group(sysdb, data->name, data->gid, NULL, 0); + ret = sysdb_add_group(sysdb, data->name, data->gid, NULL, 0, 0); if (ret == EOK) { flush_nscd_cache(mem_ctx, NSCD_DB_GROUP); } -- 1.7.6