From 0a97fad81fe51b76a7c10c9ebc0f231424c82b73 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 21 Nov 2009 13:15:46 +0000 Subject: mod_bosh: Don't log response XML --- plugins/mod_bosh.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua index 3e41ef7b..5de79eff 100644 --- a/plugins/mod_bosh.lua +++ b/plugins/mod_bosh.lua @@ -152,7 +152,7 @@ function stream_callbacks.streamopened(request, attr) local r, send_buffer = session.requests, session.send_buffer; local response = { headers = default_headers } function session.send(s) - log("debug", "Sending BOSH data: %s", tostring(s)); + --log("debug", "Sending BOSH data: %s", tostring(s)); local oldest_request = r[1]; while oldest_request and oldest_request.destroyed do t_remove(r, 1); @@ -160,7 +160,7 @@ function stream_callbacks.streamopened(request, attr) oldest_request = r[1]; end if oldest_request then - log("debug", "We have an open request, so using that to send with"); + log("debug", "We have an open request, so sending on that"); response.body = t_concat{"", tostring(s), "" }; oldest_request:send(response); --log("debug", "Sent"); -- cgit v1.2.3 From 2e17a1667d8de25e281cf2d4a11b50234673ca79 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 23 Nov 2009 02:58:42 +0000 Subject: util.dependencies: Make the commands line up properly in the "missing dependency" output. Yes, this was the commit you didn't know you were waiting for! --- util/dependencies.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/util/dependencies.lua b/util/dependencies.lua index a0535e5c..cb022644 100644 --- a/util/dependencies.lua +++ b/util/dependencies.lua @@ -17,8 +17,12 @@ local function missingdep(name, sources, msg) print("Prosody was unable to find "..tostring(name)); print("This package can be obtained in the following ways:"); print(""); - for k,v in pairs(sources) do - print("", k, v); + local longest_platform = 0; + for platform in pairs(sources) do + longest_platform = math.max(longest_platform, #platform); + end + for platform, source in pairs(sources) do + print("", platform..":"..(" "):rep(4+longest_platform-#platform)..source); end print(""); print(msg or (name.." is required for Prosody to run, so we will now exit.")); -- cgit v1.2.3 From 95b463a3ee6dc6d93e1c7b39d043357a4c72f6b1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 24 Nov 2009 20:34:22 +0000 Subject: core.sessionmanager, net.*_listener: Remove the evil collectgarbage() calls --- core/sessionmanager.lua | 1 - net/xmppclient_listener.lua | 1 - net/xmppcomponent_listener.lua | 1 - net/xmppserver_listener.lua | 1 - 4 files changed, 4 deletions(-) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 5e7fe06d..9aafe0bf 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -10,7 +10,6 @@ local tonumber, tostring = tonumber, tostring; local ipairs, pairs, print, next= ipairs, pairs, print, next; -local collectgarbage = collectgarbage; local format = import("string", "format"); local hosts = hosts; diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua index 01d73a36..f455e7be 100644 --- a/net/xmppclient_listener.lua +++ b/net/xmppclient_listener.lua @@ -140,7 +140,6 @@ function xmppclient.disconnect(conn, err) sm_destroy_session(session, err); sessions[conn] = nil; session = nil; - collectgarbage("collect"); end end diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index c16f41a0..2045d28f 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -169,7 +169,6 @@ function component_listener.disconnect(conn, err) sessions[conn] = nil; for k in pairs(session) do session[k] = nil; end session = nil; - collectgarbage("collect"); end end diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua index c7e02ec5..2ab51992 100644 --- a/net/xmppserver_listener.lua +++ b/net/xmppserver_listener.lua @@ -162,7 +162,6 @@ function xmppserver.disconnect(conn, err) s2s_destroy_session(session); sessions[conn] = nil; session = nil; - collectgarbage("collect"); end end -- cgit v1.2.3 From 24bd0394c83f8741278306eb3ba4483916aef7b0 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 25 Nov 2009 21:40:44 +0500 Subject: MUC: Improved handling of incoming groupchat messages (state preserved for possible later use). --- plugins/muc/muc.lib.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 3a185e17..0fb5223d 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -128,19 +128,21 @@ function room_mt:broadcast_presence(stanza, sid, code, nick) end end function room_mt:broadcast_message(stanza, historic) + local to = stanza.attr.to; for occupant, o_data in pairs(self._occupants) do for jid in pairs(o_data.sessions) do stanza.attr.to = jid; self:_route_stanza(stanza); end end + stanza.attr.to = to; if historic then -- add to history local history = self._data['history']; if not history then history = {}; self._data['history'] = history; end - -- stanza = st.clone(stanza); + stanza = st.clone(stanza); stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = datetime.datetime()}):up(); -- XEP-0203 stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) - t_insert(history, st.clone(st.preserialize(stanza))); + t_insert(history, st.preserialize(stanza)); while #history > history_length do t_remove(history, 1) end end end @@ -528,6 +530,7 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha else self:broadcast_message(stanza, true); end + stanza.attr.from = from; end elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then local current_nick = self._jid_nick[stanza.attr.from]; -- cgit v1.2.3 From e3c1d3f2c74ba92b1b2bb858b4e2810d78afebcf Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 25 Nov 2009 21:42:05 +0500 Subject: MUC: Prevent visitors from broadcasting messages. --- plugins/muc/muc.lib.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 0fb5223d..7907c0c3 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -519,8 +519,11 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha local from, to = stanza.attr.from, stanza.attr.to; local room = jid_bare(to); local current_nick = self._jid_nick[from]; - if not current_nick then -- not in room + local occupant = self._occupants[current_nick]; + 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")); else local from = stanza.attr.from; stanza.attr.from = current_nick; -- cgit v1.2.3 From 70ab443a15224fb4ca15a9dde4adb5227bcbda1f Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 25 Nov 2009 22:00:33 +0500 Subject: MUC: Only allow moderators to change the room subject. --- plugins/muc/muc.lib.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 7907c0c3..098fef98 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -529,7 +529,12 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha stanza.attr.from = current_nick; local subject = getText(stanza, {"subject"}); if subject then - self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza + if occupant.role == "moderator" then + self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza + else + stanza.attr.from = from; + origin.send(st.error_reply(stanza, "cancel", "forbidden")); + end else self:broadcast_message(stanza, true); end -- cgit v1.2.3 From d6a193d93e2670cb2ed48db22051b6fc9922c787 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 27 Nov 2009 17:33:55 +0000 Subject: util.jid: Add join(node, host, resource) function to join the components and return nil if invalid --- util/jid.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/util/jid.lua b/util/jid.lua index ccc8309c..b43247cc 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -65,4 +65,17 @@ function prep(jid) return host; end +function join(node, host, resource) + if node and host and resource then + return node.."@"..host.."/"..resource; + elseif node and host then + return node.."@"..host; + elseif host and resource then + return host.."/"..resource; + elseif host then + return host; + end + return nil; -- Invalid JID +end + return _M; -- cgit v1.2.3 From aa442a6b883a96b0f4dd5c76d12e6431dff65e4d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 27 Nov 2009 17:41:52 +0000 Subject: tests: Add tests for util.jid.join() --- tests/test_util_jid.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_util_jid.lua b/tests/test_util_jid.lua index fe6ec74e..f579e597 100644 --- a/tests/test_util_jid.lua +++ b/tests/test_util_jid.lua @@ -6,6 +6,16 @@ -- COPYING file in the source package for more information. -- +function join(join) + assert_equal(join("a", "b", "c"), "a@b/c", "builds full JID"); + assert_equal(join("a", "b", nil), "a@b", "builds bare JID"); + assert_equal(join(nil, "b", "c"), "b/c", "builds full host JID"); + assert_equal(join(nil, "b", nil), "b", "builds bare host JID"); + assert_equal(join(nil, nil, nil), nil, "invalid JID is nil"); + assert_equal(join("a", nil, nil), nil, "invalid JID is nil"); + assert_equal(join(nil, nil, "c"), nil, "invalid JID is nil"); + assert_equal(join("a", nil, "c"), nil, "invalid JID is nil"); +end function split(split) @@ -43,3 +53,4 @@ function bare(bare) assert_equal(bare("user@@host/resource"), nil, "invalid JID is nil"); assert_equal(bare("user@host/"), nil, "invalid JID is nil"); end + -- cgit v1.2.3 From fe45368b05889419c4f082edd0eddb5a5713cb34 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 30 Nov 2009 16:39:27 +0000 Subject: util.stanza: Add stanza:get_child(name, xmlns) to find a child tag given a name/xmlns --- util/stanza.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/util/stanza.lua b/util/stanza.lua index d295d5cc..8d3b7747 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -93,6 +93,17 @@ function stanza_mt:add_child(child) return self; end +function stanza_mt:get_child(name, xmlns) + for _, child in ipairs(self.tags) do + if (not name or child.name == name) + and ((not xmlns and self.attr.xmlns == child.attr.xmlns) + or child.attr.xmlns == xmlns) then + + return child; + end + end +end + function stanza_mt:child_with_name(name) for _, child in ipairs(self.tags) do if child.name == name then return child; end -- cgit v1.2.3 From 2ed54274630554597aa47f02471c04b2a1eb6c69 Mon Sep 17 00:00:00 2001 From: Paul Aurich Date: Sat, 5 Dec 2009 09:43:53 -0800 Subject: mod_pep: Allow storage of urn:xmpp:avatar:data node (payload only with base64 data) --- 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 bfe22867..a601e2a7 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -39,7 +39,7 @@ module:add_feature("http://jabber.org/protocol/pubsub#publish"); local function publish(session, node, item) item.attr.xmlns = nil; - local disable = #item.tags ~= 1 or #item.tags[1].tags == 0; + local disable = #item.tags ~= 1 or #item.tags[1] == 0; if #item.tags == 0 then item.name = "retract"; end local bare = session.username..'@'..session.host; local stanza = st.message({from=bare, type='headline'}) -- cgit v1.2.3 From 5d568b20f190be63fb133e1b54b00deb82cb84bf Mon Sep 17 00:00:00 2001 From: Paul Aurich Date: Sat, 5 Dec 2009 10:26:43 -0800 Subject: mod_pep: Support item retrieval use cases --- plugins/mod_pep.lua | 91 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 72 insertions(+), 19 deletions(-) diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua index a601e2a7..ef03ab0f 100644 --- a/plugins/mod_pep.lua +++ b/plugins/mod_pep.lua @@ -37,7 +37,14 @@ end module:add_identity("pubsub", "pep", "Prosody"); module:add_feature("http://jabber.org/protocol/pubsub#publish"); -local function publish(session, node, item) +local function subscription_presence(user_bare, recipient) + local recipient_bare = jid_bare(recipient); + if (recipient_bare == user_bare) then return true end + local item = load_roster(jid_split(user_bare))[recipient_bare]; + return item and (item.subscription == 'from' or item.subscription == 'both'); +end + +local function publish(session, node, id, item) item.attr.xmlns = nil; local disable = #item.tags ~= 1 or #item.tags[1] == 0; if #item.tags == 0 then item.name = "retract"; end @@ -58,9 +65,9 @@ local function publish(session, node, item) end else if not user_data then user_data = {}; data[bare] = user_data; end - user_data[node] = stanza; + user_data[node] = {id or "1", item}; end - + -- broadcast for recipient, notify in pairs(recipients[bare] or NULL) do if notify[node] then @@ -74,10 +81,14 @@ local function publish_all(user, recipient, session) local notify = recipients[user] and recipients[user][recipient]; if d and notify then for node in pairs(notify) do - local message = d[node]; - if message then - message.attr.to = recipient; - session.send(message); + if d[node] then + local id, item = unpack(d[node]); + session.send(st.message({from=user, to=recipient, type='headline'}) + :tag('event', {xmlns='http://jabber.org/protocol/pubsub#event'}) + :tag('items', {node=node}) + :add_child(item) + :up() + :up()); end end end @@ -106,11 +117,9 @@ end module:hook("presence/bare", function(event) -- inbound presence to bare JID recieved local origin, stanza = event.origin, event.stanza; - local user = stanza.attr.to or (origin.username..'@'..origin.host); - local bare = jid_bare(stanza.attr.from); - local item = load_roster(jid_split(user))[bare]; - if not stanza.attr.to or (item and (item.subscription == 'from' or item.subscription == 'both')) then + + if not stanza.attr.to or subscription_presence(user, stanza.attr.from) then local recipient = stanza.attr.from; local current = recipients[user] and recipients[user][recipient]; local hash = get_caps_hash_from_presence(stanza, current); @@ -135,19 +144,63 @@ end, 10); module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", function(event) local session, stanza = event.origin, event.stanza; + local payload = stanza.tags[1]; + if stanza.attr.type == 'set' and (not stanza.attr.to or jid_bare(stanza.attr.from) == stanza.attr.to) then - local payload = stanza.tags[1]; - if payload.name == 'pubsub' then -- + payload = payload.tags[1]; + if payload and (payload.name == 'publish' or payload.name == 'retract') and payload.attr.node then -- + local node = payload.attr.node; payload = payload.tags[1]; - if payload and (payload.name == 'publish' or payload.name == 'retract') and payload.attr.node then -- - local node = payload.attr.node; - payload = payload.tags[1]; - if payload and payload.name == "item" then -- - session.send(st.reply(stanza)); - publish(session, node, st.clone(payload)); + if payload and payload.name == "item" then -- + local id = payload.attr.id; + session.send(st.reply(stanza)); + publish(session, node, id, st.clone(payload)); + return true; + end + end + elseif stanza.attr.type == 'get' then + local user = stanza.attr.to and jid_bare(stanza.attr.to) or session.username..'@'..session.host; + if subscription_presence(user, stanza.attr.from) then + local user_data = data[user]; + local node, requested_id; + payload = payload.tags[1]; + if payload and payload.name == 'items' then + node = payload.attr.node; + local item = payload.tags[1]; + if item and item.name == "item" then + requested_id = item.attr.id; + end + end + if node and user_data and user_data[node] then -- Send the last item + local id, item = unpack(user_data[node]); + if not requested_id or id == requested_id then + local stanza = st.reply(stanza) + :tag('pubsub', {xmlns='http://jabber.org/protocol/pubsub'}) + :tag('items', {node=node}) + :add_child(item) + :up() + :up(); + session.send(stanza); + return true; + else -- requested item doesn't exist + local stanza = st.reply(stanza) + :tag('pubsub', {xmlns='http://jabber.org/protocol/pubsub'}) + :tag('items', {node=node}) + :up(); + session.send(stanza); return true; end + elseif node then -- node doesn't exist + session.send(st.error_reply(stanza, 'cancel', 'item-not-found')); + return true; + else --invalid request + session.send(st.error_reply(stanza, 'modify', 'bad-request')); + return true; end + else --no presence subscription + session.send(st.error_reply(stanza, 'auth', 'not-authorized') + :tag('presence-subscription-required', {xmlns='http://jabber.org/protocol/pubsub#errors'})); + return true; end end end); -- cgit v1.2.3 From 26df5eea856fb8b6f9a4b312eb8b5341fa828ad6 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 10 Dec 2009 01:56:16 +0500 Subject: Mainfile: Broke up a really long line. --- prosody | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/prosody b/prosody index 7f69e085..95be55e3 100755 --- a/prosody +++ b/prosody @@ -284,8 +284,11 @@ function prepare_to_start() end function init_global_protection() - -- Catch global accesses -- - local locked_globals_mt = { __index = function (t, k) error("Attempt to read a non-existent global '"..k.."'", 2); end, __newindex = function (t, k, v) error("Attempt to set a global: "..tostring(k).." = "..tostring(v), 2); end } + -- Catch global accesses + local locked_globals_mt = { + __index = function (t, k) error("Attempt to read a non-existent global '"..k.."'", 2); end; + __newindex = function (t, k, v) error("Attempt to set a global: "..tostring(k).." = "..tostring(v), 2); end; + }; function prosody.unlock_globals() setmetatable(_G, nil); -- cgit v1.2.3 From eaa3a4e22570bb7ce13f6c372a2033d33c712ef9 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 10 Dec 2009 02:47:13 +0500 Subject: prosody: Log a warning and traceback, but don't throw an error on nil global read. --- prosody | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prosody b/prosody index 95be55e3..2ca4241c 100755 --- a/prosody +++ b/prosody @@ -286,7 +286,7 @@ end function init_global_protection() -- Catch global accesses local locked_globals_mt = { - __index = function (t, k) error("Attempt to read a non-existent global '"..k.."'", 2); end; + __index = function (t, k) log("warn", "%s", debug.traceback("Attempt to read a non-existent global '"..k.."'", 2)); end; __newindex = function (t, k, v) error("Attempt to set a global: "..tostring(k).." = "..tostring(v), 2); end; }; -- cgit v1.2.3 From b62a35519f8f76f702a504cbb28d63647c93745a Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 10 Dec 2009 02:50:23 +0500 Subject: prosody: Call tostring on the key being used for nil global read before concatenating it with a string. --- prosody | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prosody b/prosody index 2ca4241c..593a0e34 100755 --- a/prosody +++ b/prosody @@ -286,7 +286,7 @@ end function init_global_protection() -- Catch global accesses local locked_globals_mt = { - __index = function (t, k) log("warn", "%s", debug.traceback("Attempt to read a non-existent global '"..k.."'", 2)); end; + __index = function (t, k) log("warn", "%s", debug.traceback("Attempt to read a non-existent global '"..tostring(k).."'", 2)); end; __newindex = function (t, k, v) error("Attempt to set a global: "..tostring(k).." = "..tostring(v), 2); end; }; -- cgit v1.2.3 From 2f8bd04c9ca0fbbc40b1f9630816f3976e6754df Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 10 Dec 2009 03:02:04 +0500 Subject: modulemanager: Fire item-removed events on module unload. --- core/modulemanager.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 9cd56187..ecb1bc6c 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -197,6 +197,15 @@ function unload(host, name, ...) end end hooks:remove(host, name); + if mod.module.items then -- remove items + for key,t in pairs(mod.module.items) do + for i = #t,1,-1 do + local value = t[i]; + t[i] = nil; + hosts[host].events.fire_event("item-removed/"..key, {source = self, item = value}); + end + end + end modulemap[host][name] = nil; return true; end -- cgit v1.2.3 From f3a1c08111f2c2d43c31800e93453e85bafba8af Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 1 Jan 2010 03:32:26 +0000 Subject: prosody.cfg.lua.dist: Remove lie about requiring console_enabled --- prosody.cfg.lua.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prosody.cfg.lua.dist b/prosody.cfg.lua.dist index d660a9bd..04a1ce5e 100644 --- a/prosody.cfg.lua.dist +++ b/prosody.cfg.lua.dist @@ -63,7 +63,7 @@ Host "*" -- Other specific functionality --"posix"; -- POSIX functionality, sends server to background, enables syslog, etc. - --"console"; -- telnet to port 5582 (needs console_enabled = true) + --"console"; -- Opens admin telnet interface on localhost port 5582 --"bosh"; -- Enable BOSH clients, aka "Jabber over HTTP" --"httpserver"; -- Serve static files from a directory over HTTP }; -- cgit v1.2.3 From 7a04ee2962ab0b83bc0042da27f1ce62225cf3c4 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 10 Jan 2010 20:21:48 +0000 Subject: util.pposix: Fix return type of lc_abort to shush compiler warning --- util-src/pposix.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util-src/pposix.c b/util-src/pposix.c index 94086ed6..cef75287 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -463,9 +463,10 @@ int lc_getrlimit(lua_State *L) { return 3; } -void lc_abort(lua_State* L) +int lc_abort(lua_State* L) { abort(); + return 0; } /* Register functions */ -- cgit v1.2.3 From 0e67359b5c5444db608af5d07821811e08c4f95f Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 11 Jan 2010 17:52:28 +0500 Subject: mod_register: Return a error on empty usernames (thanks Neustradamus). --- plugins/mod_register.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_register.lua b/plugins/mod_register.lua index bda40124..be1be0ae 100644 --- a/plugins/mod_register.lua +++ b/plugins/mod_register.lua @@ -141,7 +141,7 @@ module:add_iq_handler("c2s_unauthed", "jabber:iq:register", function (session, s username = nodeprep(table.concat(username)); password = table.concat(password); local host = module.host; - if not username then + if not username or username == "" then session.send(st.error_reply(stanza, "modify", "not-acceptable", "The requested username is invalid.")); elseif usermanager_user_exists(username, host) then session.send(st.error_reply(stanza, "cancel", "conflict", "The requested username already exists.")); -- cgit v1.2.3 From 909e439525e41721abd91b227c7f9078aeda504b Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 11 Jan 2010 18:59:06 +0500 Subject: sessionmanager: Added resource prepping, and invalid resource checking to the bind_resource function. --- core/sessionmanager.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 9aafe0bf..df144f07 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -24,6 +24,7 @@ local uuid_generate = require "util.uuid".generate; local rm_load_roster = require "core.rostermanager".load_roster; local config_get = require "core.configmanager".get; local nameprep = require "util.encodings".stringprep.nameprep; +local resourceprep = require "util.encodings".stringprep.resourceprep; local fire_event = require "core.eventmanager".fire_event; local add_task = require "util.timer".add_task; @@ -105,7 +106,8 @@ function bind_resource(session, resource) if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end -- We don't support binding multiple resources - resource = resource or uuid_generate(); + resource = resourceprep(resource); + resource = resource ~= "" and resource or uuid_generate(); --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing if not hosts[session.host].sessions[session.username] then -- cgit v1.2.3 From f4e886e7177eaf24ac415e3b8ebc80af256a3232 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 18 Jan 2010 16:31:57 +0000 Subject: stanza_router: Log the name of unhandled stanzas (thanks bear) --- core/stanza_router.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/stanza_router.lua b/core/stanza_router.lua index 00c37ed7..b60ff2b5 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -191,6 +191,6 @@ function core_route_stanza(origin, stanza) log("debug", "Routing outgoing stanza for %s to %s", from_host, host); send_s2s(from_host, host, stanza); else - log("warn", "received stanza from unhandled connection type: %s", origin.type); + log("warn", "received %s stanza from unhandled connection type: %s", tostring(stanza.name), tostring(origin.type)); end end -- cgit v1.2.3 From 649aefc28e661f4c89f49e6600646de4a673b99c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 18 Jan 2010 17:14:41 +0000 Subject: mod_presence: Automatically deny presence requests for hosts, fixes traceback in #153 --- plugins/mod_presence.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index abbc3a3d..815b5c8b 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -309,6 +309,13 @@ module:hook("presence/bare", function(data) end return true; end); +module:hook("presence/host", function (data) + local stanza = data.stanza; + local reply = st.reply(stanza); + reply.attr.type = "unsubscribed"; + handle_inbound_presence_subscriptions_and_probes(data.origin, reply, jid_bare(stanza.attr.to), jid_bare(stanza.attr.from), core_route_stanza); + return true; +end); module:hook("presence/full", function(data) -- inbound presence to full JID recieved local origin, stanza = data.origin, data.stanza; -- cgit v1.2.3 From 4c3707ec7bb896d1efaccf63eed18aee8cd88ef8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 21 Jan 2010 13:10:13 +0000 Subject: net.httpserver: Close connection on invalid HTTP status line --- net/httpserver.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/httpserver.lua b/net/httpserver.lua index ddb4475c..1341bfbb 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -175,7 +175,10 @@ local function request_reader(request, data, startpos) log("debug", "Reading request line...") local method, path, http, linelen = data:match("^(%S+) (%S+) HTTP/(%S+)\r\n()", startpos); if not method then - return call_callback(request, "invalid-status-line"); + log("warn", "Invalid HTTP status line, telling callback then closing"); + local ret = call_callback(request, "invalid-status-line"); + request:destroy(); + return ret; end request.method, request.path, request.httpversion = method, path, http; -- cgit v1.2.3 From e79181eab31b87bbab91ff2cc73f43d529d4b2dc Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 21 Jan 2010 13:14:52 +0000 Subject: net.httpserver: Make it possible to return responses with no body --- net/httpserver.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/httpserver.lua b/net/httpserver.lua index 1341bfbb..e16d4de6 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -36,8 +36,8 @@ end local function send_response(request, response) -- Write status line local resp; - if response.body then - local body = tostring(response.body); + if response.body or response.headers then + local body = response.body and tostring(response.body); log("debug", "Sending response to %s", request.id); resp = { "HTTP/1.0 ", response.status or "200 OK", "\r\n"}; local h = response.headers; @@ -49,14 +49,14 @@ local function send_response(request, response) t_insert(resp, "\r\n"); end end - if not (h and h["Content-Length"]) then + if body and not (h and h["Content-Length"]) then t_insert(resp, "Content-Length: "); t_insert(resp, #body); t_insert(resp, "\r\n"); end t_insert(resp, "\r\n"); - if request.method ~= "HEAD" then + if body and request.method ~= "HEAD" then t_insert(resp, body); end else -- cgit v1.2.3 From c103c2bb6b528a64b032e55cfb97d0f41dbf695d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 21 Jan 2010 14:53:01 +0000 Subject: net.httpserver: More robust handling of headers split across multiple packets --- net/httpserver.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/net/httpserver.lua b/net/httpserver.lua index e16d4de6..c4be59bf 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -146,22 +146,29 @@ local function request_reader(request, data, startpos) elseif request.state == "headers" then log("debug", "Reading headers...") local pos = startpos; - local headers = request.headers or {}; + local headers, headers_complete = request.headers; + if not headers then + headers = {}; + request.headers = headers; + end + for line in data:gmatch("(.-)\r\n") do startpos = (startpos or 1) + #line + 2; local k, v = line:match("(%S+): (.+)"); if k and v then headers[k:lower()] = v; --- log("debug", "Header: "..k:lower().." = "..v); + --log("debug", "Header: '"..k:lower().."' = '"..v.."'"); elseif #line == 0 then - request.headers = headers; + headers_complete = true; break; else log("debug", "Unhandled header line: "..line); end end - if not expectbody(request) then + if not headers_complete then return; end + + if not expectbody(request) then call_callback(request); return; end -- cgit v1.2.3 From f80585f35478b8c9852a59cf2d8f28c0e12586a1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 22 Jan 2010 14:58:31 +0000 Subject: util.dataforms: Add optional type parameters (defaults to 'form') --- util/dataforms.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/dataforms.lua b/util/dataforms.lua index a3bde8ca..56671347 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -23,8 +23,8 @@ function new(layout) return setmetatable(layout, form_mt); end -function form_t.form(layout, data) - local form = st.stanza("x", { xmlns = xmlns_forms, type = "form" }); +function form_t.form(layout, data, formtype) + local form = st.stanza("x", { xmlns = xmlns_forms, type = formtype or "form" }); if layout.title then form:tag("title"):text(layout.title):up(); end -- cgit v1.2.3 From 139241f580151209bb7d3579d57c601f2d99883c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 23 Jan 2010 02:53:44 +0000 Subject: mod_component: Fix name of config option in error message (thanks nulani!) --- plugins/mod_component.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_component.lua b/plugins/mod_component.lua index 69a42eaf..4201bb19 100644 --- a/plugins/mod_component.lua +++ b/plugins/mod_component.lua @@ -44,7 +44,7 @@ function handle_component_auth(session, stanza) local secret = config.get(session.user, "core", "component_secret"); if not secret then - (session.log or log)("warn", "Component attempted to identify as %s, but component_password is not set", session.user); + (session.log or log)("warn", "Component attempted to identify as %s, but component_secret is not set", session.user); session:close("not-authorized"); return; end -- cgit v1.2.3 From 06ffadf829c80908d9056d51417468da8eb5bce1 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 24 Jan 2010 05:35:21 +0500 Subject: prosody: Listen for component connections on port 5347 by default. --- prosody | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prosody b/prosody index 593a0e34..01512c1b 100755 --- a/prosody +++ b/prosody @@ -277,7 +277,7 @@ function prepare_to_start() -- start listening on sockets prosody.net_activate_ports("c2s", "xmppclient", {5222}); prosody.net_activate_ports("s2s", "xmppserver", {5269}); - prosody.net_activate_ports("component", "xmppcomponent", {}, "tcp"); + prosody.net_activate_ports("component", "xmppcomponent", {5347}, "tcp"); prosody.net_activate_ports("legacy_ssl", "xmppclient", {}, "ssl"); prosody.start_time = os.time(); -- cgit v1.2.3 From d77c415e7641d865bcea11d87b68d1c75cbc81f3 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 29 Jan 2010 18:16:39 +0500 Subject: mod_presence: Respond with an unavailable presence when subscribers probe and no resources are available. --- plugins/mod_presence.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 815b5c8b..31d2d7b4 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -217,7 +217,7 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b if stanza.attr.type == "probe" then if rostermanager.is_contact_subscribed(node, host, from_bare) then if 0 == send_presence_of_available_resources(node, host, st_from, origin, core_route_stanza) then - -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) + core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- TODO send last activity end else core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unsubscribed"})); @@ -227,7 +227,7 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="subscribed"})); -- already subscribed -- Sending presence is not clearly stated in the RFC, but it seems appropriate if 0 == send_presence_of_available_resources(node, host, from_bare, origin, core_route_stanza) then - -- TODO send last recieved unavailable presence (or we MAY do nothing, which is fine too) + core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- TODO send last activity end else core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- acknowledging receipt -- cgit v1.2.3 From b7d45c17f2c325f55ef9cb27b1896d4b7ee8d324 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 29 Jan 2010 21:04:36 +0500 Subject: stanza_router: Added third parameter to core_post_stanza, to control pre-events. --- core/stanza_router.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/stanza_router.lua b/core/stanza_router.lua index b60ff2b5..b025511e 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -98,7 +98,7 @@ function core_process_stanza(origin, stanza) return; -- FIXME what should we do here? does this work with subdomains? end end - core_post_stanza(origin, stanza); + core_post_stanza(origin, stanza, origin.full_jid); else local h = hosts[stanza.attr.to or origin.host or origin.to_host]; if h then @@ -119,7 +119,7 @@ function core_process_stanza(origin, stanza) end end -function core_post_stanza(origin, stanza) +function core_post_stanza(origin, stanza, preevents) local to = stanza.attr.to; local node, host, resource = jid_split(to); local to_bare = node and (node.."@"..host) or host; -- bare JID @@ -143,7 +143,7 @@ function core_post_stanza(origin, stanza) end local event_data = {origin=origin, stanza=stanza}; - if origin.full_jid == stanza.attr.from then -- c2s connection + if preevents then -- c2s connection if hosts[origin.host].events.fire_event('pre-'..stanza.name..to_type, event_data) then return; end -- do preprocessing end local h = hosts[to_bare] or hosts[host or origin.host]; -- cgit v1.2.3 From 0e7b83863adad24bdc4ba627f034d2f6d329cf33 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 29 Jan 2010 21:06:51 +0500 Subject: mod_presence: Added handler for presence subscriptions and probes to local hosts. --- plugins/mod_presence.lua | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 31d2d7b4..ec983fc2 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -309,13 +309,6 @@ module:hook("presence/bare", function(data) end return true; end); -module:hook("presence/host", function (data) - local stanza = data.stanza; - local reply = st.reply(stanza); - reply.attr.type = "unsubscribed"; - handle_inbound_presence_subscriptions_and_probes(data.origin, reply, jid_bare(stanza.attr.to), jid_bare(stanza.attr.from), core_route_stanza); - return true; -end); module:hook("presence/full", function(data) -- inbound presence to full JID recieved local origin, stanza = data.origin, data.stanza; @@ -333,6 +326,20 @@ module:hook("presence/full", function(data) end -- resource not online, discard return true; end); +module:hook("presence/host", function(data) + -- inbound presence to the host + local origin, stanza = data.origin, data.stanza; + + local from_bare = jid_bare(stanza.attr.from); + local t = stanza.attr.type; + if t == "probe" then + core_route_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id })); + elseif t == "subscribe" then + core_route_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id, type = "subscribed" })); + core_route_stanza(hosts[module.host], st.presence({ from = module.host, to = from_bare, id = stanza.attr.id })); + end + return true; +end); module:hook("resource-unbind", function(event) local session, err = event.session, event.error; -- cgit v1.2.3 From 0ff3e76b777a8feda3d1c1faa839daa7a397e96e Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 29 Jan 2010 21:08:18 +0500 Subject: mod_presence: Quick fix to make probes from local users to local hosts work. --- plugins/mod_presence.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index ec983fc2..c28dd338 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -76,6 +76,7 @@ function handle_normal_presence(origin, stanza, core_route_stanza) end end if stanza.attr.type == nil and not origin.presence then -- initial presence + origin.presence = stanza; -- FIXME repeated later local probe = st.presence({from = origin.full_jid, type = "probe"}); for jid, item in pairs(roster) do -- probe all contacts we are subscribed to if item.subscription == "both" or item.subscription == "to" then -- cgit v1.2.3 From da411ed5656f1d6332beaeeff3056a872bba7307 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 30 Jan 2010 18:51:07 +0000 Subject: MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo) --- plugins/muc/muc.lib.lua | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 098fef98..f5b82e0d 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -494,9 +494,14 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway? if _rol == "none" then _rol = nil; end local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); - for nick, occupant in pairs(self._occupants) do + for occupant_jid, occupant in pairs(self._occupants) do if occupant.role == _rol then - reply:tag("item", {nick = nick, role = _rol or "none", affiliation = occupant.affiliation or "none", jid = occupant.jid}):up(); + reply:tag("item", { + nick = select(3, jid_split(occupant_jid)), + role = _rol or "none", + affiliation = occupant.affiliation or "none", + jid = occupant.jid + }):up(); end end origin.send(reply); @@ -662,21 +667,21 @@ function room_mt:get_role(nick) local session = self._occupants[nick]; return session and session.role or nil; end -function room_mt:set_role(actor, nick, role, callback, reason) +function room_mt:set_role(actor, occupant_jid, role, callback, reason) if role == "none" then role = nil; end if role and role ~= "moderator" and role ~= "participant" and role ~= "visitor" then return nil, "modify", "not-acceptable"; end if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end - local occupant = self._occupants[nick]; + local occupant = self._occupants[occupant_jid]; if not occupant then return nil, "modify", "not-acceptable"; end if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end - local p = st.presence({from = nick}) + local p = st.presence({from = occupant_jid}) :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) - :tag("item", {affiliation=occupant.affiliation or "none", nick=nick, role=role or "none"}) + :tag("item", {affiliation=occupant.affiliation or "none", nick=select(3, jid_split(occupant_jid)), role=role or "none"}) :tag("reason"):text(reason or ""):up() :up(); if not role then -- kick p.attr.type = "unavailable"; - self._occupants[nick] = nil; + self._occupants[occupant_jid] = nil; for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick self._jid_nick[jid] = nil; end @@ -689,7 +694,7 @@ function room_mt:set_role(actor, nick, role, callback, reason) self:_route_stanza(p); end if callback then callback(); end - self:broadcast_except_nick(p, nick); + self:broadcast_except_nick(p, occupant_jid); return true; end -- cgit v1.2.3 From 43644666de538fedd188088111cefcead0f989db Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 31 Jan 2010 16:40:47 +0000 Subject: prosody: Log error message when failing to open ports --- prosody | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/prosody b/prosody index 01512c1b..05d91b7d 100755 --- a/prosody +++ b/prosody @@ -195,7 +195,7 @@ function init_global_state() if type(port) ~= "number" then log("error", "Non-numeric "..option.."_ports: "..tostring(port)); else - cl.start(listener, { + local ok, err = cl.start(listener, { ssl = conntype ~= "tcp" and global_ssl_ctx, port = port, interface = config.get("*", "core", option.."_interface") @@ -203,6 +203,24 @@ function init_global_state() or config.get("*", "core", "interface"), type = conntype }); + if not ok then + local friendly_message = err; + if err:match(" in use") then + if port == 5222 or port == 5223 or port == 5269 then + friendly_message = "check that Prosody or another XMPP server is " + .."not already running and using this port"; + elseif port == 80 or port == 81 then + friendly_message = "check that a HTTP server is not already using " + .."this port"; + elseif port == 5280 then + friendly_message = "check that Prosody or a BOSH connection manager " + .."is not already running"; + end + elseif err:match("permission") then + friendly_message = "Prosody does not have sufficient privileges to use this port"; + end + log("error", "Failed to open server port %d, %s", port, friendly_message); + end end end end -- cgit v1.2.3 From 4dbc6b605d93a998517eb96c4bae43038199d75a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 31 Jan 2010 17:15:35 +0000 Subject: prosody: Show friendly error when no config present for legacy SSL ports --- prosody | 3 +++ 1 file changed, 3 insertions(+) diff --git a/prosody b/prosody index 05d91b7d..ce56fbb1 100755 --- a/prosody +++ b/prosody @@ -218,6 +218,9 @@ function init_global_state() end elseif err:match("permission") then friendly_message = "Prosody does not have sufficient privileges to use this port"; + elseif err == "no ssl context" then + friendly_message = "there is no 'ssl' config under Host \"*\" which is " + .."require for legacy SSL ports"; end log("error", "Failed to open server port %d, %s", port, friendly_message); end -- cgit v1.2.3 From 9ed7624f754479dfb78d90a5367678567424a03b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 31 Jan 2010 19:27:52 +0000 Subject: util.stanza: stanza.error_reply(): Fix to put the correct namespace on --- util/stanza.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/util/stanza.lua b/util/stanza.lua index 8d3b7747..069daa53 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -291,13 +291,16 @@ function reply(orig) return stanza(orig.name, orig.attr and { to = orig.attr.from, from = orig.attr.to, id = orig.attr.id, type = ((orig.name == "iq" and "result") or orig.attr.type) }); end -function error_reply(orig, type, condition, message) - local t = reply(orig); - t.attr.type = "error"; - t:tag("error", {type = type}) - :tag(condition, {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up(); - if (message) then t:tag("text"):text(message):up(); end - return t; -- stanza ready for adding app-specific errors +do + local xmpp_stanzas_attr = { xmlns = xmlns_stanzas }; + function error_reply(orig, type, condition, message) + local t = reply(orig); + t.attr.type = "error"; + t:tag("error", {type = type}) --COMPAT: Some day xmlns:stanzas goes here + :tag(condition, xmpp_stanzas_attr):up(); + if (message) then t:tag("text", xmpp_stanzas_attr):text(message):up(); end + return t; -- stanza ready for adding app-specific errors + end end function presence(attr) -- cgit v1.2.3 From 85d9e34b7ef05738e88fa83a8eece3b5ee9077b2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 5 Feb 2010 15:05:39 +0000 Subject: prosody: Add a catch-all friendly message for when any port is in use we want to use --- prosody | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prosody b/prosody index ce56fbb1..65d8dceb 100755 --- a/prosody +++ b/prosody @@ -215,6 +215,8 @@ function init_global_state() elseif port == 5280 then friendly_message = "check that Prosody or a BOSH connection manager " .."is not already running"; + else + friendly_message = "this port is in use by another application"; end elseif err:match("permission") then friendly_message = "Prosody does not have sufficient privileges to use this port"; -- cgit v1.2.3 From e376e12502db674b55e1fe29e376225462f3a1fb Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 10 Feb 2010 00:12:48 +0500 Subject: util.encodings: Use STD3 ASCII rules for idna.to_ascii. --- util-src/encodings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util-src/encodings.c b/util-src/encodings.c index 5147512f..c573a330 100644 --- a/util-src/encodings.c +++ b/util-src/encodings.c @@ -174,7 +174,7 @@ static int Lidna_to_ascii(lua_State *L) /** idna.to_ascii(s) */ size_t len; const char *s = luaL_checklstring(L, 1, &len); char* output = NULL; - int ret = idna_to_ascii_8z(s, &output, 0); + int ret = idna_to_ascii_8z(s, &output, IDNA_USE_STD3_ASCII_RULES); if (ret == IDNA_SUCCESS) { lua_pushstring(L, output); idn_free(output); -- cgit v1.2.3 From 1349805068792385931dceb72f6b6865c8fa88ac Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 12 Feb 2010 00:54:14 +0500 Subject: mod_presence: Don't depend on sessions array existing for a user when handling outgoing presence broadcast. --- plugins/mod_presence.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index c28dd338..4aa8f497 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -18,6 +18,7 @@ local st = require "util.stanza"; local jid_split = require "util.jid".split; local jid_bare = require "util.jid".bare; local hosts = hosts; +local NULL = {}; local rostermanager = require "core.rostermanager"; local sessionmanager = require "core.sessionmanager"; @@ -63,7 +64,8 @@ end function handle_normal_presence(origin, stanza, core_route_stanza) local roster = origin.roster; local node, host = origin.username, origin.host; - for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast to all resources + local user = bare_sessions[node.."@"..host]; + for _, res in pairs(user and user.sessions or NULL) do -- broadcast to all resources if res ~= origin and res.presence then -- to resource stanza.attr.to = res.full_jid; core_route_stanza(origin, stanza); @@ -84,7 +86,7 @@ function handle_normal_presence(origin, stanza, core_route_stanza) core_route_stanza(origin, probe); end end - for _, res in pairs(hosts[host].sessions[node].sessions) do -- broadcast from all available resources + for _, res in pairs(user and user.sessions or NULL) do -- broadcast from all available resources if res ~= origin and res.presence then res.presence.attr.to = origin.full_jid; core_route_stanza(res, res.presence); -- cgit v1.2.3 From 60c40e44de335c4d7f6ed8b6ed25e8307bc4bcd9 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 12 Feb 2010 00:55:06 +0500 Subject: mod_presence: Don't depend on user being online when calculating top resources. --- plugins/mod_presence.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 4aa8f497..f6ea9e6b 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -55,10 +55,11 @@ local function select_top_resources(user) end return recipients; end -local function recalc_resource_map(origin) - local user = hosts[origin.host].sessions[origin.username]; - user.top_resources = select_top_resources(user); - if #user.top_resources == 0 then user.top_resources = nil; end +local function recalc_resource_map(user) + if user then + user.top_resources = select_top_resources(user); + if #user.top_resources == 0 then user.top_resources = nil; end + end end function handle_normal_presence(origin, stanza, core_route_stanza) @@ -117,7 +118,7 @@ function handle_normal_presence(origin, stanza, core_route_stanza) origin.presence = nil; if origin.priority then origin.priority = nil; - recalc_resource_map(origin); + recalc_resource_map(user); end if origin.directed then for jid in pairs(origin.directed) do @@ -139,7 +140,7 @@ function handle_normal_presence(origin, stanza, core_route_stanza) else priority = 0; end if origin.priority ~= priority then origin.priority = priority; - recalc_resource_map(origin); + recalc_resource_map(user); end end stanza.attr.to = nil; -- reset it -- cgit v1.2.3 From 2e726abc77cdfb09f01eb31358ad56d587a9c88e Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 12 Feb 2010 02:39:50 +0500 Subject: mod_tls: Respond with proper error when TLS cannot be negotiated. --- plugins/mod_tls.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/mod_tls.lua b/plugins/mod_tls.lua index 8a450803..fb1433da 100644 --- a/plugins/mod_tls.lua +++ b/plugins/mod_tls.lua @@ -26,8 +26,9 @@ module:add_handler("c2s_unauthed", "starttls", xmlns_starttls, session.log("info", "TLS negotiation started..."); session.secure = false; else - -- FIXME: What reply? session.log("warn", "Attempt to start TLS, but TLS is not available on this connection"); + (session.sends2s or session.send)(st.stanza("failure", { xmlns = xmlns_starttls })); + session:close(); end end); @@ -43,8 +44,9 @@ module:add_handler("s2sin_unauthed", "starttls", xmlns_starttls, session.log("info", "TLS negotiation started for incoming s2s..."); session.secure = false; else - -- FIXME: What reply? session.log("warn", "Attempt to start TLS, but TLS is not available on this s2s connection"); + (session.sends2s or session.send)(st.stanza("failure", { xmlns = xmlns_starttls })); + session:close(); end end); -- cgit v1.2.3 From db783f4a21352a560c162932d18d20cc22bb86a9 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 12 Feb 2010 03:14:53 +0500 Subject: mod_tls: Fixed an extra :up() in s2s stream feature generation. --- plugins/mod_tls.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_tls.lua b/plugins/mod_tls.lua index fb1433da..49ee18c9 100644 --- a/plugins/mod_tls.lua +++ b/plugins/mod_tls.lua @@ -68,7 +68,7 @@ module:hook("s2s-stream-features", function (data) local session, features = data.session, data.features; if session.to_host and session.conn.starttls then - features:tag("starttls", starttls_attr):up(); + features:tag("starttls", starttls_attr); if secure_s2s_only then features:tag("required"):up():up(); else -- cgit v1.2.3 From f3444ceaa2a879e7823bd772791bc7c31dc61075 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 12 Feb 2010 12:43:50 +0000 Subject: hostmanager: Log an error if no hosts are defined --- core/hostmanager.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/hostmanager.lua b/core/hostmanager.lua index f89eaeba..8010b3de 100644 --- a/core/hostmanager.lua +++ b/core/hostmanager.lua @@ -33,12 +33,19 @@ local hosts_loaded_once; local function load_enabled_hosts(config) local defined_hosts = config or configmanager.getconfig(); + local activated_any_host; for host, host_config in pairs(defined_hosts) do if host ~= "*" and (host_config.core.enabled == nil or host_config.core.enabled) and not host_config.core.component_module then + activated_any_host = true; activate(host, host_config); end end + + if not activated_any_host then + log("error", "No hosts defined in the config file. This may cause unexpected behaviour as no modules will be loaded."); + end + eventmanager.fire_event("hosts-activated", defined_hosts); hosts_loaded_once = true; end -- cgit v1.2.3 From 8e47276e919b4bd9b50916c9831e96158c0eeb4f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 12 Feb 2010 15:05:48 +0000 Subject: net.dns: Normalize records before placing them in the cache, fixes issues with CNAME targets in CAPS (fixes #161) --- net/dns.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net/dns.lua b/net/dns.lua index c50e893c..25941015 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -594,17 +594,18 @@ end function resolver:remember(rr, type) -- - - - - - - - - - - - - - remember --print ('remember', type, rr.class, rr.type, rr.name) + local qname, qtype, qclass = standardize(rr.name, rr.type, rr.class); if type ~= '*' then - type = rr.type; - local all = get(self.cache, rr.class, '*', rr.name); + type = qtype; + local all = get(self.cache, qclass, '*', qname); --print('remember all', all); if all then append(all, rr); end end self.cache = self.cache or setmetatable({}, cache_metatable); - local rrs = get(self.cache, rr.class, type, rr.name) or - set(self.cache, rr.class, type, rr.name, setmetatable({}, rrs_metatable)); + local rrs = get(self.cache, qclass, type, qname) or + set(self.cache, qclass, type, qname, setmetatable({}, rrs_metatable)); append(rrs, rr); if type == 'MX' then self.unsorted[rrs] = true; end -- cgit v1.2.3 From 2739ed3948b9df3a596d6aef6d6790f1c2e1c59f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 12 Feb 2010 17:14:54 +0000 Subject: sessionmanager, s2smanager: Give sessions dummy data handlers that log when data is received by a destroyed session --- core/s2smanager.lua | 3 +++ core/sessionmanager.lua | 3 +++ 2 files changed, 6 insertions(+) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index bfa3069a..7de97d0c 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -491,6 +491,8 @@ function mark_connected(session) end end +local function null_data_handler(data) log("debug", "Discarding data from destroyed s2s session: %s", data); end + function destroy_session(session) (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); @@ -506,6 +508,7 @@ function destroy_session(session) session[k] = nil; end end + session.data = null_data_handler; end return _M; diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index df144f07..9df7823c 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -66,6 +66,8 @@ function new_session(conn) return session; end +local function null_data_handler(data) log("debug", "Discarding data from destroyed c2s session: %s", data); end + function destroy_session(session, err) (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); @@ -88,6 +90,7 @@ function destroy_session(session, err) session[k] = nil; end end + session.data = null_data_handler; end function make_authenticated(session, username) -- cgit v1.2.3 From 4a592b5069548aa13a6aad96a1fcb54222345290 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 12 Feb 2010 17:27:53 +0000 Subject: sessionmanager, s2smanager: Fix for syntax of null_data_handler() (thanks Nolan) --- core/s2smanager.lua | 2 +- core/sessionmanager.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 7de97d0c..e8d8e723 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -491,7 +491,7 @@ function mark_connected(session) end end -local function null_data_handler(data) log("debug", "Discarding data from destroyed s2s session: %s", data); end +local function null_data_handler(conn, data) log("debug", "Discarding data from destroyed s2s session: %s", data); end function destroy_session(session) (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 9df7823c..2dd0070b 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -66,7 +66,7 @@ function new_session(conn) return session; end -local function null_data_handler(data) log("debug", "Discarding data from destroyed c2s session: %s", data); end +local function null_data_handler(conn, data) log("debug", "Discarding data from destroyed c2s session: %s", data); end function destroy_session(session, err) (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); -- cgit v1.2.3 From 27114996e41d03b74913ccf02240ae572e09ad82 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 13 Feb 2010 16:22:05 +0000 Subject: prosody: More accurate friendly error message in the event that creating the global SSL context fails --- prosody | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/prosody b/prosody index 65d8dceb..55198c2f 100755 --- a/prosody +++ b/prosody @@ -221,8 +221,12 @@ function init_global_state() elseif err:match("permission") then friendly_message = "Prosody does not have sufficient privileges to use this port"; elseif err == "no ssl context" then - friendly_message = "there is no 'ssl' config under Host \"*\" which is " - .."require for legacy SSL ports"; + 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 log("error", "Failed to open server port %d, %s", port, friendly_message); end -- cgit v1.2.3 From 107527504299072512920fe9374f85cf7687c694 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 13 Feb 2010 19:35:12 +0000 Subject: mod_saslauth: Don't print raw SASL data to avoid logging passwords unnecessarily --- plugins/mod_saslauth.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index c0f57cd7..9fd719c9 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -38,13 +38,13 @@ local new_sasl = require "util.sasl".new; local function build_reply(status, ret, err_msg) local reply = st.stanza(status, {xmlns = xmlns_sasl}); if status == "challenge" then - log("debug", "%s", ret or ""); + --log("debug", "CHALLENGE: %s", ret or ""); reply:text(base64.encode(ret or "")); elseif status == "failure" then reply:tag(ret):up(); if err_msg then reply:tag("text"):text(err_msg); end elseif status == "success" then - log("debug", "%s", ret or ""); + --log("debug", "SUCCESS: %s", ret or ""); reply:text(base64.encode(ret or "")); else module:log("error", "Unknown sasl status: %s", status); @@ -121,7 +121,7 @@ local function sasl_handler(session, stanza) local text = stanza[1]; if text then text = base64.decode(text); - log("debug", "%s", text); + --log("debug", "AUTH: %s", text:gsub("[%z\001-\008\011\012\014-\031]", " ")); if not text then session.sasl_handler = nil; session.send(build_reply("failure", "incorrect-encoding")); -- cgit v1.2.3 From 8b0ec93370f16cb2b4da3a2dd7734d6d41175312 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Feb 2010 18:41:44 +0000 Subject: configmanager: Error when a component and host clash hostnames --- core/configmanager.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/configmanager.lua b/core/configmanager.lua index 1fbe83b8..7ae472f6 100644 --- a/core/configmanager.lua +++ b/core/configmanager.lua @@ -9,8 +9,11 @@ local _G = _G; -local setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type = - setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type; +local setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table, format = + setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table, string.format; + + +local trb = debug.traceback local eventmanager = require "core.eventmanager"; @@ -115,6 +118,10 @@ do rawset(env, "__currenthost", "*") -- Default is global function env.Host(name) + if rawget(config, name) and rawget(config[name].core, "component_module") then + error(format("Host %q clashes with previously defined %s Component %q, for services use a sub-domain like conference.%s", + name, config[name].core.component_module:gsub("^%a+$", { component = "external", muc = "MUC"}), name, name), 0); + end rawset(env, "__currenthost", name); -- Needs at least one setting to logically exist :) set(name or "*", "core", "defined", true); @@ -122,6 +129,10 @@ do env.host = env.Host; function env.Component(name) + if rawget(config, name) and rawget(config[name].core, "defined") and not rawget(config[name].core, "component_module") then + error(format("Component %q clashes with previously defined Host %q, for services use a sub-domain like conference.%s", + name, name, name), 0); + end set(name, "core", "component_module", "component"); -- Don't load the global modules by default set(name, "core", "load_global_modules", false); -- cgit v1.2.3 From 4d3d1789cc57c1c0b9ce8d199a95a9a412f9d723 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Feb 2010 20:37:49 +0000 Subject: configmanager: Remove debugging code accidentally committed --- core/configmanager.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/configmanager.lua b/core/configmanager.lua index 7ae472f6..a7c7c4be 100644 --- a/core/configmanager.lua +++ b/core/configmanager.lua @@ -13,8 +13,6 @@ local setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, p setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table, string.format; -local trb = debug.traceback - local eventmanager = require "core.eventmanager"; module "configmanager" -- cgit v1.2.3 From 15b32576a96cdc8b594e8c4f5b11680c3c697ea2 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Mon, 15 Feb 2010 04:15:37 +0500 Subject: mod_presence: Reflect the user's own presence back to them. --- plugins/mod_presence.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index f6ea9e6b..a39d9c19 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -63,6 +63,9 @@ local function recalc_resource_map(user) end function handle_normal_presence(origin, stanza, core_route_stanza) + if full_sessions[origin.full_jid] then -- if user is still connected + origin.send(stanza); -- reflect their presence back to them + end local roster = origin.roster; local node, host = origin.username, origin.host; local user = bare_sessions[node.."@"..host]; -- cgit v1.2.3 From b9810d3b364fce300037e65fea4a4829c6187ccc Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 18 Feb 2010 14:28:52 +0500 Subject: MUC: Allow role changes based on JIDs. (transplanted from a4879b1e6cde5aedb6bd5827d710b6dba5e8a736) --- plugins/muc/muc.lib.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index f5b82e0d..60687886 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -463,6 +463,9 @@ function room_mt:handle_to_room(origin, stanza) -- presence changes and groupcha if not item.attr.jid and item.attr.nick then -- COMPAT Workaround for Miranda sending 'nick' instead of 'jid' when changing affiliation local occupant = self._occupants[self.jid.."/"..item.attr.nick]; if occupant then item.attr.jid = occupant.jid; end + elseif not item.attr.nick and item.attr.jid then + local nick = self._jid_nick[item.attr.jid]; + if nick then item.attr.nick = select(3, jid_split(nick)); end end local reason = item.tags[1] and item.tags[1].name == "reason" and #item.tags[1] == 1 and item.tags[1][1]; if item.attr.affiliation and item.attr.jid and not item.attr.role then -- cgit v1.2.3 From 4fa466f34f5586a4faeb4f498001836c031d27e0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 20 Feb 2010 00:12:32 +0000 Subject: mod_offline: Remove from 0.7 (offline messages are handled in core at the moment) --- plugins/mod_offline.lua | 56 ------------------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 plugins/mod_offline.lua diff --git a/plugins/mod_offline.lua b/plugins/mod_offline.lua deleted file mode 100644 index c74d011e..00000000 --- a/plugins/mod_offline.lua +++ /dev/null @@ -1,56 +0,0 @@ --- Prosody IM --- Copyright (C) 2008-2009 Matthew Wild --- Copyright (C) 2008-2009 Waqas Hussain --- --- This project is MIT/X11 licensed. Please see the --- COPYING file in the source package for more information. --- - - -local datamanager = require "util.datamanager"; -local st = require "util.stanza"; -local datetime = require "util.datetime"; -local ipairs = ipairs; -local jid_split = require "util.jid".split; - -module:add_feature("msgoffline"); - -module:hook("message/offline/store", function(event) - local origin, stanza = event.origin, event.stanza; - local to = stanza.attr.to; - local node, host; - if to then - node, host = jid_split(to) - else - node, host = origin.username, origin.host; - end - - stanza.attr.stamp, stanza.attr.stamp_legacy = datetime.datetime(), datetime.legacy(); - local result = datamanager.list_append(node, host, "offline", st.preserialize(stanza)); - stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil; - - return true; -end); - -module:hook("message/offline/broadcast", function(event) - local origin = event.origin; - local node, host = origin.username, origin.host; - - local data = datamanager.list_load(node, host, "offline"); - if not data then return true; end - for _, stanza in ipairs(data) do - stanza = st.deserialize(stanza); - stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = host, stamp = stanza.attr.stamp}):up(); -- XEP-0203 - stanza:tag("x", {xmlns = "jabber:x:delay", from = host, stamp = stanza.attr.stamp_legacy}):up(); -- XEP-0091 (deprecated) - stanza.attr.stamp, stanza.attr.stamp_legacy = nil, nil; - origin.send(stanza); - end - return true; -end); - -module:hook("message/offline/delete", function(event) - local origin = event.origin; - local node, host = origin.username, origin.host; - - return datamanager.list_store(node, host, "offline", nil); -end); -- cgit v1.2.3 From aea7db64281687e6cf6ee1c1ed384c702c359f6b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 20 Feb 2010 00:52:13 +0000 Subject: mod_selftests: Obsolete, remove --- plugins/mod_selftests.lua | 61 ----------------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 plugins/mod_selftests.lua diff --git a/plugins/mod_selftests.lua b/plugins/mod_selftests.lua deleted file mode 100644 index 1f413634..00000000 --- a/plugins/mod_selftests.lua +++ /dev/null @@ -1,61 +0,0 @@ --- Prosody IM --- Copyright (C) 2008-2009 Matthew Wild --- Copyright (C) 2008-2009 Waqas Hussain --- --- This project is MIT/X11 licensed. Please see the --- COPYING file in the source package for more information. --- - -module.host = "*" -- Global module - -local st = require "util.stanza"; -local register_component = require "core.componentmanager".register_component; -local core_route_stanza = core_route_stanza; -local socket = require "socket"; -local ping_hosts = module:get_option("ping_hosts") or { "coversant.interop.xmpp.org", "djabberd.interop.xmpp.org", "djabberd-trunk.interop.xmpp.org", "ejabberd.interop.xmpp.org", "openfire.interop.xmpp.org" }; - -local open_pings = {}; - -local t_insert = table.insert; - -local log = require "util.logger".init("mod_selftests"); - -local tests_jid = "self_tests@getjabber.ath.cx"; -local host = "getjabber.ath.cx"; - -if not (tests_jid and host) then - for currhost in pairs(host) do - if currhost ~= "localhost" then - tests_jid, host = "self_tests@"..currhost, currhost; - end - end -end - -if tests_jid and host then - local bot = register_component(tests_jid, function(origin, stanza, ourhost) - local time = open_pings[stanza.attr.id]; - - if time then - log("info", "Ping reply from %s in %fs", tostring(stanza.attr.from), socket.gettime() - time); - else - log("info", "Unexpected reply: %s", stanza:pretty_print()); - end - end); - - - local our_origin = hosts[host]; - module:add_event_hook("server-started", - function () - local id = st.new_id(); - local ping_attr = { xmlns = 'urn:xmpp:ping' }; - local function send_ping(to) - log("info", "Sending ping to %s", to); - core_route_stanza(our_origin, st.iq{ to = to, from = tests_jid, id = id, type = "get" }:tag("ping", ping_attr)); - open_pings[id] = socket.gettime(); - end - - for _, host in ipairs(ping_hosts) do - send_ping(host); - end - end); -end -- cgit v1.2.3 From ee29e24da256d2e51f33dde222dc7053af5794cd Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 20 Feb 2010 00:52:28 +0000 Subject: mod_debug: Obsoleted by mod_console --- plugins/mod_debug.lua | 191 -------------------------------------------------- 1 file changed, 191 deletions(-) delete mode 100644 plugins/mod_debug.lua diff --git a/plugins/mod_debug.lua b/plugins/mod_debug.lua deleted file mode 100644 index 9f80202f..00000000 --- a/plugins/mod_debug.lua +++ /dev/null @@ -1,191 +0,0 @@ --- Prosody IM --- Copyright (C) 2008-2009 Matthew Wild --- Copyright (C) 2008-2009 Waqas Hussain --- --- This project is MIT/X11 licensed. Please see the --- COPYING file in the source package for more information. --- - -module.host = "*"; - -local connlisteners_register = require "net.connlisteners".register; - -local console_listener = { default_port = 5583; default_mode = "*l"; default_interface = "127.0.0.1" }; - -local sha256, missingglobal = require "util.hashes".sha256; - -local commands = {}; -local debug_env = {}; -local debug_env_mt = { __index = function (t, k) return rawget(_G, k) or missingglobal(k); end, __newindex = function (t, k, v) rawset(_G, k, v); end }; - -local t_insert, t_concat = table.insert, table.concat; -local t_concatall = function (t, sep) local tt = {}; for k, s in pairs(t) do tt[k] = tostring(s); end return t_concat(tt, sep); end - - -setmetatable(debug_env, debug_env_mt); - -console = {}; - -function console:new_session(conn) - local w = function(s) conn.write(s:gsub("\n", "\r\n")); end; - local session = { conn = conn; - send = function (t) w(tostring(t)); end; - print = function (t) w("| "..tostring(t).."\n"); end; - disconnect = function () conn.close(); end; - }; - - return session; -end - -local sessions = {}; - -function console_listener.listener(conn, data) - local session = sessions[conn]; - - if not session then - -- Handle new connection - session = console:new_session(conn); - sessions[conn] = session; - printbanner(session); - end - if data then - -- Handle data - (function(session, data) - if data:match("[!.]$") then - local command = data:lower(); - command = data:match("^%w+") or data:match("%p"); - if commands[command] then - commands[command](session, data); - return; - end - end - - local chunk, err = loadstring("return "..data); - if not chunk then - chunk, err = loadstring(data); - 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); - return; - end - end - - debug_env.print = session.print; - - setfenv(chunk, debug_env); - - local ret = { pcall(chunk) }; - - if not ret[1] then - session.print("Fatal error while running command, it did not complete"); - session.print("Error: "..ret[2]); - return; - end - - table.remove(ret, 1); - - local retstr = t_concatall(ret, ", "); - if retstr ~= "" then - session.print("Result: "..retstr); - else - session.print("No result, or nil"); - return; - end - end)(session, data); - end - session.send(string.char(0)); -end - -function console_listener.disconnect(conn, err) - -end - -connlisteners_register('debug', console_listener); -require "net.connlisteners".start("debug"); - --- Console commands -- --- These are simple commands, not valid standalone in Lua - -function commands.bye(session) - session.print("See you! :)"); - session.disconnect(); -end - -commands["!"] = function (session, data) - if data:match("^!!") then - session.print("!> "..session.env._); - return console_listener.listener(session.conn, session.env._); - end - local old, new = data:match("^!(.-[^\\])!(.-)!$"); - if old and new then - local ok, res = pcall(string.gsub, session.env._, old, new); - if not ok then - session.print(res) - return; - end - session.print("!> "..res); - return console_listener.listener(session.conn, res); - end - session.print("Sorry, not sure what you want"); -end - -function printbanner(session) -session.print [[ - ____ \ / _ - | _ \ _ __ ___ ___ _-_ __| |_ _ - | |_) | '__/ _ \/ __|/ _ \ / _` | | | | - | __/| | | (_) \__ \ |_| | (_| | |_| | - |_| |_| \___/|___/\___/ \__,_|\__, | - A study in simplicity |___/ - -]] -session.print("Welcome to the Prosody debug console. For a list of commands, type: help"); -session.print("You may find more help on using this console in our online documentation at "); -session.print("http://prosody.im/doc/debugconsole\n"); -end - -local byte, char = string.byte, string.char; -local gmatch, gsub = string.gmatch, string.gsub; - -local function vdecode(text, key) - local keyarr = {}; - for l in gmatch(key, ".") do t_insert(keyarr, byte(l) - 32) end - local pos, keylen = 0, #keyarr; - return (gsub(text, ".", function (letter) - if byte(letter) < 32 then return ""; end - pos = (pos%keylen)+1; - return char(((byte(letter) - 32 - keyarr[pos]) % 94) + 32); - end)); -end - -local subst = { - ["f880c08056ba7dbecb1ccfe5d7728bd6dcd654e94f7a9b21788c43397bae0bc5"] = - [=[nRYeKR$l'5Ix%u*1Mc-K}*bwv*\ $1KLMBd$KH R38`$[6}VQ@,6Qn]=]; - ["92f718858322157202ec740698c1390e47bc819e52b6a099c54c378a9f7529d6"] = - [=[V\Z5`WZ5,T$<)7LM'w3Z}M(7V'{pa) &'>0+{v)O(0M*V5K$$LL$|2wT}6 - 1as*")e!>]=]; - ["467b65edcc7c7cd70abf2136cc56abd037216a6cd9e17291a2219645be2e2216"] = - [=[i#'Z,E1-"YaHW(j/0xs]I4x&%(Jx1h&18'(exNWT D3b+K{*8}w(%D {]=]; - ["f73729d7f2fbe686243a25ac088c7e6aead3d535e081329f2817438a5c78bee5"] = - [=[,3+(Q{3+W\ftQ%wvv/C0z-l%f>ABc(vkp Date: Sun, 21 Feb 2010 16:57:06 +0000 Subject: ejabberd2prosody: Don't print passwords of imported accounts --- tools/ejabberd2prosody.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ejabberd2prosody.lua b/tools/ejabberd2prosody.lua index 7b19260d..d0c22df7 100755 --- a/tools/ejabberd2prosody.lua +++ b/tools/ejabberd2prosody.lua @@ -49,7 +49,7 @@ function vcard(node, host, stanza) end function password(node, host, password) local ret, err = dm.store(node, host, "accounts", {password = password}); - print("["..(err or "success").."] accounts: "..node.."@"..host.." = "..password); + print("["..(err or "success").."] accounts: "..node.."@"..host); end function roster(node, host, jid, item) local roster = dm.load(node, host, "roster") or {}; -- cgit v1.2.3 From 061ca9456456cca4c21af4feb0f771ff338865d7 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 22 Feb 2010 01:02:16 +0000 Subject: mod_console: Uncomment the help for server:shutdown() - thanks darkrain --- plugins/mod_console.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_console.lua b/plugins/mod_console.lua index 82045232..d8362a07 100644 --- a/plugins/mod_console.lua +++ b/plugins/mod_console.lua @@ -192,7 +192,7 @@ function commands.help(session, data) elseif section == "server" then print [[server:version() - Show the server's version number]] print [[server:uptime() - Show how long the server has been running]] - --print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]] + print [[server:shutdown(reason) - Shut down the server, with an optional reason to be broadcast to all connections]] elseif section == "config" then print [[config:reload() - Reload the server configuration. Modules may need to be reloaded for changes to take effect.]] elseif section == "console" then -- cgit v1.2.3 From 807c489de48ebe04d8c958ce50cb0444c9cf7311 Mon Sep 17 00:00:00 2001 From: Dwayne Bent Date: Sun, 21 Feb 2010 19:27:42 -0500 Subject: prosodyctl.man: Update email address --- man/prosodyctl.man | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/prosodyctl.man b/man/prosodyctl.man index e677443f..44a84145 100644 --- a/man/prosodyctl.man +++ b/man/prosodyctl.man @@ -76,4 +76,4 @@ determine if a host has been configured. More information may be found online at: \fIhttp://prosody.im/\fP .SH AUTHORS -Dwayne Bent +Dwayne Bent -- cgit v1.2.3 From 4bfd2f37a984ea4f40b5fb94e1333b4fe250e3fd Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 12 Feb 2010 21:33:22 +0000 Subject: mod_tls: Don't offer TLS on hosts that don't have any certs --- plugins/mod_tls.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/mod_tls.lua b/plugins/mod_tls.lua index 49ee18c9..54b48161 100644 --- a/plugins/mod_tls.lua +++ b/plugins/mod_tls.lua @@ -14,9 +14,11 @@ local xmlns_starttls = 'urn:ietf:params:xml:ns:xmpp-tls'; local secure_auth_only = module:get_option("c2s_require_encryption") or module:get_option("require_encryption"); local secure_s2s_only = module:get_option("s2s_require_encryption"); +local host = hosts[module.host]; + module:add_handler("c2s_unauthed", "starttls", xmlns_starttls, function (session, stanza) - if session.conn.starttls then + if session.conn.starttls and host.ssl_ctx_in then session.send(st.stanza("proceed", { xmlns = xmlns_starttls })); session:reset_stream(); if session.host and hosts[session.host].ssl_ctx_in then @@ -34,7 +36,7 @@ module:add_handler("c2s_unauthed", "starttls", xmlns_starttls, module:add_handler("s2sin_unauthed", "starttls", xmlns_starttls, function (session, stanza) - if session.conn.starttls then + if session.conn.starttls and host.ssl_ctx_in then session.sends2s(st.stanza("proceed", { xmlns = xmlns_starttls })); session:reset_stream(); if session.to_host and hosts[session.to_host].ssl_ctx_in then -- cgit v1.2.3 From 2f06e65cd617859e230cb978af8b9a57c4bab8e6 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Tue, 1 Dec 2009 22:32:37 +0500 Subject: util.sasl.plain: Allow empty authzid (thanks bjc). --- util/sasl.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/sasl.lua b/util/sasl.lua index 402f05b4..5bc6db75 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -38,7 +38,7 @@ local function new_plain(realm, credentials_handler) function object.feed(self, message) if message == "" or message == nil then return "failure", "malformed-request" end local response = message - local authorization = s_match(response, "([^%z]+)") + local authorization = s_match(response, "([^%z]*)") local authentication = s_match(response, "%z([^%z]+)%z") local password = s_match(response, "%z[^%z]+%z([^%z]+)") -- cgit v1.2.3 From 62dccf877bc7dd1eaaed5e9ebbe20b8b8b8f13ec Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Fri, 20 Nov 2009 17:12:12 +0100 Subject: Fixing some typos. --- plugins/mod_compression.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/mod_compression.lua b/plugins/mod_compression.lua index f1cae737..ec9e24ec 100644 --- a/plugins/mod_compression.lua +++ b/plugins/mod_compression.lua @@ -14,10 +14,10 @@ local xmlns_compression_protocol = "http://jabber.org/protocol/compress" local compression_stream_feature = st.stanza("compression", {xmlns=xmlns_compression_feature}):tag("method"):text("zlib"):up(); local compression_level = module:get_option("compression_level"); - -- if not defined assume admin wants best compression if compression_level == nil then compression_level = 9 end; + compression_level = tonumber(compression_level); if not compression_level or compression_level < 1 or compression_level > 9 then module:log("warn", "Invalid compression level in config: %s", tostring(compression_level)); @@ -41,7 +41,7 @@ module:add_handler({"c2s_unauthed", "c2s"}, "compress", xmlns_compression_protoc if session.compressed then local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); session.send(error_st); - session:log("warn", "Tried to establish another compression layer."); + session.log("warn", "Tried to establish another compression layer."); end -- checking if the compression method is supported @@ -56,7 +56,7 @@ module:add_handler({"c2s_unauthed", "c2s"}, "compress", xmlns_compression_protoc if status == false then local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); session.send(error_st); - session:log("error", "Failed to create zlib.deflate filter."); + session.log("error", "Failed to create zlib.deflate filter."); module:log("error", deflate_stream); return end @@ -65,7 +65,7 @@ module:add_handler({"c2s_unauthed", "c2s"}, "compress", xmlns_compression_protoc if status == false then local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("setup-failed"); session.send(error_st); - session:log("error", "Failed to create zlib.deflate filter."); + session.log("error", "Failed to create zlib.deflate filter."); module:log("error", inflate_stream); return end -- cgit v1.2.3 From cd82ebe27d0053834d644f6f8b45b445552abf8d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 21 Nov 2009 13:47:45 +0000 Subject: s2smanager: Don't tostring() the data before sending, sends2s already does this. --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index bfa3069a..381e5e53 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -402,7 +402,7 @@ function streamopened(session, attr) if send_buffer and #send_buffer > 0 then log("debug", "Sending s2s send_buffer now..."); for i, data in ipairs(send_buffer) do - session.sends2s(tostring(data)); + session.sends2s(data); send_buffer[i] = nil; end end -- cgit v1.2.3 From b74d2847c0e893c9f189c47a184f63989b4108ab Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 2 Dec 2009 18:02:47 +0000 Subject: net.httpserver: Quick fix to set the correct Content-Type on simple (string) responses, for a few known types --- net/httpserver.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/httpserver.lua b/net/httpserver.lua index ddb4475c..7366351e 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -23,6 +23,9 @@ local urlencode = function (s) return s and (s:gsub("%W", function (c) return st local log = require "util.logger".init("httpserver"); +-- TODO: Should we read this from /etc/mime.types if it exists? (startup time...?) +local mime_map = { html = "text/html", txt = "plain/text; charset=utf-8", js = "text/javascript" }; + local http_servers = {}; module "httpserver" @@ -65,6 +68,9 @@ local function send_response(request, response) resp = { "HTTP/1.0 200 OK\r\n" }; t_insert(resp, "Connection: close\r\n"); + t_insert(resp, "Content-Type: "); + t_insert(resp, mime_map[request.url.path:match("%.(%w+)")] or "application/octet-stream"); + t_insert(resp, "\r\n"); t_insert(resp, "Content-Length: "); t_insert(resp, #response); t_insert(resp, "\r\n\r\n"); -- cgit v1.2.3 From 0ab240e0eb67622774b5a1c6f5b829db3a617721 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 3 Dec 2009 01:10:08 +0000 Subject: net.dns: Port some DNS fixes to the resolver:feed() function for net.adns to use --- net/dns.lua | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/net/dns.lua b/net/dns.lua index c50e893c..bd2e6767 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -768,21 +768,18 @@ function resolver:feed(sock, packet) self.time = socket.gettime(); local response = self:decode(packet); - if response then + if response and self.active[response.header.id] + and self.active[response.header.id][response.question.raw] then --print('received response'); --self.print(response); - for i,section in pairs({ 'answer', 'authority', 'additional' }) do - for j,rr in pairs(response[section]) do - self:remember(rr, response.question[1].type); - end + for j,rr in pairs(response.answer) do + self:remember(rr, response.question[1].type); end -- retire the query local queries = self.active[response.header.id]; - if queries[response.question.raw] then - queries[response.question.raw] = nil; - end + queries[response.question.raw] = nil; if not next(queries) then self.active[response.header.id] = nil; end if not next(self.active) then self:closeall(); end -- cgit v1.2.3 From 54c77c0054c13aed866c19bec1179a886eaefea8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 3 Dec 2009 01:13:06 +0000 Subject: net.dns: Fix for blocking dns lookups to find waiting coroutines correctly (not that we use this in Prosody...) --- net/dns.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/dns.lua b/net/dns.lua index bd2e6767..888abfbb 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -745,7 +745,7 @@ function resolver:receive(rset) -- - - - - - - - - - - - - - - - - receive if not next(self.active) then self:closeall(); end -- was the query on the wanted list? - local q = response.question; + local q = response.question[1]; local cos = get(self.wanted, q.class, q.type, q.name); if cos then for co in pairs(cos) do -- cgit v1.2.3 From d3176587c4ccffcee5ba8e4e615d3f161b4fadf6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 3 Dec 2009 02:28:34 +0000 Subject: net.server_select: Fix possibility of losing data sent from a socket just before it closes (thanks Sjoerd Simons) --- net/server.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/server.lua b/net/server.lua index 6ab8ce91..2d27f769 100644 --- a/net/server.lua +++ b/net/server.lua @@ -467,7 +467,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport end local _readbuffer = function( ) -- this function reads data local buffer, err, part = receive( socket, pattern ) -- receive buffer with "pattern" - if not err or ( err == "timeout" or err == "wantread" ) then -- received something + if not err or string_len(part) > 0 then -- received something local buffer = buffer or part or "" local len = string_len( buffer ) if len > maxreadlen then -- cgit v1.2.3 From 3ad72c194c5c6bf425299d5ecaa466b83c1ddf51 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 3 Dec 2009 14:08:54 +0000 Subject: net.server_select: Make bufferlen() method return, of all things, the buffer length --- net/server.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/server.lua b/net/server.lua index 2d27f769..b58d6ee4 100644 --- a/net/server.lua +++ b/net/server.lua @@ -434,7 +434,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport handler.bufferlen = function( readlen, sendlen ) maxsendlen = sendlen or maxsendlen maxreadlen = readlen or maxreadlen - return maxreadlen, maxsendlen + return bufferlen, maxreadlen, maxsendlen end handler.lock = function( switch ) if switch == true then -- cgit v1.2.3 From c82b309e7884e380d28b4326395c3bc52b7b3d8d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 3 Dec 2009 19:18:18 +0000 Subject: net.server_select: Restore checks for wantread/timeout errors on receive --- net/server.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/server.lua b/net/server.lua index b58d6ee4..ad46071b 100644 --- a/net/server.lua +++ b/net/server.lua @@ -467,7 +467,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport end local _readbuffer = function( ) -- this function reads data local buffer, err, part = receive( socket, pattern ) -- receive buffer with "pattern" - if not err or string_len(part) > 0 then -- received something + if not err or (err == "wantread" or err == "timeout") or string_len(part) > 0 then -- received something local buffer = buffer or part or "" local len = string_len( buffer ) if len > maxreadlen then -- cgit v1.2.3 From a5dcc1d8c6f4a0d38b0ddc84033c1dabf9127fba Mon Sep 17 00:00:00 2001 From: Paul Aurich Date: Fri, 4 Dec 2009 09:48:08 -0800 Subject: Disable SSLv2 by default, it's known to be insecure. --- core/hostmanager.lua | 4 ++-- net/httpserver.lua | 1 + prosody | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/hostmanager.lua b/core/hostmanager.lua index f89eaeba..713788dd 100644 --- a/core/hostmanager.lua +++ b/core/hostmanager.lua @@ -20,8 +20,8 @@ end local incoming_s2s = _G.prosody.incoming_s2s; -- These are the defaults if not overridden in the config -local default_ssl_ctx = { mode = "client", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; }; -local default_ssl_ctx_in = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; }; +local default_ssl_ctx = { mode = "client", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none", options = "no_sslv2"; }; +local default_ssl_ctx_in = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none", options = "no_sslv2"; }; local log = require "util.logger".init("hostmanager"); diff --git a/net/httpserver.lua b/net/httpserver.lua index 7366351e..beaa3d64 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -282,6 +282,7 @@ function new_from_config(ports, handle_request, default_options) if ssl then ssl.mode = "server"; ssl.protocol = "sslv23"; + ssl.options = "no_sslv2"; end new{ port = port, interface = interface, diff --git a/prosody b/prosody index 7f69e085..1805e5b2 100755 --- a/prosody +++ b/prosody @@ -177,7 +177,7 @@ function init_global_state() -- Load SSL settings from config, and create a ctx table local global_ssl_ctx = rawget(_G, "ssl") and config.get("*", "core", "ssl"); if global_ssl_ctx then - local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; }; + local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none", options = "no_sslv2"; }; setmetatable(global_ssl_ctx, { __index = default_ssl_ctx }); end -- cgit v1.2.3 From b041ac5805169cc70f5b7de4f8e95b5d31c387d9 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 4 Dec 2009 18:59:28 +0000 Subject: componentmanager: Set ssl_ctx[_in] for components correctly, and use global SSL context if available --- core/componentmanager.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/core/componentmanager.lua b/core/componentmanager.lua index a16c01d2..c701c4d7 100644 --- a/core/componentmanager.lua +++ b/core/componentmanager.lua @@ -14,9 +14,10 @@ local jid_split = require "util.jid".split; local fire_event = require "core.eventmanager".fire_event; local events_new = require "util.events".new; local st = require "util.stanza"; -local hosts = hosts; +local prosody, hosts = prosody, prosody.hosts; +local ssl = ssl; -local pairs, type, tostring = pairs, type, tostring; +local pairs, setmetatable, type, tostring = pairs, setmetatable, type, tostring; local components = {}; @@ -73,18 +74,24 @@ end function create_component(host, component, events) -- TODO check for host well-formedness - local ssl_ctx; - if host then + local ssl_ctx, ssl_ctx_in; + if host and ssl then -- We need to find SSL context to use... -- Discussion in prosody@ concluded that -- 1 level back is usually enough by default local base_host = host:gsub("^[^%.]+%.", ""); if hosts[base_host] then ssl_ctx = hosts[base_host].ssl_ctx; + ssl_ctx_in = hosts[base_host].ssl_ctx_in; + elseif prosody.global_ssl_ctx then + -- We have no cert, and no parent host to borrow a cert from + -- Use global/default cert if there is one + ssl_ctx = ssl.newcontext(prosody.global_ssl_ctx); + ssl_ctx_in = ssl.newcontext(setmetatable({ mode = "server" }, { __index = prosody.global_ssl_ctx })); end end return { type = "component", host = host, connected = true, s2sout = {}, - ssl_ctx = ssl_ctx, events = events or events_new() }; + ssl_ctx = ssl_ctx, ssl_ctx_in = ssl_ctx_in, events = events or events_new() }; end function register_component(host, component, session) -- cgit v1.2.3 From b4eed8099cc3e3f445fb97f882ad207b0148abac Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 7 Dec 2009 18:32:06 +0000 Subject: prosody: Less strict matching for the magic 'interrupted' error --- prosody | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prosody b/prosody index 1805e5b2..c3dd979a 100755 --- a/prosody +++ b/prosody @@ -302,7 +302,7 @@ end function loop() -- Error handler for errors that make it this far local function catch_uncaught_error(err) - if type(err) == "string" and err:match("%d*: interrupted!$") then + if type(err) == "string" and err:match("interrupted!$") then return "quitting"; end -- cgit v1.2.3 From 1b3f83b6196afa283903294add20d05071f1b04a Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 9 Dec 2009 16:25:18 +0500 Subject: util.signal: Make kill() available on Solaris; really fixes #136. --- util-src/lsignal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util-src/lsignal.c b/util-src/lsignal.c index 80799e4a..30975508 100644 --- a/util-src/lsignal.c +++ b/util-src/lsignal.c @@ -348,7 +348,7 @@ static int l_kill(lua_State *L) static const struct luaL_Reg lsignal_lib[] = { {"signal", l_signal}, {"raise", l_raise}, -#ifdef _POSIX_SOURCE +#if defined _POSIX_SOURCE || (defined(sun) || defined(__sun)) {"kill", l_kill}, #endif {NULL, NULL} -- cgit v1.2.3 From 01034310135e2240fb5726370cf53bc8efa61d0d Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 10 Dec 2009 16:22:34 +0500 Subject: mod_httpserver: Return Content-Type header based on file extension. --- plugins/mod_httpserver.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/plugins/mod_httpserver.lua b/plugins/mod_httpserver.lua index 545d4faf..80835019 100644 --- a/plugins/mod_httpserver.lua +++ b/plugins/mod_httpserver.lua @@ -17,6 +17,17 @@ local http_base = config.get("*", "core", "http_path") or "www_files"; local response_400 = { status = "400 Bad Request", body = "

Bad Request

Sorry, we didn't understand your request :(" }; local response_404 = { status = "404 Not Found", body = "

Page Not Found

Sorry, we couldn't find what you were looking for :(" }; +-- TODO: Should we read this from /etc/mime.types if it exists? (startup time...?) +local mime_map = { + html = "text/html"; + htm = "text/html"; + xml = "text/xml"; + xsl = "text/xml"; + txt = "plain/text; charset=utf-8"; + js = "text/javascript"; + css = "text/css"; +}; + local function preprocess_path(path) if path:sub(1,1) ~= "/" then path = "/"..path; @@ -40,7 +51,16 @@ function serve_file(path) if not f then return response_404; end local data = f:read("*a"); f:close(); - return data; + local ext = path:match("%.([^.]*)$"); + local mime = mime_map[ext]; + if not mime then + mime = ext and "application/octet-stream" or "text/html"; + end + module:log("warn", "ext: %s, mime: %s", ext, mime); + return { + headers = { ["Content-Type"] = mime; }; + body = data; + }; end local function handle_file_request(method, body, request) -- cgit v1.2.3 From eeee71ebc14b11389266a04ac29f0adf0710a16f Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 10 Dec 2009 16:25:50 +0500 Subject: mod_httpserver: Skip returning a Content-Type when not known (application/octet-stream is not a correct default). --- plugins/mod_httpserver.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/plugins/mod_httpserver.lua b/plugins/mod_httpserver.lua index 80835019..24247596 100644 --- a/plugins/mod_httpserver.lua +++ b/plugins/mod_httpserver.lua @@ -52,11 +52,8 @@ function serve_file(path) local data = f:read("*a"); f:close(); local ext = path:match("%.([^.]*)$"); - local mime = mime_map[ext]; - if not mime then - mime = ext and "application/octet-stream" or "text/html"; - end - module:log("warn", "ext: %s, mime: %s", ext, mime); + local mime = mime_map[ext]; -- Content-Type should be nil when not known + module:log("warn", "ext: %s, mime: %s", ext or "(nil)", mime or "(nil)"); return { headers = { ["Content-Type"] = mime; }; body = data; -- cgit v1.2.3 From 4750648ca68e97469dcbcd1fba84c82708a80b09 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 10 Dec 2009 16:27:17 +0500 Subject: mod_httpserver: Read files in binary mode; fixes issues with serving binary files. --- plugins/mod_httpserver.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_httpserver.lua b/plugins/mod_httpserver.lua index 24247596..7135f479 100644 --- a/plugins/mod_httpserver.lua +++ b/plugins/mod_httpserver.lua @@ -47,7 +47,7 @@ local function preprocess_path(path) end function serve_file(path) - local f, err = open(http_base..path, "r"); + local f, err = open(http_base..path, "rb"); if not f then return response_404; end local data = f:read("*a"); f:close(); -- cgit v1.2.3 From 01e8004bf637a42eaf94174cb809f7b459517194 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 10 Dec 2009 16:34:38 +0500 Subject: mod_httpserver: Removed a log message. --- plugins/mod_httpserver.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/mod_httpserver.lua b/plugins/mod_httpserver.lua index 7135f479..c5775ba3 100644 --- a/plugins/mod_httpserver.lua +++ b/plugins/mod_httpserver.lua @@ -53,7 +53,6 @@ function serve_file(path) f:close(); local ext = path:match("%.([^.]*)$"); local mime = mime_map[ext]; -- Content-Type should be nil when not known - module:log("warn", "ext: %s, mime: %s", ext or "(nil)", mime or "(nil)"); return { headers = { ["Content-Type"] = mime; }; body = data; -- cgit v1.2.3 From 0c6835cf3a30516049962897a7b1030012c82da1 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 10 Dec 2009 16:36:33 +0500 Subject: net.httpserver: Removed mime handling (now in mod_httpserver). Unknown dynamic content is now always served as text/html. --- net/httpserver.lua | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/net/httpserver.lua b/net/httpserver.lua index beaa3d64..dae49d2a 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -23,9 +23,6 @@ local urlencode = function (s) return s and (s:gsub("%W", function (c) return st local log = require "util.logger".init("httpserver"); --- TODO: Should we read this from /etc/mime.types if it exists? (startup time...?) -local mime_map = { html = "text/html", txt = "plain/text; charset=utf-8", js = "text/javascript" }; - local http_servers = {}; module "httpserver" @@ -68,9 +65,7 @@ local function send_response(request, response) resp = { "HTTP/1.0 200 OK\r\n" }; t_insert(resp, "Connection: close\r\n"); - t_insert(resp, "Content-Type: "); - t_insert(resp, mime_map[request.url.path:match("%.(%w+)")] or "application/octet-stream"); - t_insert(resp, "\r\n"); + t_insert(resp, "Content-Type: text/html\r\n"); t_insert(resp, "Content-Length: "); t_insert(resp, #response); t_insert(resp, "\r\n\r\n"); -- cgit v1.2.3 From cc9e756839f716de96d1bf95e4cd1eded8046a3d Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 10 Dec 2009 16:52:08 +0500 Subject: mod_httpserver: Text files are text/plain, and not plain/text. --- plugins/mod_httpserver.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_httpserver.lua b/plugins/mod_httpserver.lua index c5775ba3..6b205166 100644 --- a/plugins/mod_httpserver.lua +++ b/plugins/mod_httpserver.lua @@ -23,7 +23,7 @@ local mime_map = { htm = "text/html"; xml = "text/xml"; xsl = "text/xml"; - txt = "plain/text; charset=utf-8"; + txt = "text/plain; charset=utf-8"; js = "text/javascript"; css = "text/css"; }; -- cgit v1.2.3 From 1ea522dd46db470dc59b3bdb09ffc72a32ef1d73 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 10 Dec 2009 22:13:04 +0000 Subject: net.http: Don't expect the body on redirects --- net/http.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/http.lua b/net/http.lua index 9d2f9b96..67da59de 100644 --- a/net/http.lua +++ b/net/http.lua @@ -30,7 +30,7 @@ function urldecode(s) return s and (s:gsub("%%(%x%x)", function (c) return char( local function expectbody(reqt, code) if reqt.method == "HEAD" then return nil end - if code == 204 or code == 304 then return nil end + if code == 204 or code == 304 or code == 301 then return nil end if code >= 100 and code < 200 then return nil end return 1 end -- cgit v1.2.3 From 3992d26de2a78bc803a3edad65fc57ae825737d3 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Wed, 16 Dec 2009 00:11:54 +0500 Subject: prosody: Fixed a possible nil concatenation. --- prosody | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prosody b/prosody index c3dd979a..4900349d 100755 --- a/prosody +++ b/prosody @@ -198,8 +198,8 @@ function init_global_state() cl.start(listener, { ssl = conntype ~= "tcp" and global_ssl_ctx, port = port, - interface = config.get("*", "core", option.."_interface") - or cl.get(listener).default_interface + interface = (option and config.get("*", "core", option.."_interface")) + or cl.get(listener).default_interface or config.get("*", "core", "interface"), type = conntype }); -- cgit v1.2.3 From 2043ba8fba93b356def4bf37ae5b22c0ffc86891 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 17 Dec 2009 19:01:57 +0000 Subject: xmppserver_listener: Make log messages during SRV retries clearer --- net/xmppserver_listener.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua index c7e02ec5..37f2470c 100644 --- a/net/xmppserver_listener.lua +++ b/net/xmppserver_listener.lua @@ -152,9 +152,9 @@ function xmppserver.disconnect(conn, err) local session = sessions[conn]; if session then if err and err ~= "closed" and session.srv_hosts then - (session.log or log)("debug", "s2s connection closed unexpectedly"); + (session.log or log)("debug", "s2s connection attempt failed: %s", err); if s2s_attempt_connect(session, err) then - (session.log or log)("debug", "...so we're going to try again"); + (session.log or log)("debug", "...so we're going to try another target"); return; -- Session lives for now end end -- cgit v1.2.3 From a50ea05d63b1bee4e17b9f48d728df5666e901f8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 17 Dec 2009 21:36:31 +0000 Subject: s2smanager: Send reply stream header only after checking we serve this host (sorry darkrain... :) ) --- core/s2smanager.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 381e5e53..4891b499 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -369,17 +369,17 @@ function streamopened(session, attr) session.streamid = uuid_gen(); (session.log or log)("debug", "incoming s2s received "); - send(""); - send(stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', - ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host, version=(session.version > 0 and "1.0" or nil) }):top_tag()); if session.to_host and not hosts[session.to_host] then -- Attempting to connect to a host we don't serve session:close({ condition = "host-unknown"; text = "This host does not serve "..session.to_host }); return; end + send(""); + send(stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', + ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host, version=(session.version > 0 and "1.0" or nil) }):top_tag()); if session.version >= 1.0 then local features = st.stanza("stream:features"); - + if session.to_host then hosts[session.to_host].events.fire_event("s2s-stream-features", { session = session, features = features }); else -- cgit v1.2.3 From e394e2f22252126dcb18dd38300a366e3ad6dba7 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 17 Dec 2009 18:59:29 +0000 Subject: s2smanager: Have both destroy_session and bounce_sendq accept a reason string to include in bounced stanzas --- core/s2smanager.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 4891b499..34efc254 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -54,7 +54,7 @@ function compare_srv_priorities(a,b) return a.priority < b.priority or (a.priority == b.priority and a.weight > b.weight); end -local function bounce_sendq(session) +local function bounce_sendq(session, reason) local sendq = session.sendq; if sendq then session.log("info", "sending error replies for "..#sendq.." queued stanzas because of failed outgoing connection to "..tostring(session.to_host)); @@ -72,6 +72,9 @@ local function bounce_sendq(session) reply.attr.type = "error"; reply:tag("error", {type = "cancel"}) :tag("remote-server-not-found", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up(); + if reason then + reply:tag("text", {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):text("Connection failed: "..reason):up(); + end core_process_stanza(dummy, reply); end sendq[i] = nil; @@ -491,12 +494,12 @@ function mark_connected(session) end end -function destroy_session(session) +function destroy_session(session, reason) (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); if session.direction == "outgoing" then hosts[session.from_host].s2sout[session.to_host] = nil; - bounce_sendq(session); + bounce_sendq(session, reason); elseif session.direction == "incoming" then incoming_s2s[session] = nil; end -- cgit v1.2.3 From 7bdb84764c15dcfe23c95a69182e27f033378f24 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 17 Dec 2009 19:00:36 +0000 Subject: xmppserver_listener: When a connection fails, pass the reason to destroy_session --- net/xmppserver_listener.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua index 37f2470c..4394eac5 100644 --- a/net/xmppserver_listener.lua +++ b/net/xmppserver_listener.lua @@ -159,7 +159,7 @@ function xmppserver.disconnect(conn, err) end end (session.log or log)("info", "s2s disconnected: %s->%s (%s)", tostring(session.from_host), tostring(session.to_host), tostring(err)); - s2s_destroy_session(session); + s2s_destroy_session(session, err); sessions[conn] = nil; session = nil; collectgarbage("collect"); -- cgit v1.2.3 From 5226f7e43a8b32b1d40ebea350c6267fef6f94de Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 17 Dec 2009 21:50:02 +0000 Subject: s2smanager: Give reasons to destroy_session in more cases, including when DNS lookup fails --- core/s2smanager.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 34efc254..f444e843 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -227,7 +227,7 @@ function attempt_connection(host_session, err) if not ok then if not attempt_connection(host_session, err) then -- No more attempts will be made - destroy_session(host_session); + destroy_session(host_session, err); end end end, "_xmpp-server._tcp."..connect_host..".", "SRV"); @@ -287,7 +287,7 @@ function try_connect(host_session, connect_host, connect_port) log("debug", "DNS lookup failed to get a response for %s", connect_host); if not 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); - destroy_session(host_session); -- End of the line, we can't + destroy_session(host_session, "DNS resolution failed"); -- End of the line, we can't end end end, connect_host, "A", "IN"); -- cgit v1.2.3 From 566e3c4ac12d22073c7e376a6735af6ca4b2e52e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 21 Dec 2009 22:00:49 +0000 Subject: mod_saslauth: Requiring c2s encryption means requiring c2s encryption... thanks Flo --- plugins/mod_saslauth.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index c0f57cd7..e248479b 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -115,6 +115,9 @@ local function sasl_handler(session, stanza) if not session.sasl_handler then return session.send(build_reply("failure", "invalid-mechanism")); end + if secure_auth_only and not session.secure then + return session.send(build_reply("failure", "encryption-required")); + end elseif not session.sasl_handler then return; -- FIXME ignoring out of order stanzas because ejabberd does end -- cgit v1.2.3 From 7439c858d52879156f76f073d9dc705c3f70d57d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 1 Jan 2010 21:32:23 +0000 Subject: mod_httpserver: Rudimentary directory detection, return forbidden instead of causing a traceback (since commit 0325f241a26c) --- plugins/mod_httpserver.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/mod_httpserver.lua b/plugins/mod_httpserver.lua index 6b205166..c12f1c05 100644 --- a/plugins/mod_httpserver.lua +++ b/plugins/mod_httpserver.lua @@ -15,6 +15,7 @@ local t_concat = table.concat; local http_base = config.get("*", "core", "http_path") or "www_files"; local response_400 = { status = "400 Bad Request", body = "

Bad Request

Sorry, we didn't understand your request :(" }; +local response_403 = { status = "403 Forbidden", body = "

Forbidden

You don't have permission to view the contents of this directory :(" }; local response_404 = { status = "404 Not Found", body = "

Page Not Found

Sorry, we couldn't find what you were looking for :(" }; -- TODO: Should we read this from /etc/mime.types if it exists? (startup time...?) @@ -51,6 +52,9 @@ function serve_file(path) if not f then return response_404; end local data = f:read("*a"); f:close(); + if not data then + return response_403; + end local ext = path:match("%.([^.]*)$"); local mime = mime_map[ext]; -- Content-Type should be nil when not known return { -- cgit v1.2.3 From 67509f371ad0116a6c13b6f715d9bd3f769e6807 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 3 Jan 2010 03:36:40 +0000 Subject: prosodyctl: Gracefully handle a missing stty command, and fall back to ANSI escape sequences --- prosodyctl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/prosodyctl b/prosodyctl index 522ebde9..a44dfada 100755 --- a/prosodyctl +++ b/prosodyctl @@ -137,18 +137,33 @@ function show_usage(usage, desc) end local function getchar(n) - os.execute("stty raw -echo"); - local ok, char = pcall(io.read, n or 1); - os.execute("stty sane"); + local stty_ret = os.execute("stty raw -echo 2>/dev/null"); + local ok, char; + if stty_ret == 0 then + ok, char = pcall(io.read, n or 1); + os.execute("stty sane"); + else + ok, char = pcall(io.read, "*l"); + if ok then + char = char:sub(1, n or 1); + end + end if ok then return char; end end local function getpass() - os.execute("stty -echo"); + local stty_ret = os.execute("stty -echo 2>/dev/null"); + if stty_ret ~= 0 then + io.write("\027[08m"); -- ANSI 'hidden' text attribute + end local ok, pass = pcall(io.read, "*l"); - os.execute("stty sane"); + if stty_ret == 0 then + os.execute("stty sane"); + else + io.write("\027[00m"); + end io.write("\n"); if ok then return pass; -- cgit v1.2.3 From 92b2d54b4b515f72bdeff377bac640dd0ac3cae3 Mon Sep 17 00:00:00 2001 From: Paul Aurich Date: Sun, 3 Jan 2010 11:26:36 -0800 Subject: s2smanager: Stamp a 'to' on the reply stream:stream. This makes prosody happy. --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index f444e843..40fd6795 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -379,7 +379,7 @@ function streamopened(session, attr) end send(""); send(stanza("stream:stream", { xmlns='jabber:server', ["xmlns:db"]='jabber:server:dialback', - ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host, version=(session.version > 0 and "1.0" or nil) }):top_tag()); + ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.to_host, to=session.from_host, version=(session.version > 0 and "1.0" or nil) }):top_tag()); if session.version >= 1.0 then local features = st.stanza("stream:features"); -- cgit v1.2.3 From df3d5883caa974994f85145642a41088f5f12693 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 7 Jan 2010 01:26:01 +0000 Subject: net.dns: Make sure math.randomseed() gets passed an integer --- net/dns.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/dns.lua b/net/dns.lua index 888abfbb..ca0ec622 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -183,7 +183,7 @@ end function dns.random(...) -- - - - - - - - - - - - - - - - - - - dns.random - math.randomseed(10000*socket.gettime()); + math.randomseed(math.floor(10000*socket.gettime())); dns.random = math.random; return dns.random(...); end -- cgit v1.2.3 From 0ac9242e025f4d799b5645957f72547eff06f77f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 9 Jan 2010 07:12:30 +0000 Subject: prosody: net_activate_ports: Accept strings as well as numbers for specifying ports --- prosody | 1 + 1 file changed, 1 insertion(+) diff --git a/prosody b/prosody index 4900349d..e4e5bc47 100755 --- a/prosody +++ b/prosody @@ -192,6 +192,7 @@ function init_global_state() log("error", "core."..option.." is not a table"); else for _, port in ipairs(ports) do + port = tonumber(port); if type(port) ~= "number" then log("error", "Non-numeric "..option.."_ports: "..tostring(port)); else -- cgit v1.2.3 From 96c4c4f090617ead071487dce924517cd281b7a6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 10 Jan 2010 00:28:48 +0000 Subject: util.signal: Queue up multiple signals, instead of trampling on the previous debug hook (and never clearing our own) --- util-src/lsignal.c | 64 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/util-src/lsignal.c b/util-src/lsignal.c index 30975508..e4dffa02 100644 --- a/util-src/lsignal.c +++ b/util-src/lsignal.c @@ -27,6 +27,7 @@ */ #include +#include #include "lua.h" #include "lauxlib.h" @@ -149,43 +150,66 @@ static const struct lua_signal lua_signals[] = { {NULL, 0} }; -static int Nsig = 0; static lua_State *Lsig = NULL; static lua_Hook Hsig = NULL; static int Hmask = 0; static int Hcount = 0; +static struct signal_event +{ + int Nsig; + struct signal_event *next_event; +} *signal_queue = NULL; + +static struct signal_event *last_event = NULL; + static void sighook(lua_State *L, lua_Debug *ar) { lua_pushstring(L, LUA_SIGNAL); lua_gettable(L, LUA_REGISTRYINDEX); - lua_pushnumber(L, Nsig); - lua_gettable(L, -2); - lua_call(L, 0, 0); + struct signal_event *event; + while((event = signal_queue)) + { + lua_pushnumber(L, event->Nsig); + lua_gettable(L, -2); + lua_call(L, 0, 0); + signal_queue = event->next_event; + free(event); + }; - /* set the old hook */ + lua_pop(L, 1); /* pop lua_signal table */ + + /* restore the old hook */ lua_sethook(L, Hsig, Hmask, Hcount); } static void handle(int sig) { - Hsig = lua_gethook(Lsig); - Hmask = lua_gethookmask(Lsig); - Hcount = lua_gethookcount(Lsig); - Nsig = sig; - - lua_sethook(Lsig, sighook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); - /* - switch (sig) + if(!signal_queue) + { + /* Store the existing debug hook (if any) and its parameters */ + Hsig = lua_gethook(Lsig); + Hmask = lua_gethookmask(Lsig); + Hcount = lua_gethookcount(Lsig); + + signal_queue = malloc(sizeof(struct signal_event)); + signal_queue->Nsig = sig; + signal_queue->next_event = NULL; + + last_event = signal_queue; + + /* Set our new debug hook */ + lua_sethook(Lsig, sighook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); + } + else { - case SIGABRT: ; - case SIGFPE: ; - case SIGILL: ; - case SIGINT: ; - case SIGSEGV: ; - case SIGTERM: ; - } */ + last_event->next_event = malloc(sizeof(struct signal_event)); + last_event->next_event->Nsig = sig; + last_event->next_event->next_event = NULL; + + last_event = last_event->next_event; + } } /* -- cgit v1.2.3 From 45db3bf84a5855b2b5cdad5ee8ec584103796a7a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 10 Jan 2010 00:31:38 +0000 Subject: util.signal: Update version in header, and author's email --- util-src/lsignal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util-src/lsignal.c b/util-src/lsignal.c index e4dffa02..78c74d15 100644 --- a/util-src/lsignal.c +++ b/util-src/lsignal.c @@ -1,9 +1,9 @@ /* * lsignal.h -- Signal Handler Library for Lua * - * Version: 1.000 + * Version: 1.000+changes * - * Copyright (C) 2007 Patrick J. Donnelly (batrick@unm.edu) + * Copyright (C) 2007 Patrick J. Donnelly (batrick@batbytes.com) * * This software is distributed under the same license as Lua 5.0: * -- cgit v1.2.3 From 2aab3bf617feb6d3ba4508b0c505ffaaf117f28c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 10 Jan 2010 03:54:29 +0000 Subject: util.signal: Restore the old debug hook earlier, just in case we receive another signal between clearing the signal queue and restoring it --- util-src/lsignal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/util-src/lsignal.c b/util-src/lsignal.c index 78c74d15..b6a36e25 100644 --- a/util-src/lsignal.c +++ b/util-src/lsignal.c @@ -165,6 +165,9 @@ static struct signal_event *last_event = NULL; static void sighook(lua_State *L, lua_Debug *ar) { + /* restore the old hook */ + lua_sethook(L, Hsig, Hmask, Hcount); + lua_pushstring(L, LUA_SIGNAL); lua_gettable(L, LUA_REGISTRYINDEX); @@ -180,8 +183,6 @@ static void sighook(lua_State *L, lua_Debug *ar) lua_pop(L, 1); /* pop lua_signal table */ - /* restore the old hook */ - lua_sethook(L, Hsig, Hmask, Hcount); } static void handle(int sig) -- cgit v1.2.3 From 886d6d168fdc777c4017011e6acaf382aa628456 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 10 Jan 2010 23:49:38 +0000 Subject: mod_posix: Lock pidfile when in use, shut down if we can't write or lock the pidfile --- plugins/mod_posix.lua | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua index b75b9610..8b0bd399 100644 --- a/plugins/mod_posix.lua +++ b/plugins/mod_posix.lua @@ -19,6 +19,8 @@ end local logger_set = require "util.logger".setwriter; +local lfs = require "lfs"; + local prosody = _G.prosody; module.host = "*"; -- we're a global module @@ -59,28 +61,37 @@ module:add_event_hook("server-starting", function () end end); -local pidfile_written; +local pidfile; +local pidfile_handle; local function remove_pidfile() - if pidfile_written then - os.remove(pidfile_written); - pidfile_written = nil; + if pidfile_handle then + pidfile_handle:close(); + os.remove(pidfile); + pidfile, pidfile_handle = nil, nil; end end local function write_pidfile() - if pidfile_written then + if pidfile_handle then remove_pidfile(); end - local pidfile = module:get_option("pidfile"); + pidfile = module:get_option("pidfile"); if pidfile then - local pf, err = io.open(pidfile, "w+"); - if not pf then - module:log("error", "Couldn't write pidfile; %s", err); + pidfile_handle, err = io.open(pidfile, "a+"); + if not pidfile_handle then + module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err); + prosody.shutdown("Couldn't write pidfile"); else - pf:write(tostring(pposix.getpid())); - pf:close(); - pidfile_written = pidfile; + if not lfs.lock(pidfile_handle, "w") then -- Exclusive lock + local other_pid = pidfile_handle:read("*a"); + module:log("error", "Another Prosody instance seems to be running with PID %s, quitting", other_pid); + pidfile_handle = nil; + prosody.shutdown("Prosody already running"); + else + pidfile_handle:write(tostring(pposix.getpid())); + pidfile_handle:flush(); + end end end end -- cgit v1.2.3 From 815222417a3a085c87380f429f0507f43eedd2e5 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 11 Jan 2010 00:14:33 +0000 Subject: util.prosodyctl: Report Prosody as not running if the pidfile isn't locked --- util/prosodyctl.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index b24e194d..4d2c68ee 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -12,6 +12,7 @@ local encodings = require "util.encodings"; local stringprep = encodings.stringprep; local usermanager = require "core.usermanager"; local signal = require "util.signal"; +local lfs = require "lfs"; local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep; @@ -64,11 +65,17 @@ function getpid() return false, "no-pidfile"; end - local file, err = io.open(pidfile); + local file, err = io.open(pidfile, "w"); if not file then return false, "pidfile-read-failed", err; end + local locked, err = lfs.lock(file, "w"); + if locked then + file:close(); + return false, "pidfile-not-locked"; + end + local pid = tonumber(file:read("*a")); file:close(); @@ -82,7 +89,7 @@ end function isrunning() local ok, pid, err = _M.getpid(); if not ok then - if pid == "pidfile-read-failed" then + if pid == "pidfile-read-failed" or pid == "pidfile-not-locked" then -- Report as not running, since we can't open the pidfile -- (it probably doesn't exist) return true, false; -- cgit v1.2.3 From 275444ab8281377a6711f99d806bdc09bb907299 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 13 Jan 2010 00:03:22 +0000 Subject: mod_posix: Adjust file open mode depending on whether file exists (take that fopen designers!!!) --- plugins/mod_posix.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua index 8b0bd399..ed0dbd87 100644 --- a/plugins/mod_posix.lua +++ b/plugins/mod_posix.lua @@ -20,6 +20,7 @@ end local logger_set = require "util.logger".setwriter; local lfs = require "lfs"; +local stat = lfs.attributes; local prosody = _G.prosody; @@ -78,7 +79,8 @@ local function write_pidfile() end pidfile = module:get_option("pidfile"); if pidfile then - pidfile_handle, err = io.open(pidfile, "a+"); + local mode = stat(pidfile) and "r+" or "w+"; + pidfile_handle, err = io.open(pidfile, mode); if not pidfile_handle then module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err); prosody.shutdown("Couldn't write pidfile"); -- cgit v1.2.3 From 24aaf5e7884fbecd439c841fdce98292e7c6429f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 13 Jan 2010 00:04:38 +0000 Subject: prosodyctl: Use mode r+ for opening the file so 1) it fails if the file doesn't exist 2) we have write access to lock it --- util/prosodyctl.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua index 4d2c68ee..7ce6c513 100644 --- a/util/prosodyctl.lua +++ b/util/prosodyctl.lua @@ -65,7 +65,7 @@ function getpid() return false, "no-pidfile"; end - local file, err = io.open(pidfile, "w"); + local file, err = io.open(pidfile, "r+"); if not file then return false, "pidfile-read-failed", err; end -- cgit v1.2.3 From 15fb8092199a74af4da602d2c93ca3f0a825d21e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 28 Jan 2010 18:10:20 +0000 Subject: util.dependencies: Load luarocks.loader/luarocks.require --- prosody | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/prosody b/prosody index e4e5bc47..40aeac5e 100755 --- a/prosody +++ b/prosody @@ -31,7 +31,9 @@ if CFG_DATADIR then end -- Required to be able to find packages installed with luarocks -pcall(require, "luarocks.require") +if not pcall(require, "luarocks.loader") then -- Try LuaRocks 2.x + pcall(require, "luarocks.require") -- Try LuaRocks 1.x +end -- Replace require with one that doesn't pollute _G do -- cgit v1.2.3 From c9740f1fcf80ed25c1ab18bfba990c6d4fbe6b15 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 3 Mar 2010 20:12:24 +0000 Subject: prosodyctl: Fix to load LuaRocks 2.x if we have it --- prosodyctl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/prosodyctl b/prosodyctl index a44dfada..89368a78 100755 --- a/prosodyctl +++ b/prosodyctl @@ -30,7 +30,10 @@ if CFG_DATADIR then end -- Required to be able to find packages installed with luarocks -pcall(require, "luarocks.require") +if not pcall(require, "luarocks.loader") then -- Try LuaRocks 2.x + pcall(require, "luarocks.require") -- Try LuaRocks 1.x +end + config = require "core.configmanager" -- cgit v1.2.3 From d169b18350f21065da6455a51185759c356019c5 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 30 Jan 2010 16:42:27 +0000 Subject: s2smanager: Make require_s2s_encryption do what it says on the tin --- core/s2smanager.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 40fd6795..c9a26e04 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -449,6 +449,16 @@ function verify_dialback(id, to, from, key) end function make_authenticated(session, host) + if not session.secure then + local local_host = session.direction == "incoming" and session.to_host or session.from_host; + if config.get(local_host, "core", "require_s2s_encryption")) then + session:close({ + condition = "policy-violation", + text = "Encrypted server-to-server communication is required but was not " + ..((session.direction == "outgoing" and "offered") or "used") + }); + end + end if session.type == "s2sout_unauthed" then session.type = "s2sout"; elseif session.type == "s2sin_unauthed" then -- cgit v1.2.3 From 54f4000c5a097e782c5619f13710748c3b8e00df Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 30 Jan 2010 17:00:47 +0000 Subject: s2smanager: require_s2s_encryption -> s2s_require_encryption --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index c9a26e04..74cd8593 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -451,7 +451,7 @@ end function make_authenticated(session, host) if not session.secure then local local_host = session.direction == "incoming" and session.to_host or session.from_host; - if config.get(local_host, "core", "require_s2s_encryption")) then + if config.get(local_host, "core", "s2s_require_encryption")) then session:close({ condition = "policy-violation", text = "Encrypted server-to-server communication is required but was not " -- cgit v1.2.3 From 0b4f0121a1f2692933e80155514721811daccee2 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 30 Jan 2010 18:45:46 +0000 Subject: s2smanager: Fix syntax error) --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 74cd8593..10c27746 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -451,7 +451,7 @@ end function make_authenticated(session, host) if not session.secure then local local_host = session.direction == "incoming" and session.to_host or session.from_host; - if config.get(local_host, "core", "s2s_require_encryption")) then + if config.get(local_host, "core", "s2s_require_encryption") then session:close({ condition = "policy-violation", text = "Encrypted server-to-server communication is required but was not " -- cgit v1.2.3 From 0c333f589c00699e7a3f84b5c21b3e8854bfb165 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 31 Jan 2010 15:39:49 +0000 Subject: mod_tls: Set the sslctx on outgoing connections (possibly the cause of outgoing s2s connections not being encrypted) --- plugins/mod_tls.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/mod_tls.lua b/plugins/mod_tls.lua index 8a450803..cceef308 100644 --- a/plugins/mod_tls.lua +++ b/plugins/mod_tls.lua @@ -90,6 +90,8 @@ module:hook_stanza(xmlns_starttls, "proceed", function (session, stanza) module:log("debug", "Proceeding with TLS on s2sout..."); local format, to_host, from_host = string.format, session.to_host, session.from_host; + local ssl_ctx = session.from_host and hosts[session.from_host].ssl_ctx or global_ssl_ctx; + session.conn.set_sslctx(ssl_ctx); session:reset_stream(); session.conn.starttls(true); session.secure = false; -- cgit v1.2.3 From 15d2f14a245439cc470fe15c88ab9243a46dedb1 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 18 Feb 2010 17:10:45 +0000 Subject: TODO: Update --- TODO | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index a3266d82..c0d2b959 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,16 @@ -- Ad-hoc commands -- Clustering +== 0.8 == +- Ad-hoc commands: + http://code.google.com/p/prosody-modules/wiki/mod_adhoc + http://code.google.com/p/prosody-modules/wiki/mod_adhoc_cmd_admin + http://code.google.com/p/prosody-modules/wiki/mod_adhoc_cmd_ping + http://code.google.com/p/prosody-modules/wiki/mod_adhoc_cmd_uptime + - Pubsub +- Data storage backend abstraction +== 0.9 == +- Clustering +== 1.0 == +- Web interface? +- World domination -- cgit v1.2.3 From ebd3257e27c5eb16814a5f4e702e3d0a0d8e95be Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 3 Mar 2010 20:41:17 +0000 Subject: TODO: Update for the fact that 0.7 is done --- TODO | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TODO b/TODO index c0d2b959..17cf4e67 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,5 @@ +== 0.7 == +DONE: http://blog.prosody.im/prosody-0-7-0rc1-available-for-testing/ == 0.8 == - Ad-hoc commands: http://code.google.com/p/prosody-modules/wiki/mod_adhoc -- cgit v1.2.3 From ebff0897e282e55bd4e0bcb00ed5097b822c8ab3 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 18 Feb 2010 17:12:37 +0000 Subject: HACKERS: Update --- HACKERS | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/HACKERS b/HACKERS index a8585af0..40cbd8aa 100644 --- a/HACKERS +++ b/HACKERS @@ -5,6 +5,8 @@ involved you can join us on our mailing list and discussion rooms. More information on these at http://prosody.im/discuss Patches are welcome, though before sending we would appreciate if you read -docs/coding_style.txt for guidelines on how to format your code, and are -comfortable with copyright of contributions being assigned to the core -developers. +docs/coding_style.txt for guidelines on how to format your code, and other tips. + +Documentation for developers can be found at http://prosody.im/doc/developers + +Have fun :) -- cgit v1.2.3 From 5cb8c4b615b2ca3844d3f6a9a11ed3748d3c5977 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 18 Feb 2010 18:57:37 +0000 Subject: README: Update URL for installation docs --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index a28f135d..3cffea49 100644 --- a/README +++ b/README @@ -32,6 +32,6 @@ Mailing lists: ## Installation See the accompanying INSTALL file for help on building Prosody from source. Alternatively -see our guide at http://prosody.im/install +see our guide at http://prosody.im/doc/install -- cgit v1.2.3 From 1e2242d3194b34c8451985dec895d30217a82d2f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 19 Feb 2010 02:58:34 +0000 Subject: net.http: Port commit 2f235c57d713 to net.http to fix headers in responses (thanks dersd) --- net/http.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/net/http.lua b/net/http.lua index 67da59de..c1cfae02 100644 --- a/net/http.lua +++ b/net/http.lua @@ -73,22 +73,31 @@ local function request_reader(request, data, startpos) elseif request.state == "headers" then print("Reading headers...") local pos = startpos; - local headers = request.responseheaders or {}; + local headers, headers_complete = request.responseheaders; + if not headers then + headers = {}; + request.responseheaders = headers; + end for line in data:sub(startpos, -1):gmatch("(.-)\r\n") do startpos = startpos + #line + 2; local k, v = line:match("(%S+): (.+)"); if k and v then headers[k:lower()] = v; - print("Header: "..k:lower().." = "..v); + --print("Header: "..k:lower().." = "..v); elseif #line == 0 then - request.responseheaders = headers; + headers_complete = true; break; else print("Unhandled header line: "..line); end end + if not headers_complete then return; end -- Reached the end of the headers - request.state = "body"; + if not expectbody(request, request.code) then + request.callback(nil, request.code, request); + return; + end + request.state = "body"; if #data > startpos then return request_reader(request, data, startpos); end @@ -102,7 +111,7 @@ local function request_reader(request, data, startpos) request.code, request.responseversion = code, http; - if request.onlystatus or not expectbody(request, code) then + if request.onlystatus then if request.callback then request.callback(nil, code, request); end -- cgit v1.2.3 From 79382a23050436d490bfd030ca2cc200f371bd2b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 19 Feb 2010 03:21:20 +0000 Subject: net.http: Don't re-destroy a request when the connection is closed --- net/http.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/net/http.lua b/net/http.lua index c1cfae02..b533caae 100644 --- a/net/http.lua +++ b/net/http.lua @@ -43,6 +43,7 @@ local function request_reader(request, data, startpos) elseif request.state ~= "completed" then -- Error.. connection was closed prematurely request.callback("connection-closed", 0, request); + return; end destroy_request(request); request.body = nil; -- cgit v1.2.3 From ead6371721b1d64f5dc7e3446222e002b3c2ced6 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 19 Feb 2010 03:21:50 +0000 Subject: net.http: Close connection when invalid status line is received from the server --- net/http.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/http.lua b/net/http.lua index b533caae..bd08bdad 100644 --- a/net/http.lua +++ b/net/http.lua @@ -107,7 +107,10 @@ local function request_reader(request, data, startpos) local http, code, text, linelen = data:match("^HTTP/(%S+) (%d+) (.-)\r\n()", startpos); code = tonumber(code); if not code then - return request.callback("invalid-status-line", 0, request); + log("warn", "Invalid HTTP status line, telling callback then closing"); + local ret = request.callback("invalid-status-line", 0, request); + destroy_request(request); + return ret; end request.code, request.responseversion = code, http; -- cgit v1.2.3 From 032e7149c60e514d81140d2ddc531ed97a44b4be Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Wed, 3 Mar 2010 20:52:30 +0000 Subject: net.http: destroy_request(): Pass request.handler to disconnect() listener to fix small leak --- net/http.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/http.lua b/net/http.lua index bd08bdad..09b04e61 100644 --- a/net/http.lua +++ b/net/http.lua @@ -213,7 +213,7 @@ end function destroy_request(request) if request.conn then request.handler.close() - listener.disconnect(request.conn, "closed"); + listener.disconnect(request.handler, "closed"); end end -- cgit v1.2.3 From 063347c86ac52f02f49421df7b4043be523c9208 Mon Sep 17 00:00:00 2001 From: Tobias Markmann Date: Fri, 15 Jan 2010 18:30:33 +0100 Subject: util.signal: Using stdlib.h instead of malloc.h. --- util-src/lsignal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util-src/lsignal.c b/util-src/lsignal.c index b6a36e25..fe35e8b7 100644 --- a/util-src/lsignal.c +++ b/util-src/lsignal.c @@ -27,7 +27,7 @@ */ #include -#include +#include #include "lua.h" #include "lauxlib.h" -- cgit v1.2.3 From eda3ad332699393bed8331ebddc3c57e36a31fcb Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 19 Feb 2010 03:23:51 +0000 Subject: net.httpclient_listener: Don't notify request of closed connection if the close was initiated by us --- net/httpclient_listener.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/httpclient_listener.lua b/net/httpclient_listener.lua index 69b7946b..a688a3e0 100644 --- a/net/httpclient_listener.lua +++ b/net/httpclient_listener.lua @@ -30,7 +30,7 @@ end function httpclient.disconnect(conn, err) local request = requests[conn]; - if request then + if request and err ~= "closed" then request:reader(nil); end requests[conn] = nil; -- cgit v1.2.3 From 87ff54c75266ffa37f716d1c7a542e956bbe54b3 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 19 Feb 2010 03:30:27 +0000 Subject: s2smanager: Use s2smanager log() if session doesn't have a logger (thanks Flo) --- core/s2smanager.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 10c27746..aabfddd6 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -303,7 +303,7 @@ function try_connect(host_session, connect_host, connect_port) end function make_connect(host_session, connect_host, connect_port) - host_session.log("info", "Beginning new connection attempt to %s (%s:%d)", host_session.to_host, connect_host, connect_port); + (host_session.log or log)("info", "Beginning new connection attempt to %s (%s:%d)", host_session.to_host, connect_host, connect_port); -- Ok, we're going to try to connect local from_host, to_host = host_session.from_host, host_session.to_host; -- cgit v1.2.3 From 836da37747ac1d76aa76dbc38354daac8c79bb40 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 4 Mar 2010 02:20:17 +0500 Subject: stanza_router: Allow non-jabber:client elements after auth, before bind. --- core/stanza_router.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/stanza_router.lua b/core/stanza_router.lua index b025511e..cd7c650b 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -36,7 +36,7 @@ function core_process_stanza(origin, stanza) end end - if origin.type == "c2s" then + if origin.type == "c2s" and stanza.attr.xmlns == "jabber:client" then if not origin.full_jid and not(stanza.name == "iq" and stanza.attr.type == "set" and stanza.tags[1] and stanza.tags[1].name == "bind" and stanza.tags[1].attr.xmlns == "urn:ietf:params:xml:ns:xmpp-bind") then -- cgit v1.2.3 From 5d9b9b6b30f06a3e3aa957279357dd42ae19ddf4 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 4 Mar 2010 02:22:45 +0500 Subject: stanza_router: Don't send error replies for stanzas of type 'error' and 'result' on unbound authenticated connections. --- core/stanza_router.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/stanza_router.lua b/core/stanza_router.lua index cd7c650b..b5b1b45f 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -41,7 +41,9 @@ function core_process_stanza(origin, stanza) and not(stanza.name == "iq" and stanza.attr.type == "set" and stanza.tags[1] and stanza.tags[1].name == "bind" and stanza.tags[1].attr.xmlns == "urn:ietf:params:xml:ns:xmpp-bind") then -- authenticated client isn't bound and current stanza is not a bind request - origin.send(st.error_reply(stanza, "auth", "not-authorized")); -- FIXME maybe allow stanzas to account or server + if stanza.attr.type ~= "result" and stanza.attr.type ~= "error" then + origin.send(st.error_reply(stanza, "auth", "not-authorized")); -- FIXME maybe allow stanzas to account or server + end return; end -- cgit v1.2.3 From 80de22c29bae5672eae6b8a96a4f0a92dca7a28c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 6 Mar 2010 18:45:09 +0000 Subject: net.xmppserver_listener: Clarify log message (for nil/false) --- net/xmppserver_listener.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua index c9746ee1..8a3886ad 100644 --- a/net/xmppserver_listener.lua +++ b/net/xmppserver_listener.lua @@ -176,7 +176,7 @@ function xmppserver.ondisconnect(conn, err) return; -- 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)); + (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); sessions[conn] = nil; session = nil; -- cgit v1.2.3 From 7b445486a0173b2d2b96e5639de02d81fc10a0f8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 8 Mar 2010 02:13:41 +0000 Subject: sessionmanager, s2smanager: Destroyed sessions are now simply resting (not dead) until they are collected - prevents a whole class of tracebacks --- core/s2smanager.lua | 30 +++++++++++++++++++++--------- core/sessionmanager.lua | 26 ++++++++++++++++++-------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 16ede7b6..0435bea9 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -16,8 +16,10 @@ local socket = require "socket"; local format = string.format; local t_insert, t_sort = table.insert, table.sort; local get_traceback = debug.traceback; -local tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber - = tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber; +local tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber, + setmetatable + = tostring, pairs, ipairs, getmetatable, newproxy, error, tonumber, + setmetatable; local idna_to_ascii = require "util.encodings".idna.to_ascii; local connlisteners_get = require "net.connlisteners".get; @@ -510,7 +512,22 @@ function mark_connected(session) end end -local function null_data_handler(conn, data) log("debug", "Discarding data from destroyed s2s session: %s", data); end +local resting_session = { -- Resting, not dead + destroyed = true; + }; resting_session.__index = resting_session; + +function retire_session(session) + local log = session.log or log; + for k in pairs(session) do + if k ~= "trace" and k ~= "log" and k ~= "id" then + session[k] = nil; + end + end + + function session.send(data) log("debug", "Discarding data sent to resting session: %s", tostring(data)); end + function session.data(data) log("debug", "Discarding data received from resting session: %s", tostring(data)); end + return setmetatable(session, resting_session); +end function destroy_session(session, reason) (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); @@ -522,12 +539,7 @@ function destroy_session(session, reason) incoming_s2s[session] = nil; end - for k in pairs(session) do - if k ~= "trace" then - session[k] = nil; - end - end - session.data = null_data_handler; + retire_session(session); -- Clean session until it is GC'd end return _M; diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 29adcfbb..a2c6ed95 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -8,7 +8,7 @@ -local tonumber, tostring = tonumber, tostring; +local tonumber, tostring, setmetatable = tonumber, tostring, setmetatable; local ipairs, pairs, print, next= ipairs, pairs, print, next; local format = import("string", "format"); @@ -66,7 +66,22 @@ function new_session(conn) return session; end -local function null_data_handler(conn, data) log("debug", "Discarding data from destroyed c2s session: %s", data); end +local resting_session = { -- Resting, not dead + destroyed = true; + }; resting_session.__index = resting_session; + +function retire_session(session) + local log = session.log or log; + for k in pairs(session) do + if k ~= "trace" and k ~= "log" and k ~= "id" then + session[k] = nil; + end + end + + function session.send(data) log("debug", "Discarding data sent to resting session: %s", tostring(data)); end + function session.data(data) log("debug", "Discarding data received from resting session: %s", tostring(data)); end + return setmetatable(session, resting_session); +end function destroy_session(session, err) (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); @@ -85,12 +100,7 @@ function destroy_session(session, err) hosts[session.host].events.fire_event("resource-unbind", {session=session, error=err}); end - for k in pairs(session) do - if k ~= "trace" then - session[k] = nil; - end - end - session.data = null_data_handler; + retire_session(session); end function make_authenticated(session, username) -- cgit v1.2.3 From 8e4f70c4a2db2fd6e2a35ebefd63a9177b44fc31 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 11 Mar 2010 01:04:19 +0000 Subject: sessionmanager, s2smanager: Close session on
--- core/s2smanager.lua | 7 ++----- core/sessionmanager.lua | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 0435bea9..15d981d4 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -434,11 +434,8 @@ function streamopened(session, attr) end function streamclosed(session) - (session.log or log)("debug", ""); - if session.sends2s then - session.sends2s(""); - end - session.notopen = true; + (session.log or log)("debug", "Received "); + session:close(); end function initiate_dialback(session) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index a2c6ed95..b65e866f 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -211,8 +211,8 @@ function streamopened(session, attr) end function streamclosed(session) - session.send(""); - session.notopen = true; + session.log("debug", "Received "); + session:close(); end function send_to_available_resources(user, host, stanza) -- cgit v1.2.3 From 82d5e5fd0ce5e5c7682d8f0211a352fd8bd97efd Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 02:56:57 +0000 Subject: s2smanager: Add open_stream and close methods to resting sessions --- core/s2smanager.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 15d981d4..ccd8161f 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -511,6 +511,12 @@ end local resting_session = { -- Resting, not dead destroyed = true; + open_stream = function (session) + session.log("debug", "Attempt to open stream on resting session"); + end; + close = function (session) + session.log("debug", "Attempt to close already-closed session"); + end; }; resting_session.__index = resting_session; function retire_session(session) -- cgit v1.2.3 From 03734de797479ba2cf10002df6a040b6f7d0c010 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 02:57:22 +0000 Subject: s2smanager: Don't re-destroy destroyed sessions --- core/s2smanager.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/core/s2smanager.lua b/core/s2smanager.lua index ccd8161f..b65fe00c 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -533,6 +533,7 @@ function retire_session(session) end function destroy_session(session, reason) + if session.destroyed then return; end (session.log or log)("info", "Destroying "..tostring(session.direction).." session "..tostring(session.from_host).."->"..tostring(session.to_host)); if session.direction == "outgoing" then -- cgit v1.2.3 From 8b94f4df2504444121a345c430538b0a409e059d Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 02:58:11 +0000 Subject: sessionmanager: Add close method to resting sessions --- core/sessionmanager.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index b65e866f..5c40f756 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -68,6 +68,9 @@ end local resting_session = { -- Resting, not dead destroyed = true; + close = function (session) + session.log("debug", "Attempt to close already-closed session"); + end; }; resting_session.__index = resting_session; function retire_session(session) -- cgit v1.2.3 From c42dd4c96236f0b83654d83613d7d3cf5dffef84 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 02:59:16 +0000 Subject: sessionmanager: Return stream error when incoming stream header is missing 'to' attribute --- core/sessionmanager.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 5c40f756..264c296b 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -181,7 +181,12 @@ end function streamopened(session, attr) local send = session.send; - session.host = attr.to or error("Client failed to specify destination hostname"); + session.host = attr.to; + if not session.host then + session:close{ condition = "improper-addressing", + text = "A 'to' attribute is required on stream headers" }; + return; + end session.host = nameprep(session.host); session.version = tonumber(attr.version) or 0; session.streamid = uuid_generate(); -- cgit v1.2.3 From 415ac76d286a0488bf65ae07b43f4d1b2c27aa75 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 02:59:41 +0000 Subject: sessionmanager: Don't re-destroy destroyed sessions --- core/sessionmanager.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 264c296b..5fa757d6 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -88,6 +88,7 @@ end function destroy_session(session, err) (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)"); + if session.destroyed then return; end -- Remove session/resource from user's session list if session.full_jid then -- cgit v1.2.3 From ada4f197bba33b040746ab40fc64b50fe4523087 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:01:00 +0000 Subject: net.xmppclient_listener: Fix to correctly handle stream errors from clients --- net/xmppclient_listener.lua | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua index 3a0c65be..0d0e92ce 100644 --- a/net/xmppclient_listener.lua +++ b/net/xmppclient_listener.lua @@ -33,13 +33,32 @@ local opt_keepalives = config.get("*", "core", "tcp_keepalives"); local stream_callbacks = { default_ns = "jabber:client", streamopened = sm_streamopened, streamclosed = sm_streamclosed, handlestanza = core_process_stanza }; +local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; + function stream_callbacks.error(session, error, data) if error == "no-stream" then session.log("debug", "Invalid opening stream header"); session:close("invalid-namespace"); - elseif session.close then - (session.log or log)("debug", "Client XML parse error: %s", tostring(error)); + elseif error == "parse-error" then + (session.log or log)("debug", "Client XML parse error: %s", tostring(data)); session:close("xml-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 + end + end + text = condition .. (text and (" ("..text..")") or ""); + session.log("info", "Session closed by remote with error: %s", text); + session:close(nil, text); end end -- cgit v1.2.3 From 4481ea54a304192f483ad704ba75ffd4398ec541 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:03:02 +0000 Subject: net.xmppcomponent_listener: Fix to correctly handle stream errors from components --- net/xmppcomponent_listener.lua | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index 0b98b6bc..2483d48a 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -34,16 +34,32 @@ local xmlns_component = 'jabber:component:accept'; local stream_callbacks = { default_ns = xmlns_component }; +local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; + function stream_callbacks.error(session, error, data, data2) log("warn", "Error processing component stream: "..tostring(error)); if error == "no-stream" then session:close("invalid-namespace"); - elseif error == "xml-parse-error" and data == "unexpected-element-close" then - session.log("warn", "Unexpected close of '%s' tag", data2); - session:close("xml-not-well-formed"); - else - session.log("warn", "External component %s XML parse error: %s", tostring(session.host), tostring(error)); + elseif error == "parse-error" then + session.log("warn", "External component %s XML parse error: %s", tostring(session.host), tostring(data)); session:close("xml-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 + end + end + text = condition .. (text and (" ("..text..")") or ""); + session.log("info", "Session closed by remote with error: %s", text); + session:close(nil, text); end end -- cgit v1.2.3 From 6550edee36ee362d2373d8c98e0b40d4635e1f14 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:04:04 +0000 Subject: net.xmppcomponent_listener: Don't handle stream errors from component sessions that have already been destroyed --- net/xmppcomponent_listener.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index 2483d48a..056eb0a2 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -37,6 +37,7 @@ local stream_callbacks = { default_ns = xmlns_component }; 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 log("warn", "Error processing component stream: "..tostring(error)); if error == "no-stream" then session:close("invalid-namespace"); -- cgit v1.2.3 From ef9204bca17420748f0757806d5942f8948a1450 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:04:51 +0000 Subject: net.xmppcomponent_listener: Close component sessions on receiving a --- net/xmppcomponent_listener.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index 056eb0a2..9d7988cb 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -88,8 +88,8 @@ function stream_callbacks.streamopened(session, attr) end function stream_callbacks.streamclosed(session) - session.send(""); - session.notopen = true; + session.log("Received "); + session:close(); end local core_process_stanza = core_process_stanza; -- cgit v1.2.3 From c1cb6b9e9b87dfb2f068aa01ab1fb955852c5360 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:05:43 +0000 Subject: net.xmppcomponent_listener: Don't allow closing a session that has already been destroyed --- net/xmppcomponent_listener.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index 9d7988cb..c9a0d70b 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -106,6 +106,7 @@ end local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'}; local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/streams", xmlns = stream_callbacks.default_ns, version = "1.0", id = "" }; local function session_close(session, reason) + if session.destroyed then return; end local log = session.log or log; if session.conn then if session.notopen then -- cgit v1.2.3 From a81dc4028b418c0374bbdb56583b40472dbe8693 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:06:19 +0000 Subject: net.xmppcomponent_listener: Log invalid XML received from components (as we already do for c2s/s2s) --- net/xmppcomponent_listener.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index c9a0d70b..7b8ab95a 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -164,6 +164,7 @@ function component_listener.onincoming(conn, data) function session.data(conn, data) local ok, err = parser:parse(data); if ok then return; end + log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); session:close("xml-not-well-formed"); end -- cgit v1.2.3 From 30e384b6f629033b49c3d304f31079b508a9ef27 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 14 Mar 2010 03:07:05 +0000 Subject: net.xmppcomponent_listener: Don't remove 'log' and 'close' from sessions when destroying, and set destroyed = true --- net/xmppcomponent_listener.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index 7b8ab95a..568d947c 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -186,7 +186,12 @@ function component_listener.ondisconnect(conn, err) hosts[session.host].connected = nil; end sessions[conn] = nil; - for k in pairs(session) do session[k] = nil; end + for k in pairs(session) do + if k ~= "log" and k ~= "close" then + session[k] = nil; + end + end + session.destroyed = true; session = nil; end end -- cgit v1.2.3