Bladeren bron

SMB1: Transaction requests to the NamedPipeStore will not be blocked at the SMB layer

Tal Aloni 8 jaren geleden
bovenliggende
commit
384efe97e7
2 gewijzigde bestanden met toevoegingen van 37 en 32 verwijderingen
  1. 31 18
      SMBLibrary/Server/SMB1/Transaction2SubcommandHelper.cs
  2. 6 14
      SMBLibrary/Server/SMB1/TransactionHelper.cs

+ 31 - 18
SMBLibrary/Server/SMB1/Transaction2SubcommandHelper.cs

@@ -15,7 +15,7 @@ namespace SMBLibrary.Server.SMB1
 {
     public class Transaction2SubcommandHelper
     {
-        internal static Transaction2FindFirst2Response GetSubcommandResponse(SMB1Header header, Transaction2FindFirst2Request subcommand, FileSystemShare share, SMB1ConnectionState state)
+        internal static Transaction2FindFirst2Response GetSubcommandResponse(SMB1Header header, Transaction2FindFirst2Request subcommand, ISMBShare share, SMB1ConnectionState state)
         {
             SMB1Session session = state.GetSession(header.UID);
             string fileNamePattern = subcommand.FileName;
@@ -79,7 +79,7 @@ namespace SMBLibrary.Server.SMB1
             return response;
         }
 
-        internal static Transaction2FindNext2Response GetSubcommandResponse(SMB1Header header, Transaction2FindNext2Request subcommand, FileSystemShare share, SMB1ConnectionState state)
+        internal static Transaction2FindNext2Response GetSubcommandResponse(SMB1Header header, Transaction2FindNext2Request subcommand, ISMBShare share, SMB1ConnectionState state)
         {
             SMB1Session session = state.GetSession(header.UID);
             OpenSearch openSearch = session.GetOpenSearch(subcommand.SID);
@@ -115,13 +115,16 @@ namespace SMBLibrary.Server.SMB1
             return response;
         }
 
-        internal static Transaction2QueryFSInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryFSInformationRequest subcommand, FileSystemShare share, SMB1ConnectionState state)
+        internal static Transaction2QueryFSInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryFSInformationRequest subcommand, ISMBShare share, SMB1ConnectionState state)
         {
             SMB1Session session = state.GetSession(header.UID);
-            if (!share.HasReadAccess(session.UserName, @"\", state.ClientEndPoint))
+            if (share is FileSystemShare)
             {
-                header.Status = NTStatus.STATUS_ACCESS_DENIED;
-                return null;
+                if (!((FileSystemShare)share).HasReadAccess(session.UserName, @"\", state.ClientEndPoint))
+                {
+                    header.Status = NTStatus.STATUS_ACCESS_DENIED;
+                    return null;
+                }
             }
 
             Transaction2QueryFSInformationResponse response = new Transaction2QueryFSInformationResponse();
@@ -137,15 +140,19 @@ namespace SMBLibrary.Server.SMB1
             return response;
         }
 
-        internal static Transaction2QueryPathInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryPathInformationRequest subcommand, FileSystemShare share, SMB1ConnectionState state)
+        internal static Transaction2QueryPathInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryPathInformationRequest subcommand, ISMBShare share, SMB1ConnectionState state)
         {
             SMB1Session session = state.GetSession(header.UID);
             string path = subcommand.FileName;
-            if (!share.HasReadAccess(session.UserName, path, state.ClientEndPoint))
+            if (share is FileSystemShare)
             {
-                header.Status = NTStatus.STATUS_ACCESS_DENIED;
-                return null;
+                if (!((FileSystemShare)share).HasReadAccess(session.UserName, path, state.ClientEndPoint))
+                {
+                    header.Status = NTStatus.STATUS_ACCESS_DENIED;
+                    return null;
+                }
             }
+
             Transaction2QueryPathInformationResponse response = new Transaction2QueryPathInformationResponse();
             QueryInformation queryInformation;
             NTStatus queryStatus = SMB1FileStoreHelper.GetFileInformation(out queryInformation, share.FileStore, path, subcommand.InformationLevel);
@@ -159,7 +166,7 @@ namespace SMBLibrary.Server.SMB1
             return response;
         }
 
-        internal static Transaction2QueryFileInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryFileInformationRequest subcommand, FileSystemShare share, SMB1ConnectionState state)
+        internal static Transaction2QueryFileInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryFileInformationRequest subcommand, ISMBShare share, SMB1ConnectionState state)
         {
             SMB1Session session = state.GetSession(header.UID);
             OpenFileObject openFile = session.GetOpenFileObject(subcommand.FID);
@@ -169,10 +176,13 @@ namespace SMBLibrary.Server.SMB1
                 return null;
             }
 
