Skip to content

Commit

Permalink
improved setuidgid in Mojo::Server::Daemon slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 4, 2011
1 parent 8e8a87d commit 90cd440
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,10 +1,11 @@
This file documents the revision history for Perl extension Mojolicious.

2.0 2011-10-04 00:00:00
2.0 2011-10-05 00:00:00
- Code name "Leaf Fluttering In Wind", this is a major release.
- Increased Perl version requirement to 5.10.1.
- Improved message parser performance slightly.
- Improved Mojo::IOLoop to die if started twice.
- Improved setuidgid in Mojo::Server::Daemon slightly.
- Improved documentation.
- Improved tests.
- Fixed many portability issues.
Expand Down
45 changes: 22 additions & 23 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -81,29 +81,8 @@ sub run {

sub setuidgid {
my $self = shift;

# Group
if (my $group = $self->group) {
if (my $gid = (getgrnam($group))[2]) {

# Switch
undef $!;
$) = $gid;
croak qq/Can't switch to effective group "$group": $!/ if $!;
}
}

# User
if (my $user = $self->user) {
if (my $uid = (getpwnam($user))[2]) {

# Switch
undef $!;
$> = $uid;
croak qq/Can't switch to effective user "$user": $!/ if $!;
}
}

$self->_group;
$self->_user;
return $self;
}

Expand Down Expand Up @@ -230,6 +209,16 @@ sub _finish {
}
}

sub _group {
my $self = shift;
return unless my $group = $self->group;
croak qq/Group "$group" does not exist/
unless defined(my $gid = (getgrnam($group))[2]);
undef $!;
$( = $) = $gid;
croak qq/Can't switch to group "$group": $!/ if $!;
}

sub _listen {
my ($self, $listen) = @_;
return unless $listen;
Expand Down Expand Up @@ -325,6 +314,16 @@ sub _upgrade {
$ws->on_resume(sub {1});
}

sub _user {
my $self = shift;
return unless my $user = $self->user;
croak qq/User "$user" does not exist/
unless defined(my $uid = (getpwnam($self->user))[2]);
undef $!;
$< = $> = $uid;
croak qq/Can't switch to user "$user": $!/ if $!;
}

sub _write {
my ($self, $id) = @_;

Expand Down

0 comments on commit 90cd440

Please sign in to comment.