From b000a228e716826efd73cef77aba68760ad814d1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 21 Jan 2016 22:21:19 +0100 Subject: Backout 63f5870f9afe, no longer needed since Windows is currently unsupported --- plugins/mod_s2s/s2sout.lib.lua | 46 ++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/plugins/mod_s2s/s2sout.lib.lua b/plugins/mod_s2s/s2sout.lib.lua index 5728f67b..dc122af7 100644 --- a/plugins/mod_s2s/s2sout.lib.lua +++ b/plugins/mod_s2s/s2sout.lib.lua @@ -18,31 +18,13 @@ 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 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 sources = {}; local has_ipv4, has_ipv6; local dns_timeout = module:get_option_number("dns_timeout", 15); @@ -195,7 +177,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, get_sources(host_session.ip_hosts)); + rfc6724_dest(host_session.ip_hosts, sources); for i = 1, #IPs do IPs[i] = {ip = IPs[i], port = connect_port}; end @@ -231,7 +213,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, get_sources(host_session.ip_hosts)); + rfc6724_dest(host_session.ip_hosts, sources); for i = 1, #IPs do IPs[i] = {ip = IPs[i], port = connect_port}; end @@ -333,12 +315,28 @@ module:hook_global("service-added", function (event) return; end for source, _ in pairs(s2s_sources) do - if source:find(":") then - has_ipv6 = true; + 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 + has_ipv6 = true; + elseif sources[i].proto == "IPv4" then 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 a680ad3d2cbed18a0742681cba92dbdefea40abb Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 21 Jan 2016 22:26:46 +0100 Subject: net.dns: Remember query only after it was sent, in case it was not (fixes #598) --- net/dns.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/dns.lua b/net/dns.lua index f56157d0..d123731c 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -763,16 +763,16 @@ function resolver:query(qname, qtype, qclass) -- - - - - - - - - - -- query self.active[id] = self.active[id] or {}; self.active[id][question] = o; - -- remember which coroutine wants the answer - if co then - set(self.wanted, qclass, qtype, qname, co, true); - end - local conn, err = self:getsocket(o.server) if not conn then return nil, err; end conn:send (o.packet) + + -- remember which coroutine wants the answer + if co then + set(self.wanted, qclass, qtype, qname, co, true); + end if timer and self.timeout then local num_servers = #self.server; -- cgit v1.2.3 From 11714f287aa64f316519c85a941ef6c1c38a29d1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 22 Jan 2016 01:58:39 +0100 Subject: server_select: Keep track of which server listeners are full --- net/server_select.lua | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/server_select.lua b/net/server_select.lua index 7ac41523..0a060c9e 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -88,6 +88,7 @@ local _socketlist local _closelist local _readtimes local _writetimes +local _fullservers --// simple data types //-- @@ -130,6 +131,7 @@ _socketlist = { } -- key = socket, value = wrapped socket (handlers) _readtimes = { } -- key = handler, value = timestamp of last data reading _writetimes = { } -- key = handler, value = timestamp of last data writing/sending _closelist = { } -- handlers to close +_fullservers = { } -- servers in a paused state while there are too many clients _readlistlen = 0 -- length of readlist _sendlistlen = 0 -- length of sendlist @@ -219,6 +221,7 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx ) -- t end _readlistlen = addsocket(_readlist, socket, _readlistlen) _socketlist[ socket ] = handler + _fullservers[ handler ] = nil handler.paused = false; end end @@ -234,6 +237,7 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx ) -- t handler.readbuffer = function( ) if _readlistlen >= _maxselectlen or _sendlistlen >= _maxselectlen then handler.pause( ) + _fullservers[ handler ] = _currenttime out_put( "server.lua: refused new client connection: server full" ) return false end @@ -264,6 +268,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport out_error("server.lua: Disallowed FD number: "..socket:getfd()) -- PROTIP: Switch to libevent socket:close( ) -- Should we send some kind of error here? if server then + _fullservers[ server ] = _currenttime server.pause( ) end return nil, nil, "fd-too-large" -- cgit v1.2.3 From a7208387b48464b37195d8b9bb500da64b9039d7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 22 Jan 2016 01:59:25 +0100 Subject: server_select: Retry accepting clients from full servers after 10s (matches libevent behaviour) --- net/server.lua | 2 +- net/server_select.lua | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/net/server.lua b/net/server.lua index 375e7081..9b0d27e1 100644 --- a/net/server.lua +++ b/net/server.lua @@ -50,7 +50,7 @@ if prosody then local settings = config_get("*", "network_settings") or {}; if use_luaevent then local event_settings = { - ACCEPT_DELAY = settings.event_accept_retry_interval; + ACCEPT_DELAY = settings.accept_retry_interval; ACCEPT_QUEUE = settings.tcp_backlog; CLEAR_DELAY = settings.event_clear_interval; CONNECT_TIMEOUT = settings.connect_timeout; diff --git a/net/server_select.lua b/net/server_select.lua index 0a060c9e..f9d8dba1 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -103,6 +103,7 @@ local _readtraffic local _selecttimeout local _sleeptime local _tcpbacklog +local _accepretry local _starttime local _currenttime @@ -143,6 +144,7 @@ _readtraffic = 0 _selecttimeout = 1 -- timeout of socket.select _sleeptime = 0 -- time to wait at the end of every loop _tcpbacklog = 128 -- some kind of hint to the OS +_accepretry = 10 -- seconds to wait until the next attempt of a full server to accept _maxsendlen = 51000 * 1024 -- max len of send buffer _maxreadlen = 25000 * 1024 -- max len of read buffer @@ -798,6 +800,7 @@ getsettings = function( ) max_connections = _maxselectlen; max_ssl_handshake_roundtrips = _maxsslhandshake; highest_allowed_fd = _maxfd; + accept_retry_interval = _accepretry; } end @@ -813,6 +816,7 @@ changesettings = function( new ) _tcpbacklog = tonumber( new.tcp_backlog ) or _tcpbacklog _sendtimeout = tonumber( new.send_timeout ) or _sendtimeout _readtimeout = tonumber( new.read_timeout ) or _readtimeout + _accepretry = tonumber( new.accept_retry_interval ) or _accepretry _maxselectlen = new.max_connections or _maxselectlen _maxsslhandshake = new.max_ssl_handshake_roundtrips or _maxsslhandshake _maxfd = new.highest_allowed_fd or _maxfd @@ -901,6 +905,13 @@ loop = function(once) -- this is the main loop of the program next_timer_time = next_timer_time - (_currenttime - _timer); end + for server, paused_time in pairs( _fullservers ) do + if _currenttime - paused_time > _accepretry then + _fullservers[ server ] = nil; + server.resume(); + end + end + -- wait some time (0 by default) socket_sleep( _sleeptime ) until quitting; -- cgit v1.2.3 From d4705117740775570de1cbd3506d00f170e6f07a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 22 Jan 2016 02:00:27 +0100 Subject: server_select: Pause and mark server as full if accepting a client fails (fixes #597) --- net/server_select.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/server_select.lua b/net/server_select.lua index f9d8dba1..891151ac 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -258,6 +258,8 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx ) -- t return; elseif err then -- maybe timeout or something else out_put( "server.lua: error with new client connection: ", tostring(err) ) + handler.pause( ) + _fullservers[ handler ] = _currenttime return false end end -- cgit v1.2.3 From 22f2bb941203a840620ee0807344e6df41139ec7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 22 Jan 2016 02:00:43 +0100 Subject: server_select: Add logging of when servers are paused and resumed --- net/server_select.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/server_select.lua b/net/server_select.lua index 891151ac..c50a6ce1 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -213,6 +213,7 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx ) -- t socket = nil; end handler.paused = true; + out_put("server.lua: server [", ip, "]:", serverport, " paused") end end handler.resume = function( ) @@ -225,6 +226,7 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx ) -- t _socketlist[ socket ] = handler _fullservers[ handler ] = nil handler.paused = false; + out_put("server.lua: server [", ip, "]:", serverport, " resumed") end end handler.ip = function( ) -- cgit v1.2.3 From a545fec355584bd7424cdf59cd3219cda68ebd6f Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 26 Jan 2016 00:28:07 +0100 Subject: mod_c2s, mod_s2s: Lower priority of session shutdown to negative, so that plugins hooking at the default priority run first (fixes #601) --- plugins/mod_c2s.lua | 2 +- plugins/mod_s2s/mod_s2s.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index 3d6487c9..8524c37e 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -275,7 +275,7 @@ module:hook("server-stopping", function(event) for _, session in pairs(sessions) do session:close{ condition = "system-shutdown", text = reason }; end -end, 1000); +end, -100); diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua index ee539a2a..4173fcfa 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -671,7 +671,7 @@ module:hook("server-stopping", function(event) for _, session in pairs(sessions) do session:close{ condition = "system-shutdown", text = reason }; end -end,500); +end, -200); -- cgit v1.2.3 -- cgit v1.2.3 From 989cb458a289427d0d8f92354329bbdbcc2f7c6d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 25 Feb 2016 22:36:42 +0100 Subject: util.datamanager: Unreference file handle after closing it to prevent trying to close it again (fixes #632) --- util/datamanager.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/util/datamanager.lua b/util/datamanager.lua index a107d95c..c69ecd25 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -152,6 +152,7 @@ local function atomic_store(filename, data) if not ok then break end ok, msg = f:close(); + f = nil; -- no longer valid if not ok then break end return os_rename(scratch, filename); -- cgit v1.2.3 From 38093fa822b28840d68b6490787f565884e5c89b Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 2 Mar 2016 16:28:11 +0100 Subject: mod_c2s: Remove connection object from session object when connection disconnected to prevent accidental use (see #590) --- plugins/mod_c2s.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index 8524c37e..30a017c0 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -258,6 +258,7 @@ function listener.ondisconnect(conn, err) if session then (session.log or log)("info", "Client disconnected: %s", err or "connection closed"); sm_destroy_session(session, err); + session.conn = nil; sessions[conn] = nil; end end -- cgit v1.2.3 From 125621ca3facf59328300396bacb7ff1546071ec Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 2 Mar 2016 16:30:05 +0100 Subject: net.server_event: Prevent resuming connections without readcallback, eg closed connections (fixes #590) --- net/server_event.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/server_event.lua b/net/server_event.lua index 45938a13..a60de08e 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -289,7 +289,7 @@ do function interface_mt:resume() self:_lock(self.nointerface, false, self.nowriting); - if not self.eventread then + if self.readcallback and not self.eventread then self.eventread = addevent( base, self.conn, EV_READ, self.readcallback, cfg.READ_TIMEOUT ); -- register callback end end -- cgit v1.2.3 From 4fce11a8a4ef357bf9f083e24e9ffef17df612e0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 2 Mar 2016 16:30:46 +0100 Subject: net.server_event: Return true from conn:resume() to indicate success --- net/server_event.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/net/server_event.lua b/net/server_event.lua index a60de08e..d505825d 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -291,6 +291,7 @@ do self:_lock(self.nointerface, false, self.nowriting); if self.readcallback and not self.eventread then self.eventread = addevent( base, self.conn, EV_READ, self.readcallback, cfg.READ_TIMEOUT ); -- register callback + return true; end end -- cgit v1.2.3 From e40c5fec6ed87bf4d93bee4434c8d056bb4a8338 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 3 Mar 2016 15:28:07 +0100 Subject: mod_http_files: Fix traceback when serving a non-wildcard path (fixes #611) --- plugins/mod_http_files.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/mod_http_files.lua b/plugins/mod_http_files.lua index 6275cca5..097f8346 100644 --- a/plugins/mod_http_files.lua +++ b/plugins/mod_http_files.lua @@ -56,6 +56,7 @@ end local urldecode = require "util.http".urldecode; function sanitize_path(path) + if not path then return end local out = {}; local c = 0; @@ -88,10 +89,11 @@ function serve(opts) local directory_index = opts.directory_index; local function serve_file(event, path) local request, response = event.request, event.response; - path = sanitize_path(path); - if not path then + local sanitized_path = sanitize_path(path); + if path and not sanitized_path then return 400; end + path = sanitized_path; local orig_path = sanitize_path(request.path); local full_path = base_path .. (path and "/"..path or ""):gsub("/", path_sep); local attr = stat(full_path:match("^.*[^\\/]")); -- Strip trailing path separator because Windows -- cgit v1.2.3 From c9377b5d882a038953fb68d9af703f1e853907bd Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 3 Mar 2016 15:30:00 +0100 Subject: mod_http_files: Don't prepend / to path twice, sanitize path does this already --- plugins/mod_http_files.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_http_files.lua b/plugins/mod_http_files.lua index 097f8346..fc39628c 100644 --- a/plugins/mod_http_files.lua +++ b/plugins/mod_http_files.lua @@ -95,7 +95,7 @@ function serve(opts) end path = sanitized_path; local orig_path = sanitize_path(request.path); - local full_path = base_path .. (path and "/"..path or ""):gsub("/", path_sep); + local full_path = base_path .. (path or ""):gsub("/", path_sep); local attr = stat(full_path:match("^.*[^\\/]")); -- Strip trailing path separator because Windows if not attr then return 404; -- cgit v1.2.3 From 16d0cbe6a706a0803a2ebe1f0bb43db76d1bacfd Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 3 Mar 2016 15:31:46 +0100 Subject: mod_http_files: Preserve a trailing / in paths (fixes #639) --- plugins/mod_http_files.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/mod_http_files.lua b/plugins/mod_http_files.lua index fc39628c..53b6469b 100644 --- a/plugins/mod_http_files.lua +++ b/plugins/mod_http_files.lua @@ -75,6 +75,9 @@ function sanitize_path(path) out[c] = component; end end + if path:sub(-1,-1) == "/" then + out[c+1] = ""; + end return "/"..table.concat(out, "/"); end -- cgit v1.2.3 From 71cd96efa7f28656fd61354755b30f9054c238ea Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 3 Apr 2016 15:18:21 +0200 Subject: mod_c2s: Just destroy the session when it has no connection (see #641) --- plugins/mod_c2s.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index 30a017c0..2bb919f8 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -175,6 +175,9 @@ local function session_close(session, reason) sm_destroy_session(session, reason); conn:close(); end + else + local reason = (reason and (reason.name or reason.text or reason.condition)) or reason; + sm_destroy_session(session, reason); end end -- cgit v1.2.3 From ca0980462ee3be9d8a5eee965ec9cd5d4dbf14f1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 19 Apr 2016 17:20:39 +0200 Subject: MUC: Accept missing form as "instant room" request (fixes #377) --- plugins/muc/muc.lib.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 5879c256..f8e8f74d 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -668,6 +668,14 @@ function room_mt:process_form(origin, stanza) if form.attr.type == "cancel" then origin.send(st.reply(stanza)); return; end if form.attr.type ~= "submit" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Not a submitted form")); return; end + if form.tags[1] == nil then + -- instant room + if self.save then self:save(true); end + origin.send(st.reply(stanza)); + return true; + end + + local fields = self:get_form_layout():data(form); if fields.FORM_TYPE ~= "http://jabber.org/protocol/muc#roomconfig" then origin.send(st.error_reply(stanza, "cancel", "bad-request", "Form is not of type room configuration")); return; end -- cgit v1.2.3 From 7b9a8755b70b1d1b594d367e0c29f776eb0b5063 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 19 Apr 2016 17:24:00 +0200 Subject: net.server_event: Re-add write event if writebuffer is non-empty after write (eg due to writes from ondrain callback) (fixes #661) --- net/server_event.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/server_event.lua b/net/server_event.lua index d505825d..1c6f1547 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -548,6 +548,10 @@ do elseif interface.eventreadtimeout then return EV_WRITE, EV_TIMEOUT end + if interface.writebuffer ~= 0 then + -- data possibly written from ondrain + return EV_WRITE, cfg.WRITE_TIMEOUT + end interface.eventwrite = nil return -1 elseif byte and (err == "timeout" or err == "wantwrite") then -- want write again -- cgit v1.2.3 From ef944ea3193770dd5ca7b0e0172c2757695ed591 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 19 Apr 2016 18:18:57 +0200 Subject: net.server_event: Fix traceback if event re-added during starttls --- net/server_event.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/net/server_event.lua b/net/server_event.lua index 1c6f1547..9da2e910 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -545,12 +545,11 @@ do elseif interface.startsslcallback then -- start ssl connection if needed debug "starting ssl handshake after writing" interface.eventstarthandshake = addevent( base, nil, EV_TIMEOUT, interface.startsslcallback, 0 ) - elseif interface.eventreadtimeout then - return EV_WRITE, EV_TIMEOUT - end - if interface.writebuffer ~= 0 then + elseif interface.writebuffer ~= 0 then -- data possibly written from ondrain return EV_WRITE, cfg.WRITE_TIMEOUT + elseif interface.eventreadtimeout then + return EV_WRITE, EV_TIMEOUT end interface.eventwrite = nil return -1 -- cgit v1.2.3 From d19a9467c241e7192a5c5ee36e6114d4fc6d6274 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 19 Apr 2016 18:20:39 +0200 Subject: net.server_event: Return the correct value as timeout --- net/server_event.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/server_event.lua b/net/server_event.lua index 9da2e910..59bd269a 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -549,7 +549,7 @@ do -- data possibly written from ondrain return EV_WRITE, cfg.WRITE_TIMEOUT elseif interface.eventreadtimeout then - return EV_WRITE, EV_TIMEOUT + return EV_WRITE, cfg.WRITE_TIMEOUT end interface.eventwrite = nil return -1 -- cgit v1.2.3 From 48f984ce06cdb3675bcf5f5c73143ce3f2e8014e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 19 Apr 2016 18:58:30 +0200 Subject: net.server_event: Check the buffer *length*, not the buffer itself (Fixes 100% cpu usage introduced in 65abd9d7bf88) --- net/server_event.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/server_event.lua b/net/server_event.lua index 59bd269a..882d10ed 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -545,7 +545,7 @@ do elseif interface.startsslcallback then -- start ssl connection if needed debug "starting ssl handshake after writing" interface.eventstarthandshake = addevent( base, nil, EV_TIMEOUT, interface.startsslcallback, 0 ) - elseif interface.writebuffer ~= 0 then + elseif interface.writebufferlen ~= 0 then -- data possibly written from ondrain return EV_WRITE, cfg.WRITE_TIMEOUT elseif interface.eventreadtimeout then -- cgit v1.2.3 From 582aaf597f775c1c3b66d9d6f0eb49d958401ce1 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 21 May 2016 19:10:03 +0200 Subject: mod_presence: Re-probe for contacts presence after outgoing 'subscribed' (fixes #673) --- plugins/mod_presence.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 8dac2d35..a5b4f282 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -201,6 +201,7 @@ function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_ end core_post_stanza(origin, stanza); send_presence_of_available_resources(node, host, to_bare, origin); + core_post_stanza(origin, st.presence({ type = "probe", from = from_bare, to = to_bare })); elseif stanza.attr.type == "unsubscribed" then -- 1. send unavailable -- 2. route stanza -- cgit v1.2.3 From 6f1da3f144819018421827c0eb72a2358cfb549e Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 22 Jun 2016 22:22:29 +0200 Subject: mod_privacy: Fix selecting the top resource (fixes #694) --- plugins/mod_privacy.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_privacy.lua b/plugins/mod_privacy.lua index 49c9427f..f95dfa50 100644 --- a/plugins/mod_privacy.lua +++ b/plugins/mod_privacy.lua @@ -397,7 +397,7 @@ function preCheckIncoming(e) local prio = 0; if bare_sessions[node.."@"..host] ~= nil then for resource, session_ in pairs(bare_sessions[node.."@"..host].sessions) do - if session_.priority ~= nil and session_.priority > prio then + if session_.priority ~= nil and session_.priority >= prio then session = session_; prio = session_.priority; end -- cgit v1.2.3 From fed3f5a0da97ae8f65fa9c04e7447e2b1b68601d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 21 Sep 2015 23:19:48 +0200 Subject: sessionmanager: Make session.send() return true unless there really is an error [backported from 0.10] --- core/sessionmanager.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 4b014d18..67ceb739 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -37,9 +37,15 @@ function new_session(conn) if t then t = filter("bytes/out", tostring(t)); if t then - return w(conn, t); + local ret, err = w(conn, t); + if not ret then + session.log("debug", "Write-error: %s", tostring(err)); + return false; + end + return true; end end + return true; end session.ip = conn:ip(); local conn_name = "c2s"..tostring(session):match("[a-f0-9]+$"); -- cgit v1.2.3 From 4ba2cd3ab0bdc660bff023acded8db1dfb467176 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 13 Aug 2016 20:19:08 +0200 Subject: net.http.parser: Buffer into a table to reduce GC pressure, collapse to string when needed (fixes #603) --- net/http/parser.lua | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/net/http/parser.lua b/net/http/parser.lua index 6d7187da..af43e7a0 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -1,5 +1,6 @@ local tonumber = tonumber; local assert = assert; +local t_insert, t_concat = table.insert, table.concat; local url_parse = require "socket.url".parse; local urldecode = require "util.http".urldecode; @@ -27,7 +28,7 @@ local httpstream = {}; function httpstream.new(success_cb, error_cb, parser_type, options_cb) local client = true; if not parser_type or parser_type == "server" then client = false; else assert(parser_type == "client", "Invalid parser type"); end - local buf = ""; + local buf, buflen, buftable = {}, 0, true; local chunked, chunk_size, chunk_start; local state = nil; local packet; @@ -38,6 +39,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) feed = function(self, data) if error then return nil, "parse has failed"; end if not data then -- EOF + if buftable then buf, buftable = t_concat(buf), false; end if state and client and not len then -- reading client body until EOF packet.body = buf; success_cb(packet); @@ -46,9 +48,16 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) end return; end - buf = buf..data; - while #buf > 0 do + if buftable then + t_insert(buf, data); + else + buf = { buf, data }; + buftable = true; + end + buflen = buflen + #data; + while buflen > 0 do if state == nil then -- read request + if buftable then buf, buftable = t_concat(buf), false; end local index = buf:find("\r\n\r\n", nil, true); if not index then return; end -- not enough data local method, path, httpversion, status_code, reason_phrase; @@ -115,11 +124,13 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) }; end buf = buf:sub(index + 4); + buflen = #buf; state = true; end if state then -- read body if client then if chunked then + if buftable then buf, buftable = t_concat(buf), false; end if not buf:find("\r\n", nil, true) then return; end -- not enough data @@ -132,25 +143,29 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) state, chunk_size = nil, nil; buf = buf:gsub("^.-\r\n\r\n", ""); -- This ensure extensions and trailers are stripped success_cb(packet); - elseif #buf - chunk_start - 2 >= chunk_size then -- we have a chunk + elseif buflen - chunk_start - 2 >= chunk_size then -- we have a chunk packet.body = packet.body..buf:sub(chunk_start, chunk_start + (chunk_size-1)); buf = buf:sub(chunk_start + chunk_size + 2); chunk_size, chunk_start = nil, nil; else -- Partial chunk remaining break; end - elseif len and #buf >= len then + elseif len and buflen >= len then + if buftable then buf, buftable = t_concat(buf), false; end if packet.code == 101 then - packet.body, buf = buf, ""; + packet.body, buf, buflen, buftable = buf, {}, 0, true; else packet.body, buf = buf:sub(1, len), buf:sub(len + 1); + buflen = #buf; end state = nil; success_cb(packet); else break; end - elseif #buf >= len then + elseif buflen >= len then + if buftable then buf, buftable = t_concat(buf), false; end packet.body, buf = buf:sub(1, len), buf:sub(len + 1); + buflen = #buf; state = nil; success_cb(packet); else break; -- cgit v1.2.3 From 12ae7ac17e07564c7fc2b3dee103724a26af4b71 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Aug 2016 14:47:58 +0200 Subject: net.http.parser: Add a limit on content length, default to 10M --- net/http/parser.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/http/parser.lua b/net/http/parser.lua index af43e7a0..0f764d12 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -29,6 +29,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) local client = true; if not parser_type or parser_type == "server" then client = false; else assert(parser_type == "client", "Invalid parser type"); end local buf, buflen, buftable = {}, 0, true; + local bodylimit = 10*1024*1024; local chunked, chunk_size, chunk_start; local state = nil; local packet; @@ -88,6 +89,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) if not first_line then error = true; return error_cb("invalid-status-line"); end chunked = have_body and headers["transfer-encoding"] == "chunked"; len = tonumber(headers["content-length"]); -- TODO check for invalid len + if len and len > bodylimit then error = true; return error_cb("content-length-limit-exceeded"); end if client then -- FIXME handle '100 Continue' response (by skipping it) if not have_body then len = 0; end -- cgit v1.2.3 From a3baf231f24a3ad76b4ad669c7856852f14a2c94 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Aug 2016 14:48:42 +0200 Subject: net.http.parser: Add a limit on maximum buffer size, default to 20M --- net/http/parser.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/http/parser.lua b/net/http/parser.lua index 0f764d12..e3a2554f 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -30,6 +30,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) if not parser_type or parser_type == "server" then client = false; else assert(parser_type == "client", "Invalid parser type"); end local buf, buflen, buftable = {}, 0, true; local bodylimit = 10*1024*1024; + local buflimit = bodylimit * 2; local chunked, chunk_size, chunk_start; local state = nil; local packet; @@ -56,6 +57,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) buftable = true; end buflen = buflen + #data; + if buflen > buflimit then error = true; return error_cb("max-buffer-size-exceeded"); end while buflen > 0 do if state == nil then -- read request if buftable then buf, buftable = t_concat(buf), false; end -- cgit v1.2.3 From aa01a982522b23782e20f613da995c42192f24e6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Aug 2016 14:50:06 +0200 Subject: net.http.parser: Allow limits to be configurable via options callback --- net/http/parser.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/http/parser.lua b/net/http/parser.lua index e3a2554f..1e698728 100644 --- a/net/http/parser.lua +++ b/net/http/parser.lua @@ -29,8 +29,8 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb) local client = true; if not parser_type or parser_type == "server" then client = false; else assert(parser_type == "client", "Invalid parser type"); end local buf, buflen, buftable = {}, 0, true; - local bodylimit = 10*1024*1024; - local buflimit = bodylimit * 2; + local bodylimit = tonumber(options_cb and options_cb().body_size_limit) or 10*1024*1024; + local buflimit = tonumber(options_cb and options_cb().buffer_size_limit) or bodylimit * 2; local chunked, chunk_size, chunk_start; local state = nil; local packet; -- cgit v1.2.3 From c7c1e0eca23d2a65dab01513b74b39754a8cd0c9 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Aug 2016 14:50:39 +0200 Subject: net.http.server: Expose way to set http server options --- net/http/server.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/http/server.lua b/net/http/server.lua index f091595c..32cda8aa 100644 --- a/net/http/server.lua +++ b/net/http/server.lua @@ -19,6 +19,7 @@ local sessions = {}; local listener = {}; local hosts = {}; local default_host; +local options = {}; local function is_wildcard_event(event) return event:sub(-2, -1) == "/*"; @@ -130,7 +131,10 @@ function listener.onconnect(conn) sessions[conn] = nil; conn:close(); end - sessions[conn] = parser_new(success_cb, error_cb); + local function options_cb() + return options; + end + sessions[conn] = parser_new(success_cb, error_cb, "server", options_cb); end function listener.ondisconnect(conn) @@ -300,6 +304,9 @@ end function _M.fire_event(event, ...) return events.fire_event(event, ...); end +function _M.set_option(name, value) + options[name] = value; +end _M.listener = listener; _M.codes = codes; -- cgit v1.2.3 From 85b4b476b6e58664681f1dcd7a06f50a2eca92cc Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 18 Aug 2016 14:51:11 +0200 Subject: mod_http: Allow configuring http parser size limits --- plugins/mod_http.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/mod_http.lua b/plugins/mod_http.lua index 9b574bc8..03b23480 100644 --- a/plugins/mod_http.lua +++ b/plugins/mod_http.lua @@ -18,6 +18,9 @@ local server = require "net.http.server"; server.set_default_host(module:get_option_string("http_default_host")); +server.set_option("body_size_limit", module:get_option_number("http_max_content_size")); +server.set_option("buffer_size_limit", module:get_option_number("http_max_buffer_size")); + local function normalize_path(path) if path:sub(-1,-1) == "/" then path = path:sub(1, -2); end if path:sub(1,1) ~= "/" then path = "/"..path; end -- cgit v1.2.3 From 0f936cae0cc9b295ace2ae4715a90a978eeccb63 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 23 Sep 2016 16:09:46 +0200 Subject: util.dependencies: Set global 'ssl' for compat with LuaSec 0.6 (fixes #749) --- util/dependencies.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/dependencies.lua b/util/dependencies.lua index 4d50cf63..9ea211dd 100644 --- a/util/dependencies.lua +++ b/util/dependencies.lua @@ -99,6 +99,9 @@ function check_dependencies() ["luarocks"] = "luarocks install luasec"; ["Source"] = "http://www.inf.puc-rio.br/~brunoos/luasec/"; }, "SSL/TLS support will not be available"); + elseif not _G.ssl then + _G.ssl = ssl; + _G.ssl.context = require "ssl.context"; end local encodings, err = softreq "util.encodings" -- cgit v1.2.3 From e6f146db20466412e73a378b92d099ca3993405e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 27 Sep 2016 22:01:13 +0100 Subject: prosodyctl: Fix copy/paste error in help text for deluser command --- prosodyctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prosodyctl b/prosodyctl index 4c3ae981..e736b13e 100755 --- a/prosodyctl +++ b/prosodyctl @@ -361,8 +361,8 @@ function commands.deluser(arg) end local user, host = jid_split(arg[1]); if not user and host then - show_message [[Failed to understand JID, please supply the JID you want to set the password for]] - show_usage [[passwd user@host]] + show_message [[Failed to understand JID, please supply the JID to the user account you want to delete]] + show_usage [[deluser user@host]] return 1; end -- cgit v1.2.3 From 49cdb79dd1b4f504c9e6540704c4802af7920c98 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 27 Sep 2016 22:01:46 +0100 Subject: mod_s2s: Lower log message to 'warn' level, standard for remotely-triggered protocol issues --- 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 4173fcfa..e038e5b4 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -365,7 +365,7 @@ function stream_callbacks.streamopened(session, attr) elseif session.direction == "outgoing" then session.notopen = nil; if not attr.id then - log("error", "Stream response did not give us a stream id!"); + log("warn", "Stream response did not give us a stream id!"); session:close({ condition = "undefined-condition", text = "Missing stream ID" }); return; end -- cgit v1.2.3 -- cgit v1.2.3 From 121866daca5641c7e86f4afe8ce6e09d262d6384 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 3 Nov 2016 23:51:40 +0100 Subject: certs/Makefile: Remove -c flag to chmod, which appears to be a GNUism ... again (thanks waqas) --- certs/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/certs/Makefile b/certs/Makefile index c709ff91..587fadc6 100644 --- a/certs/Makefile +++ b/certs/Makefile @@ -27,4 +27,4 @@ keysize=2048 %.key: umask 0077 && openssl genrsa -out $@ $(keysize) - @chmod 400 $@ -c + @chmod 400 $@ -- cgit v1.2.3 From 2069dab95ac5eba91b07f090840cc16797a39c78 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 22 Nov 2016 15:28:24 +0100 Subject: net.server_select: Prevent writes after a handler is closed (fixes #783 I hope) --- net/server_select.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/net/server_select.lua b/net/server_select.lua index c50a6ce1..39640a83 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -415,6 +415,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport end handler.port = handler.clientport -- COMPAT server_event local write = function( self, data ) + if not handler then return false end bufferlen = bufferlen + #data if bufferlen > maxsendlen then _closelist[ handler ] = "send buffer exceeded" -- cannot close the client at the moment, have to wait to the end of the cycle -- cgit v1.2.3 From c6070699a957f17ec40e80d8561c9c0edb42a5d4 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 28 Nov 2016 14:27:59 +0100 Subject: util.dependencies: Set ssl.x509 so core.certmanager knows that LuaSec is capable of certificate validation (fixes #781) --- util/dependencies.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/util/dependencies.lua b/util/dependencies.lua index 9ea211dd..491bfd9b 100644 --- a/util/dependencies.lua +++ b/util/dependencies.lua @@ -102,6 +102,7 @@ function check_dependencies() elseif not _G.ssl then _G.ssl = ssl; _G.ssl.context = require "ssl.context"; + _G.ssl.x509 = softreq "ssl.x509"; end local encodings, err = softreq "util.encodings" -- cgit v1.2.3 -- cgit v1.2.3 From beca15e592d73fe3a776eb0e0953d6ceb9ce52cb Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 9 Dec 2016 15:15:10 +0100 Subject: core.rostermanager: Add method for checking if the user is subscribed to a contact --- core/rostermanager.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/rostermanager.lua b/core/rostermanager.lua index 5e06e3f7..a846fea6 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -210,6 +210,18 @@ function is_contact_subscribed(username, host, jid) local item = roster[jid]; return item and (item.subscription == "from" or item.subscription == "both"), err; end +function is_user_subscribed(username, host, jid) + do + local selfjid = username.."@"..host; + local user_subscription = _get_online_roster_subscription(selfjid, jid); + if user_subscription then return (user_subscription == "both" or user_subscription == "to"); end + local contact_subscription = _get_online_roster_subscription(jid, selfjid); + if contact_subscription then return (contact_subscription == "both" or contact_subscription == "from"); end + end + local roster, err = load_roster(username, host); + local item = roster[jid]; + return item and (item.subscription == "to" or item.subscription == "both"), err; +end function is_contact_pending_in(username, host, jid) local roster = load_roster(username, host); -- cgit v1.2.3 From 03a0cd3a090cfedbe644f054bff3313d04af83f4 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 8 Dec 2016 20:49:35 +0100 Subject: mod_presence: Send probe once subscribed (fixes #794) --- plugins/mod_presence.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index a5b4f282..6df56fe0 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -201,7 +201,9 @@ function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_ end core_post_stanza(origin, stanza); send_presence_of_available_resources(node, host, to_bare, origin); - core_post_stanza(origin, st.presence({ type = "probe", from = from_bare, to = to_bare })); + if rostermanager.is_user_subscribed(node, host, to_bare) then + core_post_stanza(origin, st.presence({ type = "probe", from = from_bare, to = to_bare })); + end elseif stanza.attr.type == "unsubscribed" then -- 1. send unavailable -- 2. route stanza -- cgit v1.2.3 From aa30e3ed7e4d2edc0aa3a069fca895fe6fa568b2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 21 Dec 2016 11:02:17 +0100 Subject: mod_net_multiplex: Enable SSL on the SSL port (fixes #803) --- plugins/mod_net_multiplex.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_net_multiplex.lua b/plugins/mod_net_multiplex.lua index 0dd3dc67..a66ab31f 100644 --- a/plugins/mod_net_multiplex.lua +++ b/plugins/mod_net_multiplex.lua @@ -67,5 +67,6 @@ module:provides("net", { module:provides("net", { name = "multiplex_ssl"; config_prefix = "ssl"; + encryption = "ssl"; listener = listener; }); -- cgit v1.2.3 From dfed4cae0481ba2bbd5babc22e702e55181a85b7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 21 Feb 2017 18:54:44 +0100 Subject: mod_register: Require encryption before registration if c2s_require_encryption is set (fixes #595) --- plugins/mod_register.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/mod_register.lua b/plugins/mod_register.lua index 3d7a068c..63d0b077 100644 --- a/plugins/mod_register.lua +++ b/plugins/mod_register.lua @@ -20,6 +20,7 @@ local jid_bare = require "util.jid".bare; local compat = module:get_option_boolean("registration_compat", true); local allow_registration = module:get_option_boolean("allow_registration", false); local additional_fields = module:get_option("additional_registration_fields", {}); +local require_encryption = module:get_option("c2s_require_encryption") or module:get_option("require_encryption"); local account_details = module:open_store("account_details"); @@ -75,7 +76,7 @@ module:hook("stream-features", function(event) local session, features = event.origin, event.features; -- Advertise registration to unauthorized clients only. - if not(allow_registration) or session.type ~= "c2s_unauthed" then + if not(allow_registration) or session.type ~= "c2s_unauthed" or (require_encryption and not session.secure) then return end @@ -183,6 +184,8 @@ module:hook("stanza/iq/jabber:iq:register:query", function(event) if not(allow_registration) or session.type ~= "c2s_unauthed" then session.send(st.error_reply(stanza, "cancel", "service-unavailable")); + elseif require_encryption and not session.secure then + session.send(st.error_reply(stanza, "modify", "policy-violation", "Encryption is required")); else local query = stanza.tags[1]; if stanza.attr.type == "get" then -- cgit v1.2.3 From 77b7ae7fe3154ce4bad3db4b23ac656c3d5dfce0 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 2 Mar 2017 15:17:32 +0100 Subject: mod_saslauth: Log SASL failure reason --- plugins/mod_saslauth.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index c5d3dc91..d374633e 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -96,8 +96,19 @@ end) module:hook_stanza(xmlns_sasl, "failure", function (session, stanza) if session.type ~= "s2sout_unauthed" or session.external_auth ~= "attempting" then return; end - module:log("info", "SASL EXTERNAL with %s failed", session.to_host) - -- TODO: Log the failure reason + local text = stanza:get_child_text("text"); + local condition = "unknown-condition"; + for child in stanza:childtags() do + if child.name ~= "text" then + condition = child.name; + break; + end + end + if text and condition then + condition = connection .. ": " .. text; + end + module:log("info", "SASL EXTERNAL with %s failed: %s", session.to_host, condition); + session.external_auth = "failed" end, 500) -- cgit v1.2.3 From fcdbf0616d0c228cc524edb4c7422aeae6bc8789 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 24 Mar 2017 00:25:49 +0100 Subject: mod_disco: Correctly set the 'node' attr (fixes #449) --- 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 72c9a34c..b41f9651 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -99,7 +99,7 @@ module:hook("iq/host/http://jabber.org/protocol/disco#info:query", function(even local node = stanza.tags[1].attr.node; if node and node ~= "" and node ~= "http://prosody.im#"..get_server_caps_hash() then return; end -- TODO fire event? local reply_query = get_server_disco_info(); - reply_query.node = node; + reply_query.attr.node = node; local reply = st.reply(stanza):add_child(reply_query); origin.send(reply); return true; -- cgit v1.2.3 From 5126ff2f6c6f1e916408f616a2b3304ba4d967af Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 17 Apr 2017 21:40:06 +0200 Subject: mod_bosh: Update session.conn to point to the current connection (fixes #890) --- plugins/mod_bosh.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua index d9c8defd..1eb95e90 100644 --- a/plugins/mod_bosh.lua +++ b/plugins/mod_bosh.lua @@ -247,7 +247,7 @@ function stream_callbacks.streamopened(context, attr) -- New session sid = new_uuid(); local session = { - type = "c2s_unauthed", conn = {}, sid = sid, rid = tonumber(attr.rid)-1, host = attr.to, + type = "c2s_unauthed", conn = request.conn, sid = sid, rid = tonumber(attr.rid)-1, host = attr.to, bosh_version = attr.ver, bosh_wait = math_min(attr.wait, bosh_max_wait), streamid = sid, bosh_hold = BOSH_DEFAULT_HOLD, bosh_max_inactive = BOSH_DEFAULT_INACTIVITY, requests = { }, send_buffer = {}, reset_stream = bosh_reset_stream, @@ -316,6 +316,8 @@ function stream_callbacks.streamopened(context, attr) context.notopen = nil; return; end + + session.conn = request.conn; if session.rid then local rid = tonumber(attr.rid); -- cgit v1.2.3 From c1e87de11a3c5e9a4764146d1737bef76f20e399 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Mon, 22 May 2017 05:32:11 +0200 Subject: net.dns: Simplify expiry calculation (fixes #919) --- net/dns.lua | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/net/dns.lua b/net/dns.lua index d123731c..5e29e906 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -137,9 +137,7 @@ local function prune(rrs, time, soft) -- - - - - - - - - - - - - - - prune time = time or socket.gettime(); for i,rr in ipairs(rrs) do if rr.tod then - -- rr.tod = rr.tod - 50 -- accelerated decripitude - rr.ttl = math.floor(rr.tod - time); - if rr.ttl <= 0 then + if rr.tod < time then rrs[rr[rr.type:lower()]] = nil; table.remove(rrs, i); return prune(rrs, time, soft); -- Re-iterate @@ -515,11 +513,7 @@ function resolver:rr() -- - - - - - - - - - - - - - - - - - - - - - - - rr rr.ttl = 0x10000*self:word() + self:word(); rr.rdlength = self:word(); - if rr.ttl <= 0 then - rr.tod = self.time + 30; - else - rr.tod = self.time + rr.ttl; - end + rr.tod = self.time + rr.ttl; local remember = self.offset; local rr_parser = self[dns.type[rr.type]]; -- cgit v1.2.3 From f1025210d8f3843d49a593dadf6af2dbbb61af85 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 27 May 2017 14:23:43 +0100 Subject: mod_watchregistrations: Return the pointer to the root of the stanza, fixes #922. --- plugins/mod_watchregistrations.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/mod_watchregistrations.lua b/plugins/mod_watchregistrations.lua index abca90bd..0e9d2fca 100644 --- a/plugins/mod_watchregistrations.lua +++ b/plugins/mod_watchregistrations.lua @@ -21,7 +21,8 @@ module:hook("user-registered", function (user) :tag("body") :text(registration_notification:gsub("%$(%w+)", function (v) return user[v] or user.session and user.session[v] or nil; - end)); + end)) + :up(); for jid in registration_watchers do module:log("debug", "Notifying %s", jid); message.attr.to = jid; -- cgit v1.2.3 From f72cbc8a32f173df8b541ad83a8d3f1dbc12c7c2 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 27 May 2017 15:53:30 +0100 Subject: mod_disco: Add an account/registered identity on subscribed accounts, fixes #826. --- plugins/mod_disco.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index b41f9651..71a04a2d 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -138,6 +138,7 @@ module:hook("iq/bare/http://jabber.org/protocol/disco#info:query", function(even if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info'}); if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account + reply:tag('identity', {category='account', type='registered'}):up(); module:fire_event("account-disco-info", { origin = origin, stanza = reply }); origin.send(reply); return true; -- cgit v1.2.3 From 17b14b71b59bf9db3eb49364a34aa7e35f68857b Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 30 May 2017 20:52:22 +0100 Subject: mod_welcome: Return the pointer to the root of the stanza, fixes a bug similar to #922. --- plugins/mod_welcome.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mod_welcome.lua b/plugins/mod_welcome.lua index e498f0b3..c4ebaf30 100644 --- a/plugins/mod_welcome.lua +++ b/plugins/mod_welcome.lua @@ -14,8 +14,8 @@ local st = require "util.stanza"; module:hook("user-registered", function (user) local welcome_stanza = - st.message({ to = user.username.."@"..user.host, from = host }) - :tag("body"):text(welcome_text:gsub("$(%w+)", user)); + st.message({ to = user.username.."@"..user.host, from = host }, + welcome_text:gsub("$(%w+)", user)); module:send(welcome_stanza); module:log("debug", "Welcomed user %s@%s", user.username, user.host); end); -- cgit v1.2.3 From 6f1020550628c90495e29d33a8952850d0e0ce83 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 13 Jun 2017 16:36:47 +0200 Subject: net.dns: Prevent answers from immediately expiring even if TTL=0 (see #919) --- net/dns.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/dns.lua b/net/dns.lua index 5e29e906..0d6a828c 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -513,7 +513,7 @@ function resolver:rr() -- - - - - - - - - - - - - - - - - - - - - - - - rr rr.ttl = 0x10000*self:word() + self:word(); rr.rdlength = self:word(); - rr.tod = self.time + rr.ttl; + rr.tod = self.time + math.min(rr.ttl, 1); local remember = self.offset; local rr_parser = self[dns.type[rr.type]]; -- cgit v1.2.3 From 35dad9610a33d5e9d540c8f6c1f5dea0cbbfc232 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 8 Jul 2017 18:21:45 +0200 Subject: mod_saslauth: Use correct varible name (thanks Roi) --- plugins/mod_saslauth.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index d374633e..a23d1f53 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -105,7 +105,7 @@ module:hook_stanza(xmlns_sasl, "failure", function (session, stanza) end end if text and condition then - condition = connection .. ": " .. text; + condition = condition .. ": " .. text; end module:log("info", "SASL EXTERNAL with %s failed: %s", session.to_host, condition); -- cgit v1.2.3 From 03aa086d185d1d5323674eacedbef2f71d8c326d Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 25 Jul 2017 13:16:31 +0200 Subject: util.dependencies: Add compatibility code for LuaSocket no longer exporting as a global --- util/dependencies.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/dependencies.lua b/util/dependencies.lua index 491bfd9b..a259c263 100644 --- a/util/dependencies.lua +++ b/util/dependencies.lua @@ -79,6 +79,9 @@ function check_dependencies() ["Source"] = "http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/"; }); fatal = true; + elseif not _G.socket then + -- COMPAT Code expecting LuaSocket to export as a global + _G.socket = socket; end local lfs, err = softreq "lfs" -- cgit v1.2.3 From bc13033a0eef68eca6e213e4b1a3e43e2f4f1589 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 25 Jul 2017 13:25:49 +0200 Subject: util.dependencies: Add comment about LuaSec compat --- util/dependencies.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/util/dependencies.lua b/util/dependencies.lua index a259c263..7ec56022 100644 --- a/util/dependencies.lua +++ b/util/dependencies.lua @@ -103,6 +103,7 @@ function check_dependencies() ["Source"] = "http://www.inf.puc-rio.br/~brunoos/luasec/"; }, "SSL/TLS support will not be available"); elseif not _G.ssl then + -- COMPAT Code expecting LuaSec to export as a global (see #749) _G.ssl = ssl; _G.ssl.context = require "ssl.context"; _G.ssl.x509 = softreq "ssl.x509"; -- cgit v1.2.3 From 5e0e0d2723d721e3ffc6c1b8f35e8008e91d6786 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Wed, 13 Sep 2017 18:18:57 +0200 Subject: mod_c2s: Iterate over child tags instead of child nodes in stream error (fixes traceback from #987) --- plugins/mod_c2s.lua | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index 2bb919f8..fdb3b211 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -98,16 +98,14 @@ function stream_callbacks.error(session, error, data) session:close("not-well-formed"); elseif error == "stream-error" then local condition, text = "undefined-condition"; - for child in data:children() do - if child.attr.xmlns == xmlns_xmpp_streams then - if child.name ~= "text" then - condition = child.name; - else - text = child:get_text(); - end - if condition ~= "undefined-condition" and text then - break; - end + for child in data:childtags(nil, xmlns_xmpp_streams) do + if child.name ~= "text" then + condition = child.name; + else + text = child:get_text(); + end + if condition ~= "undefined-condition" and text then + break; end end text = condition .. (text and (" ("..text..")") or ""); -- cgit v1.2.3 From a5deab5ee0d2c40f082daa179e39167365d699ee Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 14 Sep 2017 01:27:36 +0200 Subject: mod_component, mod_s2s: Iterate over child tags instead of child nodes (can include text) in stream error (same as 176b7f4e4ac9) --- plugins/mod_component.lua | 18 ++++++++---------- plugins/mod_s2s/mod_s2s.lua | 18 ++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/plugins/mod_component.lua b/plugins/mod_component.lua index 11abab79..acd70c60 100644 --- a/plugins/mod_component.lua +++ b/plugins/mod_component.lua @@ -151,16 +151,14 @@ function stream_callbacks.error(session, error, data, data2) session:close("not-well-formed"); elseif error == "stream-error" then local condition, text = "undefined-condition"; - for child in data:children() do - if child.attr.xmlns == xmlns_xmpp_streams then - if child.name ~= "text" then - condition = child.name; - else - text = child:get_text(); - end - if condition ~= "undefined-condition" and text then - break; - end + for child in data:childtags(nil, xmlns_xmpp_streams) do + if child.name ~= "text" then + condition = child.name; + else + text = child:get_text(); + end + if condition ~= "undefined-condition" and text then + break; end end text = condition .. (text and (" ("..text..")") or ""); diff --git a/plugins/mod_s2s/mod_s2s.lua b/plugins/mod_s2s/mod_s2s.lua index e038e5b4..10b81a17 100644 --- a/plugins/mod_s2s/mod_s2s.lua +++ b/plugins/mod_s2s/mod_s2s.lua @@ -416,16 +416,14 @@ function stream_callbacks.error(session, error, data) session:close("not-well-formed"); elseif error == "stream-error" then local condition, text = "undefined-condition"; - for child in data:children() do - if child.attr.xmlns == xmlns_xmpp_streams then - if child.name ~= "text" then - condition = child.name; - else - text = child:get_text(); - end - if condition ~= "undefined-condition" and text then - break; - end + for child in data:childtags(nil, xmlns_xmpp_streams) do + if child.name ~= "text" then + condition = child.name; + else + text = child:get_text(); + end + if condition ~= "undefined-condition" and text then + break; end end text = condition .. (text and (" ("..text..")") or ""); -- cgit v1.2.3 From dcc5e0c432d1ab5f6d4ee39f685d3c8273139213 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 Dec 2017 14:39:48 +0100 Subject: MUC: Always send subject message, even if it is empty (fixes #1053) --- plugins/muc/muc.lib.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index f8e8f74d..4b299bde 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -207,9 +207,7 @@ function room_mt:send_history(to, stanza) self:_route_stanza(msg); end end - if self._data['subject'] then - self:_route_stanza(st.message({type='groupchat', from=self._data['subject_from'] or self.jid, to=to}):tag("subject"):text(self._data['subject'])); - end + self:_route_stanza(st.message({type='groupchat', from=self._data['subject_from'] or self.jid, to=to}):tag("subject"):text(self._data['subject'])); end function room_mt:get_disco_info(stanza) -- cgit v1.2.3 From 8a27e951273eea8f63ed776b09981aa97f67dcd2 Mon Sep 17 00:00:00 2001 From: Jonas Wielicki Date: Sat, 9 Dec 2017 17:36:47 +0100 Subject: MUC: fix the @from on in history replay (fixes #1054) --- 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 4b299bde..0dfdd1aa 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -135,8 +135,8 @@ function room_mt:broadcast_message(stanza, historic) stanza = st.clone(stanza); stanza.attr.to = ""; local stamp = datetime.datetime(); - stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = stamp}):up(); -- XEP-0203 - stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) + stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = self.jid, stamp = stamp}):up(); -- XEP-0203 + stanza:tag("x", {xmlns = "jabber:x:delay", from = self.jid, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) local entry = { stanza = stanza, stamp = stamp }; t_insert(history, entry); while #history > (self._data.history_length or default_history_length) do t_remove(history, 1) end -- cgit v1.2.3 From f0c009b655106b805d8f275e4d942051dddee961 Mon Sep 17 00:00:00 2001 From: Jonas Wielicki Date: Sat, 9 Dec 2017 17:57:14 +0100 Subject: MUC: Ensure that elements which match our from are stripped (fixes #1055) --- plugins/muc/muc.lib.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 0dfdd1aa..0040b99c 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -122,6 +122,22 @@ function room_mt:broadcast_presence(stanza, sid, code, nick) end function room_mt:broadcast_message(stanza, historic) local to = stanza.attr.to; + local muc_jid = self.jid; + + stanza:maptags(function (child) + if child.name == "delay" and child.attr["xmlns"] == "urn:xmpp:delay" then + if child.attr["from"] == muc_jid then + return nil; + end + end + if child.name == "x" and child.attr["xmlns"] == "jabber:x:delay" then + if child.attr["from"] == muc_jid then + return nil; + end + end + return child; + end) + for occupant, o_data in pairs(self._occupants) do for jid in pairs(o_data.sessions) do stanza.attr.to = jid; -- cgit v1.2.3 From 6359bbd99dfa298cbf6344ba5b15ecf0da275205 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 10 Dec 2017 17:52:47 +0100 Subject: MUC: Rename variable to make it clearer that it is the room JID and not the MUC host --- plugins/muc/muc.lib.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 0040b99c..e8d565f2 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -122,16 +122,16 @@ function room_mt:broadcast_presence(stanza, sid, code, nick) end function room_mt:broadcast_message(stanza, historic) local to = stanza.attr.to; - local muc_jid = self.jid; + local room_jid = self.jid; stanza:maptags(function (child) if child.name == "delay" and child.attr["xmlns"] == "urn:xmpp:delay" then - if child.attr["from"] == muc_jid then + if child.attr["from"] == room_jid then return nil; end end if child.name == "x" and child.attr["xmlns"] == "jabber:x:delay" then - if child.attr["from"] == muc_jid then + if child.attr["from"] == room_jid then return nil; end end -- cgit v1.2.3 -- cgit v1.2.3 From bd0478207739d4f7e6ea8db92d3d1b667187a7db Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Fri, 25 May 2018 21:09:34 +0200 Subject: mod_c2s: Do not allow the stream 'to' to change across stream restarts (fixes #1147) --- plugins/mod_c2s.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/mod_c2s.lua b/plugins/mod_c2s.lua index fdb3b211..2848f92f 100644 --- a/plugins/mod_c2s.lua +++ b/plugins/mod_c2s.lua @@ -40,12 +40,19 @@ local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/strea function stream_callbacks.streamopened(session, attr) local send = session.send; - session.host = nameprep(attr.to); - if not session.host then + local host = nameprep(attr.to); + if not host then session:close{ condition = "improper-addressing", text = "A valid 'to' attribute is required on stream headers" }; return; end + if not session.host then + session.host = host; + elseif session.host ~= host then + session:close{ condition = "not-authorized", + text = "The 'to' attribute must remain the same across stream restarts" }; + return; + end session.version = tonumber(attr.version) or 0; session.streamid = uuid_generate(); (session.log or session)("debug", "Client sent opening to %s", session.host); -- cgit v1.2.3 -- cgit v1.2.3