def is_admin(user=lib.global_parameters['USER'], activeroot='/'):
""" Check if the specified user has administrative privileges on given system"""
platform = get_system_type_from_active_root(activeroot)
ip = get_address_from_active_root(activeroot)
if activeroot.startswith('/'):
if platform.startswith('linux'):
# on linux check if euid is 0
from pwd import getpwnam
if getpwnam(user).pw_uid == 0:
return True
return False
elif platform.startswith('win'):
from win32net import NetUserGetLocalGroups
return 'Administrators' in NetUserGetLocalGroups(ip, user) # should work on remote systems too
# on Windows only admins can write to C:\Windows\temp
#if os.access(os.path.join(os.environ.get('SystemRoot', 'C:\\Windows'), 'temp'), os.W_OK):
# return True
#return False
else:
log.warn('Cannot check root privileges, platform is not fully supported (%s).' % platform)
return False
else:
log.warn('Cannot check root privileges, remote system analysis (%s) not supported yet.' % activeroot)
return False
评论列表
文章目录