diff options
-rw-r--r-- | source3/smbd/process.c | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 02b190f003..4d9a90a840 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -143,39 +143,15 @@ static bool valid_packet_size(size_t len) return true; } -static ssize_t read_packet_remainder(int fd, - char *buffer, - unsigned int timeout, - ssize_t len) +static NTSTATUS read_packet_remainder(int fd, char *buffer, + unsigned int timeout, ssize_t len) { - NTSTATUS status; - if (len <= 0) { - return len; - } - - set_smb_read_error(get_srv_read_error(), SMB_READ_OK); - - status = read_socket_with_timeout_ntstatus(fd, buffer, len, len, - timeout, NULL); - - if (NT_STATUS_IS_OK(status)) { - return len; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); - return -1; + return NT_STATUS_OK; } - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_TIMEOUT); - return -1; - } - - set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR); - return -1; + return read_socket_with_timeout_ntstatus(fd, buffer, len, len, + timeout, NULL); } /**************************************************************************** @@ -293,11 +269,29 @@ static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, toread = len - STANDARD_WRITE_AND_X_HEADER_SIZE; if(toread > 0) { - ret = read_packet_remainder(fd, - (*buffer) + 4 + STANDARD_WRITE_AND_X_HEADER_SIZE, - timeout, - toread); - if (ret != toread) { + NTSTATUS status; + + set_smb_read_error(get_srv_read_error(), SMB_READ_OK); + + status = read_packet_remainder( + fd, (*buffer) + 4 + STANDARD_WRITE_AND_X_HEADER_SIZE, + timeout, toread); + + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_EOF); + return -1; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + return -1; + } + + set_smb_read_error(get_srv_read_error(), + SMB_READ_ERROR); return -1; } } @@ -313,7 +307,6 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, { char lenbuf[4]; size_t len; - ssize_t ret; int min_recv_size = lp_min_receive_file_size(); NTSTATUS status; @@ -371,8 +364,22 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, memcpy(*buffer, lenbuf, sizeof(lenbuf)); - ret = read_packet_remainder(fd, (*buffer)+4, timeout, len); - if (ret != len) { + status = read_packet_remainder(fd, (*buffer)+4, timeout, len); + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_EOF); + return -1; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + return -1; + } + + set_smb_read_error(get_srv_read_error(), + SMB_READ_ERROR); return -1; } |