From 050f39cfa2dac8366391a5443037f400a6ea8624 Mon Sep 17 00:00:00 2001 From: yvesf Date: Thu, 17 Mar 2011 08:44:52 +0100 Subject: remove nobody uid request from .py; accept all user/pw combinations --- offssh.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'offssh.py') diff --git a/offssh.py b/offssh.py index 6bca574..725affc 100644 --- a/offssh.py +++ b/offssh.py @@ -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__': -- cgit v1.2.1