strerror.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 2004 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 
00023 #include "curl_setup.h"
00024 
00025 #ifdef HAVE_STRERROR_R
00026 #  if (!defined(HAVE_POSIX_STRERROR_R) && \
00027        !defined(HAVE_GLIBC_STRERROR_R) && \
00028        !defined(HAVE_VXWORKS_STRERROR_R)) || \
00029       (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \
00030       (defined(HAVE_GLIBC_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \
00031       (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R))
00032 #    error "strerror_r MUST be either POSIX, glibc or vxworks-style"
00033 #  endif
00034 #endif
00035 
00036 #include <curl/curl.h>
00037 
00038 #ifdef USE_LIBIDN2
00039 #include <idn2.h>
00040 #endif
00041 
00042 #ifdef USE_WINDOWS_SSPI
00043 #include "curl_sspi.h"
00044 #endif
00045 
00046 #include "strerror.h"
00047 /* The last 3 #include files should be in this order */
00048 #include "curl_printf.h"
00049 #include "curl_memory.h"
00050 #include "memdebug.h"
00051 
00052 const char *
00053 curl_easy_strerror(CURLcode error)
00054 {
00055 #ifndef CURL_DISABLE_VERBOSE_STRINGS
00056   switch(error) {
00057   case CURLE_OK:
00058     return "No error";
00059 
00060   case CURLE_UNSUPPORTED_PROTOCOL:
00061     return "Unsupported protocol";
00062 
00063   case CURLE_FAILED_INIT:
00064     return "Failed initialization";
00065 
00066   case CURLE_URL_MALFORMAT:
00067     return "URL using bad/illegal format or missing URL";
00068 
00069   case CURLE_NOT_BUILT_IN:
00070     return "A requested feature, protocol or option was not found built-in in"
00071       " this libcurl due to a build-time decision.";
00072 
00073   case CURLE_COULDNT_RESOLVE_PROXY:
00074     return "Couldn't resolve proxy name";
00075 
00076   case CURLE_COULDNT_RESOLVE_HOST:
00077     return "Couldn't resolve host name";
00078 
00079   case CURLE_COULDNT_CONNECT:
00080     return "Couldn't connect to server";
00081 
00082   case CURLE_WEIRD_SERVER_REPLY:
00083     return "Weird server reply";
00084 
00085   case CURLE_REMOTE_ACCESS_DENIED:
00086     return "Access denied to remote resource";
00087 
00088   case CURLE_FTP_ACCEPT_FAILED:
00089     return "FTP: The server failed to connect to data port";
00090 
00091   case CURLE_FTP_ACCEPT_TIMEOUT:
00092     return "FTP: Accepting server connect has timed out";
00093 
00094   case CURLE_FTP_PRET_FAILED:
00095     return "FTP: The server did not accept the PRET command.";
00096 
00097   case CURLE_FTP_WEIRD_PASS_REPLY:
00098     return "FTP: unknown PASS reply";
00099 
00100   case CURLE_FTP_WEIRD_PASV_REPLY:
00101     return "FTP: unknown PASV reply";
00102 
00103   case CURLE_FTP_WEIRD_227_FORMAT:
00104     return "FTP: unknown 227 response format";
00105 
00106   case CURLE_FTP_CANT_GET_HOST:
00107     return "FTP: can't figure out the host in the PASV response";
00108 
00109   case CURLE_HTTP2:
00110     return "Error in the HTTP2 framing layer";
00111 
00112   case CURLE_FTP_COULDNT_SET_TYPE:
00113     return "FTP: couldn't set file type";
00114 
00115   case CURLE_PARTIAL_FILE:
00116     return "Transferred a partial file";
00117 
00118   case CURLE_FTP_COULDNT_RETR_FILE:
00119     return "FTP: couldn't retrieve (RETR failed) the specified file";
00120 
00121   case CURLE_QUOTE_ERROR:
00122     return "Quote command returned error";
00123 
00124   case CURLE_HTTP_RETURNED_ERROR:
00125     return "HTTP response code said error";
00126 
00127   case CURLE_WRITE_ERROR:
00128     return "Failed writing received data to disk/application";
00129 
00130   case CURLE_UPLOAD_FAILED:
00131     return "Upload failed (at start/before it took off)";
00132 
00133   case CURLE_READ_ERROR:
00134     return "Failed to open/read local data from file/application";
00135 
00136   case CURLE_OUT_OF_MEMORY:
00137     return "Out of memory";
00138 
00139   case CURLE_OPERATION_TIMEDOUT:
00140     return "Timeout was reached";
00141 
00142   case CURLE_FTP_PORT_FAILED:
00143     return "FTP: command PORT failed";
00144 
00145   case CURLE_FTP_COULDNT_USE_REST:
00146     return "FTP: command REST failed";
00147 
00148   case CURLE_RANGE_ERROR:
00149     return "Requested range was not delivered by the server";
00150 
00151   case CURLE_HTTP_POST_ERROR:
00152     return "Internal problem setting up the POST";
00153 
00154   case CURLE_SSL_CONNECT_ERROR:
00155     return "SSL connect error";
00156 
00157   case CURLE_BAD_DOWNLOAD_RESUME:
00158     return "Couldn't resume download";
00159 
00160   case CURLE_FILE_COULDNT_READ_FILE:
00161     return "Couldn't read a file:// file";
00162 
00163   case CURLE_LDAP_CANNOT_BIND:
00164     return "LDAP: cannot bind";
00165 
00166   case CURLE_LDAP_SEARCH_FAILED:
00167     return "LDAP: search failed";
00168 
00169   case CURLE_FUNCTION_NOT_FOUND:
00170     return "A required function in the library was not found";
00171 
00172   case CURLE_ABORTED_BY_CALLBACK:
00173     return "Operation was aborted by an application callback";
00174 
00175   case CURLE_BAD_FUNCTION_ARGUMENT:
00176     return "A libcurl function was given a bad argument";
00177 
00178   case CURLE_INTERFACE_FAILED:
00179     return "Failed binding local connection end";
00180 
00181   case CURLE_TOO_MANY_REDIRECTS :
00182     return "Number of redirects hit maximum amount";
00183 
00184   case CURLE_UNKNOWN_OPTION:
00185     return "An unknown option was passed in to libcurl";
00186 
00187   case CURLE_TELNET_OPTION_SYNTAX :
00188     return "Malformed telnet option";
00189 
00190   case CURLE_PEER_FAILED_VERIFICATION:
00191     return "SSL peer certificate or SSH remote key was not OK";
00192 
00193   case CURLE_GOT_NOTHING:
00194     return "Server returned nothing (no headers, no data)";
00195 
00196   case CURLE_SSL_ENGINE_NOTFOUND:
00197     return "SSL crypto engine not found";
00198 
00199   case CURLE_SSL_ENGINE_SETFAILED:
00200     return "Can not set SSL crypto engine as default";
00201 
00202   case CURLE_SSL_ENGINE_INITFAILED:
00203     return "Failed to initialise SSL crypto engine";
00204 
00205   case CURLE_SEND_ERROR:
00206     return "Failed sending data to the peer";
00207 
00208   case CURLE_RECV_ERROR:
00209     return "Failure when receiving data from the peer";
00210 
00211   case CURLE_SSL_CERTPROBLEM:
00212     return "Problem with the local SSL certificate";
00213 
00214   case CURLE_SSL_CIPHER:
00215     return "Couldn't use specified SSL cipher";
00216 
00217   case CURLE_SSL_CACERT:
00218     return "Peer certificate cannot be authenticated with given CA "
00219       "certificates";
00220 
00221   case CURLE_SSL_CACERT_BADFILE:
00222     return "Problem with the SSL CA cert (path? access rights?)";
00223 
00224   case CURLE_BAD_CONTENT_ENCODING:
00225     return "Unrecognized or bad HTTP Content or Transfer-Encoding";
00226 
00227   case CURLE_LDAP_INVALID_URL:
00228     return "Invalid LDAP URL";
00229 
00230   case CURLE_FILESIZE_EXCEEDED:
00231     return "Maximum file size exceeded";
00232 
00233   case CURLE_USE_SSL_FAILED:
00234     return "Requested SSL level failed";
00235 
00236   case CURLE_SSL_SHUTDOWN_FAILED:
00237     return "Failed to shut down the SSL connection";
00238 
00239   case CURLE_SSL_CRL_BADFILE:
00240     return "Failed to load CRL file (path? access rights?, format?)";
00241 
00242   case CURLE_SSL_ISSUER_ERROR:
00243     return "Issuer check against peer certificate failed";
00244 
00245   case CURLE_SEND_FAIL_REWIND:
00246     return "Send failed since rewinding of the data stream failed";
00247 
00248   case CURLE_LOGIN_DENIED:
00249     return "Login denied";
00250 
00251   case CURLE_TFTP_NOTFOUND:
00252     return "TFTP: File Not Found";
00253 
00254   case CURLE_TFTP_PERM:
00255     return "TFTP: Access Violation";
00256 
00257   case CURLE_REMOTE_DISK_FULL:
00258     return "Disk full or allocation exceeded";
00259 
00260   case CURLE_TFTP_ILLEGAL:
00261     return "TFTP: Illegal operation";
00262 
00263   case CURLE_TFTP_UNKNOWNID:
00264     return "TFTP: Unknown transfer ID";
00265 
00266   case CURLE_REMOTE_FILE_EXISTS:
00267     return "Remote file already exists";
00268 
00269   case CURLE_TFTP_NOSUCHUSER:
00270     return "TFTP: No such user";
00271 
00272   case CURLE_CONV_FAILED:
00273     return "Conversion failed";
00274 
00275   case CURLE_CONV_REQD:
00276     return "Caller must register CURLOPT_CONV_ callback options";
00277 
00278   case CURLE_REMOTE_FILE_NOT_FOUND:
00279     return "Remote file not found";
00280 
00281   case CURLE_SSH:
00282     return "Error in the SSH layer";
00283 
00284   case CURLE_AGAIN:
00285     return "Socket not ready for send/recv";
00286 
00287   case CURLE_RTSP_CSEQ_ERROR:
00288     return "RTSP CSeq mismatch or invalid CSeq";
00289 
00290   case CURLE_RTSP_SESSION_ERROR:
00291     return "RTSP session error";
00292 
00293   case CURLE_FTP_BAD_FILE_LIST:
00294     return "Unable to parse FTP file list";
00295 
00296   case CURLE_CHUNK_FAILED:
00297     return "Chunk callback failed";
00298 
00299   case CURLE_NO_CONNECTION_AVAILABLE:
00300     return "The max connection limit is reached";
00301 
00302   case CURLE_SSL_PINNEDPUBKEYNOTMATCH:
00303     return "SSL public key does not match pinned public key";
00304 
00305   case CURLE_SSL_INVALIDCERTSTATUS:
00306     return "SSL server certificate status verification FAILED";
00307 
00308   case CURLE_HTTP2_STREAM:
00309     return "Stream error in the HTTP/2 framing layer";
00310 
00311     /* error codes not used by current libcurl */
00312   case CURLE_OBSOLETE20:
00313   case CURLE_OBSOLETE24:
00314   case CURLE_OBSOLETE29:
00315   case CURLE_OBSOLETE32:
00316   case CURLE_OBSOLETE40:
00317   case CURLE_OBSOLETE44:
00318   case CURLE_OBSOLETE46:
00319   case CURLE_OBSOLETE50:
00320   case CURLE_OBSOLETE57:
00321   case CURL_LAST:
00322     break;
00323   }
00324   /*
00325    * By using a switch, gcc -Wall will complain about enum values
00326    * which do not appear, helping keep this function up-to-date.
00327    * By using gcc -Wall -Werror, you can't forget.
00328    *
00329    * A table would not have the same benefit.  Most compilers will
00330    * generate code very similar to a table in any case, so there
00331    * is little performance gain from a table.  And something is broken
00332    * for the user's application, anyways, so does it matter how fast
00333    * it _doesn't_ work?
00334    *
00335    * The line number for the error will be near this comment, which
00336    * is why it is here, and not at the start of the switch.
00337    */
00338   return "Unknown error";
00339 #else
00340   if(!error)
00341     return "No error";
00342   else
00343     return "Error";
00344 #endif
00345 }
00346 
00347 const char *
00348 curl_multi_strerror(CURLMcode error)
00349 {
00350 #ifndef CURL_DISABLE_VERBOSE_STRINGS
00351   switch(error) {
00352   case CURLM_CALL_MULTI_PERFORM:
00353     return "Please call curl_multi_perform() soon";
00354 
00355   case CURLM_OK:
00356     return "No error";
00357 
00358   case CURLM_BAD_HANDLE:
00359     return "Invalid multi handle";
00360 
00361   case CURLM_BAD_EASY_HANDLE:
00362     return "Invalid easy handle";
00363 
00364   case CURLM_OUT_OF_MEMORY:
00365     return "Out of memory";
00366 
00367   case CURLM_INTERNAL_ERROR:
00368     return "Internal error";
00369 
00370   case CURLM_BAD_SOCKET:
00371     return "Invalid socket argument";
00372 
00373   case CURLM_UNKNOWN_OPTION:
00374     return "Unknown option";
00375 
00376   case CURLM_ADDED_ALREADY:
00377     return "The easy handle is already added to a multi handle";
00378 
00379   case CURLM_LAST:
00380     break;
00381   }
00382 
00383   return "Unknown error";
00384 #else
00385   if(error == CURLM_OK)
00386     return "No error";
00387   else
00388     return "Error";
00389 #endif
00390 }
00391 
00392 const char *
00393 curl_share_strerror(CURLSHcode error)
00394 {
00395 #ifndef CURL_DISABLE_VERBOSE_STRINGS
00396   switch(error) {
00397   case CURLSHE_OK:
00398     return "No error";
00399 
00400   case CURLSHE_BAD_OPTION:
00401     return "Unknown share option";
00402 
00403   case CURLSHE_IN_USE:
00404     return "Share currently in use";
00405 
00406   case CURLSHE_INVALID:
00407     return "Invalid share handle";
00408 
00409   case CURLSHE_NOMEM:
00410     return "Out of memory";
00411 
00412   case CURLSHE_NOT_BUILT_IN:
00413     return "Feature not enabled in this library";
00414 
00415   case CURLSHE_LAST:
00416     break;
00417   }
00418 
00419   return "CURLSHcode unknown";
00420 #else
00421   if(error == CURLSHE_OK)
00422     return "No error";
00423   else
00424     return "Error";
00425 #endif
00426 }
00427 
00428 #ifdef USE_WINSOCK
00429 
00430 /* This function handles most / all (?) Winsock errors curl is able to produce.
00431  */
00432 static const char *
00433 get_winsock_error (int err, char *buf, size_t len)
00434 {
00435   const char *p;
00436 
00437 #ifndef CURL_DISABLE_VERBOSE_STRINGS
00438   switch(err) {
00439   case WSAEINTR:
00440     p = "Call interrupted";
00441     break;
00442   case WSAEBADF:
00443     p = "Bad file";
00444     break;
00445   case WSAEACCES:
00446     p = "Bad access";
00447     break;
00448   case WSAEFAULT:
00449     p = "Bad argument";
00450     break;
00451   case WSAEINVAL:
00452     p = "Invalid arguments";
00453     break;
00454   case WSAEMFILE:
00455     p = "Out of file descriptors";
00456     break;
00457   case WSAEWOULDBLOCK:
00458     p = "Call would block";
00459     break;
00460   case WSAEINPROGRESS:
00461   case WSAEALREADY:
00462     p = "Blocking call in progress";
00463     break;
00464   case WSAENOTSOCK:
00465     p = "Descriptor is not a socket";
00466     break;
00467   case WSAEDESTADDRREQ:
00468     p = "Need destination address";
00469     break;
00470   case WSAEMSGSIZE:
00471     p = "Bad message size";
00472     break;
00473   case WSAEPROTOTYPE:
00474     p = "Bad protocol";
00475     break;
00476   case WSAENOPROTOOPT:
00477     p = "Protocol option is unsupported";
00478     break;
00479   case WSAEPROTONOSUPPORT:
00480     p = "Protocol is unsupported";
00481     break;
00482   case WSAESOCKTNOSUPPORT:
00483     p = "Socket is unsupported";
00484     break;
00485   case WSAEOPNOTSUPP:
00486     p = "Operation not supported";
00487     break;
00488   case WSAEAFNOSUPPORT:
00489     p = "Address family not supported";
00490     break;
00491   case WSAEPFNOSUPPORT:
00492     p = "Protocol family not supported";
00493     break;
00494   case WSAEADDRINUSE:
00495     p = "Address already in use";
00496     break;
00497   case WSAEADDRNOTAVAIL:
00498     p = "Address not available";
00499     break;
00500   case WSAENETDOWN:
00501     p = "Network down";
00502     break;
00503   case WSAENETUNREACH:
00504     p = "Network unreachable";
00505     break;
00506   case WSAENETRESET:
00507     p = "Network has been reset";
00508     break;
00509   case WSAECONNABORTED:
00510     p = "Connection was aborted";
00511     break;
00512   case WSAECONNRESET:
00513     p = "Connection was reset";
00514     break;
00515   case WSAENOBUFS:
00516     p = "No buffer space";
00517     break;
00518   case WSAEISCONN:
00519     p = "Socket is already connected";
00520     break;
00521   case WSAENOTCONN:
00522     p = "Socket is not connected";
00523     break;
00524   case WSAESHUTDOWN:
00525     p = "Socket has been shut down";
00526     break;
00527   case WSAETOOMANYREFS:
00528     p = "Too many references";
00529     break;
00530   case WSAETIMEDOUT:
00531     p = "Timed out";
00532     break;
00533   case WSAECONNREFUSED:
00534     p = "Connection refused";
00535     break;
00536   case WSAELOOP:
00537     p = "Loop??";
00538     break;
00539   case WSAENAMETOOLONG:
00540     p = "Name too long";
00541     break;
00542   case WSAEHOSTDOWN:
00543     p = "Host down";
00544     break;
00545   case WSAEHOSTUNREACH:
00546     p = "Host unreachable";
00547     break;
00548   case WSAENOTEMPTY:
00549     p = "Not empty";
00550     break;
00551   case WSAEPROCLIM:
00552     p = "Process limit reached";
00553     break;
00554   case WSAEUSERS:
00555     p = "Too many users";
00556     break;
00557   case WSAEDQUOT:
00558     p = "Bad quota";
00559     break;
00560   case WSAESTALE:
00561     p = "Something is stale";
00562     break;
00563   case WSAEREMOTE:
00564     p = "Remote error";
00565     break;
00566 #ifdef WSAEDISCON  /* missing in SalfordC! */
00567   case WSAEDISCON:
00568     p = "Disconnected";
00569     break;
00570 #endif
00571     /* Extended Winsock errors */
00572   case WSASYSNOTREADY:
00573     p = "Winsock library is not ready";
00574     break;
00575   case WSANOTINITIALISED:
00576     p = "Winsock library not initialised";
00577     break;
00578   case WSAVERNOTSUPPORTED:
00579     p = "Winsock version not supported";
00580     break;
00581 
00582     /* getXbyY() errors (already handled in herrmsg):
00583      * Authoritative Answer: Host not found */
00584   case WSAHOST_NOT_FOUND:
00585     p = "Host not found";
00586     break;
00587 
00588     /* Non-Authoritative: Host not found, or SERVERFAIL */
00589   case WSATRY_AGAIN:
00590     p = "Host not found, try again";
00591     break;
00592 
00593     /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
00594   case WSANO_RECOVERY:
00595     p = "Unrecoverable error in call to nameserver";
00596     break;
00597 
00598     /* Valid name, no data record of requested type */
00599   case WSANO_DATA:
00600     p = "No data record of requested type";
00601     break;
00602 
00603   default:
00604     return NULL;
00605   }
00606 #else
00607   if(!err)
00608     return NULL;
00609   else
00610     p = "error";
00611 #endif
00612   strncpy(buf, p, len);
00613   buf [len-1] = '\0';
00614   return buf;
00615 }
00616 #endif   /* USE_WINSOCK */
00617 
00618 /*
00619  * Our thread-safe and smart strerror() replacement.
00620  *
00621  * The 'err' argument passed in to this function MUST be a true errno number
00622  * as reported on this system. We do no range checking on the number before
00623  * we pass it to the "number-to-message" conversion function and there might
00624  * be systems that don't do proper range checking in there themselves.
00625  *
00626  * We don't do range checking (on systems other than Windows) since there is
00627  * no good reliable and portable way to do it.
00628  */
00629 const char *Curl_strerror(struct connectdata *conn, int err)
00630 {
00631   char *buf, *p;
00632   size_t max;
00633   int old_errno = ERRNO;
00634 
00635   DEBUGASSERT(conn);
00636   DEBUGASSERT(err >= 0);
00637 
00638   buf = conn->syserr_buf;
00639   max = sizeof(conn->syserr_buf)-1;
00640   *buf = '\0';
00641 
00642 #ifdef USE_WINSOCK
00643 
00644 #ifdef _WIN32_WCE
00645   {
00646     wchar_t wbuf[256];
00647     wbuf[0] = L'\0';
00648 
00649     FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
00650                   LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL);
00651     wcstombs(buf, wbuf, max);
00652   }
00653 #else
00654   /* 'sys_nerr' is the maximum errno number, it is not widely portable */
00655   if(err >= 0 && err < sys_nerr)
00656     strncpy(buf, strerror(err), max);
00657   else {
00658     if(!get_winsock_error(err, buf, max) &&
00659        !FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
00660                        LANG_NEUTRAL, buf, (DWORD)max, NULL))
00661       snprintf(buf, max, "Unknown error %d (%#x)", err, err);
00662   }
00663 #endif
00664 
00665 #else /* not USE_WINSOCK coming up */
00666 
00667 #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R)
00668  /*
00669   * The POSIX-style strerror_r() may set errno to ERANGE if insufficient
00670   * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated
00671   * message string, or EINVAL if 'errnum' is not a valid error number.
00672   */
00673   if(0 != strerror_r(err, buf, max)) {
00674     if('\0' == buf[0])
00675       snprintf(buf, max, "Unknown error %d", err);
00676   }
00677 #elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)
00678  /*
00679   * The glibc-style strerror_r() only *might* use the buffer we pass to
00680   * the function, but it always returns the error message as a pointer,
00681   * so we must copy that string unconditionally (if non-NULL).
00682   */
00683   {
00684     char buffer[256];
00685     char *msg = strerror_r(err, buffer, sizeof(buffer));
00686     if(msg)
00687       strncpy(buf, msg, max);
00688     else
00689       snprintf(buf, max, "Unknown error %d", err);
00690   }
00691 #elif defined(HAVE_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)
00692  /*
00693   * The vxworks-style strerror_r() does use the buffer we pass to the function.
00694   * The buffer size should be at least NAME_MAX (256)
00695   */
00696   {
00697     char buffer[256];
00698     if(OK == strerror_r(err, buffer))
00699       strncpy(buf, buffer, max);
00700     else
00701       snprintf(buf, max, "Unknown error %d", err);
00702   }
00703 #else
00704   {
00705     char *msg = strerror(err);
00706     if(msg)
00707       strncpy(buf, msg, max);
00708     else
00709       snprintf(buf, max, "Unknown error %d", err);
00710   }
00711 #endif
00712 
00713 #endif /* end of ! USE_WINSOCK */
00714 
00715   buf[max] = '\0'; /* make sure the string is zero terminated */
00716 
00717   /* strip trailing '\r\n' or '\n'. */
00718   p = strrchr(buf, '\n');
00719   if(p && (p - buf) >= 2)
00720     *p = '\0';
00721   p = strrchr(buf, '\r');
00722   if(p && (p - buf) >= 1)
00723     *p = '\0';
00724 
00725   if(old_errno != ERRNO)
00726     SET_ERRNO(old_errno);
00727 
00728   return buf;
00729 }
00730 
00731 #ifdef USE_WINDOWS_SSPI
00732 const char *Curl_sspi_strerror (struct connectdata *conn, int err)
00733 {
00734 #ifndef CURL_DISABLE_VERBOSE_STRINGS
00735   char txtbuf[80];
00736   char msgbuf[sizeof(conn->syserr_buf)];
00737   char *p, *str, *msg = NULL;
00738   bool msg_formatted = FALSE;
00739   int old_errno;
00740 #endif
00741   const char *txt;
00742   char *outbuf;
00743   size_t outmax;
00744 
00745   DEBUGASSERT(conn);
00746 
00747   outbuf = conn->syserr_buf;
00748   outmax = sizeof(conn->syserr_buf)-1;
00749   *outbuf = '\0';
00750 
00751 #ifndef CURL_DISABLE_VERBOSE_STRINGS
00752 
00753   old_errno = ERRNO;
00754 
00755   switch(err) {
00756     case SEC_E_OK:
00757       txt = "No error";
00758       break;
00759     case CRYPT_E_REVOKED:
00760       txt = "CRYPT_E_REVOKED";
00761       break;
00762     case SEC_E_ALGORITHM_MISMATCH:
00763       txt = "SEC_E_ALGORITHM_MISMATCH";
00764       break;
00765     case SEC_E_BAD_BINDINGS:
00766       txt = "SEC_E_BAD_BINDINGS";
00767       break;
00768     case SEC_E_BAD_PKGID:
00769       txt = "SEC_E_BAD_PKGID";
00770       break;
00771     case SEC_E_BUFFER_TOO_SMALL:
00772       txt = "SEC_E_BUFFER_TOO_SMALL";
00773       break;
00774     case SEC_E_CANNOT_INSTALL:
00775       txt = "SEC_E_CANNOT_INSTALL";
00776       break;
00777     case SEC_E_CANNOT_PACK:
00778       txt = "SEC_E_CANNOT_PACK";
00779       break;
00780     case SEC_E_CERT_EXPIRED:
00781       txt = "SEC_E_CERT_EXPIRED";
00782       break;
00783     case SEC_E_CERT_UNKNOWN:
00784       txt = "SEC_E_CERT_UNKNOWN";
00785       break;
00786     case SEC_E_CERT_WRONG_USAGE:
00787       txt = "SEC_E_CERT_WRONG_USAGE";
00788       break;
00789     case SEC_E_CONTEXT_EXPIRED:
00790       txt = "SEC_E_CONTEXT_EXPIRED";
00791       break;
00792     case SEC_E_CROSSREALM_DELEGATION_FAILURE:
00793       txt = "SEC_E_CROSSREALM_DELEGATION_FAILURE";
00794       break;
00795     case SEC_E_CRYPTO_SYSTEM_INVALID:
00796       txt = "SEC_E_CRYPTO_SYSTEM_INVALID";
00797       break;
00798     case SEC_E_DECRYPT_FAILURE:
00799       txt = "SEC_E_DECRYPT_FAILURE";
00800       break;
00801     case SEC_E_DELEGATION_POLICY:
00802       txt = "SEC_E_DELEGATION_POLICY";
00803       break;
00804     case SEC_E_DELEGATION_REQUIRED:
00805       txt = "SEC_E_DELEGATION_REQUIRED";
00806       break;
00807     case SEC_E_DOWNGRADE_DETECTED:
00808       txt = "SEC_E_DOWNGRADE_DETECTED";
00809       break;
00810     case SEC_E_ENCRYPT_FAILURE:
00811       txt = "SEC_E_ENCRYPT_FAILURE";
00812       break;
00813     case SEC_E_ILLEGAL_MESSAGE:
00814       txt = "SEC_E_ILLEGAL_MESSAGE";
00815       break;
00816     case SEC_E_INCOMPLETE_CREDENTIALS:
00817       txt = "SEC_E_INCOMPLETE_CREDENTIALS";
00818       break;
00819     case SEC_E_INCOMPLETE_MESSAGE:
00820       txt = "SEC_E_INCOMPLETE_MESSAGE";
00821       break;
00822     case SEC_E_INSUFFICIENT_MEMORY:
00823       txt = "SEC_E_INSUFFICIENT_MEMORY";
00824       break;
00825     case SEC_E_INTERNAL_ERROR:
00826       txt = "SEC_E_INTERNAL_ERROR";
00827       break;
00828     case SEC_E_INVALID_HANDLE:
00829       txt = "SEC_E_INVALID_HANDLE";
00830       break;
00831     case SEC_E_INVALID_PARAMETER:
00832       txt = "SEC_E_INVALID_PARAMETER";
00833       break;
00834     case SEC_E_INVALID_TOKEN:
00835       txt = "SEC_E_INVALID_TOKEN";
00836       break;
00837     case SEC_E_ISSUING_CA_UNTRUSTED:
00838       txt = "SEC_E_ISSUING_CA_UNTRUSTED";
00839       break;
00840     case SEC_E_ISSUING_CA_UNTRUSTED_KDC:
00841       txt = "SEC_E_ISSUING_CA_UNTRUSTED_KDC";
00842       break;
00843     case SEC_E_KDC_CERT_EXPIRED:
00844       txt = "SEC_E_KDC_CERT_EXPIRED";
00845       break;
00846     case SEC_E_KDC_CERT_REVOKED:
00847       txt = "SEC_E_KDC_CERT_REVOKED";
00848       break;
00849     case SEC_E_KDC_INVALID_REQUEST:
00850       txt = "SEC_E_KDC_INVALID_REQUEST";
00851       break;
00852     case SEC_E_KDC_UNABLE_TO_REFER:
00853       txt = "SEC_E_KDC_UNABLE_TO_REFER";
00854       break;
00855     case SEC_E_KDC_UNKNOWN_ETYPE:
00856       txt = "SEC_E_KDC_UNKNOWN_ETYPE";
00857       break;
00858     case SEC_E_LOGON_DENIED:
00859       txt = "SEC_E_LOGON_DENIED";
00860       break;
00861     case SEC_E_MAX_REFERRALS_EXCEEDED:
00862       txt = "SEC_E_MAX_REFERRALS_EXCEEDED";
00863       break;
00864     case SEC_E_MESSAGE_ALTERED:
00865       txt = "SEC_E_MESSAGE_ALTERED";
00866       break;
00867     case SEC_E_MULTIPLE_ACCOUNTS:
00868       txt = "SEC_E_MULTIPLE_ACCOUNTS";
00869       break;
00870     case SEC_E_MUST_BE_KDC:
00871       txt = "SEC_E_MUST_BE_KDC";
00872       break;
00873     case SEC_E_NOT_OWNER:
00874       txt = "SEC_E_NOT_OWNER";
00875       break;
00876     case SEC_E_NO_AUTHENTICATING_AUTHORITY:
00877       txt = "SEC_E_NO_AUTHENTICATING_AUTHORITY";
00878       break;
00879     case SEC_E_NO_CREDENTIALS:
00880       txt = "SEC_E_NO_CREDENTIALS";
00881       break;
00882     case SEC_E_NO_IMPERSONATION:
00883       txt = "SEC_E_NO_IMPERSONATION";
00884       break;
00885     case SEC_E_NO_IP_ADDRESSES:
00886       txt = "SEC_E_NO_IP_ADDRESSES";
00887       break;
00888     case SEC_E_NO_KERB_KEY:
00889       txt = "SEC_E_NO_KERB_KEY";
00890       break;
00891     case SEC_E_NO_PA_DATA:
00892       txt = "SEC_E_NO_PA_DATA";
00893       break;
00894     case SEC_E_NO_S4U_PROT_SUPPORT:
00895       txt = "SEC_E_NO_S4U_PROT_SUPPORT";
00896       break;
00897     case SEC_E_NO_TGT_REPLY:
00898       txt = "SEC_E_NO_TGT_REPLY";
00899       break;
00900     case SEC_E_OUT_OF_SEQUENCE:
00901       txt = "SEC_E_OUT_OF_SEQUENCE";
00902       break;
00903     case SEC_E_PKINIT_CLIENT_FAILURE:
00904       txt = "SEC_E_PKINIT_CLIENT_FAILURE";
00905       break;
00906     case SEC_E_PKINIT_NAME_MISMATCH:
00907       txt = "SEC_E_PKINIT_NAME_MISMATCH";
00908       break;
00909     case SEC_E_POLICY_NLTM_ONLY:
00910       txt = "SEC_E_POLICY_NLTM_ONLY";
00911       break;
00912     case SEC_E_QOP_NOT_SUPPORTED:
00913       txt = "SEC_E_QOP_NOT_SUPPORTED";
00914       break;
00915     case SEC_E_REVOCATION_OFFLINE_C:
00916       txt = "SEC_E_REVOCATION_OFFLINE_C";
00917       break;
00918     case SEC_E_REVOCATION_OFFLINE_KDC:
00919       txt = "SEC_E_REVOCATION_OFFLINE_KDC";
00920       break;
00921     case SEC_E_SECPKG_NOT_FOUND:
00922       txt = "SEC_E_SECPKG_NOT_FOUND";
00923       break;
00924     case SEC_E_SECURITY_QOS_FAILED:
00925       txt = "SEC_E_SECURITY_QOS_FAILED";
00926       break;
00927     case SEC_E_SHUTDOWN_IN_PROGRESS:
00928       txt = "SEC_E_SHUTDOWN_IN_PROGRESS";
00929       break;
00930     case SEC_E_SMARTCARD_CERT_EXPIRED:
00931       txt = "SEC_E_SMARTCARD_CERT_EXPIRED";
00932       break;
00933     case SEC_E_SMARTCARD_CERT_REVOKED:
00934       txt = "SEC_E_SMARTCARD_CERT_REVOKED";
00935       break;
00936     case SEC_E_SMARTCARD_LOGON_REQUIRED:
00937       txt = "SEC_E_SMARTCARD_LOGON_REQUIRED";
00938       break;
00939     case SEC_E_STRONG_CRYPTO_NOT_SUPPORTED:
00940       txt = "SEC_E_STRONG_CRYPTO_NOT_SUPPORTED";
00941       break;
00942     case SEC_E_TARGET_UNKNOWN:
00943       txt = "SEC_E_TARGET_UNKNOWN";
00944       break;
00945     case SEC_E_TIME_SKEW:
00946       txt = "SEC_E_TIME_SKEW";
00947       break;
00948     case SEC_E_TOO_MANY_PRINCIPALS:
00949       txt = "SEC_E_TOO_MANY_PRINCIPALS";
00950       break;
00951     case SEC_E_UNFINISHED_CONTEXT_DELETED:
00952       txt = "SEC_E_UNFINISHED_CONTEXT_DELETED";
00953       break;
00954     case SEC_E_UNKNOWN_CREDENTIALS:
00955       txt = "SEC_E_UNKNOWN_CREDENTIALS";
00956       break;
00957     case SEC_E_UNSUPPORTED_FUNCTION:
00958       txt = "SEC_E_UNSUPPORTED_FUNCTION";
00959       break;
00960     case SEC_E_UNSUPPORTED_PREAUTH:
00961       txt = "SEC_E_UNSUPPORTED_PREAUTH";
00962       break;
00963     case SEC_E_UNTRUSTED_ROOT:
00964       txt = "SEC_E_UNTRUSTED_ROOT";
00965       break;
00966     case SEC_E_WRONG_CREDENTIAL_HANDLE:
00967       txt = "SEC_E_WRONG_CREDENTIAL_HANDLE";
00968       break;
00969     case SEC_E_WRONG_PRINCIPAL:
00970       txt = "SEC_E_WRONG_PRINCIPAL";
00971       break;
00972     case SEC_I_COMPLETE_AND_CONTINUE:
00973       txt = "SEC_I_COMPLETE_AND_CONTINUE";
00974       break;
00975     case SEC_I_COMPLETE_NEEDED:
00976       txt = "SEC_I_COMPLETE_NEEDED";
00977       break;
00978     case SEC_I_CONTEXT_EXPIRED:
00979       txt = "SEC_I_CONTEXT_EXPIRED";
00980       break;
00981     case SEC_I_CONTINUE_NEEDED:
00982       txt = "SEC_I_CONTINUE_NEEDED";
00983       break;
00984     case SEC_I_INCOMPLETE_CREDENTIALS:
00985       txt = "SEC_I_INCOMPLETE_CREDENTIALS";
00986       break;
00987     case SEC_I_LOCAL_LOGON:
00988       txt = "SEC_I_LOCAL_LOGON";
00989       break;
00990     case SEC_I_NO_LSA_CONTEXT:
00991       txt = "SEC_I_NO_LSA_CONTEXT";
00992       break;
00993     case SEC_I_RENEGOTIATE:
00994       txt = "SEC_I_RENEGOTIATE";
00995       break;
00996     case SEC_I_SIGNATURE_NEEDED:
00997       txt = "SEC_I_SIGNATURE_NEEDED";
00998       break;
00999     default:
01000       txt = "Unknown error";
01001   }
01002 
01003   if(err == SEC_E_OK)
01004     strncpy(outbuf, txt, outmax);
01005   else if(err == SEC_E_ILLEGAL_MESSAGE)
01006     snprintf(outbuf, outmax,
01007              "SEC_E_ILLEGAL_MESSAGE (0x%08X) - This error usually occurs "
01008              "when a fatal SSL/TLS alert is received (e.g. handshake failed). "
01009              "More detail may be available in the Windows System event log.",
01010              err);
01011   else {
01012     str = txtbuf;
01013     snprintf(txtbuf, sizeof(txtbuf), "%s (0x%08X)", txt, err);
01014     txtbuf[sizeof(txtbuf)-1] = '\0';
01015 
01016 #ifdef _WIN32_WCE
01017     {
01018       wchar_t wbuf[256];
01019       wbuf[0] = L'\0';
01020 
01021       if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
01022                        FORMAT_MESSAGE_IGNORE_INSERTS,
01023                        NULL, err, LANG_NEUTRAL,
01024                        wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL)) {
01025         wcstombs(msgbuf, wbuf, sizeof(msgbuf)-1);
01026         msg_formatted = TRUE;
01027       }
01028     }
01029 #else
01030     if(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
01031                       FORMAT_MESSAGE_IGNORE_INSERTS,
01032                       NULL, err, LANG_NEUTRAL,
01033                       msgbuf, sizeof(msgbuf)-1, NULL)) {
01034       msg_formatted = TRUE;
01035     }
01036 #endif
01037     if(msg_formatted) {
01038       msgbuf[sizeof(msgbuf)-1] = '\0';
01039       /* strip trailing '\r\n' or '\n' */
01040       p = strrchr(msgbuf, '\n');
01041       if(p && (p - msgbuf) >= 2)
01042         *p = '\0';
01043       p = strrchr(msgbuf, '\r');
01044       if(p && (p - msgbuf) >= 1)
01045         *p = '\0';
01046       msg = msgbuf;
01047     }
01048     if(msg)
01049       snprintf(outbuf, outmax, "%s - %s", str, msg);
01050     else
01051       strncpy(outbuf, str, outmax);
01052   }
01053 
01054   if(old_errno != ERRNO)
01055     SET_ERRNO(old_errno);
01056 
01057 #else
01058 
01059   if(err == SEC_E_OK)
01060     txt = "No error";
01061   else
01062     txt = "Error";
01063 
01064   strncpy(outbuf, txt, outmax);
01065 
01066 #endif
01067 
01068   outbuf[outmax] = '\0';
01069 
01070   return outbuf;
01071 }
01072 #endif /* USE_WINDOWS_SSPI */


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06