File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/selinux.cpython-310.pyc
o
�N�gD` � @ s� d Z ddlZddlZddlm mZ ddlZddlZddl Zddl
ZddlmZm
Z
dddddd d
dd�Zd
d� Zejdd� �Zdd� Zdd� Zdd� Zdd� ZdIdd�ZdIdd�Zdd� Zd d!� Zd"d#� Zd$d%� Zd&d'� Zd(d)� Zd*d+� Zd,d-� Zd.d/� Z d0d1� Z!dJd3d4�Z" dKd5d6�Z# dKd7d8�Z$ dKd9d:�Z% dKd;d<�Z&dId=d>�Z'dId?d@�Z(dLdAdB�Z)dKdCdD�Z*dMdEdF�Z+ dKdGdH�Z,dS )Na�
Execute calls on selinux
.. note::
This module requires the ``semanage``, ``setsebool``, and ``semodule``
commands to be available on the minion. On RHEL-based distributions,
ensure that the ``policycoreutils`` and ``policycoreutils-python``
packages are installed. If not on a Fedora or RHEL-based distribution,
consult the selinux documentation for your distribution to ensure that the
proper packages are installed.
� N)�CommandExecutionError�SaltInvocationErrorz all fileszregular file� directoryzcharacter devicezblock device�socketz
symbolic linkz
named pipe)�a�f�d�c�b�s�l�pc C s@ d} | D ]}t jj�|�sd|d f S qtd dkrdS dS )zg
Check if the os is Linux, and then if selinux is running in permissive or
enforcing mode.
)Zsemanage� setseboolZsemoduleFz is not in the pathZkernel�LinuxZselinux)Fz1Module only works on Linux with selinux installed)�salt�utils�path�whichZ
__grains__)Z
required_cmds�cmd� r �H/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/selinux.py�__virtual__# s �r c C sR zdD ]} t j�| �rt j�t j�| d��r| W S qW dS ty( Y dS w )z�
Return the location of the SELinux VFS directory
CLI Example:
.. code-block:: bash
salt '*' selinux.selinux_fs_path
)z/sys/fs/selinuxz/selinux�enforceN)�osr �isdir�isfile�join�AttributeError)r r r r �selinux_fs_path6 s
��r c C s� t � } | du r dS z<tj�| d�}tjj�|d��"}tjj� |�
� ��� dkr1 W d � W dS W d � W dS 1 s>w Y W dS tt
fyQ Y dS w )z�
Return the mode selinux is running in
CLI Example:
.. code-block:: bash
salt '*' selinux.getenforce
N�Disabledr �r�0Z
PermissiveZ Enforcing)r r r r r r �files�fopen�stringutils�
to_unicode�readline�strip�OSErrorr )Z_selinux_fs_pathr �_fpr r r �
getenforceN s
�(��r* c C s� zGd} t jj�| d��2}|D ]%}t jj�|�}|�� �d�r3|�d�d � � �� W d � W S qW d � W dS 1 s@w Y W dS t
tfyS Y dS w )z�
Return the selinux mode from the config file
CLI Example:
.. code-block:: bash
salt '*' selinux.getconfig
�/etc/selinux/configr zSELINUX=�=� N)r r r"