HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib64/python3.10/site-packages/asyncssh/__pycache__/channel.cpython-310.pyc
o

�h�>�@s�UdZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
mZmZmZddlmZmZmZmZmZmZddlmZmZmZmZddlmZdd	lmZmZdd
lmZm Z ddlm!Z!m"Z"ddlm#Z#m$Z$m%Z%dd
lm&Z&m'Z'ddlm(Z(m)Z)m*Z*ddlm+Z+ddlm,Z,m-Z-ddl.m/Z/m0Z0ddl1m2Z2ddl3m4Z4m5Z5m6Z6m7Z7ddl3m8Z8m9Z9m:Z:ddl3m;Z;m<Z<m=Z=m>Z>ddl?m@Z@mAZAmBZBmCZCmDZDmEZEddlFmGZGmHZHmIZIddlFmJZJmKZKmLZLddlFmMZMmNZNddlFmOZOmPZPddlFmQZQddlRmSZSddlTmUZUmVZVddlTmWZWmXZXe�r(ddlYmZZZm[Z[dd lYm\Z\ej]Z^ee_e`fead!<e=e^d"d#�Zbe=e^d$d%�Zce�dd&�Zed'd(�efe��g�D�Zhd)d(�eh�g�D�Ziee_eje_e_fZkeeeDgeejfZlGd*d+�d+eeeE�ZmGd,d-�d-emee�ZnGd.d/�d/emee�ZoGd0d1�d1emee�ZpGd2d3�d3epee�ZqGd4d5�d5epee�ZrGd6d7�d7epes�ZtGd8d9�d9epes�ZuGd:d;�d;epes�ZvdS)<z SSH channel and session handlers�N)�MappingProxyType)�
TYPE_CHECKING�Any�AnyStr�	Awaitable�Callable)�Dict�Generic�Iterable�List�Mapping�Optional)�Set�Tuple�Union�cast�)�	constants)�DEFAULT_LANG�EXTENDED_DATA_STDERR)�MSG_CHANNEL_OPEN�MSG_CHANNEL_WINDOW_ADJUST)�MSG_CHANNEL_DATA�MSG_CHANNEL_EXTENDED_DATA)�MSG_CHANNEL_EOF�MSG_CHANNEL_CLOSE�MSG_CHANNEL_REQUEST)�MSG_CHANNEL_SUCCESS�MSG_CHANNEL_FAILURE)�OPEN_CONNECT_FAILED�PTY_OP_RESERVED�
PTY_OP_END)�"OPEN_REQUEST_X11_FORWARDING_FAILED)�OPEN_REQUEST_PTY_FAILED�OPEN_REQUEST_SESSION_FAILED)�SSHLineEditorChannel�SSHLineEditorSession)�	SSHLogger)�ChannelOpenError�EnvMap�
MaybeAwait�
ProtocolError)�	TermModes�TermSize�TermSizeArg)�
decode_env�
encode_env�get_symbol_names�map_handler_name)�Boolean�Byte�String�UInt32�	SSHPacket�SSHPacketHandler)�
SSHSession�SSHClientSession�SSHServerSession)�
SSHTCPSession�SSHUNIXSession�SSHTunTapSession)�SSHSessionFactory�SSHClientSessionFactory)�SSHTCPSessionFactory�SSHUNIXSessionFactory)�SSHTunTapSessionFactory)�DataType)�SSH_TUN_MODE_POINTTOPOINT�SSH_TUN_UNIT_ANY)�SSH_TUN_AF_INET�SSH_TUN_AF_INET6)�
SSHConnection�SSHClientConnection)�SSHServerConnection�_const_dict�PTY_��EXTENDED_DATA_�zSIG[^_]cCs,i|]\}}t�|�r|dd�t|��qS)�N)�
_signal_regex�match�int��.0�k�v�rY�F/usr/local/CyberPanel/lib/python3.10/site-packages/asyncssh/channel.py�
<dictcomp>Ns�r[cCsi|]\}}||�qSrYrYrUrYrYrZr[Psc@s�eZdZUdZee�d�Ze�Ze	e
ed<e�Ze	e
ed<ddde
jdeed	ed
e
de
fdd
�Zedefdd��Zd�dd�Zde
jfdd�Zdeeeeffdd�Z	d�deed	eddfdd�Zde
fdd�Zde	e
fdd�Zde	e
fdd �Zd�d!eeddfd"d#�Zd�d$d%�Zd�d&d'�Z d�d(d)�Z!d�d*d+�Z"d�d,d-�Z#d�d!eeddfd.d/�Z$d0e%d1e&ddfd2d3�Z'd�d0e%d1e&ddfd4d5�Z(d�d6d7�Z)d8e*ddfd9d:�Z+d!eeddfd;d<�Z,d=e
d>e
d?e
d@e-e.e/ddf
dAdB�Z0d@e.e/dedCe.e/ffdDdE�Z1d8e-e.e/ddfdFdG�Z2d=e
d>e
d?e
dHe3ddf
dIdJ�Z4dKe
dLedMeddfdNdO�Z5dPe
dQe
dHe3ddfdRdS�Z6dPe
dQe
dHe3ddfdTdU�Z7dPe
dQe
dHe3ddfdVdW�Z8dPe
dQe
dHe3ddfdXdY�Z9dPe
dQe
dHe3ddfdZd[�Z:dPe
dQe
dHe3ddfd\d]�Z;d^e
dQe
dHe3ddfd_d`�Z<dHe3de*fdadb�Z=e>e6e?e7e@e8eAe9eBe:eCe;eDe<eEe<iZFdce%dde%de3fdedf�ZGd^e
dde%ddfdgdh�ZHdidj�dke%dde%dle*ddfdmdn�ZIdke%dde%dee*fdodp�ZJd�dqdr�ZKd�dsdt�ZLde*fdudv�ZMd�dwdx�ZNd�dyedzeOdeOfd{d|�ZPd}eOddfd~d�ZQde*fd�d��ZRde
fd�d��ZS		d�d�ee
d�ee
ddfd�d��ZTd�d0e/d1e&ddfd�d��ZU	d�d�eVe/d1e&ddfd�d��ZWd�d�d��ZXd�d�d��ZYd�d�d��ZZde[eeffd�d��Z\de[e%e%ffd�d��Z]deefd�d��Z^deefd�d��Z_dS)��
SSHChannelzParent class for SSH channels�MSG_CHANNEL_�_read_datatypes�_write_datatypes�connrI�loop�encoding�errors�window�max_pktsizecCs�||_||_d|_d|i|_||||i|_d|_d|_d|_d|_d|_	d|_
d|_d|_g|_
d|_d|_||_||_||_d|_g|_g|_d|_g|_t��|_|�|�|_|jjd|j��d�|_|� ||�|�!�dS)	a�Initialize an SSH channel

           If encoding is set, data sent and received will be in the form
           of strings, converted on the wire to bytes using the specified
           encoding. If encoding is None, data sent and received must be
           provided as bytes.

           Window specifies the initial receive window size.

           Max_pktsize specifies the maximum length of a single data packet.

        N�
connection�closedrF�startingzchan=)�context)"�_conn�_loop�_session�_extra�_env�_str_env�_command�
_subsystem�_send_state�
_send_chan�_send_window�
_send_pktsize�_send_paused�	_send_buf�
_send_buf_len�_recv_state�_init_recv_window�_recv_window�
_recv_pktsize�_recv_paused�	_recv_buf�_request_queue�_open_waiter�_request_waiters�asyncio�Event�_close_event�add_channel�
_recv_chan�logger�	get_child�_logger�set_encoding�set_write_buffer_limits��selfr`rarbrcrdrerYrYrZ�__init__^sB

zSSHChannel.__init__�returncC�|jS)z%A logger associated with this channel)r��r�rYrYrZr��szSSHChannel.loggercCs|jdusJ�|jS)z*Return the connection used by this channelN)rjr�rYrYrZ�get_connection�szSSHChannel.get_connectioncCr�)z*Return the event loop used by this channel)rkr�rYrYrZ�get_loop��zSSHChannel.get_loopcCs|j|jfS)z(Return the encoding used by this channel)�	_encoding�_errorsr�rYrYrZ�get_encoding�szSSHChannel.get_encoding�strictNcCsD||_||_|rt�|�|�|_t�|�|�|_dSd|_d|_dS)z Set the encoding on this channelN)r�r��codecs�getincrementalencoder�_encoder�getincrementaldecoder�_decoder)r�rbrcrYrYrZr��s��
zSSHChannel.set_encodingcCr�)z5Return the configured receive window for this channel)rzr�rYrYrZ�get_recv_window�r�zSSHChannel.get_recv_windowcCr�)z1Return the legal read data types for this channel)r^r�rYrYrZ�get_read_datatypes�r�zSSHChannel.get_read_datatypescCr�)z2Return the legal write data types for this channel)r_r�rYrYrZ�get_write_datatypes�r�zSSHChannel.get_write_datatypes�exccCs|jr|j��s|j�ttd��d|_|jr1|jD]}|��s-|r(|�|�q|�d�qg|_|jdurTz|j�|�Wnt	yP|j
jdtj
d�Ynwd|_|j��|jr�|j
�d|rhdt|�nd�|j�|�|jdusxJ�|j�|j�d|_d|_d|_dSdS)	zClean up this channel�SSH connection closedNFz%Uncaught exception in session ignored)�exc_infozChannel closed%sz: �)r��	cancelled�
set_exceptionr(rr��
set_resultrl�connection_lost�	Exceptionr��debug1�sysr�r��setrj�info�str�detach_x11_listenerr��remove_channelrs)r�r��waiterrYrYrZ�_cleanup�sJ
��

�

��
�
�zSSHChannel._cleanupcCs4g|_d|_|jdkr|�t�d|_d|_dSdS)z5Discard unsent data and close the channel for sendingrrgN)rwrxrr�send_packetrrsr�rYrYrZ�_close_send�s


�zSSHChannel._close_sendcCs2g|_d|_|jdkrd|_|j�|j�dSdS)z6Discard unreceived data and clean up if close receivedF�
close_pendingrgN)r~r}ryrk�	call_soonr�r�rYrYrZ�
_discard_recvs
�zSSHChannel._discard_recvc�s.�|jdkr|j�d�d|_|��dSdS)z)Start processing data on a new connectionrhzReading from channel startedFN�r}r��debug2�_flush_recv_bufr�rYrYrZ�_start_readings�
�zSSHChannel._start_readingcCs�|jr"|j|jkr |j�d�d|_|jdusJ�|j��dSdS|j|jkr?|j�d�d|_|jdus8J�|j��dSdS)zAPause or resume writing based on send buffer low/high water markszWriting from session resumedFNzWriting from session pausedT)	rvrx�_send_low_waterr�r�rl�resume_writing�_send_high_water�
pause_writingr�rYrYrZ�_pause_resume_writings��z SSHChannel._pause_resume_writingcCs|jr\|jr\t|j|j�}|jd\}}t|�|kr&|d|�}|d|�=n|}|jd=|jt|�8_|jt|�8_|durK|�tt|��n|�t	t
|�t|��|jr\|js|��|js}|jdkrr|�t
�d|_dS|jdkr|��dSdSdS)z;Flush as much data in send buffer as the send window allowsrN�eof_pending�eofr�)rwrt�minru�lenrxr�rr5rr6r�rrrr�)r��pktsize�buf�datatype�datarYrYrZ�_flush_send_buf1s2��



�zSSHChannel._flush_send_bufc
Cs|jr|js|j|j�d��|jr|jr|jsh|jdkrh|jrK|sK|jdvrKz|jdus/J�|j�dd�WntyJ}zt	t
|��d�d}~ww|jdkrhd|_|jdusZJ�|j��sh|j
d	krh|��|js}|jd
krd|_|j�|j|�dSdSdS)z?Flush as much data in the recv buffer as the application allowsrrh)r�r�N�Tr�r��openr�rg)r~r}�
_deliver_data�popr�ryr��decode�UnicodeDecodeErrorr+r�rl�eof_receivedrr�	write_eofrkr�r�)r�r��unicode_excrYrYrZr�Qs.�

��


�zSSHChannel._flush_recv_bufr�r�c
Cs�|jt|�8_|j|jdkr,|j|j}|j�d||j�|�tt|��|j|_|jrUz|j	dus7J�t
t|j	�|��}Wnt
yT}ztt|��d�d}~wwt
t|�}|jdurh|j�||�dSdS)z$Deliver incoming data to the session�z0Sending window adjust of %d bytes, new window %dN)r{r�rzr�r�r�rr6r�r�rrr�r�r+r�rl�
data_received)r�r�r��adjust�decoded_datar�rYrYrZr�ms(���

�zSSHChannel._deliver_datacCs@|sdS|jdvrdS|jr|j�||f�dS|�||�dS)aXAccept new data on the channel

           This method accepts new data on the channel, immediately
           delivering it to the session if it hasn't paused reading.
           If it has paused, data is buffered until reading is resumed.

           Data sent after the channel has been closed by the session
           is dropped.

        N>rgr�)rrr}r~�appendr��r�r�r�rYrYrZ�_accept_data�s
zSSHChannel._accept_datacCsv|jd\}}}dt|�d}ttt||d��}|r%ttt||��}n	|j�d|�d}|dur9|�	|�dSdS)z*Process next item on channel request queuer�	_process_�_requestNz$Received unknown channel request: %sF)
rr2r�_RequestHandler�getattrr
�boolr�r��_report_response)r��request�packet�_�name�handler�resultrYrYrZ�_service_next_request�s�z SSHChannel._service_next_requestr�cCs||j�d�\}}}|r|jdvr|r|�t�n|�t�|r3|dvr3|jdus*J�|j��|��|jr<|�	�dSdS)z?Report back the response to a previously issued channel requestr>rgr�>�exec�shell�	subsystemN)
rr�rrr�rrrl�session_started�resume_readingr�)r�r�r�r��
want_replyrYrYrZr��s

�zSSHChannel._report_responsecCs(|j�d�d|_|��|�|�dS)z"Process the SSH connection closingz'Closing channel due to connection closergN)r�r�rrr�r�)r�r�rYrYrZ�process_connection_close�sz#SSHChannel.process_connection_close�	send_chan�send_window�send_pktsize�sessioncCsJ||_||_||_|j�d||�|jdusJ�|j�|�|�|j�dS)zProcess a channel open request�(  Initial send window %d, packet size %dN)rsrtrur�r�rj�create_task�_finish_open_request)r�r�r�r�r�rYrYrZ�process_open�s�zSSHChannel.process_openzSSHChannel[AnyStr]cCs||fS)z3Hook to optionally wrap channel and session objectsrY)r�r�rYrYrZ�
_wrap_session�szSSHChannel._wrap_sessionc
�s �z]t�|�rtttt|�IdH}nttt|�}|js#ttd��|�	|�\}|_
|j�d|j
|j�|jdus<J�|jdusCJ�|j�|j|j|j
|j�d|_d|_|j
�|�WdSty�}z%|jr}|jduspJ�|j�|j|j|j|j�|j�|j�WYd}~dSd}~ww)z(Finish processing a channel open requestNr��(  Initial recv window %d, packet size %dr�)�inspect�isawaitablerrr9rrjr(rr�rlr�r�r{r|rsr��send_channel_open_confirmationrrry�connection_made�send_channel_open_failure�code�reason�langrkr�r�)r�r�r��chanr�rYrYrZr��s@�
��
����zSSHChannel._finish_open_requestr�cCs\|jstd��||_||_||_|j�d||�d|_d|_|j�	�s)|j�
|�d|_dS)z#Process a channel open confirmation�Channel not being openedr�r�N)r�r+rsrtrur�r�rrryr�r�)r�r�r�r�r�rYrYrZ�process_open_confirmations�

z$SSHChannel.process_open_confirmationr�r�r�cCsD|jstd��|j��s|j�t|||��d|_|j�|j�dS)zProcess a channel open failurerN)r�r+r�r�r(rkr�r�)r�r�r�r�rYrYrZ�process_open_failures

�zSSHChannel.process_open_failure�_pkttype�_pktidcCsN|jdvr	td��|��}|��|j|7_|j�d||j�|��dS)z Process a send window adjustment>r�r�r��Channel not openz1Received window adjust of %d bytes, new window %dN)ryr+�
get_uint32�	check_endrtr�r�r�)r�rrr�r�rYrYrZ�_process_window_adjust*s
�z!SSHChannel._process_window_adjustcCsf|jdkr	td��|��}|��t|�}||jkrtd��|j�d||dkr)dnd�|�|�dS)	zProcess incoming datar��Channel not open for sending�Window exceededzReceived %d data byte%sr�sr�N)	ryr+�
get_stringrr�r{r�r�r�)r�rrr�r��datalenrYrYrZ�
_process_data;s


�zSSHChannel._process_datacCs�|jdkr	td��|��}|��}|��||jvrtd��t|�}||jkr+td��|j�	d||dkr6dndt
|�|�||�d	S)
zProcess incoming extended datar�r
�Invalid extended data typerzReceived %d data byte%s from %srrr�N)ryr+rr
rr^r�r{r�r��_data_type_namesr�)r�rrr�r�r�rrYrYrZ�_process_extended_dataOs



�z!SSHChannel._process_extended_datacCs8|jdkr	td��|��|j�d�d|_|��dS)zProcess an incoming end of filer�r
zReceived EOFr�N)ryr+rr�r�r��r�rrr�rYrYrZ�_process_eofhs
zSSHChannel._process_eofcCs@|jdvr	td��|��|j�d�|��d|_|��dS)z!Process an incoming channel close>r�r�r�rzReceived channel closer�N)ryr+rr�r�r�r�rrYrYrZ�_process_closevs
zSSHChannel._process_closecCsz|jdvr	td��|��}|��}z|�d�}Wnty$td�d�w|j�|||f�t|j�dkr;|�	�dSdS)z#Process an incoming channel request>r�r�r�r�asciizInvalid channel requestNr)
ryr+r
�get_booleanr�r�rr�r�r�)r�rrr��
request_bytesr�r�rYrYrZ�_process_request�s

��zSSHChannel._process_request�pkttypecCs@|��|jr|j�d�}|��s|�|tk�dSdStd��)z%Process a success or failure responserzUnexpected channel responseN)rr�r�r�r�rr+)r�rrr�r�rYrYrZ�_process_response�s�zSSHChannel._process_responsecCs|��|j�d�dS)z-Process an incoming OpenSSH keepalive requestz*Received OpenSSH keepalive channel requestF)rr�r��r�r�rYrYrZ�-_process_keepalive_at_openssh_dot_com_request�sz8SSHChannel._process_keepalive_at_openssh_dot_com_request�chantype�argsc�s��|jdkr
td��|j��|_|j�d|j|j�|j	dus!J�|j
dus(J�|j	jtt
|�t|j
�t|j�t|j�g|�Rd|i�|jIdHS)z"Make a request to open the channelrgzChannel already openr�Nr�)rr�OSErrorrk�
create_futurer�r�r�r{r|rjr�r�rr5r6)r�rrrYrYrZ�_open�s&�
����zSSHChannel._opencGsF|jdurdSt|j�d�|�}|jdusJ�|jj|||d�dS)zSend a packet on the channelNr�)r�)rsr6�joinrjr�)r�rr�payloadrYrYrZr��s

zSSHChannel.send_packetF)r�r�r�cGs"|jtt|�t|�g|�R�dS)zSend a channel requestN)r�rr5r3)r�r�r�rrYrYrZ�
_send_request�s
��zSSHChannel._send_requestc�sH�|jdurdS|j��}|j�|�|j|g|�Rddi�|IdHS)z0Make a channel request and wait for the responseNFr�T)rsrkr!r�r�r%)r�r�rr�rYrYrZ�
_make_request�s�


zSSHChannel._make_requestcCs8|j�d�|jdvr|��|jdkr|��dSdS)z�Forcibly close the channel

           This method can be called to forcibly close the channel, after
           which no more data can be sent or received. Any unsent buffered
           data and any incoming data in flight will be discarded.

        zAborting channel>rgr�rgN)r�r�rrr�ryr�r�rYrYrZ�abort�s	

�zSSHChannel.abortcCs>|j�d�|jdvrd|_|��|jdkr|��dSdS)aCleanly close the channel

           This method can be called to cleanly close the channel, after
           which no more data can be sent or received. Any unsent buffered
           data will be flushed asynchronously before the channel is
           closed.

        zClosing channel>rgr�r�rgN)r�r�rrr�ryr�r�rYrYrZ�closes


�zSSHChannel.closecCs
|jdkS)z-Return if the channel is closing or is closedr�)rrr�rYrYrZ�
is_closing�
zSSHChannel.is_closingc�s�|j��IdHdS)z�Wait for this channel to close

           This method is a coroutine which can be called to block until
           this channel has finished closing.

        N)r��waitr�rYrYrZ�wait_closeds�zSSHChannel.wait_closedr��defaultcCs$|j�||jr|j�||��S|�S)aoGet additional information about the channel

           This method returns extra information about the channel once
           it is established. Supported values include `'connection'`
           to return the SSH connection this channel is running over plus
           all of the values supported on that connection.

           For TCP channels, the values `'local_peername'` and
           `'remote_peername'` are added to return the local and remote
           host and port information for the tunneled TCP connection.

           For UNIX channels, the values `'local_peername'` and
           `'remote_peername'` are added to return the local and remote
           path information for the tunneled UNIX domain socket connection.
           Since UNIX domain sockets provide no "source" address, only
           one of these will be filled in.

           See :meth:`get_extra_info() <SSHClientConnection.get_extra_info>`
           on :class:`SSHClientConnection` for more information.

           Additional information stored on the channel by calling
           :meth:`set_extra_info` can also be returned here.

        )rm�getrj�get_extra_info)r�r�r-rYrYrZr/$s
��zSSHChannel.get_extra_info�kwargscKs|jjdi|��dS)asStore additional information associated with the channel

           This method allows extra information to be associated with the
           channel. The information to store should be passed in as
           keyword parameters and can later be returned by calling
           :meth:`get_extra_info` with one of the keywords as the name
           to retrieve.

        NrY)rm�update)r�r0rYrYrZ�set_extra_infoAszSSHChannel.set_extra_infocCsdS)znReturn whether the channel supports :meth:`write_eof`

           This method always returns `True`.

        TrYr�rYrYrZ�
can_write_eofNszSSHChannel.can_write_eofcCr�)z�Return the current size of the channel's output buffer

           This method returns how many bytes are currently in the
           channel's output buffer waiting to be written.

        )rxr�rYrYrZ�get_write_buffer_sizeXsz SSHChannel.get_write_buffer_size�high�lowcCsz|dur|durd|nd}|dur|d}d|kr |ks)ntd|�d���|j�d||�||_||_|��dS)a�Set the high- and low-water limits for write flow control

           This method sets the limits used when deciding when to call
           the :meth:`pause_writing() <SSHClientSession.pause_writing>`
           and :meth:`resume_writing() <SSHClientSession.resume_writing>`
           methods on SSH sessions. Writing will be paused when the write
           buffer size exceeds the high-water mark, and resumed when the
           write buffer size equals or drops below the low-water mark.

        NrNirzhigh (high) must be >= low (z) must be >= 0z4Set write buffer limits: low-water=%d, high-water=%d)�
ValueErrorr�r�r�r�r�)r�r5r6rYrYrZr�bs
�z"SSHChannel.set_write_buffer_limitscCs�|jdkr	td��|dur||jvrtd��|sdS|jr.|jdus$J�|j�tt|��}ntt	|�}t
|�}|rAdt|��}nd}|j�
d||dkrNd	nd|�|j�t|�|f�|j|7_|��dS)
a�Write data on the channel

           This method can be called to send data on the channel. If
           an encoding was specified when the channel was created, the
           data should be provided as a string and will be converted
           using that encoding. Otherwise, the data should be provided
           as bytes.

           An extended data type can optionally be provided. For
           instance, this is used from a :class:`SSHServerSession`
           to write data to `stderr`.

           :param data:
               The data to send on the channel
           :param datatype: (optional)
               The extended data type of the data, from :ref:`extended
               data types <ExtendedDataTypes>`
           :type data: `str` or `bytes`
           :type datatype: `int`

           :raises: :exc:`OSError` if the channel isn't open for sending
                    or the extended data type is not valid for this type
                    of channel

        r�r
Nrz to r�zSending %d data byte%s%srr)rr�BrokenPipeErrorr_r r�r��encoderr��bytesr�rr�r�rwr��	bytearrayrxr�)r�r�r��encoded_datar�typenamerYrYrZ�write�s(


�zSSHChannel.write�list_of_datacCsH|jrttd�ttt|���}n
ttd�ttt|���}|�||�S)aWrite a list of data bytes on the channel

           This method can be called to write a list (or any iterable) of
           data bytes to the channel. It is functionality equivalent to
           calling :meth:`write` on each element in the list.

           :param list_of_data:
               The data to send on the channel
           :param datatype: (optional)
               The extended data type of the data, from :ref:`extended
               data types <ExtendedDataTypes>`
           :type list_of_data: iterable of `str` or `bytes`
           :type datatype: `int`

           :raises: :exc:`OSError` if the channel isn't open for sending
                    or the extended data type is not valid for this type
                    of channel

        r�r�)r�rrr#r
r�r:r>)r�r?r�r�rYrYrZ�
writelines�szSSHChannel.writelinescCs,|j�d�|jdkrd|_|��dSdS)aPWrite EOF on the channel

           This method sends an end-of-file indication on the
           channel, after which no more data can be sent. The
           channel remains open, though, and data may still be
           sent in the other direction.

           :raises: :exc:`OSError` if the channel isn't open for sending

        zSending EOFr�r�N)r�r�rrr�r�rYrYrZr��s

�zSSHChannel.write_eofcCs|j�d�d|_dS)a�Pause delivery of incoming data

           This method is used to temporarily suspend delivery of incoming
           channel data. After this call, incoming data will no longer
           be delivered until :meth:`resume_reading` is called. Data will be
           buffered locally up to the configured SSH channel window size,
           but window updates will no longer be sent, eventually causing
           back pressure on the remote system.

           .. note:: Channel close notifications are not suspended by this
                     call. If the remote system closes the channel while
                     delivery is suspended, the channel will be closed even
                     though some buffered data may not have been delivered.

        zReading from channel pausedTN)r�r�r}r�rYrYrZ�
pause_reading�s
zSSHChannel.pause_readingcCs(|jr|j�d�d|_|��dSdS)a�Resume delivery of incoming data

           This method can be called to resume delivery of incoming data
           which was suspended by a call to :meth:`pause_reading`. As soon
           as this method is called, any buffered data will be delivered
           immediately. A pending end-of-file notification may also be
           delivered if one was queued while reading was paused.

        zReading from channel resumedFNr�r�rYrYrZr��s
�zSSHChannel.resume_readingcCs$|jdur
tt|j��|_t|j�S)a�Return the environment for this session

           This method returns the environment set by the client when
           the session was opened. Keys and values are of type `str`
           and this object only provides access to keys and values sent
           as valid UTF-8 strings. Use :meth:`get_environment_bytes`
           if you need to access environment variables with keys or
           values containing binary data or non-UTF-8 encodings.

           On the server, calls to this method should only be made after
           :meth:`session_started <SSHServerSession.session_started>` has
           been called on the :class:`SSHServerSession`. When using the
           stream-based API, calls to this can be made at any time after
           the handler function has started up.

           :returns: A dictionary containing the environment variables
                     set by the client

        N)ro�dictr/rnrr�rYrYrZ�get_environment
s

zSSHChannel.get_environmentcC�
t|j�S)a�Return the environment for this session

           This method returns the environment set by the client when
           the session was opened. Keys and values are of type `bytes`
           and can include arbitrary binary data, with the exception
           of NUL () bytes.

           On the server, calls to this method should only be made after
           :meth:`session_started <SSHServerSession.session_started>` has
           been called on the :class:`SSHServerSession`. When using the
           stream-based API, calls to this can be made at any time after
           the handler function has started up.

           :returns: A dictionary containing the environment variables
                     set by the client

        )rrnr�rYrYrZ�get_environment_bytes's
z SSHChannel.get_environment_bytescCr�)a�Return the command the client requested to execute, if any

           This method returns the command the client requested to
           execute when the session was opened, if any. If the client
           did not request that a command be executed, this method
           will return `None`. On the server, calls to this method
           should only be made after :meth:`session_started
           <SSHServerSession.session_started>` has been called on the
           :class:`SSHServerSession`. When using the stream-based API,
           calls to this can be made at any time after the handler
           function has started up.

        )rpr�rYrYrZ�get_command<�zSSHChannel.get_commandcCr�)a�Return the subsystem the client requested to open, if any

           This method returns the subsystem the client requested to
           open when the session was opened, if any. If the client
           did not request that a subsystem be opened, this method will
           return `None`. On the server, calls to this method should
           only be made after :meth:`session_started
           <SSHServerSession.session_started>` has been called on the
           :class:`SSHServerSession`. When using the stream-based API,
           calls to this can be made at any time after the handler
           function has started up.

        )rqr�rYrYrZ�
get_subsystemMrGzSSHChannel.get_subsystem)r�rI)r��N�r�N�NN)`�__name__�
__module__�__qualname__�__doc__r1�globals�_handler_namesr�r^rrT�__annotations__r_r��AbstractEventLoopr
r�r��propertyr'r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r:rDr�r�r�r�r�r�r*r9rr�r�r�r7rrr	rrrrrrrrrrrrrrr�_packet_handlersr"r�r%r&r'r(r)r,rr/r2r3r4r�r>r
r@r�rAr�rrCrErFrHrYrYrYrZr\Vs4
����
�<
��
�
-



 
	
