1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 2004 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 #include "curl_setup.h"
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"
36 #include <curl/curl.h>
42 #ifdef USE_WINDOWS_SSPI
43 #include "curl_sspi.h"
47 /* The last 3 #include files should be in this order */
48 #include "curl_printf.h"
49 #include "curl_memory.h"
52 #if defined(WIN32) || defined(_WIN32_WCE)
53 #define PRESERVE_WINDOWS_ERROR_CODE
57 curl_easy_strerror(CURLcode error)
59 #ifndef CURL_DISABLE_VERBOSE_STRINGS
64 case CURLE_UNSUPPORTED_PROTOCOL:
65 return "Unsupported protocol";
67 case CURLE_FAILED_INIT:
68 return "Failed initialization";
70 case CURLE_URL_MALFORMAT:
71 return "URL using bad/illegal format or missing URL";
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.";
77 case CURLE_COULDNT_RESOLVE_PROXY:
78 return "Couldn't resolve proxy name";
80 case CURLE_COULDNT_RESOLVE_HOST:
81 return "Couldn't resolve host name";
83 case CURLE_COULDNT_CONNECT:
84 return "Couldn't connect to server";
86 case CURLE_WEIRD_SERVER_REPLY:
87 return "Weird server reply";
89 case CURLE_REMOTE_ACCESS_DENIED:
90 return "Access denied to remote resource";
92 case CURLE_FTP_ACCEPT_FAILED:
93 return "FTP: The server failed to connect to data port";
95 case CURLE_FTP_ACCEPT_TIMEOUT:
96 return "FTP: Accepting server connect has timed out";
98 case CURLE_FTP_PRET_FAILED:
99 return "FTP: The server did not accept the PRET command.";
101 case CURLE_FTP_WEIRD_PASS_REPLY:
102 return "FTP: unknown PASS reply";
104 case CURLE_FTP_WEIRD_PASV_REPLY:
105 return "FTP: unknown PASV reply";
107 case CURLE_FTP_WEIRD_227_FORMAT:
108 return "FTP: unknown 227 response format";
110 case CURLE_FTP_CANT_GET_HOST:
111 return "FTP: can't figure out the host in the PASV response";
114 return "Error in the HTTP2 framing layer";
116 case CURLE_FTP_COULDNT_SET_TYPE:
117 return "FTP: couldn't set file type";
119 case CURLE_PARTIAL_FILE:
120 return "Transferred a partial file";
122 case CURLE_FTP_COULDNT_RETR_FILE:
123 return "FTP: couldn't retrieve (RETR failed) the specified file";
125 case CURLE_QUOTE_ERROR:
126 return "Quote command returned error";
128 case CURLE_HTTP_RETURNED_ERROR:
129 return "HTTP response code said error";
131 case CURLE_WRITE_ERROR:
132 return "Failed writing received data to disk/application";
134 case CURLE_UPLOAD_FAILED:
135 return "Upload failed (at start/before it took off)";
137 case CURLE_READ_ERROR:
138 return "Failed to open/read local data from file/application";
140 case CURLE_OUT_OF_MEMORY:
141 return "Out of memory";
143 case CURLE_OPERATION_TIMEDOUT:
144 return "Timeout was reached";
146 case CURLE_FTP_PORT_FAILED:
147 return "FTP: command PORT failed";
149 case CURLE_FTP_COULDNT_USE_REST:
150 return "FTP: command REST failed";
152 case CURLE_RANGE_ERROR:
153 return "Requested range was not delivered by the server";
155 case CURLE_HTTP_POST_ERROR:
156 return "Internal problem setting up the POST";
158 case CURLE_SSL_CONNECT_ERROR:
159 return "SSL connect error";
161 case CURLE_BAD_DOWNLOAD_RESUME:
162 return "Couldn't resume download";
164 case CURLE_FILE_COULDNT_READ_FILE:
165 return "Couldn't read a file:// file";
167 case CURLE_LDAP_CANNOT_BIND:
168 return "LDAP: cannot bind";
170 case CURLE_LDAP_SEARCH_FAILED:
171 return "LDAP: search failed";
173 case CURLE_FUNCTION_NOT_FOUND:
174 return "A required function in the library was not found";
176 case CURLE_ABORTED_BY_CALLBACK:
177 return "Operation was aborted by an application callback";
179 case CURLE_BAD_FUNCTION_ARGUMENT:
180 return "A libcurl function was given a bad argument";
182 case CURLE_INTERFACE_FAILED:
183 return "Failed binding local connection end";
185 case CURLE_TOO_MANY_REDIRECTS :
186 return "Number of redirects hit maximum amount";
188 case CURLE_UNKNOWN_OPTION:
189 return "An unknown option was passed in to libcurl";
191 case CURLE_TELNET_OPTION_SYNTAX :
192 return "Malformed telnet option";
194 case CURLE_PEER_FAILED_VERIFICATION:
195 return "SSL peer certificate or SSH remote key was not OK";
197 case CURLE_GOT_NOTHING:
198 return "Server returned nothing (no headers, no data)";
200 case CURLE_SSL_ENGINE_NOTFOUND:
201 return "SSL crypto engine not found";
203 case CURLE_SSL_ENGINE_SETFAILED:
204 return "Can not set SSL crypto engine as default";
206 case CURLE_SSL_ENGINE_INITFAILED:
207 return "Failed to initialise SSL crypto engine";
209 case CURLE_SEND_ERROR:
210 return "Failed sending data to the peer";
212 case CURLE_RECV_ERROR:
213 return "Failure when receiving data from the peer";
215 case CURLE_SSL_CERTPROBLEM:
216 return "Problem with the local SSL certificate";
218 case CURLE_SSL_CIPHER:
219 return "Couldn't use specified SSL cipher";
221 case CURLE_SSL_CACERT:
222 return "Peer certificate cannot be authenticated with given CA "
225 case CURLE_SSL_CACERT_BADFILE:
226 return "Problem with the SSL CA cert (path? access rights?)";
228 case CURLE_BAD_CONTENT_ENCODING:
229 return "Unrecognized or bad HTTP Content or Transfer-Encoding";
231 case CURLE_LDAP_INVALID_URL:
232 return "Invalid LDAP URL";
234 case CURLE_FILESIZE_EXCEEDED:
235 return "Maximum file size exceeded";
237 case CURLE_USE_SSL_FAILED:
238 return "Requested SSL level failed";
240 case CURLE_SSL_SHUTDOWN_FAILED:
241 return "Failed to shut down the SSL connection";
243 case CURLE_SSL_CRL_BADFILE:
244 return "Failed to load CRL file (path? access rights?, format?)";
246 case CURLE_SSL_ISSUER_ERROR:
247 return "Issuer check against peer certificate failed";
249 case CURLE_SEND_FAIL_REWIND:
250 return "Send failed since rewinding of the data stream failed";
252 case CURLE_LOGIN_DENIED:
253 return "Login denied";
255 case CURLE_TFTP_NOTFOUND:
256 return "TFTP: File Not Found";
258 case CURLE_TFTP_PERM:
259 return "TFTP: Access Violation";
261 case CURLE_REMOTE_DISK_FULL:
262 return "Disk full or allocation exceeded";
264 case CURLE_TFTP_ILLEGAL:
265 return "TFTP: Illegal operation";
267 case CURLE_TFTP_UNKNOWNID:
268 return "TFTP: Unknown transfer ID";
270 case CURLE_REMOTE_FILE_EXISTS:
271 return "Remote file already exists";
273 case CURLE_TFTP_NOSUCHUSER:
274 return "TFTP: No such user";
276 case CURLE_CONV_FAILED:
277 return "Conversion failed";
279 case CURLE_CONV_REQD:
280 return "Caller must register CURLOPT_CONV_ callback options";
282 case CURLE_REMOTE_FILE_NOT_FOUND:
283 return "Remote file not found";
286 return "Error in the SSH layer";
289 return "Socket not ready for send/recv";
291 case CURLE_RTSP_CSEQ_ERROR:
292 return "RTSP CSeq mismatch or invalid CSeq";
294 case CURLE_RTSP_SESSION_ERROR:
295 return "RTSP session error";
297 case CURLE_FTP_BAD_FILE_LIST:
298 return "Unable to parse FTP file list";
300 case CURLE_CHUNK_FAILED:
301 return "Chunk callback failed";
303 case CURLE_NO_CONNECTION_AVAILABLE:
304 return "The max connection limit is reached";
306 case CURLE_SSL_PINNEDPUBKEYNOTMATCH:
307 return "SSL public key does not match pinned public key";
309 case CURLE_SSL_INVALIDCERTSTATUS:
310 return "SSL server certificate status verification FAILED";
312 case CURLE_HTTP2_STREAM:
313 return "Stream error in the HTTP/2 framing layer";
315 case CURLE_RECURSIVE_API_CALL:
316 return "API function called from within callback";
318 /* error codes not used by current libcurl */
319 case CURLE_OBSOLETE20:
320 case CURLE_OBSOLETE24:
321 case CURLE_OBSOLETE29:
322 case CURLE_OBSOLETE32:
323 case CURLE_OBSOLETE40:
324 case CURLE_OBSOLETE44:
325 case CURLE_OBSOLETE46:
326 case CURLE_OBSOLETE50:
327 case CURLE_OBSOLETE57:
332 * By using a switch, gcc -Wall will complain about enum values
333 * which do not appear, helping keep this function up-to-date.
334 * By using gcc -Wall -Werror, you can't forget.
336 * A table would not have the same benefit. Most compilers will
337 * generate code very similar to a table in any case, so there
338 * is little performance gain from a table. And something is broken
339 * for the user's application, anyways, so does it matter how fast
342 * The line number for the error will be near this comment, which
343 * is why it is here, and not at the start of the switch.
345 return "Unknown error";
355 curl_multi_strerror(CURLMcode error)
357 #ifndef CURL_DISABLE_VERBOSE_STRINGS
359 case CURLM_CALL_MULTI_PERFORM:
360 return "Please call curl_multi_perform() soon";
365 case CURLM_BAD_HANDLE:
366 return "Invalid multi handle";
368 case CURLM_BAD_EASY_HANDLE:
369 return "Invalid easy handle";
371 case CURLM_OUT_OF_MEMORY:
372 return "Out of memory";
374 case CURLM_INTERNAL_ERROR:
375 return "Internal error";
377 case CURLM_BAD_SOCKET:
378 return "Invalid socket argument";
380 case CURLM_UNKNOWN_OPTION:
381 return "Unknown option";
383 case CURLM_ADDED_ALREADY:
384 return "The easy handle is already added to a multi handle";
386 case CURLM_RECURSIVE_API_CALL:
387 return "API function called from within callback";
393 return "Unknown error";
395 if(error == CURLM_OK)
403 curl_share_strerror(CURLSHcode error)
405 #ifndef CURL_DISABLE_VERBOSE_STRINGS
410 case CURLSHE_BAD_OPTION:
411 return "Unknown share option";
414 return "Share currently in use";
416 case CURLSHE_INVALID:
417 return "Invalid share handle";
420 return "Out of memory";
422 case CURLSHE_NOT_BUILT_IN:
423 return "Feature not enabled in this library";
429 return "CURLSHcode unknown";
431 if(error == CURLSHE_OK)
440 /* This function handles most / all (?) Winsock errors curl is able to produce.
443 get_winsock_error (int err, char *buf, size_t len)
445 #ifdef PRESERVE_WINDOWS_ERROR_CODE
446 DWORD old_win_err = GetLastError();
448 int old_errno = errno;
451 #ifndef CURL_DISABLE_VERBOSE_STRINGS
454 p = "Call interrupted";
466 p = "Invalid arguments";
469 p = "Out of file descriptors";
472 p = "Call would block";
476 p = "Blocking call in progress";
479 p = "Descriptor is not a socket";
481 case WSAEDESTADDRREQ:
482 p = "Need destination address";
485 p = "Bad message size";
491 p = "Protocol option is unsupported";
493 case WSAEPROTONOSUPPORT:
494 p = "Protocol is unsupported";
496 case WSAESOCKTNOSUPPORT:
497 p = "Socket is unsupported";
500 p = "Operation not supported";
502 case WSAEAFNOSUPPORT:
503 p = "Address family not supported";
505 case WSAEPFNOSUPPORT:
506 p = "Protocol family not supported";
509 p = "Address already in use";
511 case WSAEADDRNOTAVAIL:
512 p = "Address not available";
518 p = "Network unreachable";
521 p = "Network has been reset";
523 case WSAECONNABORTED:
524 p = "Connection was aborted";
527 p = "Connection was reset";
530 p = "No buffer space";
533 p = "Socket is already connected";
536 p = "Socket is not connected";
539 p = "Socket has been shut down";
541 case WSAETOOMANYREFS:
542 p = "Too many references";
547 case WSAECONNREFUSED:
548 p = "Connection refused";
553 case WSAENAMETOOLONG:
559 case WSAEHOSTUNREACH:
560 p = "Host unreachable";
566 p = "Process limit reached";
569 p = "Too many users";
575 p = "Something is stale";
580 #ifdef WSAEDISCON /* missing in SalfordC! */
585 /* Extended Winsock errors */
587 p = "Winsock library is not ready";
589 case WSANOTINITIALISED:
590 p = "Winsock library not initialised";
592 case WSAVERNOTSUPPORTED:
593 p = "Winsock version not supported";
596 /* getXbyY() errors (already handled in herrmsg):
597 * Authoritative Answer: Host not found */
598 case WSAHOST_NOT_FOUND:
599 p = "Host not found";
602 /* Non-Authoritative: Host not found, or SERVERFAIL */
604 p = "Host not found, try again";
607 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
609 p = "Unrecoverable error in call to nameserver";
612 /* Valid name, no data record of requested type */
614 p = "No data record of requested type";
626 strncpy(buf, p, len);
629 if(errno != old_errno)
632 #ifdef PRESERVE_WINDOWS_ERROR_CODE
633 if(old_win_err != GetLastError())
634 SetLastError(old_win_err);
639 #endif /* USE_WINSOCK */
642 * Our thread-safe and smart strerror() replacement.
644 * The 'err' argument passed in to this function MUST be a true errno number
645 * as reported on this system. We do no range checking on the number before
646 * we pass it to the "number-to-message" conversion function and there might
647 * be systems that don't do proper range checking in there themselves.
649 * We don't do range checking (on systems other than Windows) since there is
650 * no good reliable and portable way to do it.
652 const char *Curl_strerror(struct connectdata *conn, int err)
654 #ifdef PRESERVE_WINDOWS_ERROR_CODE
655 DWORD old_win_err = GetLastError();
657 int old_errno = errno;
662 DEBUGASSERT(err >= 0);
664 buf = conn->syserr_buf;
665 max = sizeof(conn->syserr_buf)-1;
675 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
676 LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL);
677 wcstombs(buf, wbuf, max);
680 /* 'sys_nerr' is the maximum errno number, it is not widely portable */
681 if(err >= 0 && err < sys_nerr)
682 strncpy(buf, strerror(err), max);
684 if(!get_winsock_error(err, buf, max) &&
685 !FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
686 LANG_NEUTRAL, buf, (DWORD)max, NULL))
687 snprintf(buf, max, "Unknown error %d (%#x)", err, err);
691 #else /* not USE_WINSOCK coming up */
693 #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R)
695 * The POSIX-style strerror_r() may set errno to ERANGE if insufficient
696 * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated
697 * message string, or EINVAL if 'errnum' is not a valid error number.
699 if(0 != strerror_r(err, buf, max)) {
701 snprintf(buf, max, "Unknown error %d", err);
703 #elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)
705 * The glibc-style strerror_r() only *might* use the buffer we pass to
706 * the function, but it always returns the error message as a pointer,
707 * so we must copy that string unconditionally (if non-NULL).
711 char *msg = strerror_r(err, buffer, sizeof(buffer));
713 strncpy(buf, msg, max);
715 snprintf(buf, max, "Unknown error %d", err);
717 #elif defined(HAVE_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)
719 * The vxworks-style strerror_r() does use the buffer we pass to the function.
720 * The buffer size should be at least NAME_MAX (256)
724 if(OK == strerror_r(err, buffer))
725 strncpy(buf, buffer, max);
727 snprintf(buf, max, "Unknown error %d", err);
731 char *msg = strerror(err);
733 strncpy(buf, msg, max);
735 snprintf(buf, max, "Unknown error %d", err);
739 #endif /* end of ! USE_WINSOCK */
741 buf[max] = '\0'; /* make sure the string is zero terminated */
743 /* strip trailing '\r\n' or '\n'. */
744 p = strrchr(buf, '\n');
745 if(p && (p - buf) >= 2)
747 p = strrchr(buf, '\r');
748 if(p && (p - buf) >= 1)
751 if(errno != old_errno)
754 #ifdef PRESERVE_WINDOWS_ERROR_CODE
755 if(old_win_err != GetLastError())
756 SetLastError(old_win_err);
762 #ifdef USE_WINDOWS_SSPI
763 const char *Curl_sspi_strerror (struct connectdata *conn, int err)
765 #ifdef PRESERVE_WINDOWS_ERROR_CODE
766 DWORD old_win_err = GetLastError();
768 int old_errno = errno;
772 #ifndef CURL_DISABLE_VERBOSE_STRINGS
774 char msgbuf[sizeof(conn->syserr_buf)];
775 char *p, *str, *msg = NULL;
776 bool msg_formatted = FALSE;
781 outbuf = conn->syserr_buf;
782 outmax = sizeof(conn->syserr_buf)-1;
785 #ifndef CURL_DISABLE_VERBOSE_STRINGS
791 case CRYPT_E_REVOKED:
792 txt = "CRYPT_E_REVOKED";
794 case SEC_E_ALGORITHM_MISMATCH:
795 txt = "SEC_E_ALGORITHM_MISMATCH";
797 case SEC_E_BAD_BINDINGS:
798 txt = "SEC_E_BAD_BINDINGS";
800 case SEC_E_BAD_PKGID:
801 txt = "SEC_E_BAD_PKGID";
803 case SEC_E_BUFFER_TOO_SMALL:
804 txt = "SEC_E_BUFFER_TOO_SMALL";
806 case SEC_E_CANNOT_INSTALL:
807 txt = "SEC_E_CANNOT_INSTALL";
809 case SEC_E_CANNOT_PACK:
810 txt = "SEC_E_CANNOT_PACK";
812 case SEC_E_CERT_EXPIRED:
813 txt = "SEC_E_CERT_EXPIRED";
815 case SEC_E_CERT_UNKNOWN:
816 txt = "SEC_E_CERT_UNKNOWN";
818 case SEC_E_CERT_WRONG_USAGE:
819 txt = "SEC_E_CERT_WRONG_USAGE";
821 case SEC_E_CONTEXT_EXPIRED:
822 txt = "SEC_E_CONTEXT_EXPIRED";
824 case SEC_E_CROSSREALM_DELEGATION_FAILURE:
825 txt = "SEC_E_CROSSREALM_DELEGATION_FAILURE";
827 case SEC_E_CRYPTO_SYSTEM_INVALID:
828 txt = "SEC_E_CRYPTO_SYSTEM_INVALID";
830 case SEC_E_DECRYPT_FAILURE:
831 txt = "SEC_E_DECRYPT_FAILURE";
833 case SEC_E_DELEGATION_POLICY:
834 txt = "SEC_E_DELEGATION_POLICY";
836 case SEC_E_DELEGATION_REQUIRED:
837 txt = "SEC_E_DELEGATION_REQUIRED";
839 case SEC_E_DOWNGRADE_DETECTED:
840 txt = "SEC_E_DOWNGRADE_DETECTED";
842 case SEC_E_ENCRYPT_FAILURE:
843 txt = "SEC_E_ENCRYPT_FAILURE";
845 case SEC_E_ILLEGAL_MESSAGE:
846 txt = "SEC_E_ILLEGAL_MESSAGE";
848 case SEC_E_INCOMPLETE_CREDENTIALS:
849 txt = "SEC_E_INCOMPLETE_CREDENTIALS";
851 case SEC_E_INCOMPLETE_MESSAGE:
852 txt = "SEC_E_INCOMPLETE_MESSAGE";
854 case SEC_E_INSUFFICIENT_MEMORY:
855 txt = "SEC_E_INSUFFICIENT_MEMORY";
857 case SEC_E_INTERNAL_ERROR:
858 txt = "SEC_E_INTERNAL_ERROR";
860 case SEC_E_INVALID_HANDLE:
861 txt = "SEC_E_INVALID_HANDLE";
863 case SEC_E_INVALID_PARAMETER:
864 txt = "SEC_E_INVALID_PARAMETER";
866 case SEC_E_INVALID_TOKEN:
867 txt = "SEC_E_INVALID_TOKEN";
869 case SEC_E_ISSUING_CA_UNTRUSTED:
870 txt = "SEC_E_ISSUING_CA_UNTRUSTED";
872 case SEC_E_ISSUING_CA_UNTRUSTED_KDC:
873 txt = "SEC_E_ISSUING_CA_UNTRUSTED_KDC";
875 case SEC_E_KDC_CERT_EXPIRED:
876 txt = "SEC_E_KDC_CERT_EXPIRED";
878 case SEC_E_KDC_CERT_REVOKED:
879 txt = "SEC_E_KDC_CERT_REVOKED";
881 case SEC_E_KDC_INVALID_REQUEST:
882 txt = "SEC_E_KDC_INVALID_REQUEST";
884 case SEC_E_KDC_UNABLE_TO_REFER:
885 txt = "SEC_E_KDC_UNABLE_TO_REFER";
887 case SEC_E_KDC_UNKNOWN_ETYPE:
888 txt = "SEC_E_KDC_UNKNOWN_ETYPE";
890 case SEC_E_LOGON_DENIED:
891 txt = "SEC_E_LOGON_DENIED";
893 case SEC_E_MAX_REFERRALS_EXCEEDED:
894 txt = "SEC_E_MAX_REFERRALS_EXCEEDED";
896 case SEC_E_MESSAGE_ALTERED:
897 txt = "SEC_E_MESSAGE_ALTERED";
899 case SEC_E_MULTIPLE_ACCOUNTS:
900 txt = "SEC_E_MULTIPLE_ACCOUNTS";
902 case SEC_E_MUST_BE_KDC:
903 txt = "SEC_E_MUST_BE_KDC";
905 case SEC_E_NOT_OWNER:
906 txt = "SEC_E_NOT_OWNER";
908 case SEC_E_NO_AUTHENTICATING_AUTHORITY:
909 txt = "SEC_E_NO_AUTHENTICATING_AUTHORITY";
911 case SEC_E_NO_CREDENTIALS:
912 txt = "SEC_E_NO_CREDENTIALS";
914 case SEC_E_NO_IMPERSONATION:
915 txt = "SEC_E_NO_IMPERSONATION";
917 case SEC_E_NO_IP_ADDRESSES:
918 txt = "SEC_E_NO_IP_ADDRESSES";
920 case SEC_E_NO_KERB_KEY:
921 txt = "SEC_E_NO_KERB_KEY";
923 case SEC_E_NO_PA_DATA:
924 txt = "SEC_E_NO_PA_DATA";
926 case SEC_E_NO_S4U_PROT_SUPPORT:
927 txt = "SEC_E_NO_S4U_PROT_SUPPORT";
929 case SEC_E_NO_TGT_REPLY:
930 txt = "SEC_E_NO_TGT_REPLY";
932 case SEC_E_OUT_OF_SEQUENCE:
933 txt = "SEC_E_OUT_OF_SEQUENCE";
935 case SEC_E_PKINIT_CLIENT_FAILURE:
936 txt = "SEC_E_PKINIT_CLIENT_FAILURE";
938 case SEC_E_PKINIT_NAME_MISMATCH:
939 txt = "SEC_E_PKINIT_NAME_MISMATCH";
941 case SEC_E_POLICY_NLTM_ONLY:
942 txt = "SEC_E_POLICY_NLTM_ONLY";
944 case SEC_E_QOP_NOT_SUPPORTED:
945 txt = "SEC_E_QOP_NOT_SUPPORTED";
947 case SEC_E_REVOCATION_OFFLINE_C:
948 txt = "SEC_E_REVOCATION_OFFLINE_C";
950 case SEC_E_REVOCATION_OFFLINE_KDC:
951 txt = "SEC_E_REVOCATION_OFFLINE_KDC";
953 case SEC_E_SECPKG_NOT_FOUND:
954 txt = "SEC_E_SECPKG_NOT_FOUND";
956 case SEC_E_SECURITY_QOS_FAILED:
957 txt = "SEC_E_SECURITY_QOS_FAILED";
959 case SEC_E_SHUTDOWN_IN_PROGRESS:
960 txt = "SEC_E_SHUTDOWN_IN_PROGRESS";
962 case SEC_E_SMARTCARD_CERT_EXPIRED:
963 txt = "SEC_E_SMARTCARD_CERT_EXPIRED";
965 case SEC_E_SMARTCARD_CERT_REVOKED:
966 txt = "SEC_E_SMARTCARD_CERT_REVOKED";
968 case SEC_E_SMARTCARD_LOGON_REQUIRED:
969 txt = "SEC_E_SMARTCARD_LOGON_REQUIRED";
971 case SEC_E_STRONG_CRYPTO_NOT_SUPPORTED:
972 txt = "SEC_E_STRONG_CRYPTO_NOT_SUPPORTED";
974 case SEC_E_TARGET_UNKNOWN:
975 txt = "SEC_E_TARGET_UNKNOWN";
977 case SEC_E_TIME_SKEW:
978 txt = "SEC_E_TIME_SKEW";
980 case SEC_E_TOO_MANY_PRINCIPALS:
981 txt = "SEC_E_TOO_MANY_PRINCIPALS";
983 case SEC_E_UNFINISHED_CONTEXT_DELETED:
984 txt = "SEC_E_UNFINISHED_CONTEXT_DELETED";
986 case SEC_E_UNKNOWN_CREDENTIALS:
987 txt = "SEC_E_UNKNOWN_CREDENTIALS";
989 case SEC_E_UNSUPPORTED_FUNCTION:
990 txt = "SEC_E_UNSUPPORTED_FUNCTION";
992 case SEC_E_UNSUPPORTED_PREAUTH:
993 txt = "SEC_E_UNSUPPORTED_PREAUTH";
995 case SEC_E_UNTRUSTED_ROOT:
996 txt = "SEC_E_UNTRUSTED_ROOT";
998 case SEC_E_WRONG_CREDENTIAL_HANDLE:
999 txt = "SEC_E_WRONG_CREDENTIAL_HANDLE";
1001 case SEC_E_WRONG_PRINCIPAL:
1002 txt = "SEC_E_WRONG_PRINCIPAL";
1004 case SEC_I_COMPLETE_AND_CONTINUE:
1005 txt = "SEC_I_COMPLETE_AND_CONTINUE";
1007 case SEC_I_COMPLETE_NEEDED:
1008 txt = "SEC_I_COMPLETE_NEEDED";
1010 case SEC_I_CONTEXT_EXPIRED:
1011 txt = "SEC_I_CONTEXT_EXPIRED";
1013 case SEC_I_CONTINUE_NEEDED:
1014 txt = "SEC_I_CONTINUE_NEEDED";
1016 case SEC_I_INCOMPLETE_CREDENTIALS:
1017 txt = "SEC_I_INCOMPLETE_CREDENTIALS";
1019 case SEC_I_LOCAL_LOGON:
1020 txt = "SEC_I_LOCAL_LOGON";
1022 case SEC_I_NO_LSA_CONTEXT:
1023 txt = "SEC_I_NO_LSA_CONTEXT";
1025 case SEC_I_RENEGOTIATE:
1026 txt = "SEC_I_RENEGOTIATE";
1028 case SEC_I_SIGNATURE_NEEDED:
1029 txt = "SEC_I_SIGNATURE_NEEDED";
1032 txt = "Unknown error";
1036 strncpy(outbuf, txt, outmax);
1037 else if(err == SEC_E_ILLEGAL_MESSAGE)
1038 snprintf(outbuf, outmax,
1039 "SEC_E_ILLEGAL_MESSAGE (0x%08X) - This error usually occurs "
1040 "when a fatal SSL/TLS alert is received (e.g. handshake failed). "
1041 "More detail may be available in the Windows System event log.",
1045 snprintf(txtbuf, sizeof(txtbuf), "%s (0x%08X)", txt, err);
1046 txtbuf[sizeof(txtbuf)-1] = '\0';
1053 if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
1054 FORMAT_MESSAGE_IGNORE_INSERTS,
1055 NULL, err, LANG_NEUTRAL,
1056 wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL)) {
1057 wcstombs(msgbuf, wbuf, sizeof(msgbuf)-1);
1058 msg_formatted = TRUE;
1062 if(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
1063 FORMAT_MESSAGE_IGNORE_INSERTS,
1064 NULL, err, LANG_NEUTRAL,
1065 msgbuf, sizeof(msgbuf)-1, NULL)) {
1066 msg_formatted = TRUE;
1070 msgbuf[sizeof(msgbuf)-1] = '\0';
1071 /* strip trailing '\r\n' or '\n' */
1072 p = strrchr(msgbuf, '\n');
1073 if(p && (p - msgbuf) >= 2)
1075 p = strrchr(msgbuf, '\r');
1076 if(p && (p - msgbuf) >= 1)
1081 snprintf(outbuf, outmax, "%s - %s", str, msg);
1083 strncpy(outbuf, str, outmax);
1093 strncpy(outbuf, txt, outmax);
1097 outbuf[outmax] = '\0';
1099 if(errno != old_errno)
1102 #ifdef PRESERVE_WINDOWS_ERROR_CODE
1103 if(old_win_err != GetLastError())
1104 SetLastError(old_win_err);
1109 #endif /* USE_WINDOWS_SSPI */