tsig_250.c 12.8 KB
Newer Older
Mark Andrews's avatar
Mark Andrews committed
1
/*
Bob Halley's avatar
Bob Halley committed
2
 * Copyright (C) 1999, 2000  Internet Software Consortium.
3
 *
Mark Andrews's avatar
Mark Andrews committed
4 5 6
 * 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.
7
 *
8 9 10 11 12 13 14 15
 * 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.
Mark Andrews's avatar
Mark Andrews committed
16 17
 */

18
/* $Id: tsig_250.c,v 1.46 2000/12/01 01:40:14 gson Exp $ */
Mark Andrews's avatar
Mark Andrews committed
19

Andreas Gustafsson's avatar
Andreas Gustafsson committed
20 21
/* Reviewed: Thu Mar 16 13:39:43 PST 2000 by gson */

22 23
#ifndef RDATA_ANY_255_TSIG_250_C
#define RDATA_ANY_255_TSIG_250_C
Andreas Gustafsson's avatar
Andreas Gustafsson committed
24

25 26
#define RRTYPE_TSIG_ATTRIBUTES \
	(DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_NOTQUESTION)
27

28
static inline isc_result_t
29
fromtext_any_tsig(ARGS_FROMTEXT) {
Mark Andrews's avatar
Mark Andrews committed
30 31
	isc_token_t token;
	dns_name_t name;
Mark Andrews's avatar
Mark Andrews committed
32
	isc_uint64_t sigtime;
Mark Andrews's avatar
Mark Andrews committed
33
	isc_buffer_t buffer;
34 35
	dns_rcode_t rcode;
	long i;
Mark Andrews's avatar
Mark Andrews committed
36 37 38
	char *e;

	REQUIRE(type == 250);
39
	REQUIRE(rdclass == 255);
Mark Andrews's avatar
Mark Andrews committed
40

41 42
	UNUSED(rdclass);

David Lawrence's avatar
David Lawrence committed
43 44 45
	/*
	 * Algorithm Name.
	 */
46 47
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
				      ISC_FALSE));
Mark Andrews's avatar
Mark Andrews committed
48
	dns_name_init(&name, NULL);
49
	buffer_fromregion(&buffer, &token.value.as_region);
Mark Andrews's avatar
Mark Andrews committed
50 51 52
	origin = (origin != NULL) ? origin : dns_rootname;
	RETERR(dns_name_fromtext(&name, &buffer, origin, downcase, target));

David Lawrence's avatar
David Lawrence committed
53 54 55
	/*
	 * Time Signed: 48 bits.
	 */
56 57
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
				      ISC_FALSE));
58
	sigtime = isc_string_touint64(token.value.as_pointer, &e, 10);
Mark Andrews's avatar
Mark Andrews committed
59 60 61
	if (*e != 0)
		return (DNS_R_SYNTAX);
	if ((sigtime >> 48) != 0)
David Lawrence's avatar
David Lawrence committed
62
		return (ISC_R_RANGE);
63
	RETERR(uint16_tobuffer((isc_uint16_t)(sigtime >> 32), target));
Andreas Gustafsson's avatar
Andreas Gustafsson committed
64
	RETERR(uint32_tobuffer((isc_uint32_t)(sigtime & 0xffffffffU), target));
Mark Andrews's avatar
Mark Andrews committed
65

David Lawrence's avatar
David Lawrence committed
66 67 68
	/*
	 * Fudge.
	 */
69 70
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
				      ISC_FALSE));
Mark Andrews's avatar
Mark Andrews committed
71
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
72
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
73 74
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
75 76 77
	/*
	 * Signature Size.
	 */
78 79
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
				      ISC_FALSE));
Mark Andrews's avatar
Mark Andrews committed
80
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
81
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
82 83
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
84 85 86 87
	/*
	 * Signature.
	 */
	RETERR(isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
Mark Andrews's avatar
Mark Andrews committed
88

David Lawrence's avatar
David Lawrence committed
89 90 91
	/*
	 * Original ID.
	 */
92 93
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
				      ISC_FALSE));
