U
    
W[o                     @   sr   d Z ddl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 G dd	 d	eje	jZd
d ZdS )z4
Support module for making SSH servers with twistd.
    )unix)checkers)factory)portalstrcred)usage)strportsc                       s   e Zd ZdZdZddddgddd	d
gddddgddddg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>] zMakes 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moduliNz:directory to look for moduli in (if different from --data)zdata directory)Zdescrzmoduli directory)r   r   r
   )Z
optActionsc                    sL   t jj| f|| tt| t  tt| tt  d| _	d S )NT)
r   r	   __init__super
addCheckerconch_checkersZUNIXPasswordDatabaseZSSHPublicKeyCheckerZUNIXAuthorizedKeysFiles_usingDefaultAuth)selfakw	__class__ 3/usr/lib/python3/dist-packages/twisted/conch/tap.pyr   %   s    zOptions.__init__c                    s0   | j rg | d< i | d< d| _ t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).
        credCheckersZcredInterfacesFN)r   r   r	   r   )r   Zcheckerr   r   r   r   2   s
    zOptions.addChecker)__name__
__module____qualname__ZsynopsisZlongdescZoptParametersr   ZCompletionsZCompleteDirsZCompleteNetInterfacesZcompDatar   r   __classcell__r   r   r   r   r	      s   





r	   c                 C   sn   t  }t }t|| dg |_| d |_| d p>| d |_| d }| d rb|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   ZOpenSSHFactoryr   ZUnixSSHRealmr   ZPortalgetZdataRootZ
moduliRootr   service)Zconfigtrr   r   r   r   makeService@   s    
r'   N)__doc__Ztwisted.conchr   r   r   Ztwisted.conch.openssh_compatr   Ztwisted.credr   r   Ztwisted.pythonr   Ztwisted.applicationr   r	   ZAuthOptionMixinr'   r   r   r   r   <module>   s   /