mirror of
https://github.com/samba-team/samba.git
synced 2024-12-25 23:21:54 +03:00
Convert read_smb_length_return_keepalive to return NTSTATUS
This commit is contained in:
parent
59e8f22f36
commit
73a79a957a
@ -1141,20 +1141,51 @@ bool send_keepalive(int client)
|
||||
Timeout is in milliseconds.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t read_smb_length_return_keepalive(int fd,
|
||||
char *inbuf,
|
||||
NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf,
|
||||
unsigned int timeout,
|
||||
enum smb_read_errors *pre)
|
||||
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)) {
|
||||
return status;
|
||||
}
|
||||
|
||||
*len = smb_len(inbuf);
|
||||
msg_type = CVAL(inbuf,0);
|
||||
|
||||
if (msg_type == SMBkeepalive) {
|
||||
DEBUG(5,("Got keepalive packet\n"));
|
||||
}
|
||||
|
||||
DEBUG(10,("got smb length of %lu\n",(unsigned long)len));
|
||||
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Read 4 bytes of a smb packet and return the smb length of the packet.
|
||||
Store the result in the buffer. This version of the function will
|
||||
never return a session keepalive (length of zero).
|
||||
Timeout is in milliseconds.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t read_smb_length(int fd, char *inbuf, unsigned int timeout, enum smb_read_errors *pre)
|
||||
{
|
||||
size_t len;
|
||||
uint8_t msgtype = SMBkeepalive;
|
||||
|
||||
set_smb_read_error(pre, SMB_READ_OK);
|
||||
|
||||
while (msgtype == SMBkeepalive) {
|
||||
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);
|
||||
@ -1170,36 +1201,6 @@ ssize_t read_smb_length_return_keepalive(int fd,
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = smb_len(inbuf);
|
||||
msg_type = CVAL(inbuf,0);
|
||||
|
||||
if (msg_type == SMBkeepalive) {
|
||||
DEBUG(5,("Got keepalive packet\n"));
|
||||
}
|
||||
|
||||
DEBUG(10,("got smb length of %lu\n",(unsigned long)len));
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
Read 4 bytes of a smb packet and return the smb length of the packet.
|
||||
Store the result in the buffer. This version of the function will
|
||||
never return a session keepalive (length of zero).
|
||||
Timeout is in milliseconds.
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t read_smb_length(int fd, char *inbuf, unsigned int timeout, enum smb_read_errors *pre)
|
||||
{
|
||||
ssize_t len;
|
||||
uint8_t msgtype = SMBkeepalive;
|
||||
|
||||
while (msgtype == SMBkeepalive) {
|
||||
len = read_smb_length_return_keepalive(fd, inbuf, timeout,
|
||||
pre);
|
||||
if (len < 0) {
|
||||
return len;
|
||||
}
|
||||
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)));
|
||||
|
||||
cond_set_smb_read_error(pre,SMB_READ_ERROR);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user