Mark Andrews's avatar
Mark Andrews committed
94
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
95
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
96 97
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
98 99 100
	/*
	 * Error.
	 */
101 102
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
				      ISC_FALSE));
103 104 105 106 107 108 109 110 111 112 113
	if (dns_tsigrcode_fromtext(&rcode, &token.value.as_textregion)
				!= ISC_R_SUCCESS)
	{
		i = strtol(token.value.as_pointer, &e, 10);
		if (*e != 0)
			return (DNS_R_UNKNOWN);
		if (i < 0 || i > 0xffff)
			return (ISC_R_RANGE);
		rcode = (dns_rcode_t)i;
	}
	RETERR(uint16_tobuffer(rcode, target));
Mark Andrews's avatar
Mark Andrews committed
114

David Lawrence's avatar
David Lawrence committed
115 116 117
	/*
	 * Other Len.
	 */
118 119
	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
				      ISC_FALSE));
Mark Andrews's avatar
Mark Andrews committed
120
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
121
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
122 123
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
124 125 126 127
	/*
	 * Other Data.
	 */
	return (isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
Mark Andrews's avatar
Mark Andrews committed
128 129
}

130
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
131
totext_any_tsig(ARGS_TOTEXT) {
Mark Andrews's avatar
Mark Andrews committed
132 133
	isc_region_t sr;
	isc_region_t sigr;
134
	char buf[sizeof "281474976710655 "];
Mark Andrews's avatar
Mark Andrews committed
135
	char *bufp;
Mark Andrews's avatar
Mark Andrews committed
136 137 138
	dns_name_t name;
	dns_name_t prefix;
	isc_boolean_t sub;
Mark Andrews's avatar
Mark Andrews committed
139
	isc_uint64_t sigtime;
Mark Andrews's avatar
Mark Andrews committed
140 141 142
	unsigned short n;

	REQUIRE(rdata->type == 250);
143
	REQUIRE(rdata->rdclass == 255);
144
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
145 146

	dns_rdata_toregion(rdata, &sr);
David Lawrence's avatar
David Lawrence committed
147 148 149
	/*
	 * Algorithm Name.
	 */
Mark Andrews's avatar
Mark Andrews committed
150 151 152
	dns_name_init(&name, NULL);
	dns_name_init(&prefix, NULL);
	dns_name_fromregion(&name, &sr);
153
	sub = name_prefix(&name, tctx->origin, &prefix);
Mark Andrews's avatar
Mark Andrews committed
154 155 156 157
	RETERR(dns_name_totext(&prefix, sub, target));
	RETERR(str_totext(" ", target));
	isc_region_consume(&sr, name_length(&name));

David Lawrence's avatar
David Lawrence committed
158 159 160
	/*
	 * Time Signed.
	 */
Mark Andrews's avatar
Mark Andrews committed
161 162
	sigtime = ((isc_uint64_t)sr.base[0] << 40) |
		  ((isc_uint64_t)sr.base[1] << 32) |
Mark Andrews's avatar
Mark Andrews committed
163 164 165
		  (sr.base[2] << 24) | (sr.base[3] << 16) |
		  (sr.base[4] << 8) | sr.base[5];
	isc_region_consume(&sr, 6);
Mark Andrews's avatar
Mark Andrews committed
166 167 168 169 170 171 172 173 174
	bufp = &buf[sizeof buf - 1];
	*bufp-- = 0;
	*bufp-- = ' ';
	do {
		*bufp-- = decdigits[sigtime % 10];
		sigtime /= 10;
	} while (sigtime != 0);
	bufp++;
	RETERR(str_totext(bufp, target));
Mark Andrews's avatar
Mark Andrews committed
175

David Lawrence's avatar
David Lawrence committed
176 177 178
	/*
	 * Fudge.
	 */
Mark Andrews's avatar
Mark Andrews committed
179 180 181 182 183
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
	sprintf(buf, "%u ", n);
	RETERR(str_totext(buf, target));

David Lawrence's avatar
David Lawrence committed
184 185 186
	/*
	 * Signature Size.
	 */
Mark Andrews's avatar
Mark Andrews committed
187 188
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
189
	sprintf(buf, "%u", n);
Mark Andrews's avatar
Mark Andrews committed
190 191
	RETERR(str_totext(buf, target));

David Lawrence's avatar
David Lawrence committed
192 193 194
	/*
	 * Signature.
	 */
Mark Andrews's avatar
Mark Andrews committed
195 196 197
	REQUIRE(n <= sr.length);
	sigr = sr;
	sigr.length = n;
198
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
199
		RETERR(str_totext(" (", target));
200
	RETERR(str_totext(tctx->linebreak, target));
201
	RETERR(isc_base64_totext(&sigr, tctx->width - 2,
202
				 tctx->linebreak, target));
203 204 205
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(" ) ", target));
	else
