HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/names/__pycache__/authority.cpython-38.pyc
U


W[�@�@s�dZddlmZmZddlZddlZddlmZmZm	Z	ddl
mZddlm
Z
ddlmZmZmZddlmZdd
d�ZGdd
�d
e	j�ZGdd�de�ZGdd�de�ZdS)z
Authoritative resolvers.
�)�absolute_import�divisionN)�dns�error�common)�defer)�failure)�execfile�nativeString�_PY3)�FilePath�/tmp/twisted-names.serialc	Cs�t�d�}t�d�}z4tj�|�sFt|d��}|�|d�W5QRXW5t�|�Xt|d��}|���	�\}}W5QRX||kr�t
|�dp�d}t|d��}|�d||f�W5QRX|d	|f}|S)
ay
    Return a monotonically increasing (across program runs) integer.

    State is stored in the given file.  If it does not exist, it is
    created with rw-/---/--- permissions.

    @param filename: Path to a file that is used to store the state across
        program runs.
    @type filename: L{str}

    @return: a monotonically increasing number
    @rtype: L{str}
    z%Y%m%d��wz 0�r�rz%s %dz%02d)�time�strftime�os�umask�path�exists�open�write�readline�split�int)�filename�serial�o�fZ
serialFileZ
lastSerialZzoneID�r!�9/usr/lib/python3/dist-packages/twisted/names/authority.py�	getSerials

r#c@sheZdZdZejejejfZej	ej
fZdZdZ
dd�Zdd�Zdd�Zdd	d
�Zddd
�Zdd�ZdS)�
FileAuthoritya�
    An Authority that is loaded from a file.

    @ivar _ADDITIONAL_PROCESSING_TYPES: Record types for which additional
        processing will be done.

    @ivar _ADDRESS_TYPES: Record types which are useful for inclusion in the
        additional section generated during additional processing.

    @ivar soa: A 2-tuple containing the SOA domain name as a L{bytes} and a
        L{dns.Record_SOA}.
    NcCs tj�|�|�|�i|_dS�N)r�ResolverBase�__init__�loadFile�_cache)�selfrr!r!r"r'Os
