tsig_250.c 13.5 KB
Newer Older
Mark Andrews's avatar
Mark Andrews committed
1
/*
Automatic Updater's avatar
Automatic Updater committed
2
 * Copyright (C) 2004, 2005, 2007, 2009, 2011  Internet Systems Consortium, Inc. ("ISC")
Mark Andrews's avatar
Mark Andrews committed
3
 * Copyright (C) 1999-2003  Internet Software Consortium.
4
 *
Automatic Updater's avatar
Automatic Updater committed
5
 * Permission to use, copy, modify, and/or distribute this software for any
Mark Andrews's avatar
Mark Andrews committed
6
7
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
8
 *
Mark Andrews's avatar
Mark Andrews committed
9
10
11
12
13
14
15
 * 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.
Mark Andrews's avatar
Mark Andrews committed
16
17
 */

Mark Andrews's avatar
Mark Andrews committed
18
/* $Id$ */
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
	UNUSED(type);
42
	UNUSED(rdclass);
43
	UNUSED(callbacks);
44

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

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

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

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

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

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

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

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

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

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

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

	dns_rdata_toregion(rdata, &sr);
David Lawrence's avatar
David Lawrence committed
149
150
151
	/*
	 * Algorithm Name.
	 */
Mark Andrews's avatar
Mark Andrews committed
152
153
154
	dns_name_init(&name, NULL);
	dns_name_init(&prefix, NULL);
	dns_name_fromregion(&name, &sr);
155
	sub = name_prefix(&name, tctx->origin, &prefix);
Mark Andrews's avatar
Mark Andrews committed
156
157
158
159
	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
160
161
162
	/*
	 * Time Signed.
	 */
Mark Andrews's avatar
Mark Andrews committed
163
164
	sigtime = ((isc_uint64_t)sr.base[0] << 40) |
		  ((isc_uint64_t)sr.base[1] << 32) |
Mark Andrews's avatar
Mark Andrews committed
165
166
167
168
		  ((isc_uint64_t)sr.base[2] << 24) |
		  ((isc_uint64_t)sr.base[3] << 16) |
		  ((isc_uint64_t)sr.base[4] << 8) |
		  (isc_uint64_t)sr.base[5];
Mark Andrews's avatar
Mark Andrews committed
169
	isc_region_consume(&sr, 6);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
170
	bufp = &buf[sizeof(buf) - 1];
Mark Andrews's avatar
Mark Andrews committed
171
172
173
174
175
176
177
178
	*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
179

David Lawrence's avatar
David Lawrence committed
180
181
182
	/*
	 * Fudge.
	 */
Mark Andrews's avatar
Mark Andrews committed
183
184
185
186
187
	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
188
189
190
	/*
	 * Signature Size.
	 */
Mark Andrews's avatar
Mark Andrews committed
191
192
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
193
	sprintf(buf, "%u", n);
Mark Andrews's avatar
Mark Andrews committed
194
195
	RETERR(str_totext(buf, target));

David Lawrence's avatar
David Lawrence committed
196
197
198
	/*
	 * Signature.
	 */
Mark Andrews's avatar
Mark Andrews committed
199
200
201
	REQUIRE(n <= sr.length);
	sigr = sr;
	sigr.length = n;
202
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
203
		RETERR(str_totext(" (", target));
204
	RETERR(str_totext(tctx->linebreak, target));
205
206
207
208
209
	if (tctx->width == 0)   /* No splitting */
		RETERR(isc_base64_totext(&sigr, 60, "", target));
	else
		RETERR(isc_base64_totext(&sigr, tctx->width - 2,
					 tctx->linebreak, target));
210
211
212
	if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
		RETERR(str_totext(" ) ", target));
	else
213
		RETERR(str_totext(" ", target));
Mark Andrews's avatar
Mark Andrews committed
214
215
	isc_region_consume(&sr, n);

David Lawrence's avatar
David Lawrence committed
216
217
218
	/*
	 * Original ID.
	 */
Mark Andrews's avatar
Mark Andrews committed
219
220
221
222
223
	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
224
225
226
	/*
	 * Error.
	 */
Mark Andrews's avatar
Mark Andrews committed
227
228
	n = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);
229
230
231
232
233
234
	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
235

David Lawrence's avatar
David Lawrence committed
236
237
238
	/*
	 * Other Size.
	 */
Mark Andrews's avatar
Mark Andrews committed
239
240
241
242
243
	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
244
245
246
	/*
	 * Other.
	 */
247
248
249
250
	if (tctx->width == 0)   /* No splitting */
		return (isc_base64_totext(&sr, 60, "", target));
	else
		return (isc_base64_totext(&sr, 60, " ", target));
