/src/bind9/lib/dns/rdata/generic/ns_2.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) Internet Systems Consortium, Inc. ("ISC") |
3 | | * |
4 | | * SPDX-License-Identifier: MPL-2.0 |
5 | | * |
6 | | * This Source Code Form is subject to the terms of the Mozilla Public |
7 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
8 | | * file, you can obtain one at https://mozilla.org/MPL/2.0/. |
9 | | * |
10 | | * See the COPYRIGHT file distributed with this work for additional |
11 | | * information regarding copyright ownership. |
12 | | */ |
13 | | |
14 | | #ifndef RDATA_GENERIC_NS_2_C |
15 | | #define RDATA_GENERIC_NS_2_C |
16 | | |
17 | 136k | #define RRTYPE_NS_ATTRIBUTES (DNS_RDATATYPEATTR_ZONECUTAUTH) |
18 | | |
19 | | static isc_result_t |
20 | 5.55M | fromtext_ns(ARGS_FROMTEXT) { |
21 | 5.55M | isc_token_t token; |
22 | 5.55M | dns_fixedname_t fn; |
23 | 5.55M | dns_name_t *name = dns_fixedname_initname(&fn); |
24 | 5.55M | isc_buffer_t buffer; |
25 | 5.55M | bool ok; |
26 | | |
27 | 5.55M | REQUIRE(type == dns_rdatatype_ns); |
28 | | |
29 | 5.55M | UNUSED(type); |
30 | 5.55M | UNUSED(rdclass); |
31 | 5.55M | UNUSED(callbacks); |
32 | | |
33 | 5.55M | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
34 | 5.55M | false)); |
35 | | |
36 | 5.55M | buffer_fromregion(&buffer, &token.value.as_region); |
37 | 5.55M | if (origin == NULL) { |
38 | 40 | origin = dns_rootname; |
39 | 40 | } |
40 | 5.55M | RETTOK(dns_name_fromtext(name, &buffer, origin, options)); |
41 | 5.55M | RETTOK(dns_name_towire(name, NULL, target)); |
42 | 5.55M | ok = true; |
43 | 5.55M | if ((options & DNS_RDATA_CHECKNAMES) != 0) { |
44 | 0 | ok = dns_name_ishostname(name, false); |
45 | 0 | } |
46 | 5.55M | if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { |
47 | 0 | RETTOK(DNS_R_BADNAME); |
48 | 0 | } |
49 | 5.55M | if (!ok && callbacks != NULL) { |
50 | 0 | warn_badname(name, lexer, callbacks); |
51 | 0 | } |
52 | 5.55M | return ISC_R_SUCCESS; |
53 | 5.55M | } |
54 | | |
55 | | static isc_result_t |
56 | 3.20k | totext_ns(ARGS_TOTEXT) { |
57 | 3.20k | isc_region_t region; |
58 | 3.20k | dns_name_t name; |
59 | 3.20k | dns_name_t prefix; |
60 | 3.20k | unsigned int opts; |
61 | | |
62 | 3.20k | REQUIRE(rdata->type == dns_rdatatype_ns); |
63 | 3.20k | REQUIRE(rdata->length != 0); |
64 | | |
65 | 3.20k | dns_name_init(&name); |
66 | 3.20k | dns_name_init(&prefix); |
67 | | |
68 | 3.20k | dns_rdata_toregion(rdata, ®ion); |
69 | 3.20k | dns_name_fromregion(&name, ®ion); |
70 | | |
71 | 3.20k | opts = name_prefix(&name, tctx->origin, &prefix) ? DNS_NAME_OMITFINALDOT |
72 | 3.20k | : 0; |
73 | 3.20k | return dns_name_totext(&prefix, opts, target); |
74 | 3.20k | } |
75 | | |
76 | | static isc_result_t |
77 | 3.98k | fromwire_ns(ARGS_FROMWIRE) { |
78 | 3.98k | dns_name_t name; |
79 | | |
80 | 3.98k | REQUIRE(type == dns_rdatatype_ns); |
81 | | |
82 | 3.98k | UNUSED(type); |
83 | 3.98k | UNUSED(rdclass); |
84 | | |
85 | 3.98k | dctx = dns_decompress_setpermitted(dctx, true); |
86 | | |
87 | 3.98k | dns_name_init(&name); |
88 | 3.98k | return dns_name_fromwire(&name, source, dctx, target); |
89 | 3.98k | } |
90 | | |
91 | | static isc_result_t |
92 | 1.61k | towire_ns(ARGS_TOWIRE) { |
93 | 1.61k | dns_name_t name; |
94 | 1.61k | isc_region_t region; |
95 | | |
96 | 1.61k | REQUIRE(rdata->type == dns_rdatatype_ns); |
97 | 1.61k | REQUIRE(rdata->length != 0); |
98 | | |
99 | 1.61k | dns_compress_setpermitted(cctx, true); |
100 | | |
101 | 1.61k | dns_name_init(&name); |
102 | 1.61k | dns_rdata_toregion(rdata, ®ion); |
103 | 1.61k | dns_name_fromregion(&name, ®ion); |
104 | | |
105 | 1.61k | return dns_name_towire(&name, cctx, target); |
106 | 1.61k | } |
107 | | |
108 | | static int |
109 | 3.70M | compare_ns(ARGS_COMPARE) { |
110 | 3.70M | dns_name_t name1; |
111 | 3.70M | dns_name_t name2; |
112 | 3.70M | isc_region_t region1; |
113 | 3.70M | isc_region_t region2; |
114 | | |
115 | 3.70M | REQUIRE(rdata1->type == rdata2->type); |
116 | 3.70M | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
117 | 3.70M | REQUIRE(rdata1->type == dns_rdatatype_ns); |
118 | 3.70M | REQUIRE(rdata1->length != 0); |
119 | 3.70M | REQUIRE(rdata2->length != 0); |
120 | | |
121 | 3.70M | dns_name_init(&name1); |
122 | 3.70M | dns_name_init(&name2); |
123 | | |
124 | 3.70M | dns_rdata_toregion(rdata1, ®ion1); |
125 | 3.70M | dns_rdata_toregion(rdata2, ®ion2); |
126 | | |
127 | 3.70M | dns_name_fromregion(&name1, ®ion1); |
128 | 3.70M | dns_name_fromregion(&name2, ®ion2); |
129 | | |
130 | 3.70M | return dns_name_rdatacompare(&name1, &name2); |
131 | 3.70M | } |
132 | | |
133 | | static isc_result_t |
134 | 0 | fromstruct_ns(ARGS_FROMSTRUCT) { |
135 | 0 | dns_rdata_ns_t *ns = source; |
136 | 0 | isc_region_t region; |
137 | |
|
138 | 0 | REQUIRE(type == dns_rdatatype_ns); |
139 | 0 | REQUIRE(ns != NULL); |
140 | 0 | REQUIRE(ns->common.rdtype == type); |
141 | 0 | REQUIRE(ns->common.rdclass == rdclass); |
142 | |
|
143 | 0 | UNUSED(type); |
144 | 0 | UNUSED(rdclass); |
145 | |
|
146 | 0 | dns_name_toregion(&ns->name, ®ion); |
147 | 0 | return isc_buffer_copyregion(target, ®ion); |
148 | 0 | } |
149 | | |
150 | | static isc_result_t |
151 | 2 | tostruct_ns(ARGS_TOSTRUCT) { |
152 | 2 | isc_region_t region; |
153 | 2 | dns_rdata_ns_t *ns = target; |
154 | 2 | dns_name_t name; |
155 | | |
156 | 2 | REQUIRE(rdata->type == dns_rdatatype_ns); |
157 | 2 | REQUIRE(ns != NULL); |
158 | 2 | REQUIRE(rdata->length != 0); |
159 | | |
160 | 2 | DNS_RDATACOMMON_INIT(ns, rdata->type, rdata->rdclass); |
161 | | |
162 | 2 | dns_name_init(&name); |
163 | 2 | dns_rdata_toregion(rdata, ®ion); |
164 | 2 | dns_name_fromregion(&name, ®ion); |
165 | 2 | dns_name_init(&ns->name); |
166 | 2 | name_duporclone(&name, mctx, &ns->name); |
167 | 2 | ns->mctx = mctx; |
168 | 2 | return ISC_R_SUCCESS; |
169 | 2 | } |
170 | | |
171 | | static void |
172 | 0 | freestruct_ns(ARGS_FREESTRUCT) { |
173 | 0 | dns_rdata_ns_t *ns = source; |
174 | |
|
175 | 0 | REQUIRE(ns != NULL); |
176 | |
|
177 | 0 | if (ns->mctx == NULL) { |
178 | 0 | return; |
179 | 0 | } |
180 | | |
181 | 0 | dns_name_free(&ns->name, ns->mctx); |
182 | 0 | ns->mctx = NULL; |
183 | 0 | } |
184 | | |
185 | | static isc_result_t |
186 | 0 | additionaldata_ns(ARGS_ADDLDATA) { |
187 | 0 | dns_name_t name; |
188 | 0 | isc_region_t region; |
189 | |
|
190 | 0 | REQUIRE(rdata->type == dns_rdatatype_ns); |
191 | |
|
192 | 0 | UNUSED(owner); |
193 | |
|
194 | 0 | dns_name_init(&name); |
195 | 0 | dns_rdata_toregion(rdata, ®ion); |
196 | 0 | dns_name_fromregion(&name, ®ion); |
197 | |
|
198 | 0 | return (add)(arg, &name, dns_rdatatype_a, NULL DNS__DB_FILELINE); |
199 | 0 | } |
200 | | |
201 | | static isc_result_t |
202 | 0 | digest_ns(ARGS_DIGEST) { |
203 | 0 | isc_region_t r; |
204 | 0 | dns_name_t name; |
205 | |
|
206 | 0 | REQUIRE(rdata->type == dns_rdatatype_ns); |
207 | |
|
208 | 0 | dns_rdata_toregion(rdata, &r); |
209 | 0 | dns_name_init(&name); |
210 | 0 | dns_name_fromregion(&name, &r); |
211 | |
|
212 | 0 | return dns_name_digest(&name, digest, arg); |
213 | 0 | } |
214 | | |
215 | | static bool |
216 | 0 | checkowner_ns(ARGS_CHECKOWNER) { |
217 | 0 | REQUIRE(type == dns_rdatatype_ns); |
218 | |
|
219 | 0 | UNUSED(name); |
220 | 0 | UNUSED(type); |
221 | 0 | UNUSED(rdclass); |
222 | 0 | UNUSED(wildcard); |
223 | |
|
224 | 0 | return true; |
225 | 0 | } |
226 | | |
227 | | static bool |
228 | 0 | checknames_ns(ARGS_CHECKNAMES) { |
229 | 0 | isc_region_t region; |
230 | 0 | dns_name_t name; |
231 | |
|
232 | 0 | REQUIRE(rdata->type == dns_rdatatype_ns); |
233 | |
|
234 | 0 | UNUSED(owner); |
235 | |
|
236 | 0 | dns_rdata_toregion(rdata, ®ion); |
237 | 0 | dns_name_init(&name); |
238 | 0 | dns_name_fromregion(&name, ®ion); |
239 | 0 | if (!dns_name_ishostname(&name, false)) { |
240 | 0 | if (bad != NULL) { |
241 | 0 | dns_name_clone(&name, bad); |
242 | 0 | } |
243 | 0 | return false; |
244 | 0 | } |
245 | 0 | return true; |
246 | 0 | } |
247 | | |
248 | | static int |
249 | 0 | casecompare_ns(ARGS_COMPARE) { |
250 | 0 | return compare_ns(rdata1, rdata2); |
251 | 0 | } |
252 | | |
253 | | #endif /* RDATA_GENERIC_NS_2_C */ |