>From 843f0c48fe68d2544495b2cd6c14a06fa3005bda Mon Sep 17 00:00:00 2001
From: Simo Sorce <simo@redhat.com>
Date: Thu, 19 Jul 2012 19:35:43 -0400
Subject: [PATCH 12/16] Expose an initializer function from subdomain

Instead of exporting internal structures, expose an initilizer function
like the autofs code and initialize everything inside the
ipa_subdomains.c file.
---
 src/providers/ipa/ipa_init.c       |   28 ++++++----------------------
 src/providers/ipa/ipa_subdomains.c |   35 +++++++++++++++++++++++++++++++++++
 src/providers/ipa/ipa_subdomains.h |   15 +++++----------
 3 files changed, 46 insertions(+), 32 deletions(-)

diff --git a/src/providers/ipa/ipa_init.c b/src/providers/ipa/ipa_init.c
index 4fb662c26b90fd5526d1ef5344acc8bf912cda95..2237bbe610167b075f74264fc2074a7d264e0677 100644
--- a/src/providers/ipa/ipa_init.c
+++ b/src/providers/ipa/ipa_init.c
@@ -76,11 +76,6 @@ struct bet_ops ipa_hostid_ops = {
 };
 #endif
 
-struct bet_ops ipa_subdomains_ops = {
-    .handler = ipa_subdomains_handler,
-    .finalize = NULL
-};
-
 int common_ipa_init(struct be_ctx *bectx)
 {
     const char *ipa_servers;
@@ -486,30 +481,19 @@ int sssm_ipa_subdomains_init(struct be_ctx *bectx,
                              void **pvt_data)
 {
     int ret;
-    struct ipa_subdomains_ctx *subdomains_ctx;
     struct ipa_id_ctx *id_ctx;
 
-    subdomains_ctx = talloc_zero(bectx, struct ipa_subdomains_ctx);
-    if (subdomains_ctx == NULL) {
-        DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_zero failed.\n"));
-        return ENOMEM;
-    }
-
     ret = sssm_ipa_id_init(bectx, ops, (void **) &id_ctx);
     if (ret != EOK) {
         DEBUG(SSSDBG_CRIT_FAILURE, ("sssm_ipa_id_init failed.\n"));
-        goto done;
+        return ret;
     }
-    subdomains_ctx->sdap_id_ctx = id_ctx->sdap_id_ctx;
-    subdomains_ctx->search_bases = id_ctx->ipa_options->subdomains_search_bases;
-    subdomains_ctx->master_search_bases = id_ctx->ipa_options->master_domain_search_bases;
-    subdomains_ctx->ranges_search_bases = id_ctx->ipa_options->ranges_search_bases;
-    *ops = &ipa_subdomains_ops;
-    *pvt_data = subdomains_ctx;
 
-done:
+    ret = ipa_subdom_init(bectx, id_ctx, ops, pvt_data);
     if (ret != EOK) {
-        talloc_free(subdomains_ctx);
+        DEBUG(SSSDBG_CRIT_FAILURE, ("ipa_subdom_init failed.\n"));
+        return ret;
     }
-    return ret;
+
+    return EOK;
 }
diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
index 8a49c63439d96b6ec79d0a13e944903bc83932fd..a8c05c2a744eb8476e363585659c83c12b964b0a 100644
--- a/src/providers/ipa/ipa_subdomains.c
+++ b/src/providers/ipa/ipa_subdomains.c
@@ -56,6 +56,13 @@ struct ipa_subdomains_req_params {
     const char *attrs[8];
 };
 
+struct ipa_subdomains_ctx {
+    struct sdap_id_ctx *sdap_id_ctx;
+    struct sdap_search_base **search_bases;
+    struct sdap_search_base **master_search_bases;
+    struct sdap_search_base **ranges_search_bases;
+};
+
 static void ipa_subdomains_reply(struct be_req *be_req, int dp_err, int result)
 {
     be_req->fn(be_req, dp_err, result, NULL);
@@ -651,3 +658,31 @@ done:
     }
     ipa_subdomains_reply(be_req, dp_error, ret);
 }
+
+struct bet_ops ipa_subdomains_ops = {
+    .handler = ipa_subdomains_handler,
+    .finalize = NULL
+};
+
+int ipa_subdom_init(struct be_ctx *be_ctx,
+                    struct ipa_id_ctx *id_ctx,
+                    struct bet_ops **ops,
+                    void **pvt_data)
+{
+    struct ipa_subdomains_ctx *ctx;
+
+    ctx = talloc_zero(id_ctx, struct ipa_subdomains_ctx);
+    if (ctx == NULL) {
+        DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_zero failed.\n"));
+        return ENOMEM;
+    }
+
+    ctx->sdap_id_ctx = id_ctx->sdap_id_ctx;
+    ctx->search_bases = id_ctx->ipa_options->subdomains_search_bases;
+    ctx->master_search_bases = id_ctx->ipa_options->master_domain_search_bases;
+    ctx->ranges_search_bases = id_ctx->ipa_options->ranges_search_bases;
+    *ops = &ipa_subdomains_ops;
+    *pvt_data = ctx;
+
+    return EOK;
+}
diff --git a/src/providers/ipa/ipa_subdomains.h b/src/providers/ipa/ipa_subdomains.h
index 895ba29f543a2ee828d2795a67c1ce188df39665..9d24bccf29eb0de8e0f9cfba7238b444e4317faf 100644
--- a/src/providers/ipa/ipa_subdomains.h
+++ b/src/providers/ipa/ipa_subdomains.h
@@ -26,16 +26,11 @@
 #define _IPA_SUBDOMAINS_H_
 
 #include "providers/dp_backend.h"
-#include "providers/ldap/ldap_common.h"
+#include "providers/ipa/ipa_common.h"
 
-struct ipa_subdomains_ctx {
-    struct sdap_id_ctx *sdap_id_ctx;
-    struct sdap_search_base **search_bases;
-    struct sdap_search_base **master_search_bases;
-    struct sdap_search_base **ranges_search_bases;
-};
-
-
-void ipa_subdomains_handler(struct be_req *be_req);
+int ipa_subdom_init(struct be_ctx *be_ctx,
+                    struct ipa_id_ctx *id_ctx,
+                    struct bet_ops **ops,
+                    void **pvt_data);
 
 #endif /* _IPA_SUBDOMAINS_H_ */
-- 
1.7.10.4

