Merge | NativeMethods/SafeNativeMethods (#2997)

* Moving SafeNativeMethods to Interop.Windows.Kernel32 namespace, migrating usages

* Move Kernel32 calls from NativeMethods to Interop.Windows.Kernel32

* Moving AdvApi32 interop calls to Interop.Windows.AdvApi32, migrating usages

* Remove redundant safe method in SNINativeMethodWrapper, migrate usages
This commit is contained in:
Benjamin Russell 2024-11-13 12:04:41 -06:00 коммит произвёл GitHub
Родитель 35c317b99a
Коммит 4052186ac6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
11 изменённых файлов: 168 добавлений и 153 удалений

Просмотреть файл

@ -100,8 +100,8 @@
</ItemGroup>
<!-- Contains common items shared between NetFx and NetCore -->
<ItemGroup>
<Compile Include="$(CommonSourceRoot)Interop\Windows\SystemErrors.cs">
<Link>Interop\SystemErrors.cs</Link>
<Compile Include="$(CommonSourceRoot)Interop\Windows\AdvApi32\AdvApi32.netfx.cs">
<Link>Interop\AdvApi32\AdvApi32.netfx.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Interop\Windows\Kernel32\FileTypes.cs">
<Link>Interop\Kernel32\FileTypes.cs</Link>
@ -115,6 +115,9 @@
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Kernel32\Kernel32.cs">
<Link>Interop\Kernel32\Kernel32.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\Kernel32\Kernel32Safe.netfx.cs">
<Link>Interop\Kernel32\Kernel32Safe.netfx.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\CreateDisposition.cs">
<Link>Interop\NtDll\CreateDisposition.cs</Link>
</Compile>
@ -145,6 +148,9 @@
<Compile Include="$(CommonSourceRoot)\Interop\Windows\NtDll\SecurityQualityOfService.cs">
<Link>Interop\NtDll\SecurityQualityOfService.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Interop\Windows\SystemErrors.cs">
<Link>Interop\SystemErrors.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Interop\Windows\UnicodeString.cs">
<Link>Interop\UnicodeString.cs</Link>
</Compile>
@ -748,8 +754,6 @@
<Compile Include="Microsoft\Data\Common\DbConnectionOptions.cs" />
<Compile Include="Microsoft\Data\Common\DbConnectionString.cs" />
<Compile Include="Microsoft\Data\Common\GreenMethods.cs" />
<Compile Include="Microsoft\Data\Common\NativeMethods.cs" />
<Compile Include="Microsoft\Data\Common\SafeNativeMethods.cs" />
<Compile Include="Microsoft\Data\Interop\SNINativeManagedWrapperARM64.cs" />
<Compile Include="Microsoft\Data\Interop\SNINativeManagedWrapperX64.cs" />
<Compile Include="Microsoft\Data\Interop\SNINativeManagedWrapperX86.cs" />

Просмотреть файл

@ -1,106 +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.Versioning;
namespace Microsoft.Data.Common
{
internal static class NativeMethods
{
private const string Advapi32 = "advapi32.dll";
private const string Kernel32 = "kernel32.dll";
[DllImport(Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
[ResourceExposure(ResourceScope.Machine)]
static internal extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, int dwDesiredAccess, int dwFileOffsetHigh, int dwFileOffsetLow, IntPtr dwNumberOfBytesToMap);
// OpenFileMappingA contains a security venerability, in the unicode->ansi conversion
// Its possible to spoof the directory and construct ../ sequences, See FxCop Warning
// Specify marshaling for pinvoke string arguments
[DllImport(Kernel32, CharSet = System.Runtime.InteropServices.CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
// [DllImport(ExternDll.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Ansi)]
[ResourceExposure(ResourceScope.Machine)]
static internal extern IntPtr OpenFileMappingA(int dwDesiredAccess, bool bInheritHandle, [MarshalAs(UnmanagedType.LPStr)] string lpName);
// CreateFileMappingA contains a security venerability, in the unicode->ansi conversion
// Its possible to spoof the directory and construct ../ sequences, See FxCop Warning
// Specify marshaling for pinvoke string arguments
[DllImport(Kernel32, CharSet = System.Runtime.InteropServices.CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
// [DllImport(ExternDll.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Ansi)]
[ResourceExposure(ResourceScope.Machine)]
static internal extern IntPtr CreateFileMappingA(IntPtr hFile, IntPtr pAttr, int flProtect, int dwMaximumSizeHigh, int dwMaximumSizeLow, [MarshalAs(UnmanagedType.LPStr)] string lpName);
[DllImport(Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
[ResourceExposure(ResourceScope.Machine)]
static internal extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
[DllImport(Kernel32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.Machine)]
static internal extern bool CloseHandle(IntPtr handle);
[DllImport(Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static internal extern bool AllocateAndInitializeSid(
IntPtr pIdentifierAuthority, // authority
byte nSubAuthorityCount, // count of subauthorities
int dwSubAuthority0, // subauthority 0
int dwSubAuthority1, // subauthority 1
int dwSubAuthority2, // subauthority 2
int dwSubAuthority3, // subauthority 3
int dwSubAuthority4, // subauthority 4
int dwSubAuthority5, // subauthority 5
int dwSubAuthority6, // subauthority 6
int dwSubAuthority7, // subauthority 7
ref IntPtr pSid); // SID
[DllImport(Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static internal extern int GetLengthSid(
IntPtr pSid); // SID to query
[DllImport(Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static internal extern bool InitializeAcl(
IntPtr pAcl, // ACL
int nAclLength, // size of ACL
int dwAclRevision); // revision level of ACL
[DllImport(Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static internal extern bool AddAccessDeniedAce(
IntPtr pAcl, // access control list
int dwAceRevision, // ACL revision level
int AccessMask, // access mask
IntPtr pSid); // security identifier
[DllImport(Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static internal extern bool AddAccessAllowedAce(
IntPtr pAcl, // access control list
int dwAceRevision, // ACL revision level
uint AccessMask, // access mask
IntPtr pSid); // security identifier
[DllImport(Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static internal extern bool InitializeSecurityDescriptor(
IntPtr pSecurityDescriptor, // SD
int dwRevision); // revision level
[DllImport(Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static internal extern bool SetSecurityDescriptorDacl(
IntPtr pSecurityDescriptor, // SD
bool bDaclPresent, // DACL presence
IntPtr pDacl, // DACL
bool bDaclDefaulted); // default DACL
[DllImport(Advapi32, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static internal extern IntPtr FreeSid(
IntPtr pSid); // SID to free
}
}

Просмотреть файл

@ -1236,15 +1236,6 @@ namespace Microsoft.Data.SqlClient
}
}
namespace Microsoft.Data
{
internal static partial class SafeNativeMethods
{
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true, SetLastError = true)]
internal static extern IntPtr GetProcAddress(IntPtr HModule, [MarshalAs(UnmanagedType.LPStr), In] string funcName);
}
}
namespace Microsoft.Data
{
internal static class Win32NativeMethods

Просмотреть файл

@ -12,6 +12,7 @@ using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading;
using Interop.Windows.Kernel32;
using Microsoft.Data.SqlClient;
namespace Microsoft.Data
@ -121,7 +122,7 @@ namespace Microsoft.Data
Monitor.Enter(s_dllLock, ref lockTaken);
if (s_localDBCreateInstance == null)
{
IntPtr functionAddr = SafeNativeMethods.GetProcAddress(UserInstanceDLLHandle, "LocalDBCreateInstance");
IntPtr functionAddr = Kernel32Safe.GetProcAddress(UserInstanceDLLHandle, "LocalDBCreateInstance");
if (functionAddr == IntPtr.Zero)
{
@ -162,7 +163,7 @@ namespace Microsoft.Data
Monitor.Enter(s_dllLock, ref lockTaken);
if (s_localDBFormatMessage == null)
{
IntPtr functionAddr = SafeNativeMethods.GetProcAddress(UserInstanceDLLHandle, "LocalDBFormatMessage");
IntPtr functionAddr = Kernel32Safe.GetProcAddress(UserInstanceDLLHandle, "LocalDBFormatMessage");
if (functionAddr == IntPtr.Zero)
{

Просмотреть файл

@ -24,8 +24,10 @@ using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Interop.Windows.AdvApi32;
using Microsoft.Data.ProviderBase;
using Microsoft.SqlServer.Server;
using Interop.Windows.Kernel32;
[assembly: InternalsVisibleTo("System.Data.DataSetExtensions, PublicKey=" + Microsoft.Data.SqlClient.AssemblyRef.EcmaPublicKeyFull)] // DevDiv Bugs 92166
// NOTE: The current Microsoft.VSDesigner editor attributes are implemented for System.Data.SqlClient, and are not publicly available.
@ -2532,7 +2534,7 @@ namespace Microsoft.Data.SqlClient
private void CheckSQLDebugOnConnect()
{
IntPtr hFileMap;
uint pid = (uint)SafeNativeMethods.GetCurrentProcessId();
uint pid = (uint)Kernel32Safe.GetCurrentProcessId();
string mapFileName;
@ -2548,11 +2550,11 @@ namespace Microsoft.Data.SqlClient
mapFileName = mapFileName + pid.ToString(CultureInfo.InvariantCulture);
hFileMap = NativeMethods.OpenFileMappingA(0x4/*FILE_MAP_READ*/, false, mapFileName);
hFileMap = Kernel32.OpenFileMappingA(0x4/*FILE_MAP_READ*/, false, mapFileName);
if (ADP.s_ptrZero != hFileMap)
{
IntPtr pMemMap = NativeMethods.MapViewOfFile(hFileMap, 0x4/*FILE_MAP_READ*/, 0, 0, IntPtr.Zero);
IntPtr pMemMap = Kernel32.MapViewOfFile(hFileMap, 0x4/*FILE_MAP_READ*/, 0, 0, IntPtr.Zero);
if (ADP.s_ptrZero != pMemMap)
{
SqlDebugContext sdc = new SqlDebugContext();
@ -3098,12 +3100,12 @@ namespace Microsoft.Data.SqlClient
}
if (pMemMap != IntPtr.Zero)
{
NativeMethods.UnmapViewOfFile(pMemMap);
Kernel32.UnmapViewOfFile(pMemMap);
pMemMap = IntPtr.Zero;
}
if (hMemMap != IntPtr.Zero)
{
NativeMethods.CloseHandle(hMemMap);
Kernel32.CloseHandle(hMemMap);
hMemMap = IntPtr.Zero;
}
active = false;

Просмотреть файл

@ -0,0 +1,63 @@
// 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.Versioning;
namespace Interop.Windows.AdvApi32
{
internal class AdvApi32
{
private const string DllName = "advapi32.dll";
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool AddAccessAllowedAce(IntPtr pAcl, int dwAceRevision, uint AccessMask, IntPtr pSid);
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool AddAccessDeniedAce(IntPtr pAcl, int dwAceRevision, int AccessMask, IntPtr pSid);
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool AllocateAndInitializeSid(
IntPtr pIdentifierAuthority,
byte nSubAuthorityCount,
int dwSubAuthority0,
int dwSubAuthority1,
int dwSubAuthority2,
int dwSubAuthority3,
int dwSubAuthority4,
int dwSubAuthority5,
int dwSubAuthority6,
int dwSubAuthority7,
ref IntPtr pSid);
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
internal static extern IntPtr FreeSid(IntPtr pSid);
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
internal static extern int GetLengthSid(IntPtr pSid);
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool InitializeAcl(IntPtr pAcl, int nAclLength, int dwAclRevision);
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool InitializeSecurityDescriptor(IntPtr pSecurityDescriptor, int dwRevision);
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
internal static extern bool SetSecurityDescriptorDacl(
IntPtr pSecurityDescriptor,
bool bDaclPresent,
IntPtr pDacl,
bool bDaclDefaulted);
}
}

Просмотреть файл

@ -44,6 +44,27 @@ namespace Interop.Windows.Kernel32
return (uint)((deviceType << 16) | (access << 14) | (function << 2) | method);
}
#if NETFRAMEWORK
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
[ResourceExposure(ResourceScope.Machine)]
internal static extern bool CloseHandle(IntPtr handle);
#endif
#if NETFRAMEWORK
// CreateFileMappingA contains a security venerability, in the unicode->ansi conversion
// Its possible to spoof the directory and construct ../ sequences, See FxCop Warning
// Specify marshaling for pinvoke string arguments
[DllImport(DllName, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
[ResourceExposure(ResourceScope.Machine)]
internal static extern IntPtr CreateFileMappingA(
IntPtr hFile,
IntPtr pAttr,
int flProtect,
int dwMaximumSizeHigh,
int dwMaximumSizeLow,
[MarshalAs(UnmanagedType.LPStr)] string lpName);
#endif
[DllImport(DllName, CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern bool DeviceIoControl(
SafeFileHandle fileHandle,
@ -55,7 +76,7 @@ namespace Interop.Windows.Kernel32
out uint cbBytesReturned,
IntPtr overlapped);
#if !NETFRAMEWORK
#if NET
[DllImport(DllName, ExactSpelling = true, SetLastError = true)]
public static extern bool FreeLibrary([In] IntPtr hModule);
#endif
@ -63,6 +84,7 @@ namespace Interop.Windows.Kernel32
[DllImport(DllName, SetLastError = true)]
internal static extern int GetFileType(SafeHandle hFile);
#if NETFRAMEWORK
[DllImport(DllName, SetLastError = true, CharSet = CharSet.Unicode)]
[ResourceExposure(ResourceScope.Machine)]
internal static extern int GetFullPathName(
@ -70,23 +92,53 @@ namespace Interop.Windows.Kernel32
int numBufferChars,
StringBuilder buffer,
IntPtr lpFilePartOrNull);
#endif
#if !NETFRAMEWORK
#if NET
[DllImport(DllName, CharSet = CharSet.Ansi, BestFitMapping = false)]
public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
#endif
#if !NETFRAMEWORK
#if NET
[DllImport(DllName, CharSet = CharSet.Ansi, BestFitMapping = false)]
public static extern IntPtr GetProcAddress(SafeLibraryHandle hModule, string lpProcName);
#endif
#if !NETFRAMEWORK
#if NET
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Unicode, SetLastError = true)]
public static extern SafeLibraryHandle LoadLibraryExW([In] string lpwLibFileName, [In] IntPtr hFile, [In] uint dwFlags);
#endif
#if NETFRAMEWORK
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.Machine)]
internal static extern IntPtr MapViewOfFile(
IntPtr hFileMappingObject,
int dwDesiredAccess,
int dwFileOffsetHigh,
int dwFileOffsetLow,
IntPtr dwNumberOfBytesToMap);
#endif
#if NETFRAMEWORK
// OpenFileMappingA contains a security venerability, in the unicode->ansi conversion
// Its possible to spoof the directory and construct ../ sequences, See FxCop Warning
// Specify marshaling for pinvoke string arguments
[DllImport(DllName, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
[ResourceExposure(ResourceScope.Machine)]
internal static extern IntPtr OpenFileMappingA(
int dwDesiredAccess,
bool bInheritHandle,
[MarshalAs(UnmanagedType.LPStr)] string lpName);
#endif
[DllImport(DllName, SetLastError = true, ExactSpelling = true)]
internal static extern bool SetThreadErrorMode(uint dwNewMode, out uint lpOldMode);
#if NETFRAMEWORK
[DllImport(DllName, ExactSpelling = true, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.Machine)]
internal static extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
#endif
}
}

Просмотреть файл

@ -1,41 +1,43 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#if NETFRAMEWORK
using System;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Text;
using System.Threading;
namespace Microsoft.Data.Common
namespace Interop.Windows.Kernel32
{
[SuppressUnmanagedCodeSecurityAttribute()]
internal static class SafeNativeMethods
/// <remarks>
/// Be insanely careful when using methods from this class. They are configured to skip
/// runtime security checks.
/// </remarks>
[SuppressUnmanagedCodeSecurity]
internal static class Kernel32Safe
{
private const string Kernel32 = "kernel32.dll";
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getcomputernameex.asp
[DllImport(Kernel32, CharSet = CharSet.Unicode, EntryPoint = "GetComputerNameExW", SetLastError = true)]
[ResourceExposure(ResourceScope.None)]
static internal extern int GetComputerNameEx(int nameType, StringBuilder nameBuffer, ref int bufferSize);
internal static extern int GetComputerNameEx(int nameType, StringBuilder nameBuffer, ref int bufferSize);
[DllImport(Kernel32, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
[DllImport(Kernel32, CharSet = CharSet.Auto)]
[ResourceExposure(ResourceScope.Process)]
static internal extern int GetCurrentProcessId();
internal static extern int GetCurrentProcessId();
[DllImport(Kernel32, CharSet = CharSet.Auto, BestFitMapping = false, ThrowOnUnmappableChar = true)]
// [DllImport(ExternDll.Kernel32, CharSet=CharSet.Auto)]
[ResourceExposure(ResourceScope.Process)]
static internal extern IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPTStr), In] string moduleName/*lpctstr*/);
internal static extern IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPTStr), In] string moduleName);
[DllImport(Kernel32, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true, SetLastError = true)]
// [DllImport(ExternDll.Kernel32, CharSet=CharSet.Ansi)]
[ResourceExposure(ResourceScope.None)]
static internal extern IntPtr GetProcAddress(IntPtr HModule, [MarshalAs(UnmanagedType.LPStr), In] string funcName/*lpcstr*/);
internal static extern IntPtr GetProcAddress(IntPtr HModule, [MarshalAs(UnmanagedType.LPStr), In] string funcName);
}
}
#endif

Просмотреть файл

@ -25,11 +25,11 @@ using Microsoft.SqlServer.Server;
using System.Security.Authentication;
#if NETFRAMEWORK
using Microsoft.Win32;
using System.Reflection;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Interop.Windows.Kernel32;
#endif
namespace Microsoft.Data.Common
@ -1494,7 +1494,7 @@ namespace Microsoft.Data.Common
// query for the required length
// VSTFDEVDIV 479551 - ensure that GetComputerNameEx does not fail with unexpected values and that the length is positive
int getComputerNameExError = 0;
if (0 == SafeNativeMethods.GetComputerNameEx(ComputerNameDnsFullyQualified, null, ref length))
if (0 == Kernel32Safe.GetComputerNameEx(ComputerNameDnsFullyQualified, null, ref length))
{
getComputerNameExError = Marshal.GetLastWin32Error();
}
@ -1505,7 +1505,7 @@ namespace Microsoft.Data.Common
StringBuilder buffer = new(length);
length = buffer.Capacity;
if (0 == SafeNativeMethods.GetComputerNameEx(ComputerNameDnsFullyQualified, buffer, ref length))
if (0 == Kernel32Safe.GetComputerNameEx(ComputerNameDnsFullyQualified, buffer, ref length))
{
throw ADP.ComputerNameEx(Marshal.GetLastWin32Error());
}

Просмотреть файл

@ -2,6 +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 Interop.Windows.Kernel32;
#if NETFRAMEWORK
namespace Microsoft.Data.ProviderBase
@ -262,7 +264,7 @@ namespace Microsoft.Data.ProviderBase
}
// TODO: If you do not use GetCurrentProcessId after fixing VSDD 534795, please remove Resource* attributes from this method
int pid = SafeNativeMethods.GetCurrentProcessId();
int pid = Kernel32Safe.GetCurrentProcessId();
// SQLBUDT #366157 -there are several characters which have special meaning

Просмотреть файл

@ -7,19 +7,23 @@ using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Transactions;
using Microsoft.Data.Common;
#if NETFRAMEWORK
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Interop.Windows.Kernel32;
#else
using System.Net.Sockets;
#endif
namespace Microsoft.Data.SqlClient
{
/// <summary>