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: //lib/python3/dist-packages/twisted/conch/ssh/__pycache__/session.cpython-38.pyc
U

��W[�+�
@s>dZddlmZmZddlZddlZddlZddlZddlm	Z	ddl
mZmZddl
mZddlmZmZddlmZdd	lmZmZmZGd
d�dej�ZGdd
�d
ej�ZGdd�d�Zdd�Zdd�Zddddddddddddd g
Z e	ej!�Gd!d"�d"ej��Z"Gd#d$�d$ej#�Z$d%d&�Z%d'd(�Z&d)d*�Z'd+d,�Z(dS)-z�
This module contains the implementation of SSHSession, which (by default)
allows access to a shell and a python interpreter over SSH.

Maintainer: Paul Swartz
�)�division�absolute_importN)�implementer)�
interfaces�protocol)�log)�	_bytesChr�
networkString)�ISession)�common�channel�
connectionc@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�
SSHSessionssessioncOs*tjj|f|�|�d|_d|_d|_dS�N�)r�
SSHChannel�__init__�buf�client�session)�self�args�kw�r�;/usr/lib/python3/dist-packages/twisted/conch/ssh/session.pyrszSSHSession.__init__cCsrt�|�\}}t�d|�|j�||�}|r`t|�}t|�}|�|�|�t	|��||_
dSt�d�dSdS)Nzasking for subsystem "%s"�zfailed to get subsystemr)r�getNSr�msg�avatarZlookupSubsystem�SSHSessionProcessProtocol�wrapProcessProtocolZmakeConnection�wrapProtocolr)r�dataZ	subsystem�ignoredr�pp�protorrr�request_subsystem%s

zSSHSession.request_subsystemcCsZt�d�|jst|j�|_zt|�}|j�|�Wnt��YdSX||_dSdS)Nz
getting shellrr)	rrrr
rrZ	openShell�deferrr)rr"r$rrr�
request_shell4s
zSSHSession.request_shellcCsn|jst|j�|_t�|�\}}t�d|�zt|�}|j�||�Wnt�	�YdSX||_
dSdS)Nzexecuting command "%s"rr)rr
rrrrrrZexecCommandr'r)rr"�fr$rrr�request_execBszSSHSession.request_execcCsf|jst|j�|_t|�\}}}t�d||f�z|j�|||�Wnt��YdSXdSdS)Nzpty request: %r %rrr)rr
r�parseRequest_pty_reqrrZgetPty�err)rr"�termZ
windowSize�modesrrr�request_pty_reqQszSSHSession.request_pty_reqcCsT|jst|j�|_t|�}z|j�|�Wn t�d�t��YdSXdSdS)Nzerror changing window sizerr)rr
r�parseRequest_window_changeZ
windowChangedrrr,)rr"�winSizerrr�request_window_change^s
z SSHSession.request_window_changecCs*|js|j|7_dS|jj�|�dS�N)rr�	transport�write�rr"rrr�dataReceivedkszSSHSession.dataReceivedcCs@|tjkr.|jr<t|jjd�r<|jj�|�nt�d|�dS)N�writeErrzweird extended data: %s)r
�EXTENDED_DATA_STDERRr�hasattrr4r8rr)rZdataTyper"rrr�extReceivedrs
zSSHSession.extReceivedcCs(|jr|j��n|jr$|j�|�dSr3)r�eofReceivedr�connZ	sendClose�rrrrr<yszSSHSession.eofReceivedcCs(|jr|j��n|jr$|jj��dSr3)r�closedrr4�loseConnectionr>rrrr?szSSHSession.closedcCs"|jr|jj��tj�|�dSr3)rr4r@rrr>rrrr@�szSSHSession.loseConnectionN)�__name__�
__module__�__qualname__�namerr&r(r*r/r2r7r;r<r?r@rrrrrs

	rc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�_ProtocolWrapperzS
    This class wraps a L{Protocol} instance in a L{ProcessProtocol} instance.
    cCs
||_dSr3�r%�rr%rrrr�sz_ProtocolWrapper.__init__cCs|j��dSr3)r%�connectionMader>rrrrH�rz_ProtocolWrapper.connectionMadecCs|j�|�dSr3�r%r7r6rrr�outReceived�rz_ProtocolWrapper.outReceivedcCs|j�|�dSr3)r%�connectionLost�r�reasonrrr�processEnded�rz_ProtocolWrapper.processEndedN)rArBrC�__doc__rrHrJrNrrrrrE�s
rEc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�_DummyTransportcCs
||_dSr3rFrGrrrr�sz_DummyTransport.__init__cCs|jj�|�dSr3)r%r4r5r6rrrr7�sz_DummyTransport.dataReceivedcCs|j�|�dSr3rIr6rrrr5�sz_DummyTransport.writecCs|�d�|��dSr)r5�join�r�seqrrr�
writeSequence�sz_DummyTransport.writeSequencecCs|j�tj�dSr3)r%rKrZconnectionDoner>rrrr@�sz_DummyTransport.loseConnectionN)rArBrCrr7r5rTr@rrrrrP�s
rPcCst|tj�rt|�S|SdSr3)�
isinstancer�ProtocolrE)�instrrrr �sr cCst|�Sr3)rPrFrrrr!�sr!ZABRTZALRMZFPEZHUPZILLZINTZKILL�PIPEZQUITZSEGVZTERMZUSR1ZUSR2c@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
ddd�Zdd�Zd dd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS)!rz�I am both an L{IProcessProtocol} and an L{ITransport}.

    I am a transport to the remote endpoint and a process protocol to the
    local subsystem.
    NcCs||_d|_dS)NF)r�lostOutOrErrFlag)rrrrrr�sz"SSHSessionProcessProtocol.__init__cCs$|jjr |j�|jj�d|j_dSr3)rrr4r5r>rrrrH�sz(SSHSessionProcessProtocol.connectionMadecCs|j�|�dSr3�rr5r6rrrrJ�sz%SSHSessionProcessProtocol.outReceivedcCs|j�tj|�dSr3)rZ
writeExtendedr
r9)rr,rrr�errReceived�sz%SSHSessionProcessProtocol.errReceivedcCs"|jr|jj�|j�nd|_dS)zW
        EOF should only be sent when both STDOUT and STDERR have been closed.
        TN)rYrr=ZsendEOFr>rrr�outConnectionLost�sz+SSHSessionProcessProtocol.outConnectionLostcCs|��dS)z*
        See outConnectionLost().
        N)r\r>rrr�errConnectionLost�sz+SSHSessionProcessProtocol.errConnectionLostcCs|j��dSr3�rr@rLrrrrK�sz(SSHSessionProcessProtocol.connectionLostcCs�|jdkr�i|_tD]*}d|}tt|d�}|dk	r||j|<qtj��D]:\}}|�d�rJ|�d�sJ||jkrJ|dtj|j|<qJ|j|S)z:
        Get a signal name given a signal number.
        NZSIGZSIG_�@)	�_signalValuesToNames�SUPPORTED_SIGNALS�getattr�signal�__dict__�items�
startswith�sys�platform)rZsignum�signameZsigvalue�k�vrrr�_getSignalName�s

z(SSHSessionProcessProtocol._getSignalNamec
Cs�|dk	r�|j}|jdk	r�|�|j�}ttdd�dk	rVt�|j�rVt�d|f�d}nt�d|f�d}|j	j
�|j	dt�
t|dd���t|�t�
d	�t�
d	��n:|jdk	r�t�d
|jf�|j	j
�|j	dt�d|j��|j	��dS)
z�
        When we are told the process ended, try to notify the other side about
        how the process ended using the exit-signal or exit-status requests.
        Also, close the channel.
        N�	WCOREDUMPzexitSignal: %s (core dumped)rzexitSignal: %srsexit-signal�rzexitCode: %rsexit-status�>L)�valuercrlrb�osrmZstatusrrrr=ZsendRequestr�NSr	�chrZexitCode�struct�packr@)rrMr,riZ
coreDumpedrrrrNs4

����
�z&SSHSessionProcessProtocol.processEndedcCs|jjj��S)z>
        Return the host from my session's transport.
        )rr=r4�getHostr>rrrrvsz!SSHSessionProcessProtocol.getHostcCs|jjj��S)z>
        Return the peer from my session's transport.
        )rr=r4�getPeerr>rrrrw#sz!SSHSessionProcessProtocol.getPeercCs|j�|�dSr3rZr6rrrr5*szSSHSessionProcessProtocol.writecCs|j�d�|��dSr)rr5rQrRrrrrT.sz'SSHSessionProcessProtocol.writeSequencecCs|j��dSr3r^r>rrrr@2sz(SSHSessionProcessProtocol.loseConnection)N)N)rArBrCrOr`rrHrJr[r\r]rKrlrNrvrwr5rTr@rrrrr�s 	

