From 42d4cad137c929a61aff5a32fc581861206c91d1 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Aug 2009 16:45:47 +0500 Subject: mod_legacyauth: Removed useless 'require' call on every login attempt --- plugins/mod_legacyauth.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'plugins') diff --git a/plugins/mod_legacyauth.lua b/plugins/mod_legacyauth.lua index de94411e..3c4e9c82 100644 --- a/plugins/mod_legacyauth.lua +++ b/plugins/mod_legacyauth.lua @@ -47,7 +47,6 @@ module:add_iq_handler("c2s_unauthed", "jabber:iq:auth", else username, password, resource = t_concat(username), t_concat(password), t_concat(resource); local reply = st.reply(stanza); - require "core.usermanager" if usermanager.validate_credentials(session.host, username, password) then -- Authentication successful! local success, err = sessionmanager.make_authenticated(session, username); -- cgit v1.2.3 From ae63e1d1cd5b2d5024e77a32e9af2738db01b400 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Aug 2009 16:46:08 +0500 Subject: mod_legacyauth: Updated to use module:get_option instead of configmanager --- plugins/mod_legacyauth.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_legacyauth.lua b/plugins/mod_legacyauth.lua index 3c4e9c82..c4fec39f 100644 --- a/plugins/mod_legacyauth.lua +++ b/plugins/mod_legacyauth.lua @@ -11,8 +11,7 @@ local st = require "util.stanza"; local t_concat = table.concat; -local config = require "core.configmanager"; -local secure_auth_only = config.get(module:get_host(), "core", "require_encryption"); +local secure_auth_only = module:get_option("require_encryption"); local sessionmanager = require "core.sessionmanager"; local usermanager = require "core.usermanager"; -- cgit v1.2.3 From 3ede8212ce557af2e2f7e08b16a84601b8754d71 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Aug 2009 16:51:35 +0500 Subject: mod_legacyauth: Refactored a bit --- plugins/mod_legacyauth.lua | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_legacyauth.lua b/plugins/mod_legacyauth.lua index c4fec39f..3d27ba71 100644 --- a/plugins/mod_legacyauth.lua +++ b/plugins/mod_legacyauth.lua @@ -42,7 +42,6 @@ module:add_iq_handler("c2s_unauthed", "jabber:iq:auth", :tag("username"):up() :tag("password"):up() :tag("resource"):up()); - return true; else username, password, resource = t_concat(username), t_concat(password), t_concat(resource); local reply = st.reply(stanza); @@ -58,15 +57,9 @@ module:add_iq_handler("c2s_unauthed", "jabber:iq:auth", end end session.send(st.reply(stanza)); - return true; else - local reply = st.reply(stanza); - reply.attr.type = "error"; - reply:tag("error", { code = "401", type = "auth" }) - :tag("not-authorized", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" }); - session.send(reply); - return true; + session.send(st.error_reply(stanza, "auth", "not-authorized")); end end - + return true; end); -- cgit v1.2.3 From 0373133890c7122a3979253dd402829bf732ee2a Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Aug 2009 16:53:18 +0500 Subject: mod_legacyauth: Added a FIXME --- plugins/mod_legacyauth.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/mod_legacyauth.lua b/plugins/mod_legacyauth.lua index 3d27ba71..9a9c3902 100644 --- a/plugins/mod_legacyauth.lua +++ b/plugins/mod_legacyauth.lua @@ -53,7 +53,7 @@ module:add_iq_handler("c2s_unauthed", "jabber:iq:auth", success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource); if not success then session.send(st.error_reply(stanza, err_type, err, err_msg)); - return true; + return true; -- FIXME need to unauthenticate here end end session.send(st.reply(stanza)); -- cgit v1.2.3 From e928c6f02e4abeb44a243bf05d4223c232a70b2d Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Aug 2009 16:55:44 +0500 Subject: mod_posix: Updated to use module:get_option instead of configmanager --- plugins/mod_posix.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua index 0f46888d..83b8122e 100644 --- a/plugins/mod_posix.lua +++ b/plugins/mod_posix.lua @@ -17,7 +17,6 @@ if type(signal) == "string" then module:log("warn", "Couldn't load signal library, won't respond to SIGTERM"); end -local config_get = require "core.configmanager".get; local logger_set = require "util.logger".setwriter; local prosody = _G.prosody; @@ -26,7 +25,7 @@ module.host = "*"; -- we're a global module -- Don't even think about it! module:add_event_hook("server-starting", function () - if pposix.getuid() == 0 and not config_get("*", "core", "run_as_root") then + if pposix.getuid() == 0 and not module:get_option("run_as_root") then module:log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!"); module:log("error", "For more information on running Prosody as root, see http://prosody.im/doc/root"); prosody.shutdown("Refusing to run as root"); @@ -46,7 +45,7 @@ local function write_pidfile() if pidfile_written then remove_pidfile(); end - local pidfile = config_get("*", "core", "pidfile"); + local pidfile = module:get_option("pidfile"); if pidfile then local pf, err = io.open(pidfile, "w+"); if not pf then @@ -76,7 +75,7 @@ function syslog_sink_maker(config) end require "core.loggingmanager".register_sink_type("syslog", syslog_sink_maker); -if not config_get("*", "core", "no_daemonize") then +if not module:get_option("no_daemonize") then local function daemonize_server() local ok, ret = pposix.daemonize(); if not ok then -- cgit v1.2.3 From b5683f55bd23f41df3c90a2f5a6ca60fab56c6e6 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 13 Aug 2009 17:21:44 +0500 Subject: mod_register: Updated to use module:get_option instead of configmanager --- plugins/mod_register.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_register.lua b/plugins/mod_register.lua index 383ab811..0cb8d771 100644 --- a/plugins/mod_register.lua +++ b/plugins/mod_register.lua @@ -9,7 +9,6 @@ local hosts = _G.hosts; local st = require "util.stanza"; -local config = require "core.configmanager"; local datamanager = require "util.datamanager"; local usermanager_user_exists = require "core.usermanager".user_exists; local usermanager_create_user = require "core.usermanager".create_user; @@ -90,16 +89,16 @@ module:add_iq_handler("c2s", "jabber:iq:register", function (session, stanza) end); local recent_ips = {}; -local min_seconds_between_registrations = config.get(module.host, "core", "min_seconds_between_registrations"); -local whitelist_only = config.get(module.host, "core", "whitelist_registration_only"); -local whitelisted_ips = config.get(module.host, "core", "registration_whitelist") or { "127.0.0.1" }; -local blacklisted_ips = config.get(module.host, "core", "registration_blacklist") or {}; +local min_seconds_between_registrations = module:get_option("min_seconds_between_registrations"); +local whitelist_only = module:get_option("whitelist_registration_only"); +local whitelisted_ips = module:get_option("registration_whitelist") or { "127.0.0.1" }; +local blacklisted_ips = module:get_option("registration_blacklist") or {}; for _, ip in ipairs(whitelisted_ips) do whitelisted_ips[ip] = true; end for _, ip in ipairs(blacklisted_ips) do blacklisted_ips[ip] = true; end module:add_iq_handler("c2s_unauthed", "jabber:iq:register", function (session, stanza) - if config.get(module.host, "core", "allow_registration") == false then + if module:get_option("allow_registration") == false then session.send(st.error_reply(stanza, "cancel", "service-unavailable")); elseif stanza.tags[1].name == "query" then local query = stanza.tags[1]; -- cgit v1.2.3 From 2c1d3e4499cf93cd3ff69a843a3db9ef8f9e67cc Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:33:43 +0500 Subject: mod_pep: Added name 'Prosody' to the pubsub/pep identity --- plugins/mod_pep.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins') diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua index e07759f0..842f1fce 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -25,7 +25,7 @@ local data = {}; local recipients = {}; local hash_map = {}; -module:add_identity("pubsub", "pep"); +module:add_identity("pubsub", "pep", "Prosody"); module:add_feature("http://jabber.org/protocol/pubsub#publish"); local function publish(session, node, item) -- cgit v1.2.3 From 4e038edbe7034a4119337b3ff6c5b95ece423b8c Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:37:40 +0500 Subject: mod_disco: Handle disco#info queries using new APIs --- plugins/mod_disco.lua | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index 00ea01d8..c6d40c9e 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -6,8 +6,6 @@ -- COPYING file in the source package for more information. -- - - local discomanager_handle = require "core.discomanager".handle; module:add_feature("http://jabber.org/protocol/disco#info"); @@ -19,3 +17,29 @@ end); module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#items", function (session, stanza) session.send(discomanager_handle(stanza)); end); + +local st = require "util.stanza" +module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) + local origin, stanza = event.origin, event.stanza; + if stanza.attr.type ~= "get" then return; end + local node = stanza.tags[1].attr.node; + if node and node ~= "" then return; end -- TODO fire event? + + local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#info"); + local done = {}; + for _,identity in ipairs(module:get_host_items("identity")) do + local identity_s = identity.category.."\0"..identity.type; + if not done[identity_s] then + reply:tag("identity", identity):up(); + done[identity_s] = true; + end + end + for _,feature in ipairs(module:get_host_items("feature")) do + if not done[feature] then + reply:tag("feature", {var=feature}):up(); + done[feature] = true; + end + end + origin.send(reply); + return true; +end); -- cgit v1.2.3 From 444cc01f25d3c421afd03651c57ecac62b925598 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:38:28 +0500 Subject: mod_disco: Added identity server/im with name 'Prosody' --- plugins/mod_disco.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins') diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index c6d40c9e..15c6a2ff 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -18,6 +18,7 @@ module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#items" session.send(discomanager_handle(stanza)); end); +module:add_identity("server", "im", "Prosody"); local st = require "util.stanza" module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) local origin, stanza = event.origin, event.stanza; -- cgit v1.2.3 From 18d8c7ecfdf6f5fd19f12bea0226b8a1944b4315 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:39:00 +0500 Subject: mod_disco: Handle disco#items queries using new APIs --- plugins/mod_disco.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'plugins') diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index 15c6a2ff..73e1921a 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -7,6 +7,7 @@ -- local discomanager_handle = require "core.discomanager".handle; +local componentmanager_get_children = require "core.componentmanager".get_children; module:add_feature("http://jabber.org/protocol/disco#info"); module:add_feature("http://jabber.org/protocol/disco#items"); @@ -44,3 +45,16 @@ module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(even origin.send(reply); return true; end); +module:hook("iq/host/http://jabber.org/protocol/disco#items:query", function(event) + local origin, stanza = event.origin, event.stanza; + if stanza.attr.type ~= "get" then return; end + local node = stanza.tags[1].attr.node; + if node and node ~= "" then return; end -- TODO fire event? + + local reply = st.reply(stanza):query("http://jabber.org/protocol/disco#items"); + for jid in pairs(componentmanager_get_children(module.host)) do + reply:tag("item", {jid = jid}):up(); + end + origin.send(reply); + return true; +end); -- cgit v1.2.3 From 562ba73c2aaa6d83f922307f12a64934c949899c Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:42:56 +0500 Subject: mod_disco: Removed legacy IQ hooks --- plugins/mod_disco.lua | 7 ------- 1 file changed, 7 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index 73e1921a..8654e46b 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -12,13 +12,6 @@ local componentmanager_get_children = require "core.componentmanager".get_childr module:add_feature("http://jabber.org/protocol/disco#info"); module:add_feature("http://jabber.org/protocol/disco#items"); -module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#info", function (session, stanza) - session.send(discomanager_handle(stanza)); -end); -module:add_iq_handler({"c2s", "s2sin"}, "http://jabber.org/protocol/disco#items", function (session, stanza) - session.send(discomanager_handle(stanza)); -end); - module:add_identity("server", "im", "Prosody"); local st = require "util.stanza" module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) -- cgit v1.2.3 From 6bb3a75b163375623cdc8dfe1537b0fac5500017 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:43:21 +0500 Subject: mod_disco: Removed reference to core.discomanager --- plugins/mod_disco.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'plugins') diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index 8654e46b..31bf90fc 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -6,7 +6,6 @@ -- COPYING file in the source package for more information. -- -local discomanager_handle = require "core.discomanager".handle; local componentmanager_get_children = require "core.componentmanager".get_children; module:add_feature("http://jabber.org/protocol/disco#info"); -- cgit v1.2.3 From 64787ed9eb5f0a5aa31ebe01d3c6360b017fbfbb Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 18 Aug 2009 12:44:42 +0500 Subject: mod_disco: Rearranged some lines, and added a FIXME comment --- plugins/mod_disco.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'plugins') diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index 31bf90fc..06b29f0e 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -7,12 +7,12 @@ -- local componentmanager_get_children = require "core.componentmanager".get_children; +local st = require "util.stanza" +module:add_identity("server", "im", "Prosody"); -- FIXME should be in the non-existing mod_router module:add_feature("http://jabber.org/protocol/disco#info"); module:add_feature("http://jabber.org/protocol/disco#items"); -module:add_identity("server", "im", "Prosody"); -local st = require "util.stanza" module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(event) local origin, stanza = event.origin, event.stanza; if stanza.attr.type ~= "get" then return; end -- cgit v1.2.3