dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0111-util-Special-case-PCRE_ERROR_NOMATCH-in-sss_parse_na.patch

905b4d
From eedf2fc4c1432f805b16ae52939cf5e67e8df550 Mon Sep 17 00:00:00 2001
905b4d
From: Michal Zidek <mzidek@redhat.com>
905b4d
Date: Mon, 24 Nov 2014 19:50:14 +0100
905b4d
Subject: [PATCH 111/112] util: Special-case PCRE_ERROR_NOMATCH in
905b4d
 sss_parse_name
905b4d
MIME-Version: 1.0
905b4d
Content-Type: text/plain; charset=UTF-8
905b4d
Content-Transfer-Encoding: 8bit
905b4d
905b4d
Add new SSSD specific error code for the case when
905b4d
pcre_exec returns PCRE_ERROR_NOMATCH.
905b4d
905b4d
Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
905b4d
---
905b4d
 src/tests/cmocka/test_fqnames.c | 14 +++++++-------
905b4d
 src/util/usertools.c            |  2 +-
905b4d
 src/util/util_errors.c          |  1 +
905b4d
 src/util/util_errors.h          |  1 +
905b4d
 4 files changed, 10 insertions(+), 8 deletions(-)
905b4d
905b4d
diff --git a/src/tests/cmocka/test_fqnames.c b/src/tests/cmocka/test_fqnames.c
905b4d
index de208437d3d11429ebb4fd92ac6b1469564d9174..b9b6230b9e2c86dafae159630d5202e46992f5f3 100644
905b4d
--- a/src/tests/cmocka/test_fqnames.c
905b4d
+++ b/src/tests/cmocka/test_fqnames.c
905b4d
@@ -471,13 +471,13 @@ void sss_parse_name_fail(void **state)
905b4d
     struct parse_name_test_ctx *test_ctx = talloc_get_type(*state,
905b4d
                                                            struct parse_name_test_ctx);
905b4d
 
905b4d
-    sss_parse_name_check(test_ctx, "", EINVAL, NULL, NULL);
905b4d
-    sss_parse_name_check(test_ctx, "@", EINVAL, NULL, NULL);
905b4d
-    sss_parse_name_check(test_ctx, "\\", EINVAL, NULL, NULL);
905b4d
-    sss_parse_name_check(test_ctx, "\\"NAME, EINVAL, NULL, NULL);
905b4d
-    sss_parse_name_check(test_ctx, "@"NAME, EINVAL, NULL, NULL);
905b4d
-    sss_parse_name_check(test_ctx, NAME"@", EINVAL, NULL, NULL);
905b4d
-    sss_parse_name_check(test_ctx, NAME"\\", EINVAL, NULL, NULL);
905b4d
+    sss_parse_name_check(test_ctx, "", ERR_REGEX_NOMATCH, NULL, NULL);
905b4d
+    sss_parse_name_check(test_ctx, "@", ERR_REGEX_NOMATCH, NULL, NULL);
905b4d
+    sss_parse_name_check(test_ctx, "\\", ERR_REGEX_NOMATCH, NULL, NULL);
905b4d
+    sss_parse_name_check(test_ctx, "\\"NAME, ERR_REGEX_NOMATCH, NULL, NULL);
905b4d
+    sss_parse_name_check(test_ctx, "@"NAME, ERR_REGEX_NOMATCH, NULL, NULL);
905b4d
+    sss_parse_name_check(test_ctx, NAME"@", ERR_REGEX_NOMATCH, NULL, NULL);
905b4d
+    sss_parse_name_check(test_ctx, NAME"\\", ERR_REGEX_NOMATCH, NULL, NULL);
905b4d
 }
905b4d
 
905b4d
 void test_sss_get_domain_name(void **state)
905b4d
diff --git a/src/util/usertools.c b/src/util/usertools.c
905b4d
index a0b914e2fe8f65a71015944e63cb2d2813345d84..09cfd6b35505b8496413258fd05808ac0d2c095b 100644
905b4d
--- a/src/util/usertools.c
905b4d
+++ b/src/util/usertools.c
905b4d
@@ -309,7 +309,7 @@ int sss_parse_name(TALLOC_CTX *memctx,
905b4d
 
905b4d
     ret = pcre_exec(re, NULL, orig, origlen, 0, PCRE_NOTEMPTY, ovec, 30);
905b4d
     if (ret == PCRE_ERROR_NOMATCH) {
905b4d
-        return EINVAL;
905b4d
+        return ERR_REGEX_NOMATCH;
905b4d
     } else if (ret < 0) {
905b4d
         DEBUG(SSSDBG_MINOR_FAILURE, "PCRE Matching error, %d\n", ret);
905b4d
         return EINVAL;
905b4d
diff --git a/src/util/util_errors.c b/src/util/util_errors.c
905b4d
index c1ed0fb634c447904b63335d1cd161b7e7914a08..16d16fc777fc3344db8a3bdfeb3633bd5db48530 100644
905b4d
--- a/src/util/util_errors.c
905b4d
+++ b/src/util/util_errors.c
905b4d
@@ -64,6 +64,7 @@ struct err_string error_to_str[] = {
905b4d
     { "Cannot connect to system bus" }, /* ERR_NO_SYSBUS */
905b4d
     { "LDAP search returned a referral" }, /* ERR_REFERRAL */
905b4d
     { "Error setting SELinux user context" }, /* ERR_SELINUX_CONTEXT */
905b4d
+    { "Username format not allowed by re_expression" }, /* ERR_REGEX_NOMATCH */
905b4d
 };
905b4d
 
905b4d
 
905b4d
diff --git a/src/util/util_errors.h b/src/util/util_errors.h
905b4d
index f71ede8d0fa000627a1bd994ec8bd94a632b35b2..39455dc8adfe8784bd3f06382d701b7f9e97f004 100644
905b4d
--- a/src/util/util_errors.h
905b4d
+++ b/src/util/util_errors.h
905b4d
@@ -86,6 +86,7 @@ enum sssd_errors {
905b4d
     ERR_NO_SYSBUS,
905b4d
     ERR_REFERRAL,
905b4d
     ERR_SELINUX_CONTEXT,
905b4d
+    ERR_REGEX_NOMATCH,
905b4d
     ERR_LAST            /* ALWAYS LAST */
905b4d
 };
905b4d
 
905b4d
-- 
905b4d
1.9.3
905b4d