gsasl  1.10.0
About: GNU SASL is an implementation of the Simple Authentication and Security Layer (SASL). Development version.
  Fossies Dox: gsasl-1.10.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

error.c
Go to the documentation of this file.
1 /* error.c --- Error handling functionality.
2  * Copyright (C) 2002-2021 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 
39 /* *INDENT-OFF* */
40 static struct
41 {
42  int rc;
43  const char *name;
44  const char *description;
45 } errors[] = {
46  ERR (GSASL_OK, N_("Libgsasl success")),
47  ERR (GSASL_NEEDS_MORE, N_("SASL mechanism needs more data")),
48  ERR (GSASL_UNKNOWN_MECHANISM, N_("Unknown SASL mechanism")),
50  N_("SASL mechanism called too many times")),
52  N_("SASL function needs larger buffer (internal error)")),
53  OBS (5, GSASL_FOPEN_ERROR, N_("Could not open file in SASL library")),
54  OBS (6, GSASL_FCLOSE_ERROR, N_("Could not close file in SASL library")),
55  ERR (GSASL_MALLOC_ERROR, N_("Memory allocation error in SASL library")),
56  ERR (GSASL_BASE64_ERROR, N_("Base 64 coding error in SASL library")),
57  ERR (GSASL_CRYPTO_ERROR, N_("Low-level crypto error in SASL library")),
58  { 10, NULL, NULL },
60  N_("SASL mechanism needs gsasl_client_callback_anonymous() callback"
61  " (application error)")),
63  N_("SASL mechanism needs gsasl_client_callback_password() callback"
64  " (application error)")),
66  N_("SASL mechanism needs gsasl_client_callback_passcode() callback"
67  " (application error)")),
69  N_("SASL mechanism needs gsasl_client_callback_pin() callback"
70  " (application error)")),
72  N_("SASL mechanism needs gsasl_client_callback_authorization_id() "
73  "callback (application error)")),
75  N_("SASL mechanism needs gsasl_client_callback_authentication_id() "
76  "callback (application error)")),
78  N_("SASL mechanism needs gsasl_client_callback_service() callback "
79  "(application error)")),
81  N_("SASL mechanism needs gsasl_server_callback_validate() callback "
82  "(application error)")),
84  N_("SASL mechanism needs gsasl_server_callback_cram_md5() callback "
85  "(application error)")),
87  N_("SASL mechanism needs gsasl_server_callback_digest_md5() callback "
88  "(application error)")),
90  N_("SASL mechanism needs gsasl_server_callback_external() callback "
91  "(application error)")),
93  N_("SASL mechanism needs gsasl_server_callback_anonymous() callback "
94  "(application error)")),
96  N_("SASL mechanism needs gsasl_server_callback_realm() callback "
97  "(application error)")),
99  N_("SASL mechanism needs gsasl_server_callback_securid() callback "
100  "(application error)")),
102  N_("SASL mechanism needs gsasl_server_callback_service() callback "
103  "(application error)")),
105  N_("SASL mechanism needs gsasl_server_callback_gssapi() callback "
106  "(application error)")),
108  N_("SASL mechanism needs gsasl_server_callback_retrieve() callback "
109  "(application error)")),
111  N_("Failed to perform Unicode Normalization on string.")),
113  N_("Could not prepare internationalized (non-ASCII) string.")),
115  N_("SASL mechanism could not parse input")),
116  ERR (GSASL_AUTHENTICATION_ERROR, N_("Error authenticating user")),
118  N_("Cannot get internal library handle (library error)")),
119  ERR (GSASL_INTEGRITY_ERROR, N_("Integrity error in application payload")),
120  OBS (34, GSASL_NO_MORE_REALMS, N_("No more realms available (non-fatal)")),
122  N_("Client-side functionality not available in library "
123  "(application error)")),
125  N_("Server-side functionality not available in library "
126  "(application error)")),
128  N_("GSSAPI library could not deallocate memory in "
129  "gss_release_buffer() in SASL library. This is a serious "
130  "internal error.")),
132  N_("GSSAPI library could not understand a peer name in "
133  "gss_import_name() in SASL library. This is most likely due "
134  "to incorrect service and/or hostnames.")),
136  N_("GSSAPI error in client while negotiating security context in "
137  "gss_init_sec_context() in SASL library. This is most likely "
138  "due insufficient credentials or malicious interactions.")),
140  N_("GSSAPI error in server while negotiating security context in "
141  "gss_accept_sec_context() in SASL library. This is most likely due "
142  "insufficient credentials or malicious interactions.")),
144  N_("GSSAPI error while decrypting or decoding data in gss_unwrap() in "
145  "SASL library. This is most likely due to data corruption.")),
147  N_("GSSAPI error while encrypting or encoding data in gss_wrap() in "
148  "SASL library.")),
150  N_("GSSAPI error acquiring credentials in gss_acquire_cred() in "
151  "SASL library. This is most likely due to not having the proper "
152  "Kerberos key available in /etc/krb5.keytab on the server.")),
154  N_("GSSAPI error creating a display name denoting the client in "
155  "gss_display_name() in SASL library. This is probably because "
156  "the client supplied bad data.")),
158  N_("Other entity requested integrity or confidentiality protection "
159  "in GSSAPI mechanism but this is currently not implemented.")),
161  N_("Kerberos V5 initialization failure.")),
163  N_("Kerberos V5 internal error.")),
165  N_("SecurID needs additional passcode.")),
167  N_("SecurID needs new pin.")),
169  N_("The provided library handle was invalid (application error)")),
171  N_("No callback specified by caller (application error).")),
173  N_("Authentication failed because the anonymous token was "
174  "not provided.")),
176  N_("Authentication failed because the authentication identity was "
177  "not provided.")),
179  N_("Authentication failed because the authorization identity was "
180  "not provided.")),
182  N_("Authentication failed because the password was not provided.")),
184  N_("Authentication failed because the passcode was not provided.")),
185  ERR (GSASL_NO_PIN,
186  N_("Authentication failed because the pin code was not provided.")),
188  N_("Authentication failed because the service name was not provided.")),
190  N_("Authentication failed because the host name was not provided.")),
192  N_("GSSAPI error encapsulating token.")),
194  N_("GSSAPI error decapsulating token.")),
196  N_("GSSAPI error getting OID for SASL mechanism name.")),
198  N_("GSSAPI error testing for OID in OID set.")),
200  N_("GSSAPI error releasing OID set.")),
202  N_("Authentication failed because a tls-unique CB was not provided.")),
204  N_("Callback failed to provide SAML20 IdP identifier.")),
206  N_("Callback failed to provide SAML20 redirect URL.")),
208  N_("Callback failed to provide OPENID20 redirect URL."))
209 };
210 /* *INDENT-ON* */
211 
212 /**
213  * gsasl_strerror:
214  * @err: libgsasl error code
215  *
216  * Convert return code to human readable string explanation of the
217  * reason for the particular error code.
218  *
219  * This string can be used to output a diagnostic message to the user.
220  *
221  * This function is one of few in the library that can be used without
222  * a successful call to gsasl_init().
223  *
224  * Return value: Returns a pointer to a statically allocated string
225  * containing an explanation of the error code @err.
226  **/
227 const char *
228 gsasl_strerror (int err)
229 {
230  static const char *unknown = N_("Libgsasl unknown error");
231  const char *p;
232 
234 
235  if (err < 0 || err >= (int) (sizeof (errors) / sizeof (errors[0])))
236  return _(unknown);
237 
238  p = errors[err].description;
239  if (!p)
240  p = unknown;
241 
242  return _(p);
243 }
244 
245 
246 /**
247  * gsasl_strerror_name:
248  * @err: libgsasl error code
249  *
250  * Convert return code to human readable string representing the error
251  * code symbol itself. For example, gsasl_strerror_name(%GSASL_OK)
252  * returns the string "GSASL_OK".
253  *
254  * This string can be used to output a diagnostic message to the user.
255  *
256  * This function is one of few in the library that can be used without
257  * a successful call to gsasl_init().
258  *
259  * Return value: Returns a pointer to a statically allocated string
260  * containing a string version of the error code @err, or NULL if
261  * the error code is not known.
262  *
263  * Since: 0.2.29
264  **/
265 const char *
267 {
268  if (err < 0 || err >= (int) (sizeof (errors) / sizeof (errors[0])))
269  return NULL;
270 
271  return errors[err].name;
272 }
#define LOCALEDIR
Definition: config.h:8
#define PACKAGE
Definition: config.h:7
#define bindtextdomain(Domainname, Dirname)
Definition: gettext.h:88
#define NULL
Definition: stddef.in.h:72
@ GSASL_CANNOT_GET_CTX
Definition: gsasl-compat.h:40
@ GSASL_TOO_SMALL_BUFFER
Definition: gsasl-compat.h:36
@ GSASL_NEED_CLIENT_AUTHORIZATION_ID_CALLBACK
Definition: gsasl-compat.h:45
@ GSASL_NEED_CLIENT_AUTHENTICATION_ID_CALLBACK
Definition: gsasl-compat.h:46
@ GSASL_NEED_SERVER_EXTERNAL_CALLBACK
Definition: gsasl-compat.h:51
@ GSASL_INVALID_HANDLE
Definition: gsasl-compat.h:60
@ GSASL_NEED_SERVER_SECURID_CALLBACK
Definition: gsasl-compat.h:54
@ GSASL_NEED_SERVER_GSSAPI_CALLBACK
Definition: gsasl-compat.h:56
@ GSASL_NO_MORE_REALMS
Definition: gsasl-compat.h:59
@ GSASL_NEED_CLIENT_PASSCODE_CALLBACK
Definition: gsasl-compat.h:43
@ GSASL_UNICODE_NORMALIZATION_ERROR
Definition: gsasl-compat.h:58
@ GSASL_NEED_CLIENT_SERVICE_CALLBACK
Definition: gsasl-compat.h:47
@ GSASL_NEED_SERVER_RETRIEVE_CALLBACK
Definition: gsasl-compat.h:57
@ GSASL_NEED_SERVER_ANONYMOUS_CALLBACK
Definition: gsasl-compat.h:52
@ GSASL_FOPEN_ERROR
Definition: gsasl-compat.h:37
@ GSASL_NEED_CLIENT_PIN_CALLBACK
Definition: gsasl-compat.h:44
@ GSASL_NEED_SERVER_SERVICE_CALLBACK
Definition: gsasl-compat.h:55
@ GSASL_NEED_SERVER_VALIDATE_CALLBACK
Definition: gsasl-compat.h:48
@ GSASL_NEED_SERVER_CRAM_MD5_CALLBACK
Definition: gsasl-compat.h:49
@ GSASL_NEED_SERVER_DIGEST_MD5_CALLBACK
Definition: gsasl-compat.h:50
@ GSASL_NEED_SERVER_REALM_CALLBACK
Definition: gsasl-compat.h:53
@ GSASL_NEED_CLIENT_ANONYMOUS_CALLBACK
Definition: gsasl-compat.h:41
@ GSASL_NEED_CLIENT_PASSWORD_CALLBACK
Definition: gsasl-compat.h:42
@ GSASL_FCLOSE_ERROR
Definition: gsasl-compat.h:38
@ GSASL_GSSAPI_UNWRAP_ERROR
Definition: gsasl.h:202
@ GSASL_NO_CLIENT_CODE
Definition: gsasl.h:182
@ GSASL_NO_CALLBACK
Definition: gsasl.h:184
@ GSASL_GSSAPI_IMPORT_NAME_ERROR
Definition: gsasl.h:199
@ GSASL_GSSAPI_RELEASE_OID_SET_ERROR
Definition: gsasl.h:216
@ GSASL_KERBEROS_V5_INIT_ERROR
Definition: gsasl.h:207
@ GSASL_OK
Definition: gsasl.h:171
@ GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE
Definition: gsasl.h:210
@ GSASL_GSSAPI_RELEASE_BUFFER_ERROR
Definition: gsasl.h:198
@ GSASL_GSSAPI_ACCEPT_SEC_CONTEXT_ERROR
Definition: gsasl.h:201
@ GSASL_BASE64_ERROR
Definition: gsasl.h:176
@ GSASL_NO_OPENID20_REDIRECT_URL
Definition: gsasl.h:196
@ GSASL_SECURID_SERVER_NEED_NEW_PIN
Definition: gsasl.h:211
@ GSASL_GSSAPI_INQUIRE_MECH_FOR_SASLNAME_ERROR
Definition: gsasl.h:214
@ GSASL_AUTHENTICATION_ERROR
Definition: gsasl.h:180
@ GSASL_NEEDS_MORE
Definition: gsasl.h:172
@ GSASL_GSSAPI_TEST_OID_SET_MEMBER_ERROR
Definition: gsasl.h:215
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:175
@ GSASL_NO_PASSWORD
Definition: gsasl.h:188
@ GSASL_NO_SAML20_IDP_IDENTIFIER
Definition: gsasl.h:194
@ GSASL_GSSAPI_DISPLAY_NAME_ERROR
Definition: gsasl.h:205
@ GSASL_NO_PASSCODE
Definition: gsasl.h:189
@ GSASL_NO_SERVICE
Definition: gsasl.h:191
@ GSASL_GSSAPI_ENCAPSULATE_TOKEN_ERROR
Definition: gsasl.h:212
@ GSASL_NO_AUTHZID
Definition: gsasl.h:187
@ GSASL_GSSAPI_ACQUIRE_CRED_ERROR
Definition: gsasl.h:204
@ GSASL_MECHANISM_CALLED_TOO_MANY_TIMES
Definition: gsasl.h:174
@ GSASL_NO_HOSTNAME
Definition: gsasl.h:192
@ GSASL_NO_AUTHID
Definition: gsasl.h:186
@ GSASL_GSSAPI_WRAP_ERROR
Definition: gsasl.h:203
@ GSASL_MECHANISM_PARSE_ERROR
Definition: gsasl.h:179
@ GSASL_NO_PIN
Definition: gsasl.h:190
@ GSASL_CRYPTO_ERROR
Definition: gsasl.h:177
@ GSASL_SASLPREP_ERROR
Definition: gsasl.h:178
@ GSASL_GSSAPI_DECAPSULATE_TOKEN_ERROR
Definition: gsasl.h:213
@ GSASL_NO_ANONYMOUS_TOKEN
Definition: gsasl.h:185
@ GSASL_NO_SERVER_CODE
Definition: gsasl.h:183
@ GSASL_NO_SAML20_REDIRECT_URL
Definition: gsasl.h:195
@ GSASL_KERBEROS_V5_INTERNAL_ERROR
Definition: gsasl.h:208
@ GSASL_INTEGRITY_ERROR
Definition: gsasl.h:181
@ GSASL_UNKNOWN_MECHANISM
Definition: gsasl.h:173
@ GSASL_GSSAPI_INIT_SEC_CONTEXT_ERROR
Definition: gsasl.h:200
@ GSASL_NO_CB_TLS_UNIQUE
Definition: gsasl.h:193
@ GSASL_GSSAPI_UNSUPPORTED_PROTECTION_ERROR
Definition: gsasl.h:206
#define _(String)
Definition: error.c:27
#define OBS(i, name, desc)
Definition: error.c:36
const char * description
Definition: error.c:44
#define N_(String)
Definition: error.c:29
const char * name
Definition: error.c:43
#define ERR(name, desc)
Definition: error.c:31
const char * gsasl_strerror(int err)
Definition: error.c:228
static struct @21 errors[]
int rc
Definition: error.c:42
const char * gsasl_strerror_name(int err)
Definition: error.c:266
const char * p
Definition: mbrtowc-impl.h:42