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()
41 def cleanup_tmp(self):
42 self.foreach_file('/tmp', self.g.rm_rf, maxdepth=1)
43 self.foreach_file('/var/tmp', self.g.rm_rf, maxdepth=1)
45 def cleanup_log(self):
46 self.foreach_file('/var/log', self.g.truncate, ftype='r')
48 def cleanup_mail(self):
49 self.foreach_file('var/spool/mail', self.g.rm_rf, maxdepth=1)
50 self.foreach_file('var/mail', self.g.rm_rf, maxdepth=1)
52 def cleanup_userdata(self):
53 homedirs = ['/root'] + self.ls('/home/')
55 for homedir in homedirs:
56 for data in self.sensitive_userdata:
57 fname = "%s/%s" % (homedir, data)
58 if self.g.is_file(fname):
59 self.g.scrub_file(fname)
61 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :