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