-            if (!share.HasReadAccess(session.UserName, openFile.Path, state.ClientEndPoint))
+            if (share is FileSystemShare)
             {
-                header.Status = NTStatus.STATUS_ACCESS_DENIED;
-                return null;
+                if (!((FileSystemShare)share).HasReadAccess(session.UserName, openFile.Path, state.ClientEndPoint))
+                {
+                    header.Status = NTStatus.STATUS_ACCESS_DENIED;
+                    return null;
+                }
             }
 
             Transaction2QueryFileInformationResponse response = new Transaction2QueryFileInformationResponse();
@@ -188,7 +198,7 @@ namespace SMBLibrary.Server.SMB1
             return response;
         }
 
-        internal static Transaction2SetFileInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2SetFileInformationRequest subcommand, FileSystemShare share, SMB1ConnectionState state)
+        internal static Transaction2SetFileInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2SetFileInformationRequest subcommand, ISMBShare share, SMB1ConnectionState state)
         {
             SMB1Session session = state.GetSession(header.UID);
             OpenFileObject openFile = session.GetOpenFileObject(subcommand.FID);
@@ -198,10 +208,13 @@ namespace SMBLibrary.Server.SMB1
                 return null;
             }
 
-            if (!share.HasWriteAccess(session.UserName, openFile.Path, state.ClientEndPoint))
+            if (share is FileSystemShare)
             {
-                header.Status = NTStatus.STATUS_ACCESS_DENIED;
-                return null;
+                if (!((FileSystemShare)share).HasWriteAccess(session.UserName, openFile.Path, state.ClientEndPoint))
+                {
+                    header.Status = NTStatus.STATUS_ACCESS_DENIED;
+                    return null;
+                }
             }
 
             SetInformation information;

+ 6 - 14
SMBLibrary/Server/SMB1/TransactionHelper.cs

@@ -195,29 +195,21 @@ namespace SMBLibrary.Server.SMB1
             }
             Transaction2Subcommand subcommandResponse = null;
 
-            if (!(share is FileSystemShare))
-            {
-                header.Status = NTStatus.STATUS_INVALID_PARAMETER;
-                return new ErrorResponse(CommandName.SMB_COM_TRANSACTION2);
-            }
-
-            FileSystemShare fileSystemShare = (FileSystemShare)share;
-
             if (subcommand is Transaction2FindFirst2Request)
             {
-                subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2FindFirst2Request)subcommand, fileSystemShare, state);
+                subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2FindFirst2Request)subcommand, share, state);
             }
             else if (subcommand is Transaction2FindNext2Request)
             {
-                subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2FindNext2Request)subcommand, fileSystemShare, state);
+                subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2FindNext2Request)subcommand, share, state);
             }
             else if (subcommand is Transaction2QueryFSInformationRequest)
             {
-                subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2QueryFSInformationRequest)subcommand, fileSystemShare, state);
+                subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2QueryFSInformationRequest)subcommand, share, state);
             }
             else if (subcommand is Transaction2QueryPathInformationRequest)
             {
-                subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2QueryPathInformationRequest)subcommand, fileSystemShare, state);
+                subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2QueryPathInformationRequest)subcommand, share, state);
             }
             else if (subcommand is Transaction2SetPathInformationRequest)
             {
@@ -225,11 +217,11 @@ namespace SMBLibrary.Server.SMB1
             }
             else if (subcommand is Transaction2QueryFileInformationRequest)
             {
-                subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2QueryFileInformationRequest)subcommand, fileSystemShare, state);
+                subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2QueryFileInformationRequest)subcommand, share, state);
             }
             else if (subcommand is Transaction2SetFileInformationRequest)
             {
-                subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2SetFileInformationRequest)subcommand, fileSystemShare, state);
+                subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2SetFileInformationRequest)subcommand, share, state);
             }
             else if (subcommand is Transaction2CreateDirectoryRequest)
             {