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
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
def command_exists(activeroot, c): """ Check if a given command exists """ if 'linux' in get_system_type_from_active_root(activeroot): # get path to the command com = command('which %s' % (c)) return len(com) > 0 else: log.warn('Cannot determine \'%s\' existence.' % c) return False
def command_exists(activeroot, c): """ Check if a given command exists """ if 'linux' in get_system_type_from_active_root(activeroot): # get path to the command com = command('which %s' % (c)) return len(com) > 0 # TODO more system types else: log.warn('Cannot determine \'%s\' existence.' % c) return False