Add cleanup method that locks all user accounts
authorNikos Skalkotos <skalkoto@grnet.gr>
Thu, 5 Apr 2012 14:36:19 +0000 (17:36 +0300)
committerNikos Skalkotos <skalkoto@grnet.gr>
Thu, 5 Apr 2012 14:36:19 +0000 (17:36 +0300)
image_creator/os_type/__init__.py
image_creator/os_type/unix.py

index 03ca4a7..2760903 100644 (file)
@@ -42,10 +42,12 @@ def add_prefix(target):
         return map(lambda x: prefix + x, target(self, *args))
     return wrapper
 
         return map(lambda x: prefix + x, target(self, *args))
     return wrapper
 
+
 def exclude_task(func):
     func.excluded = True
     return func
 
 def exclude_task(func):
     func.excluded = True
     return func
 
+
 class OSBase(object):
     """Basic operating system class"""
     def __init__(self, rootdev, ghandler):
 class OSBase(object):
     """Basic operating system class"""
     def __init__(self, rootdev, ghandler):
index b5d0ba7..01e0987 100644 (file)
@@ -70,6 +70,23 @@ class Unix(OSBase):
 
         return users
 
 
         return users
 
+    def data_cleanup_passwords(self, print_header=True):
+        """Remove all passwords and lock all user accounts"""
+
+        if print_header:
+            output('Cleaning up passwords & locking all user accounts')
+
+        shadow = []
+
+        for line in self.g.cat('/etc/shadow').splitlines():
+            fields = line.split(':')
+            if fields[1] not in ('*', '!'):
+                fields[1] = '!'
+
+            shadow.append(":".join(fields))
+
+        self.g.write('/etc/shadow', "\n".join(shadow))
+
     def data_cleanup_cache(self, print_header=True):
         """Remove all regular files under /var/cache"""
 
     def data_cleanup_cache(self, print_header=True):
         """Remove all regular files under /var/cache"""