dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

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

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