Diff

prosodyctl @ 1119:61a011ebe243

Merge with 0.4
author Matthew Wild <mwild1@gmail.com>
date Tue, 05 May 2009 14:20:26 +0100
parent 1115:8a7bc1a5eae6
child 1120:23fa69b911f7
line wrap: on
line diff
--- a/prosodyctl	Mon May 04 19:57:05 2009 +0100
+++ b/prosodyctl	Tue May 05 14:20:26 2009 +0100
@@ -61,6 +61,29 @@
 	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";
@@ -291,6 +314,11 @@
 		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;