PageRenderTime 82ms CodeModel.GetById 67ms app.highlight 12ms RepoModel.GetById 1ms 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
  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
 23#include "internal.h"
 24
 25/* I18n of error codes. */
 26#include "gettext.h"
 27#define _(String) dgettext (PACKAGE, String)
 28#define gettext_noop(String) String
 29#define N_(String) gettext_noop (String)
 30
 31#define ERR(name, desc) { name, #name, desc }
 32
 33#ifdef GSASL_NO_OBSOLETE
 34#define OBS(i, name, desc) { i, NULL, NULL }
 35#else
 36#define OBS(i, name, desc) { name, #name, desc }
 37#endif
 38
 39static struct {
 40  int rc;
 41  const char *name;
 42  const char *description;
 43} errors[] = {
 44  ERR (GSASL_OK, N_("Libgsasl success")),
 45  ERR (GSASL_NEEDS_MORE, N_("SASL mechanism needs more data")),
 46  ERR (GSASL_UNKNOWN_MECHANISM, N_("Unknown SASL mechanism")),
 47  ERR (GSASL_MECHANISM_CALLED_TOO_MANY_TIMES,
 48       N_("SASL mechanism called too many times")),
 49  OBS (4, GSASL_TOO_SMALL_BUFFER,
 50       N_("SASL function needs larger buffer (internal error)")),
 51  OBS (5, GSASL_FOPEN_ERROR, N_("Could not open file in SASL library")),
 52  OBS (6, GSASL_FCLOSE_ERROR, N_("Could not close file in SASL library")),
 53  ERR (GSASL_MALLOC_ERROR, N_("Memory allocation error in SASL library")),
 54  ERR (GSASL_BASE64_ERROR, N_("Base 64 coding error in SASL library")),
 55  ERR (GSASL_CRYPTO_ERROR, N_("Low-level crypto error in SASL library")),
 56  { 10, NULL, NULL },
 57  OBS (11, GSASL_NEED_CLIENT_ANONYMOUS_CALLBACK,
 58       N_("SASL mechanism needs gsasl_client_callback_anonymous() callback"
 59	  " (application error)")),
 60  OBS (12, GSASL_NEED_CLIENT_PASSWORD_CALLBACK,
 61       N_("SASL mechanism needs gsasl_client_callback_password() callback"
 62	  " (application error)")),
 63  OBS (13, GSASL_NEED_CLIENT_PASSCODE_CALLBACK,
 64       N_("SASL mechanism needs gsasl_client_callback_passcode() callback"
 65	  " (application error)")),
 66  OBS (14, GSASL_NEED_CLIENT_PIN_CALLBACK,
 67       N_("SASL mechanism needs gsasl_client_callback_pin() callback"
 68	  " (application error)")),
 69  OBS (15, GSASL_NEED_CLIENT_AUTHORIZATION_ID_CALLBACK,
 70       N_("SASL mechanism needs gsasl_client_callback_authorization_id() "
 71	  "callback (application error)")),
 72  OBS (16, GSASL_NEED_CLIENT_AUTHENTICATION_ID_CALLBACK,
 73       N_("SASL mechanism needs gsasl_client_callback_authentication_id() "
 74	  "callback (application error)")),
 75  OBS (17, GSASL_NEED_CLIENT_SERVICE_CALLBACK,
 76       N_("SASL mechanism needs gsasl_client_callback_service() callback "
 77	  "(application error)")),
 78  OBS (18, GSASL_NEED_SERVER_VALIDATE_CALLBACK,
 79       N_("SASL mechanism needs gsasl_server_callback_validate() callback "
 80	  "(application error)")),
 81  OBS (19, GSASL_NEED_SERVER_CRAM_MD5_CALLBACK,
 82       N_("SASL mechanism needs gsasl_server_callback_cram_md5() callback "
 83	  "(application error)")),
 84  OBS (20, GSASL_NEED_SERVER_DIGEST_MD5_CALLBACK,
 85       N_("SASL mechanism needs gsasl_server_callback_digest_md5() callback "
 86	  "(application error)")),
 87  OBS (21, GSASL_NEED_SERVER_EXTERNAL_CALLBACK,
 88       N_("SASL mechanism needs gsasl_server_callback_external() callback "
 89	  "(application error)")),
 90  OBS (22, GSASL_NEED_SERVER_ANONYMOUS_CALLBACK,
 91       N_("SASL mechanism needs gsasl_server_callback_anonymous() callback "
 92	  "(application error)")),
 93  OBS (23, GSASL_NEED_SERVER_REALM_CALLBACK,
 94       N_("SASL mechanism needs gsasl_server_callback_realm() callback "
 95	  "(application error)")),
 96  OBS (24, GSASL_NEED_SERVER_SECURID_CALLBACK,
 97       N_("SASL mechanism needs gsasl_server_callback_securid() callback "
 98	  "(application error)")),
 99  OBS (25, GSASL_NEED_SERVER_SERVICE_CALLBACK,
100       N_("SASL mechanism needs gsasl_server_callback_service() callback "
101	  "(application error)")),
102  OBS (26, GSASL_NEED_SERVER_GSSAPI_CALLBACK,
103       N_("SASL mechanism needs gsasl_server_callback_gssapi() callback "
104	  "(application error)")),
105  OBS (27, GSASL_NEED_SERVER_RETRIEVE_CALLBACK,
106       N_("SASL mechanism needs gsasl_server_callback_retrieve() callback "
107	  "(application error)")),
108  OBS (28, GSASL_UNICODE_NORMALIZATION_ERROR,
109       N_("Failed to perform Unicode Normalization on string.")),
110  ERR (GSASL_SASLPREP_ERROR,
111       N_("Could not prepare internationalized (non-ASCII) string.")),
112  ERR (GSASL_MECHANISM_PARSE_ERROR,
113       N_("SASL mechanism could not parse input")),
114  ERR (GSASL_AUTHENTICATION_ERROR, N_("Error authenticating user")),
115  OBS (32, GSASL_CANNOT_GET_CTX,
116       N_("Cannot get internal library handle (library error)")),
117  ERR (GSASL_INTEGRITY_ERROR, N_("Integrity error in application payload")),
118  OBS (34, GSASL_NO_MORE_REALMS, N_("No more realms available (non-fatal)")),
119  ERR (GSASL_NO_CLIENT_CODE,
120       N_("Client-side functionality not available in library "
121	  "(application error)")),
122  ERR (GSASL_NO_SERVER_CODE,
123       N_("Server-side functionality not available in library "
124	  "(application error)")),
125  ERR (GSASL_GSSAPI_RELEASE_BUFFER_ERROR,
126       N_("GSSAPI library could not deallocate memory in "
127	  "gss_release_buffer() in SASL library.  This is a serious "
128	  "internal error.")),
129  ERR (GSASL_GSSAPI_IMPORT_NAME_ERROR,
130       N_("GSSAPI library could not understand a peer name in "
131	  "gss_import_name() in SASL library.  This is most likely due "
132	  "to incorrect service and/or hostnames.")),
133  ERR (GSASL_GSSAPI_INIT_SEC_CONTEXT_ERROR,
134       N_("GSSAPI error in client while negotiating security context in "
135	  "gss_init_sec_context() in SASL library.  This is most likely "
136	  "due insufficient credentials or malicious interactions.")),
137  ERR (GSASL_GSSAPI_ACCEPT_SEC_CONTEXT_ERROR,
138       N_("GSSAPI error in server while negotiating security context in "
139	  "gss_init_sec_context() in SASL library.  This is most likely due "
140	  "insufficient credentials or malicious interactions.")),
141  ERR (GSASL_GSSAPI_UNWRAP_ERROR,
142       N_("GSSAPI error while decrypting or decoding data in gss_unwrap() in "
143	  "SASL library.  This is most likely due to data corruption.")),
144  ERR (GSASL_GSSAPI_WRAP_ERROR,
145       N_("GSSAPI error while encrypting or encoding data in gss_wrap() in "
146	  "SASL library.")),
147  ERR (GSASL_GSSAPI_ACQUIRE_CRED_ERROR,
148       N_("GSSAPI error acquiring credentials in gss_acquire_cred() in "
149	  "SASL library.  This is most likely due to not having the proper "
150	  "Kerberos key available in /etc/krb5.keytab on the server.")),
151  ERR (GSASL_GSSAPI_DISPLAY_NAME_ERROR,
152       N_("GSSAPI error creating a display name denoting the client in "
153	  "gss_display_name() in SASL library.  This is probably because "
154	  "the client supplied bad data.")),
155  ERR (GSASL_GSSAPI_UNSUPPORTED_PROTECTION_ERROR,
156       N_("Other entity requested integrity or confidentiality protection "
157	  "in GSSAPI mechanism but this is currently not implemented.")),
158  ERR (GSASL_KERBEROS_V5_INIT_ERROR,
159       N_("Kerberos V5 initialization failure.")),
160  ERR (GSASL_KERBEROS_V5_INTERNAL_ERROR,
161       N_("Kerberos V5 internal error.")),
162  ERR (GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE,
163       N_("SecurID needs additional passcode.")),
164  ERR (GSASL_SECURID_SERVER_NEED_NEW_PIN,
165       N_("SecurID needs new pin.")),
166  OBS (50, GSASL_INVALID_HANDLE,
167       N_("The provided library handle was invalid (application error)")),
168  ERR (GSASL_NO_CALLBACK,
169       N_("No callback specified by caller (application error).")),
170  ERR (GSASL_NO_ANONYMOUS_TOKEN,
171       N_("Authentication failed because the anonymous token was "
172	  "not provided.")),
173  ERR (GSASL_NO_AUTHID,
174       N_("Authentication failed because the authentication identity was "
175	  "not provided.")),
176  ERR (GSASL_NO_AUTHZID,
177       N_("Authentication failed because the authorization identity was "
178	  "not provided.")),
179  ERR (GSASL_NO_PASSWORD,
180       N_("Authentication failed because the password was not provided.")),
181  ERR (GSASL_NO_PASSCODE,
182       N_("Authentication failed because the passcode was not provided.")),
183  ERR (GSASL_NO_PIN,
184       N_("Authentication failed because the pin code was not provided.")),
185  ERR (GSASL_NO_SERVICE,
186       N_("Authentication failed because the service name was not provided.")),
187  ERR (GSASL_NO_HOSTNAME,
188       N_("Authentication failed because the host name was not provided."))
189};
190
191/**
192 * gsasl_strerror:
193 * @err: libgsasl error code
194 *
195 * Convert return code to human readable string explanation of the
196 * reason for the particular error code.
197 *
198 * This string can be used to output a diagnostic message to the user.
199 *
200 * Return value: Returns a pointer to a statically allocated string
201 *   containing an explanation of the error code @err.
202 **/
203const char *
204gsasl_strerror (int err)
205{
206  static const char *unknown = N_("Libgsasl unknown error");
207  const char *p;
208
209  bindtextdomain (PACKAGE, LOCALEDIR);
210
211  if (err < 0 || err >= (sizeof (errors) / sizeof (errors[0])))
212    return _(unknown);
213
214  p = errors[err].description;
215  if (!p)
216    p = unknown;
217
218  return _(p);
219}
220
221
222/**
223 * gsasl_strerror_name:
224 * @err: libgsasl error code
225 *
226 * Convert return code to human readable string representing the error
227 * code symbol itself.  For example, gsasl_strerror_name(%GSASL_OK)
228 * returns the string "GSASL_OK".
229 *
230 * This string can be used to output a diagnostic message to the user.
231 *
232 * Return value: Returns a pointer to a statically allocated string
233 *   containing a string version of the error code @err, or %NULL if
234 *   the error code is not known.
235 *
236 * Since: 0.2.29
237 **/
238const char *
239gsasl_strerror_name (int err)
240{
241  if (err < 0 || err >= (sizeof (errors) / sizeof (errors[0])))
242    return NULL;
243
244  return errors[err].name;
245}