aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-05-05 13:23:46 +0100
committerMatthew Wild <mwild1@gmail.com>2009-05-05 13:23:46 +0100
commitb84c790f0ba57f11bbe6bf01bbbc45337c7b9943 (patch)
tree931589aeb7f4fc19796e4c08b6b73be2c6c30dbb
parent964ee27096880d45010375e937ef3f1702d128b7 (diff)
downloadprosody-b84c790f0ba57f11bbe6bf01bbbc45337c7b9943.tar.gz
prosody-b84c790f0ba57f11bbe6bf01bbbc45337c7b9943.zip
prosodyctl: Switch to Prosody user before attempting to do anything
-rwxr-xr-xprosodyctl23
1 files changed, 23 insertions, 0 deletions
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";