summaryrefslogtreecommitdiffstats
path: root/src/util/usertools.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/usertools.c')
-rw-r--r--src/util/usertools.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/util/usertools.c b/src/util/usertools.c
index 18639d9b6..bea7e58a8 100644
--- a/src/util/usertools.c
+++ b/src/util/usertools.c
@@ -716,3 +716,59 @@ errno_t sss_user_by_name_or_uid(const char *input, uid_t *_uid, gid_t *_gid)
}
return EOK;
}
+
+/* Accepts fqname in the format shortname@domname only. */
+errno_t sss_parse_internal_fqname(TALLOC_CTX *mem_ctx,
+ const char *fqname,
+ char **_shortname,
+ char **_dom_name)
+{
+ errno_t ret;
+ char *separator;
+ char *shortname = NULL;
+ char *dom_name = NULL;
+ size_t shortname_len;
+ TALLOC_CTX *tmp_ctx;
+
+ if (fqname == NULL) {
+ return EINVAL;
+ }
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ separator = strrchr(fqname, '@');
+ if (separator == NULL || *(separator + 1) == '\0' || separator == fqname) {
+ /*The name does not contain name or domain component. */
+ ret = ERR_WRONG_NAME_FORMAT;
+ goto done;
+ }
+
+ if (_dom_name != NULL) {
+ dom_name = talloc_strdup(tmp_ctx, separator + 1);
+ if (dom_name == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ *_dom_name = talloc_steal(mem_ctx, dom_name);
+ }
+
+ if (_shortname != NULL) {
+ shortname_len = strlen(fqname) - strlen(separator);
+ shortname = talloc_strndup(tmp_ctx, fqname, shortname_len);
+ if (shortname == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ *_shortname = talloc_steal(mem_ctx, shortname);
+ }
+
+ ret = EOK;
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}