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__/webdavbackend.cpython-310.pyc
o

�~�_O�@s:ddlmZe��ddlmZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlZ
ddlZ
ddlZ
ddlZddlZddlmZddlmZddlmZddlmZmZGd	d
�d
e
jj�ZGdd�dejj�ZGd
d�dej j!�Z"ej �#de"�ej �#de"�ej �#de"�ej �#de"�ej j$�%gd��dS)�)�standard_library)�str)�rangeN)�config)�log)�util)�BackendException�FatalBackendExceptionc@s eZdZdZdd�Zdd�ZdS)�CustomMethodRequestz�
    This request subclass allows explicit specification of
    the HTTP request method. Basic urllib.request.Request class
    chooses GET or POST depending on self.has_data()
    cOs&||_tjjj|g|�Ri|��dS�N)�method�urllib�request�Request�__init__)�selfr�args�kwargs�r�B/usr/lib/python3/dist-packages/duplicity/backends/webdavbackend.pyr3s zCustomMethodRequest.__init__cCs|jSr)r�rrrr�
get_method7szCustomMethodRequest.get_methodN)�__name__�
__module__�__qualname__�__doc__rrrrrrr
-sr
c@s$eZdZdd�Zdd�Zdd�ZdS)�VerifiedHTTPSConnectioncOs�z
ddladdlaWn
tyttd���wtjjj|g|�Ri|��t	j
|_gd�|_|jsI|jD]}t
j�|�}t
j�|�rH||_nq5|jr]t
�|jt
j�s_ttd�|j��dSdS)Nrz%Missing socket or ssl python modules.)z~/.duplicity/cacert.pemz~/duplicity_cacert.pemz/etc/duplicity/cacert.pemz*Cacert database file '%s' is not readable.)�socket�ssl�ImportErrorr	�_�http�client�HTTPSConnectionrr�ssl_cacert_file�cacert_file�cacert_candidates�os�path�
expanduser�isfile�access�R_OK)rrrr(rrrr<s*�

���z VerifiedHTTPSConnection.__init__cCs�t�|j|jf|j�}|jr||_|��dtt	�vr2t	j
t	jj|j
tjd�}|j||jd�|_dStjr;ttd���|j
sJttd�d�|j���t	j|t	j|j
d�|_dS)N�create_default_context)�cafile�capath)�server_hostnamezHOption '--ssl-cacert-path' is not supported with python 2.7.8 and below.aFor certificate verification with python 2.7.8 or earlier a cacert database
file is needed in one of these locations: %s
Hints:
Consult the man page, chapter 'SSL Certificate Verification'.
Consider using the options --ssl-cacert-file, --ssl-no-check-certificate .z, )�	cert_reqs�ca_certs)r�create_connection�host�port�timeout�_tunnel_host�sock�tunnel�dirrr-�Purpose�SERVER_AUTHr%r�ssl_cacert_path�wrap_socketr	r �joinr&�
CERT_REQUIRED)rr8�contextrrr�connectWs0�
��
�	�zVerifiedHTTPSConnection.connectc
OsRztjjj|g|�Ri|��WStjy(}ztdt�|�t	j
j��d}~ww)NzSSL failed: %s)r!r"r#rr�SSLErrorrr�uexcr�	ErrorCode�
backend_error)rrr�errrr{s���zVerifiedHTTPSConnection.requestN)rrrrrBrrrrrr;s$rc@s�eZdZdZ	dZ	dd�Zdd�Zdd�Zd	d
�Zd*dd
�Z	dd�Z
d+dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�ZdS),�
WebDAVBackendz}Backend for accessing a WebDAV repository.

    webdav backend contributed in 2006 by Jesper Zedlitz <jesper@zedlitz.de>
    z_<?xml version="1.0"?><D:propfind xmlns:D="DAV:"><D:prop><D:resourcetype/></D:prop></D:propfind>cCs�tjj�||�ddi|_||_d|_d|_|j|_|�	�|_
|�|j�|_
t�td�tjf�t�td�|j|jf�t�td�|j
f�d|_dS)N�
Connectionz
keep-alivezUsing WebDAV protocol %szUsing WebDAV host %s port %szUsing WebDAV directory %s)�	duplicity�backend�Backendr�headers�
parsed_url�digest_challenge�digest_auth_handler�username�get_password�password�
sanitize_pathr(�	directoryr�Infor r�webdav_proto�hostnamer5�conn)rrNrrrr�s

