Debian Codegraph @

mcs/class/referencesource/System/compmod/microsoft/win32/safehandles/SafeUserTokenHandle.cs

raw
1 // ==++==
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // ==--==
6 /*============================================================
7 **
8 ** Class: SafeUserTokenHandle
9 **
10 ** <EMAIL>Author: David Gutierrez (Microsoft) </EMAIL>
11 **
12 ** A wrapper for a user token handle
13 **
14 ** Date: July 8, 2002
15 **
16 ===========================================================*/
17
18 using System;
19 using System.Security;
20 using System.Security.Permissions;
21 using System.Runtime.InteropServices;
22 using System.Runtime.CompilerServices;
23 using Microsoft.Win32;
24 using Microsoft.Win32.SafeHandles;
25 using System.Runtime.ConstrainedExecution;
26 using System.Runtime.Versioning;
27
28 namespace Microsoft.Win32.SafeHandles {
29 [HostProtectionAttribute(MayLeakOnAbort = true)]
30 [SuppressUnmanagedCodeSecurityAttribute]
31 internal sealed class SafeUserTokenHandle : SafeHandleZeroOrMinusOneIsInvalid
32 {
33 // Note that OpenProcess returns 0 on failure.
34 internal SafeUserTokenHandle() : base (true) {}
35
36 internal SafeUserTokenHandle(IntPtr existingHandle, bool ownsHandle) : base(ownsHandle) {
37 SetHandle(existingHandle);
38 }
39
40 #if !FEATURE_PAL
41
42 [DllImport(ExternDll.Advapi32, CharSet=System.Runtime.InteropServices.CharSet.Auto, SetLastError=true, BestFitMapping=false)]
43 [ResourceExposure(ResourceScope.None)]
44 internal extern static bool DuplicateTokenEx(SafeHandle hToken, int access, NativeMethods.SECURITY_ATTRIBUTES tokenAttributes, int impersonationLevel, int tokenType, out SafeUserTokenHandle hNewToken);
45
46 #endif // !FEATURE_PAL
47
48 [DllImport(ExternDll.Kernel32, ExactSpelling=true, SetLastError=true)]
49 [ResourceExposure(ResourceScope.None)]
50 [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
51 private static extern bool CloseHandle(IntPtr handle);
52
53 override protected bool ReleaseHandle()
54 {
55 return CloseHandle(handle);
56 }
57 }
58 }
59
60
61
62
63