HOME


Mini Shell 1.0
DIR: /usr/lib/python3/dist-packages/twisted/conch/ssh/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/twisted/conch/ssh/__pycache__/forwarding.cpython-312.pyc
�

Ϫ�f ��:�dZddlZddlmZmZddlmZmZddlm	Z	m
Z
Gd�dej�ZGd�d	ej�ZGd
�de�ZGd�d
e�ZGd�dej�Zd�ZGd�dej&�Zd�ZeZd�ZeZd�Zd�Zy)z�
This module contains the implementation of the TCP forwarding, which allows
clients and servers to forward arbitrary TCP data across the connection.

Maintainer: Paul Swartz
�N)�channel�common)�protocol�reactor)�HostnameEndpoint�connectProtocolc��eZdZd�Zd�Zy)�SSHListenForwardingFactoryc�.�||_||_||_y�N)�conn�hostport�klass)�self�
connectionrrs    �>/usr/lib/python3/dist-packages/twisted/conch/ssh/forwarding.py�__init__z#SSHListenForwardingFactory.__init__s����	� ��
���
�c��|j|j��}t|�}||_|j|j
f}t
|j|�}|jj||�|S)N)r
)	rr
�SSHForwardingClient�client�host�port�packOpen_direct_tcpipr�openChannel)r�addrrr�	addrTuple�channelOpenDatas      r�
buildProtocolz(SSHListenForwardingFactory.buildProtocolsb���*�*�$�)�)�*�,��$�W�-������Y�Y��	�	�*�	�/��
�
�y�I���	�	���g��7��
rN)�__name__�
__module__�__qualname__rr�rrr
r
s���
rr
c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�SSHListenForwardingChannelc��|jjd|j��t|jj
�dkDr*|jj
dd}|j
|�d|j_y)Nzopened forwarding channel {id}��id�r)�_log�infor(�lenr�buf�write)r�specificData�bs   r�channelOpenz&SSHListenForwardingChannel.channelOpen$sZ���	�	���7�D�G�G��D��t�{�{����!�#��������#�A��J�J�q�M�����rc�$�|j�yr)�closed�r�reasons  r�
openFailedz%SSHListenForwardingChannel.openFailed+s�����
rc�N�|jjj|�yr)r�	transportr.�r�datas  r�dataReceivedz'SSHListenForwardingChannel.dataReceived.s�������#�#�D�)rc�L�|jjj�yr)rr8�loseConnection�rs r�eofReceivedz&SSHListenForwardingChannel.eofReceived1s�������,�,�.rc��t|d�rN|jjd|j��|jj
j
�|`yy)Nrz%closing local forwarding channel {id}r')�hasattrr*r+r(rr8r=r>s rr3z!SSHListenForwardingChannel.closed4sE���4��"��I�I�N�N�B�t�w�w�N�O��K�K�!�!�0�0�2���#rN)r r!r"r1r6r;r?r3r#rrr%r%#s����*�/�rr%c��eZdZdZy)� SSHListenClientForwardingChannelsdirect-tcpipN�r r!r"�namer#rrrCrC;s���DrrCc��eZdZdZy)� SSHListenServerForwardingChannelsforwarded-tcpipNrDr#rrrGrG?s���DrrGc�8�eZdZdZeZd�Zd�Zd�Zd�Z	d�Z
d�Zy)	�SSHConnectForwardingChannela�
    Channel used for handling server side forwarding request.
    It acts as a client for the remote forwarding destination.

    @ivar hostport: C{(host, port)} requested by client as forwarding
        destination.
    @type hostport: L{tuple} or a C{sequence}

    @ivar client: Protocol connected to the forwarding destination.
    @type client: L{protocol.Protocol}

    @ivar clientBuf: Data received while forwarding channel is not yet
        connected.
    @type clientBuf: L{bytes}

    @var  _reactor: Reactor used for TCP connections.
    @type _reactor: A reactor.

    @ivar _channelOpenDeferred: Deferred used in testing to check the
        result of C{channelOpen}.
    @type _channelOpenDeferred: L{twisted.internet.defer.Deferred}
    c�t�tjj|g|��i|��||_d|_d|_y)Nr)r�
SSHChannelrrr�	clientBuf)rr�args�kws    rrz$SSHConnectForwardingChannel.__init__]s5�����#�#�D�6�4�6�2�6� ��
������rc�Z�|jjd|jd|jd��t|j|jd|jd�}t|t
|��}|j|j|j�||_
y)�,
        See: L{channel.SSHChannel}
        zconnecting to {host}:{port}rr)�rrN)r*r+rr�_reactorrr�addCallbacks�
_setClient�_close�_channelOpenDeferred)rr/�ep�ds    rr1z'SSHConnectForwardingChannel.channelOpencs���	
�	�	���)��
�
�a�0@�t�}�}�UV�GW�	�	
��d�m�m�T�]�]�1�-=�t�}�}�Q�?O�
P���B� 3�D� 9�:��	���t������4�$%��!rc��||_|jjd|jd|jd��|jr6|jj
j
|j�d|_|jjddr(|j
|jjdd�d|j_y)z�
        Called when the connection was established to the forwarding
        destination.

        @param client: Client protocol connected to the forwarding destination.
        @type  client: L{protocol.Protocol}
        zconnected to {host}:{port}rr)rQNr)rr*r+rrLr8r.r-)rrs  rrTz&SSHConnectForwardingChannel._setClientos�������	�	���(�t�}�}�Q�/?�d�m�m�TU�FV�	�	
��>�>��K�K�!�!�'�'����7�!�D�N��;�;�?�?�1�2���J�J�t�{�{���q�r�*�+�����rc��|jjd|jd|jd|��|j�y)z�
        Called when failed to connect to the forwarding destination.

        @param reason: Reason why connection failed.
        @type  reason: L{twisted.python.failure.Failure}
        z,failed to connect to {host}:{port}: {reason}rr))rrr5N)r*�errorrr=r4s  rrUz"SSHConnectForwardingChannel._close�sE��	
�	�	���:����q�!����q�!��		�	
�	
���rc��|jr&|jjj|�y|xj|z
c_y)rPN)rr8r.rLr9s  rr;z(SSHConnectForwardingChannel.dataReceived�s1���;�;��K�K�!�!�'�'��-��N�N�d�"�Nrc��|jrt|jjd|j��|jjr|j�|jjj�|`yy)rPz%closed remote forwarding channel {id}r'N)rr*r+r(rr=r8r>s rr3z"SSHConnectForwardingChannel.closed�s]���;�;��I�I�N�N�B�t�w�w�N�O��{�{�"�"��#�#�%��K�K�!�!�0�0�2���rN)r r!r"�__doc__rrRrr1rTrUr;r3r#rrrIrICs,���.�H��
&��&
�#�	rrIc�<�t|�\}}t||||��S)N)�remoteWindow�remoteMaxPacket�avatar)�unpackOpen_direct_tcpiprI)r`rar:rb�remoteHP�origHPs      r�openConnectForwardingClientrf�s*��.�t�4��H�f�&��!�'��	�rc��eZdZd�Zd�Zd�Zy)rc� �||_d|_y)N�)rr-)rrs  rrzSSHForwardingClient.__init__�s�������rc�~�|jr|xj|z
c_y|jj|�yr)r-rr.r9s  rr;z SSHForwardingClient.dataReceived�s)���8�8��H�H���H��L�L���t�$rc�`�|jr"|jj�d|_yyr)rr=r4s  r�connectionLostz"SSHForwardingClient.connectionLost�s%���<�<��L�L�'�'�)��D�L�rN)r r!r"rr;rlr#rrrr�s���%� rrc�T�|\}}|\}}t|t�r|jd�}t|t�r|jd�}tj|�tjd|�z}tj|�tjd|�z}||zS)a
    Pack the data suitable for sending in a CHANNEL_OPEN packet.

    @type destination: L{tuple}
    @param destination: A tuple of the (host, port) of the destination host.

    @type source: L{tuple}
    @param source: A tuple of the (host, port) of the source host.
    �utf-8�>L)�
isinstance�str�encoder�NS�struct�pack)�destination�source�connHost�connPort�origHost�origPortr
�origs        rrr�s���'��X�x�!��X�x��(�C� ��?�?�7�+���(�C� ��?�?�7�+���9�9�X�����T�8�!<�<�D��9�9�X�����T�8�!<�<�D��$�;�rc��tj|�\}}t|t�r|j	d�}tt
jd|dd�d�}tj|dd�\}}t|t�r|j	d�}tt
jd|dd�d�}||f||ffS)z#Unpack the data to a usable format.rnroN�r�r�getNSrp�bytes�decode�intrt�unpack)r:rx�restryrzr{s      rrcrc�s����\�\�$�'�N�H�d��(�E�"��?�?�7�+���6�=�=��t�B�Q�x�0��3�4�H��\�\�$�q�r�(�+�N�H�d��(�E�"��?�?�7�+���6�=�=��t�B�Q�x�0��3�4�H��h��(�H�!5�5�5rc�d�|\}}tj|�tjd|�zS)zv
    Pack the data for tcpip forwarding.

    @param peer: A tuple of the (host, port) .
    @type peer: L{tuple}
    ro)rrsrtru)�peerrrs   r�packGlobal_tcpip_forwardr��s+���L�T�4��9�9�T�?�V�[�[��t�4�4�4rc���tj|�\}}t|t�r|j	d�}tt
jd|dd�d�}||fS)Nrnror~rr)r:rr�rs    r�unpackGlobal_tcpip_forwardr��sV�����d�#�J�D�$��$����{�{�7�#���v�}�}�T�4���8�,�Q�/�0�D���:�r)r^rt�twisted.conch.sshrr�twisted.internetrr�twisted.internet.endpointsrr�Factoryr
rKr%rCrGrIrf�Protocolrr�packOpen_forwarded_tcpiprc�unpackOpen_forwarded_tcpipr�r�r#rr�<module>r�s�����-�.�H�
��!1�!1�
� ��!3�!3��0�'A���'A��`�'�"4�"4�`�F� �(�+�+� �"�*1��
6�5��5��r