Skip to content

Commit

Permalink
Regression fix for default logging destination; Minor fixes and worka…
Browse files Browse the repository at this point in the history
…rounds for older Perls. Thanks to Simon Matter for reports and testing. Closes #30, closes #31.
  • Loading branch information
mpaperno committed Jul 30, 2021
1 parent c32287c commit d748541
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 79 deletions.
136 changes: 72 additions & 64 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ SpamPD Change Log
! : important change, change of default behavior, etc.
-----------------------------------------------------------

2.61 (30-Jul-21)

Minor bug fixes. Thanks to Simon Matter for reporting and testing.

* Restore syslog as default logging destination (https://github.com/mpaperno/spampd/issues/31)
* Fix issues with older Perl versions (https://github.com/mpaperno/spampd/issues/30)


2.60 (26-Jul-21)

This version brings quite a few changes, though the base functionality and compatibility is unchanged
Expand Down Expand Up @@ -63,7 +71,7 @@ This version brings quite a few changes, though the base functionality and compa
Please refer to commit notes at (https://github.com/mpaperno/spampd/compare/2.42...2.50) for details and credits.

########

2.42 (08-Dec-13) (experimental)

- Untaint some params for compatibility with Perl 5.18.
Expand All @@ -76,102 +84,102 @@ Please refer to commit notes at (https://github.com/mpaperno/spampd/compare/2.42

- New config option to load a specific configuration file after the default
local.cf file, thereby overriding any settings therein. The new option is
--saconfig=filename. Thanks to Sven Mueller for code and Bernd Zeimetz for
--saconfig=filename. Thanks to Sven Mueller for code and Bernd Zeimetz for
bringing it up. (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=344373)

- Integrated code by Alexander Wirt to introduce a parameter which
sets a proper home directory (--homedir=path) and also cleans up the
environment before backgrounding.
sets a proper home directory (--homedir=path) and also cleans up the
environment before backgrounding.
(http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=421100)
* NOTE: * default homedir is /var/spool/spamassassin/spampd which needs to be
* NOTE: * default homedir is /var/spool/spamassassin/spampd which needs to be
writable by the user spampd is running as. Previously, some files like the
auto-whitelist were written to the .spamassassin folder inside the users home
directory who started spampd, typically root.

- Integrated fix from Vladislav Kurz for LMTP multi-line response after DATA
is sent. (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=395355)
- Yet another fix for older Net::Server versions (<= 0.87) dying when logging

- Yet another fix for older Net::Server versions (<= 0.87) dying when logging
a % character to Sys::Syslog. This also fixes the bug in 2.30 that logs "%s"
instead of the actual messages on some system.
- Fixed bug with temp files sticking around until spampd child exists,
introduced when SA 3.0 was released

- Fixed bug with temp files sticking around until spampd child exists,
introduced when SA 3.0 was released
(https://issues.apache.org/SpamAssassin/show_bug.cgi?id=5444).
Thanks to Simon Matter for bringing this to my attention.

########

2.30 (31-Oct-05)
- Another, hopefully final, fix for the Sys::Syslog issue of % signs in the log
string. Fixes possible DoS vulnerability. Thanks to Sven Mueller and Florian
string. Fixes possible DoS vulnerability. Thanks to Sven Mueller and Florian
Weimer for the solution.
- Added new options for adding X-Envelope-From and (optionally) X-Envelope-To
headers to messages before SA processing. The idea is to help SA process any
headers to messages before SA processing. The idea is to help SA process any
blacklist/whitelist to/from directives on the actual sender/recipients instead
of the possibly bogus envelope headers. Use --seh or --set-envelope-headers
of the possibly bogus envelope headers. Use --seh or --set-envelope-headers
to enable setting both headers, or use --sef or --set-envelope-from to enable
only X-Envelope-From. If added, spampd attempts to remove the X-Envelope-To
header after SA processing to preserve BCC recipient anonymity, but enabling
this header may still expose recipient information. See man page for more
details. This patch was originally submitted by Sven Mueller, was slightly
only X-Envelope-From. If added, spampd attempts to remove the X-Envelope-To
header after SA processing to preserve BCC recipient anonymity, but enabling
this header may still expose recipient information. See man page for more
details. This patch was originally submitted by Sven Mueller, was slightly
modified, and the --sef option was added.

########

2.21 (23-Oct-05) (unreleased)
- fixed SA version check on alphanumeric version strings. Stops the annoying
- fixed SA version check on alphanumeric version strings. Stops the annoying
Perl warning messages in the mail log. Thanks to Sven Mueller for the fix.

########

2.20 (05-Oct-04)
- added support for SpamAssassin version 3. spampd should now support all
- added support for SpamAssassin version 3. spampd should now support all
SA versions (tested with 2.6.3 and 3.0.0).
- removed --add-sc-header feature. It is now redundant with SA v2.6 ability
- removed --add-sc-header feature. It is now redundant with SA v2.6 ability
to (almost fully) customize headers, which v3 improves on. If anyone
really needs this feature, please let me know.
- added --nodetach option to prevent daemon process backgrounding. Patch
provided by Urban Petry. Can be useful for win32/cygwin.
- if --debug is specified, Net::Server log level is increased to 4 (debug)
to provide some more info in the log (can be useful for diagnosing
to provide some more info in the log (can be useful for diagnosing
user/permission issues). Thanks to Urban Petry for idea.
- the message sender (From header) is now included in the log along with message
ID, recipient, and scoring info. Thanks to Roland Koeckel for the patch.

########

2.13 (24-Nov-03)
- SA debug messages redirected from STDERR (warn) to syslog. Thanks to Roland
- SA debug messages redirected from STDERR (warn) to syslog. Thanks to Roland
Koeckel for the suggestion.

########

2.12 (15-Nov-03)
- fixed bug related to Sys::Syslog where we needed to escape % signs in
Message IDs. Thanks to Jeffrey W. Collyer and Yann Grossel for the bug reports.
- minor performance improvement in SpamPD::Client using buffered write to send
- minor performance improvement in SpamPD::Client using buffered write to send
message data. Thanks to Sam Horrocks for the tip.
- fixed error condition when an error response ([4|5]xx) was returned after a
- fixed error condition when an error response ([4|5]xx) was returned after a
DATA command was sent. Thanks to Rodrigo Ventura for bug reports about this.

########

2.11 (15-Jul-03):
- fix for occasional corrupted message headers which caused blank messages
(seemed to have only affected certain malformed spam mail).
- added --logsock option for syslog socket. Defaults to 'unix' except for
HP-UX and SunOS (Solaris) which I'm told prefer 'inet'.

########

2.10 (01-Jul-03):
- added optional 'X-Spam-Checked-By: {hostname}' header, where {hostname} is,
theoretically, the name of the machine doing the message scanning. New
options --add-sc-header and --hostname=name control this behavior.

########

2.00 (10-Jun-03):
- major rewrite of how mail is handled internally. spampd now takes no
responsibility for the mail at any point, instead acting as a transparent
Expand All @@ -191,80 +199,80 @@ Please refer to commit notes at (https://github.com/mpaperno/spampd/compare/2.42
under /tmp, which should be a tmpfs; this prevents the allocation
overhead associated with large strings (often 2-3x) and ensures that
space will be returned to the OS as soon as it's not needed."

- as a bonus feature, LMTP is now supported by virtue of spampd's transparency.

- added a timeout check around the socket operations as suggested in the
- added a timeout check around the socket operations as suggested in the
Net::Server docs. Added new parameter to control this: --childtimeout=n
where n is number of seconds.

- added a timeout check around the message processing (spam checking) routines
to guard against a SpamAssassin hang. Added new parameter to control
to guard against a SpamAssassin hang. Added new parameter to control
this: --satimeout=n where n is number of seconds. If a timeout (or error)
occurs while processing, the mail is still passed on unless the new --dose
(die-on-sa-errors) paramater is given.
- added --children=n parameter to specify how many child
servers to spawn and maintain. Default is 5 children (plus

- added --children=n parameter to specify how many child
servers to spawn and maintain. Default is 5 children (plus
one parent).

- now uses Net::Server::PreForkSimple instead of PreFork. (Tried utilizing the
advanced children pool features of PreFork but either couldn't figure it out
or they're kinda broken. If anyone has experience here, please let me know.)

- improved logging including the Message-ID, recipients, 100ths precision
on spam score, processing time, and file size. Logging format now better
resembles that of spamd (which hopefully means spamd log analysis tools can be
made to work with spampd easily).

- removed dependencies on Net::SMTP, Net::SMTP::Server::Client, and Error
modules.

- host/port and relay host/port can both be specified as xx.xx.xx.xx:nn in
the --host and --relayhost parameters, or as individual parameters (--host,
--port, --relayhost, --relayport).
# The next 3 items are ideas/patches by
# Kurt Andersen,

# The next 3 items are ideas/patches by
# Kurt Andersen,
# Agilent Technologies Postmaster
# Global Messaging Team, Agilent Technologies

- added optional support for Time::HiRes for more accurate processing time
- added optional support for Time::HiRes for more accurate processing time
reporting in the log (automatically loaded if Time::HiRes is available).

- added optional logging of which SA rules matched a message. New option is
--log-rules-hit or --rh for short.

- Added auto HPUX OS detection for syslog loggging
"(for some reason HPUX chokes on using the 'unix' socket type)."

# Thanks Kurt!

- added much more verbose spampd logging when using the --debug option.

- 3 parameters are now deprecated but accepted for backwards compatability:
--dead-letters, --heloname, and --stop-at-threshold
- added shorthand choice for some options:

- added shorthand choice for some options:
--aw for --auto-whitelist; --L for --local-only; --a for --tagall
--u for --user; --g for --group; --p for --pid
--d for --debug; --h for --help;
--d for --debug; --h for --help;

- documentation updates

- licensing change due to use of Bennet Todd's code (to GNU GPL from Perl
- licensing change due to use of Bennet Todd's code (to GNU GPL from Perl
Artistic).

########

1.0.2 (13-Apr-03):
- added 'local-only' parameter to pass on to SA which turns off all
- added 'local-only' parameter to pass on to SA which turns off all
network-based tests (DNS, Razor, etc).

########
1.0.1 (3-Feb-03):
- fixed minor but substantial bug preventing child processes

1.0.1 (3-Feb-03):
- fixed minor but substantial bug preventing child processes
from exiting properly since the counter wasn't being incremented (d'oh!).
Thanks to Mark Blackman for pointing this out.

Expand All @@ -273,13 +281,13 @@ Please refer to commit notes at (https://github.com/mpaperno/spampd/compare/2.42
########

Changes to assassind (1.0.0 initial release of spampd - May 2002):
A different message rewriting method (using
Mail::SpamAssassin::NoMailAudit instead of Dave Carrigan's
custom headers and Mail::Audit);
Adding more options for message handling, network/protocol options,
A different message rewriting method (using
Mail::SpamAssassin::NoMailAudit instead of Dave Carrigan's
custom headers and Mail::Audit);
Adding more options for message handling, network/protocol options,
some options to pass on to SpamAssassin (such as whitelist usage);
More orientation to being used as a content filter for the
Postfix MTA, mostly by changing some default values;
More orientation to being used as a content filter for the
Postfix MTA, mostly by changing some default values;
Documentation changes;

## EOF ##
37 changes: 22 additions & 15 deletions spampd.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
######################
# SpamPD - Spam Proxy Daemon
#
# v2.61 - 30-Jul-21
# v2.60 - 26-Jul-21
# v2.53 - 25-Feb-19
# v2.52 - 10-Nov-18
Expand All @@ -24,7 +25,7 @@
# v1.0.1 - 03-Feb-03
# v1.0.0 - May 2002
#
# spampd is Copyright (c) 2002-2006, 2009-2010, 2013, 2018-2019 Maxim Paperno; All Rights Reserved.
# spampd is Copyright (c) Maxim Paperno; All Rights Reserved.
#
# Written and maintained by Maxim Paperno ([email protected])
#
Expand Down Expand Up @@ -392,7 +393,7 @@ BEGIN
use Time::HiRes qw(time);
use Mail::SpamAssassin ();

our $VERSION = '2.60';
our $VERSION = '2.61';

# ISA will change to a Net::Server "flavor" at runtime based on options.
our @ISA = qw(Net::Server);
Expand Down Expand Up @@ -570,14 +571,17 @@ sub initial_options_map {
# Also a good place to check for help/version/show option(s), but not if we're HUPping.
# These all cause an exit(0) (--show is processed later but still exits).
if (!$self->is_reloading()) {
my ($q2, $q3, $q4) = ("|??", "|???", "|????");
# https://github.com/mpaperno/spampd/issues/30#issuecomment-889110122
$q2 = $q3 = $q4 = "" if ($Getopt::Long::VERSION < 2.39);
%options = (
%options,
'show=s@' => \$spd_p->{show_dbg},
'help|h|?:s' => sub { $self->usage(0, 1, $_[1]); },
'hh|??:s' => sub { $self->usage(0, 2, $_[1]); },
'hhh|???:s' => sub { $self->usage(0, 3, $_[1]); },
'hhhh|????|man:s' => sub { $self->usage(0, 4, $_[1]); },
'version|vers' => sub { $self->version(); },
'show=s@' => \$spd_p->{show_dbg},
'help|h|?:s' => sub { $self->usage(0, 1, $_[1]); },
'hh'.$q2.':s' => sub { $self->usage(0, 2, $_[1]); },
'hhh'.$q3.':s' => sub { $self->usage(0, 3, $_[1]); },
'hhhh'.$q4.'|man:s' => sub { $self->usage(0, 4, $_[1]); },
'version|vers' => sub { $self->version(); },
);
}
return %options;
Expand Down Expand Up @@ -699,10 +703,10 @@ sub handle_main_opts {
$spd_p->{logtype} &= ~LOG_TYPE_MASK; # reset the low byte containing LOG_<type> constant
($spd_p->{logtype}, $srv_p->{log_file}) = logfile2logtype($spd_p->{logspec}, $spd_p->{logtype});
}
elsif (!$srv_p->{background}) {
# set default logging to stderr if not daemonizing and user didn't specify.
$spd_p->{logtype} = $spd_p->{logtype} & (~LOG_TYPE_MASK) | LOG_STDERR;
}
# elsif (!$srv_p->{background}) {
# # set default logging to stderr if not daemonizing and user didn't specify.
# $spd_p->{logtype} = $spd_p->{logtype} & (~LOG_TYPE_MASK) | LOG_SYSLOG;
# }

# fixup listening socket/host/port if needed
if ($spd_p->{socket}) {
Expand Down Expand Up @@ -1383,7 +1387,7 @@ sub print_options {
print "# This format is suitable as a configuration file. Just remove\n".
"# the '#' marks (comment characters) and change values as needed.\n\n" if $exit > -1;
for my $k (sort keys %{$opts}) {
my $v = %{$opts}{$k};
my $v = $opts->{$k};
next if ref($v) !~ /SCALAR|REF/;
$k = $1 if $k =~ /([\w-]+).*/;
$v = defined(${$v}) ? ${$v} : "(undefined)";
Expand Down Expand Up @@ -1425,8 +1429,11 @@ sub show_debug {
if (@dumps) {
eval {
require Data::Dumper;
$Data::Dumper::Quotekeys = 0; $Data::Dumper::Bless = '';
$Data::Dumper::Sortkeys = $Data::Dumper::Sparseseen = 1;
no warnings 'once'; # https://github.com/mpaperno/spampd/issues/30#issuecomment-889117210
$Data::Dumper::Quotekeys = 0;
$Data::Dumper::Bless = '';
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Sparseseen = 1;
print("\n". Data::Dumper->Dump(\@dumps, \@dnames) ."\n");
};
warn "Data::Dumper error:\n\t$@\n\n" if $@;
Expand Down

0 comments on commit d748541

Please sign in to comment.