| 1 | # $Id: HeloUnqualified.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::HeloUnqualified; | ||
| 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::HeloUnqualified - milter to check for an unqualified HELO name | ||
| 50 | |||
| 51 | =head1 SYNOPSIS | ||
| 52 | |||
| 53 | use Mail::Milter::Module::HeloUnqualified; | ||
| 54 | |||
| 55 | my $milter = new Mail::Milter::Module::HeloUnqualified([EXCEPT]); | ||
| 56 | |||
| 57 | my $milter2 = &HeloUnqualified([EXCEPT]); # convenience | ||
| 58 | |||
| 59 | =head1 DESCRIPTION | ||
| 60 | |||
| 61 | This milter module rejects any domain name that HELOs without a dot, and | ||
| 62 | which is not an IPv4/IPv6 literal. Whether or not the HELO value | ||
| 63 | corresponds to the connecting host is not checked by this module. | ||
| 64 | |||
| 65 | If the EXCEPT argument is supplied, it should be a regex enclosed in a | ||
| 66 | string which will be exempted from this check. Commonly, '^localhost' is | ||
| 67 | excepted. | ||
| 68 | |||
| 69 | =cut | ||
| 70 | |||
| 71 | our @EXPORT = qw(&HeloUnqualified); | ||
| 72 | |||
| 73 | sub HeloUnqualified { | ||
| 74 | new Mail::Milter::Module::HeloUnqualified(@_); | ||
| 75 | } | ||
| 76 | |||
| 77 | sub new ($;$) { | ||
| 78 | my $this = Mail::Milter::Object::new(shift); | ||
| 79 | my $except = shift; | ||
| 80 | |||
| 81 | $this->{_except} = qr/$except/i if defined($except); | ||
| 82 | |||
| 83 | $this; | ||
| 84 | } | ||
| 85 | |||
| 86 | sub helo_callback { | ||
| 87 | my $this = shift; | ||
| 88 | my $ctx = shift; | ||
| 89 | my $helo = shift; | ||
| 90 | |||
| 91 | if (($helo !~ /\./) && ($helo !~ /^\[.*\]$/) && | ||
| 92 | !(defined($this->{_except}) && $helo =~ $this->{_except})) { | ||
| 93 | $ctx->setreply("554", "5.7.1", "HELO/EHLO $helo: command rejected: domain name not qualified"); | ||
| 94 | return SMFIS_REJECT; | ||
| 95 | } | ||
| 96 | |||
| 97 | SMFIS_ACCEPT; | ||
| 98 | } | ||
| 99 | |||
| 100 | 1; | ||
| 101 | __END__ |