1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

strerror.c: make Curl_sspi_strerror() always return code for errors

This commit is contained in:
Yang Tse 2012-06-12 03:57:15 +02:00
parent 5e7a0fe73b
commit b8edf5bbe9

View File

@ -786,10 +786,10 @@ const char *Curl_idn_strerror (struct connectdata *conn, int err)
const char *Curl_sspi_strerror (struct connectdata *conn, int err) const char *Curl_sspi_strerror (struct connectdata *conn, int err)
{ {
#ifndef CURL_DISABLE_VERBOSE_STRINGS #ifndef CURL_DISABLE_VERBOSE_STRINGS
char txtbuf[sizeof("Unknown error (0xffffffff)")]; char txtbuf[80];
char msgbuf[sizeof(conn->syserr_buf)]; char msgbuf[sizeof(conn->syserr_buf)];
char *str, *msg = NULL;
int old_errno; int old_errno;
char *msg = NULL;
#endif #endif
const char *txt; const char *txt;
char *outbuf; char *outbuf;
@ -1047,18 +1047,21 @@ const char *Curl_sspi_strerror (struct connectdata *conn, int err)
txt = "SEC_I_SIGNATURE_NEEDED"; txt = "SEC_I_SIGNATURE_NEEDED";
break; break;
default: default:
snprintf(txtbuf, sizeof(txtbuf), "Unknown error (0x%04X%04X)", txt = "Unknown error";
(err >> 16) & 0xffff, err & 0xffff);
txtbuf[sizeof(txtbuf)-1] = '\0';
txt = txtbuf;
} }
if(err != SEC_E_OK) { if(err == SEC_E_OK)
char *p; strncpy(outbuf, txt, outmax);
else {
str = txtbuf;
snprintf(txtbuf, sizeof(txtbuf), "%s (0x%04X%04X)",
txt, (err >> 16) & 0xffff, err & 0xffff);
txtbuf[sizeof(txtbuf)-1] = '\0';
if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, LANG_NEUTRAL, NULL, err, LANG_NEUTRAL,
msgbuf, sizeof(msgbuf)-1, NULL)) { msgbuf, sizeof(msgbuf)-1, NULL)) {
char *p;
msgbuf[sizeof(msgbuf)-1] = '\0'; msgbuf[sizeof(msgbuf)-1] = '\0';
/* strip trailing '\r\n' or '\n' */ /* strip trailing '\r\n' or '\n' */
if((p = strrchr(msgbuf,'\n')) != NULL && (p - msgbuf) >= 2) if((p = strrchr(msgbuf,'\n')) != NULL && (p - msgbuf) >= 2)
@ -1067,13 +1070,12 @@ const char *Curl_sspi_strerror (struct connectdata *conn, int err)
*p = '\0'; *p = '\0';
msg = msgbuf; msg = msgbuf;
} }
if(msg)
snprintf(outbuf, outmax, "%s - %s", str, msg);
else
strncpy(outbuf, str, outmax);
} }
if(msg)
snprintf(outbuf, outmax, "%s - %s", txt, msg);
else
strncpy(outbuf, txt, outmax);
if(old_errno != ERRNO) if(old_errno != ERRNO)
SET_ERRNO(old_errno); SET_ERRNO(old_errno);