1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 Support for asynchronously authenticating using PAM.
11 import getpass, threading, os
13 from twisted.internet import threads, defer
15 def pamAuthenticateThread(service, user, conv):
17 from twisted.internet import reactor
24 ev = threading.Event()
31 reactor.callFromThread(d.addCallbacks, cb, eb)
37 raise done[1].type, done[1].value
39 return callIntoPAM(service, user, _conv)
41 def callIntoPAM(service, user, conv):
46 pam.set_item(PAM.PAM_USER, user)
47 pam.set_item(PAM.PAM_CONV, conv)
53 pam.authenticate() # these will raise
62 for i in range(len(items)):
63 message, kind = items[i]
64 if kind == 1: # password
65 p = getpass.getpass(message)
67 elif kind == 2: # text
68 p = raw_input(message)
74 return defer.fail('foo')
75 d = defer.succeed(resp)
78 def pamAuthenticate(service, user, conv):
79 return threads.deferToThread(pamAuthenticateThread, service, user, conv)