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
25 shishi_strerror_details (Shishi
* handle
)
27 return handle
->error
? handle
->
29 "Internal application error: shishi_strerror() called without an "
33 struct shishi_error_msgs
39 struct shishi_error_msgs _shishi_error_messages
[] = {
43 "Error in ASN.1 data, probably due to corrupt data." },
45 "Could not open file." },
46 { SHISHI_FCLOSE_ERROR
,
47 "Could not close file." },
48 { SHISHI_MALLOC_ERROR
,
49 "Memory allocation error in shishi library." },
50 { SHISHI_BASE64_ERROR
,
51 "Base64 encoding or decoding failed. Data corrupt?" },
52 { SHISHI_REALM_MISMATCH
,
53 "Client realm value differ between request and reply." },
54 { SHISHI_CNAME_MISMATCH
,
55 "Client name value differ between request and reply." },
56 { SHISHI_NONCE_MISMATCH
,
57 "Replay protection value (nonce) differ between request and reply." },
58 { SHISHI_TICKET_BAD_KEYTYPE
,
59 "Keytype used to encrypt ticket doesn't match provided key. "
60 "This usually indicates an internal application error." },
61 { SHISHI_CRYPTO_INTERNAL_ERROR
,
62 "Internal error in low-level crypto routines." },
63 { SHISHI_CRYPTO_ERROR
,
64 "Low-level cryptographic primitive failed. This usually indicates "
65 "bad password or data corruption." },
67 "Timedout talking to KDC. This usually indicates a network "
68 "or KDC address problem." },
69 { SHISHI_KDC_NOT_KNOWN_FOR_REALM
,
70 "No KDC for realm known." },
71 { SHISHI_SOCKET_ERROR
,
72 "The system call socket() failed. This usually indicates that "
73 "your system does not support the socket type." },
75 "The system call bind() failed. This usually indicates "
76 "insufficient permissions." },
77 { SHISHI_SENDTO_ERROR
,
78 "The system call sendto() failed." },
80 "The system call close() failed." },
81 { SHISHI_GOT_KRBERROR
,
82 "Server replied with an error message to request." },
83 { SHISHI_INVALID_TKTS
,
84 "Ticketset not initialized. This usually indicates an internal "
85 "application error." },
86 { SHISHI_APREQ_DECRYPT_FAILED
,
87 "Could not decrypt AP-REQ using provided key. "
88 "This usually indicates an internal application error." },
89 { SHISHI_TICKET_DECRYPT_FAILED
,
90 "Could not decrypt Ticket using provided key. "
91 "This usually indicates an internal application error." },
97 * @err: shishi error code
99 * Return value: Returns a pointer to a statically allocated string
100 * containing a description of the error with the error value @err.
101 * This string can be used to output a diagnostic message to the user.
104 shishi_strerror (int err
)
109 for (i
= 0; _shishi_error_messages
[i
].errorcode
!= -1; i
++)
110 if (_shishi_error_messages
[i
].errorcode
== err
)
112 p
= _(_shishi_error_messages
[i
].message
);
118 asprintf(&p
, _("Unknown shishi error: %d"), err
);
125 shishi_error_clear (Shishi
* handle
)
127 handle
->error
[0] = '\0';
131 shishi_error_set (Shishi
* handle
, const char *error
)
135 strncpy (handle
->error
, error
, sizeof (handle
->error
));
137 if (VERBOSE (handle
))
138 puts (handle
->error
);
141 shishi_error_clear (handle
);
145 shishi_error_printf (Shishi
* handle
, char *format
, ...)
150 va_start (ap
, format
);
152 vasprintf (&s
, format
, ap
);
153 strncpy (handle
->error
, s
, sizeof (handle
->error
));
154 handle
->error
[sizeof (handle
->error
) - 1] = '\0';
157 if (VERBOSE (handle
))
158 puts (handle
->error
);
163 #define INFOSTR "libshishi: info: "
164 #define WARNSTR "libshishi: warning: "
168 * @handle: shishi handle as allocated by shishi_init().
169 * @fmt: printf style format string.
170 * @...: print style arguments.
172 * Print informational message to stderr.
175 shishi_info (Shishi
* handle
, const char *fmt
, ...)
180 fprintf (stderr
, INFOSTR
);
181 vfprintf (stderr
, fmt
, ap
);
182 fprintf (stderr
, "\n");
189 * @handle: shishi handle as allocated by shishi_init().
190 * @fmt: printf style format string.
191 * @...: print style arguments.
193 * Print a warning to stderr.
196 shishi_warn (Shishi
* handle
, const char *fmt
, ...)
201 fprintf (stderr
, WARNSTR
);
202 vfprintf (stderr
, fmt
, ap
);
203 fprintf (stderr
, "\n");