206
		RETERR(str_totext(" ", target));
Mark Andrews's avatar
Mark Andrews committed
207 208
	isc_region_consume(&sr, n);

David Lawrence's avatar
David Lawrence committed
209 210 211
	/*
	 * Original ID.
	 */
Mark Andrews's avatar
Mark Andrews committed
212 213 214 215 216
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
	sprintf(buf, "%u ", n);
	RETERR(str_totext(buf, target));

David Lawrence's avatar
David Lawrence committed
217 218 219
	/*
	 * Error.
	 */
Mark Andrews's avatar
Mark Andrews committed
220 221
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
222 223 224 225 226 227
	if (dns_tsigrcode_totext((dns_rcode_t)n, target) == ISC_R_SUCCESS)
		RETERR(str_totext(" ", target));
	else {
		sprintf(buf, "%u ", n);
		RETERR(str_totext(buf, target));
	}
Mark Andrews's avatar
Mark Andrews committed
228

David Lawrence's avatar
David Lawrence committed
229 230 231
	/*
	 * Other Size.
	 */
Mark Andrews's avatar
Mark Andrews committed
232 233 234 235 236
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
	sprintf(buf, "%u ", n);
	RETERR(str_totext(buf, target));

David Lawrence's avatar
David Lawrence committed
237 238 239
	/*
	 * Other.
	 */
240
	return (isc_base64_totext(&sr, 60, " ", target));
Mark Andrews's avatar
Mark Andrews committed
241 242
}

243
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
244
fromwire_any_tsig(ARGS_FROMWIRE) {
Mark Andrews's avatar
Mark Andrews committed
245 246 247 248 249
	isc_region_t sr;
	dns_name_t name;
	unsigned long n;

	REQUIRE(type == 250);
250
	REQUIRE(rdclass == 255);
251

252 253
	UNUSED(rdclass);

254
	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
Mark Andrews's avatar
Mark Andrews committed
255

David Lawrence's avatar
David Lawrence committed
256 257 258
	/*
	 * Algorithm Name.
	 */
Mark Andrews's avatar
Mark Andrews committed
259 260 261
	dns_name_init(&name, NULL);
	RETERR(dns_name_fromwire(&name, source, dctx, downcase, target));

262
	isc_buffer_activeregion(source, &sr);
David Lawrence's avatar
David Lawrence committed
263 264 265
	/*
	 * Time Signed + Fudge.
	 */
Mark Andrews's avatar
Mark Andrews committed
266
	if (sr.length < 8)
267
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
268 269 270 271
	RETERR(mem_tobuffer(target, sr.base, 8));
	isc_region_consume(&sr, 8);
	isc_buffer_forward(source, 8);

David Lawrence's avatar
David Lawrence committed
272 273 274
	/*
	 * Signature Length + Signature.
	 */
Mark Andrews's avatar
Mark Andrews committed
275
	if (sr.length < 2)
276
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
277 278
	n = uint16_fromregion(&sr);
	if (sr.length < n + 2)
279
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
280 281 282 283
	RETERR(mem_tobuffer(target, sr.base, n + 2));
	isc_region_consume(&sr, n + 2);
	isc_buffer_forward(source, n + 2);

David Lawrence's avatar
David Lawrence committed
284 285 286
	/*
	 * Original ID + Error.
	 */
Mark Andrews's avatar
Mark Andrews committed
287
	if (sr.length < 4)
288
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
289 290 291 292
	RETERR(mem_tobuffer(target, sr.base,  4));
	isc_region_consume(&sr, 4);
	isc_buffer_forward(source, 4);

David Lawrence's avatar
David Lawrence committed
293 294 295
	/*
	 * Other Length + Other.
	 */
Mark Andrews's avatar
Mark Andrews committed
296
	if (sr.length < 2)
297
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
298 299
	n = uint16_fromregion(&sr);
	if (sr.length < n + 2)
300
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
301 302 303 304
	isc_buffer_forward(source, n + 2);
	return (mem_tobuffer(target, sr.base, n + 2));
}

