def fcontext_get_policy(name, filetype=None, sel_type=None, sel_user=None, sel_level=None):
 if filetype:
  _validate_filetype(filetype)
 re_spacer = '[ ]{2,}'
 cmd_kwargs = {'spacer': re_spacer, 'filespec': re.escape(name), 'sel_user': (sel_user or '[^:]+'), 'sel_role': '[^:]+', 'sel_type': (sel_type or '[^:]+'), 'sel_level': (sel_level or '[^:]+')}
 cmd_kwargs['filetype'] = ('[[:alpha:] ]+' if (filetype is None) else filetype_id_to_string(filetype))
 cmd = ('semanage fcontext -l | egrep ' + "'^{filespec}{spacer}{filetype}{spacer}{sel_user}:{sel_role}:{sel_type}:{sel_level}$'".format(**cmd_kwargs))
 current_entry_text = __salt__['cmd.shell'](cmd)
 if (current_entry_text == ''):
  return None
 ret = {}
 current_entry_list = re.split(re_spacer, current_entry_text)
 ret['filespec'] = current_entry_list[0]
 ret['filetype'] = current_entry_list[1]
 ret.update(_context_string_to_dict(current_entry_list[2]))
 return ret

def fcontext_get_policy ( name , filetype = None , sel_type = None , sel_user = None , sel_level = None ) : if filetype : _validate_filetype ( filetype ) re_spacer = '[ ]{2,}' cmd_kwargs = { 'spacer' : re_spacer , 'filespec' : re . escape ( name ) , 'sel_user' : ( sel_user or '[^:]+' ) , 'sel_role' : '[^:]+' , 'sel_type' : ( sel_type or '[^:]+' ) , 'sel_level' : ( sel_level or '[^:]+' ) } cmd_kwargs [ 'filetype' ] = ( '[[:alpha:] ]+' if ( filetype is None ) else filetype_id_to_string ( filetype ) ) cmd = ( 'semanage fcontext -l | egrep ' + "'^{filespec}{spacer}{filetype}{spacer}{sel_user}:{sel_role}:{sel_type}:{sel_level}$'" . format ( ** cmd_kwargs ) ) current_entry_text = __salt__ [ 'cmd.shell' ] ( cmd ) if ( current_entry_text == '' ) : return None ret = { } current_entry_list = re . split ( re_spacer , current_entry_text ) ret [ 'filespec' ] = current_entry_list [ 0 ] ret [ 'filetype' ] = current_entry_list [ 1 ] ret . update ( _context_string_to_dict ( current_entry_list [ 2 ] ) ) return ret
returns the current entry in the selinux policy list as a dictionary .