Match/UID.pm

filter: Statementstmt 78.2% 54 / 69 Branchbran 64.0% 32 / 50 Conditioncond 88.8% 8 / 9 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 75.3% 107 / 142 CC 29 SCAR 35.9
CC
29
Cov
73%
match
48.1
new
5.1
BEGIN
1.0
CRAP 36.3
↑ Summary Match/PctMem.pm »
1 package Proc::ProcessTable::Match::UID;
2  
3 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use User::pwent;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Proc::ProcessTable::Match::UID - Check if the UID or username of a process matches.
11  
12 =head1 VERSION
13  
14 Version 0.1.0
15  
16 =cut
17  
18 3 our $VERSION = '0.1.0';
19  
20  
21 =head1 SYNOPSIS
22  
23 use Proc::ProcessTable::Match::UID;
24
25 my %args=(
26 uids=>[
27 0,
28 '>1000',
29 '!foo',
30 'www'
31 ],
32 );
33
34 my $checker=Proc::ProcessTable::Match::UID->new( \%args );
35
36 if ( $checker->match( $proc ) ){
37 print "It matches.\n";
38 }
39  
40 =head1 METHODS
41  
42 =head2 new
43  
44 This intiates the object.
45  
46 It takes a hash reference with one key. One key is required and
47 that is 'uids', which is a array of UIDs or usernames to match.
48  
49 The values can be prefixed with the equalities below for doing
50 additional comparisons.
51  
52 <
53 <=
54 >
55 >=
56 !
57  
58 If a username is specified, only ! is valid. Otherwise the rest will
59 result in a unresolved or misresolved username to UID.
60  
61 Atleast one value must be specified.
62  
63 If the new method fails, it dies.
64  
65 my %args=(
66 uids=>[
67 0,
68 '>1000',
69 '!foo',
70 'www'
71 ],
72 );
73
74 my $checker=Proc::ProcessTable::Match::UID->new( \%args );
75  
76 =cut
77  
78 8 ▶sub new{
Subroutine new: called CC=5 SCAR=16.2
Pod documented
79 8 my %args;
80 8 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 8 0 8
81 8 %args= %{$_[1]};
82 };
83  
84 # run some basic checks to make sure we have the minimum stuff required to work
85 8 ▶ if ( ! defined( $args{uids} ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"uids"}) 1 7 8
86 1 die ('No uids key specified in the argument hash');
87 }
88 7 ▶ if ( ref( $args{uids} ) ne 'ARRAY' ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"uids"} ne "ARRAY") 0 7 7
89 0 die ('The uids key is not a array');
90 }
91 7 ▶ if ( ! defined $args{uids}[0] ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"uids"}[0]) 1 6 7
92 1 die ('Nothing defined in the uids array');
93 }
94  
95 6 my $class=$_[0];
96 my $self = {
97 uids=>$args{uids},
98 6 };
99 6 bless $self, $class;
100  
101 6 return $self;
102 }
103  
104 =head2 match
105  
106 Checks if a single Proc::ProcessTable::Process object matches the stack.
107  
108 One argument is taken and that is a Proc::ProcessTable::Process object.
109  
110 The returned value is a boolean.
111  
112 if ( $checker->match( $proc ) ){
113 print "The process matches.\n";
114 }
115  
116 =cut
117  
118 12 ▶sub match{
Subroutine match: called CC=25 SCAR=38.7
Pod documented
119 12 my $self=$_[0];
120 12 my $object=$_[1];
121  
122 12 ▶ if ( !defined( $object ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $object) 0 12 12
123 0 return 0;
124 }
125  
126 12 ▶ if ( ref( $object ) ne 'Proc::ProcessTable::Process' ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $object ne "Proc::ProcessTable::Process") 0 12 12
127 0 return 0;
128 }
129  
130 12 my $proc_uid;
131 12 eval{
132 12 $proc_uid=$object->uid;
133 };
134  
135 # don't bother proceeding, the object won't match ever
136 # as it does not have a UID
137 12 ▶ if ( ! defined( $proc_uid ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $proc_uid) 1 11 12
138 1 return 0;
139 }
140  
141 # use while as foreach will reference the value
142 11 my $uid_int=0;
143 11 ▶ while (defined( $self->{uids}[$uid_int] )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"uids"}[$uid_int]) 11 6 17
144 11 my $uid=$self->{uids}[$uid_int];
145 11 ▶ if (
Branch: 8 branches
BranchTrueFalseTotal
if ($uid =~ /^[0-9]+$/ and $uid == $proc_uid) { } 2 9 11
elsif ($uid =~ /[A-Za-z]/ and not $uid =~ /^\!/) { } 3 6 9
elsif ($uid =~ /[A-Za-z]/ and $uid =~ /^\!/) { } 1 5 6
elsif ($uid =~ /^\<\=[0-9]+$/) { } 0 5 5
elsif ($uid =~ /^\<[0-9]+$/) { } 0 5 5
elsif ($uid =~ /^\>\=[0-9]+$/) { } 2 3 5
elsif ($uid =~ /^\>[0-9]+$/) { } 0 3 3
elsif ($uid =~ /^\![0-9]+$/) { } 0 3 3
Condition100%3/3
$uid =~ /^[0-9]+$/ and $uid == $proc_uid
!ll&&!rl&&r
632
MC/DC100%2/2
$uid =~ /^[0-9]+$/ and $uid == $proc_uid
$uid =~ /^[0-9]+$/ $uid == $proc_uid
Truth table100%3/3
A and B
A= $uid =~ /^[0-9]+$/B= $uid == $proc_uid
ABresult
0X0
100
111
146 ( $uid =~ /^[0-9]+$/ ) &&
147 ( $uid == $proc_uid )
148 ){
149 2 return 1;
150 ▶ }elsif(
Condition100%3/3
$uid =~ /[A-Za-z]/ and not $uid =~ /^\!/
!ll&&!rl&&r
513
MC/DC100%2/2
$uid =~ /[A-Za-z]/ and not $uid =~ /^\!/
$uid =~ /[A-Za-z]/ not $uid =~ /^\!/
Truth table100%3/3
A and not(B)
A= $uid =~ /[A-Za-z]/B= not $uid =~ /^\!/
ABresult
0X0
100
111
151 ( $uid =~ /[A-Za-z]/ ) &&
152 ( $uid !~ /^\!/ )
153 ){
154 3 my $pw=getpwnam($uid);
155 3 ▶ if ( defined( $pw ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pw) 2 1 3
156 2 ▶ if ( $pw->uid == $proc_uid ){
Branch: 1 branch
BranchTrueFalseTotal
if ($pw->uid == $proc_uid) 1 1 2
157 1 return 1;
158 }
159 }
160 ▶ }elsif(
Condition66%2/3
$uid =~ /[A-Za-z]/ and $uid =~ /^\!/
!ll&&!rl&&r
501
MC/DC50%1/2
$uid =~ /[A-Za-z]/ and $uid =~ /^\!/
$uid =~ /[A-Za-z]/ $uid =~ /^\!/
Truth table66%2/3
A and B
A= $uid =~ /[A-Za-z]/B= $uid =~ /^\!/
ABresult
0X0
100
111
161 ( $uid =~ /[A-Za-z]/ ) &&
162 ( $uid =~ /^\!/ )
163 ){
164 1 $uid =~ s/^\!//;
165 1 my $pw=getpwnam($uid);
166 1 ▶ if ( defined( $pw ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pw) 1 0 1
167 1 ▶ if ( $pw->uid != $proc_uid ){
Branch: 1 branch
BranchTrueFalseTotal
if ($pw->uid != $proc_uid) 1 0 1
168 1 return 1;
169 }
170 }
171 }elsif( $uid =~ /^\<\=[0-9]+$/ ){
172 0 $uid=~s/^\<\=//;
173 0 ▶ if ( $proc_uid <= $uid ){
Branch: 1 branch
BranchTrueFalseTotal
if ($proc_uid <= $uid) 0 0 0
174 0 return 1;
175 }
176 }elsif( $uid =~ /^\<[0-9]+$/ ){
177 0 $uid=~s/^\<//;
178 0 ▶ if ( $proc_uid < $uid ){
Branch: 1 branch
BranchTrueFalseTotal
if ($proc_uid < $uid) 0 0 0
179 0 return 1;
180 }
181 }elsif( $uid =~ /^\>\=[0-9]+$/ ){
182 2 $uid=~s/^\>\=//;
183 2 ▶ if ( $proc_uid >= $uid ){
Branch: 1 branch
BranchTrueFalseTotal
if ($proc_uid >= $uid) 1 1 2
184 1 return 1;
185 }
186 }elsif( $uid =~ /^\>[0-9]+$/ ){
187 0 $uid=~s/^\>//;
188 0 ▶ if ( $proc_uid > $uid ){
Branch: 1 branch
BranchTrueFalseTotal
if ($proc_uid > $uid) 0 0 0
189 0 return 1;
190 }
191 }elsif( $uid =~ /^\![0-9]+$/ ){
192 0 $uid=~s/^\!//;
193 0 ▶ if ( $proc_uid != $uid ){
Branch: 1 branch
BranchTrueFalseTotal
if ($proc_uid != $uid) 0 0 0
194 0 return 1;
195 }
196 }
197 6 $uid_int++;
198 }
199  
200 6 return 0;
201 }
202  
203 =head1 AUTHOR
204  
205 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
206  
207 =head1 BUGS
208  
209 Please report any bugs or feature requests to C<bug-Proc-ProcessTable-Match at rt.cpan.org>, or through
210 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Proc-ProcessTable-Match>. I will be notified, and then you'll
211 automatically be notified of progress on your bug as I make changes.
212  
213  
214  
215  
216 =head1 SUPPORT
217  
218 You can find documentation for this module with the perldoc command.
219  
220 perldoc Proc::ProcessTable::Match
221  
222  
223 You can also look for information at:
224  
225 =over 4
226  
227 =item * RT: CPAN's request tracker (report bugs here)
228  
229 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Proc-ProcessTable-Match>
230  
231 =item * Search CPAN
232  
233 L<https://metacpan.org/release/Proc-ProcessTable-Match>
234  
235 =back
236  
237  
238 =head1 ACKNOWLEDGEMENTS
239  
240  
241 =head1 LICENSE AND COPYRIGHT
242  
243 Copyright 2019 Zane C. Bowers-Hadley.
244  
245 This program is free software; you can redistribute it and/or modify it
246 under the terms of the the Artistic License (2.0). You may obtain a
247 copy of the full license at:
248  
249 L<http://www.perlfoundation.org/artistic_license_2_0>
250  
251 Any use, modification, and distribution of the Standard or Modified
252 Versions is governed by this Artistic License. By using, modifying or
253 distributing the Package, you accept this license. Do not use, modify,
254 or distribute the Package, if you do not accept this license.
255  
256 If your Modified Version has been derived from a Modified Version made
257 by someone other than you, you are nevertheless required to ensure that
258 your Modified Version complies with the requirements of this license.
259  
260 This license does not grant you the right to use any trademark, service
261 mark, tradename, or logo of the Copyright Holder.
262  
263 This license includes the non-exclusive, worldwide, free-of-charge
264 patent license to make, have made, use, offer to sell, sell, import and
265 otherwise transfer the Package with respect to any patent claims
266 licensable by the Copyright Holder that are necessarily infringed by the
267 Package. If you institute patent litigation (including a cross-claim or
268 counterclaim) against any party alleging that the Package constitutes
269 direct or contributory patent infringement, then this Artistic License
270 to you shall terminate on the date that such litigation is filed.
271  
272 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
273 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
274 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
275 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
276 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
277 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
278 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
279 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
280  
281  
282 =cut
283  
284 3 1; # End of Proc::ProcessTable::Match
↑ Summary Match/PctMem.pm »