�
�

�
�
�
'��
�

�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
���
��
�






��
�9��
�


r\cs�eZdZUdZded<eeed<ehZddde	j
deeded	e
d
e
f�fdd�Zd
eedeedeedeeefdedeedededeeefdeedeedededeefdd�Zdedefdd�Zdedefd d!�Zdedefd"d#�Zdee
fd$d%�Zdeefd&d'�Zdee
fd(d)�Z	*d<d+e
d,e
d-e
d.e
dd/f
d0d1�Zd2e
dd/fd3d4�Z d5eee
fdd/fd6d7�Z!d=d8d9�Z"d=d:d;�Z#�Z$S)>�SSHClientChannelzSSH client channelrJrjrlr`rarbrcrdrecs&t��||||||�d|_d|_dSrI)�superr��_exit_status�_exit_signalr���	__class__rYrZr�gs
zSSHClientChannel.__init__�session_factory�commandr��env�request_pty�	term_type�	term_size�
term_modes�x11_forwarding�x11_display�
x11_auth_path�x11_single_connection�agent_forwardingr�c
�s��|j�d�|�d�IdH}|��|�|_|j�|�||_||_||_|�	�D]-\}}|j�
d||�t|tt
f�sAt
|�}t|tt
f�sLt
|�}|�dt|�t|��q*|�r|j�
d|pbd�|sod}}}}n<t|�d	kr�ttttf|�\}}d}}|j�
d
||�nt|�dkr�tt|�\}}}}|j�
d||||�ntd
��d}|�	�D]-\}}|tks�|tkr�td|����t�|t
|��}|j�d||�|t|�t|�7}q�|tt�7}|�dt|p�d�t|�t|�t|�t|�t|��IdH�s|��tt d��|	�r�|j�
d�z|j!�"||
||�IdH}Wn(t�yJ}z|	dk�r8tt#t
|��d�d}|j�d�WYd}~nd}~ww|�r�|\}}}|�dt$|�t|�tt%�&|��t|��IdH}|�s�|j!�rw|j!�'|�|	dk�r�tt#d��|j�d�|
�r�|j�
d�|�d�|�r�|j�d|�|�dt|��IdH}n$|�r�|j�d|�|�dt|��IdH}n|j�d �|�d!�IdH}|�s�|��tt(d"��|j�)�|j!�*|�+�|j�|jS)#zCreate an SSH client sessionzRequesting new SSH sessionssessionN�  Env: %s=%ssenv�  Terminal type: %s�Nonerr��  Terminal size: %sx%srN�%  Terminal size: %sx%s (%sx%s pixels)z8If set, terminal size must be a tuple of 2 or 4 integersr�zInvalid pty mode: z
  Mode %s: %dspty-reqr�zPTY request failed�  X11 forwarding enabled�ignore_failurez'  X11 forwarding attach failure ignoredsx11-reqzX11 forwarding request failedz(  X11 forwarding request failure ignored�  Agent forwarding enabledsauth-agent-req@openssh.com�
  Command: %ssexec�  Subsystem: %ss	subsystem�  Interactive shell requestedsshellzSession request failed),r�r�r"rrlr�rnrprq�itemsr��
