/src/bind9/lib/dns/rdata/generic/afsdb_18.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 | | /* RFC1183 */ |
15 | | |
16 | | #ifndef RDATA_GENERIC_AFSDB_18_C |
17 | | #define RDATA_GENERIC_AFSDB_18_C |
18 | | |
19 | 26.0k | #define RRTYPE_AFSDB_ATTRIBUTES (0) |
20 | | |
21 | | static isc_result_t |
22 | 8.33k | fromtext_afsdb(ARGS_FROMTEXT) { |
23 | 8.33k | isc_token_t token; |
24 | 8.33k | isc_buffer_t buffer; |
25 | 8.33k | dns_name_t name; |
26 | 8.33k | bool ok; |
27 | | |
28 | 8.33k | REQUIRE(type == dns_rdatatype_afsdb); |
29 | | |
30 | 8.33k | UNUSED(type); |
31 | 8.33k | UNUSED(rdclass); |
32 | 8.33k | UNUSED(callbacks); |
33 | | |
34 | | /* |
35 | | * Subtype. |
36 | | */ |
37 | 8.33k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
38 | 8.33k | false)); |
39 | 8.33k | if (token.value.as_ulong > 0xffffU) { |
40 | 26 | RETTOK(ISC_R_RANGE); |
41 | 26 | } |
42 | 8.30k | RETERR(uint16_tobuffer(token.value.as_ulong, target)); |
43 | | |
44 | | /* |
45 | | * Hostname. |
46 | | */ |
47 | 8.30k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
48 | 8.30k | false)); |
49 | 8.28k | dns_name_init(&name, NULL); |
50 | 8.28k | buffer_fromregion(&buffer, &token.value.as_region); |
51 | 8.28k | if (origin == NULL) { |
52 | 2 | origin = dns_rootname; |
53 | 2 | } |
54 | 8.28k | RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); |
55 | 8.27k | ok = true; |
56 | 8.27k | if ((options & DNS_RDATA_CHECKNAMES) != 0) { |
57 | 0 | ok = dns_name_ishostname(&name, false); |
58 | 0 | } |
59 | 8.27k | if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { |
60 | 0 | RETTOK(DNS_R_BADNAME); |
61 | 0 | } |
62 | 8.27k | if (!ok && callbacks != NULL) { |
63 | 0 | warn_badname(&name, lexer, callbacks); |
64 | 0 | } |
65 | 8.27k | return (ISC_R_SUCCESS); |
66 | 8.27k | } |
67 | | |
68 | | static isc_result_t |
69 | 675 | totext_afsdb(ARGS_TOTEXT) { |
70 | 675 | dns_name_t name; |
71 | 675 | dns_name_t prefix; |
72 | 675 | isc_region_t region; |
73 | 675 | char buf[sizeof("64000 ")]; |
74 | 675 | bool sub; |
75 | 675 | unsigned int num; |
76 | | |
77 | 675 | REQUIRE(rdata->type == dns_rdatatype_afsdb); |
78 | 675 | REQUIRE(rdata->length != 0); |
79 | | |
80 | 675 | dns_name_init(&name, NULL); |
81 | 675 | dns_name_init(&prefix, NULL); |
82 | | |
83 | 675 | dns_rdata_toregion(rdata, ®ion); |
84 | 675 | num = uint16_fromregion(®ion); |
85 | 675 | isc_region_consume(®ion, 2); |
86 | 675 | snprintf(buf, sizeof(buf), "%u ", num); |
87 | 675 | RETERR(str_totext(buf, target)); |
88 | 675 | dns_name_fromregion(&name, ®ion); |
89 | 675 | sub = name_prefix(&name, tctx->origin, &prefix); |
90 | 675 | return (dns_name_totext(&prefix, sub, target)); |
91 | 675 | } |
92 | | |
93 | | static isc_result_t |
94 | 8.81k | fromwire_afsdb(ARGS_FROMWIRE) { |
95 | 8.81k | dns_name_t name; |
96 | 8.81k | isc_region_t sr; |
97 | 8.81k | isc_region_t tr; |
98 | | |
99 | 8.81k | REQUIRE(type == dns_rdatatype_afsdb); |
100 | | |
101 | 8.81k | UNUSED(type); |
102 | 8.81k | UNUSED(rdclass); |
103 | | |
104 | 8.81k | dctx = dns_decompress_setpermitted(dctx, false); |
105 | | |
106 | 8.81k | dns_name_init(&name, NULL); |
107 | | |
108 | 8.81k | isc_buffer_activeregion(source, &sr); |
109 | 8.81k | isc_buffer_availableregion(target, &tr); |
110 | 8.81k | if (tr.length < 2) { |
111 | 318 | return (ISC_R_NOSPACE); |
112 | 318 | } |
113 | 8.49k | if (sr.length < 2) { |
114 | 25 | return (ISC_R_UNEXPECTEDEND); |
115 | 25 | } |
116 | 8.46k | memmove(tr.base, sr.base, 2); |
117 | 8.46k | isc_buffer_forward(source, 2); |
118 | 8.46k | isc_buffer_add(target, 2); |
119 | 8.46k | return (dns_name_fromwire(&name, source, dctx, target)); |
120 | 8.49k | } |
121 | | |
122 | | static isc_result_t |
123 | 330 | towire_afsdb(ARGS_TOWIRE) { |
124 | 330 | isc_region_t tr; |
125 | 330 | isc_region_t sr; |
126 | 330 | dns_name_t name; |
127 | 330 | dns_offsets_t offsets; |
128 | | |
129 | 330 | REQUIRE(rdata->type == dns_rdatatype_afsdb); |
130 | 330 | REQUIRE(rdata->length != 0); |
131 | | |
132 | 330 | dns_compress_setpermitted(cctx, false); |
133 | 330 | isc_buffer_availableregion(target, &tr); |
134 | 330 | dns_rdata_toregion(rdata, &sr); |
135 | 330 | if (tr.length < 2) { |
136 | 1 | return (ISC_R_NOSPACE); |
137 | 1 | } |
138 | 329 | memmove(tr.base, sr.base, 2); |
139 | 329 | isc_region_consume(&sr, 2); |
140 | 329 | isc_buffer_add(target, 2); |
141 | | |
142 | 329 | dns_name_init(&name, offsets); |
143 | 329 | dns_name_fromregion(&name, &sr); |
144 | | |
145 | 329 | return (dns_name_towire(&name, cctx, target)); |
146 | 330 | } |
147 | | |
148 | | static int |
149 | 530k | compare_afsdb(ARGS_COMPARE) { |
150 | 530k | int result; |
151 | 530k | dns_name_t name1; |
152 | 530k | dns_name_t name2; |
153 | 530k | isc_region_t region1; |
154 | 530k | isc_region_t region2; |
155 | | |
156 | 530k | REQUIRE(rdata1->type == rdata2->type); |
157 | 530k | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
158 | 530k | REQUIRE(rdata1->type == dns_rdatatype_afsdb); |
159 | 530k | REQUIRE(rdata1->length != 0); |
160 | 530k | REQUIRE(rdata2->length != 0); |
161 | | |
162 | 530k | result = memcmp(rdata1->data, rdata2->data, 2); |
163 | 530k | if (result != 0) { |
164 | 515k | return (result < 0 ? -1 : 1); |
165 | 515k | } |
166 | | |
167 | 14.7k | dns_name_init(&name1, NULL); |
168 | 14.7k | dns_name_init(&name2, NULL); |
169 | | |
170 | 14.7k | dns_rdata_toregion(rdata1, ®ion1); |
171 | 14.7k | dns_rdata_toregion(rdata2, ®ion2); |
172 | | |
173 | 14.7k | isc_region_consume(®ion1, 2); |
174 | 14.7k | isc_region_consume(®ion2, 2); |
175 | | |
176 | 14.7k | dns_name_fromregion(&name1, ®ion1); |
177 | 14.7k | dns_name_fromregion(&name2, ®ion2); |
178 | | |
179 | 14.7k | return (dns_name_rdatacompare(&name1, &name2)); |
180 | 530k | } |
181 | | |
182 | | static isc_result_t |
183 | 0 | fromstruct_afsdb(ARGS_FROMSTRUCT) { |
184 | 0 | dns_rdata_afsdb_t *afsdb = source; |
185 | 0 | isc_region_t region; |
186 | |
|
187 | 0 | REQUIRE(type == dns_rdatatype_afsdb); |
188 | 0 | REQUIRE(afsdb != NULL); |
189 | 0 | REQUIRE(afsdb->common.rdclass == rdclass); |
190 | 0 | REQUIRE(afsdb->common.rdtype == type); |
191 | |
|
192 | 0 | UNUSED(type); |
193 | 0 | UNUSED(rdclass); |
194 | |
|
195 | 0 | RETERR(uint16_tobuffer(afsdb->subtype, target)); |
196 | 0 | dns_name_toregion(&afsdb->server, ®ion); |
197 | 0 | return (isc_buffer_copyregion(target, ®ion)); |
198 | 0 | } |
199 | | |
200 | | static isc_result_t |
201 | 0 | tostruct_afsdb(ARGS_TOSTRUCT) { |
202 | 0 | isc_region_t region; |
203 | 0 | dns_rdata_afsdb_t *afsdb = target; |
204 | 0 | dns_name_t name; |
205 | |
|
206 | 0 | REQUIRE(rdata->type == dns_rdatatype_afsdb); |
207 | 0 | REQUIRE(afsdb != NULL); |
208 | 0 | REQUIRE(rdata->length != 0); |
209 | |
|
210 | 0 | afsdb->common.rdclass = rdata->rdclass; |
211 | 0 | afsdb->common.rdtype = rdata->type; |
212 | 0 | ISC_LINK_INIT(&afsdb->common, link); |
213 | |
|
214 | 0 | dns_name_init(&afsdb->server, NULL); |
215 | |
|
216 | 0 | dns_rdata_toregion(rdata, ®ion); |
217 | |
|
218 | 0 | afsdb->subtype = uint16_fromregion(®ion); |
219 | 0 | isc_region_consume(®ion, 2); |
220 | |
|
221 | 0 | dns_name_init(&name, NULL); |
222 | 0 | dns_name_fromregion(&name, ®ion); |
223 | |
|
224 | 0 | name_duporclone(&name, mctx, &afsdb->server); |
225 | 0 | afsdb->mctx = mctx; |
226 | 0 | return (ISC_R_SUCCESS); |
227 | 0 | } |
228 | | |
229 | | static void |
230 | 0 | freestruct_afsdb(ARGS_FREESTRUCT) { |
231 | 0 | dns_rdata_afsdb_t *afsdb = source; |
232 | |
|
233 | 0 | REQUIRE(afsdb != NULL); |
234 | 0 | REQUIRE(afsdb->common.rdtype == dns_rdatatype_afsdb); |
235 | |
|
236 | 0 | if (afsdb->mctx == NULL) { |
237 | 0 | return; |
238 | 0 | } |
239 | | |
240 | 0 | dns_name_free(&afsdb->server, afsdb->mctx); |
241 | 0 | afsdb->mctx = NULL; |
242 | 0 | } |
243 | | |
244 | | static isc_result_t |
245 | 0 | additionaldata_afsdb(ARGS_ADDLDATA) { |
246 | 0 | dns_name_t name; |
247 | 0 | dns_offsets_t offsets; |
248 | 0 | isc_region_t region; |
249 | |
|
250 | 0 | REQUIRE(rdata->type == dns_rdatatype_afsdb); |
251 | |
|
252 | 0 | UNUSED(owner); |
253 | |
|
254 | 0 | dns_name_init(&name, offsets); |
255 | 0 | dns_rdata_toregion(rdata, ®ion); |
256 | 0 | isc_region_consume(®ion, 2); |
257 | 0 | dns_name_fromregion(&name, ®ion); |
258 | |
|
259 | 0 | return ((add)(arg, &name, dns_rdatatype_a, NULL DNS__DB_FILELINE)); |
260 | 0 | } |
261 | | |
262 | | static isc_result_t |
263 | 0 | digest_afsdb(ARGS_DIGEST) { |
264 | 0 | isc_region_t r1, r2; |
265 | 0 | dns_name_t name; |
266 | |
|
267 | 0 | REQUIRE(rdata->type == dns_rdatatype_afsdb); |
268 | |
|
269 | 0 | dns_rdata_toregion(rdata, &r1); |
270 | 0 | r2 = r1; |
271 | 0 | isc_region_consume(&r2, 2); |
272 | 0 | r1.length = 2; |
273 | 0 | RETERR((digest)(arg, &r1)); |
274 | 0 | dns_name_init(&name, NULL); |
275 | 0 | dns_name_fromregion(&name, &r2); |
276 | |
|
277 | 0 | return (dns_name_digest(&name, digest, arg)); |
278 | 0 | } |
279 | | |
280 | | static bool |
281 | 0 | checkowner_afsdb(ARGS_CHECKOWNER) { |
282 | 0 | REQUIRE(type == dns_rdatatype_afsdb); |
283 | |
|
284 | 0 | UNUSED(name); |
285 | 0 | UNUSED(type); |
286 | 0 | UNUSED(rdclass); |
287 | 0 | UNUSED(wildcard); |
288 | |
|
289 | 0 | return (true); |
290 | 0 | } |
291 | | |
292 | | static bool |
293 | 0 | checknames_afsdb(ARGS_CHECKNAMES) { |
294 | 0 | isc_region_t region; |
295 | 0 | dns_name_t name; |
296 | |
|
297 | 0 | REQUIRE(rdata->type == dns_rdatatype_afsdb); |
298 | |
|
299 | 0 | UNUSED(owner); |
300 | |
|
301 | 0 | dns_rdata_toregion(rdata, ®ion); |
302 | 0 | isc_region_consume(®ion, 2); |
303 | 0 | dns_name_init(&name, NULL); |
304 | 0 | dns_name_fromregion(&name, ®ion); |
305 | 0 | if (!dns_name_ishostname(&name, false)) { |
306 | 0 | if (bad != NULL) { |
307 | 0 | dns_name_clone(&name, bad); |
308 | 0 | } |
309 | 0 | return (false); |
310 | 0 | } |
311 | 0 | return (true); |
312 | 0 | } |
313 | | |
314 | | static int |
315 | 0 | casecompare_afsdb(ARGS_COMPARE) { |
316 | 0 | return (compare_afsdb(rdata1, rdata2)); |
317 | 0 | } |
318 | | #endif /* RDATA_GENERIC_AFSDB_18_C */ |