MOON
Server: Apache
System: Linux s5.yayogua.com.py 6.12.0-124.55.3.el10_1.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:54:02 EDT 2026 x86_64
User: sanbercountryclu (1012)
PHP: 8.2.33
Disabled: NONE
Upload Files
File: //lib/python3.12/site-packages/sepolgen/__pycache__/module.cpython-312.pyc
�

�jt���dZddlZddlZ	ddlmZddlZddlZddl	Z	ddl
Z
ddlmZd�Z
Gd�d�Zd	�ZGd
�d�Zy#e$r	ddlmZY�>wxYw)zU
Utilities for dealing with the compilation of modules and creation
of module tress.
�N)�getstatusoutput�)�defaultsc�t�tjd|�}t|�dk(r|dj�ryy)z'Check that a module name is valid.
    z[^a-zA-Z0-9_\-\.]rTF)�re�findall�len�isalpha)�modname�ms  �4/usr/lib/python3.12/site-packages/sepolgen/module.py�
is_valid_namer(s5��	�
�
�'��1�A�
�1�v��{�w�q�z�)�)�+���c�>�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d
d	�Z
y)�
ModuleTreec� �||_d|_y�N)r�dirname)�selfrs  r
�__init__zModuleTree.__init__2s�������rc��|jSr�r�rs r
�dir_namezModuleTree.dir_name6s���|�|�rc�@�|jdz|jzdzS)N�/z.te�rrrs r
�te_namezModuleTree.te_name9����|�|�c�!�D�L�L�0�5�8�8rc�@�|jdz|jzdzS)Nrz.fcrrs r
�fc_namezModuleTree.fc_name<rrc�@�|jdz|jzdzS)Nrz.ifrrs r
�if_namezModuleTree.if_name?rrc�@�|jdz|jzdzS)Nr�.pprrs r
�package_namezModuleTree.package_nameBrrc� �|jdzS)Nz	/Makefilerrs r
�
makefile_namezModuleTree.makefile_nameEs���|�|�k�)�)rNc�.�|dz|jz|_tj|j�t	|j�d�}|r|j
d|z�n&|j
dtj�z�|j�t	|j�d�j�t	|j�d�j�t	|j�d�j�y)Nr�wzinclude )
rr�os�mkdir�openr(�writer�refpolicy_makefile�closerr!r#)r�parent_dirname�makefile_include�fds    r
�createzModuleTree.createHs���%��+�d�l�l�:���
�������
�$�$�$�&��
,����H�H�Z�"2�2�3��H�H�Z�(�"=�"=�"?�?�@�
���
�	
�T�\�\�^�S�!�'�'�)��T�\�\�^�S�!�'�'�)��T�\�\�^�S�!�'�'�)rr)�__name__�
__module__�__qualname__rrrr!r#r&r(r4�rr
rr1s*����9�9�9�9�*�*rrc��tjjtjj|�d�dS)Nrr)r+�path�splitext�split)�
sourcenames r
�modname_from_sourcenamer>Xs.��
�7�7���B�G�G�M�M�*�5�a�8�9�!�<�<rc�D�eZdZdZdd�Zd�Zd�Zd�Zdd�Zd�Z	d	�Z
d
�Zy)
�ModuleCompileraqModuleCompiler eases running of the module compiler.

    The ModuleCompiler class encapsulates running the commandline
    module compiler (checkmodule) and module packager (semodule_package).
    You are likely interested in the create_module_package method.
    
    Several options are controlled via parameters (only effects the
    non-refpol builds):
    
     .mls          [boolean] Generate an MLS module (by passed -M to
                   checkmodule). True to generate an MLS module, false
                   otherwise.
                   
     .module       [boolean] Generate a module instead of a base module.
                   True to generate a module, false to generate a base.
                   
     .checkmodule  [string] Fully qualified path to the module compiler.
                   Default is /usr/bin/checkmodule.
                   
     .semodule_package [string] Fully qualified path to the module
                   packager. Defaults to /usr/bin/semodule_package.
     .output       [file object] File object used to write verbose
                   output of the compilation and packaging process.
    Nc��tj�|_d|_d|_d|_||_d|_tj�|_