�
zWebDAVBackend.__init__cCs"|rt�d�}|�d|d�SdS)Nz/+�/)�re�compile�sub)rr(�foldpathrrrrT�s
zWebDAVBackend.sanitize_pathcCs(d}|D]
}|j|jkr||j}q|S)N�)�nodeType�	TEXT_NODE�data)r�nodelist�rc�noderrr�getText�s
�zWebDAVBackend.getTextcCs|jdd�dS)NT)�forced)rBrrrr�_retry_cleanup�szWebDAVBackend._retry_cleanupFcCs�|s|jr|jj|jjkrdSt�td�|jj�|��|jjdvr2t	j
�|jj|jj�|_dS|jjdvrUt
jrIt	j
�|jj|jj�|_dSt|jj|jj�|_dSttd�|jj��)z�
        Connect or re-connect to the server, updates self.conn
        # reconnect on errors as a precaution, there are errors e.g.
        # "[Errno 32] Broken pipe" or SSl errors that render the connection unusable
        Nz WebDAV create connection on '%s')�webdavr!)�webdavs�httpszWebDAV Unknown URI scheme: %s)rYr4rNrXrrVr �_close�schemer!r"�HTTPConnectionr5r�ssl_no_check_certificater#rr	)rrgrrrrB�s
zWebDAVBackend.connectcCs|jr
|j��dSdSr)rY�closerrrrrl�s�zWebDAVBackend._closeNrcCs�|��|��tj�|d�}|jdur|�|�|jd<t�	t
d�|||jf�t�	t
d�tt|���|j
�||||j�|j
��}t�	t
d�|j|jf�|jdvr�|dkr�|�d	d�}|��|r�t�t
d
�tj�|��|dkr~tt
d���tj�|�|_|�|jj�|_|�||j||d
�Stt
d���|jdkr�|��|��|�||�|jd<t�	t
d��t�	t
d�|||jf�t�	t
d�tt|���|j
�||||j�|j
��}t�	t
d�|j|jf�|S)zi
        Wraps the connection.request method to retry once if authentication is
        required
        z/:~N�
Authorizationz&WebDAV %s %s request with headers: %s zWebDAV data length: %s z+WebDAV response status %s with reason '%s'.)i-i.�PROPFIND�locationzWebDAV redirect to: %s �
z&WebDAV redirected 10 times. Giving up.�z4WebDAV missing location header in redirect response.i�z3WebDAV retry request with authentification headers.z'WebDAV %s %s request2 with headers: %s z,WebDAV response2 status %s with reason '%s'.) rlrBr
�parse�quoterO�get_digest_authorizationrMrrVr �lenrrYr�getresponse�status�reason�	getheaderrp�Notice�unquoter	rJrK�	ParsedUrlrNrTr(rU�read�get_authorization)rrr(rb�
redirected�quoted_path�response�redirect_urlrrrr�s@



zWebDAVBackend.requestc
Cs�z|�dd�}|�dd�\}}Wn
tyYdSw|�d�d��dkr^z|��WSty?t�td	��|�	�YSt
y]}zt�td
�|�|�	�WYd}~Sd}~ww|��dkrh|�	�S|�|�|_|�
|�S)zY
        Fetches the auth header based on the requested method (basic or digest)
        zwww-authenticater_� ruN�,r�	negotiatezkpython-kerberos needed to use kerberos                           authorization, falling back to basic auth.zWKerberos authorization failed: %s.                          Falling back to basic auth.�basic)r}�split�
ValueError�lower�get_kerberos_authorizationrr�Warnr �get_basic_authorization�	Exception�parse_digest_challengerOrx)rr�r(�auth_hdr�token�	challengerGrrrr��s.�

���
zWebDAVBackend.get_authorizationcCstj�tj�|��Sr)r
r�parse_keqv_list�parse_http_list)r�challenge_stringrrrr�sz$WebDAVBackend.parse_digest_challengecCs<ddl}|�d|jj�\}}|�|d�|�|�}d|S)NrzHTTP@%sr_zNegotiate %s)�kerberos�authGSSClientInitrYr4�authGSSClientStep�authGSSClientResponse)rr�r �ctx�tgtrrrr�s

z(WebDAVBackend.get_kerberos_authorizationcCs*d|j|jf}dt�|�������S)z/
        Returns the basic auth header
        �%s:%szBasic %s)rQrS�base64�	b64encode�encode�strip�decode)r�auth_stringrrrr�sz%WebDAVBackend.get_basic_authorizationc	Cs�|j}|jdur tj��}|�d|jj|j|j	�tj�
|�|_|jdkr'dp(d}|jr4d|j
|jfp6|j
}d|||f}t|jj|�}|j�||j�}d|S)z0
        Returns the digest auth header
        Nrjrkr!r�z	%s://%s%sz	Digest %s)rNrPr
