CfgTie/TieNamed.pm

filter: Statementstmt 78.1% 43 / 55 Branchbran 65.0% 13 / 20 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 75.0% 69 / 92 CC 14 SCAR 28.5
CC
14
Cov
74%
scan
24.3
BEGIN
1.0
BEGIN
1.0
CRAP 17.3
« CfgTie/TieShadow.pm ↑ Summary CfgTie/TieGroup.pm »
1 #!/usr/bin/perl -w
2 #Copyright 1998-2001, Randall Maas. All rights reserved. This program is free
3 #software; you can redistribute it and/or modify it under the same terms as
4 #PERL itself.
5  
6  
7 =head1 NAME
8  
9 C<CfgTie::TieNamed> -- A tool to help configure the name daemon (BIND DNS server)
10  
11 =head1 SYNOPSIS
12  
13 This is a PERL module to help make it easy to configure the DNS name server
14  
15 =head1 DESCRIPTION
16  
17 This is a tie hash to the NAMED configuration files. You use it as follows:
18  
19 tie %named, 'CfgTie::TieNamed','/path/to/named.boot';
20 $named = CfgTie::TieNamed->new('/path/to/named.boot');
21  
22 These will set up a hash (I<named>) to the named configuration files. It will
23 used the specified F<named.boot> file.
24  
25 tie %named, 'CfgTie::TieNamed';
26 $named = CfgTie::TieNamed->new();
27  
28 These will set up a hash (I<named>) to the named configuration files. The
29 files will be automatically determined from the system startup scripts.
30  
31 =head2 Examples
32  
33 Lets say you would like to name a bunch of machines (like modems) with a base
34 name and a number. The number part needs to be the same as the same as the
35 last number in the IP address. You know these go in a domain like,
36 "wikstrom.pilec.rm.net" which is a zone for your name server:
37  
38 tie %DNS, 'CfgTie::TieNamed';
39 my $Tbl = $DNS->{'primary'}->{'wikstrom.pilec.rm.net'};
40 my $N=10; #Ten modems;
41 my $prefix="usr2-port";
42 my $ip_start=11;
43 for (my $i = 0; $i < $N; $i++)
44 {
45 #Insert the address record in the table
46 $Tbl->{$prefix.$i}->{'A'} = "127.221.19.".($i+$ip_start);
47 }
48  
49 #Finally make sure that the reverse name space is up to date
50 (tied %DNS)->RevXRef('wikstrom.pilec.rm.net','19.221.127.in-addr.arpa');
51  
52  
53 Even the address to name mapping will be kept up to date.
54
55  
56 =head2 The basic structure of the named configuration table
57  
58 =over 1
59  
60 =item C<bogusns>
61  
62 A list of name server addresses to ignore.
63  
64 =item C<cache>
65  
66 See L<named(8)> for a description
67  
68 =item C<check-names>
69  
70 =item C<directory>
71  
72 This specifies the working directory of the F<named> server, and is used in
73 determining the location of the associated files.
74  
75 =item C<forwarders>
76  
77 A list of other servers' addresses on the site that can be used for recursive
78 look up.
79  
80 =item C<limit>
81  
82 Controls operational parameters of the F<named> server. See below.
83  
84 =item C<options>
85  
86 The list of options the F<named> server should adhere to.
87  
88 =item C<primary>
89  
90 This maps to a an associative array of name spaces we are primary for. See
91 below for more details on this is handled.
92  
93 =item C<secondary>
94  
95 This maps to a an associative array of name spaces we are secondary for.
96  
97 =item C<sortlist>
98  
99 See L<named(8)> for a description
100  
101 =item C<xfrnets>
102  
103 The list of networks which are allowed to request zone transfers. If not
104 present, all hosts on all networks are.
105  
106 =back
107  
108 Others may be set as well, but they are for backwards compatibility and should
109 be changed to the more appopriate form. See L<named(8)> for more information.
110  
111 =head2 Extra methods for the configuration table
112  
113 These are various methods you can use. Of course, you will need an object
114 reference you can use for the remaining methods. Note that if you tied the
115 variable, you will want to use code sorta like:
116 C<my $Obj = tied %CfgTie::TieNamed;>
117  
118 C<RevSpaces> Is the list of the reverses addresses spaces that the server is
119 primary for (except loopback)
120  
121 C<FwdSpaces> Is the list of name spaces the server is primary for (except the
122 loopback and reverse name spaces)
123  
124 C<RevXRef($>I<fwd>C<,$>I<rev>C<)> This will check that reverse look up is up
125 to date with the primary look up. It will add reverse entries as appropriate
126 (if there is one missing, or the value is correct). It will not change a
127 reverse entry if there are multiple names with the same address entry.
128 I<rev> is optional, but this method will return (with a 0) if it is not
129 specified and there is more than one reverse name space.
130 I<fwd> is optional, but this method will return (with a 0) if it is not
131 specified and there is more than one primary name space.
132 Returns the number of entries changed or added.
133  
134 I<Note:> This also derives any other methods from the C<CfgTie::Cfgfile> module
135 (L<CfgTie::Cfgfile>).
136  
137 =head2 The basic structure of a primary name space table
138  
139 The C<$named->E<gt>C<{primary}> entry refers to a associative arrays. The
140 keys are the domain names that are to be server. ie,
141  
142 my %mydom = $name->{primary}->{'mydomain.com'};
143  
144 These associations in turn refer to a table of names and their respective
145 attributes. The keys to this table are the machine names.
146  
147 The values associated keys are hash references to domain name records. This
148 in turn refers to another (confused yet?) associative array. The keys of
149 this table are the DNS attribute names. The values associated with the key
150 are list references, usually a set of possible values for the given attribute
151 and name pair. The most common ones are:
152  
153 =over 1
154  
155 =item C<A>
156  
157 This is a list reference to all of the physical addresses the given machine
158 name has.
159  
160 =item C<NS>
161  
162 This is a list reference to all of the servers that can serve as domain name
163 servers.
164  
165 =item C<CNAME>
166  
167 This is a list reference to all of the real names the given machine
168 name has.
169  
170 =item C<SOA>
171  
172 Has a list reference with the following structure
173 C<HOSTDATAFROM MAILADDR SERIAL REFRESH RETRY EXPIRE MinTTL>
174 The Serial number is automatically updated for each table that is changed.
175 The format is guessed (from various date formats include YYYYMMDD, YYYYDDD,
176 and others), and properly incremented or set.
177  
178 =item C<PTR>
179  
180 This is a list reference to the real name of a given machines address.
181  
182 =item C<TXT>
183  
184 Each element of this list refers to a string describing the domain or name.
185  
186 =item C<WKS>
187  
188 =item C<HINFO>
189  
190 =back
191  
192 =head2 Extra methods table
193  
194 C<DblLinks> This looks for entries with both a C<A> and a C<CNAME> entry.
195 I<Keep> controls whether to keep the C<A> or the C<CNAME> entry; the default
196 is to keep the C<A> entry (and delete the C<CNAME> entry). Returns a count
197 of all the records that were modified.
198  
199 I<Note:> This also derives any other methods from the C<CfgTie::Cfgfile> module
200 (L<CfgTie::Cfgfile>).
201  
202 =head1 See Also
203  
204 L<CfgTie::Cfgfile>,
205 L<CfgTie::TieAliases>, L<CfgTie::TieGeneric>, L<CfgTie::TieGroup>,
206 L<CfgTie::TieHost>, L<CfgTie::TieMTab>, L<CfgTie::TieNet>,
207 L<CfgTie::TiePh>,
208 L<CfgTie::TieProto>, L<CfgTie::TieRCService>, L<CfgTie::TieRsrc><
209 L<CfgTie::TieServ>,
210 L<CfgTie::TieShadow>, L<CfgTie::TieUser>
211  
212 =head1 Caveats
213  
214 Much of the information is cached and the file is updated at the end. The
215 C<named> process will sent the C<SIGHUP> signal to restart and reload the
216 configuration files.
217  
218 The reverse name file can not be automatically created... Only modified.
219  
220 The SOA records in the named configuration files are not easy to change.
221  
222 Changing the file name or directory currently does not move the files in the
223 file system
224  
225 =head1 Author
226  
227 Randall Maas (L<randym@acm.org>)
228  
229 =cut
230  
231 package CfgTie::TieNamed;
232 1 ▶use CfgTie::Cfgfile;
Subroutine BEGIN: called CC=1 SCAR=0.0
233 1 ▶use CfgTie::TieRCService;
Subroutine BEGIN: called CC=1 SCAR=0.0
234 1 ▶use CfgTie::filever;
Subroutine BEGIN: called CC=1 SCAR=0.0
235 1 ▶use Secure::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
236 1 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
237 1 ▶use AutoLoader 'AUTOLOAD';
Subroutine BEGIN: called CC=1 SCAR=0.0
238 1 @ISA=qw(AutoLoader CfgTie::Cfgfile);
239 1 $VERSION='0.41';
240 1 my %servs;
241 1 tie %servs, 'CfgTie::TieRCService';
242 1 my $serv = $servs{'named'};
243 1 1;
244  
245 __END__
« CfgTie/TieShadow.pm ↑ Summary CfgTie/TieGroup.pm »