From 0dcfa9ce1baa9f2074a002fdb5c8b88cc5db28db Mon Sep 17 00:00:00 2001 From: Tim Prouty Date: Fri, 20 Feb 2009 13:28:36 -0800 Subject: s3: If sendfile returns 0 bytes read, fall back to the normal read path This allows sendfile implementations that are atomic to avoid having to send zeros or kill the client connection on a short read (usually the file was truncated). --- source3/smbd/reply.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source3/smbd/reply.c') diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 457f9412a9..b30ef23c0e 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -2788,6 +2788,18 @@ static void send_file_readbraw(connection_struct *conn, DEBUG(0,("send_file_readbraw: sendfile failed for file %s (%s). Terminating\n", fsp->fsp_name, strerror(errno) )); exit_server_cleanly("send_file_readbraw sendfile failed"); + } else if (sendfile_read == 0) { + /* + * Some sendfile implementations return 0 to indicate + * that there was a short read, but nothing was + * actually written to the socket. In this case, + * fallback to the normal read path so the header gets + * the correct byte count. + */ + DEBUG(3, ("send_file_readbraw: sendfile sent zero " + "bytes falling back to the normal read: " + "%s\n", fsp->fsp_name)); + goto normal_readbraw; } /* Deal with possible short send. */ @@ -3284,6 +3296,18 @@ static void send_file_readX(connection_struct *conn, struct smb_request *req, DEBUG(0,("send_file_readX: sendfile failed for file %s (%s). Terminating\n", fsp->fsp_name, strerror(errno) )); exit_server_cleanly("send_file_readX sendfile failed"); + } else if (nread == 0) { + /* + * Some sendfile implementations return 0 to indicate + * that there was a short read, but nothing was + * actually written to the socket. In this case, + * fallback to the normal read path so the header gets + * the correct byte count. + */ + DEBUG(3, ("send_file_readX: sendfile sent zero bytes " + "falling back to the normal read: %s\n", + fsp->fsp_name)); + goto normal_read; } DEBUG( 3, ( "send_file_readX: sendfile fnum=%d max=%d nread=%d\n", -- cgit From 15f108f0917eedab89199e9fbf93ed802eed7f89 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 25 Feb 2009 09:59:53 -0800 Subject: Fix some NetBSD warnings. Jeremy. --- source3/smbd/reply.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/reply.c') diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index b30ef23c0e..80ed019e0f 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -2808,9 +2808,9 @@ static void send_file_readbraw(connection_struct *conn, } return; } -#endif normal_readbraw: +#endif outbuf = TALLOC_ARRAY(NULL, char, nread+4); if (!outbuf) { -- cgit From 3121249243f52dcbf8083f5ff137bd580515efa7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 26 Feb 2009 11:42:23 -0800 Subject: Make us pass the RAW-RENAME torture test I just added. Inside a directory, keep a file open and then renaming the directory should fail with ACCESS_DENIED. Jeremy. --- source3/smbd/reply.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/smbd/reply.c') diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 80ed019e0f..22e4c1aad7 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -2214,6 +2214,16 @@ static NTSTATUS can_rename(connection_struct *conn, files_struct *fsp, } if (S_ISDIR(pst->st_mode)) { + if (fsp->posix_open) { + return NT_STATUS_OK; + } + + /* If no pathnames are open below this + directory, allow the rename. */ + + if (file_find_subpath(fsp)) { + return NT_STATUS_ACCESS_DENIED; + } return NT_STATUS_OK; } -- cgit