Blame SOURCES/0066-LDAP-Pass-a-private-context-to-enumeration-ptask-ins.patch

2fc102
From 1a5d7f670d94cb5c2b4a727e1e4cb3f1debadaa7 Mon Sep 17 00:00:00 2001
2fc102
From: Jakub Hrozek <jhrozek@redhat.com>
2fc102
Date: Tue, 10 Dec 2013 21:49:45 +0100
2fc102
Subject: [PATCH 66/71] LDAP: Pass a private context to enumeration ptask
2fc102
 instead of hardcoded connection
2fc102
2fc102
Previously, the sdap-domain enumeration request used a single connection context to
2fc102
download all the data. Now we'd like to use different connections to
2fc102
download different objects, so the ID context is passed in and the
2fc102
request itself decides which connection to use for the sdap-domain
2fc102
enumeration.
2fc102
---
2fc102
 src/providers/ad/ad_id.c           | 12 ++++++++----
2fc102
 src/providers/ad/ad_init.c         |  7 ++++---
2fc102
 src/providers/ad/ad_subdomains.c   |  8 +++++---
2fc102
 src/providers/ipa/ipa_subdomains.c |  8 +++++---
2fc102
 src/providers/ldap/ldap_common.c   | 15 +++++++++------
2fc102
 src/providers/ldap/ldap_common.h   | 17 +++++++++--------
2fc102
 src/providers/ldap/ldap_id_enum.c  | 21 ++++++++++++---------
2fc102
 7 files changed, 52 insertions(+), 36 deletions(-)
2fc102
2fc102
diff --git a/src/providers/ad/ad_id.c b/src/providers/ad/ad_id.c
2fc102
index 85edcf6d604f705f5645f77689c2b4c7471b5edd..99383c13bdadfe9eb2af9f9323ca19a9759d4620 100644
2fc102
--- a/src/providers/ad/ad_id.c
2fc102
+++ b/src/providers/ad/ad_id.c
2fc102
@@ -414,6 +414,7 @@ ad_check_online(struct be_req *be_req)
2fc102
 }
2fc102
 
