Blame SOURCES/0038-Use-sysdb_attrs_add_lc_name_alias-to-add-case-insens.patch

2fc102
From e90d014c1ce95a30f4be2383a4b4f47ad21c5601 Mon Sep 17 00:00:00 2001
2fc102
From: Sumit Bose <sbose@redhat.com>
2fc102
Date: Thu, 28 Nov 2013 12:31:24 +0100
2fc102
Subject: [PATCH 38/41] Use sysdb_attrs_add_lc_name_alias to add
2fc102
 case-insensitive alias
2fc102
2fc102
---
2fc102
 src/providers/ipa/ipa_s2n_exop.c     | 27 ++++++---------------------
2fc102
 src/providers/ldap/sdap_async.c      | 21 ++++++++++++++++-----
2fc102
 src/providers/proxy/proxy_id.c       | 20 ++------------------
2fc102
 src/providers/proxy/proxy_netgroup.c | 10 +---------
2fc102
 src/responder/pac/pacsrv_utils.c     |  4 ++--
2fc102
 5 files changed, 27 insertions(+), 55 deletions(-)
2fc102
2fc102
diff --git a/src/providers/ipa/ipa_s2n_exop.c b/src/providers/ipa/ipa_s2n_exop.c
2fc102
index d8506aaae2582f496033212e5abeef753244c21a..8bad16d42facac3a585a4fdf579c3d2bb913dd71 100644
2fc102
--- a/src/providers/ipa/ipa_s2n_exop.c
2fc102
+++ b/src/providers/ipa/ipa_s2n_exop.c
2fc102
@@ -651,7 +651,6 @@ static void ipa_s2n_get_user_done(struct tevent_req *subreq)
2fc102
     struct sysdb_attrs *user_attrs = NULL;
2fc102
     struct sysdb_attrs *group_attrs = NULL;
2fc102
     char *name;
2fc102
-    char *lc_name;
2fc102
     char *realm;
2fc102
     char *upn;
2fc102
     struct berval *bv_req = NULL;
2fc102
@@ -767,16 +766,10 @@ static void ipa_s2n_get_user_done(struct tevent_req *subreq)
2fc102
                 goto done;
2fc102
             }
2fc102
 
2fc102
-            lc_name = sss_tc_utf8_str_tolower(user_attrs, name);
2fc102
-            if (lc_name == NULL) {
2fc102
-                DEBUG(SSSDBG_CRIT_FAILURE, ("Cannot convert name to lowercase\n"));
2fc102
-                ret =  ENOMEM;
2fc102
-                goto done;
2fc102
-            }
2fc102
-
2fc102
-            ret = sysdb_attrs_add_string(user_attrs, SYSDB_NAME_ALIAS, lc_name);
2fc102
+            ret = sysdb_attrs_add_lc_name_alias(user_attrs, name);
2fc102
             if (ret != EOK) {
2fc102
-                DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_add_string failed.\n"));
2fc102
+                DEBUG(SSSDBG_OP_FAILURE,
2fc102
+                      ("sysdb_attrs_add_lc_name_alias failed.\n"));
2fc102
                 goto done;
2fc102
             }
2fc102
 
2fc102
@@ -852,18 +845,10 @@ static void ipa_s2n_get_user_done(struct tevent_req *subreq)
2fc102
                 goto done;
2fc102
             }
2fc102
 
2fc102
-            lc_name = sss_tc_utf8_str_tolower(group_attrs, name);
2fc102
-            if (lc_name == NULL) {
2fc102
-                DEBUG(SSSDBG_CRIT_FAILURE,
2fc102
-                      ("Cannot convert name to lowercase\n"));
2fc102
-                ret = ENOMEM;
2fc102
-                goto done;
2fc102
-            }
2fc102
-
2fc102
-            ret = sysdb_attrs_add_string(group_attrs, SYSDB_NAME_ALIAS,
2fc102
-                                         lc_name);
2fc102
+            ret = sysdb_attrs_add_lc_name_alias(group_attrs, name);
2fc102
             if (ret != EOK) {
2fc102
-                DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_add_string failed.\n"));
2fc102
+                DEBUG(SSSDBG_OP_FAILURE,
2fc102
+                      ("sysdb_attrs_add_lc_name_alias failed.\n"));
2fc102
                 goto done;
2fc102
             }
