88 lines
2.9 KiB
C#
88 lines
2.9 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace System.Security.Principal
|
|
{
|
|
/// <summary>Represents the Windows user prior to an impersonation operation.</summary>
|
|
// 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;
|
|
}
|
|
|
|
/// <summary>Releases all resources used by the <see cref="T:System.Security.Principal.WindowsImpersonationContext" />.</summary>
|
|
// Token: 0x06003582 RID: 13698 RVA: 0x000B7A74 File Offset: 0x000B5C74
|
|
[ComVisible(false)]
|
|
public void Dispose()
|
|
{
|
|
if (!this.undo)
|
|
{
|
|
this.Undo();
|
|
}
|
|
}
|
|
|
|
/// <summary>Releases the unmanaged resources used by the <see cref="T:System.Security.Principal.WindowsImpersonationContext" /> and optionally releases the managed resources. </summary>
|
|
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources. </param>
|
|
// 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);
|
|
}
|
|
}
|
|
|
|
/// <summary>Reverts the user context to the Windows user represented by this object.</summary>
|
|
/// <exception cref="T:System.Security.SecurityException">An attempt is made to use this method for any purpose other than to revert identity to self. </exception>
|
|
// 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;
|
|
}
|
|
}
|