From 92b1c8226cd791122b83fa87dc5fc8cef5703e3d Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Thu, 26 May 2005 06:50:17 +0000 Subject: [PATCH] SASL auth is back, ths Alexey --- src/common/xmpp/auth.py | 18 +++++++++++------- src/common/xmpp/client.py | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/common/xmpp/auth.py b/src/common/xmpp/auth.py index b96d09af4..709942315 100644 --- a/src/common/xmpp/auth.py +++ b/src/common/xmpp/auth.py @@ -96,20 +96,24 @@ class NonSASL(PlugIn): class SASL(PlugIn): """ Implements SASL authentication. """ + def __init__(self,username,password): + PlugIn.__init__(self) + self.username=username + self.password=password + def plugin(self,owner): if not self._owner.Dispatcher.Stream._document_attrs.has_key('version'): self.startsasl='not-supported' - elif self._owner.Dispatcher.Stream.features: - try: self.FeaturesHandler(self._owner.Dispatcher,self._owner.Dispatcher.Stream.features) - except NodeProcessed: pass + elif self._owner.Dispatcher.Stream.features: + try: self.FeaturesHandler(self._owner.Dispatcher,self._owner.Dispatcher.Stream.features) + except NodeProcessed: pass else: self.startsasl=None - def auth(self,username,password): + def auth(self): """ Start authentication. Result can be obtained via "SASL.startsasl" attribute and will be either "success" or "failure". Note that successfull auth will take at least two Dispatcher.Process() calls. """ - self.username=username - self.password=password - if self._owner.Dispatcher.Stream.features: + if self.startsasl: pass + elif self._owner.Dispatcher.Stream.features: try: self.FeaturesHandler(self._owner.Dispatcher,self._owner.Dispatcher.Stream.features) except NodeProcessed: pass else: self._owner.RegisterHandler('features',self.FeaturesHandler,xmlns=NS_STREAMS) diff --git a/src/common/xmpp/client.py b/src/common/xmpp/client.py index 9cc4c7fce..ded76b35c 100644 --- a/src/common/xmpp/client.py +++ b/src/common/xmpp/client.py @@ -189,14 +189,14 @@ class Client(CommonClient): while not self.Dispatcher.Stream._document_attrs and self.Process(): pass if self.Dispatcher.Stream._document_attrs.has_key('version') and self.Dispatcher.Stream._document_attrs['version']=='1.0': while not self.Dispatcher.Stream.features and self.Process(): pass # If we get version 1.0 stream the features tag MUST BE presented - if sasl: auth.SASL().PlugIn(self) + if sasl: auth.SASL(user,password).PlugIn(self) if not sasl or self.SASL.startsasl=='not-supported': if not resource: resource='xmpppy' if auth.NonSASL(user,password,resource).PlugIn(self): self.connected+='+old_auth' return 'old_auth' return - self.SASL.auth(user,password) + self.SASL.auth() while self.SASL.startsasl=='in-process' and self.Process(): pass if self.SASL.startsasl=='success': auth.Bind().PlugIn(self)