# HG changeset patch # User Tobias Markmann # Date 1251401376 -7200 # Node ID 28d841403a21716604e0d0b7b15ba5574f8b9e47 # Parent 8505e1da5408b33c9c0e9a390cd16dfdfc10b05f Adjust SASL PLAIN mechanism to the new API. diff -r 8505e1da5408 -r 28d841403a21 util/sasl.lua --- a/util/sasl.lua Sun Aug 16 23:20:02 2009 +0200 +++ b/util/sasl.lua Thu Aug 27 21:29:36 2009 +0200 @@ -101,38 +101,45 @@ -- select a mechanism to use function method:select(mechanism) - + self.mech_i = mechanisms[mechanism] + if self.mech_i == nil then return false; end + return true; end -- feed new messages to process into the library function method:process(message) - + if message == "" or message == nil then return "failure", "malformed-request" end + return self.mech_i(self, message); end --========================= --SASL PLAIN -local function sasl_mechanism_plain(realm, credentials_handler) - local object = { mechanism = "PLAIN", realm = realm, credentials_handler = credentials_handler} - function object.feed(self, message) - if message == "" or message == nil then return "failure", "malformed-request" end - local response = message - local authorization = s_match(response, "([^&%z]+)") - local authentication = s_match(response, "%z([^&%z]+)%z") - local password = s_match(response, "%z[^&%z]+%z([^&%z]+)") +local function sasl_mechanism_plain(self, message) + local response = message + local authorization = s_match(response, "([^&%z]+)") + local authentication = s_match(response, "%z([^&%z]+)%z") + local password = s_match(response, "%z[^&%z]+%z([^&%z]+)") + + if authentication == nil or password == nil then return "failure", "malformed-request" end - if authentication == nil or password == nil then return "failure", "malformed-request" end - self.username = authentication - local auth_success = self.credentials_handler("PLAIN", self.username, self.realm, password) + local correct, state = false, false, false; + if self.profile.plain then + local correct_password, state = self.profile.plain(authentication, self.realm); + if correct_password == password then correct = true; else correct = false; end + else if self.profile.plain_test then + correct, state = self.profile.plain_test(authentication, self.realm, password); + end - if auth_success then - return "success" - elseif auth_success == nil then - return "failure", "account-disabled" - else - return "failure", "not-authorized" - end + self.username = authentication + if not state then + return "failure", "account-disabled"; end - return object + + if correct then + return "success"; + else + return "failure", "not-authorized"; + end end registerMechanism("PLAIN", {"plain", "plain_test"}, sasl_mechanism_plain);