Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
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.
Expand Down Expand Up @@ -2532,7 +2534,7 @@ internal void OnInfoMessage(SqlInfoMessageEventArgs imevent, out bool notified)
private void CheckSQLDebugOnConnect()
{
IntPtr hFileMap;
uint pid = (uint)SafeNativeMethods.GetCurrentProcessId();
uint pid = (uint)Kernel32Safe.GetCurrentProcessId();

string mapFileName;

Expand All @@ -2548,11 +2550,11 @@ private void CheckSQLDebugOnConnect()

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();
Expand Down Expand Up @@ -3098,12 +3100,12 @@ private void Dispose(bool disposing)
}
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ internal static uint CtlCode(ushort deviceType, ushort function, byte method, by
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,
Expand All @@ -55,38 +76,69 @@ internal static extern bool DeviceIoControl(
out uint cbBytesReturned,
IntPtr overlapped);

#if !NETFRAMEWORK
#if NET
[DllImport(DllName, ExactSpelling = true, SetLastError = true)]
public static extern bool FreeLibrary([In] IntPtr hModule);
#endif

[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(
string path,
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
}
}
Loading
Loading