/src/bind9/lib/dns/rdata/generic/naptr_35.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 | | /* RFC2915 */ |
15 | | |
16 | | #ifndef RDATA_GENERIC_NAPTR_35_C |
17 | | #define RDATA_GENERIC_NAPTR_35_C |
18 | | |
19 | 20.7k | #define RRTYPE_NAPTR_ATTRIBUTES (0) |
20 | | |
21 | | #include <isc/regex.h> |
22 | | |
23 | | /* |
24 | | * Check the wire format of the Regexp field. |
25 | | * Don't allow embedded NUL's. |
26 | | */ |
27 | | static isc_result_t |
28 | 10.3k | txt_valid_regex(const unsigned char *txt) { |
29 | 10.3k | unsigned int nsub = 0; |
30 | 10.3k | char regex[256]; |
31 | 10.3k | char *cp; |
32 | 10.3k | bool flags = false; |
33 | 10.3k | bool replace = false; |
34 | 10.3k | unsigned char c; |
35 | 10.3k | unsigned char delim; |
36 | 10.3k | unsigned int len; |
37 | 10.3k | int n; |
38 | | |
39 | 10.3k | len = *txt++; |
40 | 10.3k | if (len == 0U) { |
41 | 2.53k | return ISC_R_SUCCESS; |
42 | 2.53k | } |
43 | | |
44 | 7.85k | delim = *txt++; |
45 | 7.85k | len--; |
46 | | |
47 | | /* |
48 | | * Digits, backslash and flags can't be delimiters. |
49 | | */ |
50 | 7.85k | switch (delim) { |
51 | 5 | case '0': |
52 | 9 | case '1': |
53 | 13 | case '2': |
54 | 18 | case '3': |
55 | 22 | case '4': |
56 | 26 | case '5': |
57 | 33 | case '6': |
58 | 37 | case '7': |
59 | 41 | case '8': |
60 | 45 | case '9': |
61 | 49 | case '\\': |
62 | 53 | case 'i': |
63 | 57 | case 0: |
64 | 57 | return DNS_R_SYNTAX; |
65 | 7.85k | } |
66 | | |
67 | 7.80k | cp = regex; |
68 | 574k | while (len-- > 0) { |
69 | 566k | c = *txt++; |
70 | 566k | if (c == 0) { |
71 | 17 | return DNS_R_SYNTAX; |
72 | 17 | } |
73 | 566k | if (c == delim && !replace) { |
74 | 7.70k | replace = true; |
75 | 7.70k | continue; |
76 | 559k | } else if (c == delim && !flags) { |
77 | 7.37k | flags = true; |
78 | 7.37k | continue; |
79 | 551k | } else if (c == delim) { |
80 | 9 | return DNS_R_SYNTAX; |
81 | 9 | } |
82 | | /* |
83 | | * Flags are not escaped. |
84 | | */ |
85 | 551k | if (flags) { |
86 | 704 | switch (c) { |
87 | 691 | case 'i': |
88 | 691 | continue; |
89 | 13 | default: |
90 | 13 | return DNS_R_SYNTAX; |
91 | 704 | } |
92 | 704 | } |
93 | 550k | if (!replace) { |
94 | 485k | *cp++ = c; |
95 | 485k | } |
96 | 550k | if (c == '\\') { |
97 | 25.1k | if (len == 0) { |
98 | 12 | return DNS_R_SYNTAX; |
99 | 12 | } |
100 | 25.1k | c = *txt++; |
101 | 25.1k | if (c == 0) { |
102 | 6 | return DNS_R_SYNTAX; |
103 | 6 | } |
104 | 25.1k | len--; |
105 | 25.1k | if (replace) { |
106 | 14.2k | switch (c) { |
107 | 5 | case '0': |
108 | 5 | return DNS_R_SYNTAX; |
109 | 849 | case '1': |
110 | 849 | if (nsub < 1) { |
111 | 324 | nsub = 1; |
112 | 324 | } |
113 | 849 | break; |
114 | 1.18k | case '2': |
115 | 1.18k | if (nsub < 2) { |
116 | 418 | nsub = 2; |
117 | 418 | } |
118 | 1.18k | break; |
119 | 847 | case '3': |
120 | 847 | if (nsub < 3) { |
121 | 125 | nsub = 3; |
122 | 125 | } |
123 | 847 | break; |
124 | 1.71k | case '4': |
125 | 1.71k | if (nsub < 4) { |
126 | 663 | nsub = 4; |
127 | 663 | } |
128 | 1.71k | break; |
129 | 1.98k | case '5': |
130 | 1.98k | if (nsub < 5) { |
131 | 561 | nsub = 5; |
132 | 561 | } |
133 | 1.98k | break; |
134 | 669 | case '6': |
135 | 669 | if (nsub < 6) { |
136 | 151 | nsub = 6; |
137 | 151 | } |
138 | 669 | break; |
139 | 552 | case '7': |
140 | 552 | if (nsub < 7) { |
141 | 170 | nsub = 7; |
142 | 170 | } |
143 | 552 | break; |
144 | 709 | case '8': |
145 | 709 | if (nsub < 8) { |
146 | 195 | nsub = 8; |
147 | 195 | } |
148 | 709 | break; |
149 | 688 | case '9': |
150 | 688 | if (nsub < 9) { |
151 | 280 | nsub = 9; |
152 | 280 | } |
153 | 688 | break; |
154 | 14.2k | } |
155 | 14.2k | } |
156 | 25.1k | if (!replace) { |
157 | 10.8k | *cp++ = c; |
158 | 10.8k | } |
159 | 25.1k | } |
160 | 550k | } |
161 | 7.73k | if (!flags) { |
162 | 384 | return DNS_R_SYNTAX; |
163 | 384 | } |
164 | 7.35k | *cp = '\0'; |
165 | 7.35k | n = isc_regex_validate(regex); |
166 | 7.35k | if (n < 0 || nsub > (unsigned int)n) { |
167 | 1.32k | return DNS_R_SYNTAX; |
168 | 1.32k | } |
169 | 6.03k | return ISC_R_SUCCESS; |
170 | 7.35k | } |
171 | | |
172 | | static isc_result_t |
173 | 4.66k | fromtext_naptr(ARGS_FROMTEXT) { |
174 | 4.66k | isc_token_t token; |
175 | 4.66k | isc_buffer_t buffer; |
176 | 4.66k | unsigned char *regex; |
177 | | |
178 | 4.66k | REQUIRE(type == dns_rdatatype_naptr); |
179 | | |
180 | 4.66k | UNUSED(type); |
181 | 4.66k | UNUSED(rdclass); |
182 | 4.66k | UNUSED(callbacks); |
183 | | |
184 | | /* |
185 | | * Order. |
186 | | */ |
187 | 4.66k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
188 | 4.66k | false)); |
189 | 4.65k | if (token.value.as_ulong > 0xffffU) { |
190 | 32 | RETTOK(ISC_R_RANGE); |
191 | 32 | } |
192 | 4.61k | RETERR(uint16_tobuffer(token.value.as_ulong, target)); |
193 | | |
194 | | /* |
195 | | * Preference. |
196 | | */ |
197 | 4.61k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, |
198 | 4.61k | false)); |
199 | 4.57k | if (token.value.as_ulong > 0xffffU) { |
200 | 32 | RETTOK(ISC_R_RANGE); |
201 | 32 | } |
202 | 4.54k | RETERR(uint16_tobuffer(token.value.as_ulong, target)); |
203 | | |
204 | | /* |
205 | | * Flags. |
206 | | */ |
207 | 4.54k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, |
208 | 4.54k | false)); |
209 | 4.50k | RETTOK(txt_fromtext(&token.value.as_textregion, target)); |
210 | | |
211 | | /* |
212 | | * Service. |
213 | | */ |
214 | 4.49k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, |
215 | 4.49k | false)); |
216 | 4.49k | RETTOK(txt_fromtext(&token.value.as_textregion, target)); |
217 | | |
218 | | /* |
219 | | * Regexp. |
220 | | */ |
221 | 4.48k | regex = isc_buffer_used(target); |
222 | 4.48k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, |
223 | 4.48k | false)); |
224 | 4.48k | RETTOK(txt_fromtext(&token.value.as_textregion, target)); |
225 | 4.47k | RETTOK(txt_valid_regex(regex)); |
226 | | |
227 | | /* |
228 | | * Replacement. |
229 | | */ |
230 | 3.34k | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
231 | 3.34k | false)); |
232 | 3.14k | buffer_fromregion(&buffer, &token.value.as_region); |
233 | 3.14k | if (origin == NULL) { |
234 | 2 | origin = dns_rootname; |
235 | 2 | } |
236 | 3.14k | RETTOK(dns_name_wirefromtext(&buffer, origin, options, target)); |
237 | 3.14k | return ISC_R_SUCCESS; |
238 | 3.14k | } |
239 | | |
240 | | static isc_result_t |
241 | 4.36k | totext_naptr(ARGS_TOTEXT) { |
242 | 4.36k | isc_region_t region; |
243 | 4.36k | dns_name_t name; |
244 | 4.36k | dns_name_t prefix; |
245 | 4.36k | unsigned int opts; |
246 | 4.36k | char buf[sizeof("64000")]; |
247 | 4.36k | unsigned short num; |
248 | | |
249 | 4.36k | REQUIRE(rdata->type == dns_rdatatype_naptr); |
250 | 4.36k | REQUIRE(rdata->length != 0); |
251 | | |
252 | 4.36k | dns_name_init(&name); |
253 | 4.36k | dns_name_init(&prefix); |
254 | | |
255 | 4.36k | dns_rdata_toregion(rdata, ®ion); |
256 | | |
257 | | /* |
258 | | * Order. |
259 | | */ |
260 | 4.36k | num = uint16_fromregion(®ion); |
261 | 4.36k | isc_region_consume(®ion, 2); |
262 | 4.36k | snprintf(buf, sizeof(buf), "%u", num); |
263 | 4.36k | RETERR(str_totext(buf, target)); |
264 | 4.36k | RETERR(str_totext(" ", target)); |
265 | | |
266 | | /* |
267 | | * Preference. |
268 | | */ |
269 | 4.36k | num = uint16_fromregion(®ion); |
270 | 4.36k | isc_region_consume(®ion, 2); |
271 | 4.36k | snprintf(buf, sizeof(buf), "%u", num); |
272 | 4.36k | RETERR(str_totext(buf, target)); |
273 | 4.36k | RETERR(str_totext(" ", target)); |
274 | | |
275 | | /* |
276 | | * Flags. |
277 | | */ |
278 | 4.36k | RETERR(txt_totext(®ion, true, target)); |
279 | 4.36k | RETERR(str_totext(" ", target)); |
280 | | |
281 | | /* |
282 | | * Service. |
283 | | */ |
284 | 4.36k | RETERR(txt_totext(®ion, true, target)); |
285 | 4.36k | RETERR(str_totext(" ", target)); |
286 | | |
287 | | /* |
288 | | * Regexp. |
289 | | */ |
290 | 4.36k | RETERR(txt_totext(®ion, true, target)); |
291 | 4.36k | RETERR(str_totext(" ", target)); |
292 | | |
293 | | /* |
294 | | * Replacement. |
295 | | */ |
296 | 4.36k | dns_name_fromregion(&name, ®ion); |
297 | 4.36k | opts = name_prefix(&name, tctx->origin, &prefix) ? DNS_NAME_OMITFINALDOT |
298 | 4.36k | : 0; |
299 | 4.36k | return dns_name_totext(&prefix, opts, target); |
300 | 4.36k | } |
301 | | |
302 | | static isc_result_t |
303 | 7.04k | fromwire_naptr(ARGS_FROMWIRE) { |
304 | 7.04k | dns_name_t name; |
305 | 7.04k | isc_region_t sr; |
306 | 7.04k | unsigned char *regex; |
307 | | |
308 | 7.04k | REQUIRE(type == dns_rdatatype_naptr); |
309 | | |
310 | 7.04k | UNUSED(type); |
311 | 7.04k | UNUSED(rdclass); |
312 | | |
313 | 7.04k | dctx = dns_decompress_setpermitted(dctx, false); |
314 | | |
315 | 7.04k | dns_name_init(&name); |
316 | | |
317 | | /* |
318 | | * Order, preference. |
319 | | */ |
320 | 7.04k | isc_buffer_activeregion(source, &sr); |
321 | 7.04k | if (sr.length < 4) { |
322 | 11 | return ISC_R_UNEXPECTEDEND; |
323 | 11 | } |
324 | 7.03k | RETERR(mem_tobuffer(target, sr.base, 4)); |
325 | 6.81k | isc_buffer_forward(source, 4); |
326 | | |
327 | | /* |
328 | | * Flags. |
329 | | */ |
330 | 6.81k | RETERR(txt_fromwire(source, target)); |
331 | | |
332 | | /* |
333 | | * Service. |
334 | | */ |
335 | 6.60k | RETERR(txt_fromwire(source, target)); |
336 | | |
337 | | /* |
338 | | * Regexp. |
339 | | */ |
340 | 6.40k | regex = isc_buffer_used(target); |
341 | 6.40k | RETERR(txt_fromwire(source, target)); |
342 | 5.91k | RETERR(txt_valid_regex(regex)); |
343 | | |
344 | | /* |
345 | | * Replacement. |
346 | | */ |
347 | 5.21k | return dns_name_fromwire(&name, source, dctx, target); |
348 | 5.91k | } |
349 | | |
350 | | static isc_result_t |
351 | 2.19k | towire_naptr(ARGS_TOWIRE) { |
352 | 2.19k | dns_name_t name; |
353 | 2.19k | isc_region_t sr; |
354 | | |
355 | 2.19k | REQUIRE(rdata->type == dns_rdatatype_naptr); |
356 | 2.19k | REQUIRE(rdata->length != 0); |
357 | | |
358 | 2.19k | dns_compress_setpermitted(cctx, false); |
359 | | /* |
360 | | * Order, preference. |
361 | | */ |
362 | 2.19k | dns_rdata_toregion(rdata, &sr); |
363 | 2.19k | RETERR(mem_tobuffer(target, sr.base, 4)); |
364 | 2.18k | isc_region_consume(&sr, 4); |
365 | | |
366 | | /* |
367 | | * Flags. |
368 | | */ |
369 | 2.18k | RETERR(mem_tobuffer(target, sr.base, sr.base[0] + 1)); |
370 | 2.18k | isc_region_consume(&sr, sr.base[0] + 1); |
371 | | |
372 | | /* |
373 | | * Service. |
374 | | */ |
375 | 2.18k | RETERR(mem_tobuffer(target, sr.base, sr.base[0] + 1)); |
376 | 2.18k | isc_region_consume(&sr, sr.base[0] + 1); |
377 | | |
378 | | /* |
379 | | * Regexp. |
380 | | */ |
381 | 2.18k | RETERR(mem_tobuffer(target, sr.base, sr.base[0] + 1)); |
382 | 2.18k | isc_region_consume(&sr, sr.base[0] + 1); |
383 | | |
384 | | /* |
385 | | * Replacement. |
386 | | */ |
387 | 2.18k | dns_name_init(&name); |
388 | 2.18k | dns_name_fromregion(&name, &sr); |
389 | 2.18k | return dns_name_towire(&name, cctx, target); |
390 | 2.18k | } |
391 | | |
392 | | static int |
393 | 14.4k | compare_naptr(ARGS_COMPARE) { |
394 | 14.4k | dns_name_t name1; |
395 | 14.4k | dns_name_t name2; |
396 | 14.4k | isc_region_t region1; |
397 | 14.4k | isc_region_t region2; |
398 | 14.4k | int order, len; |
399 | | |
400 | 14.4k | REQUIRE(rdata1->type == rdata2->type); |
401 | 14.4k | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
402 | 14.4k | REQUIRE(rdata1->type == dns_rdatatype_naptr); |
403 | 14.4k | REQUIRE(rdata1->length != 0); |
404 | 14.4k | REQUIRE(rdata2->length != 0); |
405 | | |
406 | 14.4k | dns_rdata_toregion(rdata1, ®ion1); |
407 | 14.4k | dns_rdata_toregion(rdata2, ®ion2); |
408 | | |
409 | | /* |
410 | | * Order, preference. |
411 | | */ |
412 | 14.4k | order = memcmp(region1.base, region2.base, 4); |
413 | 14.4k | if (order != 0) { |
414 | 1.45k | return order < 0 ? -1 : 1; |
415 | 1.45k | } |
416 | 12.9k | isc_region_consume(®ion1, 4); |
417 | 12.9k | isc_region_consume(®ion2, 4); |
418 | | |
419 | | /* |
420 | | * Flags. |
421 | | */ |
422 | 12.9k | len = ISC_MIN(region1.base[0], region2.base[0]); |
423 | 12.9k | order = memcmp(region1.base, region2.base, len + 1); |
424 | 12.9k | if (order != 0) { |
425 | 1.87k | return order < 0 ? -1 : 1; |
426 | 1.87k | } |
427 | 11.0k | isc_region_consume(®ion1, region1.base[0] + 1); |
428 | 11.0k | isc_region_consume(®ion2, region2.base[0] + 1); |
429 | | |
430 | | /* |
431 | | * Service. |
432 | | */ |
433 | 11.0k | len = ISC_MIN(region1.base[0], region2.base[0]); |
434 | 11.0k | order = memcmp(region1.base, region2.base, len + 1); |
435 | 11.0k | if (order != 0) { |
436 | 1.41k | return order < 0 ? -1 : 1; |
437 | 1.41k | } |
438 | 9.67k | isc_region_consume(®ion1, region1.base[0] + 1); |
439 | 9.67k | isc_region_consume(®ion2, region2.base[0] + 1); |
440 | | |
441 | | /* |
442 | | * Regexp. |
443 | | */ |
444 | 9.67k | len = ISC_MIN(region1.base[0], region2.base[0]); |
445 | 9.67k | order = memcmp(region1.base, region2.base, len + 1); |
446 | 9.67k | if (order != 0) { |
447 | 7.10k | return order < 0 ? -1 : 1; |
448 | 7.10k | } |
449 | 2.57k | isc_region_consume(®ion1, region1.base[0] + 1); |
450 | 2.57k | isc_region_consume(®ion2, region2.base[0] + 1); |
451 | | |
452 | | /* |
453 | | * Replacement. |
454 | | */ |
455 | 2.57k | dns_name_init(&name1); |
456 | 2.57k | dns_name_init(&name2); |
457 | | |
458 | 2.57k | dns_name_fromregion(&name1, ®ion1); |
459 | 2.57k | dns_name_fromregion(&name2, ®ion2); |
460 | | |
461 | 2.57k | return dns_name_rdatacompare(&name1, &name2); |
462 | 9.67k | } |
463 | | |
464 | | static isc_result_t |
465 | 0 | fromstruct_naptr(ARGS_FROMSTRUCT) { |
466 | 0 | dns_rdata_naptr_t *naptr = source; |
467 | 0 | isc_region_t region; |
468 | |
|
469 | 0 | REQUIRE(type == dns_rdatatype_naptr); |
470 | 0 | REQUIRE(naptr != NULL); |
471 | 0 | REQUIRE(naptr->common.rdtype == type); |
472 | 0 | REQUIRE(naptr->common.rdclass == rdclass); |
473 | 0 | REQUIRE(naptr->flags != NULL || naptr->flags_len == 0); |
474 | 0 | REQUIRE(naptr->service != NULL || naptr->service_len == 0); |
475 | 0 | REQUIRE(naptr->regexp != NULL || naptr->regexp_len == 0); |
476 | |
|
477 | 0 | UNUSED(type); |
478 | 0 | UNUSED(rdclass); |
479 | |
|
480 | 0 | RETERR(uint16_tobuffer(naptr->order, target)); |
481 | 0 | RETERR(uint16_tobuffer(naptr->preference, target)); |
482 | 0 | RETERR(uint8_tobuffer(naptr->flags_len, target)); |
483 | 0 | RETERR(mem_tobuffer(target, naptr->flags, naptr->flags_len)); |
484 | 0 | RETERR(uint8_tobuffer(naptr->service_len, target)); |
485 | 0 | RETERR(mem_tobuffer(target, naptr->service, naptr->service_len)); |
486 | 0 | RETERR(uint8_tobuffer(naptr->regexp_len, target)); |
487 | 0 | RETERR(mem_tobuffer(target, naptr->regexp, naptr->regexp_len)); |
488 | 0 | dns_name_toregion(&naptr->replacement, ®ion); |
489 | 0 | return isc_buffer_copyregion(target, ®ion); |
490 | 0 | } |
491 | | |
492 | | static isc_result_t |
493 | 0 | tostruct_naptr(ARGS_TOSTRUCT) { |
494 | 0 | dns_rdata_naptr_t *naptr = target; |
495 | 0 | isc_region_t r; |
496 | 0 | dns_name_t name; |
497 | |
|
498 | 0 | REQUIRE(rdata->type == dns_rdatatype_naptr); |
499 | 0 | REQUIRE(naptr != NULL); |
500 | 0 | REQUIRE(rdata->length != 0); |
501 | |
|
502 | 0 | DNS_RDATACOMMON_INIT(naptr, rdata->type, rdata->rdclass); |
503 | |
|
504 | 0 | naptr->flags = NULL; |
505 | 0 | naptr->service = NULL; |
506 | 0 | naptr->regexp = NULL; |
507 | |
|
508 | 0 | dns_rdata_toregion(rdata, &r); |
509 | |
|
510 | 0 | naptr->order = uint16_fromregion(&r); |
511 | 0 | isc_region_consume(&r, 2); |
512 | |
|
513 | 0 | naptr->preference = uint16_fromregion(&r); |
514 | 0 | isc_region_consume(&r, 2); |
515 | |
|
516 | 0 | naptr->flags_len = uint8_fromregion(&r); |
517 | 0 | isc_region_consume(&r, 1); |
518 | 0 | INSIST(naptr->flags_len <= r.length); |
519 | 0 | naptr->flags = mem_maybedup(mctx, r.base, naptr->flags_len); |
520 | 0 | isc_region_consume(&r, naptr->flags_len); |
521 | |
|
522 | 0 | naptr->service_len = uint8_fromregion(&r); |
523 | 0 | isc_region_consume(&r, 1); |
524 | 0 | INSIST(naptr->service_len <= r.length); |
525 | 0 | naptr->service = mem_maybedup(mctx, r.base, naptr->service_len); |
526 | 0 | isc_region_consume(&r, naptr->service_len); |
527 | |
|
528 | 0 | naptr->regexp_len = uint8_fromregion(&r); |
529 | 0 | isc_region_consume(&r, 1); |
530 | 0 | INSIST(naptr->regexp_len <= r.length); |
531 | 0 | naptr->regexp = mem_maybedup(mctx, r.base, naptr->regexp_len); |
532 | 0 | isc_region_consume(&r, naptr->regexp_len); |
533 | |
|
534 | 0 | dns_name_init(&name); |
535 | 0 | dns_name_fromregion(&name, &r); |
536 | 0 | dns_name_init(&naptr->replacement); |
537 | 0 | name_duporclone(&name, mctx, &naptr->replacement); |
538 | 0 | naptr->mctx = mctx; |
539 | 0 | return ISC_R_SUCCESS; |
540 | 0 | } |
541 | | |
542 | | static void |
543 | 0 | freestruct_naptr(ARGS_FREESTRUCT) { |
544 | 0 | dns_rdata_naptr_t *naptr = source; |
545 | |
|
546 | 0 | REQUIRE(naptr != NULL); |
547 | 0 | REQUIRE(naptr->common.rdtype == dns_rdatatype_naptr); |
548 | |
|
549 | 0 | if (naptr->mctx == NULL) { |
550 | 0 | return; |
551 | 0 | } |
552 | | |
553 | 0 | if (naptr->flags != NULL) { |
554 | 0 | isc_mem_free(naptr->mctx, naptr->flags); |
555 | 0 | } |
556 | 0 | if (naptr->service != NULL) { |
557 | 0 | isc_mem_free(naptr->mctx, naptr->service); |
558 | 0 | } |
559 | 0 | if (naptr->regexp != NULL) { |
560 | 0 | isc_mem_free(naptr->mctx, naptr->regexp); |
561 | 0 | } |
562 | 0 | dns_name_free(&naptr->replacement, naptr->mctx); |
563 | 0 | naptr->mctx = NULL; |
564 | 0 | } |
565 | | |
566 | | static isc_result_t |
567 | 0 | additionaldata_naptr(ARGS_ADDLDATA) { |
568 | 0 | dns_name_t name; |
569 | 0 | isc_region_t sr; |
570 | 0 | dns_rdatatype_t atype; |
571 | 0 | unsigned int i, flagslen; |
572 | 0 | char *cp; |
573 | |
|
574 | 0 | REQUIRE(rdata->type == dns_rdatatype_naptr); |
575 | |
|
576 | 0 | UNUSED(owner); |
577 | | |
578 | | /* |
579 | | * Order, preference. |
580 | | */ |
581 | 0 | dns_rdata_toregion(rdata, &sr); |
582 | 0 | isc_region_consume(&sr, 4); |
583 | | |
584 | | /* |
585 | | * Flags. |
586 | | */ |
587 | 0 | atype = dns_rdatatype_none; |
588 | 0 | flagslen = sr.base[0]; |
589 | 0 | cp = (char *)&sr.base[1]; |
590 | 0 | for (i = 0; i < flagslen; i++, cp++) { |
591 | 0 | if (*cp == 'S' || *cp == 's') { |
592 | 0 | atype = dns_rdatatype_srv; |
593 | 0 | break; |
594 | 0 | } |
595 | 0 | if (*cp == 'A' || *cp == 'a') { |
596 | 0 | atype = dns_rdatatype_a; |
597 | 0 | break; |
598 | 0 | } |
599 | 0 | } |
600 | 0 | isc_region_consume(&sr, flagslen + 1); |
601 | | |
602 | | /* |
603 | | * Service. |
604 | | */ |
605 | 0 | isc_region_consume(&sr, sr.base[0] + 1); |
606 | | |
607 | | /* |
608 | | * Regexp. |
609 | | */ |
610 | 0 | isc_region_consume(&sr, sr.base[0] + 1); |
611 | | |
612 | | /* |
613 | | * Replacement. |
614 | | */ |
615 | 0 | dns_name_init(&name); |
616 | 0 | dns_name_fromregion(&name, &sr); |
617 | |
|
618 | 0 | if (atype != 0) { |
619 | 0 | return (add)(arg, &name, atype, NULL DNS__DB_FILELINE); |
620 | 0 | } |
621 | | |
622 | 0 | return ISC_R_SUCCESS; |
623 | 0 | } |
624 | | |
625 | | static isc_result_t |
626 | 0 | digest_naptr(ARGS_DIGEST) { |
627 | 0 | isc_region_t r1, r2; |
628 | 0 | unsigned int length, n; |
629 | 0 | isc_result_t result; |
630 | 0 | dns_name_t name; |
631 | |
|
632 | 0 | REQUIRE(rdata->type == dns_rdatatype_naptr); |
633 | |
|
634 | 0 | dns_rdata_toregion(rdata, &r1); |
635 | 0 | r2 = r1; |
636 | 0 | length = 0; |
637 | | |
638 | | /* |
639 | | * Order, preference. |
640 | | */ |
641 | 0 | length += 4; |
642 | 0 | isc_region_consume(&r2, 4); |
643 | | |
644 | | /* |
645 | | * Flags. |
646 | | */ |
647 | 0 | n = r2.base[0] + 1; |
648 | 0 | length += n; |
649 | 0 | isc_region_consume(&r2, n); |
650 | | |
651 | | /* |
652 | | * Service. |
653 | | */ |
654 | 0 | n = r2.base[0] + 1; |
655 | 0 | length += n; |
656 | 0 | isc_region_consume(&r2, n); |
657 | | |
658 | | /* |
659 | | * Regexp. |
660 | | */ |
661 | 0 | n = r2.base[0] + 1; |
662 | 0 | length += n; |
663 | 0 | isc_region_consume(&r2, n); |
664 | | |
665 | | /* |
666 | | * Digest the RR up to the replacement name. |
667 | | */ |
668 | 0 | r1.length = length; |
669 | 0 | result = (digest)(arg, &r1); |
670 | 0 | if (result != ISC_R_SUCCESS) { |
671 | 0 | return result; |
672 | 0 | } |
673 | | |
674 | | /* |
675 | | * Replacement. |
676 | | */ |
677 | | |
678 | 0 | dns_name_init(&name); |
679 | 0 | dns_name_fromregion(&name, &r2); |
680 | |
|
681 | 0 | return dns_name_digest(&name, digest, arg); |
682 | 0 | } |
683 | | |
684 | | static bool |
685 | 0 | checkowner_naptr(ARGS_CHECKOWNER) { |
686 | 0 | REQUIRE(type == dns_rdatatype_naptr); |
687 | |
|
688 | 0 | UNUSED(name); |
689 | 0 | UNUSED(type); |
690 | 0 | UNUSED(rdclass); |
691 | 0 | UNUSED(wildcard); |
692 | |
|
693 | 0 | return true; |
694 | 0 | } |
695 | | |
696 | | static bool |
697 | 0 | checknames_naptr(ARGS_CHECKNAMES) { |
698 | 0 | REQUIRE(rdata->type == dns_rdatatype_naptr); |
699 | |
|
700 | 0 | UNUSED(rdata); |
701 | 0 | UNUSED(owner); |
702 | 0 | UNUSED(bad); |
703 | |
|
704 | 0 | return true; |
705 | 0 | } |
706 | | |
707 | | static int |
708 | 0 | casecompare_naptr(ARGS_COMPARE) { |
709 | 0 | return compare_naptr(rdata1, rdata2); |
710 | 0 | } |
711 | | |
712 | | #endif /* RDATA_GENERIC_NAPTR_35_C */ |