
    Vhl                        d Z ddlmZ ddlmZmZ ddlmZmZm	Z	 ddl
mZ ddlmZ ddlmZmZ ddlmZ dd	lmZmZ  G d
 d      Z G d d      Z eej0                         G d d             Z G d dej4                        Zd Zy)z\
TAP plugin for creating telnet- and ssh-accessible manhole servers.

@author: Jp Calderone
    )implementer)servicestrports)manholemanhole_sshtelnet)insults)keys)checkersportal)protocol)filepathusagec                       e Zd Zd Zd Zy)makeTelnetProtocolc                     || _         y N)r   )selfr   s     I/home/dcms/DCMS/lib/python3.12/site-packages/twisted/conch/manhole_tap.py__init__zmakeTelnetProtocol.__init__   s	        c                 h    t         j                  }| j                  f}t        j                  |g| S r   )r   AuthenticatingTelnetProtocolr   TelnetTransport)r   authargss      r   __call__zmakeTelnetProtocol.__call__   s.    22~%%d2T22r   N__name__
__module____qualname__r   r    r   r   r   r      s    3r   r   c                       e Zd Zd Zd Zy)chainedProtocolFactoryc                     || _         y r   )	namespace)r   r&   s     r   r   zchainedProtocolFactory.__init__    s	    "r   c                 ^    t        j                  t        j                  | j                        S r   )r	   ServerProtocolr   ColoredManholer&   r   s    r   r   zchainedProtocolFactory.__call__#   s    %%g&<&<dnnMMr   Nr   r"   r   r   r$   r$      s    #Nr   r$   c                       e Zd Zd Zd Zy)_StupidRealmc                 .    || _         || _        || _        y r   )protocolFactoryprotocolArgsprotocolKwArgs)r   protoakws       r   r   z_StupidRealm.__init__)   s    $ r   c                     t         j                  |v r8t         j                   | j                  | j                  i | j                  d fS t               )Nc                       y r   r"   r"   r   r   <lambda>z,_StupidRealm.requestAvatar.<locals>.<lambda>3   s    r   )r   ITelnetProtocolr.   r/   r0   NotImplementedError)r   avatarId
interfacess      r   requestAvatarz_StupidRealm.requestAvatar.   sR    !!Z/&&$$$d&7&7O4;N;NO 
 "##r   N)r   r    r!   r   r;   r"   r   r   r,   r,   '   s    !
$r   r,   c                   @    e Zd Zg dg dg dg dg dg dgZd Zd Zy	)
Options)
telnetPorttNzMstrports description of the address on which to listen for telnet connections)sshPortsNzJstrports description of the address on which to listen for ssh connections)passwdpz/etc/passwdz1name of a passwd(5)-format username/password file)	sshKeyDirN<USER DATA DIR>z2Directory where the autogenerated SSH key is kept.)
sshKeyNameNz
server.keyz&Filename of the autogenerated SSH key.)
sshKeySizeNi   z,Size of the automatically generated SSH key.c                 L    t         j                  j                  |        d | d<   y )Nr&   )r   r=   r   r*   s    r   r   zOptions.__init__\   s    t$ [r   c                 D    | d   | d   t        j                  d      y y )Nr>   r@   z<At least one of --telnetPort and --sshPort must be specified)r   
UsageErrorr*   s    r   postOptionszOptions.postOptions`   s5    %$y/*A""N  +B%r   N)r   r    r!   optParametersr   rK   r"   r   r   r=   r=   8   s2    	
	
	
	
 	URA!MF!r   r=   c                    t        j                         }| d   }|i }t        j                  | d         }| d   rt	        t
        j                  t        j                  t        j                  |      }t        j                  ||g      }t        j                         }t        |      |_        t!        j                   | d   |      }|j#                  |       | d   rt%        j&                         }t)        |      |_        t        j                  ||g      }	t%        j*                  |	      }
| d   dk7  r| d   }nddlm}  |       }t1        j2                  |      j5                  | d	         }t7        j8                  |t;        | d
               }||
j<                  d<   ||
j>                  d<   t!        j                   | d   |
      }|j#                  |       |S )a;  
    Create a manhole server service.

    @type options: L{dict}
    @param options: A mapping describing the configuration of
    the desired service.  Recognized key/value pairs are::

        "telnetPort": strports description of the address on which
                      to listen for telnet connections.  If None,
                      no telnet service will be started.

        "sshPort": strports description of the address on which to
                   listen for ssh connections.  If None, no ssh
                   service will be started.

        "namespace": dictionary containing desired initial locals
                     for manhole connections.  If None, an empty
                     dictionary will be used.

        "passwd": Name of a passwd(5)-format username/password file.

        "sshKeyDir": The folder that the SSH server key will be kept in.

        "sshKeyName": The filename of the key.

        "sshKeySize": The size of the key, in bits. Default is 4096.

    @rtype: L{twisted.application.service.IService}
    @return: A manhole service.
    r&   rB   r>   r@   rD   rE   r   )getDataDirectoryrF   rG   s   ssh-rsa) r   MultiServicer   FilePasswordDBr,   r   TelnetBootstrapProtocolr	   r(   r   r)   r   Portalr   ServerFactoryr   r   setServiceParentr   TerminalRealmr$   ConchFactorytwisted.python._appdirsrN   r   FilePathchildr
   _getPersistentRSAKeyint
publicKeysprivateKeys)optionssvcr&   checkertelnetRealmtelnetPortaltelnetFactorytelnetServicesshRealm	sshPortal
sshFactorykeyDirrN   keyLocationsshKey
sshServices                   r   makeServicerl   g   s   > 


 C$I	%%gh&78G|"**""""	
 }}[7)< ..0!3L!A (()>N&&s+y,,.*@*K'MM(WI6	 --i8
;#44[)F@%'F''/55gl6KL**;GL<Q8RS,2
j)-3
z*%%gi&8*E
##C(Jr   N)__doc__zope.interfacer   twisted.applicationr   r   twisted.conchr   r   r   twisted.conch.insultsr	   twisted.conch.sshr
   twisted.credr   r   twisted.internetr   twisted.pythonr   r   r   r$   IRealmr,   r=   rl   r"   r   r   <module>rw      sv    ' 1 6 6 ) " ) % *3 3N N V]]$ $ $ ,emm ,^Mr   