mod error;
#[cfg(target_os = "windows")]
mod elevation;
#[cfg(target_os = "windows")]
mod ffi;
#[cfg(target_os = "windows")]
mod privilege;
pub use error::TokenPrivilegeError;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct PrivilegeInfo {
pub name: String,
pub enabled: bool,
pub enabled_by_default: bool,
pub removed: bool,
}
pub mod privileges {
pub const SE_DEBUG: &str = "SeDebugPrivilege";
pub const SE_BACKUP: &str = "SeBackupPrivilege";
pub const SE_RESTORE: &str = "SeRestorePrivilege";
pub const SE_SHUTDOWN: &str = "SeShutdownPrivilege";
pub const SE_SECURITY: &str = "SeSecurityPrivilege";
pub const SE_TAKE_OWNERSHIP: &str = "SeTakeOwnershipPrivilege";
pub const SE_LOAD_DRIVER: &str = "SeLoadDriverPrivilege";
pub const SE_SYSTEM_PROFILE: &str = "SeSystemProfilePrivilege";
pub const SE_SYSTEMTIME: &str = "SeSystemtimePrivilege";
pub const SE_CHANGE_NOTIFY: &str = "SeChangeNotifyPrivilege";
pub const SE_IMPERSONATE: &str = "SeImpersonatePrivilege";
pub const SE_CREATE_GLOBAL: &str = "SeCreateGlobalPrivilege";
pub const SE_INCREASE_QUOTA: &str = "SeIncreaseQuotaPrivilege";
pub const SE_UNDOCK: &str = "SeUndockPrivilege";
pub const SE_MANAGE_VOLUME: &str = "SeManageVolumePrivilege";
pub const SE_ASSIGN_PRIMARY_TOKEN: &str = "SeAssignPrimaryTokenPrivilege";
pub const SE_INCREASE_BASE_PRIORITY: &str = "SeIncreaseBasePriorityPrivilege";
pub const SE_CREATE_PAGEFILE: &str = "SeCreatePagefilePrivilege";
pub const SE_TCB: &str = "SeTcbPrivilege";
pub const SE_REMOTE_SHUTDOWN: &str = "SeRemoteShutdownPrivilege";
}
#[cfg(target_os = "windows")]
pub fn is_elevated() -> Result<bool, TokenPrivilegeError> {
elevation::is_elevated()
}
#[cfg(target_os = "windows")]
pub fn is_privilege_enabled(privilege_name: &str) -> Result<bool, TokenPrivilegeError> {
privilege::is_privilege_enabled(privilege_name)
}
#[cfg(target_os = "windows")]
pub fn has_privilege(privilege_name: &str) -> Result<bool, TokenPrivilegeError> {
privilege::has_privilege(privilege_name)
}
#[cfg(target_os = "windows")]
pub fn enumerate_privileges() -> Result<Vec<PrivilegeInfo>, TokenPrivilegeError> {
privilege::enumerate_privileges()
}
#[cfg(not(target_os = "windows"))]
pub const fn is_elevated() -> Result<bool, TokenPrivilegeError> {
Err(TokenPrivilegeError::UnsupportedPlatform)
}
#[cfg(not(target_os = "windows"))]
pub const fn is_privilege_enabled(_privilege_name: &str) -> Result<bool, TokenPrivilegeError> {
Err(TokenPrivilegeError::UnsupportedPlatform)
}
#[cfg(not(target_os = "windows"))]
pub const fn has_privilege(_privilege_name: &str) -> Result<bool, TokenPrivilegeError> {
Err(TokenPrivilegeError::UnsupportedPlatform)
}
#[cfg(not(target_os = "windows"))]
pub const fn enumerate_privileges() -> Result<Vec<PrivilegeInfo>, TokenPrivilegeError> {
Err(TokenPrivilegeError::UnsupportedPlatform)
}
#[cfg(not(target_os = "windows"))]
#[cfg(test)]
mod stub_tests {
use super::*;
#[test]
fn is_elevated_returns_unsupported() {
assert!(matches!(
is_elevated(),
Err(TokenPrivilegeError::UnsupportedPlatform)
));
}
#[test]
fn is_privilege_enabled_returns_unsupported() {
assert!(matches!(
is_privilege_enabled("SeDebugPrivilege"),
Err(TokenPrivilegeError::UnsupportedPlatform)
));
}
#[test]
fn has_privilege_returns_unsupported() {
assert!(matches!(
has_privilege("SeDebugPrivilege"),
Err(TokenPrivilegeError::UnsupportedPlatform)
));
}
#[test]
fn enumerate_privileges_returns_unsupported() {
assert!(matches!(
enumerate_privileges(),
Err(TokenPrivilegeError::UnsupportedPlatform)
));
}
}