-#!/usr/bin/env python
+# Copyright 2012 GRNET S.A. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or
+# without modification, are permitted provided that the following
+# conditions are met:
+#
+# 1. Redistributions of source code must retain the above
+# copyright notice, this list of conditions and the following
+# disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following
+# disclaimer in the documentation and/or other materials
+# provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
+# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+# The views and conclusions contained in the software and
+# documentation are those of the authors and should not be
+# interpreted as representing official policies, either expressed
+# or implied, of GRNET S.A.
import re
import sys
from image_creator.os_type import OSBase
+from image_creator.util import warn
+from clint.textui import puts
class Unix(OSBase):
- sensitive_userdata = ['.bash_history']
+ sensitive_userdata = [
+ '.bash_history',
+ '.gnupg',
+ '.ssh',
+ '.mozilla',
+ '.thunderbird'
+ ]
def get_metadata(self):
meta = super(Unix, self).get_metadata()
user, passwd = match.groups()
if len(passwd) > 0 and passwd[0] == '!':
- print "Warning: Ignoring locked %s account." % user
+ warn("Ignoring locked %s account." % user)
else:
users.append(user)
return users
- def data_cleanup(self):
- self.cleanup_userdata()
- self.cleanup_tmp()
- self.cleanup_log()
- self.cleanup_mail()
- self.cleanup_cache()
+ def data_cleanup_cache(self):
+ """Remove all regular files under /var/cache"""
+
+ puts('* Removing files under /var/cache')
- def cleanup_cache(self):
self.foreach_file('/var/cache', self.g.rm, ftype='r')
- def cleanup_tmp(self):
+ def data_cleanup_tmp(self):
+ """Remove all files under /tmp and /var/tmp"""
+
+ puts('* Removing files under /tmp and /var/tmp')
+
self.foreach_file('/tmp', self.g.rm_rf, maxdepth=1)
self.foreach_file('/var/tmp', self.g.rm_rf, maxdepth=1)
- def cleanup_log(self):
+ def data_cleanup_log(self):
+ """Empty all files under /var/log"""
+
+ puts('* Emptying all files under /var/log')
+
self.foreach_file('/var/log', self.g.truncate, ftype='r')
- def cleanup_mail(self):
- self.foreach_file('var/spool/mail', self.g.rm_rf, maxdepth=1)
- self.foreach_file('var/mail', self.g.rm_rf, maxdepth=1)
+ def data_cleanup_mail(self):
+ """Remove all files under /var/mail and /var/spool/mail"""
+
+ puts('* Removing files under /var/mail and /var/spool/mail')
+
+ self.foreach_file('/var/spool/mail', self.g.rm_rf, maxdepth=1)
+ self.foreach_file('/var/mail', self.g.rm_rf, maxdepth=1)
+
+ def data_cleanup_userdata(self):
+ """Delete sensitive userdata"""
- def cleanup_userdata(self):
homedirs = ['/root'] + self.ls('/home/')
for homedir in homedirs:
+ puts('* Removing sensitive user data under %s' % homedir)
for data in self.sensitive_userdata:
fname = "%s/%s" % (homedir, data)
if self.g.is_file(fname):