From 89b0207483227044e8e9f0cb9c1ff51b1d35bd27 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 5650c2572b1d18d9c4dceadd3c2cd95700d9ba43..de9ff873ee0069a31fc798eac423f3993f2e4532 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; @@ -2422,6 +2448,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