|
|
2fc102 |
From 26f41ed62ab74d628764702a1522cedd22b55599 Mon Sep 17 00:00:00 2001
|
|
|
2fc102 |
From: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
2fc102 |
Date: Tue, 1 Oct 2013 17:44:07 +0200
|
|
|
2fc102 |
Subject: [PATCH 10/11] LDAP: Split out a request to search for a user w/o
|
|
|
2fc102 |
saving
|
|
|
2fc102 |
|
|
|
2fc102 |
Related:
|
|
|
2fc102 |
https://fedorahosted.org/sssd/ticket/2077
|
|
|
2fc102 |
|
|
|
2fc102 |
Certain situations require that a user entry is downloaded for further
|
|
|
2fc102 |
inpection, but not saved to the sysdb right away. This patch splits the
|
|
|
2fc102 |
previously monolithic request into one that just downloads the data and
|
|
|
2fc102 |
one that uses the new one to download and save the user.
|
|
|
2fc102 |
---
|
|
|
2fc102 |
src/providers/ldap/sdap_async.h | 16 ++++
|
|
|
2fc102 |
src/providers/ldap/sdap_async_users.c | 162 +++++++++++++++++++++++++++-------
|
|
|
2fc102 |
2 files changed, 146 insertions(+), 32 deletions(-)
|
|
|
2fc102 |
|
|
|
2fc102 |
diff --git a/src/providers/ldap/sdap_async.h b/src/providers/ldap/sdap_async.h
|
|
|
2fc102 |
index c8031c9a9d527a6d808f1ddce096de23850ebfd6..dbf572cdc82b100ba9c26b4853f05db1ba5fa4ed 100644
|
|
|
2fc102 |
--- a/src/providers/ldap/sdap_async.h
|
|
|
2fc102 |
+++ b/src/providers/ldap/sdap_async.h
|
|
|
2fc102 |
@@ -58,6 +58,22 @@ errno_t sdap_connect_host_recv(TALLOC_CTX *mem_ctx,
|
|
|
2fc102 |
struct tevent_req *req,
|
|
|
2fc102 |
struct sdap_handle **_sh);
|
|
|
2fc102 |
|
|
|
2fc102 |
+/* Search users in LDAP, return them as attrs */
|
|
|
2fc102 |
+struct tevent_req *sdap_search_user_send(TALLOC_CTX *memctx,
|
|
|
2fc102 |
+ struct tevent_context *ev,
|
|
|
2fc102 |
+ struct sss_domain_info *dom,
|
|
|
2fc102 |
+ struct sdap_options *opts,
|
|
|
2fc102 |
+ struct sdap_search_base **search_bases,
|
|
|
2fc102 |
+ struct sdap_handle *sh,
|
|
|
2fc102 |
+ const char **attrs,
|
|
|
2fc102 |
+ const char *filter,
|
|
|
2fc102 |
+ int timeout,
|
|
|
2fc102 |
+ bool enumeration);
|
|
|
2fc102 |
+int sdap_search_user_recv(TALLOC_CTX *memctx, struct tevent_req *req,
|
|
|
2fc102 |
+ char **higher_usn, struct sysdb_attrs ***users,
|
|
|
2fc102 |
+ size_t *count);
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+/* Search users in LDAP using the request above, save them to cache */
|
|
|
2fc102 |
struct tevent_req *sdap_get_users_send(TALLOC_CTX *memctx,
|
|
|
2fc102 |
struct tevent_context *ev,
|
|
|
2fc102 |
struct sss_domain_info *dom,
|
|
|
2fc102 |
diff --git a/src/providers/ldap/sdap_async_users.c b/src/providers/ldap/sdap_async_users.c
|
|
|
2fc102 |
index 9cfe217482580d4a11ad4ace2f688f42ca55d7b3..7f0b2eea0b5ee909bcf148236c7fc43863fe8c13 100644
|
|
|
2fc102 |
--- a/src/providers/ldap/sdap_async_users.c
|
|
|
2fc102 |
+++ b/src/providers/ldap/sdap_async_users.c
|
|
|
2fc102 |
@@ -579,15 +579,15 @@ done:
|
|
|
2fc102 |
|
|
|
2fc102 |
/* ==Search-Users-with-filter============================================= */
|
|
|
2fc102 |
|
|
|
2fc102 |
-struct sdap_get_users_state {
|
|
|
2fc102 |
+struct sdap_search_user_state {
|
|
|
2fc102 |
struct tevent_context *ev;
|
|
|
2fc102 |
struct sdap_options *opts;
|
|
|
2fc102 |
struct sdap_handle *sh;
|
|
|
2fc102 |
struct sss_domain_info *dom;
|
|
|
2fc102 |
- struct sysdb_ctx *sysdb;
|
|
|
2fc102 |
+
|
|
|
2fc102 |
const char **attrs;
|
|
|
2fc102 |
const char *base_filter;
|
|
|
2fc102 |
- char *filter;
|
|
|
2fc102 |
+ const char *filter;
|
|
|
2fc102 |
int timeout;
|
|
|
2fc102 |
bool enumeration;
|
|
|
2fc102 |
|
|
|
2fc102 |
@@ -599,33 +599,31 @@ struct sdap_get_users_state {
|
|
|
2fc102 |
struct sdap_search_base **search_bases;
|
|
|
2fc102 |
};
|
|
|
2fc102 |
|
|
|
2fc102 |
-static errno_t sdap_get_users_next_base(struct tevent_req *req);
|
|
|
2fc102 |
-static void sdap_get_users_process(struct tevent_req *subreq);
|
|
|
2fc102 |
+static errno_t sdap_search_user_next_base(struct tevent_req *req);
|
|
|
2fc102 |
+static void sdap_search_user_process(struct tevent_req *subreq);
|
|
|
2fc102 |
|
|
|
2fc102 |
-struct tevent_req *sdap_get_users_send(TALLOC_CTX *memctx,
|
|
|
2fc102 |
- struct tevent_context *ev,
|
|
|
2fc102 |
- struct sss_domain_info *dom,
|
|
|
2fc102 |
- struct sysdb_ctx *sysdb,
|
|
|
2fc102 |
- struct sdap_options *opts,
|
|
|
2fc102 |
- struct sdap_search_base **search_bases,
|
|
|
2fc102 |
- struct sdap_handle *sh,
|
|
|
2fc102 |
- const char **attrs,
|
|
|
2fc102 |
- const char *filter,
|
|
|
2fc102 |
- int timeout,
|
|
|
2fc102 |
- bool enumeration)
|
|
|
2fc102 |
+struct tevent_req *sdap_search_user_send(TALLOC_CTX *memctx,
|
|
|
2fc102 |
+ struct tevent_context *ev,
|
|
|
2fc102 |
+ struct sss_domain_info *dom,
|
|
|
2fc102 |
+ struct sdap_options *opts,
|
|
|
2fc102 |
+ struct sdap_search_base **search_bases,
|
|
|
2fc102 |
+ struct sdap_handle *sh,
|
|
|
2fc102 |
+ const char **attrs,
|
|
|
2fc102 |
+ const char *filter,
|
|
|
2fc102 |
+ int timeout,
|
|
|
2fc102 |
+ bool enumeration)
|
|
|
2fc102 |
{
|
|
|
2fc102 |
errno_t ret;
|
|
|
2fc102 |
struct tevent_req *req;
|
|
|
2fc102 |
- struct sdap_get_users_state *state;
|
|
|
2fc102 |
+ struct sdap_search_user_state *state;
|
|
|
2fc102 |
|
|
|
2fc102 |
- req = tevent_req_create(memctx, &state, struct sdap_get_users_state);
|
|
|
2fc102 |
- if (!req) return NULL;
|
|
|
2fc102 |
+ req = tevent_req_create(memctx, &state, struct sdap_search_user_state);
|
|
|
2fc102 |
+ if (req == NULL) return NULL;
|
|
|
2fc102 |
|
|
|
2fc102 |
state->ev = ev;
|
|
|
2fc102 |
state->opts = opts;
|
|
|
2fc102 |
state->dom = dom;
|
|
|
2fc102 |
state->sh = sh;
|
|
|
2fc102 |
- state->sysdb = sysdb;
|
|
|
2fc102 |
state->attrs = attrs;
|
|
|
2fc102 |
state->higher_usn = NULL;
|
|
|
2fc102 |
state->users = NULL;
|
|
|
2fc102 |
@@ -643,7 +641,7 @@ struct tevent_req *sdap_get_users_send(TALLOC_CTX *memctx,
|
|
|
2fc102 |
goto done;
|
|
|
2fc102 |
}
|
|
|
2fc102 |
|
|
|
2fc102 |
- ret = sdap_get_users_next_base(req);
|
|
|
2fc102 |
+ ret = sdap_search_user_next_base(req);
|
|
|
2fc102 |
|
|
|
2fc102 |
done:
|
|
|
2fc102 |
if (ret != EOK) {
|
|
|
2fc102 |
@@ -654,18 +652,18 @@ done:
|
|
|
2fc102 |
return req;
|
|
|
2fc102 |
}
|
|
|
2fc102 |
|
|
|
2fc102 |
-static errno_t sdap_get_users_next_base(struct tevent_req *req)
|
|
|
2fc102 |
+static errno_t sdap_search_user_next_base(struct tevent_req *req)
|
|
|
2fc102 |
{
|
|
|
2fc102 |
struct tevent_req *subreq;
|
|
|
2fc102 |
- struct sdap_get_users_state *state;
|
|
|
2fc102 |
+ struct sdap_search_user_state *state;
|
|
|
2fc102 |
|
|
|
2fc102 |
- state = tevent_req_data(req, struct sdap_get_users_state);
|
|
|
2fc102 |
+ state = tevent_req_data(req, struct sdap_search_user_state);
|
|
|
2fc102 |
|
|
|
2fc102 |
talloc_zfree(state->filter);
|
|
|
2fc102 |
state->filter = sdap_get_id_specific_filter(state,
|
|
|
2fc102 |
state->base_filter,
|
|
|
2fc102 |
state->search_bases[state->base_iter]->filter);
|
|
|
2fc102 |
- if (!state->filter) {
|
|
|
2fc102 |
+ if (state->filter == NULL) {
|
|
|
2fc102 |
return ENOMEM;
|
|
|
2fc102 |
}
|
|
|
2fc102 |
|
|
|
2fc102 |
@@ -681,20 +679,20 @@ static errno_t sdap_get_users_next_base(struct tevent_req *req)
|
|
|
2fc102 |
state->opts->user_map, SDAP_OPTS_USER,
|
|
|
2fc102 |
state->timeout,
|
|
|
2fc102 |
state->enumeration); /* If we're enumerating, we need paging */
|
|
|
2fc102 |
- if (!subreq) {
|
|
|
2fc102 |
+ if (subreq == NULL) {
|
|
|
2fc102 |
return ENOMEM;
|
|
|
2fc102 |
}
|
|
|
2fc102 |
- tevent_req_set_callback(subreq, sdap_get_users_process, req);
|
|
|
2fc102 |
+ tevent_req_set_callback(subreq, sdap_search_user_process, req);
|
|
|
2fc102 |
|
|
|
2fc102 |
return EOK;
|
|
|
2fc102 |
}
|
|
|
2fc102 |
|
|
|
2fc102 |
-static void sdap_get_users_process(struct tevent_req *subreq)
|
|
|
2fc102 |
+static void sdap_search_user_process(struct tevent_req *subreq)
|
|
|
2fc102 |
{
|
|
|
2fc102 |
struct tevent_req *req = tevent_req_callback_data(subreq,
|
|
|
2fc102 |
struct tevent_req);
|
|
|
2fc102 |
- struct sdap_get_users_state *state = tevent_req_data(req,
|
|
|
2fc102 |
- struct sdap_get_users_state);
|
|
|
2fc102 |
+ struct sdap_search_user_state *state = tevent_req_data(req,
|
|
|
2fc102 |
+ struct sdap_search_user_state);
|
|
|
2fc102 |
int ret;
|
|
|
2fc102 |
size_t count, i;
|
|
|
2fc102 |
struct sysdb_attrs **users;
|
|
|
2fc102 |
@@ -744,7 +742,7 @@ static void sdap_get_users_process(struct tevent_req *subreq)
|
|
|
2fc102 |
state->base_iter++;
|
|
|
2fc102 |
if (state->search_bases[state->base_iter]) {
|
|
|
2fc102 |
/* There are more search bases to try */
|
|
|
2fc102 |
- ret = sdap_get_users_next_base(req);
|
|
|
2fc102 |
+ ret = sdap_search_user_next_base(req);
|
|
|
2fc102 |
if (ret != EOK) {
|
|
|
2fc102 |
tevent_req_error(req, ret);
|
|
|
2fc102 |
}
|
|
|
2fc102 |
@@ -760,12 +758,112 @@ static void sdap_get_users_process(struct tevent_req *subreq)
|
|
|
2fc102 |
return;
|
|
|
2fc102 |
}
|
|
|
2fc102 |
|
|
|
2fc102 |
+ DEBUG(SSSDBG_TRACE_ALL, ("Retrieved total %zu users\n", state->count));
|
|
|
2fc102 |
+ tevent_req_done(req);
|
|
|
2fc102 |
+}
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+int sdap_search_user_recv(TALLOC_CTX *memctx, struct tevent_req *req,
|
|
|
2fc102 |
+ char **higher_usn, struct sysdb_attrs ***users,
|
|
|
2fc102 |
+ size_t *count)
|
|
|
2fc102 |
+{
|
|
|
2fc102 |
+ struct sdap_search_user_state *state = tevent_req_data(req,
|
|
|
2fc102 |
+ struct sdap_search_user_state);
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+ if (higher_usn) {
|
|
|
2fc102 |
+ *higher_usn = talloc_steal(memctx, state->higher_usn);
|
|
|
2fc102 |
+ }
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+ if (users) {
|
|
|
2fc102 |
+ *users = talloc_steal(memctx, state->users);
|
|
|
2fc102 |
+ }
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+ if (count) {
|
|
|
2fc102 |
+ *count = state->count;
|
|
|
2fc102 |
+ }
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+ TEVENT_REQ_RETURN_ON_ERROR(req);
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+ return EOK;
|
|
|
2fc102 |
+}
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+/* ==Search-And-Save-Users-with-filter============================================= */
|
|
|
2fc102 |
+struct sdap_get_users_state {
|
|
|
2fc102 |
+ struct sysdb_ctx *sysdb;
|
|
|
2fc102 |
+ struct sdap_options *opts;
|
|
|
2fc102 |
+ struct sss_domain_info *dom;
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+ char *higher_usn;
|
|
|
2fc102 |
+ struct sysdb_attrs **users;
|
|
|
2fc102 |
+ size_t count;
|
|
|
2fc102 |
+};
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+static void sdap_get_users_done(struct tevent_req *subreq);
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+struct tevent_req *sdap_get_users_send(TALLOC_CTX *memctx,
|
|
|
2fc102 |
+ struct tevent_context *ev,
|
|
|
2fc102 |
+ struct sss_domain_info *dom,
|
|
|
2fc102 |
+ struct sysdb_ctx *sysdb,
|
|
|
2fc102 |
+ struct sdap_options *opts,
|
|
|
2fc102 |
+ struct sdap_search_base **search_bases,
|
|
|
2fc102 |
+ struct sdap_handle *sh,
|
|
|
2fc102 |
+ const char **attrs,
|
|
|
2fc102 |
+ const char *filter,
|
|
|
2fc102 |
+ int timeout,
|
|
|
2fc102 |
+ bool enumeration)
|
|
|
2fc102 |
+{
|
|
|
2fc102 |
+ errno_t ret;
|
|
|
2fc102 |
+ struct tevent_req *req;
|
|
|
2fc102 |
+ struct tevent_req *subreq;
|
|
|
2fc102 |
+ struct sdap_get_users_state *state;
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+ req = tevent_req_create(memctx, &state, struct sdap_get_users_state);
|
|
|
2fc102 |
+ if (!req) return NULL;
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+ state->sysdb = sysdb;
|
|
|
2fc102 |
+ state->opts = opts;
|
|
|
2fc102 |
+ state->dom = dom;
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+ subreq = sdap_search_user_send(state, ev, dom, opts, search_bases,
|
|
|
2fc102 |
+ sh, attrs, filter, timeout, enumeration);
|
|
|
2fc102 |
+ if (subreq == NULL) {
|
|
|
2fc102 |
+ ret = ENOMEM;
|
|
|
2fc102 |
+ goto done;
|
|
|
2fc102 |
+ }
|
|
|
2fc102 |
+ tevent_req_set_callback(subreq, sdap_get_users_done, req);
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+ ret = EOK;
|
|
|
2fc102 |
+done:
|
|
|
2fc102 |
+ if (ret != EOK) {
|
|
|
2fc102 |
+ tevent_req_error(req, ret);
|
|
|
2fc102 |
+ tevent_req_post(req, ev);
|
|
|
2fc102 |
+ }
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+ return req;
|
|
|
2fc102 |
+}
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+static void sdap_get_users_done(struct tevent_req *subreq)
|
|
|
2fc102 |
+{
|
|
|
2fc102 |
+ struct tevent_req *req = tevent_req_callback_data(subreq,
|
|
|
2fc102 |
+ struct tevent_req);
|
|
|
2fc102 |
+ struct sdap_get_users_state *state = tevent_req_data(req,
|
|
|
2fc102 |
+ struct sdap_get_users_state);
|
|
|
2fc102 |
+ int ret;
|
|
|
2fc102 |
+
|
|
|
2fc102 |
+ ret = sdap_search_user_recv(state, subreq, &state->higher_usn,
|
|
|
2fc102 |
+ &state->users, &state->count);
|
|
|
2fc102 |
+ if (ret) {
|
|
|
2fc102 |
+ DEBUG(SSSDBG_OP_FAILURE, ("Failed to retrieve users\n"));
|
|
|
2fc102 |
+ tevent_req_error(req, ret);
|
|
|
2fc102 |
+ return;
|
|
|
2fc102 |
+ }
|
|
|
2fc102 |
+
|
|
|
2fc102 |
ret = sdap_save_users(state, state->sysdb,
|
|
|
2fc102 |
state->dom, state->opts,
|
|
|
2fc102 |
state->users, state->count,
|
|
|
2fc102 |
&state->higher_usn);
|
|
|
2fc102 |
if (ret) {
|
|
|
2fc102 |
- DEBUG(2, ("Failed to store users.\n"));
|
|
|
2fc102 |
+ DEBUG(SSSDBG_OP_FAILURE, ("Failed to store users.\n"));
|
|
|
2fc102 |
tevent_req_error(req, ret);
|
|
|
2fc102 |
return;
|
|
|
2fc102 |
}
|
|
|
2fc102 |
--
|
|
|
2fc102 |
1.8.4.2
|
|
|
2fc102 |
|