More cleanup after uninstall

Remove more files during ipaserver uninstallation:

* /etc/gssproxy/10-ipa.conf
* /etc/httpd/alias/*.ipasave
* /etc/httpd/conf/password.conf
* /etc/ipa/dnssec/softhsm2.conf
* /etc/systemd/system/httpd.service.d/
* /var/lib/ipa/dnssec/tokens

Fixes: https://pagure.io/freeipa/issue/7183
See: https://pagure.io/freeipa/issue/2694
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Alexander Koksharov <akokshar@redhat.com>
This commit is contained in:
Christian Heimes
2018-03-20 10:15:28 +01:00
parent 64fca87a52
commit a6e6e7f5e4
3 changed files with 50 additions and 21 deletions
+10 -3
View File
@@ -5,6 +5,7 @@
from __future__ import print_function from __future__ import print_function
import logging import logging
import errno
import os import os
import pwd import pwd
import grp import grp
@@ -463,9 +464,15 @@ class DNSKeySyncInstance(service.Service):
# remove softhsm pin, to make sure new installation will generate # remove softhsm pin, to make sure new installation will generate
# new token database # new token database
# do not delete *so pin*, user can need it to get token data # do not delete *so pin*, user can need it to get token data
installutils.remove_file(paths.DNSSEC_SOFTHSM_PIN)
installutils.remove_file(paths.DNSSEC_SOFTHSM2_CONF)
try: try:
os.remove(paths.DNSSEC_SOFTHSM_PIN) shutil.rmtree(paths.DNSSEC_TOKENS_DIR)
except Exception: except OSError as e:
pass if e.errno != errno.ENOENT:
logger.exception(
"Failed to remove %s", paths.DNSSEC_TOKENS_DIR
)
installutils.remove_keytab(self.keytab) installutils.remove_keytab(self.keytab)
+35 -13
View File
@@ -22,13 +22,14 @@ from __future__ import absolute_import
import logging import logging
import os import os
import os.path import glob
import dbus import errno
import shlex import shlex
import pipes import pipes
import tempfile import tempfile
from augeas import Augeas from augeas import Augeas
import dbus
from ipalib.install import certmonger from ipalib.install import certmonger
from ipapython import ipaldap from ipapython import ipaldap
@@ -493,19 +494,40 @@ class HTTPInstance(service.Service):
except ValueError as error: except ValueError as error:
logger.debug("%s", error) logger.debug("%s", error)
installutils.remove_keytab(self.keytab)
installutils.remove_file(paths.HTTP_CCACHE)
# Remove the configuration files we create # Remove the configuration files we create
installutils.remove_file(paths.HTTPD_CERT_FILE) installutils.remove_keytab(self.keytab)
installutils.remove_file(paths.HTTPD_KEY_FILE) remove_files = [
installutils.remove_file(paths.HTTPD_IPA_REWRITE_CONF) paths.HTTP_CCACHE,
installutils.remove_file(paths.HTTPD_IPA_CONF) paths.HTTPD_CERT_FILE,
installutils.remove_file(paths.HTTPD_IPA_PKI_PROXY_CONF) paths.HTTPD_KEY_FILE,
installutils.remove_file(paths.HTTPD_IPA_KDCPROXY_CONF_SYMLINK) paths.HTTPD_IPA_REWRITE_CONF,
installutils.remove_file(paths.HTTPD_IPA_KDCPROXY_CONF) paths.HTTPD_IPA_CONF,
paths.HTTPD_IPA_PKI_PROXY_CONF,
paths.HTTPD_IPA_KDCPROXY_CONF_SYMLINK,
paths.HTTPD_IPA_KDCPROXY_CONF,
paths.GSSPROXY_CONF,
paths.GSSAPI_SESSION_KEY,
paths.HTTPD_PASSWORD_CONF,
paths.SYSTEMD_SYSTEM_HTTPD_IPA_CONF,
]
# NSS DB backups
remove_files.extend(
glob.glob(os.path.join(paths.HTTPD_ALIAS_DIR, '*.ipasave'))
)
if paths.HTTPD_IPA_WSGI_MODULES_CONF is not None: if paths.HTTPD_IPA_WSGI_MODULES_CONF is not None:
installutils.remove_file(paths.HTTPD_IPA_WSGI_MODULES_CONF) remove_files.append(paths.HTTPD_IPA_WSGI_MODULES_CONF)
for filename in remove_files:
installutils.remove_file(filename)
try:
os.rmdir(paths.SYSTEMD_SYSTEM_HTTPD_D_DIR)
except OSError as e:
if e.errno not in {errno.ENOENT, errno.ENOTEMPTY}:
logger.error(
"Failed to remove directory %s",
paths.SYSTEMD_SYSTEM_HTTPD_D_DIR
)
# Restore SELinux boolean states # Restore SELinux boolean states
boolean_states = {name: self.restore_state(name) boolean_states = {name: self.restore_state(name)
+5 -5
View File
@@ -964,14 +964,14 @@ def check_server_configuration():
def remove_file(filename): def remove_file(filename):
""" """Remove a file and log any exceptions raised.
Remove a file and log any exceptions raised.
""" """
try: try:
if os.path.lexists(filename): os.unlink(filename)
os.unlink(filename)
except Exception as e: except Exception as e:
logger.error('Error removing %s: %s', filename, str(e)) # ignore missing file
if getattr(e, 'errno', None) != errno.ENOENT:
logger.error('Error removing %s: %s', filename, str(e))
def rmtree(path): def rmtree(path):