????

Your IP : 3.14.141.163


Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/__pycache__/clcagefs.cpython-311.pyc

�

�j�e�'����ddlmZddlmZddlmZddlZddlZddlZddlZdZdZ	Gd�de
��ZGd	�d
e
��ZGd�d��Z
d
�Zdd�Zdd�Z		dd�Zd�Zd�Zd�Zdd�Zd�Zd�ZdS)�)�print_function)�absolute_import)�divisionNz/etc/cagefs/cagefs.mpz/usr/sbin/cagefsctlc��eZdZd�Zd�ZdS)�CagefsMpConflictc�2�d|�dt�d|�d�|_dS)NzConflict in adding 'z' to z5 because of pre-existing alternative specification: '�')�CAGEFS_MP_FILENAME�_msg)�self�new_item�
existing_items   ��/builddir/build/BUILDROOT/alt-python27-cllib-3.3.15-1.el8.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/clcagefs.py�__init__zCagefsMpConflict.__init__s*����X�X�1�1�1�=�=�=�B��	�	�	�c��|jS�N)r�rs r�__str__zCagefsMpConflict.__str__s
���y�rN)�__name__�
__module__�__qualname__rr�rrrrs5������B�B�B�
����rrc��eZdZdZd�ZdS)�CagefsNotSupportedErrorzCagefs Not Supported Exceptionc�<�t�||��dSr)�	Exceptionr)r�messages  rrz CagefsNotSupportedError.__init__!s�����4��)�)�)�)�)rN)rrr�__doc__rrrrrrs)������(�(�*�*�*�*�*rrc��eZdZdZdZdZd�Zd�Zd�Ze	d���Z
d�Zd	�Zd
�Z
e	d���Ze	d���Ze	d
���Zd�Zd�ZdS)�CagefsMpItemz@!%*��!c��|dd�dkr	d|_dS|���dkr	d|_dS||_dS)z�Constructor

        :param arg: Is either path to add to cagefs.mp or a raw line is read from cagefs.mp
        :param prefix: The same as adding prefix '!' to arg before passing it to ctorN��#r")�
_path_spec�strip)r�args  rrzCagefsMpItem.__init__+sI���r��r�7�c�>�>�"�D�O�O�O�
�Y�Y�[�[�B�
�
�"�D�O�O�O�!�D�O�O�Orc�\�|���dkr|�d|j|fz|_|S)z%Specify mode as in fluent constructor�@Nz%s,%03o)�prefixr')r�modes  rr-zCagefsMpItem.mode8s3���;�;�=�=�C�����'�4�?�D�*A�A�D�O��rc��|jSr�r'rs rrzCagefsMpItem.__str__@s
����rc�8�|dkrdS|ddkr|dzS|S)Nr"�/���r)�paths r�
_add_slashzCagefsMpItem._add_slashCs,���2�:�:��3���8�s�?�?��#�:���rc�d�t�|��}|���s|���rdSt�|�����}t�|�����}|�|��S�NF)r!�_adopt�is_dummyr4r3�
startswith)r�another�adopted�	this_path�test_preexist_in_paths     r�pre_exist_inzCagefsMpItem.pre_exist_inKs����%�%�g�.�.���=�=�?�?�	�g�.�.�0�0�	��5� �+�+�D�I�I�K�K�8�8�	� ,� 7� 7������ G� G���#�#�$9�:�:�:rc��t�|��}|���s|���rdS|���|���krdStjtjgi}g}|���|�|���|��vS)NFT)r!r7r8r,�_PREFIX_MOUNT_RW�_PREFIX_MOUNT_RO�get)r�existingr;�prefix_compatibility_map�null_optionss     r�is_compatible_by_prefix_withz)CagefsMpItem.is_compatible_by_prefix_withWs����%�%�h�/�/���=�=�?�?�	�g�.�.�0�0�	��5��;�;�=�=�G�N�N�,�,�,�,��4�%1�%B�l�Fc�Ed�#f� ����{�{�}�}� 8� <� <�W�^�^�=M�=M�|� \� \�\�\rc��|jduSrr/rs rr8zCagefsMpItem.is_dummygs����$�&�&rc�N�t|t��r|St|��Sr)�
isinstancer!)�xs rr7zCagefsMpItem._adoptjs%���a��&�&�	#��H���?�?�"rc�8�|�d��dS)zjCut off mode from path spec like @/var/run/screen,777

        Only one comma per path spec is allowed ;-)�,r)�split��	path_specs r�
