6 from image_creator.os_type import OSBase
11 sensitive_userdata = ['.bash_history']
13 def get_metadata(self):
14 meta = super(Unix, self).get_metadata()
15 meta["USERS"] = " ".join(self.get_passworded_users())
18 def get_passworded_users(self):
20 regexp = re.compile('(\S+):((?:!\S+)|(?:[^!*]\S+)|):(?:\S*:){6}')
22 for line in self.g.cat('/etc/shadow').splitlines():
23 match = regexp.match(line)
27 user, passwd = match.groups()
28 if len(passwd) > 0 and passwd[0] == '!':
29 print "Warning: Ignoring locked %s account." % user
35 def data_cleanup(self):
36 self.cleanup_userdata()
42 def cleanup_cache(self):
43 self.foreach_file('/var/cache', self.g.rm, ftype='r')
45 def cleanup_tmp(self):
46 self.foreach_file('/tmp', self.g.rm_rf, maxdepth=1)
47 self.foreach_file('/var/tmp', self.g.rm_rf, maxdepth=1)
49 def cleanup_log(self):
50 self.foreach_file('/var/log', self.g.truncate, ftype='r')
52 def cleanup_mail(self):
53 self.foreach_file('var/spool/mail', self.g.rm_rf, maxdepth=1)
54 self.foreach_file('var/mail', self.g.rm_rf, maxdepth=1)
56 def cleanup_userdata(self):
57 homedirs = ['/root'] + self.ls('/home/')
59 for homedir in homedirs:
60 for data in self.sensitive_userdata:
61 fname = "%s/%s" % (homedir, data)
62 if self.g.is_file(fname):
63 self.g.scrub_file(fname)
65 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :