/src/bind9/lib/dns/rdata/generic/rp_17.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_RP_17_C |
17 | | #define RDATA_GENERIC_RP_17_C |
18 | | |
19 | 17.0k | #define RRTYPE_RP_ATTRIBUTES (0) |
20 | | |
21 | | static isc_result_t |
22 | 6.32k | fromtext_rp(ARGS_FROMTEXT) { |
23 | 6.32k | isc_token_t token; |
24 | 6.32k | isc_buffer_t buffer; |
25 | 6.32k | int i; |
26 | 6.32k | bool ok; |
27 | | |
28 | 6.32k | REQUIRE(type == dns_rdatatype_rp); |
29 | | |
30 | 6.32k | UNUSED(type); |
31 | 6.32k | UNUSED(rdclass); |
32 | 6.32k | UNUSED(callbacks); |
33 | | |
34 | 6.32k | if (origin == NULL) { |
35 | 4 | origin = dns_rootname; |
36 | 4 | } |
37 | | |
38 | 18.9k | for (i = 0; i < 2; i++) { |
39 | 12.6k | dns_fixedname_t fn; |
40 | 12.6k | dns_name_t *name = dns_fixedname_initname(&fn); |
41 | | |
42 | 12.6k | RETERR(isc_lex_getmastertoken(lexer, &token, |
43 | 12.6k | isc_tokentype_string, false)); |
44 | 12.6k | buffer_fromregion(&buffer, &token.value.as_region); |
45 | | |
46 | 12.6k | RETTOK(dns_name_fromtext(name, &buffer, origin, options)); |
47 | 12.6k | RETTOK(dns_name_towire(name, NULL, target)); |
48 | | |
49 | 12.6k | ok = true; |
50 | 12.6k | if ((options & DNS_RDATA_CHECKNAMES) != 0 && i == 0) { |
51 | 0 | ok = dns_name_ismailbox(name); |
52 | 0 | } |
53 | 12.6k | if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { |
54 | 0 | RETTOK(DNS_R_BADNAME); |
55 | 0 | } |
56 | 12.6k | if (!ok && callbacks != NULL) { |
57 | 0 | warn_badname(name, lexer, callbacks); |
58 | 0 | } |
59 | 12.6k | } |
60 | 6.31k | return ISC_R_SUCCESS; |
61 | 6.32k | } |
62 | | |
63 | | static isc_result_t |
64 | 1.70k | totext_rp(ARGS_TOTEXT) { |
65 | 1.70k | isc_region_t region; |
66 | 1.70k | dns_name_t rmail; |
67 | 1.70k | dns_name_t email; |
68 | 1.70k | dns_name_t prefix; |
69 | 1.70k | unsigned int opts; |
70 | | |
71 | 1.70k | REQUIRE(rdata->type == dns_rdatatype_rp); |
72 | 1.70k | REQUIRE(rdata->length != 0); |
73 | | |
74 | 1.70k | dns_name_init(&rmail); |
75 | 1.70k | dns_name_init(&email); |
76 | 1.70k | dns_name_init(&prefix); |
77 | | |
78 | 1.70k | dns_rdata_toregion(rdata, ®ion); |
79 | | |
80 | 1.70k | dns_name_fromregion(&rmail, ®ion); |
81 | 1.70k | isc_region_consume(®ion, rmail.length); |
82 | | |
83 | 1.70k | dns_name_fromregion(&email, ®ion); |
84 | 1.70k | isc_region_consume(®ion, email.length); |
85 | | |
86 | 1.70k | opts = name_prefix(&rmail, tctx->origin, &prefix) |
87 | 1.70k | ? DNS_NAME_OMITFINALDOT |
88 | 1.70k | : 0; |
89 | 1.70k | RETERR(dns_name_totext(&prefix, opts, target)); |
90 | | |
91 | 1.70k | RETERR(str_totext(" ", target)); |
92 | | |
93 | 1.70k | opts = name_prefix(&email, tctx->origin, &prefix) |
94 | 1.70k | ? DNS_NAME_OMITFINALDOT |
95 | 1.70k | : 0; |
96 | 1.70k | return dns_name_totext(&prefix, opts, target); |
97 | 1.70k | } |
98 | | |
99 | | static isc_result_t |
100 | 2.40k | fromwire_rp(ARGS_FROMWIRE) { |
101 | 2.40k | dns_name_t rmail; |
102 | 2.40k | dns_name_t email; |
103 | | |
104 | 2.40k | REQUIRE(type == dns_rdatatype_rp); |
105 | | |
106 | 2.40k | UNUSED(type); |
107 | 2.40k | UNUSED(rdclass); |
108 | | |
109 | 2.40k | dctx = dns_decompress_setpermitted(dctx, false); |
110 | | |
111 | 2.40k | dns_name_init(&rmail); |
112 | 2.40k | dns_name_init(&email); |
113 | | |
114 | 2.40k | RETERR(dns_name_fromwire(&rmail, source, dctx, target)); |
115 | 2.28k | return dns_name_fromwire(&email, source, dctx, target); |
116 | 2.40k | } |
117 | | |
118 | | static isc_result_t |
119 | 853 | towire_rp(ARGS_TOWIRE) { |
120 | 853 | isc_region_t region; |
121 | 853 | dns_name_t rmail; |
122 | 853 | dns_name_t email; |
123 | | |
124 | 853 | REQUIRE(rdata->type == dns_rdatatype_rp); |
125 | 853 | REQUIRE(rdata->length != 0); |
126 | | |
127 | 853 | dns_compress_setpermitted(cctx, false); |
128 | 853 | dns_name_init(&rmail); |
129 | 853 | dns_name_init(&email); |
130 | | |
131 | 853 | dns_rdata_toregion(rdata, ®ion); |
132 | | |
133 | 853 | dns_name_fromregion(&rmail, ®ion); |
134 | 853 | isc_region_consume(®ion, rmail.length); |
135 | | |
136 | 853 | RETERR(dns_name_towire(&rmail, cctx, target)); |
137 | | |
138 | 852 | dns_name_fromregion(&rmail, ®ion); |
139 | 852 | isc_region_consume(®ion, rmail.length); |
140 | | |
141 | 852 | return dns_name_towire(&rmail, cctx, target); |
142 | 853 | } |
143 | | |
144 | | static int |
145 | 8.55M | compare_rp(ARGS_COMPARE) { |
146 | 8.55M | isc_region_t region1; |
147 | 8.55M | isc_region_t region2; |
148 | 8.55M | dns_name_t name1; |
149 | 8.55M | dns_name_t name2; |
150 | 8.55M | int order; |
151 | | |
152 | 8.55M | REQUIRE(rdata1->type == rdata2->type); |
153 | 8.55M | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
154 | 8.55M | REQUIRE(rdata1->type == dns_rdatatype_rp); |
155 | 8.55M | REQUIRE(rdata1->length != 0); |
156 | 8.55M | REQUIRE(rdata2->length != 0); |
157 | | |
158 | 8.55M | dns_name_init(&name1); |
159 | 8.55M | dns_name_init(&name2); |
160 | | |
161 | 8.55M | dns_rdata_toregion(rdata1, ®ion1); |
162 | 8.55M | dns_rdata_toregion(rdata2, ®ion2); |
163 | | |
164 | 8.55M | dns_name_fromregion(&name1, ®ion1); |
165 | 8.55M | dns_name_fromregion(&name2, ®ion2); |
166 | | |
167 | 8.55M | order = dns_name_rdatacompare(&name1, &name2); |
168 | 8.55M | if (order != 0) { |
169 | 8.55M | return order; |
170 | 8.55M | } |
171 | | |
172 | 2.65k | isc_region_consume(®ion1, name_length(&name1)); |
173 | 2.65k | isc_region_consume(®ion2, name_length(&name2)); |
174 | | |
175 | 2.65k | dns_name_init(&name1); |
176 | 2.65k | dns_name_init(&name2); |
177 | | |
178 | 2.65k | dns_name_fromregion(&name1, ®ion1); |
179 | 2.65k | dns_name_fromregion(&name2, ®ion2); |
180 | | |
181 | 2.65k | return dns_name_rdatacompare(&name1, &name2); |
182 | 8.55M | } |
183 | | |
184 | | static isc_result_t |
185 | 0 | fromstruct_rp(ARGS_FROMSTRUCT) { |
186 | 0 | dns_rdata_rp_t *rp = source; |
187 | 0 | isc_region_t region; |
188 | |
|
189 | 0 | REQUIRE(type == dns_rdatatype_rp); |
190 | 0 | REQUIRE(rp != NULL); |
191 | 0 | REQUIRE(rp->common.rdtype == type); |
192 | 0 | REQUIRE(rp->common.rdclass == rdclass); |
193 | |
|
194 | 0 | UNUSED(type); |
195 | 0 | UNUSED(rdclass); |
196 | |
|
197 | 0 | dns_name_toregion(&rp->mail, ®ion); |
198 | 0 | RETERR(isc_buffer_copyregion(target, ®ion)); |
199 | 0 | dns_name_toregion(&rp->text, ®ion); |
200 | 0 | return isc_buffer_copyregion(target, ®ion); |
201 | 0 | } |
202 | | |
203 | | static isc_result_t |
204 | 0 | tostruct_rp(ARGS_TOSTRUCT) { |
205 | 0 | isc_region_t region; |
206 | 0 | dns_rdata_rp_t *rp = target; |
207 | 0 | dns_name_t name; |
208 | |
|
209 | 0 | REQUIRE(rdata->type == dns_rdatatype_rp); |
210 | 0 | REQUIRE(rp != NULL); |
211 | 0 | REQUIRE(rdata->length != 0); |
212 | |
|
213 | 0 | DNS_RDATACOMMON_INIT(rp, rdata->type, rdata->rdclass); |
214 | |
|
215 | 0 | dns_name_init(&name); |
216 | 0 | dns_rdata_toregion(rdata, ®ion); |
217 | 0 | dns_name_fromregion(&name, ®ion); |
218 | 0 | dns_name_init(&rp->mail); |
219 | 0 | name_duporclone(&name, mctx, &rp->mail); |
220 | 0 | isc_region_consume(®ion, name_length(&name)); |
221 | 0 | dns_name_fromregion(&name, ®ion); |
222 | 0 | dns_name_init(&rp->text); |
223 | 0 | name_duporclone(&name, mctx, &rp->text); |
224 | 0 | rp->mctx = mctx; |
225 | 0 | return ISC_R_SUCCESS; |
226 | 0 | } |
227 | | |
228 | | static void |
229 | 0 | freestruct_rp(ARGS_FREESTRUCT) { |
230 | 0 | dns_rdata_rp_t *rp = source; |
231 | |
|
232 | 0 | REQUIRE(rp != NULL); |
233 | 0 | REQUIRE(rp->common.rdtype == dns_rdatatype_rp); |
234 | |
|
235 | 0 | if (rp->mctx == NULL) { |
236 | 0 | return; |
237 | 0 | } |
238 | | |
239 | 0 | dns_name_free(&rp->mail, rp->mctx); |
240 | 0 | dns_name_free(&rp->text, rp->mctx); |
241 | 0 | rp->mctx = NULL; |
242 | 0 | } |
243 | | |
244 | | static isc_result_t |
245 | 0 | additionaldata_rp(ARGS_ADDLDATA) { |
246 | 0 | REQUIRE(rdata->type == dns_rdatatype_rp); |
247 | |
|
248 | 0 | UNUSED(rdata); |
249 | 0 | UNUSED(owner); |
250 | 0 | UNUSED(add); |
251 | 0 | UNUSED(arg); |
252 | |
|
253 | 0 | return ISC_R_SUCCESS; |
254 | 0 | } |
255 | | |
256 | | static isc_result_t |
257 | 0 | digest_rp(ARGS_DIGEST) { |
258 | 0 | isc_region_t r; |
259 | 0 | dns_name_t name; |
260 | |
|
261 | 0 | REQUIRE(rdata->type == dns_rdatatype_rp); |
262 | |
|
263 | 0 | dns_rdata_toregion(rdata, &r); |
264 | 0 | dns_name_init(&name); |
265 | |
|
266 | 0 | dns_name_fromregion(&name, &r); |
267 | 0 | RETERR(dns_name_digest(&name, digest, arg)); |
268 | 0 | isc_region_consume(&r, name_length(&name)); |
269 | |
|
270 | 0 | dns_name_init(&name); |
271 | 0 | dns_name_fromregion(&name, &r); |
272 | |
|
273 | 0 | return dns_name_digest(&name, digest, arg); |
274 | 0 | } |
275 | | |
276 | | static bool |
277 | 0 | checkowner_rp(ARGS_CHECKOWNER) { |
278 | 0 | REQUIRE(type == dns_rdatatype_rp); |
279 | |
|
280 | 0 | UNUSED(name); |
281 | 0 | UNUSED(type); |
282 | 0 | UNUSED(rdclass); |
283 | 0 | UNUSED(wildcard); |
284 | |
|
285 | 0 | return true; |
286 | 0 | } |
287 | | |
288 | | static bool |
289 | 0 | checknames_rp(ARGS_CHECKNAMES) { |
290 | 0 | isc_region_t region; |
291 | 0 | dns_name_t name; |
292 | |
|
293 | 0 | REQUIRE(rdata->type == dns_rdatatype_rp); |
294 | |
|
295 | 0 | UNUSED(owner); |
296 | |
|
297 | 0 | dns_rdata_toregion(rdata, ®ion); |
298 | 0 | dns_name_init(&name); |
299 | 0 | dns_name_fromregion(&name, ®ion); |
300 | 0 | if (!dns_name_ismailbox(&name)) { |
301 | 0 | if (bad != NULL) { |
302 | 0 | dns_name_clone(&name, bad); |
303 | 0 | } |
304 | 0 | return false; |
305 | 0 | } |
306 | 0 | return true; |
307 | 0 | } |
308 | | |
309 | | static int |
310 | 0 | casecompare_rp(ARGS_COMPARE) { |
311 | 0 | return compare_rp(rdata1, rdata2); |
312 | 0 | } |
313 | | #endif /* RDATA_GENERIC_RP_17_C */ |