Blame SOURCES/0003-adtrust-print-DNS-records-for-external-DNS-case-after-role-is-enabled_936e27f_rhbz#1665051.patch

177dc6
From 936e27f75961c67e619ecfa641e256ce80662d68 Mon Sep 17 00:00:00 2001
177dc6
From: Alexander Bokovoy <abokovoy@redhat.com>
177dc6
Date: Feb 14 2020 07:24:58 +0000
177dc6
Subject: adtrust: print DNS records for external DNS case after role is enabled
177dc6
177dc6
177dc6
We cannot gather information about required DNS records before "ADTrust
177dc6
Controller" role is enabled on this server. As result, we need to call
177dc6
the step to add DNS records after the role was enabled.
177dc6
177dc6
Fixes: https://pagure.io/freeipa/issue/8192
177dc6
Signed-off-by: Alexander Bokovoy <abokovoy@redhat.com>
177dc6
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
177dc6
177dc6
---
177dc6
177dc6
diff --git a/install/tools/ipa-adtrust-install.in b/install/tools/ipa-adtrust-install.in
177dc6
index 1abfea9..7d94b71 100644
177dc6
--- a/install/tools/ipa-adtrust-install.in
177dc6
+++ b/install/tools/ipa-adtrust-install.in
177dc6
@@ -214,7 +214,13 @@ def main():
177dc6
 
177dc6
     # Enable configured services and update DNS SRV records
177dc6
     service.sync_services_state(api.env.host)
177dc6
-    api.Command.dns_update_system_records()
177dc6
+
177dc6
+    dns_help = adtrust.generate_dns_service_records_help(api)
177dc6
+    if dns_help:
177dc6
+        for line in dns_help:
177dc6
+            service.print_msg(line, sys.stdout)
177dc6
+    else:
177dc6
+        api.Command.dns_update_system_records()
177dc6
 
