diff options
58 files changed, 373 insertions, 160 deletions
diff --git a/core/componentmanager.lua b/core/componentmanager.lua index 974b5bf1..a63cfd7a 100644 --- a/core/componentmanager.lua +++ b/core/componentmanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/core/configmanager.lua b/core/configmanager.lua index 6601fed6..a6e86347 100644 --- a/core/configmanager.lua +++ b/core/configmanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/core/discomanager.lua b/core/discomanager.lua index 16bf2227..21080635 100644 --- a/core/discomanager.lua +++ b/core/discomanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/core/modulemanager.lua b/core/modulemanager.lua index 84486b58..da5945ac 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/core/offlinemanager.lua b/core/offlinemanager.lua index c327f979..b56b0ef7 100644 --- a/core/offlinemanager.lua +++ b/core/offlinemanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/core/offlinemessage.lua b/core/offlinemessage.lua index 9888f76d..36f2948d 100644 --- a/core/offlinemessage.lua +++ b/core/offlinemessage.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/core/presencemanager.lua b/core/presencemanager.lua index 6e27752b..e4dd6cc4 100644 --- a/core/presencemanager.lua +++ b/core/presencemanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/core/rostermanager.lua b/core/rostermanager.lua index b5698fc5..fc8a5862 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/core/s2smanager.lua b/core/s2smanager.lua index 7827381d..fa38d5cb 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- @@ -47,6 +47,9 @@ local dialback_secret = sha256_hash(tostring{} .. math.random() .. socket.gettim local dns = require "net.dns"; +incoming_s2s = {}; +local incoming_s2s = incoming_s2s; + module "s2smanager" local function compare_srv_priorities(a,b) return a.priority < b.priority or a.weight < b.weight; end @@ -91,7 +94,7 @@ end local open_sessions = 0; function new_incoming(conn) - local session = { conn = conn, type = "s2sin_unauthed", direction = "incoming" }; + local session = { conn = conn, type = "s2sin_unauthed", direction = "incoming", hosts = {} }; if true then session.trace = newproxy(true); getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end; @@ -99,6 +102,7 @@ function new_incoming(conn) open_sessions = open_sessions + 1; local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end + incoming_s2s[session] = true; return session; end @@ -239,11 +243,16 @@ function verify_dialback(id, to, from, key) return key == generate_dialback(id, to, from); end -function make_authenticated(session) +function make_authenticated(session, host) if session.type == "s2sout_unauthed" then session.type = "s2sout"; elseif session.type == "s2sin_unauthed" then session.type = "s2sin"; + if host then + session.hosts[host].authed = true; + end + elseif session.type == "s2sin" and host then + session.hosts[host].authed = true; else return false; end @@ -284,6 +293,8 @@ function destroy_session(session) if session.direction == "outgoing" then hosts[session.from_host].s2sout[session.to_host] = nil; + elseif session.direction == "incoming" then + incoming_s2s[session] = nil; end for k in pairs(session) do diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 34cc9f0f..963de7ce 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- @@ -113,8 +113,6 @@ 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 - session.conntimetotal = gettime()-session.conntime; - resource = resource or uuid_generate(); --FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing @@ -209,4 +207,4 @@ function send_to_available_resources(user, host, stanza) return count; end -return _M;
\ No newline at end of file +return _M; diff --git a/core/stanza_router.lua b/core/stanza_router.lua index c2214b1c..24eadedc 100644 --- a/core/stanza_router.lua +++ b/core/stanza_router.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- @@ -72,26 +72,27 @@ function core_process_stanza(origin, stanza) if origin.type == "c2s" then stanza.attr.from = origin.full_jid; end - local to = stanza.attr.to; + local to, xmlns = stanza.attr.to, stanza.attr.xmlns; local node, host, resource = jid_split(to); local to_bare = node and (node.."@"..host) or host; -- bare JID local from = stanza.attr.from; local from_node, from_host, from_resource = jid_split(from); local from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID - if origin.type == "s2sin" then - if origin.from_host ~= from_host then -- remote server trying to impersonate some other server? - log("warn", "Received a stanza claiming to be from %s, over a conn authed for %s!", from, origin.from_host); - return; -- FIXME what should we do here? does this work with subdomains? - end - end --[[if to and not(hosts[to]) and not(hosts[to_bare]) and (hosts[host] and hosts[host].type ~= "local") then -- not for us? log("warn", "stanza recieved for a non-local server"); return; -- FIXME what should we do here? end]] -- FIXME -- FIXME do stanzas not of jabber:client get handled by components? - if origin.type == "s2sin" or origin.type == "c2s" then + if (origin.type == "s2sin" or origin.type == "c2s") and (not xmlns or xmlns == "jabber:server" or xmlns == "jabber:client") then + if origin.type == "s2sin" then + local host_status = origin.hosts[from_host]; + if not host_status or not host_status.authed then -- remote server trying to impersonate some other server? + log("warn", "Received a stanza claiming to be from %s, over a conn authed for %s!", from_host, origin.from_host); + return; -- FIXME what should we do here? does this work with subdomains? + end + end if not to then core_handle_stanza(origin, stanza); elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server diff --git a/core/usermanager.lua b/core/usermanager.lua index 2c02394f..2da64cff 100644 --- a/core/usermanager.lua +++ b/core/usermanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua index b4dd5479..d4d9e141 100644 --- a/core/xmlhandlers.lua +++ b/core/xmlhandlers.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- @@ -47,29 +47,27 @@ local ns_prefixes = { function init_xmlhandlers(session, stream_callbacks) local ns_stack = { "" }; - local curr_ns = ""; + local curr_ns, name = ""; local curr_tag; local chardata = {}; local xml_handlers = {}; local log = session.log or default_log; - - local send = session.send; local cb_streamopened = stream_callbacks.streamopened; local cb_streamclosed = stream_callbacks.streamclosed; local cb_error = stream_callbacks.error or function (session, e) error("XML stream error: "..tostring(e)); end; local cb_handlestanza = stream_callbacks.handlestanza; - local stream_ns = stream_callbacks.ns; + local stream_tag = stream_callbacks.stream_tag; local stanza - function xml_handlers:StartElement(name, attr) + function xml_handlers:StartElement(tagname, attr) if stanza and #chardata > 0 then -- We have some character data in the buffer stanza:text(t_concat(chardata)); chardata = {}; end - curr_ns,name = name:match("^(.+)|([%w%-]+)$"); + local curr_ns,name = tagname:match("^(.+)|([%w%-]+)$"); if curr_ns ~= "jabber:server" then attr.xmlns = curr_ns; end @@ -91,7 +89,7 @@ function init_xmlhandlers(session, stream_callbacks) if not stanza then --if we are not currently inside a stanza if session.notopen then - if name == "stream" and curr_ns == stream_ns then + if tagname == stream_tag then if cb_streamopened then cb_streamopened(session, attr); end @@ -120,10 +118,10 @@ function init_xmlhandlers(session, stream_callbacks) t_insert(chardata, data); end end - function xml_handlers:EndElement(name) - curr_ns,name = name:match("^(.+)|([%w%-]+)$"); + function xml_handlers:EndElement(tagname) + curr_ns,name = tagname:match("^(.+)|([%w%-]+)$"); if (not stanza) or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then - if name == "stream" then + if tagname == stream_tag then if cb_streamclosed then cb_streamclosed(session); end diff --git a/net/connlisteners.lua b/net/connlisteners.lua index 9be144da..f027dfeb 100644 --- a/net/connlisteners.lua +++ b/net/connlisteners.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- @@ -47,7 +47,8 @@ end function get(name) local h = listeners[name]; if not h then - pcall(dofile, listeners_dir..name:gsub("[^%w%-]", "_").."_listener.lua"); + local ok, ret = pcall(dofile, listeners_dir..name:gsub("[^%w%-]", "_").."_listener.lua"); + if not ok then return nil, ret; end h = listeners[name]; end return h; diff --git a/net/dns.lua b/net/dns.lua index 8cf092fb..faad2b93 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -1,24 +1,6 @@ --- Prosody IM v0.1 --- Copyright (C) 2008 Matthew Wild --- Copyright (C) 2008 Waqas Hussain --- --- This program is free software; you can redistribute it and/or --- modify it under the terms of the GNU General Public License --- as published by the Free Software Foundation; either version 2 --- of the License, or (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. --- - - - +-- Prosody IM v0.2 +-- This file is included with Prosody IM. It has modifications, +-- which are hereby placed in the public domain. -- public domain 20080404 lua@ztact.com diff --git a/net/http.lua b/net/http.lua new file mode 100644 index 00000000..e8a981b8 --- /dev/null +++ b/net/http.lua @@ -0,0 +1,172 @@ + +local socket = require "socket" +local mime = require "mime" +local url = require "socket.url" + +local server = require "net.server" + +local connlisteners_get = require "net.connlisteners".get; +local listener = connlisteners_get("httpclient") or error("No httpclient listener!"); + +local t_insert, t_concat = table.insert, table.concat; +local tonumber, tostring, pairs = tonumber, tostring, pairs; +local print = function () end + +local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end }); +local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%x", c:byte()); end)); end + +module "http" + +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 >= 100 and code < 200 then return nil end + return 1 +end + +local function request_reader(request, data, startpos) + if not data then + if request.body then + request.callback(request.code, t_concat(request.body), request); + else + -- Error.. connection was closed prematurely + request.callback(0, "connection-closed", request); + end + destroy_request(request); + return; + end + if request.state == "body" then + print("Reading body...") + if not request.body then request.body = {}; request.havebodylength, request.bodylength = 0, tonumber(request.responseheaders["content-length"]); end + if startpos then + data = data:sub(startpos, -1) + end + t_insert(request.body, data); + if request.bodylength then + request.havebodylength = request.havebodylength + #data; + if request.havebodylength >= request.bodylength then + -- We have the body + if request.callback then + request.callback(request.code, t_concat(request.body), request); + end + end + print("", "Have "..request.havebodylength.." bytes out of "..request.bodylength); + end + elseif request.state == "headers" then + print("Reading headers...") + local pos = startpos; + local headers = request.responseheaders or {}; + 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); + elseif #line == 0 then + request.responseheaders = headers; + break; + else + print("Unhandled header line: "..line); + end + end + -- Reached the end of the headers + request.state = "body"; + if #data > startpos then + return request_reader(request, data, startpos); + end + elseif request.state == "status" then + print("Reading status...") + local http, code, text, linelen = data:match("^HTTP/(%S+) (%d+) (.-)\r\n()", startpos); + if not code then + return request.callback(0, "invalid-status-line", request); + end + + request.responsecode, request.responseversion = code, http; + + if request.onlystatus or not expectbody(request, tonumber(code)) then + if request.callback then + request.callback(code, nil, request); + end + destroy_request(request); + return; + end + + request.state = "headers"; + + if #data > linelen then + return request_reader(request, data, linelen); + end + end +end + +function request(u, callback, ex) + local req = url.parse(u); + + local custom_headers, body; + local default_headers = { ["Host"] = req.host, ["User-Agent"] = "Prosody XMPP Server" } + + + if req.userinfo then + default_headers["Authorization"] = "Basic "..mime.b64(req.userinfo); + end + + if ex then + custom_headers = ex.custom_headers; + req.onlystatus = ex.onlystatus; + body = ex.body; + if body then + req.method = "POST "; + default_headers["Content-Length"] = tostring(#body); + default_headers["Content-Type"] = "application/x-www-form-urlencoded"; + end + if ex.method then req.method = ex.method; end + end + + req.handler, req.conn = server.wraptcpclient(listener, socket.tcp(), req.host, req.port or 80, 0, "*a"); + req.write = req.handler.write; + req.conn:settimeout(0); + local ok, err = req.conn:connect(req.host, req.port or 80); + if not ok and err ~= "timeout" then + return nil, err; + end + + req.write((req.method or "GET ")..req.path.." HTTP/1.0\r\n"); + local t = { [2] = ": ", [4] = "\r\n" }; + if custom_headers then + for k, v in pairs(custom_headers) do + t[1], t[3] = k, v; + req.write(t_concat(t)); + default_headers[k] = nil; + end + end + + for k, v in pairs(default_headers) do + t[1], t[3] = k, v; + req.write(t_concat(t)); + default_headers[k] = nil; + end + req.write("\r\n"); + + if body then + req.write(body); + end + + req.callback = callback; + req.reader = request_reader; + req.state = "status" + + listener.register_request(req.handler, req); + + return req; +end + +function destroy_request(request) + if request.conn then + request.handler.close() + listener.disconnect(request.conn, "closed"); + end +end + +_M.urlencode = urlencode; + +return _M; diff --git a/net/httpclient_listener.lua b/net/httpclient_listener.lua new file mode 100644 index 00000000..1948f278 --- /dev/null +++ b/net/httpclient_listener.lua @@ -0,0 +1,36 @@ + +local connlisteners_register = require "net.connlisteners".register; + + +local requests = {}; -- Open requests +local buffers = {}; -- Buffers of partial lines + +local httpclient = { default_port = 80, default_mode = "*a" }; + +function httpclient.listener(conn, data) + local request = requests[conn]; + + if not request then + print("NO REQUEST!! for "..tostring(conn)); + return; + end + + if data and request.reader then + request:reader(data); + end +end + +function httpclient.disconnect(conn, err) + local request = requests[conn]; + if request then + request:reader(nil); + end + --requests[conn] = nil; +end + +function httpclient.register_request(conn, req) + print("Registering a request for "..tostring(conn)); + requests[conn] = req; +end + +connlisteners_register("httpclient", httpclient); diff --git a/net/server.lua b/net/server.lua index 5c129753..4e5ec366 100644 --- a/net/server.lua +++ b/net/server.lua @@ -587,6 +587,8 @@ wraptcpclient = function( listener, socket, ip, serverport, clientport, mode ) local eol, fatal_send_error + socket:settimeout(0); + local rstat, sstat = 0, 0 --// local import of socket methods //-- @@ -833,5 +835,6 @@ return { stats = stats, closeall = closeall, addtimer = addtimer, + wraptcpclient = wraptcpclient, wraptlsclient = wraptlsclient, } diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua index a130a0c1..357516e9 100644 --- a/net/xmppclient_listener.lua +++ b/net/xmppclient_listener.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- @@ -36,7 +36,7 @@ local sm_streamopened = sessionmanager.streamopened; local sm_streamclosed = sessionmanager.streamclosed; local st = stanza; -local stream_callbacks = { ns = "http://etherx.jabber.org/streams", streamopened = sm_streamopened, streamclosed = sm_streamclosed, handlestanza = core_process_stanza }; +local stream_callbacks = { stream_tag = "http://etherx.jabber.org/streams|stream", streamopened = sm_streamopened, streamclosed = sm_streamclosed, handlestanza = core_process_stanza }; function stream_callbacks.error(session, error, data) if error == "no-stream" then @@ -47,7 +47,7 @@ function stream_callbacks.error(session, error, data) end end -local function handleerr(err) log("error", "Traceback[c2s]:", err, debug.traceback()); end +local function handleerr(err) log("error", "Traceback[c2s]: %s: %s", tostring(err), debug.traceback()); end function stream_callbacks.handlestanza(a, b) xpcall(function () core_process_stanza(a, b) end, handleerr); end diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua index b8198beb..36b4c476 100644 --- a/net/xmppserver_listener.lua +++ b/net/xmppserver_listener.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- @@ -28,7 +28,7 @@ local s2s_streamopened = require "core.s2smanager".streamopened; local s2s_streamclosed = require "core.s2smanager".streamclosed; local s2s_destroy_session = require "core.s2smanager".destroy_session; local s2s_attempt_connect = require "core.s2smanager".attempt_connection; -local stream_callbacks = { ns = "http://etherx.jabber.org/streams", streamopened = s2s_streamopened, streamclosed = s2s_streamclosed, handlestanza = core_process_stanza }; +local stream_callbacks = { stream_tag = "http://etherx.jabber.org/streams|stream", streamopened = s2s_streamopened, streamclosed = s2s_streamclosed, handlestanza = core_process_stanza }; function stream_callbacks.error(session, error, data) if error == "no-stream" then @@ -39,7 +39,7 @@ function stream_callbacks.error(session, error, data) end end -local function handleerr(err) log("error", "Traceback[s2s]:", err, debug.traceback()); end +local function handleerr(err) log("error", "Traceback[s2s]: %s: %s", tostring(err), debug.traceback()); end function stream_callbacks.handlestanza(a, b) xpcall(function () core_process_stanza(a, b) end, handleerr); end diff --git a/plugins/mod_console.lua b/plugins/mod_console.lua index 4ac3c5fe..d6383a78 100644 --- a/plugins/mod_console.lua +++ b/plugins/mod_console.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/plugins/mod_dialback.lua b/plugins/mod_dialback.lua index 6bfed8fc..4e29b334 100644 --- a/plugins/mod_dialback.lua +++ b/plugins/mod_dialback.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- @@ -29,6 +29,8 @@ local log = require "util.logger".init("mod_dialback"); local xmlns_dialback = "jabber:server:dialback"; +local dialback_requests = setmetatable({}, { __mode = 'v' }); + module:add_handler({"s2sin_unauthed", "s2sin"}, "verify", xmlns_dialback, function (origin, stanza) -- We are being asked to verify the key, to ensure it was generated by us @@ -47,50 +49,78 @@ module:add_handler({"s2sin_unauthed", "s2sin"}, "verify", xmlns_dialback, origin.sends2s(st.stanza("db:verify", { from = attr.to, to = attr.from, id = attr.id, type = type }):text(stanza[1])); end); -module:add_handler("s2sin_unauthed", "result", xmlns_dialback, +module:add_handler({ "s2sin_unauthed", "s2sin" }, "result", xmlns_dialback, function (origin, stanza) -- he wants to be identified through dialback -- We need to check the key with the Authoritative server local attr = stanza.attr; - local attr = stanza.attr; - origin.from_host = attr.from; - origin.to_host = attr.to; - origin.dialback_key = stanza[1]; - log("debug", "asking %s if key %s belongs to them", origin.from_host, origin.dialback_key); - send_s2s(origin.to_host, origin.from_host, - st.stanza("db:verify", { from = origin.to_host, to = origin.from_host, id = origin.streamid }):text(origin.dialback_key)); - hosts[origin.to_host].s2sout[origin.from_host].dialback_verifying = origin; + origin.hosts[attr.from] = { dialback_key = stanza[1] }; + + if not hosts[attr.to] then + -- Not a host that we serve + log("info", "%s tried to connect to %s, which we don't serve", attr.from, attr.to); + origin:close("host-unknown"); + return; + end + + dialback_requests[attr.from] = origin; + + if not origin.from_host then + -- Just used for friendlier logging + origin.from_host = attr.from; + end + if not origin.to_host then + -- Just used for friendlier logging + origin.to_host = attr.to; + end + + log("debug", "asking %s if key %s belongs to them", attr.from, stanza[1]); + send_s2s(attr.to, attr.from, + st.stanza("db:verify", { from = attr.to, to = attr.from, id = origin.streamid }):text(stanza[1])); end); module:add_handler({ "s2sout_unauthed", "s2sout" }, "verify", xmlns_dialback, function (origin, stanza) - if origin.dialback_verifying then + local attr = stanza.attr; + local dialback_verifying = dialback_requests[attr.from]; + if dialback_verifying then local valid; - local attr = stanza.attr; if attr.type == "valid" then - s2s_make_authenticated(origin.dialback_verifying); + s2s_make_authenticated(dialback_verifying, attr.from); valid = "valid"; else -- Warn the original connection that is was not verified successfully - log("warn", "dialback for "..(origin.dialback_verifying.from_host or "(unknown)").." failed"); + log("warn", "authoritative server for "..(attr.from or "(unknown)").." denied the key"); valid = "invalid"; end - if not origin.dialback_verifying.sends2s then - log("warn", "Incoming s2s session %s was closed in the meantime, so we can't notify it of the db result", tostring(origin.dialback_verifying):match("%w+$")); + if not dialback_verifying.sends2s then + log("warn", "Incoming s2s session %s was closed in the meantime, so we can't notify it of the db result", tostring(dialback_verifying):match("%w+$")); else - origin.dialback_verifying.sends2s( + dialback_verifying.sends2s( st.stanza("db:result", { from = attr.to, to = attr.from, id = attr.id, type = valid }) - :text(origin.dialback_verifying.dialback_key)); + :text(dialback_verifying.hosts[attr.from].dialback_key)); end + dialback_requests[attr.from] = nil; end end); module:add_handler({ "s2sout_unauthed", "s2sout" }, "result", xmlns_dialback, function (origin, stanza) + -- Remote server is telling us whether we passed dialback + + local attr = stanza.attr; + if not hosts[attr.to] then + origin:close("host-unknown"); + return; + elseif hosts[attr.to].s2sout[attr.from] ~= origin then + -- This isn't right + origin:close("invalid-id"); + return; + end if stanza.attr.type == "valid" then - s2s_make_authenticated(origin); + s2s_make_authenticated(origin, attr.from); else - -- FIXME + -- FIXME: Waiting on #33 error("dialback failed!"); end end); diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua index 455f92f1..9f643134 100644 --- a/plugins/mod_disco.lua +++ b/plugins/mod_disco.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/plugins/mod_legacyauth.lua b/plugins/mod_legacyauth.lua index ca2d9f78..1869bba5 100644 --- a/plugins/mod_legacyauth.lua +++ b/plugins/mod_legacyauth.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/plugins/mod_ping.lua b/plugins/mod_ping.lua index 922c9390..53a808cd 100644 --- a/plugins/mod_ping.lua +++ b/plugins/mod_ping.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/plugins/mod_private.lua b/plugins/mod_private.lua index 8bcb6da6..76d18d39 100644 --- a/plugins/mod_private.lua +++ b/plugins/mod_private.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/plugins/mod_register.lua b/plugins/mod_register.lua index cc02a5bc..120faeab 100644 --- a/plugins/mod_register.lua +++ b/plugins/mod_register.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/plugins/mod_roster.lua b/plugins/mod_roster.lua index bbd678b8..83e9835d 100644 --- a/plugins/mod_roster.lua +++ b/plugins/mod_roster.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua index bea1012a..4934523f 100644 --- a/plugins/mod_saslauth.lua +++ b/plugins/mod_saslauth.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/plugins/mod_selftests.lua b/plugins/mod_selftests.lua index abfabc9b..1a2190dc 100644 --- a/plugins/mod_selftests.lua +++ b/plugins/mod_selftests.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/plugins/mod_time.lua b/plugins/mod_time.lua index 3d73623c..675bc023 100644 --- a/plugins/mod_time.lua +++ b/plugins/mod_time.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/plugins/mod_tls.lua b/plugins/mod_tls.lua index 20cf7c3d..fc816ad1 100644 --- a/plugins/mod_tls.lua +++ b/plugins/mod_tls.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- @@ -33,8 +33,6 @@ module:add_handler("c2s_unauthed", "starttls", xmlns_starttls, function (session, stanza) if session.conn.starttls then session.send(st.stanza("proceed", { xmlns = xmlns_starttls })); - -- FIXME: I'm commenting the below, not sure why it was necessary - -- sessions[session.conn] = nil; session:reset_stream(); session.conn.starttls(); session.log("info", "TLS negotiation started..."); diff --git a/plugins/mod_uptime.lua b/plugins/mod_uptime.lua index 51457551..33dd66fb 100644 --- a/plugins/mod_uptime.lua +++ b/plugins/mod_uptime.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/plugins/mod_vcard.lua b/plugins/mod_vcard.lua index fc71bb1b..10119252 100644 --- a/plugins/mod_vcard.lua +++ b/plugins/mod_vcard.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/plugins/mod_version.lua b/plugins/mod_version.lua index 0b7ebfaa..c263031a 100644 --- a/plugins/mod_version.lua +++ b/plugins/mod_version.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- @@ -31,7 +31,7 @@ local function handle_version_request(session, stanza) if stanza.attr.type == "get" then session.send(st.reply(stanza):query(xmlns_version) :tag("name"):text("Prosody"):up() - :tag("version"):text("0.1"):up() + :tag("version"):text("0.2"):up() :tag("os"):text("the best operating system ever!")); end end @@ -1,5 +1,5 @@ #!/usr/bin/env lua --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- @@ -18,8 +18,6 @@ -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -- - - -- Config here -- CFG_SOURCEDIR=nil; @@ -47,6 +45,9 @@ pcall(require, "luarocks.require") config = require "core.configmanager" log = require "util.logger".init("general"); +-- Disable log output, needs to read from config +-- require "util.logger".setwriter(function () end); + do -- TODO: Check for other formats when we add support for them -- Use lfs? Make a new conf/ dir? diff --git a/tests/test.lua b/tests/test.lua index 503ac4a1..eb209219 100644 --- a/tests/test.lua +++ b/tests/test.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/tests/test_core_configmanager.lua b/tests/test_core_configmanager.lua index cabe3061..74fce41d 100644 --- a/tests/test_core_configmanager.lua +++ b/tests/test_core_configmanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/tests/test_core_s2smanager.lua b/tests/test_core_s2smanager.lua index 2bbc6094..219d9df5 100644 --- a/tests/test_core_s2smanager.lua +++ b/tests/test_core_s2smanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/tests/test_core_stanza_router.lua b/tests/test_core_stanza_router.lua index 5471e95c..01e33d4e 100644 --- a/tests/test_core_stanza_router.lua +++ b/tests/test_core_stanza_router.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/tests/test_sasl.lua b/tests/test_sasl.lua index 994823c3..80eae5fc 100644 --- a/tests/test_sasl.lua +++ b/tests/test_sasl.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/tests/test_util_jid.lua b/tests/test_util_jid.lua index 98c85f4a..1c773992 100644 --- a/tests/test_util_jid.lua +++ b/tests/test_util_jid.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/tools/ejabberd2prosody.lua b/tools/ejabberd2prosody.lua index a277ea94..3c3ce945 100755 --- a/tools/ejabberd2prosody.lua +++ b/tools/ejabberd2prosody.lua @@ -1,5 +1,5 @@ #!/usr/bin/env lua --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/tools/erlparse.lua b/tools/erlparse.lua index af1628e5..37d4bb62 100644 --- a/tools/erlparse.lua +++ b/tools/erlparse.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/util/datamanager.lua b/util/datamanager.lua index a5e478c8..e229de1c 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/util/datetime.lua b/util/datetime.lua index 1c730e30..53b1700b 100644 --- a/util/datetime.lua +++ b/util/datetime.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/util/dependencies.lua b/util/dependencies.lua index d841b30d..6e78a138 100644 --- a/util/dependencies.lua +++ b/util/dependencies.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/util/discohelper.lua b/util/discohelper.lua index 7966ac55..56dfd5d0 100644 --- a/util/discohelper.lua +++ b/util/discohelper.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/util/import.lua b/util/import.lua index c7484d35..2f36ac99 100644 --- a/util/import.lua +++ b/util/import.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/util/jid.lua b/util/jid.lua index 6c387868..537735be 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/util/logger.lua b/util/logger.lua index f7ea187b..5115bbda 100644 --- a/util/logger.lua +++ b/util/logger.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/util/multitable.lua b/util/multitable.lua index 1e22c4dd..ce38e04d 100644 --- a/util/multitable.lua +++ b/util/multitable.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/util/sasl.lua b/util/sasl.lua index 311c3aff..dd8c2002 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -1,4 +1,4 @@ --- sasl.lua v0.1 +-- sasl.lua v0.2 -- Copyright (C) 2008 Tobias Markmann -- -- All rights reserved. diff --git a/util/serialization.lua b/util/serialization.lua index a3147fd8..7a377c98 100644 --- a/util/serialization.lua +++ b/util/serialization.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/util/stanza.lua b/util/stanza.lua index a4a89191..6af7e2b2 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- @@ -21,6 +21,7 @@ local t_insert = table.insert; local t_concat = table.concat; local t_remove = table.remove; +local t_concat = table.concat; local s_format = string.format; local tostring = tostring; local setmetatable = setmetatable; @@ -31,7 +32,7 @@ local next = next; local print = print; local unpack = unpack; local s_gsub = string.gsub; -local os = os; +local os = os; local do_pretty_printing = not os.getenv("WINDIR"); local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; @@ -117,22 +118,20 @@ end local xml_escape = xml_escape; -local function dostring(t, buf, self) +local function dostring(t, buf, self, xml_escape) t_insert(buf, "<"); t_insert(buf, t.name); - if t.attr then - for k, v in pairs(t.attr) do if type(k) == "string" then - t_insert(buf, " "); - t_insert(buf, k); - t_insert(buf, "='"); - t_insert(buf, (xml_escape(tostring(v)))); - t_insert(buf, "'"); - end end - end + for k, v in pairs(t.attr) do if type(k) == "string" then + t_insert(buf, " "); + t_insert(buf, k); + t_insert(buf, "='"); + t_insert(buf, (xml_escape(tostring(v)))); + t_insert(buf, "'"); + end end t_insert(buf, ">"); for n, child in ipairs(t) do if child.name then - self(child, buf, self); + self(child, buf, self, xml_escape); else t_insert(buf, (xml_escape(child))); end @@ -144,10 +143,11 @@ end function stanza_mt.__tostring(t) local buf = {}; - dostring(t, buf, dostring); + dostring(t, buf, dostring, xml_escape); return t_concat(buf); end + function stanza_mt.top_tag(t) local attr_string = ""; if t.attr then diff --git a/util/termcolours.lua b/util/termcolours.lua index 24cb0cbd..6ab1b1fd 100644 --- a/util/termcolours.lua +++ b/util/termcolours.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/util/uuid.lua b/util/uuid.lua index 0039664f..0b8526f9 100644 --- a/util/uuid.lua +++ b/util/uuid.lua @@ -1,4 +1,4 @@ --- Prosody IM v0.1 +-- Prosody IM v0.2 -- Copyright (C) 2008 Matthew Wild -- Copyright (C) 2008 Waqas Hussain -- diff --git a/util/ztact.lua b/util/ztact.lua index 55e40211..c329a685 100644 --- a/util/ztact.lua +++ b/util/ztact.lua @@ -1,24 +1,6 @@ --- Prosody IM v0.1 --- Copyright (C) 2008 Matthew Wild --- Copyright (C) 2008 Waqas Hussain --- --- This program is free software; you can redistribute it and/or --- modify it under the terms of the GNU General Public License --- as published by the Free Software Foundation; either version 2 --- of the License, or (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU General Public License for more details. --- --- You should have received a copy of the GNU General Public License --- along with this program; if not, write to the Free Software --- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. --- - - - +-- Prosody IM v0.2 +-- This file is included with Prosody IM. It has modifications, +-- which are hereby placed in the public domain. -- public domain 20080410 lua@ztact.com |