Authentication.pm

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