zFileAuthority.__init__cCs
||_dSr%)�__dict__)r*�stater!r!r"�__setstate__UszFileAuthority.__setstate__c
csn||D]`}|j|jkr|jjj}|j�|��d�D]2}|j|jkr4t	j
||jt	j|jpZ||dd�Vq4qdS)aW
        Find locally known information that could be useful to the consumer of
        the response and construct appropriate records to include in the
        I{additional} section of that response.

        Essentially, implement RFC 1034 section 4.3.2 step 6.

        @param answer: A L{list} of the records which will be included in the
            I{answer} section of the response.

        @param authority: A L{list} of the records which will be included in
            the I{authority} section of the response.

        @param ttl: The default TTL for records for which this is not otherwise
            specified.

        @return: A generator of L{dns.RRHeader} instances for inclusion in the
            I{additional} section.  These instances represent extra information
            about the records in C{answer} and C{authority}.
        r!T��authN)
�type�_ADDITIONAL_PROCESSING_TYPESZpayload�name�records�get�lower�TYPE�_ADDRESS_TYPESr�RRHeader�IN�ttl)r*Zanswer�	authorityr:�recordr2�recr!r!r"�_additionalRecordsYs
�z FileAuthority._additionalRecordscCs�g}g}g}g}t|jdj|jdj�}	|j�|���}
|
�r�|
D]�}|jdk	rZ|j}n|	}|jt	j
kr�|��|jd��kr�|�t	j||jt	j
||dd��n4|j|ks�|t	jkr�|�t	j||jt	j
||dd��|jt	jkrD|�t	j||jt	j
||dd��qD|�s|}|�|||	�}
|�r.|�|
�n
|�|
�|�sp|�sp|�t	j|jdt	jt	j
||jddd��t�|||f�St	�||jd��r�t�t�t	�|���St�t�t�|���SdS)a�
        Determine a response to a particular DNS query.

        @param name: The name which is being queried and for which to lookup a
            response.
        @type name: L{bytes}

        @param cls: The class which is being queried.  Only I{IN} is
            implemented here and this value is presently disregarded.
        @type cls: L{int}

        @param type: The type of records being queried.  See the types defined
            in L{twisted.names.dns}.
        @type type: L{int}

        @param timeout: All processing is done locally and a result is
            available immediately, so the timeout value is ignored.

        @return: A L{Deferred} that fires with a L{tuple} of three sets of
            response records (to comprise the I{answer}, I{authority}, and
            I{additional} sections of a DNS response) or with a L{Failure} if
            there is a problem processing the query.
        rNrFr.T)�max�soa�minimum�expirer3r4r5r:r6r�NS�appendr8r9ZALL_RECORDS�CNAMEr>�extend�SOAr�succeedZ_isSubdomainOf�failr�FailureZAuthoritativeDomainErrorr�DomainError)r*r2�clsr0�timeoutZcnames�resultsr;Z
additional�default_ttlZdomain_recordsr<r:ZadditionalInformationr!r!r"�_lookupxs�
��������
���zFileAuthority._lookup�
c
Cs|jd��|��kr�t|jdj|jdj�}|jdjdk	rN|jdj}n|}tj|jdtjtj	||jddd�g}|j
��D]T\}}|D]F}|jdk	r�|j}	n|}	|jtjkr�|�
tj||jtj	|	|dd��q�q�|�
|d�t�|ddf�St�t�t�|���S)NrrTr.r!)r@r5r?rArBr:rr8rGr9r3�itemsr6rDrrHrIrrJrK)
r*r2rMrOZsoa_ttlrN�krr=r:r!r!r"�
lookupZone�sB��
��zFileAuthority.lookupZonecCsbggg}}}|D]B}|dr|�|dd�|�|dd�|�|dd�q|||fS)Nrr�)rF)r*rNZansr/�add�resr!r!r"�
_cbAllRecords�szFileAuthority._cbAllRecords)N)rQ)�__name__�
__module__�__qualname__�__doc__rrEZMXrCr1�AZAAAAr7r@r3r'r-r>rPrTrXr!r!r!r"r$;s

c
r$c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�PySourceAuthorityzC
    A FileAuthority that is built up from Python source code.
    cCs||��i}}t|||�d|kr.td|��i|_|dD]:}t|dtj�rV||_|j�|d�	�g��
|d�q<dS)NZzonezNo zone defined in rr)�setupConfigNamespacer	�
ValueErrorr3�
isinstancerZ
Record_SOAr@�
setdefaultr5rD)r*r�g�lZrrr!r!r"r(	szPySourceAuthority.loadFilecs�fdd�S)Ncs|�||�fSr%r!)r2�arg�kw�r0r!r"�<lambda>�z.PySourceAuthority.wrapRecord.<locals>.<lambda>r!)r*r0r!rgr"�
wrapRecordszPySourceAuthority.wrapRecordcCsNi}tj��}dd�|D�D],}tt|�}|�|�}|||td�d�<q|S)NcSsg|]}|�d�r|�qS)�Record_)�
startswith)�.0�xr!r!r"�
<listcomp>s
z:PySourceAuthority.setupConfigNamespace.<locals>.<listcomp>rk)rr+Ziterkeys�getattrrj�len)r*rrRr<r0r r!r!r"r_s


z&PySourceAuthority.setupConfigNamespaceN)rYrZr[r\r(rjr_r!r!r!r"r^s
r^c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�
BindAuthorityz�
    An Authority that loads U{BIND zone files
    <https://en.wikipedia.org/wiki/Zone_file>}.

    Supports only C{$ORIGIN} and C{$TTL} directives.
    cCsJt|�}t|��d�|_|���d�}|�|�}|�|�}|�|�dS)z}
        Load records from C{filename}.

        @param filename: file to read from
        @type filename: L{bytes}
        �.TN)	rr
�basename�originZ
getContent�
splitlines�
stripComments�collapseContinuations�
parseLines)r*r�fp�linesr!r!r"r(,s

zBindAuthority.loadFilecCsdd�dd�|D�D�S)z�
        Strip comments from C{lines}.

        @param lines: lines to work on
        @type lines: iterable of L{bytes}

        @return: C{lines} sans comments.
        css2|]*}|�d�dkr|p(|d|�d��VqdS)�;���N)�find)rm�ar!r!r"�	<genexpr>Gsz.BindAuthority.stripComments.<locals>.<genexpr>cSsg|]}|���qSr!)�strip)rm�br!r!r"roHsz/BindAuthority.stripComments.<locals>.<listcomp>r!)r*r{r!r!r"rw>s
	��zBindAuthority.stripCommentsc
Cs�g}d}|D]�}|dkrP|�d�dkr2|�|�q�|�|d|�d���d}q|�d�dkr�|dd|d|�d��7<d}q|dd|7<qtddd	�|D��S)
z�
        Transform multiline statements into single lines.

        @param lines: lines to work on
        @type lines: iterable of L{bytes}

        @return: iterable of continuous lines
        r�(r}Nr�)� css|]}|��VqdSr%)r)rm�liner!r!r"r�fsz6BindAuthority.collapseContinuations.<locals>.<genexpr>)r~rD�filter)r*r{rdr,r�r!r!r"rxNs	"z#BindAuthority.collapseContinuationscCs�d}|j}i|_|D]p}|ddkr4t�|d�}q|ddkrJ|d}q|ddkr`td��q|ddkrvtd	��q|�|||�q||_d
