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