aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_auth_anonymous.lua2
-rw-r--r--plugins/mod_auth_internal_hashed.lua12
-rw-r--r--plugins/mod_compression.lua6
-rw-r--r--plugins/mod_http.lua5
-rw-r--r--plugins/mod_http_files.lua3
-rw-r--r--plugins/mod_pep_plus.lua368
-rw-r--r--plugins/mod_proxy65.lua19
-rw-r--r--plugins/mod_pubsub/mod_pubsub.lua2
-rw-r--r--plugins/mod_pubsub/pubsub.lib.lua4
-rw-r--r--plugins/mod_saslauth.lua2
-rw-r--r--plugins/muc/muc.lib.lua2
11 files changed, 391 insertions, 34 deletions
diff --git a/plugins/mod_auth_anonymous.lua b/plugins/mod_auth_anonymous.lua
index c877d532..8de46f8c 100644
--- a/plugins/mod_auth_anonymous.lua
+++ b/plugins/mod_auth_anonymous.lua
@@ -43,7 +43,7 @@ function provider.get_sasl_handler()
end
function provider.users()
- return next, hosts[host].sessions, nil;
+ return next, hosts[module.host].sessions, nil;
end
-- datamanager callback to disable writes
diff --git a/plugins/mod_auth_internal_hashed.lua b/plugins/mod_auth_internal_hashed.lua
index fb87bb9f..954392c9 100644
--- a/plugins/mod_auth_internal_hashed.lua
+++ b/plugins/mod_auth_internal_hashed.lua
@@ -7,6 +7,8 @@
-- COPYING file in the source package for more information.
--
+local max = math.max;
+
local getAuthenticationDatabaseSHA1 = require "util.sasl.scram".getAuthenticationDatabaseSHA1;
local usermanager = require "core.usermanager";
local generate_uuid = require "util.uuid".generate;
@@ -39,7 +41,7 @@ end
-- Default; can be set per-user
-local iteration_count = 4096;
+local default_iteration_count = 4096;
-- define auth provider
local provider = {};
@@ -80,8 +82,8 @@ function provider.set_password(username, password)
log("debug", "set_password for username '%s'", username);
local account = accounts:get(username);
if account then
- account.salt = account.salt or generate_uuid();
- account.iteration_count = account.iteration_count or iteration_count;
+ account.salt = generate_uuid();
+ account.iteration_count = max(account.iteration_count or 0, default_iteration_count);
local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, account.salt, account.iteration_count);
local stored_key_hex = to_hex(stored_key);
local server_key_hex = to_hex(server_key);
@@ -113,10 +115,10 @@ function provider.create_user(username, password)
return accounts:set(username, {});
end
local salt = generate_uuid();
- local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, salt, iteration_count);
+ local valid, stored_key, server_key = getAuthenticationDatabaseSHA1(password, salt, default_iteration_count);
local stored_key_hex = to_hex(stored_key);
local server_key_hex = to_hex(server_key);
- return accounts:set(username, {stored_key = stored_key_hex, server_key = server_key_hex, salt = salt, iteration_count = iteration_count});
+ return accounts:set(username, {stored_key = stored_key_hex, server_key = server_key_hex, salt = salt, iteration_count = default_iteration_count});
end
function provider.delete_user(username)
diff --git a/plugins/mod_compression.lua b/plugins/mod_compression.lua
index f44e8a6d..9da5254e 100644
--- a/plugins/mod_compression.lua
+++ b/plugins/mod_compression.lua
@@ -125,8 +125,8 @@ end
module:hook("stanza/http://jabber.org/protocol/compress:compressed", function(event)
local session = event.origin;
-
- if session.type == "s2sout_unauthed" or session.type == "s2sout" then
+
+ if session.type == "s2sout" then
session.log("debug", "Activating compression...")
-- create deflate and inflate streams
local deflate_stream = get_deflate_stream(session);
@@ -150,7 +150,7 @@ end);
module:hook("stanza/http://jabber.org/protocol/compress:compress", function(event)
local session, stanza = event.origin, event.stanza;
- if session.type == "c2s" or session.type == "s2sin" or session.type == "c2s_unauthed" or session.type == "s2sin_unauthed" then
+ if session.type == "c2s" or session.type == "s2sin" then
-- fail if we are already compressed
if session.compressed then
local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed");
diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua
index 95933da5..d987ef74 100644
--- a/plugins/mod_http.lua
+++ b/plugins/mod_http.lua
@@ -42,7 +42,7 @@ local function get_base_path(host_module, app_name, default_app_path)
return (normalize_path(host_module:get_option("http_paths", {})[app_name] -- Host
or module:get_option("http_paths", {})[app_name] -- Global
or default_app_path)) -- Default
- :gsub("%$(%w+)", { host = module.host });
+ :gsub("%$(%w+)", { host = host_module.host });
end
local ports_by_scheme = { http = 80, https = 443, };
@@ -51,6 +51,9 @@ local ports_by_scheme = { http = 80, https = 443, };
function moduleapi.http_url(module, app_name, default_path)
app_name = app_name or (module.name:gsub("^http_", ""));
local external_url = url_parse(module:get_option_string("http_external_url")) or {};
+ if external_url.scheme and external_url.port == nil then
+ external_url.port = ports_by_scheme[external_url.scheme];
+ end
local services = portmanager.get_active_services();
local http_services = services:get("https") or services:get("http") or {};
for interface, ports in pairs(http_services) do
diff --git a/plugins/mod_http_files.lua b/plugins/mod_http_files.lua
index dd04853b..2e9f4182 100644
--- a/plugins/mod_http_files.lua
+++ b/plugins/mod_http_files.lua
@@ -14,6 +14,7 @@ local os_date = os.date;
local open = io.open;
local stat = lfs.attributes;
local build_path = require"socket.url".build_path;
+local path_sep = package.config:sub(1,1);
local base_path = module:get_option_string("http_files_dir", module:get_option_string("http_path"));
local dir_indices = module:get_option("http_index_files", { "index.html", "index.htm" });
@@ -61,7 +62,7 @@ function serve(opts)
local request, response = event.request, event.response;
local orig_path = request.path;
local full_path = base_path .. (path and "/"..path or "");
- local attr = stat(full_path);
+ local attr = stat((full_path:gsub('%'..path_sep..'+$','')));
if not attr then
return 404;
end
diff --git a/plugins/mod_pep_plus.lua b/plugins/mod_pep_plus.lua
new file mode 100644
index 00000000..4a74e437
--- /dev/null
+++ b/plugins/mod_pep_plus.lua
@@ -0,0 +1,368 @@
+local pubsub = require "util.pubsub";
+local jid_bare = require "util.jid".bare;
+local jid_split = require "util.jid".split;
+local set_new = require "util.set".new;
+local st = require "util.stanza";
+local calculate_hash = require "util.caps".calculate_hash;
+local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
+
+local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
+local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
+local xmlns_pubsub_owner = "http://jabber.org/protocol/pubsub#owner";
+
+local lib_pubsub = module:require "pubsub";
+local handlers = lib_pubsub.handlers;
+local pubsub_error_reply = lib_pubsub.pubsub_error_reply;
+
+local services = {};
+local recipients = {};
+local hash_map = {};
+
+function module.save()
+ return { services = services };
+end
+
+function module.restore(data)
+ services = data.services;
+end
+
+local function subscription_presence(user_bare, recipient)
+ local recipient_bare = jid_bare(recipient);
+ if (recipient_bare == user_bare) then return true; end
+ local username, host = jid_split(user_bare);
+ return is_contact_subscribed(username, host, recipient_bare);
+end
+
+local function get_broadcaster(name)
+ local function simple_broadcast(kind, node, jids, item)
+ if item then
+ item = st.clone(item);
+ item.attr.xmlns = nil; -- Clear the pubsub namespace
+ end
+ local message = st.message({ from = name, type = "headline" })
+ :tag("event", { xmlns = xmlns_pubsub_event })
+ :tag(kind, { node = node })
+ :add_child(item);
+ for jid in pairs(jids) do
+ module:log("debug", "Sending notification to %s from %s: %s", jid, name, tostring(item));
+ message.attr.to = jid;
+ module:send(message);
+ end
+ end
+ return simple_broadcast;
+end
+
+local function get_pep_service(name)
+ if services[name] then
+ return services[name];
+ end
+ services[name] = pubsub.new({
+ capabilities = {
+ none = {
+ create = false;
+ publish = false;
+ retract = false;
+ get_nodes = false;
+
+ subscribe = false;
+ unsubscribe = false;
+ get_subscription = false;
+ get_subscriptions = false;
+ get_items = false;
+
+ subscribe_other = false;
+ unsubscribe_other = false;
+ get_subscription_other = false;
+ get_subscriptions_other = false;
+
+ be_subscribed = true;
+ be_unsubscribed = true;
+
+ set_affiliation = false;
+ };
+ subscriber = {
+ create = false;
+ publish = false;
+ retract = false;
+ get_nodes = true;
+
+ subscribe = true;
+ unsubscribe = true;
+ get_subscription = true;
+ get_subscriptions = true;
+ get_items = true;
+
+ subscribe_other = false;
+ unsubscribe_other = false;
+ get_subscription_other = false;
+ get_subscriptions_other = false;
+
+ be_subscribed = true;
+ be_unsubscribed = true;
+
+ set_affiliation = false;
+ };
+ publisher = {
+ create = false;
+ publish = true;
+ retract = true;
+ get_nodes = true;
+
+ subscribe = true;
+ unsubscribe = true;
+ get_subscription = true;
+ get_subscriptions = true;
+ get_items = true;
+
+ subscribe_other = false;
+ unsubscribe_other = false;
+ get_subscription_other = false;
+ get_subscriptions_other = false;
+
+ be_subscribed = true;
+ be_unsubscribed = true;
+
+ set_affiliation = false;
+ };
+ owner = {
+ create = true;
+ publish = true;
+ retract = true;
+ delete = true;
+ get_nodes = true;
+
+ subscribe = true;
+ unsubscribe = true;
+ get_subscription = true;
+ get_subscriptions = true;
+ get_items = true;
+
+
+ subscribe_other = true;
+ unsubscribe_other = true;
+ get_subscription_other = true;
+ get_subscriptions_other = true;
+
+ be_subscribed = true;
+ be_unsubscribed = true;
+
+ set_affiliation = true;
+ };
+ };
+
+ autocreate_on_publish = true;
+ autocreate_on_subscribe = true;
+
+ broadcaster = get_broadcaster(name);
+ get_affiliation = function (jid)
+ if jid_bare(jid) == name then
+ return "owner";
+ elseif subscription_presence(name, jid) then
+ return "subscriber";
+ end
+ end;
+
+ normalize_jid = jid_bare;
+ });
+ return services[name];
+end
+
+function handle_pubsub_iq(event)
+ local origin, stanza = event.origin, event.stanza;
+ local pubsub = stanza.tags[1];
+ local action = pubsub.tags[1];
+ if not action then
+ return origin.send(st.error_reply(stanza, "cancel", "bad-request"));
+ end
+ local service_name = stanza.attr.to or origin.username.."@"..origin.host
+ local service = get_pep_service(service_name);
+ local handler = handlers[stanza.attr.type.."_"..action.name];
+ if handler then
+ handler(origin, stanza, action, service);
+ return true;
+ end
+end
+
+module:hook("iq/bare/"..xmlns_pubsub..":pubsub", handle_pubsub_iq);
+module:hook("iq/bare/"..xmlns_pubsub_owner..":pubsub", handle_pubsub_iq);
+
+module:add_identity("pubsub", "pep", module:get_option_string("name", "Prosody"));
+module:add_feature("http://jabber.org/protocol/pubsub#publish");
+
+local function get_caps_hash_from_presence(stanza, current)
+ local t = stanza.attr.type;
+ if not t then
+ local child = stanza:get_child("c", "http://jabber.org/protocol/caps");
+ if child then
+ local attr = child.attr;
+ if attr.hash then -- new caps
+ if attr.hash == 'sha-1' and attr.node and attr.ver then
+ return attr.ver, attr.node.."#"..attr.ver;
+ end
+ else -- legacy caps
+ if attr.node and attr.ver then
+ return attr.node.."#"..attr.ver.."#"..(attr.ext or ""), attr.node.."#"..attr.ver;
+ end
+ end
+ end
+ return; -- no or bad caps
+ elseif t == "unavailable" or t == "error" then
+ return;
+ end
+ return current; -- no caps, could mean caps optimization, so return current
+end
+
+local function resend_last_item(jid, node, service)
+ local ok, items = service:get_items(node, jid);
+ if not ok then return; end
+ for i, id in ipairs(items) do
+ service.config.broadcaster("items", node, { [jid] = true }, items[id]);
+ end
+end
+
+local function update_subscriptions(recipient, service_name, nodes)
+ local service = get_pep_service(service_name);
+
+ recipients[service_name] = recipients[service_name] or {};
+ nodes = nodes or set_new();
+ local old = recipients[service_name][recipient];
+
+ if old and type(old) == table then
+ for node in pairs((old - nodes):items()) do
+ service:remove_subscription(node, recipient, recipient);
+ end
+ end
+
+ for node in nodes:items() do
+ service:add_subscription(node, recipient, recipient);
+ resend_last_item(recipient, node, service);
+ end
+ recipients[service_name][recipient] = nodes;
+end
+
+module:hook("presence/bare", function(event)
+ -- inbound presence to bare JID recieved
+ local origin, stanza = event.origin, event.stanza;
+ local user = stanza.attr.to or (origin.username..'@'..origin.host);
+ local t = stanza.attr.type;
+ local self = not stanza.attr.to;
+ local service = get_pep_service(user);
+
+ if not t then -- available presence
+ if self or subscription_presence(user, stanza.attr.from) then
+ local recipient = stanza.attr.from;
+ local current = recipients[user] and recipients[user][recipient];
+ local hash, query_node = get_caps_hash_from_presence(stanza, current);
+ if current == hash or (current and current == hash_map[hash]) then return; end
+ if not hash then
+ update_subscriptions(recipient, user);
+ else
+ recipients[user] = recipients[user] or {};
+ if hash_map[hash] then
+ update_subscriptions(recipient, user, hash_map[hash]);
+ else
+ recipients[user][recipient] = hash;
+ local from_bare = origin.type == "c2s" and origin.username.."@"..origin.host;
+ if self or origin.type ~= "c2s" or (recipients[from_bare] and recipients[from_bare][origin.full_jid]) ~= hash then
+ -- COMPAT from ~= stanza.attr.to because OneTeam can't deal with missing from attribute
+ origin.send(
+ st.stanza("iq", {from=user, to=stanza.attr.from, id="disco", type="get"})
+ :tag("query", {xmlns = "http://jabber.org/protocol/disco#info", node = query_node})
+ );
+ end
+ end
+ end
+ end
+ elseif t == "unavailable" then
+ update_subscriptions(stanza.attr.from, user);
+ elseif not self and t == "unsubscribe" then
+ local from = jid_bare(stanza.attr.from);
+ local subscriptions = recipients[user];
+ if subscriptions then
+ for subscriber in pairs(subscriptions) do
+ if jid_bare(subscriber) == from then
+ update_subscriptions(subscriber, user);
+ end
+ end
+ end
+ end
+end, 10);
+
+module:hook("iq-result/bare/disco", function(event)
+ local origin, stanza = event.origin, event.stanza;
+ local disco = stanza:get_child("query", "http://jabber.org/protocol/disco#info");
+ if not disco then
+ return;
+ end
+
+ -- Process disco response
+ local self = not stanza.attr.to;
+ local user = stanza.attr.to or (origin.username..'@'..origin.host);
+ local contact = stanza.attr.from;
+ local current = recipients[user] and recipients[user][contact];
+ if type(current) ~= "string" then return; end -- check if waiting for recipient's response
+ local ver = current;
+ if not string.find(current, "#") then
+ ver = calculate_hash(disco.tags); -- calculate hash
+ end
+ local notify = set_new();
+ for _, feature in pairs(disco.tags) do
+ if feature.name == "feature" and feature.attr.var then
+ local nfeature = feature.attr.var:match("^(.*)%+notify$");
+ if nfeature then notify:add(nfeature); end
+ end
+ end
+ hash_map[ver] = notify; -- update hash map
+ if self then
+ for jid, item in pairs(origin.roster) do -- for all interested contacts
+ if item.subscription == "both" or item.subscription == "from" then
+ if not recipients[jid] then recipients[jid] = {}; end
+ update_subscriptions(contact, jid, notify);
+ end
+ end
+ end
+ update_subscriptions(contact, user, notify);
+end);
+
+module:hook("account-disco-info-node", function(event)
+ local reply, stanza, origin = event.reply, event.stanza, event.origin;
+ local service_name = stanza.attr.to or origin.username.."@"..origin.host
+ local service = get_pep_service(service_name);
+ local node = event.node;
+ local ok = service:get_items(node, jid_bare(stanza.attr.from) or true);
+ if not ok then return; end
+ event.exists = true;
+ reply:tag('identity', {category='pubsub', type='leaf'}):up();
+end);
+
+module:hook("account-disco-info", function(event)
+ local reply = event.reply;
+ reply:tag('identity', {category='pubsub', type='pep'}):up();
+ reply:tag('feature', {var='http://jabber.org/protocol/pubsub#publish'}):up();
+end);
+
+module:hook("account-disco-items-node", function(event)
+ local reply, stanza, origin = event.reply, event.stanza, event.origin;
+ local node = event.node;
+ local service_name = stanza.attr.to or origin.username.."@"..origin.host
+ local service = get_pep_service(service_name);
+ local ok, ret = service:get_items(node, jid_bare(stanza.attr.from) or true);
+ if not ok then return; end
+ event.exists = true;
+ for _, id in ipairs(ret) do
+ reply:tag("item", { jid = service_name, name = id }):up();
+ end
+end);
+
+module:hook("account-disco-items", function(event)
+ local reply, stanza, origin = event.reply, event.stanza, event.origin;
+
+ local service_name = reply.attr.from or origin.username.."@"..origin.host
+ local service = get_pep_service(service_name);
+ local ok, ret = service:get_nodes(jid_bare(stanza.attr.from));
+ if not ok then return; end
+
+ for node, node_obj in pairs(ret) do
+ reply:tag("item", { jid = service_name, node = node, name = node_obj.config.name }):up();
+ end
+end);
diff --git a/plugins/mod_proxy65.lua b/plugins/mod_proxy65.lua
index 2ed9faac..73527cbc 100644
--- a/plugins/mod_proxy65.lua
+++ b/plugins/mod_proxy65.lua
@@ -101,27 +101,10 @@ function module.add_host(module)
module:log("warn", "proxy65_port is deprecated, please put proxy65_ports = { %d } into the global section instead", legacy_config);
end
+ module:depends("disco");
module:add_identity("proxy", "bytestreams", name);
module:add_feature("http://jabber.org/protocol/bytestreams");
- module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function(event)
- local origin, stanza = event.origin, event.stanza;
- if not stanza.tags[1].attr.node then
- origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#info")
- :tag("identity", {category='proxy', type='bytestreams', name=name}):up()
- :tag("feature", {var="http://jabber.org/protocol/bytestreams"}) );
- return true;
- end
- end, -1);
-
- module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function(event)
- local origin, stanza = event.origin, event.stanza;
- if not stanza.tags[1].attr.node then
- origin.send(st.reply(stanza):query("http://jabber.org/protocol/disco#items"));
- return true;
- end
- end, -1);
-
module:hook("iq-get/host/http://jabber.org/protocol/bytestreams:query", function(event)
local origin, stanza = event.origin, event.stanza;
diff --git a/plugins/mod_pubsub/mod_pubsub.lua b/plugins/mod_pubsub/mod_pubsub.lua
index c6dbe831..33e729af 100644
--- a/plugins/mod_pubsub/mod_pubsub.lua
+++ b/plugins/mod_pubsub/mod_pubsub.lua
@@ -100,7 +100,7 @@ module:hook("host-disco-items-node", function (event)
return;
end
- for id, item in pairs(ret) do
+ for _, id in ipairs(ret) do
reply:tag("item", { jid = module.host, name = id }):up();
end
event.exists = true;
diff --git a/plugins/mod_pubsub/pubsub.lib.lua b/plugins/mod_pubsub/pubsub.lib.lua
index 2b015e34..4e9acd68 100644
--- a/plugins/mod_pubsub/pubsub.lib.lua
+++ b/plugins/mod_pubsub/pubsub.lib.lua
@@ -42,8 +42,8 @@ function handlers.get_items(origin, stanza, items, service)
end
local data = st.stanza("items", { node = node });
- for _, entry in pairs(results) do
- data:add_child(entry);
+ for _, id in ipairs(results) do
+ data:add_child(results[id]);
end
local reply;
if data then
diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua
index 94c060b3..df60aefa 100644
--- a/plugins/mod_saslauth.lua
+++ b/plugins/mod_saslauth.lua
@@ -197,7 +197,7 @@ module:hook("stanza/urn:ietf:params:xml:ns:xmpp-sasl:auth", function(event)
return s2s_external_auth(session, stanza)
end
- if session.type ~= "c2s_unauthed" then return; end
+ if session.type ~= "c2s_unauthed" or module:get_host_type() ~= "local" then return; end
if session.sasl_handler and session.sasl_handler.selected then
session.sasl_handler = nil; -- allow starting a new SASL negotiation before completing an old one
diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua
index 27c50cd4..5debb4a3 100644
--- a/plugins/muc/muc.lib.lua
+++ b/plugins/muc/muc.lib.lua
@@ -1265,7 +1265,7 @@ function room_mt:can_set_role(actor_jid, occupant_jid, role)
if actor_jid == true then return true; end
local actor = self._occupants[self:get_occupant_jid(actor_jid)];
- if actor.role == "moderator" then
+ if actor and actor.role == "moderator" then
if occupant.affiliation ~= "owner" and occupant.affiliation ~= "admin" then
if actor.affiliation == "owner" or actor.affiliation == "admin" then
return true;