2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: tkey_249.c,v 1.48.2.1.2.6 2004/03/08 09:04:42 marka Exp $ */
21 * Reviewed: Thu Mar 16 17:35:30 PST 2000 by halley.
24 /* draft-ietf-dnsext-tkey-01.txt */
26 #ifndef RDATA_GENERIC_TKEY_249_C
27 #define RDATA_GENERIC_TKEY_249_C
29 #define RRTYPE_TKEY_ATTRIBUTES (DNS_RDATATYPEATTR_META)
31 static inline isc_result_t
32 fromtext_tkey(ARGS_FROMTEXT) {
49 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
51 dns_name_init(&name, NULL);
52 buffer_fromregion(&buffer, &token.value.as_region);
53 origin = (origin != NULL) ? origin : dns_rootname;
54 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
60 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
62 RETERR(uint32_tobuffer(token.value.as_ulong, target));
67 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
69 RETERR(uint32_tobuffer(token.value.as_ulong, target));
74 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
76 if (token.value.as_ulong > 0xffffU)
78 RETERR(uint16_tobuffer(token.value.as_ulong, target));
83 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
85 if (dns_tsigrcode_fromtext(&rcode, &token.value.as_textregion)
88 i = strtol(DNS_AS_STR(token), &e, 10);
90 RETTOK(DNS_R_UNKNOWN);
91 if (i < 0 || i > 0xffff)
93 rcode = (dns_rcode_t)i;
95 RETERR(uint16_tobuffer(rcode, target));
100 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
102 if (token.value.as_ulong > 0xffffU)
104 RETERR(uint16_tobuffer(token.value.as_ulong, target));
109 RETERR(isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
114 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
116 if (token.value.as_ulong > 0xffffU)
118 RETERR(uint16_tobuffer(token.value.as_ulong, target));
123 return (isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
126 static inline isc_result_t
127 totext_tkey(ARGS_TOTEXT) {
129 char buf[sizeof("4294967295 ")];
135 REQUIRE(rdata->type == 249);
136 REQUIRE(rdata->length != 0);
138 dns_rdata_toregion(rdata, &sr);
143 dns_name_init(&name, NULL);
144 dns_name_init(&prefix, NULL);
145 dns_name_fromregion(&name, &sr);
146 sub = name_prefix(&name, tctx->origin, &prefix);
147 RETERR(dns_name_totext(&prefix, sub, target));
148 RETERR(str_totext(" ", target));
149 isc_region_consume(&sr, name_length(&name));
154 n = uint32_fromregion(&sr);
155 isc_region_consume(&sr, 4);
156 sprintf(buf, "%lu ", n);
157 RETERR(str_totext(buf, target));
162 n = uint32_fromregion(&sr);
163 isc_region_consume(&sr, 4);
164 sprintf(buf, "%lu ", n);
165 RETERR(str_totext(buf, target));
170 n = uint16_fromregion(&sr);
171 isc_region_consume(&sr, 2);
172 sprintf(buf, "%lu ", n);
173 RETERR(str_totext(buf, target));
178 n = uint16_fromregion(&sr);
179 isc_region_consume(&sr, 2);
180 if (dns_tsigrcode_totext((dns_rcode_t)n, target) == ISC_R_SUCCESS)
181 RETERR(str_totext(" ", target));
183 sprintf(buf, "%lu ", n);
184 RETERR(str_totext(buf, target));
190 n = uint16_fromregion(&sr);
191 isc_region_consume(&sr, 2);
192 sprintf(buf, "%lu", n);
193 RETERR(str_totext(buf, target));
198 REQUIRE(n <= sr.length);
201 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
202 RETERR(str_totext(" (", target));
203 RETERR(str_totext(tctx->linebreak, target));
204 RETERR(isc_base64_totext(&dr, tctx->width - 2,
205 tctx->linebreak, target));
206 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
207 RETERR(str_totext(" ) ", target));
209 RETERR(str_totext(" ", target));
210 isc_region_consume(&sr, n);
215 n = uint16_fromregion(&sr);
216 isc_region_consume(&sr, 2);
217 sprintf(buf, "%lu", n);
218 RETERR(str_totext(buf, target));
223 REQUIRE(n <= sr.length);
227 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
228 RETERR(str_totext(" (", target));
229 RETERR(str_totext(tctx->linebreak, target));
230 RETERR(isc_base64_totext(&dr, tctx->width - 2,
231 tctx->linebreak, target));
232 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
233 RETERR(str_totext(" )", target));
235 return (ISC_R_SUCCESS);
238 static inline isc_result_t
239 fromwire_tkey(ARGS_FROMWIRE) {
244 REQUIRE(type == 249);
249 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
254 dns_name_init(&name, NULL);
255 RETERR(dns_name_fromwire(&name, source, dctx, options, target));
263 isc_buffer_activeregion(source, &sr);
265 return (ISC_R_UNEXPECTEDEND);
266 RETERR(mem_tobuffer(target, sr.base, 12));
267 isc_region_consume(&sr, 12);
268 isc_buffer_forward(source, 12);
271 * Key Length + Key Data.
274 return (ISC_R_UNEXPECTEDEND);
275 n = uint16_fromregion(&sr);
276 if (sr.length < n + 2)
277 return (ISC_R_UNEXPECTEDEND);
278 RETERR(mem_tobuffer(target, sr.base, n + 2));
279 isc_region_consume(&sr, n + 2);
280 isc_buffer_forward(source, n + 2);
283 * Other Length + Other Data.
286 return (ISC_R_UNEXPECTEDEND);
287 n = uint16_fromregion(&sr);
288 if (sr.length < n + 2)
289 return (ISC_R_UNEXPECTEDEND);
290 isc_buffer_forward(source, n + 2);
291 return (mem_tobuffer(target, sr.base, n + 2));
294 static inline isc_result_t
295 towire_tkey(ARGS_TOWIRE) {
298 dns_offsets_t offsets;
300 REQUIRE(rdata->type == 249);
301 REQUIRE(rdata->length != 0);
303 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
307 dns_rdata_toregion(rdata, &sr);
308 dns_name_init(&name, offsets);
309 dns_name_fromregion(&name, &sr);
310 RETERR(dns_name_towire(&name, cctx, target));
311 isc_region_consume(&sr, name_length(&name));
313 return (mem_tobuffer(target, sr.base, sr.length));
317 compare_tkey(ARGS_COMPARE) {
324 REQUIRE(rdata1->type == rdata2->type);
325 REQUIRE(rdata1->rdclass == rdata2->rdclass);
326 REQUIRE(rdata1->type == 249);
327 REQUIRE(rdata1->length != 0);
328 REQUIRE(rdata2->length != 0);
333 dns_rdata_toregion(rdata1, &r1);
334 dns_rdata_toregion(rdata2, &r2);
335 dns_name_init(&name1, NULL);
336 dns_name_init(&name2, NULL);
337 dns_name_fromregion(&name1, &r1);
338 dns_name_fromregion(&name2, &r2);
339 if ((order = dns_name_rdatacompare(&name1, &name2)) != 0)
341 isc_region_consume(&r1, name_length(&name1));
342 isc_region_consume(&r2, name_length(&name2));
343 return (isc_region_compare(&r1, &r2));
346 static inline isc_result_t
347 fromstruct_tkey(ARGS_FROMSTRUCT) {
348 dns_rdata_tkey_t *tkey = source;
350 REQUIRE(type == 249);
351 REQUIRE(source != NULL);
352 REQUIRE(tkey->common.rdtype == type);
353 REQUIRE(tkey->common.rdclass == rdclass);
361 RETERR(name_tobuffer(&tkey->algorithm, target));
364 * Inception: 32 bits.
366 RETERR(uint32_tobuffer(tkey->inception, target));
371 RETERR(uint32_tobuffer(tkey->expire, target));
376 RETERR(uint16_tobuffer(tkey->mode, target));
381 RETERR(uint16_tobuffer(tkey->error, target));
386 RETERR(uint16_tobuffer(tkey->keylen, target));
391 RETERR(mem_tobuffer(target, tkey->key, tkey->keylen));
394 * Other size: 16 bits.
396 RETERR(uint16_tobuffer(tkey->otherlen, target));
401 return (mem_tobuffer(target, tkey->other, tkey->otherlen));
404 static inline isc_result_t
405 tostruct_tkey(ARGS_TOSTRUCT) {
406 dns_rdata_tkey_t *tkey = target;
410 REQUIRE(rdata->type == 249);
411 REQUIRE(target != NULL);
412 REQUIRE(rdata->length != 0);
414 tkey->common.rdclass = rdata->rdclass;
415 tkey->common.rdtype = rdata->type;
416 ISC_LINK_INIT(&tkey->common, link);
418 dns_rdata_toregion(rdata, &sr);
423 dns_name_init(&alg, NULL);
424 dns_name_fromregion(&alg, &sr);
425 dns_name_init(&tkey->algorithm, NULL);
426 RETERR(name_duporclone(&alg, mctx, &tkey->algorithm));
427 isc_region_consume(&sr, name_length(&tkey->algorithm));
432 tkey->inception = uint32_fromregion(&sr);
433 isc_region_consume(&sr, 4);
438 tkey->expire = uint32_fromregion(&sr);
439 isc_region_consume(&sr, 4);
444 tkey->mode = uint16_fromregion(&sr);
445 isc_region_consume(&sr, 2);
450 tkey->error = uint16_fromregion(&sr);
451 isc_region_consume(&sr, 2);
456 tkey->keylen = uint16_fromregion(&sr);
457 isc_region_consume(&sr, 2);
462 tkey->key = mem_maybedup(mctx, sr.base, tkey->keylen);
463 if (tkey->key == NULL)
465 isc_region_consume(&sr, tkey->keylen);
470 tkey->otherlen = uint16_fromregion(&sr);
471 isc_region_consume(&sr, 2);
476 tkey->other = mem_maybedup(mctx, sr.base, tkey->otherlen);
477 if (tkey->other == NULL)
481 return (ISC_R_SUCCESS);
485 dns_name_free(&tkey->algorithm, mctx);
486 if (mctx != NULL && tkey->key != NULL)
487 isc_mem_free(mctx, tkey->key);
488 return (ISC_R_NOMEMORY);
492 freestruct_tkey(ARGS_FREESTRUCT) {
493 dns_rdata_tkey_t *tkey = (dns_rdata_tkey_t *) source;
495 REQUIRE(source != NULL);
497 if (tkey->mctx == NULL)
500 dns_name_free(&tkey->algorithm, tkey->mctx);
501 if (tkey->key != NULL)
502 isc_mem_free(tkey->mctx, tkey->key);
503 if (tkey->other != NULL)
504 isc_mem_free(tkey->mctx, tkey->other);
508 static inline isc_result_t
509 additionaldata_tkey(ARGS_ADDLDATA) {
514 REQUIRE(rdata->type == 249);
516 return (ISC_R_SUCCESS);
519 static inline isc_result_t
520 digest_tkey(ARGS_DIGEST) {
525 REQUIRE(rdata->type == 249);
527 return (ISC_R_NOTIMPLEMENTED);
530 static inline isc_boolean_t
531 checkowner_tkey(ARGS_CHECKOWNER) {
533 REQUIRE(type == 249);
543 static inline isc_boolean_t
544 checknames_tkey(ARGS_CHECKNAMES) {
546 REQUIRE(rdata->type == 249);
555 #endif /* RDATA_GENERIC_TKEY_249_C */