305
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
306
towire_any_tsig(ARGS_TOWIRE) {
Mark Andrews's avatar
Mark Andrews committed
307 308 309 310
	isc_region_t sr;
	dns_name_t name;

	REQUIRE(rdata->type == 250);
311
	REQUIRE(rdata->rdclass == 255);
312
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
313

314
	dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
Mark Andrews's avatar
Mark Andrews committed
315 316 317 318 319 320 321 322
	dns_rdata_toregion(rdata, &sr);
	dns_name_init(&name, NULL);
	dns_name_fromregion(&name, &sr);
	RETERR(dns_name_towire(&name, cctx, target));
	isc_region_consume(&sr, name_length(&name));
	return (mem_tobuffer(target, sr.base, sr.length));
}

323
static inline int
David Lawrence's avatar
David Lawrence committed
324
compare_any_tsig(ARGS_COMPARE) {
Mark Andrews's avatar
Mark Andrews committed
325 326 327 328
	isc_region_t r1;
	isc_region_t r2;
	dns_name_t name1;
	dns_name_t name2;
329
	int order;
Mark Andrews's avatar
Mark Andrews committed
330 331

	REQUIRE(rdata1->type == rdata2->type);
332
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
333
	REQUIRE(rdata1->type == 250);
334
	REQUIRE(rdata1->rdclass == 255);
335 336
	REQUIRE(rdata1->length != 0);
	REQUIRE(rdata2->length != 0);
337

Mark Andrews's avatar
Mark Andrews committed
338 339 340 341 342 343
	dns_rdata_toregion(rdata1, &r1);
	dns_rdata_toregion(rdata2, &r2);
	dns_name_init(&name1, NULL);
	dns_name_init(&name2, NULL);
	dns_name_fromregion(&name1, &r1);
	dns_name_fromregion(&name2, &r2);
344 345 346
	order = dns_name_rdatacompare(&name1, &name2);
	if (order != 0)
		return (order);
Mark Andrews's avatar
Mark Andrews committed
347 348 349 350 351
	isc_region_consume(&r1, name_length(&name1));
	isc_region_consume(&r2, name_length(&name2));
	return (compare_region(&r1, &r2));
}

