# HG changeset patch # User Matthew Wild # Date 1250597015 -3600 # Node ID 45a81d6d877778c896b56c9c4fa03beb81911548 # Parent 232c2bf155c713793fd6ff4e5e4929c542cec104# Parent 00ad2488ef0b445ee430d52b6da7480058866048 Merge waqas with Tobias. Eww. diff -r 00ad2488ef0b -r 45a81d6d8777 core/s2smanager.lua --- a/core/s2smanager.lua Tue Aug 18 12:58:34 2009 +0500 +++ b/core/s2smanager.lua Tue Aug 18 13:03:35 2009 +0100 @@ -126,6 +126,7 @@ end open_sessions = open_sessions + 1; local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); + session.log = log; session.sends2s = function (t) log("debug", "sending: %s", tostring(t)); w(tostring(t)); end incoming_s2s[session] = true; return session; diff -r 00ad2488ef0b -r 45a81d6d8777 core/sessionmanager.lua --- a/core/sessionmanager.lua Tue Aug 18 12:58:34 2009 +0500 +++ b/core/sessionmanager.lua Tue Aug 18 13:03:35 2009 +0100 @@ -19,7 +19,8 @@ local bare_sessions = bare_sessions; local modulemanager = require "core.modulemanager"; -local log = require "util.logger".init("sessionmanager"); +local logger = require "util.logger"; +local log = logger.init("sessionmanager"); local error = error; local uuid_generate = require "util.uuid".generate; local rm_load_roster = require "core.rostermanager".load_roster; @@ -50,6 +51,9 @@ local w = conn.write; session.send = function (t) w(tostring(t)); end session.ip = conn.ip(); + local conn_name = "c2s"..tostring(conn):match("[a-f0-9]+$"); + session.log = logger.init(conn_name); + return session; end diff -r 00ad2488ef0b -r 45a81d6d8777 net/server.lua --- a/net/server.lua Tue Aug 18 12:58:34 2009 +0500 +++ b/net/server.lua Tue Aug 18 13:03:35 2009 +0100 @@ -246,7 +246,7 @@ _socketlist[ socket ] = nil handler = nil socket = nil - mem_free( ) + --mem_free( ) out_put "server.lua: closed server handler and removed sockets from list" end handler.ip = function( ) @@ -373,7 +373,7 @@ handler = nil end socket = nil - mem_free( ) + --mem_free( ) if server then server.remove( ) end @@ -559,7 +559,7 @@ socket, err = ssl_wrap( socket, sslctx ) -- wrap socket if err then out_put( "server.lua: ssl error: ", tostring(err) ) - mem_free( ) + --mem_free( ) return nil, nil, err -- fatal error end socket:settimeout( 0 ) @@ -664,7 +664,7 @@ _readlistlen = removesocket( _readlist, socket, _readlistlen ) _socketlist[ socket ] = nil socket:close( ) - mem_free( ) + --mem_free( ) end ----------------------------------// PUBLIC //-- @@ -733,7 +733,7 @@ _sendlist = { } _timerlist = { } _socketlist = { } - mem_free( ) + --mem_free( ) end getsettings = function( ) diff -r 00ad2488ef0b -r 45a81d6d8777 net/xmppclient_listener.lua --- a/net/xmppclient_listener.lua Tue Aug 18 12:58:34 2009 +0500 +++ b/net/xmppclient_listener.lua Tue Aug 18 13:03:35 2009 +0100 @@ -114,11 +114,6 @@ session = sm_new_session(conn); sessions[conn] = session; - -- Logging functions -- - - local conn_name = "c2s"..tostring(conn):match("[a-f0-9]+$"); - session.log = logger.init(conn_name); - session.log("info", "Client connected"); -- Client is using legacy SSL (otherwise mod_tls sets this flag) diff -r 00ad2488ef0b -r 45a81d6d8777 net/xmppserver_listener.lua --- a/net/xmppserver_listener.lua Tue Aug 18 12:58:34 2009 +0500 +++ b/net/xmppserver_listener.lua Tue Aug 18 13:03:35 2009 +0100 @@ -114,12 +114,6 @@ session = s2s_new_incoming(conn); sessions[conn] = session; - -- Logging functions -- - - - local conn_name = "s2sin"..tostring(conn):match("[a-f0-9]+$"); - session.log = logger.init(conn_name); - session.log("info", "Incoming s2s connection"); session.reset_stream = session_reset_stream; diff -r 00ad2488ef0b -r 45a81d6d8777 plugins/mod_compression.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/mod_compression.lua Tue Aug 18 13:03:35 2009 +0100 @@ -0,0 +1,115 @@ +-- Prosody IM +-- Copyright (C) 2009 Tobias Markmann +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- + +local st = require "util.stanza"; +local zlib = require "zlib"; +local pcall = pcall; + +local xmlns_compression_feature = "http://jabber.org/features/compress" +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)); + module:log("warn", "Module loading aborted. Compression won't be available."); + return; +end + +module:add_event_hook("stream-features", + function (session, features) + if not session.compressed then + -- FIXME only advertise compression support when TLS layer has no compression enabled + features:add_child(compression_stream_feature); + end + end +); + +-- TODO Support compression on S2S level too. +module:add_handler("c2s_unauthed", "compress", xmlns_compression_protocol, + function(session, stanza) + -- checking if the compression method is supported + local method = stanza:child_with_name("method")[1]; + if method == "zlib" then + session.log("info", method.." compression selected."); + session.send(st.stanza("compressed", {xmlns=xmlns_compression_protocol})); + session:reset_stream(); + + -- create deflate and inflate streams + local status, deflate_stream = pcall(zlib.deflate, compression_level); + 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."); + module:log("error", inflate_stream); + return + end + + local status, inflate_stream = pcall(zlib.inflate); + 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."); + module:log("error", inflate_stream); + return + end + + -- setup compression for session.w + local old_send = session.send; + + session.send = function(t) + local status, compressed, eof = pcall(deflate_stream, tostring(t), 'sync'); + if status == false then + session:close({ + condition = "undefined-condition"; + text = compressed; + extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); + }); + module:log("error", compressed); + return; + end + old_send(compressed); + end; + + -- setup decompression for session.data + local function setup_decompression(session) + local old_data = session.data + session.data = function(conn, data) + local status, decompressed, eof = pcall(inflate_stream, data); + if status == false then + session:close({ + condition = "undefined-condition"; + text = compressed; + extra = st.stanza("failure", {xmlns="http://jabber.org/protocol/compress"}):tag("processing-failed"); + }); + module:log("error", compressed); + return; + end + old_data(conn, decompressed); + end; + end + setup_decompression(session); + + local session_reset_stream = session.reset_stream; + session.reset_stream = function(session) + session_reset_stream(session); + setup_decompression(session); + return true; + end; + session.compressed = true; + else + session.log("info", method.." compression selected. But we don't support it."); + local error_st = st.stanza("failure", {xmlns=xmlns_compression_protocol}):tag("unsupported-method"); + session.send(error_st); + end + end +); diff -r 00ad2488ef0b -r 45a81d6d8777 plugins/mod_posix.lua --- a/plugins/mod_posix.lua Tue Aug 18 12:58:34 2009 +0500 +++ b/plugins/mod_posix.lua Tue Aug 18 13:03:35 2009 +0100 @@ -23,12 +23,39 @@ module.host = "*"; -- we're a global module +-- Allow switching away from root, some people like strange ports. +module:add_event_hook("server-started", function () + local uid = module:get_option("setuid"); + local gid = module:get_option("setgid"); + if gid then + local success, msg = pposix.setgid(gid); + if success then + module:log("debug", "Changed group to "..gid.." successfully."); + else + module:log("error", "Failed to change group to "..gid..". Error: "..msg); + prosody.shutdown("Failed to change group to "..gid); + end + end + if uid then + local success, msg = pposix.setuid(uid); + if success then + module:log("debug", "Changed user to "..uid.." successfully."); + else + module:log("error", "Failed to change user to "..uid..". Error: "..msg); + prosody.shutdown("Failed to change user to "..uid); + end + end + end); + -- Don't even think about it! module:add_event_hook("server-starting", function () - if pposix.getuid() == 0 and not module:get_option("run_as_root") then - module:log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!"); - module:log("error", "For more information on running Prosody as root, see http://prosody.im/doc/root"); - prosody.shutdown("Refusing to run as root"); + local suid = module:get_option("setuid"); + if not suid or suid == 0 or suid == "root" then + if pposix.getuid() == 0 and not module:get_option("run_as_root") then + module:log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!"); + module:log("error", "For more information on running Prosody as root, see http://prosody.im/doc/root"); + prosody.shutdown("Refusing to run as root"); + end end end); diff -r 00ad2488ef0b -r 45a81d6d8777 plugins/mod_roster.lua --- a/plugins/mod_roster.lua Tue Aug 18 12:58:34 2009 +0500 +++ b/plugins/mod_roster.lua Tue Aug 18 13:03:35 2009 +0100 @@ -24,7 +24,7 @@ local rosterver_stream_feature = st.stanza("ver", {xmlns="urn:xmpp:features:rosterver"}):tag("optional"):up(); module:add_event_hook("stream-features", - function (session, features) + function (session, features) if session.username then features:add_child(rosterver_stream_feature); end diff -r 00ad2488ef0b -r 45a81d6d8777 plugins/mod_tls.lua --- a/plugins/mod_tls.lua Tue Aug 18 12:58:34 2009 +0500 +++ b/plugins/mod_tls.lua Tue Aug 18 13:03:35 2009 +0100 @@ -28,7 +28,7 @@ local starttls_attr = { xmlns = xmlns_starttls }; module:add_event_hook("stream-features", - function (session, features) + function (session, features) if session.conn.starttls then features:tag("starttls", starttls_attr); if secure_auth_only then