tsig_250.c 12.4 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.43 2000/08/01 01:25:04 tale 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
David Lawrence's avatar
David Lawrence committed
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

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

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

David Lawrence's avatar
David Lawrence committed
62
63
64
	/*
	 * Fudge.
	 */
Mark Andrews's avatar
Mark Andrews committed
65
66
	RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
67
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
68
69
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
70
71
72
	/*
	 * Signature Size.
	 */
Mark Andrews's avatar
Mark Andrews committed
73
74
	RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
75
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
76
77
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
78
79
80
81
	/*
	 * Signature.
	 */
	RETERR(isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
Mark Andrews's avatar
Mark Andrews committed
82

David Lawrence's avatar
David Lawrence committed
83
84
85
	/*
	 * Original ID.
	 */
Mark Andrews's avatar
Mark Andrews committed
86
87
	RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
88
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
89
90
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
91
92
93
	/*
	 * Error.
	 */
94
95
96
97
98
99
100
101
102
103
104
105
	RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
	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
106

David Lawrence's avatar
David Lawrence committed
107
108
109
	/*
	 * Other Len.
	 */
Mark Andrews's avatar
Mark Andrews committed
110
111
	RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
	if (token.value.as_ulong > 0xffff)
David Lawrence's avatar
David Lawrence committed
112
		return (ISC_R_RANGE);
Mark Andrews's avatar
Mark Andrews committed
113
114
	RETERR(uint16_tobuffer(token.value.as_ulong, target));

David Lawrence's avatar
David Lawrence committed
115
116
117
118
	/*
	 * Other Data.
	 */
	return (isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
Mark Andrews's avatar
Mark Andrews committed
119
120
}

121
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
122
totext_any_tsig(ARGS_TOTEXT) {
Mark Andrews's avatar
Mark Andrews committed
123
124
	isc_region_t sr;
	isc_region_t sigr;
125
	char buf[sizeof "281474976710655 "];
Mark Andrews's avatar
Mark Andrews committed
126
	char *bufp;
Mark Andrews's avatar
Mark Andrews committed
127
128
129
	dns_name_t name;
	dns_name_t prefix;
	isc_boolean_t sub;
Mark Andrews's avatar
Mark Andrews committed
130
	isc_uint64_t sigtime;
Mark Andrews's avatar
Mark Andrews committed
131
132
133
	unsigned short n;

	REQUIRE(rdata->type == 250);
134
	REQUIRE(rdata->rdclass == 255);
Mark Andrews's avatar
Mark Andrews committed
135
136

	dns_rdata_toregion(rdata, &sr);
David Lawrence's avatar
David Lawrence committed
137
138
139
	/*
	 * Algorithm Name.
	 */
Mark Andrews's avatar
Mark Andrews committed
140
141
142
	dns_name_init(&name, NULL);
	dns_name_init(&prefix, NULL);
	dns_name_fromregion(&name, &sr);
143
	sub = name_prefix(&name, tctx->origin, &prefix);
Mark Andrews's avatar
Mark Andrews committed
144
145
146
147
	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
148
149
150
	/*
	 * Time Signed.
	 */
Mark Andrews's avatar
Mark Andrews committed
151
152
	sigtime = ((isc_uint64_t)sr.base[0] << 40) |
		  ((isc_uint64_t)sr.base[1] << 32) |
Mark Andrews's avatar
Mark Andrews committed
153
154
155
		  (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
156
157
158
159
160
161
162
163
164
	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
165

David Lawrence's avatar
David Lawrence committed
166
167
168
	/*
	 * Fudge.
	 */
Mark Andrews's avatar
Mark Andrews committed
169
170
171
172
173
	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
174
175
176
	/*
	 * Signature Size.
	 */
Mark Andrews's avatar
Mark Andrews committed
177
178
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
179
	sprintf(buf, "%u", n);
Mark Andrews's avatar
Mark Andrews committed
180
181
	RETERR(str_totext(buf, target));

David Lawrence's avatar
David Lawrence committed
182
183
184
	/*
	 * Signature.
	 */
Mark Andrews's avatar
Mark Andrews committed
185
186
187
	REQUIRE(n <= sr.length);
	sigr = sr;
	sigr.length = n;
188
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
189
		RETERR(str_totext(" (", target));
190
	RETERR(str_totext(tctx->linebreak, target));
191
	RETERR(isc_base64_totext(&sigr, tctx->width - 2,
192
				 tctx->linebreak, target));
193
194
195
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(" ) ", target));
	else
196
		RETERR(str_totext(" ", target));
Mark Andrews's avatar
Mark Andrews committed
197
198
	isc_region_consume(&sr, n);

David Lawrence's avatar
David Lawrence committed
199
200
201
	/*
	 * Original ID.
	 */
Mark Andrews's avatar
Mark Andrews committed
202
203
204
205
206
	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
207
208
209
	/*
	 * Error.
	 */
Mark Andrews's avatar
Mark Andrews committed
210
211
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
212
213
214
215
216
217
	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
218

David Lawrence's avatar
David Lawrence committed
219
220
221
	/*
	 * Other Size.
	 */
Mark Andrews's avatar
Mark Andrews committed
222
223
224
225
226
	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
227
228
229
	/*
	 * Other.
	 */
230
	return (isc_base64_totext(&sr, 60, " ", target));
Mark Andrews's avatar
Mark Andrews committed
231
232
}

233
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
234
fromwire_any_tsig(ARGS_FROMWIRE) {
Mark Andrews's avatar
Mark Andrews committed
235
236
237
238
239
	isc_region_t sr;
	dns_name_t name;
	unsigned long n;

	REQUIRE(type == 250);
240
	REQUIRE(rdclass == 255);
241

242
	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
Mark Andrews's avatar
Mark Andrews committed
243

David Lawrence's avatar
David Lawrence committed
244
245
246
	/*
	 * Algorithm Name.
	 */
Mark Andrews's avatar
Mark Andrews committed
247
248
249
	dns_name_init(&name, NULL);
	RETERR(dns_name_fromwire(&name, source, dctx, downcase, target));

250
	isc_buffer_activeregion(source, &sr);
David Lawrence's avatar
David Lawrence committed
251
252
253
	/*
	 * Time Signed + Fudge.
	 */
Mark Andrews's avatar
Mark Andrews committed
254
	if (sr.length < 8)
255
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
256
257
258
259
	RETERR(mem_tobuffer(target, sr.base, 8));
	isc_region_consume(&sr, 8);
	isc_buffer_forward(source, 8);

David Lawrence's avatar
David Lawrence committed
260
261
262
	/*
	 * Signature Length + Signature.
	 */
Mark Andrews's avatar
Mark Andrews committed
263
	if (sr.length < 2)
264
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
265
266
	n = uint16_fromregion(&sr);
	if (sr.length < n + 2)
267
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
268
269
270
271
	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
272
273
274
	/*
	 * Original ID + Error.
	 */
Mark Andrews's avatar
Mark Andrews committed
275
	if (sr.length < 4)
276
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
277
278
279
280
	RETERR(mem_tobuffer(target, sr.base,  4));
	isc_region_consume(&sr, 4);
	isc_buffer_forward(source, 4);

David Lawrence's avatar
David Lawrence committed
281
282
283
	/*
	 * Other Length + Other.
	 */
Mark Andrews's avatar
Mark Andrews committed
284
	if (sr.length < 2)
285
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
286
287
	n = uint16_fromregion(&sr);
	if (sr.length < n + 2)
288
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
289
290
291
292
	isc_buffer_forward(source, n + 2);
	return (mem_tobuffer(target, sr.base, n + 2));
}

293
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
294
towire_any_tsig(ARGS_TOWIRE) {
Mark Andrews's avatar
Mark Andrews committed
295
296
297
298
	isc_region_t sr;
	dns_name_t name;

	REQUIRE(rdata->type == 250);
299
	REQUIRE(rdata->rdclass == 255);
Mark Andrews's avatar
Mark Andrews committed
300

301
	dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
Mark Andrews's avatar
Mark Andrews committed
302
303
304
305
306
307
308
309
	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));
}