isinstancer:r�r%r5r�rrrTr-r7r!r �_pty_mode_namesr.r�r4r6r&r(r(r#rj�attach_x11_listenerr"r3�binascii�b2a_hexr�r$r�r�r�)r�r\r]r�r^r_r`rarbrcrdrerfrgr��key�value�width�height�pixwidth�	pixheight�modes�mode�
mode_valuer��
attach_resultr��
auth_proto�remote_auth�screenr�rYrYrZ�createos��
�
����
����

�
��
�
zSSHClientChannel.creater�cCs6|��}|��|j�d|rdnd�|j�|�dS)z/Process a request to set up XON/XOFF processingz)Received XON/XOFF flow control %s request�enable�disableT)rrr�r�rl�xon_xoff_requested)r�r��
client_can_dorYrYrZ�_process_xon_xoff_request�s
�z*SSHClientChannel._process_xon_xoff_requestcCs8|��d@}|��|j�d|�||_|j�|�dS)z(Process a request to deliver exit status�zReceived exit status %dT)rrr�r�rXrl�exit_status_received)r�r��statusrYrYrZ�_process_exit_status_request�sz-SSHClientChannel._process_exit_status_requestc	Cs�|��}|��}|��}|��}|��z|�d�}|�d�}|�d�}Wnty1td�d�w|j�d|�|j�d|�|j�d|�||||f|_	|j
�||||�dS)	z+Process a request to deliver an exit signalr�utf-8zInvalid exit signal requestNzReceived exit signal %s�  Core dumped: %s�
  Message: %sT)r
