460745
From c8fcaa5dc792e7b87c8f21c7c322ddfabe219980 Mon Sep 17 00:00:00 2001
460745
From: Felipe Volpone <fbarreto@redhat.com>
460745
Date: Wed, 13 Sep 2017 09:26:41 -0300
460745
Subject: [PATCH] Fixing how sssd.conf is updated when promoting a client to
460745
 replica
460745
460745
When promoting a client to a replica we have to change sssd.conf,
460745
deleting _srv_ part from 'ipa_server' property and setting
460745
'ipa_server_mode' to true.
460745
460745
Previously, the wrong domain could be updated since the ipa_domain
460745
variable was not being used properly.
460745
460745
https://pagure.io/freeipa/issue/7127
460745
460745
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
460745
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
460745
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
460745
---
460745
 ipaserver/install/server/replicainstall.py | 27 ++++++++++++---------------
460745
 ipaserver/install/server/upgrade.py        |  4 ++++
460745
 2 files changed, 16 insertions(+), 15 deletions(-)
460745
460745
diff --git a/ipaserver/install/server/replicainstall.py b/ipaserver/install/server/replicainstall.py
460745
index 814925de152809808f726c60ae7f35a24bc32a4a..326daf708f091d9d2c56ad399e46aef659dbba2e 100644
460745
--- a/ipaserver/install/server/replicainstall.py
460745
+++ b/ipaserver/install/server/replicainstall.py
460745
@@ -432,30 +432,27 @@ def promote_sssd(host_name):
460745
     sssdconfig.import_config()
460745
     domains = sssdconfig.list_active_domains()
460745
460745
-    ipa_domain = None
460745
-
460745
     for name in domains:
460745
         domain = sssdconfig.get_domain(name)
460745
         try:
460745
             hostname = domain.get_option('ipa_hostname')
460745
             if hostname == host_name:
460745
-                ipa_domain = domain
460745
+                break
460745
         except SSSDConfig.NoOptionError:
460745
             continue
460745
-
460745
-    if ipa_domain is None:
460745
-        raise RuntimeError("Couldn't find IPA domain in sssd.conf")
460745
     else:
460745
-        domain.set_option('ipa_server', host_name)
460745
-        domain.set_option('ipa_server_mode', True)
460745
-        sssdconfig.save_domain(domain)
460745
-        sssdconfig.write()
460745
+        raise RuntimeError("Couldn't find IPA domain in sssd.conf")
460745
460745
-        sssd = services.service('sssd', api)
460745
-        try:
460745
-            sssd.restart()
460745
-        except CalledProcessError:
460745
-            root_logger.warning("SSSD service restart was unsuccessful.")
460745
+    domain.set_option('ipa_server', host_name)
460745
+    domain.set_option('ipa_server_mode', True)
460745
+    sssdconfig.save_domain(domain)
460745
+    sssdconfig.write()
460745
+
460745
+    sssd = services.service('sssd', api)
460745
+    try:
460745
+        sssd.restart()
460745
+    except CalledProcessError:
460745
+        root_logger.warning("SSSD service restart was unsuccessful.")
460745
460745
460745
 def promote_openldap_conf(hostname, master):
460745
diff --git a/ipaserver/install/server/upgrade.py b/ipaserver/install/server/upgrade.py
460745
index 732776f2cf513a4bb11d8f3f0dfaac78217e460f..109e922e3a3ea25f882fdd81765788a3881e87bd 100644
460745
--- a/ipaserver/install/server/upgrade.py
460745
+++ b/ipaserver/install/server/upgrade.py
460745
@@ -1816,11 +1816,15 @@ def upgrade_configuration():
460745
         cainstance.ensure_ipa_authority_entry()
460745
460745
     set_sssd_domain_option('ipa_server_mode', 'True')
460745
+    set_sssd_domain_option('ipa_server', api.env.host)
460745
 
460745
     sssdconfig = SSSDConfig.SSSDConfig()
460745
     sssdconfig.import_config()
460745
     sssd_enable_service(sssdconfig, 'ifp')
460745
 
460745
+    sssd = services.service('sssd', api)
460745
+    sssd.restart()
460745
+
460745
     krb = krbinstance.KrbInstance(fstore)
460745
     krb.fqdn = fqdn
460745
     krb.realm = api.env.realm
460745
--
460745
2.13.5