Re: AXFR from Bind oddities
Peter Pentchev <[email protected]> Tue, 13 Apr 2010 02:04:14 +0300
| Newsgroups | gmane.network.djbdns |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Apr 12, 2010 at 01:00:41PM -0400, DAve wrote:
> John Levine wrote:
> >> Example,
> >> :djgusa.com:16:Zv\075spf1 <snip>
> >> Why is the "Z" in "16:Zv"?
> >>
> >> :djgusa.com:16:\136spf2.0 <snip>
> >> Why is the "\136" in "16:\136spf2"?
> >
> > They're the length byte at the start of the text field. They
> > belong there.
> >
> > The axfr-get program only knows how to format SOA, NS, CNAME,
> > PTR, MX, and A records. Everything else is written out using
> > the generic colon record type with an explicit record type and
> > the literal record contents, which for a TXT record includes the
> > length byte before each text string.
> >
> > It wouldn't be hard to add a few lines to axfr-get.c to format
> > txt records, but there would be no benefit I can see.
> >
> > R's,
> > John
>
> As I suspected, I didn't fully understand what was going on 8^)
> This is a very unique situation for two client's only, so I will change
> my script to use dig to make the axfr query and Net-DNS-Zonefile to
> parse the result and load VegaDNS.
Erm, why not decode the RR lines properly and convert them into
TXT (') lines, e.g. with something like the attached simple Perl
utility? If the attachment should not come through for some reason
or other, it's available at
http://devel.ringlet.net/textproc/decodetinydns/decodetinydns.pl
G'luck,
Peter
--
Peter Pentchev [email protected] [email protected] [email protected]
PGP key: http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint FDBA FD79 C26F 3C51 C95E DF9E ED18 B68D 1619 4553
decodetinydns.pl
(text/x-perl, 2.9 KB)
# Copyright (c) 2010 Peter Pentchev
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# A simple tinydns-data filter to convert type 16 RR records to TXT records.
use strict;
use warnings;
sub decode_single($);
sub decode_several($ $);
while (<>) {
my ($data, $res, $len, $part);
my (@a);
if (!/^:/ || !(@a = split /:/) || @a < 4 || $a[1] ne '16') {
print;
next;
}
# We have a TXT record! Try to decode its contents...
$a[$#a] =~ s/[\r\n]*$//;
$data = $a[3];
$res = '';
while (($len, $data) = decode_single($data)) {
if ($len =~ /^\\(\d+)$/) {
$len = oct $1;
} else {
$len = unpack('C', $len);
}
($part, $data) = decode_several($len, $data);
$res .= $part;
}
print "'".join(':', $a[2], $res, @a[4..$#a])."\n";
}
=item * decode_single (STRING)
Extract the first (possibly encoded) byte from C<STRING>.
Return a list of two elements - the first byte (still possibly encoded) and
the rest of the string.
=cut
sub decode_single($)
{
my ($s) = @_;
return () if !defined($s) || $s eq '';
if ($s =~ /^(\\\d{3}|.)(.*)/) {
return ($1, $2);
} else {
return ();
}
}
=item * decode_several (LENGTH, STRING)
Extract several (possibly encoded) bytes from the beginning of C<STRING>.
Return a list of two elements - the first C<LENGTH> bytes (still possibly
encoded) and the rest of the string.
=cut
sub decode_several($ $)
{
my ($len, $s) = @_;
my ($idx);
return ('', $s) if $len < 1;
$idx = index($s, '\\');
if ($idx == -1 || $idx >= $len) {
return (substr($s, 0, $len), substr($s, $len));
} else {
# Decode the rest of the string...
my ($part, $data) = decode_several($len - $idx - 1,
substr($s, $idx + 4));
# ...then prepend the part with the first \ooo
return (substr($s, 0, $idx + 4).$part, $data);
}
}
signature.asc
(application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEARECAAYFAkvDpuMACgkQ7Ri2jRYZRVNtQwCgtUzvw2veIrLzbmA4ZuwtGUz7 rg0AnR2jifgrufqJHs3UFyxxXDeOecBO =1lXV -----END PGP SIGNATURE-----