Blob Blame History Raw
From 6ab5595ec7360bd4cc4c0494a1e0afedda701961 Mon Sep 17 00:00:00 2001
From: Pavel Reichl <preichl@redhat.com>
Date: Sun, 26 Jan 2014 12:39:43 +0000
Subject: [PATCH 80/80] utils: handling NULL params in sss_parse_name

Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
---
 src/util/usertools.c | 50 +++++++++++++++++++++++++++-----------------------
 src/util/util.h      |  2 +-
 2 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/src/util/usertools.c b/src/util/usertools.c
index 9edae41e0f216f9f0d1660e473f3aa1bf7160b06..fab0a261e82b8c4d8071ced1dac99b8e3b987b00 100644
--- a/src/util/usertools.c
+++ b/src/util/usertools.c
@@ -322,7 +322,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;
@@ -346,31 +346,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;
+    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;
     }
-    *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 (_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 3334476ab83a137d957765fe2c9afba4ad0d014c..7b185bcb4287a4afc5bf67b40164cf69b9beeb19 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -349,7 +349,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);
 
 char *
 sss_get_cased_name(TALLOC_CTX *mem_ctx, const char *orig_name,
-- 
1.8.5.3