URL: https://github.com/freeipa/freeipa/pull/1536
Author: tiran
 Title: #1536: Fix multiple uninstallation of server
Action: opened

PR body:
"""
"ipa-server-install --uninstall" no longer fails with error message
"'Env' object has no attribute 'basedn'" when executed on a system that
has no freeIPA server installation.

Fixes: https://pagure.io/freeipa/issue/7063
Signed-off-by: Christian Heimes <chei...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1536/head:pr1536
git checkout pr1536
From 8026c6d8e1803d2e8f3e5ee0dd54a696a421e9d1 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Wed, 7 Feb 2018 14:22:06 +0100
Subject: [PATCH] Fix multiple uninstallation of server

"ipa-server-install --uninstall" no longer fails with error message
"'Env' object has no attribute 'basedn'" when executed on a system that
has no freeIPA server installation.

Fixes: https://pagure.io/freeipa/issue/7063
Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 ipalib/config.py         | 10 ++++++++++
 ipaserver/secrets/kem.py | 20 ++++++++++++--------
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/ipalib/config.py b/ipalib/config.py
index 4ee10d2a80..52b032a25a 100644
--- a/ipalib/config.py
+++ b/ipalib/config.py
@@ -576,6 +576,16 @@ def _finalize_core(self, **defaults):
         if 'log' not in self:
             self.log = self._join('logdir', '%s.log' % self.context)
 
+        # Workaround for ipa-server-install --uninstall. When no config file
+        # is available, we set realm, domain, and basedn to RFC 2606 reserved
+        # suffix to suppress attribute errors during uninstallation.
+        if (self.in_server and self.context == 'installer' and
+                not getattr(self, 'config_loaded', False)):
+            if 'realm' not in self:
+                self.realm = 'UNCONFIGURED.INVALID'
+            if 'domain' not in self:
+                self.domain = self.realm.lower()
+
         if 'basedn' not in self and 'domain' in self:
             self.basedn = DN(*(('dc', dc) for dc in self.domain.split('.')))
 
diff --git a/ipaserver/secrets/kem.py b/ipaserver/secrets/kem.py
index 5521c4772b..ad932b6b68 100644
--- a/ipaserver/secrets/kem.py
+++ b/ipaserver/secrets/kem.py
@@ -207,12 +207,15 @@ class IPAKEMKeys(KEMKeysStore):
     def __init__(self, config=None, ipaconf=paths.IPA_DEFAULT_CONF):
         super(IPAKEMKeys, self).__init__(config)
         conf = ConfigParser()
-        conf.read(ipaconf)
-        self.host = conf.get('global', 'host')
-        self.realm = conf.get('global', 'realm')
+        self.host = None
+        self.realm = None
         self.ldap_uri = config.get('ldap_uri', None)
-        if self.ldap_uri is None:
-            self.ldap_uri = conf.get('global', 'ldap_uri', raw=True)
+        if conf.read(ipaconf):
+            self.host = conf.get('global', 'host')
+            self.realm = conf.get('global', 'realm')
+            if self.ldap_uri is None:
+                self.ldap_uri = conf.get('global', 'ldap_uri', raw=True)
+
         self._server_keys = None
 
     def find_key(self, kid, usage):
@@ -259,9 +262,10 @@ def remove_keys(self, servicename):
         """
         self.remove_server_keys_file()
         principal = '%s/%s@%s' % (servicename, self.host, self.realm)
-        ldapconn = KEMLdap(self.ldap_uri)
-        ldapconn.del_key(KEY_USAGE_SIG, principal)
-        ldapconn.del_key(KEY_USAGE_ENC, principal)
+        if self.ldap_uri is not None:
+            ldapconn = KEMLdap(self.ldap_uri)
+            ldapconn.del_key(KEY_USAGE_SIG, principal)
+            ldapconn.del_key(KEY_USAGE_ENC, principal)
 
     @property
     def server_keys(self):
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to