using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; namespace System.Security.Principal { /// Represents a Windows user. // Token: 0x020005B8 RID: 1464 [ComVisible(true)] [Serializable] public class WindowsIdentity : IDisposable, ISerializable, IDeserializationCallback, IIdentity { /// Initializes a new instance of the class for the user represented by the specified Windows account token. /// The account token for the user on whose behalf the code is running. /// /// is 0.-or- is duplicated and invalid for impersonation. /// The caller does not have the correct permissions. -or-A Win32 error occurred. // Token: 0x0600355E RID: 13662 RVA: 0x000B75C8 File Offset: 0x000B57C8 public WindowsIdentity(IntPtr userToken) : this(userToken, null, WindowsAccountType.Normal, false) { } /// Initializes a new instance of the class for the user represented by the specified Windows account token and the specified authentication type. /// The account token for the user on whose behalf the code is running. /// (Informational) The type of authentication used to identify the user. For more information, see Remarks. /// /// is 0.-or- is duplicated and invalid for impersonation. /// The caller does not have the correct permissions. -or-A Win32 error occurred. // Token: 0x0600355F RID: 13663 RVA: 0x000B75D4 File Offset: 0x000B57D4 public WindowsIdentity(IntPtr userToken, string type) : this(userToken, type, WindowsAccountType.Normal, false) { } /// Initializes a new instance of the class for the user represented by the specified Windows account token, the specified authentication type, and the specified Windows account type. /// The account token for the user on whose behalf the code is running. /// (Informational) The type of authentication used to identify the user. For more information, see Remarks. /// One of the values. /// /// is 0.-or- is duplicated and invalid for impersonation. /// The caller does not have the correct permissions. -or-A Win32 error occurred. // Token: 0x06003560 RID: 13664 RVA: 0x000B75E0 File Offset: 0x000B57E0 public WindowsIdentity(IntPtr userToken, string type, WindowsAccountType acctType) : this(userToken, type, acctType, false) { } /// Initializes a new instance of the class for the user represented by the specified Windows account token, the specified authentication type, the specified Windows account type, and the specified authentication status. /// The account token for the user on whose behalf the code is running. /// (Informational) The type of authentication used to identify the user. For more information, see Remarks. /// One of the values. /// true to indicate that the user is authenticated; otherwise, false. /// /// is 0.-or- is duplicated and invalid for impersonation. /// The caller does not have the correct permissions. -or-A Win32 error occurred. // Token: 0x06003561 RID: 13665 RVA: 0x000B75EC File Offset: 0x000B57EC public WindowsIdentity(IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated) { this._type = type; this._account = acctType; this._authenticated = isAuthenticated; this._name = null; this.SetToken(userToken); } /// Initializes a new instance of the class for the user represented by the specified User Principal Name (UPN). /// The UPN for the user on whose behalf the code is running. /// Windows returned the Windows NT status code STATUS_ACCESS_DENIED. /// There is insufficient memory available. /// The caller does not have the correct permissions. // Token: 0x06003562 RID: 13666 RVA: 0x000B7624 File Offset: 0x000B5824 public WindowsIdentity(string sUserPrincipalName) : this(sUserPrincipalName, null) { } /// Initializes a new instance of the class for the user represented by the specified User Principal Name (UPN) and the specified authentication type. /// The UPN for the user on whose behalf the code is running. /// (Informational) The type of authentication used to identify the user. /// Windows returned the Windows NT status code STATUS_ACCESS_DENIED. /// There is insufficient memory available. /// The caller does not have the correct permissions. // Token: 0x06003563 RID: 13667 RVA: 0x000B7630 File Offset: 0x000B5830 public WindowsIdentity(string sUserPrincipalName, string type) { if (sUserPrincipalName == null) { throw new NullReferenceException("sUserPrincipalName"); } IntPtr userToken = WindowsIdentity.GetUserToken(sUserPrincipalName); if (!WindowsIdentity.IsPosix && userToken == IntPtr.Zero) { throw new ArgumentException("only for Windows Server 2003 +"); } this._authenticated = true; this._account = WindowsAccountType.Normal; this._type = type; this.SetToken(userToken); } /// Initializes a new instance of the class for the user represented by information in a stream. /// The containing the account information for the user. /// A that indicates the stream characteristics. /// A cannot be serialized across processes. /// The caller does not have the correct permissions. -or-A Win32 error occurred. // Token: 0x06003564 RID: 13668 RVA: 0x000B769C File Offset: 0x000B589C public WindowsIdentity(SerializationInfo info, StreamingContext context) { this._info = info; } /// Implements the interface and is called back by the deserialization event when deserialization is complete. /// The source of the deserialization event. // Token: 0x06003566 RID: 13670 RVA: 0x000B76B8 File Offset: 0x000B58B8 void IDeserializationCallback.OnDeserialization(object sender) { this._token = (IntPtr)this._info.GetValue("m_userToken", typeof(IntPtr)); this._name = this._info.GetString("m_name"); if (this._name != null) { string tokenName = WindowsIdentity.GetTokenName(this._token); if (tokenName != this._name) { throw new SerializationException("Token-Name mismatch."); } } else { this._name = WindowsIdentity.GetTokenName(this._token); if (this._name == string.Empty || this._name == null) { throw new SerializationException("Token doesn't match a user."); } } this._type = this._info.GetString("m_type"); this._account = (WindowsAccountType)((int)this._info.GetValue("m_acctType", typeof(WindowsAccountType))); this._authenticated = this._info.GetBoolean("m_isAuthenticated"); } /// Sets the object with the logical context information needed to recreate an instance of this execution context. /// A object containing the information required to serialize the . /// A object containing the source and destination of the serialized stream associated with the . // Token: 0x06003567 RID: 13671 RVA: 0x000B77C8 File Offset: 0x000B59C8 void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { info.AddValue("m_userToken", this._token); info.AddValue("m_name", this._name); info.AddValue("m_type", this._type); info.AddValue("m_acctType", this._account); info.AddValue("m_isAuthenticated", this._authenticated); } /// Releases all resources used by the . // Token: 0x06003568 RID: 13672 RVA: 0x000B7834 File Offset: 0x000B5A34 [ComVisible(false)] public void Dispose() { this._token = IntPtr.Zero; } /// 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: 0x06003569 RID: 13673 RVA: 0x000B7844 File Offset: 0x000B5A44 [ComVisible(false)] protected virtual void Dispose(bool disposing) { this._token = IntPtr.Zero; } /// Returns a object that represents an anonymous user. /// A object that represents an anonymous user. // Token: 0x0600356A RID: 13674 RVA: 0x000B7854 File Offset: 0x000B5A54 public static WindowsIdentity GetAnonymous() { WindowsIdentity windowsIdentity; if (WindowsIdentity.IsPosix) { windowsIdentity = new WindowsIdentity("nobody"); windowsIdentity._account = WindowsAccountType.Anonymous; windowsIdentity._authenticated = false; windowsIdentity._type = string.Empty; } else { windowsIdentity = new WindowsIdentity(IntPtr.Zero, string.Empty, WindowsAccountType.Anonymous, false); windowsIdentity._name = string.Empty; } return windowsIdentity; } /// Returns a object that represents the current Windows user. /// A object that represents the current user. /// The caller does not have the correct permissions. /// /// /// // Token: 0x0600356B RID: 13675 RVA: 0x000B78B4 File Offset: 0x000B5AB4 public static WindowsIdentity GetCurrent() { return new WindowsIdentity(WindowsIdentity.GetCurrentToken(), null, WindowsAccountType.Normal, true); } /// Returns a object that represents the Windows identity for either the thread or the process, depending on the value of the parameter. /// A object that represents a Windows user. /// true to return the only if the thread is currently impersonating; false to return the of the thread if it is impersonating or the of the process if the thread is not currently impersonating. /// /// /// // Token: 0x0600356C RID: 13676 RVA: 0x000B78C4 File Offset: 0x000B5AC4 [MonoTODO("need icall changes")] public static WindowsIdentity GetCurrent(bool ifImpersonating) { throw new NotImplementedException(); } /// Returns a object that represents the current Windows user, using the specified desired token access level. /// A object that represents the current user. /// A bitwise combination of the values. /// /// /// // Token: 0x0600356D RID: 13677 RVA: 0x000B78CC File Offset: 0x000B5ACC [MonoTODO("need icall changes")] public static WindowsIdentity GetCurrent(TokenAccessLevels desiredAccess) { throw new NotImplementedException(); } /// Impersonates the user represented by the object. /// A object that represents the Windows user prior to impersonation; this can be used to revert to the original user's context. /// An anonymous identity attempted to perform an impersonation. /// A Win32 error occurred. /// /// /// // Token: 0x0600356E RID: 13678 RVA: 0x000B78D4 File Offset: 0x000B5AD4 public virtual WindowsImpersonationContext Impersonate() { return new WindowsImpersonationContext(this._token); } /// Impersonates the user represented by the specified user token. /// A object that represents the Windows user prior to impersonation; this object can be used to revert to the original user's context. /// The handle of a Windows account token. This token is usually retrieved through a call to unmanaged code, such as a call to the Win32 API LogonUser function. /// Windows returned the Windows NT status code STATUS_ACCESS_DENIED. /// There is insufficient memory available. /// The caller does not have the correct permissions. /// /// /// // Token: 0x0600356F RID: 13679 RVA: 0x000B78E4 File Offset: 0x000B5AE4 public static WindowsImpersonationContext Impersonate(IntPtr userToken) { return new WindowsImpersonationContext(userToken); } /// Gets the type of authentication used to identify the user. /// The type of authentication used to identify the user. // Token: 0x17000A77 RID: 2679 // (get) Token: 0x06003570 RID: 13680 RVA: 0x000B78EC File Offset: 0x000B5AEC public string AuthenticationType { get { return this._type; } } /// Gets a value indicating whether the user account is identified as an anonymous account by the system. /// true if the user account is an anonymous account; otherwise, false. // Token: 0x17000A78 RID: 2680 // (get) Token: 0x06003571 RID: 13681 RVA: 0x000B78F4 File Offset: 0x000B5AF4 public virtual bool IsAnonymous { get { return this._account == WindowsAccountType.Anonymous; } } /// Gets a value indicating whether the user has been authenticated by Windows. /// true if the user was authenticated; otherwise, false. // Token: 0x17000A79 RID: 2681 // (get) Token: 0x06003572 RID: 13682 RVA: 0x000B7900 File Offset: 0x000B5B00 public virtual bool IsAuthenticated { get { return this._authenticated; } } /// Gets a value indicating whether the user account is identified as a account by the system. /// true if the user account is a account; otherwise, false. // Token: 0x17000A7A RID: 2682 // (get) Token: 0x06003573 RID: 13683 RVA: 0x000B7908 File Offset: 0x000B5B08 public virtual bool IsGuest { get { return this._account == WindowsAccountType.Guest; } } /// Gets a value indicating whether the user account is identified as a account by the system. /// true if the user account is a account; otherwise, false. // Token: 0x17000A7B RID: 2683 // (get) Token: 0x06003574 RID: 13684 RVA: 0x000B7914 File Offset: 0x000B5B14 public virtual bool IsSystem { get { return this._account == WindowsAccountType.System; } } /// Gets the user's Windows logon name. /// The Windows logon name of the user on whose behalf the code is being run. // Token: 0x17000A7C RID: 2684 // (get) Token: 0x06003575 RID: 13685 RVA: 0x000B7920 File Offset: 0x000B5B20 public virtual string Name { get { if (this._name == null) { this._name = WindowsIdentity.GetTokenName(this._token); } return this._name; } } /// Gets the Windows account token for the user. /// The handle of the access token associated with the current execution thread. // Token: 0x17000A7D RID: 2685 // (get) Token: 0x06003576 RID: 13686 RVA: 0x000B7950 File Offset: 0x000B5B50 public virtual IntPtr Token { get { return this._token; } } /// Gets the groups the current Windows user belongs to. /// An object representing the groups the current Windows user belongs to. // Token: 0x17000A7E RID: 2686 // (get) Token: 0x06003577 RID: 13687 RVA: 0x000B7958 File Offset: 0x000B5B58 [MonoTODO("not implemented")] public IdentityReferenceCollection Groups { get { throw new NotImplementedException(); } } /// Gets the impersonation level for the user. /// One of the values. // Token: 0x17000A7F RID: 2687 // (get) Token: 0x06003578 RID: 13688 RVA: 0x000B7960 File Offset: 0x000B5B60 [ComVisible(false)] [MonoTODO("not implemented")] public TokenImpersonationLevel ImpersonationLevel { get { throw new NotImplementedException(); } } /// Gets the security identifier (SID) for the token owner. /// A object for the token owner. // Token: 0x17000A80 RID: 2688 // (get) Token: 0x06003579 RID: 13689 RVA: 0x000B7968 File Offset: 0x000B5B68 [ComVisible(false)] [MonoTODO("not implemented")] public SecurityIdentifier Owner { get { throw new NotImplementedException(); } } /// Gets the security identifier (SID) for the user. /// A object for the user. // Token: 0x17000A81 RID: 2689 // (get) Token: 0x0600357A RID: 13690 RVA: 0x000B7970 File Offset: 0x000B5B70 [ComVisible(false)] [MonoTODO("not implemented")] public SecurityIdentifier User { get { throw new NotImplementedException(); } } // Token: 0x17000A82 RID: 2690 // (get) Token: 0x0600357B RID: 13691 RVA: 0x000B7978 File Offset: 0x000B5B78 private static bool IsPosix { get { int platform = (int)Environment.Platform; return platform == 128 || platform == 4 || platform == 6; } } // Token: 0x0600357C RID: 13692 RVA: 0x000B79A4 File Offset: 0x000B5BA4 private void SetToken(IntPtr token) { if (WindowsIdentity.IsPosix) { this._token = token; if (this._type == null) { this._type = "POSIX"; } if (this._token == IntPtr.Zero) { this._account = WindowsAccountType.System; } } else { if (token == WindowsIdentity.invalidWindows && this._account != WindowsAccountType.Anonymous) { throw new ArgumentException("Invalid token"); } this._token = token; if (this._type == null) { this._type = "NTLM"; } } } // Token: 0x0600357D RID: 13693 [MethodImpl(MethodImplOptions.InternalCall)] internal static extern string[] _GetRoles(IntPtr token); // Token: 0x0600357E RID: 13694 [MethodImpl(MethodImplOptions.InternalCall)] internal static extern IntPtr GetCurrentToken(); // Token: 0x0600357F RID: 13695 [MethodImpl(MethodImplOptions.InternalCall)] private static extern string GetTokenName(IntPtr token); // Token: 0x06003580 RID: 13696 [MethodImpl(MethodImplOptions.InternalCall)] private static extern IntPtr GetUserToken(string username); // Token: 0x040015FE RID: 5630 private IntPtr _token; // Token: 0x040015FF RID: 5631 private string _type; // Token: 0x04001600 RID: 5632 private WindowsAccountType _account; // Token: 0x04001601 RID: 5633 private bool _authenticated; // Token: 0x04001602 RID: 5634 private string _name; // Token: 0x04001603 RID: 5635 private SerializationInfo _info; // Token: 0x04001604 RID: 5636 private static IntPtr invalidWindows = IntPtr.Zero; } }