From b803dd8676bdf7408d0befb58b1d477c7937ea5f Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 12 Jun 2012 16:55:27 +0500 Subject: MUC: Handle missing persistent room data. --- plugins/muc/mod_muc.lua | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua index 43b8423d..77ad2647 100644 --- a/plugins/muc/mod_muc.lua +++ b/plugins/muc/mod_muc.lua @@ -65,19 +65,27 @@ local function room_save(room, forced) if forced then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end end +local persistent_errors = false; for jid in pairs(persistent_rooms) do local node = jid_split(jid); - local data = datamanager.load(node, muc_host, "config") or {}; - local room = muc_new_room(jid, { - max_history_length = max_history_messages; - }); - room._data = data._data; - room._data.max_history_length = max_history_messages; -- Overwrite old max_history_length in data with current settings - room._affiliations = data._affiliations; - room.route_stanza = room_route_stanza; - room.save = room_save; - rooms[jid] = room; + local data = datamanager.load(node, muc_host, "config"); + if data then + local room = muc_new_room(jid, { + max_history_length = max_history_messages; + }); + room._data = data._data; + room._data.max_history_length = max_history_messages; -- Overwrite old max_history_length in data with current settings + room._affiliations = data._affiliations; + room.route_stanza = room_route_stanza; + room.save = room_save; + rooms[jid] = room; + else -- missing room data + persistent_rooms[jid] = nil; + module:log("error", "Missing data for room '%s', removing from persistent room list", jid); + persistent_errors = true; + end end +if persistent_errors then datamanager.store(nil, muc_host, "persistent", persistent_rooms); end local host_room = muc_new_room(muc_host, { max_history_length = max_history_messages; -- cgit v1.2.3 From 93f062ef641152f54cc25fa2f1e71111cdba6aaf Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 12 Jun 2012 17:02:35 +0500 Subject: certmanager: Add quotes around cert file path when logging. --- core/certmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/certmanager.lua b/core/certmanager.lua index d524a07e..38092654 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -78,7 +78,7 @@ function create_context(host, mode, user_ssl_config) else reason = "Reason: "..tostring(reason):lower(); end - log("error", "SSL/TLS: Failed to load %s: %s (for %s)", file, reason, host); + log("error", "SSL/TLS: Failed to load '%s': %s (for %s)", file, reason, host); else log("error", "SSL/TLS: Error initialising for %s: %s", host, err); end -- cgit v1.2.3 From f76c2aa90b3cc7ba714571448865fcb30d63ef78 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Tue, 12 Jun 2012 14:29:04 +0200 Subject: mod_adhoc, mod_admin_adhoc, mod_announce: Use module:provides() to manage Ad-Hoc commands --- plugins/adhoc/mod_adhoc.lua | 1 + plugins/mod_admin_adhoc.lua | 28 ++++++++++++++-------------- plugins/mod_announce.lua | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/plugins/adhoc/mod_adhoc.lua b/plugins/adhoc/mod_adhoc.lua index 49d07103..69b2c8da 100644 --- a/plugins/adhoc/mod_adhoc.lua +++ b/plugins/adhoc/mod_adhoc.lua @@ -100,3 +100,4 @@ local function adhoc_removed(event) end module:handle_items("adhoc", adhoc_added, adhoc_removed); +module:handle_items("adhoc-provider", adhoc_added, adhoc_removed); diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua index 4d2c60d7..b8cb0637 100644 --- a/plugins/mod_admin_adhoc.lua +++ b/plugins/mod_admin_adhoc.lua @@ -605,17 +605,17 @@ local reload_modules_desc = adhoc_new("Reload modules", "http://prosody.im/proto local shut_down_service_desc = adhoc_new("Shut Down Service", "http://jabber.org/protocol/admin#shutdown", shut_down_service_handler, "global_admin"); local unload_modules_desc = adhoc_new("Unload modules", "http://prosody.im/protocol/modules#unload", unload_modules_handler, "admin"); -module:add_item("adhoc", add_user_desc); -module:add_item("adhoc", change_user_password_desc); -module:add_item("adhoc", config_reload_desc); -module:add_item("adhoc", delete_user_desc); -module:add_item("adhoc", end_user_session_desc); -module:add_item("adhoc", get_user_password_desc); -module:add_item("adhoc", get_user_roster_desc); -module:add_item("adhoc", get_user_stats_desc); -module:add_item("adhoc", get_online_users_desc); -module:add_item("adhoc", list_modules_desc); -module:add_item("adhoc", load_module_desc); -module:add_item("adhoc", reload_modules_desc); -module:add_item("adhoc", shut_down_service_desc); -module:add_item("adhoc", unload_modules_desc); +module:provides("adhoc", add_user_desc); +module:provides("adhoc", change_user_password_desc); +module:provides("adhoc", config_reload_desc); +module:provides("adhoc", delete_user_desc); +module:provides("adhoc", end_user_session_desc); +module:provides("adhoc", get_user_password_desc); +module:provides("adhoc", get_user_roster_desc); +module:provides("adhoc", get_user_stats_desc); +module:provides("adhoc", get_online_users_desc); +module:provides("adhoc", list_modules_desc); +module:provides("adhoc", load_module_desc); +module:provides("adhoc", reload_modules_desc); +module:provides("adhoc", shut_down_service_desc); +module:provides("adhoc", unload_modules_desc); diff --git a/plugins/mod_announce.lua b/plugins/mod_announce.lua index 77555bec..99fbae50 100644 --- a/plugins/mod_announce.lua +++ b/plugins/mod_announce.lua @@ -96,5 +96,5 @@ end local adhoc_new = module:require "adhoc".new; local announce_desc = adhoc_new("Send Announcement to Online Users", "http://jabber.org/protocol/admin#announce", announce_handler, "admin"); -module:add_item("adhoc", announce_desc); +module:provides("adhoc", announce_desc); -- cgit v1.2.3 From 49d3586dc142ca99b3f8b95584b8375fd7b5ab7c Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Tue, 12 Jun 2012 18:29:58 +0200 Subject: util.dataforms: Fix parsing of -multi fields --- util/dataforms.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/util/dataforms.lua b/util/dataforms.lua index 8cb39144..55bad998 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -185,7 +185,7 @@ field_readers["list-multi"] = function (field_tag, required) local result = {}; for value in field_tag:childtags("value") do - result[#result+1] = value; + result[#result+1] = value:get_text(); end return result, (required and #result == 0 and "Required value missing" or nil); end @@ -202,10 +202,10 @@ field_readers["text-multi"] = field_readers["list-single"] = field_readers["text-single"]; - local boolean_values = { - ["1"] = true, ["true"] = true, - ["0"] = false, ["false"] = false, - }; +local boolean_values = { + ["1"] = true, ["true"] = true, + ["0"] = false, ["false"] = false, +}; field_readers["boolean"] = function (field_tag, required) -- cgit v1.2.3 From 6e9784727f51c2aff07c8bfbdead6ab78cce7269 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 13 Jun 2012 11:47:04 +0500 Subject: s2smanager: Fix a traceback when we close a s2s connection ourselves (thanks for the testing Zash). --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 9e0a91d1..5fe3a375 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -133,7 +133,7 @@ local resting_session = { -- Resting, not dead function retire_session(session, reason) local log = session.log or log; for k in pairs(session) do - if k ~= "trace" and k ~= "log" and k ~= "id" then + if k ~= "trace" and k ~= "log" and k ~= "id" and k ~= "conn" then session[k] = nil; end end -- cgit v1.2.3 From d1a89e8f9c898545d2ef3c9c3e8740a04f19628b Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 15 Jun 2012 02:53:57 +0500 Subject: mod_dialback: Skip an unnecessary nameprep. --- plugins/mod_dialback.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_dialback.lua b/plugins/mod_dialback.lua index 2299c0dc..67be15e3 100644 --- a/plugins/mod_dialback.lua +++ b/plugins/mod_dialback.lua @@ -84,7 +84,7 @@ module:hook("stanza/jabber:server:dialback:result", function(event) origin.from_host = from; end if not origin.to_host then - origin.to_host = nameprep(attr.to); + origin.to_host = to; end origin.log("debug", "asking %s if key %s belongs to them", from, stanza[1]); -- cgit v1.2.3 From 9d379a1dae9a6b46a4e11a13ccdcece4f8c60679 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 18 Jun 2012 16:57:46 +0100 Subject: util.sasl: Make registerMechanism a public function --- util/sasl.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/sasl.lua b/util/sasl.lua index 17d10b80..afb3861b 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -35,7 +35,7 @@ local mechanisms = {}; local backend_mechanism = {}; -- register a new SASL mechanims -local function registerMechanism(name, backends, f) +function registerMechanism(name, backends, f) assert(type(name) == "string", "Parameter name MUST be a string."); assert(type(backends) == "string" or type(backends) == "table", "Parameter backends MUST be either a string or a table."); assert(type(f) == "function", "Parameter f MUST be a function."); -- cgit v1.2.3 From 0c7777aeb6c1b668e2b9e1fddf036dcb27f6db46 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 3 Jul 2012 15:43:46 +0200 Subject: util.pposix: Add setenv() --- util-src/pposix.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/util-src/pposix.c b/util-src/pposix.c index dae48390..a5a89d55 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -581,6 +581,37 @@ int lc_uname(lua_State* L) return 1; } +int lc_setenv(lua_State* L) +{ + const char *var = luaL_checkstring(L, 1); + const char *value; + + /* If the second argument is nil or nothing, unset the var */ + if(lua_isnoneornil(L, 2)) + { + if(unsetenv(var) != 0) + { + lua_pushnil(L); + lua_pushstring(L, strerror(errno)); + return 2; + } + lua_pushboolean(L, 1); + return 1; + } + + value = luaL_checkstring(L, 2); + + if(setenv(var, value, 1) != 0) + { + lua_pushnil(L); + lua_pushstring(L, strerror(errno)); + return 2; + } + + lua_pushboolean(L, 1); + return 1; +} + /* Register functions */ int luaopen_util_pposix(lua_State *L) @@ -612,6 +643,8 @@ int luaopen_util_pposix(lua_State *L) { "uname", lc_uname }, + { "setenv", lc_setenv }, + { NULL, NULL } }; -- cgit v1.2.3 From 92a51d69e913aca81c39b98a9c79751ee97f24e8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 3 Jul 2012 15:56:32 +0200 Subject: prosodyctl: Fix typo --- prosodyctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prosodyctl b/prosodyctl index 45b5604a..0e733d07 100755 --- a/prosodyctl +++ b/prosodyctl @@ -688,7 +688,7 @@ function cert_commands.key(arg) show_message("There was a problem, see OpenSSL output"); else show_usage("cert key HOSTNAME ", "Generates a RSA key named HOSTNAME.key\n " - .."Promps for a key size if none given") + .."Prompts for a key size if none given") end end -- cgit v1.2.3 From ae0fdd43a4248bda8d1f3d01ab592dff0412b574 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 5 Jul 2012 17:58:47 +0200 Subject: util.stanza: Make stanza:childtags() behave like :get_child() --- util/stanza.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/stanza.lua b/util/stanza.lua index 1449f707..5c430f1d 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -133,14 +133,14 @@ function stanza_mt:children() end function stanza_mt:childtags(name, xmlns) - xmlns = xmlns or self.attr.xmlns; local tags = self.tags; local start_i, max_i = 1, #tags; return function () for i = start_i, max_i do local v = tags[i]; if (not name or v.name == name) - and (not xmlns or xmlns == v.attr.xmlns) then + and ((not xmlns and self.attr.xmlns == v.attr.xmlns) + or v.attr.xmlns == xmlns) then start_i = i+1; return v; end -- cgit v1.2.3 From 538620add408ab838ecd6271ea18f5dafab199a0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 25 Jun 2012 00:16:08 +0100 Subject: util.logger: Remove some redundant code --- util/logger.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/util/logger.lua b/util/logger.lua index 4fadb4b9..26206d4d 100644 --- a/util/logger.lua +++ b/util/logger.lua @@ -23,8 +23,6 @@ function init(name) local log_warn = make_logger(name, "warn"); local log_error = make_logger(name, "error"); - --name = nil; -- While this line is not commented, will automatically fill in file/line number info - local namelen = #name; return function (level, message, ...) if level == "debug" then return log_debug(message, ...); -- cgit v1.2.3 From bb7fd8bb306ea2d2893bb7c5bc460ec2f9886687 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Thu, 5 Jul 2012 00:15:49 +0200 Subject: mod_admin_web: Use util.dataforms' own error checking --- plugins/mod_admin_adhoc.lua | 84 +++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua index b8cb0637..efb7f72b 100644 --- a/plugins/mod_admin_adhoc.lua +++ b/plugins/mod_admin_adhoc.lua @@ -27,6 +27,14 @@ local modulemanager = require "modulemanager"; module:depends("adhoc"); local adhoc_new = module:require "adhoc".new; +local function generate_error_message(errors) + local errmsg = {}; + for name, err in pairs(errors) do + errmsg[#errmsg + 1] = name .. ": " .. err; + end + return { status = "completed", error = { message = t_concat(errmsg, "\n") } }; +end + function add_user_command_handler(self, data, state) local add_user_layout = dataforms_new{ title = "Adding a User"; @@ -42,9 +50,9 @@ function add_user_command_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = add_user_layout:data(data.form); - if not fields.accountjid then - return { status = "completed", error = { message = "You need to specify a JID." } }; + local fields, err = add_user_layout:data(data.form); + if err then + return generate_error_message(err); end local username, host, resource = jid.split(fields.accountjid); if data.to ~= host then @@ -85,9 +93,9 @@ function change_user_password_command_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = change_user_password_layout:data(data.form); - if not fields.accountjid or fields.accountjid == "" or not fields.password then - return { status = "completed", error = { message = "Please specify username and password" } }; + local fields, err = change_user_password_layout:data(data.form); + if err then + return generate_error_message(err); end local username, host, resource = jid.split(fields.accountjid); if data.to ~= host then @@ -126,7 +134,10 @@ function delete_user_command_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = delete_user_layout:data(data.form); + local fields, err = delete_user_layout:data(data.form); + if err then + return generate_error_message(err); + end local failed = {}; local succeeded = {}; for _, aJID in ipairs(fields.accountjids) do @@ -175,7 +186,10 @@ function end_user_session_handler(self, data, state) return { status = "canceled" }; end - local fields = end_user_session_layout:data(data.form); + local fields, err = end_user_session_layout:data(data.form); + if err then + return generate_error_message(err); + end local failed = {}; local succeeded = {}; for _, aJID in ipairs(fields.accountjids) do @@ -223,9 +237,9 @@ function get_user_password_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = get_user_password_layout:data(data.form); - if not fields.accountjid then - return { status = "completed", error = { message = "Please specify a JID." } }; + local fields, err = get_user_password_layout:data(data.form); + if err then + return generate_error_message(err); end local user, host, resource = jid.split(fields.accountjid); local accountjid = ""; @@ -261,10 +275,10 @@ function get_user_roster_handler(self, data, state) return { status = "canceled" }; end - local fields = get_user_roster_layout:data(data.form); + local fields, err = get_user_roster_layout:data(data.form); - if not fields.accountjid then - return { status = "completed", error = { message = "Please specify a JID" } }; + if err then + return generate_error_message(err); end local user, host, resource = jid.split(fields.accountjid); @@ -323,10 +337,10 @@ function get_user_stats_handler(self, data, state) return { status = "canceled" }; end - local fields = get_user_stats_layout:data(data.form); + local fields, err = get_user_stats_layout:data(data.form); - if not fields.accountjid then - return { status = "completed", error = { message = "Please specify a JID." } }; + if err then + return generate_error_message(err); end local user, host, resource = jid.split(fields.accountjid); @@ -376,7 +390,11 @@ function get_online_users_command_handler(self, data, state) return { status = "canceled" }; end - local fields = get_online_users_layout:data(data.form); + local fields, err = get_online_users_layout:data(data.form); + + if err then + return generate_error_message(err); + end local max_items = nil if fields.max_items ~= "all" then @@ -436,11 +454,9 @@ function load_module_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = layout:data(data.form); - if (not fields.module) or (fields.module == "") then - return { status = "completed", error = { - message = "Please specify a module." - } }; + local fields, err = layout:data(data.form); + if err then + return generate_error_message(err); end if modulemanager.is_loaded(data.to, fields.module) then return { status = "completed", info = "Module already loaded" }; @@ -470,11 +486,9 @@ function reload_modules_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = layout:data(data.form); - if #fields.modules == 0 then - return { status = "completed", error = { - message = "Please specify a module. (This means your client misbehaved, as this field is required)" - } }; + local fields, err = layout:data(data.form); + if err then + return generate_error_message(err); end local ok_list, err_list = {}, {}; for _, module in ipairs(fields.modules) do @@ -538,7 +552,11 @@ function shut_down_service_handler(self, data, state) return { status = "canceled" }; end - local fields = shut_down_service_layout:data(data.form); + local fields, err = shut_down_service_layout:data(data.form); + + if err then + return generate_error_message(err); + end if fields.announcement and #fields.announcement > 0 then local message = st.message({type = "headline"}, fields.announcement):up() @@ -566,11 +584,9 @@ function unload_modules_handler(self, data, state) if data.action == "cancel" then return { status = "canceled" }; end - local fields = layout:data(data.form); - if #fields.modules == 0 then - return { status = "completed", error = { - message = "Please specify a module. (This means your client misbehaved, as this field is required)" - } }; + local fields, err = layout:data(data.form); + if err then + return generate_error_message(err); end local ok_list, err_list = {}, {}; for _, module in ipairs(fields.modules) do -- cgit v1.2.3 From c0dcd19718cf520511c8986a5cb73d3de9c49a4c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 4 Jul 2012 23:43:18 +0100 Subject: TODO: Add statistics --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index a49bb52b..40e775a3 100644 --- a/TODO +++ b/TODO @@ -5,5 +5,6 @@ - Web interface == 1.0 == +- Statistics - Clustering - World domination -- cgit v1.2.3 From 02dc79e546ce19f54b858c102943ee6d80eec584 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 4 Jul 2012 23:44:13 +0100 Subject: mod_saslauth: Pass session to usermanager.get_sasl_handler() --- plugins/mod_saslauth.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index 804db5f9..f6abd3b8 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -208,7 +208,7 @@ module:hook("stanza/urn:ietf:params:xml:ns:xmpp-sasl:auth", function(event) session.sasl_handler = nil; -- allow starting a new SASL negotiation before completing an old one end if not session.sasl_handler then - session.sasl_handler = usermanager_get_sasl_handler(module.host); + session.sasl_handler = usermanager_get_sasl_handler(module.host, session); end local mechanism = stanza.attr.mechanism; if not session.secure and (secure_auth_only or (mechanism == "PLAIN" and not allow_unencrypted_plain_auth)) then @@ -246,7 +246,7 @@ module:hook("stream-features", function(event) if secure_auth_only and not origin.secure then return; end - origin.sasl_handler = usermanager_get_sasl_handler(module.host); + origin.sasl_handler = usermanager_get_sasl_handler(module.host, origin); local mechanisms = st.stanza("mechanisms", mechanisms_attr); for mechanism in pairs(origin.sasl_handler:mechanisms()) do if mechanism ~= "PLAIN" or origin.secure or allow_unencrypted_plain_auth then -- cgit v1.2.3 From 82ad5962d98bd25ae3ab06103788b6748c000f9a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 7 Jul 2012 02:32:39 +0100 Subject: usermanager: Pass session on to auth provider (missing half of commit 0545a574667b) (thanks Zash) --- core/usermanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/usermanager.lua b/core/usermanager.lua index 50aee701..3aba5786 100644 --- a/core/usermanager.lua +++ b/core/usermanager.lua @@ -91,8 +91,8 @@ function delete_user(username, host) return hosts[host].users.delete_user(username); end -function get_sasl_handler(host) - return hosts[host].users.get_sasl_handler(); +function get_sasl_handler(host, session) + return hosts[host].users.get_sasl_handler(session); end function get_provider(host) -- cgit v1.2.3 From 7180665b081fef6f162e5b06564ebf515d2515f7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 7 Jul 2012 03:42:31 +0200 Subject: mod_auth_anonymous: Attach a fake roster to the session, so the null storage backend can be used --- plugins/mod_auth_anonymous.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/mod_auth_anonymous.lua b/plugins/mod_auth_anonymous.lua index c080177d..3cb7cf98 100644 --- a/plugins/mod_auth_anonymous.lua +++ b/plugins/mod_auth_anonymous.lua @@ -32,9 +32,10 @@ function new_default_provider(host) return nil, "Account creation/modification not supported."; end - function provider.get_sasl_handler() + function provider.get_sasl_handler(session) local anonymous_authentication_profile = { anonymous = function(sasl, username, realm) + session.roster = {}; -- so that the null storage backend doesn't upset rostermanager return true; -- for normal usage you should always return true here end }; -- cgit v1.2.3 From 7b894f50d3a5156fa6f5d5b537d18ab334b78a98 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 7 Jul 2012 23:22:15 +0200 Subject: net.http: Use base64 from util.encodings instead of luasocket --- net/http.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/http.lua b/net/http.lua index f2061e00..6498f8fa 100644 --- a/net/http.lua +++ b/net/http.lua @@ -7,7 +7,7 @@ -- local socket = require "socket" -local mime = require "mime" +local b64 = require "util.encodings".base64.encode; local url = require "socket.url" local httpstream_new = require "util.httpstream".new; @@ -154,7 +154,7 @@ function request(u, ex, callback) }; if req.userinfo then - headers["Authorization"] = "Basic "..mime.b64(req.userinfo); + headers["Authorization"] = "Basic "..b64(req.userinfo); end if ex then -- cgit v1.2.3 From 364fd6915460a12a2fcdcee972da836ba0244e5a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 8 Jul 2012 18:47:05 +0100 Subject: util.pposix: Add meminfo() binding to memory allocation stats provided by mallinfo() [compilation tested on Ubuntu...] --- util-src/pposix.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/util-src/pposix.c b/util-src/pposix.c index a5a89d55..8dfd6c75 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -34,6 +34,11 @@ #include "lua.h" #include "lauxlib.h" +#if (defined(_SVID_SOURCE) && !defined(WITHOUT_MALLINFO)) + #include + #define WITH_MALLINFO +#endif + /* Daemonization support */ static int lc_daemonize(lua_State *L) @@ -612,6 +617,25 @@ int lc_setenv(lua_State* L) return 1; } +#ifdef WITH_MALLINFO +int lc_meminfo(lua_State* L) +{ + struct mallinfo info = mallinfo(); + lua_newtable(L); + lua_pushinteger(L, info.arena); + lua_setfield(L, -2, "allocated"); + lua_pushinteger(L, info.hblkhd); + lua_setfield(L, -2, "allocated_mmap"); + lua_pushinteger(L, info.uordblks); + lua_setfield(L, -2, "used"); + lua_pushinteger(L, info.fordblks); + lua_setfield(L, -2, "unused"); + lua_pushinteger(L, info.keepcost); + lua_setfield(L, -2, "returnable"); + return 1; +} +#endif + /* Register functions */ int luaopen_util_pposix(lua_State *L) @@ -645,6 +669,10 @@ int luaopen_util_pposix(lua_State *L) { "setenv", lc_setenv }, +#ifdef WITH_MALLINFO + { "meminfo", lc_meminfo }, +#endif + { NULL, NULL } }; -- cgit v1.2.3 From ff4d31cd03974874de3ea7d0d09ccc852aee4531 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 8 Jul 2012 18:48:22 +0100 Subject: Backed out changeset 72a2eec4204a (incomplete fix) --- plugins/mod_auth_anonymous.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/mod_auth_anonymous.lua b/plugins/mod_auth_anonymous.lua index 3cb7cf98..c080177d 100644 --- a/plugins/mod_auth_anonymous.lua +++ b/plugins/mod_auth_anonymous.lua @@ -32,10 +32,9 @@ function new_default_provider(host) return nil, "Account creation/modification not supported."; end - function provider.get_sasl_handler(session) + function provider.get_sasl_handler() local anonymous_authentication_profile = { anonymous = function(sasl, username, realm) - session.roster = {}; -- so that the null storage backend doesn't upset rostermanager return true; -- for normal usage you should always return true here end }; -- cgit v1.2.3 From 1c1baa42c8a2c047f938a442d776f33320013c0c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 8 Jul 2012 18:54:30 +0100 Subject: util.pposix: Add comments to mallinfo fields we use, so I don't forget tomorrow what they mean --- util-src/pposix.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util-src/pposix.c b/util-src/pposix.c index 8dfd6c75..65f8b4ab 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -622,14 +622,20 @@ int lc_meminfo(lua_State* L) { struct mallinfo info = mallinfo(); lua_newtable(L); + /* This is the total size of memory allocated with sbrk by malloc, in bytes. */ lua_pushinteger(L, info.arena); lua_setfield(L, -2, "allocated"); + /* This is the total size of memory allocated with mmap, in bytes. */ lua_pushinteger(L, info.hblkhd); lua_setfield(L, -2, "allocated_mmap"); + /* This is the total size of memory occupied by chunks handed out by malloc. */ lua_pushinteger(L, info.uordblks); lua_setfield(L, -2, "used"); + /* This is the total size of memory occupied by free (not in use) chunks. */ lua_pushinteger(L, info.fordblks); lua_setfield(L, -2, "unused"); + /* This is the size of the top-most releasable chunk that normally borders the + end of the heap (i.e., the high end of the virtual address space's data segment). */ lua_pushinteger(L, info.keepcost); lua_setfield(L, -2, "returnable"); return 1; -- cgit v1.2.3 From 88f2090c5b3ace2f2f07de9735fa60307a19d010 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 9 Jul 2012 02:35:47 +0100 Subject: util.throttle: floor() internal balance calculation --- util/throttle.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/throttle.lua b/util/throttle.lua index 2e901158..55e1d07b 100644 --- a/util/throttle.lua +++ b/util/throttle.lua @@ -1,6 +1,7 @@ local gettime = require "socket".gettime; local setmetatable = setmetatable; +local floor = math.floor; module "throttle" @@ -11,7 +12,7 @@ function throttle:update() local newt = gettime(); local elapsed = newt - self.t; self.t = newt; - local balance = self.rate * elapsed + self.balance; + local balance = floor(self.rate * elapsed) + self.balance; if balance > self.max then self.balance = self.max; else -- cgit v1.2.3 From 5968142ab2b3891a2650ae003f34f19c1ed66d94 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 9 Jul 2012 20:21:47 +0200 Subject: mod_admin_telnet: Add some user management commands. --- plugins/mod_admin_telnet.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index b56f9291..208cb08b 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -856,6 +856,37 @@ function def_env.muc:room(room_jid) return setmetatable({ room = room_obj }, console_room_mt); end +def_env.user = {}; +function def_env.user:create(jid, password) + local username, host = jid_split(jid); + local ok, err = um.create_user(username, password, host); + if ok then + return true, "User created"; + else + return nil, "Could not create user: "..err; + end +end + +function def_env.user:delete(jid) + local username, host = jid_split(jid); + local ok, err = um.delete_user(username, host); + if ok then + return true, "User deleted"; + else + return nil, "Could not delete user: "..err; + end +end + +function def_env.user:passwd(jid, password) + local username, host = jid_split(jid); + local ok, err = um.set_password(username, password, host); + if ok then + return true, "User created"; + else + return nil, "Could not change password for user: "..err; + end +end + ------------- function printbanner(session) -- cgit v1.2.3 From 1cecc287b6bc4e4c4d1a091e300b0b733f517ae7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 9 Jul 2012 20:39:55 +0200 Subject: mod_admin_telnet: Add info about user management commands to the help --- plugins/mod_admin_telnet.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index 208cb08b..3390d62e 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -187,6 +187,7 @@ function commands.help(session, data) print [[s2s - Commands to manage sessions between this server and others]] print [[module - Commands to load/reload/unload modules/plugins]] print [[host - Commands to activate, deactivate and list virtual hosts]] + print [[user - Commands to create and delete users, and change their passwords]] print [[server - Uptime, version, shutting down, etc.]] print [[config - Reloading the configuration, etc.]] print [[console - Help regarding the console itself]] @@ -207,6 +208,10 @@ function commands.help(session, data) print [[host:activate(hostname) - Activates the specified host]] print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]] print [[host:list() - List the currently-activated hosts]] + elseif section == "user" then + print [[user:create(jid, password) - Create the specified user account]] + print [[user:password(jid, password) - Set the password for the specified user account]] + print [[user:delete(jid, password) - Permanently remove the specified user account]] elseif section == "server" then print [[server:version() - Show the server's version number]] print [[server:uptime() - Show how long the server has been running]] -- cgit v1.2.3 From 00038375f5fc116b761b3f3f1f8f2f0f4791a3dd Mon Sep 17 00:00:00 2001 From: Marco Cirillo Date: Mon, 9 Jul 2012 19:50:11 +0000 Subject: mod_admin_telnet: add s2s:closeall command and relative help entry. --- plugins/mod_admin_telnet.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index b56f9291..d378edf4 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -198,6 +198,7 @@ function commands.help(session, data) elseif section == "s2s" then print [[s2s:show(domain) - Show all s2s connections for the given domain (or all if no domain given)]] print [[s2s:close(from, to) - Close a connection from one domain to another]] + print [[s2s:closeall(host) - Close all the incoming/outgoing s2s sessions to specified host]] elseif section == "module" then print [[module:load(module, host) - Load the specified module on the specified host (or all hosts if none given)]] print [[module:reload(module, host) - The same, but unloads and loads the module (saving state if the module supports it)]] @@ -769,6 +770,40 @@ function def_env.s2s:close(from, to) return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); end +function def_env.s2s:closeall(host) + local count = 0; + + if not host or type(host) ~= "string" then return false, "wrong syntax: please use s2s:closeall('hostname.tld')"; end + if hosts[host] then + for session in pairs(incoming_s2s) do + if session.to_host == host then + (session.close or s2smanager.destroy_session)(session); + count = count + 1; + end + end + for _, session in pairs(hosts[host].s2sout) do + (session.close or s2smanager.destroy_session)(session); + count = count + 1; + end + else + for session in pairs(incoming_s2s) do + if session.from_host == host then + (session.close or s2smanager.destroy_session)(session); + count = count + 1; + end + end + for _, h in pairs(hosts) do + if h.s2sout[host] then + (h.s2sout[host].close or s2smanager.destroy_session)(h.s2sout[host]); + count = count + 1; + end + end + end + + if count == 0 then return false, "No sessions to close."; + else return true, "Closed "..count.." s2s session"..((count == 1 and "") or "s"); end +end + def_env.host = {}; def_env.hosts = def_env.host; function def_env.host:activate(hostname, config) -- cgit v1.2.3 From bc2afeeef7f74a98466ba5691eb6c3a45b9665a0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 18 Jul 2012 21:18:17 +0200 Subject: adhoc.lib: Make some globals local --- plugins/adhoc/adhoc.lib.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/adhoc/adhoc.lib.lua b/plugins/adhoc/adhoc.lib.lua index eff3caff..f9510172 100644 --- a/plugins/adhoc/adhoc.lib.lua +++ b/plugins/adhoc/adhoc.lib.lua @@ -12,7 +12,7 @@ local states = {} local _M = {}; -function _cmdtag(desc, status, sessionid, action) +local function _cmdtag(desc, status, sessionid, action) local cmd = st.stanza("command", { xmlns = xmlns_cmd, node = desc.node, status = status }); if sessionid then cmd.attr.sessionid = sessionid; end if action then cmd.attr.action = action; end @@ -35,6 +35,7 @@ function _M.handle_cmd(command, origin, stanza) local data, state = command:handler(dataIn, states[sessionid]); states[sessionid] = state; local stanza = st.reply(stanza); + local cmdtag; if data.status == "completed" then states[sessionid] = nil; cmdtag = command:cmdtag("completed", sessionid); -- cgit v1.2.3 From 9f5ddb8708ac4cca468523877c23cd1ebdb2a3de Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 19 Jul 2012 15:35:07 +0100 Subject: moduleapi: Remove unused import of util.multitable --- core/moduleapi.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/moduleapi.lua b/core/moduleapi.lua index 24d29dfe..572dc179 100644 --- a/core/moduleapi.lua +++ b/core/moduleapi.lua @@ -14,8 +14,6 @@ local logger = require "util.logger"; local pluginloader = require "util.pluginloader"; local timer = require "util.timer"; -local multitable_new = require "util.multitable".new; - local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat; local error, setmetatable, setfenv, type = error, setmetatable, setfenv, type; local ipairs, pairs, select, unpack = ipairs, pairs, select, unpack; @@ -339,4 +337,4 @@ function api:load_resource(path, mode) return io.open(path, mode); end -return api; +return api; \ No newline at end of file -- cgit v1.2.3 From f4719b66bc5ed4391b93fb5931a256c1b21fbf1a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 19 Jul 2012 15:36:16 +0100 Subject: mod_admin_adhoc: Remove unused variable and save a bit of CPU... --- plugins/mod_admin_adhoc.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua index b8cb0637..80fca4b7 100644 --- a/plugins/mod_admin_adhoc.lua +++ b/plugins/mod_admin_adhoc.lua @@ -453,7 +453,6 @@ function load_module_handler(self, data, state) '". Error was: "'..tostring(err or "")..'"' } }; end else - local modules = array.collect(keys(hosts[data.to].modules)):sort(); return { status = "executing", form = layout }, "executing"; end end -- cgit v1.2.3 From fb3b789dca8a2cf050dad7a7bd445d4789eaabea Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 16:17:04 +0100 Subject: mod_s2s/s2sout.lib: Don't wait for both v4 and v6 DNS responses if we only send one (e.g. because v6 is disabled) --- plugins/mod_s2s/s2sout.lib.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/mod_s2s/s2sout.lib.lua b/plugins/mod_s2s/s2sout.lib.lua index 48a49036..6e1eb3d7 100644 --- a/plugins/mod_s2s/s2sout.lib.lua +++ b/plugins/mod_s2s/s2sout.lib.lua @@ -170,7 +170,7 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err) local IPs = {}; host_session.ip_hosts = IPs; local handle4, handle6; - local has_other = false; + local have_other_result = not(has_ipv4) or not(has_ipv6) or false; if has_ipv4 then handle4 = adns.lookup(function (reply, err) @@ -195,7 +195,7 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err) end end - if has_other then + if have_other_result then if #IPs > 0 then rfc3484_dest(host_session.ip_hosts, sources); for i = 1, #IPs do @@ -213,11 +213,11 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err) end end else - has_other = true; + have_other_result = true; end end, connect_host, "A", "IN"); else - has_other = true; + have_other_result = true; end if has_ipv6 then @@ -231,7 +231,7 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err) end end - if has_other then + if have_other_result then if #IPs > 0 then rfc3484_dest(host_session.ip_hosts, sources); for i = 1, #IPs do @@ -249,13 +249,12 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err) end end else - has_other = true; + have_other_result = true; end end, connect_host, "AAAA", "IN"); else - has_other = true; + have_other_result = true; end - return true; elseif host_session.ip_hosts and #host_session.ip_hosts > host_session.ip_choice then -- Not our first attempt, and we also have IPs left to try s2sout.try_next_ip(host_session); -- cgit v1.2.3 From 07c9903d58c0d350e705f41a5f4ef780f17fa659 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 16:29:52 +0100 Subject: mod_s2s/s2sout.lib: Fix indentation --- plugins/mod_s2s/s2sout.lib.lua | 120 ++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/plugins/mod_s2s/s2sout.lib.lua b/plugins/mod_s2s/s2sout.lib.lua index 6e1eb3d7..d2c6023e 100644 --- a/plugins/mod_s2s/s2sout.lib.lua +++ b/plugins/mod_s2s/s2sout.lib.lua @@ -173,85 +173,85 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err) local have_other_result = not(has_ipv4) or not(has_ipv6) or false; if has_ipv4 then - handle4 = adns.lookup(function (reply, err) - handle4 = nil; + handle4 = adns.lookup(function (reply, err) + handle4 = nil; - -- COMPAT: This is a compromise for all you CNAME-(ab)users :) - if not (reply and reply[#reply] and reply[#reply].a) then - local count = max_dns_depth; - reply = dns.peek(connect_host, "CNAME", "IN"); - while count > 0 and reply and reply[#reply] and not reply[#reply].a and reply[#reply].cname do - log("debug", "Looking up %s (DNS depth is %d)", tostring(reply[#reply].cname), count); - reply = dns.peek(reply[#reply].cname, "A", "IN") or dns.peek(reply[#reply].cname, "CNAME", "IN"); - count = count - 1; + -- COMPAT: This is a compromise for all you CNAME-(ab)users :) + if not (reply and reply[#reply] and reply[#reply].a) then + local count = max_dns_depth; + reply = dns.peek(connect_host, "CNAME", "IN"); + while count > 0 and reply and reply[#reply] and not reply[#reply].a and reply[#reply].cname do + log("debug", "Looking up %s (DNS depth is %d)", tostring(reply[#reply].cname), count); + reply = dns.peek(reply[#reply].cname, "A", "IN") or dns.peek(reply[#reply].cname, "CNAME", "IN"); + count = count - 1; + end end - end - -- end of CNAME resolving + -- end of CNAME resolving - if reply and reply[#reply] and reply[#reply].a then - for _, ip in ipairs(reply) do - log("debug", "DNS reply for %s gives us %s", connect_host, ip.a); - IPs[#IPs+1] = new_ip(ip.a, "IPv4"); + if reply and reply[#reply] and reply[#reply].a then + for _, ip in ipairs(reply) do + log("debug", "DNS reply for %s gives us %s", connect_host, ip.a); + IPs[#IPs+1] = new_ip(ip.a, "IPv4"); + end end - end - if have_other_result then - if #IPs > 0 then - rfc3484_dest(host_session.ip_hosts, sources); - for i = 1, #IPs do - IPs[i] = {ip = IPs[i], port = connect_port}; + if have_other_result then + if #IPs > 0 then + rfc3484_dest(host_session.ip_hosts, sources); + for i = 1, #IPs do + IPs[i] = {ip = IPs[i], port = connect_port}; + end + host_session.ip_choice = 0; + s2sout.try_next_ip(host_session); + else + log("debug", "DNS lookup failed to get a response for %s", connect_host); + host_session.ip_hosts = nil; + if not s2sout.attempt_connection(host_session, "name resolution failed") then -- Retry if we can + log("debug", "No other records to try for %s - destroying", host_session.to_host); + err = err and (": "..err) or ""; + s2s_destroy_session(host_session, "DNS resolution failed"..err); -- End of the line, we can't + end end - host_session.ip_choice = 0; - s2sout.try_next_ip(host_session); else - log("debug", "DNS lookup failed to get a response for %s", connect_host); - host_session.ip_hosts = nil; - if not s2sout.attempt_connection(host_session, "name resolution failed") then -- Retry if we can - log("debug", "No other records to try for %s - destroying", host_session.to_host); - err = err and (": "..err) or ""; - s2s_destroy_session(host_session, "DNS resolution failed"..err); -- End of the line, we can't - end + have_other_result = true; end - else - have_other_result = true; - end - end, connect_host, "A", "IN"); + end, connect_host, "A", "IN"); else have_other_result = true; end if has_ipv6 then - handle6 = adns.lookup(function (reply, err) - handle6 = nil; + handle6 = adns.lookup(function (reply, err) + handle6 = nil; - if reply and reply[#reply] and reply[#reply].aaaa then - for _, ip in ipairs(reply) do - log("debug", "DNS reply for %s gives us %s", connect_host, ip.aaaa); - IPs[#IPs+1] = new_ip(ip.aaaa, "IPv6"); + if reply and reply[#reply] and reply[#reply].aaaa then + for _, ip in ipairs(reply) do + log("debug", "DNS reply for %s gives us %s", connect_host, ip.aaaa); + IPs[#IPs+1] = new_ip(ip.aaaa, "IPv6"); + end end - end - if have_other_result then - if #IPs > 0 then - rfc3484_dest(host_session.ip_hosts, sources); - for i = 1, #IPs do - IPs[i] = {ip = IPs[i], port = connect_port}; + if have_other_result then + if #IPs > 0 then + rfc3484_dest(host_session.ip_hosts, sources); + for i = 1, #IPs do + IPs[i] = {ip = IPs[i], port = connect_port}; + end + host_session.ip_choice = 0; + s2sout.try_next_ip(host_session); + else + log("debug", "DNS lookup failed to get a response for %s", connect_host); + host_session.ip_hosts = nil; + if not s2sout.attempt_connection(host_session, "name resolution failed") then -- Retry if we can + log("debug", "No other records to try for %s - destroying", host_session.to_host); + err = err and (": "..err) or ""; + s2s_destroy_session(host_session, "DNS resolution failed"..err); -- End of the line, we can't + end end - host_session.ip_choice = 0; - s2sout.try_next_ip(host_session); else - log("debug", "DNS lookup failed to get a response for %s", connect_host); - host_session.ip_hosts = nil; - if not s2sout.attempt_connection(host_session, "name resolution failed") then -- Retry if we can - log("debug", "No other records to try for %s - destroying", host_session.to_host); - err = err and (": "..err) or ""; - s2s_destroy_session(host_session, "DNS resolution failed"..err); -- End of the line, we can't - end + have_other_result = true; end - else - have_other_result = true; - end - end, connect_host, "AAAA", "IN"); + end, connect_host, "AAAA", "IN"); else have_other_result = true; end -- cgit v1.2.3 From 2057401904191d1ee3d7f6e6e620484d954a852d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 16:45:27 +0100 Subject: mod_s2s: Make unauthed session timeout a little more aggressive... otherwise it's possible for sessions to slip under the net and never get killed off --- plugins/mod_s2s/mod_s2s.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua index f6c20606..1dbdc6ee 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -413,11 +413,9 @@ local function initialize_session(session) return handlestanza(session, stanza); end - local conn = session.conn; add_task(connect_timeout, function () - if session.conn ~= conn or session.connecting - or session.type == "s2sin" or session.type == "s2sout" then - return; -- Ok, we're connect[ed|ing] + if session.type == "s2sin" or session.type == "s2sout" then + return; -- Ok, we're connected end -- Not connected, need to close session and clean up (session.log or log)("debug", "Destroying incomplete session %s->%s due to inactivity", -- cgit v1.2.3 From 5e7ab4f153891bb8d220c9d12ce639ad6e31db0a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 16:50:14 +0100 Subject: sessionmanager: Have session.send() of a retired session return false to indicate failure --- core/sessionmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 37c1626a..131c29f7 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -82,7 +82,7 @@ function retire_session(session) end end - function session.send(data) log("debug", "Discarding data sent to resting session: %s", tostring(data)); end + function session.send(data) log("debug", "Discarding data sent to resting session: %s", tostring(data)); return false; end function session.data(data) log("debug", "Discarding data received from resting session: %s", tostring(data)); end return setmetatable(session, resting_session); end -- cgit v1.2.3 From 73c5470e83551c632206d765ac3094f9598d664b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 16:54:33 +0100 Subject: net.server_select, net.server_event: Change semantics of conn:close() - always call ondisconnect (with err == nil), and never close with data in send buffer (i.e. 'now' parameter removed) --- net/server_event.lua | 16 ++++++++-------- net/server_select.lua | 42 ++++++++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/net/server_event.lua b/net/server_event.lua index 03a7708c..3c4185af 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -249,7 +249,7 @@ do return true end function interface_mt:_destroy() -- close this interface + events and call last listener - debug( "closing client with id:", self.id ) + debug( "closing client with id:", self.id, self.fatalerror ) self:_lock( true, true, true ) -- first of all, lock the interface to avoid further actions local _ _ = self.eventread and self.eventread:close( ) -- close events; this must be called outside of the event callbacks! @@ -328,22 +328,22 @@ do end return true end - function interface_mt:close(now) + function interface_mt:close() if self.nointerface then return nil, "locked"; end debug( "try to close client connection with id:", self.id ) if self.type == "client" then self.fatalerror = "client to close" - if ( not self.eventwrite ) or now then -- try to close immediately - self:_lock( true, true, true ) - self:_close() - return true - else -- wait for incomplete write request + if self.eventwrite then -- wait for incomplete write request self:_lock( true, true, false ) debug "closing delayed until writebuffer is empty" return nil, "writebuffer not empty, waiting" + else -- close now + self:_lock( true, true, true ) + self:_close() + return true end else - debug( "try to close server with id:", tostring(self.id), "args:", tostring(now) ) + debug( "try to close server with id:", tostring(self.id)) self.fatalerror = "server to close" self:_lock( true ) self:_close( 0 ) -- add new event to remove the server interface diff --git a/net/server_select.lua b/net/server_select.lua index de637f70..c0f8742e 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -314,22 +314,28 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport end return false, "setoption not implemented"; end - handler.close = function( self, forced ) + handler.force_close = function ( self ) + if bufferqueuelen ~= 0 then + out_put("discarding unwritten data for ", tostring(ip), ":", tostring(clientport)) + for i = bufferqueuelen, 1, -1 do + bufferqueue[i] = nil; + end + bufferqueuelen = 0; + end + return self:close(); + end + handler.close = function( self ) if not handler then return true; end _readlistlen = removesocket( _readlist, socket, _readlistlen ) _readtimes[ handler ] = nil if bufferqueuelen ~= 0 then - if not ( forced or fatalerror ) then - handler.sendbuffer( ) - if bufferqueuelen ~= 0 then -- try again... - if handler then - handler.write = nil -- ... but no further writing allowed - end - toclose = true - return false + handler.sendbuffer() -- Try now to send any outstanding data + if bufferqueuelen ~= 0 then -- Still not empty, so we'll try again later + if handler then + handler.write = nil -- ... but no further writing allowed end - else - send( socket, table_concat( bufferqueue, "", 1, bufferqueuelen ), 1, bufferlen ) -- forced send + toclose = true + return false end end if socket then @@ -347,7 +353,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport local _handler = handler; handler = nil if disconnect then - disconnect(_handler, "closed"); + disconnect(_handler, false); end end if server then @@ -480,7 +486,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport _ = _cleanqueue and clean( bufferqueue ) --out_put( "server.lua: sended '", buffer, "', bytes: ", tostring(succ), ", error: ", tostring(err), ", part: ", tostring(byte), ", to: ", tostring(ip), ":", tostring(clientport) ) else - succ, err, count = false, "closed", 0; + succ, err, count = false, "unexpected close", 0; end if succ then -- sending succesful bufferqueuelen = 0 @@ -491,7 +497,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport drain(handler) end _ = needtls and handler:starttls(nil) - _ = toclose and handler:close( ) + _ = toclose and handler:force_close( ) return true elseif byte and ( err == "timeout" or err == "wantwrite" ) then -- want write buffer = string_sub( buffer, byte + 1, bufferlen ) -- new buffer @@ -504,7 +510,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " write error: ", tostring(err) ) fatalerror = true disconnect( handler, err ) - _ = handler and handler:close( ) + _ = handler and handler:force_close( ) return false end end @@ -547,7 +553,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport end out_put( "server.lua: ssl handshake error: ", tostring(err or "handshake too long") ) disconnect( handler, "ssl handshake failed" ) - _ = handler and handler:close( true ) -- forced disconnect + _ = handler and handler:force_close() return false, err -- handshake failed end ) @@ -810,7 +816,7 @@ loop = function(once) -- this is the main loop of the program end for handler, err in pairs( _closelist ) do handler.disconnect( )( handler, err ) - handler:close( true ) -- forced disconnect + handler:force_close() -- forced disconnect end clean( _closelist ) _currenttime = luasocket_gettime( ) @@ -896,7 +902,7 @@ addtimer( function( ) if os_difftime( _currenttime - timestamp ) > _sendtimeout then --_writetimes[ handler ] = nil handler.disconnect( )( handler, "send timeout" ) - handler:close( true ) -- forced disconnect + handler:force_close() -- forced disconnect end end for handler, timestamp in pairs( _readtimes ) do -- cgit v1.2.3 From ef888131115082b3a54a568128101cf442475dce Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 16:54:58 +0100 Subject: net.http: Don't call ondisconnect manually, net.server now calls it on close --- net/http.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/net/http.lua b/net/http.lua index f2061e00..02f3a265 100644 --- a/net/http.lua +++ b/net/http.lua @@ -203,7 +203,6 @@ function destroy_request(request) if request.conn then request.conn = nil; request.handler:close() - listener.ondisconnect(request.handler, "closed"); end end -- cgit v1.2.3 From 3424d79abb28d65288331e5ff7c2cca17c280e89 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 16:59:12 +0100 Subject: mod_c2s: Don't call ondisconnect manually on close, it is now called by net.server. Replace with inline code for destroying the session, and also waiting for a reply if there is a chance of further data sent by the client. session.send() on a half-closed stream returns false (and does not deliver the data). --- plugins/mod_c2s.lua | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index 55c53e2d..75a6f689 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -24,6 +24,7 @@ local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; local log = module._log; local c2s_timeout = module:get_option_number("c2s_timeout"); +local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5); local opt_keepalives = module:get_option_boolean("tcp_keepalives", false); local sessions = module:shared("sessions"); @@ -143,8 +144,27 @@ local function session_close(session, reason) end end session.send(""); - session.conn:close(); - listener.ondisconnect(session.conn, (reason and (reason.text or reason.condition)) or reason or "session closed"); + + function session.send() return false; end + + local reason = (reason and (reason.text or reason.condition)) or reason or "session closed"; + session.log("info", "c2s stream for %s closed: %s", session.full_jid or ("<"..session.ip..">"), reason); + + -- Authenticated incoming stream may still be sending us stanzas, so wait for from remote + local conn = session.conn; + if reason == "session closed" and not session.notopen and session.type == "c2s" then + -- Grace time to process data from authenticated cleanly-closed stream + add_task(stream_close_timeout, function () + if not session.destroyed then + session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); + sm_destroy_session(session, reason); + conn:close(); + end + end); + else + sm_destroy_session(session, reason); + conn:close(); + end end end @@ -208,10 +228,9 @@ end function listener.ondisconnect(conn, err) local session = sessions[conn]; if session then - (session.log or log)("info", "Client disconnected: %s", err); + (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); sm_destroy_session(session, err); sessions[conn] = nil; - session = nil; end end -- cgit v1.2.3 From 2ab34e601926f595fa7bfb06e9fbf99ea0795525 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 16:59:55 +0100 Subject: mod_message: Don't treat a message as delivered ok if session.send() returns false --- plugins/mod_message.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/mod_message.lua b/plugins/mod_message.lua index ebff2fe7..0b0ad8e4 100644 --- a/plugins/mod_message.lua +++ b/plugins/mod_message.lua @@ -35,10 +35,13 @@ local function process_to_bare(bare, origin, stanza) if user then -- some resources are connected local recipients = user.top_resources; if recipients then + local sent; for i=1,#recipients do - recipients[i].send(stanza); + sent = recipients[i].send(stanza) or sent; + end + if sent then + return true; end - return true; end end -- no resources are online @@ -65,9 +68,7 @@ module:hook("message/full", function(data) local origin, stanza = data.origin, data.stanza; local session = full_sessions[stanza.attr.to]; - if session then - -- TODO fire post processing event - session.send(stanza); + if session and session.send(stanza) then return true; else -- resource not online return process_to_bare(jid_bare(stanza.attr.to), origin, stanza); -- cgit v1.2.3 From 1135a220df42900779c5cdfbd6c2511d4e7dcc4c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 17:01:52 +0100 Subject: mod_iq: Don't treat an iq as handled if session.send() returns false --- plugins/mod_iq.lua | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/mod_iq.lua b/plugins/mod_iq.lua index 6412ad11..8044a533 100644 --- a/plugins/mod_iq.lua +++ b/plugins/mod_iq.lua @@ -17,10 +17,7 @@ if module:get_host_type() == "local" then local origin, stanza = data.origin, data.stanza; local session = full_sessions[stanza.attr.to]; - if session then - -- TODO fire post processing event - session.send(stanza); - else -- resource not online + if not (session and session.send(stanza)) then if stanza.attr.type == "get" or stanza.attr.type == "set" then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); end -- cgit v1.2.3 From 3bdb9e7da9470303b85edf4aea0131d79839b281 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 17:02:18 +0100 Subject: mod_presence: Handle nil disconnection error --- plugins/mod_presence.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 6d039d83..09a6f9f2 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -352,13 +352,15 @@ module:hook("resource-unbind", function(event) -- Send unavailable presence if session.presence then local pres = st.presence{ type = "unavailable" }; - if not(err) or err == "closed" then err = "connection closed"; end - pres:tag("status"):text("Disconnected: "..err):up(); + if err then + pres:tag("status"):text("Disconnected: "..err):up(); + end session:dispatch_stanza(pres); elseif session.directed then local pres = st.presence{ type = "unavailable", from = session.full_jid }; - if not(err) or err == "closed" then err = "connection closed"; end - pres:tag("status"):text("Disconnected: "..err):up(); + if err then + pres:tag("status"):text("Disconnected: "..err):up(); + end for jid in pairs(session.directed) do pres.attr.to = jid; core_post_stanza(session, pres, true); -- cgit v1.2.3 From 900a0add219fab0bc4beb1bcd093ee8c1164958a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 17:04:02 +0100 Subject: mod_s2s: Don't treat a stanza as delivered if session.sends2s() returns false --- plugins/mod_s2s/mod_s2s.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua index 1dbdc6ee..8b1c7dab 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -97,9 +97,10 @@ function route_to_existing_session(event) log("error", "WARNING! This might, possibly, be a bug, but it might not..."); log("error", "We are going to send from %s instead of %s", tostring(host.from_host), tostring(from_host)); end - host.sends2s(stanza); - host.log("debug", "stanza sent over "..host.type); - return true; + if host.sends2s(stanza) then + host.log("debug", "stanza sent over "..host.type); + return true; + end end end end -- cgit v1.2.3 From 6aa575f09b858fef93101afbc7c776f138aca380 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 17:07:21 +0100 Subject: mod_s2s: Don't call ondisconnect manually, don't call conn:close() 3 times (!) and merge its logic and streamdisconnected into session_close - including now waiting for a reply if there is the chance of further stanzas requiring delivery arriving. session.sends2s() on a half-closed stream returns false. --- plugins/mod_s2s/mod_s2s.lua | 48 +++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua index 8b1c7dab..f686fcfb 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -31,6 +31,7 @@ local cert_verify_identity = require "util.x509".verify_identity; local s2sout = module:require("s2sout"); local connect_timeout = module:get_option_number("s2s_timeout", 60); +local stream_close_timeout = module:get_option_number("s2s_close_timeout", 5); local sessions = module:shared("sessions"); @@ -292,18 +293,6 @@ function stream_callbacks.streamclosed(session) session:close(); end -function stream_callbacks.streamdisconnected(session, err) - if err and err ~= "closed" and session.direction == "outgoing" and session.notopen then - (session.log or log)("debug", "s2s connection attempt failed: %s", err); - if s2sout.attempt_connection(session, err) then - (session.log or log)("debug", "...so we're going to try another target"); - return true; -- Session lives for now - end - end - (session.log or log)("info", "s2s disconnected: %s->%s (%s)", tostring(session.from_host), tostring(session.to_host), tostring(err or "closed")); - s2s_destroy_session(session, err); -end - function stream_callbacks.error(session, error, data) if error == "no-stream" then session:close("invalid-namespace"); @@ -375,11 +364,26 @@ local function session_close(session, reason, remote_reason) end end session.sends2s(""); - if session.notopen or not session.conn:close() then - session.conn:close(true); -- Force FIXME: timer? + + function session.sends2s() return false; end + + local reason = remote_reason or (reason and (reason.text or reason.condition)) or reason or "stream closed"; + session.log("info", "%s s2s stream %s->%s closed: %s", session.direction, session.from_host or "(unknown host)", session.to_host or "(unknown host)", reason); + + -- Authenticated incoming stream may still be sending us stanzas, so wait for from remote + local conn = session.conn; + if not session.notopen and session.type == "s2sin" then + add_task(stream_close_timeout, function () + if not session.destroyed then + session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); + s2s_destroy_session(session, reason); + conn:close(); + end + end); + else + s2s_destroy_session(session, reason); + conn:close(); -- Close immediately, as this is an outgoing connection or is not authed end - session.conn:close(); - listener.ondisconnect(session.conn, remote_reason or (reason and (reason.text or reason.condition)) or reason or "stream closed"); end end @@ -473,11 +477,17 @@ end function listener.ondisconnect(conn, err) local session = sessions[conn]; if session then - if stream_callbacks.streamdisconnected(session, err) then - return; -- Connection lives, for now + if err and session.direction == "outgoing" and session.notopen then + (session.log or log)("debug", "s2s connection attempt failed: %s", err); + if s2sout.attempt_connection(session, err) then + (session.log or log)("debug", "...so we're going to try another target"); + return; -- Session lives for now + end end + (session.log or log)("debug", "s2s disconnected: %s->%s (%s)", tostring(session.from_host), tostring(session.to_host), tostring(err or "connection closed")); + s2s_destroy_session(session, err); + sessions[conn] = nil; end - sessions[conn] = nil; end function listener.register_outgoing(conn, session) -- cgit v1.2.3 From f07fe41db1238eaef4efe905f9b136c2d293609e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 18:00:59 +0100 Subject: mod_admin_telnet: Replace anonymous function with loop (saves a closure) --- plugins/mod_admin_telnet.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index b56f9291..0b966f16 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -76,22 +76,22 @@ end function console_listener.onincoming(conn, data) local session = sessions[conn]; - -- Handle data - (function(session, data) + -- Handle data (loop allows us to break to add \0 after response) + repeat local useglobalenv; - + if data:match("^>") then data = data:gsub("^>", ""); useglobalenv = true; elseif data == "\004" then commands["bye"](session, data); - return; + break; else local command = data:lower(); command = data:match("^%w+") or data:match("%p"); if commands[command] then commands[command](session, data); - return; + break; end end @@ -106,7 +106,7 @@ function console_listener.onincoming(conn, data) err = err:gsub("^:%d+: ", ""); err = err:gsub("''", "the end of the line"); session.print("Sorry, I couldn't understand that... "..err); - return; + break; end end @@ -116,26 +116,26 @@ function console_listener.onincoming(conn, data) if not (ranok or message or useglobalenv) and commands[data:lower()] then commands[data:lower()](session, data); - return; + break; end if not ranok then session.print("Fatal error while running command, it did not complete"); session.print("Error: "..taskok); - return; + break; end if not message then session.print("Result: "..tostring(taskok)); - return; + break; elseif (not taskok) and message then session.print("Command completed with a problem"); session.print("Message: "..tostring(message)); - return; + break; end session.print("OK: "..tostring(message)); - end)(session, data); + until true session.send(string.char(0)); end -- cgit v1.2.3 From 689b6f19a0e986598a364f8692d4af31de2c388b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 22:12:17 +0100 Subject: net.server_select: Never call ondisconnect() directly, go via handler:close() or handler:force_close() - fixes cases where ondisconnect() could be called multiple times for the same connection, leading to issues with s2sout retry logic. --- net/server_select.lua | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/net/server_select.lua b/net/server_select.lua index c0f8742e..990188a1 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -314,17 +314,17 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport end return false, "setoption not implemented"; end - handler.force_close = function ( self ) + handler.force_close = function ( self, err ) if bufferqueuelen ~= 0 then - out_put("discarding unwritten data for ", tostring(ip), ":", tostring(clientport)) + out_put("server.lua: discarding unwritten data for ", tostring(ip), ":", tostring(clientport)) for i = bufferqueuelen, 1, -1 do bufferqueue[i] = nil; end bufferqueuelen = 0; end - return self:close(); + return self:close(err); end - handler.close = function( self ) + handler.close = function( self, err ) if not handler then return true; end _readlistlen = removesocket( _readlist, socket, _readlistlen ) _readtimes[ handler ] = nil @@ -353,7 +353,8 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport local _handler = handler; handler = nil if disconnect then - disconnect(_handler, false); + disconnect(_handler, err or false); + disconnect = nil end end if server then @@ -456,8 +457,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport local buffer = buffer or part or "" local len = string_len( buffer ) if len > maxreadlen then - disconnect( handler, "receive buffer exceeded" ) - handler:close( true ) + handler:close( "receive buffer exceeded" ) return false end local count = len * STAT_UNIT @@ -469,8 +469,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport else -- connections was closed or fatal error out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " read error: ", tostring(err) ) fatalerror = true - disconnect( handler, err ) - _ = handler and handler:close( ) + _ = handler and handler:force_close( err ) return false end end @@ -509,8 +508,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport else -- connection was closed during sending or fatal error out_put( "server.lua: client ", tostring(ip), ":", tostring(clientport), " write error: ", tostring(err) ) fatalerror = true - disconnect( handler, err ) - _ = handler and handler:force_close( ) + _ = handler and handler:force_close( err ) return false end end @@ -552,9 +550,8 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport end end out_put( "server.lua: ssl handshake error: ", tostring(err or "handshake too long") ) - disconnect( handler, "ssl handshake failed" ) - _ = handler and handler:force_close() - return false, err -- handshake failed + _ = handler and handler:force_close("ssl handshake failed") + return false, err -- handshake failed end ) end -- cgit v1.2.3 From 360e6eeeeb37625d3fd1a87e2fae9d99068a1d53 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 23:38:21 +0100 Subject: sessionmanager: Clean up some unused variables and imports --- core/sessionmanager.lua | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 131c29f7..bd9255a2 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -6,8 +6,8 @@ -- COPYING file in the source package for more information. -- -local tonumber, tostring, setmetatable = tonumber, tostring, setmetatable; -local ipairs, pairs, print, next= ipairs, pairs, print, next; +local tostring, setmetatable = tostring, setmetatable; +local pairs, next= pairs, next; local hosts = hosts; local full_sessions = full_sessions; @@ -15,7 +15,6 @@ local bare_sessions = bare_sessions; local logger = require "util.logger"; local log = logger.init("sessionmanager"); -local error = error; local rm_load_roster = require "core.rostermanager".load_roster; local config_get = require "core.configmanager".get; local resourceprep = require "util.encodings".stringprep.resourceprep; @@ -23,12 +22,8 @@ local nodeprep = require "util.encodings".stringprep.nodeprep; local uuid_generate = require "util.uuid".generate; local initialize_filters = require "util.filters".initialize; -local fire_event = prosody.events.fire_event; -local add_task = require "util.timer".add_task; local gettime = require "socket".gettime; -local st = require "util.stanza"; - local newproxy = newproxy; local getmetatable = getmetatable; -- cgit v1.2.3 From a60f6500eac1b42712c540a69b3c1e6248fcdd93 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 23:39:27 +0100 Subject: net.server_select: Remove extraneous variable --- net/server_select.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/net/server_select.lua b/net/server_select.lua index 990188a1..025f145d 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -475,7 +475,6 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport end local _sendbuffer = function( ) -- this function sends data local succ, err, byte, buffer, count; - local count; if socket then buffer = table_concat( bufferqueue, "", 1, bufferqueuelen ) succ, err, byte = send( socket, buffer, 1, bufferlen ) -- cgit v1.2.3 From 189de127dceaa78286084213072fd7ccb232dc37 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 23:41:33 +0100 Subject: net.server_select: Remove unused variables and imports --- net/server_select.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/net/server_select.lua b/net/server_select.lua index 025f145d..9104dace 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -19,7 +19,6 @@ end local log, table_concat = require ("util.logger").init("socket"), table.concat; local out_put = function (...) return log("debug", table_concat{...}); end local out_error = function (...) return log("warn", table_concat{...}); end -local mem_free = collectgarbage ----------------------------------// DECLARATION //-- @@ -34,7 +33,6 @@ local pairs = use "pairs" local ipairs = use "ipairs" local tonumber = use "tonumber" local tostring = use "tostring" -local collectgarbage = use "collectgarbage" --// lua libs //-- @@ -49,7 +47,6 @@ local os_difftime = os.difftime local math_min = math.min local math_huge = math.huge local table_concat = table.concat -local table_remove = table.remove local string_len = string.len local string_sub = string.sub local coroutine_wrap = coroutine.wrap @@ -67,7 +64,6 @@ local ssl_wrap = ( luasec and luasec.wrap ) local socket_bind = luasocket.bind local socket_sleep = luasocket.sleep local socket_select = luasocket.select -local ssl_newcontext = ( luasec and luasec.newcontext ) --// functions //-- @@ -84,7 +80,6 @@ local getsettings local closesocket local removesocket local removeserver -local changetimeout local wrapconnection local changesettings -- cgit v1.2.3 From 8a79164f2b9532f912023d343b2d9f0c11dd4b50 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 22 Jul 2012 23:45:53 +0100 Subject: net.server_event: Remove unused variables and imports --- net/server_event.lua | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/net/server_event.lua b/net/server_event.lua index 3c4185af..de44e5fd 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -33,8 +33,6 @@ local cfg = { } local function use(x) return rawget(_G, x); end -local print = use "print" -local pcall = use "pcall" local ipairs = use "ipairs" local string = use "string" local select = use "select" @@ -212,7 +210,6 @@ do self:_lock( false, false, false ) -- unlock the interface; sending, closing etc allowed self.send = self.conn.send -- caching table lookups with new client object self.receive = self.conn.receive - local onsomething if not call_onconnect then -- trigger listener self:onstatus("ssl-handshake-complete"); end @@ -470,9 +467,7 @@ do local string_sub = string.sub -- caching table lookups local string_len = string.len local addevent = base.addevent - local coroutine_wrap = coroutine.wrap local socket_gettime = socket.gettime - local coroutine_yield = coroutine.yield function handleclient( client, ip, port, server, pattern, listener, sslctx ) -- creates an client interface --vdebug("creating client interfacce...") local interface = { @@ -742,7 +737,7 @@ end )( ) local addclient, wrapclient do - function wrapclient( client, ip, port, listeners, pattern, sslctx, startssl ) + function wrapclient( client, ip, port, listeners, pattern, sslctx ) local interface = handleclient( client, ip, port, nil, pattern, listeners, sslctx ) interface:_start_connection(sslctx) return interface, client @@ -778,9 +773,6 @@ do local res, err = client:connect( addr, serverport ) -- connect if res or ( err == "timeout" ) then local ip, port = client:getsockname( ) - local server = function( ) - return nil, "this is a dummy server interface" - end local interface = wrapclient( client, ip, serverport, listener, pattern, sslctx, startssl ) interface:_start_connection( startssl ) debug( "new connection id:", interface.id ) -- cgit v1.2.3 From 8b103580ec6f6d75fb91d6612abfe5fdda8acf90 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 12:25:33 +0100 Subject: mod_disco: Allow configurable name in disco identity (defaults to 'Prosody') --- plugins/mod_disco.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index c3a9c54d..6587d435 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -32,7 +32,7 @@ do -- validate disco_items end end -module:add_identity("server", "im", "Prosody"); -- FIXME should be in the non-existing mod_router +module:add_identity("server", "im", module:get_option_string("name", "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"); -- cgit v1.2.3 From bac46c9935d90b29408e1b3177ad10609b3b9678 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 12:56:47 +0100 Subject: mod_c2s: Change 'reason' parameter of session:close() to take nil to mean 'graceful close initiated by us' and false for 'graceful close initiated by client' --- plugins/mod_c2s.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index 75a6f689..6d8356de 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -76,7 +76,7 @@ end function stream_callbacks.streamclosed(session) session.log("debug", "Received "); - session:close(); + session:close(false); end function stream_callbacks.error(session, error, data) @@ -122,7 +122,7 @@ local function session_close(session, reason) session.send(""); session.send(st.stanza("stream:stream", default_stream_attr):top_tag()); end - if reason then + if reason then -- nil == no err, initiated by us, false == initiated by client if type(reason) == "string" then -- assume stream error log("info", "Disconnecting client, is: %s", reason); session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); @@ -143,16 +143,16 @@ local function session_close(session, reason) end end end - session.send(""); + session.send(""); function session.send() return false; end - local reason = (reason and (reason.text or reason.condition)) or reason or "session closed"; - session.log("info", "c2s stream for %s closed: %s", session.full_jid or ("<"..session.ip..">"), reason); + local reason = (reason and (reason.text or reason.condition)) or reason; + session.log("info", "c2s stream for %s closed: %s", session.full_jid or ("<"..session.ip..">"), reason or "session closed"); -- Authenticated incoming stream may still be sending us stanzas, so wait for from remote local conn = session.conn; - if reason == "session closed" and not session.notopen and session.type == "c2s" then + if reason == nil and not session.notopen and session.type == "c2s" then -- Grace time to process data from authenticated cleanly-closed stream add_task(stream_close_timeout, function () if not session.destroyed then -- cgit v1.2.3 From 9f24aa6cf83b4da1254facafc52d8ed7cda2bc16 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 13:29:33 +0100 Subject: mod_s2s/s2sout.lib: Use %s to insert strings into log messages instead of concatenation --- plugins/mod_s2s/s2sout.lib.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/mod_s2s/s2sout.lib.lua b/plugins/mod_s2s/s2sout.lib.lua index d2c6023e..17978b39 100644 --- a/plugins/mod_s2s/s2sout.lib.lua +++ b/plugins/mod_s2s/s2sout.lib.lua @@ -95,14 +95,14 @@ function s2sout.attempt_connection(host_session, err) handle = nil; host_session.connecting = nil; if answer then - log("debug", to_host.." has SRV records, handling..."); + log("debug", "%s has SRV records, handling...", to_host); local srv_hosts = {}; host_session.srv_hosts = srv_hosts; for _, record in ipairs(answer) do t_insert(srv_hosts, record.srv); end if #srv_hosts == 1 and srv_hosts[1].target == "." then - log("debug", to_host.." does not provide a XMPP service"); + log("debug", "%s does not provide a XMPP service", to_host); s2s_destroy_session(host_session, err); -- Nothing to see here return; end @@ -115,7 +115,7 @@ function s2sout.attempt_connection(host_session, err) log("debug", "Best record found, will connect to %s:%d", connect_host, connect_port); end else - log("debug", to_host.." has no SRV records, falling back to A/AAAA"); + log("debug", "%s has no SRV records, falling back to A/AAAA", to_host); end -- Try with SRV, or just the plain hostname if no SRV local ok, err = s2sout.try_connect(host_session, connect_host, connect_port); -- cgit v1.2.3 From 0771b51658e5f1a83026a71111f9ec89f3bd3493 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 13:31:26 +0100 Subject: mod_s2s: Adjust session:close() in line with mod_c2s's - fixes waiting for if it has already been sent by the peer --- plugins/mod_s2s/mod_s2s.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua index f686fcfb..16a8b461 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -290,7 +290,7 @@ end function stream_callbacks.streamclosed(session) (session.log or log)("debug", "Received "); - session:close(); + session:close(false); end function stream_callbacks.error(session, error, data) @@ -342,7 +342,7 @@ local function session_close(session, reason, remote_reason) session.sends2s(""); session.sends2s(st.stanza("stream:stream", default_stream_attr):top_tag()); end - if reason then + if reason then -- nil == no err, initiated by us, false == initiated by remote if type(reason) == "string" then -- assume stream error log("info", "Disconnecting %s[%s], is: %s", session.host or "(unknown host)", session.type, reason); session.sends2s(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); @@ -363,16 +363,16 @@ local function session_close(session, reason, remote_reason) end end end - session.sends2s(""); + session.sends2s(""); function session.sends2s() return false; end - local reason = remote_reason or (reason and (reason.text or reason.condition)) or reason or "stream closed"; - session.log("info", "%s s2s stream %s->%s closed: %s", session.direction, session.from_host or "(unknown host)", session.to_host or "(unknown host)", reason); + local reason = remote_reason or (reason and (reason.text or reason.condition)) or reason; + session.log("info", "%s s2s stream %s->%s closed: %s", session.direction, session.from_host or "(unknown host)", session.to_host or "(unknown host)", reason or "stream closed"); -- Authenticated incoming stream may still be sending us stanzas, so wait for from remote local conn = session.conn; - if not session.notopen and session.type == "s2sin" then + if reason == nil and not session.notopen and session.type == "s2sin" then add_task(stream_close_timeout, function () if not session.destroyed then session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); -- cgit v1.2.3 From effb9a4c488682020870a17398f6e5e2ed5345ad Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 14:03:00 +0100 Subject: mod_admin_telnet: Always handle commands terminated by line feeds - ensures consistency even when packets are joined or split on the network --- plugins/mod_admin_telnet.lua | 118 +++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 55 deletions(-) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index c5e423da..2ed4ac79 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -13,7 +13,7 @@ local _G = _G; local prosody = _G.prosody; local hosts = prosody.hosts; -local console_listener = { default_port = 5582; default_mode = "*l"; interface = "127.0.0.1" }; +local console_listener = { default_port = 5582; default_mode = "*a"; interface = "127.0.0.1" }; local iterators = require "util.iterators"; local keys, values = iterators.keys, iterators.values; @@ -76,68 +76,76 @@ end function console_listener.onincoming(conn, data) local session = sessions[conn]; - -- Handle data (loop allows us to break to add \0 after response) - repeat - local useglobalenv; + local partial = session.partial_data; + if partial then + data = partial..data; + end - if data:match("^>") then - data = data:gsub("^>", ""); - useglobalenv = true; - elseif data == "\004" then - commands["bye"](session, data); - break; - else - local command = data:lower(); - command = data:match("^%w+") or data:match("%p"); - if commands[command] then - commands[command](session, data); + for line in data:gmatch("[^\n]*[\n\004]") do + -- Handle data (loop allows us to break to add \0 after response) + repeat + local useglobalenv; + + if line:match("^>") then + line = line:gsub("^>", ""); + useglobalenv = true; + elseif line == "\004" then + commands["bye"](session, line); break; + else + local command = line:lower(); + command = line:match("^%w+") or line:match("%p"); + if commands[command] then + commands[command](session, line); + break; + end end - end - session.env._ = data; - - local chunkname = "=console"; - local chunk, err = loadstring("return "..data, chunkname); - if not chunk then - chunk, err = loadstring(data, chunkname); + session.env._ = line; + + local chunkname = "=console"; + local chunk, err = loadstring("return "..line, chunkname); if not chunk then - err = err:gsub("^%[string .-%]:%d+: ", ""); - err = err:gsub("^:%d+: ", ""); - err = err:gsub("''", "the end of the line"); - session.print("Sorry, I couldn't understand that... "..err); + chunk, err = loadstring(line, chunkname); + if not chunk then + err = err:gsub("^%[string .-%]:%d+: ", ""); + err = err:gsub("^:%d+: ", ""); + err = err:gsub("''", "the end of the line"); + session.print("Sorry, I couldn't understand that... "..err); + break; + end + end + + setfenv(chunk, (useglobalenv and redirect_output(_G, session)) or session.env or nil); + + local ranok, taskok, message = pcall(chunk); + + if not (ranok or message or useglobalenv) and commands[line:lower()] then + commands[line:lower()](session, line); break; end - end - - setfenv(chunk, (useglobalenv and redirect_output(_G, session)) or session.env or nil); - - local ranok, taskok, message = pcall(chunk); - - if not (ranok or message or useglobalenv) and commands[data:lower()] then - commands[data:lower()](session, data); - break; - end - - if not ranok then - session.print("Fatal error while running command, it did not complete"); - session.print("Error: "..taskok); - break; - end - - if not message then - session.print("Result: "..tostring(taskok)); - break; - elseif (not taskok) and message then - session.print("Command completed with a problem"); - session.print("Message: "..tostring(message)); - break; - end + + if not ranok then + session.print("Fatal error while running command, it did not complete"); + session.print("Error: "..taskok); + break; + end + + if not message then + session.print("Result: "..tostring(taskok)); + break; + elseif (not taskok) and message then + session.print("Command completed with a problem"); + session.print("Message: "..tostring(message)); + break; + end + + session.print("OK: "..tostring(message)); + until true - session.print("OK: "..tostring(message)); - until true - - session.send(string.char(0)); + session.send(string.char(0)); + end + session.partial_data = data:match("[^\n]+$"); end function console_listener.ondisconnect(conn, err) -- cgit v1.2.3 From 9d5b5e9a9133e4aab2017824f0317db2e8053152 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 14:17:42 +0100 Subject: certmanager: Fix traceback for missing LuaSec (thanks Link Mauve) --- core/certmanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/certmanager.lua b/core/certmanager.lua index 38092654..e5006694 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -17,8 +17,8 @@ local prosody = prosody; local resolve_path = configmanager.resolve_relative_path; local config_path = prosody.paths.config; -local luasec_major, luasec_minor = ssl._VERSION:match("^(%d+)%.(%d+)"); -local luasec_has_noticket = tonumber(luasec_major)>0 or tonumber(luasec_minor)>=4; +local luasec_major, luasec_minor = ssl and ssl._VERSION:match("^(%d+)%.(%d+)"); +local luasec_has_noticket = ssl and (tonumber(luasec_major)>0 or tonumber(luasec_minor)>=4); module "certmanager" -- cgit v1.2.3 From d1da857c337479cf0d9d9f0c62936faefa08d957 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 16:39:49 +0100 Subject: certmanager: Fix for traceback WITH LuaSec... (!) (thanks IRON) --- core/certmanager.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/certmanager.lua b/core/certmanager.lua index e5006694..8a22f3df 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -17,8 +17,11 @@ local prosody = prosody; local resolve_path = configmanager.resolve_relative_path; local config_path = prosody.paths.config; -local luasec_major, luasec_minor = ssl and ssl._VERSION:match("^(%d+)%.(%d+)"); -local luasec_has_noticket = ssl and (tonumber(luasec_major)>0 or tonumber(luasec_minor)>=4); +local luasec_has_noticket; +if ssl then + local luasec_major, luasec_minor = ssl._VERSION:match("^(%d+)%.(%d+)"); + luasec_has_noticket = tonumber(luasec_major)>0 or tonumber(luasec_minor)>=4; +end module "certmanager" -- cgit v1.2.3 From badc4159d600642f97d064a7f74c2ff68dda8abf Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 16:42:26 +0100 Subject: certmanager: Remove unused import of setmetatable --- core/certmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/certmanager.lua b/core/certmanager.lua index 8a22f3df..20a6d609 100644 --- a/core/certmanager.lua +++ b/core/certmanager.lua @@ -11,7 +11,7 @@ local log = require "util.logger".init("certmanager"); local ssl = ssl; local ssl_newcontext = ssl and ssl.newcontext; -local setmetatable, tostring = setmetatable, tostring; +local tostring = tostring; local prosody = prosody; local resolve_path = configmanager.resolve_relative_path; -- cgit v1.2.3 From e89b006f03f692a7e807c54757f0623302c40b85 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 17:32:33 +0100 Subject: Hopefully inert commit to clean up logging across a number of modules, removing all cases of concatenation when building log messages --- core/rostermanager.lua | 12 ++++++------ core/s2smanager.lua | 4 ++-- core/sessionmanager.lua | 2 +- plugins/adhoc/adhoc.lib.lua | 4 ++-- plugins/mod_admin_adhoc.lua | 11 +++++------ plugins/mod_component.lua | 2 +- plugins/mod_dialback.lua | 3 +-- plugins/mod_posix.lua | 12 ++++++------ plugins/mod_presence.lua | 6 +++--- plugins/mod_s2s/mod_s2s.lua | 2 +- util/datamanager.lua | 18 +++++++++--------- 11 files changed, 37 insertions(+), 39 deletions(-) diff --git a/core/rostermanager.lua b/core/rostermanager.lua index 59ba6579..524b61be 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -83,15 +83,15 @@ end function load_roster(username, host) local jid = username.."@"..host; - log("debug", "load_roster: asked for: "..jid); + log("debug", "load_roster: asked for: %s", jid); local user = bare_sessions[jid]; local roster; if user then roster = user.roster; if roster then return roster; end - log("debug", "load_roster: loading for new user: "..username.."@"..host); + log("debug", "load_roster: loading for new user: %s@%s", username, host); else -- Attempt to load roster for non-loaded user - log("debug", "load_roster: loading for offline user: "..username.."@"..host); + log("debug", "load_roster: loading for offline user: %s@%s", username, host); end local data, err = datamanager.load(username, host, "roster"); roster = data or {}; @@ -99,7 +99,7 @@ function load_roster(username, host) if not roster[false] then roster[false] = { broken = err or nil }; end if roster[jid] then roster[jid] = nil; - log("warn", "roster for "..jid.." has a self-contact"); + log("warn", "roster for %s has a self-contact", jid); end if not err then hosts[host].events.fire_event("roster-load", username, host, roster); @@ -108,7 +108,7 @@ function load_roster(username, host) end function save_roster(username, host, roster) - log("debug", "save_roster: saving roster for "..username.."@"..host); + log("debug", "save_roster: saving roster for %s@%s", username, host); if not roster then roster = hosts[host] and hosts[host].sessions[username] and hosts[host].sessions[username].roster; --if not roster then @@ -238,7 +238,7 @@ function set_contact_pending_out(username, host, jid) -- subscribe roster[jid] = item; end item.ask = "subscribe"; - log("debug", "set_contact_pending_out: saving roster; set "..username.."@"..host..".roster["..jid.."].ask=subscribe"); + log("debug", "set_contact_pending_out: saving roster; set %s@%s.roster[%q].ask=subscribe", username, host, jid); return save_roster(username, host, roster); end function unsubscribe(username, host, jid) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 5fe3a375..ece90e8f 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -87,7 +87,7 @@ function mark_connected(session) local from, to = session.from_host, session.to_host; - session.log("info", session.direction.." s2s connection "..from.."->"..to.." complete"); + session.log("info", "%s s2s connection %s->%s complete", session.direction, from, to); local event_data = { session = session }; if session.type == "s2sout" then @@ -105,7 +105,7 @@ function mark_connected(session) if session.direction == "outgoing" then if sendq then - session.log("debug", "sending "..#sendq.." queued stanzas across new outgoing connection to "..session.to_host); + session.log("debug", "sending %d queued stanzas across new outgoing connection to %s", #sendq, session.to_host); for i, data in ipairs(sendq) do send(data[1]); sendq[i] = nil; diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index bd9255a2..f542c021 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -38,7 +38,7 @@ function new_session(conn) getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end; end open_sessions = open_sessions + 1; - log("debug", "open sessions now: ".. open_sessions); + log("debug", "open sessions now: %d", open_sessions); local filter = initialize_filters(session); local w = conn.write; diff --git a/plugins/adhoc/adhoc.lib.lua b/plugins/adhoc/adhoc.lib.lua index f9510172..acdae6b9 100644 --- a/plugins/adhoc/adhoc.lib.lua +++ b/plugins/adhoc/adhoc.lib.lua @@ -65,8 +65,8 @@ function _M.handle_cmd(command, origin, stanza) if (action == "prev") or (action == "next") or (action == "complete") then actions:tag(action):up(); else - module:log("error", 'Command "'..command.name.. - '" at node "'..command.node..'" provided an invalid action "'..action..'"'); + module:log("error", "Command %q at node %q provided an invalid action %q", + command.name, command.node, action); end end cmdtag:add_child(actions); diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua index ee89d84f..016eeb4a 100644 --- a/plugins/mod_admin_adhoc.lua +++ b/plugins/mod_admin_adhoc.lua @@ -63,15 +63,14 @@ function add_user_command_handler(self, data, state) return { status = "completed", error = { message = "Account already exists" } }; else if usermanager_create_user(username, fields.password, host) then - module:log("info", "Created new account " .. username.."@"..host); + module:log("info", "Created new account %s@%s", username, host); return { status = "completed", info = "Account successfully created" }; else return { status = "completed", error = { message = "Failed to write data to disk" } }; end end else - module:log("debug", (fields.accountjid or "") .. " " .. (fields.password or "") .. " " - .. (fields["password-verify"] or "")); + module:log("debug", "Invalid data, password mismatch or empty username while creating account for %s", fields.accountjid or ""); return { status = "completed", error = { message = "Invalid data.\nPassword mismatch, or empty username" } }; end else @@ -143,10 +142,10 @@ function delete_user_command_handler(self, data, state) for _, aJID in ipairs(fields.accountjids) do local username, host, resource = jid.split(aJID); if (host == data.to) and usermanager_user_exists(username, host) and disconnect_user(aJID) and usermanager_create_user(username, nil, host) then - module:log("debug", "User " .. aJID .. " has been deleted"); + module:log("debug", "User %s has been deleted", aJID); succeeded[#succeeded+1] = aJID; else - module:log("debug", "Tried to delete non-existant user "..aJID); + module:log("debug", "Tried to delete non-existant user %s", aJID); failed[#failed+1] = aJID; end end @@ -165,7 +164,7 @@ function disconnect_user(match_jid) local sessions = host.sessions[node] and host.sessions[node].sessions; for resource, session in pairs(sessions or {}) do if not givenResource or (resource == givenResource) then - module:log("debug", "Disconnecting "..node.."@"..hostname.."/"..resource); + module:log("debug", "Disconnecting %s@%s/%s", node, hostname, resource); session:close(); end end diff --git a/plugins/mod_component.lua b/plugins/mod_component.lua index 738124cc..4037ad28 100644 --- a/plugins/mod_component.lua +++ b/plugins/mod_component.lua @@ -124,7 +124,7 @@ local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; function stream_callbacks.error(session, error, data, data2) if session.destroyed then return; end - module:log("warn", "Error processing component stream: "..tostring(error)); + module:log("warn", "Error processing component stream: %s", tostring(error)); if error == "no-stream" then session:close("invalid-namespace"); elseif error == "parse-error" then diff --git a/plugins/mod_dialback.lua b/plugins/mod_dialback.lua index 67be15e3..73a799e9 100644 --- a/plugins/mod_dialback.lua +++ b/plugins/mod_dialback.lua @@ -102,7 +102,6 @@ module:hook("stanza/jabber:server:dialback:verify", function(event) if origin.type == "s2sout_unauthed" or origin.type == "s2sout" then local attr = stanza.attr; local dialback_verifying = dialback_requests[attr.from.."/"..(attr.id or "")]; - module:log("debug", tostring(dialback_verifying).." "..attr.from.." "..origin.to_host); if dialback_verifying and attr.from == origin.to_host then local valid; if attr.type == "valid" then @@ -110,7 +109,7 @@ module:hook("stanza/jabber:server:dialback:verify", function(event) valid = "valid"; else -- Warn the original connection that is was not verified successfully - log("warn", "authoritative server for "..(attr.from or "(unknown)").." denied the key"); + log("warn", "authoritative server for %s denied the key", attr.from or "(unknown)"); valid = "invalid"; end if not dialback_verifying.sends2s then diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua index 1670ac95..db594ccc 100644 --- a/plugins/mod_posix.lua +++ b/plugins/mod_posix.lua @@ -34,19 +34,19 @@ module:hook("server-started", function () if gid then local success, msg = pposix.setgid(gid); if success then - module:log("debug", "Changed group to "..gid.." successfully."); + module:log("debug", "Changed group to %s successfully.", gid); else - module:log("error", "Failed to change group to "..gid..". Error: "..msg); - prosody.shutdown("Failed to change group to "..gid); + module:log("error", "Failed to change group to %s. Error: %s", gid, msg); + prosody.shutdown("Failed to change group to %s", gid); end end if uid then local success, msg = pposix.setuid(uid); if success then - module:log("debug", "Changed user to "..uid.." successfully."); + module:log("debug", "Changed user to %s successfully.", uid); else - module:log("error", "Failed to change user to "..uid..". Error: "..msg); - prosody.shutdown("Failed to change user to "..uid); + module:log("error", "Failed to change user to %s. Error: %s", uid, msg); + prosody.shutdown("Failed to change user to %s", uid); end end end); diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 09a6f9f2..3cac0973 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -160,7 +160,7 @@ function send_presence_of_available_resources(user, host, jid, recipient_session end end end - log("debug", "broadcasted presence of "..count.." resources from "..user.."@"..host.." to "..jid); + log("debug", "broadcasted presence of %d resources from %s@%s to %s", count, user, host, jid); return count; end @@ -169,7 +169,7 @@ function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_ if to_bare == from_bare then return; end -- No self contacts local st_from, st_to = stanza.attr.from, stanza.attr.to; stanza.attr.from, stanza.attr.to = from_bare, to_bare; - log("debug", "outbound presence "..stanza.attr.type.." from "..from_bare.." for "..to_bare); + log("debug", "outbound presence %s from %s for %s", stanza.attr.type, from_bare, to_bare); if stanza.attr.type == "probe" then stanza.attr.from, stanza.attr.to = st_from, st_to; return; @@ -214,7 +214,7 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b local node, host = jid_split(to_bare); local st_from, st_to = stanza.attr.from, stanza.attr.to; stanza.attr.from, stanza.attr.to = from_bare, to_bare; - log("debug", "inbound presence "..stanza.attr.type.." from "..from_bare.." for "..to_bare); + log("debug", "inbound presence %s from %s for %s", stanza.attr.type, from_bare, to_bare); if stanza.attr.type == "probe" then local result, err = rostermanager.is_contact_subscribed(node, host, from_bare); diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua index 16a8b461..314be3f0 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -99,7 +99,7 @@ function route_to_existing_session(event) log("error", "We are going to send from %s instead of %s", tostring(host.from_host), tostring(from_host)); end if host.sends2s(stanza) then - host.log("debug", "stanza sent over "..host.type); + host.log("debug", "stanza sent over %s", host.type); return true; end end diff --git a/util/datamanager.lua b/util/datamanager.lua index a5d676cc..30c1e298 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -115,18 +115,18 @@ function load(username, host, datastore) if not data then local mode = lfs.attributes(getpath(username, host, datastore), "mode"); if not mode then - log("debug", "Assuming empty "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil")); + log("debug", "Assuming empty %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil"); return nil; else -- file exists, but can't be read -- TODO more detailed error checking and logging? - log("error", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil")); + log("error", "Failed to load %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil"); return nil, "Error reading storage"; end end setfenv(data, {}); local success, ret = pcall(data); if not success then - log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil")); + log("error", "Unable to load %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil"); return nil, "Error reading storage"; end return ret; @@ -145,7 +145,7 @@ function store(username, host, datastore, data) -- save the datastore local f, msg = io_open(getpath(username, host, datastore, nil, true), "w+"); if not f then - log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil")); + log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil"); return nil, "Error saving to storage"; end f:write("return "); @@ -166,7 +166,7 @@ function list_append(username, host, datastore, data) -- save the datastore local f, msg = io_open(getpath(username, host, datastore, "list", true), "a+"); if not f then - log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil")); + log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil"); return; end f:write("item("); @@ -184,7 +184,7 @@ function list_store(username, host, datastore, data) -- save the datastore local f, msg = io_open(getpath(username, host, datastore, "list", true), "w+"); if not f then - log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or "nil").."@"..(host or "nil")); + log("error", "Unable to write to %s storage ('%s') for user: %s@%s", datastore, msg, username or "nil", host or "nil"); return; end for _, d in ipairs(data) do @@ -207,11 +207,11 @@ function list_load(username, host, datastore) if not data then local mode = lfs.attributes(getpath(username, host, datastore, "list"), "mode"); if not mode then - log("debug", "Assuming empty "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil")); + log("debug", "Assuming empty %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil"); return nil; else -- file exists, but can't be read -- TODO more detailed error checking and logging? - log("error", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil")); + log("error", "Failed to load %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil"); return nil, "Error reading storage"; end end @@ -219,7 +219,7 @@ function list_load(username, host, datastore) setfenv(data, {item = function(i) t_insert(items, i); end}); local success, ret = pcall(data); if not success then - log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil")); + log("error", "Unable to load %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil"); return nil, "Error reading storage"; end return items; -- cgit v1.2.3 From 249829afcb3933e8ce24252209400088a751ebf6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 17:35:18 +0100 Subject: s2smanager: Remove logging of (unknown) in a case where from_host and to_host should always be set --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index ece90e8f..76dde9d2 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -74,7 +74,7 @@ function make_authenticated(session, host) else return false; end - session.log("debug", "connection %s->%s is now authenticated for %s", session.from_host or "(unknown)", session.to_host or "(unknown)", host); + session.log("debug", "connection %s->%s is now authenticated for %s", session.from_host, session.to_host, host); mark_connected(session); -- cgit v1.2.3 From 99fee69edbabfff0bb8dcc2d1e840d51cc2ad4f4 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 18:26:30 +0100 Subject: sessionmanager: Lower 'destroying session' message to 'debug' level (from 'info') --- core/sessionmanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index f542c021..6945b8de 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -83,7 +83,7 @@ function retire_session(session) end function destroy_session(session, err) - (session.log or log)("info", "Destroying session for %s (%s@%s)%s", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)", err and (": "..err) or ""); + (session.log or log)("debug", "Destroying session for %s (%s@%s)%s", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)", err and (": "..err) or ""); if session.destroyed then return; end -- Remove session/resource from user's session list -- cgit v1.2.3 From 9931497619b53ed5006f0cce5346d6618ad49863 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 18:28:14 +0100 Subject: mod_c2s, mod_s2s: Lower 'Disconnecting X' log messages from 'info' to 'debug' --- plugins/mod_c2s.lua | 6 +++--- plugins/mod_s2s/mod_s2s.lua | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index 6d8356de..1f62b4d4 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -124,7 +124,7 @@ local function session_close(session, reason) end if reason then -- nil == no err, initiated by us, false == initiated by client if type(reason) == "string" then -- assume stream error - log("info", "Disconnecting client, is: %s", reason); + log("debug", "Disconnecting client, is: %s", reason); session.send(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); elseif type(reason) == "table" then if reason.condition then @@ -135,10 +135,10 @@ local function session_close(session, reason) if reason.extra then stanza:add_child(reason.extra); end - log("info", "Disconnecting client, is: %s", tostring(stanza)); + log("debug", "Disconnecting client, is: %s", tostring(stanza)); session.send(stanza); elseif reason.name then -- a stanza - log("info", "Disconnecting client, is: %s", tostring(reason)); + log("debug", "Disconnecting client, is: %s", tostring(reason)); session.send(reason); end end diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua index 314be3f0..d22463bd 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -344,7 +344,7 @@ local function session_close(session, reason, remote_reason) end if reason then -- nil == no err, initiated by us, false == initiated by remote if type(reason) == "string" then -- assume stream error - log("info", "Disconnecting %s[%s], is: %s", session.host or "(unknown host)", session.type, reason); + log("debug", "Disconnecting %s[%s], is: %s", session.host or "(unknown host)", session.type, reason); session.sends2s(st.stanza("stream:error"):tag(reason, {xmlns = 'urn:ietf:params:xml:ns:xmpp-streams' })); elseif type(reason) == "table" then if reason.condition then @@ -355,10 +355,10 @@ local function session_close(session, reason, remote_reason) if reason.extra then stanza:add_child(reason.extra); end - log("info", "Disconnecting %s[%s], is: %s", session.host or "(unknown host)", session.type, tostring(stanza)); + log("debug", "Disconnecting %s[%s], is: %s", session.host or "(unknown host)", session.type, tostring(stanza)); session.sends2s(stanza); elseif reason.name then -- a stanza - log("info", "Disconnecting %s->%s[%s], is: %s", session.from_host or "(unknown host)", session.to_host or "(unknown host)", session.type, tostring(reason)); + log("debug", "Disconnecting %s->%s[%s], is: %s", session.from_host or "(unknown host)", session.to_host or "(unknown host)", session.type, tostring(reason)); session.sends2s(reason); end end -- cgit v1.2.3 From be5630627292219cfdee1bbba855648ba395a76e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Jul 2012 18:57:28 +0100 Subject: mod_s2s: Bump s2s_timeout to 90, to allow for the TCP timeout (in most cases) - this allows us to continue to try other targets --- plugins/mod_s2s/mod_s2s.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua index d22463bd..9f65f346 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -30,7 +30,7 @@ local cert_verify_identity = require "util.x509".verify_identity; local s2sout = module:require("s2sout"); -local connect_timeout = module:get_option_number("s2s_timeout", 60); +local connect_timeout = module:get_option_number("s2s_timeout", 90); local stream_close_timeout = module:get_option_number("s2s_close_timeout", 5); local sessions = module:shared("sessions"); -- cgit v1.2.3 From 679474405392564918f652f8abb78b878f51036f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 23 Jul 2012 23:05:32 +0200 Subject: mod_bosh: Use new format for headers when checking for proxies to get the originating IP --- plugins/mod_bosh.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua index 8b612286..2ac6b4ed 100644 --- a/plugins/mod_bosh.lua +++ b/plugins/mod_bosh.lua @@ -56,7 +56,7 @@ local trusted_proxies = module:get_option_set("trusted_proxies", {"127.0.0.1"}). local function get_ip_from_request(request) local ip = request.conn:ip(); - local forwarded_for = request.headers["x-forwarded-for"]; + local forwarded_for = request.headers.x_forwarded_for; if forwarded_for then forwarded_for = forwarded_for..", "..ip; for forwarded_ip in forwarded_for:gmatch("[^%s,]+") do -- cgit v1.2.3 From ce33d9c59d49b9b290a8c2c142861dc35779c1b1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 24 Jul 2012 10:44:37 +0100 Subject: mod_muc: Fix a couple of cases of 'forbidden' stanza error being sent with type 'cancel' - fixes #303 --- plugins/muc/muc.lib.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 5178cb1e..a40dc05f 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -856,7 +856,7 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha if not occupant then -- not in room origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); elseif occupant.role == "visitor" then - origin.send(st.error_reply(stanza, "cancel", "forbidden")); + origin.send(st.error_reply(stanza, "auth", "forbidden")); else local from = stanza.attr.from; stanza.attr.from = current_nick; @@ -867,7 +867,7 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza else stanza.attr.from = from; - origin.send(st.error_reply(stanza, "cancel", "forbidden")); + origin.send(st.error_reply(stanza, "auth", "forbidden")); end else self:broadcast_message(stanza, self:get_historylength() > 0); -- cgit v1.2.3 From 9306fa497983088359c6f1f6b8c4658bf0ec2b99 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 24 Jul 2012 10:56:47 +0100 Subject: mod_auth_cyrus, util.sasl_cyrus: Add new option 'cyrus_server_fqdn' to override the hostname passed to Cyrus (and used in e.g. GSSAPI/Kerberos) - fixes #295 --- plugins/mod_auth_cyrus.lua | 4 +++- util/sasl_cyrus.lua | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/mod_auth_cyrus.lua b/plugins/mod_auth_cyrus.lua index 447fae51..e4493f04 100644 --- a/plugins/mod_auth_cyrus.lua +++ b/plugins/mod_auth_cyrus.lua @@ -14,6 +14,7 @@ local cyrus_service_realm = module:get_option("cyrus_service_realm"); local cyrus_service_name = module:get_option("cyrus_service_name"); local cyrus_application_name = module:get_option("cyrus_application_name"); local require_provisioning = module:get_option("cyrus_require_provisioning") or false; +local host_fqdn = module:get_option("cyrus_server_fqdn"); prosody.unlock_globals(); --FIXME: Figure out why this is needed and -- why cyrussasl isn't caught by the sandbox @@ -23,7 +24,8 @@ local new_sasl = function(realm) return cyrus_new( cyrus_service_realm or realm, cyrus_service_name or "xmpp", - cyrus_application_name or "prosody" + cyrus_application_name or "prosody", + host_fqdn ); end diff --git a/util/sasl_cyrus.lua b/util/sasl_cyrus.lua index 002118fd..19684587 100644 --- a/util/sasl_cyrus.lua +++ b/util/sasl_cyrus.lua @@ -78,11 +78,15 @@ local function init(service_name) end -- create a new SASL object which can be used to authenticate clients -function new(realm, service_name, app_name) +-- host_fqdn may be nil in which case gethostname() gives the value. +-- For GSSAPI, this determines the hostname in the service ticket (after +-- reverse DNS canonicalization, only if [libdefaults] rdns = true which +-- is the default). +function new(realm, service_name, app_name, host_fqdn) init(app_name or service_name); - local st, ret = pcall(cyrussasl.server_new, service_name, nil, realm, nil, nil) + local st, ret = pcall(cyrussasl.server_new, service_name, host_fqdn, realm, nil, nil) if not st then log("error", "Creating SASL server connection failed: %s", ret); return nil; -- cgit v1.2.3 From a9b451200578c00115686b2db7e41ef09e622115 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 24 Jul 2012 15:50:11 +0100 Subject: loggingmanager: Remove unused variables --- core/loggingmanager.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua index 56a3ee2c..ce25b0e8 100644 --- a/core/loggingmanager.lua +++ b/core/loggingmanager.lua @@ -7,14 +7,12 @@ -- -local format, rep = string.format, string.rep; -local pcall = pcall; -local debug = debug; -local tostring, setmetatable, rawset, pairs, ipairs, type = - tostring, setmetatable, rawset, pairs, ipairs, type; +local format = string.format; +local setmetatable, rawset, pairs, ipairs, type = + setmetatable, rawset, pairs, ipairs, type; local io_open, io_write = io.open, io.write; local math_max, rep = math.max, string.rep; -local os_date, os_getenv = os.date, os.getenv; +local os_date = os.date; local getstyle, setstyle = require "util.termcolours".getstyle, require "util.termcolours".setstyle; if os.getenv("__FLUSH_LOG") then -- cgit v1.2.3 From edf00237621d4e280a07090be83ae8a64c790768 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 24 Jul 2012 21:36:47 +0200 Subject: mod_admin_telnet: Remove unused or duplicated locals --- plugins/mod_admin_telnet.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index 2ed4ac79..7cfb2751 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -642,7 +642,6 @@ local function print_errors(print, errors) end function def_env.s2s:showcert(domain) - local ser = require "util.serialization".serialize; local print = self.session.print; local domain_sessions = set.new(array.collect(keys(incoming_s2s))) /function(session) return session.from_host == domain and session or nil; end; @@ -689,7 +688,6 @@ function def_env.s2s:showcert(domain) end local domain_certs = array.collect(values(cert_set)); -- Phew. We now have a array of unique certificates presented by domain. - local print = self.session.print; local n_certs = #domain_certs; if n_certs == 0 then -- cgit v1.2.3 From 61ea70dcd6a33bd54e681df7ae89fa1c0916dbdc Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 24 Jul 2012 21:37:16 +0200 Subject: mod_admin_telnet: Add missing import of usermanager --- plugins/mod_admin_telnet.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index 7cfb2751..17e5babc 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -902,6 +902,8 @@ function def_env.muc:room(room_jid) return setmetatable({ room = room_obj }, console_room_mt); end +local um = require"core.usermanager"; + def_env.user = {}; function def_env.user:create(jid, password) local username, host = jid_split(jid); -- cgit v1.2.3 From b27ef47ca4af1b2aad018806ddff4cececd163a1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 24 Jul 2012 22:03:51 +0200 Subject: mod_admin_telnet: Remove useless call to string.lower() --- plugins/mod_admin_telnet.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index 17e5babc..b698d200 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -93,8 +93,7 @@ function console_listener.onincoming(conn, data) commands["bye"](session, line); break; else - local command = line:lower(); - command = line:match("^%w+") or line:match("%p"); + local command = line:match("^%w+") or line:match("%p"); if commands[command] then commands[command](session, line); break; -- cgit v1.2.3 From 372049e1141baf204af3d719ad38ff5bcd71a53d Mon Sep 17 00:00:00 2001 From: IRON Date: Wed, 25 Jul 2012 18:49:13 +0300 Subject: mod_pep: Allow configurable service discovery identity --- plugins/mod_pep.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua index bbdd5f19..5a6196f2 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -32,7 +32,7 @@ module.restore = function(state) hash_map = state.hash_map or {}; end -module:add_identity("pubsub", "pep", "Prosody"); +module:add_identity("pubsub", "pep", "pep", module:get_option_string("name", "Prosody")); module:add_feature("http://jabber.org/protocol/pubsub#publish"); local function subscription_presence(user_bare, recipient) -- cgit v1.2.3 From 6da5a6f1c0955b5f3031ab075d83393563e92446 Mon Sep 17 00:00:00 2001 From: IRON Date: Wed, 25 Jul 2012 19:04:42 +0300 Subject: mod_pep: Allow configurable service discovery identity (Fix) --- plugins/mod_pep.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua index 5a6196f2..d6fe9a81 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -32,7 +32,7 @@ module.restore = function(state) hash_map = state.hash_map or {}; end -module:add_identity("pubsub", "pep", "pep", module:get_option_string("name", "Prosody")); +module:add_identity("pubsub", "pep", module:get_option_string("name", "Prosody")); module:add_feature("http://jabber.org/protocol/pubsub#publish"); local function subscription_presence(user_bare, recipient) -- cgit v1.2.3 From fe4e7ec80f11408df9ebbfed5ba16e50262658a2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 25 Jul 2012 20:31:14 +0200 Subject: portmanager: Show a friendly error message when initializing SSL fails (thanks MattJ for the entire patch that I fixed one line in) --- core/portmanager.lua | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/core/portmanager.lua b/core/portmanager.lua index b563fb10..3fcc8173 100644 --- a/core/portmanager.lua +++ b/core/portmanager.lua @@ -52,13 +52,6 @@ local function error_to_friendly_message(service_name, port, err) end elseif err:match("permission") then friendly_message = "Prosody does not have sufficient privileges to use this port"; - elseif err == "no ssl context" then - if not config.get("*", "core", "ssl") then - friendly_message = "there is no 'ssl' config under Host \"*\" which is " - .."require for legacy SSL ports"; - else - friendly_message = "initializing SSL support failed, see previous log entries"; - end end return friendly_message; end @@ -110,22 +103,28 @@ function activate(service_name) if #active_services:search(nil, interface, port) > 0 then log("error", "Multiple services configured to listen on the same port ([%s]:%d): %s, %s", interface, port, active_services:search(nil, interface, port)[1][1].service.name or "", service_name or ""); else + local err; -- Create SSL context for this service/port if service_info.encryption == "ssl" then local ssl_config = config.get("*", config_prefix.."ssl"); - ssl = certmanager.create_context(service_info.name.." port "..port, "server", ssl_config and (ssl_config[port] + ssl, err = certmanager.create_context(service_info.name.." port "..port, "server", ssl_config and (ssl_config[port] or (ssl_config.certificate and ssl_config))); + if not ssl then + log("error", "Error binding encrypted port for %s: %s", service_info.name, error_to_friendly_message(service_name, port, err) or "unknown error"); + end end - -- Start listening on interface+port - local handler, err = server.addserver(interface, port, listener, mode, ssl); - if not handler then - log("error", "Failed to open server port %d on %s, %s", port, interface, error_to_friendly_message(service_name, port, err)); - else - log("debug", "Added listening service %s to [%s]:%d", service_name, interface, port); - active_services:add(service_name, interface, port, { - server = handler; - service = service_info; - }); + if not err then + -- Start listening on interface+port + local handler, err = server.addserver(interface, port, listener, mode, ssl); + if not handler then + log("error", "Failed to open server port %d on %s, %s", port, interface, error_to_friendly_message(service_name, port, err)); + else + log("debug", "Added listening service %s to [%s]:%d", service_name, interface, port); + active_services:add(service_name, interface, port, { + server = handler; + service = service_info; + }); + end end end end -- cgit v1.2.3 From 7f3c5bae633adf3d19aef14d545b0fede000c545 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 25 Jul 2012 20:33:20 +0200 Subject: net.server_event: Don't emit empty packets, check for errors first. (fixes #287) --- net/server_event.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/server_event.lua b/net/server_event.lua index de44e5fd..264d50a7 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -597,16 +597,14 @@ do end local buffer, err, part = interface.conn:receive( interface._pattern ) -- receive buffer with "pattern" --vdebug( "read data:", tostring(buffer), "error:", tostring(err), "part:", tostring(part) ) - buffer = buffer or part or "" - local len = string_len( buffer ) - if len > cfg.MAX_READ_LENGTH then -- check buffer length + buffer = buffer or part + if buffer and #buffer > cfg.MAX_READ_LENGTH then -- check buffer length interface.fatalerror = "receive buffer exceeded" debug( "fatal error:", interface.fatalerror ) interface:_close() interface.eventread = nil return -1 end - interface.onincoming( interface, buffer, err ) -- send new data to listener if err and ( err ~= "timeout" and err ~= "wantread" ) then if "wantwrite" == err then -- need to read on write event if not interface.eventwrite then -- register new write event if needed @@ -626,6 +624,8 @@ do interface.eventread = nil return -1 end + else + interface.onincoming( interface, buffer, err ) -- send new data to listener end if interface.noreading then interface.eventread = nil; -- cgit v1.2.3 From a6f403360b7064c2f787655f04825b829bb2d78e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 26 Jul 2012 02:27:24 +0200 Subject: mod_admin_telnet: Add xmpp:ping(from, to), useful for initiating s2s connections --- plugins/mod_admin_telnet.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index b698d200..7b176d73 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -934,6 +934,20 @@ function def_env.user:passwd(jid, password) end end +def_env.xmpp = {}; + +local st = require "util.stanza"; +function def_env.xmpp:ping(localhost, remotehost) + if hosts[localhost] then + core_post_stanza(hosts[localhost], + st.iq{ from=localhost, to=remotehost, type="get", id="ping" } + :tag("ping", {xmlns="urn:xmpp:ping"})); + return true, "Sent ping"; + else + return nil, "No such host"; + end +end + ------------- function printbanner(session) -- cgit v1.2.3 From d4e9884d66ab69c34c06bdfb9c2acda34dce2ec2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 26 Jul 2012 04:30:30 +0200 Subject: stanza_router: Warn if the global core_*_stanza() functions are called --- core/stanza_router.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/stanza_router.lua b/core/stanza_router.lua index f01c0fee..94753678 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -17,6 +17,18 @@ local jid_prepped_split = require "util.jid".prepped_split; local full_sessions = _G.prosody.full_sessions; local bare_sessions = _G.prosody.bare_sessions; +local core_post_stanza, core_process_stanza, core_route_stanza; + +function deprecated_warning(f) + _G[f] = function(...) + log("warn", "Using the global %s() is deprecated, use module:send() or prosody.%s(). %s", f, f, debug.traceback()); + return prosody[f](...); + end +end +deprecated_warning"core_post_stanza"; +deprecated_warning"core_process_stanza"; +deprecated_warning"core_route_stanza"; + local function handle_unhandled_stanza(host, origin, stanza) local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns or "jabber:client", origin.type; if name == "iq" and xmlns == "jabber:client" then -- cgit v1.2.3 From 9114e88ee0cf86ca0ffe500e089389e54bb730ec Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 26 Jul 2012 04:33:17 +0200 Subject: mod_admin_adhoc, mod_admin_telnet, mod_bosh, mod_c2s, mod_component, mod_pep, mod_presence, mod_roster, mod_s2s: Import core_post_stanza from the global prosody table. --- plugins/mod_admin_adhoc.lua | 1 + plugins/mod_admin_telnet.lua | 1 + plugins/mod_bosh.lua | 2 +- plugins/mod_c2s.lua | 1 + plugins/mod_component.lua | 4 ++-- plugins/mod_pep.lua | 1 + plugins/mod_presence.lua | 1 + plugins/mod_roster.lua | 2 +- plugins/mod_s2s/mod_s2s.lua | 2 +- 9 files changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/mod_admin_adhoc.lua b/plugins/mod_admin_adhoc.lua index 016eeb4a..50493abe 100644 --- a/plugins/mod_admin_adhoc.lua +++ b/plugins/mod_admin_adhoc.lua @@ -23,6 +23,7 @@ local timer_add_task = require "util.timer".add_task; local dataforms_new = require "util.dataforms".new; local array = require "util.array"; local modulemanager = require "modulemanager"; +local core_post_stanza = prosody.core_post_stanza; module:depends("adhoc"); local adhoc_new = module:require "adhoc".new; diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index 7b176d73..ca37ca7a 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -25,6 +25,7 @@ local cert_verify_identity = require "util.x509".verify_identity; local commands = module:shared("commands") local def_env = module:shared("env"); local default_env_mt = { __index = def_env }; +local core_post_stanza = prosody.core_post_stanza; local function redirect_output(_G, session) local env = setmetatable({ print = session.print }, { __index = function (t, k) return rawget(_G, k); end }); diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua index 2ac6b4ed..f6e3095e 100644 --- a/plugins/mod_bosh.lua +++ b/plugins/mod_bosh.lua @@ -14,7 +14,7 @@ local sm = require "core.sessionmanager"; local sm_destroy_session = sm.destroy_session; local new_uuid = require "util.uuid".generate; local fire_event = prosody.events.fire_event; -local core_process_stanza = core_process_stanza; +local core_process_stanza = prosody.core_process_stanza; local st = require "util.stanza"; local logger = require "util.logger"; local log = logger.init("mod_bosh"); diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index 1f62b4d4..2318ecad 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -28,6 +28,7 @@ local stream_close_timeout = module:get_option_number("c2s_close_timeout", 5); local opt_keepalives = module:get_option_boolean("tcp_keepalives", false); local sessions = module:shared("sessions"); +local core_process_stanza = prosody.core_process_stanza; local stream_callbacks = { default_ns = "jabber:client", handlestanza = core_process_stanza }; local listener = {}; diff --git a/plugins/mod_component.lua b/plugins/mod_component.lua index 4037ad28..751de59b 100644 --- a/plugins/mod_component.lua +++ b/plugins/mod_component.lua @@ -18,6 +18,8 @@ local jid_split = require "util.jid".split; local new_xmpp_stream = require "util.xmppstream".new; local uuid_gen = require "util.uuid".generate; +local core_process_stanza = prosody.core_process_stanza; + local log = module._log; @@ -169,8 +171,6 @@ function stream_callbacks.streamclosed(session) session:close(); end -local core_process_stanza = core_process_stanza; - function stream_callbacks.handlestanza(session, stanza) -- Namespaces are icky. if not stanza.attr.xmlns and stanza.name == "handshake" then diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua index d6fe9a81..c2261e5f 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -17,6 +17,7 @@ local pairs, ipairs = pairs, ipairs; local next = next; local type = type; local calculate_hash = require "util.caps".calculate_hash; +local core_post_stanza = prosody.core_post_stanza; local NULL = {}; local data = {}; diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 3cac0973..dac86ae6 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -14,6 +14,7 @@ local t_concat, t_insert = table.concat, table.insert; local s_find = string.find; local tonumber = tonumber; +local core_post_stanza = prosody.core_post_stanza; local st = require "util.stanza"; local jid_split = require "util.jid".split; local jid_bare = require "util.jid".bare; diff --git a/plugins/mod_roster.lua b/plugins/mod_roster.lua index 96cc15f2..bfb2d927 100644 --- a/plugins/mod_roster.lua +++ b/plugins/mod_roster.lua @@ -18,7 +18,7 @@ local pairs, ipairs = pairs, ipairs; local rm_remove_from_roster = require "core.rostermanager".remove_from_roster; local rm_add_to_roster = require "core.rostermanager".add_to_roster; local rm_roster_push = require "core.rostermanager".roster_push; -local core_post_stanza = core_post_stanza; +local core_post_stanza = prosody.core_post_stanza; module:add_feature("jabber:iq:roster"); diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua index 9f65f346..321ed0d7 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -10,7 +10,7 @@ module:set_global(); local prosody = prosody; local hosts = prosody.hosts; -local core_process_stanza = core_process_stanza; +local core_process_stanza = prosody.core_process_stanza; local tostring, type = tostring, type; local t_insert = table.insert; -- cgit v1.2.3 From df70fc25088c763d2878f796f9628415db79e8c6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 26 Jul 2012 04:35:13 +0200 Subject: mod_announce, mod_motd, mod_pubsub, mod_register, mod_watchregistrations, mod_welcome: Use module:send() instead of core_*_stanza() --- plugins/mod_announce.lua | 2 +- plugins/mod_motd.lua | 2 +- plugins/mod_pubsub.lua | 2 +- plugins/mod_register.lua | 4 ++-- plugins/mod_watchregistrations.lua | 2 +- plugins/mod_welcome.lua | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/mod_announce.lua b/plugins/mod_announce.lua index 99fbae50..0cfd284c 100644 --- a/plugins/mod_announce.lua +++ b/plugins/mod_announce.lua @@ -25,7 +25,7 @@ function send_to_online(message, host) for username in pairs(host_session.sessions) do c = c + 1; message.attr.to = username.."@"..hostname; - core_post_stanza(host_session, message); + module:send(message); end end end diff --git a/plugins/mod_motd.lua b/plugins/mod_motd.lua index 39b74de9..ddde9c78 100644 --- a/plugins/mod_motd.lua +++ b/plugins/mod_motd.lua @@ -24,7 +24,7 @@ module:hook("presence/bare", function (event) local motd_stanza = st.message({ to = session.full_jid, from = motd_jid }) :tag("body"):text(motd_text); - core_route_stanza(hosts[host], motd_stanza); + module:send(motd_stanza); module:log("debug", "MOTD send to user %s", session.full_jid); end end, 1); diff --git a/plugins/mod_pubsub.lua b/plugins/mod_pubsub.lua index 2cbd7184..40b119cc 100644 --- a/plugins/mod_pubsub.lua +++ b/plugins/mod_pubsub.lua @@ -201,7 +201,7 @@ function simple_broadcast(node, jids, item) for jid in pairs(jids) do module:log("debug", "Sending notification to %s", jid); message.attr.to = jid; - core_post_stanza(hosts[module.host], message); + module:send(message); end end diff --git a/plugins/mod_register.lua b/plugins/mod_register.lua index 755b718e..6c690c3b 100644 --- a/plugins/mod_register.lua +++ b/plugins/mod_register.lua @@ -120,10 +120,10 @@ local function handle_registration_stanza(event) for jid, item in pairs(roster) do if jid and jid ~= "pending" then if item.subscription == "both" or item.subscription == "from" or (roster.pending and roster.pending[jid]) then - core_post_stanza(hosts[host], st.presence({type="unsubscribed", from=bare, to=jid})); + module:send(st.presence({type="unsubscribed", from=bare, to=jid})); end if item.subscription == "both" or item.subscription == "to" or item.ask then - core_post_stanza(hosts[host], st.presence({type="unsubscribe", from=bare, to=jid})); + module:send(st.presence({type="unsubscribe", from=bare, to=jid})); end end end diff --git a/plugins/mod_watchregistrations.lua b/plugins/mod_watchregistrations.lua index ef18d713..abca90bd 100644 --- a/plugins/mod_watchregistrations.lua +++ b/plugins/mod_watchregistrations.lua @@ -25,6 +25,6 @@ module:hook("user-registered", function (user) for jid in registration_watchers do module:log("debug", "Notifying %s", jid); message.attr.to = jid; - core_route_stanza(hosts[host], message); + module:send(message); end end); diff --git a/plugins/mod_welcome.lua b/plugins/mod_welcome.lua index 8f9cca2a..e498f0b3 100644 --- a/plugins/mod_welcome.lua +++ b/plugins/mod_welcome.lua @@ -16,6 +16,6 @@ module:hook("user-registered", local welcome_stanza = st.message({ to = user.username.."@"..user.host, from = host }) :tag("body"):text(welcome_text:gsub("$(%w+)", user)); - core_route_stanza(hosts[host], welcome_stanza); + module:send(welcome_stanza); module:log("debug", "Welcomed user %s@%s", user.username, user.host); end); -- cgit v1.2.3 From a3f9da1b44df0cfb56699d30497a85c3d4a8aa8f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 26 Jul 2012 04:41:56 +0200 Subject: mod_muc: Use module:send() instead of core_*_stanza() --- plugins/muc/mod_muc.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua index 77ad2647..eb4129d3 100644 --- a/plugins/muc/mod_muc.lua +++ b/plugins/muc/mod_muc.lua @@ -42,7 +42,7 @@ local function is_admin(jid) return um_is_admin(jid, module.host); end -local function room_route_stanza(room, stanza) core_post_stanza(component, stanza); end +local function room_route_stanza(room, stanza) module:send(stanza); end local function room_save(room, forced) local node = jid_split(room.jid); persistent_rooms[room.jid] = room._data.persistent; @@ -168,7 +168,7 @@ module:hook("presence/host", handle_to_domain, -1); hosts[module.host].send = function(stanza) -- FIXME do a generic fix if stanza.attr.type == "result" or stanza.attr.type == "error" then - core_post_stanza(component, stanza); + module:send(stanza); else error("component.send only supports result and error stanzas at the moment"); end end -- cgit v1.2.3 From 3436718fab8e0d94b5e308c8400a42bf7fdbfda2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 26 Jul 2012 04:45:22 +0200 Subject: mod_muc: Remove unused variable and pull hosts into a local --- plugins/muc/mod_muc.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/muc/mod_muc.lua b/plugins/muc/mod_muc.lua index eb4129d3..0fa172ee 100644 --- a/plugins/muc/mod_muc.lua +++ b/plugins/muc/mod_muc.lua @@ -29,11 +29,11 @@ local st = require "util.stanza"; local uuid_gen = require "util.uuid".generate; local datamanager = require "util.datamanager"; local um_is_admin = require "core.usermanager".is_admin; +local hosts = hosts; rooms = {}; local rooms = rooms; local persistent_rooms = datamanager.load(nil, muc_host, "persistent") or {}; -local component = hosts[module.host]; -- Configurable options local max_history_messages = module:get_option_number("max_history_messages"); @@ -172,7 +172,7 @@ hosts[module.host].send = function(stanza) -- FIXME do a generic fix else error("component.send only supports result and error stanzas at the moment"); end end -prosody.hosts[module:get_host()].muc = { rooms = rooms }; +hosts[module:get_host()].muc = { rooms = rooms }; module.save = function() return {rooms = rooms}; @@ -188,5 +188,5 @@ module.restore = function(data) room.save = room_save; rooms[jid] = room; end - prosody.hosts[module:get_host()].muc = { rooms = rooms }; + hosts[module:get_host()].muc = { rooms = rooms }; end -- cgit v1.2.3 From 37dbbe422ea6e22d04819a6e3fdc55e73a16f38b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 26 Jul 2012 15:16:52 +0100 Subject: mod_vcard: Remove vcard_compatibility COMPAT (moved to mod_compat_vcard in prosody-modules), and add warning for those using the option --- plugins/mod_vcard.lua | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/plugins/mod_vcard.lua b/plugins/mod_vcard.lua index e2f1dfb8..d3c27cc0 100644 --- a/plugins/mod_vcard.lua +++ b/plugins/mod_vcard.lua @@ -46,13 +46,8 @@ end module:hook("iq/bare/vcard-temp:vCard", handle_vcard); module:hook("iq/host/vcard-temp:vCard", handle_vcard); --- COMPAT: https://support.process-one.net/browse/EJAB-1045 -if module:get_option("vcard_compatibility") then - module:hook("iq/full", function(data) - local stanza = data.stanza; - local payload = stanza.tags[1]; - if stanza.attr.type == "get" and payload.name == "vCard" and payload.attr.xmlns == "vcard-temp" then - return handle_vcard(data); - end - end, 1); +-- COMPAT w/0.8 +if module:get_option("vcard_compatibility") ~= nil then + module:log("error", "The vcard_compatibility option has been removed, see".. + "mod_compat_vcard in prosody-modules if you still need this."); end -- cgit v1.2.3 From 28dfdedc653bd2977eb60e84e2f582e07eb37708 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 26 Jul 2012 16:46:18 +0100 Subject: net.server_event: Replace usage of string.len() with # operator --- net/server_event.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/server_event.lua b/net/server_event.lua index 264d50a7..f2626f5f 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -115,7 +115,6 @@ do local addevent = base.addevent local coroutine_wrap, coroutine_yield = coroutine.wrap,coroutine.yield - local string_len = string.len -- Private methods function interface_mt:_position(new_position) @@ -310,7 +309,7 @@ do if self.nowriting then return nil, "locked" end --vdebug( "try to send data to client, id/data:", self.id, data ) data = tostring( data ) - local len = string_len( data ) + local len = #data local total = len + self.writebufferlen if total > cfg.MAX_SEND_LENGTH then -- check buffer length local err = "send buffer exceeded" -- cgit v1.2.3 From 47619af14cd24fcb48b4d2b4c4653f72b882087e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 27 Jul 2012 20:29:32 +0100 Subject: mod_dialback: Ignore with a 'type' attribute on incoming connections, instead of interpreting them as a request to verify a key --- plugins/mod_dialback.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/mod_dialback.lua b/plugins/mod_dialback.lua index 73a799e9..69616a57 100644 --- a/plugins/mod_dialback.lua +++ b/plugins/mod_dialback.lua @@ -41,6 +41,11 @@ module:hook("stanza/jabber:server:dialback:verify", function(event) -- We are being asked to verify the key, to ensure it was generated by us origin.log("debug", "verifying that dialback key is ours..."); local attr = stanza.attr; + if attr.type then + module:log("warn", "Ignoring incoming session from %s claiming a dialback key for %s is %s", + origin.from_host or "(unknown)", attr.from or "(unknown)", attr.type); + return true; + end -- COMPAT: Grr, ejabberd breaks this one too?? it is black and white in XEP-220 example 34 --if attr.from ~= origin.to_host then error("invalid-from"); end local type; -- cgit v1.2.3