PageRenderTime 22ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/libgsasl/libgsasl-1.0/src/error.c

https://bitbucket.org/thelearninglabs/uclinux-distro-tll-public
C | 245 lines | 182 code | 13 blank | 50 comment | 5 complexity | 6a28dca326b99528b516c405aa27009d MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, Unlicense, GPL-2.0, GPL-3.0, CC-BY-SA-3.0, AGPL-1.0, ISC, MIT, 0BSD, LGPL-2.0
  1. /* error.c --- Error handling functionality.
  2. * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Simon Josefsson
  3. *
  4. * This file is part of GNU SASL Library.
  5. *
  6. * GNU SASL Library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public License
  8. * as published by the Free Software Foundation; either version 2.1 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * GNU SASL Library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License License along with GNU SASL Library; if not, write to the
  18. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. *
  21. */
  22. #include "internal.h"
  23. /* I18n of error codes. */
  24. #include "gettext.h"
  25. #define _(String) dgettext (PACKAGE, String)
  26. #define gettext_noop(String) String
  27. #define N_(String) gettext_noop (String)
  28. #define ERR(name, desc) { name, #name, desc }
  29. #ifdef GSASL_NO_OBSOLETE
  30. #define OBS(i, name, desc) { i, NULL, NULL }
  31. #else
  32. #define OBS(i, name, desc) { name, #name, desc }
  33. #endif
  34. static struct {
  35. int rc;
  36. const char *name;
  37. const char *description;
  38. } errors[] = {
  39. ERR (GSASL_OK, N_("Libgsasl success")),
  40. ERR (GSASL_NEEDS_MORE, N_("SASL mechanism needs more data")),
  41. ERR (GSASL_UNKNOWN_MECHANISM, N_("Unknown SASL mechanism")),
  42. ERR (GSASL_MECHANISM_CALLED_TOO_MANY_TIMES,
  43. N_("SASL mechanism called too many times")),
  44. OBS (4, GSASL_TOO_SMALL_BUFFER,
  45. N_("SASL function needs larger buffer (internal error)")),
  46. OBS (5, GSASL_FOPEN_ERROR, N_("Could not open file in SASL library")),
  47. OBS (6, GSASL_FCLOSE_ERROR, N_("Could not close file in SASL library")),
  48. ERR (GSASL_MALLOC_ERROR, N_("Memory allocation error in SASL library")),
  49. ERR (GSASL_BASE64_ERROR, N_("Base 64 coding error in SASL library")),
  50. ERR (GSASL_CRYPTO_ERROR, N_("Low-level crypto error in SASL library")),
  51. { 10, NULL, NULL },
  52. OBS (11, GSASL_NEED_CLIENT_ANONYMOUS_CALLBACK,
  53. N_("SASL mechanism needs gsasl_client_callback_anonymous() callback"
  54. " (application error)")),
  55. OBS (12, GSASL_NEED_CLIENT_PASSWORD_CALLBACK,
  56. N_("SASL mechanism needs gsasl_client_callback_password() callback"
  57. " (application error)")),
  58. OBS (13, GSASL_NEED_CLIENT_PASSCODE_CALLBACK,
  59. N_("SASL mechanism needs gsasl_client_callback_passcode() callback"
  60. " (application error)")),
  61. OBS (14, GSASL_NEED_CLIENT_PIN_CALLBACK,
  62. N_("SASL mechanism needs gsasl_client_callback_pin() callback"
  63. " (application error)")),
  64. OBS (15, GSASL_NEED_CLIENT_AUTHORIZATION_ID_CALLBACK,
  65. N_("SASL mechanism needs gsasl_client_callback_authorization_id() "
  66. "callback (application error)")),
  67. OBS (16, GSASL_NEED_CLIENT_AUTHENTICATION_ID_CALLBACK,
  68. N_("SASL mechanism needs gsasl_client_callback_authentication_id() "
  69. "callback (application error)")),
  70. OBS (17, GSASL_NEED_CLIENT_SERVICE_CALLBACK,
  71. N_("SASL mechanism needs gsasl_client_callback_service() callback "
  72. "(application error)")),
  73. OBS (18, GSASL_NEED_SERVER_VALIDATE_CALLBACK,
  74. N_("SASL mechanism needs gsasl_server_callback_validate() callback "
  75. "(application error)")),
  76. OBS (19, GSASL_NEED_SERVER_CRAM_MD5_CALLBACK,
  77. N_("SASL mechanism needs gsasl_server_callback_cram_md5() callback "
  78. "(application error)")),
  79. OBS (20, GSASL_NEED_SERVER_DIGEST_MD5_CALLBACK,
  80. N_("SASL mechanism needs gsasl_server_callback_digest_md5() callback "
  81. "(application error)")),
  82. OBS (21, GSASL_NEED_SERVER_EXTERNAL_CALLBACK,
  83. N_("SASL mechanism needs gsasl_server_callback_external() callback "
  84. "(application error)")),
  85. OBS (22, GSASL_NEED_SERVER_ANONYMOUS_CALLBACK,
  86. N_("SASL mechanism needs gsasl_server_callback_anonymous() callback "
  87. "(application error)")),
  88. OBS (23, GSASL_NEED_SERVER_REALM_CALLBACK,
  89. N_("SASL mechanism needs gsasl_server_callback_realm() callback "
  90. "(application error)")),
  91. OBS (24, GSASL_NEED_SERVER_SECURID_CALLBACK,
  92. N_("SASL mechanism needs gsasl_server_callback_securid() callback "
  93. "(application error)")),
  94. OBS (25, GSASL_NEED_SERVER_SERVICE_CALLBACK,
  95. N_("SASL mechanism needs gsasl_server_callback_service() callback "
  96. "(application error)")),
  97. OBS (26, GSASL_NEED_SERVER_GSSAPI_CALLBACK,
  98. N_("SASL mechanism needs gsasl_server_callback_gssapi() callback "
  99. "(application error)")),
  100. OBS (27, GSASL_NEED_SERVER_RETRIEVE_CALLBACK,
  101. N_("SASL mechanism needs gsasl_server_callback_retrieve() callback "
  102. "(application error)")),
  103. OBS (28, GSASL_UNICODE_NORMALIZATION_ERROR,
  104. N_("Failed to perform Unicode Normalization on string.")),
  105. ERR (GSASL_SASLPREP_ERROR,
  106. N_("Could not prepare internationalized (non-ASCII) string.")),
  107. ERR (GSASL_MECHANISM_PARSE_ERROR,
  108. N_("SASL mechanism could not parse input")),
  109. ERR (GSASL_AUTHENTICATION_ERROR, N_("Error authenticating user")),
  110. OBS (32, GSASL_CANNOT_GET_CTX,
  111. N_("Cannot get internal library handle (library error)")),
  112. ERR (GSASL_INTEGRITY_ERROR, N_("Integrity error in application payload")),
  113. OBS (34, GSASL_NO_MORE_REALMS, N_("No more realms available (non-fatal)")),
  114. ERR (GSASL_NO_CLIENT_CODE,
  115. N_("Client-side functionality not available in library "
  116. "(application error)")),
  117. ERR (GSASL_NO_SERVER_CODE,
  118. N_("Server-side functionality not available in library "
  119. "(application error)")),
  120. ERR (GSASL_GSSAPI_RELEASE_BUFFER_ERROR,
  121. N_("GSSAPI library could not deallocate memory in "
  122. "gss_release_buffer() in SASL library. This is a serious "
  123. "internal error.")),
  124. ERR (GSASL_GSSAPI_IMPORT_NAME_ERROR,
  125. N_("GSSAPI library could not understand a peer name in "
  126. "gss_import_name() in SASL library. This is most likely due "
  127. "to incorrect service and/or hostnames.")),
  128. ERR (GSASL_GSSAPI_INIT_SEC_CONTEXT_ERROR,
  129. N_("GSSAPI error in client while negotiating security context in "
  130. "gss_init_sec_context() in SASL library. This is most likely "
  131. "due insufficient credentials or malicious interactions.")),
  132. ERR (GSASL_GSSAPI_ACCEPT_SEC_CONTEXT_ERROR,
  133. N_("GSSAPI error in server while negotiating security context in "
  134. "gss_init_sec_context() in SASL library. This is most likely due "
  135. "insufficient credentials or malicious interactions.")),
  136. ERR (GSASL_GSSAPI_UNWRAP_ERROR,
  137. N_("GSSAPI error while decrypting or decoding data in gss_unwrap() in "
  138. "SASL library. This is most likely due to data corruption.")),
  139. ERR (GSASL_GSSAPI_WRAP_ERROR,
  140. N_("GSSAPI error while encrypting or encoding data in gss_wrap() in "
  141. "SASL library.")),
  142. ERR (GSASL_GSSAPI_ACQUIRE_CRED_ERROR,
  143. N_("GSSAPI error acquiring credentials in gss_acquire_cred() in "
  144. "SASL library. This is most likely due to not having the proper "
  145. "Kerberos key available in /etc/krb5.keytab on the server.")),
  146. ERR (GSASL_GSSAPI_DISPLAY_NAME_ERROR,
  147. N_("GSSAPI error creating a display name denoting the client in "
  148. "gss_display_name() in SASL library. This is probably because "
  149. "the client supplied bad data.")),
  150. ERR (GSASL_GSSAPI_UNSUPPORTED_PROTECTION_ERROR,
  151. N_("Other entity requested integrity or confidentiality protection "
  152. "in GSSAPI mechanism but this is currently not implemented.")),
  153. ERR (GSASL_KERBEROS_V5_INIT_ERROR,
  154. N_("Kerberos V5 initialization failure.")),
  155. ERR (GSASL_KERBEROS_V5_INTERNAL_ERROR,
  156. N_("Kerberos V5 internal error.")),
  157. ERR (GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE,
  158. N_("SecurID needs additional passcode.")),
  159. ERR (GSASL_SECURID_SERVER_NEED_NEW_PIN,
  160. N_("SecurID needs new pin.")),
  161. OBS (50, GSASL_INVALID_HANDLE,
  162. N_("The provided library handle was invalid (application error)")),
  163. ERR (GSASL_NO_CALLBACK,
  164. N_("No callback specified by caller (application error).")),
  165. ERR (GSASL_NO_ANONYMOUS_TOKEN,
  166. N_("Authentication failed because the anonymous token was "
  167. "not provided.")),
  168. ERR (GSASL_NO_AUTHID,
  169. N_("Authentication failed because the authentication identity was "
  170. "not provided.")),
  171. ERR (GSASL_NO_AUTHZID,
  172. N_("Authentication failed because the authorization identity was "
  173. "not provided.")),
  174. ERR (GSASL_NO_PASSWORD,
  175. N_("Authentication failed because the password was not provided.")),
  176. ERR (GSASL_NO_PASSCODE,
  177. N_("Authentication failed because the passcode was not provided.")),
  178. ERR (GSASL_NO_PIN,
  179. N_("Authentication failed because the pin code was not provided.")),
  180. ERR (GSASL_NO_SERVICE,
  181. N_("Authentication failed because the service name was not provided.")),
  182. ERR (GSASL_NO_HOSTNAME,
  183. N_("Authentication failed because the host name was not provided."))
  184. };
  185. /**
  186. * gsasl_strerror:
  187. * @err: libgsasl error code
  188. *
  189. * Convert return code to human readable string explanation of the
  190. * reason for the particular error code.
  191. *
  192. * This string can be used to output a diagnostic message to the user.
  193. *
  194. * Return value: Returns a pointer to a statically allocated string
  195. * containing an explanation of the error code @err.
  196. **/
  197. const char *
  198. gsasl_strerror (int err)
  199. {
  200. static const char *unknown = N_("Libgsasl unknown error");
  201. const char *p;
  202. bindtextdomain (PACKAGE, LOCALEDIR);
  203. if (err < 0 || err >= (sizeof (errors) / sizeof (errors[0])))
  204. return _(unknown);
  205. p = errors[err].description;
  206. if (!p)
  207. p = unknown;
  208. return _(p);
  209. }
  210. /**
  211. * gsasl_strerror_name:
  212. * @err: libgsasl error code
  213. *
  214. * Convert return code to human readable string representing the error
  215. * code symbol itself. For example, gsasl_strerror_name(%GSASL_OK)
  216. * returns the string "GSASL_OK".
  217. *
  218. * This string can be used to output a diagnostic message to the user.
  219. *
  220. * Return value: Returns a pointer to a statically allocated string
  221. * containing a string version of the error code @err, or %NULL if
  222. * the error code is not known.
  223. *
  224. * Since: 0.2.29
  225. **/
  226. const char *
  227. gsasl_strerror_name (int err)
  228. {
  229. if (err < 0 || err >= (sizeof (errors) / sizeof (errors[0])))
  230. return NULL;
  231. return errors[err].name;
  232. }