summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2008-01-25 21:24:48 +0100
committerVolker Lendecke <vl@samba.org>2008-02-02 11:03:21 +0100
commit0afbfa4284db8204a3696f4fea6cff96965e6074 (patch)
tree431cc875538207f6817d883f1a4ddfc71b8d3909 /source3
parent3e5b98555b832772d6fe93a57005bc39222a5189 (diff)
downloadsamba-0afbfa4284db8204a3696f4fea6cff96965e6074.tar.gz
samba-0afbfa4284db8204a3696f4fea6cff96965e6074.tar.bz2
samba-0afbfa4284db8204a3696f4fea6cff96965e6074.zip
Convert read_smb_length_return_keepalive to return NTSTATUS
(This used to be commit 73a79a957a33a8761acf54598ce71e3604ecf3c5)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/util_sock.c80
-rw-r--r--source3/smbd/process.c28
2 files changed, 61 insertions, 47 deletions
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index d32d67f2fc..f62b20b6fc 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -1141,36 +1141,21 @@ bool send_keepalive(int client)
Timeout is in milliseconds.
****************************************************************************/
-ssize_t read_smb_length_return_keepalive(int fd,
- char *inbuf,
- unsigned int timeout,
- enum smb_read_errors *pre)
+NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf,
+ unsigned int timeout,
+ size_t *len)
{
- size_t len=0;
int msg_type;
NTSTATUS status;
- set_smb_read_error(pre, SMB_READ_OK);
-
status = read_socket_with_timeout_ntstatus(fd, inbuf, 4, 4, timeout,
NULL);
if (!NT_STATUS_IS_OK(status)) {
- if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
- set_smb_read_error(pre, SMB_READ_EOF);
- return -1;
- }
-
- if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
- set_smb_read_error(pre, SMB_READ_TIMEOUT);
- return -1;
- }
-
- set_smb_read_error(pre, SMB_READ_ERROR);
- return -1;
+ return status;
}
- len = smb_len(inbuf);
+ *len = smb_len(inbuf);
msg_type = CVAL(inbuf,0);
if (msg_type == SMBkeepalive) {
@@ -1179,7 +1164,7 @@ ssize_t read_smb_length_return_keepalive(int fd,
DEBUG(10,("got smb length of %lu\n",(unsigned long)len));
- return len;
+ return NT_STATUS_OK;
}
/****************************************************************************
@@ -1191,15 +1176,31 @@ ssize_t read_smb_length_return_keepalive(int fd,
ssize_t read_smb_length(int fd, char *inbuf, unsigned int timeout, enum smb_read_errors *pre)
{
- ssize_t len;
+ size_t len;
uint8_t msgtype = SMBkeepalive;
+ set_smb_read_error(pre, SMB_READ_OK);
+
while (msgtype == SMBkeepalive) {
- len = read_smb_length_return_keepalive(fd, inbuf, timeout,
- pre);
- if (len < 0) {
- return len;
+ NTSTATUS status;
+
+ status = read_smb_length_return_keepalive(fd, inbuf, timeout,
+ &len);
+ if (!NT_STATUS_IS_OK(status)) {
+ if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
+ set_smb_read_error(pre, SMB_READ_EOF);
+ return -1;
+ }
+
+ if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
+ set_smb_read_error(pre, SMB_READ_TIMEOUT);
+ return -1;
+ }
+
+ set_smb_read_error(pre, SMB_READ_ERROR);
+ return -1;
}
+
msgtype = CVAL(inbuf, 0);
}
@@ -1225,21 +1226,28 @@ ssize_t receive_smb_raw(int fd,
size_t maxlen,
enum smb_read_errors *pre)
{
- ssize_t len,ret;
+ size_t len;
+ ssize_t ret;
+ NTSTATUS status;
set_smb_read_error(pre,SMB_READ_OK);
- len = read_smb_length_return_keepalive(fd,buffer,timeout,pre);
- if (len < 0) {
- DEBUG(10,("receive_smb_raw: length < 0!\n"));
+ status = read_smb_length_return_keepalive(fd,buffer,timeout,&len);
- /*
- * Correct fix. smb_read_error may have already been
- * set. Only set it here if not already set. Global
- * variables still suck :-). JRA.
- */
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10, ("receive_smb_raw: %s!\n", nt_errstr(status)));
+
+ if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
+ set_smb_read_error(pre, SMB_READ_EOF);
+ return -1;
+ }
+
+ if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
+ set_smb_read_error(pre, SMB_READ_TIMEOUT);
+ return -1;
+ }
- cond_set_smb_read_error(pre,SMB_READ_ERROR);
+ set_smb_read_error(pre, SMB_READ_ERROR);
return -1;
}
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index 4672510d8d..d6301d0d00 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -300,24 +300,30 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx,
size_t *p_unread)
{
char lenbuf[4];
- ssize_t len,ret;
+ size_t len;
+ ssize_t ret;
int min_recv_size = lp_min_receive_file_size();
+ NTSTATUS status;
set_smb_read_error(get_srv_read_error(),SMB_READ_OK);
*p_unread = 0;
- len = read_smb_length_return_keepalive(fd, lenbuf,
- timeout, get_srv_read_error());
- if (len < 0) {
- DEBUG(10,("receive_smb_raw: length < 0!\n"));
+ status = read_smb_length_return_keepalive(fd, lenbuf, timeout, &len);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(10, ("receive_smb_raw: %s\n", nt_errstr(status)));
- /*
- * Correct fix. smb_read_error may have already been
- * set. Only set it here if not already set. Global
- * variables still suck :-). JRA.
- */
+ if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) {
+ set_smb_read_error(get_srv_read_error(), SMB_READ_EOF);
+ return -1;
+ }
- cond_set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR);
+ if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
+ set_smb_read_error(get_srv_read_error(),
+ SMB_READ_TIMEOUT);
+ return -1;
+ }
+
+ set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR);
return -1;
}