From a96b80ffb3968afd2c182ad9e5dd5a9da7798743 Mon Sep 17 00:00:00 2001
From: Petr Cech <pcech@redhat.com>
Date: Thu, 9 Jun 2016 02:43:01 -0400
Subject: [PATCH 3/5] 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 a30199912db52d97da8fb94d42cb323c3950c957..381143bf945a419cb3a3163bb7fdc1acc8d0107b 100644
--- a/src/providers/ad/ad_subdomains.c
+++ b/src/providers/ad/ad_subdomains.c
@@ -577,6 +577,7 @@ static void ad_subdomains_get_conn_done(struct tevent_req *req)
         goto fail;
     }
 
+    /* connect to the DC we are a member of */
     req = ad_master_domain_send(ctx, ctx->sd_ctx->be_ctx->ev,
                                 ctx->sd_ctx->ldap_ctx,
                                 ctx->sdap_op,
@@ -627,6 +628,21 @@ static void ad_subdomains_master_dom_done(struct tevent_req *req)
         goto done;
     }
 
+    /*
+     * If ad_enabled_domains contains only master domain
+     * we shouldn't lookup other domains.
+     */
+    if (ctx->sd_ctx->ad_enabled_domains != NULL) {
+        if (talloc_array_length(ctx->sd_ctx->ad_enabled_domains) == 2) {
+            if (strcmp(ctx->sd_ctx->ad_enabled_domains[0],
+                       ctx->sd_ctx->be_ctx->domain->name) == 0) {
+                DEBUG(SSSDBG_TRACE_FUNC,
+                      "No other enabled domain than master.\n");
+                goto done;
+            }
+        }
+    }
+
     if (ctx->forest == NULL ||
           strcasecmp(ctx->sd_ctx->be_ctx->domain->name, ctx->forest) != 0) {
         DEBUG(SSSDBG_TRACE_FUNC,
-- 
2.5.5

