mod_saslauth, usermanager: Fetch list of mechanisms from usermanager
authorNick Thomas
Thu, 23 Jul 2009 22:15:06 +0100
changeset 1584 ffe8a9296e04
parent 1583 e17001ce0e9d
child 1585 edc066730d11
mod_saslauth, usermanager: Fetch list of mechanisms from usermanager
plugins/mod_saslauth.lua
--- a/plugins/mod_saslauth.lua	Thu Jul 23 21:09:25 2009 +0100
+++ b/plugins/mod_saslauth.lua	Thu Jul 23 22:15:06 2009 +0100
@@ -1,7 +1,7 @@
 -- Prosody IM
 -- Copyright (C) 2008-2009 Matthew Wild
 -- Copyright (C) 2008-2009 Waqas Hussain
--- 
+--
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
 --
@@ -15,6 +15,7 @@
 
 local datamanager_load = require "util.datamanager".load;
 local usermanager_validate_credentials = require "core.usermanager".validate_credentials;
+local usermanager_get_supported_methods = require "core.usermanager".get_supported_methods;
 local t_concat, t_insert = table.concat, table.insert;
 local tostring = tostring;
 local jid_split = require "util.jid".split
@@ -57,7 +58,7 @@
 			session.sasl_handler = nil;
 			session:reset_stream();
 			return;
-		end 
+		end
 		sm_make_authenticated(session, session.sasl_handler.username);
 		session.sasl_handler = nil;
 		session:reset_stream();
@@ -107,7 +108,7 @@
 	end
 	local status, ret, err_msg = session.sasl_handler:feed(text);
 	handle_status(session, status);
-	local s = build_reply(status, ret, err_msg); 
+	local s = build_reply(status, ret, err_msg);
 	log("debug", "sasl reply: %s", tostring(s));
 	session.send(s);
 end
@@ -119,8 +120,8 @@
 local mechanisms_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-sasl' };
 local bind_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-bind' };
 local xmpp_session_attr = { xmlns='urn:ietf:params:xml:ns:xmpp-session' };
-module:add_event_hook("stream-features", 
-		function (session, features)												
+module:add_event_hook("stream-features",
+		function (session, features)
 			if not session.username then
 				if secure_auth_only and not session.secure then
 					return;
@@ -130,8 +131,10 @@
 					if config.get(session.host or "*", "core", "anonymous_login") then
 						features:tag("mechanism"):text("ANONYMOUS"):up();
 					else
-						features:tag("mechanism"):text("DIGEST-MD5"):up();
-						features:tag("mechanism"):text("PLAIN"):up();
+						mechanisms = usermanager_get_supported_methods(session.host or "*");
+						for k, v in pairs(mechanisms) do
+							features:tag("mechanism"):text(k):up();
+						end
 					end
 				features:up();
 			else
@@ -139,8 +142,8 @@
 				features:tag("session", xmpp_session_attr):up();
 			end
 		end);
-					
-module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-bind", 
+
+module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-bind",
 		function (session, stanza)
 			log("debug", "Client requesting a resource bind");
 			local resource;
@@ -162,8 +165,8 @@
 					:tag("jid"):text(session.full_jid));
 			end
 		end);
-		
-module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-session", 
+
+module:add_iq_handler("c2s", "urn:ietf:params:xml:ns:xmpp-session",
 		function (session, stanza)
 			log("debug", "Client requesting a session");
 			session.send(st.reply(stanza));