master.c revision 8e68489885e744ab48907414b4199c36858c27dd
/*
* Copyright (C) 1999-2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: master.c,v 1.104 2001/02/01 21:29:40 marka Exp $ */
#include <config.h>
#include <dns/callbacks.h>
#include <dns/fixedname.h>
#include <dns/rdataclass.h>
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#include <dns/rdatatype.h>
/*
* Grow the number of dns_rdatalist_t (RDLSZ) and dns_rdata_t (RDSZ) structures
* by these sizes when we need to.
*
* RDLSZ reflects the number of different types with the same name expected.
* RDSZ reflects the number of rdata expected at a give name that can fit into
* 64k.
*/
#define RDLSZ 32
#define RDSZ 512
#define NBUFS 4
#define MAXWIRESZ 255
/*
* Target buffer size and minimum target size.
* MINTSIZ must be big enough to hold the largest rdata record.
*
* TSIZ >= MINTSIZ
*/
/*
* max message size - header - root - type - class - ttl - rdlen
*/
/*
* Size for tokens in the presentation format,
* The largest tokens are the base64 blocks in KEY and CERT records,
* Largest key allowed is about 1372 bytes but
* there is no fixed upper bound on CERT records.
* 2K is too small for some X.509s, 8K is overkill.
*/
#define DNS_MASTER_BUFSZ 2048
/*
* Master file load state.
*/
struct dns_loadctx {
void *done_arg;
unsigned int options;
/* Which fixed buffers we are using? */
int glue_in_use;
int current_in_use;
int origin_in_use;
unsigned int loop_cnt; /* records per quantum,
* 0 => all. */
/* locked by lock */
};
static isc_result_t
static isc_result_t
dns_name_t *);
static isc_boolean_t
static dns_rdatalist_t *
static dns_rdata_t *
isc_mem_t *);
static void
static isc_result_t
static void
do { \
switch (result) { \
case ISC_R_SUCCESS: \
break; \
case ISC_R_UNEXPECTED: \
goto insist_and_cleanup; \
default: \
read_till_eol = ISC_TRUE; \
goto next_line; \
} else \
goto log_and_cleanup; \
} \
result = DNS_R_SYNTAX; \
read_till_eol = ISC_TRUE; \
goto next_line; \
} else \
goto log_and_cleanup; \
} \
} while (0)
#define COMMITALL \
do { \
} else if (result != ISC_R_SUCCESS) \
goto log_and_cleanup; \
} else if (result != ISC_R_SUCCESS) \
goto log_and_cleanup; \
rdcount = 0; \
rdlcount = 0; \
rdcount_save = rdcount; \
rdlcount_save = rdlcount; \
} while (0)
#define WARNUNEXPECTEDEOF(lexer) \
do { \
if (isc_lex_isfile(lexer)) \
"%s:%lu: file does not end with newline", \
} while (0)
((result != ISC_R_SUCCESS) && \
do { \
} while (0)
if (result == ISC_R_NOMEMORY) \
dns_result_totext(result)); \
else \
"dns_master_load", \
static inline isc_result_t
{
if (result != ISC_R_SUCCESS) {
switch (result) {
case ISC_R_NOMEMORY:
return (ISC_R_NOMEMORY);
default:
"dns_master_load: %s:%lu:"
" isc_lex_gettoken() failed: %s",
return (result);
}
/*NOTREACHED*/
}
"dns_master_load: %s:%lu: unexpected end of %s",
"line" : "file");
return (ISC_R_UNEXPECTEDEND);
}
return (ISC_R_SUCCESS);
}
void
source->references++;
}
void
ctx->references--;
if (ctx->references == 0)
if (need_destroy)
}
static void
}
}
static isc_result_t
{
isc_region_t r;
int i;
return (ISC_R_NOMEMORY);
if (result != ISC_R_SUCCESS) {
"isc_mutex_init() failed: %s",
return (ISC_R_UNEXPECTED);
}
if (result != ISC_R_SUCCESS)
goto cleanup_ctx;
ctx->default_ttl = 0;
dns_name_toregion(top, &r);
for (i = 0; i < NBUFS; i++) {
}
ctx->origin_in_use = 0;
dns_name_toregion(origin, &r);
return (ISC_R_SUCCESS);
return (result);
}
static isc_result_t
char fmt[sizeof("%04000000000d")];
char numbuf[128];
char *cp;
char mode[2];
int delta = 0;
unsigned int n;
unsigned int width;
while (*name != '\0') {
if (*name == '$') {
name++;
if (*name == '$') {
if (r.length == 0)
return (ISC_R_NOSPACE);
isc_textregion_consume(&r, 1);
continue;
}
/* Get format specifier. */
if (*name == '{' ) {
switch (n) {
case 1:
break;
case 2:
"%%0%ud", width);
break;
case 3:
break;
default:
return (DNS_R_SYNTAX);
}
if (n >= sizeof(fmt))
return (ISC_R_NOSPACE);
/* Skip past closing brace. */
continue;
}
if (n >= sizeof(numbuf))
return (ISC_R_NOSPACE);
while (*cp != '\0') {
if (r.length == 0)
return (ISC_R_NOSPACE);
isc_textregion_consume(&r, 1);
}
} else if (*name == '\\') {
if (r.length == 0)
return (ISC_R_NOSPACE);
isc_textregion_consume(&r, 1);
if (*name == '\0')
continue;
if (r.length == 0)
return (ISC_R_NOSPACE);
isc_textregion_consume(&r, 1);
} else {
if (r.length == 0)
return (ISC_R_NOSPACE);
isc_textregion_consume(&r, 1);
}
}
if (r.length == 0)
return (ISC_R_NOSPACE);
r.base[0] = '\0';
return (ISC_R_SUCCESS);
}
static isc_result_t
char *target_mem = NULL;
int n;
goto error_cleanup;
}
"%s: %s:%lu: invalid range '%s'",
"$GENERATE",
range);
goto insist_cleanup;
}
if (n == 2)
step = 1;
/*
* Get type.
*/
if (result != ISC_R_SUCCESS) {
"%s: %s:%lu: unknown RR type '%s'",
"$GENERATE",
gtype);
goto insist_cleanup;
}
switch (type) {
case dns_rdatatype_ns:
case dns_rdatatype_ptr:
case dns_rdatatype_cname:
case dns_rdatatype_dname:
break;
case dns_rdatatype_a:
case dns_rdatatype_aaaa:
break;
/* FALLTHROUGH */
default:
"%s: %s:%lu: unsupported type '%s'",
"$GENERATE",
gtype);
goto error_cleanup;
}
if (result != ISC_R_SUCCESS)
goto error_cleanup;
if (result != ISC_R_SUCCESS)
goto error_cleanup;
if (result != ISC_R_SUCCESS)
goto error_cleanup;
if (result != ISC_R_SUCCESS)
goto error_cleanup;
if (result != ISC_R_SUCCESS)
goto error_cleanup;
if (result != ISC_R_SUCCESS)
goto error_cleanup;
}
goto cleanup;
if (result == ISC_R_NOMEMORY)
else
if (target_mem != NULL)
return (result);
}
static isc_result_t
isc_uint32_t ttl_offset = 0;
char *include_file = NULL;
int rdlcount = 0;
int rdlcount_save = 0;
int rdatalist_size = 0;
int rdcount = 0;
int rdcount_save = 0;
int rdata_size = 0;
unsigned char *target_mem = NULL;
int target_size = TSIZ;
int new_in_use;
unsigned int loop_cnt = 0;
/*
* Allocate target_size of buffer space. This is greater than twice
* the maximum individual RR data size.
*/
if (target_mem == NULL) {
goto log_and_cleanup;
}
do {
if (read_till_eol)
/* Pop the include stack? */
continue;
}
continue;
}
continue; /* blank line */
}
if (read_till_eol)
continue;
/*
* Still working on the same name.
*/
/*
* "$" Support.
*
* "$ORIGIN" and "$INCLUDE" can both take domain names.
* The processing of "$ORIGIN" and "$INCLUDE" extends
* across the normal domain name processing.
*/
"$ORIGIN") == 0) {
"$TTL") == 0) {
result =
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
"%s: %s:%lu: "
"$TTL %lu > MAXTTL, "
"setting $TTL to 0",
"dns_master_load",
}
continue;
"$INCLUDE") == 0) {
"%s: %s:%lu: $INCLUDE not allowed",
"dns_master_load",
goto insist_and_cleanup;
}
if (ttl_offset != 0) {
"%s: %s:%lu: $INCLUDE "
"may not be used with $DATE",
"dns_master_load",
goto insist_and_cleanup;
}
if (include_file != NULL)
if (include_file == NULL) {
goto log_and_cleanup;
}
/*
* No origin field.
*/
ctxp);
continue;
} else if (result != ISC_R_SUCCESS)
goto log_and_cleanup;
continue;
}
/*
* There is an origin field. Fall through
* to domain name processing code and do
* the actual inclusion later.
*/
"$DATE") == 0) {
dump_time64 = 0;
} else if (result != ISC_R_SUCCESS)
goto log_and_cleanup;
if (dump_time != dump_time64) {
"%s: %s:%lu: "
"$DATE outside epoch",
"dns_master_load",
goto insist_and_cleanup;
}
if (dump_time > current_time) {
"%s: %s:%lu: "
"$DATE in future, using current date",
"dns_master_load",
}
continue;
"$GENERATE") == 0) {
/*
* Use default ttl if known otherwise
* inherit or error.
*/
!ctx->default_ttl_known) {
"%s: %s:%lu: no TTL specified",
"dns_master_load",
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
} else if (ctx->default_ttl_known) {
}
/*
* Lazy cleanup.
*/
/* range */
goto log_and_cleanup;
}
/* LHS */
goto log_and_cleanup;
}
/* TYPE */
goto log_and_cleanup;
}
/* RHS */
goto log_and_cleanup;
}
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
continue;
"$", 1) == 0) {
"%s: %s:%lu: "
"unknown $ directive '%s'",
"dns_master_load",
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
}
/*
* Normal processing resumes.
*
* Find a free name buffer.
*/
break;
continue;
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
/*
* Finish $ORIGIN / $INCLUDE processing if required.
*/
if (finish_origin) {
continue;
}
if (finish_include) {
continue;
} else if (result != ISC_R_SUCCESS)
goto log_and_cleanup;
continue;
}
/*
* "$" Processing Finished
*/
/*
* If we are processing glue and the new name does
* not match the current glue name, commit the glue
* and pop stacks leaving us in 'normal' processing
* state. Linked lists are undone by commit().
*/
} else if (result != ISC_R_SUCCESS)
goto log_and_cleanup;
}
/*
* If we are in 'normal' processing state and the new
* name does not match the current name, see if the
* new name is for glue and treat it as such,
* otherwise we have a new name so commit what we
* have.
*/
if (current_has_delegation &&
} else {
} else if (result != ISC_R_SUCCESS)
goto log_and_cleanup;
rdcount = 0;
rdlcount = 0;
}
}
} else {
"%s:%lu: isc_lex_gettoken() returned "
"unexpeced token type (%d)",
continue;
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
}
/*
* Find TTL, class and type. Both TTL and class are optional
* and may occur in any order if they exist. TTL and class
* come before type which must exist.
*
* [<TTL>] [<class>] <type> <RDATA>
* [<class>] [<TTL>] <type> <RDATA>
*/
type = 0;
rdclass = 0;
if (initialws) {
continue; /* blank line */
}
continue;
}
"%s: %s:%lu: No current owner name",
"dns_master_load",
continue;
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
}
}
== ISC_R_SUCCESS)
== ISC_R_SUCCESS) {
"%s: %s:%lu: "
"TTL %lu > MAXTTL, "
"setting TTL to 0",
"dns_master_load",
}
/*
* BIND 4 / 8 'USE_SOA_MINIMUM' could be set here.
*/
"%s: %s:%lu: no TTL specified",
"dns_master_load",
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
} else if (ctx->default_ttl_known) {
"%s: %s:%lu: "
"using RFC 1035 TTL semantics",
"dns_master_load",
}
"isc_lex_gettoken() returned unexpected token type");
continue;
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
}
if (rdclass == 0 &&
== ISC_R_SUCCESS)
"isc_lex_gettoken() returned unexpected token type");
continue;
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
}
if (result != ISC_R_SUCCESS) {
"%s: %s:%lu: unknown RR type '%.*s'",
"dns_master_load",
continue;
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
}
/*
* If the class specified does not match the zone's class
* print out a error message and exit.
*/
sizeof(classname1));
sizeof(classname2));
"%s: %s:%lu: class '%s' != "
"zone class '%s'",
"dns_master_load",
continue;
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
}
/*
* Adjust the TTL for $DATE. If the RR has already
* expired, ignore it without even parsing the rdata
* part (good for performance, bad for catching
* syntax errors).
*/
continue;
}
}
/*
* Find a rdata structure.
*/
if (rdcount == rdata_size) {
goto log_and_cleanup;
}
rdata_size += RDSZ;
}
/*
* Read rdata contents.
*/
continue;
} else if (result != ISC_R_SUCCESS)
goto insist_and_cleanup;
if (type == dns_rdatatype_sig)
else
covers = 0;
/*
* Find type in rdatalist.
* If it does not exist create new one and prepend to list
* as this will mimimise list traversal.
*/
else
break;
}
if (rdlcount == rdatalist_size) {
mctx);
if (new_rdatalist == NULL) {
goto log_and_cleanup;
}
rdatalist_size += RDLSZ;
}
else
link);
"%s: %s:%lu: "
"TTL set to prior TTL (%lu)",
"dns_master_load",
}
rdcount++;
/*
* We must have at least 64k as rdlen is 16 bits.
* If we don't commit everything we have so far.
*/
;
/*
* Commit what has not yet been committed.
*/
} else if (result != ISC_R_SUCCESS)
goto log_and_cleanup;
} else if (result != ISC_R_SUCCESS)
goto log_and_cleanup;
if (!done) {
goto cleanup;
rdatalist_size * sizeof *rdatalist);
if (target_mem != NULL)
if (include_file != NULL)
return (result);
}
static isc_result_t
isc_region_t r;
int new_in_use;
&new);
if (result != ISC_R_SUCCESS)
return (result);
/* Set current domain. */
break;
}
if (result != ISC_R_SUCCESS)
goto cleanup;
return (ISC_R_SUCCESS);
return (result);
}
{
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
goto cleanup;
return (result);
}
{
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result == ISC_R_SUCCESS) {
return (DNS_R_CONTINUE);
}
return (result);
}
{
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS)
goto cleanup;
return (result);
}
{
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result == ISC_R_SUCCESS) {
return (DNS_R_CONTINUE);
}
return (result);
}
unsigned int options,
{
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
goto cleanup;
return (result);
}
unsigned int options,
{
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
goto cleanup;
if (result == ISC_R_SUCCESS) {
return (DNS_R_CONTINUE);
}
return (result);
}
/*
* Grow the slab of dns_rdatalist_t structures.
* Re-link glue and current list.
*/
static dns_rdatalist_t *
{
int rdlcount = 0;
return (NULL);
}
rdlcount++;
}
}
rdlcount++;
}
return (new);
}
/*
* Grow the slab of rdata structs.
* Re-link the current and glue chains.
*/
static dns_rdata_t *
{
int rdcount = 0;
return (NULL);
/*
* Copy current relinking.
*/
}
rdcount++;
}
}
/*
* Copy glue relinking.
*/
}
rdcount++;
}
}
return (new);
}
/*
* Convert each element from a rdatalist_t to rdataset then call commit.
* Unlink each element as we go.
*/
static isc_result_t
{
return (ISC_R_SUCCESS);
/*
* Ignore out-of-zone data.
*/
"%s: %s:%lu: "
"ignoring out-of-zone data",
"dns_master_load",
}
do {
if (!ignore) {
&dataset));
if (result != ISC_R_SUCCESS)
return (result);
}
return (ISC_R_SUCCESS);
}
/*
* Returns ISC_TRUE if one of the NS rdata's contains 'owner'.
*/
static isc_boolean_t
/*
* Find NS rrset.
*/
break;
}
return (ISC_FALSE);
return (ISC_TRUE);
}
return (ISC_FALSE);
}
static void
else
if (result == DNS_R_CONTINUE) {
} else {
}
}
static isc_result_t
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
}
void
}