_cut_off_modezCagefsMpItem._cut_off_modeqs�����s�#�#�A�&�&rc�@�|�tj��Sr)�lstripr!�PREFIX_LISTrNs r�_cut_off_prefixzCagefsMpItem._cut_off_prefixys������ 8�9�9�9rc�p�t�t�|j����Sr)r!rTrPr'rs rr3zCagefsMpItem.path}s&���+�+�L�,F�,F�t��,W�,W�X�X�Xrc�Z�|j|���kr
|jdSdS)Nrr")r'r3rs rr,zCagefsMpItem.prefix�s)���?�d�i�i�k�k�)�)��?�1�%�%��2rN)rrrrSr@rArr-r�staticmethodr4r>rFr8r7rPrTr3r,rrrr!r!%s�������K�����"�"�"�����������\��
;�
;�
;�]�]�]� '�'�'��#�#��\�#��'�'��\�'��:�:��\�:�Y�Y�Y�����rr!c�J�tj�t��Sr)�osr3�exists�CAGEFSCTL_TOOLrrr�is_cagefs_presentr\�s��
�7�>�>�.�)�)�)r��c���|�d}|�d}tj�|��stj|��|�tj||��tj|||��dS)Nr2)rYr3�isdir�mkdir�chmod�chown)r3r-�owner_id�group_ids    r�_mk_mount_dir_setup_permre�sm����������
�7�=�=�����
��������
���t�����H�T�8�X�&�&�&�&�&rFc��t��sdS|�tddg}n
td|g}|r-tj|tjtj���dStj|tjtj���dS)Nz--wait-lockz
--remount-allz	--remount��stdout�stderr)r\r[�
subprocess�Popen�DEVNULL�run)�user�remount_in_background�commands   r�_remount_cagefsrq�s����������|�!�=�/�B���!�;��5���V�����);�J�DV�W�W�W�W�W�W���w�z�'9�*�BT�U�U�U�U�U�Urr"c�j��t||||��t��sdStj�t
��s2t
jtdgtj	tj	���t��tt
d��}	t||z���
|���d�|D��}	�fd�|	D��}
|
sv|�dd��|�&|���}t!d	||�
��t!�|�
��|���|rt%|���n1��|
d��st)�|
d���|���dS#|���wxYw)
a�
    Add mount point to /etc/cagefs/cagefs.mp

    :param path: Directory path to be added in cagefs.mp and mounted
                 from within setup_mount_dir_cagefs().
                 If this directory does not exist, then it is created.

    :param added_by: package or component, mount dir relates to, or whatever will
                     stay in cagefs.mp with "# added by..." comment

    :param mode: If is not None: Regardless of whether directory exists or not prior this call,
                 it's permissions will be set to mode.

    :param owner_id: Regardless of whether directory exists or not prior this call,
                     it's owner id will be set to.
                     If None, the owner won't be changed.

    :param group_id: Regardless of whether directory exists or not prior this call,
                     it's group id will be set to.
                     If None, the group won't be changed.

    :param prefix: Mount point prefix. Default is mount as RW.
                   Pass '!' to add read-only mount point.
                   Refer CageFS section at http://docs.cloudlinux.com/ for more options.

    :param remount_cagefs: If True, cagefs skeleton will be automatically
                           remounted to apply changes.

    :param remount_in_background: If True, cagefs remount will be done in separate
                    background process, without waiting for completion

    :returns: None

    Propagates native EnvironmentError if no CageFS installed or something else goes wrong.

    Raises CagefsMpConflict if path is already specified in cagefs.mp, but in a way which is opposite
    to mount_as_readonly param.
    Nz--create-mprgzr+c3�>K�|]}|���V��dSr)�rstrip)�.0�	file_lines  r�	<genexpr>z)setup_mount_dir_cagefs.<locals>.<genexpr>�s.����F�F�y�	�(�(�*�*�F�F�F�F�F�Frc�>��g|]}��|���|��Sr)r>)rurJr
