dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0123-NSS-Move-output-name-formatting-to-utils.patch

ecf709
From 43b07b3fe8794a6e19db5cd2e9036e3d4d6c43ad Mon Sep 17 00:00:00 2001
ecf709
From: Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
ecf709
Date: Wed, 22 Mar 2017 14:32:35 +0200
ecf709
Subject: [PATCH 123/127] NSS: Move output name formatting to utils
ecf709
MIME-Version: 1.0
ecf709
Content-Type: text/plain; charset=UTF-8
ecf709
Content-Transfer-Encoding: 8bit
ecf709
ecf709
Move NSS nss_get_name_from_msg and the core of sized_output_name to the
ecf709
utils to make them available to provider and other responders.
ecf709
ecf709
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
ecf709
(cherry picked from commit a012a71f21bf1a4687e58085f19c18cc5b2bbadd)
ecf709
---
ecf709
 src/responder/common/responder_common.c | 27 ++++---------
ecf709
 src/responder/nss/nss_protocol_grent.c  |  2 +-
ecf709
 src/responder/nss/nss_protocol_pwent.c  |  2 +-
ecf709
 src/responder/nss/nss_protocol_sid.c    |  2 +-
ecf709
 src/responder/nss/nss_utils.c           | 27 -------------
ecf709
 src/util/usertools.c                    | 67 +++++++++++++++++++++++++++++++++
ecf709
 src/util/util.h                         |  9 +++++
ecf709
 7 files changed, 87 insertions(+), 49 deletions(-)
