void reply_unlink(struct smb_request *req);
ssize_t fake_sendfile(struct smbXsrv_connection *xconn, files_struct *fsp,
off_t startpos, size_t nread);
-void sendfile_short_send(files_struct *fsp,
- ssize_t nread,
- size_t headersize,
- size_t smb_maxcnt);
+ssize_t sendfile_short_send(struct smbXsrv_connection *xconn,
+ files_struct *fsp,
+ ssize_t nread,
+ size_t headersize,
+ size_t smb_maxcnt);
void reply_readbraw(struct smb_request *req);
void reply_lockread(struct smb_request *req);
void reply_read(struct smb_request *req);
/****************************************************************************
Deal with the case of sendfile reading less bytes from the file than
- requested. Fill with zeros (all we can do).
+ requested. Fill with zeros (all we can do). Returns 0 on success
****************************************************************************/
-void sendfile_short_send(files_struct *fsp,
- ssize_t nread,
- size_t headersize,
- size_t smb_maxcnt)
+ssize_t sendfile_short_send(struct smbXsrv_connection *xconn,
+ files_struct *fsp,
+ ssize_t nread,
+ size_t headersize,
+ size_t smb_maxcnt)
{
- struct smbXsrv_connection *xconn = fsp->conn->sconn->conn;
-
#define SHORT_SEND_BUFSIZE 1024
if (nread < headersize) {
DEBUG(0,("sendfile_short_send: sendfile failed to send "
"header for file %s (%s). Terminating\n",
fsp_str_dbg(fsp), strerror(errno)));
- exit_server_cleanly("sendfile_short_send failed");
+ return -1;
}
nread -= headersize;
if (nread < smb_maxcnt) {
char *buf = SMB_CALLOC_ARRAY(char, SHORT_SEND_BUFSIZE);
if (!buf) {
- exit_server_cleanly("sendfile_short_send: "
- "malloc failed");
+ DEBUG(0,("sendfile_short_send: malloc failed "
+ "for file %s (%s). Terminating\n",
+ fsp_str_dbg(fsp), strerror(errno)));
+ return -1;
}
DEBUG(0,("sendfile_short_send: filling truncated file %s "
smbXsrv_connection_dbg(xconn),
strerror(saved_errno)));
errno = saved_errno;
- exit_server_cleanly("sendfile_short_send: "
- "write_data failed");
+ return -1;
}
nread += to_write;
}
SAFE_FREE(buf);
}
+
+ return 0;
}
/****************************************************************************
/* Deal with possible short send. */
if (sendfile_read != 4+nread) {
- sendfile_short_send(fsp, sendfile_read, 4, nread);
+ ret = sendfile_short_send(xconn, fsp,
+ sendfile_read, 4, nread);
+ if (ret == -1) {
+ fail_readraw();
+ }
}
return;
}
/* Deal with possible short send. */
if (nread != smb_maxcnt + sizeof(headerbuf)) {
- sendfile_short_send(fsp, nread, sizeof(headerbuf), smb_maxcnt);
+ ssize_t ret;
+
+ ret = sendfile_short_send(xconn, fsp, nread,
+ sizeof(headerbuf), smb_maxcnt);
+ if (ret == -1) {
+ const char *r;
+ r = "send_file_readX: sendfile_short_send failed";
+ DEBUG(0,("%s for file %s (%s).\n",
+ r, fsp_str_dbg(fsp), strerror(errno)));
+ exit_server_cleanly(r);
+ }
}
/* No outbuf here means successful sendfile. */
SMB_PERFCOUNT_SET_MSGLEN_OUT(&req->pcd, nread);
out:
if (nread < in_length) {
- sendfile_short_send(fsp, nread, hdr->length, in_length);
+ ret = sendfile_short_send(xconn, fsp, nread,
+ hdr->length, in_length);
+ if (ret == -1) {
+ saved_errno = errno;
+ DEBUG(0,("smb2_sendfile_send_data: sendfile_short_send "
+ "failed for file %s (%s) for client %s. "
+ "Terminating\n",
+ fsp_str_dbg(fsp), strerror(saved_errno),
+ smbXsrv_connection_dbg(xconn)));
+ exit_server_cleanly("smb2_sendfile_send_data: "
+ "sendfile_short_send failed");
+ }
}
init_strict_lock_struct(fsp,