summaryrefslogtreecommitdiff
path: root/src/conf_mode
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-02-05 20:54:23 +0100
committerChristian Poessinger <christian@poessinger.com>2020-02-05 20:54:23 +0100
commitf5b95cdda6788b12e41ae13aa6979b988a147723 (patch)
tree9ed3b6b94bf1b307b0417fee603d710eb93e6c59 /src/conf_mode
parent218062a8903864cfb35e298f21c19a7b7a30adb3 (diff)
downloadvyos-1x-f5b95cdda6788b12e41ae13aa6979b988a147723.tar.gz
vyos-1x-f5b95cdda6788b12e41ae13aa6979b988a147723.zip
user: T1948: logout user when he is deleted
Diffstat (limited to 'src/conf_mode')
-rwxr-xr-xsrc/conf_mode/system-login-user.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/conf_mode/system-login-user.py b/src/conf_mode/system-login-user.py
index 73fda1b05..4e41ebd21 100755
--- a/src/conf_mode/system-login-user.py
+++ b/src/conf_mode/system-login-user.py
@@ -20,6 +20,7 @@ import os
from pwd import getpwall, getpwnam
from stat import S_IRUSR, S_IWUSR, S_IRWXU, S_IRGRP, S_IXGRP
from subprocess import Popen, PIPE, STDOUT
+from psutil import users
from vyos.config import Config
from vyos.configdict import list_diff
@@ -207,9 +208,14 @@ def apply(login):
for user in login['del_users']:
try:
- # TODO: check if user is logged in and force logout
+ # Logout user if he is logged in
+ if user in list(set([tmp[0] for tmp in users()])):
+ print('{} is logged in, forcing logout'.format(user))
+ os.system('pkill -HUP -u {}'.format(user))
+
# Remove user account but leave home directory to be safe
- os.system('userdel {}'.format(user))
+ os.system('userdel -r {} 2>/dev/null'.format(user))
+
except Exception as e:
raise ConfigError('Deleting user "{}" raised an exception: {}'.format(user, e))