From 30bb33ba8dac5fc0fef70ff0200af4a574f7aaad Mon Sep 17 00:00:00 2001
From: Petr Cech <pcech@redhat.com>
Date: Tue, 21 Jun 2016 09:48:52 +0200
Subject: [PATCH 3/4] AD_PROVIDER: ad_enabled_domains - only master

We can skip looking up other domains if option ad_enabled_domains
contains only master domain.

Resolves:
https://fedorahosted.org/sssd/ticket/2828
---
 src/providers/ad/ad_subdomains.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
index 1a92359f9d78f871fa0fcd3ebb9d3c7cfd37e7ad..f209f0b02a62416d5f422e7e0e8c3ec9cfe436c0 100644
--- a/src/providers/ad/ad_subdomains.c
+++ b/src/providers/ad/ad_subdomains.c
@@ -1170,6 +1170,7 @@ static void ad_subdomains_refresh_connect_done(struct tevent_req *subreq)
         return;
     }
 
+    /* connect to the DC we are a member of */
     subreq = ad_master_domain_send(state, state->ev, state->id_ctx->conn,
                                    state->sdap_op, state->sd_ctx->domain_name);
     if (subreq == NULL) {
@@ -1219,6 +1220,21 @@ static void ad_subdomains_refresh_master_done(struct tevent_req *subreq)
         goto done;
     }
 
+    /*
+     * If ad_enabled_domains contains only master domain
+     * we shouldn't lookup other domains.
+     */
+    if (state->sd_ctx->ad_enabled_domains != NULL) {
+        if (talloc_array_length(state->sd_ctx->ad_enabled_domains) == 2) {
+            if (strcmp(state->sd_ctx->ad_enabled_domains[0],
+                       state->be_ctx->domain->name) == 0) {
+                DEBUG(SSSDBG_TRACE_FUNC,
+                      "No other enabled domain than master.\n");
+                goto done;
+            }
+        }
+    }
+
     subreq = ad_get_root_domain_send(state, state->ev, forest,
                                      sdap_id_op_handle(state->sdap_op),
                                      state->sd_ctx);
-- 
2.5.5

