From fae996319dd206f0d8081e8465558faf0b4858e8 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Thu, 19 Jan 2012 20:38:40 -0500
Subject: [PATCH] RESPONDER: Extend sss_dp_account_send() to include extra
 data

Some NSS maps such as 'services' require more values to be passed
to the data provider than just the name or ID. In these cases, we
will amend an optional component to filter value to pass to the
data provider backend.
---
 src/responder/common/responder.h           |    3 +-
 src/responder/common/responder_dp.c        |   31 +++++++++++++++++++++------
 src/responder/nss/nsssrv_cmd.c             |    8 +++---
 src/responder/pam/pamsrv_cmd.c             |    2 +-
 src/responder/sudo/sudosrv_get_sudorules.c |    2 +-
 5 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/src/responder/common/responder.h b/src/responder/common/responder.h
index cbac67b56bc7526adced0c43ccd5ebcbfdffdf41..c27de3115640fe1b969601c9d55f88eca88fc1b1 100644
--- a/src/responder/common/responder.h
+++ b/src/responder/common/responder.h
@@ -192,7 +192,8 @@ sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
                         bool fast_reply,
                         int type,
                         const char *opt_name,
-                        uint32_t opt_id);
+                        uint32_t opt_id,
+                        const char *extra);
 errno_t
 sss_dp_get_account_recv(TALLOC_CTX *mem_ctx,
                         struct tevent_req *req,
diff --git a/src/responder/common/responder_dp.c b/src/responder/common/responder_dp.c
index f51e2496a165cc2b776af776f2e9d1ea75b8e62c..6bc086c2a745802ee961d71f2f3162a2ae3cc1b7 100644
--- a/src/responder/common/responder_dp.c
+++ b/src/responder/common/responder_dp.c
@@ -247,7 +247,8 @@ sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
                         bool fast_reply,
                         int type,
                         const char *opt_name,
-                        uint32_t opt_id)
+                        uint32_t opt_id,
+                        const char *extra)
 {
     errno_t ret;
     int hret;
@@ -312,13 +313,29 @@ sss_dp_get_account_send(TALLOC_CTX *mem_ctx,
     state->key->type = HASH_KEY_STRING;
 
     if (opt_name) {
-        filter = talloc_asprintf(state, "name=%s", opt_name);
-        state->key->str = talloc_asprintf(state->key, "%d:%s@%s",
-                                          type, opt_name, dom->name);
+        if (extra) {
+            filter = talloc_asprintf(state, "name=%s:%s",
+                                     opt_name, extra);
+            state->key->str = talloc_asprintf(state->key, "%d:%s:%s@%s",
+                                              type, opt_name,
+                                              extra, dom->name);
+        } else {
+            filter = talloc_asprintf(state, "name=%s", opt_name);
+            state->key->str = talloc_asprintf(state->key, "%d:%s@%s",
+                                              type, opt_name, dom->name);
+        }
     } else if (opt_id) {
-        filter = talloc_asprintf(state, "idnumber=%u", opt_id);
-        state->key->str = talloc_asprintf(state->key, "%d:%d@%s",
-                                          type, opt_id, dom->name);
+        if (extra) {
+            filter = talloc_asprintf(state, "idnumber=%u:%s",
+                                     opt_id, extra);
+            state->key->str = talloc_asprintf(state->key, "%d:%d:%s@%s",
+                                              type, opt_id,
+                                              extra, dom->name);
+        } else {
+            filter = talloc_asprintf(state, "idnumber=%u", opt_id);
+            state->key->str = talloc_asprintf(state->key, "%d:%d@%s",
+                                              type, opt_id, dom->name);
+        }
     } else {
         filter = talloc_strdup(state, ENUM_INDICATOR);
         state->key->str = talloc_asprintf(state->key, "%d:*@%s",
diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c
index 781bdf9a471ac241d1ad8b8134d142e14243bc41..28021106a042a6a6f0ddad686bdbdaa189d86f19 100644
--- a/src/responder/nss/nsssrv_cmd.c
+++ b/src/responder/nss/nsssrv_cmd.c
@@ -638,7 +638,7 @@ errno_t check_cache(struct nss_dom_ctx *dctx,
          * immediately.
          */
         req = sss_dp_get_account_send(cctx, cctx->rctx, dctx->domain, true,
-                                      req_type, opt_name, opt_id);
+                                      req_type, opt_name, opt_id, NULL);
         if (!req) {
             DEBUG(SSSDBG_CRIT_FAILURE,
                   ("Out of memory sending out-of-band data provider "
@@ -667,7 +667,7 @@ errno_t check_cache(struct nss_dom_ctx *dctx,
         }
 
         req = sss_dp_get_account_send(cctx, cctx->rctx, dctx->domain, true,
-                                      req_type, opt_name, opt_id);
+                                      req_type, opt_name, opt_id, NULL);
         if (!req) {
             DEBUG(SSSDBG_CRIT_FAILURE,
                   ("Out of memory sending data provider request\n"));
@@ -1402,7 +1402,7 @@ static errno_t nss_cmd_setpwent_step(struct setent_step_ctx *step_ctx)
             dctx->check_provider = false;
 
             dpreq = sss_dp_get_account_send(step_ctx, rctx, dctx->domain, true,
-                                          SSS_DP_USER, NULL, 0);
+                                          SSS_DP_USER, NULL, 0, NULL);
             if (!dpreq) {
                 DEBUG(SSSDBG_MINOR_FAILURE,
                       ("Enum Cache refresh for domain [%s] failed."
@@ -2709,7 +2709,7 @@ static errno_t nss_cmd_setgrent_step(struct setent_step_ctx *step_ctx)
             step_ctx->returned_to_mainloop = true;
             /* Only do this once per provider */
             dpreq = sss_dp_get_account_send(step_ctx, rctx, dctx->domain, true,
-                                          SSS_DP_USER, NULL, 0);
+                                          SSS_DP_USER, NULL, 0, NULL);
             if (!dpreq) {
                 DEBUG(SSSDBG_MINOR_FAILURE,
                       ("Enum Cache refresh for domain [%s] failed."
diff --git a/src/responder/pam/pamsrv_cmd.c b/src/responder/pam/pamsrv_cmd.c
index 4a98dd6383e6177c3a18ae19322cc8690b33ad88..8cb6422177271289131c3b0d035c4fcf21791074 100644
--- a/src/responder/pam/pamsrv_cmd.c
+++ b/src/responder/pam/pamsrv_cmd.c
@@ -953,7 +953,7 @@ static int pam_check_user_search(struct pam_auth_req *preq)
 
         dpreq = sss_dp_get_account_send(preq, preq->cctx->rctx,
                                         dom, false, SSS_DP_INITGROUPS,
-                                        name, 0);
+                                        name, 0, NULL);
         if (!dpreq) {
             DEBUG(SSSDBG_CRIT_FAILURE,
                   ("Out of memory sending data provider request\n"));
diff --git a/src/responder/sudo/sudosrv_get_sudorules.c b/src/responder/sudo/sudosrv_get_sudorules.c
index fca6257d81a3f7dd364aec80b56db4639a741b1e..b1c3fa5e8c385b588b00cc87334881aaf064a41a 100644
--- a/src/responder/sudo/sudosrv_get_sudorules.c
+++ b/src/responder/sudo/sudosrv_get_sudorules.c
@@ -136,7 +136,7 @@ static errno_t sudosrv_get_user(struct sudo_dom_ctx *dctx)
              cache_expire < time(NULL)) {
             dpreq = sss_dp_get_account_send(cli_ctx, cli_ctx->rctx,
                                             dom, false, SSS_DP_INITGROUPS,
-                                            cmd_ctx->username, 0);
+                                            cmd_ctx->username, 0, NULL);
             if (!dpreq) {
                 DEBUG(SSSDBG_CRIT_FAILURE,
                       ("Out of memory sending data provider request\n"));
-- 
1.7.7.5

