Skip to content

added NTLM support #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Identity.Client" Version="$(MicrosoftIdentityClientVersion)" />
<PackageReference Include="SharpCifs.Std" Version="0.2.13" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpCifs.Std" Version="0.2.13" />
<PackageReference Condition="$(TargetGroup) == 'netstandard' and '$(TargetsWindows)' == 'true' and '$(IsUAPAssembly)' != 'true'" Include="Microsoft.Win32.Registry" Version="$(MicrosoftWin32RegistryVersion)" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerVersion)" />
<PackageReference Include="System.Security.Permissions" Version="$(SystemSecurityPermissionsVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8514,29 +8514,56 @@ private void SSPIData(byte[] receivedBuff, uint receivedLength, ref byte[] sendB

private void SNISSPIData(byte[] receivedBuff, uint receivedLength, ref byte[] sendBuff, ref uint sendLength)
{
if (TdsParserStateObjectFactory.UseManagedSNI)
if (_connHandler.ConnectionOptions.IntegratedSecurity
&& !string.IsNullOrEmpty(_connHandler.ConnectionOptions.UserID) && !string.IsNullOrEmpty(_connHandler.ConnectionOptions.Password))
{
try
if (receivedBuff == null) // first message
{
_physicalStateObj.GenerateSspiClientContext(receivedBuff, receivedLength, ref sendBuff, ref sendLength, _sniSpnBuffer);
var type1Message = new SharpCifs.Ntlmssp.Type1Message(); //[review] FLAGS
type1Message.SetSuppliedWorkstation(_connHandler.ConnectionOptions.ObtainWorkstationId());
//type1Message.SetSuppliedDomain //TODO creo que no necesito
sendBuff = type1Message.ToByteArray();
sendLength = (uint)sendBuff.Length;
}
catch (Exception e)
else // challenged
{
SSPIError(e.Message + Environment.NewLine + e.StackTrace, TdsEnums.GEN_CLIENT_CONTEXT);
var type2MessageBytes = new byte[receivedLength];
Array.Copy(receivedBuff, type2MessageBytes, receivedLength);
var type2Message = new SharpCifs.Ntlmssp.Type2Message(receivedBuff);
var userId = _connHandler.ConnectionOptions.UserID;
var domain = userId.Split('\\')[0];
var user = userId.Split('\\')[1];
var type3Message = new SharpCifs.Ntlmssp.Type3Message(type2Message, _connHandler.ConnectionOptions.Password, domain, user, _connHandler.ConnectionOptions.ObtainWorkstationId(), type2Message.GetFlags());
sendBuff = type3Message.ToByteArray();
sendLength = (uint)sendBuff.Length;
}
}
else
else // the following block is the original.
{
if (receivedBuff == null)
if (TdsParserStateObjectFactory.UseManagedSNI)
{
// if we do not have SSPI data coming from server, send over 0's for pointer and length
receivedLength = 0;
try
{
_physicalStateObj.GenerateSspiClientContext(receivedBuff, receivedLength, ref sendBuff, ref sendLength, _sniSpnBuffer);
}
catch (Exception e)
{
SSPIError(e.Message + Environment.NewLine + e.StackTrace, TdsEnums.GEN_CLIENT_CONTEXT);
}
}

// we need to respond to the server's message with SSPI data
if (0 != _physicalStateObj.GenerateSspiClientContext(receivedBuff, receivedLength, ref sendBuff, ref sendLength, _sniSpnBuffer))
else
{
SSPIError(SQLMessage.SSPIGenerateError(), TdsEnums.GEN_CLIENT_CONTEXT);
if (receivedBuff == null)
{
// if we do not have SSPI data coming from server, send over 0's for pointer and length
receivedLength = 0;
}

// we need to respond to the server's message with SSPI data
if (0 != _physicalStateObj.GenerateSspiClientContext(receivedBuff, receivedLength, ref sendBuff, ref sendLength, _sniSpnBuffer))
{
SSPIError(SQLMessage.SSPIGenerateError(), TdsEnums.GEN_CLIENT_CONTEXT);
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="dotnet-public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
<add key="dotnet-eng" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json" />
</packageSources>
</configuration>
2 changes: 1 addition & 1 deletion tools/props/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- Should only be changed in future when a non-backwards compatible driver is released. -->
<!-- Future Assembly Version values shall be Major.Minor.0.0; e.g. 4.0.0.0 -->
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<NugetPackageVersion Condition="'$(NugetPackageVersion)' == ''">5.2.0-dev</NugetPackageVersion>
<NugetPackageVersion Condition="'$(NugetPackageVersion)' == ''">1.1.18</NugetPackageVersion>
<Version>$(NugetPackageVersion)</Version>
</PropertyGroup>
<PropertyGroup>
Expand Down
141 changes: 141 additions & 0 deletions tools/specs/Reveal.Data.SqlClient.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata minClientVersion="2.12">
<id>Reveal.Data.SqlClient</id>
<version>1.0.0</version>
<title>Reveal.Data.SqlClient</title>
<authors>Infragstics</authors>
<requireLicenseAcceptance>true</requireLicenseAcceptance>
<license type="expression">MIT</license>
<projectUrl>https://github.com/RevealBi/SqlClient</projectUrl>
<icon>dotnet.png</icon>
<repository type="git" url="https://github.com/RevealBi/SqlClient" />
<description>Patch over Microsoft.Data.SqlClient to get NTLM support on linux</description>
<tags>sqlclient reveal.data.sqlclient</tags>
<dependencies>
<group targetFramework="netcoreapp3.1">
<dependency id="Microsoft.Data.SqlClient.SNI.runtime" version="5.0.0-preview2.22084.1" exclude="Compile" />
<dependency id="Azure.Identity" version="1.6.0" />
<dependency id="Microsoft.Identity.Client" version="4.43.2" exclude="Compile"/>
<dependency id="Microsoft.IdentityModel.Protocols.OpenIdConnect" version="6.8.0" />
<dependency id="Microsoft.IdentityModel.JsonWebTokens" version="6.8.0" />
<dependency id="Microsoft.SqlServer.Server" version="1.0.0"/>
<dependency id="Microsoft.Win32.Registry" version="5.0.0" exclude="Compile" />
<dependency id="System.Buffers" version="4.5.1" />
<dependency id="System.Configuration.ConfigurationManager" version="5.0.0" exclude="Compile" />
<dependency id="System.Diagnostics.DiagnosticSource" version="5.0.0" exclude="Compile" />
<dependency id="System.IO" version="4.3.0" />
<dependency id="System.Runtime.Caching" version="5.0.0" exclude="Compile" />
<dependency id="System.Text.Encoding.CodePages" version="5.0.0" exclude="Compile" />
<dependency id="System.Text.Encodings.Web" version="4.7.2" />
<dependency id="System.Resources.ResourceManager" version="4.3.0" />
<dependency id="System.Security.Cryptography.Cng" version="5.0.0" />
<dependency id="System.Security.Principal.Windows" version="5.0.0" exclude="Compile" />
</group>
<group targetFramework="netstandard2.0">
<dependency id="Microsoft.Data.SqlClient.SNI.runtime" version="5.0.0-preview2.22084.1" exclude="Compile" />
<dependency id="Azure.Identity" version="1.6.0" />
<dependency id="Microsoft.Identity.Client" version="4.43.2" exclude="Compile"/>
<dependency id="Microsoft.IdentityModel.Protocols.OpenIdConnect" version="6.8.0" />
<dependency id="Microsoft.IdentityModel.JsonWebTokens" version="6.8.0" />
<dependency id="Microsoft.SqlServer.Server" version="1.0.0"/>
<dependency id="Microsoft.Win32.Registry" version="5.0.0" exclude="Compile" />
<dependency id="System.Buffers" version="4.5.1" />
<dependency id="System.Configuration.ConfigurationManager" version="5.0.0" exclude="Compile" />
<dependency id="System.IO" version="4.3.0" />
<dependency id="System.Runtime.Caching" version="5.0.0" exclude="Compile" />
<dependency id="System.Text.Encoding.CodePages" version="5.0.0" exclude="Compile" />
<dependency id="System.Text.Encodings.Web" version="4.7.2" />
<dependency id="System.Runtime.Loader" version="4.3.0" />
<dependency id="System.Resources.ResourceManager" version="4.3.0" />
<dependency id="System.Security.Cryptography.Cng" version="5.0.0" />
<dependency id="System.Security.Principal.Windows" version="5.0.0" exclude="Compile" />
</group>
<group targetFramework="netstandard2.1">
<dependency id="Microsoft.Data.SqlClient.SNI.runtime" version="5.0.0-preview2.22084.1" exclude="Compile" />
<dependency id="Azure.Identity" version="1.6.0" />
<dependency id="Microsoft.Identity.Client" version="4.43.2" exclude="Compile"/>
<dependency id="Microsoft.IdentityModel.Protocols.OpenIdConnect" version="6.8.0" />
<dependency id="Microsoft.IdentityModel.JsonWebTokens" version="6.8.0" />
<dependency id="Microsoft.SqlServer.Server" version="1.0.0"/>
<dependency id="Microsoft.Win32.Registry" version="5.0.0" exclude="Compile" />
<dependency id="System.Buffers" version="4.5.1" />
<dependency id="System.Configuration.ConfigurationManager" version="5.0.0" exclude="Compile" />
<dependency id="System.IO" version="4.3.0" />
<dependency id="System.Runtime.Caching" version="5.0.0" exclude="Compile" />
<dependency id="System.Text.Encoding.CodePages" version="5.0.0" exclude="Compile" />
<dependency id="System.Text.Encodings.Web" version="4.7.2" />
<dependency id="System.Runtime.Loader" version="4.3.0" />
<dependency id="System.Resources.ResourceManager" version="4.3.0" />
<dependency id="System.Security.Cryptography.Cng" version="5.0.0" />
<dependency id="System.Security.Principal.Windows" version="5.0.0" exclude="Compile" />
</group>
</dependencies>
<references>
<group targetFramework="netcoreapp3.1">
<reference file="Microsoft.Data.SqlClient.dll" />
<reference file="Microsoft.Data.SqlClient.pdb" />
<reference file="Microsoft.Data.SqlClient.xml" />
</group>
<group targetFramework="netstandard2.0">
<reference file="Microsoft.Data.SqlClient.dll" />
<reference file="Microsoft.Data.SqlClient.pdb" />
<reference file="Microsoft.Data.SqlClient.xml" />
</group>
<group targetFramework="netstandard2.1">
<reference file="Microsoft.Data.SqlClient.dll" />
<reference file="Microsoft.Data.SqlClient.pdb" />
<reference file="Microsoft.Data.SqlClient.xml" />
</group>
</references>
</metadata>
<files>
<file src="..\icons\dotnet.png" target="" />

<!-- ref NetCore -->
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$\Microsoft.Data.SqlClient\ref\netcoreapp3.1\Microsoft.Data.SqlClient.dll" target="ref\netcoreapp3.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$\Microsoft.Data.SqlClient\ref\netcoreapp3.1\Microsoft.Data.SqlClient.pdb" target="ref\netcoreapp3.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$\Microsoft.Data.SqlClient\ref\netcoreapp3.1\Microsoft.Data.SqlClient.xml" target="ref\netcoreapp3.1\" exclude="" />

<!-- ref NetStandard -->
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$\Microsoft.Data.SqlClient\ref\netstandard2.0\Microsoft.Data.SqlClient.dll" target="ref\netstandard2.0\" exclude="" />
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$\Microsoft.Data.SqlClient\ref\netstandard2.0\Microsoft.Data.SqlClient.pdb" target="ref\netstandard2.0\" exclude="" />
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$\Microsoft.Data.SqlClient\ref\netstandard2.0\Microsoft.Data.SqlClient.xml" target="ref\netstandard2.0\" exclude="" />

<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$\Microsoft.Data.SqlClient\ref\netstandard2.1\Microsoft.Data.SqlClient.dll" target="ref\netstandard2.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$\Microsoft.Data.SqlClient\ref\netstandard2.1\Microsoft.Data.SqlClient.pdb" target="ref\netstandard2.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$\Microsoft.Data.SqlClient\ref\netstandard2.1\Microsoft.Data.SqlClient.xml" target="ref\netstandard2.1\" exclude="" />

<!-- lib NetCore -->
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netcoreapp3.1\Microsoft.Data.SqlClient.dll" target="lib\netcoreapp3.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netcoreapp3.1\Microsoft.Data.SqlClient.pdb" target="lib\netcoreapp3.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\Windows_NT\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netcoreapp3.1\Microsoft.Data.SqlClient.xml" target="lib\netcoreapp3.1\" exclude="" />

<!-- lib NetStandard -->
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.0\Microsoft.Data.SqlClient.dll" target="lib\netstandard2.0\" exclude="" />
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.0\Microsoft.Data.SqlClient.pdb" target="lib\netstandard2.0\" exclude="" />
<file src="..\..\artifacts\Project\bin\Windows_NT\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.0\Microsoft.Data.SqlClient.xml" target="lib\netstandard2.0\" exclude="" />

<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.1\Microsoft.Data.SqlClient.dll" target="lib\netstandard2.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\AnyOS\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.1\Microsoft.Data.SqlClient.pdb" target="lib\netstandard2.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\Windows_NT\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.1\Microsoft.Data.SqlClient.xml" target="lib\netstandard2.1\" exclude="" />

<!-- runtimes NetCore -->
<file src="..\..\artifacts\Project\bin\Windows_NT\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netcoreapp3.1\Microsoft.Data.SqlClient.dll" target="runtimes\win\lib\netcoreapp3.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\Windows_NT\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netcoreapp3.1\Microsoft.Data.SqlClient.pdb" target="runtimes\win\lib\netcoreapp3.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\Unix\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netcoreapp3.1\Microsoft.Data.SqlClient.dll" target="runtimes\unix\lib\netcoreapp3.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\Unix\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netcoreapp3.1\Microsoft.Data.SqlClient.pdb" target="runtimes\unix\lib\netcoreapp3.1\" exclude="" />

<!-- runtimes NetStandard -->
<file src="..\..\artifacts\Project\bin\Windows_NT\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.0\Microsoft.Data.SqlClient.dll" target="runtimes\win\lib\netstandard2.0\" exclude="" />
<file src="..\..\artifacts\Project\bin\Windows_NT\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.0\Microsoft.Data.SqlClient.pdb" target="runtimes\win\lib\netstandard2.0\" exclude="" />
<file src="..\..\artifacts\Project\bin\Unix\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.0\Microsoft.Data.SqlClient.dll" target="runtimes\unix\lib\netstandard2.0\" exclude="" />
<file src="..\..\artifacts\Project\bin\Unix\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.0\Microsoft.Data.SqlClient.pdb" target="runtimes\unix\lib\netstandard2.0\" exclude="" />

<file src="..\..\artifacts\Project\bin\Windows_NT\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.1\Microsoft.Data.SqlClient.dll" target="runtimes\win\lib\netstandard2.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\Windows_NT\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.1\Microsoft.Data.SqlClient.pdb" target="runtimes\win\lib\netstandard2.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\Unix\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.1\Microsoft.Data.SqlClient.dll" target="runtimes\unix\lib\netstandard2.1\" exclude="" />
<file src="..\..\artifacts\Project\bin\Unix\$Configuration$.AnyCPU\Microsoft.Data.SqlClient\netcore\netstandard2.1\Microsoft.Data.SqlClient.pdb" target="runtimes\unix\lib\netstandard2.1\" exclude="" />

</files>
</package>
2 changes: 1 addition & 1 deletion tools/targets/GenerateNugetPackage.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Message Text="Setting NugetPackageVersion to $(NugetPackageVersion)" />
<Exec Command="powershell.exe -NonInteractive -executionpolicy Unrestricted ^
-command &quot;&amp;$(ToolsDir)scripts\downloadLatestNuget.ps1 -nugetDestPath '$(NuGetRoot)'&quot;" />
<Exec Command="$(NuGetCmd) pack $(ToolsDir)specs\Microsoft.Data.SqlClient.nuspec -Version $(NugetPackageVersion) -OutputDirectory $(PackagesDir) -properties Configuration=$(Configuration)" />
<Exec Command="$(NuGetCmd) pack $(ToolsDir)specs\Reveal.Data.SqlClient.nuspec -Version $(NugetPackageVersion) -OutputDirectory $(PackagesDir) -properties Configuration=$(Configuration)" />
</Target>
<Target Name="GenerateSqlServerPackage" Condition="'$(GenerateNuget)' == 'true'">
<PropertyGroup>
Expand Down