2fc102
 struct ad_enumeration_state {
2fc102
+    struct ad_id_ctx *id_ctx;
2fc102
     struct ldap_enum_ctx *ectx;
2fc102
     struct sdap_id_op *sdap_op;
2fc102
     struct tevent_context *ev;
2fc102
@@ -443,6 +444,7 @@ ad_enumeration_send(TALLOC_CTX *mem_ctx,
2fc102
 
2fc102
     ectx = talloc_get_type(pvt, struct ldap_enum_ctx);
2fc102
     if (ectx == NULL) {
2fc102
+        DEBUG(SSSDBG_CRIT_FAILURE, ("Cannot retrieve ldap_enum_ctx!\n"));
2fc102
         ret = EFAULT;
2fc102
         goto fail;
2fc102
     }
2fc102
@@ -450,8 +452,10 @@ ad_enumeration_send(TALLOC_CTX *mem_ctx,
2fc102
     state->ectx = ectx;
2fc102
     state->ev = ev;
2fc102
     state->sdom = ectx->sdom;
2fc102
+    state->id_ctx = talloc_get_type(ectx->pvt, struct ad_id_ctx);
2fc102
 
2fc102
-    state->sdap_op = sdap_id_op_create(state, ectx->conn->conn_cache);
2fc102
+    state->sdap_op = sdap_id_op_create(state,
2fc102
+                                       state->id_ctx->ldap_ctx->conn_cache);
2fc102
     if (state->sdap_op == NULL) {
2fc102
         DEBUG(SSSDBG_OP_FAILURE, ("sdap_id_op_create failed.\n"));
2fc102
         ret = ENOMEM;
2fc102
@@ -500,7 +504,7 @@ ad_enumeration_conn_done(struct tevent_req *subreq)
2fc102
     }
2fc102
 
2fc102
     subreq = ad_master_domain_send(state, state->ev,
2fc102
-                                   state->ectx->conn,
2fc102
+                                   state->id_ctx->ldap_ctx,
2fc102
                                    state->sdap_op,
2fc102
                                    state->sdom->dom->name);
2fc102
     if (subreq == NULL) {
2fc102
@@ -540,8 +544,8 @@ ad_enumeration_master_done(struct tevent_req *subreq)
2fc102
         return;
2fc102
     }
2fc102
 
2fc102
-    subreq = sdap_dom_enum_send(state, state->ev, state->ectx->ctx,
2fc102
-                                state->sdom, state->ectx->conn);
2fc102
+    subreq = sdap_dom_enum_send(state, state->ev, state->id_ctx->sdap_id_ctx,
2fc102
+                                state->sdom, state->id_ctx->ldap_ctx);
2fc102
     if (subreq == NULL) {
2fc102
         /* The ptask API will reschedule the enumeration on its own on
2fc102
          * failure */
2fc102
diff --git a/src/providers/ad/ad_init.c b/src/providers/ad/ad_init.c
2fc102
index ed69a7d9889bac1281b5ff7c7b0f290ab09173fb..eff6d990d131e3aba124d252d001dd39e78b45cf 100644
2fc102
--- a/src/providers/ad/ad_init.c
2fc102
+++ b/src/providers/ad/ad_init.c
2fc102
@@ -205,11 +205,12 @@ sssm_ad_id_init(struct be_ctx *bectx,
2fc102
         goto done;
2fc102
     }
2fc102
 
2fc102
-    ret = sdap_id_setup_tasks(ad_ctx->sdap_id_ctx,
2fc102
-                              ad_ctx->sdap_id_ctx->conn,
2fc102
+    ret = sdap_id_setup_tasks(bectx,
2fc102
+                              ad_ctx->sdap_id_ctx,
2fc102
                               ad_ctx->sdap_id_ctx->opts->sdom,
2fc102
                               ad_enumeration_send,
2fc102
-                              ad_enumeration_recv);
2fc102
+                              ad_enumeration_recv,
2fc102
+                              ad_ctx);
2fc102
     if (ret != EOK) {
2fc102
         goto done;
2fc102
     }
2fc102
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
2fc102
index 348561a85524c203293c713d3f31552a99d74a43..e7871cc32407893948fe1b2803258d68c70889c1 100644
2fc102
--- a/src/providers/ad/ad_subdomains.c
2fc102
+++ b/src/providers/ad/ad_subdomains.c
2fc102
@@ -177,10 +177,12 @@ ad_subdom_ad_ctx_new(struct be_ctx *be_ctx,
2fc102
         return EFAULT;
2fc102
     }
2fc102
 
2fc102
-    ret = sdap_id_setup_tasks(ad_id_ctx->sdap_id_ctx,
2fc102
-                              ad_id_ctx->ldap_ctx, sdom,
2fc102
+    ret = sdap_id_setup_tasks(be_ctx,
2fc102
+                              ad_id_ctx->sdap_id_ctx,
2fc102
+                              sdom,
2fc102
                               ldap_enumeration_send,
2fc102
-                              ldap_enumeration_recv);
2fc102
+                              ldap_enumeration_recv,
2fc102
+                              ad_id_ctx->sdap_id_ctx);
2fc102
     if (ret != EOK) {
2fc102
         talloc_free(ad_options);
2fc102
         return ret;
2fc102
diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
2fc102
index d9c204451f1b734ee98ce4c48f3f139731e47dec..88b6ba52538be83417e98c9a5dd033bea87ebe4b 100644
2fc102
--- a/src/providers/ipa/ipa_subdomains.c
2fc102
+++ b/src/providers/ipa/ipa_subdomains.c
2fc102
@@ -183,10 +183,12 @@ ipa_ad_ctx_new(struct be_ctx *be_ctx,
2fc102
         return EFAULT;
2fc102
     }
2fc102
 
2fc102
-    ret = sdap_id_setup_tasks(ad_id_ctx->sdap_id_ctx,
2fc102
-                              ad_id_ctx->ldap_ctx, sdom,
2fc102
+    ret = sdap_id_setup_tasks(be_ctx,
2fc102
+                              ad_id_ctx->sdap_id_ctx,
2fc102
+                              sdom,
2fc102
                               ldap_enumeration_send,
2fc102
-                              ldap_enumeration_recv);
2fc102
+                              ldap_enumeration_recv,
2fc102
+                              ad_id_ctx->sdap_id_ctx);
2fc102
     if (ret != EOK) {
2fc102
         talloc_free(ad_options);
2fc102
         return ret;
2fc102
diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c
2fc102
index 4c94937aad9e25bd1cd0b6d573da2982b0f1be05..e799c783c118309409faca0294eadc4736d15108 100644
2fc102
--- a/src/providers/ldap/ldap_common.c
2fc102
+++ b/src/providers/ldap/ldap_common.c
2fc102
@@ -974,16 +974,18 @@ void sdap_mark_offline(struct sdap_id_ctx *ctx)
2fc102
 
2fc102
 int ldap_id_setup_tasks(struct sdap_id_ctx *ctx)
2fc102
 {
2fc102
-    return sdap_id_setup_tasks(ctx, ctx->conn, ctx->opts->sdom,
2fc102
+    return sdap_id_setup_tasks(ctx->be, ctx, ctx->opts->sdom,
2fc102
                                ldap_enumeration_send,
2fc102
-                               ldap_enumeration_recv);
2fc102
+                               ldap_enumeration_recv,
2fc102
+                               ctx);
2fc102
 }
2fc102
 
2fc102
-int sdap_id_setup_tasks(struct sdap_id_ctx *ctx,
2fc102
-                        struct sdap_id_conn_ctx *conn,
2fc102
+int sdap_id_setup_tasks(struct be_ctx *be_ctx,
2fc102
+                        struct sdap_id_ctx *ctx,
2fc102
                         struct sdap_domain *sdom,
2fc102
                         be_ptask_send_t send_fn,
2fc102
-                        be_ptask_recv_t recv_fn)
2fc102
+                        be_ptask_recv_t recv_fn,
2fc102
+                        void *pvt)
2fc102
 {
2fc102
     int ret;
2fc102
 
2fc102
@@ -991,7 +993,8 @@ int sdap_id_setup_tasks(struct sdap_id_ctx *ctx,
2fc102
     if (sdom->dom->enumerate) {
2fc102
         DEBUG(SSSDBG_TRACE_FUNC, ("Setting up enumeration for %s\n",
2fc102
                                   sdom->dom->name));
2fc102
-        ret = ldap_setup_enumeration(ctx, conn, sdom, send_fn, recv_fn);
2fc102
+        ret = ldap_setup_enumeration(be_ctx, ctx->opts, sdom,
2fc102
+                                     send_fn, recv_fn, pvt);
2fc102
     } else {
2fc102
         /* the enumeration task, runs the cleanup process by itself,
2fc102
          * but if enumeration is not running we need to schedule it */
2fc102
diff --git a/src/providers/ldap/ldap_common.h b/src/providers/ldap/ldap_common.h
2fc102
index b3bd950e1dca6df0f5668397d5e5a0796e519862..889d5b118861e4ea3f51ab8a8ea5c5947e2560b9 100644
2fc102
--- a/src/providers/ldap/ldap_common.h
2fc102
+++ b/src/providers/ldap/ldap_common.h
2fc102
@@ -95,11 +95,12 @@ void sdap_handle_account_info(struct be_req *breq, struct sdap_id_ctx *ctx,
2fc102
 
2fc102
 /* Set up enumeration and/or cleanup */
2fc102
 int ldap_id_setup_tasks(struct sdap_id_ctx *ctx);
2fc102
-int sdap_id_setup_tasks(struct sdap_id_ctx *ctx,
2fc102
-                        struct sdap_id_conn_ctx *conn,
2fc102
+int sdap_id_setup_tasks(struct be_ctx *be_ctx,
2fc102
+                        struct sdap_id_ctx *ctx,
2fc102
                         struct sdap_domain *sdom,
2fc102
                         be_ptask_send_t send_fn,
2fc102
-                        be_ptask_recv_t recv_fn);
2fc102
+                        be_ptask_recv_t recv_fn,
2fc102
+                        void *pvt);
2fc102
 
2fc102
 struct tevent_req *
2fc102
 sdap_handle_acct_req_send(TALLOC_CTX *mem_ctx,
2fc102
@@ -177,16 +178,16 @@ int ldap_get_autofs_options(TALLOC_CTX *memctx,
2fc102
  * structure that contains the request data
2fc102
  */
2fc102
 struct ldap_enum_ctx {
2fc102
-    struct sdap_id_ctx *ctx;
2fc102
     struct sdap_domain *sdom;
2fc102
-    struct sdap_id_conn_ctx *conn;
2fc102
+    void *pvt;
2fc102
 };
2fc102
 
2fc102
-errno_t ldap_setup_enumeration(struct sdap_id_ctx *ctx,
2fc102
-                               struct sdap_id_conn_ctx *conn,
2fc102
+errno_t ldap_setup_enumeration(struct be_ctx *be_ctx,
2fc102
+                               struct sdap_options *opts,
2fc102
                                struct sdap_domain *sdom,
2fc102
                                be_ptask_send_t send_fn,
2fc102
-                               be_ptask_recv_t recv_fn);
2fc102
+                               be_ptask_recv_t recv_fn,
2fc102
+                               void *pvt);
2fc102
 struct tevent_req *
2fc102
 ldap_enumeration_send(TALLOC_CTX *mem_ctx,
2fc102
                       struct tevent_context *ev,
2fc102
diff --git a/src/providers/ldap/ldap_id_enum.c b/src/providers/ldap/ldap_id_enum.c
2fc102
index 8cccaa916a24beb10fe692d9a0e09f5f47ceb6f7..c791496a6143b23118bf17a58f738fb0bfb5f95a 100644
2fc102
--- a/src/providers/ldap/ldap_id_enum.c
2fc102
+++ b/src/providers/ldap/ldap_id_enum.c
2fc102
@@ -27,11 +27,12 @@
2fc102
 #include "providers/ldap/ldap_common.h"
2fc102
 #include "providers/ldap/sdap_async_enum.h"
2fc102
 
2fc102
-errno_t ldap_setup_enumeration(struct sdap_id_ctx *ctx,
2fc102
-                               struct sdap_id_conn_ctx *conn,
2fc102
+errno_t ldap_setup_enumeration(struct be_ctx *be_ctx,
2fc102
+                               struct sdap_options *opts,
2fc102
                                struct sdap_domain *sdom,
2fc102
                                be_ptask_send_t send_fn,
2fc102
-                               be_ptask_recv_t recv_fn)
2fc102
+                               be_ptask_recv_t recv_fn,
2fc102
+                               void *pvt)
2fc102
 {
2fc102
     errno_t ret;
2fc102
     time_t first_delay;
2fc102
@@ -60,17 +61,16 @@ errno_t ldap_setup_enumeration(struct sdap_id_ctx *ctx,
2fc102
         first_delay = 0;
2fc102
     }
2fc102
 
2fc102
-    period = dp_opt_get_int(ctx->opts->basic, SDAP_ENUM_REFRESH_TIMEOUT);
2fc102
+    period = dp_opt_get_int(opts->basic, SDAP_ENUM_REFRESH_TIMEOUT);
2fc102
 
2fc102
     ectx = talloc(sdom, struct ldap_enum_ctx);
2fc102
     if (ectx == NULL) {
2fc102
         return ENOMEM;
2fc102
     }
2fc102
-    ectx->ctx = ctx;
2fc102
     ectx->sdom = sdom;
2fc102
-    ectx->conn = conn;
2fc102
+    ectx->pvt = pvt;
2fc102
 
2fc102
-    ret = be_ptask_create(sdom, ctx->be,
2fc102
+    ret = be_ptask_create(sdom, be_ctx,
2fc102
                           period,                   /* period */
2fc102
                           first_delay,              /* first_delay */
2fc102
                           5,                        /* enabled delay */
2fc102
@@ -91,6 +91,7 @@ errno_t ldap_setup_enumeration(struct sdap_id_ctx *ctx,
2fc102
 
2fc102
 struct ldap_enumeration_state {
2fc102
     struct ldap_enum_ctx *ectx;
2fc102
+    struct sdap_id_ctx *id_ctx;
2fc102
     struct sss_domain_info *dom;
2fc102
 };
2fc102
 
2fc102
@@ -118,14 +119,16 @@ ldap_enumeration_send(TALLOC_CTX *mem_ctx,
2fc102
 
2fc102
     ectx = talloc_get_type(pvt, struct ldap_enum_ctx);
2fc102
     if (ectx == NULL) {
2fc102
+        DEBUG(SSSDBG_CRIT_FAILURE, ("Cannot retrieve ldap_enum_ctx!\n"));
2fc102
         ret = EFAULT;
2fc102
         goto fail;
2fc102
     }
2fc102
     state->ectx = ectx;
2fc102
     state->dom = ectx->sdom->dom;
2fc102
+    state->id_ctx = talloc_get_type_abort(ectx->pvt, struct sdap_id_ctx);
2fc102
 
2fc102
-    subreq = sdap_dom_enum_send(ectx, ev, ectx->ctx, ectx->sdom,
2fc102
-                                ectx->conn);
2fc102
+    subreq = sdap_dom_enum_send(ectx, ev, state->id_ctx, ectx->sdom,
2fc102
+                                state->id_ctx->conn);
2fc102
     if (subreq == NULL) {
2fc102
         /* The ptask API will reschedule the enumeration on its own on
2fc102
          * failure */
2fc102
-- 
2fc102
1.8.4.2
2fc102