Mark Andrews's avatar
Mark Andrews committed
251
252
}

253
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
254
fromwire_any_tsig(ARGS_FROMWIRE) {
Mark Andrews's avatar
Mark Andrews committed
255
256
257
258
259
	isc_region_t sr;
	dns_name_t name;
	unsigned long n;

	REQUIRE(type == 250);
260
	REQUIRE(rdclass == 255);
261

262
	UNUSED(type);
263
264
	UNUSED(rdclass);

265
	dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
Mark Andrews's avatar
Mark Andrews committed
266

David Lawrence's avatar
David Lawrence committed
267
268
269
	/*
	 * Algorithm Name.
	 */
Mark Andrews's avatar
Mark Andrews committed
270
	dns_name_init(&name, NULL);
271
	RETERR(dns_name_fromwire(&name, source, dctx, options, target));
Mark Andrews's avatar
Mark Andrews committed
272

273
	isc_buffer_activeregion(source, &sr);
David Lawrence's avatar
David Lawrence committed
274
275
276
	/*
	 * Time Signed + Fudge.
	 */
Mark Andrews's avatar
Mark Andrews committed
277
	if (sr.length < 8)
278
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
279
280
281
282
	RETERR(mem_tobuffer(target, sr.base, 8));
	isc_region_consume(&sr, 8);
	isc_buffer_forward(source, 8);

David Lawrence's avatar
David Lawrence committed
283
284
285
	/*
	 * Signature Length + Signature.
	 */
Mark Andrews's avatar
Mark Andrews committed
286
	if (sr.length < 2)
287
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
288
289
	n = uint16_fromregion(&sr);
	if (sr.length < n + 2)
290
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
291
292
293
294
	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
295
296
297
	/*
	 * Original ID + Error.
	 */
Mark Andrews's avatar
Mark Andrews committed
298
	if (sr.length < 4)
299
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
300
301
302
303
	RETERR(mem_tobuffer(target, sr.base,  4));
	isc_region_consume(&sr, 4);
	isc_buffer_forward(source, 4);

David Lawrence's avatar
David Lawrence committed
304
305
306
	/*
	 * Other Length + Other.
	 */
Mark Andrews's avatar
Mark Andrews committed
307
	if (sr.length < 2)
308
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
309
310
	n = uint16_fromregion(&sr);
	if (sr.length < n + 2)
311
		return (ISC_R_UNEXPECTEDEND);
Mark Andrews's avatar
Mark Andrews committed
312
313
314
315
	isc_buffer_forward(source, n + 2);
	return (mem_tobuffer(target, sr.base, n + 2));
}

316
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
317
towire_any_tsig(ARGS_TOWIRE) {
Mark Andrews's avatar
Mark Andrews committed
318
319
	isc_region_t sr;
	dns_name_t name;
320
	dns_offsets_t offsets;
Mark Andrews's avatar
Mark Andrews committed
321
322

	REQUIRE(rdata->type == 250);
323
	REQUIRE(rdata->rdclass == 255);
324
	REQUIRE(rdata->length != 0);
Mark Andrews's avatar
Mark Andrews committed
325

326
	dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
Mark Andrews's avatar
Mark Andrews committed
327
	dns_rdata_toregion(rdata, &sr);
328
	dns_name_init(&name, offsets);
Mark Andrews's avatar
Mark Andrews committed
329
330
331
332
333
334
	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));
}

335
static inline int
David Lawrence's avatar
David Lawrence committed
336
compare_any_tsig(ARGS_COMPARE) {
Mark Andrews's avatar
Mark Andrews committed
337
338
339
340
	isc_region_t r1;
	isc_region_t r2;
	dns_name_t name1;
	dns_name_t name2;
341
	int order;
Mark Andrews's avatar
Mark Andrews committed
342
343

	REQUIRE(rdata1->type == rdata2->type);
344
	REQUIRE(rdata1->rdclass == rdata2->rdclass);
Mark Andrews's avatar
Mark Andrews committed
345
	REQUIRE(rdata1->type == 250);
346
	REQUIRE(rdata1->rdclass == 255);
347
348
	REQUIRE(rdata1->length != 0);
	REQUIRE(rdata2->length != 0);
349

Mark Andrews's avatar
Mark Andrews committed
350
351
352
353
354
355
	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);
356
357
358
	order = dns_name_rdatacompare(&name1, &name2);
	if (order != 0)
		return (order);
Mark Andrews's avatar
Mark Andrews committed
359
360
	isc_region_consume(&r1, name_length(&name1));
	isc_region_consume(&r2, name_length(&name2));
361
	return (isc_region_compare(&r1, &r2));
