Skip to content

Commit 5e730ed

Browse files
authored
Milter Hotfix (#623)
* Integrate working version of Sendmail::PMilter * Update VERSION, changelog Add failsafe mechanism to MSMilter
1 parent 56f8e3f commit 5e730ed

File tree

6 files changed

+2120
-5
lines changed

6 files changed

+2120
-5
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.4.5-2
1+
5.4.5-3

changelog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
10/29/2022 Changes in v5.4.5-3
2+
==================================
3+
4+
- Integrate working version of Sendmail::PMilter (milter)
5+
(Version 1.2x from CPAN not working with postfix currently)
6+
17
10/09/2022 Changes in v5.4.5-2
28
==================================
39

common/usr/sbin/MSMilter

+10-4
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,20 @@ sub eom_callback
515515
Sendmail::PMilter::SMFIS_TEMPFAIL;
516516
return;
517517
}
518+
518519
my $file = @{$incoming}[0] . '/temp-' . ${$message_ref};
519520
my $file2 = @{$incoming}[0] . '/' . ${$message_ref};
520521

521-
copy($file, $file2);
522+
if ( -e $file) {
523+
copy($file, $file2);
522524

523-
# Send DISCARD signal to accept message and drop from postfix
524-
# for mailscanner processing
525-
Sendmail::PMilter::SMFIS_DISCARD;
525+
# Send DISCARD signal to accept message and drop from postfix
526+
# for mailscanner processing
527+
Sendmail::PMilter::SMFIS_DISCARD;
528+
} else {
529+
# Something went wrong (file not present, could indicate broken module dependency)
530+
Sendmail::PMilter::SMFIS_TEMPFAIL;
531+
}
526532
}
527533