352
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
353
fromstruct_any_tsig(ARGS_FROMSTRUCT) {
354
	dns_rdata_any_tsig_t *tsig = source;
355
	isc_region_t tr;
Mark Andrews's avatar
Mark Andrews committed
356 357

	REQUIRE(type == 250);
358
	REQUIRE(rdclass == 255);
359 360 361
	REQUIRE(source != NULL);
	REQUIRE(tsig->common.rdclass == rdclass);
	REQUIRE(tsig->common.rdtype == type);
362

363 364
	UNUSED(rdclass);

David Lawrence's avatar
David Lawrence committed
365 366 367
	/*
	 * Algorithm Name.
	 */
368
	RETERR(name_tobuffer(&tsig->algorithm, target));
369

370
	isc_buffer_availableregion(target, &tr);
371
	if (tr.length < 6 + 2 + 2)
372
		return (ISC_R_NOSPACE);
373

David Lawrence's avatar
David Lawrence committed
374 375 376 377 378
	/*
	 * Time Signed: 48 bits.
	 */
	RETERR(uint16_tobuffer((isc_uint16_t)(tsig->timesigned >> 32),
			       target));
Andreas Gustafsson's avatar
Andreas Gustafsson committed
379
	RETERR(uint32_tobuffer((isc_uint32_t)(tsig->timesigned & 0xffffffffU),
380
			       target));
381

David Lawrence's avatar
David Lawrence committed
382 383 384
	/*
	 * Fudge.
	 */
385 386
	RETERR(uint16_tobuffer(tsig->fudge, target));

David Lawrence's avatar
David Lawrence committed
387 388 389
	/*
	 * Signature Size.
	 */
390 391
	RETERR(uint16_tobuffer(tsig->siglen, target));

David Lawrence's avatar
David Lawrence committed
392 393 394
	/*
	 * Signature.
	 */
395
	RETERR(mem_tobuffer(target, tsig->signature, tsig->siglen));
396

397
	isc_buffer_availableregion(target, &tr);
398
	if (tr.length < 2 + 2 + 2)
399
		return (ISC_R_NOSPACE);
400

David Lawrence's avatar
David Lawrence committed
401 402 403
	/*
	 * Original ID.
	 */
404 405
	RETERR(uint16_tobuffer(tsig->originalid, target));

David Lawrence's avatar
David Lawrence committed
406 407 408
	/*
	 * Error.
	 */
409 410
	RETERR(uint16_tobuffer(tsig->error, target));

David Lawrence's avatar
David Lawrence committed
411 412 413
	/*
	 * Other Len.
	 */
414 415
	RETERR(uint16_tobuffer(tsig->otherlen, target));

David Lawrence's avatar
David Lawrence committed
416 417 418
	/*
	 * Other Data.
	 */
419
	return (mem_tobuffer(target, tsig->other, tsig->otherlen));
Mark Andrews's avatar
Mark Andrews committed
420 421
}

