|
|
956cae |
From ed3bdd8998c5e0e18f9b8cfefa9acd00b8531585 Mon Sep 17 00:00:00 2001
|
|
|
956cae |
From: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
956cae |
Date: Wed, 19 Apr 2017 17:44:40 +0200
|
|
|
956cae |
Subject: [PATCH 164/165] Move sized_output_name() and sized_domain_name() into
|
|
|
956cae |
responder common code
|
|
|
956cae |
MIME-Version: 1.0
|
|
|
956cae |
Content-Type: text/plain; charset=UTF-8
|
|
|
956cae |
Content-Transfer-Encoding: 8bit
|
|
|
956cae |
|
|
|
956cae |
These functions are used to format a name into a format that the user
|
|
|
956cae |
configured for output, including case sensitiveness, replacing
|
|
|
956cae |
whitespace and qualified format. They were used only in the NSS
|
|
|
956cae |
responder, which typically returns strings to the NSS client library and
|
|
|
956cae |
then the user.
|
|
|
956cae |
|
|
|
956cae |
But it makes sense to just reuse the same code in the IFP responder as
|
|
|
956cae |
well, since it does essentially the same job.
|
|
|
956cae |
|
|
|
956cae |
The patch also renames sized_member_name to sized_domain_name.
|
|
|
956cae |
Previously, the function was only used to format a group member, the IFP
|
|
|
956cae |
responder would use the same function to format a group the user is a
|
|
|
956cae |
member of.
|
|
|
956cae |
|
|
|
956cae |
Related to:
|
|
|
956cae |
https://pagure.io/SSSD/sssd/issue/3268
|
|
|
956cae |
|
|
|
956cae |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
956cae |
(cherry picked from commit 7c074ba2f923985ab0d4f9d6a5e01ff3f2f0a7a8)
|
|
|
956cae |
---
|
|
|
956cae |
src/responder/common/responder.h | 21 ++++++++
|
|
|
956cae |
src/responder/common/responder_common.c | 90 +++++++++++++++++++++++++++++++++
|
|
|
956cae |
src/responder/nss/nsssrv_cmd.c | 89 +-------------------------------
|
|
|
956cae |
3 files changed, 112 insertions(+), 88 deletions(-)
|
|
|
956cae |
|
|
|
956cae |
diff --git a/src/responder/common/responder.h b/src/responder/common/responder.h
|
|
|
956cae |
index 9e3b2fdbda4e30b859df597374fc7d490b1720e5..fd6a67ba72f28f52d6cc1bbad16e1a7245462c93 100644
|
|
|
956cae |
--- a/src/responder/common/responder.h
|
|
|
956cae |
+++ b/src/responder/common/responder.h
|
|
|
956cae |
@@ -358,4 +358,25 @@ char *sss_resp_create_fqname(TALLOC_CTX *mem_ctx,
|
|
|
956cae |
bool name_is_upn,
|
|
|
956cae |
const char *orig_name);
|
|
|
956cae |
|
|
|
956cae |
+/**
|
|
|
956cae |
+ * Helper functions to format output names
|
|
|
956cae |
+ */
|
|
|
956cae |
+
|
|
|
956cae |
+/* Format orig_name into a sized_string in output format as prescribed
|
|
|
956cae |
+ * by the name_dom domain
|
|
|
956cae |
+ */
|
|
|
956cae |
+int sized_output_name(TALLOC_CTX *mem_ctx,
|
|
|
956cae |
+ struct resp_ctx *rctx,
|
|
|
956cae |
+ const char *orig_name,
|
|
|
956cae |
+ struct sss_domain_info *name_dom,
|
|
|
956cae |
+ struct sized_string **_name);
|
|
|
956cae |
+
|
|
|
956cae |
+/* Format orig_name into a sized_string in output format as prescribed
|
|
|
956cae |
+ * by the domain read from the fully qualified name.
|
|
|
956cae |
+ */
|
|
|
956cae |
+int sized_domain_name(TALLOC_CTX *mem_ctx,
|
|
|
956cae |
+ struct resp_ctx *rctx,
|
|
|
956cae |
+ const char *member_name,
|
|
|
956cae |
+ struct sized_string **_name);
|
|
|
956cae |
+
|
|
|
956cae |
#endif /* __SSS_RESPONDER_H__ */
|
|
|
956cae |
diff --git a/src/responder/common/responder_common.c b/src/responder/common/responder_common.c
|
|
|
956cae |
index c604c64a652221521ec7114b8588186f087eb11a..1db8a2283f3e96bccebe9a8443d5d04b9d5f4a54 100644
|
|
|
956cae |
--- a/src/responder/common/responder_common.c
|
|
|
956cae |
+++ b/src/responder/common/responder_common.c
|
|
|
956cae |
@@ -1248,3 +1248,93 @@ void responder_set_fd_limit(rlim_t fd_limit)
|
|
|
956cae |
"Proceeding with system values\n");
|
|
|
956cae |
}
|
|
|
956cae |
}
|
|
|
956cae |
+
|
|
|
956cae |
+/**
|
|
|
956cae |
+ * Helper functions to format output names
|
|
|
956cae |
+ */
|
|
|
956cae |
+int sized_output_name(TALLOC_CTX *mem_ctx,
|
|
|
956cae |
+ struct resp_ctx *rctx,
|
|
|
956cae |
+ const char *orig_name,
|
|
|
956cae |
+ struct sss_domain_info *name_dom,
|
|
|
956cae |
+ struct sized_string **_name)
|
|
|
956cae |
+{
|
|
|
956cae |
+ TALLOC_CTX *tmp_ctx = NULL;
|
|
|
956cae |
+ errno_t ret;
|
|
|
956cae |
+ char *username;
|
|
|
956cae |
+ struct sized_string *name;
|
|
|
956cae |
+
|
|
|
956cae |
+ tmp_ctx = talloc_new(NULL);
|
|
|
956cae |
+ if (tmp_ctx == NULL) {
|
|
|
956cae |
+ return ENOMEM;
|
|
|
956cae |
+ }
|
|
|
956cae |
+
|
|
|
956cae |
+ username = sss_output_name(tmp_ctx, orig_name, name_dom->case_preserve,
|
|
|
956cae |
+ rctx->override_space);
|
|
|
956cae |
+ if (username == NULL) {
|
|
|
956cae |
+ ret = EIO;
|
|
|
956cae |
+ goto done;
|
|
|
956cae |
+ }
|
|
|
956cae |
+
|
|
|
956cae |
+ if (name_dom->fqnames) {
|
|
|
956cae |
+ username = sss_tc_fqname(tmp_ctx, name_dom->names, name_dom, username);
|
|
|
956cae |
+ if (username == NULL) {
|
|
|
956cae |
+ DEBUG(SSSDBG_CRIT_FAILURE, "sss_replace_space failed\n");
|
|
|
956cae |
+ ret = EIO;
|
|
|
956cae |
+ goto done;
|
|
|
956cae |
+ }
|
|
|
956cae |
+ }
|
|
|
956cae |
+
|
|
|
956cae |
+ name = talloc_zero(tmp_ctx, struct sized_string);
|
|
|
956cae |
+ if (name == NULL) {
|
|
|
956cae |
+ ret = ENOMEM;
|
|
|
956cae |
+ goto done;
|
|
|
956cae |
+ }
|
|
|
956cae |
+
|
|
|
956cae |
+ to_sized_string(name, username);
|
|
|
956cae |
+ name->str = talloc_steal(name, username);
|
|
|
956cae |
+ *_name = talloc_steal(mem_ctx, name);
|
|
|
956cae |
+ ret = EOK;
|
|
|
956cae |
+done:
|
|
|
956cae |
+ talloc_zfree(tmp_ctx);
|
|
|
956cae |
+ return ret;
|
|
|
956cae |
+}
|
|
|
956cae |
+
|
|
|
956cae |
+int sized_domain_name(TALLOC_CTX *mem_ctx,
|
|
|
956cae |
+ struct resp_ctx *rctx,
|
|
|
956cae |
+ const char *member_name,
|
|
|
956cae |
+ struct sized_string **_name)
|
|
|
956cae |
+{
|
|
|
956cae |
+ TALLOC_CTX *tmp_ctx = NULL;
|
|
|
956cae |
+ errno_t ret;
|
|
|
956cae |
+ char *domname;
|
|
|
956cae |
+ struct sss_domain_info *member_dom;
|
|
|
956cae |
+
|
|
|
956cae |
+ tmp_ctx = talloc_new(NULL);
|
|
|
956cae |
+ if (tmp_ctx == NULL) {
|
|
|
956cae |
+ return ENOMEM;
|
|
|
956cae |
+ }
|
|
|
956cae |
+
|
|
|
956cae |
+ ret = sss_parse_internal_fqname(tmp_ctx, member_name, NULL, &domname);
|
|
|
956cae |
+ if (ret != EOK) {
|
|
|
956cae |
+ DEBUG(SSSDBG_CRIT_FAILURE, "sss_parse_internal_fqname failed\n");
|
|
|
956cae |
+ goto done;
|
|
|
956cae |
+ }
|
|
|
956cae |
+
|
|
|
956cae |
+ if (domname == NULL) {
|
|
|
956cae |
+ ret = ERR_WRONG_NAME_FORMAT;
|
|
|
956cae |
+ goto done;
|
|
|
956cae |
+ }
|
|
|
956cae |
+
|
|
|
956cae |
+ member_dom = find_domain_by_name(get_domains_head(rctx->domains),
|
|
|
956cae |
+ domname, true);
|
|
|
956cae |
+ if (member_dom == NULL) {
|
|
|
956cae |
+ ret = ERR_DOMAIN_NOT_FOUND;
|
|
|
956cae |
+ goto done;
|
|
|
956cae |
+ }
|
|
|
956cae |
+
|
|
|
956cae |
+ ret = sized_output_name(mem_ctx, rctx, member_name,
|
|
|
956cae |
+ member_dom, _name);
|
|
|
956cae |
+done:
|
|
|
956cae |
+ talloc_free(tmp_ctx);
|
|
|
956cae |
+ return ret;
|
|
|
956cae |
+}
|
|
|
956cae |
diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c
|
|
|
956cae |
index b64cea2a53ec6032904237b0afc1377022c2c804..0a9dd301266d4db1be1977cc8c337abde7cd79f5 100644
|
|
|
956cae |
--- a/src/responder/nss/nsssrv_cmd.c
|
|
|
956cae |
+++ b/src/responder/nss/nsssrv_cmd.c
|
|
|
956cae |
@@ -253,93 +253,6 @@ static const char *get_shell_override(TALLOC_CTX *mem_ctx,
|
|
|
956cae |
return talloc_strdup(mem_ctx, NOLOGIN_SHELL);
|
|
|
956cae |
}
|
|
|
956cae |
|
|
|
956cae |
-static int sized_output_name(TALLOC_CTX *mem_ctx,
|
|
|
956cae |
- struct resp_ctx *rctx,
|
|
|
956cae |
- const char *orig_name,
|
|
|
956cae |
- struct sss_domain_info *name_dom,
|
|
|
956cae |
- struct sized_string **_name)
|
|
|
956cae |
-{
|
|
|
956cae |
- TALLOC_CTX *tmp_ctx = NULL;
|
|
|
956cae |
- errno_t ret;
|
|
|
956cae |
- char *username;
|
|
|
956cae |
- struct sized_string *name;
|
|
|
956cae |
-
|
|
|
956cae |
- tmp_ctx = talloc_new(NULL);
|
|
|
956cae |
- if (tmp_ctx == NULL) {
|
|
|
956cae |
- return ENOMEM;
|
|
|
956cae |
- }
|
|
|
956cae |
-
|
|
|
956cae |
- username = sss_output_name(tmp_ctx, orig_name, name_dom->case_preserve,
|
|
|
956cae |
- rctx->override_space);
|
|
|
956cae |
- if (username == NULL) {
|
|
|
956cae |
- ret = EIO;
|
|
|
956cae |
- goto done;
|
|
|
956cae |
- }
|
|
|
956cae |
-
|
|
|
956cae |
- if (name_dom->fqnames) {
|
|
|
956cae |
- username = sss_tc_fqname(tmp_ctx, name_dom->names, name_dom, username);
|
|
|
956cae |
- if (username == NULL) {
|
|
|
956cae |
- DEBUG(SSSDBG_CRIT_FAILURE, "sss_replace_space failed\n");
|
|
|
956cae |
- ret = EIO;
|
|
|
956cae |
- goto done;
|
|
|
956cae |
- }
|
|
|
956cae |
- }
|
|
|
956cae |
-
|
|
|
956cae |
- name = talloc_zero(tmp_ctx, struct sized_string);
|
|
|
956cae |
- if (name == NULL) {
|
|
|
956cae |
- ret = ENOMEM;
|
|
|
956cae |
- goto done;
|
|
|
956cae |
- }
|
|
|
956cae |
-
|
|
|
956cae |
- to_sized_string(name, username);
|
|
|
956cae |
- name->str = talloc_steal(name, username);
|
|
|
956cae |
- *_name = talloc_steal(mem_ctx, name);
|
|
|
956cae |
- ret = EOK;
|
|
|
956cae |
-done:
|
|
|
956cae |
- talloc_zfree(tmp_ctx);
|
|
|
956cae |
- return ret;
|
|
|
956cae |
-}
|
|
|
956cae |
-
|
|
|
956cae |
-static int sized_member_name(TALLOC_CTX *mem_ctx,
|
|
|
956cae |
- struct resp_ctx *rctx,
|
|
|
956cae |
- const char *member_name,
|
|
|
956cae |
- struct sized_string **_name)
|
|
|
956cae |
-{
|
|
|
956cae |
- TALLOC_CTX *tmp_ctx = NULL;
|
|
|
956cae |
- errno_t ret;
|
|
|
956cae |
- char *domname;
|
|
|
956cae |
- struct sss_domain_info *member_dom;
|
|
|
956cae |
-
|
|
|
956cae |
- tmp_ctx = talloc_new(NULL);
|
|
|
956cae |
- if (tmp_ctx == NULL) {
|
|
|
956cae |
- return ENOMEM;
|
|
|
956cae |
- }
|
|
|
956cae |
-
|
|
|
956cae |
- ret = sss_parse_internal_fqname(tmp_ctx, member_name, NULL, &domname);
|
|
|
956cae |
- if (ret != EOK) {
|
|
|
956cae |
- DEBUG(SSSDBG_CRIT_FAILURE, "sss_parse_internal_fqname failed\n");
|
|
|
956cae |
- goto done;
|
|
|
956cae |
- }
|
|
|
956cae |
-
|
|
|
956cae |
- if (domname == NULL) {
|
|
|
956cae |
- ret = ERR_WRONG_NAME_FORMAT;
|
|
|
956cae |
- goto done;
|
|
|
956cae |
- }
|
|
|
956cae |
-
|
|
|
956cae |
- member_dom = find_domain_by_name(get_domains_head(rctx->domains),
|
|
|
956cae |
- domname, true);
|
|
|
956cae |
- if (member_dom == NULL) {
|
|
|
956cae |
- ret = ERR_DOMAIN_NOT_FOUND;
|
|
|
956cae |
- goto done;
|
|
|
956cae |
- }
|
|
|
956cae |
-
|
|
|
956cae |
- ret = sized_output_name(mem_ctx, rctx, member_name,
|
|
|
956cae |
- member_dom, _name);
|
|
|
956cae |
-done:
|
|
|
956cae |
- talloc_free(tmp_ctx);
|
|
|
956cae |
- return ret;
|
|
|
956cae |
-}
|
|
|
956cae |
-
|
|
|
956cae |
static int fill_pwent(struct sss_packet *packet,
|
|
|
956cae |
struct sss_domain_info *dom,
|
|
|
956cae |
struct nss_ctx *nctx,
|
|
|
956cae |
@@ -2727,7 +2640,7 @@ static int fill_members(struct sss_packet *packet,
|
|
|
956cae |
}
|
|
|
956cae |
}
|
|
|
956cae |
|
|
|
956cae |
- ret = sized_member_name(tmp_ctx, rctx, fqname, &name);
|
|
|
956cae |
+ ret = sized_domain_name(tmp_ctx, rctx, fqname, &name);
|
|
|
956cae |
if (ret != EOK) {
|
|
|
956cae |
DEBUG(SSSDBG_OP_FAILURE, "sized_member_name failed: %d\n", ret);
|
|
|
956cae |
goto done;
|
|
|
956cae |
--
|
|
|
956cae |
2.9.3
|
|
|
956cae |
|