/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 | 168k | #define RRTYPE_NS_ATTRIBUTES (DNS_RDATATYPEATTR_ZONECUTAUTH) |
18 | | |
19 | | static inline isc_result_t |
20 | 246k | fromtext_ns(ARGS_FROMTEXT) { |
21 | 246k | isc_token_t token; |
22 | 246k | dns_name_t name; |
23 | 246k | isc_buffer_t buffer; |
24 | 246k | bool ok; |
25 | | |
26 | 246k | REQUIRE(type == dns_rdatatype_ns); |
27 | | |
28 | 246k | UNUSED(type); |
29 | 246k | UNUSED(rdclass); |
30 | 246k | UNUSED(callbacks); |
31 | | |
32 | 246k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
33 | 246k | false)); |
34 | | |
35 | 246k | dns_name_init(&name, NULL); |
36 | 246k | buffer_fromregion(&buffer, &token.value.as_region); |
37 | 246k | if (origin == NULL) { |
38 | 25 | origin = dns_rootname; |
39 | 25 | } |
40 | 246k | RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); |
41 | 246k | ok = true; |
42 | 246k | if ((options & DNS_RDATA_CHECKNAMES) != 0) { |
43 | 0 | ok = dns_name_ishostname(&name, false); |
44 | 0 | } |
45 | 246k | if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { |
46 | 0 | RETTOK(DNS_R_BADNAME); |
47 | 0 | } |
48 | 246k | if (!ok && callbacks != NULL) { |
49 | 0 | warn_badname(&name, lexer, callbacks); |
50 | 0 | } |
51 | 246k | return (ISC_R_SUCCESS); |
52 | 246k | } |
53 | | |
54 | | static inline isc_result_t |
55 | 1.20k | totext_ns(ARGS_TOTEXT) { |
56 | 1.20k | isc_region_t region; |
57 | 1.20k | dns_name_t name; |
58 | 1.20k | dns_name_t prefix; |
59 | 1.20k | bool sub; |
60 | | |
61 | 1.20k | REQUIRE(rdata->type == dns_rdatatype_ns); |
62 | 1.20k | REQUIRE(rdata->length != 0); |
63 | | |
64 | 0 | dns_name_init(&name, NULL); |
65 | 1.20k | dns_name_init(&prefix, NULL); |
66 | | |
67 | 1.20k | dns_rdata_toregion(rdata, ®ion); |
68 | 1.20k | dns_name_fromregion(&name, ®ion); |
69 | | |
70 | 1.20k | sub = name_prefix(&name, tctx->origin, &prefix); |
71 | | |
72 | 1.20k | return (dns_name_totext(&prefix, sub, target)); |
73 | 1.20k | } |
74 | | |
75 | | static inline isc_result_t |
76 | 1.39k | fromwire_ns(ARGS_FROMWIRE) { |
77 | 1.39k | dns_name_t name; |
78 | | |
79 | 1.39k | REQUIRE(type == dns_rdatatype_ns); |
80 | | |
81 | 1.39k | UNUSED(type); |
82 | 1.39k | UNUSED(rdclass); |
83 | | |
84 | 1.39k | dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14); |
85 | | |
86 | 1.39k | dns_name_init(&name, NULL); |
87 | 1.39k | return (dns_name_fromwire(&name, source, dctx, options, target)); |
88 | 1.39k | } |
89 | | |
90 | | static inline isc_result_t |
91 | 557 | towire_ns(ARGS_TOWIRE) { |
92 | 557 | dns_name_t name; |
93 | 557 | dns_offsets_t offsets; |
94 | 557 | isc_region_t region; |
95 | | |
96 | 557 | REQUIRE(rdata->type == dns_rdatatype_ns); |
97 | 557 | REQUIRE(rdata->length != 0); |
98 | | |
99 | 557 | dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); |
100 | | |
101 | 557 | dns_name_init(&name, offsets); |
102 | 557 | dns_rdata_toregion(rdata, ®ion); |
103 | 557 | dns_name_fromregion(&name, ®ion); |
104 | | |
105 | 557 | return (dns_name_towire(&name, cctx, target)); |
106 | 557 | } |
107 | | |
108 | | static inline int |
109 | 683k | compare_ns(ARGS_COMPARE) { |
110 | 683k | dns_name_t name1; |
111 | 683k | dns_name_t name2; |
112 | 683k | isc_region_t region1; |
113 | 683k | isc_region_t region2; |
114 | | |
115 | 683k | REQUIRE(rdata1->type == rdata2->type); |
116 | 683k | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
117 | 683k | REQUIRE(rdata1->type == dns_rdatatype_ns); |
118 | 683k | REQUIRE(rdata1->length != 0); |
119 | 683k | REQUIRE(rdata2->length != 0); |
120 | | |
121 | 0 | dns_name_init(&name1, NULL); |
122 | 683k | dns_name_init(&name2, NULL); |
123 | | |
124 | 683k | dns_rdata_toregion(rdata1, ®ion1); |
125 | 683k | dns_rdata_toregion(rdata2, ®ion2); |
126 | | |
127 | 683k | dns_name_fromregion(&name1, ®ion1); |
128 | 683k | dns_name_fromregion(&name2, ®ion2); |
129 | | |
130 | 683k | return (dns_name_rdatacompare(&name1, &name2)); |
131 | 683k | } |
132 | | |
133 | | static inline 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 inline isc_result_t |
151 | 0 | tostruct_ns(ARGS_TOSTRUCT) { |
152 | 0 | isc_region_t region; |
153 | 0 | dns_rdata_ns_t *ns = target; |
154 | 0 | dns_name_t name; |
155 | |
|
156 | 0 | REQUIRE(rdata->type == dns_rdatatype_ns); |
157 | 0 | REQUIRE(ns != NULL); |
158 | 0 | REQUIRE(rdata->length != 0); |
159 | | |
160 | 0 | ns->common.rdclass = rdata->rdclass; |
161 | 0 | ns->common.rdtype = rdata->type; |
162 | 0 | ISC_LINK_INIT(&ns->common, link); |
163 | |
|
164 | 0 | dns_name_init(&name, NULL); |
165 | 0 | dns_rdata_toregion(rdata, ®ion); |
166 | 0 | dns_name_fromregion(&name, ®ion); |
167 | 0 | dns_name_init(&ns->name, NULL); |
168 | 0 | name_duporclone(&name, mctx, &ns->name); |
169 | 0 | ns->mctx = mctx; |
170 | 0 | return (ISC_R_SUCCESS); |
171 | 0 | } |
172 | | |
173 | | static inline 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 inline 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)); |
202 | 0 | } |
203 | | |
204 | | static inline 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 inline 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 inline 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 inline int |
252 | 0 | casecompare_ns(ARGS_COMPARE) { |
253 | 0 | return (compare_ns(rdata1, rdata2)); |
254 | 0 | } |
255 | | |
256 | | #endif /* RDATA_GENERIC_NS_2_C */ |