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