422
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
423
tostruct_any_tsig(ARGS_TOSTRUCT) {
424 425 426
	dns_rdata_any_tsig_t *tsig;
	dns_name_t alg;
	isc_region_t sr;
Mark Andrews's avatar
Mark Andrews committed
427 428

	REQUIRE(rdata->type == 250);
429
	REQUIRE(rdata->rdclass == 255);
430
	REQUIRE(rdata->length != 0);
431

432 433 434 435
	tsig = (dns_rdata_any_tsig_t *) target;
	tsig->common.rdclass = rdata->rdclass;
	tsig->common.rdtype = rdata->type;
	ISC_LINK_INIT(&tsig->common, link);
Mark Andrews's avatar
Mark Andrews committed
436

437 438
	dns_rdata_toregion(rdata, &sr);

David Lawrence's avatar
David Lawrence committed
439 440 441
	/*
	 * Algorithm Name.
	 */
442 443
	dns_name_init(&alg, NULL);
	dns_name_fromregion(&alg, &sr);
444
	dns_name_init(&tsig->algorithm, NULL);
Mark Andrews's avatar
Mark Andrews committed
445
	RETERR(name_duporclone(&alg, mctx, &tsig->algorithm));
446

447
	isc_region_consume(&sr, name_length(&tsig->algorithm));
448

David Lawrence's avatar
David Lawrence committed
449 450 451
	/*
	 * Time Signed.
	 */
Mark Andrews's avatar
Mark Andrews committed
452
	INSIST(sr.length >= 6);
453 454 455 456 457 458
	tsig->timesigned = ((isc_uint64_t)sr.base[0] << 40) |
			   ((isc_uint64_t)sr.base[1] << 32) |
			   (sr.base[2] << 24) | (sr.base[3] << 16) |
			   (sr.base[4] << 8) | sr.base[5];
	isc_region_consume(&sr, 6);

David Lawrence's avatar
David Lawrence committed
459 460 461
	/*
	 * Fudge.
	 */
462 463 464
	tsig->fudge = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
465 466 467
	/*
	 * Signature Size.
	 */
468 469 470
	tsig->siglen = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
471 472 473
	/*
	 * Signature.
	 */
Mark Andrews's avatar
Mark Andrews committed
474 475 476 477 478 479 480 481
	INSIST(sr.length >= tsig->siglen);
	if (tsig->siglen != 0) {
		tsig->signature = mem_maybedup(mctx, sr.base, tsig->siglen);
		if (tsig->signature == NULL)
			goto cleanup;
		isc_region_consume(&sr, tsig->siglen);
	} else
		tsig->signature = NULL;
482

David Lawrence's avatar
David Lawrence committed
483 484 485
	/*
	 * Original ID.
	 */
486 487 488
	tsig->originalid = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
489 490 491
	/*
	 * Error.
	 */
492 493 494
	tsig->error = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
495 496 497
	/*
	 * Other Size.
	 */
498 499 500
	tsig->otherlen = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
501 502 503
	/*
	 * Other.
	 */
Mark Andrews's avatar
Mark Andrews committed
504 505 506 507 508 509 510
	INSIST(sr.length == tsig->otherlen);
	if (tsig->otherlen != 0) {
		tsig->other = mem_maybedup(mctx, sr.base, tsig->otherlen);
		if (tsig->other == NULL)
			goto cleanup;
	} else
		tsig->other = NULL;
511

Mark Andrews's avatar
Mark Andrews committed
512
	tsig->mctx = mctx;
513
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
514 515 516

 cleanup:
	if (mctx != NULL)
517
		dns_name_free(&tsig->algorithm, tsig->mctx);
Mark Andrews's avatar
Mark Andrews committed
518 519 520
	if (mctx != NULL && tsig->signature != NULL)
		isc_mem_free(mctx, tsig->signature);
	return (ISC_R_NOMEMORY);
Mark Andrews's avatar
Mark Andrews committed
521
}
522

523
static inline void
David Lawrence's avatar
David Lawrence committed
524
freestruct_any_tsig(ARGS_FREESTRUCT) {
525
	dns_rdata_any_tsig_t *tsig = (dns_rdata_any_tsig_t *) source;
526 527 528 529 530

	REQUIRE(source != NULL);
	REQUIRE(tsig->common.rdclass == 255);
	REQUIRE(tsig->common.rdtype == 250);

Mark Andrews's avatar
Mark Andrews committed
531 532 533
	if (tsig->mctx == NULL)
		return;

534
	dns_name_free(&tsig->algorithm, tsig->mctx);
535
	if (tsig->signature != NULL)
Mark Andrews's avatar
Mark Andrews committed
536
		isc_mem_free(tsig->mctx, tsig->signature);
537
	if (tsig->other != NULL)
Mark Andrews's avatar
Mark Andrews committed
538 539
		isc_mem_free(tsig->mctx, tsig->other);
	tsig->mctx = NULL;
540
}
541

542
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
543
additionaldata_any_tsig(ARGS_ADDLDATA) {
544 545 546
	REQUIRE(rdata->type == 250);
	REQUIRE(rdata->rdclass == 255);

547
	UNUSED(rdata);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
548 549
	UNUSED(add);
	UNUSED(arg);
550

551
	return (ISC_R_SUCCESS);
552 553
}

554
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
555
digest_any_tsig(ARGS_DIGEST) {
Bob Halley's avatar
Bob Halley committed
556 557 558 559

	REQUIRE(rdata->type == 250);
	REQUIRE(rdata->rdclass == 255);

560
	UNUSED(rdata);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
561 562
	UNUSED(digest);
	UNUSED(arg);
Bob Halley's avatar
Bob Halley committed
563

564
	return (ISC_R_NOTIMPLEMENTED);
Bob Halley's avatar
Bob Halley committed
565 566
}

567
#endif	/* RDATA_ANY_255_TSIG_250_C */