sssd/0019-be_refresh-support-users.patch

160 lines
5.9 KiB
Diff

From 40f5e40aa0bb9aa6b80b547e9643bebf53f7620a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Thu, 19 Feb 2015 12:00:52 +0100
Subject: [PATCH 19/99] be_refresh: support users
Resolves:
https://fedorahosted.org/sssd/ticket/2346
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
(cherry picked from commit e77d6366ff9e49dbbb607f1709f1ae4190b99489)
---
src/db/sysdb.c | 7 +++++++
src/db/sysdb.h | 2 ++
src/providers/dp_refresh.c | 23 +++++++++++++++++++++++
src/providers/dp_refresh.h | 1 +
src/providers/ldap/sdap_refresh.c | 29 +++++++++++++++++++++++++++++
5 files changed, 62 insertions(+)
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index 61a2240016b5cb77e6fbbc3286fd1a194c5a0b48..2bb4a41aa4a9e6201ac27ac8d9a1803c1fb5c43e 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -172,6 +172,13 @@ struct ldb_dn *sysdb_user_dn(TALLOC_CTX *mem_ctx, struct sss_domain_info *dom,
return dn;
}
+struct ldb_dn *sysdb_user_base_dn(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *dom)
+{
+ return ldb_dn_new_fmt(mem_ctx, dom->sysdb->ldb,
+ SYSDB_TMPL_USER_BASE, dom->name);
+}
+
struct ldb_dn *sysdb_group_dn(TALLOC_CTX *mem_ctx,
struct sss_domain_info *dom, const char *name)
{
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index cf6028acb806d5d4eedf4cf0680cf4ac9fd6368d..ce1b45be984b65c61d8c09dee2bdf7f2e461494e 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -383,6 +383,8 @@ errno_t sysdb_get_rdn(struct sysdb_ctx *sysdb, TALLOC_CTX *mem_ctx,
const char *dn, char **_name, char **_val);
struct ldb_dn *sysdb_user_dn(TALLOC_CTX *mem_ctx, struct sss_domain_info *dom,
const char *name);
+struct ldb_dn *sysdb_user_base_dn(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *dom);
struct ldb_dn *sysdb_group_dn(TALLOC_CTX *mem_ctx, struct sss_domain_info *dom,
const char *name);
struct ldb_dn *sysdb_netgroup_dn(TALLOC_CTX *mem_ctx,
diff --git a/src/providers/dp_refresh.c b/src/providers/dp_refresh.c
index bd02d0cd99f9a061109f0c17797c6e018d602dc5..f599618e074e6c0ef29363f014ec0ec422de3a55 100644
--- a/src/providers/dp_refresh.c
+++ b/src/providers/dp_refresh.c
@@ -89,6 +89,26 @@ done:
return ret;
}
+static errno_t be_refresh_get_users(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *domain,
+ time_t period,
+ char ***_values)
+{
+ struct ldb_dn *base_dn = NULL;
+ errno_t ret;
+
+ base_dn = sysdb_user_base_dn(mem_ctx, domain);
+ if (base_dn == NULL) {
+ return ENOMEM;
+ }
+
+ ret = be_refresh_get_values(mem_ctx, domain, period, SYSDB_USER_CLASS,
+ base_dn, SYSDB_NAME, _values);
+
+ talloc_free(base_dn);
+ return ret;
+}
+
static errno_t be_refresh_get_netgroups(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
time_t period,
@@ -138,6 +158,9 @@ struct be_refresh_ctx *be_refresh_ctx_init(TALLOC_CTX *mem_ctx)
return NULL;
}
+ ctx->callbacks[BE_REFRESH_TYPE_USERS].name = "users";
+ ctx->callbacks[BE_REFRESH_TYPE_USERS].get_values = be_refresh_get_users;
+
ctx->callbacks[BE_REFRESH_TYPE_NETGROUPS].name = "netgroups";
ctx->callbacks[BE_REFRESH_TYPE_NETGROUPS].get_values \
= be_refresh_get_netgroups;
diff --git a/src/providers/dp_refresh.h b/src/providers/dp_refresh.h
index d7c775fff78455cc016a0419ee4b9b00ba8ec3f7..a0d42734b64e16184a3a2cdfe45057003ddec6cc 100644
--- a/src/providers/dp_refresh.h
+++ b/src/providers/dp_refresh.h
@@ -44,6 +44,7 @@ typedef errno_t
(*be_refresh_recv_t)(struct tevent_req *req);
enum be_refresh_type {
+ BE_REFRESH_TYPE_USERS,
BE_REFRESH_TYPE_NETGROUPS,
BE_REFRESH_TYPE_SENTINEL
};
diff --git a/src/providers/ldap/sdap_refresh.c b/src/providers/ldap/sdap_refresh.c
index e300e28b68aa87957a607259b6439ceca0796e7e..8fff9d49297b4efe3f4673003859242dd9192070 100644
--- a/src/providers/ldap/sdap_refresh.c
+++ b/src/providers/ldap/sdap_refresh.c
@@ -75,6 +75,9 @@ static struct tevent_req *sdap_refresh_send(TALLOC_CTX *mem_ctx,
}
switch (entry_type) {
+ case BE_REQ_USER:
+ state->type = "user";
+ break;
case BE_REQ_NETGROUP:
state->type = "netgroup";
break;
@@ -200,6 +203,23 @@ static errno_t sdap_refresh_recv(struct tevent_req *req)
}
static struct tevent_req *
+sdap_refresh_users_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct be_ctx *be_ctx,
+ struct sss_domain_info *domain,
+ char **names,
+ void *pvt)
+{
+ return sdap_refresh_send(mem_ctx, ev, be_ctx, domain,
+ BE_REQ_USER, names, pvt);
+}
+
+static errno_t sdap_refresh_users_recv(struct tevent_req *req)
+{
+ return sdap_refresh_recv(req);
+}
+
+static struct tevent_req *
sdap_refresh_netgroups_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct be_ctx *be_ctx,
@@ -221,6 +241,15 @@ errno_t sdap_refresh_init(struct be_refresh_ctx *refresh_ctx,
{
errno_t ret;
+ ret = be_refresh_add_cb(refresh_ctx, BE_REFRESH_TYPE_USERS,
+ sdap_refresh_users_send,
+ sdap_refresh_users_recv,
+ id_ctx);
+ if (ret != EOK && ret != EEXIST) {
+ DEBUG(SSSDBG_MINOR_FAILURE, "Periodical refresh of users "
+ "will not work [%d]: %s\n", ret, strerror(ret));
+ }
+
ret = be_refresh_add_cb(refresh_ctx, BE_REFRESH_TYPE_NETGROUPS,
sdap_refresh_netgroups_send,
sdap_refresh_netgroups_recv,
--
2.4.0