HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/duplicity/backends/__pycache__/ssh_paramiko_backend.cpython-310.pyc
o

�&�`tO�@sddlmZddlmZddlmZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddlZddlmZddlmZdd	lmZdd
lmZdZGdd
�d
ejj�Zej�de�ej�de�ej�de�ej�de�ejj�gd��dS)�)�division)�input)�oct)�zipN)�hexlify)�progress)�config)�util)�BackendExceptionicc@sJeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zddd�Z	dd�Z
dS)�SSHParamikoBackenda�This backend accesses files using the sftp or scp protocols.
    It does not need any local client programs, but an ssh server and the sftp
    program must be installed on the remote side (or with scp, the programs
    scp, ls, mkdir, rm and a POSIX-compliant shell).

    Authentication keys are requested from an ssh agent if present, then
    ~/.ssh/id_rsa/dsa are tried. If -oIdentityFile=path is present in
    --ssh-options, then that file is also tried. The passphrase for any of
    these keys is taken from the URI or FTP_PASSWORD. If none of the above are
    available, password authentication is attempted (using the URI or
    FTP_PASSWORD).

    Missing directories on the remote side will be created.

    If scp is active then all operations on the remote side require passing
    arguments through a shell, which introduces unavoidable quoting issues:
    directory and file names that contain single quotes will not work.
    This problem does not exist with sftp.
    cs�tjj�||�d|_|jrt�dd|jd�|_nd|_t	�
��t	�d�zddlaWnt
y4�wWd�n1s?wYG�fdd	�d	tj�}Gd
d�dtj��t��|_|j�|��|j�d�tj�d�}t�tj�}|�t�d
��|�|�t�d���}|dkr�tj}n|dkr�tj }n|dkr�tj!}n|dkr�tj"}ntj#}|�$|�d}t�%dt&j'tj(�}|dur�|�)d�r�|�)d�n|�)d�}zt*j�+|�r�|j�,|�Wnt-y�}	zt.d|�d���d}	~	wwt*j�/d�}
t�%dt&j'tj(�}|du�r|�)d��r|�)d�n|�)d�}
zt*j�+|
��r&|j�0|
�n|
|j_1Wnt-�y@}	zt.d|
�d���d}	~	ww	d|j2i|_&|j&�3|�4d|j2��|j&�3|�4d|j2��|j5�rk|j&�3d|j5i�d|j&v�r{|j&�3dt6�7�i�|j8�r�|j&�3d|j8i�d|j&v�r�|j&�3dt9|j&d�i�n|j&�3ddi�t�%dt&j'tj(�}|du�r�|�)d��r�|�)d�n|�)d�}|�:d �|j&d!<d!|j&v�r�t;|j&d!t<��s�|j&d!g|j&d!<d"d#�|j&d!D�|j&d!<nd|j&d!<t&j=|_>|j&d|_5|j&d|_2|�?�}z|jj@|j&d|j&d|j&d|d$d$|j&d!d%�Wn t-�yD}	zt.d&|j&d|j&d|j&d|	f��d}	~	ww|j�A��Bt9t&jCd'��tj�D|jEd(�|_E|jEd)k|_F|jF�r~t�%d*|j��rqt.d+��|�Gd,|jfd-d.�dSz|j�H�|_IWnt-�y�}	zt.d/|	��d}	~	ww|j�Jt*jK�}
tL|
�dk�r>|
ddk�r�d0|
d<|
D]�}|dk�r��q�z|jI�M|�}WnPtN�y}	zC|	jOtOjPk�r�z|jI�Q|�Wn-t-�y�}	zt.d1|jI�Rd�d0||	f��d}	~	wwt.d2|jI�Rd�d0||	f��WYd}	~	nd}	~	wwz	|jI�S|�W�q�t-�y=}	zt.d3|jI�Rd�d0||	f��d}	~	wwdSdS)4N�
z^/���.�ignorercseZdZdZ�fdd�ZdS)z4SSHParamikoBackend.__init__.<locals>.AgreedAddPolicyz�
            Policy for showing a yes/no prompt and adding the hostname and new
            host key to the known host file accordingly.

            This class simply extends the AutoAddPolicy class with a yes/no
            prompt.
            c
s�t|���}d�dd�tt|ddd�|ddd���D��}d||����|f}	tj�	|�t
���}|dvrEtj
�||||�dS|d	vrM�|��d
}q+)N�:css �|]\}}t||�VqdS)N)�str)�.0�a�b�r�I/usr/lib/python3/dist-packages/duplicity/backends/ssh_paramiko_backend.py�	<genexpr>is�zXSSHParamikoBackend.__init__.<locals>.AgreedAddPolicy.missing_host_key.<locals>.<genexpr>�rz�The authenticity of host '%s' can't be established.
%s key fingerprint is %s.
Are you sure you want to continue connecting (yes/no)? T)�yes�y)�no�nzPlease type 'yes' or 'no': )r�get_fingerprint�join�listr�get_name�upper�sys�stdout�writer�lower�paramiko�
AutoAddPolicy�missing_host_key)�self�client�hostname�key�fp�fingerprint�question�choice��AuthenticityExceptionrrr)gs(2
��

��zESSHParamikoBackend.__init__.<locals>.AgreedAddPolicy.missing_host_keyN)�__name__�
__module__�__qualname__�__doc__r)rr2rr�AgreedAddPolicy_sr8c@seZdZdd�ZdS)z:SSHParamikoBackend.__init__.<locals>.AuthenticityExceptioncSstj�|d|�dS)Nz+Host key verification for server %s failed.)r'�SSHException�__init__)r*r,rrrr:|s
��zCSSHParamikoBackend.__init__.<locals>.AuthenticityException.__init__N)r4r5r6r:rrrrr3{sr3�
sshbackendzssh: %(message)s�	duplicity���	z/etc/ssh/ssh_known_hostsa;
                      ^(?:.+\s+)?
                      (?:-oGlobalKnownHostsFile=)
                      (
                          ([\"'])
                          ([^\\2]+)
                          \\2
                          |
                          [\S]+
                      )
                      �zcould not load z, maybe corrupt?z~/.ssh/known_hostsa9
                      ^(?:.+\s+)?
                      (?:-oUserKnownHostsFile=)
                      (
                          ([\"'])
                          ([^\\2]+)
                          \\2
                          |
                          [\S]+
                      )
                      r,z/etc/ssh/ssh_configz
~/.ssh/config�user�port�a
                      ^(?:.+\s+)?
                      (?:-oIdentityFile=|-i\s+)
                      (([\"'])
                      (
                          [^\\2]+)\\2
                          |
                          [\S]+
                      )
                      z'"�identityfilecSsg|]}tj�|��qSr)�os�path�
expanduser)r�irrr�
<listcomp>s�z/SSHParamikoBackend.__init__.<locals>.<listcomp>T)r,rB�username�password�allow_agent�
look_for_keys�key_filenamez%ssh connection to %s@%s:%d failed: %srr'�scp�'z9cannot handle directory names with single quotes with scpz
mkdir -p '%s'Fz
scp mkdir zsftp negotiation failed: %s�/zsftp mkdir %s failed: %szsftp stat %s failed: %szsftp chdir to %s failed: %s)Tr<�backend�Backendr:�retry_delayrF�re�sub�
remote_dir�warnings�catch_warnings�simplefilterr'�ImportErrorr(r9�	SSHClientr+�set_missing_host_key_policy�set_log_channelr	�
get_logger�logging�
StreamHandlerr#�stderr�setFormatter�	Formatter�
addHandler�	getLogger�getEffectiveLevel�DEBUG�INFO�WARNING�ERROR�CRITICAL�setLevel�searchr�ssh_options�VERBOSE�grouprE�isfile�load_system_host_keys�	Exceptionr
rG�load_host_keys�_host_keys_filenamer,�update�
gethostconfigrJ�getpass�getuserrB�int�strip�
isinstancer �ssh_askpass�use_getpass�get_password�connect�
get_transport�
set_keepalive�timeout�strip_prefix�scheme�use_scp�	runremote�	open_sftp�sftp�split�sep�len�stat�IOError�errno�ENOENT�mkdir�	normalize�chdir)r*�
parsed_urlr8�ours�dest�plevel�wanted�global_known_hosts�m�e�user_known_hosts�keyfilenamerK�dirs�d�attrsrr2rr:GsH

���


�����
 �����
�
 	�

�
���
���
�������
����zSSHParamikoBackend.__init__c

Cs�t�|�}|jr�t|jd�}z|j����}|�t	j
�|�d|j�Wnt
y7}ztd|��d}~ww|�d�}|dkrJtd|�d���t�|j�}|�dt|j�d	d�|j|f�|�d�}|dkrttd|�d���d
}|j}	||	kr�|�|�d��|��}t�||	�||	ks}|�d�|��|�d�}|dkr�td|�d���|��dS|jj|j|tjd
�dS)N�rbzscp -t '%s'�scp execution failed: %sr�sscp remote error: %b���z
C%s %d %s
���ri@zscp remote error: %s)�callback)r	�fsdecoder��open�namer+r��open_session�
settimeoutrr��exec_commandrWrtr
�recvrEr��sendr�st_mode�st_size�sendall�read�tellr�report_transfer�closer��put)
r*�source_path�remote_filename�f�chanr��response�fstat�file_pos�	file_sizerrr�_putKsF
��
�
�

zSSHParamikoBackend._putc
Cs�t�|�}|jr�z|j����}|�tj�|�	d|j
|f�Wnty3}ztd|��d}~ww|�
d�|�d�}t|t�rG|��}t�d|�}|dusX|�d�|kr`td||f��|�d�t|�d	��}|}t|jd
�}	|�
d�z#|dkr�|tkr�t}
n|}
|�|
�}|	�|�|t|�8}|dks~Wnty�}ztd||f��d}~ww|�d�}|d
kr�td||�d�f��|	��|�
d�|��dS|j�||j�dS)Nzscp -f '%s/%s'r��r�zC([0-7]{4})\s+(\d+)\s+(\S.*)$r@z*scp get %s failed: incorrect response '%s'rr�wbrzscp get %s failed: %sr�)r	r�r�r+r�r�r�rr�r�rWrtr
r�r�r}�bytes�decoderU�matchrqr{r�r��read_blocksizer%r�r�r��get)r*r��
local_pathr�r��msgr��size�togor��	blocksize�buffrrr�_getrsb

