NativeMethods.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //------------------------------------------------------------------------------
  2. // <copyright file="NativeMethods.cs" company="Microsoft">
  3. // Copyright (c) Microsoft Corporation. All rights reserved.
  4. // </copyright>
  5. // <owner current="true" primary="true">markash</owner>
  6. // <owner current="true" primary="false">blained</owner>
  7. // <owner current="true" primary="false">mithomas</owner>
  8. //------------------------------------------------------------------------------
  9. using System;
  10. using System.Runtime.InteropServices;
  11. using System.Runtime.Versioning;
  12. namespace System.Data.Common {
  13. internal static class NativeMethods {
  14. #if !NO_OLEDB
  15. [Guid("0c733a1e-2a1c-11ce-ade5-00aa0044773d"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), ComImport]
  16. internal interface ISourcesRowset {
  17. [PreserveSig] System.Data.OleDb.OleDbHResult GetSourcesRowset(
  18. [In] IntPtr pUnkOuter,
  19. [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid,
  20. [In] int cPropertySets,
  21. [In] IntPtr rgProperties,
  22. [Out, MarshalAs(UnmanagedType.Interface)] out object ppRowset);
  23. }
  24. #endif
  25. [Guid("0C733A5E-2A1C-11CE-ADE5-00AA0044773D"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown), ComImport]
  26. internal interface ITransactionJoin {
  27. [ Obsolete("not used", true)] [PreserveSig] int GetOptionsObject(
  28. /*deleted parameter signature*/);
  29. void JoinTransaction(
  30. [In, MarshalAs(UnmanagedType.Interface)] object punkTransactionCoord,
  31. [In] Int32 isoLevel,
  32. [In] Int32 isoFlags,
  33. [In] IntPtr pOtherOptions);
  34. }
  35. [DllImport(ExternDll.Kernel32, ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Auto)]
  36. [ResourceExposure(ResourceScope.Machine)]
  37. static internal extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, int dwDesiredAccess, int dwFileOffsetHigh, int dwFileOffsetLow, IntPtr dwNumberOfBytesToMap);
  38. // OpenFileMappingA contains a security venerability, in the unicode->ansi conversion
  39. // Its possible to spoof the directory and construct ../ sequeences, See FxCop Warrning
  40. // Specify marshaling for pinvoke string arguments
  41. [DllImport(ExternDll.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Ansi, BestFitMapping=false, ThrowOnUnmappableChar=true)]
  42. // [DllImport(ExternDll.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Ansi)]
  43. [ResourceExposure(ResourceScope.Machine)]
  44. static internal extern IntPtr OpenFileMappingA(int dwDesiredAccess, bool bInheritHandle, [MarshalAs(UnmanagedType.LPStr)] string lpName);
  45. // CreateFileMappingA contains a security venerability, in the unicode->ansi conversion
  46. // Its possible to spoof the directory and construct ../ sequeences, See FxCop Warrning
  47. // Specify marshaling for pinvoke string arguments
  48. [DllImport(ExternDll.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Ansi, BestFitMapping=false, ThrowOnUnmappableChar=true)]
  49. // [DllImport(ExternDll.Kernel32, CharSet=System.Runtime.InteropServices.CharSet.Ansi)]
  50. [ResourceExposure(ResourceScope.Machine)]
  51. static internal extern IntPtr CreateFileMappingA(IntPtr hFile, IntPtr pAttr, int flProtect, int dwMaximumSizeHigh, int dwMaximumSizeLow, [MarshalAs(UnmanagedType.LPStr)] string lpName);
  52. [DllImport(ExternDll.Kernel32, ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Auto)]
  53. [ResourceExposure(ResourceScope.Machine)]
  54. static internal extern bool UnmapViewOfFile(IntPtr lpBaseAddress);
  55. [DllImport(ExternDll.Kernel32, ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)]
  56. [ResourceExposure(ResourceScope.Machine)]
  57. static internal extern bool CloseHandle(IntPtr handle);
  58. [DllImport(ExternDll.Advapi32, ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)]
  59. [ResourceExposure(ResourceScope.None)]
  60. static internal extern bool AllocateAndInitializeSid(
  61. IntPtr pIdentifierAuthority, // authority
  62. byte nSubAuthorityCount, // count of subauthorities
  63. int dwSubAuthority0, // subauthority 0
  64. int dwSubAuthority1, // subauthority 1
  65. int dwSubAuthority2, // subauthority 2
  66. int dwSubAuthority3, // subauthority 3
  67. int dwSubAuthority4, // subauthority 4
  68. int dwSubAuthority5, // subauthority 5
  69. int dwSubAuthority6, // subauthority 6
  70. int dwSubAuthority7, // subauthority 7
  71. ref IntPtr pSid ); // SID
  72. [DllImport(ExternDll.Advapi32, ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)]
  73. [ResourceExposure(ResourceScope.None)]
  74. static internal extern int GetLengthSid(
  75. IntPtr pSid); // SID to query
  76. [DllImport(ExternDll.Advapi32, ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)]
  77. [ResourceExposure(ResourceScope.None)]
  78. static internal extern bool InitializeAcl(
  79. IntPtr pAcl, // ACL
  80. int nAclLength, // size of ACL
  81. int dwAclRevision ); // revision level of ACL
  82. [DllImport(ExternDll.Advapi32, ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)]
  83. [ResourceExposure(ResourceScope.None)]
  84. static internal extern bool AddAccessDeniedAce(
  85. IntPtr pAcl, // access control list
  86. int dwAceRevision, // ACL revision level
  87. int AccessMask, // access mask
  88. IntPtr pSid ); // security identifier
  89. [DllImport(ExternDll.Advapi32, ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)]
  90. [ResourceExposure(ResourceScope.None)]
  91. static internal extern bool AddAccessAllowedAce(
  92. IntPtr pAcl, // access control list
  93. int dwAceRevision, // ACL revision level
  94. uint AccessMask, // access mask
  95. IntPtr pSid ); // security identifier
  96. [DllImport(ExternDll.Advapi32, ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)]
  97. [ResourceExposure(ResourceScope.None)]
  98. static internal extern bool InitializeSecurityDescriptor(
  99. IntPtr pSecurityDescriptor, // SD
  100. int dwRevision ); // revision level
  101. [DllImport(ExternDll.Advapi32, ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)]
  102. [ResourceExposure(ResourceScope.None)]
  103. static internal extern bool SetSecurityDescriptorDacl(
  104. IntPtr pSecurityDescriptor, // SD
  105. bool bDaclPresent, // DACL presence
  106. IntPtr pDacl, // DACL
  107. bool bDaclDefaulted); // default DACL
  108. [DllImport(ExternDll.Advapi32, ExactSpelling=true, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true)]
  109. [ResourceExposure(ResourceScope.None)]
  110. static internal extern IntPtr FreeSid(
  111. IntPtr pSid); // SID to free
  112. }
  113. }