From e129347af6f9d011ec3315e7510480a17e84db22 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Sun, 21 Jan 2018 19:09:06 +0000 Subject: [PATCH] Add an option to enable root accounts after filesystem creation This is a minor hack. The code should be rearranged to allow a more natural workflow to modify filesystems post-creation. --- tools/onlrfs.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tools/onlrfs.py b/tools/onlrfs.py index d08401aa..be2e198f 100755 --- a/tools/onlrfs.py +++ b/tools/onlrfs.py @@ -109,10 +109,10 @@ class OnlRfsSystemAdmin(object): def useradd(self, username, uid=None, gid=None, password=None, shell='/bin/bash', home=None, groups=None, sudo=False, deleteFirst=True): args = [ 'useradd', '--create-home' ] - if uid: + if uid is not None: args = args + [ '--non-unique', '--uid', str(uid) ] - if gid: + if gid is not None: args = args + [ '--gid', str(gid) ] if password: @@ -574,9 +574,30 @@ if __name__ == '__main__': ap.add_argument("--no-multistrap", action='store_true') ap.add_argument("--cpio") ap.add_argument("--squash") - + ap.add_argument("--enable-root") ops = ap.parse_args() + if ops.enable_root: + # + # Fixme -- this should all be rearranged to naturally support + # arbitrary filesystem modifications. + # + sa = OnlRfsSystemAdmin(ops.dir) + sa.user_password_set('root', ops.enable_root) + config = os.path.join(ops.dir, 'etc/ssh/sshd_config') + sa.chmod('a+rw', config) + lines = open(config).readlines() + with open(config, "w") as f: + for line in lines: + if line.startswith('PermitRootLogin'): + v = "Yes" + logger.info("Setting PermitRootLogin to %s" % v) + f.write('PermitRootLogin %s\n' % v) + else: + f.write(line) + sa.chmod('644', config) + sys.exit(0) + try: x = OnlRfsBuilder(ops.config, ops.arch)