rrr�r�r+r�r�r�rYrl�exit_signal_received)	r�r��signal_bytes�core_dumped�	msg_bytes�
lang_bytes�signal�msgr�rYrYrZ�_process_exit_signal_requests$


�z-SSHClientChannel._process_exit_signal_requestcCs|jdur|jS|jr
dSdS)aiReturn the session's exit status

           This method returns the exit status of the session if one has
           been sent. If an exit signal was sent, this method returns -1
           and the exit signal information can be collected by calling
           :meth:`get_exit_signal`. If neither has been sent, this method
           returns `None`.

        N���)rXrYr�rYrYrZ�get_exit_status#s

z SSHClientChannel.get_exit_statuscCr�)a�Return the session's exit signal, if one was sent

           This method returns information about the exit signal sent on
           this session. If an exit signal was sent, a tuple is returned
           containing the signal name, a boolean for whether a core dump
           occurred, a message associated with the signal, and the language
           the message was in. Otherwise, this method returns `None`.

        )rYr�rYrYrZ�get_exit_signal5sz SSHClientChannel.get_exit_signalcCs.|jdur|jS|jrt�|jdd�SdS)a�Return the session's exit status or signal

           This method returns the exit status of the session if one has
           been sent. If an exit signal was sent, this method returns
           the negative of the numeric value of that signal, matching
           the behavior of :meth:`asyncio.SubprocessTransport.get_returncode`.
           If neither has been sent, this method returns `None`.

           :returns: `int` or `None`

        Nr�c)rXrY�_signal_numbersr.r�rYrYrZ�get_returncodeBs


