From 250115f5420471c3fedbaff9cd6ed5b4399712f7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 13 May 2015 21:43:05 +0200 Subject: mod_s2s/s2sout: Remove now unused config option dns_max_depth --- plugins/mod_s2s/s2sout.lib.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/mod_s2s/s2sout.lib.lua b/plugins/mod_s2s/s2sout.lib.lua index 67b8fd0f..dc122af7 100644 --- a/plugins/mod_s2s/s2sout.lib.lua +++ b/plugins/mod_s2s/s2sout.lib.lua @@ -29,7 +29,6 @@ local has_ipv4, has_ipv6; local dns_timeout = module:get_option_number("dns_timeout", 15); dns.settimeout(dns_timeout); -local max_dns_depth = module:get_option_number("dns_max_depth", 3); local s2sout = {}; -- cgit v1.2.3 From 3c56b42545955de55ff55ea6d93484c139223038 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 13 May 2015 21:44:13 +0200 Subject: util.datamanager: Fix traceback from trying to purge when storage is empty or otherwise unaccessible (fixes #496) --- util/datamanager.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/util/datamanager.lua b/util/datamanager.lua index b4138638..a107d95c 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -348,8 +348,12 @@ end function purge(username, host) local host_dir = format("%s/%s/", data_path, encode(host)); + local ok, iter, state, var = pcall(lfs.dir, host_dir); + if not ok then + return ok, iter; + end local errs = {}; - for file in lfs.dir(host_dir) do + for file in iter, state, var do if lfs.attributes(host_dir..file, "mode") == "directory" then local store = decode(file); local ok, err = do_remove(getpath(username, host, store)); -- cgit v1.2.3 From 8057766c7f6bdfd7629203f6247a6f681ee00529 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 13 May 2015 21:47:39 +0200 Subject: mod_s2s/s2sout: Use the local address assigned to UDP sockets instead of util.net to enumerate possible source addresses --- plugins/mod_s2s/s2sout.lib.lua | 46 ++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/plugins/mod_s2s/s2sout.lib.lua b/plugins/mod_s2s/s2sout.lib.lua index dc122af7..5728f67b 100644 --- a/plugins/mod_s2s/s2sout.lib.lua +++ b/plugins/mod_s2s/s2sout.lib.lua @@ -18,13 +18,31 @@ local socket = require "socket"; local adns = require "net.adns"; local dns = require "net.dns"; local t_insert, t_sort, ipairs = table.insert, table.sort, ipairs; -local local_addresses = require "util.net".local_addresses; local s2s_destroy_session = require "core.s2smanager".destroy_session; local log = module._log; -local sources = {}; +local anysource = { IPv4 = "0.0.0.0", IPv6 = "::" }; +local function get_sources(addrs) + local sources = {}; + for _, IP in ipairs(addrs) do + local sock; + if IP.proto == "IPv4" then + sock = socket.udp(); + elseif IP.proto == "IPv6" then + sock = socket.udp6(); + end + sock:setpeername(IP.addr, 9); + local localaddr = sock:getsockname() or anysource[IP.proto]; + sock:close(); + if not sources[localaddr] then + sources[localaddr] = true; + t_insert(sources, new_ip(localaddr, IP.proto)); + end + end + return sources; +end local has_ipv4, has_ipv6; local dns_timeout = module:get_option_number("dns_timeout", 15); @@ -177,7 +195,7 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err) if have_other_result then if #IPs > 0 then - rfc6724_dest(host_session.ip_hosts, sources); + rfc6724_dest(host_session.ip_hosts, get_sources(host_session.ip_hosts)); for i = 1, #IPs do IPs[i] = {ip = IPs[i], port = connect_port}; end @@ -213,7 +231,7 @@ function s2sout.try_connect(host_session, connect_host, connect_port, err) if have_other_result then if #IPs > 0 then - rfc6724_dest(host_session.ip_hosts, sources); + rfc6724_dest(host_session.ip_hosts, get_sources(host_session.ip_hosts)); for i = 1, #IPs do IPs[i] = {ip = IPs[i], port = connect_port}; end @@ -315,28 +333,12 @@ module:hook_global("service-added", function (event) return; end for source, _ in pairs(s2s_sources) do - if source == "*" or source == "0.0.0.0" then - for _, addr in ipairs(local_addresses("ipv4", true)) do - sources[#sources + 1] = new_ip(addr, "IPv4"); - end - elseif source == "::" then - for _, addr in ipairs(local_addresses("ipv6", true)) do - sources[#sources + 1] = new_ip(addr, "IPv6"); - end - else - sources[#sources + 1] = new_ip(source, (source:find(":") and "IPv6") or "IPv4"); - end - end - for i = 1,#sources do - if sources[i].proto == "IPv6" then + if source:find(":") then has_ipv6 = true; - elseif sources[i].proto == "IPv4" then + else has_ipv4 = true; end end - if not (has_ipv4 or has_ipv6) then - module:log("warn", "No local IPv4 or IPv6 addresses detected, outgoing connections may fail"); - end end); return s2sout; -- cgit v1.2.3 From edfc34c0fbe5e369d7d2b2ca97c089e18847d139 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 13 May 2015 21:55:08 +0200 Subject: mod_s2s: Don't cache session.sends2s (or do it later), prevents sending data after session was closed --- plugins/mod_s2s/mod_s2s.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua index f5297efe..1408fd5e 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -147,7 +147,7 @@ end -- Stream is authorised, and ready for normal stanzas function mark_connected(session) - local sendq, send = session.sendq, session.sends2s; + local sendq = session.sendq; local from, to = session.from_host, session.to_host; @@ -170,6 +170,7 @@ function mark_connected(session) if session.direction == "outgoing" then if sendq then session.log("debug", "sending %d queued stanzas across new outgoing connection to %s", #sendq, session.to_host); + local send = session.sends2s; for i, data in ipairs(sendq) do send(data[1]); sendq[i] = nil; @@ -269,8 +270,6 @@ local stream_callbacks = { default_ns = "jabber:server", handlestanza = core_pr local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; function stream_callbacks.streamopened(session, attr) - local send = session.sends2s; - session.version = tonumber(attr.version) or 0; -- TODO: Rename session.secure to session.encrypted @@ -360,7 +359,7 @@ function stream_callbacks.streamopened(session, attr) end log("debug", "Sending stream features: %s", tostring(features)); - send(features); + session.sends2s(features); end session.notopen = nil; elseif session.direction == "outgoing" then -- cgit v1.2.3 From bbdd807af4b5bb1a5cf78accefa26f7f36e4668f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 13 May 2015 21:56:22 +0200 Subject: mod_s2s: Mark stream as opened directly after opening stream, prevents session.close opening it again --- 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 1408fd5e..ee539a2a 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -349,6 +349,7 @@ function stream_callbacks.streamopened(session, attr) end session:open_stream(session.to_host, session.from_host) + session.notopen = nil; if session.version >= 1.0 then local features = st.stanza("stream:features"); @@ -361,7 +362,6 @@ function stream_callbacks.streamopened(session, attr) log("debug", "Sending stream features: %s", tostring(features)); session.sends2s(features); end - session.notopen = nil; elseif session.direction == "outgoing" then session.notopen = nil; if not attr.id then -- cgit v1.2.3