# HG changeset patch # User Waqas Hussain # Date 1275860020 -18000 # Node ID b5f26112301340c4d165f37802f33e8e7e1a8570 # Parent 09174a6e83660fcae6b875d02bddd19f327a7003 mod_auth_internal, mod_auth_internal_hashed: Updated to provide get_sasl_handler. diff -r 09174a6e8366 -r b5f261123013 plugins/mod_auth_internal.lua --- a/plugins/mod_auth_internal.lua Mon Jun 07 02:32:13 2010 +0500 +++ b/plugins/mod_auth_internal.lua Mon Jun 07 02:33:40 2010 +0500 @@ -16,6 +16,8 @@ local jid_bare = require "util.jid".bare; local config = require "core.configmanager"; local usermanager = require "core.usermanager"; +local new_sasl = require "util.sasl".new; +local nodeprep = require "util.encodings".stringprep.nodeprep; local hosts = hosts; local prosody = _G.prosody; @@ -73,8 +75,23 @@ return datamanager.store(username, host, "accounts", {password = password}); end - function provider.get_supported_methods() - return {["PLAIN"] = true, ["DIGEST-MD5"] = true}; -- TODO this should be taken from the config + function provider.get_sasl_handler() + local realm = module:get_option("sasl_realm") or origin.host; + local getpass_authentication_profile = { + plain = function(username, realm) + local prepped_username = nodeprep(username); + if not prepped_username then + log("debug", "NODEprep failed on username: %s", username); + return "", nil; + end + local password = usermanager.get_password(prepped_username, realm); + if not password then + return "", nil; + end + return password, true; + end + }; + return new_sasl(realm, getpass_authentication_profile); end function provider.is_admin(jid) diff -r 09174a6e8366 -r b5f261123013 plugins/mod_auth_internal_hashed.lua --- a/plugins/mod_auth_internal_hashed.lua Mon Jun 07 02:32:13 2010 +0500 +++ b/plugins/mod_auth_internal_hashed.lua Mon Jun 07 02:33:40 2010 +0500 @@ -18,6 +18,8 @@ local config = require "core.configmanager"; local usermanager = require "core.usermanager"; local generate_uuid = require "util.uuid".generate; +local new_sasl = require "util.sasl".new; +local nodeprep = require "util.encodings".stringprep.nodeprep; local hosts = hosts; local prosody = _G.prosody; @@ -105,8 +107,19 @@ return datamanager.store(username, host, "accounts", {hashpass = hexpass, salt = salt, iteration_count = iteration_count}); end - function provider.get_supported_methods() - return {["PLAIN"] = true}; -- TODO this should be taken from the config + function provider.get_sasl_handler() + local realm = module:get_option("sasl_realm") or origin.host; + local testpass_authentication_profile = { + plain_test = function(username, password, realm) + local prepped_username = nodeprep(username); + if not prepped_username then + log("debug", "NODEprep failed on username: %s", username); + return "", nil; + end + return usermanager.test_password(prepped_username, password, realm), true; + end + }; + return new_sasl(realm, testpass_authentication_profile); end function provider.is_admin(jid)