From 0d88ad9642ccf0b8780c063a3a77cac74dd0ee0d Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 5 Feb 2020 19:32:55 +0100 Subject: user: T1948: fix system user creation --- src/conf_mode/system-login-user.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/conf_mode/system-login-user.py b/src/conf_mode/system-login-user.py index 3317f87d8..a9e194859 100755 --- a/src/conf_mode/system-login-user.py +++ b/src/conf_mode/system-login-user.py @@ -118,6 +118,7 @@ def get_config(): return login def verify(login): + # TODO: should we be able to delete ourself? pass def generate(login): @@ -156,16 +157,16 @@ def apply(login): cmd = "usermod" # encrypted password must be quited in '' else it won't work! - cmd += " -p '{}'".format(user['password_encrypted']) - cmd += " -s /bin/vbash" + cmd += ' -p "{}"'.format(user['password_encrypted']) + cmd += ' -s /bin/vbash' if user['full_name']: - cmd += " -c {}".format(user['full_name']) + cmd += ' -c "{}"'.format(user['full_name']) if user['home_dir']: - cmd += " -d '{}'".format(user['home_dir']) + cmd += ' -d "{}"'.format(user['home_dir']) - cmd += " -G frrvty,vyattacfg,sudo,adm,dip,disk" - cmd += " {}".format(user['name']) + cmd += ' -G frrvty,vyattacfg,sudo,adm,dip,disk' + cmd += ' {}'.format(user['name']) try: os.system(cmd) @@ -197,10 +198,11 @@ def apply(login): os.chmod(key_file, S_IRUSR | S_IWUSR) except Exception as e: - print('Adding user "{}" raised an exception'.format(user)) + print('Adding user "{}" raised an exception: {}'.format(user['name'], e)) for user in login['del_users']: try: + # TODO: check if user is logged in and force logout # Remove user account but leave home directory to be safe os.system('userdel {}'.format(user)) except Exception as e: -- cgit v1.2.3