HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /lib/python3/dist-packages/certbot/compat/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/certbot/compat/__pycache__/filesystem.cpython-311.pyc
�

E��cw���dZddlmZddlmZddlZddlZddlZddlZddl	m
Z
ddl	mZddl	mZddl	m
Z
dd	l	mZ	ddlZddlZddlZddlZddlZddlZddlZd
Zn
#e$rdZYnwxYwGd�d
��Ze��Zdededdfd�Zdedefd�Zedede
dfd���Zdedededededdfd�Z 	dAdededededdf
d�Z!dededefd�Z"dedefd�Z#dededefd�Z$dBded ededefd!�Z%dBdededdfd"�Z&dBdededdfd#�Z'dededdfd$�Z(dedefd%�Z)d&edefd'�Z*d(edefd)�Z+d(edefd*�Z,d+ed,edefd-�Z-d.ed/edefd0�Z.d(ed1edefd2�Z/d(edefd3�Z0dededdfd4�Z1dCd5e
dedeede
fd6�Z2dedeeeeefffd7�Z3dededdfd8�Z4dededdfd9�Z5d:eeefdefd;�Z6dededefd<�Z7d=e
d>e
defd?�Z8de
fd@�Z9dS)Dz;Compat module to handle files security on Windows and Linux�)�absolute_import)�contextmanagerN)�Any)�Dict)�List)�	Generator)�OptionalFTc��eZdZdZdd�ZdS)�
_WindowsUmaskz+Store the current umask to apply on Windows�returnNc��d|_dS)N�)�mask)�selfs �;/usr/lib/python3/dist-packages/certbot/compat/filesystem.py�__init__z_WindowsUmask.__init__$s
����	�	�	�)rN)�__name__�
__module__�__qualname__�__doc__r�rrrr"s.������5�5������rr�	file_path�moderc�b�trtj||��dSt||��dS)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�l�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"@s0�����x��~�~��#�(�N��N���r)NNNc#�K�d}	t|��}dV�|�t|��dSdS#|�t|��wwxYw)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'Qsg���� $�I���$�K�K�	��
�
�
�� ��)������!� ��9� ��)�����!���s	�.�A�src�dst�	copy_user�
copy_groupc���trAtj|��}|r|jnd}|r|jnd}tj|||��n|rt
||��t||��dS)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_moder6ks����
&�������"+�3�%�,�,���#-�5�5�<�<�2��	���g�x�(�(�(�(�	�&��C��%�%�%�	�#�t�����rc��trWtj|��}|r|jnd}|r|jnd}tj|||��t
||j��dS|rt||��t||��dS)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:�s����!�������"+�3�%�,�,���#-�5�5�<�<�2��
���g�x�(�(�(�
�c�5�=�!�!�!�!�!��	*���S�)�)�)��s�C� � � � � rc��tr/tjtj|��j��|kSt||��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>�s?���@��|�B�G�I�.�.�6�7�7�4�?�?��9�d�+�+�+rc��tr.tj|��jtj��kStj|t
j��}|���}t��|kS)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�se���8��w�y�!�!�(�B�I�K�K�7�7��,�Y�
�8`�a�a�H��.�.�0�0�D����$�&�&rc�@�t|��ot||��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�&A�Ar��flagsc	��trtj|||��S|tjz�r�|tjzrt
jnt
j}tj	��}|j
}t��}t||tj��}|�|d��|�d|d��d}	t#j|t"jt"jt"jz||dd��}n�#t,j$ro}	|	jt0jkrt5t6j|	j���|	jt0jkrt5t6j|	j���|	�d}	~	wwxYw	|r|� ��n#|r|� ��wwxYwtj||tjztjz��Stj||��}tC||��|S)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)
rrLr�disposition�
attributesrFrG�dacl�handle�errs
          rrOrO�s����/��w�y�%��.�.�.�
�r�z��)B�.3�R�Y�->�Z�h�)�)�H�DZ��"�6�8�8�
��1�� �"�"���d�D�.�*=�>�>��	�+�+�D�!�4�4�4�	�*�*�1�d�A�6�6�6���	��)�)�Y�5K�*3�*C�i�F`�*`�*4�k�1�d�L�L�F�F����	�	�	��|�x�9�9�9��e�l�C�L�9�9�9��|�x�?�?�?��e�l�C�L�9�9�9��I�����	����
��
����������
��������
�����w�y�%�"�*�"4�r�y�"@�A�A�A��W�Y��
&�
&�F�	�)�T�����Ms+�;D�F�F�A*E=�=F�F�F6c��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``
    rrK)r"rr�makedirs�mkdir)rr�
current_umask�
orig_mkdir_fns    rrprps����!�H�H�M��
	�m�e�d�l�*�+�+�+��	0��;�y�$�/�/�	�m�������
�	%��B�H��;�y�$�/�/�$�B�H�
�m������%�B�H�$�$�$�$��
�m�������s)�0B0�B0�%B�B0�B-�-B0�0Cc���trtj||��Stj��}|j}t
��}t||tj	��}|�
|d��|�d|d��	tj
||��nT#tj$rB}|jt jkr&t%t&j|j||j���|�d}~wwxYwdS)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``
    FrNrN)rrrqrArUrVrErWr#rrXrYrZ�CreateDirectoryr_r`ra�ERROR_ALREADY_EXISTSrcrdrerf)rrrkrFrGrlrns       rrqrq:s����)��x�	�4�(�(�(��2�4�4�J��-�H����D��$��n�&9�:�:�D��'�'��e�4�4�4��&�&�q�$��2�2�2���!�)�Z�8�8�8�8��������<�8�8�8�8��%�,���i���N�N�N��	����������4s�B$�$C5�3=C0�0C5c��ttd��r!ttd��||��dStj||��dS)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  rrxrxYsT���r�9����	���I���s�C�(�(�(�(�(�	�	�#�s�����rc��|}tstjdkrbtj�|��}tj�|��r"td�|�����|Sg}tj�|��r�|}tj	|��}tj�
|��s=tj�tj�|��|��}||vr"td�|�����|�
|��tj�|����tj�|��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�jsC���M���S�%��/�/��w���	�*�*��
�7�>�>�$���	S��;�B�B�=�Q�Q�R�R�R���!#�O�
�'�.�.��
#�
#�*��	��K�	�*�*�	��w�}�}�Y�'�'�	L�����R�W�_�_�Y�%?�%?��K�K�I���'�'��;�B�B�=�Q�Q�R�R�R����y�)�)�)�
�'�.�.��
#�
#�*��7�?�?�9�%�%�%rr�c��tj|��}ts|�d��s|St	|��dkr
|dd�Std���)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��s`���;�y�!�!�D�������3�3�����4�y�y�3����A�B�B�x��
�J�
K�
K�Krr�c��tr>tj�|��otj|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��sB���A��w�~�~�d�#�#�@��	�$���(@�(@�@��d�#�#�#rc	��trEttjt	j|��j��tjz��Stj|tj	��}|�
��}t|�tjtj
tjd��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�rFrls   r�has_world_permissionsr��s����H��D�L������!6�7�7�$�,�F�G�G�G��,�T�=�3Z�[�[�H��-�-�/�/�D���.�.�$�3�$�4�#�9�)�D�D�0�0�����r�old_key�	base_modec���trdtjtj|��j��tjtjztjztjzz}||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��s]���$��L����!1�!1�!9�:�:��\�D�L�0�4�<�?�$�,�N�P���8�#�#��r�path1�path2c�t�trFtj|��}tj|��}|j|jf|j|jfkStj|t
j��}|���}tj|t
j��}|���}||kS)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����P��������������
�v�}�-�&�-���1O�O�O��-�e�]�5]�^�^�I��0�0�2�2�E��-�e�]�5]�^�^�I��0�0�2�2�E��E�>�r�min_modec�B�tr"tj|��j}|||zkSt	|��}tj|t
jt
jz��}|�	��}|�
��}t||��}t|�
����D]`}|�|��}|d}	|d}|�t
jt
j|d���}
|
|
|	zkrdS�adS)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
    rN�r�FT)rrr.r8r�rArBrCr�rDr�rW�range�GetAceCount�GetAcer�r�r�)r�r�r8rFrGrl�min_dacl�index�min_acer�effective_masks           r�has_min_permissionsr��s+���-��'�$�-�-�'���'�H�,�,�,��D�>�>�D��,��m�6��9`�`�b�b�H��.�.�0�0�D��-�-�/�/�D��d�H�-�-�H��x�+�+�-�-�.�.�����/�/�%�(�(���q�z���q�z���7�7�(�7�(�8��9