zSSHClientChannel.get_returncoderr{r|r}r~NcCsT|s|r|j�d||||�n|j�d||�|�dt|�t|�t|�t|��dS)a�Change the terminal window size for this session

           This method changes the width and height of the terminal
           associated with this session.

           :param width:
               The width of the terminal in characters
           :param height:
               The height of the terminal in characters
           :param pixwidth: (optional)
               The width of the terminal in pixels
           :param pixheight: (optional)
               The height of the terminal in pixels
           :type width: `int`
           :type height: `int`
           :type pixwidth: `int`
           :type pixheight: `int`

        z0Sending window size change: %sx%s (%sx%s pixels)z!Sending window size change: %sx%ss
window-changeN�r�r�r%r6)r�r{r|r}r~rYrYrZ�change_terminal_sizeVs��z%SSHClientChannel.change_terminal_size�mseccCs"|j�d|�|�dt|��dS)aySend a break to the remote process

           This method requests that the server perform a break
           operation on the remote process or service as described in
           :rfc:`4335`.

           :param msec:
               The duration of the break in milliseconds
           :type msec: `int`

           :raises: :exc:`OSError` if the channel is not open

        zSending %d msec breaksbreakNr�)r�r�rYrYrZ�
send_breakuszSSHClientChannel.send_breakr�cCsXt|t�rzt|}Wntytd|���d�w|j�d|�|�dt|��dS)a}Send a signal to the remote process

           This method can be called to deliver a signal to the remote
           process or service. Signal names should be as described in
           section 6.10 of :rfc:`RFC 4254 <4254#section-6.10>`, or
           can be integer values as defined in the :mod:`signal`
           module, in which case they will be translated to their
           corresponding signal name before being sent.

           .. note:: OpenSSH's SSH server implementation prior to version
                     7.9 does not support this message, so attempts to
                     use :meth:`send_signal`, :meth:`terminate`, or
                     :meth:`kill` with an older OpenSSH SSH server will
                     end up being ignored. This was tracked in OpenSSH
                     `bug 1424`__.

                     __ https://bugzilla.mindrot.org/show_bug.cgi?id=1424

           :param signal:
               The signal to deliver
           :type signal: `str` or `int`

           :raises: | :exc:`OSError` if the channel is not open
                    | :exc:`ValueError` if the signal number is unknown

        zUnknown signal: NzSending %s signalssignal)	rtrT�
