From 9f0e10931624dbdb26bb89fa5825fec62bd52428 Mon Sep 17 00:00:00 2001
From: Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
Date: Wed, 20 Jul 2016 18:53:57 +0300
Subject: [PATCH 09/15] NSS: Make fill_pwent take cmdctx, not nctx

Make fill_pwent in nsssrv_cmd.c accept more specific command context,
instead of just NSS context to prepare for addition of command-specific
session-recording code.
---
 src/responder/nss/nsssrv_cmd.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c
index 7c6ed5d..9eccf78 100644
--- a/src/responder/nss/nsssrv_cmd.c
+++ b/src/responder/nss/nsssrv_cmd.c
@@ -358,7 +358,7 @@ done:
  *
  * @param packet        The packet to transfer user information to.
  * @param dom           Domain the users belong to.
- * @param nctx          NSS context the operation is carried within.
+ * @param cmdctx        The command context the operation is carried within.
  * @param filter_users  True if users present in negative cache should be
  *                      skipped, false otherwise.
  * @param pw_mmap_cache True if unskipped users should be stored in mmap
@@ -372,11 +372,12 @@ done:
  */
 static int fill_pwent(struct sss_packet *packet,
                       struct sss_domain_info *dom,
-                      struct nss_ctx *nctx,
+                      struct nss_cmd_ctx *cmdctx,
                       bool filter_users, bool pw_mmap_cache,
                       struct ldb_message **msgs,
                       int *count)
 {
+    struct nss_ctx *nctx;
     struct ldb_message *msg;
     uint8_t *body;
     const char *upn;
@@ -397,6 +398,8 @@ static int fill_pwent(struct sss_packet *packet,
     TALLOC_CTX *tmp_ctx = NULL;
     struct sss_nss_homedir_ctx homedir_ctx;
 
+    nctx = talloc_get_type(cmdctx->cctx->rctx->pvt_ctx, struct nss_ctx);
+
     to_sized_string(&pwfield, nctx->pwfield);
 
     rp = 2*sizeof(uint32_t);
@@ -554,12 +557,10 @@ static int nss_cmd_getpw_send_reply(struct nss_dom_ctx *dctx, bool filter)
     struct nss_cmd_ctx *cmdctx = dctx->cmdctx;
     struct cli_ctx *cctx = cmdctx->cctx;
     struct cli_protocol *pctx;
-    struct nss_ctx *nctx;
     int ret;
     int i;
 
     pctx = talloc_get_type(cctx->protocol_ctx, struct cli_protocol);
-    nctx = talloc_get_type(cctx->rctx->pvt_ctx, struct nss_ctx);
 
     ret = sss_packet_new(pctx->creq, 0,
                          sss_packet_get_cmd(pctx->creq->in),
@@ -571,7 +572,7 @@ static int nss_cmd_getpw_send_reply(struct nss_dom_ctx *dctx, bool filter)
 
     ret = fill_pwent(pctx->creq->out,
                      dctx->domain,
-                     nctx, filter, true,
+                     cmdctx, filter, true,
                      dctx->res->msgs, &i);
     if (ret) {
         return ret;
@@ -2499,7 +2500,7 @@ static int nss_cmd_getpwent(struct cli_ctx *cctx)
     return nss_cmd_getpwent_immediate(cmdctx);
 }
 
-static int nss_cmd_retpwent(struct cli_ctx *cctx, int num);
+static int nss_cmd_retpwent(struct nss_cmd_ctx *cmdctx, int num);
 static int nss_cmd_getpwent_immediate(struct nss_cmd_ctx *cmdctx)
 {
     struct cli_protocol *pctx;
@@ -2525,7 +2526,7 @@ static int nss_cmd_getpwent_immediate(struct nss_cmd_ctx *cmdctx)
         return ret;
     }
 
-    ret = nss_cmd_retpwent(cmdctx->cctx, num);
+    ret = nss_cmd_retpwent(cmdctx, num);
 
     sss_packet_set_error(pctx->creq->out, ret);
     sss_cmd_done(cmdctx->cctx, cmdctx);
@@ -2533,7 +2534,7 @@ static int nss_cmd_getpwent_immediate(struct nss_cmd_ctx *cmdctx)
     return EOK;
 }
 
-static int nss_cmd_retpwent(struct cli_ctx *cctx, int num)
+static int nss_cmd_retpwent(struct nss_cmd_ctx *cmdctx, int num)
 {
     struct cli_protocol *pctx;
     struct nss_state_ctx *state_ctx;
@@ -2544,9 +2545,9 @@ static int nss_cmd_retpwent(struct cli_ctx *cctx, int num)
     int n = 0;
     int ret = ENOENT;
 
-    pctx = talloc_get_type(cctx->protocol_ctx, struct cli_protocol);
-    state_ctx = talloc_get_type(cctx->state_ctx, struct nss_state_ctx);
-    nctx = talloc_get_type(cctx->rctx->pvt_ctx, struct nss_ctx);
+    pctx = talloc_get_type(cmdctx->cctx->protocol_ctx, struct cli_protocol);
+    state_ctx = talloc_get_type(cmdctx->cctx->state_ctx, struct nss_state_ctx);
+    nctx = talloc_get_type(cmdctx->cctx->rctx->pvt_ctx, struct nss_ctx);
     if (!nctx->pctx) goto none;
 
     gctx = nctx->pctx;
@@ -2579,7 +2580,7 @@ static int nss_cmd_retpwent(struct cli_ctx *cctx, int num)
 
         msgs = &(pdom->res->msgs[state_ctx->pwent.cur]);
 
-        ret = fill_pwent(pctx->creq->out, pdom->domain, nctx,
+        ret = fill_pwent(pctx->creq->out, pdom->domain, cmdctx,
                          true, false, msgs, &n);
 
         state_ctx->pwent.cur += n;
-- 
2.8.1

