Skip Menu |

This queue is for tickets about the Net-DNS CPAN distribution.

Report information
The Basics
Id: 62030
Status: resolved
Priority: 0/
Queue: Net-DNS

People
Owner: Nobody in particular
Requestors: BTIETZ [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Extending the interface to support parsing rdata from zonefiles
These patches first adding a new method to the interface defined by Net::DNS::RR. This method is called new_from_filestring and performs the parsing of the rdata and generates a new suitable object. The default-function, given by Net::DNS::RR directly simply reuses the new_from_string-method of the corresponding subclass. For CNAME and MX-records corresponding special functions are given in the other patches.
Subject: 0004--Net-DNS-RR-MX-support-new_from_filestring.patch
From 4ac0576b7a07bb42c2573be7bf505797347e059a Mon Sep 17 00:00:00 2001 From: Benjamin Tietz <benjamin@micronet24.de> Date: Sun, 10 Oct 2010 20:24:40 +0200 Subject: [PATCH] [Net::DNS::RR::MX] support new_from_filestring with the MX-record the second most common record is now able to expand its rdata to a full qualified name. --- lib/Net/DNS/RR/MX.pm | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/lib/Net/DNS/RR/MX.pm b/lib/Net/DNS/RR/MX.pm index aef2948..9de0629 100644 --- a/lib/Net/DNS/RR/MX.pm +++ b/lib/Net/DNS/RR/MX.pm @@ -53,6 +53,14 @@ sub new_from_string { return bless $self, $class; } +sub new_from_filestring { + my ($self, $ele, $data, $param) = @_; + # as the exchange is the only host and always the last item, + # it is possible to simply use dns_fqdn here, too + return $self->new_from_string($ele, + $self->dns_fqdn($data, $param->{origin})); +} + sub rdatastr { my $self = shift; @@ -132,6 +140,7 @@ Copyright (c) 1997-2002 Michael Fuhr. Portions Copyright (c) 2002-2004 Chris Reinhardt. Portions Copyright (c) 2005 Olaf Kolkman NLnet Labs. +Portions Copyright (c) 2010 Benjamin Tietz All rights reserved. This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. -- 1.5.6.5
Subject: 0002--Net-DNS-RR-support-for-adding-filed-rdata.patch
From 720e98565519d47d3bb49a1d1c1ef2d782bfeb02 Mon Sep 17 00:00:00 2001 From: Benjamin Tietz <benjamin@micronet24.de> Date: Sun, 10 Oct 2010 20:18:08 +0200 Subject: [PATCH] [Net::DNS::RR] support for adding filed rdata Parsing the data from a zone-file may be different from parsing the data from a packet. To make the Records able to interprete these, the interface was extended by a new creation-method new_from_filestring. --- lib/Net/DNS/RR.pm | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 53 insertions(+), 0 deletions(-) diff --git a/lib/Net/DNS/RR.pm b/lib/Net/DNS/RR.pm index 25a6a3b..7bc4602 100644 --- a/lib/Net/DNS/RR.pm +++ b/lib/Net/DNS/RR.pm @@ -751,6 +751,57 @@ sub rr_rdata { return exists $self->{'rdata'} ? $self->{'rdata'} : ''; } +# $fqdn = $self->dns_fqdn($domain, $origin) +# +# If $domain isn't fully qualified and thus not ending with a dot, the origin +# will be appended. In both cases the finalizing dot will be cut off afterwards. +# +# This functions is inteded to be used by the extension of Net::DNS::RR::xx +# parsing functionality. +sub dns_fqdn { + my ($self, $name, $origin) = @_; + $name = $self->_dns_expand_chars($name, $origin); + $name = $origin unless $name; + $name .= ".".$origin unless(substr($name, -1) eq "."); + return substr($name, 0, -1); # last char must be a dot now +} + +# expand any special character within one item +# called as +# $self->_dns_expand_chars($string, $origin) +sub _dns_expand_chars { + local($_); + $_ = $_[1]; + my $origin = $_[2] || ""; + s/(?<![\w\\])@/$origin/; + s/\\(\d+)/pack("C",$1)/e; + s/\\//; + $_[1] = $_; + return $_; +} + +# +# $subclass->new_from_filestring($rr, $rdata, $parameter); +# +# extend Net::DNS::RR to make it possible to parse the string differently +# from files and from packets +# +# $rr is a prepared hash, consisting of the records name, class, type and +# ttl. +# +# $rdata is the RDATA-part of this record, which has to be parsed. +# +# $parameter is a hashreference with additional data. Currently only the +# key origin is supported, holding the domain for not fully qualified hosts. +# +# the default is to reuse the new_from_string +# +sub new_from_filestring { + my ($self, $ele, $data, $param) = @_; + return $self->new_from_string($ele, $self->_dns_expand_chars( + $data, $param->{origin})); +} + #------------------------------------------------------------------------------ # sub data # @@ -1097,6 +1148,8 @@ Portions Copyright (c) 2005-2007 Olaf Kolkman Portions Copyright (c) 2007 Dick Franks +Portions Copyright (c) 2010 Benjamin Tietz + All rights reserved. This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. -- 1.5.6.5
Subject: 0003--Net-DNS-RR-CNAME-add-file-parsing-hook.patch
From 4d61d3e38fd3007d34626da863403e49814f9822 Mon Sep 17 00:00:00 2001 From: Benjamin Tietz <benjamin@micronet24.de> Date: Sun, 10 Oct 2010 20:21:48 +0200 Subject: [PATCH] [Net::DNS::RR::CNAME] add file-parsing hook The CNAME record is the record most commonly used for without a FQDN in the rdata. This may also work as a example. --- lib/Net/DNS/RR/CNAME.pm | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/lib/Net/DNS/RR/CNAME.pm b/lib/Net/DNS/RR/CNAME.pm index 7474d96..e2f1f37 100644 --- a/lib/Net/DNS/RR/CNAME.pm +++ b/lib/Net/DNS/RR/CNAME.pm @@ -32,6 +32,13 @@ sub new_from_string { return bless $self, $class; } +sub new_from_filestring { + my ($self, $ele, $data, $param) = @_; + return $self->new_from_string($ele, + $self->dns_fqdn($data, $param->{origin})); +} + + sub rdatastr { my $self = shift; -- 1.5.6.5
From: rwfranks [...] acm.org
Satisfactory solutions to this problem lie well beyond the reach of simple patches. BIND zone files are best represented by a Net::DNS::ZoneFile object. use Net::DNS::ZoneFile; $zonefile = new Net::DNS::ZoneFile( 'db.example' ); while ( $rr = $zonefile->read ) { $rr->print; } The whole zone is returned if read() is called in list context: @zone = $zonefile->read; $INCLUDE, $ORIGIN, $TTL and BIND $GENERATE directives are handled automatically. Any RRtype known to Net::DNS is acceptable in the zone file. A compatibility interface is provided as a migration path for users of the CPAN module of the same name.