[Mimedefang] MX -> 127.0.0.1

Les Mikesell les at futuresource.com
Mon Sep 12 18:19:39 EDT 2005


On Mon, 2005-09-12 at 16:45, Matthew.van.Eerde at hbinc.com wrote:

> One nitpick:
> 
>   #172.16/12
>   if ($ip =~ /^172\.16\./) { # not complete
>     #return 1;
>   }
> 
> True enough, but actually 172.16/12 includes 172.16-31...
> 
>   #172.16/12
>   if ($ip =~ /^172\.(16|17|18|19|2[0-9]|30|31)\./) { # messy?
>     #return 1;
>   }

Don't you really want to just reverse the logic in the
'trusted relay' function that someone posted ages ago?



# test for local origin so we can skip spam test
sub relayIsTrusted($) {
  my ($address) = @_;
  my $trustedRelay = 0;
  my %trustedSubnets = (
#   network           =>  netmask
    '127.0.0.1'       => '255.255.255.255',
    '10.0.0.0'        => '255.0.0.0'
  );

 my $addr = inet_aton $address;
  while (my ($networkString, $netmaskString) = each %trustedSubnets) {
    my $network = inet_aton $networkString;
    my $netmask = inet_aton $netmaskString;
    if (($addr & $netmask) eq $network) { $trustedRelay = 1; last; }
  }
  return $trustedRelay;
}

The names/comments don't make much sense, but the test for
whether an address is in the subnet should be the same.

-- 
   Les Mikesell
     les at futuresource.com





More information about the MIMEDefang mailing list