310
static inline int
David Lawrence's avatar
David Lawrence committed
311
compare_any_tsig(ARGS_COMPARE) {
Mark Andrews's avatar
Mark Andrews committed
312
313
314
315
	isc_region_t r1;
	isc_region_t r2;
	dns_name_t name1;
	dns_name_t name2;
316
	int order;
Mark Andrews's avatar
Mark Andrews committed
317
318

	REQUIRE(rdata1->type == rdata2->type);
319
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
320
	REQUIRE(rdata1->type == 250);
321
	REQUIRE(rdata1->rdclass == 255);
322

Mark Andrews's avatar
Mark Andrews committed
323
324
325
326
327
328
	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);
329
330
331
	order = dns_name_rdatacompare(&name1, &name2);
	if (order != 0)
		return (order);
Mark Andrews's avatar
Mark Andrews committed
332
333
334
335
336
	isc_region_consume(&r1, name_length(&name1));
	isc_region_consume(&r2, name_length(&name2));
	return (compare_region(&r1, &r2));
}

337
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
338
fromstruct_any_tsig(ARGS_FROMSTRUCT) {
339
	dns_rdata_any_tsig_t *tsig = source;
340
	isc_region_t tr;
Mark Andrews's avatar
Mark Andrews committed
341
342

	REQUIRE(type == 250);
343
	REQUIRE(rdclass == 255);
344
345
346
	REQUIRE(source != NULL);
	REQUIRE(tsig->common.rdclass == rdclass);
	REQUIRE(tsig->common.rdtype == type);
347

David Lawrence's avatar
David Lawrence committed
348
349
350
	/*
	 * Algorithm Name.
	 */
351
	RETERR(name_tobuffer(&tsig->algorithm, target));
352

353
	isc_buffer_availableregion(target, &tr);
354
	if (tr.length < 6 + 2 + 2)
355
		return (ISC_R_NOSPACE);
356

David Lawrence's avatar
David Lawrence committed
357
358
359
360
361
	/*
	 * Time Signed: 48 bits.
	 */
	RETERR(uint16_tobuffer((isc_uint16_t)(tsig->timesigned >> 32),
			       target));
Andreas Gustafsson's avatar
Andreas Gustafsson committed
362
	RETERR(uint32_tobuffer((isc_uint32_t)(tsig->timesigned & 0xffffffffU),
363
			       target));
364

David Lawrence's avatar
David Lawrence committed
365
366
367
	/*
	 * Fudge.
	 */
368
369
	RETERR(uint16_tobuffer(tsig->fudge, target));

David Lawrence's avatar
David Lawrence committed
370
371
372
	/*
	 * Signature Size.
	 */
373
374
	RETERR(uint16_tobuffer(tsig->siglen, target));

David Lawrence's avatar
David Lawrence committed
375
376
377
	/*
	 * Signature.
	 */
378
	RETERR(mem_tobuffer(target, tsig->signature, tsig->siglen));
379

380
	isc_buffer_availableregion(target, &tr);
381
	if (tr.length < 2 + 2 + 2)
382
		return (ISC_R_NOSPACE);
383

David Lawrence's avatar
David Lawrence committed
384
385
386
	/*
	 * Original ID.
	 */
387
388
	RETERR(uint16_tobuffer(tsig->originalid, target));

David Lawrence's avatar
David Lawrence committed
389
390
391
	/*
	 * Error.
	 */
392
393
	RETERR(uint16_tobuffer(tsig->error, target));

David Lawrence's avatar
David Lawrence committed
394
395
396
	/*
	 * Other Len.
	 */
397
398
	RETERR(uint16_tobuffer(tsig->otherlen, target));

David Lawrence's avatar
David Lawrence committed
399
400
401
	/*
	 * Other Data.
	 */
402
	return (mem_tobuffer(target, tsig->other, tsig->otherlen));
Mark Andrews's avatar
Mark Andrews committed
403
404
}

