summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorPavel Reichl <preichl@redhat.com>2014-01-26 12:39:43 +0000
committerJakub Hrozek <jhrozek@redhat.com>2014-01-28 16:42:33 +0100
commit7e7a8b9e67808d69663d2178eecec3769191f5e7 (patch)
tree94161e8d7da67406b4e4ecd583d617b6d7ab6d31 /src/util
parent88ca28caa4675026d4ab222c9e4ef635da57f610 (diff)
downloadsssd-7e7a8b9e67808d69663d2178eecec3769191f5e7.tar.gz
sssd-7e7a8b9e67808d69663d2178eecec3769191f5e7.tar.xz
sssd-7e7a8b9e67808d69663d2178eecec3769191f5e7.zip
utils: handling NULL params in sss_parse_name
Diffstat (limited to 'src/util')
-rw-r--r--src/util/usertools.c54
-rw-r--r--src/util/util.h2
2 files changed, 30 insertions, 26 deletions
diff --git a/src/util/usertools.c b/src/util/usertools.c
index c77aa7ce0..f0d09ffc2 100644
--- a/src/util/usertools.c
+++ b/src/util/usertools.c
@@ -303,7 +303,7 @@ done:
int sss_parse_name(TALLOC_CTX *memctx,
struct sss_names_ctx *snctx,
- const char *orig, char **domain, char **name)
+ const char *orig, char **_domain, char **_name)
{
pcre *re = snctx->re;
const char *result;
@@ -327,31 +327,35 @@ int sss_parse_name(TALLOC_CTX *memctx,
strnum = ret;
- result = NULL;
- ret = pcre_get_named_substring(re, orig, ovec, strnum, "name", &result);
- if (ret < 0 || !result) {
- DEBUG(2, ("Name not found!\n"));
- return EINVAL;
- }
- *name = talloc_strdup(memctx, result);
- pcre_free_substring(result);
- if (!*name) return ENOMEM;
-
-
- result = NULL;
- ret = pcre_get_named_substring(re, orig, ovec, strnum, "domain", &result);
- if (ret < 0 || !result) {
- DEBUG(4, ("Domain not provided!\n"));
- *domain = NULL;
- } else {
- /* ignore "" string */
- if (*result) {
- *domain = talloc_strdup(memctx, result);
- pcre_free_substring(result);
- if (!*domain) return ENOMEM;
+ if (_name != NULL) {
+ result = NULL;
+ ret = pcre_get_named_substring(re, orig, ovec, strnum, "name", &result);
+ if (ret < 0 || !result) {
+ DEBUG(2, ("Name not found!\n"));
+ return EINVAL;
+ }
+ *_name = talloc_strdup(memctx, result);
+ pcre_free_substring(result);
+ if (!*_name) return ENOMEM;
+ }
+
+ if (_domain != NULL) {
+ result = NULL;
+ ret = pcre_get_named_substring(re, orig, ovec, strnum, "domain",
+ &result);
+ if (ret < 0 || !result) {
+ DEBUG(4, ("Domain not provided!\n"));
+ *_domain = NULL;
} else {
- pcre_free_substring(result);
- *domain = NULL;
+ /* ignore "" string */
+ if (*result) {
+ *_domain = talloc_strdup(memctx, result);
+ pcre_free_substring(result);
+ if (!*_domain) return ENOMEM;
+ } else {
+ pcre_free_substring(result);
+ *_domain = NULL;
+ }
}
}
diff --git a/src/util/util.h b/src/util/util.h
index 4a9dbb75f..04fe0cefb 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -345,7 +345,7 @@ int sss_names_init(TALLOC_CTX *mem_ctx,
int sss_parse_name(TALLOC_CTX *memctx,
struct sss_names_ctx *snctx,
- const char *orig, char **domain, char **name);
+ const char *orig, char **_domain, char **_name);
int sss_parse_name_for_domains(TALLOC_CTX *memctx,
struct sss_domain_info *domains,