d|_y)z�Create a ModuleCompiler instance, optionally with an
        output file object for verbose output of the compilation process.
        Tz/usr/bin/checkmodulez/usr/bin/semodule_package�z
/usr/bin/makeN)�selinux�is_selinux_mls_enabled�mls�module�checkmodule�semodule_package�output�last_outputrr/�refpol_makefile�make)rrIs  r
rzModuleCompiler.__init__tsR���1�1�3������1��� ;���������'�:�:�<���#��	rc�f�|jr|jj|dz�||_y)N�
)rIr.rJ)r�strs  r
�ozModuleCompiler.o�s'���;�;��K�K���c�D�j�)���rc�f�|j|�t|�\}}|j|�|Sr)rPr)r�command�rcrIs    r
�runzModuleCompiler.run�s+�����w��$�W�-�
��F����v���	rc��|jd�}t|�dkrtd|��dj|dd�}|dz}|dz}||fS)z�Generate the module and policy package filenames from
        a source file name. The source file must be in the form
        of "foo.te". This will generate "foo.mod" and "foo.pp".
        
        Returns a tuple with (modname, policypackage).
        �.�z,invalid sourcefile name %s (must end in .te)r���z.modr%)r<r	�RuntimeError�join)rr=�	splitname�basenamer�packagenames      r
�
gen_filenameszModuleCompiler.gen_filenames�sa���$�$�S�)�	��y�>�A���M�z�Z�Z��8�8�I�a��O�,���V�#����&����%�%rc���|r|j|�y|j|�\}}|j||�|j||�t	j
|�y)a�Create a module package saved in a packagename from a
        sourcename.

        The create_module_package creates a module package saved in a
        file named sourcename (.pp is the standard extension) from a
        source file (.te is the standard extension). The source file
        should contain SELinux policy statements appropriate for a
        base or non-base module (depending on the setting of .module).

        Only file names are accepted, not open file objects or
        descriptors because the command line SELinux tools are used.

        On error a RuntimeError will be raised with a descriptive
        error message.
        N)�refpol_buildr^�compile�packager+�unlink)rr=�	refpolicyrr]s     r
�create_module_packagez$ModuleCompiler.create_module_package�sR�� ����j�)�#'�#5�#5�j�#A� �G�[��L�L��W�-��L�L��+�.��I�I�g�rc��|jdz|jz}|j|�}|dk7rtd|jz��y)Nz -f r�compilation failed:
%s)rLrKrTrYrJ)rr=rRrSs    r
r`zModuleCompiler.refpol_build�sN���)�)�f�$�t�';�';�;��
�X�X�g�
����7��8�4�;K�;K�K�L�L�rc�r�|jg}|jr|jd�|jr|jd�|jd�|j|�|j|�|j	dj|��}|dk7rt
d|jz��y)Nz-M�-m�-o� rrg)rGrE�appendrFrTrZrYrJ)rr=r�srSs     r
razModuleCompiler.compile�s���
�
�
����8�8�
�H�H�T�N��;�;�
�H�H�T�N�	�����	�����	�����
�X�X�c�h�h�q�k�
"��
��7��8�4�;K�;K�K�L�L�rc� �|jg}|jd�|j|�|jd�|j|�|jdj|��}|dk7rt	d|j
z��y)Nrjrirkrzpackaging failed [%s])rHrlrTrZrYrJ)rrr]rmrSs     r
rbzModuleCompiler.package�sw��
�
"�
"�#��	�����	�����	�����	�����
�X�X�c�h�h�q�k�
"��
��7��6��9I�9I�I�J�J�rr)T)r5r6r7�__doc__rrPrTr^rer`rarbr8rr
r@r@[s2���0$��
�&�"�0M�M�	Krr@)ror�tempfile�
subprocessr�ImportError�commandsr+�os.path�shutilrCrBrrrr>r@r8rr
�<module>rvsc��(�

��)�*�
��
����%*�%*�N=�{K�{K��}�)�(�)�s�A�A�A