def handle_request_set_password(self, request): username = self._username password = request.options['password']['password'] new_password = request.options['password']['new_password'] CORE.info('Changing password of user %r' % (username,)) pam = PamAuth(str(self.i18n.locale)) change_password = notifier.Callback(pam.change_password, username, password, new_password) password_changed = notifier.Callback(self._password_changed, request, new_password) thread = threads.Simple('change_password', change_password, password_changed) thread.run()
def authenticate(self, msg): # PAM MUST be initialized outside of a thread. Otherwise it segfaults e.g. with pam_saml.so. # See http://pam-python.sourceforge.net/doc/html/#bugs args = msg.body.copy() locale = args.pop('locale', None) args.pop('auth_type', None) args.setdefault('new_password', None) args.setdefault('username', '') args.setdefault('password', '') self.pam = PamAuth(locale) thread = threads.Simple('pam', notifier.Callback(self.__authenticate_thread, **args), notifier.Callback(self.__authentication_result, msg)) thread.run()
def my_thread(words): for i in range(5): print i, words time.sleep(0.1) return words def done_with_it(thread, result, another): print "Thread '%s' is finished" % thread.name print "Argument:", another print "Result:", result def doing_something_else(): print 'doing something else' return True if __name__ == '__main__': notifier.init(notifier.GENERIC) # task = threads.Simple( 'test', # notifier.Callback( my_thread, [ 'hello', 'world' ] ), # done_with_it ) task = threads.Simple('test', notifier.Callback(my_thread, ['hello', 'world']), notifier.Callback(done_with_it, 'another argument')) task.run() notifier.timer_add(1000, doing_something_else) notifier.loop()
def authenticate(self): self._pam.set_item(PAM.PAM_USER, self._username) ask = threads.Simple('pam', self._ask_pam, self._auth_result) ask.run()