>From 904d9e8a887b7ddfa456bbb12186478131a6850a Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 10 Dec 2013 21:49:45 +0100 Subject: [PATCH 2/4] LDAP: Pass a private context to enumeration ptask instead of hardcoded connection Previously, the sdap-domain enumeration request used a single connection context to download all the data. Now we'd like to use different connections to download different objects, so the ID context is passed in and the request itself decides which connection to use for the sdap-domain enumeration. --- src/providers/ad/ad_id.c | 12 ++++++++---- src/providers/ad/ad_init.c | 7 ++++--- src/providers/ad/ad_subdomains.c | 8 +++++--- src/providers/ipa/ipa_subdomains.c | 8 +++++--- src/providers/ldap/ldap_common.c | 15 +++++++++------ src/providers/ldap/ldap_common.h | 17 +++++++++-------- src/providers/ldap/ldap_id_enum.c | 21 ++++++++++++--------- 7 files changed, 52 insertions(+), 36 deletions(-) diff --git a/src/providers/ad/ad_id.c b/src/providers/ad/ad_id.c index 3a90a17f387a6714958e31d603a50ab8e58b82a6..97599c3cb1c599995fba0157e51f9db949f53938 100644 --- a/src/providers/ad/ad_id.c +++ b/src/providers/ad/ad_id.c @@ -420,6 +420,7 @@ ad_check_online(struct be_req *be_req) } struct ad_enumeration_state { + struct ad_id_ctx *id_ctx; struct ldap_enum_ctx *ectx; struct sdap_id_op *sdap_op; struct tevent_context *ev; @@ -449,6 +450,7 @@ ad_enumeration_send(TALLOC_CTX *mem_ctx, ectx = talloc_get_type(pvt, struct ldap_enum_ctx); if (ectx == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, ("Cannot retrieve ldap_enum_ctx!\n")); ret = EFAULT; goto fail; } @@ -456,8 +458,10 @@ ad_enumeration_send(TALLOC_CTX *mem_ctx, state->ectx = ectx; state->ev = ev; state->sdom = ectx->sdom; + state->id_ctx = talloc_get_type(ectx->pvt, struct ad_id_ctx); - state->sdap_op = sdap_id_op_create(state, ectx->conn->conn_cache); + state->sdap_op = sdap_id_op_create(state, + state->id_ctx->ldap_ctx->conn_cache); if (state->sdap_op == NULL) { DEBUG(SSSDBG_OP_FAILURE, ("sdap_id_op_create failed.\n")); ret = ENOMEM; @@ -523,7 +527,7 @@ ad_enumeration_conn_done(struct tevent_req *subreq) } subreq = ad_master_domain_send(state, state->ev, - state->ectx->conn, + state->id_ctx->ldap_ctx, state->sdap_op, state->sdom->dom->name); if (subreq == NULL) { @@ -569,8 +573,8 @@ ad_enumeration_master_done(struct tevent_req *subreq) return; } - subreq = sdap_dom_enum_send(state, state->ev, state->ectx->ctx, - state->sdom, state->ectx->conn); + subreq = sdap_dom_enum_send(state, state->ev, state->id_ctx->sdap_id_ctx, + state->sdom, state->id_ctx->ldap_ctx); if (subreq == NULL) { /* The ptask API will reschedule the enumeration on its own on * failure */ diff --git a/src/providers/ad/ad_init.c b/src/providers/ad/ad_init.c index 858b445d3d294635e5ca17c0be492a34865deaf8..b99caac0c73f3a757869a9ad549a57e2e34d2f7d 100644 --- a/src/providers/ad/ad_init.c +++ b/src/providers/ad/ad_init.c @@ -205,11 +205,12 @@ sssm_ad_id_init(struct be_ctx *bectx, goto done; } - ret = sdap_id_setup_tasks(ad_ctx->sdap_id_ctx, - ad_ctx->sdap_id_ctx->conn, + ret = sdap_id_setup_tasks(bectx, + ad_ctx->sdap_id_ctx, ad_ctx->sdap_id_ctx->opts->sdom, ad_enumeration_send, - ad_enumeration_recv); + ad_enumeration_recv, + ad_ctx); if (ret != EOK) { goto done; } diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c index 3bbf801e9fb44a164684e84a2f5a5f03267b6575..381d17697b73e6a9cfb81ca7e03e20f88de433f5 100644 --- a/src/providers/ad/ad_subdomains.c +++ b/src/providers/ad/ad_subdomains.c @@ -176,10 +176,12 @@ ad_subdom_ad_ctx_new(struct be_ctx *be_ctx, return EFAULT; } - ret = sdap_id_setup_tasks(ad_id_ctx->sdap_id_ctx, - ad_id_ctx->ldap_ctx, sdom, + ret = sdap_id_setup_tasks(be_ctx, + ad_id_ctx->sdap_id_ctx, + sdom, ldap_enumeration_send, - ldap_enumeration_recv); + ldap_enumeration_recv, + ad_id_ctx->sdap_id_ctx); if (ret != EOK) { talloc_free(ad_options); return ret; diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c index 56fd4f99654aa07f822c49d6d39526765785f0de..b43e622c2cac8a4a2f4a8e0b2174004f629e0c7e 100644 --- a/src/providers/ipa/ipa_subdomains.c +++ b/src/providers/ipa/ipa_subdomains.c @@ -183,10 +183,12 @@ ipa_ad_ctx_new(struct be_ctx *be_ctx, return EFAULT; } - ret = sdap_id_setup_tasks(ad_id_ctx->sdap_id_ctx, - ad_id_ctx->ldap_ctx, sdom, + ret = sdap_id_setup_tasks(be_ctx, + ad_id_ctx->sdap_id_ctx, + sdom, ldap_enumeration_send, - ldap_enumeration_recv); + ldap_enumeration_recv, + ad_id_ctx->sdap_id_ctx); if (ret != EOK) { talloc_free(ad_options); return ret; diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c index 482271b8c22095116c7090e3ec70ed2a3c763b34..ee7296f206422ec0b78d1b3a8a669738ea55dfd9 100644 --- a/src/providers/ldap/ldap_common.c +++ b/src/providers/ldap/ldap_common.c @@ -986,16 +986,18 @@ void sdap_mark_offline(struct sdap_id_ctx *ctx) int ldap_id_setup_tasks(struct sdap_id_ctx *ctx) { - return sdap_id_setup_tasks(ctx, ctx->conn, ctx->opts->sdom, + return sdap_id_setup_tasks(ctx->be, ctx, ctx->opts->sdom, ldap_enumeration_send, - ldap_enumeration_recv); + ldap_enumeration_recv, + ctx); } -int sdap_id_setup_tasks(struct sdap_id_ctx *ctx, - struct sdap_id_conn_ctx *conn, +int sdap_id_setup_tasks(struct be_ctx *be_ctx, + struct sdap_id_ctx *ctx, struct sdap_domain *sdom, be_ptask_send_t send_fn, - be_ptask_recv_t recv_fn) + be_ptask_recv_t recv_fn, + void *pvt) { int ret; @@ -1003,7 +1005,8 @@ int sdap_id_setup_tasks(struct sdap_id_ctx *ctx, if (sdom->dom->enumerate) { DEBUG(SSSDBG_TRACE_FUNC, ("Setting up enumeration for %s\n", sdom->dom->name)); - ret = ldap_setup_enumeration(ctx, conn, sdom, send_fn, recv_fn); + ret = ldap_setup_enumeration(be_ctx, ctx->opts, sdom, + send_fn, recv_fn, pvt); } else { /* the enumeration task, runs the cleanup process by itself, * but if enumeration is not running we need to schedule it */ diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h index b3bd950e1dca6df0f5668397d5e5a0796e519862..889d5b118861e4ea3f51ab8a8ea5c5947e2560b9 100644 --- a/src/providers/ldap/ldap_common.h +++ b/src/providers/ldap/ldap_common.h @@ -95,11 +95,12 @@ void sdap_handle_account_info(struct be_req *breq, struct sdap_id_ctx *ctx, /* Set up enumeration and/or cleanup */ int ldap_id_setup_tasks(struct sdap_id_ctx *ctx); -int sdap_id_setup_tasks(struct sdap_id_ctx *ctx, - struct sdap_id_conn_ctx *conn, +int sdap_id_setup_tasks(struct be_ctx *be_ctx, + struct sdap_id_ctx *ctx, struct sdap_domain *sdom, be_ptask_send_t send_fn, - be_ptask_recv_t recv_fn); + be_ptask_recv_t recv_fn, + void *pvt); struct tevent_req * sdap_handle_acct_req_send(TALLOC_CTX *mem_ctx, @@ -177,16 +178,16 @@ int ldap_get_autofs_options(TALLOC_CTX *memctx, * structure that contains the request data */ struct ldap_enum_ctx { - struct sdap_id_ctx *ctx; struct sdap_domain *sdom; - struct sdap_id_conn_ctx *conn; + void *pvt; }; -errno_t ldap_setup_enumeration(struct sdap_id_ctx *ctx, - struct sdap_id_conn_ctx *conn, +errno_t ldap_setup_enumeration(struct be_ctx *be_ctx, + struct sdap_options *opts, struct sdap_domain *sdom, be_ptask_send_t send_fn, - be_ptask_recv_t recv_fn); + be_ptask_recv_t recv_fn, + void *pvt); struct tevent_req * ldap_enumeration_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, diff --git a/src/providers/ldap/ldap_id_enum.c b/src/providers/ldap/ldap_id_enum.c index 58ff459c0914cf4f703261d7c5e207ee1f6f00cb..368ad932862f21f82089068c0fd78c06a5bf4679 100644 --- a/src/providers/ldap/ldap_id_enum.c +++ b/src/providers/ldap/ldap_id_enum.c @@ -27,11 +27,12 @@ #include "providers/ldap/ldap_common.h" #include "providers/ldap/sdap_async_enum.h" -errno_t ldap_setup_enumeration(struct sdap_id_ctx *ctx, - struct sdap_id_conn_ctx *conn, +errno_t ldap_setup_enumeration(struct be_ctx *be_ctx, + struct sdap_options *opts, struct sdap_domain *sdom, be_ptask_send_t send_fn, - be_ptask_recv_t recv_fn) + be_ptask_recv_t recv_fn, + void *pvt) { errno_t ret; time_t first_delay; @@ -60,17 +61,16 @@ errno_t ldap_setup_enumeration(struct sdap_id_ctx *ctx, first_delay = 0; } - period = dp_opt_get_int(ctx->opts->basic, SDAP_ENUM_REFRESH_TIMEOUT); + period = dp_opt_get_int(opts->basic, SDAP_ENUM_REFRESH_TIMEOUT); ectx = talloc(sdom, struct ldap_enum_ctx); if (ectx == NULL) { return ENOMEM; } - ectx->ctx = ctx; ectx->sdom = sdom; - ectx->conn = conn; + ectx->pvt = pvt; - ret = be_ptask_create(sdom, ctx->be, + ret = be_ptask_create(sdom, be_ctx, period, /* period */ first_delay, /* first_delay */ 5, /* enabled delay */ @@ -91,6 +91,7 @@ errno_t ldap_setup_enumeration(struct sdap_id_ctx *ctx, struct ldap_enumeration_state { struct ldap_enum_ctx *ectx; + struct sdap_id_ctx *id_ctx; struct sss_domain_info *dom; }; @@ -118,14 +119,16 @@ ldap_enumeration_send(TALLOC_CTX *mem_ctx, ectx = talloc_get_type(pvt, struct ldap_enum_ctx); if (ectx == NULL) { + DEBUG(SSSDBG_CRIT_FAILURE, ("Cannot retrieve ldap_enum_ctx!\n")); ret = EFAULT; goto fail; } state->ectx = ectx; state->dom = ectx->sdom->dom; + state->id_ctx = talloc_get_type_abort(ectx->pvt, struct sdap_id_ctx); - subreq = sdap_dom_enum_send(ectx, ev, ectx->ctx, ectx->sdom, - ectx->conn); + subreq = sdap_dom_enum_send(ectx, ev, state->id_ctx, ectx->sdom, + state->id_ctx->conn); if (subreq == NULL) { /* The ptask API will reschedule the enumeration on its own on * failure */ -- 1.8.4.2