nscperror.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. /* nscperrors.c
  39. * Very crude error handling for nspr and libsec.
  40. */
  41. #include "netsite.h"
  42. #define NSCP_NSPR_ERROR_BASE (-6000)
  43. #define NSCP_NSPR_MAX_ERROR (NSCP_NSPR_ERROR_BASE + 29)
  44. #define NSCP_LIBSEC_ERROR_BASE (-8192)
  45. #define NSCP_LIBSEC_MAX_ERROR (NSCP_LIBSEC_ERROR_BASE + 63)
  46. #define NSCP_LIBSSL_ERROR_BASE (-12288)
  47. #define NSCP_LIBSSL_MAX_ERROR (NSCP_LIBSSL_ERROR_BASE + 19)
  48. typedef struct nscp_error_t {
  49. int errorNumber;
  50. const char *errorString;
  51. } nscp_error_t;
  52. nscp_error_t nscp_nspr_errors[] = {
  53. { 0, "NSPR error" },
  54. { 1, "Out of memory" },
  55. { 2, "Bad file descriptor" },
  56. { 3, "Data temporarily not available" },
  57. { 4, "Access fault" },
  58. { 5, "Invalid method" },
  59. { 6, "Illegal access" },
  60. { 7, "Unknown error" },
  61. { 8, "Pending interrupt" },
  62. { 9, "Not implemented" },
  63. { 10, "IO error" },
  64. { 11, "IO timeout error" },
  65. { 12, "IO already pending error" },
  66. { 13, "Directory open error" },
  67. { 14, "Invalid Argument" },
  68. { 15, "Address not available" },
  69. { 16, "Address not supported" },
  70. { 17, "Already connected" },
  71. { 18, "Bad address" },
  72. { 19, "Address already in use" },
  73. { 20, "Connection refused" },
  74. { 21, "Network unreachable" },
  75. { 22, "Connection timed out" },
  76. { 23, "Not connected" },
  77. { 24, "Load library error" },
  78. { 25, "Unload library error" },
  79. { 26, "Find symbol error" },
  80. { 27, "Connection reset by peer" },
  81. { 28, "Range Error" },
  82. { 29, "File Not Found Error" }
  83. };
  84. nscp_error_t nscp_libsec_errors[] = {
  85. { 0, "SEC_ERROR_IO" },
  86. { 1, "SEC_ERROR_LIBRARY_FAILURE" },
  87. { 2, "SEC_ERROR_BAD_DATA" },
  88. { 3, "SEC_ERROR_OUTPUT_LEN" },
  89. { 4, "SEC_ERROR_INPUT_LEN" },
  90. { 5, "SEC_ERROR_INVALID_ARGS" },
  91. { 6, "SEC_ERROR_INVALID_ALGORITHM" },
  92. { 7, "SEC_ERROR_INVALID_AVA" },
  93. { 8, "SEC_ERROR_INVALID_TIME" },
  94. { 9, "SEC_ERROR_BAD_DER" },
  95. { 10, "SEC_ERROR_BAD_SIGNATURE" },
  96. { 11, "SEC_ERROR_EXPIRED_CERTIFICATE" },
  97. { 12, "SEC_ERROR_REVOKED_CERTIFICATE" },
  98. { 13, "SEC_ERROR_UNKNOWN_ISSUER" },
  99. { 14, "SEC_ERROR_BAD_KEY" },
  100. { 15, "SEC_ERROR_BAD_PASSWORD" },
  101. { 16, "SEC_ERROR_UNUSED" },
  102. { 17, "SEC_ERROR_NO_NODELOCK" },
  103. { 18, "SEC_ERROR_BAD_DATABASE" },
  104. { 19, "SEC_ERROR_NO_MEMORY" },
  105. { 20, "SEC_ERROR_UNTRUSTED_ISSUER" },
  106. { 21, "SEC_ERROR_UNTRUSTED_CERT" },
  107. { 22, "SEC_ERROR_DUPLICATE_CERT" },
  108. { 23, "SEC_ERROR_DUPLICATE_CERT_TIME" },
  109. { 24, "SEC_ERROR_ADDING_CERT" },
  110. { 25, "SEC_ERROR_FILING_KEY" },
  111. { 26, "SEC_ERROR_NO_KEY" },
  112. { 27, "SEC_ERROR_CERT_VALID" },
  113. { 28, "SEC_ERROR_CERT_NOT_VALID" },
  114. { 29, "SEC_ERROR_CERT_NO_RESPONSE" },
  115. { 30, "SEC_ERROR_EXPIRED_ISSUER_CERTIFICATE" },
  116. { 31, "SEC_ERROR_CRL_EXPIRED" },
  117. { 32, "SEC_ERROR_CRL_BAD_SIGNATURE" },
  118. { 33, "SEC_ERROR_CRL_INVALID" },
  119. { 34, "SEC_ERROR_" },
  120. { 35, "SEC_ERROR_" },
  121. { 36, "SEC_ERROR_" },
  122. { 37, "SEC_ERROR_" },
  123. { 38, "SEC_ERROR_" },
  124. { 39, "SEC_ERROR_" },
  125. { 40, "SEC_ERROR_" },
  126. { 41, "SEC_ERROR_" },
  127. { 42, "SEC_ERROR_" },
  128. { 43, "SEC_ERROR_" },
  129. { 44, "SEC_ERROR_" },
  130. { 45, "SEC_ERROR_" },
  131. { 46, "SEC_ERROR_" },
  132. { 47, "SEC_ERROR_" },
  133. { 48, "SEC_ERROR_" },
  134. { 49, "SEC_ERROR_" },
  135. { 50, "SEC_ERROR_" },
  136. { 51, "SEC_ERROR_" },
  137. { 52, "SEC_ERROR_" },
  138. { 53, "SEC_ERROR_" },
  139. { 54, "SEC_ERROR_" },
  140. { 55, "SEC_ERROR_" },
  141. { 56, "SEC_ERROR_" },
  142. { 57, "SEC_ERROR_" },
  143. { 58, "SEC_ERROR_" },
  144. { 59, "SEC_ERROR_" },
  145. { 60, "SEC_ERROR_" },
  146. { 61, "SEC_ERROR_" },
  147. { 62, "SEC_ERROR_" },
  148. { 63, "SEC_ERROR_NEED_RANDOM" }
  149. };
  150. nscp_error_t nscp_libssl_errors[] = {
  151. { 0, "SSL_ERROR_EXPORT_ONLY_SERVER" },
  152. { 1, "SSL_ERROR_US_ONLY_SERVER" },
  153. { 2, "SSL_ERROR_NO_CYPHER_OVERLAP" },
  154. { 3, "SSL_ERROR_NO_CERTIFICATE" },
  155. { 4, "SSL_ERROR_BAD_CERTIFICATE" },
  156. { 5, "unused SSL error #5" },
  157. { 6, "SSL_ERROR_BAD_CLIENT - the server has encountered bad data from the client." },
  158. { 7, "SSL_ERROR_BAD_SERVER" },
  159. { 8, "SSL_ERROR_UNSUPPORTED_CERTIFICATE_TYPE" },
  160. { 9, "SSL_ERROR_UNSUPPORTED_VERSION" },
  161. { 10, "unused SSL error #10" },
  162. { 11, "SSL_ERROR_WRONG_CERTIFICATE" },
  163. { 12, "SSL_ERROR_BAD_CERT_DOMAIN" },
  164. { 13, "SSL_ERROR_POST_WARNING" },
  165. { 14, "SSL_ERROR_SSL2_DISABLED" },
  166. { 15, "SSL_ERROR_BAD_MAC_READ - SSL has received a record with an incorrect Message Authentication Code." },
  167. { 16, "SSL_ERROR_BAD_MAC_ALERT - SSL has received an error indicating an incorrect Message Authentication Code." },
  168. { 17, "SSL_ERROR_BAD_CERT_ALERT - the server cannot verify your certificate." },
  169. { 18, "SSL_ERROR_REVOKED_CERT_ALERT - the server has rejected your certificate as revoked." },
  170. { 19, "SSL_ERROR_EXPIRED_CERT_ALERT - the server has rejected your certificate as expired." },
  171. };
  172. const char *
  173. nscperror_lookup(int error)
  174. {
  175. if ((error >= NSCP_NSPR_ERROR_BASE) &&
  176. (error <= NSCP_NSPR_MAX_ERROR)) {
  177. return nscp_nspr_errors[error-NSCP_NSPR_ERROR_BASE].errorString;
  178. } else if ((error >= NSCP_LIBSEC_ERROR_BASE) &&
  179. (error <= NSCP_LIBSEC_MAX_ERROR)) {
  180. return nscp_libsec_errors[error-NSCP_LIBSEC_ERROR_BASE].errorString;
  181. } else if ((error >= NSCP_LIBSSL_ERROR_BASE) &&
  182. (error <= NSCP_LIBSSL_MAX_ERROR)) {
  183. return nscp_libssl_errors[error-NSCP_LIBSSL_ERROR_BASE].errorString;
  184. } else {
  185. return (const char *)NULL;
  186. }
  187. }