2fc102
 
2fc102
diff --git a/src/providers/ldap/sdap_async.c b/src/providers/ldap/sdap_async.c
2fc102
index f5cc962b34c8ef5e8c8dc9cf90b77d782b389032..e905d2dd6d539baadcd29aa0869ca04e845947e2 100644
2fc102
--- a/src/providers/ldap/sdap_async.c
2fc102
+++ b/src/providers/ldap/sdap_async.c
2fc102
@@ -2318,12 +2318,23 @@ sdap_save_all_names(const char *name,
2fc102
             goto done;
2fc102
         }
2fc102
 
2fc102
-        ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, domname);
2fc102
-        if (ret) {
2fc102
-            DEBUG(SSSDBG_OP_FAILURE, ("Failed to add alias [%s] into the "
2fc102
-                                      "attribute list\n", aliases[i]));
2fc102
-            goto done;
2fc102
+        if (lowercase) {
2fc102
+            ret = sysdb_attrs_add_lc_name_alias(attrs, domname);
2fc102
+            if (ret) {
2fc102
+                DEBUG(SSSDBG_OP_FAILURE, ("Failed to add lower-cased version "
2fc102
+                                          "of alias [%s] into the "
2fc102
+                                          "attribute list\n", aliases[i]));
2fc102
+                goto done;
2fc102
+            }
2fc102
+        } else {
2fc102
+            ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, domname);
2fc102
+            if (ret) {
2fc102
+                DEBUG(SSSDBG_OP_FAILURE, ("Failed to add alias [%s] into the "
2fc102
+                                          "attribute list\n", aliases[i]));
2fc102
+                goto done;
2fc102
+            }
2fc102
         }
2fc102
+
2fc102
     }
2fc102
 
2fc102
     ret = EOK;
