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: //proc/self/root/usr/lib/python3/dist-packages/twisted/protocols/__pycache__/ident.cpython-38.pyc
U


W[e�@s�dZddlZddlmZddlmZddlmZmZdZ	dZ
Gdd	�d	e�ZGd
d�de�Z
Gdd
�d
e�ZGdd�de�ZGdd�dej�ZGdd�d�ZGdd�dej�Zd	dd
ddddgZdS)z 
Ident protocol implementation.
�N)�defer)�basic)�log�failure�i��c@seZdZdZdZdd�ZdS)�
IdentErrorz;
    Can't determine connection owner; reason unknown.
    z
UNKNOWN-ERRORcCs|jS�N)�identDescription��self�r�9/usr/lib/python3/dist-packages/twisted/protocols/ident.py�__str__szIdentError.__str__N)�__name__�
__module__�__qualname__�__doc__r	rrrrr
rsrc@seZdZdZdZdS)�NoUserz�
    The connection specified by the port pair is not currently in use or
    currently not owned by an identifiable entity.
    zNO-USERN�rrrrr	rrrr
rsrc@seZdZdZdZdS)�InvalidPorta
    Either the local or foreign port was improperly specified. This should
    be returned if either or both of the port ids were out of range (TCP
    port numbers are from 1-65535), negative integers, reals or in any
    fashion not recognized as a non-negative integer.
    zINVALID-PORTNrrrrr
r'src@seZdZdZdZdS)�
HiddenUserz�
    The server was able to identify the user of this port, but the
    information was not returned at the request of the user.
    zHIDDEN-USERNrrrrr
r2src@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�IdentServera�
    The Identification Protocol (a.k.a., "ident", a.k.a., "the Ident
    Protocol") provides a means to determine the identity of a user of a
    particular TCP connection. Given a TCP port number pair, it returns a
    character string which identifies the owner of that connection on the
    server's system.

    Server authors should subclass this class and override the lookup method.
    The default implementation returns an UNKNOWN-ERROR response for every
    query.
    cCs�|�d�}t|�dkr |��n�ztt|�\}}Wntk
rN|��YnVXt|krdtkr�nn&t|kr|tkr�nn|�||�n|�	t
�t��||�dS)N�,�)
�split�len�invalidQuery�map�int�
ValueError�	_MIN_PORT�	_MAX_PORT�
validQuery�	_ebLookuprZFailurer)r�line�parts�portOnServer�portOnClientrrr
�lineReceivedHs

0zIdentServer.lineReceivedcCs|j��dSr)�	transportZloseConnectionr
rrr
rXszIdentServer.invalidQuerycCsL|j��j|f}|j��j|f}t�|j||��|j||��	|j
||�dS)z�
        Called when a valid query is received to look up and deliver the
        response.

        @param portOnServer: The server port from the query.
        @param portOnClient: The client port from the query.
        N)r)ZgetHostZhostZgetPeerrZ
maybeDeferred�lookupZaddCallback�	_cbLookupZ
addErrbackr#)rr&r'Z
serverAddrZ
clientAddrrrr
r"\s��zIdentServer.validQuerycCs"|\}}|�d||||f�dS)Nz%d, %d : USERID : %s : %s)�sendLine)r�result�sport�cportZsysNameZuserIdrrr
r+lszIdentServer._cbLookupcCsJ|�t�r"|�d|||jf�n$t�|�|�d||t|j�f�dS)Nz%d, %d : ERROR : %s)Zcheckrr,�valuer�err)rrr.r/rrr
r#qs

zIdentServer._ebLookupcCs
t��dS)aq
        Lookup user information about the specified address pair.

        Return value should be a two-tuple of system name and username.
        Acceptable values for the system name may be found online at::

            U{http://www.iana.org/assignments/operating-system-names}

        This method may also raise any IdentError subclass (or IdentError
        itself) to indicate user information will not be provided for the
        given query.

        A Deferred may also be returned.

        @param serverAddress: A two-tuple representing the server endpoint
        of the address being queried.  The first element is a string holding
        a dotted-quad IP address.  The second element is an integer
        representing the port.

        @param clientAddress: Like I{serverAddress}, but represents the
        client endpoint of the address being queried.
        N�r)r�
serverAddress�
clientAddressrrr
r*yszIdentServer.lookupN)
rrrrr(rr"r+r#r*rrrr
r;src@sxeZdZdZdZzddlmZefdd�Z[Wnek
rJdd�ZYnXdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dS)�ProcServerMixinzIImplements lookup() to grab entries for responses from /proc/net/tcp
    ZLINUXr)�getpwuidcCs||�dS�Nrr)r�uidr6rrr
�getUsername�szProcServerMixin.getUsernamecCs
t��dSrr2)rr8rrr
r9�sc	cs4td��"}|��|D]}|��VqW5QRXdS)Nz
/proc/net/tcp)�open�readline�strip)r�f�Lrrr
�entries�s
zProcServerMixin.entriesc
Cs&d�ttt�dt�dt|d�����S)N�.Z4Bz=L�)�joinr�str�structZunpackZpackr)rZhexstrrrr
�dottedQuadFromHexString�sz'ProcServerMixin.dottedQuadFromHexStringcCs*|�d�\}}|�|�}t|d�}||fS)N�:rA)rrEr)rZpackedZaddrZportrrr
�
unpackAddress�s

zProcServerMixin.unpackAddresscCsN|����}|�|d�\}}|�|d�\}}t|d�}||f||f|fS)Nrr�)r<rrGr)rr$r%�	localAddrZ	localPort�
remoteAddrZ
remotePortr8rrr
�	parseLine�s
zProcServerMixin.parseLinecCsT|��D]@}|�|�\}}}||kr|d|dkr|j|�|�fSqt��dS)Nr)r?rK�SYSTEM_NAMEr9r)rr3r4ZentrIrJr8rrr
r*�s
zProcServerMixin.lookupN)rrrrrL�pwdr6r9�ImportErrorr?rErGrKr*rrrr
r5�sr5c@s@eZdZeeeefZdd�Zdd�Z	dd�Z
dd�Zd	d
�ZdS)�IdentClientcCs
g|_dSr)�queriesr
rrr
�__init__�szIdentClient.__init__cCsR|j�t��||f�t|j�dkr2|jddS|�d||f�|jddS)zK
        Lookup user information about the specified address pair.
        r���r�%d, %d)rP�appendrZDeferredrr,)rr&r'rrr
r*�s
zIdentClient.lookupcCsf|jst�d|f�nJ|j�d�\}}}|�||�|jrb|�d|jdd|jddf�dS)NzUnexpected server response: %rrrSrr)rPr�msg�pop�
parseResponser,)rr$�d�_rrr
r(�szIdentClient.lineReceivedcCs(|jD]}|d�t|��qg|_dSr7)rP�errbackr)r�reason�qrrr
�connectionLost�s
zIdentClient.connectionLostcCs�|�dd�}t|�dkr(|�t|��nbttj|�\}}}|dkr||jD]"}|j|krH|�||��dSqH|�t|��n|�	||f�dS)NrFr�ZERROR)
rrrZrrrCr<�
errorTypesr	�callback)rZdeferredr$r%Zports�typeZaddInfoZetrrr
rW�s

zIdentClient.parseResponseN)
rrrrrrrr_rQr*r(r]rWrrrr
rO�s
rO)rrDZtwisted.internetrZtwisted.protocolsrZtwisted.pythonrrr r!�	ExceptionrrrrZLineOnlyReceiverrr5rO�__all__rrrr
�<module>s$		Y45