>From ea2761e02e9832e81e04a605f134dc12c325c342 Mon Sep 17 00:00:00 2001
From: Jan Zeleny <jzeleny@redhat.com>
Date: Tue, 5 Jun 2012 09:10:24 -0400
Subject: [PATCH 08/10] Primary server support: new option in ldap provider

This patch adds support for new config option ldap_secondary_uri. The
description of this option's functionality is included in man page in
previous patch.
---
 src/config/SSSDConfig/__init__.py.in     |    2 ++
 src/config/etc/sssd.api.d/sssd-ldap.conf |    1 +
 src/man/sssd-ldap.5.xml                  |   10 +++++-----
 src/providers/ipa/ipa_opts.h             |    2 ++
 src/providers/ldap/ldap_init.c           |    7 +++----
 src/providers/ldap/ldap_opts.h           |    2 ++
 src/providers/ldap/sdap.h                |    2 ++
 7 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/config/SSSDConfig/__init__.py.in b/src/config/SSSDConfig/__init__.py.in
index b90f505d110bf293e8b65964a38c7d620e779a11..51ea228e87c6243a3e530102dccd7b89a65889ed 100644
--- a/src/config/SSSDConfig/__init__.py.in
+++ b/src/config/SSSDConfig/__init__.py.in
@@ -156,6 +156,7 @@ option_strings = {
 
     # [provider/ldap]
     'ldap_uri' : _('ldap_uri, The URI of the LDAP server'),
+    'ldap_secondary_uri' : _('ldap_secondary_uri, The URI of the LDAP server'),
     'ldap_search_base' : _('The default base DN'),
     'ldap_schema' : _('The Schema Type in use on the LDAP server, rfc2307'),
     'ldap_default_bind_dn' : _('The default bind DN'),
@@ -287,6 +288,7 @@ option_strings = {
 
     # [provider/ldap/chpass]
     'ldap_chpass_uri' : _('URI of an LDAP server where password changes are allowed'),
+    'ldap_chpass_secondary_uri' : _('URI of a secondary LDAP server where password changes are allowed'),
     'ldap_chpass_dns_service_name' : _('DNS service name for LDAP password change server'),
 
     # [provider/ldap/sudo]
diff --git a/src/config/etc/sssd.api.d/sssd-ldap.conf b/src/config/etc/sssd.api.d/sssd-ldap.conf
index cfd47e5eb5f25a46eed654ac049e2ef1e70f501f..8f5ecea4882e7e85ed4c555e17109d41f30521a7 100644
--- a/src/config/etc/sssd.api.d/sssd-ldap.conf
+++ b/src/config/etc/sssd.api.d/sssd-ldap.conf
@@ -1,5 +1,6 @@
 [provider/ldap]
 ldap_uri = str, None, false
+ldap_secondary_uri = str, None, false
 ldap_search_base = str, None, false
 ldap_schema = str, None, false
 ldap_default_bind_dn = str, None, false
diff --git a/src/man/sssd-ldap.5.xml b/src/man/sssd-ldap.5.xml
index d20d84bca2068d61aa1a64700a702eb19df73156..b4799c582abc29c1fc9cb62c83fbfa8f7f018817 100644
--- a/src/man/sssd-ldap.5.xml
+++ b/src/man/sssd-ldap.5.xml
@@ -57,14 +57,14 @@
 
             <variablelist>
                 <varlistentry>
-                    <term>ldap_uri (string)</term>
+                    <term>ldap_uri, ldap_secondary_uri (string)</term>
                     <listitem>
                         <para>
                             Specifies the comma-separated list of URIs of the LDAP servers to which
                             SSSD should connect in the order of preference. Refer to the
                             <quote>FAILOVER</quote> section for more information on failover and server redundancy.
-                            If not specified, service discovery is enabled. For more information, refer
-                            to the <quote>SERVICE DISCOVERY</quote> section.
+                            If neither option is specified, service discovery is enabled. For more information,
+                            refer to the <quote>SERVICE DISCOVERY</quote> section.
                         </para>
                         <para>
                             The format of the URI must match the format defined in RFC 2732:
@@ -82,7 +82,7 @@
                 </varlistentry>
 
                 <varlistentry>
-                    <term>ldap_chpass_uri (string)</term>
+                    <term>ldap_chpass_uri, ldap_chpass_secondary_uri (string)</term>
                     <listitem>
                         <para>
                             Specifies the comma-separated list of URIs of the LDAP servers to
@@ -1474,7 +1474,7 @@
                 </varlistentry>
 
                 <varlistentry>
-                    <term>krb5_server (string)</term>
+                    <term>krb5_server, krb5_secondary_server (string)</term>
                     <listitem>
                         <para>
                             Specifies the comma-separated list of IP addresses or hostnames
diff --git a/src/providers/ipa/ipa_opts.h b/src/providers/ipa/ipa_opts.h
index 4366a12c2ff20d5a5c2b1cedd36f8021cec41535..fcf4b3f612fd45539523dc9743ce6113a3985709 100644
--- a/src/providers/ipa/ipa_opts.h
+++ b/src/providers/ipa/ipa_opts.h
@@ -50,6 +50,7 @@ struct dp_option ipa_basic_opts[] = {
 
 struct dp_option ipa_def_ldap_opts[] = {
     { "ldap_uri", DP_OPT_STRING, NULL_STRING, NULL_STRING },
+    { "ldap_secondary_uri", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_search_base", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_default_bind_dn", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_default_authtok_type", DP_OPT_STRING, NULL_STRING, NULL_STRING},
@@ -103,6 +104,7 @@ struct dp_option ipa_def_ldap_opts[] = {
     { "ldap_account_expire_policy", DP_OPT_STRING, { "ipa" }, NULL_STRING },
     { "ldap_access_order", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_chpass_uri", DP_OPT_STRING, NULL_STRING, NULL_STRING },
+    { "ldap_chpass_secondary_uri", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_chpass_dns_service_name", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_chpass_update_last_change", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE },
     { "ldap_enumeration_search_timeout", DP_OPT_NUMBER, { .number = 60 }, NULL_NUMBER },
diff --git a/src/providers/ldap/ldap_init.c b/src/providers/ldap/ldap_init.c
index 8a6e5ee5600c48c1342be5ef03c7d5cf4c8511b0..b7e5622b48830496fdbee3eac20cd7cd12e52939 100644
--- a/src/providers/ldap/ldap_init.c
+++ b/src/providers/ldap/ldap_init.c
@@ -88,6 +88,7 @@ int sssm_ldap_id_init(struct be_ctx *bectx,
 {
     struct sdap_id_ctx *ctx;
     const char *urls;
+    const char *secondary_urls;
     const char *dns_service_name;
     const char *sasl_mech;
     int ret;
@@ -117,12 +118,10 @@ int sssm_ldap_id_init(struct be_ctx *bectx,
     DEBUG(7, ("Service name for discovery set to %s\n", dns_service_name));
 
     urls = dp_opt_get_string(ctx->opts->basic, SDAP_URI);
-    if (!urls) {
-        DEBUG(1, ("Missing ldap_uri, will use service discovery\n"));
-    }
+    secondary_urls = dp_opt_get_string(ctx->opts->basic, SDAP_SECONDARY_URI);
 
     ret = sdap_service_init(ctx, ctx->be, "LDAP",
-                            dns_service_name, urls, NULL,
+                            dns_service_name, urls, secondary_urls,
                             &ctx->service);
     if (ret != EOK) {
         DEBUG(1, ("Failed to initialize failover service!\n"));
diff --git a/src/providers/ldap/ldap_opts.h b/src/providers/ldap/ldap_opts.h
index 2d08f7a6006d5d2b79bc0eefb0f7ac66e277eb14..f0a5baa5bd9bb0ec26e879d4181c9613c293c850 100644
--- a/src/providers/ldap/ldap_opts.h
+++ b/src/providers/ldap/ldap_opts.h
@@ -31,6 +31,7 @@
 
 struct dp_option default_basic_opts[] = {
     { "ldap_uri", DP_OPT_STRING, NULL_STRING, NULL_STRING },
+    { "ldap_secondary_uri", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_search_base", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_default_bind_dn", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_default_authtok_type", DP_OPT_STRING, { "password" }, NULL_STRING},
@@ -84,6 +85,7 @@ struct dp_option default_basic_opts[] = {
     { "ldap_account_expire_policy", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_access_order", DP_OPT_STRING, { "filter" }, NULL_STRING },
     { "ldap_chpass_uri", DP_OPT_STRING, NULL_STRING, NULL_STRING },
+    { "ldap_chpass_secondary_uri", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_chpass_dns_service_name", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ldap_chpass_update_last_change", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE },
     { "ldap_enumeration_search_timeout", DP_OPT_NUMBER, { .number = 60 }, NULL_NUMBER },
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
index 253b08c57a1fe92196d6ea537fda99c664ef9e9b..a67fbf609a790717f07ffce49c5b69281cddf2cc 100644
--- a/src/providers/ldap/sdap.h
+++ b/src/providers/ldap/sdap.h
@@ -150,6 +150,7 @@ enum sdap_result {
 
 enum sdap_basic_opt {
     SDAP_URI = 0,
+    SDAP_SECONDARY_URI,
     SDAP_SEARCH_BASE,
     SDAP_DEFAULT_BIND_DN,
     SDAP_DEFAULT_AUTHTOK_TYPE,
@@ -202,6 +203,7 @@ enum sdap_basic_opt {
     SDAP_ACCOUNT_EXPIRE_POLICY,
     SDAP_ACCESS_ORDER,
     SDAP_CHPASS_URI,
+    SDAP_CHPASS_SECONDARY_URI,
     SDAP_CHPASS_DNS_SERVICE_NAME,
     SDAP_CHPASS_UPDATE_LAST_CHANGE,
     SDAP_ENUM_SEARCH_TIMEOUT,
-- 
1.7.7.6

