/src/bind9/lib/dns/rdata/generic/ptr_12.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 | | #ifndef RDATA_GENERIC_PTR_12_C |
15 | | #define RDATA_GENERIC_PTR_12_C |
16 | | |
17 | 24.2k | #define RRTYPE_PTR_ATTRIBUTES (0) |
18 | | |
19 | | static isc_result_t |
20 | 34.7k | fromtext_ptr(ARGS_FROMTEXT) { |
21 | 34.7k | isc_token_t token; |
22 | 34.7k | isc_buffer_t buffer; |
23 | 34.7k | dns_fixedname_t fn; |
24 | 34.7k | dns_name_t *name = dns_fixedname_initname(&fn); |
25 | | |
26 | 34.7k | REQUIRE(type == dns_rdatatype_ptr); |
27 | | |
28 | 34.7k | UNUSED(type); |
29 | 34.7k | UNUSED(rdclass); |
30 | 34.7k | UNUSED(callbacks); |
31 | | |
32 | 34.7k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
33 | 34.7k | false)); |
34 | | |
35 | 34.7k | buffer_fromregion(&buffer, &token.value.as_region); |
36 | 34.7k | if (origin == NULL) { |
37 | 20 | origin = dns_rootname; |
38 | 20 | } |
39 | | |
40 | 34.7k | RETTOK(dns_name_fromtext(name, &buffer, origin, options)); |
41 | 34.7k | RETTOK(dns_name_towire(name, NULL, target)); |
42 | | |
43 | 34.7k | if (rdclass == dns_rdataclass_in && |
44 | 34.6k | (options & DNS_RDATA_CHECKNAMES) != 0 && |
45 | 0 | (options & DNS_RDATA_CHECKREVERSE) != 0) |
46 | 0 | { |
47 | 0 | bool ok; |
48 | 0 | ok = dns_name_ishostname(name, false); |
49 | 0 | if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { |
50 | 0 | RETTOK(DNS_R_BADNAME); |
51 | 0 | } |
52 | 0 | if (!ok && callbacks != NULL) { |
53 | 0 | warn_badname(name, lexer, callbacks); |
54 | 0 | } |
55 | 0 | } |
56 | 34.7k | return ISC_R_SUCCESS; |
57 | 34.7k | } |
58 | | |
59 | | static isc_result_t |
60 | 1.02k | totext_ptr(ARGS_TOTEXT) { |
61 | 1.02k | isc_region_t region; |
62 | 1.02k | dns_name_t name; |
63 | 1.02k | dns_name_t prefix; |
64 | 1.02k | unsigned int opts; |
65 | | |
66 | 1.02k | REQUIRE(rdata->type == dns_rdatatype_ptr); |
67 | 1.02k | REQUIRE(rdata->length != 0); |
68 | | |
69 | 1.02k | dns_name_init(&name); |
70 | 1.02k | dns_name_init(&prefix); |
71 | | |
72 | 1.02k | dns_rdata_toregion(rdata, ®ion); |
73 | 1.02k | dns_name_fromregion(&name, ®ion); |
74 | | |
75 | 1.02k | opts = name_prefix(&name, tctx->origin, &prefix) ? DNS_NAME_OMITFINALDOT |
76 | 1.02k | : 0; |
77 | 1.02k | return dns_name_totext(&prefix, opts, target); |
78 | 1.02k | } |
79 | | |
80 | | static isc_result_t |
81 | 1.28k | fromwire_ptr(ARGS_FROMWIRE) { |
82 | 1.28k | dns_name_t name; |
83 | | |
84 | 1.28k | REQUIRE(type == dns_rdatatype_ptr); |
85 | | |
86 | 1.28k | UNUSED(type); |
87 | 1.28k | UNUSED(rdclass); |
88 | | |
89 | 1.28k | dctx = dns_decompress_setpermitted(dctx, true); |
90 | | |
91 | 1.28k | dns_name_init(&name); |
92 | 1.28k | return dns_name_fromwire(&name, source, dctx, target); |
93 | 1.28k | } |
94 | | |
95 | | static isc_result_t |
96 | 519 | towire_ptr(ARGS_TOWIRE) { |
97 | 519 | dns_name_t name; |
98 | 519 | isc_region_t region; |
99 | | |
100 | 519 | REQUIRE(rdata->type == dns_rdatatype_ptr); |
101 | 519 | REQUIRE(rdata->length != 0); |
102 | | |
103 | 519 | dns_compress_setpermitted(cctx, true); |
104 | | |
105 | 519 | dns_name_init(&name); |
106 | 519 | dns_rdata_toregion(rdata, ®ion); |
107 | 519 | dns_name_fromregion(&name, ®ion); |
108 | | |
109 | 519 | return dns_name_towire(&name, cctx, target); |
110 | 519 | } |
111 | | |
112 | | static int |
113 | 17.9M | compare_ptr(ARGS_COMPARE) { |
114 | 17.9M | dns_name_t name1; |
115 | 17.9M | dns_name_t name2; |
116 | 17.9M | isc_region_t region1; |
117 | 17.9M | isc_region_t region2; |
118 | | |
119 | 17.9M | REQUIRE(rdata1->type == rdata2->type); |
120 | 17.9M | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
121 | 17.9M | REQUIRE(rdata1->type == dns_rdatatype_ptr); |
122 | 17.9M | REQUIRE(rdata1->length != 0); |
123 | 17.9M | REQUIRE(rdata2->length != 0); |
124 | | |
125 | 17.9M | dns_name_init(&name1); |
126 | 17.9M | dns_name_init(&name2); |
127 | | |
128 | 17.9M | dns_rdata_toregion(rdata1, ®ion1); |
129 | 17.9M | dns_rdata_toregion(rdata2, ®ion2); |
130 | | |
131 | 17.9M | dns_name_fromregion(&name1, ®ion1); |
132 | 17.9M | dns_name_fromregion(&name2, ®ion2); |
133 | | |
134 | 17.9M | return dns_name_rdatacompare(&name1, &name2); |
135 | 17.9M | } |
136 | | |
137 | | static isc_result_t |
138 | 0 | fromstruct_ptr(ARGS_FROMSTRUCT) { |
139 | 0 | dns_rdata_ptr_t *ptr = source; |
140 | 0 | isc_region_t region; |
141 | |
|
142 | 0 | REQUIRE(type == dns_rdatatype_ptr); |
143 | 0 | REQUIRE(ptr != NULL); |
144 | 0 | REQUIRE(ptr->common.rdtype == type); |
145 | 0 | REQUIRE(ptr->common.rdclass == rdclass); |
146 | |
|
147 | 0 | UNUSED(type); |
148 | 0 | UNUSED(rdclass); |
149 | |
|
150 | 0 | dns_name_toregion(&ptr->ptr, ®ion); |
151 | 0 | return isc_buffer_copyregion(target, ®ion); |
152 | 0 | } |
153 | | |
154 | | static isc_result_t |
155 | 0 | tostruct_ptr(ARGS_TOSTRUCT) { |
156 | 0 | isc_region_t region; |
157 | 0 | dns_rdata_ptr_t *ptr = target; |
158 | 0 | dns_name_t name; |
159 | |
|
160 | 0 | REQUIRE(rdata->type == dns_rdatatype_ptr); |
161 | 0 | REQUIRE(ptr != NULL); |
162 | 0 | REQUIRE(rdata->length != 0); |
163 | |
|
164 | 0 | DNS_RDATACOMMON_INIT(ptr, rdata->type, rdata->rdclass); |
165 | |
|
166 | 0 | dns_name_init(&name); |
167 | 0 | dns_rdata_toregion(rdata, ®ion); |
168 | 0 | dns_name_fromregion(&name, ®ion); |
169 | 0 | dns_name_init(&ptr->ptr); |
170 | 0 | name_duporclone(&name, mctx, &ptr->ptr); |
171 | 0 | ptr->mctx = mctx; |
172 | 0 | return ISC_R_SUCCESS; |
173 | 0 | } |
174 | | |
175 | | static void |
176 | 0 | freestruct_ptr(ARGS_FREESTRUCT) { |
177 | 0 | dns_rdata_ptr_t *ptr = source; |
178 | |
|
179 | 0 | REQUIRE(ptr != NULL); |
180 | 0 | REQUIRE(ptr->common.rdtype == dns_rdatatype_ptr); |
181 | |
|
182 | 0 | if (ptr->mctx == NULL) { |
183 | 0 | return; |
184 | 0 | } |
185 | | |
186 | 0 | dns_name_free(&ptr->ptr, ptr->mctx); |
187 | 0 | ptr->mctx = NULL; |
188 | 0 | } |
189 | | |
190 | | static isc_result_t |
191 | 0 | additionaldata_ptr(ARGS_ADDLDATA) { |
192 | 0 | REQUIRE(rdata->type == dns_rdatatype_ptr); |
193 | |
|
194 | 0 | UNUSED(rdata); |
195 | 0 | UNUSED(owner); |
196 | 0 | UNUSED(add); |
197 | 0 | UNUSED(arg); |
198 | |
|
199 | 0 | return ISC_R_SUCCESS; |
200 | 0 | } |
201 | | |
202 | | static isc_result_t |
203 | 0 | digest_ptr(ARGS_DIGEST) { |
204 | 0 | isc_region_t r; |
205 | 0 | dns_name_t name; |
206 | |
|
207 | 0 | REQUIRE(rdata->type == dns_rdatatype_ptr); |
208 | |
|
209 | 0 | dns_rdata_toregion(rdata, &r); |
210 | 0 | dns_name_init(&name); |
211 | 0 | dns_name_fromregion(&name, &r); |
212 | |
|
213 | 0 | return dns_name_digest(&name, digest, arg); |
214 | 0 | } |
215 | | |
216 | | static bool |
217 | 0 | checkowner_ptr(ARGS_CHECKOWNER) { |
218 | 0 | REQUIRE(type == dns_rdatatype_ptr); |
219 | |
|
220 | 0 | UNUSED(name); |
221 | 0 | UNUSED(type); |
222 | 0 | UNUSED(rdclass); |
223 | 0 | UNUSED(wildcard); |
224 | |
|
225 | 0 | return true; |
226 | 0 | } |
227 | | |
228 | | static bool |
229 | 0 | checknames_ptr(ARGS_CHECKNAMES) { |
230 | 0 | isc_region_t region; |
231 | 0 | dns_name_t name; |
232 | |
|
233 | 0 | REQUIRE(rdata->type == dns_rdatatype_ptr); |
234 | |
|
235 | 0 | if (rdata->rdclass != dns_rdataclass_in) { |
236 | 0 | return true; |
237 | 0 | } |
238 | | |
239 | 0 | if (dns_name_isdnssd(owner)) { |
240 | 0 | return true; |
241 | 0 | } |
242 | | |
243 | 0 | if (dns_name_issubdomain(owner, dns_inaddrarpa) || |
244 | 0 | dns_name_issubdomain(owner, dns_ip6arpa) || |
245 | 0 | dns_name_issubdomain(owner, dns_ip6int)) |
246 | 0 | { |
247 | 0 | dns_rdata_toregion(rdata, ®ion); |
248 | 0 | dns_name_init(&name); |
249 | 0 | dns_name_fromregion(&name, ®ion); |
250 | 0 | if (!dns_name_ishostname(&name, false)) { |
251 | 0 | if (bad != NULL) { |
252 | 0 | dns_name_clone(&name, bad); |
253 | 0 | } |
254 | 0 | return false; |
255 | 0 | } |
256 | 0 | } |
257 | 0 | return true; |
258 | 0 | } |
259 | | |
260 | | static int |
261 | 0 | casecompare_ptr(ARGS_COMPARE) { |
262 | 0 | return compare_ptr(rdata1, rdata2); |
263 | 0 | } |
264 | | #endif /* RDATA_GENERIC_PTR_12_C */ |