| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | """ |
|---|
| 6 | Support module for making SSH servers with twistd. |
|---|
| 7 | """ |
|---|
| 8 | |
|---|
| 9 | from twisted.conch import checkers, unix |
|---|
| 10 | from twisted.conch.openssh_compat import factory |
|---|
| 11 | from twisted.cred import portal |
|---|
| 12 | from twisted.python import usage |
|---|
| 13 | from twisted.application import strports |
|---|
| 14 | try: |
|---|
| 15 | from twisted.cred import pamauth |
|---|
| 16 | except ImportError: |
|---|
| 17 | pamauth = None |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | class 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 | |
|---|
| 34 | def 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 | |
|---|
| 47 | port += ':interface='+config['interface'] |
|---|
| 48 | return strports.service(port, t) |
|---|