%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/certbot/compat/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/certbot/compat/__pycache__/filesystem.cpython-312.pyc

�

M/�ew��h�dZddlmZddlmZddlZddlZddlZddlZddl	m
Z
ddl	mZddl	mZddl	m
Z
dd	l	mZ	ddlZddlZddlZddlZddlZddlZddlZd
ZGd�d
�Ze�Zdededdfd�Zdedefd�Zedededfd��Zdedededededdfd�Z 	d@dededededdf
d�Z!dededefd�Z"dedefd�Z#dededefd�Z$dAdedededefd �Z%dAdededdfd!�Z&dAdededdfd"�Z'dededdfd#�Z(dedefd$�Z)d%edefd&�Z*d'edefd(�Z+d'edefd)�Z,d*ed+edefd,�Z-d-ed.edefd/�Z.d'ed0edefd1�Z/d'edefd2�Z0dededdfd3�Z1dBd4e
dedeede
fd5�Z2dedeeeeefffd6�Z3dededdfd7�Z4dededdfd8�Z5d9eeefdefd:�Z6dededefd;�Z7d<e
d=e
defd>�Z8de
fd?�Z9y#e$rdZY��TwxYw)Cz;Compat module to handle files security on Windows and Linux�)�absolute_import)�contextmanagerN)�Any)�Dict)�	Generator)�List)�OptionalFTc��eZdZdZdd�Zy)�
_WindowsUmaskz+Store the current umask to apply on WindowsNc��d|_y)N�)�mask)�selfs �;/usr/lib/python3/dist-packages/certbot/compat/filesystem.py�__init__z_WindowsUmask.__init__$s	����	�)�returnN)�__name__�
__module__�__qualname__�__doc__r�rrrr"s
��5�rr�	file_path�moderc�V�trtj||�yt||�y)a[
    Apply a POSIX mode on given file_path:

      - for Linux, the POSIX mode will be directly applied using chmod,
      - for Windows, the POSIX mode will be translated into a Windows DACL that make sense for
        Certbot context, and applied to the file using kernel calls.

    The definition of the Windows DACL that correspond to a POSIX mode, in the context of Certbot,
    is explained at https://github.com/certbot/certbot/issues/6356 and is implemented by the
    method `_generate_windows_flags()`.

    :param str file_path: Path of the file
    :param int mode: POSIX mode to apply
    N)�
POSIX_MODE�os�chmod�_apply_win_mode�rrs  rrr+s���
����D�!��	�4�(rrc�r�trtj|�Stj}|t_|S)a$
    Set the current numeric umask and return the previous umask. On Linux, the built-in umask
    method is used. On Windows, our Certbot-side implementation is used.

    :param int mask: The user file-creation mode mask to apply.
    :rtype: int
    :return: The previous umask value.
    )rr�umask�_WINDOWS_UMASKr)r�previous_umasks  rr"r"@s.����x�x��~��#�(�(�N��N���r)NNNc#�rK�d}	t|�}d��|�t|�yy#|�t|�wwxYw�w)z�
    Apply a umask temporarily, meant to be used in a `with` block. Uses the Certbot
    implementation of umask.

    :param int mask: The user file-creation mode mask to apply temporarily
    N)r")r�	old_umasks  r�
temp_umaskr'QsF���� $�I���$�K�	��
�� ��)��!��9� ��)��!�s�7�$�7�4�7�src�dst�	copy_user�
copy_groupc���trMtj|�}|r|jnd}|r|jnd}tj
|||�n|rt
||�t||�y)a�
    Copy ownership (user and optionally group on Linux) from the source to the
    destination, then apply given mode in compatible way for Linux and Windows.
    This replaces the os.chown command.

    :param str src: Path of the source file
    :param str dst: Path of the destination file
    :param int mode: Permission mode to apply on the destination file
    :param bool copy_user: Copy user if `True`
    :param bool copy_group: Copy group if `True` on Linux (has no effect on Windows)
    ���N)rr�stat�st_uid�st_gid�chown�_copy_win_ownershipr)r(r)rr*r+�stats�user_id�group_ids        r�copy_ownership_and_apply_moder6ksW���������"+�%�,�,���#-�5�<�<�2��	����g�x�(�	��C��%�	�#�t�rc�
�trctj|�}|r|jnd}|r|jnd}tj
|||�t
||j�y|rt||�t||�y)aU
    Copy ownership (user and optionally group on Linux) and mode/DACL
    from the source to the destination.

    :param str src: Path of the source file
    :param str dst: Path of the destination file
    :param bool copy_user: Copy user if `True`
    :param bool copy_group: Copy group if `True` on Linux (has no effect on Windows)
    r-N)
