483b06
From 6602dffc7ab8e9bdc7fefd02f9ed11e5575f5f7b Mon Sep 17 00:00:00 2001
483b06
From: Martin Babinsky <mbabinsk@redhat.com>
483b06
Date: Wed, 22 Mar 2017 16:41:59 +0100
483b06
Subject: [PATCH] Always check and create anonymous principal during KDC
483b06
 install
483b06
483b06
The anonymous principal will now be checked for presence and created on
483b06
both server and replica install. This fixes errors caused during replica
483b06
installation against older master that do not have anonymous principal
483b06
present.
483b06
483b06
https://pagure.io/freeipa/issue/6799
483b06
483b06
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
483b06
---
483b06
 ipaserver/install/krbinstance.py | 17 +++++++++++++----
483b06
 1 file changed, 13 insertions(+), 4 deletions(-)
483b06
483b06
diff --git a/ipaserver/install/krbinstance.py b/ipaserver/install/krbinstance.py
483b06
index 5f4b5282f54234c15b1a8d8273eff69e134e665b..6c105f74c8da2bfd34ace607b13170bc96a8ff1d 100644
483b06
--- a/ipaserver/install/krbinstance.py
483b06
+++ b/ipaserver/install/krbinstance.py
483b06
@@ -33,7 +33,7 @@ from ipaserver.install import installutils
483b06
 from ipapython import ipaldap
483b06
 from ipapython import ipautil
483b06
 from ipapython import kernel_keyring
483b06
-from ipalib import api
483b06
+from ipalib import api, errors
483b06
 from ipalib.constants import ANON_USER
483b06
 from ipalib.install import certmonger
483b06
 from ipapython.ipa_log_manager import root_logger
483b06
@@ -142,6 +142,7 @@ class KrbInstance(service.Service):
483b06
             pass
483b06
 
483b06
     def __common_post_setup(self):
483b06
+        self.step("creating anonymous principal", self.add_anonymous_principal)
483b06
         self.step("starting the KDC", self.__start_instance)
483b06
         self.step("configuring KDC to start on boot", self.__enable)
483b06
 
483b06
@@ -160,7 +161,6 @@ class KrbInstance(service.Service):
483b06
         self.step("creating a keytab for the directory", self.__create_ds_keytab)
483b06
         self.step("creating a keytab for the machine", self.__create_host_keytab)
483b06
         self.step("adding the password extension to the directory", self.__add_pwd_extop_module)
483b06
-        self.step("creating anonymous principal", self.add_anonymous_principal)
483b06
 
483b06
         self.__common_post_setup()
483b06
 
483b06
@@ -432,8 +432,17 @@ class KrbInstance(service.Service):
483b06
     def add_anonymous_principal(self):
483b06
         # Create the special anonymous principal
483b06
         princ_realm = self.get_anonymous_principal_name()
483b06
-        installutils.kadmin_addprinc(princ_realm)
483b06
-        self._ldap_mod("anon-princ-aci.ldif", self.sub_dict)
483b06
+        dn = DN(('krbprincipalname', princ_realm), self.get_realm_suffix())
483b06
+        try:
483b06
+            self.api.Backend.ldap2.get_entry(dn)
483b06
+        except errors.NotFound:
483b06
+            installutils.kadmin_addprinc(princ_realm)
483b06
+            self._ldap_mod("anon-princ-aci.ldif", self.sub_dict)
483b06
+
483b06
+        try:
483b06
+            self.api.Backend.ldap2.set_entry_active(dn, True)
483b06
+        except errors.AlreadyActive:
483b06
+            pass
483b06
 
483b06
     def __convert_to_gssapi_replication(self):
483b06
         repl = replication.ReplicationManager(self.realm,
483b06
-- 
483b06
2.12.2
483b06