From 57c2a7c4390a1549a2dbe3c6ae25fffd1e6e9f4d Mon Sep 17 00:00:00 2001
From: Ondrej Kos <okos@redhat.com>
Date: Thu, 29 Aug 2013 17:12:34 +0200
Subject: [PATCH 3/5] DP: Save request domain name, if available

---
 src/providers/ad/ad_subdomains.c   |  2 +-
 src/providers/data_provider_be.c   | 31 ++++++++++++++++++++++---------
 src/providers/dp_backend.h         |  2 +-
 src/providers/ipa/ipa_subdomains.c |  2 +-
 4 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
index e6d85541d0f93af4ed7dcabce2236c4d225a326e..6e44680e9fc7797a1924cdaff6dfcd60e090a2b5 100644
--- a/src/providers/ad/ad_subdomains.c
+++ b/src/providers/ad/ad_subdomains.c
@@ -719,7 +719,7 @@ static void ad_subdom_online_cb(void *pvt)
         return;
     }
 
-    be_req = be_req_create(ctx, NULL, ctx->be_ctx,
+    be_req = be_req_create(ctx, NULL, NULL, ctx->be_ctx,
                            ad_subdom_be_req_callback, NULL);
     if (be_req == NULL) {
         DEBUG(SSSDBG_CRIT_FAILURE, ("be_req_create() failed.\n"));
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index a80bfa136068e593f8afdd5a4b3e52a363a54463..52dc5e0358656cf93e1a8c47111fa45a667665ba 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -129,6 +129,7 @@ struct be_req {
     struct be_req *next;
     struct be_client *becli;
     struct be_ctx *be_ctx;
+    char *domain_name;
     void *req_data;
 
     be_async_callback_t fn;
@@ -141,7 +142,7 @@ struct be_req {
     int phase;
 };
 
-struct be_req *be_req_create(TALLOC_CTX *mem_ctx,
+struct be_req *be_req_create(TALLOC_CTX *mem_ctx, char *domain_name,
                              struct be_client *becli, struct be_ctx *be_ctx,
                              be_async_callback_t fn, void *pvt_fn_data)
 {
@@ -154,6 +155,12 @@ struct be_req *be_req_create(TALLOC_CTX *mem_ctx,
     be_req->be_ctx = be_ctx;
     be_req->fn = fn;
     be_req->pvt = pvt_fn_data;
+    if (domain_name != NULL) {
+        be_req->domain_name = talloc_strdup(mem_ctx, domain_name);
+        if (!be_req->domain_name) {
+           return NULL;
+        }
+    }
 
     return be_req;
 }
@@ -631,7 +638,7 @@ static int be_get_subdomains(DBusMessage *message, struct sbus_connection *conn)
 
     /* process request */
 
-    be_req = be_req_create(becli, becli, becli->bectx,
+    be_req = be_req_create(becli, NULL, becli, becli->bectx,
                            get_subdomains_callback, reply);
     if (!be_req) {
         err_maj = DP_ERR_FATAL;
@@ -998,7 +1005,7 @@ be_get_account_info_send(TALLOC_CTX *mem_ctx,
                             struct be_get_account_info_state);
     if (!req) return NULL;
 
-    be_req = be_req_create(state, becli, be_ctx,
+    be_req = be_req_create(state, ar->domain, becli, be_ctx,
                            be_get_account_info_done, req);
     if (!be_req) {
         ret = ENOMEM;
@@ -1145,7 +1152,7 @@ static int be_get_account_info(DBusMessage *message, struct sbus_connection *con
          */
     }
 
-    be_req = be_req_create(becli, becli, becli->bectx,
+    be_req = be_req_create(becli, domain, becli, becli->bectx,
                            acctinfo_callback, reply);
     if (!be_req) {
         err_maj = DP_ERR_FATAL;
@@ -1343,7 +1350,7 @@ static int be_pam_handler(DBusMessage *message, struct sbus_connection *conn)
         return ENOMEM;
     }
 
-    be_req = be_req_create(becli, becli, becli->bectx,
+    be_req = be_req_create(becli, NULL, becli, becli->bectx,
                            be_pam_handler_callback, reply);
     if (!be_req) {
         DEBUG(7, ("talloc_zero failed.\n"));
@@ -1367,6 +1374,12 @@ static int be_pam_handler(DBusMessage *message, struct sbus_connection *conn)
             talloc_free(be_req);
             return ENOMEM;
         }
+    } else {
+        be_req->domain_name = talloc_strdup(becli, pd->domain);
+        if (be_req->domain_name == NULL) {
+            talloc_free(be_req);
+            return ENOMEM;
+        }
     }
 
 
@@ -1528,7 +1541,7 @@ static int be_sudo_handler(DBusMessage *message, struct sbus_connection *conn)
     }
 
     /* create be request */
-    be_req = be_req_create(be_cli, be_cli, be_cli->bectx,
+    be_req = be_req_create(be_cli, NULL, be_cli, be_cli->bectx,
                            be_sudo_handler_callback, reply);
     if (be_req == NULL) {
         DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_zero failed.\n"));
@@ -1764,7 +1777,7 @@ static int be_autofs_handler(DBusMessage *message, struct sbus_connection *conn)
     }
 
     /* create be request */
-    be_req = be_req_create(be_cli, be_cli, be_cli->bectx,
+    be_req = be_req_create(be_cli, NULL, be_cli, be_cli->bectx,
                            be_autofs_handler_callback, reply);
     if (be_req == NULL) {
         DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_zero failed.\n"));
@@ -1980,7 +1993,7 @@ static int be_host_handler(DBusMessage *message, struct sbus_connection *conn)
          */
     }
 
-    be_req = be_req_create(becli, becli, becli->bectx,
+    be_req = be_req_create(becli, NULL, becli, becli->bectx,
                            acctinfo_callback, reply);
     if (!be_req) {
         err_maj = DP_ERR_FATAL;
@@ -2256,7 +2269,7 @@ static void check_if_online(struct be_ctx *ctx)
         goto failed;
     }
 
-    be_req = be_req_create(ctx, NULL, ctx,
+    be_req = be_req_create(ctx, NULL, NULL, ctx,
                            check_online_callback, NULL);
     if (be_req == NULL) {
         DEBUG(1, ("talloc_zero failed.\n"));
diff --git a/src/providers/dp_backend.h b/src/providers/dp_backend.h
index ff36015fbc139288d4d1fcea465037b49a80164e..42e03647623d988e18b00722c878afc456f717a5 100644
--- a/src/providers/dp_backend.h
+++ b/src/providers/dp_backend.h
@@ -276,7 +276,7 @@ errno_t be_res_init(struct be_ctx *ctx);
 
 /* be_req helpers */
 
-struct be_req *be_req_create(TALLOC_CTX *mem_ctx,
+struct be_req *be_req_create(TALLOC_CTX *mem_ctx, char *domain_name,
                              struct be_client *becli, struct be_ctx *be_ctx,
                              be_async_callback_t fn, void *pvt_fn_data);
 struct be_ctx *be_req_get_be_ctx(struct be_req *be_req);
diff --git a/src/providers/ipa/ipa_subdomains.c b/src/providers/ipa/ipa_subdomains.c
index 15d71c6ebfee405ec54e4a5c48e36ee39b9b1c86..8c3f176538909f2eed86077bb2fe899239189579 100644
--- a/src/providers/ipa/ipa_subdomains.c
+++ b/src/providers/ipa/ipa_subdomains.c
@@ -1026,7 +1026,7 @@ static void ipa_subdom_online_cb(void *pvt)
 
     ctx->disabled_until = 0;
 
-    be_req = be_req_create(ctx, NULL, ctx->be_ctx,
+    be_req = be_req_create(ctx, NULL, NULL, ctx->be_ctx,
                            ipa_subdom_be_req_callback, NULL);
     if (be_req == NULL) {
         DEBUG(SSSDBG_CRIT_FAILURE, ("be_req_create() failed.\n"));
-- 
1.8.1.4