rrr.r/r0r1r�st_moder2�_copy_win_mode)r(r)r*r+r3r4r5s       r�copy_ownership_and_moder:�sc���������"+�%�,�,���#-�5�<�<�2��
����g�x�(�
�c�5�=�=�!����S�)��s�C� rc��tr5tjtj|�j�|k(St||�S)aa
    Check if the given mode matches the permissions of the given file.
    On Linux, will make a direct comparison, on Windows, mode will be compared against
    the security model.

    :param str file_path: Path of the file
    :param int mode: POSIX mode to test
    :rtype: bool
    :return: True if the POSIX mode matches the file permissions
    )rr.�S_IMODErr8�_check_win_moder s  r�
check_moder>�s7����|�|�B�G�G�I�.�6�6�7�4�?�?��9�d�+�+rc��tr4tj|�jtj�k(Stj|t
j�}|j�}t�|k(S)z�
    Check if given file is owned by current user.

    :param str file_path: File path to check
    :rtype: bool
    :return: True if given file is owned by current user, False otherwise.
    )
rrr.r/�getuid�
win32security�GetFileSecurity�OWNER_SECURITY_INFORMATION�GetSecurityDescriptorOwner�_get_current_user)r�security�users   r�check_ownerrH�s_����w�w�y�!�(�(�B�I�I�K�7�7��,�,�Y�
�8`�8`�a�H��.�.�0�D���$�&�&rc�4�t|�xrt||�S)z�
    Check if given file has the given mode and is owned by current user.

    :param str file_path: File path to check
    :param int mode: POSIX mode to check
    :rtype: bool
    :return: True if file has correct mode and owner, False otherwise.
    )rHr>r s  r�check_permissionsrJ�s���y�!�A�j��D�&A�Ar�flagsc	��trtj|||�S|tjz�r4|tjzrt
jnt
j}tj�}|j}t�}t||tj�}|j|d�|j!d|d�d}	t#j$|t"j&t"j(t"j*z||dd�}	|r|jA�	tj||tjztjz�Stj||�}
tC||�|
S#t,j.$r�}	|	j0t0j2k(r$t5t6j8|	j:��|	j0t0j<k(r$t5t6j>|	j:��|	�d}	~	wwxYw#|r|jA�wwxYw)aw
    Wrapper of original os.open function, that will ensure on Windows that given mode
    is correctly applied.

    :param str file_path: The file path to open
    :param int flags: Flags to apply on file while opened
    :param int mode: POSIX mode to apply on file when opened,
        Python defaults will be applied if ``None``
    :returns: the file descriptor to the opened file
    :rtype: int
    :raise: OSError(errno.EEXIST) if the file already exists and os.O_CREAT & os.O_EXCL are set,
            OSError(errno.EACCES) on Windows if the file already exists and is a directory, and
            os.O_CREAT is set.
    r�N)"rr�open�O_CREAT�O_EXCL�win32con�
CREATE_NEW�
CREATE_ALWAYSrA�SECURITY_ATTRIBUTES�SECURITY_DESCRIPTORrE�_generate_daclr#r�SetSecurityDescriptorOwner�SetSecurityDescriptorDacl�	win32file�
CreateFile�GENERIC_READ�FILE_SHARE_READ�FILE_SHARE_WRITE�
pywintypes�error�winerror�ERROR_FILE_EXISTS�OSError�errno�EEXIST�strerror�ERROR_SHARING_VIOLATION�EACCES�Closer)rrKr�disposition�
attributesrFrG�dacl�handle�err�fds           rrNrN�s�����w�w�y�%��.�.�
�r�z�z��.3�R�Y�Y�->�h�)�)�H�DZ�DZ��"�6�6�8�
��1�1�� �"���d�D�.�*=�*=�>��	�+�+�D�!�4�	�*�*�1�d�A�6���	��)�)�)�Y�5K�5K�*3�*C�*C�i�F`�F`�*`�*4�k�1�d�L�F������
�w�w�y�%�"�*�*�"4�r�y�y�"@�A�A�
����E�	"�B�	�)�T��
�I��)���	��|�|�x�9�9�9��e�l�l�C�L�L�9�9��|�|�x�?�?�?��e�l�l�C�L�L�9�9��I��	��������s&�AF
�
H&�BH!�!H&�&H)�)H>c�b�td�}	t|d|zz�tr!tj||�t|�Stj}	tt_tj||�|t_t|�S#|t_wxYw#t|�wxYw)a4
    Rewrite of original os.makedirs function, that will ensure on Windows that given mode
    is correctly applied.

    :param str file_path: The file path to open
    :param int mode: POSIX mode to apply on leaf directory when created, Python defaults
                     will be applied if ``None``
    r�)r"rr�makedirs�mkdir)rr�
current_umask�
orig_mkdir_fns    rrqrqs����!�H�M��
	�m�e�d�l�*�+���;�;�y�$�/�	�m�����
�	%��B�H��;�;�y�$�/�$�B�H�
�m���%�B�H��
�m��s)�,B!�B!�$B�:B!�
B�B!�!
B.c��trtj||�Stj�}|j
}t
�}t||tj�}|j|d�|jd|d�	tj||�y#tj$rT}|j t j"k(r0t%t&j(|j*||j ��|�d}~wwxYw)a,
    Rewrite of original os.mkdir function, that will ensure on Windows that given mode
    is correctly applied.

    :param str file_path: The file path to open
    :param int mode: POSIX mode to apply on directory when created, Python defaults
                     will be applied if ``None``
    FrMrN)rrrrrArTrUrErVr#rrWrXrY�CreateDirectoryr^r_r`�ERROR_ALREADY_EXISTSrbrcrdre)rrrjrFrGrkrms       rrrrr:s�����x�x�	�4�(�(��2�2�4�J��-�-�H���D��$��n�&9�&9�:�D��'�'��e�4��&�&�q�$��2���!�!�)�Z�8��������<�<�8�8�8�8��%�,�,����i����N�N��	���s�B�D�2AD�Dc��ttd�rttd�||�ytj||�y)z�
    Rename a file to a destination path and handles situations where the destination exists.

    :param str src: The current file path.
    :param str dst: The new file path.
    �replaceN)�hasattrr�getattr�rename)r(r)s  rryryYs3���r�9��	���I��s�C�(�	�	�	�#�s�rc���|}tstjdk\rZtjj|�}tjj
|�rtdj|���|Sg}tjj
|�r�|}tj|�}tjj|�s=tjjtjj|�|�}||vrtdj|���|j|�tjj
|�r��tjj|�S)a 
    Find the real path for the given path. This method resolves symlinks, including
    recursive symlinks, and is protected against symlinks that creates an infinite loop.

    :param str file_path: The path to resolve
    :returns: The real path for the given path
    :rtype: str
    )��zError, link {0} is a loop!)r�sys�version_infor�path�realpath�islink�RuntimeError�format�readlink�isabs�join�dirname�append�abspath)r�
original_pathr��inspected_paths�	link_paths     rr�r�js
���M��S�%�%��/��w�w���	�*��
�7�7�>�>�$���;�B�B�=�Q�R�R���!#�O�
�'�'�.�.��
#��	��K�K�	�*�	��w�w�}�}�Y�'������R�W�W�_�_�Y�%?��K�I���'��;�B�B�=�Q�R�R����y�)�
�'�'�.�.��
#��7�7�?�?�9�%�%rr�c��tj|�}ts|jd�s|St	|�dkr|ddStd��)a
    Return a string representing the path to which the symbolic link points.

    :param str link_path: The symlink path to resolve
    :return: The path the symlink points to
    :returns: str
    :raise: ValueError if a long path (260> characters) is encountered on Windows
    z\\?\i�Nz3Long paths are not supported by Certbot on Windows.)rr�r�
startswith�len�
ValueError)r�r�s  rr�r��sI���;�;�y�!�D������3����4�y�3���A�B�x��
�J�
K�Krr�c��trEtjj|�xr$tj|tj
�St
|�S)z�
    Is path an executable file?

    :param str path: path to test
    :return: True if path is an executable file
    :rtype: bool
    )rrr��isfile�access�X_OK�_win_is_executable)r�s r�
is_executabler��s9����w�w�~�~�d�#�@��	�	�$����(@�@��d�#�#rc	��trLttjt	j|�j
�tjz�Stj|tj�}|j�}t|jtjtjtjd�d���S)z�
    Check if everybody/world has any right (read/write/execute) on a file given its path.

    :param str path: path to test
    :return: True if everybody/world has any right to the file
    :rtype: bool
    �S-1-1-0��TrusteeForm�TrusteeType�
Identifier)r�boolr.r<rr8�S_IRWXOrArB�DACL_SECURITY_INFORMATION�GetSecurityDescriptorDacl�GetEffectiveRightsFromAcl�TRUSTEE_IS_SID�TRUSTEE_IS_USER�ConvertStringSidToSid)r�rFrks   r�has_world_permissionsr��s�����D�L�L������!6�!6�7�$�,�,�F�G�G��,�,�T�=�3Z�3Z�[�H��-�-�/�D���.�.�$�3�3�$�4�4�#�9�9�)�D�0���r�old_key�	base_modec��tr{tjtj|�j�tj
tjztjztjzz}||zS|S)a
    Calculate the POSIX mode to apply to a private key given the previous private key.

    :param str old_key: path to the previous private key
    :param int base_mode: the minimum modes to apply to a private key
    :return: the POSIX mode to apply
    :rtype: int
    )	rr.r<rr8�S_IRGRP�S_IWGRP�S_IXGRP�S_IROTH)r�r��old_modes   r�compute_private_key_moder��sa����L�L�����!1�!9�!9�:��\�\�D�L�L�0�4�<�<�?�$�,�,�N�P���8�#�#��r�path1�path2c��tr[tj|�}tj|�}|j|jf|j|jfk(Stj|t
j�}|j�}tj|t
j�}|j�}||k(S)as
    Return True if the ownership of two files given their respective path is the same.
    On Windows, ownership is checked against owner only, since files do not have a group owner.

    :param str path1: path to the first file
    :param str path2: path to the second file
    :return: True if both files have the same ownership, False otherwise
    :rtype: bool

    )	rrr.r/r0rArBrCrD)r�r��stats1�stats2�	security1�user1�	security2�user2s        r�has_same_ownershipr��s�����������������
�
�v�}�}�-�&�-�-����1O�O�O��-�-�e�]�5]�5]�^�I��0�0�2�E��-�-�e�]�5]�5]�^�I��0�0�2�E��E�>�r�min_modec��tr'tj|�j}|||zk(St	|�}tj|t
jt
jz�}|j�}|j�}t||�}t|j��D]X}|j|�}|d}	|d}|jt
j t
j"|d��}
|
|
|	zk7s�Xyy)a�
    Check if a file given its path has at least the permissions defined by the given minimal mode.
    On Windows, group permissions are ignored since files do not have a group owner.

    :param str path: path to the file to check
    :param int min_mode: the minimal permissions expected
    :return: True if the file matches the minimal permissions expectations, False otherwise
    :rtype: bool
    rM�r�FT)rrr.r8r�rArBrCr�rDr�rV�range�GetAceCount�GetAcer�r�r�)r�r�r8rFrGrk�min_dacl�index�min_acer�effective_masks           r�has_min_permissionsr��s����'�'�$�-�'�'���'�H�,�,�,��D�>�D��,�,��m�6�6��9`�9`�`�b�H��.�.�0�D��-�-�/�D��d�H�-�H��x�+�+�-�.����/�/�%�(���q�z���q�z���7�7�(�7�7�(�8�8��9
����^�d�2�2���"rc�d�tjj|�sytj|tj
�}|j
�}|jtjtjt�d��}|tjztjk(S)NFr�)
rr�r�rArBr�r�r�r�r�rE�
ntsecuritycon�FILE_GENERIC_EXECUTE)r�rFrkrs    rr�r�,s���
�7�7�>�>�$����,�,�T�=�3Z�3Z�[�H��-�-�/�D��)�)�$�3�3�$�4�4�'�)�+��D��-�4�4�4�
�8Z�8Z�Z�Zrc�
�t|�}tj|tj�}|j	�}t||�}|j
d|d�tj|tj|�y)z�
    This function converts the given POSIX mode into a Windows ACL list, and applies it to the
    file given its path. If the given path is a symbolic link, it will resolved to apply the
    mode on the targeted file.
    rMrN)	r�rArBrCrDrVrX�SetFileSecurityr�)rrrFrGrks     rrr<so����#�I��,�,�Y�
�8`�8`�a�H��.�.�0�D��$��%�D�
�&�&�q�$��2��!�!�)�]�-T�-T�V^�_r�user_sidc�H�|r|d|z
z}t|�}tjd�}tjd�}tjd�}tj�}|||fvr1t	|d�}|r!|jtj||�t	|d�}	|	r!|jtj|	|�t	dddd��}
|jtj|
|�|jtj|
|�|S)	NrpzS-1-5-18zS-1-5-32-544r�rG�allT��read�write�execute)�
_analyze_moderAr��ACL�_generate_windows_flags�AddAccessAllowedAce�ACL_REVISION)r�rr�analysis�system�admins�everyonerk�
user_flags�everybody_flags�full_permissionss           rrVrVOs����u�t�|�$���T�"�H�
�
0�
0��
<�F�
�
0�
0��
@�F��2�2�9�=�H�����D����'�'�,�X�f�-=�>�
���$�$�]�%?�%?��X�V�.�h�u�o�>�O��� � ��!;�!;�_�h�W�/��t�X\�/]�^�����]�7�7�9I�6�R����]�7�7�9I�6�R��Krc���|tjz|tjz|tjzd�|tjz|tj
z|tjzd�d�S)Nr�)rGr�)r.�S_IRUSR�S_IWUSR�S_IXUSRr��S_IWOTH�S_IXOTH)rs rr�r�ssb���4�<�<�'��D�L�L�(��d�l�l�*�
��4�<�<�'��D�L�L�(��d�l�l�*�
�
�rc�8�t|�}tj|tj�}|j	�}tj|tj�}|j|d�tj|tj|�y�NF)r�rArBrCrDrWr�)r(r)�security_src�user_src�security_dsts     rr2r2�st��
�3�-�C� �0�0��m�6^�6^�_�L��6�6�8�H� �0�0��m�6^�6^�_�L��+�+�H�e�<��!�!�#�}�'O�'O�Q]�^rc�:�t|�}tj|tj�}|j	�}tj|tj�}|jd|d�tj|tj|�y)NrMr)r�rArBr�r�rXr�)r(r)r�rkr�s     rr9r9�sv��
�3�-�C�!�0�0��m�6]�6]�^�L��1�1�3�D� �0�0��m�6]�6]�^�L��*�*�1�d�A�6��!�!�#�}�'N�'N�P\�]r�rights_descc���d}|dr|tjz}|dr5|tjtjztjzz}|dr|tjz}|S)Nrr�r�r�)r��FILE_GENERIC_READ�FILE_ALL_ACCESSr�)r��flags  rr�r��sv��$
�D��6���m�5�5�5���7���}�4�4�&�8�8�9�&�;�;�<�=���9���m�8�8�8���Krc��t|�}tj|tjtjz�}|j�}|j
�}|syt||�}t||�Sr�)	r�rArBrCr�r�rDrV�_compare_dacls)rrrFrkrG�ref_dacls      rr=r=�sw����#�I��,�,�Y�
�8`�8`�/<�/V�/V�9W�X�H��-�-�/�D��.�.�0�D����d�D�)�H��$��)�)r�dacl1�dacl2c���t|j��D�cgc]}|j|���c}t|j��D�cgc]}|j|���c}k(Scc}wcc}w)z�
    This method compare the two given DACLs to check if they are identical.
    Identical means here that they contains the same set of ACEs in the same order.
    )r�r�r�)r�r�r�s   rr�r��s`��
/4�E�4E�4E�4G�.H�I�U�U�\�\�%�
 �I�.3�E�4E�4E�4G�.H�I�U�U�\�\�%�
 �I�
J�K��I��Is�A.�A3c��djtj�tj��}t	j
d|�dS)z=
    Return the pySID corresponding to the current user.
    z{0}\{1}Nr)r��win32api�
GetDomainName�GetUserNamerA�LookupAccountName)�account_names rrErE�sB���$�$�X�%;�%;�%=�x�?S�?S�?U�V�L��*�*�4��>�q�A�Ar)TT)rp)N):r�
__future__r�
contextlibrrcrr.r��typingrrrrr	r�r^r�rQrYrAr`r�ImportErrorrr#�str�intrr"r'r�r6r:r>rHrJrNrqrrryr�r�r�r�r�r�r�r�rrVr�r2r9r�r=r�rErrr�<module>rs���A�&�%��	��
���������������J������)�S�)��)��)�*�����"�
�S�
�Y�'7�8�
��
�2�s����C��-1��?C��HL��DHL�!��!�3�!�'+�!�@D�!�PT�!�2,�#�,�S�,�T�,�"'�3�'�4�'�&	B��	B�C�	B�D�	B�B�C�B��B�3�B�3�B�J���3��4��@�S������>���3��4��"&��&��&�DL��L��L�D$��$��$������*�c��c��c��*�c��#��$��2*�c�*�S�*�T�*�Z
[�S�
[�T�
[� `�s�`�#�`�$�`�&!�S�!��!�8�C�=�!�C�!�H����S�$�s�C�x�.�%8� 9��_�S�_�s�_�t�_�
^��
^�#�
^�$�
^���c�3�h���C��>*�s�*�#�*�$�*�,K�#�K�c�K�d�K�B�3�B��K���J��s�F&�&F1�0F1

Zerion Mini Shell 1.0