1238104Sdes/*
2238104Sdes * a error2str function to make sense of all the
3238104Sdes * error codes we have laying ardoun
4238104Sdes *
5238104Sdes * a Net::DNS like library for C
6238104Sdes * LibDNS Team @ NLnet Labs
7238104Sdes * (c) NLnet Labs, 2005-2006
8238104Sdes * See the file LICENSE for the license
9238104Sdes */
10238104Sdes
11238104Sdes#include <ldns/config.h>
12238104Sdes
13238104Sdes#include <ldns/ldns.h>
14238104Sdes
15238104Sdesldns_lookup_table ldns_error_str[] = {
16238104Sdes	{ LDNS_STATUS_OK, "All OK" },
17238104Sdes	{ LDNS_STATUS_EMPTY_LABEL, "Empty label" },
18238104Sdes        { LDNS_STATUS_LABEL_OVERFLOW, "Label length overflow" },
19238104Sdes        { LDNS_STATUS_DOMAINNAME_OVERFLOW, "Domainname length overflow" },
20238104Sdes        { LDNS_STATUS_DOMAINNAME_UNDERFLOW, "Domainname length underflow (zero length)" },
21238104Sdes        { LDNS_STATUS_DDD_OVERFLOW, "\\DDD sequence overflow (>255)" },
22238104Sdes        { LDNS_STATUS_PACKET_OVERFLOW, "Packet size overflow" },
23238104Sdes        { LDNS_STATUS_INVALID_POINTER, "Invalid compression pointer" },
24238104Sdes        { LDNS_STATUS_MEM_ERR, "General memory error" },
25238104Sdes        { LDNS_STATUS_INTERNAL_ERR, "Internal error, this should not happen" },
26238104Sdes        { LDNS_STATUS_SSL_ERR, "Error in SSL library" },
27238104Sdes        { LDNS_STATUS_ERR, "General LDNS error" },
28238104Sdes        { LDNS_STATUS_INVALID_INT, "Conversion error, integer expected" },
29238104Sdes        { LDNS_STATUS_INVALID_IP4, "Conversion error, ip4 addr expected" },
30238104Sdes        { LDNS_STATUS_INVALID_IP6, "Conversion error, ip6 addr expected" },
31238104Sdes        { LDNS_STATUS_INVALID_STR, "Conversion error, string expected" },
32238104Sdes	{ LDNS_STATUS_INVALID_B32_EXT, "Conversion error, b32 ext encoding expected" },
33238104Sdes        { LDNS_STATUS_INVALID_B64, "Conversion error, b64 encoding expected" },
34238104Sdes        { LDNS_STATUS_INVALID_HEX, "Conversion error, hex encoding expected" },
35238104Sdes        { LDNS_STATUS_INVALID_TIME, "Conversion error, time encoding expected" },
36238104Sdes        { LDNS_STATUS_NETWORK_ERR, "Could not send or receive, because of network error" },
37238104Sdes        { LDNS_STATUS_ADDRESS_ERR, "Could not start AXFR, because of address error" },
38238104Sdes        { LDNS_STATUS_FILE_ERR, "Could not open the files" },
39238104Sdes        { LDNS_STATUS_UNKNOWN_INET, "Uknown address family" },
40238104Sdes        { LDNS_STATUS_NOT_IMPL, "This function is not implemented (yet), please notify the developers - or not..." },
41238104Sdes	{ LDNS_STATUS_NULL, "Supplied value pointer null" },
42238104Sdes        { LDNS_STATUS_CRYPTO_UNKNOWN_ALGO, "Unknown cryptographic algorithm" },
43238104Sdes        { LDNS_STATUS_CRYPTO_ALGO_NOT_IMPL, "Cryptographic algorithm not implemented" },
44238104Sdes        { LDNS_STATUS_CRYPTO_NO_RRSIG, "No DNSSEC signature(s)" },
45238104Sdes        { LDNS_STATUS_CRYPTO_NO_DNSKEY, "No DNSSEC public key(s)" },
46238104Sdes        { LDNS_STATUS_CRYPTO_TYPE_COVERED_ERR, "The signature does not cover this RRset" },
47238104Sdes        { LDNS_STATUS_CRYPTO_NO_TRUSTED_DNSKEY, "No signatures found for trusted DNSSEC public key(s)" },
48238104Sdes        { LDNS_STATUS_CRYPTO_NO_DS, "No DS record(s)" },
49238104Sdes        { LDNS_STATUS_CRYPTO_NO_TRUSTED_DS, "Could not validate DS record(s)" },
50238104Sdes        { LDNS_STATUS_CRYPTO_NO_MATCHING_KEYTAG_DNSKEY, "No keys with the keytag and algorithm from the RRSIG found" },
51238104Sdes        { LDNS_STATUS_CRYPTO_VALIDATED, "Valid DNSSEC signature" },
52238104Sdes        { LDNS_STATUS_CRYPTO_BOGUS, "Bogus DNSSEC signature" },
53238104Sdes        { LDNS_STATUS_CRYPTO_SIG_EXPIRED, "DNSSEC signature has expired" },
54238104Sdes        { LDNS_STATUS_CRYPTO_SIG_NOT_INCEPTED, "DNSSEC signature not incepted yet" },
55238104Sdes	{ LDNS_STATUS_CRYPTO_TSIG_BOGUS, "Bogus TSIG signature" },
56238104Sdes	{ LDNS_STATUS_CRYPTO_TSIG_ERR, "Could not create TSIG signature" },
57238104Sdes        { LDNS_STATUS_CRYPTO_EXPIRATION_BEFORE_INCEPTION, "DNSSEC signature has expiration date earlier than inception date" },
58238104Sdes	{ LDNS_STATUS_ENGINE_KEY_NOT_LOADED, "Unable to load private key from engine" },
59238104Sdes        { LDNS_STATUS_NSEC3_ERR, "Error in NSEC3 denial of existence proof" },
60238104Sdes	{ LDNS_STATUS_RES_NO_NS, "No (valid) nameservers defined in the resolver" },
61238104Sdes	{ LDNS_STATUS_RES_QUERY, "No correct query given to resolver" },
62238104Sdes	{ LDNS_STATUS_WIRE_INCOMPLETE_HEADER, "header section incomplete" },
63238104Sdes	{ LDNS_STATUS_WIRE_INCOMPLETE_QUESTION, "question section incomplete" },
64238104Sdes	{ LDNS_STATUS_WIRE_INCOMPLETE_ANSWER, "answer section incomplete" },
65238104Sdes	{ LDNS_STATUS_WIRE_INCOMPLETE_AUTHORITY, "authority section incomplete" },
66238104Sdes	{ LDNS_STATUS_WIRE_INCOMPLETE_ADDITIONAL, "additional section incomplete" },
67238104Sdes	{ LDNS_STATUS_NO_DATA, "No data" },
68269257Sdes	{ LDNS_STATUS_EXISTS_ERR, "Element already exists" },
69238104Sdes	{ LDNS_STATUS_CERT_BAD_ALGORITHM, "Bad algorithm type for CERT record" },
70238104Sdes	{ LDNS_STATUS_SYNTAX_TYPE_ERR, "Syntax error, could not parse the RR's type" },
71238104Sdes	{ LDNS_STATUS_SYNTAX_CLASS_ERR, "Syntax error, could not parse the RR's class" },
72238104Sdes	{ LDNS_STATUS_SYNTAX_TTL_ERR, "Syntax error, could not parse the RR's TTL" },
73238104Sdes	{ LDNS_STATUS_SYNTAX_INCLUDE_ERR_NOTIMPL, "Syntax error, $INCLUDE not implemented" },
74238104Sdes	{ LDNS_STATUS_SYNTAX_RDATA_ERR, "Syntax error, could not parse the RR's rdata" },
75238104Sdes	{ LDNS_STATUS_SYNTAX_DNAME_ERR, "Syntax error, could not parse the RR's dname(s)" },
76238104Sdes	{ LDNS_STATUS_SYNTAX_VERSION_ERR, "Syntax error, version mismatch" },
77238104Sdes	{ LDNS_STATUS_SYNTAX_ALG_ERR, "Syntax error, algorithm unknown or non parseable" },
78238104Sdes	{ LDNS_STATUS_SYNTAX_KEYWORD_ERR, "Syntax error, unknown keyword in input" },
79238104Sdes	{ LDNS_STATUS_SYNTAX_ERR, "Syntax error, could not parse the RR" },
80238104Sdes	{ LDNS_STATUS_SYNTAX_EMPTY, "Empty line was returned" },
81238104Sdes	{ LDNS_STATUS_SYNTAX_TTL, "$TTL directive was seen in the zone" },
82238104Sdes	{ LDNS_STATUS_SYNTAX_ORIGIN, "$ORIGIN directive was seen in the zone" },
83238104Sdes	{ LDNS_STATUS_SYNTAX_INCLUDE, "$INCLUDE directive was seen in the zone" },
84238104Sdes	{ LDNS_STATUS_SYNTAX_ITERATIONS_OVERFLOW, "Iterations count for NSEC3 record higher than maximum" },
85238104Sdes	{ LDNS_STATUS_SYNTAX_MISSING_VALUE_ERR, "Syntax error, value expected" },
86238104Sdes	{ LDNS_STATUS_SYNTAX_INTEGER_OVERFLOW, "Syntax error, integer value too large" },
87238104Sdes	{ LDNS_STATUS_SYNTAX_BAD_ESCAPE, "Syntax error, bad escape sequence" },
88238104Sdes	{ LDNS_STATUS_SOCKET_ERROR, "Error creating socket" },
89238104Sdes	{ LDNS_STATUS_DNSSEC_EXISTENCE_DENIED, "Existence denied by NSEC" },
90238104Sdes	{ LDNS_STATUS_DNSSEC_NSEC_RR_NOT_COVERED, "RR not covered by the given NSEC RRs" },
91238104Sdes	{ LDNS_STATUS_DNSSEC_NSEC_WILDCARD_NOT_COVERED, "wildcard not covered by the given NSEC RRs" },
92238104Sdes	{ LDNS_STATUS_DNSSEC_NSEC3_ORIGINAL_NOT_FOUND, "original of NSEC3 hashed name could not be found" },
93238104Sdes	{ LDNS_STATUS_MISSING_RDATA_FIELDS_RRSIG, "The RRSIG has to few rdata fields" },
94238104Sdes	{ LDNS_STATUS_MISSING_RDATA_FIELDS_KEY, "The DNSKEY has to few rdata fields" },
95238104Sdes	{ LDNS_STATUS_CRYPTO_SIG_EXPIRED_WITHIN_MARGIN,
96238104Sdes		"DNSSEC signature will expire too soon" },
97238104Sdes	{ LDNS_STATUS_CRYPTO_SIG_NOT_INCEPTED_WITHIN_MARGIN,
98238104Sdes		"DNSSEC signature not incepted long enough" },
99246854Sdes	{ LDNS_STATUS_DANE_UNKNOWN_CERTIFICATE_USAGE,
100246854Sdes		"Unknown TLSA Certificate Usage" },
101246854Sdes	{ LDNS_STATUS_DANE_UNKNOWN_SELECTOR, "Unknown TLSA Selector" },
102246854Sdes	{ LDNS_STATUS_DANE_UNKNOWN_MATCHING_TYPE,
103246854Sdes		"Unknown TLSA Matching Type" },
104246854Sdes	{ LDNS_STATUS_DANE_UNKNOWN_PROTOCOL,
105246854Sdes		"Unknown protocol. Only IPv4 and IPv6 are understood" },
106246854Sdes	{ LDNS_STATUS_DANE_UNKNOWN_TRANSPORT,
107246854Sdes		"Unknown transport. Should be one of {tcp, udp, sctp}" },
108246854Sdes	{ LDNS_STATUS_DANE_MISSING_EXTRA_CERTS,  /* Trust anchor assertion */
109246854Sdes		"More than one certificate should be provided" },
110246854Sdes	{ LDNS_STATUS_DANE_EXTRA_CERTS_NOT_USED, /* Trust anchor assertion */
111246854Sdes		"Non of the extra certificates is used to sign the first" },
112246854Sdes	{ LDNS_STATUS_DANE_OFFSET_OUT_OF_RANGE,   /* Trust anchor assertion */
113246854Sdes		"The offset was out of range" },
114246854Sdes	{ LDNS_STATUS_DANE_INSECURE,             /* Unused by library */
115246854Sdes		"The queried resource records were insecure" },
116246854Sdes	{ LDNS_STATUS_DANE_BOGUS,             /* Unused by library */
117246854Sdes		"The queried resource records were bogus" },
118246854Sdes	{ LDNS_STATUS_DANE_TLSA_DID_NOT_MATCH,
119246854Sdes		"The TLSA record(s) "
120246854Sdes		"did not match with the server certificate (chain)" },
121246854Sdes	{ LDNS_STATUS_DANE_NON_CA_CERTIFICATE,
122246854Sdes		"The certificate was not a CA certificate" },
123246854Sdes	{ LDNS_STATUS_DANE_PKIX_DID_NOT_VALIDATE,
124246854Sdes		"Could not PKIX validate" },
125246854Sdes	{ LDNS_STATUS_DANE_PKIX_NO_SELF_SIGNED_TRUST_ANCHOR,
126246854Sdes		"The validation path "
127246854Sdes		"did not end in a self-signed certificate" },
128269257Sdes        { LDNS_STATUS_INVALID_ILNP64,
129269257Sdes		"Conversion error, 4 colon separated hex numbers expected" },
130269257Sdes        { LDNS_STATUS_INVALID_EUI48,
131269257Sdes		"Conversion error, 6 two character hex numbers "
132269257Sdes		"separated by dashes expected (i.e. xx-xx-xx-xx-xx-xx" },
133269257Sdes        { LDNS_STATUS_INVALID_EUI64,
134269257Sdes		"Conversion error, 8 two character hex numbers "
135269257Sdes		"separated by dashes expected (i.e. xx-xx-xx-xx-xx-xx-xx-xx" },
136269257Sdes	{ LDNS_STATUS_WIRE_RDATA_ERR, "invalid rdata in wire format" },
137269257Sdes        { LDNS_STATUS_INVALID_TAG,
138269257Sdes		"Conversion error, a non-zero sequence of US-ASCII letters "
139269257Sdes		"and numbers in lower case expected" },
140269257Sdes        { LDNS_STATUS_TYPE_NOT_IN_BITMAP,
141269257Sdes		"The RR type bitmap rdata field did not have "
142269257Sdes		"a bit reserved for the specific RR type" },
143269257Sdes        { LDNS_STATUS_INVALID_RDF_TYPE,
144269257Sdes		"The rdata field was not of the expected type" },
145269257Sdes        { LDNS_STATUS_RDATA_OVERFLOW, "Rdata size overflow" },
146238104Sdes	{ 0, NULL }
147238104Sdes};
148238104Sdes
149238104Sdesconst char *
150238104Sdesldns_get_errorstr_by_id(ldns_status err)
151238104Sdes{
152238104Sdes        ldns_lookup_table *lt;
153238104Sdes
154238104Sdes        lt = ldns_lookup_by_id(ldns_error_str, err);
155238104Sdes
156238104Sdes        if (lt) {
157238104Sdes                return lt->name;
158238104Sdes        }
159238104Sdes        return NULL;
160238104Sdes}
161