Skip to content
Merged
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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,9 @@
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\IoType.cs">
<Link>Interop\Windows\Sni\IoType.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\ISniNativeMethods.cs">
<Link>Interop\Windows\Sni\ISniNativeMethods.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\Prefix.cs">
<Link>Interop\Windows\Sni\Prefix.cs</Link>
</Compile>
Expand All @@ -752,6 +755,12 @@
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\SniError.cs">
<Link>Interop\Windows\Sni\SniError.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeMethods.netcore.cs">
<Link>Interop\Windows\Sni\SniNativeMethods.netcore.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeWrapper.cs">
<Link>Interop\Windows\Sni\SniNativeWrapper.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\TransparentNetworkResolutionMode.cs">
<Link>Interop\Windows\Sni\TransparentNetworkResolutionMode.cs</Link>
</Compile>
Expand Down Expand Up @@ -788,8 +797,7 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlTypes\SqlFileStream.Windows.cs">
<Link>Microsoft\Data\SqlTypes\SqlFileStream.Windows.cs</Link>
</Compile>

<Compile Include="Interop\SNINativeMethodWrapper.Windows.cs" />

<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.Common.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\PacketHandle.Windows.cs" />
Expand All @@ -808,8 +816,7 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Unix.cs">
<Link>Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Unix.cs</Link>
</Compile>

<Compile Include="Interop\SNINativeMethodWrapper.Unix.cs" />

<Compile Include="Microsoft\Data\Sql\SqlDataSourceEnumerator.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\PacketHandle.Unix.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
// See the LICENSE file in the project root for more information.

using System;
using Interop.Windows.Kernel32;
using Microsoft.Data.SqlClient;
using Interop.Windows.Sni;

