diff options
author | Simo Sorce <ssorce@redhat.com> | 2010-03-03 16:22:46 -0500 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2010-04-12 09:22:14 -0400 |
commit | 8a6449480e4be898248c1d35bbf5c24d91503e4e (patch) | |
tree | bced6561c7fce796e653d6b88a3da3a16322ddc6 /src/db | |
parent | 3b3dc1a8ad19100951d19abe4038791f01faa0b7 (diff) | |
download | sssd-8a6449480e4be898248c1d35bbf5c24d91503e4e.tar.gz sssd-8a6449480e4be898248c1d35bbf5c24d91503e4e.tar.xz sssd-8a6449480e4be898248c1d35bbf5c24d91503e4e.zip |
sysdb: convert sysdb_search_groups
Diffstat (limited to 'src/db')
-rw-r--r-- | src/db/sysdb.h | 16 | ||||
-rw-r--r-- | src/db/sysdb_ops.c | 121 |
2 files changed, 35 insertions, 102 deletions
diff --git a/src/db/sysdb.h b/src/db/sysdb.h index a0714b86a..b39d26c99 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -570,15 +570,13 @@ int sysdb_delete_user(TALLOC_CTX *mem_ctx, struct sss_domain_info *domain, const char *name, uid_t uid); -struct tevent_req *sysdb_search_groups_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_ctx *sysdb, - struct sysdb_handle *handle, - struct sss_domain_info *domain, - const char *sub_filter, - const char **attrs); -int sysdb_search_groups_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, - size_t *msgs_count, struct ldb_message ***msgs); +int sysdb_search_groups(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + struct sss_domain_info *domain, + const char *sub_filter, + const char **attrs, + size_t *msgs_count, + struct ldb_message ***msgs); int sysdb_delete_group(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb, diff --git a/src/db/sysdb_ops.c b/src/db/sysdb_ops.c index 1a816dca3..19427d443 100644 --- a/src/db/sysdb_ops.c +++ b/src/db/sysdb_ops.c @@ -1857,120 +1857,55 @@ fail: /* =Search-Groups-with-Custom-Filter===================================== */ -struct sysdb_search_groups_state { - struct tevent_context *ev; - struct sysdb_handle *handle; - struct sss_domain_info *domain; - const char *sub_filter; - const char **attrs; - - struct ldb_message **msgs; - size_t msgs_count; -}; - -static void sysdb_search_groups_check_handle(struct tevent_req *subreq); - -struct tevent_req *sysdb_search_groups_send(TALLOC_CTX *mem_ctx, - struct tevent_context *ev, - struct sysdb_ctx *sysdb, - struct sysdb_handle *handle, - struct sss_domain_info *domain, - const char *sub_filter, - const char **attrs) -{ - struct tevent_req *req, *subreq; - struct sysdb_search_groups_state *state; - int ret; - - req = tevent_req_create(mem_ctx, &state, struct sysdb_search_groups_state); - if (req == NULL) { - DEBUG(1, ("tevent_req_create failed.\n")); - return NULL; - } - - state->ev = ev; - state->handle = handle; - state->domain = domain; - state->sub_filter = sub_filter; - state->attrs = attrs; - - state->msgs_count = 0; - state->msgs = NULL; - - subreq = sysdb_check_handle_send(state, ev, sysdb, handle); - if (!subreq) { - DEBUG(1, ("sysdb_check_handle_send failed.\n")); - ret = ENOMEM; - goto fail; - } - tevent_req_set_callback(subreq, sysdb_search_groups_check_handle, req); - - return req; - -fail: - tevent_req_error(req, ret); - tevent_req_post(req, ev); - return req; -} - -static void sysdb_search_groups_check_handle(struct tevent_req *subreq) +int sysdb_search_groups(TALLOC_CTX *mem_ctx, + struct sysdb_ctx *sysdb, + struct sss_domain_info *domain, + const char *sub_filter, + const char **attrs, + size_t *msgs_count, + struct ldb_message ***msgs) { - struct tevent_req *req = tevent_req_callback_data(subreq, - struct tevent_req); - struct sysdb_search_groups_state *state = tevent_req_data(req, - struct sysdb_search_groups_state); + TALLOC_CTX *tmpctx; struct ldb_dn *basedn; char *filter; int ret; - ret = sysdb_check_handle_recv(subreq, state, &state->handle); - talloc_zfree(subreq); - if (ret != EOK) { - tevent_req_error(req, ret); - return; + tmpctx = talloc_new(mem_ctx); + if (!tmpctx) { + return ENOMEM; } - basedn = ldb_dn_new_fmt(state, state->handle->ctx->ldb, - SYSDB_TMPL_GROUP_BASE, state->domain->name); + basedn = ldb_dn_new_fmt(tmpctx, sysdb->ldb, + SYSDB_TMPL_GROUP_BASE, domain->name); if (!basedn) { DEBUG(2, ("Failed to build base dn\n")); - tevent_req_error(req, ENOMEM); - return; + ret = ENOMEM; + goto fail; } - filter = talloc_asprintf(state, "(&(%s)%s)", - SYSDB_GC, state->sub_filter); + filter = talloc_asprintf(tmpctx, "(&(%s)%s)", SYSDB_GC, sub_filter); if (!filter) { DEBUG(2, ("Failed to build filter\n")); - tevent_req_error(req, ENOMEM); - return; + ret = ENOMEM; + goto fail; } DEBUG(6, ("Search groups with filter: %s\n", filter)); - ret = sysdb_search_entry(state, state->handle->ctx, basedn, - LDB_SCOPE_SUBTREE, filter, state->attrs, - &state->msgs_count, &state->msgs); + ret = sysdb_search_entry(mem_ctx, sysdb, basedn, + LDB_SCOPE_SUBTREE, filter, attrs, + msgs_count, msgs); if (ret) { - tevent_req_error(req, ret); - return; + goto fail; } - tevent_req_done(req); -} - -int sysdb_search_groups_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, - size_t *msgs_count, struct ldb_message ***msgs) -{ - struct sysdb_search_groups_state *state = tevent_req_data(req, - struct sysdb_search_groups_state); - - TEVENT_REQ_RETURN_ON_ERROR(req); - - *msgs_count = state->msgs_count; - *msgs = talloc_move(mem_ctx, &state->msgs); - + talloc_zfree(tmpctx); return EOK; + +fail: + DEBUG(6, ("Error: %d (%s)\n", ret, strerror(ret))); + talloc_zfree(tmpctx); + return ret; } /* =Delete-Group-by-Name-OR-gid=========================================== */ |