_signal_names�KeyErrorr7r�r�r%r5)r�r�rYrYrZ�send_signal�s
�zSSHClientChannel.send_signalcC�|�d�dS)a�Terminate the remote process

           This method can be called to terminate the remote process or
           service by sending it a `TERM` signal.

           :raises: :exc:`OSError` if the channel is not open

           .. note:: If your server-side runs on OpenSSH,
                     this might be ineffective;
                     for more details, see the note in
                     :meth:`send_signal`

        �TERMN�r�r�rYrYrZ�	terminate��zSSHClientChannel.terminatecCr�)a�Forcibly kill the remote process

           This method can be called to forcibly stop the remote process
           or service by sending it a `KILL` signal.

           :raises: :exc:`OSError` if the channel is not open

           .. note:: If your server-side runs on OpenSSH,
                     this might be ineffective;
                     for more details, see the note in
                     :meth:`send_signal`

        �KILLNr�r�rYrYrZ�kill�r�zSSHClientChannel.kill)rrrJ)%rLrMrNrOrRr:rrr^r�rSr
r�rTr�r@rr:r�r.r,rr�r7r�r�r�r��_ExitSignalr�r�r�r�r�r�r��
__classcell__rYrYrZrZrV_s|
�����
��
�����
�����
�
���
�
&rVcspeZdZUdZded<eeed<ehZddde	j
deded	ed
edede
ed
ededef�fdd�Zdeedeeeeeffdd�Zdedefdd�Zdede
efdd�Zdedededdfdd �Zdeddfd!d"�ZdXd#d$�Zdedefd%d&�Z		dYd'e
ed(e
edefd)d*�Zdedefd+d,�Zdedefd-d.�Zdedefd/d0�Zdedefd1d2�Z dedefd3d4�Z!dedefd5d6�Z"de
efd7d8�Z#de$fd9d:�Z%d;ede
efd<d=�Z&de'fd>d?�Z(de
efd@dA�Z)de
efdBdC�Z*dDeddfdEdF�Z+dGeddfdHdI�Z,dJe-eddfdKdL�Z.dMeddfdNdO�Z/dPdQe0fdRedSedTedUeddf
dVdW�Z1�Z2S)Z�SSHServerChannelzSSH server channelrKrjrlr`ra�	allow_pty�line_editor�	line_echo�line_history�max_line_lengthrbrcrdrec
s|t��||||	|
|�tt|�di��}tt|��|_||_||_	||_
||_||_d|_
d|_i|_d|_|j�d�dS)z Initialize an SSH server channel�environmentN)rrrrzNew SSH session requested)rWr�rr)�get_key_optionrBr0rn�
_allow_pty�_line_editor�
_line_echo�
_line_history�_max_line_length�
_term_type�
_term_size�_term_modes�_x11_displayr�r�)
r�r`rar�r�r�r�r�rbrcrdre�env_optrZrYrZr��szSSHServerChannel.__init__r�r�cCsr|jr3ttt|�}ttt|�}t|||j|j|j�}t	||�}tt
t|�}ttt|�}||fS|}||fS)z0Wrap a line editor around the session if enabled)
r�rr�r�r;r%r�r�r�r&r\rr9)r�r��server_chan�server_session�editor_chan�editor_sessionrrYrYrZr��s�
�zSSHServerChannel._wrap_sessionr�cCs�|��}|��}|��}|��}|��}|��}|��|jr+|j�d�r+|j�d�s3|j�d�dSz|�	d�}Wnt
yFtd�d�w||||f}	i}
|j�d|�|sZ|re|j�d||||�n|j�d	||�d
}|t
|�kr�||}|d7}|tks�|tkr�n7|dt
|�kr�t�|t|��}
t�|||d�d
�}|j�d|
|�||
|<|d7}ntd��|t
|�ksu|j�||	|
�}|r�|j�d�|jr�|j�d�||_|	|_|
|_|S|j�d�|S)z+Process a request to open a pseudo-terminal�ptyz%PTY request denied: PTY not permittedFrzInvalid pty requestNrirlrkrrrN�bigz
  Mode %s: %szInvalid pty modes stringz
  PTY createdz  Line editor enabledz  PTY creation failed)r
