From 15ea3058071ba1ae73a01785abb9179574760c41 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Wed, 22 Jul 2020 23:02:11 -0700 Subject: [PATCH 1/4] Interop Changes Part 1 - Cleanup Interop source --- .../src/Interop/Unix/Interop.Libraries.cs | 6 - .../Interop.GssApiException.cs | 26 +-- .../Interop.GssBuffer.cs | 5 +- .../Interop.NetSecurityNative.cs | 81 +------- .../src/Interop/Windows/Interop.Errors.cs | 71 ------- .../src/Interop/Windows/Interop.Libraries.cs | 25 --- .../Interop/Windows/sspicli/Interop.SSPI.cs | 50 ++--- .../Win32/SafeHandles/GssSafeHandles.cs | 58 +++--- .../Net/Security/NegotiateStreamPal.Unix.cs | 192 +----------------- .../Security/Unix/SafeDeleteNegoContext.cs | 3 - .../Net/Security/Unix/SafeFreeCredentials.cs | 11 +- .../Security/Unix/SafeFreeNegoCredentials.cs | 3 - .../Microsoft/Data/SqlClient/SNI/SNIProxy.cs | 129 ++++++------ .../Data/SqlClient/TdsParser.Unix.cs | 2 +- .../Data/SqlClient/TdsParser.Windows.cs | 5 +- .../SqlClient/TdsParserStateObjectManaged.cs | 29 +-- 16 files changed, 155 insertions(+), 541 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/Interop.Libraries.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/Interop.Libraries.cs index 7446e1bfba..c4f2f36493 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/Interop.Libraries.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/Interop.Libraries.cs @@ -7,12 +7,6 @@ internal static partial class Interop internal static partial class Libraries { // Shims - internal const string SystemNative = "System.Native"; - internal const string HttpNative = "System.Net.Http.Native"; internal const string NetSecurityNative = "System.Net.Security.Native"; - internal const string CryptoNative = "System.Security.Cryptography.Native.OpenSsl"; - internal const string CompressionNative = "System.IO.Compression.Native"; - internal const string IOPortsNative = "System.IO.Ports.Native"; - internal const string Libdl = "libdl"; } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssApiException.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssApiException.cs index 0da9396f54..9f620b7935 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssApiException.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssApiException.cs @@ -3,8 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; -using System.Diagnostics; using System.Runtime.InteropServices; internal static partial class Interop @@ -13,22 +11,19 @@ internal static partial class NetSecurityNative { internal sealed class GssApiException : Exception { - private readonly Status _minorStatus; + internal Status MinorStatus { get; private set; } - public Status MinorStatus - { - get { return _minorStatus;} - } + internal GssApiException() { } - public GssApiException(string message) : base(message) - { - } + internal GssApiException(string message) : base(message) { } + + internal GssApiException(string message, Exception innerException) : base(message, innerException) { } - public GssApiException(Status majorStatus, Status minorStatus) + internal GssApiException(Status majorStatus, Status minorStatus) : base(GetGssApiDisplayStatus(majorStatus, minorStatus)) { HResult = (int)majorStatus; - _minorStatus = minorStatus; + MinorStatus = minorStatus; } private static string GetGssApiDisplayStatus(Status majorStatus, Status minorStatus) @@ -43,13 +38,12 @@ private static string GetGssApiDisplayStatus(Status majorStatus, Status minorSta private static string GetGssApiDisplayStatus(Status status, bool isMinor) { - GssBuffer displayBuffer = default(GssBuffer); + GssBuffer displayBuffer = default; try { - Interop.NetSecurityNative.Status minStat; - Interop.NetSecurityNative.Status displayCallStatus = isMinor ? - DisplayMinorStatus(out minStat, status, ref displayBuffer): + Status displayCallStatus = isMinor ? + DisplayMinorStatus(out Status minStat, status, ref displayBuffer) : DisplayMajorStatus(out minStat, status, ref displayBuffer); return (Status.GSS_S_COMPLETE != displayCallStatus) ? null : Marshal.PtrToStringAnsi(displayBuffer._data); } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs index 8bed992b93..b65fce2512 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs @@ -5,7 +5,6 @@ using System; using System.Diagnostics; using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; internal static partial class Interop { @@ -32,7 +31,7 @@ internal int Copy(byte[] destination, int offset) int destinationAvailable = destination.Length - offset; // amount of space in the given buffer if (sourceLength > destinationAvailable) { - throw new NetSecurityNative.GssApiException(SRHelper.Format(SR.net_context_buffer_too_small, sourceLength, destinationAvailable)); + throw new GssApiException(SRHelper.Format(SR.net_context_buffer_too_small, sourceLength, destinationAvailable)); } Marshal.Copy(_data, destination, offset, sourceLength); @@ -56,7 +55,7 @@ public void Dispose() { if (_data != IntPtr.Zero) { - Interop.NetSecurityNative.ReleaseGssBuffer(_data, _length); + ReleaseGssBuffer(_data, _length); _data = IntPtr.Zero; } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.NetSecurityNative.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.NetSecurityNative.cs index ab08863b9f..e3e3e3759b 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.NetSecurityNative.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.NetSecurityNative.cs @@ -5,56 +5,55 @@ using System; using System.Diagnostics; using System.Runtime.InteropServices; -using System.Text; using Microsoft.Win32.SafeHandles; internal static partial class Interop { internal static partial class NetSecurityNative { - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_ReleaseGssBuffer")] + [DllImport(Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_ReleaseGssBuffer")] internal static extern void ReleaseGssBuffer( IntPtr bufferPtr, ulong length); - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_DisplayMinorStatus")] + [DllImport(Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_DisplayMinorStatus")] internal static extern Status DisplayMinorStatus( out Status minorStatus, Status statusValue, ref GssBuffer buffer); - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_DisplayMajorStatus")] + [DllImport(Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_DisplayMajorStatus")] internal static extern Status DisplayMajorStatus( out Status minorStatus, Status statusValue, ref GssBuffer buffer); - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_ImportUserName")] + [DllImport(Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_ImportUserName", CharSet = CharSet.Unicode)] internal static extern Status ImportUserName( out Status minorStatus, string inputName, int inputNameByteCount, out SafeGssNameHandle outputName); - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_ImportPrincipalName")] + [DllImport(Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_ImportPrincipalName", CharSet = CharSet.Unicode)] internal static extern Status ImportPrincipalName( out Status minorStatus, string inputName, int inputNameByteCount, out SafeGssNameHandle outputName); - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_ReleaseName")] + [DllImport(Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_ReleaseName")] internal static extern Status ReleaseName( out Status minorStatus, ref IntPtr inputName); - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_InitiateCredSpNego")] + [DllImport(Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_InitiateCredSpNego")] internal static extern Status InitiateCredSpNego( out Status minorStatus, SafeGssNameHandle desiredName, out SafeGssCredHandle outputCredHandle); - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_InitiateCredWithPassword")] + [DllImport(Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_InitiateCredWithPassword", CharSet = CharSet.Unicode)] internal static extern Status InitiateCredWithPassword( out Status minorStatus, bool isNtlm, @@ -63,12 +62,12 @@ internal static extern Status InitiateCredWithPassword( int passwordLen, out SafeGssCredHandle outputCredHandle); - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_ReleaseCred")] + [DllImport(Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_ReleaseCred")] internal static extern Status ReleaseCred( out Status minorStatus, ref IntPtr credHandle); - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_InitSecContext")] + [DllImport(Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_InitSecContext")] internal static extern Status InitSecContext( out Status minorStatus, SafeGssCredHandle initiatorCredHandle, @@ -82,69 +81,11 @@ internal static extern Status InitSecContext( out uint retFlags, out int isNtlmUsed); - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_AcceptSecContext")] - internal static extern Status AcceptSecContext( - out Status minorStatus, - ref SafeGssContextHandle acceptContextHandle, - byte[] inputBytes, - int inputLength, - ref GssBuffer token); - - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_DeleteSecContext")] + [DllImport(Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_DeleteSecContext")] internal static extern Status DeleteSecContext( out Status minorStatus, ref IntPtr contextHandle); - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_Wrap")] - private static extern Status Wrap( - out Status minorStatus, - SafeGssContextHandle contextHandle, - bool isEncrypt, - byte[] inputBytes, - int offset, - int count, - ref GssBuffer outBuffer); - - [DllImport(Interop.Libraries.NetSecurityNative, EntryPoint="NetSecurityNative_Unwrap")] - private static extern Status Unwrap( - out Status minorStatus, - SafeGssContextHandle contextHandle, - byte[] inputBytes, - int offset, - int count, - ref GssBuffer outBuffer); - - internal static Status WrapBuffer( - out Status minorStatus, - SafeGssContextHandle contextHandle, - bool isEncrypt, - byte[] inputBytes, - int offset, - int count, - ref GssBuffer outBuffer) - { - Debug.Assert(inputBytes != null, "inputBytes must be valid value"); - Debug.Assert(offset >= 0 && offset <= inputBytes.Length, "offset must be valid"); - Debug.Assert(count >= 0 && count <= (inputBytes.Length - offset), "count must be valid"); - - return Wrap(out minorStatus, contextHandle, isEncrypt, inputBytes, offset, count, ref outBuffer); - } - - internal static Status UnwrapBuffer( - out Status minorStatus, - SafeGssContextHandle contextHandle, - byte[] inputBytes, - int offset, - int count, - ref GssBuffer outBuffer) - { - Debug.Assert(inputBytes != null, "inputBytes must be valid value"); - Debug.Assert(offset >= 0 && offset <= inputBytes.Length, "offset must be valid"); - Debug.Assert(count >= 0 && count <= inputBytes.Length, "count must be valid"); - - return Unwrap(out minorStatus, contextHandle, inputBytes, offset, count, ref outBuffer); - } - internal enum Status : uint { GSS_S_COMPLETE = 0, diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Errors.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Errors.cs index 7836b049eb..2e0c3553f2 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Errors.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Errors.cs @@ -7,80 +7,9 @@ internal partial class Interop // https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382.aspx internal partial class Errors { - internal const int ERROR_SUCCESS = 0x0; - internal const int ERROR_INVALID_FUNCTION = 0x1; internal const int ERROR_FILE_NOT_FOUND = 0x2; - internal const int ERROR_PATH_NOT_FOUND = 0x3; - internal const int ERROR_ACCESS_DENIED = 0x5; internal const int ERROR_INVALID_HANDLE = 0x6; - internal const int ERROR_NOT_ENOUGH_MEMORY = 0x8; - internal const int ERROR_INVALID_DATA = 0xD; - internal const int ERROR_INVALID_DRIVE = 0xF; - internal const int ERROR_NO_MORE_FILES = 0x12; - internal const int ERROR_NOT_READY = 0x15; - internal const int ERROR_BAD_COMMAND = 0x16; - internal const int ERROR_BAD_LENGTH = 0x18; internal const int ERROR_SHARING_VIOLATION = 0x20; - internal const int ERROR_LOCK_VIOLATION = 0x21; - internal const int ERROR_HANDLE_EOF = 0x26; - internal const int ERROR_BAD_NETPATH = 0x35; - internal const int ERROR_NETWORK_ACCESS_DENIED = 0x41; - internal const int ERROR_BAD_NET_NAME = 0x43; - internal const int ERROR_FILE_EXISTS = 0x50; internal const int ERROR_INVALID_PARAMETER = 0x57; - internal const int ERROR_BROKEN_PIPE = 0x6D; - internal const int ERROR_SEM_TIMEOUT = 0x79; - internal const int ERROR_CALL_NOT_IMPLEMENTED = 0x78; - internal const int ERROR_INSUFFICIENT_BUFFER = 0x7A; - internal const int ERROR_INVALID_NAME = 0x7B; - internal const int ERROR_NEGATIVE_SEEK = 0x83; - internal const int ERROR_DIR_NOT_EMPTY = 0x91; - internal const int ERROR_BAD_PATHNAME = 0xA1; - internal const int ERROR_LOCK_FAILED = 0xA7; - internal const int ERROR_BUSY = 0xAA; - internal const int ERROR_ALREADY_EXISTS = 0xB7; - internal const int ERROR_BAD_EXE_FORMAT = 0xC1; - internal const int ERROR_ENVVAR_NOT_FOUND = 0xCB; - internal const int ERROR_FILENAME_EXCED_RANGE = 0xCE; - internal const int ERROR_EXE_MACHINE_TYPE_MISMATCH = 0xD8; - internal const int ERROR_PIPE_BUSY = 0xE7; - internal const int ERROR_NO_DATA = 0xE8; - internal const int ERROR_PIPE_NOT_CONNECTED = 0xE9; - internal const int ERROR_MORE_DATA = 0xEA; - internal const int ERROR_NO_MORE_ITEMS = 0x103; - internal const int ERROR_DIRECTORY = 0x10B; - internal const int ERROR_PARTIAL_COPY = 0x12B; - internal const int ERROR_ARITHMETIC_OVERFLOW = 0x216; - internal const int ERROR_PIPE_CONNECTED = 0x217; - internal const int ERROR_PIPE_LISTENING = 0x218; - internal const int ERROR_OPERATION_ABORTED = 0x3E3; - internal const int ERROR_IO_INCOMPLETE = 0x3E4; - internal const int ERROR_IO_PENDING = 0x3E5; - internal const int ERROR_NO_TOKEN = 0x3f0; - internal const int ERROR_DLL_INIT_FAILED = 0x45A; - internal const int ERROR_COUNTER_TIMEOUT = 0x461; - internal const int ERROR_NO_ASSOCIATION = 0x483; - internal const int ERROR_DDE_FAIL = 0x484; - internal const int ERROR_DLL_NOT_FOUND = 0x485; - internal const int ERROR_NOT_FOUND = 0x490; - internal const int ERROR_NETWORK_UNREACHABLE = 0x4CF; - internal const int ERROR_NON_ACCOUNT_SID = 0x4E9; - internal const int ERROR_NOT_ALL_ASSIGNED = 0x514; - internal const int ERROR_UNKNOWN_REVISION = 0x519; - internal const int ERROR_INVALID_OWNER = 0x51B; - internal const int ERROR_INVALID_PRIMARY_GROUP = 0x51C; - internal const int ERROR_NO_SUCH_PRIVILEGE = 0x521; - internal const int ERROR_PRIVILEGE_NOT_HELD = 0x522; - internal const int ERROR_INVALID_ACL = 0x538; - internal const int ERROR_INVALID_SECURITY_DESCR = 0x53A; - internal const int ERROR_INVALID_SID = 0x539; - internal const int ERROR_BAD_IMPERSONATION_LEVEL = 0x542; - internal const int ERROR_CANT_OPEN_ANONYMOUS = 0x543; - internal const int ERROR_NO_SECURITY_ON_OBJECT = 0x546; - internal const int ERROR_CLASS_ALREADY_EXISTS = 0x582; - internal const int ERROR_TRUSTED_RELATIONSHIP_FAILURE = 0x6FD; - internal const int ERROR_RESOURCE_LANG_NOT_FOUND = 0x717; - internal const int EFail = unchecked((int)0x80004005); - internal const int E_FILENOTFOUND = unchecked((int)0x80070002); } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Libraries.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Libraries.cs index f130aa1bfb..a1c85bb09d 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Libraries.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Libraries.cs @@ -7,34 +7,9 @@ internal static partial class Interop internal static partial class Libraries { internal const string Advapi32 = "advapi32.dll"; - internal const string BCrypt = "BCrypt.dll"; - internal const string CoreComm_L1_1_1 = "api-ms-win-core-comm-l1-1-1.dll"; - internal const string CoreComm_L1_1_2 = "api-ms-win-core-comm-l1-1-2.dll"; internal const string Crypt32 = "crypt32.dll"; - internal const string CryptUI = "cryptui.dll"; - internal const string Error_L1 = "api-ms-win-core-winrt-error-l1-1-0.dll"; - internal const string HttpApi = "httpapi.dll"; - internal const string IpHlpApi = "iphlpapi.dll"; internal const string Kernel32 = "kernel32.dll"; - internal const string Memory_L1_3 = "api-ms-win-core-memory-l1-1-3.dll"; - internal const string Mswsock = "mswsock.dll"; - internal const string NCrypt = "ncrypt.dll"; internal const string NtDll = "ntdll.dll"; - internal const string Odbc32 = "odbc32.dll"; - internal const string Ole32 = "ole32.dll"; - internal const string OleAut32 = "oleaut32.dll"; - internal const string PerfCounter = "perfcounter.dll"; - internal const string RoBuffer = "api-ms-win-core-winrt-robuffer-l1-1-0.dll"; - internal const string Secur32 = "secur32.dll"; - internal const string Shell32 = "shell32.dll"; internal const string SspiCli = "sspicli.dll"; - internal const string User32 = "user32.dll"; - internal const string Version = "version.dll"; - internal const string WebSocket = "websocket.dll"; - internal const string WinHttp = "winhttp.dll"; - internal const string Ws2_32 = "ws2_32.dll"; - internal const string Wtsapi32 = "wtsapi32.dll"; - internal const string CompressionNative = "clrcompression.dll"; - internal const string CoreWinRT = "api-ms-win-core-winrt-l1-1-0.dll"; } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/Interop.SSPI.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/Interop.SSPI.cs index 34bed7ce31..8ceed0e870 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/Interop.SSPI.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/sspicli/Interop.SSPI.cs @@ -20,23 +20,23 @@ internal static partial class SspiCli [StructLayout(LayoutKind.Sequential, Pack = 1)] internal struct CredHandle { - private IntPtr dwLower; - private IntPtr dwUpper; + private IntPtr _dwLower; + private IntPtr _dwUpper; public bool IsZero { - get { return dwLower == IntPtr.Zero && dwUpper == IntPtr.Zero; } + get { return _dwLower == IntPtr.Zero && _dwUpper == IntPtr.Zero; } } internal void SetToInvalid() { - dwLower = IntPtr.Zero; - dwUpper = IntPtr.Zero; + _dwLower = IntPtr.Zero; + _dwUpper = IntPtr.Zero; } public override string ToString() { - { return dwLower.ToString("x") + ":" + dwUpper.ToString("x"); } + { return _dwLower.ToString("x") + ":" + _dwUpper.ToString("x"); } } } @@ -201,7 +201,7 @@ internal struct SCHANNEL_CRED public int dwMinimumCipherStrength; public int dwMaximumCipherStrength; public int dwSessionLifespan; - public SCHANNEL_CRED.Flags dwFlags; + public Flags dwFlags; public int reserved; [Flags] @@ -243,7 +243,7 @@ public SecBufferDesc(int count) } } - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern int EncryptMessage( ref CredHandle contextHandle, [In] uint qualityOfProtection, @@ -251,7 +251,7 @@ internal static extern int EncryptMessage( [In] uint sequenceNumber ); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern unsafe int DecryptMessage( [In] ref CredHandle contextHandle, [In, Out] ref SecBufferDesc inputOutput, @@ -259,26 +259,26 @@ internal static extern unsafe int DecryptMessage( uint* qualityOfProtection ); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern int QuerySecurityContextToken( ref CredHandle phContext, [Out] out SecurityContextTokenHandle handle); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern int FreeContextBuffer( [In] IntPtr contextBuffer); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern int FreeCredentialsHandle( ref CredHandle handlePtr ); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern int DeleteSecurityContext( ref CredHandle handlePtr ); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern unsafe int AcceptSecurityContext( ref CredHandle credentialHandle, [In] void* inContextPtr, @@ -291,25 +291,25 @@ internal static extern unsafe int AcceptSecurityContext( out long timeStamp ); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern unsafe int QueryContextAttributesW( ref CredHandle contextHandle, [In] ContextAttribute attribute, [In] void* buffer); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern unsafe int SetContextAttributesW( ref CredHandle contextHandle, [In] ContextAttribute attribute, [In] byte[] buffer, [In] int bufferSize); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern int EnumerateSecurityPackagesW( [Out] out int pkgnum, [Out] out SafeFreeContextBuffer_SECURITY handle); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] internal static extern unsafe int AcquireCredentialsHandleW( [In] string principal, [In] string moduleName, @@ -322,7 +322,7 @@ internal static extern unsafe int AcquireCredentialsHandleW( [Out] out long timeStamp ); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] internal static extern unsafe int AcquireCredentialsHandleW( [In] string principal, [In] string moduleName, @@ -335,7 +335,7 @@ internal static extern unsafe int AcquireCredentialsHandleW( [Out] out long timeStamp ); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] internal static extern unsafe int AcquireCredentialsHandleW( [In] string principal, [In] string moduleName, @@ -348,7 +348,7 @@ internal static extern unsafe int AcquireCredentialsHandleW( [Out] out long timeStamp ); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern unsafe int InitializeSecurityContextW( ref CredHandle credentialHandle, [In] void* inContextPtr, @@ -364,23 +364,23 @@ internal static extern unsafe int InitializeSecurityContextW( out long timeStamp ); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern unsafe int CompleteAuthToken( [In] void* inContextPtr, [In, Out] ref SecBufferDesc inputBuffers ); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern unsafe int ApplyControlToken( [In] void* inContextPtr, [In, Out] ref SecBufferDesc inputBuffers ); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, SetLastError = true)] internal static extern unsafe SECURITY_STATUS SspiFreeAuthIdentity( [In] IntPtr authData); - [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] + [DllImport(Libraries.SspiCli, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)] internal static extern unsafe SECURITY_STATUS SspiEncodeStringsAsAuthIdentity( [In] string userName, [In] string domainName, diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Win32/SafeHandles/GssSafeHandles.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Win32/SafeHandles/GssSafeHandles.cs index 6daf3f2191..6921ef6aba 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Win32/SafeHandles/GssSafeHandles.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Win32/SafeHandles/GssSafeHandles.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; +using static Interop.NetSecurityNative; namespace Microsoft.Win32.SafeHandles { @@ -17,15 +18,13 @@ internal sealed class SafeGssNameHandle : SafeHandle public static SafeGssNameHandle CreateUser(string name) { Debug.Assert(!string.IsNullOrEmpty(name), "Invalid user name passed to SafeGssNameHandle create"); - SafeGssNameHandle retHandle; - Interop.NetSecurityNative.Status minorStatus; - Interop.NetSecurityNative.Status status = Interop.NetSecurityNative.ImportUserName( - out minorStatus, name, Encoding.UTF8.GetByteCount(name), out retHandle); + Status status = ImportUserName( + out Status minorStatus, name, Encoding.UTF8.GetByteCount(name), out SafeGssNameHandle retHandle); - if (status != Interop.NetSecurityNative.Status.GSS_S_COMPLETE) + if (status != Status.GSS_S_COMPLETE) { retHandle.Dispose(); - throw new Interop.NetSecurityNative.GssApiException(status, minorStatus); + throw new GssApiException(status, minorStatus); } return retHandle; @@ -34,15 +33,13 @@ public static SafeGssNameHandle CreateUser(string name) public static SafeGssNameHandle CreatePrincipal(string name) { Debug.Assert(!string.IsNullOrEmpty(name), "Invalid principal passed to SafeGssNameHandle create"); - SafeGssNameHandle retHandle; - Interop.NetSecurityNative.Status minorStatus; - Interop.NetSecurityNative.Status status = Interop.NetSecurityNative.ImportPrincipalName( - out minorStatus, name, Encoding.UTF8.GetByteCount(name), out retHandle); + Status status = ImportPrincipalName( + out Status minorStatus, name, Encoding.UTF8.GetByteCount(name), out SafeGssNameHandle retHandle); - if (status != Interop.NetSecurityNative.Status.GSS_S_COMPLETE) + if (status != Status.GSS_S_COMPLETE) { retHandle.Dispose(); - throw new Interop.NetSecurityNative.GssApiException(status, minorStatus); + throw new GssApiException(status, minorStatus); } return retHandle; @@ -55,16 +52,12 @@ public override bool IsInvalid protected override bool ReleaseHandle() { - Interop.NetSecurityNative.Status minorStatus; - Interop.NetSecurityNative.Status status = Interop.NetSecurityNative.ReleaseName(out minorStatus, ref handle); + Status status = ReleaseName(out _, ref handle); SetHandle(IntPtr.Zero); - return status == Interop.NetSecurityNative.Status.GSS_S_COMPLETE; + return status == Status.GSS_S_COMPLETE; } - private SafeGssNameHandle() - : base(IntPtr.Zero, true) - { - } + private SafeGssNameHandle() : base(IntPtr.Zero, true) { } } /// @@ -86,21 +79,21 @@ public static SafeGssCredHandle Create(string username, string password, bool is SafeGssCredHandle retHandle = null; using (SafeGssNameHandle userHandle = SafeGssNameHandle.CreateUser(username)) { - Interop.NetSecurityNative.Status status; - Interop.NetSecurityNative.Status minorStatus; + Status status; + Status minorStatus; if (string.IsNullOrEmpty(password)) { - status = Interop.NetSecurityNative.InitiateCredSpNego(out minorStatus, userHandle, out retHandle); + status = InitiateCredSpNego(out minorStatus, userHandle, out retHandle); } else { - status = Interop.NetSecurityNative.InitiateCredWithPassword(out minorStatus, isNtlmOnly, userHandle, password, Encoding.UTF8.GetByteCount(password), out retHandle); + status = InitiateCredWithPassword(out minorStatus, isNtlmOnly, userHandle, password, Encoding.UTF8.GetByteCount(password), out retHandle); } - if (status != Interop.NetSecurityNative.Status.GSS_S_COMPLETE) + if (status != Status.GSS_S_COMPLETE) { retHandle.Dispose(); - throw new Interop.NetSecurityNative.GssApiException(status, minorStatus); + throw new GssApiException(status, minorStatus); } } @@ -119,19 +112,15 @@ public override bool IsInvalid protected override bool ReleaseHandle() { - Interop.NetSecurityNative.Status minorStatus; - Interop.NetSecurityNative.Status status = Interop.NetSecurityNative.ReleaseCred(out minorStatus, ref handle); + Status status = ReleaseCred(out _, ref handle); SetHandle(IntPtr.Zero); - return status == Interop.NetSecurityNative.Status.GSS_S_COMPLETE; + return status == Status.GSS_S_COMPLETE; } } internal sealed class SafeGssContextHandle : SafeHandle { - public SafeGssContextHandle() - : base(IntPtr.Zero, true) - { - } + public SafeGssContextHandle() : base(IntPtr.Zero, true) { } public override bool IsInvalid { @@ -140,10 +129,9 @@ public override bool IsInvalid protected override bool ReleaseHandle() { - Interop.NetSecurityNative.Status minorStatus; - Interop.NetSecurityNative.Status status = Interop.NetSecurityNative.DeleteSecContext(out minorStatus, ref handle); + Status status = DeleteSecContext(out _, ref handle); SetHandle(IntPtr.Zero); - return status == Interop.NetSecurityNative.Status.GSS_S_COMPLETE; + return status == Status.GSS_S_COMPLETE; } } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/NegotiateStreamPal.Unix.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/NegotiateStreamPal.Unix.cs index 74ed1b5d61..2fa4890fc2 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/NegotiateStreamPal.Unix.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/NegotiateStreamPal.Unix.cs @@ -2,15 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.IO; -using System.Security; -using System.Security.Principal; -using System.Threading; using System.ComponentModel; using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security.Authentication; -using System.Security.Authentication.ExtendedProtection; using Microsoft.Win32.SafeHandles; namespace System.Net.Security @@ -26,74 +19,6 @@ internal static partial class NegotiateStreamPal // defined in winerror.h private const int NTE_FAIL = unchecked((int)0x80090020); - internal static string QueryContextClientSpecifiedSpn(SafeDeleteContext securityContext) - { - throw new PlatformNotSupportedException(SR.net_nego_server_not_supported); - } - - internal static string QueryContextAuthenticationPackage(SafeDeleteContext securityContext) - { - SafeDeleteNegoContext negoContext = (SafeDeleteNegoContext)securityContext; - return negoContext.IsNtlmUsed ? NegotiationInfoClass.NTLM : NegotiationInfoClass.Kerberos; - } - - static byte[] GssWrap( - SafeGssContextHandle context, - bool encrypt, - byte[] buffer, - int offset, - int count) - { - Debug.Assert((buffer != null) && (buffer.Length > 0), "Invalid input buffer passed to Encrypt"); - Debug.Assert((offset >= 0) && (offset < buffer.Length), "Invalid input offset passed to Encrypt"); - Debug.Assert((count >= 0) && (count <= (buffer.Length - offset)), "Invalid input count passed to Encrypt"); - - Interop.NetSecurityNative.GssBuffer encryptedBuffer = default(Interop.NetSecurityNative.GssBuffer); - try - { - Interop.NetSecurityNative.Status minorStatus; - Interop.NetSecurityNative.Status status = Interop.NetSecurityNative.WrapBuffer(out minorStatus, context, encrypt, buffer, offset, count, ref encryptedBuffer); - if (status != Interop.NetSecurityNative.Status.GSS_S_COMPLETE) - { - throw new Interop.NetSecurityNative.GssApiException(status, minorStatus); - } - - return encryptedBuffer.ToByteArray(); - } - finally - { - encryptedBuffer.Dispose(); - } - } - - private static int GssUnwrap( - SafeGssContextHandle context, - byte[] buffer, - int offset, - int count) - { - Debug.Assert((buffer != null) && (buffer.Length > 0), "Invalid input buffer passed to Decrypt"); - Debug.Assert((offset >= 0) && (offset <= buffer.Length), "Invalid input offset passed to Decrypt"); - Debug.Assert((count >= 0) && (count <= (buffer.Length - offset)), "Invalid input count passed to Decrypt"); - - Interop.NetSecurityNative.GssBuffer decryptedBuffer = default(Interop.NetSecurityNative.GssBuffer); - try - { - Interop.NetSecurityNative.Status minorStatus; - Interop.NetSecurityNative.Status status = Interop.NetSecurityNative.UnwrapBuffer(out minorStatus, context, buffer, offset, count, ref decryptedBuffer); - if (status != Interop.NetSecurityNative.Status.GSS_S_COMPLETE) - { - throw new Interop.NetSecurityNative.GssApiException(status, minorStatus); - } - - return decryptedBuffer.Copy(buffer, offset); - } - finally - { - decryptedBuffer.Dispose(); - } - } - private static bool GssInitSecurityContext( ref SafeGssContextHandle context, SafeGssCredHandle credential, @@ -116,7 +41,7 @@ private static bool GssInitSecurityContext( context = new SafeGssContextHandle(); } - Interop.NetSecurityNative.GssBuffer token = default(Interop.NetSecurityNative.GssBuffer); + Interop.NetSecurityNative.GssBuffer token = default; Interop.NetSecurityNative.Status status; try @@ -259,22 +184,6 @@ internal static SecurityStatusPal InitializeSecurityContext( return status; } - internal static SecurityStatusPal AcceptSecurityContext( - SafeFreeCredentials credentialsHandle, - ref SafeDeleteContext securityContext, - ContextFlagsPal requestedContextFlags, - SecurityBuffer[] inSecurityBufferArray, - SecurityBuffer outSecurityBuffer, - ref ContextFlagsPal contextFlags) - { - throw new PlatformNotSupportedException(SR.net_nego_server_not_supported); - } - - internal static Win32Exception CreateExceptionFromError(SecurityStatusPal statusCode) - { - return new Win32Exception(NTE_FAIL, (statusCode.Exception != null) ? statusCode.Exception.Message : statusCode.ErrorCode.ToString()); - } - internal static int QueryMaxTokenSize(string package) { // This value is not used on Unix @@ -313,104 +222,5 @@ internal static SafeFreeCredentials AcquireCredentialsHandle(string package, boo throw new Win32Exception(NTE_FAIL, ex.Message); } } - - internal static SecurityStatusPal CompleteAuthToken( - ref SafeDeleteContext securityContext, - SecurityBuffer[] inSecurityBufferArray) - { - return new SecurityStatusPal(SecurityStatusPalErrorCode.OK); - } - - internal static int Encrypt( - SafeDeleteContext securityContext, - byte[] buffer, - int offset, - int count, - bool isConfidential, - bool isNtlm, - ref byte[] output, - uint sequenceNumber) - { - SafeDeleteNegoContext gssContext = (SafeDeleteNegoContext) securityContext; - byte[] tempOutput = GssWrap(gssContext.GssContext, isConfidential, buffer, offset, count); - - // Create space for prefixing with the length - const int prefixLength = 4; - output = new byte[tempOutput.Length + prefixLength]; - Array.Copy(tempOutput, 0, output, prefixLength, tempOutput.Length); - int resultSize = tempOutput.Length; - unchecked - { - output[0] = (byte)((resultSize) & 0xFF); - output[1] = (byte)(((resultSize) >> 8) & 0xFF); - output[2] = (byte)(((resultSize) >> 16) & 0xFF); - output[3] = (byte)(((resultSize) >> 24) & 0xFF); - } - - return resultSize + 4; - } - - internal static int Decrypt( - SafeDeleteContext securityContext, - byte[] buffer, - int offset, - int count, - bool isConfidential, - bool isNtlm, - out int newOffset, - uint sequenceNumber) - { - if (offset < 0 || offset > (buffer == null ? 0 : buffer.Length)) - { - NetEventSource.Fail(securityContext, "Argument 'offset' out of range"); - throw new ArgumentOutOfRangeException(nameof(offset)); - } - - if (count < 0 || count > (buffer == null ? 0 : buffer.Length - offset)) - { - NetEventSource.Fail(securityContext, "Argument 'count' out of range."); - throw new ArgumentOutOfRangeException(nameof(count)); - } - - newOffset = offset; - return GssUnwrap(((SafeDeleteNegoContext)securityContext).GssContext, buffer, offset, count); - } - - internal static int VerifySignature(SafeDeleteContext securityContext, byte[] buffer, int offset, int count) - { - if (offset < 0 || offset > (buffer == null ? 0 : buffer.Length)) - { - NetEventSource.Fail(securityContext, "Argument 'offset' out of range"); - throw new ArgumentOutOfRangeException(nameof(offset)); - } - - if (count < 0 || count > (buffer == null ? 0 : buffer.Length - offset)) - { - NetEventSource.Fail(securityContext, "Argument 'count' out of range."); - throw new ArgumentOutOfRangeException(nameof(count)); - } - - return GssUnwrap(((SafeDeleteNegoContext)securityContext).GssContext, buffer, offset, count); - } - - internal static int MakeSignature(SafeDeleteContext securityContext, byte[] buffer, int offset, int count, ref byte[] output) - { - SafeDeleteNegoContext gssContext = (SafeDeleteNegoContext)securityContext; - byte[] tempOutput = GssWrap(gssContext.GssContext, false, buffer, offset, count); - // Create space for prefixing with the length - const int prefixLength = 4; - output = new byte[tempOutput.Length + prefixLength]; - Array.Copy(tempOutput, 0, output, prefixLength, tempOutput.Length); - int resultSize = tempOutput.Length; - unchecked - { - output[0] = (byte)((resultSize) & 0xFF); - output[1] = (byte)(((resultSize) >> 8) & 0xFF); - output[2] = (byte)(((resultSize) >> 16) & 0xFF); - output[3] = (byte)(((resultSize) >> 24) & 0xFF); - } - - return resultSize + 4; - } } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/Unix/SafeDeleteNegoContext.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/Unix/SafeDeleteNegoContext.cs index 9b07e53e5e..b98e9ac80b 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/Unix/SafeDeleteNegoContext.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/Unix/SafeDeleteNegoContext.cs @@ -2,10 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Text; using Microsoft.Win32.SafeHandles; namespace System.Net.Security diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/Unix/SafeFreeCredentials.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/Unix/SafeFreeCredentials.cs index 245f0f24cf..51d6869a8d 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/Unix/SafeFreeCredentials.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/Unix/SafeFreeCredentials.cs @@ -2,9 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Diagnostics; using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; +using Microsoft.Win32.SafeHandles; namespace System.Net.Security { @@ -37,7 +36,7 @@ internal sealed class SafeCredentialReference : CriticalHandleMinusOneIsInvalid // // Static cache will return the target handle if found the reference in the table. // - internal SafeFreeCredentials Target; + internal SafeFreeCredentials _target; internal static SafeCredentialReference CreateReference(SafeFreeCredentials target) { @@ -55,19 +54,19 @@ private SafeCredentialReference(SafeFreeCredentials target) : base() // its dispose should be postponed bool ignore = false; target.DangerousAddRef(ref ignore); - Target = target; + _target = target; SetHandle(new IntPtr(0)); // make this handle valid } protected override bool ReleaseHandle() { - SafeFreeCredentials target = Target; + SafeFreeCredentials target = _target; if (target != null) { target.DangerousRelease(); } - Target = null; + _target = null; return true; } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/Unix/SafeFreeNegoCredentials.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/Unix/SafeFreeNegoCredentials.cs index ab8cf2fea0..217c787619 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/Unix/SafeFreeNegoCredentials.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Security/Unix/SafeFreeNegoCredentials.cs @@ -2,10 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Text; using Microsoft.Win32.SafeHandles; namespace System.Net.Security diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs index b578cb6364..f25b8ac2d6 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs @@ -5,7 +5,6 @@ using System; using System.Diagnostics; using System.IO; -using System.Linq; using System.Net; using System.Net.Security; using System.Net.Sockets; @@ -21,6 +20,7 @@ internal class SNIProxy private const int DefaultSqlServerPort = 1433; private const int DefaultSqlServerDacPort = 1434; private const string SqlServerSpnHeader = "MSSQLSvc"; + private const int MaxTokenSize = 0; internal class SspiClientContextResult { @@ -29,13 +29,11 @@ internal class SspiClientContextResult internal const uint KerberosTicketMissing = 2; } - public static readonly SNIProxy Singleton = new SNIProxy(); + internal static readonly SNIProxy s_singleton = new SNIProxy(); - /// - /// Terminate SNI - /// - public void Terminate() + internal static SNIProxy GetInstance() { + return s_singleton; } /// @@ -44,7 +42,7 @@ public void Terminate() /// Connection handle /// /// SNI error code - public uint EnableSsl(SNIHandle handle, uint options) + internal uint EnableSsl(SNIHandle handle, uint options) { try { @@ -61,7 +59,7 @@ public uint EnableSsl(SNIHandle handle, uint options) /// /// Connection handle /// SNI error code - public uint DisableSsl(SNIHandle handle) + internal uint DisableSsl(SNIHandle handle) { handle.DisableSsl(); return TdsEnums.SNI_SUCCESS; @@ -75,7 +73,7 @@ public uint DisableSsl(SNIHandle handle) /// Send buffer /// Service Principal Name buffer /// SNI error code - public void GenSspiClientContext(SspiClientContextStatus sspiClientContextStatus, byte[] receivedBuff, ref byte[] sendBuff, byte[] serverName) + internal void GenSspiClientContext(SspiClientContextStatus sspiClientContextStatus, byte[] receivedBuff, ref byte[] sendBuff, byte[] serverName) { SafeDeleteContext securityContext = sspiClientContextStatus.SecurityContext; ContextFlagsPal contextFlags = sspiClientContextStatus.ContextFlags; @@ -88,7 +86,7 @@ public void GenSspiClientContext(SspiClientContextStatus sspiClientContextStatus credentialsHandle = NegotiateStreamPal.AcquireDefaultCredential(securityPackage, false); } - SecurityBuffer[] inSecurityBufferArray = null; + SecurityBuffer[] inSecurityBufferArray; if (receivedBuff != null) { inSecurityBufferArray = new SecurityBuffer[] { new SecurityBuffer(receivedBuff, SecurityBufferType.SECBUFFER_TOKEN) }; @@ -98,7 +96,7 @@ public void GenSspiClientContext(SspiClientContextStatus sspiClientContextStatus inSecurityBufferArray = Array.Empty(); } - int tokenSize = NegotiateStreamPal.QueryMaxTokenSize(securityPackage); + int tokenSize = MaxTokenSize; SecurityBuffer outSecurityBuffer = new SecurityBuffer(tokenSize, SecurityBufferType.SECBUFFER_TOKEN); ContextFlagsPal requestedContextFlags = ContextFlagsPal.Connection @@ -121,7 +119,7 @@ public void GenSspiClientContext(SspiClientContextStatus sspiClientContextStatus statusCode.ErrorCode == SecurityStatusPalErrorCode.CompAndContinue) { inSecurityBufferArray = new SecurityBuffer[] { outSecurityBuffer }; - statusCode = NegotiateStreamPal.CompleteAuthToken(ref securityContext, inSecurityBufferArray); + statusCode = new SecurityStatusPal(SecurityStatusPalErrorCode.OK); outSecurityBuffer.token = null; } @@ -164,23 +162,13 @@ private static bool IsErrorStatus(SecurityStatusPalErrorCode errorCode) errorCode != SecurityStatusPalErrorCode.Renegotiate; } - /// - /// Initialize SSPI - /// - /// Max length of SSPI packet - /// SNI error code - public uint InitializeSspiPackage(ref uint maxLength) - { - throw new PlatformNotSupportedException(); - } - /// /// Set connection buffer size /// /// SNI handle /// Buffer size /// SNI error code - public uint SetConnectionBufferSize(SNIHandle handle, uint bufferSize) + internal uint SetConnectionBufferSize(SNIHandle handle, uint bufferSize) { handle.SetBufferSize((int)bufferSize); return TdsEnums.SNI_SUCCESS; @@ -193,7 +181,7 @@ public uint SetConnectionBufferSize(SNIHandle handle, uint bufferSize) /// Destination byte array where data packets are copied to /// Length of data packets /// SNI error status - public uint PacketGetData(SNIPacket packet, byte[] inBuff, ref uint dataSize) + internal uint PacketGetData(SNIPacket packet, byte[] inBuff, ref uint dataSize) { int dataSizeInt = 0; packet.GetData(inBuff, ref dataSizeInt); @@ -209,7 +197,7 @@ public uint PacketGetData(SNIPacket packet, byte[] inBuff, ref uint dataSize) /// SNI packet /// Timeout /// SNI error status - public uint ReadSyncOverAsync(SNIHandle handle, out SNIPacket packet, int timeout) + internal uint ReadSyncOverAsync(SNIHandle handle, out SNIPacket packet, int timeout) { return handle.Receive(out packet, timeout); } @@ -220,7 +208,7 @@ public uint ReadSyncOverAsync(SNIHandle handle, out SNIPacket packet, int timeou /// SNI handle /// Client connection ID /// SNI error status - public uint GetConnectionId(SNIHandle handle, ref Guid clientConnectionId) + internal uint GetConnectionId(SNIHandle handle, ref Guid clientConnectionId) { clientConnectionId = handle.ConnectionId; @@ -234,7 +222,7 @@ public uint GetConnectionId(SNIHandle handle, ref Guid clientConnectionId) /// SNI packet /// true if synchronous, false if asynchronous /// SNI error status - public uint WritePacket(SNIHandle handle, SNIPacket packet, bool sync) + internal uint WritePacket(SNIHandle handle, SNIPacket packet, bool sync) { uint result; if (sync) @@ -266,7 +254,7 @@ public uint WritePacket(SNIHandle handle, SNIPacket packet, bool sync) /// Used for DNS Cache /// Used for DNS Cache /// SNI handle - public SNIHandle CreateConnectionHandle(object callbackObject, string fullServerName, bool ignoreSniOpenTimeout, long timerExpire, out byte[] instanceName, ref byte[] spnBuffer, bool flushCache, bool async, bool parallel, bool isIntegratedSecurity, string cachedFQDN, ref SQLDNSInfo pendingDNSInfo) + internal SNIHandle CreateConnectionHandle(object callbackObject, string fullServerName, bool ignoreSniOpenTimeout, long timerExpire, out byte[] instanceName, ref byte[] spnBuffer, bool flushCache, bool async, bool parallel, bool isIntegratedSecurity, string cachedFQDN, ref SQLDNSInfo pendingDNSInfo) { instanceName = new byte[1]; @@ -288,7 +276,7 @@ public SNIHandle CreateConnectionHandle(object callbackObject, string fullServer } SNIHandle sniHandle = null; - switch (details.ConnectionProtocol) + switch (details._connectionProtocol) { case DataSource.Protocol.Admin: case DataSource.Protocol.None: // default to using tcp if no protocol is provided @@ -299,7 +287,7 @@ public SNIHandle CreateConnectionHandle(object callbackObject, string fullServer sniHandle = CreateNpHandle(details, timerExpire, callbackObject, parallel); break; default: - Debug.Fail($"Unexpected connection protocol: {details.ConnectionProtocol}"); + Debug.Fail($"Unexpected connection protocol: {details._connectionProtocol}"); break; } @@ -333,7 +321,7 @@ private static byte[] GetSqlServerSPN(DataSource dataSource) postfix = dataSource.InstanceName; } // For handling tcp: format - else if (dataSource.ConnectionProtocol == DataSource.Protocol.TCP) + else if (dataSource._connectionProtocol == DataSource.Protocol.TCP) { postfix = DefaultSqlServerPort.ToString(); } @@ -396,7 +384,7 @@ private SNITCPHandle CreateTcpHandle(DataSource details, long timerExpire, objec } int port = -1; - bool isAdminConnection = details.ConnectionProtocol == DataSource.Protocol.Admin; + bool isAdminConnection = details._connectionProtocol == DataSource.Protocol.Admin; if (details.IsSsrpRequired) { try @@ -449,7 +437,7 @@ private SNINpHandle CreateNpHandle(DataSource details, long timerExpire, object /// SNI handle /// Packet /// SNI error status - public uint ReadAsync(SNIHandle handle, out SNIPacket packet) + internal uint ReadAsync(SNIHandle handle, out SNIPacket packet) { packet = null; return handle.ReceiveAsync(ref packet); @@ -461,7 +449,7 @@ public uint ReadAsync(SNIHandle handle, out SNIPacket packet) /// SNI packet /// Data /// Length - public void PacketSetData(SNIPacket packet, byte[] data, int length) + internal void PacketSetData(SNIPacket packet, byte[] data, int length) { packet.AppendData(data, length); } @@ -471,7 +459,7 @@ public void PacketSetData(SNIPacket packet, byte[] data, int length) /// /// /// SNI error status - public uint CheckConnection(SNIHandle handle) + internal uint CheckConnection(SNIHandle handle) { return handle.CheckConnection(); } @@ -480,7 +468,7 @@ public uint CheckConnection(SNIHandle handle) /// Get last SNI error on this thread /// /// - public SNIError GetLastError() + internal SNIError GetLastError() { return SNILoadHandle.SingletonInstance.LastError; } @@ -524,10 +512,13 @@ private string GetLocalDBDataSource(string fullServerName, out bool error) internal class DataSource { private const char CommaSeparator = ','; - private const char BackSlashSeparator = '\\'; + private const char SemiColon = ':'; + private const char BackSlashCharacter = '\\'; + private const string DefaultHostName = "localhost"; private const string DefaultSqlServerInstanceName = "mssqlserver"; private const string PipeBeginning = @"\\"; + private const string Slash = @"/"; private const string PipeToken = "pipe"; private const string LocalDbHost = "(localdb)"; private const string NamedPipeInstanceNameHeader = "mssql$"; @@ -535,7 +526,7 @@ internal class DataSource internal enum Protocol { TCP, NP, None, Admin }; - internal Protocol ConnectionProtocol = Protocol.None; + internal Protocol _connectionProtocol = Protocol.None; /// /// Provides the HostName of the server to connect to for TCP protocol. @@ -551,17 +542,17 @@ internal enum Protocol { TCP, NP, None, Admin }; /// /// Provides the inferred Instance Name from Server Data Source /// - public string InstanceName { get; internal set; } + internal string InstanceName { get; private set; } /// /// Provides the pipe name in case of Named Pipes /// - public string PipeName { get; internal set; } + internal string PipeName { get; private set; } /// /// Provides the HostName to connect to in case of Named pipes Data Source /// - public string PipeHostName { get; internal set; } + internal string PipeHostName { get; private set; } private string _workingDataSource; private string _dataSourceAfterTrimmingProtocol; @@ -574,31 +565,31 @@ private DataSource(string dataSource) // Remove all whitespaces from the datasource and all operations will happen on lower case. _workingDataSource = dataSource.Trim().ToLowerInvariant(); - int firstIndexOfColon = _workingDataSource.IndexOf(':'); + int firstIndexOfColon = _workingDataSource.IndexOf(SemiColon); PopulateProtocol(); - _dataSourceAfterTrimmingProtocol = (firstIndexOfColon > -1) && ConnectionProtocol != DataSource.Protocol.None + _dataSourceAfterTrimmingProtocol = (firstIndexOfColon > -1) && _connectionProtocol != Protocol.None ? _workingDataSource.Substring(firstIndexOfColon + 1).Trim() : _workingDataSource; - if (_dataSourceAfterTrimmingProtocol.Contains("/")) // Pipe paths only allow back slashes + if (_dataSourceAfterTrimmingProtocol.Contains(Slash)) // Pipe paths only allow back slashes { - if (ConnectionProtocol == DataSource.Protocol.None) + if (_connectionProtocol == Protocol.None) ReportSNIError(SNIProviders.INVALID_PROV); - else if (ConnectionProtocol == DataSource.Protocol.NP) + else if (_connectionProtocol == Protocol.NP) ReportSNIError(SNIProviders.NP_PROV); - else if (ConnectionProtocol == DataSource.Protocol.TCP) + else if (_connectionProtocol == Protocol.TCP) ReportSNIError(SNIProviders.TCP_PROV); } } private void PopulateProtocol() { - string[] splitByColon = _workingDataSource.Split(':'); + string[] splitByColon = _workingDataSource.Split(SemiColon); if (splitByColon.Length <= 1) { - ConnectionProtocol = DataSource.Protocol.None; + _connectionProtocol = Protocol.None; } else { @@ -606,29 +597,29 @@ private void PopulateProtocol() switch (splitByColon[0].Trim()) { case TdsEnums.TCP: - ConnectionProtocol = DataSource.Protocol.TCP; + _connectionProtocol = Protocol.TCP; break; case TdsEnums.NP: - ConnectionProtocol = DataSource.Protocol.NP; + _connectionProtocol = Protocol.NP; break; case TdsEnums.ADMIN: - ConnectionProtocol = DataSource.Protocol.Admin; + _connectionProtocol = Protocol.Admin; break; default: // None of the supported protocols were found. This may be a IPv6 address - ConnectionProtocol = DataSource.Protocol.None; + _connectionProtocol = Protocol.None; break; } } } - public static string GetLocalDBInstance(string dataSource, out bool error) + internal static string GetLocalDBInstance(string dataSource, out bool error) { string instanceName = null; string workingDataSource = dataSource.ToLowerInvariant(); - string[] tokensByBackSlash = workingDataSource.Split(BackSlashSeparator); + string[] tokensByBackSlash = workingDataSource.Split(BackSlashCharacter); error = false; @@ -650,7 +641,7 @@ public static string GetLocalDBInstance(string dataSource, out bool error) return instanceName; } - public static DataSource ParseServerName(string dataSource) + internal static DataSource ParseServerName(string dataSource) { DataSource details = new DataSource(dataSource); @@ -682,19 +673,19 @@ private void InferLocalServerName() // If Server name is empty or localhost, then use "localhost" if (string.IsNullOrEmpty(ServerName) || IsLocalHost(ServerName)) { - ServerName = ConnectionProtocol == DataSource.Protocol.Admin ? + ServerName = _connectionProtocol == Protocol.Admin ? Environment.MachineName : DefaultHostName; } } private bool InferConnectionDetails() { - string[] tokensByCommaAndSlash = _dataSourceAfterTrimmingProtocol.Split(BackSlashSeparator, ','); + string[] tokensByCommaAndSlash = _dataSourceAfterTrimmingProtocol.Split(BackSlashCharacter, CommaSeparator); ServerName = tokensByCommaAndSlash[0].Trim(); - int commaIndex = _dataSourceAfterTrimmingProtocol.IndexOf(','); + int commaIndex = _dataSourceAfterTrimmingProtocol.IndexOf(CommaSeparator); - int backSlashIndex = _dataSourceAfterTrimmingProtocol.IndexOf(BackSlashSeparator); + int backSlashIndex = _dataSourceAfterTrimmingProtocol.IndexOf(PipeBeginning); // Check the parameters. The parameters are Comma separated in the Data Source. The parameter we really care about is the port // If Comma exists, the try to get the port number @@ -712,11 +703,11 @@ private bool InferConnectionDetails() } // For Tcp and Only Tcp are parameters allowed. - if (ConnectionProtocol == DataSource.Protocol.None) + if (_connectionProtocol == Protocol.None) { - ConnectionProtocol = DataSource.Protocol.TCP; + _connectionProtocol = Protocol.TCP; } - else if (ConnectionProtocol != DataSource.Protocol.TCP) + else if (_connectionProtocol != Protocol.TCP) { // Parameter has been specified for non-TCP protocol. This is not allowed. ReportSNIError(SNIProviders.INVALID_PROV); @@ -774,10 +765,10 @@ private void ReportSNIError(SNIProviders provider) private bool InferNamedPipesInformation() { // If we have a datasource beginning with a pipe or we have already determined that the protocol is Named Pipe - if (_dataSourceAfterTrimmingProtocol.StartsWith(PipeBeginning) || ConnectionProtocol == Protocol.NP) + if (_dataSourceAfterTrimmingProtocol.StartsWith(PipeBeginning) || _connectionProtocol == Protocol.NP) { // If the data source is "np:servername" - if (!_dataSourceAfterTrimmingProtocol.Contains(BackSlashSeparator)) + if (!_dataSourceAfterTrimmingProtocol.Contains(PipeBeginning)) { PipeHostName = ServerName = _dataSourceAfterTrimmingProtocol; InferLocalServerName(); @@ -787,7 +778,7 @@ private bool InferNamedPipesInformation() try { - string[] tokensByBackSlash = _dataSourceAfterTrimmingProtocol.Split(BackSlashSeparator); + string[] tokensByBackSlash = _dataSourceAfterTrimmingProtocol.Split(BackSlashCharacter); // The datasource is of the format \\host\pipe\sql\query [0]\[1]\[2]\[3]\[4]\[5] // It would at least have 6 parts. @@ -846,11 +837,11 @@ private bool InferNamedPipesInformation() } // DataSource is something like "\\pipename" - if (ConnectionProtocol == DataSource.Protocol.None) + if (_connectionProtocol == Protocol.None) { - ConnectionProtocol = DataSource.Protocol.NP; + _connectionProtocol = Protocol.NP; } - else if (ConnectionProtocol != DataSource.Protocol.NP) + else if (_connectionProtocol != Protocol.NP) { // In case the path began with a "\\" and protocol was not Named Pipes ReportSNIError(SNIProviders.NP_PROV); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs index 1c875f5813..692633efd6 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs @@ -26,7 +26,7 @@ private void WaitForSSLHandShakeToComplete(ref uint error, ref int protocolVersi private SNIErrorDetails GetSniErrorDetails() { SNIErrorDetails details; - SNIError sniError = SNIProxy.Singleton.GetLastError(); + SNIError sniError = SNIProxy.GetInstance().GetLastError(); details.sniErrorNumber = sniError.sniError; details.errorMessage = sniError.errorMessage; details.nativeError = sniError.nativeError; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs index d5ddb5d47d..07846127d7 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs @@ -95,7 +95,7 @@ private SNIErrorDetails GetSniErrorDetails() if (TdsParserStateObjectFactory.UseManagedSNI) { - SNIError sniError = SNIProxy.Singleton.GetLastError(); + SNIError sniError = SNIProxy.GetInstance().GetLastError(); details.sniErrorNumber = sniError.sniError; details.errorMessage = sniError.errorMessage; details.nativeError = sniError.nativeError; @@ -106,8 +106,7 @@ private SNIErrorDetails GetSniErrorDetails() } else { - SNINativeMethodWrapper.SNI_Error sniError; - SNINativeMethodWrapper.SNIGetLastError(out sniError); + SNINativeMethodWrapper.SNIGetLastError(out SNINativeMethodWrapper.SNI_Error sniError); details.sniErrorNumber = sniError.sniError; details.errorMessage = sniError.errorMessage; details.nativeError = sniError.nativeError; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs index cc2430bf24..eb6f0811f9 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs @@ -47,11 +47,11 @@ internal SNIMarsHandle CreateMarsSession(object callbackObject, bool async) } protected override uint SNIPacketGetData(PacketHandle packet, byte[] _inBuff, ref uint dataSize) - => SNIProxy.Singleton.PacketGetData(packet.ManagedPacket, _inBuff, ref dataSize); + => SNIProxy.GetInstance().PacketGetData(packet.ManagedPacket, _inBuff, ref dataSize); internal override void CreatePhysicalSNIHandle(string serverName, bool ignoreSniOpenTimeout, long timerExpire, out byte[] instanceName, ref byte[] spnBuffer, bool flushCache, bool async, bool parallel, string cachedFQDN, ref SQLDNSInfo pendingDNSInfo, bool isIntegratedSecurity) { - _sessionHandle = SNIProxy.Singleton.CreateConnectionHandle(this, serverName, ignoreSniOpenTimeout, timerExpire, out instanceName, ref spnBuffer, flushCache, async, parallel, isIntegratedSecurity, cachedFQDN, ref pendingDNSInfo); + _sessionHandle = SNIProxy.GetInstance().CreateConnectionHandle(this, serverName, ignoreSniOpenTimeout, timerExpire, out instanceName, ref spnBuffer, flushCache, async, parallel, isIntegratedSecurity, cachedFQDN, ref pendingDNSInfo); if (_sessionHandle == null) { _parser.ProcessSNIError(this); @@ -121,7 +121,7 @@ internal override PacketHandle ReadSyncOverAsync(int timeoutRemaining, out uint { throw ADP.ClosedConnectionError(); } - error = SNIProxy.Singleton.ReadSyncOverAsync(handle, out SNIPacket packet, timeoutRemaining); + error = SNIProxy.GetInstance().ReadSyncOverAsync(handle, out SNIPacket packet, timeoutRemaining); return PacketHandle.FromManagedPacket(packet); } @@ -142,12 +142,12 @@ internal override void ReleasePacket(PacketHandle syncReadPacket) internal override uint CheckConnection() { SNIHandle handle = Handle; - return handle == null ? TdsEnums.SNI_SUCCESS : SNIProxy.Singleton.CheckConnection(handle); + return handle == null ? TdsEnums.SNI_SUCCESS : SNIProxy.GetInstance().CheckConnection(handle); } internal override PacketHandle ReadAsync(SessionHandle handle, out uint error) { - error = SNIProxy.Singleton.ReadAsync(handle.ManagedHandle, out SNIPacket packet); + error = SNIProxy.GetInstance().ReadAsync(handle.ManagedHandle, out SNIPacket packet); return PacketHandle.FromManagedPacket(packet); } @@ -155,7 +155,7 @@ internal override PacketHandle CreateAndSetAttentionPacket() { PacketHandle packetHandle = GetResetWritePacket(TdsEnums.HEADER_LEN); #if DEBUG - Debug.Assert(packetHandle.ManagedPacket.IsActive, "rental packet is not active a serious pooling error may have occured"); + Debug.Assert(packetHandle.ManagedPacket.IsActive, "rental packet is not active a serious pooling error may have occurred"); #endif SetPacketData(packetHandle, SQL.AttentionHeader, TdsEnums.HEADER_LEN); packetHandle.ManagedPacket.IsOutOfBand = true; @@ -163,7 +163,7 @@ internal override PacketHandle CreateAndSetAttentionPacket() } internal override uint WritePacket(PacketHandle packet, bool sync) => - SNIProxy.Singleton.WritePacket(Handle, packet.ManagedPacket, sync); + SNIProxy.GetInstance().WritePacket(Handle, packet.ManagedPacket, sync); // No- Op in managed SNI internal override PacketHandle AddPacketToPendingList(PacketHandle packet) => packet; @@ -183,7 +183,7 @@ internal override PacketHandle GetResetWritePacket(int dataSize) SNIHandle handle = Handle; SNIPacket packet = handle.RentPacket(headerSize: handle.ReserveHeaderSize, dataSize: dataSize); #if DEBUG - Debug.Assert(packet.IsActive, "packet is not active, a serious pooling error may have occured"); + Debug.Assert(packet.IsActive, "packet is not active, a serious pooling error may have occurred"); #endif Debug.Assert(packet.ReservedHeaderSize == handle.ReserveHeaderSize, "failed to reserve header"); return PacketHandle.FromManagedPacket(packet); @@ -194,11 +194,11 @@ internal override void ClearAllWritePackets() Debug.Assert(_asyncWriteCount == 0, "Should not clear all write packets if there are packets pending"); } - internal override void SetPacketData(PacketHandle packet, byte[] buffer, int bytesUsed) => SNIProxy.Singleton.PacketSetData(packet.ManagedPacket, buffer, bytesUsed); + internal override void SetPacketData(PacketHandle packet, byte[] buffer, int bytesUsed) => SNIProxy.GetInstance().PacketSetData(packet.ManagedPacket, buffer, bytesUsed); - internal override uint SniGetConnectionId(ref Guid clientConnectionId) => SNIProxy.Singleton.GetConnectionId(Handle, ref clientConnectionId); + internal override uint SniGetConnectionId(ref Guid clientConnectionId) => SNIProxy.GetInstance().GetConnectionId(Handle, ref clientConnectionId); - internal override uint DisableSsl() => SNIProxy.Singleton.DisableSsl(Handle); + internal override uint DisableSsl() => SNIProxy.GetInstance().DisableSsl(Handle); internal override uint EnableMars(ref uint info) { @@ -211,9 +211,9 @@ internal override uint EnableMars(ref uint info) return TdsEnums.SNI_ERROR; } - internal override uint EnableSsl(ref uint info) => SNIProxy.Singleton.EnableSsl(Handle, info); + internal override uint EnableSsl(ref uint info) => SNIProxy.GetInstance().EnableSsl(Handle, info); - internal override uint SetConnectionBufferSize(ref uint unsignedPacketSize) => SNIProxy.Singleton.SetConnectionBufferSize(Handle, unsignedPacketSize); + internal override uint SetConnectionBufferSize(ref uint unsignedPacketSize) => SNIProxy.GetInstance().SetConnectionBufferSize(Handle, unsignedPacketSize); internal override uint GenerateSspiClientContext(byte[] receivedBuff, uint receivedLength, ref byte[] sendBuff, ref uint sendLength, byte[] _sniSpnBuffer) { @@ -221,7 +221,8 @@ internal override uint GenerateSspiClientContext(byte[] receivedBuff, uint recei { _sspiClientContextStatus = new SspiClientContextStatus(); } - SNIProxy.Singleton.GenSspiClientContext(_sspiClientContextStatus, receivedBuff, ref sendBuff, _sniSpnBuffer); + + // SNIProxy.GetInstance().GenSspiClientContext(_sspiClientContextStatus, receivedBuff, ref sendBuff, _sniSpnBuffer); sendLength = (uint)(sendBuff != null ? sendBuff.Length : 0); return 0; } From 0b8fcf362776870c19d2eef34d075703d8e9a17d Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Thu, 23 Jul 2020 15:31:27 -0700 Subject: [PATCH 2/4] More changes --- src/Microsoft.Data.SqlClient.sln | 54 -- .../CoreLib/Interop/Unix/Interop.Errors.cs | 209 ------- .../CoreLib/Interop/Unix/Interop.IOErrors.cs | 172 ------ .../CoreLib/Interop/Unix/Interop.Libraries.cs | 12 - .../Interop.Calendar.cs | 33 -- .../Interop.Casing.cs | 23 - .../Interop.Collation.cs | 79 --- .../Interop.ICU.cs | 16 - .../Interop.Idna.cs | 21 - .../Interop.Locale.cs | 40 -- .../Interop.Normalization.cs | 19 - .../Interop.ResultCode.cs | 18 - .../Interop.TimeZoneInfo.cs | 28 - .../Interop.Utils.cs | 52 -- .../Unix/System.Native/Interop.Close.cs | 15 - .../Unix/System.Native/Interop.FLock.cs | 31 - .../Unix/System.Native/Interop.FSync.cs | 15 - .../Unix/System.Native/Interop.FTruncate.cs | 15 - .../Unix/System.Native/Interop.GetCwd.cs | 74 --- .../System.Native/Interop.GetRandomBytes.cs | 21 - .../Unix/System.Native/Interop.LSeek.cs | 22 - .../System.Native/Interop.LockFileRegion.cs | 21 - .../Unix/System.Native/Interop.MksTemps.cs | 17 - .../Unix/System.Native/Interop.Open.cs | 15 - .../Unix/System.Native/Interop.OpenFlags.cs | 27 - .../Unix/System.Native/Interop.PathConf.cs | 28 - .../Unix/System.Native/Interop.Permissions.cs | 32 - .../System.Native/Interop.PosixFAdvise.cs | 36 -- .../Unix/System.Native/Interop.Read.cs | 25 - .../Unix/System.Native/Interop.ReadDir.cs | 102 ---- .../Unix/System.Native/Interop.ReadLink.cs | 63 -- .../Unix/System.Native/Interop.Stat.cs | 65 -- .../Unix/System.Native/Interop.SysLog.cs | 58 -- .../Unix/System.Native/Interop.Unlink.cs | 15 - .../Unix/System.Native/Interop.Write.cs | 27 - .../Unix/System.Native/Interop.Accept.cs | 15 - .../Unix/System.Native/Interop.Access.cs | 23 - .../Unix/System.Native/Interop.Bind.cs | 16 - .../Unix/System.Native/Interop.ChDir.cs | 15 - .../Unix/System.Native/Interop.ChMod.cs | 15 - .../Unix/System.Native/Interop.Connect.cs | 15 - .../Unix/System.Native/Interop.CopyFile.cs | 16 - .../Interop/Unix/System.Native/Interop.Dup.cs | 16 - .../Interop.EnumerateInterfaceAddresses.cs | 45 -- .../Unix/System.Native/Interop.FChMod.cs | 16 - .../Unix/System.Native/Interop.Fcntl.Pipe.cs | 27 - .../Interop.Fcntl.SetCloseOnExec.cs | 19 - .../Unix/System.Native/Interop.Fcntl.cs | 21 - .../System.Native/Interop.FileDescriptors.cs | 24 - .../Interop.ForkAndExecProcess.cs | 111 ---- .../Interop.GetBytesAvailable.cs | 18 - .../Interop.GetControlCharacters.cs | 37 -- .../System.Native/Interop.GetDomainName.cs | 39 -- .../Interop.GetDomainSocketSizes.cs | 15 - .../Unix/System.Native/Interop.GetEGid.cs | 15 - .../Unix/System.Native/Interop.GetEUid.cs | 15 - .../Unix/System.Native/Interop.GetHostName.cs | 40 -- .../Unix/System.Native/Interop.GetLine.cs | 15 - .../Unix/System.Native/Interop.GetNameInfo.cs | 30 - .../Unix/System.Native/Interop.GetNodeName.cs | 35 -- .../Interop.GetOSArchitecture.cs | 15 - .../Unix/System.Native/Interop.GetPeerID.cs | 15 - .../Unix/System.Native/Interop.GetPeerName.cs | 15 - .../System.Native/Interop.GetPeerUserName.cs | 16 - .../Unix/System.Native/Interop.GetPid.cs | 15 - .../Interop.GetProcessArchitecture.cs | 15 - .../Unix/System.Native/Interop.GetPwUid.cs | 31 - .../System.Native/Interop.GetSetPriority.cs | 63 -- .../Unix/System.Native/Interop.GetSockName.cs | 15 - .../Unix/System.Native/Interop.GetSockOpt.cs | 16 - .../Interop.GetSocketErrorOption.cs | 16 - .../System.Native/Interop.GetTimestamp.cs | 23 - .../Unix/System.Native/Interop.GetUnixName.cs | 21 - .../System.Native/Interop.GetUnixRelease.cs | 14 - .../System.Native/Interop.GetUnixVersion.cs | 36 -- .../System.Native/Interop.GetWindowWidth.cs | 24 - .../Unix/System.Native/Interop.HostEntry.cs | 59 -- .../Unix/System.Native/Interop.IPAddress.cs | 78 --- .../Interop.IPPacketInformation.cs | 24 - .../Interop.InitializeConsole.cs | 17 - .../Unix/System.Native/Interop.IsATty.cs | 16 - .../Unix/System.Native/Interop.Kill.cs | 21 - .../System.Native/Interop.LingerOption.cs | 28 - .../Unix/System.Native/Interop.Link.cs | 15 - .../Unix/System.Native/Interop.Listen.cs | 15 - .../Unix/System.Native/Interop.MAdvise.cs | 20 - .../Unix/System.Native/Interop.MMap.cs | 38 -- .../Unix/System.Native/Interop.MSync.cs | 23 - .../Unix/System.Native/Interop.MUnmap.cs | 15 - .../Unix/System.Native/Interop.MapTcpState.cs | 15 - .../Unix/System.Native/Interop.MemSet.cs | 15 - .../System.Native/Interop.MessageHeader.cs | 29 - .../Unix/System.Native/Interop.MkDir.cs | 15 - .../Interop.MountPoints.FormatInfo.cs | 440 -------------- .../Unix/System.Native/Interop.MountPoints.cs | 40 -- .../System.Native/Interop.MulticastOption.cs | 47 -- .../Unix/System.Native/Interop.POpen.cs | 18 - .../Unix/System.Native/Interop.Pipe.cs | 31 - .../Interop.PlatformSocketSupport.cs | 14 - .../Unix/System.Native/Interop.Poll.cs | 78 --- .../Unix/System.Native/Interop.PrintF.cs | 19 - .../Interop.ProcessorArchitecture.cs | 20 - .../Unix/System.Native/Interop.Read.Pipe.cs | 25 - .../Unix/System.Native/Interop.ReadDir.cs | 86 --- .../Interop.ReadStdinUnbuffered.cs | 21 - .../Unix/System.Native/Interop.RealPath.cs | 20 - .../System.Native/Interop.ReceiveMessage.cs | 16 - .../System.Native/Interop.RegisterForCtrlC.cs | 25 - .../Interop.RegisterForSigChld.cs | 16 - .../Unix/System.Native/Interop.Rename.cs | 23 - .../System.Native/Interop.ResourceLimits.cs | 40 -- .../Interop.RestoreAndHandleCtrl.cs | 14 - .../Unix/System.Native/Interop.RmDir.cs | 22 - .../Unix/System.Native/Interop.SNPrintF.cs | 54 -- .../Interop.SchedGetSetAffinity.cs | 18 - .../Unix/System.Native/Interop.SendFile.cs | 14 - .../Unix/System.Native/Interop.SendMessage.cs | 16 - .../Unix/System.Native/Interop.SetEUid.cs | 15 - .../Interop.SetReceiveTimeout.cs | 16 - .../System.Native/Interop.SetSendTimeout.cs | 16 - .../Interop.SetSignalForBreak.cs | 17 - .../Unix/System.Native/Interop.SetSockOpt.cs | 19 - .../Unix/System.Native/Interop.ShmOpen.cs | 18 - .../Unix/System.Native/Interop.Shutdown.cs | 16 - .../Unix/System.Native/Interop.Socket.cs | 18 - .../System.Native/Interop.SocketAddress.cs | 40 -- .../Unix/System.Native/Interop.SocketEvent.cs | 52 -- .../Unix/System.Native/Interop.Stat.Pipe.cs | 16 - .../Unix/System.Native/Interop.Stat.Span.cs | 41 -- .../Unix/System.Native/Interop.StdinReady.cs | 14 - .../Unix/System.Native/Interop.Sync.cs | 18 - .../Unix/System.Native/Interop.SysConf.cs | 20 - .../Unix/System.Native/Interop.UTimensat.cs | 29 - .../Unix/System.Native/Interop.WaitId.cs | 23 - .../Unix/System.Native/Interop.WaitPid.cs | 24 - .../Unix/System.Native/Interop.Write.Pipe.cs | 24 - .../Interop.CURLcode.cs | 25 - .../System.Net.Http.Native/Interop.Easy.cs | 268 --------- .../Interop.Initialization.cs | 52 -- .../System.Net.Http.Native/Interop.Multi.cs | 104 ---- .../System.Net.Http.Native/Interop.SList.cs | 63 -- .../Interop.VersionInfo.cs | 54 -- .../Interop.ASN1.GetIntegerBytes.cs | 45 -- .../Interop.ASN1.Nid.cs | 16 - .../Interop.ASN1.cs | 113 ---- .../Interop.BIO.cs | 39 -- .../Interop.Bignum.cs | 91 --- .../Interop.Crypto.cs | 183 ------ .../Interop.Dsa.cs | 176 ------ .../Interop.ERR.cs | 123 ---- .../Interop.EVP.Cipher.cs | 85 --- .../Interop.EVP.cs | 56 -- .../Interop.EcDsa.ImportExport.cs | 338 ----------- .../Interop.EcDsa.cs | 62 -- .../Interop.EcKey.cs | 87 --- .../Interop.Encode.cs | 46 -- .../Interop.EvpPkey.Dsa.cs | 20 - .../Interop.EvpPkey.EcKey.cs | 20 - .../Interop.EvpPkey.Ecdh.cs | 43 -- .../Interop.EvpPkey.Rsa.cs | 20 - .../Interop.EvpPkey.cs | 22 - .../Interop.Hmac.cs | 31 - .../Interop.Initialization.cs | 47 -- .../Interop.LookupFriendlyNameByOid.cs | 15 - .../Interop.OpenSsl.cs | 558 ------------------ .../Interop.OpenSslVersion.cs | 31 - .../Interop.Pkcs12.cs | 45 -- .../Interop.Pkcs7.cs | 61 -- .../Interop.RAND.cs | 23 - .../Interop.Rsa.cs | 217 ------- .../Interop.SetProtocolOptions.cs | 17 - .../Interop.Ssl.cs | 341 ----------- .../Interop.SslCtx.cs | 100 ---- .../Interop.SslCtxOptions.cs | 36 -- .../Interop.X509.cs | 214 ------- .../Interop.X509Ext.cs | 41 -- .../Interop.X509Name.cs | 71 --- .../Interop.X509Stack.cs | 76 --- .../Interop.X509StoreCtx.cs | 63 -- .../src/Interop/Unix/libdl/Interop.dlopen.cs | 17 - .../src/Interop/Unix/libdl/Interop.dlsym.cs | 15 - .../src/Interop/Windows/Interop.Libraries.cs | 1 - .../Interop.GetTokenInformation_void.cs | 21 - .../Interop.OpenProcessToken_IntPtr.cs | 20 - ....OpenProcessToken_SafeAccessTokenHandle.cs | 17 - .../advapi32/Interop.TOKEN_ELEVATION.cs | 15 - .../Interop.TOKEN_INFORMATION_CLASS.cs | 57 -- .../kernel32/Interop.FileOperations.cs | 28 - .../src/Microsoft.Data.SqlClient.csproj | 3 - .../Microsoft.Data.SqlClient.Tests.csproj | 3 - .../SqlConnectionBasicTests.cs | 2 +- .../DataCommon/AssemblyResourceManager.cs | 30 +- ....Data.SqlClient.ManualTesting.Tests.csproj | 3 - .../ExceptionTest/ConnectionExceptionTest.cs | 7 +- .../CoreFx.Private.TestUtilities.csproj | 121 ---- .../CoreFx.Private.TestUtilities.rd.xml | 7 - .../System/AdminHelpers.Unix.cs | 24 - .../System/AdminHelpers.Windows.cs | 44 -- .../System/AdminHelpers.cs | 33 -- .../Net/PlatformDetection.Networking.cs | 14 - .../System/PlatformDetection.NetFx.cs | 68 --- .../System/PlatformDetection.NonNetFx.cs | 62 -- .../System/PlatformDetection.Unix.cs | 244 -------- .../System/PlatformDetection.Windows.cs | 272 --------- .../System/PlatformDetection.cs | 133 ----- .../System/TestEnvironment.cs | 22 - .../System/TheoryExtensions.cs | 38 -- .../Extensions}/AssertExtensions.cs | 0 .../Extensions/PlatformDetection.cs} | 8 +- .../Microsoft.DotNet.XUnitExtensions.csproj | 3 + tools/props/Versions.props | 1 + 211 files changed, 23 insertions(+), 9947 deletions(-) delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/Interop.Errors.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/Interop.IOErrors.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/Interop.Libraries.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Casing.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Collation.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.ICU.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Idna.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Locale.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Utils.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Close.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.FLock.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.FSync.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.FTruncate.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.GetCwd.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.GetRandomBytes.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.LSeek.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.LockFileRegion.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.MksTemps.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Open.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.OpenFlags.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.PathConf.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Permissions.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.PosixFAdvise.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Read.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.ReadDir.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.ReadLink.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Stat.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.SysLog.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Unlink.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Write.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Accept.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Access.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Bind.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ChDir.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ChMod.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Connect.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.CopyFile.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Dup.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.FChMod.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Fcntl.Pipe.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Fcntl.SetCloseOnExec.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Fcntl.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.FileDescriptors.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ForkAndExecProcess.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetBytesAvailable.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetControlCharacters.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetDomainName.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetDomainSocketSizes.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetEGid.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetEUid.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetLine.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetNameInfo.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetNodeName.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetOSArchitecture.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPeerID.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPeerName.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPeerUserName.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPid.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetProcessArchitecture.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPwUid.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSetPriority.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSockName.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSockOpt.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSocketErrorOption.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetTimestamp.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetUnixName.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetUnixRelease.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetUnixVersion.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetWindowWidth.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.HostEntry.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.IPAddress.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.IPPacketInformation.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.InitializeConsole.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.IsATty.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Kill.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.LingerOption.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Link.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Listen.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MAdvise.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MMap.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MSync.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MUnmap.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MapTcpState.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MemSet.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MessageHeader.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MkDir.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MountPoints.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MulticastOption.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.POpen.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Pipe.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.PlatformSocketSupport.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Poll.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.PrintF.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ProcessorArchitecture.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Read.Pipe.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ReadDir.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ReadStdinUnbuffered.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RealPath.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ReceiveMessage.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RegisterForCtrlC.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RegisterForSigChld.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Rename.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ResourceLimits.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RestoreAndHandleCtrl.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RmDir.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SNPrintF.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SchedGetSetAffinity.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SendFile.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SendMessage.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetEUid.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetReceiveTimeout.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetSendTimeout.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetSignalForBreak.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetSockOpt.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ShmOpen.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Shutdown.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Socket.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SocketAddress.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SocketEvent.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Stat.Pipe.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Stat.Span.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.StdinReady.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Sync.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SysConf.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.UTimensat.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.WaitId.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.WaitPid.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Write.Pipe.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.CURLcode.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.Easy.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.Initialization.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.Multi.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.SList.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.VersionInfo.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.GetIntegerBytes.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.Nid.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.BIO.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Bignum.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Crypto.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Dsa.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ERR.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.Cipher.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.ImportExport.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcKey.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Encode.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Dsa.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.EcKey.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Ecdh.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Rsa.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Hmac.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Initialization.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.LookupFriendlyNameByOid.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSslVersion.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Pkcs12.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Pkcs7.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.RAND.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Rsa.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SetProtocolOptions.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SslCtx.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SslCtxOptions.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Ext.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Name.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Stack.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509StoreCtx.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/libdl/Interop.dlopen.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/libdl/Interop.dlsym.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.GetTokenInformation_void.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.OpenProcessToken_IntPtr.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.OpenProcessToken_SafeAccessTokenHandle.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.TOKEN_ELEVATION.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.TOKEN_INFORMATION_CLASS.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/kernel32/Interop.FileOperations.cs delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/Resources/CoreFx.Private.TestUtilities.rd.xml delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AdminHelpers.Unix.cs delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AdminHelpers.Windows.cs delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AdminHelpers.cs delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Net/PlatformDetection.Networking.cs delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.NetFx.cs delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.NonNetFx.cs delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.Unix.cs delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.Windows.cs delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.cs delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/TestEnvironment.cs delete mode 100644 src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/TheoryExtensions.cs rename src/Microsoft.Data.SqlClient/tests/tools/{CoreFx.Private.TestUtilities/System => Microsoft.DotNet.XUnitExtensions/Extensions}/AssertExtensions.cs (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSid.cs => tests/tools/Microsoft.DotNet.XUnitExtensions/Extensions/PlatformDetection.cs} (52%) diff --git a/src/Microsoft.Data.SqlClient.sln b/src/Microsoft.Data.SqlClient.sln index 9077063825..d9a372c48c 100644 --- a/src/Microsoft.Data.SqlClient.sln +++ b/src/Microsoft.Data.SqlClient.sln @@ -15,11 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TDS", "Microsoft.Data.SqlCl {FDA6971D-9F57-4DA4-B10A-261C91684CFC} = {FDA6971D-9F57-4DA4-B10A-261C91684CFC} EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoreFx.Private.TestUtilities", "Microsoft.Data.SqlClient\tests\tools\CoreFx.Private.TestUtilities\CoreFx.Private.TestUtilities.csproj", "{EBDB0247-CA43-4226-B7A1-8FEF21061D09}" - ProjectSection(ProjectDependencies) = postProject - {FDA6971D-9F57-4DA4-B10A-261C91684CFC} = {FDA6971D-9F57-4DA4-B10A-261C91684CFC} - EndProjectSection -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.SqlClient.Tests", "Microsoft.Data.SqlClient\tests\FunctionalTests\Microsoft.Data.SqlClient.Tests.csproj", "{D2D1E2D1-B6E0-489F-A36D-1F3047AB87B9}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.SqlClient", "Microsoft.Data.SqlClient\netcore\src\Microsoft.Data.SqlClient.csproj", "{37431336-5307-4184-9356-C4B7E47DC714}" @@ -386,54 +381,6 @@ Global {8DC9D1A0-351B-47BC-A90F-B9DA542550E9}.Release|x64.Build.0 = Release|Any CPU {8DC9D1A0-351B-47BC-A90F-B9DA542550E9}.Release|x86.ActiveCfg = Release|Any CPU {8DC9D1A0-351B-47BC-A90F-B9DA542550E9}.Release|x86.Build.0 = Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Debug|x64.ActiveCfg = Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Debug|x64.Build.0 = Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Debug|x86.ActiveCfg = Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Debug|x86.Build.0 = Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.net46-Debug|Any CPU.ActiveCfg = net46-Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.net46-Debug|Any CPU.Build.0 = net46-Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.net46-Debug|x64.ActiveCfg = net46-Debug|x64 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.net46-Debug|x64.Build.0 = net46-Debug|x64 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.net46-Debug|x86.ActiveCfg = net46-Debug|x86 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.net46-Debug|x86.Build.0 = net46-Debug|x86 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.net46-Release|Any CPU.ActiveCfg = net46-Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.net46-Release|Any CPU.Build.0 = net46-Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.net46-Release|x64.ActiveCfg = net46-Release|x64 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.net46-Release|x64.Build.0 = net46-Release|x64 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.net46-Release|x86.ActiveCfg = net46-Release|x86 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.net46-Release|x86.Build.0 = net46-Release|x86 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp2.1-Debug|Any CPU.ActiveCfg = netcoreapp2.1-Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp2.1-Debug|Any CPU.Build.0 = netcoreapp2.1-Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp2.1-Debug|x64.ActiveCfg = netcoreapp2.1-Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp2.1-Debug|x64.Build.0 = netcoreapp2.1-Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp2.1-Debug|x86.ActiveCfg = netcoreapp2.1-Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp2.1-Debug|x86.Build.0 = netcoreapp2.1-Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp2.1-Release|Any CPU.ActiveCfg = netcoreapp2.1-Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp2.1-Release|Any CPU.Build.0 = netcoreapp2.1-Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp2.1-Release|x64.ActiveCfg = netcoreapp2.1-Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp2.1-Release|x64.Build.0 = netcoreapp2.1-Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp2.1-Release|x86.ActiveCfg = netcoreapp2.1-Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp2.1-Release|x86.Build.0 = netcoreapp2.1-Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp3.1-Debug|Any CPU.ActiveCfg = netcoreapp3.1-Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp3.1-Debug|Any CPU.Build.0 = netcoreapp3.1-Debug|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp3.1-Debug|x64.ActiveCfg = netcoreapp3.1-Debug|x64 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp3.1-Debug|x64.Build.0 = netcoreapp3.1-Debug|x64 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp3.1-Debug|x86.ActiveCfg = netcoreapp3.1-Debug|x86 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp3.1-Debug|x86.Build.0 = netcoreapp3.1-Debug|x86 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp3.1-Release|Any CPU.ActiveCfg = netcoreapp3.1-Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp3.1-Release|Any CPU.Build.0 = netcoreapp3.1-Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp3.1-Release|x64.ActiveCfg = netcoreapp3.1-Release|x64 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp3.1-Release|x64.Build.0 = netcoreapp3.1-Release|x64 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp3.1-Release|x86.ActiveCfg = netcoreapp3.1-Release|x86 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.netcoreapp3.1-Release|x86.Build.0 = netcoreapp3.1-Release|x86 - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Release|Any CPU.Build.0 = Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Release|x64.ActiveCfg = Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Release|x64.Build.0 = Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Release|x86.ActiveCfg = Release|Any CPU - {EBDB0247-CA43-4226-B7A1-8FEF21061D09}.Release|x86.Build.0 = Release|Any CPU {D2D1E2D1-B6E0-489F-A36D-1F3047AB87B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D2D1E2D1-B6E0-489F-A36D-1F3047AB87B9}.Debug|Any CPU.Build.0 = Debug|Any CPU {D2D1E2D1-B6E0-489F-A36D-1F3047AB87B9}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -1093,7 +1040,6 @@ Global {1FF891B4-D3DE-4CCE-887C-CB48F5351A45} = {0CC4817A-12F3-4357-912C-09315FAAD008} {978063D3-FBB5-4E10-8C45-67C90BE1B931} = {0CC4817A-12F3-4357-912C-09315FAAD008} {8DC9D1A0-351B-47BC-A90F-B9DA542550E9} = {0CC4817A-12F3-4357-912C-09315FAAD008} - {EBDB0247-CA43-4226-B7A1-8FEF21061D09} = {0CC4817A-12F3-4357-912C-09315FAAD008} {D2D1E2D1-B6E0-489F-A36D-1F3047AB87B9} = {0CC4817A-12F3-4357-912C-09315FAAD008} {37431336-5307-4184-9356-C4B7E47DC714} = {28E5EFE6-C9DD-4FF9-9FEC-532F72DFFA6E} {D1392B54-998A-4F27-BC17-4CE149117BCC} = {0CC4817A-12F3-4357-912C-09315FAAD008} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/Interop.Errors.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/Interop.Errors.cs deleted file mode 100644 index 9cb05809db..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/Interop.Errors.cs +++ /dev/null @@ -1,209 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - /// Common Unix errno error codes. - internal enum Error - { - // These values were defined in src/Native/System.Native/fxerrno.h - // - // They compare against values obtained via Interop.Sys.GetLastError() not Marshal.GetLastWin32Error() - // which obtains the raw errno that varies between unixes. The strong typing as an enum is meant to - // prevent confusing the two. Casting to or from int is suspect. Use GetLastErrorInfo() if you need to - // correlate these to the underlying platform values or obtain the corresponding error message. - // - - SUCCESS = 0, - - E2BIG = 0x10001, // Argument list too long. - EACCES = 0x10002, // Permission denied. - EADDRINUSE = 0x10003, // Address in use. - EADDRNOTAVAIL = 0x10004, // Address not available. - EAFNOSUPPORT = 0x10005, // Address family not supported. - EAGAIN = 0x10006, // Resource unavailable, try again (same value as EWOULDBLOCK), - EALREADY = 0x10007, // Connection already in progress. - EBADF = 0x10008, // Bad file descriptor. - EBADMSG = 0x10009, // Bad message. - EBUSY = 0x1000A, // Device or resource busy. - ECANCELED = 0x1000B, // Operation canceled. - ECHILD = 0x1000C, // No child processes. - ECONNABORTED = 0x1000D, // Connection aborted. - ECONNREFUSED = 0x1000E, // Connection refused. - ECONNRESET = 0x1000F, // Connection reset. - EDEADLK = 0x10010, // Resource deadlock would occur. - EDESTADDRREQ = 0x10011, // Destination address required. - EDOM = 0x10012, // Mathematics argument out of domain of function. - EDQUOT = 0x10013, // Reserved. - EEXIST = 0x10014, // File exists. - EFAULT = 0x10015, // Bad address. - EFBIG = 0x10016, // File too large. - EHOSTUNREACH = 0x10017, // Host is unreachable. - EIDRM = 0x10018, // Identifier removed. - EILSEQ = 0x10019, // Illegal byte sequence. - EINPROGRESS = 0x1001A, // Operation in progress. - EINTR = 0x1001B, // Interrupted function. - EINVAL = 0x1001C, // Invalid argument. - EIO = 0x1001D, // I/O error. - EISCONN = 0x1001E, // Socket is connected. - EISDIR = 0x1001F, // Is a directory. - ELOOP = 0x10020, // Too many levels of symbolic links. - EMFILE = 0x10021, // File descriptor value too large. - EMLINK = 0x10022, // Too many links. - EMSGSIZE = 0x10023, // Message too large. - EMULTIHOP = 0x10024, // Reserved. - ENAMETOOLONG = 0x10025, // Filename too long. - ENETDOWN = 0x10026, // Network is down. - ENETRESET = 0x10027, // Connection aborted by network. - ENETUNREACH = 0x10028, // Network unreachable. - ENFILE = 0x10029, // Too many files open in system. - ENOBUFS = 0x1002A, // No buffer space available. - ENODEV = 0x1002C, // No such device. - ENOENT = 0x1002D, // No such file or directory. - ENOEXEC = 0x1002E, // Executable file format error. - ENOLCK = 0x1002F, // No locks available. - ENOLINK = 0x10030, // Reserved. - ENOMEM = 0x10031, // Not enough space. - ENOMSG = 0x10032, // No message of the desired type. - ENOPROTOOPT = 0x10033, // Protocol not available. - ENOSPC = 0x10034, // No space left on device. - ENOSYS = 0x10037, // Function not supported. - ENOTCONN = 0x10038, // The socket is not connected. - ENOTDIR = 0x10039, // Not a directory or a symbolic link to a directory. - ENOTEMPTY = 0x1003A, // Directory not empty. - ENOTRECOVERABLE = 0x1003B, // State not recoverable. - ENOTSOCK = 0x1003C, // Not a socket. - ENOTSUP = 0x1003D, // Not supported (same value as EOPNOTSUP). - ENOTTY = 0x1003E, // Inappropriate I/O control operation. - ENXIO = 0x1003F, // No such device or address. - EOVERFLOW = 0x10040, // Value too large to be stored in data type. - EOWNERDEAD = 0x10041, // Previous owner died. - EPERM = 0x10042, // Operation not permitted. - EPIPE = 0x10043, // Broken pipe. - EPROTO = 0x10044, // Protocol error. - EPROTONOSUPPORT = 0x10045, // Protocol not supported. - EPROTOTYPE = 0x10046, // Protocol wrong type for socket. - ERANGE = 0x10047, // Result too large. - EROFS = 0x10048, // Read-only file system. - ESPIPE = 0x10049, // Invalid seek. - ESRCH = 0x1004A, // No such process. - ESTALE = 0x1004B, // Reserved. - ETIMEDOUT = 0x1004D, // Connection timed out. - ETXTBSY = 0x1004E, // Text file busy. - EXDEV = 0x1004F, // Cross-device link. - ESOCKTNOSUPPORT = 0x1005E, // Socket type not supported. - EPFNOSUPPORT = 0x10060, // Protocol family not supported. - ESHUTDOWN = 0x1006C, // Socket shutdown. - EHOSTDOWN = 0x10070, // Host is down. - ENODATA = 0x10071, // No data available. - - // POSIX permits these to have the same value and we make them always equal so - // that CoreFX cannot introduce a dependency on distinguishing between them that - // would not work on all platforms. - EOPNOTSUPP = ENOTSUP, // Operation not supported on socket. - EWOULDBLOCK = EAGAIN, // Operation would block. - } - - - // Represents a platform-agnostic Error and underlying platform-specific errno - internal struct ErrorInfo - { - private Error _error; - private int _rawErrno; - - internal ErrorInfo(int errno) - { - _error = Interop.Sys.ConvertErrorPlatformToPal(errno); - _rawErrno = errno; - } - - internal ErrorInfo(Error error) - { - _error = error; - _rawErrno = -1; - } - - internal Error Error - { - get { return _error; } - } - - internal int RawErrno - { - get { return _rawErrno == -1 ? (_rawErrno = Interop.Sys.ConvertErrorPalToPlatform(_error)) : _rawErrno; } - } - - internal string GetErrorMessage() - { - return Interop.Sys.StrError(RawErrno); - } - - public override string ToString() - { - return string.Format( - "RawErrno: {0} Error: {1} GetErrorMessage: {2}", // No localization required; text is member names used for debugging purposes - RawErrno, Error, GetErrorMessage()); - } - } - - internal partial class Sys - { - internal static Error GetLastError() - { - return ConvertErrorPlatformToPal(Marshal.GetLastWin32Error()); - } - - internal static ErrorInfo GetLastErrorInfo() - { - return new ErrorInfo(Marshal.GetLastWin32Error()); - } - - internal static unsafe string StrError(int platformErrno) - { - int maxBufferLength = 1024; // should be long enough for most any UNIX error - byte* buffer = stackalloc byte[maxBufferLength]; - byte* message = StrErrorR(platformErrno, buffer, maxBufferLength); - - if (message == null) - { - // This means the buffer was not large enough, but still contains - // as much of the error message as possible and is guaranteed to - // be null-terminated. We're not currently resizing/retrying because - // maxBufferLength is large enough in practice, but we could do - // so here in the future if necessary. - message = buffer; - } - - return Marshal.PtrToStringAnsi((IntPtr)message); - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ConvertErrorPlatformToPal")] - internal static extern Error ConvertErrorPlatformToPal(int platformErrno); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ConvertErrorPalToPlatform")] - internal static extern int ConvertErrorPalToPlatform(Error error); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_StrErrorR")] - private static extern unsafe byte* StrErrorR(int platformErrno, byte* buffer, int bufferSize); - } -} - -// NOTE: extension method can't be nested inside Interop class. -internal static class InteropErrorExtensions -{ - // Intended usage is e.g. Interop.Error.EFAIL.Info() for brevity - // vs. new Interop.ErrorInfo(Interop.Error.EFAIL) for synthesizing - // errors. Errors originated from the system should be obtained - // via GetLastErrorInfo(), not GetLastError().Info() as that will - // convert twice, which is not only inefficient but also lossy if - // we ever encounter a raw errno that no equivalent in the Error - // enum. - public static Interop.ErrorInfo Info(this Interop.Error error) - { - return new Interop.ErrorInfo(error); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/Interop.IOErrors.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/Interop.IOErrors.cs deleted file mode 100644 index 5babcd1d05..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/Interop.IOErrors.cs +++ /dev/null @@ -1,172 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.IO; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - private static void ThrowExceptionForIoErrno(ErrorInfo errorInfo, string path, bool isDirectory, Func errorRewriter) - { - Debug.Assert(errorInfo.Error != Error.SUCCESS); - Debug.Assert(errorInfo.Error != Error.EINTR, "EINTR errors should be handled by the native shim and never bubble up to managed code"); - - if (errorRewriter != null) - { - errorInfo = errorRewriter(errorInfo); - } - - throw Interop.GetExceptionForIoErrno(errorInfo, path, isDirectory); - } - - internal static void CheckIo(Error error, string path = null, bool isDirectory = false, Func errorRewriter = null) - { - if (error != Interop.Error.SUCCESS) - { - ThrowExceptionForIoErrno(error.Info(), path, isDirectory, errorRewriter); - } - } - - /// - /// Validates the result of system call that returns greater than or equal to 0 on success - /// and less than 0 on failure, with errno set to the error code. - /// If the system call failed for any reason, an exception is thrown. Otherwise, the system call succeeded. - /// - /// The result of the system call. - /// The path with which this error is associated. This may be null. - /// true if the is known to be a directory; otherwise, false. - /// Optional function to change an error code prior to processing it. - /// - /// On success, returns the non-negative result long that was validated. - /// - internal static long CheckIo(long result, string path = null, bool isDirectory = false, Func errorRewriter = null) - { - if (result < 0) - { - ThrowExceptionForIoErrno(Sys.GetLastErrorInfo(), path, isDirectory, errorRewriter); - } - - return result; - } - - /// - /// Validates the result of system call that returns greater than or equal to 0 on success - /// and less than 0 on failure, with errno set to the error code. - /// If the system call failed for any reason, an exception is thrown. Otherwise, the system call succeeded. - /// - /// - /// On success, returns the non-negative result int that was validated. - /// - internal static int CheckIo(int result, string path = null, bool isDirectory = false, Func errorRewriter = null) - { - CheckIo((long)result, path, isDirectory, errorRewriter); - - return result; - } - - /// - /// Validates the result of system call that returns greater than or equal to 0 on success - /// and less than 0 on failure, with errno set to the error code. - /// If the system call failed for any reason, an exception is thrown. Otherwise, the system call succeeded. - /// - /// - /// On success, returns the non-negative result IntPtr that was validated. - /// - internal static IntPtr CheckIo(IntPtr result, string path = null, bool isDirectory = false, Func errorRewriter = null) - { - CheckIo((long)result, path, isDirectory, errorRewriter); - - return result; - } - - /// - /// Validates the result of system call that returns greater than or equal to 0 on success - /// and less than 0 on failure, with errno set to the error code. - /// If the system call failed for any reason, an exception is thrown. Otherwise, the system call succeeded. - /// - /// - /// On success, returns the valid SafeFileHandle that was validated. - /// - internal static TSafeHandle CheckIo(TSafeHandle handle, string path = null, bool isDirectory = false, Func errorRewriter = null) - where TSafeHandle : SafeHandle - { - if (handle.IsInvalid) - { - ThrowExceptionForIoErrno(Sys.GetLastErrorInfo(), path, isDirectory, errorRewriter); - } - - return handle; - } - - /// - /// Gets an Exception to represent the supplied error info. - /// - /// The error info - /// The path with which this error is associated. This may be null. - /// true if the is known to be a directory; otherwise, false. - /// - internal static Exception GetExceptionForIoErrno(ErrorInfo errorInfo, string path = null, bool isDirectory = false) - { - // Translate the errno into a known set of exception types. For cases where multiple errnos map - // to the same exception type, include an inner exception with the details. - switch (errorInfo.Error) - { - case Error.ENOENT: - if (isDirectory) - { - return !string.IsNullOrEmpty(path) ? - new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, path)) : - new DirectoryNotFoundException(SR.IO_PathNotFound_NoPathName); - } - else - { - return !string.IsNullOrEmpty(path) ? - new FileNotFoundException(SR.Format(SR.IO_FileNotFound_FileName, path), path) : - new FileNotFoundException(SR.IO_FileNotFound); - } - - case Error.EACCES: - case Error.EBADF: - case Error.EPERM: - Exception inner = GetIOException(errorInfo); - return !string.IsNullOrEmpty(path) ? - new UnauthorizedAccessException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, path), inner) : - new UnauthorizedAccessException(SR.UnauthorizedAccess_IODenied_NoPathName, inner); - - case Error.ENAMETOOLONG: - return !string.IsNullOrEmpty(path) ? - new PathTooLongException(SR.Format(SR.IO_PathTooLong_Path, path)) : - new PathTooLongException(SR.IO_PathTooLong); - - case Error.EWOULDBLOCK: - return !string.IsNullOrEmpty(path) ? - new IOException(SR.Format(SR.IO_SharingViolation_File, path), errorInfo.RawErrno) : - new IOException(SR.IO_SharingViolation_NoFileName, errorInfo.RawErrno); - - case Error.ECANCELED: - return new OperationCanceledException(); - - case Error.EFBIG: - return new ArgumentOutOfRangeException("value", SR.ArgumentOutOfRange_FileLengthTooBig); - - case Error.EEXIST: - if (!string.IsNullOrEmpty(path)) - { - return new IOException(SR.Format(SR.IO_FileExists_Name, path), errorInfo.RawErrno); - } - goto default; - - default: - return GetIOException(errorInfo); - } - } - - internal static Exception GetIOException(Interop.ErrorInfo errorInfo) - { - return new IOException(errorInfo.GetErrorMessage(), errorInfo.RawErrno); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/Interop.Libraries.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/Interop.Libraries.cs deleted file mode 100644 index 02d0092445..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/Interop.Libraries.cs +++ /dev/null @@ -1,12 +0,0 @@ -// 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. - -internal static partial class Interop -{ - internal static partial class Libraries - { - internal const string GlobalizationNative = "System.Globalization.Native"; - internal const string SystemNative = "System.Native"; - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs deleted file mode 100644 index 55553cc7ea..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Calendar.cs +++ /dev/null @@ -1,33 +0,0 @@ -// 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. - -using System; -using System.Globalization; -using System.Runtime.InteropServices; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Globalization - { - internal delegate void EnumCalendarInfoCallback( - [MarshalAs(UnmanagedType.LPWStr)] string calendarString, - IntPtr context); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendars")] - internal static extern int GetCalendars(string localeName, CalendarId[] calendars, int calendarsCapacity); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendarInfo")] - internal static extern ResultCode GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType calendarDataType, [Out] StringBuilder result, int resultCapacity); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EnumCalendarInfo")] - internal static extern bool EnumCalendarInfo(EnumCalendarInfoCallback callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context); - - [DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLatestJapaneseEra")] - internal static extern int GetLatestJapaneseEra(); - - [DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetJapaneseEraStartDate")] - internal static extern bool GetJapaneseEraStartDate(int era, out int startYear, out int startMonth, out int startDay); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Casing.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Casing.cs deleted file mode 100644 index 503a864d69..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Casing.cs +++ /dev/null @@ -1,23 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Security; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Globalization - { - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCase")] - internal static extern unsafe void ChangeCase(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseInvariant")] - internal static extern unsafe void ChangeCaseInvariant(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ChangeCaseTurkish")] - internal static extern unsafe void ChangeCaseTurkish(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Collation.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Collation.cs deleted file mode 100644 index aeeb60ff77..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Collation.cs +++ /dev/null @@ -1,79 +0,0 @@ -// 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. - -using System; -using System.Globalization; -using System.Runtime.InteropServices; -using System.Security; - -internal static partial class Interop -{ - internal static partial class Globalization - { - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetSortHandle")] - internal static extern unsafe ResultCode GetSortHandle(byte[] localeName, out SafeSortHandle sortHandle); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CloseSortHandle")] - internal static extern unsafe void CloseSortHandle(IntPtr handle); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CompareString")] - internal static extern unsafe int CompareString(SafeSortHandle sortHandle, char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len, CompareOptions options); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOf")] - internal static extern unsafe int IndexOf(SafeSortHandle sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options, int* matchLengthPtr); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_LastIndexOf")] - internal static extern unsafe int LastIndexOf(SafeSortHandle sortHandle, char* target, int cwTargetLength, char* pSource, int cwSourceLength, CompareOptions options); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOfOrdinalIgnoreCase")] - internal static extern unsafe int IndexOfOrdinalIgnoreCase(string target, int cwTargetLength, char* pSource, int cwSourceLength, bool findLast); - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IndexOfOrdinalIgnoreCase")] - internal static extern unsafe int IndexOfOrdinalIgnoreCase(char* target, int cwTargetLength, char* pSource, int cwSourceLength, bool findLast); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_StartsWith")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool StartsWith(SafeSortHandle sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EndsWith")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool EndsWith(SafeSortHandle sortHandle, char* target, int cwTargetLength, char* source, int cwSourceLength, CompareOptions options); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_StartsWith")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool StartsWith(SafeSortHandle sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EndsWith")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool EndsWith(SafeSortHandle sortHandle, string target, int cwTargetLength, string source, int cwSourceLength, CompareOptions options); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetSortKey")] - internal static extern unsafe int GetSortKey(SafeSortHandle sortHandle, string str, int strLength, byte* sortKey, int sortKeyLength, CompareOptions options); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_CompareStringOrdinalIgnoreCase")] - internal static extern unsafe int CompareStringOrdinalIgnoreCase(char* lpStr1, int cwStr1Len, char* lpStr2, int cwStr2Len); - - [DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetSortVersion")] - internal static extern int GetSortVersion(SafeSortHandle sortHandle); - - internal class SafeSortHandle : SafeHandle - { - private SafeSortHandle() : - base(IntPtr.Zero, true) - { - } - - public override bool IsInvalid - { - get { return handle == IntPtr.Zero; } - } - - protected override bool ReleaseHandle() - { - CloseSortHandle(handle); - SetHandle(IntPtr.Zero); - return true; - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.ICU.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.ICU.cs deleted file mode 100644 index a16c813b2f..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.ICU.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Runtime.CompilerServices; - -internal static partial class Interop -{ - internal static partial class Globalization - { - [DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_LoadICU")] - internal static extern int LoadICU(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Idna.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Idna.cs deleted file mode 100644 index 89b6c3cebe..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Idna.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Globalization - { - internal const int AllowUnassigned = 0x1; - internal const int UseStd3AsciiRules = 0x2; - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToAscii")] - internal static extern unsafe int ToAscii(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_ToUnicode")] - internal static extern unsafe int ToUnicode(uint flags, char* src, int srcLen, char* dstBuffer, int dstBufferCapacity); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Locale.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Locale.cs deleted file mode 100644 index b6f5fbec1c..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Locale.cs +++ /dev/null @@ -1,40 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Globalization - { - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleName")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool GetLocaleName(string localeName, [Out] StringBuilder value, int valueLength); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoString")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool GetLocaleInfoString(string localeName, uint localeStringData, [Out] StringBuilder value, int valueLength); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetDefaultLocaleName")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool GetDefaultLocaleName([Out] StringBuilder value, int valueLength); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleTimeFormat")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool GetLocaleTimeFormat(string localeName, bool shortFormat, [Out] StringBuilder value, int valueLength); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoInt")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool GetLocaleInfoInt(string localeName, uint localeNumberData, ref int value); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocaleInfoGroupingSizes")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool GetLocaleInfoGroupingSizes(string localeName, uint localeGroupingData, ref int primaryGroupSize, ref int secondaryGroupSize); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetLocales")] - internal static extern unsafe int GetLocales([Out] char[] value, int valueLength); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs deleted file mode 100644 index d442da0ea1..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Normalization.cs +++ /dev/null @@ -1,19 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Globalization - { - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_IsNormalized")] - internal static extern int IsNormalized(NormalizationForm normalizationForm, string src, int srcLen); - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_NormalizeString")] - internal static extern int NormalizeString(NormalizationForm normalizationForm, string src, int srcLen, [Out] char[] dstBuffer, int dstBufferCapacity); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs deleted file mode 100644 index 4a9933f929..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.ResultCode.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - -internal static partial class Interop -{ - internal static partial class Globalization - { - // needs to be kept in sync with ResultCode in System.Globalization.Native - internal enum ResultCode - { - Success = 0, - UnknownError = 1, - InsufficentBuffer = 2, - OutOfMemory = 3 - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs deleted file mode 100644 index 47cf26662b..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.TimeZoneInfo.cs +++ /dev/null @@ -1,28 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Globalization - { - // needs to be kept in sync with TimeZoneDisplayNameType in System.Globalization.Native - internal enum TimeZoneDisplayNameType - { - Generic = 0, - Standard = 1, - DaylightSavings = 2, - } - - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetTimeZoneDisplayName")] - internal static extern ResultCode GetTimeZoneDisplayName( - string localeName, - string timeZoneId, - TimeZoneDisplayNameType type, - [Out] StringBuilder result, - int resultLength); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Utils.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Utils.cs deleted file mode 100644 index 9887bd4f0b..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Globalization.Native/Interop.Utils.cs +++ /dev/null @@ -1,52 +0,0 @@ -// 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. - -using System; -using System.Text; - -internal static partial class Interop -{ - /// - /// Helper for making interop calls that return a string, but we don't know - /// the correct size of buffer to make. So invoke the interop call with an - /// increasing buffer until the size is big enough. - /// - internal static bool CallStringMethod( - Func interopCall, - TArg1 arg1, - TArg2 arg2, - TArg3 arg3, - out string result) - { - const int initialStringSize = 80; - const int maxDoubleAttempts = 5; - - StringBuilder stringBuilder = StringBuilderCache.Acquire(initialStringSize); - - for (int i = 0; i < maxDoubleAttempts; i++) - { - Interop.Globalization.ResultCode resultCode = interopCall(arg1, arg2, arg3, stringBuilder); - - if (resultCode == Interop.Globalization.ResultCode.Success) - { - result = StringBuilderCache.GetStringAndRelease(stringBuilder); - return true; - } - else if (resultCode == Interop.Globalization.ResultCode.InsufficentBuffer) - { - // increase the string size and loop - stringBuilder.EnsureCapacity(stringBuilder.Capacity * 2); - } - else - { - // if there is an unknown error, don't proceed - break; - } - } - - StringBuilderCache.Release(stringBuilder); - result = null; - return false; - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Close.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Close.cs deleted file mode 100644 index 8d192398a0..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Close.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Close", SetLastError = true)] - internal static extern int Close(IntPtr fd); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.FLock.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.FLock.cs deleted file mode 100644 index 22934a3e77..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.FLock.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal enum LockOperations : int - { - LOCK_SH = 1, /* shared lock */ - LOCK_EX = 2, /* exclusive lock */ - LOCK_NB = 4, /* don't block when locking*/ - LOCK_UN = 8, /* unlock */ - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FLock", SetLastError = true)] - internal static extern int FLock(SafeFileHandle fd, LockOperations operation); - - /// - /// Exposing this for SafeFileHandle.ReleaseHandle() to call. - /// Normal callers should use FLock(SafeFileHandle fd). - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FLock", SetLastError = true)] - internal static extern int FLock(IntPtr fd, LockOperations operation); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.FSync.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.FSync.cs deleted file mode 100644 index e3ab970931..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.FSync.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FSync", SetLastError = true)] - internal static extern int FSync(SafeFileHandle fd); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.FTruncate.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.FTruncate.cs deleted file mode 100644 index 5dad650362..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.FTruncate.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FTruncate", SetLastError = true)] - internal static extern int FTruncate(SafeFileHandle fd, long length); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.GetCwd.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.GetCwd.cs deleted file mode 100644 index a8bef6bde8..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.GetCwd.cs +++ /dev/null @@ -1,74 +0,0 @@ -// 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. - -using System; -using System.Buffers; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetCwd", SetLastError = true)] - private static extern unsafe byte* GetCwd(byte* buffer, int bufferLength); - - internal static unsafe string GetCwd() - { - const int StackLimit = 256; - - // First try to get the path into a buffer on the stack - byte* stackBuf = stackalloc byte[StackLimit]; - string result = GetCwdHelper(stackBuf, StackLimit); - if (result != null) - { - return result; - } - - // If that was too small, try increasing large buffer sizes - int bufferSize = StackLimit; - do - { - checked { bufferSize *= 2; } - byte[] buf = ArrayPool.Shared.Rent(bufferSize); - try - { - fixed (byte* ptr = &buf[0]) - { - result = GetCwdHelper(ptr, buf.Length); - if (result != null) - { - return result; - } - } - } - finally - { - ArrayPool.Shared.Return(buf); - } - } - while (true); - } - - private static unsafe string GetCwdHelper(byte* ptr, int bufferSize) - { - // Call the real getcwd - byte* result = GetCwd(ptr, bufferSize); - - // If it returned non-null, the null-terminated path is in the buffer - if (result != null) - { - return Marshal.PtrToStringAnsi((IntPtr)ptr); - } - - // Otherwise, if it failed due to the buffer being too small, return null; - // for anything else, throw. - ErrorInfo errorInfo = Interop.Sys.GetLastErrorInfo(); - if (errorInfo.Error == Interop.Error.ERANGE) - { - return null; - } - throw Interop.GetExceptionForIoErrno(errorInfo); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.GetRandomBytes.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.GetRandomBytes.cs deleted file mode 100644 index e911b13583..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.GetRandomBytes.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; - -internal partial class Interop -{ - internal unsafe partial class Sys - { - [DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_GetNonCryptographicallySecureRandomBytes")] - internal static extern unsafe void GetNonCryptographicallySecureRandomBytes(byte* buffer, int length); - } - - internal static unsafe void GetRandomBytes(byte* buffer, int length) - { - Sys.GetNonCryptographicallySecureRandomBytes(buffer, length); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.LSeek.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.LSeek.cs deleted file mode 100644 index 7f8df7c6bf..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.LSeek.cs +++ /dev/null @@ -1,22 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal enum SeekWhence - { - SEEK_SET = 0, - SEEK_CUR = 1, - SEEK_END = 2 - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LSeek", SetLastError = true)] - internal static extern long LSeek(SafeFileHandle fd, long offset, SeekWhence whence); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.LockFileRegion.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.LockFileRegion.cs deleted file mode 100644 index 23b48a4f5d..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.LockFileRegion.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal enum LockType : short - { - F_WRLCK = 1, // exclusive or write lock - F_UNLCK = 2 // unlock - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LockFileRegion", SetLastError=true)] - internal static extern int LockFileRegion(SafeHandle fd, long offset, long length, LockType lockType); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.MksTemps.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.MksTemps.cs deleted file mode 100644 index b8694d9007..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.MksTemps.cs +++ /dev/null @@ -1,17 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_MksTemps", SetLastError = true)] - internal static extern IntPtr MksTemps( - byte[] template, - int suffixlen); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Open.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Open.cs deleted file mode 100644 index a9a994c78c..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Open.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Open", SetLastError = true)] - internal static extern SafeFileHandle Open(string filename, OpenFlags flags, int mode); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.OpenFlags.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.OpenFlags.cs deleted file mode 100644 index f9e54c3cbc..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.OpenFlags.cs +++ /dev/null @@ -1,27 +0,0 @@ -// 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. - -using System; - -internal static partial class Interop -{ - internal static partial class Sys - { - [Flags] - internal enum OpenFlags - { - // Access modes (mutually exclusive) - O_RDONLY = 0x0000, - O_WRONLY = 0x0001, - O_RDWR = 0x0002, - - // Flags (combinable) - O_CLOEXEC = 0x0010, - O_CREAT = 0x0020, - O_EXCL = 0x0040, - O_TRUNC = 0x0080, - O_SYNC = 0x0100, - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.PathConf.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.PathConf.cs deleted file mode 100644 index 7213cb0264..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.PathConf.cs +++ /dev/null @@ -1,28 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal enum PathConfName : int - { - PC_LINK_MAX = 1, - PC_MAX_CANON = 2, - PC_MAX_INPUT = 3, - PC_NAME_MAX = 4, - PC_PATH_MAX = 5, - PC_PIPE_BUF = 6, - PC_CHOWN_RESTRICTED = 7, - PC_NO_TRUNC = 8, - PC_VDISABLE = 9, - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PathConf", SetLastError = true)] - private static extern int PathConf(string path, PathConfName name); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Permissions.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Permissions.cs deleted file mode 100644 index f1d13787d2..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Permissions.cs +++ /dev/null @@ -1,32 +0,0 @@ -// 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. - -using System; - -internal static partial class Interop -{ - internal static partial class Sys - { - [Flags] - internal enum Permissions - { - Mask = S_IRWXU | S_IRWXG | S_IRWXO, - - S_IRWXU = S_IRUSR | S_IWUSR | S_IXUSR, - S_IRUSR = 0x100, - S_IWUSR = 0x80, - S_IXUSR = 0x40, - - S_IRWXG = S_IRGRP | S_IWGRP | S_IXGRP, - S_IRGRP = 0x20, - S_IWGRP = 0x10, - S_IXGRP = 0x8, - - S_IRWXO = S_IROTH | S_IWOTH | S_IXOTH, - S_IROTH = 0x4, - S_IWOTH = 0x2, - S_IXOTH = 0x1, - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.PosixFAdvise.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.PosixFAdvise.cs deleted file mode 100644 index ad8b73aed2..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.PosixFAdvise.cs +++ /dev/null @@ -1,36 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal enum FileAdvice : int - { - POSIX_FADV_NORMAL = 0, /* no special advice, the default value */ - POSIX_FADV_RANDOM = 1, /* random I/O access */ - POSIX_FADV_SEQUENTIAL = 2, /* sequential I/O access */ - POSIX_FADV_WILLNEED = 3, /* will need specified pages */ - POSIX_FADV_DONTNEED = 4, /* don't need the specified pages */ - POSIX_FADV_NOREUSE = 5, /* data will only be accessed once */ - } - - /// - /// Notifies the OS kernel that the specified file will be accessed in a particular way soon; this allows the kernel to - /// potentially optimize the access pattern of the file. - /// - /// The file descriptor of the file - /// The start of the region to advise about - /// The number of bytes of the region (until the end of the file if 0) - /// The type of advice to give the kernel about the specified region - /// - /// Returns 0 on success; otherwise, the error code is returned - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PosixFAdvise", SetLastError = false /* this is explicitly called out in the man page */)] - internal static extern int PosixFAdvise(SafeFileHandle fd, long offset, long length, FileAdvice advice); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Read.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Read.cs deleted file mode 100644 index 1be5e789c2..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Read.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - /// - /// Reads a number of bytes from an open file descriptor into a specified buffer. - /// - /// The open file descriptor to try to read from - /// The buffer to read info into - /// The size of the buffer - /// - /// Returns the number of bytes read on success; otherwise, -1 is returned - /// Note - on fail. the position of the stream may change depending on the platform; consult man 2 read for more info - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Read", SetLastError = true)] - internal static extern unsafe int Read(SafeFileHandle fd, byte* buffer, int count); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.ReadDir.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.ReadDir.cs deleted file mode 100644 index d98c4285c0..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.ReadDir.cs +++ /dev/null @@ -1,102 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Threading; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - private static readonly int s_readBufferSize = GetReadDirRBufferSize(); - - internal enum NodeType : int - { - DT_UNKNOWN = 0, - DT_FIFO = 1, - DT_CHR = 2, - DT_DIR = 4, - DT_BLK = 6, - DT_REG = 8, - DT_LNK = 10, - DT_SOCK = 12, - DT_WHT = 14 - } - - [StructLayout(LayoutKind.Sequential)] - private unsafe struct InternalDirectoryEntry - { - internal IntPtr Name; - internal int NameLength; - internal NodeType InodeType; - } - - internal struct DirectoryEntry - { - internal NodeType InodeType; - internal string InodeName; - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_OpenDir", SetLastError = true)] - internal static extern Microsoft.Win32.SafeHandles.SafeDirectoryHandle OpenDir(string path); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetReadDirRBufferSize", SetLastError = false)] - internal static extern int GetReadDirRBufferSize(); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadDirR", SetLastError = false)] - private static extern unsafe int ReadDirR(IntPtr dir, byte* buffer, int bufferSize, out InternalDirectoryEntry outputEntry); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CloseDir", SetLastError = true)] - internal static extern int CloseDir(IntPtr dir); - - // The calling pattern for ReadDir is described in src/Native/System.Native/pal_readdir.cpp - internal static int ReadDir(SafeDirectoryHandle dir, out DirectoryEntry outputEntry) - { - bool addedRef = false; - try - { - // We avoid a native string copy into InternalDirectoryEntry. - // - If the platform suppors reading into a buffer, the data is read directly into the buffer. The - // data can be read as long as the buffer is valid. - // - If the platform does not support reading into a buffer, the information returned in - // InternalDirectoryEntry points to native memory owned by the SafeDirectoryHandle. The data is only - // valid until the next call to CloseDir/ReadDir. We extend the reference until we have copied all data - // to ensure it does not become invalid by a CloseDir; and we copy the data so our caller does not - // use the native memory held by the SafeDirectoryHandle. - dir.DangerousAddRef(ref addedRef); - - unsafe - { - // s_readBufferSize is zero when the native implementation does not support reading into a buffer. - byte* buffer = stackalloc byte[s_readBufferSize]; - InternalDirectoryEntry temp; - int ret = ReadDirR(dir.DangerousGetHandle(), buffer, s_readBufferSize, out temp); - // We copy data into DirectoryEntry to ensure there are no dangling references. - outputEntry = ret == 0 ? - new DirectoryEntry() { InodeName = GetDirectoryEntryName(temp), InodeType = temp.InodeType } : - default(DirectoryEntry); - - return ret; - } - } - finally - { - if (addedRef) - { - dir.DangerousRelease(); - } - } - } - - private static unsafe string GetDirectoryEntryName(InternalDirectoryEntry dirEnt) - { - if (dirEnt.NameLength == -1) - return Marshal.PtrToStringAnsi(dirEnt.Name); - else - return Marshal.PtrToStringAnsi(dirEnt.Name, dirEnt.NameLength); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.ReadLink.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.ReadLink.cs deleted file mode 100644 index 50f1ae545e..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.ReadLink.cs +++ /dev/null @@ -1,63 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using System.Buffers; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Sys - { - /// - /// Takes a path to a symbolic link and attempts to place the link target path into the buffer. If the buffer is too - /// small, the path will be truncated. No matter what, the buffer will not be null terminated. - /// - /// The path to the symlink - /// The buffer to hold the output path - /// The size of the buffer - /// - /// Returns the number of bytes placed into the buffer on success; bufferSize if the buffer is too small; and -1 on error. - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadLink", SetLastError = true)] - private static extern unsafe int ReadLink(string path, byte[] buffer, int bufferSize); - - /// - /// Takes a path to a symbolic link and returns the link target path. - /// - /// The path to the symlink - /// - /// Returns the link to the target path on success; and null otherwise. - /// - public static string ReadLink(string path) - { - int bufferSize = 256; - do - { - byte[] buffer = ArrayPool.Shared.Rent(bufferSize); - try - { - int resultLength = Interop.Sys.ReadLink(path, buffer, buffer.Length); - if (resultLength < 0) - { - // error - return null; - } - else if (resultLength < buffer.Length) - { - // success - return Encoding.UTF8.GetString(buffer, 0, resultLength); - } - } - finally - { - ArrayPool.Shared.Return(buffer); - } - - // buffer was too small, loop around again and try with a larger buffer. - bufferSize *= 2; - } while (true); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Stat.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Stat.cs deleted file mode 100644 index 0ca199b70d..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Stat.cs +++ /dev/null @@ -1,65 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - // Even though csc will by default use a sequential layout, a CS0649 warning as error - // is produced for un-assigned fields when no StructLayout is specified. - // - // Explicitly saying Sequential disables that warning/error for consumers which only - // use Stat in debug builds. - [StructLayout(LayoutKind.Sequential)] - internal struct FileStatus - { - internal FileStatusFlags Flags; - internal int Mode; - internal uint Uid; - internal uint Gid; - internal long Size; - internal long ATime; - internal long ATimeNsec; - internal long MTime; - internal long MTimeNsec; - internal long CTime; - internal long CTimeNsec; - internal long BirthTime; - internal long BirthTimeNsec; - internal long Dev; - internal long Ino; - } - - internal static class FileTypes - { - internal const int S_IFMT = 0xF000; - internal const int S_IFIFO = 0x1000; - internal const int S_IFCHR = 0x2000; - internal const int S_IFDIR = 0x4000; - internal const int S_IFREG = 0x8000; - internal const int S_IFLNK = 0xA000; - internal const int S_IFSOCK = 0xC000; - } - - [Flags] - internal enum FileStatusFlags - { - None = 0, - HasBirthTime = 1, - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FStat2", SetLastError = true)] - internal static extern int FStat(SafeFileHandle fd, out FileStatus output); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Stat2", SetLastError = true)] - internal static extern int Stat(string path, out FileStatus output); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LStat2", SetLastError = true)] - internal static extern int LStat(string path, out FileStatus output); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.SysLog.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.SysLog.cs deleted file mode 100644 index 6b6a74b743..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.SysLog.cs +++ /dev/null @@ -1,58 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal enum SysLogPriority : int - { - // Priorities - LOG_EMERG = 0, /* system is unusable */ - LOG_ALERT = 1, /* action must be taken immediately */ - LOG_CRIT = 2, /* critical conditions */ - LOG_ERR = 3, /* error conditions */ - LOG_WARNING = 4, /* warning conditions */ - LOG_NOTICE = 5, /* normal but significant condition */ - LOG_INFO = 6, /* informational */ - LOG_DEBUG = 7, /* debug-level messages */ - // Facilities - LOG_KERN = (0<<3), /* kernel messages */ - LOG_USER = (1<<3), /* random user-level messages */ - LOG_MAIL = (2<<3), /* mail system */ - LOG_DAEMON = (3<<3), /* system daemons */ - LOG_AUTH = (4<<3), /* authorization messages */ - LOG_SYSLOG = (5<<3), /* messages generated internally by syslogd */ - LOG_LPR = (6<<3), /* line printer subsystem */ - LOG_NEWS = (7<<3), /* network news subsystem */ - LOG_UUCP = (8<<3), /* UUCP subsystem */ - LOG_CRON = (9<<3), /* clock daemon */ - LOG_AUTHPRIV = (10<<3), /* authorization messages (private) */ - LOG_FTP = (11<<3), /* ftp daemon */ - // Between FTP and Local is reserved for system use - LOG_LOCAL0 = (16<<3), /* reserved for local use */ - LOG_LOCAL1 = (17<<3), /* reserved for local use */ - LOG_LOCAL2 = (18<<3), /* reserved for local use */ - LOG_LOCAL3 = (19<<3), /* reserved for local use */ - LOG_LOCAL4 = (20<<3), /* reserved for local use */ - LOG_LOCAL5 = (21<<3), /* reserved for local use */ - LOG_LOCAL6 = (22<<3), /* reserved for local use */ - LOG_LOCAL7 = (23<<3), /* reserved for local use */ - } - - /// - /// Write a message to the system logger, which in turn writes the message to the system console, log files, etc. - /// See man 3 syslog for more info - /// - /// - /// The OR of a priority and facility in the SysLogPriority enum to declare the priority and facility of the log entry - /// - /// The message to put in the log entry - /// Like printf, the argument is passed to the variadic part of the C++ function to wildcards in the message - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SysLog")] - internal static extern void SysLog(SysLogPriority priority, string message, string arg1); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Unlink.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Unlink.cs deleted file mode 100644 index 829210fa7e..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Unlink.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Unlink", SetLastError = true)] - internal static extern int Unlink(string pathname); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Write.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Write.cs deleted file mode 100644 index 0636615a8b..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/CoreLib/Interop/Unix/System.Native/Interop.Write.cs +++ /dev/null @@ -1,27 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - /// - /// Writes the specified buffer to the provided open file descriptor - /// - /// The file descriptor to try and write to - /// The data to attempt to write - /// The amount of data to write, in bytes - /// - /// Returns the number of bytes written on success; otherwise, returns -1 and sets errno - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Write", SetLastError = true)] - internal static extern unsafe int Write(SafeFileHandle fd, byte* buffer, int bufferSize); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Write", SetLastError = true)] - internal static extern unsafe int Write(int fd, byte* buffer, int bufferSize); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Accept.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Accept.cs deleted file mode 100644 index b37883a358..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Accept.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Accept")] - internal static extern unsafe Error Accept(SafeHandle socket, byte* socketAddress, int* socketAddressLen, IntPtr* acceptedFd); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Access.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Access.cs deleted file mode 100644 index a723f572a5..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Access.cs +++ /dev/null @@ -1,23 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal enum AccessMode : int - { - F_OK = 0, /* Check for existence */ - X_OK = 1, /* Check for execute */ - W_OK = 2, /* Check for write */ - R_OK = 4, /* Check for read */ - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Access", SetLastError = true)] - internal static extern int Access(string path, AccessMode mode); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Bind.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Bind.cs deleted file mode 100644 index 03f68de856..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Bind.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Net.Sockets; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Bind")] - internal static extern unsafe Error Bind(SafeHandle socket, ProtocolType socketProtocolType, byte* socketAddress, int socketAddressLen); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ChDir.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ChDir.cs deleted file mode 100644 index 3c66995182..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ChDir.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ChDir", SetLastError = true)] - internal static extern int ChDir(string path); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ChMod.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ChMod.cs deleted file mode 100644 index 51381e2c2d..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ChMod.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ChMod", SetLastError = true)] - internal static extern int ChMod(string path, int mode); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Connect.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Connect.cs deleted file mode 100644 index 151b51e2f6..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Connect.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Connect")] - internal static extern unsafe Error Connect(SafeHandle socket, byte* socketAddress, int socketAddressLen); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.CopyFile.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.CopyFile.cs deleted file mode 100644 index f7035fcead..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.CopyFile.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using Microsoft.Win32.SafeHandles; -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CopyFile", SetLastError = true)] - internal static extern int CopyFile(SafeFileHandle source, SafeFileHandle destination); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Dup.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Dup.cs deleted file mode 100644 index 8ca2ad760d..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Dup.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Dup", SetLastError = true)] - internal static extern SafeFileHandle Dup(SafeFileHandle oldfd); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs deleted file mode 100644 index 1efe322f6f..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs +++ /dev/null @@ -1,45 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [StructLayout(LayoutKind.Sequential)] - public unsafe struct LinkLayerAddressInfo - { - public int InterfaceIndex; - public fixed byte AddressBytes[8]; - public byte NumAddressBytes; - private byte __padding; // For native struct-size padding. Does not contain useful data. - public ushort HardwareType; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe struct IpAddressInfo - { - public int InterfaceIndex; - public fixed byte AddressBytes[16]; - public byte NumAddressBytes; - private fixed byte __padding[3]; - } - - public unsafe delegate void IPv4AddressDiscoveredCallback(string ifaceName, IpAddressInfo* ipAddressInfo, IpAddressInfo* netMaskInfo); - public unsafe delegate void IPv6AddressDiscoveredCallback(string ifaceName, IpAddressInfo* ipAddressInfo, uint* scopeId); - public unsafe delegate void LinkLayerAddressDiscoveredCallback(string ifaceName, LinkLayerAddressInfo* llAddress); - public unsafe delegate void DnsAddessDiscoveredCallback(IpAddressInfo* gatewayAddress); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_EnumerateInterfaceAddresses")] - public static extern int EnumerateInterfaceAddresses( - IPv4AddressDiscoveredCallback ipv4Found, - IPv6AddressDiscoveredCallback ipv6Found, - LinkLayerAddressDiscoveredCallback linkLayerFound); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_EnumerateGatewayAddressesForInterface")] - public static extern int EnumerateGatewayAddressesForInterface(uint interfaceIndex, DnsAddessDiscoveredCallback onGatewayFound); - - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.FChMod.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.FChMod.cs deleted file mode 100644 index 161ac71d81..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.FChMod.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using Microsoft.Win32.SafeHandles; -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FChMod", SetLastError = true)] - internal static extern int FChMod(SafeFileHandle fd, int mode); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Fcntl.Pipe.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Fcntl.Pipe.cs deleted file mode 100644 index 96c7caf165..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Fcntl.Pipe.cs +++ /dev/null @@ -1,27 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal static partial class Fcntl - { - internal static readonly bool CanGetSetPipeSz = (FcntlCanGetSetPipeSz() != 0); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FcntlGetPipeSz", SetLastError=true)] - internal static extern int GetPipeSz(SafePipeHandle fd); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FcntlSetPipeSz", SetLastError=true)] - internal static extern int SetPipeSz(SafePipeHandle fd, int size); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FcntlCanGetSetPipeSz")] - private static extern int FcntlCanGetSetPipeSz(); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Fcntl.SetCloseOnExec.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Fcntl.SetCloseOnExec.cs deleted file mode 100644 index ec0836bacb..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Fcntl.SetCloseOnExec.cs +++ /dev/null @@ -1,19 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal static partial class Fcntl - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FcntlSetCloseOnExec", SetLastError=true)] - internal static extern int SetCloseOnExec(SafeHandle fd); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Fcntl.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Fcntl.cs deleted file mode 100644 index 5b2fb45e3e..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Fcntl.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal static class Fcntl - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FcntlSetIsNonBlocking", SetLastError = true)] - internal static extern int DangerousSetIsNonBlocking(IntPtr fd, int isNonBlocking); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FcntlSetIsNonBlocking", SetLastError=true)] - internal static extern int SetIsNonBlocking(SafeHandle fd, int isNonBlocking); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.FileDescriptors.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.FileDescriptors.cs deleted file mode 100644 index 82abc8bffa..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.FileDescriptors.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -using System; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal static class FileDescriptors - { - internal static readonly SafeFileHandle STDIN_FILENO = CreateFileHandle(0); - internal static readonly SafeFileHandle STDOUT_FILENO = CreateFileHandle(1); - internal static readonly SafeFileHandle STDERR_FILENO = CreateFileHandle(2); - - private static SafeFileHandle CreateFileHandle(int fileNumber) - { - return new SafeFileHandle((IntPtr)fileNumber, ownsHandle: false); - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ForkAndExecProcess.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ForkAndExecProcess.cs deleted file mode 100644 index 3aa37279bc..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ForkAndExecProcess.cs +++ /dev/null @@ -1,111 +0,0 @@ -// 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. - -using System; -using System.ComponentModel; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal static unsafe void ForkAndExecProcess( - string filename, string[] argv, string[] envp, string cwd, - bool redirectStdin, bool redirectStdout, bool redirectStderr, - bool setUser, uint userId, uint groupId, - out int lpChildPid, out int stdinFd, out int stdoutFd, out int stderrFd, bool shouldThrow = true) - { - byte** argvPtr = null, envpPtr = null; - int result = -1; - try - { - AllocNullTerminatedArray(argv, ref argvPtr); - AllocNullTerminatedArray(envp, ref envpPtr); - result = ForkAndExecProcess( - filename, argvPtr, envpPtr, cwd, - redirectStdin ? 1 : 0, redirectStdout ? 1 : 0, redirectStderr ? 1 :0, - setUser ? 1 : 0, userId, groupId, - out lpChildPid, out stdinFd, out stdoutFd, out stderrFd); - if (result != 0) - { - // Normally we'd simply make this method return the result of the native - // call and allow the caller to use GetLastWin32Error. However, we need - // to free the native arrays after calling the function, and doing so - // stomps on the runtime's captured last error. So we need to access the - // error here, and without SetLastWin32Error available, we can't propagate - // the error to the caller via the normal GetLastWin32Error mechanism. We could - // return 0 on success or the GetLastWin32Error value on failure, but that's - // technically ambiguous, in the case of a failure with a 0 errno. Simplest - // solution then is just to throw here the same exception the Process caller - // would have. This can be revisited if we ever have another call site. - throw new Win32Exception(); - } - } - finally - { - FreeArray(envpPtr, envp.Length); - FreeArray(argvPtr, argv.Length); - } - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ForkAndExecProcess", SetLastError = true)] - private static extern unsafe int ForkAndExecProcess( - string filename, byte** argv, byte** envp, string cwd, - int redirectStdin, int redirectStdout, int redirectStderr, - int setUser, uint userId, uint groupId, - out int lpChildPid, out int stdinFd, out int stdoutFd, out int stderrFd); - - private static unsafe void AllocNullTerminatedArray(string[] arr, ref byte** arrPtr) - { - int arrLength = arr.Length + 1; // +1 is for null termination - - // Allocate the unmanaged array to hold each string pointer. - // It needs to have an extra element to null terminate the array. - arrPtr = (byte**)Marshal.AllocHGlobal(sizeof(IntPtr) * arrLength); - Debug.Assert(arrPtr != null); - - // Zero the memory so that if any of the individual string allocations fails, - // we can loop through the array to free any that succeeded. - // The last element will remain null. - for (int i = 0; i < arrLength; i++) - { - arrPtr[i] = null; - } - - // Now copy each string to unmanaged memory referenced from the array. - // We need the data to be an unmanaged, null-terminated array of UTF8-encoded bytes. - for (int i = 0; i < arr.Length; i++) - { - byte[] byteArr = Encoding.UTF8.GetBytes(arr[i]); - - arrPtr[i] = (byte*)Marshal.AllocHGlobal(byteArr.Length + 1); //+1 for null termination - Debug.Assert(arrPtr[i] != null); - - Marshal.Copy(byteArr, 0, (IntPtr)arrPtr[i], byteArr.Length); // copy over the data from the managed byte array - arrPtr[i][byteArr.Length] = (byte)'\0'; // null terminate - } - } - - private static unsafe void FreeArray(byte** arr, int length) - { - if (arr != null) - { - // Free each element of the array - for (int i = 0; i < length; i++) - { - if (arr[i] != null) - { - Marshal.FreeHGlobal((IntPtr)arr[i]); - arr[i] = null; - } - } - - // And then the array itself - Marshal.FreeHGlobal((IntPtr)arr); - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetBytesAvailable.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetBytesAvailable.cs deleted file mode 100644 index ee42a483d3..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetBytesAvailable.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetBytesAvailable")] - internal static extern unsafe Error GetBytesAvailable(SafeHandle socket, int* available); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetAtOutOfBandMark")] - internal static extern unsafe Error GetAtOutOfBandMark(SafeHandle socket, int* atMark); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetControlCharacters.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetControlCharacters.cs deleted file mode 100644 index f33a5544b9..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetControlCharacters.cs +++ /dev/null @@ -1,37 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetControlCharacters")] - internal static extern void GetControlCharacters( - ControlCharacterNames[] controlCharacterNames, byte[] controlCharacterValues, int controlCharacterLength, - out byte posixDisableValue); - - internal enum ControlCharacterNames : int - { - VINTR = 0, - VQUIT = 1, - VERASE = 2, - VKILL = 3, - VEOF = 4, - VTIME = 5, - VMIN = 6, - VSWTC = 7, - VSTART = 8, - VSTOP = 9, - VSUSP = 10, - VEOL = 11, - VREPRINT = 12, - VDISCARD = 13, - VWERASE = 14, - VLNEXT = 15, - VEOL2 = 16 - }; - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetDomainName.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetDomainName.cs deleted file mode 100644 index 4466d63413..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetDomainName.cs +++ /dev/null @@ -1,39 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetDomainName", SetLastError = true)] - private static extern unsafe int GetDomainName(byte* name, int len); - - internal static unsafe string GetDomainName() - { - const int HOST_NAME_MAX = 255; // man getdomainname - const int ArrLength = HOST_NAME_MAX + 1; - - byte* name = stackalloc byte[ArrLength]; - int err = GetDomainName(name, ArrLength); - if (err != 0) - { - // This should never happen. According to the man page, - // the only possible errno for getdomainname is ENAMETOOLONG, - // which should only happen if the buffer we supply isn't big - // enough, and we're using a buffer size that the man page - // says is the max for POSIX (and larger than the max for Linux). - Debug.Fail($"{nameof(GetDomainName)} failed with error {err}"); - throw new InvalidOperationException($"{nameof(GetDomainName)}: {err}"); - } - - // Marshal.PtrToStringAnsi uses UTF8 on Unix. - return Marshal.PtrToStringAnsi((IntPtr)name); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetDomainSocketSizes.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetDomainSocketSizes.cs deleted file mode 100644 index bb0f48c721..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetDomainSocketSizes.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetDomainSocketSizes")] - internal static extern void GetDomainSocketSizes(out int pathOffset, out int pathSize, out int addressSize); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetEGid.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetEGid.cs deleted file mode 100644 index 6530b2303a..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetEGid.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEGid")] - internal static extern uint GetEGid(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetEUid.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetEUid.cs deleted file mode 100644 index 8b525fa327..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetEUid.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEUid")] - internal static extern uint GetEUid(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs deleted file mode 100644 index 3858b495a1..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetHostName.cs +++ /dev/null @@ -1,40 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetHostName", SetLastError = true)] - private static extern unsafe int GetHostName(byte* name, int nameLength); - - internal static unsafe string GetHostName() - { - const int HOST_NAME_MAX = 255; - const int ArrLength = HOST_NAME_MAX + 1; - - byte* name = stackalloc byte[ArrLength]; - int err = GetHostName(name, ArrLength); - if (err != 0) - { - // This should never happen. According to the man page, - // the only possible errno for gethostname is ENAMETOOLONG, - // which should only happen if the buffer we supply isn't big - // enough, and we're using a buffer size that the man page - // says is the max for POSIX (and larger than the max for Linux). - Debug.Fail("gethostname failed"); - throw new InvalidOperationException(string.Format("gethostname returned {0}", err)); - } - - // If the hostname is truncated, it is unspecified whether the returned buffer includes a terminating null byte. - name[ArrLength - 1] = 0; - - return Marshal.PtrToStringAnsi((IntPtr)name); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetLine.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetLine.cs deleted file mode 100644 index f6a6c7e3ae..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetLine.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetLine", SetLastError = true)] - internal static extern string GetLine(IntPtr stream); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetNameInfo.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetNameInfo.cs deleted file mode 100644 index bd22e8c912..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetNameInfo.cs +++ /dev/null @@ -1,30 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [Flags] - internal enum GetNameInfoFlags : int - { - NI_NAMEREQD = 0x1, - NI_NUMERICHOST = 0x2, - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNameInfo")] - internal static extern unsafe int GetNameInfo( - byte* address, - uint addressLength, - byte isIpv6, - byte* host, - uint hostLength, - byte* service, - uint serviceLength, - GetNameInfoFlags flags); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetNodeName.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetNodeName.cs deleted file mode 100644 index a303544e4e..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetNodeName.cs +++ /dev/null @@ -1,35 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNodeName", SetLastError = true)] - private static extern unsafe int GetNodeName(char* name, out int len); - - internal static unsafe string GetNodeName() - { - // max value of _UTSNAME_LENGTH on known Unix platforms is 1024. - const int _UTSNAME_LENGTH = 1024; - int len = _UTSNAME_LENGTH; - char* name = stackalloc char[_UTSNAME_LENGTH]; - int err = GetNodeName(name, out len); - if (err != 0) - { - // max domain name can be 255 chars. - Debug.Fail($"{nameof(GetNodeName)} failed with error {err}"); - throw new InvalidOperationException(string.Format($"{nameof(GetNodeName)}: {err}"); - } - - // Marshal.PtrToStringAnsi uses UTF8 on Unix. - return Marshal.PtrToStringAnsi((IntPtr)name); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetOSArchitecture.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetOSArchitecture.cs deleted file mode 100644 index 70f614ebcf..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetOSArchitecture.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetOSArchitecture")] - internal static extern int GetOSArchitecture(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPeerID.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPeerID.cs deleted file mode 100644 index 9ebb48ec39..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPeerID.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPeerID", SetLastError = true)] - internal static extern unsafe int GetPeerID(SafeHandle socket, out uint euid); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPeerName.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPeerName.cs deleted file mode 100644 index 3635b92d29..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPeerName.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPeerName")] - internal static extern unsafe Error GetPeerName(SafeHandle socket, byte* socketAddress, int* socketAddressLen); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPeerUserName.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPeerUserName.cs deleted file mode 100644 index 8effc8883e..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPeerUserName.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPeerUserName", SetLastError = true)] - internal static extern unsafe string GetPeerUserName(SafeHandle socket); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPid.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPid.cs deleted file mode 100644 index f25005d798..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPid.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPid")] - internal static extern int GetPid(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetProcessArchitecture.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetProcessArchitecture.cs deleted file mode 100644 index be23a335b7..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetProcessArchitecture.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetProcessArchitecture")] - internal static extern int GetProcessArchitecture(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPwUid.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPwUid.cs deleted file mode 100644 index 56d55c948f..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetPwUid.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal unsafe struct Passwd - { - internal const int InitialBufferSize = 256; - - internal byte* Name; - internal byte* Password; - internal uint UserId; - internal uint GroupId; - internal byte* UserInfo; - internal byte* HomeDirectory; - internal byte* Shell; - }; - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPwUidR", SetLastError = false)] - internal static extern unsafe int GetPwUidR(uint uid, out Passwd pwd, byte* buf, int bufLen); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPwNamR", SetLastError = false)] - internal static extern unsafe int GetPwNamR(string name, out Passwd pwd, byte* buf, int bufLen); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSetPriority.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSetPriority.cs deleted file mode 100644 index fc1002be97..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSetPriority.cs +++ /dev/null @@ -1,63 +0,0 @@ -// 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. - -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Reflection; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal enum PriorityWhich : int - { - PRIO_PROCESS = 0, - PRIO_PGRP = 1, - PRIO_USER = 2, - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPriority", SetLastError = true)] - private static extern int GetPriority(PriorityWhich which, int who); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetPriority", SetLastError = true)] - internal static extern int SetPriority(PriorityWhich which, int who, int nice); - - /// - /// Wrapper around getpriority since getpriority can return from -20 to 20; therefore, - /// we cannot rely on the return value for success and failure. This wrapper makes the - /// getpriority call to act more naturally where the return value is the actual error - /// value (or 0 if success) instead of forcing the caller to retrieve the last error. - /// - /// Returns 0 on success; otherwise, returns the errno value - internal static int GetPriority(PriorityWhich which, int who, out int priority) - { - priority = GetPriority(which, who); - return Marshal.GetLastWin32Error(); - } - - internal static System.Diagnostics.ThreadPriorityLevel GetThreadPriorityFromNiceValue(int nice) - { - Debug.Assert((nice >= -20) && (nice <= 20)); - return - (nice < -15) ? ThreadPriorityLevel.TimeCritical : - (nice < -10) ? ThreadPriorityLevel.Highest : - (nice < -5) ? ThreadPriorityLevel.AboveNormal : - (nice == 0) ? ThreadPriorityLevel.Normal : - (nice <= 5) ? ThreadPriorityLevel.BelowNormal : - (nice <= 10) ? ThreadPriorityLevel.Lowest : - ThreadPriorityLevel.Idle; - } - - internal static int GetNiceValueFromThreadPriority(System.Diagnostics.ThreadPriorityLevel priority) - { - return (priority == ThreadPriorityLevel.TimeCritical ? -20 : - priority == ThreadPriorityLevel.Highest ? -15 : - priority == ThreadPriorityLevel.AboveNormal ? -10 : - priority == ThreadPriorityLevel.Normal ? 0 : - priority == ThreadPriorityLevel.BelowNormal ? 5 : - priority == ThreadPriorityLevel.Lowest ? 10 : - 20); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSockName.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSockName.cs deleted file mode 100644 index f46297943e..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSockName.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetSockName")] - internal static extern unsafe Error GetSockName(SafeHandle socket, byte* socketAddress, int* socketAddressLen); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSockOpt.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSockOpt.cs deleted file mode 100644 index 3e48b84536..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSockOpt.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Net.Sockets; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetSockOpt")] - internal static extern unsafe Error GetSockOpt(SafeHandle socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte* optionValue, int* optionLen); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSocketErrorOption.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSocketErrorOption.cs deleted file mode 100644 index 070171d63d..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSocketErrorOption.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Net.Sockets; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetSocketErrorOption")] - internal static extern unsafe Error GetSocketErrorOption(SafeHandle socket, Error* socketError); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetTimestamp.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetTimestamp.cs deleted file mode 100644 index a6c9d28054..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetTimestamp.cs +++ /dev/null @@ -1,23 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTimestampResolution")] - internal static extern bool GetTimestampResolution(out long resolution); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTimestamp")] - internal static extern bool GetTimestamp(out long timestamp); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetAbsoluteTime")] - internal static extern bool GetAbsoluteTime(out ulong timestamp); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetTimebaseInfo")] - internal static extern bool GetTimebaseInfo(out uint numer, out uint denom); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetUnixName.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetUnixName.cs deleted file mode 100644 index 33664c4d39..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetUnixName.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUnixName")] - private static extern IntPtr GetUnixNamePrivate(); - - internal static string GetUnixName() - { - IntPtr ptr = GetUnixNamePrivate(); - return Marshal.PtrToStringAnsi(ptr); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetUnixRelease.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetUnixRelease.cs deleted file mode 100644 index 5e41ae9804..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetUnixRelease.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUnixRelease", CharSet = CharSet.Ansi, SetLastError = true)] - public static extern string GetUnixRelease(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetUnixVersion.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetUnixVersion.cs deleted file mode 100644 index 9124607552..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetUnixVersion.cs +++ /dev/null @@ -1,36 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetUnixVersion", CharSet = CharSet.Ansi, SetLastError = true)] - private static extern int GetUnixVersion(StringBuilder version, out int capacity); - - internal static string GetUnixVersion() - { - // max value of _UTSNAME_LENGTH on known Unix platforms is 1024. - const int _UTSNAME_LENGTH = 1024; - int capacity = _UTSNAME_LENGTH * 3 + 2; - StringBuilder version = new StringBuilder(capacity); - - if (GetUnixVersion(version, out capacity) != 0) - { - // Check if the function failed due to insufficient buffer. - if (capacity > version.Capacity) - { - version.Capacity = capacity; - GetUnixVersion(version, out capacity); - } - } - - return version.ToString(); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetWindowWidth.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetWindowWidth.cs deleted file mode 100644 index 290857d742..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetWindowWidth.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [StructLayout(LayoutKind.Sequential)] - internal struct WinSize - { - internal ushort Row; - internal ushort Col; - internal ushort XPixel; - internal ushort YPixel; - }; - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetWindowSize", SetLastError = true)] - internal static extern int GetWindowSize(out WinSize winSize); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.HostEntry.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.HostEntry.cs deleted file mode 100644 index 944a235821..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.HostEntry.cs +++ /dev/null @@ -1,59 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal const int NI_MAXHOST = 1025; - internal const int NI_MAXSERV = 32; - - internal enum GetAddrInfoErrorFlags : int - { - EAI_AGAIN = 1, // Temporary failure in name resolution. - EAI_BADFLAGS = 2, // Invalid value for `ai_flags' field. - EAI_FAIL = 3, // Non-recoverable failure in name resolution. - EAI_FAMILY = 4, // 'ai_family' not supported. - EAI_NONAME = 5, // NAME or SERVICE is unknown. - EAI_BADARG = 6, // One or more input arguments were invalid. - EAI_NOMORE = 7, // No more entries are present in the list. - } - - internal enum GetHostErrorCodes : int - { - HOST_NOT_FOUND = 1, - TRY_AGAIN = 2, - NO_RECOVERY = 3, - NO_DATA = 4, - NO_ADDRESS = NO_DATA, - } - - //opaque structure to maintain consistency with native function signature - internal unsafe struct addrinfo - { - - } - - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct HostEntry - { - internal byte* CanonicalName; // Canonical Name of the Host - internal byte** Aliases; // List of aliases for the host - internal addrinfo* AddressListHandle; // Handle for socket address list - internal int IPAddressCount; // Number of IP addresses in the list - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetHostEntryForName")] - internal static extern unsafe int GetHostEntryForName(string address, HostEntry* entry); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetNextIPAddress")] - internal static extern unsafe int GetNextIPAddress(HostEntry* entry, addrinfo** addressListHandle, IPAddress* endPoint); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FreeHostEntry")] - internal static extern unsafe void FreeHostEntry(HostEntry* entry); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.IPAddress.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.IPAddress.cs deleted file mode 100644 index dc9b25f758..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.IPAddress.cs +++ /dev/null @@ -1,78 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal const int IPv4AddressBytes = 4; - internal const int IPv6AddressBytes = 16; - - internal const int MAX_IP_ADDRESS_BYTES = 16; - - internal const int INET_ADDRSTRLEN = 22; - internal const int INET6_ADDRSTRLEN = 65; - - // NOTE: `_isIPv6` cannot be of type `bool` because `bool` is not a blittable type and this struct is - // embedded in other structs for interop purposes. - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct IPAddress : IEquatable - { - public bool IsIPv6 - { - get { return _isIPv6 != 0; } - set { _isIPv6 = value ? 1u : 0u; } - } - - internal fixed byte Address[MAX_IP_ADDRESS_BYTES]; // Buffer to fit an IPv4 or IPv6 address - private uint _isIPv6; // Non-zero if this is an IPv6 address; zero for IPv4. - internal uint ScopeId; // Scope ID (IPv6 only) - - public bool Equals(IPAddress other) - { - int addressByteCount; - if (IsIPv6) - { - if (!other.IsIPv6) - { - return false; - } - if (ScopeId != other.ScopeId) - { - return false; - } - - addressByteCount = IPv6AddressBytes; - } - else - { - if (other.IsIPv6) - { - return false; - } - - addressByteCount = IPv4AddressBytes; - } - - fixed (byte* thisAddress = Address) - { - for (int i = 0; i < addressByteCount; i++) - { - if (thisAddress[i] != other.Address[i]) - { - return false; - } - } - } - - return true; - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.IPPacketInformation.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.IPPacketInformation.cs deleted file mode 100644 index b676eaaad8..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.IPPacketInformation.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal struct IPPacketInformation - { - public IPAddress Address; // Destination IP Address - public int InterfaceIndex; // Interface index - private int Padding; // Pad out to 8-byte alignment - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetControlMessageBufferSize")] - internal static extern int GetControlMessageBufferSize(bool isIPv4, bool isIPv6); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_TryGetIPPacketInformation")] - internal static extern unsafe bool TryGetIPPacketInformation(MessageHeader* messageHeader, bool isIPv4, IPPacketInformation* packetInfo); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.InitializeConsole.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.InitializeConsole.cs deleted file mode 100644 index aeb1b69bfb..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.InitializeConsole.cs +++ /dev/null @@ -1,17 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_InitializeConsole", SetLastError = true)] - internal static extern bool InitializeConsole(); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetKeypadXmit")] - internal static extern void SetKeypadXmit(string terminfoString); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.IsATty.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.IsATty.cs deleted file mode 100644 index c68e8c7cdb..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.IsATty.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_IsATty", SetLastError = true)] - internal static extern bool IsATty(SafeFileHandle fd); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Kill.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Kill.cs deleted file mode 100644 index 47b22366ab..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Kill.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal enum Signals : int - { - None = 0, - SIGKILL = 9, - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Kill", SetLastError = true)] - internal static extern int Kill(int pid, Signals signal); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.LingerOption.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.LingerOption.cs deleted file mode 100644 index e1d659f350..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.LingerOption.cs +++ /dev/null @@ -1,28 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal struct LingerOption - { - public int OnOff; // Non-zero to enable linger - public int Seconds; // Number of seconds to linger for - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetLingerOption")] - internal static extern unsafe Error GetLingerOption(SafeHandle socket, LingerOption* option); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetLingerOption")] - internal static extern unsafe Error SetLingerOption(SafeHandle socket, LingerOption* option); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetLingerOption")] - internal static extern unsafe Error SetLingerOption(IntPtr socket, LingerOption* option); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Link.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Link.cs deleted file mode 100644 index 714649f5b2..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Link.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Link", SetLastError = true)] - internal static extern int Link(string source, string link); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Listen.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Listen.cs deleted file mode 100644 index 03b95ed00f..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Listen.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Listen")] - internal static extern Error Listen(SafeHandle socket, int backlog); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MAdvise.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MAdvise.cs deleted file mode 100644 index b46a506986..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MAdvise.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_MAdvise", SetLastError = true)] - internal static extern int MAdvise(IntPtr addr, ulong length, MemoryAdvice advice); - - internal enum MemoryAdvice - { - MADV_DONTFORK = 1, - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MMap.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MMap.cs deleted file mode 100644 index d7d1957af1..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MMap.cs +++ /dev/null @@ -1,38 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - - internal static partial class Sys - { - [Flags] - internal enum MemoryMappedProtections - { - PROT_NONE = 0x0, - PROT_READ = 0x1, - PROT_WRITE = 0x2, - PROT_EXEC = 0x4 - } - - [Flags] - internal enum MemoryMappedFlags - { - MAP_SHARED = 0x01, - MAP_PRIVATE = 0x02, - MAP_ANONYMOUS = 0x10, - } - - // NOTE: Shim returns null pointer on failure, not non-null MAP_FAILED sentinel. - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_MMap", SetLastError = true)] - internal static extern IntPtr MMap( - IntPtr addr, ulong len, - MemoryMappedProtections prot, MemoryMappedFlags flags, - SafeFileHandle fd, long offset); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MSync.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MSync.cs deleted file mode 100644 index 9326c64004..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MSync.cs +++ /dev/null @@ -1,23 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [Flags] - internal enum MemoryMappedSyncFlags - { - MS_ASYNC = 0x1, - MS_SYNC = 0x2, - MS_INVALIDATE = 0x10, - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_MSync", SetLastError = true)] - internal static extern int MSync(IntPtr addr, ulong len, MemoryMappedSyncFlags flags); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MUnmap.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MUnmap.cs deleted file mode 100644 index 1bfc1bae65..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MUnmap.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_MUnmap", SetLastError = true)] - internal static extern int MUnmap(IntPtr addr, ulong len); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MapTcpState.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MapTcpState.cs deleted file mode 100644 index f0ac9d98a9..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MapTcpState.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System.Net.NetworkInformation; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_MapTcpState")] - internal static extern TcpState MapTcpState(int nativeState); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MemSet.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MemSet.cs deleted file mode 100644 index 431d17029b..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MemSet.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_MemSet")] - internal static extern unsafe void* MemSet(void *s, int c, UIntPtr n); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MessageHeader.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MessageHeader.cs deleted file mode 100644 index 0748eb9213..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MessageHeader.cs +++ /dev/null @@ -1,29 +0,0 @@ -// 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. - -using System; -using System.Net.Sockets; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal unsafe struct IOVector - { - public byte* Base; - public UIntPtr Count; - } - - internal unsafe struct MessageHeader - { - public byte* SocketAddress; - public IOVector* IOVectors; - public byte* ControlBuffer; - public int SocketAddressLen; - public int IOVectorCount; - public int ControlBufferLen; - public SocketFlags Flags; - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MkDir.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MkDir.cs deleted file mode 100644 index 3e4105cf43..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MkDir.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_MkDir", SetLastError = true)] - internal static extern int MkDir(string path, int mode); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs deleted file mode 100644 index 217790122e..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MountPoints.FormatInfo.cs +++ /dev/null @@ -1,440 +0,0 @@ -// 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. - -using System; -using System.IO; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { -#if DEBUG - static Sys() - { - foreach (string name in Enum.GetNames(typeof(UnixFileSystemTypes))) - { - System.Diagnostics.Debug.Assert(GetDriveType(name) != DriveType.Unknown, - $"Expected {nameof(UnixFileSystemTypes)}.{name} to have an entry in {nameof(GetDriveType)}."); - } - } -#endif - - private const int MountPointFormatBufferSizeInBytes = 32; - - /// - /// Internal FileSystem names and magic numbers taken from man(2) statfs - /// - /// - /// These value names MUST be kept in sync with those in GetDriveType below, - /// where this enum must be a subset of the GetDriveType list, with the enum - /// values here exactly matching a string there. - /// - internal enum UnixFileSystemTypes : long - { - adfs = 0xADF5, - affs = 0xADFF, - afs = 0x5346414F, - anoninode = 0x09041934, - aufs = 0x61756673, - autofs = 0x0187, - autofs4 = 0x6D4A556D, - befs = 0x42465331, - bdevfs = 0x62646576, - bfs = 0x1BADFACE, - binfmt_misc = 0x42494E4D, - btrfs = 0x9123683E, - ceph = 0x00C36400, - cgroupfs = 0x0027E0EB, - cifs = 0xFF534D42, - coda = 0x73757245, - coherent = 0x012FF7B7, - configfs = 0x62656570, - cramfs = 0x28CD3D45, - debugfs = 0x64626720, - devfs = 0x1373, - devpts = 0x1CD1, - ecryptfs = 0xF15F, - efs = 0x00414A53, - exofs = 0x5DF5, - ext = 0x137D, - ext2_old = 0xEF51, - ext2 = 0xEF53, - ext3 = 0xEF53, - ext4 = 0xEF53, - fat = 0x4006, - fhgfs = 0x19830326, - fuse = 0x65735546, - fuseblk = 0x65735546, - fusectl = 0x65735543, - futexfs = 0x0BAD1DEA, - gfsgfs2 = 0x1161970, - gfs2 = 0x01161970, - gpfs = 0x47504653, - hfs = 0x4244, - hfsplus = 0x482B, - hpfs = 0xF995E849, - hugetlbfs = 0x958458F6, - inodefs = 0x11307854, - inotifyfs = 0x2BAD1DEA, - isofs = 0x9660, - // isofs = 0x4004, // R_WIN - // isofs = 0x4000, // WIN - jffs = 0x07C0, - jffs2 = 0x72B6, - jfs = 0x3153464A, - kafs = 0x6B414653, - logfs = 0xC97E8168, - lustre = 0x0BD00BD0, - minix_old = 0x137F, /* orig. minix */ - minix = 0x138F, /* 30 char minix */ - minix2 = 0x2468, /* minix V2 */ - minix2v2 = 0x2478, /* MINIX V2, 30 char names */ - minix3 = 0x4D5A, - mqueue = 0x19800202, - msdos = 0x4D44, - nfs = 0x6969, - nfsd = 0x6E667364, - nilfs = 0x3434, - novell = 0x564C, - ntfs = 0x5346544E, - openprom = 0x9FA1, - ocfs2 = 0x7461636F, - omfs = 0xC2993D87, - overlay = 0x794C7630, - overlayfs = 0x794C764F, - panfs = 0xAAD7AAEA, - pipefs = 0x50495045, - proc = 0x9FA0, - pstorefs = 0x6165676C, - qnx4 = 0x002F, - qnx6 = 0x68191122, - ramfs = 0x858458F6, - reiserfs = 0x52654973, - romfs = 0x7275, - rpc_pipefs = 0x67596969, - samba = 0x517B, - securityfs = 0x73636673, - selinux = 0xF97CFF8C, - smb = 0x517B, - sockfs = 0x534F434B, - squashfs = 0x73717368, - sysfs = 0x62656572, - sysv2 = 0x012FF7B6, - sysv4 = 0x012FF7B5, - tmpfs = 0x01021994, - ubifs = 0x24051905, - udf = 0x15013346, - ufs = 0x00011954, - ufscigam = 0x54190100, // ufs byteswapped - ufs2 = 0x19540119, - usbdevice = 0x9FA2, - v9fs = 0x01021997, - vmhgfs = 0xBACBACBC, - vxfs = 0xA501FCF5, - vzfs = 0x565A4653, - xenfs = 0xABBA1974, - xenix = 0x012FF7B4, - xfs = 0x58465342, - xia = 0x012FD16D, - zfs = 0x2FC12FC1, - } - - [StructLayout(LayoutKind.Sequential)] - internal struct MountPointInformation - { - internal ulong AvailableFreeSpace; - internal ulong TotalFreeSpace; - internal ulong TotalSize; - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetSpaceInfoForMountPoint", SetLastError = true)] - internal static extern int GetSpaceInfoForMountPoint([MarshalAs(UnmanagedType.LPStr)]string name, out MountPointInformation mpi); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetFormatInfoForMountPoint", SetLastError = true)] - private static extern unsafe int GetFormatInfoForMountPoint( - [MarshalAs(UnmanagedType.LPStr)]string name, - byte* formatNameBuffer, - int bufferLength, - long* formatType); - - internal static int GetFormatInfoForMountPoint(string name, out string format) - { - DriveType temp; - return GetFormatInfoForMountPoint(name, out format, out temp); - } - - internal static int GetFormatInfoForMountPoint(string name, out DriveType type) - { - string temp; - return GetFormatInfoForMountPoint(name, out temp, out type); - } - - private static int GetFormatInfoForMountPoint(string name, out string format, out DriveType type) - { - unsafe - { - byte* formatBuffer = stackalloc byte[MountPointFormatBufferSizeInBytes]; // format names should be small - long numericFormat; - int result = GetFormatInfoForMountPoint(name, formatBuffer, MountPointFormatBufferSizeInBytes, &numericFormat); - if (result == 0) - { - // Check if we have a numeric answer or string - format = numericFormat != -1 ? - Enum.GetName(typeof(UnixFileSystemTypes), numericFormat) : - Marshal.PtrToStringAnsi((IntPtr)formatBuffer); - type = GetDriveType(format); - } - else - { - format = string.Empty; - type = DriveType.Unknown; - } - - return result; - } - } - - /// Categorizes a file system name into a drive type. - /// The name to categorize. - /// The recognized drive type. - private static DriveType GetDriveType(string fileSystemName) - { - // This list is based primarily on "man fs", "man mount", "mntent.h", "/proc/filesystems", coreutils "stat.c", - // and "wiki.debian.org/FileSystem". It can be extended over time as we find additional file systems that should - // be recognized as a particular drive type. - switch (fileSystemName) - { - case "cddafs": - case "cd9660": - case "iso": - case "isofs": - case "iso9660": - case "fuseiso": - case "fuseiso9660": - case "udf": - case "umview-mod-umfuseiso9660": - return DriveType.CDRom; - - case "aafs": - case "adfs": - case "affs": - case "anoninode": - case "anon-inode FS": - case "apfs": - case "balloon-kvm-fs": - case "bdevfs": - case "befs": - case "bfs": - case "bpf_fs": - case "btrfs": - case "btrfs_test": - case "cgroup2fs": - case "coh": - case "daxfs": - case "drvfs": - case "efivarfs": - case "efs": - case "exfat": - case "exofs": - case "ext": - case "ext2": - case "ext2_old": - case "ext3": - case "ext2/ext3": - case "ext4": - case "ext4dev": - case "f2fs": - case "fat": - case "fuseext2": - case "fusefat": - case "hfs": - case "hfs+": - case "hfsplus": - case "hfsx": - case "hostfs": - case "hpfs": - case "inodefs": - case "inotifyfs": - case "jbd": - case "jbd2": - case "jffs": - case "jffs2": - case "jfs": - case "logfs": - case "lxfs": - case "minix (30 char.)": - case "minix v2 (30 char.)": - case "minix v2": - case "minix": - case "minix_old": - case "minix2": - case "minix2v2": - case "minix2 v2": - case "minix3": - case "mlfs": - case "msdos": - case "nilfs": - case "nsfs": - case "ntfs": - case "ntfs-3g": - case "ocfs2": - case "omfs": - case "overlay": - case "overlayfs": - case "pstorefs": - case "qnx4": - case "qnx6": - case "reiserfs": - case "rpc_pipefs": - case "smackfs": - case "squashfs": - case "swap": - case "sysv": - case "sysv2": - case "sysv4": - case "tracefs": - case "ubifs": - case "ufs": - case "ufscigam": - case "ufs2": - case "umsdos": - case "umview-mod-umfuseext2": - case "v9fs": - case "vxfs": - case "vxfs_olt": - case "vzfs": - case "wslfs": - case "xenix": - case "xfs": - case "xia": - case "xiafs": - case "xmount": - case "zfs": - case "zfs-fuse": - case "zsmallocfs": - return DriveType.Fixed; - - case "9p": - case "acfs": - case "afp": - case "afpfs": - case "afs": - case "aufs": - case "autofs": - case "autofs4": - case "beaglefs": - case "ceph": - case "cifs": - case "coda": - case "coherent": - case "curlftpfs": - case "davfs2": - case "dlm": - case "ecryptfs": - case "eCryptfs": - case "fhgfs": - case "flickrfs": - case "ftp": - case "fuse": - case "fuseblk": - case "fusedav": - case "fusesmb": - case "gfsgfs2": - case "gfs/gfs2": - case "gfs2": - case "glusterfs-client": - case "gmailfs": - case "gpfs": - case "ibrix": - case "k-afs": - case "kafs": - case "kbfuse": - case "ltspfs": - case "lustre": - case "ncp": - case "ncpfs": - case "nfs": - case "nfs4": - case "nfsd": - case "novell": - case "obexfs": - case "panfs": - case "prl_fs": - case "s3ql": - case "samba": - case "smb": - case "smb2": - case "smbfs": - case "snfs": - case "sshfs": - case "vmhgfs": - case "webdav": - case "wikipediafs": - case "xenfs": - return DriveType.Network; - - case "anon_inode": - case "anon_inodefs": - case "aptfs": - case "avfs": - case "bdev": - case "binfmt_misc": - case "cgroup": - case "cgroupfs": - case "configfs": - case "cramfs": - case "cramfs-wend": - case "cryptkeeper": - case "cpuset": - case "debugfs": - case "devfs": - case "devpts": - case "devtmpfs": - case "encfs": - case "fdesc": - case "fuse.gvfsd-fuse": - case "fusectl": - case "futexfs": - case "hugetlbfs": - case "libpam-encfs": - case "ibpam-mount": - case "mtpfs": - case "mythtvfs": - case "mqueue": - case "openprom": - case "openpromfs": - case "pipefs": - case "plptools": - case "proc": - case "pstore": - case "pytagsfs": - case "ramfs": - case "rofs": - case "romfs": - case "rootfs": - case "securityfs": - case "selinux": - case "selinuxfs": - case "sockfs": - case "sysfs": - case "tmpfs": - case "usbdev": - case "usbdevfs": - return DriveType.Ram; - - case "gphotofs": - case "usbfs": - case "usbdevice": - case "vfat": - return DriveType.Removable; - - // Categorize as "Unknown" everything else not explicitly - // recognized as a particular drive type. - default: - return DriveType.Unknown; - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MountPoints.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MountPoints.cs deleted file mode 100644 index 7e31197149..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MountPoints.cs +++ /dev/null @@ -1,40 +0,0 @@ -// 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. - -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private unsafe delegate void MountPointFound(byte* name); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetAllMountPoints", SetLastError = true)] - private static extern int GetAllMountPoints(MountPointFound mpf); - - internal static string[] GetAllMountPoints() - { - int count = 0; - var found = new string[4]; - - unsafe - { - int result = GetAllMountPoints((byte* name) => - { - if (count == found.Length) - { - Array.Resize(ref found, count * 2); - } - found[count++] = Marshal.PtrToStringAnsi((IntPtr)name); - }); - } - - Array.Resize(ref found, count); - return found; - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MulticastOption.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MulticastOption.cs deleted file mode 100644 index 8a12048c8e..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.MulticastOption.cs +++ /dev/null @@ -1,47 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal enum MulticastOption : int - { - MULTICAST_ADD = 0, - MULTICAST_DROP = 1, - MULTICAST_IF = 2 - } - - internal struct IPv4MulticastOption - { - public uint MulticastAddress; - public uint LocalAddress; - public int InterfaceIndex; - private int _padding; - } - - internal struct IPv6MulticastOption - { - public IPAddress Address; - public int InterfaceIndex; - private int _padding; - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPv4MulticastOption")] - internal static extern unsafe Error GetIPv4MulticastOption(SafeHandle socket, MulticastOption multicastOption, IPv4MulticastOption* option); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetIPv4MulticastOption")] - internal static extern unsafe Error SetIPv4MulticastOption(SafeHandle socket, MulticastOption multicastOption, IPv4MulticastOption* option); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPv6MulticastOption")] - internal static extern unsafe Error GetIPv6MulticastOption(SafeHandle socket, MulticastOption multicastOption, IPv6MulticastOption* option); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetIPv6MulticastOption")] - internal static extern unsafe Error SetIPv6MulticastOption(SafeHandle socket, MulticastOption multicastOption, IPv6MulticastOption* option); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.POpen.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.POpen.cs deleted file mode 100644 index 06854f0a45..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.POpen.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_POpen", SetLastError = true)] - internal static extern IntPtr POpen(string command, string type); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PClose", SetLastError = true)] - internal static extern int PClose(IntPtr stream); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Pipe.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Pipe.cs deleted file mode 100644 index 4cea90805d..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Pipe.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [Flags] - internal enum PipeFlags - { - O_CLOEXEC = 0x0010, - } - - /// - /// The index into the array filled by which represents the read end of the pipe. - /// - internal const int ReadEndOfPipe = 0; - - /// - /// The index into the array filled by which represents the read end of the pipe. - /// - internal const int WriteEndOfPipe = 1; - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Pipe", SetLastError = true)] - internal static extern unsafe int Pipe(int* pipefd, PipeFlags flags = 0); // pipefd is an array of two ints - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.PlatformSocketSupport.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.PlatformSocketSupport.cs deleted file mode 100644 index a148f64c0c..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.PlatformSocketSupport.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PlatformSupportsDualModeIPv4PacketInfo")] - internal static extern bool PlatformSupportsDualModeIPv4PacketInfo(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Poll.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Poll.cs deleted file mode 100644 index 255cd55291..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Poll.cs +++ /dev/null @@ -1,78 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - [Flags] - internal enum PollEvents : short - { - POLLNONE = 0x0000, // No events occurred. - POLLIN = 0x0001, // non-urgent readable data available - POLLPRI = 0x0002, // urgent readable data available - POLLOUT = 0x0004, // data can be written without blocked - POLLERR = 0x0008, // an error occurred - POLLHUP = 0x0010, // the file descriptor hung up - POLLNVAL = 0x0020, // the requested events were invalid - } - - internal struct PollEvent - { - internal int FileDescriptor; // The file descriptor to poll - internal PollEvents Events; // The events to poll for - internal PollEvents TriggeredEvents; // The events that occurred which triggered the poll - } - - /// - /// Polls a set of file descriptors for signals and returns what signals have been set - /// - /// A list of PollEvent entries - /// The number of entries in pollEvents - /// The amount of time to wait; -1 for infinite, 0 for immediate return, and a positive number is the number of milliseconds - /// The number of events triggered (i.e. the number of entries in pollEvents with a non-zero TriggeredEvents). May be zero in the event of a timeout. - /// An error or Error.SUCCESS. - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Poll")] - internal static extern unsafe Error Poll(PollEvent* pollEvents, uint eventCount, int timeout, uint* triggered); - - /// - /// Polls a File Descriptor for the passed in flags. - /// - /// The descriptor to poll - /// The events to poll for - /// The amount of time to wait; -1 for infinite, 0 for immediate return, and a positive number is the number of milliseconds - /// The events that were returned by the poll call. May be PollEvents.POLLNONE in the case of a timeout. - /// An error or Error.SUCCESS. - internal static unsafe Error Poll(SafeHandle fd, PollEvents events, int timeout, out PollEvents triggered) - { - bool gotRef = false; - try - { - fd.DangerousAddRef(ref gotRef); - - var pollEvent = new PollEvent - { - FileDescriptor = fd.DangerousGetHandle().ToInt32(), - Events = events, - }; - - uint unused; - Error err = Poll(&pollEvent, 1, timeout, &unused); - triggered = pollEvent.TriggeredEvents; - return err; - } - finally - { - if (gotRef) - { - fd.DangerousRelease(); - } - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.PrintF.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.PrintF.cs deleted file mode 100644 index 465c34e4bb..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.PrintF.cs +++ /dev/null @@ -1,19 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - // printf takes a variable number of arguments, which is difficult to represent in C#. - // Instead, since we only have a small and fixed number of call sites, we declare - // an overload for each of the specific argument sets we need. - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_PrintF", SetLastError = true)] - internal static extern unsafe int PrintF(string format, string arg1); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ProcessorArchitecture.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ProcessorArchitecture.cs deleted file mode 100644 index 9535f392f1..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ProcessorArchitecture.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal enum ProcessorArchitecture - { - x86, - x64, - ARM, - ARM64 - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Read.Pipe.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Read.Pipe.cs deleted file mode 100644 index f41f6eefab..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Read.Pipe.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - /// - /// Reads a number of bytes from an open file descriptor into a specified buffer. - /// - /// The open file descriptor to try to read from - /// The buffer to read info into - /// The size of the buffer - /// - /// Returns the number of bytes read on success; otherwise, -1 is returned - /// Note - on fail. the position of the stream may change depending on the platform; consult man 2 read for more info - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Read", SetLastError = true)] - internal static extern unsafe int Read(SafePipeHandle fd, byte* buffer, int count); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ReadDir.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ReadDir.cs deleted file mode 100644 index 695d50ba2b..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ReadDir.cs +++ /dev/null @@ -1,86 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Text; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal static int ReadBufferSize { get; } = GetReadDirRBufferSize(); - - internal enum NodeType : int - { - DT_UNKNOWN = 0, - DT_FIFO = 1, - DT_CHR = 2, - DT_DIR = 4, - DT_BLK = 6, - DT_REG = 8, - DT_LNK = 10, - DT_SOCK = 12, - DT_WHT = 14 - } - - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct DirectoryEntry - { - internal byte* Name; - internal int NameLength; - internal NodeType InodeType; - - internal ReadOnlySpan GetName(Span buffer) - { - Debug.Assert(buffer.Length >= Encoding.UTF8.GetMaxCharCount(255), "should have enough space for the max file name"); - Debug.Assert(Name != null, "should not have a null name"); - - ReadOnlySpan nameBytes = (NameLength == -1) - // In this case the struct was allocated via struct dirent *readdir(DIR *dirp); - ? new ReadOnlySpan(Name, new ReadOnlySpan(Name, 255).IndexOf(0)) - : new ReadOnlySpan(Name, NameLength); - - Debug.Assert(nameBytes.Length > 0, "we shouldn't have gotten a garbage value from the OS"); - if (nameBytes.Length == 0) - return buffer.Slice(0, 0); - - int charCount = Encoding.UTF8.GetChars(nameBytes, buffer); - ReadOnlySpan value = buffer.Slice(0, charCount); - Debug.Assert(NameLength != -1 || value.IndexOf('\0') == -1, "should not have embedded nulls if we parsed the end of string"); - return value; - } - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_OpenDir", SetLastError = true)] - internal static extern IntPtr OpenDir(string path); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetReadDirRBufferSize", SetLastError = false)] - internal static extern int GetReadDirRBufferSize(); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadDirR", SetLastError = false)] - private static extern unsafe int ReadDirR(IntPtr dir, ref byte buffer, int bufferSize, ref DirectoryEntry outputEntry); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CloseDir", SetLastError = true)] - internal static extern int CloseDir(IntPtr dir); - - /// - /// Get the next directory entry for the given handle. **Note** the actual memory used may be allocated - /// by the OS and will be freed when the handle is closed. As such, the handle lifespan MUST be kept tightly - /// controlled. The DirectoryEntry name cannot be accessed after the handle is closed. - /// - /// Call to see what size buffer to allocate. - /// - internal static int ReadDir(IntPtr dir, Span buffer, ref DirectoryEntry entry) - { - // The calling pattern for ReadDir is described in src/Native/Unix/System.Native/pal_io.cpp|.h - Debug.Assert(buffer.Length >= ReadBufferSize, "should have a big enough buffer for the raw data"); - - // ReadBufferSize is zero when the native implementation does not support reading into a buffer. - return ReadDirR(dir, ref MemoryMarshal.GetReference(buffer), ReadBufferSize, ref entry); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ReadStdinUnbuffered.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ReadStdinUnbuffered.cs deleted file mode 100644 index 1b3b0ac7ea..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ReadStdinUnbuffered.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReadStdin", SetLastError = true)] - internal static extern unsafe int ReadStdin(byte* buffer, int bufferSize); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_InitializeConsoleBeforeRead")] - internal static extern unsafe void InitializeConsoleBeforeRead(byte minChars = 1, byte decisecondsTimeout = 0); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_UninitializeConsoleAfterRead")] - internal static extern unsafe void UninitializeConsoleAfterRead(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RealPath.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RealPath.cs deleted file mode 100644 index aabb54cc7c..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RealPath.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - /// - /// Takes a path containing relative subpaths or links and returns the absolute path. - /// This function works on both files and folders and returns a null-terminated string. - /// - /// The path to the file system object - /// Returns the result string on success and null on failure - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_RealPath", SetLastError = true)] - internal static extern string RealPath(string path); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ReceiveMessage.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ReceiveMessage.cs deleted file mode 100644 index 5a89ecf6de..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ReceiveMessage.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Net.Sockets; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ReceiveMessage")] - internal static extern unsafe Error ReceiveMessage(IntPtr socket, MessageHeader* messageHeader, SocketFlags flags, long* received); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RegisterForCtrlC.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RegisterForCtrlC.cs deleted file mode 100644 index 603d8fa68b..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RegisterForCtrlC.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal partial class Interop -{ - internal partial class Sys - { - internal enum CtrlCode - { - Interrupt = 0, - Break = 1 - } - - internal delegate void CtrlCallback(CtrlCode ctrlCode); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_RegisterForCtrl")] - internal static extern void RegisterForCtrl(CtrlCallback handler); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_UnregisterForCtrl")] - internal static extern void UnregisterForCtrl(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RegisterForSigChld.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RegisterForSigChld.cs deleted file mode 100644 index f0d428d45c..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RegisterForSigChld.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal partial class Interop -{ - internal partial class Sys - { - internal delegate void SigChldCallback(bool reapAll); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_RegisterForSigChld")] - internal static extern bool RegisterForSigChld(SigChldCallback handler); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Rename.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Rename.cs deleted file mode 100644 index a82d913a15..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Rename.cs +++ /dev/null @@ -1,23 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - /// - /// Renames a file, moving to the correct destination if necessary. There are many edge cases to this call, check man 2 rename for more info - /// - /// Path to the source item - /// Path to the desired new item - /// - /// Returns 0 on success; otherwise, returns -1 - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Rename", SetLastError = true)] - internal static extern int Rename(string oldPath, string newPath); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ResourceLimits.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ResourceLimits.cs deleted file mode 100644 index bf8bf00700..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ResourceLimits.cs +++ /dev/null @@ -1,40 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal const ulong RLIM_INFINITY = ulong.MaxValue; - - internal enum RlimitResources : int - { - RLIMIT_CPU = 0, // CPU limit in seconds - RLIMIT_FSIZE = 1, // Largest file that can be created, in bytes - RLIMIT_DATA = 2, // Maximum size of data segment, in bytes - RLIMIT_STACK = 3, // Maximum size of stack segment, in bytes - RLIMIT_CORE = 4, // Largest core file that can be created, in bytes - RLIMIT_AS = 5, // Address space limit - RLIMIT_RSS = 6, // Largest resident set size, in bytes - RLIMIT_MEMLOCK = 7, // Locked-in-memory address space - RLIMIT_NPROC = 8, // Number of processes - RLIMIT_NOFILE = 9, // Number of open files - } - - [StructLayout(LayoutKind.Sequential)] - internal struct RLimit - { - internal ulong CurrentLimit; - internal ulong MaximumLimit; - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetRLimit", SetLastError = true)] - internal static extern int GetRLimit(RlimitResources resourceType, out RLimit limits); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetRLimit", SetLastError = true)] - internal static extern int SetRLimit(RlimitResources resourceType, ref RLimit limits); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RestoreAndHandleCtrl.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RestoreAndHandleCtrl.cs deleted file mode 100644 index 0f7b1a1e12..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RestoreAndHandleCtrl.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal partial class Interop -{ - internal partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_RestoreAndHandleCtrl")] - internal static extern void RestoreAndHandleCtrl(CtrlCode ctrlCode); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RmDir.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RmDir.cs deleted file mode 100644 index ddc0c3ad34..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.RmDir.cs +++ /dev/null @@ -1,22 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - /// - /// Deletes the specified empty directory. - /// - /// The path of the directory to delete - /// - /// Returns 0 on success; otherwise, returns -1 - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_RmDir", SetLastError = true)] - internal static extern int RmDir(string path); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SNPrintF.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SNPrintF.cs deleted file mode 100644 index 61fa8d60a0..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SNPrintF.cs +++ /dev/null @@ -1,54 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - /// - /// Takes a string and applies a formatting to it to transform - /// parameters to input values (such as replacing %s in the string with a variable) - /// - /// The output buffer to put the transformed data into - /// The size of the output buffer - /// The input string with wildcards to be replaced - /// The argument to replace a wildcard with - /// - /// Since snprintf has a variadic parameter, which cannot be described by C#, we have different - /// PInvokes declared for each one we need. The PInvoke layer will take care of putting the - /// arguments in correctly. - /// - /// - /// Returns the number of characters (excluding null terminator) written to the buffer on - /// success; if the return value is equal to the size then the result may have been truncated. - /// On failure, returns a negative value. - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SNPrintF", SetLastError = true)] - internal static extern unsafe int SNPrintF(byte* str, int size, string format, string arg1); - - /// - /// Takes a string and applies a formatting to it to transform - /// parameters to input values (such as replacing %s in the string with a variable) - /// - /// The output buffer to put the transformed data into - /// The size of the output buffer - /// The input string with wildcards to be replaced - /// The argument to replace a wildcard with - /// - /// Since snprintf has a variadic parameter, which cannot be described by C#, we have different - /// PInvokes declared for each one we need. The PInvoke layer will take care of putting the - /// arguments in correctly. - /// - /// - /// Returns the number of characters (excluding null terminator) written to the buffer on - /// success; if the return value is equal to the size then the result may have been truncated. - /// On failure, returns a negative value. - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SNPrintF", SetLastError = true)] - internal static extern unsafe int SNPrintF(byte* str, int size, string format, int arg1); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SchedGetSetAffinity.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SchedGetSetAffinity.cs deleted file mode 100644 index 881223aeff..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SchedGetSetAffinity.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SchedSetAffinity", SetLastError = true)] - internal static extern int SchedSetAffinity(int pid, ref IntPtr mask); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SchedGetAffinity", SetLastError = true)] - internal static extern int SchedGetAffinity(int pid, out IntPtr mask); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SendFile.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SendFile.cs deleted file mode 100644 index b253a59b0d..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SendFile.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SendFile", SetLastError = true)] - internal static extern unsafe Error SendFile(SafeHandle out_fd, SafeHandle in_fd, long offset, long count, out long sent); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SendMessage.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SendMessage.cs deleted file mode 100644 index 62cca3bdb5..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SendMessage.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Net.Sockets; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SendMessage")] - internal static extern unsafe Error SendMessage(IntPtr socket, MessageHeader* messageHeader, SocketFlags flags, long* sent); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetEUid.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetEUid.cs deleted file mode 100644 index 8f537f8b46..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetEUid.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetEUid")] - internal static extern unsafe int SetEUid(uint euid); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetReceiveTimeout.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetReceiveTimeout.cs deleted file mode 100644 index b1bf252f25..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetReceiveTimeout.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Net.Sockets; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetReceiveTimeout")] - internal static extern unsafe Error SetReceiveTimeout(SafeHandle socket, int millisecondsTimeout); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetSendTimeout.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetSendTimeout.cs deleted file mode 100644 index 89a3bfbbf6..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetSendTimeout.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Net.Sockets; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetSendTimeout")] - internal static extern unsafe Error SetSendTimeout(SafeHandle socket, int millisecondsTimeout); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetSignalForBreak.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetSignalForBreak.cs deleted file mode 100644 index 40eacccd5a..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetSignalForBreak.cs +++ /dev/null @@ -1,17 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetSignalForBreak")] - internal static extern bool GetSignalForBreak(); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetSignalForBreak")] - internal static extern bool SetSignalForBreak(bool signalForBreak); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetSockOpt.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetSockOpt.cs deleted file mode 100644 index 4c92eccaca..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SetSockOpt.cs +++ /dev/null @@ -1,19 +0,0 @@ -// 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. - -using System; -using System.Net.Sockets; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetSockOpt")] - internal static extern unsafe Error SetSockOpt(SafeHandle socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte* optionValue, int optionLen); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetSockOpt")] - internal static extern unsafe Error SetSockOpt(IntPtr socket, SocketOptionLevel optionLevel, SocketOptionName optionName, byte* optionValue, int optionLen); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ShmOpen.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ShmOpen.cs deleted file mode 100644 index 8481c61dd1..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.ShmOpen.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ShmOpen", SetLastError = true)] - internal static extern SafeFileHandle ShmOpen(string name, OpenFlags flags, int mode); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_ShmUnlink", SetLastError = true)] - internal static extern int ShmUnlink(string name); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Shutdown.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Shutdown.cs deleted file mode 100644 index ad5e72945b..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Shutdown.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Net.Sockets; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Shutdown")] - internal static extern Error Shutdown(SafeHandle socket, SocketShutdown how); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Socket.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Socket.cs deleted file mode 100644 index e69171690c..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Socket.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - -using System; -using System.Net; -using System.Net.Internals; -using System.Net.Sockets; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Socket")] - internal static extern unsafe Error Socket(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, IntPtr* socket); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SocketAddress.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SocketAddress.cs deleted file mode 100644 index 86a83fdf8c..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SocketAddress.cs +++ /dev/null @@ -1,40 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPSocketAddressSizes")] - internal static extern unsafe Error GetIPSocketAddressSizes(int* ipv4SocketAddressSize, int* ipv6SocketAddressSize); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetAddressFamily")] - internal static extern unsafe Error GetAddressFamily(byte* socketAddress, int socketAddressLen, int* addressFamily); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetAddressFamily")] - internal static extern unsafe Error SetAddressFamily(byte* socketAddress, int socketAddressLen, int addressFamily); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetPort")] - internal static extern unsafe Error GetPort(byte* socketAddress, int socketAddressLen, ushort* port); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetPort")] - internal static extern unsafe Error SetPort(byte* socketAddress, int socketAddressLen, ushort port); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPv4Address")] - internal static extern unsafe Error GetIPv4Address(byte* socketAddress, int socketAddressLen, uint* address); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetIPv4Address")] - internal static extern unsafe Error SetIPv4Address(byte* socketAddress, int socketAddressLen, uint address); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetIPv6Address")] - internal static extern unsafe Error GetIPv6Address(byte* socketAddress, int socketAddressLen, byte* address, int addressLen, uint* scopeId); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SetIPv6Address")] - internal static extern unsafe Error SetIPv6Address(byte* socketAddress, int socketAddressLen, byte* address, int addressLen, uint scopeId); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SocketEvent.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SocketEvent.cs deleted file mode 100644 index 7752f309aa..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SocketEvent.cs +++ /dev/null @@ -1,52 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [Flags] - internal enum SocketEvents : int - { - None = 0x00, - Read = 0x01, - Write = 0x02, - ReadClose = 0x04, - Close = 0x08, - Error = 0x10 - } - - [StructLayout(LayoutKind.Sequential)] - internal struct SocketEvent - { - public IntPtr Data; - public SocketEvents Events; - private int _padding; - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateSocketEventPort")] - internal static extern unsafe Error CreateSocketEventPort(out IntPtr port); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CloseSocketEventPort")] - internal static extern Error CloseSocketEventPort(IntPtr port); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateSocketEventBuffer")] - internal static extern unsafe Error CreateSocketEventBuffer(int count, out SocketEvent* buffer); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FreeSocketEventBuffer")] - internal static extern unsafe Error FreeSocketEventBuffer(SocketEvent* buffer); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_TryChangeSocketEventRegistration")] - internal static extern Error TryChangeSocketEventRegistration(IntPtr port, SafeHandle socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_TryChangeSocketEventRegistration")] - internal static extern Error TryChangeSocketEventRegistration(IntPtr port, IntPtr socket, SocketEvents currentEvents, SocketEvents newEvents, IntPtr data); - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_WaitForSocketEvents")] - internal static extern unsafe Error WaitForSocketEvents(IntPtr port, SocketEvent* buffer, int* count); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Stat.Pipe.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Stat.Pipe.cs deleted file mode 100644 index 7985cebaa6..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Stat.Pipe.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_FStat2", SetLastError = true)] - internal static extern int FStat(SafePipeHandle fd, out FileStatus output); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Stat.Span.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Stat.Span.cs deleted file mode 100644 index 6216a6bda8..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Stat.Span.cs +++ /dev/null @@ -1,41 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Sys - { - // Unix max paths are typically 1K or 4K UTF-8 bytes, 256 should handle the majority of paths - // without putting too much pressure on the stack. - private const int StackBufferSize = 256; - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Stat2", SetLastError = true)] - internal unsafe static extern int Stat(ref byte path, out FileStatus output); - - internal unsafe static int Stat(ReadOnlySpan path, out FileStatus output) - { - byte* buffer = stackalloc byte[StackBufferSize]; - var converter = new ValueUtf8Converter(new Span(buffer, StackBufferSize)); - int result = Stat(ref MemoryMarshal.GetReference(converter.ConvertAndTerminateString(path)), out output); - converter.Dispose(); - return result; - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_LStat2", SetLastError = true)] - internal static extern int LStat(ref byte path, out FileStatus output); - - internal unsafe static int LStat(ReadOnlySpan path, out FileStatus output) - { - byte* buffer = stackalloc byte[StackBufferSize]; - var converter = new ValueUtf8Converter(new Span(buffer, StackBufferSize)); - int result = LStat(ref MemoryMarshal.GetReference(converter.ConvertAndTerminateString(path)), out output); - converter.Dispose(); - return result; - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.StdinReady.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.StdinReady.cs deleted file mode 100644 index 7a19512c66..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.StdinReady.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_StdinReady")] - internal static extern unsafe bool StdinReady(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Sync.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Sync.cs deleted file mode 100644 index babb2d6740..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Sync.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - /// - /// Forces a write of all modified I/O buffers to their storage mediums. - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Sync")] - internal static extern void Sync(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SysConf.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SysConf.cs deleted file mode 100644 index be0c0dee7b..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.SysConf.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal enum SysConfName - { - _SC_CLK_TCK = 1, - _SC_PAGESIZE = 2 - } - - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SysConf", SetLastError = true)] - internal static extern long SysConf(SysConfName name); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.UTimensat.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.UTimensat.cs deleted file mode 100644 index 769ca687e3..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.UTimensat.cs +++ /dev/null @@ -1,29 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - internal struct TimeSpec - { - internal long TvSec; - internal long TvNsec; - } - - /// - /// Sets the last access and last modified time of a file - /// - /// The path to the item to get time values for - /// The output time values of the item - /// - /// Returns 0 on success; otherwise, returns -1 - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_UTimensat", SetLastError = true)] - internal static extern int UTimensat(string path, ref TimeSpec times); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.WaitId.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.WaitId.cs deleted file mode 100644 index 3bf9e82e11..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.WaitId.cs +++ /dev/null @@ -1,23 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - /// - /// Returns the pid of a terminated child without reaping it. - /// - /// - /// 1) returns the process id of a terminated child process - /// 2) if no children are terminated, 0 is returned - /// 3) on error, -1 is returned - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_WaitIdAnyExitedNoHangNoWait", SetLastError = true)] - internal static extern int WaitIdAnyExitedNoHangNoWait(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.WaitPid.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.WaitPid.cs deleted file mode 100644 index 8292971d48..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.WaitPid.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Sys - { - /// - /// Reaps a terminated child. - /// - /// - /// 1) when a child is reaped, its process id is returned - /// 2) if pid is not a child or there are no unwaited-for children, -1 is returned (errno=ECHILD) - /// 3) if the child has not yet terminated, 0 is returned - /// 4) on error, -1 is returned. - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_WaitPidExitedNoHang", SetLastError = true)] - internal static extern int WaitPidExitedNoHang(int pid, out int exitCode); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Write.Pipe.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Write.Pipe.cs deleted file mode 100644 index 89bf8c3383..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.Write.Pipe.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Sys - { - /// - /// Writes the specified buffer to the provided open file descriptor - /// - /// The file descriptor to try and write to - /// The data to attempt to write - /// The amount of data to write, in bytes - /// - /// Returns the number of bytes written on success; otherwise, returns -1 and sets errno - /// - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_Write", SetLastError = true)] - internal static extern unsafe int Write(SafePipeHandle fd, byte* buffer, int bufferSize); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.CURLcode.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.CURLcode.cs deleted file mode 100644 index b2d0c5c0bb..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.CURLcode.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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. - -internal static partial class Interop -{ - internal static partial class Http - { - // Enum for constants defined for the enum CURLcode in curl.h - internal enum CURLcode - { - CURLE_OK = 0, - CURLE_UNSUPPORTED_PROTOCOL = 1, - CURLE_FAILED_INIT = 2, - CURLE_NOT_BUILT_IN = 4, - CURLE_COULDNT_RESOLVE_HOST = 6, - CURLE_OUT_OF_MEMORY = 27, - CURLE_OPERATION_TIMEDOUT = 28, - CURLE_ABORTED_BY_CALLBACK = 42, - CURLE_UNKNOWN_OPTION = 48, - CURLE_RECV_ERROR = 56, - CURLE_SEND_FAIL_REWIND = 65 - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.Easy.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.Easy.cs deleted file mode 100644 index ab3200b333..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.Easy.cs +++ /dev/null @@ -1,268 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Http - { - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EasyCreate")] - public static extern SafeCurlHandle EasyCreate(); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EasyDestroy")] - private static extern void EasyDestroy(IntPtr handle); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EasySetOptionString", CharSet = CharSet.Ansi)] - public static extern CURLcode EasySetOptionString(SafeCurlHandle curl, CURLoption option, string value); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EasySetOptionLong")] - public static extern CURLcode EasySetOptionLong(SafeCurlHandle curl, CURLoption option, long value); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EasySetOptionPointer")] - public static extern CURLcode EasySetOptionPointer(SafeCurlHandle curl, CURLoption option, IntPtr value); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EasySetOptionPointer")] - public static extern CURLcode EasySetOptionPointer(SafeCurlHandle curl, CURLoption option, SafeHandle value); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EasyGetErrorString")] - public static extern IntPtr EasyGetErrorString(int code); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EasyGetInfoPointer")] - public static extern CURLcode EasyGetInfoPointer(IntPtr handle, CURLINFO info, out IntPtr value); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EasyGetInfoPointer")] - public static extern CURLcode EasyGetInfoPointer(SafeCurlHandle handle, CURLINFO info, out IntPtr value); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EasyGetInfoLong")] - public static extern CURLcode EasyGetInfoLong(SafeCurlHandle handle, CURLINFO info, out long value); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EasyPerform")] - public static extern CURLcode EasyPerform(SafeCurlHandle curl); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EasyUnpause")] - public static extern CURLcode EasyUnpause(SafeCurlHandle easy); - - public delegate CurlSeekResult SeekCallback(IntPtr userPointer, long offset, int origin); - - public delegate ulong ReadWriteCallback(IntPtr buffer, ulong bufferSize, ulong nitems, IntPtr userPointer); - - public delegate CURLcode SslCtxCallback(IntPtr curl, IntPtr sslCtx, IntPtr userPointer); - - public delegate void DebugCallback(IntPtr curl, CurlInfoType type, IntPtr data, ulong size, IntPtr userPointer); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_RegisterSeekCallback")] - public static extern void RegisterSeekCallback( - SafeCurlHandle curl, - SeekCallback callback, - IntPtr userPointer, - ref SafeCallbackHandle callbackHandle); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_RegisterReadWriteCallback")] - public static extern void RegisterReadWriteCallback( - SafeCurlHandle curl, - ReadWriteFunction functionType, - ReadWriteCallback callback, - IntPtr userPointer, - ref SafeCallbackHandle callbackHandle); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_RegisterSslCtxCallback")] - public static extern CURLcode RegisterSslCtxCallback( - SafeCurlHandle curl, - SslCtxCallback callback, - IntPtr userPointer, - ref SafeCallbackHandle callbackHandle); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_RegisterDebugCallback")] - public static extern CURLcode RegisterDebugCallback( - SafeCurlHandle curl, - DebugCallback callback, - IntPtr userPointer, - ref SafeCallbackHandle callbackHandle); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_FreeCallbackHandle")] - private static extern void FreeCallbackHandle(IntPtr handle); - - // Curl options are of the format + - private const int CurlOptionLongBase = 0; - private const int CurlOptionObjectPointBase = 10000; - private const int CurlOptionOffTBase = 30000; - - // Enum for constants defined for the enum CURLoption in curl.h - internal enum CURLoption - { - CURLOPT_INFILESIZE = CurlOptionLongBase + 14, - CURLOPT_SSLVERSION = CurlOptionLongBase + 32, - CURLOPT_VERBOSE = CurlOptionLongBase + 41, - CURLOPT_NOBODY = CurlOptionLongBase + 44, - CURLOPT_UPLOAD = CurlOptionLongBase + 46, - CURLOPT_POST = CurlOptionLongBase + 47, - CURLOPT_FOLLOWLOCATION = CurlOptionLongBase + 52, - CURLOPT_PROXYPORT = CurlOptionLongBase + 59, - CURLOPT_POSTFIELDSIZE = CurlOptionLongBase + 60, - CURLOPT_SSL_VERIFYPEER = CurlOptionLongBase + 64, - CURLOPT_MAXREDIRS = CurlOptionLongBase + 68, - CURLOPT_SSL_VERIFYHOST = CurlOptionLongBase + 81, - CURLOPT_HTTP_VERSION = CurlOptionLongBase + 84, - CURLOPT_DNS_CACHE_TIMEOUT = CurlOptionLongBase + 92, - CURLOPT_NOSIGNAL = CurlOptionLongBase + 99, - CURLOPT_PROXYTYPE = CurlOptionLongBase + 101, - CURLOPT_HTTPAUTH = CurlOptionLongBase + 107, - CURLOPT_TCP_NODELAY = CurlOptionLongBase + 121, - CURLOPT_TCP_KEEPALIVE = CurlOptionLongBase + 213, - CURLOPT_CONNECTTIMEOUT_MS = CurlOptionLongBase + 156, - CURLOPT_ADDRESS_SCOPE = CurlOptionLongBase + 171, - CURLOPT_PROTOCOLS = CurlOptionLongBase + 181, - CURLOPT_REDIR_PROTOCOLS = CurlOptionLongBase + 182, - - CURLOPT_URL = CurlOptionObjectPointBase + 2, - CURLOPT_PROXY = CurlOptionObjectPointBase + 4, - CURLOPT_PROXYUSERPWD = CurlOptionObjectPointBase + 6, - CURLOPT_COOKIE = CurlOptionObjectPointBase + 22, - CURLOPT_HTTPHEADER = CurlOptionObjectPointBase + 23, - CURLOPT_CUSTOMREQUEST = CurlOptionObjectPointBase + 36, - CURLOPT_ACCEPT_ENCODING = CurlOptionObjectPointBase + 102, - CURLOPT_PRIVATE = CurlOptionObjectPointBase + 103, - CURLOPT_COPYPOSTFIELDS = CurlOptionObjectPointBase + 165, - CURLOPT_USERNAME = CurlOptionObjectPointBase + 173, - CURLOPT_PASSWORD = CurlOptionObjectPointBase + 174, - CURLOPT_CAPATH = CurlOptionObjectPointBase + 97, - CURLOPT_PROXY_CAPATH = CurlOptionObjectPointBase + 247, - CURLOPT_CAINFO = CurlOptionObjectPointBase + 65, - CURLOPT_PROXY_CAINFO = CurlOptionObjectPointBase + 246, - - CURLOPT_INFILESIZE_LARGE = CurlOptionOffTBase + 115, - CURLOPT_POSTFIELDSIZE_LARGE = CurlOptionOffTBase + 120, - } - - internal enum ReadWriteFunction - { - Write = 0, - Read = 1, - Header = 2, - } - - // Curl info are of the format + - private const int CurlInfoStringBase = 0x100000; - private const int CurlInfoLongBase = 0x200000; - - // Enum for constants defined for CURL_HTTP_VERSION - internal enum CurlHttpVersion - { - CURL_HTTP_VERSION_NONE = 0, - CURL_HTTP_VERSION_1_0 = 1, - CURL_HTTP_VERSION_1_1 = 2, - CURL_HTTP_VERSION_2TLS = 4, - }; - - // Enum for constants defined for CURL_SSLVERSION - internal enum CurlSslVersion - { - CURL_SSLVERSION_TLSv1 = 1, /* TLS 1.x */ - CURL_SSLVERSION_SSLv2 = 2, /* SSL 2 */ - CURL_SSLVERSION_SSLv3 = 3, /* SSL 3 */ - CURL_SSLVERSION_TLSv1_0 = 4, /* TLS 1.0 */ - CURL_SSLVERSION_TLSv1_1 = 5, /* TLS 1.1 */ - CURL_SSLVERSION_TLSv1_2 = 6, /* TLS 1.2 */ - }; - - // Enum for constants defined for the enum CURLINFO in curl.h - internal enum CURLINFO - { - CURLINFO_EFFECTIVE_URL = CurlInfoStringBase + 1, - CURLINFO_PRIVATE = CurlInfoStringBase + 21, - CURLINFO_HTTPAUTH_AVAIL = CurlInfoLongBase + 23, - } - - // AUTH related constants - [Flags] - internal enum CURLAUTH - { - None = 0, - Basic = 1 << 0, - Digest = 1 << 1, - Negotiate = 1 << 2, - NTLM = 1 << 3, - } - - // Enum for constants defined for the enum curl_proxytype in curl.h - internal enum curl_proxytype - { - CURLPROXY_HTTP = 0, - } - - [Flags] - internal enum CurlProtocols - { - CURLPROTO_HTTP = (1 << 0), - CURLPROTO_HTTPS = (1 << 1), - } - - // Enum for constants defined for the results of CURL_SEEKFUNCTION - internal enum CurlSeekResult : int - { - CURL_SEEKFUNC_OK = 0, - CURL_SEEKFUNC_FAIL = 1, - CURL_SEEKFUNC_CANTSEEK = 2, - } - - internal enum CurlInfoType : int - { - CURLINFO_TEXT = 0, - CURLINFO_HEADER_IN = 1, - CURLINFO_HEADER_OUT = 2, - CURLINFO_DATA_IN = 3, - CURLINFO_DATA_OUT = 4, - CURLINFO_SSL_DATA_IN = 5, - CURLINFO_SSL_DATA_OUT = 6, - }; - - // constants defined for the results of a CURL_READ or CURL_WRITE function - internal const ulong CURL_READFUNC_ABORT = 0x10000000; - internal const ulong CURL_READFUNC_PAUSE = 0x10000001; - internal const ulong CURL_WRITEFUNC_PAUSE = 0x10000001; - - internal const ulong CURL_MAX_HTTP_HEADER = 100 * 1024; - - internal sealed class SafeCurlHandle : SafeHandle - { - public SafeCurlHandle() : base(IntPtr.Zero, true) - { - } - - public override bool IsInvalid - { - get { return handle == IntPtr.Zero; } - } - - protected override bool ReleaseHandle() - { - EasyDestroy(handle); - SetHandle(IntPtr.Zero); - return true; - } - } - - internal sealed class SafeCallbackHandle : SafeHandle - { - public SafeCallbackHandle() - : base(IntPtr.Zero, true) - { - } - - public override bool IsInvalid - { - get { return handle == IntPtr.Zero; } - } - - protected override bool ReleaseHandle() - { - FreeCallbackHandle(handle); - SetHandle(IntPtr.Zero); - return true; - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.Initialization.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.Initialization.cs deleted file mode 100644 index eef56ec0b3..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.Initialization.cs +++ /dev/null @@ -1,52 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - // Initialization of libcurl is done in a static constructor. - // This enables a project simply to include this file, and any usage of any of - // the Http functions will trigger initialization. - - internal static partial class Http - { - static Http() - { - HttpInitializer.Initialize(); - } - } - - internal static class HttpInitializer - { - static HttpInitializer() - { -#if !SYSNETHTTP_NO_OPENSSL - string opensslVersion = Interop.Http.GetSslVersionDescription(); - if (string.IsNullOrEmpty(opensslVersion) || - opensslVersion.IndexOf(Interop.Http.OpenSsl10Description, StringComparison.OrdinalIgnoreCase) != -1) - { - // CURL uses OpenSSL which we must initialize first to guarantee thread-safety - // Only initialize for OpenSSL/1.0, any newer versions may have mismatched - // pointers, resulting in segfaults. - CryptoInitializer.Initialize(); - } -#endif - - if (EnsureCurlIsInitialized() != 0) - { - throw new InvalidOperationException(); - } - } - - internal static void Initialize() - { - // No-op that exists to provide a hook for other static constructors - } - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_EnsureCurlIsInitialized")] - private static extern int EnsureCurlIsInitialized(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.Multi.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.Multi.cs deleted file mode 100644 index f3c058e319..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.Multi.cs +++ /dev/null @@ -1,104 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Http - { - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_MultiCreate")] - public static extern SafeCurlMultiHandle MultiCreate(); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_MultiDestroy")] - private static extern CURLMcode MultiDestroy(IntPtr handle); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_MultiAddHandle")] - public static extern CURLMcode MultiAddHandle(SafeCurlMultiHandle multiHandle, SafeCurlHandle easyHandle); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_MultiRemoveHandle")] - public static extern CURLMcode MultiRemoveHandle(SafeCurlMultiHandle multiHandle, SafeCurlHandle easyHandle); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_MultiWait")] - public static extern CURLMcode MultiWait( - SafeCurlMultiHandle multiHandle, - SafeFileHandle extraFileDescriptor, - out bool isExtraFileDescriptorActive, - out bool isTimeout); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_MultiPerform")] - public static extern CURLMcode MultiPerform(SafeCurlMultiHandle multiHandle); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_MultiInfoRead")] - public static extern bool MultiInfoRead( - SafeCurlMultiHandle multiHandle, - out CURLMSG message, - out IntPtr easyHandle, - out CURLcode result); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_MultiGetErrorString")] - public static extern IntPtr MultiGetErrorString(int code); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_MultiSetOptionLong")] - public static extern CURLMcode MultiSetOptionLong(SafeCurlMultiHandle curl, CURLMoption option, long value); - - // Enum for constants defined for the enum CURLMcode in multi.h - internal enum CURLMcode : int - { - CURLM_CALL_MULTI_PERFORM = -1, - CURLM_OK = 0, - CURLM_BAD_HANDLE = 1, - CURLM_BAD_EASY_HANDLE = 2, - CURLM_OUT_OF_MEMORY = 3, - CURLM_INTERNAL_ERROR = 4, - CURLM_BAD_SOCKET = 5, - CURLM_UNKNOWN_OPTION = 6, - CURLM_ADDED_ALREADY = 7, - } - - internal enum CURLMoption : int - { - CURLMOPT_PIPELINING = 3, - CURLMOPT_MAX_HOST_CONNECTIONS = 7, - } - - internal enum CurlPipe : int - { - CURLPIPE_MULTIPLEX = 2 - } - - // Enum for constants defined for the enum CURLMSG in multi.h - internal enum CURLMSG : int - { - CURLMSG_DONE = 1, - } - - internal sealed class SafeCurlMultiHandle : SafeHandle - { - public SafeCurlMultiHandle() - : base(IntPtr.Zero, true) - { - } - - public override bool IsInvalid - { - get { return this.handle == IntPtr.Zero; } - } - - protected override bool ReleaseHandle() - { - bool result = MultiDestroy(handle) == CURLMcode.CURLM_OK; - SetHandle(IntPtr.Zero); - -#if !SYSNETHTTP_NO_OPENSSL - Interop.Crypto.ErrClearError(); // Ensure that no SSL errors were left on the queue by libcurl. -#endif - - return result; - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.SList.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.SList.cs deleted file mode 100644 index 58fe776f93..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.SList.cs +++ /dev/null @@ -1,63 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Http - { - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_SListAppend", CharSet = CharSet.Ansi)] - private static extern IntPtr SListAppend(IntPtr slist, string headerValue); - - internal static bool SListAppend(SafeCurlSListHandle slist, string headerValue) - { - bool gotRef = false; - try - { - slist.DangerousAddRef(ref gotRef); - IntPtr newHandle = SListAppend(slist.DangerousGetHandle(), headerValue); - if (newHandle != IntPtr.Zero) - { - slist.SetHandle(newHandle); - return true; - } - return false; - } - finally - { - if (gotRef) - slist.DangerousRelease(); - } - } - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_SListFreeAll")] - private static extern void SListFreeAll(IntPtr slist); - - internal sealed class SafeCurlSListHandle : SafeHandle - { - public SafeCurlSListHandle() : base(IntPtr.Zero, true) - { - } - - public override bool IsInvalid - { - get { return handle == IntPtr.Zero; } - } - - public new void SetHandle(IntPtr newHandle) - { - base.SetHandle(newHandle); - } - - protected override bool ReleaseHandle() - { - SListFreeAll(handle); - SetHandle(IntPtr.Zero); - return true; - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.VersionInfo.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.VersionInfo.cs deleted file mode 100644 index 1899fd0af3..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Http.Native/Interop.VersionInfo.cs +++ /dev/null @@ -1,54 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Http - { - [Flags] - internal enum CurlFeatures : int - { - CURL_VERSION_IPV6 = (1 << 0), - CURL_VERSION_KERBEROS4 = (1 << 1), - CURL_VERSION_SSL = (1 << 2), - CURL_VERSION_LIBZ = (1 << 3), - CURL_VERSION_NTLM = (1 << 4), - CURL_VERSION_GSSNEGOTIATE = (1 << 5), - CURL_VERSION_DEBUG = (1 << 6), - CURL_VERSION_ASYNCHDNS = (1 << 7), - CURL_VERSION_SPNEGO = (1 << 8), - CURL_VERSION_LARGEFILE = (1 << 9), - CURL_VERSION_IDN = (1 << 10), - CURL_VERSION_SSPI = (1 << 11), - CURL_VERSION_CONV = (1 << 12), - CURL_VERSION_CURLDEBUG = (1 << 13), - CURL_VERSION_TLSAUTH_SRP = (1 << 14), - CURL_VERSION_NTLM_WB = (1 << 15), - CURL_VERSION_HTTP2 = (1 << 16), - CURL_VERSION_GSSAPI = (1 << 17), - CURL_VERSION_KERBEROS5 = (1 << 18), - CURL_VERSION_UNIX_SOCKETS = (1 << 19), - CURL_VERSION_PSL = (1 << 20), - }; - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_GetSupportedFeatures")] - internal static extern CurlFeatures GetSupportedFeatures(); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_GetSupportsHttp2Multiplexing")] - internal static extern bool GetSupportsHttp2Multiplexing(); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_GetVersionDescription")] - internal static extern string GetVersionDescription(); - - [DllImport(Libraries.HttpNative, EntryPoint = "HttpNative_GetSslVersionDescription")] - internal static extern string GetSslVersionDescription(); - - internal const string OpenSsl10Description = "openssl/1.0"; - internal const string SecureTransportDescription = "SecureTransport"; - internal const string LibreSslDescription = "LibreSSL"; - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.GetIntegerBytes.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.GetIntegerBytes.cs deleted file mode 100644 index 692abb2ab4..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.GetIntegerBytes.cs +++ /dev/null @@ -1,45 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using System.Text; - -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetAsn1IntegerDerSize")] - private static extern int GetAsn1IntegerDerSize(SafeSharedAsn1IntegerHandle i); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EncodeAsn1Integer")] - private static extern int EncodeAsn1Integer(SafeSharedAsn1IntegerHandle i, byte[] buf); - - internal static byte[] GetAsn1IntegerBytes(SafeSharedAsn1IntegerHandle asn1Integer) - { - CheckValidOpenSslHandle(asn1Integer); - - // OpenSSL stores negative numbers in their two's complement (positive) form, but - // sets an internal negative bit. - // - // If the number was positive, but could sign-test as negative, DER puts in a leading - // 0x00 byte, which reading OpenSSL's data directly won't have. - // - // So to ensure we're getting a set of bytes compatible with BigInteger (though with the - // wrong endianness here), DER encode it, then use the DER reader to skip past the tag - // and length. - byte[] derEncoded = OpenSslEncode( - handle => GetAsn1IntegerDerSize(handle), - (handle, buf) => EncodeAsn1Integer(handle, buf), - asn1Integer); - - DerSequenceReader reader = DerSequenceReader.CreateForPayload(derEncoded); - return reader.ReadIntegerBytes(); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.Nid.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.Nid.cs deleted file mode 100644 index afc79ae504..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.Nid.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Crypto - { - internal const int NID_undef = 0; - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ObjSn2Nid", CharSet = CharSet.Ansi)] - internal static extern int ObjSn2Nid(string sn); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.cs deleted file mode 100644 index 5bd2e8b9b4..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.cs +++ /dev/null @@ -1,113 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security.Cryptography; - -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ObjTxt2Obj", CharSet = CharSet.Ansi)] - internal static extern SafeAsn1ObjectHandle ObjTxt2Obj(string s); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ObjObj2Txt")] - private static extern unsafe int ObjObj2Txt(byte* buf, int buf_len, IntPtr a); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetObjectDefinitionByName", CharSet = CharSet.Ansi)] - private static extern IntPtr CryptoNative_GetObjectDefinitionByName(string friendlyName); - internal static IntPtr GetObjectDefinitionByName(string friendlyName) - { - IntPtr ret = CryptoNative_GetObjectDefinitionByName(friendlyName); - if (ret == IntPtr.Zero) - { - ErrClearError(); - } - - return ret; - } - - // Returns shared pointers, should not be tracked as a SafeHandle. - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ObjNid2Obj")] - internal static extern IntPtr ObjNid2Obj(int nid); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Asn1ObjectFree")] - internal static extern void Asn1ObjectFree(IntPtr o); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DecodeAsn1BitString")] - internal static extern SafeAsn1BitStringHandle DecodeAsn1BitString(byte[] buf, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Asn1BitStringFree")] - internal static extern void Asn1BitStringFree(IntPtr o); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DecodeAsn1OctetString")] - internal static extern SafeAsn1OctetStringHandle DecodeAsn1OctetString(byte[] buf, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Asn1OctetStringNew")] - internal static extern SafeAsn1OctetStringHandle Asn1OctetStringNew(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Asn1OctetStringSet")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool Asn1OctetStringSet(SafeAsn1OctetStringHandle o, byte[] d, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Asn1OctetStringFree")] - internal static extern void Asn1OctetStringFree(IntPtr o); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Asn1StringFree")] - internal static extern void Asn1StringFree(IntPtr o); - - internal static unsafe string GetOidValue(IntPtr asn1ObjectPtr) - { - // OBJ_obj2txt returns the number of bytes that should have been in the answer, but it does not accept - // a NULL buffer. The documentation says "A buffer length of 80 should be more than enough to handle - // any OID encountered in practice", so start with a buffer of size 80, and try again if required. - const int StackCapacity = 80; - byte* bufStack = stackalloc byte[StackCapacity]; - - int bytesNeeded = ObjObj2Txt(bufStack, StackCapacity, asn1ObjectPtr); - - if (bytesNeeded < 0) - { - throw CreateOpenSslCryptographicException(); - } - - Debug.Assert(bytesNeeded != 0, "OBJ_obj2txt reported a zero-length response"); - - if (bytesNeeded < StackCapacity) - { - return Marshal.PtrToStringAnsi((IntPtr)bufStack, bytesNeeded); - } - - // bytesNeeded does not count the \0 which will be written on the end (based on OpenSSL 1.0.1f), - // so make sure to leave room for it. - int initialBytesNeeded = bytesNeeded; - byte[] bufHeap = new byte[bytesNeeded + 1]; - fixed (byte* buf = &bufHeap[0]) - { - bytesNeeded = ObjObj2Txt(buf, bufHeap.Length, asn1ObjectPtr); - - if (bytesNeeded < 0) - { - throw CreateOpenSslCryptographicException(); - } - - Debug.Assert( - bytesNeeded == initialBytesNeeded, - "OBJ_obj2txt changed the required number of bytes for the realloc call"); - - if (bytesNeeded > initialBytesNeeded) - { - // OBJ_obj2txt is demanding yet more memory - throw new CryptographicException(); - } - - return Marshal.PtrToStringAnsi((IntPtr)buf, bytesNeeded); - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.BIO.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.BIO.cs deleted file mode 100644 index ffa82ef001..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.BIO.cs +++ /dev/null @@ -1,39 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Text; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_CreateMemoryBio")] - internal static extern SafeBioHandle CreateMemoryBio(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_BioNewFile")] - internal static extern SafeBioHandle BioNewFile(string filename, string mode); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_BioDestroy")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool BioDestroy(IntPtr a); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_BioGets")] - internal static extern int BioGets(SafeBioHandle b, byte[] buf, int size); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_BioRead")] - internal static extern int BioRead(SafeBioHandle b, byte[] data, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_BioWrite")] - internal static extern int BioWrite(SafeBioHandle b, byte[] data, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetMemoryBioSize")] - internal static extern int GetMemoryBioSize(SafeBioHandle bio); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_BioCtrlPending")] - internal static extern int BioCtrlPending(SafeBioHandle bio); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Bignum.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Bignum.cs deleted file mode 100644 index 6faf7f8915..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Bignum.cs +++ /dev/null @@ -1,91 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_BigNumDestroy")] - internal static extern void BigNumDestroy(IntPtr a); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_BigNumFromBinary")] - private static extern IntPtr BigNumFromBinary(byte[] s, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_BigNumToBinary")] - private static extern unsafe int BigNumToBinary(SafeBignumHandle a, byte* to); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetBigNumBytes")] - private static extern int GetBigNumBytes(SafeBignumHandle a); - - private static IntPtr CreateBignumPtr(byte[] bigEndianValue) - { - if (bigEndianValue == null) - { - return IntPtr.Zero; - } - - IntPtr ret = BigNumFromBinary(bigEndianValue, bigEndianValue.Length); - - if (ret == IntPtr.Zero) - { - throw CreateOpenSslCryptographicException(); - } - - return ret; - } - - internal static SafeBignumHandle CreateBignum(byte[] bigEndianValue) - { - IntPtr handle = CreateBignumPtr(bigEndianValue); - return new SafeBignumHandle(handle, true); - } - - internal static byte[] ExtractBignum(IntPtr bignum, int targetSize) - { - // Given that the only reference held to bignum is an IntPtr, create an unowned SafeHandle - // to ensure that we don't destroy the key after extraction. - using (SafeBignumHandle handle = new SafeBignumHandle(bignum, ownsHandle: false)) - { - return ExtractBignum(handle, targetSize); - } - } - - private static unsafe byte[] ExtractBignum(SafeBignumHandle bignum, int targetSize) - { - if (bignum == null || bignum.IsInvalid) - { - return null; - } - - int compactSize = GetBigNumBytes(bignum); - - if (targetSize < compactSize) - { - targetSize = compactSize; - } - - // OpenSSL BIGNUM values do not record leading zeroes. - // Windows Crypt32 does. - // - // Since RSACryptoServiceProvider already checks that RSAParameters.DP.Length is - // exactly half of RSAParameters.Modulus.Length, we need to left-pad (big-endian) - // the array with zeroes. - int offset = targetSize - compactSize; - - byte[] buf = new byte[targetSize]; - - fixed (byte* to = buf) - { - byte* start = to + offset; - BigNumToBinary(bignum, start); - } - - return buf; - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Crypto.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Crypto.cs deleted file mode 100644 index cfcac7d7dc..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Crypto.cs +++ /dev/null @@ -1,183 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - private delegate int NegativeSizeReadMethod(THandle handle, byte[] buf, int cBuf); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_BioTell")] - internal static extern int CryptoNative_BioTell(SafeBioHandle bio); - - internal static int BioTell(SafeBioHandle bio) - { - int ret = CryptoNative_BioTell(bio); - if (ret < 0) - { - throw CreateOpenSslCryptographicException(); - } - - return ret; - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_BioSeek")] - internal static extern int BioSeek(SafeBioHandle bio, int pos); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509Thumbprint")] - private static extern int GetX509Thumbprint(SafeX509Handle x509, byte[] buf, int cBuf); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509NameRawBytes")] - private static extern int GetX509NameRawBytes(IntPtr x509Name, byte[] buf, int cBuf); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ReadX509AsDerFromBio")] - internal static extern SafeX509Handle ReadX509AsDerFromBio(SafeBioHandle bio); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509NotBefore")] - internal static extern IntPtr GetX509NotBefore(SafeX509Handle x509); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509NotAfter")] - internal static extern IntPtr GetX509NotAfter(SafeX509Handle x509); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509CrlNextUpdate")] - internal static extern IntPtr GetX509CrlNextUpdate(SafeX509CrlHandle crl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509Version")] - internal static extern int GetX509Version(SafeX509Handle x509); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509SignatureAlgorithm")] - internal static extern IntPtr GetX509SignatureAlgorithm(SafeX509Handle x509); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509PublicKeyAlgorithm")] - internal static extern IntPtr GetX509PublicKeyAlgorithm(SafeX509Handle x509); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509PublicKeyParameterBytes")] - private static extern int GetX509PublicKeyParameterBytes(SafeX509Handle x509, byte[] buf, int cBuf); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509PublicKeyBytes")] - internal static extern IntPtr GetX509PublicKeyBytes(SafeX509Handle x509); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509EkuFieldCount")] - internal static extern int GetX509EkuFieldCount(SafeEkuExtensionHandle eku); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509EkuField")] - internal static extern IntPtr GetX509EkuField(SafeEkuExtensionHandle eku, int loc); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509NameInfo")] - internal static extern SafeBioHandle GetX509NameInfo(SafeX509Handle x509, int nameType, [MarshalAs(UnmanagedType.Bool)] bool forIssuer); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetAsn1StringBytes")] - private static extern int GetAsn1StringBytes(IntPtr asn1, byte[] buf, int cBuf); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_PushX509StackField")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool PushX509StackField(SafeX509StackHandle stack, SafeX509Handle x509); - - internal static string GetX509RootStorePath() - { - return Marshal.PtrToStringAnsi(GetX509RootStorePath_private()); - } - - internal static string GetX509RootStoreFile() - { - return Marshal.PtrToStringAnsi(GetX509RootStoreFile_private()); - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509RootStorePath")] - private static extern IntPtr GetX509RootStorePath_private(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509RootStoreFile")] - private static extern IntPtr GetX509RootStoreFile_private(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SetX509ChainVerifyTime")] - private static extern int SetX509ChainVerifyTime( - SafeX509StoreCtxHandle ctx, - int year, - int month, - int day, - int hour, - int minute, - int second, - [MarshalAs(UnmanagedType.Bool)] bool isDst); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_CheckX509IpAddress")] - internal static extern int CheckX509IpAddress(SafeX509Handle x509, [In]byte[] addressBytes, int addressLen, string hostname, int cchHostname); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_CheckX509Hostname")] - internal static extern int CheckX509Hostname(SafeX509Handle x509, string hostname, int cchHostname); - - internal static byte[] GetAsn1StringBytes(IntPtr asn1) - { - return GetDynamicBuffer((ptr, buf, i) => GetAsn1StringBytes(ptr, buf, i), asn1); - } - - internal static byte[] GetX509Thumbprint(SafeX509Handle x509) - { - return GetDynamicBuffer((handle, buf, i) => GetX509Thumbprint(handle, buf, i), x509); - } - - internal static X500DistinguishedName LoadX500Name(IntPtr namePtr) - { - CheckValidOpenSslHandle(namePtr); - - byte[] buf = GetDynamicBuffer((ptr, buf1, i) => GetX509NameRawBytes(ptr, buf1, i), namePtr); - return new X500DistinguishedName(buf); - } - - internal static byte[] GetX509PublicKeyParameterBytes(SafeX509Handle x509) - { - return GetDynamicBuffer((handle, buf, i) => GetX509PublicKeyParameterBytes(handle, buf, i), x509); - } - - internal static void SetX509ChainVerifyTime(SafeX509StoreCtxHandle ctx, DateTime verifyTime) - { - // OpenSSL is going to convert our input time to universal, so we should be in Local or - // Unspecified (local-assumed). - Debug.Assert(verifyTime.Kind != DateTimeKind.Utc, "UTC verifyTime should have been normalized to Local"); - - int succeeded = SetX509ChainVerifyTime( - ctx, - verifyTime.Year, - verifyTime.Month, - verifyTime.Day, - verifyTime.Hour, - verifyTime.Minute, - verifyTime.Second, - verifyTime.IsDaylightSavingTime()); - - if (succeeded != 1) - { - throw Interop.Crypto.CreateOpenSslCryptographicException(); - } - } - - private static byte[] GetDynamicBuffer(NegativeSizeReadMethod method, THandle handle) - { - int negativeSize = method(handle, null, 0); - - if (negativeSize > 0) - { - throw Interop.Crypto.CreateOpenSslCryptographicException(); - } - - byte[] bytes = new byte[-negativeSize]; - - int ret = method(handle, bytes, bytes.Length); - - if (ret != 1) - { - throw Interop.Crypto.CreateOpenSslCryptographicException(); - } - - return bytes; - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Dsa.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Dsa.cs deleted file mode 100644 index 8d69e89577..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Dsa.cs +++ /dev/null @@ -1,176 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DsaCreate")] - internal static extern SafeDsaHandle DsaCreate(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DsaUpRef")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool DsaUpRef(IntPtr dsa); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DsaDestroy")] - internal static extern void DsaDestroy(IntPtr dsa); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DsaGenerateKey")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool DsaGenerateKey(out SafeDsaHandle dsa, int bits); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DsaSizeSignature")] - private static extern int DsaSizeSignature(SafeDsaHandle dsa); - - /// - /// Return the maximum size of the DER-encoded key in bytes. - /// - internal static int DsaEncodedSignatureSize(SafeDsaHandle dsa) - { - int size = DsaSizeSignature(dsa); - return size; - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DsaSizeQ")] - private static extern int DsaSizeQ(SafeDsaHandle dsa); - - /// - /// Return the size of the 'r' or 's' signature fields in bytes. - /// - internal static int DsaSignatureFieldSize(SafeDsaHandle dsa) - { - int size = DsaSizeQ(dsa); - Debug.Assert(size * 2 < DsaEncodedSignatureSize(dsa)); - return size; - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DsaSizeP")] - private static extern int DsaSizeP(SafeDsaHandle dsa); - - /// - /// Return the size of the key in bytes. - /// - internal static int DsaKeySize(SafeDsaHandle dsa) - { - int keySize = DsaSizeP(dsa); - - // Assume an even multiple of 8 bytes \ 64 bits (OpenSsl also makes the same assumption) - keySize = (keySize + 7) / 8 * 8; - return keySize; - } - - internal static bool DsaSign(SafeDsaHandle dsa, ReadOnlySpan hash, int hashLength, ReadOnlySpan refSignature, out int outSignatureLength) => - DsaSign(dsa, ref MemoryMarshal.GetReference(hash), hashLength, ref MemoryMarshal.GetReference(refSignature), out outSignatureLength); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DsaSign")] - [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool DsaSign(SafeDsaHandle dsa, ref byte hash, int hashLength, ref byte refSignature, out int outSignatureLength); - - internal static bool DsaVerify(SafeDsaHandle dsa, ReadOnlySpan hash, ReadOnlySpan signature) - { - bool ret = DsaVerify( - dsa, - ref MemoryMarshal.GetReference(hash), - hash.Length, - ref MemoryMarshal.GetReference(signature), - signature.Length); - - // Error queue already cleaned on the native function. - - return ret; - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DsaVerify")] - [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool DsaVerify(SafeDsaHandle dsa, ref byte hash, int hashLength, ref byte signature, int signatureLength); - - internal static DSAParameters ExportDsaParameters(SafeDsaHandle key, bool includePrivateParameters) - { - Debug.Assert( - key != null && !key.IsInvalid, - "Callers should check the key is invalid and throw an exception with a message"); - - if (key == null || key.IsInvalid) - { - throw new CryptographicException(); - } - - IntPtr p_bn, q_bn, g_bn, y_bn, x_bn; // these are not owned - int p_cb, q_cb, g_cb, y_cb, x_cb; - - bool refAdded = false; - try - { - key.DangerousAddRef(ref refAdded); // Protect access to the *_bn variables - - if (!GetDsaParameters(key, - out p_bn, out p_cb, - out q_bn, out q_cb, - out g_bn, out g_cb, - out y_bn, out y_cb, - out x_bn, out x_cb)) - { - throw new CryptographicException(); - } - - // Match Windows semantics where p, g and y have same length - int pgy_cb = GetMax(p_cb, g_cb, y_cb); - - // Match Windows semantics where q and x have same length - int qx_cb = GetMax(q_cb, x_cb); - - DSAParameters dsaParameters = new DSAParameters - { - P = Crypto.ExtractBignum(p_bn, pgy_cb), - Q = Crypto.ExtractBignum(q_bn, qx_cb), - G = Crypto.ExtractBignum(g_bn, pgy_cb), - Y = Crypto.ExtractBignum(y_bn, pgy_cb), - }; - - if (includePrivateParameters) - { - dsaParameters.X = Crypto.ExtractBignum(x_bn, qx_cb); - } - - return dsaParameters; - } - finally - { - if (refAdded) - key.DangerousRelease(); - } - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetDsaParameters")] - [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool GetDsaParameters( - SafeDsaHandle key, - out IntPtr p, out int p_cb, - out IntPtr q, out int q_cb, - out IntPtr g, out int g_cb, - out IntPtr y, out int y_cb, - out IntPtr x, out int x_cb); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DsaKeyCreateByExplicitParameters")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool DsaKeyCreateByExplicitParameters( - out SafeDsaHandle dsa, - byte[] p, - int pLength, - byte[] q, - int qLength, - byte[] g, - int gLength, - byte[] y, - int yLength, - byte[] x, - int xLength); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ERR.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ERR.cs deleted file mode 100644 index 95d24bc12d..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ERR.cs +++ /dev/null @@ -1,123 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using System.Text; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ErrClearError")] - internal static extern ulong ErrClearError(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ErrGetError")] - internal static extern ulong ErrGetError(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ErrGetErrorAlloc")] - private static extern ulong ErrGetErrorAlloc([MarshalAs(UnmanagedType.Bool)] out bool isAllocFailure); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ErrPeekError")] - internal static extern ulong ErrPeekError(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ErrPeekLastError")] - internal static extern ulong ErrPeekLastError(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ErrReasonErrorString")] - internal static extern IntPtr ErrReasonErrorString(ulong error); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ErrErrorStringN")] - private static extern unsafe void ErrErrorStringN(ulong e, byte* buf, int len); - - private static unsafe string ErrErrorStringN(ulong error) - { - var buffer = new byte[1024]; - fixed (byte* buf = &buffer[0]) - { - ErrErrorStringN(error, buf, buffer.Length); - return Marshal.PtrToStringAnsi((IntPtr)buf); - } - } - - internal static Exception CreateOpenSslCryptographicException() - { - // The Windows cryptography library reports error codes through - // Marshal.GetLastWin32Error, which has a single value when the - // function exits, last writer wins. - // - // OpenSSL maintains an error queue. Calls to ERR_get_error read - // values out of the queue in the order that ERR_set_error wrote - // them. Nothing enforces that a single call into an OpenSSL - // function will guarantee at-most one error being set. - // - // In order to maintain parity in how error flows look between the - // Windows code and the OpenSSL-calling code, drain the queue - // whenever an Exception is desired, and report the exception - // related to the last value in the queue. - bool isAllocFailure; - ulong error = ErrGetErrorAlloc(out isAllocFailure); - ulong lastRead = error; - bool lastIsAllocFailure = isAllocFailure; - - // 0 (there's no named constant) is only returned when the calls - // to ERR_get_error exceed the calls to ERR_set_error. - while (lastRead != 0) - { - error = lastRead; - isAllocFailure = lastIsAllocFailure; - - lastRead = ErrGetErrorAlloc(out lastIsAllocFailure); - } - - // If we're in an error flow which results in an Exception, but - // no calls to ERR_set_error were made, throw the unadorned - // CryptographicException. - if (error == 0) - { - return new CryptographicException(); - } - - if (isAllocFailure) - { - return new OutOfMemoryException(); - } - - // Even though ErrGetError returns ulong (C++ unsigned long), we - // really only expect error codes in the UInt32 range - Debug.Assert(error <= uint.MaxValue, "ErrGetError should only return error codes in the UInt32 range."); - - // If there was an error code, and it wasn't something handled specially, - // use the OpenSSL error string as the message to a CryptographicException. - return new OpenSslCryptographicException(unchecked((int)error), ErrErrorStringN(error)); - } - - internal static void CheckValidOpenSslHandle(SafeHandle handle) - { - if (handle == null || handle.IsInvalid) - { - throw CreateOpenSslCryptographicException(); - } - } - - internal static void CheckValidOpenSslHandle(IntPtr handle) - { - if (handle == IntPtr.Zero) - { - throw CreateOpenSslCryptographicException(); - } - } - - private sealed class OpenSslCryptographicException : CryptographicException - { - internal OpenSslCryptographicException(int errorCode, string message) - : base(message) - { - HResult = errorCode; - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.Cipher.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.Cipher.cs deleted file mode 100644 index 44cbc146b1..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.Cipher.cs +++ /dev/null @@ -1,85 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpCipherCreate2")] - internal static extern SafeEvpCipherCtxHandle EvpCipherCreate( - IntPtr cipher, - byte[] key, - int keyLength, - int effectivekeyLength, - byte[] iv, - int enc); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpCipherDestroy")] - internal static extern void EvpCipherDestroy(IntPtr ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpCipherReset")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool EvpCipherReset(SafeEvpCipherCtxHandle ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpCipherCtxSetPadding")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool EvpCipherCtxSetPadding(SafeEvpCipherCtxHandle x, int padding); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpCipherUpdate")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool EvpCipherUpdate( - SafeEvpCipherCtxHandle ctx, - byte* @out, - out int outl, - byte* @in, - int inl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpCipherFinalEx")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern unsafe bool EvpCipherFinalEx( - SafeEvpCipherCtxHandle ctx, - byte* outm, - out int outl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpAes128Ecb")] - internal static extern IntPtr EvpAes128Ecb(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpAes128Cbc")] - internal static extern IntPtr EvpAes128Cbc(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpAes192Ecb")] - internal static extern IntPtr EvpAes192Ecb(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpAes192Cbc")] - internal static extern IntPtr EvpAes192Cbc(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpAes256Ecb")] - internal static extern IntPtr EvpAes256Ecb(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpAes256Cbc")] - internal static extern IntPtr EvpAes256Cbc(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpDesCbc")] - internal static extern IntPtr EvpDesCbc(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpDesEcb")] - internal static extern IntPtr EvpDesEcb(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpDes3Cbc")] - internal static extern IntPtr EvpDes3Cbc(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpDes3Ecb")] - internal static extern IntPtr EvpDes3Ecb(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpRC2Cbc")] - internal static extern IntPtr EvpRC2Cbc(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpRC2Ecb")] - internal static extern IntPtr EvpRC2Ecb(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.cs deleted file mode 100644 index 67a9b54230..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EVP.cs +++ /dev/null @@ -1,56 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpMdCtxCreate")] - internal extern static SafeEvpMdCtxHandle EvpMdCtxCreate(IntPtr type); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpMdCtxDestroy")] - internal extern static void EvpMdCtxDestroy(IntPtr ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpDigestReset")] - internal extern static int EvpDigestReset(SafeEvpMdCtxHandle ctx, IntPtr type); - - internal static int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ReadOnlySpan d, int cnt) => - EvpDigestUpdate(ctx, ref MemoryMarshal.GetReference(d), cnt); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpDigestUpdate")] - private extern static int EvpDigestUpdate(SafeEvpMdCtxHandle ctx, ref byte d, int cnt); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpDigestFinalEx")] - internal extern static int EvpDigestFinalEx(SafeEvpMdCtxHandle ctx, ref byte md, ref uint s); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpMdSize")] - internal extern static int EvpMdSize(IntPtr md); - - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpMd5")] - internal extern static IntPtr EvpMd5(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpSha1")] - internal extern static IntPtr EvpSha1(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpSha256")] - internal extern static IntPtr EvpSha256(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpSha384")] - internal extern static IntPtr EvpSha384(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpSha512")] - internal extern static IntPtr EvpSha512(); - - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetMaxMdSize")] - private extern static int GetMaxMdSize(); - - internal static readonly int EVP_MAX_MD_SIZE = GetMaxMdSize(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.ImportExport.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.ImportExport.cs deleted file mode 100644 index 5f72e26625..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.ImportExport.cs +++ /dev/null @@ -1,338 +0,0 @@ -// 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. - -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using Microsoft.Win32.SafeHandles; -using System; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EcKeyGetCurveType")] - internal static extern ECCurve.ECCurveType EcKeyGetCurveType(SafeEcKeyHandle key); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EcKeyCreateByKeyParameters", CharSet = CharSet.Ansi)] - private static extern int EcKeyCreateByKeyParameters( - out SafeEcKeyHandle key, - string oid, - byte[] qx, int qxLength, - byte[] qy, int qyLength, - byte[] d, int dLength); - - internal static SafeEcKeyHandle EcKeyCreateByKeyParameters( - string oid, - byte[] qx, int qxLength, - byte[] qy, int qyLength, - byte[] d, int dLength) - { - SafeEcKeyHandle key; - int rc = EcKeyCreateByKeyParameters(out key, oid, qx, qxLength, qy, qyLength, d, dLength); - if (rc == -1) - { - key?.Dispose(); - Interop.Crypto.ErrClearError(); - - throw new PlatformNotSupportedException(SR.Format(SR.Cryptography_CurveNotSupported, oid)); - } - return key; - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EcKeyCreateByExplicitParameters")] - internal static extern SafeEcKeyHandle EcKeyCreateByExplicitParameters( - ECCurve.ECCurveType curveType, - byte[] qx, int qxLength, - byte[] qy, int qyLength, - byte[] d, int dLength, - byte[] p, int pLength, - byte[] a, int aLength, - byte[] b, int bLength, - byte[] gx, int gxLength, - byte[] gy, int gyLength, - byte[] order, int nLength, - byte[] cofactor, int cofactorLength, - byte[] seed, int seedLength); - - internal static SafeEcKeyHandle EcKeyCreateByExplicitCurve(ECCurve curve) - { - byte[] p; - if (curve.IsPrime) - { - p = curve.Prime; - } - else if (curve.IsCharacteristic2) - { - p = curve.Polynomial; - } - else - { - throw new PlatformNotSupportedException(SR.Format(SR.Cryptography_CurveNotSupported, curve.CurveType.ToString())); - } - - SafeEcKeyHandle key = Interop.Crypto.EcKeyCreateByExplicitParameters( - curve.CurveType, - null, 0, - null, 0, - null, 0, - p, p.Length, - curve.A, curve.A.Length, - curve.B, curve.B.Length, - curve.G.X, curve.G.X.Length, - curve.G.Y, curve.G.Y.Length, - curve.Order, curve.Order.Length, - curve.Cofactor, curve.Cofactor.Length, - curve.Seed, curve.Seed == null ? 0 : curve.Seed.Length); - - if (key == null || key.IsInvalid) - { - if (key != null) - key.Dispose(); - throw Interop.Crypto.CreateOpenSslCryptographicException(); - } - - // EcKeyCreateByExplicitParameters may have polluted the error queue, but key was good in the end. - // Clean up the error queue. - Interop.Crypto.ErrClearError(); - - return key; - } - - - [DllImport(Libraries.CryptoNative)] - private static extern int CryptoNative_GetECKeyParameters( - SafeEcKeyHandle key, - bool includePrivate, - out SafeBignumHandle qx_bn, out int x_cb, - out SafeBignumHandle qy_bn, out int y_cb, - out IntPtr d_bn_not_owned, out int d_cb); - - internal static ECParameters GetECKeyParameters( - SafeEcKeyHandle key, - bool includePrivate) - { - SafeBignumHandle qx_bn, qy_bn, d_bn; - IntPtr d_bn_not_owned; - int qx_cb, qy_cb, d_cb; - ECParameters parameters = new ECParameters(); - - bool refAdded = false; - try - { - key.DangerousAddRef(ref refAdded); // Protect access to d_bn_not_owned - int rc = CryptoNative_GetECKeyParameters( - key, - includePrivate, - out qx_bn, out qx_cb, - out qy_bn, out qy_cb, - out d_bn_not_owned, out d_cb); - - if (rc == -1) - { - throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey); - } - else if (rc != 1) - { - throw Interop.Crypto.CreateOpenSslCryptographicException(); - } - - using (qx_bn) - using (qy_bn) - using (d_bn = new SafeBignumHandle(d_bn_not_owned, false)) - { - // Match Windows semantics where qx, qy, and d have same length - int keySizeBits = EcKeyGetSize(key); - int expectedSize = (keySizeBits + 7) / 8; - int cbKey = GetMax(qx_cb, qy_cb, d_cb); - - Debug.Assert( - cbKey <= expectedSize, - $"Expected output size was {expectedSize}, which a parameter exceeded. qx={qx_cb}, qy={qy_cb}, d={d_cb}"); - - cbKey = GetMax(cbKey, expectedSize); - - parameters.Q = new ECPoint - { - X = Crypto.ExtractBignum(qx_bn, cbKey), - Y = Crypto.ExtractBignum(qy_bn, cbKey) - }; - parameters.D = d_cb == 0 ? null : Crypto.ExtractBignum(d_bn, cbKey); - } - } - finally - { - if (refAdded) - key.DangerousRelease(); - } - - return parameters; - } - - [DllImport(Libraries.CryptoNative)] - private static extern int CryptoNative_GetECCurveParameters( - SafeEcKeyHandle key, - bool includePrivate, - out ECCurve.ECCurveType curveType, - out SafeBignumHandle qx, out int x_cb, - out SafeBignumHandle qy, out int y_cb, - out IntPtr d_bn_not_owned, out int d_cb, - out SafeBignumHandle p, out int P_cb, - out SafeBignumHandle a, out int A_cb, - out SafeBignumHandle b, out int B_cb, - out SafeBignumHandle gx, out int Gx_cb, - out SafeBignumHandle gy, out int Gy_cb, - out SafeBignumHandle order, out int order_cb, - out SafeBignumHandle cofactor, out int cofactor_cb, - out SafeBignumHandle seed, out int seed_cb); - - internal static ECParameters GetECCurveParameters( - SafeEcKeyHandle key, - bool includePrivate) - { - ECCurve.ECCurveType curveType; - SafeBignumHandle qx_bn, qy_bn, p_bn, a_bn, b_bn, gx_bn, gy_bn, order_bn, cofactor_bn, seed_bn; - IntPtr d_bn_not_owned; - int qx_cb, qy_cb, p_cb, a_cb, b_cb, gx_cb, gy_cb, order_cb, cofactor_cb, seed_cb, d_cb; - - bool refAdded = false; - try - { - key.DangerousAddRef(ref refAdded); // Protect access to d_bn_not_owned - int rc = CryptoNative_GetECCurveParameters( - key, - includePrivate, - out curveType, - out qx_bn, out qx_cb, - out qy_bn, out qy_cb, - out d_bn_not_owned, out d_cb, - out p_bn, out p_cb, - out a_bn, out a_cb, - out b_bn, out b_cb, - out gx_bn, out gx_cb, - out gy_bn, out gy_cb, - out order_bn, out order_cb, - out cofactor_bn, out cofactor_cb, - out seed_bn, out seed_cb); - - if (rc == -1) - { - throw new CryptographicException(SR.Cryptography_CSP_NoPrivateKey); - } - else if (rc != 1) - { - throw Interop.Crypto.CreateOpenSslCryptographicException(); - } - - using (qx_bn) - using (qy_bn) - using (p_bn) - using (a_bn) - using (b_bn) - using (gx_bn) - using (gy_bn) - using (order_bn) - using (cofactor_bn) - using (seed_bn) - using (var d_h = new SafeBignumHandle(d_bn_not_owned, false)) - { - int cbFieldLength; - int pFieldLength; - if (curveType == ECCurve.ECCurveType.Characteristic2) - { - // Match Windows semantics where a,b,gx,gy,qx,qy have same length - // Treat length of m separately as it is not tied to other fields for Char2 (Char2 not supported by Windows) - cbFieldLength = GetMax(new[] { a_cb, b_cb, gx_cb, gy_cb, qx_cb, qy_cb }); - pFieldLength = p_cb; - } - else - { - // Match Windows semantics where p,a,b,gx,gy,qx,qy have same length - cbFieldLength = GetMax(new[] { p_cb, a_cb, b_cb, gx_cb, gy_cb, qx_cb, qy_cb }); - pFieldLength = cbFieldLength; - } - - // Match Windows semantics where order and d have same length - int cbSubgroupOrder = GetMax(order_cb, d_cb); - - // Copy values to ECParameters - ECParameters parameters = new ECParameters(); - parameters.Q = new ECPoint - { - X = Crypto.ExtractBignum(qx_bn, cbFieldLength), - Y = Crypto.ExtractBignum(qy_bn, cbFieldLength) - }; - parameters.D = d_cb == 0 ? null : Crypto.ExtractBignum(d_h, cbSubgroupOrder); - - var curve = parameters.Curve; - curve.CurveType = curveType; - curve.A = Crypto.ExtractBignum(a_bn, cbFieldLength); - curve.B = Crypto.ExtractBignum(b_bn, cbFieldLength); - curve.G = new ECPoint - { - X = Crypto.ExtractBignum(gx_bn, cbFieldLength), - Y = Crypto.ExtractBignum(gy_bn, cbFieldLength) - }; - curve.Order = Crypto.ExtractBignum(order_bn, cbSubgroupOrder); - - if (curveType == ECCurve.ECCurveType.Characteristic2) - { - curve.Polynomial = Crypto.ExtractBignum(p_bn, pFieldLength); - } - else - { - curve.Prime = Crypto.ExtractBignum(p_bn, pFieldLength); - } - - // Optional parameters - curve.Cofactor = cofactor_cb == 0 ? null : Crypto.ExtractBignum(cofactor_bn, cofactor_cb); - curve.Seed = seed_cb == 0 ? null : Crypto.ExtractBignum(seed_bn, seed_cb); - - parameters.Curve = curve; - return parameters; - } - } - finally - { - if (refAdded) - key.DangerousRelease(); - } - } - - /// - /// Return the maximum value in the array; assumes non-negative values. - /// - private static int GetMax(int[] values) - { - int max = 0; - - foreach (var i in values) - { - Debug.Assert(i >= 0); - if (i > max) - max = i; - } - - return max; - } - - /// - /// Return the maximum value in the array; assumes non-negative values. - /// - private static int GetMax(int value1, int value2) - { - Debug.Assert(value1 >= 0); - Debug.Assert(value2 >= 0); - return (value1 > value2 ? value1 : value2); - } - - /// - /// Return the maximum value in the array; assumes non-negative values. - /// - private static int GetMax(int value1, int value2, int value3) - { - return GetMax(GetMax(value1, value2), value3); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.cs deleted file mode 100644 index 17c1232f24..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.cs +++ /dev/null @@ -1,62 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - internal static bool EcDsaSign(ReadOnlySpan dgst, int dlen, Span sig, [In, Out] ref int siglen, SafeEcKeyHandle ecKey) => - EcDsaSign(ref MemoryMarshal.GetReference(dgst), dlen, ref MemoryMarshal.GetReference(sig), ref siglen, ecKey); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EcDsaSign")] - [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool EcDsaSign(ref byte dgst, int dlen, ref byte sig, [In, Out] ref int siglen, SafeEcKeyHandle ecKey); - - internal static int EcDsaVerify(ReadOnlySpan dgst, ReadOnlySpan sigbuf, SafeEcKeyHandle ecKey) - { - int ret = EcDsaVerify( - ref MemoryMarshal.GetReference(dgst), - dgst.Length, - ref MemoryMarshal.GetReference(sigbuf), - sigbuf.Length, - ecKey); - - if (ret < 0) - { - ErrClearError(); - } - - return ret; - } - - /*- - * returns - * 1: correct signature - * 0: incorrect signature - * -1: error - */ - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EcDsaVerify")] - private static extern int EcDsaVerify(ref byte dgst, int dgst_len, ref byte sigbuf, int sig_len, SafeEcKeyHandle ecKey); - - // returns the maximum length of a DER encoded ECDSA signature created with this key. - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EcDsaSize")] - private static extern int CryptoNative_EcDsaSize(SafeEcKeyHandle ecKey); - - internal static int EcDsaSize(SafeEcKeyHandle ecKey) - { - int ret = CryptoNative_EcDsaSize(ecKey); - - if (ret == 0) - { - throw CreateOpenSslCryptographicException(); - } - - return ret; - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcKey.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcKey.cs deleted file mode 100644 index b9e7c91d9e..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcKey.cs +++ /dev/null @@ -1,87 +0,0 @@ -// 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. - -using Microsoft.Win32.SafeHandles; -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EcKeyCreateByOid")] - private static extern SafeEcKeyHandle CryptoNative_EcKeyCreateByOid(string oid); - internal static SafeEcKeyHandle EcKeyCreateByOid(string oid) - { - SafeEcKeyHandle handle = CryptoNative_EcKeyCreateByOid(oid); - if (handle == null || handle.IsInvalid) - { - ErrClearError(); - } - - return handle; - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EcKeyDestroy")] - internal static extern void EcKeyDestroy(IntPtr a); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EcKeyGenerateKey")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool EcKeyGenerateKey(SafeEcKeyHandle eckey); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EcKeyUpRef")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool EcKeyUpRef(IntPtr r); - - [DllImport(Libraries.CryptoNative)] - private static extern int CryptoNative_EcKeyGetSize(SafeEcKeyHandle ecKey, out int keySize); - internal static int EcKeyGetSize(SafeEcKeyHandle key) - { - int keySize; - int rc = CryptoNative_EcKeyGetSize(key, out keySize); - if (rc == 1) - { - return keySize; - } - throw Interop.Crypto.CreateOpenSslCryptographicException(); - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EcKeyGetCurveName2")] - private static extern int CryptoNative_EcKeyGetCurveName(SafeEcKeyHandle ecKey, out int nid); - - internal static string EcKeyGetCurveName(SafeEcKeyHandle key) - { - int nidCurveName; - int rc = CryptoNative_EcKeyGetCurveName(key, out nidCurveName); - if (rc == 1) - { - if (nidCurveName == Interop.Crypto.NID_undef) - { - Debug.Fail("Key is invalid or doesn't have a curve"); - return string.Empty; - } - - IntPtr objCurveName = Interop.Crypto.ObjNid2Obj(nidCurveName); - if (objCurveName != IntPtr.Zero) - { - return Interop.Crypto.GetOidValue(objCurveName); - } - } - throw Interop.Crypto.CreateOpenSslCryptographicException(); - } - - internal static bool EcKeyHasCurveName(SafeEcKeyHandle key) - { - int nidCurveName; - int rc = CryptoNative_EcKeyGetCurveName(key, out nidCurveName); - if (rc == 1) - { - // Key is invalid or doesn't have a curve - return (nidCurveName != Interop.Crypto.NID_undef); - } - throw Interop.Crypto.CreateOpenSslCryptographicException(); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Encode.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Encode.cs deleted file mode 100644 index 27861a263e..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Encode.cs +++ /dev/null @@ -1,46 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security.Cryptography; - -internal static partial class Interop -{ - internal static partial class Crypto - { - internal delegate int GetEncodedSizeFunc(THandle handle); - - internal delegate int EncodeFunc(THandle handle, byte[] buf); - - internal static byte[] OpenSslEncode(GetEncodedSizeFunc getSize, EncodeFunc encode, THandle handle) - where THandle : SafeHandle - { - int size = getSize(handle); - - if (size < 1) - { - throw Crypto.CreateOpenSslCryptographicException(); - } - - byte[] data = new byte[size]; - - int size2 = encode(handle, data); - if (size2 < 1) - { - Debug.Fail( - $"{nameof(OpenSslEncode)}: {nameof(getSize)} succeeded ({size}) and {nameof(encode)} failed ({size2})"); - - // If it ever happens, ensure the error queue gets cleared. - // And since it didn't write the data, reporting an exception is good too. - throw CreateOpenSslCryptographicException(); - } - - Debug.Assert(size == size2); - - return data; - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Dsa.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Dsa.cs deleted file mode 100644 index 6c1d3cddc1..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Dsa.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPkeyGetDsa")] - internal static extern SafeDsaHandle EvpPkeyGetDsa(SafeEvpPKeyHandle pkey); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPkeySetDsa")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool EvpPkeySetDsa(SafeEvpPKeyHandle pkey, SafeDsaHandle key); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.EcKey.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.EcKey.cs deleted file mode 100644 index 70dfa425d5..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.EcKey.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPkeyGetEcKey")] - internal static extern SafeEcKeyHandle EvpPkeyGetEcKey(SafeEvpPKeyHandle pkey); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPkeySetEcKey")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool EvpPkeySetEcKey(SafeEvpPKeyHandle pkey, SafeEcKeyHandle key); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Ecdh.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Ecdh.cs deleted file mode 100644 index 74967f6104..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Ecdh.cs +++ /dev/null @@ -1,43 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPKeyCtxCreate")] - internal static extern SafeEvpPKeyCtxHandle EvpPKeyCtxCreate(SafeEvpPKeyHandle pkey, SafeEvpPKeyHandle peerkey, out uint secretLength); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPKeyDeriveSecretAgreement")] - private static extern int EvpPKeyDeriveSecretAgreement( - ref byte secret, - uint secretLength, - SafeEvpPKeyCtxHandle ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPKeyCtxDestroy")] - internal static extern void EvpPKeyCtxDestroy(IntPtr ctx); - - internal static void EvpPKeyDeriveSecretAgreement(SafeEvpPKeyCtxHandle ctx, Span destination) - { - Debug.Assert(ctx != null); - Debug.Assert(!ctx.IsInvalid); - - int ret = EvpPKeyDeriveSecretAgreement( - ref MemoryMarshal.GetReference(destination), - (uint)destination.Length, - ctx); - - if (ret != 1) - { - throw CreateOpenSslCryptographicException(); - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Rsa.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Rsa.cs deleted file mode 100644 index 1f61a826a9..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.Rsa.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPkeyGetRsa")] - internal static extern SafeRsaHandle EvpPkeyGetRsa(SafeEvpPKeyHandle pkey); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPkeySetRsa")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool EvpPkeySetRsa(SafeEvpPKeyHandle pkey, SafeRsaHandle rsa); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.cs deleted file mode 100644 index 2eff6bfcd1..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EvpPkey.cs +++ /dev/null @@ -1,22 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Security.Cryptography; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPkeyCreate")] - internal static extern SafeEvpPKeyHandle EvpPkeyCreate(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EvpPkeyDestroy")] - internal static extern void EvpPkeyDestroy(IntPtr pkey); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_UpRefEvpPkey")] - internal static extern int UpRefEvpPkey(SafeEvpPKeyHandle handle); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Hmac.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Hmac.cs deleted file mode 100644 index 6849b4f2e0..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Hmac.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_HmacCreate")] - internal extern static SafeHmacCtxHandle HmacCreate(ref byte key, int keyLen, IntPtr md); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_HmacDestroy")] - internal extern static void HmacDestroy(IntPtr ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_HmacReset")] - internal extern static int HmacReset(SafeHmacCtxHandle ctx); - - internal static int HmacUpdate(SafeHmacCtxHandle ctx, ReadOnlySpan data, int len) => - HmacUpdate(ctx, ref MemoryMarshal.GetReference(data), len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_HmacUpdate")] - private extern static int HmacUpdate(SafeHmacCtxHandle ctx, ref byte data, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_HmacFinal")] - internal extern static int HmacFinal(SafeHmacCtxHandle ctx, ref byte data, ref int len); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Initialization.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Initialization.cs deleted file mode 100644 index 7f105dec44..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Initialization.cs +++ /dev/null @@ -1,47 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - // Initialization of libcrypto threading support is done in a static constructor. - // This enables a project simply to include this file, and any usage of any of - // the System.Security.Cryptography.Native functions will trigger - // initialization of the threading support. - - internal static partial class Crypto - { - static Crypto() - { - CryptoInitializer.Initialize(); - } - } - - internal static class CryptoInitializer - { - static CryptoInitializer() - { - if (EnsureOpenSslInitialized() != 0) - { - // Ideally this would be a CryptographicException, but we use - // OpenSSL in libraries lower than System.Security.Cryptography. - // It's not a big deal, though: this will already be wrapped in a - // TypeLoadException, and this failing means something is very - // wrong with the system's configuration and any code using - // these libraries will be unable to operate correctly. - throw new InvalidOperationException(); - } - } - - internal static void Initialize() - { - // No-op that exists to provide a hook for other static constructors. - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EnsureOpenSslInitialized")] - private static extern int EnsureOpenSslInitialized(); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.LookupFriendlyNameByOid.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.LookupFriendlyNameByOid.cs deleted file mode 100644 index 37c1dd40e6..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.LookupFriendlyNameByOid.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_LookupFriendlyNameByOid")] - internal static extern int LookupFriendlyNameByOid(string oidValue, ref IntPtr friendlyNamePtr); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs deleted file mode 100644 index 1f9530594c..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs +++ /dev/null @@ -1,558 +0,0 @@ -// 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. - -using System; -using System.Buffers; -using System.Collections.Generic; -using System.Diagnostics; -using System.Globalization; -using System.IO; -using System.Net.Http; -using System.Net.Security; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using System.Security.Authentication; -using System.Security.Authentication.ExtendedProtection; -using System.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class OpenSsl - { - private static readonly Ssl.SslCtxSetVerifyCallback s_verifyClientCertificate = VerifyClientCertificate; - private unsafe static readonly Ssl.SslCtxSetAlpnCallback s_alpnServerCallback = AlpnServerSelectCallback; - private static readonly IdnMapping s_idnMapping = new IdnMapping(); - - #region internal methods - internal static SafeChannelBindingHandle QueryChannelBinding(SafeSslHandle context, ChannelBindingKind bindingType) - { - Debug.Assert( - bindingType != ChannelBindingKind.Endpoint, - "Endpoint binding should be handled by EndpointChannelBindingToken"); - - SafeChannelBindingHandle bindingHandle; - switch (bindingType) - { - case ChannelBindingKind.Unique: - bindingHandle = new SafeChannelBindingHandle(bindingType); - QueryUniqueChannelBinding(context, bindingHandle); - break; - - default: - // Keeping parity with windows, we should return null in this case. - bindingHandle = null; - break; - } - - return bindingHandle; - } - - internal static SafeSslHandle AllocateSslContext(SslProtocols protocols, SafeX509Handle certHandle, SafeEvpPKeyHandle certKeyHandle, EncryptionPolicy policy, SslAuthenticationOptions sslAuthenticationOptions) - { - SafeSslHandle context = null; - - // Always use SSLv23_method, regardless of protocols. It supports negotiating to the highest - // mutually supported version and can thus handle any of the set protocols, and we then use - // SetProtocolOptions to ensure we only allow the ones requested. - using (SafeSslContextHandle innerContext = Ssl.SslCtxCreate(Ssl.SslMethods.SSLv23_method)) - { - if (innerContext.IsInvalid) - { - throw CreateSslException(SR.net_allocate_ssl_context_failed); - } - - // Configure allowed protocols. It's ok to use DangerousGetHandle here without AddRef/Release as we just - // create the handle, it's rooted by the using, no one else has a reference to it, etc. - Ssl.SetProtocolOptions(innerContext.DangerousGetHandle(), protocols); - - // The logic in SafeSslHandle.Disconnect is simple because we are doing a quiet - // shutdown (we aren't negotiating for session close to enable later session - // restoration). - // - // If you find yourself wanting to remove this line to enable bidirectional - // close-notify, you'll probably need to rewrite SafeSslHandle.Disconnect(). - // https://www.openssl.org/docs/manmaster/ssl/SSL_shutdown.html - Ssl.SslCtxSetQuietShutdown(innerContext); - - if (!Ssl.SetEncryptionPolicy(innerContext, policy)) - { - Crypto.ErrClearError(); - throw new PlatformNotSupportedException(SR.Format(SR.net_ssl_encryptionpolicy_notsupported, policy)); - } - - bool hasCertificateAndKey = - certHandle != null && !certHandle.IsInvalid - && certKeyHandle != null && !certKeyHandle.IsInvalid; - - if (hasCertificateAndKey) - { - SetSslCertificate(innerContext, certHandle, certKeyHandle); - } - - if (sslAuthenticationOptions.IsServer && sslAuthenticationOptions.RemoteCertRequired) - { - Ssl.SslCtxSetVerify(innerContext, s_verifyClientCertificate); - } - - GCHandle alpnHandle = default; - try - { - if (sslAuthenticationOptions.ApplicationProtocols != null) - { - if (sslAuthenticationOptions.IsServer) - { - alpnHandle = GCHandle.Alloc(sslAuthenticationOptions.ApplicationProtocols); - Interop.Ssl.SslCtxSetAlpnSelectCb(innerContext, s_alpnServerCallback, GCHandle.ToIntPtr(alpnHandle)); - } - else - { - if (Interop.Ssl.SslCtxSetAlpnProtos(innerContext, sslAuthenticationOptions.ApplicationProtocols) != 0) - { - throw CreateSslException(SR.net_alpn_config_failed); - } - } - } - - context = SafeSslHandle.Create(innerContext, sslAuthenticationOptions.IsServer); - Debug.Assert(context != null, "Expected non-null return value from SafeSslHandle.Create"); - if (context.IsInvalid) - { - context.Dispose(); - throw CreateSslException(SR.net_allocate_ssl_context_failed); - } - - if (!sslAuthenticationOptions.IsServer) - { - // The IdnMapping converts unicode input into the IDNA punycode sequence. - string punyCode = s_idnMapping.GetAscii(sslAuthenticationOptions.TargetHost); - - // Similar to windows behavior, set SNI on openssl by default for client context, ignore errors. - if (!Ssl.SslSetTlsExtHostName(context, punyCode)) - { - Crypto.ErrClearError(); - } - } - - if (hasCertificateAndKey) - { - bool hasCertReference = false; - try - { - certHandle.DangerousAddRef(ref hasCertReference); - using (X509Certificate2 cert = new X509Certificate2(certHandle.DangerousGetHandle())) - { - using (X509Chain chain = TLSCertificateExtensions.BuildNewChain(cert, includeClientApplicationPolicy: false)) - { - if (chain != null && !Ssl.AddExtraChainCertificates(context, chain)) - throw CreateSslException(SR.net_ssl_use_cert_failed); - } - } - } - finally - { - if (hasCertReference) - certHandle.DangerousRelease(); - } - } - - context.AlpnHandle = alpnHandle; - } - catch - { - if (alpnHandle.IsAllocated) - { - alpnHandle.Free(); - } - - throw; - } - } - - return context; - } - - internal static bool DoSslHandshake(SafeSslHandle context, byte[] recvBuf, int recvOffset, int recvCount, out byte[] sendBuf, out int sendCount) - { - sendBuf = null; - sendCount = 0; - - if ((recvBuf != null) && (recvCount > 0)) - { - if (BioWrite(context.InputBio, recvBuf, recvOffset, recvCount) <= 0) - { - // Make sure we clear out the error that is stored in the queue - throw Crypto.CreateOpenSslCryptographicException(); - } - } - - int retVal = Ssl.SslDoHandshake(context); - if (retVal != 1) - { - Exception innerError; - Ssl.SslErrorCode error = GetSslError(context, retVal, out innerError); - - if ((retVal != -1) || (error != Ssl.SslErrorCode.SSL_ERROR_WANT_READ)) - { - throw new SslException(SR.Format(SR.net_ssl_handshake_failed_error, error), innerError); - } - } - - sendCount = Crypto.BioCtrlPending(context.OutputBio); - if (sendCount > 0) - { - sendBuf = new byte[sendCount]; - - try - { - sendCount = BioRead(context.OutputBio, sendBuf, sendCount); - } - finally - { - if (sendCount <= 0) - { - // Make sure we clear out the error that is stored in the queue - Crypto.ErrClearError(); - sendBuf = null; - sendCount = 0; - } - } - } - - bool stateOk = Ssl.IsSslStateOK(context); - if (stateOk) - { - context.MarkHandshakeCompleted(); - } - return stateOk; - } - - internal static int Encrypt(SafeSslHandle context, ReadOnlyMemory input, ref byte[] output, out Ssl.SslErrorCode errorCode) - { -#if DEBUG - ulong assertNoError = Crypto.ErrPeekError(); - Debug.Assert(assertNoError == 0, "OpenSsl error queue is not empty, run: 'openssl errstr " + assertNoError.ToString("X") + "' for original error."); -#endif - errorCode = Ssl.SslErrorCode.SSL_ERROR_NONE; - - int retVal; - unsafe - { - using (MemoryHandle handle = input.Pin()) - { - retVal = Ssl.SslWrite(context, (byte*)handle.Pointer, input.Length); - } - } - - if (retVal != input.Length) - { - errorCode = GetSslError(context, retVal, out Exception innerError); - retVal = 0; - - switch (errorCode) - { - // indicate end-of-file - case Ssl.SslErrorCode.SSL_ERROR_ZERO_RETURN: - case Ssl.SslErrorCode.SSL_ERROR_WANT_READ: - break; - - default: - throw new SslException(SR.Format(SR.net_ssl_encrypt_failed, errorCode), innerError); - } - } - else - { - int capacityNeeded = Crypto.BioCtrlPending(context.OutputBio); - - if (output == null || output.Length < capacityNeeded) - { - output = new byte[capacityNeeded]; - } - - retVal = BioRead(context.OutputBio, output, capacityNeeded); - if (retVal <= 0) - { - // Make sure we clear out the error that is stored in the queue - Crypto.ErrClearError(); - } - } - - return retVal; - } - - internal static int Decrypt(SafeSslHandle context, byte[] outBuffer, int offset, int count, out Ssl.SslErrorCode errorCode) - { -#if DEBUG - ulong assertNoError = Crypto.ErrPeekError(); - Debug.Assert(assertNoError == 0, "OpenSsl error queue is not empty, run: 'openssl errstr " + assertNoError.ToString("X") + "' for original error."); -#endif - errorCode = Ssl.SslErrorCode.SSL_ERROR_NONE; - - int retVal = BioWrite(context.InputBio, outBuffer, offset, count); - - if (retVal == count) - { - unsafe - { - fixed (byte* fixedBuffer = outBuffer) - { - retVal = Ssl.SslRead(context, fixedBuffer + offset, outBuffer.Length); - } - } - - if (retVal > 0) - { - count = retVal; - } - } - - if (retVal != count) - { - Exception innerError; - errorCode = GetSslError(context, retVal, out innerError); - retVal = 0; - - switch (errorCode) - { - // indicate end-of-file - case Ssl.SslErrorCode.SSL_ERROR_ZERO_RETURN: - break; - - case Ssl.SslErrorCode.SSL_ERROR_WANT_READ: - // update error code to renegotiate if renegotiate is pending, otherwise make it SSL_ERROR_WANT_READ - errorCode = Ssl.IsSslRenegotiatePending(context) ? - Ssl.SslErrorCode.SSL_ERROR_RENEGOTIATE : - Ssl.SslErrorCode.SSL_ERROR_WANT_READ; - break; - - default: - throw new SslException(SR.Format(SR.net_ssl_decrypt_failed, errorCode), innerError); - } - } - - return retVal; - } - - internal static SafeX509Handle GetPeerCertificate(SafeSslHandle context) - { - return Ssl.SslGetPeerCertificate(context); - } - - internal static SafeSharedX509StackHandle GetPeerCertificateChain(SafeSslHandle context) - { - return Ssl.SslGetPeerCertChain(context); - } - - #endregion - - #region private methods - - private static void QueryUniqueChannelBinding(SafeSslHandle context, SafeChannelBindingHandle bindingHandle) - { - bool sessionReused = Ssl.SslSessionReused(context); - int certHashLength = context.IsServer ^ sessionReused ? - Ssl.SslGetPeerFinished(context, bindingHandle.CertHashPtr, bindingHandle.Length) : - Ssl.SslGetFinished(context, bindingHandle.CertHashPtr, bindingHandle.Length); - - if (0 == certHashLength) - { - throw CreateSslException(SR.net_ssl_get_channel_binding_token_failed); - } - - bindingHandle.SetCertHashLength(certHashLength); - } - - private static int VerifyClientCertificate(int preverify_ok, IntPtr x509_ctx_ptr) - { - // Full validation is handled after the handshake in VerifyCertificateProperties and the - // user callback. It's also up to those handlers to decide if a null certificate - // is appropriate. So just return success to tell OpenSSL that the cert is acceptable, - // we'll process it after the handshake finishes. - const int OpenSslSuccess = 1; - return OpenSslSuccess; - } - - private static unsafe int AlpnServerSelectCallback(IntPtr ssl, out byte* outp, out byte outlen, byte* inp, uint inlen, IntPtr arg) - { - outp = null; - outlen = 0; - - GCHandle protocolHandle = GCHandle.FromIntPtr(arg); - if (!(protocolHandle.Target is List protocolList)) - { - return Ssl.SSL_TLSEXT_ERR_NOACK; - } - - try - { - for (int i = 0; i < protocolList.Count; i++) - { - Span clientList = new Span(inp, (int)inlen); - while (clientList.Length > 0) - { - byte length = clientList[0]; - Span clientProto = clientList.Slice(1, length); - if (clientProto.SequenceEqual(protocolList[i].Protocol.Span)) - { - fixed (byte* p = &MemoryMarshal.GetReference(clientProto)) outp = p; - outlen = length; - return Ssl.SSL_TLSEXT_ERR_OK; - } - - clientList = clientList.Slice(1 + length); - } - } - } - catch - { - // No common application protocol was negotiated, set the target on the alpnHandle to null. - // It is ok to clear the handle value here, this results in handshake failure, so the SslStream object is disposed. - protocolHandle.Target = null; - - return Ssl.SSL_TLSEXT_ERR_NOACK; - } - - // No common application protocol was negotiated, set the target on the alpnHandle to null. - // It is ok to clear the handle value here, this results in handshake failure, so the SslStream object is disposed. - protocolHandle.Target = null; - - return Ssl.SSL_TLSEXT_ERR_NOACK; - } - - private static int BioRead(SafeBioHandle bio, byte[] buffer, int count) - { - Debug.Assert(buffer != null); - Debug.Assert(count >= 0); - Debug.Assert(buffer.Length >= count); - - int bytes = Crypto.BioRead(bio, buffer, count); - if (bytes != count) - { - throw CreateSslException(SR.net_ssl_read_bio_failed_error); - } - return bytes; - } - - private static int BioWrite(SafeBioHandle bio, byte[] buffer, int offset, int count) - { - Debug.Assert(buffer != null); - Debug.Assert(offset >= 0); - Debug.Assert(count >= 0); - Debug.Assert(buffer.Length >= offset + count); - - int bytes; - unsafe - { - fixed (byte* bufPtr = buffer) - { - bytes = Ssl.BioWrite(bio, bufPtr + offset, count); - } - } - - if (bytes != count) - { - throw CreateSslException(SR.net_ssl_write_bio_failed_error); - } - return bytes; - } - - private static Ssl.SslErrorCode GetSslError(SafeSslHandle context, int result, out Exception innerError) - { - ErrorInfo lastErrno = Sys.GetLastErrorInfo(); // cache it before we make more P/Invoke calls, just in case we need it - - Ssl.SslErrorCode retVal = Ssl.SslGetError(context, result); - switch (retVal) - { - case Ssl.SslErrorCode.SSL_ERROR_SYSCALL: - // Some I/O error occurred - innerError = - Crypto.ErrPeekError() != 0 ? Crypto.CreateOpenSslCryptographicException() : // crypto error queue not empty - result == 0 ? new EndOfStreamException() : // end of file that violates protocol - result == -1 && lastErrno.Error != Error.SUCCESS ? new IOException(lastErrno.GetErrorMessage(), lastErrno.RawErrno) : // underlying I/O error - null; // no additional info available - break; - - case Ssl.SslErrorCode.SSL_ERROR_SSL: - // OpenSSL failure occurred. The error queue contains more details, when building the exception the queue will be cleared. - innerError = Interop.Crypto.CreateOpenSslCryptographicException(); - break; - - default: - // No additional info available. - innerError = null; - break; - } - return retVal; - } - - private static void SetSslCertificate(SafeSslContextHandle contextPtr, SafeX509Handle certPtr, SafeEvpPKeyHandle keyPtr) - { - Debug.Assert(certPtr != null && !certPtr.IsInvalid, "certPtr != null && !certPtr.IsInvalid"); - Debug.Assert(keyPtr != null && !keyPtr.IsInvalid, "keyPtr != null && !keyPtr.IsInvalid"); - - int retVal = Ssl.SslCtxUseCertificate(contextPtr, certPtr); - - if (1 != retVal) - { - throw CreateSslException(SR.net_ssl_use_cert_failed); - } - - retVal = Ssl.SslCtxUsePrivateKey(contextPtr, keyPtr); - - if (1 != retVal) - { - throw CreateSslException(SR.net_ssl_use_private_key_failed); - } - - //check private key - retVal = Ssl.SslCtxCheckPrivateKey(contextPtr); - - if (1 != retVal) - { - throw CreateSslException(SR.net_ssl_check_private_key_failed); - } - } - - internal static SslException CreateSslException(string message) - { - // Capture last error to be consistent with CreateOpenSslCryptographicException - ulong errorVal = Crypto.ErrPeekLastError(); - Crypto.ErrClearError(); - string msg = SR.Format(message, Marshal.PtrToStringAnsi(Crypto.ErrReasonErrorString(errorVal))); - return new SslException(msg, (int)errorVal); - } - - #endregion - - #region Internal class - - internal sealed class SslException : Exception - { - public SslException(string inputMessage) - : base(inputMessage) - { - } - - public SslException(string inputMessage, Exception ex) - : base(inputMessage, ex) - { - } - - public SslException(string inputMessage, int error) - : this(inputMessage) - { - HResult = error; - } - - public SslException(int error) - : this(SR.Format(SR.net_generic_operation_failed, error)) - { - HResult = error; - } - } - - #endregion - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSslVersion.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSslVersion.cs deleted file mode 100644 index b5c6960d94..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSslVersion.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class OpenSsl - { - private static Version s_opensslVersion; - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_OpenSslVersionNumber")] - private static extern uint OpenSslVersionNumber(); - - internal static Version OpenSslVersion - { - get - { - if (s_opensslVersion == null) - { - uint versionNumber = OpenSslVersionNumber(); - s_opensslVersion = new Version((int)(versionNumber >> 28), (int)((versionNumber >> 20) & 0xff), (int)((versionNumber >> 12) & 0xff)); - } - - return s_opensslVersion; - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Pkcs12.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Pkcs12.cs deleted file mode 100644 index 1be561006f..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Pkcs12.cs +++ /dev/null @@ -1,45 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DecodePkcs12")] - internal static extern unsafe SafePkcs12Handle DecodePkcs12(byte[] buf, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DecodePkcs12FromBio")] - internal static extern SafePkcs12Handle DecodePkcs12FromBio(SafeBioHandle bio); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Pkcs12Destroy")] - internal static extern void Pkcs12Destroy(IntPtr p12); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Pkcs12Create", CharSet = CharSet.Ansi)] - internal static extern SafePkcs12Handle Pkcs12Create( - SafePasswordHandle pass, - SafeEvpPKeyHandle pkey, - SafeX509Handle cert, - SafeX509StackHandle ca); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetPkcs12DerSize")] - internal static extern int GetPkcs12DerSize(SafePkcs12Handle p12); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EncodePkcs12")] - internal static extern int EncodePkcs12(SafePkcs12Handle p12, byte[] buf); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Pkcs12Parse")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool Pkcs12Parse( - SafePkcs12Handle p12, - SafePasswordHandle pass, - out SafeEvpPKeyHandle pkey, - out SafeX509Handle cert, - out SafeX509StackHandle ca); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Pkcs7.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Pkcs7.cs deleted file mode 100644 index d05ec4cadc..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Pkcs7.cs +++ /dev/null @@ -1,61 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_PemReadBioPkcs7")] - internal static extern SafePkcs7Handle PemReadBioPkcs7(SafeBioHandle bp); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DecodePkcs7")] - internal static extern SafePkcs7Handle DecodePkcs7(byte[] buf, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_D2IPkcs7Bio")] - internal static extern SafePkcs7Handle D2IPkcs7Bio(SafeBioHandle bp); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Pkcs7CreateCertificateCollection")] - internal static extern SafePkcs7Handle Pkcs7CreateCertificateCollection(SafeX509StackHandle certs); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Pkcs7Destroy")] - internal static extern void Pkcs7Destroy(IntPtr p7); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetPkcs7Certificates")] - private static extern int GetPkcs7Certificates(SafePkcs7Handle p7, out SafeSharedX509StackHandle certs); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_Pkcs7AddCertificate")] - internal static extern bool Pkcs7AddCertificate(SafePkcs7Handle p7, IntPtr x509); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetPkcs7DerSize")] - internal static extern int GetPkcs7DerSize(SafePkcs7Handle p7); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EncodePkcs7")] - internal static extern int EncodePkcs7(SafePkcs7Handle p7, byte[] buf); - - internal static SafeSharedX509StackHandle GetPkcs7Certificates(SafePkcs7Handle p7) - { - if (p7 == null || p7.IsInvalid) - { - return SafeSharedX509StackHandle.InvalidHandle; - } - - SafeSharedX509StackHandle certs; - int result = GetPkcs7Certificates(p7, out certs); - - if (result != 1) - { - throw Interop.Crypto.CreateOpenSslCryptographicException(); - } - - // Track the parent relationship for the interior pointer so lifetime is well-managed. - certs.SetParent(p7); - - return certs; - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.RAND.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.RAND.cs deleted file mode 100644 index 2643abe6f6..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.RAND.cs +++ /dev/null @@ -1,23 +0,0 @@ -// 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. - -using System.Diagnostics; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Crypto - { - internal unsafe static bool GetRandomBytes(byte* pbBuffer, int count) - { - Debug.Assert(count >= 0); - - return CryptoNative_GetRandomBytes(pbBuffer, count); - } - - [DllImport(Libraries.CryptoNative)] - [return: MarshalAs(UnmanagedType.Bool)] - private unsafe static extern bool CryptoNative_GetRandomBytes(byte* buf, int num); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Rsa.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Rsa.cs deleted file mode 100644 index 296b9f18b5..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Rsa.cs +++ /dev/null @@ -1,217 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaCreate")] - internal static extern SafeRsaHandle RsaCreate(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaUpRef")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool RsaUpRef(IntPtr rsa); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaDestroy")] - internal static extern void RsaDestroy(IntPtr rsa); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DecodeRsaPublicKey")] - internal static extern SafeRsaHandle DecodeRsaPublicKey(byte[] buf, int len); - - internal static int RsaPublicEncrypt( - int flen, - ReadOnlySpan from, - Span to, - SafeRsaHandle rsa, - RsaPadding padding) => - RsaPublicEncrypt(flen, ref MemoryMarshal.GetReference(from), ref MemoryMarshal.GetReference(to), rsa, padding); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaPublicEncrypt")] - private extern static int RsaPublicEncrypt( - int flen, - ref byte from, - ref byte to, - SafeRsaHandle rsa, - RsaPadding padding); - - internal static int RsaPrivateDecrypt( - int flen, - ReadOnlySpan from, - Span to, - SafeRsaHandle rsa, - RsaPadding padding) => - RsaPrivateDecrypt(flen, ref MemoryMarshal.GetReference(from), ref MemoryMarshal.GetReference(to), rsa, padding); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaPrivateDecrypt")] - private extern static int RsaPrivateDecrypt( - int flen, - ref byte from, - ref byte to, - SafeRsaHandle rsa, - RsaPadding padding); - - internal static int RsaSignPrimitive( - ReadOnlySpan from, - Span to, - SafeRsaHandle rsa) => - RsaSignPrimitive(from.Length, ref MemoryMarshal.GetReference(from), ref MemoryMarshal.GetReference(to), rsa); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaSignPrimitive")] - private static extern int RsaSignPrimitive( - int flen, - ref byte from, - ref byte to, - SafeRsaHandle rsa); - - internal static int RsaVerificationPrimitive( - ReadOnlySpan from, - Span to, - SafeRsaHandle rsa) => - RsaVerificationPrimitive(from.Length, ref MemoryMarshal.GetReference(from), ref MemoryMarshal.GetReference(to), rsa); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaVerificationPrimitive")] - private static extern int RsaVerificationPrimitive( - int flen, - ref byte from, - ref byte to, - SafeRsaHandle rsa); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaSize")] - internal static extern int RsaSize(SafeRsaHandle rsa); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaGenerateKeyEx")] - internal static extern int RsaGenerateKeyEx(SafeRsaHandle rsa, int bits, SafeBignumHandle e); - - internal static bool RsaSign(int type, ReadOnlySpan m, int m_len, Span sigret, out int siglen, SafeRsaHandle rsa) => - RsaSign(type, ref MemoryMarshal.GetReference(m), m_len, ref MemoryMarshal.GetReference(sigret), out siglen, rsa); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaSign")] - [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool RsaSign(int type, ref byte m, int m_len, ref byte sigret, out int siglen, SafeRsaHandle rsa); - - internal static bool RsaVerify(int type, ReadOnlySpan m, ReadOnlySpan sigbuf, SafeRsaHandle rsa) - { - bool ret = RsaVerify( - type, - ref MemoryMarshal.GetReference(m), - m.Length, - ref MemoryMarshal.GetReference(sigbuf), - sigbuf.Length, - rsa); - - if (!ret) - { - ErrClearError(); - } - - return ret; - } - - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RsaVerify")] - [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool RsaVerify(int type, ref byte m, int m_len, ref byte sigbuf, int siglen, SafeRsaHandle rsa); - - internal static RSAParameters ExportRsaParameters(SafeRsaHandle key, bool includePrivateParameters) - { - Debug.Assert( - key != null && !key.IsInvalid, - "Callers should check the key is invalid and throw an exception with a message"); - - if (key == null || key.IsInvalid) - { - throw new CryptographicException(); - } - - bool addedRef = false; - - try - { - key.DangerousAddRef(ref addedRef); - - IntPtr n, e, d, p, dmp1, q, dmq1, iqmp; - if (!GetRsaParameters(key, out n, out e, out d, out p, out dmp1, out q, out dmq1, out iqmp)) - { - throw new CryptographicException(); - } - - int modulusSize = Crypto.RsaSize(key); - - // RSACryptoServiceProvider expects P, DP, Q, DQ, and InverseQ to all - // be padded up to half the modulus size. - int halfModulus = modulusSize / 2; - - RSAParameters rsaParameters = new RSAParameters - { - Modulus = Crypto.ExtractBignum(n, modulusSize), - Exponent = Crypto.ExtractBignum(e, 0), - }; - - if (includePrivateParameters) - { - rsaParameters.D = Crypto.ExtractBignum(d, modulusSize); - rsaParameters.P = Crypto.ExtractBignum(p, halfModulus); - rsaParameters.DP = Crypto.ExtractBignum(dmp1, halfModulus); - rsaParameters.Q = Crypto.ExtractBignum(q, halfModulus); - rsaParameters.DQ = Crypto.ExtractBignum(dmq1, halfModulus); - rsaParameters.InverseQ = Crypto.ExtractBignum(iqmp, halfModulus); - } - - return rsaParameters; - } - finally - { - if (addedRef) - key.DangerousRelease(); - } - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetRsaParameters")] - [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool GetRsaParameters( - SafeRsaHandle key, - out IntPtr n, - out IntPtr e, - out IntPtr d, - out IntPtr p, - out IntPtr dmp1, - out IntPtr q, - out IntPtr dmq1, - out IntPtr iqmp); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SetRsaParameters")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool SetRsaParameters( - SafeRsaHandle key, - byte[] n, - int nLength, - byte[] e, - int eLength, - byte[] d, - int dLength, - byte[] p, - int pLength, - byte[] dmp1, - int dmp1Length, - byte[] q, - int qLength, - byte[] dmq1, - int dmq1Length, - byte[] iqmp, - int iqmpLength); - - internal enum RsaPadding : int - { - Pkcs1 = 0, - OaepSHA1 = 1, - NoPadding = 2, - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SetProtocolOptions.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SetProtocolOptions.cs deleted file mode 100644 index 25cf9cb8f3..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SetProtocolOptions.cs +++ /dev/null @@ -1,17 +0,0 @@ -// 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. - -using Microsoft.Win32.SafeHandles; -using System; -using System.Runtime.InteropServices; -using System.Security.Authentication; - -internal static partial class Interop -{ - internal static partial class Ssl - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SetProtocolOptions")] - internal static extern void SetProtocolOptions(IntPtr ctx, SslProtocols protocols); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs deleted file mode 100644 index 8e9db6fb66..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs +++ /dev/null @@ -1,341 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Security.Cryptography.X509Certificates; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Ssl - { - internal const int SSL_TLSEXT_ERR_OK = 0; - internal const int OPENSSL_NPN_NEGOTIATED = 1; - internal const int SSL_TLSEXT_ERR_NOACK = 3; - - internal delegate int SslCtxSetVerifyCallback(int preverify_ok, IntPtr x509_ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EnsureLibSslInitialized")] - internal static extern void EnsureLibSslInitialized(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslV2_3Method")] - internal static extern IntPtr SslV2_3Method(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCreate")] - internal static extern SafeSslHandle SslCreate(SafeSslContextHandle ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslGetError")] - internal static extern SslErrorCode SslGetError(SafeSslHandle ssl, int ret); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslGetError")] - internal static extern SslErrorCode SslGetError(IntPtr ssl, int ret); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslSetQuietShutdown")] - internal static extern void SslSetQuietShutdown(SafeSslHandle ssl, int mode); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslDestroy")] - internal static extern void SslDestroy(IntPtr ssl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslSetConnectState")] - internal static extern void SslSetConnectState(SafeSslHandle ssl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslSetAcceptState")] - internal static extern void SslSetAcceptState(SafeSslHandle ssl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslGetVersion")] - private static extern IntPtr SslGetVersion(SafeSslHandle ssl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslSetTlsExtHostName")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool SslSetTlsExtHostName(SafeSslHandle ssl, string host); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslGet0AlpnSelected")] - internal static extern void SslGetAlpnSelected(SafeSslHandle ssl, out IntPtr protocol, out int len); - - internal static byte[] SslGetAlpnSelected(SafeSslHandle ssl) - { - IntPtr protocol; - int len; - SslGetAlpnSelected(ssl, out protocol, out len); - - if (len == 0) - return null; - - byte[] result = new byte[len]; - Marshal.Copy(protocol, result, 0, len); - return result; - } - - internal static string GetProtocolVersion(SafeSslHandle ssl) - { - return Marshal.PtrToStringAnsi(SslGetVersion(ssl)); - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetSslConnectionInfo")] - internal static extern bool GetSslConnectionInfo( - SafeSslHandle ssl, - out int dataCipherAlg, - out int keyExchangeAlg, - out int dataHashAlg, - out int dataKeySize, - out int hashKeySize); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslWrite")] - internal static extern unsafe int SslWrite(SafeSslHandle ssl, byte* buf, int num); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslRead")] - internal static extern unsafe int SslRead(SafeSslHandle ssl, byte* buf, int num); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_IsSslRenegotiatePending")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool IsSslRenegotiatePending(SafeSslHandle ssl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslShutdown")] - internal static extern int SslShutdown(IntPtr ssl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslShutdown")] - internal static extern int SslShutdown(SafeSslHandle ssl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslSetBio")] - internal static extern void SslSetBio(SafeSslHandle ssl, SafeBioHandle rbio, SafeBioHandle wbio); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslDoHandshake")] - internal static extern int SslDoHandshake(SafeSslHandle ssl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_IsSslStateOK")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool IsSslStateOK(SafeSslHandle ssl); - - // NOTE: this is just an (unsafe) overload to the BioWrite method from Interop.Bio.cs. - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_BioWrite")] - internal static extern unsafe int BioWrite(SafeBioHandle b, byte* data, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslGetPeerCertificate")] - internal static extern SafeX509Handle SslGetPeerCertificate(SafeSslHandle ssl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslGetPeerCertChain")] - internal static extern SafeSharedX509StackHandle SslGetPeerCertChain(SafeSslHandle ssl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslGetPeerFinished")] - internal static extern int SslGetPeerFinished(SafeSslHandle ssl, IntPtr buf, int count); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslGetFinished")] - internal static extern int SslGetFinished(SafeSslHandle ssl, IntPtr buf, int count); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslSessionReused")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool SslSessionReused(SafeSslHandle ssl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslAddExtraChainCert")] - internal static extern bool SslAddExtraChainCert(SafeSslHandle ssl, SafeX509Handle x509); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslGetClientCAList")] - private static extern SafeSharedX509NameStackHandle SslGetClientCAList_private(SafeSslHandle ssl); - - internal static SafeSharedX509NameStackHandle SslGetClientCAList(SafeSslHandle ssl) - { - Crypto.CheckValidOpenSslHandle(ssl); - - SafeSharedX509NameStackHandle handle = SslGetClientCAList_private(ssl); - - if (!handle.IsInvalid) - { - handle.SetParent(ssl); - } - - return handle; - } - - internal static bool AddExtraChainCertificates(SafeSslHandle sslContext, X509Chain chain) - { - Debug.Assert(chain != null, "X509Chain should not be null"); - Debug.Assert(chain.ChainElements.Count > 0, "chain.Build should have already been called"); - - for (int i = chain.ChainElements.Count - 2; i > 0; i--) - { - SafeX509Handle dupCertHandle = Crypto.X509UpRef(chain.ChainElements[i].Certificate.Handle); - Crypto.CheckValidOpenSslHandle(dupCertHandle); - if (!SslAddExtraChainCert(sslContext, dupCertHandle)) - { - Crypto.ErrClearError(); - dupCertHandle.Dispose(); // we still own the safe handle; clean it up - return false; - } - dupCertHandle.SetHandleAsInvalid(); // ownership has been transferred to sslHandle; do not free via this safe handle - } - - return true; - } - - internal static class SslMethods - { - internal static readonly IntPtr SSLv23_method = SslV2_3Method(); - } - - internal enum SslErrorCode - { - SSL_ERROR_NONE = 0, - SSL_ERROR_SSL = 1, - SSL_ERROR_WANT_READ = 2, - SSL_ERROR_WANT_WRITE = 3, - SSL_ERROR_SYSCALL = 5, - SSL_ERROR_ZERO_RETURN = 6, - - // NOTE: this SslErrorCode value doesn't exist in OpenSSL, but - // we use it to distinguish when a renegotiation is pending. - // Choosing an arbitrarily large value that shouldn't conflict - // with any actual OpenSSL error codes - SSL_ERROR_RENEGOTIATE = 29304 - } - } -} - -namespace Microsoft.Win32.SafeHandles -{ - internal sealed class SafeSslHandle : SafeHandle - { - private SafeBioHandle _readBio; - private SafeBioHandle _writeBio; - private bool _isServer; - private bool _handshakeCompleted = false; - - public GCHandle AlpnHandle; - - public bool IsServer - { - get { return _isServer; } - } - - public SafeBioHandle InputBio - { - get - { - return _readBio; - } - } - - public SafeBioHandle OutputBio - { - get - { - return _writeBio; - } - } - - internal void MarkHandshakeCompleted() - { - _handshakeCompleted = true; - } - - public static SafeSslHandle Create(SafeSslContextHandle context, bool isServer) - { - SafeBioHandle readBio = Interop.Crypto.CreateMemoryBio(); - SafeBioHandle writeBio = Interop.Crypto.CreateMemoryBio(); - SafeSslHandle handle = Interop.Ssl.SslCreate(context); - if (readBio.IsInvalid || writeBio.IsInvalid || handle.IsInvalid) - { - readBio.Dispose(); - writeBio.Dispose(); - handle.Dispose(); // will make IsInvalid==true if it's not already - return handle; - } - handle._isServer = isServer; - - // SslSetBio will transfer ownership of the BIO handles to the SSL context - try - { - readBio.TransferOwnershipToParent(handle); - writeBio.TransferOwnershipToParent(handle); - handle._readBio = readBio; - handle._writeBio = writeBio; - Interop.Ssl.SslSetBio(handle, readBio, writeBio); - } - catch (Exception exc) - { - // The only way this should be able to happen without thread aborts is if we hit OOMs while - // manipulating the safe handles, in which case we may leak the bio handles. - Debug.Fail("Unexpected exception while transferring SafeBioHandle ownership to SafeSslHandle", exc.ToString()); - throw; - } - - if (isServer) - { - Interop.Ssl.SslSetAcceptState(handle); - } - else - { - Interop.Ssl.SslSetConnectState(handle); - } - return handle; - } - - public override bool IsInvalid - { - get { return handle == IntPtr.Zero; } - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - _readBio?.Dispose(); - _writeBio?.Dispose(); - } - - if (AlpnHandle.IsAllocated) - { - AlpnHandle.Free(); - } - - base.Dispose(disposing); - } - - protected override bool ReleaseHandle() - { - if (_handshakeCompleted) - { - Disconnect(); - } - - IntPtr h = handle; - SetHandle(IntPtr.Zero); - Interop.Ssl.SslDestroy(h); // will free the handles underlying _readBio and _writeBio - - return true; - } - - private void Disconnect() - { - Debug.Assert(!IsInvalid, "Expected a valid context in Disconnect"); - - int retVal = Interop.Ssl.SslShutdown(handle); - - // Here, we are ignoring checking for <0 return values from Ssl_Shutdown, - // since the underlying memory bio is already disposed, we are not - // interested in reading or writing to it. - if (retVal == 0) - { - // Do a bi-directional shutdown. - retVal = Interop.Ssl.SslShutdown(handle); - } - - if (retVal < 0) - { - // Clean up the errors - Interop.Crypto.ErrClearError(); - } - } - - private SafeSslHandle() : base(IntPtr.Zero, true) - { - } - - internal SafeSslHandle(IntPtr validSslPointer, bool ownsHandle) : base(IntPtr.Zero, ownsHandle) - { - handle = validSslPointer; - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SslCtx.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SslCtx.cs deleted file mode 100644 index b1996871d9..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SslCtx.cs +++ /dev/null @@ -1,100 +0,0 @@ -// 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. - -using System; -using System.Collections.Generic; -using System.Net.Security; -using System.Runtime.InteropServices; -using System.Text; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Ssl - { - internal delegate int AppVerifyCallback(IntPtr storeCtx, IntPtr arg); - internal delegate int ClientCertCallback(IntPtr ssl, out IntPtr x509, out IntPtr pkey); - internal unsafe delegate int SslCtxSetAlpnCallback(IntPtr ssl, out byte* outp, out byte outlen, byte* inp, uint inlen, IntPtr arg); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxCreate")] - internal static extern SafeSslContextHandle SslCtxCreate(IntPtr method); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxDestroy")] - internal static extern void SslCtxDestroy(IntPtr ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxSetCertVerifyCallback")] - internal static extern void SslCtxSetCertVerifyCallback(IntPtr ctx, AppVerifyCallback cb, IntPtr arg); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxSetClientCertCallback")] - internal static extern void SslCtxSetClientCertCallback(IntPtr ctx, ClientCertCallback callback); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxSetAlpnProtos")] - internal static extern int SslCtxSetAlpnProtos(SafeSslContextHandle ctx, IntPtr protos, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxSetAlpnSelectCb")] - internal static unsafe extern void SslCtxSetAlpnSelectCb(SafeSslContextHandle ctx, SslCtxSetAlpnCallback callback, IntPtr arg); - - internal static unsafe int SslCtxSetAlpnProtos(SafeSslContextHandle ctx, List protocols) - { - byte[] buffer = ConvertAlpnProtocolListToByteArray(protocols); - fixed (byte* b = buffer) - { - return SslCtxSetAlpnProtos(ctx, (IntPtr)b, buffer.Length); - } - } - - internal static byte[] ConvertAlpnProtocolListToByteArray(List applicationProtocols) - { - int protocolSize = 0; - foreach (SslApplicationProtocol protocol in applicationProtocols) - { - if (protocol.Protocol.Length == 0 || protocol.Protocol.Length > byte.MaxValue) - { - throw new ArgumentException(SR.net_ssl_app_protocols_invalid, nameof(applicationProtocols)); - } - - protocolSize += protocol.Protocol.Length + 1; - } - - byte[] buffer = new byte[protocolSize]; - var offset = 0; - foreach (SslApplicationProtocol protocol in applicationProtocols) - { - buffer[offset++] = (byte)(protocol.Protocol.Length); - protocol.Protocol.Span.CopyTo(new Span(buffer).Slice(offset)); - offset += protocol.Protocol.Length; - } - - return buffer; - } - } -} - -namespace Microsoft.Win32.SafeHandles -{ - internal sealed class SafeSslContextHandle : SafeHandle - { - private SafeSslContextHandle() - : base(IntPtr.Zero, true) - { - } - - internal SafeSslContextHandle(IntPtr handle, bool ownsHandle) - : base(handle, ownsHandle) - { - } - - public override bool IsInvalid - { - get { return handle == IntPtr.Zero; } - } - - protected override bool ReleaseHandle() - { - Interop.Ssl.SslCtxDestroy(handle); - SetHandle(IntPtr.Zero); - return true; - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SslCtxOptions.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SslCtxOptions.cs deleted file mode 100644 index 4c4721f412..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.SslCtxOptions.cs +++ /dev/null @@ -1,36 +0,0 @@ -// 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. - -using System; -using System.Diagnostics; -using System.Net.Security; -using System.Runtime.InteropServices; -using System.Security.Authentication; -using System.Security.Authentication.ExtendedProtection; -using System.Security.Cryptography; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Ssl - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxUseCertificate")] - internal static extern int SslCtxUseCertificate(SafeSslContextHandle ctx, SafeX509Handle certPtr); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxUsePrivateKey")] - internal static extern int SslCtxUsePrivateKey(SafeSslContextHandle ctx, SafeEvpPKeyHandle keyPtr); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxCheckPrivateKey")] - internal static extern int SslCtxCheckPrivateKey(SafeSslContextHandle ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxSetQuietShutdown")] - internal static extern void SslCtxSetQuietShutdown(SafeSslContextHandle ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslCtxSetVerify")] - internal static extern void SslCtxSetVerify(SafeSslContextHandle ctx, SslCtxSetVerifyCallback callback); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SetEncryptionPolicy")] - internal static extern bool SetEncryptionPolicy(SafeSslContextHandle ctx, EncryptionPolicy policy); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs deleted file mode 100644 index c7f88e63d5..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs +++ /dev/null @@ -1,214 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - internal delegate int X509StoreVerifyCallback(int ok, IntPtr ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509EvpPublicKey")] - internal static extern SafeEvpPKeyHandle GetX509EvpPublicKey(SafeX509Handle x509); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DecodeX509Crl")] - internal static extern SafeX509CrlHandle DecodeX509Crl(byte[] buf, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DecodeX509")] - internal static extern SafeX509Handle DecodeX509(byte[] buf, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509DerSize")] - internal static extern int GetX509DerSize(SafeX509Handle x); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EncodeX509")] - internal static extern int EncodeX509(SafeX509Handle x, byte[] buf); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509Destroy")] - internal static extern void X509Destroy(IntPtr a); - - /// - /// Clone the input certificate into a new object. - /// - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509Duplicate")] - internal static extern SafeX509Handle X509Duplicate(IntPtr handle); - - /// - /// Clone the input certificate into a new object. - /// - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509Duplicate")] - internal static extern SafeX509Handle X509Duplicate(SafeX509Handle handle); - - /// - /// Increment the native reference count of the certificate to protect against - /// a free from another pointer-holder. - /// - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509UpRef")] - internal static extern SafeX509Handle X509UpRef(IntPtr handle); - - /// - /// Increment the native reference count of the certificate to protect against - /// a free from another pointer-holder. - /// - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509UpRef")] - internal static extern SafeX509Handle X509UpRef(SafeX509Handle handle); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_PemReadX509FromBio")] - internal static extern SafeX509Handle PemReadX509FromBio(SafeBioHandle bio); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509GetSerialNumber")] - private static extern SafeSharedAsn1IntegerHandle X509GetSerialNumber_private(SafeX509Handle x); - - internal static SafeSharedAsn1IntegerHandle X509GetSerialNumber(SafeX509Handle x) - { - CheckValidOpenSslHandle(x); - - return SafeInteriorHandle.OpenInteriorHandle( - handle => X509GetSerialNumber_private(handle), - x); - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509GetIssuerName")] - internal static extern IntPtr X509GetIssuerName(SafeX509Handle x); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509GetSubjectName")] - internal static extern IntPtr X509GetSubjectName(SafeX509Handle x); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509CheckPurpose")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool X509CheckPurpose(SafeX509Handle x, int id, int ca); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509CheckIssued")] - internal static extern int X509CheckIssued(SafeX509Handle issuer, SafeX509Handle subject); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509IssuerNameHash")] - internal static extern ulong X509IssuerNameHash(SafeX509Handle x); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509GetExtCount")] - internal static extern int X509GetExtCount(SafeX509Handle x); - - // Returns a pointer already being tracked by the SafeX509Handle, shouldn't be SafeHandle tracked/freed. - // Bounds checking is in place for "loc", IntPtr.Zero is returned on violations. - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509GetExt")] - internal static extern IntPtr X509GetExt(SafeX509Handle x, int loc); - - // Returns a pointer already being tracked by a SafeX509Handle, shouldn't be SafeHandle tracked/freed. - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509ExtensionGetOid")] - internal static extern IntPtr X509ExtensionGetOid(IntPtr ex); - - // Returns a pointer already being tracked by a SafeX509Handle, shouldn't be SafeHandle tracked/freed. - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509ExtensionGetData")] - internal static extern IntPtr X509ExtensionGetData(IntPtr ex); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509ExtensionGetCritical")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool X509ExtensionGetCritical(IntPtr ex); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreCreate")] - internal static extern SafeX509StoreHandle X509StoreCreate(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreDestory")] - internal static extern void X509StoreDestory(IntPtr v); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreAddCert")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool X509StoreAddCert(SafeX509StoreHandle ctx, SafeX509Handle x); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreAddCrl")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool X509StoreAddCrl(SafeX509StoreHandle ctx, SafeX509CrlHandle x); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreSetRevocationFlag")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool X509StoreSetRevocationFlag(SafeX509StoreHandle ctx, X509RevocationFlag revocationFlag); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreCtxInit")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool X509StoreCtxInit( - SafeX509StoreCtxHandle ctx, - SafeX509StoreHandle store, - SafeX509Handle x509, - SafeX509StackHandle extraCerts); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509VerifyCert")] - internal static extern int X509VerifyCert(SafeX509StoreCtxHandle ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreCtxGetError")] - internal static extern X509VerifyStatusCode X509StoreCtxGetError(SafeX509StoreCtxHandle ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreCtxGetErrorDepth")] - internal static extern int X509StoreCtxGetErrorDepth(SafeX509StoreCtxHandle ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreCtxSetVerifyCallback")] - internal static extern void X509StoreCtxSetVerifyCallback(SafeX509StoreCtxHandle ctx, X509StoreVerifyCallback callback); - - internal static string GetX509VerifyCertErrorString(X509VerifyStatusCode n) - { - return Marshal.PtrToStringAnsi(X509VerifyCertErrorString(n)); - } - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509VerifyCertErrorString")] - private static extern IntPtr X509VerifyCertErrorString(X509VerifyStatusCode n); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509CrlDestroy")] - internal static extern void X509CrlDestroy(IntPtr a); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_PemWriteBioX509Crl")] - internal static extern int PemWriteBioX509Crl(SafeBioHandle bio, SafeX509CrlHandle crl); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_PemReadBioX509Crl")] - internal static extern SafeX509CrlHandle PemReadBioX509Crl(SafeBioHandle bio); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509SubjectPublicKeyInfoDerSize")] - internal static extern int GetX509SubjectPublicKeyInfoDerSize(SafeX509Handle x509); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_EncodeX509SubjectPublicKeyInfo")] - internal static extern int EncodeX509SubjectPublicKeyInfo(SafeX509Handle x509, byte[] buf); - - internal enum X509VerifyStatusCode : int - { - X509_V_OK = 0, - X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT = 2, - X509_V_ERR_UNABLE_TO_GET_CRL = 3, - X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE = 5, - X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY = 6, - X509_V_ERR_CERT_SIGNATURE_FAILURE = 7, - X509_V_ERR_CRL_SIGNATURE_FAILURE = 8, - X509_V_ERR_CERT_NOT_YET_VALID = 9, - X509_V_ERR_CERT_HAS_EXPIRED = 10, - X509_V_ERR_CRL_NOT_YET_VALID = 11, - X509_V_ERR_CRL_HAS_EXPIRED = 12, - X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD = 13, - X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD = 14, - X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD = 15, - X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD = 16, - X509_V_ERR_OUT_OF_MEM = 17, - X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT = 18, - X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN = 19, - X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY = 20, - X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE = 21, - X509_V_ERR_CERT_CHAIN_TOO_LONG = 22, - X509_V_ERR_CERT_REVOKED = 23, - X509_V_ERR_INVALID_CA = 24, - X509_V_ERR_PATH_LENGTH_EXCEEDED = 25, - X509_V_ERR_INVALID_PURPOSE = 26, - X509_V_ERR_CERT_UNTRUSTED = 27, - X509_V_ERR_CERT_REJECTED = 28, - X509_V_ERR_KEYUSAGE_NO_CERTSIGN = 32, - X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER = 33, - X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION = 34, - X509_V_ERR_KEYUSAGE_NO_CRL_SIGN = 35, - X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION = 36, - X509_V_ERR_INVALID_NON_CA = 37, - X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE = 39, - X509_V_ERR_INVALID_EXTENSION = 41, - X509_V_ERR_INVALID_POLICY_EXTENSION = 42, - X509_V_ERR_NO_EXPLICIT_POLICY = 43, - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Ext.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Ext.cs deleted file mode 100644 index c57d75d99d..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Ext.cs +++ /dev/null @@ -1,41 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509ExtensionCreateByObj")] - internal static extern SafeX509ExtensionHandle X509ExtensionCreateByObj( - SafeAsn1ObjectHandle oid, - [MarshalAs(UnmanagedType.Bool)] bool isCritical, - SafeAsn1OctetStringHandle data); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509ExtensionDestroy")] - internal static extern int X509ExtensionDestroy(IntPtr x); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509V3ExtPrint")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool X509V3ExtPrint(SafeBioHandle buf, SafeX509ExtensionHandle ext); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DecodeX509BasicConstraints2Extension")] - [return: MarshalAs(UnmanagedType.Bool)] - internal static extern bool DecodeX509BasicConstraints2Extension( - byte[] encoded, - int encodedLength, - [MarshalAs(UnmanagedType.Bool)] out bool certificateAuthority, - [MarshalAs(UnmanagedType.Bool)] out bool hasPathLengthConstraint, - out int pathLengthConstraint); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_DecodeExtendedKeyUsage")] - internal static extern SafeEkuExtensionHandle DecodeExtendedKeyUsage(byte[] buf, int len); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_ExtendedKeyUsageDestory")] - internal static extern void ExtendedKeyUsageDestory(IntPtr a); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Name.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Name.cs deleted file mode 100644 index 70097d7db2..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Name.cs +++ /dev/null @@ -1,71 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Security; -using System.Security.Cryptography.X509Certificates; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509NameStackFieldCount")] - internal static extern int GetX509NameStackFieldCount(SafeSharedX509NameStackHandle sk); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509NameStackField")] - private static extern SafeSharedX509NameHandle GetX509NameStackField_private(SafeSharedX509NameStackHandle sk, - int loc); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509NameRawBytes")] - private static extern int GetX509NameRawBytes(SafeSharedX509NameHandle x509Name, byte[] buf, int cBuf); - - internal static X500DistinguishedName LoadX500Name(SafeSharedX509NameHandle namePtr) - { - CheckValidOpenSslHandle(namePtr); - - byte[] buf = GetDynamicBuffer((ptr, buf1, i) => GetX509NameRawBytes(ptr, buf1, i), namePtr); - return new X500DistinguishedName(buf); - } - - internal static SafeSharedX509NameHandle GetX509NameStackField(SafeSharedX509NameStackHandle sk, int loc) - { - CheckValidOpenSslHandle(sk); - - return SafeInteriorHandle.OpenInteriorHandle( - (handle, i) => GetX509NameStackField_private(handle, i), - sk, - loc); - } - } -} - -namespace Microsoft.Win32.SafeHandles -{ - /// - /// Represents access to a X509_NAME* which is a member of a structure tracked - /// by another SafeHandle. - /// - internal sealed class SafeSharedX509NameHandle : SafeInteriorHandle - { - private SafeSharedX509NameHandle() : - base(IntPtr.Zero, ownsHandle: true) - { - } - } - - /// - /// Represents access to a STACK_OF(X509_NAME)* which is a member of a structure tracked - /// by another SafeHandle. - /// - internal sealed class SafeSharedX509NameStackHandle : SafeInteriorHandle - { - private SafeSharedX509NameStackHandle() : - base(IntPtr.Zero, ownsHandle: true) - { - } - } -} - diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Stack.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Stack.cs deleted file mode 100644 index 7853e8e638..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Stack.cs +++ /dev/null @@ -1,76 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_NewX509Stack")] - internal static extern SafeX509StackHandle NewX509Stack(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_RecursiveFreeX509Stack")] - internal static extern void RecursiveFreeX509Stack(IntPtr stack); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509StackFieldCount")] - internal static extern int GetX509StackFieldCount(SafeX509StackHandle stack); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509StackFieldCount")] - internal static extern int GetX509StackFieldCount(SafeSharedX509StackHandle stack); - - /// - /// Gets a pointer to a certificate within a STACK_OF(X509). This pointer will later - /// be freed, so it should be cloned via new X509Certificate2(IntPtr) - /// - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509StackField")] - internal static extern IntPtr GetX509StackField(SafeX509StackHandle stack, int loc); - - /// - /// Gets a pointer to a certificate within a STACK_OF(X509). This pointer will later - /// be freed, so it should be cloned via new X509Certificate2(IntPtr) - /// - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_GetX509StackField")] - internal static extern IntPtr GetX509StackField(SafeSharedX509StackHandle stack, int loc); - } -} - -namespace Microsoft.Win32.SafeHandles -{ - internal sealed class SafeX509StackHandle : SafeHandle - { - private SafeX509StackHandle() : - base(IntPtr.Zero, ownsHandle: true) - { - } - - protected override bool ReleaseHandle() - { - Interop.Crypto.RecursiveFreeX509Stack(handle); - SetHandle(IntPtr.Zero); - return true; - } - - public override bool IsInvalid - { - get { return handle == IntPtr.Zero; } - } - } - - /// - /// Represents access to a STACK_OF(X509)* which is a member of a structure tracked - /// by another SafeHandle. - /// - internal sealed class SafeSharedX509StackHandle : SafeInteriorHandle - { - internal static readonly SafeSharedX509StackHandle InvalidHandle = new SafeSharedX509StackHandle(); - - private SafeSharedX509StackHandle() : - base(IntPtr.Zero, ownsHandle: true) - { - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509StoreCtx.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509StoreCtx.cs deleted file mode 100644 index 0da65d10ce..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509StoreCtx.cs +++ /dev/null @@ -1,63 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Crypto - { - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreCtxCreate")] - internal static extern SafeX509StoreCtxHandle X509StoreCtxCreate(); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreCtxDestroy")] - internal static extern void X509StoreCtxDestroy(IntPtr v); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreCtxGetChain")] - internal static extern SafeX509StackHandle X509StoreCtxGetChain(SafeX509StoreCtxHandle ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreCtxGetSharedUntrusted")] - private static extern SafeSharedX509StackHandle X509StoreCtxGetSharedUntrusted_private(SafeX509StoreCtxHandle ctx); - - [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_X509StoreCtxGetTargetCert")] - internal static extern IntPtr X509StoreCtxGetTargetCert(SafeX509StoreCtxHandle ctx); - - internal static SafeSharedX509StackHandle X509StoreCtxGetSharedUntrusted(SafeX509StoreCtxHandle ctx) - { - return SafeInteriorHandle.OpenInteriorHandle( - x => X509StoreCtxGetSharedUntrusted_private(x), - ctx); - } - } -} - -namespace Microsoft.Win32.SafeHandles -{ - internal sealed class SafeX509StoreCtxHandle : SafeHandle - { - private SafeX509StoreCtxHandle() : - base(IntPtr.Zero, ownsHandle: true) - { - } - - internal SafeX509StoreCtxHandle(IntPtr handle, bool ownsHandle) : - base(handle, ownsHandle) - { - } - - protected override bool ReleaseHandle() - { - Interop.Crypto.X509StoreCtxDestroy(handle); - SetHandle(IntPtr.Zero); - return true; - } - - public override bool IsInvalid - { - get { return handle == IntPtr.Zero; } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/libdl/Interop.dlopen.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/libdl/Interop.dlopen.cs deleted file mode 100644 index 4a4c31f035..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/libdl/Interop.dlopen.cs +++ /dev/null @@ -1,17 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal partial class Interop -{ - internal partial class Libdl - { - public const int RTLD_NOW = 0x002; - - [DllImport(Libraries.Libdl)] - public static extern IntPtr dlopen(string fileName, int flag); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/libdl/Interop.dlsym.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/libdl/Interop.dlsym.cs deleted file mode 100644 index 2ea7a98e98..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/libdl/Interop.dlsym.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; - -internal partial class Interop -{ - internal partial class Libdl - { - [DllImport(Libraries.Libdl)] - public static extern IntPtr dlsym(IntPtr handle, string symbol); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Libraries.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Libraries.cs index a1c85bb09d..879bb0a38d 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Libraries.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Libraries.cs @@ -6,7 +6,6 @@ internal static partial class Interop { internal static partial class Libraries { - internal const string Advapi32 = "advapi32.dll"; internal const string Crypt32 = "crypt32.dll"; internal const string Kernel32 = "kernel32.dll"; internal const string NtDll = "ntdll.dll"; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.GetTokenInformation_void.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.GetTokenInformation_void.cs deleted file mode 100644 index 3430c2d2c0..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.GetTokenInformation_void.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -using Microsoft.Win32.SafeHandles; -using System; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Advapi32 - { - [DllImport(Interop.Libraries.Advapi32, SetLastError = true)] - internal unsafe static extern bool GetTokenInformation( - SafeAccessTokenHandle TokenHandle, - TOKEN_INFORMATION_CLASS TokenInformationClass, - void* TokenInformation, - uint TokenInformationLength, - out uint ReturnLength); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.OpenProcessToken_IntPtr.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.OpenProcessToken_IntPtr.cs deleted file mode 100644 index d93e162dfb..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.OpenProcessToken_IntPtr.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -using Microsoft.Win32.SafeHandles; -using System.Runtime.InteropServices; -using System; -using System.Security.Principal; - -internal partial class Interop -{ - internal partial class Advapi32 - { - [DllImport(Libraries.Advapi32, CharSet = CharSet.Unicode, SetLastError = true)] - internal static extern bool OpenProcessToken( - IntPtr ProcessToken, - TokenAccessLevels DesiredAccess, - out SafeTokenHandle TokenHandle); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.OpenProcessToken_SafeAccessTokenHandle.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.OpenProcessToken_SafeAccessTokenHandle.cs deleted file mode 100644 index 3bf14f03e7..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.OpenProcessToken_SafeAccessTokenHandle.cs +++ /dev/null @@ -1,17 +0,0 @@ -// 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. - -using System; -using System.Runtime.InteropServices; -using System.Security.Principal; -using Microsoft.Win32.SafeHandles; - -internal static partial class Interop -{ - internal static partial class Advapi32 - { - [DllImport(Interop.Libraries.Advapi32, SetLastError = true)] - internal static extern bool OpenProcessToken(IntPtr ProcessToken, TokenAccessLevels DesiredAccess, out SafeAccessTokenHandle TokenHandle); - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.TOKEN_ELEVATION.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.TOKEN_ELEVATION.cs deleted file mode 100644 index 55b49c9df3..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.TOKEN_ELEVATION.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. - -internal static partial class Interop -{ - internal static partial class Advapi32 - { - // https://msdn.microsoft.com/en-us/library/windows/desktop/bb530717.aspx - internal struct TOKEN_ELEVATION - { - public BOOL TokenIsElevated; - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.TOKEN_INFORMATION_CLASS.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.TOKEN_INFORMATION_CLASS.cs deleted file mode 100644 index 89c36b694a..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/advapi32/Interop.TOKEN_INFORMATION_CLASS.cs +++ /dev/null @@ -1,57 +0,0 @@ -// 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. - -internal static partial class Interop -{ - internal static partial class Advapi32 - { - /// - /// TOKEN_INFORMATION_CLASS enumeration. - /// - internal enum TOKEN_INFORMATION_CLASS : uint - { - TokenUser = 1, - TokenGroups, - TokenPrivileges, - TokenOwner, - TokenPrimaryGroup, - TokenDefaultDacl, - TokenSource, - TokenType, - TokenImpersonationLevel, - TokenStatistics, - TokenRestrictedSids, - TokenSessionId, - TokenGroupsAndPrivileges, - TokenSessionReference, - TokenSandBoxInert, - TokenAuditPolicy, - TokenOrigin, - TokenElevationType, - TokenLinkedToken, - TokenElevation, - TokenHasRestrictions, - TokenAccessInformation, - TokenVirtualizationAllowed, - TokenVirtualizationEnabled, - TokenIntegrityLevel, - TokenUIAccess, - TokenMandatoryPolicy, - TokenLogonSid, - TokenIsAppContainer, - TokenCapabilities, - TokenAppContainerSid, - TokenAppContainerNumber, - TokenUserClaimAttributes, - TokenDeviceClaimAttributes, - TokenRestrictedUserClaimAttributes, - TokenRestrictedDeviceClaimAttributes, - TokenDeviceGroups, - TokenRestrictedDeviceGroups, - TokenSecurityAttributes, - TokenIsRestricted, - MaxTokenInfoClass - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/kernel32/Interop.FileOperations.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/kernel32/Interop.FileOperations.cs deleted file mode 100644 index 8576834ea8..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/kernel32/Interop.FileOperations.cs +++ /dev/null @@ -1,28 +0,0 @@ -// 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. - -internal partial class Interop -{ - internal partial class Kernel32 - { - internal partial class IOReparseOptions - { - internal const uint IO_REPARSE_TAG_FILE_PLACEHOLDER = 0x80000015; - internal const uint IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003; - } - - internal partial class FileOperations - { - internal const int OPEN_EXISTING = 3; - internal const int COPY_FILE_FAIL_IF_EXISTS = 0x00000001; - - internal const int FILE_FLAG_BACKUP_SEMANTICS = 0x02000000; - internal const int FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000; - internal const int FILE_FLAG_OVERLAPPED = 0x40000000; - - internal const int FILE_LIST_DIRECTORY = 0x0001; - } - - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 746fe1d9ae..26abfa28a5 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -468,9 +468,6 @@ Common\Interop\Windows\kernel32\Interop.DeviceIoControl.cs - - Common\Interop\Windows\kernel32\Interop.FileOperations.cs - Common\Interop\Windows\Kernel32\Interop.IoControlTransferType.cs diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj index c0cdf6fd85..ceac3514a8 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj @@ -80,9 +80,6 @@ TDS - - CoreFx.Private.TestUtilities - Microsoft.DotNet.XUnitExtensions diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionBasicTests.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionBasicTests.cs index beb797abef..c21275ebde 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionBasicTests.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlConnectionBasicTests.cs @@ -24,7 +24,7 @@ public void ConnectionTest() } } - [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer), nameof(PlatformDetection.IsNotArmProcess))] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotArmProcess))] [ActiveIssue(4830, TestPlatforms.AnyUnix)] [PlatformSpecific(TestPlatforms.Windows)] public void IntegratedAuthConnectionTest() diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/AssemblyResourceManager.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/AssemblyResourceManager.cs index 357c45f82f..023dcfa12e 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/AssemblyResourceManager.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/AssemblyResourceManager.cs @@ -20,7 +20,7 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests /// public class AssemblyResourceManager : DynamicObject { - private System.Reflection.Assembly _resourceAssembly; + private Assembly _resourceAssembly; public AssemblyResourceManager(Assembly assembly) { @@ -56,31 +56,23 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o private bool TryGetResourceValue(string resourceName, object[] args, out object result) { - if (PlatformDetection.IsNetNative) - { - result = string.Empty; - return true; - } - else - { #if netcoreapp - var type = _resourceAssembly.GetType("System.SR"); + Type type = _resourceAssembly.GetType("System.SR"); #else - var type = _resourceAssembly.GetType("System.Strings"); + Type type = _resourceAssembly.GetType("System.Strings"); #endif - var info = type.GetProperty(resourceName, BindingFlags.NonPublic | BindingFlags.Static); + PropertyInfo info = type.GetProperty(resourceName, BindingFlags.NonPublic | BindingFlags.Static); - result = null; - if (info != null) + result = null; + if (info != null) + { + result = info.GetValue(null); + if (args != null) { - result = info.GetValue(null); - if (args != null) - { - result = string.Format((string)result, args); - } + result = string.Format((string)result, args); } - return result != null; } + return result != null; } } } diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj b/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj index 34bd1e6ead..89f9e36a4e 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/Microsoft.Data.SqlClient.ManualTesting.Tests.csproj @@ -272,9 +272,6 @@ Utf8String - - CoreFx.Private.TestUtilities - diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ConnectionExceptionTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ConnectionExceptionTest.cs index 70726e4448..48a9be0b22 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ConnectionExceptionTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ConnectionExceptionTest.cs @@ -180,10 +180,9 @@ private TException VerifyConnectionFailure(Action connectAction, str TException ex = Assert.Throws(connectAction); // Some exception messages are different between Framework and Core - if (!PlatformDetection.IsFullFramework) - { - Assert.Contains(expectedExceptionMessage, ex.Message); - } +#if netfx + Assert.Contains(expectedExceptionMessage, ex.Message); +#endif Assert.True(exVerifier(ex), "FAILED Exception verifier failed on the exception."); return ex; diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj deleted file mode 100644 index 1825cd49b0..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/CoreFx.Private.TestUtilities.csproj +++ /dev/null @@ -1,121 +0,0 @@ - - - CoreFx.Private.TestUtilities - CoreFx.Private.TestUtilities - {EBDB0247-CA43-4226-B7A1-8FEF21061D09} - netcoreapp - netfx - false - false - true - $(NoWarn);CS3021 - Test Utilities are not supported on this platform - false - Debug;Release;net46-Release;net46-Debug;netcoreapp2.1-Debug;netcoreapp2.1-Release;netcoreapp3.1-Debug;netcoreapp3.1-Release - AnyCPU;x86;x64 - $(ObjFolder)$(Configuration).$(Platform)\$(AssemblyName) - $(BinFolder)$(Configuration).$(Platform)\$(AssemblyName) - - - - - - - - - - - - - Common\System\PasteArguments.cs - - - - - - - Common\Interop\Windows\kernel32\Interop.GetCurrentProcess_IntPtr.cs - - - Common\System\PasteArguments.Windows.cs - - - Common\Interop\Windows\advapi32\Interop.OpenProcessToken_SafeAccessTokenHandle.cs - - - Common\Interop\Windows\Interop.Libraries.cs - - - Common\CoreLib\Interop\Windows\Kernel32\Interop.CloseHandle.cs - - - Common\Interop\Windows\advapi32\Interop.TOKEN_INFORMATION_CLASS.cs - - - Common\Interop\Windows\advapi32\Interop.GetTokenInformation_void.cs - - - Common\Interop\Windows\advapi32\Interop.TOKEN_ELEVATION.cs - - - Common\CoreLib\Interop\Windows\Interop.BOOL.cs - - - - - - Common\Interop\Unix\System.Security.Cryptography.Native\Interop.OpenSslVersion.cs - - - Common\System\PasteArguments.Unix.cs - - - - Common\Interop\Unix\Interop.GetEUid.cs - - - Common\Interop\Unix\Interop.Libraries.cs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/Resources/CoreFx.Private.TestUtilities.rd.xml b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/Resources/CoreFx.Private.TestUtilities.rd.xml deleted file mode 100644 index 05a1597d16..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/Resources/CoreFx.Private.TestUtilities.rd.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AdminHelpers.Unix.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AdminHelpers.Unix.cs deleted file mode 100644 index dd20faab20..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AdminHelpers.Unix.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace System -{ - /// - /// Returns true if the current process is elevated (in Unix). - /// - public static partial class AdminHelpers - { - public unsafe static bool IsProcessElevated() - { - uint userId = Interop.Sys.GetEUid(); - return(userId == 0); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AdminHelpers.Windows.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AdminHelpers.Windows.cs deleted file mode 100644 index 64173a9448..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AdminHelpers.Windows.cs +++ /dev/null @@ -1,44 +0,0 @@ -// 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. - -using System.ComponentModel; -using System.Runtime.InteropServices; -using System.Security.Principal; -using Microsoft.Win32.SafeHandles; - -namespace System -{ - public static partial class AdminHelpers - { - /// - /// Returns true if the current process is elevated (in Windows). - /// - public unsafe static bool IsProcessElevated() - { - IntPtr processHandle = Interop.Kernel32.GetCurrentProcess(); - SafeAccessTokenHandle token; - if (!Interop.Advapi32.OpenProcessToken(processHandle, TokenAccessLevels.Read, out token)) - { - throw new Win32Exception(Marshal.GetLastWin32Error(), "Open process token failed"); - } - - using (token) - { - Interop.Advapi32.TOKEN_ELEVATION elevation = new Interop.Advapi32.TOKEN_ELEVATION(); - uint ignore; - if (!Interop.Advapi32.GetTokenInformation( - token, - Interop.Advapi32.TOKEN_INFORMATION_CLASS.TokenElevation, - &elevation, - (uint)sizeof(Interop.Advapi32.TOKEN_ELEVATION), - out ignore)) - { - throw new Win32Exception(Marshal.GetLastWin32Error(), "Get token information failed"); - } - return elevation.TokenIsElevated != Interop.BOOL.FALSE; - } - } - - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AdminHelpers.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AdminHelpers.cs deleted file mode 100644 index 526e6bd500..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AdminHelpers.cs +++ /dev/null @@ -1,33 +0,0 @@ -// 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. - -using System.Diagnostics; -using Xunit; - -namespace System -{ - public static partial class AdminHelpers - { - /// - /// Runs the given command as sudo (for Unix). - /// - /// The command line to run as sudo - /// Returns the process exit code (0 typically means it is successful) - public static int RunAsSudo(string commandLine) - { - ProcessStartInfo startInfo = new ProcessStartInfo() - { - FileName = "sudo", - Arguments = commandLine - }; - - using (Process process = Process.Start(startInfo)) - { - Assert.True(process.WaitForExit(30000)); - return process.ExitCode; - } - } - - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Net/PlatformDetection.Networking.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Net/PlatformDetection.Networking.cs deleted file mode 100644 index 0aa9faf541..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/Net/PlatformDetection.Networking.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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. - -namespace System -{ - public static partial class PlatformDetection - { - // Windows 10 Insider Preview Build 16215 introduced the necessary APIs for the UAP version of - // ClientWebSocket.ReceiveAsync to consume partial message data as it arrives, without having to wait - // for "end of message" to be signaled. - public static bool ClientWebSocketPartialMessagesSupported => !IsUap || IsWindows10Version1709OrGreater; - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.NetFx.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.NetFx.cs deleted file mode 100644 index b6a33810ca..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.NetFx.cs +++ /dev/null @@ -1,68 +0,0 @@ -// 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. - -using Xunit; -using Microsoft.Win32; -using System.Runtime.Versioning; - -namespace System -{ - public static partial class PlatformDetection - { - private static string FrameworkName => AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName; - private static Version TargetVersion => string.IsNullOrEmpty(FrameworkName) ? new Version(4, 5, 0, 0) : new FrameworkName(FrameworkName).Version; - - // The current full framework xunit runner is targeting 4.5.2 so we expect TargetsNetFx452OrLower to be true. - // When we update xunit runner in the future which may target recent framework version, TargetsNetFx452OrLower can start return - // false but we don't expect any code change though. - public static bool TargetsNetFx452OrLower => TargetVersion.CompareTo(new Version(4, 5, 3, 0)) < 0; - - public static bool IsNetfx462OrNewer => GetFrameworkVersion() >= new Version(4, 6, 2); - - public static bool IsNetfx470OrNewer => GetFrameworkVersion() >= new Version(4, 7, 0); - - public static bool IsNetfx471OrNewer => GetFrameworkVersion() >= new Version(4, 7, 1); - - public static bool IsNetfx472OrNewer => GetFrameworkVersion() >= new Version(4, 7, 2); - - public static string LibcRelease => ""; - public static string LibcVersion => ""; - - // To get the framework version we can do it throught the registry key and getting the Release value under the .NET Framework key. - // the mapping to each version can be found in: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed - // everytime we ship a new version this method should be updated to include the new framework version. - private static Version GetFrameworkVersion() - { - using (RegistryKey ndpKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full")) - { - if (ndpKey != null) - { - int value = (int)(ndpKey.GetValue("Release") ?? 0); - if (value >= 461808) - return new Version(4, 7, 2); - if (value >= 461308) - return new Version(4, 7, 1); - if (value >= 460798) - return new Version(4, 7, 0); - if (value >= 394802) - return new Version(4, 6, 2); - if (value >= 394254) - return new Version(4, 6, 1); - if (value >= 393295) - return new Version(4, 6, 0); - if (value >= 379893) - return new Version(4, 5, 2); - if (value >= 378675) - return new Version(4, 5, 1); - if (value >= 378389) - return new Version(4, 5, 0); - - throw new NotSupportedException($"No 4.5 or later framework version detected, framework key value: {value}"); - } - - throw new NotSupportedException(@"No registry key found under 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' to determine running framework version"); - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.NonNetFx.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.NonNetFx.cs deleted file mode 100644 index 3d5dd55b4e..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.NonNetFx.cs +++ /dev/null @@ -1,62 +0,0 @@ -// 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. - -using System.Runtime.InteropServices; - -namespace System -{ - public static partial class PlatformDetection - { - public static bool TargetsNetFx452OrLower => false; - public static bool IsNetfx462OrNewer => false; - public static bool IsNetfx470OrNewer => false; - public static bool IsNetfx471OrNewer => false; - public static bool IsNetfx472OrNewer => false; - - - [DllImport("libc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr gnu_get_libc_release(); - - [DllImport("libc", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr gnu_get_libc_version(); - - /// - /// If gnulibc is available, returns the release, such as "stable". - /// Otherwise (eg., Windows, musl) returns "glibc_not_found". - /// - public static string LibcRelease - { - get - { - try - { - return Marshal.PtrToStringUTF8(gnu_get_libc_release()); - } - catch (Exception e) when (e is DllNotFoundException || e is EntryPointNotFoundException) - { - return "glibc_not_found"; - } - } - } - - /// - /// If gnulibc is available, returns the version, such as "2.22". - /// Otherwise (eg., Windows, musl) returns "glibc_not_found". (In future could run "ldd -version" for musl) - /// - public static string LibcVersion - { - get - { - try - { - return Marshal.PtrToStringUTF8(gnu_get_libc_version()); - } - catch (Exception e) when (e is DllNotFoundException || e is EntryPointNotFoundException) - { - return "glibc_not_found"; - } - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.Unix.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.Unix.cs deleted file mode 100644 index 3d2ab7f404..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.Unix.cs +++ /dev/null @@ -1,244 +0,0 @@ -// 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. - -using System.Diagnostics; -using System.IO; -using System.Xml.Linq; -using System.Runtime.InteropServices; -using System.Text; -using Xunit; - -namespace System -{ - public static partial class PlatformDetection - { - public static bool IsWindowsIoTCore => false; - public static bool IsWindows => false; - public static bool IsWindows7 => false; - public static bool IsWindows8x => false; - public static bool IsWindows10Version1607OrGreater => false; - public static bool IsWindows10Version1703OrGreater => false; - public static bool IsWindows10Version1709OrGreater => false; - public static bool IsWindows10Version1803OrGreater => false; - public static bool IsNotOneCoreUAP => true; - public static bool IsInAppContainer => false; - public static int WindowsVersion => -1; - - public static bool IsCentos6 => IsDistroAndVersion("centos", 6); - public static bool IsAlpine => IsDistroAndVersion("alpine"); - public static bool IsOpenSUSE => IsDistroAndVersion("opensuse"); - public static bool IsUbuntu => IsDistroAndVersion("ubuntu"); - public static bool IsDebian => IsDistroAndVersion("debian"); - public static bool IsDebian8 => IsDistroAndVersion("debian", 8); - public static bool IsUbuntu1404 => IsDistroAndVersion("ubuntu", 14, 4); - public static bool IsUbuntu1604 => IsDistroAndVersion("ubuntu", 16, 4); - public static bool IsUbuntu1704 => IsDistroAndVersion("ubuntu", 17, 4); - public static bool IsUbuntu1710 => IsDistroAndVersion("ubuntu", 17, 10); - public static bool IsUbuntu1710OrHigher => IsDistroAndVersionOrHigher("ubuntu", 17, 10); - public static bool IsUbuntu1804 => IsDistroAndVersion("ubuntu", 18, 04); - public static bool IsTizen => IsDistroAndVersion("tizen"); - public static bool IsFedora => IsDistroAndVersion("fedora"); - public static bool IsWindowsNanoServer => false; - public static bool IsWindowsServerCore => false; - public static bool IsWindowsAndElevated => false; - - // RedHat family covers RedHat and CentOS - public static bool IsRedHatFamily => IsRedHatFamilyAndVersion(); - public static bool IsNotRedHatFamily => !IsRedHatFamily; - public static bool IsRedHatFamily6 => IsRedHatFamilyAndVersion(6); - public static bool IsNotRedHatFamily6 => !IsRedHatFamily6; - public static bool IsRedHatFamily7 => IsRedHatFamilyAndVersion(7); - public static bool IsNotFedoraOrRedHatFamily => !IsFedora && !IsRedHatFamily; - - public static Version OSXVersion { get; } = ToVersion(Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion); - - public static Version OpenSslVersion => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? Interop.OpenSsl.OpenSslVersion : throw new PlatformNotSupportedException(); - - public static string GetDistroVersionString() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - return "OSX Version=" + s_osxProductVersion.ToString(); - } - - DistroInfo v = GetDistroInfo(); - - return "Distro=" + v.Id + " VersionId=" + v.VersionId; - } - - private static readonly Version s_osxProductVersion = GetOSXProductVersion(); - - public static bool IsMacOsHighSierraOrHigher { get; } = - IsOSX && (s_osxProductVersion.Major > 10 || (s_osxProductVersion.Major == 10 && s_osxProductVersion.Minor >= 13)); - - private static readonly Version s_icuVersion = GetICUVersion(); - public static Version ICUVersion => s_icuVersion; - - private static Version GetICUVersion() - { - int ver = GlobalizationNative_GetICUVersion(); - return new Version( ver & 0xFF, - (ver >> 8) & 0xFF, - (ver >> 16) & 0xFF, - ver >> 24); - } - - static Version ToVersion(string versionString) - { - if (versionString.IndexOf('.') != -1) - return new Version(versionString); - - // minor version is required by Version - // let's default it to 0 - return new Version(int.Parse(versionString), 0); - } - - private static DistroInfo GetDistroInfo() => new DistroInfo() - { - Id = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystem, - VersionId = ToVersion(Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment.OperatingSystemVersion) - }; - - private static bool IsRedHatFamilyAndVersion(int major = -1, int minor = -1, int build = -1, int revision = -1) - { - return IsDistroAndVersion((distro) => distro == "rhel" || distro == "centos", major, minor, build, revision); - } - - /// - /// Get whether the OS platform matches the given Linux distro and optional version. - /// - /// The distribution id. - /// The distro version. If omitted, compares the distro only. - /// Whether the OS platform matches the given Linux distro and optional version. - private static bool IsDistroAndVersion(string distroId, int major = -1, int minor = -1, int build = -1, int revision = -1) - { - return IsDistroAndVersion(distro => (distro == distroId), major, minor, build, revision); - } - - /// - /// Get whether the OS platform matches the given Linux distro and optional version is same or higher. - /// - /// The distribution id. - /// The distro version. If omitted, compares the distro only. - /// Whether the OS platform matches the given Linux distro and optional version is same or higher. - private static bool IsDistroAndVersionOrHigher(string distroId, int major = -1, int minor = -1, int build = -1, int revision = -1) - { - return IsDistroAndVersionOrHigher(distro => (distro == distroId), major, minor, build, revision); - } - - private static bool IsDistroAndVersion(Predicate distroPredicate, int major = -1, int minor = -1, int build = -1, int revision = -1) - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - DistroInfo v = GetDistroInfo(); - if (distroPredicate(v.Id) && VersionEquivalentTo(major, minor, build, revision, v.VersionId)) - { - return true; - } - } - - return false; - } - - private static bool IsDistroAndVersionOrHigher(Predicate distroPredicate, int major = -1, int minor = -1, int build = -1, int revision = -1) - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - DistroInfo v = GetDistroInfo(); - if (distroPredicate(v.Id) && VersionEquivalentToOrHigher(major, minor, build, revision, v.VersionId)) - { - return true; - } - } - - return false; - } - - private static bool VersionEquivalentTo(int major, int minor, int build, int revision, Version actualVersionId) - { - return (major == -1 || major == actualVersionId.Major) - && (minor == -1 || minor == actualVersionId.Minor) - && (build == -1 || build == actualVersionId.Build) - && (revision == -1 || revision == actualVersionId.Revision); - } - - private static bool VersionEquivalentToOrHigher(int major, int minor, int build, int revision, Version actualVersionId) - { - return - VersionEquivalentTo(major, minor, build, revision, actualVersionId) || - (actualVersionId.Major > major || - (actualVersionId.Major == major && actualVersionId.Minor > minor || - (actualVersionId.Minor == minor && actualVersionId.Build > build || - (actualVersionId.Build == build && actualVersionId.Revision > revision || - (actualVersionId.Revision == revision))))); - } - - private static Version GetOSXProductVersion() - { - try - { - if (IsOSX) - { - // - // - // ProductBuildVersion - // 17A330h - // ProductCopyright - // 1983-2017 Apple Inc. - // ProductName - // Mac OS X - // ProductUserVisibleVersion - // 10.13 - // ProductVersion - // 10.13 - // - // - - XElement dict = XDocument.Load("/System/Library/CoreServices/SystemVersion.plist").Root.Element("dict"); - if (dict != null) - { - foreach (XElement key in dict.Elements("key")) - { - if ("ProductVersion".Equals(key.Value)) - { - XElement stringElement = key.NextNode as XElement; - if (stringElement != null && stringElement.Name.LocalName.Equals("string")) - { - string versionString = stringElement.Value; - if (versionString != null) - { - return Version.Parse(versionString); - } - } - } - } - } - } - } - catch - { - } - - // In case of exception or couldn't get the version - return new Version(0, 0, 0); - } - - [DllImport("libc", SetLastError = true)] - private static extern int sysctlbyname(string ctlName, byte[] oldp, ref IntPtr oldpLen, byte[] newp, IntPtr newpLen); - - [DllImport("libc", SetLastError = true)] - internal static extern unsafe uint geteuid(); - - [DllImport("System.Globalization.Native", SetLastError = true)] - private static extern int GlobalizationNative_GetICUVersion(); - - public static bool IsSuperUser => geteuid() == 0; - - private struct DistroInfo - { - public string Id { get; set; } - public Version VersionId { get; set; } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.Windows.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.Windows.cs deleted file mode 100644 index 607e52d7aa..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.Windows.cs +++ /dev/null @@ -1,272 +0,0 @@ -// 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. - -using System.IO; -using System.Runtime.InteropServices; -using System.Security; -using Microsoft.Win32; -using Xunit; - -namespace System -{ - public static partial class PlatformDetection - { - public static Version OSXVersion => throw new PlatformNotSupportedException(); - public static Version OpenSslVersion => throw new PlatformNotSupportedException(); - public static bool IsSuperUser => throw new PlatformNotSupportedException(); - public static bool IsCentos6 => false; - public static bool IsOpenSUSE => false; - public static bool IsUbuntu => false; - public static bool IsDebian => false; - public static bool IsAlpine => false; - public static bool IsDebian8 => false; - public static bool IsUbuntu1404 => false; - public static bool IsUbuntu1604 => false; - public static bool IsUbuntu1704 => false; - public static bool IsUbuntu1710 => false; - public static bool IsUbuntu1710OrHigher => false; - public static bool IsUbuntu1804 => false; - public static bool IsTizen => false; - public static bool IsNotFedoraOrRedHatFamily => true; - public static bool IsFedora => false; - public static bool IsWindowsNanoServer => (IsNotWindowsIoTCore && GetInstallationType().Equals("Nano Server", StringComparison.OrdinalIgnoreCase)); - public static bool IsWindowsServerCore => GetInstallationType().Equals("Server Core", StringComparison.OrdinalIgnoreCase); - public static int WindowsVersion => GetWindowsVersion(); - public static bool IsMacOsHighSierraOrHigher { get; } = false; - public static Version ICUVersion => new Version(0, 0, 0, 0); - public static bool IsRedHatFamily => false; - public static bool IsNotRedHatFamily => true; - public static bool IsRedHatFamily6 => false; - public static bool IsRedHatFamily7 => false; - public static bool IsNotRedHatFamily6 => true; - - public static bool IsWindows10Version1607OrGreater => - GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildNumber() >= 14393; - public static bool IsWindows10Version1703OrGreater => - GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildNumber() >= 15063; - public static bool IsWindows10Version1709OrGreater => - GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildNumber() >= 16299; - public static bool IsWindows10Version1803OrGreater => - GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildNumber() >= 17134; - - // Windows OneCoreUAP SKU doesn't have httpapi.dll - public static bool IsNotOneCoreUAP => - File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "System32", "httpapi.dll")); - - public static bool IsWindowsIoTCore - { - get - { - int productType = GetWindowsProductType(); - if ((productType == PRODUCT_IOTUAPCOMMERCIAL) || - (productType == PRODUCT_IOTUAP)) - { - return true; - } - return false; - } - } - - public static bool IsWindows => true; - public static bool IsWindows7 => GetWindowsVersion() == 6 && GetWindowsMinorVersion() == 1; - public static bool IsWindows8x => GetWindowsVersion() == 6 && (GetWindowsMinorVersion() == 2 || GetWindowsMinorVersion() == 3); - - public static string GetDistroVersionString() { return "WindowsProductType=" + GetWindowsProductType() + " WindowsInstallationType=" + GetInstallationType(); } - - private static int s_isInAppContainer = -1; - - public static bool IsInAppContainer - { - // This actually checks whether code is running in a modern app. - // Currently this is the only situation where we run in app container. - // If we want to distinguish the two cases in future, - // EnvironmentHelpers.IsAppContainerProcess in desktop code shows how to check for the AC token. - get - { - if (s_isInAppContainer != -1) - return s_isInAppContainer == 1; - - if (!IsWindows || IsWindows7) - { - s_isInAppContainer = 0; - return false; - } - - byte[] buffer = Array.Empty(); - uint bufferSize = 0; - try - { - int result = GetCurrentApplicationUserModelId(ref bufferSize, buffer); - switch (result) - { - case 15703: // APPMODEL_ERROR_NO_APPLICATION - s_isInAppContainer = 0; - break; - case 0: // ERROR_SUCCESS - case 122: // ERROR_INSUFFICIENT_BUFFER - // Success is actually insufficent buffer as we're really only looking for - // not NO_APPLICATION and we're not actually giving a buffer here. The - // API will always return NO_APPLICATION if we're not running under a - // WinRT process, no matter what size the buffer is. - s_isInAppContainer = 1; - break; - default: - throw new InvalidOperationException($"Failed to get AppId, result was {result}."); - } - } - catch (Exception e) - { - // We could catch this here, being friendly with older portable surface area should we - // desire to use this method elsewhere. - if (e.GetType().FullName.Equals("System.EntryPointNotFoundException", StringComparison.Ordinal)) - { - // API doesn't exist, likely pre Win8 - s_isInAppContainer = 0; - } - else - { - throw; - } - } - - return s_isInAppContainer == 1; - } - } - - private static int s_isWindowsElevated = -1; - - public static bool IsWindowsAndElevated - { - get - { - if (s_isWindowsElevated != -1) - return s_isWindowsElevated == 1; - - if (!IsWindows || IsInAppContainer) - { - s_isWindowsElevated = 0; - return false; - } - - IntPtr processToken; - Assert.True(OpenProcessToken(GetCurrentProcess(), TOKEN_READ, out processToken)); - - try - { - uint tokenInfo; - uint returnLength; - Assert.True(GetTokenInformation( - processToken, TokenElevation, out tokenInfo, sizeof(uint), out returnLength)); - - s_isWindowsElevated = tokenInfo == 0 ? 0 : 1; - } - finally - { - CloseHandle(processToken); - } - - return s_isWindowsElevated == 1; - } - } - - private static string GetInstallationType() - { - string key = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"; - string value = ""; - - try - { - value = (string)Registry.GetValue(key, "InstallationType", defaultValue: ""); - } - catch (Exception e) when (e is SecurityException || e is InvalidCastException || e is PlatformNotSupportedException /* UAP */) - { - } - - return value; - } - - private static int GetWindowsProductType() - { - Assert.True(GetProductInfo(Environment.OSVersion.Version.Major, Environment.OSVersion.Version.Minor, 0, 0, out int productType)); - return productType; - } - - private static int GetWindowsMinorVersion() - { - RTL_OSVERSIONINFOEX osvi = new RTL_OSVERSIONINFOEX(); - osvi.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osvi); - Assert.Equal(0, RtlGetVersion(out osvi)); - return (int)osvi.dwMinorVersion; - } - - private static int GetWindowsBuildNumber() - { - RTL_OSVERSIONINFOEX osvi = new RTL_OSVERSIONINFOEX(); - osvi.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osvi); - Assert.Equal(0, RtlGetVersion(out osvi)); - return (int)osvi.dwBuildNumber; - } - - private const uint TokenElevation = 20; - private const uint STANDARD_RIGHTS_READ = 0x00020000; - private const uint TOKEN_QUERY = 0x0008; - private const uint TOKEN_READ = STANDARD_RIGHTS_READ | TOKEN_QUERY; - - [DllImport("advapi32.dll", SetLastError = true, ExactSpelling = true)] - private static extern bool GetTokenInformation( - IntPtr TokenHandle, - uint TokenInformationClass, - out uint TokenInformation, - uint TokenInformationLength, - out uint ReturnLength); - - private const int PRODUCT_IOTUAP = 0x0000007B; - private const int PRODUCT_IOTUAPCOMMERCIAL = 0x00000083; - - [DllImport("kernel32.dll", SetLastError = false)] - private static extern bool GetProductInfo( - int dwOSMajorVersion, - int dwOSMinorVersion, - int dwSpMajorVersion, - int dwSpMinorVersion, - out int pdwReturnedProductType - ); - - [DllImport("ntdll.dll")] - private static extern int RtlGetVersion(out RTL_OSVERSIONINFOEX lpVersionInformation); - - [StructLayout(LayoutKind.Sequential)] - private struct RTL_OSVERSIONINFOEX - { - internal uint dwOSVersionInfoSize; - internal uint dwMajorVersion; - internal uint dwMinorVersion; - internal uint dwBuildNumber; - internal uint dwPlatformId; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] - internal string szCSDVersion; - } - - private static int GetWindowsVersion() - { - RTL_OSVERSIONINFOEX osvi = new RTL_OSVERSIONINFOEX(); - osvi.dwOSVersionInfoSize = (uint)Marshal.SizeOf(osvi); - Assert.Equal(0, RtlGetVersion(out osvi)); - return (int)osvi.dwMajorVersion; - } - - [DllImport("kernel32.dll", ExactSpelling = true)] - private static extern int GetCurrentApplicationUserModelId(ref uint applicationUserModelIdLength, byte[] applicationUserModelId); - - [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)] - private static extern bool CloseHandle(IntPtr handle); - - [DllImport("advapi32.dll", SetLastError = true, ExactSpelling = true)] - private static extern bool OpenProcessToken(IntPtr ProcessHandle, uint DesiredAccess, out IntPtr TokenHandle); - - // The process handle does NOT need closing - [DllImport("kernel32.dll", ExactSpelling = true)] - private static extern IntPtr GetCurrentProcess(); - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.cs deleted file mode 100644 index d1b8a63e98..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/PlatformDetection.cs +++ /dev/null @@ -1,133 +0,0 @@ -// 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. - -using System.IO; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -namespace System -{ - public static partial class PlatformDetection - { - // - // Do not use the " { get; } = " pattern here. Having all the initialization happen in the type initializer - // means that one exception anywhere means all tests using PlatformDetection fail. If you feel a value is worth latching, - // do it in a way that failures don't cascade. - // - - public static bool HasWindowsShell => IsWindows && IsNotWindowsServerCore && IsNotWindowsNanoServer && IsNotWindowsIoTCore; - public static bool IsUap => IsInAppContainer || IsNetNative; - public static bool IsFullFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase); - public static bool IsNetNative => RuntimeInformation.FrameworkDescription.StartsWith(".NET Native", StringComparison.OrdinalIgnoreCase); - public static bool IsNetCore => RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase); - public static bool IsOSX => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); - public static bool IsFreeBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")); - public static bool IsNetBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")); - public static bool IsNotWindows8x => !IsWindows8x; - public static bool IsNotWindowsNanoServer => !IsWindowsNanoServer; - public static bool IsNotWindowsServerCore => !IsWindowsServerCore; - public static bool IsNotWindowsIoTCore => !IsWindowsIoTCore; - public static bool IsDrawingSupported => (IsNotWindowsNanoServer && IsNotWindowsIoTCore); - public static bool IsArmProcess => RuntimeInformation.ProcessArchitecture == Architecture.Arm; - public static bool IsNotArmProcess => !IsArmProcess; - - public static bool IsNotInAppContainer => !IsInAppContainer; - public static bool IsWinRTSupported => IsWindows && !IsWindows7; - public static bool IsNotWinRTSupported => !IsWinRTSupported; - public static bool IsNotMacOsHighSierraOrHigher => !IsMacOsHighSierraOrHigher; - - public static bool IsDomainJoinedMachine => !Environment.MachineName.Equals(Environment.UserDomainName, StringComparison.OrdinalIgnoreCase); - - public static bool IsNotNetNative => !IsNetNative; - - // Windows - Schannel supports alpn from win8.1/2012 R2 and higher. - // Linux - OpenSsl supports alpn from openssl 1.0.2 and higher. - // OSX - SecureTransport doesn't expose alpn APIs. #30492 - public static bool SupportsAlpn => (IsWindows && !IsWindows7) || - (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && - (OpenSslVersion.Major >= 1 && (OpenSslVersion.Minor >= 1 || OpenSslVersion.Build >= 2))); - - // Officially, .NET Native only supports processes running in an AppContainer. However, the majority of tests still work fine - // in a normal Win32 process and we often do so as running in an AppContainer imposes a substantial tax in debuggability - // and investigatability. This predicate is used in ConditionalFacts to disable the specific tests that really need to be - // running in AppContainer when running on .NetNative. - public static bool IsNotNetNativeRunningAsConsoleApp => !(IsNetNative && !IsInAppContainer); - - private static Lazy m_isWindowsSubsystemForLinux = new Lazy(GetIsWindowsSubsystemForLinux); - - public static bool IsWindowsSubsystemForLinux => m_isWindowsSubsystemForLinux.Value; - public static bool IsNotWindowsSubsystemForLinux => !IsWindowsSubsystemForLinux; - - private static bool GetIsWindowsSubsystemForLinux() - { - // https://github.com/Microsoft/BashOnWindows/issues/423#issuecomment-221627364 - - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - const string versionFile = "/proc/version"; - if (File.Exists(versionFile)) - { - string s = File.ReadAllText(versionFile); - - if (s.Contains("Microsoft") || s.Contains("WSL")) - { - return true; - } - } - } - - return false; - } - - private static Lazy s_largeArrayIsNotSupported = new Lazy(IsLargeArrayNotSupported); - - [MethodImpl(MethodImplOptions.NoOptimization)] - private static bool IsLargeArrayNotSupported() - { - try - { - var tmp = new byte[int.MaxValue]; - return tmp == null; - } - catch (OutOfMemoryException) - { - return true; - } - } - - public static bool IsNotIntMaxValueArrayIndexSupported => s_largeArrayIsNotSupported.Value; - - public static bool IsNonZeroLowerBoundArraySupported - { - get - { - if (s_lazyNonZeroLowerBoundArraySupported == null) - { - bool nonZeroLowerBoundArraysSupported = false; - try - { - Array.CreateInstance(typeof(int), new int[] { 5 }, new int[] { 5 }); - nonZeroLowerBoundArraysSupported = true; - } - catch (PlatformNotSupportedException) - { - } - s_lazyNonZeroLowerBoundArraySupported = Tuple.Create(nonZeroLowerBoundArraysSupported); - } - return s_lazyNonZeroLowerBoundArraySupported.Item1; - } - } - - private static volatile Tuple s_lazyNonZeroLowerBoundArraySupported; - - public static bool IsReflectionEmitSupported = !PlatformDetection.IsNetNative; - - // Tracked in: https://github.com/dotnet/corert/issues/3643 in case we change our mind about this. - public static bool IsInvokingStaticConstructorsSupported => !PlatformDetection.IsNetNative; - - // System.Security.Cryptography.Xml.XmlDsigXsltTransform.GetOutput() relies on XslCompiledTransform which relies - // heavily on Reflection.Emit - public static bool IsXmlDsigXsltTransformSupported => !PlatformDetection.IsUap; - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/TestEnvironment.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/TestEnvironment.cs deleted file mode 100644 index f083cd862b..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/TestEnvironment.cs +++ /dev/null @@ -1,22 +0,0 @@ -// 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. - -namespace System -{ - public static partial class TestEnvironment - { - /// - /// Check if the stress mode is enabled. - /// - /// true if the environment variable COREFX_STRESS set to '1' or 'true'. returns false otherwise - public static bool IsStressModeEnabled - { - get - { - string value = Environment.GetEnvironmentVariable("COREFX_STRESS"); - return value != null && (value == "1" || value.Equals("true", StringComparison.OrdinalIgnoreCase)); - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/TheoryExtensions.cs b/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/TheoryExtensions.cs deleted file mode 100644 index ed682e41a7..0000000000 --- a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/TheoryExtensions.cs +++ /dev/null @@ -1,38 +0,0 @@ -// 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. - -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using Xunit; - -namespace System -{ - public static class TheoryExtensions - { - /// - /// Converts an IEnumerable into an Xunit theory compatible enumerable. - /// - public static TheoryData ToTheoryData(this IEnumerable data) - { - // Returning TheoryData rather than IEnumerable directly should - // encourage discover and usage of TheoryData classes for more - // complicated theories. Slightly easier to type as well. - return new TheoryDataAdapter(data.Select(d => new object[] { d })); - } - - private class TheoryDataAdapter : TheoryData, IEnumerable - { - private IEnumerable _data; - - public TheoryDataAdapter(IEnumerable data) - { - _data = data; - } - - public new IEnumerator GetEnumerator() => _data.GetEnumerator(); - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AssertExtensions.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.DotNet.XUnitExtensions/Extensions/AssertExtensions.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/tests/tools/CoreFx.Private.TestUtilities/System/AssertExtensions.cs rename to src/Microsoft.Data.SqlClient/tests/tools/Microsoft.DotNet.XUnitExtensions/Extensions/AssertExtensions.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSid.cs b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.DotNet.XUnitExtensions/Extensions/PlatformDetection.cs similarity index 52% rename from src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSid.cs rename to src/Microsoft.Data.SqlClient/tests/tools/Microsoft.DotNet.XUnitExtensions/Extensions/PlatformDetection.cs index d13108bfb0..1d089151aa 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Native/Interop.GetSid.cs +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.DotNet.XUnitExtensions/Extensions/PlatformDetection.cs @@ -4,11 +4,11 @@ using System.Runtime.InteropServices; -internal static partial class Interop +namespace System { - internal static partial class Sys + public static partial class PlatformDetection { - [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetSid")] - internal static extern int GetSid(int pid); + public static bool IsArmProcess => RuntimeInformation.ProcessArchitecture == Architecture.Arm; + public static bool IsNotArmProcess => !IsArmProcess; } } diff --git a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.DotNet.XUnitExtensions/Microsoft.DotNet.XUnitExtensions.csproj b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.DotNet.XUnitExtensions/Microsoft.DotNet.XUnitExtensions.csproj index 5fcdbc135e..cc26e34f12 100644 --- a/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.DotNet.XUnitExtensions/Microsoft.DotNet.XUnitExtensions.csproj +++ b/src/Microsoft.Data.SqlClient/tests/tools/Microsoft.DotNet.XUnitExtensions/Microsoft.DotNet.XUnitExtensions.csproj @@ -26,6 +26,8 @@ + + @@ -46,6 +48,7 @@ + diff --git a/tools/props/Versions.props b/tools/props/Versions.props index 16c550dfd6..76973e673a 100644 --- a/tools/props/Versions.props +++ b/tools/props/Versions.props @@ -56,6 +56,7 @@ 15.9.0 3.1.0 12.0.3 + 4.3.0 4.3.0 4.5.0 4.6.0 From 74deeec17145434bf43ac6314c973e68b4da39dc Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Fri, 24 Jul 2020 09:40:50 -0700 Subject: [PATCH 3/4] Minor edit --- .../src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs index eb6f0811f9..ea802107ff 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs @@ -222,7 +222,7 @@ internal override uint GenerateSspiClientContext(byte[] receivedBuff, uint recei _sspiClientContextStatus = new SspiClientContextStatus(); } - // SNIProxy.GetInstance().GenSspiClientContext(_sspiClientContextStatus, receivedBuff, ref sendBuff, _sniSpnBuffer); + SNIProxy.GetInstance().GenSspiClientContext(_sspiClientContextStatus, receivedBuff, ref sendBuff, _sniSpnBuffer); sendLength = (uint)(sendBuff != null ? sendBuff.Length : 0); return 0; } From 2fada146740365c0c026919389b0d7270c34c924 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Thu, 27 Aug 2020 11:00:03 -0700 Subject: [PATCH 4/4] Merge issues resolved --- .../Unix/System.Net.Security.Native/Interop.GssBuffer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs index b7c2f93d9f..80a32e6c5a 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs @@ -31,7 +31,7 @@ internal int Copy(byte[] destination, int offset) int destinationAvailable = destination.Length - offset; // amount of space in the given buffer if (sourceLength > destinationAvailable) { - throw new GssApiException(SRHelper.Format(Strings.net_context_buffer_too_small, sourceLength, destinationAvailable)); + throw new GssApiException(StringsHelper.Format(Strings.net_context_buffer_too_small, sourceLength, destinationAvailable)); } Marshal.Copy(_data, destination, offset, sourceLength);