1#!/usr/bin/perl
2#
3# Copyright (C) 2004, 2007, 2012  Internet Systems Consortium, Inc. ("ISC")
4# Copyright (C) 2000, 2001  Internet Software Consortium.
5#
6# Permission to use, copy, modify, and/or distribute this software for any
7# purpose with or without fee is hereby granted, provided that the above
8# copyright notice and this permission notice appear in all copies.
9#
10# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16# PERFORMANCE OF THIS SOFTWARE.
17
18# Id: setup.pl,v 1.6 2007/06/19 23:47:05 tbox Exp
19
20#
21# Set up test data for zone transfer quota tests.
22#
23use FileHandle;
24
25my $n_zones = 5;
26my $n_names = 1000;
27
28make_zones(2, undef);
29make_zones(3, "10.53.0.2");
30make_zones(4, "10.53.0.3");
31
32my $rootdelegations =
33    new FileHandle("ns1/root.db", "w") or die;
34
35print $rootdelegations <<END;
36\$TTL 300
37.                       IN SOA  gson.nominum.com. a.root.servers.nil. (
38					       2000042100      ; serial
39					       600             ; refresh
40					       600             ; retry
41					       1200            ; expire
42					       600             ; minimum
43                                )
44.                       NS      a.root-servers.nil.
45a.root-servers.nil.     A       10.53.0.1
46END
47
48for ($z = 0; $z < $n_zones; $z++) {
49	my $zn = sprintf("zone%06d.example", $z);
50	foreach $ns (qw(2 3 4)) {
51		print $rootdelegations "$zn.		NS	ns$ns.$zn.\n";
52		print $rootdelegations "ns$ns.$zn.	A	10.53.0.$ns\n";
53	}
54}
55close $rootdelegations;
56
57sub make_zones {
58	my ($nsno, $slaved_from) = @_;
59	my $namedconf = new FileHandle("ns$nsno/zones.conf", "w") or die;
60	for ($z = 0; $z < $n_zones; $z++) {
61		my $zn = sprintf("zone%06d.example", $z);
62		if (defined($slaved_from)) {
63			print $namedconf "zone \"$zn\" { type slave; " .
64			    "file \"$zn.bk\"; masters { $slaved_from; }; };\n";
65		} else {
66			print $namedconf "zone \"$zn\" { " .
67			    "type master; " .
68			    "allow-update { any; }; " .
69			    "file \"$zn.db\"; };\n";
70
71			my $fn = "ns$nsno/$zn.db";
72			my $f = new FileHandle($fn, "w") or die "open: $fn: $!";
73			print $f "\$TTL 300
74\@	IN SOA 	ns2.$zn. hostmaster 1 300 120 3600 86400
75@	NS	ns2.$zn.
76ns2.$zn.	A	10.53.0.2
77@	NS	ns3.$zn.
78ns3.$zn.	A	10.53.0.3
79@	NS	ns4.$zn.
80ns4.$zn.	A	10.53.0.4
81	MX	10 mail1.isp.example.
82	MX	20 mail2.isp.example.
83";
84			for ($i = 0; $i < $n_names; $i++) {
85			    print $f sprintf("name%06d", $i) .
86				"	A	10.0.0.1\n";
87		    }
88		    $f->close;
89		}
90	}
91}
92