namespace Microsoft.Data
{
internal static partial class LocalDBAPI
{
private static IntPtr LoadProcAddress() => SafeNativeMethods.GetProcAddress(UserInstanceDLLHandle, "LocalDBFormatMessage");
private static IntPtr LoadProcAddress() =>
Kernel32.GetProcAddress(UserInstanceDLLHandle, "LocalDBFormatMessage");

private static IntPtr UserInstanceDLLHandle
{
Expand All @@ -22,15 +24,15 @@ private static IntPtr UserInstanceDLLHandle
{
if (s_userInstanceDLLHandle == IntPtr.Zero)
{
SNINativeMethodWrapper.SNIQueryInfo(QueryType.SNI_QUERY_LOCALDB_HMODULE, ref s_userInstanceDLLHandle);
SniNativeWrapper.SNIQueryInfo(QueryType.SNI_QUERY_LOCALDB_HMODULE, ref s_userInstanceDLLHandle);
if (s_userInstanceDLLHandle != IntPtr.Zero)
{
SqlClientEventSource.Log.TryTraceEvent("LocalDBAPI.UserInstanceDLLHandle | LocalDB - handle obtained");
}
else
{
SNINativeMethodWrapper.SNIGetLastError(out SniError sniError);
throw CreateLocalDBException(StringsHelper.GetString("LocalDB_FailedGetDLLHandle"), sniError.sniError);
SniNativeWrapper.SNIGetLastError(out SniError sniError);
throw CreateLocalDBException(errorMessage: StringsHelper.GetString("LocalDB_FailedGetDLLHandle"), sniError: sniError.sniError);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private SNIErrorDetails GetSniErrorDetails()
}
else
{
SNINativeMethodWrapper.SNIGetLastError(out SniError sniError);
SniNativeWrapper.SNIGetLastError(out SniError sniError);
details.sniErrorNumber = sniError.sniError;
details.errorMessage = sniError.errorMessage;
details.nativeError = sniError.nativeError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ internal override void AssignPendingDNSInfo(string userProtocol, string DNSCache
if (string.IsNullOrEmpty(userProtocol))
{

result = SNINativeMethodWrapper.SniGetProviderNumber(Handle, ref providerNumber);
result = SniNativeWrapper.SniGetProviderNumber(Handle, ref providerNumber);
Debug.Assert(result == TdsEnums.SNI_SUCCESS, "Unexpected failure state upon calling SniGetProviderNumber");
_parser.isTcpProtocol = (providerNumber == Provider.TCP_PROV);
}
Expand All @@ -96,10 +96,10 @@ internal override void AssignPendingDNSInfo(string userProtocol, string DNSCache
// serverInfo.UserProtocol could be empty
if (_parser.isTcpProtocol)
{
result = SNINativeMethodWrapper.SniGetConnectionPort(Handle, ref portFromSNI);
result = SniNativeWrapper.SniGetConnectionPort(Handle, ref portFromSNI);
Debug.Assert(result == TdsEnums.SNI_SUCCESS, "Unexpected failure state upon calling SniGetConnectionPort");

result = SNINativeMethodWrapper.SniGetConnectionIPString(Handle, ref IPStringFromSNI);
result = SniNativeWrapper.SniGetConnectionIPString(Handle, ref IPStringFromSNI);
Debug.Assert(result == TdsEnums.SNI_SUCCESS, "Unexpected failure state upon calling SniGetConnectionIPString");

pendingDNSInfo = new SQLDNSInfo(DNSCacheKey, null, null, portFromSNI.ToString());
Expand Down Expand Up @@ -166,13 +166,13 @@ internal override void CreatePhysicalSNIHandle(
{
// Native SNI requires the Unicode encoding and any other encoding like UTF8 breaks the code.
byte[] srvSPN = Encoding.Unicode.GetBytes(serverSPN);
Trace.Assert(srvSPN.Length <= SNINativeMethodWrapper.SniMaxComposedSpnLength, "Length of the provided SPN exceeded the buffer size.");
Trace.Assert(srvSPN.Length <= SniNativeWrapper.SniMaxComposedSpnLength, "Length of the provided SPN exceeded the buffer size.");
spnBuffer[0] = srvSPN;
SqlClientEventSource.Log.TryTraceEvent("<{0}.{1}|SEC> Server SPN `{2}` from the connection string is used.", nameof(TdsParserStateObjectNative), nameof(CreatePhysicalSNIHandle), serverSPN);
}
else
{
spnBuffer[0] = new byte[SNINativeMethodWrapper.SniMaxComposedSpnLength];
spnBuffer[0] = new byte[SniNativeWrapper.SniMaxComposedSpnLength];
}
}

Expand All @@ -187,7 +187,7 @@ internal override void CreatePhysicalSNIHandle(
protected override uint SNIPacketGetData(PacketHandle packet, byte[] _inBuff, ref uint dataSize)
{
Debug.Assert(packet.Type == PacketHandle.NativePointerType, "unexpected packet type when requiring NativePointer");
return SNINativeMethodWrapper.SNIPacketGetData(packet.NativePointer, _inBuff, ref dataSize);
return SniNativeWrapper.SNIPacketGetData(packet.NativePointer, _inBuff, ref dataSize);
}

protected override bool CheckPacket(PacketHandle packet, TaskCompletionSource<object> source)
Expand Down Expand Up @@ -267,7 +267,7 @@ internal override PacketHandle ReadSyncOverAsync(int timeoutRemaining, out uint
throw ADP.ClosedConnectionError();
}
IntPtr readPacketPtr = IntPtr.Zero;
error = SNINativeMethodWrapper.SNIReadSyncOverAsync(handle, ref readPacketPtr, GetTimeoutRemaining());
error = SniNativeWrapper.SNIReadSyncOverAsync(handle, ref readPacketPtr, GetTimeoutRemaining());
return PacketHandle.FromNativePointer(readPacketPtr);
}

Expand All @@ -284,20 +284,20 @@ internal override bool IsPacketEmpty(PacketHandle readPacket)
internal override void ReleasePacket(PacketHandle syncReadPacket)
{
Debug.Assert(syncReadPacket.Type == PacketHandle.NativePointerType, "unexpected packet type when requiring NativePointer");
SNINativeMethodWrapper.SNIPacketRelease(syncReadPacket.NativePointer);
SniNativeWrapper.SNIPacketRelease(syncReadPacket.NativePointer);
}

internal override uint CheckConnection()
{
SNIHandle handle = Handle;
return handle == null ? TdsEnums.SNI_SUCCESS : SNINativeMethodWrapper.SNICheckConnection(handle);
return handle == null ? TdsEnums.SNI_SUCCESS : SniNativeWrapper.SNICheckConnection(handle);
}

internal override PacketHandle ReadAsync(SessionHandle handle, out uint error)
{
Debug.Assert(handle.Type == SessionHandle.NativeHandleType, "unexpected handle type when requiring NativePointer");
IntPtr readPacketPtr = IntPtr.Zero;
error = SNINativeMethodWrapper.SNIReadAsync(handle.NativeHandle, ref readPacketPtr);
error = SniNativeWrapper.SNIReadAsync(handle.NativeHandle, ref readPacketPtr);
return PacketHandle.FromNativePointer(readPacketPtr);
}

Expand All @@ -313,7 +313,7 @@ internal override PacketHandle CreateAndSetAttentionPacket()
internal override uint WritePacket(PacketHandle packet, bool sync)
{
Debug.Assert(packet.Type == PacketHandle.NativePacketType, "unexpected packet type when requiring NativePacket");
return SNINativeMethodWrapper.SNIWritePacket(Handle, packet.NativePacket, sync);
return SniNativeWrapper.SNIWritePacket(Handle, packet.NativePacket, sync);
}

internal override PacketHandle AddPacketToPendingList(PacketHandle packetToAdd)
Expand Down Expand Up @@ -346,7 +346,7 @@ internal override PacketHandle GetResetWritePacket(int dataSize)
{
if (_sniPacket != null)
{
SNINativeMethodWrapper.SNIPacketReset(Handle, IoType.WRITE, _sniPacket, ConsumerNumber.SNI_Consumer_SNI);
SniNativeWrapper.SNIPacketReset(Handle, IoType.WRITE, _sniPacket, ConsumerNumber.SNI_Consumer_SNI);
}
else
{
Expand Down Expand Up @@ -375,17 +375,17 @@ internal override void ClearAllWritePackets()
internal override void SetPacketData(PacketHandle packet, byte[] buffer, int bytesUsed)
{
Debug.Assert(packet.Type == PacketHandle.NativePacketType, "unexpected packet type when requiring NativePacket");
SNINativeMethodWrapper.SNIPacketSetData(packet.NativePacket, buffer, bytesUsed);
SniNativeWrapper.SNIPacketSetData(packet.NativePacket, buffer, bytesUsed);
}

internal override uint SniGetConnectionId(ref Guid clientConnectionId)
=> SNINativeMethodWrapper.SniGetConnectionId(Handle, ref clientConnectionId);
=> SniNativeWrapper.SniGetConnectionId(Handle, ref clientConnectionId);

internal override uint DisableSsl()
=> SNINativeMethodWrapper.SNIRemoveProvider(Handle, Provider.SSL_PROV);
=> SniNativeWrapper.SNIRemoveProvider(Handle, Provider.SSL_PROV);

internal override uint EnableMars(ref uint info)
=> SNINativeMethodWrapper.SNIAddProvider(Handle, Provider.SMUX_PROV, ref info);
=> SniNativeWrapper.SNIAddProvider(Handle, Provider.SMUX_PROV, ref info);

internal override uint EnableSsl(ref uint info, bool tlsFirst, string serverCertificateFilename)
{
Expand All @@ -395,15 +395,15 @@ internal override uint EnableSsl(ref uint info, bool tlsFirst, string serverCert
authInfo.serverCertFileName = serverCertificateFilename;

// Add SSL (Encryption) SNI provider.
return SNINativeMethodWrapper.SNIAddProvider(Handle, Provider.SSL_PROV, ref authInfo);
return SniNativeWrapper.SNIAddProvider(Handle, Provider.SSL_PROV, ref authInfo);
}

internal override uint SetConnectionBufferSize(ref uint unsignedPacketSize)
=> SNINativeMethodWrapper.SNISetInfo(Handle, QueryType.SNI_QUERY_CONN_BUFSIZE, ref unsignedPacketSize);
=> SniNativeWrapper.SNISetInfo(Handle, QueryType.SNI_QUERY_CONN_BUFSIZE, ref unsignedPacketSize);

internal override uint WaitForSSLHandShakeToComplete(out int protocolVersion)
{
uint returnValue = SNINativeMethodWrapper.SNIWaitForSSLHandshakeToComplete(Handle, GetTimeoutRemaining(), out uint nativeProtocolVersion);
uint returnValue = SniNativeWrapper.SNIWaitForSSLHandshakeToComplete(Handle, GetTimeoutRemaining(), out uint nativeProtocolVersion);
var nativeProtocol = (NativeProtocols)nativeProtocolVersion;

#pragma warning disable CA5398 // Avoid hardcoded SslProtocols values
Expand Down Expand Up @@ -472,7 +472,7 @@ public SNIPacket Take(SNIHandle sniHandle)
{
// Success - reset the packet
packet = _packets.Pop();
SNINativeMethodWrapper.SNIPacketReset(sniHandle, IoType.WRITE, packet, ConsumerNumber.SNI_Consumer_SNI);
SniNativeWrapper.SNIPacketReset(sniHandle, IoType.WRITE, packet, ConsumerNumber.SNI_Consumer_SNI);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\IoType.cs">
<Link>Interop\Windows\Sni\IoType.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\ISniNativeMethods.cs">
<Link>Interop\Windows\Sni\ISniNativeMethods.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\Prefix.cs">
<Link>Interop\Windows\Sni\Prefix.cs</Link>
</Compile>
Expand All @@ -193,6 +196,21 @@
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\SniError.cs">
<Link>Interop\Windows\Sni\SniError.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeMethodsArm64.netfx.cs">
<Link>Interop\Windows\Sni\SniNativeMethodsArm64.netfx.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeMethodsNotSupported.netfx.cs">
<Link>Interop\Windows\Sni\SniNativeMethodsNotSupported.netfx.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeMethodsX64.netfx.cs">
<Link>Interop\Windows\Sni\SniNativeMethodsX64.netfx.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeMethodsX86.netfx.cs">
<Link>Interop\Windows\Sni\SniNativeMethodsX86.netfx.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\SniNativeWrapper.cs">
<Link>Interop\Windows\Sni\SniNativeWrapper.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Sni\SqlDependencyProcessDispatcherStorage.netfx.cs">
<Link>Interop\Windows\Sni\SqlDependencyProcessDispatcherStorage.netfx.cs</Link>
</Compile>
Expand Down Expand Up @@ -808,10 +826,6 @@
<Compile Include="Microsoft\Data\Common\DbConnectionOptions.cs" />
<Compile Include="Microsoft\Data\Common\DbConnectionString.cs" />
<Compile Include="Microsoft\Data\Common\GreenMethods.cs" />
<Compile Include="Microsoft\Data\Interop\SNINativeManagedWrapperARM64.cs" />
<Compile Include="Microsoft\Data\Interop\SNINativeManagedWrapperX64.cs" />
<Compile Include="Microsoft\Data\Interop\SNINativeManagedWrapperX86.cs" />
<Compile Include="Microsoft\Data\Interop\SNINativeMethodWrapper.cs" />
<Compile Include="Microsoft\Data\SqlClient\assemblycache.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalDBConfig.cs" />
Expand Down Expand Up @@ -895,12 +909,12 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Azure.Identity" Version="$(AzureIdentityVersion)" />
<PackageReference Include="Microsoft.Bcl.Cryptography" Version="$(MicrosoftBclCryptographyVersion)" />
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="$(MicrosoftIdentityModelProtocolsOpenIdConnectVersion)" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="$(MicrosoftIdentityModelJsonWebTokensVersion)" />
<PackageReference Include="System.Buffers" Version="$(SystemBuffersVersion)" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="$(SystemSecurityCryptographyPkcsVersion)" />
<PackageReference Include="Microsoft.Bcl.Cryptography" Version="$(MicrosoftBclCryptographyVersion)" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />
</ItemGroup>
<Import Project="$(CommonSourceRoot)tools\targets\GenerateResourceStringsSource.targets" />
<Import Project="$(NetFxSource)tools\targets\GenerateThisAssemblyCs.targets" />
Expand Down
Loading
Loading