Skip to content

Commit

Permalink
Remove SQLDebugging class (#2940)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardneal authored Nov 6, 2024
1 parent ca1a943 commit 4bc9ee6
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 319 deletions.
14 changes: 0 additions & 14 deletions doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml

This file was deleted.

1 change: 0 additions & 1 deletion src/Microsoft.Data.SqlClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Microsoft.Data.SqlClient",
..\doc\snippets\Microsoft.Data.SqlClient\SqlCredential.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlCredential.xml
..\doc\snippets\Microsoft.Data.SqlClient\SqlDataAdapter.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlDataAdapter.xml
..\doc\snippets\Microsoft.Data.SqlClient\SqlDataReader.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlDataReader.xml
..\doc\snippets\Microsoft.Data.SqlClient\SQLDebugging.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SQLDebugging.xml
..\doc\snippets\Microsoft.Data.SqlClient\SqlDependency.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlDependency.xml
..\doc\snippets\Microsoft.Data.SqlClient\SqlEnclaveAttestationParameters.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlEnclaveAttestationParameters.xml
..\doc\snippets\Microsoft.Data.SqlClient\SqlEnclaveSession.xml = ..\doc\snippets\Microsoft.Data.SqlClient\SqlEnclaveSession.xml
Expand Down
10 changes: 0 additions & 10 deletions src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,16 +1401,6 @@ public override void Close() { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
System.Data.IDataReader System.Data.IDataRecord.GetData(int i) { throw null; }
}
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml' path='docs/members[@name="SQLDebugging"]/SQLDebugging/*'/>
[System.Runtime.InteropServices.ClassInterfaceAttribute(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
[System.Runtime.InteropServices.GuidAttribute("afef65ad-4577-447a-a148-83acadd3d4b9")]
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name = "FullTrust")]
public sealed partial class SQLDebugging
{
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml' path='docs/members[@name="SQLDebugging"]/ctor/*'/>
public SQLDebugging() { }
}
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDependency.xml' path='docs/members[@name="SqlDependency"]/SqlDependency/*'/>
public sealed partial class SqlDependency
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3065,300 +3065,6 @@ internal byte[] GetBytes(object o, out Format format, out int maxSize)
}
} // SqlConnection

// TODO: This really belongs in it's own source file...
//
// This is a private interface for the SQL Debugger
// You must not change the guid for this coclass
// or the iid for the ISQLDebug interface
//
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDebugging.xml' path='docs/members[@name="SQLDebugging"]/SQLDebugging/*'/>
[
ComVisible(true),
ClassInterface(ClassInterfaceType.None),
Guid("afef65ad-4577-447a-a148-83acadd3d4b9"),
]
[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name = "FullTrust")]
public sealed class SQLDebugging : ISQLDebug
{

// Security stuff
const int STANDARD_RIGHTS_REQUIRED = (0x000F0000);
const int DELETE = (0x00010000);
const int READ_CONTROL = (0x00020000);
const int WRITE_DAC = (0x00040000);
const int WRITE_OWNER = (0x00080000);
const int SYNCHRONIZE = (0x00100000);
const int FILE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x000001FF);
const uint GENERIC_READ = (0x80000000);
const uint GENERIC_WRITE = (0x40000000);
const uint GENERIC_EXECUTE = (0x20000000);
const uint GENERIC_ALL = (0x10000000);

const int SECURITY_DESCRIPTOR_REVISION = (1);
const int ACL_REVISION = (2);

const int SECURITY_AUTHENTICATED_USER_RID = (0x0000000B);
const int SECURITY_LOCAL_SYSTEM_RID = (0x00000012);
const int SECURITY_BUILTIN_DOMAIN_RID = (0x00000020);
const int SECURITY_WORLD_RID = (0x00000000);
const byte SECURITY_NT_AUTHORITY = 5;
const int DOMAIN_GROUP_RID_ADMINS = (0x00000200);
const int DOMAIN_ALIAS_RID_ADMINS = (0x00000220);

const int sizeofSECURITY_ATTRIBUTES = 12; // sizeof(SECURITY_ATTRIBUTES);
const int sizeofSECURITY_DESCRIPTOR = 20; // sizeof(SECURITY_DESCRIPTOR);
const int sizeofACCESS_ALLOWED_ACE = 12; // sizeof(ACCESS_ALLOWED_ACE);
const int sizeofACCESS_DENIED_ACE = 12; // sizeof(ACCESS_DENIED_ACE);
const int sizeofSID_IDENTIFIER_AUTHORITY = 6; // sizeof(SID_IDENTIFIER_AUTHORITY)
const int sizeofACL = 8; // sizeof(ACL);

private IntPtr CreateSD(ref IntPtr pDacl)
{
IntPtr pSecurityDescriptor = IntPtr.Zero;
IntPtr pUserSid = IntPtr.Zero;
IntPtr pAdminSid = IntPtr.Zero;
IntPtr pNtAuthority = IntPtr.Zero;
int cbAcl = 0;
bool status = false;

pNtAuthority = Marshal.AllocHGlobal(sizeofSID_IDENTIFIER_AUTHORITY);
if (pNtAuthority == IntPtr.Zero)
goto cleanup;
Marshal.WriteInt32(pNtAuthority, 0, 0);
Marshal.WriteByte(pNtAuthority, 4, 0);
Marshal.WriteByte(pNtAuthority, 5, SECURITY_NT_AUTHORITY);

status =
NativeMethods.AllocateAndInitializeSid(
pNtAuthority,
(byte)1,
SECURITY_AUTHENTICATED_USER_RID,
0,
0,
0,
0,
0,
0,
0,
ref pUserSid);

if (!status || pUserSid == IntPtr.Zero)
{
goto cleanup;
}
status =
NativeMethods.AllocateAndInitializeSid(
pNtAuthority,
(byte)2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0,
0,
0,
0,
0,
0,
ref pAdminSid);

if (!status || pAdminSid == IntPtr.Zero)
{
goto cleanup;
}
status = false;
pSecurityDescriptor = Marshal.AllocHGlobal(sizeofSECURITY_DESCRIPTOR);
if (pSecurityDescriptor == IntPtr.Zero)
{
goto cleanup;
}
for (int i = 0; i < sizeofSECURITY_DESCRIPTOR; i++)
Marshal.WriteByte(pSecurityDescriptor, i, (byte)0);
cbAcl = sizeofACL
+ (2 * (sizeofACCESS_ALLOWED_ACE))
+ sizeofACCESS_DENIED_ACE
+ NativeMethods.GetLengthSid(pUserSid)
+ NativeMethods.GetLengthSid(pAdminSid);

pDacl = Marshal.AllocHGlobal(cbAcl);
if (pDacl == IntPtr.Zero)
{
goto cleanup;
}
// rights must be added in a certain order. Namely, deny access first, then add access
if (NativeMethods.InitializeAcl(pDacl, cbAcl, ACL_REVISION))
if (NativeMethods.AddAccessDeniedAce(pDacl, ACL_REVISION, WRITE_DAC, pUserSid))
if (NativeMethods.AddAccessAllowedAce(pDacl, ACL_REVISION, GENERIC_READ, pUserSid))
if (NativeMethods.AddAccessAllowedAce(pDacl, ACL_REVISION, GENERIC_ALL, pAdminSid))
if (NativeMethods.InitializeSecurityDescriptor(pSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION))
if (NativeMethods.SetSecurityDescriptorDacl(pSecurityDescriptor, true, pDacl, false))
{
status = true;
}

cleanup:
if (pNtAuthority != IntPtr.Zero)
{
Marshal.FreeHGlobal(pNtAuthority);
}
if (pAdminSid != IntPtr.Zero)
NativeMethods.FreeSid(pAdminSid);
if (pUserSid != IntPtr.Zero)
NativeMethods.FreeSid(pUserSid);
if (status)
return pSecurityDescriptor;
else
{
if (pSecurityDescriptor != IntPtr.Zero)
{
Marshal.FreeHGlobal(pSecurityDescriptor);
}
}
return IntPtr.Zero;
}

// SxS: using file mapping API (CreateFileMapping)
// TODO: review this code for SxS issues (VSDD 540765)
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
bool ISQLDebug.SQLDebug(int dwpidDebugger, int dwpidDebuggee, [MarshalAs(UnmanagedType.LPStr)] string pszMachineName,
[MarshalAs(UnmanagedType.LPStr)] string pszSDIDLLName, int dwOption, int cbData, byte[] rgbData)
{
bool result = false;
IntPtr hFileMap = IntPtr.Zero;
IntPtr pMemMap = IntPtr.Zero;
IntPtr pSecurityDescriptor = IntPtr.Zero;
IntPtr pSecurityAttributes = IntPtr.Zero;
IntPtr pDacl = IntPtr.Zero;

// validate the structure
if (pszMachineName == null || pszSDIDLLName == null)
{
return false;
}

if (pszMachineName.Length > TdsEnums.SDCI_MAX_MACHINENAME ||
pszSDIDLLName.Length > TdsEnums.SDCI_MAX_DLLNAME)
{
return false;
}

// note that these are ansi strings
Encoding cp = System.Text.Encoding.GetEncoding(TdsEnums.DEFAULT_ENGLISH_CODE_PAGE_VALUE);
byte[] rgbMachineName = cp.GetBytes(pszMachineName);
byte[] rgbSDIDLLName = cp.GetBytes(pszSDIDLLName);

if (rgbData != null && cbData > TdsEnums.SDCI_MAX_DATA)
{
return false;
}

string mapFileName;

// If Win2k or later, prepend "Global\\" to enable this to work through TerminalServices.
if (ADP.s_isPlatformNT5)
{
mapFileName = "Global\\" + TdsEnums.SDCI_MAPFILENAME;
}
else
{
mapFileName = TdsEnums.SDCI_MAPFILENAME;
}

mapFileName = mapFileName + dwpidDebuggee.ToString(CultureInfo.InvariantCulture);

// Create Security Descriptor
pSecurityDescriptor = CreateSD(ref pDacl);
pSecurityAttributes = Marshal.AllocHGlobal(sizeofSECURITY_ATTRIBUTES);
if ((pSecurityDescriptor == IntPtr.Zero) || (pSecurityAttributes == IntPtr.Zero))
return false;

Marshal.WriteInt32(pSecurityAttributes, 0, sizeofSECURITY_ATTRIBUTES); // nLength = sizeof(SECURITY_ATTRIBUTES)
Marshal.WriteIntPtr(pSecurityAttributes, 4, pSecurityDescriptor); // lpSecurityDescriptor = pSecurityDescriptor
Marshal.WriteInt32(pSecurityAttributes, 8, 0); // bInheritHandle = FALSE
hFileMap = NativeMethods.CreateFileMappingA(
ADP.s_invalidPtr/*INVALID_HANDLE_VALUE*/,
pSecurityAttributes,
0x4/*PAGE_READWRITE*/,
0,
Marshal.SizeOf(typeof(MEMMAP)),
mapFileName);

