[SSSD] [PATCH] IPA: Resolve IPA user groups' overrideDN in non-default view
Jakub Hrozek
jhrozek at redhat.com
Fri Jan 30 10:33:42 UTC 2015
Hi,
the attached patches fix
https://fedorahosted.org/sssd/ticket/2571 for me.
Sumit was kind to provide first round of review comments on IRC. I hope
I managed to implement them all. Feel free to suggest even better name
for the new async request.
-------------- next part --------------
>From 21416fb578b6c916a64c2130a3625d891b6256ef Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Tue, 27 Jan 2015 16:02:33 +0100
Subject: [PATCH 1/2] LDAP: Add UUID when saving incomplete groups
Related to:
https://fedorahosted.org/sssd/ticket/2571
---
src/db/sysdb.h | 1 +
src/db/sysdb_ops.c | 6 ++++++
src/providers/ldap/sdap_async_initgroups.c | 16 +++++++++++++---
src/providers/ldap/sdap_async_initgroups_ad.c | 2 +-
src/tests/sysdb-tests.c | 16 ++++++++--------
5 files changed, 29 insertions(+), 12 deletions(-)
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 3fb18b9bb9d006c4810301dd898b7c48fe6ec504..0574a91fbaa1598a1ef0ff83ee353e7348ba4311 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -797,6 +797,7 @@ int sysdb_add_incomplete_group(struct sss_domain_info *domain,
gid_t gid,
const char *original_dn,
const char *sid_str,
+ const char *uuid,
bool posix,
time_t now);
diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c
index 0c254d8cdad1144c32aad7e470fa2a35cd24b38b..6085762dcc5585114dd3049dd3a365856cb6b190 100644
--- a/src/db/sysdb_ops.c
+++ b/src/db/sysdb_ops.c
@@ -1610,6 +1610,7 @@ int sysdb_add_incomplete_group(struct sss_domain_info *domain,
gid_t gid,
const char *original_dn,
const char *sid_str,
+ const char *uuid,
bool posix,
time_t now)
{
@@ -1656,6 +1657,11 @@ int sysdb_add_incomplete_group(struct sss_domain_info *domain,
if (ret) goto done;
}
+ if (uuid) {
+ ret = sysdb_attrs_add_string(attrs, SYSDB_UUID, uuid);
+ if (ret) goto done;
+ }
+
ret = sysdb_set_group_attr(domain, name, attrs, SYSDB_MOD_REP);
done:
diff --git a/src/providers/ldap/sdap_async_initgroups.c b/src/providers/ldap/sdap_async_initgroups.c
index d3e080013ec99c18648c6a57e478d50eb3b666f1..6b3179d2d6bb30b3b00aa35b07da42de3cf08a34 100644
--- a/src/providers/ldap/sdap_async_initgroups.c
+++ b/src/providers/ldap/sdap_async_initgroups.c
@@ -41,6 +41,7 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
int i, mi, ai;
const char *groupname;
const char *original_dn;
+ const char *uuid = NULL;
char **missing;
gid_t gid;
int ret;
@@ -191,15 +192,24 @@ static errno_t sdap_add_incomplete_groups(struct sysdb_ctx *sysdb,
&original_dn);
if (ret) {
DEBUG(SSSDBG_FUNC_DATA,
- "The group has no name original DN\n");
+ "The group has no original DN\n");
original_dn = NULL;
}
+ ret = sysdb_attrs_get_string(ldap_groups[ai],
+ SYSDB_UUID,
+ &uuid);
+ if (ret) {
+ DEBUG(SSSDBG_FUNC_DATA,
+ "The group has no UUID\n");
+ uuid = NULL;
+ }
+
DEBUG(SSSDBG_TRACE_INTERNAL,
"Adding fake group %s to sysdb\n", groupname);
ret = sysdb_add_incomplete_group(domain, groupname, gid,
- original_dn, sid_str, posix,
- now);
+ original_dn, sid_str,
+ uuid, posix, now);
if (ret != EOK) {
goto done;
}
diff --git a/src/providers/ldap/sdap_async_initgroups_ad.c b/src/providers/ldap/sdap_async_initgroups_ad.c
index a533279f680d5cabc096cb9e64cfdb1057c5c799..1b8c8d981ea14ac0fca0903f16296c8a6701c5dd 100644
--- a/src/providers/ldap/sdap_async_initgroups_ad.c
+++ b/src/providers/ldap/sdap_async_initgroups_ad.c
@@ -929,7 +929,7 @@ static void sdap_ad_tokengroups_initgr_mapping_done(struct tevent_req *subreq)
* it will replace this temporary entry. */
name = sid;
ret = sysdb_add_incomplete_group(domain, name, gid,
- NULL, sid, false, now);
+ NULL, sid, NULL, false, now);
if (ret != EOK) {
DEBUG(SSSDBG_MINOR_FAILURE, "Could not create incomplete "
"group: [%s]\n", strerror(ret));
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index 6643710db42f5469ada2fe3e0cf8611b508d2c41..7c2c6d208127b0b6f9025435619b027246c6dd35 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -266,7 +266,7 @@ static int test_add_incomplete_group(struct test_data *data)
int ret;
ret = sysdb_add_incomplete_group(data->ctx->domain, data->groupname,
- data->gid, NULL, NULL, true, 0);
+ data->gid, NULL, NULL, NULL, true, 0);
return ret;
}
@@ -4038,8 +4038,8 @@ START_TEST(test_odd_characters)
/* ===== Groups ===== */
/* Add */
- ret = sysdb_add_incomplete_group(test_ctx->domain,
- odd_groupname, 20000, NULL, NULL, true, 0);
+ ret = sysdb_add_incomplete_group(test_ctx->domain, odd_groupname,
+ 20000, NULL, NULL, NULL, true, 0);
fail_unless(ret == EOK, "sysdb_add_incomplete_group error [%d][%s]",
ret, strerror(ret));
@@ -4195,8 +4195,8 @@ START_TEST(test_SSS_LDB_SEARCH)
fail_if(nonexist_dn == NULL, "sysdb_group_dn failed");
/* Add */
- ret = sysdb_add_incomplete_group(test_ctx->domain,
- groupname, 20000, NULL, NULL, true, 0);
+ ret = sysdb_add_incomplete_group(test_ctx->domain, groupname,
+ 20000, NULL, NULL, NULL, true, 0);
fail_unless(ret == EOK, "sysdb_add_incomplete_group error [%d][%s]",
ret, strerror(ret));
@@ -4992,14 +4992,14 @@ START_TEST(test_sysdb_original_dn_case_insensitive)
ret = sysdb_add_incomplete_group(test_ctx->domain,
"case_sensitive_group1", 29000,
"cn=case_sensitive_group1,cn=example,cn=com",
- NULL, true, 0);
+ NULL, NULL, true, 0);
fail_unless(ret == EOK, "sysdb_add_incomplete_group error [%d][%s]",
ret, strerror(ret));
ret = sysdb_add_incomplete_group(test_ctx->domain,
"case_sensitive_group2", 29001,
"cn=CASE_SENSITIVE_GROUP1,cn=EXAMPLE,cn=COM",
- NULL, true, 0);
+ NULL, NULL, true, 0);
fail_unless(ret == EOK, "sysdb_add_incomplete_group error [%d][%s]",
ret, strerror(ret));
@@ -5035,7 +5035,7 @@ START_TEST(test_sysdb_search_sid_str)
ret = sysdb_add_incomplete_group(test_ctx->domain,
"group", 29000,
"cn=group,cn=example,cn=com",
- "S-1-2-3-4", true, 0);
+ "S-1-2-3-4", NULL, true, 0);
fail_unless(ret == EOK, "sysdb_add_incomplete_group error [%d][%s]",
ret, strerror(ret));
--
2.1.0
-------------- next part --------------
>From 1a769d579bd794a4645b41518790f41a0e2f7e93 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Mon, 26 Jan 2015 23:25:17 +0100
Subject: [PATCH 2/2] IPA: Resolve IPA user groups' overrideDN in non-default
view
When the client is in a non-default view, we need to store the override
data, in particular the overrideDN as well.
Resolves:
https://fedorahosted.org/sssd/ticket/2571
---
src/providers/ipa/ipa_id.c | 318 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 311 insertions(+), 7 deletions(-)
diff --git a/src/providers/ipa/ipa_id.c b/src/providers/ipa/ipa_id.c
index 3d6861eeb562683518d425616b0e5c413cddba0b..cc6abcf8721e3f05526bf62063f0cbdc7c1c257b 100644
--- a/src/providers/ipa/ipa_id.c
+++ b/src/providers/ipa/ipa_id.c
@@ -286,6 +286,239 @@ static int ipa_resolve_user_list_recv(struct tevent_req *req, int *dp_error)
return EOK;
}
+struct ipa_initgr_get_overrides_state {
+ struct tevent_context *ev;
+ struct ipa_id_ctx *ipa_ctx;
+ struct sss_domain_info *user_dom;
+ const char *realm;
+
+ struct ldb_message **groups;
+ size_t group_count;
+ size_t group_idx;
+ struct be_acct_req *ar;
+
+ int dp_error;
+};
+
+static int ipa_initgr_get_overrides_step(struct tevent_req *req);
+
+static struct tevent_req *
+ipa_initgr_get_overrides_send(TALLOC_CTX *memctx,
+ struct tevent_context *ev,
+ struct ipa_id_ctx *ipa_ctx,
+ struct sss_domain_info *user_dom,
+ size_t groups_count,
+ struct ldb_message **groups)
+{
+ int ret;
+ struct tevent_req *req;
+ struct ipa_initgr_get_overrides_state *state;
+
+ req = tevent_req_create(memctx, &state,
+ struct ipa_initgr_get_overrides_state);
+ if (req == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "tevent_req_create failed.\n");
+ return NULL;
+ }
+ state->ev = ev;
+ state->ipa_ctx = ipa_ctx;
+ state->user_dom = user_dom;
+ state->groups = groups;
+ state->group_count = groups_count;
+ state->group_idx = 0;
+ state->ar = NULL;
+ state->realm = dp_opt_get_string(state->ipa_ctx->ipa_options->basic,
+ IPA_KRB5_REALM);
+ if (state->realm == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "No Kerberos realm for IPA?\n");
+ ret = EINVAL;
+ goto done;
+ }
+
+ ret = ipa_initgr_get_overrides_step(req);
+done:
+ if (ret == EOK) {
+ tevent_req_done(req);
+ tevent_req_post(req, ev);
+ } else if (ret != EAGAIN) {
+ tevent_req_error(req, ret);
+ tevent_req_post(req, ev);
+ }
+
+ return req;
+}
+
+static void ipa_initgr_get_overrides_override_done(struct tevent_req *subreq);
+
+static int ipa_initgr_get_overrides_step(struct tevent_req *req)
+{
+ int ret;
+ struct tevent_req *subreq;
+ const char *ipa_uuid;
+ struct ipa_initgr_get_overrides_state *state = tevent_req_data(req,
+ struct ipa_initgr_get_overrides_state);
+
+ DEBUG(SSSDBG_TRACE_LIBS,
+ "Processing group %zu/%zu\n", state->group_idx, state->group_count);
+
+ if (state->group_idx >= state->group_count) {
+ return EOK;
+ }
+
+ ipa_uuid = ldb_msg_find_attr_as_string(state->groups[state->group_idx],
+ SYSDB_UUID, NULL);
+ if (ipa_uuid == NULL) {
+ /* This should never happen, the search filter used to get the list
+ * of groups includes "uuid=*"
+ */
+ DEBUG(SSSDBG_OP_FAILURE, "A group with no UUID, error!\n");
+ return EINVAL;
+ }
+
+ talloc_free(state->ar); /* Avoid spiking memory with many groups */
+
+ ret = get_be_acct_req_for_uuid(state, ipa_uuid,
+ state->user_dom->name, &state->ar);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, "get_be_acct_req_for_sid failed.\n");
+ return ret;
+ }
+
+ DEBUG(SSSDBG_TRACE_LIBS, "Fetching group %s\n", ipa_uuid);
+
+ subreq = ipa_get_ad_override_send(state, state->ev,
+ state->ipa_ctx->sdap_id_ctx,
+ state->ipa_ctx->ipa_options,
+ state->realm,
+ state->ipa_ctx->view_name,
+ state->ar);
+ if (subreq == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "ipa_get_ad_override_send failed.\n");
+ return ENOMEM;
+ }
+ tevent_req_set_callback(subreq,
+ ipa_initgr_get_overrides_override_done, req);
+ return EAGAIN;
+}
+
+static void ipa_initgr_get_overrides_override_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(subreq,
+ struct tevent_req);
+ struct ipa_initgr_get_overrides_state *state = tevent_req_data(req,
+ struct ipa_initgr_get_overrides_state);
+ int ret;
+ struct sysdb_attrs *override_attrs;
+
+ ret = ipa_get_ad_override_recv(subreq, &state->dp_error, state,
+ &override_attrs);
+ talloc_zfree(subreq);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, "IPA override lookup failed: %d\n", ret);
+ tevent_req_error(req, ret);
+ return;
+ }
+
+ ret = sysdb_store_override(state->user_dom, state->ipa_ctx->view_name,
+ SYSDB_MEMBER_GROUP,
+ override_attrs,
+ state->groups[state->group_idx]->dn);
+ talloc_free(override_attrs);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, "sysdb_store_override failed.\n");
+ tevent_req_error(req, ret);
+ return;
+ }
+
+ state->group_idx++;
+
+ ret = ipa_initgr_get_overrides_step(req);
+ if (ret == EAGAIN) {
+ return;
+ } else if (ret != EOK) {
+ tevent_req_error(req, ret);
+ return;
+ }
+
+ tevent_req_done(req);
+}
+
+static int ipa_initgr_get_overrides_recv(struct tevent_req *req, int *dp_error)
+{
+ struct ipa_initgr_get_overrides_state *state = tevent_req_data(req,
+ struct ipa_initgr_get_overrides_state);
+
+ if (dp_error) {
+ *dp_error = state->dp_error;
+ }
+
+ TEVENT_REQ_RETURN_ON_ERROR(req);
+ return EOK;
+}
+
+/* Given a user name, retrieve an array of group UUIDs of groups that have
+ * no overrideDN attribute but do have an UUID attribute.
+ */
+static errno_t ipa_id_get_group_uuids(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ const char *username,
+ size_t *_msgs_count,
+ struct ldb_message ***_msgs)
+{
+ const char *filter;
+ TALLOC_CTX *tmp_ctx;
+ char **uuid_list = NULL;
+ errno_t ret;
+ struct ldb_dn *base_dn;
+ const char *attrs[] = { SYSDB_UUID, NULL };
+ size_t msgs_count;
+ struct ldb_message **msgs;
+
+ tmp_ctx = talloc_new(mem_ctx);
+ if (tmp_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ filter = talloc_asprintf(tmp_ctx,
+ "(&(objectclass=%s)(!(%s=*))(%s=*))",
+ SYSDB_GROUP_CLASS, SYSDB_OVERRIDE_DN,
+ SYSDB_UUID);
+ if (filter == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ base_dn = sysdb_base_dn(sysdb, tmp_ctx);
+ if (base_dn == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = sysdb_search_entry(tmp_ctx, sysdb, base_dn,
+ LDB_SCOPE_SUBTREE, filter, attrs,
+ &msgs_count, &msgs);
+ if (ret == ENOENT) {
+ DEBUG(SSSDBG_TRACE_FUNC,
+ "No groups without %s in sysdb\n", SYSDB_OVERRIDE_DN);
+ ret = EOK;
+ goto done;
+ } else if (ret != EOK) {
+ goto done;
+ }
+
+ uuid_list = talloc_zero_array(tmp_ctx, char *, msgs_count);
+ if (uuid_list == NULL) {
+ goto done;
+ }
+
+ *_msgs_count = msgs_count;
+ *_msgs = talloc_steal(mem_ctx, msgs);
+ ret = EOK;
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}
+
struct ipa_id_get_account_info_state {
struct tevent_context *ev;
struct ipa_id_ctx *ipa_ctx;
@@ -300,6 +533,11 @@ struct ipa_id_get_account_info_state {
struct sysdb_attrs *override_attrs;
struct ldb_message *obj_msg;
struct ldb_message_element *ghosts;
+
+ struct ldb_message **user_groups;
+ size_t group_cnt;
+ size_t group_idx;
+
int dp_error;
};
@@ -519,6 +757,8 @@ static errno_t ipa_id_get_account_info_get_original_step(struct tevent_req *req,
return EOK;
}
+static void ipa_id_get_user_groups_done(struct tevent_req *subreq);
+
static void ipa_id_get_account_info_orig_done(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(subreq,
@@ -549,16 +789,28 @@ static void ipa_id_get_account_info_orig_done(struct tevent_req *subreq)
goto fail;
}
- if ((state->ar->entry_type & BE_REQ_TYPE_MASK) == BE_REQ_GROUP
- && state->ipa_ctx->view_name != NULL
- && strcmp(state->ipa_ctx->view_name,
- SYSDB_DEFAULT_VIEW_NAME) != 0) {
- /* check for ghost members because ghost members are not allowed if a
- * view other than the default view is applied.*/
+ if (state->ipa_ctx->view_name != NULL &&
+ strcmp(state->ipa_ctx->view_name, SYSDB_DEFAULT_VIEW_NAME) != 0) {
- state->ghosts = ldb_msg_find_element(state->obj_msg, SYSDB_GHOST);
+ if ((state->ar->entry_type & BE_REQ_TYPE_MASK) == BE_REQ_GROUP) {
+ /* check for ghost members because ghost members are not allowed
+ * if a view other than the default view is applied.*/
+ state->ghosts = ldb_msg_find_element(state->obj_msg, SYSDB_GHOST);
+ } else if ((state->ar->entry_type & BE_REQ_TYPE_MASK) == \
+ BE_REQ_INITGROUPS) {
+ /* Get UUID list of groups that have no overrideDN set. */
+ ret = ipa_id_get_group_uuids(state, state->sysdb,
+ state->ar->filter_value,
+ &state->group_cnt,
+ &state->user_groups);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, "Cannot get UUID list: %d\n", ret);
+ goto fail;
+ }
+ }
}
+
if (state->override_attrs == NULL) {
uuid = ldb_msg_find_attr_as_string(state->obj_msg, SYSDB_UUID, NULL);
if (uuid == NULL) {
@@ -626,6 +878,19 @@ static void ipa_id_get_account_info_orig_done(struct tevent_req *subreq)
return;
}
+ if (state->user_groups != NULL) {
+ subreq = ipa_initgr_get_overrides_send(state, state->ev, state->ipa_ctx,
+ state->domain, state->group_cnt,
+ state->user_groups);
+ if (subreq == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "ipa_resolve_user_list_send failed.\n");
+ ret = ENOMEM;
+ goto fail;
+ }
+ tevent_req_set_callback(subreq, ipa_id_get_user_groups_done, req);
+ return;
+ }
+
state->dp_error = DP_ERR_OK;
tevent_req_done(req);
return;
@@ -692,6 +957,19 @@ static void ipa_id_get_account_info_done(struct tevent_req *subreq)
return;
}
+ if (state->user_groups != NULL) {
+ subreq = ipa_initgr_get_overrides_send(state, state->ev, state->ipa_ctx,
+ state->domain, state->group_cnt,
+ state->user_groups);
+ if (subreq == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, "ipa_resolve_user_list_send failed.\n");
+ ret = ENOMEM;
+ goto fail;
+ }
+ tevent_req_set_callback(subreq, ipa_id_get_user_groups_done, req);
+ return;
+ }
+
state->dp_error = DP_ERR_OK;
tevent_req_done(req);
return;
@@ -728,6 +1006,32 @@ fail:
return;
}
+static void ipa_id_get_user_groups_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(subreq,
+ struct tevent_req);
+ struct ipa_id_get_account_info_state *state = tevent_req_data(req,
+ struct ipa_id_get_account_info_state);
+ int dp_error = DP_ERR_FATAL;
+ int ret;
+
+ ret = ipa_initgr_get_overrides_recv(subreq, &dp_error);
+ talloc_zfree(subreq);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, "IPA resolve user groups %d\n", ret);
+ goto fail;
+ }
+
+ state->dp_error = DP_ERR_OK;
+ tevent_req_done(req);
+ return;
+
+fail:
+ state->dp_error = dp_error;
+ tevent_req_error(req, ret);
+ return;
+}
+
static int ipa_id_get_account_info_recv(struct tevent_req *req, int *dp_error)
{
struct ipa_id_get_account_info_state *state = tevent_req_data(req,
--
2.1.0
More information about the sssd-devel
mailing list