
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
ôn»j­  ã               @   sR   d dl Z ddlmZmZmZmZ dd„ Zdd„ Zdd	„ Zd
d„ Z	ej
dd„ ƒZdS )é    Né   )ÚerrorsÚ	log_utilsÚprocess_utilsÚutilsc             C   s"   t jj| ƒ\}}t jj|d| ƒS )Nztmp.)ÚosÚpathÚsplitÚjoin)ÚfnameÚheadÚtail© r   ú-/usr/libexec/kcare/python/kcarectl/selinux.pyÚselinux_safe_tmpname
   s    r   c             C   sN   t ƒ rJtjdd
ƒd| g}tj|ddd�\}}}|rJtjdj| ||ƒdd	� d S )NZ
restoreconú	/usr/sbinú/sbinz-RT)Úcatch_stdoutÚcatch_stderrz8SELinux context restoration for {0} failed with {1}: {2}F)Ú	print_msg)r   r   )Úis_selinux_enabledr   Úfind_cmdÚrun_commandr   ÚlogerrorÚformat)ÚdnameÚcmdÚcodeÚ_Ústderrr   r   r   Úrestore_selinux_context   s    r    c             C   sV   t jddgdd�\}}}|r2tjdj||ƒdd�‚x|jdƒD ]}| |kr>dS q>W d	S )
Nz/usr/sbin/semodulez-lT)r   z/SELinux modules list gathering error: '{0}' {1}zselinux modules error)ÚstatusÚ
F)r   r   r   Ú
KcareErrorr   r	   )Zsemodule_namer   ÚoutÚerrÚliner   r   r   Úis_selinux_module_present   s    r'   c                s   ‡ fdd„}|S )Nc                 s$   t ƒ rtdƒ rtjdƒ‚ˆ | |ŽS )NÚlibcarez:SELinux is enabled but libcare policy module is not loaded)r   r'   r   r#   )ÚargsÚkwargs)Úclblr   r   Úwrapper%   s    
z*skip_if_no_selinux_module.<locals>.wrapperr   )r+   r,   r   )r+   r   Úskip_if_no_selinux_module$   s    r-   c              C   s,   t jjdƒr tjdgƒ\} }}ndS | dkS )Nz/usr/sbin/selinuxenabledFr   )r   r   Úisfiler   r   )r   r   r   r   r   r   -   s    r   )r   Ú r   r   r   r   r   r    r'   r-   Úcachedr   r   r   r   r   Ú<module>   s   
	