rrr�rj�check_key_permission�check_certificate_permissionr�r�r�r�r+r�r�r!r rur.r�rT�
from_bytesr�rl�
pty_requestedr�r�r�r�)r�r��term_type_bytesr{r|r}r~rr`rarb�idxr�r�rzr�rYrYrZ�_process_pty_req_requestsh
�
�
��
��z)SSHServerChannel._process_pty_req_requestcCsx|��}|��}|��}|��}|��zt�|�}Wntjy,|j�d�YdSw|j	�
|�|||�|j�dS)z(Process request to enable X11 forwardingz  Invalid X11 auth dataFN)rr
rrrw�a2b_hex�Errorr�r�rjr��_finish_x11_req_request)r�r�r�r��	auth_datar�rYrYrZ�_process_x11_req_requestGs"���z)SSHServerChannel._process_x11_req_requestr�r�r�Nc�sV�|j�||||�IdH|_|jr|j�d�|�d�dS|j�d�|�d�dS)z2Finish processing request to enable X11 forwardingNrmTz  X11 forwarding failedF)rjrvr�r�r�r�)r�r�r�r�rYrYrZr�[s��z(SSHServerChannel._finish_x11_req_requestcCs |��|j�|��|j�dS)z0Process a request to enable ssh-agent forwardingN)rrjr��_finish_agent_req_requestr�rrYrYrZ�2_process_auth_agent_req_at_openssh_dot_com_requestiszCSSHServerChannel._process_auth_agent_req_at_openssh_dot_com_requestc�sF�|j��IdHr|j�d�|�d�dS|j�d�|�d�dS)z4Finish processing request to enable agent forwardingNroTz  Agent forwarding failedF)rj�create_agent_listenerr�r�r�r�rYrYrZr�qs�z*SSHServerChannel._finish_agent_req_requestcCs6|��}|��}|��|j�d||�||j|<dS)z0Process a request to set an environment variablerhT)r
rr�r�rn)r�r�ryrzrYrYrZ�_process_env_request{s
z%SSHServerChannel._process_env_requestr]r�cCs�tt|j�d��}|durtt|j�d��}|dur#|j�d|�|}|dur2||_|j�	|�}|S|durA||_
|j�|�}|S|j��}|S)z8Tell the session what type of channel is being requestedz
force-commandNr]z  Forced command override: %s)
rr�rj�get_certificate_optionr�r�r�rprl�exec_requestedrq�subsystem_requested�shell_requested)r�r]r��forced_commandr�rYrYrZ�_start_session�s"��
�zSSHServerChannel._start_sessioncCs|��|j�d�|��S)z!Process a request to open a shellrr)rr�r�r�rrYrYrZ�_process_shell_request�sz'SSHServerChannel._process_shell_requestcC�N|��}|��z|�d�}Wn
tyYdSw|j�d|�|j|d�S)z&Process a request to execute a commandr�Frp)r]�r
rr�r�r�r�r�)r�r��
command_bytesr]rYrYrZ�_process_exec_request���z&SSHServerChannel._process_exec_requestcCr�)z%Process a request to open a subsystemrFrq)r�r�)r�r��subsystem_bytesr�rYrYrZ�_process_subsystem_request�r�z+SSHServerChannel._process_subsystem_requestcCsz|��}|��}|��}|��}|��|s|r#|j�d||||�n|j�d||�||||f|_|j�||||�dS)z+Process a request to change the window sizez,Received window change: %sx%s (%sx%s pixels)zReceived window change: %sx%sT)rrr�r�r�rl�terminal_size_changed)r�r�r{r|r}r~rYrYrZ�_process_window_change_request�s�z/SSHServerChannel._process_window_change_requestcCsR|��}|��z|�d�}Wn
tyYdSw|j�d|�|j�|�dS)z"Process a request to send a signalrFzReceived %s signalT)r
rr�r�r�r�rl�signal_received)r�r�r�r�rYrYrZ�_process_signal_request�s�z(SSHServerChannel._process_signal_requestcCs*|��}|��|j�d|�|j�|�S)z!Process a request to send a breakzReceived %d msec break)rrr�r�rl�break_received)r�r�r�rYrYrZ�_process_break_request�sz'SSHServerChannel._process_break_requestcCr�)a�Return the terminal type for this session

           This method returns the terminal type set by the client
           when the session was opened. If the client didn't request
           a pseudo-terminal, this method will return `None`. Calls
           to this method should only be made after :meth:`session_started
           <SSHServerSession.session_started>` has been called on the
           :class:`SSHServerSession`. When using the stream-based API,
           calls to this can be made at any time after the handler
           function has started up.

           :returns: A `str` containing the terminal type or `None` if
                     no pseudo-terminal was requested

        )r�r�rYrYrZ�get_terminal_type�sz"SSHServerChannel.get_terminal_typecCr�)a�Return terminal size information for this session

           This method returns the latest terminal size information set
           by the client. If the client didn't set any terminal size
           information, all values returned will be zero. Calls to
           this method should only be made after :meth:`session_started
           <SSHServerSession.session_started>` has been called on the
           :class:`SSHServerSession`. When using the stream-based API,
           calls to this can be made at any time after the handler
           function has started up.

           Also see :meth:`terminal_size_changed()
           <SSHServerSession.terminal_size_changed>` or the
           :exc:`TerminalSizeChanged` exception for how to get notified
           when the terminal size changes.

           :returns: A tuple of four `int` values containing the width and
                     height of the terminal in characters and the width
                     and height of the terminal in pixels

        )r�r�rYrYrZ�get_terminal_sizesz"SSHServerChannel.get_terminal_sizer�cCs|j�|�S)a�Return the requested TTY mode for this session

           This method looks up the value of a POSIX terminal mode
           set by the client when the session was opened. If the client
           didn't request a pseudo-terminal or didn't set the requested
           TTY mode opcode, this method will return `None`. Calls to
           this method should only be made after :meth:`session_started
           <SSHServerSession.session_started>` has been called on the
           :class:`SSHServerSession`. When using the stream-based API,
           calls to this can be made at any time after the handler
           function has started up.

           :param mode:
               POSIX terminal mode taken from :ref:`POSIX terminal modes
               <PTYModes>` to look up
           :type mode: `int`

           :returns: An `int` containing the value of the requested
                     POSIX terminal mode or `None` if the requested
                     mode was not set

        )r�r.�r�r�rYrYrZ�get_terminal_modesz"SSHServerChannel.get_terminal_modecCrD)aReturn the TTY modes for this session

           This method returns a mapping of all the POSIX terminal modes
           set by the client when the session was opened. If the client
           didn't request a pseudo-terminal, this method will return an
           empty mapping. Calls to this method should only be made after
           :meth:`session_started <SSHServerSession.session_started>`
           has been called on the :class:`SSHServerSession`. When using
           the stream-based API, calls to this can be made at any time
           after the handler function has started up.

            :returns: A mapping containing all the POSIX terminal modes
                      set by the client or an empty mapping if no
                      pseudo-terminal was requested

        )rr�r�rYrYrZ�get_terminal_modes7s
z#SSHServerChannel.get_terminal_modescCr�)a�Return the display to use for X11 forwarding

           When X11 forwarding has been requested by the client, this
           method returns the X11 display which should be used to open
           a forwarded connection. If the client did not request X11
           forwarding, this method returns `None`.

           :returns: A `str` containing the X11 display or `None` if
                     X11 forwarding was not requested

        )r�r�rYrYrZ�get_x11_displayKs
z SSHServerChannel.get_x11_displaycCs
|j��S)a�Return the path of the ssh-agent listening socket

           When agent forwarding has been requested by the client,
           this method returns the path of the listening socket which
           should be used to open a forwarded agent connection. If the
           client did not request agent forwarding, this method returns
           `None`.

           :returns: A `str` containing the ssh-agent socket path or
                     `None` if agent forwarding was not requested

        )rj�get_agent_pathr�rYrYrZr�Zs
zSSHServerChannel.get_agent_pathr�cCs*|j�d|rdnd�|�dt|��dS)a�Set whether the client should enable XON/XOFF flow control

           This method can be called to tell the client whether or not
           to enable XON/XOFF flow control, indicating that it should
           intercept Control-S and Control-Q coming from its local
           terminal to pause and resume output, respectively.
           Applications should set client_can_do to `True` to
           enable this functionality or to `False` to tell the client
           to forward Control-S and Control-Q through as normal input.

           :param client_can_do:
               Whether or not the client should enable XON/XOFF flow control
           :type client_can_do: `bool`

        z Sending XON/XOFF flow control %sr�r�sxon-xoffN)r�r�r%r3)r�r�rYrYrZ�set_xon_xoffjs
�zSSHServerChannel.set_xon_xoffr�cC�|�|t�dS)a0Write output to stderr

           This method can be called to send output to the client which
           is intended to be displayed on stderr. If an encoding was
           specified when the channel was created, the data should be
           provided as a string and will be converted using that
           encoding. Otherwise, the data should be provided as bytes.

           :param data:
               The data to send to stderr
           :type data: `str` or `bytes`

           :raises: :exc:`OSError` if the channel isn't open for sending

        N)r>r)r�r�rYrYrZ�write_stderr�szSSHServerChannel.write_stderrr?cCr�)aWrite a list of data bytes to stderr

           This method can be called to write a list (or any iterable) of
           data bytes to the channel. It is functionality equivalent to
           calling :meth:`write_stderr` on each element in the list.

        N)r@r)r�r?rYrYrZ�writelines_stderr�s	z"SSHServerChannel.writelines_stderrr�cCs@|dM}|jdvr|j�d|�|�dt|��|��dSdS)aSend exit status and close the channel

           This method can be called to report an exit status for the
           process back to the client and close the channel. A zero
           exit status is generally returned when the operation was
           successful. After reporting the status, the channel is
           closed.

           :param status:
               The exit status to report to the client
           :type status: `int`

           :raises: :exc:`OSError` if the channel isn't open

        r�>rgr�zSending exit status %dsexit-statusN)rrr�r�r%r6r()r�r�rYrYrZ�exit�s
�zSSHServerChannel.exitFr�r�r�r�r�cCsf|j�d|�|j�d|�|j�d|�|jdvr1|�dt|�t|�t|�t|��|��dSdS)a�Send exit signal and close the channel

           This method can be called to report that the process
           terminated abnormslly with a signal. A more detailed
           error message may also provided, along with an indication
           of whether or not the process dumped core. After
           reporting the signal, the channel is closed.

           :param signal:
               The signal which caused the process to exit
           :param core_dumped: (optional)
               Whether or not the process dumped core
           :param msg: (optional)
               Details about what error occurred
           :param lang: (optional)
               The language the error message is in
           :type signal: `str`
           :type core_dumped: `bool`
           :type msg: `str`
           :type lang: `str`

           :raises: :exc:`OSError` if the channel isn't open

        zSending exit signal %sr�r�>rgr�sexit-signalN)r�r�r�rrr%r5r3r()r�r�r�r�r�rYrYrZ�exit_with_signal�s
��z!SSHServerChannel.exit_with_signalrJrK)3rLrMrNrOrRr;rrr_r�rSr�rTr
r�r�r9rr\r�r7r�r�r:r�r�r�r�r�r�r�r�r�r�r�r�r-r�r�r,r�r�r�r�r�r
r�r�rr�r�rYrYrZrZr��s�
����������

�A��
��
�

��
�
����r�c	sXeZdZdZdeeeddf�fdd�Zdeede	d	e	deef�fd
d�Z
�ZS)�SSHForwardChannelz:SSH channel for forwarding TCP and UNIX domain connectionsr�r�Nc�s8�t��|�IdH|jdur|j��|��dSdS)z0Finish processing a forward channel open requestN)rWr�rlr�r�)r�r�rZrYrZr��s�

�z&SSHForwardChannel._finish_open_requestr\rrc�sj�t�j|g|�R�IdH}|��|�|_|j�|�|j��|jdus(J�|j�|��|j	�|jS)zOpen a forward channelN)
rWr"rrlr�r�rjr�r�r�)r�r\rrr�rZrYrZ�
_open_forward�s�
zSSHForwardChannel._open_forward)rLrMrNrOr*r9rr�r?r:r�r�rYrYrZrZr��s
��

���r�c@s�eZdZdZdeedededededede	efd	d
�Z
deededededede	efdd�Zdeededededede	efd
d�Zdededededdf
dd�Z
dS)�
SSHTCPChannelzSSH TCP channelr\r�host�port�	orig_host�	orig_portr�c�sN�|jd||f||fd�ttt|�||t|�t|�t|�t|��IdH�S)zOpen a TCP channel�r�r��peername�local_peername�remote_peernameN)r2rr<rr�r5r6)r�r\rr�r�r�rrYrYrZ�	_open_tcps����zSSHTCPChannel._open_tcpc���|�|d||||�IdHS)z!Create a new outbound TCP sessionsdirect-tcpipN�r�r�r\r�r�r�rrYrYrZ�connect��
�zSSHTCPChannel.connectc�r)z"Create a new forwarded TCP sessionsforwarded-tcpipNrr	rYrYrZ�acceptrzSSHTCPChannel.accept�	dest_host�	dest_portNcCs|jd||f||fd�dS)�7Set local and remote peer names for inbound connectionsrrN�r2)r�r
rr�rrYrYrZ�set_inbound_peer_namess
�z$SSHTCPChannel.set_inbound_peer_names)rLrMrNrOrArr:r�rTr<rr
rrrYrYrYrZr��sX
�����
�
����
�
����
�
���r�c@s�eZdZdZdeededededeef
dd�Z	deededeefd	d
�Z
deededeefdd�Zd
eddfdd�ZdS)�SSHUNIXChannelzSSH UNIX channelr\r�pathrr�c�s:�|jd|d�ttt|j||t|�g|�R�IdH�S)zOpen a UNIX channelr��rrN)r2rr=rr�r5)r�r\rrrrYrYrZ�
_open_unix+s����zSSHUNIXChannel._open_unixc�s"�|�|d|td�td��IdHS)z"Create a new outbound UNIX sessionsdirect-streamlocal@openssh.comr�rN)rr5r6�r�r\rrYrYrZr
6s
�
�zSSHUNIXChannel.connectc�s�|�|d|td��IdHS)z#Create a new forwarded UNIX sessions!forwarded-streamlocal@openssh.comr�N)rr5rrYrYrZrAs
�
�zSSHUNIXChannel.accept�	dest_pathNcCs|j|dd�dS)rr�rNr)r�rrYrYrZrIsz%SSHUNIXChannel.set_inbound_peer_names)
rLrMrNrOrBrr:r�r=rr
rrrYrYrYrZr(s,
���
�
�
�
�
�rcs�eZdZdZdddejdeedededef�fd	d
�Z	dde
d
eddf�fdd�
Zdde
d
eddf�fdd�
Z
dededeedefdd�Zdeddfdd�Z�ZS)�SSHTunTapChannelzSSH TunTap channelr`rIrarbrcrdrecs t��||||||�d|_dSrI)rWr��_moder�rZrYrZr�Rs
zSSHTunTapChannel.__init__Nr�r�r�cs(|jtkr|dd�}t��||�dS)z8Strip off address family on incoming packets in TUN moderNN)rrErWr�r�rZrYrZr�Ys
zSSHTunTapChannel._accept_datacsD|jtkr|dd?}|dkrtnt}t|�|}t��||�dS)z2Add address family in outbound packets in TUN moderrNN)rrErGrHr6rWr>)r�r�r��version�familyrZrYrZr>as

