From f48b238e41fb7a42dce7b0946e68e0e468fd2873 Mon Sep 17 00:00:00 2001
From: Jan Zeleny <jzeleny@redhat.com>
Date: Wed, 12 Oct 2011 09:27:56 -0400
Subject: [PATCH 3/5] New IPA ID context

---
 src/providers/ipa/ipa_common.h |    7 ++++++-
 src/providers/ipa/ipa_dyndns.c |   18 ++++++++++--------
 src/providers/ipa/ipa_init.c   |   34 +++++++++++++++++++++-------------
 3 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/src/providers/ipa/ipa_common.h b/src/providers/ipa/ipa_common.h
index 14a154f9b854c7976497b0b72feb9f34bf35aa95..c3ed61e6a8ebc2817cbab6c0f1ddd29461cd4960 100644
--- a/src/providers/ipa/ipa_common.h
+++ b/src/providers/ipa/ipa_common.h
@@ -84,6 +84,11 @@ struct ipa_auth_ctx {
     struct dp_option *ipa_options;
 };
 
+struct ipa_id_ctx {
+    struct sdap_id_ctx *sdap_id_ctx;
+    struct ipa_options *ipa_options;
+};
+
 struct ipa_options {
     struct dp_option *basic;
 
@@ -91,7 +96,7 @@ struct ipa_options {
 
     /* id provider */
     struct sdap_options *id;
-    struct sdap_id_ctx *id_ctx;
+    struct ipa_id_ctx *id_ctx;
     struct resolv_ctx *resolv;
 
     /* auth and chpass provider */
diff --git a/src/providers/ipa/ipa_dyndns.c b/src/providers/ipa/ipa_dyndns.c
index c532c3d0b2f3632b113c68e1723ac1dfb8b41b9b..bd72cc454d629eaf6c90f339310d20a42e1fa3ac 100644
--- a/src/providers/ipa/ipa_dyndns.c
+++ b/src/providers/ipa/ipa_dyndns.c
@@ -264,7 +264,7 @@ ipa_dyndns_update_send(struct ipa_options *ctx)
 
     else {
         /* Detect DYNDNS interface from LDAP connection */
-        state->sdap_op = sdap_id_op_create(state, state->ipa_ctx->id_ctx->conn_cache);
+        state->sdap_op = sdap_id_op_create(state, state->ipa_ctx->id_ctx->sdap_id_ctx->conn_cache);
         if (!state->sdap_op) {
             DEBUG(1, ("sdap_id_op_create failed\n"));
             ret = ENOMEM;
@@ -431,11 +431,11 @@ static int ipa_dyndns_gss_tsig_update_step(struct tevent_req *req)
 static errno_t
 ipa_dyndns_gss_tsig_update_setup_check(struct ipa_dyndns_ctx *state)
 {
+    struct sdap_id_ctx *id_ctx = state->ipa_ctx->id_ctx->sdap_id_ctx;
     errno_t ret;
 
     if (dp_opt_get_string(state->ipa_ctx->basic, IPA_DYNDNS_IFACE)) {
-        ret = resolv_get_family_order(state->ipa_ctx->id_ctx->be->cdb,
-                                      state->ipa_ctx->id_ctx->be->conf_path,
+        ret = resolv_get_family_order(id_ctx->be->cdb, id_ctx->be->conf_path,
                                       &state->family_order);
         if (ret != EOK) {
             return ret;
@@ -574,6 +574,7 @@ ipa_dyndns_update_get_addrs_send(TALLOC_CTX *mem_ctx,
     errno_t ret;
     struct tevent_req *req;
     struct ipa_dyndns_update_get_addrs_state *state;
+    struct sdap_id_ctx *id_ctx = ctx->ipa_ctx->id_ctx->sdap_id_ctx;
 
     req = tevent_req_create(mem_ctx, &state,
                             struct ipa_dyndns_update_get_addrs_state);
@@ -599,7 +600,7 @@ ipa_dyndns_update_get_addrs_send(TALLOC_CTX *mem_ctx,
 immediate:
     if (ret != EOK) {
         tevent_req_error(req, ret);
-        tevent_req_post(req, ctx->ipa_ctx->id_ctx->be->ev);
+        tevent_req_post(req, id_ctx->be->ev);
     }
     return req;
 }
@@ -610,9 +611,10 @@ ipa_dyndns_update_get_addrs_step(struct tevent_req *req)
     struct tevent_req *subreq;
     struct ipa_dyndns_update_get_addrs_state *state = tevent_req_data(req,
                                         struct ipa_dyndns_update_get_addrs_state);
+    struct ipa_id_ctx *ipa_id_ctx = state->dctx->ipa_ctx->id_ctx;
 
     subreq = resolv_gethostbyname_send(state,
-                                       state->dctx->ipa_ctx->id_ctx->be->ev,
+                                       ipa_id_ctx->sdap_id_ctx->be->ev,
                                        state->dctx->ipa_ctx->resolv,
                                        state->dctx->hostname,
                                        state->family_order,
@@ -996,7 +998,7 @@ fork_nsupdate_send(struct ipa_nsupdate_ctx *ctx)
 
         /* Write the update message to the nsupdate child */
         subreq = write_pipe_send(req,
-                                 ctx->dyndns_ctx->ipa_ctx->id_ctx->be->ev,
+                                 ctx->dyndns_ctx->ipa_ctx->id_ctx->sdap_id_ctx->be->ev,
                                  (uint8_t *)ctx->update_msg,
                                  strlen(ctx->update_msg)+1,
                                  ctx->pipefd_to_child);
@@ -1006,7 +1008,7 @@ fork_nsupdate_send(struct ipa_nsupdate_ctx *ctx)
         tevent_req_set_callback(subreq, ipa_dyndns_stdin_done, req);
 
         /* Set up SIGCHLD handler */
-        ret = child_handler_setup(ctx->dyndns_ctx->ipa_ctx->id_ctx->be->ev,
+        ret = child_handler_setup(ctx->dyndns_ctx->ipa_ctx->id_ctx->sdap_id_ctx->be->ev,
                                   pid, ipa_dyndns_child_handler, req);
         if (ret != EOK) {
             return NULL;
@@ -1015,7 +1017,7 @@ fork_nsupdate_send(struct ipa_nsupdate_ctx *ctx)
         /* Set up timeout handler */
         tv = tevent_timeval_current_ofs(IPA_DYNDNS_TIMEOUT, 0);
         ctx->timeout_handler = tevent_add_timer(
-                ctx->dyndns_ctx->ipa_ctx->id_ctx->be->ev,
+                ctx->dyndns_ctx->ipa_ctx->id_ctx->sdap_id_ctx->be->ev,
                 req, tv, ipa_dyndns_timeout, req);
         if(ctx->timeout_handler == NULL) {
             return NULL;
diff --git a/src/providers/ipa/ipa_init.c b/src/providers/ipa/ipa_init.c
index 5d08b8c18769369470ee2668d683843c1c8d011c..713b9a43e1311affdb8df702f8b37b257096d2c8 100644
--- a/src/providers/ipa/ipa_init.c
+++ b/src/providers/ipa/ipa_init.c
@@ -89,7 +89,8 @@ int sssm_ipa_id_init(struct be_ctx *bectx,
                      struct bet_ops **ops,
                      void **pvt_data)
 {
-    struct sdap_id_ctx *ctx;
+    struct ipa_id_ctx *ipa_ctx;
+    struct sdap_id_ctx *sdap_ctx;
     struct stat stat_buf;
     errno_t err;
     int ret;
@@ -108,17 +109,24 @@ int sssm_ipa_id_init(struct be_ctx *bectx,
         return EOK;
     }
 
-    ctx = talloc_zero(ipa_options, struct sdap_id_ctx);
-    if (!ctx) {
+    ipa_ctx = talloc_zero(ipa_options, struct ipa_id_ctx);
+    if (!ipa_ctx) {
         return ENOMEM;
     }
-    ctx->be = bectx;
-    ctx->service = ipa_options->service->sdap;
-    ipa_options->id_ctx = ctx;
+    ipa_options->id_ctx = ipa_ctx;
+    ipa_ctx->ipa_options = ipa_options;
+
+    sdap_ctx = talloc_zero(ipa_options, struct sdap_id_ctx);
+    if (!sdap_ctx) {
+        return ENOMEM;
+    }
+    sdap_ctx->be = bectx;
+    sdap_ctx->service = ipa_options->service->sdap;
+    ipa_ctx->sdap_id_ctx = sdap_ctx;
 
     ret = ipa_get_id_options(ipa_options, bectx->cdb,
                              bectx->conf_path,
-                             &ctx->opts);
+                             &sdap_ctx->opts);
     if (ret != EOK) {
         goto done;
     }
@@ -149,7 +157,7 @@ int sssm_ipa_id_init(struct be_ctx *bectx,
             /* nsupdate is available. Dynamic updates
              * are supported
              */
-            ret = ipa_dyndns_init(ctx, ctx->be, ipa_options);
+            ret = ipa_dyndns_init(sdap_ctx, sdap_ctx->be, ipa_options);
             if (ret != EOK) {
                 DEBUG(1, ("Failure setting up automatic DNS update\n"));
                 /* We will continue without DNS updating */
@@ -159,24 +167,24 @@ int sssm_ipa_id_init(struct be_ctx *bectx,
 
 
 
-    ret = setup_tls_config(ctx->opts->basic);
+    ret = setup_tls_config(sdap_ctx->opts->basic);
     if (ret != EOK) {
         DEBUG(1, ("setup_tls_config failed [%d][%s].\n",
                   ret, strerror(ret)));
         goto done;
     }
 
-    ret = sdap_id_conn_cache_create(ctx, ctx, &ctx->conn_cache);
+    ret = sdap_id_conn_cache_create(sdap_ctx, sdap_ctx, &sdap_ctx->conn_cache);
     if (ret != EOK) {
         goto done;
     }
 
-    ret = sdap_id_setup_tasks(ctx);
+    ret = sdap_id_setup_tasks(sdap_ctx);
     if (ret != EOK) {
         goto done;
     }
 
-    ret = setup_child(ctx);
+    ret = setup_child(sdap_ctx);
     if (ret != EOK) {
         DEBUG(1, ("setup_child failed [%d][%s].\n",
                   ret, strerror(ret)));
@@ -184,7 +192,7 @@ int sssm_ipa_id_init(struct be_ctx *bectx,
     }
 
     *ops = &ipa_id_ops;
-    *pvt_data = ctx;
+    *pvt_data = ipa_ctx;
     ret = EOK;
 
 done:
-- 
1.7.6.4

