[Slim-Checkins] r10016 - in /trunk/server: Slim/bootstrap.pm
slimserver.pl
dsully at svn.slimdevices.com
dsully at svn.slimdevices.com
Sun Sep 24 08:15:36 PDT 2006
Author: dsully
Date: Sun Sep 24 08:15:35 2006
New Revision: 10016
URL: http://svn.slimdevices.com?rev=10016&view=rev
Log:
Bug: N/A
Description: Better root detection. Try to change to the 'slimserver' user if it exists, even if the --user option wasn't specified.
Modified:
trunk/server/Slim/bootstrap.pm
trunk/server/slimserver.pl
Modified: trunk/server/Slim/bootstrap.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/bootstrap.pm?rev=10016&r1=10015&r2=10016&view=diff
==============================================================================
--- trunk/server/Slim/bootstrap.pm (original)
+++ trunk/server/Slim/bootstrap.pm Sun Sep 24 08:15:35 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: trunk/server/slimserver.pl
URL: http://svn.slimdevices.com/trunk/server/slimserver.pl?rev=10016&r1=10015&r2=10016&view=diff
==============================================================================
--- trunk/server/slimserver.pl (original)
+++ trunk/server/slimserver.pl Sun Sep 24 08:15:35 2006
@@ -853,51 +853,72 @@
sub changeEffectiveUserAndGroup {
+ # 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.
+ my $testUser = 'slimserver';
+ my $uid = getpwnam($testUser);
+
+ if ($^O ne 'MSWin32' && $> == 0 && !$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)) {
-
- # Can only change effective UID/GID if root
- if ($> != 0) {
- my $uname = getpwuid($>);
- print STDERR "Current user is $uname\n";
- print STDERR "Must run as root to change effective user or group.\n";
- die "Aborting";
+ if (!defined($user) && !defined($group)) {
+
+ return;
+ }
+
+ # Can only change effective UID/GID if root
+ if ($> != 0) {
+ my $uname = getpwuid($>);
+ print STDERR "Current user is $uname\n";
+ print STDERR "Must run as root to change effective user or group.\n";
+ die "Aborting";
+ }
+
+ # Change effective group ID if necessary
+ # Need to do this while still root, so do group first
+ if (defined($group)) {
+
+ my $gid = getgrnam($group);
+
+ if (!defined $gid) {
+ die "Group $group not found.\n";
}
- # Change effective group ID if necessary
- # Need to do this while still root, so do group first
- if (defined($group)) {
-
- my $gid = getgrnam($group);
-
- if (!defined $gid) {
- die "Group $group not found.\n";
- }
-
- $) = $gid;
-
- # $) is a space separated list that begins with the effective gid then lists
- # any supplementary group IDs, so compare against that. On some systems
- # no supplementary group IDs are present at system startup or at all.
- if ( $) !~ /^$gid\b/) {
- die "Unable to set effective group(s) to $group ($gid) is: $): $!\n";
- }
+ $) = $gid;
+
+ # $) is a space separated list that begins with the effective gid then lists
+ # any supplementary group IDs, so compare against that. On some systems
+ # no supplementary group IDs are present at system startup or at all.
+ if ( $) !~ /^$gid\b/) {
+ die "Unable to set effective group(s) to $group ($gid) is: $): $!\n";
}
-
- # Change effective user ID if necessary
- if (defined($user)) {
-
- my $uid = getpwnam($user);
-
- if (!defined ($uid)) {
- die "User $user not found.\n";
- }
-
- $> = $uid;
-
- if ($> != $uid) {
- die "Unable to set effective user to $user, ($uid)!\n";
- }
+ }
+
+ # Change effective user ID if necessary
+ if (defined($user)) {
+
+ my $uid = getpwnam($user);
+
+ if (!defined ($uid)) {
+ die "User $user not found.\n";
+ }
+
+ $> = $uid;
+
+ if ($> != $uid) {
+ die "Unable to set effective user to $user, ($uid)!\n";
}
}
}
More information about the checkins
mailing list