528534
sub close_callback
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# $Id: Milter.pm,v 1.10 2004/08/04 17:07:51 tvierling Exp $
2+
#
3+
# Copyright (c) 2002-2004 Todd Vierling <[email protected]> <[email protected]>
4+
# All rights reserved.
5+
#
6+
# Redistribution and use in source and binary forms, with or without
7+
# modification, are permitted provided that the following conditions are met:
8+
#
9+
# 1. Redistributions of source code must retain the above copyright notice,
10+
# this list of conditions and the following disclaimer.
11+
#
12+
# 2. Redistributions in binary form must reproduce the above copyright
13+
# notice, this list of conditions and the following disclaimer in the
14+
# documentation and/or other materials provided with the distribution.
15+
#
16+
# 3. Neither the name of the author nor the names of contributors may be used
17+
# to endorse or promote products derived from this software without specific
18+
# prior written permission.
19+
#
20+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
# POSSIBILITY OF SUCH DAMAGE.
31+
32+
package Sendmail::Milter;
33+
34+
use base Exporter;
35+
36+
use strict;
37+
use warnings;
38+
39+
##### Symbols exported to the caller
40+
41+
our @EXPORT = qw(
42+
SMFIS_CONTINUE
43+
SMFIS_REJECT
44+
SMFIS_DISCARD
45+
SMFIS_ACCEPT
46+
SMFIS_TEMPFAIL
47+
48+
SMFIF_ADDHDRS
49+
SMFIF_CHGBODY
50+
SMFIF_ADDRCPT
51+
SMFIF_DELRCPT
52+
SMFIF_CHGHDRS
53+
SMFIF_MODBODY
54+
55+
SMFI_V1_ACTS
56+
SMFI_V2_ACTS
57+
SMFI_CURR_ACTS
58+
);
59+
our @EXPORT_OK = ( @EXPORT );
60+
our %EXPORT_TAGS = ( 'all' => [ @EXPORT_OK ] );
61+
62+
##### Protocol constants
63+
64+
# SMFIS_ are not the same as the standard, in order to keep "0" and "1"
65+
# from being valid response codes by mistake.
66+
67+
use constant SMFIS_CONTINUE => 100;
68+
use constant SMFIS_REJECT => 101;
69+
use constant SMFIS_DISCARD => 102;
70+
use constant SMFIS_ACCEPT => 103;
71+
use constant SMFIS_TEMPFAIL => 104;
72+
73+
use constant SMFIF_ADDHDRS => 0x01;
74+
use constant SMFIF_CHGBODY => 0x02;
75+
use constant SMFIF_ADDRCPT => 0x04;
76+
use constant SMFIF_DELRCPT => 0x08;
77+
use constant SMFIF_CHGHDRS => 0x10;
78+
use constant SMFIF_MODBODY => SMFIF_CHGBODY;
79+
80+
use constant SMFI_V1_ACTS => SMFIF_ADDHDRS|SMFIF_CHGBODY|SMFIF_ADDRCPT|SMFIF_DELRCPT;
81+
use constant SMFI_V2_ACTS => SMFI_V1_ACTS|SMFIF_CHGHDRS;
82+
use constant SMFI_CURR_ACTS => SMFI_V2_ACTS;
83+
84+
##### Callback function names
85+
86+
my @callback_names = qw(close connect helo abort envfrom envrcpt header eoh body eom);
87+
our %DEFAULT_CALLBACKS = map { $_ => $_.'_callback' } @callback_names;
88+
89+
##### Version of "official" Sendmail::Milter emulated here
90+
91+
our $VERSION = '0.18';
92+
93+
##### Global instance of PMilter engine
94+
95+
my $milter;
96+
97+
##### Function subroutines
98+
99+
sub auto_getconn ($;$) {
100+
require Sendmail::PMilter;
101+
unshift(@_, get_milter());
102+
goto &Sendmail::PMilter::auto_getconn;
103+
}
104+
105+
sub auto_setconn ($;$) {
106+
require Sendmail::PMilter;
107+
unshift(@_, get_milter());
108+
goto &Sendmail::PMilter::auto_setconn;
109+
}
110+
111+
sub get_milter () {
112+
require Sendmail::PMilter;
113+
$milter = new Sendmail::PMilter unless defined($milter);
114+
$milter;
115+
}
116+
117+
sub main (;$$) {
118+
require Sendmail::PMilter;
119+
unshift(@_, get_milter());
120+
goto &Sendmail::PMilter::main;
121+
}
122+
123+
sub register ($$;$) {
124+
require Sendmail::PMilter;
125+
unshift(@_, get_milter());
126+
goto &Sendmail::PMilter::register;
127+
}
128+
129+
sub setconn ($) {
130+
require Sendmail::PMilter;
131+
unshift(@_, get_milter());
132+
goto &Sendmail::PMilter::setconn;
133+
}
134+
135+
sub setdbg ($) {
136+
# no-op
137+
}
138+
139+
sub settimeout ($) {
140+
# no-op
141+
}
142+
143+
1;
144+
__END__
145+
146+
=pod
147+
148+
=head1 SYNOPSIS
149+
150+
use Sendmail::Milter;
151+
152+
Sendmail::Milter::auto_setconn(NAME);
153+
Sendmail::Milter::register(NAME, { CALLBACKS }, FLAGS);
154+
Sendmail::Milter::main();
155+
156+
=head1 DESCRIPTION
157+
158+
This is a compatibility interface which emulates the "standard"
159+
Sendmail::Milter API.
160+
161+
=head1 FUNCTIONS
162+
163+
The following functions are available in this module. Unlike
164+
C<Sendmail::PMilter>, this interface involves a single, global instance of
165+
milter data, so these functions are called without an object reference.
166+
167+
For each function, see the description of its object-based counterpart in
168+
L<Sendmail::PMilter>.
169+
170+
=over 4
171+
172+
=item Sendmail::Milter::auto_getconn(NAME[, CONFIG])
173+
174+
=item Sendmail::Milter::auto_setconn(NAME[, CONFIG])
175+
176+
=item Sendmail::Milter::main([MAXCHILDREN[, MAXREQ]])
177+
178+
=item Sendmail::Milter::register(NAME, CALLBACKS[, FLAGS])
179+
180+
=item Sendmail::Milter::setconn(DESC)
181+
182+
=back
183+
184+
One extension function is provided by this implementation.
185+
186+
=over 4
187+
188+
=item Sendmail::Milter::get_milter()
189+
190+
Returns the C<Sendmail::PMilter> instance underlying this emulation layer.
191+
This allows mostly-unmodified milter scripts to set PMilter extensions
192+
(such as dispatcher and sendmail.cf values). It is recommended, however,
193+
that new code use the object instance methods described in
194+
L<Sendmail::PMilter>.
195+
196+
=back
197+
198+
=head1 EXPORTS
199+
200+
In order to preserve compatibility with the standard C<Sendmail::Milter>
201+
interface, all SMFI* constants described in L<Sendmail::PMilter> are
202+
exported into the caller's namespace by default.
203+
204+
(Note that C<Sendmail::PMilter> itself does not export these symbols
205+
by default.)
206+
207+
=cut

0 commit comments

Comments
 (0)