00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef RDATA_ANY_255_TSIG_250_C
00023 #define RDATA_ANY_255_TSIG_250_C
00024
00025 #define RRTYPE_TSIG_ATTRIBUTES \
00026 (DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_NOTQUESTION)
00027
00028 static inline isc_result_t
00029 fromtext_any_tsig(ARGS_FROMTEXT) {
00030 isc_token_t token;
00031 dns_name_t name;
00032 isc_uint64_t sigtime;
00033 isc_buffer_t buffer;
00034 dns_rcode_t rcode;
00035 long i;
00036 char *e;
00037
00038 REQUIRE(type == 250);
00039 REQUIRE(rdclass == 255);
00040
00041 UNUSED(type);
00042 UNUSED(rdclass);
00043 UNUSED(callbacks);
00044
00045
00046
00047
00048 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00049 ISC_FALSE));
00050 dns_name_init(&name, NULL);
00051 buffer_fromregion(&buffer, &token.value.as_region);
00052 origin = (origin != NULL) ? origin : dns_rootname;
00053 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
00054
00055
00056
00057
00058 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00059 ISC_FALSE));
00060 sigtime = isc_string_touint64(DNS_AS_STR(token), &e, 10);
00061 if (*e != 0)
00062 RETTOK(DNS_R_SYNTAX);
00063 if ((sigtime >> 48) != 0)
00064 RETTOK(ISC_R_RANGE);
00065 RETERR(uint16_tobuffer((isc_uint16_t)(sigtime >> 32), target));
00066 RETERR(uint32_tobuffer((isc_uint32_t)(sigtime & 0xffffffffU), target));
00067
00068
00069
00070
00071 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00072 ISC_FALSE));
00073 if (token.value.as_ulong > 0xffffU)
00074 RETTOK(ISC_R_RANGE);
00075 RETERR(uint16_tobuffer(token.value.as_ulong, target));
00076
00077
00078
00079
00080 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00081 ISC_FALSE));
00082 if (token.value.as_ulong > 0xffffU)
00083 RETTOK(ISC_R_RANGE);
00084 RETERR(uint16_tobuffer(token.value.as_ulong, target));
00085
00086
00087
00088
00089 RETERR(isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
00090
00091
00092
00093
00094 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00095 ISC_FALSE));
00096 if (token.value.as_ulong > 0xffffU)
00097 RETTOK(ISC_R_RANGE);
00098 RETERR(uint16_tobuffer(token.value.as_ulong, target));
00099
00100
00101
00102
00103 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00104 ISC_FALSE));
00105 if (dns_tsigrcode_fromtext(&rcode, &token.value.as_textregion)
00106 != ISC_R_SUCCESS)
00107 {
00108 i = strtol(DNS_AS_STR(token), &e, 10);
00109 if (*e != 0)
00110 RETTOK(DNS_R_UNKNOWN);
00111 if (i < 0 || i > 0xffff)
00112 RETTOK(ISC_R_RANGE);
00113 rcode = (dns_rcode_t)i;
00114 }
00115 RETERR(uint16_tobuffer(rcode, target));
00116
00117
00118
00119
00120 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00121 ISC_FALSE));
00122 if (token.value.as_ulong > 0xffffU)
00123 RETTOK(ISC_R_RANGE);
00124 RETERR(uint16_tobuffer(token.value.as_ulong, target));
00125
00126
00127
00128
00129 return (isc_base64_tobuffer(lexer, target, (int)token.value.as_ulong));
00130 }
00131
00132 static inline isc_result_t
00133 totext_any_tsig(ARGS_TOTEXT) {
00134 isc_region_t sr;
00135 isc_region_t sigr;
00136 char buf[sizeof(" 281474976710655 ")];
00137 char *bufp;
00138 dns_name_t name;
00139 dns_name_t prefix;
00140 isc_boolean_t sub;
00141 isc_uint64_t sigtime;
00142 unsigned short n;
00143
00144 REQUIRE(rdata->type == 250);
00145 REQUIRE(rdata->rdclass == 255);
00146 REQUIRE(rdata->length != 0);
00147
00148 dns_rdata_toregion(rdata, &sr);
00149
00150
00151
00152 dns_name_init(&name, NULL);
00153 dns_name_init(&prefix, NULL);
00154 dns_name_fromregion(&name, &sr);
00155 sub = name_prefix(&name, tctx->origin, &prefix);
00156 RETERR(dns_name_totext(&prefix, sub, target));
00157 RETERR(str_totext(" ", target));
00158 isc_region_consume(&sr, name_length(&name));
00159
00160
00161
00162
00163 sigtime = ((isc_uint64_t)sr.base[0] << 40) |
00164 ((isc_uint64_t)sr.base[1] << 32) |
00165 ((isc_uint64_t)sr.base[2] << 24) |
00166 ((isc_uint64_t)sr.base[3] << 16) |
00167 ((isc_uint64_t)sr.base[4] << 8) |
00168 (isc_uint64_t)sr.base[5];
00169 isc_region_consume(&sr, 6);
00170 bufp = &buf[sizeof(buf) - 1];
00171 *bufp-- = 0;
00172 *bufp-- = ' ';
00173 do {
00174 *bufp-- = decdigits[sigtime % 10];
00175 sigtime /= 10;
00176 } while (sigtime != 0);
00177 bufp++;
00178 RETERR(str_totext(bufp, target));
00179
00180
00181
00182
00183 n = uint16_fromregion(&sr);
00184 isc_region_consume(&sr, 2);
00185 sprintf(buf, "%u ", n);
00186 RETERR(str_totext(buf, target));
00187
00188
00189
00190
00191 n = uint16_fromregion(&sr);
00192 isc_region_consume(&sr, 2);
00193 sprintf(buf, "%u", n);
00194 RETERR(str_totext(buf, target));
00195
00196
00197
00198
00199 REQUIRE(n <= sr.length);
00200 sigr = sr;
00201 sigr.length = n;
00202 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00203 RETERR(str_totext(" (", target));
00204 RETERR(str_totext(tctx->linebreak, target));
00205 if (tctx->width == 0)
00206 RETERR(isc_base64_totext(&sigr, 60, "", target));
00207 else
00208 RETERR(isc_base64_totext(&sigr, tctx->width - 2,
00209 tctx->linebreak, target));
00210 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
00211 RETERR(str_totext(" ) ", target));
00212 else
00213 RETERR(str_totext(" ", target));
00214 isc_region_consume(&sr, n);
00215
00216
00217
00218
00219 n = uint16_fromregion(&sr);
00220 isc_region_consume(&sr, 2);
00221 sprintf(buf, "%u ", n);
00222 RETERR(str_totext(buf, target));
00223
00224
00225
00226
00227 n = uint16_fromregion(&sr);
00228 isc_region_consume(&sr, 2);
00229 RETERR(dns_tsigrcode_totext((dns_rcode_t)n, target));
00230
00231
00232
00233
00234 n = uint16_fromregion(&sr);
00235 isc_region_consume(&sr, 2);
00236 sprintf(buf, " %u ", n);
00237 RETERR(str_totext(buf, target));
00238
00239
00240
00241
00242 if (tctx->width == 0)
00243 return (isc_base64_totext(&sr, 60, "", target));
00244 else
00245 return (isc_base64_totext(&sr, 60, " ", target));
00246 }
00247
00248 static inline isc_result_t
00249 fromwire_any_tsig(ARGS_FROMWIRE) {
00250 isc_region_t sr;
00251 dns_name_t name;
00252 unsigned long n;
00253
00254 REQUIRE(type == 250);
00255 REQUIRE(rdclass == 255);
00256
00257 UNUSED(type);
00258 UNUSED(rdclass);
00259
00260 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
00261
00262
00263
00264
00265 dns_name_init(&name, NULL);
00266 RETERR(dns_name_fromwire(&name, source, dctx, options, target));
00267
00268 isc_buffer_activeregion(source, &sr);
00269
00270
00271
00272 if (sr.length < 8)
00273 return (ISC_R_UNEXPECTEDEND);
00274 RETERR(mem_tobuffer(target, sr.base, 8));
00275 isc_region_consume(&sr, 8);
00276 isc_buffer_forward(source, 8);
00277
00278
00279
00280
00281 if (sr.length < 2)
00282 return (ISC_R_UNEXPECTEDEND);
00283 n = uint16_fromregion(&sr);
00284 if (sr.length < n + 2)
00285 return (ISC_R_UNEXPECTEDEND);
00286 RETERR(mem_tobuffer(target, sr.base, n + 2));
00287 isc_region_consume(&sr, n + 2);
00288 isc_buffer_forward(source, n + 2);
00289
00290
00291
00292
00293 if (sr.length < 4)
00294 return (ISC_R_UNEXPECTEDEND);
00295 RETERR(mem_tobuffer(target, sr.base, 4));
00296 isc_region_consume(&sr, 4);
00297 isc_buffer_forward(source, 4);
00298
00299
00300
00301
00302 if (sr.length < 2)
00303 return (ISC_R_UNEXPECTEDEND);
00304 n = uint16_fromregion(&sr);
00305 if (sr.length < n + 2)
00306 return (ISC_R_UNEXPECTEDEND);
00307 isc_buffer_forward(source, n + 2);
00308 return (mem_tobuffer(target, sr.base, n + 2));
00309 }
00310
00311 static inline isc_result_t
00312 towire_any_tsig(ARGS_TOWIRE) {
00313 isc_region_t sr;
00314 dns_name_t name;
00315 dns_offsets_t offsets;
00316
00317 REQUIRE(rdata->type == 250);
00318 REQUIRE(rdata->rdclass == 255);
00319 REQUIRE(rdata->length != 0);
00320
00321 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
00322 dns_rdata_toregion(rdata, &sr);
00323 dns_name_init(&name, offsets);
00324 dns_name_fromregion(&name, &sr);
00325 RETERR(dns_name_towire(&name, cctx, target));
00326 isc_region_consume(&sr, name_length(&name));
00327 return (mem_tobuffer(target, sr.base, sr.length));
00328 }
00329
00330 static inline int
00331 compare_any_tsig(ARGS_COMPARE) {
00332 isc_region_t r1;
00333 isc_region_t r2;
00334 dns_name_t name1;
00335 dns_name_t name2;
00336 int order;
00337
00338 REQUIRE(rdata1->type == rdata2->type);
00339 REQUIRE(rdata1->rdclass == rdata2->rdclass);
00340 REQUIRE(rdata1->type == 250);
00341 REQUIRE(rdata1->rdclass == 255);
00342 REQUIRE(rdata1->length != 0);
00343 REQUIRE(rdata2->length != 0);
00344
00345 dns_rdata_toregion(rdata1, &r1);
00346 dns_rdata_toregion(rdata2, &r2);
00347 dns_name_init(&name1, NULL);
00348 dns_name_init(&name2, NULL);
00349 dns_name_fromregion(&name1, &r1);
00350 dns_name_fromregion(&name2, &r2);
00351 order = dns_name_rdatacompare(&name1, &name2);
00352 if (order != 0)
00353 return (order);
00354 isc_region_consume(&r1, name_length(&name1));
00355 isc_region_consume(&r2, name_length(&name2));
00356 return (isc_region_compare(&r1, &r2));
00357 }
00358
00359 static inline isc_result_t
00360 fromstruct_any_tsig(ARGS_FROMSTRUCT) {
00361 dns_rdata_any_tsig_t *tsig = source;
00362 isc_region_t tr;
00363
00364 REQUIRE(type == 250);
00365 REQUIRE(rdclass == 255);
00366 REQUIRE(source != NULL);
00367 REQUIRE(tsig->common.rdclass == rdclass);
00368 REQUIRE(tsig->common.rdtype == type);
00369
00370 UNUSED(type);
00371 UNUSED(rdclass);
00372
00373
00374
00375
00376 RETERR(name_tobuffer(&tsig->algorithm, target));
00377
00378 isc_buffer_availableregion(target, &tr);
00379 if (tr.length < 6 + 2 + 2)
00380 return (ISC_R_NOSPACE);
00381
00382
00383
00384
00385 RETERR(uint16_tobuffer((isc_uint16_t)(tsig->timesigned >> 32),
00386 target));
00387 RETERR(uint32_tobuffer((isc_uint32_t)(tsig->timesigned & 0xffffffffU),
00388 target));
00389
00390
00391
00392
00393 RETERR(uint16_tobuffer(tsig->fudge, target));
00394
00395
00396
00397
00398 RETERR(uint16_tobuffer(tsig->siglen, target));
00399
00400
00401
00402
00403 RETERR(mem_tobuffer(target, tsig->signature, tsig->siglen));
00404
00405 isc_buffer_availableregion(target, &tr);
00406 if (tr.length < 2 + 2 + 2)
00407 return (ISC_R_NOSPACE);
00408
00409
00410
00411
00412 RETERR(uint16_tobuffer(tsig->originalid, target));
00413
00414
00415
00416
00417 RETERR(uint16_tobuffer(tsig->error, target));
00418
00419
00420
00421
00422 RETERR(uint16_tobuffer(tsig->otherlen, target));
00423
00424
00425
00426
00427 return (mem_tobuffer(target, tsig->other, tsig->otherlen));
00428 }
00429
00430 static inline isc_result_t
00431 tostruct_any_tsig(ARGS_TOSTRUCT) {
00432 dns_rdata_any_tsig_t *tsig;
00433 dns_name_t alg;
00434 isc_region_t sr;
00435
00436 REQUIRE(rdata->type == 250);
00437 REQUIRE(rdata->rdclass == 255);
00438 REQUIRE(rdata->length != 0);
00439
00440 tsig = (dns_rdata_any_tsig_t *) target;
00441 tsig->common.rdclass = rdata->rdclass;
00442 tsig->common.rdtype = rdata->type;
00443 ISC_LINK_INIT(&tsig->common, link);
00444
00445 dns_rdata_toregion(rdata, &sr);
00446
00447
00448
00449
00450 dns_name_init(&alg, NULL);
00451 dns_name_fromregion(&alg, &sr);
00452 dns_name_init(&tsig->algorithm, NULL);
00453 RETERR(name_duporclone(&alg, mctx, &tsig->algorithm));
00454
00455 isc_region_consume(&sr, name_length(&tsig->algorithm));
00456
00457
00458
00459
00460 INSIST(sr.length >= 6);
00461 tsig->timesigned = ((isc_uint64_t)sr.base[0] << 40) |
00462 ((isc_uint64_t)sr.base[1] << 32) |
00463 ((isc_uint64_t)sr.base[2] << 24) |
00464 ((isc_uint64_t)sr.base[3] << 16) |
00465 ((isc_uint64_t)sr.base[4] << 8) |
00466 (isc_uint64_t)sr.base[5];
00467 isc_region_consume(&sr, 6);
00468
00469
00470
00471
00472 tsig->fudge = uint16_fromregion(&sr);
00473 isc_region_consume(&sr, 2);
00474
00475
00476
00477
00478 tsig->siglen = uint16_fromregion(&sr);
00479 isc_region_consume(&sr, 2);
00480
00481
00482
00483
00484 INSIST(sr.length >= tsig->siglen);
00485 tsig->signature = mem_maybedup(mctx, sr.base, tsig->siglen);
00486 if (tsig->signature == NULL)
00487 goto cleanup;
00488 isc_region_consume(&sr, tsig->siglen);
00489
00490
00491
00492
00493 tsig->originalid = uint16_fromregion(&sr);
00494 isc_region_consume(&sr, 2);
00495
00496
00497
00498
00499 tsig->error = uint16_fromregion(&sr);
00500 isc_region_consume(&sr, 2);
00501
00502
00503
00504
00505 tsig->otherlen = uint16_fromregion(&sr);
00506 isc_region_consume(&sr, 2);
00507
00508
00509
00510
00511 INSIST(sr.length == tsig->otherlen);
00512 tsig->other = mem_maybedup(mctx, sr.base, tsig->otherlen);
00513 if (tsig->other == NULL)
00514 goto cleanup;
00515
00516 tsig->mctx = mctx;
00517 return (ISC_R_SUCCESS);
00518
00519 cleanup:
00520 if (mctx != NULL)
00521 dns_name_free(&tsig->algorithm, tsig->mctx);
00522 if (mctx != NULL && tsig->signature != NULL)
00523 isc_mem_free(mctx, tsig->signature);
00524 return (ISC_R_NOMEMORY);
00525 }
00526
00527 static inline void
00528 freestruct_any_tsig(ARGS_FREESTRUCT) {
00529 dns_rdata_any_tsig_t *tsig = (dns_rdata_any_tsig_t *) source;
00530
00531 REQUIRE(source != NULL);
00532 REQUIRE(tsig->common.rdclass == 255);
00533 REQUIRE(tsig->common.rdtype == 250);
00534
00535 if (tsig->mctx == NULL)
00536 return;
00537
00538 dns_name_free(&tsig->algorithm, tsig->mctx);
00539 if (tsig->signature != NULL)
00540 isc_mem_free(tsig->mctx, tsig->signature);
00541 if (tsig->other != NULL)
00542 isc_mem_free(tsig->mctx, tsig->other);
00543 tsig->mctx = NULL;
00544 }
00545
00546 static inline isc_result_t
00547 additionaldata_any_tsig(ARGS_ADDLDATA) {
00548 REQUIRE(rdata->type == 250);
00549 REQUIRE(rdata->rdclass == 255);
00550
00551 UNUSED(rdata);
00552 UNUSED(add);
00553 UNUSED(arg);
00554
00555 return (ISC_R_SUCCESS);
00556 }
00557
00558 static inline isc_result_t
00559 digest_any_tsig(ARGS_DIGEST) {
00560
00561 REQUIRE(rdata->type == 250);
00562 REQUIRE(rdata->rdclass == 255);
00563
00564 UNUSED(rdata);
00565 UNUSED(digest);
00566 UNUSED(arg);
00567
00568 return (ISC_R_NOTIMPLEMENTED);
00569 }
00570
00571 static inline isc_boolean_t
00572 checkowner_any_tsig(ARGS_CHECKOWNER) {
00573
00574 REQUIRE(type == 250);
00575 REQUIRE(rdclass == 255);
00576
00577 UNUSED(name);
00578 UNUSED(type);
00579 UNUSED(rdclass);
00580 UNUSED(wildcard);
00581
00582 return (ISC_TRUE);
00583 }
00584
00585 static inline isc_boolean_t
00586 checknames_any_tsig(ARGS_CHECKNAMES) {
00587
00588 REQUIRE(rdata->type == 250);
00589 REQUIRE(rdata->rdclass == 250);
00590
00591 UNUSED(rdata);
00592 UNUSED(owner);
00593 UNUSED(bad);
00594
00595 return (ISC_TRUE);
00596 }
00597
00598 static inline int
00599 casecompare_any_tsig(ARGS_COMPARE) {
00600 return (compare_any_tsig(rdata1, rdata2));
00601 }
00602
00603 #endif