1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#!/usr/bin/perl -w
use strict;
use IO::Async::Test;
use Test::More;
use POSIX qw( WEXITSTATUS );
# These tests check the parts of Loop->spawn_child that need to be root to
# work. Since we're unlikely to be root, skip the lot if we're not.
if( $< == 0 ) {
plan tests => 5;
}
else {
plan skip_all => "not root";
}
is( $>, 0, 'am root');
require IO::Async::Loop::Poll;
my $loop = IO::Async::Loop::Poll->new;
testing_loop( $loop );
my ( $exitcode, $dollarbang, $dollarat );
$loop->spawn_child(
code => sub { return $> },
setup => [ setuid => 10 ],
on_exit => sub { ( undef, $exitcode, $dollarbang, $dollarat ) = @_ },
);
wait_for { defined $exitcode };
is( WEXITSTATUS($exitcode), 10, 'setuid' );
$loop->spawn_child(
code => sub { return $) },
setup => [ setgid => 10 ],
on_exit => sub { ( undef, $exitcode, $dollarbang, $dollarat ) = @_ },
);
undef $exitcode;
wait_for { defined $exitcode };
is( WEXITSTATUS($exitcode), 10, 'setgid' );
$loop->spawn_child(
code => sub { return $) =~ m/ 5 / },
setup => [ setgroups => [ 4, 5, 6 ] ],
on_exit => sub { ( undef, $exitcode, $dollarbang, $dollarat ) = @_ },
);
undef $exitcode;
wait_for { defined $exitcode };
is( WEXITSTATUS($exitcode), 1, 'setgroups' );
my $child_out;
$loop->run_child(
code => sub {
print "EUID: $>\n";
my ( $gid, @groups ) = split( m/ /, $) );
print "EGID: $gid\n";
print "Groups: " . join( " ", sort { $a <=> $b } @groups ) . "\n";
return 0;
},
setup => [
setgid => 10,
setgroups => [ 4, 5, 6, 10 ],
setuid => 20,
],
on_finish => sub { ( undef, $exitcode, $child_out ) = @_; },
);
undef $exitcode;
wait_for { defined $exitcode };
is( $child_out,
"EUID: 20\nEGID: 10\nGroups: 4 5 6 10\n",
'combined setuid/gid/groups' );
|