Mark Andrews's avatar
Mark Andrews committed
362
363
}

364
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
365
fromstruct_any_tsig(ARGS_FROMSTRUCT) {
366
	dns_rdata_any_tsig_t *tsig = source;
367
	isc_region_t tr;
Mark Andrews's avatar
Mark Andrews committed
368
369

	REQUIRE(type == 250);
370
	REQUIRE(rdclass == 255);
371
372
373
	REQUIRE(source != NULL);
	REQUIRE(tsig->common.rdclass == rdclass);
	REQUIRE(tsig->common.rdtype == type);
374

375
	UNUSED(type);
376
377
	UNUSED(rdclass);

David Lawrence's avatar
David Lawrence committed
378
379
380
	/*
	 * Algorithm Name.
	 */
381
	RETERR(name_tobuffer(&tsig->algorithm, target));
382

383
	isc_buffer_availableregion(target, &tr);
384
	if (tr.length < 6 + 2 + 2)
385
		return (ISC_R_NOSPACE);
386

David Lawrence's avatar
David Lawrence committed
387
388
389
390
391
	/*
	 * Time Signed: 48 bits.
	 */
	RETERR(uint16_tobuffer((isc_uint16_t)(tsig->timesigned >> 32),
			       target));
Andreas Gustafsson's avatar
Andreas Gustafsson committed
392
	RETERR(uint32_tobuffer((isc_uint32_t)(tsig->timesigned & 0xffffffffU),
393
			       target));
394

David Lawrence's avatar
David Lawrence committed
395
396
397
	/*
	 * Fudge.
	 */
398
399
	RETERR(uint16_tobuffer(tsig->fudge, target));

David Lawrence's avatar
David Lawrence committed
400
401
402
	/*
	 * Signature Size.
	 */
403
404
	RETERR(uint16_tobuffer(tsig->siglen, target));

David Lawrence's avatar
David Lawrence committed
405
406
407
	/*
	 * Signature.
	 */
408
	RETERR(mem_tobuffer(target, tsig->signature, tsig->siglen));
409

410
	isc_buffer_availableregion(target, &tr);
411
	if (tr.length < 2 + 2 + 2)
412
		return (ISC_R_NOSPACE);
413

David Lawrence's avatar
David Lawrence committed
414
415
416
	/*
	 * Original ID.
	 */
417
418
	RETERR(uint16_tobuffer(tsig->originalid, target));

David Lawrence's avatar
David Lawrence committed
419
420
421
	/*
	 * Error.
	 */
422
423
	RETERR(uint16_tobuffer(tsig->error, target));

David Lawrence's avatar
David Lawrence committed
424
425
426
	/*
	 * Other Len.
	 */
427
428
	RETERR(uint16_tobuffer(tsig->otherlen, target));

David Lawrence's avatar
David Lawrence committed
429
430
431
	/*
	 * Other Data.
	 */
432
	return (mem_tobuffer(target, tsig->other, tsig->otherlen));
Mark Andrews's avatar
Mark Andrews committed
433
434
}

