root/trunk/twisted/conch/tap.py

Revision 27097, 1.6 KB (checked in by therve, 14 months ago)

Merge conch-tap-fix-3871-2

Author: therve
Reviewers: exarkun, mwh
Fixes #3871

Fixes a bad import in twisted.conch.tap preventing from running it at all
and add some test coverage for it.

Line 
1# -*- test-case-name: twisted.conch.test.test_tap -*-
2# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
3# See LICENSE for details.
4
5"""
6Support module for making SSH servers with twistd.
7"""
8
9from twisted.conch import checkers, unix
10from twisted.conch.openssh_compat import factory
11from twisted.cred import portal
12from twisted.python import usage
13from twisted.application import strports
14try:
15    from twisted.cred import pamauth
16except ImportError:
17    pamauth = None
18
19
20
21class Options(usage.Options):
22    synopsis = "[-i <interface>] [-p <port>] [-d <dir>] "
23    longdesc = "Makes a Conch SSH server."
24    optParameters = [
25         ["interface", "i", "", "local interface to which we listen"],
26         ["port", "p", "22", "Port on which to listen"],
27         ["data", "d", "/etc", "directory to look for host keys in"],
28         ["moduli", "", None, "directory to look for moduli in "
29                              "(if different from --data)"]
30    ]
31    zsh_actions = {"data" : "_dirs", "moduli" : "_dirs"}
32
33
34def makeService(config):
35    t = factory.OpenSSHFactory()
36    t.portal = portal.Portal(unix.UnixSSHRealm())
37    t.portal.registerChecker(checkers.UNIXPasswordDatabase())
38    t.portal.registerChecker(checkers.SSHPublicKeyDatabase())
39    if pamauth is not None:
40        from twisted.cred.checkers import PluggableAuthenticationModulesChecker
41        t.portal.registerChecker(PluggableAuthenticationModulesChecker())
42    t.dataRoot = config['data']
43    t.moduliRoot = config['moduli'] or config['data']
44    port = config['port']
45    if config['interface']:
46        # Add warning here
47        port += ':interface='+config['interface']
48    return strports.service(port, t)
Note: See TracBrowser for help on using the browser.