�9
�����^�d�2�2�2��5�5�3��4rc�V�tj�|��sdStj|tj��}|���}|�tjtj	t��d���}|tjztjkS)NFr�)
rr�r�rArBr�r�r�r�r�rE�
ntsecuritycon�FILE_GENERIC_EXECUTE)r�rFrlrs    rr�r�,s���
�7�>�>�$�����u��,�T�=�3Z�[�[�H��-�-�/�/�D��)�)�$�3�$�4�'�)�)�+�+���D��-�4�4�
�8Z�Z�Zrc��t|��}tj|tj��}|���}t||��}|�d|d��tj|tj|��dS)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.
    rNrN)	r�rArBrCrDrWrY�SetFileSecurityr�)rrrFrGrls     rrr<s�����#�#�I��,�Y�
�8`�a�a�H��.�.�0�0�D��$��%�%�D�
�&�&�q�$��2�2�2��!�)�]�-T�V^�_�_�_�_�_r�user_sidc�l�|r|d|z
z}t|��}tjd��}tjd��}tjd��}tj��}|||fvr8t	|d��}|r!|�tj||��t	|d��}	|	r!|�tj|	|��t	dddd���}
|�tj|
|��|�tj|
|��|S)	NrKzS-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�everyonerl�
user_flags�everybody_flags�full_permissionss           rrWrWOs>���%��u�t�|�$���T�"�"�H�
�
0��
<�
<�F�
�
0��
@�
@�F��2�9�=�=�H�����D����'�'�'�,�X�f�-=�>�>�
��	W��$�$�]�%?��X�V�V�V�.�h�u�o�>�>�O��X�� � ��!;�_�h�W�W�W�/��t�X\�/]�/]�^�^�����]�7�9I�6�R�R�R����]�7�9I�6�R�R�R��Krc��|tjz|tjz|tjzd�|tjz|tjz|tjzd�d�S)Nr�)rGr�)r.�S_IRUSR�S_IWUSR�S_IXUSRr��S_IWOTH�S_IXOTH)rs rr�r�sse���4�<�'��D�L�(��d�l�*�
�
��4�<�'��D�L�(��d�l�*�
�
�
��rc�4�t|��}tj|tj��}|���}tj|tj��}|�|d��tj|tj|��dS�NF)r�rArBrCrDrXr�)r(r)�security_src�user_src�security_dsts     rr2r2�s��
�3�-�-�C� �0��m�6^�_�_�L��6�6�8�8�H� �0��m�6^�_�_�L��+�+�H�e�<�<�<��!�#�}�'O�Q]�^�^�^�^�^rc�6�t|��}tj|tj��}|���}tj|tj��}|�d|d��tj|tj|��dS)NrNr)r�rArBr�r�rYr�)r(r)r�rlr�s     rr9r9�s���
�3�-�-�C�!�0��m�6]�^�^�L��1�1�3�3�D� �0��m�6]�^�^�L��*�*�1�d�A�6�6�6��!�#�}�'N�P\�]�]�]�]�]r�rights_descc���d}|dr|tjz}|dr)|tjtjztjzz}|dr|tjz}|S)Nrr�r�r�)r��FILE_GENERIC_READ�FILE_ALL_ACCESSr�)r��flags  rr�r��sv��$
�D��6��6��m�5�5���7��=��}�4�&�8�9�&�;�<�=���9��9��m�8�8���Krc��t|��}tj|tjtjz��}|���}|���}|sdSt||��}t||��Sr�)	r�rArBrCr�r�rDrW�_compare_dacls)rrrFrlrG�ref_dacls      rr=r=�s�����#�#�I��,�Y�
�8`�/<�/V�9W�X�X�H��-�-�/�/�D��.�.�0�0�D����u��d�D�)�)�H��$��)�)�)r�dacl1�dacl2c�����fd�t������D���fd�t������D��kS)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.
    c�:��g|]}��|����Sr�r�)�.0r�r�s  �r�
<listcomp>z"_compare_dacls.<locals>.<listcomp>��%���I�I�I�U�U�\�\�%�
 �
 �I�I�Irc�:��g|]}��|����Srr�)r�r�r�s  �rr�z"_compare_dacls.<locals>.<listcomp>�r�r)r�r�)r�r�s``rr�r��si����

J�I�I�I�e�E�4E�4E�4G�4G�.H�.H�I�I�I�I�I�I�I�e�E�4E�4E�4G�4G�.H�.H�I�I�I�
J�Krc��d�tj��tj����}t	jd|��dS)z=
    Return the pySID corresponding to the current user.
    z{0}\{1}Nr)r��win32api�
GetDomainName�GetUserNamerA�LookupAccountName)�account_names rrErE�sE���$�$�X�%;�%=�%=�x�?S�?U�?U�V�V�L��*�4��>�>�q�A�Ar)TT)rK)N):r�
__future__r�
contextlibrrdrr.r�typingrrrrr	r�r_r�rRrZrArar�ImportErrorrr#�str�intrr"r'r�r6r:r>rHrJrOrprqrxr�r�r�r�r�r�r�r�rrWr�r2r9r�r=r�rErrr�<module>rs���A�A�&�&�&�&�&�&�%�%�%�%�%�%�����	�	�	�	�����
�
�
�
�����������������������������������������O�O�O��O�O�O����������O�O�O��J�J�������J�J�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�	B�	B�B�B�C�B��B�3�B�3�B�B�B�B�J����3��4�����@��S���������>���3��4�����"&��&��&�&�&�&�DL��L��L�L�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�K�K�K�B�3�B�B�B�B�B�Bs�A�A'�&A'