o
    ¯bv  ã                   @   sj   d 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 ddlmZ G dd„ dejejƒZd	d
„ ZdS )z4
Support module for making SSH servers with twistd.
é    )Ústrports)ÚcheckersÚunix)Úfactory)ÚportalÚstrcred)Úusagec                       st   e Zd ZdZdZg d¢g d¢g d¢g d¢gZejejdd�ejd	d�e 	¡ d
œd�Z
‡ fdd„Z‡ fdd„Z‡  ZS )ÚOptionsz([-i <interface>] [-p <port>] [-d <dir>] zÚMakes a Conch SSH server.  If no authentication methods are specified, the default authentication methods are UNIX passwords and SSH public keys.  If --auth options are passed, only the measures specified will be used.)Ú	interfaceÚiÚ z"local interface to which we listen)ÚportÚpztcp:22zPort on which to listen)ÚdataÚdz/etcz"directory to look for host keys in)Úmodulir   Nz:directory to look for moduli in (if different from --data)zdata directory)Údescrzmoduli directory)r   r   r
   )Ú
optActionsc                    sJ   t jj| g|¢R i |¤Ž tƒ  t ¡ ¡ tƒ  t t ¡ ¡¡ d| _	d S )NT)
r   r	   Ú__init__ÚsuperÚ
addCheckerÚconch_checkersÚUNIXPasswordDatabaseÚSSHPublicKeyCheckerÚUNIXAuthorizedKeysFilesÚ_usingDefaultAuth)ÚselfÚaÚkw©Ú	__class__© ú3/usr/lib/python3/dist-packages/twisted/conch/tap.pyr   +   s   ÿ
zOptions.__init__c                    s,   | j rg | d< i | d< d| _ tƒ  |¡ dS )z»
        Add the checker specified.  If any checkers are added, the default
        checkers are automatically cleared and the only checkers will be the
        specified one(s).
        ÚcredCheckersÚcredInterfacesFN)r   r   r   )r   Úcheckerr   r!   r"   r   8   s
   zOptions.addChecker)Ú__name__Ú
__module__Ú__qualname__ÚsynopsisÚlongdescÚoptParametersr   ÚCompletionsÚCompleteDirsÚCompleteNetInterfacesÚcompDatar   r   Ú__classcell__r!   r!   r   r"   r	      s"    ÿü

ýÿr	   c                 C   sn   t  ¡ }t ¡ }t ||  dg ¡¡|_| d |_| d p| d |_| d }| d r1|d| d  7 }t	 
||¡S )aH  
    Construct a service for operating a SSH server.

    @param config: An L{Options} instance specifying server options, including
        where server keys are stored and what authentication methods to use.

    @return: A L{twisted.application.service.IService} provider which contains
        the requested SSH server.
    r#   r   r   r   r
   z:interface=)r   ÚOpenSSHFactoryr   ÚUnixSSHRealmr   ÚPortalÚgetÚdataRootÚ
moduliRootr   Úservice)ÚconfigÚtÚrr   r!   r!   r"   ÚmakeServiceE   s   
r;   N)Ú__doc__Útwisted.applicationr   Útwisted.conchr   r   r   Útwisted.conch.openssh_compatr   Útwisted.credr   r   Útwisted.pythonr   r	   ÚAuthOptionMixinr;   r!   r!   r!   r"   Ú<module>   s   5