milter-ahead/1.13
|
text!/path/map.txt | R/O text file, memory hash |
/path/map.db | Berkeley DB hash format |
db!/path/map.db | Berkeley DB hash format |
db!btree!/path/map.db | Berkeley DB btree format |
sql!/path/database | An SQLite3 database |
socketmap!host:port | Sendmail style socket-map |
socketmap!/path/local/socket | Sendmail style socket-map |
socketmap!123.45.67.89:port | Sendmail style socket-map |
socketmap![2001:0DB8::1234]:port | Sendmail style socket-map |
If :port is omitted, the default is 7953.
The access-db contains key-value pairs. Lookups are performed from most to least specific, stopping on the first entry found. Keys are case-insensitive.
There are essentially three types of keys used in the access-db. Many of the tags available will use one or more of these lookup sequences.
IPv6 Lookup | IPv4 Lookup | |
---|---|---|
tag:2001:0DB8:0:0:0:0:1234:5678 | tag:192.0.2.9 | |
tag:2001:0DB8:0:0:0:0:1234 | tag:192.0.2 | |
tag:2001:0DB8:0:0:0:0 | tag:192.0 | |
tag:2001:0DB8:0:0:0 | tag:192 | |
tag:2001:0DB8:0:0 | ||
tag:2001:0DB8:0 | ||
tag:2001:0DB8 | ||
tag:2001 |
Note that the compact form of an IPv6 address, "2001:0DB8::1234:5678
", cannot be used.
Only the full IPv6 address format, with all intervening zeros, is currently supported.
tag:[ipv6:2001:0DB8::1234:5678] | |
tag:[192.0.2.9] | |
tag:sub.domain.tld | |
tag:domain.tld | |
tag:tld | |
tag: |
Note that the bare tag is often used to specify system wide defaults.
tag:account@sub.domain.tld | |
tag:sub.domain.tld | |
tag:domain.tld | |
tag:tld | |
tag:account@ | |
tag: |
Note that the bare tag is often used to specify system wide defaults.
The following list outlines the available tags and their supported key lookups:
{auth_authen}
.
The string searched by the pattern list will be the sender's mail address.
The empty form of milter-ahead-Auth: allows for a
milter specific default only when {auth_authen}
is defined.
When a key lookup matches, then the value returned is a pattern list, which in
its simplest and most common form is either an action word like
OK
, REJECT
, etc.;
a numerical value; or some arbitrary string depending on the tag involved. For example:
Connect:192.168.0 OK Rate-Connect:fsl.com 17 Msg-Limit-From:hotmail.com 150/30m
The action words supported by milter-ahead are:
OK White list, by-pass one or more tests. REJECT Black list, reject connection, sender, recipient, etc. SKIP Stop lookup and return no result ie. continue testing. DUNNO Same as SKIP, commonly used by postfix.
In most instances, the above forms of key lookup and values are sufficient. However, there may be times when finer granularity of control is required, in which case pattern lists can be used. A pattern list is a white space separated list of pattern-action pairs followed by an optional default action. The supported types are:
[network/cidr]action Classless Inter-Domain Routing
(only with IP address lookups)!pattern!action Simple fast text matching. /regex/action POSIX Extended Regular Expressions.
The simple pattern matching, !pattern!, uses an asterisk (*) for a wildcard, scanning over zero or more characters; a question-mark (?) matches any single character; a backslash followed by any character treats that character as a literal. This method always tries to match the beginning and end of string. For example:
!abc! exact match for 'abc' !abc*! match 'abc' at start of string !*abc! match 'abc' at the end of string !abc*def! match 'abc' at the start and match 'def' at the end, maybe with stuff in between. !*abc*def*! find 'abc', then find 'def'
The following is an example using a simple pattern to reject client connections that originate from a range of IP addresses of an ISP assigned to ADSL customers. Using a pattern like this allows you to drop connects from the ISP's ADSL, while still accepting connections from mail and web servers.
Connect:hananet.net !adsl-*-*.usr.hananet.net!REJECT
If you know that an ISP's mail and web servers follow a standard naming convention, you might prefer to only accept mail from those instead. We include web servers here to handle the case where a web server might have to send a mail response based on a form being filled in.
Connect:hananet.net !smtp*.hananet.net!OK !www*.hananet.net!OK REJECT
Note that SPF was designed to help mail servers identify originators of mail, so creating patterns as shown in the above two examples is not normally required. However, SPF is still considered experimental and not as widely deployed as one might hope.
The next example, /regex/, uses Extended Regular Expressions to validate the
format of the local-part of an AOL address, which must be between 3 and 16
characters long, can contain dots and RFC 2822 ``atext'' characters except %
and /
.
The SKIP word allows the one regular expression to validate the format of the address and continue if the
pattern matches; otherwise if the regular expression failed to match, REJECT the suspect aol.com address.
From:grandma@aol.com OK
From:aol.com /^[a-zA-Z0-9!#$&'*+=?^_`{|}~.-]{3,16}@aol.com$/SKIP REJECT
The discussion of Extended Regular Expressions is vast and complex, well beyond the scope of this document. There are many on-line tutorials and references available and the book Mastering Regular Expressions, 3e from O'Reilly covers the topic in depth.
If you need to use a pattern list, then try and follow these suggestions:
The milter-ahead-Connect:, milter-ahead-From:, and milter-ahead-To: tags provide a milter specific means to override the Sendmail and Postfix variants. For example, you normally white list your local network through any and all milters, but on the odd occasion you might want to actually scan mail from inside going out, without removing the Connect: tag that allows Sendmail or Postfix to relay for your network or white listing for other milters. So for example if you have tags like:
To:mx.example.com RELAY
You might have to add milter specific overrides in order to make sure the mail still gets filtered:
To:mx.example.com RELAY milter-ahead-To:mx.example.com SKIP
Some additional examples:
milter-ahead-Connect:80.94 [80.94.96.0/20]OK REJECT Accept connections from the netblock 80.94.96.0/20 (80.94.96.0 through to 80.94.111.255) and rejecting anything else in 80.94.0.0/16. milter-ahead-Connect:192.0.2 /^192\.0\.2\.8[0-9]/OK REJECT Accept connections from 192.0.2.80 through to 192.0.2.89, reject everything else in 192.0.2.0/24. milter-ahead-From:example.com /^john@.+/OK /^fred\+.*@.*/OK REJECT Accept mail from <john@example.com> and <fred@example.com> when fred's address contains a plus-detail in the address. Reject everything else from example.com. milter-ahead-To:example.net !*+*@*!REJECT !*.smith@*!REJECT /^[0-9].*/REJECT Reject mail to example.net using a plus-detail address or to any user who's last name is "smith" or addresses starting with a digit. No default given, so it is assumed to be SKIP..
bdb
,
flatfile
, hash
.
text!/path/map.txt R/O text file, memory hash /path/map.db Berkeley DB hash format db!/path/map.db Berkeley DB hash format db!btree!/path/map.db Berkeley DB btree format sql!/path/database An SQLite3 database socketmap!host:port Sendmail style socket-map socketmap!/path/local/socket Sendmail style socket-map socketmap!123.45.67.89:port Sendmail style socket-map socketmap![2001:0DB8::1234]:port Sendmail style socket-map
The recipient's domain is first used as the lookup key followed by each parent domain component that makes up the domain name. If no key is found, then the value of {rcpt_host} will be used.
When a key is found, then the value returned must be the name or IP
of the mail server to consult surrounded by square brackets. An optional :port
specifier may follow the closing square bracket. To consult the MX of another
domain specify the other domain name to lookup. This only works when
mx-lookup is enabled. Note that :port
cannot be used in this case, because using an MX implies SMTP port 25.
Below is an example of what the database file might look like with using IPv4, IPv6, hostname, and MX of domain values:
snert.biz [192.0.2.7] snert.com [192.0.2.7]:1234 snert.eu [2001:0DB8::beef] snert.fr [2001:0DB8::beef]:1234 snert.info [pop.snert.example] mx.snert.net [smtp.snert.example]:1234 snert.net snert.org
all all reserved IP address 0 accept all. benchmark 198.18.0.0/15 RFC 2544 link-local 169.254.0.0/16, FE80::/10 RFC 3330, 3513 localhost 127.0.0.1, ::1 RFC 3330, 3513 loopback 127.0.0.0/8 excluding 127.0.0.1 multicast 224.0.0.0/4, FF00::/8 RFC 3330, 3513 private-a 10.0.0.0/8 RFC 3330 private-b 172.16.0.0/12 RFC 3330 private-c 192.168.0.0/16 RFC 3330 reserved IPv6 unassigned prefixes RFC 3513 site-local FEC0::/10 RFC 3513 test-net 192.0.2.0/24, 2001:DB8::/32 RFC 3513, 3849 this-net 0.0.0.0/8, ::0 RFC 3330, 3513
milter-ahead
.
Typically a unix named socket or a host:port. This value must match the value specified for
the INPUT_MAIL_FILTER() macro in the sendmail.mc file. The accepted syntax is:
{unix|local}:/path/to/file
- A named pipe. (default)
inet:port@{hostname|ip-address}
- An IPV4 socket.
inet6:port@{hostname|ip-address}
- An IPV6 socket.
Spammers often attempt to by-pass spam filters by sending email directly to secondary MX machines, which often have weaker requirements. This option essentially demands that a client only deliver to the primary MX when it is available.
kill -QUIT `cat /var/run/milter/milter-ahead.pid`
§ all All messages § 0 Log nothing. § info General info messages. (default) § trace Trace progress through the milter. § parse Details from parsing addresses or special strings. debug Lots of debug messages. § dialog I/O from Communications dialog state State transitions of message body scanner. § dns Trace & debug of DNS operations § cache Cache get/put/gc operations. § database Sendmail database lookups. § socket-fd Socket open & close calls § socket-all All socket operations & I/O § libmilter libmilter engine diagnostics
This is the list of possible SMTP responses generated by milter-ahead
.
Download:
milter-ahead/1.13 md5sum Change Log LibSnert md5sum Change Log Sendmail 8.14 http://www.sendmail.org/ Berkeley DB http://www.sleepycat.com/
If you have never built a milter for Sendmail, then please make sure that you
build and install libmilter
, which is not built by default when you build Sendmail.
Please read the libmilter
documentation. Briefly, it should be something like this:
cd (path to)/sendmail-8.14.0/libmilter sh Build -c install
The build process for libsnert
and milter-ahead
is pretty straight forward
once you have libmilter
installed:
cd (path to)/com/snert/src/lib ./configure make build cd ../milter-ahead ./configure make build make install
Both configuration scripts have some options that allow you to override defaults. Those options are listed with:
./configure --help
An example /usr/local/share/examples/milter-ahead/milter-ahead.mc
is supplied.
This file should be reviewed and the necessary elements inserted into your Sendmail
.mc
file and sendmail.cf
rebuilt.
Please note the comments on the general milter flags.
Once installed and configured, start milter-ahead
and then restart Sendmail.
An example startup script is provided in /usr/local/share/examples/milter-ahead/milter-ahead.sh
.
The default options can be altered by specifying them on the command-line or
within a /etc/mail/milter-ahead.cf
. The milter-ahead.cf
is
parsed first followed by the command-line options.
Currently tested platforms:
Cobalt Qube 1 with Linux RH 5.1 (mips 2.0.34 kernel)
;Linux RH 5.1 (Intel x386 2.2.25 kernel)
;FreeBSD 4.8, 4.9 (Intel x386)
;OpenBSD 3.6 (Intel x386)
The minimum desired file ownership and permissions are as follows for a typical Linux system. For FreeBSD, NetBSD, and OpenBSD the binary and cache locations may differ, but have the same permissions.
Process user ``milter'' is primary member of group ``milter'' and secondary member of group ``smmsp''. Note that the milter should be started as root, so that it can create a .pid file and .socket file in /var/run; after which it will switch process ownership to milter:milter before starting the accept socket thread.
/etc/mail/ root:smmsp 0750 drwxr-x--- /etc/mail/access.db root:smmsp 0640 -rw-r----- /etc/mail/sendmail.cf root:smmsp 0640 -rw-r----- /etc/mail/milter-ahead.cf root:root 0644 -rw-r--r-- /var/run/milter/milter-ahead.pid milter:milter 0644 -rw-r--r-- /var/run/milter/milter-ahead.socket milter:milter 0644 srw-r--r-- /var/db/milter-ahead milter:milter 0644 -rw-r--r-- (*BSD) /var/cache/milter-ahead milter:milter 0644 -rw-r--r-- (linux) /usr/local/libexec/milter-ahead root:milter 0550 -r-xr-x---
We would like to express our thanks to Derek Balling for his support at http://www.milter.org/ and to April Lorenzen for her poking and proding to create this milter.
SNERTSOFT & CO. ARE WILLING TO LICENSE THE SOFTWARE IDENTIFIED ABOVE TO YOU ONLY UPON THE CONDITION THAT YOU ACCEPT ALL OF THE TERMS CONTAINED IN THIS LICENSE AGREEMENT. PLEASE READ THE AGREEMENT CAREFULLY. BY DOWNLOADING OR INSTALLING THIS SOFTWARE, YOU ACCEPT THE TERMS OF THE AGREEMENT.
``Package'' means the identified above in source and/or binary form, any other machine readable materials provided (including, but not limited to documentation, sample files, data files), any updates or error corrections, and its derivative works.
``Organisation'' means a legal entity or an individual.
``You'' (or ``Your'') means an Organisation exercising rights under, and complying with all of the terms of, this License or a future version of this License issued under Section 6.1. For legal entities, ``You'' includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition,``control'' means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
``SnertSoft'' means Anthony C. Howe situated in Cannes, France (SIRET #489 259 937 00014).
``SnertSoft & Co.'' means SnertSoft and all authorised & licensed partners, such as value-added resellers or appliance manufacturers.
The Package is an original work written by SnertSoft, with exception of following third party code:
MD5 routines written by L. Peter Deutsch, based on RFC 1321;
SQLite3 package is written by D. Richard Hipp of Hwaci and is in the public domain.
strnatcmp.c is written by Martin Pool of sourcefrog.net and has a BSD style license.
Protothreads headers originally written by Adam Dunkels and has a BSD style license.
You may install and use this Package, without modifications, exclusively on machines for which You have purchased a license, provided You retain this notice, SnertSoft's copyright notice, any and all license control methods (see below), and any links within the Package back to the most current online versions of this License and Disclaimer.
You may copy, share, distribute, modify, and create derivative works from the user manuals and any related documentation solely for Your internal business purposes, such as in-house documentation, training manuals, or reference material.
Redistribution, including but not limited to books, CDROMS, download mirrors, floppy diskettes, hard disks, hardcopy print outs, online archives, solid state disks, streaming tapes, or other current or future forms of storage or communication media of the Package, with or without modifications, including any and all derivative works such as source patches, binaries, binary patches, or similar is expressly forbidden without prior written permission in hardcopy (ie. letter or fax) signed and dated by SnertSoft.
It is expressly forbidden for You to use the Package, in whole or in part, in any other software or appliance without prior written permission in hardcopy (ie. letter or fax) signed and dated by SnertSoft.
It is expressly forbidden for You to use the Package to develop any software or other technology having the same primary function as the Package, including but not limited to using the Package in any development or test procedure that seeks to develop like software or other technology, or determine if such software or other technology performs in a similar manner as the Package.
You may not sell, rent, lease, or transfer the Package to third parties without prior written permission in hardcopy (ie. letter or fax) signed and dated by SnertSoft.
This Agreement is effective until terminated. You may terminate this Agreement at any time by destroying all copies of the Package.
This Agreement will terminate immediately without notice from SnertSoft if You fail to comply with any provision of this Agreement.
Either party may terminate this Agreement immediately should any portion of the Package become, or in either party's opinion be likely to become, the subject of a claim of infringement of any intellectual property right. Upon Termination, You must destroy all copies of the Package.
New Versions. SnertSoft may publish revised and/or new versions of the License from time to time. Each version will be given a distinguishing version number.
Effect of New Versions. Once a version of the Package has been published under a particular version of the License, You may always continue to use it under the terms of that License version. You may also choose to use such Package under the terms of the most current version of the License published by SnertSoft.
No one other than SnertSoft has the right to modify the terms applicable to the Package created under this License.
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO WAY SHALL SNERTSOFT OR LICENSEE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The Package may use one or more license control methods including, but not limited to, license key activation, periodic reporting of Package details and IP address of installation to SnertSoft & Co., or remote license verification by SnertSoft & Co.. Any information reported to or gathered by SnertSoft & Co. shall remain strictly confidential and the private property of SnertSoft & Co.. Under no circumstances will SnertSoft & Co. resell or release this information to third parties, unless demanded by court order.
Support is provided for one year from date of purchase and only for SnertSoft's original Package that was purchased directly from SnertSoft. Additional support beyond the first year can be obtained from SnertSoft on time & materials basis or from one of SnertSoft's authorised partners.
Support for the Package obtained from authorised partners, such as value-added resllers or appliance manufacturers, will be supplied by those partners. SnertSoft will not support the Package without proof of purchase from SnertSoft, such as an Order N° or Invoice N°.
Package enhancements requests and product suggestions are always welcome. A community mailing list is available; please refer to SnertSoft web site Support area for details.
Gifts from the author's Amazon US or Amazon UK wishlist (search by mail address <achowe at snert dot com>) are welcomed for the continued encouragement, moral support, and ego pumping needed to work in foreign non-english speaking lands.
pretzels since 24 January 2004