Trait winsafe::prelude::kernel_Haccesstoken

source ·
pub trait kernel_Haccesstoken: Handle {
    // Provided methods
    fn AdjustTokenPrivileges(&self, new_state: DisabPriv<'_>) -> SysResult<()> { ... }
    fn CheckTokenCapability(
        &self,
        capability_sid_to_check: &SID
    ) -> SysResult<bool> { ... }
    fn CheckTokenMembership(&self, sid_to_check: &SID) -> SysResult<bool> { ... }
    fn DuplicateToken(
        &self,
        level: SECURITY_IMPERSONATION
    ) -> SysResult<CloseHandleGuard<HACCESSTOKEN>> { ... }
    fn GetCurrentProcessToken() -> HACCESSTOKEN { ... }
    fn GetCurrentThreadEffectiveToken() -> HACCESSTOKEN { ... }
    fn GetTokenInformation(
        &self,
        information_class: TOKEN_INFORMATION_CLASS
    ) -> SysResult<TokenInfo<'_, '_, '_, '_, '_, '_>> { ... }
    fn ImpersonateLoggedOnUser(&self) -> SysResult<()> { ... }
    fn IsTokenRestricted(&self) -> SysResult<bool> { ... }
}
Available on crate feature kernel only.
Expand description

This trait is enabled with the kernel feature, and provides methods for HACCESSTOKEN.

Prefer importing this trait through the prelude:

use winsafe::prelude::*;

Provided Methods§

source

fn AdjustTokenPrivileges(&self, new_state: DisabPriv<'_>) -> SysResult<()>

AdjustTokenPrivileges function.

§Examples
use winsafe::{self as w, prelude::*, co};

let htoken = w::HPROCESS::GetCurrentProcess()
    .OpenProcessToken(co::TOKEN::ADJUST_PRIVILEGES | co::TOKEN::QUERY)?;

let luid = w::LookupPrivilegeValue(None, co::SE_PRIV::SHUTDOWN_NAME)?;

let privs = w::TOKEN_PRIVILEGES::new(&[
    w::LUID_AND_ATTRIBUTES::new(luid, co::SE_PRIV_ATTR::ENABLED),
])?;

htoken.AdjustTokenPrivileges(w::DisabPriv::Privs(&privs))?;
source

fn CheckTokenCapability(&self, capability_sid_to_check: &SID) -> SysResult<bool>

source

fn CheckTokenMembership(&self, sid_to_check: &SID) -> SysResult<bool>

source

fn DuplicateToken( &self, level: SECURITY_IMPERSONATION ) -> SysResult<CloseHandleGuard<HACCESSTOKEN>>

DuplicateToken function.

source

fn GetCurrentProcessToken() -> HACCESSTOKEN

source

fn GetCurrentThreadEffectiveToken() -> HACCESSTOKEN

source

fn GetTokenInformation( &self, information_class: TOKEN_INFORMATION_CLASS ) -> SysResult<TokenInfo<'_, '_, '_, '_, '_, '_>>

GetTokenInformation function.

The returned enum variant will correspond to the passed information_class.

§Examples

Retrieving the Groups information:

use winsafe::{self as w, prelude::*, co};

let htoken = w::HPROCESS::GetCurrentProcess()
    .OpenProcessToken(co::TOKEN::QUERY)?;

let nfo = htoken.GetTokenInformation(co::TOKEN_INFORMATION_CLASS::Groups)?;
let w::TokenInfo::Groups(groups) = nfo else { panic!("never") };

for (idx, g) in groups.Groups().iter().enumerate() {
    println!("{}: {}", idx, g.Sid().unwrap());
}
source

fn ImpersonateLoggedOnUser(&self) -> SysResult<()>

source

fn IsTokenRestricted(&self) -> SysResult<bool>

Object Safety§

This trait is not object safe.

Implementors§