Ë
    oj  ã                   ó  — d Z ddlZddlmZ ddlmZ ddlmZmZ dZ	dZ
 G d„ d	e«      Z G d
„ de«      Z G d„ de«      Z G d„ de«      Z G d„ dej                   «      Z G d„ d«      Z G d„ dej                   «      Zg d¢Zy)z 
Ident protocol implementation.
é    N)Údefer)Úbasic)ÚfailureÚlogé   iÿÿ  c                   ó    — e Zd ZdZdZdefd„Zy)Ú
IdentErrorz;
    Can't determine connection owner; reason unknown.
    zUNKNOWN-ERRORÚreturnc                 ó   — | j                   S ©N)ÚidentDescription©Úselfs    ú9/usr/lib/python3/dist-packages/twisted/protocols/ident.pyÚ__str__zIdentError.__str__   s   € Ø×$Ñ$Ð$ó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústrr   © r   r   r	   r	      s   „ ñð 'Ðð%˜ô %r   r	   c                   ó   — e Zd ZdZdZy)ÚNoUserz�
    The connection specified by the port pair is not currently in use or
    currently not owned by an identifiable entity.
    zNO-USERN©r   r   r   r   r   r   r   r   r   r      s   „ ñð
 !Ñr   r   c                   ó   — e Zd ZdZdZy)Ú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-PORTNr   r   r   r   r   r   '   s   „ ñð &Ñr   r   c                   ó   — e Zd ZdZdZy)Ú
HiddenUserz…
    The server was able to identify the user of this port, but the
    information was not returned at the request of the user.
    zHIDDEN-USERNr   r   r   r   r   r   2   s   „ ñð
 %Ñr   r   c                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	Ú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.
    c                 ó¤  — |j                  d«      }t        |«      dk7  r| j                  «        y 	 t        t        |«      \  }}t
        |cxk  r	t        k  r,n n)t
        |cxk  r	t        k  rn n| j                  ||«       y | j                  t        j                  t        «       «      ||«       y # t        $ r | j                  «        Y y w xY w)Nú,é   )ÚsplitÚlenÚinvalidQueryÚmapÚintÚ	_MIN_PORTÚ	_MAX_PORTÚ
validQueryÚ	_ebLookupr   ÚFailurer   Ú
ValueError)r   ÚlineÚpartsÚportOnServerÚportOnClients        r   ÚlineReceivedzIdentServer.lineReceivedH   s    € Ø—
‘
˜3“ˆÜˆu‹:˜Š?Ø×ÑÕðÜ-0´°e«_Ñ*�˜lô
  Ô:´Õ:Ü! \Ô>´YÕ>à—O‘O L°,Õ?à—N‘NÜŸ™¬«Ó6¸Àlõøô ò $Ø×!Ñ!Ö#ð$ús   ²B3 Â3CÃCc                 ó8   — | j                   j                  «        y r   )Ú	transportÚloseConnectionr   s    r   r'   zIdentServer.invalidQuery\   s   € Ø�‰×%Ñ%Õ'r   c                 óJ  — | j                   j                  «       j                  |f}| j                   j                  «       j                  |f}t	        j
                  | j                  ||«      j                  | j                  ||«      j                  | j                  ||«       y)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)r6   ÚgetHostÚhostÚgetPeerr   ÚmaybeDeferredÚlookupÚaddCallbackÚ	_cbLookupÚ
addErrbackr-   )r   r2   r3   Ú
serverAddrÚ
clientAddrs        r   r,   zIdentServer.validQuery_   s|   € ð —^‘^×+Ñ+Ó-×2Ñ2°LÐ@ˆ
Ø—^‘^×+Ñ+Ó-×2Ñ2°LÐ@ˆ
Ü×Ñ˜DŸK™K¨°ZÓ@×LÑLØ�N‰N˜L¨,ó	
ç
‰*�T—^‘^ \°<Õ
@r   c                 ó>   — |\  }}| j                  d||||fz  «       y )Nz%d, %d : USERID : %s : %s)ÚsendLine)r   ÚresultÚsportÚcportÚsysNameÚuserIds         r   r?   zIdentServer._cbLookupm   s'   € Ø"Ñˆ�&Ø�‰Ð1°U¸EÀ7ÈFÐ4SÑSÕTr   c                 óò   —  |j                   t        «      r"| j                  d|||j                  fz  «       y t	        j
                  |«       | j                  d||t        |j                  «      fz  «       y )Nz%d, %d : ERROR : %s)Úcheckr	   rD   Úvaluer   Úerr)r   r   rF   rG   s       r   r-   zIdentServer._ebLookupq   s]   € Øˆ7�=‰=œÔ$Ø�M‰MÐ/°5¸%ÀÇÁÐ2OÑOÕPä�G‰G�GÔØ�M‰MØ%¨°´zÀ'Ç-Á-Ó7PÐ(QÑQõr   c                 ó   — t        «       ‚)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.
        ©r	   )r   ÚserverAddressÚclientAddresss      r   r=   zIdentServer.lookupz   s   € ô. ‹lÐr   N)
