From 056ab48a7103a50b86ae7e31ee863da52e9427b8 Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Thu, 24 Aug 2017 12:01:12 +0300 Subject: [PATCH] SMBServer: Bugfix: Do not send NotifyChange response if the session has been closed --- SMBLibrary/Server/SMB1/NotifyChangeHelper.cs | 48 ++++++++++---------- SMBLibrary/Server/SMB2/ChangeNotifyHelper.cs | 19 ++++---- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/SMBLibrary/Server/SMB1/NotifyChangeHelper.cs b/SMBLibrary/Server/SMB1/NotifyChangeHelper.cs index b14db95..dcf24c0 100644 --- a/SMBLibrary/Server/SMB1/NotifyChangeHelper.cs +++ b/SMBLibrary/Server/SMB1/NotifyChangeHelper.cs @@ -52,31 +52,31 @@ namespace SMBLibrary.Server.SMB1 { connection.LogToServer(Severity.Verbose, "NotifyChange: Monitoring of '{0}{1}' completed. NTStatus: {2}. PID: {3}. MID: {4}.", openFile.ShareName, openFile.Path, status, asyncContext.PID, asyncContext.MID); } - } - SMB1Header header = new SMB1Header(); - header.Command = CommandName.SMB_COM_NT_TRANSACT; - header.Status = status; - header.Flags = HeaderFlags.CaseInsensitive | HeaderFlags.CanonicalizedPaths | HeaderFlags.Reply; - // [MS-CIFS] SMB_FLAGS2_LONG_NAMES SHOULD be set to 1 when the negotiated dialect is NT LANMAN. - // [MS-CIFS] SMB_FLAGS2_UNICODE SHOULD be set to 1 when the negotiated dialect is NT LANMAN. - // [MS-CIFS] The Windows NT Server implementation of NT_TRANSACT_NOTIFY_CHANGE always returns the names of changed files in Unicode format. - header.Flags2 = HeaderFlags2.LongNamesAllowed | HeaderFlags2.NTStatusCode | HeaderFlags2.Unicode; - header.UID = asyncContext.UID; - header.TID = asyncContext.TID; - header.PID = asyncContext.PID; - header.MID = asyncContext.MID; - notifyChangeResponse.FileNotifyInformationBytes = buffer; + SMB1Header header = new SMB1Header(); + header.Command = CommandName.SMB_COM_NT_TRANSACT; + header.Status = status; + header.Flags = HeaderFlags.CaseInsensitive | HeaderFlags.CanonicalizedPaths | HeaderFlags.Reply; + // [MS-CIFS] SMB_FLAGS2_LONG_NAMES SHOULD be set to 1 when the negotiated dialect is NT LANMAN. + // [MS-CIFS] SMB_FLAGS2_UNICODE SHOULD be set to 1 when the negotiated dialect is NT LANMAN. + // [MS-CIFS] The Windows NT Server implementation of NT_TRANSACT_NOTIFY_CHANGE always returns the names of changed files in Unicode format. + header.Flags2 = HeaderFlags2.LongNamesAllowed | HeaderFlags2.NTStatusCode | HeaderFlags2.Unicode; + header.UID = asyncContext.UID; + header.TID = asyncContext.TID; + header.PID = asyncContext.PID; + header.MID = asyncContext.MID; + notifyChangeResponse.FileNotifyInformationBytes = buffer; - byte[] responseSetup = notifyChangeResponse.GetSetup(); - byte[] responseParameters = notifyChangeResponse.GetParameters(false); - byte[] responseData = notifyChangeResponse.GetData(); - List responseList = NTTransactHelper.GetNTTransactResponse(responseSetup, responseParameters, responseData, asyncContext.Connection.MaxBufferSize); - foreach (SMB1Command response in responseList) - { - SMB1Message reply = new SMB1Message(); - reply.Header = header; - reply.Commands.Add(response); - SMBServer.EnqueueMessage(asyncContext.Connection, reply); + byte[] responseSetup = notifyChangeResponse.GetSetup(); + byte[] responseParameters = notifyChangeResponse.GetParameters(false); + byte[] responseData = notifyChangeResponse.GetData(); + List responseList = NTTransactHelper.GetNTTransactResponse(responseSetup, responseParameters, responseData, asyncContext.Connection.MaxBufferSize); + foreach (SMB1Command response in responseList) + { + SMB1Message reply = new SMB1Message(); + reply.Header = header; + reply.Commands.Add(response); + SMBServer.EnqueueMessage(asyncContext.Connection, reply); + } } } } diff --git a/SMBLibrary/Server/SMB2/ChangeNotifyHelper.cs b/SMBLibrary/Server/SMB2/ChangeNotifyHelper.cs index e291d54..5c4854f 100644 --- a/SMBLibrary/Server/SMB2/ChangeNotifyHelper.cs +++ b/SMBLibrary/Server/SMB2/ChangeNotifyHelper.cs @@ -53,17 +53,16 @@ namespace SMBLibrary.Server.SMB2 { connection.LogToServer(Severity.Verbose, "NotifyChange: Monitoring of '{0}{1}' completed. NTStatus: {2}. AsyncID: {3}", openFile.ShareName, openFile.Path, status, asyncContext.AsyncID); } + ChangeNotifyResponse response = new ChangeNotifyResponse(); + response.Header.Status = status; + response.Header.IsAsync = true; + response.Header.IsSigned = session.SigningRequired; + response.Header.AsyncID = asyncContext.AsyncID; + response.Header.SessionID = asyncContext.SessionID; + response.OutputBuffer = buffer; + + SMBServer.EnqueueResponse(connection, response); } - - ChangeNotifyResponse response = new ChangeNotifyResponse(); - response.Header.Status = status; - response.Header.IsAsync = true; - response.Header.IsSigned = session.SigningRequired; - response.Header.AsyncID = asyncContext.AsyncID; - response.Header.SessionID = asyncContext.SessionID; - response.OutputBuffer = buffer; - - SMBServer.EnqueueResponse(connection, response); } } }