/src/bind9/lib/dns/rdata/generic/doa_259.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_DOA_259_C |
15 | | #define RDATA_GENERIC_DOA_259_C |
16 | | |
17 | 9.02k | #define RRTYPE_DOA_ATTRIBUTES (0) |
18 | | |
19 | | static isc_result_t |
20 | 550 | fromtext_doa(ARGS_FROMTEXT) { |
21 | 550 | isc_token_t token; |
22 | | |
23 | 550 | REQUIRE(type == dns_rdatatype_doa); |
24 | | |
25 | 550 | UNUSED(rdclass); |
26 | 550 | UNUSED(origin); |
27 | 550 | UNUSED(options); |
28 | 550 | UNUSED(callbacks); |
29 | | |
30 | | /* |
31 | | * DOA-ENTERPRISE |
32 | | */ |
33 | 550 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
34 | 550 | false)); |
35 | 547 | RETERR(uint32_tobuffer(token.value.as_ulong, target)); |
36 | | |
37 | | /* |
38 | | * DOA-TYPE |
39 | | */ |
40 | 547 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
41 | 547 | false)); |
42 | 542 | RETERR(uint32_tobuffer(token.value.as_ulong, target)); |
43 | | |
44 | | /* |
45 | | * DOA-LOCATION |
46 | | */ |
47 | 542 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
48 | 542 | false)); |
49 | 538 | if (token.value.as_ulong > 0xffU) { |
50 | 49 | RETTOK(ISC_R_RANGE); |
51 | 49 | } |
52 | 489 | RETERR(uint8_tobuffer(token.value.as_ulong, target)); |
53 | | |
54 | | /* |
55 | | * DOA-MEDIA-TYPE |
56 | | */ |
57 | 489 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, |
58 | 489 | false)); |
59 | 471 | RETTOK(txt_fromtext(&token.value.as_textregion, target)); |
60 | | |
61 | | /* |
62 | | * DOA-DATA |
63 | | */ |
64 | 469 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
65 | 469 | false)); |
66 | 464 | if (strcmp(DNS_AS_STR(token), "-") == 0) { |
67 | 56 | return ISC_R_SUCCESS; |
68 | 408 | } else { |
69 | 408 | isc_lex_ungettoken(lexer, &token); |
70 | 408 | return isc_base64_tobuffer(lexer, target, -1); |
71 | 408 | } |
72 | 464 | } |
73 | | |
74 | | static isc_result_t |
75 | 1.34k | totext_doa(ARGS_TOTEXT) { |
76 | 1.34k | char buf[sizeof("4294967295 ")]; |
77 | 1.34k | isc_region_t region; |
78 | 1.34k | uint32_t n; |
79 | | |
80 | 1.34k | REQUIRE(rdata != NULL); |
81 | 1.34k | REQUIRE(rdata->type == dns_rdatatype_doa); |
82 | 1.34k | REQUIRE(rdata->length != 0); |
83 | | |
84 | 1.34k | UNUSED(tctx); |
85 | | |
86 | 1.34k | dns_rdata_toregion(rdata, ®ion); |
87 | | |
88 | | /* |
89 | | * DOA-ENTERPRISE |
90 | | */ |
91 | 1.34k | n = uint32_fromregion(®ion); |
92 | 1.34k | isc_region_consume(®ion, 4); |
93 | 1.34k | snprintf(buf, sizeof(buf), "%u ", n); |
94 | 1.34k | RETERR(str_totext(buf, target)); |
95 | | |
96 | | /* |
97 | | * DOA-TYPE |
98 | | */ |
99 | 1.34k | n = uint32_fromregion(®ion); |
100 | 1.34k | isc_region_consume(®ion, 4); |
101 | 1.34k | snprintf(buf, sizeof(buf), "%u ", n); |
102 | 1.34k | RETERR(str_totext(buf, target)); |
103 | | |
104 | | /* |
105 | | * DOA-LOCATION |
106 | | */ |
107 | 1.34k | n = uint8_fromregion(®ion); |
108 | 1.34k | isc_region_consume(®ion, 1); |
109 | 1.34k | snprintf(buf, sizeof(buf), "%u ", n); |
110 | 1.34k | RETERR(str_totext(buf, target)); |
111 | | |
112 | | /* |
113 | | * DOA-MEDIA-TYPE |
114 | | */ |
115 | 1.34k | RETERR(txt_totext(®ion, true, target)); |
116 | 1.34k | RETERR(str_totext(" ", target)); |
117 | | |
118 | | /* |
119 | | * DOA-DATA |
120 | | */ |
121 | 1.34k | if (region.length == 0) { |
122 | 690 | return str_totext("-", target); |
123 | 690 | } else { |
124 | 655 | return isc_base64_totext(®ion, 60, "", target); |
125 | 655 | } |
126 | 1.34k | } |
127 | | |
128 | | static isc_result_t |
129 | 1.42k | fromwire_doa(ARGS_FROMWIRE) { |
130 | 1.42k | isc_region_t region; |
131 | | |
132 | 1.42k | UNUSED(rdclass); |
133 | 1.42k | UNUSED(dctx); |
134 | | |
135 | 1.42k | REQUIRE(type == dns_rdatatype_doa); |
136 | | |
137 | 1.42k | isc_buffer_activeregion(source, ®ion); |
138 | | /* |
139 | | * DOA-MEDIA-TYPE may be an empty <character-string> (i.e., |
140 | | * comprising of just the length octet) and DOA-DATA can have |
141 | | * zero length. |
142 | | */ |
143 | 1.42k | if (region.length < 4 + 4 + 1 + 1) { |
144 | 22 | return ISC_R_UNEXPECTEDEND; |
145 | 22 | } |
146 | | |
147 | | /* |
148 | | * Check whether DOA-MEDIA-TYPE length is not malformed. |
149 | | */ |
150 | 1.40k | if (region.base[9] > region.length - 10) { |
151 | 7 | return ISC_R_UNEXPECTEDEND; |
152 | 7 | } |
153 | | |
154 | 1.40k | isc_buffer_forward(source, region.length); |
155 | 1.40k | return mem_tobuffer(target, region.base, region.length); |
156 | 1.40k | } |
157 | | |
158 | | static isc_result_t |
159 | 713 | towire_doa(ARGS_TOWIRE) { |
160 | 713 | isc_region_t region; |
161 | | |
162 | 713 | UNUSED(cctx); |
163 | | |
164 | 713 | REQUIRE(rdata != NULL); |
165 | 713 | REQUIRE(rdata->type == dns_rdatatype_doa); |
166 | 713 | REQUIRE(rdata->length != 0); |
167 | | |
168 | 713 | dns_rdata_toregion(rdata, ®ion); |
169 | 713 | return mem_tobuffer(target, region.base, region.length); |
170 | 713 | } |
171 | | |
172 | | static int |
173 | 1.36k | compare_doa(ARGS_COMPARE) { |
174 | 1.36k | isc_region_t r1; |
175 | 1.36k | isc_region_t r2; |
176 | | |
177 | 1.36k | REQUIRE(rdata1 != NULL); |
178 | 1.36k | REQUIRE(rdata2 != NULL); |
179 | 1.36k | REQUIRE(rdata1->type == rdata2->type); |
180 | 1.36k | REQUIRE(rdata1->type == dns_rdatatype_doa); |
181 | 1.36k | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
182 | 1.36k | REQUIRE(rdata1->length != 0); |
183 | 1.36k | REQUIRE(rdata2->length != 0); |
184 | | |
185 | 1.36k | dns_rdata_toregion(rdata1, &r1); |
186 | 1.36k | dns_rdata_toregion(rdata2, &r2); |
187 | 1.36k | return isc_region_compare(&r1, &r2); |
188 | 1.36k | } |
189 | | |
190 | | static isc_result_t |
191 | 0 | fromstruct_doa(ARGS_FROMSTRUCT) { |
192 | 0 | dns_rdata_doa_t *doa = source; |
193 | |
|
194 | 0 | REQUIRE(type == dns_rdatatype_doa); |
195 | 0 | REQUIRE(doa != NULL); |
196 | 0 | REQUIRE(doa->common.rdtype == dns_rdatatype_doa); |
197 | 0 | REQUIRE(doa->common.rdclass == rdclass); |
198 | |
|
199 | 0 | RETERR(uint32_tobuffer(doa->enterprise, target)); |
200 | 0 | RETERR(uint32_tobuffer(doa->type, target)); |
201 | 0 | RETERR(uint8_tobuffer(doa->location, target)); |
202 | 0 | RETERR(uint8_tobuffer(doa->mediatype_len, target)); |
203 | 0 | RETERR(mem_tobuffer(target, doa->mediatype, doa->mediatype_len)); |
204 | 0 | return mem_tobuffer(target, doa->data, doa->data_len); |
205 | 0 | } |
206 | | |
207 | | static isc_result_t |
208 | 0 | tostruct_doa(ARGS_TOSTRUCT) { |
209 | 0 | dns_rdata_doa_t *doa = target; |
210 | 0 | isc_region_t region; |
211 | |
|
212 | 0 | REQUIRE(rdata != NULL); |
213 | 0 | REQUIRE(rdata->type == dns_rdatatype_doa); |
214 | 0 | REQUIRE(doa != NULL); |
215 | 0 | REQUIRE(rdata->length >= 10); |
216 | |
|
217 | 0 | DNS_RDATACOMMON_INIT(doa, rdata->type, rdata->rdclass); |
218 | |
|
219 | 0 | dns_rdata_toregion(rdata, ®ion); |
220 | | |
221 | | /* |
222 | | * DOA-ENTERPRISE |
223 | | */ |
224 | 0 | doa->enterprise = uint32_fromregion(®ion); |
225 | 0 | isc_region_consume(®ion, 4); |
226 | | |
227 | | /* |
228 | | * DOA-TYPE |
229 | | */ |
230 | 0 | doa->type = uint32_fromregion(®ion); |
231 | 0 | isc_region_consume(®ion, 4); |
232 | | |
233 | | /* |
234 | | * DOA-LOCATION |
235 | | */ |
236 | 0 | doa->location = uint8_fromregion(®ion); |
237 | 0 | isc_region_consume(®ion, 1); |
238 | | |
239 | | /* |
240 | | * DOA-MEDIA-TYPE |
241 | | */ |
242 | 0 | doa->mediatype_len = uint8_fromregion(®ion); |
243 | 0 | isc_region_consume(®ion, 1); |
244 | 0 | INSIST(doa->mediatype_len <= region.length); |
245 | 0 | doa->mediatype = mem_maybedup(mctx, region.base, doa->mediatype_len); |
246 | 0 | isc_region_consume(®ion, doa->mediatype_len); |
247 | | |
248 | | /* |
249 | | * DOA-DATA |
250 | | */ |
251 | 0 | doa->data_len = region.length; |
252 | 0 | doa->data = NULL; |
253 | 0 | if (doa->data_len > 0) { |
254 | 0 | doa->data = mem_maybedup(mctx, region.base, doa->data_len); |
255 | 0 | isc_region_consume(®ion, doa->data_len); |
256 | 0 | } |
257 | |
|
258 | 0 | doa->mctx = mctx; |
259 | |
|
260 | 0 | return ISC_R_SUCCESS; |
261 | 0 | } |
262 | | |
263 | | static void |
264 | 0 | freestruct_doa(ARGS_FREESTRUCT) { |
265 | 0 | dns_rdata_doa_t *doa = source; |
266 | |
|
267 | 0 | REQUIRE(doa != NULL); |
268 | 0 | REQUIRE(doa->common.rdtype == dns_rdatatype_doa); |
269 | |
|
270 | 0 | if (doa->mctx == NULL) { |
271 | 0 | return; |
272 | 0 | } |
273 | | |
274 | 0 | if (doa->mediatype != NULL) { |
275 | 0 | isc_mem_free(doa->mctx, doa->mediatype); |
276 | 0 | } |
277 | 0 | if (doa->data != NULL) { |
278 | 0 | isc_mem_free(doa->mctx, doa->data); |
279 | 0 | } |
280 | |
|
281 | 0 | doa->mctx = NULL; |
282 | 0 | } |
283 | | |
284 | | static isc_result_t |
285 | 0 | additionaldata_doa(ARGS_ADDLDATA) { |
286 | 0 | REQUIRE(rdata->type == dns_rdatatype_doa); |
287 | |
|
288 | 0 | UNUSED(rdata); |
289 | 0 | UNUSED(owner); |
290 | 0 | UNUSED(add); |
291 | 0 | UNUSED(arg); |
292 | |
|
293 | 0 | return ISC_R_SUCCESS; |
294 | 0 | } |
295 | | |
296 | | static isc_result_t |
297 | 0 | digest_doa(ARGS_DIGEST) { |
298 | 0 | isc_region_t r; |
299 | |
|
300 | 0 | REQUIRE(rdata->type == dns_rdatatype_doa); |
301 | |
|
302 | 0 | dns_rdata_toregion(rdata, &r); |
303 | |
|
304 | 0 | return (digest)(arg, &r); |
305 | 0 | } |
306 | | |
307 | | static bool |
308 | 0 | checkowner_doa(ARGS_CHECKOWNER) { |
309 | 0 | UNUSED(name); |
310 | 0 | UNUSED(type); |
311 | 0 | UNUSED(rdclass); |
312 | 0 | UNUSED(wildcard); |
313 | |
|
314 | 0 | REQUIRE(type == dns_rdatatype_doa); |
315 | |
|
316 | 0 | return true; |
317 | 0 | } |
318 | | |
319 | | static bool |
320 | 0 | checknames_doa(ARGS_CHECKNAMES) { |
321 | 0 | UNUSED(rdata); |
322 | 0 | UNUSED(owner); |
323 | 0 | UNUSED(bad); |
324 | |
|
325 | 0 | REQUIRE(rdata->type == dns_rdatatype_doa); |
326 | |
|
327 | 0 | return true; |
328 | 0 | } |
329 | | |
330 | | static int |
331 | 0 | casecompare_doa(ARGS_COMPARE) { |
332 | 0 | return compare_doa(rdata1, rdata2); |
333 | 0 | } |
334 | | |
335 | | #endif /* RDATA_GENERIC_DOA_259_C */ |