Re: [Exim] Relay problems

Góra strony
Delete this message
Reply to this message
Autor: Suresh Ramasubramanian
Data:  
Dla: Michael Shanks
CC: exim-users
Temat: Re: [Exim] Relay problems
* Michael Shanks <06/06/01 12:45 +0100>:

> Sorry could you clairfy that a bit more, is it the 216.171.74.116/140
> section that is wrong?


Yes.

> I assumed that this is meant to allow relaying from ips 216.171.74.116 -
> 216.171.74.140 inclusice


That is not the way it works. Please search for CIDR on google - you'll get
an idea :) (for example, 192.168.1.0/24 is not 192.168.1.0 to 192.168.1.24
- it is the entire class C - 192.168.1.0 to 192.168.1.255

The attached script in the sendmail source (in their contribs directory)
should help you in this case ... it's called cidrexpand.

     -suresh


--
Suresh Ramasubramanian <--> mallet <at> efn <dot> org
EMail Sturmbannfuhrer, Lower Middle Class Unix Sysadmin

#!/usr/local/bin/perl -w

# v 0.2-very-very-beta
#
# 17 July 2000 Derek J. Balling (dredd@???)
#
# The $SENDMAIL flag tells the code to lump networks in sendmail format
# if applicable. If this flag is disabled, cidrexpand will literally create
# a single line for each entry, which may or may not be what you want. :)
# makes for a rather large hash table...
#
# Acts as a preparser on /etc/mail/access_db to allow you to use address/bit
# notation. Caveat: the address portion MUST be the start address or your
# results will NOT be what what you want.
#
#
# usage:
# cidrexpand < /etc/mail/access | makemap hash /etc/mail/access
#
#
# Report bugs to: dredd@???
#

my $spaceregex = '\s+';

while (my $arg = shift @ARGV)
{
     if ($arg eq '-t')
     {
    $spaceregex = shift;
     }
}


use strict;

my $SENDMAIL = 1;

while (<>)
{
     my ($left,$right,$space);


     if (! /^(\d+\.){3}\d+\/\d\d?$spaceregex.*/ )
     {
    print;
     }
     else
     {
    ($left,$space,$right) = /^((?:\d+\.){3}\d+\/\d\d?)($spaceregex)(.*)$/;


    my @new_lefts = expand_network($left);
    foreach my $nl (@new_lefts)
    {
        print "$nl$space$right\n";
    }


     }
}


sub expand_network
{
     my ($network,$mask) = split /\//, shift;
     my @diffs = calc_changes($network,$mask);
     my ($first,$second,$third,$fourth) = split /\./, $network;


     my @rc = ();


     for my $f ($first..($first+$diffs[0]))
     {
    if ( ( $SENDMAIL ) and ($diffs[1] == 255))
    {
        push @rc, "$f";
    }
    else
    {
        for my $s ($second..($second+$diffs[1]))
        {
        if ( ($SENDMAIL) and ($diffs[2] == 255) )
        {
            push @rc,"$f\.$s";
        }
        else
        {
            for my $t ($third..($third+$diffs[2]))
            {
            if ( ($SENDMAIL) and ($diffs[3] == 255))
            {
                push @rc, "$f\.$s\.$t";
            }
            else
            {
                for my $fr ($fourth..($fourth+$diffs[3]))
                {
                push @rc, "$f\.$s\.$t\.$fr";
                }
            }
            }
        }
        }
    }
     }
     return @rc;
}


sub calc_changes
{
     my ($network,$mask) = @_;


     my @octs = split /\./, $network;


     my ($first,$second,$third,$fourth) = (0,0,0,0);


     my $power = 32 - $mask;


     if ($mask > 24)
     {
    $fourth = 2**$power - 1;
     }
     elsif ($mask > 16)
     {
    $fourth = 255;
    $third = 2**($power-8) - 1;
     }
     elsif ($mask > 8)
     {
    $fourth = 255;
    $third  = 255;
    $second = 2**($power-16) - 1;
     }
     elsif ($mask > 0)
     {
    $fourth = 255;
    $third = 255;
    $second = 255;
    $first = 2**($power-24) - 1;
     }
     return ($first,$second,$third,$fourth);
}