[PATCH - 1/1] libsmb: Sending smb echo or keepalive request on the cached connection before re-using

Har Gagan Sahai shargagan at novell.com
Sun Feb 1 21:56:26 MST 2015


This patch is fixing the issue : 
*11079 ( https://bugzilla.samba.org/show_bug.cgi?id=11079. ) - libsmbclient not checking the cached connection alive status before re-using it from connection cache 

 The ( https://bugzilla.samba.org/show_bug.cgi?id=11079.The ) issue is with libsmbclient, which is using the cached connection part of SMBC context without checking for its alive status. We noticed this issue while using libsmbclient against 2008R2 (SMB2).  

[MS-SMB2] Session Expiration Timer -  
This timer controls the periodic scheduling of searching for sessions that have passed their expiration time. The server SHOULD<172> schedule this timer such that sessions are expired in a timely manner. This timer is also used for scavenging connections on which the NEGOTIATE and SESSION_SETUP have not been performed within a specified time. 

This timer is typically 45 secs. Because of 45 secs of session expiration timer, if the SMBC context is reused after 45 secs anytime, the cached connection is picked without checking for its connection status. In that case the SMB call done on that connection fails with NT_STATUS_CONNECTION_RESET error. 

This patch is attempting to address the issue. After doing this change, the SMBC_check_server() will returns '1', when the connection is closed during time expiration processing on the server. When that happens, SMBC_find_server() which had called SMBC_check_server(), will return 'NULL' for the 'srv' to the SMBC_server_internal(). In that case the function will attempt to re-create the connection, so that the client is not impacted. 

Here is the patch : 

Signed-off-by: Har Gagan Sahai <SHarGagan at novell.com> 
 source3/libsmb/libsmb_server.c | 14 ++++++++++++++ 
 1 file changed, 14 insertions(+) 

diff --git a/source3/libsmb/libsmb_server.c b/source3/libsmb/libsmb_server.c 
index 8f68a40..118770b 100644 
--- a/source3/libsmb/libsmb_server.c 
+++ b/source3/libsmb/libsmb_server.c 
@@ -45,10 +45,24 @@ int 
 SMBC_check_server(SMBCCTX * context, 
                   SMBCSRV * server) 
+       NT_STATUS status = NT_STATUS_OK; 
        if (!cli_state_is_connected(server->cli)) { 
                return 1; 

+       if (smbXcli_conn_protocol(server->cli->conn) >= PROTOCOL_SMB2_02) { 
+               status = smb2cli_echo(server->cli->conn, 0); 
+       } else { 
+               unsigned char data[16] = {0}; 
+               memset(data, 0xf0, sizeof(data)); 
+               status = cli_echo(server->cli, 1, data_blob_const(data, sizeof(data))); 
+       } 
+       if (!NT_STATUS_IS_OK(status)) { 
+               return 1; 
+       } 
        return 0; 


Har Gagan Sahai 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0001-Sending-SMB-Echo-or-KeepAlive-request-on-the-cached-.patch
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20150201/349c1d21/attachment.ksh>

More information about the samba-technical mailing list