1 | /***************************************************************************
|
---|
2 | * _ _ ____ _
|
---|
3 | * Project ___| | | | _ \| |
|
---|
4 | * / __| | | | |_) | |
|
---|
5 | * | (__| |_| | _ <| |___
|
---|
6 | * \___|\___/|_| \_\_____|
|
---|
7 | *
|
---|
8 | * Copyright (C) 2004 - 2018, Daniel Stenberg, <[email protected]>, et al.
|
---|
9 | *
|
---|
10 | * This software is licensed as described in the file COPYING, which
|
---|
11 | * you should have received as part of this distribution. The terms
|
---|
12 | * are also available at https://curl.haxx.se/docs/copyright.html.
|
---|
13 | *
|
---|
14 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
---|
15 | * copies of the Software, and permit persons to whom the Software is
|
---|
16 | * furnished to do so, under the terms of the COPYING file.
|
---|
17 | *
|
---|
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
---|
19 | * KIND, either express or implied.
|
---|
20 | *
|
---|
21 | ***************************************************************************/
|
---|
22 |
|
---|
23 | #include "curl_setup.h"
|
---|
24 |
|
---|
25 | #ifdef HAVE_STRERROR_R
|
---|
26 | # if (!defined(HAVE_POSIX_STRERROR_R) && \
|
---|
27 | !defined(HAVE_GLIBC_STRERROR_R) && \
|
---|
28 | !defined(HAVE_VXWORKS_STRERROR_R)) || \
|
---|
29 | (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \
|
---|
30 | (defined(HAVE_GLIBC_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \
|
---|
31 | (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R))
|
---|
32 | # error "strerror_r MUST be either POSIX, glibc or vxworks-style"
|
---|
33 | # endif
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #include <curl/curl.h>
|
---|
37 |
|
---|
38 | #ifdef USE_LIBIDN2
|
---|
39 | #include <idn2.h>
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #ifdef USE_WINDOWS_SSPI
|
---|
43 | #include "curl_sspi.h"
|
---|
44 | #endif
|
---|
45 |
|
---|
46 | #include "strerror.h"
|
---|
47 | /* The last 3 #include files should be in this order */
|
---|
48 | #include "curl_printf.h"
|
---|
49 | #include "curl_memory.h"
|
---|
50 | #include "memdebug.h"
|
---|
51 |
|
---|
52 | #if defined(WIN32) || defined(_WIN32_WCE)
|
---|
53 | #define PRESERVE_WINDOWS_ERROR_CODE
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | const char *
|
---|
57 | curl_easy_strerror(CURLcode error)
|
---|
58 | {
|
---|
59 | #ifndef CURL_DISABLE_VERBOSE_STRINGS
|
---|
60 | switch(error) {
|
---|
61 | case CURLE_OK:
|
---|
62 | return "No error";
|
---|
63 |
|
---|
64 | case CURLE_UNSUPPORTED_PROTOCOL:
|
---|
65 | return "Unsupported protocol";
|
---|
66 |
|
---|
67 | case CURLE_FAILED_INIT:
|
---|
68 | return "Failed initialization";
|
---|
69 |
|
---|
70 | case CURLE_URL_MALFORMAT:
|
---|
71 | return "URL using bad/illegal format or missing URL";
|
---|
72 |
|
---|
73 | case CURLE_NOT_BUILT_IN:
|
---|
74 | return "A requested feature, protocol or option was not found built-in in"
|
---|
75 | " this libcurl due to a build-time decision.";
|
---|
76 |
|
---|
77 | case CURLE_COULDNT_RESOLVE_PROXY:
|
---|
78 | return "Couldn't resolve proxy name";
|
---|
79 |
|
---|
80 | case CURLE_COULDNT_RESOLVE_HOST:
|
---|
81 | return "Couldn't resolve host name";
|
---|
82 |
|
---|
83 | case CURLE_COULDNT_CONNECT:
|
---|
84 | return "Couldn't connect to server";
|
---|
85 |
|
---|
86 | case CURLE_WEIRD_SERVER_REPLY:
|
---|
87 | return "Weird server reply";
|
---|
88 |
|
---|
89 | case CURLE_REMOTE_ACCESS_DENIED:
|
---|
90 | return "Access denied to remote resource";
|
---|
91 |
|
---|
92 | case CURLE_FTP_ACCEPT_FAILED:
|
---|
93 | return "FTP: The server failed to connect to data port";
|
---|
94 |
|
---|
95 | case CURLE_FTP_ACCEPT_TIMEOUT:
|
---|
96 | return "FTP: Accepting server connect has timed out";
|
---|
97 |
|
---|
98 | case CURLE_FTP_PRET_FAILED:
|
---|
99 | return "FTP: The server did not accept the PRET command.";
|
---|
100 |
|
---|
101 | case CURLE_FTP_WEIRD_PASS_REPLY:
|
---|
102 | return "FTP: unknown PASS reply";
|
---|
103 |
|
---|
104 | case CURLE_FTP_WEIRD_PASV_REPLY:
|
---|
105 | return "FTP: unknown PASV reply";
|
---|
106 |
|
---|
107 | case CURLE_FTP_WEIRD_227_FORMAT:
|
---|
108 | return "FTP: unknown 227 response format";
|
---|
109 |
|
---|
110 | case CURLE_FTP_CANT_GET_HOST:
|
---|
111 | return "FTP: can't figure out the host in the PASV response";
|
---|
112 |
|
---|
113 | case CURLE_HTTP2:
|
---|
114 | return "Error in the HTTP2 framing layer";
|
---|
115 |
|
---|
116 | case CURLE_FTP_COULDNT_SET_TYPE:
|
---|
117 | return "FTP: couldn't set file type";
|
---|
118 |
|
---|
119 | case CURLE_PARTIAL_FILE:
|
---|
120 | return "Transferred a partial file";
|
---|
121 |
|
---|
122 | case CURLE_FTP_COULDNT_RETR_FILE:
|
---|
123 | return "FTP: couldn't retrieve (RETR failed) the specified file";
|
---|
124 |
|
---|
125 | case CURLE_QUOTE_ERROR:
|
---|
126 | return "Quote command returned error";
|
---|
127 |
|
---|
128 | case CURLE_HTTP_RETURNED_ERROR:
|
---|
129 | return "HTTP response code said error";
|
---|
130 |
|
---|
131 | case CURLE_WRITE_ERROR:
|
---|
132 | return "Failed writing received data to disk/application";
|
---|
133 |
|
---|
134 | case CURLE_UPLOAD_FAILED:
|
---|
135 | return "Upload failed (at start/before it took off)";
|
---|
136 |
|
---|
137 | case CURLE_READ_ERROR:
|
---|
138 | return "Failed to open/read local data from file/application";
|
---|
139 |
|
---|
140 | case CURLE_OUT_OF_MEMORY:
|
---|
141 | return "Out of memory";
|
---|
142 |
|
---|
143 | case CURLE_OPERATION_TIMEDOUT:
|
---|
144 | return "Timeout was reached";
|
---|
145 |
|
---|
146 | case CURLE_FTP_PORT_FAILED:
|
---|
147 | return "FTP: command PORT failed";
|
---|
148 |
|
---|
149 | case CURLE_FTP_COULDNT_USE_REST:
|
---|
150 | return "FTP: command REST failed";
|
---|
151 |
|
---|
152 | case CURLE_RANGE_ERROR:
|
---|
153 | return "Requested range was not delivered by the server";
|
---|
154 |
|
---|
155 | case CURLE_HTTP_POST_ERROR:
|
---|
156 | return "Internal problem setting up the POST";
|
---|
157 |
|
---|
158 | case CURLE_SSL_CONNECT_ERROR:
|
---|
159 | return "SSL connect error";
|
---|
160 |
|
---|
161 | case CURLE_BAD_DOWNLOAD_RESUME:
|
---|
162 | return "Couldn't resume download";
|
---|
163 |
|
---|
164 | case CURLE_FILE_COULDNT_READ_FILE:
|
---|
165 | return "Couldn't read a file:// file";
|
---|
166 |
|
---|
167 | case CURLE_LDAP_CANNOT_BIND:
|
---|
168 | return "LDAP: cannot bind";
|
---|
169 |
|
---|
170 | case CURLE_LDAP_SEARCH_FAILED:
|
---|
171 | return "LDAP: search failed";
|
---|
172 |
|
---|
173 | case CURLE_FUNCTION_NOT_FOUND:
|
---|
174 | return "A required function in the library was not found";
|
---|
175 |
|
---|
176 | case CURLE_ABORTED_BY_CALLBACK:
|
---|
177 | return "Operation was aborted by an application callback";
|
---|
178 |
|
---|
179 | case CURLE_BAD_FUNCTION_ARGUMENT:
|
---|
180 | return "A libcurl function was given a bad argument";
|
---|
181 |
|
---|
182 | case CURLE_INTERFACE_FAILED:
|
---|
183 | return "Failed binding local connection end";
|
---|
184 |
|
---|
185 | case CURLE_TOO_MANY_REDIRECTS :
|
---|
186 | return "Number of redirects hit maximum amount";
|
---|
187 |
|
---|
188 | case CURLE_UNKNOWN_OPTION:
|
---|
189 | return "An unknown option was passed in to libcurl";
|
---|
190 |
|
---|
191 | case CURLE_TELNET_OPTION_SYNTAX :
|
---|
192 | return "Malformed telnet option";
|
---|
193 |
|
---|
194 | case CURLE_GOT_NOTHING:
|
---|
195 | return "Server returned nothing (no headers, no data)";
|
---|
196 |
|
---|
197 | case CURLE_SSL_ENGINE_NOTFOUND:
|
---|
198 | return "SSL crypto engine not found";
|
---|
199 |
|
---|
200 | case CURLE_SSL_ENGINE_SETFAILED:
|
---|
201 | return "Can not set SSL crypto engine as default";
|
---|
202 |
|
---|
203 | case CURLE_SSL_ENGINE_INITFAILED:
|
---|
204 | return "Failed to initialise SSL crypto engine";
|
---|
205 |
|
---|
206 | case CURLE_SEND_ERROR:
|
---|
207 | return "Failed sending data to the peer";
|
---|
208 |
|
---|
209 | case CURLE_RECV_ERROR:
|
---|
210 | return "Failure when receiving data from the peer";
|
---|
211 |
|
---|
212 | case CURLE_SSL_CERTPROBLEM:
|
---|
213 | return "Problem with the local SSL certificate";
|
---|
214 |
|
---|
215 | case CURLE_SSL_CIPHER:
|
---|
216 | return "Couldn't use specified SSL cipher";
|
---|
217 |
|
---|
218 | case CURLE_PEER_FAILED_VERIFICATION:
|
---|
219 | return "SSL peer certificate or SSH remote key was not OK";
|
---|
220 |
|
---|
221 | case CURLE_SSL_CACERT_BADFILE:
|
---|
222 | return "Problem with the SSL CA cert (path? access rights?)";
|
---|
223 |
|
---|
224 | case CURLE_BAD_CONTENT_ENCODING:
|
---|
225 | return "Unrecognized or bad HTTP Content or Transfer-Encoding";
|
---|
226 |
|
---|
227 | case CURLE_LDAP_INVALID_URL:
|
---|
228 | return "Invalid LDAP URL";
|
---|
229 |
|
---|
230 | case CURLE_FILESIZE_EXCEEDED:
|
---|
231 | return "Maximum file size exceeded";
|
---|
232 |
|
---|
233 | case CURLE_USE_SSL_FAILED:
|
---|
234 | return "Requested SSL level failed";
|
---|
235 |
|
---|
236 | case CURLE_SSL_SHUTDOWN_FAILED:
|
---|
237 | return "Failed to shut down the SSL connection";
|
---|
238 |
|
---|
239 | case CURLE_SSL_CRL_BADFILE:
|
---|
240 | return "Failed to load CRL file (path? access rights?, format?)";
|
---|
241 |
|
---|
242 | case CURLE_SSL_ISSUER_ERROR:
|
---|
243 | return "Issuer check against peer certificate failed";
|
---|
244 |
|
---|
245 | case CURLE_SEND_FAIL_REWIND:
|
---|
246 | return "Send failed since rewinding of the data stream failed";
|
---|
247 |
|
---|
248 | case CURLE_LOGIN_DENIED:
|
---|
249 | return "Login denied";
|
---|
250 |
|
---|
251 | case CURLE_TFTP_NOTFOUND:
|
---|
252 | return "TFTP: File Not Found";
|
---|
253 |
|
---|
254 | case CURLE_TFTP_PERM:
|
---|
255 | return "TFTP: Access Violation";
|
---|
256 |
|
---|
257 | case CURLE_REMOTE_DISK_FULL:
|
---|
258 | return "Disk full or allocation exceeded";
|
---|
259 |
|
---|
260 | case CURLE_TFTP_ILLEGAL:
|
---|
261 | return "TFTP: Illegal operation";
|
---|
262 |
|
---|
263 | case CURLE_TFTP_UNKNOWNID:
|
---|
264 | return "TFTP: Unknown transfer ID";
|
---|
265 |
|
---|
266 | case CURLE_REMOTE_FILE_EXISTS:
|
---|
267 | return "Remote file already exists";
|
---|
268 |
|
---|
269 | case CURLE_TFTP_NOSUCHUSER:
|
---|
270 | return "TFTP: No such user";
|
---|
271 |
|
---|
272 | case CURLE_CONV_FAILED:
|
---|
273 | return "Conversion failed";
|
---|
274 |
|
---|
275 | case CURLE_CONV_REQD:
|
---|
276 | return "Caller must register CURLOPT_CONV_ callback options";
|
---|
277 |
|
---|
278 | case CURLE_REMOTE_FILE_NOT_FOUND:
|
---|
279 | return "Remote file not found";
|
---|
280 |
|
---|
281 | case CURLE_SSH:
|
---|
282 | return "Error in the SSH layer";
|
---|
283 |
|
---|
284 | case CURLE_AGAIN:
|
---|
285 | return "Socket not ready for send/recv";
|
---|
286 |
|
---|
287 | case CURLE_RTSP_CSEQ_ERROR:
|
---|
288 | return "RTSP CSeq mismatch or invalid CSeq";
|
---|
289 |
|
---|
290 | case CURLE_RTSP_SESSION_ERROR:
|
---|
291 | return "RTSP session error";
|
---|
292 |
|
---|
293 | case CURLE_FTP_BAD_FILE_LIST:
|
---|
294 | return "Unable to parse FTP file list";
|
---|
295 |
|
---|
296 | case CURLE_CHUNK_FAILED:
|
---|
297 | return "Chunk callback failed";
|
---|
298 |
|
---|
299 | case CURLE_NO_CONNECTION_AVAILABLE:
|
---|
300 | return "The max connection limit is reached";
|
---|
301 |
|
---|
302 | case CURLE_SSL_PINNEDPUBKEYNOTMATCH:
|
---|
303 | return "SSL public key does not match pinned public key";
|
---|
304 |
|
---|
305 | case CURLE_SSL_INVALIDCERTSTATUS:
|
---|
306 | return "SSL server certificate status verification FAILED";
|
---|
307 |
|
---|
308 | case CURLE_HTTP2_STREAM:
|
---|
309 | return "Stream error in the HTTP/2 framing layer";
|
---|
310 |
|
---|
311 | case CURLE_RECURSIVE_API_CALL:
|
---|
312 | return "API function called from within callback";
|
---|
313 |
|
---|
314 | /* error codes not used by current libcurl */
|
---|
315 | case CURLE_OBSOLETE20:
|
---|
316 | case CURLE_OBSOLETE24:
|
---|
317 | case CURLE_OBSOLETE29:
|
---|
318 | case CURLE_OBSOLETE32:
|
---|
319 | case CURLE_OBSOLETE40:
|
---|
320 | case CURLE_OBSOLETE44:
|
---|
321 | case CURLE_OBSOLETE46:
|
---|
322 | case CURLE_OBSOLETE50:
|
---|
323 | case CURLE_OBSOLETE51:
|
---|
324 | case CURLE_OBSOLETE57:
|
---|
325 | case CURL_LAST:
|
---|
326 | break;
|
---|
327 | }
|
---|
328 | /*
|
---|
329 | * By using a switch, gcc -Wall will complain about enum values
|
---|
330 | * which do not appear, helping keep this function up-to-date.
|
---|
331 | * By using gcc -Wall -Werror, you can't forget.
|
---|
332 | *
|
---|
333 | * A table would not have the same benefit. Most compilers will
|
---|
334 | * generate code very similar to a table in any case, so there
|
---|
335 | * is little performance gain from a table. And something is broken
|
---|
336 | * for the user's application, anyways, so does it matter how fast
|
---|
337 | * it _doesn't_ work?
|
---|
338 | *
|
---|
339 | * The line number for the error will be near this comment, which
|
---|
340 | * is why it is here, and not at the start of the switch.
|
---|
341 | */
|
---|
342 | return "Unknown error";
|
---|
343 | #else
|
---|
344 | if(!error)
|
---|
345 | return "No error";
|
---|
346 | else
|
---|
347 | return "Error";
|
---|
348 | #endif
|
---|
349 | }
|
---|
350 |
|
---|
351 | const char *
|
---|
352 | curl_multi_strerror(CURLMcode error)
|
---|
353 | {
|
---|
354 | #ifndef CURL_DISABLE_VERBOSE_STRINGS
|
---|
355 | switch(error) {
|
---|
356 | case CURLM_CALL_MULTI_PERFORM:
|
---|
357 | return "Please call curl_multi_perform() soon";
|
---|
358 |
|
---|
359 | case CURLM_OK:
|
---|
360 | return "No error";
|
---|
361 |
|
---|
362 | case CURLM_BAD_HANDLE:
|
---|
363 | return "Invalid multi handle";
|
---|
364 |
|
---|
365 | case CURLM_BAD_EASY_HANDLE:
|
---|
366 | return "Invalid easy handle";
|
---|
367 |
|
---|
368 | case CURLM_OUT_OF_MEMORY:
|
---|
369 | return "Out of memory";
|
---|
370 |
|
---|
371 | case CURLM_INTERNAL_ERROR:
|
---|
372 | return "Internal error";
|
---|
373 |
|
---|
374 | case CURLM_BAD_SOCKET:
|
---|
375 | return "Invalid socket argument";
|
---|
376 |
|
---|
377 | case CURLM_UNKNOWN_OPTION:
|
---|
378 | return "Unknown option";
|
---|
379 |
|
---|
380 | case CURLM_ADDED_ALREADY:
|
---|
381 | return "The easy handle is already added to a multi handle";
|
---|
382 |
|
---|
383 | case CURLM_RECURSIVE_API_CALL:
|
---|
384 | return "API function called from within callback";
|
---|
385 |
|
---|
386 | case CURLM_LAST:
|
---|
387 | break;
|
---|
388 | }
|
---|
389 |
|
---|
390 | return "Unknown error";
|
---|
391 | #else
|
---|
392 | if(error == CURLM_OK)
|
---|
393 | return "No error";
|
---|
394 | else
|
---|
395 | return "Error";
|
---|
396 | #endif
|
---|
397 | }
|
---|
398 |
|
---|
399 | const char *
|
---|
400 | curl_share_strerror(CURLSHcode error)
|
---|
401 | {
|
---|
402 | #ifndef CURL_DISABLE_VERBOSE_STRINGS
|
---|
403 | switch(error) {
|
---|
404 | case CURLSHE_OK:
|
---|
405 | return "No error";
|
---|
406 |
|
---|
407 | case CURLSHE_BAD_OPTION:
|
---|
408 | return "Unknown share option";
|
---|
409 |
|
---|
410 | case CURLSHE_IN_USE:
|
---|
411 | return "Share currently in use";
|
---|
412 |
|
---|
413 | case CURLSHE_INVALID:
|
---|
414 | return "Invalid share handle";
|
---|
415 |
|
---|
416 | case CURLSHE_NOMEM:
|
---|
417 | return "Out of memory";
|
---|
418 |
|
---|
419 | case CURLSHE_NOT_BUILT_IN:
|
---|
420 | return "Feature not enabled in this library";
|
---|
421 |
|
---|
422 | case CURLSHE_LAST:
|
---|
423 | break;
|
---|
424 | }
|
---|
425 |
|
---|
426 | return "CURLSHcode unknown";
|
---|
427 | #else
|
---|
428 | if(error == CURLSHE_OK)
|
---|
429 | return "No error";
|
---|
430 | else
|
---|
431 | return "Error";
|
---|
432 | #endif
|
---|
433 | }
|
---|
434 |
|
---|
435 | #ifdef USE_WINSOCK
|
---|
436 |
|
---|
437 | /* This function handles most / all (?) Winsock errors curl is able to produce.
|
---|
438 | */
|
---|
439 | static const char *
|
---|
440 | get_winsock_error (int err, char *buf, size_t len)
|
---|
441 | {
|
---|
442 | #ifdef PRESERVE_WINDOWS_ERROR_CODE
|
---|
443 | DWORD old_win_err = GetLastError();
|
---|
444 | #endif
|
---|
445 | int old_errno = errno;
|
---|
446 | const char *p;
|
---|
447 |
|
---|
448 | #ifndef CURL_DISABLE_VERBOSE_STRINGS
|
---|
449 | switch(err) {
|
---|
450 | case WSAEINTR:
|
---|
451 | p = "Call interrupted";
|
---|
452 | break;
|
---|
453 | case WSAEBADF:
|
---|
454 | p = "Bad file";
|
---|
455 | break;
|
---|
456 | case WSAEACCES:
|
---|
457 | p = "Bad access";
|
---|
458 | break;
|
---|
459 | case WSAEFAULT:
|
---|
460 | p = "Bad argument";
|
---|
461 | break;
|
---|
462 | case WSAEINVAL:
|
---|
463 | p = "Invalid arguments";
|
---|
464 | break;
|
---|
465 | case WSAEMFILE:
|
---|
466 | p = "Out of file descriptors";
|
---|
467 | break;
|
---|
468 | case WSAEWOULDBLOCK:
|
---|
469 | p = "Call would block";
|
---|
470 | break;
|
---|
471 | case WSAEINPROGRESS:
|
---|
472 | case WSAEALREADY:
|
---|
473 | p = "Blocking call in progress";
|
---|
474 | break;
|
---|
475 | case WSAENOTSOCK:
|
---|
476 | p = "Descriptor is not a socket";
|
---|
477 | break;
|
---|
478 | case WSAEDESTADDRREQ:
|
---|
479 | p = "Need destination address";
|
---|
480 | break;
|
---|
481 | case WSAEMSGSIZE:
|
---|
482 | p = "Bad message size";
|
---|
483 | break;
|
---|
484 | case WSAEPROTOTYPE:
|
---|
485 | p = "Bad protocol";
|
---|
486 | break;
|
---|
487 | case WSAENOPROTOOPT:
|
---|
488 | p = "Protocol option is unsupported";
|
---|
489 | break;
|
---|
490 | case WSAEPROTONOSUPPORT:
|
---|
491 | p = "Protocol is unsupported";
|
---|
492 | break;
|
---|
493 | case WSAESOCKTNOSUPPORT:
|
---|
494 | p = "Socket is unsupported";
|
---|
495 | break;
|
---|
496 | case WSAEOPNOTSUPP:
|
---|
497 | p = "Operation not supported";
|
---|
498 | break;
|
---|
499 | case WSAEAFNOSUPPORT:
|
---|
500 | p = "Address family not supported";
|
---|
501 | break;
|
---|
502 | case WSAEPFNOSUPPORT:
|
---|
503 | p = "Protocol family not supported";
|
---|
504 | break;
|
---|
505 | case WSAEADDRINUSE:
|
---|
506 | p = "Address already in use";
|
---|
507 | break;
|
---|
508 | case WSAEADDRNOTAVAIL:
|
---|
509 | p = "Address not available";
|
---|
510 | break;
|
---|
511 | case WSAENETDOWN:
|
---|
512 | p = "Network down";
|
---|
513 | break;
|
---|
514 | case WSAENETUNREACH:
|
---|
515 | p = "Network unreachable";
|
---|
516 | break;
|
---|
517 | case WSAENETRESET:
|
---|
518 | p = "Network has been reset";
|
---|
519 | break;
|
---|
520 | case WSAECONNABORTED:
|
---|
521 | p = "Connection was aborted";
|
---|
522 | break;
|
---|
523 | case WSAECONNRESET:
|
---|
524 | p = "Connection was reset";
|
---|
525 | break;
|
---|
526 | case WSAENOBUFS:
|
---|
527 | p = "No buffer space";
|
---|
528 | break;
|
---|
529 | case WSAEISCONN:
|
---|
530 | p = "Socket is already connected";
|
---|
531 | break;
|
---|
532 | case WSAENOTCONN:
|
---|
533 | p = "Socket is not connected";
|
---|
534 | break;
|
---|
535 | case WSAESHUTDOWN:
|
---|
536 | p = "Socket has been shut down";
|
---|
537 | break;
|
---|
538 | case WSAETOOMANYREFS:
|
---|
539 | p = "Too many references";
|
---|
540 | break;
|
---|
541 | case WSAETIMEDOUT:
|
---|
542 | p = "Timed out";
|
---|
543 | break;
|
---|
544 | case WSAECONNREFUSED:
|
---|
545 | p = "Connection refused";
|
---|
546 | break;
|
---|
547 | case WSAELOOP:
|
---|
548 | p = "Loop??";
|
---|
549 | break;
|
---|
550 | case WSAENAMETOOLONG:
|
---|
551 | p = "Name too long";
|
---|
552 | break;
|
---|
553 | case WSAEHOSTDOWN:
|
---|
554 | p = "Host down";
|
---|
555 | break;
|
---|
556 | case WSAEHOSTUNREACH:
|
---|
557 | p = "Host unreachable";
|
---|
558 | break;
|
---|
559 | case WSAENOTEMPTY:
|
---|
560 | p = "Not empty";
|
---|
561 | break;
|
---|
562 | case WSAEPROCLIM:
|
---|
563 | p = "Process limit reached";
|
---|
564 | break;
|
---|
565 | case WSAEUSERS:
|
---|
566 | p = "Too many users";
|
---|
567 | break;
|
---|
568 | case WSAEDQUOT:
|
---|
569 | p = "Bad quota";
|
---|
570 | break;
|
---|
571 | case WSAESTALE:
|
---|
572 | p = "Something is stale";
|
---|
573 | break;
|
---|
574 | case WSAEREMOTE:
|
---|
575 | p = "Remote error";
|
---|
576 | break;
|
---|
577 | #ifdef WSAEDISCON /* missing in SalfordC! */
|
---|
578 | case WSAEDISCON:
|
---|
579 | p = "Disconnected";
|
---|
580 | break;
|
---|
581 | #endif
|
---|
582 | /* Extended Winsock errors */
|
---|
583 | case WSASYSNOTREADY:
|
---|
584 | p = "Winsock library is not ready";
|
---|
585 | break;
|
---|
586 | case WSANOTINITIALISED:
|
---|
587 | p = "Winsock library not initialised";
|
---|
588 | break;
|
---|
589 | case WSAVERNOTSUPPORTED:
|
---|
590 | p = "Winsock version not supported";
|
---|
591 | break;
|
---|
592 |
|
---|
593 | /* getXbyY() errors (already handled in herrmsg):
|
---|
594 | * Authoritative Answer: Host not found */
|
---|
595 | case WSAHOST_NOT_FOUND:
|
---|
596 | p = "Host not found";
|
---|
597 | break;
|
---|
598 |
|
---|
599 | /* Non-Authoritative: Host not found, or SERVERFAIL */
|
---|
600 | case WSATRY_AGAIN:
|
---|
601 | p = "Host not found, try again";
|
---|
602 | break;
|
---|
603 |
|
---|
604 | /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
|
---|
605 | case WSANO_RECOVERY:
|
---|
606 | p = "Unrecoverable error in call to nameserver";
|
---|
607 | break;
|
---|
608 |
|
---|
609 | /* Valid name, no data record of requested type */
|
---|
610 | case WSANO_DATA:
|
---|
611 | p = "No data record of requested type";
|
---|
612 | break;
|
---|
613 |
|
---|
614 | default:
|
---|
615 | return NULL;
|
---|
616 | }
|
---|
617 | #else
|
---|
618 | if(!err)
|
---|
619 | return NULL;
|
---|
620 | else
|
---|
621 | p = "error";
|
---|
622 | #endif
|
---|
623 | strncpy(buf, p, len);
|
---|
624 | buf [len-1] = '\0';
|
---|
625 |
|
---|
626 | if(errno != old_errno)
|
---|
627 | errno = old_errno;
|
---|
628 |
|
---|
629 | #ifdef PRESERVE_WINDOWS_ERROR_CODE
|
---|
630 | if(old_win_err != GetLastError())
|
---|
631 | SetLastError(old_win_err);
|
---|
632 | #endif
|
---|
633 |
|
---|
634 | return buf;
|
---|
635 | }
|
---|
636 | #endif /* USE_WINSOCK */
|
---|
637 |
|
---|
638 | /*
|
---|
639 | * Our thread-safe and smart strerror() replacement.
|
---|
640 | *
|
---|
641 | * The 'err' argument passed in to this function MUST be a true errno number
|
---|
642 | * as reported on this system. We do no range checking on the number before
|
---|
643 | * we pass it to the "number-to-message" conversion function and there might
|
---|
644 | * be systems that don't do proper range checking in there themselves.
|
---|
645 | *
|
---|
646 | * We don't do range checking (on systems other than Windows) since there is
|
---|
647 | * no good reliable and portable way to do it.
|
---|
648 | */
|
---|
649 | const char *Curl_strerror(struct connectdata *conn, int err)
|
---|
650 | {
|
---|
651 | #ifdef PRESERVE_WINDOWS_ERROR_CODE
|
---|
652 | DWORD old_win_err = GetLastError();
|
---|
653 | #endif
|
---|
654 | int old_errno = errno;
|
---|
655 | char *buf, *p;
|
---|
656 | size_t max;
|
---|
657 |
|
---|
658 | DEBUGASSERT(conn);
|
---|
659 | DEBUGASSERT(err >= 0);
|
---|
660 |
|
---|
661 | buf = conn->syserr_buf;
|
---|
662 | max = sizeof(conn->syserr_buf)-1;
|
---|
663 | *buf = '\0';
|
---|
664 |
|
---|
665 | #ifdef USE_WINSOCK
|
---|
666 |
|
---|
667 | #ifdef _WIN32_WCE
|
---|
668 | {
|
---|
669 | wchar_t wbuf[256];
|
---|
670 | wbuf[0] = L'\0';
|
---|
671 |
|
---|
672 | FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
|
---|
673 | LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL);
|
---|
674 | wcstombs(buf, wbuf, max);
|
---|
675 | }
|
---|
676 | #else
|
---|
677 | /* 'sys_nerr' is the maximum errno number, it is not widely portable */
|
---|
678 | if(err >= 0 && err < sys_nerr)
|
---|
679 | strncpy(buf, strerror(err), max);
|
---|
680 | else {
|
---|
681 | if(!get_winsock_error(err, buf, max) &&
|
---|
682 | !FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
|
---|
683 | LANG_NEUTRAL, buf, (DWORD)max, NULL))
|
---|
684 | msnprintf(buf, max, "Unknown error %d (%#x)", err, err);
|
---|
685 | }
|
---|
686 | #endif
|
---|
687 |
|
---|
688 | #else /* not USE_WINSOCK coming up */
|
---|
689 |
|
---|
690 | #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R)
|
---|
691 | /*
|
---|
692 | * The POSIX-style strerror_r() may set errno to ERANGE if insufficient
|
---|
693 | * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated
|
---|
694 | * message string, or EINVAL if 'errnum' is not a valid error number.
|
---|
695 | */
|
---|
696 | if(0 != strerror_r(err, buf, max)) {
|
---|
697 | if('\0' == buf[0])
|
---|
698 | msnprintf(buf, max, "Unknown error %d", err);
|
---|
699 | }
|
---|
700 | #elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)
|
---|
701 | /*
|
---|
702 | * The glibc-style strerror_r() only *might* use the buffer we pass to
|
---|
703 | * the function, but it always returns the error message as a pointer,
|
---|
704 | * so we must copy that string unconditionally (if non-NULL).
|
---|
705 | */
|
---|
706 | {
|
---|
707 | char buffer[256];
|
---|
708 | char *msg = strerror_r(err, buffer, sizeof(buffer));
|
---|
709 | if(msg)
|
---|
710 | strncpy(buf, msg, max);
|
---|
711 | else
|
---|
712 | msnprintf(buf, max, "Unknown error %d", err);
|
---|
713 | }
|
---|
714 | #elif defined(HAVE_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)
|
---|
715 | /*
|
---|
716 | * The vxworks-style strerror_r() does use the buffer we pass to the function.
|
---|
717 | * The buffer size should be at least NAME_MAX (256)
|
---|
718 | */
|
---|
719 | {
|
---|
720 | char buffer[256];
|
---|
721 | if(OK == strerror_r(err, buffer))
|
---|
722 | strncpy(buf, buffer, max);
|
---|
723 | else
|
---|
724 | msnprintf(buf, max, "Unknown error %d", err);
|
---|
725 | }
|
---|
726 | #else
|
---|
727 | {
|
---|
728 | char *msg = strerror(err);
|
---|
729 | if(msg)
|
---|
730 | strncpy(buf, msg, max);
|
---|
731 | else
|
---|
732 | msnprintf(buf, max, "Unknown error %d", err);
|
---|
733 | }
|
---|
734 | #endif
|
---|
735 |
|
---|
736 | #endif /* end of ! USE_WINSOCK */
|
---|
737 |
|
---|
738 | buf[max] = '\0'; /* make sure the string is zero terminated */
|
---|
739 |
|
---|
740 | /* strip trailing '\r\n' or '\n'. */
|
---|
741 | p = strrchr(buf, '\n');
|
---|
742 | if(p && (p - buf) >= 2)
|
---|
743 | *p = '\0';
|
---|
744 | p = strrchr(buf, '\r');
|
---|
745 | if(p && (p - buf) >= 1)
|
---|
746 | *p = '\0';
|
---|
747 |
|
---|
748 | if(errno != old_errno)
|
---|
749 | errno = old_errno;
|
---|
750 |
|
---|
751 | #ifdef PRESERVE_WINDOWS_ERROR_CODE
|
---|
752 | if(old_win_err != GetLastError())
|
---|
753 | SetLastError(old_win_err);
|
---|
754 | #endif
|
---|
755 |
|
---|
756 | return buf;
|
---|
757 | }
|
---|
758 |
|
---|
759 | #ifdef USE_WINDOWS_SSPI
|
---|
760 | const char *Curl_sspi_strerror (struct connectdata *conn, int err)
|
---|
761 | {
|
---|
762 | #ifdef PRESERVE_WINDOWS_ERROR_CODE
|
---|
763 | DWORD old_win_err = GetLastError();
|
---|
764 | #endif
|
---|
765 | int old_errno = errno;
|
---|
766 | const char *txt;
|
---|
767 | char *outbuf;
|
---|
768 | size_t outmax;
|
---|
769 | #ifndef CURL_DISABLE_VERBOSE_STRINGS
|
---|
770 | char txtbuf[80];
|
---|
771 | char msgbuf[sizeof(conn->syserr_buf)];
|
---|
772 | char *p, *str, *msg = NULL;
|
---|
773 | bool msg_formatted = FALSE;
|
---|
774 | #endif
|
---|
775 |
|
---|
776 | DEBUGASSERT(conn);
|
---|
777 |
|
---|
778 | outbuf = conn->syserr_buf;
|
---|
779 | outmax = sizeof(conn->syserr_buf)-1;
|
---|
780 | *outbuf = '\0';
|
---|
781 |
|
---|
782 | #ifndef CURL_DISABLE_VERBOSE_STRINGS
|
---|
783 |
|
---|
784 | switch(err) {
|
---|
785 | case SEC_E_OK:
|
---|
786 | txt = "No error";
|
---|
787 | break;
|
---|
788 | case CRYPT_E_REVOKED:
|
---|
789 | txt = "CRYPT_E_REVOKED";
|
---|
790 | break;
|
---|
791 | case SEC_E_ALGORITHM_MISMATCH:
|
---|
792 | txt = "SEC_E_ALGORITHM_MISMATCH";
|
---|
793 | break;
|
---|
794 | case SEC_E_BAD_BINDINGS:
|
---|
795 | txt = "SEC_E_BAD_BINDINGS";
|
---|
796 | break;
|
---|
797 | case SEC_E_BAD_PKGID:
|
---|
798 | txt = "SEC_E_BAD_PKGID";
|
---|
799 | break;
|
---|
800 | case SEC_E_BUFFER_TOO_SMALL:
|
---|
801 | txt = "SEC_E_BUFFER_TOO_SMALL";
|
---|
802 | break;
|
---|
803 | case SEC_E_CANNOT_INSTALL:
|
---|
804 | txt = "SEC_E_CANNOT_INSTALL";
|
---|
805 | break;
|
---|
806 | case SEC_E_CANNOT_PACK:
|
---|
807 | txt = "SEC_E_CANNOT_PACK";
|
---|
808 | break;
|
---|
809 | case SEC_E_CERT_EXPIRED:
|
---|
810 | txt = "SEC_E_CERT_EXPIRED";
|
---|
811 | break;
|
---|
812 | case SEC_E_CERT_UNKNOWN:
|
---|
813 | txt = "SEC_E_CERT_UNKNOWN";
|
---|
814 | break;
|
---|
815 | case SEC_E_CERT_WRONG_USAGE:
|
---|
816 | txt = "SEC_E_CERT_WRONG_USAGE";
|
---|
817 | break;
|
---|
818 | case SEC_E_CONTEXT_EXPIRED:
|
---|
819 | txt = "SEC_E_CONTEXT_EXPIRED";
|
---|
820 | break;
|
---|
821 | case SEC_E_CROSSREALM_DELEGATION_FAILURE:
|
---|
822 | txt = "SEC_E_CROSSREALM_DELEGATION_FAILURE";
|
---|
823 | break;
|
---|
824 | case SEC_E_CRYPTO_SYSTEM_INVALID:
|
---|
825 | txt = "SEC_E_CRYPTO_SYSTEM_INVALID";
|
---|
826 | break;
|
---|
827 | case SEC_E_DECRYPT_FAILURE:
|
---|
828 | txt = "SEC_E_DECRYPT_FAILURE";
|
---|
829 | break;
|
---|
830 | case SEC_E_DELEGATION_POLICY:
|
---|
831 | txt = "SEC_E_DELEGATION_POLICY";
|
---|
832 | break;
|
---|
833 | case SEC_E_DELEGATION_REQUIRED:
|
---|
834 | txt = "SEC_E_DELEGATION_REQUIRED";
|
---|
835 | break;
|
---|
836 | case SEC_E_DOWNGRADE_DETECTED:
|
---|
837 | txt = "SEC_E_DOWNGRADE_DETECTED";
|
---|
838 | break;
|
---|
839 | case SEC_E_ENCRYPT_FAILURE:
|
---|
840 | txt = "SEC_E_ENCRYPT_FAILURE";
|
---|
841 | break;
|
---|
842 | case SEC_E_ILLEGAL_MESSAGE:
|
---|
843 | txt = "SEC_E_ILLEGAL_MESSAGE";
|
---|
844 | break;
|
---|
845 | case SEC_E_INCOMPLETE_CREDENTIALS:
|
---|
846 | txt = "SEC_E_INCOMPLETE_CREDENTIALS";
|
---|
847 | break;
|
---|
848 | case SEC_E_INCOMPLETE_MESSAGE:
|
---|
849 | txt = "SEC_E_INCOMPLETE_MESSAGE";
|
---|
850 | break;
|
---|
851 | case SEC_E_INSUFFICIENT_MEMORY:
|
---|
852 | txt = "SEC_E_INSUFFICIENT_MEMORY";
|
---|
853 | break;
|
---|
854 | case SEC_E_INTERNAL_ERROR:
|
---|
855 | txt = "SEC_E_INTERNAL_ERROR";
|
---|
856 | break;
|
---|
857 | case SEC_E_INVALID_HANDLE:
|
---|
858 | txt = "SEC_E_INVALID_HANDLE";
|
---|
859 | break;
|
---|
860 | case SEC_E_INVALID_PARAMETER:
|
---|
861 | txt = "SEC_E_INVALID_PARAMETER";
|
---|
862 | break;
|
---|
863 | case SEC_E_INVALID_TOKEN:
|
---|
864 | txt = "SEC_E_INVALID_TOKEN";
|
---|
865 | break;
|
---|
866 | case SEC_E_ISSUING_CA_UNTRUSTED:
|
---|
867 | txt = "SEC_E_ISSUING_CA_UNTRUSTED";
|
---|
868 | break;
|
---|
869 | case SEC_E_ISSUING_CA_UNTRUSTED_KDC:
|
---|
870 | txt = "SEC_E_ISSUING_CA_UNTRUSTED_KDC";
|
---|
871 | break;
|
---|
872 | case SEC_E_KDC_CERT_EXPIRED:
|
---|
873 | txt = "SEC_E_KDC_CERT_EXPIRED";
|
---|
874 | break;
|
---|
875 | case SEC_E_KDC_CERT_REVOKED:
|
---|
876 | txt = "SEC_E_KDC_CERT_REVOKED";
|
---|
877 | break;
|
---|
878 | case SEC_E_KDC_INVALID_REQUEST:
|
---|
879 | txt = "SEC_E_KDC_INVALID_REQUEST";
|
---|
880 | break;
|
---|
881 | case SEC_E_KDC_UNABLE_TO_REFER:
|
---|
882 | txt = "SEC_E_KDC_UNABLE_TO_REFER";
|
---|
883 | break;
|
---|
884 | case SEC_E_KDC_UNKNOWN_ETYPE:
|
---|
885 | txt = "SEC_E_KDC_UNKNOWN_ETYPE";
|
---|
886 | break;
|
---|
887 | case SEC_E_LOGON_DENIED:
|
---|
888 | txt = "SEC_E_LOGON_DENIED";
|
---|
889 | break;
|
---|
890 | case SEC_E_MAX_REFERRALS_EXCEEDED:
|
---|
891 | txt = "SEC_E_MAX_REFERRALS_EXCEEDED";
|
---|
892 | break;
|
---|
893 | case SEC_E_MESSAGE_ALTERED:
|
---|
894 | txt = "SEC_E_MESSAGE_ALTERED";
|
---|
895 | break;
|
---|
896 | case SEC_E_MULTIPLE_ACCOUNTS:
|
---|
897 | txt = "SEC_E_MULTIPLE_ACCOUNTS";
|
---|
898 | break;
|
---|
899 | case SEC_E_MUST_BE_KDC:
|
---|
900 | txt = "SEC_E_MUST_BE_KDC";
|
---|
901 | break;
|
---|
902 | case SEC_E_NOT_OWNER:
|
---|
903 | txt = "SEC_E_NOT_OWNER";
|
---|
904 | break;
|
---|
905 | case SEC_E_NO_AUTHENTICATING_AUTHORITY:
|
---|
906 | txt = "SEC_E_NO_AUTHENTICATING_AUTHORITY";
|
---|
907 | break;
|
---|
908 | case SEC_E_NO_CREDENTIALS:
|
---|
909 | txt = "SEC_E_NO_CREDENTIALS";
|
---|
910 | break;
|
---|
911 | case SEC_E_NO_IMPERSONATION:
|
---|
912 | txt = "SEC_E_NO_IMPERSONATION";
|
---|
913 | break;
|
---|
914 | case SEC_E_NO_IP_ADDRESSES:
|
---|
915 | txt = "SEC_E_NO_IP_ADDRESSES";
|
---|
916 | break;
|
---|
917 | case SEC_E_NO_KERB_KEY:
|
---|
918 | txt = "SEC_E_NO_KERB_KEY";
|
---|
919 | break;
|
---|
920 | case SEC_E_NO_PA_DATA:
|
---|
921 | txt = "SEC_E_NO_PA_DATA";
|
---|
922 | break;
|
---|
923 | case SEC_E_NO_S4U_PROT_SUPPORT:
|
---|
924 | txt = "SEC_E_NO_S4U_PROT_SUPPORT";
|
---|
925 | break;
|
---|
926 | case SEC_E_NO_TGT_REPLY:
|
---|
927 | txt = "SEC_E_NO_TGT_REPLY";
|
---|
928 | break;
|
---|
929 | case SEC_E_OUT_OF_SEQUENCE:
|
---|
930 | txt = "SEC_E_OUT_OF_SEQUENCE";
|
---|
931 | break;
|
---|
932 | case SEC_E_PKINIT_CLIENT_FAILURE:
|
---|
933 | txt = "SEC_E_PKINIT_CLIENT_FAILURE";
|
---|
934 | break;
|
---|
935 | case SEC_E_PKINIT_NAME_MISMATCH:
|
---|
936 | txt = "SEC_E_PKINIT_NAME_MISMATCH";
|
---|
937 | break;
|
---|
938 | case SEC_E_POLICY_NLTM_ONLY:
|
---|
939 | txt = "SEC_E_POLICY_NLTM_ONLY";
|
---|
940 | break;
|
---|
941 | case SEC_E_QOP_NOT_SUPPORTED:
|
---|
942 | txt = "SEC_E_QOP_NOT_SUPPORTED";
|
---|
943 | break;
|
---|
944 | case SEC_E_REVOCATION_OFFLINE_C:
|
---|
945 | txt = "SEC_E_REVOCATION_OFFLINE_C";
|
---|
946 | break;
|
---|
947 | case SEC_E_REVOCATION_OFFLINE_KDC:
|
---|
948 | txt = "SEC_E_REVOCATION_OFFLINE_KDC";
|
---|
949 | break;
|
---|
950 | case SEC_E_SECPKG_NOT_FOUND:
|
---|
951 | txt = "SEC_E_SECPKG_NOT_FOUND";
|
---|
952 | break;
|
---|
953 | case SEC_E_SECURITY_QOS_FAILED:
|
---|
954 | txt = "SEC_E_SECURITY_QOS_FAILED";
|
---|
955 | break;
|
---|
956 | case SEC_E_SHUTDOWN_IN_PROGRESS:
|
---|
957 | txt = "SEC_E_SHUTDOWN_IN_PROGRESS";
|
---|
958 | break;
|
---|
959 | case SEC_E_SMARTCARD_CERT_EXPIRED:
|
---|
960 | txt = "SEC_E_SMARTCARD_CERT_EXPIRED";
|
---|
961 | break;
|
---|
962 | case SEC_E_SMARTCARD_CERT_REVOKED:
|
---|
963 | txt = "SEC_E_SMARTCARD_CERT_REVOKED";
|
---|
964 | break;
|
---|
965 | case SEC_E_SMARTCARD_LOGON_REQUIRED:
|
---|
966 | txt = "SEC_E_SMARTCARD_LOGON_REQUIRED";
|
---|
967 | break;
|
---|
968 | case SEC_E_STRONG_CRYPTO_NOT_SUPPORTED:
|
---|
969 | txt = "SEC_E_STRONG_CRYPTO_NOT_SUPPORTED";
|
---|
970 | break;
|
---|
971 | case SEC_E_TARGET_UNKNOWN:
|
---|
972 | txt = "SEC_E_TARGET_UNKNOWN";
|
---|
973 | break;
|
---|
974 | case SEC_E_TIME_SKEW:
|
---|
975 | txt = "SEC_E_TIME_SKEW";
|
---|
976 | break;
|
---|
977 | case SEC_E_TOO_MANY_PRINCIPALS:
|
---|
978 | txt = "SEC_E_TOO_MANY_PRINCIPALS";
|
---|
979 | break;
|
---|
980 | case SEC_E_UNFINISHED_CONTEXT_DELETED:
|
---|
981 | txt = "SEC_E_UNFINISHED_CONTEXT_DELETED";
|
---|
982 | break;
|
---|
983 | case SEC_E_UNKNOWN_CREDENTIALS:
|
---|
984 | txt = "SEC_E_UNKNOWN_CREDENTIALS";
|
---|
985 | break;
|
---|
986 | case SEC_E_UNSUPPORTED_FUNCTION:
|
---|
987 | txt = "SEC_E_UNSUPPORTED_FUNCTION";
|
---|
988 | break;
|
---|
989 | case SEC_E_UNSUPPORTED_PREAUTH:
|
---|
990 | txt = "SEC_E_UNSUPPORTED_PREAUTH";
|
---|
991 | break;
|
---|
992 | case SEC_E_UNTRUSTED_ROOT:
|
---|
993 | txt = "SEC_E_UNTRUSTED_ROOT";
|
---|
994 | break;
|
---|
995 | case SEC_E_WRONG_CREDENTIAL_HANDLE:
|
---|
996 | txt = "SEC_E_WRONG_CREDENTIAL_HANDLE";
|
---|
997 | break;
|
---|
998 | case SEC_E_WRONG_PRINCIPAL:
|
---|
999 | txt = "SEC_E_WRONG_PRINCIPAL";
|
---|
1000 | break;
|
---|
1001 | case SEC_I_COMPLETE_AND_CONTINUE:
|
---|
1002 | txt = "SEC_I_COMPLETE_AND_CONTINUE";
|
---|
1003 | break;
|
---|
1004 | case SEC_I_COMPLETE_NEEDED:
|
---|
1005 | txt = "SEC_I_COMPLETE_NEEDED";
|
---|
1006 | break;
|
---|
1007 | case SEC_I_CONTEXT_EXPIRED:
|
---|
1008 | txt = "SEC_I_CONTEXT_EXPIRED";
|
---|
1009 | break;
|
---|
1010 | case SEC_I_CONTINUE_NEEDED:
|
---|
1011 | txt = "SEC_I_CONTINUE_NEEDED";
|
---|
1012 | break;
|
---|
1013 | case SEC_I_INCOMPLETE_CREDENTIALS:
|
---|
1014 | txt = "SEC_I_INCOMPLETE_CREDENTIALS";
|
---|
1015 | break;
|
---|
1016 | case SEC_I_LOCAL_LOGON:
|
---|
1017 | txt = "SEC_I_LOCAL_LOGON";
|
---|
1018 | break;
|
---|
1019 | case SEC_I_NO_LSA_CONTEXT:
|
---|
1020 | txt = "SEC_I_NO_LSA_CONTEXT";
|
---|
1021 | break;
|
---|
1022 | case SEC_I_RENEGOTIATE:
|
---|
1023 | txt = "SEC_I_RENEGOTIATE";
|
---|
1024 | break;
|
---|
1025 | case SEC_I_SIGNATURE_NEEDED:
|
---|
1026 | txt = "SEC_I_SIGNATURE_NEEDED";
|
---|
1027 | break;
|
---|
1028 | default:
|
---|
1029 | txt = "Unknown error";
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | if(err == SEC_E_OK)
|
---|
1033 | strncpy(outbuf, txt, outmax);
|
---|
1034 | else if(err == SEC_E_ILLEGAL_MESSAGE)
|
---|
1035 | msnprintf(outbuf, outmax,
|
---|
1036 | "SEC_E_ILLEGAL_MESSAGE (0x%08X) - This error usually occurs "
|
---|
1037 | "when a fatal SSL/TLS alert is received (e.g. handshake failed)."
|
---|
1038 | " More detail may be available in the Windows System event log.",
|
---|
1039 | err);
|
---|
1040 | else {
|
---|
1041 | str = txtbuf;
|
---|
1042 | msnprintf(txtbuf, sizeof(txtbuf), "%s (0x%08X)", txt, err);
|
---|
1043 | txtbuf[sizeof(txtbuf)-1] = '\0';
|
---|
1044 |
|
---|
1045 | #ifdef _WIN32_WCE
|
---|
1046 | {
|
---|
1047 | wchar_t wbuf[256];
|
---|
1048 | wbuf[0] = L'\0';
|
---|
1049 |
|
---|
1050 | if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
|
---|
1051 | FORMAT_MESSAGE_IGNORE_INSERTS,
|
---|
1052 | NULL, err, LANG_NEUTRAL,
|
---|
1053 | wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL)) {
|
---|
1054 | wcstombs(msgbuf, wbuf, sizeof(msgbuf)-1);
|
---|
1055 | msg_formatted = TRUE;
|
---|
1056 | }
|
---|
1057 | }
|
---|
1058 | #else
|
---|
1059 | if(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
|
---|
1060 | FORMAT_MESSAGE_IGNORE_INSERTS,
|
---|
1061 | NULL, err, LANG_NEUTRAL,
|
---|
1062 | msgbuf, sizeof(msgbuf)-1, NULL)) {
|
---|
1063 | msg_formatted = TRUE;
|
---|
1064 | }
|
---|
1065 | #endif
|
---|
1066 | if(msg_formatted) {
|
---|
1067 | msgbuf[sizeof(msgbuf)-1] = '\0';
|
---|
1068 | /* strip trailing '\r\n' or '\n' */
|
---|
1069 | p = strrchr(msgbuf, '\n');
|
---|
1070 | if(p && (p - msgbuf) >= 2)
|
---|
1071 | *p = '\0';
|
---|
1072 | p = strrchr(msgbuf, '\r');
|
---|
1073 | if(p && (p - msgbuf) >= 1)
|
---|
1074 | *p = '\0';
|
---|
1075 | msg = msgbuf;
|
---|
1076 | }
|
---|
1077 | if(msg)
|
---|
1078 | msnprintf(outbuf, outmax, "%s - %s", str, msg);
|
---|
1079 | else
|
---|
1080 | strncpy(outbuf, str, outmax);
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | #else
|
---|
1084 |
|
---|
1085 | if(err == SEC_E_OK)
|
---|
1086 | txt = "No error";
|
---|
1087 | else
|
---|
1088 | txt = "Error";
|
---|
1089 |
|
---|
1090 | strncpy(outbuf, txt, outmax);
|
---|
1091 |
|
---|
1092 | #endif
|
---|
1093 |
|
---|
1094 | outbuf[outmax] = '\0';
|
---|
1095 |
|
---|
1096 | if(errno != old_errno)
|
---|
1097 | errno = old_errno;
|
---|
1098 |
|
---|
1099 | #ifdef PRESERVE_WINDOWS_ERROR_CODE
|
---|
1100 | if(old_win_err != GetLastError())
|
---|
1101 | SetLastError(old_win_err);
|
---|
1102 | #endif
|
---|
1103 |
|
---|
1104 | return outbuf;
|
---|
1105 | }
|
---|
1106 | #endif /* USE_WINDOWS_SSPI */
|
---|