fix: populate ldns submodule and add autotools to LDNS build stage

- Re-cloned zonemaster-ldns with --recurse-submodules so the bundled
  ldns C library source (including Changelog and configure.ac) is present
- Added autoconf, automake, libtool to Dockerfile.backend ldns-build stage
  so libtoolize + autoreconf can generate ldns/configure during make

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-21 08:33:38 +02:00
parent 8d4eaa1489
commit eaaa8f6a11
541 changed files with 138189 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
Revision history for Perl extension DNS::LDNS.
0.01 Thu Nov 22 12:48:29 2012
- original version; created by h2xs 1.23 with options
-A -n LDNS
0.02 Fri Jan 18 09:47:57 2013
- Support for DNSSec and Resolver. Added some more constants from
the header files; created by h2xs 1.23 with options
-n LDNS /usr/include/ldns/ldns.h /usr/include/ldns/error.h /usr/include/ldns/rr.h /usr/include/ldns/keys.h /usr/include/ldns/packet.h /usr/include/ldns/resolver.h /usr/include/ldns/rdata.h /usr/include/ldns/dnssec.h
0.03 Fri Apr 19 13:40:57 2013
- Renamed module to Net::LDNS
0.04 Fri Dec 13 14:15:26 2013
- Renamed module to DNS::LDNS
0.05 Mon Dec 30 10:14:00 2013
- Corrected versioning variable in all classes.
- Cleaned up the base class documentation.
0.06 Tue Dec 31 12:17:00 2013
- Corrected pod syntax
0.50 Sun Mar 30 11:05:23 2014
- Added prev parameter to the DNS::LDNS::RR::new(str) constructor.
- Corrected DNS::LDNS::RR::new(file/filename) constructor. Added prev
parameter, changed the default_ttl and origin parameters to
references so they can return data back to the caller as intended.
Using the 'built-in' default values for ttl and origin, rather than
my own values.
- Corrected the DNS::LDNS::Zone::new() constructor. Corrected file
option for reading zone from stream. Using the 'built-in' default
values for ttl and origin, rather than my own values.
- Removed the $DNS::LDNS::DEFAULT_* variables, they proved to be less
useful after modifying the Zone and RR constructors.
- More robust Makefile.PL. Check for existence of ldns library
and perl modules required for the test suite.
0.51 Wed Apr 2 09:12:00 2014
- Added META.yml, and added some more package dependencies.
- Compatibility with ldns < 1.6.12.
0.52 Tue May 5 09:13:00 2015
- Fixed typo in META.yml
0.60 Thu Dec 29 11:15:00 2016
- Compatibility with ldns 1.7
- Dist::zilla build management
0.61 Fri Dec 30 14:32:00 2016
- Bugfixes for ldns 1.7 compatibility
- Compatibility with perl 5.25

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
Changes
constants.PL
dist.ini
LDNS.xs
lib/DNS/LDNS.pm
lib/DNS/LDNS/DNSSecDataChain.pm
lib/DNS/LDNS/DNSSecName.pm
lib/DNS/LDNS/DNSSecRRs.pm
lib/DNS/LDNS/DNSSecRRSets.pm
lib/DNS/LDNS/DNSSecTrustTree.pm
lib/DNS/LDNS/DNSSecZone.pm
lib/DNS/LDNS/GC.pm
lib/DNS/LDNS/Key.pm
lib/DNS/LDNS/KeyList.pm
lib/DNS/LDNS/Packet.pm
lib/DNS/LDNS/RBNode.pm
lib/DNS/LDNS/RBTree.pm
lib/DNS/LDNS/RData.pm
lib/DNS/LDNS/Resolver.pm
lib/DNS/LDNS/RR.pm
lib/DNS/LDNS/RRList.pm
lib/DNS/LDNS/Zone.pm
MANIFEST
ppport.h
README
t/dnssec_datachain.t
t/dnssec_zone.t
t/key.t
t/DNS-LDNS.t
t/rdata.t
t/resolver.t
t/rr.t
t/rrlist.t
t/testdata/key.private
t/testdata/myzone.org
t/testdata/resolv.conf
t/zone.t
typemap

View File

@@ -0,0 +1,36 @@
DNS::LDNS version 0.61
======================
DESCRIPTION
DNS::LDNS is a perl OO-wrapper for the ldns library. For a detailed
description on how this library works, you are advised to read the ldns
documentation. For a functional description of the wrapper classes,
please read the perldoc for DNS::LDNS and subclasses.
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
DEPENDENCIES
This module requires these other modules and libraries:
ldns
AUTHOR
Erik Pihl Ostlyngen, erik.ostlyngen@uninett.no
COPYRIGHT AND LICENCE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.8 or,
at your option, any later version of Perl 5 you may have available.

View File

@@ -0,0 +1,280 @@
use ExtUtils::Constant;
# If you edit these definitions to change the constants used by this module,
# you will need to use the generated const-c.inc and const-xs.inc
# files to replace their "fallback" counterparts before distributing your
# changes.
my @names = (qw(LDNS_AA LDNS_AD LDNS_CD LDNS_DEFAULT_EXP_TIME
LDNS_DEFAULT_TTL LDNS_DNSSEC_KEYPROTO LDNS_IP4ADDRLEN
LDNS_IP6ADDRLEN LDNS_KEY_REVOKE_KEY LDNS_KEY_SEP_KEY
LDNS_KEY_ZONE_KEY LDNS_MAX_DOMAINLEN LDNS_MAX_KEYLEN
LDNS_MAX_LABELLEN LDNS_MAX_PACKETLEN LDNS_MAX_POINTERS
LDNS_MAX_RDFLEN LDNS_NSEC3_MAX_ITERATIONS
LDNS_NSEC3_VARS_OPTOUT_MASK LDNS_PORT LDNS_QR LDNS_RA LDNS_RD
LDNS_RDATA_FIELD_DESCRIPTORS_COMMON LDNS_RDF_SIZE_16BYTES
LDNS_RDF_SIZE_6BYTES LDNS_RDF_SIZE_BYTE
LDNS_RDF_SIZE_DOUBLEWORD LDNS_RDF_SIZE_WORD LDNS_RESOLV_ANCHOR
LDNS_RESOLV_DEFDOMAIN LDNS_RESOLV_INET LDNS_RESOLV_INET6
LDNS_RESOLV_INETANY LDNS_RESOLV_KEYWORD LDNS_RESOLV_KEYWORDS
LDNS_RESOLV_NAMESERVER LDNS_RESOLV_OPTIONS LDNS_RESOLV_RTT_INF
LDNS_RESOLV_RTT_MIN LDNS_RESOLV_SEARCH LDNS_RESOLV_SORTLIST
LDNS_RR_OVERHEAD LDNS_SIGNATURE_LEAVE_ADD_NEW
LDNS_SIGNATURE_LEAVE_NO_ADD LDNS_SIGNATURE_REMOVE_ADD_NEW
LDNS_SIGNATURE_REMOVE_NO_ADD LDNS_TC),
{name=>"LDNS_CERT_ACPKIX", macro=>"1"},
{name=>"LDNS_CERT_IACPKIX", macro=>"1"},
{name=>"LDNS_CERT_IPGP", macro=>"1"},
{name=>"LDNS_CERT_IPKIX", macro=>"1"},
{name=>"LDNS_CERT_ISPKI", macro=>"1"},
{name=>"LDNS_CERT_OID", macro=>"1"},
{name=>"LDNS_CERT_PGP", macro=>"1"},
{name=>"LDNS_CERT_PKIX", macro=>"1"},
{name=>"LDNS_CERT_SPKI", macro=>"1"},
{name=>"LDNS_CERT_URI", macro=>"1"},
{name=>"LDNS_DH", macro=>"1"},
{name=>"LDNS_DSA", macro=>"1"},
{name=>"LDNS_DSA_NSEC3", macro=>"1"},
{name=>"LDNS_ECC", macro=>"1"},
{name=>"LDNS_ECC_GOST", macro=>"1"},
{name=>"LDNS_HASH_GOST", macro=>"1"},
{name=>"LDNS_PACKET_ANSWER", macro=>"1"},
{name=>"LDNS_PACKET_IQUERY", macro=>"1"},
{name=>"LDNS_PACKET_NODATA", macro=>"1"},
{name=>"LDNS_PACKET_NOTIFY", macro=>"1"},
{name=>"LDNS_PACKET_NXDOMAIN", macro=>"1"},
{name=>"LDNS_PACKET_QUERY", macro=>"1"},
{name=>"LDNS_PACKET_QUESTION", macro=>"1"},
{name=>"LDNS_PACKET_REFERRAL", macro=>"1"},
{name=>"LDNS_PACKET_STATUS", macro=>"1"},
{name=>"LDNS_PACKET_UNKNOWN", macro=>"1"},
{name=>"LDNS_PACKET_UPDATE", macro=>"1"},
{name=>"LDNS_PRIVATEDNS", macro=>"1"},
{name=>"LDNS_PRIVATEOID", macro=>"1"},
{name=>"LDNS_RCODE_FORMERR", macro=>"1"},
{name=>"LDNS_RCODE_NOERROR", macro=>"1"},
{name=>"LDNS_RCODE_NOTAUTH", macro=>"1"},
{name=>"LDNS_RCODE_NOTIMPL", macro=>"1"},
{name=>"LDNS_RCODE_NOTZONE", macro=>"1"},
{name=>"LDNS_RCODE_NXDOMAIN", macro=>"1"},
{name=>"LDNS_RCODE_NXRRSET", macro=>"1"},
{name=>"LDNS_RCODE_REFUSED", macro=>"1"},
{name=>"LDNS_RCODE_SERVFAIL", macro=>"1"},
{name=>"LDNS_RCODE_YXDOMAIN", macro=>"1"},
{name=>"LDNS_RCODE_YXRRSET", macro=>"1"},
{name=>"LDNS_RDF_TYPE_A", macro=>"1"},
{name=>"LDNS_RDF_TYPE_AAAA", macro=>"1"},
{name=>"LDNS_RDF_TYPE_ALG", macro=>"1"},
{name=>"LDNS_RDF_TYPE_APL", macro=>"1"},
{name=>"LDNS_RDF_TYPE_ATMA", macro=>"1"},
{name=>"LDNS_RDF_TYPE_B32_EXT", macro=>"1"},
{name=>"LDNS_RDF_TYPE_B64", macro=>"1"},
{name=>"LDNS_RDF_TYPE_CERT_ALG", macro=>"1"},
{name=>"LDNS_RDF_TYPE_CLASS", macro=>"1"},
{name=>"LDNS_RDF_TYPE_DNAME", macro=>"1"},
{name=>"LDNS_RDF_TYPE_HEX", macro=>"1"},
{name=>"LDNS_RDF_TYPE_INT16", macro=>"1"},
{name=>"LDNS_RDF_TYPE_INT16_DATA", macro=>"1"},
{name=>"LDNS_RDF_TYPE_INT32", macro=>"1"},
{name=>"LDNS_RDF_TYPE_INT8", macro=>"1"},
{name=>"LDNS_RDF_TYPE_IPSECKEY", macro=>"1"},
{name=>"LDNS_RDF_TYPE_LOC", macro=>"1"},
{name=>"LDNS_RDF_TYPE_NONE", macro=>"1"},
{name=>"LDNS_RDF_TYPE_NSAP", macro=>"1"},
{name=>"LDNS_RDF_TYPE_NSEC", macro=>"1"},
{name=>"LDNS_RDF_TYPE_NSEC3_NEXT_OWNER", macro=>"1"},
{name=>"LDNS_RDF_TYPE_NSEC3_SALT", macro=>"1"},
{name=>"LDNS_RDF_TYPE_PERIOD", macro=>"1"},
{name=>"LDNS_RDF_TYPE_SERVICE", macro=>"1"},
{name=>"LDNS_RDF_TYPE_STR", macro=>"1"},
{name=>"LDNS_RDF_TYPE_TIME", macro=>"1"},
{name=>"LDNS_RDF_TYPE_HIP", macro=>"1"},
{name=>"LDNS_RDF_TYPE_TSIGTIME", macro=>"1"},
{name=>"LDNS_RDF_TYPE_TYPE", macro=>"1"},
{name=>"LDNS_RDF_TYPE_UNKNOWN", macro=>"1"},
{name=>"LDNS_RDF_TYPE_WKS", macro=>"1"},
{name=>"LDNS_RR_CLASS_ANY", macro=>"1"},
{name=>"LDNS_RR_CLASS_CH", macro=>"1"},
{name=>"LDNS_RR_CLASS_COUNT", macro=>"1"},
{name=>"LDNS_RR_CLASS_FIRST", macro=>"1"},
{name=>"LDNS_RR_CLASS_HS", macro=>"1"},
{name=>"LDNS_RR_CLASS_IN", macro=>"1"},
{name=>"LDNS_RR_CLASS_LAST", macro=>"1"},
{name=>"LDNS_RR_CLASS_NONE", macro=>"1"},
{name=>"LDNS_RR_COMPRESS", macro=>"1"},
{name=>"LDNS_RR_NO_COMPRESS", macro=>"1"},
{name=>"LDNS_RR_TYPE_A", macro=>"1"},
{name=>"LDNS_RR_TYPE_A6", macro=>"1"},
{name=>"LDNS_RR_TYPE_AAAA", macro=>"1"},
{name=>"LDNS_RR_TYPE_AFSDB", macro=>"1"},
{name=>"LDNS_RR_TYPE_ANY", macro=>"1"},
{name=>"LDNS_RR_TYPE_APL", macro=>"1"},
{name=>"LDNS_RR_TYPE_ATMA", macro=>"1"},
{name=>"LDNS_RR_TYPE_AXFR", macro=>"1"},
{name=>"LDNS_RR_TYPE_CERT", macro=>"1"},
{name=>"LDNS_RR_TYPE_CNAME", macro=>"1"},
{name=>"LDNS_RR_TYPE_COUNT", macro=>"1"},
{name=>"LDNS_RR_TYPE_DHCID", macro=>"1"},
{name=>"LDNS_RR_TYPE_DLV", macro=>"1"},
{name=>"LDNS_RR_TYPE_DNAME", macro=>"1"},
{name=>"LDNS_RR_TYPE_DNSKEY", macro=>"1"},
{name=>"LDNS_RR_TYPE_DS", macro=>"1"},
{name=>"LDNS_RR_TYPE_EID", macro=>"1"},
{name=>"LDNS_RR_TYPE_FIRST", macro=>"1"},
{name=>"LDNS_RR_TYPE_GID", macro=>"1"},
{name=>"LDNS_RR_TYPE_GPOS", macro=>"1"},
{name=>"LDNS_RR_TYPE_HINFO", macro=>"1"},
{name=>"LDNS_RR_TYPE_IPSECKEY", macro=>"1"},
{name=>"LDNS_RR_TYPE_ISDN", macro=>"1"},
{name=>"LDNS_RR_TYPE_IXFR", macro=>"1"},
{name=>"LDNS_RR_TYPE_KEY", macro=>"1"},
{name=>"LDNS_RR_TYPE_KX", macro=>"1"},
{name=>"LDNS_RR_TYPE_LAST", macro=>"1"},
{name=>"LDNS_RR_TYPE_LOC", macro=>"1"},
{name=>"LDNS_RR_TYPE_MAILA", macro=>"1"},
{name=>"LDNS_RR_TYPE_MAILB", macro=>"1"},
{name=>"LDNS_RR_TYPE_MB", macro=>"1"},
{name=>"LDNS_RR_TYPE_MD", macro=>"1"},
{name=>"LDNS_RR_TYPE_MF", macro=>"1"},
{name=>"LDNS_RR_TYPE_MG", macro=>"1"},
{name=>"LDNS_RR_TYPE_MINFO", macro=>"1"},
{name=>"LDNS_RR_TYPE_MR", macro=>"1"},
{name=>"LDNS_RR_TYPE_MX", macro=>"1"},
{name=>"LDNS_RR_TYPE_NAPTR", macro=>"1"},
{name=>"LDNS_RR_TYPE_NIMLOC", macro=>"1"},
{name=>"LDNS_RR_TYPE_NS", macro=>"1"},
{name=>"LDNS_RR_TYPE_NSAP", macro=>"1"},
{name=>"LDNS_RR_TYPE_NSAP_PTR", macro=>"1"},
{name=>"LDNS_RR_TYPE_NSEC", macro=>"1"},
{name=>"LDNS_RR_TYPE_NSEC3", macro=>"1"},
{name=>"LDNS_RR_TYPE_NSEC3PARAM", macro=>"1"},
{name=>"LDNS_RR_TYPE_NSEC3PARAMS", macro=>"1"},
{name=>"LDNS_RR_TYPE_NULL", macro=>"1"},
{name=>"LDNS_RR_TYPE_NXT", macro=>"1"},
{name=>"LDNS_RR_TYPE_OPT", macro=>"1"},
{name=>"LDNS_RR_TYPE_PTR", macro=>"1"},
{name=>"LDNS_RR_TYPE_PX", macro=>"1"},
{name=>"LDNS_RR_TYPE_RP", macro=>"1"},
{name=>"LDNS_RR_TYPE_RRSIG", macro=>"1"},
{name=>"LDNS_RR_TYPE_RT", macro=>"1"},
{name=>"LDNS_RR_TYPE_SIG", macro=>"1"},
{name=>"LDNS_RR_TYPE_SINK", macro=>"1"},
{name=>"LDNS_RR_TYPE_SOA", macro=>"1"},
{name=>"LDNS_RR_TYPE_SPF", macro=>"1"},
{name=>"LDNS_RR_TYPE_SRV", macro=>"1"},
{name=>"LDNS_RR_TYPE_SSHFP", macro=>"1"},
{name=>"LDNS_RR_TYPE_TALINK", macro=>"1"},
{name=>"LDNS_RR_TYPE_TSIG", macro=>"1"},
{name=>"LDNS_RR_TYPE_TXT", macro=>"1"},
{name=>"LDNS_RR_TYPE_UID", macro=>"1"},
{name=>"LDNS_RR_TYPE_UINFO", macro=>"1"},
{name=>"LDNS_RR_TYPE_UNSPEC", macro=>"1"},
{name=>"LDNS_RR_TYPE_WKS", macro=>"1"},
{name=>"LDNS_RR_TYPE_X25", macro=>"1"},
{name=>"LDNS_RSAMD5", macro=>"1"},
{name=>"LDNS_RSASHA1", macro=>"1"},
{name=>"LDNS_RSASHA1_NSEC3", macro=>"1"},
{name=>"LDNS_RSASHA256", macro=>"1"},
{name=>"LDNS_RSASHA512", macro=>"1"},
{name=>"LDNS_SECTION_ADDITIONAL", macro=>"1"},
{name=>"LDNS_SECTION_ANSWER", macro=>"1"},
{name=>"LDNS_SECTION_ANY", macro=>"1"},
{name=>"LDNS_SECTION_ANY_NOQUESTION", macro=>"1"},
{name=>"LDNS_SECTION_AUTHORITY", macro=>"1"},
{name=>"LDNS_SECTION_QUESTION", macro=>"1"},
{name=>"LDNS_SHA1", macro=>"1"},
{name=>"LDNS_SHA256", macro=>"1"},
{name=>"LDNS_SIGN_DSA", macro=>"1"},
{name=>"LDNS_SIGN_DSA_NSEC3", macro=>"1"},
{name=>"LDNS_SIGN_ECC_GOST", macro=>"1"},
{name=>"LDNS_SIGN_HMACSHA1", macro=>"1"},
{name=>"LDNS_SIGN_HMACSHA256", macro=>"1"},
{name=>"LDNS_SIGN_RSAMD5", macro=>"1"},
{name=>"LDNS_SIGN_RSASHA1", macro=>"1"},
{name=>"LDNS_SIGN_RSASHA1_NSEC3", macro=>"1"},
{name=>"LDNS_SIGN_RSASHA256", macro=>"1"},
{name=>"LDNS_SIGN_RSASHA512", macro=>"1"},
{name=>"LDNS_STATUS_ADDRESS_ERR", macro=>"1"},
{name=>"LDNS_STATUS_CERT_BAD_ALGORITHM", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_ALGO_NOT_IMPL", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_BOGUS", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_EXPIRATION_BEFORE_INCEPTION", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_NO_DNSKEY", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_NO_DS", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_NO_MATCHING_KEYTAG_DNSKEY", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_NO_RRSIG", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_NO_TRUSTED_DNSKEY", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_NO_TRUSTED_DS", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_SIG_EXPIRED", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_SIG_NOT_INCEPTED", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_TSIG_BOGUS", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_TSIG_ERR", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_TYPE_COVERED_ERR", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_UNKNOWN_ALGO", macro=>"1"},
{name=>"LDNS_STATUS_CRYPTO_VALIDATED", macro=>"1"},
{name=>"LDNS_STATUS_DDD_OVERFLOW", macro=>"1"},
{name=>"LDNS_STATUS_DNSSEC_EXISTENCE_DENIED", macro=>"1"},
{name=>"LDNS_STATUS_DNSSEC_NSEC3_ORIGINAL_NOT_FOUND", macro=>"1"},
{name=>"LDNS_STATUS_DNSSEC_NSEC_RR_NOT_COVERED", macro=>"1"},
{name=>"LDNS_STATUS_DNSSEC_NSEC_WILDCARD_NOT_COVERED", macro=>"1"},
{name=>"LDNS_STATUS_DOMAINNAME_OVERFLOW", macro=>"1"},
{name=>"LDNS_STATUS_DOMAINNAME_UNDERFLOW", macro=>"1"},
{name=>"LDNS_STATUS_EMPTY_LABEL", macro=>"1"},
{name=>"LDNS_STATUS_ENGINE_KEY_NOT_LOADED", macro=>"1"},
{name=>"LDNS_STATUS_ERR", macro=>"1"},
{name=>"LDNS_STATUS_FILE_ERR", macro=>"1"},
{name=>"LDNS_STATUS_INTERNAL_ERR", macro=>"1"},
{name=>"LDNS_STATUS_INVALID_B32_EXT", macro=>"1"},
{name=>"LDNS_STATUS_INVALID_B64", macro=>"1"},
{name=>"LDNS_STATUS_INVALID_HEX", macro=>"1"},
{name=>"LDNS_STATUS_INVALID_INT", macro=>"1"},
{name=>"LDNS_STATUS_INVALID_IP4", macro=>"1"},
{name=>"LDNS_STATUS_INVALID_IP6", macro=>"1"},
{name=>"LDNS_STATUS_INVALID_POINTER", macro=>"1"},
{name=>"LDNS_STATUS_INVALID_STR", macro=>"1"},
{name=>"LDNS_STATUS_INVALID_TIME", macro=>"1"},
{name=>"LDNS_STATUS_LABEL_OVERFLOW", macro=>"1"},
{name=>"LDNS_STATUS_MEM_ERR", macro=>"1"},
{name=>"LDNS_STATUS_MISSING_RDATA_FIELDS_KEY", macro=>"1"},
{name=>"LDNS_STATUS_MISSING_RDATA_FIELDS_RRSIG", macro=>"1"},
{name=>"LDNS_STATUS_NETWORK_ERR", macro=>"1"},
{name=>"LDNS_STATUS_NOT_IMPL", macro=>"1"},
{name=>"LDNS_STATUS_NO_DATA", macro=>"1"},
{name=>"LDNS_STATUS_NSEC3_ERR", macro=>"1"},
{name=>"LDNS_STATUS_NULL", macro=>"1"},
{name=>"LDNS_STATUS_OK", macro=>"1"},
{name=>"LDNS_STATUS_PACKET_OVERFLOW", macro=>"1"},
{name=>"LDNS_STATUS_RES_NO_NS", macro=>"1"},
{name=>"LDNS_STATUS_RES_QUERY", macro=>"1"},
{name=>"LDNS_STATUS_SOCKET_ERROR", macro=>"1"},
{name=>"LDNS_STATUS_SSL_ERR", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_ALG_ERR", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_BAD_ESCAPE", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_CLASS_ERR", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_DNAME_ERR", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_EMPTY", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_ERR", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_INCLUDE", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_INCLUDE_ERR_NOTIMPL", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_INTEGER_OVERFLOW", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_ITERATIONS_OVERFLOW", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_KEYWORD_ERR", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_ORIGIN", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_RDATA_ERR", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_TTL", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_TTL_ERR", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_TYPE_ERR", macro=>"1"},
{name=>"LDNS_STATUS_SYNTAX_VERSION_ERR", macro=>"1"},
{name=>"LDNS_STATUS_UNKNOWN_INET", macro=>"1"},
{name=>"LDNS_STATUS_WIRE_INCOMPLETE_ADDITIONAL", macro=>"1"},
{name=>"LDNS_STATUS_WIRE_INCOMPLETE_ANSWER", macro=>"1"},
{name=>"LDNS_STATUS_WIRE_INCOMPLETE_AUTHORITY", macro=>"1"},
{name=>"LDNS_STATUS_WIRE_INCOMPLETE_HEADER", macro=>"1"},
{name=>"LDNS_STATUS_WIRE_INCOMPLETE_QUESTION", macro=>"1"});
ExtUtils::Constant::WriteConstants(
NAME => 'LDNS',
NAMES => \@names,
DEFAULT_TYPE => 'IV',
C_FILE => 'const-c.inc',
XS_FILE => 'const-xs.inc',
);

View File

@@ -0,0 +1,18 @@
name = DNS-LDNS
author = Erik Ostlyngen <erik@uninett.no>
copyright_holder = UNINETT Norid AS
copyright_year = 2013
license = None
version = 0.61
[AutoPrereqs]
[GatherDir]
[MetaYAML]
[MakeMaker::Awesome]
WriteMakefile_arg = LIBS => ['-lldns']
footer_file = constants.PL
[CheckLib]
lib = ldns
header = ldns/ldns.h
[License]
[PruneCruft]

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,87 @@
package DNS::LDNS::DNSSecDataChain;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS;
our $VERSION = '0.61';
sub rrset {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrset, $self);
}
sub signatures {
my $self = shift;
return DNS::LDNS::GC::own($self->_signatures, $self);
}
sub parent {
my $self = shift;
return DNS::LDNS::GC::own($self->_parent, $self);
}
sub derive_trust_tree {
my ($self, $rr) = @_;
if (!DNS::LDNS::GC::is_owned($rr) or DNS::LDNS::GC::owner($rr) ne $self) {
die "The rr ($rr) must be in the data chain ($self)";
}
return DNS::LDNS::GC::own($self->_derive_trust_tree($rr), $self);
}
sub derive_trust_tree_time {
my ($self, $rr, $checktime) = @_;
if (!DNS::LDNS::GC::is_owned($rr) or DNS::LDNS::GC::owner($rr) ne $self) {
die "The rr ($rr) must be in the data chain ($self)";
}
return DNS::LDNS::GC::own(
$self->_derive_trust_tree_time($rr, $checktime), $self);
}
1;
__END__
=head1 NAME
DNS::LDNS::DNSSecDataChain - DNSSec data chain element
=head1 SYNOPSIS
use DNS::LDNS ':all'
chain = new DNS::LDNS::DNSSecDataChain
chain->print(fp)
chain->derive_trust_tree(rr)
chain->derive_trust_tree_time(rr, checktime)
# Node attributes
rrset = chain->rrset
rrset = chain->signatures
rrtype = chain->parent_type
pchain = chain->parent
rcode = chain->packet_rcode
rrtype = chain->packet_qtype
bool = chain->packet_nodata
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,110 @@
package DNS::LDNS::DNSSecName;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS ':all';
our $VERSION = '0.61';
sub new {
my $class = shift;
return _new;
}
sub name {
my $self = shift;
return DNS::LDNS::GC::own($self->_name, $self);
}
sub set_name {
my ($self, $name) = @_;
DNS::LDNS::GC::disown(my $old = $self->name);
_set_name($self, my $copy = $name->clone);
DNS::LDNS::GC::own($copy, $self);
}
sub rrsets {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrsets, $self);
}
sub add_rr {
my ($self, $rr) = @_;
my $s = _add_rr($self, my $copy = $rr->clone);
DNS::LDNS::GC::own($copy, $self);
$DNS::LDNS::last_status = $s;
return $s;
}
sub nsec {
my $self = shift;
return DNS::LDNS::GC::own($self->_nsec, $self);
}
sub set_nsec {
my ($self, $nsec) = @_;
DNS::LDNS::GC::disown(my $old = $self->nsec);
_set_nsec($self, my $copy = $nsec->clone);
DNS::LDNS::GC::own($copy, $self);
}
sub hashed_name {
my $self = shift;
return DNS::LDNS::GC::own($self->_hashed_name, $self);
}
sub nsec_signatures {
my $self = shift;
return DNS::LDNS::GC::own($self->_nsec_signatures, $self);
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::DNSSecName - Dname with rrsets in a dnssec zone
=head1 SYNOPSIS
use LDNS ':all'
my name = new DNS::LDNS::DNSSecName
rdata = name->name
name->set_name(rdata)
bool = name->is_glue
rrsets = name->rrsets
name->add_rr(rr)
rr = name->nsec
name->set_nsec(rr)
hash = name->hashed_name
rrs = name->nsec_signatures
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,85 @@
package DNS::LDNS::DNSSecRRSets;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS;
our $VERSION = '0.61';
# Note: Since this class does not have a constructor, we can let its child
# objects be owned by the parent. This reduces the recursion depth on
# DESTROY.
sub rrs {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrs, DNS::LDNS::GC::owner($self));
}
sub signatures {
my $self = shift;
return DNS::LDNS::GC::own($self->_signatures, DNS::LDNS::GC::owner($self));
}
sub next {
my $self = shift;
return DNS::LDNS::GC::own($self->_next, DNS::LDNS::GC::owner($self));
}
sub set_type {
my ($self, $type) = @_;
my $s = _set_type($self, $type);
$DNS::LDNS::last_status = $s;
return $s;
}
sub add_rr {
my ($self, $rr) = @_;
my $s = _add_rr($self, my $copy = $rr->clone);
$DNS::LDNS::last_status = $s;
DNS::LDNS::GC::own($copy, $self);
return $s;
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::DNSSecRRSets - Linked list of rrsets in a dnssec zone
=head1 SYNOPSIS
use DNS::LDNS ':all'
rrs = rrsets->rrs
rrs = rrsets->signatures
rrsets2 = rrsets->next
rrsets->add_rr(rr)
bool = rrsets->contains_type(rr_type)
rr_type = rrsets->type
rrsets->set_type(rr_type)
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,82 @@
package DNS::LDNS::DNSSecRRs;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS;
our $VERSION = '0.61';
# Note: This class does not have a constructor. Thus, it can not be created
# as an individual object. The data structure of the node is owned
# and freed by the owner of the parent rather than the parent node. This
# is to prevent deep recursion on DESTROY.
sub to_string {
my $self = shift;
my $ret = '';
while ($self and $self->rr) {
$ret .= $self->rr->to_string;
$self = $self->next;
}
return $ret;
}
sub add_rr {
my ($self, $rr) = @_;
my $s = _add_rr($self, my $copy = $rr->clone);
DNS::LDNS::GC::own($self, $copy);
$DNS::LDNS::last_status = $s;
return $s;
}
sub rr {
my $self = shift;
return DNS::LDNS::GC::own($self->_rr, DNS::LDNS::GC::owner($self));
}
sub next {
my $self = shift;
return DNS::LDNS::GC::own($self->_next, DNS::LDNS::GC::owner($self));
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::DNSSecRRs - Linked list of rrs in a dnssec zone
=head1 SYNOPSIS
use DNS::LDNS ':all'
rrs->to_string
rrs->add_rr(rr)
rr = rrs->rr
rrs2 = rrs->next
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,99 @@
package DNS::LDNS::DNSSecTrustTree;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS;
our $VERSION = '0.61';
sub add_parent {
my ($self, $parent, $sig, $parent_status) = @_;
if (DNS::LDNS::GC::is_owned($parent)) {
die "Cannot add to multiple trees.";
}
my $s = _add_parent($self, $parent, $sig, $parent_status);
DNS::LDNS::GC::own($parent, $self);
$DNS::LDNS::last_status = $s;
return $s;
}
sub contains_keys {
my ($self, $trusted_keys) = @_;
my $s = _contains_keys($self, $trusted_keys);
$DNS::LDNS::last_status = $s;
return $s;
}
sub rr {
my $self = shift;
return DNS::LDNS::GC::own($self->_rr, $self);
}
sub rrset {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrset, $self);
}
sub parent {
my ($self, $i) = @_;
return DNS::LDNS::GC::own($self->_parent($i), $self);
}
sub parent_status {
my ($self, $i) = @_;
my $s = _parent_status($self, $i);
$DNS::LDNS::last_status = $s;
return $s;
}
sub parent_signature {
my ($self, $i) = @_;
return DNS::LDNS::GC::own($self->_parent_signature($i), $self);
}
1;
__END__
=head1 NAME
DNS::LDNS::DNSSecTrustTree - Trust tree from signed RR to trust anchors
=head1 SYNOPSIS
use DNS::LDNS ':all'
tree = new DNS::LDNS::DNSSecTrustTree
tree->print(fp)
d = tree->depth
status = tree->add_parent(parent, sig, parent_status)
status = tree->contains_keys(trusted_keys)
# Node attributes
rr = tree->rr;
rrset = tree->rrset
ptree = tree->parent(i)
pstatus = tree->parent_status(i)
rr = tree->parent_signature(i)
count = tree->parent_count
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,176 @@
package DNS::LDNS::DNSSecZone;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS ':all';
our $VERSION = '0.61';
sub new {
my ($class, %args) = @_;
my $line_nr;
my $status = &LDNS_STATUS_OK;
my $zone;
my $file;
if ($args{filename}) {
unless (open FILE, $args{filename}) {
$DNS::LDNS::last_status = &LDNS_STATUS_FILE_ERR;
$DNS::LDNS::line_nr = 0;
return;
}
$file = \*FILE;
}
elsif ($args{file}) {
$file = $args{file};
}
if ($file) {
$zone = _new_from_file($file,
$args{origin},
$args{ttl} || 0,
$args{class} || 0,
$status, $line_nr);
}
else {
$zone = _new();
}
if ($args{filename}) {
close $file;
}
$DNS::LDNS::last_status = $status;
$DNS::LDNS::line_nr = $line_nr;
if (!defined $zone) {
return;
}
return $zone;
}
sub soa {
my $self = shift;
return DNS::LDNS::GC::own($self->_soa, $self);
}
sub names {
my $self = shift;
return DNS::LDNS::GC::own($self->_names, $self);
}
sub find_rrset {
my ($self, $name, $type) = @_;
return DNS::LDNS::GC::own($self->_find_rrset($name, $type), $self);
}
sub add_rr {
my ($self, $rr) = @_;
# Set a copy of the rr in case it is already owned
my $s = _add_rr($self, my $copy = $rr->clone);
$DNS::LDNS::last_status = $s;
DNS::LDNS::GC::own($copy, $self);
return $s;
}
sub add_empty_nonterminals {
my $self = shift;
my $s = _add_empty_nonterminals($self);
$DNS::LDNS::last_status = $s;
return $s;
}
sub mark_glue {
my $self = shift;
my $s = _mark_glue($self);
$DNS::LDNS::last_status = $s;
return $s;
}
sub sign {
my ($self, $keylist, $policy, $flags) = @_;
my $s = _sign($self, $keylist, $policy, $flags);
$DNS::LDNS::last_status = $s;
return $s;
}
sub sign_nsec3 {
my ($self, $keylist, $policy, $algorithm, $flags, $iterations, $salt,
$signflags) = @_;
my $s = _sign_nsec3($self, $keylist, $policy, $algorithm, $flags,
$iterations, $salt, $signflags);
$DNS::LDNS::last_status = $s;
return $s;
}
sub to_string {
return "DNS::LDNS::DNSSecZone::to_string is not yet implemented";
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::DNSSecZone - Zone with dnssec data
=head1 SYNOPSIS
use DNS::LDNS ':all'
my z = new DNS::LDNS::DNSSecZone(
filename => '/path/to/myzone',
origin => new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'myzone'), #optional
ttl => 3600, #optional
class => LDNS_RR_CLASS_, #optional
)
my z = new DNS::LDNS::DNSSecZone(
file => \*FILE,
origin => ..., ttl => ..., class => ...
)
my z = new DNS::LDNS::DNSSecZone
rr = z->soa
rbtree = z->names
rrsets = z->find_rrset
z->add_rr(rr)
z->create_from_zone(zone)
z->add_empty_nonterminals
z->sign(keylist, policy)
z->sign_nsec3(keylist, policy, algorithm, flags, iterations, salt)
z->create_nsecs
z->create_nsec3s(algorithm, flags, iterations, salt)
z->create_rrsigs(key_list, policy, flags)
=head1 TODO
z->to_string
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,122 @@
package DNS::LDNS::GC;
use strict;
use warnings;
our $VERSION = '0.61';
my %ref_count;
my %owned_by;
sub own {
my ($obj, $owner) = @_;
# print STDERR "Owning $obj -> $owner\n";
return unless (defined $obj);
if ($owned_by{$$owner}) {
# If the owner is an owned object, let obj be owned by
# the owners owner. We want to avoid recursive ownerships.
$owner = $owned_by{$$owner};
}
if (exists $owned_by{$$obj}) {
$ref_count{$$obj}++;
}
else {
$ref_count{$$obj} = 1;
$owned_by{$$obj} = $owner;
}
return $obj;
}
# Return true if the object is owned by someone
sub is_owned {
return (exists $owned_by{${$_[0]}});
}
sub owner {
return $owned_by{${$_[0]}};
}
sub disown {
return unless (defined $_[0]);
delete $owned_by{${$_[0]}};
}
my %free_method = (
'DNS::LDNS::Zone' => '_zone_deep_free',
'DNS::LDNS::RRList' => '_rrlist_deep_free',
'DNS::LDNS::RR' => '_rr_free',
'DNS::LDNS::RData' => '_rdata_deep_free',
'DNS::LDNS::DNSSecZone' => '_dnssec_zone_deep_free',
'DNS::LDNS::DNSSecName' => '_dnssec_name_deep_free',
'DNS::LDNS::Resolver' => '_resolver_deep_free',
'DNS::LDNS::Packet' => '_packet_free',
'DNS::LDNS::Key' => '_key_deep_free',
'DNS::LDNS::KeyList' => '_keylist_free',
'DNS::LDNS::DNSSecDataChain' => '_dnssec_datachain',
);
my %not_deleted_by_owner = (
'DNS::LDNS::DNSSecTrustChain' => 1,
);
sub free {
my $obj = shift;
# print STDERR "Freeing $obj\n";
if (exists $ref_count{$$obj}) {
# print STDERR "Derefing $obj\n";
$ref_count{$$obj}--;
return if ($ref_count{$$obj} > 0);
}
# print STDERR "Deleting $obj\n";
delete $ref_count{$$obj};
if (exists $owned_by{$$obj}) {
delete $owned_by{$$obj};
return unless ($not_deleted_by_owner{ref $obj});
}
my $class = ref $obj;
my $free = $free_method{ref $obj};
die "Internal error: No freeing method for $obj (".ref $obj.")"
unless ($free);
no strict;
&$free($obj);
}
1;
__END__
=head1 NAME
DNS::LDNS::GC - Garbage collector, used internally by the DNS::LDNS modules
=head1 SYNOPSIS
Garbage collector class for DNS::LDNS objects.
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,122 @@
package DNS::LDNS::Key;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS ':all';
our $VERSION = '0.61';
sub new {
my ($class, %args) = @_;
my $key;
if ($args{filename} or $args{file}) {
my $status = &LDNS_STATUS_OK;
my $line_nr = 0;
my $file = $args{file};
if ($args{filename}) {
unless (open FILE, $args{filename}) {
$DNS::LDNS::last_status = &LDNS_STATUS_FILE_ERR;
return;
}
$file = \*FILE;
}
$key = _new_from_file($file, $line_nr, $status);
if ($args{filename}) {
close $file;
}
$DNS::LDNS::last_status = $status;
$DNS::LDNS::line_nr = $line_nr;
if (!defined $key) {
return;
}
}
else {
$key = _new();
}
return $key;
}
sub set_pubkey_owner {
my ($self, $owner) = @_;
my $oldowner = $self->pubkey_owner;
DNS::LDNS::GC::disown(my $old = $self->pubkey_owner);
$self->_set_pubkey_owner($owner);
return DNS::LDNS::GC::own($owner, $self);
}
sub pubkey_owner {
my $self = shift;
return DNS::LDNS::GC::own($self->_pubkey_owner, $self);
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::Key - DNSSec private key
=head1 SYNOPSIS
use DNS::LDNS ':all'
key = new DNS::LDNS::Key
key = new DNS::LDNS::Key(file => \*FILE)
key = new DNS::LDNS::Key(filename => 'keyfile')
str = key->to_string
key->print(\*OUTPUT)
key->set_algorithm(alg)
alg = key->algorithm
key->set_flags(flags)
flags = key->flags
key->set_hmac_key(hmac)
hmac = key->hmac_key
key->set_hmac_size(size)
size = key->hmac_size
key->set_origttl(ttl)
ttl = key->origttl
key->set_inception(epoch)
epoch = key->inception
key->set_expiration(epoch)
epoch = key->expiration
key->set_pubkey_owner(rdata)
rdata = key->pubkey_owner
key->set_keytag(tag)
tag = key->keytag
key->set_use(bool)
bool = key->use
str = key->get_file_base_name
rr = key->to_rr
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,72 @@
package DNS::LDNS::KeyList;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS ':all';
our $VERSION = '0.61';
sub new {
my $class = shift;
return _new();
}
sub push {
my ($self, @keys) = @_;
for my $k (@keys) {
if (DNS::LDNS::GC::is_owned($k)) {
die "Cannot push a key on multiple lists.";
}
$self->_push($k);
DNS::LDNS::GC::own($k, $self);
}
}
sub key {
my ($self, $index) = @_;
return DNS::LDNS::GC::own($self->_key($index), $self);
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::KeyList - Linked list of dnssec keys
=head1 SYNOPSIS
use DNS::LDNS ':all'
my l = new DNS::LDNS::KeyList
l->set_use(bool)
l->push(@keys)
key = l->pop
c = l->count
key = l->key(index)
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,259 @@
package DNS::LDNS::Packet;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS;
our $VERSION = '0.61';
sub new {
my ($class, %args) = @_;
if ($args{name}) {
return _query_new(
$args{name}, $args{type}, $args{class}, $args{flags});
}
else {
return _new;
}
}
sub question {
my $self = shift;
return DNS::LDNS::GC::own($self->_question, $self);
}
sub set_question {
my ($self, $l) = @_;
DNS::LDNS::GC::disown(my $old = $self->question);
$self->_set_question($l);
return DNS::LDNS::GC::own($l, $self);
}
sub answer {
my $self = shift;
return DNS::LDNS::GC::own($self->_answer, $self);
}
sub set_answer {
my ($self, $l) = @_;
DNS::LDNS::GC::disown(my $old = $self->answer);
$self->_set_answer($l);
return DNS::LDNS::GC::own($l, $self);
}
sub authority {
my $self = shift;
return DNS::LDNS::GC::own($self->_authority, $self);
}
sub set_authority {
my ($self, $l) = @_;
DNS::LDNS::GC::disown(my $old = $self->authority);
$self->_set_authority($l);
return DNS::LDNS::GC::own($l, $self);
}
sub additional {
my $self = shift;
return DNS::LDNS::GC::own($self->_additional, $self);
}
sub set_additional {
my ($self, $l) = @_;
DNS::LDNS::GC::disown(my $old = $self->additional);
$self->_set_additional($l);
return DNS::LDNS::GC::own($l, $self);
}
sub answerfrom {
my $self = shift;
return DNS::LDNS::GC::own($self->_answerfrom, $self);
}
sub set_answerfrom {
my ($self, $a) = @_;
DNS::LDNS::GC::disown(my $old = $self->answerfrom);
$self->_set_answerfrom($a);
return DNS::LDNS::GC::own($a, $self);
}
sub timestamp {
my $self = shift;
my $t = _timestamp($self);
return wantarray ? @$t : $t;
}
sub edns_data {
my $self = shift;
return DNS::LDNS::GC::own($self->_edns_data, $self);
}
sub set_edns_data {
my ($self, $data) = @_;
DNS::LDNS::GC::disown(my $old = $self->edns_data);
$self->_set_edns_data($data);
return DNS::LDNS::GC::own($data, $self);
}
sub push_rr {
my ($self, $sec, $rr) = @_;
my $ret = $self->_push_rr($sec, my $copy = $_->clone);
DNS::LDNS::GC::own($copy, $self);
return $ret;
}
sub safe_push_rr {
my ($self, $sec, $rr) = @_;
my $ret = $self->_safe_push_rr($sec, my $copy = $_->clone);
if ($ret) {
DNS::LDNS::GC::own($copy, $self);
}
return $ret;
}
sub tsig {
my $self = shift;
return DNS::LDNS::GC::own($self->_tsig, $self);
}
sub set_tsig {
my ($self, $rr) = @_;
DNS::LDNS::GC::disown(my $old = $self->tsig);
$self->_set_tsig($rr);
return DNS::LDNS::GC::own($rr, $self);
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::Packet - DNS packet
=head1 SYNOPSIS
use DNS::LDNS ':all'
my pkt = new DNS::LDNS::Packet(name => rdata, type => LDNS_RR_TYPE_...,
class => LDNS_RR_CLASS_..., flags => ...)
my pkt = new DNS::LDNS::Packet
pkt2 = pkt->clone
pkt->to_string
rrlist = pkt->question
pkt->set_question(rrlist)
'
rrlist = pkt->answer
pkt->set_answer(rrlist)
rrlist = pkt->authority
pkt->set_authority(rrlist)
rrlist = pkt->additional
pkt->set_additional(rrlist)
rrlist = pkt->all
rrlist = pkt->all_noquestion
for (qw/qr aa tc rd cd ra ad/) {
bool = pkt->$_
pkt->set_$_(bool)
}
id = pkt->id
pkt->set_id(id)
pkt->set_random_id
count = pkt->qdcount
count = pkt->ancount
count = pkt->nscount
count = pkt->arcount
opcode = pkt->opcode
pkt->set_opcode(opcode)
rcode = pkt->rcode # Response code
pkt->set_rcode(rcode)
size = pkt->size
epoch = pkt->querytime
pkt->set_querytime(epoch)
rdata = pkt->answerfrom
pkt->set_answerfrom(rdata)
(sec, usec) = pkt->timestamp
pkt->set_timestamp(sec, usec)
bool = pkt->edns
size = pkt->edns_udp_size
pkt->set_edns_udp_size(size)
rcode = pkt->edns_extended_rcode
pkt->set_edns_extended_rcode(rcode)
v = pkt->edns_version
pkt->set_edns_version(v)
z = pkt->edns_z
pkt->set_edns_z(z)
do = pkt->edns_do
pkt->set_edns_do(do)
rdata = pkt->edns_data
pkt->set_edns_data(rdata)
pkt->set_flags(flags)
rrlist = pkt->rr_list_by_name(rdata, section)
rrlist = pkt->rr_list_by_type(type, section)
rrlist = pkt->rr_list_by_name_and_type(rdata, type, section)
bool = pkt->rr(section, rr) # Check if rr exists
pkt->push_rr(section, rr)
pkt->safe_push_rr(section, rr)
count = pkt->section_count(section)
bool = pkt->empty
rr = pkt->tsig
pkt->set_tsig(rr)
type = pkt->reply_type
rrlist = pkt->get_rrsigs_for_name_and_type(rdata, rrtype)
rrlist = pkt->get_rrsigs_for_type(rrtype)
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,71 @@
package DNS::LDNS::RBNode;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS;
our $VERSION = '0.61';
# Note: This class does not have a constructor. Thus, it can not be created
# as an individual object. The data structure of the object will always be
# owned and freed by its parent object.
sub next {
my $self = shift;
return DNS::LDNS::GC::own($self->_next, $self);
}
sub previous {
my $self = shift;
return DNS::LDNS::GC::own($self->_previous, $self);
}
sub next_nonglue {
my $self = shift;
return DNS::LDNS::GC::own($self->_next_nonglue, $self);
}
sub name {
my ($self) = @_;
return DNS::LDNS::GC::own($self->_name, $self);
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::RBNode - Node in the RBTree
=head1 SYNOPSIS
use DNS::LDNS ':all'
node2 = node->next
node2 = node->next_nonglue
bool = node->is_null
dnssec_name = node->name
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,59 @@
package DNS::LDNS::RBTree;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS;
our $VERSION = '0.61';
# Note: Since this class does not have a constructor, we can let its child
# objects be owned by the parent. This reduces the recursion depth on
# DESTROY.
sub first {
my $self = shift;
return DNS::LDNS::GC::own($self->_first, $self);
}
sub last {
my $self = shift;
return DNS::LDNS::GC::own($self->_last, $self);
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::RBTree - Tree of DNSSecName nodes
=head1 SYNOPSIS
use DNS::LDNS ':all'
rbnode = rbtree->first
rbnode = rbtree->last
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,91 @@
package DNS::LDNS::RData;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS;
our $VERSION = '0.61';
sub new {
my ($class, $type, $str) = @_;
return _new($type, $str);
}
sub cat {
my ($self, $other) = @_;
my $s = _cat($self, $other);
$DNS::LDNS::last_status = $s;
return $s;
}
sub nsec3_hash_name {
my ($self, $algorithm, $iterations, $salt) = @_;
return DNS::LDNS::GC::own(
$self->_nsec3_hash_name($algorithm, $iterations, $salt), $self);
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::RData - Rdata field or a dname in an rr
=head1 SYNOPSIS
use DNS::LDNS ':all'
my rd = new DNS::LDNS::RData(rdf_type, str)
rd2 = rd->clone
rdf_type = rd->type
rd->set_type(rdf_type)
rd->print(\*FILE)
str = rd->to_string
count = rd->label_count
rd2 = rd->label(pos)
bool = rd->is_wildcard
bool = rd->matches_wildcard(wildcard)
bool = rd->is_subdomain(parent)
rd2 = rd->left_chop
status = rd->cat(rd2)
rd->compare(rd2)
rd2 = rd->address_reverse
rd2 = rd->dname_reverse
rd2 = rd->nsec3_hash_name(name, algorithm, iterations, salt)
epoch = rd->to_unix_time
( epoch = rd->2native_time_t )
rr_type = rd->to_rr_type
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,493 @@
package DNS::LDNS::RR;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS ':all';
our $VERSION = '0.61';
sub new {
my $class = shift;
my $rr;
my $status = &LDNS_STATUS_OK;
if (scalar(@_) == 0) {
$rr = _new;
}
elsif (scalar(@_) == 1) {
$rr = _new_from_str($_[0], 0,
undef, undef,
$status);
}
else {
my %args = @_;
# Perl 5.25 does not allow us to pass read-only undef into a
# parameter changing function. So we must send it with a variable.
my $undef = undef;
if ($args{str}) {
$rr = _new_from_str($args{str},
$args{default_ttl} || 0,
$args{origin},
$args{prev} ? ${$args{prev}} : $undef,
$status);
}
elsif ($args{filename} or $args{file}) {
my $line_nr = 0;
my $file = $args{file};
if ($args{filename}) {
unless (open FILE, $args{filename}) {
$DNS::LDNS::last_status = &LDNS_STATUS_FILE_ERR;
$DNS::LDNS::line_nr = 0;
return;
}
$file = \*FILE;
}
my $ttl = 0;
$rr = _new_from_file($file,
$args{default_ttl} ? ${$args{default_ttl}} : $ttl,
$args{origin} ? ${$args{origin}} : $undef,
$args{prev} ? ${$args{prev}} : $undef,
$status,
$line_nr);
if ($args{filename}) {
close $file;
}
$DNS::LDNS::line_nr = $line_nr;
}
elsif ($args{type}) {
$rr = _new_from_type($args{type});
if ($args{owner}) {
$rr->set_owner(ref $args{owner} ? $args{owner} :
new DNS::LDNS::RData(&LDNS_RDF_TYPE_DNAME, $args{owner}));
}
$rr->set_ttl($args{ttl}) if ($args{ttl});
$rr->set_class($args{class}) if ($args{class});
if ($args{rdata}) {
if (!$rr->set_rdata(@{$args{rdata}})) {
$DNS::LDNS::last_status = &LDNS_STATUS_SYNTAX_RDATA_ERR;
return;
}
}
}
}
if (!defined $rr) {
$DNS::LDNS::last_status = $status;
return;
}
return $rr;
}
sub owner {
my $self = shift;
return DNS::LDNS::GC::own($self->_owner, $self);
}
sub set_owner {
my ($self, $owner) = @_;
DNS::LDNS::GC::disown(my $old = $self->owner);
$self->_set_owner($owner);
return DNS::LDNS::GC::own($owner, $self);
}
sub dname {
return $_[0]->owner->to_string;
}
sub rdata {
my ($self, $index) = @_;
return DNS::LDNS::GC::own($self->_rdata($index), $self);
}
# replace all existing rdata with new ones. Requires the
# input array to be exactly same length as rd_count
sub set_rdata {
my ($self, @rdata) = @_;
if (scalar @rdata != $self->rd_count) {
# Hopefully this is a proper error to return here...
$DNS::LDNS::last_status = LDNS_STATUS_SYNTAX_RDATA_ERR;
return;
}
my $i = 0;
for (@rdata) {
my $oldrd = _set_rdata($self, my $copy = $_->clone, $i);
DNS::LDNS::GC::disown(my $old = $oldrd);
DNS::LDNS::GC::own($copy, $self);
$i++;
}
return 1;
}
sub push_rdata {
my ($self, @rdata) = @_;
for (@rdata) {
# Push a copy in case the input rdata are already owned
$self->_push_rdata(my $copy = $_->clone);
DNS::LDNS::GC::own($copy, $self);
}
}
sub rrsig_typecovered {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrsig_typecovered, $self);
}
sub rrsig_set_typecovered {
my ($self, $type) = shift;
DNS::LDNS::GC::disown(my $old = $self->rrsig_typecovered);
my $result = $self->_rrsig_set_typecovered(my $copy = $type->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub rrsig_algorithm {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrsig_algorithm, $self);
}
sub rrsig_set_algorithm {
my ($self, $algo) = shift;
DNS::LDNS::GC::disown(my $old = $self->rrsig_algorithm);
my $result = $self->_rrsig_set_algorithm(my $copy = $algo->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub rrsig_expiration {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrsig_expiration, $self);
}
sub rrsig_set_expiration {
my ($self, $date) = shift;
DNS::LDNS::GC::disown(my $old = $self->rrsig_expiration);
my $result = $self->_rrsig_set_expiration(my $copy = $date->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub rrsig_inception {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrsig_inception, $self);
}
sub rrsig_set_inception {
my ($self, $date) = shift;
DNS::LDNS::GC::disown(my $old = $self->rrsig_inception);
my $result = $self->_rrsig_set_inception(my $copy = $date->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub rrsig_keytag {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrsig_keytag, $self);
}
sub rrsig_set_keytag {
my ($self, $tag) = shift;
DNS::LDNS::GC::disown(my $old = $self->rrsig_keytag);
my $result = $self->_rrsig_set_keytag(my $copy = $tag->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub rrsig_sig {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrsig_sig, $self);
}
sub rrsig_set_sig {
my ($self, $sig) = shift;
DNS::LDNS::GC::disown(my $old = $self->rrsig_sig);
my $result = $self->_rrsig_set_sig(my $copy = $sig->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub rrsig_labels {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrsig_labels, $self);
}
sub rrsig_set_labels {
my ($self, $lab) = shift;
DNS::LDNS::GC::disown(my $old = $self->rrsig_labels);
my $result = $self->_rrsig_set_labels(my $copy = $lab->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub rrsig_origttl {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrsig_origttl, $self);
}
sub rrsig_set_origttl {
my ($self, $ttl) = shift;
DNS::LDNS::GC::disown(my $old = $self->rrsig_origttl);
my $result = $self->_rrsig_set_origttl(my $copy = $ttl->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub rrsig_signame {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrsig_signame, $self);
}
sub rrsig_set_signame {
my ($self, $name) = shift;
DNS::LDNS::GC::disown(my $old = $self->rrsig_signame);
my $result = $self->_rrsig_set_signame(my $copy = $name->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub dnskey_algorithm {
my $self = shift;
return DNS::LDNS::GC::own($self->_dnskey_algorithm, $self);
}
sub dnskey_set_algorithm {
my ($self, $algo) = shift;
DNS::LDNS::GC::disown(my $old = $self->dnskey_algorithm);
my $result = $self->_dnskey_set_algorithm(my $copy = $algo->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub dnskey_flags {
my $self = shift;
return DNS::LDNS::GC::own($self->_dnskey_flags, $self);
}
sub dnskey_set_flags {
my ($self, $flags) = shift;
DNS::LDNS::GC::disown(my $old = $self->flags);
my $result = $self->_dnskey_set_flags(my $copy = $flags->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub dnskey_protocol {
my $self = shift;
return DNS::LDNS::GC::own($self->_dnskey_protocol, $self);
}
sub dnskey_set_protocol {
my ($self, $proto) = shift;
DNS::LDNS::GC::disown(my $old = $self->dnskey_protocol);
my $result = $self->_dnskey_set_protocol(my $copy = $proto->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub dnskey_key {
my $self = shift;
return DNS::LDNS::GC::own($self->_dnskey_key, $self);
}
sub dnskey_set_key {
my ($self, $key) = shift;
DNS::LDNS::GC::disown(my $old = $self->dnskey_key);
my $result = $self->_dnskey_set_key(my $copy = $key->clone);
DNS::LDNS::GC::own($copy, $self);
return $result;
}
sub nsec3_next_owner {
my $self = shift;
return DNS::LDNS::GC::own($self->_nsec3_next_owner, $self);
}
sub nsec3_bitmap {
my $self = shift;
return DNS::LDNS::GC::own($self->_nsec3_bitmap, $self);
}
sub nsec3_salt {
my $self = shift;
return DNS::LDNS::GC::own($self->_nsec3_salt, $self);
}
sub hash_name_from_nsec3 {
my ($self, $name) = @_;
my $hash = $self->_hash_name_from_nsec3($name);
return DNS::LDNS::GC::own($self->_hash_name_from_nsec3($name), $self);
}
sub verify_denial {
my ($self, $nsecs, $rrsigs) = @_;
my $s = _verify_denial($self, $nsecs, $rrsigs);
$DNS::LDNS::last_status = $s;
return $s;
}
sub verify_denial_nsec3 {
my ($self, $nsecs, $rrsigs, $packet_rcode, $packet_qtype,
$packet_nodata) = @_;
my $s = _verify_denial_nsec3($self, $nsecs, $rrsigs, $packet_rcode,
$packet_qtype, $packet_nodata);
$DNS::LDNS::last_status = $s;
return $s;
}
sub verify_denial_nsec3_match {
my ($self, $nsecs, $rrsigs, $packet_rcode, $packet_qtype,
$packet_nodata) = @_;
my $status;
my $match = _verify_denial_nsec3_match($self, $nsecs, $rrsigs, $packet_rcode, $packet_qtype, $packet_nodata, $status);
$DNS::LDNS::last_status = $status;
if ($status != &LDNS_STATUS_OK) {
return;
}
# $match is an RR owned by the $nsecs list.
return DNS::LDNS::GC::own($match, $nsecs);
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::RR - Resource record
=head1 SYNOPSIS
use DNS::LDNS ':all'
my rr = new DNS::LDNS::RR('mylabel 3600 IN A 168.10.10.10')
my rr = new DNS::LDNS::RR(
str => 'mylabel 3600 IN A 168.10.10.10',
default_ttl => 3600, # optional
origin => $origin_rdata, # optional
prev => \$prev_rdata, # optional
)
my rr = new DNS::LDNS::RR(
filename => '/path/to/rr',
default_ttl => \$ttl, # optional
origin => \$origin_rdata, # optional
prev => \$prev_rdata) # optional
my rr = new DNS::LDNS::RR(
file => \*FILE,
default_ttl => \$ttl, # optional
origin => \$origin_rdata, # optional
prev => \$prev_rdata) # optional
my rr = new DNS::LDNS::RR(
type => LDNS_RR_TYPE_A,
rdata => [new DNS::LDNS::RData(...), new DNS::LDNS::RData(...), ...],
class => LDNS_RR_CLASS_IN, # optional
ttl => 3600, # optional
owner => new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'mylabel'), # optional)
my rr = new DNS::LDNS::RR
rr2 = rr->clone
rr->print(\*FILE)
rr->to_string
ttl = rr->ttl
rr->set_ttl(ttl)
type = rr->type
rr->set_type(type)
class = rr->class
rr->set_class(class)
rdata = rr->owner
rr->set_owner(rdata)
str = rr->dname
count = rr->rd_count
rdata = rr->rdata(index)
rr->set_rdata(rd1, rd2, rd3, ...)
rr->push_rdata(rd1, rd2, rd3, ...)
rdata = rr->pop_rdata
rr->compare(rr2)
rr->compare_dname(rr2)
rr->compare_no_rdata(rr2)
rr->compare_ds(rr2)
hash = rr->hash_name_from_nsec3(dname)
status = rr->verify_denial(nsecs, rrsigs)
status = rr->verify_denial_nsec3(nsecs, rrsigs, packet_rcode, packet_qtype, packet_nodata)
match = rr->verify_denial_nsec3_match(nsecs, rrsigs, packet_rcode, packet_qtype, packet_nodata)
rr->nsec3_add_param_rdfs(algorithm, flags, iterations, salt)
a = rr->nsec3_algorithm
f = rr->nsec3_flags
o = rr->nsec3_optout
i = rr->nsec3_iterations
rdata = rr->nsec3_next_owner
rdata = rr->nsec3_bitmap
rdata = rr->nsec3_salt
rdata = rr->rrsig_keytag
bool = rr->rrsig_set_keytag(rdata)
rdata = rr->rrsig_signame
bool = rr->rrsig_set_signame(rdata)
rdata = rr->rrsig_sig
bool = rr->rrsig_set_sig(rdata)
rdata = rr->rrsig_algorithm
bool = rr->rrsig_set_algorithm(rdata)
rdata = rr->rrsig_inception
bool = rr->rrsig_set_inception(rdata)
rdata = rr->rrsig_expiration
bool = rr->rrsig_set_expiration(rdata)
rdata = rr->rrsig_labels
bool = rr->rrsig_set_labels(rdata)
rdata = rr->rrsig_origttl
bool = rr->rrsig_set_origttl(rdata)
key = rr->get_dnskey_for_rrsig(rrlist)
rdata = rr->dnskey_algorithm
bool = rr->dnskey_set_algorithm(rdata)
rdata = rr->dnskey_flags
bool = rr->dnskey_set_flags(rdata)
rdata = rr->dnskey_protocol
bool = rr->dnskey_set_protocol(rdata)
rdata = rr->dnskey_key
bool = rr->dnskey_set_key(rdata)
bits = rr->dnskey_key_size
tag = rr->calc_keytag
ds = rr->key_to_ds(hash)
rr->is_question
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,183 @@
package DNS::LDNS::RRList;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS;
our $VERSION = '0.61';
sub new {
my ($class, %args) = @_;
if ($args{hosts_filename} or $args{hosts_file}) {
my $file = $args{hosts_file};
if ($args{hosts_filename}) {
unless (open FILE, $args{hosts_filename}) {
$DNS::LDNS::last_status = &LDNS_STATUS_FILE_ERR;
$DNS::LDNS::line_nr = 0;
return;
}
$file = \*FILE;
}
my $list = _new_hosts_from_file($file, $DNS::LDNS::line_nr);
if ($args{hosts_filename}) {
close $file;
}
return $list;
}
return _new();
}
sub rr {
my ($self, $index) = @_;
return DNS::LDNS::GC::own($self->_rr($index), $self);
}
sub push {
my ($self, @rrs) = @_;
for my $rr (@rrs) {
# Push a copy of the rr in case it is already owned
$self->_push(my $copy = $rr->clone);
DNS::LDNS::GC::own($copy, $self);
}
}
sub push_list {
my ($self, $list) = @_;
$self->_push_list(my $copy = $list->clone);
DNS::LDNS::GC::own($copy, $self);
}
sub verify {
my ($self, $sig, $keys) = @_;
my $goodkeys = new DNS::LDNS::RRList;
my $s = _verify($self, $sig, $keys, $goodkeys);
$DNS::LDNS::last_status = $s;
return wantarray ? ($s, $goodkeys) : $s;
}
sub verify_time {
my ($self, $sig, $keys, $checktime) = @_;
my $goodkeys = new DNS::LDNS::RRList;
my $s = _verify_time($self, $sig, $keys, $checktime, $goodkeys);
$DNS::LDNS::last_status = $s;
return wantarray ? ($s, $goodkeys) : $s;
}
sub verify_notime {
my ($self, $sig, $keys) = @_;
my $goodkeys = new DNS::LDNS::RRList;
my $s = _verify_notime($self, $sig, $keys, $goodkeys);
$DNS::LDNS::last_status = $s;
return wantarray ? ($s, $goodkeys) : $s;
}
sub verify_rrsig_keylist {
my ($self, $sig, $keys) = @_;
my $goodkeys = new DNS::LDNS::RRList;
my $s = _verify_rrsig_keylist($self, $sig, $keys, $goodkeys);
$DNS::LDNS::last_status = $s;
return wantarray ? ($s, $goodkeys) : $s;
}
sub verify_rrsig_keylist_notime {
my ($self, $sig, $keys, $check_time) = @_;
my $goodkeys = new DNS::LDNS::RRList;
my $s = _verify_rrsig_keylist_notime($self, $sig, $keys, $goodkeys);
$DNS::LDNS::last_status = $s;
return wantarray ? ($s, $goodkeys) : $s;
}
sub get_dnskey_for_rrsig {
my ($self, $rrsig) = @_;
return DNS::LDNS::GC::own(_get_dnskey_for_rrsig($rrsig, $self), $self);
}
sub get_rrsig_for_name_and_type {
my ($self, $name, $type) = @_;
return DNS::LDNS::GC::own(
_get_dnskey_for_name_and_type($name, $type, $self), $self);
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::RRList - List of rrs
=head1 SYNOPSIS
use DNS::LDNS ':all'
my l = new DNS::LDNS::RRList
my l = new DNS::LDNS::RRList(hosts_file => \*FILE)
my l = new DNS::LDNS::RRList(hosts_filename => fname)
my l2 = l->clone
l->to_string
l->print(\*FILE)
count = l->rr_count
rr = l->rr(index)
l->push(@rr)
rr = l->pop
l->push_list(l2)
l2 = l->pop_list(count)
l2 = l->pop_rrset
l->compare(l2)
l2 = l->subtype_by_rdata(rdata, pos)
bool = l->is_rrset
bool = l->contains_rr(rr)
(status, goodkeys) = l->verify(sig, keys)
(status, goodkeys) = l->verify_time(sig, keys, checktime)
(status, goodkeys) = l->verify_notime(sig, keys)
(status, goodkeys) = l->verify_rrsig_keylist(sig, keys)
(status, goodkeys) = l->verify_rrsig_keylist_time(sig, keys, checktime)
(status, goodkeys) = l->verify_rrsig_keylist_notime(sig, keys)
status = l->verify_rrsig(sig, keys)
status = l->verify_rrsig_time(sig, keys, checktime)
rr = l->create_empty_rrsig(key)
rrlist = l->sign_public(keylist)
rrlist->canonicalize
rrlist->sort
rrlist->sort_nsec3 # the list must contain only nsec3 rrs
rr = keylist->get_dnskey_for_rrsig(rrsig)
rr = keylist->get_rrsig_for_name_and_type(name, type)
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,355 @@
package DNS::LDNS::Resolver;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS ':all';
our $VERSION = '0.61';
sub new {
my ($class, %args) = @_;
my $file;
my $status = &LDNS_STATUS_OK;
if ($args{filename}) {
unless (open FILE, $args{filename}) {
$DNS::LDNS::last_status = &LDNS_STATUS_FILE_ERR;
$DNS::LDNS::line_nr = 0;
return;
}
$file = \*FILE;
}
elsif ($args{file}) {
$file = $args{file};
}
my $resolver;
if ($file) {
$resolver = _new_from_file($file, $status);
}
else {
$resolver = _new();
}
if ($args{filename}) {
close $file;
}
$DNS::LDNS::last_status = $status;
if (!defined $resolver) {
return;
}
return $resolver;
}
sub dnssec_anchors {
my $self = shift;
return DNS::LDNS::GC::own($self->_dnssec_anchors, $self);
}
sub push_dnssec_anchor {
my ($self, $rr) = @_;
_push_dnssec_anchor($self, my $copy = $rr->clone);
DNS::LDNS::GC::own($copy, $self);
}
sub set_dnssec_anchors {
my ($self, $l) = @_;
DNS::LDNS::GC::disown(my $old = $self->dnssec_anchors);
$self->_set_dnssec_anchors($l);
DNS::LDNS::GC::own($l, $self);
return $l;
}
sub domain {
my $self = shift;
return DNS::LDNS::GC::own($self->_domain, $self);
}
sub set_domain {
my ($self, $dom) = @_;
DNS::LDNS::GC::disown(my $old = $self->domain);
_set_domain($self, my $copy = $dom->clone);
DNS::LDNS::GC::own($copy, $self);
}
sub nameservers {
my $self = shift;
my $list = _nameservers($self);
for my $r (@$list) {
DNS::LDNS::GC::own($r, $self);
}
return wantarray ? @$list : $list;
}
sub push_nameserver {
my ($self, $n) = @_;
my $s = _push_nameserver($self, my $copy = $n->clone);
DNS::LDNS::GC::own($copy, $self);
$DNS::LDNS::last_status = $s;
return $s;
}
sub pop_nameserver {
my $self = shift;
return DNS::LDNS::GC::own($self->_pop_nameserver);
}
sub push_searchlist {
my ($self, $rd) = @_;
_push_searchlist($self, my $copy = $rd->clone);
DNS::LDNS::GC::own($copy, $self);
}
sub searchlist {
my $self = shift;
my $list = _searchlist($self);
for my $r (@$list) {
DNS::LDNS::GC::own($r, $self);
}
return wantarray ? @$list : $list;
}
sub timeout {
my $self = shift;
my $t = _timeout($self);
return wantarray ? @$t : $t;
}
sub rtt {
my $self = shift;
my $list = _rtt($self);
return wantarray ? @$list : $list;
}
sub set_rtt {
my ($self, @rtt) = @_;
# FIXME: Validate @rtt, existence, size
_set_rtt($self, \@rtt);
}
sub fetch_valid_domain_keys {
my ($self, $domain, $keys) = @_;
my $status;
my $trusted = _fetch_valid_domain_keys($self, $domain, $keys, $status);
$DNS::LDNS::last_status = $status;
if (!$trusted) {
return;
}
return DNS::LDNS::GC::own($trusted, $self);
}
sub fetch_valid_domain_keys_time {
my ($self, $domain, $keys, $checktime) = @_;
my $status;
my $trusted = _fetch_valid_domain_keys_time(
$self, $domain, $keys, $checktime, $status);
$DNS::LDNS::last_status = $status;
if (!$trusted) {
return;
}
return DNS::LDNS::GC::own($trusted, $self);
}
sub prepare_query_pkt {
my ($self, $rdata, $type, $class, $flags) = @_;
my $s = &LDNS_STATUS_OK;
my $qry = _prepare_query_pkt($self, $rdata, $type, $class, $flags, $s);
$DNS::LDNS::last_status = $s;
if ($s != LDNS_STATUS_OK) {
return;
}
return $qry;
}
sub send {
my ($self, $rdata, $type, $class, $flags) = @_;
my $s = &LDNS_STATUS_OK;
my $ans = _send($self, $rdata, $type, $class, $flags, $s);
$DNS::LDNS::last_status = $s;
if ($s != LDNS_STATUS_OK) {
return;
}
return $ans;
}
sub send_pkt {
my ($self, $qry) = @_;
my $s = &LDNS_STATUS_OK;
my $ans = _send_pkt($self, $qry, $s);
$DNS::LDNS::last_status = $s;
if ($s != LDNS_STATUS_OK) {
return;
}
return $ans;
}
sub verify_trusted {
my ($self, $rrset, $rrsigs, $validating_keys) = @_;
my $s = _verify_trusted($self, $rrset, $rrsigs, $validating_keys);
$DNS::LDNS::last_status = $s;
return $s;
}
sub verify_trusted_time {
my ($self, $rrset, $rrsigs, $check_time, $validating_keys) = @_;
my $s = _verify_trusted_time($self, $rrset, $rrsigs, $check_time,
$validating_keys);
$DNS::LDNS::last_status = $s;
return $s;
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::Resolver - DNS resolver
=head1 SYNOPSIS
use DNS::LDNS ':all'
my r = new DNS::LDNS::Resolver(filename => '/my/resolv.conf')
my r = new DNS::LDNS::Resolver(file => \*FILE)
my r = new DNS::LDNS::Resolver
bool = r->dnssec
r->set_dnssec(bool)
bool = r->dnssec_cd # Resolver sets the CD bit
r->set_dnssec_cd(bool)
port = r->port
r->set_port(port)
bool = r->recursive
r->set_recursive(bool)
bool = r->debug
r->set_debug(bool)
count = r->retry
r->set_retry(count)
count = r->retrans
r->set_retrans(count)
bool = r->fallback # Resolver truncation fallback mechanism
r->set_fallback(bool)
bool = r->ip6
r->set_ip6(bool)
size = r->edns_udp_size
r->set_edns_udp_size(size)
bool = r->usevc # Use virtual circuit (TCP)
r->set_usevc(bool)
r->fail
r->set_fail
r->defnames
r->set_defnames
r->dnsrch
r->set_dnsrch
r->igntc
r->set_igntc
bool = r->random # randomize nameserver before usage
r->set_random(bool)
rrlist = r->dnssec_anchors # list of trusted DNSSEC anchors
r->push_dnssec_anchor(rr)
r->set_dnssec_anchors(rrlist)
rdata = r->domain # Domain to add to relative queries
r->set_domain(rdata)
@rdata = r->nameservers
count = r->nameserver_count
r->push_nameserver(rdata)
rdata = r->pop_nameserver
r->nameservers_randomize
str = r->tsig_keyname
r->set_tsig_keyname(str)
str = r->tsig_algorithm
r->set_tsig_algorithm(str)
str = r->tsig_keydata
r->set_tsig_keydata(str)
count = r->searchlist_count
r->push_searchlist(rdata)
@rdata = r->searchlist
@times = r->rtt # Round trip times
r->set_rtt(@rtt)
time = r->nameserver_rtt(pos)
r->set_nameserver_rtt(pos, time)
(sec, usec) = r->timeout
r->set_timeout(sec, usec)
# DNSSec validation
rrlist = r->fetch_valid_domain_keys(domain, keys)
rrlist = r->fetch_valid_domain_keys_time(domain, keys, checktime)
rrlist = r->validate_domain_ds(domain, keys)
rrlist = r->validate_domain_ds_time(domain, keys, checktime)
rrlist = r->validate_domain_dnskey(domain, keys)
rrlist = r->validate_domain_dnskey_time(domain, keys, checktime)
status = r->verify_trusted(rrset, rrsigs, validation_keys)
status = r->verify_trusted_time(rrset, rrsigs, checktime, validation_keys)
bool = r->trusted_key(keys, trusted_keys)
chain = r->build_data_chain(qflags, dataset, pkt, orig_rr)
# Query
pkt = r->query(rdata, type, class, flags)
pkt = r->search(rdata, type, class, flags)
query = r->prepare_query_pkt(rdata, type, class, flags)
answer = r->send(rdata, type, class, flags)
answer = r->send_pkt(query)
rrlist = r->get_rr_list_addr_by_name(name, class, flags)
rrlist = r->get_rr_list_name_by_addr(addr, class, flags)
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,140 @@
package DNS::LDNS::Zone;
use 5.008008;
use strict;
use warnings;
use DNS::LDNS ':all';
our $VERSION = '0.61';
sub new {
my ($class, %args) = @_;
my $line_nr = 0;
my $status = &LDNS_STATUS_OK;
my $zone;
my $file;
if ($args{filename}) {
unless (open FILE, $args{filename}) {
$DNS::LDNS::last_status = &LDNS_STATUS_FILE_ERR;
$DNS::LDNS::line_nr = 0;
return;
}
$file = \*FILE;
}
elsif ($args{file}) {
$file = $args{file};
}
if ($file) {
$zone = _new_from_file($file,
$args{origin},
$args{default_ttl} || 0,
$args{class} || 0,
$status, $line_nr);
}
else {
$zone = _new();
}
if ($args{filename}) {
close $file;
}
$DNS::LDNS::last_status = $status;
$DNS::LDNS::line_nr = $line_nr;
if (!defined $zone) {
return;
}
return $zone;
}
sub to_string {
my $self = shift;
return join('', map { $self->$_ ? $self->$_->to_string : '' } qw/soa rrs/);
}
sub soa {
my $self = shift;
return DNS::LDNS::GC::own($self->_soa, $self);
}
sub set_soa {
my ($self, $soa) = @_;
DNS::LDNS::GC::disown(my $old = $self->soa);
$self->_set_soa(my $copy = $soa->clone);
return DNS::LDNS::GC::own($copy, $self);
}
sub rrs {
my $self = shift;
return DNS::LDNS::GC::own($self->_rrs, $self);
}
sub set_rrs {
my ($self, $list) = @_;
DNS::LDNS::GC::disown(my $old = $self->rrs);
$self->_set_rrs(my $copy = $list->clone);
return DNS::LDNS::GC::own($copy, $self);
}
sub DESTROY {
DNS::LDNS::GC::free($_[0]);
}
1;
__END__
=head1 NAME
DNS::LDNS::Zone - Parsed zonefile
=head1 SYNOPSIS
use DNS::LDNS ':all'
my z = new DNS::LDNS::Zone(
filename => '/path/to/myzone',
origin => new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'myzone'), #optional
default_ttl => 3600, #optional
class => LDNS_RR_CLASS_IN, #optional
)
my z = new DNS::LDNS::Zone(
file => \*FILE,
origin => ..., default_ttl => ..., class => ...
)
my z = new DNS::LDNS::Zone
z->to_string
z->print(\*FILE)
z->canonicalize
z->sort
rr = z->soa
z->set_soa(rr)
rrlist = z->rrs
z->set_rrs(rrlist)
z->sign(keylist)
z->sign_nsec3(keylist, algorithm, flags, iterations, salt)
=head1 SEE ALSO
http://www.nlnetlabs.nl/projects/ldns
=head1 AUTHOR
Erik Pihl Ostlyngen, E<lt>erik.ostlyngen@uninett.noE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2013 by UNINETT Norid AS
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.14.2 or,
at your option, any later version of Perl 5 you may have available.
=cut

View File

@@ -0,0 +1,136 @@
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl DNS-LDNS.t'
#########################
# change 'tests => 2' to 'tests => last_test_to_print';
use strict;
use warnings;
use Test::More tests => 2;
BEGIN { use_ok('DNS::LDNS') };
my $fail = 0;
foreach my $constname (qw(
LDNS_AA LDNS_AD LDNS_CD LDNS_CERT_ACPKIX LDNS_CERT_IACPKIX
LDNS_CERT_IPGP LDNS_CERT_IPKIX LDNS_CERT_ISPKI LDNS_CERT_OID
LDNS_CERT_PGP LDNS_CERT_PKIX LDNS_CERT_SPKI LDNS_CERT_URI
LDNS_DEFAULT_TTL LDNS_DH LDNS_DSA LDNS_DSA_NSEC3 LDNS_ECC LDNS_ECC_GOST
LDNS_HASH_GOST LDNS_IP4ADDRLEN LDNS_IP6ADDRLEN
LDNS_KEY_REVOKE_KEY LDNS_KEY_SEP_KEY LDNS_KEY_ZONE_KEY
LDNS_MAX_DOMAINLEN LDNS_MAX_LABELLEN LDNS_MAX_PACKETLEN
LDNS_MAX_POINTERS LDNS_MAX_RDFLEN LDNS_NSEC3_VARS_OPTOUT_MASK
LDNS_PACKET_ANSWER LDNS_PACKET_IQUERY LDNS_PACKET_NODATA
LDNS_PACKET_NOTIFY LDNS_PACKET_NXDOMAIN LDNS_PACKET_QUERY
LDNS_PACKET_QUESTION LDNS_PACKET_REFERRAL LDNS_PACKET_STATUS
LDNS_PACKET_UNKNOWN LDNS_PACKET_UPDATE LDNS_PORT LDNS_PRIVATEDNS
LDNS_PRIVATEOID LDNS_QR LDNS_RA LDNS_RCODE_FORMERR LDNS_RCODE_NOERROR
LDNS_RCODE_NOTAUTH LDNS_RCODE_NOTIMPL LDNS_RCODE_NOTZONE
LDNS_RCODE_NXDOMAIN LDNS_RCODE_NXRRSET LDNS_RCODE_REFUSED
LDNS_RCODE_SERVFAIL LDNS_RCODE_YXDOMAIN LDNS_RCODE_YXRRSET LDNS_RD
LDNS_RDATA_FIELD_DESCRIPTORS_COMMON LDNS_RDF_SIZE_16BYTES
LDNS_RDF_SIZE_6BYTES LDNS_RDF_SIZE_BYTE LDNS_RDF_SIZE_DOUBLEWORD
LDNS_RDF_SIZE_WORD LDNS_RDF_TYPE_A LDNS_RDF_TYPE_AAAA LDNS_RDF_TYPE_ALG
LDNS_RDF_TYPE_APL LDNS_RDF_TYPE_ATMA LDNS_RDF_TYPE_B32_EXT
LDNS_RDF_TYPE_B64 LDNS_RDF_TYPE_CERT_ALG LDNS_RDF_TYPE_CLASS
LDNS_RDF_TYPE_DNAME LDNS_RDF_TYPE_HEX LDNS_RDF_TYPE_INT16
LDNS_RDF_TYPE_INT16_DATA LDNS_RDF_TYPE_INT32 LDNS_RDF_TYPE_INT8
LDNS_RDF_TYPE_IPSECKEY LDNS_RDF_TYPE_LOC LDNS_RDF_TYPE_NONE
LDNS_RDF_TYPE_NSAP LDNS_RDF_TYPE_NSEC LDNS_RDF_TYPE_NSEC3_NEXT_OWNER
LDNS_RDF_TYPE_NSEC3_SALT LDNS_RDF_TYPE_PERIOD LDNS_RDF_TYPE_SERVICE
LDNS_RDF_TYPE_STR LDNS_RDF_TYPE_TIME LDNS_RDF_TYPE_HIP
LDNS_RDF_TYPE_TSIGTIME LDNS_RDF_TYPE_TYPE LDNS_RDF_TYPE_UNKNOWN
LDNS_RDF_TYPE_WKS LDNS_RESOLV_ANCHOR LDNS_RESOLV_DEFDOMAIN
LDNS_RESOLV_INET LDNS_RESOLV_INET6 LDNS_RESOLV_INETANY
LDNS_RESOLV_KEYWORD LDNS_RESOLV_KEYWORDS LDNS_RESOLV_NAMESERVER
LDNS_RESOLV_OPTIONS LDNS_RESOLV_RTT_INF LDNS_RESOLV_RTT_MIN
LDNS_RESOLV_SEARCH LDNS_RESOLV_SORTLIST LDNS_RR_CLASS_ANY
LDNS_RR_CLASS_CH LDNS_RR_CLASS_COUNT LDNS_RR_CLASS_FIRST
LDNS_RR_CLASS_HS LDNS_RR_CLASS_IN LDNS_RR_CLASS_LAST LDNS_RR_CLASS_NONE
LDNS_RR_COMPRESS LDNS_RR_NO_COMPRESS LDNS_RR_OVERHEAD LDNS_RR_TYPE_A
LDNS_RR_TYPE_A6 LDNS_RR_TYPE_AAAA LDNS_RR_TYPE_AFSDB LDNS_RR_TYPE_ANY
LDNS_RR_TYPE_APL LDNS_RR_TYPE_ATMA LDNS_RR_TYPE_AXFR LDNS_RR_TYPE_CERT
LDNS_RR_TYPE_CNAME LDNS_RR_TYPE_COUNT LDNS_RR_TYPE_DHCID
LDNS_RR_TYPE_DLV LDNS_RR_TYPE_DNAME LDNS_RR_TYPE_DNSKEY LDNS_RR_TYPE_DS
LDNS_RR_TYPE_EID LDNS_RR_TYPE_FIRST LDNS_RR_TYPE_GID LDNS_RR_TYPE_GPOS
LDNS_RR_TYPE_HINFO LDNS_RR_TYPE_IPSECKEY LDNS_RR_TYPE_ISDN
LDNS_RR_TYPE_IXFR LDNS_RR_TYPE_KEY LDNS_RR_TYPE_KX LDNS_RR_TYPE_LAST
LDNS_RR_TYPE_LOC LDNS_RR_TYPE_MAILA LDNS_RR_TYPE_MAILB LDNS_RR_TYPE_MB
LDNS_RR_TYPE_MD LDNS_RR_TYPE_MF LDNS_RR_TYPE_MG LDNS_RR_TYPE_MINFO
LDNS_RR_TYPE_MR LDNS_RR_TYPE_MX LDNS_RR_TYPE_NAPTR LDNS_RR_TYPE_NIMLOC
LDNS_RR_TYPE_NS LDNS_RR_TYPE_NSAP LDNS_RR_TYPE_NSAP_PTR
LDNS_RR_TYPE_NSEC LDNS_RR_TYPE_NSEC3 LDNS_RR_TYPE_NSEC3PARAM
LDNS_RR_TYPE_NSEC3PARAMS LDNS_RR_TYPE_NULL LDNS_RR_TYPE_NXT
LDNS_RR_TYPE_OPT LDNS_RR_TYPE_PTR LDNS_RR_TYPE_PX LDNS_RR_TYPE_RP
LDNS_RR_TYPE_RRSIG LDNS_RR_TYPE_RT LDNS_RR_TYPE_SIG LDNS_RR_TYPE_SINK
LDNS_RR_TYPE_SOA LDNS_RR_TYPE_SPF LDNS_RR_TYPE_SRV LDNS_RR_TYPE_SSHFP
LDNS_RR_TYPE_TALINK LDNS_RR_TYPE_TSIG LDNS_RR_TYPE_TXT LDNS_RR_TYPE_UID
LDNS_RR_TYPE_UINFO LDNS_RR_TYPE_UNSPEC LDNS_RR_TYPE_WKS
LDNS_RR_TYPE_X25 LDNS_RSAMD5 LDNS_RSASHA1 LDNS_RSASHA1_NSEC3
LDNS_RSASHA256 LDNS_RSASHA512 LDNS_SECTION_ADDITIONAL
LDNS_SECTION_ANSWER LDNS_SECTION_ANY LDNS_SECTION_ANY_NOQUESTION
LDNS_SECTION_AUTHORITY LDNS_SECTION_QUESTION LDNS_SHA1 LDNS_SHA256
LDNS_SIGN_DSA LDNS_SIGN_DSA_NSEC3 LDNS_SIGN_ECC_GOST
LDNS_SIGN_HMACSHA1 LDNS_SIGN_HMACSHA256
LDNS_SIGN_RSAMD5 LDNS_SIGN_RSASHA1 LDNS_SIGN_RSASHA1_NSEC3
LDNS_SIGN_RSASHA256 LDNS_SIGN_RSASHA512 LDNS_STATUS_ADDRESS_ERR
LDNS_STATUS_CERT_BAD_ALGORITHM LDNS_STATUS_CRYPTO_ALGO_NOT_IMPL
LDNS_STATUS_CRYPTO_BOGUS LDNS_STATUS_CRYPTO_EXPIRATION_BEFORE_INCEPTION
LDNS_STATUS_CRYPTO_NO_DNSKEY LDNS_STATUS_CRYPTO_NO_DS
LDNS_STATUS_CRYPTO_NO_MATCHING_KEYTAG_DNSKEY
LDNS_STATUS_CRYPTO_NO_RRSIG LDNS_STATUS_CRYPTO_NO_TRUSTED_DNSKEY
LDNS_STATUS_CRYPTO_NO_TRUSTED_DS LDNS_STATUS_CRYPTO_SIG_EXPIRED
LDNS_STATUS_CRYPTO_SIG_NOT_INCEPTED LDNS_STATUS_CRYPTO_TSIG_BOGUS
LDNS_STATUS_CRYPTO_TSIG_ERR LDNS_STATUS_CRYPTO_TYPE_COVERED_ERR
LDNS_STATUS_CRYPTO_UNKNOWN_ALGO LDNS_STATUS_CRYPTO_VALIDATED
LDNS_STATUS_DDD_OVERFLOW LDNS_STATUS_DNSSEC_EXISTENCE_DENIED
LDNS_STATUS_DNSSEC_NSEC3_ORIGINAL_NOT_FOUND
LDNS_STATUS_DNSSEC_NSEC_RR_NOT_COVERED
LDNS_STATUS_DNSSEC_NSEC_WILDCARD_NOT_COVERED
LDNS_STATUS_DOMAINNAME_OVERFLOW LDNS_STATUS_DOMAINNAME_UNDERFLOW
LDNS_STATUS_EMPTY_LABEL LDNS_STATUS_ENGINE_KEY_NOT_LOADED
LDNS_STATUS_ERR LDNS_STATUS_FILE_ERR LDNS_STATUS_INTERNAL_ERR
LDNS_STATUS_INVALID_B32_EXT LDNS_STATUS_INVALID_B64
LDNS_STATUS_INVALID_HEX LDNS_STATUS_INVALID_INT LDNS_STATUS_INVALID_IP4
LDNS_STATUS_INVALID_IP6 LDNS_STATUS_INVALID_POINTER
LDNS_STATUS_INVALID_STR LDNS_STATUS_INVALID_TIME
LDNS_STATUS_LABEL_OVERFLOW LDNS_STATUS_MEM_ERR
LDNS_STATUS_MISSING_RDATA_FIELDS_KEY
LDNS_STATUS_MISSING_RDATA_FIELDS_RRSIG LDNS_STATUS_NETWORK_ERR
LDNS_STATUS_NOT_IMPL LDNS_STATUS_NO_DATA LDNS_STATUS_NSEC3_ERR
LDNS_STATUS_NULL LDNS_STATUS_OK LDNS_STATUS_PACKET_OVERFLOW
LDNS_STATUS_RES_NO_NS LDNS_STATUS_RES_QUERY LDNS_STATUS_SOCKET_ERROR
LDNS_STATUS_SSL_ERR LDNS_STATUS_SYNTAX_ALG_ERR
LDNS_STATUS_SYNTAX_BAD_ESCAPE LDNS_STATUS_SYNTAX_CLASS_ERR
LDNS_STATUS_SYNTAX_DNAME_ERR LDNS_STATUS_SYNTAX_EMPTY
LDNS_STATUS_SYNTAX_ERR LDNS_STATUS_SYNTAX_INCLUDE
LDNS_STATUS_SYNTAX_INCLUDE_ERR_NOTIMPL
LDNS_STATUS_SYNTAX_INTEGER_OVERFLOW
LDNS_STATUS_SYNTAX_ITERATIONS_OVERFLOW LDNS_STATUS_SYNTAX_KEYWORD_ERR
LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR LDNS_STATUS_SYNTAX_ORIGIN
LDNS_STATUS_SYNTAX_RDATA_ERR LDNS_STATUS_SYNTAX_TTL
LDNS_STATUS_SYNTAX_TTL_ERR LDNS_STATUS_SYNTAX_TYPE_ERR
LDNS_STATUS_SYNTAX_VERSION_ERR LDNS_STATUS_UNKNOWN_INET
LDNS_STATUS_WIRE_INCOMPLETE_ADDITIONAL
LDNS_STATUS_WIRE_INCOMPLETE_ANSWER
LDNS_STATUS_WIRE_INCOMPLETE_AUTHORITY
LDNS_STATUS_WIRE_INCOMPLETE_HEADER LDNS_STATUS_WIRE_INCOMPLETE_QUESTION
LDNS_TC)) {
next if (eval "my \$a = $constname; 1");
if ($@ =~ /^Your vendor has not defined LDNS macro $constname/) {
print "# pass: $@";
} else {
print "# fail: $@";
$fail = 1;
}
}
ok( $fail == 0 , 'Constants' );
#########################
# Insert your test code below, the Test::More module is use()ed here so read
# its man page ( perldoc Test::More ) for help writing this test script.

View File

@@ -0,0 +1,60 @@
use Test::More tests => 10;
use Test::Exception;
use FindBin qw/$Bin/;
use DNS::LDNS ':all';
BEGIN { use_ok('DNS::LDNS') };
# Note: This test makes queries on real internet dns data, and assumes
# that the iis.se domain is signed.
my $r = new DNS::LDNS::Resolver(filename => "/etc/resolv.conf");
$r->set_dnssec(1);
$r->set_random(0);
my $p = $r->query(
new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'iis.se.'),
LDNS_RR_TYPE_SOA, LDNS_RR_CLASS_IN, LDNS_RD);
SKIP: {
skip "Resolver is not dnssec able. Skip this test.", 9 unless ($p->ad);
isa_ok($p, 'DNS::LDNS::Packet');
my $rrset = $p->rr_list_by_type(LDNS_RR_TYPE_SOA, LDNS_SECTION_ANSWER);
ok($rrset->rr_count > 0, 'Got an answer with some content');
my $chain = $r->build_data_chain(LDNS_RD, $rrset, $p, undef);
isa_ok($chain, 'DNS::LDNS::DNSSecDataChain');
isa_ok($chain->parent, 'DNS::LDNS::DNSSecDataChain');
dies_ok {
my $new_rr = new DNS::LDNS::RR(str => 'test.test. 1234 IN A 10.0.0.1');
my $t = $chain->derive_trust_tree($new_rr);
} 'Making a trust tree with foreign rr fails.';
my $rr = $chain->rrset->rr(0);
my $tree = $chain->derive_trust_tree($rr);
isa_ok($tree, 'DNS::LDNS::DNSSecTrustTree');
# Get root keys.
my $root_keys_pk = $r->query(
new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, '.'),
LDNS_RR_TYPE_DNSKEY, LDNS_RR_CLASS_IN, LDNS_RD);
my $root_keys = $root_keys_pk->rr_list_by_type(
LDNS_RR_TYPE_DNSKEY, LDNS_SECTION_ANSWER);
is($tree->contains_keys($root_keys), LDNS_STATUS_OK,
'Root key found in trust chain');
ok($tree->depth > 1, 'The trust tree is more than one node.');
isa_ok($tree->parent(0), 'DNS::LDNS::DNSSecTrustTree');
}

View File

@@ -0,0 +1,35 @@
use Test::More tests => 7;
use FindBin qw/$Bin/;
use DNS::LDNS ':all';
BEGIN { use_ok('DNS::LDNS') };
# Create a new dnssec zone
my $z = new DNS::LDNS::DNSSecZone;
isa_ok($z, 'DNS::LDNS::DNSSecZone', 'Create an empty zone');
# Read a zone from file and create a dnssec zone from it
my $z2 = new DNS::LDNS::Zone(
filename => "$Bin/testdata/myzone.org");
$z->create_from_zone($z2);
my $rrset = $z->find_rrset(
new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'ns1.myzone.org.'),
LDNS_RR_TYPE_A);
is($rrset->rrs->rr->type, LDNS_RR_TYPE_A, 'Found an A record');
is($rrset->rrs->rr->dname, 'ns1.myzone.org.', 'Dname is ns1.myzone.org.');
is($z->add_empty_nonterminals, LDNS_STATUS_OK, 'Add empty non-terminals');
my $klist = new DNS::LDNS::KeyList;
$klist->push(new DNS::LDNS::Key(filename => "$Bin/testdata/key.private"));
$klist->key(0)->set_pubkey_owner(
new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'myzone.org'));
is($z->sign($klist, LDNS_SIGNATURE_REMOVE_ADD_NEW, 0), LDNS_STATUS_OK, 'Sign');
is($z->sign_nsec3($klist, LDNS_SIGNATURE_REMOVE_ADD_NEW, 1, 0, 10, 'ABBA', 0),
LDNS_STATUS_OK, 'Sign nsec3');

View File

@@ -0,0 +1,25 @@
use Test::More tests => 8;
use FindBin qw/$Bin/;
use DNS::LDNS ':all';
BEGIN { use_ok('DNS::LDNS') };
my $key = new DNS::LDNS::Key(filename => "$Bin/testdata/key.private");
ok($key, 'Created new key object from file');
is($key->algorithm, 7, 'Algorithm is NSEC3RSASHA1');
my $now = time;
$key->set_inception($now);
$key->set_expiration($now + 10000);
is($key->inception, $now, 'Inception time');
is($key->expiration, $now + 10000, 'Expiration time');
like($key->to_rr->to_string, qr|3600\s+IN\s+DNSKEY\s+256\s+3\s+7\s+AwEAAfg/ghOkk|, 'Got rr representation of key');
my $klist = new DNS::LDNS::KeyList;
$klist->push($key);
is($klist->count, 1, 'Keylist has one key');
is($$key, ${$klist->key(0)}, 'Key in keylist is the one we pushed');
# FIXME: pop is buggy in ldns 1.6.12, uncomment when this starts working
# is($klist->pop(), $$key, 'Pop key from list');
# is($klist->count, 0, 'No keys left in list');

View File

@@ -0,0 +1,47 @@
use Test::More tests => 18;
use DNS::LDNS ':all';
BEGIN { use_ok('DNS::LDNS') };
# Integer data
my $i = new DNS::LDNS::RData(LDNS_RDF_TYPE_INT32, '1237654');
is($i->to_string, '1237654', 'Integer value rdata');
my $ii = new DNS::LDNS::RData(LDNS_RDF_TYPE_INT32, '1237654X');
is($ii, undef, '1237654X is invalid');
# Period data
my $p1 = new DNS::LDNS::RData(LDNS_RDF_TYPE_PERIOD, '3h3m3s');
is($p1->to_string, sprintf("%d", 3600*3 + 60*3 + 3), 'Normalizing period');
my $pi = new DNS::LDNS::RData(LDNS_RDF_TYPE_PERIOD, '3h3X3s');
is($pi, undef, 'Invalid period value 3h3X3s');
# DNames
my $dn1 = new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'azone.org');
my $dn2 = new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'other.org');
my $dn3 = new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'sub.other.org');
my $dn4 = new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'adder.org');
$dn1->cat($dn2);
is($dn1->to_string, 'azone.org.other.org.', 'Concatenating two domain names');
my $chopped = $dn1->left_chop;
is($chopped->to_string, 'org.other.org.', 'Chop off left domain name label');
ok($dn3->is_subdomain($dn2), 'sub.other.org is subdomain of other.org');
ok(!$dn2->is_subdomain($dn3), 'other.org is not subdomain of sub.other.org');
is($dn3->label_count, 3, 'sub.other.org has 3 labels');
is($dn3->label(1)->to_string, 'other.', 'label 1 of sub.other.org is other.');
my $dni = new DNS::LDNS::RData(
LDNS_RDF_TYPE_DNAME, 'not..valid.org');
is($dni, undef, 'Invalid dname not_valid.org');
my $wc = new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, '*.other.org');
ok($wc->is_wildcard, '*.other.org is a wildcard');
ok(!$dn3->is_wildcard, 'sub.other.org is not a wildcard');
ok($dn3->matches_wildcard($wc), 'sub.other.org matches *.other.org');
ok(!$dn4->matches_wildcard($wc), 'adder.org does not match *.other.org');
is($dn3->compare($dn4), 1, 'sub.other.org > adder.org');
is($dn4->compare($dn3), -1, 'adder.org < sub.other.org');

View File

@@ -0,0 +1,23 @@
use Test::More tests => 3;
use FindBin qw/$Bin/;
use DNS::LDNS ':all';
BEGIN { use_ok('DNS::LDNS') };
my $r = new DNS::LDNS::Resolver(filename => "/etc/resolv.conf");
$r->set_random(0);
my $p = $r->query(
new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'org'),
LDNS_RR_TYPE_SOA, LDNS_RR_CLASS_IN, LDNS_RD);
isa_ok($p, 'DNS::LDNS::Packet', 'Make a simple query');
my $r2 = new DNS::LDNS::Resolver(filename => "$Bin/testdata/resolv.conf");
$r2->set_rtt(2, 3);
my @rtt = $r2->rtt;
is_deeply(\@rtt, [2, 3], "set_rtt and rtt");

View File

@@ -0,0 +1,74 @@
use Test::More tests => 19;
use FindBin qw/$Bin/;
use DNS::LDNS ':all';
BEGIN { use_ok('DNS::LDNS') };
my $rr1 = new DNS::LDNS::RR;
isa_ok($rr1, 'DNS::LDNS::RR', 'Create empty rr');
$rr1 = new DNS::LDNS::RR(
type => LDNS_RR_TYPE_SOA,
class => LDNS_RR_CLASS_CH,
ttl => 1234,
owner => 'myzone.org',
rdata => [
new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'hostmaster.myzone.org'),
new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'master.myzone.org'),
new DNS::LDNS::RData(LDNS_RDF_TYPE_INT32, '2012113030'),
new DNS::LDNS::RData(LDNS_RDF_TYPE_PERIOD, '12345'),
new DNS::LDNS::RData(LDNS_RDF_TYPE_PERIOD, '1827'),
new DNS::LDNS::RData(LDNS_RDF_TYPE_PERIOD, '2345678'),
new DNS::LDNS::RData(LDNS_RDF_TYPE_PERIOD, '87654')
],
);
isa_ok($rr1, 'DNS::LDNS::RR', 'Create SOA rr with rdata');
like($rr1->to_string, qr/^myzone\.org\.\s+1234\s+CH\s+SOA\s+hostmaster\.myzone\.org\.\s+master\.myzone\.org\.\s+2012113030\s+12345\s+1827\s+2345678\s+87654$/,
'Format SOA rr as string');
is($rr1->pop_rdata->to_string, '87654', 'pop rdata');
$rr1->push_rdata(new DNS::LDNS::RData(LDNS_RDF_TYPE_PERIOD, '55667'));
is($rr1->rdata(6)->to_string, '55667', 'push_rdata and access rdata by index');
my $rr2 = new DNS::LDNS::RR(str => 'myzone.org. 1234 IN SOA hostmaster.myzone.org. master.myzone.org. 2012 12345 1827 2345678 87654');
isa_ok($rr2, 'DNS::LDNS::RR', 'Create SOA rr from string');
like($rr2->to_string, qr/^myzone\.org\.\s+1234\s+IN\s+SOA\s+hostmaster\.myzone\.org\.\s+master\.myzone\.org\.\s+2012\s+12345\s+1827\s+2345678\s+87654$/,
'Format it back to string');
ok($rr1->compare($rr2) > 0, 'Compare rr, greater than');
ok($rr2->compare($rr1) < 0, 'Compare rr, less than');
is($rr1->compare($rr1), 0, 'Compare rr, equal');
my $rr3 = new DNS::LDNS::RR(str => 'ozone.org. 1234 IN SOA hostmaster.ozone.org. master.ozone.org. 2012 12345 1827 2345678 87654');
ok($rr3->compare_dname($rr1) > 0, 'Compare dname, greater than');
ok($rr1->compare_dname($rr3) < 0, 'Compare dname, less than');
is($rr1->compare_dname($rr2), 0, 'Compare dname, equal');
# Read records from a zonefile
my $origin = new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, '.');
my $prev = $origin->clone;
my $ttl = 0;
my $count = 0;
open(ZONE, "$Bin/testdata/myzone.org");
my $rr4 = new DNS::LDNS::RR(file => \*ZONE, default_ttl => \$ttl,
origin => \$origin, prev => \$prev);
is($DNS::LDNS::last_status, LDNS_STATUS_SYNTAX_TTL, "Read ttl statement.");
is($ttl, 4500, "TTL is 4500");
$rr4 = new DNS::LDNS::RR(file => \*ZONE, default_ttl => \$ttl,
origin => \$origin, prev => \$prev);
is($DNS::LDNS::last_status, LDNS_STATUS_SYNTAX_ORIGIN, "Read origin statement.");
is($origin->to_string, "myzone.org.", "Origin is myzone.org.");
while (!eof(\*ZONE)) {
$rr4 = new DNS::LDNS::RR(file => \*ZONE, default_ttl => \$ttl,
origin => \$origin, prev => \$prev);
last unless ($rr4);
$count++;
}
is($count, 6);

View File

@@ -0,0 +1,84 @@
use Test::More tests => 24;
use FindBin qw/$Bin/;
use DNS::LDNS ':all';
BEGIN { use_ok('DNS::LDNS') };
# Create list
my $list = new DNS::LDNS::RRList;
isa_ok($list, 'DNS::LDNS::RRList', 'Create an empty rr list');
# Push/pop/count rr
$list->push(new DNS::LDNS::RR(str => 'ns.myzone.org 3600 IN AAAA ::1'));
is($list->rr_count, 1, 'Added one rr');
like($list->rr(0)->to_string, qr/^ns\.myzone\.org\.\s+3600\s+IN\s+AAAA\s+::1$/, 'Added rr is at position 0');
$list->push(new DNS::LDNS::RR(str => 'ns.myzone.org 7200 IN A 192.168.100.2'));
is($list->rr_count, 2, 'Added another rr');
like($list->rr(1)->to_string, qr/^ns\.myzone\.org\.\s+7200\s+IN\s+A\s+192\.168\.100\.2$/, 'Last added rr is at position 1');
like($list->pop->to_string, qr/^ns\.myzone\.org\.\s+7200\s+IN\s+A\s+192\.168\.100\.2$/, 'pop the last element');
is($list->rr_count, 1, '1 element left in the list');
# Push/pop list
my $l2 = new DNS::LDNS::RRList;
$l2->push(new DNS::LDNS::RR(str => 'ns2.myzone.org 3600 IN A 192.168.100.0'));
$l2->push(new DNS::LDNS::RR(str => 'ns2.myzone.org 3600 IN A 192.168.100.1'));
$list->push_list($l2);
is($list->rr_count, 3, 'Pushed two elements. List count is now 3.');
$list->push_list($l2);
$list->push_list($l2);
my $l3 = $list->pop_list(1);
is($list->rr_count, 6, 'Pushed 4 elements, popped 1, count is now 6');
is($l3->rr_count, 1, 'Popped list contains 1 elements');
$l3 = $list->pop_list(3);
is($list->rr_count, 3, 'Popped 3 elements, count is now 3');
is($l3->rr_count, 3, 'Popped list contains 3 elements');
# RRSets
ok($l2->is_rrset, 'List is rrset');
ok(!$list->is_rrset, 'List is no longer an rrset');
my $rrset = $list->pop_rrset;
ok($rrset->is_rrset, 'Popped list is rrset');
is($rrset->rr_count, 2, 'Popped rrset has two elements.');
# Compare, contains, subtype
my $rr = new DNS::LDNS::RR(str => 'ns2.myzone.org 3600 IN A 192.168.100.0');
ok($rrset->contains_rr($rr), 'RRSet contains rr '.$rr->to_string);
is($list->compare($l2), -1, '$list < $l2');
is($l2->compare($list), 1, '$l2 > $list');
$list->push(new DNS::LDNS::RR(str => 'ns3.myzone.org 3600 IN A 192.168.100.0'),
new DNS::LDNS::RR(str => 'ns3.myzone.org 3600 IN A 192.168.100.1'),
new DNS::LDNS::RR(str => 'ns4.myzone.org 3600 IN A 192.168.100.1'));
my $subtype = $list->subtype_by_rdata(
new DNS::LDNS::RData(LDNS_RDF_TYPE_A, '192.168.100.1'), 0);
is($subtype->to_string, "ns3.myzone.org.\t3600\tIN\tA\t192.168.100.1\nns4.myzone.org.\t3600\tIN\tA\t192.168.100.1\n", 'Filter rrs by rdata');
# DNSSec signature verification
my $keylist = new DNS::LDNS::RRList;
$keylist->push(
new DNS::LDNS::RR(str => 'trondheim.no. 3600 IN DNSKEY 256 3 8 AwEAAZIDdRI8I+F/J6OT8xX7CbGQYRr8rWH9dvloUlRJXcEVE2pRAez6 pJC5Odg+i2WvDUeE4tUO1gwwjU83TIinZxxsDnqr7FzvqpHeJbVd2N3d S4zaJcbjSnwMqdebmTEXSrflp8DeIAH0GQGNQjhOPubbb/nADYP2RS1i CoOADa8P'),
new DNS::LDNS::RR(str => 'trondheim.no. 3600 IN DNSKEY 257 3 8 AwEAAax9EgKyRsMpU2B0E2dZ+nkWnmZHjlBO3uXBI+2x33dG8bk+XSqr kyWTelhhsqLqIxsaYSwYgzLtn+/qzlFjKwcaU95p+Tp95MOVXYqUtRyC VyLGkzA7ZDbx7TFCi3PyLDM/Arx+DvOx6nNvA/erqIU5gYEo9Nm1KXEy rhfSn3xc96p1AOhmTuSo6EfYlPY4gxHDgJdHFv7Fi9zV6VFmJ29h0rsG 5g3pV1lvCcGcxfRLJ1u7JRw2BWMo9lgHzGuypEVV7iLnvbfDlXhF+jAS owR2JxlESC3dOgNiNWvc4pbyVXBXpP6h/5JpcxkzF7BNJMZiLN14qvam G1+LuZM8qfc=')
);
my $soalist = new DNS::LDNS::RRList;
$soalist->push(
new DNS::LDNS::RR(str => 'trondheim.no. 3600 IN SOA charm.norid.no. hostmaster.norid.no. 2013021137 14400 1800 2419200 3600')
);
my $siglist = new DNS::LDNS::RRList;
$siglist->push(
new DNS::LDNS::RR(str => 'trondheim.no. 3600 IN RRSIG SOA 8 2 3600 20130227105101 20130213090318 36381 trondheim.no. NbeN8E4pvQSDk3Dn0i8B4e2A3KAY8JrX+zcJazPTgHbT6wjzCncn3ANn 6rs+HdcCLtptyX1QbzlZD/lOY8kjJw5TEUoFX2Q/2sBYdt1aT6qgt/+H o71iUz3bk1V73zjSG/OpqG0oXmjCWSBZgzK6UI+zGlgG0Kvrc7H1pw5S ZBA=')
);
my ($status, $goodkeys) = $soalist->verify_notime($siglist, $keylist);
is ($status, LDNS_STATUS_OK, 'Verification returned status ok.');
is ($goodkeys->rr_count, 1, 'One key matched the signature.');
my $klist = new DNS::LDNS::KeyList;
$klist->push(new DNS::LDNS::Key(filename => "$Bin/testdata/key.private"));
$klist->key(0)->set_pubkey_owner(
new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'myzone.org'));
my $sigs = $l2->sign_public($klist);
is($sigs->rr_count, 1, 'Sign public, got 1 rrsig');

View File

@@ -0,0 +1,13 @@
Private-key-format: v1.2
Algorithm: 7 (NSEC3RSASHA1)
Modulus: +D+CE6ST+vFtbnXLdNESSprWSpbpRqEyri20vOx/JIViYdflGQyT0SDWSAE0JqtRlq73qSTDNuR3KWG/57oQQQ5P/wdQaF4TXA/nGjQJPEnhwKVUPVl5WRvqJLpW3C5xSSkhUkwjCp8y6z4NkbX0x7kum9ZTyTai6hkAhjyXu56yXAHX80DWadGK7RmX4JNlJalp2O33hJmakw8BVpgM9yaN4TixVsmZyHLi4hLjMAsjkEEJnfV8WoMEyyjs4kdKDHQAIa854loRcOluT1FiBKgecVAjDu/mkxnqYedN68Yx/wi7D+eClGf/gZjsmuoKKxCxnvDkRCKxrdMJtrsduw==
PublicExponent: AQAB
PrivateExponent: A8m0SmhweZvFd7IEcLvf85N5QZob5SAAjffUki1poz0Fy0hoDoHKn55IpsCd8xkaHZp93O7aq7PAvbjoHLkSFmwJfHK4H1+QHA+CDzxMB8d40l+zcVw0Jc/vOrA9Mw7iW6NtBrxyrG7RcBV6T4bfPUzuESKsFJ3oznmjMGksR4iUrnYAoUgi1pCQlxhSkPM74YhNWbUxYr4gRlL2xGGcJ2qMM8KG06or/Ok+d4bxnxiDBo41THik8ptfu/DL3HrJLOJ1CrvZGy9Q3uFiCvfD9Sk+eOZz1XPkJrUDKGYGoUvZc8enStXSM+TKd3EQy5owjJt+j2h0JdYJM8pxF2EWwQ==
Prime1: /5r4e+6kJS/+UJ0DMenJGm0vxfgFHvk5yLfz+1sKd6C9qQJN5da1m6kWuPdtBG7XGhZb8cJPOfK//g9hVS9GYEDyYmhYZsPTL+1vkiecDpeEQkrf4RCtU7NXLNT/AVNe01iEnIGuKbva6z19P1hjNO23d7LXHil1oULM1W8O1Z8=
Prime2: +KGhJOe+dB5Ud9cFlspMIIpZKHvoDc8VUb2avnhicDX5YC8dVS3nBoyc1cBNgxi4nSvBSl8/fwNT1cHJsPj7Xp2FOAsIBITRnmQt2P5JDpTEuMkEjMT8h/gJ8WnJ0+/VQhLG6rfsSAXdXvVhP4VYttPdiQ0fAe8b5v2MH1VzamU=
Exponent1: UWCEVeifR9ukywOCHeUBirFScWPKNZdBR18RhWfxyC5b07ARHuihvyIxQsg7ZBrpzrtpoGmtkZRwfbFl2poHfOOQh7YS1vzngq3ERLLpo1en2vc9mckWdbx2N6bEXSau3Pikl7NNwKm3RAe6lW1NgG9iZvCAPnESqzm6PwVxop8=
Exponent2: FMsnt/dttTZoKBGilQbcMQiBBmK+eJEuHkT2MSHOUcYh0gp+sIYDQUf3QeUwVlt17ScgpkCrBctYcpMfdB6On04bOyGpDP+yrEWClBhIMeD9RtsA92juGc0Dv93yFDiFpF3/pte0+h0Lc4qgFHjpf3jemTywsC+4LKxd0K0L1wU=
Coefficient: klnXksRr0Z8HPLASytPt4EeBK3Md7MM+Ihm6DIM5PA/KO9k0s8231hspcxBDj37HYwJ7eD77svUJFzdUOqIT8gChc6uq9VI9NFggs8rn4EndoEe+zU477NpL4U09LMfbAN+NATkhDWabVIQBeGqpIAR0fxFIqGhDtkiLyNqhq3c=
Created: 20120614100023
Publish: 20120614100023
Activate: 20120614100023

View File

@@ -0,0 +1,17 @@
$TTL 4500
$ORIGIN myzone.org.
myzone.org. 1000 IN SOA (
ldns.myzone.org.
ns.ldns.myzone.org.
2012113030
12345
1827
2345678
87654 )
ns.ldns A 192.168.100.2
ns2 5600 IN AAAA 2001:dead:dead::2
ns2 6600 IN A 192.168.100.7
ns1 3600 IN A 192.168.100.2
ns1 4600 IN AAAA 2001:dead:dead::1

View File

@@ -0,0 +1,3 @@
nameserver 127.0.0.1
nameserver 192.168.100.1
search foo.bar.org

View File

@@ -0,0 +1,75 @@
use Test::More tests => 16;
use FindBin qw/$Bin/;
use DNS::LDNS ':all';
BEGIN { use_ok('DNS::LDNS') };
# Create a new zone
my $z = new DNS::LDNS::Zone;
isa_ok($z, 'DNS::LDNS::Zone', 'Create an empty zone');
# Fill inn a soa and some rrs
$z->set_soa(new DNS::LDNS::RR(str => join(' ', qw/myzone.org 1000 IN SOA
hostmaster.myzone.org. master.myzone.org. 2012113030 12345 1827 2345678
87654/)));
is($z->soa->dname, 'myzone.org.', 'Found soa record');
my $rrs = new DNS::LDNS::RRList;
$rrs->push(new DNS::LDNS::RR(str => 'ns2.myzone.org 3600 IN A 192.168.100.2'),
new DNS::LDNS::RR(str => 'ns2.myzone.org 3600 IN A 192.168.100.9'),
new DNS::LDNS::RR(str => 'ns3.myzone.org 3600 IN A 192.168.100.2'),
new DNS::LDNS::RR(str => 'ns1.myzone.org 3600 IN A 192.168.100.7'));
$z->set_rrs($rrs);
is($z->rrs->rr(0)->to_string, "ns2.myzone.org.\t3600\tIN\tA\t192.168.100.2\n",
'Check first rr');
is($z->rrs->rr(3)->to_string, "ns1.myzone.org.\t3600\tIN\tA\t192.168.100.7\n",
'Check last rr');
$z->sort;
is($z->rrs->rr(0)->to_string, "ns1.myzone.org.\t3600\tIN\tA\t192.168.100.7\n",
'Check first rr after sorting');
is($z->rrs->rr(3)->to_string, "ns3.myzone.org.\t3600\tIN\tA\t192.168.100.2\n",
'Check last rr after sorting');
# Read a zone from file
my $z2 = new DNS::LDNS::Zone(
filename => "$Bin/testdata/myzone.org", ttl => 100);
$z2->canonicalize;
like($z2->to_string, qr/\nns.ldns.myzone.org.\s+/, 'Canonicalize');
like($z2->to_string, qr/^myzone.org.\s+1000\s+IN\s+SOA\s+ldns.myzone.org.\s+ns.ldns.myzone.org.\s+2012113030\s+12345\s+1827\s+2345678\s+87654\s+/, 'Found soa rec');
like($z2->to_string, qr/ns.ldns.myzone.org.\s+4500\s+IN\s+A\s+192.168.100.2/, 'Found ns rec');
like($z2->to_string, qr/ns2.myzone.org.\s+5600\s+IN\s+AAAA\s+2001:dead:dead::2/, 'Found yet another ns rec');
is($z2->rrs->rr_count, 5, 'Zone has 5 rrs');
my $klist = new DNS::LDNS::KeyList;
$klist->push(new DNS::LDNS::Key(filename => "$Bin/testdata/key.private"));
$klist->key(0)->set_pubkey_owner(
new DNS::LDNS::RData(LDNS_RDF_TYPE_DNAME, 'myzone.org'));
my $z3 = $z2->sign($klist);
my $sigc = grep { $z3->rrs->rr($_)->type == LDNS_RR_TYPE_RRSIG }
(0 .. $z3->rrs->rr_count - 1);
is($sigc, 10, 'Signed zone has 10 signatures');
my $nsecc = grep { $z3->rrs->rr($_)->type == LDNS_RR_TYPE_NSEC }
(0 .. $z3->rrs->rr_count - 1);
is($nsecc, 4, 'Signed zone has 3 nsec recs');
my $z4 = $z2->sign_nsec3($klist, 1, 0, 2, 'ABC');
my $sigc3 = grep { $z4->rrs->rr($_)->type == LDNS_RR_TYPE_RRSIG }
(0 .. $z4->rrs->rr_count - 1);
is($sigc3, 12, 'NSEC3-signed zone has 12 signatures');
my $nsecc3 = grep { $z4->rrs->rr($_)->type == LDNS_RR_TYPE_NSEC3 }
(0 .. $z4->rrs->rr_count - 1);
is($nsecc3, 5, 'NSEC3-signed zone has 5 nsec recs');

View File

@@ -0,0 +1,71 @@
TYPEMAP
DNS__LDNS__Zone LDNS_GENERIC_STRUCT
DNS__LDNS__RRList LDNS_GENERIC_STRUCT
DNS__LDNS__RR LDNS_GENERIC_STRUCT
DNS__LDNS__RData LDNS_GENERIC_STRUCT
DNS__LDNS__DNSSecZone LDNS_GENERIC_STRUCT
DNS__LDNS__DNSSecRRSets LDNS_GENERIC_STRUCT
DNS__LDNS__DNSSecRRs LDNS_GENERIC_STRUCT
DNS__LDNS__DNSSecName LDNS_GENERIC_STRUCT
DNS__LDNS__RBTree LDNS_GENERIC_STRUCT
DNS__LDNS__RBNode LDNS_GENERIC_STRUCT
DNS__LDNS__Resolver LDNS_GENERIC_STRUCT
DNS__LDNS__Packet LDNS_GENERIC_STRUCT
DNS__LDNS__Key LDNS_GENERIC_STRUCT
DNS__LDNS__KeyList LDNS_GENERIC_STRUCT
DNS__LDNS__DNSSecDataChain LDNS_GENERIC_STRUCT
DNS__LDNS__DNSSecTrustTree LDNS_GENERIC_STRUCT
Mortal_PV Mortal_PV
DNS__LDNS__RR__Opt LDNS_GENERIC_STRUCT_OPT
DNS__LDNS__RData__Opt LDNS_GENERIC_STRUCT_OPT
LDNS_Pkt_Opcode T_ENUM
LDNS_Pkt_Rcode T_ENUM
LDNS_Pkt_Section T_ENUM
LDNS_Pkt_Type T_ENUM
LDNS_RR_Type T_ENUM
LDNS_RR_Class T_ENUM
LDNS_RDF_Type T_ENUM
LDNS_Hash T_ENUM
LDNS_Status T_ENUM
LDNS_Signing_Algorithm T_ENUM
uint32_t T_UV
uint16_t T_UV
uint8_t T_UV
signed char T_UV
INPUT
LDNS_GENERIC_STRUCT_OPT
if (!SvOK($arg)) {
$var = NULL;
}
else if (sv_derived_from($arg, \"${(my $ntt=$ntype)=~s/__/::/g;$ntt=~s/::Opt$//;\$ntt}\")){
IV tmp = SvIV((SV*)SvRV($arg));
$var = INT2PTR($type, tmp);
}
else
croak(\"$var is not of type ${(my $ntt=$ntype)=~s/__/::/g;$ntt=~s/::Opt$//;\$ntt}\")
INPUT
LDNS_GENERIC_STRUCT
if (sv_derived_from($arg, \"${(my $ntt=$ntype)=~s/__/::/g;\$ntt}\")){
IV tmp = SvIV((SV*)SvRV($arg));
$var = INT2PTR($type, tmp);
}
else
croak(\"$var is not of type ${(my $ntt=$ntype)=~s/__/::/g;\$ntt}\")
OUTPUT
LDNS_GENERIC_STRUCT
sv_setref_pv($arg, \"${(my $ntt=$ntype)=~s/__/::/g;\$ntt}\", (void*)$var);
OUTPUT
LDNS_GENERIC_STRUCT_OPT
sv_setref_pv($arg, \"${(my $ntt=$ntype)=~s/__/::/g;$ntt=~s/::Opt$//;\$ntt}\", (void*)$var);
OUTPUT
Mortal_PV
sv_setsv($arg, sv_2mortal(newSVpv($var, 0)));
free((void *)$var);

View File

@@ -0,0 +1,10 @@
NETLDNS is a functionality port of NLnet Labs' LDNS to the .NET
2.0 framework, contributed by Alex Nicoll of the Carnegie Mellon
University Software Engineering Institute. NETLDNS is released
under the BSD license. NETLDNS uses Mihnea Radulescu's BigInteger
Library (http://www.codeproject.com/KB/cs/BigInteger_Library.aspx)
from CodeProject to help with key manipulation. Please contact Alex at
anicoll@cert.org with inquiries or requests for newer versions.
This project is not supported by NLnet Labs.

Binary file not shown.

View File

@@ -0,0 +1,50 @@
#!/bin/ksh
#
# $Id$
PREFIX=/opt/ldns
OPENSSL=/usr/sfw
SUDO=sudo
MAKE_PROGRAM=gmake
MAKE_ARGS="-j 4"
OBJ32=obj32
OBJ64=obj64
SRCDIR=`pwd`
test -d $OBJ32 && $SUDO rm -fr $OBJ32
mkdir $OBJ32
export CFLAGS=""
export LDFLAGS="-L${OPENSSL}/lib -R${OPENSSL}/lib"
(cd $OBJ32; \
${SRCDIR}/configure --with-ssl=${OPENSSL} --prefix=${PREFIX} --libdir=${PREFIX}/lib; \
$MAKE_PROGRAM $MAKE_ARGS)
if [ `isainfo -k` = amd64 ]; then
test -d $OBJ64 && $SUDO rm -fr $OBJ64
mkdir $OBJ64
export CFLAGS="-m64"
export LDFLAGS="-L${OPENSSL}/lib/amd64 -R${OPENSSL}/lib/amd64"
(cd $OBJ64; \
${SRCDIR}/configure --with-ssl=${OPENSSL} --prefix=${PREFIX} --libdir=${PREFIX}/lib/amd64; \
$MAKE_PROGRAM $MAKE_ARGS)
fi
# optionally install
#
if [ x$1 = xinstall ]; then
(cd $OBJ32; $SUDO $MAKE_PROGRAM install-h)
(cd $OBJ32; $SUDO $MAKE_PROGRAM install-doc)
(cd $OBJ32; $SUDO $MAKE_PROGRAM install-lib)
if [ `isainfo -k` = amd64 ]; then
(cd $OBJ64; $SUDO $MAKE_PROGRAM install-lib)
fi
fi

View File

@@ -0,0 +1,28 @@
Copyright (c) 2011, Xelerance
Author: Christopher Olah <chris@xelerance.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* 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.
* Neither the name of Xelerance nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.

View File

@@ -0,0 +1,89 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/ldnsx.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/ldnsx.qhc"
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
"run these through (pdf)latex."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."

View File

@@ -0,0 +1,36 @@
LDNSX: Easy DNS (including DNSSEC) via ldns.
ldns is a great library. It is a powerful tool for
working with DNS. python-ldns it is a straight up clone of the C
interface, however that is not a very good interface for python. Its
documentation is incomplete and some functions don't work as
described. And some objects don't have a full python API.
ldnsx aims to fix this. It wraps around the ldns python bindings,
working around its limitations and providing a well-documented, more
pythonistic interface.
Written by Christopher Olah <chris@xelerance.com>
Examples
========
Query the default resolver for google.com's A records. Print the response
packet.
>>> import ldnsx
>>> resolver = ldnsx.resolver()
>>> print resolver.query("google.com","A")
Print the NS records for com. from f.root-servers.net if we get a
response, else an error message.
>>> import ldnsx
>>> pkt = ldnsx.resolver("f.root-servers.net").query("com.","NS")
>>> if pkt:
>>> for rr in pkt.answer():
>>> print rr
>>> else:
>>> print "response not received"

View File

@@ -0,0 +1,30 @@
#!/usr/bin/python
# vim:fileencoding=utf-8
#
# AXFR client with IDN (Internationalized Domain Names) support
#
import ldns
import encodings.idna
def utf2name(name):
return '.'.join([encodings.idna.ToASCII(a) for a in name.split('.')])
def name2utf(name):
return '.'.join([encodings.idna.ToUnicode(a) for a in name.split('.')])
resolver = ldnsx.resolver("zone.nic.cz")
#Print results
for rr in resolver.AXFR(utf2name(u"háčkyčárky.cz")):
# rdf = rr.owner()
# if (rdf.get_type() == ldns.LDNS_RDF_TYPE_DNAME):
# print "RDF owner: type=",rr.type(),"data=",name2utf(rr.owner())
# else:
# print "RDF owner: type=",rdf.get_type_str(),"data=",str(rdf)
# print " RR type=", rr.get_type_str()," ttl=",rr.ttl()
# for rdf in rr.rdfs():
# if (rdf.get_type() == ldns.LDNS_RDF_TYPE_DNAME):
# print " RDF: type=",rdf.get_type_str(),"data=",name2utf(str(rdf))
# else:
# print " RDF: type=",rdf.get_type_str(),"data=",str(rdf)

View File

@@ -0,0 +1,39 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import ldnsx
import sys
debug = True
if len(sys.argv) < 2:
print "Usage:", sys.argv[0], "domain [resolver_addr]"
sys.exit(1)
name = sys.argv[1]
# Create resolver
resolver = ldnsx.resolver(dnssec=True)
# Custom resolver
if len(sys.argv) > 2:
# Clear previous nameservers
resolver.set_nameservers(sys.argv[2:])
# Resolve DNS name
pkt = resolver.query(name, "A")
if pkt and pkt.answer():
# Debug
if debug:
print "NS returned:", pkt.rcode(), "(AA: %d AD: %d)" % ( "AA" in pkt.flags(), "AD" in pkt.flags() )
# SERVFAIL indicated bogus name
if pkt.rcode() == "SERVFAIL":
print name, "failed to resolve"
# Check AD (Authenticated) bit
if pkt.rcode() == "NOERROR":
if "AD" in pkt.flags(): print name, "is secure"
else: print name, "is insecure"

View File

@@ -0,0 +1,11 @@
import ldnsx
resolver = ldnsx.resolver()
pkt = resolver.query("nic.cz", "MX")
if (pkt):
mx = pkt.answer()
if (mx):
mx.sort()
print mx

View File

@@ -0,0 +1,17 @@
#!/usr/bin/python
#
# MX is a small program that prints out the mx records for a particular domain
#
import ldnsx
resolver = ldnsx.resolver()
pkt = resolver.query("nic.cz", "MX")
if pkt:
for rr in pkt.answer(rr_type = "MX"):
rdf = rr.owner()
print rr
#Could also do:
#print rr[0], rr[1], rr[2], rr[3], " ".join(rr[4:])
#print rr.owner(), rr.ttl(), rr.rr_clas(), rr.rr_type(), " ".join(rr[4:])

View File

@@ -0,0 +1,25 @@
#!/usr/bin/python
# vim:fileencoding=utf-8
#
# Walk a domain that's using NSEC and print in zonefile format.
import sys
import ldnsx
def walk(domain):
res = ldnsx.resolver("193.110.157.136", dnssec=True)
pkt = res.query(domain, 666)
try:
nsec_rr = pkt.authority(rr_type="NSEC")[0]
except:
print "no NSEC found, domain is not signed or using NSEC3"
sys.exit()
for rr_type in nsec_rr[5].split(' ')[:-1]:
for rr in ldnsx.get_rrs(domain, rr_type):
print str(rr)[:-1]
next_rec = nsec_rr[4]
if (next_rec != domain) and (next_rec[-len(domain):] == domain):
walk(next_rec)
walk("xelerance.com")

View File

@@ -0,0 +1,921 @@
# Copyright (C) Xelerance Corp. <http://www.xelerance.com/>.
# Author: Christopher Olah <colah@xelerance.com>
# License: BSD
""" Easy DNS (including DNSSEC) via ldns.
ldns is a great library. It is a powerful tool for
working with DNS. python-ldns it is a straight up clone of the C
interface, however that is not a very good interface for python. Its
documentation is incomplete and some functions don't work as
described. And some objects don't have a full python API.
ldnsx aims to fix this. It wraps around the ldns python bindings,
working around its limitations and providing a well-documented, more
pythonistic interface.
**WARNING:**
**API subject to change.** No backwards compatibility guarantee. Write software using this version at your own risk!
Examples
--------
Query the default resolver for google.com's A records. Print the response
packet.
>>> import ldnsx
>>> resolver = ldnsx.resolver()
>>> print resolver.query("google.com","A")
Print the root NS records from f.root-servers.net; if we get a
response, else an error message.
>>> import ldnsx
>>> pkt = ldnsx.resolver("f.root-servers.net").query(".", "NS")
>>> if pkt:
>>> for rr in pkt.answer():
>>> print rr
>>> else:
>>> print "response not received"
"""
import time, sys, calendar, warnings, socket
try:
import ldns
except ImportError:
print >> sys.stderr, "ldnsx requires the ldns-python sub-package from http://www.nlnetlabs.nl/projects/ldns/"
print >> sys.stderr, "Fedora/CentOS: yum install ldns-python"
print >> sys.stderr, "Debian/Ubuntu: apt-get install python-ldns"
print >> sys.stderr, "openSUSE: zypper in python-ldns"
sys.exit(1)
__version__ = "0.1"
def isValidIP(ipaddr):
try:
v4 = socket.inet_pton(socket.AF_INET,ipaddr)
return 4
except:
try:
v6 = socket.inet_pton(socket.AF_INET6,ipaddr)
return 6
except:
return 0
def query(name, rr_type, rr_class="IN", flags=["RD"], tries = 3, res=None):
"""Convenience function. Creates a resolver and then queries it. Refer to resolver.query()
* name -- domain to query for
* rr_type -- rr_type to query for
* flags -- flags for query (list of strings)
* tries -- number of times to retry the query on failure
* res -- configurations for the resolver as a dict -- see resolver()
"""
if isinstance(res, list) or isinstance(res, tuple):
res = resolver(*res)
elif isinstance(res, dict):
res = resolver(**res)
else:
res = resolver(res)
return res.query(name, rr_type, rr_class, flags, tries)
def get_rrs(name, rr_type, rr_class="IN", tries = 3, strict = False, res=None, **kwds):
"""Convenience function. Gets RRs for name of type rr_type trying tries times.
If strict, it raises and exception on failure, otherwise it returns [].
* name -- domain to query for
* rr_type -- rr_type to query for
* flags -- flags for query (list of strings)
* tries -- number of times to retry the query on failure
* strict -- if the query fails, do we return [] or raise an exception?
* res -- configurations for the resolver as a dict -- see resolver()
* kwds -- query filters, refer to packet.answer()
"""
if isinstance(res, list) or isinstance(res, tuple):
res = resolver(*res)
elif isinstance(res, dict):
res = resolver(**res)
else:
res = resolver(res)
if "|" in rr_type:
pkt = res.query(name, "ANY", rr_class=rr_class, tries=tries)
else:
pkt = res.query(name, rr_type, rr_class=rr_class, tries=tries)
if pkt:
if rr_type in ["", "ANY", "*"]:
return pkt.answer( **kwds)
else:
return pkt.answer(rr_type=rr_type, **kwds)
else:
if strict:
raise Exception("LDNS couldn't complete query")
else:
return []
def secure_query(name, rr_type, rr_class="IN", flags=["RD"], tries = 1, flex=False, res=None):
"""Convenience function. Creates a resolver and then does a DNSSEC query. Refer to resolver.query()
* name -- domain to query for
* rr_type -- rr_type to query for
* flags -- flags for query (list of strings)
* tries -- number of times to retry the query on failure
* flex -- if we can't verify data, exception or warning?
* res -- configurations for the resolver as a dict -- see resolver()"""
if isinstance(res, list) or isinstance(res, tuple):
res = resolver(*res)
elif isinstance(res, dict):
res = resolver(**res)
else:
res = resolver(res)
pkt = res.query(name, rr_type, rr_class, flags, tries)
if pkt.rcode() == "SERVFAIL":
raise Exception("%s lookup failed (server error or dnssec validation failed)" % name)
if pkt.rcode() == "NXDOMAIN":
if "AD" in pkt.flags():
raise Exception("%s lookup failed (non-existence proven by DNSSEC)" % name )
else:
raise Exception("%s lookup failed" % name )
if pkt.rcode() == "NOERROR":
if "AD" not in pkt.flags():
if not flex:
raise Exception("DNS lookup was insecure")
else:
warnings.warn("DNS lookup was insecure")
return pkt
else:
raise Exception("unknown ldns error, %s" % pkt.rcode())
class resolver:
""" A wrapper around ldns.ldns_resolver.
**Examples**
Making resolvers is easy!
>>> from ldnsx import resolver
>>> resolver() # from /etc/resolv.conf
<resolver: 192.168.111.9>
>>> resolver("") # resolver with no nameservers
<resolver: >
>>> resolver("193.110.157.135") #resolver pointing to ip addr
<resolver: 193.110.157.135>
>>> resolver("f.root-servers.net") # resolver pointing ip address(es) resolved from name
<resolver: 2001:500:2f::f, 192.5.5.241>
>>> resolver("193.110.157.135, 193.110.157.136")
>>> # resolver pointing to multiple ip addr, first takes precedence.
<resolver: 193.110.157.136, 193.110.157.135>
So is playing around with their nameservers!
>>> import ldnsx
>>> res = ldnsx.resolver("192.168.1.1")
>>> res.add_nameserver("192.168.1.2")
>>> res.add_nameserver("192.168.1.3")
>>> res.nameservers_ip()
["192.168.1.1","192.168.1.2","192.168.1.3"]
And querying!
>>> from ldnsx import resolver
>>> res= resolver()
>>> res.query("cow.com","A")
;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 7663
;; flags: qr rd ra ; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;; cow.com. IN A
;; ANSWER SECTION:
cow.com. 300 IN A 208.87.34.18
;; AUTHORITY SECTION:
;; ADDITIONAL SECTION:
;; Query time: 313 msec
;; SERVER: 192.168.111.9
;; WHEN: Fri Jun 3 11:01:02 2011
;; MSG SIZE rcvd: 41
"""
def __init__(self, ns = None, dnssec = False, tcp = False, port = 53):
"""resolver constructor
* ns -- the nameserver/comma delimited nameserver list
defaults to settings from /etc/resolv.conf
* dnssec -- should the resolver try and use dnssec or not?
* tcp -- should the resolver use TCP
'auto' is a deprecated work around for old ldns problems
* port -- the port to use, must be the same for all nameservers
"""
# We construct based on a file and dump the nameservers rather than using
# ldns_resolver_new() to avoid environment/configuration/magic specific
# bugs.
self._ldns_resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
if ns != None:
self.drop_nameservers()
nm_list = ns.split(',')
nm_list = map(lambda s: s.strip(), nm_list)
nm_list = list(filter(lambda s: s != "", nm_list))
nm_list.reverse()
for nm in nm_list:
self.add_nameserver(nm)
# Configure DNSSEC, tcp and port
self.set_dnssec(dnssec)
if tcp == 'auto':
self.autotcp = True
self._ldns_resolver.set_usevc(False)
else:
self.autotcp = False
self._ldns_resolver.set_usevc(tcp)
self._ldns_resolver.set_port(port)
def query(self, name, rr_type, rr_class="IN", flags=["RD"], tries = 3):
"""Run a query on the resolver.
* name -- name to query for
* rr_type -- the record type to query for
* rr_class -- the class to query for, defaults to IN (Internet)
* flags -- the flags to send the query with
* tries -- the number of times to attempt to achieve query in case of packet loss, etc
**Examples**
Let's get some A records!
>>> google_a_records = resolver.query("google.com","A").answer()
Using DNSSEC is easy :)
>>> dnssec_pkt = ldnsx.resolver(dnssec=True).query("xelerance.com")
We let you use strings to make things easy, but if you prefer stay close to DNS...
>>> AAAA = 28
>>> resolver.query("ipv6.google.com", AAAA)
**More about rr_type**
rr_type must be a supported resource record type. There are a large number of RR types:
=========== =================================== ==================
TYPE Value and meaning Reference
=========== =================================== ==================
A 1 a host address [RFC1035]
NS 2 an authoritative name server [RFC1035]
...
AAAA 28 IP6 Address [RFC3596]
...
DS 43 Delegation Signer [RFC4034][RFC3658]
...
DNSKEY 48 DNSKEY [RFC4034][RFC3755]
...
Unassigned 32770-65279
Private use 65280-65534
Reserved 65535
=========== =================================== ==================
(From http://www.iana.org/assignments/dns-parameters)
RR types are given as a string (eg. "A"). In the case of Unassigned/Private use/Reserved ones,
they are given as "TYPEXXXXX" where XXXXX is the number. ie. RR type 65280 is "TYPE65280". You
may also pass the integer, but you always be given the string.
If the version of ldnsx you are using is old, it is possible that there could be new rr_types that
we don't recognise mnemonic for. You can still use the number XXX or the string "TYPEXXX". To
determine what rr_type mnemonics we support, please refer to resolver.supported_rr_types()
"""
# Determine rr_type int
if rr_type in _rr_types.keys():
_rr_type = _rr_types[rr_type]
elif isinstance(rr_type,int):
_rr_type = rr_type
elif isinstance(rr_type,str) and rr_type[0:4] == "TYPE":
try:
_rr_type = int(rr_type[4:])
except:
raise Exception("%s is a bad RR type. TYPEXXXX: XXXX must be a number")
else:
raise Exception("ldnsx (version %s) does not support the RR type %s." % (__version__, str(rr_type)) )
# Determine rr_class int
if rr_class == "IN": _rr_class = ldns.LDNS_RR_CLASS_IN
elif rr_class == "CH": _rr_class = ldns.LDNS_RR_CLASS_CH
elif rr_class == "HS": _rr_class = ldns.LDNS_RR_CLASS_HS
else:
raise Exception("ldnsx (version %s) does not support the RR class %s." % (__version__, str(rr_class)) )
# Determine flags int
_flags = 0
if "QR" in flags: _flags |= ldns.LDNS_QR
if "AA" in flags: _flags |= ldns.LDNS_AA
if "TC" in flags: _flags |= ldns.LDNS_TC
if "RD" in flags: _flags |= ldns.LDNS_RD
if "CD" in flags: _flags |= ldns.LDNS_CD
if "RA" in flags: _flags |= ldns.LDNS_RA
if "AD" in flags: _flags |= ldns.LDNS_AD
# Query
if tries == 0: return None
try:
pkt = self._ldns_resolver.query(name, _rr_type, _rr_class, _flags)
except KeyboardInterrupt: #Since so much time is spent waiting on ldns, this is very common place for Ctr-C to fall
raise
except: #Since the ldns exception is not very descriptive...
raise Exception("ldns backend ran into problems. Likely, the name you were querying for, %s, was invalid." % name)
#Deal with failed queries
if not pkt:
if tries <= 1:
return None
else:
# One of the major causes of none-packets is truncation of packets
# When autotcp is set, we are in a flexible enough position to try and use tcp
# to get around this.
# Either way, we want to replace the resolver, since resolvers will sometimes
# just freeze up.
if self.autotcp:
self = resolver( ",".join(self.nameservers_ip()),tcp=True, dnssec = self._ldns_resolver.dnssec())
self.autotcp = True
pkt = self.query(name, rr_type, rr_class=rr_class, flags=flags, tries = tries-1)
self._ldns_resolver.set_usevc(False)
return pkt
else:
self = resolver( ",".join(self.nameservers_ip()), tcp = self._ldns_resolver.usevc(), dnssec = self._ldns_resolver.dnssec() )
time.sleep(1) # It could be that things are failing because of a brief outage
return self.query(name, rr_type, rr_class=rr_class, flags=flags, tries = tries-1)
elif self.autotcp:
pkt = packet(pkt)
if "TC" in pkt.flags():
self._ldns_resolver.set_usevc(True)
pkt2 = self.query(name, rr_type, rr_class=rr_class, flags=flags, tries = tries-1)
self._ldns_resolver.set_usevc(False)
if pkt2: return packet(pkt2)
return pkt
return packet(pkt)
#ret = []
#for rr in pkt.answer().rrs():
# ret.append([str(rr.owner()),rr.ttl(),rr.get_class_str(),rr.get_type_str()]+[str(rdf) for rdf in rr.rdfs()])
#return ret
def suported_rr_types(self):
""" Returns the supported DNS resource record types.
Refer to resolver.query() for thorough documentation of resource
record types or refer to:
http://www.iana.org/assignments/dns-parameters
"""
return _rr_types.keys()
def AXFR(self,name):
"""AXFR for name
* name -- name to AXFR for
This function is a generator. As it AXFRs it will yield you the records.
**Example**
Let's get a list of the tlds (gotta catch em all!):
>>> tlds = []
>>> for rr in resolver("f.root-servers.net").AXFR("."):
>>> if rr.rr_type() == "NS":
>>> tlds.append(rr.owner())
"""
#Dname seems to be unnecessary on some computers, but it is on others. Avoid bugs.
if self._ldns_resolver.axfr_start(ldns.ldns_dname(name), ldns.LDNS_RR_CLASS_IN) != ldns.LDNS_STATUS_OK:
raise Exception("Starting AXFR failed. Error: %s" % ldns.ldns_get_errorstr_by_id(status))
pres = self._ldns_resolver.axfr_next()
while pres:
yield resource_record(pres)
pres = self._ldns_resolver.axfr_next()
def nameservers_ip(self):
""" returns a list of the resolvers nameservers (as IP addr)
"""
nm_stack2 =[]
nm_str_stack2=[]
nm = self._ldns_resolver.pop_nameserver()
while nm:
nm_stack2.append(nm)
nm_str_stack2.append(str(nm))
nm = self._ldns_resolver.pop_nameserver()
for nm in nm_stack2:
self._ldns_resolver.push_nameserver(nm)
nm_str_stack2.reverse()
return nm_str_stack2
def add_nameserver(self,ns):
""" Add a nameserver, IPv4/IPv6/name.
"""
if isValidIP(ns) == 4:
address = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_A,ns)
self._ldns_resolver.push_nameserver(address)
elif isValidIP(ns) == 6:
address = ldns.ldns_rdf_new_frm_str(ldns.LDNS_RDF_TYPE_AAAA,ns)
self._ldns_resolver.push_nameserver(address)
else:
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
#address = resolver.get_addr_by_name(ns)
address = resolver.get_addr_by_name(ldns.ldns_dname(ns))
if not address:
address = resolver.get_addr_by_name(ldns.ldns_dname(ns))
if not address:
raise Exception("Failed to resolve address for %s" % ns)
for rr in address.rrs():
self._ldns_resolver.push_nameserver_rr(rr)
def drop_nameservers(self):
"""Drops all nameservers.
This function causes the resolver to forget all nameservers.
"""
while self._ldns_resolver.pop_nameserver():
pass
def set_nameservers(self, nm_list):
"""Takes a list of nameservers and sets the resolver to use them
"""
self.drop_nameservers()
for nm in nm_list:
self.add_nameserver(nm)
def __repr__(self):
return "<resolver: %s>" % ", ".join(self.nameservers_ip())
__str__ = __repr__
def set_dnssec(self,new_dnssec_status):
"""Set whether the resolver uses DNSSEC.
"""
self._ldns_resolver.set_dnssec(new_dnssec_status)
class packet:
def _construct_rr_filter(self, **kwds):
def match(pattern, target):
if pattern[0] in ["<",">","!"]:
rel = pattern[0]
pattern=pattern[1:]
elif pattern[0:2] in ["<=","=>"]:
rel = pattern[0:2]
pattern=pattern[2:]
else:
rel = "="
for val in pattern.split("|"):
if {"<" : target < val,
">" : target > val,
"!" : target != val,
"=" : target == val,
">=": target >= val,
"<=": target <= val}[rel]:
return True
return False
def f(rr):
for key in kwds.keys():
if ( ( isinstance(kwds[key], list) and str(rr[key]) not in map(str,kwds[key]) )
or ( not isinstance(kwds[key], list) and not match(str(kwds[key]), str(rr[key])))):
return False
return True
return f
def __init__(self, pkt):
self._ldns_pkt = pkt
def __repr__(self):
return str(self._ldns_pkt)
__str__ = __repr__
def rcode(self):
"""Returns the rcode.
Example returned value: "NOERROR"
possible rcodes (via ldns): "FORMERR", "MASK", "NOERROR",
"NOTAUTH", "NOTIMPL", "NOTZONE", "NXDOMAIN",
"NXRSET", "REFUSED", "SERVFAIL", "SHIFT",
"YXDOMAIN", "YXRRSET"
Refer to http://www.iana.org/assignments/dns-parameters
section: DNS RCODEs
"""
return self._ldns_pkt.rcode2str()
def opcode(self):
"""Returns the rcode.
Example returned value: "QUERY"
"""
return self._ldns_pkt.opcode2str()
def flags(self):
"""Return packet flags (as list of strings).
Example returned value: ['QR', 'RA', 'RD']
**What are the flags?**
======== ==== ===================== =========
Bit Flag Description Reference
======== ==== ===================== =========
bit 5 AA Authoritative Answer [RFC1035]
bit 6 TC Truncated Response [RFC1035]
bit 7 RD Recursion Desired [RFC1035]
bit 8 RA Recursion Allowed [RFC1035]
bit 9 Reserved
bit 10 AD Authentic Data [RFC4035]
bit 11 CD Checking Disabled [RFC4035]
======== ==== ===================== =========
(from http://www.iana.org/assignments/dns-parameters)
There is also QR. It is mentioned in other sources,
though not the above page. It being false means that
the packet is a query, it being true means that it is
a response.
"""
ret = []
if self._ldns_pkt.aa(): ret += ["AA"]
if self._ldns_pkt.ad(): ret += ["AD"]
if self._ldns_pkt.cd(): ret += ["CD"]
if self._ldns_pkt.qr(): ret += ["QR"]
if self._ldns_pkt.ra(): ret += ["RA"]
if self._ldns_pkt.rd(): ret += ["RD"]
if self._ldns_pkt.tc(): ret += ["TC"]
return ret
def answer(self, **filters):
"""Returns the answer section.
* filters -- a filtering mechanism
Since a very common desire is to filter the resource records in a packet
section, we provide a special tool for doing this: filters. They are a
lot like regular python filters, but more convenient. If you set a
field equal to some value, you will only receive resource records for which
it holds true.
**Examples**
>>> res = ldnsx.resolver()
>>> pkt = res.query("google.ca","A")
>>> pkt.answer()
[google.ca. 28 IN A 74.125.91.99
, google.ca. 28 IN A 74.125.91.105
, google.ca. 28 IN A 74.125.91.147
, google.ca. 28 IN A 74.125.91.103
, google.ca. 28 IN A 74.125.91.104
, google.ca. 28 IN A 74.125.91.106
]
To understand filters, consider the following:
>>> pkt = ldnsx.query("cow.com","ANY")
>>> pkt.answer()
[cow.com. 276 IN A 208.87.32.75
, cow.com. 3576 IN NS sell.internettraffic.com.
, cow.com. 3576 IN NS buy.internettraffic.com.
, cow.com. 3576 IN SOA buy.internettraffic.com. hostmaster.hostingnet.com. 1308785320 10800 3600 604800 3600
]
>>> pkt.answer(rr_type="A")
[cow.com. 276 IN A 208.87.32.75
]
>>> pkt.answer(rr_type="A|NS")
[cow.com. 276 IN A 208.87.32.75
, cow.com. 3576 IN NS sell.internettraffic.com.
, cow.com. 3576 IN NS buy.internettraffic.com.
]
>>> pkt.answer(rr_type="!NS")
[cow.com. 276 IN A 208.87.32.75
, cow.com. 3576 IN SOA buy.internettraffic.com. hostmaster.hostingnet.com. 1308785320 10800 3600 604800 3600
]
fields are the same as when indexing a resource record.
note: ordering is alphabetical.
"""
ret = [resource_record(rr) for rr in self._ldns_pkt.answer().rrs()]
return filter(self._construct_rr_filter(**filters), ret)
def authority(self, **filters):
"""Returns the authority section.
* filters -- a filtering mechanism
Since a very common desire is to filter the resource records in a packet
section, we provide a special tool for doing this: filters. They are a
lot like regular python filters, but more convenient. If you set a
field equal to some value, you will only receive resource records for which
it holds true. See answer() for details.
**Examples**
>>> res = ldnsx.resolver()
>>> pkt = res.query("google.ca","A")
>>> pkt.authority()
[google.ca. 251090 IN NS ns3.google.com.
, google.ca. 251090 IN NS ns1.google.com.
, google.ca. 251090 IN NS ns2.google.com.
, google.ca. 251090 IN NS ns4.google.com.
]
"""
ret = [resource_record(rr) for rr in self._ldns_pkt.authority().rrs()]
return filter(self._construct_rr_filter(**filters), ret)
def additional(self, **filters):
"""Returns the additional section.
* filters -- a filtering mechanism
Since a very common desire is to filter the resource records in a packet
section, we provide a special tool for doing this: filters. They are a
lot like regular python filters, but more convenient. If you set a
field equal to some value, you will only receive resource records for which
it holds true. See answer() for details.
**Examples**
>>> res = ldnsx.resolver()
>>> pkt = res.query("google.ca","A")
>>> pkt.additional()
[ns3.google.com. 268778 IN A 216.239.36.10
, ns1.google.com. 262925 IN A 216.239.32.10
, ns2.google.com. 255659 IN A 216.239.34.10
, ns4.google.com. 264489 IN A 216.239.38.10
]
"""
ret = [resource_record(rr) for rr in self._ldns_pkt.additional().rrs()]
return filter(self._construct_rr_filter(**filters), ret)
def question(self, **filters):
"""Returns the question section.
* filters -- a filtering mechanism
Since a very common desire is to filter the resource records in a packet
section, we provide a special tool for doing this: filters. They are a
lot like regular python filters, but more convenient. If you set a
field equal to some value, you will only receive resource records for which
it holds true. See answer() for details.
"""
ret = [resource_record(rr) for rr in self._ldns_pkt.question().rrs()]
return filter(self._construct_rr_filter(**filters), ret)
class resource_record:
_rdfs = None
_iter_pos = None
def __init__(self, rr):
self._ldns_rr = rr
self._rdfs = [str(rr.owner()),rr.ttl(),rr.get_class_str(),rr.get_type_str()]+[str(rdf) for rdf in rr.rdfs()]
def __repr__(self):
return str(self._ldns_rr)
__str__ = __repr__
def __iter__(self):
self._iter_pos = 0
return self
def next(self):
if self._iter_pos < len(self._rdfs):
self._iter_pos += 1
return self._rdfs[self._iter_pos-1]
else:
raise StopIteration
def __len__(self):
try:
return len(self._rdfs)
except:
return 0
def __getitem__(self, n):
if isinstance(n, int):
return self._rdfs[n]
elif isinstance(n, str):
n = n.lower()
if n in ["owner"]:
return self.owner()
elif n in ["rr_type", "rr type", "type"]:
return self.rr_type()
elif n in ["rr_class", "rr class", "class"]:
return self.rr_class()
elif n in ["covered_type", "covered type", "type2"]:
return self.covered_type()
elif n in ["ttl"]:
return self.ttl()
elif n in ["ip"]:
return self.ip()
elif n in ["alg", "algorithm"]:
return self.alg()
elif n in ["protocol"]:
return self.protocol()
elif n in ["flags"]:
return self.flags()
else:
raise Exception("ldnsx (version %s) does not recognize the rr field %s" % (__version__,n) )
else:
raise TypeError("bad type %s for index resource record" % type(n) )
#def rdfs(self):
# return self._rdfs.clone()
def owner(self):
"""Get the RR's owner"""
return str(self._ldns_rr.owner())
def rr_type(self):
"""Get a RR's type """
return self._ldns_rr.get_type_str()
def covered_type(self):
"""Get an RRSIG RR's covered type"""
if self.rr_type() == "RRSIG":
return self[4]
else:
return ""
def rr_class(self):
"""Get the RR's collapse"""
return self._ldns_rr.get_class_str()
def ttl(self):
"""Get the RR's TTL"""
return self._ldns_rr.ttl()
def inception(self, out_format="UTC"):
"""returns the inception time in format out_format, defaulting to a UTC string.
options for out_format are:
UTC -- a UTC string eg. 20110712192610 (2011/07/12 19:26:10)
unix -- number of seconds since the epoch, Jan 1, 1970
struct_time -- the format used by python's time library
"""
# Something very strange is going on with inception/expiration dates in DNS.
# According to RFC 4034 section 3.1.5 (http://tools.ietf.org/html/rfc4034#page-9)
# the inception/expiration fields should be in seconds since Jan 1, 1970, the Unix
# epoch (as is standard in unix). Yet all the packets I've seen provide UTC encoded
# as a string instead, eg. "20110712192610" which is 2011/07/12 19:26:10.
#
# It turns out that this is a standard thing that ldns is doing before the data gets
# to us.
if self.rr_type() == "RRSIG":
if out_format.lower() in ["utc", "utc str", "utc_str"]:
return self[9]
elif out_format.lower() in ["unix", "posix", "ctime"]:
return calendar.timegm(time.strptime(self[9], "%Y%m%d%H%M%S"))
elif out_format.lower() in ["relative"]:
return calendar.timegm(time.strptime(self[9], "%Y%m%d%H%M%S")) - time.time()
elif out_format.lower() in ["struct_time", "time.struct_time"]:
return time.strptime(self[9], "%Y%m%d%H%M%S")
else:
raise Exception("unrecognized time format")
else:
return ""
def expiration(self, out_format="UTC"):
"""get expiration time. see inception() for more information"""
if self.rr_type() == "RRSIG":
if out_format.lower() in ["utc", "utc str", "utc_str"]:
return self[8]
elif out_format.lower() in ["unix", "posix", "ctime"]:
return calendar.timegm(time.strptime(self[8], "%Y%m%d%H%M%S"))
elif out_format.lower() in ["relative"]:
return calendar.timegm(time.strptime(self[8], "%Y%m%d%H%M%S")) - time.time()
elif out_format.lower() in ["struct_time", "time.struct_time"]:
return time.strptime(self[8], "%Y%m%d%H%M%S")
else:
raise Exception("unrecognized time format")
else:
return ""
def ip(self):
""" IP address form A/AAAA record"""
if self.rr_type() in ["A", "AAAA"]:
return self[4]
else:
raise Exception("ldnsx does not support ip for records other than A/AAAA")
def alg(self):
"""Returns algorithm of RRSIG/DNSKEY/DS"""
t = self.rr_type()
if t == "RRSIG":
return int(self[5])
elif t == "DNSKEY":
return int(self[6])
elif t == "DS":
return int(self[5])
else:
return -1
def protocol(self):
""" Returns protocol of the DNSKEY"""
t = self.rr_type()
if t == "DNSKEY":
return int(self[5])
else:
return -1
def flags(self):
"""Return RR flags for DNSKEY """
t = self.rr_type()
if t == "DNSKEY":
ret = []
n = int(self[4])
for m in range(1):
if 2**(15-m) & n:
if m == 7: ret.append("ZONE")
elif m == 8: ret.append("REVOKE")
elif m ==15: ret.append("SEP")
else: ret.append(m)
return ret
else:
return []
_rr_types={
"A" : ldns.LDNS_RR_TYPE_A,
"A6" : ldns.LDNS_RR_TYPE_A6,
"AAAA" : ldns.LDNS_RR_TYPE_AAAA,
"AFSDB": ldns.LDNS_RR_TYPE_AFSDB,
"ANY" : ldns.LDNS_RR_TYPE_ANY,
"APL" : ldns.LDNS_RR_TYPE_APL,
"ATMA" : ldns.LDNS_RR_TYPE_ATMA,
"AXFR" : ldns.LDNS_RR_TYPE_AXFR,
"CDNSKEY" : ldns.LDNS_RR_TYPE_CDNSKEY,
"CDS" : ldns.LDNS_RR_TYPE_CDS,
"CERT" : ldns.LDNS_RR_TYPE_CERT,
"CNAME": ldns.LDNS_RR_TYPE_CNAME,
"COUNT": ldns.LDNS_RR_TYPE_COUNT,
"DHCID": ldns.LDNS_RR_TYPE_DHCID,
"DLV" : ldns.LDNS_RR_TYPE_DLV,
"DNAME": ldns.LDNS_RR_TYPE_DNAME,
"DNSKEY": ldns.LDNS_RR_TYPE_DNSKEY,
"DS" : ldns.LDNS_RR_TYPE_DS,
"EID" : ldns.LDNS_RR_TYPE_EID,
"FIRST": ldns.LDNS_RR_TYPE_FIRST,
"GID" : ldns.LDNS_RR_TYPE_GID,
"GPOS" : ldns.LDNS_RR_TYPE_GPOS,
"HINFO": ldns.LDNS_RR_TYPE_HINFO,
"IPSECKEY": ldns.LDNS_RR_TYPE_IPSECKEY,
"ISDN" : ldns.LDNS_RR_TYPE_ISDN,
"IXFR" : ldns.LDNS_RR_TYPE_IXFR,
"KEY" : ldns.LDNS_RR_TYPE_KEY,
"KX" : ldns.LDNS_RR_TYPE_KX,
"LAST" : ldns.LDNS_RR_TYPE_LAST,
"LOC" : ldns.LDNS_RR_TYPE_LOC,
"MAILA": ldns.LDNS_RR_TYPE_MAILA,
"MAILB": ldns.LDNS_RR_TYPE_MAILB,
"MB" : ldns.LDNS_RR_TYPE_MB,
"MD" : ldns.LDNS_RR_TYPE_MD,
"MF" : ldns.LDNS_RR_TYPE_MF,
"MG" : ldns.LDNS_RR_TYPE_MG,
"MINFO": ldns.LDNS_RR_TYPE_MINFO,
"MR" : ldns.LDNS_RR_TYPE_MR,
"MX" : ldns.LDNS_RR_TYPE_MX,
"NAPTR": ldns.LDNS_RR_TYPE_NAPTR,
"NIMLOC": ldns.LDNS_RR_TYPE_NIMLOC,
"NS" : ldns.LDNS_RR_TYPE_NS,
"NSAP" : ldns.LDNS_RR_TYPE_NSAP,
"NSAP_PTR" : ldns.LDNS_RR_TYPE_NSAP_PTR,
"NSEC" : ldns.LDNS_RR_TYPE_NSEC,
"NSEC3": ldns.LDNS_RR_TYPE_NSEC3,
"NSEC3PARAM" : ldns.LDNS_RR_TYPE_NSEC3PARAM,
"NSEC3PARAMS" : ldns.LDNS_RR_TYPE_NSEC3PARAMS,
"NULL" : ldns.LDNS_RR_TYPE_NULL,
"NXT" : ldns.LDNS_RR_TYPE_NXT,
"OPENPGPKEY" : ldns.LDNS_RR_TYPE_OPENPGPKEY,
"OPT" : ldns.LDNS_RR_TYPE_OPT,
"PTR" : ldns.LDNS_RR_TYPE_PTR,
"PX" : ldns.LDNS_RR_TYPE_PX,
"RP" : ldns.LDNS_RR_TYPE_RP,
"RRSIG": ldns.LDNS_RR_TYPE_RRSIG,
"RT" : ldns.LDNS_RR_TYPE_RT,
"SIG" : ldns.LDNS_RR_TYPE_SIG,
"SINK" : ldns.LDNS_RR_TYPE_SINK,
"SOA" : ldns.LDNS_RR_TYPE_SOA,
"SRV" : ldns.LDNS_RR_TYPE_SRV,
"SSHFP": ldns.LDNS_RR_TYPE_SSHFP,
"TLSA" : ldns.LDNS_RR_TYPE_TLSA,
"TSIG" : ldns.LDNS_RR_TYPE_TSIG,
"TXT" : ldns.LDNS_RR_TYPE_TXT,
"UID" : ldns.LDNS_RR_TYPE_UID,
"UINFO": ldns.LDNS_RR_TYPE_UINFO,
"UNSPEC": ldns.LDNS_RR_TYPE_UNSPEC,
"WKS" : ldns.LDNS_RR_TYPE_WKS,
"X25" : ldns.LDNS_RR_TYPE_X25
}

View File

@@ -0,0 +1,15 @@
LDNSX API Reference
===================
.. automodule:: ldnsx
:members: query, get_rrs, secure_query
Classes
-------
.. toctree::
:maxdepth: 1
:glob:
resolver
packet
resource_record

View File

@@ -0,0 +1,6 @@
Class packet
==============
.. autoclass:: ldnsx.packet
:members:
:undoc-members:

View File

@@ -0,0 +1,6 @@
Class resolver
===============
.. autoclass:: ldnsx.resolver
:members:
:undoc-members:

View File

@@ -0,0 +1,6 @@
Class resource_record
=====================
.. autoclass:: ldnsx.resource_record
:members:
:undoc-members:

View File

@@ -0,0 +1,194 @@
# -*- coding: utf-8 -*-
#
# ldnsx documentation build configuration file, created by
# sphinx-quickstart on Mon May 30 16:56:19 2011.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.append(os.path.abspath('..'))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest']#, 'sphinx.ext.jsmath']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'ldnsx'
copyright = u'2011, Christopher Olah'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.0'
# The full version, including alpha/beta/rc tags.
release = '-1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
#unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = []
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_use_modindex = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'ldnsxdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'ldnsx.tex', u'ldnsx Documentation',
u'Christopher Olah', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_use_modindex = True

View File

@@ -0,0 +1,6 @@
AXFR Example
============
.. literalinclude:: ../../examples/ldnsx-axfr.py
:language: python
:linenos:

View File

@@ -0,0 +1,6 @@
DNSSEC Example
==============
.. literalinclude:: ../../examples/ldnsx-dnssec.py
:language: python
:linenos:

View File

@@ -0,0 +1,6 @@
MX1
===
.. literalinclude:: ../../examples/ldnsx-mx1.py
:language: python
:linenos:

View File

@@ -0,0 +1,6 @@
MX2
===
.. literalinclude:: ../../examples/ldnsx-mx2.py
:language: python
:linenos:

View File

@@ -0,0 +1,6 @@
NSEC Walker
===========
.. literalinclude:: ../../examples/ldnsx-walk.py
:language: python
:linenos:

View File

@@ -0,0 +1,57 @@
Welcome to ldnsx's documentation!
=================================
LDNSX: Easy DNS (including DNSSEC) via ldns.
ldns is a great library. It is a powerful tool for
working with DNS. python-ldns it is a straight up clone of the C
interface, however that is not a very good interface for python. Its
documentation is incomplete and some functions don't work as
described. And some objects don't have a full python API.
ldnsx aims to fix this. It wraps around the ldns python bindings,
working around its limitations and providing a well-documented, more
pythonistic interface.
Reference
=========
.. toctree::
:maxdepth: 1
api/ldnsx
.. toctree::
:maxdepth: 2
api/resolver
api/packet
api/resource_record
Examples
========
Examples translated from ldns examples:
.. toctree::
:maxdepth: 1
examples/ldnsx-axfr
examples/ldnsx-dnssec
examples/ldnsx-mx1
examples/ldnsx-mx2
Others:
.. toctree::
:maxdepth: 1
examples/ldnsx-walk
Indices and tables
==================
* :ref:`genindex`
* :ref:`search`

View File

@@ -0,0 +1,92 @@
1.6.17 2014-01-10
* Added ldns_rdf.data_as_bytearray(). The method returns a bytearray object
containing rdf data.
* Changed the behaviour of ldns_resolver.trusted_key() in order to prevent
memory corruption and leaks.
* Fixed memory leaks when destroying ldns_resolver.
* Removed ldns_pkt.section_count(), ldns_resolver.set_searchlist_count()
because it is marked static in the library.
* Added ldns_pkt.new(), ldns_resolver.new().
* Marked as returning new object ldns_pkt.get_section_clone(),
ldns_resolver.get_addr_by_name(), ldns_resolver.get_name_by_addr(),
ldns_resolver.search().
* Added push cloning for ldns_pkt.safe_push_rr(),
ldns_pkt.safe_push_rr_list(), ldns_pkt.set_additional(),
ldns_pkt.set_answer(), ldns_pkt.set_answerfrom(),
ldns_pkt.set_authority(), ldns_pkt.set_edns_data(),
ldns_pkt.set_question(), ldns_pkt.set_tsig(),
ldns_resolver.set_dnssec_anchors(), ldns_resolver.set_domain().
* Added pull cloning for ldns_pkt.answerfrom(), ldns_pkt.edns_data(),
ldns_pkt.tsig(), ldns_resolver.axfr_last_pkt(),
ldns_resolver.dnssec_anchors(), ldns_resolver.domain(),
ldns_resolver.tsig_algorithm(), ldns_resolver.tsig_keydata(),
ldns_resolver.tsig_keyname().
* Method ldns_rdf.reverse() now throws an exception when not applied
on dname rdfs. This is to prevent assertion fails in ldns' C code.
1.6.16 2012-11-13
* Fix typo in ldns_struct_pkt.opcode2str
1.6.14 2012-10-23
* Added rich comparison methods for ldns_dname, ldns_rdf, ldns_rr and
ldns_rr_list classes.
* Added deprecation warnings into ldns_rr.new_frm_fp() and
ldns_rr.new_frm_fp_l() and others.
* Fixed ldns_rr.set_rdf(), which may cause memory leaks, because it
returns new objects (in the scope of Python). Also it leaked memory,
when the call was not successful.
* Fixed ldns_get_rr_list_hosts_frm_file, marked as newobject.
* Fixed ldns_rr_list.cat() to return bool as mentioned in documentation.
* Fixed ldns_rr_list_cat_clone, marked as newobject.
* Fixed ldns_rr_list.new_frm_file(). Exception argument was invalid.
* Fixed ldns_rr_list.push_rr() to return bool as mentioned in
documentation.
* Fixed ldns_rr_list.push_rr_list() to return bool as mentioned in
documentation.
* Fixed ldns_rr_list.set_rr(), which caused memory corruption, double free
problems and memory leaks. (The wrapper used original function instead
of its push cloned variant which was missing.)
* Fixed ldns_rr_list.set_rr_count(), added python exception raise in order
to avoid assertion failure.
* Fixed ldns_rr_list.subtype_by_rdf(), marked as newobject.
* Added ldns_rr.to_canonical(), ldns_rr.is_question(),
ldns_rr.type_by_name(), ldns_rr.class_by_name(), ldns_rr_list.new(),
ldns_rr.set_question().
* Modified ldns_rr_list.owner() and ldns_rr.owner(), now returns ldns_dname.
* Fixed assertion failures for several methods when receiving incorrect but
syntactically valid arguments (i.e., ldns_rr.a_address(),
ldns_rr.dnskey_algorithm(), ldns_rr.dnskey_flags(),
ldns_rr.dnskey_key(), ldns_rr.dnskey_protocol(),
ldns_rr.mx_exchange(), ldns_rr.mx_preference(), ldns_rr.ns_nsdname(),
ldns_rr.owner(), ldns_rr.rdf(), ldns_rr.rrsig_algorithm(),
ldns_rr.rrsig_expiration(), ldns_rr.rrsig_inception(),
ldns_rr.rrsig_keytag(), ldns_rr.rrsig_labels(), ldns_rr.rrsig_origttl(),
ldns_rr.rrsig_sig(), ldns_rr.rrsig_signame(),
ldns_rr.rrsig_typecovered(), ldns_rr_list.owner(), ldns_rr_list.rr())
* Fixed ldns_rr.a_address(), which was asserting when called
on non A or AAAA type rr. Now returns None when fails.
* Added scripts for testing the basic functionality of the ldns_rr,
ldns_rr_descriptor and ldns_rr_list class code.
* Improved documentation of ldns_rr, ldns_rr_descriptor and ldns_rr_list.
* Fixed automatic conversion from Python string to ldns_rdf and
ldns_dname. Caused memory corruption when using Python 3.
* The Python 3 wrapper code now raises TypeError instead of ValueError
when receiving a non FILE * argument when it should be a FILE *.
* Fixed wrong handling of _ldns_rr_list_free() and
_ldns_rr_list_deep_free() when compiling with LDNS_DEBUG directive.
* Fixed malfunctioning ldns.ldns_rdf_new_frm_fp_l().
* Fixed malfunctioning ldns_drf.absolute() and ldns_dname.absolute().
* Marked several functions related to ldns_rdf and ldns_buffer as
returning new objects.
* Method operating on ldns_dnames and returning dname ldns_rdfs now
return ldns_dname instances.
* Improved documentation of ldns_buffer, ldns_rdf and ldns_dname
classes.
* Methods ldns_buffer.available() and ldns_buffer.available_at() now
return bool types as described in the documentation.
* Added scripts for testing the basic functionality of the ldns_buffer,
ldns_rdf, ldns_dname class code.
* Added deprecation warnings to ldns_rdf methods operating on dname
rdfs. The user is encouraged to converts dname ldns_rdfs to
ldns_dnames.
* Extended ldns_dname constructor to accept ldns_rdfs containing dnames.

View File

@@ -0,0 +1,27 @@
Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz)
Karel Slany (slany AT fit.vutbr.cz)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* 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.
* Neither the name of the organization nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.

View File

@@ -0,0 +1,110 @@
# Makefile: compilation of sources and documentation, test environment
#
# Copyright (c) 2009, Zdenek Vasicek (vasicek AT fit.vutbr.cz)
# Karel Slany (slany AT fit.vutbr.cz)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * 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.
# * Neither the name of the organization nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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.
.PHONY: help clean testenv test doc te bw bw3 sw sw3
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " testenv to make test environment and run bash "
@echo " useful in case you don't want to install ldns but want to test examples"
@echo " doc to make documentation"
@echo " clean clean all"
../../Makefile: ../../configure
cd ../.. && ./configure --with-python
_ldns.so: ../../Makefile
$(MAKE) -C ../..
../../.libs/libldns.so.1: ../../Makefile
$(MAKE) -C ../..
clean:
rm -rf examples/ldns
rm -f _ldns.so ldns_wrapper.o
$(MAKE) -C ../.. clean
testenv: ../../.libs/libldns.so.1 _ldns.so
rm -rf examples/ldns
cd examples && mkdir ldns && ln -s ../../ldns.py ldns/__init__.py && ln -s ../../../../.libs/_ldns.so ldns/_ldns.so && ln -s ../../../../.libs/libldns.so.1 ldns/libldns.so.1 && ls -la
@echo "Run a script by typing ./script_name.py"
cd examples && LD_LIBRARY_PATH=ldns bash
rm -rf examples/ldns
test: ../../.libs/libldns.so.1 _ldns.so examples/test_buffer.py examples/test_rdf.py examples/test_dname.py examples/test_rr.py examples/test_pkt.py examples/test_resolver.py
@rm -rf examples/ldns
@cd examples && mkdir ldns && ln -s ../../ldns.py ldns/__init__.py && ln -s ../../../../.libs/_ldns.so ldns/_ldns.so && ln -s ../../../../.libs/libldns.so.1 ldns/libldns.so.1
@cd examples && LD_LIBRARY_PATH=ldns ./test_buffer.py 2>/dev/null
@cd examples && LD_LIBRARY_PATH=ldns ./test_rdf.py 2>/dev/null
@cd examples && LD_LIBRARY_PATH=ldns ./test_dname.py 2>/dev/null
@cd examples && LD_LIBRARY_PATH=ldns ./test_rr.py 2>/dev/null
@cd examples && LD_LIBRARY_PATH=ldns ./test_pkt.py 2>/dev/null
@cd examples && LD_LIBRARY_PATH=ldns ./test_resolver.py 2>/dev/null
@rm -rf examples/ldns
doc: ../../.libs/libldns.so.1 _ldns.so
echo @VERSION_MAJOR@
rm -f _ldns.so
ln -s ../../.libs/_ldns.so
$(MAKE) -C docs html
rm -f _ldns.so
# For development only:
# Test environment, does not build the wrapper from dependencies.
te:
rm -rf examples/ldns
cd examples && mkdir ldns && ln -s ../../ldns.py ldns/__init__.py && ln -s ../../../../.libs/_ldns.so ldns/_ldns.so && ln -s ../../../../.libs/libldns.so.1 ldns/libldns.so.1 && ls -la
@echo "Run a script by typing ./script_name.py"
cd examples && LD_LIBRARY_PATH=ldns bash
rm -rf examples/ldns
# Builds Python 2 wrapper from present wrapper C code.
bw:
gcc -c ldns_wrapper.c -O9 -fPIC -I../.. -I../../ldns -I/usr/include/python2.7 -I. -o ldns_wrapper.o
mkdir -p ../../.libs
ld -shared ldns_wrapper.o -L../../.libs -lldns -o ../../.libs/_ldns.so
# Builds Python 3 wrapper from present wrapper C code.
bw3:
gcc -c ldns_wrapper.c -O9 -fPIC -I../.. -I../../ldns -I/usr/include/python3.2 -I. -o ldns_wrapper.o
mkdir -p ../../.libs
ld -shared ldns_wrapper.o -L../../.libs -ldns -o ../../.libs/_ldns.so
# Builds Python 2 wrapper from interface file.
sw: ldns.i
swig -python -o ldns_wrapper.c -I../.. ldns.i
$(MAKE) bw
# Builds Python 3 wrapper from interface file.
sw3: ldns.i
swig -python -py3 -DPY3 -o ldns_wrapper.c -I../.. ldns.i
$(MAKE) bw3

View File

@@ -0,0 +1,70 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d build/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
.PHONY: help clean html web pickle htmlhelp latex changes linkcheck
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " pickle to make pickle files (usable by e.g. sphinx-web)"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " changes to make an overview over all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
clean:
-rm -rf build/*
html:
mkdir -p build/html build/doctrees
LD_LIBRARY_PATH=../../../.libs $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) build/html
@echo
@echo "Build finished. The HTML pages are in build/html."
pickle:
mkdir -p build/pickle build/doctrees
LD_LIBRARY_PATH=../../../.libs $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) build/pickle
@echo
@echo "Build finished; now you can process the pickle files or run"
@echo " sphinx-web build/pickle"
@echo "to start the sphinx-web server."
web: pickle
htmlhelp:
mkdir -p build/htmlhelp build/doctrees
LD_LIBRARY_PATH=../../../.libs $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) build/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in build/htmlhelp."
latex:
mkdir -p build/latex build/doctrees
LD_LIBRARY_PATH=../../../.libs $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) build/latex
@echo
@echo "Build finished; the LaTeX files are in build/latex."
@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
"run these through (pdf)latex."
changes:
mkdir -p build/changes build/doctrees
LD_LIBRARY_PATH=../../../.libs $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) build/changes
@echo
@echo "The overview file is in build/changes."
linkcheck:
mkdir -p build/linkcheck build/doctrees
LD_LIBRARY_PATH=../../../.libs $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) build/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in build/linkcheck/output.txt."

View File

@@ -0,0 +1,180 @@
# -*- coding: utf-8 -*-
#
# Unbound documentation build configuration file, created by
# sphinx-quickstart on Fri Jan 2 19:14:13 2009.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# The contents of this file are pickled, so don't put values in the namespace
# that aren't pickleable (module imports are okay, they're removed automatically).
#
# All configuration values have a default value; values that are commented out
# serve to show the default value.
import sys, os
# If your extensions are in another directory, add it here. If the directory
# is relative to the documentation root, use os.path.abspath to make it
# absolute, like shown here.
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__),'../../')))
#print sys.path
# General configuration
# ---------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The master toctree document.
master_doc = 'index'
# General substitutions.
project = 'pyLDNS'
copyright = '2009-2013, Karel Slany, Zdenek Vasicek'
# The default replacements for |version| and |release|, also used in various
# other places throughout the built documents.
#
# The short X.Y version.
version = '1.6'
# The full version, including alpha/beta/rc tags.
release = '1.6.17'
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
#unused_docs = []
# List of directories, relative to source directories, that shouldn't be searched
# for source files.
#exclude_dirs = []
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# Options for HTML output
# -----------------------
# The style sheet to use for HTML and HTML Help pages. A file of that name
# must exist either in Sphinx' static/ path, or in one of the custom paths
# given in html_static_path.
html_style = 'default.css'
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (within the static path) to place at the top of
# the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
html_use_modindex = False
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
html_split_index = False
# If true, the reST sources are included in the HTML build as _sources/<name>.
html_copy_source = False
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'ldnsdoc'
# Options for LaTeX output
# ------------------------
# The paper size ('letter' or 'a4').
#latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
#latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, document class [howto/manual]).
latex_documents = [
('index', 'ldns-doc.tex', 'LDNS Documentation',
'Karel Slany, Zdenek Vasicek', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_use_modindex = True

View File

@@ -0,0 +1,68 @@
Resolving the MX records
==============================
This basic example shows how to create a resolver which asks for MX records which contain the information about mail servers.
::
#!/usr/bin/python
#
# MX is a small program that prints out the mx records for a particular domain
#
import ldns
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
dname = ldns.ldns_dname("nic.cz")
pkt = resolver.query(dname, ldns.LDNS_RR_TYPE_MX, ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD)
if (pkt):
mx = pkt.rr_list_by_type(ldns.LDNS_RR_TYPE_MX, ldns.LDNS_SECTION_ANSWER)
if (mx):
mx.sort()
print mx
Resolving step by step
------------------------
First of all we import :mod:`ldns` extension module which make LDNS functions and classes accessible::
import ldns
If importing fails, it means that Python cannot find the module or ldns library.
Then we create the resolver by :meth:`ldns.ldns_resolver.new_frm_file` constructor ::
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
and domain name variable dname::
dname = ldns.ldns_dname("nic.cz")
To create a resolver you may also use::
resolver = ldns.ldns_resolver.new_frm_file(None)
which behaves in the same manner as the command above.
In the third step we tell the resolver to query for our domain, type MX, of class IN::
pkt = resolver.query(dname, ldns.LDNS_RR_TYPE_MX, ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD)
The function should return a packet if everything goes well and this packet will contain resource records we asked for.
Note that there exists a simpler way. Instead of using a dname variable, we can use a string which will be automatically converted.
::
pkt = resolver.query("fit.vutbr.cz", ldns.LDNS_RR_TYPE_MX, ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD)
Now, we test whether the resolver returns a packet and then get all RRs of type MX from the answer packet and store them in list mx::
if (pkt):
mx = pkt.rr_list_by_type(ldns.LDNS_RR_TYPE_MX, ldns.LDNS_SECTION_ANSWER)
If this list is not empty, we sort and print the content to stdout::
if (mx):
mx.sort()
print mx

View File

@@ -0,0 +1,45 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import ldns
import sys
debug = True
# Check args
argc = len(sys.argv)
name = "www.nic.cz"
if argc < 2:
print("Usage:", sys.argv[0], "domain [resolver_addr]")
sys.exit(1)
else:
name = sys.argv[1]
# Create resolver
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
resolver.set_dnssec(True)
# Custom resolver
if argc > 2:
# Clear previous nameservers
ns = resolver.pop_nameserver()
while ns != None:
ns = resolver.pop_nameserver()
ip = ldns.ldns_rdf.new_frm_str(sys.argv[2], ldns.LDNS_RDF_TYPE_A)
resolver.push_nameserver(ip)
# Resolve DNS name
pkt = resolver.query(name, ldns.LDNS_RR_TYPE_A, ldns.LDNS_RR_CLASS_IN)
if pkt and pkt.answer():
# Debug
if debug:
print("NS returned:", pkt.get_rcode(), "(AA: %d AD: %d)" % ( pkt.ad(), pkt.ad() ))
# SERVFAIL indicated bogus name
if pkt.get_rcode() is ldns.LDNS_RCODE_SERVFAIL:
print(name, "is bogus")
# Check AD (Authenticated) bit
if pkt.get_rcode() is ldns.LDNS_RCODE_NOERROR:
if pkt.ad(): print(name, "is secure")
else: print(name, "is insecure")

View File

@@ -0,0 +1,100 @@
.. _ex_dnssec:
Querying DNS-SEC validators
===========================
This basic example shows how to query validating resolver and
evaluate answer.
Resolving step by step
------------------------
For DNS queries, we need to initialize ldns resolver (covered in previous example).
::
# Create resolver
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
resolver.set_dnssec(True)
# Custom resolver
if argc > 2:
# Clear previous nameservers
ns = resolver.pop_nameserver()
while ns != None:
ns = resolver.pop_nameserver()
ip = ldns.ldns_rdf.new_frm_str(sys.argv[2], ldns.LDNS_RDF_TYPE_A)
resolver.push_nameserver(ip)
Note the second line :meth:`resolver.set_dnssec`, which enables DNSSEC OK bit
in queries in order to get meaningful results.
As we have resolver initialized, we can start querying for domain names :
::
# Resolve DNS name
pkt = resolver.query(name, ldns.LDNS_RR_TYPE_A, ldns.LDNS_RR_CLASS_IN)
if pkt and pkt.answer():
Now we evaluate result, where two flags are crucial :
* Return code
* AD flag (authenticated)
When return code is `SERVFAIL`, it means that validating resolver marked requested
name as **bogus** (or bad configuration).
**AD** flag is set if domain name is authenticated **(secure)** or false if
it's insecure.
Complete source code
--------------------
.. literalinclude:: ../../../examples/ldns-dnssec.py
:language: python
Testing
-------
In order to get meaningful results, you have to enter IP address of validating
resolver or setup your own (see howto).
Execute `./example2.py` with options `domain name` and `resolver IP`,
example:
::
user@localhost# ./example2.py www.dnssec.cz 127.0.0.1 # Secure (Configured Unbound running on localhost)
user@localhost# ./example2.py www.rhybar.cz 127.0.0.1 # Bogus
Howto setup Unbound as validating resolver
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Install Unbound according to instructions.
Modify following options in `unbound.conf` (located in `/etc` or `/usr/local/etc`)/
Uncomment `module-config` and set `validator` before iterator.
::
module-config: "validator iterator"
Download DLV keys and update path in `unbound.conf`::
# DLV keys
# Download from http://ftp.isc.org/www/dlv/dlv.isc.org.key
dlv-anchor-file: "/usr/local/etc/unbound/dlv.isc.org.key"
Update trusted keys (`.cz` for example)::
# Trusted keys
# For current key, see www.dnssec.cz
trusted-keys-file: "/usr/local/etc/unbound/trusted.key"
Now you should have well configured Unbound, so run it::
user@localhost# unbound -dv

View File

@@ -0,0 +1,7 @@
High-level functions
===========================
This basic example shows how to get name by addr and vice versa.
.. literalinclude:: ../../../examples/ldns-higher.py
:language: python

View File

@@ -0,0 +1,7 @@
AXFR client with IDN support
===============================
This example shows how to get AXFR working and how to get involved Internationalized Domain Names (IDN)
.. literalinclude:: ../../../examples/ldns-axfr.py
:language: python

View File

@@ -0,0 +1,14 @@
Examine the results
===============================
This example shows how to go through the obtained results
.. literalinclude:: ../../../examples/ldns-mx2.py
:language: python
This snippet of code prints::
nic.cz. 1761 IN MX 20 mx.cznic.org.
nic.cz. 1761 IN MX 10 mail.nic.cz.
nic.cz. 1761 IN MX 15 mail4.nic.cz.

View File

@@ -0,0 +1,12 @@
Read zone file
===============================
This example shows how to read the content of a zone file
.. literalinclude:: ../../../examples/ldns-zone.py
:language: python
Zone file ``zone.txt``:
.. literalinclude:: ../../../examples/zone.txt

View File

@@ -0,0 +1,8 @@
Generate public/private key pair
=======================================
This example shows how generate keys for DNSSEC (i.e. for signing a zone file according DNSSECbis).
.. literalinclude:: ../../../examples/ldns-keygen.py
:language: python

View File

@@ -0,0 +1,17 @@
Signing of a zone file
===============================
This example shows how to sign the content of the given zone file
.. literalinclude:: ../../../examples/ldns-signzone.py
:language: python
In order to be able sign a zone file, you have to generate a key-pair using ``ldns-keygen.py``. Don't forget to modify tag number.
Signing consists of three steps
1. In the first step, the content of a zone file is read and parsed. This can be done using :class:`ldns.ldns_zone` class.
2. In the second step, the private and public key is read and public key is inserted into zone (as DNSKEY).
3. In the last step, the DNSSEC zone instance is created and all the RRs from zone file are copied here. Then, all the records are signed using :meth:`ldns.ldns_zone.sign` method. If the signing was successful, the content of DNSSEC zone is written to a file.

View File

@@ -0,0 +1,12 @@
Tutorials
==============================
Here you can find a set of simple applications which utilizes the ldns library in Python environment.
`Tutorials`
.. toctree::
:maxdepth: 1
:glob:
example*

View File

@@ -0,0 +1,22 @@
PyLDNS documentation
=======================================
PyLDNS provides an `LDNS`_ wrapper (Python extension module) - the thinnest layer over the library possible. Everything you can do from the C API, you can do from Python, but with less effort. The purpose of porting LDNS library to Python is to simplify DNS programming and usage of LDNS, however, still preserve the performance of this library as the speed represents the main benefit of LDNS. The proposed object approach allows the users to be concentrated at the essential part of application only and don't bother with deallocation of objects and so on.
.. _LDNS: http://www.nlnetlabs.nl/projects/ldns/
Contents
----------
.. toctree::
:maxdepth: 2
install.rst
examples/index.rst
modules/ldns
Indices and tables
-------------------
* :ref:`genindex`
* :ref:`search`

View File

@@ -0,0 +1,72 @@
Installation
===================================
**Prerequisites**
SWIG 1.3 and GNU make are required to build modules for Python 2.4 and higher
(but lower than 3). In order to build modules for Python 3.2 or higher,
SWIG in version 2.0.4 or higher is required.
Note that Python 3.0 and 3.1 are not supported.
In order to build this documentation the Sphinx Python documentation generator
is required.
**Download**
The latest source codes can be downloaded from `here`_.
.. _here: http://nlnetlabs.nl/projects/ldns/
**Compiling**
After downloading the source code archive (this example uses
ldns-1.6.13.tar.gz), pyLDNS can be enabled and compiled by typing::
> tar -xzf ldns-1.6.13.tar.gz
> cd ldns-1.6.13
> ./configure --with-pyldns
> make
You need GNU make to compile pyLDNS; SWIG and Python development libraries to
compile the extension module.
**Selecting Target Python Interpreter**
By default, the pyLDNS module builds for the default Python interpreter (i.e.,
the Python interpreter which can be accessed by just typing ``python`` in
the command line). If you desire to build the pyLDNS module for a different
Python version then you must specify the desired Python version by setting
the ``PYTHON_VERSION`` variable during the configure phase::
> PYTHON_VERSION=3.2 ./configure --with-pyldns
> make
By default the pyLDNS compiles from sources for a single Python interpreter.
Remember to execute scripts requiring pyLDNS in those Python interpreters which
have pyLDNS installed.
**Testing**
If the compilation is successful, you can test the python LDNS extension module
by executing the commands::
> cd contrib/python
> make testenv
> ./ldns-mx.py
Again, remember to use the Python interpreter version which the pyLDNS module
has been compiled with.
The commands will start a new shell, in which several symbolic links will be
set-up. When you exit the shell, then symbolic links will be deleted.
In ``contrib/python/examples`` several simple Python scripts utilising pyLDNS
can be found. These scripts demonstrate the capabilities of the LDNS library.
**Installation**
To install the libraries and it's extensions type::
> cd ldns-1.6.13
> make install

View File

@@ -0,0 +1,40 @@
LDNS module documentation
================================
Here you can find the documentation of pyLDNS extension module. This module consists of several classes and a couple of functions.
.. toctree::
:maxdepth: 1
:glob:
ldns_resolver
ldns_pkt
ldns_rr
ldns_rdf
ldns_dname
ldns_rr_list
ldns_zone
ldns_key
ldns_key_list
ldns_buffer
ldns_dnssec
ldns_func
**Differences against libLDNS**
* You don't need to use ldns-compare functions, instances can be compared using standard operators <, >, = ::
if (some_rr.owner() == another_rr.rdf(1)):
pass
* Classes contain static methods that create new instances, the name of these methods starts with the new\_ prefix (e.g. :meth:`ldns.ldns_pkt.new_frm_file`).
* Is it possible to print the content of an object using ``print objinst`` (see :meth:`ldns.ldns_resolver.get_addr_by_name`).
* Classes contain write_to_buffer method that writes the content into buffer.
* All the methods that consume parameter of (const ldns_rdf) type allows to use string instead (see :meth:`ldns.ldns_resolver.query`).

View File

@@ -0,0 +1,11 @@
Class ldns_buffer
================================
.. automodule:: ldns
Class ldns_buffer
------------------------------
.. autoclass:: ldns_buffer
:members:
:undoc-members:

View File

@@ -0,0 +1,11 @@
Class ldns_dname
================================
.. automodule:: ldns
Class ldns_dname
------------------------------
.. autoclass:: ldns_dname
:members:
:undoc-members:

View File

@@ -0,0 +1,28 @@
Class ldns_dnssec_zone
================================
.. automodule:: ldns
Class ldns_dnssec_zone
------------------------------
.. autoclass:: ldns_dnssec_zone
:members:
:undoc-members:
Class ldns_dnssec_name
------------------------------
.. autoclass:: ldns_dnssec_name
:members:
:undoc-members:
Class ldns_dnssec_rrsets
------------------------------
.. autoclass:: ldns_dnssec_rrsets
:members:
:undoc-members:
Class ldns_dnssec_rrs
------------------------------
.. autoclass:: ldns_dnssec_rrs
:members:
:undoc-members:

View File

@@ -0,0 +1,253 @@
Various functions
================================
Here you can find list of functions that are not assigned to the classes.
These functions have the same parameters as LDNS functions of the same name.
You are encouraged to read the LDNS documentation.
**List of functions**
* ldns_algorithm2buffer_str
* ldns_bget_keyword_data
* ldns_bget_token
* ldns_bgetc
* ldns_bskipcs
* ldns_bubblebabble
* ldns_buffer2pkt_wire
* ldns_buffer2str
* ldns_calc_keytag
* ldns_calc_keytag_raw
* ldns_cert_algorithm2buffer_str
* ldns_convert_dsa_rrsig_asn12rdf
* ldns_convert_dsa_rrsig_rdf2asn1
* ldns_create_nsec
* ldns_create_nsec3
* ldns_dname2buffer_wire
* ldns_dname2canonical
* ldns_dnssec_build_data_chain
* ldns_dnssec_chain_nsec3_list
* ldns_dnssec_create_nsec
* ldns_dnssec_create_nsec3
* ldns_dnssec_create_nsec_bitmap
* ldns_dnssec_data_chain_deep_free
* ldns_dnssec_data_chain_free
* ldns_dnssec_data_chain_new
* ldns_dnssec_data_chain_print
* ldns_dnssec_default_add_to_signatures
* ldns_dnssec_default_delete_signatures
* ldns_dnssec_default_leave_signatures
* ldns_dnssec_default_replace_signatures
* ldns_dnssec_derive_trust_tree
* ldns_dnssec_derive_trust_tree_dnskey_rrset
* ldns_dnssec_derive_trust_tree_ds_rrset
* ldns_dnssec_derive_trust_tree_no_sig
* ldns_dnssec_derive_trust_tree_normal_rrset
* ldns_dnssec_get_dnskey_for_rrsig
* ldns_dnssec_get_rrsig_for_name_and_type
* ldns_dnssec_nsec3_closest_encloser
* ldns_dnssec_pkt_get_rrsigs_for_name_and_type
* ldns_dnssec_pkt_get_rrsigs_for_type
* ldns_dnssec_pkt_has_rrsigs
* ldns_dnssec_remove_signatures
* ldns_dnssec_trust_tree_add_parent
* ldns_dnssec_trust_tree_contains_keys
* ldns_dnssec_trust_tree_depth
* ldns_dnssec_trust_tree_free
* ldns_dnssec_trust_tree_new
* ldns_dnssec_trust_tree_print
* ldns_dnssec_verify_denial
* ldns_dnssec_verify_denial_nsec3
* ldns_fetch_valid_domain_keys
* ldns_fget_keyword_data
* ldns_fget_keyword_data_l
* ldns_fget_token
* ldns_fget_token_l
* ldns_fskipcs
* ldns_fskipcs_l
* ldns_get_bit
* ldns_get_bit_r
* ldns_get_errorstr_by_id
* ldns_get_rr_class_by_name
* ldns_get_rr_list_addr_by_name
* ldns_get_rr_list_hosts_frm_file
* ldns_get_rr_list_hosts_frm_fp
* ldns_get_rr_list_hosts_frm_fp_l
* ldns_get_rr_list_name_by_addr
* ldns_get_rr_type_by_name
* ldns_getaddrinfo
* ldns_hexdigit_to_int
* ldns_hexstring_to_data
* ldns_init_random
* ldns_int_to_hexdigit
* ldns_is_rrset
* ldns_key2buffer_str
* ldns_key2rr
* ldns_key2str
* ldns_lookup_by_id
* ldns_lookup_by_name
* ldns_native2rdf_int16
* ldns_native2rdf_int16_data
* ldns_native2rdf_int32
* ldns_native2rdf_int8
* ldns_nsec3_add_param_rdfs
* ldns_nsec3_algorithm
* ldns_nsec3_bitmap
* ldns_nsec3_flags
* ldns_nsec3_hash_name
* ldns_nsec3_hash_name_frm_nsec3
* ldns_nsec3_iterations
* ldns_nsec3_next_owner
* ldns_nsec3_optout
* ldns_nsec3_salt
* ldns_nsec3_salt_data
* ldns_nsec3_salt_length
* ldns_nsec_bitmap_covers_type
* ldns_nsec_covers_name
* ldns_nsec_get_bitmap
* ldns_nsec_type_check
* ldns_octet
* ldns_pkt2buffer_str
* ldns_pkt2buffer_wire
* ldns_pkt2str
* ldns_pkt2wire
* ldns_pktheader2buffer_str
* ldns_power
* ldns_print_rr_rdf
* ldns_rbtree_create
* ldns_rbtree_delete
* ldns_rbtree_find_less_equal
* ldns_rbtree_first
* ldns_rbtree_free
* ldns_rbtree_init
* ldns_rbtree_insert
* ldns_rbtree_insert_vref
* ldns_rbtree_last
* ldns_rbtree_next
* ldns_rbtree_previous
* ldns_rbtree_search
* ldns_rdf2buffer_str
* ldns_rdf2buffer_str_a
* ldns_rdf2buffer_str_aaaa
* ldns_rdf2buffer_str_alg
* ldns_rdf2buffer_str_apl
* ldns_rdf2buffer_str_b64
* ldns_rdf2buffer_str_cert_alg
* ldns_rdf2buffer_str_class
* ldns_rdf2buffer_str_dname
* ldns_rdf2buffer_str_hex
* ldns_rdf2buffer_str_int16
* ldns_rdf2buffer_str_int16_data
* ldns_rdf2buffer_str_ipseckey
* ldns_rdf2buffer_str_loc
* ldns_rdf2buffer_str_nsap
* ldns_rdf2buffer_str_nsec
* ldns_rdf2buffer_str_period
* ldns_rdf2buffer_str_str
* ldns_rdf2buffer_str_tsig
* ldns_rdf2buffer_str_tsigtime
* ldns_rdf2buffer_str_type
* ldns_rdf2buffer_str_unknown
* ldns_rdf2buffer_str_wks
* ldns_rdf2buffer_wire
* ldns_rdf2buffer_wire_canonical
* ldns_rdf2native_int16
* ldns_rdf2native_int32
* ldns_rdf2native_int8
* ldns_rdf2native_sockaddr_storage
* ldns_rdf2native_time_t
* ldns_rdf2rr_type
* ldns_rdf2str
* ldns_rdf2wire
* ldns_read_anchor_file
* ldns_read_uint16
* ldns_read_uint32
* ldns_rr2buffer_str
* ldns_rr2buffer_wire
* ldns_rr2buffer_wire_canonical
* ldns_rr2canonical
* ldns_rr2str
* ldns_rr2wire
* ldns_rrsig2buffer_wire
* ldns_send
* ldns_send_buffer
* ldns_set_bit
* ldns_sign_public
* ldns_sockaddr_storage2rdf
* ldns_str2period
* ldns_str2rdf_a
* ldns_str2rdf_aaaa
* ldns_str2rdf_alg
* ldns_str2rdf_apl
* ldns_str2rdf_b32_ext
* ldns_str2rdf_b64
* ldns_str2rdf_cert_alg
* ldns_str2rdf_class
* ldns_str2rdf_dname
* ldns_str2rdf_hex
* ldns_str2rdf_int16
* ldns_str2rdf_int32
* ldns_str2rdf_int8
* ldns_str2rdf_loc
* ldns_str2rdf_nsap
* ldns_str2rdf_nsec
* ldns_str2rdf_nsec3_salt
* ldns_str2rdf_period
* ldns_str2rdf_service
* ldns_str2rdf_str
* ldns_str2rdf_time
* ldns_str2rdf_tsig
* ldns_str2rdf_type
* ldns_str2rdf_unknown
* ldns_str2rdf_wks
* ldns_tcp_bgsend
* ldns_tcp_connect
* ldns_tcp_read_wire
* ldns_tcp_send
* ldns_tcp_send_query
* ldns_traverse_postorder
* ldns_tsig_algorithm
* ldns_tsig_keydata
* ldns_tsig_keydata_clone
* ldns_tsig_keyname
* ldns_tsig_keyname_clone
* ldns_udp_bgsend
* ldns_udp_connect
* ldns_udp_read_wire
* ldns_udp_send
* ldns_udp_send_query
* ldns_update_pkt_new
* ldns_update_pkt_tsig_add
* ldns_update_prcount
* ldns_update_set_adcount
* ldns_update_set_prcount
* ldns_update_set_upcount
* ldns_update_soa_mname
* ldns_update_soa_zone_mname
* ldns_update_upcount
* ldns_update_zocount
* ldns_validate_domain_dnskey
* ldns_validate_domain_ds
* ldns_verify
* ldns_verify_rrsig
* ldns_verify_rrsig_buffers
* ldns_verify_rrsig_buffers_raw
* ldns_verify_rrsig_dsa
* ldns_verify_rrsig_dsa_raw
* ldns_verify_rrsig_keylist
* ldns_verify_rrsig_rsamd5
* ldns_verify_rrsig_rsamd5_raw
* ldns_verify_rrsig_rsasha1
* ldns_verify_rrsig_rsasha1_raw
* ldns_verify_rrsig_rsasha256_raw
* ldns_verify_rrsig_rsasha512_raw
* ldns_verify_trusted
* ldns_version
* ldns_wire2dname
* ldns_wire2pkt
* ldns_wire2rdf
* ldns_wire2rr
* ldns_write_uint16
* ldns_write_uint32
* ldns_write_uint64_as_uint48
* mktime_from_utc
* qsort_rr_compare_nsec3

View File

@@ -0,0 +1,11 @@
Class ldns_key
================================
.. automodule:: ldns
Class ldns_key
------------------------------
.. autoclass:: ldns_key
:members:
:undoc-members:

View File

@@ -0,0 +1,11 @@
Class ldns_key_list
================================
.. automodule:: ldns
Class ldns_key_list
------------------------------
.. autoclass:: ldns_key_list
:members:
:undoc-members:

View File

@@ -0,0 +1,11 @@
Class ldns_pkt
================================
.. automodule:: ldns
Class ldns_pkt
------------------------------
.. autoclass:: ldns_pkt
:members:
:undoc-members:

View File

@@ -0,0 +1,47 @@
Class ldns_rdf
================================
.. automodule:: ldns
Class ldns_rdf
------------------------------
.. autoclass:: ldns_rdf
:members:
:undoc-members:
Predefined constants
------------------------------
**RDF TYPE**
* LDNS_RDF_TYPE_NONE,
* LDNS_RDF_TYPE_DNAME,
* LDNS_RDF_TYPE_INT8,
* LDNS_RDF_TYPE_INT16,
* LDNS_RDF_TYPE_INT32,
* LDNS_RDF_TYPE_A,
* LDNS_RDF_TYPE_AAAA,
* LDNS_RDF_TYPE_STR,
* LDNS_RDF_TYPE_APL,
* LDNS_RDF_TYPE_B32_EXT,
* LDNS_RDF_TYPE_B64,
* LDNS_RDF_TYPE_HEX,
* LDNS_RDF_TYPE_NSEC,
* LDNS_RDF_TYPE_TYPE,
* LDNS_RDF_TYPE_CLASS,
* LDNS_RDF_TYPE_CERT_ALG,
* LDNS_RDF_TYPE_ALG,
* LDNS_RDF_TYPE_UNKNOWN,
* LDNS_RDF_TYPE_TIME,
* LDNS_RDF_TYPE_PERIOD,
* LDNS_RDF_TYPE_TSIGTIME,
* LDNS_RDF_TYPE_HIP,
* LDNS_RDF_TYPE_INT16_DATA,
* LDNS_RDF_TYPE_SERVICE,
* LDNS_RDF_TYPE_LOC,
* LDNS_RDF_TYPE_WKS,
* LDNS_RDF_TYPE_NSAP,
* LDNS_RDF_TYPE_IPSECKEY,
* LDNS_RDF_TYPE_NSEC3_SALT,
* LDNS_RDF_TYPE_NSEC3_NEXT_OWNER

View File

@@ -0,0 +1,13 @@
Class ldns_resolver
================================
.. automodule:: ldns
Class ldns_resolver
------------------------------
.. autoclass:: ldns_resolver
:members:
:undoc-members:

View File

@@ -0,0 +1,18 @@
Class ldns_rr
================================
.. automodule:: ldns
Class ldns_rr
------------------------------
.. autoclass:: ldns_rr
:members:
:undoc-members:
Class ldns_rr_descriptor
------------------------------
.. autoclass:: ldns_rr_descriptor
:members:
:undoc-members:

View File

@@ -0,0 +1,11 @@
Class ldns_rr_list
================================
.. automodule:: ldns
Class ldns_rr_list
------------------------------
.. autoclass:: ldns_rr_list
:members:
:undoc-members:

View File

@@ -0,0 +1,11 @@
Class ldns_zone
================================
.. automodule:: ldns
Class ldns_zone
------------------------------
.. autoclass:: ldns_zone
:members:
:undoc-members:

View File

@@ -0,0 +1,56 @@
#!/usr/bin/python
# vim:fileencoding=utf-8
#
# AXFR client with IDN (Internationalized Domain Names) support
#
import ldns
import encodings.idna
def utf2name(name):
return '.'.join([encodings.idna.ToASCII(a) for a in name.split('.')])
def name2utf(name):
return '.'.join([encodings.idna.ToUnicode(a) for a in name.split('.')])
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
#addr = ldns.ldns_get_rr_list_addr_by_name(resolver, "zone.nic.cz", ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD);
addr = resolver.get_addr_by_name("zone.nic.cz", ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD);
if (not addr):
raise Exception("Can't retrieve server address")
print "Addr_by_name:",str(addr).replace("\n","; ")
#remove all nameservers
while resolver.pop_nameserver():
pass
#insert server addr
for rr in addr.rrs():
resolver.push_nameserver_rr(rr)
#AXFR transfer
status = resolver.axfr_start(utf2name(u"háčkyčárky.cz"), ldns.LDNS_RR_CLASS_IN)
if status != ldns.LDNS_STATUS_OK:
raise Exception("Can't start AXFR. Error: %s" % ldns.ldns_get_errorstr_by_id(status))
#Print results
while True:
rr = resolver.axfr_next()
if not rr:
break
rdf = rr.owner()
if (rdf.get_type() == ldns.LDNS_RDF_TYPE_DNAME):
print "RDF owner: type=",rdf.get_type_str(),"data=",name2utf(str(rdf))
else:
print "RDF owner: type=",rdf.get_type_str(),"data=",str(rdf)
print " RR type=", rr.get_type_str()," ttl=",rr.ttl()
for rdf in rr.rdfs():
if (rdf.get_type() == ldns.LDNS_RDF_TYPE_DNAME):
print " RDF: type=",rdf.get_type_str(),"data=",name2utf(str(rdf))
else:
print " RDF: type=",rdf.get_type_str(),"data=",str(rdf)
print

View File

@@ -0,0 +1,8 @@
#!/usr/bin/python
import ldns
buf = ldns.ldns_buffer(1024)
buf.printf("Test buffer")
print buf

View File

@@ -0,0 +1,45 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import ldns
import sys
debug = True
# Check args
argc = len(sys.argv)
name = "www.nic.cz"
if argc < 2:
print "Usage:", sys.argv[0], "domain [resolver_addr]"
sys.exit(1)
else:
name = sys.argv[1]
# Create resolver
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
resolver.set_dnssec(True)
# Custom resolver
if argc > 2:
# Clear previous nameservers
ns = resolver.pop_nameserver()
while ns != None:
ns = resolver.pop_nameserver()
ip = ldns.ldns_rdf.new_frm_str(sys.argv[2], ldns.LDNS_RDF_TYPE_A)
resolver.push_nameserver(ip)
# Resolve DNS name
pkt = resolver.query(name, ldns.LDNS_RR_TYPE_A, ldns.LDNS_RR_CLASS_IN)
if pkt and pkt.answer():
# Debug
if debug:
print "NS returned:", pkt.get_rcode(), "(AA: %d AD: %d)" % ( pkt.ad(), pkt.ad() )
# SERVFAIL indicated bogus name
if pkt.get_rcode() is ldns.LDNS_RCODE_SERVFAIL:
print name, "is bogus"
# Check AD (Authenticated) bit
if pkt.get_rcode() is ldns.LDNS_RCODE_NOERROR:
if pkt.ad(): print name, "is secure"
else: print name, "is insecure"

View File

@@ -0,0 +1,36 @@
#!/usr/bin/python
import ldns
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
dnn = ldns.ldns_dname("www.google.com")
print dnn.get_type_str(), dnn
dna = ldns.ldns_rdf.new_frm_str("74.125.43.99",ldns.LDNS_RDF_TYPE_A)
print dna.get_type_str(), dna
name = resolver.get_name_by_addr(dna)
if (not name): raise Exception("Can't retrieve server name")
for rr in name.rrs():
print rr
name = resolver.get_name_by_addr("74.125.43.99")
if (not name): raise Exception("Can't retrieve server name")
for rr in name.rrs():
print rr
addr = resolver.get_addr_by_name(dnn)
if (not addr): raise Exception("Can't retrieve server address")
for rr in addr.rrs():
print rr
addr = resolver.get_addr_by_name("www.google.com")
if (not addr): raise Exception("Can't retrieve server address")
for rr in addr.rrs():
print rr
hosts = ldns.ldns_rr_list.new_frm_file("/etc/hosts")
if (not hosts): raise Exception("Can't retrieve the content of file")
for rr in hosts.rrs():
print rr

View File

@@ -0,0 +1,46 @@
#!/usr/bin/python
#
# This example shows how to generate public/private key pair
#
import ldns
algorithm = ldns.LDNS_SIGN_DSA
bits = 512
ldns.ldns_init_random(open("/dev/urandom","rb"), (bits+7)//8)
domain = ldns.ldns_dname("example.")
#generate a new key
key = ldns.ldns_key.new_frm_algorithm(algorithm, bits);
print key
#set owner
key.set_pubkey_owner(domain)
#create the public from the ldns_key
pubkey = key.key_to_rr()
#previous command is equivalent to
# pubkey = ldns.ldns_key2rr(key)
print pubkey
#calculate and set the keytag
key.set_keytag(ldns.ldns_calc_keytag(pubkey))
#build the DS record
ds = ldns.ldns_key_rr2ds(pubkey, ldns.LDNS_SHA1)
print ds
owner, tag = pubkey.owner(), key.keytag()
#write public key to .key file
fw = open("key-%s-%d.key" % (owner,tag), "wb")
pubkey.print_to_file(fw)
#write private key to .priv file
fw = open("key-%s-%d.private" % (owner,tag), "wb")
key.print_to_file(fw)
#write DS to .ds file
fw = open("key-%s-%d.ds" % (owner,tag), "wb")
ds.print_to_file(fw)

View File

@@ -0,0 +1,15 @@
#!/usr/bin/python
#
# MX is a small program that prints out the mx records for a particular domain
#
import ldns
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
pkt = resolver.query("nic.cz", ldns.LDNS_RR_TYPE_MX,ldns.LDNS_RR_CLASS_IN)
if (pkt):
mx = pkt.rr_list_by_type(ldns.LDNS_RR_TYPE_MX, ldns.LDNS_SECTION_ANSWER)
if (mx):
mx.sort()
print mx

View File

@@ -0,0 +1,18 @@
#!/usr/bin/python
#
# MX is a small program that prints out the mx records for a particular domain
#
import ldns
dname = ldns.ldns_dname("nic.cz")
print dname
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
pkt = resolver.query(dname, ldns.LDNS_RR_TYPE_MX,ldns.LDNS_RR_CLASS_IN)
if (pkt):
mx = pkt.rr_list_by_type(ldns.LDNS_RR_TYPE_MX, ldns.LDNS_SECTION_ANSWER)
if (mx):
mx.sort()
print mx

View File

@@ -0,0 +1,19 @@
#!/usr/bin/python
#
# MX is a small program that prints out the mx records for a particular domain
#
import ldns
resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
pkt = resolver.query("nic.cz", ldns.LDNS_RR_TYPE_MX,ldns.LDNS_RR_CLASS_IN)
if (pkt) and (pkt.answer()):
for rr in pkt.answer().rrs():
if (rr.get_type() != ldns.LDNS_RR_TYPE_MX):
continue
rdf = rr.owner()
print rdf," ",rr.ttl()," ",rr.get_class_str()," ",rr.get_type_str()," ",
print " ".join(str(rdf) for rdf in rr.rdfs())

View File

@@ -0,0 +1,17 @@
#!/usr/bin/python
import ldns
pkt = ldns.ldns_pkt.new_query_frm_str("www.google.com",ldns.LDNS_RR_TYPE_ANY, ldns.LDNS_RR_CLASS_IN, ldns.LDNS_QR | ldns.LDNS_AA)
rra = ldns.ldns_rr.new_frm_str("www.google.com. IN A 192.168.1.1",300)
rrb = ldns.ldns_rr.new_frm_str("www.google.com. IN TXT Some\ Description",300)
list = ldns.ldns_rr_list()
if (rra): list.push_rr(rra)
if (rrb): list.push_rr(rrb)
pkt.push_rr_list(ldns.LDNS_SECTION_ANSWER, list)
print "Packet:"
print pkt

View File

@@ -0,0 +1,65 @@
#!/usr/bin/python
# This example shows how to sign a given zone file with private key
import ldns
import sys, os, time
#private key TAG which identifies the private key
#use ldns-keygen.py in order to obtain private key
keytag = 30761
# Read zone file
#-------------------------------------------------------------
zone = ldns.ldns_zone.new_frm_fp(open("zone.txt","r"), None, 0, ldns.LDNS_RR_CLASS_IN)
soa = zone.soa()
origin = soa.owner()
# Prepare keys
#-------------------------------------------------------------
#Read private key from file
keyfile = open("key-%s-%d.private" % (origin, keytag), "r");
key = ldns.ldns_key.new_frm_fp(keyfile)
#Read public key from file
pubfname = "key-%s-%d.key" % (origin, keytag)
pubkey = None
if os.path.isfile(pubfname):
pubkeyfile = open(pubfname, "r");
pubkey,_,_,_ = ldns.ldns_rr.new_frm_fp(pubkeyfile)
if not pubkey:
#Create new public key
pubkey = key.key_to_rr()
#Set key expiration
key.set_expiration(int(time.time()) + 365*60*60*24) #365 days
#Set key owner (important step)
key.set_pubkey_owner(origin)
#Insert DNSKEY RR
zone.push_rr(pubkey)
# Sign zone
#-------------------------------------------------------------
#Create keylist and push private key
keys = ldns.ldns_key_list()
keys.push_key(key)
#Add SOA
signed_zone = ldns.ldns_dnssec_zone()
signed_zone.add_rr(soa)
#Add RRs
for rr in zone.rrs().rrs():
print "RR:",str(rr),
signed_zone.add_rr(rr)
added_rrs = ldns.ldns_rr_list()
status = signed_zone.sign(added_rrs, keys)
if (status == ldns.LDNS_STATUS_OK):
signed_zone.print_to_file(open("zone_signed.txt","w"))

Some files were not shown because too many files have changed in this diff Show More