John Peacock wrote:
            ( $host =~ m/([0-9]{1,3})(\.[0-9]{1,3}){3}/ ) #IP4 address
            or
            ( $host =~ m/.+[.].+/ ) # at least one dot

Doh! I thought this code looked familiar (and too simplistic). I just faked up an e-mail address and used Qpsmtpd::Address's canonify() to validate whether the $host is acceptable. New version attached...

John
#!/usr/bin/perl -w

=head1 NAME

check_helofqdn - Check a HELO message delivered from a connecting host.

=head1 DESCRIPTION

Check a HELO message delivered from a connecting host.  Reject any
that are not a Fully Qualified Host Name, per RFC-2821 Section 3.6.

=head1 CONFIGURATION

None

=cut

use Qpsmtpd::Address;

sub hook_helo {
  my ($self, $transaction, $host) = @_;

  # fake up an e-mail address to use the logic in Q::A::canonify
  my($localpart, $domainpart) = Qpsmtpd::Address->canonify("<[EMAIL 
PROTECTED]>");

  # must have at least one dot
  unless ( defined $domainpart && $domainpart =~ /\./ ) {
      $self->log(LOGDEBUG, "$host violates RFC-2821 Section 3.6 FQDN");
      return (DENY, "HELO/EHLO require valid hostname (#5.7.1)");
  }
  return DECLINED;
}

# also support EHLO
*hook_ehlo = \&hook_helo;

Reply via email to