182 lines
6.5 KiB
Diff
182 lines
6.5 KiB
Diff
From 5d855b5d546eb995023d80d61433bbe91888dbdf Mon Sep 17 00:00:00 2001
|
|
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
|
|
Date: Fri, 5 May 2017 10:38:41 +0200
|
|
Subject: [PATCH 40/93] IFP: Change ifp_list_ctx_remaining_capacity() return
|
|
type
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
Now ifp_list_ctx_remaining_capacity() returns an errno_t and receives
|
|
the count as an output parameter. It allows better handling and error
|
|
reporting in case something goes wrong internally in this function.
|
|
|
|
Related:
|
|
https://pagure.io/SSSD/sssd/issue/3306
|
|
|
|
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
|
|
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
---
|
|
src/responder/ifp/ifp_groups.c | 14 +++++++++++---
|
|
src/responder/ifp/ifp_private.h | 5 +++--
|
|
src/responder/ifp/ifp_users.c | 21 +++++++++++++++++----
|
|
src/responder/ifp/ifpsrv_util.c | 22 ++++++++++++++++------
|
|
4 files changed, 47 insertions(+), 15 deletions(-)
|
|
|
|
diff --git a/src/responder/ifp/ifp_groups.c b/src/responder/ifp/ifp_groups.c
|
|
index def241f27241f415b91463dc214fa7791c2a6462..7503254238eafdafbe2d90fbf7416587be49e1b7 100644
|
|
--- a/src/responder/ifp/ifp_groups.c
|
|
+++ b/src/responder/ifp/ifp_groups.c
|
|
@@ -87,8 +87,12 @@ static int ifp_groups_list_copy(struct ifp_list_ctx *list_ctx,
|
|
struct ldb_result *result)
|
|
{
|
|
size_t copy_count, i;
|
|
+ errno_t ret;
|
|
|
|
- copy_count = ifp_list_ctx_remaining_capacity(list_ctx, result->count);
|
|
+ ret = ifp_list_ctx_remaining_capacity(list_ctx, result->count, ©_count);
|
|
+ if (ret != EOK) {
|
|
+ goto done;
|
|
+ }
|
|
|
|
for (i = 0; i < copy_count; i++) {
|
|
list_ctx->paths[list_ctx->path_count + i] = \
|
|
@@ -96,12 +100,16 @@ static int ifp_groups_list_copy(struct ifp_list_ctx *list_ctx,
|
|
list_ctx->dom,
|
|
result->msgs[i]);
|
|
if (list_ctx->paths[list_ctx->path_count + i] == NULL) {
|
|
- return ENOMEM;
|
|
+ ret = ENOMEM;
|
|
+ goto done;
|
|
}
|
|
}
|
|
|
|
list_ctx->path_count += copy_count;
|
|
- return EOK;
|
|
+ ret = EOK;
|
|
+
|
|
+done:
|
|
+ return ret;
|
|
}
|
|
|
|
static void ifp_groups_find_by_name_done(struct tevent_req *req);
|
|
diff --git a/src/responder/ifp/ifp_private.h b/src/responder/ifp/ifp_private.h
|
|
index a6e5701b8d1ebb27af0c35fa3ebe0c6c00d16bd6..ed1b63ad69433094dd6e40a9ca5f16725e8e3371 100644
|
|
--- a/src/responder/ifp/ifp_private.h
|
|
+++ b/src/responder/ifp/ifp_private.h
|
|
@@ -103,8 +103,9 @@ struct ifp_list_ctx *ifp_list_ctx_new(struct sbus_request *sbus_req,
|
|
const char *filter,
|
|
uint32_t limit);
|
|
|
|
-size_t ifp_list_ctx_remaining_capacity(struct ifp_list_ctx *list_ctx,
|
|
- size_t entries);
|
|
+errno_t ifp_list_ctx_remaining_capacity(struct ifp_list_ctx *list_ctx,
|
|
+ size_t entries,
|
|
+ size_t *_capacity);
|
|
|
|
errno_t ifp_ldb_el_output_name(struct resp_ctx *rctx,
|
|
struct ldb_message *msg,
|
|
diff --git a/src/responder/ifp/ifp_users.c b/src/responder/ifp/ifp_users.c
|
|
index 90b947ed9ca345fbeba6772c90f898451a0868aa..86a1f43a2c6e7d785c9d34e350c71f242ff7182f 100644
|
|
--- a/src/responder/ifp/ifp_users.c
|
|
+++ b/src/responder/ifp/ifp_users.c
|
|
@@ -436,8 +436,12 @@ static int ifp_users_list_copy(struct ifp_list_ctx *list_ctx,
|
|
struct ldb_result *result)
|
|
{
|
|
size_t copy_count, i;
|
|
+ errno_t ret;
|
|
|
|
- copy_count = ifp_list_ctx_remaining_capacity(list_ctx, result->count);
|
|
+ ret = ifp_list_ctx_remaining_capacity(list_ctx, result->count, ©_count);
|
|
+ if (ret != EOK) {
|
|
+ goto done;
|
|
+ }
|
|
|
|
for (i = 0; i < copy_count; i++) {
|
|
list_ctx->paths[list_ctx->path_count + i] = \
|
|
@@ -445,12 +449,16 @@ static int ifp_users_list_copy(struct ifp_list_ctx *list_ctx,
|
|
list_ctx->dom,
|
|
result->msgs[i]);
|
|
if (list_ctx->paths[list_ctx->path_count + i] == NULL) {
|
|
- return ENOMEM;
|
|
+ ret = ENOMEM;
|
|
+ goto done;
|
|
}
|
|
}
|
|
|
|
list_ctx->path_count += copy_count;
|
|
- return EOK;
|
|
+ ret = EOK;
|
|
+
|
|
+done:
|
|
+ return ret;
|
|
}
|
|
|
|
struct name_and_cert_ctx {
|
|
@@ -906,7 +914,12 @@ static void ifp_users_list_by_domain_and_name_done(struct tevent_req *req)
|
|
goto done;
|
|
}
|
|
|
|
- copy_count = ifp_list_ctx_remaining_capacity(list_ctx, result->count);
|
|
+ ret = ifp_list_ctx_remaining_capacity(list_ctx, result->count, ©_count);
|
|
+ if (ret != EOK) {
|
|
+ error = sbus_error_new(sbus_req, SBUS_ERROR_INTERNAL,
|
|
+ "Failed to get the list remaining capacity\n");
|
|
+ goto done;
|
|
+ }
|
|
|
|
for (i = 0; i < copy_count; i++) {
|
|
list_ctx->paths[i] = ifp_users_build_path_from_msg(list_ctx->paths,
|
|
diff --git a/src/responder/ifp/ifpsrv_util.c b/src/responder/ifp/ifpsrv_util.c
|
|
index 33a49f4b4653af3b2e4e8bc01f3ec2397095e880..6eea3354c0d07fe9605f5788f50524115de4b46c 100644
|
|
--- a/src/responder/ifp/ifpsrv_util.c
|
|
+++ b/src/responder/ifp/ifpsrv_util.c
|
|
@@ -381,28 +381,38 @@ struct ifp_list_ctx *ifp_list_ctx_new(struct sbus_request *sbus_req,
|
|
return list_ctx;
|
|
}
|
|
|
|
-size_t ifp_list_ctx_remaining_capacity(struct ifp_list_ctx *list_ctx,
|
|
- size_t entries)
|
|
+errno_t ifp_list_ctx_remaining_capacity(struct ifp_list_ctx *list_ctx,
|
|
+ size_t entries,
|
|
+ size_t *_capacity)
|
|
{
|
|
size_t capacity = list_ctx->limit - list_ctx->path_count;
|
|
+ errno_t ret;
|
|
|
|
if (list_ctx->limit == 0) {
|
|
list_ctx->paths = talloc_zero_array(list_ctx, const char *, entries);
|
|
if (list_ctx->paths == NULL) {
|
|
DEBUG(SSSDBG_CRIT_FAILURE, "talloc_zero_array() failed\n");
|
|
- return 0;
|
|
+ ret = ENOMEM;
|
|
+ goto done;
|
|
}
|
|
- return entries;
|
|
+ capacity = entries;
|
|
+ goto immediately;
|
|
}
|
|
|
|
if (capacity < entries) {
|
|
DEBUG(SSSDBG_MINOR_FAILURE,
|
|
"IFP list request has limit of %"PRIu32" entries but back end "
|
|
"returned %zu entries\n", list_ctx->limit, entries);
|
|
- return capacity;
|
|
} else {
|
|
- return entries;
|
|
+ capacity = entries;
|
|
}
|
|
+
|
|
+immediately:
|
|
+ *_capacity = capacity;
|
|
+ ret = EOK;
|
|
+
|
|
+done:
|
|
+ return ret;
|
|
}
|
|
|
|
errno_t ifp_ldb_el_output_name(struct resp_ctx *rctx,
|
|
--
|
|
2.14.1
|
|
|