diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index a8479979..ea183bb5 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -158,7 +158,7 @@ logdir Loggerhas logon Lrs -Lsa +lsa ltsc luid macikgo diff --git a/Cargo.lock b/Cargo.lock index 89417abf..982d70ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,7 +99,7 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -109,7 +109,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -192,7 +192,7 @@ dependencies = [ "winapi", "windows-acl", "windows-service", - "windows-sys 0.42.0", + "windows-sys", "winres", ] @@ -680,7 +680,7 @@ dependencies = [ "hermit-abi", "libc", "wasi", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -746,7 +746,7 @@ checksum = "ae99c7fa6dd38c7cafe1ec085e804f8f555a2f8659b0dbe03f1f9963a9b51092" dependencies = [ "log", "serde", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -816,7 +816,7 @@ dependencies = [ "time", "tokio", "windows-service", - "windows-sys 0.42.0", + "windows-sys", "winreg", ] @@ -1001,7 +1001,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1121,7 +1121,7 @@ dependencies = [ "pin-project-lite", "socket2", "tokio-macros", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1368,22 +1368,7 @@ checksum = "d24d6bcc7f734a4091ecf8d7a64c5f7d7066f45585c1861eba06449909609c8a" dependencies = [ "bitflags", "widestring 1.1.0", - "windows-sys 0.52.0", -] - -[[package]] -name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows-sys", ] [[package]] @@ -1401,46 +1386,28 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" - [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_i686_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" - [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -1453,48 +1420,24 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" - [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" - [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" - [[package]] name = "windows_x86_64_msvc" version = "0.52.6" diff --git a/proxy_agent/Cargo.toml b/proxy_agent/Cargo.toml index 7a690c3f..f16a52c3 100644 --- a/proxy_agent/Cargo.toml +++ b/proxy_agent/Cargo.toml @@ -62,8 +62,10 @@ winres = "0.1.12" # Rust Windows resource helper to add file version static_vcruntime = "2.0.0" # Statically link the VCRuntime when using the MSVC toolchain [target.'cfg(windows)'.dependencies.windows-sys] -version = "0.42.0" +version = "0.52.0" features = [ + "Wdk_Foundation", + "Wdk_System_Threading", "Win32_Foundation", "Win32_Networking_WinSock", "Win32_System_IO", @@ -76,7 +78,7 @@ features = [ "Win32_System_ProcessStatus", "Win32_System_Kernel", "Win32_Security_Cryptography", - "Win32_System_Memory", + "Win32_System_Memory" ] [features] diff --git a/proxy_agent/src/common/windows.rs b/proxy_agent/src/common/windows.rs index a6f34c9e..5513695e 100644 --- a/proxy_agent/src/common/windows.rs +++ b/proxy_agent/src/common/windows.rs @@ -12,7 +12,7 @@ use windows_sys::Win32::Security::Cryptography::{ // msasn1.dll (ASN.1 library) is also used by crypt32.dll CryptProtectData, CryptUnprotectData, - CRYPTOAPI_BLOB, + CRYPT_INTEGER_BLOB, }; use windows_sys::Win32::System::SystemInformation::{ GetSystemInfo, // kernel32.dll @@ -46,11 +46,11 @@ pub fn get_memory_in_mb() -> Result { pub fn store_key_data(encrypted_file_path: &Path, key_data: String) -> Result<()> { let data = key_data.as_bytes(); - let data_in = CRYPTOAPI_BLOB { + let data_in = CRYPT_INTEGER_BLOB { cbData: data.len() as u32, pbData: data.as_ptr() as *mut u8, }; - let mut data_out = CRYPTOAPI_BLOB { + let mut data_out = CRYPT_INTEGER_BLOB { cbData: 0, pbData: std::ptr::null_mut(), }; @@ -73,7 +73,9 @@ pub fn store_key_data(encrypted_file_path: &Path, key_data: String) -> Result<() let encrypted_data = unsafe { std::slice::from_raw_parts(data_out.pbData, data_out.cbData as usize).to_vec() }; - unsafe { windows_sys::Win32::System::Memory::LocalFree(data_out.pbData as isize) }; + unsafe { + windows_sys::Win32::Foundation::LocalFree(data_out.pbData as *mut ::core::ffi::c_void) + }; std::fs::write(encrypted_file_path, encrypted_data).map_err(|e| { Error::Io( format!( @@ -97,11 +99,11 @@ pub fn fetch_key_data(encrypted_file_path: &Path) -> Result { e, ) })?; - let data_in = CRYPTOAPI_BLOB { + let data_in = CRYPT_INTEGER_BLOB { cbData: encrypted_data.len() as u32, pbData: encrypted_data.as_ptr() as *mut u8, }; - let mut data_out = CRYPTOAPI_BLOB { + let mut data_out = CRYPT_INTEGER_BLOB { cbData: 0, pbData: std::ptr::null_mut(), }; @@ -125,7 +127,9 @@ pub fn fetch_key_data(encrypted_file_path: &Path) -> Result { let decrypted_data = unsafe { std::slice::from_raw_parts(data_out.pbData as *const u8, data_out.cbData as usize).to_vec() }; - unsafe { windows_sys::Win32::System::Memory::LocalFree(data_out.pbData as isize) }; + unsafe { + windows_sys::Win32::Foundation::LocalFree(data_out.pbData as *mut ::core::ffi::c_void) + }; let key_data = String::from_utf8_lossy(&decrypted_data).to_string(); Ok(key_data) diff --git a/proxy_agent/src/proxy/windows.rs b/proxy_agent/src/proxy/windows.rs index fe96ed9e..c75869d4 100644 --- a/proxy_agent/src/proxy/windows.rs +++ b/proxy_agent/src/proxy/windows.rs @@ -11,18 +11,23 @@ use once_cell::sync::Lazy; use std::mem::MaybeUninit; use std::ptr::null_mut; use std::{collections::HashMap, ffi::OsString, os::windows::ffi::OsStringExt, path::PathBuf}; +use windows_sys::Wdk::System::Threading::{ + NtQueryInformationProcess, // ntdll.dll + PROCESSINFOCLASS, +}; use windows_sys::Win32::Foundation::{BOOL, HANDLE, LUID, NTSTATUS, UNICODE_STRING}; use windows_sys::Win32::Security::Authentication::Identity; -use windows_sys::Win32::Security::Authentication::Identity::SECURITY_LOGON_SESSION_DATA; +use windows_sys::Win32::Security::Authentication::Identity::{ + LSA_UNICODE_STRING, SECURITY_LOGON_SESSION_DATA, +}; use windows_sys::Win32::System::ProcessStatus::{ K32GetModuleBaseNameW, // kernel32.dll K32GetModuleFileNameExW, // kernel32.dll }; +use windows_sys::Win32::System::Threading::PROCESS_BASIC_INFORMATION; use windows_sys::Win32::System::Threading::{ - NtQueryInformationProcess, // ntdll.dll - OpenProcess, //kernel32.dll + OpenProcess, //kernel32.dll }; -use windows_sys::Win32::System::Threading::{PROCESSINFOCLASS, PROCESS_BASIC_INFORMATION}; const LG_INCLUDE_INDIRECT: u32 = 1u32; const MAX_PREFERRED_LENGTH: u32 = 4294967295u32; @@ -179,7 +184,7 @@ pub fn get_user(logon_id: u64) -> Result<(String, Vec)> { Ok((user_name, user_groups)) } -fn from_unicode_string(unicode_string: &UNICODE_STRING) -> String { +fn from_unicode_string(unicode_string: &LSA_UNICODE_STRING) -> String { let mut v = vec![0u16; unicode_string.Length as usize]; unsafe { std::ptr::copy_nonoverlapping( diff --git a/proxy_agent_shared/Cargo.toml b/proxy_agent_shared/Cargo.toml index 77ee5be8..ef217730 100644 --- a/proxy_agent_shared/Cargo.toml +++ b/proxy_agent_shared/Cargo.toml @@ -25,7 +25,7 @@ windows-service = "0.7.0" # windows NT service winreg = "0.11.0" # windows reg read/write [target.'cfg(windows)'.dependencies.windows-sys] -version = "0.42.0" +version = "0.52.0" features = [ "Win32_Foundation", "Win32_Networking_WinSock", diff --git a/proxy_agent_shared/src/windows.rs b/proxy_agent_shared/src/windows.rs index 27f2e0d3..c9e1fb14 100644 --- a/proxy_agent_shared/src/windows.rs +++ b/proxy_agent_shared/src/windows.rs @@ -174,11 +174,11 @@ pub fn get_processor_arch() -> String { .Anonymous .wProcessorArchitecture { - windows_sys::Win32::System::Diagnostics::Debug::PROCESSOR_ARCHITECTURE_INTEL => "x86", // 0 - windows_sys::Win32::System::Diagnostics::Debug::PROCESSOR_ARCHITECTURE_ARM => "ARM", // 5 - windows_sys::Win32::System::Diagnostics::Debug::PROCESSOR_ARCHITECTURE_IA64 => "IA64", // 6 - windows_sys::Win32::System::Diagnostics::Debug::PROCESSOR_ARCHITECTURE_AMD64 => "AMD64", // 9 - 12 => "ARM64", // 12 - ARM64 is missed here + windows_sys::Win32::System::SystemInformation::PROCESSOR_ARCHITECTURE_INTEL => "x86", // 0 + windows_sys::Win32::System::SystemInformation::PROCESSOR_ARCHITECTURE_ARM => "ARM", // 5 + windows_sys::Win32::System::SystemInformation::PROCESSOR_ARCHITECTURE_IA64 => "IA64", // 6 + windows_sys::Win32::System::SystemInformation::PROCESSOR_ARCHITECTURE_AMD64 => "AMD64", // 9 + windows_sys::Win32::System::SystemInformation::PROCESSOR_ARCHITECTURE_ARM64 => "ARM64", // 12 _ => "unknown", } .to_owned()