blob: 460d619947ded8e1b8f1ede18192a6213689068f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
// <OWNER>Microsoft</OWNER>
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
[SecurityCritical]
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
{
[SecurityCritical]
get { return new SafeAccessTokenHandle(IntPtr.Zero); }
}
public override bool IsInvalid
{
[SecurityCritical]
get { return handle == IntPtr.Zero || handle == new IntPtr(-1); }
}
[SecurityCritical]
protected override bool ReleaseHandle()
{
return Win32Native.CloseHandle(handle);
}
}
#if !FEATURE_PAL
[System.Security.SecurityCritical] // auto-generated
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); }
}
[System.Security.SecurityCritical]
override protected bool ReleaseHandle()
{
// LsaDeregisterLogonProcess returns an NTSTATUS
return Win32Native.LsaDeregisterLogonProcess(handle) >= 0;
}
}
[System.Security.SecurityCritical] // auto-generated
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 ); }
}
[System.Security.SecurityCritical]
override protected bool ReleaseHandle()
{
return Win32Native.LsaFreeMemory(handle) == 0;
}
}
[System.Security.SecurityCritical] // auto-generated
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 ); }
}
[System.Security.SecurityCritical]
override protected bool ReleaseHandle()
{
return Win32Native.LsaClose(handle) == 0;
}
}
[System.Security.SecurityCritical] // auto-generated
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); }
}
[System.Security.SecurityCritical]
override protected bool ReleaseHandle()
{
// LsaFreeReturnBuffer returns an NTSTATUS
return Win32Native.LsaFreeReturnBuffer(handle) >= 0;
}
}
[System.Security.SecurityCritical] // auto-generated
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); }
}
[System.Security.SecurityCritical]
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
override protected bool ReleaseHandle()
{
return Win32Native.CloseHandle(handle);
}
}
[System.Security.SecurityCritical] // auto-generated
internal sealed class SafeThreadHandle : SafeHandleZeroOrMinusOneIsInvalid {
private SafeThreadHandle() : base (true) {}
// 0 is an Invalid Handle
internal SafeThreadHandle(IntPtr handle) : base (true) {
SetHandle(handle);
}
[System.Security.SecurityCritical]
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
override protected bool ReleaseHandle()
{
return Win32Native.CloseHandle(handle);
}
}
#endif // !FEATURE_PAL
}
|