Subject: | incorrect testing of values returned by getgrnam and getpwnam |
Net::Daemon dies with an error when I try to run my server as root:
$ perl -Mblib -MNet::Daemon -we 'Net::Daemon->new({ user => "root", group => "root", pidfile => "none", localport => 1034 })->Bind'
Using /home/test/.cpan/build/Net-Daemon-0.37/blib
Cannot determine gid of root: at /home/test/.cpan/build/Net-Daemon-0.37/blib/lib/Net/Daemon.pm line 569. at /home/test/.cpan/build/Net-Daemon-0.37/blib/lib/Net/Daemon/Log.pm line 130.
The test "if (my $gid = getgrnam($group))" needs to be changed to
"if (defined(my $gid = getgrnam($group)))" to make it work when user or group is given by name and its ID is zero.
--- lib/Net/Daemon.pm.orig Tue Aug 20 21:44:06 2002
+++ lib/Net/Daemon.pm Fri Nov 7 17:11:34 2003
@@ -563,7 +563,7 @@
$self->Debug("Changing GID to $group");
my $gid;
if ($group !~ /^\d+$/) {
- if (my $gid = getgrnam($group)) {
+ if (defined(my $gid = getgrnam($group))) {
$group = $gid;
} else {
$self->Fatal("Cannot determine gid of $group: $!");
@@ -575,7 +575,7 @@
$self->Debug("Changing UID to $user");
my $uid;
if ($user !~ /^\d+$/) {
- if (my $uid = getpwnam($user)) {
+ if (defined(my $uid = getpwnam($user))) {
$user = $uid;
} else {
$self->Fatal("Cannot determine uid of $user: $!");