result.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004, 2005, 2007-2014  Internet Systems Consortium, Inc. ("ISC")
00003  * Copyright (C) 1998-2003  Internet Software Consortium.
00004  *
00005  * Permission to use, copy, modify, and/or distribute this software for any
00006  * purpose with or without fee is hereby granted, provided that the above
00007  * copyright notice and this permission notice appear in all copies.
00008  *
00009  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
00010  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
00011  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
00012  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00013  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00014  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00015  * PERFORMANCE OF THIS SOFTWARE.
00016  */
00017 
00018 /* $Id$ */
00019 
00020 /*! \file */
00021 
00022 #include <config.h>
00023 
00024 #include <isc/once.h>
00025 #include <isc/util.h>
00026 
00027 #include <dns/result.h>
00028 #include <dns/lib.h>
00029 
00030 static const char *text[DNS_R_NRESULTS] = {
00031         "label too long",                      /*%< 0 DNS_R_LABELTOOLONG */
00032         "bad escape",                          /*%< 1 DNS_R_BADESCAPE */
00033         /*!
00034          * Note that DNS_R_BADBITSTRING and DNS_R_BITSTRINGTOOLONG are
00035          * deprecated.
00036          */
00037         "bad bitstring",                       /*%< 2 DNS_R_BADBITSTRING */
00038         "bitstring too long",                  /*%< 3 DNS_R_BITSTRINGTOOLONG */
00039         "empty label",                         /*%< 4 DNS_R_EMPTYLABEL */
00040 
00041         "bad dotted quad",                     /*%< 5 DNS_R_BADDOTTEDQUAD */
00042         "invalid NS owner name (wildcard)",    /*%< 6 DNS_R_INVALIDNS */
00043         "unknown class/type",                  /*%< 7 DNS_R_UNKNOWN */
00044         "bad label type",                      /*%< 8 DNS_R_BADLABELTYPE */
00045         "bad compression pointer",             /*%< 9 DNS_R_BADPOINTER */
00046 
00047         "too many hops",                       /*%< 10 DNS_R_TOOMANYHOPS */
00048         "disallowed (by application policy)",  /*%< 11 DNS_R_DISALLOWED */
00049         "extra input text",                    /*%< 12 DNS_R_EXTRATOKEN */
00050         "extra input data",                    /*%< 13 DNS_R_EXTRADATA */
00051         "text too long",                       /*%< 14 DNS_R_TEXTTOOLONG */
00052 
00053         "not at top of zone",                  /*%< 15 DNS_R_NOTZONETOP */
00054         "syntax error",                        /*%< 16 DNS_R_SYNTAX */
00055         "bad checksum",                        /*%< 17 DNS_R_BADCKSUM */
00056         "bad IPv6 address",                    /*%< 18 DNS_R_BADAAAA */
00057         "no owner",                            /*%< 19 DNS_R_NOOWNER */
00058 
00059         "no ttl",                              /*%< 20 DNS_R_NOTTL */
00060         "bad class",                           /*%< 21 DNS_R_BADCLASS */
00061         "name too long",                       /*%< 22 DNS_R_NAMETOOLONG */
00062         "partial match",                       /*%< 23 DNS_R_PARTIALMATCH */
00063         "new origin",                          /*%< 24 DNS_R_NEWORIGIN */
00064 
00065         "unchanged",                           /*%< 25 DNS_R_UNCHANGED */
00066         "bad ttl",                             /*%< 26 DNS_R_BADTTL */
00067         "more data needed/to be rendered",     /*%< 27 DNS_R_NOREDATA */
00068         "continue",                            /*%< 28 DNS_R_CONTINUE */
00069         "delegation",                          /*%< 29 DNS_R_DELEGATION */
00070 
00071         "glue",                                /*%< 30 DNS_R_GLUE */
00072         "dname",                               /*%< 31 DNS_R_DNAME */
00073         "cname",                               /*%< 32 DNS_R_CNAME */
00074         "bad database",                        /*%< 33 DNS_R_BADDB */
00075         "zonecut",                             /*%< 34 DNS_R_ZONECUT */
00076 
00077         "bad zone",                            /*%< 35 DNS_R_BADZONE */
00078         "more data",                           /*%< 36 DNS_R_MOREDATA */
00079         "up to date",                          /*%< 37 DNS_R_UPTODATE */
00080         "tsig verify failure",                 /*%< 38 DNS_R_TSIGVERIFYFAILURE */
00081         "tsig indicates error",                /*%< 39 DNS_R_TSIGERRORSET */
00082 
00083         "RRSIG failed to verify",              /*%< 40 DNS_R_SIGINVALID */
00084         "RRSIG has expired",                   /*%< 41 DNS_R_SIGEXPIRED */
00085         "RRSIG validity period has not begun", /*%< 42 DNS_R_SIGFUTURE */
00086         "key is unauthorized to sign data",    /*%< 43 DNS_R_KEYUNAUTHORIZED */
00087         "invalid time",                        /*%< 44 DNS_R_INVALIDTIME */
00088 
00089         "expected a TSIG or SIG(0)",           /*%< 45 DNS_R_EXPECTEDTSIG */
00090         "did not expect a TSIG or SIG(0)",     /*%< 46 DNS_R_UNEXPECTEDTSIG */
00091         "TKEY is unacceptable",                /*%< 47 DNS_R_INVALIDTKEY */
00092         "hint",                                /*%< 48 DNS_R_HINT */
00093         "drop",                                /*%< 49 DNS_R_DROP */
00094 
00095         "zone not loaded",                     /*%< 50 DNS_R_NOTLOADED */
00096         "ncache nxdomain",                     /*%< 51 DNS_R_NCACHENXDOMAIN */
00097         "ncache nxrrset",                      /*%< 52 DNS_R_NCACHENXRRSET */
00098         "wait",                                /*%< 53 DNS_R_WAIT */
00099         "not verified yet",                    /*%< 54 DNS_R_NOTVERIFIEDYET */
00100 
00101         "no identity",                         /*%< 55 DNS_R_NOIDENTITY */
00102         "no journal",                          /*%< 56 DNS_R_NOJOURNAL */
00103         "alias",                               /*%< 57 DNS_R_ALIAS */
00104         "use TCP",                             /*%< 58 DNS_R_USETCP */
00105         "no valid RRSIG",                      /*%< 59 DNS_R_NOVALIDSIG */
00106 
00107         "no valid NSEC",                       /*%< 60 DNS_R_NOVALIDNSEC */
00108         "insecurity proof failed",             /*%< 61 DNS_R_NOTINSECURE */
00109         "unknown service",                     /*%< 62 DNS_R_UNKNOWNSERVICE */
00110         "recoverable error occurred",          /*%< 63 DNS_R_RECOVERABLE */
00111         "unknown opt attribute record",        /*%< 64 DNS_R_UNKNOWNOPT */
00112 
00113         "unexpected message id",               /*%< 65 DNS_R_UNEXPECTEDID */
00114         "seen include file",                   /*%< 66 DNS_R_SEENINCLUDE */
00115         "not exact",                           /*%< 67 DNS_R_NOTEXACT */
00116         "address blackholed",                  /*%< 68 DNS_R_BLACKHOLED */
00117         "bad algorithm",                       /*%< 69 DNS_R_BADALG */
00118 
00119         "invalid use of a meta type",          /*%< 70 DNS_R_METATYPE */
00120         "CNAME and other data",                /*%< 71 DNS_R_CNAMEANDOTHER */
00121         "multiple RRs of singleton type",      /*%< 72 DNS_R_SINGLETON */
00122         "hint nxrrset",                        /*%< 73 DNS_R_HINTNXRRSET */
00123         "no master file configured",           /*%< 74 DNS_R_NOMASTERFILE */
00124 
00125         "unknown protocol",                    /*%< 75 DNS_R_UNKNOWNPROTO */
00126         "clocks are unsynchronized",           /*%< 76 DNS_R_CLOCKSKEW */
00127         "IXFR failed",                         /*%< 77 DNS_R_BADIXFR */
00128         "not authoritative",                   /*%< 78 DNS_R_NOTAUTHORITATIVE */
00129         "no valid KEY",                        /*%< 79 DNS_R_NOVALIDKEY */
00130 
00131         "obsolete",                            /*%< 80 DNS_R_OBSOLETE */
00132         "already frozen",                      /*%< 81 DNS_R_FROZEN */
00133         "unknown flag",                        /*%< 82 DNS_R_UNKNOWNFLAG */
00134         "expected a response",                 /*%< 83 DNS_R_EXPECTEDRESPONSE */
00135         "no valid DS",                         /*%< 84 DNS_R_NOVALIDDS */
00136 
00137         "NS is an address",                    /*%< 85 DNS_R_NSISADDRESS */
00138         "received FORMERR",                    /*%< 86 DNS_R_REMOTEFORMERR */
00139         "truncated TCP response",              /*%< 87 DNS_R_TRUNCATEDTCP */
00140         "lame server detected",                /*%< 88 DNS_R_LAME */
00141         "unexpected RCODE",                    /*%< 89 DNS_R_UNEXPECTEDRCODE */
00142 
00143         "unexpected OPCODE",                   /*%< 90 DNS_R_UNEXPECTEDOPCODE */
00144         "chase DS servers",                    /*%< 91 DNS_R_CHASEDSSERVERS */
00145         "empty name",                          /*%< 92 DNS_R_EMPTYNAME */
00146         "empty wild",                          /*%< 93 DNS_R_EMPTYWILD */
00147         "bad bitmap",                          /*%< 94 DNS_R_BADBITMAP */
00148 
00149         "from wildcard",                       /*%< 95 DNS_R_FROMWILDCARD */
00150         "bad owner name (check-names)",        /*%< 96 DNS_R_BADOWNERNAME */
00151         "bad name (check-names)",              /*%< 97 DNS_R_BADNAME */
00152         "dynamic zone",                        /*%< 98 DNS_R_DYNAMIC */
00153         "unknown command",                     /*%< 99 DNS_R_UNKNOWNCOMMAND */
00154 
00155         "must-be-secure",                      /*%< 100 DNS_R_MUSTBESECURE */
00156         "covering NSEC record returned",       /*%< 101 DNS_R_COVERINGNSEC */
00157         "MX is an address",                    /*%< 102 DNS_R_MXISADDRESS */
00158         "duplicate query",                     /*%< 103 DNS_R_DUPLICATE */
00159         "invalid NSEC3 owner name (wildcard)", /*%< 104 DNS_R_INVALIDNSEC3 */
00160 
00161         "not master",                          /*%< 105 DNS_R_NOTMASTER */
00162         "broken trust chain",                  /*%< 106 DNS_R_BROKENCHAIN */
00163         "expired",                             /*%< 107 DNS_R_EXPIRED */
00164         "not dynamic",                         /*%< 108 DNS_R_NOTDYNAMIC */
00165         "bad EUI",                             /*%< 109 DNS_R_BADEUI */
00166 
00167         "covered by negative trust anchor"     /*%< 110 DNS_R_NTACOVERED */
00168 };
00169 
00170 static const char *rcode_text[DNS_R_NRCODERESULTS] = {
00171         "NOERROR",                              /*%< 0 DNS_R_NOEROR */
00172         "FORMERR",                              /*%< 1 DNS_R_FORMERR */
00173         "SERVFAIL",                             /*%< 2 DNS_R_SERVFAIL */
00174         "NXDOMAIN",                             /*%< 3 DNS_R_NXDOMAIN */
00175         "NOTIMP",                               /*%< 4 DNS_R_NOTIMP */
00176 
00177         "REFUSED",                              /*%< 5 DNS_R_REFUSED */
00178         "YXDOMAIN",                             /*%< 6 DNS_R_YXDOMAIN */
00179         "YXRRSET",                              /*%< 7 DNS_R_YXRRSET */
00180         "NXRRSET",                              /*%< 8 DNS_R_NXRRSET */
00181         "NOTAUTH",                              /*%< 9 DNS_R_NOTAUTH */
00182 
00183         "NOTZONE",                              /*%< 10 DNS_R_NOTZONE */
00184         "<rcode 11>",                           /*%< 11 has no macro */
00185         "<rcode 12>",                           /*%< 12 has no macro */
00186         "<rcode 13>",                           /*%< 13 has no macro */
00187         "<rcode 14>",                           /*%< 14 has no macro */
00188 
00189         "<rcode 15>",                           /*%< 15 has no macro */
00190         "BADVERS",                              /*%< 16 DNS_R_BADVERS */
00191 };
00192 
00193 #define DNS_RESULT_RESULTSET                    2
00194 #define DNS_RESULT_RCODERESULTSET               3
00195 
00196 static isc_once_t               once = ISC_ONCE_INIT;
00197 
00198 static void
00199 initialize_action(void) {
00200         isc_result_t result;
00201 
00202         result = isc_result_register(ISC_RESULTCLASS_DNS, DNS_R_NRESULTS,
00203                                      text, dns_msgcat, DNS_RESULT_RESULTSET);
00204         if (result == ISC_R_SUCCESS)
00205                 result = isc_result_register(ISC_RESULTCLASS_DNSRCODE,
00206                                              DNS_R_NRCODERESULTS,
00207                                              rcode_text, dns_msgcat,
00208                                              DNS_RESULT_RCODERESULTSET);
00209         if (result != ISC_R_SUCCESS)
00210                 UNEXPECTED_ERROR(__FILE__, __LINE__,
00211                                  "isc_result_register() failed: %u", result);
00212 }
00213 
00214 static void
00215 initialize(void) {
00216         dns_lib_initmsgcat();
00217         RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
00218 }
00219 
00220 const char *
00221 dns_result_totext(isc_result_t result) {
00222         initialize();
00223 
00224         return (isc_result_totext(result));
00225 }
00226 
00227 void
00228 dns_result_register(void) {
00229         initialize();
00230 }
00231 
00232 dns_rcode_t
00233 dns_result_torcode(isc_result_t result) {
00234         dns_rcode_t rcode = dns_rcode_servfail;
00235 
00236         if (DNS_RESULT_ISRCODE(result)) {
00237                 /*
00238                  * Rcodes can't be bigger than 12 bits, which is why we
00239                  * AND with 0xFFF instead of 0xFFFF.
00240                  */
00241                 return ((dns_rcode_t)((result) & 0xFFF));
00242         }
00243         /*
00244          * Try to supply an appropriate rcode.
00245          */
00246         switch (result) {
00247         case ISC_R_SUCCESS:
00248                 rcode = dns_rcode_noerror;
00249                 break;
00250         case ISC_R_BADBASE64:
00251         case ISC_R_NOSPACE:
00252         case ISC_R_RANGE:
00253         case ISC_R_UNEXPECTEDEND:
00254         case DNS_R_BADAAAA:
00255         /* case DNS_R_BADBITSTRING: deprecated */
00256         case DNS_R_BADCKSUM:
00257         case DNS_R_BADCLASS:
00258         case DNS_R_BADLABELTYPE:
00259         case DNS_R_BADPOINTER:
00260         case DNS_R_BADTTL:
00261         case DNS_R_BADZONE:
00262         /* case DNS_R_BITSTRINGTOOLONG: deprecated */
00263         case DNS_R_EXTRADATA:
00264         case DNS_R_LABELTOOLONG:
00265         case DNS_R_NOREDATA:
00266         case DNS_R_SYNTAX:
00267         case DNS_R_TEXTTOOLONG:
00268         case DNS_R_TOOMANYHOPS:
00269         case DNS_R_TSIGERRORSET:
00270         case DNS_R_UNKNOWN:
00271         case DNS_R_NAMETOOLONG:
00272                 rcode = dns_rcode_formerr;
00273                 break;
00274         case DNS_R_DISALLOWED:
00275                 rcode = dns_rcode_refused;
00276                 break;
00277         case DNS_R_TSIGVERIFYFAILURE:
00278         case DNS_R_CLOCKSKEW:
00279                 rcode = dns_rcode_notauth;
00280                 break;
00281         default:
00282                 rcode = dns_rcode_servfail;
00283         }
00284 
00285         return (rcode);
00286 }

Generated on Tue Apr 28 17:41:05 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha