aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/modulemanager.lua2
-rw-r--r--core/usermanager.lua117
-rw-r--r--plugins/mod_defaultauth.lua96
-rw-r--r--plugins/mod_groups.lua10
-rw-r--r--plugins/mod_hashpassauth.lua128
-rw-r--r--plugins/mod_motd.lua25
-rw-r--r--plugins/mod_register.lua4
-rw-r--r--plugins/mod_saslauth.lua24
-rw-r--r--prosody.cfg.lua.dist1
-rwxr-xr-xprosodyctl2
-rw-r--r--util/sasl/plain.lua4
11 files changed, 320 insertions, 93 deletions
diff --git a/core/modulemanager.lua b/core/modulemanager.lua
index 8e62aecb..2847663c 100644
--- a/core/modulemanager.lua
+++ b/core/modulemanager.lua
@@ -39,7 +39,7 @@ end
local array, set = require "util.array", require "util.set";
-local autoload_modules = {"presence", "message", "iq"};
+local autoload_modules = {"presence", "message", "iq", "defaultauth"};
-- We need this to let modules access the real global namespace
local _G = _G;
diff --git a/core/usermanager.lua b/core/usermanager.lua
index 07097dc1..6c269401 100644
--- a/core/usermanager.lua
+++ b/core/usermanager.lua
@@ -20,117 +20,72 @@ local require_provisioning = config.get("*", "core", "cyrus_require_provisioning
local prosody = _G.prosody;
+local setmetatable = setmetatable;
+
module "usermanager"
-local new_default_provider;
+function new_null_provider()
+ local function dummy() end;
+ return setmetatable({name = "null"}, { __index = function() return dummy; end });
+end
local function host_handler(host)
local host_session = hosts[host];
- host_session.events.add_handler("item-added/auth-provider", function (provider)
- if config.get(host, "core", "authentication") == provider.name then
+ host_session.events.add_handler("item-added/auth-provider", function (event)
+ local provider = event.item;
+ if config.get(host, "core", "authentication") == nil and provider.name == "default" then
+ host_session.users = provider;
+ elseif config.get(host, "core", "authentication") == provider.name then
host_session.users = provider;
end
+ if host_session.users ~= nil and host_session.users.name ~= nil then
+ log("debug", "host '%s' now set to use user provider '%s'", host, host_session.users.name);
+ end
end);
- host_session.events.add_handler("item-removed/auth-provider", function (provider)
+ host_session.events.add_handler("item-removed/auth-provider", function (event)
+ local provider = event.item;
if host_session.users == provider then
- host_session.users = new_default_provider(host);
+ host_session.users = new_null_provider();
end
end);
- host_session.users = new_default_provider(host); -- Start with the default usermanager provider
-end
-prosody.events.add_handler("host-activated", host_handler);
-prosody.events.add_handler("component-activated", host_handler);
-
-local function is_cyrus(host) return config.get(host, "core", "sasl_backend") == "cyrus"; end
-
-function new_default_provider(host)
- local provider = { name = "default" };
-
- function provider:test_password(username, password)
- if is_cyrus(host) then return nil, "Legacy auth not supported with Cyrus SASL."; end
- local credentials = datamanager.load(username, host, "accounts") or {};
-
- if password == credentials.password then
- return true;
- else
- return nil, "Auth failed. Invalid username or password.";
- end
- end
-
- function provider:get_password(username)
- if is_cyrus(host) then return nil, "Passwords unavailable for Cyrus SASL."; end
- return (datamanager.load(username, host, "accounts") or {}).password;
- end
-
- function provider:set_password(username, password)
- if is_cyrus(host) then return nil, "Passwords unavailable for Cyrus SASL."; end
- local account = datamanager.load(username, host, "accounts");
- if account then
- account.password = password;
- return datamanager.store(username, host, "accounts", account);
- end
- return nil, "Account not available.";
- end
-
- function provider:user_exists(username)
- if not(require_provisioning) and is_cyrus(host) then return true; end
- local account, err = datamanager.load(username, host, "accounts") ~= nil; -- FIXME also check for empty credentials
- return (account or err) ~= nil; -- FIXME also check for empty credentials
- end
-
- function provider:create_user(username, password)
- if not(require_provisioning) and is_cyrus(host) then return nil, "Account creation/modification not available with Cyrus SASL."; end
- return datamanager.store(username, host, "accounts", {password = password});
- end
+ host_session.users = new_null_provider(); -- Start with the default usermanager provider
+end;
+prosody.events.add_handler("host-activated", host_handler, 100);
+prosody.events.add_handler("component-activated", host_handler, 100);
- function provider:get_supported_methods()
- return {["PLAIN"] = true, ["DIGEST-MD5"] = true}; -- TODO this should be taken from the config
- end
-
- function provider:is_admin(jid)
- local admins = config.get(host, "core", "admins");
- if admins ~= config.get("*", "core", "admins") then
- if type(admins) == "table" then
- jid = jid_bare(jid);
- for _,admin in ipairs(admins) do
- if admin == jid then return true; end
- end
- elseif admins then
- log("error", "Option 'admins' for host '%s' is not a table", host);
- end
- end
- return is_admin(jid); -- Test whether it's a global admin instead
- end
- return provider;
-end
+function is_cyrus(host) return config.get(host, "core", "sasl_backend") == "cyrus"; end
-function validate_credentials(host, username, password, method)
- return hosts[host].users:test_password(username, password);
+function test_password(username, password, host)
+ return hosts[host].users.test_password(username, password);
end
function get_password(username, host)
- return hosts[host].users:get_password(username);
+ return hosts[host].users.get_password(username);
end
-function set_password(username, host, password)
- return hosts[host].users:set_password(username, password);
+function set_password(username, password, host)
+ return hosts[host].users.set_password(username, password);
end
function user_exists(username, host)
- return hosts[host].users:user_exists(username);
+ return hosts[host].users.user_exists(username);
end
function create_user(username, password, host)
- return hosts[host].users:create_user(username, password);
+ return hosts[host].users.create_user(username, password);
end
function get_supported_methods(host)
- return hosts[host].users:get_supported_methods();
+ return hosts[host].users.get_supported_methods();
+end
+
+function get_provider(host)
+ return hosts[host].users;
end
function is_admin(jid, host)
if host and host ~= "*" then
- return hosts[host].users:is_admin(jid);
+ return hosts[host].users.is_admin(jid);
else -- Test only whether this JID is a global admin
local admins = config.get("*", "core", "admins");
if type(admins) == "table" then
@@ -145,6 +100,4 @@ function is_admin(jid, host)
end
end
-_M.new_default_provider = new_default_provider;
-
return _M;
diff --git a/plugins/mod_defaultauth.lua b/plugins/mod_defaultauth.lua
new file mode 100644
index 00000000..6782ae09
--- /dev/null
+++ b/plugins/mod_defaultauth.lua
@@ -0,0 +1,96 @@
+-- Prosody IM
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
+-- Copyright (C) 2010 Jeff Mitchell
+--
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+
+local datamanager = require "util.datamanager";
+local log = require "util.logger".init("usermanager");
+local type = type;
+local error = error;
+local ipairs = ipairs;
+local hashes = require "util.hashes";
+local jid_bare = require "util.jid".bare;
+local config = require "core.configmanager";
+local usermanager = require "core.usermanager";
+local hosts = hosts;
+
+local prosody = _G.prosody;
+
+local is_cyrus = usermanager.is_cyrus;
+
+function new_default_provider(host)
+ local provider = { name = "default" };
+ log("debug", "initializing default authentication provider for host '%s'", host);
+
+ function provider.test_password(username, password)
+ log("debug", "test password '%s' for user %s at host %s", password, username, module.host);
+ if is_cyrus(host) then return nil, "Legacy auth not supported with Cyrus SASL."; end
+ local credentials = datamanager.load(username, host, "accounts") or {};
+
+ if password == credentials.password then
+ return true;
+ else
+ return nil, "Auth failed. Invalid username or password.";
+ end
+ end
+
+ function provider.get_password(username)
+ log("debug", "get_password for username '%s' at host '%s'", username, module.host);
+ if is_cyrus(host) then return nil, "Passwords unavailable for Cyrus SASL."; end
+ return (datamanager.load(username, host, "accounts") or {}).password;
+ end
+
+ function provider.set_password(username, password)
+ if is_cyrus(host) then return nil, "Passwords unavailable for Cyrus SASL."; end
+ local account = datamanager.load(username, host, "accounts");
+ if account then
+ account.password = password;
+ return datamanager.store(username, host, "accounts", account);
+ end
+ return nil, "Account not available.";
+ end
+
+ function provider.user_exists(username)
+ if is_cyrus(host) then return true; end
+ local account = datamanager.load(username, host, "accounts");
+ if not account then
+ log("debug", "account not found for username '%s' at host '%s'", username, module.host);
+ return nil, "Auth failed. Invalid username";
+ end
+ if account.password == nil or string.len(account.password) == 0 then
+ log("debug", "account password not set or zero-length for username '%s' at host '%s'", username, module.host);
+ return nil, "Auth failed. Password invalid.";
+ end
+ return true;
+ end
+
+ function provider.create_user(username, password)
+ if is_cyrus(host) then return nil, "Account creation/modification not available with Cyrus SASL."; end
+ 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
+ end
+
+ function provider.is_admin(jid)
+ local admins = config.get(host, "core", "admins");
+ if admins ~= config.get("*", "core", "admins") and type(admins) == "table" then
+ jid = jid_bare(jid);
+ for _,admin in ipairs(admins) do
+ if admin == jid then return true; end
+ end
+ elseif admins then
+ log("error", "Option 'admins' for host '%s' is not a table", host);
+ end
+ return is_admin(jid); -- Test whether it's a global admin instead
+ end
+ return provider;
+end
+
+module:add_item("auth-provider", new_default_provider(module.host));
+
diff --git a/plugins/mod_groups.lua b/plugins/mod_groups.lua
index 5f821cbc..7a876f1d 100644
--- a/plugins/mod_groups.lua
+++ b/plugins/mod_groups.lua
@@ -29,6 +29,9 @@ function inject_roster_contacts(username, host, roster)
if jid ~= bare_jid then
if not roster[jid] then roster[jid] = {}; end
roster[jid].subscription = "both";
+ if groups[group_name][jid] then
+ roster[jid].name = groups[group_name][jid];
+ end
if not roster[jid].groups then
roster[jid].groups = { [group_name] = true };
end
@@ -100,10 +103,13 @@ function module.load()
groups[curr_group] = groups[curr_group] or {};
else
-- Add JID
- local jid = jid_prep(line:match("%S+"));
+ local entryjid, name = line:match("([^=]*)=?(.*)");
+ module:log("debug", "entryjid = '%s', name = '%s'", entryjid, name);
+ local jid;
+ jid = jid_prep(entryjid:match("%S+"));
if jid then
module:log("debug", "New member of %s: %s", tostring(curr_group), tostring(jid));
- groups[curr_group][jid] = true;
+ groups[curr_group][jid] = name or false;
members[jid] = members[jid] or {};
members[jid][#members[jid]+1] = curr_group;
end
diff --git a/plugins/mod_hashpassauth.lua b/plugins/mod_hashpassauth.lua
new file mode 100644
index 00000000..bea2c67f
--- /dev/null
+++ b/plugins/mod_hashpassauth.lua
@@ -0,0 +1,128 @@
+-- Prosody IM
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
+-- Copyright (C) 2010 Jeff Mitchell
+--
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+
+local datamanager = require "util.datamanager";
+local log = require "util.logger".init("usermanager");
+local type = type;
+local error = error;
+local ipairs = ipairs;
+local hashes = require "util.hashes";
+local jid_bare = require "util.jid".bare;
+local saltedPasswordSHA1 = require "util.sasl.scram".saltedPasswordSHA1;
+local config = require "core.configmanager";
+local usermanager = require "core.usermanager";
+local generate_uuid = require "util.uuid".generate;
+local hosts = hosts;
+
+local prosody = _G.prosody;
+
+local is_cyrus = usermanager.is_cyrus;
+
+-- Default; can be set per-user
+local iteration_count = 4096;
+
+function new_hashpass_provider(host)
+ local provider = { name = "hashpass" };
+ log("debug", "initializing hashpass authentication provider for host '%s'", host);
+
+ function provider.test_password(username, password)
+ if is_cyrus(host) then return nil, "Legacy auth not supported with Cyrus SASL."; end
+ local credentials = datamanager.load(username, host, "accounts") or {};
+
+ if credentials.password ~= nil and string.len(credentials.password) ~= 0 then
+ if credentials.password ~= password then
+ return nil, "Auth failed. Provided password is incorrect.";
+ end
+
+ if provider.set_password(username, credentials.password) == nil then
+ return nil, "Auth failed. Could not set hashed password from plaintext.";
+ else
+ return true;
+ end
+ end
+
+ if credentials.iteration_count == nil or credentials.salt == nil or string.len(credentials.salt) == 0 then
+ return nil, "Auth failed. Stored salt and iteration count information is not complete.";
+ end
+
+ local valid, binpass = saltedPasswordSHA1(password, credentials.salt, credentials.iteration_count);
+ local hexpass = binpass:gsub(".", function (c) return ("%02x"):format(c:byte()); end);
+
+ if valid and hexpass == credentials.hashpass then
+ return true;
+ else
+ return nil, "Auth failed. Invalid username, password, or password hash information.";
+ end
+ end
+
+ function provider.set_password(username, password)
+ if is_cyrus(host) then return nil, "Passwords unavailable for Cyrus SASL."; end
+ local account = datamanager.load(username, host, "accounts");
+ if account then
+ if account.iteration_count == nil then
+ account.iteration_count = iteration_count;
+ end
+
+ if account.salt == nil then
+ account.salt = generate_uuid();
+ end
+
+ local valid, binpass = saltedPasswordSHA1(password, account.salt, account.iteration_count);
+ local hexpass = binpass:gsub(".", function (c) return ("%02x"):format(c:byte()); end);
+ account.hashpass = hexpass;
+
+ account.password = nil;
+ return datamanager.store(username, host, "accounts", account);
+ end
+ return nil, "Account not available.";
+ end
+
+ function provider.user_exists(username)
+ if is_cyrus(host) then return true; end
+ local account = datamanager.load(username, host, "accounts");
+ if not account then
+ log("debug", "account not found for username '%s' at host '%s'", username, module.host);
+ return nil, "Auth failed. Invalid username";
+ end
+ if (account.hashpass == nil or string.len(account.hashpass) == 0) and (account.password == nil or string.len(account.password) == 0) then
+ log("debug", "account password not set or zero-length for username '%s' at host '%s'", username, module.host);
+ return nil, "Auth failed. Password invalid.";
+ end
+ return true;
+ end
+
+ function provider.create_user(username, password)
+ if is_cyrus(host) then return nil, "Account creation/modification not available with Cyrus SASL."; end
+ local salt = generate_uuid();
+ local valid, binpass = saltedPasswordSHA1(password, salt, iteration_count);
+ local hexpass = binpass:gsub(".", function (c) return ("%02x"):format(c:byte()); end);
+ 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
+ end
+
+ function provider.is_admin(jid)
+ local admins = config.get(host, "core", "admins");
+ if admins ~= config.get("*", "core", "admins") and type(admins) == "table" then
+ jid = jid_bare(jid);
+ for _,admin in ipairs(admins) do
+ if admin == jid then return true; end
+ end
+ elseif admins then
+ log("error", "Option 'admins' for host '%s' is not a table", host);
+ end
+ return is_admin(jid); -- Test whether it's a global admin instead
+ end
+ return provider;
+end
+
+module:add_item("auth-provider", new_hashpass_provider(module.host));
+
diff --git a/plugins/mod_motd.lua b/plugins/mod_motd.lua
new file mode 100644
index 00000000..f323e606
--- /dev/null
+++ b/plugins/mod_motd.lua
@@ -0,0 +1,25 @@
+-- Prosody IM
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
+-- Copyright (C) 2010 Jeff Mitchell
+--
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+
+local host = module:get_host();
+local motd_text = module:get_option("motd_text") or "MOTD: (blank)";
+local motd_jid = module:get_option("motd_jid") or host;
+
+local st = require "util.stanza";
+
+module:hook("resource-bind",
+ function (event)
+ local session = event.session;
+ local motd_stanza =
+ st.message({ to = session.username..'@'..session.host, from = motd_jid })
+ :tag("body"):text(motd_text);
+ core_route_stanza(hosts[host], motd_stanza);
+ module:log("debug", "MOTD send to user %s@%s", session.username, session.host);
+
+end);
diff --git a/plugins/mod_register.lua b/plugins/mod_register.lua
index b8d142f7..7e150ac7 100644
--- a/plugins/mod_register.lua
+++ b/plugins/mod_register.lua
@@ -35,7 +35,7 @@ module:add_iq_handler("c2s", "jabber:iq:register", function (session, stanza)
local username, host = session.username, session.host;
--session.send(st.error_reply(stanza, "cancel", "not-allowed"));
--return;
- usermanager_set_password(username, host, nil); -- Disable account
+ usermanager_set_password(username, nil, host); -- Disable account
-- FIXME the disabling currently allows a different user to recreate the account
-- we should add an in-memory account block mode when we have threading
session.send(st.reply(stanza));
@@ -70,7 +70,7 @@ module:add_iq_handler("c2s", "jabber:iq:register", function (session, stanza)
username = nodeprep(table.concat(username));
password = table.concat(password);
if username == session.username then
- if usermanager_set_password(username, session.host, password) then
+ if usermanager_set_password(username, password, session.host) then
session.send(st.reply(stanza));
else
-- TODO unable to write file, file may be locked, etc, what's the correct error?
diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua
index 9f940c37..c16a14da 100644
--- a/plugins/mod_saslauth.lua
+++ b/plugins/mod_saslauth.lua
@@ -15,10 +15,11 @@ local base64 = require "util.encodings".base64;
local nodeprep = require "util.encodings".stringprep.nodeprep;
local datamanager_load = require "util.datamanager".load;
-local usermanager_validate_credentials = require "core.usermanager".validate_credentials;
+local usermanager_get_provider = require "core.usermanager".get_provider;
local usermanager_get_supported_methods = require "core.usermanager".get_supported_methods;
local usermanager_user_exists = require "core.usermanager".user_exists;
local usermanager_get_password = require "core.usermanager".get_password;
+local usermanager_test_password = require "core.usermanager".test_password;
local t_concat, t_insert = table.concat, table.insert;
local tostring = tostring;
local jid_split = require "util.jid".split;
@@ -66,7 +67,7 @@ else
error("Unknown SASL backend");
end
-local default_authentication_profile = {
+local getpass_authentication_profile = {
plain = function(username, realm)
local prepped_username = nodeprep(username);
if not prepped_username then
@@ -81,6 +82,17 @@ local default_authentication_profile = {
end
};
+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
+};
+
local anonymous_authentication_profile = {
anonymous = function(username, realm)
return true; -- for normal usage you should always return true here
@@ -183,7 +195,13 @@ module:hook("stream-features", function(event)
if module:get_option("anonymous_login") then
origin.sasl_handler = new_sasl(realm, anonymous_authentication_profile);
else
- origin.sasl_handler = new_sasl(realm, default_authentication_profile);
+ if usermanager_get_provider(realm).get_password then
+ origin.sasl_handler = new_sasl(realm, getpass_authentication_profile);
+ elseif usermanager_get_provider(realm).test_password then
+ origin.sasl_handler = new_sasl(realm, testpass_authentication_profile);
+ else
+ log("warn", "AUTH: Could not load an authentication profile for the given provider.");
+ end
if not (module:get_option("allow_unencrypted_plain_auth")) and not origin.secure then
origin.sasl_handler:forbidden({"PLAIN"});
end
diff --git a/prosody.cfg.lua.dist b/prosody.cfg.lua.dist
index a17eb877..2e07b7f5 100644
--- a/prosody.cfg.lua.dist
+++ b/prosody.cfg.lua.dist
@@ -71,6 +71,7 @@ modules_disabled = {
-- "presence";
-- "message";
-- "iq";
+ -- "defaultauth";
};
-- Disable account creation by default, for security
diff --git a/prosodyctl b/prosodyctl
index c0cd89a0..5bdc5187 100755
--- a/prosodyctl
+++ b/prosodyctl
@@ -123,7 +123,7 @@ local error_messages = setmetatable({
hosts = prosody.hosts;
local function make_host(hostname)
- return { events = prosody.events, users = require "core.usermanager".new_default_provider(hostname) };
+ return { events = prosody.events, users = require "core.usermanager".new_null_provider(hostname) };
end
for hostname, config in pairs(config.getconfig()) do
diff --git a/util/sasl/plain.lua b/util/sasl/plain.lua
index eaf03d83..1a2ba01e 100644
--- a/util/sasl/plain.lua
+++ b/util/sasl/plain.lua
@@ -29,7 +29,7 @@ plain:
end
plain_test:
- function(username, realm, password)
+ function(username, password, realm)
return true or false, state;
end
]]
@@ -60,7 +60,7 @@ local function plain(self, message)
correct_password, state = self.profile.plain(authentication, self.realm);
correct = (correct_password == password);
elseif self.profile.plain_test then
- correct, state = self.profile.plain_test(authentication, self.realm, password);
+ correct, state = self.profile.plain_test(authentication, password, self.realm);
end
self.username = authentication