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
24 struct shishi_error_msgs
30 struct shishi_error_msgs _shishi_error_messages
[] = {
34 "Error in ASN.1 data, probably due to corrupt data."},
36 "Could not open file."},
38 "Could not close file."},
40 "Memory allocation error in shishi library."},
42 "Base64 encoding or decoding failed. Data corrupt?"},
43 {SHISHI_REALM_MISMATCH
,
44 "Client realm value differ between request and reply."},
45 {SHISHI_CNAME_MISMATCH
,
46 "Client name value differ between request and reply."},
47 {SHISHI_NONCE_MISMATCH
,
48 "Replay protection value (nonce) differ between request and reply."},
49 {SHISHI_TICKET_BAD_KEYTYPE
,
50 "Keytype used to encrypt ticket doesn't match provided key. "
51 "This usually indicates an internal application error."},
52 {SHISHI_CRYPTO_INTERNAL_ERROR
,
53 "Internal error in low-level crypto routines."},
55 "Low-level cryptographic primitive failed. This usually indicates "
56 "bad password or data corruption."},
58 "Timedout talking to KDC. This usually indicates a network "
59 "or KDC address problem."},
60 {SHISHI_KDC_NOT_KNOWN_FOR_REALM
,
61 "No KDC for realm known."},
63 "The system call socket() failed. This usually indicates that "
64 "your system does not support the socket type."},
66 "The system call bind() failed. This usually indicates "
67 "insufficient permissions."},
69 "The system call sendto() failed."},
71 "The system call close() failed."},
73 "Server replied with an error message to request."},
75 "Ticketset not initialized. This usually indicates an internal "
76 "application error."},
77 {SHISHI_APREQ_DECRYPT_FAILED
,
78 "Could not decrypt AP-REQ using provided key. "
79 "This usually indicates an internal application error."},
80 {SHISHI_TICKET_DECRYPT_FAILED
,
81 "Could not decrypt Ticket using provided key. "
82 "This usually indicates an internal application error."},
88 * @err: shishi error code
90 * Return value: Returns a pointer to a statically allocated string
91 * containing a description of the error with the error value @err.
92 * This string can be used to output a diagnostic message to the user.
95 shishi_strerror (int err
)
100 for (i
= 0; _shishi_error_messages
[i
].errorcode
!= -1; i
++)
101 if (_shishi_error_messages
[i
].errorcode
== err
)
103 p
= _(_shishi_error_messages
[i
].message
);
109 asprintf (&p
, _("Unknown shishi error: %d"), err
);
117 * @handle: shishi handle as allocated by shishi_init().
119 * Extract detailed error information string. Note that the memory is
120 * managed by the Shishi library, so you must not deallocate the
123 * Return value: Returns pointer to error information string, that must
124 * not be deallocate by caller.
127 shishi_error (Shishi
* handle
)
130 return handle
->error
;
136 * shishi_error_clear:
137 * @handle: shishi handle as allocated by shishi_init().
139 * Clear the detailed error information string. See shishi_error()
140 * for how to access the error string, and shishi_error_set() and
141 * shishi_error_printf() for how to set the error string. This
142 * function is mostly for Shishi internal use, but if you develop an
143 * extension of Shishi, it may be useful to use the same error
144 * handling infrastructure.
147 shishi_error_clear (Shishi
* handle
)
149 handle
->error
[0] = '\0';
154 * @handle: shishi handle as allocated by shishi_init().
155 * @error: Zero terminated character array containing error description,
156 * or NULL to clear the error description string.
158 * Set the detailed error information string to specified string. The
159 * string is copied into the Shishi internal structure, so you can
160 * deallocate the string passed to this function after the call. This
161 * function is mostly for Shishi internal use, but if you develop an
162 * extension of Shishi, it may be useful to use the same error
163 * handling infrastructure.
166 shishi_error_set (Shishi
* handle
, const char *error
)
170 strncpy (handle
->error
, error
, sizeof (handle
->error
));
172 if (VERBOSE (handle
))
173 puts (handle
->error
);
176 shishi_error_clear (handle
);
180 * shishi_error_printf:
181 * @handle: shishi handle as allocated by shishi_init().
182 * @format: printf style format string.
183 * @...: print style arguments.
185 * Set the detailed error information string to a printf formatted
186 * string. This function is mostly for Shishi internal use, but if
187 * you develop an extension of Shishi, it may be useful to use the
188 * same error handling infrastructure.
191 shishi_error_printf (Shishi
* handle
, const char *format
, ...)
196 va_start (ap
, format
);
198 vasprintf (&s
, format
, ap
);
199 strncpy (handle
->error
, s
, sizeof (handle
->error
));
200 handle
->error
[sizeof (handle
->error
) - 1] = '\0';
203 if (VERBOSE (handle
))
204 puts (handle
->error
);
211 * @handle: shishi handle as allocated by shishi_init().
213 * Return output type (NULL, stderr or syslog) for informational
214 * and warning messages.
217 shishi_outputtype (Shishi
* handle
)
219 return handle
->outputtype
;
223 * shishi_set_outputtype:
224 * @handle: shishi handle as allocated by shishi_init().
225 * @type: output type.
227 * Set output type (NULL, stderr or syslog) for informational
228 * and warning messages.
231 shishi_set_outputtype (Shishi
* handle
, int type
)
233 handle
->outputtype
= type
;
236 #define INFOSTR "libshishi: info: "
237 #define WARNSTR "libshishi: warning: "
241 * @handle: shishi handle as allocated by shishi_init().
242 * @format: printf style format string.
243 * @...: print style arguments.
245 * Print informational message to output as defined in handle.
248 shishi_info (Shishi
* handle
, const char *format
, ...)
254 va_start (ap
, format
);
255 vasprintf (&out
, format
, ap
);
257 type
= shishi_outputtype (handle
);
260 case SHISHI_OUTPUTTYPE_STDERR
:
261 fprintf (stderr
, "%s%s\n", INFOSTR
, out
);
263 case SHISHI_OUTPUTTYPE_SYSLOG
:
264 syslog (LOG_ERR
, "%s%s", INFOSTR
, out
);
276 * @handle: shishi handle as allocated by shishi_init().
277 * @format: printf style format string.
278 * @...: print style arguments.
280 * Print a warning to output as defined in handle.
283 shishi_warn (Shishi
* handle
, const char *format
, ...)
289 va_start (ap
, format
);
290 vasprintf (&out
, format
, ap
);
292 type
= shishi_outputtype (handle
);
295 case SHISHI_OUTPUTTYPE_STDERR
:
296 fprintf (stderr
, "%s%s\n", WARNSTR
, out
);
298 case SHISHI_OUTPUTTYPE_SYSLOG
:
299 syslog (LOG_ERR
, "%s%s", WARNSTR
, out
);