From 7ec579cd5d07228c0d6cece58b80694ad8d59de9 Mon Sep 17 00:00:00 2001 From: Michael Graff Date: Fri, 14 Apr 2000 20:13:49 +0000 Subject: [PATCH] Add functions to check that a type is only or is not allowed in a question section --- lib/dns/gen.c | 11 +++++--- lib/dns/include/dns/rdata.h | 36 ++++++++++++++++++++---- lib/dns/message.c | 18 ++++++++++++ lib/dns/rdata.c | 47 +++++++++++++++++++++----------- lib/dns/rdata/any_255/tsig_250.c | 4 +-- lib/dns/rdata/generic/opt_41.c | 4 +-- 6 files changed, 91 insertions(+), 29 deletions(-) diff --git a/lib/dns/gen.c b/lib/dns/gen.c index 947dd455d4..d9c13e13d4 100644 --- a/lib/dns/gen.c +++ b/lib/dns/gen.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: gen.c,v 1.33 2000/04/07 03:54:03 explorer Exp $ */ +/* $Id: gen.c,v 1.34 2000/04/14 20:13:43 explorer Exp $ */ #include @@ -560,6 +560,9 @@ main(int argc, char **argv) { #define PRINT_COMMA(x) (x == 255 ? "" : ",") +#define METANOTQUESTION "DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_NOTQUESTION" +#define METAQUESTIONONLY "DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_QUESTIONONLY" + printf("\ntypedef struct {\n"); printf("\tchar *name;\n"); printf("\tunsigned int flags;\n"); @@ -613,13 +616,13 @@ main(int argc, char **argv) { break; case 251: printf("\t{ \"IXFR\", " - "DNS_RDATATYPEATTR_META }%s\n", + METANOTQUESTION " }%s\n", PRINT_COMMA(i)); special = 1; break; case 252: printf("\t{ \"AXFR\", " - "DNS_RDATATYPEATTR_META }%s\n", + METANOTQUESTION " }%s\n", PRINT_COMMA(i)); special = 1; break; @@ -637,7 +640,7 @@ main(int argc, char **argv) { break; case 255: printf("\t{ \"ANY\", " - "DNS_RDATATYPEATTR_META }%s\n", + METAQUESTIONONLY " }%s\n", PRINT_COMMA(i)); special = 1; break; diff --git a/lib/dns/include/dns/rdata.h b/lib/dns/include/dns/rdata.h index a4c64a7329..51bb72bc23 100644 --- a/lib/dns/include/dns/rdata.h +++ b/lib/dns/include/dns/rdata.h @@ -538,6 +538,28 @@ dns_rdata_digest(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg); * Many other results are possible if not successful. */ +isc_boolean_t +dns_rdatatype_questiononly(dns_rdatatype_t type); +/* + * Return true iff rdata of type 'type' can only appear in the question + * section of a properly formatted message. + * + * Requires: + * 'type' is a valid rdata type. + * + */ + +isc_boolean_t +dns_rdatatype_notquestion(dns_rdatatype_t type); +/* + * Return true iff rdata of type 'type' can not appear in the question + * section of a properly formatted message. + * + * Requires: + * 'type' is a valid rdata type. + * + */ + unsigned int dns_rdatatype_attributes(dns_rdatatype_t rdtype); /* @@ -551,19 +573,23 @@ dns_rdatatype_attributes(dns_rdatatype_t rdtype); */ /* only one may exist for a name */ -#define DNS_RDATATYPEATTR_SINGLETON 0x00000001U +#define DNS_RDATATYPEATTR_SINGLETON 0x00000001U /* requires no other data be present */ -#define DNS_RDATATYPEATTR_EXCLUSIVE 0x00000002U +#define DNS_RDATATYPEATTR_EXCLUSIVE 0x00000002U /* Is a meta type */ -#define DNS_RDATATYPEATTR_META 0x00000004U +#define DNS_RDATATYPEATTR_META 0x00000004U /* Is a DNSSEC type, like SIG or NXT */ #define DNS_RDATATYPEATTR_DNSSEC 0x00000008U -/* Is a zone cut authority type XXXMLG */ -#define DNS_RDATATYPEATTR_ZONECUTAUTH 0x00000010U +/* Is a zone cut authority type */ +#define DNS_RDATATYPEATTR_ZONECUTAUTH 0x00000010U /* Is reserved (unusable) */ #define DNS_RDATATYPEATTR_RESERVED 0x00000020U /* Is an unknown type */ #define DNS_RDATATYPEATTR_UNKNOWN 0x00000040U +/* Is META, and can only be in a question section */ +#define DNS_RDATATYPEATTR_QUESTIONONLY 0x00000080U +/* is META, and can NOT be in a question section */ +#define DNS_RDATATYPEATTR_NOTQUESTION 0x00000100U dns_rdatatype_t dns_rdata_covers(dns_rdata_t *rdata); diff --git a/lib/dns/message.c b/lib/dns/message.c index 0a2c952749..ed8a72a994 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -890,6 +890,15 @@ getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx) result = DNS_R_FORMERR; goto cleanup; } + + /* + * If this is a type that cannot occur in a question section, + * return failure. + */ + if (dns_rdatatype_notquestion(rdtype)) { + result = DNS_R_FORMERR; + goto cleanup; + } /* * Can't ask the same question twice. @@ -1186,6 +1195,15 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, skip_type_search) result = ISC_R_NOTFOUND; else { + /* + * If this is a type that can only occur in + * the question section, fail. + */ + if (dns_rdatatype_questiononly(rdtype)) { + result = DNS_R_FORMERR; + goto cleanup; + } + rdataset = NULL; result = dns_message_findtype(name, rdtype, covers, &rdataset); diff --git a/lib/dns/rdata.c b/lib/dns/rdata.c index 66bd3309da..ddc3cd4995 100644 --- a/lib/dns/rdata.c +++ b/lib/dns/rdata.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: rdata.c,v 1.76 2000/04/14 18:36:00 explorer Exp $ */ +/* $Id: rdata.c,v 1.77 2000/04/14 20:13:45 explorer Exp $ */ #include @@ -1553,25 +1553,13 @@ dns_rdata_covers(dns_rdata_t *rdata) return (covers_sig(rdata)); } -static isc_boolean_t -ismeta(unsigned int code, struct tbl *table) -{ - struct tbl *t; - REQUIRE(code < 65536); - for (t = table; t->name != NULL; t++) { - if (code == t->value) - return ((t->flags & META) ? ISC_TRUE : ISC_FALSE); - } - return (ISC_FALSE); /* Unknown, assume non-meta. */ -} - isc_boolean_t dns_rdatatype_ismeta(dns_rdatatype_t type) { if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_META) != 0) return (ISC_TRUE); return (ISC_FALSE); -} +} isc_boolean_t dns_rdatatype_issingleton(dns_rdatatype_t type) @@ -1580,12 +1568,39 @@ dns_rdatatype_issingleton(dns_rdatatype_t type) != 0) return (ISC_TRUE); return (ISC_FALSE); -} +} + +isc_boolean_t +dns_rdatatype_notquestion(dns_rdatatype_t type) +{ + if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_NOTQUESTION) + != 0) + return (ISC_TRUE); + return (ISC_FALSE); +} + +isc_boolean_t +dns_rdatatype_questiononly(dns_rdatatype_t type) +{ + if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_QUESTIONONLY) + != 0) + return (ISC_TRUE); + return (ISC_FALSE); +} isc_boolean_t dns_rdataclass_ismeta(dns_rdataclass_t rdclass) { - return (ismeta(rdclass, classes)); + struct tbl *t; + + REQUIRE(rdclass < 65536); + + for (t = classes; t->name != NULL; t++) { + if (rdclass == t->value) + return ((t->flags & META) ? ISC_TRUE : ISC_FALSE); + } + + return (ISC_FALSE); /* assume it is not a meta class */ } isc_boolean_t diff --git a/lib/dns/rdata/any_255/tsig_250.c b/lib/dns/rdata/any_255/tsig_250.c index a91ee55a90..22e399e61e 100644 --- a/lib/dns/rdata/any_255/tsig_250.c +++ b/lib/dns/rdata/any_255/tsig_250.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: tsig_250.c,v 1.27 2000/04/07 03:54:06 explorer Exp $ */ +/* $Id: tsig_250.c,v 1.28 2000/04/14 20:13:48 explorer Exp $ */ /* Reviewed: Thu Mar 16 13:39:43 PST 2000 by gson */ @@ -26,7 +26,7 @@ #include -#define RRTYPE_TSIG_ATTRIBUTES (DNS_RDATATYPEATTR_META) +#define RRTYPE_TSIG_ATTRIBUTES (DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_NOTQUESTION) static inline isc_result_t fromtext_any_tsig(dns_rdataclass_t rdclass, dns_rdatatype_t type, diff --git a/lib/dns/rdata/generic/opt_41.c b/lib/dns/rdata/generic/opt_41.c index d0f7cfb9ef..daca822b82 100644 --- a/lib/dns/rdata/generic/opt_41.c +++ b/lib/dns/rdata/generic/opt_41.c @@ -15,7 +15,7 @@ * SOFTWARE. */ -/* $Id: opt_41.c,v 1.7 2000/04/07 03:54:28 explorer Exp $ */ +/* $Id: opt_41.c,v 1.8 2000/04/14 20:13:49 explorer Exp $ */ /* Reviewed: Thu Mar 16 14:06:44 PST 2000 by gson */ @@ -24,7 +24,7 @@ #ifndef RDATA_GENERIC_OPT_41_C #define RDATA_GENERIC_OPT_41_C -#define RRTYPE_OPT_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON) +#define RRTYPE_OPT_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON | DNS_RDATATYPEATTR_META | DNS_RDATATYPEATTR_NOTQUESTION) static inline isc_result_t fromtext_opt(dns_rdataclass_t rdclass, dns_rdatatype_t type,