summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2013-05-10 18:19:12 +0200
committerJakub Hrozek <jhrozek@redhat.com>2013-05-30 13:44:35 +0200
commit1987bff88e01c74d647dd2db4f541ac311537e1a (patch)
tree5b74ee7f10bc033009a1822b69010b64b249c718 /src/util
parentb36153ce4c3eeb19274ce32e82949da446184406 (diff)
downloadsssd-1987bff88e01c74d647dd2db4f541ac311537e1a.tar.gz
sssd-1987bff88e01c74d647dd2db4f541ac311537e1a.tar.xz
sssd-1987bff88e01c74d647dd2db4f541ac311537e1a.zip
Add utility functions for formatting fully-qualified names
Instead of using printf-like functions directly, provide two wrappers that would encapsulate formatting the fully-qualified names. No functional change is present in this patch.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/usertools.c25
-rw-r--r--src/util/util.h16
2 files changed, 41 insertions, 0 deletions
diff --git a/src/util/usertools.c b/src/util/usertools.c
index 91110f263..20ca407f3 100644
--- a/src/util/usertools.c
+++ b/src/util/usertools.c
@@ -507,3 +507,28 @@ sss_get_cased_name_list(TALLOC_CTX *mem_ctx, const char * const *orig,
*_cased = out;
return EOK;
}
+
+static inline const char *
+safe_fq_str(struct sss_names_ctx *nctx, uint8_t part, const char *str)
+{
+
+ return nctx->fq_flags & part ? str : "";
+}
+
+char *
+sss_tc_fqname(TALLOC_CTX *mem_ctx, struct sss_names_ctx *nctx,
+ struct sss_domain_info *domain, const char *name)
+{
+ if (domain == NULL || nctx == NULL) return NULL;
+
+ return talloc_asprintf(mem_ctx, nctx->fq_fmt, name, domain->name);
+}
+
+int
+sss_fqname(char *str, size_t size, struct sss_names_ctx *nctx,
+ struct sss_domain_info *domain, const char *name)
+{
+ if (domain == NULL || nctx == NULL) return -EINVAL;
+
+ return snprintf(str, size, nctx->fq_fmt, name, domain->name);
+}
diff --git a/src/util/util.h b/src/util/util.h
index bdb04a8f3..2f65fa201 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -43,6 +43,7 @@
#include <ldb.h>
#include <dhash.h>
+#include "confdb/confdb.h"
#include "util/atomic_io.h"
#include "util/util_errors.h"
#include "util/util_safealign.h"
@@ -365,6 +366,21 @@ errno_t
sss_get_cased_name_list(TALLOC_CTX *mem_ctx, const char * const *orig,
bool case_sensitive, const char ***_cased);
+/* Return fully-qualified name according to the fq_fmt. The name is allocated using
+ * talloc on top of mem_ctx
+ */
+char *
+sss_tc_fqname(TALLOC_CTX *mem_ctx, struct sss_names_ctx *nctx,
+ struct sss_domain_info *domain, const char *name);
+
+/* Return fully-qualified name formatted according to the fq_fmt. The buffer in "str" is
+ * "size" bytes long. Returns the number of bytes written on success or a negative
+ * value of failure.
+ */
+int
+sss_fqname(char *str, size_t size, struct sss_names_ctx *nctx,
+ struct sss_domain_info *domain, const char *name);
+
/* from backup-file.c */
int backup_file(const char *src, int dbglvl);