From: Nikos Skalkotos Date: Wed, 22 May 2013 11:12:38 +0000 (+0300) Subject: Add cleanup_password sysprep for freebsd X-Git-Tag: v0.3~6 X-Git-Url: https://code.grnet.gr/git/snf-image-creator/commitdiff_plain/e56edd2922a1378ff112836d60abd227cb8b8b58 Add cleanup_password sysprep for freebsd --- diff --git a/image_creator/os_type/freebsd.py b/image_creator/os_type/freebsd.py index a9f8fa8..d0ed78b 100644 --- a/image_creator/os_type/freebsd.py +++ b/image_creator/os_type/freebsd.py @@ -31,7 +31,7 @@ # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. -from image_creator.os_type.unix import Unix +from image_creator.os_type.unix import Unix, sysprep import re @@ -72,4 +72,32 @@ class Freebsd(Unix): return users + @sysprep() + def cleanup_password(self, print_header=True): + """Remove all passwords and lock all user accounts""" + + if print_header: + self.out.output("Cleaning up passwords & locking all user " + "accounts") + + master_passwd = [] + + for line in self.g.cat('/etc/master.passwd').splitlines(): + + # Check for empty or comment lines + if len(line.split('#')[0]) == 0: + master_passwd.append(line) + continue + + fields = line.split(':') + if fields[1] not in ('*', '!'): + fields[1] = '!' + + master_passwd.append(":".join(fields)) + + self.g.write('/etc/master.passwd', "\n".join(master_passwd) + '\n') + + # Make sure no one can login on the system + self.g.rm_rf('/etc/spwd.db') + # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :