Blame SOURCES/0001-ad_gpo_ndr.c-more-ndr-updates.patch

a4c784
From a7c755672cd277497da3df4714f6d9457b6ac5ae Mon Sep 17 00:00:00 2001
a4c784
From: Sumit Bose <sbose@redhat.com>
a4c784
Date: Thu, 28 May 2020 15:02:43 +0200
a4c784
Subject: [PATCH] ad_gpo_ndr.c: more ndr updates
a4c784
MIME-Version: 1.0
a4c784
Content-Type: text/plain; charset=UTF-8
a4c784
Content-Transfer-Encoding: 8bit
a4c784
a4c784
This patch add another update to the ndr code which was previously
a4c784
updated by commit c031adde4f532f39845a0efd78693600f1f8b2f4 and
a4c784
1fdd8fa2fded1985fbfc6aa67394eebcdbb6a2fc.
a4c784
a4c784
As missing update in ndr_pull_security_ace() cased
a4c784
a failure in ad_gpo_parse_sd(). A unit-test for ad_gpo_parse_sd() was
a4c784
added to prevent similar issues in future.
a4c784
a4c784
Resolves: https://github.com/SSSD/sssd/issues/5183
a4c784
a4c784
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
a4c784
---
a4c784
 src/providers/ad/ad_gpo_ndr.c  |  1 +
a4c784
 src/tests/cmocka/test_ad_gpo.c | 57 ++++++++++++++++++++++++++++++++++
a4c784
 2 files changed, 58 insertions(+)
a4c784
a4c784
diff --git a/src/providers/ad/ad_gpo_ndr.c b/src/providers/ad/ad_gpo_ndr.c
a4c784
index acd7b77c8..71d6d40f2 100644
a4c784
--- a/src/providers/ad/ad_gpo_ndr.c
a4c784
+++ b/src/providers/ad/ad_gpo_ndr.c
a4c784
@@ -317,6 +317,7 @@ ndr_pull_security_ace(struct ndr_pull *ndr,
a4c784
         ndr->offset += pad;
a4c784
     }
a4c784
     if (ndr_flags & NDR_BUFFERS) {
a4c784
+        NDR_CHECK(ndr_pull_set_switch_value(ndr, &r->object, r->type));
a4c784
         NDR_CHECK(ndr_pull_security_ace_object_ctr
a4c784
                   (ndr, NDR_BUFFERS, &r->object));
a4c784
     }
a4c784
diff --git a/src/tests/cmocka/test_ad_gpo.c b/src/tests/cmocka/test_ad_gpo.c
a4c784
index 97f70408a..d1f7a6915 100644
a4c784
--- a/src/tests/cmocka/test_ad_gpo.c
a4c784
+++ b/src/tests/cmocka/test_ad_gpo.c
a4c784
@@ -347,6 +347,60 @@ void test_ad_gpo_ace_includes_host_sid_true(void **state)
a4c784
                                         group_size, ace_dom_sid, true);
a4c784
 }
a4c784
 
