def fcontext_apply_policy(name, recursive=False):
 ret = {}
 changes_text = fcontext_policy_is_applied(name, recursive)
 cmd = 'restorecon -v -F '
 if recursive:
  cmd += '-R '
 cmd += re.escape(name)
 apply_ret = __salt__['cmd.run_all'](cmd)
 ret.update(apply_ret)
 if (apply_ret['retcode'] == 0):
  changes_list = re.findall('restorecon reset (.*) context (.*)->(.*)$', changes_text, re.M)
  if (len(changes_list) > 0):
   ret.update({'changes': {}})
  for item in changes_list:
   filespec = item[0]
   old = _context_string_to_dict(item[1])
   new = _context_string_to_dict(item[2])
   intersect = {}
   for (key, value) in old.iteritems():
    if (new.get(key) == value):
     intersect.update({key: value})
   for key in intersect.keys():
    del old[key]
    del new[key]
   ret['changes'].update({filespec: {'old': old, 'new': new}})
 return ret

def fcontext_apply_policy ( name , recursive = False ) : ret = { } changes_text = fcontext_policy_is_applied ( name , recursive ) cmd = 'restorecon -v -F ' if recursive : cmd += '-R ' cmd += re . escape ( name ) apply_ret = __salt__ [ 'cmd.run_all' ] ( cmd ) ret . update ( apply_ret ) if ( apply_ret [ 'retcode' ] == 0 ) : changes_list = re . findall ( 'restorecon reset (.*) context (.*)->(.*)$' , changes_text , re . M ) if ( len ( changes_list ) > 0 ) : ret . update ( { 'changes' : { } } ) for item in changes_list : filespec = item [ 0 ] old = _context_string_to_dict ( item [ 1 ] ) new = _context_string_to_dict ( item [ 2 ] ) intersect = { } for ( key , value ) in old . iteritems ( ) : if ( new . get ( key ) == value ) : intersect . update ( { key : value } ) for key in intersect . keys ( ) : del old [ key ] del new [ key ] ret [ 'changes' ] . update ( { filespec : { 'old' : old , 'new' : new } } ) return ret
applies selinux policies to filespec using restorecon [-r] filespec .