Improved NTLM authentication API

This commit is contained in:
Tal Aloni 2017-02-17 19:01:58 +02:00
parent 05f49c3128
commit 217451d18f
23 changed files with 602 additions and 526 deletions

View file

@ -70,6 +70,8 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="User.cs" />
<Compile Include="UserCollection.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SMBLibrary\SMBLibrary.csproj">

View file

@ -17,8 +17,9 @@ using System.Text;
using System.Windows.Forms;
using System.Xml;
using SMBLibrary;
using SMBLibrary.Authentication.NTLM;
using SMBLibrary.Server;
using SMBLibrary.Server.Win32;
using SMBLibrary.Win32.Security;
using Utilities;
namespace SMBServer
@ -61,10 +62,10 @@ namespace SMBServer
transportType = SMBTransportType.DirectTCPTransport;
}
INTLMAuthenticationProvider provider;
NTLMAuthenticationProviderBase provider;
if (chkIntegratedWindowsAuthentication.Checked)
{
provider = new Win32UserCollection();
provider = new IntegratedNTLMAuthenticationProvider();
}
else
@ -80,7 +81,7 @@ namespace SMBServer
return;
}
provider = new IndependentUserCollection(users);
provider = new IndependentNTLMAuthenticationProvider(users.GetUserPassword);
}

18
SMBServer/User.cs Normal file
View file

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SMBLibrary.Server
{
public class User
{
public string AccountName;
public string Password;
public User(string accountName, string password)
{
AccountName = accountName;
Password = password;
}
}
}

View file

@ -0,0 +1,52 @@
/* Copyright (C) 2014 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.Text;
namespace SMBLibrary.Server
{
public class UserCollection : List<User>
{
public void Add(string accountName, string password)
{
Add(new User(accountName, password));
}
public int IndexOf(string accountName)
{
for (int index = 0; index < this.Count; index++)
{
if (string.Equals(this[index].AccountName, accountName, StringComparison.InvariantCultureIgnoreCase))
{
return index;
}
}
return -1;
}
public string GetUserPassword(string accountName)
{
int index = IndexOf(accountName);
if (index >= 0)
{
return this[index].Password;
}
return null;
}
public List<string> ListUsers()
{
List<string> result = new List<string>();
foreach (User user in this)
{
result.Add(user.AccountName);
}
return result;
}
}
}