Commit 594f6824 authored by Daniel Salzman's avatar Daniel Salzman

Add ZSCANNER (for nsupdate)

refs #2137
parent ff74a195
......@@ -39,6 +39,7 @@ src/unittests
src/unittests-libknot
src/unittests-libknot-realdata
src/unittests-zcompile
src/unittests-zscanner
src/knotc
src/knotd
src/knot-zcompile
......
......@@ -50,6 +50,9 @@ AS_IF([test "x$YACC_BISON" != "xbison"],
[AC_MSG_ERROR([GNU bison needed for reentrant parsers, set the \$YACC variable before running configure])])
AC_PROG_INSTALL
# Check for Ragel
AC_PATH_PROG(RAGEL, ragel)
# Set compiler compatibility flags
AC_PROG_CPP_WERROR
AC_PROG_CC_C99
......
ACLOCAL_AMFLAGS = -I ../m4
libexec_PROGRAMS = knot-zcompile unittests unittests-zcompile unittests-xfr khost knsupdate
libexec_PROGRAMS = knot-zcompile unittests unittests-zcompile unittests-xfr unittests-zscanner khost knsupdate
sbin_PROGRAMS = knotc knotd
dist_man_MANS = knot.conf.5 knotc.8 knotd.8
......@@ -123,7 +123,7 @@ nodist_unittests_SOURCES = \
knotd_SOURCES = \
knot/main.c
noinst_LTLIBRARIES = libknot.la libknotd.la libknots.la
noinst_LTLIBRARIES = libknot.la libknotd.la libknots.la libzscanner.la
libknot_la_SOURCES = \
libknot/util/utils.c \
......@@ -194,6 +194,8 @@ libknots_la_SOURCES = \
common/libtap/tap_unit.h \
common/mempattern.h \
common/mempattern.c \
common/descriptor_new.h \
common/descriptor_new.c \
common/lists.c \
common/base64.c \
common/base64.h \
......@@ -224,22 +226,22 @@ libknots_la_SOURCES = \
common/errors.c \
common/errcode.h \
common/errcode.c \
common/dSFMT.h \
common/dSFMT-params.h \
common/dSFMT-params521.h \
common/dSFMT.c \
common/prng.h \
common/prng.c \
common/fdset.h \
common/fdset.c \
common/fdset_poll.h \
common/fdset_poll.c \
common/fdset_kqueue.h \
common/fdset_kqueue.c \
common/fdset_epoll.h \
common/fdset_epoll.c \
common/dSFMT.h \
common/dSFMT-params.h \
common/dSFMT-params521.h \
common/dSFMT.c \
common/prng.h \
common/prng.c \
common/fdset.h \
common/fdset.c \
common/fdset_poll.h \
common/fdset_poll.c \
common/fdset_kqueue.h \
common/fdset_kqueue.c \
common/fdset_epoll.h \
common/fdset_epoll.c \
common/log.c \
common/log.h
common/log.h
libknotd_la_SOURCES = \
knot/stat/gatherer.c \
......@@ -286,8 +288,27 @@ libknotd_la_SOURCES = \
knot/zone/zone-dump.h \
knot/server/server.h
zscanner/scanner.c: zscanner/scanner.rl zscanner/scanner_body.rl
$(RAGEL) -s -o zscanner/scanner.c zscanner/scanner.rl
unittests_zscanner_SOURCES = \
zscanner/test/zscanner_test.c \
zscanner/test/tests.h \
zscanner/test/tests.c \
zscanner/test/processing.h \
zscanner/test/processing.c
libzscanner_la_SOURCES = \
zscanner/file_loader.h \
zscanner/file_loader.c \
zscanner/scanner.h \
zscanner/scanner.c \
zscanner/scanner_functions.h \
zscanner/scanner_functions.c
libknotd_la_LIBADD = libknot.la libknots.la @LIBOBJS@
libknots_la_LIBADD = @LIBOBJS@
libzscanner_la_LIBADD = libknots.la
knotd_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@
knotc_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@
khost_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@
......@@ -296,6 +317,7 @@ knot_zcompile_LDADD = libknots.la libknot.la libknotd.la @LIBOBJS@
unittests_LDADD = libknotd.la libknots.la @LIBOBJS@
unittests_zcompile_LDADD = libknot.la libknots.la libknotd.la @LIBOBJS@
unittests_xfr_LDADD = libknotd.la libknot.la libknots.la @LIBOBJS@
unittests_zscanner_LDADD = libknots.la libknot.la libknotd.la libzscanner.la @LIBOBJS@
# automake complains on % rules:
# `%'-style pattern rules are a GNU make extension
......
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY 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, see <http://www.gnu.org/licenses/>.
*/
#include "common/descriptor_new.h"
/*!
* \brief RR type descriptors.
*/
static const rdata_descriptor_t rdata_descriptors[] = {
[0] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_A] = { { 4, KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_NS] = { { KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_CNAME] = { { KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_SOA] = { { KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_COMPRESSED_DNAME,
20, KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_PTR] = { { KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_HINFO] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_MINFO] = { { KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_MX] = { { 2, KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_TXT] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_RP] = { { KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_AFSDB] = { { 2, KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_RT] = { { 2, KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_KEY] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_AAAA] = { { 16, KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_LOC] = { { 16, KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_SRV] = { { 6, KNOT_RDATA_WF_UNCOMPRESSED_DNAME,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_NAPTR] = { { KNOT_RDATA_WF_NAPTR_HEADER,
KNOT_RDATA_WF_UNCOMPRESSED_DNAME,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_KX] = { { 2, KNOT_RDATA_WF_COMPRESSED_DNAME,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_CERT] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_DNAME] = { { KNOT_RDATA_WF_UNCOMPRESSED_DNAME,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_OPT] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_APL] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_DS] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_SSHFP] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_IPSECKEY] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_RRSIG] = { { 18, KNOT_RDATA_WF_LITERAL_DNAME,
KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_NSEC] = { { KNOT_RDATA_WF_LITERAL_DNAME,
KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_DNSKEY] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_DHCID] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_NSEC3] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_NSEC3PARAM] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_TLSA] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_SPF] = { { KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
[KNOT_RRTYPE_TSIG] = { { KNOT_RDATA_WF_UNCOMPRESSED_DNAME,
KNOT_RDATA_WF_REMAINDER,
KNOT_RDATA_WF_END } },
};
const rdata_descriptor_t *get_rdata_descriptor(const uint16_t type)
{
if (type <= KNOT_RRTYPE_TSIG) {
return &rdata_descriptors[type];
} else {
return &rdata_descriptors[0];
}
}
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY 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, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file descriptor_new.h
*
* \author Jan Kadlec <jan.kadlec@nic.cz>
*
* @{
*/
#ifndef _KNOT_DESCRIPTOR_NEW_H_
#define _KNOT_DESCRIPTOR_NEW_H_
#include <stdint.h>
#define KNOT_MAX_RDATA_BLOCKS 8
/*!
* \brief Resource record class codes.
*/
enum knot_rr_class {
KNOT_CLASS_IN = 1,
KNOT_CLASS_NONE = 254,
KNOT_CLASS_ANY = 255,
};
/*!
* \brief Resource record type constants.
*/
enum knot_rr_type {
KNOT_RRTYPE_A = 1, /*!< An IPv4 host address. */
KNOT_RRTYPE_NS = 2, /*!< An authoritative name server. */
KNOT_RRTYPE_CNAME = 5, /*!< The canonical name for an alias. */
KNOT_RRTYPE_SOA = 6, /*!< The start of a zone of authority. */
KNOT_RRTYPE_PTR = 12, /*!< A domain name pointer. */
KNOT_RRTYPE_HINFO = 13, /*!< A host information. */
KNOT_RRTYPE_MINFO = 14, /*!< A mailbox information. */
KNOT_RRTYPE_MX = 15, /*!< Mail exchange. */
KNOT_RRTYPE_TXT = 16, /*!< Text strings. */
KNOT_RRTYPE_RP = 17, /*!< For responsible person. */
KNOT_RRTYPE_AFSDB = 18, /*!< For AFS Data Base location. */
KNOT_RRTYPE_RT = 21, /*!< For route through. */
KNOT_RRTYPE_KEY = 25, /*!< For security key. */
KNOT_RRTYPE_AAAA = 28, /*!< IPv6 address. */
KNOT_RRTYPE_LOC = 29, /*!< Location information. */
KNOT_RRTYPE_SRV = 33, /*!< Server selection. */
KNOT_RRTYPE_NAPTR = 35, /*!< Naming authority pointer . */
KNOT_RRTYPE_KX = 36, /*!< Key exchanger. */
KNOT_RRTYPE_CERT = 37, /*!< Certificate record. */
KNOT_RRTYPE_DNAME = 39, /*!< Delegation name. */
KNOT_RRTYPE_OPT = 41, /*!< Option for EDNS*/
KNOT_RRTYPE_APL = 42, /*!< Address prefix list. */
KNOT_RRTYPE_DS = 43, /*!< Delegation signer. */
KNOT_RRTYPE_SSHFP = 44, /*!< SSH public key fingerprint. */
KNOT_RRTYPE_IPSECKEY = 45, /*!< IPSEC key. */
KNOT_RRTYPE_RRSIG = 46, /*!< DNSSEC signature. */
KNOT_RRTYPE_NSEC = 47, /*!< Next-secure record. */
KNOT_RRTYPE_DNSKEY = 48, /*!< DNS key. */
KNOT_RRTYPE_DHCID = 49, /*!< DHCP identifier. */
KNOT_RRTYPE_NSEC3 = 50, /*!< NSEC version 3. */
KNOT_RRTYPE_NSEC3PARAM = 51, /*!< NSEC3 parameters. */
KNOT_RRTYPE_TLSA = 52, /*!< DANE. */
KNOT_RRTYPE_SPF = 99, /*!< Sender policy framework. */
KNOT_RRTYPE_TSIG = 250, /*!< Transaction signature. */
KNOT_RRTYPE_IXFR = 251, /*!< Incremental zone transfer. */
KNOT_RRTYPE_AXFR = 252, /*!< Authoritative zone transfer. */
KNOT_RRTYPE_ANY = 255, /*!< Any record. */
};
/*!
* \brief Constants characterising the wire format of RDATA items.
*/
enum knot_rdata_wireformat {
/*!< Possibly compressed dname. */
KNOT_RDATA_WF_COMPRESSED_DNAME = -10,
/*!< Uncompressed dname. */
KNOT_RDATA_WF_UNCOMPRESSED_DNAME,
/*!< Dname with preserved letter cases. */
KNOT_RDATA_WF_LITERAL_DNAME,
/*!< Initial part of NAPTR record before dname. */
KNOT_RDATA_WF_NAPTR_HEADER,
/*!< Uninteresting final part of a record. */
KNOT_RDATA_WF_REMAINDER,
/*!< The last descriptor in array. */
KNOT_RDATA_WF_END = 0,
};
/*!
* \brief Structure describing rdata.
*/
typedef struct {
int block_types[KNOT_MAX_RDATA_BLOCKS];
} rdata_descriptor_t;
/*!
* \brief Gets rdata descriptor for given RR name.
*
* \param name Mnemonic of RR type whose descriptor should be returned.
*
* \return RR descriptor for given name, NULL descriptor if
* unknown type.
*/
const rdata_descriptor_t *get_rdata_descriptor(const uint16_t type);
#endif // _KNOT_DESCRIPTOR_NEW_H_
/*! @} */
......@@ -69,7 +69,67 @@ const error_table_t knot_error_msgs[] = {
{KNOT_EIXFRSPACE, "IXFR reply did not fit in."},
{KNOT_ECNAME, "CNAME loop found in zone."},
{KNOT_ENODIFF, "Cannot create zone diff."},
{KNOT_EDSDIGESTLEN, "DS digest length does not match digest type." },
{KNOT_EDSDIGESTLEN, "DS digest length does not match digest type."},
{KNOT_ERROR, 0}
/* Zone file loader errors. */
{FLOADER_EFSTAT, "Fstat error!"},
{FLOADER_EDIRECTORY, "Zone file is a directory!"},
{FLOADER_EEMPTY, "Empty zone file!"},
{FLOADER_EDEFAULTS, "Zone defaults processing error!"},
{FLOADER_EMMAP, "Mmap error!"},
{FLOADER_EMUNMAP, "Munmap error!"},
{FLOADER_ESCANNER, "Zone processing error!"},
/* Zone scanner errors. */
{ZSCANNER_UNCOVERED_STATE, "General scanner error!"},
{ZSCANNER_ELEFT_PARENTHESIS, "Too many left parentheses!"},
{ZSCANNER_ERIGHT_PARENTHESIS, "Too many right parentheses!"},
{ZSCANNER_EUNSUPPORTED_TYPE, "Unsupported record type!"},
{ZSCANNER_EBAD_PREVIOUS_OWNER, "Previous owner is invalid!"},
{ZSCANNER_EBAD_DNAME_CHAR, "Bad domain name character!"},
{ZSCANNER_EBAD_OWNER, "Owner is invalid!"},
{ZSCANNER_ELABEL_OVERFLOW, "Maximal domain name label length has exceeded!"},
{ZSCANNER_EDNAME_OVERFLOW, "Maximal domain name length has exceeded!"},
{ZSCANNER_EBAD_NUMBER, "Bad number!"},
{ZSCANNER_ENUMBER64_OVERFLOW, "Number is too big!"},
{ZSCANNER_ENUMBER32_OVERFLOW, "Number is bigger than 32 bits!"},
{ZSCANNER_ENUMBER16_OVERFLOW, "Number is bigger than 16 bits!"},
{ZSCANNER_ENUMBER8_OVERFLOW, "Number is bigger than 8 bits!"},
{ZSCANNER_EFLOAT_OVERFLOW, "Float number overflow!"},
{ZSCANNER_ERDATA_OVERFLOW, "Maximal record data length has exceeded!"},
{ZSCANNER_EITEM_OVERFLOW, "Maximal item length has exceeded!"},
{ZSCANNER_EBAD_ADDRESS_CHAR, "Bad address character!"},
{ZSCANNER_EBAD_IPV4, "Bad IPv4 address!"},
{ZSCANNER_EBAD_IPV6, "Bad IPv6 address!"},
{ZSCANNER_EBAD_GATEWAY, "Bad gateway!"},
{ZSCANNER_EBAD_GATEWAY_KEY, "Bad gateway key!"},
{ZSCANNER_EBAD_APL, "Bad adress prefix list!"},
{ZSCANNER_EBAD_RDATA, "Bad record data!"},
{ZSCANNER_EBAD_HEX_RDATA, "Bad record data in hex format!"},
{ZSCANNER_EBAD_HEX_CHAR, "Bad hexadecimal character!"},
{ZSCANNER_EBAD_BASE64_CHAR, "Bad Base64 character!"},
{ZSCANNER_EBAD_BASE32HEX_CHAR, "Bad Base32hex character!"},
{ZSCANNER_EBAD_REST, "Unexpected data!"},
{ZSCANNER_EBAD_TIMESTAMP_CHAR, "Bad timestamp character!"},
{ZSCANNER_EBAD_TIMESTAMP_LENGTH, "Bad timestamp length!"},
{ZSCANNER_EBAD_TIMESTAMP, "Bad timestamp!"},
{ZSCANNER_EBAD_DATE, "Bad date!"},
{ZSCANNER_EBAD_TIME, "Bad time!"},
{ZSCANNER_EBAD_TIME_UNIT, "Bad time unit!"},
{ZSCANNER_EBAD_BITMAP, "Bad bitmap!"},
{ZSCANNER_ETEXT_OVERFLOW, "Text is too long!"},
{ZSCANNER_EBAD_TEXT_CHAR, "Bad text character!"},
{ZSCANNER_EBAD_TEXT, "Bad text string!"},
{ZSCANNER_EBAD_DIRECTIVE, "Bad directive!"},
{ZSCANNER_EBAD_TTL, "Bad zone TTL!"},
{ZSCANNER_EBAD_ORIGIN, "Bad zone origin!"},
{ZSCANNER_EBAD_INCLUDE_FILENAME, "Bad filename in include directive!"},
{ZSCANNER_EBAD_INCLUDE_ORIGIN, "Bad origin in include directive!"},
{ZSCANNER_EUNPROCESSED_INCLUDE, "Include file processing error!"},
{ZSCANNER_EUNOPENED_INCLUDE, "Include file opening error!"},
{ZSCANNER_EBAD_RDATA_LENGTH, "The rdata length statement is incorrect!"},
{ZSCANNER_ECANNOT_TEXT_DATA, "Unable to process text form for this type!"},
{ZSCANNER_EBAD_HEX_DATA, "Bad hexadecimal rdata format!"},
{ZSCANNER_EBAD_LOC_DATA, "Bad zone location data!"},
{ZSCANNER_EUNKNOWN_BLOCK, "Unknown rdata block!"},
};
......@@ -83,7 +83,69 @@ enum knot_error {
KNOT_EIXFRSPACE, /*!< IXFR reply did not fit in. */
KNOT_ECNAME, /*!< CNAME loop found in zone. */
KNOT_ENODIFF, /*!< No zone diff can be created. */
KNOT_EDSDIGESTLEN /*!< DS digest length does not match digest type. */
KNOT_EDSDIGESTLEN, /*!< DS digest length does not match digest type. */
/* Zone file loader errors. */
FLOADER_EFSTAT,
FLOADER_EDIRECTORY,
FLOADER_EEMPTY,
FLOADER_EDEFAULTS,
FLOADER_EMMAP,
FLOADER_EMUNMAP,
FLOADER_ESCANNER,
/* Zone scanner errors. */
ZSCANNER_UNCOVERED_STATE,
ZSCANNER_ELEFT_PARENTHESIS,
ZSCANNER_ERIGHT_PARENTHESIS,
ZSCANNER_EUNSUPPORTED_TYPE,
ZSCANNER_EBAD_PREVIOUS_OWNER,
ZSCANNER_EBAD_DNAME_CHAR,
ZSCANNER_EBAD_OWNER,
ZSCANNER_ELABEL_OVERFLOW,
ZSCANNER_EDNAME_OVERFLOW,
ZSCANNER_EBAD_NUMBER,
ZSCANNER_ENUMBER64_OVERFLOW,
ZSCANNER_ENUMBER32_OVERFLOW,
ZSCANNER_ENUMBER16_OVERFLOW,
ZSCANNER_ENUMBER8_OVERFLOW,
ZSCANNER_EFLOAT_OVERFLOW,
ZSCANNER_ERDATA_OVERFLOW,
ZSCANNER_EITEM_OVERFLOW,
ZSCANNER_EBAD_ADDRESS_CHAR,
ZSCANNER_EBAD_IPV4,
ZSCANNER_EBAD_IPV6,
ZSCANNER_EBAD_GATEWAY,
ZSCANNER_EBAD_GATEWAY_KEY,
ZSCANNER_EBAD_APL,
ZSCANNER_EBAD_RDATA,
ZSCANNER_EBAD_HEX_RDATA,
ZSCANNER_EBAD_HEX_CHAR,
ZSCANNER_EBAD_BASE64_CHAR,
ZSCANNER_EBAD_BASE32HEX_CHAR,
ZSCANNER_EBAD_REST,
ZSCANNER_EBAD_TIMESTAMP_CHAR,
ZSCANNER_EBAD_TIMESTAMP_LENGTH,
ZSCANNER_EBAD_TIMESTAMP,
ZSCANNER_EBAD_DATE,
ZSCANNER_EBAD_TIME,
ZSCANNER_EBAD_TIME_UNIT,
ZSCANNER_EBAD_BITMAP,
ZSCANNER_ETEXT_OVERFLOW,
ZSCANNER_EBAD_TEXT_CHAR,
ZSCANNER_EBAD_TEXT,
ZSCANNER_EBAD_DIRECTIVE,
ZSCANNER_EBAD_TTL,
ZSCANNER_EBAD_ORIGIN,
ZSCANNER_EBAD_INCLUDE_FILENAME,
ZSCANNER_EBAD_INCLUDE_ORIGIN,
ZSCANNER_EUNPROCESSED_INCLUDE,
ZSCANNER_EUNOPENED_INCLUDE,
ZSCANNER_EBAD_RDATA_LENGTH,
ZSCANNER_ECANNOT_TEXT_DATA,
ZSCANNER_EBAD_HEX_DATA,
ZSCANNER_EBAD_LOC_DATA,
ZSCANNER_EUNKNOWN_BLOCK,
};
/*! \brief Table linking error messages to error codes. */
......
- the newline character is appended to each zone file during processing (for simplicity)
- the class IN is supported only (CLASS12345 notation is not supported too)
- domain names can contain alphanumeric, '-', '_' and '/' characters
- \x and \DDD notations are allowed in domain names and text strings only
- @ can be used instead of domain names anywhere (excluding directives)
- directive $INCLUDE is allowed in included zone files (BEWARE of recursion)
- relative file path is relative to parent zone file
- blank zone file causes error (same rule is for included zone file)
- the line numbers of multiline records are the numbers of the last lines with appropriate record parts
- items parts lengths must be multiples of 2 for HEX, 4 for base64 and 8 for base32hex blocks (but DHCID example from RFC is more general!)
- NSEC3 hash is with padding (but RFC 5155 section 3.3 says "unpadded")
- date version of timestamp in RRSIG is limited to the end of the year 2105 (for better checking of 32bit integer)
- algorithm, certificate and flags (in KEY) mnemonics aren't supported
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY 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, see <http://www.gnu.org/licenses/>.
*/
#include "zscanner/file_loader.h"
#include <inttypes.h> // PRIu64
#include <unistd.h> // sysconf
#include <stdio.h> // sprintf
#include <stdlib.h> // free
#include <stdbool.h> // bool
#include <string.h> // strlen
#include <fcntl.h> // open
#include <sys/stat.h> // fstat
#include <sys/mman.h> // mmap
#include "common/errcode.h" // error codes
/*! \brief Mmap block size in bytes. */
#define BLOCK_SIZE 30000000
/*!
* \brief Processes zone settings block.
*
* Before zone file processing via scanner it's necessary to process first
* settings block using this function. Settings block contains ORIGIN and
* TTL directive.
*
* \param fl File loader structure.
*
* \retval 0 if success.
* \retval -1 if error.
*/
static int load_settings(file_loader_t *fl)
{
int ret;
char *settings_name;
scanner_t *settings_scanner;
// Creating name for zone defaults.
settings_name = malloc(strlen(fl->file_name) + 100);
sprintf(settings_name, "ZONE DEFAULTS <%s>", fl->file_name);
// Temporary scanner for zone settings.
settings_scanner = scanner_create(settings_name);
// Use parent processing functions.
settings_scanner->process_record = fl->scanner->process_record;
settings_scanner->process_error = fl->scanner->process_error;
// Scanning zone settings.
ret = scanner_process(fl->settings_buffer,
fl->settings_buffer + fl->settings_length,
true,
settings_scanner);
// If no error occured, then copy scanned settings to actual context.
if (ret == 0) {
memcpy(fl->scanner->zone_origin,
settings_scanner->zone_origin,
settings_scanner->zone_origin_length);
fl->scanner->zone_origin_length =
settings_scanner->zone_origin_length;
fl->scanner->default_ttl = settings_scanner->default_ttl;
}
// Destroying temporary scanner.
scanner_free(settings_scanner);
free(settings_name);
return ret;
}
file_loader_t* file_loader_create(const char *file_name,