Blame SOURCES/0159-sysdb-sysdb_get_certmap-allow-empty-certmap.patch

ecf709
From b435e510fb06af4e8f3cffd3730f43a6aff165fa Mon Sep 17 00:00:00 2001
ecf709
From: Sumit Bose <sbose@redhat.com>
ecf709
Date: Mon, 8 May 2017 17:30:06 +0200
ecf709
Subject: [PATCH 159/160] sysdb: sysdb_get_certmap() allow empty certmap
ecf709
MIME-Version: 1.0
ecf709
Content-Type: text/plain; charset=UTF-8
ecf709
Content-Transfer-Encoding: 8bit
ecf709
ecf709
Since sysdb_get_certmap() returns the user name hint information as well
ecf709
it should return a result even if there are no certmaps.
ecf709
ecf709
Related to https://pagure.io/SSSD/sssd/issue/3395
ecf709
ecf709
Reviewed-by: Fabiano FidĂȘncio <fidencio@redhat.com>
ecf709
(cherry picked from commit ee7e72a65d323636600ffda271d5b5c4ddbc78b1)
ecf709
---
ecf709
 src/db/sysdb_certmap.c                | 13 ++++++++-----
ecf709
 src/tests/cmocka/test_sysdb_certmap.c |  9 +++++----
ecf709
 2 files changed, 13 insertions(+), 9 deletions(-)
ecf709
ecf709
diff --git a/src/db/sysdb_certmap.c b/src/db/sysdb_certmap.c
ecf709
index 4917796b11c3967b4d147ebee7c7e83f09b872ce..2d89c08a07be6e8eaf853d6c50b206c5c53d5a37 100644
ecf709
--- a/src/db/sysdb_certmap.c
ecf709
+++ b/src/db/sysdb_certmap.c
ecf709
@@ -269,7 +269,7 @@ errno_t sysdb_get_certmap(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
ecf709
     size_t d;
ecf709
     struct ldb_dn *container_dn = NULL;
ecf709
     int ret;
ecf709
-    struct certmap_info **maps;
ecf709
+    struct certmap_info **maps = NULL;
ecf709
     TALLOC_CTX *tmp_ctx = NULL;
ecf709
     struct ldb_result *res;
ecf709
     const char *tmp_str;
ecf709
@@ -320,7 +320,7 @@ errno_t sysdb_get_certmap(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
ecf709
 
ecf709
     if (res->count == 0) {
ecf709
         DEBUG(SSSDBG_TRACE_FUNC, "No certificate maps found.\n");
ecf709
-        ret = ENOENT;
ecf709
+        ret = EOK;
ecf709
         goto done;
ecf709
     }
ecf709
 
ecf709
@@ -377,7 +377,7 @@ errno_t sysdb_get_certmap(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
ecf709
                                                SYSDB_CERTMAP_PRIORITY,
ecf709
                                                (uint64_t) -1);
ecf709
         if (tmp_uint != (uint64_t) -1) {
ecf709
-            if (tmp_uint >= UINT32_MAX) {
ecf709
+            if (tmp_uint > UINT32_MAX) {
ecf709
                 DEBUG(SSSDBG_OP_FAILURE, "Priority value [%lu] too large.\n",
ecf709
                                          (unsigned long) tmp_uint);
ecf709
                 ret = EINVAL;
ecf709
@@ -414,11 +414,14 @@ errno_t sysdb_get_certmap(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
ecf709
         }
ecf709
     }
ecf709
 
ecf709
-    *certmaps = talloc_steal(mem_ctx, maps);
ecf709
-    *user_name_hint = hint;
ecf709
     ret = EOK;
ecf709
 
ecf709
 done:
ecf709
+    if (ret == EOK) {
ecf709
+        *certmaps = talloc_steal(mem_ctx, maps);
ecf709
+        *user_name_hint = hint;
ecf709
+    }
ecf709
+
ecf709
     talloc_free(tmp_ctx);
ecf709
 
ecf709
     return ret;
ecf709
diff --git a/src/tests/cmocka/test_sysdb_certmap.c b/src/tests/cmocka/test_sysdb_certmap.c
ecf709
index fb07165561779226935f436c308c85abfc305635..72edf5f53fd6d23d7279eaa496b3e798c06cb903 100644
ecf709
--- a/src/tests/cmocka/test_sysdb_certmap.c
ecf709
+++ b/src/tests/cmocka/test_sysdb_certmap.c
ecf709
@@ -88,8 +88,8 @@ static void test_sysdb_get_certmap_not_exists(void **state)
ecf709
 
ecf709
     ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
ecf709
                             &user_name_hint);
ecf709
-    assert_int_equal(ret, ENOENT);
ecf709
-
ecf709
+    assert_int_equal(ret, EOK);
ecf709
+    assert_null(certmap);
ecf709
 }
ecf709
 
ecf709
 static void check_certmap(struct certmap_info *m, struct certmap_info *r,
ecf709
@@ -134,7 +134,7 @@ static void test_sysdb_update_certmap(void **state)
ecf709
     int ret;
ecf709
     const char *domains[] = { "dom1.test", "dom2.test", "dom3.test", NULL };
ecf709
     struct certmap_info map_a = { discard_const("map_a"), 11, discard_const("abc"), discard_const("def"), NULL };
ecf709
-    struct certmap_info map_b = { discard_const("map_b"), 22, discard_const("abc"), NULL, domains };
ecf709
+    struct certmap_info map_b = { discard_const("map_b"), UINT_MAX, discard_const("abc"), NULL, domains };
ecf709
     struct certmap_info *certmap_empty[] = { NULL };
ecf709
     struct certmap_info *certmap_a[] = { &map_a, NULL };
ecf709
     struct certmap_info *certmap_b[] = { &map_b, NULL };
ecf709
@@ -152,7 +152,8 @@ static void test_sysdb_update_certmap(void **state)
ecf709
 
ecf709
     ret = sysdb_get_certmap(ctctx, ctctx->tctx->sysdb, &certmap,
ecf709
                             &user_name_hint);
ecf709
-    assert_int_equal(ret, ENOENT);
ecf709
+    assert_int_equal(ret, EOK);
ecf709
+    assert_null(certmap);
ecf709
 
ecf709
     ret = sysdb_update_certmap(ctctx->tctx->sysdb, certmap_a, false);
ecf709
     assert_int_equal(ret, EOK);
ecf709
-- 
ecf709
2.9.4
ecf709