summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryvesf <yvesf-git@xapek.org>2011-03-17 08:44:52 +0100
committeryvesf <yvesf-git@xapek.org>2011-03-17 08:44:52 +0100
commit050f39cfa2dac8366391a5443037f400a6ea8624 (patch)
tree08601cfe85df04409e1b1e3042ccce8a8b6d1fde
parentee64aabc5ffb4cf7c47cc3e3bda614343132ee7b (diff)
downloadoffssh-050f39cfa2dac8366391a5443037f400a6ea8624.tar.gz
offssh-050f39cfa2dac8366391a5443037f400a6ea8624.zip
remove nobody uid request from .py; accept all user/pw combinations
-rw-r--r--.gitignore3
-rw-r--r--offssh.py36
2 files changed, 35 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e332aa8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*~
+*.pid
+*.log
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__':