Skip to content

Commit

Permalink
Merge pull request #6157 from cmouse/lua
Browse files Browse the repository at this point in the history
Lua2 backend
  • Loading branch information
Habbie committed Mar 8, 2018
2 parents a809f41 + 6f09dd5 commit 0c0c011
Show file tree
Hide file tree
Showing 44 changed files with 1,228 additions and 1 deletion.
5 changes: 4 additions & 1 deletion build-scripts/travis.sh
Expand Up @@ -370,7 +370,7 @@ build_auth() {
run "./bootstrap"
# Build without --enable-botan, no botan 2.x in Travis CI
run "CFLAGS='-O1' CXXFLAGS='-O1' ./configure \
--with-dynmodules='bind gmysql geoip gpgsql gsqlite3 ldap lua mydns opendbx pipe random remote tinydns godbc' \
--with-dynmodules='bind gmysql geoip gpgsql gsqlite3 ldap lua mydns opendbx pipe random remote tinydns godbc lua2' \
--with-modules='' \
--with-sqlite3 \
--enable-libsodium \
Expand Down Expand Up @@ -532,6 +532,9 @@ test_auth() {
run "./timestamp ./start-test-stop 5300 gsqlite3-nsec3-optout-both"
run "./timestamp ./start-test-stop 5300 gsqlite3-nsec3-narrow"

run "./timestamp ./start-test-stop 5300 lua2"
run "./timestamp ./start-test-stop 5300 lua2-dnssec"

run "cd .."

### api ###
Expand Down
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
188 changes: 188 additions & 0 deletions docs/backends/lua2.rst
@@ -0,0 +1,188 @@
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 from original ``Luabackend``, 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)``.

.. warning::
There is no API version 1.
Use Luabackend if you need version 1.

API description (v2)
^^^^^^^^^^^^^^^^^^^^

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

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

INPUT:
- QType qtype - Type of queried resource record
- DNSName qname - Name of queried resource record
- int domain_id - ID of associated domain
- table ctx - Query context table, contains ``source_address`` and ``real_source_address``.

OUTPUT:
Expects a array which has tables with following keys:
- DNSName name - resource record name (can also be string)
- string type - type of resource record (can also be QType or valid integer)
- 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:
Defaults are used for omitted keys.
Return empty array 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 with keys:
- string account - Associated account of this domain (default: <empty>)
- string kind - Domain kind (NATIVE,MASTER,SLAVE) (default: NATIVE)
- int id - Associated domain ID (default: -1)
- int last_check - UNIX timestamp of last check from master (default: 0)
- table of strings masters - Master servers for this domain (default: <empty>)
- long notified_serial - Notified serial to slaves (default: 0)
- long serial - Current domain serial

NOTES:
This function is **optional**.
Defaults are used for omitted keys.
``last_check`` is for automatic serial.
``masters``, ``account``, ``notified_serial`` are for master/slave interaction only.
If this function is missing, it will revert into looking up SOA record for the given domain,
and uses that, if found.

``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**, except if you need master functionality.

``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:
- array 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 with metadata keys containing array 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 array of tables with keys:
- 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:
Table with keys:
- unhashed - DNSName of the unhashed relative to domain
- before - (hashed) name of previous record relative to domain
- after - (hashed) name of next record relative to domain

NOTES:
Strings are promoted to DNSNames (you can also return DNSNames directly)
This function is **required** if ``dns_dnssec`` is true.
Hashing is required with NSEC3/5.
``before`` and ``after`` should wrap, so that after record of last record is apex record.
You can use ``DNSName#canonCompare`` to sort records in correct order.

``dns_set_notified(id, serial)``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Called after NOTIFY so that backend can store the notified serial.

INPUT:
- int id - Associated domain id
- long serial - Notified serial

NOTES:
This function is **optional**. However, not implementing this can cause problems with master functionality.
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 \
lua2api2.hh lua2api2.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 lua2api2.lo
1 change: 1 addition & 0 deletions modules/lua2backend/OBJECTLIBS
@@ -0,0 +1 @@
$(LUA_LIBS)
30 changes: 30 additions & 0 deletions modules/lua2backend/lua2api2.cc
@@ -0,0 +1,30 @@
/*
* 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"

Lua2BackendAPIv2::~Lua2BackendAPIv2() {
if (f_deinit)
f_deinit();
}

0 comments on commit 0c0c011

Please sign in to comment.