-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanagement.py
executable file
·58 lines (45 loc) · 1.51 KB
/
management.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Function to load lucent configuration.
def loadConf(yamlFile):
import yaml_interop as yi # For importing yaml files.
#import jsonschema # For testing sytax. TODO: implement.
# Load the configuration.
config = yi.loadDictianories("./conf/config.yaml")[0]
# Handle includes.
for includeFile in config["include"]:
config = config | yi.loadDictianories(includeFile)[0]
# Return the complete config.
return config
# Curtosy of: https://unix.stackexchange.com/questions/11470/how-to-get-the
# -name-of-the-user-that-launched-sudo
def getSudoingUser():
import os
import getpass
import pwd
# This is the generic method. First thing to try.
try:
return os.getlogin()
except OSError:
# failed in some ubuntu installations and in systemd services
pass
# If the above method fails try to obtain the environmental
# variable.
try:
user = os.environ['USER']
except KeyError:
# possibly a systemd service. no sudo was used
return getpass.getuser()
# This should only happend, if sudo was called without -u.
# Don't allow this in /etc/sudoers.
if user == 'root':
try:
return os.environ['SUDO_USER']
except KeyError:
# no sudo was used
pass
try:
pkexec_uid = int(os.environ['PKEXEC_UID'])
return pwd.getpwuid(pkexec_uid).pw_name
except KeyError:
# no pkexec was used
pass
return user