From f3c749b25cff90dd851629c7d6424664e7ff52cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Wed, 24 Feb 2016 12:33:47 +0100
Subject: [PATCH 14/15] cache_req: hide cache_req_input

It is no longer needed.
---
 src/responder/common/responder_cache_req.c | 148 +++++++----------------------
 src/responder/common/responder_cache_req.h |  13 +--
 src/responder/ifp/ifpsrv_cmd.c             |  17 +---
 3 files changed, 42 insertions(+), 136 deletions(-)

diff --git a/src/responder/common/responder_cache_req.c b/src/responder/common/responder_cache_req.c
index 3964a5f900e1bcdb01501e45e0c6e88fa0c55d1c..abb2b01f224b7263f08924fbdb511894d69160e4 100644
--- a/src/responder/common/responder_cache_req.c
+++ b/src/responder/common/responder_cache_req.c
@@ -1082,10 +1082,12 @@ struct tevent_req *cache_req_send(TALLOC_CTX *mem_ctx,
                                   struct sss_nc_ctx *ncache,
                                   int neg_timeout,
                                   int cache_refresh_percent,
-                                  const char *domain,
-                                  struct cache_req_input *input)
+                                  enum cache_req_type type,
+                                  struct cache_req_data *data,
+                                  const char *domain)
 {
     struct cache_req_state *state = NULL;
+    struct cache_req_input *input = NULL;
     struct tevent_req *req = NULL;
     struct tevent_req *subreq = NULL;
     errno_t ret;
@@ -1096,6 +1098,12 @@ struct tevent_req *cache_req_send(TALLOC_CTX *mem_ctx,
         return NULL;
     }
 
+    input = cache_req_input_create(state, rctx, type, data);
+    if (input == NULL) {
+        ret = ENOMEM;
+        goto immediately;
+    }
+
     CACHE_REQ_DEBUG(SSSDBG_TRACE_FUNC, input, "New request\n");
 
     state->ev = ev;
@@ -1354,29 +1362,6 @@ errno_t cache_req_recv(TALLOC_CTX *mem_ctx,
     return EOK;
 }
 
-static struct tevent_req *
-cache_req_steal_input_and_send(TALLOC_CTX *mem_ctx,
-                               struct tevent_context *ev,
-                               struct resp_ctx *rctx,
-                               struct sss_nc_ctx *ncache,
-                               int neg_timeout,
-                               int cache_refresh_percent,
-                               const char *domain,
-                               struct cache_req_input *input)
-{
-    struct tevent_req *req;
-
-    req = cache_req_send(mem_ctx, ev, rctx, ncache, neg_timeout,
-                         cache_refresh_percent, domain, input);
-    if (req == NULL) {
-        talloc_zfree(input);
-    }
-
-    talloc_steal(req, input);
-
-    return req;
-}
-
 struct tevent_req *
 cache_req_user_by_name_send(TALLOC_CTX *mem_ctx,
                             struct tevent_context *ev,
@@ -1388,19 +1373,12 @@ cache_req_user_by_name_send(TALLOC_CTX *mem_ctx,
                             const char *name)
 {
     struct cache_req_data data;
-    struct cache_req_input *input;
 
     CACHE_REQ_DATA_SET_NAME(&data, name);
 
-    input = cache_req_input_create(mem_ctx, rctx, CACHE_REQ_USER_BY_NAME,
-                                   &data);
-    if (input == NULL) {
-        return NULL;
-    }
-
-    return cache_req_steal_input_and_send(mem_ctx, ev, rctx, ncache,
-                                          neg_timeout, cache_refresh_percent,
-                                          domain, input);
+    return cache_req_send(mem_ctx, ev, rctx, ncache, neg_timeout,
+                          cache_refresh_percent,
+                          CACHE_REQ_USER_BY_NAME, &data, domain);
 }
 
 struct tevent_req *
@@ -1414,19 +1392,12 @@ cache_req_user_by_id_send(TALLOC_CTX *mem_ctx,
                           uid_t uid)
 {
     struct cache_req_data data;
-    struct cache_req_input *input;
 
     CACHE_REQ_DATA_SET_ID(&data, uid);
 
-    input = cache_req_input_create(mem_ctx, rctx, CACHE_REQ_USER_BY_ID,
-                                   &data);
-    if (input == NULL) {
-        return NULL;
-    }
-
-    return cache_req_steal_input_and_send(mem_ctx, ev, rctx, ncache,
-                                          neg_timeout, cache_refresh_percent,
-                                          domain, input);
+    return cache_req_send(mem_ctx, ev, rctx, ncache, neg_timeout,
+                          cache_refresh_percent,
+                          CACHE_REQ_USER_BY_ID, &data, domain);
 }
 
 struct tevent_req *
@@ -1440,19 +1411,12 @@ cache_req_user_by_cert_send(TALLOC_CTX *mem_ctx,
                             const char *pem_cert)
 {
     struct cache_req_data data;
-    struct cache_req_input *input;
 
     CACHE_REQ_DATA_SET_CERT(&data, pem_cert);
 
-    input = cache_req_input_create(mem_ctx, rctx, CACHE_REQ_USER_BY_CERT,
-                                   &data);
-    if (input == NULL) {
-        return NULL;
-    }
-
-    return cache_req_steal_input_and_send(mem_ctx, ev, rctx, ncache,
-                                          neg_timeout, cache_refresh_percent,
-                                          domain, input);
+    return cache_req_send(mem_ctx, ev, rctx, ncache, neg_timeout,
+                          cache_refresh_percent,
+                          CACHE_REQ_USER_BY_CERT, &data, domain);
 }
 
 struct tevent_req *
@@ -1466,19 +1430,12 @@ cache_req_group_by_name_send(TALLOC_CTX *mem_ctx,
                              const char *name)
 {
     struct cache_req_data data;
-    struct cache_req_input *input;
 
     CACHE_REQ_DATA_SET_NAME(&data, name);
 
-    input = cache_req_input_create(mem_ctx, rctx, CACHE_REQ_GROUP_BY_NAME,
-                                   &data);
-    if (input == NULL) {
-        return NULL;
-    }
-
-    return cache_req_steal_input_and_send(mem_ctx, ev, rctx, ncache,
-                                          neg_timeout, cache_refresh_percent,
-                                          domain, input);
+    return cache_req_send(mem_ctx, ev, rctx, ncache, neg_timeout,
+                          cache_refresh_percent,
+                          CACHE_REQ_GROUP_BY_NAME, &data, domain);
 }
 
 struct tevent_req *
@@ -1492,19 +1449,12 @@ cache_req_group_by_id_send(TALLOC_CTX *mem_ctx,
                            gid_t gid)
 {
     struct cache_req_data data;
-    struct cache_req_input *input;
 
     CACHE_REQ_DATA_SET_ID(&data, gid);
 
-    input = cache_req_input_create(mem_ctx, rctx, CACHE_REQ_GROUP_BY_ID,
-                                   &data);
-    if (input == NULL) {
-        return NULL;
-    }
-
-    return cache_req_steal_input_and_send(mem_ctx, ev, rctx, ncache,
-                                          neg_timeout, cache_refresh_percent,
-                                          domain, input);
+    return cache_req_send(mem_ctx, ev, rctx, ncache, neg_timeout,
+                          cache_refresh_percent,
+                          CACHE_REQ_GROUP_BY_ID, &data, domain);
 }
 
 struct tevent_req *
@@ -1518,19 +1468,12 @@ cache_req_initgr_by_name_send(TALLOC_CTX *mem_ctx,
                               const char *name)
 {
     struct cache_req_data data;
-    struct cache_req_input *input;
 
     CACHE_REQ_DATA_SET_NAME(&data, name);
 
-    input = cache_req_input_create(mem_ctx, rctx, CACHE_REQ_INITGROUPS,
-                                   &data);
-    if (input == NULL) {
-        return NULL;
-    }
-
-    return cache_req_steal_input_and_send(mem_ctx, ev, rctx, ncache,
-                                          neg_timeout, cache_refresh_percent,
-                                          domain, input);
+    return cache_req_send(mem_ctx, ev, rctx, ncache, neg_timeout,
+                          cache_refresh_percent,
+                          CACHE_REQ_INITGROUPS, &data, domain);
 }
 
 struct tevent_req *
@@ -1541,18 +1484,11 @@ cache_req_user_by_filter_send(TALLOC_CTX *mem_ctx,
                               const char *filter)
 {
     struct cache_req_data data;
-    struct cache_req_input *input;
 
     CACHE_REQ_DATA_SET_NAME(&data, filter);
 
-    input = cache_req_input_create(mem_ctx, rctx, CACHE_REQ_USER_BY_FILTER,
-                                   &data);
-    if (input == NULL) {
-        return NULL;
-    }
-
-    return cache_req_steal_input_and_send(mem_ctx, ev, rctx, NULL,
-                                          0, 0, domain, input);
+    return cache_req_send(mem_ctx, ev, rctx, NULL, 0, 0,
+                          CACHE_REQ_USER_BY_FILTER, &data, domain);
 }
 
 struct tevent_req *
@@ -1563,18 +1499,11 @@ cache_req_group_by_filter_send(TALLOC_CTX *mem_ctx,
                                const char *filter)
 {
     struct cache_req_data data;
-    struct cache_req_input *input;
 
     CACHE_REQ_DATA_SET_NAME(&data, filter);
 
-    input = cache_req_input_create(mem_ctx, rctx, CACHE_REQ_GROUP_BY_FILTER,
-                                   &data);
-    if (input == NULL) {
-        return NULL;
-    }
-
-    return cache_req_steal_input_and_send(mem_ctx, ev, rctx, NULL,
-                                          0, 0, domain, input);
+    return cache_req_send(mem_ctx, ev, rctx, NULL, 0, 0,
+                          CACHE_REQ_GROUP_BY_FILTER, &data, domain);
 }
 
 struct tevent_req *
@@ -1589,17 +1518,10 @@ cache_req_object_by_sid_send(TALLOC_CTX *mem_ctx,
                              const char **attrs)
 {
     struct cache_req_data data;
-    struct cache_req_input *input;
 
     CACHE_REQ_DATA_SET_SID(&data, sid, attrs);
 
-    input = cache_req_input_create(mem_ctx, rctx, CACHE_REQ_OBJECT_BY_SID,
-                                   &data);
-    if (input == NULL) {
-        return NULL;
-    }
-
-    return cache_req_steal_input_and_send(mem_ctx, ev, rctx, ncache,
-                                          neg_timeout, cache_refresh_percent,
-                                          domain, input);
+    return cache_req_send(mem_ctx, ev, rctx, ncache, neg_timeout,
+                          cache_refresh_percent,
+                          CACHE_REQ_OBJECT_BY_SID, &data, domain);
 }
diff --git a/src/responder/common/responder_cache_req.h b/src/responder/common/responder_cache_req.h
index 5b21d6d3e84469cbdb7223d467738ef156b94e5c..ef8d191233068839a1a0404e02a803be168e11f6 100644
--- a/src/responder/common/responder_cache_req.h
+++ b/src/responder/common/responder_cache_req.h
@@ -77,14 +77,6 @@ enum cache_req_type {
     CACHE_REQ_OBJECT_BY_SID
 };
 
-struct cache_req_input;
-
-struct cache_req_input *
-cache_req_input_create(TALLOC_CTX *mem_ctx,
-                       struct resp_ctx *rctx,
-                       enum cache_req_type type,
-                       struct cache_req_data *data);
-
 /**
  * Currently only SSS_DP_USER and SSS_DP_INITGROUPS are supported.
  *
@@ -96,8 +88,9 @@ struct tevent_req *cache_req_send(TALLOC_CTX *mem_ctx,
                                   struct sss_nc_ctx *ncache,
                                   int neg_timeout,
                                   int cache_refresh_percent,
-                                  const char *domain,
-                                  struct cache_req_input *input);
+                                  enum cache_req_type type,
+                                  struct cache_req_data *data,
+                                  const char *domain);
 
 errno_t cache_req_recv(TALLOC_CTX *mem_ctx,
                        struct tevent_req *req,
diff --git a/src/responder/ifp/ifpsrv_cmd.c b/src/responder/ifp/ifpsrv_cmd.c
index 1bdcc7b25cb3f2659b94bc4135702656f05f5988..25a1a7133e3e42aae146e2d13da8e25b07b51140 100644
--- a/src/responder/ifp/ifpsrv_cmd.c
+++ b/src/responder/ifp/ifpsrv_cmd.c
@@ -480,9 +480,9 @@ static void
 ifp_user_get_attr_lookup(struct tevent_req *subreq)
 {
     struct ifp_user_get_attr_state *state = NULL;
-    struct cache_req_input *input = NULL;
     struct tevent_req *req = NULL;
     struct cache_req_data data;
+    enum cache_req_type type;
     errno_t ret;
 
     req = tevent_req_callback_data(subreq, struct tevent_req);
@@ -499,14 +499,10 @@ ifp_user_get_attr_lookup(struct tevent_req *subreq)
 
     switch (state->search_type) {
     case SSS_DP_USER:
-        input = cache_req_input_create(state, state->rctx,
-                                       CACHE_REQ_USER_BY_NAME,
-                                       &data);
+        type = CACHE_REQ_USER_BY_NAME;
         break;
     case SSS_DP_INITGROUPS:
-        input = cache_req_input_create(state, state->rctx,
-                                       CACHE_REQ_INITGROUPS,
-                                       &data);
+        type = CACHE_REQ_INITGROUPS;
         break;
     default:
         DEBUG(SSSDBG_CRIT_FAILURE, "Unsupported search type [%d]!\n",
@@ -515,14 +511,9 @@ ifp_user_get_attr_lookup(struct tevent_req *subreq)
         return;
     }
 
-    if (input == NULL) {
-        tevent_req_error(req, ENOMEM);
-        return;
-    }
-
     subreq = cache_req_send(state, state->rctx->ev, state->rctx,
                             state->ncache, state->neg_timeout, 0,
-                            state->domname, input);
+                            type, &data, state->domname);
     if (subreq == NULL) {
         tevent_req_error(req, ENOMEM);
         return;
-- 
2.1.0

