diff --git a/PInvoke/Security/AdvApi32/PSID.cs b/PInvoke/Security/AdvApi32/PSID.cs
index 03e845b1..9b8ce316 100644
--- a/PInvoke/Security/AdvApi32/PSID.cs
+++ b/PInvoke/Security/AdvApi32/PSID.cs
@@ -53,6 +53,10 @@ namespace Vanara.PInvoke
/// Initializes a new instance of the class.
private SafePSID() : base() { }
+ /// Gets a pointer to the SID_IDENTIFIER_AUTHORITY structure in this security identifier (SID).
+ /// A pointer to the SID_IDENTIFIER_AUTHORITY structure for this SID structure.
+ public PSID_IDENTIFIER_AUTHORITY Authority => GetSidIdentifierAuthority(this);
+
/// Gets the SID for the current user
/// The current user's SID.
public static SafePSID Current
@@ -78,6 +82,10 @@ namespace Vanara.PInvoke
/// The SID length, in bytes.
public int Length => IsValidSid ? GetLengthSid(this) : 0;
+ /// Enumerates the subauthorities in a security identifier (SID). The subauthority values are relative identifiers (RID).
+ /// A sequence of subauthorities.
+ public IEnumerable SubAuthorities => ((PSID)this).GetSubAuthorities();
+
/// Gets the string used to display in the debugger.
internal string DebugString
{
@@ -211,16 +219,13 @@ namespace Vanara.PInvoke
/// Determines whether the specified is equal to the current .
/// The object to compare with the current object.
/// true if the specified is equal to the current ; otherwise, false.
- public override bool Equals(object obj)
+ public override bool Equals(object obj) => obj switch
{
- if (obj is SafePSID psid2)
- return Equals(psid2);
- if (obj is PSID psidh)
- return Equals(psidh);
- if (obj is IntPtr ptr)
- return Equals(ptr);
- return false;
- }
+ SafePSID psid2 => Equals(psid2),
+ PSID psidh => Equals(psidh),
+ IntPtr ptr => Equals(ptr),
+ _ => false
+ };
/// Gets the binary form of this SafePSID.
/// An array of bytes containing the Sid.
@@ -383,6 +388,30 @@ namespace Vanara.PInvoke
/// if the SID structures are equal; otherwise.
public static bool Equals(this PSID psid1, PSID psid2) => AdvApi32.EqualSid(psid1, psid2);
+ ///
+ /// The GetAuthority function returns a pointer to the SID_IDENTIFIER_AUTHORITY structure in a specified security identifier (SID).
+ ///
+ ///
+ /// A pointer to the SID structure for which a pointer to the SID_IDENTIFIER_AUTHORITY structure is returned.
+ ///
+ /// This function does not handle SID structures that are not valid. Call the IsValidSid function to verify that the SID
+ /// structure is valid before you call this function.
+ ///
+ ///
+ ///
+ ///
+ /// If the function succeeds, the return value is a pointer to the SID_IDENTIFIER_AUTHORITY structure for the specified SID structure.
+ ///
+ ///
+ /// If the function fails, the return value is undefined. The function fails if the SID structure pointed to by the pSid parameter
+ /// is not valid. To get extended error information, call GetLastError.
+ ///
+ ///
+ ///
+ /// This function uses a 32-bit RID value. For applications that require a larger RID value, use CreateWellKnownSid and related functions.
+ ///
+ public static AdvApi32.PSID_IDENTIFIER_AUTHORITY GetAuthority(this PSID pSid) => AdvApi32.GetSidIdentifierAuthority(pSid);
+
/// Gets the binary form of the SID structure.
/// The SID structure pointer.
/// The binary form (byte array) of the SID structure.
@@ -399,6 +428,15 @@ namespace Vanara.PInvoke
return pDomSid;
}
+ /// Enumerates the subauthorities in a security identifier (SID). The subauthority values are relative identifiers (RID).
+ /// A pointer to the SID structure from which a pointer to a subauthority is to be returned.
+ /// A sequence of subauthorities.
+ public static IEnumerable GetSubAuthorities(this PSID pSid)
+ {
+ for (uint i = 0; i < AdvApi32.GetSidSubAuthorityCount(pSid); i++)
+ yield return AdvApi32.GetSidSubAuthority(pSid, i);
+ }
+
///
/// Validates a security identifier (SID) by verifying that the revision number is within a known range, and that the number of
/// subauthorities is less than the maximum.