From 51080a5cf156f4d741b35d25e0ff6c943a93e513 Mon Sep 17 00:00:00 2001
From: Jan Zeleny <jzeleny@redhat.com>
Date: Wed, 6 Jun 2012 05:11:44 -0400
Subject: [PATCH 8/8] Primary server support: new option in IPA provider

This patch adds support for new config option ipa_secondary_server. The
description of this option's functionality is included in man page in
one of previous patches.
---
 src/config/etc/sssd.api.d/sssd-ipa.conf |    1 +
 src/man/sssd-ipa.5.xml                  |    2 +-
 src/providers/ipa/ipa_common.c          |    4 ++++
 src/providers/ipa/ipa_common.h          |    1 +
 src/providers/ipa/ipa_init.c            |    8 ++++----
 src/providers/ipa/ipa_opts.h            |    1 +
 6 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/config/etc/sssd.api.d/sssd-ipa.conf b/src/config/etc/sssd.api.d/sssd-ipa.conf
index 20eb71f4cc0cb0d7304865fa88923fc372ce67a3..42bc6d1597faf6c72edbe7878b54811ed387b2b2 100644
--- a/src/config/etc/sssd.api.d/sssd-ipa.conf
+++ b/src/config/etc/sssd.api.d/sssd-ipa.conf
@@ -1,6 +1,7 @@
 [provider/ipa]
 ipa_domain = str, None, false
 ipa_server = str, None, false
+ipa_secondary_server = str, None, false
 ipa_hostname = str, None, false
 ipa_dyndns_update = bool, None, false
 ipa_dyndns_iface = str, None, false
diff --git a/src/man/sssd-ipa.5.xml b/src/man/sssd-ipa.5.xml
index 9b8a140ce539b929b5d2af056e3bff78f28d2214..38a6caefce5979c3cb1ff3b6a87f0943100faab6 100644
--- a/src/man/sssd-ipa.5.xml
+++ b/src/man/sssd-ipa.5.xml
@@ -80,7 +80,7 @@
                 </varlistentry>
 
                 <varlistentry>
-                    <term>ipa_server (string)</term>
+                    <term>ipa_server, ipa_secondary_server (string)</term>
                     <listitem>
                         <para>
                             The comma-separated list of IP addresses or hostnames of the
diff --git a/src/providers/ipa/ipa_common.c b/src/providers/ipa/ipa_common.c
index 07976130e26fd77f6dba53a85d8d03e116779805..251c7598fafa3491183b907b18285dffafd0128f 100644
--- a/src/providers/ipa/ipa_common.c
+++ b/src/providers/ipa/ipa_common.c
@@ -867,9 +867,13 @@ int ipa_service_init(TALLOC_CTX *memctx, struct be_ctx *ctx,
 
     if (!primary_servers) {
         if (secondary_servers) {
+            DEBUG(SSSDBG_CONF_SETTINGS, ("Missing primary IPA server but "
+                                         "secondary server given - using it as primary!\n"));
             primary_servers = secondary_servers;
             secondary_servers = NULL;
         } else {
+            DEBUG(SSSDBG_CONF_SETTINGS, ("Missing primary and secondary IPA "
+                                         "servers - using service discovery!\n"));
             primary_servers = BE_SRV_IDENTIFIER;
         }
     }
diff --git a/src/providers/ipa/ipa_common.h b/src/providers/ipa/ipa_common.h
index 524920261c98601158371a478e796f48f155cc9a..81f4171a27459ec0c7b5b10f93e2e832c2239af3 100644
--- a/src/providers/ipa/ipa_common.h
+++ b/src/providers/ipa/ipa_common.h
@@ -35,6 +35,7 @@ struct ipa_service {
 enum ipa_basic_opt {
     IPA_DOMAIN = 0,
     IPA_SERVER,
+    IPA_SECONDARY_SERVER,
     IPA_HOSTNAME,
     IPA_DYNDNS_UPDATE,
     IPA_DYNDNS_IFACE,
diff --git a/src/providers/ipa/ipa_init.c b/src/providers/ipa/ipa_init.c
index 5e79cb41de495d787671b63ea67c6300c71f57cb..0132c8c4c2d537ebcec0699730035c81cd31ee7e 100644
--- a/src/providers/ipa/ipa_init.c
+++ b/src/providers/ipa/ipa_init.c
@@ -83,6 +83,7 @@ struct bet_ops ipa_subdomains_ops = {
 int common_ipa_init(struct be_ctx *bectx)
 {
     const char *ipa_servers;
+    const char *ipa_secondary_servers;
     int ret;
 
     ret = ipa_get_options(bectx, bectx->cdb,
@@ -93,11 +94,10 @@ int common_ipa_init(struct be_ctx *bectx)
     }
 
     ipa_servers = dp_opt_get_string(ipa_options->basic, IPA_SERVER);
-    if (!ipa_servers) {
-        DEBUG(1, ("Missing ipa_server option - using service discovery!\n"));
-    }
+    ipa_secondary_servers = dp_opt_get_string(ipa_options->basic, IPA_SECONDARY_SERVER);
 
-    ret = ipa_service_init(ipa_options, bectx, ipa_servers, NULL, ipa_options,
+    ret = ipa_service_init(ipa_options, bectx, ipa_servers,
+                           ipa_secondary_servers, ipa_options,
                            &ipa_options->service);
     if (ret != EOK) {
         DEBUG(0, ("Failed to init IPA failover service!\n"));
diff --git a/src/providers/ipa/ipa_opts.h b/src/providers/ipa/ipa_opts.h
index 0eb9f215dbcf89e702413766b3d223ac49047c90..36ad2daf9ce840e353330889be82b7a2850e3868 100644
--- a/src/providers/ipa/ipa_opts.h
+++ b/src/providers/ipa/ipa_opts.h
@@ -32,6 +32,7 @@
 struct dp_option ipa_basic_opts[] = {
     { "ipa_domain", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ipa_server", DP_OPT_STRING, NULL_STRING, NULL_STRING },
+    { "ipa_secondary_server", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ipa_hostname", DP_OPT_STRING, NULL_STRING, NULL_STRING },
     { "ipa_dyndns_update", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE },
     { "ipa_dyndns_iface", DP_OPT_STRING, NULL_STRING, NULL_STRING},
-- 
1.7.7.6

