"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.17.5/lib/dns/rdata/generic/afsdb_18.c" (4 Sep 2020, 7120 Bytes) of package /linux/misc/dns/bind9/9.17.5/bind-9.17.5.tar.xz:


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 "afsdb_18.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 /* RFC1183 */
   13 
   14 #ifndef RDATA_GENERIC_AFSDB_18_C
   15 #define RDATA_GENERIC_AFSDB_18_C
   16 
   17 #define RRTYPE_AFSDB_ATTRIBUTES (0)
   18 
   19 static inline isc_result_t
   20 fromtext_afsdb(ARGS_FROMTEXT) {
   21     isc_token_t token;
   22     isc_buffer_t buffer;
   23     dns_name_t name;
   24     bool ok;
   25 
   26     REQUIRE(type == dns_rdatatype_afsdb);
   27 
   28     UNUSED(type);
   29     UNUSED(rdclass);
   30     UNUSED(callbacks);
   31 
   32     /*
   33      * Subtype.
   34      */
   35     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
   36                       false));
   37     if (token.value.as_ulong > 0xffffU) {
   38         RETTOK(ISC_R_RANGE);
   39     }
   40     RETERR(uint16_tobuffer(token.value.as_ulong, target));
   41 
   42     /*
   43      * Hostname.
   44      */
   45     RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
   46                       false));
   47     dns_name_init(&name, NULL);
   48     buffer_fromregion(&buffer, &token.value.as_region);
   49     if (origin == NULL) {
   50         origin = dns_rootname;
   51     }
   52     RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
   53     ok = true;
   54     if ((options & DNS_RDATA_CHECKNAMES) != 0) {
   55         ok = dns_name_ishostname(&name, false);
   56     }
   57     if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) {
   58         RETTOK(DNS_R_BADNAME);
   59     }
   60     if (!ok && callbacks != NULL) {
   61         warn_badname(&name, lexer, callbacks);
   62     }
   63     return (ISC_R_SUCCESS);
   64 }
   65 
   66 static inline isc_result_t
   67 totext_afsdb(ARGS_TOTEXT) {
   68     dns_name_t name;
   69     dns_name_t prefix;
   70     isc_region_t region;
   71     char buf[sizeof("64000 ")];
   72     bool sub;
   73     unsigned int num;
   74 
   75     REQUIRE(rdata->type == dns_rdatatype_afsdb);
   76     REQUIRE(rdata->length != 0);
   77 
   78     dns_name_init(&name, NULL);
   79     dns_name_init(&prefix, NULL);
   80 
   81     dns_rdata_toregion(rdata, &region);
   82     num = uint16_fromregion(&region);
   83     isc_region_consume(&region, 2);
   84     snprintf(buf, sizeof(buf), "%u ", num);
   85     RETERR(str_totext(buf, target));
   86     dns_name_fromregion(&name, &region);
   87     sub = name_prefix(&name, tctx->origin, &prefix);
   88     return (dns_name_totext(&prefix, sub, target));
   89 }
   90 
   91 static inline isc_result_t
   92 fromwire_afsdb(ARGS_FROMWIRE) {
   93     dns_name_t name;
   94     isc_region_t sr;
   95     isc_region_t tr;
   96 
   97     REQUIRE(type == dns_rdatatype_afsdb);
   98 
   99     UNUSED(type);
  100     UNUSED(rdclass);
  101 
  102     dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
  103 
  104     dns_name_init(&name, NULL);
  105 
  106     isc_buffer_activeregion(source, &sr);
  107     isc_buffer_availableregion(target, &tr);
  108     if (tr.length < 2) {
  109         return (ISC_R_NOSPACE);
  110     }
  111     if (sr.length < 2) {
  112         return (ISC_R_UNEXPECTEDEND);
  113     }
  114     memmove(tr.base, sr.base, 2);
  115     isc_buffer_forward(source, 2);
  116     isc_buffer_add(target, 2);
  117     return (dns_name_fromwire(&name, source, dctx, options, target));
  118 }
  119 
  120 static inline isc_result_t
  121 towire_afsdb(ARGS_TOWIRE) {
  122     isc_region_t tr;
  123     isc_region_t sr;
  124     dns_name_t name;
  125     dns_offsets_t offsets;
  126 
  127     REQUIRE(rdata->type == dns_rdatatype_afsdb);
  128     REQUIRE(rdata->length != 0);
  129 
  130     dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
  131     isc_buffer_availableregion(target, &tr);
  132     dns_rdata_toregion(rdata, &sr);
  133     if (tr.length < 2) {
  134         return (ISC_R_NOSPACE);
  135     }
  136     memmove(tr.base, sr.base, 2);
  137     isc_region_consume(&sr, 2);
  138     isc_buffer_add(target, 2);
  139 
  140     dns_name_init(&name, offsets);
  141     dns_name_fromregion(&name, &sr);
  142 
  143     return (dns_name_towire(&name, cctx, target));
  144 }
  145 
  146 static inline int
  147 compare_afsdb(ARGS_COMPARE) {
  148     int result;
  149     dns_name_t name1;
  150     dns_name_t name2;
  151     isc_region_t region1;
  152     isc_region_t region2;
  153 
  154     REQUIRE(rdata1->type == rdata2->type);
  155     REQUIRE(rdata1->rdclass == rdata2->rdclass);
  156     REQUIRE(rdata1->type == dns_rdatatype_afsdb);
  157     REQUIRE(rdata1->length != 0);
  158     REQUIRE(rdata2->length != 0);
  159 
  160     result = memcmp(rdata1->data, rdata2->data, 2);
  161     if (result != 0) {
  162         return (result < 0 ? -1 : 1);
  163     }
  164 
  165     dns_name_init(&name1, NULL);
  166     dns_name_init(&name2, NULL);
  167 
  168     dns_rdata_toregion(rdata1, &region1);
  169     dns_rdata_toregion(rdata2, &region2);
  170 
  171     isc_region_consume(&region1, 2);
  172     isc_region_consume(&region2, 2);
  173 
  174     dns_name_fromregion(&name1, &region1);
  175     dns_name_fromregion(&name2, &region2);
  176 
  177     return (dns_name_rdatacompare(&name1, &name2));
  178 }
  179 
  180 static inline isc_result_t
  181 fromstruct_afsdb(ARGS_FROMSTRUCT) {
  182     dns_rdata_afsdb_t *afsdb = source;
  183     isc_region_t region;
  184 
  185     REQUIRE(type == dns_rdatatype_afsdb);
  186     REQUIRE(afsdb != NULL);
  187     REQUIRE(afsdb->common.rdclass == rdclass);
  188     REQUIRE(afsdb->common.rdtype == type);
  189 
  190     UNUSED(type);
  191     UNUSED(rdclass);
  192 
  193     RETERR(uint16_tobuffer(afsdb->subtype, target));
  194     dns_name_toregion(&afsdb->server, &region);
  195     return (isc_buffer_copyregion(target, &region));
  196 }
  197 
  198 static inline isc_result_t
  199 tostruct_afsdb(ARGS_TOSTRUCT) {
  200     isc_region_t region;
  201     dns_rdata_afsdb_t *afsdb = target;
  202     dns_name_t name;
  203 
  204     REQUIRE(rdata->type == dns_rdatatype_afsdb);
  205     REQUIRE(afsdb != NULL);
  206     REQUIRE(rdata->length != 0);
  207 
  208     afsdb->common.rdclass = rdata->rdclass;
  209     afsdb->common.rdtype = rdata->type;
  210     ISC_LINK_INIT(&afsdb->common, link);
  211 
  212     dns_name_init(&afsdb->server, NULL);
  213 
  214     dns_rdata_toregion(rdata, &region);
  215 
  216     afsdb->subtype = uint16_fromregion(&region);
  217     isc_region_consume(&region, 2);
  218 
  219     dns_name_init(&name, NULL);
  220     dns_name_fromregion(&name, &region);
  221 
  222     RETERR(name_duporclone(&name, mctx, &afsdb->server));
  223     afsdb->mctx = mctx;
  224     return (ISC_R_SUCCESS);
  225 }
  226 
  227 static inline void
  228 freestruct_afsdb(ARGS_FREESTRUCT) {
  229     dns_rdata_afsdb_t *afsdb = source;
  230 
  231     REQUIRE(afsdb != NULL);
  232     REQUIRE(afsdb->common.rdtype == dns_rdatatype_afsdb);
  233 
  234     if (afsdb->mctx == NULL) {
  235         return;
  236     }
  237 
  238     dns_name_free(&afsdb->server, afsdb->mctx);
  239     afsdb->mctx = NULL;
  240 }
  241 
  242 static inline isc_result_t
  243 additionaldata_afsdb(ARGS_ADDLDATA) {
  244     dns_name_t name;
  245     dns_offsets_t offsets;
  246     isc_region_t region;
  247 
  248     REQUIRE(rdata->type == dns_rdatatype_afsdb);
  249 
  250     dns_name_init(&name, offsets);
  251     dns_rdata_toregion(rdata, &region);
  252     isc_region_consume(&region, 2);
  253     dns_name_fromregion(&name, &region);
  254 
  255     return ((add)(arg, &name, dns_rdatatype_a));
  256 }
  257 
  258 static inline isc_result_t
  259 digest_afsdb(ARGS_DIGEST) {
  260     isc_region_t r1, r2;
  261     dns_name_t name;
  262 
  263     REQUIRE(rdata->type == dns_rdatatype_afsdb);
  264 
  265     dns_rdata_toregion(rdata, &r1);
  266     r2 = r1;
  267     isc_region_consume(&r2, 2);
  268     r1.length = 2;
  269     RETERR((digest)(arg, &r1));
  270     dns_name_init(&name, NULL);
  271     dns_name_fromregion(&name, &r2);
  272 
  273     return (dns_name_digest(&name, digest, arg));
  274 }
  275 
  276 static inline bool
  277 checkowner_afsdb(ARGS_CHECKOWNER) {
  278     REQUIRE(type == dns_rdatatype_afsdb);
  279 
  280     UNUSED(name);
  281     UNUSED(type);
  282     UNUSED(rdclass);
  283     UNUSED(wildcard);
  284 
  285     return (true);
  286 }
  287 
  288 static inline bool
  289 checknames_afsdb(ARGS_CHECKNAMES) {
  290     isc_region_t region;
  291     dns_name_t name;
  292 
  293     REQUIRE(rdata->type == dns_rdatatype_afsdb);
  294 
  295     UNUSED(owner);
  296 
  297     dns_rdata_toregion(rdata, &region);
  298     isc_region_consume(&region, 2);
  299     dns_name_init(&name, NULL);
  300     dns_name_fromregion(&name, &region);
  301     if (!dns_name_ishostname(&name, false)) {
  302         if (bad != NULL) {
  303             dns_name_clone(&name, bad);
  304         }
  305         return (false);
  306     }
  307     return (true);
  308 }
  309 
  310 static inline int
  311 casecompare_afsdb(ARGS_COMPARE) {
  312     return (compare_afsdb(rdata1, rdata2));
  313 }
  314 #endif /* RDATA_GENERIC_AFSDB_18_C */