o
    'h3                     @   sr  d dl mZ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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e deeeef  dee dee dee deeejj  dedeej j! deej j!e"f deej#j$ee f fddZ%dej#j&dee fddZ'dS )    )AnyListOptionalTupleUnionNc                       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__ C/var/www/html/olx_land/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   )       r   c                   @   r   )UseTCPz'This IXFR cannot be completed with UDP.Nr   r   r   r   r   r   -   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
e 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   st   || _ d| _|| _|tjjkr|du rtdn|r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 IXFRszis_udp specified for AXFRF)r   txnr   r   	rdatatypeIXFR
ValueErrorr    r!   origin_informationoriginsoa_rdatasetdoneexpecting_SOAdelete_mode)r   r   r   r    r!   _r   r   r   r   6   s    
zInbound.__init__r   returnc                 C   sT  | j du r| jtjjk}| j|| _ | }|tjjkr!t	|t
|jdkrF|jd j| jkr7tjd|jd j| jkrFtjdd}| jdu r|jrY|jd j| jkr_tjd|jd }|}|jtjjkrstjdd}| | _| jtjjkr| jd j| jkrd| _n"tj| jd j| jk rt| jrt
|j|d dkrtd| _|j|d D ]}|j}|}| jrtjd	| j dusJ |jtjjkrj|| jkrj| jtjjkr| j | _|| jkr6| jtjjks| jtjjkr6| jr6| jrtjd
| jtjjkr#| j|d jkr#tjd| j || | j   d| _ d| _n3d| _| jtjjkrc| jrU|d j| jkrTtjdn|d j| _| j || ntjdq| jrtjj| _d| _d| _| j   | jd| _ | jr| j  || q| j !|| q| jr| jst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   r   r#   AXFRr   writerr	   NOERRORr   lenquestionnamer'   	exception	FormErrorr(   answerSOAcopyr$   r    r)   Serialr   r!   r   r*   r+   replacecommitrollbackdelete_exactadd)r   r   replacementr	   answer_indexrrsetrdatasetr4   r   r   r   process_messageY   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	RdataTyper   intboolr   r   MessagerD   rE   rI   r   r   r   r   r   1   s$    
# r   r   r    use_edns	ednsflagspayloadrequest_payloadoptionskeyringkeynamekeyalgorithmr-   c
                 C   sP  |   \}
}}|
du rtd|du rtjj}nKt|ts!td|dkrR|   }||d}|r<|d j	}tjj
}nd}tjj}W d   n1 sLw   Y  n|dkr_|dk r_tjj
}ntd|  }tj|
|||d||||	}|durt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/   
isinstancerM   readergetr    r$   	get_classr   
make_queryrdata	from_text
find_rrset	authorityr8   r?   use_tsig)r   r    rP   rQ   rR   rS   rT   rU   rV   rW   zone_originr,   r'   r   r"   rC   rdclassqr_   rB   r   r   r   r^      sT   





r^   queryc                 C   sl   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}|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)rZ   r   r   QueryMessager%   r3   r   r#   r/   r$   ra   rb   r4   re   r8   r    )rg   r3   soar   r   r   extract_serial_from_queryD  s   	

rj   )(typingr   r   r   r   r   dns.exceptionr   dns.messagedns.name	dns.rcodedns.rdatasetdns.rdatatype
dns.serialdns.transactiondns.tsigdns.zoner5   DNSExceptionr   r6   r   r   r   tsigdefault_algorithmrJ   rK   rM   rN   ednsOptionr4   Namestrr   rh   r^   rO   rj   r   r   r   r   <module>   sb   	 L
	

J