/src/bind9/lib/dns/rdata/generic/ns_2.c
Line | Count | Source (jump to first uncovered line) |
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 | 67.8k | #define RRTYPE_NS_ATTRIBUTES (DNS_RDATATYPEATTR_ZONECUTAUTH) |
18 | | |
19 | | static isc_result_t |
20 | 1.60M | fromtext_ns(ARGS_FROMTEXT) { |
21 | 1.60M | isc_token_t token; |
22 | 1.60M | dns_name_t name; |
23 | 1.60M | isc_buffer_t buffer; |
24 | 1.60M | bool ok; |
25 | | |
26 | 1.60M | REQUIRE(type == dns_rdatatype_ns); |
27 | | |
28 | 1.60M | UNUSED(type); |
29 | 1.60M | UNUSED(rdclass); |
30 | 1.60M | UNUSED(callbacks); |
31 | | |
32 | 1.60M | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
33 | 1.60M | false)); |
34 | | |
35 | 1.60M | dns_name_init(&name, NULL); |
36 | 1.60M | buffer_fromregion(&buffer, &token.value.as_region); |
37 | 1.60M | if (origin == NULL) { |
38 | 41 | origin = dns_rootname; |
39 | 41 | } |
40 | 1.60M | RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); |
41 | 1.60M | ok = true; |
42 | 1.60M | if ((options & DNS_RDATA_CHECKNAMES) != 0) { |
43 | 0 | ok = dns_name_ishostname(&name, false); |
44 | 0 | } |
45 | 1.60M | if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { |
46 | 0 | RETTOK(DNS_R_BADNAME); |
47 | 0 | } |
48 | 1.60M | if (!ok && callbacks != NULL) { |
49 | 0 | warn_badname(&name, lexer, callbacks); |
50 | 0 | } |
51 | 1.60M | return (ISC_R_SUCCESS); |
52 | 1.60M | } |
53 | | |
54 | | static isc_result_t |
55 | 1.43k | totext_ns(ARGS_TOTEXT) { |
56 | 1.43k | isc_region_t region; |
57 | 1.43k | dns_name_t name; |
58 | 1.43k | dns_name_t prefix; |
59 | 1.43k | bool sub; |
60 | | |
61 | 1.43k | REQUIRE(rdata->type == dns_rdatatype_ns); |
62 | 1.43k | REQUIRE(rdata->length != 0); |
63 | | |
64 | 1.43k | dns_name_init(&name, NULL); |
65 | 1.43k | dns_name_init(&prefix, NULL); |
66 | | |
67 | 1.43k | dns_rdata_toregion(rdata, ®ion); |
68 | 1.43k | dns_name_fromregion(&name, ®ion); |
69 | | |
70 | 1.43k | sub = name_prefix(&name, tctx->origin, &prefix); |
71 | | |
72 | 1.43k | return (dns_name_totext(&prefix, sub, target)); |
73 | 1.43k | } |
74 | | |
75 | | static isc_result_t |
76 | 1.97k | fromwire_ns(ARGS_FROMWIRE) { |
77 | 1.97k | dns_name_t name; |
78 | | |
79 | 1.97k | REQUIRE(type == dns_rdatatype_ns); |
80 | | |
81 | 1.97k | UNUSED(type); |
82 | 1.97k | UNUSED(rdclass); |
83 | | |
84 | 1.97k | dctx = dns_decompress_setpermitted(dctx, true); |
85 | | |
86 | 1.97k | dns_name_init(&name, NULL); |
87 | 1.97k | return (dns_name_fromwire(&name, source, dctx, target)); |
88 | 1.97k | } |
89 | | |
90 | | static isc_result_t |
91 | 725 | towire_ns(ARGS_TOWIRE) { |
92 | 725 | dns_name_t name; |
93 | 725 | dns_offsets_t offsets; |
94 | 725 | isc_region_t region; |
95 | | |
96 | 725 | REQUIRE(rdata->type == dns_rdatatype_ns); |
97 | 725 | REQUIRE(rdata->length != 0); |
98 | | |
99 | 725 | dns_compress_setpermitted(cctx, true); |
100 | | |
101 | 725 | dns_name_init(&name, offsets); |
102 | 725 | dns_rdata_toregion(rdata, ®ion); |
103 | 725 | dns_name_fromregion(&name, ®ion); |
104 | | |
105 | 725 | return (dns_name_towire(&name, cctx, target)); |
106 | 725 | } |
107 | | |
108 | | static int |
109 | 7.00M | compare_ns(ARGS_COMPARE) { |
110 | 7.00M | dns_name_t name1; |
111 | 7.00M | dns_name_t name2; |
112 | 7.00M | isc_region_t region1; |
113 | 7.00M | isc_region_t region2; |
114 | | |
115 | 7.00M | REQUIRE(rdata1->type == rdata2->type); |
116 | 7.00M | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
117 | 7.00M | REQUIRE(rdata1->type == dns_rdatatype_ns); |
118 | 7.00M | REQUIRE(rdata1->length != 0); |
119 | 7.00M | REQUIRE(rdata2->length != 0); |
120 | | |
121 | 7.00M | dns_name_init(&name1, NULL); |
122 | 7.00M | dns_name_init(&name2, NULL); |
123 | | |
124 | 7.00M | dns_rdata_toregion(rdata1, ®ion1); |
125 | 7.00M | dns_rdata_toregion(rdata2, ®ion2); |
126 | | |
127 | 7.00M | dns_name_fromregion(&name1, ®ion1); |
128 | 7.00M | dns_name_fromregion(&name2, ®ion2); |
129 | | |
130 | 7.00M | return (dns_name_rdatacompare(&name1, &name2)); |
131 | 7.00M | } |
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 | ns->common.rdclass = rdata->rdclass; |
161 | 2 | ns->common.rdtype = rdata->type; |
162 | 2 | ISC_LINK_INIT(&ns->common, link); |
163 | | |
164 | 2 | dns_name_init(&name, NULL); |
165 | 2 | dns_rdata_toregion(rdata, ®ion); |
166 | 2 | dns_name_fromregion(&name, ®ion); |
167 | 2 | dns_name_init(&ns->name, NULL); |
168 | 2 | name_duporclone(&name, mctx, &ns->name); |
169 | 2 | ns->mctx = mctx; |
170 | 2 | return (ISC_R_SUCCESS); |
171 | 2 | } |
172 | | |
173 | | static void |
174 | 0 | freestruct_ns(ARGS_FREESTRUCT) { |
175 | 0 | dns_rdata_ns_t *ns = source; |
176 | |
|
177 | 0 | REQUIRE(ns != NULL); |
178 | |
|
179 | 0 | if (ns->mctx == NULL) { |
180 | 0 | return; |
181 | 0 | } |
182 | | |
183 | 0 | dns_name_free(&ns->name, ns->mctx); |
184 | 0 | ns->mctx = NULL; |
185 | 0 | } |
186 | | |
187 | | static isc_result_t |
188 | 0 | additionaldata_ns(ARGS_ADDLDATA) { |
189 | 0 | dns_name_t name; |
190 | 0 | dns_offsets_t offsets; |
191 | 0 | isc_region_t region; |
192 | |
|
193 | 0 | REQUIRE(rdata->type == dns_rdatatype_ns); |
194 | |
|
195 | 0 | UNUSED(owner); |
196 | |
|
197 | 0 | dns_name_init(&name, offsets); |
198 | 0 | dns_rdata_toregion(rdata, ®ion); |
199 | 0 | dns_name_fromregion(&name, ®ion); |
200 | |
|
201 | 0 | return ((add)(arg, &name, dns_rdatatype_a, NULL DNS__DB_FILELINE)); |
202 | 0 | } |
203 | | |
204 | | static isc_result_t |
205 | 0 | digest_ns(ARGS_DIGEST) { |
206 | 0 | isc_region_t r; |
207 | 0 | dns_name_t name; |
208 | |
|
209 | 0 | REQUIRE(rdata->type == dns_rdatatype_ns); |
210 | |
|
211 | 0 | dns_rdata_toregion(rdata, &r); |
212 | 0 | dns_name_init(&name, NULL); |
213 | 0 | dns_name_fromregion(&name, &r); |
214 | |
|
215 | 0 | return (dns_name_digest(&name, digest, arg)); |
216 | 0 | } |
217 | | |
218 | | static bool |
219 | 0 | checkowner_ns(ARGS_CHECKOWNER) { |
220 | 0 | REQUIRE(type == dns_rdatatype_ns); |
221 | |
|
222 | 0 | UNUSED(name); |
223 | 0 | UNUSED(type); |
224 | 0 | UNUSED(rdclass); |
225 | 0 | UNUSED(wildcard); |
226 | |
|
227 | 0 | return (true); |
228 | 0 | } |
229 | | |
230 | | static bool |
231 | 0 | checknames_ns(ARGS_CHECKNAMES) { |
232 | 0 | isc_region_t region; |
233 | 0 | dns_name_t name; |
234 | |
|
235 | 0 | REQUIRE(rdata->type == dns_rdatatype_ns); |
236 | |
|
237 | 0 | UNUSED(owner); |
238 | |
|
239 | 0 | dns_rdata_toregion(rdata, ®ion); |
240 | 0 | dns_name_init(&name, NULL); |
241 | 0 | dns_name_fromregion(&name, ®ion); |
242 | 0 | if (!dns_name_ishostname(&name, false)) { |
243 | 0 | if (bad != NULL) { |
244 | 0 | dns_name_clone(&name, bad); |
245 | 0 | } |
246 | 0 | return (false); |
247 | 0 | } |
248 | 0 | return (true); |
249 | 0 | } |
250 | | |
251 | | static int |
252 | 0 | casecompare_ns(ARGS_COMPARE) { |
253 | 0 | return (compare_ns(rdata1, rdata2)); |
254 | 0 | } |
255 | | |
256 | | #endif /* RDATA_GENERIC_NS_2_C */ |