|
NAMENet::DNS::Zone::Parser - A Zone Pre-ParserSYNOPSIS"use Net::DNS::Zone::Parser;"DESCRIPTIONThe Net::DNS::Zone::Parser should be considered a preprocessor that "normalizes" a zonefile.It will read a zonefile in a format conforming to the relevant RFCs with the addition of BIND's GENERATE directive from disk and will write fully specified resource records (RRs) to a filehandle. Whereby:
Note that this module does not have a notion of what constitutes a valid zone; it only parses. For example, the parser will happilly parse RRs with ownernames that are below in another zone because a NS RR elsewhere in the zone. METHODSnewmy $parser=Net::DNS::Zone::Parser->new($io); Creates the a parser instance. The optional argument should be a IO::File or IO::Handle type of object. If not specified a temporary IO::File type object will be created to which the lines will be printed. This object can be obtained using the get_io method get_iomy $io=$parser->get_io; $io->seek(0,0); print while (< $io >); Returns the filehandle to which the zone file has been written. This is either the filehandle specified as argument to the new() method or one that points to a temporary file. readmy $parser=Net::DNS::Zone::Parser->new; $parser->read("/tmp/example.foo"); $parser->read("/tmp/foo.db", { ORIGIN => "example.db", }; # alternatively $returnval=$parser->read("/tmp/foo.db", { ORIGIN => "example.db", CREATE_RR => 1, STRIP_SEC => 1, }; if ($returnval) { die $returnval; }else{ $RRarrayref=$parser->get_array(); } 'read' reads a zonefile from disk to 'pre-processes' it. The first argument is a path to the zonefile. The second parameter is a hash with optional arguments to tweak the reading. The read method returns 0 on success and a string starting with "READ FAILURE:" and a description on why the error occurred, on error. The zone file is written (streamed) to a filehandle, also see the get_io method. The HASH may contain 1 or more of the following arguments.
get_arrayReturns a reference to the array that is created if CREATE_RR is set to true during the read method.get_originmy $origin=$parser->get_origin; Returns the origin of the zone that was parsed. FunctionsprocessGENERATEarguse Net::DNS::Zone::Parser (processGENERATEarg) $generated=processGENERATEarg(0.0.${1,3},5,"inaddr.arpa." This exported function parses the "LHS" and "RHS" from a BIND generate directive. The first argument contains the "LHS" or "RHS", the second argument the iterator vallue and the last argument contains the value of the "origin" that is to be added if the result of the generate is not a FQDN (it is the vallue that is stupidly appended if the synthesized name does not end with a "."). From the BIND documentation: lhs describes the owner name of the resource records to be created. Any single $ symbols within the lhs side are replaced by the iterator value. To get a $ in the output you need to escape the $ using a backslash \, e.g. \$. The $ may optionally be followed by modifiers which change the offset from the iterator, field width and base. Modifiers are introduced by a { immediately following the $ as ${offset[,width[,base]]}. e.g. ${-20,3,d} which subtracts 20 from the current value, prints the result as a decimal in a zero padded field of with 3. Available output forms are decimal (d), octal (o) and hexadecimal (x or X for uppercase). The default modifier is ${0,0,d}. If the lhs is not absolute, the current $ORIGIN is appended to the name. Supported DIRECTIVEsINCLUDE$INCLUDE <path> [<origin>]will read the file as specified by 'path'. If 'path' is absolute it will be interpreted as such. If it is relative it will be taken relative to the path of the zonefile that includes it. Optionally $INCLUDE will take a 2nd argument that sets the current origin for relative domains. The parser only accept IN class zone files. TTLSpecifying the default TTLORIGINSpecifying the origin used to complete non fully qualified domain names.GENERATESee the BIND documentation.Related packages.There are other packages with likewise functionality; they where not suitable for my purposes. But maybe they are suitable for you. So before you start using this module you may want to look at these.DNS::Zone::File will parse a zonefile but will not expand domain names that are not fully qualified since it has no logic to interpret the RDATA of each individual RR. You can use this module to pre-process the file and then feed it to DNS::Zone::File (Default) to create a DNS::Zone instance. DNS::ZoneFile has almost the same functionality as this code it the canonicalises RR records it is aware off. It also has an INCLUDE function. Being an abstraction of a zonefile it has an interface to add and delete RRs from the zonefile and print it. The code does not support a GENERATE feature. Net::DNS::ZoneFile also almost has the same functionality, it supports the GENERATE, INCLUDE and ORIGIN primitives. It also supports more classes than just the IN class. However, this module first loads the complete zone in memory; which may be problematic for very large zones. It only seems to support a subset of the available RR types. All of these classes are abstractions of zonefiles, not of zones i.e. there is no notion of where the zonecuts are and what data is out of zone. TODO, BUGS and FEATURES.
Copyright (c) 2003, 2004 RIPE NCC. Author Olaf M. Kolkman <net-dns-sec@ripe.net> All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. The $GENERATE primitive parser is based on code in Net::DNS::ZoneFile SEE ALSOperl(1), Net::DNS, Net::DNS::RR, Net::DNS::RR::RRSIG, Net::DNS::ZonePOD ERRORSHey! The above document had some coding errors, which are explained below:
Visit the GSP FreeBSD Man Page Interface. |