From 78f9a9d4a2725f1b2cb6e582c965b5e6f7bdff7d Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Wed, 30 Mar 2016 13:38:17 +0200 Subject: RESPONDER: Add a helper function sss_resp_create_fqname When looking up entries in the responders that have not been yet converted to the cache_req API, we need to perform some common operations all the time. These include converting the name to the right case, reverse-replacing whitespace and converting the name to the qualified format for that domain. This patch adds a function that performs these steps to avoid code duplication. Reviewed-by: Sumit Bose --- src/responder/common/responder.h | 6 +++++ src/responder/common/responder_utils.c | 44 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) (limited to 'src') diff --git a/src/responder/common/responder.h b/src/responder/common/responder.h index 23e7d46f8..335b313ce 100644 --- a/src/responder/common/responder.h +++ b/src/responder/common/responder.h @@ -356,4 +356,10 @@ errno_t sss_parse_inp_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, const char **parse_attr_list_ex(TALLOC_CTX *mem_ctx, const char *conf_str, const char **defaults); +char *sss_resp_create_fqname(TALLOC_CTX *mem_ctx, + struct resp_ctx *rctx, + struct sss_domain_info *dom, + bool name_is_upn, + const char *orig_name); + #endif /* __SSS_RESPONDER_H__ */ diff --git a/src/responder/common/responder_utils.c b/src/responder/common/responder_utils.c index 815b61b39..b02212dfd 100644 --- a/src/responder/common/responder_utils.c +++ b/src/responder/common/responder_utils.c @@ -22,6 +22,7 @@ #include +#include "responder/common/responder.h" #include "util/util.h" static inline bool @@ -149,3 +150,46 @@ done: talloc_free(tmp_ctx); return res; } + +char *sss_resp_create_fqname(TALLOC_CTX *mem_ctx, + struct resp_ctx *rctx, + struct sss_domain_info *dom, + bool name_is_upn, + const char *orig_name) +{ + TALLOC_CTX *tmp_ctx; + char *name; + + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + return NULL; + } + + name = sss_get_cased_name(tmp_ctx, orig_name, dom->case_sensitive); + if (name == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "sss_get_cased_name failed\n"); + talloc_free(tmp_ctx); + return NULL; + } + + name = sss_reverse_replace_space(tmp_ctx, name, rctx->override_space); + if (name == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "sss_reverse_replace_space failed\n"); + talloc_free(tmp_ctx); + return NULL; + } + + + if (name_is_upn == false) { + name = sss_create_internal_fqname(tmp_ctx, name, dom->name); + if (name == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "sss_create_internal_fqname failed\n"); + talloc_free(tmp_ctx); + return NULL; + } + } + + name = talloc_steal(mem_ctx, name); + talloc_free(tmp_ctx); + return name; +} -- cgit