using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Security.Principal { /// Allows code to check the Windows group membership of a Windows user. // Token: 0x020005BA RID: 1466 [ComVisible(true)] [Serializable] public class WindowsPrincipal : IPrincipal { /// Initializes a new instance of the class by using the specified object. /// The object from which to construct the new instance of . /// /// is null. // Token: 0x06003589 RID: 13705 RVA: 0x000B7AF0 File Offset: 0x000B5CF0 public WindowsPrincipal(WindowsIdentity ntIdentity) { if (ntIdentity == null) { throw new ArgumentNullException("ntIdentity"); } this._identity = ntIdentity; } /// Gets the identity of the current principal. /// The object of the current principal. // Token: 0x17000A83 RID: 2691 // (get) Token: 0x0600358A RID: 13706 RVA: 0x000B7B10 File Offset: 0x000B5D10 public virtual IIdentity Identity { get { return this._identity; } } /// Determines whether the current principal belongs to the Windows user group with the specified relative identifier (RID). /// true if the current principal is a member of the specified Windows user group, that is, in a particular role; otherwise, false. /// The RID of the Windows user group in which to check for the principal’s membership status. /// /// /// // Token: 0x0600358B RID: 13707 RVA: 0x000B7B18 File Offset: 0x000B5D18 public virtual bool IsInRole(int rid) { if (WindowsPrincipal.IsPosix) { return WindowsPrincipal.IsMemberOfGroupId(this.Token, (IntPtr)rid); } string text; switch (rid) { case 544: text = "BUILTIN\\Administrators"; break; case 545: text = "BUILTIN\\Users"; break; case 546: text = "BUILTIN\\Guests"; break; case 547: text = "BUILTIN\\Power Users"; break; case 548: text = "BUILTIN\\Account Operators"; break; case 549: text = "BUILTIN\\System Operators"; break; case 550: text = "BUILTIN\\Print Operators"; break; case 551: text = "BUILTIN\\Backup Operators"; break; case 552: text = "BUILTIN\\Replicator"; break; default: return false; } return this.IsInRole(text); } /// Determines whether the current principal belongs to the Windows user group with the specified name. /// true if the current principal is a member of the specified Windows user group; otherwise, false. /// The name of the Windows user group for which to check membership. /// /// /// // Token: 0x0600358C RID: 13708 RVA: 0x000B7BE8 File Offset: 0x000B5DE8 public virtual bool IsInRole(string role) { if (role == null) { return false; } if (WindowsPrincipal.IsPosix) { return WindowsPrincipal.IsMemberOfGroupName(this.Token, role); } if (this.m_roles == null) { this.m_roles = WindowsIdentity._GetRoles(this.Token); } role = role.ToUpperInvariant(); foreach (string text in this.m_roles) { if (text != null && role == text.ToUpperInvariant()) { return true; } } return false; } /// Determines whether the current principal belongs to the Windows user group with the specified . /// true if the current principal is a member of the specified Windows user group; otherwise, false. /// One of the values. /// /// is not a valid value. /// /// /// // Token: 0x0600358D RID: 13709 RVA: 0x000B7C74 File Offset: 0x000B5E74 public virtual bool IsInRole(WindowsBuiltInRole role) { if (!WindowsPrincipal.IsPosix) { return this.IsInRole((int)role); } if (role != WindowsBuiltInRole.Administrator) { return false; } string text = "root"; return this.IsInRole(text); } /// Determines whether the current principal belongs to the Windows user group with the specified security identifier (SID). /// true if the current principal is a member of the specified Windows user group; otherwise, false. /// A that uniquely identifies a Windows user group. /// /// is null. /// Windows returned a Win32 error. /// /// /// // Token: 0x0600358E RID: 13710 RVA: 0x000B7CBC File Offset: 0x000B5EBC [MonoTODO("not implemented")] [ComVisible(false)] public virtual bool IsInRole(SecurityIdentifier sid) { throw new NotImplementedException(); } // Token: 0x17000A84 RID: 2692 // (get) Token: 0x0600358F RID: 13711 RVA: 0x000B7CC4 File Offset: 0x000B5EC4 private static bool IsPosix { get { int platform = (int)Environment.Platform; return platform == 128 || platform == 4 || platform == 6; } } // Token: 0x17000A85 RID: 2693 // (get) Token: 0x06003590 RID: 13712 RVA: 0x000B7CF0 File Offset: 0x000B5EF0 private IntPtr Token { get { return this._identity.Token; } } // Token: 0x06003591 RID: 13713 [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool IsMemberOfGroupId(IntPtr user, IntPtr group); // Token: 0x06003592 RID: 13714 [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool IsMemberOfGroupName(IntPtr user, string group); // Token: 0x04001607 RID: 5639 private WindowsIdentity _identity; // Token: 0x04001608 RID: 5640 private string[] m_roles; } }