>From 94d55a4ffc1072ee44b0043e9c20158c143a9091 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 10 Dec 2013 21:49:45 +0100 Subject: [PATCH 2/7] 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 85edcf6d604f705f5645f77689c2b4c7471b5edd..99383c13bdadfe9eb2af9f9323ca19a9759d4620 100644 --- a/src/providers/ad/ad_id.c +++ b/src/providers/ad/ad_id.c @@ -414,6 +414,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; @@ -443,6 +444,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; } @@ -450,8 +452,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; @@ -500,7 +504,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) { @@ -540,8 +544,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 ed69a7d9889bac1281b5ff7c7b0f290ab09173fb..eff6d990d131e3aba124d252d001dd39e78b45cf 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 348561a85524c203293c713d3f31552a99d74a43..e7871cc32407893948fe1b2803258d68c70889c1 100644 --- a/src/providers/ad/ad_subdomains.c +++ b/src/providers/ad/ad_subdomains.c @@ -177,10 +177,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 d9c204451f1b734ee98ce4c48f3f139731e47dec..88b6ba52538be83417e98c9a5dd033bea87ebe4b 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 f1a2ed97e211757ebc21906482f7f18d4012b913..1eb848a9de5f67e4aa48c4675ef424576fbed89b 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