177dc6
     print("""
177dc6
 =============================================================================
177dc6
diff --git a/ipaserver/install/adtrust.py b/ipaserver/install/adtrust.py
177dc6
index 70c4359..6c14e84 100644
177dc6
--- a/ipaserver/install/adtrust.py
177dc6
+++ b/ipaserver/install/adtrust.py
177dc6
@@ -26,6 +26,8 @@ from ipaserver.install import installutils
177dc6
 from ipaserver.install import adtrustinstance
177dc6
 from ipaserver.install import service
177dc6
 from ipaserver.install.plugins.adtrust import update_host_cifs_keytabs
177dc6
+from ipaserver.install.bindinstance import dns_zone_exists
177dc6
+from ipaserver.dns_data_management import IPASystemRecords
177dc6
 
177dc6
 
177dc6
 if six.PY3:
177dc6
@@ -436,6 +438,41 @@ def install(standalone, options, fstore, api):
177dc6
         add_new_adtrust_agents(api, options)
177dc6
 
177dc6
 
177dc6
+def generate_dns_service_records_help(api):
177dc6
+    """
177dc6
+    Return list of instructions to create DNS service records for Windows
177dc6
+    if in case DNS is not enabled and the DNS zone is not managed by IPA.
177dc6
+    In case IPA manages the DNS zone, nothing is returned.
177dc6
+    """
177dc6
+
177dc6
+    zone = api.env.domain
177dc6
+
177dc6
+    err_msg = []
177dc6
+
177dc6
+    ret = api.Command['dns_is_enabled']()
177dc6
+    if not ret['result']:
177dc6
+        err_msg.append("DNS management was not enabled at install time.")
177dc6
+    else:
177dc6
+        if not dns_zone_exists(zone):
177dc6
+            err_msg.append(
177dc6
+                "DNS zone %s cannot be managed as it is not defined in "
177dc6
+                "IPA" % zone)
177dc6
+
177dc6
+    if err_msg:
177dc6
+        err_msg.append("Add the following service records to your DNS "
177dc6
+                       "server for DNS zone %s: " % zone)
177dc6
+        system_records = IPASystemRecords(api, all_servers=True)
177dc6
+        adtrust_records = system_records.get_base_records(
177dc6
+            [api.env.host], ["AD trust controller"],
177dc6
+            include_master_role=False, include_kerberos_realm=False)
177dc6
+        for r_name, node in adtrust_records.items():
177dc6
+            for rec in IPASystemRecords.records_list_from_node(r_name, node):
177dc6
+                err_msg.append(rec)
177dc6
+        return err_msg
177dc6
+
177dc6
+    return None
177dc6
+
177dc6
+
177dc6
 @group
177dc6
 class ADTrustInstallInterface(ServiceAdminInstallInterface):
177dc6
     """
177dc6
diff --git a/ipaserver/install/adtrustinstance.py b/ipaserver/install/adtrustinstance.py
177dc6
index 8699d53..a59e85d 100644
177dc6
--- a/ipaserver/install/adtrustinstance.py
177dc6
+++ b/ipaserver/install/adtrustinstance.py
177dc6
@@ -32,10 +32,8 @@ import socket
177dc6
 
177dc6
 import six
177dc6
 
177dc6
-from ipaserver.dns_data_management import IPASystemRecords
177dc6
 from ipaserver.install import service
177dc6
 from ipaserver.install import installutils
177dc6
-from ipaserver.install.bindinstance import dns_zone_exists
177dc6
 from ipaserver.install.replication import wait_for_task
177dc6
 from ipalib import errors, api
177dc6
 from ipalib.util import normalize_zone
177dc6
@@ -586,43 +584,6 @@ class ADTRUSTInstance(service.Service):
177dc6
                     logger.critical("Failed to remove old key for %s",
177dc6
                                     self.principal)
177dc6
 
177dc6
-    def srv_rec(self, host, port, prio):
177dc6
-        return "%(prio)d 100 %(port)d %(host)s" % dict(host=host,prio=prio,port=port)
177dc6
-
177dc6
-    def __add_dns_service_records(self):
177dc6
-        """
177dc6
-        Add DNS service records for Windows if DNS is enabled and the DNS zone
177dc6
-        is managed. If there are already service records for LDAP and Kerberos
177dc6
-        their values are used. Otherwise default values are used.
177dc6
-        """
177dc6
-
177dc6
-        zone = api.env.domain
177dc6
-
177dc6
-        err_msg = None
177dc6
-
177dc6
-        ret = api.Command['dns_is_enabled']()
177dc6
-        if not ret['result']:
177dc6
-            err_msg = "DNS management was not enabled at install time."
177dc6
-        else:
177dc6
-            if not dns_zone_exists(zone):
177dc6
-                err_msg = (
177dc6
-                    "DNS zone %s cannot be managed as it is not defined in "
177dc6
-                    "IPA" % zone)
177dc6
-
177dc6
-        if err_msg:
177dc6
-            self.print_msg(err_msg)
177dc6
-            self.print_msg("Add the following service records to your DNS " \
177dc6
-                           "server for DNS zone %s: " % zone)
177dc6
-            system_records = IPASystemRecords(api, all_servers=True)
177dc6
-            adtrust_records = system_records.get_base_records(
177dc6
-                [self.fqdn], ["AD trust controller"],
177dc6
-                include_master_role=False, include_kerberos_realm=False)
177dc6
-            for r_name, node in adtrust_records.items():
177dc6
-                for rec in IPASystemRecords.records_list_from_node(r_name, node):
177dc6
-                    self.print_msg(rec)
177dc6
-        else:
177dc6
-            api.Command.dns_update_system_records()
177dc6
-
177dc6
     def __configure_selinux_for_smbd(self):
177dc6
         try:
177dc6
             tasks.set_selinux_booleans(constants.SELINUX_BOOLEAN_ADTRUST,
177dc6
@@ -876,8 +837,6 @@ class ADTRUSTInstance(service.Service):
177dc6
         self.step("map BUILTIN\\Guests to nobody group",
177dc6
                   self.__map_Guests_to_nobody)
177dc6
         self.step("configuring smbd to start on boot", self.__enable)
177dc6
-        self.step("adding special DNS service records", \
177dc6
-                  self.__add_dns_service_records)
177dc6
 
177dc6
         if self.enable_compat:
177dc6
             self.step("enabling trusted domains support for older clients via Schema Compatibility plugin",
177dc6
diff --git a/ipaserver/install/server/install.py b/ipaserver/install/server/install.py
177dc6
index 6b08b70..afce0d7 100644
177dc6
--- a/ipaserver/install/server/install.py
177dc6
+++ b/ipaserver/install/server/install.py
177dc6
@@ -984,6 +984,12 @@ def install(installer):
177dc6
     service.enable_services(host_name)
177dc6
     api.Command.dns_update_system_records()
177dc6
 
177dc6
+    if options.setup_adtrust:
177dc6
+        dns_help = adtrust.generate_dns_service_records_help(api)
177dc6
+        if dns_help:
177dc6
+            for line in dns_help:
177dc6
+                service.print_msg(line, sys.stdout)
177dc6
+
177dc6
     if not options.setup_dns:
177dc6
         # After DNS and AD trust are configured and services are
177dc6
         # enabled, create a dummy instance to dump DNS configuration.
177dc6
diff --git a/ipaserver/install/server/replicainstall.py b/ipaserver/install/server/replicainstall.py
177dc6
index 536f0db..71ea091 100644
177dc6
--- a/ipaserver/install/server/replicainstall.py
177dc6
+++ b/ipaserver/install/server/replicainstall.py
177dc6
@@ -1351,6 +1351,12 @@ def install(installer):
177dc6
     # enabled-service case, also perform update in hidden replica case.
177dc6
     api.Command.dns_update_system_records()
177dc6
 
177dc6
+    if options.setup_adtrust:
177dc6
+        dns_help = adtrust.generate_dns_service_records_help(api)
177dc6
+        if dns_help:
177dc6
+            for line in dns_help:
177dc6
+                service.print_msg(line, sys.stdout)
177dc6
+
177dc6
     ca_servers = find_providing_servers('CA', api.Backend.ldap2, api=api)
177dc6
     api.Backend.ldap2.disconnect()
177dc6
 
177dc6