function parsers.lua.load(data, filename)
local env;
-- The ' = true' are needed so as not to set off __newindex when we assign the functions below
- env = setmetatable({ Host = true; host = true; Component = true, component = true,
- env = setmetatable({
- Host = true, host = true, VirtualHost = true,
- Component = true, component = true,
- Include = true, include = true, RunScript = dofile }, {
- __index = function (t, k)
- return rawget(_G, k) or
- function (settings_table)
- config[__currenthost or "*"][k] = settings_table;
- end;
- end,
- __newindex = function (t, k, v)
- set(env.__currenthost or "*", "core", k, v);
- end
- });
++ env = setmetatable({ Host = true, host = true, VirtualHost = true, Component = true, component = true,
+ Include = true, include = true, RunScript = dofile }, { __index = function (t, k)
+ return rawget(_G, k) or
+ function (settings_table)
+ config[__currenthost or "*"][k] = settings_table;
+ end;
+ end,
+ __newindex = function (t, k, v)
+ set(env.__currenthost or "*", "core", k, v);
+ end});
rawset(env, "__currenthost", "*") -- Default is global
- function env.Host(name)
+ function env.VirtualHost(name)
if rawget(config, name) and rawget(config[name].core, "component_module") then
error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s",
name, config[name].core.component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0);
local hashes = require "util.hashes";
local jid_bare = require "util.jid".bare;
local config = require "core.configmanager";
+ local hosts = hosts;
+
+ local require_provisioning = config.get("*", "core", "cyrus_require_provisioning") or false;
-local prosody = _G.prosody;
-
module "usermanager"
-local new_default_provider;
-
-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.users = provider;
- end
- end);
- host_session.events.add_handler("item-removed/auth-provider", function (provider)
- if host_session.users == provider then
- host_session.users = new_default_provider(host);
- 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 {};
-
+function validate_credentials(host, username, password, method)
+ log("debug", "User '%s' is being validated", username);
++ if is_cyrus(host) then return nil, "Legacy auth not supported with Cyrus SASL."; end
+ local credentials = datamanager.load(username, host, "accounts") or {};
+
+ if method == nil then method = "PLAIN"; end
+ if method == "PLAIN" and credentials.password then -- PLAIN, do directly
if password == credentials.password then
return true;
else
end
function get_password(username, host)
- return (datamanager.load(username, host, "accounts") or {}).password
- return hosts[host].users: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 set_password(username, host, password)
- return hosts[host].users: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 user_exists(username, host)
- return hosts[host].users:user_exists(username);
++ if not(require_provisioning) and is_cyrus(host) then return true; end
+ return datamanager.load(username, host, "accounts") ~= nil; -- FIXME also check for empty credentials
end
function create_user(username, password, host)
- return hosts[host].users: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
function get_supported_methods(host)
+++ /dev/null
---- 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.
----
--
- \r
- local datamanager = require "util.datamanager";\r
- local st = require "util.stanza";\r
- local datetime = require "util.datetime";\r
-
-local datamanager = require "util.datamanager";
-local st = require "util.stanza";
-local datetime = require "util.datetime";
--local ipairs = ipairs;
- local jid_split = require "util.jid".split;\r
- \r
- module:add_feature("msgoffline");\r
- \r
- module:hook("message/offline/store", function(event)\r
- local origin, stanza = event.origin, event.stanza;\r
- local to = stanza.attr.to;\r
- local node, host;\r
- if to then\r
- node, host = jid_split(to)\r
- else\r
- node, host = origin.username, origin.host;\r
- end\r
- \r
- stanza.attr.stamp, stanza.attr.stamp_legacy = datetime.datetime(), datetime.legacy();\r
- local result = datamanager.list_append(node, host, "offline", st.preserialize(stanza));\r
- stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;\r
- \r
- return true;\r
- end);\r
- \r
- module:hook("message/offline/broadcast", function(event)\r
- local origin = event.origin;\r
- local node, host = origin.username, origin.host;\r
- \r
- local data = datamanager.list_load(node, host, "offline");\r
- if not data then return true; end\r
- for _, stanza in ipairs(data) do\r
- stanza = st.deserialize(stanza);\r
- stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203\r
- stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated)\r
- stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;\r
- origin.send(stanza);\r
- end\r
- return true;\r
- end);\r
- \r
- module:hook("message/offline/delete", function(event)\r
- local origin = event.origin;\r
- local node, host = origin.username, origin.host;\r
- \r
- return datamanager.list_store(node, host, "offline", nil);\r
- end);\r
-local jid_split = require "util.jid".split;
-
-module:add_feature("msgoffline");
-
-module:hook("message/offline/store", function(event)
- local origin, stanza = event.origin, event.stanza;
- local to = stanza.attr.to;
- local node, host;
- if to then
- node, host = jid_split(to)
- else
- node, host = origin.username, origin.host;
- end
-
- stanza.attr.stamp, stanza.attr.stamp_legacy = datetime.datetime(), datetime.legacy();
- local result = datamanager.list_append(node, host, "offline", st.preserialize(stanza));
- stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
-
- return true;
-end);
-
-module:hook("message/offline/broadcast", function(event)
- local origin = event.origin;
- local node, host = origin.username, origin.host;
-
- local data = datamanager.list_load(node, host, "offline");
- if not data then return true; end
- for _, stanza in ipairs(data) do
- stanza = st.deserialize(stanza);
- stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203
- stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated)
- stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil;
- origin.send(stanza);
- end
- return true;
-end);
-
-module:hook("message/offline/delete", function(event)
- local origin = event.origin;
- local node, host = origin.username, origin.host;
-
- return datamanager.list_store(node, host, "offline", nil);
-end);
:tag("item", {affiliation=affiliation or "none", role=role or "none"}):up()
:tag("status", {code='110'}));
end
- self:send_history(from, stanza);
++ if self._data.whois == 'anyone' then -- non-anonymous?
++ self:_route_stanza(st.stanza("message", {from=to, to=from, type='groupchat'})
++ :tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
++ :tag("status", {code='100'}));
++ end
+ self:send_history(from);
else -- banned
local reply = st.error_reply(stanza, "auth", "forbidden"):up();
reply.tags[1].attr.code = "403";
function room_mt:set_role(actor, occupant_jid, role, callback, reason)
if role == "none" then role = nil; end
if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end
-- if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end
++ if self:get_role(self._jid_nick[actor]) ~= "moderator" then return nil, "cancel", "not-allowed"; end
local occupant = self._occupants[occupant_jid];
if not occupant then return nil, "modify", "not-acceptable"; end
if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end
end
end
end
-- if self._data.whois == 'anyone' then
-- muc_child:tag('status', { code = '100' });
-- end
end
self:route_stanza(stanza);
if muc_child then