if (IntPtr.Zero == hFileMap)
{
goto cleanup;
}


pMemMap = NativeMethods.MapViewOfFile(hFileMap, 0x6/*FILE_MAP_READ|FILE_MAP_WRITE*/, 0, 0, IntPtr.Zero);

if (IntPtr.Zero == pMemMap)
{
goto cleanup;
}

// copy data to memory-mapped file
// layout of MEMMAP structure is:
// uint dbgpid
// uint fOption
// byte[32] machineName
// byte[16] sdiDllName
// uint dbData
// byte[255] vData
int offset = 0;
Marshal.WriteInt32(pMemMap, offset, (int)dwpidDebugger);
offset += 4;
Marshal.WriteInt32(pMemMap, offset, (int)dwOption);
offset += 4;
Marshal.Copy(rgbMachineName, 0, ADP.IntPtrOffset(pMemMap, offset), rgbMachineName.Length);
offset += TdsEnums.SDCI_MAX_MACHINENAME;
Marshal.Copy(rgbSDIDLLName, 0, ADP.IntPtrOffset(pMemMap, offset), rgbSDIDLLName.Length);
offset += TdsEnums.SDCI_MAX_DLLNAME;
Marshal.WriteInt32(pMemMap, offset, (int)cbData);
offset += 4;
if (rgbData != null)
{
Marshal.Copy(rgbData, 0, ADP.IntPtrOffset(pMemMap, offset), (int)cbData);
}
NativeMethods.UnmapViewOfFile(pMemMap);
result = true;
cleanup:
if (result == false)
{
if (hFileMap != IntPtr.Zero)
NativeMethods.CloseHandle(hFileMap);
}
if (pSecurityAttributes != IntPtr.Zero)
Marshal.FreeHGlobal(pSecurityAttributes);
if (pSecurityDescriptor != IntPtr.Zero)
Marshal.FreeHGlobal(pSecurityDescriptor);
if (pDacl != IntPtr.Zero)
Marshal.FreeHGlobal(pDacl);
return result;
}
}

// this is a private interface to com+ users
// do not change this guid
[
ComImport,
ComVisible(true),
Guid("6cb925bf-c3c0-45b3-9f44-5dd67c7b7fe8"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
BestFitMapping(false, ThrowOnUnmappableChar = true),
]
interface ISQLDebug
{

[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Name = "FullTrust")]
bool SQLDebug(
int dwpidDebugger,
int dwpidDebuggee,
[MarshalAs(UnmanagedType.LPStr)] string pszMachineName,
[MarshalAs(UnmanagedType.LPStr)] string pszSDIDLLName,
int dwOption,
int cbData,
byte[] rgbData);
}

sealed class SqlDebugContext : IDisposable
{
// context data
Expand Down

0 comments on commit 4bc9ee6

Please sign in to comment.