schannel.c: Improve error and return code handling upon aa99a63f03

This commit is contained in:
Marc Hoersken 2015-05-02 20:05:22 +02:00
parent aa99a63f03
commit d93619ca5d

View File

@ -823,7 +823,7 @@ schannel_recv(struct connectdata *conn, int sockindex,
char *buf, size_t len, CURLcode *err)
{
size_t size = 0;
ssize_t nread = 0, ret = 0;
ssize_t nread = 0;
CURLcode result;
struct SessionHandle *data = conn->data;
struct ssl_connect_data *connssl = &conn->ssl[sockindex];
@ -989,10 +989,16 @@ schannel_recv(struct connectdata *conn, int sockindex,
infof(data, "schannel: encrypted data cached: offset %zu length %zu\n",
connssl->encdata_offset, connssl->encdata_length);
}
else{
else {
/* reset encrypted buffer offset, because there is no data remaining */
connssl->encdata_offset = 0;
}
} /* check if something went wrong and we need to return an error */
else {
infof(data, "schannel: failed to read data from server: %s\n",
Curl_sspi_strerror(conn, sspi_status));
*err = CURLE_RECV_ERROR;
return -1;
}
/* check if server wants to renegotiate the connection context */
@ -1021,7 +1027,6 @@ schannel_recv(struct connectdata *conn, int sockindex,
size = len < connssl->decdata_offset ? len : connssl->decdata_offset;
if(size > 0) {
memcpy(buf, connssl->decdata_buffer, size);
ret = size;
/* move remaining decrypted data forward to the beginning of buffer */
memmove(connssl->decdata_buffer, connssl->decdata_buffer + size,
@ -1031,27 +1036,16 @@ schannel_recv(struct connectdata *conn, int sockindex,
infof(data, "schannel: decrypted data returned %zd\n", size);
infof(data, "schannel: decrypted data buffer: offset %zu length %zu\n",
connssl->decdata_offset, connssl->decdata_length);
}
/* check if the server closed the connection */
if(ret <= 0 && ( /* special check for Windows 2000 Professional */
sspi_status == SEC_I_CONTEXT_EXPIRED ||
(sspi_status == SEC_E_OK && connssl->encdata_offset > 0 &&
connssl->encdata_buffer[0] == 0x15))) {
} /* check if the server closed the connection */
else if(sspi_status == SEC_I_CONTEXT_EXPIRED ||
/* special check for Windows 2000 Professional */
(sspi_status == SEC_E_OK && connssl->encdata_offset > 0 &&
connssl->encdata_buffer[0] == 0x15)) {
infof(data, "schannel: server closed the conunection\n");
*err = CURLE_OK;
return 0;
}
/* check if something went wrong and we need to return an error */
if(ret < 0 && sspi_status != SEC_E_OK) {
infof(data, "schannel: failed to read data from server: %s\n",
Curl_sspi_strerror(conn, sspi_status));
*err = CURLE_RECV_ERROR;
return -1;
}
return ret;
return size;
}
CURLcode