rdata.c revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Copyright (C) 1998-2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id$ */
/*! \file */
#include <config.h>
#include <ctype.h>
#include <isc/parseint.h>
#include <dns/callbacks.h>
#include <dns/compress.h>
#include <dns/dsdigest.h>
#include <dns/enumtype.h>
#include <dns/keyflags.h>
#include <dns/keyvalues.h>
#include <dns/rdataclass.h>
#include <dns/rdatastruct.h>
#include <dns/rdatatype.h>
#include <dns/secproto.h>
#define RETERR(x) \
do { \
isc_result_t _r = (x); \
if (_r != ISC_R_SUCCESS) \
return (_r); \
} while (0)
#define RETTOK(x) \
do { \
isc_result_t _r = (x); \
if (_r != ISC_R_SUCCESS) { \
return (_r); \
} \
} while (0)
#define ARGS_FREESTRUCT void *source
void *arg
/*%
* Context structure for the totext_ functions.
* Contains formatting options for rdata-to-text
* conversion.
*/
typedef struct dns_rdata_textctx {
unsigned int flags; /*%< DNS_STYLEFLAG_* */
unsigned int width; /*%< Width of rdata column. */
const char *linebreak; /*%< Line break string. */
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_boolean_t
static unsigned int
static isc_result_t
static isc_result_t
static isc_boolean_t
static void
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_uint32_t
static isc_uint16_t
static isc_uint8_t
static isc_uint8_t
static isc_result_t
static int
static int
static isc_result_t
static isc_result_t
static void
static void
static void
static isc_result_t
static void
static void
static isc_uint16_t
static isc_result_t
static inline isc_result_t
static inline isc_result_t
static inline isc_result_t
static inline isc_result_t
static inline isc_result_t
static inline void
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static void
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static isc_result_t
static void
/*% INT16 Size */
#define NS_INT16SZ 2
/*% IPv6 Address Size */
#define NS_LOCATORSZ 8
/*
* Active Diretory gc._msdcs.<forest> prefix.
*/
static unsigned char gc_msdcs_data[] = "\002gc\006_msdcs";
static unsigned char gc_msdcs_offset [] = { 0, 3 };
static const dns_name_t gc_msdcs = {
{(void *)-1, (void *)-1},
};
/*%
* convert presentation level address to network order binary form.
* \return
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
* \note
* (1) does not touch `dst' unless it's returning 1.
*/
static inline int
static const char xdigits_l[] = "0123456789abcdef",
xdigits_u[] = "0123456789ABCDEF";
unsigned char tmp[NS_LOCATORSZ];
const char *xdigits;
int ch, seen_xdigits;
unsigned int val;
seen_xdigits = 0;
val = 0;
const char *pch;
val <<= 4;
if (++seen_xdigits > 4)
return (0);
continue;
}
if (ch == ':') {
if (!seen_xdigits)
return (0);
return (0);
seen_xdigits = 0;
val = 0;
continue;
}
return (0);
}
if (seen_xdigits) {
return (0);
}
return (0);
return (1);
}
static inline int
{
int result;
name = "UNKNOWN";
"is not a decimal dotted quad", name,
}
return (result);
}
static inline isc_result_t
return (ISC_R_SUCCESS);
}
static inline void *
void *copy;
return (source);
return (copy);
}
static inline isc_result_t
{
int octet;
int window;
max_used = 0;
bm[0] = 0;
end = 0;
do {
break;
}
}
} while (1);
if (!allow_empty && first)
return (DNS_R_FORMERR);
break;
if (max_octet >= 256)
max_octet = 31;
else
max_octet /= 8;
/*
* Find if we have a type in this window.
*/
break;
}
if (octet < 0)
continue;
}
return (ISC_R_SUCCESS);
}
static inline isc_result_t
{
unsigned int i, j, k;
}
i += 2;
for (j = 0; j < len; j++) {
continue;
for (k = 0; k < 8; k++) {
continue;
if (!first)
if (dns_rdatatype_isknown(t)) {
} else {
char buf[sizeof("TYPE65535")];
}
}
}
}
return (ISC_R_SUCCESS);
}
static isc_result_t
unsigned int window, lastwindow = 0;
unsigned int len;
unsigned int i;
/*
* Check for overflow.
*/
i += 2;
/*
* Check that bitmap windows are in the correct order.
*/
/*
* Check for legal lengths.
*/
/*
* Check for overflow.
*/
/*
* The last octet of the bitmap must be non zero.
*/
lastwindow = window;
}
return (DNS_R_EXTRADATA);
if (!allow_empty && first)
return (ISC_R_SUCCESS);
}
static const char hexdigits[] = "0123456789abcdef";
static const char decdigits[] = "0123456789";
#include "code.h"
#define META 0x0001
#define RESERVED 0x0002
/***
*** Initialization
***/
void
/* ISC_LIST_INIT(rdata->list); */
}
void
}
/***
***
***/
void
}
/***
*** Comparisons
***/
int
int result = 0;
if (use_default) {
}
return (result);
}
int
int result = 0;
if (use_default) {
}
return (result);
}
/***
*** Conversions
***/
void
{
}
void
}
{
unsigned int length;
}
if (type == 0)
return (DNS_R_FORMERR);
if (use_default) {
else {
}
}
/*
* Reject any rdata that expands out to more than DNS_RDATA_MAXLENGTH
* as we cannot transmit it.
*/
/*
* We should have consumed all of our buffer.
*/
}
if (result != ISC_R_SUCCESS) {
}
return (result);
}
{
/*
* Some DynDNS meta-RRs have empty rdata.
*/
return (ISC_R_SUCCESS);
}
if (use_default) {
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
if (result != ISC_R_SUCCESS) {
}
return (result);
}
/*
* If the binary data in 'src' is valid uncompressed wire format
* rdata of class 'rdclass' and type 'type', return ISC_R_SUCCESS
* and copy the validated rdata to 'dest'. Otherwise return an error.
*/
static isc_result_t
{
return (result);
}
static isc_result_t
{
return (DNS_R_METATYPE);
ISC_FALSE));
return (ISC_R_RANGE);
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
goto failure;
goto failure;
}
if (dns_rdatatype_isknown(type)) {
} else {
isc_region_t r;
isc_buffer_usedregion(buf, &r);
}
if (result != ISC_R_SUCCESS)
goto failure;
return (ISC_R_SUCCESS);
return (result);
}
{
char *name;
unsigned long line;
void (*callback)(dns_rdatacallbacks_t *, const char *, ...);
unsigned int length;
}
}
else
if (result != ISC_R_SUCCESS) {
return (result);
}
/*
* If this is a TXT record '\#' could be a escaped '#'.
* Look to see if the next token is a number and if so
* treat it as a unknown record format.
*/
if (type == dns_rdatatype_txt) {
if (result == ISC_R_SUCCESS)
}
if (result == ISC_R_SUCCESS) {
} else
} else
if (!unknown)
/*
* Consume to end of line / file.
* If not at end of line initially set error code.
* Call callback via fromtext_error once if there was an error.
*/
do {
if (tresult != ISC_R_SUCCESS) {
if (result == ISC_R_SUCCESS)
break;
if (result == ISC_R_SUCCESS)
}
break;
} else {
break;
}
} while (1);
}
if (result != ISC_R_SUCCESS) {
}
return (result);
}
static isc_result_t
{
char buf[sizeof("65535")];
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
return (result);
else
if (result != ISC_R_SUCCESS)
return (result);
else
target);
if (result == ISC_R_SUCCESS &&
}
return (result);
}
static isc_result_t
{
unsigned int cur;
/*
* Some DynDNS meta-RRs have empty rdata.
*/
return (ISC_R_SUCCESS);
}
unsigned int u = isc_buffer_usedlength(target);
}
return (result);
}
{
/*
* Set up formatting options for single-line output.
*/
}
unsigned int split_width, const char *linebreak,
{
/*
* Set up formatting options for formatted output.
*/
if (split_width == 0xffffffff)
else
if ((flags & DNS_STYLEFLAG_MULTILINE) != 0)
else {
if (split_width == 0xffffffff)
}
}
{
unsigned int length;
}
if (use_default)
(void)NULL;
}
if (result != ISC_R_SUCCESS)
return (result);
}
if (use_default)
(void)NULL;
return (result);
}
void
dns_rdata_freestruct(void *source) {
}
void *arg)
{
/*
* Call 'add' for each name and type from 'rdata' which is subject to
* additional section processing.
*/
/* No additional processing for unknown types */
if (use_default)
return (result);
}
isc_region_t r;
/*
* Send 'rdata' in DNSSEC canonical form to 'digest'.
*/
if (use_default) {
dns_rdata_toregion(rdata, &r);
}
return (result);
}
{
return (result);
}
{
return (result);
}
unsigned int
{
return (DNS_RDATATYPEATTR_UNKNOWN | DNS_RDATATYPEATTR_META);
return (DNS_RDATATYPEATTR_UNKNOWN);
}
unsigned int hash;
unsigned int n;
unsigned char a, b;
if (n == 0)
return (DNS_R_UNKNOWN);
hash = ((a + n) * b) % 256;
/*
* This switch block is inlined via \#define, and will use "return"
* to return a result to the caller if it is a valid (known)
* rdatatype name.
*/
char buf[sizeof("65000")];
char *endp;
unsigned int val;
return (ISC_R_SUCCESS);
}
}
return (DNS_R_UNKNOWN);
}
}
char buf[sizeof("TYPE65535")];
}
void
{
if (size == 0U)
return;
/*
* Null terminate.
*/
if (result == ISC_R_SUCCESS) {
isc_buffer_putuint8(&buf, 0);
else
}
if (result != ISC_R_SUCCESS)
}
/*
* Private function.
*/
static unsigned int
}
static isc_result_t
unsigned int tl;
unsigned int n;
unsigned char *sp;
char *tp;
n = *sp++;
if (n == 0U)
if (quote) {
if (tl < 1)
return (ISC_R_NOSPACE);
*tp++ = '"';
tl--;
}
while (n--) {
/*
* \DDD space (0x20) if not quoting.
*/
if (tl < 4)
return (ISC_R_NOSPACE);
*tp++ = 0x5c;
sp++;
tl -= 4;
continue;
}
/*
* Escape double quote and backslash. If we are not
* enclosing the string in double quotes also escape
* at sign and semicolon.
*/
if (tl < 2)
return (ISC_R_NOSPACE);
*tp++ = '\\';
tl--;
}
if (tl < 1)
return (ISC_R_NOSPACE);
tl--;
}
if (quote) {
if (tl < 1)
return (ISC_R_NOSPACE);
*tp++ = '"';
tl--;
}
return (ISC_R_SUCCESS);
}
static isc_result_t
unsigned int n, nrem;
char *s;
unsigned char *t;
int d;
int c;
if (nrem < 1)
return (ISC_R_NOSPACE);
/*
* Length byte.
*/
nrem--;
t++;
/*
* Maximum text string length.
*/
if (nrem > 255)
nrem = 255;
while (n-- != 0) {
c = (*s++) & 0xff;
c = d;
if (n == 0)
return (DNS_R_SYNTAX);
n--;
if ((d = decvalue(*s++)) != -1)
c = c * 10 + d;
else
return (DNS_R_SYNTAX);
if (n == 0)
return (DNS_R_SYNTAX);
n--;
if ((d = decvalue(*s++)) != -1)
c = c * 10 + d;
else
return (DNS_R_SYNTAX);
if (c > 255)
return (DNS_R_SYNTAX);
} else if (!escape && c == '\\') {
continue;
}
if (nrem == 0)
*t++ = c;
nrem--;
}
if (escape)
return (DNS_R_SYNTAX);
return (ISC_R_SUCCESS);
}
static isc_result_t
unsigned int n;
return (ISC_R_UNEXPECTEDEND);
return (ISC_R_UNEXPECTEDEND);
return (ISC_R_NOSPACE);
isc_buffer_forward(source, n);
isc_buffer_add(target, n);
return (ISC_R_SUCCESS);
}
/*
* Conversion of TXT-like rdata fields without length limits.
*/
static isc_result_t
unsigned int tl;
unsigned int n0, n;
unsigned char *sp;
char *tp;
if (tl < 1)
return (ISC_R_NOSPACE);
*tp++ = '"';
tl--;
do {
while (n--) {
if (tl < 4)
return (ISC_R_NOSPACE);
*tp++ = 0x5c;
sp++;
tl -= 4;
continue;
}
/* double quote, semi-colon, backslash */
if (tl < 2)
return (ISC_R_NOSPACE);
*tp++ = '\\';
tl--;
}
if (tl < 1)
return (ISC_R_NOSPACE);
tl--;
}
if (tl < 1)
return (ISC_R_NOSPACE);
*tp++ = '"';
tl--;
return (ISC_R_SUCCESS);
}
static isc_result_t
unsigned int n, nrem;
char *s;
unsigned char *t0, *t;
int d;
int c;
do {
if (nrem < 1)
return (ISC_R_NOSPACE);
while (n != 0) {
--n;
c = (*s++) & 0xff;
c = d;
if (n == 0)
return (DNS_R_SYNTAX);
n--;
if ((d = decvalue(*s++)) != -1)
c = c * 10 + d;
else
return (DNS_R_SYNTAX);
if (n == 0)
return (DNS_R_SYNTAX);
n--;
if ((d = decvalue(*s++)) != -1)
c = c * 10 + d;
else
return (DNS_R_SYNTAX);
if (c > 255)
return (DNS_R_SYNTAX);
} else if (!escape && c == '\\') {
continue;
}
*t++ = c;
nrem--;
if (nrem == 0)
break;
}
if (escape)
return (DNS_R_SYNTAX);
} while (n != 0);
return (ISC_R_SUCCESS);
}
static isc_boolean_t
goto return_false;
goto return_false;
goto return_false;
goto return_false;
/* Master files should be case preserving. */
goto return_false;
return (ISC_TRUE);
return (ISC_FALSE);
}
static isc_result_t
unsigned int l;
return (ISC_R_NOSPACE);
isc_buffer_add(target, l);
return (ISC_R_SUCCESS);
}
static isc_result_t
char tmpbuf[64];
/* Note - inet_ntop doesn't do size checking on its input. */
return (ISC_R_NOSPACE);
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
static isc_boolean_t
}
static void
}
static isc_result_t
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
static isc_result_t
if (value > 0xffff)
return (ISC_R_RANGE);
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
static isc_result_t
if (value > 0xff)
return (ISC_R_RANGE);
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
static isc_result_t
isc_region_t r;
dns_name_toregion(name, &r);
return (isc_buffer_copyregion(target, &r));
}
static isc_uint32_t
return(value);
}
static isc_uint16_t
return r;
}
static isc_uint16_t
}
static isc_uint8_t
}
static isc_uint8_t
return r;
}
static isc_result_t
if (length == 0U)
return (ISC_R_SUCCESS);
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
static int
const char *s;
unsigned char c;
c = (unsigned char)value;
if (!isascii(c))
return (-1);
if (isupper(c))
c = tolower(c);
return (-1);
return (int)(s - hexdigits);
}
static int
const char *s;
/*
* isascii() is valid for full range of int values, no need to
* mask or cast.
*/
return (-1);
return (-1);
return (int)(s - decdigits);
}
static const char atob_digits[86] =
"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" \
"abcdefghijklmnopqrstu";
/*
* Subroutines to convert between 8 bit binary bytes and printable ASCII.
* Computes the number of bytes, and three kinds of simple checksums.
* Incoming bytes are collected into 32-bit words, then printed in base 85:
* exp(85,5) > exp(2,32)
* The ASCII characters used are between '!' and 'u';
* 'z' encodes 32-bit zero; 'x' is used to mark the end of encoded data.
*
* Originally by Paul Rutter (philabs!per) and Joe Orost (petsd!joe) for
* Modified by Mike Schwartz 8/19/86 for use in BIND.
* Modified to be re-entrant 3/2/99.
*/
struct state {
};
/*
* Decode ASCII-encoded byte c into binary representation and
* place into *bufp, advancing bufp.
*/
static isc_result_t
const char *s;
if (c == 'z') {
if (bcount != 0)
return(DNS_R_SYNTAX);
else {
}
if (bcount == 0) {
++bcount;
} else if (bcount < 4) {
++bcount;
} else {
word = 0;
bcount = 0;
}
} else
return(DNS_R_SYNTAX);
return(ISC_R_SUCCESS);
}
/*
* Compute checksum info and place c into target.
*/
static isc_result_t
Ceor ^= c;
Csum += c;
Csum += 1;
if ((Crot & 0x80000000)) {
Crot <<= 1;
Crot += 1;
} else {
Crot <<= 1;
}
Crot += c;
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
/*
* Read the ASCII-encoded data from inbuf, of length inbuflen, and convert
* it into T_UNSPEC (binary data) in outbuf, not to exceed outbuflen bytes;
* outbuflen must be divisible by 4. (Note: this is because outbuf is filled
* in 4 bytes at a time. If the actual data doesn't end on an even 4-byte
* boundary, there will be no problem...it will be padded with 0 bytes, and
* numbytes will indicate the correct number of bytes. The main point is
* that since the buffer is filled in 4 bytes at a time, even if there is
* not a full 4 bytes of data at the end, there has to be room to 0-pad the
* data, so the buffer must be of size divisible by 4). Place the number of
*/
static isc_result_t
char c;
char *e;
ISC_FALSE));
break;
} else
}
/*
* Number of bytes.
*/
ISC_FALSE));
return (DNS_R_SYNTAX);
}
/*
* Checksum.
*/
ISC_FALSE));
if (*e != 0)
return (DNS_R_SYNTAX);
/*
* Checksum.
*/
ISC_FALSE));
if (*e != 0)
return (DNS_R_SYNTAX);
/*
* Checksum.
*/
ISC_FALSE));
if (*e != 0)
return (DNS_R_SYNTAX);
return(DNS_R_BADCKSUM);
return (ISC_R_SUCCESS);
}
/*
* Encode binary byte c into ASCII representation and place into *bufp,
* advancing bufp.
*/
static isc_result_t
Ceor ^= c;
Csum += c;
Csum += 1;
if ((Crot & 0x80000000)) {
Crot <<= 1;
Crot += 1;
} else {
Crot <<= 1;
}
Crot += c;
word <<= 8;
word |= c;
if (bcount == 3) {
if (word == 0) {
return (ISC_R_NOSPACE);
} else {
register int tmp = 0;
if (tmpword < 0) {
/*
* Because some don't support u_long.
*/
tmp = 32;
}
if (tmpword < 0) {
tmp = 64;
}
return (ISC_R_NOSPACE);
+ tmp];
tmpword %= 85;
}
bcount = 0;
} else {
bcount += 1;
}
return (ISC_R_SUCCESS);
}
/*
* Encode the binary data from inbuf, of length inbuflen, into a
*/
static isc_result_t
int inc;
char buf[sizeof("x 2000000000 ffffffff ffffffff ffffffff")];
while (bcount != 0)
/*
* Put byte count and checksum information at end of buffer,
* delimited by 'x'
*/
}
static void
...)
{
}
static void
name = "UNKNOWN";
"%s:%lu: file does not end with newline",
}
}
static void
{
const char *file;
unsigned long line;
}
}
static void
{
const char *file;
unsigned long line;
char namebuf[DNS_NAME_FORMATSIZE];
}
}
static void
{
name = "UNKNOWN";
case isc_tokentype_eol:
break;
case isc_tokentype_eof:
break;
case isc_tokentype_number:
break;
case isc_tokentype_string:
case isc_tokentype_qstring:
DNS_AS_STR(*token),
break;
default:
break;
}
} else {
}
}
return (covers_rrsig(rdata));
return (covers_sig(rdata));
}
return (ISC_TRUE);
return (ISC_FALSE);
}
!= 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
!= 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
!= 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
return (ISC_TRUE);
return (ISC_FALSE);
}
if (rdclass == dns_rdataclass_reserved0
|| rdclass == dns_rdataclass_none
|| rdclass == dns_rdataclass_any)
return (ISC_TRUE);
return (ISC_FALSE); /* Assume it is not a meta class. */
}
return (ISC_TRUE);
return (ISC_FALSE);
}
if ((dns_rdatatype_attributes(type)
!= 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
== 0)
return (ISC_TRUE);
return (ISC_FALSE);
}
void
}
void
}
void
}
void
}
const char *
switch (section) {
case DNS_SECTION_PREREQUISITE:
case dns_rdataclass_none:
case dns_rdatatype_any:
return ("domain doesn't exist");
default:
return ("rrset doesn't exist");
}
case dns_rdataclass_any:
case dns_rdatatype_any:
return ("domain exists");
default:
return ("rrset exists (value independent)");
}
default:
return ("rrset exists (value dependent)");
}
case DNS_SECTION_UPDATE:
case dns_rdataclass_none:
return ("delete");
case dns_rdataclass_any:
case dns_rdatatype_any:
return ("delete all rrsets");
default:
return ("delete rrset");
}
default:
return ("add");
}
}
return ("invalid");
}