summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2010-03-03 16:22:46 -0500
committerStephen Gallagher <sgallagh@redhat.com>2010-04-12 09:22:14 -0400
commit8a6449480e4be898248c1d35bbf5c24d91503e4e (patch)
treebced6561c7fce796e653d6b88a3da3a16322ddc6 /src/tools
parent3b3dc1a8ad19100951d19abe4038791f01faa0b7 (diff)
downloadsssd-8a6449480e4be898248c1d35bbf5c24d91503e4e.tar.gz
sssd-8a6449480e4be898248c1d35bbf5c24d91503e4e.tar.xz
sssd-8a6449480e4be898248c1d35bbf5c24d91503e4e.zip
sysdb: convert sysdb_search_groups
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/sss_groupshow.c234
1 files changed, 59 insertions, 175 deletions
diff --git a/src/tools/sss_groupshow.c b/src/tools/sss_groupshow.c
index 20f1a7654..b6fb1a152 100644
--- a/src/tools/sss_groupshow.c
+++ b/src/tools/sss_groupshow.c
@@ -275,7 +275,6 @@ struct group_show_state {
};
static void group_show_recurse_done(struct tevent_req *subreq);
-static void group_show_trim_done(struct tevent_req *subreq);
struct tevent_req *group_show_recurse_send(TALLOC_CTX *,
struct group_show_state *,
@@ -285,16 +284,12 @@ struct tevent_req *group_show_recurse_send(TALLOC_CTX *,
static int group_show_recurse_recv(TALLOC_CTX *, struct tevent_req *,
struct group_info ***);
-static struct tevent_req *group_show_trim_memberof_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_ctx *sysdb,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- const char *name,
- const char **memberofs);
-static int group_show_trim_memberof_recv(TALLOC_CTX *mem_ctx,
- struct tevent_req *req,
- const char ***direct);
+static int group_show_trim_memberof(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ struct sss_domain_info *domain,
+ const char *name,
+ const char **memberofs,
+ const char ***_direct);
struct tevent_req *group_show_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
@@ -370,17 +365,11 @@ struct tevent_req *group_show_send(TALLOC_CTX *mem_ctx,
}
/* if not recursive, only show the direct parent */
- subreq = group_show_trim_memberof_send(state, state->ev,
- state->sysdb, state->handle,
- state->domain, state->root->name,
- state->root->memberofs);
- if (!subreq) {
- ret = ENOMEM;
- goto done;
- }
- tevent_req_set_callback(subreq, group_show_trim_done, req);
-
- return req;
+ ret = group_show_trim_memberof(state, state->sysdb,
+ state->domain, state->root->name,
+ state->root->memberofs,
+ &state->root->memberofs);
+ goto done;
}
if (group_members == NULL) {
@@ -410,26 +399,6 @@ done:
return req;
}
-static void group_show_trim_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct group_show_state *state = tevent_req_data(req,
- struct group_show_state);
- int ret;
-
- ret = group_show_trim_memberof_recv(state->root, subreq,
- &state->root->memberofs);
- talloc_zfree(subreq);
- if (ret) {
- tevent_req_error(req, ret);
- return;
- }
-
- tevent_req_done(req);
- return;
-}
-
static void group_show_recurse_done(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(subreq,
@@ -465,156 +434,71 @@ static int group_show_recv(TALLOC_CTX *mem_ctx,
}
/*=========Nonrecursive search should only show direct parent========== */
-struct group_show_trim_state {
- const char *name;
- struct ldb_dn *dn;
- const char **all;
- int current;
-
- const char **direct;
- int ndirect;
-
- struct tevent_context *ev;
- struct sysdb_ctx *sysdb;
- struct sysdb_handle *handle;
- struct sss_domain_info *domain;
-};
-
-static int group_show_trim_memberof_next(struct tevent_req *req);
-static void group_show_trim_memberof_done(struct tevent_req *subreq);
-
-static struct tevent_req *group_show_trim_memberof_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- struct sysdb_ctx *sysdb,
- struct sysdb_handle *handle,
- struct sss_domain_info *domain,
- const char *name,
- const char **memberofs)
+static int group_show_trim_memberof(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ struct sss_domain_info *domain,
+ const char *name,
+ const char **memberofs,
+ const char ***_direct)
{
- struct tevent_req *req = NULL;
- struct group_show_trim_state *state;
+ struct ldb_dn *dn;
+ char *filter;
+ struct ldb_message **msgs;
+ size_t count;
+ const char **direct = NULL;
+ int ndirect = 0;
int ret;
+ int i;
- req = tevent_req_create(mem_ctx, &state, struct group_show_trim_state);
- if (req == NULL) {
- return NULL;
- }
- state->ev = ev;
- state->sysdb = sysdb;
- state->handle = handle;
- state->domain = domain;
- state->name = name;
- state->all = memberofs;
-
- state->dn = sysdb_group_dn(state->sysdb, state,
- state->domain->name,
- state->name);
- if (!state->dn) {
- talloc_zfree(req);
- return NULL;
- }
-
- ret = group_show_trim_memberof_next(req);
- if (ret) {
- talloc_zfree(req);
- return NULL;
- }
-
- return req;
-}
-
-static int group_show_trim_memberof_next(struct tevent_req *req)
-{
- const char *filter;
- struct tevent_req *subreq = NULL;
- struct group_show_trim_state *state = tevent_req_data(req,
- struct group_show_trim_state);
-
- filter = talloc_asprintf(req, "(&(%s=%s)(%s=%s))",
- SYSDB_NAME, state->all[state->current],
- SYSDB_MEMBER, ldb_dn_get_linearized(state->dn));
- if (!filter) {
- return ENOMEM;
- }
-
- subreq = sysdb_search_groups_send(state, state->ev, state->sysdb,
- state->handle, state->domain,
- filter, NULL);
- if (!subreq) {
+ dn = sysdb_group_dn(sysdb, mem_ctx, domain->name, name);
+ if (!dn) {
return ENOMEM;
}
- tevent_req_set_callback(subreq, group_show_trim_memberof_done, req);
- return EOK;
-}
+ for (i = 0; memberofs[i]; i++) {
-static void group_show_trim_memberof_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(subreq,
- struct tevent_req);
- struct group_show_trim_state *state = tevent_req_data(req,
- struct group_show_trim_state);
- int ret;
- struct ldb_message **msgs;
- size_t count = 0;
- const char *name;
-
- ret = sysdb_search_groups_recv(subreq, state, &count, &msgs);
- talloc_zfree(subreq);
- /* ENOENT is OK, the group is just not a direct parent */
- if (ret != EOK && ret != ENOENT) {
- tevent_req_error(req, ret);
- return;
- }
-
- if (count > 0) {
- name = ldb_msg_find_attr_as_string(msgs[0],
- SYSDB_NAME, NULL);
- if (!name) {
- DEBUG(2, ("Entry %s has no Name Attribute ?!?\n",
- ldb_dn_get_linearized(msgs[0]->dn)));
- tevent_req_error(req, EFAULT);
- return;
+ filter = talloc_asprintf(mem_ctx, "(&(%s=%s)(%s=%s))",
+ SYSDB_NAME, memberofs[i],
+ SYSDB_MEMBER, ldb_dn_get_linearized(dn));
+ if (!filter) {
+ return ENOMEM;
}
- state->direct = talloc_realloc(state, state->direct,
- const char *, state->ndirect+2);
- if (!state->direct) {
- tevent_req_error(req, ENOMEM);
+ ret = sysdb_search_groups(mem_ctx, sysdb,
+ domain, filter, NULL,
+ &count, &msgs);
+ /* ENOENT is OK, the group is just not a direct parent */
+ if (ret != EOK && ret != ENOENT) {
+ return ret;
}
- state->direct[state->ndirect] = talloc_strdup(state->direct, name);
- if (!state->direct[state->ndirect]) {
- tevent_req_error(req, ENOMEM);
- }
+ if (count > 0) {
+ name = ldb_msg_find_attr_as_string(msgs[0],
+ SYSDB_NAME, NULL);
+ if (!name) {
+ DEBUG(2, ("Entry %s has no Name Attribute ?!?\n",
+ ldb_dn_get_linearized(msgs[0]->dn)));
+ return EFAULT;
+ }
- state->direct[state->ndirect+1] = NULL;
- state->ndirect++;
- }
+ direct = talloc_realloc(mem_ctx, direct,
+ const char *, ndirect + 2);
+ if (!direct) {
+ return ENOMEM;
+ }
- state->current++;
- if (state->all[state->current] != NULL) {
- ret = group_show_trim_memberof_next(req);
- if (ret != EOK) {
- tevent_req_error(req, ret);
+ direct[ndirect] = talloc_strdup(direct, name);
+ if (!direct[ndirect]) {
+ return ENOMEM;
+ }
+
+ direct[ndirect + 1] = NULL;
+ ndirect++;
}
- return;
}
- tevent_req_done(req);
-}
-
-static int group_show_trim_memberof_recv(TALLOC_CTX *mem_ctx,
- struct tevent_req *req,
- const char ***direct)
-{
- struct group_show_trim_state *state = tevent_req_data(req,
- struct group_show_trim_state);
-
- TEVENT_REQ_RETURN_ON_ERROR(req);
- *direct = talloc_move(mem_ctx, &state->direct);
-
+ *_direct = direct;
return EOK;
}