[SSSD] [PATCH] sss_idmap: fix typo which prevents sub auth larger then 2^31

Sumit Bose sbose at redhat.com
Fri Jun 1 11:10:32 UTC 2012


Hi,

I found a missing 'u' in the idmap code. This patch fixes the typo and
adds a test.

bye,
Sumit
-------------- next part --------------
From 1ecf801a22f0ad842500118ddd4d7851cddbef74 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Fri, 1 Jun 2012 13:08:04 +0200
Subject: [PATCH] sss_idmap: fix typo which prevents sub auth larger then 2^31

A test to cover this is added as well.
---
 src/lib/idmap/sss_idmap_conv.c |    2 +-
 src/tests/sss_idmap-tests.c    |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 1 deletions(-)

diff --git a/src/lib/idmap/sss_idmap_conv.c b/src/lib/idmap/sss_idmap_conv.c
index d74df8c..a523bfc 100644
--- a/src/lib/idmap/sss_idmap_conv.c
+++ b/src/lib/idmap/sss_idmap_conv.c
@@ -305,7 +305,7 @@ enum idmap_error_code sss_idmap_sid_to_dom_sid(struct sss_idmap_ctx *ctx,
         }
 
         errno = 0;
-        ul = strtol(r, &end, 10);
+        ul = strtoul(r, &end, 10);
         if (errno != 0 || end == NULL ||
             (*end != '\0' && *end != '-')) {
             err = IDMAP_SID_INVALID;
diff --git a/src/tests/sss_idmap-tests.c b/src/tests/sss_idmap-tests.c
index a7d5f57..838e074 100644
--- a/src/tests/sss_idmap-tests.c
+++ b/src/tests/sss_idmap-tests.c
@@ -40,6 +40,9 @@ size_t test_bin_sid_length = sizeof(test_bin_sid);
 
 struct dom_sid test_smb_sid = {1, 5, {0, 0, 0, 0, 0, 5}, {21, 2127521184, 1604012920, 1887927527, 72713, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
 
+const char large_sid[] = "S-1-5-21-1-2-4294967295-1000";
+const char too_large_sid[] = "S-1-5-21-1-2-4294967296-1000";
+
 struct sss_idmap_ctx *idmap_ctx;
 
 static void *idmap_talloc(size_t size, void *pvt)
@@ -326,6 +329,39 @@ START_TEST(idmap_test_sid2dom_sid)
 }
 END_TEST
 
+START_TEST(idmap_test_large_and_too_large_sid)
+{
+    struct sss_dom_sid *dom_sid = NULL;
+    enum idmap_error_code err;
+    char *new_sid = NULL;
+
+    err = sss_idmap_sid_to_dom_sid(idmap_ctx, large_sid, &dom_sid);
+
+    fail_unless(err == IDMAP_SUCCESS,
+                "Failed to convert SID string with a UINT32_MAX component "
+                "to struct sss_dom_sid.");
+
+    err = sss_idmap_dom_sid_to_sid(idmap_ctx, dom_sid, &new_sid);
+    fail_unless(err == IDMAP_SUCCESS,
+                "Failed to convert struct sss_dom_sid to SID string.");
+
+    fail_unless(new_sid != NULL, "SID string not set");
+    fail_unless(strlen(large_sid) == strlen(new_sid),
+                "Length of SID strings do not match.");
+    fail_unless(strcmp(large_sid, new_sid) == 0,
+                "SID strings do not match, expected [%s], got [%s]",
+                large_sid, new_sid);
+
+    err = sss_idmap_sid_to_dom_sid(idmap_ctx, too_large_sid, &dom_sid);
+    fail_unless(err == IDMAP_SID_INVALID,
+                "Trying to convert  a SID with a too large component "
+                "did not return IDMAP_SID_INVALID");
+
+    talloc_free(dom_sid);
+    talloc_free(new_sid);
+}
+END_TEST
+
 START_TEST(idmap_test_sid2bin_sid)
 {
     enum idmap_error_code err;
@@ -496,6 +532,7 @@ Suite *idmap_test_suite (void)
     tcase_add_test(tc_conv, idmap_test_bin_sid2smb_sid);
     tcase_add_test(tc_conv, idmap_test_smb_sid2sid);
     tcase_add_test(tc_conv, idmap_test_sid2smb_sid);
+    tcase_add_test(tc_conv, idmap_test_large_and_too_large_sid);
 
     suite_add_tcase(s, tc_conv);
 
-- 
1.7.7.6



More information about the sssd-devel mailing list