Blame SOURCES/0029-AD-Add-a-new-option-to-turn-off-GC-lookups.patch

2fc102
From 168396cd93b3f0e42b4842f520f2bcece91274c6 Mon Sep 17 00:00:00 2001
2fc102
From: Jakub Hrozek <jhrozek@redhat.com>
2fc102
Date: Fri, 29 Nov 2013 11:39:09 +0100
2fc102
Subject: [PATCH 29/31] AD: Add a new option to turn off GC lookups
2fc102
2fc102
SSSD now defaults to using GC by default. For some environments, for
2fc102
instance those that don't or can't replicate the POSIX attributes to
2fc102
Global Catalog, this might not be desirable.
2fc102
2fc102
This patch introduces a new option ad_enable_gc, that is enabled by
2fc102
default. Setting this option to false makes the SSSD contact only the
2fc102
LDAP port of AD DCs.
2fc102
---
2fc102
 src/config/etc/sssd.api.d/sssd-ad.conf |  1 +
2fc102
 src/man/sssd-ad.5.xml                  | 17 +++++++++++++++++
2fc102
 src/providers/ad/ad_common.c           | 31 ++++++++++++++++++-------------
2fc102
 src/providers/ad/ad_common.h           |  1 +
2fc102
 src/providers/ad/ad_opts.h             |  1 +
2fc102
 src/tests/cmocka/test_ad_common.c      | 20 ++++++++++++++++++++
2fc102
 6 files changed, 58 insertions(+), 13 deletions(-)
2fc102
2fc102
diff --git a/src/config/etc/sssd.api.d/sssd-ad.conf b/src/config/etc/sssd.api.d/sssd-ad.conf
2fc102
index 9f606f6c4da65d4bfb20a97ee27801dac9307868..00e8968d2b6dab33a39005f11a497cb3e2185302 100644
2fc102
--- a/src/config/etc/sssd.api.d/sssd-ad.conf
2fc102
+++ b/src/config/etc/sssd.api.d/sssd-ad.conf
2fc102
@@ -5,6 +5,7 @@ ad_backup_server = str, None, false
2fc102
 ad_hostname = str, None, false
2fc102
 ad_enable_dns_sites = bool, None, false
2fc102
 ad_access_filter = str, None, false
2fc102
+ad_enable_gc = bool, None, false
2fc102
 ldap_uri = str, None, false
2fc102
 ldap_backup_uri = str, None, false
2fc102
 ldap_search_base = str, None, false
2fc102
diff --git a/src/man/sssd-ad.5.xml b/src/man/sssd-ad.5.xml
2fc102
index e31f87a96a14907c64166e53da443ad735c6e85e..38cc31278cf87c98ca9e53cf91fda7b141bff78d 100644
2fc102
--- a/src/man/sssd-ad.5.xml
2fc102
+++ b/src/man/sssd-ad.5.xml
2fc102
@@ -228,6 +228,23 @@ FOREST:EXAMPLE.COM:(memberOf=cn=admins,ou=groups,dc=example,dc=com)
2fc102
                 </varlistentry>
2fc102
 
2fc102
                 <varlistentry>
2fc102
+                    <term>ad_enable_gc (boolean)</term>
2fc102
+                    <listitem>
2fc102
+                        <para>
2fc102
+                            By default, the SSSD connects to the Global
2fc102
+                            Catalog first to retrieve users and uses the
2fc102
+                            LDAP port to retrieve group memberships or
2fc102
+                            as a fallback. Disabling this option makes
2fc102
+                            the SSSD only connect to the LDAP port of the
2fc102
+                            current AD server.
2fc102
+                        </para>
2fc102
+                        <para>
2fc102
+                            Default: true
2fc102
+                        </para>
2fc102
+                    </listitem>
2fc102
+                </varlistentry>
2fc102
+
2fc102
+                <varlistentry>
2fc102
                     <term>dyndns_update (boolean)</term>
2fc102
                     <listitem>
2fc102
                         <para>
2fc102
diff --git a/src/providers/ad/ad_common.c b/src/providers/ad/ad_common.c
2fc102
index af0ec839964233c7642205f4489e5b6462509848..a5ea4f587f30575a5903d8ae1a459f53512c011f 100644
2fc102
--- a/src/providers/ad/ad_common.c
2fc102
+++ b/src/providers/ad/ad_common.c
2fc102
@@ -1125,26 +1125,31 @@ ad_gc_conn_list(TALLOC_CTX *mem_ctx, struct ad_id_ctx *ad_ctx,
2fc102
                 struct sss_domain_info *dom)
