line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Proc::ProcessTable::Match::UID; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
52236
|
use 5.006; |
|
1
|
|
|
|
|
10
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
382
|
use User::pwent; |
|
1
|
|
|
|
|
4927
|
|
|
1
|
|
|
|
|
3
|
|
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.0.0 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.0.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
|
|
|
|
|
|
|
sub new{ |
79
|
0
|
|
|
0
|
1
|
|
my %args; |
80
|
0
|
0
|
|
|
|
|
if(defined($_[1])){ |
81
|
0
|
|
|
|
|
|
%args= %{$_[1]}; |
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
}; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# run some basic checks to make sure we have the minimum stuff required to work |
85
|
0
|
0
|
|
|
|
|
if ( ! defined( $args{uids} ) ){ |
86
|
0
|
|
|
|
|
|
die ('No uids key specified in the argument hash'); |
87
|
|
|
|
|
|
|
} |
88
|
0
|
0
|
|
|
|
|
if ( ref( \$args{uids} ) eq 'ARRAY' ){ |
89
|
0
|
|
|
|
|
|
die ('The uids key is not a array'); |
90
|
|
|
|
|
|
|
} |
91
|
0
|
0
|
|
|
|
|
if ( ! defined $args{uids}[0] ){ |
92
|
0
|
|
|
|
|
|
die ('Nothing defined in the uids array'); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $self = { |
96
|
|
|
|
|
|
|
uids=>$args{uids}, |
97
|
0
|
|
|
|
|
|
}; |
98
|
0
|
|
|
|
|
|
bless $self; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $self; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head2 match |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Checks if a single Proc::ProcessTable::Process object matches the stack. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
One argument is taken and that is a Proc::ProcessTable::Process object. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
The returned value is a boolean. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
if ( $checker->match( $proc ) ){ |
112
|
|
|
|
|
|
|
print "The process matches.\n"; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub match{ |
118
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
119
|
0
|
|
|
|
|
|
my $object=$_[1]; |
120
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
if ( !defined( $object ) ){ |
122
|
0
|
|
|
|
|
|
return 0; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
0
|
|
|
|
|
if ( ref( $object ) ne 'Proc::ProcessTable::Process' ){ |
126
|
0
|
|
|
|
|
|
return 0; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
my $proc_uid; |
130
|
0
|
|
|
|
|
|
eval{ |
131
|
0
|
|
|
|
|
|
$proc_uid=$object->uid; |
132
|
|
|
|
|
|
|
}; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# don't bother proceeding, the object won't match ever |
135
|
|
|
|
|
|
|
# as it does not have a UID |
136
|
0
|
0
|
|
|
|
|
if ( ! defined( $proc_uid ) ){ |
137
|
0
|
|
|
|
|
|
return 0; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# use while as foreach will reference the value |
141
|
0
|
|
|
|
|
|
my $uid_int=0; |
142
|
0
|
|
|
|
|
|
while (defined( $self->{uids}[$uid_int] )){ |
143
|
0
|
|
|
|
|
|
my $uid=$self->{uids}[$uid_int]; |
144
|
0
|
0
|
0
|
|
|
|
if ( |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
145
|
|
|
|
|
|
|
( $uid =~ /^[0-9]+$/ ) && |
146
|
|
|
|
|
|
|
( $uid eq $proc_uid ) |
147
|
|
|
|
|
|
|
){ |
148
|
0
|
|
|
|
|
|
return 1; |
149
|
|
|
|
|
|
|
}elsif( |
150
|
|
|
|
|
|
|
( $uid =~ /[A-Za-z]/ ) && |
151
|
|
|
|
|
|
|
( $uid !~ /^\!/ ) |
152
|
|
|
|
|
|
|
){ |
153
|
0
|
|
|
|
|
|
my $pw=getpwnam($uid); |
154
|
0
|
0
|
|
|
|
|
if ( defined( $pw ) ){ |
155
|
0
|
0
|
|
|
|
|
if ( $pw->uid eq $proc_uid ){ |
156
|
0
|
|
|
|
|
|
return 1; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
}elsif( |
160
|
|
|
|
|
|
|
( $uid =~ /[A-Za-z]/ ) && |
161
|
|
|
|
|
|
|
( $uid =~ /^\!/ ) |
162
|
|
|
|
|
|
|
){ |
163
|
0
|
|
|
|
|
|
$uid =~ s/^\!//; |
164
|
0
|
|
|
|
|
|
my $pw=getpwnam($uid); |
165
|
0
|
0
|
|
|
|
|
if ( defined( $pw ) ){ |
166
|
0
|
0
|
|
|
|
|
if ( $pw->uid ne $proc_uid ){ |
167
|
0
|
|
|
|
|
|
return 1; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
}elsif( $uid =~ /^\<\=[0-9]+$/ ){ |
171
|
0
|
|
|
|
|
|
$uid=~s/^\<\=//; |
172
|
0
|
0
|
|
|
|
|
if ( $proc_uid <= $uid ){ |
173
|
0
|
|
|
|
|
|
return 1; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
}elsif( $uid =~ /^\<[0-9]+$/ ){ |
176
|
0
|
|
|
|
|
|
$uid=~s/^\/; |
177
|
0
|
0
|
|
|
|
|
if ( $proc_uid < $uid ){ |
178
|
0
|
|
|
|
|
|
return 1; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
}elsif( $uid =~ /^\>\=[0-9]+$/ ){ |
181
|
0
|
|
|
|
|
|
$uid=~s/^\>\=//; |
182
|
0
|
0
|
|
|
|
|
if ( $proc_uid >= $uid ){ |
183
|
0
|
|
|
|
|
|
return 1; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
}elsif( $uid =~ /^\>[0-9]+$/ ){ |
186
|
0
|
|
|
|
|
|
$uid=~s/^\>//; |
187
|
0
|
0
|
|
|
|
|
if ( $proc_uid > $uid ){ |
188
|
0
|
|
|
|
|
|
return 1; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
}elsif( $uid =~ /^\![0-9]+$/ ){ |
191
|
0
|
|
|
|
|
|
$uid=~s/^\!//; |
192
|
0
|
0
|
|
|
|
|
if ( $proc_uid ne $uid ){ |
193
|
0
|
|
|
|
|
|
return 1; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
} |
196
|
0
|
|
|
|
|
|
$uid_int++; |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
return 0; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 AUTHOR |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Zane C. Bowers-Hadley, C<< >> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 BUGS |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
209
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
210
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 SUPPORT |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
perldoc Proc::ProcessTable::Match |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
You can also look for information at: |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=over 4 |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
L |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
L |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item * CPAN Ratings |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
L |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=item * Search CPAN |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
L |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=back |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Copyright 2019 Zane C. Bowers-Hadley. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
253
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
254
|
|
|
|
|
|
|
copy of the full license at: |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
L |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
259
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
260
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
261
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
264
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
265
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
268
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
271
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
272
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
273
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
274
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
275
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
276
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
277
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
280
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
281
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
282
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
283
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
284
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
285
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
286
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=cut |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
1; # End of Proc::ProcessTable::Match |