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