From: Felix Bussmann Date: Mon, 18 Mar 2024 14:19:18 +0000 (+0100) Subject: smbclient3: Replacing Echos in the cli status check with TCP status check. X-Git-Tag: tevent-0.17.0~599 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3830f2fe4d50402760de88695118a28c83c7f3b;p=thirdparty%2Fsamba.git smbclient3: Replacing Echos in the cli status check with TCP status check. Replacing the echoes, which were being sent every 5 seconds by the client for a CLI status check, with a method that checks the status of the file descriptor instead, for a POLLHUP, POLLRDHUP, or a timeout. Signed-off-by: Felix Bussmann Reviewed-by: Ralph Boehme Reviewed-by: Andreas Schneider Autobuild-User(master): Anoop C S Autobuild-Date(master): Wed Mar 5 16:21:34 UTC 2025 on atb-devel-224 --- diff --git a/libcli/smb/smbXcli_base.c b/libcli/smb/smbXcli_base.c index 6b479a78145..7f275b59991 100644 --- a/libcli/smb/smbXcli_base.c +++ b/libcli/smb/smbXcli_base.c @@ -474,6 +474,8 @@ struct smbXcli_conn *smbXcli_conn_create(TALLOC_CTX *mem_ctx, bool smbXcli_conn_is_connected(struct smbXcli_conn *conn) { + int ret; + if (conn == NULL) { return false; } @@ -482,6 +484,11 @@ bool smbXcli_conn_is_connected(struct smbXcli_conn *conn) return false; } + ret = samba_socket_poll_or_sock_error(conn->sock_fd); + if ( ret < 0) { + return false; + } + return true; } diff --git a/source3/client/client.c b/source3/client/client.c index d1ccc8cb54e..c15d9a9eb69 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -6124,42 +6124,11 @@ cleanup: static bool finished; -/**************************************************************************** - Make sure we swallow keepalives during idle time. -****************************************************************************/ - -static void readline_callback(void) +static void cli_status_check(void) { - static time_t last_t; - struct timespec now; - time_t t; - NTSTATUS status; - unsigned char garbage[16]; - - clock_gettime_mono(&now); - t = now.tv_sec; - - if (t - last_t < 5) - return; - - last_t = t; - - /* Ping the server to keep the connection alive using SMBecho. */ - memset(garbage, 0xf0, sizeof(garbage)); - status = cli_echo(cli, 1, data_blob_const(garbage, sizeof(garbage))); - if (NT_STATUS_IS_OK(status) || - NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) { - /* - * Even if server returns NT_STATUS_INVALID_PARAMETER - * it still responded. - * BUG: https://bugzilla.samba.org/show_bug.cgi?id=13007 - */ - return; - } - if (!cli_state_is_connected(cli)) { - DEBUG(0,("SMBecho failed (%s). The connection is " - "disconnected now\n", nt_errstr(status))); + DEBUG(0,("SMB echo failed (%s). The connection is " + "disconnected now\n", nt_errstr(NT_STATUS_CONNECTION_DISCONNECTED))); finished = true; smb_readline_done(); } @@ -6192,7 +6161,7 @@ static int process_stdin(void) TALLOC_FREE(frame); break; } - line = smb_readline(the_prompt, readline_callback, completion_fn); + line = smb_readline(the_prompt, cli_status_check, completion_fn); if (!line) { TALLOC_FREE(frame); break;