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
This commit is contained in:
Rob Crittenden
2012-02-22 16:40:29 -05:00
committed by Martin Kosek
parent 5c7cd8ee2f
commit de9a22b3f3
2 changed files with 57 additions and 0 deletions

View File

@@ -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())

View File

@@ -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