s  �r�
<listcomp>z*setup_mount_dir_cagefs.<locals>.<listcomp>�s,���P�P�P�!�x�7L�7L�Q�7O�7O�P�A�P�P�Prr�z# next line is added by )�file�ror2)rer\rYr3rZr
rjrmr[rl�add_new_line_to_cagefs_mp�openr!r-�seekr(�print�closerqrFr)r3�added_byr-rcrdr,�remount_cagefsro�	cagefs_mp�trim_nl_iter�pre_exist_optionr
s           @r�setup_mount_dir_cagefsr��s����R�T�4��8�<�<�<��������7�>�>�,�-�-�n����
�6�z�?Q�Zd�Zl�m�m�m�m�����
�'��.�.�I�����
�.�.�3�3�D�9�9��F�F�I�F�F�F��P�P�P�P�|�P�P�P���	C��N�N�1�a� � � ��#�#�>�>�+�+���0�(��K�K�K�K��(��+�+�+�+��O�O�����
M��6K�L�L�L�L���6�6�7G��7K�L�L�	C�"�8�-=�b�-A�B�B�B�
�O�O�������I�O�O�������s
�C(F�F2c��ttd��5}|���cddd��S#1swxYwYdS)N�r)r~r
�	readlines)�fs r�_get_cagefs_mp_linesr��s��	
� �#�	&�	&��!��{�{�}�}���������������������s�7�;�;c��ttd��5}|�|��cddd��S#1swxYwYdS)N�w)r~r
�
writelines)�linesr�s  r�_write_cagefs_mp_linesr�s���	
� �#�	&�	&�#�!��|�|�E�"�"�#�#�#�#�#�#�#�#�#�#�#�#����#�#�#�#�#�#s�8�<�<c��t��}|r?|ddkr5|dddkr%|dxxdz
cc<t|��dSdSdSdS)zR
    Add new line to the end of /etc/cagefs/cagefs.mp file if it is not there
    rr"r2�
N)r�r�)r�s rr}r}ss��
!�"�"�E��&��q��R���E�"�I�b�M�T�$9�$9�
�b�	�	�	�T��	�	�	��u�%�%�%�%�%�&�&���$9�$9rc�T��t��}tjd�tjtj|���������fd�|D��}t|��t|��krdSt|��|rt|���dSdS)af
    Remove mount points matching given path from cagefs.mp file
    :param str path: Path that should be removed from file.
    :param bool remount_cagefs: Remount cagefs skeleton or not
    :param remount_in_background: If True, cagefs remount will be done in separate
           background process, without waiting for completion
    :return: Nothing
    z^[{prefix}]?{path}(,\d+)?$)r,r3c�>��g|]}��|���|��Sr)�match)ru�liner�s  �rryz+remove_mount_dir_cagefs.<locals>.<listcomp> s(���L�L�L��a�g�g�d�m�m�L��L�L�LrNr|)
r��re�compile�formatr!rS�escape�lenr�rq)r3r�ror��lines_with_excluded_pathr�s     @r�remove_mount_dir_cagefsr�s����
!�"�"�E�
�
�/�6�6��'�
�Y�t�_�_�7���	�	�A� M�L�L�L��L�L�L���5�z�z�S�1�2�2�2�2����3�4�4�4��E��.C�D�D�D�D�D�D�E�Erc�@�tj�d��S)zEIf this folder /var/.cagefs exists, it means process is inside cagefsz/var/.cagefs)rYr3r_rrr�	in_cagefsr�+s��
�7�=�=��(�(�(rc��	d}|tjvrtj�|��ddl}n#t$rYdSwxYw	|�|��sdSn#t$rtd���wxYwdS)z,
    Check that cagefs enabled for user
    z/usr/share/cagefs/rNFz;ERROR: CageFS version is unsupported. Please update CageFS.T)�sysr3�append�	cagefsctl�ImportError�is_user_enabled�AttributeErrorr)rn�cagefs_lib_dirr�s   r�_is_cagefs_enabledr�0s����-�����)�)��H�O�O�N�+�+�+������������u�u�����e��(�(��.�.�	��5�	���e�e�e�%�&c�d�d�d�e�����4s�36�
A�A�A � A:)r]NNr6)Nr]NNr"FF)FF)�
__future__rrrrYr�rjr�r
r[rrrr!r\rerqr�r�r�r}r�r�r�rrr�<module>r�s���&�%�%�%�%�%�&�&�&�&�&�&�������	�	�	�	�	�	�	�	�����
�
�
�
�,��*�������y����*�*�*�*�*�i�*�*�*�_�_�_�_�_�_�_�_�D*�*�*�
'�
'�
'�
'� V�V�V�V�UY�RW�P�P�P�P�f���
#�#�#�
&�&�&�E�E�E�E�2)�)�)�
����r