rc@seZdZdd�ZdS)�SSHSessionClientcCs|jr|j�|�dSr3)r4r5r6rrrr79szSSHSessionClient.dataReceivedN)rArBrCr7rrrrrx7srxc	sxt�|�\}}t�d|dd��\}}}}t�|dd��\�}||||f}�fdd�tdt��dd�D��||�fS)	z�Parse the data from a pty-req request into usable data.

    @returns: a tuple of (terminal type, (rows, cols, xpixel, ypixel), modes)
    �>4LN�c
s@g|]8}t�||d��t�d�|d|d��df�qS)rro�r)�ordrt�unpack)�.0�i�r.rr�
<listcomp>Gs�z(parseRequest_pty_req.<locals>.<listcomp>rrr{)rrrtr}�range�len)	r"r-�rest�cols�rows�xpixel�ypixelr#r1rr�rr+>s
�r+c
Cs>|\}}}}t�|�}t�d||||�}t�|�}	|||	S)z�
    Pack a pty-req request so that it is suitable for sending.

    NOTE: modes must be packed before being sent here.

    @type geometry: L{tuple}
    @param geometry: A tuple of (rows, columns, xpixel, ypixel)
    ry)rrrrtru)
r-�geometryr.r�r�r�r�Z
termPackedZ
winSizePackedZmodesPackedrrr�packRequest_pty_reqKs
	

r�cCs t�d|�\}}}}||||fS)zzParse the data from a window-change request into usuable data.

    @returns: a tuple of (rows, cols, xpixel, ypixel)
    ry)rtr})r"r�r�r�r�rrrr0Zsr0cCs|\}}}}t�d||||�S)z�
    Pack a window-change request so that it is suitable for sending.

    @type geometry: L{tuple}
    @param geometry: A tuple of (rows, columns, xpixel, ypixel)
    ry)rtru)r�r�r�r�r�rrr�packRequest_window_changebsr�))rOZ
__future__rrrtrcrgrqZzope.interfacerZtwisted.internetrrZtwisted.pythonrZtwisted.python.compatrrsr	Ztwisted.conch.interfacesr
Ztwisted.conch.sshrrr
rrZProcessProtocolrErPr r!raZ
ITransportrrVrxr+r�r0r�rrrr�<module>s>q
�y