r   r   r   r   r4   r'   r,   r?   r-   r=   r   r   r   r!   r!   ;   s'   „ ñ
òò((òAòUòór   r!   c                   ój   — e Zd ZdZdZ	 ddlmZ efd„Z[d„ Z	d	„ Z
d
„ Zd„ Zd„ Zy# e$ r dd„ZY Œw xY w)ÚProcServerMixinzDImplements lookup() to grab entries for responses from /proc/net/tcpÚLINUXr   )Úgetpwuidc                 ó   —  ||«      d   S ©Nr   r   ©r   ÚuidrU   s      r   ÚgetUsernamezProcServerMixin.getUsernameœ   s   € Ù˜C“= Ñ#Ð#r   Nc                 ó   — t        «       ‚r   rO   rX   s      r   rZ   zProcServerMixin.getUsername¢   s
   € Ü“,Ðr   c              #   ó    K  — t        d«      5 }|j                  «        |D ]  }|j                  «       –— Œ 	 d d d «       y # 1 sw Y   y xY w­w)Nz/proc/net/tcp)ÚopenÚreadlineÚstrip)r   ÚfÚLs      r   ÚentrieszProcServerMixin.entries¥   sG   è ø€ Ü�/Ó"ð 	  aØ�J‰JŒLØò  �Ø—g‘g“i“ñ ÷	 ÷ 	 ñ 	 üs   ‚AŽ*A¹	AÁAÁAc                 ó¤   — dj                  t        t        t        j                  dt        j
                  dt        |d«      «      «      «      «      S )Nú.Ú4Bz=Lé   )Újoinr(   r   ÚstructÚunpackÚpackr)   )r   Úhexstrs     r   ÚdottedQuadFromHexStringz'ProcServerMixin.dottedQuadFromHexString«   s9   € Ø�x‰xÜ””V—]‘] 4¬¯©°T¼3¸vÀr»?Ó)KÓLÓMó
