From 71fd6f0779c461a526a79dde7fc65883c762e7b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Wed, 8 May 2013 22:29:43 +0200 Subject: [PATCH] Make it possible to set user/group to root/root Change the check for valid users/groups to check for definiedness instead of for whether the return value is true. Makes it possible to run a daemon as root/root. --- Changes | 4 ++++ lib/Daemon/Control.pm | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index ec23cc3..2347f09 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,7 @@ + * Due to checking for true values instead of define it was + possible to start a daemon as root by setting uid/gid to 0/0, + but not user/group to root/root, which would resolve to 0/0 and + be considered an invalid user, which it's not. * Fix an encoding error in the POD resulting from Ævar Arnfjörð Bjarmason contributing to the project. * Tests that invoke Perl now use $^X instead of the $PATH's perl. diff --git a/lib/Daemon/Control.pm b/lib/Daemon/Control.pm index 8aa470a..a29d930 100644 --- a/lib/Daemon/Control.pm +++ b/lib/Daemon/Control.pm @@ -94,7 +94,7 @@ sub _set_uid_from_name { my ( $self, $name ) = @_; my $uid = getpwnam( $name ); die "Error: Couldn't get uid for non-existent user " . $self->user - unless $uid; + unless defined $uid; $self->trace( "Set UID => $uid" ); $self->uid( $uid ); } @@ -104,7 +104,7 @@ sub _set_gid_from_name { my ( $self, $name ) = @_; my $gid = getgrnam( $name ); die "Error: Couldn't get gid for non-existent group " . $self->group - unless $gid; + unless defined $gid; $self->trace( "Set GID => $gid" ); $self->gid( $gid );