POSIX/ReducedPrivileges/Inode.pm

filter: Statementstmt 59.7% 43 / 72 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 65.0% 13 / 20 Podpod 0.0% 0 / 2 totaltotal 44.4% 56 / 126 CC 13 SCAR 23.1
CC
13
Cov
44%
from_disk
30.0
new
20.0
__ANON__
12.0
CRAP 10.1
« POSIX/Real/Directory.pm ↑ Summary POSIX/ReducedPrivileges.pm »
1 package Filesys::POSIX::ReducedPrivileges::Inode;
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::ReducedPrivileges::Directory ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Filesys::POSIX::Real::Inode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Filesys::POSIX::Mem::Inode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Filesys::POSIX::Bits;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Filesys::POSIX::Bits::System;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Filesys::POSIX::Error qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Fcntl qw(:DEFAULT :mode);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 our @ISA = qw(Filesys::POSIX::Real::Inode);
25 1 our $AUTOLOAD;
26  
27 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
28 0 my ( $class, $path, %opts ) = @_;
29 0 ▶ unless ( defined $opts{dev} && ref $opts{dev} && $opts{dev}->isa('Filesys::POSIX::ReducedPrivileges') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"dev"} and ref $opts{"dev"} and $opts{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")) 0 0 0
Condition0%0/6
defined $opts{"dev"} and ref $opts{"dev"} and $opts{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")
!ll&&!rl&&r
000
defined $opts{"dev"} and ref $opts{"dev"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $opts{"dev"} and ref $opts{"dev"} and $opts{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")
defined $opts{"dev"} ref $opts{"dev"} $opts{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")
Truth table0%0/4
A and B and C
A= defined $opts{"dev"}B= ref $opts{"dev"}C= $opts{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")
ABCresult
0XX0
10X0
1100
1111
30 0 Carp::confess("invalid filesystem device");
31 }
32  
33 # No need to enter the ReducedContext for new. No file operations are performed.
34 # Typically new() is called by from_disk() anyway
35 0 return $class->SUPER::new( $path, %opts );
36 }
37  
38 0 ▶sub from_disk {
Subroutine from_disk: not called CC=5 SCAR=34.0
Pod undocumented
39 0 my ( $class, $path, %opts ) = @_;
40 0 ▶ unless ( defined $opts{dev} && ref $opts{dev} && $opts{dev}->isa('Filesys::POSIX::ReducedPrivileges') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"dev"} and ref $opts{"dev"} and $opts{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")) 0 0 0
Condition0%0/6
defined $opts{"dev"} and ref $opts{"dev"} and $opts{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")
!ll&&!rl&&r
000
defined $opts{"dev"} and ref $opts{"dev"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $opts{"dev"} and ref $opts{"dev"} and $opts{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")
defined $opts{"dev"} ref $opts{"dev"} $opts{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")
Truth table0%0/4
A and B and C
A= defined $opts{"dev"}B= ref $opts{"dev"}C= $opts{"dev"}->isa("Filesys::POSIX::ReducedPrivileges")
ABCresult
0XX0
10X0
1100
1111
41 0 Carp::confess("invalid filesystem device");
42 }
43  
44 0 my $self;
45 0 $opts{dev}->enter_filesystem();
46 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 $self = $class->SUPER::from_disk( $path, %opts );
48 }
49 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 $opts{dev}->exit_filesystem();
51 0 die $_;
52 0 };
53  
54 0 $opts{dev}->exit_filesystem();
55  
56 # Fix the class of the directory object
57 0 ▶ bless $self->{directory}, 'Filesys::POSIX::ReducedPrivileges::Directory' if ( ref $self->{directory} );
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"directory"} 0 0 0
58  
59 0 return $self;
60 }
61  
62 # Wrap the normal Inode methods that do actual filesystem activity with privilege dropping and restoring.
63 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=13.0
64 1 foreach my $method (qw(open chown chmod readlink symlink child)) {
65 6 my $super_method = "SUPER::$method";
66 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
67 6 ▶ *{ __PACKAGE__ . "::$method" } = sub {
Subroutine __ANON__: not called CC=3 SCAR=23.8
68 0 my ( $self, @args ) = @_;
69 0 $self->{dev}->enter_filesystem();
70 0 my $context = wantarray();
71 0 my @result;
72 0 ▶ try {
Subroutine __ANON__: not called CC=3 SCAR=24.8
73 0 ▶ if ($context) {
Branch: 2 branches
BranchTrueFalseTotal
if ($context) { } 0 0 0
elsif (defined $context) { } 0 0 0
74 0 @result = $self->$super_method(@args);
75 }
76 elsif ( defined $context ) {
77 0 @result = ( scalar $self->$super_method(@args) );
78 }
79 else {
80 0 $self->$super_method(@args);
81 }
82 }
83 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 0 $self->{dev}->exit_filesystem();
85 0 die $_;
86 0 };
87 0 $self->{dev}->exit_filesystem();
88 0 ▶ return $context ? @result : defined $context ? $result[0] : ();
Branch: 2 branches
BranchTrueFalseTotal
$context ? : 0 0 0
defined $context ? : 0 0 0
89 6 };
90 }
91 }
92  
93 1 1;
« POSIX/Real/Directory.pm ↑ Summary POSIX/ReducedPrivileges.pm »