o
    Þý°jE5  ã                   @   sž  d dl mZmZmZmZ d dlZd dlZd dlZd dl	Zd dl
Zd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZG dd„ dejjƒZG dd„ dejjƒZG dd„ dejjƒZG d	d
„ d
ƒZd dddddddejjf	dej j!de"dB de"e#B dB de"dB de"dB de"dB deej$j% dB dedej&j'dB dej&j'e(B deej)j*e"dB f fdd„Z+dej)j,de"dB fdd„Z-dS )é    )ÚAnyÚListÚTupleÚcastNc                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚTransferErrorz.A zone transfer response got a non-zero rcode.c                    s(   dt j |¡› �}tƒ  |¡ || _d S )NzZone transfer error: )ÚdnsÚrcodeÚto_textÚsuperÚ__init__)Úselfr   Úmessage©Ú	__class__© úz/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/dns/xfr.pyr   *   s   
zTransferError.__init__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   r   r   r   '   s    r   c                   @   ó   e Zd ZdZdS )ÚSerialWentBackwardsz:The current serial number is less than the serial we know.N©r   r   r   r   r   r   r   r   r   0   ó    r   c                   @   r   )ÚUseTCPz'This IXFR cannot be completed with UDP.Nr   r   r   r   r   r   4   r   r   c                	   @   sh   e Zd ZdZejjddfdejjdejj	de
dB defdd	„Zd
ejjdefdd„Zdd„ Zdd„ ZdS )ÚInboundz+
    State machine for zone transfers.
    NFÚtxn_managerÚrdtypeÚserialÚis_udpc                 C   s–   || _ d| _|| _|tjjkr|du rtdƒ‚d| _n|tjjkr+|r'tdƒ‚d| _ntdƒ‚|| _	|| _
| ¡ \}}| _d| _d| _d| _d| _dS )aq  Initialize an inbound zone transfer.

        *txn_manager* is a :py:class:`dns.transaction.TransactionManager`.

        *rdtype* can be `dns.rdatatype.AXFR` or `dns.rdatatype.IXFR`

        *serial* is the base serial number for IXFRs, and is required in
        that case.

        *is_udp*, a ``bool`` indidicates if UDP is being used for this
        XFR.
        Nz,a starting serial must be supplied for IXFRsTzis_udp specified for AXFRFzrdtype is not IXFR or AXFR)r   Útxnr   r   Ú	rdatatypeÚIXFRÚ
ValueErrorÚincrementalÚAXFRr   r    Úorigin_informationÚoriginÚsoa_rdatasetÚdoneÚexpecting_SOAÚdelete_mode)r   r   r   r   r    Ú_r   r   r   r   =   s&   
zInbound.__init__r   Úreturnc                 C   sF  | j du r| j | j ¡| _ | ¡ }|tjjkrt|ƒ‚t|j	ƒdkrA|j	d j
| jkr2tj d¡‚|j	d j| jkrAtj d¡‚d}| jdu r´|jrT|jd j
| jkrZtj d¡‚|jd }|}|jtjjkrntj d¡‚d}| ¡ | _| jr´| jdusJ ‚ttjjjj| jd ƒ}|j| jkr•d| _ntj |j¡| jk r¡t‚| jr±t|j|d… ƒdkr±t‚d| _|j|d… D ]Ö}|j
}|}| jrËtj d	¡‚| j dusÒJ ‚|jtjjk�re|| jk�re| jrè| j | _|| jk�r.| jrõ| j�r.ttjjjj|d ƒ}| j�r
tj d
¡‚| j�r| j|jk�rtj d¡‚| j  ||¡ | j   ¡  d| _ d| _n6d| _ttjjjj|d ƒ}| j�r^| j�rR|j| jk�rQtj d¡‚n|j| _| j  ||¡ ntj d¡‚q»| j�r~d| _d| _d| _| j  !¡  | j d¡| _ | j�rŠ| j  "||¡ q»| j  #||¡ q»| j�r | j�s tj d¡‚| jS )aZ  Process one message in the transfer.

        The message should have the same relativization as was specified when
        the `dns.xfr.Inbound` was created.  The message should also have been
        created with `one_rr_per_rrset=True` because order matters.

        Returns `True` if the transfer is complete, and `False` otherwise.
        Nr   zwrong question namezwrong question rdatatypez&No answer or RRset not for zone originzfirst RRset is not an SOAé   Tzanswers after final SOAzempty IXFR sequencezunexpected end of IXFR sequenceFzIXFR base serial mismatchzunexpected origin SOA in AXFRzunexpected end of UDP IXFR)$r!   r   Úwriterr%   r   r   ÚNOERRORr   ÚlenÚquestionÚnamer(   Ú	exceptionÚ	FormErrorr   r)   Úanswerr"   ÚSOAÚcopyr   ÚrdtypesÚANYr   r*   ÚSerialr   r    r   r+   r,   ÚreplaceÚcommitÚrollbackÚdelete_exactÚadd)r   r   r   Úanswer_indexÚrrsetÚrdatasetÚsoar4   r   r   r   Úprocess_messagee   sœ   
	



