From 0afbfa4284db8204a3696f4fea6cff96965e6074 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 21:24:48 +0100 Subject: Convert read_smb_length_return_keepalive to return NTSTATUS (This used to be commit 73a79a957a33a8761acf54598ce71e3604ecf3c5) --- source3/smbd/process.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'source3/smbd/process.c') 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; } -- cgit From 48b1ee61db5f513321b7f3360eb17f94ef339872 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 22:21:38 +0100 Subject: Convert read_packet_remainder to use read_socket_with_timeout_ntstatus (This used to be commit fff31f8f35ad26d67e78b9a71cfd35670aa9ac5f) --- source3/smbd/process.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index d6301d0d00..02b190f003 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -148,22 +148,34 @@ static ssize_t read_packet_remainder(int fd, unsigned int timeout, ssize_t len) { - ssize_t ret; + NTSTATUS status; - if(len <= 0) { + if (len <= 0) { return len; } - ret = read_socket_with_timeout(fd, buffer, len, len, timeout, - get_srv_read_error()); + set_smb_read_error(get_srv_read_error(), SMB_READ_OK); - if (ret != len) { - cond_set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); + status = read_socket_with_timeout_ntstatus(fd, buffer, len, len, + timeout, NULL); + + if (NT_STATUS_IS_OK(status)) { + return len; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); return -1; } - return len; + 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; } /**************************************************************************** -- cgit From e604e137e21af52efdbabc28863a5ea76d8d620d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 22:27:59 +0100 Subject: Convert read_packet_remainder to return NTSTATUS (This used to be commit 667864d442ea7e1faed7b032315db8856fa91481) --- source3/smbd/process.c | 81 +++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 37 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 02b190f003..4d9a90a840 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -143,39 +143,15 @@ static bool valid_packet_size(size_t len) return true; } -static ssize_t read_packet_remainder(int fd, - char *buffer, - unsigned int timeout, - ssize_t len) +static NTSTATUS read_packet_remainder(int fd, char *buffer, + unsigned int timeout, ssize_t len) { - NTSTATUS status; - if (len <= 0) { - return len; - } - - set_smb_read_error(get_srv_read_error(), SMB_READ_OK); - - status = read_socket_with_timeout_ntstatus(fd, buffer, len, len, - timeout, NULL); - - if (NT_STATUS_IS_OK(status)) { - return len; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); - return -1; + return NT_STATUS_OK; } - 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; + return read_socket_with_timeout_ntstatus(fd, buffer, len, len, + timeout, NULL); } /**************************************************************************** @@ -293,11 +269,29 @@ static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, toread = len - STANDARD_WRITE_AND_X_HEADER_SIZE; if(toread > 0) { - ret = read_packet_remainder(fd, - (*buffer) + 4 + STANDARD_WRITE_AND_X_HEADER_SIZE, - timeout, - toread); - if (ret != toread) { + NTSTATUS status; + + set_smb_read_error(get_srv_read_error(), SMB_READ_OK); + + status = read_packet_remainder( + fd, (*buffer) + 4 + STANDARD_WRITE_AND_X_HEADER_SIZE, + timeout, toread); + + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_EOF); + return -1; + } + + 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; } } @@ -313,7 +307,6 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, { char lenbuf[4]; size_t len; - ssize_t ret; int min_recv_size = lp_min_receive_file_size(); NTSTATUS status; @@ -371,8 +364,22 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, memcpy(*buffer, lenbuf, sizeof(lenbuf)); - ret = read_packet_remainder(fd, (*buffer)+4, timeout, len); - if (ret != len) { + status = read_packet_remainder(fd, (*buffer)+4, timeout, len); + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_EOF); + return -1; + } + + 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; } -- cgit From 250b2b6464521fa4e2b5c737164e1ce68755677f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:12:04 +0100 Subject: Convert receive_smb_raw_talloc_partial_read to NTSTATUS (This used to be commit 9a82350ba92bf5fc4f2968d5130bcb2118e7a981) --- source3/smbd/process.c | 106 ++++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 59 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 4d9a90a840..10ef67c2b2 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -128,15 +128,6 @@ static bool valid_packet_size(size_t len) DEBUG(0,("Invalid packet length! (%lu bytes).\n", (unsigned long)len)); if (len > BUFFER_SIZE + (SAFETY_MARGIN/2)) { - - /* - * Correct fix. smb_read_error may have already been - * set. Only set it here if not already set. Global - * variables still suck :-). JRA. - */ - - cond_set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); return false; } } @@ -170,30 +161,29 @@ static NTSTATUS read_packet_remainder(int fd, char *buffer, (2*14) + /* word count (including bcc) */ \ 1 /* pad byte */) -static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, - const char lenbuf[4], - int fd, - char **buffer, - unsigned int timeout, - size_t *p_unread) +static NTSTATUS receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, + const char lenbuf[4], + int fd, char **buffer, + unsigned int timeout, + size_t *p_unread, + size_t *len_ret) { /* Size of a WRITEX call (+4 byte len). */ char writeX_header[4 + STANDARD_WRITE_AND_X_HEADER_SIZE]; ssize_t len = smb_len_large(lenbuf); /* Could be a UNIX large writeX. */ ssize_t toread; - ssize_t ret; + NTSTATUS status; memcpy(writeX_header, lenbuf, sizeof(lenbuf)); - ret = read_socket_with_timeout(fd, writeX_header + 4, - STANDARD_WRITE_AND_X_HEADER_SIZE, - STANDARD_WRITE_AND_X_HEADER_SIZE, - timeout, get_srv_read_error()); + status = read_socket_with_timeout_ntstatus( + fd, writeX_header + 4, + STANDARD_WRITE_AND_X_HEADER_SIZE, + STANDARD_WRITE_AND_X_HEADER_SIZE, + timeout, NULL); - if (ret != STANDARD_WRITE_AND_X_HEADER_SIZE) { - cond_set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); - return -1; + if (!NT_STATUS_IS_OK(status)) { + return status; } /* @@ -232,19 +222,17 @@ static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)sizeof(writeX_header))); - cond_set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); - return -1; + return NT_STATUS_NO_MEMORY; } /* Work out the remaining bytes. */ *p_unread = len - STANDARD_WRITE_AND_X_HEADER_SIZE; - - return newlen + 4; + *len_ret = newlen + 4; + return NT_STATUS_OK; } if (!valid_packet_size(len)) { - return -1; + return NT_STATUS_INVALID_PARAMETER; } /* @@ -257,9 +245,7 @@ static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)len+4)); - cond_set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); - return -1; + return NT_STATUS_NO_MEMORY; } /* Copy in what we already read. */ @@ -269,34 +255,17 @@ static ssize_t receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, toread = len - STANDARD_WRITE_AND_X_HEADER_SIZE; if(toread > 0) { - NTSTATUS status; - - set_smb_read_error(get_srv_read_error(), SMB_READ_OK); - status = read_packet_remainder( fd, (*buffer) + 4 + STANDARD_WRITE_AND_X_HEADER_SIZE, timeout, toread); if (!NT_STATUS_IS_OK(status)) { - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_EOF); - return -1; - } - - 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; + return status; } } - return len + 4; + *len_ret = len + 4; + return NT_STATUS_OK; } static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, @@ -337,15 +306,34 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, smb_len_large(lenbuf) > min_recv_size && /* Could be a UNIX large writeX. */ !srv_is_signing_active()) { - return receive_smb_raw_talloc_partial_read(mem_ctx, - lenbuf, - fd, - buffer, - timeout, - p_unread); + status = receive_smb_raw_talloc_partial_read( + mem_ctx, lenbuf, fd, buffer, timeout, p_unread, &len); + + 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(get_srv_read_error(), + SMB_READ_EOF); + return -1; + } + + 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; + } } if (!valid_packet_size(len)) { + cond_set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); return -1; } -- cgit From 9fe66ddd15b3c5b5d9a30fc79d6ed6cdb31cae12 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:18:56 +0100 Subject: Convert receive_smb_raw_talloc to NTSTATUS (This used to be commit 187707591ffa2668aecd4857cb2ef2cd20bd6b08) --- source3/smbd/process.c | 90 ++++++++++++++++---------------------------------- 1 file changed, 29 insertions(+), 61 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 10ef67c2b2..cb7d12a0c3 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -268,37 +268,21 @@ static NTSTATUS receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } -static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, - int fd, - char **buffer, - unsigned int timeout, - size_t *p_unread) +static NTSTATUS receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, int fd, + char **buffer, unsigned int timeout, + size_t *p_unread, size_t *plen) { char lenbuf[4]; size_t len; 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; 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))); - - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); - return -1; - } - - 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; + return status; } if (CVAL(lenbuf,0) == 0 && @@ -310,31 +294,14 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, mem_ctx, lenbuf, fd, buffer, timeout, p_unread, &len); 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(get_srv_read_error(), - SMB_READ_EOF); - return -1; - } - - 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; + return status; } } if (!valid_packet_size(len)) { - cond_set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); - return -1; + return NT_STATUS_INVALID_PARAMETER; } /* @@ -346,32 +313,18 @@ static ssize_t receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, if (*buffer == NULL) { DEBUG(0, ("Could not allocate inbuf of length %d\n", (int)len+4)); - cond_set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); - return -1; + return NT_STATUS_NO_MEMORY; } memcpy(*buffer, lenbuf, sizeof(lenbuf)); status = read_packet_remainder(fd, (*buffer)+4, timeout, len); if (!NT_STATUS_IS_OK(status)) { - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_EOF); - return -1; - } - - 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; + return status; } - return len + 4; + *plen = len + 4; + return NT_STATUS_OK; } static ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, @@ -381,18 +334,33 @@ static ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, size_t *p_unread, bool *p_encrypted) { - ssize_t len; + size_t len; + NTSTATUS status; *p_encrypted = false; - len = receive_smb_raw_talloc(mem_ctx, fd, buffer, timeout, p_unread); + set_smb_read_error(get_srv_read_error(), SMB_READ_OK); + + status = receive_smb_raw_talloc(mem_ctx, fd, buffer, timeout, + p_unread, &len); + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); + return -1; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + return -1; + } - if (len < 0) { + set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR); return -1; } if (is_encrypted_packet((uint8_t *)*buffer)) { - NTSTATUS status = srv_decrypt_buffer(*buffer); + status = srv_decrypt_buffer(*buffer); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("receive_smb_talloc: SMB decryption failed on " "incoming packet! Error %s\n", -- cgit From e514cd0af56031cd0396e716e9e77edf897420e9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:28:22 +0100 Subject: Convert receive_smb_talloc to NTSTATUS (This used to be commit ddbdd11a49fba9ec4834807dec385cdf3120ce00) --- source3/smbd/process.c | 61 +++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 33 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index cb7d12a0c3..e21229109d 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -327,36 +327,20 @@ static NTSTATUS receive_smb_raw_talloc(TALLOC_CTX *mem_ctx, int fd, return NT_STATUS_OK; } -static ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, - int fd, - char **buffer, - unsigned int timeout, - size_t *p_unread, - bool *p_encrypted) +static NTSTATUS receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, + char **buffer, unsigned int timeout, + size_t *p_unread, bool *p_encrypted, + size_t *p_len) { size_t len; NTSTATUS status; *p_encrypted = false; - set_smb_read_error(get_srv_read_error(), SMB_READ_OK); - status = receive_smb_raw_talloc(mem_ctx, fd, buffer, timeout, p_unread, &len); if (!NT_STATUS_IS_OK(status)) { - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); - return -1; - } - - 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; + return status; } if (is_encrypted_packet((uint8_t *)*buffer)) { @@ -365,9 +349,7 @@ static ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, DEBUG(0, ("receive_smb_talloc: SMB decryption failed on " "incoming packet! Error %s\n", nt_errstr(status) )); - cond_set_smb_read_error(get_srv_read_error(), - SMB_READ_BAD_DECRYPT); - return -1; + return status; } *p_encrypted = true; } @@ -376,11 +358,11 @@ static ssize_t receive_smb_talloc(TALLOC_CTX *mem_ctx, if (!srv_check_sign_mac(*buffer, true)) { DEBUG(0, ("receive_smb: SMB Signature verification failed on " "incoming packet!\n")); - cond_set_smb_read_error(get_srv_read_error(),SMB_READ_BAD_SIG); - return -1; + return NT_STATUS_INVALID_NETWORK_RESPONSE; } - return len; + *p_len = len; + return NT_STATUS_OK; } /* @@ -748,7 +730,8 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, int selrtn; struct timeval to; int maxfd = 0; - ssize_t len; + size_t len; + NTSTATUS status; *p_unread = 0; set_smb_read_error(get_srv_read_error(),SMB_READ_OK); @@ -926,14 +909,26 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, goto again; } - len = receive_smb_talloc(mem_ctx, smbd_server_fd(), - buffer, 0, p_unread, p_encrypted); + status = receive_smb_talloc(mem_ctx, smbd_server_fd(), buffer, 0, + p_unread, p_encrypted, &len); - if (len == -1) { - return False; + if (!NT_STATUS_IS_OK(status)) { + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); + return false; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + return false; + } + + set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR); + return false; } - *buffer_len = (size_t)len; + *buffer_len = len; return True; } -- cgit From 6ddfa6ae7734ffdd26ac38478c27cc9d646ddadd Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:43:50 +0100 Subject: read_socket_with_timeout_ntstatus->read_socket_with_timeout (This used to be commit 90554799afa42855c3e7b87dc632e67f0952f988) --- source3/smbd/process.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index e21229109d..83e51e3892 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -141,8 +141,7 @@ static NTSTATUS read_packet_remainder(int fd, char *buffer, return NT_STATUS_OK; } - return read_socket_with_timeout_ntstatus(fd, buffer, len, len, - timeout, NULL); + return read_socket_with_timeout(fd, buffer, len, len, timeout, NULL); } /**************************************************************************** @@ -176,7 +175,7 @@ static NTSTATUS receive_smb_raw_talloc_partial_read(TALLOC_CTX *mem_ctx, memcpy(writeX_header, lenbuf, sizeof(lenbuf)); - status = read_socket_with_timeout_ntstatus( + status = read_socket_with_timeout( fd, writeX_header + 4, STANDARD_WRITE_AND_X_HEADER_SIZE, STANDARD_WRITE_AND_X_HEADER_SIZE, -- cgit From 21e7344d2f45416ea996f88be72de1a923c0ee9c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Jan 2008 23:57:20 +0100 Subject: Make get_srv_read_error static to process.c (This used to be commit 9e2947039ef70cab8bbd6027182d9c721eac3194) --- source3/smbd/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 83e51e3892..f5a3186e5e 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -43,7 +43,7 @@ extern int max_send; /* Accessor function for smb_read_error for smbd functions. */ -enum smb_read_errors *get_srv_read_error(void) +static enum smb_read_errors *get_srv_read_error(void) { return &smb_read_error; } -- cgit From eaf7621c51629f058b85ce4593a2338b9b2d06ed Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Jan 2008 15:18:33 +0100 Subject: Convert receive_message_or_smb to NTSTATUS (This used to be commit 0f7d360a01baf02e251846118cb36e6a1cdcbeb9) --- source3/smbd/process.c | 79 +++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 36 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index f5a3186e5e..4fa1248e3b 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -718,12 +718,9 @@ static int select_on_fd(int fd, int maxfd, fd_set *fds) The timeout is in milliseconds ****************************************************************************/ -static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, - char **buffer, - size_t *buffer_len, - int timeout, - size_t *p_unread, - bool *p_encrypted) +static NTSTATUS receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, + size_t *buffer_len, int timeout, + size_t *p_unread, bool *p_encrypted) { fd_set r_fds, w_fds; int selrtn; @@ -733,7 +730,6 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, NTSTATUS status; *p_unread = 0; - set_smb_read_error(get_srv_read_error(),SMB_READ_OK); again: @@ -787,8 +783,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, msg->buf.length); if (*buffer == NULL) { DEBUG(0, ("talloc failed\n")); - set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); - return False; + return NT_STATUS_NO_MEMORY; } *buffer_len = msg->buf.length; *p_encrypted = msg->encrypted; @@ -796,7 +791,7 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, /* We leave this message on the queue so the open code can know this is a retry. */ DEBUG(5,("receive_message_or_smb: returning deferred open smb message.\n")); - return True; + return NT_STATUS_OK; } } @@ -882,14 +877,12 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, /* Check if error */ if (selrtn == -1) { /* something is wrong. Maybe the socket is dead? */ - set_smb_read_error(get_srv_read_error(),SMB_READ_ERROR); - return False; + return map_nt_error_from_unix(errno); } /* Did we timeout ? */ if (selrtn == 0) { - set_smb_read_error(get_srv_read_error(),SMB_READ_TIMEOUT); - return False; + return NT_STATUS_IO_TIMEOUT; } /* @@ -912,24 +905,12 @@ static bool receive_message_or_smb(TALLOC_CTX *mem_ctx, p_unread, p_encrypted, &len); if (!NT_STATUS_IS_OK(status)) { - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), SMB_READ_EOF); - return false; - } - - if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_TIMEOUT); - return false; - } - - set_smb_read_error(get_srv_read_error(), SMB_READ_ERROR); - return false; + return status; } *buffer_len = len; - return True; + return NT_STATUS_OK; } /* @@ -2024,8 +2005,8 @@ void smbd_process(void) while (True) { int select_timeout = setup_select_timeout(); int num_echos; - char *inbuf; - size_t inbuf_len; + char *inbuf = NULL; + size_t inbuf_len = 0; bool encrypted = false; TALLOC_CTX *frame = talloc_stackframe_pool(8192); @@ -2041,13 +2022,39 @@ void smbd_process(void) run_events(smbd_event_context(), 0, NULL, NULL); - while (!receive_message_or_smb(talloc_tos(), &inbuf, &inbuf_len, - select_timeout, - &unread_bytes, - &encrypted)) { - if(!timeout_processing(&select_timeout, - &last_timeout_processing_time)) + while (True) { + NTSTATUS status; + + set_smb_read_error(get_srv_read_error(), SMB_READ_OK); + + status = receive_message_or_smb( + talloc_tos(), &inbuf, &inbuf_len, + select_timeout, &unread_bytes, &encrypted); + + if (NT_STATUS_IS_OK(status)) { + break; + } + + if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_EOF); + } + else if (NT_STATUS_EQUAL(status, + NT_STATUS_IO_TIMEOUT)) { + set_smb_read_error(get_srv_read_error(), + SMB_READ_TIMEOUT); + } + else { + set_smb_read_error(get_srv_read_error(), + SMB_READ_ERROR); + } + + if (!timeout_processing( + &select_timeout, + &last_timeout_processing_time)) { return; + } + num_smbs = 0; /* Reset smb counter. */ } -- cgit From 9e5a5d49dee83335f6990c4ec5d3b11f1f69e2e7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Jan 2008 15:33:40 +0100 Subject: Remove dependency on get_srv_read_error() from main loop (This used to be commit fad87968921eca0b5144760c412c5f599f9066f3) --- source3/smbd/process.c | 69 +++++++++++++++----------------------------------- 1 file changed, 20 insertions(+), 49 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 4fa1248e3b..3cb1331054 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -1888,27 +1888,11 @@ void check_reload(time_t t) Process any timeout housekeeping. Return False if the caller should exit. ****************************************************************************/ -static bool timeout_processing(int *select_timeout, +static void timeout_processing(int *select_timeout, time_t *last_timeout_processing_time) { time_t t; - if (*get_srv_read_error() == SMB_READ_EOF) { - DEBUG(3,("timeout_processing: End of file from client (client has disconnected).\n")); - return false; - } - - if (*get_srv_read_error() == SMB_READ_ERROR) { - DEBUG(3,("timeout_processing: receive_smb error (%s) Exiting\n", - strerror(errno))); - return false; - } - - if (*get_srv_read_error() == SMB_READ_BAD_SIG) { - DEBUG(3,("timeout_processing: receive_smb error bad smb signature. Exiting\n")); - return false; - } - *last_timeout_processing_time = t = time(NULL); /* become root again if waiting */ @@ -1938,14 +1922,14 @@ static bool timeout_processing(int *select_timeout, if (secrets_lock_trust_account_password(lp_workgroup(), True) == False) { DEBUG(0,("process: unable to lock the machine account password for \ machine %s in domain %s.\n", global_myname(), lp_workgroup() )); - return True; + return; } if(!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd_hash, &lct, NULL)) { DEBUG(0,("process: unable to read the machine account password for \ machine %s in domain %s.\n", global_myname(), lp_workgroup())); secrets_lock_trust_account_password(lp_workgroup(), False); - return True; + return; } /* @@ -1955,7 +1939,7 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); if(t < lct + lp_machine_password_timeout()) { global_machine_password_needs_changing = False; secrets_lock_trust_account_password(lp_workgroup(), False); - return True; + return; } /* always just contact the PDC here */ @@ -1987,7 +1971,7 @@ machine %s in domain %s.\n", global_myname(), lp_workgroup())); *select_timeout = setup_select_timeout(); - return True; + return; } /**************************************************************************** @@ -2014,9 +1998,8 @@ void smbd_process(void) /* Did someone ask for immediate checks on things like blocking locks ? */ if (select_timeout == 0) { - if(!timeout_processing(&select_timeout, - &last_timeout_processing_time)) - return; + timeout_processing(&select_timeout, + &last_timeout_processing_time); num_smbs = 0; /* Reset smb counter. */ } @@ -2025,8 +2008,6 @@ void smbd_process(void) while (True) { NTSTATUS status; - set_smb_read_error(get_srv_read_error(), SMB_READ_OK); - status = receive_message_or_smb( talloc_tos(), &inbuf, &inbuf_len, select_timeout, &unread_bytes, &encrypted); @@ -2035,25 +2016,16 @@ void smbd_process(void) break; } - if (NT_STATUS_EQUAL(status, NT_STATUS_END_OF_FILE)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_EOF); - } - else if (NT_STATUS_EQUAL(status, - NT_STATUS_IO_TIMEOUT)) { - set_smb_read_error(get_srv_read_error(), - SMB_READ_TIMEOUT); - } - else { - set_smb_read_error(get_srv_read_error(), - SMB_READ_ERROR); + if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { + timeout_processing( + &select_timeout, + &last_timeout_processing_time); + continue; } - if (!timeout_processing( - &select_timeout, - &last_timeout_processing_time)) { - return; - } + DEBUG(3, ("receive_message_or_smb failed: %s, " + "exiting\n", nt_errstr(status))); + return; num_smbs = 0; /* Reset smb counter. */ } @@ -2075,8 +2047,8 @@ void smbd_process(void) TALLOC_FREE(inbuf); if (smb_echo_count != num_echos) { - if(!timeout_processing( &select_timeout, &last_timeout_processing_time)) - return; + timeout_processing(&select_timeout, + &last_timeout_processing_time); num_smbs = 0; /* Reset smb counter. */ } @@ -2092,10 +2064,9 @@ void smbd_process(void) if ((num_smbs % 200) == 0) { time_t new_check_time = time(NULL); if(new_check_time - last_timeout_processing_time >= (select_timeout/1000)) { - if(!timeout_processing( - &select_timeout, - &last_timeout_processing_time)) - return; + timeout_processing( + &select_timeout, + &last_timeout_processing_time); num_smbs = 0; /* Reset smb counter. */ last_timeout_processing_time = new_check_time; /* Reset time. */ } -- cgit From e8f1edb9cd0d2014c05cdb2aba4f4deef48efedf Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Jan 2008 15:36:00 +0100 Subject: Remove smb_read_error global YESS :-) (This used to be commit 26771bdca0e6837db267f4db7907e489acd92fc6) --- source3/smbd/process.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 3cb1331054..2a643864fa 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -22,8 +22,6 @@ extern int smb_echo_count; -static enum smb_read_errors smb_read_error = SMB_READ_OK; - /* * Size of data we can send to client. Set * by the client for all protocols above CORE. @@ -43,11 +41,6 @@ extern int max_send; /* Accessor function for smb_read_error for smbd functions. */ -static enum smb_read_errors *get_srv_read_error(void) -{ - return &smb_read_error; -} - /**************************************************************************** Send an smb to a fd. ****************************************************************************/ -- cgit From 47666c93a78dc7a9c18212bfe7be3e6487313226 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 5 Feb 2008 13:36:17 -0800 Subject: Fix a couple of "might be used uninitialized" warnings. Jeremy. (This used to be commit b3ac8073a23afbba19d045302aa0700197c58bd5) --- source3/smbd/process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/smbd/process.c') diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2a643864fa..68bec7830a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -324,7 +324,7 @@ static NTSTATUS receive_smb_talloc(TALLOC_CTX *mem_ctx, int fd, size_t *p_unread, bool *p_encrypted, size_t *p_len) { - size_t len; + size_t len = 0; NTSTATUS status; *p_encrypted = false; @@ -719,7 +719,7 @@ static NTSTATUS receive_message_or_smb(TALLOC_CTX *mem_ctx, char **buffer, int selrtn; struct timeval to; int maxfd = 0; - size_t len; + size_t len = 0; NTSTATUS status; *p_unread = 0; -- cgit