<CDefines Condition="'$(FeatureLazyCOWPages)' == 'true'">$(CDefines);FEATURE_LAZY_COW_PAGES</CDefines>
<CDefines Condition="'$(FeatureLeakCultureInfo)' == 'true'">$(CDefines);FEATURE_LEAK_CULTURE_INFO</CDefines>
<CDefines Condition="'$(FeatureLegacyNetCFDbgHostControl)' == 'true'">$(CDefines);FEATURE_LEGACYNETCF_DBG_HOST_CONTROL</CDefines>
- <CDefines Condition="'$(FeatureLegacySurface)' == 'true'">$(CDefines);FEATURE_LEGACYSURFACE</CDefines>
<CDefines Condition="'$(FeatureLoaderOptimization)' == 'true'">$(CDefines);FEATURE_LOADER_OPTIMIZATION</CDefines>
<CDefines Condition="'$(FeatureMacl)' == 'true'">$(CDefines);FEATURE_MACL</CDefines>
<CDefines Condition="'$(FeatureManagedEtw)' == 'true'">$(CDefines);FEATURE_MANAGED_ETW</CDefines>
<DefineConstants Condition="'$(FeatureIsostore)' == 'true'">$(DefineConstants);FEATURE_ISOSTORE</DefineConstants>
<DefineConstants Condition="'$(FeatureIsostoreLight)' == 'true'">$(DefineConstants);FEATURE_ISOSTORE_LIGHT</DefineConstants>
<DefineConstants Condition="'$(FeatureLeakCultureInfo)' == 'true'">$(DefineConstants);FEATURE_LEAK_CULTURE_INFO</DefineConstants>
- <DefineConstants Condition="'$(FeatureLegacySurface)' == 'true'">$(DefineConstants);FEATURE_LEGACYSURFACE</DefineConstants>
<DefineConstants Condition="'$(FeatureLoaderOptimization)' == 'true'">$(DefineConstants);FEATURE_LOADER_OPTIMIZATION</DefineConstants>
<DefineConstants Condition="'$(FeatureMacl)' == 'true'">$(DefineConstants);FEATURE_MACL</DefineConstants>
<DefineConstants Condition="'$(FeatureManagedEtw)' == 'true'">$(DefineConstants);FEATURE_MANAGED_ETW</DefineConstants>
<Member Name="#ctor(System.String,System.Exception)" />
<Member Name="#ctor(System.Runtime.Serialization.SerializationInfo,System.Runtime.Serialization.StreamingContext)" />
</Type>
- <Type Name="System.IO.SearchOption" Condition="FEATURE_LEGACYSURFACE">
- <Member MemberType="Field" Name="TopDirectoryOnly" />
- <Member MemberType="Field" Name="AllDirectories" />
- <Member MemberType="Field" Name="value__" />
- </Type>
- <Type Name="System.IO.SeekOrigin" Condition="FEATURE_LEGACYSURFACE">
- <Member MemberType="Field" Name="Begin" />
- <Member MemberType="Field" Name="Current" />
- <Member MemberType="Field" Name="End" />
- <Member MemberType="Field" Name="value__" />
- </Type>
<Type Name="System.IO.Stream">
<Member MemberType="Field" Name="Null" />
<Member Name="#ctor" />
</Type>
<Type Status="ImplRoot" Name="System.Security.DynamicSecurityMethodAttribute" />
<Type Status="ImplRoot" Name="System.Security.FrameSecurityDescriptor">
- <Member MemberType="Field" Name="m_callerToken" Condition="not FEATURE_PAL" />
<Member MemberType="Field" Name="m_DeclarativeDenials" />
<Member MemberType="Field" Name="m_DeclarativeRestrictions" />
<Member MemberType="Field" Name="m_denials" />
- <Member MemberType="Field" Name="m_impToken" Condition="not FEATURE_PAL" />
<Member MemberType="Field" Name="m_restriction" />
</Type>
<Type Status="ImplRoot" Name="System.Security.PermissionListSet">
<SecuritySources Include="$(BclSourcesRoot)\System\Security\PermissionToken.cs" />
<SecuritySources Include="$(BclSourcesRoot)\System\Security\PermissionSetTriple.cs" />
<SecuritySources Include="$(BclSourcesRoot)\System\Security\PermissionListSet.cs" />
- <SecuritySources Include="$(BclSourcesRoot)\System\Security\SafeSecurityHandles.cs" />
<SecuritySources Include="$(BclSourcesRoot)\System\Security\SecurityContext.cs" />
<SecuritySources Include="$(BclSourcesRoot)\System\Security\SecurityException.cs" />
<SecuritySources Include="$(BclSourcesRoot)\System\Security\SecurityState.cs" />
<SecuritySources Include="$(BclSourcesRoot)\System\Security\SecurityRuntime.cs" />
<SecuritySources Include="$(BclSourcesRoot)\System\Security\SecurityZone.cs" />
<SecuritySources Include="$(BclSourcesRoot)\System\Security\VerificationException.cs" />
- <SecuritySources Condition="'$(FeatureLegacySurface)' == 'true'" Include="$(BclSourcesRoot)\System\Security\securestring.cs" />
</ItemGroup>
<ItemGroup>
internal const int HWND_BROADCAST = 0xffff;
internal const int WM_SETTINGCHANGE = 0x001A;
- // CryptProtectMemory and CryptUnprotectMemory.
- internal const uint CRYPTPROTECTMEMORY_BLOCK_SIZE = 16;
- internal const uint CRYPTPROTECTMEMORY_SAME_PROCESS = 0x00;
- internal const uint CRYPTPROTECTMEMORY_CROSS_PROCESS = 0x01;
- internal const uint CRYPTPROTECTMEMORY_SAME_LOGON = 0x02;
-
- // Security Quality of Service flags
- internal const int SECURITY_ANONYMOUS = ((int)SECURITY_IMPERSONATION_LEVEL.Anonymous << 16);
- internal const int SECURITY_SQOS_PRESENT = 0x00100000;
-
- // Access Control library.
- internal const string MICROSOFT_KERBEROS_NAME = "Kerberos";
- internal const uint ANONYMOUS_LOGON_LUID = 0x3e6;
-
- internal const int SECURITY_ANONYMOUS_LOGON_RID = 0x00000007;
- internal const int SECURITY_AUTHENTICATED_USER_RID = 0x0000000B;
- internal const int SECURITY_LOCAL_SYSTEM_RID = 0x00000012;
- internal const int SECURITY_BUILTIN_DOMAIN_RID = 0x00000020;
-
- internal const uint SE_PRIVILEGE_DISABLED = 0x00000000;
- internal const uint SE_PRIVILEGE_ENABLED_BY_DEFAULT = 0x00000001;
- internal const uint SE_PRIVILEGE_ENABLED = 0x00000002;
- internal const uint SE_PRIVILEGE_USED_FOR_ACCESS = 0x80000000;
-
- internal const uint SE_GROUP_MANDATORY = 0x00000001;
- internal const uint SE_GROUP_ENABLED_BY_DEFAULT = 0x00000002;
- internal const uint SE_GROUP_ENABLED = 0x00000004;
- internal const uint SE_GROUP_OWNER = 0x00000008;
- internal const uint SE_GROUP_USE_FOR_DENY_ONLY = 0x00000010;
- internal const uint SE_GROUP_LOGON_ID = 0xC0000000;
- internal const uint SE_GROUP_RESOURCE = 0x20000000;
-
- internal const uint DUPLICATE_CLOSE_SOURCE = 0x00000001;
- internal const uint DUPLICATE_SAME_ACCESS = 0x00000002;
- internal const uint DUPLICATE_SAME_ATTRIBUTES = 0x00000004;
-
// TimeZone
internal const int TIME_ZONE_ID_INVALID = -1;
internal const int TIME_ZONE_ID_UNKNOWN = 0;
[DllImport(Win32Native.OLEAUT32)]
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
internal static extern uint SysStringByteLen(IntPtr bstr);
-
-#if FEATURE_LEGACYSURFACE
- [DllImport(Win32Native.OLEAUT32)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern uint SysStringLen(SafeBSTRHandle bstr);
-#endif
-
#endif
[DllImport(KERNEL32)]
[DllImport(OLE32)]
internal static extern IntPtr CoTaskMemRealloc(IntPtr pv, UIntPtr cb);
- [StructLayoutAttribute(LayoutKind.Sequential)]
- internal struct COORD
- {
- internal short X;
- internal short Y;
- }
-
- [StructLayoutAttribute(LayoutKind.Sequential)]
- internal struct SMALL_RECT
- {
- internal short Left;
- internal short Top;
- internal short Right;
- internal short Bottom;
- }
-
- [StructLayoutAttribute(LayoutKind.Sequential)]
- internal struct CONSOLE_SCREEN_BUFFER_INFO
- {
- internal COORD dwSize;
- internal COORD dwCursorPosition;
- internal short wAttributes;
- internal SMALL_RECT srWindow;
- internal COORD dwMaximumWindowSize;
- }
-
- [StructLayoutAttribute(LayoutKind.Sequential)]
- internal struct CONSOLE_CURSOR_INFO
- {
- internal int dwSize;
- internal bool bVisible;
- }
-
- // Win32's KEY_EVENT_RECORD
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
- internal struct KeyEventRecord
- {
- internal bool keyDown;
- internal short repeatCount;
- internal short virtualKeyCode;
- internal short virtualScanCode;
- internal char uChar; // Union between WCHAR and ASCII char
- internal int controlKeyState;
- }
-
- // Really, this is a union of KeyEventRecords and other types.
- [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
- internal struct InputRecord
- {
- internal short eventType;
- internal KeyEventRecord keyEvent;
- // This struct is a union! Word alighment should take care of padding!
- }
-
-[Serializable]
- [Flags]
- internal enum Color : short
- {
- Black = 0,
- ForegroundBlue = 0x1,
- ForegroundGreen = 0x2,
- ForegroundRed = 0x4,
- ForegroundYellow = 0x6,
- ForegroundIntensity = 0x8,
- BackgroundBlue = 0x10,
- BackgroundGreen = 0x20,
- BackgroundRed = 0x40,
- BackgroundYellow = 0x60,
- BackgroundIntensity = 0x80,
-
- ForegroundMask = 0xf,
- BackgroundMask = 0xf0,
- ColorMask = 0xff
- }
-
- [StructLayout(LayoutKind.Sequential)]
- internal struct CHAR_INFO
- {
- ushort charData; // Union between WCHAR and ASCII char
- short attributes;
- }
-
- internal const int ENABLE_PROCESSED_INPUT = 0x0001;
- internal const int ENABLE_LINE_INPUT = 0x0002;
- internal const int ENABLE_ECHO_INPUT = 0x0004;
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, int mode);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out int mode);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool Beep(int frequency, int duration);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool GetConsoleScreenBufferInfo(IntPtr hConsoleOutput,
- out CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleScreenBufferSize(IntPtr hConsoleOutput, COORD size);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern COORD GetLargestConsoleWindowSize(IntPtr hConsoleOutput);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern bool FillConsoleOutputCharacter(IntPtr hConsoleOutput,
- char character, int nLength, COORD dwWriteCoord, out int pNumCharsWritten);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool FillConsoleOutputAttribute(IntPtr hConsoleOutput,
- short wColorAttribute, int numCells, COORD startCoord, out int pNumBytesWritten);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static unsafe extern bool SetConsoleWindowInfo(IntPtr hConsoleOutput,
- bool absolute, SMALL_RECT* consoleWindow);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput, short attributes);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleCursorPosition(IntPtr hConsoleOutput,
- COORD cursorPosition);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool GetConsoleCursorInfo(IntPtr hConsoleOutput,
- out CONSOLE_CURSOR_INFO cci);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleCursorInfo(IntPtr hConsoleOutput,
- ref CONSOLE_CURSOR_INFO cci);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=true)]
- internal static extern bool SetConsoleTitle(String title);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern bool ReadConsoleInput(IntPtr hConsoleInput, out InputRecord buffer, int numInputRecords_UseOne, out int numEventsRead);
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern bool PeekConsoleInput(IntPtr hConsoleInput, out InputRecord buffer, int numInputRecords_UseOne, out int numEventsRead);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static unsafe extern bool ReadConsoleOutput(IntPtr hConsoleOutput, CHAR_INFO* pBuffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT readRegion);
-
- [DllImport(KERNEL32, CharSet=CharSet.Unicode, SetLastError=true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static unsafe extern bool ReadConsoleW(SafeFileHandle hConsoleInput, Byte* lpBuffer, Int32 nNumberOfCharsToRead, out Int32 lpNumberOfCharsRead, IntPtr pInputControl);
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static unsafe extern bool WriteConsoleOutput(IntPtr hConsoleOutput, CHAR_INFO* buffer, COORD bufferSize, COORD bufferCoord, ref SMALL_RECT writeRegion);
-
- [DllImport(KERNEL32, CharSet=CharSet.Unicode, SetLastError=true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static unsafe extern bool WriteConsoleW(SafeFileHandle hConsoleOutput, Byte* lpBuffer, Int32 nNumberOfCharsToWrite, out Int32 lpNumberOfCharsWritten, IntPtr lpReservedMustBeNull);
-
- [DllImport(USER32)] // Appears to always succeed
- internal static extern short GetKeyState(int virtualKeyCode);
-
- [DllImport(KERNEL32, SetLastError=false)]
- internal static extern uint GetConsoleCP();
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleCP(uint codePage);
-
- [DllImport(KERNEL32, SetLastError=false)]
- internal static extern uint GetConsoleOutputCP();
-
- [DllImport(KERNEL32, SetLastError=true)]
- internal static extern bool SetConsoleOutputCP(uint codePage);
-
#if FEATURE_WIN32_REGISTRY
[DllImport(ADVAPI32, CharSet=CharSet.Auto, BestFitMapping=false)]
internal static extern int RegConnectRegistry(String machineName,
internal static extern bool LookupAccountName(string machineName, string accountName, byte[] sid,
ref int sidLen, [Out]StringBuilder domainName, ref uint domainNameLen, out int peUse);
- // Note: This returns a handle, but it shouldn't be closed. The Avalon
- // team says CloseWindowStation would ignore this handle. So there
- // isn't a lot of value to switching to SafeHandle here.
- [DllImport(USER32, ExactSpelling=true)]
- internal static extern IntPtr GetProcessWindowStation();
-
- [DllImport(USER32, SetLastError=true)]
- internal static extern bool GetUserObjectInformation(IntPtr hObj, int nIndex,
- [MarshalAs(UnmanagedType.LPStruct)] USEROBJECTFLAGS pvBuffer, int nLength, ref int lpnLengthNeeded);
-
[DllImport(USER32, SetLastError=true, BestFitMapping=false)]
internal static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, String lParam, uint fuFlags, uint uTimeout, IntPtr lpdwResult);
- [StructLayout(LayoutKind.Sequential)]
- internal class USEROBJECTFLAGS {
- internal int fInherit = 0;
- internal int fReserved = 0;
- internal int dwFlags = 0;
- }
-
- //
- // DPAPI
- //
-
-#if FEATURE_LEGACYSURFACE
- //
- // RtlEncryptMemory and RtlDecryptMemory are declared in the internal header file crypt.h.
- // They were also recently declared in the public header file ntsecapi.h (in the Platform SDK as well as the current build of Server 2003).
- // We use them instead of CryptProtectMemory and CryptUnprotectMemory because
- // they are available in both WinXP and in Windows Server 2003.
- //
-
- [DllImport(Win32Native.ADVAPI32, CharSet=CharSet.Unicode, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern
- int SystemFunction040 (
- [In,Out] SafeBSTRHandle pDataIn,
- [In] uint cbDataIn, // multiple of RTL_ENCRYPT_MEMORY_SIZE
- [In] uint dwFlags);
-
- [DllImport(Win32Native.ADVAPI32, CharSet=CharSet.Unicode, SetLastError=true)]
- internal static extern
- int SystemFunction041 (
- [In,Out] SafeBSTRHandle pDataIn,
- [In] uint cbDataIn, // multiple of RTL_ENCRYPT_MEMORY_SIZE
- [In] uint dwFlags);
-#endif // FEATURE_LEGACYSURFACE
-
- [DllImport(NTDLL, CharSet=CharSet.Unicode, SetLastError=true)]
- internal static extern
- int RtlNtStatusToDosError (
- [In] int status);
-
- // Get the current FIPS policy setting on Vista and above
- [DllImport("bcrypt.dll")]
- internal static extern uint BCryptGetFipsAlgorithmMode(
- [MarshalAs(UnmanagedType.U1), Out]out bool pfEnabled);
-
- //
- // Managed ACLs
- //
-
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- [DllImport(ADVAPI32, CharSet=CharSet.Unicode, SetLastError=true)]
- internal static extern
- bool AdjustTokenPrivileges (
- [In] SafeAccessTokenHandle TokenHandle,
- [In] bool DisableAllPrivileges,
- [In] ref TOKEN_PRIVILEGE NewState,
- [In] uint BufferLength,
- [In,Out] ref TOKEN_PRIVILEGE PreviousState,
- [In,Out] ref uint ReturnLength);
-
- [DllImport(ADVAPI32, CharSet=CharSet.Unicode, SetLastError=true)]
- internal static extern
- bool AllocateLocallyUniqueId(
- [In,Out] ref LUID Luid);
-
- [DllImport(ADVAPI32, CharSet=CharSet.Unicode, SetLastError=true)]
- internal static extern
- bool CheckTokenMembership(
- [In] SafeAccessTokenHandle TokenHandle,
- [In] byte[] SidToCheck,
- [In,Out] ref bool IsMember);
-
- [DllImport(
- ADVAPI32,
- EntryPoint="ConvertSecurityDescriptorToStringSecurityDescriptorW",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL ConvertSdToStringSd(
- byte[] securityDescriptor,
- /* DWORD */ uint requestedRevision,
- ULONG securityInformation,
- out IntPtr resultString,
- ref ULONG resultStringLength );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="ConvertStringSecurityDescriptorToSecurityDescriptorW",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL ConvertStringSdToSd(
- string stringSd,
- /* DWORD */ uint stringSdRevision,
- out IntPtr resultSd,
- ref ULONG resultSdLength );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="ConvertStringSidToSidW",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL ConvertStringSidToSid(
- string stringSid,
- out IntPtr ByteArray
- );
-
- [DllImport(
- ADVAPI32,
- EntryPoint = "ConvertSidToStringSidW",
- CallingConvention = CallingConvention.Winapi,
- SetLastError = true,
- ExactSpelling = true,
- CharSet = CharSet.Unicode)]
- [return: MarshalAs(UnmanagedType.Bool)]
- internal static extern bool ConvertSidToStringSid(
- IntPtr Sid,
- ref IntPtr StringSid
- );
-
-
- [DllImport(
- ADVAPI32,
- EntryPoint="CreateWellKnownSid",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL CreateWellKnownSid(
- int sidType,
- byte[] domainSid,
- [Out] byte[] resultSid,
- ref /*DWORD*/ uint resultSidLength );
-
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- bool DuplicateHandle (
- [In] IntPtr hSourceProcessHandle,
- [In] IntPtr hSourceHandle,
- [In] IntPtr hTargetProcessHandle,
- [In,Out] ref SafeAccessTokenHandle lpTargetHandle,
- [In] uint dwDesiredAccess,
- [In] bool bInheritHandle,
- [In] uint dwOptions);
-
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- [DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- bool DuplicateHandle (
- [In] IntPtr hSourceProcessHandle,
- [In] SafeAccessTokenHandle hSourceHandle,
- [In] IntPtr hTargetProcessHandle,
- [In,Out] ref SafeAccessTokenHandle lpTargetHandle,
- [In] uint dwDesiredAccess,
- [In] bool bInheritHandle,
- [In] uint dwOptions);
-
- [DllImport(
- ADVAPI32,
- EntryPoint="EqualDomainSid",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL IsEqualDomainSid(
- byte[] sid1,
- byte[] sid2,
- out bool result);
-
[DllImport(KERNEL32, CharSet=CharSet.Auto, SetLastError=true)]
internal static extern IntPtr GetCurrentProcess();
- [DllImport(KERNEL32, CharSet = CharSet.Auto, SetLastError = true)]
- internal static extern IntPtr GetCurrentThread();
-
- [DllImport(
- ADVAPI32,
- EntryPoint="GetSecurityDescriptorLength",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint GetSecurityDescriptorLength(
- IntPtr byteArray );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="GetSecurityInfo",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint GetSecurityInfoByHandle(
- SafeHandle handle,
- /*DWORD*/ uint objectType,
- /*DWORD*/ uint securityInformation,
- out IntPtr sidOwner,
- out IntPtr sidGroup,
- out IntPtr dacl,
- out IntPtr sacl,
- out IntPtr securityDescriptor );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="GetNamedSecurityInfoW",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint GetSecurityInfoByName(
- string name,
- /*DWORD*/ uint objectType,
- /*DWORD*/ uint securityInformation,
- out IntPtr sidOwner,
- out IntPtr sidGroup,
- out IntPtr dacl,
- out IntPtr sacl,
- out IntPtr securityDescriptor );
-
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- bool GetTokenInformation (
- [In] IntPtr TokenHandle,
- [In] uint TokenInformationClass,
- [In] SafeLocalAllocHandle TokenInformation,
- [In] uint TokenInformationLength,
- [Out] out uint ReturnLength);
-
- [DllImport(ADVAPI32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- bool GetTokenInformation (
- [In] SafeAccessTokenHandle TokenHandle,
- [In] uint TokenInformationClass,
- [In] SafeLocalAllocHandle TokenInformation,
- [In] uint TokenInformationLength,
- [Out] out uint ReturnLength);
-
- [DllImport(
- ADVAPI32,
- EntryPoint="GetWindowsAccountDomainSid",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL GetWindowsAccountDomainSid(
- byte[] sid,
- [Out] byte[] resultSid,
- ref /*DWORD*/ uint resultSidLength );
-
- internal enum SECURITY_IMPERSONATION_LEVEL
- {
- Anonymous = 0,
- Identification = 1,
- Impersonation = 2,
- Delegation = 3,
- }
-
- // Structures and definitions for Claims that are being introduced in Win8
- // inside the NTTOken - see winnt.h. They will be surfaced through WindowsIdentity.Claims
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_INVALID -> 0x00
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_INVALID = 0;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_INT64 -> 0x01
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_INT64 = 1;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_UINT64 -> 0x02
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_UINT64 = 2;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_STRING -> 0x03
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_STRING = 3;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_FQBN -> 0x04
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_FQBN = 4;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_SID -> 0x05
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_SID = 5;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_BOOLEAN -> 0x06
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_BOOLEAN = 6;
-
- // CLAIM_SECURITY_ATTRIBUTE_TYPE_OCTET_STRING -> 0x10
- internal const int CLAIM_SECURITY_ATTRIBUTE_TYPE_OCTET_STRING = 16;
-
- // CLAIM_SECURITY_ATTRIBUTE_NON_INHERITABLE -> 0x0001
- internal const int CLAIM_SECURITY_ATTRIBUTE_NON_INHERITABLE = 1;
-
- // CLAIM_SECURITY_ATTRIBUTE_VALUE_CASE_SENSITIVE -> 0x0002
- internal const int CLAIM_SECURITY_ATTRIBUTE_VALUE_CASE_SENSITIVE = 2;
-
- // CLAIM_SECURITY_ATTRIBUTE_USE_FOR_DENY_ONLY -> 0x0004
- internal const int CLAIM_SECURITY_ATTRIBUTE_USE_FOR_DENY_ONLY = 4;
-
- // CLAIM_SECURITY_ATTRIBUTE_DISABLED_BY_DEFAULT -> 0x0008
- internal const int CLAIM_SECURITY_ATTRIBUTE_DISABLED_BY_DEFAULT = 8;
-
- // CLAIM_SECURITY_ATTRIBUTE_DISABLED -> 0x0010
- internal const int CLAIM_SECURITY_ATTRIBUTE_DISABLED = 16;
-
- // CLAIM_SECURITY_ATTRIBUTE_MANDATORY -> 0x0020
- internal const int CLAIM_SECURITY_ATTRIBUTE_MANDATORY = 32;
-
- internal const int CLAIM_SECURITY_ATTRIBUTE_VALID_FLAGS =
- CLAIM_SECURITY_ATTRIBUTE_NON_INHERITABLE
- | CLAIM_SECURITY_ATTRIBUTE_VALUE_CASE_SENSITIVE
- | CLAIM_SECURITY_ATTRIBUTE_USE_FOR_DENY_ONLY
- | CLAIM_SECURITY_ATTRIBUTE_DISABLED_BY_DEFAULT
- | CLAIM_SECURITY_ATTRIBUTE_DISABLED
- | CLAIM_SECURITY_ATTRIBUTE_MANDATORY;
-
-
- [StructLayoutAttribute( LayoutKind.Explicit )]
- internal struct CLAIM_SECURITY_ATTRIBUTE_INFORMATION_V1
- {
- // defined as union in CLAIM_SECURITY_ATTRIBUTES_INFORMATION
- [FieldOffsetAttribute( 0 )]
- public IntPtr pAttributeV1;
- }
-
- [StructLayoutAttribute( LayoutKind.Sequential )]
- internal struct CLAIM_SECURITY_ATTRIBUTES_INFORMATION
- {
- /// WORD->unsigned short
- public ushort Version;
-
- /// WORD->unsigned short
- public ushort Reserved;
-
- /// DWORD->unsigned int
- public uint AttributeCount;
-
- /// CLAIM_SECURITY_ATTRIBUTE_V1
- public CLAIM_SECURITY_ATTRIBUTE_INFORMATION_V1 Attribute;
- }
-
- //
- // Fully-qualified binary name.
- //
- [StructLayoutAttribute( LayoutKind.Sequential, CharSet = CharSet.Unicode )]
- internal struct CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE
- {
- // DWORD64->unsigned __int64
- public ulong Version;
-
- // PWSTR->WCHAR*
- [MarshalAsAttribute( UnmanagedType.LPWStr )]
- public string Name;
- }
-
- [StructLayoutAttribute( LayoutKind.Sequential, CharSet = CharSet.Unicode )]
- internal struct CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE
- {
- /// PVOID->void*
- public IntPtr pValue;
-
- /// DWORD->unsigned int
- public uint ValueLength;
- }
-
- [StructLayoutAttribute( LayoutKind.Explicit, CharSet = CharSet.Unicode )]
- internal struct CLAIM_VALUES_ATTRIBUTE_V1
- {
- // PLONG64->__int64*
- [FieldOffsetAttribute( 0 )]
- public IntPtr pInt64;
-
- // PDWORD64->unsigned __int64*
- [FieldOffsetAttribute( 0 )]
- public IntPtr pUint64;
-
- // PWSTR*
- [FieldOffsetAttribute( 0 )]
- public IntPtr ppString;
-
- // PCLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE->_CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE*
- [FieldOffsetAttribute( 0 )]
- public IntPtr pFqbn;
-
- // PCLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE->_CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE*
- [FieldOffsetAttribute( 0 )]
- public IntPtr pOctetString;
- }
-
- [StructLayoutAttribute( LayoutKind.Sequential, CharSet = CharSet.Unicode )]
- internal struct CLAIM_SECURITY_ATTRIBUTE_V1
- {
- // PWSTR->WCHAR*
- [MarshalAsAttribute( UnmanagedType.LPWStr )]
- public string Name;
-
- // WORD->unsigned short
- public ushort ValueType;
-
- // WORD->unsigned short
- public ushort Reserved;
-
- // DWORD->unsigned int
- public uint Flags;
-
- // DWORD->unsigned int
- public uint ValueCount;
-
- // struct CLAIM_VALUES - a union of 4 possible values
- public CLAIM_VALUES_ATTRIBUTE_V1 Values;
- }
-
- [DllImport(
- ADVAPI32,
- EntryPoint="IsWellKnownSid",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern BOOL IsWellKnownSid(
- byte[] sid,
- int type );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="LsaOpenPolicy",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint LsaOpenPolicy(
- string systemName,
- ref LSA_OBJECT_ATTRIBUTES attributes,
- int accessMask,
- out SafeLsaPolicyHandle handle
- );
-
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- [DllImport(
- ADVAPI32,
- EntryPoint="LookupPrivilegeValueW",
- CharSet=CharSet.Auto,
- SetLastError=true,
- ExactSpelling=true,
- BestFitMapping=false)]
- internal static extern
- bool LookupPrivilegeValue (
- [In] string lpSystemName,
- [In] string lpName,
- [In,Out] ref LUID Luid);
-
- [DllImport(
- ADVAPI32,
- EntryPoint="LsaLookupSids",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint LsaLookupSids(
- SafeLsaPolicyHandle handle,
- int count,
- IntPtr[] sids,
- ref SafeLsaMemoryHandle referencedDomains,
- ref SafeLsaMemoryHandle names
- );
-
- [DllImport(ADVAPI32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern int LsaFreeMemory( IntPtr handle );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="LsaLookupNames",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint LsaLookupNames(
- SafeLsaPolicyHandle handle,
- int count,
- UNICODE_STRING[] names,
- ref SafeLsaMemoryHandle referencedDomains,
- ref SafeLsaMemoryHandle sids
- );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="LsaLookupNames2",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint LsaLookupNames2(
- SafeLsaPolicyHandle handle,
- int flags,
- int count,
- UNICODE_STRING[] names,
- ref SafeLsaMemoryHandle referencedDomains,
- ref SafeLsaMemoryHandle sids
- );
-
- [DllImport(SECUR32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- int LsaConnectUntrusted (
- [In,Out] ref SafeLsaLogonProcessHandle LsaHandle);
-
- [DllImport(SECUR32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- int LsaGetLogonSessionData (
- [In] ref LUID LogonId,
- [In,Out] ref SafeLsaReturnBufferHandle ppLogonSessionData);
-
- [DllImport(SECUR32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- int LsaLogonUser (
- [In] SafeLsaLogonProcessHandle LsaHandle,
- [In] ref UNICODE_INTPTR_STRING OriginName,
- [In] uint LogonType,
- [In] uint AuthenticationPackage,
- [In] IntPtr AuthenticationInformation,
- [In] uint AuthenticationInformationLength,
- [In] IntPtr LocalGroups,
- [In] ref TOKEN_SOURCE SourceContext,
- [In,Out] ref SafeLsaReturnBufferHandle ProfileBuffer,
- [In,Out] ref uint ProfileBufferLength,
- [In,Out] ref LUID LogonId,
- [In,Out] ref SafeAccessTokenHandle Token,
- [In,Out] ref QUOTA_LIMITS Quotas,
- [In,Out] ref int SubStatus);
-
- [DllImport(SECUR32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- int LsaLookupAuthenticationPackage (
- [In] SafeLsaLogonProcessHandle LsaHandle,
- [In] ref UNICODE_INTPTR_STRING PackageName,
- [In,Out] ref uint AuthenticationPackage);
-
- [DllImport(SECUR32, CharSet=CharSet.Auto, SetLastError=true)]
- internal static extern
- int LsaRegisterLogonProcess (
- [In] ref UNICODE_INTPTR_STRING LogonProcessName,
- [In,Out] ref SafeLsaLogonProcessHandle LsaHandle,
- [In,Out] ref IntPtr SecurityMode);
-
- [DllImport(SECUR32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern int LsaDeregisterLogonProcess(IntPtr handle);
-
- [DllImport(ADVAPI32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern int LsaClose( IntPtr handle );
-
- [DllImport(SECUR32, SetLastError=true)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal static extern int LsaFreeReturnBuffer(IntPtr handle);
-
- [DllImport(
- ADVAPI32,
- EntryPoint="SetNamedSecurityInfoW",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint SetSecurityInfoByName(
- string name,
- /*DWORD*/ uint objectType,
- /*DWORD*/ uint securityInformation,
- byte[] owner,
- byte[] group,
- byte[] dacl,
- byte[] sacl );
-
- [DllImport(
- ADVAPI32,
- EntryPoint="SetSecurityInfo",
- CallingConvention=CallingConvention.Winapi,
- SetLastError=true,
- ExactSpelling=true,
- CharSet=CharSet.Unicode)]
- internal static extern /*DWORD*/ uint SetSecurityInfoByHandle(
- SafeHandle handle,
- /*DWORD*/ uint objectType,
- /*DWORD*/ uint securityInformation,
- byte[] owner,
- byte[] group,
- byte[] dacl,
- byte[] sacl );
-
[DllImport(KERNEL32, CharSet=CharSet.Unicode)]
[SuppressUnmanagedCodeSecurityAttribute()]
internal unsafe static extern int WideCharToMultiByte(
private static Type GetConsoleType()
{
-#if FEATURE_LEGACYSURFACE
- return typeof(Console);
-#else
return Type.GetType(
"System.Console, System.Console, Version=4.0.0.0, Culture=neutral, PublicKeyToken=" + AssemblyRef.MicrosoftPublicKeyToken,
throwOnError: true);
-#endif
}
public virtual void EmitWriteLine(String value)
private PermissionSet m_DeclarativeDenials;
private PermissionSet m_DeclarativeRestrictions;
-#if !FEATURE_PAL
- // if this frame contains a call to any WindowsIdentity.Impersonate(),
- // we save the previous SafeTokenHandles here (in the next two fields)
- // Used during exceptionstackwalks to revert impersonation before calling filters
- [NonSerialized]
- private SafeAccessTokenHandle m_callerToken;
- [NonSerialized]
- private SafeAccessTokenHandle m_impToken;
-#endif
-
private bool m_AssertFT;
private bool m_assertAllPossible;
#pragma warning disable 169
return (fDeclarative) ? m_DeclarativeRestrictions : m_restriction;
}
-#if !FEATURE_PAL
- //-----------------------------------------------------------+
- // SafeAccessTokenHandle (Impersonation + EH purposes)
- //-----------------------------------------------------------+
- internal void SetTokenHandles (SafeAccessTokenHandle callerToken, SafeAccessTokenHandle impToken)
- {
- m_callerToken = callerToken;
- m_impToken = impToken;
- }
-#endif
+
//-----------------------------------------------------------+
// R E V E R T
//-----------------------------------------------------------+
+++ /dev/null
-// 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.
-namespace Microsoft.Win32.SafeHandles {
- using System;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Runtime.ConstrainedExecution;
- using System.Runtime.Versioning;
- using System.Security;
-
- // Introduce this handle to replace internal SafeTokenHandle,
- // which is mainly used to hold Windows thread or process access token
- public sealed class SafeAccessTokenHandle : SafeHandle
- {
- private SafeAccessTokenHandle()
- : base(IntPtr.Zero, true)
- { }
-
- // 0 is an Invalid Handle
- public SafeAccessTokenHandle(IntPtr handle)
- : base(IntPtr.Zero, true)
- {
- SetHandle(handle);
- }
-
- public static SafeAccessTokenHandle InvalidHandle
- {
- get { return new SafeAccessTokenHandle(IntPtr.Zero); }
- }
-
- public override bool IsInvalid
- {
- get { return handle == IntPtr.Zero || handle == new IntPtr(-1); }
- }
-
- protected override bool ReleaseHandle()
- {
- return Win32Native.CloseHandle(handle);
- }
- }
-
- internal sealed class SafeLsaLogonProcessHandle : SafeHandleZeroOrMinusOneIsInvalid {
- private SafeLsaLogonProcessHandle() : base (true) {}
-
- // 0 is an Invalid Handle
- internal SafeLsaLogonProcessHandle(IntPtr handle) : base (true) {
- SetHandle(handle);
- }
-
- internal static SafeLsaLogonProcessHandle InvalidHandle {
- get { return new SafeLsaLogonProcessHandle(IntPtr.Zero); }
- }
-
- override protected bool ReleaseHandle()
- {
- // LsaDeregisterLogonProcess returns an NTSTATUS
- return Win32Native.LsaDeregisterLogonProcess(handle) >= 0;
- }
- }
-
- internal sealed class SafeLsaMemoryHandle : SafeBuffer {
- private SafeLsaMemoryHandle() : base(true) {}
-
- // 0 is an Invalid Handle
- internal SafeLsaMemoryHandle(IntPtr handle) : base (true) {
- SetHandle(handle);
- }
-
- internal static SafeLsaMemoryHandle InvalidHandle {
- get { return new SafeLsaMemoryHandle( IntPtr.Zero ); }
- }
-
- override protected bool ReleaseHandle()
- {
- return Win32Native.LsaFreeMemory(handle) == 0;
- }
- }
-
- internal sealed class SafeLsaPolicyHandle : SafeHandleZeroOrMinusOneIsInvalid {
- private SafeLsaPolicyHandle() : base(true) {}
-
- // 0 is an Invalid Handle
- internal SafeLsaPolicyHandle(IntPtr handle) : base (true) {
- SetHandle(handle);
- }
-
- internal static SafeLsaPolicyHandle InvalidHandle {
- get { return new SafeLsaPolicyHandle( IntPtr.Zero ); }
- }
-
- override protected bool ReleaseHandle()
- {
- return Win32Native.LsaClose(handle) == 0;
- }
- }
-
- internal sealed class SafeLsaReturnBufferHandle : SafeBuffer {
- private SafeLsaReturnBufferHandle() : base (true) {}
-
- // 0 is an Invalid Handle
- internal SafeLsaReturnBufferHandle(IntPtr handle) : base (true) {
- SetHandle(handle);
- }
-
- internal static SafeLsaReturnBufferHandle InvalidHandle {
- get { return new SafeLsaReturnBufferHandle(IntPtr.Zero); }
- }
-
- override protected bool ReleaseHandle()
- {
- // LsaFreeReturnBuffer returns an NTSTATUS
- return Win32Native.LsaFreeReturnBuffer(handle) >= 0;
- }
- }
-
- internal sealed class SafeProcessHandle : SafeHandleZeroOrMinusOneIsInvalid {
- private SafeProcessHandle() : base (true) {}
-
- // 0 is an Invalid Handle
- internal SafeProcessHandle(IntPtr handle) : base (true) {
- SetHandle(handle);
- }
-
- internal static SafeProcessHandle InvalidHandle {
- get { return new SafeProcessHandle(IntPtr.Zero); }
- }
-
- override protected bool ReleaseHandle()
- {
- return Win32Native.CloseHandle(handle);
- }
- }
-
- internal sealed class SafeThreadHandle : SafeHandleZeroOrMinusOneIsInvalid {
- private SafeThreadHandle() : base (true) {}
-
- // 0 is an Invalid Handle
- internal SafeThreadHandle(IntPtr handle) : base (true) {
- SetHandle(handle);
- }
-
- override protected bool ReleaseHandle()
- {
- return Win32Native.CloseHandle(handle);
- }
- }
-}
+++ /dev/null
-// 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.
-namespace System.Security {
- using System.Security.Cryptography;
- using System.Runtime.InteropServices;
-#if FEATURE_CORRUPTING_EXCEPTIONS
- using System.Runtime.ExceptionServices;
-#endif // FEATURE_CORRUPTING_EXCEPTIONS
- using System.Text;
- using Microsoft.Win32;
- using System.Runtime.CompilerServices;
- using System.Security.Permissions;
- using System.Runtime.ConstrainedExecution;
- using System.Runtime.Versioning;
- using Microsoft.Win32.SafeHandles;
- using System.Diagnostics;
- using System.Diagnostics.Contracts;
-
- public sealed class SecureString: IDisposable {
- [System.Security.SecurityCritical] // auto-generated
- private SafeBSTRHandle m_buffer;
- [ContractPublicPropertyName("Length")]
- private int m_length;
- private bool m_readOnly;
- private bool m_encrypted;
-
- static bool supportedOnCurrentPlatform = EncryptionSupported();
-
- const int BlockSize = (int)Win32Native.CRYPTPROTECTMEMORY_BLOCK_SIZE /2; // a char is two bytes
- const int MaxLength = 65536;
- const uint ProtectionScope = Win32Native.CRYPTPROTECTMEMORY_SAME_PROCESS;
-
- [System.Security.SecuritySafeCritical] // auto-generated
- static SecureString()
- {
- }
-
- [System.Security.SecurityCritical] // auto-generated
- unsafe static bool EncryptionSupported() {
- // check if the enrypt/decrypt function is supported on current OS
- bool supported = true;
- try {
- Win32Native.SystemFunction041(
- SafeBSTRHandle.Allocate(null , (int)Win32Native.CRYPTPROTECTMEMORY_BLOCK_SIZE),
- Win32Native.CRYPTPROTECTMEMORY_BLOCK_SIZE,
- Win32Native.CRYPTPROTECTMEMORY_SAME_PROCESS);
- }
- catch (EntryPointNotFoundException) {
- supported = false;
- }
- return supported;
- }
-
- [System.Security.SecurityCritical] // auto-generated
- internal SecureString(SecureString str) {
- AllocateBuffer(str.BufferLength);
- SafeBSTRHandle.Copy(str.m_buffer, this.m_buffer);
- m_length = str.m_length;
- m_encrypted = str.m_encrypted;
- }
-
-
- [System.Security.SecuritySafeCritical] // auto-generated
- public SecureString() {
- CheckSupportedOnCurrentPlatform();
-
- // allocate the minimum block size for calling protectMemory
- AllocateBuffer(BlockSize);
- m_length = 0;
- }
-
-
- [System.Security.SecurityCritical] // auto-generated
-#if FEATURE_CORRUPTING_EXCEPTIONS
- [HandleProcessCorruptedStateExceptions]
-#endif // FEATURE_CORRUPTING_EXCEPTIONS
- private unsafe void InitializeSecureString(char* value, int length)
- {
- CheckSupportedOnCurrentPlatform();
-
- AllocateBuffer(length);
- m_length = length;
-
- byte* bufferPtr = null;
- RuntimeHelpers.PrepareConstrainedRegions();
- try
- {
- m_buffer.AcquirePointer(ref bufferPtr);
- Buffer.Memcpy(bufferPtr, (byte*)value, length * 2);
- }
- catch (Exception) {
- ProtectMemory();
- throw;
- }
- finally
- {
- if (bufferPtr != null)
- m_buffer.ReleasePointer();
- }
-
- ProtectMemory();
- }
-
- [System.Security.SecurityCritical] // auto-generated
- [CLSCompliant(false)]
- public unsafe SecureString(char* value, int length) {
- if( value == null) {
- throw new ArgumentNullException(nameof(value));
- }
-
- if( length < 0) {
- throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
- }
-
- if( length > MaxLength) {
- throw new ArgumentOutOfRangeException(nameof(length), Environment.GetResourceString("ArgumentOutOfRange_Length"));
- }
- Contract.EndContractBlock();
-
- // Refactored since HandleProcessCorruptedStateExceptionsAttribute applies to methods only (yet).
- InitializeSecureString(value, length);
- }
-
- public int Length {
- [System.Security.SecuritySafeCritical] // auto-generated
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
- get {
- EnsureNotDisposed();
- return m_length;
- }
- }
-
- [System.Security.SecuritySafeCritical] // auto-generated
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
-#if FEATURE_CORRUPTING_EXCEPTIONS
- [HandleProcessCorruptedStateExceptions]
-#endif // FEATURE_CORRUPTING_EXCEPTIONS
- public void AppendChar(char c) {
- EnsureNotDisposed();
- EnsureNotReadOnly();
-
- EnsureCapacity(m_length + 1);
-
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- UnProtectMemory();
- m_buffer.Write<char>((uint)m_length * sizeof(char), c);
- m_length++;
- }
- catch (Exception) {
- ProtectMemory();
- throw;
- }
- finally {
- ProtectMemory();
- }
- }
-
- // clears the current contents. Only available if writable
- [System.Security.SecuritySafeCritical] // auto-generated
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
- public void Clear() {
- EnsureNotDisposed();
- EnsureNotReadOnly();
-
- m_length = 0;
- m_buffer.ClearBuffer();
- m_encrypted = false;
- }
-
- // Do a deep-copy of the SecureString
- [System.Security.SecuritySafeCritical] // auto-generated
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
- public SecureString Copy() {
- EnsureNotDisposed();
- return new SecureString(this);
- }
-
- [System.Security.SecuritySafeCritical] // auto-generated
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
- public void Dispose() {
- if(m_buffer != null && !m_buffer.IsInvalid) {
- m_buffer.Close();
- m_buffer = null;
- }
- }
-
- [System.Security.SecuritySafeCritical] // auto-generated
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
-#if FEATURE_CORRUPTING_EXCEPTIONS
- [HandleProcessCorruptedStateExceptions]
-#endif // FEATURE_CORRUPTING_EXCEPTIONS
- public void InsertAt( int index, char c ) {
- if( index < 0 || index > m_length) {
- throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_IndexString"));
- }
- Contract.EndContractBlock();
-
- EnsureNotDisposed();
- EnsureNotReadOnly();
-
- EnsureCapacity(m_length + 1);
-
- unsafe {
- byte* bufferPtr = null;
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- UnProtectMemory();
- m_buffer.AcquirePointer(ref bufferPtr);
- char* pBuffer = (char*)bufferPtr;
-
- for (int i = m_length; i > index; i--) {
- pBuffer[i] = pBuffer[i - 1];
- }
- pBuffer[index] = c;
- ++m_length;
- }
- catch (Exception) {
- ProtectMemory();
- throw;
- }
- finally {
- ProtectMemory();
- if (bufferPtr != null)
- m_buffer.ReleasePointer();
- }
- }
- }
-
- [System.Security.SecuritySafeCritical] // auto-generated
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
- public bool IsReadOnly() {
- EnsureNotDisposed();
- return m_readOnly;
- }
-
- [System.Security.SecuritySafeCritical] // auto-generated
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
- public void MakeReadOnly() {
- EnsureNotDisposed();
- m_readOnly = true;
- }
-
- [System.Security.SecuritySafeCritical] // auto-generated
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
-#if FEATURE_CORRUPTING_EXCEPTIONS
- [HandleProcessCorruptedStateExceptions]
-#endif // FEATURE_CORRUPTING_EXCEPTIONS
- public void RemoveAt( int index ) {
- EnsureNotDisposed();
- EnsureNotReadOnly();
-
- if( index < 0 || index >= m_length) {
- throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_IndexString"));
- }
-
- unsafe
- {
- byte* bufferPtr = null;
- RuntimeHelpers.PrepareConstrainedRegions();
- try
- {
- UnProtectMemory();
- m_buffer.AcquirePointer(ref bufferPtr);
- char* pBuffer = (char*)bufferPtr;
-
- for (int i = index; i < m_length - 1; i++)
- {
- pBuffer[i] = pBuffer[i + 1];
- }
- pBuffer[--m_length] = (char)0;
- }
- catch (Exception) {
- ProtectMemory();
- throw;
- }
- finally
- {
- ProtectMemory();
- if (bufferPtr != null)
- m_buffer.ReleasePointer();
- }
- }
- }
-
- [System.Security.SecuritySafeCritical] // auto-generated
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
-#if FEATURE_CORRUPTING_EXCEPTIONS
- [HandleProcessCorruptedStateExceptions]
-#endif // FEATURE_CORRUPTING_EXCEPTIONS
- public void SetAt( int index, char c ) {
- if( index < 0 || index >= m_length) {
- throw new ArgumentOutOfRangeException(nameof(index), Environment.GetResourceString("ArgumentOutOfRange_IndexString"));
- }
- Contract.EndContractBlock();
- Debug.Assert(index <= Int32.MaxValue / sizeof(char));
-
- EnsureNotDisposed();
- EnsureNotReadOnly();
-
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- UnProtectMemory();
- m_buffer.Write<char>((uint)index * sizeof(char), c);
- }
- catch (Exception) {
- ProtectMemory();
- throw;
- }
- finally {
- ProtectMemory();
- }
- }
-
- private int BufferLength {
- [System.Security.SecurityCritical] // auto-generated
- get {
- Debug.Assert(m_buffer != null, "Buffer is not initialized!");
- return m_buffer.Length;
- }
- }
-
- [System.Security.SecurityCritical] // auto-generated
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- private void AllocateBuffer(int size) {
- uint alignedSize = GetAlignedSize(size);
-
- m_buffer = SafeBSTRHandle.Allocate(null, alignedSize);
- if (m_buffer.IsInvalid) {
- throw new OutOfMemoryException();
- }
- }
-
- private void CheckSupportedOnCurrentPlatform() {
- if( !supportedOnCurrentPlatform) {
- throw new NotSupportedException(Environment.GetResourceString("Arg_PlatformSecureString"));
- }
- Contract.EndContractBlock();
- }
-
- [System.Security.SecurityCritical] // auto-generated
- private void EnsureCapacity(int capacity) {
- if( capacity > MaxLength) {
- throw new ArgumentOutOfRangeException(nameof(capacity), Environment.GetResourceString("ArgumentOutOfRange_Capacity"));
- }
- Contract.EndContractBlock();
-
- if( capacity <= m_buffer.Length) {
- return;
- }
-
- SafeBSTRHandle newBuffer = SafeBSTRHandle.Allocate(null, GetAlignedSize(capacity));
-
- if (newBuffer.IsInvalid) {
- throw new OutOfMemoryException();
- }
-
- SafeBSTRHandle.Copy(m_buffer, newBuffer);
- m_buffer.Close();
- m_buffer = newBuffer;
- }
-
- [System.Security.SecurityCritical] // auto-generated
- private void EnsureNotDisposed() {
- if( m_buffer == null) {
- throw new ObjectDisposedException(null);
- }
- Contract.EndContractBlock();
- }
-
- private void EnsureNotReadOnly() {
- if( m_readOnly) {
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_ReadOnly"));
- }
- Contract.EndContractBlock();
- }
-
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- private static uint GetAlignedSize( int size) {
- Debug.Assert(size >= 0, "size must be non-negative");
-
- uint alignedSize = ((uint)size / BlockSize) * BlockSize;
- if( (size % BlockSize != 0) || size == 0) { // if size is 0, set allocated size to blocksize
- alignedSize += BlockSize;
- }
- return alignedSize;
- }
-
- [System.Security.SecurityCritical] // auto-generated
- private unsafe int GetAnsiByteCount() {
- const uint CP_ACP = 0;
- const uint WC_NO_BEST_FIT_CHARS = 0x00000400;
-
- uint flgs = WC_NO_BEST_FIT_CHARS;
- uint DefaultCharUsed = (uint)'?';
-
- byte* bufferPtr = null;
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- m_buffer.AcquirePointer(ref bufferPtr);
-
- return Win32Native.WideCharToMultiByte(
- CP_ACP,
- flgs,
- (char*) bufferPtr,
- m_length,
- null,
- 0,
- IntPtr.Zero,
- new IntPtr((void*)&DefaultCharUsed));
- }
- finally {
- if (bufferPtr != null)
- m_buffer.ReleasePointer();
- }
- }
-
- [System.Security.SecurityCritical] // auto-generated
- private unsafe void GetAnsiBytes( byte * ansiStrPtr, int byteCount) {
- const uint CP_ACP = 0;
- const uint WC_NO_BEST_FIT_CHARS = 0x00000400;
-
- uint flgs = WC_NO_BEST_FIT_CHARS;
- uint DefaultCharUsed = (uint)'?';
-
- byte* bufferPtr = null;
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- m_buffer.AcquirePointer(ref bufferPtr);
-
- Win32Native.WideCharToMultiByte(
- CP_ACP,
- flgs,
- (char*) bufferPtr,
- m_length,
- ansiStrPtr,
- byteCount - 1,
- IntPtr.Zero,
- new IntPtr((void*)&DefaultCharUsed));
-
- *(ansiStrPtr + byteCount - 1) = (byte)0;
- }
- finally {
- if (bufferPtr != null)
- m_buffer.ReleasePointer();
- }
- }
-
- [System.Security.SecurityCritical] // auto-generated
- [ReliabilityContract(Consistency.MayCorruptInstance, Cer.MayFail)]
- private void ProtectMemory() {
- Debug.Assert(!m_buffer.IsInvalid && m_buffer.Length != 0, "Invalid buffer!");
- Debug.Assert(m_buffer.Length % BlockSize == 0, "buffer length must be multiple of blocksize!");
-
- if( m_length == 0 || m_encrypted) {
- return;
- }
-
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- }
- finally {
- // RtlEncryptMemory return an NTSTATUS
- int status = Win32Native.SystemFunction040(m_buffer, (uint)m_buffer.Length * 2, ProtectionScope);
- if (status < 0) { // non-negative numbers indicate success
-#if FEATURE_CORECLR
- throw new CryptographicException(Win32Native.RtlNtStatusToDosError(status));
-#else
- throw new CryptographicException(Win32Native.LsaNtStatusToWinError(status));
-#endif
- }
- m_encrypted = true;
- }
- }
-
- [System.Security.SecurityCritical] // auto-generated
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
-#if FEATURE_CORRUPTING_EXCEPTIONS
- [HandleProcessCorruptedStateExceptions]
-#endif // FEATURE_CORRUPTING_EXCEPTIONS
- internal unsafe IntPtr ToBSTR() {
- EnsureNotDisposed();
- int length = m_length;
- IntPtr ptr = IntPtr.Zero;
- IntPtr result = IntPtr.Zero;
- byte* bufferPtr = null;
-
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- }
- finally {
- ptr = Win32Native.SysAllocStringLen(null, length);
- }
-
- if (ptr == IntPtr.Zero) {
- throw new OutOfMemoryException();
- }
-
- UnProtectMemory();
- m_buffer.AcquirePointer(ref bufferPtr);
- Buffer.Memcpy((byte*) ptr.ToPointer(), bufferPtr, length *2);
- result = ptr;
- }
- catch (Exception) {
- ProtectMemory();
- throw;
- }
- finally {
- ProtectMemory();
- if( result == IntPtr.Zero) {
- // If we failed for any reason, free the new buffer
- if (ptr != IntPtr.Zero) {
- Win32Native.ZeroMemory(ptr, (UIntPtr)(length * 2));
- Win32Native.SysFreeString(ptr);
- }
- }
- if (bufferPtr != null)
- m_buffer.ReleasePointer();
- }
- return result;
- }
-
- [System.Security.SecurityCritical] // auto-generated
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
-#if FEATURE_CORRUPTING_EXCEPTIONS
- [HandleProcessCorruptedStateExceptions]
-#endif // FEATURE_CORRUPTING_EXCEPTIONS
- internal unsafe IntPtr ToUniStr(bool allocateFromHeap) {
- EnsureNotDisposed();
- int length = m_length;
- IntPtr ptr = IntPtr.Zero;
- IntPtr result = IntPtr.Zero;
- byte* bufferPtr = null;
-
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- }
- finally {
- if( allocateFromHeap) {
- ptr = Marshal.AllocHGlobal((length + 1) * 2);
- }
- else {
- ptr = Marshal.AllocCoTaskMem((length + 1) * 2);
- }
- }
-
- if (ptr == IntPtr.Zero) {
- throw new OutOfMemoryException();
- }
-
- UnProtectMemory();
- m_buffer.AcquirePointer(ref bufferPtr);
- Buffer.Memcpy((byte*) ptr.ToPointer(), bufferPtr, length *2);
- char * endptr = (char *) ptr.ToPointer();
- *(endptr + length) = '\0';
- result = ptr;
- }
- catch (Exception) {
- ProtectMemory();
- throw;
- }
- finally {
- ProtectMemory();
-
- if( result == IntPtr.Zero) {
- // If we failed for any reason, free the new buffer
- if (ptr != IntPtr.Zero) {
- Win32Native.ZeroMemory(ptr, (UIntPtr)(length * 2));
- if( allocateFromHeap) {
- Marshal.FreeHGlobal(ptr);
- }
- else {
- Marshal.FreeCoTaskMem(ptr);
- }
- }
- }
-
- if (bufferPtr != null)
- m_buffer.ReleasePointer();
- }
- return result;
- }
-
- [System.Security.SecurityCritical] // auto-generated
- [MethodImplAttribute(MethodImplOptions.Synchronized)]
-#if FEATURE_CORRUPTING_EXCEPTIONS
- [HandleProcessCorruptedStateExceptions]
-#endif // FEATURE_CORRUPTING_EXCEPTIONS
- internal unsafe IntPtr ToAnsiStr(bool allocateFromHeap) {
- EnsureNotDisposed();
-
- IntPtr ptr = IntPtr.Zero;
- IntPtr result = IntPtr.Zero;
- int byteCount = 0;
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- // GetAnsiByteCount uses the string data, so the calculation must happen after we are decrypted.
- UnProtectMemory();
-
- // allocating an extra char for terminating zero
- byteCount = GetAnsiByteCount() + 1;
-
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- }
- finally {
- if( allocateFromHeap) {
- ptr = Marshal.AllocHGlobal(byteCount);
- }
- else {
- ptr = Marshal.AllocCoTaskMem(byteCount);
- }
- }
-
- if (ptr == IntPtr.Zero) {
- throw new OutOfMemoryException();
- }
-
- GetAnsiBytes((byte *)ptr.ToPointer(), byteCount);
- result = ptr;
- }
- catch (Exception) {
- ProtectMemory();
- throw;
- }
- finally {
- ProtectMemory();
- if( result == IntPtr.Zero) {
- // If we failed for any reason, free the new buffer
- if (ptr != IntPtr.Zero) {
- Win32Native.ZeroMemory(ptr, (UIntPtr)byteCount);
- if( allocateFromHeap) {
- Marshal.FreeHGlobal(ptr);
- }
- else {
- Marshal.FreeCoTaskMem(ptr);
- }
- }
- }
-
- }
- return result;
- }
-
- [System.Security.SecurityCritical] // auto-generated
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- private void UnProtectMemory() {
- Debug.Assert(!m_buffer.IsInvalid && m_buffer.Length != 0, "Invalid buffer!");
- Debug.Assert(m_buffer.Length % BlockSize == 0, "buffer length must be multiple of blocksize!");
-
- if( m_length == 0) {
- return;
- }
-
- RuntimeHelpers.PrepareConstrainedRegions();
- try {
- }
- finally {
- if (m_encrypted) {
- // RtlEncryptMemory return an NTSTATUS
- int status = Win32Native.SystemFunction041(m_buffer, (uint)m_buffer.Length * 2, ProtectionScope);
- if (status < 0)
- { // non-negative numbers indicate success
-#if FEATURE_CORECLR
- throw new CryptographicException(Win32Native.RtlNtStatusToDosError(status));
-#else
- throw new CryptographicException(Win32Native.LsaNtStatusToWinError(status));
-#endif
- }
- m_encrypted = false;
- }
- }
- }
- }
-
- [System.Security.SecurityCritical] // auto-generated
- [SuppressUnmanagedCodeSecurityAttribute()]
- internal sealed class SafeBSTRHandle : SafeBuffer {
- internal SafeBSTRHandle () : base(true) {}
-
- internal static SafeBSTRHandle Allocate(String src, uint len)
- {
- SafeBSTRHandle bstr = SysAllocStringLen(src, len);
- bstr.Initialize(len * sizeof(char));
- return bstr;
- }
-
- [DllImport(Win32Native.OLEAUT32, CharSet = CharSet.Unicode)]
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
- private static extern SafeBSTRHandle SysAllocStringLen(String src, uint len); // BSTR
-
- [System.Security.SecurityCritical]
- override protected bool ReleaseHandle()
- {
- Win32Native.ZeroMemory(handle, (UIntPtr) (Win32Native.SysStringLen(handle) * 2));
- Win32Native.SysFreeString(handle);
- return true;
- }
-
- [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
- internal unsafe void ClearBuffer() {
- byte* bufferPtr = null;
- RuntimeHelpers.PrepareConstrainedRegions();
- try
- {
- AcquirePointer(ref bufferPtr);
- Win32Native.ZeroMemory((IntPtr)bufferPtr, (UIntPtr) (Win32Native.SysStringLen((IntPtr)bufferPtr) * 2));
- }
- finally
- {
- if (bufferPtr != null)
- ReleasePointer();
- }
- }
-
-
- internal unsafe int Length {
- get {
- return (int) Win32Native.SysStringLen(this);
- }
- }
-
- internal unsafe static void Copy(SafeBSTRHandle source, SafeBSTRHandle target) {
- byte* sourcePtr = null, targetPtr = null;
- RuntimeHelpers.PrepareConstrainedRegions();
- try
- {
- source.AcquirePointer(ref sourcePtr);
- target.AcquirePointer(ref targetPtr);
-
- Debug.Assert(Win32Native.SysStringLen((IntPtr)targetPtr) >= Win32Native.SysStringLen((IntPtr)sourcePtr), "Target buffer is not large enough!");
-
- Buffer.Memcpy(targetPtr, sourcePtr, (int) Win32Native.SysStringLen((IntPtr)sourcePtr) * 2);
- }
- finally
- {
- if (sourcePtr != null)
- source.ReleasePointer();
- if (targetPtr != null)
- target.ReleasePointer();
- }
- }
- }
-}
-
#include "ipcfunccall.h"
#include "perflog.h"
#include "../dlls/mscorrc/resource.h"
-#if defined(FEATURE_LEGACYSURFACE) || defined(FEATURE_USE_LCID)
+#ifdef FEATURE_USE_LCID
#include "nlsinfo.h"
#endif
#include "util.hpp"
FCFuncElement("BeginThreadAffinity", ThreadNative::BeginThreadAffinity)
FCFuncElement("EndThreadAffinity", ThreadNative::EndThreadAffinity)
#endif // FEATURE_CORECLR
-#ifdef FEATURE_LEGACYSURFACE
- FCFuncElement("AbortInternal", ThreadNative::Abort)
-#endif // FEATURE_LEGACYSURFACE
#ifndef FEATURE_CORECLR
FCFuncElement("ResetAbortNative", ThreadNative::ResetAbort)
#endif // FEATURE_CORECLR
MethodDesc * pProfilerNotify; // Context for profiler callbacks -- see COMPlusFrameHandler().
BOOL bReplaceStack; // Used to pass info to SaveStackTrace call
BOOL bSkipLastElement;// Used to pass info to SaveStackTrace call
-#ifndef FEATURE_PAL
- HANDLE hCallerToken;
- HANDLE hImpersonationToken;
- BOOL bImpersonationTokenSet;
-#endif // !FEATURE_PAL
#ifdef _DEBUG
void * pCurrentExceptionRecord;
void * pPrevExceptionRecord;
pProfilerNotify = NULL;
bReplaceStack = FALSE;
bSkipLastElement = FALSE;
-#ifndef FEATURE_PAL
- hCallerToken = NULL;
- hImpersonationToken = NULL;
- bImpersonationTokenSet = FALSE;
-#endif // !FEATURE_PAL
-
#ifdef _DEBUG
pCurrentExceptionRecord = 0;
pPrevExceptionRecord = 0;
#include "common.h"
-#ifndef FEATURE_PAL
-#include "securityprincipal.h"
-#endif // !FEATURE_PAL
-
#ifdef WIN64EXCEPTIONS
#include "exceptionhandling.h"
#include "dbginterface.h"
// we probably don't want to be so strict in not calling handlers.
if (! IsStackOverflowException())
{
-#ifndef FEATURE_PAL
- // Check for any impersonation on the frame and save that for use during EH filter callbacks
- OBJECTREF* pRefSecDesc = pcfThisFrame->GetAddrOfSecurityObject();
- if (pRefSecDesc != NULL && *pRefSecDesc != NULL)
- {
- GCX_COOP();
- FRAMESECDESCREF fsdRef = (FRAMESECDESCREF)*pRefSecDesc;
- if (fsdRef->GetCallerToken() != NULL)
- {
- m_hCallerToken = fsdRef->GetCallerToken();
- STRESS_LOG1(LF_EH, LL_INFO100, "In COMPlusThrowCallback. Found non-NULL callertoken on FSD:%d\n",m_hCallerToken);
- if (!m_ExceptionFlags.ImpersonationTokenSet())
- {
- m_hImpersonationToken = fsdRef->GetImpersonationToken();
- STRESS_LOG1(LF_EH, LL_INFO100, "In COMPlusThrowCallback. Found non-NULL impersonationtoken on FSD:%d\n",m_hImpersonationToken);
- m_ExceptionFlags.SetImpersonationTokenSet();
- }
- }
- }
- BOOL impersonating = FALSE;
-#endif // !FEATURE_PAL
-
// Save the current EHClause Index and Establisher of the clause post which
// ThreadAbort was raised. This is done an exception handled inside a filter
// reset the state that was setup before the filter was invoked.
EX_TRY
{
-#ifndef FEATURE_PAL
- if (m_hCallerToken != NULL)
- {
- STRESS_LOG1(LF_EH, LL_INFO100, "About to call filter with hCallerToken = %d\n",m_hCallerToken);
- // CLR_ImpersonateLoggedOnUser fails fast on error
- COMPrincipal::CLR_ImpersonateLoggedOnUser(m_hCallerToken);
- impersonating = TRUE;
- }
-#endif // !FEATURE_PAL
-
// We want to call filters even if the thread is aborting, so suppress abort
// checks while the filter runs.
ThreadPreventAsyncHolder preventAbort(TRUE);
GCX_COOP();
dwResult = CallHandler(dwFilterStartPC, sf, &EHClause, pMD, Filter ARM_ARG(pCurRegDisplay->pCallerContext) ARM64_ARG(pCurRegDisplay->pCallerContext));
}
-
-#ifndef FEATURE_PAL
- if (impersonating)
- {
- STRESS_LOG1(LF_EH, LL_INFO100, "After calling filter, resetting to hImpersonationToken = %d\n",m_hImpersonationToken);
- // CLR_ImpersonateLoggedOnUser fails fast on error
- COMPrincipal::CLR_ImpersonateLoggedOnUser(m_hImpersonationToken);
- impersonating = FALSE;
- }
-#endif // !FEATURE_PAL
}
EX_CATCH
{
// We had an exception in filter invocation that remained unhandled.
-#ifndef FEATURE_PAL
- if (impersonating)
- {
- STRESS_LOG1(LF_EH, LL_INFO100, "Filter threw exception. In Catch. Resetting to hImpersonationToken = %d\n",m_hImpersonationToken);
- // CLR_ImpersonateLoggedOnUser fails fast on error
- COMPrincipal::CLR_ImpersonateLoggedOnUser(m_hImpersonationToken);
- impersonating = FALSE;
- }
-#endif // !FEATURE_PAL
// Sync managed exception state, for the managed thread, based upon the active exception tracker.
pThread->SyncManagedExceptionState(false);
ExceptionTracker() :
m_pThread(NULL),
- m_hThrowable(NULL),
- m_hCallerToken(NULL),
- m_hImpersonationToken(NULL)
+ m_hThrowable(NULL)
{
#ifndef DACCESS_COMPILE
m_StackTraceInfo.Init();
// these members were added for resume frame processing
m_pClauseForCatchToken(NULL),
// end resume frame members
- m_ExceptionCode(pExceptionRecord->ExceptionCode),
- m_hCallerToken(NULL),
- m_hImpersonationToken(NULL)
+ m_ExceptionCode(pExceptionRecord->ExceptionCode)
{
m_ptrs.ExceptionRecord = pExceptionRecord;
m_ptrs.ContextRecord = pContextRecord;
DWORD m_ExceptionCode;
PTR_Frame m_pLimitFrame;
-
- // Thread Security State
- HANDLE m_hCallerToken;
- HANDLE m_hImpersonationToken;
#ifdef DEBUGGING_SUPPORTED
//
void SetDebuggerInterceptInfo() { LIMITED_METHOD_DAC_CONTRACT; AssertIfReadOnly(); m_flags |= Ex_DebuggerInterceptInfo; }
#endif
- BOOL ImpersonationTokenSet() { LIMITED_METHOD_CONTRACT; return m_flags & Ex_ImpersonationTokenSet; }
- void SetImpersonationTokenSet() { LIMITED_METHOD_CONTRACT; AssertIfReadOnly(); m_flags |= Ex_ImpersonationTokenSet; }
- void ResetImpersonationTokenSet() { LIMITED_METHOD_CONTRACT; AssertIfReadOnly(); m_flags &= ~Ex_ImpersonationTokenSet; }
-
BOOL WasThrownByUs() { LIMITED_METHOD_CONTRACT; return m_flags & Ex_WasThrownByUs; }
void SetWasThrownByUs() { LIMITED_METHOD_CONTRACT; AssertIfReadOnly(); m_flags |= Ex_WasThrownByUs; }
void ResetWasThrownByUs() { LIMITED_METHOD_CONTRACT; AssertIfReadOnly(); m_flags &= ~Ex_WasThrownByUs; }
Ex_DebuggerInterceptNotPossible = 0x00000400,
Ex_IsUnhandled = 0x00000800,
#endif
- Ex_ImpersonationTokenSet = 0x00001000,
+ // Unused = 0x00001000,
Ex_WasThrownByUs = 0x00002000,
CONTRACTL_END;
int iFilt = 0;
- BOOL impersonating = FALSE;
#ifndef FEATURE_PAL
EX_TRY
{
GCPROTECT_BEGIN (throwable);
- if (pData->hCallerToken != NULL)
- {
- STRESS_LOG1(LF_EH, LL_INFO100, "In COMPlusThrowCallbackHelper hCallerToken = %d\n",pData->hCallerToken);
- // CLR_ImpersonateLoggedOnUser fails fast on error
- COMPrincipal::CLR_ImpersonateLoggedOnUser(pData->hCallerToken);
- impersonating = TRUE;
- }
// We want to call filters even if the thread is aborting, so suppress abort
// checks while the filter runs.
BYTE* startAddress = (BYTE*)pCf->GetCodeInfo()->GetStartAddress();
iFilt = ::CallJitEHFilter(pCf, startAddress, EHClausePtr, nestingLevel, throwable);
- if (impersonating)
- {
- STRESS_LOG1(LF_EH, LL_INFO100, "In COMPlusThrowCallbackHelper hImpersonationToken = %d\n",pData->hImpersonationToken);
- // CLR_ImpersonateLoggedOnUser fails fast on error
- COMPrincipal::CLR_ImpersonateLoggedOnUser(pData->hImpersonationToken);
- impersonating = FALSE;
- }
GCPROTECT_END();
}
EX_CATCH
{
- if (impersonating)
- {
- STRESS_LOG1(LF_EH, LL_INFO100, "In COMPlusThrowCallbackHelper EX_CATCH hImpersonationToken = %d\n",pData->hImpersonationToken);
- // CLR_ImpersonateLoggedOnUser fails fast on error
- COMPrincipal::CLR_ImpersonateLoggedOnUser(pData->hImpersonationToken);
- impersonating = FALSE;
- }
-
// We had an exception in filter invocation that remained unhandled.
// Sync managed exception state, for the managed thread, based upon the active exception tracker.
pThread->SyncManagedExceptionState(false);
pData->bSkipLastElement = FALSE;
}
-#ifndef FEATURE_PAL
- // Check for any impersonation on the frame and save that for use during EH filter callbacks
- OBJECTREF* pRefSecDesc = pCf->GetAddrOfSecurityObject();
- if (pRefSecDesc != NULL && *pRefSecDesc != NULL)
- {
- FRAMESECDESCREF fsdRef = (FRAMESECDESCREF)*pRefSecDesc;
- if (fsdRef->GetCallerToken() != NULL)
- {
- // Impersonation info present on the Frame
- pData->hCallerToken = fsdRef->GetCallerToken();
- STRESS_LOG1(LF_EH, LL_INFO100, "In COMPlusThrowCallback. Found non-NULL callertoken on FSD:%d\n",pData->hCallerToken);
- if (!pData->bImpersonationTokenSet)
- {
- pData->hImpersonationToken = fsdRef->GetImpersonationToken();
- STRESS_LOG1(LF_EH, LL_INFO100, "In COMPlusThrowCallback. Found non-NULL impersonationtoken on FSD:%d\n",pData->hImpersonationToken);
- pData->bImpersonationTokenSet = TRUE;
- }
- }
- }
-#endif // !FEATURE_PAL
-
// now we've got the stack trace, if we aren't allowed to catch this and we're first pass, return
if (pData->bDontCatch)
return SWA_CONTINUE;
#include "customattribute.h"
#include "comdynamic.h"
#include "commethodrental.h"
-#ifndef FEATURE_LEGACYSURFACEAREA
#include "nlsinfo.h"
-#endif
#include "calendardata.h"
#include "commodule.h"
#include "marshalnative.h"
DEFINE_FIELD_U(m_DeclarativeAssertions, FrameSecurityDescriptorBaseObject, m_DeclarativeAssertions)
DEFINE_FIELD_U(m_DeclarativeDenials, FrameSecurityDescriptorBaseObject, m_DeclarativeDenials)
DEFINE_FIELD_U(m_DeclarativeRestrictions, FrameSecurityDescriptorBaseObject, m_DeclarativeRestrictions)
-#ifndef FEATURE_PAL
-DEFINE_FIELD_U(m_callerToken, FrameSecurityDescriptorBaseObject, m_callerToken)
-DEFINE_FIELD_U(m_impToken, FrameSecurityDescriptorBaseObject, m_impToken)
-#endif
DEFINE_CLASS(FRAME_SECURITY_DESCRIPTOR, Security, FrameSecurityDescriptor)
DEFINE_CLASS(GUID, System, Guid)
}
#endif // FEATURE_COMPRESSEDSTACK
-#ifndef FEATURE_PAL
-LPVOID FrameSecurityDescriptorBaseObject::GetCallerToken()
-{
- LIMITED_METHOD_CONTRACT;
- return ((m_callerToken!= NULL)?m_callerToken->GetHandle():NULL);
-
-}
-
-LPVOID FrameSecurityDescriptorBaseObject::GetImpersonationToken()
-{
- LIMITED_METHOD_CONTRACT;
- return ((m_impToken != NULL)?m_impToken->GetHandle():NULL);
-}
-#endif
-
SVAL_IMPL(INT32, ArrayBase, s_arrayBoundsZero);
// follow the necessary rules to get a new valid hashcode for an object
OBJECTREF m_DeclarativeAssertions;
OBJECTREF m_DeclarativeDenials;
OBJECTREF m_DeclarativeRestrictions;
-#ifndef FEATURE_PAL
- SAFEHANDLEREF m_callerToken; // the thread token (or process token if there was no thread token) when a call to Impersonate was made ("previous" token)
- SAFEHANDLEREF m_impToken; // the thread token after a call to Impersonate is made (the "current" impersonation)
-#endif // !FEATURE_PAL
CLR_BOOL m_assertFT;
CLR_BOOL m_assertAllPossible;
CLR_BOOL m_declSecComputed;
LIMITED_METHOD_CONTRACT;
m_declSecComputed = !!declSec;
}
-#ifndef FEATURE_PAL
- LPVOID GetCallerToken();
- LPVOID GetImpersonationToken();
-#endif // FEATURE_PAL
};
#ifdef FEATURE_COMPRESSEDSTACK