2019-09-23 06:45:18 -04:00
|
|
|
import os
|
|
|
|
import grp
|
|
|
|
import pwd
|
|
|
|
|
2019-09-20 12:55:13 -04:00
|
|
|
def xmlBool(xmlobj):
|
|
|
|
if isinstance(xmlobj, bool):
|
|
|
|
return (xmlobj)
|
|
|
|
if xmlobj.lower() in ('1', 'true'):
|
|
|
|
return(True)
|
|
|
|
elif xmlobj.lower() in ('0', 'false'):
|
|
|
|
return(False)
|
|
|
|
else:
|
2019-09-23 06:45:18 -04:00
|
|
|
return(None)
|
|
|
|
|
|
|
|
|
|
|
|
def getSudoGroup():
|
|
|
|
is_sudo = False
|
|
|
|
if os.environ.get('SUDO_GID'):
|
|
|
|
gid = int(os.environ['SUDO_GID'])
|
|
|
|
is_sudo = True
|
|
|
|
else:
|
|
|
|
gid = os.getegid()
|
|
|
|
group = grp.getgrgid(gid)
|
|
|
|
return((group, gid, is_sudo))
|
|
|
|
|
|
|
|
|
|
|
|
def getSudoUser():
|
|
|
|
is_sudo = False
|
|
|
|
if os.environ.get('SUDO_UID'):
|
|
|
|
uid = int(os.environ['SUDO_UID'])
|
|
|
|
is_sudo = True
|
|
|
|
else:
|
|
|
|
uid = os.geteuid()
|
|
|
|
user = pwd.getpwuid(os.geteuid())
|
|
|
|
return((user, uid, is_sudo))
|