Build gl/m4/Makefile.
[shishi.git] / lib / error.c
blobfbc51ae96aa75d382cb6b3dfd4e2105587b704a0
1 /* error.c error handling functions
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Shishi 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "internal.h"
24 const char *
25 shishi_strerror_details (Shishi * handle)
27 return handle->error ? handle->
28 error :
29 "Internal application error: shishi_strerror() called without an "
30 "error condition";
33 /**
34 * shishi_strerror:
35 * @err: shishi error code
37 * Return value: Returns a pointer to a statically allocated string
38 * containing a description of the error with the error value @err.
39 * This string can be used to output a diagnostic message to the user.
40 **/
41 const char *
42 shishi_strerror (int err)
44 char *p;
46 switch (err)
48 case SHISHI_OK:
49 p = _("Shishi success");
50 break;
52 case SHISHI_MALLOC_ERROR:
53 p = _("Memory allocation error in shishi library.");
54 break;
56 case SHISHI_BASE64_ERROR:
57 p = _("Base64 encoding or decoding failed. This usually means the "
58 "data is corrupt.");
59 break;
61 case SHISHI_FOPEN_ERROR:
62 p = _("Could not open file.");
63 break;
65 case SHISHI_FCLOSE_ERROR:
66 p = _("Could not close file.");
67 break;
69 case SHISHI_GCRYPT_ERROR:
70 p = _("Internal libgcrypt error.");
71 break;
73 case SHISHI_NONCE_MISMATCH:
74 p =
76 ("Replay protection value (nonce) differ between request and reply.");
77 break;
79 case SHISHI_REALM_MISMATCH:
80 p = _("Client realm value differ between request and reply.");
81 break;
83 case SHISHI_CNAME_MISMATCH:
84 p = _("Client name value differ between request and reply.");
85 break;
87 case SHISHI_ASN1_ERROR:
88 p = _("Error in ASN.1 data, probably due to corrupt data.");
89 break;
91 case SHISHI_CRYPTO_ERROR:
92 p =
94 ("Low-level cryptographic primitive failed. This usually indicates "
95 "bad password or data corruption.");
96 break;
98 case SHISHI_KDC_TIMEOUT:
99 p = _("Timedout talking to KDC. This usually indicates a network "
100 "or KDC address problem.");
101 break;
103 case SHISHI_KDC_NOT_KNOWN_FOR_REALM:
104 p = _("No KDC for realm known.");
105 break;
107 case SHISHI_SOCKET_ERROR:
108 p = _("The system call socket() failed. This usually indicates that "
109 "your system does not support the socket type.");
110 break;
112 case SHISHI_BIND_ERROR:
113 p = _("The system call bind() failed. This usually indicates "
114 "insufficient permissions.");
115 break;
117 case SHISHI_SENDTO_ERROR:
118 p = _("The system call sendto() failed.");
119 break;
121 case SHISHI_CLOSE_ERROR:
122 p = _("The system call close() failed.");
123 break;
125 case SHISHI_GOT_KRBERROR:
126 p = _("Server replied with an error message to request.");
127 break;
129 case SHISHI_INVALID_TKTS:
130 p = _("Ticketset not initialized. This usually indicates an internal "
131 "application error.");
132 break;
134 case SHISHI_TICKET_BAD_KEYTYPE:
135 p = _("Keytype used to encrypt ticket doesn't match provided key. "
136 "This usually indicates an internal application error.");
137 break;
139 case SHISHI_APREQ_DECRYPT_FAILED:
140 p = _("Could not decrypt AP-REQ using provided key. "
141 "This usually indicates an internal application error.");
142 break;
144 case SHISHI_TICKET_DECRYPT_FAILED:
145 p = _("Could not decrypt Ticket using provided key. "
146 "This usually indicates an internal application error.");
147 break;
149 default:
150 asprintf (&p, _("Unknown shishi error (%d)"), err);
151 break;
154 return p;
158 void
159 shishi_error_clear (Shishi * handle)
161 handle->error[0] = '\0';
164 void
165 shishi_error_set (Shishi * handle, const char *error)
167 if (error)
168 strncpy (handle->error, error, sizeof (handle->error));
169 else
170 shishi_error_clear (handle);
173 void
174 shishi_error_printf (Shishi * handle, char *format, ...)
176 va_list ap;
178 va_start (ap, format);
180 vsnprintf (handle->error, sizeof (handle->error), format, ap);