From 87c6d9ea92d83460457353cfea6c5bde8744994a Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Sun, 19 Jun 2016 07:14:23 +0200 Subject: UTIL: Add a utility function sss_output_name Adds a convenience function that will help reduce the amount of code duplication in the responders. All responders need to parse the username from the internal format, lower-case the name, if the domain is case-insensitive and then replace spaces if the responder is configured to do so. Reviewed-by: Sumit Bose --- src/util/usertools.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/util/util.h | 6 ++++++ 2 files changed, 46 insertions(+) (limited to 'src/util') diff --git a/src/util/usertools.c b/src/util/usertools.c index ee2e86264..8e5be9788 100644 --- a/src/util/usertools.c +++ b/src/util/usertools.c @@ -831,3 +831,43 @@ char **sss_create_internal_fqname_list(TALLOC_CTX *mem_ctx, return fqname_list; } + +char *sss_output_name(TALLOC_CTX *mem_ctx, + const char *name, + bool case_sensitive, + const char replace_space) +{ + TALLOC_CTX *tmp_ctx = NULL; + errno_t ret; + char *shortname; + char *outname = NULL; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) return NULL; + + ret = sss_parse_internal_fqname(tmp_ctx, name, &shortname, NULL); + if (ret != EOK) { + DEBUG(SSSDBG_CRIT_FAILURE, "sss_parse_internal_fqname failed\n"); + goto done; + } + + outname = sss_get_cased_name(tmp_ctx, shortname, case_sensitive); + if (outname == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, + "sss_get_cased_name failed, skipping\n"); + ret = EIO; + goto done; + } + + outname = sss_replace_space(tmp_ctx, outname, replace_space); + if (outname == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, "sss_replace_space failed\n"); + ret = EIO; + goto done; + } + + outname = talloc_steal(mem_ctx, outname); +done: + talloc_free(tmp_ctx); + return outname; +} diff --git a/src/util/util.h b/src/util/util.h index cd975c2c8..3b8acd1c5 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -290,6 +290,12 @@ char **sss_create_internal_fqname_list(TALLOC_CTX *mem_ctx, const char * const *shortname_list, const char *dom_name); +/* Turn fqname into cased shortname with replaced space. */ +char *sss_output_name(TALLOC_CTX *mem_ctx, + const char *fqname, + bool case_sensitive, + const char replace_space); + /* from backup-file.c */ int backup_file(const char *src, int dbglvl); -- cgit