>From 425eaf360c00a3195021abf228168b03b695ae45 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Tue, 6 Oct 2015 15:07:48 +0200
Subject: [PATCH 4/4] cache_req: remove raw_name and do not touch orig_name

Parsed name or UPN is now stored in input->name instead of touching
orig_name and storing the original name in raw_name.
---
 src/responder/common/responder_cache_req.c | 43 +++++++++++++++---------------
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/src/responder/common/responder_cache_req.c b/src/responder/common/responder_cache_req.c
index 70a3010eb697cf14874bd1a950cb7a874bc060b4..f69a55726acf7cc4e95b851bef122a5462575753 100644
--- a/src/responder/common/responder_cache_req.c
+++ b/src/responder/common/responder_cache_req.c
@@ -70,11 +70,13 @@ struct cache_req_input {
     enum cache_req_type type;
 
     /* Provided input. */
-    const char *raw_name;
     const char *orig_name;
     uint32_t id;
     const char *cert;
 
+    /* Parsed name or UPN. */
+    const char *name;
+
     /* Data Provider request type resolved from @type.
      * FIXME: This is currently needed for data provider calls. We should
      * refactor responder_dp.c to get rid of this member. */
@@ -125,11 +127,6 @@ cache_req_input_create(TALLOC_CTX *mem_ctx,
             goto fail;
         }
 
-        input->raw_name = talloc_strdup(input, name);
-        if (input->raw_name == NULL) {
-            goto fail;
-        }
-
         input->orig_name = talloc_strdup(input, name);
         if (input->orig_name == NULL) {
             goto fail;
@@ -196,8 +193,8 @@ fail:
 }
 
 static errno_t
-cache_req_input_set_orig_name(struct cache_req_input *input,
-                              const char *name)
+cache_req_input_set_name(struct cache_req_input *input,
+                         const char *name)
 {
     const char *dup;
 
@@ -206,8 +203,8 @@ cache_req_input_set_orig_name(struct cache_req_input *input,
         return ENOMEM;
     }
 
-    talloc_zfree(input->orig_name);
-    input->orig_name = dup;
+    talloc_zfree(input->name);
+    input->name = dup;
 
     return EOK;
 }
@@ -238,8 +235,13 @@ cache_req_input_set_domain(struct cache_req_input *input,
     case CACHE_REQ_GROUP_BY_FILTER:
     case CACHE_REQ_INITGROUPS:
     case CACHE_REQ_INITGROUPS_BY_UPN:
-        name = sss_get_cased_name(tmp_ctx, input->orig_name,
-                                  domain->case_sensitive);
+        if (input->name == NULL) {
+            DEBUG(SSSDBG_CRIT_FAILURE, "Bug: input->name is NULL?\n");
+            ret = ERR_INTERNAL;
+            goto done;
+        }
+
+        name = sss_get_cased_name(tmp_ctx, input->name, domain->case_sensitive);
         if (name == NULL) {
             ret = ENOMEM;
             goto done;
@@ -316,7 +318,7 @@ cache_req_input_assume_upn(struct cache_req_input *input)
     errno_t ret;
     bool bret;
 
-    if (input->raw_name == NULL || strchr(input->raw_name, '@') == NULL) {
+    if (input->orig_name == NULL || strchr(input->orig_name, '@') == NULL) {
         return false;
     }
 
@@ -335,14 +337,14 @@ cache_req_input_assume_upn(struct cache_req_input *input)
     }
 
     if (bret == true) {
-        ret = cache_req_input_set_orig_name(input, input->raw_name);
+        ret = cache_req_input_set_name(input, input->orig_name);
         if (ret != EOK) {
             DEBUG(SSSDBG_CRIT_FAILURE,
                   "cache_req_input_set_orig_name() failed\n");
             return false;
         }
 
-        DEBUG(SSSDBG_TRACE_FUNC, "Assuming UPN %s\n", input->raw_name);
+        DEBUG(SSSDBG_TRACE_FUNC, "Assuming UPN %s\n", input->orig_name);
     }
 
     return bret;
@@ -909,13 +911,10 @@ static void cache_req_input_parsed(struct tevent_req *subreq)
     ret = sss_parse_inp_recv(subreq, state, &name, &domain);
     switch (ret) {
     case EOK:
-        if (strcmp(name, state->input->orig_name) != 0) {
-            /* The name has changed during input parse phase. */
-            ret = cache_req_input_set_orig_name(state->input, name);
-            if (ret != EOK) {
-                tevent_req_error(req, ret);
-                return;
-            }
+        ret = cache_req_input_set_name(state->input, name);
+        if (ret != EOK) {
+            tevent_req_error(req, ret);
+            return;
         }
         break;
     case ERR_DOMAIN_NOT_FOUND:
-- 
1.9.3

