Blob Blame History Raw
From e90d014c1ce95a30f4be2383a4b4f47ad21c5601 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Thu, 28 Nov 2013 12:31:24 +0100
Subject: [PATCH 38/41] Use sysdb_attrs_add_lc_name_alias to add
 case-insensitive alias

---
 src/providers/ipa/ipa_s2n_exop.c     | 27 ++++++---------------------
 src/providers/ldap/sdap_async.c      | 21 ++++++++++++++++-----
 src/providers/proxy/proxy_id.c       | 20 ++------------------
 src/providers/proxy/proxy_netgroup.c | 10 +---------
 src/responder/pac/pacsrv_utils.c     |  4 ++--
 5 files changed, 27 insertions(+), 55 deletions(-)

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