| 1 | package Ubic::Credentials::OS::POSIX; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 172 | $Ubic::Credentials::OS::POSIX::VERSION = '1.59'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 172 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 172 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 172 | ▶ | use parent qw(Ubic::Credentials); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # ABSTRACT: POSIX-specific credentials implementation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 172 | ▶ | use List::MoreUtils qw(uniq); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 172 | ▶ | use Params::Validate qw(:all); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 172 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 952 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 952 | my $params = validate(@_, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | user => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | group => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | service => { optional => 1, isa => 'Ubic::Service' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 952 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 952 | ▶ | if (defined $params->{user}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | if (defined $params->{service}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | croak "Only one of 'user' and 'service' parameters should be specified"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $self->{user} = $params->{user}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $self->{group} = $params->{group} if defined $params->{group}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | elsif (defined $params->{service}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 514 | $self->{user} = $params->{service}->user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 514 | my @group = $params->{service}->group; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 514 | ▶ | $self->{group} = [ @group ] if @group; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 438 | $self->{real_user_id} = $<; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 438 | $self->{effective_user_id} = $>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 438 | $self->{real_group_id} = [ split / /, $( ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 438 | $self->{effective_group_id} = [ split / /, $) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # TODO - derive user from real_user_id when user is not specified (or from effective_user_id?!) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 952 | return bless $self => $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | sub user { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 1198 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
user: called CC=3 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1198 | ▶ | unless (defined $self->{user}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $user = getpwuid($>); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | unless (defined $user) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | die "failed to get user name by uid $>"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $self->{user} = $user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1198 | return $self->{user}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | sub group { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 684 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
group: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 684 | ▶ | unless (defined $self->{group}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 514 | $self->_user2group; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 684 | ▶ | unless (ref $self->{group}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->{group} = [ $self->{group} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 684 | return @{ $self->{group} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | sub _user2uid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 340 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_user2uid: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 340 | my $user = $self->user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 340 | my $id = scalar getpwnam($user); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 340 | ▶ | unless (defined $id) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | die "user $user not found"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 340 | return $id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | sub real_user_id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 264 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
real_user_id: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 264 | ▶ | return $self->{real_user_id} if defined $self->{real_user_id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 170 | return $self->_user2uid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | sub effective_user_id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 608 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
effective_user_id: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 608 | ▶ | return $self->{effective_user_id} if defined $self->{effective_user_id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 170 | return $self->_user2uid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | sub _group2gid { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 340 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_group2gid: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 340 | my @group = $self->group; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 340 | my @gid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 340 | for my $group (@group) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 340 | my $gid = getgrnam($group); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 340 | ▶ | unless (defined $gid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | croak "group $group not found"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 340 | push @gid, $gid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 340 | ▶ | @gid = (@gid, @gid) if @gid == 1; # otherwise $) = "1 0"; $) = "1" leaves 0 in group list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 340 | return @gid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | sub real_group_id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 264 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
real_group_id: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 264 | ▶ | return @{ $self->{real_group_id} } if defined $self->{real_group_id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 170 | return $self->_group2gid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | sub effective_group_id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 608 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
effective_group_id: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 608 | ▶ | return @{ $self->{effective_group_id} } if defined $self->{effective_group_id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 170 | return $self->_group2gid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | sub _user2group { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 514 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_user2group: called CC=6 SCAR=18.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 514 | my $user = $self->user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 514 | ▶ | confess "user not defined" unless defined $user; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 514 | my @pwnam = getpwnam $user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 514 | ▶ | unless (@pwnam) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | die "getpwnam failed for user $user"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 514 | my $group_id = $pwnam[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 514 | my $main_group = getgrgid($group_id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 514 | ▶ | unless ($main_group) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | die "failed to get group name by gid $group_id"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # TODO - can getgrent fail? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 514 | setgrent(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 514 | my @groups; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 514 | ▶ | while (my @grent = getgrent()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 20560 | my @users = split / /, $grent[3]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 20560 | ▶ | push @groups, $grent[0] if grep { $_ eq $user } @users; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 514 | endgrent(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 514 | $self->{group} = [ $main_group, @groups ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | sub set_effective { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 344 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_effective: called CC=10 SCAR=29.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 344 | my $current_creds = Ubic::Credentials->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 344 | my $euid = $current_creds->effective_user_id(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 344 | my ($egid) = $current_creds->effective_group_id(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 344 | $egid =~ s/^(\d+).*/$1/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 344 | my $current_user = getpwuid($euid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 344 | ▶ | unless (defined $current_user) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | die "failed to get current user name by euid $euid"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 344 | my $current_group = getgrgid($egid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 344 | ▶ | unless (defined $current_group) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | die "failed to get current group name by egid $egid"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 344 | my $user = $self->user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 344 | my ($group) = $self->group; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 344 | ▶ | if ($group ne $current_group) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | $self->{old_egid} = $); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | my $new_gid = getgrnam($group); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | ▶ | unless (defined $new_gid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | die "group $group not found"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # AccessGuard don't need to handle supplementary groups correctly, so this is ok | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | $) = "$new_gid 0"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | my ($current_gid) = $) =~ /^(\d+)/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | ▶ | if ($current_gid != $new_gid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | die "Failed to change group from $current_group to $group: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 343 | ▶ | if ($user ne $current_user) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $self->{old_euid} = $>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if ($current_user ne 'root') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | die "Can't change user from $current_user to $user"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $new_uid = getpwnam($user); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | unless (defined $new_uid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | die "user $user not found"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $> = $new_uid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ($> != $new_uid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | die "Failed to change user from $current_user to $user: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | sub _groups_equal { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 342 | ▶ | my ($self, $g1, $g2) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_groups_equal: called CC=2 SCAR=8.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 342 | my ($main1, @other1) = split / /, $g1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 342 | my ($main2, @other2) = split / /, $g2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 342 | ▶ | return ($main1 == $main2 and join(' ', sort { $a <=> $b } uniq($main1, @other1)) eq join(' ', sort { $a <=> $b } uniq($main2, @other2))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$main1 == $main2 && join(' ', (sort {$a <=> $b;} &uniq($main1, @other1))) eq join(' ', (sort {$a <=> $b;} &uniq($main2, @other2)))
MC/DC0%0/2
$main1 == $main2 && join(' ', (sort {$a <=> $b;} &uniq($main1, @other1))) eq join(' ', (sort {$a <=> $b;} &uniq($main2, @other2)))
$main1 == $main2
join(' ', (sort {$a <=> $b;} &uniq($main1, @other1))) eq join(' ', (sort {$a <=> $b;} &uniq($main2, @other2)))
Truth table33%1/3
A && B
A= $main1 == $main2B= join(' ', (sort {$a <=> $b;} &uniq($main1, @other1))) eq join(' ', (sort {$a <=> $b;} &uniq($main2, @other2)))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | sub reset_effective { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 344 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
reset_effective: called CC=5 SCAR=20.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 344 | ▶ | if (defined $self->{old_euid}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $> = $self->{old_euid}; # return euid back to normal | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if ($> != $self->{old_euid}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | warn "Failed to restore euid from $> to $self->{old_euid}: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 344 | ▶ | if (defined $self->{old_egid}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | $) = $self->{old_egid}; # return egid back to normal | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ▶ | if ($) != $self->{old_egid}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | warn "Failed to restore egid from '$)' to '$self->{old_egid}': $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | sub eq { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 93 | ▶ | my ($self, $other) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eq: called CC=5 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 93 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$self->effective_user_id == $other->effective_user_id and $self->real_user_id == $other->real_user_id and $self->_groups_equal(join(" ", $self->effective_group_id), join(" ", $other->effective_group_id)) and $self->_groups_equal(join(" ", $self->real_group_id), join(" ", $other->real_group_id))
$self->effective_user_id == $other->effective_user_id and $self->real_user_id == $other->real_user_id and $self->_groups_equal(join(" ", $self->effective_group_id), join(" ", $other->effective_group_id))
$self->effective_user_id == $other->effective_user_id and $self->real_user_id == $other->real_user_id
MC/DC0%0/4
$self->effective_user_id == $other->effective_user_id and $self->real_user_id == $other->real_user_id and $self->_groups_equal(join(" ", $self->effective_group_id), join(" ", $other->effective_group_id)) and $self->_groups_equal(join(" ", $self->real_group_id), join(" ", $other->real_group_id))
$self->effective_user_id == $other->effective_user_id
$self->real_user_id == $other->real_user_id
$self->_groups_equal(join(" ", $self->effective_group_id), join(" ", $other->effective_group_id))
$self->_groups_equal(join(" ", $self->real_group_id), join(" ", $other->real_group_id))
Truth table20%1/5
A and B and C and D
A= $self->effective_user_id == $other->effective_user_idB= $self->real_user_id == $other->real_user_idC= $self->_groups_equal(join(" ", $self->effective_group_id), join(" ", $other->effective_group_id))D= $self->_groups_equal(join(" ", $self->real_group_id), join(" ", $other->real_group_id))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | $self->effective_user_id == $other->effective_user_id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | and $self->real_user_id == $other->real_user_id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | and $self->_groups_equal(join(" ", $self->effective_group_id), join(" ", $other->effective_group_id)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | and $self->_groups_equal(join(" ", $self->real_group_id), join(" ", $other->real_group_id)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 93 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | sub set { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 78 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=5 SCAR=17.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 78 | my @effective_gid = $self->effective_group_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 78 | $) = "@effective_gid"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 78 | ▶ | unless ($self->_groups_equal($), "@effective_gid")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | die "Failed to set effective gid to @effective_gid: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 78 | my $new_euid = $self->effective_user_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 78 | $> = $new_euid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 78 | ▶ | unless ($> == $new_euid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | die "Failed to set effective uid to $new_euid: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 78 | my @real_gid = $self->real_group_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 78 | $( = $real_gid[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 78 | ▶ | unless ($self->_groups_equal($(, "@real_gid")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | die "Failed to set real gid to @real_gid: $! (\$( = $(, real_gid = @real_gid)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 78 | my $new_ruid = $self->real_user_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 78 | $< = $new_ruid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 78 | ▶ | unless ($< == $new_ruid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | die "Failed to set real uid to $new_ruid: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | sub as_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $user = $self->user; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my ($group) = $self->group; # ignore complementary groups for the sake of readability | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | return "$user:$group"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 172 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||