2fc102
 {
2fc102
     struct sdap_id_conn_ctx **clist;
2fc102
+    int cindex = 0;
2fc102
 
2fc102
     clist = talloc_zero_array(mem_ctx, struct sdap_id_conn_ctx *, 3);
2fc102
     if (clist == NULL) return NULL;
2fc102
 
2fc102
     /* Always try GC first */
2fc102
-    clist[0] = ad_ctx->gc_ctx;
2fc102
-    if (IS_SUBDOMAIN(dom) == true) {
2fc102
-        clist[0]->ignore_mark_offline = false;
2fc102
-        /* Subdomain users are only present in GC. */
2fc102
-        return clist;
2fc102
+    if (dp_opt_get_bool(ad_ctx->ad_options->basic, AD_ENABLE_GC)) {
2fc102
+        clist[cindex] = ad_ctx->gc_ctx;
2fc102
+        if (IS_SUBDOMAIN(dom) == true) {
2fc102
+            clist[cindex]->ignore_mark_offline = false;
2fc102
+            /* Subdomain users are only present in GC. */
2fc102
+            return clist;
2fc102
+        }
2fc102
+        /* fall back to ldap if gc is not available */
2fc102
+        clist[cindex]->ignore_mark_offline = true;
2fc102
+        cindex++;
2fc102
     }
2fc102
 
2fc102
-    /* fall back to ldap if gc is not available */
2fc102
-    clist[0]->ignore_mark_offline = true;
2fc102
-
2fc102
-    /* With root domain users we have the option to
2fc102
-     * fall back to LDAP in case ie POSIX attributes
2fc102
-     * are used but not replicated to GC
2fc102
-     */
2fc102
-    clist[1] = ad_ctx->ldap_ctx;
2fc102
+    if (IS_SUBDOMAIN(dom) == false) {
2fc102
+        /* With root domain users we have the option to
2fc102
+         * fall back to LDAP in case ie POSIX attributes
2fc102
+         * are used but not replicated to GC
2fc102
+         */
2fc102
+        clist[cindex] = ad_ctx->ldap_ctx;
2fc102
+    }
2fc102
 
2fc102
     return clist;
2fc102
 }
2fc102
diff --git a/src/providers/ad/ad_common.h b/src/providers/ad/ad_common.h
2fc102
index ed5b8584dc5327a24e60985486c6155604271fd2..d370cef69124c127f41d7c4cbaa25713363e7752 100644
2fc102
--- a/src/providers/ad/ad_common.h
2fc102
+++ b/src/providers/ad/ad_common.h
2fc102
@@ -42,6 +42,7 @@ enum ad_basic_opt {
2fc102
     AD_KRB5_REALM,
2fc102
     AD_ENABLE_DNS_SITES,
2fc102
     AD_ACCESS_FILTER,
2fc102
+    AD_ENABLE_GC,
2fc102
 
2fc102
     AD_OPTS_BASIC /* opts counter */
2fc102
 };
2fc102
diff --git a/src/providers/ad/ad_opts.h b/src/providers/ad/ad_opts.h
2fc102
index 8022a16274a04389b7a64b491ec28a0c3c55aaef..5b7b1c89f5f45d7cc744a955e6378390948a99fd 100644
2fc102
--- a/src/providers/ad/ad_opts.h
2fc102
+++ b/src/providers/ad/ad_opts.h
2fc102
@@ -36,6 +36,7 @@ struct dp_option ad_basic_opts[] = {
2fc102
     { "krb5_realm", DP_OPT_STRING, NULL_STRING, NULL_STRING},
2fc102
     { "ad_enable_dns_sites", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
2fc102
     { "ad_access_filter", DP_OPT_STRING, NULL_STRING, NULL_STRING},
2fc102
+    { "ad_enable_gc", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
2fc102
     DP_OPTION_TERMINATOR
2fc102
 };
2fc102
 
2fc102
diff --git a/src/tests/cmocka/test_ad_common.c b/src/tests/cmocka/test_ad_common.c
2fc102
index 648b68f2dc05947b1fbb4c680ec63d3c2c6275b3..07502b82d43d730562c60125b639d8e7d1034458 100644
2fc102
--- a/src/tests/cmocka/test_ad_common.c
2fc102
+++ b/src/tests/cmocka/test_ad_common.c
2fc102
@@ -159,6 +159,8 @@ void test_conn_list(void **state)
2fc102
                                                      struct ad_common_test_ctx);
2fc102
     assert_non_null(test_ctx);
2fc102
 
2fc102
+    assert_true(dp_opt_get_bool(test_ctx->ad_ctx->ad_options->basic,
2fc102
+                                AD_ENABLE_GC));
2fc102
     conn_list = ad_gc_conn_list(test_ctx, test_ctx->ad_ctx, test_ctx->dom);
2fc102
     assert_non_null(conn_list);
2fc102
 
2fc102
@@ -177,6 +179,24 @@ void test_conn_list(void **state)
2fc102
     assert_false(conn_list[0]->ignore_mark_offline);
2fc102
     assert_null(conn_list[1]);
2fc102
     talloc_free(conn_list);
2fc102
+
2fc102
+    dp_opt_set_bool(test_ctx->ad_ctx->ad_options->basic, AD_ENABLE_GC, false);
2fc102
+    assert_false(dp_opt_get_bool(test_ctx->ad_ctx->ad_options->basic,
2fc102
+                                 AD_ENABLE_GC));
2fc102
+
2fc102
+    conn_list = ad_gc_conn_list(test_ctx, test_ctx->ad_ctx, test_ctx->dom);
2fc102
+    assert_non_null(conn_list);
2fc102
+
2fc102
+    assert_true(conn_list[0] == test_ctx->ad_ctx->ldap_ctx);
2fc102
+    assert_false(conn_list[0]->ignore_mark_offline);
2fc102
+    assert_null(conn_list[1]);
2fc102
+    talloc_free(conn_list);
2fc102
+
2fc102
+    conn_list = ad_gc_conn_list(test_ctx, test_ctx->ad_ctx, test_ctx->subdom);
2fc102
+    assert_non_null(conn_list);
2fc102
+
2fc102
+    assert_null(conn_list[0]);
2fc102
+    talloc_free(conn_list);
2fc102
 }
2fc102
 
2fc102
 int main(int argc, const char *argv[])
2fc102
-- 
2fc102
1.8.4.2
2fc102