���


�



����
�
zSSHParamikoBackend._getcCs,|jr|�d|jdd�}|��S|j��S)Nz
ls -1 '%s'Fzscp dir listing )r�r�rW�
splitlinesr��listdir)r*�outputrrr�_list�s�
zSSHParamikoBackend._listcCs<t�|�}|jr|�d|j|fdd�dS|j�|�dS)Nz
rm '%s/%s'Fzscp rm )r	r�r�r�rWr��remove)r*�filenamerrr�_delete�s
�zSSHParamikoBackend._deleteFr
c	
Cslz|j�|dtj�\}}}|�d�}|WSty5}z|s*td||t�|�f��WYd}~dSd}~ww)z�small convenience function that opens a shell channel, runs remote
        command and returns stdout of command. throws an exception if exit
        code!=0 and not ignoredr�z%sfailed: %s 
 %sN)	r+r�rr�r�rtr
r	�uexc)	r*�cmd�ignoreexitcode�errorprefix�ch_in�ch_out�ch_errr�r�rrrr��s
����zSSHParamikoBackend.runremotec
Csftj�|�}tj�|�siSt��}z	|�t|��Wnty-}zt	d|��d}~ww|�
|�S)Nz#could not load '%s', maybe corrupt?)rErFrGrrr'�	SSHConfig�parser�rtr
�lookup)r*�file�host�	sshconfigr�rrrrx�s��
z SSHParamikoBackend.gethostconfigN)Fr
)r4r5r6r7r:r�r�r�r�r�rxrrrrr3s'0


rr�rO�
paramiko+sftp�paramiko+scp)r�rOr�r�)�
__future__r�builtinsrrrr�ryr`rErUr#rX�binasciir�duplicity.backendr<rrr	�duplicity.errorsr
r�rRrSr�register_backend�uses_netloc�extendrrrr�<module>s6"