HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/cloudlinux/venv/lib/python3.11/site-packages/clcagefslib/__pycache__/io.cpython-311.pyc
�

�9Vj	����ddlZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZeje
��Zd
d�Zejd���Zd�Zd�Zdd
�Zd�Zd�ZdS)�N)�	clcaptain)�ExternalProgramFailedTc�$�	t|d��5}|���cddd��S#1swxYwYdS#ttf$r>t	jd|ztjd��|s�tjd��YdSwxYw)z�
    Helper for read file, process errors and make backup before read
    :param: filename `str` name of file for read
    :param: exit_on_error `bool` use sys.exit on error or raise exception
    �rNzError: failed to read �)	�open�	readlines�OSError�IOError�secureio�logging�SILENT_FLAG�sys�exit)�filename�
exit_on_error�_files   �Bopt/cloudlinux/venv/lib/python3.11/site-packages/clcagefslib/io.py�	read_filers����
�(�C�
 �
 �	%�E��?�?�$�$�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%����	%�	%�	%�	%�	%�	%��
�W�������1�H�<�h�>R�TU�V�V�V��	�����������	���s-�A�3�A�7�A�7�A�AB�Bc� �t|��S�N)r)�paths r�read_file_cachedr&s���T�?�?��c�z�tj|||||tj���}tj|��|duS)N)�logger)r�create_dir_securer
�closefd)r�perm�uid�gid�parent_path�fds      r�make_userdirr$,sF��	�	#��d�C��k�(�2B�
�
�
�B�
��R����
��:�rc�B�	tj|��j}n#t$rYdSwxYw||krdS	t	j|��}n#t$rYdSwxYwtj�|j	��tj�|��kS)a�
    CLOS-4545 guard against stealing a shared home's ``.cagefs``.

    Return ``True`` when ``home_path`` is owned by a user *other than*
    ``target_uid`` and that owner is a real ``/etc/passwd`` user whose home
    directory is ``home_path`` itself.

    On every panel CageFS supports, the home directory is owned by the real
    subscription/account user, so its owner is the authoritative answer to
    "who does this home belong to".  When several ``/etc/passwd`` entries share
    one home -- e.g. an orphan ``sys_user`` left behind by a reverted Plesk
    migration, which merely has the home as its ``pw_dir`` but does not own it
    -- an operation aimed at a uid that is *not* the home owner must not chown
    ``<home>/.cagefs`` to it: that would strip the real owner of its own
    ``.cagefs`` and break the subscription (the next HTTP request fails with
    503).  Callers must skip the chown when this returns ``True``.

    Keying on the home owner (rather than the current ``.cagefs`` owner) means
    the legitimate owner -- and automated repair such as
    ``update_status(fix_owner=True)`` -- can always (re)claim ``.cagefs``, even
    after it was previously flipped to an orphan.  ``False`` is also returned
    when ``target_uid`` owns the home, when the home cannot be stat'd, or when
    it is owned by an unrelated uid (e.g. root) that does not live in this home,
    so normal provisioning, brand-new subscriptions and ownership repair keep
    working.
    F)
�os�stat�st_uidr
�pwd�getpwuid�KeyErrorr�realpath�pw_dir)�	home_path�
target_uid�home_uid�
home_owners    r�home_owned_by_other_userr25s���6��7�9�%�%�,���������u�u������:����u���\�(�+�+�
�
�������u�u������7���J�-�.�.�"�'�2B�2B�9�2M�2M�M�Ms��
*�*�A�
A�AFc
��|s tj�|���s2	tj|��nj#t$r]}|jt
jkrt�d|�d���nt�	d|��|���Yd}~nd}~wwxYw	tj||��n�#ttf$r�}d|�d|�dt|���dd	����}t�	||���|rtj||d
��nt#|t$j���Yd}~d
Sd}~wwxYwdS)
NzSymlink z does not existz Error: Unable to remove symlink )�exc_infoz Error: failed to create symlink z to z : �ErrnozErr codeT)�fileF)r&r�islink�unlinkr
�errno�ENOENTr�info�errorr�symlinkr�str�replacerr
�printr�stderr)�	dest_path�	link_name�	write_log�force�silent�e�msgs       r�switch_symlinkrIas�����B�G�N�N�9�-�-��	Y��I�i� � � � ���	Y�	Y�	Y��w�%�,�&�&����A�y�A�A�A�B�B�B�B����K�	�K�K�VW��X�X�X����������		Y����
		���i��3�3�3�3���.�/�	�	�	�w�Y�w�w�I�w�w�RU�VW�RX�RX�R`�R`�ah�jt�Ru�Ru�w�w�C��L�L��q�L�)�)�)��
,�� ��f�d�3�3�3�3��c��
�+�+�+�+��4�4�4�4�4�����	�����5s/�9�
B �AB�B �$B:�:E�A<E
�
Ec�p�d}	tjd|d���5}|j}|�|��|���tj|�����ddd��n#1swxYwYtj||��|rGt
j	�
|��r*	tj|��dS#t$rYdSwxYwdSdS#|rEt
j	�
|��r'	tj|��w#t$rYwwxYwwwxYw)N�wF)�dir�delete)
�tempfile�NamedTemporaryFile�name�write�flushr&�fsync�filenor?r�exists�remover
)�	directoryr�content�	temp_path�tmp_files     r�
write_via_tmpr[ws����I��
�
(��)�E�
J�
J�
J�	(�h� �
�I��N�N�7�#�#�#��N�N�����H�X�_�_�&�&�'�'�'�		(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(����	(�	(�	(�	(�
	�
�9�h�'�'�'��	�����	�2�2�	�
��	�)�$�$�$�$�$���
�
�
����
����	�	�	�	��9�	�����	�2�2�	�
��	�)�$�$�$�$���
�
�
���
����	�	���se�C+�AA>�2C+�>B�C+�B�C+�C�
C$�#C$�+"D5�D#�"D5�#
D0�-D5�/D0�0D5c�*�tj|tjtjztjz��}	tj||��tj|||��tj|��dS#tj|��wxYwr)r&r�O_RDONLY�
O_NOFOLLOW�	O_CLOEXEC�fchmod�fchown�close)r�moder r!r#s     r�apply_metadata_nofollowrd�ss��
���r�{�R�]�2�R�\�A�	B�	B�B��
�	�"�d����
�	�"�c�3����
������������������s�+A<�<B)T)TTF)r9�	functoolsr
r&r)rrNr�clcommonr�clcommon.utilsr�	getLogger�__name__rr�cacherr$r2rIr[rd�rr�<module>rls��

������������	�	�	�	�
�
�
�
�
�
�
�
���������������0�0�0�0�0�0�
��	�8�	$�	$������"�������
���)N�)N�)N�X����,���"	�	�	�	�	r