r�HTTPPasswordMgrWithDefaultRealm�add_passwordrYr4rQrS�HTTPDigestAuthHandlerrmr5rXr
�_methodr�rO)	rr(�u�
pw_managerrmrX�	dummy_url�	dummy_reqr�rrrrx%s

�z&WebDAVBackend.get_digest_authorizationc

Cs2d}z�zd|jd<|�d|j|j�}|jd=|jdkr.|��|��gWW|r-|��SS|jdvr<|��}|��n|j}|j}|��t	d||f��t
�d|f�tj
j�|�}g}|�d�|�d	�D]}|�|�}|rw|�|�qi|WW|r�|��SSty�}	z|	�d}	~	ww|r�|��ww)
N�1�Depthrr�)����zBad status code %s reason %s.z%szd:hrefzD:href)rMrrU�listbodyr{rp�makedirr�r|rr�Debug�xml�dom�minidom�parseString�getElementsByTagName�
taste_href�appendr�)
rr��documentr{r|r��result�href�filenamerGrrr�_list9sL


�
�


�
����
�zWebDAVBackend._listcCs�|j�d�}|ddkr|dd�}tdt|��D]N}d�|d|d��d}d|jd<|�d|�}|jd=t�d	||j	f�|j	d
krgt�t
d�|�|�d|�}|j	d
krgtt
d�||j	|jf��qdS)z(Make (nested) directories on the server.rZ���r_rrur�r�rrzChecking existence dir %s: %dr�zCreating missing directory %s�MKCOL��zWebDAV MKCOL %s failed: %s %sN)
rUr�rryr?rMrrrVr{r rr|)r�dirs�i�dr��resrrrr�\s$


���zWebDAVBackend.makedircCs�|�|j���}tj�tj�|��}|j}t�	t
d�||f�|jdur9|j|jjks9d|j|jjf}t
|��|�|j�rI|�|jdd�}|SdS)z�
        Internal helper to taste the given href node and, if
        it is a duplicity file, collect it as a result file.

        @return: A matching filename, or None if the href did not match.
        z.WebDAV path decoding and translation: %s -> %sNz�Received filename was in the form of a full url, but the hostname (%s) did not match that of the webdav backend url (%s) - aborting as a conservative safety measure. If this happens to you, please report the problemr_ru)rf�
childNodesr�r
rv�urlparserr(rr�r rXrNr�
startswithrU�replace)rr��raw_filenamerNr��mrrrr�ts$
�
	��zWebDAVBackend.taste_hrefc	
Cs�|jt�|�}d}zQz7|�d�}|�d|�}|jdkr-t�||�|��r(J�|��n|j}|j	}|��t
td�||f��WntyP}z|�d}~wwW|rZ|��dSdS|rc|��ww)N�wb�GETr�z(WebDAV GET Bad status code %s reason %s.)
rUr�fsdecode�openrr{�shutil�copyfileobjrpr|rr r�)	r�remote_filename�
local_path�urlr��target_filer{r|rGrrr�_get�s4


�����
�
�zWebDAVBackend._getc	
Cs�|jt�|�}d}zLz2|�d�}|�d||���}|jdvr(|��|��n|j}|j}|��t	t
d�||f��WntyK}z|�d}~wwW|rU|��dSdS|r^|��ww)N�rb�PUT)r�r���z(WebDAV PUT Bad status code %s reason %s.)rUrr�r�rr�r{rpr|rr r�)	r�source_pathr�r�r��source_filer{r|rGrrr�_put�s2


�����
�
�zWebDAVBackend._putc
Cs�|jt�|�}d}zDz*|�d|�}|jdvr |��|��n|j}|j}|��tt	d�||f��Wnt
yC}z|�d}~wwW|rM|��dSdS|rV|��ww)N�DELETE)r�r�z(WebDAV DEL Bad status code %s reason %s.)rUrr�rr{r�rpr|rr r�)rr�r�r�r{r|rGrrr�_delete�s0

�����
�
�zWebDAVBackend._delete)F)Nr)rrrrr�rrTrfrhrBrlrr�r�r�r�rxr�r�r�r�r�r�rrrrrH�s.

,#%rHr!rkrirj)r!rkrirj)&�futurer�install_aliases�builtinsrrr��http.clientr!r'r[r��urllib.requestr
�urllib.parse�urllib.error�xml.dom.minidomr��duplicity.backendrJrrr�duplicity.errorsrr	rrr
r"r#rrKrLrH�register_backend�uses_netloc�extendrrrr�<module>s8I\