Sid

Struct Sid 

Source
#[repr(C)]
pub struct Sid { /* private fields */ }
Expand description

A SID (Security Identifier) that can be used with Windows API calls.

Implementations§

Source§

impl Sid

Source

pub fn new(id_auth: [u8; 6], sub_auths: &[u32]) -> Result<LocalBox<Sid>>

Create a new SID from raw parts

use windows_permissions::Sid;

let sid_8 = Sid::new([1, 2, 3, 4, 5, 6], &[1, 2, 3, 4, 5, 6, 7, 8]).unwrap();

assert_eq!(sid_8.id_authority(), &[1, 2, 3, 4, 5, 6]);
assert_eq!(sid_8.sub_authority_count(), 8);
assert_eq!(sid_8.sub_authorities(), &[1, 2, 3, 4, 5, 6, 7, 8]);

No more than 8 sub-authorities can be made using this function. If more are needed, you can parse SDDL or use a wrapper function directly.

use windows_permissions::Sid;

assert!(Sid::new([1, 2, 3, 4, 5, 6], &[1, 2, 3, 4, 5, 6, 7, 8]).is_ok());
assert!(Sid::new([1, 2, 3, 4, 5, 6], &[1, 2, 3, 4, 5, 6, 7, 8, 9]).is_err());
Source

pub fn well_known_sid(well_known_sid_type: u32) -> Result<LocalBox<Sid>>

Create a new well-known SID

This is equivalent to calling wrappers::CreateWellKnownSid with None as the domain.

use windows_permissions::{Sid, LocalBox};
use winapi::um::winnt::WinWorldSid;

let win_world_sid = Sid::well_known_sid(WinWorldSid).unwrap();
let another_sid = "S-1-1-0".parse().unwrap();

assert_eq!(win_world_sid, another_sid);
Source

pub fn sub_authority_count(&self) -> u8

Get the number of sub-authorities in the SID

use windows_permissions::{Sid, LocalBox};

let sid1: LocalBox<Sid> = "S-1-5-1".parse().unwrap();
let sid2: LocalBox<Sid> = "S-1-5-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15".parse().unwrap();

assert_eq!(sid1.sub_authority_count(), 1);
assert_eq!(sid2.sub_authority_count(), 15);
Source

pub fn id_authority(&self) -> &[u8; 6]

Get the ID authority of the SID

use windows_permissions::{Sid, LocalBox};

let sid1: LocalBox<Sid> = "S-1-5-12-62341".parse().unwrap();
let sid2: LocalBox<Sid> = "S-1-211111900160837-1".parse().unwrap();

assert_eq!(sid1.id_authority(), &[0, 0, 0, 0, 0, 5]);
assert_eq!(sid2.id_authority(), &[0xC0, 0x01, 0x51, 0xD1, 0x23, 0x45]);
Source

pub fn sub_authority(&self, index: u8) -> Option<u32>

Get a sub-authority of the SID if it is available

Returns None if the SID has too few sub-authorities.

use windows_permissions::{Sid, LocalBox};

let sid: LocalBox<Sid> = "S-1-5-12-62341".parse().unwrap();

assert_eq!(sid.sub_authority(0), Some(12));
assert_eq!(sid.sub_authority(1), Some(62341));
assert_eq!(sid.sub_authority(2), None);
Source

pub fn sub_authorities(&self) -> Vec<u32>

Generate a list of the sub-authorities in the SID

Changes in the returned Vec are not reflected in the SID

Source

pub fn id_auth_to_number(id_auth: [u8; 6]) -> u64

Get the numeric value of an ID authority

use windows_permissions::Sid;

assert_eq!(
    Sid::id_auth_to_number([0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC]),
    0x123456789ABCu64
);

Trait Implementations§

Source§

impl Debug for Sid

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Sid

Source§

fn fmt(&self, fmt: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'s> From<&'s Sid> for Trustee<'s>

Source§

fn from(sid: &'s Sid) -> Self

Converts to this type from the input type.
Source§

impl Hash for Sid

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Sid

Source§

fn eq(&self, other: &Sid) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Sid

Auto Trait Implementations§

§

impl Freeze for Sid

§

impl RefUnwindSafe for Sid

§

impl Send for Sid

§

impl Sync for Sid

§

impl Unpin for Sid

§

impl UnwindSafe for Sid

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.