ecf709
ecf709
diff --git a/src/responder/common/responder_common.c b/src/responder/common/responder_common.c
ecf709
index 7496d293fddb3e947d59a4f2aaeb2c83234dfcc7..9d4889be652c6d6fb974b59001a9ac77b496e9ab 100644
ecf709
--- a/src/responder/common/responder_common.c
ecf709
+++ b/src/responder/common/responder_common.c
ecf709
@@ -1685,7 +1685,7 @@ int sized_output_name(TALLOC_CTX *mem_ctx,
ecf709
 {
ecf709
     TALLOC_CTX *tmp_ctx = NULL;
ecf709
     errno_t ret;
ecf709
-    char *username;
ecf709
+    char *name_str;
ecf709
     struct sized_string *name;
ecf709
 
ecf709
     tmp_ctx = talloc_new(NULL);
ecf709
@@ -1693,30 +1693,19 @@ int sized_output_name(TALLOC_CTX *mem_ctx,
ecf709
         return ENOMEM;
ecf709
     }
ecf709
 
ecf709
-    username = sss_output_name(tmp_ctx, orig_name, name_dom->case_preserve,
ecf709
-                               rctx->override_space);
ecf709
-    if (username == NULL) {
ecf709
-        ret = EIO;
ecf709
-        goto done;
ecf709
-    }
ecf709
-
ecf709
-    if (name_dom->fqnames) {
ecf709
-        username = sss_tc_fqname(tmp_ctx, name_dom->names, name_dom, username);
ecf709
-        if (username == NULL) {
ecf709
-            DEBUG(SSSDBG_CRIT_FAILURE, "sss_replace_space failed\n");
ecf709
-            ret = EIO;
ecf709
-            goto done;
ecf709
-        }
ecf709
-    }
ecf709
-
ecf709
     name = talloc_zero(tmp_ctx, struct sized_string);
ecf709
     if (name == NULL) {
ecf709
         ret = ENOMEM;
ecf709
         goto done;
ecf709
     }
ecf709
 
ecf709
-    to_sized_string(name, username);
ecf709
-    name->str = talloc_steal(name, username);
ecf709
+    ret = sss_output_fqname(mem_ctx, name_dom, orig_name,
ecf709
+                            rctx->override_space, &name_str);
ecf709
+    if (ret != EOK) {
ecf709
+        goto done;
ecf709
+    }
ecf709
+
ecf709
+    to_sized_string(name, name_str);
ecf709
     *_name = talloc_steal(mem_ctx, name);
ecf709
     ret = EOK;
ecf709
 done:
ecf709
diff --git a/src/responder/nss/nss_protocol_grent.c b/src/responder/nss/nss_protocol_grent.c
ecf709
index fae1d47d7b217beafba75740e2e6d9cb8cdbc1d0..947463df93e188729959737efa4ac4f44a8459c4 100644
ecf709
--- a/src/responder/nss/nss_protocol_grent.c
ecf709
+++ b/src/responder/nss/nss_protocol_grent.c
ecf709
@@ -41,7 +41,7 @@ nss_get_grent(TALLOC_CTX *mem_ctx,
ecf709
     }
ecf709
 
ecf709
     /* Get fields. */
ecf709
-    name = nss_get_name_from_msg(domain, msg);
ecf709
+    name = sss_get_name_from_msg(domain, msg);
ecf709
     gid = sss_view_ldb_msg_find_attr_as_uint64(domain, msg, SYSDB_GIDNUM, 0);
ecf709
 
ecf709
     if (name == NULL || gid == 0) {
ecf709
diff --git a/src/responder/nss/nss_protocol_pwent.c b/src/responder/nss/nss_protocol_pwent.c
ecf709
index edda9d3c87389898435a34fe7927868bc1cd9ac5..cb643f29e2d5f0a0c55c51afd9def73813061aa7 100644
ecf709
--- a/src/responder/nss/nss_protocol_pwent.c
ecf709
+++ b/src/responder/nss/nss_protocol_pwent.c
ecf709
@@ -225,7 +225,7 @@ nss_get_pwent(TALLOC_CTX *mem_ctx,
ecf709
 
ecf709
     /* Get fields. */
ecf709
     upn = ldb_msg_find_attr_as_string(msg, SYSDB_UPN, NULL);
ecf709
-    name = nss_get_name_from_msg(domain, msg);
ecf709
+    name = sss_get_name_from_msg(domain, msg);
ecf709
     gid = nss_get_gid(domain, msg);
ecf709
     uid = sss_view_ldb_msg_find_attr_as_uint64(domain, msg, SYSDB_UIDNUM, 0);
ecf709
 
ecf709
diff --git a/src/responder/nss/nss_protocol_sid.c b/src/responder/nss/nss_protocol_sid.c
ecf709
index a6a4e27d039c67ef98f6d5900d5e3fcadb3ee717..d4b7ee22d7c68a9e6f7c668f7268cdc5f36768b3 100644
ecf709
--- a/src/responder/nss/nss_protocol_sid.c
ecf709
+++ b/src/responder/nss/nss_protocol_sid.c
ecf709
@@ -532,7 +532,7 @@ nss_protocol_fill_name_list(struct nss_ctx *nss_ctx,
ecf709
             return ret;
ecf709
         }
ecf709
 
ecf709
-        tmp_str = nss_get_name_from_msg(result->domain, result->msgs[c]);
ecf709
+        tmp_str = sss_get_name_from_msg(result->domain, result->msgs[c]);
ecf709
         if (tmp_str == NULL) {
ecf709
             return EINVAL;
ecf709
         }
ecf709
diff --git a/src/responder/nss/nss_utils.c b/src/responder/nss/nss_utils.c
ecf709
index 2cd9c33b42f7e018ea89d2df206637f35646489e..b4950e5a6eaec6a4511f7251dcf2e623c0177230 100644
ecf709
--- a/src/responder/nss/nss_utils.c
ecf709
+++ b/src/responder/nss/nss_utils.c
ecf709
@@ -27,33 +27,6 @@
ecf709
 #include "responder/nss/nss_private.h"
ecf709
 
ecf709
 const char *
ecf709
-nss_get_name_from_msg(struct sss_domain_info *domain,
ecf709
-                      struct ldb_message *msg)
ecf709
-{
ecf709
-    const char *name;
ecf709
-
ecf709
-    /* If domain has a view associated we return overridden name
ecf709
-     * if possible. */
ecf709
-    if (DOM_HAS_VIEWS(domain)) {
ecf709
-        name = ldb_msg_find_attr_as_string(msg, OVERRIDE_PREFIX SYSDB_NAME,
ecf709
-                                           NULL);
ecf709
-        if (name != NULL) {
ecf709
-            return name;
ecf709
-        }
ecf709
-    }
ecf709
-
ecf709
-    /* Otherwise we try to return name override from
ecf709
-     * Default Truest View for trusted users. */
ecf709
-    name = ldb_msg_find_attr_as_string(msg, SYSDB_DEFAULT_OVERRIDE_NAME, NULL);
ecf709
-    if (name != NULL) {
ecf709
-        return name;
ecf709
-    }
ecf709
-
ecf709
-    /* If no override is found we return the original name. */
ecf709
-    return ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
ecf709
-}
ecf709
-
ecf709
-const char *
ecf709
 nss_get_pwfield(struct nss_ctx *nctx,
ecf709
                struct sss_domain_info *dom)
ecf709
 {
ecf709
diff --git a/src/util/usertools.c b/src/util/usertools.c
ecf709
index 7b87c567a6c2dc7e9c267407434b2a7a9edeaa00..5dfe6d7765b8032c7447de75e10c6c2a1d4c49ec 100644
ecf709
--- a/src/util/usertools.c
ecf709
+++ b/src/util/usertools.c
ecf709
@@ -816,3 +816,70 @@ done:
ecf709
     talloc_free(tmp_ctx);
ecf709
     return outname;
ecf709
 }
ecf709
+
ecf709
+const char *
ecf709
+sss_get_name_from_msg(struct sss_domain_info *domain,
ecf709
+                      struct ldb_message *msg)
ecf709
+{
ecf709
+    const char *name;
ecf709
+
ecf709
+    /* If domain has a view associated we return overridden name
ecf709
+     * if possible. */
ecf709
+    if (DOM_HAS_VIEWS(domain)) {
ecf709
+        name = ldb_msg_find_attr_as_string(msg, OVERRIDE_PREFIX SYSDB_NAME,
ecf709
+                                           NULL);
ecf709
+        if (name != NULL) {
ecf709
+            return name;
ecf709
+        }
ecf709
+    }
ecf709
+
ecf709
+    /* Otherwise we try to return name override from
ecf709
+     * Default Truest View for trusted users. */
ecf709
+    name = ldb_msg_find_attr_as_string(msg, SYSDB_DEFAULT_OVERRIDE_NAME, NULL);
ecf709
+    if (name != NULL) {
ecf709
+        return name;
ecf709
+    }
ecf709
+
ecf709
+    /* If no override is found we return the original name. */
ecf709
+    return ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
ecf709
+}
ecf709
+
ecf709
+int sss_output_fqname(TALLOC_CTX *mem_ctx,
ecf709
+                      struct sss_domain_info *domain,
ecf709
+                      const char *name,
ecf709
+                      char override_space,
ecf709
+                      char **_output_name)
ecf709
+{
ecf709
+    TALLOC_CTX *tmp_ctx = NULL;
ecf709
+    errno_t ret;
ecf709
+    char *output_name;
ecf709
+
ecf709
+    tmp_ctx = talloc_new(NULL);
ecf709
+    if (tmp_ctx == NULL) {
ecf709
+        ret = ENOMEM;
ecf709
+        goto done;
ecf709
+    }
ecf709
+
ecf709
+    output_name = sss_output_name(tmp_ctx, name, domain->case_preserve,
ecf709
+                                  override_space);
ecf709
+    if (output_name == NULL) {
ecf709
+        ret = EIO;
ecf709
+        goto done;
ecf709
+    }
ecf709
+
ecf709
+    if (domain->fqnames) {
ecf709
+        output_name = sss_tc_fqname(tmp_ctx, domain->names,
ecf709
+                                    domain, output_name);
ecf709
+        if (output_name == NULL) {
ecf709
+            DEBUG(SSSDBG_CRIT_FAILURE, "sss_tc_fqname failed\n");
ecf709
+            ret = EIO;
ecf709
+            goto done;
ecf709
+        }
ecf709
+    }
ecf709
+
ecf709
+    *_output_name = talloc_steal(mem_ctx, output_name);
ecf709
+    ret = EOK;
ecf709
+done:
ecf709
+    talloc_zfree(tmp_ctx);
ecf709
+    return ret;
ecf709
+}
ecf709
diff --git a/src/util/util.h b/src/util/util.h
ecf709
index 4ef13ced48addc19403402d7d880176da24ceec6..5ba4c36ca88e325c20a3b1ecc8080a11ca276dcf 100644
ecf709
--- a/src/util/util.h
ecf709
+++ b/src/util/util.h
ecf709
@@ -304,6 +304,15 @@ char *sss_output_name(TALLOC_CTX *mem_ctx,
ecf709
                       bool case_sensitive,
ecf709
                       const char replace_space);
ecf709
 
ecf709
+int sss_output_fqname(TALLOC_CTX *mem_ctx,
ecf709
+                      struct sss_domain_info *domain,
ecf709
+                      const char *name,
ecf709
+                      char override_space,
ecf709
+                      char **_output_name);
ecf709
+
ecf709
+const char *sss_get_name_from_msg(struct sss_domain_info *domain,
ecf709
+                                  struct ldb_message *msg);
ecf709
+
ecf709
 /* from backup-file.c */
ecf709
 int backup_file(const char *src, int dbglvl);
ecf709
 
ecf709
-- 
ecf709
2.9.3
ecf709