From 684d1b48b5582a1bf7812b8c3c663592dc6dfed9 Mon Sep 17 00:00:00 2001 From: Pavel Březina Date: Mon, 19 Sep 2011 12:53:37 +0200 Subject: SysDB commands that save lastUpdate allows this value to be passed in https://fedorahosted.org/sssd/ticket/836 --- src/providers/ldap/sdap_async_groups.c | 34 +++++++++++++++++++----------- src/providers/ldap/sdap_async_initgroups.c | 6 ++++-- src/providers/ldap/sdap_async_netgroups.c | 10 ++++++--- src/providers/ldap/sdap_async_private.h | 3 ++- src/providers/ldap/sdap_async_users.c | 9 +++++--- 5 files changed, 41 insertions(+), 21 deletions(-) (limited to 'src/providers/ldap') diff --git a/src/providers/ldap/sdap_async_groups.c b/src/providers/ldap/sdap_async_groups.c index 1e8e4b3d8..535c38338 100644 --- a/src/providers/ldap/sdap_async_groups.c +++ b/src/providers/ldap/sdap_async_groups.c @@ -185,7 +185,8 @@ sdap_store_group_with_gid(TALLOC_CTX *mem_ctx, gid_t gid, struct sysdb_attrs *group_attrs, uint64_t cache_timeout, - bool posix_group) + bool posix_group, + time_t now) { errno_t ret; @@ -199,7 +200,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, now); if (ret) { DEBUG(2, ("Could not store group %s\n", name)); return ret; @@ -215,7 +216,8 @@ static int sdap_save_group(TALLOC_CTX *memctx, struct sysdb_attrs *attrs, bool store_members, bool populate_members, - char **_usn_value) + char **_usn_value, + time_t now) { struct ldb_message_element *el; struct sysdb_attrs *group_attrs; @@ -389,7 +391,7 @@ static int sdap_save_group(TALLOC_CTX *memctx, name, gid, group_attrs, dp_opt_get_int(opts->basic, SDAP_ENTRY_CACHE_TIMEOUT), - posix_group); + posix_group, now); if (ret) goto fail; if (_usn_value) { @@ -417,7 +419,8 @@ static int sdap_save_grpmem(TALLOC_CTX *memctx, struct sysdb_ctx *ctx, struct sdap_options *opts, struct sss_domain_info *dom, - struct sysdb_attrs *attrs) + struct sysdb_attrs *attrs, + time_t now) { struct ldb_message_element *el; struct sysdb_attrs *group_attrs = NULL; @@ -459,7 +462,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), now); if (ret) goto fail; return EOK; @@ -489,6 +492,7 @@ static int sdap_save_groups(TALLOC_CTX *memctx, int i; struct sysdb_attrs **saved_groups = NULL; int nsaved_groups = 0; + time_t now; switch (opts->schema_type) { case SDAP_SCHEMA_RFC2307: @@ -524,13 +528,14 @@ static int sdap_save_groups(TALLOC_CTX *memctx, } } + now = time(NULL); for (i = 0; i < num_groups; i++) { usn_value = NULL; /* if 2 pass savemembers = false */ ret = sdap_save_group(tmpctx, sysdb, opts, dom, groups[i], - (!twopass), populate_members, &usn_value); + (!twopass), populate_members, &usn_value, now); /* Do not fail completely on errors. * Just report the failure to save and go on */ @@ -563,7 +568,7 @@ static int sdap_save_groups(TALLOC_CTX *memctx, for (i = 0; i < nsaved_groups; i++) { - ret = sdap_save_grpmem(tmpctx, sysdb, opts, dom, saved_groups[i]); + ret = sdap_save_grpmem(tmpctx, sysdb, opts, dom, saved_groups[i], now); /* Do not fail completely on errors. * Just report the failure to save and go on */ if (ret) { @@ -891,7 +896,8 @@ sdap_add_group_member_2307(struct sdap_process_group_state *state, static int sdap_process_missing_member_2307(struct sdap_process_group_state *state, - char *member_name, bool *in_transaction) + char *member_name, bool *in_transaction, + time_t now) { int ret, sret; TALLOC_CTX *tmp_ctx; @@ -946,7 +952,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, now); if (ret != EOK) { DEBUG(1, ("Cannot store fake user entry: [%d]: %s\n", ret, strerror(ret))); @@ -989,8 +995,10 @@ sdap_process_group_members_2307(struct sdap_process_group_state *state, char *member_name; int ret; errno_t sret; + time_t now; int i; + now = time(NULL); for (i=0; i < memberel->num_values; i++) { member_name = (char *)memberel->values[i].data; @@ -1017,7 +1025,7 @@ sdap_process_group_members_2307(struct sdap_process_group_state *state, i, member_name)); ret = sdap_process_missing_member_2307(state, member_name, - &in_transaction); + &in_transaction, now); if (ret != EOK) { DEBUG(1, ("Error processing missing member #%d (%s):\n", i, member_name)); @@ -1529,6 +1537,7 @@ static errno_t sdap_nested_group_populate_users(struct sysdb_ctx *sysdb, struct sysdb_attrs *attrs; static const char *search_attrs[] = { SYSDB_NAME, NULL }; size_t count; + time_t now; if (num_users == 0) { /* Nothing to do if there are no users */ @@ -1544,6 +1553,7 @@ static errno_t sdap_nested_group_populate_users(struct sysdb_ctx *sysdb, goto done; } + now = time(NULL); for (i = 0; i < num_users; i++) { ret = sysdb_attrs_primary_name(sysdb, users[i], opts->user_map[SDAP_AT_USER_NAME].name, @@ -1613,7 +1623,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, now); 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 4cf5a53bb..65ff86cd0 100644 --- a/src/providers/ldap/sdap_async_initgroups.c +++ b/src/providers/ldap/sdap_async_initgroups.c @@ -44,6 +44,7 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb, int ret; bool in_transaction = false; bool posix; + time_t now; /* There are no groups in LDAP but we should add user to groups ?? */ if (ldap_groups_count == 0) return EOK; @@ -90,6 +91,7 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb, goto done; } + now = time(NULL); for (i=0; missing[i]; i++) { /* The group is not in sysdb, need to add a fake entry */ for (ai=0; ai < ldap_groups_count; ai++) { @@ -127,7 +129,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, now); if (ret != EOK) { goto fail; } @@ -1832,7 +1834,7 @@ static void sdap_get_initgr_user(struct tevent_req *subreq) ret = sdap_save_user(state, state->sysdb, state->opts, state->dom, state->orig_user, state->ldap_attrs, - true, NULL); + true, NULL, 0); if (ret) { sysdb_transaction_cancel(state->sysdb); tevent_req_error(req, ret); diff --git a/src/providers/ldap/sdap_async_netgroups.c b/src/providers/ldap/sdap_async_netgroups.c index 6f884bc52..586d079e7 100644 --- a/src/providers/ldap/sdap_async_netgroups.c +++ b/src/providers/ldap/sdap_async_netgroups.c @@ -40,7 +40,8 @@ static errno_t sdap_save_netgroup(TALLOC_CTX *memctx, struct sdap_options *opts, struct sss_domain_info *dom, struct sysdb_attrs *attrs, - char **_timestamp) + char **_timestamp, + time_t now) { struct ldb_message_element *el; struct sysdb_attrs *netgroup_attrs; @@ -167,7 +168,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), now); if (ret) goto fail; if (_timestamp) { @@ -666,6 +667,7 @@ static void netgr_translate_members_done(struct tevent_req *subreq) struct sdap_get_netgroups_state); int ret; size_t c; + time_t now; ret = netgroup_translate_ldap_members_recv(subreq, state, &state->count, &state->netgroups); @@ -675,11 +677,13 @@ static void netgr_translate_members_done(struct tevent_req *subreq) return; } + now = time(NULL); for (c = 0; c < state->count; c++) { ret = sdap_save_netgroup(state, state->sysdb, state->opts, state->dom, state->netgroups[c], - &state->higher_timestamp); + &state->higher_timestamp, + now); if (ret) { DEBUG(2, ("Failed to store netgroups.\n")); tevent_req_error(req, ret); diff --git a/src/providers/ldap/sdap_async_private.h b/src/providers/ldap/sdap_async_private.h index 5b0417163..fa7844e72 100644 --- a/src/providers/ldap/sdap_async_private.h +++ b/src/providers/ldap/sdap_async_private.h @@ -81,7 +81,8 @@ int sdap_save_user(TALLOC_CTX *memctx, struct sysdb_attrs *attrs, const char **ldap_attrs, bool is_initgr, - char **_usn_value); + char **_usn_value, + time_t now); int sdap_save_users(TALLOC_CTX *memctx, struct sysdb_ctx *sysdb, diff --git a/src/providers/ldap/sdap_async_users.c b/src/providers/ldap/sdap_async_users.c index adf3cf4ef..949cc0268 100644 --- a/src/providers/ldap/sdap_async_users.c +++ b/src/providers/ldap/sdap_async_users.c @@ -37,7 +37,8 @@ int sdap_save_user(TALLOC_CTX *memctx, struct sysdb_attrs *attrs, const char **ldap_attrs, bool is_initgr, - char **_usn_value) + char **_usn_value, + time_t now) { struct ldb_message_element *el; int ret; @@ -315,7 +316,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, now); if (ret) goto fail; if (_usn_value) { @@ -350,6 +351,7 @@ int sdap_save_users(TALLOC_CTX *memctx, char *usn_value; int ret; int i; + time_t now; if (num_users == 0) { /* Nothing to do if there are no users */ @@ -366,12 +368,13 @@ int sdap_save_users(TALLOC_CTX *memctx, goto done; } + now = time(NULL); for (i = 0; i < num_users; i++) { usn_value = NULL; ret = sdap_save_user(tmpctx, sysdb, opts, dom, users[i], attrs, false, - &usn_value); + &usn_value, now); /* Do not fail completely on errors. * Just report the failure to save and go on */ -- cgit