master.c revision 7d32c065c7bb56f281651ae3dd2888f32ce4f1d9
/*
* Copyright (C) 1999, 2000 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.39 2000/02/03 23:43:49 halley Exp $ */
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
#include <isc/assertions.h>
#include <dns/rdatalist.h>
#include <dns/rdataset.h>
#include <dns/rdataclass.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.509's 8K is an overkill
*/
dns_name_t *);
isc_mem_t *);
do { \
switch (result) { \
case DNS_R_SUCCESS: \
break; \
case DNS_R_UNEXPECTED: \
goto cleanup; \
default: \
goto error_cleanup; \
} \
} while (0) \
static inline isc_result_t
{
if (result != ISC_R_SUCCESS) {
switch (result) {
case ISC_R_NOMEMORY:
return (DNS_R_NOMEMORY);
default:
"isc_lex_gettoken() failed: %s",
return (DNS_R_UNEXPECTED);
}
/*NOTREACHED*/
}
"dns_master_load: %s:%d: unexpected end of %s",
"line" : "file");
return (DNS_R_UNEXPECTEDEND);
}
return (DNS_R_SUCCESS);
}
static isc_result_t
{
isc_uint32_t ttl = 0;
isc_uint32_t default_ttl = 0;
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 glue_in_use = -1;
int current_in_use = -1;
int origin_in_use = -1;
int new_in_use;
/*
* Allocate target_size of buffer space. This is greater than twice
* the maximum individual RR data size.
*/
if (target_mem == NULL) {
goto error_cleanup;
}
do {
continue;
}
continue; /* blank line */
}
if (read_till_eol)
continue;
if (!current_known) {
"%s: %s:%d: No current owner name",
"dns_master_load",
goto cleanup;
}
/* 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 =
&ttl);
if (result != DNS_R_SUCCESS)
goto cleanup;
if (ttl > 0x7fffffffUL) {
"dns_master_load: %s:%d: $TTL %lu > MAXTLL, setting TTL to 0",
ttl);
ttl = 0;
}
default_ttl = ttl;
continue;
"$INCLUDE") == 0) {
if (ttl_offset != 0) {
"dns_master_load: %s:%d: $INCLUDE "
"may not be used with $DATE",
goto cleanup;
}
if (include_file != NULL)
if (include_file == NULL) {
goto error_cleanup;
}
result =
top,
mctx);
if (result != DNS_R_SUCCESS)
goto cleanup;
continue;
}
"$DATE") == 0) {
if (result != ISC_R_SUCCESS)
goto error_cleanup;
if (dump_time != dump_time64) {
"dns_master_load: %s:%d: "
"$DATE outside epoch",
goto cleanup;
}
if (dump_time > current_time) {
"dns_master_load: %s:%d: "
"$DATE in future, using current date",
}
continue;
"$", 1) == 0) {
"dns_master_load: %s %d "
"UNKOWN $<DIRECTIVE> %s ",
goto cleanup;
}
/*
* Normal processing resumes.
*
* Find a free name buffer.
*/
if (!name_in_use[new_in_use])
break;
if (result != DNS_R_SUCCESS)
goto error_cleanup;
/*
* Finish $ORIGIN / $INCLUDE processing if required.
*/
if (finish_origin) {
if (origin_in_use != -1)
continue;
}
if (finish_include) {
top,
&new_name,
mctx);
if (result != DNS_R_SUCCESS)
goto 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().
*/
&new_name) != 0) {
&glue_name);
if (result != DNS_R_SUCCESS)
goto cleanup;
if (glue_in_use != -1)
glue_in_use = -1;
}
/*
* 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 (!in_glue && (!current_known ||
if (current_has_delegation &&
} else {
¤t_name);
if (result != DNS_R_SUCCESS)
goto cleanup;
rdcount = 0;
rdlcount = 0;
if (current_in_use != -1)
= ISC_FALSE;
}
}
} else {
"%s:%d: isc_lex_gettoken() returned unexpeced token type (%d)",
goto 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;
== DNS_R_SUCCESS)
== DNS_R_SUCCESS) {
if (ttl > 0x7fffffffUL) {
"dns_master_load: %s:%d: TTL %lu > maxtll, setting ttl to 0",
ttl);
ttl = 0;
}
} else if (!ttl_known && !default_ttl_known) {
/*
* BIND 4 / 8 'USE_SOA_MINIMUM' could be set here.
*/
"%s: %s:%d: no TTL specified",
"dns_master_load",
goto cleanup;
} else if (default_ttl_known) {
ttl = default_ttl;
} else if (warn_1035) {
"%s: %s:%d: using RFC 1035 TTL semantics",
"dns_master_load",
}
"isc_lex_gettoken() returned unexpected token type");
goto cleanup;
}
if (rdclass == 0 &&
== DNS_R_SUCCESS)
"isc_lex_gettoken() returned unexpected token type");
goto cleanup;
}
if (result != DNS_R_SUCCESS)
goto cleanup;
/*
* If the class specified does not match the zone's class
* print out a error message and exit.
*/
char buf1[32];
char buf2[32];
if (result != DNS_R_SUCCESS) {
"dns_rdataclass_totext() failed: %s",
goto cleanup;
}
if (result != DNS_R_SUCCESS) {
"dns_rdataclass_totext() failed: %s",
goto cleanup;
}
"%s: %s:%d: class (%.*s) != zone class (%.*s)",
"dns_master_load",
goto cleanup;
}
if (age_ttl) {
/*
* 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).
*/
if (ttl < ttl_offset) {
continue;
}
ttl -= ttl_offset;
}
/*
* Find a rdata structure.
*/
if (rdcount == rdata_size) {
goto error_cleanup;
}
rdata_size += RDSZ;
}
/*
* Read rdata contents.
*/
if (result != DNS_R_SUCCESS)
goto 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.
*/
if (in_glue)
else
break;
}
if (rdlcount == rdatalist_size) {
mctx);
if (new_rdatalist == NULL) {
goto error_cleanup;
}
rdatalist_size += RDLSZ;
}
if (in_glue)
else
"%s: %s:%d: TTL set to prior TTL (%lu)",
"dns_master_load",
}
/*
* If the new rdata is not on the list add it.
*
* If the new rdata is on the list do not worry about
* recovering the space it is using in target as it will be
* recovered when we next call commit. The worst that can
* happen is that we make a few extra calls to commit.
*/
rdcount++;
}
/*
* We must have at least 64k as rdlen is 16 bits.
* If we don't commit everything we have so far.
*/
¤t_name);
if (result != DNS_R_SUCCESS)
goto cleanup;
if (result != DNS_R_SUCCESS)
goto cleanup;
rdcount = 0;
rdlcount = 0;
if (glue_in_use != -1)
glue_in_use = -1;
}
} while (!done);
/*
* Commit what has not yet been committed.
*/
if (result != DNS_R_SUCCESS)
goto cleanup;
if (result != DNS_R_SUCCESS)
goto cleanup;
else
goto cleanup;
}
rdatalist_size * sizeof *rdatalist);
if (target_mem != NULL)
if (include_file != NULL)
return (result);
}
{
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS) {
return (result);
}
}
{
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS) {
return (result);
}
}
{
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS) {
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
{
&dataset));
if (result != DNS_R_SUCCESS)
return (result);
}
return (DNS_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);
}
/*
* Returns ISC_TRUE if the 'rdata' is already on 'rdatalist'.
*/
static isc_boolean_t
return (ISC_TRUE);
}
return (ISC_FALSE);
}