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