Blame SOURCES/0125-CACHE_REQ_RESULT-Introduce-cache_req_create_ldb_resu.patch

bb7cd1
From a2bfa4d2074cacc5d30f17a3b3af260ec9eaaa59 Mon Sep 17 00:00:00 2001
bb7cd1
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
bb7cd1
Date: Thu, 27 Apr 2017 11:24:45 +0200
bb7cd1
Subject: [PATCH 125/127] CACHE_REQ_RESULT: Introduce
bb7cd1
 cache_req_create_ldb_result_from_msg_list()
bb7cd1
MIME-Version: 1.0
bb7cd1
Content-Type: text/plain; charset=UTF-8
bb7cd1
Content-Transfer-Encoding: 8bit
bb7cd1
bb7cd1
Similarly to what cache_req_create_ldb_result_from_msg() does this new
bb7cd1
function creates a new ldb_result from a list of ldb_message.
bb7cd1
bb7cd1
It's going to be used in the follow-up patch where some messages from
bb7cd1
ldb_result may be filtered and then a new ldb_result has to be created.
bb7cd1
bb7cd1
Related:
bb7cd1
https://pagure.io/SSSD/sssd/issue/3362
bb7cd1
bb7cd1
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
bb7cd1
bb7cd1
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
bb7cd1
(cherry picked from commit 180e0b282be6aeb047c4b24b46e0b56afba1fdc8)
bb7cd1
---
bb7cd1
 src/responder/common/cache_req/cache_req_private.h |  5 ++++
bb7cd1
 src/responder/common/cache_req/cache_req_result.c  | 35 ++++++++++++++++++++++
bb7cd1
 2 files changed, 40 insertions(+)
bb7cd1
bb7cd1
diff --git a/src/responder/common/cache_req/cache_req_private.h b/src/responder/common/cache_req/cache_req_private.h
bb7cd1
index 851005c389f994b1bd2d04cda9b68df8b18492cc..c0ee5f969f2a171b8a6eb396b3d14b593d157b76 100644
bb7cd1
--- a/src/responder/common/cache_req/cache_req_private.h
bb7cd1
+++ b/src/responder/common/cache_req/cache_req_private.h
bb7cd1
@@ -137,6 +137,11 @@ cache_req_create_and_add_result(TALLOC_CTX *mem_ctx,
bb7cd1
                                 size_t *_num_results);
bb7cd1
 
bb7cd1
 struct ldb_result *
bb7cd1
+cache_req_create_ldb_result_from_msg_list(TALLOC_CTX *mem_ctx,
bb7cd1
+                                          struct ldb_message **ldb_msgs,
bb7cd1
+                                          size_t ldb_msg_count);
bb7cd1
+
bb7cd1
+struct ldb_result *
bb7cd1
 cache_req_create_ldb_result_from_msg(TALLOC_CTX *mem_ctx,
bb7cd1
                                      struct ldb_message *ldb_msg);
bb7cd1
 
bb7cd1
diff --git a/src/responder/common/cache_req/cache_req_result.c b/src/responder/common/cache_req/cache_req_result.c
bb7cd1
index e20ae5653acf22a2e0190ef6a88836c7fab9868e..366ba748082336c7c752b576cfd7b8fb8cd82fcf 100644
bb7cd1
--- a/src/responder/common/cache_req/cache_req_result.c
bb7cd1
+++ b/src/responder/common/cache_req/cache_req_result.c
bb7cd1
@@ -122,6 +122,41 @@ cache_req_create_and_add_result(TALLOC_CTX *mem_ctx,
bb7cd1
 }
bb7cd1
 
bb7cd1
 struct ldb_result *
bb7cd1
+cache_req_create_ldb_result_from_msg_list(TALLOC_CTX *mem_ctx,
bb7cd1
+                                          struct ldb_message **ldb_msgs,
bb7cd1
+                                          size_t ldb_msg_count)
bb7cd1
+{
bb7cd1
+    struct ldb_result *ldb_result;
bb7cd1
+
bb7cd1
+    if (ldb_msgs == NULL || ldb_msgs[0] == NULL) {
bb7cd1
+        DEBUG(SSSDBG_CRIT_FAILURE, "No message set!\n");
bb7cd1
+        return NULL;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    ldb_result = talloc_zero(NULL, struct ldb_result);
bb7cd1
+    if (ldb_result == NULL) {
bb7cd1
+        return NULL;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    ldb_result->extended = NULL;
bb7cd1
+    ldb_result->controls = NULL;
bb7cd1
+    ldb_result->refs = NULL;
bb7cd1
+    ldb_result->count = ldb_msg_count;
bb7cd1
+    ldb_result->msgs = talloc_zero_array(ldb_result, struct ldb_message *,
bb7cd1
+                                         ldb_msg_count + 1);
bb7cd1
+    if (ldb_result->msgs == NULL) {
bb7cd1
+        talloc_free(ldb_result);
bb7cd1
+        return NULL;
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    for (size_t i = 0; i < ldb_msg_count; i++) {
bb7cd1
+        ldb_result->msgs[i] = talloc_steal(ldb_result->msgs, ldb_msgs[i]);
bb7cd1
+    }
bb7cd1
+
bb7cd1
+    return ldb_result;
bb7cd1
+}
bb7cd1
+
bb7cd1
+struct ldb_result *
bb7cd1
 cache_req_create_ldb_result_from_msg(TALLOC_CTX *mem_ctx,
bb7cd1
                                      struct ldb_message *ldb_msg)
bb7cd1
 {
bb7cd1
-- 
bb7cd1
2.9.3
bb7cd1