|
|
ecf709 |
From 992a6410a3100cc64f9f2ea674fda9151fa5d474 Mon Sep 17 00:00:00 2001
|
|
|
ecf709 |
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
|
|
|
ecf709 |
Date: Mon, 29 May 2017 14:58:33 +0200
|
|
|
ecf709 |
Subject: [PATCH 168/169] CACHE_REQ: Simplify _search_ncache_filter()
|
|
|
ecf709 |
MIME-Version: 1.0
|
|
|
ecf709 |
Content-Type: text/plain; charset=UTF-8
|
|
|
ecf709 |
Content-Transfer-Encoding: 8bit
|
|
|
ecf709 |
|
|
|
ecf709 |
Let's make the result and input/output argument for
|
|
|
ecf709 |
_search_ncache_filter() and free it inside the function whenever it's
|
|
|
ecf709 |
needed instead of leaving this responsibility for the caller.
|
|
|
ecf709 |
|
|
|
ecf709 |
Related:
|
|
|
ecf709 |
https://pagure.io/SSSD/sssd/issue/3362
|
|
|
ecf709 |
|
|
|
ecf709 |
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
|
|
|
ecf709 |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
ecf709 |
(cherry picked from commit c8193b1602cf44740b59f5dfcdc5330508c0c365)
|
|
|
ecf709 |
---
|
|
|
ecf709 |
src/responder/common/cache_req/cache_req_search.c | 27 ++++++-----------------
|
|
|
ecf709 |
1 file changed, 7 insertions(+), 20 deletions(-)
|
|
|
ecf709 |
|
|
|
ecf709 |
diff --git a/src/responder/common/cache_req/cache_req_search.c b/src/responder/common/cache_req/cache_req_search.c
|
|
|
ecf709 |
index 70448a7639bc9f98d380b8edce9d130adfa0ceb2..d3aaa7542ddfd28716fbf9cdcedfeadb649dbaa0 100644
|
|
|
ecf709 |
--- a/src/responder/common/cache_req/cache_req_search.c
|
|
|
ecf709 |
+++ b/src/responder/common/cache_req/cache_req_search.c
|
|
|
ecf709 |
@@ -86,7 +86,6 @@ static void cache_req_search_ncache_add(struct cache_req *cr)
|
|
|
ecf709 |
|
|
|
ecf709 |
static errno_t cache_req_search_ncache_filter(TALLOC_CTX *mem_ctx,
|
|
|
ecf709 |
struct cache_req *cr,
|
|
|
ecf709 |
- struct ldb_result *result,
|
|
|
ecf709 |
struct ldb_result **_result)
|
|
|
ecf709 |
{
|
|
|
ecf709 |
TALLOC_CTX *tmp_ctx;
|
|
|
ecf709 |
@@ -106,8 +105,6 @@ static errno_t cache_req_search_ncache_filter(TALLOC_CTX *mem_ctx,
|
|
|
ecf709 |
"This request type does not support filtering "
|
|
|
ecf709 |
"result by negative cache\n");
|
|
|
ecf709 |
|
|
|
ecf709 |
- *_result = talloc_steal(mem_ctx, result);
|
|
|
ecf709 |
-
|
|
|
ecf709 |
ret = EOK;
|
|
|
ecf709 |
goto done;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
@@ -115,11 +112,11 @@ static errno_t cache_req_search_ncache_filter(TALLOC_CTX *mem_ctx,
|
|
|
ecf709 |
CACHE_REQ_DEBUG(SSSDBG_TRACE_FUNC, cr,
|
|
|
ecf709 |
"Filtering out results by negative cache\n");
|
|
|
ecf709 |
|
|
|
ecf709 |
- msgs = talloc_zero_array(tmp_ctx, struct ldb_message *, result->count);
|
|
|
ecf709 |
+ msgs = talloc_zero_array(tmp_ctx, struct ldb_message *, (*_result)->count);
|
|
|
ecf709 |
msg_count = 0;
|
|
|
ecf709 |
|
|
|
ecf709 |
- for (size_t i = 0; i < result->count; i++) {
|
|
|
ecf709 |
- name = sss_get_name_from_msg(cr->domain, result->msgs[i]);
|
|
|
ecf709 |
+ for (size_t i = 0; i < (*_result)->count; i++) {
|
|
|
ecf709 |
+ name = sss_get_name_from_msg(cr->domain, (*_result)->msgs[i]);
|
|
|
ecf709 |
if (name == NULL) {
|
|
|
ecf709 |
CACHE_REQ_DEBUG(SSSDBG_CRIT_FAILURE, cr,
|
|
|
ecf709 |
"sss_get_name_from_msg() returned NULL, which should never "
|
|
|
ecf709 |
@@ -141,7 +138,7 @@ static errno_t cache_req_search_ncache_filter(TALLOC_CTX *mem_ctx,
|
|
|
ecf709 |
goto done;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
|
|
|
ecf709 |
- msgs[msg_count] = talloc_steal(msgs, result->msgs[i]);
|
|
|
ecf709 |
+ msgs[msg_count] = talloc_steal(msgs, (*_result)->msgs[i]);
|
|
|
ecf709 |
msg_count++;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
|
|
|
ecf709 |
@@ -157,6 +154,7 @@ static errno_t cache_req_search_ncache_filter(TALLOC_CTX *mem_ctx,
|
|
|
ecf709 |
goto done;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
|
|
|
ecf709 |
+ talloc_zfree(*_result);
|
|
|
ecf709 |
*_result = talloc_steal(mem_ctx, filtered_result);
|
|
|
ecf709 |
ret = EOK;
|
|
|
ecf709 |
|
|
|
ecf709 |
@@ -419,10 +417,8 @@ static void cache_req_search_oob_done(struct tevent_req *subreq)
|
|
|
ecf709 |
|
|
|
ecf709 |
static void cache_req_search_done(struct tevent_req *subreq)
|
|
|
ecf709 |
{
|
|
|
ecf709 |
- TALLOC_CTX *tmp_ctx;
|
|
|
ecf709 |
struct cache_req_search_state *state;
|
|
|
ecf709 |
struct tevent_req *req;
|
|
|
ecf709 |
- struct ldb_result *result = NULL;
|
|
|
ecf709 |
errno_t ret;
|
|
|
ecf709 |
|
|
|
ecf709 |
req = tevent_req_callback_data(subreq, struct tevent_req);
|
|
|
ecf709 |
@@ -431,14 +427,8 @@ static void cache_req_search_done(struct tevent_req *subreq)
|
|
|
ecf709 |
state->dp_success = state->cr->plugin->dp_recv_fn(subreq, state->cr);
|
|
|
ecf709 |
talloc_zfree(subreq);
|
|
|
ecf709 |
|
|
|
ecf709 |
- tmp_ctx = talloc_new(NULL);
|
|
|
ecf709 |
- if (tmp_ctx == NULL) {
|
|
|
ecf709 |
- ret = ENOMEM;
|
|
|
ecf709 |
- goto done;
|
|
|
ecf709 |
- }
|
|
|
ecf709 |
-
|
|
|
ecf709 |
/* Get result from cache again. */
|
|
|
ecf709 |
- ret = cache_req_search_cache(tmp_ctx, state->cr, &result);
|
|
|
ecf709 |
+ ret = cache_req_search_cache(state, state->cr, &state->result);
|
|
|
ecf709 |
if (ret != EOK) {
|
|
|
ecf709 |
if (ret == ENOENT) {
|
|
|
ecf709 |
/* Only store entry in negative cache if DP request succeeded
|
|
|
ecf709 |
@@ -451,8 +441,7 @@ static void cache_req_search_done(struct tevent_req *subreq)
|
|
|
ecf709 |
}
|
|
|
ecf709 |
|
|
|
ecf709 |
/* ret == EOK */
|
|
|
ecf709 |
- ret = cache_req_search_ncache_filter(state, state->cr, result,
|
|
|
ecf709 |
- &state->result);
|
|
|
ecf709 |
+ ret = cache_req_search_ncache_filter(state, state->cr, &state->result);
|
|
|
ecf709 |
if (ret != EOK) {
|
|
|
ecf709 |
goto done;
|
|
|
ecf709 |
}
|
|
|
ecf709 |
@@ -461,8 +450,6 @@ static void cache_req_search_done(struct tevent_req *subreq)
|
|
|
ecf709 |
"Returning updated object [%s]\n", state->cr->debugobj);
|
|
|
ecf709 |
|
|
|
ecf709 |
done:
|
|
|
ecf709 |
- talloc_free(tmp_ctx);
|
|
|
ecf709 |
-
|
|
|
ecf709 |
if (ret != EOK) {
|
|
|
ecf709 |
tevent_req_error(req, ret);
|
|
|
ecf709 |
return;
|
|
|
ecf709 |
--
|
|
|
ecf709 |
2.9.4
|
|
|
ecf709 |
|