ð 	
r   c                 ól   — |j                  d«      \  }}| j                  |«      }t        |d«      }||fS )Nú:rf   )r%   rl   r)   )r   ÚpackedÚaddrÚports       r   ÚunpackAddresszProcServerMixin.unpackAddress°   s9   € Ø—\‘\ #Ó&‰
ˆˆdØ×+Ñ+¨DÓ1ˆÜ�4˜‹}ˆØ�TˆzÐr   c                 óÈ   — |j                  «       j                  «       }| j                  |d   «      \  }}| j                  |d   «      \  }}t        |d   «      }||f||f|fS )Nr   r$   é   )r_   r%   rr   r)   )r   r0   r1   Ú	localAddrÚ	localPortÚ
remoteAddrÚ
remotePortrY   s           r   Ú	parseLinezProcServerMixin.parseLine¶   sl   € Ø—
‘
“×"Ñ"Ó$ˆØ#×1Ñ1°%¸±(Ó;Ñˆ	�9Ø!%×!3Ñ!3°E¸!±HÓ!=Ñˆ
�JÜ�%˜‘(‹mˆØ˜9Ð%¨
°JÐ'?ÀÐDÐDr   c                 óÊ   — | j                  «       D ]G  }| j                  |«      \  }}}||k(  sŒ|d   |d   k(  sŒ*| j                  | j                  |«      fc S  t	        «       ‚)Nr   )rb   ry   ÚSYSTEM_NAMErZ   r   )r   rP   rQ   Úentru   rw   rY   s          r   r=   zProcServerMixin.lookup½   sk   € Ø—<‘<“>ò 	AˆCØ)-¯©¸Ó)<Ñ&ˆI�z 3Ø˜]Ó*¨y¸©|¸}ÈQÑ?OÓ/OØ×(Ñ(¨$×*:Ñ*:¸3Ó*?Ð@Ò@ð	Aô
 ‹hˆr   r   )r   r   r   r   r{   ÚpwdrU   rZ   ÚImportErrorrb   rl   rr   ry   r=   r   r   r   rS   rS   ”   sO   „ ÙNà€Kð
Ý à,4ó 	$ð ò ò
ò
òEóøð; ò õ	ðús   Š& ¦	2±2rS   c                   ó6   — e Zd ZeeeefZd„ Zd„ Z	d„ Z
d„ Zd„ Zy)ÚIdentClientc                 ó   — g | _         y r   )Úqueriesr   s    r   Ú__init__zIdentClient.__init__É   s	   € Øˆ�r   c                 ó  — | j                   j                  t        j                  «       ||f«       t	        | j                   «      dkD  r| j                   d   d   S | j                  d||fz  «       | j                   d   d   S )zK
        Lookup user information about the specified address pair.
        r   éÿÿÿÿr   ú%d, %d)r‚   Úappendr   ÚDeferredr&   rD   )r   r2   r3   s      r   r=   zIdentClient.lookupÌ   ss   € ð 	�‰×ÑœUŸ^™^Ó-¨|¸\ÐJÔKÜˆt�|‰|Ó˜qÒ Ø—<‘< Ñ# AÑ&Ð&à�‰�h ,°Ð!=Ñ=Ô>Ø�|‰|˜BÑ Ñ"Ð"r   c                 ó6  — | j                   st        j                  d|›�«       y | j                   j                  d«      \  }}}| j	                  ||«       | j                   r7| j                  d| j                   d   d   | j                   d   d   fz  «       y y )NzUnexpected server response: r   r†   r   r$   )r‚   r   ÚmsgÚpopÚparseResponserD   )r   r0   ÚdÚ_s       r   r4   zIdentClient.lineReceived×   sƒ   € Ø�|Š|Ü�G‰GÐ2°4°(Ð;Õ<à—l‘l×&Ñ& qÓ)‰GˆAˆq�!Ø×Ñ˜q $Ô'Ø�|Š|Ø—‘˜h¨$¯,©,°q©/¸!Ñ*<¸d¿l¹lÈ1¹oÈaÑ>PÐ)QÑQÕRð r   c                 ón   — | j                   D ]  }|d   j                  t        |«      «       Œ! g | _         y rW   )r‚   Úerrbackr	   )r   ÚreasonÚqs      r   ÚconnectionLostzIdentClient.connectionLostà   s1   € Ø—‘ò 	-ˆAØˆa‰D�L‰Lœ FÓ+Õ,ð	-àˆ�r   c                 óŽ  — |j                  dd«      }t        |«      dk7  r|j                  t        |«      «       y t	        t
        j                  |«      \  }}}|dk(  rT| j                  D ]*  }|j                  |k(  sŒ|j                   ||«      «        y  |j                  t        |«      «       y |j                  ||f«       y )Nrn   r$   é   ÚERROR)
r%   r&   r�   r	   r(   r   r_   Ú
errorTypesr   Úcallback)r   Údeferredr0   r1   ÚportsÚtypeÚaddInfoÚets           r   rŒ   zIdentClient.parseResponseå   s«   € Ø—
‘
˜3 Ó"ˆÜˆu‹:˜Š?Ø×ÑœZ¨Ó-Õ.ä#&¤s§y¡y°%Ó#8Ñ ˆE�4˜Ø�wŠØŸ/™/ò �BØ×*Ñ*¨gÓ5Ø ×(Ñ(©¨D«Ô2Ùðð × Ñ ¤¨DÓ!1Õ2à×!Ñ! 4¨ /Õ2r   N)r   r   r   r	   r   r   r   r—   rƒ   r=   r4   r“   rŒ   r   r   r   r€   r€   Æ   s*   „ Ø˜f k°:Ð>€Jòò	#òSòó
3r   r€   )r	   r   r   r   r!   r€   rS   )r   rh   Útwisted.internetr   Útwisted.protocolsr   Útwisted.pythonr   r   r*   r+   Ú	Exceptionr	   r   r   r   ÚLineOnlyReceiverr!   rS   r€   Ú__all__r   r   r   ú<module>r¤      sŒ   ðñ
ó å "Ý #ß 'à€	Ø€	ô%�ô %ô!ˆZô !ô&�*ô &ô%�ô %ôV�%×(Ñ(ô V÷r/ñ /ôd,3�%×(Ñ(ô ,3ò^�r   