Skip to content

Commit

Permalink
lua2backend: Add new backend
Browse files Browse the repository at this point in the history
This is API version 1 of lua2 backend.

It provides improved interface for Lua script to act as backends.

Configuration
 - `lua2-filename` - path to script
 - `lua2-query-logging` - log lua queries and results
 - `lua2-api' - API version (default 1)
  • Loading branch information
cmouse committed Jan 8, 2018
1 parent f560a1c commit 7e62cc9
Show file tree
Hide file tree
Showing 11 changed files with 665 additions and 0 deletions.
5 changes: 5 additions & 0 deletions configure.ac
Expand Up @@ -237,6 +237,10 @@ AM_CONDITIONAL([SQLITE3], [test "x$needsqlite3" = "xyes"])

for a in $modules; do
AC_MSG_CHECKING([whether we can build module "${a}"])
AS_IF([test "x$a" = "xlua2"], [
AS_IF([test "x$with_lua" != "xyes"],
AC_MSG_ERROR([Cannot build lua2 module without lua]),[])
])
if [[ -d "$srcdir/modules/${a}backend" ]]; then
AC_MSG_RESULT([yes])
moduledirs="$moduledirs ${a}backend"
Expand Down Expand Up @@ -314,6 +318,7 @@ AC_CONFIG_FILES([
modules/gsqlite3backend/Makefile
modules/ldapbackend/Makefile
modules/luabackend/Makefile
modules/lua2backend/Makefile
modules/mydnsbackend/Makefile
modules/opendbxbackend/Makefile
modules/oraclebackend/Makefile
Expand Down
3 changes: 3 additions & 0 deletions docs/backends/index.rst
Expand Up @@ -22,6 +22,8 @@ The following table describes the supported backends and some of their capabilit
+------------------------------------------------+--------+--------+-------+--------------+-------------+---------------------------------+--------------+
| :doc:`LDAP <ldap>` | Yes | No | No | No | No | No | ``ldap`` |
+------------------------------------------------+--------+--------+-------+--------------+-------------+---------------------------------+--------------+
| :doc:`Lua2 <lua2>` | Yes | Yes | No | No | Yes | Yes | ``lua2`` |
+------------------------------------------------+--------+--------+-------+--------------+-------------+---------------------------------+--------------+
| :doc:`MyDNS <mydns>` | Yes | No | No | No | No | No | ``mydns`` |
+------------------------------------------------+--------+--------+-------+--------------+-------------+---------------------------------+--------------+
| :doc:`OpenDBX <opendbx>` | Yes | Yes | Yes | Yes | No | No | ``opendbx`` |
Expand Down Expand Up @@ -53,6 +55,7 @@ These backends have :doc:`features unique <generic-sql>` to the generic SQL back
geoip
ldap
lua
lua2
mydns
opendbx
oracle
Expand Down
160 changes: 160 additions & 0 deletions docs/backends/lua2.rst
@@ -0,0 +1,160 @@
Lua Backend
===========

* Native: Yes
* Master: Yes
* Slave: No
* Superslave: No
* Autoserial: No
* DNSSEC: Yes
* Disabled data: No
* Comments: No
* Module name: lua2
* Launch name: ``lua2``

This is a rewrite of existing Lua backend.
This backend is stub between your Lua script and PowerDNS authoritative server.
The backend uses AuthLua4 base class, and you can use same functions and types as in any other Lua script.

.. warning::
Some of the function calls and configuration settings have been changed, please review this document carefully.

.. warning::
All places which use DNS names now use DNSName class which cannot be compared directly to a string.
To compare them against a string use either ``tostring(dnsname)`` or ``newDN(string)``.

API description (v1)
^^^^^^^^^^^^^^^^^^^^

``bool dns_dnssec``
~~~~~~~~~~~~~~~~~~~
If your script supports DNSSEC, set this to true.

``dns_lookup(qtype, qname, domain_id)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Perform lookup of given resource record name and type.

INPUT:
- string qtype - Type of queried resource record
- DNSName qname - Name of queried resource record
- int domain_id - ID of associated domain

OUTPUT:
Expects a table which has rows of following tables:
- DNSName name - resource record name (can also be string)
- string type - type of resource record
- string content - resource record content
- int ttl - time to live for this resource record (default: configured value)
- int domain_id - ID of associated domain (default: -1)
- bool auth - Whether data is authoritative or not (default: true)
- int last_modified - UNIX timestamp of last modification
- int scope_mask - How many bytes of source IP netmask was used for this result

NOTES:
Return empty table if you have no results.
The requested record type is unlikely to match what was asked from PowerDNS.
This function is **required**.


``dns_list(target, domain_id)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
List all resource records for target.

INPUT:
- DNSName target - Zone name to list
- int domain_id - Associated domain ID

OUTPUT:
Same as ``lookup`` function. Return false if not found or wanted.

NOTES:
This function is **optional**.

``dns_get_domaininfo(domain)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get domain information for given domain.

INPUT:
- DNSName domain - Domain to get info for

OUTPUT:
Return false if not supported or found, otherwise expects a table of:
- string account - Associated account of this domain (default: <empty>)
- string kind - Domain kind (NATIVE,MASTER,SLAVE) (default: master)
- int id - Associated domain ID (default: -1)
- int last_check - UNIX timestamp of last check from master
- table of strings masters - Master servers for this domain (default: <empty>)
- long notified_serial - Notified serial to slaves
- long serial - Current domain serial

NOTES:
This function is **optional**.
masters, account, last_check, notified_serial are for master/slave interaction only.

``dns_get_all_domains()``
~~~~~~~~~~~~~~~~~~~~~~~~~
Get domain information for all domains.

OUTPUT:
Return false if not supported or found, otherwise return a table of string, domaininfo. See ``dns_get_domaininfo```.

NOTES:
This function is **optional**.

``dns_get_domain_metadata(domain, kind)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get metadata value(s) for given domain and metadata kind.

INPUT:
- DNSName domain - Domain to get metadata for
- string kind - What kind of metadata to return

OUTPUT:
- table of strings. Or false if not supported or found.

NOTES:
This function is **required** if ``dns_dnssec`` is true.

``dns_get_all_domain_metadata(domain)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get all metadata for domain.

INPUT:
- DNSName domain - Domain to get metadata for

OUTPUT:
- table of string keys with table of strings. Or false if not supported or found.

NOTES:
This function is **optional**.

``dns_get_domain_keys(domain)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Get DNSSEC key(s) for the given domain. Content must be valid key record in format that PowerDNS understands.

INPUT:
- DNSName domain - Domain to get key(s) for

OUTPUT:
Return false if not found or supported, otherwise expects table of:
- int id - Key ID
- int flags - Key flags
- bool active - Is key active
- string content - Key itself

NOTES:
This function is **optional**. However, not implementing this means you cannot do live signing.

``dns_get_before_and_after_names_absolute(id, qname)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Calculate NSEC before/after value for the given qname for domain with id.

INPUT:
- int id - Associated domain id
- DNSName qname - DNS name to calculate

OUTPUT:
Tuple of three DNSNames. Unhashed, before and after.

NOTES:
This function is **required** if ``dns_dnssec`` is true.
1 change: 1 addition & 0 deletions modules/Makefile.am
Expand Up @@ -10,6 +10,7 @@ DIST_SUBDIRS = \
gsqlite3backend \
ldapbackend \
luabackend \
lua2backend \
mydnsbackend \
opendbxbackend \
oraclebackend \
Expand Down
13 changes: 13 additions & 0 deletions modules/lua2backend/Makefile.am
@@ -0,0 +1,13 @@
AM_CPPFLAGS += $(LUA_CFLAGS) \
-I$(top_srcdir)/ext/luawrapper/include

EXTRA_DIST = OBJECTFILES OBJECTLIBS

pkglib_LTLIBRARIES = liblua2backend.la

liblua2backend_la_SOURCES = \
lua2backend.cc lua2backend.hh \
lua2api1.hh lua2api1.cc

liblua2backend_la_LDFLAGS = -module -avoid-version
liblua2backend_la_LIBADD = $(LUA_LIBS)
1 change: 1 addition & 0 deletions modules/lua2backend/OBJECTFILES
@@ -0,0 +1 @@
lua2backend.lo lua2api1.lo
1 change: 1 addition & 0 deletions modules/lua2backend/OBJECTLIBS
@@ -0,0 +1 @@
$(LUA_LIBS)
27 changes: 27 additions & 0 deletions modules/lua2backend/lua2api1.cc
@@ -0,0 +1,27 @@
/*
* This file is part of PowerDNS or dnsdist.
* Copyright -- PowerDNS.COM B.V. and its contributors
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* In addition, for the avoidance of any doubt, permission is granted to
* link this program with OpenSSL and to (re)distribute the binaries
* produced as the result of such linking.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTAPILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "lua2backend.hh"

Lua2BackendAPIv1::~Lua2BackendAPIv1(){}

0 comments on commit 7e62cc9

Please sign in to comment.