Diff

util/sasl.lua @ 288:dc53343af9ac

Set username in a SASL object.
author Tobias Markmann <tm@ayena.de>
date Sat, 15 Nov 2008 20:28:09 +0100
parent 285:372d0891e8fd
child 292:33175ad2f682
line wrap: on
line diff
--- a/util/sasl.lua	Sat Nov 15 19:25:51 2008 +0100
+++ b/util/sasl.lua	Sat Nov 15 20:28:09 2008 +0100
@@ -19,7 +19,9 @@
 local function new_plain(realm, password_handler)
 	local object = { mechanism = "PLAIN", realm = realm, password_handler = password_handler}
 	object.feed = 	function(self, message)
-						log("debug", "feed: "..message)
+						--print(message:gsub("%W", function (c) return string.format("\\%d", string.byte(c)) end));
+
+						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")
@@ -31,9 +33,12 @@
 						if password_encoding == nil then claimed_password = password
 						else claimed_password = password_encoding(password) end
 						
+						self.username = authentication
 						if claimed_password == correct_password then
+							log("debug", "success")
 							return "success", nil
 						else
+							log("debug", "failure")
 							return "failure", "not-authorized"
 						end
 					end