S)zs
        Parse C{lines}.

        @param lines: lines to work on
        @type lines: iterable of L{bytes}
        i0*rs$TTLrs$ORIGINs$INCLUDEz"$INCLUDE directive not implementeds	$GENERATEz#$GENERATE directive not implementedN)rur3rZstr2time�NotImplementedError�parseRecordLine)r*r{r:rur�r!r!r"ryis 

�zBindAuthority.parseLinescCsd|�d�s |d|dd�}n|dd�}t|d|fd�}|rR|||||�ntd|f��dS)a
        Add a record to our authority.  Expand domain with origin if necessary.

        @param owner: origin?
        @type owner: L{bytes}

        @param ttl: time to live for the record
        @type ttl: L{int}

        @param domain: the domain for which the record is to be added
        @type domain: L{bytes}

        @param type: record type
        @type type: L{str}

        @param cls: record class
        @type cls: L{str}

        @param rdata: record data
        @type rdata: L{list} of L{bytes}
        rsNr}zclass_%szRecord class %r not supported)�endswithrpr�)r*�ownerr:r0�domainrL�rdatar r!r!r"�	addRecord�s
�zBindAuthority.addRecordcCsjttdt|�fd�}|rT||�}||_|j�|��g��|�|dkrf||f|_nt	dt|�f��dS)a>
        Simulate a class IN and recurse into the actual class.

        @param ttl: time to live for the record
        @type ttl: L{int}

        @param type: record type
        @type type: str

        @param domain: the domain
        @type domain: bytes

        @param rdata:
        @type rdate: bytes
        z	Record_%sNrGzRecord type %r not supported)
rprr
r:r3rbr5rDr@r�)r*r:r0r�r�r<rr!r!r"�class_IN�s�zBindAuthority.class_INcCs�tr6tdd�tj��D��}tdd�tj��D��}nttj���}ttj���}||B}d}|}|ddkr�|dd�}|}n,|d��s�|d|kr�|d}|dd�}|d��s�|d|kr�|}	|}n|d}	|dd�}|d|k�r,|d}|dd�}|d���rtt|d�}|dd�}nH|d���rtt|d�}|dd�}|d|k�rt|d}|dd�}|d}
|dd�}|�||t	|
�|	t	|�|�dS)	a�
        Parse a C{line} from a zone file respecting C{origin} and C{ttl}.

        Add resulting records to authority.

        @param origin: starting point for the zone
        @type origin: L{bytes}

        @param ttl: time to live for the record
        @type ttl: L{int}

        @param line: zone file line to parse; split by word
        @type line: L{list} of L{bytes}
        css|]}|�d�VqdS��asciiN��encode)rmZqcr!r!r"r��sz0BindAuthority.parseRecordLine.<locals>.<genexpr>css|]}|�d�VqdSr�r�)rmZqtr!r!r"r��ssINr�@rN)
r�setrZ
QUERY_CLASSES�valuesZQUERY_TYPES�isdigitrr�r
)r*rur:r�ZqueryClassesZ
queryTypesZmarkersrLr�r�r0r�r!r!r"r��sZ��
�zBindAuthority.parseRecordLineN)rYrZr[r\r(rwrxryr�r�r�r!r!r!r"rr%s#rr)r
)r\Z
__future__rrrrZ
twisted.namesrrrZtwisted.internetrZtwisted.pythonrZtwisted.python.compatr	r
rZtwisted.python.filepathrr#r&r$r^rrr!r!r!r"�<module>s
%K