s3:libsmb only log a dead connection if it was not closed
[samba.git] / source3 / libsmb / clientgen.c
index 1b438091389607fdc57dc8483a8029a930a41b0d..e26c1718d80e1a749e2e7c0cc0ee3a65426d5d2c 100644 (file)
@@ -19,6 +19,8 @@
 */
 
 #include "includes.h"
+#include "smb_signing.h"
+#include "async_smb.h"
 
 /*******************************************************************
  Setup the word count and byte count for a client smb message.
@@ -246,9 +248,18 @@ bool cli_receive_smb(struct cli_state *cli)
 
        /* If the server is not responding, note that now */
        if (len < 0) {
-                DEBUG(0, ("Receiving SMB: Server stopped responding\n"));
-               close(cli->fd);
-               cli->fd = -1;
+               /*
+                * only log if the connection should still be open and not when
+                * the connection was closed due to a dropped ip message
+                */
+               if (cli->fd != -1) {
+                       char addr[INET6_ADDRSTRLEN];
+                       print_sockaddr(addr, sizeof(addr), &cli->dest_ss);
+                       DEBUG(0, ("Receiving SMB: Server %s stopped responding\n",
+                               addr));
+                       close(cli->fd);
+                       cli->fd = -1;
+               }
                return false;
        }
 
@@ -285,37 +296,6 @@ bool cli_receive_smb(struct cli_state *cli)
        return true;
 }
 
-/****************************************************************************
- Read the data portion of a readX smb.
- The timeout is in milliseconds
-****************************************************************************/
-
-ssize_t cli_receive_smb_data(struct cli_state *cli, char *buffer, size_t len)
-{
-       NTSTATUS status;
-
-       set_smb_read_error(&cli->smb_rw_error, SMB_READ_OK);
-
-       status = read_fd_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;
-}
-
 static ssize_t write_socket(int fd, const char *buf, size_t len)
 {
         ssize_t ret=0;
@@ -737,6 +717,9 @@ static void _cli_shutdown(struct cli_state *cli)
 void cli_shutdown(struct cli_state *cli)
 {
        struct cli_state *cli_head;
+       if (cli == NULL) {
+               return;
+       }
        DLIST_HEAD(cli, cli_head);
        if (cli_head == cli) {
                /*
@@ -788,25 +771,6 @@ bool cli_set_case_sensitive(struct cli_state *cli, bool case_sensitive)
        return ret;
 }
 
-/****************************************************************************
-Send a keepalive packet to the server
-****************************************************************************/
-
-bool cli_send_keepalive(struct cli_state *cli)
-{
-        if (cli->fd == -1) {
-                DEBUG(3, ("cli_send_keepalive: fd == -1\n"));
-                return false;
-        }
-        if (!send_keepalive(cli->fd)) {
-                close(cli->fd);
-                cli->fd = -1;
-                DEBUG(0,("Error sending keepalive packet to client.\n"));
-                return false;
-        }
-        return true;
-}
-
 struct cli_echo_state {
        uint16_t vwv[1];
        DATA_BLOB data;
@@ -995,7 +959,7 @@ NTSTATUS cli_smb(TALLOC_CTX *mem_ctx, struct cli_state *cli,
                              pnum_bytes, pbytes);
 fail:
         TALLOC_FREE(ev);
-       if (NT_STATUS_IS_OK(status)) {
+       if (NT_STATUS_IS_OK(status) && (result_parent != NULL)) {
                *result_parent = req;
        }
         return status;