Commit 9fe8cca0 authored by Francis Dupont's avatar Francis Dupont
Browse files

add URI support

parent d54394cb
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: named.conf,v 1.58 2007/06/19 23:46:59 tbox Exp $ */
/* $Id: named.conf,v 1.59 2011/03/03 14:10:26 fdupont Exp $ */
/*
* This is a worthless, nonrunnable example of a named.conf file that has
......@@ -394,7 +394,7 @@ zone "non-default-acl.demo.zone" {
grant root.domain. name host.domain. a ns md mf cname soa mb mg
mr "null" wks ptr hinfo minfo mx txt rp afsdb x25
isdn rt nsap sig "key" px gpos aaaa loc nxt srv naptr kx
cert a6 dname opt unspec tkey tsig ;
cert a6 dname opt unspec uri tkey tsig ;
grant foo.bar.com. self foo.bar.com. a;
};
};
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rdata_test.c,v 1.48 2007/06/19 23:46:59 tbox Exp $ */
/* $Id: rdata_test.c,v 1.49 2011/03/03 14:10:26 fdupont Exp $ */
#include <config.h>
......@@ -279,6 +279,11 @@ viastruct(dns_rdata_t *rdata, isc_mem_t *mctx,
result = dns_rdata_tostruct(rdata, sp = &unspec, NULL);
break;
}
case dns_rdatatype_uri: {
dns_rdata_uri_t uri;
result = dns_rdata_tostruct(rdata, sp = &uri, NULL);
break;
}
case dns_rdatatype_wks: {
dns_rdata_in_wks_t in_wks;
result = dns_rdata_tostruct(rdata, sp = &in_wks, NULL);
......@@ -541,6 +546,11 @@ viastruct(dns_rdata_t *rdata, isc_mem_t *mctx,
result = dns_rdata_tostruct(rdata, sp = &unspec, mctx);
break;
}
case dns_rdatatype_uri: {
dns_rdata_uri_t uri;
result = dns_rdata_tostruct(rdata, sp = &uri, mctx);
break;
}
case dns_rdatatype_wks: {
dns_rdata_in_wks_t in_wks;
result = dns_rdata_tostruct(rdata, sp = &in_wks, mctx);
......@@ -833,6 +843,11 @@ viastruct(dns_rdata_t *rdata, isc_mem_t *mctx,
result = dns_rdata_fromstruct(rdata2, rdc, rdt, &unspec, b);
break;
}
case dns_rdatatype_uri: {
dns_rdata_uri_t uri;
result = dns_rdata_fromstruct(rdata2, rdc, rdt, &uri, b);
break;
}
case dns_rdatatype_wks: {
dns_rdata_in_wks_t in_wks;
result = dns_rdata_fromstruct(rdata2, rdc, rdt, &in_wks, b);
......
......@@ -15,7 +15,7 @@
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
# $Id: genzone.sh,v 1.11 2009/02/26 06:09:19 marka Exp $
# $Id: genzone.sh,v 1.12 2011/03/03 14:10:26 fdupont Exp $
#
# Set up a test zone
......@@ -272,4 +272,9 @@ hip2 HIP ( 2 200100107B1A74DF365639CC39F1D578
; type 255
; TSIG is a meta-type and should never occur in master files.
; type 256
uri01 URI 10 20 "https://www.isc.org/"
uri02 URI 30 40 "https://www.isc.org/HolyCowThisSureIsAVeryLongURIRecordIDontEvenKnowWhatSomeoneWouldEverWantWithSuchAThingButTheSpecificationRequiresThatWesupportItSoHereWeGoTestingItLaLaLaLaLaLaLaSeriouslyThoughWhyWouldYouEvenConsiderUsingAURIThisLongItSeemsLikeASillyIdeaButEnhWhatAreYouGonnaDo/"
EOF
......@@ -75,6 +75,8 @@ txt09.example. 3600 IN TXT "foo\010bar"
txt10.example. 3600 IN TXT "foo bar"
txt11.example. 3600 IN TXT "\"foo\""
txt12.example. 3600 IN TXT "\"foo\""
uri01.example. 3600 IN URI 10 20 "https://www.isc.org/"
uri02.example. 3600 IN URI 30 40 "https://www.isc.org/HolyCowThisSureIsAVeryLongURIRecordIDontEvenKnowWhatSomeoneWouldEverWantWithSuchAThingButTheSpecificationRequiresThatWesupportItSoHereWeGoTestingItLaLaLaLaLaLaLaSeriouslyThoughWhyWouldYouEvenConsiderUsingAURIThisLongItSeemsLikeASillyIdeaButEnhWhatAreYouGonnaDo/"
wks01.example. 3600 IN WKS 10.0.0.1 6 0 1 2 21 23
wks02.example. 3600 IN WKS 10.0.0.1 17 0 1 2 53
wks03.example. 3600 IN WKS 10.0.0.2 6 65535
......
......@@ -75,6 +75,8 @@ txt09.example. 3600 IN TXT "foo\010bar"
txt10.example. 3600 IN TXT "foo bar"
txt11.example. 3600 IN TXT "\"foo\""
txt12.example. 3600 IN TXT "\"foo\""
uri01.example. 3600 IN URI 10 20 "https://www.isc.org/"
uri02.example. 3600 IN URI 30 40 "https://www.isc.org/HolyCowThisSureIsAVeryLongURIRecordIDontEvenKnowWhatSomeoneWouldEverWantWithSuchAThingButTheSpecificationRequiresThatWesupportItSoHereWeGoTestingItLaLaLaLaLaLaLaSeriouslyThoughWhyWouldYouEvenConsiderUsingAURIThisLongItSeemsLikeASillyIdeaButEnhWhatAreYouGonnaDo/"
wks01.example. 3600 IN WKS 10.0.0.1 6 0 1 2 21 23
wks02.example. 3600 IN WKS 10.0.0.1 17 0 1 2 53
wks03.example. 3600 IN WKS 10.0.0.2 6 65535
......
This diff is collapsed.
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: rdata.c,v 1.210 2011/02/21 06:41:07 marka Exp $ */
/* $Id: rdata.c,v 1.211 2011/03/03 14:10:27 fdupont Exp $ */
/*! \file */
......@@ -124,6 +124,15 @@ txt_fromtext(isc_textregion_t *source, isc_buffer_t *target);
static isc_result_t
txt_fromwire(isc_buffer_t *source, isc_buffer_t *target);
static isc_result_t
multitxt_totext(isc_region_t *source, isc_buffer_t *target);
static isc_result_t
multitxt_fromtext(isc_textregion_t *source, isc_buffer_t *target);
static isc_result_t
multitxt_fromwire(isc_buffer_t *source, isc_buffer_t *target);
static isc_boolean_t
name_prefix(dns_name_t *name, dns_name_t *origin, dns_name_t *target);
......@@ -1132,6 +1141,157 @@ txt_fromwire(isc_buffer_t *source, isc_buffer_t *target) {
return (ISC_R_SUCCESS);
}
static isc_result_t
multitxt_totext(isc_region_t *source, isc_buffer_t *target) {
unsigned int tl;
unsigned int n0, n;
unsigned char *sp;
char *tp;
isc_region_t region;
isc_buffer_availableregion(target, &region);
sp = source->base;
tp = (char *)region.base;
tl = region.length;
if (tl < 1)
return (ISC_R_NOSPACE);
*tp++ = '"';
tl--;
do {
n0 = n = *sp++;
REQUIRE(n0 + 1 <= source->length);
while (n--) {
if (*sp < 0x20 || *sp >= 0x7f) {
if (tl < 4)
return (ISC_R_NOSPACE);
*tp++ = 0x5c;
*tp++ = 0x30 + ((*sp / 100) % 10);
*tp++ = 0x30 + ((*sp / 10) % 10);
*tp++ = 0x30 + (*sp % 10);
sp++;
tl -= 4;
continue;
}
/* double quote, semi-colon, backslash */
if (*sp == 0x22 || *sp == 0x3b || *sp == 0x5c) {
if (tl < 2)
return (ISC_R_NOSPACE);
*tp++ = '\\';
tl--;
}
if (tl < 1)
return (ISC_R_NOSPACE);
*tp++ = *sp++;
tl--;
}
isc_region_consume(source, n0 + 1);
} while (source->length != 0);
if (tl < 1)
return (ISC_R_NOSPACE);
*tp++ = '"';
tl--;
isc_buffer_add(target, tp - (char *)region.base);
return (ISC_R_SUCCESS);
}
static isc_result_t
multitxt_fromtext(isc_textregion_t *source, isc_buffer_t *target) {
isc_region_t tregion;
isc_boolean_t escape;
unsigned int n, nrem;
char *s;
unsigned char *t0, *t;
int d;
int c;
s = source->base;
n = source->length;
escape = ISC_FALSE;
do {
isc_buffer_availableregion(target, &tregion);
t0 = tregion.base;
nrem = tregion.length;
if (nrem < 1)
return (ISC_R_NOSPACE);
/* length byte */
t = t0;
nrem--;
t++;
/* 255 byte character-string slice */
if (nrem > 255)
nrem = 255;
while (n != 0) {
--n;
c = (*s++) & 0xff;
if (escape && (d = decvalue((char)c)) != -1) {
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 == '\\') {
escape = ISC_TRUE;
continue;
}
escape = ISC_FALSE;
*t++ = c;
nrem--;
if (nrem == 0)
break;
}
if (escape)
return (DNS_R_SYNTAX);
*t0 = t - t0 - 1;
isc_buffer_add(target, *t0 + 1);
} while (n != 0);
return (ISC_R_SUCCESS);
}
static isc_result_t
multitxt_fromwire(isc_buffer_t *source, isc_buffer_t *target) {
unsigned int n;
isc_region_t sregion;
isc_region_t tregion;
isc_buffer_activeregion(source, &sregion);
if (sregion.length == 0)
return(ISC_R_UNEXPECTEDEND);
n = 256U;
do {
if (n != 256U)
return (DNS_R_SYNTAX);
n = *sregion.base + 1;
if (n > sregion.length)
return (ISC_R_UNEXPECTEDEND);
isc_buffer_availableregion(target, &tregion);
if (n > tregion.length)
return (ISC_R_NOSPACE);
memcpy(tregion.base, sregion.base, n);
isc_buffer_forward(source, n);
isc_buffer_add(target, n);
isc_buffer_activeregion(source, &sregion);
} while (sregion.length != 0);
return (ISC_R_SUCCESS);
}
static isc_boolean_t
name_prefix(dns_name_t *name, dns_name_t *origin, dns_name_t *target) {
int l1, l2;
......
/*
* Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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: uri_256.c,v 1.2 2011/03/03 14:10:27 fdupont Exp $ */
#ifndef GENERIC_URI_256_C
#define GENERIC_URI_256_C 1
#define RRTYPE_URI_ATTRIBUTES (0)
static inline isc_result_t
fromtext_uri(ARGS_FROMTEXT) {
isc_token_t token;
REQUIRE(type == 256);
UNUSED(type);
UNUSED(rdclass);
UNUSED(origin);
UNUSED(options);
UNUSED(callbacks);
/*
* Priority
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
ISC_FALSE));
if (token.value.as_ulong > 0xffffU)
RETTOK(ISC_R_RANGE);
RETERR(uint16_tobuffer(token.value.as_ulong, target));
/*
* Weight
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
ISC_FALSE));
if (token.value.as_ulong > 0xffffU)
RETTOK(ISC_R_RANGE);
RETERR(uint16_tobuffer(token.value.as_ulong, target));
/*
* Target URI
*/
RETERR(isc_lex_getmastertoken(lexer, &token,
isc_tokentype_qstring, ISC_FALSE));
if (token.type != isc_tokentype_qstring)
RETTOK(DNS_R_SYNTAX);
RETTOK(multitxt_fromtext(&token.value.as_textregion, target));
return (ISC_R_SUCCESS);
}
static inline isc_result_t
totext_uri(ARGS_TOTEXT) {
isc_region_t region;
unsigned short priority, weight;
char buf[sizeof("65000 ")];
UNUSED(tctx);
REQUIRE(rdata->type == 256);
REQUIRE(rdata->length != 0);
dns_rdata_toregion(rdata, &region);
/*
* Priority
*/
priority = uint16_fromregion(&region);
isc_region_consume(&region, 2);
sprintf(buf, "%u ", priority);
RETERR(str_totext(buf, target));
/*
* Weight
*/
weight = uint16_fromregion(&region);
isc_region_consume(&region, 2);
sprintf(buf, "%u ", weight);
RETERR(str_totext(buf, target));
/*
* Target URI
*/
RETERR(multitxt_totext(&region, target));
return (ISC_R_SUCCESS);
}
static inline isc_result_t
fromwire_uri(ARGS_FROMWIRE) {
isc_region_t region;
REQUIRE(type == 256);
UNUSED(type);
UNUSED(rdclass);
UNUSED(dctx);
UNUSED(options);
/*
* Priority, weight
*/
isc_buffer_activeregion(source, &region);
if (region.length < 4)
return (ISC_R_UNEXPECTEDEND);
RETERR(mem_tobuffer(target, region.base, 4));
isc_buffer_forward(source, 4);
/*
* Target URI
*/
RETERR(multitxt_fromwire(source, target));
return (ISC_R_SUCCESS);
}
static inline isc_result_t
towire_uri(ARGS_TOWIRE) {
isc_region_t region;
REQUIRE(rdata->type == 256);
REQUIRE(rdata->length != 0);
UNUSED(cctx);
dns_rdata_toregion(rdata, &region);
return (mem_tobuffer(target, region.base, region.length));
}
static inline int
compare_uri(ARGS_COMPARE) {
isc_region_t r1;
isc_region_t r2;
int order;
REQUIRE(rdata1->type == rdata2->type);
REQUIRE(rdata1->rdclass == rdata2->rdclass);
REQUIRE(rdata1->type == 256);
REQUIRE(rdata1->length != 0);
REQUIRE(rdata2->length != 0);
dns_rdata_toregion(rdata1, &r1);
dns_rdata_toregion(rdata2, &r2);
/*
* Priority
*/
order = memcmp(r1.base, r2.base, 2);
if (order != 0)
return (order < 0 ? -1 : 1);
isc_region_consume(&r1, 2);
isc_region_consume(&r2, 2);
/*
* Weight
*/
order = memcmp(r1.base, r2.base, 2);
if (order != 0)
return (order < 0 ? -1 : 1);
isc_region_consume(&r1, 2);
isc_region_consume(&r2, 2);
return (isc_region_compare(&r1, &r2));
}
static inline isc_result_t
fromstruct_uri(ARGS_FROMSTRUCT) {
dns_rdata_uri_t *uri = source;
isc_region_t region;
isc_uint8_t len;
REQUIRE(type == 256);
REQUIRE(source != NULL);
REQUIRE(uri->common.rdtype == type);
REQUIRE(uri->common.rdclass == rdclass);
REQUIRE(uri->target != NULL && uri->tgt_len != 0);
UNUSED(type);
UNUSED(rdclass);
/*
* Priority
*/
RETERR(uint16_tobuffer(uri->priority, target));
/*
* Weight
*/
RETERR(uint16_tobuffer(uri->weight, target));
/*
* Target URI
*/
len = 255U;
region.base = uri->target;
region.length = uri->tgt_len;
while (region.length > 0) {
REQUIRE(len == 255U);
len = uint8_fromregion(&region);
isc_region_consume(&region, 1);
if (region.length < len)
return (ISC_R_UNEXPECTEDEND);
isc_region_consume(&region, len);
}
return (mem_tobuffer(target, uri->target, uri->tgt_len));
}
static inline isc_result_t
tostruct_uri(ARGS_TOSTRUCT) {
dns_rdata_uri_t *uri = target;
isc_region_t sr;
REQUIRE(rdata->type == 256);
REQUIRE(target != NULL);
REQUIRE(rdata->length != 0);
uri->common.rdclass = rdata->rdclass;
uri->common.rdtype = rdata->type;
ISC_LINK_INIT(&uri->common, link);
dns_rdata_toregion(rdata, &sr);
/*
* Priority
*/
if (sr.length < 2)
return (ISC_R_UNEXPECTEDEND);
uri->priority = uint16_fromregion(&sr);
isc_region_consume(&sr, 2);
/*
* Weight
*/
if (sr.length < 2)
return (ISC_R_UNEXPECTEDEND);
uri->weight = uint16_fromregion(&sr);
isc_region_consume(&sr, 2);
/*
* Target URI
*/
uri->tgt_len = sr.length;
uri->target = mem_maybedup(mctx, sr.base, sr.length);
if (uri->target == NULL)
return (ISC_R_NOMEMORY);
uri->mctx = mctx;
return (ISC_R_SUCCESS);
}
static inline void
freestruct_uri(ARGS_FREESTRUCT) {
dns_rdata_uri_t *uri = (dns_rdata_uri_t *) source;
REQUIRE(source != NULL);
REQUIRE(uri->common.rdtype == 256);
if (uri->mctx == NULL)
return;
if (uri->target != NULL)
isc_mem_free(uri->mctx, uri->target);
uri->mctx = NULL;
}
static inline isc_result_t
additionaldata_uri(ARGS_ADDLDATA) {
REQUIRE(rdata->type == 256);
UNUSED(rdata);
UNUSED(add);
UNUSED(arg);
return (ISC_R_SUCCESS);
}
static inline isc_result_t
digest_uri(ARGS_DIGEST) {
isc_region_t r;
REQUIRE(rdata->type == 256);
dns_rdata_toregion(rdata, &r);
return ((digest)(arg, &r));
}
static inline isc_boolean_t
checkowner_uri(ARGS_CHECKOWNER) {
REQUIRE(type == 256);
UNUSED(name);
UNUSED(type);
UNUSED(rdclass);
UNUSED(wildcard);
return (ISC_TRUE);
}
static inline isc_boolean_t
checknames_uri(ARGS_CHECKNAMES) {
REQUIRE(rdata->type == 256);
UNUSED(rdata);
UNUSED(owner);
UNUSED(bad);
return (ISC_TRUE);
}
static inline int
casecompare_uri(ARGS_COMPARE) {
return (compare_uri(rdata1, rdata2));
}
#endif /* GENERIC_URI_256_C */