From 3156020666ba99db68e3c0c62e817ae90ec6b5a5 Mon Sep 17 00:00:00 2001 From: Scott Kitterman Date: Fri, 3 Feb 2012 23:13:46 -0500 Subject: [PATCH] Reduce non-verbose logging to a single line per message. --- CHANGES | 3 ++ postfix-policyd-spf-perl | 82 +++++++++++++++++++++++----------------- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/CHANGES b/CHANGES index f68d5c4..a0b4a0a 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,9 @@ * Chomp erroneus NULLs off the end of local and authority explanations to work around a Mail::SPF bug (in Mail::SPF versions prior to 2.008) - Patch thanks to Allison Randal + * Stop logging queue ID since it is virtually never available and clutters + the logs + * Reduced non-verbose logging to a single line per-message --- 2.008 (2012-01-19 13:46 -0500) ! Query only TXT and not DNS RR Type SPF records to reduce unnecessary DNS lookups (LP: #161133) diff --git a/postfix-policyd-spf-perl b/postfix-policyd-spf-perl index 2357b13..ec8f9a3 100755 --- a/postfix-policyd-spf-perl +++ b/postfix-policyd-spf-perl @@ -145,7 +145,7 @@ while () { for (sort keys %attr) { syslog(debug => "Attribute: %s=%s", $_ || '', $attr{$_} || ''); } - } + }; my $message_instance = $attr{instance}; my $cache = defined($message_instance) ? $results_cache{$message_instance} ||= {} : {}; @@ -160,11 +160,13 @@ while () { if ($VERBOSE) { syslog(debug => "handler %s: %s", $handler_name || '', $response || ''); - } + }; # Pick whatever response is not 'DUNNO' if ($response and $response !~ /^DUNNO/i) { - syslog(info => "handler %s: is decisive.", $handler_name || ''); + if ($VERBOSE) { + syslog(info => "handler %s: is decisive.", $handler_name || ''); + } $action = $response; last; } @@ -238,12 +240,14 @@ sub sender_policy_framework { # probably due to invalid input data! my $errmsg = $@; $errmsg = $errmsg->text if UNIVERSAL::isa($@, 'Mail::SPF::Exception'); - syslog( - info => "HELO check failed - Mail::SPF->new(%s, %s, %s) failed: %s", - $attr->{client_address} || '', - $attr->{sender} || '', $attr->{helo_name} || '', - $errmsg || '' - ); + if ($VERBOSE) { + syslog( + info => "HELO check failed - Mail::SPF->new(%s, %s, %s) failed: %s", + $attr->{client_address} || '', + $attr->{sender} || '', $attr->{helo_name} || '', + $errmsg || '' + ); + }; return; } @@ -268,27 +272,33 @@ sub sender_policy_framework { # Reject on HELO fail. Defer on HELO temperror if message would otherwise # be accepted. Use the HELO result and return for null sender. if ($helo_result->is_code('fail')) { - syslog( - info => "SPF %s: HELO/EHLO: %s", - $helo_result || '', - $attr->{helo_name} || '' - ); + if ($VERBOSE) { + syslog( + info => "SPF %s: HELO/EHLO: %s", + $helo_result || '', + $attr->{helo_name} || '' + ); + }; return "550 $helo_authority_exp"; } elsif ($helo_result->is_code('temperror')) { - syslog( - info => "SPF %s: HELO/EHLO: %s", - $helo_result || '', - $attr->{helo_name} || '' - ); + if ($VERBOSE) { + syslog( + info => "SPF %s: HELO/EHLO: %s", + $helo_result || '', + $attr->{helo_name} || '' + ); + }; return "DEFER_IF_PERMIT SPF-Result=$helo_local_exp"; } elsif ($attr->{sender} eq '') { - syslog( - info => "SPF %s: HELO/EHLO (Null Sender): %s", - $helo_result || '', - $attr->{helo_name} || '' - ); + if ($VERBOSE) { + syslog( + info => "SPF %s: HELO/EHLO (Null Sender): %s", + $helo_result || '', + $attr->{helo_name} || '' + ); + }; return "PREPEND $helo_spf_header" unless $cache->{added_spf_header}++; } @@ -316,11 +326,13 @@ sub sender_policy_framework { # probably due to invalid input data! my $errmsg = $@; $errmsg = $errmsg->text if UNIVERSAL::isa($@, 'Mail::SPF::Exception'); - syslog( - info => "Mail From (sender) check failed - Mail::SPF->new(%s, %s, %s) failed: %s", - $attr->{client_address} || '', - $attr->{sender} || '', $attr->{helo_name} || '', $errmsg || '' - ); + if ($VERBOSE) { + syslog( + info => "Mail From (sender) check failed - Mail::SPF->new(%s, %s, %s) failed: %s", + $attr->{client_address} || '', + $attr->{sender} || '', $attr->{helo_name} || '', $errmsg || '' + ); + }; return; } @@ -343,11 +355,13 @@ sub sender_policy_framework { }; # Same approach as HELO.... - syslog( - info => "SPF %s: Envelope-from: %s", - $mfrom_result || '', - $attr->{sender} || '' - ); + if ($VERBOSE) { + syslog( + info => "SPF %s: Envelope-from: %s", + $mfrom_result || '', + $attr->{sender} || '' + ); + }; if ($mfrom_result->is_code('fail')) { return "550 $mfrom_authority_exp"; }