From 40af1d1f6aaa595ba131679b55707c268f9a62c1 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Thu, 11 Oct 2012 14:50:33 +0200 Subject: [PATCH 2/3] Check for subdomains if getpwuid or getgrgid are the first requests Fixes https://fedorahosted.org/sssd/ticket/1561 --- src/responder/nss/nsssrv_cmd.c | 72 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 72 insertions(+), 0 deletions(-) diff --git a/src/responder/nss/nsssrv_cmd.c b/src/responder/nss/nsssrv_cmd.c index 26a3473..42d32e9 100644 --- a/src/responder/nss/nsssrv_cmd.c +++ b/src/responder/nss/nsssrv_cmd.c @@ -1090,6 +1090,7 @@ done: } } +static void nss_cmd_getpwuid_cb(struct tevent_req *req); static int nss_cmd_getpwuid(struct cli_ctx *cctx) { struct nss_cmd_ctx *cmdctx; @@ -1098,6 +1099,7 @@ static int nss_cmd_getpwuid(struct cli_ctx *cctx) uint8_t *body; size_t blen; int ret; + struct tevent_req *req; nctx = talloc_get_type(cctx->rctx->pvt_ctx, struct nss_ctx); @@ -1137,6 +1139,17 @@ static int nss_cmd_getpwuid(struct cli_ctx *cctx) dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider); + if (cctx->rctx->get_domains_last_call.tv_sec == 0) { + req = sss_dp_get_domains_send(cctx->rctx, cctx->rctx, false, NULL); + if (req == NULL) { + ret = ENOMEM; + } else { + tevent_req_set_callback(req, nss_cmd_getpwuid_cb, dctx); + ret = EAGAIN; + } + goto done; + } + /* ok, find it ! */ ret = nss_cmd_getpwuid_search(dctx); if (ret == EOK) { @@ -1148,6 +1161,29 @@ done: return nss_cmd_done(cmdctx, ret); } +static void nss_cmd_getpwuid_cb(struct tevent_req *req) +{ + struct nss_dom_ctx *dctx = tevent_req_callback_data(req, struct nss_dom_ctx); + struct nss_cmd_ctx *cmdctx = dctx->cmdctx; + errno_t ret; + + ret = sss_dp_get_domains_recv(req); + talloc_free(req); + if (ret != EOK) { + goto done; + } + + /* ok, find it ! */ + ret = nss_cmd_getpwuid_search(dctx); + if (ret == EOK) { + /* we have results to return */ + ret = nss_cmd_getpw_send_reply(dctx, true); + } + +done: + nss_cmd_done(cmdctx, ret); +} + /* to keep it simple at this stage we are retrieving the * full enumeration again for each request for each process * and we also block on setpwent() for the full time needed @@ -2564,6 +2600,7 @@ done: } } +static void nss_cmd_getgrgid_cb(struct tevent_req *req); static int nss_cmd_getgrgid(struct cli_ctx *cctx) { struct nss_cmd_ctx *cmdctx; @@ -2572,6 +2609,7 @@ static int nss_cmd_getgrgid(struct cli_ctx *cctx) uint8_t *body; size_t blen; int ret; + struct tevent_req *req; nctx = talloc_get_type(cctx->rctx->pvt_ctx, struct nss_ctx); @@ -2611,6 +2649,17 @@ static int nss_cmd_getgrgid(struct cli_ctx *cctx) dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider); + if (cctx->rctx->get_domains_last_call.tv_sec == 0) { + req = sss_dp_get_domains_send(cctx->rctx, cctx->rctx, false, NULL); + if (req == NULL) { + ret = ENOMEM; + } else { + tevent_req_set_callback(req, nss_cmd_getgrgid_cb, dctx); + ret = EAGAIN; + } + goto done; + } + /* ok, find it ! */ ret = nss_cmd_getgrgid_search(dctx); if (ret == EOK) { @@ -2622,6 +2671,29 @@ done: return nss_cmd_done(cmdctx, ret); } +static void nss_cmd_getgrgid_cb(struct tevent_req *req) +{ + struct nss_dom_ctx *dctx = tevent_req_callback_data(req, struct nss_dom_ctx); + struct nss_cmd_ctx *cmdctx = dctx->cmdctx; + errno_t ret; + + ret = sss_dp_get_domains_recv(req); + talloc_free(req); + if (ret != EOK) { + goto done; + } + + /* ok, find it ! */ + ret = nss_cmd_getgrgid_search(dctx); + if (ret == EOK) { + /* we have results to return */ + ret = nss_cmd_getpw_send_reply(dctx, true); + } + +done: + nss_cmd_done(cmdctx, ret); +} + /* to keep it simple at this stage we are retrieving the * full enumeration again for each request for each process * and we also block on setgrent() for the full time needed -- 1.7.7.6