[Slim-Checkins] r10020 - /trunk/server/slimserver.pl
dsully at svn.slimdevices.com
dsully at svn.slimdevices.com
Sun Sep 24 11:00:18 PDT 2006
Author: dsully
Date: Sun Sep 24 11:00:17 2006
New Revision: 10020
URL: http://svn.slimdevices.com?rev=10020&view=rev
Log:
Bug: N/A
Description: More tweaks to the root / user issue.
Modified:
trunk/server/slimserver.pl
Modified: trunk/server/slimserver.pl
URL: http://svn.slimdevices.com/trunk/server/slimserver.pl?rev=10020&r1=10019&r2=10020&view=diff
==============================================================================
--- trunk/server/slimserver.pl (original)
+++ trunk/server/slimserver.pl Sun Sep 24 11:00:17 2006
@@ -862,68 +862,69 @@
# 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 ($> == 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;
+ 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)) {
-
- 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";
+ 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";
}
- $) = $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 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";
+ }
}
- }
-
- # 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