summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-06-15 08:44:10 +0200
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2024-06-24 14:08:27 +0000
commit6baee9809a0626f9f555060cfb7b173388377deb (patch)
tree55347ea6407791ce5bbaa61160505167466ab5e6 /python
parentfad0128567931fd32e568896a0ba789396ab9311 (diff)
downloadvyos-1x-6baee9809a0626f9f555060cfb7b173388377deb.tar.gz
vyos-1x-6baee9809a0626f9f555060cfb7b173388377deb.zip
T6489: add abstraction vyos.utils.auth.get_current_user()
(cherry picked from commit e1a34e661d3e5f0090550796ac266dac15e1e337)
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/auth.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/python/vyos/utils/auth.py b/python/vyos/utils/auth.py
index a59858d72..d014f756f 100644
--- a/python/vyos/utils/auth.py
+++ b/python/vyos/utils/auth.py
@@ -1,6 +1,6 @@
# authutils -- miscelanneous functions for handling passwords and publis keys
#
-# Copyright (C) 2018 VyOS maintainers and contributors
+# Copyright (C) 2023-2024 VyOS maintainers and contributors
#
# This library is free software; you can redistribute it and/or modify it under the terms of
# the GNU Lesser General Public License as published by the Free Software Foundation;
@@ -11,13 +11,12 @@
# See the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along with this library;
-# if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import re
from vyos.utils.process import cmd
-
def make_password_hash(password):
""" Makes a password hash for /etc/shadow using mkpasswd """
@@ -39,3 +38,10 @@ def split_ssh_public_key(key_string, defaultname=""):
raise ValueError("Bad key type \'{0}\', must be one of must be one of ssh-rsa, ssh-dss, ecdsa-sha2-nistp<256|384|521> or ssh-ed25519".format(key_type))
return({"type": key_type, "data": key_data, "name": key_name})
+
+def get_current_user() -> str:
+ import os
+ current_user = 'nobody'
+ if 'SUDO_USER' in os.environ:
+ current_user = os.environ['SUDO_USER']
+ return current_user