Skip to main content

Token

Struct Token 

Source
pub struct Token(/* private fields */);
Expand description

Strongly-typed RAII guard holding an open process or thread token handle.

Implementations§

Source§

impl Token

Source

pub fn current() -> Result<Self, ElevateError>

Open the token belonging to the current application process.

Source

pub fn from_pid(pid: u32) -> Result<Self, ElevateError>

Open the security token belonging to an arbitrary running process by PID.

Source

pub const fn as_raw(&self) -> HANDLE

Borrow the underlying raw Win32 HANDLE.

Source

pub fn duplicate(&self, token_type: TokenType) -> Result<Self, ElevateError>

Duplicate this token as either a Primary or Impersonation token.

Source

pub fn enable_privileges( &self, privileges: &[Privilege], ) -> Result<(), ElevateError>

Enable the specified administrative privileges on this token.

Source

pub fn session_id(&self) -> Result<u32, ElevateError>

Query the Windows Session ID currently associated with this token.

Source

pub fn set_session_id(&self, session_id: u32) -> Result<(), ElevateError>

Explicitly assign a Windows Session ID to this token.

Source

pub fn impersonate(&self) -> Result<ImpersonationGuard, ElevateError>

Impersonate this token on the current thread, returning an RAII revert guard.

Source

pub fn user_sid(&self) -> Result<String, ElevateError>

Retrieve the owner user SID string of this token.

Source

pub fn has_sid(&self, target_sid: PCWSTR) -> Result<bool, ElevateError>

Check whether this token holds membership in the specified string SID.

Trait Implementations§

Source§

impl Drop for Token

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !Send for Token

§

impl !Sync for Token

§

impl Freeze for Token

§

impl RefUnwindSafe for Token

§

impl Unpin for Token

§

impl UnsafeUnpin for Token

§

impl UnwindSafe for Token

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.