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