From 964ee27096880d45010375e937ef3f1702d128b7 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 4 May 2009 20:35:44 +0100 Subject: net.httpserver: Fix for urlencoding to always produce 2 digits --- net/httpserver.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/httpserver.lua b/net/httpserver.lua index 12328b29..af23a91d 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -11,7 +11,7 @@ local t_insert, t_concat = table.insert, table.concat; local s_match, s_gmatch = string.match, string.gmatch; local tonumber, tostring, pairs = tonumber, tostring, pairs; -local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%x", c:byte()); end)); end +local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); end local log = require "util.logger".init("httpserver"); -- cgit v1.2.3 From b84c790f0ba57f11bbe6bf01bbbc45337c7b9943 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 5 May 2009 13:23:46 +0100 Subject: prosodyctl: Switch to Prosody user before attempting to do anything --- prosodyctl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/prosodyctl b/prosodyctl index 7998d033..b7fe1d02 100755 --- a/prosodyctl +++ b/prosodyctl @@ -61,6 +61,29 @@ do end end +-- Switch away from root and into the prosody user -- +local switched_user, current_uid; +local ok, pposix = pcall(require, "util.pposix"); +if ok and pposix then + current_uid = pposix.getuid(); + if current_uid == 0 then + -- We haz root! + local desired_user = config.get("*", "core", "prosody_user") or "prosody"; + local ok, err = pposix.setuid(desired_user); + if ok then + -- Yay! + switched_user = true; + else + -- Boo! + print("Warning: Couldn't switch to Prosody user '"..tostring(desired_user).."': "..tostring(err)); + end + end +else + print("Error: Unable to load pposix module. Check that Prosody is installed correctly.") + print("For more help send the below error to us through http://prosody.im/discuss"); + print(tostring(pposix)) +end + local error_messages = setmetatable({ ["invalid-username"] = "The given username is invalid in a Jabber ID"; ["invalid-hostname"] = "The given hostname is invalid"; -- cgit v1.2.3 From 264c83dbd9a515de6fde79de746a7a4fe3f6fd55 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 5 May 2009 13:24:17 +0100 Subject: prosodyctl: status: Show warning if we can't find a running Prosody, and we didn't switch user --- prosodyctl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/prosodyctl b/prosodyctl index b7fe1d02..f451b7ee 100755 --- a/prosodyctl +++ b/prosodyctl @@ -314,6 +314,11 @@ function commands.status(arg) return 0; else show_message("Prosody is not running"); + if not switched_user and current_uid ~= 0 then + print("\nNote: You will also see this if prosodyctl is not running under the same"); + print(" user account as Prosody. Try running as root (e.g. with 'sudo' in front) to"); + print(" gain access to Prosody's real status."); + end return 2 end return 1; -- cgit v1.2.3 From bff3101d36f42871243f3190808f3b1eeb0c13f4 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 5 May 2009 14:17:06 +0100 Subject: prosody: Add functions to reload the config and re-open log files --- prosody | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/prosody b/prosody index 8b6b8ae6..2febe4d8 100755 --- a/prosody +++ b/prosody @@ -114,7 +114,27 @@ end); ----------- End of out-of-place code -------------- --- Global function to initiate prosody shutdown +-- Function to reload the config file +function prosody_reload_config() + log("info", "Reloading configuration file"); + eventmanager.fire_event("reloading-config"); + local ok, level, err = config.load((rawget(_G, "CFG_CONFIGDIR") or ".").."/prosody.cfg.lua"); + if not ok then + if level == "parser" then + log("error", "There was an error parsing the configuration file: %s", tostring(err)); + elseif level == "file" then + log("error", "Couldn't read the config file when trying to reload: %s", tostring(err)); + end + end +end + +-- Function to reopen logfiles +function prosody_reopen_logfiles() + log("info", "Re-opening log files"); + eventmanager.fire_event("reopen-log-files"); -- Handled by appropriate log sinks +end + +-- Function to initiate prosody shutdown function prosody_shutdown(reason) log("info", "Shutting down: %s", reason or "unknown reason"); eventmanager.fire_event("server-stopping", { reason = reason }); -- cgit v1.2.3 From 7f04c5117e674ad8ca5bd4621fa30937fa59d7fa Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 5 May 2009 14:19:20 +0100 Subject: loggingmanager: File log sinks react to reopen-log-files event --- core/loggingmanager.lua | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/core/loggingmanager.lua b/core/loggingmanager.lua index 58108a23..aa8f368d 100644 --- a/core/loggingmanager.lua +++ b/core/loggingmanager.lua @@ -10,7 +10,7 @@ local os_date, os_getenv = os.date, os.getenv; local getstyle, getstring = require "util.termcolours".getstyle, require "util.termcolours".getstring; local config = require "core.configmanager"; - +local eventmanager = require "core.eventmanager"; local logger = require "util.logger"; _G.log = logger.init("general"); @@ -190,12 +190,26 @@ do end end +local empty_function = function () end; function log_sink_types.file(config) local log = config.filename; local logfile = io_open(log, "a+"); if not logfile then - return function () end + return empty_function; end + local write, flush = logfile.write, logfile.flush; + + eventmanager.add_event_hook("reopen-log-files", function () + if logfile then + logfile:close(); + end + logfile = io_open(log, "a+"); + if not logfile then + write, flush = empty_function, empty_function; + else + write, flush = logfile.write, logfile.flush; + end + end); local timestamps = config.timestamps; @@ -203,7 +217,6 @@ function log_sink_types.file(config) timestamps = default_timestamp; -- Default format end - local write, format, flush = logfile.write, format, logfile.flush; return function (name, level, message, ...) if timestamps then write(logfile, os_date(timestamps), " "); -- cgit v1.2.3 From a4afb372653da9df1bc407230838a7bb958242ac Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 5 May 2009 14:19:45 +0100 Subject: mod_posix: Reload the config and reopen log files on SIGHUP --- plugins/mod_posix.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua index e6f17cc1..f8a168f0 100644 --- a/plugins/mod_posix.lua +++ b/plugins/mod_posix.lua @@ -86,16 +86,18 @@ end module:add_event_hook("server-stopped", remove_pidfile); --- Set signal handler +-- Set signal handlers if signal.signal then signal.signal("SIGTERM", function () - module:log("warn", "Received SIGTERM..."); + module:log("warn", "Received SIGTERM"); _G.unlock_globals(); - if _G.prosody_shutdown then - _G.prosody_shutdown("Received SIGTERM"); - else - module:log("warn", "...no prosody_shutdown(), ignoring."); - end + _G.prosody_shutdown("Received SIGTERM"); _G.lock_globals(); end); + + signal.signal("SIGHUP", function () + module:log("info", "Received SIGHUP"); + _G.prosody_reload_config(); + _G.prosody_reopen_logfiles(); + end); end -- cgit v1.2.3