| 1 | # $Id: HeloRawLiteral.pm,v 1.4 2004/02/26 19:24:52 tvierling Exp $ | ||
| 2 | # | ||
| 3 | # Copyright (c) 2002-2004 Todd Vierling <tv@pobox.com> <tv@duh.org> | ||
| 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 Mail::Milter::Module::HeloRawLiteral; | ||
| 33 | |||
| 34 | use 5.006; | ||
| 35 | use base Exporter; | ||
| 36 | use base Mail::Milter::Object; | ||
| 37 | |||
| 38 | use strict; | ||
| 39 | use warnings; | ||
| 40 | |||
| 41 | use Sendmail::Milter 0.18; # get needed constants | ||
| 42 | |||
| 43 | our $VERSION = '0.03'; | ||
| 44 | |||
| 45 | =pod | ||
| 46 | |||
| 47 | =head1 NAME | ||
| 48 | |||
| 49 | Mail::Milter::Module::HeloRawLiteral - milter to check for an IP literal without brackets in HELO | ||
| 50 | |||
| 51 | =head1 SYNOPSIS | ||
| 52 | |||
| 53 | use Mail::Milter::Module::HeloRawLiteral; | ||
| 54 | |||
| 55 | my $milter = new Mail::Milter::Module::HeloRawLiteral(); | ||
| 56 | |||
| 57 | my $milter2 = &HeloRawLiteral; # convenience | ||
| 58 | |||
| 59 | =head1 DESCRIPTION | ||
| 60 | |||
| 61 | RFC2821:4.1.3 specifies that raw IP addresses may be used in HELO, but | ||
| 62 | only if they are enclosed in [square brackets]. Spam engines sometimes | ||
| 63 | forget the brackets, so this milter will catch them. | ||
| 64 | |||
| 65 | =cut | ||
| 66 | |||
| 67 | our @EXPORT = qw(&HeloRawLiteral); | ||
| 68 | |||
| 69 | sub HeloRawLiteral { | ||
| 70 | new Mail::Milter::Module::HeloRawLiteral(@_); | ||
| 71 | } | ||
| 72 | |||
| 73 | sub helo_callback { | ||
| 74 | shift; # $this | ||
| 75 | my $ctx = shift; | ||
| 76 | my $helo = shift; | ||
| 77 | |||
| 78 | if ($helo =~ /^([\d\.]+|[^\[].*:.*[^\]])$/) { | ||
| 79 | $ctx->setreply("554", "5.7.1", "HELO/EHLO $helo: command rejected: raw IP literal not in [square brackets], required by RFC2821:4.1.3"); | ||
| 80 | return SMFIS_REJECT; | ||
| 81 | } | ||
| 82 | |||
| 83 | SMFIS_ACCEPT; | ||
| 84 | } | ||
| 85 | |||
| 86 | 1; | ||
| 87 | __END__ |