1 /* $NetBSD: result.c,v 1.6 2014/12/10 04:37:58 christos Exp $ */
2
3 /*
4 * Copyright (C) 2004, 2005, 2007-2013 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2003 Internet Software Consortium.
6 *
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.
10 *
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.
18 */
19
20 /* Id */
21
22 /*! \file */
23
24 #include <config.h>
25
26 #include <isc/once.h>
27 #include <isc/util.h>
28
29 #include <dns/result.h>
30 #include <dns/lib.h>
31
32 static const char *text[DNS_R_NRESULTS] = {
33 "label too long", /*%< 0 DNS_R_LABELTOOLONG */
34 "bad escape", /*%< 1 DNS_R_BADESCAPE */
35 /*!
36 * Note that DNS_R_BADBITSTRING and DNS_R_BITSTRINGTOOLONG are
37 * deprecated.
38 */
39 "bad bitstring", /*%< 2 DNS_R_BADBITSTRING */
40 "bitstring too long", /*%< 3 DNS_R_BITSTRINGTOOLONG */
41 "empty label", /*%< 4 DNS_R_EMPTYLABEL */
42
43 "bad dotted quad", /*%< 5 DNS_R_BADDOTTEDQUAD */
44 "invalid NS owner name (wildcard)", /*%< 6 DNS_R_INVALIDNS */
45 "unknown class/type", /*%< 7 DNS_R_UNKNOWN */
46 "bad label type", /*%< 8 DNS_R_BADLABELTYPE */
47 "bad compression pointer", /*%< 9 DNS_R_BADPOINTER */
48
49 "too many hops", /*%< 10 DNS_R_TOOMANYHOPS */
50 "disallowed (by application policy)", /*%< 11 DNS_R_DISALLOWED */
51 "extra input text", /*%< 12 DNS_R_EXTRATOKEN */
52 "extra input data", /*%< 13 DNS_R_EXTRADATA */
53 "text too long", /*%< 14 DNS_R_TEXTTOOLONG */
54
55 "not at top of zone", /*%< 15 DNS_R_NOTZONETOP */
56 "syntax error", /*%< 16 DNS_R_SYNTAX */
57 "bad checksum", /*%< 17 DNS_R_BADCKSUM */
58 "bad IPv6 address", /*%< 18 DNS_R_BADAAAA */
59 "no owner", /*%< 19 DNS_R_NOOWNER */
60
61 "no ttl", /*%< 20 DNS_R_NOTTL */
62 "bad class", /*%< 21 DNS_R_BADCLASS */
63 "name too long", /*%< 22 DNS_R_NAMETOOLONG */
64 "partial match", /*%< 23 DNS_R_PARTIALMATCH */
65 "new origin", /*%< 24 DNS_R_NEWORIGIN */
66
67 "unchanged", /*%< 25 DNS_R_UNCHANGED */
68 "bad ttl", /*%< 26 DNS_R_BADTTL */
69 "more data needed/to be rendered", /*%< 27 DNS_R_NOREDATA */
70 "continue", /*%< 28 DNS_R_CONTINUE */
71 "delegation", /*%< 29 DNS_R_DELEGATION */
72
73 "glue", /*%< 30 DNS_R_GLUE */
74 "dname", /*%< 31 DNS_R_DNAME */
75 "cname", /*%< 32 DNS_R_CNAME */
76 "bad database", /*%< 33 DNS_R_BADDB */
77 "zonecut", /*%< 34 DNS_R_ZONECUT */
78
79 "bad zone", /*%< 35 DNS_R_BADZONE */
80 "more data", /*%< 36 DNS_R_MOREDATA */
81 "up to date", /*%< 37 DNS_R_UPTODATE */
82 "tsig verify failure", /*%< 38 DNS_R_TSIGVERIFYFAILURE */
83 "tsig indicates error", /*%< 39 DNS_R_TSIGERRORSET */
84
85 "RRSIG failed to verify", /*%< 40 DNS_R_SIGINVALID */
86 "RRSIG has expired", /*%< 41 DNS_R_SIGEXPIRED */
87 "RRSIG validity period has not begun", /*%< 42 DNS_R_SIGFUTURE */
88 "key is unauthorized to sign data", /*%< 43 DNS_R_KEYUNAUTHORIZED */
89 "invalid time", /*%< 44 DNS_R_INVALIDTIME */
90
91 "expected a TSIG or SIG(0)", /*%< 45 DNS_R_EXPECTEDTSIG */
92 "did not expect a TSIG or SIG(0)", /*%< 46 DNS_R_UNEXPECTEDTSIG */
93 "TKEY is unacceptable", /*%< 47 DNS_R_INVALIDTKEY */
94 "hint", /*%< 48 DNS_R_HINT */
95 "drop", /*%< 49 DNS_R_DROP */
96
97 "zone not loaded", /*%< 50 DNS_R_NOTLOADED */
98 "ncache nxdomain", /*%< 51 DNS_R_NCACHENXDOMAIN */
99 "ncache nxrrset", /*%< 52 DNS_R_NCACHENXRRSET */
100 "wait", /*%< 53 DNS_R_WAIT */
101 "not verified yet", /*%< 54 DNS_R_NOTVERIFIEDYET */
102
103 "no identity", /*%< 55 DNS_R_NOIDENTITY */
104 "no journal", /*%< 56 DNS_R_NOJOURNAL */
105 "alias", /*%< 57 DNS_R_ALIAS */
106 "use TCP", /*%< 58 DNS_R_USETCP */
107 "no valid RRSIG", /*%< 59 DNS_R_NOVALIDSIG */
108
109 "no valid NSEC", /*%< 60 DNS_R_NOVALIDNSEC */
110 "insecurity proof failed", /*%< 61 DNS_R_NOTINSECURE */
111 "unknown service", /*%< 62 DNS_R_UNKNOWNSERVICE */
112 "recoverable error occurred", /*%< 63 DNS_R_RECOVERABLE */
113 "unknown opt attribute record", /*%< 64 DNS_R_UNKNOWNOPT */
114
115 "unexpected message id", /*%< 65 DNS_R_UNEXPECTEDID */
116 "seen include file", /*%< 66 DNS_R_SEENINCLUDE */
117 "not exact", /*%< 67 DNS_R_NOTEXACT */
118 "address blackholed", /*%< 68 DNS_R_BLACKHOLED */
119 "bad algorithm", /*%< 69 DNS_R_BADALG */
120
121 "invalid use of a meta type", /*%< 70 DNS_R_METATYPE */
122 "CNAME and other data", /*%< 71 DNS_R_CNAMEANDOTHER */
123 "multiple RRs of singleton type", /*%< 72 DNS_R_SINGLETON */
124 "hint nxrrset", /*%< 73 DNS_R_HINTNXRRSET */
125 "no master file configured", /*%< 74 DNS_R_NOMASTERFILE */
126
127 "unknown protocol", /*%< 75 DNS_R_UNKNOWNPROTO */
128 "clocks are unsynchronized", /*%< 76 DNS_R_CLOCKSKEW */
129 "IXFR failed", /*%< 77 DNS_R_BADIXFR */
130 "not authoritative", /*%< 78 DNS_R_NOTAUTHORITATIVE */
131 "no valid KEY", /*%< 79 DNS_R_NOVALIDKEY */
132
133 "obsolete", /*%< 80 DNS_R_OBSOLETE */
134 "already frozen", /*%< 81 DNS_R_FROZEN */
135 "unknown flag", /*%< 82 DNS_R_UNKNOWNFLAG */
136 "expected a response", /*%< 83 DNS_R_EXPECTEDRESPONSE */
137 "no valid DS", /*%< 84 DNS_R_NOVALIDDS */
138
139 "NS is an address", /*%< 85 DNS_R_NSISADDRESS */
140 "received FORMERR", /*%< 86 DNS_R_REMOTEFORMERR */
141 "truncated TCP response", /*%< 87 DNS_R_TRUNCATEDTCP */
142 "lame server detected", /*%< 88 DNS_R_LAME */
143 "unexpected RCODE", /*%< 89 DNS_R_UNEXPECTEDRCODE */
144
145 "unexpected OPCODE", /*%< 90 DNS_R_UNEXPECTEDOPCODE */
146 "chase DS servers", /*%< 91 DNS_R_CHASEDSSERVERS */
147 "empty name", /*%< 92 DNS_R_EMPTYNAME */
148 "empty wild", /*%< 93 DNS_R_EMPTYWILD */
149 "bad bitmap", /*%< 94 DNS_R_BADBITMAP */
150
151 "from wildcard", /*%< 95 DNS_R_FROMWILDCARD */
152 "bad owner name (check-names)", /*%< 96 DNS_R_BADOWNERNAME */
153 "bad name (check-names)", /*%< 97 DNS_R_BADNAME */
154 "dynamic zone", /*%< 98 DNS_R_DYNAMIC */
155 "unknown command", /*%< 99 DNS_R_UNKNOWNCOMMAND */
156
157 "must-be-secure", /*%< 100 DNS_R_MUSTBESECURE */
158 "covering NSEC record returned", /*%< 101 DNS_R_COVERINGNSEC */
159 "MX is an address", /*%< 102 DNS_R_MXISADDRESS */
160 "duplicate query", /*%< 103 DNS_R_DUPLICATE */
161 "invalid NSEC3 owner name (wildcard)", /*%< 104 DNS_R_INVALIDNSEC3 */
162
163 "not master", /*%< 105 DNS_R_NOTMASTER */
164 "broken trust chain", /*%< 106 DNS_R_BROKENCHAIN */
165 "expired", /*%< 107 DNS_R_EXPIRED */
166 "not dynamic", /*%< 108 DNS_R_NOTDYNAMIC */
167 "bad EUI" /*%< 109 DNS_R_BADEUI */
168 };
169
170 static const char *rcode_text[DNS_R_NRCODERESULTS] = {
171 "NOERROR", /*%< 0 DNS_R_NOEROR */
172 "FORMERR", /*%< 1 DNS_R_FORMERR */
173 "SERVFAIL", /*%< 2 DNS_R_SERVFAIL */
174 "NXDOMAIN", /*%< 3 DNS_R_NXDOMAIN */
175 "NOTIMP", /*%< 4 DNS_R_NOTIMP */
176
177 "REFUSED", /*%< 5 DNS_R_REFUSED */
178 "YXDOMAIN", /*%< 6 DNS_R_YXDOMAIN */
179 "YXRRSET", /*%< 7 DNS_R_YXRRSET */
180 "NXRRSET", /*%< 8 DNS_R_NXRRSET */
181 "NOTAUTH", /*%< 9 DNS_R_NOTAUTH */
182
183 "NOTZONE", /*%< 10 DNS_R_NOTZONE */
184 "<rcode 11>", /*%< 11 has no macro */
185 "<rcode 12>", /*%< 12 has no macro */
186 "<rcode 13>", /*%< 13 has no macro */
187 "<rcode 14>", /*%< 14 has no macro */
188
189 "<rcode 15>", /*%< 15 has no macro */
190 "BADVERS", /*%< 16 DNS_R_BADVERS */
191 };
192
193 #define DNS_RESULT_RESULTSET 2
194 #define DNS_RESULT_RCODERESULTSET 3
195
196 static isc_once_t once = ISC_ONCE_INIT;
197
198 static void
initialize_action(void)199 initialize_action(void) {
200 isc_result_t result;
201
202 result = isc_result_register(ISC_RESULTCLASS_DNS, DNS_R_NRESULTS,
203 text, dns_msgcat, DNS_RESULT_RESULTSET);
204 if (result == ISC_R_SUCCESS)
205 result = isc_result_register(ISC_RESULTCLASS_DNSRCODE,
206 DNS_R_NRCODERESULTS,
207 rcode_text, dns_msgcat,
208 DNS_RESULT_RCODERESULTSET);
209 if (result != ISC_R_SUCCESS)
210 UNEXPECTED_ERROR(__FILE__, __LINE__,
211 "isc_result_register() failed: %u", result);
212 }
213
214 static void
initialize(void)215 initialize(void) {
216 dns_lib_initmsgcat();
217 RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
218 }
219
220 const char *
dns_result_totext(isc_result_t result)221 dns_result_totext(isc_result_t result) {
222 initialize();
223
224 return (isc_result_totext(result));
225 }
226
227 void
dns_result_register(void)228 dns_result_register(void) {
229 initialize();
230 }
231
232 dns_rcode_t
dns_result_torcode(isc_result_t result)233 dns_result_torcode(isc_result_t result) {
234 dns_rcode_t rcode = dns_rcode_servfail;
235
236 if (DNS_RESULT_ISRCODE(result)) {
237 /*
238 * Rcodes can't be bigger than 12 bits, which is why we
239 * AND with 0xFFF instead of 0xFFFF.
240 */
241 return ((dns_rcode_t)((result) & 0xFFF));
242 }
243 /*
244 * Try to supply an appropriate rcode.
245 */
246 switch (result) {
247 case ISC_R_SUCCESS:
248 rcode = dns_rcode_noerror;
249 break;
250 case ISC_R_BADBASE64:
251 case ISC_R_NOSPACE:
252 case ISC_R_RANGE:
253 case ISC_R_UNEXPECTEDEND:
254 case DNS_R_BADAAAA:
255 /* case DNS_R_BADBITSTRING: deprecated */
256 case DNS_R_BADCKSUM:
257 case DNS_R_BADCLASS:
258 case DNS_R_BADLABELTYPE:
259 case DNS_R_BADPOINTER:
260 case DNS_R_BADTTL:
261 case DNS_R_BADZONE:
262 /* case DNS_R_BITSTRINGTOOLONG: deprecated */
263 case DNS_R_EXTRADATA:
264 case DNS_R_LABELTOOLONG:
265 case DNS_R_NOREDATA:
266 case DNS_R_SYNTAX:
267 case DNS_R_TEXTTOOLONG:
268 case DNS_R_TOOMANYHOPS:
269 case DNS_R_TSIGERRORSET:
270 case DNS_R_UNKNOWN:
271 case DNS_R_NAMETOOLONG:
272 rcode = dns_rcode_formerr;
273 break;
274 case DNS_R_DISALLOWED:
275 rcode = dns_rcode_refused;
276 break;
277 case DNS_R_TSIGVERIFYFAILURE:
278 case DNS_R_CLOCKSKEW:
279 rcode = dns_rcode_notauth;
280 break;
281 default:
282 rcode = dns_rcode_servfail;
283 }
284
285 return (rcode);
286 }
287