435
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
436
tostruct_any_tsig(ARGS_TOSTRUCT) {
437
438
439
	dns_rdata_any_tsig_t *tsig;
	dns_name_t alg;
	isc_region_t sr;
Mark Andrews's avatar
Mark Andrews committed
440
441

	REQUIRE(rdata->type == 250);
442
	REQUIRE(rdata->rdclass == 255);
443
	REQUIRE(rdata->length != 0);
444

445
446
447
448
	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
449

450
451
	dns_rdata_toregion(rdata, &sr);

David Lawrence's avatar
David Lawrence committed
452
453
454
	/*
	 * Algorithm Name.
	 */
455
456
	dns_name_init(&alg, NULL);
	dns_name_fromregion(&alg, &sr);
457
	dns_name_init(&tsig->algorithm, NULL);
Mark Andrews's avatar
Mark Andrews committed
458
	RETERR(name_duporclone(&alg, mctx, &tsig->algorithm));
459

460
	isc_region_consume(&sr, name_length(&tsig->algorithm));
461

David Lawrence's avatar
David Lawrence committed
462
463
464
	/*
	 * Time Signed.
	 */
Mark Andrews's avatar
Mark Andrews committed
465
	INSIST(sr.length >= 6);
466
467
	tsig->timesigned = ((isc_uint64_t)sr.base[0] << 40) |
			   ((isc_uint64_t)sr.base[1] << 32) |
Mark Andrews's avatar
Mark Andrews committed
468
469
470
471
			   ((isc_uint64_t)sr.base[2] << 24) |
			   ((isc_uint64_t)sr.base[3] << 16) |
			   ((isc_uint64_t)sr.base[4] << 8) |
			   (isc_uint64_t)sr.base[5];
472
473
	isc_region_consume(&sr, 6);

David Lawrence's avatar
David Lawrence committed
474
475
476
	/*
	 * Fudge.
	 */
477
478
479
	tsig->fudge = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
480
481
482
	/*
	 * Signature Size.
	 */
483
484
485
	tsig->siglen = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
486
487
488
	/*
	 * Signature.
	 */
Mark Andrews's avatar
Mark Andrews committed
489
	INSIST(sr.length >= tsig->siglen);
490
491
492
493
	tsig->signature = mem_maybedup(mctx, sr.base, tsig->siglen);
	if (tsig->signature == NULL)
		goto cleanup;
	isc_region_consume(&sr, tsig->siglen);
494

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

David Lawrence's avatar
David Lawrence committed
501
502
503
	/*
	 * Error.
	 */
504
505
506
	tsig->error = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
507
508
509
	/*
	 * Other Size.
	 */
510
511
512
	tsig->otherlen = uint16_fromregion(&sr);
	isc_region_consume(&sr, 2);

David Lawrence's avatar
David Lawrence committed
513
514
515
	/*
	 * Other.
	 */
Mark Andrews's avatar
Mark Andrews committed
516
	INSIST(sr.length == tsig->otherlen);
517
518
519
	tsig->other = mem_maybedup(mctx, sr.base, tsig->otherlen);
	if (tsig->other == NULL)
		goto cleanup;
520

Mark Andrews's avatar
Mark Andrews committed
521
	tsig->mctx = mctx;
522
	return (ISC_R_SUCCESS);
Mark Andrews's avatar
Mark Andrews committed
523
524
525

 cleanup:
	if (mctx != NULL)
526
		dns_name_free(&tsig->algorithm, tsig->mctx);
Mark Andrews's avatar
Mark Andrews committed
527
528
529
	if (mctx != NULL && tsig->signature != NULL)
		isc_mem_free(mctx, tsig->signature);
	return (ISC_R_NOMEMORY);
Mark Andrews's avatar
Mark Andrews committed
530
}
531

532
static inline void
David Lawrence's avatar
David Lawrence committed
533
freestruct_any_tsig(ARGS_FREESTRUCT) {
534
	dns_rdata_any_tsig_t *tsig = (dns_rdata_any_tsig_t *) source;
535
536
537
538
539

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

Mark Andrews's avatar
Mark Andrews committed
540
541
542
	if (tsig->mctx == NULL)
		return;

543
	dns_name_free(&tsig->algorithm, tsig->mctx);
544
	if (tsig->signature != NULL)
Mark Andrews's avatar
Mark Andrews committed
545
		isc_mem_free(tsig->mctx, tsig->signature);
546
	if (tsig->other != NULL)
Mark Andrews's avatar
Mark Andrews committed
547
548
		isc_mem_free(tsig->mctx, tsig->other);
	tsig->mctx = NULL;
549
}
550

551
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
552
additionaldata_any_tsig(ARGS_ADDLDATA) {
553
554
555
	REQUIRE(rdata->type == 250);
	REQUIRE(rdata->rdclass == 255);

556
	UNUSED(rdata);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
557
558
	UNUSED(add);
	UNUSED(arg);
559

560
	return (ISC_R_SUCCESS);
561
562
}

563
static inline isc_result_t
David Lawrence's avatar
David Lawrence committed
564
digest_any_tsig(ARGS_DIGEST) {
Bob Halley's avatar
Bob Halley committed
565
566
567
568

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

569
	UNUSED(rdata);
Andreas Gustafsson's avatar
Andreas Gustafsson committed
570
571
	UNUSED(digest);
	UNUSED(arg);
Bob Halley's avatar
Bob Halley committed
572

573
	return (ISC_R_NOTIMPLEMENTED);
Bob Halley's avatar
Bob Halley committed
574
575
}

576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
static inline isc_boolean_t
checkowner_any_tsig(ARGS_CHECKOWNER) {

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

	UNUSED(name);
	UNUSED(type);
	UNUSED(rdclass);
	UNUSED(wildcard);

	return (ISC_TRUE);
}

static inline isc_boolean_t
checknames_any_tsig(ARGS_CHECKNAMES) {

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

	UNUSED(rdata);
	UNUSED(owner);
	UNUSED(bad);

	return (ISC_TRUE);
}

603
604
605
606
607
static inline int
casecompare_any_tsig(ARGS_COMPARE) {
	return (compare_any_tsig(rdata1, rdata2));
}

608
#endif	/* RDATA_ANY_255_TSIG_250_C */