result.c revision 135446
145SN/A/*
2553SN/A * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
345SN/A * Copyright (C) 1998-2003  Internet Software Consortium.
445SN/A *
545SN/A * Permission to use, copy, modify, and distribute this software for any
645SN/A * purpose with or without fee is hereby granted, provided that the above
7553SN/A * copyright notice and this permission notice appear in all copies.
845SN/A *
9553SN/A * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
1045SN/A * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1145SN/A * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
1245SN/A * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1345SN/A * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
1445SN/A * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1545SN/A * PERFORMANCE OF THIS SOFTWARE.
1645SN/A */
1745SN/A
1845SN/A/* $Id: result.c,v 1.90.2.9.2.13 2004/05/14 05:06:39 marka Exp $ */
1945SN/A
2045SN/A#include <config.h>
21553SN/A
22553SN/A#include <isc/once.h>
23553SN/A#include <isc/util.h>
2445SN/A
2545SN/A#include <dns/result.h>
2645SN/A#include <dns/lib.h>
2745SN/A
2845SN/Astatic const char *text[DNS_R_NRESULTS] = {
2945SN/A	"label too long",		       /*  0 DNS_R_LABELTOOLONG	     */
3045SN/A	"bad escape",			       /*  1 DNS_R_BADESCAPE	     */
31971SN/A	/*
3245SN/A	 * Note that DNS_R_BADBITSTRING and DNS_R_BITSTRINGTOOLONG are
33580SN/A	 * deprecated.
34580SN/A	 */
3545SN/A	"bad bitstring",		       /*  2 DNS_R_BADBITSTRING	     */
3645SN/A	"bitstring too long",		       /*  3 DNS_R_BITSTRINGTOOLONG  */
3745SN/A	"empty label",			       /*  4 DNS_R_EMPTYLABEL	     */
3845SN/A
3945SN/A	"bad dotted quad",		       /*  5 DNS_R_BADDOTTEDQUAD     */
4045SN/A	"invalid NS owner name (wildcard)",    /*  6 DNS_R_INVALIDNS	     */
4145SN/A	"unknown class/type",		       /*  7 DNS_R_UNKNOWN	     */
4245SN/A	"bad label type",		       /*  8 DNS_R_BADLABELTYPE	     */
4345SN/A	"bad compression pointer",	       /*  9 DNS_R_BADPOINTER	     */
4445SN/A
4545SN/A	"too many hops",		       /* 10 DNS_R_TOOMANYHOPS	     */
4645SN/A	"disallowed (by application policy)",  /* 11 DNS_R_DISALLOWED	     */
4745SN/A	"extra input text",		       /* 12 DNS_R_EXTRATOKEN	     */
4845SN/A	"extra input data",		       /* 13 DNS_R_EXTRADATA	     */
4945SN/A	"text too long",		       /* 14 DNS_R_TEXTTOOLONG	     */
5045SN/A
5145SN/A	"not at top of zone",		       /* 15 DNS_R_NOTZONETOP	     */
5245SN/A	"syntax error",			       /* 16 DNS_R_SYNTAX	     */
5345SN/A	"bad checksum",			       /* 17 DNS_R_BADCKSUM	     */
5445SN/A	"bad IPv6 address",		       /* 18 DNS_R_BADAAAA	     */
5545SN/A	"no owner",			       /* 19 DNS_R_NOOWNER	     */
5645SN/A
5745SN/A	"no ttl",			       /* 20 DNS_R_NOTTL	     */
5845SN/A	"bad class",			       /* 21 DNS_R_BADCLASS	     */
5945SN/A	"name too long",		       /* 22 DNS_R_NAMETOOLONG	     */
60	"partial match",		       /* 23 DNS_R_PARTIALMATCH	     */
61	"new origin",			       /* 24 DNS_R_NEWORIGIN	     */
62
63	"unchanged",			       /* 25 DNS_R_UNCHANGED	     */
64	"bad ttl",			       /* 26 DNS_R_BADTTL	     */
65	"more data needed/to be rendered",     /* 27 DNS_R_NOREDATA	     */
66	"continue",			       /* 28 DNS_R_CONTINUE	     */
67	"delegation",			       /* 29 DNS_R_DELEGATION	     */
68
69	"glue",				       /* 30 DNS_R_GLUE		     */
70	"dname",			       /* 31 DNS_R_DNAME	     */
71	"cname",			       /* 32 DNS_R_CNAME	     */
72	"bad database",			       /* 33 DNS_R_BADDB	     */
73	"zonecut",			       /* 34 DNS_R_ZONECUT	     */
74
75	"bad zone",			       /* 35 DNS_R_BADZONE	     */
76	"more data",			       /* 36 DNS_R_MOREDATA	     */
77	"up to date",			       /* 37 DNS_R_UPTODATE	     */
78	"tsig verify failure",		       /* 38 DNS_R_TSIGVERIFYFAILURE */
79	"tsig indicates error",		       /* 39 DNS_R_TSIGERRORSET	     */
80
81	"RRSIG failed to verify",	       /* 40 DNS_R_SIGINVALID	     */
82	"RRSIG has expired",		       /* 41 DNS_R_SIGEXPIRED	     */
83	"RRSIG validity period has not begun", /* 42 DNS_R_SIGFUTURE	     */
84	"key is unauthorized to sign data",    /* 43 DNS_R_KEYUNAUTHORIZED   */
85	"invalid time",			       /* 44 DNS_R_INVALIDTIME	     */
86
87	"expected a TSIG or SIG(0)",	       /* 45 DNS_R_EXPECTEDTSIG	     */
88	"did not expect a TSIG or SIG(0)",     /* 46 DNS_R_UNEXPECTEDTSIG    */
89	"TKEY is unacceptable",		       /* 47 DNS_R_INVALIDTKEY	     */
90	"hint",				       /* 48 DNS_R_HINT		     */
91	"drop",				       /* 49 DNS_R_DROP		     */
92
93	"zone not loaded",		       /* 50 DNS_R_NOTLOADED	     */
94	"ncache nxdomain",		       /* 51 DNS_R_NCACHENXDOMAIN    */
95	"ncache nxrrset",		       /* 52 DNS_R_NCACHENXRRSET     */
96	"wait",				       /* 53 DNS_R_WAIT		     */
97	"not verified yet",		       /* 54 DNS_R_NOTVERIFIEDYET    */
98
99	"no identity",			       /* 55 DNS_R_NOIDENTITY	     */
100	"no journal",			       /* 56 DNS_R_NOJOURNAL	     */
101	"alias",			       /* 57 DNS_R_ALIAS	     */
102	"use TCP",			       /* 58 DNS_R_USETCP	     */
103	"no valid RRSIG",		       /* 59 DNS_R_NOVALIDSIG	     */
104
105	"no valid NSEC",		       /* 60 DNS_R_NOVALIDNSEC	     */
106	"not insecure",			       /* 61 DNS_R_NOTINSECURE	     */
107	"unknown service",		       /* 62 DNS_R_UNKNOWNSERVICE    */
108	"recoverable error occurred",	       /* 63 DNS_R_RECOVERABLE       */
109	"unknown opt attribute record",	       /* 64 DNS_R_UNKNOWNOPT	     */
110
111	"unexpected message id",	       /* 65 DNS_R_UNEXPECTEDID      */
112	"seen include file",		       /* 66 DNS_R_SEENINCLUDE       */
113	"not exact",		       	       /* 67 DNS_R_NOTEXACT	     */
114	"address blackholed",	       	       /* 68 DNS_R_BLACKHOLED	     */
115	"bad algorithm",		       /* 69 DNS_R_BADALG	     */
116
117	"invalid use of a meta type",	       /* 70 DNS_R_METATYPE	     */
118	"CNAME and other data",		       /* 71 DNS_R_CNAMEANDOTHER     */
119	"multiple RRs of singleton type",      /* 72 DNS_R_SINGLETON	     */
120	"hint nxrrset",			       /* 73 DNS_R_HINTNXRRSET	     */
121	"no master file configured",	       /* 74 DNS_R_NOMASTERFILE	     */
122
123	"unknown protocol",		       /* 75 DNS_R_UNKNOWNPROTO	     */
124	"clocks are unsynchronized",	       /* 76 DNS_R_CLOCKSKEW	     */
125	"IXFR failed",			       /* 77 DNS_R_BADIXFR	     */
126	"not authoritative",		       /* 78 DNS_R_NOTAUTHORITATIVE  */
127	"no valid KEY",		       	       /* 79 DNS_R_NOVALIDKEY	     */
128
129	"obsolete",			       /* 80 DNS_R_OBSOLETE	     */
130	"already frozen",		       /* 81 DNS_R_FROZEN	     */
131	"unknown flag",			       /* 82 DNS_R_UNKNOWNFLAG	     */
132	"expected a response",		       /* 83 DNS_R_EXPECTEDRESPONSE  */
133	"no valid DS",			       /* 84 DNS_R_NOVALIDDS	     */
134
135	"NS is an address",		       /* 85 DNS_R_NSISADDRESS	     */
136	"received FORMERR",		       /* 86 DNS_R_REMOTEFORMERR     */
137	"truncated TCP response",	       /* 87 DNS_R_TRUNCATEDTCP	     */
138	"lame server detected",		       /* 88 DNS_R_LAME		     */
139	"unexpected RCODE",		       /* 89 DNS_R_UNEXPECTEDRCODE   */
140
141	"unexpected OPCODE",		       /* 90 DNS_R_UNEXPECTEDOPCODE  */
142	"chase DS servers",		       /* 91 DNS_R_CHASEDSSERVERS    */
143	"empty name",			       /* 92 DNS_R_EMPTYNAME	     */
144	"empty wild",			       /* 93 DNS_R_EMPTYWILD	     */
145	"bad bitmap",			       /* 94 DNS_R_BADBITMAP	     */
146
147	"from wildcard",		       /* 95 DNS_R_FROMWILDCARD	     */
148	"bad owner name (check-names)",	       /* 96 DNS_R_BADOWNERNAME	     */
149	"bad name (check-names)",	       /* 97 DNS_R_BADNAME	     */
150	"dynamic zone",			       /* 98 DNS_R_DYNAMIC	     */
151	"unknown command",		       /* 99 DNS_R_UNKNOWNCOMMAND    */
152
153	"must-be-secure",		       /* 100 DNS_R_MUSTBESECURE     */
154	"covering NSEC record returned"	       /* 101 DNS_R_COVERINGNSEC     */
155};
156
157static const char *rcode_text[DNS_R_NRCODERESULTS] = {
158	"NOERROR",				/*  0 DNS_R_NOEROR	     */
159	"FORMERR",				/*  1 DNS_R_FORMERR	     */
160	"SERVFAIL",				/*  2 DNS_R_SERVFAIL	     */
161	"NXDOMAIN",				/*  3 DNS_R_NXDOMAIN	     */
162	"NOTIMP",				/*  4 DNS_R_NOTIMP	     */
163
164	"REFUSED",				/*  5 DNS_R_REFUSED	     */
165	"YXDOMAIN",				/*  6 DNS_R_YXDOMAIN	     */
166	"YXRRSET",				/*  7 DNS_R_YXRRSET	     */
167	"NXRRSET",				/*  8 DNS_R_NXRRSET	     */
168	"NOTAUTH",				/*  9 DNS_R_NOTAUTH	     */
169
170	"NOTZONE",				/* 10 DNS_R_NOTZONE 	     */
171	"<rcode 11>",				/* 11 has no macro	     */
172	"<rcode 12>",				/* 12 has no macro	     */
173	"<rcode 13>",				/* 13 has no macro	     */
174	"<rcode 14>",				/* 14 has no macro	     */
175
176	"<rcode 15>",				/* 15 has no macro	     */
177	"BADVERS",				/* 16 DNS_R_BADVERS	     */
178};
179
180#define DNS_RESULT_RESULTSET			2
181#define DNS_RESULT_RCODERESULTSET		3
182
183static isc_once_t		once = ISC_ONCE_INIT;
184
185static void
186initialize_action(void) {
187	isc_result_t result;
188
189	result = isc_result_register(ISC_RESULTCLASS_DNS, DNS_R_NRESULTS,
190				     text, dns_msgcat, DNS_RESULT_RESULTSET);
191	if (result == ISC_R_SUCCESS)
192		result = isc_result_register(ISC_RESULTCLASS_DNSRCODE,
193					     DNS_R_NRCODERESULTS,
194					     rcode_text, dns_msgcat,
195					     DNS_RESULT_RCODERESULTSET);
196	if (result != ISC_R_SUCCESS)
197		UNEXPECTED_ERROR(__FILE__, __LINE__,
198				 "isc_result_register() failed: %u", result);
199}
200
201static void
202initialize(void) {
203	dns_lib_initmsgcat();
204	RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
205}
206
207const char *
208dns_result_totext(isc_result_t result) {
209	initialize();
210
211	return (isc_result_totext(result));
212}
213
214void
215dns_result_register(void) {
216	initialize();
217}
218
219dns_rcode_t
220dns_result_torcode(isc_result_t result) {
221	dns_rcode_t rcode = dns_rcode_servfail;
222
223	if (DNS_RESULT_ISRCODE(result)) {
224		/*
225		 * Rcodes can't be bigger than 12 bits, which is why we
226		 * AND with 0xFFF instead of 0xFFFF.
227		 */
228		return ((dns_rcode_t)((result) & 0xFFF));
229	}
230	/*
231	 * Try to supply an appropriate rcode.
232	 */
233	switch (result) {
234	case ISC_R_SUCCESS:
235		rcode = dns_rcode_noerror;
236		break;
237	case ISC_R_BADBASE64:
238	case ISC_R_NOSPACE:
239	case ISC_R_RANGE:
240	case ISC_R_UNEXPECTEDEND:
241	case DNS_R_BADAAAA:
242	/* case DNS_R_BADBITSTRING: deprecated */
243	case DNS_R_BADCKSUM:
244	case DNS_R_BADCLASS:
245	case DNS_R_BADLABELTYPE:
246	case DNS_R_BADPOINTER:
247	case DNS_R_BADTTL:
248	case DNS_R_BADZONE:
249	/* case DNS_R_BITSTRINGTOOLONG: deprecated */
250	case DNS_R_EXTRADATA:
251	case DNS_R_LABELTOOLONG:
252	case DNS_R_NOREDATA:
253	case DNS_R_SYNTAX:
254	case DNS_R_TEXTTOOLONG:
255	case DNS_R_TOOMANYHOPS:
256	case DNS_R_TSIGERRORSET:
257	case DNS_R_UNKNOWN:
258		rcode = dns_rcode_formerr;
259		break;
260	case DNS_R_DISALLOWED:
261		rcode = dns_rcode_refused;
262		break;
263	case DNS_R_TSIGVERIFYFAILURE:
264	case DNS_R_CLOCKSKEW:
265		rcode = dns_rcode_notauth;
266		break;
267	default:
268		rcode = dns_rcode_servfail;
269	}
270
271	return (rcode);
272}
273