| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} // []
MC/DC0%0/1
$self->{"server"}{"sock"} // []
$self->{"server"}{"sock"}
Truth table50%1/2
A
A= $self->{"server"}{"sock"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 73 | ▶ | next if $sock->NS_proto !~ /^UNIX/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 72 | my $path = $sock->NS_port; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 72 | my $umask = $umasks->{ $path }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 72 | ▶ | next if ! defined $umask; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} // {}
MC/DC100%1/1
$config->{"connections"} // {}
$config->{"connections"}
Truth table100%2/2
A
A= $config->{"connections"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'}
MC/DC100%2/2
$connection->{'umask'} || $config->{'umask'}
$connection->{'umask'}
$config->{'umask'}
Truth table100%3/3
A || B
A= $connection->{'umask'}B= $config->{'umask'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 84 | ▶ | next if ! $umask; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 81 | ▶ | next if ( $connection->{'connection'} // q{} ) !~ /^unix:([^:@]+)/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$connection->{"connection"} // ""
MC/DC0%0/1
$connection->{"connection"} // ""
$connection->{"connection"}
Truth table50%1/2
A
A= $connection->{"connection"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 66 | $object->pre_loop_setup(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 298 | ▶ | if ( $object->can( 'register_metrics' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 34 | ▶ | open( STDERR, '>>', $config->{'error_log'} ) || die "Cannot open errlog [$!]"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 34 | ▶ | open( STDOUT, '>>', $config->{'error_log'} ) || die "Cannot open errlog [$!]"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 23 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 23 | ▶ | open( STDERR, '>>', $config->{'error_log'} ) || die "Cannot open errlog [$!]"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 23 | ▶ | open( STDOUT, '>>', $config->{'error_log'} ) || die "Cannot open errlog [$!]"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 23 | ▶ | if ( my $error = $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 23 | ▶ | if ( $arg eq 'dequeue' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 22 | ▶ | if ( $arg eq 'dequeue' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$config->{"dequeue_timeout"} // 300
$config->{"dequeue_timeout"}
Truth table0%0/2
A
A= $config->{"dequeue_timeout"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my $proto = $socket->NS_proto; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | ▶ | $proto = "UNIX" if $proto =~ m/^UNIX/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | return $proto; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1205 | ▶ | if ($socket->isa("IO::Socket::IP")) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | return "TCP"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 1205 | ▶ | if ($socket->isa("IO::Socket::INET")) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | return "TCP"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 1205 | ▶ | if ($socket->isa("IO::Socket::INET6")) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | return "TCP"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1205 | ▶ | if ($socket->isa("IO::Socket::UNIX")) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 || ''
MC/DC0%0/1
$3 || ''
$3
Truth table50%1/2
A
A= $3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
defined $config->{"metric_port"} and $self->get_client_proto eq "TCP" and $self->get_client_port eq $config->{"metric_port"}
defined $config->{"metric_port"} and $self->get_client_proto eq "TCP"
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
defined $config->{"metric_connection"} and $metric_type eq "inet" and $self->get_client_proto eq "TCP"
defined $config->{"metric_connection"} and $metric_type eq "inet"
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
defined $config->{"metric_connection"} and $metric_type eq "unix" and $self->get_client_proto eq "UNIX"
defined $config->{"metric_connection"} and $metric_type eq "unix"
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
MC/DC0%0/1
$config->{'errors_to'} || (return)
$config->{'errors_to'}
Truth table50%1/2
A
A= $config->{'errors_to'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | my $errors_from = $config->{'errors_from'} || return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{'errors_from'} || (return)
MC/DC0%0/1
$config->{'errors_from'} || (return)
$config->{'errors_from'}
Truth table0%0/2
A
A= $config->{'errors_from'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | ▶ | my $errors_headers = $config->{'errors_headers'} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{'errors_headers'} || {}
MC/DC0%0/1
$config->{'errors_headers'} || {}
$config->{'errors_headers'}
Truth table0%0/2
A
A= $config->{'errors_headers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$process->pid == $ppid or $process->ppid == $ppid
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | my $pid = eval{ $process->pid } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$process->pid
}
} // ""
MC/DC0%0/1
eval {
do {
$process->pid
}
} // ""
eval {
do {
$process->pid
}
}
Truth table0%0/2
A
A= eval {
do {
$process->pid
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | my $cmndline = eval{ $process->cmndline } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$process->cmndline
}
} // ""
MC/DC0%0/1
eval {
do {
$process->cmndline
}
} // ""
eval {
do {
$process->cmndline
}
}
Truth table0%0/2
A
A= eval {
do {
$process->cmndline
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | my $size = eval{ $process->size } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$process->size
}
} // ""
MC/DC0%0/1
eval {
do {
$process->size
}
} // ""
eval {
do {
$process->size
}
}
Truth table0%0/2
A
A= eval {
do {
$process->size
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | my $rss = eval{ $process->rss } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$process->rss
}
} // ""
MC/DC0%0/1
eval {
do {
$process->rss
}
} // ""
eval {
do {
$process->rss
}
}
Truth table0%0/2
A
A= eval {
do {
$process->rss
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | ▶ | my $pctmem = eval{ $process->pctmem } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$process->pctmem
}
} // ""
MC/DC0%0/1
eval {
do {
$process->pctmem
}
} // ""
eval {
do {
$process->pctmem
}
}
Truth table0%0/2
A
A= eval {
do {
$process->pctmem
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | my $pctcpu = eval{ $process->pctcpu } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$process->pctcpu
}
} // ""
MC/DC0%0/1
eval {
do {
$process->pctcpu
}
} // ""
eval {
do {
$process->pctcpu
}
}
Truth table0%0/2
A
A= eval {
do {
$process->pctcpu
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
MC/DC0%0/1
$config->{'errors_to'} || (return)
$config->{'errors_to'}
Truth table0%0/2
A
A= $config->{'errors_to'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | my $errors_from = $config->{'errors_from'} || return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{'errors_from'} || (return)
MC/DC0%0/1
$config->{'errors_from'} || (return)
$config->{'errors_from'}
Truth table0%0/2
A
A= $config->{'errors_from'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | my $errors_headers = $config->{'errors_headers'} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config->{'errors_headers'} || {}
MC/DC0%0/1
$config->{'errors_headers'} || {}
$config->{'errors_headers'}
Truth table0%0/2
A
A= $config->{'errors_headers'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$process->pid == $Mail::Milter::Authentication::PID or $process->ppid == $Mail::Milter::Authentication::PID
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | ▶ | my $pid = eval{ $process->pid } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$process->pid
}
} // ""
MC/DC0%0/1
eval {
do {
$process->pid
}
} // ""
eval {
do {
$process->pid
}
}
Truth table0%0/2
A
A= eval {
do {
$process->pid
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | my $cmndline = eval{ $process->cmndline } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$process->cmndline
}
} // ""
MC/DC0%0/1
eval {
do {
$process->cmndline
}
} // ""
eval {
do {
$process->cmndline
}
}
Truth table0%0/2
A
A= eval {
do {
$process->cmndline
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | my $size = eval{ $process->size } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$process->size
}
} // ""
MC/DC0%0/1
eval {
do {
$process->size
}
} // ""
eval {
do {
$process->size
}
}
Truth table0%0/2
A
A= eval {
do {
$process->size
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | my $rss = eval{ $process->rss } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$process->rss
}
} // ""
MC/DC0%0/1
eval {
do {
$process->rss
}
} // ""
eval {
do {
$process->rss
}
}
Truth table0%0/2
A
A= eval {
do {
$process->rss
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | ▶ | my $pctmem = eval{ $process->pctmem } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$process->pctmem
}
} // ""
MC/DC0%0/1
eval {
do {
$process->pctmem
}
} // ""
eval {
do {
$process->pctmem
}
}
Truth table0%0/2
A
A= eval {
do {
$process->pctmem
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | my $pctcpu = eval{ $process->pctcpu } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
$process->pctcpu
}
} // ""
MC/DC0%0/1
eval {
do {
$process->pctcpu
}
} // ""
eval {
do {
$process->pctcpu
}
}
Truth table0%0/2
A
A= eval {
do {
$process->pctcpu
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | return undef; ## no critic | |||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | if ( ! -e $pid_file ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
MC/DC0%0/1
$pid_file || (return undef)
$pid_file
Truth table0%0/2
A
A= $pid_file
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | ▶ | if ( $process->cmndline eq $Mail::Milter::Authentication::Config::IDENT . ':control' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | $found_self = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | if ( $process->pid == $pid ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | $found_pid = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | ▶ | if ( $process->cmndline eq $Mail::Milter::Authentication::Config::IDENT . ':parent' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | ▶ | if ( $found_pid ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | return $process->pid; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | ▶ | if ( $process->cmndline eq $Mail::Milter::Authentication::Config::IDENT . ':parent' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | my $pid = get_valid_pid( $pid_file ) || find_process(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
get_valid_pid($pid_file) || find_process()
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()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | ▶ | if ( $pid ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | ▶ | my $pid = get_valid_pid( $pid_file ) || find_process(); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
get_valid_pid($pid_file) || find_process()
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()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ▶ | if ( $pid ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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()
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()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | if ( $pid ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | print "Process running with pid $pid\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | ▶ | if ( ! get_valid_pid( $pid_file ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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')
MC/DC0%0/1
$config->{'connection'} || die('No connection details given')
$config->{'connection'}
Truth table50%1/2
A
A= $config->{'connection'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$config->{'listen_backlog'} || 20
$config->{'listen_backlog'}
Truth table50%1/2
A
A= $config->{'listen_backlog'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 34 | ▶ | my $max_children = $config->{'max_children'} || 100; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'max_children'} || 100
MC/DC0%0/1
$config->{'max_children'} || 100
$config->{'max_children'}
Truth table50%1/2
A
A= $config->{'max_children'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 34 | ▶ | my $max_requests_per_child = $config->{'max_requests_per_child'} || 200; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'max_requests_per_child'} || 200
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 34 | ▶ | my $min_children = $config->{'min_children'} || 20; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'min_children'} || 20
MC/DC0%0/1
$config->{'min_children'} || 20
$config->{'min_children'}
Truth table50%1/2
A
A= $config->{'min_children'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 34 | ▶ | my $max_spare_children = $config->{'max_spare_children'} || 20; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'max_spare_children'} || 20
MC/DC0%0/1
$config->{'max_spare_children'} || 20
$config->{'max_spare_children'}
Truth table50%1/2
A
A= $config->{'max_spare_children'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 34 | ▶ | my $min_spare_children = $config->{'min_spare_children'} || 10; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{'min_spare_children'} || 10
MC/DC0%0/1
$config->{'min_spare_children'} || 10
$config->{'min_spare_children'}
Truth table50%1/2
A
A= $config->{'min_spare_children'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 34 | ▶ | open( STDERR, '>>', $config->{'error_log'} ) || die "Cannot open errlog [$!]"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 34 | ▶ | open( STDOUT, '>>', $config->{'error_log'} ) || die "Cannot open errlog [$!]"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 34 | ▶ | if ( $args->{'daemon'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 0 | ▶ | if ( $EUID == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 34 | ▶ | if ( $EUID == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | my $user = $config->{'runas'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | my $group = $config->{'rungroup'}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | ▶ | if ( $user && $group ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$user and $group
MC/DC0%0/2
$user and $group
$user
$group
Truth table0%0/3
A and B
A= $userB= $group
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | ▶ | if ( ! -e $config->{'error_log'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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")
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | close $outf; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 0 | ▶ | if ( $user ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 || ''
MC/DC0%0/1
$3 || ''
$3
Truth table50%1/2
A
A= $3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 34 | ▶ | if ( $type eq 'inet' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 || ''
MC/DC0%0/1
$3 || ''
$3
Truth table50%1/2
A
A= $3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 34 | ▶ | if ( $type eq 'inet' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'
MC/DC0%0/1
$config->{'metric_host'} || '127.0.0.1'
$config->{'metric_host'}
Truth table0%0/2
A
A= $config->{'metric_host'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$config->{"patch_net_server"} and scalar @ports == 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$config->{"max_dequeue"} // 5
$config->{"max_dequeue"}
Truth table50%1/2
A
A= $config->{"max_dequeue"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 34 | ▶ | $srvargs{'check_for_dequeue'} = $config->{'check_for_dequeue'} // 60; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$config->{"check_for_dequeue"} // 60
MC/DC0%0/1
$config->{"check_for_dequeue"} // 60
$config->{"check_for_dequeue"}
Truth table50%1/2
A
A= $config->{"check_for_dequeue"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 1 | _warn "Child exiting"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 1 | die; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 0 | ▶ | $error = 'unknown error' if ! $error; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 0 | ▶ | if ( $start_times[3] > ( time() - 120 ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | 360 | $self->logdebug( "Load Handler Module $name" ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | 360 | eval { load $package; }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 360 | ▶ | if ( my $error = $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 747 | $self->{'callbacks'}->{$callback} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 1834 | ▶ | if ( ! exists $self->{'callbacks_list'}->{$callback} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | 135 | $requires_met = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 2278 | ▶ | if ( $requires_met == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 538 | ▶ | if ( $self->{'smtp'}->{'queue_id'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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()
MC/DC0%0/2
$self->{'config'} || get_config()
$self->{'config'}
get_config()
Truth table0%0/3
A || B
A= $self->{'config'}B= get_config()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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()
MC/DC0%0/2
$self->{'config'} || get_config()
$self->{'config'}
get_config()
Truth table33%1/3
A || B
A= $self->{'config'}B= get_config()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 1 | ▶ | if ( my $queue_id = $self->get_queue_id() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | 0 | $line = $queue_id . ': ' . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | 1 | ▶ | _warn( $line ) if $config->{'logtoerr'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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()
MC/DC0%0/2
$self->{'config'} || get_config()
$self->{'config'}
get_config()
Truth table33%1/3
A || B
A= $self->{'config'}B= get_config()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | 144 | ▶ | if ( my $queue_id = $self->get_queue_id() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 6 | $line = $queue_id . ': ' . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | 144 | ▶ | _warn( $line ) if $config->{'logtoerr'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 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()
MC/DC0%0/2
$self->{'config'} || get_config()
$self->{'config'}
get_config()
Truth table66%2/3
A || B
A= $self->{'config'}B= get_config()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | 9327 | ▶ | if ( my $queue_id = $self->get_queue_id() ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | 1140 | $line = $queue_id . ': ' . $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | 9327 | ▶ | if ( $config->{'debug'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | 2068 | ▶ | _warn( $line ) if $config->{'logtoerr'}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | 2068 | logger()->log( { 'level' => 'debug' }, $line ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | 143 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||