Skip to content

Commit

Permalink
Upgrade windows crate to version 0.58
Browse files Browse the repository at this point in the history
  • Loading branch information
niluxv committed Nov 17, 2024
1 parent 5491e39 commit 0708faa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ rustix = { version = "0.38", default-features = false, features = ["process"] }
libc = "0.2.107"

[target.'cfg(windows)'.dependencies]
windows = { version = "0.52", features = ["Win32_Foundation", "Win32_Security", "Win32_System_Threading", "Win32_Security_Authorization", "Win32_System_Diagnostics_Debug"] }
windows = { version = "0.58", features = ["Win32_Foundation", "Win32_Security", "Win32_System_Threading", "Win32_Security_Authorization", "Win32_System_Diagnostics_Debug"] }

[dev-dependencies]
assert_cmd = "2.0"
Expand Down
32 changes: 17 additions & 15 deletions src/internals/win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use alloc::alloc;
use core::alloc::Layout;
use core::ffi::c_void;
use core::ptr::NonNull;
use windows::core::IntoParam;
use windows::core::{Param, ParamValue};

#[allow(non_upper_case_globals)]
mod win {
Expand All @@ -30,8 +30,9 @@ mod win {
};

// import structures
pub(super) use windows::Win32::Foundation::{BOOL, HANDLE, PSID};
pub(super) use windows::Win32::Foundation::{BOOL, HANDLE};
pub(super) use windows::Win32::Security::Authorization::SE_OBJECT_TYPE;
pub(super) use windows::Win32::Security::PSID;
pub(super) use windows::Win32::Security::{
ACCESS_ALLOWED_ACE, ACCESS_DENIED_ACE, ACE_REVISION, ACL, OBJECT_SECURITY_INFORMATION,
TOKEN_ACCESS_MASK, TOKEN_USER,
Expand Down Expand Up @@ -61,18 +62,18 @@ impl From<ThreadHandle> for win::HANDLE {
handle.0
}
}
impl IntoParam<win::HANDLE> for ProcessHandle {
fn into_param(self) -> windows::core::Param<win::HANDLE> {
windows::core::Param::Owned(self.0)
impl Param<win::HANDLE> for ProcessHandle {
unsafe fn param(self) -> ParamValue<win::HANDLE> {
ParamValue::Owned(self.0)
}
}
impl IntoParam<win::HANDLE> for ThreadHandle {
fn into_param(self) -> windows::core::Param<win::HANDLE> {
windows::core::Param::Owned(self.0)
impl Param<win::HANDLE> for ThreadHandle {
unsafe fn param(self) -> ParamValue<win::HANDLE> {
ParamValue::Owned(self.0)
}
}

/// Creates pseudo-handle to the current process. Needs not be closed.
/// Creates pseudo-handle to the current process. Need not be closed.
#[must_use]
pub fn get_process_handle() -> ProcessHandle {
// calling `GetCurrentProcess` just returns a constant, is safe and cannot fail
Expand Down Expand Up @@ -151,9 +152,9 @@ impl From<SidPtr> for win::PSID {
}
}

impl IntoParam<win::PSID> for SidPtr {
fn into_param(self) -> windows::core::Param<win::PSID> {
windows::core::Param::Owned(self.0)
impl Param<win::PSID> for SidPtr {
unsafe fn param(self) -> ParamValue<win::PSID> {
ParamValue::Owned(self.0)
}
}

Expand Down Expand Up @@ -253,7 +254,7 @@ impl AccessToken {
handle: ProcessHandle,
access: win::TOKEN_ACCESS_MASK,
) -> anyhow::Result<Self> {
let mut token_handle = win::HANDLE(0);
let mut token_handle = win::HANDLE(core::ptr::null_mut());
unsafe { win::OpenProcessToken(handle, access, &mut token_handle as *mut win::HANDLE) }
.map_anyhow()?;
Ok(AccessToken(token_handle))
Expand Down Expand Up @@ -398,7 +399,7 @@ unsafe fn initialize_acl(
/// and <https://docs.microsoft.com/en-us/windows/win32/secauthz/security-information> for more
/// information.
unsafe fn set_security_info(
handle: impl IntoParam<win::HANDLE>,
handle: impl Param<win::HANDLE>,
obj_type: win::SE_OBJECT_TYPE,
sec_info: win::OBJECT_SECURITY_INFORMATION,
owner: SidPtr,
Expand All @@ -407,6 +408,7 @@ unsafe fn set_security_info(
sacl: Option<*const win::ACL>,
) -> anyhow::Result<()> {
unsafe { win::SetSecurityInfo(handle, obj_type, sec_info, owner, group, dacl, sacl) }
.ok()
.map_anyhow()?;
Ok(())
}
Expand Down Expand Up @@ -510,7 +512,7 @@ impl AclBox {
/// `handle` must point to a valid object of type `obj_type`.
pub unsafe fn set_protected(
&self,
handle: impl IntoParam<win::HANDLE>,
handle: impl Param<win::HANDLE>,
obj_type: win::SE_OBJECT_TYPE,
) -> anyhow::Result<()> {
// change only DACL, do not inherit ACEs
Expand Down

0 comments on commit 0708faa

Please sign in to comment.