2
* Copyright (C) 2002 Internet Software Consortium.
4
* Permission to use, copy, modify, and distribute this software for any
5
* purpose with or without fee is hereby granted, provided that the above
6
* copyright notice and this permission notice appear in all copies.
8
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
10
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
11
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
12
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
13
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
14
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
/* From BIND 9 lib/isc/win32/: strerror.c,v 1.5 2002/08/01 03:52:14 mayer */
25
* Forward declarations
29
FormatError(int error);
32
GetWSAErrorMessage(int errval);
35
NTstrerror(int err, BOOL *bfreebuf);
38
strerror(int errnum) {
40
return (NTstrerror(errnum, &bfreebuf));
43
* This routine needs to free up any buffer allocated by FormatMessage
44
* if that routine gets used.
48
isc__strerror(int num, char *buf, size_t size) {
51
unsigned int unum = num;
54
msg = NTstrerror(num, &freebuf);
56
_snprintf(buf, size, "%s", msg);
58
_snprintf(buf, size, "Unknown error: %u", unum);
59
if(freebuf && msg != NULL) {
65
* Note this will cause a memory leak unless the memory allocated here
66
* is freed by calling LocalFree. isc__strerror does this before unlocking.
67
* This only gets called if there is a system type of error and will likely
68
* be an unusual event.
71
FormatError(int error) {
72
LPVOID lpMsgBuf = NULL;
74
FORMAT_MESSAGE_ALLOCATE_BUFFER |
75
FORMAT_MESSAGE_FROM_SYSTEM |
76
FORMAT_MESSAGE_IGNORE_INSERTS,
79
/* Default language */
80
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
89
* This routine checks the error value and calls the WSA Windows Sockets
90
* Error message function GetWSAErrorMessage below if it's within that range
91
* since those messages are not available in the system error messages.
94
NTstrerror(int err, BOOL *bfreebuf) {
97
/* Copy the error value first in case of other errors */
102
/* Get the Winsock2 error messages */
103
if (errval >= WSABASEERR && errval <= (WSABASEERR + 1015)) {
104
retmsg = GetWSAErrorMessage(errval);
109
* If it's not one of the standard Unix error codes,
110
* try a system error message
112
if (errval > (DWORD) _sys_nerr) {
114
return (FormatError(errval));
116
return (_sys_errlist[errval]);
121
* This is a replacement for perror
124
NTperror(char *errmsg) {
125
/* Copy the error value first in case of other errors */
127
BOOL bfreebuf = FALSE;
130
msg = NTstrerror(errval, &bfreebuf);
131
fprintf(stderr, "%s: %s\n", errmsg, msg);
132
if(bfreebuf == TRUE) {
139
* Return the error string related to Winsock2 errors.
140
* This function is necessary since FormatMessage knows nothing about them
141
* and there is no function to get them.
144
GetWSAErrorMessage(int errval) {
150
msg = "Interrupted system call";
154
msg = "Bad file number";
158
msg = "Permission denied";
166
msg = "Invalid argument";
170
msg = "Too many open sockets";
174
msg = "Operation would block";
178
msg = "Operation now in progress";
182
msg = "Operation already in progress";
186
msg = "Socket operation on non-socket";
189
case WSAEDESTADDRREQ:
190
msg = "Destination address required";
194
msg = "Message too long";
198
msg = "Protocol wrong type for socket";
202
msg = "Bad protocol option";
205
case WSAEPROTONOSUPPORT:
206
msg = "Protocol not supported";
209
case WSAESOCKTNOSUPPORT:
210
msg = "Socket type not supported";
214
msg = "Operation not supported on socket";
217
case WSAEPFNOSUPPORT:
218
msg = "Protocol family not supported";
221
case WSAEAFNOSUPPORT:
222
msg = "Address family not supported";
226
msg = "Address already in use";
229
case WSAEADDRNOTAVAIL:
230
msg = "Can't assign requested address";
234
msg = "Network is down";
238
msg = "Network is unreachable";
242
msg = "Net connection reset";
245
case WSAECONNABORTED:
246
msg = "Software caused connection abort";
250
msg = "Connection reset by peer";
254
msg = "No buffer space available";
258
msg = "Socket is already connected";
262
msg = "Socket is not connected";
266
msg = "Can't send after socket shutdown";
269
case WSAETOOMANYREFS:
270
msg = "Too many references: can't splice";
274
msg = "Connection timed out";
277
case WSAECONNREFUSED:
278
msg = "Connection refused";
282
msg = "Too many levels of symbolic links";
285
case WSAENAMETOOLONG:
286
msg = "File name too long";
290
msg = "Host is down";
293
case WSAEHOSTUNREACH:
294
msg = "No route to host";
298
msg = "Directory not empty";
302
msg = "Too many processes";
306
msg = "Too many users";
310
msg = "Disc quota exceeded";
314
msg = "Stale NFS file handle";
318
msg = "Too many levels of remote in path";
322
msg = "Network system is unavailable";
325
case WSAVERNOTSUPPORTED:
326
msg = "Winsock version out of range";
329
case WSANOTINITIALISED:
330
msg = "WSAStartup not yet called";
334
msg = "Graceful shutdown in progress";
337
case WSAHOST_NOT_FOUND:
338
msg = "Host not found";
342
msg = "No host data of that type was found";
353
* These error messages are more informative about CryptAPI Errors than the
354
* standard error messages
358
GetCryptErrorMessage(int errval) {
364
msg = "The dwFlags parameter has an illegal value.";
367
msg = "The Registry entry for the key container "
368
"could not be opened and may not exist.";
370
case NTE_BAD_KEYSET_PARAM:
371
msg = "The pszContainer or pszProvider parameter "
372
"is set to an illegal value.";
374
case NTE_BAD_PROV_TYPE:
375
msg = "The value of the dwProvType parameter is out "
376
"of range. All provider types must be from "
377
"1 to 999, inclusive.";
379
case NTE_BAD_SIGNATURE:
380
msg = "The provider DLL signature did not verify "
381
"correctly. Either the DLL or the digital "
382
"signature has been tampered with.";
385
msg = "The dwFlags parameter is CRYPT_NEWKEYSET, but the key"
386
" container already exists.";
388
case NTE_KEYSET_ENTRY_BAD:
389
msg = "The Registry entry for the pszContainer key container "
390
"was found (in the HKEY_CURRENT_USER window), but is "
391
"corrupt. See the section System Administration for "
392
" etails about CryptoAPI's Registry usage.";
394
case NTE_KEYSET_NOT_DEF:
395
msg = "No Registry entry exists in the HKEY_CURRENT_USER "
396
"window for the key container specified by "
400
msg = "The CSP ran out of memory during the operation.";
402
case NTE_PROV_DLL_NOT_FOUND:
403
msg = "The provider DLL file does not exist or is not on the "
406
case NTE_PROV_TYPE_ENTRY_BAD:
407
msg = "The Registry entry for the provider type specified by "
408
"dwProvType is corrupt. This error may relate to "
409
"either the user default CSP list or the machine "
410
"default CSP list. See the section System "
411
"Administration for details about CryptoAPI's "
414
case NTE_PROV_TYPE_NO_MATCH:
415
msg = "The provider type specified by dwProvType does not "
416
"match the provider type found in the Registry. Note "
417
"that this error can only occur when pszProvider "
418
"specifies an actual CSP name.";
420
case NTE_PROV_TYPE_NOT_DEF:
421
msg = "No Registry entry exists for the provider type "
422
"specified by dwProvType.";
424
case NTE_PROVIDER_DLL_FAIL:
425
msg = "The provider DLL file could not be loaded, and "
426
"may not exist. If it exists, then the file is "
429
case NTE_SIGNATURE_FILE_BAD:
430
msg = "An error occurred while loading the DLL file image, "
431
"prior to verifying its signature.";