rdata.c revision 0e8cf9a887c70f96ac448b06c069d90b830215cc
/*
* Copyright (C) 1998, 1999 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: rdata.c,v 1.35 1999/02/16 22:42:23 marka Exp $ */
#include <config.h>
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#include <isc/assertions.h>
#include <dns/rdataclass.h>
#include <dns/rdatatype.h>
#define RETERR(x) do { \
dns_result_t __r = (x); \
if (__r != DNS_R_SUCCESS) \
return (__r); \
} while (0)
dns_name_t *target);
unsigned int type);
unsigned int length);
int length);
static void default_fromtext_callback(
char *, ...);
char *, ...),
static const char hexdigits[] = "0123456789abcdef";
static const char decdigits[] = "0123456789";
static const char octdigits[] = "01234567";
#include "code.h"
#define META 0x0001
#define RESERVED 0x0002
#define METATYPES \
{ 0, "NONE", META }, \
#define METACLASSES \
{ 0, "NONE", META }, \
#define RCODENAMES \
/* standard rcodes */ \
{ dns_rcode_noerror, "NOERROR", 0}, \
{ dns_rcode_formerr, "FORMERR", 0}, \
{ dns_rcode_servfail, "SERVFAIL", 0}, \
{ dns_rcode_nxdomain, "NXDOMAIN", 0}, \
{ dns_rcode_notimp, "NOTIMP", 0}, \
{ dns_rcode_refused, "REFUSED", 0}, \
{ dns_rcode_yxdomain, "YXDOMAIN", 0}, \
{ dns_rcode_yxrrset, "YXRRSET", 0}, \
{ dns_rcode_nxrrset, "NXRRSET", 0}, \
{ dns_rcode_notauth, "NOTAUTH", 0}, \
{ dns_rcode_notzone, "NOTZONE", 0}, \
/* extended rcodes */ \
{ dns_rcode_badsig, "BADSIG", 0}, \
{ dns_rcode_badkey, "BADKEY", 0}, \
{ dns_rcode_badtime, "BADTIME", 0}, \
{ dns_rcode_badmode, "BADMODE", 0}, \
{ 0, NULL, 0 }
#define CERTNAMES \
{ 1, "SKIX", 0}, \
{ 2, "SPKI", 0}, \
{ 3, "PGP", 0}, \
{ 253, "URI", 0}, \
{ 254, "OID", 0}, \
{ 0, NULL, 0}
#define SECALGNAMES \
{ 2, "Diffie-Hellman", 0}, \
{ 3, "DSA", 0}, \
{ 4, "Ellyptic-Curve", 0}, \
{ 0, NULL, 0}
static struct tbl {
unsigned int value;
char *name;
int flags;
rcodes[] = { RCODENAMES },
secalgs[] = { SECALGNAMES };
/***
*** Initialization
***/
void
/* ISC_LIST_INIT(rdata->list); */
}
/***
*** Comparisons
***/
int
int result = 0;
if (use_default) {
}
return (result);
}
/***
*** Conversions
***/
void
{
}
void
}
{
/* XXX */
if (use_default)
(void)NULL;
/* We should have consumed all out buffer */
}
if (result != DNS_R_SUCCESS) {
}
return (result);
}
{
if (use_default) {
return (DNS_R_NOSPACE);
return (DNS_R_SUCCESS);
}
return (result);
}
{
char *name;
int line;
void (*callback)(dns_rdatacallbacks_t *, char *, ...);
if (use_default)
(void)NULL;
else
/*
* 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 (iresult != ISC_R_SUCCESS) {
if (result == DNS_R_SUCCESS) {
switch (iresult) {
case ISC_R_NOMEMORY:
break;
case ISC_R_NOSPACE:
break;
default:
"isc_lex_gettoken() failed: %s\n",
break;
}
}
break;
if (result == DNS_R_SUCCESS)
}
break;
} else
break;
} while (1);
}
if (result != DNS_R_SUCCESS) {
}
return (result);
}
{
if (use_default)
(void)NULL;
return (result);
}
{
if (use_default)
(void)NULL;
}
if (result != DNS_R_SUCCESS)
return (result);
}
if (use_default)
(void)NULL;
return (result);
}
int i = 0;
unsigned int n;
return (DNS_R_NOTIMPLEMENTED);
return (DNS_R_SUCCESS);
}
i++;
}
return (DNS_R_UNKNOWN);
}
int i = 0;
char buf[sizeof "65000"];
}
i++;
}
}
int i = 0;
unsigned int n;
return (DNS_R_NOTIMPLEMENTED);
return (DNS_R_SUCCESS);
}
i++;
}
return (DNS_R_UNKNOWN);
}
int i = 0;
char buf[sizeof "65000"];
}
i++;
}
}
int i = 0;
unsigned int n;
return (DNS_R_SUCCESS);
}
i++;
}
return (DNS_R_UNKNOWN);
}
int i = 0;
char buf[sizeof "65000"];
}
i++;
}
}
int i = 0;
unsigned int n;
return (DNS_R_SUCCESS);
}
i++;
}
return (DNS_R_UNKNOWN);
}
int i = 0;
char buf[sizeof "65000"];
}
i++;
}
}
int i = 0;
unsigned int n;
return (DNS_R_SUCCESS);
}
i++;
}
return (DNS_R_UNKNOWN);
}
int i = 0;
char buf[sizeof "65000"];
}
i++;
}
}
/* Private function */
static unsigned int
}
static dns_result_t
unsigned int tl;
unsigned int n;
unsigned char *sp;
char *tp;
n = *sp++;
if (tl < 1)
return (DNS_R_NOSPACE);
*tp++ = '"';
tl--;
while (n--) {
if (tl < 4)
return (DNS_R_NOSPACE);
tp += 4;
tl -= 4;
continue;
}
if (tl < 2)
return (DNS_R_NOSPACE);
*tp++ = '\\';
tl--;
}
if (tl < 1)
return (DNS_R_NOSPACE);
tl--;
}
if (tl < 1)
return (DNS_R_NOSPACE);
*tp++ = '"';
tl--;
return (DNS_R_SUCCESS);
}
static dns_result_t
return (DNS_R_NOSPACE);
return (DNS_R_TEXTTOLONG);
return (DNS_R_SUCCESS);
}
static dns_result_t
unsigned int n;
return(DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTEDEND);
return (DNS_R_NOSPACE);
isc_buffer_forward(source, n);
isc_buffer_add(target, n);
return (DNS_R_SUCCESS);
}
static isc_boolean_t
goto return_false;
goto return_false;
goto return_false;
goto return_false;
return (ISC_TRUE);
return (ISC_FALSE);
}
static dns_result_t
unsigned int l;
return (DNS_R_NOSPACE);
isc_buffer_add(target, l);
return (DNS_R_SUCCESS);
}
static isc_boolean_t
}
static void
unsigned int type) {
}
static dns_result_t
return (DNS_R_NOSPACE);
return (DNS_R_SUCCESS);
}
static dns_result_t
if (value > 0xffff)
return (DNS_R_RANGE);
return (DNS_R_NOSPACE);
return (DNS_R_SUCCESS);
}
static isc_uint32_t
unsigned long value;
return(value);
}
static isc_uint16_t
}
static dns_result_t
{
if (expect == isc_tokentype_qstring)
else if (expect == isc_tokentype_number)
switch (result) {
case ISC_R_SUCCESS:
break;
case ISC_R_NOMEMORY:
return (DNS_R_NOMEMORY);
case ISC_R_NOSPACE:
return (DNS_R_NOSPACE);
default:
"isc_lex_gettoken() failed: %s\n",
return (DNS_R_UNEXPECTED);
}
return (DNS_R_SUCCESS);
return (DNS_R_SUCCESS);
return (DNS_R_UNEXPECTEDEND);
return (DNS_R_UNEXPECTEDTOKEN);
}
return (DNS_R_SUCCESS);
}
static dns_result_t
return (DNS_R_NOSPACE);
return (DNS_R_SUCCESS);
}
static int
unsigned int l;
int result;
else
}
static int
char *s;
return (-1);
return (-1);
return (s - hexdigits);
}
static int
char *s;
return (-1);
return (-1);
return (s - decdigits);
}
static const char base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
static dns_result_t
char buf[5];
int loops = 0;
loops = 0;
}
}
}
return (DNS_R_SUCCESS);
}
static dns_result_t
int digits = 0;
int val[4];
unsigned char buf[3];
int seen_end = 0;
unsigned int i;
char *s;
int n;
if (length > 0)
ISC_FALSE));
else
ISC_TRUE));
break;
if (seen_end)
return (DNS_R_BADBASE64);
return (DNS_R_BADBASE64);
if (digits == 4) {
return (DNS_R_BADBASE64);
return (DNS_R_BADBASE64);
if (n != 3) {
seen_end = 1;
val[2] = 0;
val[3] = 0;
}
if (length >= 0)
if (n > length)
return (DNS_R_BADBASE64);
else
length -= n;
digits = 0;
}
}
}
if (length > 0)
return (DNS_R_UNEXPECTEDEND);
if (digits != 0)
return (DNS_R_BADBASE64);
return (DNS_R_SUCCESS);
}
static dns_result_t
isc_int64_t t;
char buf[sizeof "YYYYMMDDHHMMSS"];
int secs;
/* find the right epoch */
start -= 0x7fffffff;
base = 0;
base += 0x80000000;
base += 0x80000000;
}
t -= secs;
}
t -= secs;
}
while (86400 <= t) {
t -= 86400;
}
while (3600 <= t) {
t -= 3600;
}
while (60 <= t) {
t -= 60;
}
/* yy mm dd HH MM SS */
}
static dns_result_t
unsigned long value;
int secs;
int i;
do { \
return (DNS_R_RANGE); \
} while (0)
return (DNS_R_SYNTAX);
return (DNS_R_SYNTAX);
/* calulate seconds since epoch */
for (i = 0; i < (month - 1) ; i++)
value += 86400;
for (i = 1970; i < year; i++) {
}
}
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 dns_result_t
char *s;
if (c == 'z') {
if (bcount != 0)
return(DNS_R_SYNTAX);
else {
}
if (bcount == 0) {
word = s - atob_digits;
++bcount;
} else if (bcount < 4) {
word += s - atob_digits;
++bcount;
} else {
word += s - atob_digits;
word = 0;
bcount = 0;
}
} else
return(DNS_R_SYNTAX);
return(DNS_R_SUCCESS);
}
/* Compute checksum info and place c into target */
static dns_result_t
Ceor ^= c;
Csum += c;
Csum += 1;
if ((Crot & 0x80000000)) {
Crot <<= 1;
Crot += 1;
} else {
Crot <<= 1;
}
Crot += c;
return (DNS_R_NOSPACE);
return (DNS_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 dns_result_t
char c;
char *e;
break;
} else
}
/* number of bytes */
/* checksum */
if (*e != 0)
return (DNS_R_SYNTAX);
/* checksum */
if (*e != 0)
return (DNS_R_SYNTAX);
/* checksum */
if (*e != 0)
return (DNS_R_SYNTAX);
return(DNS_R_BADCKSUM);
return(DNS_R_SUCCESS);
}
/* Encode binary byte c into ASCII representation and place into *bufp,
advancing bufp */
static dns_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 (DNS_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 (DNS_R_NOSPACE);
+ tmp];
tmpword %= 85;
}
bcount = 0;
} else {
bcount += 1;
}
return (DNS_R_SUCCESS);
}
/*
* Encode the binary data from inbuf, of length inbuflen, into a
*/
static dns_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";
case isc_tokentype_eol:
break;
case isc_tokentype_eof:
break;
case isc_tokentype_number:
break;
case isc_tokentype_string:
case isc_tokentype_qstring:
break;
default:
break;
}
} else {
}
}