summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorNikolai Kondrashov <Nikolai.Kondrashov@redhat.com>2017-03-22 14:32:35 +0200
committerJakub Hrozek <jhrozek@redhat.com>2017-05-10 15:03:04 +0200
commita012a71f21bf1a4687e58085f19c18cc5b2bbadd (patch)
tree7048779c2f11e16a749e86545aed910e70200962 /src/util
parente98d085b529e0ae5e07a717ce3b30f3943be0ee0 (diff)
downloadsssd-a012a71f21bf1a4687e58085f19c18cc5b2bbadd.tar.gz
sssd-a012a71f21bf1a4687e58085f19c18cc5b2bbadd.tar.xz
sssd-a012a71f21bf1a4687e58085f19c18cc5b2bbadd.zip
NSS: Move output name formatting to utils
Move NSS nss_get_name_from_msg and the core of sized_output_name to the utils to make them available to provider and other responders. Reviewed-by: Pavel Březina <pbrezina@redhat.com>
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);