summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/usertools.c67
-rw-r--r--src/util/util.h9
2 files changed, 76 insertions, 0 deletions
diff --git a/src/util/usertools.c b/src/util/usertools.c
index 7b87c567a..5dfe6d776 100644
--- a/src/util/usertools.c
+++ b/src/util/usertools.c
@@ -816,3 +816,70 @@ done:
talloc_free(tmp_ctx);
return outname;
}
+
+const char *
+sss_get_name_from_msg(struct sss_domain_info *domain,
+ struct ldb_message *msg)
+{
+ const char *name;
+
+ /* If domain has a view associated we return overridden name
+ * if possible. */
+ if (DOM_HAS_VIEWS(domain)) {
+ name = ldb_msg_find_attr_as_string(msg, OVERRIDE_PREFIX SYSDB_NAME,
+ NULL);
+ if (name != NULL) {
+ return name;
+ }
+ }
+
+ /* Otherwise we try to return name override from
+ * Default Truest View for trusted users. */
+ name = ldb_msg_find_attr_as_string(msg, SYSDB_DEFAULT_OVERRIDE_NAME, NULL);
+ if (name != NULL) {
+ return name;
+ }
+
+ /* If no override is found we return the original name. */
+ return ldb_msg_find_attr_as_string(msg, SYSDB_NAME, NULL);
+}
+
+int sss_output_fqname(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *domain,
+ const char *name,
+ char override_space,
+ char **_output_name)
+{
+ TALLOC_CTX *tmp_ctx = NULL;
+ errno_t ret;
+ char *output_name;
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ output_name = sss_output_name(tmp_ctx, name, domain->case_preserve,
+ override_space);
+ if (output_name == NULL) {
+ ret = EIO;
+ goto done;
+ }
+
+ if (domain->fqnames) {
+ output_name = sss_tc_fqname(tmp_ctx, domain->names,
+ domain, output_name);
+ if (output_name == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "sss_tc_fqname failed\n");
+ ret = EIO;
+ goto done;
+ }
+ }
+
+ *_output_name = talloc_steal(mem_ctx, output_name);
+ ret = EOK;
+done:
+ talloc_zfree(tmp_ctx);
+ return ret;
+}
diff --git a/src/util/util.h b/src/util/util.h
index 4ef13ced4..5ba4c36ca 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -304,6 +304,15 @@ char *sss_output_name(TALLOC_CTX *mem_ctx,
bool case_sensitive,
const char replace_space);
+int sss_output_fqname(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *domain,
+ const char *name,
+ char override_space,
+ char **_output_name);
+
+const char *sss_get_name_from_msg(struct sss_domain_info *domain,
+ struct ldb_message *msg);
+
/* from backup-file.c */
int backup_file(const char *src, int dbglvl);