summaryrefslogtreecommitdiff
path: root/source3/libsmb/clientgen.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/libsmb/clientgen.c')
-rw-r--r--source3/libsmb/clientgen.c53
1 files changed, 47 insertions, 6 deletions
diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c
index 042b3bdfb0..3b7669f33e 100644
--- a/source3/libsmb/clientgen.c
+++ b/source3/libsmb/clientgen.c
@@ -69,15 +69,36 @@ int cli_set_port(struct cli_state *cli, int port)
static ssize_t client_receive_smb(struct cli_state *cli, size_t maxlen)
{
- ssize_t len;
+ size_t len;
for(;;) {
- len = receive_smb_raw(cli->fd, cli->inbuf, cli->timeout,
- maxlen, &cli->smb_rw_error);
+ NTSTATUS status;
- if (len < 0) {
+ set_smb_read_error(&cli->smb_rw_error, SMB_READ_OK);
+
+ status = receive_smb_raw(cli->fd, cli->inbuf, cli->timeout,
+ maxlen, &len);
+ if (!NT_STATUS_IS_OK(status)) {
DEBUG(10,("client_receive_smb failed\n"));
show_msg(cli->inbuf);
+
+ if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
+ set_smb_read_error(&cli->smb_rw_error,
+ SMB_READ_EOF);
+ return -1;
+ }
+
+ if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
+ set_smb_read_error(&cli->smb_rw_error,
+ SMB_READ_TIMEOUT);
+ return -1;
+ }
+
+ set_smb_read_error(&cli->smb_rw_error, SMB_READ_ERROR);
+ return -1;
+ }
+
+ if (len < 0) {
return len;
}
@@ -180,8 +201,28 @@ bool cli_receive_smb(struct cli_state *cli)
ssize_t cli_receive_smb_data(struct cli_state *cli, char *buffer, size_t len)
{
- return read_socket_with_timeout(cli->fd, buffer, len, len,
- cli->timeout, &cli->smb_rw_error);
+ NTSTATUS status;
+
+ set_smb_read_error(&cli->smb_rw_error, SMB_READ_OK);
+
+ status = read_socket_with_timeout(
+ cli->fd, buffer, len, len, cli->timeout, NULL);
+ if (NT_STATUS_IS_OK(status)) {
+ return len;
+ }
+
+ if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
+ set_smb_read_error(&cli->smb_rw_error, SMB_READ_EOF);
+ return -1;
+ }
+
+ if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
+ set_smb_read_error(&cli->smb_rw_error, SMB_READ_TIMEOUT);
+ return -1;
+ }
+
+ set_smb_read_error(&cli->smb_rw_error, SMB_READ_ERROR);
+ return -1;
}
/****************************************************************************