summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-02-05 20:32:09 +0100
committerChristian Poessinger <christian@poessinger.com>2020-02-05 20:32:09 +0100
commit6ea62706d09ad2908eb0376ade85b73b4bf93c60 (patch)
tree556306b8538413555bdac4d1d815accb9727bd5b /src
parent1244baf36371623b3dadcd5e98ba93a74d8330bc (diff)
downloadvyos-1x-6ea62706d09ad2908eb0376ade85b73b4bf93c60.tar.gz
vyos-1x-6ea62706d09ad2908eb0376ade85b73b4bf93c60.zip
user: T1948: one can not delete his own user account
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/system-login-user.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/conf_mode/system-login-user.py b/src/conf_mode/system-login-user.py
index a9e194859..c7ed96dcf 100755
--- a/src/conf_mode/system-login-user.py
+++ b/src/conf_mode/system-login-user.py
@@ -56,9 +56,11 @@ def get_config():
conf = Config()
base_level = ['system', 'login', 'user']
- if not conf.exists(base_level):
- login['deleted'] = True
- return login
+ # We do not need to check if the nodes exist or not and bail out early
+ # ... this would interrupt the following logic on determine which users
+ # should be deleted and which users should stay.
+ #
+ # All fine so far!
# Read in all local users and store to list
for username in conf.list_nodes(base_level):
@@ -115,13 +117,6 @@ def get_config():
login['add_users'].append(user)
- return login
-
-def verify(login):
- # TODO: should we be able to delete ourself?
- pass
-
-def generate(login):
# users no longer existing in the running configuration need to be deleted
local_users = get_local_users()
cli_users = [tmp['name'] for tmp in login['add_users']]
@@ -133,6 +128,16 @@ def generate(login):
# system is rebooted.
login['del_users'] = [tmp for tmp in all_users if tmp not in cli_users]
+ return login
+
+def verify(login):
+ cur_user = os.environ['SUDO_USER']
+ if cur_user in login['del_users']:
+ raise ConfigError('Attempting to delete current user: {}'.format(cur_user))
+
+ pass
+
+def generate(login):
# calculate users encrypted password
for user in login['add_users']:
if user['password_plaintext']: