diff options
Diffstat (limited to '')
-rw-r--r-- | debian/postfix-add-filter | 126 | ||||
-rw-r--r-- | debian/postfix-add-filter.8 | 68 |
2 files changed, 194 insertions, 0 deletions
diff --git a/debian/postfix-add-filter b/debian/postfix-add-filter new file mode 100644 index 0000000..7b1ae27 --- /dev/null +++ b/debian/postfix-add-filter @@ -0,0 +1,126 @@ +#!/usr/bin/python3 +''' +postfix-add-filter - A script to append new services to Postfix master.cf to +simplify integration of content filters. + +Copyright (c) 2008 Scott Kitterman <scott@kitterman.com> +Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +''' +__author__ = "Scott Kitterman" +__email__ = "scott@kitterman.com" +__version__ = "0.11: August 2, 2008" + +import sys +import shutil +import os +import time + +def makeservice(name, port): + # Recommendations from amavisd-new 2.6.0 documentation plus chrooted to + # match Debian Postfix package defaults. + header = """# ========================================================================== +# service type private unpriv chroot wakeup maxproc command + args +# (yes) (yes) (yes) (never) (100) +# ========================================================================== +# Added using postfix-add-filter script: +""" + smtp = ("""%s unix - - - - 2 smtp + -o smtp_data_done_timeout=1200 + -o smtp_send_xforward_command=yes + -o smtp_tls_note_starttls_offer=no + +""" % (name)) + + smtpd = ("""127.0.0.1:%s inet n - - - - smtpd + -o content_filter= + -o smtpd_delay_reject=no + -o smtpd_client_restrictions=permit_mynetworks,reject + -o smtpd_helo_restrictions= + -o smtpd_sender_restrictions= + -o smtpd_recipient_restrictions=permit_mynetworks,reject + -o smtpd_data_restrictions=reject_unauth_pipelining + -o smtpd_end_of_data_restrictions= + -o smtpd_restriction_classes= + -o mynetworks=127.0.0.0/8 + -o smtpd_error_sleep_time=0 + -o smtpd_soft_error_limit=1001 + -o smtpd_hard_error_limit=1000 + -o smtpd_client_connection_count_limit=0 + -o smtpd_client_connection_rate_limit=0 + -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks,no_milters + -o local_header_rewrite_clients= + -o smtpd_milters= + -o local_recipient_maps= + -o relay_recipient_maps= +""" % (port)) + additions = header + smtp + smtpd + return (additions) + + +USAGE = """To add a new filter service to your master.cf: + % sudo postfix-add-filter {smtp client name} {smtpd service port} + +Example: + % sudo postfix-add-filter amavisfeed 10025 + +Adds the following to master.cf: +""" + makeservice('amavisfeed', '10025') + """ +To output this usage message: + % postfix-add-filter +""" + + +if __name__ == '__main__': + import sys + if len(sys.argv) < 3: + print(USAGE + "\n") + elif len(sys.argv) == 3: + servicename = sys.argv[1] + listenerport = sys.argv[2] + # Read in master.cf and check to make sure specified names aren't + # already used + masterfile = open('/etc/postfix/master.cf', mode='r') + master = masterfile.readlines() + masterfile.close() + bailout = False + for line in master: + if servicename in line or listenerport in line: + # Service name or listen port already used, print error and bail + print('Selected service name, %s, or smtpd port, %s, \ + already in master.cf. Master.cf not updated.\n' + % (servicename, listenerport)) + bailout = True + break + if not bailout: + # Make backup copy + backupname = '/etc/postfix/master.cf.' + str(int(time.time())) + shutil.copy2('/etc/postfix/master.cf', backupname) + # Make working copy + shutil.copy2('/etc/postfix/master.cf', \ + '/etc/postfix/master.cf.working') + # Add stuff in + stuff = makeservice(servicename, listenerport) + # Append stuff to the working copy: + newmaster = open('/etc/postfix/master.cf.working', mode='a') + newmaster.writelines(stuff) + newmaster.close() + # Put working copy in place. + shutil.move('/etc/postfix/master.cf.working', \ + '/etc/postfix/master.cf') + else: + print(USAGE + '\n') + diff --git a/debian/postfix-add-filter.8 b/debian/postfix-add-filter.8 new file mode 100644 index 0000000..ac20992 --- /dev/null +++ b/debian/postfix-add-filter.8 @@ -0,0 +1,68 @@ +.TH POSTFIX-ADD-FILTER 8 +.ad +.fi +.SH NAME +postfix-add-filter +\- +add filter service to Postfix master.cf +.SH "SYNOPSIS" +.na +.nf +\fBpostfix-add-filter\fR [\fIsmtp service name\fR...] [\fIsmtpd port\fR...] +.SH DESCRIPTION +.ad +.fi +The \fBpostfix-add-filter\fR(8) command adds an smtp service named +\fIsmtp service name\fR and and smtpd server listening on \fIsmtpd port\fR to +\/etc/postfix/master.cf to facilitate integration of SMTP filters such as +amavisd-new or clamsmtp. The configuration is based on the upstream +recommendations for amavisd-new 2.6.0. Adminstrators should verify it is +appropriate for their requirements. + +The original file is copied prior to modification and left in /etc/postfix to +make it possible to revert changes easily. + +Available in the Debian package for Postfix version 2.5.3 and later. + +.SH DIAGNOSTICS +.ad +.fi +If the given \fIsmtp service name\fR or \fIsmtpd port\fR already appear in the +master.cf, a message will be printed to standard out and master.cf will not be +modified. + +.SH "ENVIRONMENT" +.na +.nf +.ad +.fi +.IP \fBMAIL_CONFIG\fR +Directory with Postfix configuration files. + +The \fBpostfix-add-filter\fR(8) command should use this, but it currently +doesn't. It is hard coded to /etc/postfix. This should be changed. +.SH "CONFIGURATION PARAMETERS" +.na +.nf +.ad +.fi +None +.SH "FILES" +.na +.nf +/etc/postfix/master.cf +.SH "SEE ALSO" +.na +.nf +postconf(5), Postfix configuration +.SH "LICENSE" +.na +.nf +.ad +.fi +This software is licensed under the MIT open source license. +.SH "AUTHOR(S)" +.na +.nf +Scott Kitterman +<scott@kitterman.com> |