line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Inetd; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
58169
|
use strict; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
50
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
58
|
|
5
|
2
|
|
|
2
|
|
720
|
use boolean qw(true false); |
|
2
|
|
|
|
|
6217
|
|
|
2
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
157
|
use Carp qw(croak); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
153
|
|
8
|
2
|
|
|
2
|
|
11
|
use Fcntl qw(O_RDWR LOCK_EX); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
112
|
|
9
|
2
|
|
|
2
|
|
903
|
use Params::Validate ':all'; |
|
2
|
|
|
|
|
15819
|
|
|
2
|
|
|
|
|
332
|
|
10
|
2
|
|
|
2
|
|
1178
|
use Tie::File (); |
|
2
|
|
|
|
|
35463
|
|
|
2
|
|
|
|
|
2244
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our ($VERSION, $INETD_CONF); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '0.32'; |
15
|
|
|
|
|
|
|
$INETD_CONF = '/etc/inetd.conf'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
validation_options( |
18
|
|
|
|
|
|
|
on_fail => sub |
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
my ($error) = @_; |
21
|
|
|
|
|
|
|
chomp $error; |
22
|
|
|
|
|
|
|
croak $error; |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
stack_skip => 2, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new |
28
|
|
|
|
|
|
|
{ |
29
|
1
|
|
|
1
|
1
|
611
|
my $class = shift; |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
33
|
|
|
8
|
my $self = bless {}, ref($class) || $class; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
7
|
$self->_tie_conf(@_); |
34
|
1
|
|
|
|
|
62
|
$self->_parse_enabled; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
16
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _tie_conf |
40
|
|
|
|
|
|
|
{ |
41
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
42
|
1
|
|
|
|
|
2
|
my ($conf_file) = @_; |
43
|
1
|
|
33
|
|
|
3
|
$conf_file ||= $INETD_CONF; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $conf_tied = tie( |
46
|
1
|
50
|
|
|
|
2
|
@{$self->{CONF}}, 'Tie::File', $conf_file, |
|
1
|
|
|
|
|
9
|
|
47
|
|
|
|
|
|
|
mode => O_RDWR, autochomp => false |
48
|
|
|
|
|
|
|
) or croak "Cannot tie `$conf_file': $!"; |
49
|
1
|
50
|
|
|
|
179
|
$conf_tied->flock(LOCK_EX) |
50
|
|
|
|
|
|
|
or croak "Cannot lock `$conf_file': $!"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _parse_enabled |
54
|
|
|
|
|
|
|
{ |
55
|
1
|
|
|
1
|
|
9
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
8
|
$self->_filter_conf($self->{CONF}); |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
798
|
foreach my $entry (@{$self->{CONF}}) { |
|
1
|
|
|
|
|
5
|
|
60
|
49
|
|
|
|
|
662
|
my ($serv, $prot) = $self->_extract_serv_prot($entry); |
61
|
49
|
100
|
|
|
|
130
|
$self->{ENABLED}{$serv}{$prot} = $entry !~ /^\#/ |
62
|
|
|
|
|
|
|
? true : false; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub is_enabled |
67
|
|
|
|
|
|
|
{ |
68
|
2
|
|
|
2
|
1
|
561
|
my $self = shift; |
69
|
2
|
|
|
|
|
8
|
$self->_validate(@_); |
70
|
2
|
|
|
|
|
8
|
my ($serv, $prot) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
return exists $self->{ENABLED}{$serv}{$prot} |
73
|
2
|
50
|
|
|
|
13
|
? $self->{ENABLED}{$serv}{$prot} |
74
|
|
|
|
|
|
|
: undef; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub enable |
78
|
|
|
|
|
|
|
{ |
79
|
1
|
|
|
1
|
1
|
6406
|
my $self = shift; |
80
|
1
|
|
|
|
|
5
|
$self->_validate(@_); |
81
|
1
|
|
|
|
|
5
|
my ($serv, $prot) = @_; |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
3
|
foreach my $entry (@{$self->{CONF}}) { |
|
1
|
|
|
|
|
5
|
|
84
|
27
|
100
|
|
|
|
3481
|
if ($entry =~ /^ \# .*? $serv .+? $prot \b/x) { |
85
|
1
|
|
|
|
|
163
|
$self->{ENABLED}{$serv}{$prot} = true; |
86
|
1
|
|
|
|
|
8
|
$entry = substr($entry, 1); |
87
|
1
|
|
|
|
|
423
|
return true; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
0
|
return false; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub disable |
95
|
|
|
|
|
|
|
{ |
96
|
1
|
|
|
1
|
1
|
6415
|
my $self = shift; |
97
|
1
|
|
|
|
|
4
|
$self->_validate(@_); |
98
|
1
|
|
|
|
|
4
|
my ($serv, $prot) = @_; |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
3
|
foreach my $entry (@{$self->{CONF}}) { |
|
1
|
|
|
|
|
5
|
|
101
|
27
|
100
|
|
|
|
3640
|
if ($entry =~ /^ (?!\#) .*? $serv .+? $prot \b/x) { |
102
|
1
|
|
|
|
|
131
|
$self->{ENABLED}{$serv}{$prot} = false; |
103
|
1
|
|
|
|
|
10
|
$entry = "#$entry"; |
104
|
1
|
|
|
|
|
395
|
return true; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
0
|
return false; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub dump_enabled |
112
|
|
|
|
|
|
|
{ |
113
|
1
|
|
|
1
|
1
|
7
|
my $self = shift; |
114
|
|
|
|
|
|
|
|
115
|
1
|
|
|
|
|
2
|
my @conf = @{$self->{CONF}}; |
|
1
|
|
|
|
|
3
|
|
116
|
1
|
|
|
|
|
5790
|
$self->_filter_conf(\@conf, qr/^[^\#]/); |
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
7
|
return @conf; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub dump_disabled |
122
|
|
|
|
|
|
|
{ |
123
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
124
|
|
|
|
|
|
|
|
125
|
1
|
|
|
|
|
1
|
my @conf = @{$self->{CONF}}; |
|
1
|
|
|
|
|
5
|
|
126
|
1
|
|
|
|
|
6141
|
$self->_filter_conf(\@conf, qr/^\#/); |
127
|
|
|
|
|
|
|
|
128
|
1
|
|
|
|
|
6
|
return @conf; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub config |
132
|
|
|
|
|
|
|
{ |
133
|
5
|
|
|
5
|
1
|
9398
|
my $self = shift; |
134
|
5
|
|
|
|
|
41
|
validate_pos(@_); |
135
|
|
|
|
|
|
|
|
136
|
5
|
|
|
|
|
27
|
return $self->{CONF}; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _filter_conf |
140
|
|
|
|
|
|
|
{ |
141
|
3
|
|
|
3
|
|
6
|
my $self = shift; |
142
|
3
|
|
|
|
|
4
|
my ($conf, @regexps) = @_; |
143
|
|
|
|
|
|
|
|
144
|
3
|
|
|
|
|
12
|
unshift @regexps, qr/(?:stream|dgram|raw|rdm|seqpacket)/; |
145
|
|
|
|
|
|
|
|
146
|
3
|
|
|
|
|
12
|
for (my $i = $#$conf; $i >= 0; $i--) { |
147
|
156
|
|
|
|
|
11876
|
foreach my $regexp (@regexps) { |
148
|
254
|
100
|
50
|
|
|
838
|
splice(@$conf, $i, 1) and last |
149
|
|
|
|
|
|
|
unless $conf->[$i] =~ $regexp; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub _extract_serv_prot |
155
|
|
|
|
|
|
|
{ |
156
|
49
|
|
|
49
|
|
50
|
my $self = shift; |
157
|
49
|
|
|
|
|
87
|
my ($entry) = @_; |
158
|
|
|
|
|
|
|
|
159
|
49
|
|
|
|
|
2586
|
my ($serv, $prot) = (split /\s+/, $entry)[0,2]; |
160
|
|
|
|
|
|
|
|
161
|
49
|
|
|
|
|
95
|
$serv =~ s/.*:(.*)/$1/; |
162
|
49
|
100
|
|
|
|
120
|
$serv = substr($serv, 1) if $serv =~ /^\#/; |
163
|
|
|
|
|
|
|
|
164
|
49
|
|
|
|
|
94
|
return ($serv, $prot); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub _validate |
168
|
|
|
|
|
|
|
{ |
169
|
4
|
|
|
4
|
|
7
|
my $self = shift; |
170
|
4
|
|
|
|
|
60
|
validate_pos(@_, { type => SCALAR }, { type => SCALAR }); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
DESTROY |
174
|
|
|
|
|
|
|
{ |
175
|
1
|
|
|
1
|
|
6588
|
my $self = shift; |
176
|
1
|
|
|
|
|
3
|
untie @{$self->{CONF}}; |
|
1
|
|
|
|
|
13
|
|
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
1; |
180
|
|
|
|
|
|
|
__END__ |