gsasl  2.2.2
error.c
Go to the documentation of this file.
1 /* error.c --- Error handling functionality.
2  * Copyright (C) 2002-2025 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 along with GNU SASL Library; if not, see
18  * <https://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #include <config.h>
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 /* *INDENT-OFF* */
34 static struct
35 {
36  int rc;
37  const char *name;
38  const char *description;
39 } errors[] = {
40  ERR (GSASL_OK, N_("Libgsasl success")),
41  ERR (GSASL_NEEDS_MORE, N_("SASL mechanism needs more data")),
42  ERR (GSASL_UNKNOWN_MECHANISM, N_("Unknown SASL mechanism")),
44  N_("SASL mechanism called too many times")),
45  { 4, NULL, NULL },
46  { 5, NULL, NULL },
47  { 6, NULL, NULL },
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  { 11, NULL, NULL },
53  { 12, NULL, NULL },
54  { 13, NULL, NULL },
55  { 14, NULL, NULL },
56  { 15, NULL, NULL },
57  { 16, NULL, NULL },
58  { 17, NULL, NULL },
59  { 18, NULL, NULL },
60  { 19, NULL, NULL },
61  { 20, NULL, NULL },
62  { 21, NULL, NULL },
63  { 22, NULL, NULL },
64  { 23, NULL, NULL },
65  { 24, NULL, NULL },
66  { 25, NULL, NULL },
67  { 26, NULL, NULL },
68  { 27, NULL, NULL },
69  { 28, NULL, NULL },
71  N_("Could not prepare internationalized (non-ASCII) string.")),
73  N_("SASL mechanism could not parse input")),
74  ERR (GSASL_AUTHENTICATION_ERROR, N_("Error authenticating user")),
75  { 32, NULL, NULL },
76  ERR (GSASL_INTEGRITY_ERROR, N_("Integrity error in application payload")),
77  { 34, NULL, NULL },
79  N_("Client-side functionality not available in library "
80  "(application error)")),
82  N_("Server-side functionality not available in library "
83  "(application error)")),
85  N_("GSSAPI library could not deallocate memory in "
86  "gss_release_buffer() in SASL library. This is a serious "
87  "internal error.")),
89  N_("GSSAPI library could not understand a peer name in "
90  "gss_import_name() in SASL library. This is most likely due "
91  "to incorrect service and/or hostnames.")),
93  N_("GSSAPI error in client while negotiating security context in "
94  "gss_init_sec_context() in SASL library. This is most likely "
95  "due insufficient credentials or malicious interactions.")),
97  N_("GSSAPI error in server while negotiating security context in "
98  "gss_accept_sec_context() in SASL library. This is most likely due "
99  "insufficient credentials or malicious interactions.")),
101  N_("GSSAPI error while decrypting or decoding data in gss_unwrap() in "
102  "SASL library. This is most likely due to data corruption.")),
104  N_("GSSAPI error while encrypting or encoding data in gss_wrap() in "
105  "SASL library.")),
107  N_("GSSAPI error acquiring credentials in gss_acquire_cred() in "
108  "SASL library. This is most likely due to not having the proper "
109  "Kerberos key available in /etc/krb5.keytab on the server.")),
111  N_("GSSAPI error creating a display name denoting the client in "
112  "gss_display_name() in SASL library. This is probably because "
113  "the client supplied bad data.")),
115  N_("Other entity requested integrity or confidentiality protection "
116  "in GSSAPI mechanism but this is currently not implemented.")),
117  { 46, NULL, NULL },
118  { 47, NULL, NULL },
120  N_("SecurID needs additional passcode.")),
122  N_("SecurID needs new pin.")),
123  { 50, NULL, NULL },
125  N_("No callback specified by caller (application error).")),
127  N_("Authentication failed because the anonymous token was "
128  "not provided.")),
130  N_("Authentication failed because the authentication identity was "
131  "not provided.")),
133  N_("Authentication failed because the authorization identity was "
134  "not provided.")),
136  N_("Authentication failed because the password was not provided.")),
138  N_("Authentication failed because the passcode was not provided.")),
139  ERR (GSASL_NO_PIN,
140  N_("Authentication failed because the pin code was not provided.")),
142  N_("Authentication failed because the service name was not provided.")),
144  N_("Authentication failed because the host name was not provided.")),
146  N_("GSSAPI error encapsulating token.")),
148  N_("GSSAPI error decapsulating token.")),
150  N_("GSSAPI error getting OID for SASL mechanism name.")),
152  N_("GSSAPI error testing for OID in OID set.")),
154  N_("GSSAPI error releasing OID set.")),
156  N_("Authentication failed because a tls-unique CB was not provided.")),
158  N_("Callback failed to provide SAML20 IdP identifier.")),
160  N_("Callback failed to provide SAML20 redirect URL.")),
162  N_("Callback failed to provide OPENID20 redirect URL.")),
164  N_("Authentication failed because a tls-exporter channel binding was not provided."))
165 };
166 /* *INDENT-ON* */
167 
183 const char *
184 gsasl_strerror (int err)
185 {
186  static const char *unknown = N_("Libgsasl unknown error");
187  const char *p;
188 
189  bindtextdomain (PACKAGE, LOCALEDIR);
190 
191  if (err < 0 || err >= (int) (sizeof (errors) / sizeof (errors[0])))
192  return _(unknown);
193 
194  p = errors[err].description;
195  if (!p)
196  p = unknown;
197 
198  return _(p);
199 }
200 
201 
221 const char *
223 {
224  if (err < 0 || err >= (int) (sizeof (errors) / sizeof (errors[0])))
225  return NULL;
226 
227  return errors[err].name;
228 }
#define _(String)
Definition: error.c:27
const char * description
Definition: error.c:38
#define N_(String)
Definition: error.c:29
const char * name
Definition: error.c:37
#define ERR(name, desc)
Definition: error.c:31
const char * gsasl_strerror(int err)
Definition: error.c:184
int rc
Definition: error.c:36
const char * gsasl_strerror_name(int err)
Definition: error.c:222
@ GSASL_GSSAPI_UNWRAP_ERROR
Definition: gsasl.h:160
@ GSASL_NO_CLIENT_CODE
Definition: gsasl.h:139
@ GSASL_NO_CALLBACK
Definition: gsasl.h:141
@ GSASL_GSSAPI_IMPORT_NAME_ERROR
Definition: gsasl.h:157
@ GSASL_GSSAPI_RELEASE_OID_SET_ERROR
Definition: gsasl.h:171
@ GSASL_OK
Definition: gsasl.h:128
@ GSASL_SECURID_SERVER_NEED_ADDITIONAL_PASSCODE
Definition: gsasl.h:165
@ GSASL_GSSAPI_RELEASE_BUFFER_ERROR
Definition: gsasl.h:156
@ GSASL_NO_CB_TLS_EXPORTER
Definition: gsasl.h:154
@ GSASL_GSSAPI_ACCEPT_SEC_CONTEXT_ERROR
Definition: gsasl.h:159
@ GSASL_BASE64_ERROR
Definition: gsasl.h:133
@ GSASL_NO_OPENID20_REDIRECT_URL
Definition: gsasl.h:153
@ GSASL_SECURID_SERVER_NEED_NEW_PIN
Definition: gsasl.h:166
@ GSASL_GSSAPI_INQUIRE_MECH_FOR_SASLNAME_ERROR
Definition: gsasl.h:169
@ GSASL_AUTHENTICATION_ERROR
Definition: gsasl.h:137
@ GSASL_NEEDS_MORE
Definition: gsasl.h:129
@ GSASL_GSSAPI_TEST_OID_SET_MEMBER_ERROR
Definition: gsasl.h:170
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:132
@ GSASL_NO_PASSWORD
Definition: gsasl.h:145
@ GSASL_NO_SAML20_IDP_IDENTIFIER
Definition: gsasl.h:151
@ GSASL_GSSAPI_DISPLAY_NAME_ERROR
Definition: gsasl.h:163
@ GSASL_NO_PASSCODE
Definition: gsasl.h:146
@ GSASL_NO_SERVICE
Definition: gsasl.h:148
@ GSASL_GSSAPI_ENCAPSULATE_TOKEN_ERROR
Definition: gsasl.h:167
@ GSASL_NO_AUTHZID
Definition: gsasl.h:144
@ GSASL_GSSAPI_ACQUIRE_CRED_ERROR
Definition: gsasl.h:162
@ GSASL_MECHANISM_CALLED_TOO_MANY_TIMES
Definition: gsasl.h:131
@ GSASL_NO_HOSTNAME
Definition: gsasl.h:149
@ GSASL_NO_AUTHID
Definition: gsasl.h:143
@ GSASL_GSSAPI_WRAP_ERROR
Definition: gsasl.h:161
@ GSASL_MECHANISM_PARSE_ERROR
Definition: gsasl.h:136
@ GSASL_NO_PIN
Definition: gsasl.h:147
@ GSASL_CRYPTO_ERROR
Definition: gsasl.h:134
@ GSASL_SASLPREP_ERROR
Definition: gsasl.h:135
@ GSASL_GSSAPI_DECAPSULATE_TOKEN_ERROR
Definition: gsasl.h:168
@ GSASL_NO_ANONYMOUS_TOKEN
Definition: gsasl.h:142
@ GSASL_NO_SERVER_CODE
Definition: gsasl.h:140
@ GSASL_NO_SAML20_REDIRECT_URL
Definition: gsasl.h:152
@ GSASL_INTEGRITY_ERROR
Definition: gsasl.h:138
@ GSASL_UNKNOWN_MECHANISM
Definition: gsasl.h:130
@ GSASL_GSSAPI_INIT_SEC_CONTEXT_ERROR
Definition: gsasl.h:158
@ GSASL_NO_CB_TLS_UNIQUE
Definition: gsasl.h:150
@ GSASL_GSSAPI_UNSUPPORTED_PROTECTION_ERROR
Definition: gsasl.h:164