1 /* $NetBSD: rdata.c,v 1.12 2015/09/03 07:33:34 christos Exp $ */
4 * Copyright (C) 2004-2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
27 #include <isc/base64.h>
31 #include <isc/parseint.h>
32 #include <isc/print.h>
33 #include <isc/string.h>
34 #include <isc/stdlib.h>
37 #include <dns/callbacks.h>
39 #include <dns/compress.h>
40 #include <dns/dsdigest.h>
41 #include <dns/enumtype.h>
42 #include <dns/keyflags.h>
43 #include <dns/keyvalues.h>
44 #include <dns/message.h>
45 #include <dns/rcode.h>
46 #include <dns/rdata.h>
47 #include <dns/rdataclass.h>
48 #include <dns/rdatastruct.h>
49 #include <dns/rdatatype.h>
50 #include <dns/result.h>
51 #include <dns/secalg.h>
52 #include <dns/secproto.h>
58 isc_result_t _r = (x); \
59 if (_r != ISC_R_SUCCESS) \
61 } while (/*CONSTCOND*/0)
65 isc_result_t _r = (x); \
66 if (_r != ISC_R_SUCCESS) { \
67 isc_lex_ungettoken(lexer, &token); \
70 } while (/*CONSTCOND*/0)
72 #define DNS_AS_STR(t) ((t).value.as_textregion.base)
74 #define ARGS_FROMTEXT int rdclass, dns_rdatatype_t type, \
75 isc_lex_t *lexer, dns_name_t *origin, \
76 unsigned int options, isc_buffer_t *target, \
77 dns_rdatacallbacks_t *callbacks
79 #define ARGS_TOTEXT dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, \
82 #define ARGS_FROMWIRE int rdclass, dns_rdatatype_t type, \
83 isc_buffer_t *source, dns_decompress_t *dctx, \
84 unsigned int options, isc_buffer_t *target
86 #define ARGS_TOWIRE dns_rdata_t *rdata, dns_compress_t *cctx, \
89 #define ARGS_COMPARE const dns_rdata_t *rdata1, const dns_rdata_t *rdata2
91 #define ARGS_FROMSTRUCT int rdclass, dns_rdatatype_t type, \
92 void *source, isc_buffer_t *target
94 #define ARGS_TOSTRUCT dns_rdata_t *rdata, void *target, isc_mem_t *mctx
96 #define ARGS_FREESTRUCT void *source
98 #define ARGS_ADDLDATA dns_rdata_t *rdata, dns_additionaldatafunc_t add, \
101 #define ARGS_DIGEST dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg
103 #define ARGS_CHECKOWNER dns_name_t *name, dns_rdataclass_t rdclass, \
104 dns_rdatatype_t type, isc_boolean_t wildcard
106 #define ARGS_CHECKNAMES dns_rdata_t *rdata, dns_name_t *owner, dns_name_t *bad
110 * Context structure for the totext_ functions.
111 * Contains formatting options for rdata-to-text
114 typedef struct dns_rdata_textctx
{
115 dns_name_t
*origin
; /*%< Current origin, or NULL. */
116 unsigned int flags
; /*%< DNS_STYLEFLAG_* */
117 unsigned int width
; /*%< Width of rdata column. */
118 const char *linebreak
; /*%< Line break string. */
119 } dns_rdata_textctx_t
;
122 txt_totext(isc_region_t
*source
, isc_boolean_t quote
, isc_buffer_t
*target
);
125 txt_fromtext(isc_textregion_t
*source
, isc_buffer_t
*target
);
128 txt_fromwire(isc_buffer_t
*source
, isc_buffer_t
*target
);
131 multitxt_totext(isc_region_t
*source
, isc_buffer_t
*target
);
134 multitxt_fromtext(isc_textregion_t
*source
, isc_buffer_t
*target
);
137 name_prefix(dns_name_t
*name
, dns_name_t
*origin
, dns_name_t
*target
);
140 name_length(dns_name_t
*name
);
143 str_totext(const char *source
, isc_buffer_t
*target
);
146 inet_totext(int af
, isc_region_t
*src
, isc_buffer_t
*target
);
149 buffer_empty(isc_buffer_t
*source
);
152 buffer_fromregion(isc_buffer_t
*buffer
, isc_region_t
*region
);
155 uint32_tobuffer(isc_uint32_t
, isc_buffer_t
*target
);
158 uint16_tobuffer(isc_uint32_t
, isc_buffer_t
*target
);
161 uint8_tobuffer(isc_uint32_t
, isc_buffer_t
*target
);
164 name_tobuffer(dns_name_t
*name
, isc_buffer_t
*target
);
167 uint32_fromregion(isc_region_t
*region
);
170 uint16_fromregion(isc_region_t
*region
);
173 uint8_fromregion(isc_region_t
*region
);
176 uint8_consume_fromregion(isc_region_t
*region
);
179 mem_tobuffer(isc_buffer_t
*target
, void *base
, unsigned int length
);
182 hexvalue(char value
);
185 decvalue(char value
);
188 btoa_totext(unsigned char *inbuf
, int inbuflen
, isc_buffer_t
*target
);
191 atob_tobuffer(isc_lex_t
*lexer
, isc_buffer_t
*target
);
194 default_fromtext_callback(dns_rdatacallbacks_t
*callbacks
, const char *, ...)
195 ISC_FORMAT_PRINTF(2, 3);
198 fromtext_error(void (*callback
)(dns_rdatacallbacks_t
*, const char *, ...),
199 dns_rdatacallbacks_t
*callbacks
, const char *name
,
200 unsigned long line
, isc_token_t
*token
, isc_result_t result
);
203 fromtext_warneof(isc_lex_t
*lexer
, dns_rdatacallbacks_t
*callbacks
);
206 rdata_totext(dns_rdata_t
*rdata
, dns_rdata_textctx_t
*tctx
,
207 isc_buffer_t
*target
);
210 warn_badname(dns_name_t
*name
, isc_lex_t
*lexer
,
211 dns_rdatacallbacks_t
*callbacks
);
214 warn_badmx(isc_token_t
*token
, isc_lex_t
*lexer
,
215 dns_rdatacallbacks_t
*callbacks
);
218 uint16_consume_fromregion(isc_region_t
*region
);
221 unknown_totext(dns_rdata_t
*rdata
, dns_rdata_textctx_t
*tctx
,
222 isc_buffer_t
*target
);
226 /*% IPv6 Address Size */
227 #define NS_LOCATORSZ 8
230 * convert presentation level address to network order binary form.
232 * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
234 * (1) does not touch `dst' unless it's returning 1.
237 locator_pton(const char *src
, unsigned char *dst
) {
238 static const char xdigits_l
[] = "0123456789abcdef",
239 xdigits_u
[] = "0123456789ABCDEF";
240 unsigned char tmp
[NS_LOCATORSZ
];
241 unsigned char *tp
= tmp
, *endp
;
243 int ch
, seen_xdigits
;
246 memset(tp
, '\0', NS_LOCATORSZ
);
247 endp
= tp
+ NS_LOCATORSZ
;
250 while ((ch
= *src
++) != '\0') {
253 pch
= strchr((xdigits
= xdigits_l
), ch
);
255 pch
= strchr((xdigits
= xdigits_u
), ch
);
258 val
|= (pch
- xdigits
);
259 if (++seen_xdigits
> 4)
266 if (tp
+ NS_INT16SZ
> endp
)
268 *tp
++ = (unsigned char) (val
>> 8) & 0xff;
269 *tp
++ = (unsigned char) val
& 0xff;
277 if (tp
+ NS_INT16SZ
> endp
)
279 *tp
++ = (unsigned char) (val
>> 8) & 0xff;
280 *tp
++ = (unsigned char) val
& 0xff;
284 memmove(dst
, tmp
, NS_LOCATORSZ
);
289 getquad(const void *src
, struct in_addr
*dst
,
290 isc_lex_t
*lexer
, dns_rdatacallbacks_t
*callbacks
)
295 result
= inet_aton(src
, dst
);
296 if (result
== 1 && callbacks
!= NULL
&&
297 inet_pton(AF_INET
, src
, &tmp
) != 1) {
298 const char *name
= isc_lex_getsourcename(lexer
);
301 (*callbacks
->warn
)(callbacks
, "%s:%lu: \"%s\" "
302 "is not a decimal dotted quad", name
,
303 isc_lex_getsourceline(lexer
), src
);
308 static inline isc_result_t
309 name_duporclone(dns_name_t
*source
, isc_mem_t
*mctx
, dns_name_t
*target
) {
312 return (dns_name_dup(source
, mctx
, target
));
313 dns_name_clone(source
, target
);
314 return (ISC_R_SUCCESS
);
318 mem_maybedup(isc_mem_t
*mctx
, void *source
, size_t length
) {
323 new = isc_mem_allocate(mctx
, length
);
325 memmove(new, source
, length
);
330 static const char hexdigits
[] = "0123456789abcdef";
331 static const char decdigits
[] = "0123456789";
336 #define RESERVED 0x0002
343 dns_rdata_init(dns_rdata_t
*rdata
) {
345 REQUIRE(rdata
!= NULL
);
352 ISC_LINK_INIT(rdata
, link
);
353 /* ISC_LIST_INIT(rdata->list); */
357 dns_rdata_reset(dns_rdata_t
*rdata
) {
359 REQUIRE(rdata
!= NULL
);
361 REQUIRE(!ISC_LINK_LINKED(rdata
, link
));
362 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata
));
376 dns_rdata_clone(const dns_rdata_t
*src
, dns_rdata_t
*target
) {
378 REQUIRE(src
!= NULL
);
379 REQUIRE(target
!= NULL
);
381 REQUIRE(DNS_RDATA_INITIALIZED(target
));
383 REQUIRE(DNS_RDATA_VALIDFLAGS(src
));
384 REQUIRE(DNS_RDATA_VALIDFLAGS(target
));
386 target
->data
= src
->data
;
387 target
->length
= src
->length
;
388 target
->rdclass
= src
->rdclass
;
389 target
->type
= src
->type
;
390 target
->flags
= src
->flags
;
399 dns_rdata_compare(const dns_rdata_t
*rdata1
, const dns_rdata_t
*rdata2
) {
401 isc_boolean_t use_default
= ISC_FALSE
;
403 REQUIRE(rdata1
!= NULL
);
404 REQUIRE(rdata2
!= NULL
);
405 REQUIRE(rdata1
->length
== 0 || rdata1
->data
!= NULL
);
406 REQUIRE(rdata2
->length
== 0 || rdata2
->data
!= NULL
);
407 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata1
));
408 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata2
));
410 if (rdata1
->rdclass
!= rdata2
->rdclass
)
411 return (rdata1
->rdclass
< rdata2
->rdclass
? -1 : 1);
413 if (rdata1
->type
!= rdata2
->type
)
414 return (rdata1
->type
< rdata2
->type
? -1 : 1);
422 dns_rdata_toregion(rdata1
, &r1
);
423 dns_rdata_toregion(rdata2
, &r2
);
424 result
= isc_region_compare(&r1
, &r2
);
430 dns_rdata_casecompare(const dns_rdata_t
*rdata1
, const dns_rdata_t
*rdata2
) {
432 isc_boolean_t use_default
= ISC_FALSE
;
434 REQUIRE(rdata1
!= NULL
);
435 REQUIRE(rdata2
!= NULL
);
436 REQUIRE(rdata1
->length
== 0 || rdata1
->data
!= NULL
);
437 REQUIRE(rdata2
->length
== 0 || rdata2
->data
!= NULL
);
438 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata1
));
439 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata2
));
441 if (rdata1
->rdclass
!= rdata2
->rdclass
)
442 return (rdata1
->rdclass
< rdata2
->rdclass
? -1 : 1);
444 if (rdata1
->type
!= rdata2
->type
)
445 return (rdata1
->type
< rdata2
->type
? -1 : 1);
453 dns_rdata_toregion(rdata1
, &r1
);
454 dns_rdata_toregion(rdata2
, &r2
);
455 result
= isc_region_compare(&r1
, &r2
);
465 dns_rdata_fromregion(dns_rdata_t
*rdata
, dns_rdataclass_t rdclass
,
466 dns_rdatatype_t type
, isc_region_t
*r
)
469 REQUIRE(rdata
!= NULL
);
470 REQUIRE(DNS_RDATA_INITIALIZED(rdata
));
473 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata
));
475 rdata
->data
= r
->base
;
476 rdata
->length
= r
->length
;
477 rdata
->rdclass
= rdclass
;
483 dns_rdata_toregion(const dns_rdata_t
*rdata
, isc_region_t
*r
) {
485 REQUIRE(rdata
!= NULL
);
487 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata
));
489 r
->base
= rdata
->data
;
490 r
->length
= rdata
->length
;
494 dns_rdata_fromwire(dns_rdata_t
*rdata
, dns_rdataclass_t rdclass
,
495 dns_rdatatype_t type
, isc_buffer_t
*source
,
496 dns_decompress_t
*dctx
, unsigned int options
,
497 isc_buffer_t
*target
)
499 isc_result_t result
= ISC_R_NOTIMPLEMENTED
;
503 isc_boolean_t use_default
= ISC_FALSE
;
504 isc_uint32_t activelength
;
507 REQUIRE(dctx
!= NULL
);
509 REQUIRE(DNS_RDATA_INITIALIZED(rdata
));
510 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata
));
512 REQUIRE(source
!= NULL
);
513 REQUIRE(target
!= NULL
);
516 return (DNS_R_FORMERR
);
521 activelength
= isc_buffer_activelength(source
);
522 INSIST(activelength
< 65536);
527 if (activelength
> isc_buffer_availablelength(target
))
528 result
= ISC_R_NOSPACE
;
530 isc_buffer_putmem(target
, isc_buffer_current(source
),
532 isc_buffer_forward(source
, activelength
);
533 result
= ISC_R_SUCCESS
;
538 * Reject any rdata that expands out to more than DNS_RDATA_MAXLENGTH
539 * as we cannot transmit it.
541 length
= isc_buffer_usedlength(target
) - isc_buffer_usedlength(&st
);
542 if (result
== ISC_R_SUCCESS
&& length
> DNS_RDATA_MAXLENGTH
)
543 result
= DNS_R_FORMERR
;
546 * We should have consumed all of our buffer.
548 if (result
== ISC_R_SUCCESS
&& !buffer_empty(source
))
549 result
= DNS_R_EXTRADATA
;
551 if (rdata
!= NULL
&& result
== ISC_R_SUCCESS
) {
552 region
.base
= isc_buffer_used(&st
);
553 region
.length
= length
;
554 dns_rdata_fromregion(rdata
, rdclass
, type
, ®ion
);
557 if (result
!= ISC_R_SUCCESS
) {
565 dns_rdata_towire(dns_rdata_t
*rdata
, dns_compress_t
*cctx
,
566 isc_buffer_t
*target
)
568 isc_result_t result
= ISC_R_NOTIMPLEMENTED
;
569 isc_boolean_t use_default
= ISC_FALSE
;
573 REQUIRE(rdata
!= NULL
);
574 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata
));
577 * Some DynDNS meta-RRs have empty rdata.
579 if ((rdata
->flags
& DNS_RDATA_UPDATE
) != 0) {
580 INSIST(rdata
->length
== 0);
581 return (ISC_R_SUCCESS
);
589 isc_buffer_availableregion(target
, &tr
);
590 if (tr
.length
< rdata
->length
)
591 return (ISC_R_NOSPACE
);
592 memmove(tr
.base
, rdata
->data
, rdata
->length
);
593 isc_buffer_add(target
, rdata
->length
);
594 return (ISC_R_SUCCESS
);
596 if (result
!= ISC_R_SUCCESS
) {
598 INSIST(target
->used
< 65536);
599 dns_compress_rollback(cctx
, (isc_uint16_t
)target
->used
);
605 * If the binary data in 'src' is valid uncompressed wire format
606 * rdata of class 'rdclass' and type 'type', return ISC_R_SUCCESS
607 * and copy the validated rdata to 'dest'. Otherwise return an error.
610 rdata_validate(isc_buffer_t
*src
, isc_buffer_t
*dest
, dns_rdataclass_t rdclass
,
611 dns_rdatatype_t type
)
613 dns_decompress_t dctx
;
616 dns_decompress_init(&dctx
, -1, DNS_DECOMPRESS_NONE
);
617 isc_buffer_setactive(src
, isc_buffer_usedlength(src
));
618 result
= dns_rdata_fromwire(NULL
, rdclass
, type
, src
, &dctx
, 0, dest
);
619 dns_decompress_invalidate(&dctx
);
625 unknown_fromtext(dns_rdataclass_t rdclass
, dns_rdatatype_t type
,
626 isc_lex_t
*lexer
, isc_mem_t
*mctx
, isc_buffer_t
*target
)
629 isc_buffer_t
*buf
= NULL
;
632 if (type
== 0 || dns_rdatatype_ismeta(type
))
633 return (DNS_R_METATYPE
);
635 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
637 if (token
.value
.as_ulong
> 65535U)
638 return (ISC_R_RANGE
);
639 result
= isc_buffer_allocate(mctx
, &buf
, token
.value
.as_ulong
);
640 if (result
!= ISC_R_SUCCESS
)
643 result
= isc_hex_tobuffer(lexer
, buf
,
644 (unsigned int)token
.value
.as_ulong
);
645 if (result
!= ISC_R_SUCCESS
)
647 if (isc_buffer_usedlength(buf
) != token
.value
.as_ulong
) {
648 result
= ISC_R_UNEXPECTEDEND
;
652 if (dns_rdatatype_isknown(type
)) {
653 result
= rdata_validate(buf
, target
, rdclass
, type
);
656 isc_buffer_usedregion(buf
, &r
);
657 result
= isc_buffer_copyregion(target
, &r
);
659 if (result
!= ISC_R_SUCCESS
)
662 isc_buffer_free(&buf
);
663 return (ISC_R_SUCCESS
);
666 isc_buffer_free(&buf
);
671 dns_rdata_fromtext(dns_rdata_t
*rdata
, dns_rdataclass_t rdclass
,
672 dns_rdatatype_t type
, isc_lex_t
*lexer
,
673 dns_name_t
*origin
, unsigned int options
, isc_mem_t
*mctx
,
674 isc_buffer_t
*target
, dns_rdatacallbacks_t
*callbacks
)
676 isc_result_t result
= ISC_R_NOTIMPLEMENTED
;
680 unsigned int lexoptions
= ISC_LEXOPT_EOL
| ISC_LEXOPT_EOF
|
681 ISC_LEXOPT_DNSMULTILINE
| ISC_LEXOPT_ESCAPE
;
684 void (*callback
)(dns_rdatacallbacks_t
*, const char *, ...);
685 isc_result_t tresult
;
687 isc_boolean_t unknown
;
689 REQUIRE(origin
== NULL
|| dns_name_isabsolute(origin
) == ISC_TRUE
);
691 REQUIRE(DNS_RDATA_INITIALIZED(rdata
));
692 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata
));
694 if (callbacks
!= NULL
) {
695 REQUIRE(callbacks
->warn
!= NULL
);
696 REQUIRE(callbacks
->error
!= NULL
);
701 if (callbacks
!= NULL
)
702 callback
= callbacks
->error
;
704 callback
= default_fromtext_callback
;
706 result
= isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_qstring
,
708 if (result
!= ISC_R_SUCCESS
) {
709 name
= isc_lex_getsourcename(lexer
);
710 line
= isc_lex_getsourceline(lexer
);
711 fromtext_error(callback
, callbacks
, name
, line
, NULL
, result
);
716 if (token
.type
== isc_tokentype_string
&&
717 strcmp(DNS_AS_STR(token
), "\\#") == 0) {
719 * If this is a TXT record '\#' could be a escaped '#'.
720 * Look to see if the next token is a number and if so
721 * treat it as a unknown record format.
723 if (type
== dns_rdatatype_txt
) {
724 result
= isc_lex_getmastertoken(lexer
, &token
,
725 isc_tokentype_number
,
727 if (result
== ISC_R_SUCCESS
)
728 isc_lex_ungettoken(lexer
, &token
);
731 if (result
== ISC_R_SUCCESS
) {
733 result
= unknown_fromtext(rdclass
, type
, lexer
,
736 options
|= DNS_RDATA_UNKNOWNESCAPE
;
738 isc_lex_ungettoken(lexer
, &token
);
744 * Consume to end of line / file.
745 * If not at end of line initially set error code.
746 * Call callback via fromtext_error once if there was an error.
749 name
= isc_lex_getsourcename(lexer
);
750 line
= isc_lex_getsourceline(lexer
);
751 tresult
= isc_lex_gettoken(lexer
, lexoptions
, &token
);
752 if (tresult
!= ISC_R_SUCCESS
) {
753 if (result
== ISC_R_SUCCESS
)
755 if (callback
!= NULL
)
756 fromtext_error(callback
, callbacks
, name
,
759 } else if (token
.type
!= isc_tokentype_eol
&&
760 token
.type
!= isc_tokentype_eof
) {
761 if (result
== ISC_R_SUCCESS
)
762 result
= DNS_R_EXTRATOKEN
;
763 if (callback
!= NULL
) {
764 fromtext_error(callback
, callbacks
, name
,
765 line
, &token
, result
);
768 } else if (result
!= ISC_R_SUCCESS
&& callback
!= NULL
) {
769 fromtext_error(callback
, callbacks
, name
, line
,
773 if (token
.type
== isc_tokentype_eof
)
774 fromtext_warneof(lexer
, callbacks
);
779 length
= isc_buffer_usedlength(target
) - isc_buffer_usedlength(&st
);
780 if (result
== ISC_R_SUCCESS
&& length
> DNS_RDATA_MAXLENGTH
)
781 result
= ISC_R_NOSPACE
;
783 if (rdata
!= NULL
&& result
== ISC_R_SUCCESS
) {
784 region
.base
= isc_buffer_used(&st
);
785 region
.length
= length
;
786 dns_rdata_fromregion(rdata
, rdclass
, type
, ®ion
);
788 if (result
!= ISC_R_SUCCESS
) {
795 unknown_totext(dns_rdata_t
*rdata
, dns_rdata_textctx_t
*tctx
,
796 isc_buffer_t
*target
)
799 char buf
[sizeof("65535")];
802 strlcpy(buf
, "\\# ", sizeof(buf
));
803 result
= str_totext(buf
, target
);
804 if (result
!= ISC_R_SUCCESS
)
807 dns_rdata_toregion(rdata
, &sr
);
808 INSIST(sr
.length
< 65536);
809 snprintf(buf
, sizeof(buf
), "%u", sr
.length
);
810 result
= str_totext(buf
, target
);
811 if (result
!= ISC_R_SUCCESS
)
814 if (sr
.length
!= 0U) {
815 if ((tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
816 result
= str_totext(" ( ", target
);
818 result
= str_totext(" ", target
);
820 if (result
!= ISC_R_SUCCESS
)
823 if (tctx
->width
== 0) /* No splitting */
824 result
= isc_hex_totext(&sr
, 0, "", target
);
826 result
= isc_hex_totext(&sr
, tctx
->width
- 2,
829 if (result
== ISC_R_SUCCESS
&&
830 (tctx
->flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
831 result
= str_totext(" )", target
);
837 rdata_totext(dns_rdata_t
*rdata
, dns_rdata_textctx_t
*tctx
,
838 isc_buffer_t
*target
)
840 isc_result_t result
= ISC_R_NOTIMPLEMENTED
;
841 isc_boolean_t use_default
= ISC_FALSE
;
843 REQUIRE(rdata
!= NULL
);
844 REQUIRE(tctx
->origin
== NULL
||
845 dns_name_isabsolute(tctx
->origin
) == ISC_TRUE
);
848 * Some DynDNS meta-RRs have empty rdata.
850 if ((rdata
->flags
& DNS_RDATA_UPDATE
) != 0) {
851 INSIST(rdata
->length
== 0);
852 return (ISC_R_SUCCESS
);
858 result
= unknown_totext(rdata
, tctx
, target
);
864 dns_rdata_totext(dns_rdata_t
*rdata
, dns_name_t
*origin
, isc_buffer_t
*target
)
866 dns_rdata_textctx_t tctx
;
868 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata
));
871 * Set up formatting options for single-line output.
873 tctx
.origin
= origin
;
876 tctx
.linebreak
= " ";
877 return (rdata_totext(rdata
, &tctx
, target
));
881 dns_rdata_tofmttext(dns_rdata_t
*rdata
, dns_name_t
*origin
,
882 unsigned int flags
, unsigned int width
,
883 unsigned int split_width
, const char *linebreak
,
884 isc_buffer_t
*target
)
886 dns_rdata_textctx_t tctx
;
888 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata
));
891 * Set up formatting options for formatted output.
893 tctx
.origin
= origin
;
895 if (split_width
== 0xffffffff)
898 tctx
.width
= split_width
;
900 if ((flags
& DNS_STYLEFLAG_MULTILINE
) != 0)
901 tctx
.linebreak
= linebreak
;
903 if (split_width
== 0xffffffff)
904 tctx
.width
= 60; /* Used for hex word length only. */
905 tctx
.linebreak
= " ";
907 return (rdata_totext(rdata
, &tctx
, target
));
911 dns_rdata_fromstruct(dns_rdata_t
*rdata
, dns_rdataclass_t rdclass
,
912 dns_rdatatype_t type
, void *source
,
913 isc_buffer_t
*target
)
915 isc_result_t result
= ISC_R_NOTIMPLEMENTED
;
918 isc_boolean_t use_default
= ISC_FALSE
;
921 REQUIRE(source
!= NULL
);
923 REQUIRE(DNS_RDATA_INITIALIZED(rdata
));
924 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata
));
934 length
= isc_buffer_usedlength(target
) - isc_buffer_usedlength(&st
);
935 if (result
== ISC_R_SUCCESS
&& length
> DNS_RDATA_MAXLENGTH
)
936 result
= ISC_R_NOSPACE
;
938 if (rdata
!= NULL
&& result
== ISC_R_SUCCESS
) {
939 region
.base
= isc_buffer_used(&st
);
940 region
.length
= length
;
941 dns_rdata_fromregion(rdata
, rdclass
, type
, ®ion
);
943 if (result
!= ISC_R_SUCCESS
)
949 dns_rdata_tostruct(dns_rdata_t
*rdata
, void *target
, isc_mem_t
*mctx
) {
950 isc_result_t result
= ISC_R_NOTIMPLEMENTED
;
951 isc_boolean_t use_default
= ISC_FALSE
;
953 REQUIRE(rdata
!= NULL
);
954 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata
));
965 dns_rdata_freestruct(void *source
) {
966 dns_rdatacommon_t
*common
= source
;
967 REQUIRE(source
!= NULL
);
973 dns_rdata_additionaldata(dns_rdata_t
*rdata
, dns_additionaldatafunc_t add
,
976 isc_result_t result
= ISC_R_NOTIMPLEMENTED
;
977 isc_boolean_t use_default
= ISC_FALSE
;
980 * Call 'add' for each name and type from 'rdata' which is subject to
981 * additional section processing.
984 REQUIRE(rdata
!= NULL
);
985 REQUIRE(add
!= NULL
);
986 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata
));
990 /* No additional processing for unknown types */
992 result
= ISC_R_SUCCESS
;
998 dns_rdata_digest(dns_rdata_t
*rdata
, dns_digestfunc_t digest
, void *arg
) {
999 isc_result_t result
= ISC_R_NOTIMPLEMENTED
;
1000 isc_boolean_t use_default
= ISC_FALSE
;
1004 * Send 'rdata' in DNSSEC canonical form to 'digest'.
1007 REQUIRE(rdata
!= NULL
);
1008 REQUIRE(digest
!= NULL
);
1009 REQUIRE(DNS_RDATA_VALIDFLAGS(rdata
));
1014 dns_rdata_toregion(rdata
, &r
);
1015 result
= (digest
)(arg
, &r
);
1022 dns_rdata_checkowner(dns_name_t
*name
, dns_rdataclass_t rdclass
,
1023 dns_rdatatype_t type
, isc_boolean_t wildcard
)
1025 isc_boolean_t result
;
1032 dns_rdata_checknames(dns_rdata_t
*rdata
, dns_name_t
*owner
, dns_name_t
*bad
)
1034 isc_boolean_t result
;
1041 dns_rdatatype_attributes(dns_rdatatype_t type
)
1043 RDATATYPE_ATTRIBUTE_SW
1044 if (type
>= (dns_rdatatype_t
)128 && type
< (dns_rdatatype_t
)255)
1045 return (DNS_RDATATYPEATTR_UNKNOWN
| DNS_RDATATYPEATTR_META
);
1046 return (DNS_RDATATYPEATTR_UNKNOWN
);
1050 dns_rdatatype_fromtext(dns_rdatatype_t
*typep
, isc_textregion_t
*source
) {
1058 return (DNS_R_UNKNOWN
);
1060 a
= tolower((unsigned char)source
->base
[0]);
1061 b
= tolower((unsigned char)source
->base
[n
- 1]);
1063 hash
= ((a
+ n
) * b
) % 256;
1066 * This switch block is inlined via \#define, and will use "return"
1067 * to return a result to the caller if it is a valid (known)
1070 RDATATYPE_FROMTEXT_SW(hash
, source
->base
, n
, typep
);
1072 if (source
->length
> 4 && source
->length
< (4 + sizeof("65000")) &&
1073 strncasecmp("type", source
->base
, 4) == 0) {
1074 char buf
[sizeof("65000")];
1078 strncpy(buf
, source
->base
+ 4, source
->length
- 4);
1079 buf
[source
->length
- 4] = '\0';
1080 val
= strtoul(buf
, &endp
, 10);
1081 if (*endp
== '\0' && val
<= 0xffff) {
1082 *typep
= (dns_rdatatype_t
)val
;
1083 return (ISC_R_SUCCESS
);
1087 return (DNS_R_UNKNOWN
);
1091 dns_rdatatype_totext(dns_rdatatype_t type
, isc_buffer_t
*target
) {
1092 char buf
[sizeof("TYPE65535")];
1095 snprintf(buf
, sizeof(buf
), "TYPE%u", type
);
1096 return (str_totext(buf
, target
));
1100 dns_rdatatype_format(dns_rdatatype_t rdtype
,
1101 char *array
, unsigned int size
)
1103 isc_result_t result
;
1109 isc_buffer_init(&buf
, array
, size
);
1110 result
= dns_rdatatype_totext(rdtype
, &buf
);
1114 if (result
== ISC_R_SUCCESS
) {
1115 if (isc_buffer_availablelength(&buf
) >= 1)
1116 isc_buffer_putuint8(&buf
, 0);
1118 result
= ISC_R_NOSPACE
;
1120 if (result
!= ISC_R_SUCCESS
)
1121 strlcpy(array
, "<unknown>", size
);
1129 name_length(dns_name_t
*name
) {
1130 return (name
->length
);
1134 txt_totext(isc_region_t
*source
, isc_boolean_t quote
, isc_buffer_t
*target
) {
1139 isc_region_t region
;
1141 isc_buffer_availableregion(target
, ®ion
);
1143 tp
= (char *)region
.base
;
1148 REQUIRE(n
+ 1 <= source
->length
);
1150 REQUIRE(quote
== ISC_TRUE
);
1154 return (ISC_R_NOSPACE
);
1160 * \DDD space (0x20) if not quoting.
1162 if (*sp
< (quote
? 0x20 : 0x21) || *sp
>= 0x7f) {
1164 return (ISC_R_NOSPACE
);
1166 *tp
++ = 0x30 + ((*sp
/ 100) % 10);
1167 *tp
++ = 0x30 + ((*sp
/ 10) % 10);
1168 *tp
++ = 0x30 + (*sp
% 10);
1174 * Escape double quote and backslash. If we are not
1175 * enclosing the string in double quotes also escape
1176 * at sign and semicolon.
1178 if (*sp
== 0x22 || *sp
== 0x5c ||
1179 (!quote
&& (*sp
== 0x40 || *sp
== 0x3b))) {
1181 return (ISC_R_NOSPACE
);
1186 return (ISC_R_NOSPACE
);
1192 return (ISC_R_NOSPACE
);
1196 isc_buffer_add(target
, (unsigned int)(tp
- (char *)region
.base
));
1197 isc_region_consume(source
, *source
->base
+ 1);
1198 return (ISC_R_SUCCESS
);
1202 txt_fromtext(isc_textregion_t
*source
, isc_buffer_t
*target
) {
1203 isc_region_t tregion
;
1204 isc_boolean_t escape
;
1205 unsigned int n
, nrem
;
1211 isc_buffer_availableregion(target
, &tregion
);
1215 nrem
= tregion
.length
;
1218 return (ISC_R_NOSPACE
);
1225 * Maximum text string length.
1231 if (escape
&& (d
= decvalue((char)c
)) != -1) {
1234 return (DNS_R_SYNTAX
);
1236 if ((d
= decvalue(*s
++)) != -1)
1239 return (DNS_R_SYNTAX
);
1241 return (DNS_R_SYNTAX
);
1243 if ((d
= decvalue(*s
++)) != -1)
1246 return (DNS_R_SYNTAX
);
1248 return (DNS_R_SYNTAX
);
1249 } else if (!escape
&& c
== '\\') {
1255 return ((tregion
.length
<= 256U) ?
1256 ISC_R_NOSPACE
: DNS_R_SYNTAX
);
1261 return (DNS_R_SYNTAX
);
1262 *tregion
.base
= (unsigned char)(t
- tregion
.base
- 1);
1263 isc_buffer_add(target
, *tregion
.base
+ 1);
1264 return (ISC_R_SUCCESS
);
1268 txt_fromwire(isc_buffer_t
*source
, isc_buffer_t
*target
) {
1270 isc_region_t sregion
;
1271 isc_region_t tregion
;
1273 isc_buffer_activeregion(source
, &sregion
);
1274 if (sregion
.length
== 0)
1275 return (ISC_R_UNEXPECTEDEND
);
1276 n
= *sregion
.base
+ 1;
1277 if (n
> sregion
.length
)
1278 return (ISC_R_UNEXPECTEDEND
);
1280 isc_buffer_availableregion(target
, &tregion
);
1281 if (n
> tregion
.length
)
1282 return (ISC_R_NOSPACE
);
1284 if (tregion
.base
!= sregion
.base
)
1285 memmove(tregion
.base
, sregion
.base
, n
);
1286 isc_buffer_forward(source
, n
);
1287 isc_buffer_add(target
, n
);
1288 return (ISC_R_SUCCESS
);
1292 * Conversion of TXT-like rdata fields without length limits.
1295 multitxt_totext(isc_region_t
*source
, isc_buffer_t
*target
) {
1300 isc_region_t region
;
1302 isc_buffer_availableregion(target
, ®ion
);
1304 tp
= (char *)region
.base
;
1308 return (ISC_R_NOSPACE
);
1313 n0
= source
->length
- 1;
1316 if (*sp
< 0x20 || *sp
>= 0x7f) {
1318 return (ISC_R_NOSPACE
);
1320 *tp
++ = 0x30 + ((*sp
/ 100) % 10);
1321 *tp
++ = 0x30 + ((*sp
/ 10) % 10);
1322 *tp
++ = 0x30 + (*sp
% 10);
1327 /* double quote, semi-colon, backslash */
1328 if (*sp
== 0x22 || *sp
== 0x3b || *sp
== 0x5c) {
1330 return (ISC_R_NOSPACE
);
1335 return (ISC_R_NOSPACE
);
1339 isc_region_consume(source
, n0
+ 1);
1340 } while (source
->length
!= 0);
1342 return (ISC_R_NOSPACE
);
1345 isc_buffer_add(target
, (unsigned int)(tp
- (char *)region
.base
));
1346 return (ISC_R_SUCCESS
);
1350 multitxt_fromtext(isc_textregion_t
*source
, isc_buffer_t
*target
) {
1351 isc_region_t tregion
;
1352 isc_boolean_t escape
;
1353 unsigned int n
, nrem
;
1355 unsigned char *t0
, *t
;
1364 isc_buffer_availableregion(target
, &tregion
);
1365 t0
= t
= tregion
.base
;
1366 nrem
= tregion
.length
;
1368 return (ISC_R_NOSPACE
);
1373 if (escape
&& (d
= decvalue((char)c
)) != -1) {
1376 return (DNS_R_SYNTAX
);
1378 if ((d
= decvalue(*s
++)) != -1)
1381 return (DNS_R_SYNTAX
);
1383 return (DNS_R_SYNTAX
);
1385 if ((d
= decvalue(*s
++)) != -1)
1388 return (DNS_R_SYNTAX
);
1390 return (DNS_R_SYNTAX
);
1391 } else if (!escape
&& c
== '\\') {
1402 return (DNS_R_SYNTAX
);
1404 isc_buffer_add(target
, t
- t0
);
1406 return (ISC_R_SUCCESS
);
1409 static isc_boolean_t
1410 name_prefix(dns_name_t
*name
, dns_name_t
*origin
, dns_name_t
*target
) {
1416 if (dns_name_compare(origin
, dns_rootname
) == 0)
1419 if (!dns_name_issubdomain(name
, origin
))
1422 l1
= dns_name_countlabels(name
);
1423 l2
= dns_name_countlabels(origin
);
1428 /* Master files should be case preserving. */
1429 dns_name_getlabelsequence(name
, l1
- l2
, l2
, target
);
1430 if (!dns_name_caseequal(origin
, target
))
1433 dns_name_getlabelsequence(name
, 0, l1
- l2
, target
);
1442 str_totext(const char *source
, isc_buffer_t
*target
) {
1444 isc_region_t region
;
1446 isc_buffer_availableregion(target
, ®ion
);
1449 if (l
> region
.length
)
1450 return (ISC_R_NOSPACE
);
1452 memmove(region
.base
, source
, l
);
1453 isc_buffer_add(target
, l
);
1454 return (ISC_R_SUCCESS
);
1458 inet_totext(int af
, isc_region_t
*src
, isc_buffer_t
*target
) {
1461 /* Note - inet_ntop doesn't do size checking on its input. */
1462 if (inet_ntop(af
, src
->base
, tmpbuf
, sizeof(tmpbuf
)) == NULL
)
1463 return (ISC_R_NOSPACE
);
1464 if (strlen(tmpbuf
) > isc_buffer_availablelength(target
))
1465 return (ISC_R_NOSPACE
);
1466 isc_buffer_putstr(target
, tmpbuf
);
1467 return (ISC_R_SUCCESS
);
1470 static isc_boolean_t
1471 buffer_empty(isc_buffer_t
*source
) {
1472 return((source
->current
== source
->active
) ? ISC_TRUE
: ISC_FALSE
);
1476 buffer_fromregion(isc_buffer_t
*buffer
, isc_region_t
*region
) {
1477 isc_buffer_init(buffer
, region
->base
, region
->length
);
1478 isc_buffer_add(buffer
, region
->length
);
1479 isc_buffer_setactive(buffer
, region
->length
);
1483 uint32_tobuffer(isc_uint32_t value
, isc_buffer_t
*target
) {
1484 isc_region_t region
;
1486 isc_buffer_availableregion(target
, ®ion
);
1487 if (region
.length
< 4)
1488 return (ISC_R_NOSPACE
);
1489 isc_buffer_putuint32(target
, value
);
1490 return (ISC_R_SUCCESS
);
1494 uint16_tobuffer(isc_uint32_t value
, isc_buffer_t
*target
) {
1495 isc_region_t region
;
1498 return (ISC_R_RANGE
);
1499 isc_buffer_availableregion(target
, ®ion
);
1500 if (region
.length
< 2)
1501 return (ISC_R_NOSPACE
);
1502 isc_buffer_putuint16(target
, (isc_uint16_t
)value
);
1503 return (ISC_R_SUCCESS
);
1507 uint8_tobuffer(isc_uint32_t value
, isc_buffer_t
*target
) {
1508 isc_region_t region
;
1511 return (ISC_R_RANGE
);
1512 isc_buffer_availableregion(target
, ®ion
);
1513 if (region
.length
< 1)
1514 return (ISC_R_NOSPACE
);
1515 isc_buffer_putuint8(target
, (isc_uint8_t
)value
);
1516 return (ISC_R_SUCCESS
);
1520 name_tobuffer(dns_name_t
*name
, isc_buffer_t
*target
) {
1522 dns_name_toregion(name
, &r
);
1523 return (isc_buffer_copyregion(target
, &r
));
1527 uint32_fromregion(isc_region_t
*region
) {
1530 REQUIRE(region
->length
>= 4);
1531 value
= region
->base
[0] << 24;
1532 value
|= region
->base
[1] << 16;
1533 value
|= region
->base
[2] << 8;
1534 value
|= region
->base
[3];
1539 uint16_consume_fromregion(isc_region_t
*region
) {
1540 isc_uint16_t r
= uint16_fromregion(region
);
1542 isc_region_consume(region
, 2);
1547 uint16_fromregion(isc_region_t
*region
) {
1549 REQUIRE(region
->length
>= 2);
1551 return ((region
->base
[0] << 8) | region
->base
[1]);
1555 uint8_fromregion(isc_region_t
*region
) {
1557 REQUIRE(region
->length
>= 1);
1559 return (region
->base
[0]);
1563 uint8_consume_fromregion(isc_region_t
*region
) {
1564 isc_uint8_t r
= uint8_fromregion(region
);
1566 isc_region_consume(region
, 1);
1571 mem_tobuffer(isc_buffer_t
*target
, void *base
, unsigned int length
) {
1574 isc_buffer_availableregion(target
, &tr
);
1575 if (length
> tr
.length
)
1576 return (ISC_R_NOSPACE
);
1577 if (tr
.base
!= base
)
1578 memmove(tr
.base
, base
, length
);
1579 isc_buffer_add(target
, length
);
1580 return (ISC_R_SUCCESS
);
1584 hexvalue(char value
) {
1588 c
= (unsigned char)value
;
1594 if ((s
= strchr(hexdigits
, c
)) == NULL
)
1596 return (int)(s
- hexdigits
);
1600 decvalue(char value
) {
1604 * isascii() is valid for full range of int values, no need to
1607 if (!isascii(value
))
1609 if ((s
= strchr(decdigits
, value
)) == NULL
)
1611 return (int)(s
- decdigits
);
1614 static const char atob_digits
[86] =
1615 "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`" \
1616 "abcdefghijklmnopqrstu";
1618 * Subroutines to convert between 8 bit binary bytes and printable ASCII.
1619 * Computes the number of bytes, and three kinds of simple checksums.
1620 * Incoming bytes are collected into 32-bit words, then printed in base 85:
1621 * exp(85,5) > exp(2,32)
1622 * The ASCII characters used are between '!' and 'u';
1623 * 'z' encodes 32-bit zero; 'x' is used to mark the end of encoded data.
1625 * Originally by Paul Rutter (philabs!per) and Joe Orost (petsd!joe) for
1626 * the atob/btoa programs, released with the compress program, in mod.sources.
1627 * Modified by Mike Schwartz 8/19/86 for use in BIND.
1628 * Modified to be re-entrant 3/2/99.
1640 #define Ceor state->Ceor
1641 #define Csum state->Csum
1642 #define Crot state->Crot
1643 #define word state->word
1644 #define bcount state->bcount
1646 #define times85(x) ((((((x<<2)+x)<<2)+x)<<2)+x)
1648 static isc_result_t
byte_atob(int c
, isc_buffer_t
*target
,
1649 struct state
*state
);
1650 static isc_result_t
putbyte(int c
, isc_buffer_t
*, struct state
*state
);
1651 static isc_result_t
byte_btoa(int c
, isc_buffer_t
*, struct state
*state
);
1654 * Decode ASCII-encoded byte c into binary representation and
1655 * place into *bufp, advancing bufp.
1658 byte_atob(int c
, isc_buffer_t
*target
, struct state
*state
) {
1662 return(DNS_R_SYNTAX
);
1664 RETERR(putbyte(0, target
, state
));
1665 RETERR(putbyte(0, target
, state
));
1666 RETERR(putbyte(0, target
, state
));
1667 RETERR(putbyte(0, target
, state
));
1669 } else if ((s
= strchr(atob_digits
, c
)) != NULL
) {
1671 word
= (isc_int32_t
)(s
- atob_digits
);
1673 } else if (bcount
< 4) {
1674 word
= times85(word
);
1675 word
+= (isc_int32_t
)(s
- atob_digits
);
1678 word
= times85(word
);
1679 word
+= (isc_int32_t
)(s
- atob_digits
);
1680 RETERR(putbyte((word
>> 24) & 0xff, target
, state
));
1681 RETERR(putbyte((word
>> 16) & 0xff, target
, state
));
1682 RETERR(putbyte((word
>> 8) & 0xff, target
, state
));
1683 RETERR(putbyte(word
& 0xff, target
, state
));
1688 return(DNS_R_SYNTAX
);
1689 return(ISC_R_SUCCESS
);
1693 * Compute checksum info and place c into target.
1696 putbyte(int c
, isc_buffer_t
*target
, struct state
*state
) {
1702 if ((Crot
& 0x80000000)) {
1709 isc_buffer_availableregion(target
, &tr
);
1711 return (ISC_R_NOSPACE
);
1713 isc_buffer_add(target
, 1);
1714 return (ISC_R_SUCCESS
);
1718 * Read the ASCII-encoded data from inbuf, of length inbuflen, and convert
1719 * it into T_UNSPEC (binary data) in outbuf, not to exceed outbuflen bytes;
1720 * outbuflen must be divisible by 4. (Note: this is because outbuf is filled
1721 * in 4 bytes at a time. If the actual data doesn't end on an even 4-byte
1722 * boundary, there will be no problem...it will be padded with 0 bytes, and
1723 * numbytes will indicate the correct number of bytes. The main point is
1724 * that since the buffer is filled in 4 bytes at a time, even if there is
1725 * not a full 4 bytes of data at the end, there has to be room to 0-pad the
1726 * data, so the buffer must be of size divisible by 4). Place the number of
1727 * output bytes in numbytes, and return a failure/success status.
1731 atob_tobuffer(isc_lex_t
*lexer
, isc_buffer_t
*target
) {
1732 long oeor
, osum
, orot
;
1733 struct state statebuf
, *state
= &statebuf
;
1738 Ceor
= Csum
= Crot
= word
= bcount
= 0;
1740 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
1742 while (token
.value
.as_textregion
.length
!= 0) {
1743 if ((c
= token
.value
.as_textregion
.base
[0]) == 'x') {
1746 RETERR(byte_atob(c
, target
, state
));
1747 isc_textregion_consume(&token
.value
.as_textregion
, 1);
1753 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_number
,
1755 if ((token
.value
.as_ulong
% 4) != 0U)
1756 isc_buffer_subtract(target
, 4 - (token
.value
.as_ulong
% 4));
1761 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
1763 oeor
= strtol(DNS_AS_STR(token
), &e
, 16);
1765 return (DNS_R_SYNTAX
);
1770 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
1772 osum
= strtol(DNS_AS_STR(token
), &e
, 16);
1774 return (DNS_R_SYNTAX
);
1779 RETERR(isc_lex_getmastertoken(lexer
, &token
, isc_tokentype_string
,
1781 orot
= strtol(DNS_AS_STR(token
), &e
, 16);
1783 return (DNS_R_SYNTAX
);
1785 if ((oeor
!= Ceor
) || (osum
!= Csum
) || (orot
!= Crot
))
1786 return(DNS_R_BADCKSUM
);
1787 return (ISC_R_SUCCESS
);
1791 * Encode binary byte c into ASCII representation and place into *bufp,
1795 byte_btoa(int c
, isc_buffer_t
*target
, struct state
*state
) {
1798 isc_buffer_availableregion(target
, &tr
);
1802 if ((Crot
& 0x80000000)) {
1815 return (ISC_R_NOSPACE
);
1817 isc_buffer_add(target
, 1);
1819 register int tmp
= 0;
1820 register isc_int32_t tmpword
= word
;
1824 * Because some don't support u_long.
1827 tmpword
-= (isc_int32_t
)(85 * 85 * 85 * 85 * 32);
1831 tmpword
-= (isc_int32_t
)(85 * 85 * 85 * 85 * 32);
1834 return (ISC_R_NOSPACE
);
1835 tr
.base
[0] = atob_digits
[(tmpword
/
1836 (isc_int32_t
)(85 * 85 * 85 * 85))
1838 tmpword
%= (isc_int32_t
)(85 * 85 * 85 * 85);
1839 tr
.base
[1] = atob_digits
[tmpword
/ (85 * 85 * 85)];
1840 tmpword
%= (85 * 85 * 85);
1841 tr
.base
[2] = atob_digits
[tmpword
/ (85 * 85)];
1842 tmpword
%= (85 * 85);
1843 tr
.base
[3] = atob_digits
[tmpword
/ 85];
1845 tr
.base
[4] = atob_digits
[tmpword
];
1846 isc_buffer_add(target
, 5);
1852 return (ISC_R_SUCCESS
);
1857 * Encode the binary data from inbuf, of length inbuflen, into a
1858 * target. Return success/failure status
1861 btoa_totext(unsigned char *inbuf
, int inbuflen
, isc_buffer_t
*target
) {
1863 struct state statebuf
, *state
= &statebuf
;
1864 char buf
[sizeof("x 2000000000 ffffffff ffffffff ffffffff")];
1866 Ceor
= Csum
= Crot
= word
= bcount
= 0;
1867 for (inc
= 0; inc
< inbuflen
; inbuf
++, inc
++)
1868 RETERR(byte_btoa(*inbuf
, target
, state
));
1871 RETERR(byte_btoa(0, target
, state
));
1874 * Put byte count and checksum information at end of buffer,
1877 snprintf(buf
, sizeof(buf
), "x %d %x %x %x", inbuflen
, Ceor
, Csum
, Crot
);
1878 return (str_totext(buf
, target
));
1883 default_fromtext_callback(dns_rdatacallbacks_t
*callbacks
, const char *fmt
,
1891 vfprintf(stderr
, fmt
, ap
);
1893 fprintf(stderr
, "\n");
1897 fromtext_warneof(isc_lex_t
*lexer
, dns_rdatacallbacks_t
*callbacks
) {
1898 if (isc_lex_isfile(lexer
) && callbacks
!= NULL
) {
1899 const char *name
= isc_lex_getsourcename(lexer
);
1902 (*callbacks
->warn
)(callbacks
,
1903 "%s:%lu: file does not end with newline",
1904 name
, isc_lex_getsourceline(lexer
));
1909 warn_badmx(isc_token_t
*token
, isc_lex_t
*lexer
,
1910 dns_rdatacallbacks_t
*callbacks
)
1915 if (lexer
!= NULL
) {
1916 file
= isc_lex_getsourcename(lexer
);
1917 line
= isc_lex_getsourceline(lexer
);
1918 (*callbacks
->warn
)(callbacks
, "%s:%u: warning: '%s': %s",
1919 file
, line
, DNS_AS_STR(*token
),
1920 dns_result_totext(DNS_R_MXISADDRESS
));
1925 warn_badname(dns_name_t
*name
, isc_lex_t
*lexer
,
1926 dns_rdatacallbacks_t
*callbacks
)
1930 char namebuf
[DNS_NAME_FORMATSIZE
];
1932 if (lexer
!= NULL
) {
1933 file
= isc_lex_getsourcename(lexer
);
1934 line
= isc_lex_getsourceline(lexer
);
1935 dns_name_format(name
, namebuf
, sizeof(namebuf
));
1936 (*callbacks
->warn
)(callbacks
, "%s:%u: warning: %s: %s",
1937 file
, line
, namebuf
,
1938 dns_result_totext(DNS_R_BADNAME
));
1943 fromtext_error(void (*callback
)(dns_rdatacallbacks_t
*, const char *, ...),
1944 dns_rdatacallbacks_t
*callbacks
, const char *name
,
1945 unsigned long line
, isc_token_t
*token
, isc_result_t result
)
1950 if (token
!= NULL
) {
1951 switch (token
->type
) {
1952 case isc_tokentype_eol
:
1953 (*callback
)(callbacks
, "%s: %s:%lu: near eol: %s",
1954 "dns_rdata_fromtext", name
, line
,
1955 dns_result_totext(result
));
1957 case isc_tokentype_eof
:
1958 (*callback
)(callbacks
, "%s: %s:%lu: near eof: %s",
1959 "dns_rdata_fromtext", name
, line
,
1960 dns_result_totext(result
));
1962 case isc_tokentype_number
:
1963 (*callback
)(callbacks
, "%s: %s:%lu: near %lu: %s",
1964 "dns_rdata_fromtext", name
, line
,
1965 token
->value
.as_ulong
,
1966 dns_result_totext(result
));
1968 case isc_tokentype_string
:
1969 case isc_tokentype_qstring
:
1970 (*callback
)(callbacks
, "%s: %s:%lu: near '%s': %s",
1971 "dns_rdata_fromtext", name
, line
,
1973 dns_result_totext(result
));
1976 (*callback
)(callbacks
, "%s: %s:%lu: %s",
1977 "dns_rdata_fromtext", name
, line
,
1978 dns_result_totext(result
));
1982 (*callback
)(callbacks
, "dns_rdata_fromtext: %s:%lu: %s",
1983 name
, line
, dns_result_totext(result
));
1988 dns_rdata_covers(dns_rdata_t
*rdata
) {
1989 if (rdata
->type
== 46)
1990 return (covers_rrsig(rdata
));
1991 return (covers_sig(rdata
));
1995 dns_rdatatype_ismeta(dns_rdatatype_t type
) {
1996 if ((dns_rdatatype_attributes(type
) & DNS_RDATATYPEATTR_META
) != 0)
2002 dns_rdatatype_issingleton(dns_rdatatype_t type
) {
2003 if ((dns_rdatatype_attributes(type
) & DNS_RDATATYPEATTR_SINGLETON
)
2010 dns_rdatatype_notquestion(dns_rdatatype_t type
) {
2011 if ((dns_rdatatype_attributes(type
) & DNS_RDATATYPEATTR_NOTQUESTION
)
2018 dns_rdatatype_questiononly(dns_rdatatype_t type
) {
2019 if ((dns_rdatatype_attributes(type
) & DNS_RDATATYPEATTR_QUESTIONONLY
)
2026 dns_rdatatype_atparent(dns_rdatatype_t type
) {
2027 if ((dns_rdatatype_attributes(type
) & DNS_RDATATYPEATTR_ATPARENT
) != 0)
2033 dns_rdataclass_ismeta(dns_rdataclass_t rdclass
) {
2035 if (rdclass
== dns_rdataclass_reserved0
2036 || rdclass
== dns_rdataclass_none
2037 || rdclass
== dns_rdataclass_any
)
2040 return (ISC_FALSE
); /* Assume it is not a meta class. */
2044 dns_rdatatype_isdnssec(dns_rdatatype_t type
) {
2045 if ((dns_rdatatype_attributes(type
) & DNS_RDATATYPEATTR_DNSSEC
) != 0)
2051 dns_rdatatype_iszonecutauth(dns_rdatatype_t type
) {
2052 if ((dns_rdatatype_attributes(type
)
2053 & (DNS_RDATATYPEATTR_DNSSEC
| DNS_RDATATYPEATTR_ZONECUTAUTH
))
2060 dns_rdatatype_isknown(dns_rdatatype_t type
) {
2061 if ((dns_rdatatype_attributes(type
) & DNS_RDATATYPEATTR_UNKNOWN
)
2068 dns_rdata_exists(dns_rdata_t
*rdata
, dns_rdatatype_t type
) {
2070 REQUIRE(rdata
!= NULL
);
2071 REQUIRE(DNS_RDATA_INITIALIZED(rdata
));
2075 rdata
->flags
= DNS_RDATA_UPDATE
;
2077 rdata
->rdclass
= dns_rdataclass_any
;
2081 dns_rdata_notexist(dns_rdata_t
*rdata
, dns_rdatatype_t type
) {
2083 REQUIRE(rdata
!= NULL
);
2084 REQUIRE(DNS_RDATA_INITIALIZED(rdata
));
2088 rdata
->flags
= DNS_RDATA_UPDATE
;
2090 rdata
->rdclass
= dns_rdataclass_none
;
2094 dns_rdata_deleterrset(dns_rdata_t
*rdata
, dns_rdatatype_t type
) {
2096 REQUIRE(rdata
!= NULL
);
2097 REQUIRE(DNS_RDATA_INITIALIZED(rdata
));
2101 rdata
->flags
= DNS_RDATA_UPDATE
;
2103 rdata
->rdclass
= dns_rdataclass_any
;
2107 dns_rdata_makedelete(dns_rdata_t
*rdata
) {
2108 REQUIRE(rdata
!= NULL
);
2110 rdata
->rdclass
= dns_rdataclass_none
;
2114 dns_rdata_updateop(dns_rdata_t
*rdata
, dns_section_t section
) {
2116 REQUIRE(rdata
!= NULL
);
2117 REQUIRE(DNS_RDATA_INITIALIZED(rdata
));
2120 case DNS_SECTION_PREREQUISITE
:
2121 switch (rdata
->rdclass
) {
2122 case dns_rdataclass_none
:
2123 switch (rdata
->type
) {
2124 case dns_rdatatype_any
:
2125 return ("domain doesn't exist");
2127 return ("rrset doesn't exist");
2129 case dns_rdataclass_any
:
2130 switch (rdata
->type
) {
2131 case dns_rdatatype_any
:
2132 return ("domain exists");
2134 return ("rrset exists (value independent)");
2137 return ("rrset exists (value dependent)");
2139 case DNS_SECTION_UPDATE
:
2140 switch (rdata
->rdclass
) {
2141 case dns_rdataclass_none
:
2143 case dns_rdataclass_any
:
2144 switch (rdata
->type
) {
2145 case dns_rdatatype_any
:
2146 return ("delete all rrsets");
2148 return ("delete rrset");