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

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