ns_2.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1998-2001  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id: ns_2.c,v 1.48 2009/12/04 22:06:37 tbox Exp $ */
00019 
00020 /* Reviewed: Wed Mar 15 18:15:00 PST 2000 by bwelling */
00021 
00022 #ifndef RDATA_GENERIC_NS_2_C
00023 #define RDATA_GENERIC_NS_2_C
00024 
00025 #define RRTYPE_NS_ATTRIBUTES (DNS_RDATATYPEATTR_ZONECUTAUTH)
00026 
00027 static inline isc_result_t
00028 fromtext_ns(ARGS_FROMTEXT) {
00029         isc_token_t token;
00030         dns_name_t name;
00031         isc_buffer_t buffer;
00032         isc_boolean_t ok;
00033 
00034         REQUIRE(type == 2);
00035 
00036         UNUSED(type);
00037         UNUSED(rdclass);
00038         UNUSED(callbacks);
00039 
00040         RETERR(isc_lex_getmastertoken(lexer, &token,isc_tokentype_string,
00041                                       ISC_FALSE));
00042 
00043         dns_name_init(&name, NULL);
00044         buffer_fromregion(&buffer, &token.value.as_region);
00045         origin = (origin != NULL) ? origin : dns_rootname;
00046         RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
00047         ok = ISC_TRUE;
00048         if ((options & DNS_RDATA_CHECKNAMES) != 0)
00049                 ok = dns_name_ishostname(&name, ISC_FALSE);
00050         if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
00051                 RETTOK(DNS_R_BADNAME);
00052         if (!ok && callbacks != NULL)
00053                 warn_badname(&name, lexer, callbacks);
00054         return (ISC_R_SUCCESS);
00055 }
00056 
00057 static inline isc_result_t
00058 totext_ns(ARGS_TOTEXT) {
00059         isc_region_t region;
00060         dns_name_t name;
00061         dns_name_t prefix;
00062         isc_boolean_t sub;
00063 
00064         REQUIRE(rdata->type == 2);
00065         REQUIRE(rdata->length != 0);
00066 
00067         dns_name_init(&name, NULL);
00068         dns_name_init(&prefix, NULL);
00069 
00070         dns_rdata_toregion(rdata, &region);
00071         dns_name_fromregion(&name, &region);
00072 
00073         sub = name_prefix(&name, tctx->origin, &prefix);
00074 
00075         return (dns_name_totext(&prefix, sub, target));
00076 }
00077 
00078 static inline isc_result_t
00079 fromwire_ns(ARGS_FROMWIRE) {
00080         dns_name_t name;
00081 
00082         REQUIRE(type == 2);
00083 
00084         UNUSED(type);
00085         UNUSED(rdclass);
00086 
00087         dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
00088 
00089         dns_name_init(&name, NULL);
00090         return (dns_name_fromwire(&name, source, dctx, options, target));
00091 }
00092 
00093 static inline isc_result_t
00094 towire_ns(ARGS_TOWIRE) {
00095         dns_name_t name;
00096         dns_offsets_t offsets;
00097         isc_region_t region;
00098 
00099         REQUIRE(rdata->type == 2);
00100         REQUIRE(rdata->length != 0);
00101 
00102         dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
00103 
00104         dns_name_init(&name, offsets);
00105         dns_rdata_toregion(rdata, &region);
00106         dns_name_fromregion(&name, &region);
00107 
00108         return (dns_name_towire(&name, cctx, target));
00109 }
00110 
00111 static inline int
00112 compare_ns(ARGS_COMPARE) {
00113         dns_name_t name1;
00114         dns_name_t name2;
00115         isc_region_t region1;
00116         isc_region_t region2;
00117 
00118         REQUIRE(rdata1->type == rdata2->type);
00119         REQUIRE(rdata1->rdclass == rdata2->rdclass);
00120         REQUIRE(rdata1->type == 2);
00121         REQUIRE(rdata1->length != 0);
00122         REQUIRE(rdata2->length != 0);
00123 
00124         dns_name_init(&name1, NULL);
00125         dns_name_init(&name2, NULL);
00126 
00127         dns_rdata_toregion(rdata1, &region1);
00128         dns_rdata_toregion(rdata2, &region2);
00129 
00130         dns_name_fromregion(&name1, &region1);
00131         dns_name_fromregion(&name2, &region2);
00132 
00133         return (dns_name_rdatacompare(&name1, &name2));
00134 }
00135 
00136 static inline isc_result_t
00137 fromstruct_ns(ARGS_FROMSTRUCT) {
00138         dns_rdata_ns_t *ns = source;
00139         isc_region_t region;
00140 
00141         REQUIRE(type == 2);
00142         REQUIRE(source != NULL);
00143         REQUIRE(ns->common.rdtype == type);
00144         REQUIRE(ns->common.rdclass == rdclass);
00145 
00146         UNUSED(type);
00147         UNUSED(rdclass);
00148 
00149         dns_name_toregion(&ns->name, &region);
00150         return (isc_buffer_copyregion(target, &region));
00151 }
00152 
00153 static inline isc_result_t
00154 tostruct_ns(ARGS_TOSTRUCT) {
00155         isc_region_t region;
00156         dns_rdata_ns_t *ns = target;
00157         dns_name_t name;
00158 
00159         REQUIRE(rdata->type == 2);
00160         REQUIRE(target != NULL);
00161         REQUIRE(rdata->length != 0);
00162 
00163         ns->common.rdclass = rdata->rdclass;
00164         ns->common.rdtype = rdata->type;
00165         ISC_LINK_INIT(&ns->common, link);
00166 
00167         dns_name_init(&name, NULL);
00168         dns_rdata_toregion(rdata, &region);
00169         dns_name_fromregion(&name, &region);
00170         dns_name_init(&ns->name, NULL);
00171         RETERR(name_duporclone(&name, mctx, &ns->name));
00172         ns->mctx = mctx;
00173         return (ISC_R_SUCCESS);
00174 }
00175 
00176 static inline void
00177 freestruct_ns(ARGS_FREESTRUCT) {
00178         dns_rdata_ns_t *ns = source;
00179 
00180         REQUIRE(source != NULL);
00181 
00182         if (ns->mctx == NULL)
00183                 return;
00184 
00185         dns_name_free(&ns->name, ns->mctx);
00186         ns->mctx = NULL;
00187 }
00188 
00189 static inline isc_result_t
00190 additionaldata_ns(ARGS_ADDLDATA) {
00191         dns_name_t name;
00192         dns_offsets_t offsets;
00193         isc_region_t region;
00194 
00195         REQUIRE(rdata->type == 2);
00196 
00197         dns_name_init(&name, offsets);
00198         dns_rdata_toregion(rdata, &region);
00199         dns_name_fromregion(&name, &region);
00200 
00201         return ((add)(arg, &name, dns_rdatatype_a));
00202 }
00203 
00204 static inline isc_result_t
00205 digest_ns(ARGS_DIGEST) {
00206         isc_region_t r;
00207         dns_name_t name;
00208 
00209         REQUIRE(rdata->type == 2);
00210 
00211         dns_rdata_toregion(rdata, &r);
00212         dns_name_init(&name, NULL);
00213         dns_name_fromregion(&name, &r);
00214 
00215         return (dns_name_digest(&name, digest, arg));
00216 }
00217 
00218 static inline isc_boolean_t
00219 checkowner_ns(ARGS_CHECKOWNER) {
00220 
00221         REQUIRE(type == 2);
00222 
00223         UNUSED(name);
00224         UNUSED(type);
00225         UNUSED(rdclass);
00226         UNUSED(wildcard);
00227 
00228         return (ISC_TRUE);
00229 }
00230 
00231 static inline isc_boolean_t
00232 checknames_ns(ARGS_CHECKNAMES) {
00233         isc_region_t region;
00234         dns_name_t name;
00235 
00236         REQUIRE(rdata->type == 2);
00237 
00238         UNUSED(owner);
00239 
00240         dns_rdata_toregion(rdata, &region);
00241         dns_name_init(&name, NULL);
00242         dns_name_fromregion(&name, &region);
00243         if (!dns_name_ishostname(&name, ISC_FALSE)) {
00244                 if (bad != NULL)
00245                         dns_name_clone(&name, bad);
00246                 return (ISC_FALSE);
00247         }
00248         return (ISC_TRUE);
00249 }
00250 
00251 static inline int
00252 casecompare_ns(ARGS_COMPARE) {
00253         return (compare_ns(rdata1, rdata2));
00254 }
00255 
00256 #endif  /* RDATA_GENERIC_NS_2_C */

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