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