summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorPetr Čech <pcech@redhat.com>2017-02-14 12:07:19 +0100
committerJakub Hrozek <jhrozek@redhat.com>2017-03-08 12:36:56 +0100
commit57a924e71230ea360b19a88e0d5818cf01017161 (patch)
treea046c67a239f969f1183a876c182d35eccbf2f52 /src/db
parent4358d76475f0292461a2a479d2149472db103c1d (diff)
downloadsssd-57a924e71230ea360b19a88e0d5818cf01017161.tar.gz
sssd-57a924e71230ea360b19a88e0d5818cf01017161.tar.xz
sssd-57a924e71230ea360b19a88e0d5818cf01017161.zip
sss_cache: User/groups invalidation in domain cache
When a group/users are invalidated from sss_cache, the group/user information in domain and timestamps cache are inconsistent with regard to dataExpireTimestamp attribute. This patch fixes the problem by explicitly invalidating the domain cache's entry when the timestamp cache entry is invalidated by sss_cache call. There is one new function: * sysdb_invalidate_cache_entry() provided for this purpose and used only in sss_cache utility. Resolves: https://fedorahosted.org/sssd/ticket/3164 Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com> Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb.h9
-rw-r--r--src/db/sysdb_ops.c65
2 files changed, 74 insertions, 0 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 54bac7e5f..83d0d794c 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -877,6 +877,15 @@ int sysdb_set_entry_attr(struct sysdb_ctx *sysdb,
struct sysdb_attrs *attrs,
int mod_op);
+/* User/group invalidation of cache by direct writing to persistent cache
+ * WARNING: This function can cause performance issue!!
+ * is_user = true --> user invalidation
+ * is_user = false --> group invalidation
+ */
+int sysdb_invalidate_cache_entry(struct sss_domain_info *domain,
+ const char *name,
+ bool is_user);
+
/* Replace user attrs */
int sysdb_set_user_attr(struct sss_domain_info *domain,
const char *name,
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 47f878f35..eb40f9bb0 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -5012,3 +5012,68 @@ done:
talloc_free(tmp_ctx);
return ret;
}
+
+/* User/group invalidation of cache by direct writing to persistent cache
+ * WARNING: This function can cause performance issue!!
+ * is_user = true --> user invalidation
+ * is_user = false --> group invalidation
+ */
+int sysdb_invalidate_cache_entry(struct sss_domain_info *domain,
+ const char *name,
+ bool is_user)
+{
+ TALLOC_CTX *tmp_ctx;
+ struct sysdb_ctx *sysdb = domain->sysdb;
+ struct ldb_dn *entry_dn = NULL;
+ struct sysdb_attrs *attrs = NULL;
+ errno_t ret;
+
+ tmp_ctx = talloc_new(NULL);
+ if (!tmp_ctx) {
+ return ENOMEM;
+ }
+
+ if (is_user == true) {
+ entry_dn = sysdb_user_dn(tmp_ctx, domain, name);
+ } else {
+ entry_dn = sysdb_group_dn(tmp_ctx, domain, name);
+ }
+
+ if (entry_dn == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ attrs = sysdb_new_attrs(tmp_ctx);
+ if (attrs == NULL) {
+ DEBUG(SSSDBG_MINOR_FAILURE, "Could not create sysdb attributes\n");
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE, 1);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_MINOR_FAILURE,
+ "Could not add expiration time to attributes\n");
+ goto done;
+ }
+
+ ret = sysdb_set_cache_entry_attr(sysdb->ldb, entry_dn,
+ attrs, SYSDB_MOD_REP);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_MINOR_FAILURE,
+ "Cannot set attrs for %s, %d [%s]\n",
+ ldb_dn_get_linearized(entry_dn), ret, sss_strerror(ret));
+ goto done;
+ }
+
+ DEBUG(SSSDBG_FUNC_DATA,
+ "Cache entry [%s] has been invalidated.\n",
+ ldb_dn_get_linearized(entry_dn));
+
+ ret = EOK;
+
+done:
+ talloc_zfree(tmp_ctx);
+ return ret;
+}