a4c784
+uint8_t test_sid_data[] = {
a4c784
+0x01, 0x00, 0x04, 0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
a4c784
+0x14, 0x00, 0x00, 0x00, 0x04, 0x00, 0x34, 0x01, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00,
a4c784
+0xbd, 0x00, 0x0e, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00,
a4c784
+0xda, 0x0e, 0xba, 0x60, 0x0f, 0xa2, 0xf4, 0x55, 0xb5, 0x57, 0x47, 0xf8, 0x00, 0x02, 0x00, 0x00,
a4c784
+0x00, 0x0a, 0x24, 0x00, 0xff, 0x00, 0x0f, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
a4c784
+0x15, 0x00, 0x00, 0x00, 0xda, 0x0e, 0xba, 0x60, 0x0f, 0xa2, 0xf4, 0x55, 0xb5, 0x57, 0x47, 0xf8,
a4c784
+0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0xbd, 0x00, 0x0e, 0x00, 0x01, 0x05, 0x00, 0x00,
a4c784
+0x00, 0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0xda, 0x0e, 0xba, 0x60, 0x0f, 0xa2, 0xf4, 0x55,
a4c784
+0xb5, 0x57, 0x47, 0xf8, 0x07, 0x02, 0x00, 0x00, 0x00, 0x0a, 0x24, 0x00, 0xff, 0x00, 0x0f, 0x00,
a4c784
+0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00, 0xda, 0x0e, 0xba, 0x60,
a4c784
+0x0f, 0xa2, 0xf4, 0x55, 0xb5, 0x57, 0x47, 0xf8, 0x07, 0x02, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00,
a4c784
+0xbd, 0x00, 0x0e, 0x00, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x00, 0x00, 0x00,
a4c784
+0xda, 0x0e, 0xba, 0x60, 0x0f, 0xa2, 0xf4, 0x55, 0xb5, 0x57, 0x47, 0xf8, 0x00, 0x02, 0x00, 0x00,
a4c784
+0x00, 0x0a, 0x14, 0x00, 0xff, 0x00, 0x0f, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
a4c784
+0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x14, 0x00, 0xff, 0x00, 0x0f, 0x00, 0x01, 0x01, 0x00, 0x00,
a4c784
+0x00, 0x00, 0x00, 0x05, 0x12, 0x00, 0x00, 0x00, 0x00, 0x02, 0x14, 0x00, 0x94, 0x00, 0x02, 0x00,
a4c784
+0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0b, 0x00, 0x00, 0x00, 0x05, 0x02, 0x28, 0x00,
a4c784
+0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x8f, 0xfd, 0xac, 0xed, 0xb3, 0xff, 0xd1, 0x11,
a4c784
+0xb4, 0x1d, 0x00, 0xa0, 0xc9, 0x68, 0xf9, 0x39, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
a4c784
+0x0b, 0x00, 0x00, 0x00, 0x00, 0x02, 0x14, 0x00, 0x94, 0x00, 0x02, 0x00, 0x01, 0x01, 0x00, 0x00,
a4c784
+0x00, 0x00, 0x00, 0x05, 0x09, 0x00, 0x00, 0x00
a4c784
+};
a4c784
+
a4c784
+void test_ad_gpo_parse_sd(void **state)
a4c784
+{
a4c784
+    int ret;
a4c784
+    struct security_descriptor *sd = NULL;
a4c784
+
a4c784
+    ret = ad_gpo_parse_sd(test_ctx, NULL, 0, &sd);
a4c784
+    assert_int_equal(ret, EINVAL);
a4c784
+
a4c784
+    ret = ad_gpo_parse_sd(test_ctx, test_sid_data, sizeof(test_sid_data), &sd);
a4c784
+    assert_int_equal(ret, EOK);
a4c784
+    assert_non_null(sd);
a4c784
+    assert_int_equal(sd->revision, 1);
a4c784
+    assert_int_equal(sd->type, 39940);
a4c784
+    assert_null(sd->owner_sid);
a4c784
+    assert_null(sd->group_sid);
a4c784
+    assert_null(sd->sacl);
a4c784
+    assert_non_null(sd->dacl);
a4c784
+    assert_int_equal(sd->dacl->revision, 4);
a4c784
+    assert_int_equal(sd->dacl->size, 308);
a4c784
+    assert_int_equal(sd->dacl->num_aces, 10);
a4c784
+    assert_int_equal(sd->dacl->aces[0].type, 0);
a4c784
+    assert_int_equal(sd->dacl->aces[0].flags, 0);
a4c784
+    assert_int_equal(sd->dacl->aces[0].size, 36);
a4c784
+    assert_int_equal(sd->dacl->aces[0].access_mask, 917693);
a4c784
+    /* There are more components and ACEs in the security_descriptor struct
a4c784
+     * which are not checked here. */
a4c784
+
a4c784
+    talloc_free(sd);
a4c784
+}
a4c784
+
a4c784
 int main(int argc, const char *argv[])
a4c784
 {
a4c784
     poptContext pc;
a4c784
@@ -385,6 +439,9 @@ int main(int argc, const char *argv[])
a4c784
         cmocka_unit_test_setup_teardown(test_ad_gpo_ace_includes_host_sid_true,
a4c784
                                         ad_gpo_test_setup,
a4c784
                                         ad_gpo_test_teardown),
a4c784
+        cmocka_unit_test_setup_teardown(test_ad_gpo_parse_sd,
a4c784
+                                        ad_gpo_test_setup,
a4c784
+                                        ad_gpo_test_teardown),
a4c784
     };
a4c784
 
a4c784
     /* Set debug level to invalid value so we can decide if -d 0 was used. */
a4c784
-- 
a4c784
2.21.1
a4c784