pub struct Sid { /* private fields */ }Expand description
A borrowed SID.
Sid is byte-compatible with the Windows SID structure but represented as
a dynamically sized type. It is normally obtained by dereferencing a
SidBuf or, when borrowing memory owned elsewhere, by calling
Sid::from_psid.
Use ToOwned::to_owned to copy a borrowed SID into a SidBuf.
Implementations§
Source§impl Sid
impl Sid
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns the logical SID as raw bytes.
The slice contains the eight-byte header followed by four bytes for each
sub-authority. Spare capacity in a SidBuf::with_capacity allocation
is not included.
Sourcepub unsafe fn as_psid(&self) -> PSID
Available on crate feature windows-full only.
pub unsafe fn as_psid(&self) -> PSID
windows-full only.Returns a PSID pointing at this SID for use with Windows APIs.
§Safety
The returned pointer is borrowed from self and must not outlive it.
Although PSID contains a mutable pointer, the pointee must not be
mutated through this shared reference.
Sourcepub fn as_ptr(&self) -> *const c_void
pub fn as_ptr(&self) -> *const c_void
Returns a raw pointer to this SID for use with Windows APIs.
The pointer remains valid only while self is alive and has not been
mutably borrowed. The called API must not mutate the SID through it.
Sourcepub unsafe fn from_psid<'a>(psid: impl AsSidPtr) -> Result<&'a Sid>
pub unsafe fn from_psid<'a>(psid: impl AsSidPtr) -> Result<&'a Sid>
Borrow a raw PSID as &'a Sid, validating its structure.
Returns ERROR_INVALID_SID if psid is not a valid SID.
§Safety
psid must point to a readable SID that stays valid for 'a. It must also be 4-byte
aligned since the words are borrowed as &[u32]. The sub-authority count must be accurate
to prevent out-of-bounds reads. Every SID Windows hands out is already aligned with a correct
count.
§Errors
Returns ERROR_INVALID_SID if the revision or sub-authority count is
outside the range allowed by Windows.
Sourcepub fn revision(&self) -> u8
pub fn revision(&self) -> u8
Returns the SID revision.
Valid Windows SIDs currently have revision 1.
Returns the number of sub-authorities recorded in the SID header.
Returns the 48-bit identifier authority as an integer.
Returns the sub-authority at idx, or None if it is out of bounds.
Returns all of the SID’s sub-authorities.
Sourcepub fn equal_prefix(&self, other: &Sid) -> bool
pub fn equal_prefix(&self, other: &Sid) -> bool
Tests whether this SID and other have equal prefixes.
A SID prefix contains the revision, identifier authority, sub-authority count, and every sub-authority except the last.
Sourcepub fn equal_domain(&self, other: &Sid) -> Result<bool>
pub fn equal_domain(&self, other: &Sid) -> Result<bool>
Determines whether this SID and other belong to the same Windows account domain.
Calls the Windows EqualDomainSid function.
Both SIDs must be account-domain SIDs or BUILTIN SIDs.
§Errors
Returns the error reported by EqualDomainSid.
Sourcepub fn account_domain_sid(&self) -> Result<SidBuf>
pub fn account_domain_sid(&self) -> Result<SidBuf>
Returns the Windows account-domain SID containing this SID.
Calls the Windows GetWindowsAccountDomainSid function.
§Errors
Returns the error reported by GetWindowsAccountDomainSid.
Sourcepub fn is_well_known(&self, well_known_type: impl AsWellKnownSidType) -> bool
pub fn is_well_known(&self, well_known_type: impl AsWellKnownSidType) -> bool
Tests whether this SID has the specified well-known SID type.
Calls the Windows IsWellKnownSid function.