ÿÿ
ÿÿ
zInbound.process_messagec                 C   s   | S )Nr   )r   r   r   r   Ú	__enter__ü   s   zInbound.__enter__c                 C   s   | j r| j  ¡  dS )NF)r!   r?   )r   Úexc_typeÚexc_valÚexc_tbr   r   r   Ú__exit__ÿ   s   
zInbound.__exit__)r   r   r   r   r   r"   r&   ÚtransactionÚTransactionManagerÚ	RdataTypeÚintÚboolr   r   ÚMessagerF   rG   rK   r   r   r   r   r   8   s$    ûþýü
û( r   r   r   Úuse_ednsÚ	ednsflagsÚpayloadÚrequest_payloadÚoptionsÚkeyringÚkeynameÚkeyalgorithmr.   c
                 C   sb  |   ¡ \}
}}|
du rtdƒ‚|du rtjj}nTt|tƒs!tdƒ‚|dkr[|  ¡ �)}| |d¡}|rEt	tj
jjj|d ƒ}|j}tjj}nd}tjj}W d  ƒ n1 sUw   Y  n|dkrh|dk rhtjj}ntdƒ‚|  ¡ }tj |
|||d||||¡	}|dur¡tj |dd	|› d
�¡}|j|j|
|tjjdd�}| |d¡ |dur­|j|||	d� ||fS )a  Make an AXFR or IXFR query.

    *txn_manager* is a ``dns.transaction.TransactionManager``, typically a
    ``dns.zone.Zone``.

    *serial* is an ``int`` or ``None``.  If 0, then IXFR will be
    attempted using the most recent serial number from the
    *txn_manager*; it is the caller's responsibility to ensure there
    are no write transactions active that could invalidate the
    retrieved serial.  If a serial cannot be determined, AXFR will be
    forced.  Other integer values are the starting serial to use.
    ``None`` forces an AXFR.

    Please see the documentation for :py:func:`dns.message.make_query` and
    :py:func:`dns.message.Message.use_tsig` for details on the other parameters
    to this function.

    Returns a `(query, serial)` tuple.
    Nzno zone originzserial is not an integerr   r8   l        zserial out-of-rangeFz. . z 0 0 0 0T)Úcreate)Ú	algorithm)r'   r$   r   r"   r&   Ú
isinstancerO   ÚreaderÚgetr   r:   r;   r8   r   r#   Ú	get_classr   Ú
make_queryÚrdataÚ	from_textÚ
find_rrsetÚ	authorityrA   Úuse_tsig)r   r   rR   rS   rT   rU   rV   rW   rX   rY   Úzone_originr-   r(   r   r!   rD   rE   ÚrdclassÚqra   rC   r   r   r   r`     sV   



€ø€	
÷ÿr`   Úqueryc                 C   s~   t | tjjƒstdƒ‚| jd }|jtjjkrdS |jtjj	kr$tdƒ‚|  
| j|j|jtjj¡}ttjjjj|d ƒ}|jS )a7  Extract the SOA serial number from query if it is an IXFR and return
    it, otherwise return None.

    *query* is a dns.message.QueryMessage that is an IXFR or AXFR request.

    Raises if the query is not an IXFR or AXFR, or if an IXFR doesn't have
    an appropriate SOA RRset in the authority section.
    zquery not a QueryMessager   Nzquery is not an AXFR or IXFR)r\   r   r   ÚQueryMessager$   r3   r   r"   r&   r#   rc   rd   r4   rg   r8   r   r:   r;   r   )ri   r3   Ú	soa_rrsetrE   r   r   r   Úextract_serial_from_queryP  s   	
ÿrl   ).Útypingr   r   r   r   Údns.ednsr   Údns.exceptionÚdns.messageÚdns.nameÚ	dns.rcodeÚ	dns.rdataÚdns.rdatasetÚdns.rdatatypeÚdns.rdtypesÚdns.rdtypes.ANYÚdns.rdtypes.ANY.SMIMEAÚdns.rdtypes.ANY.SOAÚdns.rdtypes.svcbbaseÚ
dns.serialÚdns.transactionÚdns.tsigÚdns.zoner5   ÚDNSExceptionr   r6   r   r   r   ÚtsigÚdefault_algorithmrL   rM   rO   rP   ÚednsÚOptionr4   ÚNameÚstrr   rj   r`   rQ   rl   r   r   r   r   Ú<module>   sp   	 Pöÿþ
ýüûúùø
	÷

ö
õK