X-Git-Url: https://code.grnet.gr/git/snf-image-creator/blobdiff_plain/aa2062ba36d87b174fcea2a5daf6b987cdc9b61b..8c574358704d999eaea8c53e6f327b15dae8ad95:/image_creator/os_type/unix.py diff --git a/image_creator/os_type/unix.py b/image_creator/os_type/unix.py index ad65c15..2aacd8a 100644 --- a/image_creator/os_type/unix.py +++ b/image_creator/os_type/unix.py @@ -1,19 +1,22 @@ #!/usr/bin/env python import re +import sys from image_creator.os_type import OSBase + class Unix(OSBase): + + sensitive_userdata = ['.bash_history'] + def get_metadata(self): meta = super(Unix, self).get_metadata() meta["USERS"] = " ".join(self.get_passworded_users()) return meta def get_passworded_users(self): - users = [] - regexp = re.compile('(\S+):((?:!\S+)|(?:[^!*]\S+)|):(?:\S*:){6}') for line in open('/etc/shadow', 'r').readlines(): @@ -29,9 +32,24 @@ class Unix(OSBase): return users - def cleanup_sensitive_data(self): - cleanup_userdata() - cleanup_tmp() - cleanup_log() + def data_cleanup(self): + self.cleanup_userdata() + self.cleanup_tmp() + self.cleanup_log() + + def cleanup_tmp(self): + self.foreach_file('/tmp', self.g.rm_rf, maxdepth=1) + + def cleanup_log(self): + self.foreach_file('/var/log', self.g.truncate, ftype='r') + + def cleanup_userdata(self): + homedirs = ['/root'] + self.ls('/home/') + + for homedir in homedirs: + for data in self.sensitive_userdata: + fname = "%s/%s" % (homedir, data) + if self.g.is_file(fname): + self.g.scrub_file(fname) # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :