ldns base 1.6.9 from tarball

This commit is contained in:
Jeff Lenk
2011-03-25 11:23:32 -05:00
parent d09f96d44f
commit 579927b53a
240 changed files with 115445 additions and 0 deletions

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,67 @@
# 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.
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " testenv to make test environment and run bash "
@echo " usefull 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/ldns.so.1: ../../Makefile
$(MAKE) -C ../..
clean:
rm -rdf examples/ldns
rm -f _ldns.so ldns_wrapper.o
$(MAKE) -C ../.. clean
testenv: ../../.libs/libldns.so.1 _ldns.so
rm -rdf examples/ldns
cd examples && mkdir ldns && ln -s ../../ldns.py ldns/__init__.py && ln -s ../../_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 -rdf examples/ldns
doc: ../../.libs/ldns.so.1 _ldns.so
$(MAKE) -C docs html
#for development only
swig: ldns.i
swig -python -o ldns_wrapper.c -I../.. ldns.i
gcc -c ldns_wrapper.c -O9 -fPIC -I../.. -I../../ldns -I/usr/include/python2.5 -I. -o ldns_wrapper.o
ld -shared ldns_wrapper.o -L../../.libs -lldns -o _ldns.so

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, 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.0'
# The full version, including alpha/beta/rc tags.
release = '1.0.0'
# 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 simplier 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 readed and parsed. This can be done using :class:`ldns.ldns_zone` class.
2. In the second step, the private and public key is readed and public key is inserted into zone (as DNSKEY).
3. In the last step, the DNSSEC zone instace 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 successfull, 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,46 @@
Installation
===================================
**Prerequisites**
Python 2.4 or higher, SWIG 1.3 or higher, GNU make
**Download**
You can download the source codes `here`_.
The latest release is 1.4.1, Jan 15, 2009.
.. _here: ldns-1.4.1-py.tar.gz
**Compiling**
After downloading, you can compile the library by doing::
> tar -xzf ldns-1.4.1-py.tar.gz
> cd ldns-1.4.1
> ./configure --with-pyldns
> make
You need GNU make to compile pyLDNS; SWIG and Python development libraries to compile extension module.
**Testing**
If the compilation is successfull, you can test the python LDNS extension module by::
> cd contrib/python
> make testenv
> ./ldns-mx.py
This will start a new shell, during which the symbolic links will be working.
When you exit the shell, then symbolic links will be deleted.
In ``contrib/examples`` you can find many simple applications in python which demostrates the capabilities of LDNS library.
**Installation**
To install libraries and extension type::
> cd ldns-1.4.1
> 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_TSIG,
* 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/random","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"))

View File

@@ -0,0 +1,15 @@
#!/usr/bin/python
import ldns
#Read zone from file
zone = ldns.ldns_zone.new_frm_fp(open("zone.txt","r"), None, 0, ldns.LDNS_RR_CLASS_IN)
print zone
print "SOA:", zone.soa()
for r in zone.rrs().rrs():
print "RR:", r
zone = ldns.ldns_zone()
#print zone

View File

@@ -0,0 +1,15 @@
$ORIGIN example.
$TTL 600
example. IN SOA example. admin.example. (
2008022501 ; serial
28800 ; refresh (8 hours)
7200 ; retry (2 hours)
604800 ; expire (1 week)
18000 ; minimum (5 hours)
)
@ IN MX 10 mail.example.
@ IN NS ns1
@ IN NS ns2
@ IN A 192.168.1.1

View File

@@ -0,0 +1,267 @@
/*
* ldns.i: LDNS interface file
*
* 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.
*/
%module ldns
%{
#include "ldns.h"
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ldns/util.h>
#include <ldns/buffer.h>
#include <ldns/common.h>
#include <ldns/dname.h>
#include <ldns/dnssec.h>
#include <ldns/dnssec_verify.h>
#include <ldns/dnssec_sign.h>
#include <ldns/error.h>
#include <ldns/higher.h>
#include <ldns/host2str.h>
#include <ldns/host2wire.h>
#include <ldns/net.h>
#include <ldns/packet.h>
#include <ldns/rdata.h>
#include <ldns/resolver.h>
#include <ldns/rr.h>
#include <ldns/str2host.h>
#include <ldns/tsig.h>
#include <ldns/update.h>
#include <ldns/wire2host.h>
#include <ldns/rr_functions.h>
#include <ldns/keys.h>
#include <ldns/parse.h>
#include <ldns/zone.h>
#include <ldns/dnssec_zone.h>
#include <ldns/rbtree.h>
%}
//#define LDNS_DEBUG
%include "stdint.i" // uint_16_t is known type now
%include "file.i" // FILE *
%include "typemaps.i"
%inline %{
struct timeval* ldns_make_timeval(uint32_t sec, uint32_t usec)
{
struct timeval* res = (struct timeval*)malloc(sizeof(*res));
res->tv_sec = sec;
res->tv_usec = usec;
return res;
}
uint32_t ldns_read_timeval_sec(struct timeval* t) {
return (uint32_t)t->tv_sec; }
uint32_t ldns_read_timeval_usec(struct timeval* t) {
return (uint32_t)t->tv_usec; }
%}
%immutable ldns_struct_lookup_table::name;
%immutable ldns_struct_rr_descriptor::_name;
%immutable ldns_error_str;
%immutable ldns_signing_algorithms;
//new_frm_fp_l
%apply int *OUTPUT { int *line_nr};
%apply uint32_t *OUTPUT { uint32_t *default_ttl};
%include "ldns_packet.i"
%include "ldns_resolver.i"
%include "ldns_rr.i"
%include "ldns_rdf.i"
%include "ldns_zone.i"
%include "ldns_key.i"
%include "ldns_buffer.i"
%include "ldns_dnssec.i"
%include <ldns/util.h>
%include <ldns/buffer.h>
%include <ldns/dnssec.h>
%include <ldns/dnssec_verify.h>
%include <ldns/dnssec_sign.h>
%include <ldns/error.h>
%include <ldns/higher.h>
%include <ldns/host2str.h>
%include <ldns/host2wire.h>
%include <ldns/net.h>
%include <ldns/packet.h>
%include <ldns/rdata.h>
%include <ldns/resolver.h>
%include <ldns/rr.h>
%include <ldns/str2host.h>
%include <ldns/tsig.h>
%include <ldns/update.h>
%include <ldns/wire2host.h>
%include <ldns/rr_functions.h>
%include <ldns/keys.h>
%include <ldns/parse.h>
%include <ldns/zone.h>
%include <ldns/dnssec_zone.h>
%include <ldns/rbtree.h>
%include <ldns/dname.h>
typedef struct ldns_dnssec_name { };
typedef struct ldns_dnssec_rrs { };
typedef struct ldns_dnssec_rrsets { };
typedef struct ldns_dnssec_zone { };
// ================================================================================
%include "ldns_dname.i"
%inline %{
PyObject* ldns_rr_new_frm_str_(const char *str, uint32_t default_ttl, ldns_rdf* origin, ldns_rdf* prev)
//returns tuple (status, ldns_rr, prev)
{
PyObject* tuple;
ldns_rdf *p_prev = prev;
ldns_rdf **pp_prev = &p_prev;
if (p_prev == 0) pp_prev = 0;
ldns_rr *p_rr = 0;
ldns_rr **pp_rr = &p_rr;
ldns_status st = ldns_rr_new_frm_str(pp_rr, str, default_ttl, origin, pp_prev);
tuple = PyTuple_New(3);
PyTuple_SetItem(tuple, 0, SWIG_From_int(st));
PyTuple_SetItem(tuple, 1, (st == LDNS_STATUS_OK) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_rr), SWIGTYPE_p_ldns_struct_rr, SWIG_POINTER_OWN | 0 ) :
Py_None);
PyTuple_SetItem(tuple, 2, (p_prev != prev) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_prev), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 ) :
Py_None);
return tuple;
}
PyObject* ldns_rr_new_frm_fp_l_(FILE *fp, uint32_t default_ttl, ldns_rdf* origin, ldns_rdf* prev, int ret_linenr)
//returns tuple (status, ldns_rr, [line if ret_linenr], ttl, origin, prev)
{
int linenr = 0;
int *p_linenr = &linenr;
uint32_t defttl = default_ttl;
uint32_t *p_defttl = &defttl;
if (defttl == 0) p_defttl = 0;
ldns_rdf *p_origin = origin;
ldns_rdf **pp_origin = &p_origin;
if (p_origin == 0) pp_origin = 0;
ldns_rdf *p_prev = prev;
ldns_rdf **pp_prev = &p_prev;
if (p_prev == 0) pp_prev = 0;
ldns_rr *p_rr = 0;
ldns_rr **pp_rr = &p_rr;
ldns_status st = ldns_rr_new_frm_fp_l(pp_rr, fp, p_defttl, pp_origin, pp_prev, p_linenr);
PyObject* tuple;
tuple = PyTuple_New(ret_linenr ? 6 : 5);
int idx = 0;
PyTuple_SetItem(tuple, idx, SWIG_From_int(st));
idx++;
PyTuple_SetItem(tuple, idx, (st == LDNS_STATUS_OK) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_rr), SWIGTYPE_p_ldns_struct_rr, SWIG_POINTER_OWN | 0 ) :
Py_None);
idx++;
if (ret_linenr) {
PyTuple_SetItem(tuple, idx, SWIG_From_int(linenr));
idx++;
}
PyTuple_SetItem(tuple, idx, (defttl != default_ttl) ? SWIG_From_int(defttl) : Py_None);
idx++;
PyTuple_SetItem(tuple, idx, (p_origin != origin) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_origin), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 ) :
Py_None);
idx++;
PyTuple_SetItem(tuple, idx, (p_prev != prev) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_prev), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 ) :
Py_None);
return tuple;
}
PyObject* ldns_rr_new_question_frm_str_(const char *str, ldns_rdf* origin, ldns_rdf* prev)
//returns tuple (status, ldns_rr, prev)
{
PyObject* tuple;
ldns_rdf *p_prev = prev;
ldns_rdf **pp_prev = &p_prev;
if (p_prev == 0) pp_prev = 0;
ldns_rr *p_rr = 0;
ldns_rr **pp_rr = &p_rr;
ldns_status st = ldns_rr_new_question_frm_str(pp_rr, str, origin, pp_prev);
tuple = PyTuple_New(3);
PyTuple_SetItem(tuple, 0, SWIG_From_int(st));
PyTuple_SetItem(tuple, 1, (st == LDNS_STATUS_OK) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_rr), SWIGTYPE_p_ldns_struct_rr, SWIG_POINTER_OWN | 0 ) :
Py_None);
PyTuple_SetItem(tuple, 2, (p_prev != prev) ?
SWIG_NewPointerObj(SWIG_as_voidptr(p_prev), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 ) :
Py_None);
return tuple;
}
PyObject* ldns_fetch_valid_domain_keys_(const ldns_resolver * res, const ldns_rdf * domain,
const ldns_rr_list * keys)
//returns tuple (status, result)
{
PyObject* tuple;
ldns_rr_list *rrl = 0;
ldns_status st = 0;
rrl = ldns_fetch_valid_domain_keys(res, domain, keys, &st);
tuple = PyTuple_New(2);
PyTuple_SetItem(tuple, 0, SWIG_From_int(st));
PyTuple_SetItem(tuple, 1, (st == LDNS_STATUS_OK) ?
SWIG_NewPointerObj(SWIG_as_voidptr(rrl), SWIGTYPE_p_ldns_struct_rr_list, SWIG_POINTER_OWN | 0 ) :
Py_None);
return tuple;
}
%}
%pythoncode %{
def ldns_fetch_valid_domain_keys(res, domain, keys):
return _ldns.ldns_fetch_valid_domain_keys_(res, domain, keys)
%}

View File

@@ -0,0 +1,560 @@
/******************************************************************************
* ldns_buffer.i: LDNS buffer class
*
* 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.
******************************************************************************/
%typemap(in,numinputs=0,noblock=1) (ldns_buffer **)
{
ldns_buffer *$1_buf;
$1 = &$1_buf;
}
/* result generation */
%typemap(argout,noblock=1) (ldns_buffer **)
{
$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr($1_buf), SWIGTYPE_p_ldns_struct_buffer, SWIG_POINTER_OWN | 0 ));
}
%nodefaultctor ldns_struct_buffer; //no default constructor & destructor
%nodefaultdtor ldns_struct_buffer;
%delobject ldns_buffer_free;
%newobject ldns_buffer_new;
%newobject ldns_dname_new;
%newobject ldns_dname_new_frm_data;
%newobject ldns_dname_label;
%rename(ldns_buffer) ldns_struct_buffer;
#ifdef LDNS_DEBUG
%rename(__ldns_buffer_free) ldns_buffer_free;
%inline %{
void _ldns_buffer_free (ldns_buffer* b) {
printf("******** LDNS_BUFFER free 0x%lX ************\n", (long unsigned int)b);
ldns_buffer_free(b);
}
%}
#else
%rename(_ldns_buffer_free) ldns_buffer_free;
#endif
%ignore ldns_struct_buffer::_position;
%ignore ldns_struct_buffer::_limit;
%ignore ldns_struct_buffer::_capacity;
%ignore ldns_struct_buffer::_data;
%ignore ldns_struct_buffer::_fixed;
%ignore ldns_struct_buffer::_status;
%extend ldns_struct_buffer {
%pythoncode %{
def __init__(self, capacity):
"""Creates a new buffer with the specified capacity.
:param capacity: the size (in bytes) to allocate for the buffer
"""
self.this = _ldns.ldns_buffer_new(capacity)
__swig_destroy__ = _ldns._ldns_buffer_free
def __str__(self):
"""Returns the data in the buffer as a string. Buffer data must be char * type."""
return _ldns.ldns_buffer2str(self)
def getc(self):
"""returns the next character from a buffer.
Advances the position pointer with 1. When end of buffer is reached returns EOF. This is the buffer's equivalent for getc().
:returns: (int) EOF on failure otherwise return the character
"""
return _ldns.ldns_bgetc(self)
#LDNS_BUFFER_METHODS_#
def at(self,at):
"""returns a pointer to the data at the indicated position.
:param at:
position
:returns: (uint8_t \*) the pointer to the data
"""
return _ldns.ldns_buffer_at(self,at)
#parameters: const ldns_buffer *,size_t,
#retvals: uint8_t *
def available(self,count):
"""checks if the buffer has count bytes available at the current position
:param count:
how much is available
:returns: (int) true or false
"""
return _ldns.ldns_buffer_available(self,count)
#parameters: ldns_buffer *,size_t,
#retvals: int
def available_at(self,at,count):
"""checks if the buffer has at least COUNT more bytes available.
Before reading or writing the caller needs to ensure enough space is available!
:param at:
indicated position
:param count:
how much is available
:returns: (int) true or false
"""
return _ldns.ldns_buffer_available_at(self,at,count)
#parameters: ldns_buffer *,size_t,size_t,
#retvals: int
def begin(self):
"""returns a pointer to the beginning of the buffer (the data at position 0).
:returns: (uint8_t \*) the pointer
"""
return _ldns.ldns_buffer_begin(self)
#parameters: const ldns_buffer *,
#retvals: uint8_t *
def capacity(self):
"""returns the number of bytes the buffer can hold.
:returns: (size_t) the number of bytes
"""
return _ldns.ldns_buffer_capacity(self)
#parameters: ldns_buffer *,
#retvals: size_t
def clear(self):
"""clears the buffer and make it ready for writing.
The buffer's limit is set to the capacity and the position is set to 0.
"""
_ldns.ldns_buffer_clear(self)
#parameters: ldns_buffer *,
#retvals:
def copy(self,bfrom):
"""Copy contents of the other buffer to this buffer.
Silently truncated if this buffer is too small.
:param bfrom: other buffer
"""
_ldns.ldns_buffer_copy(self,bfrom)
#parameters: ldns_buffer *,ldns_buffer *,
#retvals:
def current(self):
"""returns a pointer to the data at the buffer's current position.
:returns: (uint8_t \*) the pointer
"""
return _ldns.ldns_buffer_current(self)
#parameters: ldns_buffer *,
#retvals: uint8_t *
def end(self):
"""returns a pointer to the end of the buffer (the data at the buffer's limit).
:returns: (uint8_t \*) the pointer
"""
return _ldns.ldns_buffer_end(self)
#parameters: ldns_buffer *,
#retvals: uint8_t *
def export(self):
"""Makes the buffer fixed and returns a pointer to the data.
The caller is responsible for free'ing the result.
:returns: (void \*) void
"""
return _ldns.ldns_buffer_export(self)
#parameters: ldns_buffer *,
#retvals: void *
def flip(self):
"""makes the buffer ready for reading the data that has been written to the buffer.
The buffer's limit is set to the current position and the position is set to 0.
"""
_ldns.ldns_buffer_flip(self)
#parameters: ldns_buffer *,
def invariant(self):
_ldns.ldns_buffer_invariant(self)
#parameters: ldns_buffer *,
def limit(self):
"""returns the maximum size of the buffer
:returns: (size_t) the size
"""
return _ldns.ldns_buffer_limit(self)
#parameters: ldns_buffer *,
#retvals: size_t
def position(self):
"""returns the current position in the buffer (as a number of bytes)
:returns: (size_t) the current position
"""
return _ldns.ldns_buffer_position(self)
#parameters: ldns_buffer *,
#retvals: size_t
def printf(self,*str):
"""Prints to the buffer, increasing the capacity if required using buffer_reserve().
The buffer's position is set to the terminating '\0'. Returns the number of characters written (not including the terminating '\0') or -1 on failure.
:param str: a string
:returns: (int)
"""
return _ldns.ldns_buffer_printf(self,*str)
#parameters: ldns_buffer *,const char *,...
#retvals: int
def read(self,data,count):
"""copies count bytes of data at the current position to the given data-array
:param data:
buffer to copy to
:param count:
the length of the data to copy
"""
_ldns.ldns_buffer_read(self,data,count)
#parameters: ldns_buffer *,void *,size_t,
#retvals:
def read_at(self,at,data,count):
"""copies count bytes of data at the given position to the given data-array
:param at:
the position in the buffer to start
:param data:
buffer to copy to
:param count:
the length of the data to copy
"""
_ldns.ldns_buffer_read_at(self,at,data,count)
#parameters: ldns_buffer *,size_t,void *,size_t,
#retvals:
def read_u16(self):
"""returns the 2-byte integer value at the current position in the buffer
:returns: (uint16_t) 2 byte integer
"""
return _ldns.ldns_buffer_read_u16(self)
#parameters: ldns_buffer *,
#retvals: uint16_t
def read_u16_at(self,at):
"""returns the 2-byte integer value at the given position in the buffer
:param at:
position in the buffer
:returns: (uint16_t) 2 byte integer
"""
return _ldns.ldns_buffer_read_u16_at(self,at)
#parameters: ldns_buffer *,size_t,
#retvals: uint16_t
def read_u32(self):
"""returns the 4-byte integer value at the current position in the buffer
:returns: (uint32_t) 4 byte integer
"""
return _ldns.ldns_buffer_read_u32(self)
#parameters: ldns_buffer *,
#retvals: uint32_t
def read_u32_at(self,at):
"""returns the 4-byte integer value at the given position in the buffer
:param at:
position in the buffer
:returns: (uint32_t) 4 byte integer
"""
return _ldns.ldns_buffer_read_u32_at(self,at)
#parameters: ldns_buffer *,size_t,
#retvals: uint32_t
def read_u8(self):
"""returns the byte value at the current position in the buffer
:returns: (uint8_t) 1 byte integer
"""
return _ldns.ldns_buffer_read_u8(self)
#parameters: ldns_buffer *,
#retvals: uint8_t
def read_u8_at(self,at):
"""returns the byte value at the given position in the buffer
:param at:
the position in the buffer
:returns: (uint8_t) 1 byte integer
"""
return _ldns.ldns_buffer_read_u8_at(self,at)
#parameters: ldns_buffer *,size_t,
#retvals: uint8_t
def remaining(self):
"""returns the number of bytes remaining between the buffer's position and limit.
:returns: (size_t) the number of bytes
"""
return _ldns.ldns_buffer_remaining(self)
#parameters: ldns_buffer *,
#retvals: size_t
def remaining_at(self,at):
"""returns the number of bytes remaining between the indicated position and the limit.
:param at:
indicated position
:returns: (size_t) number of bytes
"""
return _ldns.ldns_buffer_remaining_at(self,at)
#parameters: ldns_buffer *,size_t,
#retvals: size_t
def reserve(self,amount):
"""ensures BUFFER can contain at least AMOUNT more bytes.
The buffer's capacity is increased if necessary using buffer_set_capacity().
The buffer's limit is always set to the (possibly increased) capacity.
:param amount:
amount to use
:returns: (bool) whether this failed or succeeded
"""
return _ldns.ldns_buffer_reserve(self,amount)
#parameters: ldns_buffer *,size_t,
#retvals: bool
def rewind(self):
"""make the buffer ready for re-reading the data.
The buffer's position is reset to 0.
"""
_ldns.ldns_buffer_rewind(self)
#parameters: ldns_buffer *,
#retvals:
def set_capacity(self,capacity):
"""changes the buffer's capacity.
The data is reallocated so any pointers to the data may become invalid. The buffer's limit is set to the buffer's new capacity.
:param capacity:
the capacity to use
:returns: (bool) whether this failed or succeeded
"""
return _ldns.ldns_buffer_set_capacity(self,capacity)
#parameters: ldns_buffer *,size_t,
#retvals: bool
def set_limit(self,limit):
"""changes the buffer's limit.
If the buffer's position is greater than the new limit the position is set to the limit.
:param limit:
the new limit
"""
_ldns.ldns_buffer_set_limit(self,limit)
#parameters: ldns_buffer *,size_t,
#retvals:
def set_position(self,mark):
"""sets the buffer's position to MARK.
The position must be less than or equal to the buffer's limit.
:param mark:
the mark to use
"""
_ldns.ldns_buffer_set_position(self,mark)
#parameters: ldns_buffer *,size_t,
#retvals:
def skip(self,count):
"""changes the buffer's position by COUNT bytes.
The position must not be moved behind the buffer's limit or before the beginning of the buffer.
:param count:
the count to use
"""
_ldns.ldns_buffer_skip(self,count)
#parameters: ldns_buffer *,ssize_t,
#retvals:
def status(self):
"""returns the status of the buffer
:returns: (ldns_status) the status
"""
return _ldns.ldns_buffer_status(self)
#parameters: ldns_buffer *,
#retvals: ldns_status
def status_ok(self):
"""returns true if the status of the buffer is LDNS_STATUS_OK, false otherwise
:returns: (bool) true or false
"""
return _ldns.ldns_buffer_status_ok(self)
#parameters: ldns_buffer *,
#retvals: bool
def write(self,data,count):
"""writes count bytes of data to the current position of the buffer
:param data:
the data to write
:param count:
the lenght of the data to write
"""
_ldns.ldns_buffer_write(self,data,count)
#parameters: ldns_buffer *,const void *,size_t,
#retvals:
def write_at(self,at,data,count):
"""writes the given data to the buffer at the specified position
:param at:
the position (in number of bytes) to write the data at
:param data:
pointer to the data to write to the buffer
:param count:
the number of bytes of data to write
"""
_ldns.ldns_buffer_write_at(self,at,data,count)
#parameters: ldns_buffer *,size_t,const void *,size_t,
#retvals:
def write_string(self,str):
"""copies the given (null-delimited) string to the current position at the buffer
:param str:
the string to write
"""
_ldns.ldns_buffer_write_string(self,str)
#parameters: ldns_buffer *,const char *,
#retvals:
def write_string_at(self,at,str):
"""copies the given (null-delimited) string to the specified position at the buffer
:param at:
the position in the buffer
:param str:
the string to write
"""
_ldns.ldns_buffer_write_string_at(self,at,str)
#parameters: ldns_buffer *,size_t,const char *,
#retvals:
def write_u16(self,data):
"""writes the given 2 byte integer at the current position in the buffer
:param data:
the 16 bits to write
"""
_ldns.ldns_buffer_write_u16(self,data)
#parameters: ldns_buffer *,uint16_t,
#retvals:
def write_u16_at(self,at,data):
"""writes the given 2 byte integer at the given position in the buffer
:param at:
the position in the buffer
:param data:
the 16 bits to write
"""
_ldns.ldns_buffer_write_u16_at(self,at,data)
#parameters: ldns_buffer *,size_t,uint16_t,
#retvals:
def write_u32(self,data):
"""writes the given 4 byte integer at the current position in the buffer
:param data:
the 32 bits to write
"""
_ldns.ldns_buffer_write_u32(self,data)
#parameters: ldns_buffer *,uint32_t,
#retvals:
def write_u32_at(self,at,data):
"""writes the given 4 byte integer at the given position in the buffer
:param at:
the position in the buffer
:param data:
the 32 bits to write
"""
_ldns.ldns_buffer_write_u32_at(self,at,data)
#parameters: ldns_buffer *,size_t,uint32_t,
#retvals:
def write_u8(self,data):
"""writes the given byte of data at the current position in the buffer
:param data:
the 8 bits to write
"""
_ldns.ldns_buffer_write_u8(self,data)
#parameters: ldns_buffer *,uint8_t,
#retvals:
def write_u8_at(self,at,data):
"""writes the given byte of data at the given position in the buffer
:param at:
the position in the buffer
:param data:
the 8 bits to write
"""
_ldns.ldns_buffer_write_u8_at(self,at,data)
#parameters: ldns_buffer *,size_t,uint8_t,
#retvals:
#_LDNS_BUFFER_METHODS#
%}
}

View File

@@ -0,0 +1,196 @@
/******************************************************************************
* ldns_dname.i: LDNS domain name class
*
* 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.
******************************************************************************/
%pythoncode %{
class ldns_dname(ldns_rdf):
"""Domain name
This class contains methods to read and manipulate domain names.
Domain names are stored in ldns_rdf structures, with the type LDNS_RDF_TYPE_DNAME
**Usage**
>>> import ldns
>>> resolver = ldns.ldns_resolver.new_frm_file("/etc/resolv.conf")
>>> dn1 = ldns.ldns_dname("test.nic.cz")
>>> print dn1
test.nic.cz.
>>> dn2 = ldns.ldns_dname("nic.cz")
>>> if dn2.is_subdomain(dn1): print dn2,"is subdomain of",dn1
>>> if dn1.is_subdomain(dn2): print dn1,"is subdomain of",dn2
test.nic.cz. is subdomain of nic.cz.
"""
def __init__(self, str):
"""Creates a new dname rdf from a string.
:parameter str: str string to use
"""
self.this = _ldns.ldns_dname_new_frm_str(str)
@staticmethod
def new_frm_str(str):
"""Creates a new dname rdf instance from a string.
This static method is equivalent to using of default class constructor.
:parameter str: str string to use
"""
return ldns_dname(str)
def absolute(self):
"""Checks whether the given dname string is absolute (i.e. ends with a '.')
:returns: (bool) True or False
"""
return self.endswith(".")
def make_canonical(self):
"""Put a dname into canonical fmt - ie. lowercase it
"""
_ldns.ldns_dname2canonical(self)
def __cmp__(self,other):
"""Compares the two dname rdf's according to the algorithm for ordering in RFC4034 Section 6.
:param other:
the second dname rdf to compare
:returns: (int) -1 if dname comes before other, 1 if dname comes after other, and 0 if they are equal.
"""
return _ldns.ldns_dname_compare(self,other)
def write_to_buffer(self,buffer):
"""Copies the dname data to the buffer in wire format.
:param buffer: buffer to append the result to
:returns: (ldns_status) ldns_status
"""
return _ldns.ldns_dname2buffer_wire(buffer,self)
#parameters: ldns_buffer *,const ldns_rdf *,
#retvals: ldns_status
#LDNS_DNAME_METHODS_#
def cat(self,rd2):
"""concatenates rd2 after this dname (rd2 is copied, this dname is modified)
:param rd2:
the rightside
:returns: (ldns_status) LDNS_STATUS_OK on success
"""
return _ldns.ldns_dname_cat(self,rd2)
#parameters: ldns_rdf *,ldns_rdf *,
#retvals: ldns_status
def cat_clone(self,rd2):
"""concatenates two dnames together
:param rd2:
the rightside
:returns: (ldns_rdf \*) a new rdf with leftside/rightside
"""
return _ldns.ldns_dname_cat_clone(self,rd2)
#parameters: const ldns_rdf *,const ldns_rdf *,
#retvals: ldns_rdf *
def interval(self,middle,next):
"""check if middle lays in the interval defined by prev and next prev <= middle < next.
This is usefull for nsec checking
:param middle:
the dname to check
:param next:
the next dname return 0 on error or unknown, -1 when middle is in the interval, +1 when not
:returns: (int)
"""
return _ldns.ldns_dname_interval(self,middle,next)
#parameters: const ldns_rdf *,const ldns_rdf *,const ldns_rdf *,
#retvals: int
def is_subdomain(self,parent):
"""Tests wether the name sub falls under parent (i.e. is a subdomain of parent).
This function will return false if the given dnames are equal.
:param parent:
(ldns_rdf) the parent's name
:returns: (bool) true if sub falls under parent, otherwise false
"""
return _ldns.ldns_dname_is_subdomain(self,parent)
#parameters: const ldns_rdf *,const ldns_rdf *,
#retvals: bool
def label(self,labelpos):
"""look inside the rdf and if it is an LDNS_RDF_TYPE_DNAME try and retrieve a specific label.
The labels are numbered starting from 0 (left most).
:param labelpos:
return the label with this number
:returns: (ldns_rdf \*) a ldns_rdf* with the label as name or NULL on error
"""
return _ldns.ldns_dname_label(self,labelpos)
#parameters: const ldns_rdf *,uint8_t,
#retvals: ldns_rdf *
def label_count(self):
"""count the number of labels inside a LDNS_RDF_DNAME type rdf.
:returns: (uint8_t) the number of labels
"""
return _ldns.ldns_dname_label_count(self)
#parameters: const ldns_rdf *,
#retvals: uint8_t
def left_chop(self):
"""chop one label off the left side of a dname.
so wwww.nlnetlabs.nl, becomes nlnetlabs.nl
:returns: (ldns_rdf \*) the remaining dname
"""
return _ldns.ldns_dname_left_chop(self)
#parameters: const ldns_rdf *,
#retvals: ldns_rdf *
def reverse(self):
"""Returns a clone of the given dname with the labels reversed.
:returns: (ldns_rdf \*) clone of the dname with the labels reversed.
"""
return _ldns.ldns_dname_reverse(self)
#parameters: const ldns_rdf *,
#retvals: ldns_rdf *
#_LDNS_DNAME_METHODS#
%}

View File

@@ -0,0 +1,434 @@
/******************************************************************************
* ldns_dnssec.i: DNSSEC zone, name, rrs
*
* 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.
******************************************************************************/
%nodefaultctor ldns_dnssec_rrs; //no default constructor & destructor
%nodefaultdtor ldns_dnssec_rrs;
%newobject ldns_dnssec_rrs_new;
%delobject ldns_dnssec_rrs_free;
%extend ldns_dnssec_rrs {
%pythoncode %{
def __init__(self):
"""Creates a new entry for 1 pointer to an rr and 1 pointer to the next rrs.
:returns: (ldns_dnssec_rrs) the allocated data
"""
self.this = _ldns.ldns_dnssec_rrs_new()
if not self.this:
raise Exception("Can't create rrs instance")
__swig_destroy__ = _ldns.ldns_dnssec_rrs_free
#LDNS_DNSSEC_RRS_METHODS_#
def add_rr(self,rr):
"""Adds an RR to the list of RRs.
The list will remain ordered
:param rr:
the RR to add
:returns: (ldns_status) LDNS_STATUS_OK on success
"""
return _ldns.ldns_dnssec_rrs_add_rr(self,rr)
#parameters: ldns_dnssec_rrs *,ldns_rr *,
#retvals: ldns_status
#_LDNS_DNSSEC_RRS_METHODS#
%}
}
// ================================================================================
// DNNSEC RRS
// ================================================================================
%nodefaultctor ldns_dnssec_rrsets; //no default constructor & destructor
%nodefaultdtor ldns_dnssec_rrsets;
%newobject ldns_dnssec_rrsets_new;
%delobject ldns_dnssec_rrsets_free;
%extend ldns_dnssec_rrsets {
%pythoncode %{
def __init__(self):
"""Creates a new list (entry) of RRsets.
:returns: (ldns_dnssec_rrsets \*) instance
"""
self.this = _ldns.ldns_dnssec_rrsets_new()
if not self.this:
raise Exception("Can't create rrsets instance")
__swig_destroy__ = _ldns.ldns_dnssec_rrsets_free
def print_to_file(self, file, follow):
"""Print the given list of rrsets to the given file descriptor.
:param file: file pointer
:param follow: if set to false, only print the first RRset
"""
_ldns.ldns_dnssec_rrsets_print(file,self,follow)
#parameters: FILE *,ldns_dnssec_rrsets *,bool,
#retvals:
#LDNS_DNSSEC_RRSETS_METHODS_#
def add_rr(self,rr):
"""Add an ldns_rr to the corresponding RRset in the given list of RRsets.
If it is not present, add it as a new RRset with 1 record.
:param rr:
the rr to add to the list of rrsets
:returns: (ldns_status) LDNS_STATUS_OK on success
"""
return _ldns.ldns_dnssec_rrsets_add_rr(self,rr)
#parameters: ldns_dnssec_rrsets *,ldns_rr *,
#retvals: ldns_status
def set_type(self,atype):
"""Sets the RR type of the rrset (that is head of the given list).
:param atype:
:returns: (ldns_status) LDNS_STATUS_OK on success
"""
return _ldns.ldns_dnssec_rrsets_set_type(self,atype)
#parameters: ldns_dnssec_rrsets *,ldns_rr_type,
#retvals: ldns_status
def type(self):
"""Returns the rr type of the rrset (that is head of the given list).
:returns: (ldns_rr_type) the rr type
"""
return _ldns.ldns_dnssec_rrsets_type(self)
#parameters: ldns_dnssec_rrsets *,
#retvals: ldns_rr_type
#_LDNS_DNSSEC_RRSETS_METHODS#
%}
}
// ================================================================================
// DNNSEC NAME
// ================================================================================
%nodefaultctor ldns_dnssec_name; //no default constructor & destructor
%nodefaultdtor ldns_dnssec_name;
%newobject ldns_dnssec_name_new;
%delobject ldns_dnssec_name_free;
%extend ldns_dnssec_name {
%pythoncode %{
def __init__(self):
"""Create a new instance of dnssec name."""
self.this = _ldns.ldns_dnssec_name_new()
if not self.this:
raise Exception("Can't create dnssec name instance")
__swig_destroy__ = _ldns.ldns_dnssec_name_free
def print_to_file(self,file):
"""Prints the RRs in the dnssec name structure to the given file descriptor.
:param file: file pointer
"""
_ldns.ldns_dnssec_name_print(file, self)
#parameters: FILE *,ldns_dnssec_name *,
@staticmethod
def new_frm_rr(raiseException=True):
"""Create a new instace of dnssec name for the given RR.
:returns: (ldns_dnssec_name) instance
"""
name = _ldns.ldns_dnssec_name_new_frm_rr(self)
if (not name) and (raiseException):
raise Exception("Can't create dnssec name")
return name
#LDNS_DNSSEC_NAME_METHODS_#
def add_rr(self,rr):
"""Inserts the given rr at the right place in the current dnssec_name No checking is done whether the name matches.
:param rr:
The RR to add
:returns: (ldns_status) LDNS_STATUS_OK on success, error code otherwise
"""
return _ldns.ldns_dnssec_name_add_rr(self,rr)
#parameters: ldns_dnssec_name *,ldns_rr *,
#retvals: ldns_status
def find_rrset(self,atype):
"""Find the RRset with the given type in within this name structure.
:param atype:
:returns: (ldns_dnssec_rrsets \*) the RRset, or NULL if not present
"""
return _ldns.ldns_dnssec_name_find_rrset(self,atype)
#parameters: ldns_dnssec_name *,ldns_rr_type,
#retvals: ldns_dnssec_rrsets *
def name(self):
"""Returns the domain name of the given dnssec_name structure.
:returns: (ldns_rdf \*) the domain name
"""
return _ldns.ldns_dnssec_name_name(self)
#parameters: ldns_dnssec_name *,
#retvals: ldns_rdf *
def set_name(self,dname):
"""Sets the domain name of the given dnssec_name structure.
:param dname:
the domain name to set it to. This data is *not* copied.
"""
_ldns.ldns_dnssec_name_set_name(self,dname)
#parameters: ldns_dnssec_name *,ldns_rdf *,
#retvals:
def set_nsec(self,nsec):
"""Sets the NSEC(3) RR of the given dnssec_name structure.
:param nsec:
the nsec rr to set it to. This data is *not* copied.
"""
_ldns.ldns_dnssec_name_set_nsec(self,nsec)
#parameters: ldns_dnssec_name *,ldns_rr *,
#retvals:
#_LDNS_DNSSEC_NAME_METHODS#
%}
}
// ================================================================================
// DNNSEC ZONE
// ================================================================================
%nodefaultctor ldns_dnssec_zone; //no default constructor & destructor
%nodefaultdtor ldns_dnssec_zone;
%newobject ldns_dnssec_zone_new;
%delobject ldns_dnssec_zone_free;
%inline %{
ldns_status ldns_dnssec_zone_sign_defcb(ldns_dnssec_zone *zone, ldns_rr_list *new_rrs, ldns_key_list *key_list, int cbtype)
{
if (cbtype == 0)
return ldns_dnssec_zone_sign(zone, new_rrs, key_list, ldns_dnssec_default_add_to_signatures, NULL);
if (cbtype == 1)
return ldns_dnssec_zone_sign(zone, new_rrs, key_list, ldns_dnssec_default_leave_signatures, NULL);
if (cbtype == 2)
return ldns_dnssec_zone_sign(zone, new_rrs, key_list, ldns_dnssec_default_delete_signatures, NULL);
return ldns_dnssec_zone_sign(zone, new_rrs, key_list, ldns_dnssec_default_replace_signatures, NULL);
}
%}
%extend ldns_dnssec_zone {
%pythoncode %{
def __init__(self):
"""Creates a new dnssec_zone instance"""
self.this = _ldns.ldns_dnssec_zone_new()
if not self.this:
raise Exception("Can't create dnssec zone instance")
__swig_destroy__ = _ldns.ldns_dnssec_zone_free
def print_to_file(self,file):
"""Prints the complete zone to the given file descriptor.
:param file: file pointer
"""
_ldns.ldns_dnssec_zone_print(file, self)
#parameters: FILE *, ldns_dnssec_zone *,
#retvals:
def create_nsec3s(self,new_rrs,algorithm,flags,iterations,salt_length,salt):
"""Adds NSEC3 records to the zone.
:param new_rrs:
:param algorithm:
:param flags:
:param iterations:
:param salt_length:
:param salt:
:returns: (ldns_status)
"""
return _ldns.ldns_dnssec_zone_create_nsec3s(self,new_rrs,algorithm,flags,iterations,salt_length,salt)
#parameters: ldns_dnssec_zone *,ldns_rr_list *,uint8_t,uint8_t,uint16_t,uint8_t,uint8_t *,
#retvals: ldns_status
def create_nsecs(self,new_rrs):
"""Adds NSEC records to the given dnssec_zone.
:param new_rrs:
ldns_rr's created by this function are added to this rr list, so the caller can free them later
:returns: (ldns_status) LDNS_STATUS_OK on success, an error code otherwise
"""
return _ldns.ldns_dnssec_zone_create_nsecs(self,new_rrs)
#parameters: ldns_dnssec_zone *,ldns_rr_list *,
#retvals: ldns_status
def create_rrsigs(self,new_rrs,key_list,func,arg):
"""Adds signatures to the zone.
:param new_rrs:
the RRSIG RRs that are created are also added to this list, so the caller can free them later
:param key_list:
list of keys to sign with.
:param func:
Callback function to decide what keys to use and what to do with old signatures
:param arg:
Optional argument for the callback function
:returns: (ldns_status) LDNS_STATUS_OK on success, error otherwise
"""
return _ldns.ldns_dnssec_zone_create_rrsigs(self,new_rrs,key_list,func,arg)
#parameters: ldns_dnssec_zone *,ldns_rr_list *,ldns_key_list *,int(*)(ldns_rr *, void *),void *,
#retvals: ldns_status
def sign_cb(self,new_rrs,key_list,func,arg):
"""signs the given zone with the given keys (with callback function)
:param new_rrs:
newly created resource records are added to this list, to free them later
:param key_list:
the list of keys to sign the zone with
:param func:
callback function that decides what to do with old signatures.
This function takes an ldns_rr and an optional arg argument, and returns one of four values:
* LDNS_SIGNATURE_LEAVE_ADD_NEW - leave the signature and add a new one for the corresponding key
* LDNS_SIGNATURE_REMOVE_ADD_NEW - remove the signature and replace is with a new one from the same key
* LDNS_SIGNATURE_LEAVE_NO_ADD - leave the signature and do not add a new one with the corresponding key
* LDNS_SIGNATURE_REMOVE_NO_ADD - remove the signature and do not replace
:param arg:
optional argument for the callback function
:returns: (ldns_status) LDNS_STATUS_OK on success, an error code otherwise
"""
return _ldns.ldns_dnssec_zone_sign(self,new_rrs,key_list,func,arg)
#parameters: ldns_dnssec_zone *,ldns_rr_list *,ldns_key_list *,int(*)(ldns_rr *, void *),void *,
#retvals: ldns_status
def sign(self,new_rrs,key_list, cbtype=3):
"""signs the given zone with the given keys
:param new_rrs:
newly created resource records are added to this list, to free them later
:param key_list:
the list of keys to sign the zone with
:param cb_type:
specifies how to deal with old signatures, possible values:
* 0 - ldns_dnssec_default_add_to_signatures,
* 1 - ldns_dnssec_default_leave_signatures,
* 2 - ldns_dnssec_default_delete_signatures,
* 3 - ldns_dnssec_default_replace_signatures
:returns: (ldns_status) LDNS_STATUS_OK on success, an error code otherwise
"""
return _ldns.ldns_dnssec_zone_sign_defcb(self,new_rrs,key_list, cbtype)
#parameters: ldns_dnssec_zone *,ldns_rr_list *,ldns_key_list *,
#retvals: ldns_status
def sign_nsec3(self,new_rrs,key_list,func,arg,algorithm,flags,iterations,salt_length,salt):
"""signs the given zone with the given new zone, with NSEC3
:param new_rrs:
newly created resource records are added to this list, to free them later
:param key_list:
the list of keys to sign the zone with
:param func:
callback function that decides what to do with old signatures
:param arg:
optional argument for the callback function
:param algorithm:
the NSEC3 hashing algorithm to use
:param flags:
NSEC3 flags
:param iterations:
the number of NSEC3 hash iterations to use
:param salt_length:
the length (in octets) of the NSEC3 salt
:param salt:
the NSEC3 salt data
:returns: (ldns_status) LDNS_STATUS_OK on success, an error code otherwise
"""
return _ldns.ldns_dnssec_zone_sign_nsec3(self,new_rrs,key_list,func,arg,algorithm,flags,iterations,salt_length,salt)
#parameters: ldns_dnssec_zone *,ldns_rr_list *,ldns_key_list *,int(*)(ldns_rr *, void *),void *,uint8_t,uint8_t,uint16_t,uint8_t,uint8_t *,
#retvals: ldns_status
#LDNS_DNSSEC_ZONE_METHODS_#
def add_empty_nonterminals(self):
"""Adds explicit dnssec_name structures for the empty nonterminals in this zone.
(this is needed for NSEC3 generation)
:returns: (ldns_status)
"""
return _ldns.ldns_dnssec_zone_add_empty_nonterminals(self)
#parameters: ldns_dnssec_zone *,
#retvals: ldns_status
def add_rr(self,rr):
"""Adds the given RR to the zone.
It find whether there is a dnssec_name with that name present.
If so, add it to that, if not create a new one.
Special handling of NSEC and RRSIG provided.
:param rr:
The RR to add
:returns: (ldns_status) LDNS_STATUS_OK on success, an error code otherwise
"""
return _ldns.ldns_dnssec_zone_add_rr(self,rr)
#parameters: ldns_dnssec_zone *,ldns_rr *,
#retvals: ldns_status
def find_rrset(self,dname,atype):
"""Find the RRset with the given name and type in the zone.
:param dname:
the domain name of the RRset to find
:param atype:
:returns: (ldns_dnssec_rrsets \*) the RRset, or NULL if not present
"""
return _ldns.ldns_dnssec_zone_find_rrset(self,dname,atype)
#parameters: ldns_dnssec_zone *,ldns_rdf *,ldns_rr_type,
#retvals: ldns_dnssec_rrsets *
#_LDNS_DNSSEC_ZONE_METHODS#
%}
}

View File

@@ -0,0 +1,536 @@
/******************************************************************************
* ldns_key.i: LDNS key class
*
* 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.
******************************************************************************/
%typemap(in,numinputs=0,noblock=1) (ldns_key **)
{
ldns_key *$1_key;
$1 = &$1_key;
}
/* result generation */
%typemap(argout,noblock=1) (ldns_key **)
{
$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr($1_key), SWIGTYPE_p_ldns_struct_key, SWIG_POINTER_OWN | 0 ));
}
%exception ldns_key_set_pubkey_owner(ldns_key *k, ldns_rdf *r) %{ $action Py_INCREF(obj1); %}
%nodefaultctor ldns_struct_key; //no default constructor & destructor
%nodefaultdtor ldns_struct_key;
%delobject ldns_key_free;
%delobject ldns_key_deep_free;
%newobject ldns_key_list_pop_key;
%newobject ldns_key2rr;
%newobject ldns_key_new_frm_algorithm;
%newobject ldns_key_new_frm_fp;
%newobject ldns_key_new_frm_fp_l;
%newobject ldns_key_new_frm_engine;
%rename(ldns_key) ldns_struct_key;
#ifdef LDNS_DEBUG
%rename(__ldns_key_free) ldns_key_free;
%inline %{
void _ldns_key_free (ldns_key* k) {
printf("******** LDNS_KEY free 0x%lX ************\n", (long unsigned int)k);
ldns_key_deep_free(k);
}
%}
#else
%rename(_ldns_key_free) ldns_key_deep_free;
%rename(__ldns_key_free) ldns_key_free;
#endif
%feature("docstring") ldns_struct_key "Key class
This class can contains all types of keys that are used in DNSSEC. Mostly used to store private keys, since public keys can also be stored in a ldns_rr with type LDNS_RR_TYPE_DNSKEY. This class can also store some variables that influence the signatures generated by signing with this key, for instance the inception date.
**Usage**
>>> import ldns
>>> ldns.ldns_init_random(open(\"/dev/random\",\"rb\"), 512/8)
>>> key = ldns.ldns_key.new_frm_algorithm(ldns.LDNS_SIGN_DSA, 512) #generate new DSA key
>>> print key
Private-key-format: v1.2
Algorithm: 3 (DSA)
Prime(p): XXXXXXXXHRQBGRflHZQriSAoLI2g+LGvZz8BlEesO+ZQg65wrFGs9IC441y/mn3nFnXfCdtX6zbN5bQuabPdlQ==
Subprime(q): XXXXXdnWs/cWsGDglhEyZRLEVA8=
Base(g): XXXXXXXqrd+dm2bcxDBdCsZRzkXQ22FxCk2ycnjgevr+s2HfA57BPk3xwqCrHUwuOBVg3Fvq4bpldrCe0sT6Og==
Private_value(x): XXXXXcVubZF33pj04z4ZoETsQW1Y=
Public_value(y): XXXXXX8t6zfOxJHoy57qteIw9sOZ/Zu0yFiPO083sPm11NlFx3b4m7TJ2k41gYicHXHLUQK1p0xXFToeZEkPGQ==
>>> fw = open(\"key.priv\", \"wb\")
>>> key.print_to_file(fw) #write priv key to file
"
%extend ldns_struct_key {
%pythoncode %{
def __init__(self):
self.this = _ldns.ldns_key_new()
if not self.this:
raise Exception("Can't create instance of this class")
__swig_destroy__ = _ldns._ldns_key_free
def __str__(self):
"""converts the data to presentation format"""
return _ldns.ldns_key2str(self)
def key_to_rr(self):
"""converts a ldns_key to a public key rr
:returns: (ldns_rr \*) ldns_rr representation of the key
"""
return _ldns.ldns_key2rr(self)
#parameters: const ldns_key *,
#retvals: ldns_rr *
def print_to_file(self, file):
"""print a private key to the file ouput
:param file: output file pointer
"""
_ldns.ldns_key_print(file, self)
#parameters: FILE *, const ldns_key *,
#retvals:
#LDNS_KEY_CONSTRUCTORS_#
@staticmethod
def new_frm_fp(file, raiseException=True):
"""Creates a new priv key based on the contents of the file pointed by fp.
:param file: a file object
:param raiseException: if True, an exception occurs in case a key instance can't be created
:returns: key instance or None. If the object can't be created and raiseException is True, an exception occurs.
"""
status, key = _ldns.ldns_key_new_frm_fp(file)
if status != LDNS_STATUS_OK:
if (raiseException): raise Exception("Can't create key, error: %s (%d)" % (_ldns.ldns_get_errorstr_by_id(status),status))
return None
return key
@staticmethod
def new_frm_fp_l(file, raiseException=True):
"""Creates a new private key based on the contents of the file pointed by fp.
:param file: a file object
:param raiseException: if True, an exception occurs in case a key instance can't be created
:returns:
* key - key instance or None. If an instance can't be created and raiseException is True, an exception occurs.
* line - the line number (for debugging)
"""
status, key, line = _ldns.ldns_key_new_frm_fp_l(file)
if status != LDNS_STATUS_OK:
if (raiseException): raise Exception("Can't create key, error: %d" % status)
return None
return key, line
@staticmethod
def new_frm_algorithm(algorithm, size, raiseException=True):
"""Creates a new key based on the algorithm.
:param algorithm: the algorithm to use
:param size: the number of bytes for the keysize
:param raiseException: if True, an exception occurs in case a key instance can't be created
:returns: key instance or None. If the object can't be created and raiseException is True, an exception occurs.
**Algorithms**
LDNS_SIGN_RSAMD5, LDNS_SIGN_RSASHA1, LDNS_SIGN_DSA, LDNS_SIGN_RSASHA1_NSEC3, LDNS_SIGN_RSASHA256, LDNS_SIGN_RSASHA256_NSEC3, LDNS_SIGN_RSASHA512, LDNS_SIGN_RSASHA512_NSEC3, LDNS_SIGN_DSA_NSEC3, LDNS_SIGN_HMACMD5, LDNS_SIGN_HMACSHA1, LDNS_SIGN_HMACSHA256
"""
key = _ldns.ldns_key_new_frm_algorithm(algorithm, size)
if (not key) and (raiseException): raise Exception("Can't create key, error: %d" % status)
return key
#_LDNS_KEY_CONSTRUCTORS#
#LDNS_KEY_METHODS_#
def algorithm(self):
"""return the signing alg of the key
:returns: (ldns_signing_algorithm) the algorithm
"""
return _ldns.ldns_key_algorithm(self)
#parameters: const ldns_key *,
#retvals: ldns_signing_algorithm
def dsa_key(self):
"""returns the (openssl) DSA struct contained in the key
:returns: (DSA \*)
"""
return _ldns.ldns_key_dsa_key(self)
#parameters: const ldns_key *,
#retvals: DSA *
def evp_key(self):
"""returns the (openssl) EVP struct contained in the key
:returns: (EVP_PKEY \*) the RSA * structure in the key
"""
return _ldns.ldns_key_evp_key(self)
#parameters: const ldns_key *,
#retvals: EVP_PKEY *
def expiration(self):
"""return the key's expiration date
:returns: (uint32_t) the experiration date
"""
return _ldns.ldns_key_expiration(self)
#parameters: const ldns_key *,
#retvals: uint32_t
def flags(self):
"""return the flag of the key
:returns: (uint16_t) the flag
"""
return _ldns.ldns_key_flags(self)
#parameters: const ldns_key *,
#retvals: uint16_t
def hmac_key(self):
"""return the hmac key data
:returns: (unsigned char \*) the hmac key data
"""
return _ldns.ldns_key_hmac_key(self)
#parameters: const ldns_key *,
#retvals: unsigned char *
def hmac_size(self):
"""return the hmac key size
:returns: (size_t) the hmac key size
"""
return _ldns.ldns_key_hmac_size(self)
#parameters: const ldns_key *,
#retvals: size_t
def inception(self):
"""return the key's inception date
:returns: (uint32_t) the inception date
"""
return _ldns.ldns_key_inception(self)
#parameters: const ldns_key *,
#retvals: uint32_t
def keytag(self):
"""return the keytag
:returns: (uint16_t) the keytag
"""
return _ldns.ldns_key_keytag(self)
#parameters: const ldns_key *,
#retvals: uint16_t
def origttl(self):
"""return the original ttl of the key
:returns: (uint32_t) the original ttl
"""
return _ldns.ldns_key_origttl(self)
#parameters: const ldns_key *,
#retvals: uint32_t
def pubkey_owner(self):
"""return the public key's owner
:returns: (ldns_rdf \*) the owner
"""
return _ldns.ldns_key_pubkey_owner(self)
#parameters: const ldns_key *,
#retvals: ldns_rdf *
def rsa_key(self):
"""returns the (openssl) RSA struct contained in the key
:returns: (RSA \*) the RSA * structure in the key
"""
return _ldns.ldns_key_rsa_key(self)
#parameters: const ldns_key *,
#retvals: RSA *
def set_algorithm(self,l):
"""Set the key's algorithm.
:param l:
the algorithm
"""
_ldns.ldns_key_set_algorithm(self,l)
#parameters: ldns_key *,ldns_signing_algorithm,
#retvals:
def set_dsa_key(self,d):
"""Set the key's dsa data.
:param d:
the dsa data
"""
_ldns.ldns_key_set_dsa_key(self,d)
#parameters: ldns_key *,DSA *,
#retvals:
def set_evp_key(self,e):
"""Set the key's evp key.
:param e:
the evp key
"""
_ldns.ldns_key_set_evp_key(self,e)
#parameters: ldns_key *,EVP_PKEY *,
#retvals:
def set_expiration(self,e):
"""Set the key's expiration date (seconds after epoch).
:param e:
the expiration
"""
_ldns.ldns_key_set_expiration(self,e)
#parameters: ldns_key *,uint32_t,
#retvals:
def set_flags(self,flags):
"""Set the key's flags.
:param flags:
the flags
"""
_ldns.ldns_key_set_flags(self,flags)
#parameters: ldns_key *,uint16_t,
#retvals:
def set_hmac_key(self,hmac):
"""Set the key's hmac data.
:param hmac:
the raw key data
"""
_ldns.ldns_key_set_hmac_key(self,hmac)
#parameters: ldns_key *,unsigned char *,
#retvals:
def set_hmac_size(self,hmac_size):
"""Set the key's hmac size.
:param hmac_size:
the size of the hmac data
"""
_ldns.ldns_key_set_hmac_size(self,hmac_size)
#parameters: ldns_key *,size_t,
#retvals:
def set_inception(self,i):
"""Set the key's inception date (seconds after epoch).
:param i:
the inception
"""
_ldns.ldns_key_set_inception(self,i)
#parameters: ldns_key *,uint32_t,
#retvals:
def set_keytag(self,tag):
"""Set the key's key tag.
:param tag:
the keytag
"""
_ldns.ldns_key_set_keytag(self,tag)
#parameters: ldns_key *,uint16_t,
#retvals:
def set_origttl(self,t):
"""Set the key's original ttl.
:param t:
the ttl
"""
_ldns.ldns_key_set_origttl(self,t)
#parameters: ldns_key *,uint32_t,
#retvals:
def set_pubkey_owner(self,r):
"""Set the key's pubkey owner.
:param r:
the owner
"""
_ldns.ldns_key_set_pubkey_owner(self,r)
#parameters: ldns_key *,ldns_rdf *,
#retvals:
def set_rsa_key(self,r):
"""Set the key's rsa data.
:param r:
the rsa data
"""
_ldns.ldns_key_set_rsa_key(self,r)
#parameters: ldns_key *,RSA *,
#retvals:
def set_use(self,v):
"""set the use flag
:param v:
the boolean value to set the _use field to
"""
_ldns.ldns_key_set_use(self,v)
#parameters: ldns_key *,bool,
#retvals:
def use(self):
"""return the use flag
:returns: (bool) the boolean value of the _use field
"""
return _ldns.ldns_key_use(self)
#parameters: const ldns_key *,
#retvals: bool
#_LDNS_KEY_METHODS#
%}
}
%nodefaultctor ldns_struct_key_list; //no default constructor & destructor
%nodefaultdtor ldns_struct_key_list;
%newobject ldns_key_list_new;
%newobject ldns_key_list_pop_key;
%delobject ldns_key_list_free;
%delobject ldns_key_list_push_key;
%rename(ldns_key_list) ldns_struct_key_list;
#ifdef LDNS_DEBUG
%rename(__ldns_key_list_free) ldns_key_list_free;
%inline %{
void _ldns_key_list_free (ldns_key_list* k) {
printf("******** LDNS_KEY_LIST free 0x%lX ************\n", (long unsigned int)k);
ldns_key_list_free(k);
}
%}
#else
%rename(_ldns_key_list_free) ldns_key_list_free;
#endif
%extend ldns_struct_key_list {
%pythoncode %{
def __init__(self):
self.this = _ldns.ldns_key_list_new()
if not self.this:
raise Exception("Can't create class")
__swig_destroy__ = _ldns._ldns_key_list_free
def keys(self):
"""Key list iterator"""
for i in range(0, self.key_count()):
yield self.key(i)
def __str__(self):
i = 0
s = ""
for k in self.keys():
i += 1
s += "key %d:\n %s\n" % (i, str(k).replace("\n","\n "))
return s
#LDNS_KEY_LIST_METHODS_#
def key(self,nr):
"""returns a pointer to the key in the list at the given position
:param nr:
the position in the list
:returns: (ldns_key \*) the key
"""
return _ldns.ldns_key_list_key(self,nr)
#parameters: const ldns_key_list *,size_t,
#retvals: ldns_key *
def key_count(self):
"""returns the number of keys in the key list
:returns: (size_t) the numbers of keys in the list
"""
return _ldns.ldns_key_list_key_count(self)
#parameters: const ldns_key_list *,
#retvals: size_t
def pop_key(self):
"""pops the last rr from a keylist
:returns: (ldns_key \*) NULL if nothing to pop. Otherwise the popped RR
"""
return _ldns.ldns_key_list_pop_key(self)
#parameters: ldns_key_list *,
#retvals: ldns_key *
def push_key(self,key):
"""pushes a key to a keylist
:param key:
the key to push
:returns: (bool) false on error, otherwise true
"""
return _ldns.ldns_key_list_push_key(self,key)
#parameters: ldns_key_list *,ldns_key *,
#retvals: bool
def set_key_count(self,count):
"""Set the keylist's key count to count.
:param count:
the cuont
"""
_ldns.ldns_key_list_set_key_count(self,count)
#parameters: ldns_key_list *,size_t,
#retvals:
def set_use(self,v):
"""Set the 'use' flag for all keys in the list.
:param v:
The value to set the use flags to
"""
_ldns.ldns_key_list_set_use(self,v)
#parameters: ldns_key_list *,bool,
#retvals:
#_LDNS_KEY_LIST_METHODS#
%}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,418 @@
/******************************************************************************
* ldns_rdata.i: LDNS record data
*
* 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.
******************************************************************************/
//automatic conversion of const ldns_rdf* parameter from string
%typemap(in,noblock=1) const ldns_rdf * (void* argp, $1_ltype tmp = 0, int res) {
if (PyString_Check($input)) {
tmp = ldns_dname_new_frm_str(PyString_AsString($input));
if (tmp == NULL) {
%argument_fail(SWIG_TypeError, "char *", $symname, $argnum);
}
$1 = ($1_ltype) tmp;
} else {
res = SWIG_ConvertPtr($input, &argp, SWIGTYPE_p_ldns_struct_rdf, 0 | 0 );
if (!SWIG_IsOK(res)) {
%argument_fail(res, "ldns_rdf const *", $symname, $argnum);
}
$1 = ($1_ltype) argp;
}
}
%typemap(in,numinputs=0,noblock=1) (ldns_rdf **)
{
ldns_rdf *$1_rdf;
$1 = &$1_rdf;
}
// result generation
%typemap(argout,noblock=1) (ldns_rdf **)
{
$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr($1_rdf), SWIGTYPE_p_ldns_struct_rdf, SWIG_POINTER_OWN | 0 ));
}
%nodefaultctor ldns_struct_rdf; //no default constructor & destructor
%nodefaultdtor ldns_struct_rdf;
%newobject ldns_dname_new;
%newobject ldns_dname_new_frm_str;
%newobject ldns_dname_new_frm_data;
%delobject ldns_rdf_deep_free;
%delobject ldns_rdf_free;
%rename(ldns_rdf) ldns_struct_rdf;
%inline %{
const char *ldns_rdf_type2str(const ldns_rdf *rdf)
{
if (rdf) {
switch(ldns_rdf_get_type(rdf)) {
case LDNS_RDF_TYPE_NONE: return 0;
case LDNS_RDF_TYPE_DNAME: return "DNAME";
case LDNS_RDF_TYPE_INT8: return "INT8";
case LDNS_RDF_TYPE_INT16: return "INT16";
case LDNS_RDF_TYPE_INT32: return "INT32";
case LDNS_RDF_TYPE_PERIOD: return "PERIOD";
case LDNS_RDF_TYPE_TSIGTIME: return "TSIGTIME";
case LDNS_RDF_TYPE_A: return "A";
case LDNS_RDF_TYPE_AAAA: return "AAAA";
case LDNS_RDF_TYPE_STR: return "STR";
case LDNS_RDF_TYPE_APL: return "APL";
case LDNS_RDF_TYPE_B32_EXT: return "B32_EXT";
case LDNS_RDF_TYPE_B64: return "B64";
case LDNS_RDF_TYPE_HEX: return "HEX";
case LDNS_RDF_TYPE_NSEC: return "NSEC";
case LDNS_RDF_TYPE_NSEC3_SALT: return "NSEC3_SALT";
case LDNS_RDF_TYPE_TYPE: return "TYPE";
case LDNS_RDF_TYPE_CLASS: return "CLASS";
case LDNS_RDF_TYPE_CERT_ALG: return "CER_ALG";
case LDNS_RDF_TYPE_ALG: return "ALG";
case LDNS_RDF_TYPE_UNKNOWN: return "UNKNOWN";
case LDNS_RDF_TYPE_TIME: return "TIME";
case LDNS_RDF_TYPE_LOC: return "LOC";
case LDNS_RDF_TYPE_WKS: return "WKS";
case LDNS_RDF_TYPE_SERVICE: return "SERVICE";
case LDNS_RDF_TYPE_NSAP: return "NSAP";
case LDNS_RDF_TYPE_ATMA: return "ATMA";
case LDNS_RDF_TYPE_IPSECKEY: return "IPSECKEY";
case LDNS_RDF_TYPE_TSIG: return "TSIG";
case LDNS_RDF_TYPE_INT16_DATA: return "INT16_DATA";
case LDNS_RDF_TYPE_NSEC3_NEXT_OWNER: return "NSEC3_NEXT_OWNER";
}
}
return 0;
}
%}
#ifdef LDNS_DEBUG
%rename(__ldns_rdf_deep_free) ldns_rdf_deep_free;
%rename(__ldns_rdf_free) ldns_rdf_free;
%inline %{
void _ldns_rdf_free (ldns_rdf* r) {
printf("******** LDNS_RDF free 0x%lX ************\n", (long unsigned int)r);
ldns_rdf_free(r);
}
%}
#else
%rename(_ldns_rdf_deep_free) ldns_rdf_deep_free;
%rename(_ldns_rdf_free) ldns_rdf_free;
#endif
%newobject ldns_rdf2str;
%feature("docstring") ldns_struct_rdf "Resource record data field.
The data is a network ordered array of bytes, which size is specified by the (16-bit) size field. To correctly parse it, use the type specified in the (16-bit) type field with a value from ldns_rdf_type."
%extend ldns_struct_rdf {
%pythoncode %{
def __init__(self):
raise Exception("This class can't be created directly. Please use: ldns_rdf_new, ldns_rdf_new_frm_data, ldns_rdf_new_frm_str, ldns_rdf_new_frm_fp, ldns_rdf_new_frm_fp_l")
__swig_destroy__ = _ldns._ldns_rdf_free
#LDNS_RDF_CONSTRUCTORS_#
@staticmethod
def new_frm_str(str, rr_type, raiseException = True):
"""Creates a new rdf from a string of a given type.
:param str: string to use
:param rr_type: the type of RDF. See predefined `RDF_TYPE_` constants
:param raiseException: if True, an exception occurs in case a RDF object can't be created
:returns: RDF object or None. If the object can't be created and raiseException is True, an exception occurs.
**Usage**
>>> rdf = ldns.ldns_rdf.new_frm_str("74.125.43.99",ldns.LDNS_RDF_TYPE_A)
>>> print rdf, rdf.get_type_str()
A 74.125.43.99
>>> name = ldns.ldns_resolver.new_frm_file().get_name_by_addr(rdf)
>>> if (name): print name
99.43.125.74.in-addr.arpa. 85277 IN PTR bw-in-f99.google.com.
"""
rr = _ldns.ldns_rdf_new_frm_str(rr_type, str)
if not rr:
if (raiseException): raise Exception("Can't create query packet, error: %d" % status)
return rr
#_LDNS_RDF_CONSTRUCTORS#
def __str__(self):
"""Converts the rdata field to presentation format"""
return _ldns.ldns_rdf2str(self)
def __cmp__(self,other):
"""compares two rdf's on their wire formats.
(To order dnames according to rfc4034, use ldns_dname_compare)
:param other:
the second one RDF
:returns: (int) 0 if equal -1 if self comes before other +1 if other comes before self
"""
return _ldns.ldns_rdf_compare(self,other)
def print_to_file(self,output):
"""Prints the data in the rdata field to the given file stream (in presentation format)."""
_ldns.ldns_rdf_print(output,self)
def get_type_str(self):
"""Converts type to string"""
return ldns_rdf_type2str(self)
def write_to_buffer(self, buffer):
"""Copies the rdata data to the buffer in wire format.
:param buffer: buffer to append the result to
:returns: (ldns_status) ldns_status
"""
return _ldns.ldns_rdf2buffer_wire(buffer, self)
#parameters: ldns_buffer *,const ldns_rdf *,
#retvals: ldns_status
def write_to_buffer_canonical(self, buffer):
"""Copies the rdata data to the buffer in wire format If the rdata is a dname, the letters will be lowercased during the conversion.
:param buffer: LDNS buffer
:returns: (ldns_status) ldns_status
"""
return _ldns.ldns_rdf2buffer_wire_canonical(buffer, self)
#parameters: ldns_buffer *,const ldns_rdf *,
#retvals: ldns_status
#LDNS_RDF_METHODS_#
def address_reverse(self):
"""reverses an rdf, only actually useful for AAAA and A records.
The returned rdf has the type LDNS_RDF_TYPE_DNAME!
:returns: (ldns_rdf \*) the reversed rdf (a newly created rdf)
"""
return _ldns.ldns_rdf_address_reverse(self)
#parameters: ldns_rdf *,
#retvals: ldns_rdf *
def clone(self):
"""clones a rdf structure.
The data is copied.
:returns: (ldns_rdf \*) a new rdf structure
"""
return _ldns.ldns_rdf_clone(self)
#parameters: const ldns_rdf *,
#retvals: ldns_rdf *
def data(self):
"""returns the data of the rdf.
:returns: (uint8_t \*) uint8_t* pointer to the rdf's data
"""
return _ldns.ldns_rdf_data(self)
#parameters: const ldns_rdf *,
#retvals: uint8_t *
def get_type(self):
"""returns the type of the rdf.
We need to insert _get_ here to prevent conflict the the rdf_type TYPE.
:returns: (ldns_rdf_type) ldns_rdf_type with the type
"""
return _ldns.ldns_rdf_get_type(self)
#parameters: const ldns_rdf *,
#retvals: ldns_rdf_type
def set_data(self,data):
"""sets the size of the rdf.
:param data:
"""
_ldns.ldns_rdf_set_data(self,data)
#parameters: ldns_rdf *,void *,
#retvals:
def set_size(self,size):
"""sets the size of the rdf.
:param size:
the new size
"""
_ldns.ldns_rdf_set_size(self,size)
#parameters: ldns_rdf *,size_t,
#retvals:
def set_type(self,atype):
"""sets the size of the rdf.
:param atype:
"""
_ldns.ldns_rdf_set_type(self,atype)
#parameters: ldns_rdf *,ldns_rdf_type,
#retvals:
def size(self):
"""returns the size of the rdf.
:returns: (size_t) uint16_t with the size
"""
return _ldns.ldns_rdf_size(self)
#parameters: const ldns_rdf *,
#retvals: size_t
@staticmethod
def dname_new_frm_str(str):
"""Creates a new dname rdf instance from a string.
This static method is equivalent to using of default class constructor.
:parameter str: str string to use
"""
return _ldns.ldns_dname_new_frm_str(str)
def absolute(self):
"""Checks whether the given dname string is absolute (i.e. ends with a '.')
:returns: (bool) True or False
"""
return self.endswith(".")
def make_canonical(self):
"""Put a dname into canonical fmt - ie. lowercase it
"""
_ldns.ldns_dname2canonical(self)
def dname_compare(self,other):
"""Compares the two dname rdf's according to the algorithm for ordering in RFC4034 Section 6.
:param other:
the second dname rdf to compare
:returns: (int) -1 if dname comes before other, 1 if dname comes after other, and 0 if they are equal.
"""
return _ldns.ldns_dname_compare(self,other)
def cat(self,rd2):
"""concatenates rd2 after this dname (rd2 is copied, this dname is modified)
:param rd2:
the rightside
:returns: (ldns_status) LDNS_STATUS_OK on success
"""
return _ldns.ldns_dname_cat(self,rd2)
#parameters: ldns_rdf *,ldns_rdf *,
#retvals: ldns_status
def cat_clone(self,rd2):
"""concatenates two dnames together
:param rd2:
the rightside
:returns: (ldns_rdf \*) a new rdf with leftside/rightside
"""
return _ldns.ldns_dname_cat_clone(self,rd2)
#parameters: const ldns_rdf *,const ldns_rdf *,
#retvals: ldns_rdf *
def interval(self,middle,next):
"""check if middle lays in the interval defined by prev and next prev <= middle < next.
This is usefull for nsec checking
:param middle:
the dname to check
:param next:
the next dname return 0 on error or unknown, -1 when middle is in the interval, +1 when not
:returns: (int)
"""
return _ldns.ldns_dname_interval(self,middle,next)
#parameters: const ldns_rdf *,const ldns_rdf *,const ldns_rdf *,
#retvals: int
def is_subdomain(self,parent):
"""Tests wether the name sub falls under parent (i.e. is a subdomain of parent).
This function will return false if the given dnames are equal.
:param parent:
(ldns_rdf) the parent's name
:returns: (bool) true if sub falls under parent, otherwise false
"""
return _ldns.ldns_dname_is_subdomain(self,parent)
#parameters: const ldns_rdf *,const ldns_rdf *,
#retvals: bool
def label(self,labelpos):
"""look inside the rdf and if it is an LDNS_RDF_TYPE_DNAME try and retrieve a specific label.
The labels are numbered starting from 0 (left most).
:param labelpos:
return the label with this number
:returns: (ldns_rdf \*) a ldns_rdf* with the label as name or NULL on error
"""
return _ldns.ldns_dname_label(self,labelpos)
#parameters: const ldns_rdf *,uint8_t,
#retvals: ldns_rdf *
def label_count(self):
"""count the number of labels inside a LDNS_RDF_DNAME type rdf.
:returns: (uint8_t) the number of labels
"""
return _ldns.ldns_dname_label_count(self)
#parameters: const ldns_rdf *,
#retvals: uint8_t
def left_chop(self):
"""chop one label off the left side of a dname.
so wwww.nlnetlabs.nl, becomes nlnetlabs.nl
:returns: (ldns_rdf \*) the remaining dname
"""
return _ldns.ldns_dname_left_chop(self)
#parameters: const ldns_rdf *,
#retvals: ldns_rdf *
def reverse(self):
"""Returns a clone of the given dname with the labels reversed.
:returns: (ldns_rdf \*) clone of the dname with the labels reversed.
"""
return _ldns.ldns_dname_reverse(self)
#parameters: const ldns_rdf *,
#retvals: ldns_rdf *
#_LDNS_RDF_METHODS#
%}
}

View File

@@ -0,0 +1,940 @@
/******************************************************************************
* ldns_resolver.i: LDNS resolver class
*
* 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.
******************************************************************************/
%typemap(in,numinputs=0,noblock=1) (ldns_resolver **r)
{
ldns_resolver *$1_res;
$1 = &$1_res;
}
/* result generation */
%typemap(argout,noblock=1) (ldns_resolver **r)
{
$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr($1_res), SWIGTYPE_p_ldns_struct_resolver, SWIG_POINTER_OWN | 0 ));
}
//TODO: pop_nameserver a podobne funkce musi predat objekt do spravy PYTHONU!!
%newobject ldns_resolver_pop_nameserver;
%newobject ldns_resolver_query;
%newobject ldns_axfr_next;
%delobject ldns_resolver_deep_free;
%delobject ldns_resolver_free;
%nodefaultctor ldns_struct_resolver; //no default constructor & destructor
%nodefaultdtor ldns_struct_resolver;
%ignore ldns_struct_resolver::_searchlist;
%ignore ldns_struct_resolver::_nameservers;
%ignore ldns_resolver_set_nameservers;
%rename(ldns_resolver) ldns_struct_resolver;
#ifdef LDNS_DEBUG
%rename(__ldns_resolver_deep_free) ldns_resolver_deep_free;
%rename(__ldns_resolver_free) ldns_resolver_free;
%inline %{
void _ldns_resolver_free (ldns_resolver* r) {
printf("******** LDNS_RESOLVER deep free 0x%lX ************\n", (long unsigned int)r);
ldns_resolver_deep_free(r);
}
%}
#else
%rename(_ldns_resolver_deep_free) ldns_resolver_deep_free;
%rename(_ldns_resolver_free) ldns_resolver_free;
#endif
%feature("docstring") ldns_struct_resolver "LDNS resolver object.
The ldns_resolver object keeps a list of nameservers and can perform queries.
**Usage**
>>> import ldns
>>> resolver = ldns.ldns_resolver.new_frm_file(\"/etc/resolv.conf\")
>>> pkt = resolver.query(\"www.nic.cz\", ldns.LDNS_RR_TYPE_A,ldns.LDNS_RR_CLASS_IN)
>>> if (pkt) and (pkt.answer()):
>>> print pkt.answer()
www.nic.cz. 1757 IN A 217.31.205.50
This simple example instances a resolver in order to resolve www.nic.cz record of A type.
"
%extend ldns_struct_resolver {
%pythoncode %{
def __init__(self):
raise Exception("This class can't be created directly. Please use: new_frm_file(filename), new_frm_fp(file) or new_frm_fp_l(file,line)")
__swig_destroy__ = _ldns._ldns_resolver_free
#LDNS_RESOLVER_CONSTRUCTORS_#
@staticmethod
def new_frm_file(filename = "/etc/resolv.conf", raiseException=True):
"""Creates a resolver object from given filename
:param filename: name of file which contains informations (usually /etc/resolv.conf)
:param raiseException: if True, an exception occurs in case a resolver object can't be created
:returns: resolver object or None. If the object can't be created and raiseException is True, an exception occurs.
"""
status, resolver = _ldns.ldns_resolver_new_frm_file(filename)
if status != LDNS_STATUS_OK:
if (raiseException): raise Exception("Can't create resolver, error: %d" % status)
return None
return resolver
@staticmethod
def new_frm_fp(file, raiseException=True):
"""Creates a resolver object from file
:param file: a file object
:param raiseException: if True, an exception occurs in case a resolver object can't be created
:returns: resolver object or None. If the object can't be created and raiseException is True, an exception occurs.
"""
status, resolver = _ldns.ldns_resolver_new_frm_fp(file)
if status != LDNS_STATUS_OK:
if (raiseException): raise Exception("Can't create resolver, error: %d" % status)
return None
return resolver
@staticmethod
def new_frm_fp_l(file, raiseException=True):
"""Creates a resolver object from file
:param file: a file object
:param raiseException: if True, an exception occurs in case a resolver instance can't be created
:returns:
* resolver - resolver instance or None. If an instance can't be created and raiseException is True, an exception occurs.
* line - the line number (for debugging)
"""
status, resolver, line = _ldns.ldns_resolver_new_frm_fp_l(file)
if status != LDNS_STATUS_OK:
if (raiseException): raise Exception("Can't create resolver, error: %d" % status)
return None
return resolver, line
#_LDNS_RESOLVER_CONSTRUCTORS#
# High level functions
def get_addr_by_name(self, name, aclass = _ldns.LDNS_RR_CLASS_IN, flags = _ldns.LDNS_RD):
"""Ask the resolver about name and return all address records
:param name: (ldns_rdf) the name to look for
:param aclass: the class to use
:param flags: give some optional flags to the query
:returns: RR List object or None
**Usage**
>>> addr = resolver.get_addr_by_name("www.google.com", ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD)
>>> if (not addr): raise Exception("Can't retrieve server address")
>>> for rr in addr.rrs():
>>> print rr
www.l.google.com. 300 IN A 74.125.43.99
www.l.google.com. 300 IN A 74.125.43.103
www.l.google.com. 300 IN A 74.125.43.104
www.l.google.com. 300 IN A 74.125.43.147
"""
return _ldns.ldns_get_rr_list_addr_by_name(self, name, aclass, flags)
def get_name_by_addr(self, addr, aclass = _ldns.LDNS_RR_CLASS_IN, flags = _ldns.LDNS_RD):
"""Ask the resolver about the address and return the name
:param name: (ldns_rdf of A or AAAA type) the addr to look for. If a string is given, A or AAAA type is identified automatically
:param aclass: the class to use
:param flags: give some optional flags to the query
:returns: RR List object or None
**Usage**
>>> addr = resolver.get_name_by_addr("74.125.43.99", ldns.LDNS_RR_CLASS_IN, ldns.LDNS_RD)
>>> if (not addr): raise Exception("Can't retrieve server address")
>>> for rr in addr.rrs():
>>> print rr
99.43.125.74.in-addr.arpa. 85641 IN PTR bw-in-f99.google.com.
"""
rdf = addr
if isinstance(addr, str):
if (addr.find("::") >= 0): #IPv6
rdf = _ldns.ldns_rdf_new_frm_str(_ldns.LDNS_RDF_TYPE_AAAA, addr)
else:
rdf = _ldns.ldns_rdf_new_frm_str(_ldns.LDNS_RDF_TYPE_A, addr)
return _ldns.ldns_get_rr_list_name_by_addr(self, rdf, aclass, flags)
def print_to_file(self,output):
"""Print a resolver (in sofar that is possible) state to output."""
_ldns.ldns_resolver_print(output,self)
def axfr_start(self, domain, aclass):
"""Prepares the resolver for an axfr query. The query is sent and the answers can be read with axfr_next
**Usage**
::
status = resolver.axfr_start("nic.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 the results
while True:
rr = resolver.axfr_next()
if not rr:
break
print rr
"""
return _ldns.ldns_axfr_start(self, domain, aclass)
#parameters: ldns_resolver *resolver, ldns_rdf *domain, ldns_rr_class c
#retvals: int
def axfr_complete(self):
"""returns true if the axfr transfer has completed (i.e. 2 SOA RRs and no errors were encountered)"""
return _ldns.ldns_axfr_complete(self)
#parameters: const ldns_resolver *,
#retvals: bool
def axfr_last_pkt(self):
"""returns a pointer to the last ldns_pkt that was sent by the server in the AXFR transfer uasable for instance to get the error code on failure"""
return _ldns.ldns_axfr_last_pkt(self)
#parameters: const ldns_resolver *,
#retvals: ldns_pkt *
def axfr_next(self):
"""get the next stream of RRs in a AXFR"""
return _ldns.ldns_axfr_next(self)
#parameters: ldns_resolver *,
#retvals: ldns_rr *
#LDNS_RESOLVER_METHODS_#
def debug(self):
"""Get the debug status of the resolver.
:returns: (bool) true if so, otherwise false
"""
return _ldns.ldns_resolver_debug(self)
#parameters: const ldns_resolver *,
#retvals: bool
def dec_nameserver_count(self):
"""Decrement the resolver's nameserver count.
"""
_ldns.ldns_resolver_dec_nameserver_count(self)
#parameters: ldns_resolver *,
#retvals:
def defnames(self):
return _ldns.ldns_resolver_defnames(self)
#parameters: const ldns_resolver *,
#retvals: bool
def dnsrch(self):
return _ldns.ldns_resolver_dnsrch(self)
#parameters: const ldns_resolver *,
#retvals: bool
def dnssec(self):
"""Does the resolver do DNSSEC.
:returns: (bool) true: yes, false: no
"""
return _ldns.ldns_resolver_dnssec(self)
#parameters: const ldns_resolver *,
#retvals: bool
def dnssec_anchors(self):
"""Get the resolver's DNSSEC anchors.
:returns: (ldns_rr_list \*) an rr_list containg trusted DNSSEC anchors
"""
return _ldns.ldns_resolver_dnssec_anchors(self)
#parameters: const ldns_resolver *,
#retvals: ldns_rr_list *
def dnssec_cd(self):
"""Does the resolver set the CD bit.
:returns: (bool) true: yes, false: no
"""
return _ldns.ldns_resolver_dnssec_cd(self)
#parameters: const ldns_resolver *,
#retvals: bool
def domain(self):
"""What is the default dname to add to relative queries.
:returns: (ldns_rdf \*) the dname which is added
"""
return _ldns.ldns_resolver_domain(self)
#parameters: const ldns_resolver *,
#retvals: ldns_rdf *
def edns_udp_size(self):
"""Get the resolver's udp size.
:returns: (uint16_t) the udp mesg size
"""
return _ldns.ldns_resolver_edns_udp_size(self)
#parameters: const ldns_resolver *,
#retvals: uint16_t
def fail(self):
"""Does the resolver only try the first nameserver.
:returns: (bool) true: yes, fail, false: no, try the others
"""
return _ldns.ldns_resolver_fail(self)
#parameters: const ldns_resolver *,
#retvals: bool
def fallback(self):
"""Get the truncation fallback status.
:returns: (bool) whether the truncation fallback mechanism is used
"""
return _ldns.ldns_resolver_fallback(self)
#parameters: const ldns_resolver *,
#retvals: bool
def igntc(self):
"""Does the resolver ignore the TC bit (truncated).
:returns: (bool) true: yes, false: no
"""
return _ldns.ldns_resolver_igntc(self)
#parameters: const ldns_resolver *,
#retvals: bool
def incr_nameserver_count(self):
"""Incremental the resolver's nameserver count.
"""
_ldns.ldns_resolver_incr_nameserver_count(self)
#parameters: ldns_resolver *,
#retvals:
def ip6(self):
"""Does the resolver use ip6 or ip4.
:returns: (uint8_t) 0: both, 1: ip4, 2:ip6
"""
return _ldns.ldns_resolver_ip6(self)
#parameters: const ldns_resolver *,
#retvals: uint8_t
def nameserver_count(self):
"""How many nameserver are configured in the resolver.
:returns: (size_t) number of nameservers
"""
return _ldns.ldns_resolver_nameserver_count(self)
#parameters: const ldns_resolver *,
#retvals: size_t
def nameserver_rtt(self,pos):
"""Return the used round trip time for a specific nameserver.
:param pos:
the index to the nameserver
:returns: (size_t) the rrt, 0: infinite, >0: undefined (as of * yet)
"""
return _ldns.ldns_resolver_nameserver_rtt(self,pos)
#parameters: const ldns_resolver *,size_t,
#retvals: size_t
def nameservers(self):
"""Return the configured nameserver ip address.
:returns: (ldns_rdf \*\*) a ldns_rdf pointer to a list of the addresses
"""
return _ldns.ldns_resolver_nameservers(self)
#parameters: const ldns_resolver *,
#retvals: ldns_rdf **
def nameservers_randomize(self):
"""randomize the nameserver list in the resolver
"""
_ldns.ldns_resolver_nameservers_randomize(self)
#parameters: ldns_resolver *,
#retvals:
def pop_nameserver(self):
"""pop the last nameserver from the resolver.
:returns: (ldns_rdf \*) the popped address or NULL if empty
"""
return _ldns.ldns_resolver_pop_nameserver(self)
#parameters: ldns_resolver *,
#retvals: ldns_rdf *
def port(self):
"""Get the port the resolver should use.
:returns: (uint16_t) the port number
"""
return _ldns.ldns_resolver_port(self)
#parameters: const ldns_resolver *,
#retvals: uint16_t
def prepare_query_pkt(self,name,t,c,f):
"""Form a query packet from a resolver and name/type/class combo.
:param name:
:param t:
query for this type (may be 0, defaults to A)
:param c:
query for this class (may be 0, default to IN)
:param f:
the query flags
:returns: * (ldns_status) ldns_pkt* a packet with the reply from the nameserver
* (ldns_pkt \*\*) query packet class
"""
return _ldns.ldns_resolver_prepare_query_pkt(self,name,t,c,f)
#parameters: ldns_resolver *,const ldns_rdf *,ldns_rr_type,ldns_rr_class,uint16_t,
#retvals: ldns_status,ldns_pkt **
def push_dnssec_anchor(self,rr):
"""Push a new trust anchor to the resolver.
It must be a DS or DNSKEY rr
:param rr:
the RR to add as a trust anchor.
:returns: (ldns_status) a status
"""
return _ldns.ldns_resolver_push_dnssec_anchor(self,rr)
#parameters: ldns_resolver *,ldns_rr *,
#retvals: ldns_status
def push_nameserver(self,n):
"""push a new nameserver to the resolver.
It must be an IP address v4 or v6.
:param n:
the ip address
:returns: (ldns_status) ldns_status a status
"""
return _ldns.ldns_resolver_push_nameserver(self,n)
#parameters: ldns_resolver *,ldns_rdf *,
#retvals: ldns_status
def push_nameserver_rr(self,rr):
"""push a new nameserver to the resolver.
It must be an A or AAAA RR record type
:param rr:
the resource record
:returns: (ldns_status) ldns_status a status
"""
return _ldns.ldns_resolver_push_nameserver_rr(self,rr)
#parameters: ldns_resolver *,ldns_rr *,
#retvals: ldns_status
def push_nameserver_rr_list(self,rrlist):
"""push a new nameserver rr_list to the resolver.
:param rrlist:
the rr_list to push
:returns: (ldns_status) ldns_status a status
"""
return _ldns.ldns_resolver_push_nameserver_rr_list(self,rrlist)
#parameters: ldns_resolver *,ldns_rr_list *,
#retvals: ldns_status
def push_searchlist(self,rd):
"""Push a new rd to the resolver's searchlist.
:param rd:
to push
"""
_ldns.ldns_resolver_push_searchlist(self,rd)
#parameters: ldns_resolver *,ldns_rdf *,
#retvals:
def query(self,name,atype=_ldns.LDNS_RR_TYPE_A,aclass=_ldns.LDNS_RR_CLASS_IN,flags=_ldns.LDNS_RD):
"""Send a query to a nameserver.
:param name: (ldns_rdf) the name to look for
:param atype: the RR type to use
:param aclass: the RR class to use
:param flags: give some optional flags to the query
:returns: (ldns_pkt) a packet with the reply from the nameserver if _defnames is true the default domain will be added
"""
return _ldns.ldns_resolver_query(self,name,atype,aclass,flags)
#parameters: const ldns_resolver *,const ldns_rdf *,ldns_rr_type,ldns_rr_class,uint16_t,
#retvals: ldns_pkt *
def random(self):
"""Does the resolver randomize the nameserver before usage.
:returns: (bool) true: yes, false: no
"""
return _ldns.ldns_resolver_random(self)
#parameters: const ldns_resolver *,
#retvals: bool
def recursive(self):
"""Is the resolver set to recurse.
:returns: (bool) true if so, otherwise false
"""
return _ldns.ldns_resolver_recursive(self)
#parameters: const ldns_resolver *,
#retvals: bool
def retrans(self):
"""Get the retransmit interval.
:returns: (uint8_t) the retransmit interval
"""
return _ldns.ldns_resolver_retrans(self)
#parameters: const ldns_resolver *,
#retvals: uint8_t
def retry(self):
"""Get the number of retries.
:returns: (uint8_t) the number of retries
"""
return _ldns.ldns_resolver_retry(self)
#parameters: const ldns_resolver *,
#retvals: uint8_t
def rtt(self):
"""Return the used round trip times for the nameservers.
:returns: (size_t \*) a size_t* pointer to the list. yet)
"""
return _ldns.ldns_resolver_rtt(self)
#parameters: const ldns_resolver *,
#retvals: size_t *
def search(self,rdf,t,c,flags):
"""Send the query for using the resolver and take the search list into account The search algorithm is as follows: If the name is absolute, try it as-is, otherwise apply the search list.
:param rdf:
:param t:
query for this type (may be 0, defaults to A)
:param c:
query for this class (may be 0, default to IN)
:param flags:
the query flags
:returns: (ldns_pkt \*) ldns_pkt* a packet with the reply from the nameserver
"""
return _ldns.ldns_resolver_search(self,rdf,t,c,flags)
#parameters: const ldns_resolver *,const ldns_rdf *,ldns_rr_type,ldns_rr_class,uint16_t,
#retvals: ldns_pkt *
def searchlist(self):
"""What is the searchlist as used by the resolver.
:returns: (ldns_rdf \*\*) a ldns_rdf pointer to a list of the addresses
"""
return _ldns.ldns_resolver_searchlist(self)
#parameters: const ldns_resolver *,
#retvals: ldns_rdf \*\*
def searchlist_count(self):
"""Return the resolver's searchlist count.
:returns: (size_t) the searchlist count
"""
return _ldns.ldns_resolver_searchlist_count(self)
#parameters: const ldns_resolver *,
#retvals: size_t
def send(self,name,t,c,flags):
"""Send the query for name as-is.
:param name:
:param t:
query for this type (may be 0, defaults to A)
:param c:
query for this class (may be 0, default to IN)
:param flags:
the query flags
:returns: * (ldns_status) ldns_pkt* a packet with the reply from the nameserver
* (ldns_pkt \*\*)
"""
return _ldns.ldns_resolver_send(self,name,t,c,flags)
#parameters: ldns_resolver *,const ldns_rdf *,ldns_rr_type,ldns_rr_class,uint16_t,
#retvals: ldns_status,ldns_pkt **
def send_pkt(self,query_pkt):
"""Send the given packet to a nameserver.
:param query_pkt:
:returns: * (ldns_status)
* (ldns_pkt \*\*)
"""
return _ldns.ldns_resolver_send_pkt(self,query_pkt)
#parameters: ldns_resolver *,ldns_pkt *,
#retvals: ldns_status,ldns_pkt **
def set_debug(self,b):
"""Set the resolver debugging.
:param b:
true: debug on: false debug off
"""
_ldns.ldns_resolver_set_debug(self,b)
#parameters: ldns_resolver *,bool,
#retvals:
def set_defnames(self,b):
"""Whether the resolver uses the name set with _set_domain.
:param b:
true: use the defaults, false: don't use them
"""
_ldns.ldns_resolver_set_defnames(self,b)
#parameters: ldns_resolver *,bool,
#retvals:
def set_dnsrch(self,b):
"""Whether the resolver uses the searchlist.
:param b:
true: use the list, false: don't use the list
"""
_ldns.ldns_resolver_set_dnsrch(self,b)
#parameters: ldns_resolver *,bool,
#retvals:
def set_dnssec(self,b):
"""Whether the resolver uses DNSSEC.
:param b:
true: use DNSSEC, false: don't use DNSSEC
"""
_ldns.ldns_resolver_set_dnssec(self,b)
#parameters: ldns_resolver *,bool,
#retvals:
def set_dnssec_anchors(self,l):
"""Set the resolver's DNSSEC anchor list directly.
RRs should be of type DS or DNSKEY.
:param l:
the list of RRs to use as trust anchors
"""
_ldns.ldns_resolver_set_dnssec_anchors(self,l)
#parameters: ldns_resolver *,ldns_rr_list *,
#retvals:
def set_dnssec_cd(self,b):
"""Whether the resolver uses the checking disable bit.
:param b:
true: enable , false: don't use TCP
"""
_ldns.ldns_resolver_set_dnssec_cd(self,b)
#parameters: ldns_resolver *,bool,
#retvals:
def set_domain(self,rd):
"""Set the resolver's default domain.
This gets appended when no absolute name is given
:param rd:
the name to append
"""
_ldns.ldns_resolver_set_domain(self,rd)
#parameters: ldns_resolver *,ldns_rdf *,
#retvals:
def set_edns_udp_size(self,s):
"""Set maximum udp size.
:param s:
the udp max size
"""
_ldns.ldns_resolver_set_edns_udp_size(self,s)
#parameters: ldns_resolver *,uint16_t,
#retvals:
def set_fail(self,b):
"""Whether or not to fail after one failed query.
:param b:
true: yes fail, false: continue with next nameserver
"""
_ldns.ldns_resolver_set_fail(self,b)
#parameters: ldns_resolver *,bool,
#retvals:
def set_fallback(self,fallback):
"""Set whether the resolvers truncation fallback mechanism is used when ldns_resolver_query() is called.
:param fallback:
whether to use the fallback mechanism
"""
_ldns.ldns_resolver_set_fallback(self,fallback)
#parameters: ldns_resolver *,bool,
#retvals:
def set_igntc(self,b):
"""Whether or not to ignore the TC bit.
:param b:
true: yes ignore, false: don't ignore
"""
_ldns.ldns_resolver_set_igntc(self,b)
#parameters: ldns_resolver *,bool,
#retvals:
def set_ip6(self,i):
"""Whether the resolver uses ip6.
:param i:
0: no pref, 1: ip4, 2: ip6
"""
_ldns.ldns_resolver_set_ip6(self,i)
#parameters: ldns_resolver *,uint8_t,
#retvals:
def set_nameserver_count(self,c):
"""Set the resolver's nameserver count directly.
:param c:
the nameserver count
"""
_ldns.ldns_resolver_set_nameserver_count(self,c)
#parameters: ldns_resolver *,size_t,
#retvals:
def set_nameserver_rtt(self,pos,value):
"""Set round trip time for a specific nameserver.
Note this currently differentiates between: unreachable and reachable.
:param pos:
the nameserver position
:param value:
the rtt
"""
_ldns.ldns_resolver_set_nameserver_rtt(self,pos,value)
#parameters: ldns_resolver *,size_t,size_t,
#retvals:
def set_nameservers(self,rd):
"""Set the resolver's nameserver count directly by using an rdf list.
:param rd:
the resolver addresses
"""
_ldns.ldns_resolver_set_nameservers(self,rd)
#parameters: ldns_resolver *,ldns_rdf **,
#retvals:
def set_port(self,p):
"""Set the port the resolver should use.
:param p:
the port number
"""
_ldns.ldns_resolver_set_port(self,p)
#parameters: ldns_resolver *,uint16_t,
#retvals:
def set_random(self,b):
"""Should the nameserver list be randomized before each use.
:param b:
true: randomize, false: don't
"""
_ldns.ldns_resolver_set_random(self,b)
#parameters: ldns_resolver *,bool,
#retvals:
def set_recursive(self,b):
"""Set the resolver recursion.
:param b:
true: set to recurse, false: unset
"""
_ldns.ldns_resolver_set_recursive(self,b)
#parameters: ldns_resolver *,bool,
#retvals:
def set_retrans(self,re):
"""Set the resolver retrans timeout (in seconds).
:param re:
the retransmission interval in seconds
"""
_ldns.ldns_resolver_set_retrans(self,re)
#parameters: ldns_resolver *,uint8_t,
#retvals:
def set_retry(self,re):
"""Set the resolver retry interval (in seconds).
:param re:
the retry interval
"""
_ldns.ldns_resolver_set_retry(self,re)
#parameters: ldns_resolver *,uint8_t,
#retvals:
def set_rtt(self,rtt):
"""Set round trip time for all nameservers.
Note this currently differentiates between: unreachable and reachable.
:param rtt:
a list with the times
"""
_ldns.ldns_resolver_set_rtt(self,rtt)
#parameters: ldns_resolver *,size_t *,
#retvals:
def set_searchlist_count(self,c):
_ldns.ldns_resolver_set_searchlist_count(self,c)
#parameters: ldns_resolver *,size_t,
#retvals:
def set_timeout(self,timeout):
"""Set the resolver's socket time out when talking to remote hosts.
:param timeout:
the timeout to use
"""
_ldns.ldns_resolver_set_timeout(self,timeout)
#parameters: ldns_resolver *,struct timeval,
#retvals:
def set_tsig_algorithm(self,tsig_algorithm):
"""Set the tsig algorithm.
:param tsig_algorithm:
the tsig algorithm
"""
_ldns.ldns_resolver_set_tsig_algorithm(self,tsig_algorithm)
#parameters: ldns_resolver *,char *,
#retvals:
def set_tsig_keydata(self,tsig_keydata):
"""Set the tsig key data.
:param tsig_keydata:
the key data
"""
_ldns.ldns_resolver_set_tsig_keydata(self,tsig_keydata)
#parameters: ldns_resolver *,char *,
#retvals:
def set_tsig_keyname(self,tsig_keyname):
"""Set the tsig key name.
:param tsig_keyname:
the tsig key name
"""
_ldns.ldns_resolver_set_tsig_keyname(self,tsig_keyname)
#parameters: ldns_resolver *,char *,
#retvals:
def set_usevc(self,b):
"""Whether the resolver uses a virtual circuit (TCP).
:param b:
true: use TCP, false: don't use TCP
"""
_ldns.ldns_resolver_set_usevc(self,b)
#parameters: ldns_resolver *,bool,
#retvals:
def timeout(self):
"""What is the timeout on socket connections.
:returns: (struct timeval) the timeout as struct timeval
"""
return _ldns.ldns_resolver_timeout(self)
#parameters: const ldns_resolver *,
#retvals: struct timeval
def trusted_key(self,keys,trusted_keys):
"""Returns true if at least one of the provided keys is a trust anchor.
:param keys:
the keyset to check
:param trusted_keys:
the subset of trusted keys in the 'keys' rrset
:returns: (bool) true if at least one of the provided keys is a configured trust anchor
"""
return _ldns.ldns_resolver_trusted_key(self,keys,trusted_keys)
#parameters: const ldns_resolver *,ldns_rr_list *,ldns_rr_list *,
#retvals: bool
def tsig_algorithm(self):
"""Return the tsig algorithm as used by the nameserver.
:returns: (char \*) the algorithm used.
"""
return _ldns.ldns_resolver_tsig_algorithm(self)
#parameters: const ldns_resolver *,
#retvals: char *
def tsig_keydata(self):
"""Return the tsig keydata as used by the nameserver.
:returns: (char \*) the keydata used.
"""
return _ldns.ldns_resolver_tsig_keydata(self)
#parameters: const ldns_resolver *,
#retvals: char *
def tsig_keyname(self):
"""Return the tsig keyname as used by the nameserver.
:returns: (char \*) the name used.
"""
return _ldns.ldns_resolver_tsig_keyname(self)
#parameters: const ldns_resolver *,
#retvals: char *
def usevc(self):
"""Does the resolver use tcp or udp.
:returns: (bool) true: tcp, false: udp
"""
return _ldns.ldns_resolver_usevc(self)
#parameters: const ldns_resolver *,
#retvals: bool
#_LDNS_RESOLVER_METHODS#
%}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,298 @@
/******************************************************************************
* ldns_zone.i: LDNS zone class
*
* 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.
******************************************************************************/
%typemap(in,numinputs=0,noblock=1) (ldns_zone **)
{
ldns_zone *$1_zone;
$1 = &$1_zone;
}
/* result generation */
%typemap(argout,noblock=1) (ldns_zone **)
{
$result = SWIG_Python_AppendOutput($result, SWIG_NewPointerObj(SWIG_as_voidptr($1_zone), SWIGTYPE_p_ldns_struct_zone, SWIG_POINTER_OWN | 0 ));
}
%nodefaultctor ldns_struct_zone; //no default constructor & destructor
%nodefaultdtor ldns_struct_zone;
%newobject ldns_zone_new_frm_fp;
%newobject ldns_zone_new_frm_fp_l;
%newobject ldns_zone_new;
%delobject ldns_zone_free;
%delobject ldns_zone_deep_free;
%delobject ldns_zone_push_rr;
%delobject ldns_zone_push_rr_list;
%ignore ldns_struct_zone::_soa;
%ignore ldns_struct_zone::_rrs;
%rename(ldns_zone) ldns_struct_zone;
#ifdef LDNS_DEBUG
%rename(__ldns_zone_free) ldns_zone_free;
%rename(__ldns_zone_deep_free) ldns_zone_deep_free;
%inline %{
void _ldns_zone_free (ldns_zone* z) {
printf("******** LDNS_ZONE free 0x%lX ************\n", (long unsigned int)z);
ldns_zone_deep_free(z);
}
%}
#else
%rename(__ldns_zone_free) ldns_zone_free;
%rename(_ldns_zone_free) ldns_zone_deep_free;
#endif
%feature("docstring") ldns_struct_zone "Zone definitions
**Usage**
This class is able to read and parse the content of zone file by doing:
>>> import ldns
>>> zone = ldns.ldns_zone.new_frm_fp(open(\"zone.txt\",\"r\"), None, 0, ldns.LDNS_RR_CLASS_IN)
>>> print zone.soa()
example. 600 IN SOA example. admin.example. 2008022501 28800 7200 604800 18000
>>> print zone.rrs()
example. 600 IN MX 10 mail.example.
example. 600 IN NS ns1.example.
example. 600 IN NS ns2.example.
example. 600 IN A 192.168.1.1
The ``zone.txt`` file contains the following records::
$ORIGIN example.
$TTL 600
example. IN SOA example. admin.example. (
2008022501 ; serial
28800 ; refresh (8 hours)
7200 ; retry (2 hours)
604800 ; expire (1 week)
18000 ; minimum (5 hours)
)
@ IN MX 10 mail.example.
@ IN NS ns1
@ IN NS ns2
@ IN A 192.168.1.1
"
%extend ldns_struct_zone {
%pythoncode %{
def __init__(self):
self.this = _ldns.ldns_zone_new()
if not self.this:
raise Exception("Can't create zone.")
__swig_destroy__ = _ldns._ldns_zone_free
def __str__(self):
return str(self.soa()) + "\n" + str(self.rrs())
def print_to_file(self,output):
"""Prints the data in the zone to the given file stream (in presentation format)."""
_ldns.ldns_zone_print(output,self)
#parameters: FILE *,const ldns_zone *,
#LDNS_ZONE_CONSTRUCTORS_#
@staticmethod
def new_frm_fp(file, origin, ttl, rr_class=_ldns.LDNS_RR_CLASS_IN, raiseException=True):
"""Creates a new zone object from given file pointer
:param file: a file object
:param origin: (ldns_rdf) the zones' origin
:param ttl: default ttl to use
:param rr_class: efault class to use (IN)
:param raiseException: if True, an exception occurs in case a zone instance can't be created
:returns: zone instance or None. If an instance can't be created and raiseException is True, an exception occurs.
"""
status, zone = _ldns.ldns_zone_new_frm_fp(file, origin, ttl, rr_class)
if status != LDNS_STATUS_OK:
if (raiseException): raise Exception("Can't create zone, error: %s (%d)" % (_ldns.ldns_get_errorstr_by_id(status),status))
return None
return zone
@staticmethod
def new_frm_fp_l(file, origin, ttl, rr_class, raiseException=True):
"""Create a new zone from a file, keep track of the line numbering
:param file: a file object
:param origin: (ldns_rdf) the zones' origin
:param ttl: default ttl to use
:param rr_class: efault class to use (IN)
:param raiseException: if True, an exception occurs in case a zone instance can't be created
:returns:
* zone - zone instance or None. If an instance can't be created and raiseException is True, an exception occurs.
* line - used for error msg, to get to the line number
"""
status, zone = _ldns.ldns_zone_new_frm_fp_l(file, line)
if status != LDNS_STATUS_OK:
if (raiseException): raise Exception("Can't create zone, error: %d" % status)
return None
return zone
#_LDNS_ZONE_CONSTRUCTORS#
def sign(self,key_list):
"""Signs the zone, and returns a newly allocated signed zone.
:param key_list:
list of keys to sign with
:returns: (ldns_zone \*) signed zone
"""
return _ldns.ldns_zone_sign(self,key_list)
#parameters: const ldns_zone *,ldns_key_list *,
#retvals: ldns_zone *
def sign_nsec3(self,key_list,algorithm,flags,iterations,salt_length,salt):
"""Signs the zone with NSEC3, and returns a newly allocated signed zone.
:param key_list:
list of keys to sign with
:param algorithm:
the NSEC3 hashing algorithm to use
:param flags:
NSEC3 flags
:param iterations:
the number of NSEC3 hash iterations to use
:param salt_length:
the length (in octets) of the NSEC3 salt
:param salt:
the NSEC3 salt data
:returns: (ldns_zone \*) signed zone
"""
return _ldns.ldns_zone_sign_nsec3(self,key_list,algorithm,flags,iterations,salt_length,salt)
#parameters: ldns_zone *,ldns_key_list *,uint8_t,uint8_t,uint16_t,uint8_t,uint8_t *,
#retvals: ldns_zone *
#LDNS_ZONE_METHODS_#
def glue_rr_list(self):
"""Retrieve all resource records from the zone that are glue records.
The resulting list does are pointer references to the zone's data.
Due to the current zone implementation (as a list of rr's), this function is extremely slow. Another (probably better) way to do this is to use an ldns_dnssec_zone structure and the mark_glue function
:returns: (ldns_rr_list \*) the rr_list with the glue
"""
return _ldns.ldns_zone_glue_rr_list(self)
#parameters: const ldns_zone *,
#retvals: ldns_rr_list *
def push_rr(self,rr):
"""push an single rr to a zone structure.
This function use pointer copying, so the rr_list structure inside z is modified!
:param rr:
the rr to add
:returns: (bool) a true on succes otherwise falsed
"""
return _ldns.ldns_zone_push_rr(self,rr)
#parameters: ldns_zone *,ldns_rr *,
#retvals: bool
def push_rr_list(self,list):
"""push an rrlist to a zone structure.
This function use pointer copying, so the rr_list structure inside z is modified!
:param list:
the list to add
:returns: (bool) a true on succes otherwise falsed
"""
return _ldns.ldns_zone_push_rr_list(self,list)
#parameters: ldns_zone *,ldns_rr_list *,
#retvals: bool
def rr_count(self):
"""Returns the number of resource records in the zone, NOT counting the SOA record.
:returns: (size_t) the number of rr's in the zone
"""
return _ldns.ldns_zone_rr_count(self)
#parameters: const ldns_zone *,
#retvals: size_t
def rrs(self):
"""Get a list of a zone's content.
Note that the SOA isn't included in this list. You need to get the with ldns_zone_soa.
:returns: (ldns_rr_list \*) the rrs from this zone
"""
return _ldns.ldns_zone_rrs(self)
#parameters: const ldns_zone *,
#retvals: ldns_rr_list *
def set_rrs(self,rrlist):
"""Set the zone's contents.
:param rrlist:
the rrlist to use
"""
_ldns.ldns_zone_set_rrs(self,rrlist)
#parameters: ldns_zone *,ldns_rr_list *,
#retvals:
def set_soa(self,soa):
"""Set the zone's soa record.
:param soa:
the soa to set
"""
_ldns.ldns_zone_set_soa(self,soa)
#parameters: ldns_zone *,ldns_rr *,
#retvals:
def soa(self):
"""Return the soa record of a zone.
:returns: (ldns_rr \*) the soa record in the zone
"""
return _ldns.ldns_zone_soa(self)
#parameters: const ldns_zone *,
#retvals: ldns_rr *
def sort(self):
"""Sort the rrs in a zone, with the current impl.
this is slow
"""
_ldns.ldns_zone_sort(self)
#parameters: ldns_zone *,
#retvals:
#_LDNS_ZONE_METHODS#
%}
}