Diff

plugins/mod_saslauth.lua @ 292:33175ad2f682

Started using realm in password hashing, and added support for error message replies from sasl
author Waqas Hussain <waqas20@gmail.com>
date Sun, 16 Nov 2008 01:54:14 +0500
parent 291:5672d2be1bf3
child 293:b446de4e258e
line wrap: on
line diff
--- a/plugins/mod_saslauth.lua	Sat Nov 15 19:50:22 2008 +0000
+++ b/plugins/mod_saslauth.lua	Sun Nov 16 01:54:14 2008 +0500
@@ -17,12 +17,13 @@
 
 local new_sasl = require "util.sasl".new;
 
-local function build_reply(status, ret)
+local function build_reply(status, ret, err_msg)
 	local reply = st.stanza(status, {xmlns = xmlns_sasl});
 	if status == "challenge" then
 		reply:text(ret or "");
 	elseif status == "failure" then
 		reply:tag(ret):up();
+		if err_msg then reply:tag("text"); end
 	elseif status == "success" then
 		reply:text(ret or "");
 	else
@@ -42,15 +43,14 @@
 	end
 end
 
-local function password_callback(jid, mechanism)
-	local node, host = jid_split(jid);
+local function password_callback(node, host, mechanism)
 	local password = (datamanager.load(node, host, "accounts") or {}).password; -- FIXME handle hashed passwords
 	local func = function(x) return x; end;
 	if password then
 		if mechanism == "PLAIN" then
 			return func, password;
 		elseif mechanism == "DIGEST-MD5" then
-			return func, require "hashes".md5(node.."::"..password);
+			return func, require "hashes".md5(node..":"..host..":"..password);
 		end
 	end
 	return func, nil;
@@ -66,9 +66,9 @@
 			return;
 		end
 	end
-	local status, ret = session.sasl_handler:feed(text);
+	local status, ret, err_msg = session.sasl_handler:feed(text);
 	handle_status(session, status);
-	local s = build_reply(status, ret); 
+	local s = build_reply(status, ret, err_msg); 
 	log("debug", "sasl reply: "..tostring(s));
 	session.send(s);
 end