Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ToggleState()

unsafe void System.Security.AccessControl.Privilege.ToggleState ( bool enable)
inlineprivate

Definition at line 264 of file Privilege.cs.

265 {
266 int num = 0;
268 {
270 }
271 if (needToRevert)
272 {
274 }
275 try
276 {
278 if (tlsContents == null)
279 {
280 tlsContents = new TlsContents();
282 }
283 else
284 {
286 }
287 Unsafe.SkipInit(out global::Interop.Advapi32.TOKEN_PRIVILEGE tOKEN_PRIVILEGE);
288 tOKEN_PRIVILEGE.PrivilegeCount = 1u;
289 tOKEN_PRIVILEGE.Privileges.Luid = luid;
290 tOKEN_PRIVILEGE.Privileges.Attributes = (enable ? 2u : 0u);
291 global::Interop.Advapi32.TOKEN_PRIVILEGE tOKEN_PRIVILEGE2 = default(global::Interop.Advapi32.TOKEN_PRIVILEGE);
292 uint num2 = 0u;
293 if (!global::Interop.Advapi32.AdjustTokenPrivileges(tlsContents.ThreadHandle, DisableAllPrivileges: false, &tOKEN_PRIVILEGE, (uint)sizeof(global::Interop.Advapi32.TOKEN_PRIVILEGE), &tOKEN_PRIVILEGE2, &num2))
294 {
296 }
297 else if (1300 == Marshal.GetLastWin32Error())
298 {
299 num = 1300;
300 }
301 else
302 {
303 initialState = (tOKEN_PRIVILEGE2.Privileges.Attributes & 2) != 0;
304 stateWasChanged = initialState != enable;
305 needToRevert = tlsContents.IsImpersonating || stateWasChanged;
306 }
307 }
308 finally
309 {
310 if (!needToRevert)
311 {
312 Reset();
313 }
314 }
315 switch (num)
316 {
317 case 1300:
318 throw new PrivilegeNotHeldException(privileges[luid]);
319 case 8:
320 throw new OutOfMemoryException();
321 case 5:
322 case 1347:
323 throw new UnauthorizedAccessException();
324 default:
325 throw new InvalidOperationException();
326 case 0:
327 break;
328 }
329 }
static string InvalidOperation_MustBeSameThread
Definition SR.cs:84
static string InvalidOperation_MustRevertPrivilege
Definition SR.cs:90
Definition SR.cs:7
static readonly Dictionary< global::Interop.Advapi32.LUID, string > privileges
Definition Privilege.cs:170
global::Interop.Advapi32.LUID luid
Definition Privilege.cs:182
static Thread CurrentThread
Definition Thread.cs:312

References System.Threading.Thread.CurrentThread, System.Security.AccessControl.Privilege.currentThread, System.Runtime.InteropServices.Marshal.GetLastWin32Error(), System.Security.AccessControl.Privilege.TlsContents.IncrementReferenceCount(), System.Security.AccessControl.Privilege.initialState, System.SR.InvalidOperation_MustBeSameThread, System.SR.InvalidOperation_MustRevertPrivilege, System.Security.AccessControl.Privilege.luid, System.Security.AccessControl.Privilege.needToRevert, System.Security.AccessControl.Privilege.privileges, System.Security.AccessControl.Privilege.Reset(), System.Security.AccessControl.Privilege.stateWasChanged, System.Security.AccessControl.Privilege.t_tlsSlotData, System.Security.AccessControl.Privilege.TlsContents.ThreadHandle, and System.Security.AccessControl.Privilege.tlsContents.

Referenced by System.Security.AccessControl.Privilege.Enable().