diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-08-14 20:13:31 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-08-14 20:23:14 +0200 |
commit | 4a79ca1b27af3d3c9d333ba428e4c0f3fa62dd3c (patch) | |
tree | 44fd89fb431381f65c9c604eb78c24936455b2f0 /python | |
parent | 2cd7e709c7961bd673be737ad197465aab143137 (diff) | |
download | vyos-1x-4a79ca1b27af3d3c9d333ba428e4c0f3fa62dd3c.tar.gz vyos-1x-4a79ca1b27af3d3c9d333ba428e4c0f3fa62dd3c.zip |
vyos.util: T1503: use build in methods to determine current user for commit_in_progress()
(cherry picked from commit a74e67a778a6c698e44cbc6c5d184d03c9c12396)
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/util.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index 28f0c9bd1..f3451fd77 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -565,12 +565,13 @@ def commit_in_progress(): # Since this will be used in scripts that modify the config outside of the CLI # framework, those knowingly have root permissions. # For everything else, we add a safeguard. - from psutil import process_iter, NoSuchProcess + from psutil import process_iter + from psutil import NoSuchProcess + from getpass import getuser from vyos.defaults import commit_lock - idu = cmd('/usr/bin/id -u') - if idu != '0': - raise OSError("This functions needs root permissions to return correct results") + if getuser() != 'root': + raise OSError('This functions needs to be run as root to return correct results!') for proc in process_iter(): try: |