From 3be9f035f81d68723855c405b2a270f0733fd650 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 31 May 2016 17:38:03 +0200 Subject: [PATCH 11/14] SYSDB: Only update user attributes if needed Uses the same logic as previously used for updating group entries to only update user attributes if the group entry actually changed. --- src/db/sysdb_ops.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c index 235f39ee57f578c472463a6076242d7a4cf202d2..f1f797f4fec2a3e5a8d7af62f644c4c46b383628 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -1089,6 +1089,16 @@ done: return ret; } +static errno_t sysdb_check_and_update_ts_usr(struct sss_domain_info *domain, + const char *grp_name, + struct sysdb_attrs *attrs, + uint64_t cache_timeout, + time_t now) +{ + return sysdb_check_and_update_ts_obj(domain, SYSDB_USER, grp_name, + attrs, cache_timeout, now); +} + static errno_t sysdb_check_and_update_ts_grp(struct sss_domain_info *domain, const char *grp_name, struct sysdb_attrs *attrs, @@ -1108,6 +1118,15 @@ static errno_t sysdb_create_ts_grp(struct sss_domain_info *domain, cache_timeout, now); } +static errno_t sysdb_create_ts_usr(struct sss_domain_info *domain, + const char *usr_name, + uint64_t cache_timeout, + time_t now) +{ + return sysdb_create_ts_obj(domain, SYSDB_USER, usr_name, + cache_timeout, now); +} + /* =Replace-Attributes-On-Entry=========================================== */ static int sysdb_set_cache_entry_attr(struct ldb_context *ldb, struct ldb_dn *entry_dn, @@ -1850,6 +1869,13 @@ int sysdb_add_user(struct sss_domain_info *domain, ret = sysdb_add_basic_user(domain, name, uid, gid, gecos, homedir, shell); if (ret) goto done; + ret = sysdb_create_ts_usr(domain, name, cache_timeout, now); + if (ret != EOK) { + DEBUG(SSSDBG_MINOR_FAILURE, + "Cannot create user timestamp entry\n"); + /* Not fatal */ + } + if (uid == 0) { ret = sysdb_get_new_id(domain, &id); if (ret) goto done; @@ -2415,6 +2441,15 @@ int sysdb_store_user(struct sss_domain_info *domain, errno_t sret = EOK; bool in_transaction = false; + ret = sysdb_check_and_update_ts_usr(domain, name, attrs, + cache_timeout, now); + if (ret == EOK) { + DEBUG(SSSDBG_TRACE_LIBS, + "The user record of %s did not change, only updated " + "the timestamp cache\n", name); + return EOK; + } + tmp_ctx = talloc_new(NULL); if (!tmp_ctx) { return ENOMEM; -- 2.4.11