Revision 22a6d232 image_creator/os_type/unix.py
b/image_creator/os_type/unix.py | ||
---|---|---|
35 | 35 |
import sys |
36 | 36 |
|
37 | 37 |
from image_creator.os_type import OSBase |
38 |
from image_creator.util import warn |
|
39 |
from clint.textui import puts |
|
38 | 40 |
|
39 | 41 |
|
40 | 42 |
class Unix(OSBase): |
... | ... | |
63 | 65 |
|
64 | 66 |
user, passwd = match.groups() |
65 | 67 |
if len(passwd) > 0 and passwd[0] == '!': |
66 |
print "Warning: Ignoring locked %s account." % user
|
|
68 |
warn("Ignoring locked %s account." % user)
|
|
67 | 69 |
else: |
68 | 70 |
users.append(user) |
69 | 71 |
|
70 | 72 |
return users |
71 | 73 |
|
72 |
def data_cleanup(self): |
|
73 |
self.data_cleanup_userdata() |
|
74 |
self.data_cleanup_tmp() |
|
75 |
self.data_cleanup_log() |
|
76 |
self.data_cleanup_mail() |
|
77 |
self.data_cleanup_cache() |
|
78 |
|
|
79 | 74 |
def data_cleanup_cache(self): |
80 | 75 |
"""Remove all regular files under /var/cache""" |
76 |
|
|
77 |
puts('* Removing files under /var/cache') |
|
78 |
|
|
81 | 79 |
self.foreach_file('/var/cache', self.g.rm, ftype='r') |
82 | 80 |
|
83 | 81 |
def data_cleanup_tmp(self): |
84 | 82 |
"""Remove all files under /tmp and /var/tmp""" |
83 |
|
|
84 |
puts('* Removing files under /tmp and /var/tmp') |
|
85 |
|
|
85 | 86 |
self.foreach_file('/tmp', self.g.rm_rf, maxdepth=1) |
86 | 87 |
self.foreach_file('/var/tmp', self.g.rm_rf, maxdepth=1) |
87 | 88 |
|
88 | 89 |
def data_cleanup_log(self): |
89 | 90 |
"""Empty all files under /var/log""" |
91 |
|
|
92 |
puts('* Emptying all files under /var/log') |
|
93 |
|
|
90 | 94 |
self.foreach_file('/var/log', self.g.truncate, ftype='r') |
91 | 95 |
|
92 | 96 |
def data_cleanup_mail(self): |
93 | 97 |
"""Remove all files under /var/mail and /var/spool/mail""" |
98 |
|
|
99 |
puts('* Removing files under /var/mail and /var/spool/mail') |
|
100 |
|
|
94 | 101 |
self.foreach_file('/var/spool/mail', self.g.rm_rf, maxdepth=1) |
95 | 102 |
self.foreach_file('/var/mail', self.g.rm_rf, maxdepth=1) |
96 | 103 |
|
97 | 104 |
def data_cleanup_userdata(self): |
98 | 105 |
"""Delete sensitive userdata""" |
106 |
|
|
99 | 107 |
homedirs = ['/root'] + self.ls('/home/') |
100 | 108 |
|
101 | 109 |
for homedir in homedirs: |
110 |
puts('* Removing sensitive user data under %s' % homedir) |
|
102 | 111 |
for data in self.sensitive_userdata: |
103 | 112 |
fname = "%s/%s" % (homedir, data) |
104 | 113 |
if self.g.is_file(fname): |
Also available in: Unified diff