"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.11.23/lib/dns/rdata/generic/zonemd_63.c" (7 Sep 2020, 7144 Bytes) of package /linux/misc/dns/bind9/9.11.23/bind-9.11.23.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "zonemd_63.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 /* draft-wessels-zone-digest-05 */
   13 
   14 #ifndef RDATA_GENERIC_ZONEMD_63_C
   15 #define RDATA_GENERIC_ZONEMD_63_C
   16 
   17 #define RRTYPE_ZONEMD_ATTRIBUTES 0
   18 
   19 static inline isc_result_t
   20 fromtext_zonemd(ARGS_FROMTEXT) {
   21     isc_token_t token;
   22     int digest_type, length;
   23 
   24     UNUSED(type);
   25     UNUSED(rdclass);
   26     UNUSED(origin);
   27     UNUSED(options);
   28     UNUSED(callbacks);
   29 
   30     /*
   31      * Serial.
   32      */
   33     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   34                       false));
   35     RETERR(uint32_tobuffer(token.value.as_ulong, target));
   36 
   37     /*
   38      * Digest type.
   39      */
   40     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   41                       false));
   42     digest_type = token.value.as_ulong;
   43     RETERR(uint8_tobuffer(digest_type, target));
   44 
   45     /*
   46      * Reserved.
   47      */
   48     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   49                       false));
   50     RETERR(uint8_tobuffer(token.value.as_ulong, target));
   51 
   52     /*
   53      * Digest.
   54      */
   55     switch (digest_type) {
   56     case DNS_ZONEMD_DIGEST_SHA384:
   57         length = ISC_SHA384_DIGESTLENGTH;
   58         break;
   59     default:
   60         length = -2;
   61         break;
   62     }
   63 
   64     return (isc_hex_tobuffer(lexer, target, length));
   65 }
   66 
   67 static inline isc_result_t
   68 totext_zonemd(ARGS_TOTEXT) {
   69     isc_region_t sr;
   70     char buf[sizeof("0123456789")];
   71     unsigned long num;
   72 
   73     REQUIRE(rdata->length > 6);
   74 
   75     UNUSED(tctx);
   76 
   77     dns_rdata_toregion(rdata, &sr);
   78 
   79     /*
   80      * Serial.
   81      */
   82     num = uint32_fromregion(&sr);
   83     isc_region_consume(&sr, 4);
   84     snprintf(buf, sizeof(buf), "%lu", num);
   85     RETERR(str_totext(buf, target));
   86 
   87     RETERR(str_totext(" ", target));
   88 
   89     /*
   90      * Digest type.
   91      */
   92     num = uint8_fromregion(&sr);
   93     isc_region_consume(&sr, 1);
   94     snprintf(buf, sizeof(buf), "%lu", num);
   95     RETERR(str_totext(buf, target));
   96 
   97     RETERR(str_totext(" ", target));
   98     /*
   99      * Reserved.
  100      */
  101     num = uint8_fromregion(&sr);
  102     isc_region_consume(&sr, 1);
  103     snprintf(buf, sizeof(buf), "%lu", num);
  104     RETERR(str_totext(buf, target));
  105 
  106     /*
  107      * Digest.
  108      */
  109     if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
  110         RETERR(str_totext(" (", target));
  111     RETERR(str_totext(tctx->linebreak, target));
  112     if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) {
  113         if (tctx->width == 0) /* No splitting */
  114             RETERR(isc_hex_totext(&sr, 0, "", target));
  115         else
  116             RETERR(isc_hex_totext(&sr, tctx->width - 2,
  117                           tctx->linebreak, target));
  118     } else {
  119         RETERR(str_totext("[omitted]", target));
  120     }
  121     if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) {
  122         RETERR(str_totext(" )", target));
  123     }
  124     return (ISC_R_SUCCESS);
  125 }
  126 
  127 static inline isc_result_t
  128 fromwire_zonemd(ARGS_FROMWIRE) {
  129     isc_region_t sr;
  130 
  131     UNUSED(type);
  132     UNUSED(rdclass);
  133     UNUSED(dctx);
  134     UNUSED(options);
  135 
  136     isc_buffer_activeregion(source, &sr);
  137 
  138     /*
  139      * If we do not recognize the digest type, only ensure that the digest
  140      * is present at all.
  141      *
  142      * If we do recognize the digest type, ensure that the digest is of the
  143      * correct length.
  144      */
  145     if (sr.length < 7 ||
  146         (sr.base[4] == DNS_ZONEMD_DIGEST_SHA384 &&
  147          sr.length < 6 + ISC_SHA384_DIGESTLENGTH))
  148     {
  149         return (ISC_R_UNEXPECTEDEND);
  150     }
  151 
  152     /*
  153      * Only specify the number of octets to consume if we recognize the
  154      * digest type.
  155      *
  156      * If there is extra data, dns_rdata_fromwire() will detect that.
  157      */
  158     if (sr.base[4] == DNS_ZONEMD_DIGEST_SHA384) {
  159         sr.length = 6 + ISC_SHA384_DIGESTLENGTH;
  160     }
  161 
  162     isc_buffer_forward(source, sr.length);
  163     return (mem_tobuffer(target, sr.base, sr.length));
  164 }
  165 
  166 static inline isc_result_t
  167 towire_zonemd(ARGS_TOWIRE) {
  168     isc_region_t sr;
  169 
  170     REQUIRE(rdata->type == dns_rdatatype_zonemd);
  171     REQUIRE(rdata->length != 0);
  172 
  173     UNUSED(cctx);
  174 
  175     dns_rdata_toregion(rdata, &sr);
  176     return (mem_tobuffer(target, sr.base, sr.length));
  177 }
  178 
  179 static inline int
  180 compare_zonemd(ARGS_COMPARE) {
  181     isc_region_t r1;
  182     isc_region_t r2;
  183 
  184     REQUIRE(rdata1->type == rdata2->type);
  185     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  186     REQUIRE(rdata1->type == dns_rdatatype_zonemd);
  187     REQUIRE(rdata1->length != 0);
  188     REQUIRE(rdata2->length != 0);
  189 
  190     dns_rdata_toregion(rdata1, &r1);
  191     dns_rdata_toregion(rdata2, &r2);
  192     return (isc_region_compare(&r1, &r2));
  193 }
  194 
  195 static inline isc_result_t
  196 fromstruct_zonemd(ARGS_FROMSTRUCT) {
  197     dns_rdata_zonemd_t *zonemd;
  198 
  199     REQUIRE(((dns_rdata_zonemd_t *)source) != NULL);
  200     REQUIRE(((dns_rdata_zonemd_t *)source)->common.rdtype == type);
  201     REQUIRE(((dns_rdata_zonemd_t *)source)->common.rdclass == rdclass);
  202 
  203     zonemd = source;
  204 
  205     UNUSED(type);
  206     UNUSED(rdclass);
  207 
  208     switch (zonemd->digest_type) {
  209     case DNS_ZONEMD_DIGEST_SHA384:
  210         REQUIRE(zonemd->length == ISC_SHA384_DIGESTLENGTH);
  211         break;
  212     }
  213 
  214     RETERR(uint32_tobuffer(zonemd->serial, target));
  215     RETERR(uint8_tobuffer(zonemd->digest_type, target));
  216     RETERR(uint8_tobuffer(zonemd->reserved, target));
  217 
  218     return (mem_tobuffer(target, zonemd->digest, zonemd->length));
  219 }
  220 
  221 static inline isc_result_t
  222 tostruct_zonemd(ARGS_TOSTRUCT) {
  223     dns_rdata_zonemd_t *zonemd;
  224     isc_region_t region;
  225 
  226     REQUIRE(((dns_rdata_zonemd_t *)target) != NULL);
  227     REQUIRE(rdata->type == dns_rdatatype_zonemd);
  228     REQUIRE(rdata->length != 0);
  229 
  230     zonemd = target;
  231 
  232     zonemd->common.rdclass = rdata->rdclass;
  233     zonemd->common.rdtype = rdata->type;
  234     ISC_LINK_INIT(&zonemd->common, link);
  235 
  236     dns_rdata_toregion(rdata, &region);
  237 
  238     zonemd->serial = uint32_fromregion(&region);
  239     isc_region_consume(&region, 4);
  240     zonemd->digest_type = uint8_fromregion(&region);
  241     isc_region_consume(&region, 1);
  242     zonemd->reserved = uint8_fromregion(&region);
  243     isc_region_consume(&region, 1);
  244     zonemd->length = region.length;
  245 
  246     zonemd->digest = mem_maybedup(mctx, region.base, region.length);
  247     if (zonemd->digest == NULL) {
  248         return (ISC_R_NOMEMORY);
  249     }
  250 
  251     zonemd->mctx = mctx;
  252     return (ISC_R_SUCCESS);
  253 }
  254 
  255 static inline void
  256 freestruct_zonemd(ARGS_FREESTRUCT) {
  257     dns_rdata_zonemd_t *zonemd;
  258 
  259     REQUIRE(((dns_rdata_zonemd_t *)source) != NULL);
  260     REQUIRE(((dns_rdata_zonemd_t *)source)->common.rdtype ==
  261         dns_rdatatype_zonemd);
  262 
  263     zonemd = source;
  264 
  265     if (zonemd->mctx == NULL) {
  266         return;
  267     }
  268 
  269     if (zonemd->digest != NULL) {
  270         isc_mem_free(zonemd->mctx, zonemd->digest);
  271     }
  272     zonemd->mctx = NULL;
  273 }
  274 
  275 static inline isc_result_t
  276 additionaldata_zonemd(ARGS_ADDLDATA) {
  277     REQUIRE(rdata->type == dns_rdatatype_zonemd);
  278 
  279     UNUSED(rdata);
  280     UNUSED(add);
  281     UNUSED(arg);
  282 
  283     return (ISC_R_SUCCESS);
  284 }
  285 
  286 static inline isc_result_t
  287 digest_zonemd(ARGS_DIGEST) {
  288     isc_region_t r;
  289 
  290     REQUIRE(rdata->type == dns_rdatatype_zonemd);
  291 
  292     dns_rdata_toregion(rdata, &r);
  293 
  294     return ((digest)(arg, &r));
  295 }
  296 
  297 static inline bool
  298 checkowner_zonemd(ARGS_CHECKOWNER) {
  299     REQUIRE(type == dns_rdatatype_zonemd);
  300 
  301     UNUSED(name);
  302     UNUSED(type);
  303     UNUSED(rdclass);
  304     UNUSED(wildcard);
  305 
  306     return (true);
  307 }
  308 
  309 static inline bool
  310 checknames_zonemd(ARGS_CHECKNAMES) {
  311     REQUIRE(rdata->type == dns_rdatatype_zonemd);
  312 
  313     UNUSED(rdata);
  314     UNUSED(owner);
  315     UNUSED(bad);
  316 
  317     return (true);
  318 }
  319 
  320 static inline int
  321 casecompare_zonemd(ARGS_COMPARE) {
  322     return (compare_zonemd(rdata1, rdata2));
  323 }
  324 
  325 #endif  /* RDATA_GENERIC_ZONEMD_63_C */