[Slim-Checkins] r10022 - in /branches/6.5/server: Slim/bootstrap.pm slimserver.pl

dsully at svn.slimdevices.com dsully at svn.slimdevices.com
Sun Sep 24 13:40:29 PDT 2006


Author: dsully
Date: Sun Sep 24 13:40:28 2006
New Revision: 10022

URL: http://svn.slimdevices.com?rev=10022&view=rev
Log:
Bug: N/A
Description: Merge from trunk -r 10015:10020

Modified:
    branches/6.5/server/Slim/bootstrap.pm
    branches/6.5/server/slimserver.pl

Modified: branches/6.5/server/Slim/bootstrap.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/bootstrap.pm?rev=10022&r1=10021&r2=10022&view=diff
==============================================================================
--- branches/6.5/server/Slim/bootstrap.pm (original)
+++ branches/6.5/server/Slim/bootstrap.pm Sun Sep 24 13:40:28 2006
@@ -19,16 +19,6 @@
 use File::Spec::Functions qw(:ALL);
 use POSIX ":sys_wait_h";
 use Symbol;
-
-BEGIN {
-	# Don't allow the server to be started as root.
-	# MySQL can't be run as root, and it's generally a bad idea anyways.
-	if ($^O ne 'MSWin32' && $> == 0) {
-
-		print "* Error: SlimServer must not be run as root! Exiting! *\n";
-		exit;
-	}
-}
 
 # loadModules contains some trickery to deal with modules
 # that need to load XS code. Previously, we would check in a module

Modified: branches/6.5/server/slimserver.pl
URL: http://svn.slimdevices.com/branches/6.5/server/slimserver.pl?rev=10022&r1=10021&r2=10022&view=diff
==============================================================================
--- branches/6.5/server/slimserver.pl (original)
+++ branches/6.5/server/slimserver.pl Sun Sep 24 13:40:28 2006
@@ -854,6 +854,33 @@
 
 sub changeEffectiveUserAndGroup {
 
+	# Windows doesn't have getpwnam, and the uid is always 0.
+	if ($^O eq 'MSWin32') {
+		return;
+	}
+
+	# Don't allow the server to be started as root.
+	# MySQL can't be run as root, and it's generally a bad idea anyways.
+	#
+	# See if there's a slimserver user we can switch to.
+	if ($> == 0 && !$user) {
+
+		my $testUser = 'slimserver';
+		my $uid      = getpwnam($testUser);
+
+		if ($> == 0 && (!defined $uid || $uid == 0)) {
+
+			# Don't allow the server to be started as root.
+			# MySQL can't be run as root, and it's generally a bad idea anyways.
+			print "* Error: SlimServer must not be run as root! Exiting! *\n";
+			exit;
+
+		} else {
+
+			$user = $testUser;
+		}
+	}
+
 	# Do we want to change the effective user or group?
 	if (defined($user) || defined($group)) {
 



More information about the checkins mailing list