[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [Freeipa-devel] [PATCH] 960 remove unused kdc files



Rob Crittenden wrote:
Martin Kosek wrote:
On Wed, 2012-02-22 at 17:12 -0500, Rob Crittenden wrote:
These files are deprecated by new ipa-kdb backend, remove them if they
exist.

rob

This left entries in our sysrestore.

/var/lib/ipa/sysrestore/sysrestore.index
[files]
...
0ecc2886db996851-ldappwd = 33152,0,0,/var/kerberos/krb5kdc/ldappwd
bbe9d5b1dddf0151-kpasswd.keytab =
33152,0,0,/var/kerberos/krb5kdc/kpasswd.keytab
...

These will be restored during uninstall. I am wondering if this is a
behavior we want.

Martin


I think you'd only have this if you configured 2.1, unconfigured,
reconfigured then updated to 2.2.

But yeah, I'll see if I can remove these from the index. Otherwise when
2.2 was uninstalled it would complain about left-over files.

rob

Updated patch to remove any backup files as well.

rob
>From d82c4e2283eb4a4e0e1a8bd5b5c4fca2cde29019 Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcritten redhat com>
Date: Wed, 22 Feb 2012 16:40:29 -0500
Subject: [PATCH] Remove unused kpasswd.keytab and ldappwd files if they
 exist.

These were used by ipa_kpasswd and krb5-server-ldap respectivily.

https://fedorahosted.org/freeipa/ticket/2397
---
 install/tools/ipa-upgradeconfig |   14 ++++++++++++
 ipapython/sysrestore.py         |   43 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/install/tools/ipa-upgradeconfig b/install/tools/ipa-upgradeconfig
index 725a9d106833b8892fedf9897061e80ebf4500e6..535628a72bc2a989e24fedd7735174d97d248db8 100644
--- a/install/tools/ipa-upgradeconfig
+++ b/install/tools/ipa-upgradeconfig
@@ -220,6 +220,19 @@ def update_dbmodules(realm, filename="/etc/krb5.conf"):
     fd.write("".join(newfile))
     fd.close()
 
+def cleanup_kdc():
+    """
+    Clean up old KDC files if they exist. We need to remove the actual
+    file and any references in the uninstall configuration.
+    """
+    fstore = sysrestore.FileStore('/var/lib/ipa/sysrestore')
+
+    for file in ['kpasswd.keytab', 'ldappwd']:
+        filename = '/var/kerberos/krb5kdc/%s' % file
+        installutils.remove_file(filename)
+        if fstore.has_file(filename):
+            fstore.untrack_file(filename)
+
 def main():
     """
     Get some basics about the system. If getting those basics fail then
@@ -266,6 +279,7 @@ def main():
     except (ldap.ALREADY_EXISTS, ipalib.errors.DuplicateEntry):
         pass
 
+    cleanup_kdc()
 try:
     if __name__ == "__main__":
         sys.exit(main())
diff --git a/ipapython/sysrestore.py b/ipapython/sysrestore.py
index 8177a1bf2edc4a6014e9114d98c5a7c708a20cab..82817acadce84af0371734db40ef27e74f575a0d 100644
--- a/ipapython/sysrestore.py
+++ b/ipapython/sysrestore.py
@@ -226,6 +226,49 @@ class FileStore:
 
         return len(self.files) > 0
 
+    def untrack_file(self, path):
+        """Remove file at path @path from list of backed up files.
+
+        Does not remove any files from the filesystem.
+
+        Returns #True if the file was untracked, #False if there
+        was no backup file to restore
+        """
+
+        root_logger.debug("Untracking system configuration file '%s'", path)
+
+        if not os.path.isabs(path):
+            raise ValueError("Absolute path required")
+
+        mode = None
+        uid = None
+        gid = None
+        filename = None
+
+        for (key, value) in self.files.items():
+            (mode,uid,gid,filepath) = string.split(value, ',', 3)
+            if (filepath == path):
+                filename = key
+                break
+
+        if not filename:
+            raise ValueError("No such file name in the index")
+
+        backup_path = os.path.join(self._path, filename)
+        if not os.path.exists(backup_path):
+            root_logger.debug("  -> Not restoring - '%s' doesn't exist", backup_path)
+            return False
+
+        try:
+            os.unlink(backup_path)
+        except Exception, e:
+            root_logger.error('Error removing %s: %s' % (backup_path, str(e)))
+
+        del self.files[filename]
+        self.save()
+
+        return True
+
 class StateFile:
     """A metadata file for recording system state which can
     be backed up and later restored. The format is something
-- 
1.7.7.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]