s3:smb2_server: fix drain_socket error handling
authorStefan Metzmacher <metze@samba.org>
Mon, 14 Oct 2013 14:42:55 +0000 (16:42 +0200)
committerKarolin Seeger <kseeger@samba.org>
Tue, 10 Dec 2013 11:57:29 +0000 (12:57 +0100)
smbd_smb2_request_error_ex() should return NTSTATUS and the caller
will terminate the connection.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
(cherry picked from commit 9393e28df59954414313bfae70ffb796d3e332fe)

source3/smbd/smb2_server.c

index b031c6d153f42a5d3569af10c06455f58eab3ef7..1918460f6fa3e972e0f9c1fd48e1a4ad3d224e25 100644 (file)
@@ -2644,10 +2644,24 @@ NTSTATUS smbd_smb2_request_error_ex(struct smbd_smb2_request *req,
 
        if (unread_bytes) {
                /* Recvfile error. Drain incoming socket. */
-               size_t ret = drain_socket(req->sconn->sock, unread_bytes);
+               size_t ret;
+
+               errno = 0;
+               ret = drain_socket(req->sconn->sock, unread_bytes);
                if (ret != unread_bytes) {
-                       smbd_server_connection_terminate(req->sconn,
-                               "Failed to drain SMB2 socket\n");
+                       NTSTATUS error;
+
+                       if (errno == 0) {
+                               error = NT_STATUS_IO_DEVICE_ERROR;
+                       } else {
+                               error = map_nt_error_from_unix_common(errno);
+                       }
+
+                       DEBUG(2, ("Failed to drain %u bytes from SMB2 socket: "
+                                 "ret[%u] errno[%d] => %s\n",
+                                 (unsigned)unread_bytes,
+                                 (unsigned)ret, errno, nt_errstr(error)));
+                       return error;
                }
        }