Blame SOURCES/0036-sss_cache-fix-case-sensitivity-issue.patch

2fc102
From 2db8726f09800d64231f403198742d22a04a8d8b Mon Sep 17 00:00:00 2001
2fc102
From: Sumit Bose <sbose@redhat.com>
2fc102
Date: Tue, 26 Nov 2013 10:27:50 +0100
2fc102
Subject: [PATCH 36/41] sss_cache: fix case-sensitivity issue
2fc102
2fc102
For case-insensitive domains the lower-case name for case-insensitive
2fc102
searches is stored in SYSDB_NAME_ALIAS.
2fc102
2fc102
Related to https://fedorahosted.org/sssd/ticket/1741
2fc102
---
2fc102
 src/tools/sss_cache.c | 63 +++++++++++++++++++++++++++++----------------------
2fc102
 1 file changed, 36 insertions(+), 27 deletions(-)
2fc102
2fc102
diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c
2fc102
index 3b6e62393f6cf0f6ccc94aea8cf19bf3aedc444f..56dc47afdcb92b71dc1ef71d7f26fdf276a1c45f 100644
2fc102
--- a/src/tools/sss_cache.c
2fc102
+++ b/src/tools/sss_cache.c
2fc102
@@ -196,6 +196,8 @@ static errno_t update_filter(struct cache_tool_ctx *tctx,
2fc102
     TALLOC_CTX *tmp_ctx = NULL;
2fc102
     char *use_name = NULL;
2fc102
     char *filter;
2fc102
+    char *sanitized;
2fc102
+    char *lc_sanitized;
2fc102
 
2fc102
     if (!name || !update) {
2fc102
         /* Nothing to do */
2fc102
@@ -215,6 +217,14 @@ static errno_t update_filter(struct cache_tool_ctx *tctx,
2fc102
         goto done;
2fc102
     }
2fc102
 
2fc102
+    if (parsed_domain != NULL && strcasecmp(dinfo->name, parsed_domain) != 0) {
2fc102
+        /* We were able to parse the domain from given fqdn, but it
2fc102
+         * does not match with currently processed domain. */
2fc102
+        filter = NULL;
2fc102
+        ret = EOK;
2fc102
+        goto done;
2fc102
+    }
2fc102
+
2fc102
     if (!dinfo->case_sensitive && !force_case_sensitivity) {
2fc102
         use_name = sss_tc_utf8_str_tolower(tmp_ctx, parsed_name);
2fc102
         if (!use_name) {
2fc102
@@ -232,41 +242,40 @@ static errno_t update_filter(struct cache_tool_ctx *tctx,
2fc102
             ret = ENOMEM;
2fc102
             goto done;
2fc102
         }
2fc102
+    }
2fc102
 
2fc102
-        if (!strcasecmp(dinfo->name, parsed_domain)) {
2fc102
-            if (fmt) {
2fc102
-                filter = talloc_asprintf(tmp_ctx, fmt,
2fc102
-                                         SYSDB_NAME, use_name);
2fc102
-            } else {
2fc102
-                filter = talloc_strdup(tmp_ctx, use_name);
2fc102
-            }
2fc102
-            if (filter == NULL) {
2fc102
-                DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
2fc102
-                ret = ENOMEM;
2fc102
-                goto done;
2fc102
-            }
2fc102
+    ret = sss_filter_sanitize_for_dom(tmp_ctx, use_name, dinfo,
2fc102
+                                      &sanitized, &lc_sanitized);
2fc102
+    if (ret != EOK) {
2fc102
+        DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to sanitize the given name.\n"));
2fc102
+        goto done;
2fc102
+    }
2fc102
+
2fc102
+    if (fmt) {
2fc102
+        if (!dinfo->case_sensitive && !force_case_sensitivity) {
2fc102
+            filter = talloc_asprintf(tmp_ctx, "(|(%s=%s)(%s=%s))",
2fc102
+                                     SYSDB_NAME_ALIAS, lc_sanitized,
2fc102
+                                     SYSDB_NAME_ALIAS, sanitized);
2fc102
         } else {
2fc102
-            /* We were able to parse the domain from given fqdn, but it
2fc102
-             * does not match with currently processed domain. */
2fc102
-            filter = NULL;
2fc102
+            filter = talloc_asprintf(tmp_ctx, fmt, SYSDB_NAME, sanitized);
2fc102
         }
2fc102
     } else {
2fc102
-        if (fmt) {
2fc102
-            filter = talloc_asprintf(tmp_ctx, fmt, SYSDB_NAME, name);
2fc102
-        } else {
2fc102
-            filter = talloc_strdup(tmp_ctx, name);
2fc102
-        }
2fc102
-        if (filter == NULL) {
2fc102
-            DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
2fc102
-            ret = ENOMEM;
2fc102
-            goto done;
2fc102
-        }
2fc102
+        filter = talloc_strdup(tmp_ctx, sanitized);
2fc102
+    }
2fc102
+    if (filter == NULL) {
2fc102
+        DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
2fc102
+        ret = ENOMEM;
2fc102
+        goto done;
2fc102
     }
2fc102
 
2fc102
-    talloc_free(*_filter);
2fc102
-    *_filter = talloc_steal(tctx, filter);
2fc102
     ret = EOK;
2fc102
+
2fc102
 done:
2fc102
+    if (ret == EOK) {
2fc102
+        talloc_free(*_filter);
2fc102
+        *_filter = talloc_steal(tctx, filter);
2fc102
+    }
2fc102
+
2fc102
     talloc_free(tmp_ctx);
2fc102
     return ret;
2fc102
 
2fc102
-- 
2fc102
1.8.4.2
2fc102