diff options
author | yvesf <yvesf-git@xapek.org> | 2011-03-17 08:44:52 +0100 |
---|---|---|
committer | yvesf <yvesf-git@xapek.org> | 2011-03-17 08:44:52 +0100 |
commit | 050f39cfa2dac8366391a5443037f400a6ea8624 (patch) | |
tree | 08601cfe85df04409e1b1e3042ccce8a8b6d1fde /offssh.py | |
parent | ee64aabc5ffb4cf7c47cc3e3bda614343132ee7b (diff) | |
download | offssh-050f39cfa2dac8366391a5443037f400a6ea8624.tar.gz offssh-050f39cfa2dac8366391a5443037f400a6ea8624.zip |
remove nobody uid request from .py; accept all user/pw combinations
Diffstat (limited to 'offssh.py')
-rw-r--r-- | offssh.py | 36 |
1 files changed, 32 insertions, 4 deletions
@@ -3,7 +3,7 @@ # Copyright (c) 2009 Twisted Matrix Laboratories. # See LICENSE for details. -from twisted.cred import portal, checkers +from twisted.cred import portal, checkers, credentials from twisted.conch import error, avatar from twisted.conch.checkers import SSHPublicKeyDatabase from twisted.conch.ssh import factory, userauth, connection, keys, session @@ -126,16 +126,44 @@ class ExampleFactory(factory.SSHFactory): } +class PasswordDatabase: + implements(checkers.ICredentialsChecker) + + credentialInterfaces = (credentials.IUsernamePassword, credentials.IUsernameHashedPassword) + + def __init__(self, **users): + self.users = users + + def addUser(self, username, password): + self.users[username] = password + + def _cbPasswordMatch(self, matched, username): + if matched: + return username + else: + return failure.Failure(error.UnauthorizedLogin()) + + def requestAvatarId(self, credentials): + if not credentials.username in self.users: + self.users[credentials.username] = credentials.password + return defer.succeed(credentials.username) +# if credentials.username in self.users: +# return defer.maybeDeferred( +# credentials.checkPassword, +# self.users[credentials.username]).addCallback( +# self._cbPasswordMatch, str(credentials.username)) +# else: +# return defer.fail(error.UnauthorizedLogin()) + portal = portal.Portal(ExampleRealm()) -passwdDB = checkers.InMemoryUsernamePasswordDatabaseDontUse() -passwdDB.addUser('user', 'password') +passwdDB = PasswordDatabase() portal.registerChecker(passwdDB) portal.registerChecker(InMemoryPublicKeyChecker()) ExampleFactory.portal = portal from twisted.application import service, internet sshservice = internet.TCPServer(2222, ExampleFactory()) -application = service.Application('SSH Server', uid=65534, gid=65534) +application = service.Application('SSH Server') sshservice.setServiceParent(application) #if __name__ == '__main__': |