Authentication.pm

filter: Statementstmt 63.3% 422 / 666 Branchbran 47.4% 112 / 236 Conditioncond 22.3% 29 / 130 MC/DCmcdc 1.4% 1 / 70 Subroutinesub 85.4% 53 / 62 Podpod 97.5% 39 / 40 totaltotal 54.4% 656 / 1204 CC 201 SCAR 45.1
CC
201
Cov
55%
start
306.0
send_panic_email
210.0
send_exception_email
184.0
CRAP 91.4
« Authentication/Handler/DMARC.pm ↑ Summary Authentication/Handler/DKIM.pm »
1 package Mail::Milter::Authentication;
2 143 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 143 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 143 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 143 ▶use Mail::Milter::Authentication::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: A Perl Mail Authentication Milter
7 143 our $VERSION = '4.20261116'; # VERSION
8 143 ▶use Mail::Milter::Authentication::Handler;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 143 ▶use Mail::Milter::Authentication::Metric;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 143 ▶use Mail::Milter::Authentication::Protocol::Milter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 143 ▶use Mail::Milter::Authentication::Protocol::SMTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 143 ▶use Email::Sender::Simple qw(try_to_sendmail);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 143 ▶use Email::Simple::Creator;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 143 ▶use Email::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 143 ▶use ExtUtils::Installed;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 143 ▶use Log::Dispatchouli;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 143 ▶use Net::DNS 1.01;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 143 ▶use Net::DNS::Resolver;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 143 ▶use Net::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 143 ▶use Proc::ProcessTable;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 143 ▶use Date::Format qw{ time2str };
Subroutine BEGIN: called CC=1 SCAR=0.0
22 143 ▶use base 'Mail::Milter::Authentication::Net::ServerPatches';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 143 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25  
26 {
27 143 my $LOGGER;
28 25569 ▶ sub logger {
Subroutine logger: called CC=4 SCAR=14.8
Pod undocumented
29  
30 25569 ▶ return $LOGGER if $LOGGER;
Branch: 1 branch
BranchTrueFalseTotal
if $LOGGER 25506 63 25569
31 63 my $config = get_config();
32  
33 63 my $MYARGS = {
34 'ident' => $Mail::Milter::Authentication::Config::IDENT,
35 'to_stderr' => 0, # handled elsewhere
36 'to_stdout' => 0, # handled elsewhere
37 'log_pid' => 1,
38 'facility' => LOG_MAIL,
39 };
40 63 ▶ if ( exists $config->{ 'log_dispatchouli' } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{"log_dispatchouli"}) 0 63 63
41 0 foreach my $k (keys %{$config->{ 'log_dispatchouli' }}) {
42 0 $MYARGS->{$k} = $config->{ 'log_dispatchouli' }->{$k};
43 }
44 }
45  
46 63 $LOGGER = Log::Dispatchouli->new( $MYARGS );
47 63 $LOGGER->log('Logging instantiated');
48 63 return $LOGGER;
49 }
50 }
51  
52 143 ▶sub _warn($msg) {
Subroutine _warn: called CC=3 SCAR=11.1
53 26041 my @parts = split "\n", $msg;
54 26041 foreach my $part ( @parts ) {
55 26065 ▶ next if $part eq q{};
Branch: 1 branch
BranchTrueFalseTotal
if $part eq "" 0 26065 26065
56 26065 print STDERR scalar(localtime) . ' ' . $Mail::Milter::Authentication::Config::IDENT . "[$PID] $part\n";
57 }
58 }
59  
60  
61 35 ▶sub preload_modules($self,$from,$matching) {
Subroutine preload_modules: called CC=5 SCAR=16.1
Pod documented
62 35 my $installed = ExtUtils::Installed->new( 'skip_cwd' => 1 );
63 35 my $path_matching = $matching;
64 35 $path_matching =~ s/::/\//g;
65 35 foreach my $module ( grep { /$from/ } $installed->modules() ) {
66 FILE:
67 140 foreach my $file ( grep { /$path_matching\/\w+\.pm$/ } $installed->files( $module ) ) {
68 2275 ▶ next FILE if ! -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 0 2275 2275
69 2275 my ( $module ) = reverse split '/', $file;
70 2275 $module =~ s/\.pm$//;
71 2275 $module = join( '::', $matching, $module );
72 2275 ▶ if ( ! is_loaded( $module ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not &is_loaded($module)) { } 1958 317 2275
73 1958 $self->logdebug( "Preloading Module $module" );
74 1958 load $module;
75 }
76 else {
77 317 $self->logdebug( "Preloading Module $module already loaded" );
78 }
79 }
80 }
81 }
82  
83  
84 0 ▶sub get_installed_handlers {
Subroutine get_installed_handlers: not called CC=4 SCAR=30.0
Pod documented
85 0 my @installed_handlers;
86 0 my $installed = ExtUtils::Installed->new( 'skip_cwd' => 1 );
87 0 foreach my $module ( grep { /Mail::Milter::Authentication/ } $installed->modules() ) {
88 FILE:
89 0 foreach my $file ( grep { /Mail\/Milter\/Authentication\/Handler\/\w+\.pm$/ } $installed->files( $module ) ) {
90 0 ▶ next FILE if ! -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 0 0 0
91 0 my ( $handler ) = reverse split '/', $file;
92 0 $handler =~ s/\.pm$//;
93 0 push @installed_handlers, $handler;
94 }
95 }
96 0 return \@installed_handlers;
97 }
98  
99  
100 219 ▶sub write_to_log_hook($self,$priority,$line,@) {
Subroutine write_to_log_hook: called CC=6 SCAR=21.5
Pod documented
101 219 ▶ my $log_priority = $priority == 0 ? 'debug'
Branch: 5 branches
BranchTrueFalseTotal
$priority == 0 ? : 11 208 219
$priority == 1 ? : 70 138 208
$priority == 2 ? : 138 0 138
$priority == 3 ? : 0 0 0
$priority == 4 ? : 0 0 0
102 : $priority == 1 ? 'info'
103 : $priority == 2 ? 'notice'
104 : $priority == 3 ? 'warning'
105 : $priority == 4 ? 'error'
106 : 'debug';
107 219 logger()->log( { 'level' => $log_priority }, $line );
108 }
109  
110  
111 201 ▶sub idle_loop_hook($self,@) {
Subroutine idle_loop_hook: called CC=1 SCAR=0.0
Pod documented
112 201 $self->{'metric'}->parent_metric_update( $self );
113 }
114  
115  
116 35 ▶sub pre_loop_hook($self,@) {
Subroutine pre_loop_hook: called CC=9 SCAR=22.3
Pod documented
117 35 $PROGRAM_NAME = $Mail::Milter::Authentication::Config::IDENT . ':parent';
118  
119 35 $self->preload_modules( 'Net::DNS', 'Net::DNS::RR' );
120 35 $self->{'metric'} = Mail::Milter::Authentication::Metric->new($self);
121  
122 # Load handlers
123 35 my $config = get_config();
124 35 $self->{'config'} = $config;
125 35 foreach my $name ( @{$config->{'load_handlers'}} ) {
126 310 $self->load_handler( $name );
127  
128 310 my $package = "Mail::Milter::Authentication::Handler::$name";
129 310 my $object = $package->new( $self );
130 310 ▶ if ( $object->can( 'pre_loop_setup' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can("pre_loop_setup")) 69 241 310
131 69 $object->pre_loop_setup();
132 }
133 310 ▶ if ( $object->can( 'register_metrics' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can("register_metrics")) 310 0 310
134 310 $self->{'metric'}->register_metrics( $object->register_metrics() );
135 }
136  
137 }
138  
139 35 $self->{'metric'}->register_metrics( {
140 'forked_children_total' => 'Total number of child processes forked',
141 'reaped_children_total' => 'Total number of child processes reaped',
142 'dequeue_files_total' => { help => 'The number of dequeue files queued', type => 'gauge' },
143 } );
144  
145 35 $self->{'metric'}->register_metrics( Mail::Milter::Authentication::Handler->register_metrics() );
146  
147 35 ▶ if ( $config->{'protocol'} eq 'milter' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($config->{'protocol'} eq 'milter') { } 19 16 35
elsif ($config->{'protocol'} eq 'smtp') { } 16 0 16
148 19 $self->{'metric'}->register_metrics( Mail::Milter::Authentication::Protocol::Milter->register_metrics() );
149 }
150 elsif ( $config->{'protocol'} eq 'smtp' ) {
151 16 $self->{'metric'}->register_metrics( Mail::Milter::Authentication::Protocol::SMTP->register_metrics() );
152 }
153 else {
154 0 die "Unknown protocol " . $config->{'protocol'} . "\n";
155 }
156  
157 35 ▶ if ( $config->{'error_log'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"error_log"}) 35 0 35
158 35 ▶ open( STDERR, '>>', $config->{'error_log'} ) || die "Cannot open errlog [$!]";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">>", $config->{"error_log"} or die "Cannot open errlog [$!]" 35 0 35
159 35 ▶ open( STDOUT, '>>', $config->{'error_log'} ) || die "Cannot open errlog [$!]";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">>", $config->{"error_log"} or die "Cannot open errlog [$!]" 35 0 35
160 }
161 }
162  
163  
164 37 ▶sub run_n_children_hook($self,@) {
Subroutine run_n_children_hook: called CC=3 SCAR=11.0
Pod documented
165 # Load handlers
166 37 my $config = get_config();
167 37 $self->{'config'} = $config;
168 37 $self->{metric}->re_register_metrics;
169 37 foreach my $name ( @{$config->{'load_handlers'}} ) {
170  
171 312 my $package = "Mail::Milter::Authentication::Handler::$name";
172 312 my $object = $package->new( $self );
173 312 ▶ if ( $object->can( 'pre_fork_setup' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can("pre_fork_setup")) 31 281 312
174 31 $object->pre_fork_setup();
175 }
176  
177 }
178 }
179  
180  
181 24 ▶sub child_init_hook {
Subroutine child_init_hook: called CC=11 SCAR=24.1
Pod documented
182 24 my ( $self,$arg ) = @_;
183 24 srand();
184  
185 24 my $config = get_config();
186 24 $self->{'config'} = $config;
187  
188 24 ▶ if ( $config->{'error_log'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"error_log"}) 24 0 24
189 24 eval {
190 24 ▶ open( STDERR, '>>', $config->{'error_log'} ) || die "Cannot open errlog [$!]";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">>", $config->{"error_log"} or die "Cannot open errlog [$!]" 24 0 24
191 24 ▶ open( STDOUT, '>>', $config->{'error_log'} ) || die "Cannot open errlog [$!]";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">>", $config->{"error_log"} or die "Cannot open errlog [$!]" 24 0 24
192 };
193 24 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 24 24
194 0 $self->logerror( "Child process $PID could not open the error log: $error" );
195 }
196 }
197  
198 24 ▶ $arg = '' if !defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 23 1 24
199 24 ▶ if ( $arg eq 'dequeue' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq 'dequeue') { } 1 23 24
200 1 $self->logdebug( "Dequeue process $PID starting up" );
201 1 $PROGRAM_NAME = $Mail::Milter::Authentication::Config::IDENT . ':dequeue';
202 }
203 else {
204 23 $self->loginfo( "Child process $PID starting up" );
205 23 $PROGRAM_NAME = $Mail::Milter::Authentication::Config::IDENT . ':starting';
206 }
207  
208 24 my $base;
209 24 ▶ if ( $config->{'protocol'} eq 'milter' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($config->{'protocol'} eq 'milter') { } 13 11 24
elsif ($config->{'protocol'} eq 'smtp') { } 11 0 11
210 13 $base = 'Mail::Milter::Authentication::Protocol::Milter';
211 }
212 elsif ( $config->{'protocol'} eq 'smtp' ) {
213 11 $base = 'Mail::Milter::Authentication::Protocol::SMTP';
214 }
215 else {
216 0 die "Unknown protocol " . $config->{'protocol'} . "\n";
217 }
218 24 push @ISA, $base;
219  
220 # BEGIN MILTER PROTOCOL BLOCK
221 24 ▶ if ( $config->{'protocol'} eq 'milter' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"protocol"} eq "milter") 13 11 24
222 13 my $protocol = SMFIP_NONE & ~(SMFIP_NOCONNECT|SMFIP_NOMAIL);
223 13 $protocol &= ~SMFIP_NOHELO;
224 13 $protocol &= ~SMFIP_NORCPT;
225 13 $protocol &= ~SMFIP_NOBODY;
226 13 $protocol &= ~SMFIP_NOHDRS;
227 13 $protocol &= ~SMFIP_NOEOH;
228 13 $protocol |= SMFIP_HDR_LEADSPC;
229 13 $self->{'protocol'} = $protocol;
230 13 $self->{'headers_include_space'} = 0;
231  
232 13 my $callback_flags = SMFI_CURR_ACTS|SMFIF_CHGBODY|SMFIF_QUARANTINE|SMFIF_SETSENDER;
233 13 $self->{'callback_flags'} = $callback_flags;
234 }
235 # END MILTER PROTOCOL BLOCK
236  
237 24 my $callbacks_list = {};
238 24 my $callbacks = {};
239 24 my $handler = {};
240 24 my $object = {};
241 24 my $object_maker = {};
242 24 my $count = 0;
243  
244 24 $self->{'callbacks_list'} = $callbacks_list;
245 24 $self->{'callbacks'} = $callbacks;
246 24 $self->{'count'} = $count;
247 24 $self->{'handler'} = $handler;
248 24 $self->{'object'} = $object;
249 24 $self->{'object_maker'} = $object_maker;
250  
251 24 $self->setup_handlers();
252 24 $self->{'metric'}->set_versions( $self );
253  
254 24 ▶ $self->{'handler'}->{'_Handler'}->metric_count( 'forked_children_total', {}, 1 ) unless $arg eq 'dequeue';
Branch: 1 branch
BranchTrueFalseTotal
unless $arg eq "dequeue" 23 1 24
255  
256 24 $PROGRAM_NAME = $Mail::Milter::Authentication::Config::IDENT . ':waiting(0)';
257 }
258  
259  
260 23 ▶sub child_finish_hook {
Subroutine child_finish_hook: called CC=3 SCAR=11.0
Pod documented
261 23 my ( $self,$arg ) = @_;
262 23 $PROGRAM_NAME = $Mail::Milter::Authentication::Config::IDENT . ':exiting';
263 23 ▶ $arg = '' if !defined $arg;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 22 1 23
264 23 ▶ if ( $arg eq 'dequeue' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq 'dequeue') { } 1 22 23
265 1 $self->logdebug( "Dequeue process $PID shutting down" );
266 }
267 else {
268 22 $self->loginfo( "Child process $PID shutting down" );
269 22 eval {
270 22 $self->{'handler'}->{'_Handler'}->metric_count( 'reaped_children_total', {}, 1 );
271 };
272 }
273 23 $self->destroy_objects();
274 }
275  
276  
277 11 ▶sub pre_server_close_hook($self,@) {
Subroutine pre_server_close_hook: called CC=1 SCAR=0.0
Pod documented
278 11 $self->loginfo( 'Server closing down' );
279 }
280  
281  
282 1 ▶sub dequeue($self,@) {
Subroutine dequeue: called CC=2 SCAR=7.0
Pod documented
283 1 my $config = $self->{ 'config' };
284 1 ▶ my $seconds = $config->{'dequeue_timeout'} // 300;
Condition50%1/2
$config->{"dequeue_timeout"} // 300
l!l
01
MC/DC0%0/1
$config->{"dequeue_timeout"} // 300
$config->{"dequeue_timeout"}
Truth table50%1/2
A
A= $config->{"dequeue_timeout"}
Aresult
11
00
285 1 $self->{handler}->{_Handler}->set_overall_timeout( $seconds * 1000000 );
286 1 $self->{handler}->{_Handler}->top_dequeue_callback();
287 1 $self->{handler}->{_Handler}->clear_overall_timeout();
288 }
289  
290  
291 244 ▶sub get_client_proto($self,@) {
Subroutine get_client_proto: called CC=7 SCAR=26.8
Pod documented
292 244 my $socket = $self->{server}{client};
293 244 ▶ if ($socket->isa("Net::Server::Proto")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($socket->isa("Net::Server::Proto")) 0 244 244
294 0 my $proto = $socket->NS_proto;
295 0 ▶ $proto = "UNIX" if $proto =~ m/^UNIX/;
Branch: 1 branch
BranchTrueFalseTotal
if $proto =~ /^UNIX/u 0 0 0
296 0 return $proto;
297 }
298  
299 244 ▶ if ($socket->isa("IO::Socket::IP")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($socket->isa("IO::Socket::IP")) 0 244 244
300 0 return "TCP";
301 }
302  
303 244 ▶ if ($socket->isa("IO::Socket::INET")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($socket->isa("IO::Socket::INET")) 0 244 244
304 0 return "TCP";
305 }
306  
307 244 ▶ if ($socket->isa("IO::Socket::INET6")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($socket->isa("IO::Socket::INET6")) 0 244 244
308 0 return "TCP";
309 }
310  
311 244 ▶ if ($socket->isa("IO::Socket::UNIX")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($socket->isa("IO::Socket::UNIX")) 244 0 244
312 244 return "UNIX";
313 }
314  
315 0 $self->logerror( "Could not determine connection protocol: " . ref($socket) );
316 }
317  
318  
319 0 ▶sub get_client_port($self,@) {
Subroutine get_client_port: not called CC=1 SCAR=6.9
Pod documented
320 0 my $socket = $self->{server}{client};
321 0 return $socket->sockport();
322 }
323  
324  
325 0 ▶sub get_client_host($self,@) {
Subroutine get_client_host: not called CC=1 SCAR=6.9
Pod documented
326 0 my $socket = $self->{server}{client};
327 0 return $socket->sockhost();
328 }
329  
330  
331 244 ▶sub get_client_path($self,@) {
Subroutine get_client_path: called CC=1 SCAR=0.0
Pod documented
332 244 my $socket = $self->{server}{client};
333 244 return $socket->hostpath();
334 }
335  
336  
337 163 ▶sub get_client_details($self,@) {
Subroutine get_client_details: called CC=3 SCAR=12.5
Pod documented
338 163 my $proto = lc $self->get_client_proto();
339 163 ▶ if ( $proto eq 'tcp' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($proto eq 'tcp') { } 0 163 163
elsif ($proto eq 'unix') { } 163 0 163
340 0 return 'inet:' . $self->get_client_port();
341 }
342 elsif ( $proto eq 'unix' ) {
343 163 return 'unix:' . $self->get_client_path();
344 }
345 }
346  
347  
348 81 ▶sub process_request($self,@) {
Subroutine process_request: called CC=14 SCAR=33.2
Pod documented
349 81 my $config = $self->{'config'};
350  
351 81 my $metric_type;
352 my $metric_path;
353 81 my $metric_host;
354  
355 81 ▶ if ( defined( $config->{'metric_connection'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{"metric_connection"}) 81 0 81
356 81 my $connection = $config->{'metric_connection'};
357 81 my $umask = $config->{'metric_umask'};
358  
359 81 $connection =~ /^([^:]+):([^:@]+)(?:@([^:@]+|\[[0-9a-f:\.]+\]))?$/;
360 81 $metric_type = $1;
361 81 $metric_path = $2;
362 81 ▶ $metric_host = $3 || q{};
Condition50%1/2
$3 || ''
l!l
081
MC/DC0%0/1
$3 || ''
$3
Truth table50%1/2
A
A= $3
Aresult
11
00
363 }
364  
365 ## ToDo, match also on client_host
366  
367 # Legacy metrics
368 81 ▶ if ( defined( $config->{ 'metric_port' } ) && $self->get_client_proto() eq 'TCP' && $self->get_client_port() eq $config->{'metric_port'} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $config->{'metric_port'} and $self->get_client_proto eq 'TCP' and $self->get_client_port eq $config->{'metric_port'}) { } 0 81 81
elsif (defined $config->{'metric_connection'} and $metric_type eq 'inet' and $self->get_client_proto eq 'TCP' and $self->get_client_port eq $metric_path) { } 0 81 81
elsif (defined $config->{'metric_connection'} and $metric_type eq 'unix' and $self->get_client_proto eq 'UNIX' and $self->get_client_path eq $metric_path) { } 11 70 81
Condition33%2/6
defined $config->{"metric_port"} and $self->get_client_proto eq "TCP" and $self->get_client_port eq $config->{"metric_port"}
!ll&&!rl&&r
8100
defined $config->{"metric_port"} and $self->get_client_proto eq "TCP"
!ll&&!rl&&r
8100
MC/DC0%0/3
defined $config->{"metric_port"} and $self->get_client_proto eq "TCP" and $self->get_client_port eq $config->{"metric_port"}
defined $config->{"metric_port"} $self->get_client_proto eq "TCP" $self->get_client_port eq $config->{"metric_port"}
Truth table25%1/4
A and B and C
A= defined $config->{"metric_port"}B= $self->get_client_proto eq "TCP"C= $self->get_client_port eq $config->{"metric_port"}
ABCresult
0XX0
10X0
1100
1111
369 0 $self->{'metric'}->child_handler( $self );
370 }
371  
372 ▶ elsif ( defined( $config->{ 'metric_connection' } ) && $metric_type eq 'inet' && $self->get_client_proto eq 'TCP' && $self->get_client_port() eq $metric_path ) {
Condition33%3/9
defined $config->{"metric_connection"} and $metric_type eq "inet" and $self->get_client_proto eq "TCP" and $self->get_client_port eq $metric_path
!ll&&!rl&&r
8100
defined $config->{"metric_connection"} and $metric_type eq "inet" and $self->get_client_proto eq "TCP"
!ll&&!rl&&r
8100
defined $config->{"metric_connection"} and $metric_type eq "inet"
!ll&&!rl&&r
0810
MC/DC0%0/4
defined $config->{"metric_connection"} and $metric_type eq "inet" and $self->get_client_proto eq "TCP" and $self->get_client_port eq $metric_path
defined $config->{"metric_connection"} $metric_type eq "inet" $self->get_client_proto eq "TCP" $self->get_client_port eq $metric_path
Truth table20%1/5
A and B and C and D
A= defined $config->{"metric_connection"}B= $metric_type eq "inet"C= $self->get_client_proto eq "TCP"D= $self->get_client_port eq $metric_path
ABCDresult
0XXX0
10XX0
110X0
11100
11111
373 0 $self->{'metric'}->child_handler( $self );
374 }
375  
376 ▶ elsif ( defined( $config->{ 'metric_connection' } ) && $metric_type eq 'unix' && $self->get_client_proto eq 'UNIX' && $self->get_client_path() eq $metric_path ) {
Condition44%4/9
defined $config->{"metric_connection"} and $metric_type eq "unix" and $self->get_client_proto eq "UNIX" and $self->get_client_path eq $metric_path
!ll&&!rl&&r
07011
defined $config->{"metric_connection"} and $metric_type eq "unix" and $self->get_client_proto eq "UNIX"
!ll&&!rl&&r
0081
defined $config->{"metric_connection"} and $metric_type eq "unix"
!ll&&!rl&&r
0081
MC/DC25%1/4
defined $config->{"metric_connection"} and $metric_type eq "unix" and $self->get_client_proto eq "UNIX" and $self->get_client_path eq $metric_path
defined $config->{"metric_connection"} $metric_type eq "unix" $self->get_client_proto eq "UNIX" $self->get_client_path eq $metric_path
Truth table40%2/5
A and B and C and D
A= defined $config->{"metric_connection"}B= $metric_type eq "unix"C= $self->get_client_proto eq "UNIX"D= $self->get_client_path eq $metric_path
ABCDresult
0XXX0
10XX0
110X0
11100
11111
377 11 $self->{'metric'}->child_handler( $self );
378 }
379  
380 else {
381 70 $self->process_main();
382 }
383  
384 80 my $count = $self->{'count'};
385 80 $PROGRAM_NAME = $Mail::Milter::Authentication::Config::IDENT . ':waiting(' . $count . ')';
386 }
387  
388  
389 70 ▶sub process_main($self,@) {
Subroutine process_main: called CC=6 SCAR=20.4
Pod documented
390 70 $self->{'count'}++;
391 70 my $count = $self->{'count'};
392 70 my $config = $self->{'config'};
393  
394 70 $PROGRAM_NAME = $Mail::Milter::Authentication::Config::IDENT . ':processing(' . $count . ')';
395 70 $self->logdebug( 'Processing request ' . $self->{'count'} );
396 70 $self->{'socket'} = $self->{'server'}->{'client'};
397  
398 70 $self->{'tracelog'} = [];
399  
400 70 $self->protocol_process_request();
401  
402 # Call close callback
403 70 $self->{'handler'}->{'_Handler'}->top_close_callback();
404 70 ▶ if ( $self->{'handler'}->{'_Handler'}->{'exit_on_close'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"handler"}{"_Handler"}{"exit_on_close"}) 1 69 70
405 1 ▶ my $error = $self->{'handler'}->{'_Handler'}->{'exit_on_close_error'} // 'no reason given';
Condition50%1/2
$self->{"handler"}{"_Handler"}{"exit_on_close_error"} // "no reason given"
l!l
10
MC/DC0%0/1
$self->{"handler"}{"_Handler"}{"exit_on_close_error"} // "no reason given"
$self->{"handler"}{"_Handler"}{"exit_on_close_error"}
Truth table50%1/2
A
A= $self->{"handler"}{"_Handler"}{"exit_on_close_error"}
Aresult
11
00
406 1 $self->send_exception_email($error);
407 1 $self->fatal('exit_on_close requested - '.$error);
408 }
409  
410 69 $self->{'tracelog'} = [];
411  
412 69 ▶ if ( $config->{'debug'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"debug"}) 0 69 69
413 0 my $process_table = Proc::ProcessTable->new();
414 0 foreach my $process ( @{$process_table->table} ) {
415 0 ▶ if ( $process->pid == $PID ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($process->pid == $Mail::Milter::Authentication::PID) 0 0 0
416 0 my $size = $process->size;
417 0 my $rss = $process->rss;
418 0 my $pctmem = $process->pctmem;
419 0 my $pctcpu = $process->pctcpu;
420 0 $self->loginfo( "Resource usage: ($count) size $size/rss $rss/memory $pctmem\%/cpu $pctcpu\%" );
421 }
422 }
423 }
424  
425 69 delete $self->{'handler'}->{'_Handler'}->{'reject_mail'};
426 69 delete $self->{'handler'}->{'_Handler'}->{'return_code'};
427 69 delete $self->{'socket'};
428 69 $self->logdebug( 'Request processing completed' );
429 }
430  
431  
432 1 ▶sub send_exception_email {
Subroutine send_exception_email: called CC=15 SCAR=52.2
Pod documented
433 1 my ( $self, $error ) = @_;
434  
435 1 ▶ if ( $self->{'handler'}->{'_Handler'}->{'suppress_error_emails'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"handler"}{"_Handler"}{"suppress_error_emails"}) 0 1 1
436 0 return;
437 }
438  
439 1 my $config = get_config();
440 1 ▶ my $errors_to = $config->{'errors_to'} || return;
Condition50%1/2
$config->{'errors_to'} || (return)
l!l
01
MC/DC0%0/1
$config->{'errors_to'} || (return)
$config->{'errors_to'}
Truth table50%1/2
A
A= $config->{'errors_to'}
Aresult
11
00
441 0 ▶ my $errors_from = $config->{'errors_from'} || return;
Condition0%0/2
$config->{'errors_from'} || (return)
l!l
00
MC/DC0%0/1
$config->{'errors_from'} || (return)
$config->{'errors_from'}
Truth table0%0/2
A
A= $config->{'errors_from'}
Aresult
11
00
442 0 ▶ my $errors_headers = $config->{'errors_headers'} || {};
Condition0%0/2
$config->{'errors_headers'} || {}
l!l
00
MC/DC0%0/1
$config->{'errors_headers'} || {}
$config->{'errors_headers'}
Truth table0%0/2
A
A= $config->{'errors_headers'}
Aresult
11
00
443  
444 0 my $email = "Authentication Milter " . $Mail::Milter::Authentication::Config::IDENT . " Error\n\n";
445 0 $email .= "$error\n\n";
446  
447 0 $email .= "Child PID: $PID\n\n";
448  
449 0 $email .= "Log:\n";
450 0 $email .= join( "\n", map { time2str('%Y:%m:%d %X %z', $_->[0]) . " " . $_->[1] } $self->{'tracelog'}->@* );
451 0 $email .= "\n\n";
452  
453 0 $email .= "Processes Running\n";
454 0 my $ppid = $self->{'server'}->{'ppid'};
455 0 my $process_table = Proc::ProcessTable->new;
456 0 foreach my $process ( $process_table->table->@* ) {
457 0 ▶ next if ! ( $process->pid == $ppid || $process->ppid == $ppid );
Branch: 1 branch
BranchTrueFalseTotal
unless $process->pid == $ppid or $process->ppid == $ppid 0 0 0
Condition0%0/3
$process->pid == $ppid or $process->ppid == $ppid
l!l&&r!l&&!r
000
MC/DC0%0/2
$process->pid == $ppid or $process->ppid == $ppid
$process->pid == $ppid $process->ppid == $ppid
Truth table0%0/3
A or B
A= $process->pid == $ppidB= $process->ppid == $ppid
ABresult
1X1
011
000
458 0 ▶ my $pid = eval{ $process->pid } // '';
Condition0%0/2
eval { do { $process->pid } } // ""
l!l
00
MC/DC0%0/1
eval { do { $process->pid } } // ""
eval { do { $process->pid } }
Truth table0%0/2
A
A= eval { do { $process->pid } }
Aresult
11
00
459 0 ▶ my $cmndline = eval{ $process->cmndline } // '';
Condition0%0/2
eval { do { $process->cmndline } } // ""
l!l
00
MC/DC0%0/1
eval { do { $process->cmndline } } // ""
eval { do { $process->cmndline } }
Truth table0%0/2
A
A= eval { do { $process->cmndline } }
Aresult
11
00
460 0 ▶ my $size = eval{ $process->size } // '';
Condition0%0/2
eval { do { $process->size } } // ""
l!l
00
MC/DC0%0/1
eval { do { $process->size } } // ""
eval { do { $process->size } }
Truth table0%0/2
A
A= eval { do { $process->size } }
Aresult
11
00
461 0 ▶ my $rss = eval{ $process->rss } // '';
Condition0%0/2
eval { do { $process->rss } } // ""
l!l
00
MC/DC0%0/1
eval { do { $process->rss } } // ""
eval { do { $process->rss } }
Truth table0%0/2
A
A= eval { do { $process->rss } }
Aresult
11
00
462 0 ▶ my $pctmem = eval{ $process->pctmem } // '';
Condition0%0/2
eval { do { $process->pctmem } } // ""
l!l
00
MC/DC0%0/1
eval { do { $process->pctmem } } // ""
eval { do { $process->pctmem } }
Truth table0%0/2
A
A= eval { do { $process->pctmem } }
Aresult
11
00
463 0 ▶ my $pctcpu = eval{ $process->pctcpu } // '';
Condition0%0/2
eval { do { $process->pctcpu } } // ""
l!l
00
MC/DC0%0/1
eval { do { $process->pctcpu } } // ""
eval { do { $process->pctcpu } }
Truth table0%0/2
A
A= eval { do { $process->pctcpu } }
Aresult
11
00
464 0 $email .= "pid:$pid, $cmndline, size:$size, mem:$rss ($pctmem%), cpu: $pctcpu%\n";
465 }
466  
467 0 my @headers;
468 0 foreach my $key ( sort keys $errors_headers->%* ) {
469 0 push @headers, $key => $errors_headers->{$key};
470 }
471 0 push @headers, to => $errors_to;
472 0 push @headers, From => $errors_from;
473 0 push @headers, Subject => 'Authentication Milter Error';
474 0 push @headers, 'X-Authentication-Milter-Error' => 'Generated Error Report';
475  
476 0 my $emailer = Email::Simple->create(
477 header => \@headers,
478 body => $email,
479 );
480 0 try_to_sendmail($emailer);
481  
482 }
483  
484  
485 0 ▶sub send_panic_email {
Subroutine send_panic_email: not called CC=14 SCAR=53.5
Pod documented
486 0 my ( $error ) = @_;
487  
488 0 my $config = get_config();
489 0 ▶ my $errors_to = $config->{'errors_to'} || return;
Condition0%0/2
$config->{'errors_to'} || (return)
l!l
00
MC/DC0%0/1
$config->{'errors_to'} || (return)
$config->{'errors_to'}
Truth table0%0/2
A
A= $config->{'errors_to'}
Aresult
11
00
490 0 ▶ my $errors_from = $config->{'errors_from'} || return;
Condition0%0/2
$config->{'errors_from'} || (return)
l!l
00
MC/DC0%0/1
$config->{'errors_from'} || (return)
$config->{'errors_from'}
Truth table0%0/2
A
A= $config->{'errors_from'}
Aresult
11
00
491 0 ▶ my $errors_headers = $config->{'errors_headers'} || {};
Condition0%0/2
$config->{'errors_headers'} || {}
l!l
00
MC/DC0%0/1
$config->{'errors_headers'} || {}
$config->{'errors_headers'}
Truth table0%0/2
A
A= $config->{'errors_headers'}
Aresult
11
00
492  
493 0 my $email = "Authentication Milter " . $Mail::Milter::Authentication::Config::IDENT . " Error\n\n";
494 0 $email .= "$error\n\n";
495  
496 0 $email .= "PID: $PID\n\n";
497  
498 0 $email .= "Processes Running\n";
499 0 my $process_table = Proc::ProcessTable->new;
500 0 foreach my $process ( $process_table->table->@* ) {
501 0 ▶ next if ! ( $process->pid == $PID || $process->ppid == $PID );
Branch: 1 branch
BranchTrueFalseTotal
unless $process->pid == $Mail::Milter::Authentication::PID or $process->ppid == $Mail::Milter::Authentication::PID 0 0 0
Condition0%0/3
$process->pid == $Mail::Milter::Authentication::PID or $process->ppid == $Mail::Milter::Authentication::PID
l!l&&r!l&&!r
000
MC/DC0%0/2
$process->pid == $Mail::Milter::Authentication::PID or $process->ppid == $Mail::Milter::Authentication::PID
$process->pid == $Mail::Milter::Authentication::PID $process->ppid == $Mail::Milter::Authentication::PID
Truth table0%0/3
A or B
A= $process->pid == $Mail::Milter::Authentication::PIDB= $process->ppid == $Mail::Milter::Authentication::PID
ABresult
1X1
011
000
502 0 ▶ my $pid = eval{ $process->pid } // '';
Condition0%0/2
eval { do { $process->pid } } // ""
l!l
00
MC/DC0%0/1
eval { do { $process->pid } } // ""
eval { do { $process->pid } }
Truth table0%0/2
A
A= eval { do { $process->pid } }
Aresult
11
00
503 0 ▶ my $cmndline = eval{ $process->cmndline } // '';
Condition0%0/2
eval { do { $process->cmndline } } // ""
l!l
00
MC/DC0%0/1
eval { do { $process->cmndline } } // ""
eval { do { $process->cmndline } }
Truth table0%0/2
A
A= eval { do { $process->cmndline } }
Aresult
11
00
504 0 ▶ my $size = eval{ $process->size } // '';
Condition0%0/2
eval { do { $process->size } } // ""
l!l
00
MC/DC0%0/1
eval { do { $process->size } } // ""
eval { do { $process->size } }
Truth table0%0/2
A
A= eval { do { $process->size } }
Aresult
11
00
505 0 ▶ my $rss = eval{ $process->rss } // '';
Condition0%0/2
eval { do { $process->rss } } // ""
l!l
00
MC/DC0%0/1
eval { do { $process->rss } } // ""
eval { do { $process->rss } }
Truth table0%0/2
A
A= eval { do { $process->rss } }
Aresult
11
00
506 0 ▶ my $pctmem = eval{ $process->pctmem } // '';
Condition0%0/2
eval { do { $process->pctmem } } // ""
l!l
00
MC/DC0%0/1
eval { do { $process->pctmem } } // ""
eval { do { $process->pctmem } }
Truth table0%0/2
A
A= eval { do { $process->pctmem } }
Aresult
11
00
507 0 ▶ my $pctcpu = eval{ $process->pctcpu } // '';
Condition0%0/2
eval { do { $process->pctcpu } } // ""
l!l
00
MC/DC0%0/1
eval { do { $process->pctcpu } } // ""
eval { do { $process->pctcpu } }
Truth table0%0/2
A
A= eval { do { $process->pctcpu } }
Aresult
11
00
508 0 $email .= "pid:$pid, $cmndline, size:$size, mem:$rss ($pctmem%), cpu: $pctcpu%\n";
509 }
510  
511 0 my @headers;
512 0 foreach my $key ( sort keys $errors_headers->%* ) {
513 0 push @headers, $key => $errors_headers->{$key};
514 }
515 0 push @headers, to => $errors_to;
516 0 push @headers, From => $errors_from;
517 0 push @headers, Subject => 'Authentication Milter Error';
518 0 push @headers, 'X-Authentication-Milter-Error' => 'Generated Error Report';
519  
520 0 my $emailer = Email::Simple->create(
521 header => \@headers,
522 body => $email,
523 );
524 0 try_to_sendmail($emailer);
525  
526 }
527  
528  
529 0 ▶sub get_valid_pid($pid_file) {
Subroutine get_valid_pid: not called CC=11 SCAR=48.8
Pod documented
530 0 ▶ if ( ! $pid_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid_file) 0 0 0
531 0 return undef; ## no critic
532 }
533 0 ▶ if ( ! -e $pid_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $pid_file) 0 0 0
534 0 return undef; ## no critic
535 }
536  
537 0 ▶ open my $inf, '<', $pid_file || return undef; ## no critic
Condition0%0/2
$pid_file || (return undef)
l!l
00
MC/DC0%0/1
$pid_file || (return undef)
$pid_file
Truth table0%0/2
A
A= $pid_file
Aresult
11
00
538 0 my $pid = <$inf>;
539 0 close $inf;
540  
541 0 my $self_pid = $PID;
542 0 my $found_self = 0;
543 0 my $found_pid = 0;
544  
545 0 my $process_table = Proc::ProcessTable->new();
546 0 foreach my $process ( $process_table->table->@* ) {
547 0 ▶ if ( $process->pid == $self_pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($process->pid == $self_pid) 0 0 0
548 0 ▶ if ( $process->cmndline eq $Mail::Milter::Authentication::Config::IDENT . ':control' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($process->cmndline eq $Mail::Milter::Authentication::Config::IDENT . ':control') 0 0 0
549 0 $found_self = 1;
550 }
551 }
552 0 ▶ if ( $process->pid == $pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($process->pid == $pid) 0 0 0
553 0 $found_pid = 1;
554 0 ▶ if ( $process->cmndline eq $Mail::Milter::Authentication::Config::IDENT . ':parent' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($process->cmndline eq $Mail::Milter::Authentication::Config::IDENT . ':parent') 0 0 0
555 0 return $pid;
556 }
557 }
558 }
559  
560 # If we didn't find ourself in the process table then we can assume that
561 # $0 is read only on our current operating system, and return the pid that we read from the
562 # pidfile if it is in the process table regardness of it's process name..
563 0 ▶ if ( ! $found_self ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found_self) 0 0 0
564 0 ▶ if ( $found_pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found_pid) 0 0 0
565 0 return $pid;
566 }
567 }
568  
569 0 return undef; ## no critic
570 }
571  
572  
573 0 ▶sub find_process {
Subroutine find_process: not called CC=4 SCAR=30.0
Pod documented
574 0 my $process_table = Proc::ProcessTable->new();
575 0 foreach my $process ( $process_table->table->@* ) {
576 0 ▶ if ( $process->cmndline eq $Mail::Milter::Authentication::Config::IDENT . ':master' ) { ## Legacy naming, will be removed in later version
Branch: 1 branch
BranchTrueFalseTotal
if ($process->cmndline eq $Mail::Milter::Authentication::Config::IDENT . ':master') 0 0 0
577 0 return $process->pid;
578 }
579 0 ▶ if ( $process->cmndline eq $Mail::Milter::Authentication::Config::IDENT . ':parent' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($process->cmndline eq $Mail::Milter::Authentication::Config::IDENT . ':parent') 0 0 0
580 0 return $process->pid;
581 }
582 }
583 0 return undef; ## no critic
584 }
585  
586  
587 0 ▶sub control($args) {
Subroutine control: not called CC=12 SCAR=50.5
Pod documented
588 0 my $pid_file = $args->{'pid_file'};
589 0 my $command = $args->{'command'};
590  
591 0 my $OriginalProgramName = $PROGRAM_NAME;
592 0 $PROGRAM_NAME = $Mail::Milter::Authentication::Config::IDENT . ':control';
593  
594 0 ▶ if ( $command eq 'stop' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($command eq 'stop') { } 0 0 0
elsif ($command eq 'restart' or $command eq 'start') { } 0 0 0
elsif ($command eq 'status') { } 0 0 0
595 0 ▶ my $pid = get_valid_pid( $pid_file ) || find_process();
Condition0%0/3
get_valid_pid($pid_file) || find_process()
l!l&&r!l&&!r
000
MC/DC0%0/2
get_valid_pid($pid_file) || find_process()
get_valid_pid($pid_file) find_process()
Truth table0%0/3
A || B
A= get_valid_pid($pid_file)B= find_process()
ABresult
1X1
011
000
596 0 ▶ if ( $pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) { } 0 0 0
597 0 print "Process found, stopping\n";
598 0 kill 'QUIT', $pid;
599 }
600 else {
601 0 print "No process found\n";
602 }
603 }
604 ▶ elsif ( $command eq 'restart' || $command eq 'start' ) {
Condition0%0/3
$command eq "restart" or $command eq "start"
l!l&&r!l&&!r
000
MC/DC0%0/2
$command eq "restart" or $command eq "start"
$command eq "restart" $command eq "start"
Truth table0%0/3
A or B
A= $command eq "restart"B= $command eq "start"
ABresult
1X1
011
000
605 0 ▶ my $pid = get_valid_pid( $pid_file ) || find_process();
Condition0%0/3
get_valid_pid($pid_file) || find_process()
l!l&&r!l&&!r
000
MC/DC0%0/2
get_valid_pid($pid_file) || find_process()
get_valid_pid($pid_file) find_process()
Truth table0%0/3
A || B
A= get_valid_pid($pid_file)B= find_process()
ABresult
1X1
011
000
606 0 ▶ if ( $pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) { } 0 0 0
607 0 print "Process found, restarting\n";
608 0 kill 'HUP', $pid;
609 }
610 else {
611 0 print "No process found, starting up\n";
612 0 $PROGRAM_NAME = $OriginalProgramName;
613 0 start({
614 'pid_file' => $pid_file,
615 'daemon' => 1,
616 });
617 }
618 }
619 elsif ( $command eq 'status' ) {
620 0 ▶ my $pid = get_valid_pid( $pid_file ) || find_process();
Condition0%0/3
get_valid_pid($pid_file) || find_process()
l!l&&r!l&&!r
000
MC/DC0%0/2
get_valid_pid($pid_file) || find_process()
get_valid_pid($pid_file) find_process()
Truth table0%0/3
A || B
A= get_valid_pid($pid_file)B= find_process()
ABresult
1X1
011
000
621 0 ▶ if ( $pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid) { } 0 0 0
622 0 print "Process running with pid $pid\n";
623 0 ▶ if ( ! get_valid_pid( $pid_file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not get_valid_pid($pid_file)) 0 0 0
624 0 print "pid file $pid_file is invalid\n";
625 }
626 }
627 else {
628 0 print "No process found\n";
629 }
630 }
631 else {
632 0 die 'unknown command';
633 }
634 }
635  
636  
637 35 ▶sub start($args) {
Subroutine start: called CC=44 SCAR=57.2
Pod documented
638 82 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
639 82 foreach my $msg ( @_ ) {
640 82 logger()->log( { level => 'warning' }, "Warning: $msg" );
641 82 _warn( "Warning: $msg" );
642 }
643 35 };
644  
645 35 my $config = get_config();
646  
647 35 ▶ my $default_connection = $config->{'connection'} || die('No connection details given');
Condition50%1/2
$config->{'connection'} || die('No connection details given')
l!l
350
MC/DC0%0/1
$config->{'connection'} || die('No connection details given')
$config->{'connection'}
Truth table50%1/2
A
A= $config->{'connection'}
Aresult
11
00
648  
649 35 my $pid_file = $args->{'pid_file'};
650  
651 35 ▶ my $listen_backlog = $config->{'listen_backlog'} || 20;
Condition50%1/2
$config->{'listen_backlog'} || 20
l!l
350
MC/DC0%0/1
$config->{'listen_backlog'} || 20
$config->{'listen_backlog'}
Truth table50%1/2
A
A= $config->{'listen_backlog'}
Aresult
11
00
652 35 ▶ my $max_children = $config->{'max_children'} || 100;
Condition50%1/2
$config->{'max_children'} || 100
l!l
350
MC/DC0%0/1
$config->{'max_children'} || 100
$config->{'max_children'}
Truth table50%1/2
A
A= $config->{'max_children'}
Aresult
11
00
653 35 ▶ my $max_requests_per_child = $config->{'max_requests_per_child'} || 200;
Condition50%1/2
$config->{'max_requests_per_child'} || 200
l!l
350
MC/DC0%0/1
$config->{'max_requests_per_child'} || 200
$config->{'max_requests_per_child'}
Truth table50%1/2
A
A= $config->{'max_requests_per_child'}
Aresult
11
00
654 35 ▶ my $min_children = $config->{'min_children'} || 20;
Condition50%1/2
$config->{'min_children'} || 20
l!l
350
MC/DC0%0/1
$config->{'min_children'} || 20
$config->{'min_children'}
Truth table50%1/2
A
A= $config->{'min_children'}
Aresult
11
00
655 35 ▶ my $max_spare_children = $config->{'max_spare_children'} || 20;
Condition50%1/2
$config->{'max_spare_children'} || 20
l!l
350
MC/DC0%0/1
$config->{'max_spare_children'} || 20
$config->{'max_spare_children'}
Truth table50%1/2
A
A= $config->{'max_spare_children'}
Aresult
11
00
656 35 ▶ my $min_spare_children = $config->{'min_spare_children'} || 10;
Condition50%1/2
$config->{'min_spare_children'} || 10
l!l
350
MC/DC0%0/1
$config->{'min_spare_children'} || 10
$config->{'min_spare_children'}
Truth table50%1/2
A
A= $config->{'min_spare_children'}
Aresult
11
00
657  
658 35 setup_config();
659  
660 35 my %srvargs;
661  
662 35 $srvargs{'no_client_stdout'} = 1;
663  
664 # Early redirection to log file if possible
665 35 ▶ if ( $config->{'error_log'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"error_log"}) 35 0 35
666 35 ▶ open( STDERR, '>>', $config->{'error_log'} ) || die "Cannot open errlog [$!]";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">>", $config->{"error_log"} or die "Cannot open errlog [$!]" 35 0 35
667 35 ▶ open( STDOUT, '>>', $config->{'error_log'} ) || die "Cannot open errlog [$!]";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">>", $config->{"error_log"} or die "Cannot open errlog [$!]" 35 0 35
668 }
669  
670 35 ▶ if ( $args->{'daemon'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"daemon"}) 0 35 35
671 0 ▶ if ( $EUID == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::EUID == 0) { } 0 0 0
672 0 _warn(
673 join( ' ',
674 'daemonize',
675 "servers=$min_children/$max_children",
676 "spares=$min_spare_children/$max_spare_children",
677 "requests=$max_requests_per_child",
678 )
679 );
680 0 $srvargs{'background'} = 1;
681 0 $srvargs{'setsid'} = 1;
682 }
683 else {
684 0 _warn("Not running as root, daemonize ignored!");
685 }
686 }
687 35 $srvargs{'pid_file'} = $pid_file;
688 35 $srvargs{'max_servers'} = $max_children;
689 35 $srvargs{'max_requests'} = $max_requests_per_child;
690 35 $srvargs{'min_servers'} = $min_children;
691 35 $srvargs{'min_spare_servers'} = $min_spare_children;
692 35 $srvargs{'max_spare_servers'} = $max_spare_children;
693  
694 35 ▶ $srvargs{'lock_file'} = $config->{'lock_file'} if $config->{'lock_file'};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"lock_file"} 0 35 35
695  
696 35 ▶ if ( $EUID == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::EUID == 0) { } 0 35 35
697 0 my $user = $config->{'runas'};
698 0 my $group = $config->{'rungroup'};
699 0 ▶ if ( $user && $group ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user and $group) { } 0 0 0
Condition0%0/3
$user and $group
!ll&&!rl&&r
000
MC/DC0%0/2
$user and $group
$user $group
Truth table0%0/3
A and B
A= $userB= $group
ABresult
0X0
100
111
700 0 _warn("run as user=$user group=$group");
701 0 $srvargs{'user'} = $user;
702 0 $srvargs{'group'} = $group;
703 }
704 else {
705 0 _warn("No runas details supplied, could not drop privs - be careful!");
706 }
707 # Note, Chroot requires a chroot environment which is out of scope at present
708 0 ▶ if ( $config->{'error_log'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"error_log"}) 0 0 0
709 0 ▶ if ( ! -e $config->{'error_log'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $config->{"error_log"}) 0 0 0
710 0 ▶ open my $outf, '>', $config->{'error_log'} || die "Could not create error log: $!\n";;
Condition0%0/2
$config->{'error_log'} || die("Could not create error log: $!\n")
l!l
00
MC/DC0%0/1
$config->{'error_log'} || die("Could not create error log: $!\n")
$config->{'error_log'}
Truth table0%0/2
A
A= $config->{'error_log'}
Aresult
11
00
711 0 close $outf;
712 }
713 0 ▶ if ( $user ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user) 0 0 0
714 0 my ($login,$pass,$uid,$gid) = getpwnam($user);
715 0 chown $uid, $gid, $config->{'error_log'};
716 }
717 }
718 0 ▶ if ( exists( $config->{'chroot'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{"chroot"}) 0 0 0
719 0 _warn('Chroot to ' . $config->{'chroot'});
720 0 $srvargs{'chroot'} = $config->{'chroot'};
721 }
722 }
723 else {
724 35 _warn("Not running as root, could not drop privs - be careful!");
725 }
726  
727 35 my $connections = {};
728  
729 35 ▶ if ( exists $config->{'connections'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{"connections"}) 0 35 35
730 0 $connections = $config->{'connections'};
731 }
732  
733 $connections->{'default'} = {
734 'connection' => $default_connection,
735 35 'umask' => $config->{'umask'},
736 };
737  
738 35 my @ports;
739 35 foreach my $key ( keys %$connections ) {
740 35 my $connection = $connections->{$key}->{'connection'};
741 35 my $umask = $connections->{$key}->{'umask'};
742  
743 35 $connection =~ /^([^:]+):([^:@]+)(?:@([^:@]+|\[[0-9a-f:\.]+\]))?$/;
744 35 my $type = $1;
745 35 my $path = $2;
746 35 ▶ my $host = $3 || q{};
Condition50%1/2
$3 || ''
l!l
035
MC/DC0%0/1
$3 || ''
$3
Truth table50%1/2
A
A= $3
Aresult
11
00
747 35 ▶ if ( $type eq 'inet' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'inet') { } 0 35 35
elsif ($type eq 'unix') { } 35 0 35
748 0 _warn(
749 join( ' ',
750 'listening on inet',
751 "host=$host",
752 "port=$path",
753 "backlog=$listen_backlog",
754 )
755 );
756 0 push @ports, {
757 'host' => $host,
758 'port' => $path,
759 'ipv' => '*',
760 'proto' => 'tcp',
761 };
762 }
763 elsif ( $type eq 'unix' ) {
764 35 _warn(
765 join( ' ',
766 'listening on unix',
767 "socket=$path",
768 "backlog=$listen_backlog",
769 )
770 );
771 35 push @ports, {
772 'port' => $path,
773 'proto' => 'unix',
774 };
775  
776 35 ▶ if ($umask) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umask) 35 0 35
777 35 umask ( oct( $umask ) );
778 35 _warn( 'setting umask to ' . $umask );
779 }
780  
781 }
782 else {
783 0 die 'Invalid connection';
784 }
785 }
786  
787 35 ▶ if ( defined( $config->{'metric_connection'} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $config->{'metric_connection'}) { } 35 0 35
elsif (defined $config->{'metric_port'}) { } 0 0 0
788 35 my $connection = $config->{'metric_connection'};
789 35 my $umask = $config->{'metric_umask'};
790  
791 35 $connection =~ /^([^:]+):([^:@]+)(?:@([^:@]+|\[[0-9a-f:\.]+\]))?$/;
792 35 my $type = $1;
793 35 my $path = $2;
794 35 ▶ my $host = $3 || q{};
Condition50%1/2
$3 || ''
l!l
035
MC/DC0%0/1
$3 || ''
$3
Truth table50%1/2
A
A= $3
Aresult
11
00
795 35 ▶ if ( $type eq 'inet' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'inet') { } 0 35 35
elsif ($type eq 'unix') { } 35 0 35
796 0 _warn(
797 join( ' ',
798 'metrics listening on inet',
799 "host=$host",
800 "port=$path",
801 "backlog=$listen_backlog",
802 )
803 );
804 0 push @ports, {
805 'host' => $host,
806 'port' => $path,
807 'ipv' => '*',
808 'proto' => 'tcp',
809 };
810 }
811 elsif ( $type eq 'unix' ) {
812 35 _warn(
813 join( ' ',
814 'metrics listening on unix',
815 "socket=$path",
816 "backlog=$listen_backlog",
817 )
818 );
819 35 push @ports, {
820 'port' => $path,
821 'proto' => 'unix',
822 };
823  
824 35 ▶ if ($umask) {
Branch: 1 branch
BranchTrueFalseTotal
if ($umask) 35 0 35
825 35 umask ( oct( $umask ) );
826 35 _warn( 'setting umask to ' . $umask );
827 }
828  
829 }
830 else {
831 0 die 'Invalid metrics connection';
832 }
833  
834 35 ▶ if ( defined( $config->{'metric_port'} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $config->{"metric_port"}) 0 35 35
835 0 _warn( 'metric_port ignored when metric_connection supplied' );
836 }
837  
838 }
839 elsif ( defined( $config->{'metric_port'} ) ) {
840 0 ▶ my $metric_host = $config->{ 'metric_host' } || '127.0.0.1';
Condition0%0/2
$config->{'metric_host'} || '127.0.0.1'
l!l
00
MC/DC0%0/1
$config->{'metric_host'} || '127.0.0.1'
$config->{'metric_host'}
Truth table0%0/2
A
A= $config->{'metric_host'}
Aresult
11
00
841 push @ports, {
842 'host' => $metric_host,
843 0 'port' => $config->{'metric_port'},
844 'ipv' => '*',
845 'proto' => 'tcp',
846 };
847 0 _warn( 'Metrics available on ' . $metric_host . ':' . $config->{'metric_port'} );
848 0 _warn( 'metric_host/metric_port are depricated, please use metric_connection/metric_umask instead' );
849 }
850  
851 35 $srvargs{'port'} = \@ports;
852 35 $srvargs{'listen'} = $listen_backlog;
853 35 $srvargs{'leave_children_open_on_hup'} = 1;
854  
855 35 ▶ if ( $config->{'patch_net_server'} && scalar @ports == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"patch_net_server"} and scalar @ports == 1) 0 35 35
Condition33%1/3
$config->{"patch_net_server"} and scalar @ports == 1
!ll&&!rl&&r
3500
MC/DC0%0/2
$config->{"patch_net_server"} and scalar @ports == 1
$config->{"patch_net_server"} scalar @ports == 1
Truth table33%1/3
A and B
A= $config->{"patch_net_server"}B= scalar @ports == 1
ABresult
0X0
100
111
856 0 my $error = 'Net::Server patches can not be applied when listening on a single port';
857 0 _warn $error;
858 0 die;
859 }
860  
861 35 ▶ $srvargs{'max_dequeue'} = $config->{'max_dequeue'} // 5;
Condition50%1/2
$config->{"max_dequeue"} // 5
l!l
035
MC/DC0%0/1
$config->{"max_dequeue"} // 5
$config->{"max_dequeue"}
Truth table50%1/2
A
A= $config->{"max_dequeue"}
Aresult
11
00
862 35 ▶ $srvargs{'check_for_dequeue'} = $config->{'check_for_dequeue'} // 60;
Condition50%1/2
$config->{"check_for_dequeue"} // 60
l!l
035
MC/DC0%0/1
$config->{"check_for_dequeue"} // 60
$config->{"check_for_dequeue"}
Truth table50%1/2
A
A= $config->{"check_for_dequeue"}
Aresult
11
00
863  
864 35 _warn "==========";
865 35 _warn "Starting server";
866 35 _warn "Running with perl $PERL_VERSION";
867 35 _warn "==========";
868  
869 35 my @start_times;
870 35 my $parent_pid = $PID;
871 35 while ( 1 ) {
872 35 unshift @start_times, time();
873  
874 35 eval {
875 35 __PACKAGE__->run( %srvargs );
876 };
877 1 my $error = $@;
878 1 ▶ if ( $PID != $parent_pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Mail::Milter::Authentication::PID != $parent_pid) 1 0 1
879 1 _warn "Child exiting";
880 1 die;
881 }
882 0 ▶ $error = 'unknown error' if ! $error;
Branch: 1 branch
BranchTrueFalseTotal
unless $error 0 0 0
883 0 _warn "Server failed: $error";
884  
885 # We exited abnormally, try and clean up
886 0 eval{ __PACKAGE__->close_children };
887 0 eval{ __PACKAGE__->post_child_cleanup_hook };
888 0 eval{ __PACKAGE__->shutdown_sockets };
889 0 sleep 10;
890  
891 0 ▶ if ( scalar @start_times >= 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @start_times >= 4) 0 0 0
892 0 ▶ if ( $start_times[3] > ( time() - 120 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_times[3] > time - 120) 0 0 0
893 0 eval{ send_panic_email("Error: $error - Abandoning") };
894 0 _warn "Abandoning automatic restart: too many restarts in a short time";
895 0 last;
896 }
897 }
898  
899 0 eval{ send_panic_email("Error: $error - Attempting automatic restart") };
900 0 _warn "Attempting automatic restart";
901 0 sleep 10;
902 }
903 0 _warn "Server exiting abnormally";
904 0 die;
905 }
906  
907 ##### Protocol methods
908  
909  
910 1 ▶sub fatal($self,$error) {
Subroutine fatal: called CC=1 SCAR=0.0
Pod documented
911 1 $self->logerror( "Child process $PID shutting down due to fatal error: $error" );
912 1 die "$error\n";
913 }
914  
915  
916 0 ▶sub fatal_global($self,$error) {
Subroutine fatal_global: not called CC=2 SCAR=17.9
Pod documented
917 0 my $ppid = $self->{'server'}->{'ppid'};
918 0 ▶ if ( $ppid == $PID ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ppid == $Mail::Milter::Authentication::PID) { } 0 0 0
919 0 $self->logerror( "Global shut down due to fatal error: $error" );
920 }
921 else {
922 0 $self->logerror( "Child process $PID signalling global shut down due to fatal error: $error" );
923 0 kill 'TERM', $ppid;
924 }
925 0 die "$error\n";
926 }
927  
928  
929 132 ▶sub setup_handlers($self) {
Subroutine setup_handlers: called CC=2 SCAR=6.9
Pod documented
930 132 $self->logdebug( 'setup objects' );
931 132 my $handler = Mail::Milter::Authentication::Handler->new( $self );
932 132 $self->{'handler'}->{'_Handler'} = $handler;
933  
934 132 my $config = $self->{'config'};
935 132 foreach my $name ( $config->{'load_handlers'}->@* ) {
936 457 $self->setup_handler( $name );
937 }
938 132 $self->sort_all_callbacks();
939 }
940  
941  
942 556 ▶sub load_handler($self,$name) {
Subroutine load_handler: called CC=3 SCAR=11.1
Pod documented
943 ## TODO error handling here
944 556 $self->logdebug( "Load Handler $name" );
945  
946 556 my $package = "Mail::Milter::Authentication::Handler::$name";
947 556 ▶ if ( ! is_loaded ( $package ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not &is_loaded($package)) 369 187 556
948 369 $self->logdebug( "Load Handler Module $name" );
949 369 eval { load $package; };
950 369 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 0 369 369
951 0 $self->fatal_global('Could not load handler ' . $name . ' : ' . $error);
952 }
953 }
954 }
955  
956  
957 457 ▶sub setup_handler($self,$name) {
Subroutine setup_handler: called CC=3 SCAR=11.0
Pod documented
958 ## TODO error handling here
959 457 $self->logdebug( "Instantiate Handler $name" );
960  
961 457 my $package = "Mail::Milter::Authentication::Handler::$name";
962 457 my $object = $package->new( $self );
963 457 $self->{'handler'}->{$name} = $object;
964  
965 457 foreach my $callback ( qw { metrics setup connect helo envfrom envrcpt header eoh body eom addheader abort close dequeue } ) {
966 6398 ▶ if ( $object->can( $callback . '_callback' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($object->can($callback . '_callback')) 2233 4165 6398
967 2233 $self->register_callback( $name, $callback );
968 }
969 }
970 }
971  
972  
973 210 ▶sub destroy_handler {
Subroutine destroy_handler: called CC=1 SCAR=0.0
Pod documented
974 # Unused!
975 210 my ( $self, $name ) = @_;
976 # Remove some back references
977 210 delete $self->{'handler'}->{$name}->{'thischild'};
978 # Remove reference to handler
979 210 delete $self->{'handler'}->{$name};
980 }
981  
982  
983 2233 ▶sub register_callback($self,$name,$callback) {
Subroutine register_callback: called CC=2 SCAR=6.9
Pod documented
984 2233 $self->logdebug( "Register Callback $name:$callback" );
985 2233 ▶ if ( ! exists $self->{'callbacks'}->{$callback} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"callbacks"}{$callback}) 1100 1133 2233
986 1100 $self->{'callbacks'}->{$callback} = [];
987 }
988 2233 push @{ $self->{'callbacks'}->{$callback} }, $name;
989 }
990  
991  
992 132 ▶sub sort_all_callbacks($self) {
Subroutine sort_all_callbacks: called CC=2 SCAR=6.9
Pod documented
993 132 foreach my $callback ( qw { metrics setup connect helo envfrom envrcpt header eoh body eom addheader abort close dequeue } ) {
994 1848 $self->sort_callbacks( $callback );
995 }
996 }
997  
998  
999 1848 ▶sub sort_callbacks($self,$callback) {
Subroutine sort_callbacks: called CC=15 SCAR=27.5
Pod documented
1000 1848 ▶ if ( ! exists $self->{'callbacks'}->{$callback} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"callbacks"}{$callback}) 748 1100 1848
1001 748 $self->{'callbacks'}->{$callback} = [];
1002 }
1003  
1004 1848 ▶ if ( ! exists $self->{'callbacks_list'}->{$callback} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $self->{'callbacks_list'}{$callback}) { } 1848 0 1848
1005 1848 $self->{'callbacks_list'}->{$callback} = [];
1006 }
1007 else {
1008 0 return $self->{'callbacks_list'}->{$callback};
1009 }
1010  
1011 1848 my $callbacks_ref = $self->{'callbacks'}->{$callback};
1012  
1013 1848 my $added = {};
1014 1848 my @order;
1015  
1016 1848 my @todo = sort @{$callbacks_ref};
1017 1848 my $todo_count = scalar @todo;
1018  
1019 # Process requirements
1020 1848 my $requirements = {};
1021 1848 foreach my $item ( @todo ) {
1022 2233 $requirements->{ $item } = [];
1023 2233 my $handler = $self->{'handler'}->{ $item };
1024 2233 my $requires_method = $callback . '_requires';
1025 2233 ▶ if ( $handler->can( $requires_method ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler->can($requires_method)) 182 2051 2233
1026 182 my $requires = $handler->$requires_method;
1027 182 foreach my $require ( $requires->@* ) {
1028 191 push @{ $requirements->{ $item } }, $require;
1029 }
1030 }
1031 }
1032 1848 foreach my $item ( @todo ) {
1033 2233 my $handler = $self->{'handler'}->{ $item };
1034 2233 my $requires_method = $callback . '_required_before';
1035 2233 ▶ if ( $handler->can( $requires_method ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler->can($requires_method)) 0 2233 2233
1036 0 my $requires = $handler->$requires_method;
1037 0 foreach my $require ( $requires->@* ) {
1038 0 push @{ $requirements->{ $require } }, $item;
1039 }
1040 }
1041 }
1042  
1043 1848 ▶ while ( $todo_count ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($todo_count) 1196 1848 3044
1044 1196 my @defer;
1045 1196 foreach my $item ( @todo ) {
1046 2332 my $requires_met = 1;
1047 2332 my $requires = $requirements->{ $item };
1048 2332 foreach my $require ( $requires->@* ) {
1049 331 ▶ if ( ! exists $added->{$require} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $added->{$require}) 138 193 331
1050 138 $requires_met = 0;
1051 }
1052 }
1053 2332 ▶ if ( $requires_met == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($requires_met == 1) { } 2233 99 2332
1054 2233 push @order, $item;
1055 2233 $added->{$item} = 1;
1056 }
1057 else {
1058 99 push @defer, $item;
1059 }
1060 }
1061  
1062 1196 my $defer_count = scalar @defer;
1063 1196 ▶ if ( $defer_count == $todo_count ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($defer_count == $todo_count) 0 1196 1196
1064 0 $self->fatal_global('Could not build order list');
1065 }
1066 1196 $todo_count = $defer_count;
1067 1196 @todo = @defer;
1068 }
1069  
1070 1848 $self->{'callbacks_list'}->{$callback} = \@order;
1071 }
1072  
1073  
1074 23 ▶sub destroy_objects($self) {
Subroutine destroy_objects: called CC=3 SCAR=11.0
Pod documented
1075 23 $self->logdebug ( 'destroy objects' );
1076 23 my $handler = $self->{'handler'}->{'_Handler'};
1077 23 ▶ if ( $handler ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handler) 23 0 23
1078 23 $handler->destroy_all_objects();
1079 23 my $config = $self->{'config'};
1080 23 foreach my $name ( $config->{'load_handlers'}->@* ) {
1081 210 $self->destroy_handler( $name );
1082 }
1083 23 delete $self->{'handler'}->{'_Handler'}->{'config'};
1084 23 delete $self->{'handler'}->{'_Handler'}->{'thischild'};
1085 23 delete $self->{'handler'}->{'_Handler'};
1086 }
1087 }
1088  
1089  
1090  
1091  
1092 ## Logging
1093  
1094  
1095 9595 ▶sub get_queue_id($self) {
Subroutine get_queue_id: called CC=4 SCAR=13.9
Pod documented
1096 9595 my $queue_id;
1097  
1098 9595 ▶ if ( exists ( $self->{'smtp'} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'smtp'}) { } 538 9057 9595
elsif (exists $self->{'handler'}{'_Handler'}) { } 5483 3574 9057
1099 538 ▶ if ( $self->{'smtp'}->{'queue_id'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"smtp"}{"queue_id"}) 538 0 538
1100 538 $queue_id = $self->{'smtp'}->{'queue_id'};
1101 }
1102 }
1103 elsif ( exists ( $self->{'handler'}->{'_Handler'} ) ) {
1104 5483 $queue_id = $self->{'handler'}->{'_Handler'}->get_symbol('i');
1105 }
1106  
1107 9595 return $queue_id;
1108 }
1109  
1110  
1111 0 ▶sub enable_extra_debugging($self) {
Subroutine enable_extra_debugging: not called CC=2 SCAR=17.9
Pod documented
1112 0 ▶ my $config = $self->{'config'} || get_config();
Condition0%0/3
$self->{'config'} || get_config()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'config'} || get_config()
$self->{'config'} get_config()
Truth table0%0/3
A || B
A= $self->{'config'}B= get_config()
ABresult
1X1
011
000
1113 0 $config->{'logtoerr'} = 1;
1114 0 $config->{'debug'} = 1;
1115 0 $self->{'extra_debugging'} = 1;
1116 0 $self->logerror( 'Extra debugging enabled. Child will exit on close.' );
1117 # We don't want to persist this, so force an exit on close state.
1118 0 $self->{'handler'}->{'_Handler'}->{'exit_on_close'} = 1;
1119 }
1120  
1121  
1122 2598 ▶sub extra_debugging($self,$line) {
Subroutine extra_debugging: called CC=2 SCAR=9.2
Pod documented
1123 2598 ▶ if ( $self->{'extra_debugging'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"extra_debugging"}) 0 2598 2598
1124 0 $self->logerror( $line );
1125 }
1126 }
1127  
1128  
1129 1 ▶sub logerror($self,$line) {
Subroutine logerror: called CC=4 SCAR=16.4
Pod documented
1130 1 ▶ my $config = $self->{'config'} || get_config();
Condition33%1/3
$self->{'config'} || get_config()
l!l&&r!l&&!r
100
MC/DC0%0/2
$self->{'config'} || get_config()
$self->{'config'} get_config()
Truth table33%1/3
A || B
A= $self->{'config'}B= get_config()
ABresult
1X1
011
000
1131 1 ▶ if ( my $queue_id = $self->get_queue_id() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $queue_id = $self->get_queue_id) 0 1 1
1132 0 $line = $queue_id . ': ' . $line;
1133 }
1134 1 ▶ _warn( $line ) if $config->{'logtoerr'};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"logtoerr"} 1 0 1
1135 1 logger()->log( { 'level' => 'error' }, $line );
1136 }
1137  
1138  
1139 145 ▶sub loginfo($self,$line) {
Subroutine loginfo: called CC=4 SCAR=14.5
Pod documented
1140 145 ▶ my $config = $self->{'config'} || get_config();
Condition33%1/3
$self->{'config'} || get_config()
l!l&&r!l&&!r
14500
MC/DC0%0/2
$self->{'config'} || get_config()
$self->{'config'} get_config()
Truth table33%1/3
A || B
A= $self->{'config'}B= get_config()
ABresult
1X1
011
000
1141 145 ▶ if ( my $queue_id = $self->get_queue_id() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $queue_id = $self->get_queue_id) 6 139 145
1142 6 $line = $queue_id . ': ' . $line;
1143 }
1144 145 ▶ _warn( $line ) if $config->{'logtoerr'};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"logtoerr"} 145 0 145
1145 145 logger()->log( { 'level' => 'info' }, $line );
1146 }
1147  
1148  
1149 9449 ▶sub logdebug($self,$line) {
Subroutine logdebug: called CC=5 SCAR=16.2
Pod documented
1150 9449 ▶ my $config = $self->{'config'} || get_config();
Condition66%2/3
$self->{'config'} || get_config()
l!l&&r!l&&!r
703124180
MC/DC0%0/2
$self->{'config'} || get_config()
$self->{'config'} get_config()
Truth table66%2/3
A || B
A= $self->{'config'}B= get_config()
ABresult
1X1
011
000
1151 9449 ▶ if ( my $queue_id = $self->get_queue_id() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $queue_id = $self->get_queue_id) 1142 8307 9449
1152 1142 $line = $queue_id . ': ' . $line;
1153 }
1154 9449 ▶ if ( $config->{'debug'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"debug"}) 2068 7381 9449
1155 2068 ▶ _warn( $line ) if $config->{'logtoerr'};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"logtoerr"} 2068 0 2068
1156 2068 logger()->log( { 'level' => 'debug' }, $line );
1157 }
1158 }
1159  
1160 143 1;
1161  
1162 __END__
« Authentication/Handler/DMARC.pm ↑ Summary Authentication/Handler/DKIM.pm »