Browse Source

Client: ISMBClient interface added

Tal Aloni 7 years ago
parent
commit
873720d6ff

+ 29 - 0
SMBLibrary/Client/ISMBClient.cs

@@ -0,0 +1,29 @@
+/* Copyright (C) 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;
+
+namespace SMBLibrary.Client
+{
+    public interface ISMBClient
+    {
+        bool Connect(IPAddress serverAddress, SMBTransportType transport);
+
+        void Disconnect();
+
+        NTStatus Login(string domainName, string userName, string password);
+
+        NTStatus Login(string domainName, string userName, string password, AuthenticationMethod authenticationMethod);
+
+        NTStatus Logoff();
+
+        List<string> ListShares(out NTStatus status);
+
+        ISMBFileStore TreeConnect(string shareName, out NTStatus status);
+    }
+}

+ 9 - 4
SMBLibrary/Client/SMB1Client.cs

@@ -18,7 +18,7 @@ using Utilities;
 
 namespace SMBLibrary.Client
 {
-    public class SMB1Client
+    public class SMB1Client : ISMBClient
     {
         public const int NetBiosOverTCPPort = 139;
         public const int DirectTCPPort = 445;
@@ -81,8 +81,8 @@ namespace SMBLibrary.Client
                 ConnectionState state = new ConnectionState();
                 NBTConnectionReceiveBuffer buffer = state.ReceiveBuffer;
                 m_currentAsyncResult = m_clientSocket.BeginReceive(buffer.Buffer, buffer.WriteOffset, buffer.AvailableLength, SocketFlags.None, new AsyncCallback(OnClientSocketReceive), state);
-                bool supportsCIFS = NegotiateNTLanManagerDialect(m_forceExtendedSecurity);
-                if (!supportsCIFS)
+                bool supportsDialect = NegotiateDialect(m_forceExtendedSecurity);
+                if (!supportsDialect)
                 {
                     m_clientSocket.Close();
                 }
@@ -103,7 +103,7 @@ namespace SMBLibrary.Client
             }
         }
 
-        private bool NegotiateNTLanManagerDialect(bool forceExtendedSecurity)
+        private bool NegotiateDialect(bool forceExtendedSecurity)
         {
             if (m_transport == SMBTransportType.NetBiosOverTCP)
             {
@@ -266,6 +266,11 @@ namespace SMBLibrary.Client
             return shares;
         }
 
+        public ISMBFileStore TreeConnect(string shareName, out NTStatus status)
+        {
+            return TreeConnect(shareName, ServiceName.AnyType, out status);
+        }
+
         public SMB1FileStore TreeConnect(string shareName, ServiceName serviceName, out NTStatus status)
         {
             if (!m_isConnected || !m_isLoggedIn)

+ 5 - 5
SMBLibrary/Client/SMB2Client.cs

@@ -18,7 +18,7 @@ using Utilities;
 
 namespace SMBLibrary.Client
 {
-    public class SMB2Client
+    public class SMB2Client : ISMBClient
     {
         public const int NetBiosOverTCPPort = 139;
         public const int DirectTCPPort = 445;
@@ -74,8 +74,8 @@ namespace SMBLibrary.Client
                 ConnectionState state = new ConnectionState();
                 NBTConnectionReceiveBuffer buffer = state.ReceiveBuffer;
                 m_currentAsyncResult = m_clientSocket.BeginReceive(buffer.Buffer, buffer.WriteOffset, buffer.AvailableLength, SocketFlags.None, new AsyncCallback(OnClientSocketReceive), state);
-                bool supportsSMB2 = NegotiateDialect();
-                if (!supportsSMB2)
+                bool supportsDialect = NegotiateDialect();
+                if (!supportsDialect)
                 {
                     m_clientSocket.Close();
                 }
@@ -181,7 +181,7 @@ namespace SMBLibrary.Client
                 throw new InvalidOperationException("A login session must be successfully established before retrieving share list");
             }
 
-            SMB2FileStore namedPipeShare = TreeConnect("IPC$", out status);
+            ISMBFileStore namedPipeShare = TreeConnect("IPC$", out status);
             if (namedPipeShare == null)
             {
                 return null;
@@ -192,7 +192,7 @@ namespace SMBLibrary.Client
             return shares;
         }
 
-        public SMB2FileStore TreeConnect(string shareName, out NTStatus status)
+        public ISMBFileStore TreeConnect(string shareName, out NTStatus status)
         {
             if (!m_isConnected || !m_isLoggedIn)
             {

+ 1 - 0
SMBLibrary/SMBLibrary.csproj

@@ -58,6 +58,7 @@
     <Compile Include="Client\Enums\AuthenticationMethod.cs" />
     <Compile Include="Client\Helpers\NTLMAuthenticationHelper.cs" />
     <Compile Include="Client\Helpers\ServerServiceHelper.cs" />
+    <Compile Include="Client\ISMBClient.cs" />
     <Compile Include="Client\ISMBFileStore.cs" />
     <Compile Include="Client\SMB1Client.cs" />
     <Compile Include="Client\SMB1FileStore.cs" />