zSSHTunTapChannel.writer\r��unitc	�s8�||_|dur
t}tt|�|dt|�t|��IdH�S)zOpen a TUN/TAP channelNstun@openssh.com)rrFrr>r�r6)r�r\r�rrYrYrZr�ks���zSSHTunTapChannel.opencCs
||_dS)z Set mode for inbound connectionsN)rr�rYrYrZ�set_modeyr*zSSHTunTapChannel.set_moderI)rLrMrNrOr�rSr
r�rTr�r:rDr�r>rCr>r�rr�rYrYrZrZrOs.�����
��
�rc	@sHeZdZdZdeedededeefdd�Z	dededdfd	d
�Z
dS)�
SSHX11ChannelzSSH X11 channelr\r�rr�c	�s<�|j||fdd�ttt|�|dt|�t|��IdH�S)zOpen an SSH X11 channelrrsx11N)r2rr<r:r�r5r6)r�r\r�rrYrYrZr��s�
���zSSHX11Channel.openNcCs|jd||fd�dS)z6Set local and remote peer name for inbound connectionsrrNr)r�r�rrYrYrZr�s
�z$SSHX11Channel.set_inbound_peer_names)rLrMrNrOrAr:r�rTr<r�rrYrYrYrZrs
��
�rc@s*eZdZdZdeedeefdd�ZdS)�SSHAgentChannelzSSH agent channelr\r�c�s�ttt|�|d�IdH�S)zOpen an SSH agent channelsauth-agent@openssh.comN)rr=r:r�)r�r\rYrYrZr��s���zSSHAgentChannel.openN)rLrMrNrOrBr:r=r�rYrYrYrZr�s

�r)wrOr�rwr�r��rer��_signalr��typesr�typingrrrrrrr	r
rrr
rrrrr�rrrrrrrrrrrrrr r!r"r#r$�editorr%r&�loggingr'�miscr(r)r*r+r,r-r.r/r0r1r2r�r3r4r5r6r7r8r�r9r:r;r<r=r>r?r@rArBrC�streamrD�tuntaprErFrGrHrfrIrJrK�__dict__rLr�rTrRrur�compilerR�varsrsr�r�r�r�r�r\rVr�r�r�rr:rrrrYrYrYrZ�<module>s�  
t!+'0