Bump version to 0.2.2
[snf-image-creator] / image_creator / os_type / unix.py
index 06eccbf..2cd8452 100644 (file)
@@ -43,14 +43,18 @@ class Unix(OSBase):
         '.bash_history',
         '.gnupg',
         '.ssh',
-        '.mozilla',
-        '.thunderbird'
+        '.kamakirc',
+        '.kamaki.history'
     ]
 
     def __init__(self, rootdev, ghandler, output):
         super(Unix, self).__init__(rootdev, ghandler, output)
 
         self.meta["USERS"] = " ".join(self._get_passworded_users())
+        # Delete the USERS metadata if empty
+        if not len(self.meta['USERS']):
+            self.out.warn("No passworded users found!")
+            del self.meta['USERS']
 
     def _get_passworded_users(self):
         users = []
@@ -63,7 +67,7 @@ class Unix(OSBase):
 
             user, passwd = match.groups()
             if len(passwd) > 0 and passwd[0] == '!':
-                warn("Ignoring locked %s account." % user)
+                self.out.warn("Ignoring locked %s account." % user)
             else:
                 users.append(user)
 
@@ -74,8 +78,11 @@ class Unix(OSBase):
         """Remove all user accounts with id greater than 1000"""
 
         if print_header:
-            self.out.output(
-                    'Removing all user accounts with id greater than 1000')
+            self.out.output("Removing all user accounts with id greater than "
+                            "1000")
+
+        if 'USERS' not in self.meta:
+            return
 
         # Remove users from /etc/passwd
         passwd = []
@@ -92,6 +99,11 @@ class Unix(OSBase):
                 passwd.append(':'.join(fields))
 
         self.meta['USERS'] = " ".join(metadata_users)
+
+        # Delete the USERS metadata if empty
+        if not len(self.meta['USERS']):
+            del self.meta['USERS']
+
         self.g.write('/etc/passwd', '\n'.join(passwd) + '\n')
 
         # Remove the corresponding /etc/shadow entries
@@ -123,8 +135,8 @@ class Unix(OSBase):
         """Remove all passwords and lock all user accounts"""
 
         if print_header:
-            self.out.output(
-                    'Cleaning up passwords & locking all user accounts')
+            self.out.output("Cleaning up passwords & locking all user "
+                            "accounts")
 
         shadow = []
 
@@ -182,13 +194,15 @@ class Unix(OSBase):
         homedirs = ['/root'] + self.ls('/home/')
 
         if print_header:
-            self.out.output('Removing sensitive user data under %s' % " ".
-                                                        join(homedirs))
+            self.out.output("Removing sensitive user data under %s" %
+                            " ".join(homedirs))
 
         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)
+                elif self.g.is_dir(fname):
+                    self.foreach_file(fname, self.g.scrub_file, ftype='r')
 
 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :