head	1.4;
access;
symbols
	perseant-exfatfs-base-20250801:1.4
	perseant-exfatfs-base-20240630:1.4
	cjep_sun2x:1.4.0.44
	cjep_sun2x-base:1.4
	cjep_staticlib_x-base1:1.4
	cjep_staticlib_x:1.4.0.42
	cjep_staticlib_x-base:1.4
	phil-wifi-20200421:1.4
	phil-wifi-20200411:1.4
	phil-wifi-20200406:1.4
	pgoyette-compat-merge-20190127:1.4
	pgoyette-compat-20190127:1.4
	pgoyette-compat-20190118:1.4
	pgoyette-compat-1226:1.4
	pgoyette-compat-1126:1.4
	pgoyette-compat-1020:1.4
	pgoyette-compat-0930:1.4
	pgoyette-compat-0906:1.4
	pgoyette-compat-0728:1.4
	pgoyette-compat-0625:1.4
	pgoyette-compat-0521:1.4
	pgoyette-compat-0502:1.4
	pgoyette-compat-0422:1.4
	pgoyette-compat-0415:1.4
	pgoyette-compat-0407:1.4
	pgoyette-compat-0330:1.4
	pgoyette-compat-0322:1.4
	pgoyette-compat-0315:1.4
	pgoyette-compat:1.4.0.40
	pgoyette-compat-base:1.4
	perseant-stdc-iso10646:1.4.0.38
	perseant-stdc-iso10646-base:1.4
	prg-localcount2-base3:1.4
	prg-localcount2-base2:1.4
	prg-localcount2-base1:1.4
	prg-localcount2:1.4.0.36
	prg-localcount2-base:1.4
	pgoyette-localcount-20170426:1.4
	bouyer-socketcan-base1:1.4
	pgoyette-localcount-20170320:1.4
	bouyer-socketcan:1.4.0.34
	bouyer-socketcan-base:1.4
	pgoyette-localcount-20170107:1.4
	pgoyette-localcount-20161104:1.4
	localcount-20160914:1.4
	pgoyette-localcount-20160806:1.4
	pgoyette-localcount-20160726:1.4
	pgoyette-localcount:1.4.0.32
	pgoyette-localcount-base:1.4
	netbsd-5-2-3-RELEASE:1.4
	netbsd-5-1-5-RELEASE:1.4
	yamt-pagecache-base9:1.4
	yamt-pagecache-tag8:1.4
	tls-earlyentropy:1.4.0.28
	tls-earlyentropy-base:1.4
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.4
	riastradh-drm2-base3:1.4
	netbsd-5-2-2-RELEASE:1.4
	netbsd-5-1-4-RELEASE:1.4
	netbsd-5-2-1-RELEASE:1.4
	netbsd-5-1-3-RELEASE:1.4
	agc-symver:1.4.0.30
	agc-symver-base:1.4
	tls-maxphys-base:1.4
	yamt-pagecache-base8:1.4
	netbsd-5-2:1.4.0.26
	yamt-pagecache-base7:1.4
	netbsd-5-2-RELEASE:1.4
	netbsd-5-2-RC1:1.4
	yamt-pagecache-base6:1.4
	yamt-pagecache-base5:1.4
	yamt-pagecache-base4:1.4
	netbsd-5-1-2-RELEASE:1.4
	netbsd-5-1-1-RELEASE:1.4
	yamt-pagecache-base3:1.4
	yamt-pagecache-base2:1.4
	yamt-pagecache:1.4.0.24
	yamt-pagecache-base:1.4
	bouyer-quota2-nbase:1.4
	bouyer-quota2:1.4.0.22
	bouyer-quota2-base:1.4
	matt-nb5-pq3:1.4.0.20
	matt-nb5-pq3-base:1.4
	netbsd-5-1:1.4.0.18
	netbsd-5-1-RELEASE:1.4
	netbsd-5-1-RC4:1.4
	netbsd-5-1-RC3:1.4
	netbsd-5-1-RC2:1.4
	netbsd-5-1-RC1:1.4
	netbsd-5-0-2-RELEASE:1.4
	netbsd-5-0-1-RELEASE:1.4
	jym-xensuspend-nbase:1.4
	netbsd-5-0:1.4.0.16
	netbsd-5-0-RELEASE:1.4
	netbsd-5-0-RC4:1.4
	netbsd-5-0-RC3:1.4
	netbsd-5-0-RC2:1.4
	jym-xensuspend:1.4.0.14
	jym-xensuspend-base:1.4
	netbsd-5-0-RC1:1.4
	netbsd-5:1.4.0.12
	netbsd-5-base:1.4
	mjf-devfs2:1.4.0.10
	mjf-devfs2-base:1.4
	yamt-pf42-base4:1.4
	yamt-pf42-base3:1.4
	hpcarm-cleanup-nbase:1.4
	yamt-pf42-base2:1.4
	yamt-pf42:1.4.0.8
	yamt-pf42-base:1.4
	keiichi-mipv6:1.4.0.6
	keiichi-mipv6-base:1.4
	cube-autoconf:1.4.0.4
	cube-autoconf-base:1.4
	hpcarm-cleanup:1.4.0.2
	hpcarm-cleanup-base:1.4
	netbsd-3-1-1-RELEASE:1.3
	netbsd-3-0-3-RELEASE:1.3
	netbsd-3-1:1.3.0.6
	netbsd-3-1-RELEASE:1.3
	netbsd-3-0-2-RELEASE:1.3
	netbsd-3-1-RC4:1.3
	netbsd-3-1-RC3:1.3
	netbsd-3-1-RC2:1.3
	netbsd-3-1-RC1:1.3
	netbsd-3-0-1-RELEASE:1.3
	netbsd-3-0:1.3.0.4
	netbsd-3-0-RELEASE:1.3
	netbsd-3-0-RC6:1.3
	netbsd-3-0-RC5:1.3
	netbsd-3-0-RC4:1.3
	netbsd-3-0-RC3:1.3
	netbsd-3-0-RC2:1.3
	netbsd-3-0-RC1:1.3
	netbsd-2-0-3-RELEASE:1.2
	netbsd-2-1:1.2.0.6
	netbsd-2-1-RELEASE:1.2
	netbsd-2-1-RC6:1.2
	netbsd-2-1-RC5:1.2
	netbsd-2-1-RC4:1.2
	netbsd-2-1-RC3:1.2
	netbsd-2-1-RC2:1.2
	netbsd-2-1-RC1:1.2
	netbsd-2-0-2-RELEASE:1.2
	netbsd-3:1.3.0.2
	netbsd-3-base:1.3
	sendmail-8-13-3:1.1.1.3
	netbsd-2-0-1-RELEASE:1.2
	netbsd-2:1.2.0.4
	netbsd-2-base:1.2
	netbsd-2-0-RELEASE:1.2
	netbsd-2-0-RC5:1.2
	netbsd-2-0-RC4:1.2
	netbsd-2-0-RC3:1.2
	netbsd-2-0-RC2:1.2
	netbsd-2-0-RC1:1.2
	netbsd-2-0:1.2.0.2
	netbsd-2-0-base:1.2
	sendmail-8-12-11:1.1.1.2
	netbsd-1-6-PATCH002-RELEASE:1.1
	netbsd-1-6-PATCH002:1.1
	netbsd-1-6-PATCH002-RC4:1.1
	netbsd-1-6-PATCH002-RC3:1.1
	netbsd-1-6-PATCH002-RC2:1.1
	netbsd-1-6-PATCH002-RC1:1.1
	sendmail-8-12-9:1.1.1.2
	netbsd-1-6-PATCH001:1.1
	netbsd-1-6-PATCH001-RELEASE:1.1
	sendmail-8-12-8:1.1.1.2
	netbsd-1-6-PATCH001-RC3:1.1
	netbsd-1-6-PATCH001-RC2:1.1
	netbsd-1-6-PATCH001-RC1:1.1
	fvdl_fs64_base:1.1
	netbsd-1-6-RELEASE:1.1
	netbsd-1-6-RC3:1.1
	netbsd-1-6-RC2:1.1
	netbsd-1-6-RC1:1.1
	netbsd-1-6:1.1.1.1.0.4
	netbsd-1-6-base:1.1
	netbsd-1-5-PATCH003:1.1.1.1.2.2
	sendmail-8-11-6:1.1.1.1
	netbsd-1-5-PATCH002:1.1.1.1.2.2
	sendmail-8-11-5:1.1.1.1
	netbsd-1-5-PATCH001:1.1.1.1.2.2
	sendmail-8-11-4:1.1.1.1
	sendmail-8-11-3:1.1.1.1
	sendmail-8-11-2:1.1.1.1
	netbsd-1-5-RELEASE:1.1.1.1.2.2
	netbsd-1-5-BETA2:1.1.1.1.2.2
	netbsd-1-5-BETA:1.1.1.1.2.2
	sendmail-8-11-1:1.1.1.1
	netbsd-1-5:1.1.1.1.0.2
	sendmail-8-11-0:1.1.1.1
	SENDMAIL_INC:1.1.1;
locks; strict;
comment	@# @;


1.4
date	2006.05.30.00.42.34;	author christos;	state dead;
branches;
next	1.3;

1.3
date	2005.03.15.02.14.16;	author atatat;	state Exp;
branches;
next	1.2;

1.2
date	2003.03.24.15.03.44;	author atatat;	state Exp;
branches;
next	1.1;

1.1
date	2000.07.23.14.08.09;	author itojun;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2000.07.23.14.08.09;	author itojun;	state Exp;
branches
	1.1.1.1.2.1;
next	1.1.1.2;

1.1.1.2
date	2003.03.24.14.47.34;	author atatat;	state Exp;
branches;
next	1.1.1.3;

1.1.1.3
date	2005.03.15.02.06.03;	author atatat;	state Exp;
branches;
next	;

1.1.1.1.2.1
date	2000.07.23.14.08.09;	author itojun;	state dead;
branches;
next	1.1.1.1.2.2;

1.1.1.1.2.2
date	2000.08.13.16.49.10;	author itojun;	state Exp;
branches;
next	;


desc
@@


1.4
log
@Remove sendmail.
@
text
@#!/usr/bin/perl -w

# Id: cidrexpand,v 8.4 2002/11/22 21:13:14 ca Exp
# $NetBSD: cidrexpand,v 1.3 2005/03/15 02:14:16 atatat Exp $
#
# v 0.4
#
# 17 July 2000 Derek J. Balling (dredd@@megacity.org)
# 
# Acts as a preparser on /etc/mail/access_db to allow you to use address/bit
# notation. 
#
# If you have two overlapping CIDR blocks with conflicting actions
# e.g.   10.2.3.128/25 REJECT and 10.2.3.143 ACCEPT
# make sure that the exceptions to the more general block are specified
# later in the access_db.
#
# the -r flag to makemap will make it "do the right thing"
#
# Modifications
# -------------
# 26 Jul 2001 Derek Balling (dredd@@megacity.org)
#     Now uses Net::CIDR because it makes life a lot easier.
#
#  5 Nov 2002 Richard Rognlie (richard@@sendmail.com)
#     Added code to deal with the prefix tags that may now be included in
#     the access_db
#
#     Added clarification in the notes for what to do if you have 
#     exceptions to a larger CIDR block.
#
# usage: 
#  cidrexpand < /etc/mail/access | makemap -r hash /etc/mail/access
#
#
# Report bugs to: <dredd@@megacity.org>
#


use strict;
use Net::CIDR;

my $spaceregex = '\s+';

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

use strict;

my $SENDMAIL = 1;

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

    if (! /^(|\S\S*:)(\d+\.){3}\d+\/\d\d?$spaceregex.*/ )
    {
	print;
    }
    else
    {
	($prefix,$left,$space,$right) = /^(|\S\S*:)((?:\d+\.){3}\d+\/\d\d?)($spaceregex)(.*)$/;
	
	my @@new_lefts = expand_network($left);
	foreach my $nl (@@new_lefts)
	{
	    print "$prefix$nl$space$right\n";
	}
    }
}
    
sub expand_network
{
    my $left_input = shift;
    my @@rc = ($left_input);
    my ($network,$mask) = split /\//, $left_input;
    if (defined $mask)
    {
	my @@parts = split /\./, $network;
	while ($#parts < 3)
	{
	    push @@parts, "0";
	}
	my $clean_input = join '.', @@parts;
	$clean_input .= "/$mask";
	my @@octets = Net::CIDR::cidr2octets($clean_input);
	@@rc = @@octets;
    }
    return @@rc;
}
@


1.3
log
@resolve conflicts, pull 8.13.3 to head, make it build
@
text
@d4 1
a4 1
# $NetBSD$
@


1.2
log
@Pull sendmail 8.12.8 to the head, resolve the import conflicts, and
make it build.
@
text
@d1 1
a1 1
#!/usr/local/bin/perl -w
d3 4
a6 1
# v 0.2-very-beta
d9 1
a9 6
#
# 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...
#
d11 1
a11 2
# notation. Caveat: the address portion MUST be the start address or your
# results will NOT be what what you want.
d22 4
a25 1
#  5 Nov  2002 Richard Rognlie (richard@@sendmail.com)
d32 1
a32 1
# usage:
d35 2
a36 1
# Report bugs to: dredd@@megacity.org
d39 4
d47 2
a48 2
     if ($arg eq '-t')
     {
d50 1
a50 1
     }
d59 1
a59 1
     my ($prefix,$left,$right,$space);
d61 2
a62 2
     if (! /^(|\S\S*:)(\d+\.){3}\d+\/\d\d?$spaceregex.*/ )
     {
d64 3
a66 3
     }
     else
     {
d68 1
a68 1

d74 1
a74 2

     }
d79 7
a85 9
     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))
d87 1
a87 1
	    push @@rc, "$f";
d89 6
a94 72
	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;
     }
     elsif ($mask == 0)
     {
	$fourth = 255;
	$third = 255;
	$second = 255;
	$first = 255;
     }

     return ($first,$second,$third,$fourth);
@


1.1
log
@Initial revision
@
text
@d3 1
a3 1
# v 0.2-very-very-beta
d16 15
d33 1
a33 2
#  cidrexpand < /etc/mail/access | makemap hash /etc/mail/access
#
d54 1
a54 1
     my ($left,$right,$space);
d56 1
a56 1
     if (! /^(\d+\.){3}\d+\/\d\d?$spaceregex.*/ )
d62 1
a62 1
	($left,$space,$right) = /^((?:\d+\.){3}\d+\/\d\d?)($spaceregex)(.*)$/;
d67 1
a67 1
	    print "$nl$space$right\n";
d150 8
@


1.1.1.1
log
@sendmail 8.11.0
@
text
@@


1.1.1.1.2.1
log
@file cidrexpand was added on branch netbsd-1-5 on 2000-08-13 16:49:10 +0000
@
text
@d1 137
@


1.1.1.1.2.2
log
@pullup (approved by releng-1-5)

switch to sendmail 8.11.0.

see the following email for the list of files/tags:
http://mail-index.netbsd.org/source-changes/2000/07/23/0048.html
@
text
@a0 137
#!/usr/local/bin/perl -w

# v 0.2-very-very-beta
#
# 17 July 2000 Derek J. Balling (dredd@@megacity.org)
#
# 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@@megacity.org
#

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);
}
@


1.1.1.2
log
@sendmail 8.12.8
@
text
@d3 1
a3 1
# v 0.2-very-beta
a15 12
# If you have two overlapping CIDR blocks with conflicting actions
# e.g.   10.2.3.128/25 REJECT and 10.2.3.143 ACCEPT
# make sure that the exceptions to the more general block are specified
# later in the access_db.
#
# the -r flag to makemap will make it "do the right thing"
#
# Modifications
# -------------
#  5 Nov  2002 Richard Rognlie (richard@@sendmail.com)
#     Added code to deal with the prefix tags that may now be included in
#     the access_db
d17 2
a18 2
#     Added clarification in the notes for what to do if you have 
#     exceptions to a larger CIDR block.
a19 2
# usage:
#  cidrexpand < /etc/mail/access | makemap -r hash /etc/mail/access
d40 1
a40 1
     my ($prefix,$left,$right,$space);
d42 1
a42 1
     if (! /^(|\S\S*:)(\d+\.){3}\d+\/\d\d?$spaceregex.*/ )
d48 1
a48 1
	($prefix,$left,$space,$right) = /^(|\S\S*:)((?:\d+\.){3}\d+\/\d\d?)($spaceregex)(.*)$/;
d53 1
a53 1
	    print "$prefix$nl$space$right\n";
a135 8
     elsif ($mask == 0)
     {
	$fourth = 255;
	$third = 255;
	$second = 255;
	$first = 255;
     }

@


1.1.1.3
log
@sendmail 8.13.3
@
text
@d1 1
a1 1
#!/usr/bin/perl -w
d3 1
a3 2
# Id: cidrexpand,v 8.4 2002/11/22 21:13:14 ca Exp
# $NetBSD$
d5 6
a10 1
# v 0.4
a11 2
# 17 July 2000 Derek J. Balling (dredd@@megacity.org)
# 
d13 2
a14 1
# notation. 
d25 1
a25 4
# 26 Jul 2001 Derek Balling (dredd@@megacity.org)
#     Now uses Net::CIDR because it makes life a lot easier.
#
#  5 Nov 2002 Richard Rognlie (richard@@sendmail.com)
d32 1
a32 1
# usage: 
d35 1
a35 2
#
# Report bugs to: <dredd@@megacity.org>
a37 4

use strict;
use Net::CIDR;

d42 2
a43 2
    if ($arg eq '-t')
    {
d45 1
a45 1
    }
d54 1
a54 1
    my ($prefix,$left,$right,$space);
d56 2
a57 2
    if (! /^(|\S\S*:)(\d+\.){3}\d+\/\d\d?$spaceregex.*/ )
    {
d59 3
a61 3
    }
    else
    {
d63 1
a63 1
	
d69 2
a70 1
    }
d75 9
a83 7
    my $left_input = shift;
    my @@rc = ($left_input);
    my ($network,$mask) = split /\//, $left_input;
    if (defined $mask)
    {
	my @@parts = split /\./, $network;
	while ($#parts < 3)
d85 1
a85 1
	    push @@parts, "0";
d87 72
a158 6
	my $clean_input = join '.', @@parts;
	$clean_input .= "/$mask";
	my @@octets = Net::CIDR::cidr2octets($clean_input);
	@@rc = @@octets;
    }
    return @@rc;
@
