Skip to content
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 @@ -6,6 +6,7 @@
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.NativeSni;

namespace Interop.Windows.Sni
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.NativeSni;

namespace Interop.Windows.Sni
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.NativeSni;

namespace Interop.Windows.Sni
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
using System.Text;
using Microsoft.Data.Common;
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.NativeSni;

namespace Interop.Windows.Sni
{
internal sealed class SniNativeMethodsNotSupported : ISniNativeMethods
{
private readonly string _architecture;

public SniNativeMethodsNotSupported(Architecture architecture)
{
_architecture = architecture.ToString();
}

public uint SniAddProvider(SNIHandle pConn, Provider provider, ref AuthProviderInfo pInfo) =>
throw ADP.SNIPlatformNotSupported(_architecture);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.NativeSni;

namespace Interop.Windows.Sni
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.NativeSni;

namespace Interop.Windows.Sni
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Text;
using Interop.Windows.Sni;
using Microsoft.Data.Common;
using Microsoft.Data.SqlClient.NativeSni;
using Microsoft.Data.SqlClient.Utilities;

#if NETFRAMEWORK
Expand All @@ -20,13 +21,13 @@ namespace Microsoft.Data.SqlClient
internal static class SniNativeWrapper
{
#region Member Variables

private const int SniIpv6AddrStringBufferLength = 48;

#if NET
private const int SniOpenTimeOut = -1;
#endif

#if NETFRAMEWORK
private static readonly ISniNativeMethods s_nativeMethods = RuntimeInformation.ProcessArchitecture switch
{
Expand All @@ -38,11 +39,11 @@ internal static class SniNativeWrapper
#else
private static readonly SniNativeMethods s_nativeMethods = new SniNativeMethods();
#endif

private static int s_sniMaxComposedSpnLength = -1;

#endregion

internal static int SniMaxComposedSpnLength
{
get
Expand All @@ -56,10 +57,10 @@ internal static int SniMaxComposedSpnLength
}

#region Public Methods

internal static uint SniAddProvider(SNIHandle pConn, Provider provNum, ref AuthProviderInfo pInfo) =>
s_nativeMethods.SniAddProvider(pConn, provNum, ref pInfo);

#if NETFRAMEWORK
internal static uint SniAddProvider(SNIHandle pConn,
Provider providerEnum,
Expand All @@ -78,19 +79,19 @@ internal static uint SniAddProvider(SNIHandle pConn,
return ret;
}
#endif

internal static uint SniAddProvider(SNIHandle pConn, Provider provNum, ref uint pInfo) =>
s_nativeMethods.SniAddProvider(pConn, provNum, ref pInfo);

internal static uint SniCheckConnection(SNIHandle pConn) =>
s_nativeMethods.SniCheckConnection(pConn);

internal static uint SniClose(IntPtr pConn) =>
s_nativeMethods.SniClose(pConn);

internal static uint SniGetConnectionId(SNIHandle pConn, ref Guid connId) =>
s_nativeMethods.SniGetInfoWrapper(pConn, QueryType.SNI_QUERY_CONN_CONNID, out connId);

internal static uint SniGetConnectionIpString(SNIHandle pConn, ref string connIpStr)
{
StringBuilder addrBuffer = new StringBuilder(SniIpv6AddrStringBufferLength);
Expand All @@ -105,13 +106,13 @@ internal static uint SniGetConnectionIpString(SNIHandle pConn, ref string connIp

return ret;
}

internal static uint SniGetConnectionPort(SNIHandle pConn, ref ushort portNum) =>
s_nativeMethods.SniGetInfoWrapper(pConn, QueryType.SNI_QUERY_CONN_PEERPORT, out portNum);

internal static void SniGetLastError(out SniError pErrorStruct) =>
s_nativeMethods.SniGetLastError(out pErrorStruct);

internal static uint SniGetProviderNumber(SNIHandle pConn, ref Provider provNum) =>
s_nativeMethods.SniGetInfoWrapper(pConn, QueryType.SNI_QUERY_CONN_PROVIDERNUM, out provNum);

Expand All @@ -128,7 +129,7 @@ internal static uint SniIsTokenRestricted(IntPtr token, out bool isRestricted)

return result;
}

internal static uint SniOpenMarsSession(
ConsumerInfo consumerInfo,
SNIHandle parent,
Expand Down Expand Up @@ -169,12 +170,12 @@ internal static unsafe uint SniOpenSyncEx(
bool fSync,
int timeout,
bool fParallel,

#if NETFRAMEWORK
int transparentNetworkResolutionStateNo,
int totalTimeout,
#endif

SqlConnectionIPAddressPreference ipPreference,
SQLDNSInfo cachedDnsInfo,
string hostNameInCertificate)
Expand Down Expand Up @@ -285,39 +286,39 @@ internal static unsafe uint SniOpenSyncEx(

internal static void SniPacketAllocate(SafeHandle pConn, IoType ioType, ref IntPtr pPacket) =>
pPacket = s_nativeMethods.SniPacketAllocateWrapper(pConn, ioType);

internal static uint SniPacketGetData(IntPtr packet, byte[] readBuffer, ref uint dataSize) =>
s_nativeMethods.SniPacketGetDataWrapper(packet, readBuffer, (uint)readBuffer.Length, out dataSize);

internal static void SniPacketRelease(IntPtr pPacket) =>
s_nativeMethods.SniPacketRelease(pPacket);

internal static unsafe void SniPacketSetData(SNIPacket packet, byte[] data, int length)
{
fixed (byte* pData = data)
{
s_nativeMethods.SniPacketSetData(packet, pData, (uint)length);
}
}

internal static void SniPacketReset(SNIHandle pConn, IoType ioType, SNIPacket pPacket, ConsumerNumber consNum) =>
s_nativeMethods.SniPacketReset(pConn, ioType, pPacket, consNum);

internal static uint SniQueryInfo(QueryType qType, ref uint pbQInfo) =>
s_nativeMethods.SniQueryInfo(qType, ref pbQInfo);

internal static uint SniQueryInfo(QueryType qType, ref IntPtr pbQInfo) =>
s_nativeMethods.SniQueryInfo(qType, ref pbQInfo);

internal static uint SniReadAsync(SNIHandle pConn, ref IntPtr ppNewPacket) =>
s_nativeMethods.SniReadAsync(pConn, ref ppNewPacket);

internal static uint SniReadSyncOverAsync(SNIHandle pConn, ref IntPtr ppNewPacket, int timeout) =>
s_nativeMethods.SniReadSyncOverAsync(pConn, ref ppNewPacket, timeout);

internal static uint SniRemoveProvider(SNIHandle pConn, Provider provNum) =>
s_nativeMethods.SniRemoveProvider(pConn, provNum);

internal static unsafe uint SniSecGenClientContext(
SNIHandle pConnectionObject,
ReadOnlySpan<byte> inBuff,
Expand Down Expand Up @@ -353,22 +354,22 @@ internal static unsafe uint SniSecGenClientContext(
ObjectPools.BufferWriter.Return(serverWriter);
}
}

internal static uint SniSecInitPackage(ref uint pcbMaxToken) =>
s_nativeMethods.SniSecInitPackage(ref pcbMaxToken);

internal static void SniServerEnumClose(IntPtr packet) =>
s_nativeMethods.SniServerEnumClose(packet);

internal static IntPtr SniServerEnumOpen() =>
s_nativeMethods.SniServerEnumOpen();

internal static int SniServerEnumRead(IntPtr packet, char[] readBuffer, int bufferLength, out bool more) =>
s_nativeMethods.SniServerEnumRead(packet, readBuffer, bufferLength, out more);

internal static uint SniSetInfo(SNIHandle pConn, QueryType qType, ref uint pbQInfo) =>
s_nativeMethods.SniSetInfo(pConn, qType, ref pbQInfo);

internal static uint SniTerminate() =>
s_nativeMethods.SniTerminate();

Expand Down Expand Up @@ -430,7 +431,7 @@ internal static uint SniWritePacket(SNIHandle pConn, SNIPacket packet, bool sync
sync
? s_nativeMethods.SniWriteSyncOverAsync(pConn, packet)
: s_nativeMethods.SniWriteAsyncWrapper(pConn, packet);

#endregion

#region Private Methods
Expand All @@ -446,7 +447,7 @@ private static void MarshalConsumerInfo(ConsumerInfo consumerInfo, ref SniConsum
: IntPtr.Zero;
nativeConsumerInfo.ConsumerKey = consumerInfo.key;
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Microsoft.Win32;
using IsolationLevel = System.Data.IsolationLevel;
using Microsoft.Data.SqlClient.Internal;
using Microsoft.Data.SqlClient.Parser;

#if NETFRAMEWORK
using System.Reflection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.Data.SqlClient;
using static Microsoft.Data.Sql.SqlDataSourceEnumeratorUtil;
using Microsoft.Data.SqlClient.Internal;
using Microsoft.Data.SqlClient.Parser;

namespace Microsoft.Data.Sql
{
Expand Down Expand Up @@ -109,7 +110,7 @@ internal static DataTable ParseServerEnumString(string serverInstances)
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Number of received server instances are {2}",
nameof(SqlDataSourceEnumeratorNativeHelper), nameof(ParseServerEnumString), serverinstanceslist.Length);

// Every row comes in the format "serverName\instanceName;Clustered:[Yes|No];Version:.."
// Every row comes in the format "serverName\instanceName;Clustered:[Yes|No];Version:.."
// Every row is terminated by a null character.
// Process one row at a time
foreach (string instance in serverinstanceslist)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ComponentModel;
using System.Security.Cryptography;
using System.Text;
using Microsoft.Data.SqlClient.Parser.Login;

namespace Microsoft.Data.SqlClient
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

Expand Down Expand Up @@ -191,7 +191,7 @@ internal SqlTceCipherInfoEntry(int ordinal = 0)
}
}

/// <summary>
/// <summary>
/// Represents a table with various CEKs used in a resultset. Each entry corresponds to one (unique) CEK. The CEK
/// may have been encrypted using multiple master keys (giving us multiple CEK values). All these values form one single
/// entry in this table.
Expand Down Expand Up @@ -229,17 +229,6 @@ internal int Size
}
}

internal sealed partial class _SqlMetaDataSet
{
internal readonly SqlTceCipherInfoTable cekTable; // table of "column encryption keys" used for this metadataset

internal _SqlMetaDataSet(int count, SqlTceCipherInfoTable cipherTable)
: this(count)
{
cekTable = cipherTable;
}
}

/// <summary>
/// Represents Encryption related information of the cipher data.
/// </summary>
Expand Down Expand Up @@ -428,44 +417,6 @@ internal bool IsAlgorithmInitialized()
}
}

internal partial class SqlMetaDataPriv
{
internal bool isEncrypted; // TCE encrypted?
internal SqlMetaDataPriv baseTI; // for encrypted columns, represents the TYPE_INFO for plaintext value
internal SqlCipherMetadata cipherMD; // Cipher related metadata for encrypted columns.

/// <summary>
/// Is the algorithm handle for the cipher encryption initialized ?
/// </summary>
/// <returns></returns>
internal bool IsAlgorithmInitialized()
{
if (cipherMD != null)
{
return cipherMD.IsAlgorithmInitialized();
}

return false;
}

/// <summary>
/// Returns the normalization rule version byte.
/// </summary>
/// <returns></returns>
internal byte NormalizationRuleVersion
{
get
{
if (cipherMD != null)
{
return cipherMD.NormalizationRuleVersion;
}

return 0x00;
}
}
}

/// <summary>
/// Class encapsulating additional information when sending encrypted input parameters.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Data.SqlClient.Internal;
using System;
using System.Text;
using Microsoft.Data.SqlClient.Parser;

#nullable enable

Expand Down
Loading
Loading