2fc102
diff --git a/src/providers/proxy/proxy_id.c b/src/providers/proxy/proxy_id.c
2fc102
index 963aad2d0676a665d69be2ea2996ad49cb2bacc6..2c01aad5ae86e11d22383d6b618073ef8e9d6dbb 100644
2fc102
--- a/src/providers/proxy/proxy_id.c
2fc102
+++ b/src/providers/proxy/proxy_id.c
2fc102
@@ -223,7 +223,6 @@ static int save_user(struct sysdb_ctx *sysdb, struct sss_domain_info *domain,
2fc102
 {
2fc102
     const char *shell;
2fc102
     const char *gecos;
2fc102
-    char *lower;
2fc102
     struct sysdb_attrs *attrs = NULL;
2fc102
     errno_t ret;
2fc102
     const char *cased_alias;
2fc102
@@ -249,14 +248,7 @@ static int save_user(struct sysdb_ctx *sysdb, struct sss_domain_info *domain,
2fc102
     }
2fc102
 
2fc102
     if (lowercase) {
2fc102
-        lower = sss_tc_utf8_str_tolower(attrs, pwd->pw_name);
2fc102
-        if (!lower) {
2fc102
-            DEBUG(SSSDBG_CRIT_FAILURE, ("Cannot convert name to lowercase\n"));
2fc102
-            talloc_zfree(attrs);
2fc102
-            return ENOMEM;
2fc102
-        }
2fc102
-
2fc102
-        ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, lower);
2fc102
+        ret = sysdb_attrs_add_lc_name_alias(attrs, pwd->pw_name);
2fc102
         if (ret) {
2fc102
             DEBUG(SSSDBG_OP_FAILURE, ("Could not add name alias\n"));
2fc102
             talloc_zfree(attrs);
2fc102
@@ -540,7 +532,6 @@ static int save_group(struct sysdb_ctx *sysdb, struct sss_domain_info *dom,
2fc102
 {
2fc102
     errno_t ret, sret;
2fc102
     struct sysdb_attrs *attrs = NULL;
2fc102
-    char *lower;
2fc102
     const char *cased_alias;
2fc102
     TALLOC_CTX *tmp_ctx;
2fc102
     time_t now = time(NULL);
2fc102
@@ -595,14 +586,7 @@ static int save_group(struct sysdb_ctx *sysdb, struct sss_domain_info *dom,
2fc102
         }
2fc102
 
2fc102
         if (dom->case_sensitive == false) {
2fc102
-            lower = sss_tc_utf8_str_tolower(attrs, grp->gr_name);
2fc102
-            if (!lower) {
2fc102
-                DEBUG(SSSDBG_CRIT_FAILURE, ("Cannot convert name to lowercase\n"));
2fc102
-                ret = ENOMEM;
2fc102
-                goto done;
2fc102
-            }
2fc102
-
2fc102
-            ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, lower);
2fc102
+            ret = sysdb_attrs_add_lc_name_alias(attrs, grp->gr_name);
2fc102
             if (ret) {
2fc102
                 DEBUG(SSSDBG_OP_FAILURE, ("Could not add name alias\n"));
2fc102
                 ret = ENOMEM;
2fc102
diff --git a/src/providers/proxy/proxy_netgroup.c b/src/providers/proxy/proxy_netgroup.c
2fc102
index 04a0b18d7079aa15d04562ee5c785caed4456fb5..bb0bc171b8c3688a92c14f711669f752653a39f0 100644
2fc102
--- a/src/providers/proxy/proxy_netgroup.c
2fc102
+++ b/src/providers/proxy/proxy_netgroup.c
2fc102
@@ -74,17 +74,9 @@ static errno_t save_netgroup(struct sysdb_ctx *sysdb,
2fc102
                              uint64_t cache_timeout)
2fc102
 {
2fc102
     errno_t ret;
2fc102
-    char *lower;
2fc102
 
2fc102
     if (lowercase) {
2fc102
-        lower = sss_tc_utf8_str_tolower(NULL, name);
2fc102
-        if (!lower) {
2fc102
-            DEBUG(SSSDBG_CRIT_FAILURE, ("Cannot convert name to lowercase\n"));
2fc102
-            return ENOMEM;
2fc102
-        }
2fc102
-
2fc102
-        ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, lower);
2fc102
-        talloc_free(lower);
2fc102
+        ret = sysdb_attrs_add_lc_name_alias(attrs, name);
2fc102
         if (ret) {
2fc102
             DEBUG(SSSDBG_OP_FAILURE, ("Could not add name alias\n"));
2fc102
             return ret;
2fc102
diff --git a/src/responder/pac/pacsrv_utils.c b/src/responder/pac/pacsrv_utils.c
2fc102
index 30055a1345b7d943e6adf822438263c92e53b51a..6a6ea2e357483c68533c501b93c16383ee644048 100644
2fc102
--- a/src/responder/pac/pacsrv_utils.c
2fc102
+++ b/src/responder/pac/pacsrv_utils.c
2fc102
@@ -483,9 +483,9 @@ errno_t get_pwd_from_pac(TALLOC_CTX *mem_ctx,
2fc102
         goto done;
2fc102
     }
2fc102
 
2fc102
-    ret = sysdb_attrs_add_string(attrs, SYSDB_NAME_ALIAS, pwd->pw_name);
2fc102
+    ret = sysdb_attrs_add_lc_name_alias(attrs, pwd->pw_name);
2fc102
     if (ret != EOK) {
2fc102
-        DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_add_string failed.\n"));
2fc102
+        DEBUG(SSSDBG_OP_FAILURE, ("sysdb_attrs_add_lc_name_alias failed.\n"));
2fc102
         goto done;
2fc102
     }
2fc102
 
2fc102
-- 
2fc102
1.8.4.2
2fc102