summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2016-06-19 07:14:23 +0200
committerJakub Hrozek <jhrozek@redhat.com>2016-07-07 10:24:31 +0200
commit87c6d9ea92d83460457353cfea6c5bde8744994a (patch)
treec64f26590a7408fd7ce2c81c02301fa241878070 /src/util
parent8858d820445cffb67ef8cf790b3a8d37b008d654 (diff)
downloadsssd-87c6d9ea92d83460457353cfea6c5bde8744994a.tar.gz
sssd-87c6d9ea92d83460457353cfea6c5bde8744994a.tar.xz
sssd-87c6d9ea92d83460457353cfea6c5bde8744994a.zip
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 <sbose@redhat.com>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/usertools.c40
-rw-r--r--src/util/util.h6
2 files changed, 46 insertions, 0 deletions
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);