using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Security.Principal { /// Represents the Windows user prior to an impersonation operation. // Token: 0x020005B9 RID: 1465 [ComVisible(true)] public class WindowsImpersonationContext : IDisposable { // Token: 0x06003581 RID: 13697 RVA: 0x000B7A40 File Offset: 0x000B5C40 internal WindowsImpersonationContext(IntPtr token) { this._token = WindowsImpersonationContext.DuplicateToken(token); if (!WindowsImpersonationContext.SetCurrentToken(token)) { throw new SecurityException("Couldn't impersonate token."); } this.undo = false; } /// Releases all resources used by the . // Token: 0x06003582 RID: 13698 RVA: 0x000B7A74 File Offset: 0x000B5C74 [ComVisible(false)] public void Dispose() { if (!this.undo) { this.Undo(); } } /// Releases the unmanaged resources used by the and optionally releases the managed resources. /// true to release both managed and unmanaged resources; false to release only unmanaged resources. // Token: 0x06003583 RID: 13699 RVA: 0x000B7A88 File Offset: 0x000B5C88 [ComVisible(false)] protected virtual void Dispose(bool disposing) { if (!this.undo) { this.Undo(); } if (disposing) { GC.SuppressFinalize(this); } } /// Reverts the user context to the Windows user represented by this object. /// An attempt is made to use this method for any purpose other than to revert identity to self. // Token: 0x06003584 RID: 13700 RVA: 0x000B7AA8 File Offset: 0x000B5CA8 public void Undo() { if (!WindowsImpersonationContext.RevertToSelf()) { WindowsImpersonationContext.CloseToken(this._token); throw new SecurityException("Couldn't switch back to original token."); } WindowsImpersonationContext.CloseToken(this._token); this.undo = true; GC.SuppressFinalize(this); } // Token: 0x06003585 RID: 13701 [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool CloseToken(IntPtr token); // Token: 0x06003586 RID: 13702 [MethodImpl(MethodImplOptions.InternalCall)] private static extern IntPtr DuplicateToken(IntPtr token); // Token: 0x06003587 RID: 13703 [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool SetCurrentToken(IntPtr token); // Token: 0x06003588 RID: 13704 [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool RevertToSelf(); // Token: 0x04001605 RID: 5637 private IntPtr _token; // Token: 0x04001606 RID: 5638 private bool undo; } }