From fceab48ac589473216067e40d8577e19a02d3b45 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Mon, 4 May 2015 16:27:06 +0200
Subject: [PATCH 08/13] LDAP: Add sdap_get_and_parse_generic_send
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Related:
https://fedorahosted.org/sssd/ticket/2553
So far we had a simple sdap_get_generic_send() request that uses the
right defaults around the low-level sdap_get_generic_ext_send() request
and calls the parser.
This patch adds also sdap_get_and_parse_generic_send() that exposes all
options that sdap_get_generic_ext_send() offers but also calls the
parser.
In this patch the function is not used at all.
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
---
src/providers/ldap/sdap_async.c | 185 ++++++++++++++++++++++++++++------------
src/providers/ldap/sdap_async.h | 22 +++++
2 files changed, 154 insertions(+), 53 deletions(-)
diff --git a/src/providers/ldap/sdap_async.c b/src/providers/ldap/sdap_async.c
index 5263c250b8a15a98e685ca81e636def27ea05894..c5be8561a197c96f62bb2582a4d30c28de71f580 100644
--- a/src/providers/ldap/sdap_async.c
+++ b/src/providers/ldap/sdap_async.c
@@ -1656,9 +1656,8 @@ static void generic_ext_search_handler(struct tevent_req *subreq,
tevent_req_done(req);
}
-
-/* ==Generic Search============================================ */
-struct sdap_get_generic_state {
+/* ==Generic Search exposing all options======================= */
+struct sdap_get_and_parse_generic_state {
struct sdap_attr_map *map;
int map_num_attrs;
@@ -1666,10 +1665,119 @@ struct sdap_get_generic_state {
struct sdap_options *opts;
};
+static void sdap_get_and_parse_generic_done(struct tevent_req *subreq);
+static errno_t sdap_get_and_parse_generic_parse_entry(struct sdap_handle *sh,
+ struct sdap_msg *msg,
+ void *pvt);
+
+struct tevent_req *sdap_get_and_parse_generic_send(TALLOC_CTX *memctx,
+ struct tevent_context *ev,
+ struct sdap_options *opts,
+ struct sdap_handle *sh,
+ const char *search_base,
+ int scope,
+ const char *filter,
+ const char **attrs,
+ struct sdap_attr_map *map,
+ int map_num_attrs,
+ int attrsonly,
+ LDAPControl **serverctrls,
+ LDAPControl **clientctrls,
+ int sizelimit,
+ int timeout,
+ bool allow_paging)
+{
+ struct tevent_req *req = NULL;
+ struct tevent_req *subreq = NULL;
+ struct sdap_get_and_parse_generic_state *state = NULL;
+
+ req = tevent_req_create(memctx, &state,
+ struct sdap_get_and_parse_generic_state);
+ if (!req) return NULL;
+
+ state->map = map;
+ state->map_num_attrs = map_num_attrs;
+ state->opts = opts;
+
+ subreq = sdap_get_generic_ext_send(state, ev, opts, sh, search_base,
+ scope, filter, attrs, false, NULL,
+ NULL, sizelimit, timeout, allow_paging,
+ sdap_get_and_parse_generic_parse_entry, state);
+ if (!subreq) {
+ talloc_zfree(req);
+ return NULL;
+ }
+ tevent_req_set_callback(subreq, sdap_get_and_parse_generic_done, req);
+
+ return req;
+}
+
+static errno_t sdap_get_and_parse_generic_parse_entry(struct sdap_handle *sh,
+ struct sdap_msg *msg,
+ void *pvt)
+{
+ errno_t ret;
+ struct sysdb_attrs *attrs;
+ struct sdap_get_and_parse_generic_state *state =
+ talloc_get_type(pvt, struct sdap_get_and_parse_generic_state);
+
+ bool disable_range_rtrvl = dp_opt_get_bool(state->opts->basic,
+ SDAP_DISABLE_RANGE_RETRIEVAL);
+
+ ret = sdap_parse_entry(state, sh, msg,
+ state->map, state->map_num_attrs,
+ &attrs, disable_range_rtrvl);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_MINOR_FAILURE,
+ "sdap_parse_entry failed [%d]: %s\n", ret, strerror(ret));
+ return ret;
+ }
+
+ ret = add_to_reply(state, &state->sreply, attrs);
+ if (ret != EOK) {
+ talloc_free(attrs);
+ DEBUG(SSSDBG_CRIT_FAILURE, "add_to_reply failed.\n");
+ return ret;
+ }
+
+ /* add_to_reply steals attrs, no need to free them here */
+ return EOK;
+}
+
+static void sdap_get_and_parse_generic_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(subreq,
+ struct tevent_req);
+ struct sdap_get_and_parse_generic_state *state =
+ tevent_req_data(req, struct sdap_get_and_parse_generic_state);
+
+ return generic_ext_search_handler(subreq, state->opts);
+}
+
+int sdap_get_and_parse_generic_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ size_t *reply_count,
+ struct sysdb_attrs ***reply)
+{
+ struct sdap_get_and_parse_generic_state *state = tevent_req_data(req,
+ struct sdap_get_and_parse_generic_state);
+
+ TEVENT_REQ_RETURN_ON_ERROR(req);
+
+ *reply_count = state->sreply.reply_count;
+ *reply = talloc_steal(mem_ctx, state->sreply.reply);
+
+ return EOK;
+}
+
+
+/* ==Simple generic search============================================== */
+struct sdap_get_generic_state {
+ size_t reply_count;
+ struct sysdb_attrs **reply;
+};
+
static void sdap_get_generic_done(struct tevent_req *subreq);
-static errno_t sdap_get_generic_parse_entry(struct sdap_handle *sh,
- struct sdap_msg *msg,
- void *pvt);
struct tevent_req *sdap_get_generic_send(TALLOC_CTX *memctx,
struct tevent_context *ev,
@@ -1691,16 +1799,12 @@ struct tevent_req *sdap_get_generic_send(TALLOC_CTX *memctx,
req = tevent_req_create(memctx, &state, struct sdap_get_generic_state);
if (!req) return NULL;
- state->map = map;
- state->map_num_attrs = map_num_attrs;
- state->opts = opts;
-
- subreq = sdap_get_generic_ext_send(state, ev, opts, sh, search_base,
- scope, filter, attrs, false, NULL,
- NULL, 0, timeout, allow_paging,
- sdap_get_generic_parse_entry, state);
- if (!subreq) {
- talloc_zfree(req);
+ subreq = sdap_get_and_parse_generic_send(memctx, ev, opts, sh, search_base,
+ scope, filter, attrs,
+ map, map_num_attrs,
+ false, NULL, NULL, 0, timeout,
+ allow_paging);
+ if (subreq == NULL) {
return NULL;
}
tevent_req_set_callback(subreq, sdap_get_generic_done, req);
@@ -1708,46 +1812,21 @@ struct tevent_req *sdap_get_generic_send(TALLOC_CTX *memctx,
return req;
}
-static errno_t sdap_get_generic_parse_entry(struct sdap_handle *sh,
- struct sdap_msg *msg,
- void *pvt)
-{
- errno_t ret;
- struct sysdb_attrs *attrs;
- struct sdap_get_generic_state *state =
- talloc_get_type(pvt, struct sdap_get_generic_state);
-
- bool disable_range_rtrvl = dp_opt_get_bool(state->opts->basic,
- SDAP_DISABLE_RANGE_RETRIEVAL);
-
- ret = sdap_parse_entry(state, sh, msg,
- state->map, state->map_num_attrs,
- &attrs, disable_range_rtrvl);
- if (ret != EOK) {
- DEBUG(SSSDBG_MINOR_FAILURE,
- "sdap_parse_entry failed [%d]: %s\n", ret, strerror(ret));
- return ret;
- }
-
- ret = add_to_reply(state, &state->sreply, attrs);
- if (ret != EOK) {
- talloc_free(attrs);
- DEBUG(SSSDBG_CRIT_FAILURE, "add_to_reply failed.\n");
- return ret;
- }
-
- /* add_to_reply steals attrs, no need to free them here */
- return EOK;
-}
-
static void sdap_get_generic_done(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(subreq,
struct tevent_req);
struct sdap_get_generic_state *state =
tevent_req_data(req, struct sdap_get_generic_state);
+ errno_t ret;
- return generic_ext_search_handler(subreq, state->opts);
+ ret = sdap_get_and_parse_generic_recv(subreq, state,
+ &state->reply_count, &state->reply);
+ if (ret != EOK) {
+ tevent_req_error(req, ret);
+ return;
+ }
+ tevent_req_done(req);
}
int sdap_get_generic_recv(struct tevent_req *req,
@@ -1755,13 +1834,13 @@ int sdap_get_generic_recv(struct tevent_req *req,
size_t *reply_count,
struct sysdb_attrs ***reply)
{
- struct sdap_get_generic_state *state = tevent_req_data(req,
- struct sdap_get_generic_state);
+ struct sdap_get_generic_state *state =
+ tevent_req_data(req, struct sdap_get_generic_state);
TEVENT_REQ_RETURN_ON_ERROR(req);
- *reply_count = state->sreply.reply_count;
- *reply = talloc_steal(mem_ctx, state->sreply.reply);
+ *reply_count = state->reply_count;
+ *reply = talloc_steal(mem_ctx, state->reply);
return EOK;
}
diff --git a/src/providers/ldap/sdap_async.h b/src/providers/ldap/sdap_async.h
index b5db64d7fa3c852fba60e07db19e823e818d29f3..b23dfc313905d01caedd1eace6bcb525481b9ebe 100644
--- a/src/providers/ldap/sdap_async.h
+++ b/src/providers/ldap/sdap_async.h
@@ -181,6 +181,28 @@ int sdap_cli_connect_recv(struct tevent_req *req,
struct sdap_handle **gsh,
struct sdap_server_opts **srv_opts);
+/* Exposes all options of generic send while allowing to parse by map */
+struct tevent_req *sdap_get_and_parse_generic_send(TALLOC_CTX *memctx,
+ struct tevent_context *ev,
+ struct sdap_options *opts,
+ struct sdap_handle *sh,
+ const char *search_base,
+ int scope,
+ const char *filter,
+ const char **attrs,
+ struct sdap_attr_map *map,
+ int map_num_attrs,
+ int attrsonly,
+ LDAPControl **serverctrls,
+ LDAPControl **clientctrls,
+ int sizelimit,
+ int timeout,
+ bool allow_paging);
+int sdap_get_and_parse_generic_recv(struct tevent_req *req,
+ TALLOC_CTX *mem_ctx,
+ size_t *reply_count,
+ struct sysdb_attrs ***reply);
+
struct tevent_req *sdap_get_generic_send(TALLOC_CTX *memctx,
struct tevent_context *ev,
struct sdap_options *opts,
--
2.4.3