summaryrefslogtreecommitdiffstats
path: root/src/responder
diff options
context:
space:
mode:
authorFabiano Fidêncio <fidencio@redhat.com>2017-05-05 10:38:41 +0200
committerLukas Slebodnik <lslebodn@redhat.com>2017-08-25 21:02:54 +0200
commit5d855b5d546eb995023d80d61433bbe91888dbdf (patch)
treecbbe5b09f54fdd91d482eeea43d2059da302d6e1 /src/responder
parent3c31ce392ad9da4ac7c3d8190db89efcdbbc8b85 (diff)
downloadsssd-5d855b5d546eb995023d80d61433bbe91888dbdf.tar.gz
sssd-5d855b5d546eb995023d80d61433bbe91888dbdf.tar.xz
sssd-5d855b5d546eb995023d80d61433bbe91888dbdf.zip
IFP: Change ifp_list_ctx_remaining_capacity() return type
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>
Diffstat (limited to 'src/responder')
-rw-r--r--src/responder/ifp/ifp_groups.c14
-rw-r--r--src/responder/ifp/ifp_private.h5
-rw-r--r--src/responder/ifp/ifp_users.c21
-rw-r--r--src/responder/ifp/ifpsrv_util.c22
4 files changed, 47 insertions, 15 deletions
diff --git a/src/responder/ifp/ifp_groups.c b/src/responder/ifp/ifp_groups.c
index def241f27..750325423 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, &copy_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 a6e5701b8..ed1b63ad6 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 90b947ed9..86a1f43a2 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, &copy_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, &copy_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 33a49f4b4..6eea3354c 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,