caa_257.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2014, 2015  Internet Systems Consortium, Inc. ("ISC")
00003  *
00004  * Permission to use, copy, modify, and/or distribute this software for any
00005  * purpose with or without fee is hereby granted, provided that the above
00006  * copyright notice and this permission notice appear in all copies.
00007  *
00008  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00009  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00010  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00011  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00012  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00013  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00014  * PERFORMANCE OF THIS SOFTWARE.
00015  */
00016 
00017 #ifndef GENERIC_CAA_257_C
00018 #define GENERIC_CAA_257_C 1
00019 
00020 #define RRTYPE_CAA_ATTRIBUTES (0)
00021 
00022 static unsigned char const alphanumeric[256] = {
00023         /* 0x00-0x0f */ 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
00024         /* 0x10-0x1f */ 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
00025         /* 0x20-0x2f */ 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
00026         /* 0x30-0x3f */ 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 0, 0, 0, 0, 0, 0,
00027         /* 0x40-0x4f */ 0, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,
00028         /* 0x50-0x5f */ 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 0, 0, 0, 0, 0,
00029         /* 0x60-0x6f */ 0, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,
00030         /* 0x70-0x7f */ 1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 0, 0, 0, 0, 0,
00031         /* 0x80-0x8f */ 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
00032         /* 0x90-0x9f */ 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
00033         /* 0xa0-0xaf */ 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
00034         /* 0xb0-0xbf */ 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
00035         /* 0xc0-0xcf */ 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
00036         /* 0xd0-0xdf */ 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
00037         /* 0xe0-0xef */ 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
00038         /* 0xf0-0xff */ 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
00039 };
00040 
00041 static inline isc_result_t
00042 fromtext_caa(ARGS_FROMTEXT) {
00043         isc_token_t token;
00044         isc_textregion_t tr;
00045         isc_uint8_t flags;
00046         unsigned int i;
00047 
00048         REQUIRE(type == 257);
00049 
00050         UNUSED(type);
00051         UNUSED(rdclass);
00052         UNUSED(origin);
00053         UNUSED(options);
00054         UNUSED(callbacks);
00055 
00056         /* Flags. */
00057         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00058                                       ISC_FALSE));
00059         if (token.value.as_ulong > 255U)
00060                 RETTOK(ISC_R_RANGE);
00061         flags = token.value.as_ulong & 255U;
00062         RETERR(uint8_tobuffer(flags, target));
00063 
00064         /*
00065          * Tag
00066          */
00067         RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00068                                       ISC_FALSE));
00069         tr = token.value.as_textregion;
00070         for (i = 0; i < tr.length; i++)
00071                 if (!alphanumeric[(unsigned char) tr.base[i]])
00072                         RETTOK(DNS_R_SYNTAX);
00073         RETERR(uint8_tobuffer(tr.length, target));
00074         RETERR(mem_tobuffer(target, tr.base, tr.length));
00075 
00076         /*
00077          * Value
00078          */
00079         RETERR(isc_lex_getmastertoken(lexer, &token,
00080                                       isc_tokentype_qstring, ISC_FALSE));
00081         if (token.type != isc_tokentype_qstring &&
00082             token.type != isc_tokentype_string)
00083                 RETERR(DNS_R_SYNTAX);
00084         RETERR(multitxt_fromtext(&token.value.as_textregion, target));
00085         return (ISC_R_SUCCESS);
00086 }
00087 
00088 static inline isc_result_t
00089 totext_caa(ARGS_TOTEXT) {
00090         isc_region_t region;
00091         isc_uint8_t flags;
00092         char buf[256];
00093 
00094         UNUSED(tctx);
00095 
00096         REQUIRE(rdata->type == 257);
00097         REQUIRE(rdata->length >= 3U);
00098         REQUIRE(rdata->data != NULL);
00099 
00100         dns_rdata_toregion(rdata, &region);
00101 
00102         /*
00103          * Flags
00104          */
00105         flags = uint8_consume_fromregion(&region);
00106         sprintf(buf, "%u ", flags);
00107         RETERR(str_totext(buf, target));
00108 
00109         /*
00110          * Tag
00111          */
00112         RETERR(txt_totext(&region, ISC_FALSE, target));
00113         RETERR(str_totext(" ", target));
00114 
00115         /*
00116          * Value
00117          */
00118         RETERR(multitxt_totext(&region, target));
00119         return (ISC_R_SUCCESS);
00120 }
00121 
00122 static inline isc_result_t
00123 fromwire_caa(ARGS_FROMWIRE) {
00124         isc_region_t sr;
00125         unsigned int len, i;
00126 
00127         REQUIRE(type == 257);
00128 
00129         UNUSED(type);
00130         UNUSED(rdclass);
00131         UNUSED(dctx);
00132         UNUSED(options);
00133 
00134         /*
00135          * Flags
00136          */
00137         isc_buffer_activeregion(source, &sr);
00138         if (sr.length < 2)
00139                 return (ISC_R_UNEXPECTEDEND);
00140 
00141         /*
00142          * Flags, tag length
00143          */
00144         RETERR(mem_tobuffer(target, sr.base, 2));
00145         len = sr.base[1];
00146         isc_region_consume(&sr, 2);
00147         isc_buffer_forward(source, 2);
00148 
00149         /*
00150          * Zero length tag fields are illegal.
00151          */
00152         if (sr.length < len || len == 0)
00153                 RETERR(DNS_R_FORMERR);
00154 
00155         /* Check the Tag's value */
00156         for (i = 0; i < len; i++)
00157                 if (!alphanumeric[sr.base[i]])
00158                         RETERR(DNS_R_FORMERR);
00159         /*
00160          * Tag + Value
00161          */
00162         isc_buffer_forward(source, sr.length);
00163         return (mem_tobuffer(target, sr.base, sr.length));
00164 }
00165 
00166 static inline isc_result_t
00167 towire_caa(ARGS_TOWIRE) {
00168         isc_region_t region;
00169 
00170         REQUIRE(rdata->type == 257);
00171         REQUIRE(rdata->length >= 3U);
00172         REQUIRE(rdata->data != NULL);
00173 
00174         UNUSED(cctx);
00175 
00176         dns_rdata_toregion(rdata, &region);
00177         return (mem_tobuffer(target, region.base, region.length));
00178 }
00179 
00180 static inline int
00181 compare_caa(ARGS_COMPARE) {
00182         isc_region_t r1, r2;
00183 
00184         REQUIRE(rdata1->type == rdata2->type);
00185         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00186         REQUIRE(rdata1->type == 257);
00187         REQUIRE(rdata1->length >= 3U);
00188         REQUIRE(rdata2->length >= 3U);
00189         REQUIRE(rdata1->data != NULL);
00190         REQUIRE(rdata2->data != NULL);
00191 
00192         dns_rdata_toregion(rdata1, &r1);
00193         dns_rdata_toregion(rdata2, &r2);
00194         return (isc_region_compare(&r1, &r2));
00195 }
00196 
00197 static inline isc_result_t
00198 fromstruct_caa(ARGS_FROMSTRUCT) {
00199         dns_rdata_caa_t *caa = source;
00200         isc_region_t region;
00201         unsigned int i;
00202 
00203         REQUIRE(type == 257);
00204         REQUIRE(source != NULL);
00205         REQUIRE(caa->common.rdtype == type);
00206         REQUIRE(caa->common.rdclass == rdclass);
00207         REQUIRE(caa->tag != NULL && caa->tag_len != 0);
00208         REQUIRE(caa->value != NULL);
00209 
00210         UNUSED(type);
00211         UNUSED(rdclass);
00212 
00213         /*
00214          * Flags
00215          */
00216         RETERR(uint8_tobuffer(caa->flags, target));
00217 
00218         /*
00219          * Tag length
00220          */
00221         RETERR(uint8_tobuffer(caa->tag_len, target));
00222 
00223         /*
00224          * Tag
00225          */
00226         region.base = caa->tag;
00227         region.length = caa->tag_len;
00228         for (i = 0; i < region.length; i++)
00229                 if (!alphanumeric[region.base[i]])
00230                         RETERR(DNS_R_SYNTAX);
00231         RETERR(isc_buffer_copyregion(target, &region));
00232 
00233         /*
00234          * Value
00235          */
00236         region.base = caa->value;
00237         region.length = caa->value_len;
00238         return (isc_buffer_copyregion(target, &region));
00239 }
00240 
00241 static inline isc_result_t
00242 tostruct_caa(ARGS_TOSTRUCT) {
00243         dns_rdata_caa_t *caa = target;
00244         isc_region_t sr;
00245 
00246         REQUIRE(rdata->type == 257);
00247         REQUIRE(target != NULL);
00248         REQUIRE(rdata->length >= 3U);
00249         REQUIRE(rdata->data != NULL);
00250 
00251         caa->common.rdclass = rdata->rdclass;
00252         caa->common.rdtype = rdata->type;
00253         ISC_LINK_INIT(&caa->common, link);
00254 
00255         dns_rdata_toregion(rdata, &sr);
00256 
00257         /*
00258          * Flags
00259          */
00260         if (sr.length < 1)
00261                 return (ISC_R_UNEXPECTEDEND);
00262         caa->flags = uint8_fromregion(&sr);
00263         isc_region_consume(&sr, 1);
00264 
00265         /*
00266          * Tag length
00267          */
00268         if (sr.length < 1)
00269                 return (ISC_R_UNEXPECTEDEND);
00270         caa->tag_len = uint8_fromregion(&sr);
00271         isc_region_consume(&sr, 1);
00272 
00273         /*
00274          * Tag
00275          */
00276         if (sr.length < caa->tag_len)
00277                 return (ISC_R_UNEXPECTEDEND);
00278         caa->tag = mem_maybedup(mctx, sr.base, caa->tag_len);
00279         if (caa->tag == NULL)
00280                 return (ISC_R_NOMEMORY);
00281         isc_region_consume(&sr, caa->tag_len);
00282 
00283         /*
00284          * Value
00285          */
00286         caa->value_len = sr.length;
00287         caa->value = mem_maybedup(mctx, sr.base, sr.length);
00288         if (caa->value == NULL)
00289                 return (ISC_R_NOMEMORY);
00290 
00291         caa->mctx = mctx;
00292         return (ISC_R_SUCCESS);
00293 }
00294 
00295 static inline void
00296 freestruct_caa(ARGS_FREESTRUCT) {
00297         dns_rdata_caa_t *caa = (dns_rdata_caa_t *) source;
00298 
00299         REQUIRE(source != NULL);
00300         REQUIRE(caa->common.rdtype == 257);
00301 
00302         if (caa->mctx == NULL)
00303                 return;
00304 
00305         if (caa->tag != NULL)
00306                 isc_mem_free(caa->mctx, caa->tag);
00307         if (caa->value != NULL)
00308                 isc_mem_free(caa->mctx, caa->value);
00309         caa->mctx = NULL;
00310 }
00311 
00312 static inline isc_result_t
00313 additionaldata_caa(ARGS_ADDLDATA) {
00314         REQUIRE(rdata->type == 257);
00315         REQUIRE(rdata->data != NULL);
00316         REQUIRE(rdata->length >= 3U);
00317 
00318         UNUSED(rdata);
00319         UNUSED(add);
00320         UNUSED(arg);
00321 
00322         return (ISC_R_SUCCESS);
00323 }
00324 
00325 static inline isc_result_t
00326 digest_caa(ARGS_DIGEST) {
00327         isc_region_t r;
00328 
00329         REQUIRE(rdata->type == 257);
00330         REQUIRE(rdata->data != NULL);
00331         REQUIRE(rdata->length >= 3U);
00332 
00333         dns_rdata_toregion(rdata, &r);
00334 
00335         return ((digest)(arg, &r));
00336 }
00337 
00338 static inline isc_boolean_t
00339 checkowner_caa(ARGS_CHECKOWNER) {
00340 
00341         REQUIRE(type == 257);
00342 
00343         UNUSED(name);
00344         UNUSED(type);
00345         UNUSED(rdclass);
00346         UNUSED(wildcard);
00347 
00348         return (ISC_TRUE);
00349 }
00350 
00351 static inline isc_boolean_t
00352 checknames_caa(ARGS_CHECKNAMES) {
00353 
00354         REQUIRE(rdata->type == 257);
00355         REQUIRE(rdata->data != NULL);
00356         REQUIRE(rdata->length >= 3U);
00357 
00358         UNUSED(rdata);
00359         UNUSED(owner);
00360         UNUSED(bad);
00361 
00362         return (ISC_TRUE);
00363 }
00364 
00365 static inline int
00366 casecompare_caa(ARGS_COMPARE) {
00367         return (compare_caa(rdata1, rdata2));
00368 }
00369 
00370 #endif /* GENERIC_CAA_257_C */

Generated on Tue Apr 28 17:40:59 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha