From 4bc9ee65ce173c5c502f63afdf148ab71e7a9799 Mon Sep 17 00:00:00 2001 From: Edward Neal <55035479+edwardneal@users.noreply.github.com> Date: Wed, 6 Nov 2024 03:03:14 +0000 Subject: [PATCH] Remove SQLDebugging class (#2940) --- .../Microsoft.Data.SqlClient/SQLDebugging.xml | 14 - src/Microsoft.Data.SqlClient.sln | 1 - .../netfx/ref/Microsoft.Data.SqlClient.cs | 10 - .../Microsoft/Data/SqlClient/SqlConnection.cs | 294 ------------------ 4 files changed, 319 deletions(-) delete mode 100644 doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml diff --git a/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml b/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml deleted file mode 100644 index d9f7a5f014..0000000000 --- a/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - Included to support debugging applications. Not intended for direct use. - - - - - Initiates instance of class object. Not intended for direct use. - - - - diff --git a/src/Microsoft.Data.SqlClient.sln b/src/Microsoft.Data.SqlClient.sln index ca18e751ee..78a38c76b0 100644 --- a/src/Microsoft.Data.SqlClient.sln +++ b/src/Microsoft.Data.SqlClient.sln @@ -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 diff --git a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs index 8e64378330..fe2f2a9bbe 100644 --- a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs @@ -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; } } - /// - [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 - { - /// - public SQLDebugging() { } - } /// public sealed partial class SqlDependency { diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs index 359d196f16..cfd4798afd 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs @@ -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 - // - /// - [ - 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