| 1 | package Filesys::POSIX::ReducedPrivileges::Directory; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # Copyright (c) 2016, cPanel, Inc. | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # http://cpanel.net/ | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under the same | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # terms as Perl itself. See the LICENSE file for further details. | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Filesys::POSIX::Real::Directory (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | our @ISA = qw(Filesys::POSIX::Real::Directory); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my ( $class, $path, $inode ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | unless ( defined $inode->{dev} && ref $inode->{dev} && $inode->{dev}->isa('Filesys::POSIX::ReducedPrivileges') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $inode->{"dev"} and ref $inode->{"dev"} and $inode->{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")
defined $inode->{"dev"} and ref $inode->{"dev"}
MC/DC0%0/3
defined $inode->{"dev"} and ref $inode->{"dev"} and $inode->{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")
defined $inode->{"dev"}
ref $inode->{"dev"}
$inode->{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")
Truth table0%0/4
A and B and C
A= defined $inode->{"dev"}B= ref $inode->{"dev"}C= $inode->{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | Carp::confess("invalid filesystem device"); | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | return $class->SUPER::new( $path, $inode ); | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub _sync_member { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sync_member: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $self->{inode}{dev}->enter_filesystem(); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $subpath = "$self->{'path'}/$name"; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my @st = lstat $subpath; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ( scalar @st == 0 && $!{'ENOENT'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @st == 0 and $!{"ENOENT"}
MC/DC0%0/2
scalar @st == 0 and $!{"ENOENT"}
scalar @st == 0
$!{"ENOENT"}
Truth table0%0/3
A and B
A= scalar @st == 0B= $!{"ENOENT"}
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | delete $self->{'members'}->{$name}; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | Carp::confess($!) unless @st; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ( exists $self->{'members'}->{$name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $self->{'members'}->{$name}->update(@st); | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 47 | $self->{'members'}->{$name} = Filesys::POSIX::ReducedPrivileges::Inode->from_disk( | ||||||||||||||||||||||||||||||||||||||||||
| 48 | $subpath, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 'st_info' => \@st, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 'dev' => $self->{'inode'}->{'dev'}, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | 'parent' => $self->{'inode'} | |||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $self->{inode}{dev}->exit_filesystem(); | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | die $_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $self->{inode}{dev}->exit_filesystem(); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Wrap all of the normal Inode methods with privilege dropping and restoring. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=13.0
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | foreach my $method (qw(_sync_all rename_member delete open rewind read close)) { | |||||||||||||||||||||||||||||||||||||||||
| 67 | 7 | my $super_method = "SUPER::$method"; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 7 | ▶ | *{ __PACKAGE__ . "::$method" } = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=23.8
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $self->{inode}{dev}->enter_filesystem(); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $context = wantarray(); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my @result; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ($context) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | @result = $self->$super_method(@args); | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | elsif ( defined $context ) { | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | @result = ( scalar $self->$super_method(@args) ); | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $self->$super_method(@args); | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $self->{inode}{dev}->exit_filesystem(); | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | die $_; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $self->{inode}{dev}->exit_filesystem(); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return $context ? @result : defined $context ? $result[0] : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 7 | }; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||