405
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
406
tostruct_any_tsig(ARGS_TOSTRUCT) {
407
408
409
	dns_rdata_any_tsig_t *tsig;
	dns_name_t alg;
	isc_region_t sr;
Mark Andrews's avatar
Mark Andrews committed
410
411

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

414
415
416
417
	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
418

419
420
	dns_rdata_toregion(rdata, &sr);

David Lawrence's avatar
David Lawrence committed
421
422
423
	/*
	 * Algorithm Name.
	 */
424
425
	dns_name_init(&alg, NULL);
	dns_name_fromregion(&alg, &sr);
426
	dns_name_init(&tsig->algorithm, NULL);
Mark Andrews's avatar
Mark Andrews committed
427
	RETERR(name_duporclone(&alg, mctx, &tsig->algorithm));
428

429
	isc_region_consume(&sr, name_length(&tsig->algorithm));
430

David Lawrence's avatar
David Lawrence committed
431
432
433
	/*
	 * Time Signed.
	 */
Mark Andrews's avatar
Mark Andrews committed
434
	INSIST(sr.length >= 6);
435
436
437
438
439
440
	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
441
442
443
	/*
	 * Fudge.
	 */
444
445
446
	tsig->fudge = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
447
448
449
	/*
	 * Signature Size.
	 */
450
451
452
	tsig->siglen = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
453
454
455
	/*
	 * Signature.
	 */
Mark Andrews's avatar
Mark Andrews committed
456
457
458
459
460
461
462
463
	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;
464

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

David Lawrence's avatar
David Lawrence committed
471
472
473
	/*
	 * Error.
	 */
474
475
476
	tsig->error = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
477
478
479
	/*
	 * Other Size.
	 */
480
481
482
	tsig->otherlen = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
483
484
485
	/*
	 * Other.
	 */
Mark Andrews's avatar
Mark Andrews committed
486
487
488
489
490
491
492
	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;
493

Mark Andrews's avatar
Mark Andrews committed
494
	tsig->mctx = mctx;
495
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
496
497
498

 cleanup:
	if (mctx != NULL)
499
		dns_name_free(&tsig->algorithm, tsig->mctx);
Mark Andrews's avatar
Mark Andrews committed
500
501
502
	if (mctx != NULL && tsig->signature != NULL)
		isc_mem_free(mctx, tsig->signature);
	return (ISC_R_NOMEMORY);
Mark Andrews's avatar
Mark Andrews committed
503
}
504

505
static inline void
David Lawrence's avatar
David Lawrence committed
506
freestruct_any_tsig(ARGS_FREESTRUCT) {
507
	dns_rdata_any_tsig_t *tsig = (dns_rdata_any_tsig_t *) source;
508
509
510
511
512

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

Mark Andrews's avatar
Mark Andrews committed
513
514
515
	if (tsig->mctx == NULL)
		return;

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

524
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
525
additionaldata_any_tsig(ARGS_ADDLDATA) {
526
527
528
	REQUIRE(rdata->type == 250);
	REQUIRE(rdata->rdclass == 255);

529
	UNUSED(rdata);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
530
531
	UNUSED(add);
	UNUSED(arg);
532

533
	return (ISC_R_SUCCESS);
534
535
}

536
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
537
digest_any_tsig(ARGS_DIGEST) {
Bob Halley's avatar
Bob Halley committed
538
539
540
541

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

542
	UNUSED(rdata);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
543
544
	UNUSED(digest);
	UNUSED(arg);
Bob Halley's avatar
Bob Halley committed
545

546
	return (ISC_R_NOTIMPLEMENTED);
Bob Halley's avatar
Bob Halley committed
547
548
}

549
#endif	/* RDATA_ANY_255_TSIG_250_C */