/src/bind9/lib/dns/rdata/generic/dsync_66.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_DSYNC_66_C |
15 | | #define RDATA_GENERIC_DSYNC_66_C |
16 | | |
17 | | #include <string.h> |
18 | | |
19 | | #include <isc/net.h> |
20 | | |
21 | | #include <dns/dsync.h> |
22 | | #include <dns/fixedname.h> |
23 | | |
24 | 76.3k | #define RRTYPE_DSYNC_ATTRIBUTES (0) |
25 | | |
26 | | static isc_result_t |
27 | 1.29M | fromtext_dsync(ARGS_FROMTEXT) { |
28 | 1.29M | isc_token_t token; |
29 | 1.29M | isc_result_t result; |
30 | 1.29M | dns_fixedname_t fn; |
31 | 1.29M | dns_name_t *name = dns_fixedname_initname(&fn); |
32 | 1.29M | isc_buffer_t buffer; |
33 | 1.29M | dns_rdatatype_t rrtype; |
34 | 1.29M | dns_dsyncscheme_t scheme; |
35 | 1.29M | bool ok = true; |
36 | | |
37 | 1.29M | REQUIRE(type == dns_rdatatype_dsync); |
38 | | |
39 | 1.29M | UNUSED(type); |
40 | 1.29M | UNUSED(rdclass); |
41 | 1.29M | UNUSED(callbacks); |
42 | | |
43 | | /* |
44 | | * RRtype |
45 | | */ |
46 | 1.29M | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
47 | 1.29M | false)); |
48 | 1.29M | result = dns_rdatatype_fromtext(&rrtype, &token.value.as_textregion); |
49 | 1.29M | if (result != ISC_R_SUCCESS && result != ISC_R_NOTIMPLEMENTED) { |
50 | 1.27M | char *e = NULL; |
51 | 1.27M | long i = strtol(DNS_AS_STR(token), &e, 10); |
52 | 1.27M | if (i < 0 || i > 65535) { |
53 | 264 | RETTOK(ISC_R_RANGE); |
54 | 264 | } |
55 | 1.27M | if (*e != 0) { |
56 | 16 | RETTOK(result); |
57 | 16 | } |
58 | 1.27M | rrtype = (dns_rdatatype_t)i; |
59 | 1.27M | } |
60 | 1.29M | RETERR(uint16_tobuffer(rrtype, target)); |
61 | | |
62 | | /* |
63 | | * Scheme |
64 | | */ |
65 | 1.29M | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
66 | 1.29M | false)); |
67 | 1.29M | RETERR(dns_dsyncscheme_fromtext(&scheme, &token.value.as_textregion)); |
68 | 1.29M | RETERR(uint8_tobuffer(scheme, target)); |
69 | | |
70 | | /* |
71 | | * Port |
72 | | */ |
73 | 1.29M | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
74 | 1.29M | false)); |
75 | 1.29M | if (token.value.as_ulong > 0xffffU) { |
76 | 23 | RETTOK(ISC_R_RANGE); |
77 | 23 | } |
78 | 1.29M | RETERR(uint16_tobuffer(token.value.as_ulong, target)); |
79 | | |
80 | | /* |
81 | | * Target |
82 | | */ |
83 | 1.29M | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
84 | 1.29M | false)); |
85 | | |
86 | 1.29M | buffer_fromregion(&buffer, &token.value.as_region); |
87 | 1.29M | if (origin == NULL) { |
88 | 7 | origin = dns_rootname; |
89 | 7 | } |
90 | 1.29M | RETTOK(dns_name_fromtext(name, &buffer, origin, options)); |
91 | 1.29M | RETTOK(dns_name_towire(name, NULL, target)); |
92 | 1.29M | if ((options & DNS_RDATA_CHECKNAMES) != 0) { |
93 | 0 | ok = dns_name_ishostname(name, false); |
94 | 0 | } |
95 | 1.29M | if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { |
96 | 0 | RETTOK(DNS_R_BADNAME); |
97 | 0 | } |
98 | 1.29M | if (!ok && callbacks != NULL) { |
99 | 0 | warn_badname(name, lexer, callbacks); |
100 | 0 | } |
101 | 1.29M | return ISC_R_SUCCESS; |
102 | 1.29M | } |
103 | | |
104 | | static isc_result_t |
105 | 1.12k | totext_dsync(ARGS_TOTEXT) { |
106 | 1.12k | isc_region_t region; |
107 | 1.12k | dns_name_t name; |
108 | 1.12k | dns_name_t prefix; |
109 | 1.12k | unsigned int opts; |
110 | 1.12k | char buf[sizeof("TYPE64000")]; |
111 | 1.12k | unsigned short num; |
112 | 1.12k | dns_rdatatype_t type; |
113 | 1.12k | dns_dsyncscheme_t scheme; |
114 | | |
115 | 1.12k | REQUIRE(rdata->type == dns_rdatatype_dsync); |
116 | 1.12k | REQUIRE(rdata->length != 0); |
117 | | |
118 | 1.12k | dns_name_init(&name); |
119 | 1.12k | dns_name_init(&prefix); |
120 | | |
121 | 1.12k | dns_rdata_toregion(rdata, ®ion); |
122 | | |
123 | | /* |
124 | | * Type. |
125 | | */ |
126 | 1.12k | type = uint16_fromregion(®ion); |
127 | 1.12k | isc_region_consume(®ion, 2); |
128 | | /* |
129 | | * XXXAG We should have something like dns_rdatatype_isknown() |
130 | | * that does the right thing with type 0. |
131 | | */ |
132 | 1.12k | if (dns_rdatatype_isknown(type) && type != 0) { |
133 | 477 | RETERR(dns_rdatatype_totext(type, target)); |
134 | 651 | } else { |
135 | 651 | snprintf(buf, sizeof(buf), "TYPE%u", type); |
136 | 651 | RETERR(str_totext(buf, target)); |
137 | 651 | } |
138 | 1.12k | RETERR(str_totext(" ", target)); |
139 | | |
140 | | /* |
141 | | * Scheme. |
142 | | */ |
143 | 1.12k | scheme = uint8_fromregion(®ion); |
144 | 1.12k | isc_region_consume(®ion, 1); |
145 | 1.12k | RETERR(dns_dsyncscheme_totext(scheme, target)); |
146 | | |
147 | 1.12k | RETERR(str_totext(" ", target)); |
148 | | |
149 | | /* |
150 | | * Port |
151 | | */ |
152 | 1.12k | num = uint16_fromregion(®ion); |
153 | 1.12k | isc_region_consume(®ion, 2); |
154 | 1.12k | snprintf(buf, sizeof(buf), "%u", num); |
155 | 1.12k | RETERR(str_totext(buf, target)); |
156 | | |
157 | 1.12k | RETERR(str_totext(" ", target)); |
158 | | |
159 | | /* |
160 | | * Target |
161 | | */ |
162 | 1.12k | dns_name_fromregion(&name, ®ion); |
163 | 1.12k | opts = name_prefix(&name, tctx->origin, &prefix) ? DNS_NAME_OMITFINALDOT |
164 | 1.12k | : 0; |
165 | 1.12k | return dns_name_totext(&prefix, opts, target); |
166 | 1.12k | } |
167 | | |
168 | | static isc_result_t |
169 | 1.68k | fromwire_dsync(ARGS_FROMWIRE) { |
170 | 1.68k | dns_name_t name; |
171 | 1.68k | isc_region_t sregion; |
172 | | |
173 | 1.68k | REQUIRE(type == dns_rdatatype_dsync); |
174 | | |
175 | 1.68k | UNUSED(type); |
176 | 1.68k | UNUSED(rdclass); |
177 | | |
178 | 1.68k | dctx = dns_decompress_setpermitted(dctx, false); |
179 | | |
180 | 1.68k | dns_name_init(&name); |
181 | | |
182 | 1.68k | isc_buffer_activeregion(source, &sregion); |
183 | 1.68k | if (sregion.length < 5) { |
184 | 10 | return ISC_R_UNEXPECTEDEND; |
185 | 10 | } |
186 | 1.67k | RETERR(mem_tobuffer(target, sregion.base, 5)); |
187 | 1.48k | isc_buffer_forward(source, 5); |
188 | 1.48k | return dns_name_fromwire(&name, source, dctx, target); |
189 | 1.67k | } |
190 | | |
191 | | static isc_result_t |
192 | 585 | towire_dsync(ARGS_TOWIRE) { |
193 | 585 | dns_name_t name; |
194 | 585 | isc_region_t region; |
195 | | |
196 | 585 | REQUIRE(rdata->type == dns_rdatatype_dsync); |
197 | 585 | REQUIRE(rdata->length != 0); |
198 | | |
199 | 585 | dns_compress_setpermitted(cctx, false); |
200 | | |
201 | 585 | dns_rdata_toregion(rdata, ®ion); |
202 | 585 | RETERR(mem_tobuffer(target, region.base, 5)); |
203 | 584 | isc_region_consume(®ion, 5); |
204 | | |
205 | 584 | dns_name_init(&name); |
206 | 584 | dns_name_fromregion(&name, ®ion); |
207 | | |
208 | 584 | return dns_name_towire(&name, cctx, target); |
209 | 585 | } |
210 | | |
211 | | static int |
212 | 122M | compare_dsync(ARGS_COMPARE) { |
213 | 122M | isc_region_t region1; |
214 | 122M | isc_region_t region2; |
215 | | |
216 | 122M | REQUIRE(rdata1->type == rdata2->type); |
217 | 122M | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
218 | 122M | REQUIRE(rdata1->type == dns_rdatatype_dsync); |
219 | 122M | REQUIRE(rdata1->length != 0); |
220 | 122M | REQUIRE(rdata2->length != 0); |
221 | | |
222 | 122M | dns_rdata_toregion(rdata1, ®ion1); |
223 | 122M | dns_rdata_toregion(rdata2, ®ion2); |
224 | 122M | return isc_region_compare(®ion1, ®ion2); |
225 | 122M | } |
226 | | |
227 | | static isc_result_t |
228 | 0 | fromstruct_dsync(ARGS_FROMSTRUCT) { |
229 | 0 | dns_rdata_dsync_t *dsync = source; |
230 | 0 | isc_region_t region; |
231 | |
|
232 | 0 | REQUIRE(type == dns_rdatatype_dsync); |
233 | 0 | REQUIRE(dsync != NULL); |
234 | 0 | REQUIRE(dsync->common.rdtype == type); |
235 | 0 | REQUIRE(dsync->common.rdclass == rdclass); |
236 | |
|
237 | 0 | UNUSED(type); |
238 | 0 | UNUSED(rdclass); |
239 | |
|
240 | 0 | RETERR(uint16_tobuffer(dsync->type, target)); |
241 | 0 | RETERR(uint8_tobuffer(dsync->scheme, target)); |
242 | 0 | RETERR(uint16_tobuffer(dsync->port, target)); |
243 | 0 | dns_name_toregion(&dsync->target, ®ion); |
244 | 0 | return isc_buffer_copyregion(target, ®ion); |
245 | 0 | } |
246 | | |
247 | | static isc_result_t |
248 | 0 | tostruct_dsync(ARGS_TOSTRUCT) { |
249 | 0 | isc_region_t region; |
250 | 0 | dns_rdata_dsync_t *dsync = target; |
251 | 0 | dns_name_t name; |
252 | |
|
253 | 0 | REQUIRE(rdata->type == dns_rdatatype_dsync); |
254 | 0 | REQUIRE(dsync != NULL); |
255 | 0 | REQUIRE(rdata->length != 0); |
256 | |
|
257 | 0 | DNS_RDATACOMMON_INIT(dsync, rdata->type, rdata->rdclass); |
258 | |
|
259 | 0 | dns_name_init(&name); |
260 | 0 | dns_rdata_toregion(rdata, ®ion); |
261 | 0 | dsync->type = uint16_fromregion(®ion); |
262 | 0 | isc_region_consume(®ion, 2); |
263 | 0 | dsync->scheme = uint8_fromregion(®ion); |
264 | 0 | isc_region_consume(®ion, 1); |
265 | 0 | dsync->port = uint16_fromregion(®ion); |
266 | 0 | isc_region_consume(®ion, 2); |
267 | 0 | dns_name_fromregion(&name, ®ion); |
268 | 0 | dns_name_init(&dsync->target); |
269 | 0 | name_duporclone(&name, mctx, &dsync->target); |
270 | 0 | dsync->mctx = mctx; |
271 | 0 | return ISC_R_SUCCESS; |
272 | 0 | } |
273 | | |
274 | | static void |
275 | 0 | freestruct_dsync(ARGS_FREESTRUCT) { |
276 | 0 | dns_rdata_dsync_t *dsync = source; |
277 | |
|
278 | 0 | REQUIRE(dsync != NULL); |
279 | 0 | REQUIRE(dsync->common.rdtype == dns_rdatatype_dsync); |
280 | |
|
281 | 0 | if (dsync->mctx == NULL) { |
282 | 0 | return; |
283 | 0 | } |
284 | | |
285 | 0 | dns_name_free(&dsync->target, dsync->mctx); |
286 | 0 | dsync->mctx = NULL; |
287 | 0 | } |
288 | | |
289 | | static isc_result_t |
290 | 0 | additionaldata_dsync(ARGS_ADDLDATA) { |
291 | 0 | dns_name_t name; |
292 | 0 | isc_region_t region; |
293 | |
|
294 | 0 | REQUIRE(rdata->type == dns_rdatatype_dsync); |
295 | |
|
296 | 0 | UNUSED(owner); |
297 | |
|
298 | 0 | dns_name_init(&name); |
299 | 0 | dns_rdata_toregion(rdata, ®ion); |
300 | 0 | isc_region_consume(®ion, 5); |
301 | 0 | dns_name_fromregion(&name, ®ion); |
302 | |
|
303 | 0 | if (dns_name_equal(&name, dns_rootname)) { |
304 | 0 | return ISC_R_SUCCESS; |
305 | 0 | } |
306 | | |
307 | 0 | return (add)(arg, &name, dns_rdatatype_a, NULL DNS__DB_FILELINE); |
308 | 0 | } |
309 | | |
310 | | static isc_result_t |
311 | 0 | digest_dsync(ARGS_DIGEST) { |
312 | 0 | isc_region_t r1; |
313 | |
|
314 | 0 | REQUIRE(rdata->type == dns_rdatatype_dsync); |
315 | |
|
316 | 0 | dns_rdata_toregion(rdata, &r1); |
317 | 0 | return (digest)(arg, &r1); |
318 | 0 | } |
319 | | |
320 | | static bool |
321 | 0 | checkowner_dsync(ARGS_CHECKOWNER) { |
322 | 0 | REQUIRE(type == dns_rdatatype_dsync); |
323 | |
|
324 | 0 | UNUSED(name); |
325 | 0 | UNUSED(rdclass); |
326 | 0 | UNUSED(type); |
327 | 0 | UNUSED(wildcard); |
328 | |
|
329 | 0 | return true; |
330 | 0 | } |
331 | | |
332 | | static bool |
333 | 0 | checknames_dsync(ARGS_CHECKNAMES) { |
334 | 0 | isc_region_t region; |
335 | 0 | dns_name_t name; |
336 | |
|
337 | 0 | REQUIRE(rdata->type == dns_rdatatype_dsync); |
338 | 0 | REQUIRE(rdata->length > 5); |
339 | |
|
340 | 0 | UNUSED(owner); |
341 | |
|
342 | 0 | dns_rdata_toregion(rdata, ®ion); |
343 | 0 | isc_region_consume(®ion, 5); |
344 | 0 | dns_name_init(&name); |
345 | 0 | dns_name_fromregion(&name, ®ion); |
346 | 0 | if (!dns_name_ishostname(&name, false)) { |
347 | 0 | if (bad != NULL) { |
348 | 0 | dns_name_clone(&name, bad); |
349 | 0 | } |
350 | 0 | return false; |
351 | 0 | } |
352 | 0 | return true; |
353 | 0 | } |
354 | | |
355 | | static int |
356 | 0 | casecompare_dsync(ARGS_COMPARE) { |
357 | 0 | return compare_dsync(rdata1, rdata2); |
358 | 0 | } |
359 | | |
360 | | #endif /* RDATA_GENERIC_DSYNC_66_C */ |