Browse Source

Added a new ConnectionState class, SMB1 specific functionality will reside in SMB1ConnectionState

Tal Aloni 8 years ago
parent
commit
08717b5358

+ 1 - 0
SMBLibrary/SMBLibrary.csproj

@@ -103,6 +103,7 @@
     <Compile Include="RPC\Structures\ResultElement.cs" />
     <Compile Include="RPC\Structures\ResultList.cs" />
     <Compile Include="RPC\Structures\SyntaxID.cs" />
+    <Compile Include="Server\ConnectionState\ConnectionState.cs" />
     <Compile Include="Server\ConnectionState\OpenedFileObject.cs" />
     <Compile Include="Server\ConnectionState\ProcessStateObject.cs" />
     <Compile Include="Server\ConnectionState\SMB1ConnectionState.cs" />

+ 31 - 0
SMBLibrary/Server/ConnectionState/ConnectionState.cs

@@ -0,0 +1,31 @@
+/* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
+ * 
+ * You can redistribute this program and/or modify it under the terms of
+ * the GNU Lesser Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ */
+using System;
+using System.Collections.Generic;
+using System.Net.Sockets;
+using SMBLibrary.NetBios;
+using Utilities;
+
+namespace SMBLibrary.Server
+{
+    public class ConnectionState
+    {
+        public Socket ClientSocket;
+        public NBTConnectionReceiveBuffer ReceiveBuffer;
+
+        public ConnectionState()
+        {
+            ReceiveBuffer = new NBTConnectionReceiveBuffer();
+        }
+
+        public ConnectionState(ConnectionState state)
+        {
+            ClientSocket = state.ClientSocket;
+            ReceiveBuffer = state.ReceiveBuffer;
+        }
+    }
+}

+ 6 - 7
SMBLibrary/Server/ConnectionState/SMB1ConnectionState.cs

@@ -7,17 +7,12 @@
 using System;
 using System.Collections.Generic;
 using System.IO;
-using System.Net.Sockets;
-using SMBLibrary.NetBios;
 using Utilities;
 
 namespace SMBLibrary.Server
 {
-    public class SMB1ConnectionState
+    public class SMB1ConnectionState : ConnectionState
     {
-        public Socket ClientSocket = null;
-        public NBTConnectionReceiveBuffer ReceiveBuffer = new NBTConnectionReceiveBuffer();
-
         public int MaxBufferSize;
         public bool LargeRead;
         public bool LargeWrite;
@@ -35,13 +30,17 @@ namespace SMBLibrary.Server
         private ushort m_nextFID = 1;
         // Key is FID
         private Dictionary<ushort, byte[]> m_namedPipeResponse = new Dictionary<ushort, byte[]>();
-        
+
         // Key is PID
         public Dictionary<uint, ProcessStateObject> ProcessStateList = new Dictionary<uint, ProcessStateObject>();
         public const int MaxSearches = 2048; // Windows servers initialize Server.MaxSearches to 2048.
         public Dictionary<ushort, List<FileSystemEntry>> OpenSearches = new Dictionary<ushort, List<FileSystemEntry>>();
         private ushort m_nextSearchHandle = 1;
 
+        public SMB1ConnectionState(ConnectionState state) : base(state)
+        {
+        }
+
         /// <summary>
         /// An open UID MUST be unique within an SMB connection.
         /// The value of 0xFFFE SHOULD NOT be used as a valid UID. All other possible values for a UID, excluding zero (0x0000), are valid.

+ 1 - 1
SMBLibrary/Server/SMBServer.cs

@@ -92,7 +92,7 @@ namespace SMBLibrary.Server
                 return;
             }
 
-            SMB1ConnectionState state = new SMB1ConnectionState();
+            SMB1ConnectionState state = new SMB1ConnectionState(new ConnectionState());
             // Disable the Nagle Algorithm for this tcp socket:
             clientSocket.NoDelay = true;
             state.ClientSocket = clientSocket;