summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--talpid-core/src/dns/windows/netsh.rs27
-rw-r--r--talpid-platform-metadata/Cargo.toml3
-rw-r--r--talpid-platform-metadata/src/windows.rs25
-rw-r--r--talpid-windows/src/env.rs18
-rw-r--r--talpid-windows/src/lib.rs3
-rw-r--r--test/Cargo.lock1
7 files changed, 38 insertions, 40 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 13214926ba..1ae07c676e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5745,6 +5745,7 @@ version = "0.0.0"
dependencies = [
"rs-release",
"talpid-dbus",
+ "talpid-windows",
"windows-sys 0.52.0",
]
diff --git a/talpid-core/src/dns/windows/netsh.rs b/talpid-core/src/dns/windows/netsh.rs
index fe5a135e87..2f8a4d77d1 100644
--- a/talpid-core/src/dns/windows/netsh.rs
+++ b/talpid-core/src/dns/windows/netsh.rs
@@ -2,22 +2,20 @@
use crate::dns::{DnsMonitorT, ResolvedDnsConfig};
use std::{
- ffi::OsString,
io::{self, Write},
net::IpAddr,
- os::windows::prelude::{AsRawHandle, OsStringExt},
- path::PathBuf,
+ os::windows::prelude::AsRawHandle,
process::{Child, Command, ExitStatus, Stdio},
time::Duration,
};
use talpid_types::{ErrorExt, net::IpVersion};
-use talpid_windows::net::{index_from_luid, luid_from_alias};
+use talpid_windows::{
+ env::get_system_dir,
+ net::{index_from_luid, luid_from_alias},
+};
use windows_sys::Win32::{
- Foundation::{MAX_PATH, WAIT_OBJECT_0, WAIT_TIMEOUT},
- System::{
- SystemInformation::GetSystemDirectoryW,
- Threading::{INFINITE, WaitForSingleObject},
- },
+ Foundation::{WAIT_OBJECT_0, WAIT_TIMEOUT},
+ System::Threading::{INFINITE, WaitForSingleObject},
};
const NETSH_TIMEOUT: Duration = Duration::from_secs(10);
@@ -213,14 +211,3 @@ fn create_netsh_flush_command(interface_index: u32, ip_version: IpVersion) -> St
"interface {interface_type} set dnsservers name={interface_index} source=static address=none validate=no\r\n"
)
}
-
-fn get_system_dir() -> io::Result<PathBuf> {
- let mut sysdir = [0u16; MAX_PATH as usize + 1];
- let len = unsafe { GetSystemDirectoryW(sysdir.as_mut_ptr(), (sysdir.len() - 1) as u32) };
- if len == 0 {
- return Err(io::Error::last_os_error());
- }
- Ok(PathBuf::from(OsString::from_wide(
- &sysdir[0..(len as usize)],
- )))
-}
diff --git a/talpid-platform-metadata/Cargo.toml b/talpid-platform-metadata/Cargo.toml
index 66db6c4285..281914e721 100644
--- a/talpid-platform-metadata/Cargo.toml
+++ b/talpid-platform-metadata/Cargo.toml
@@ -18,6 +18,9 @@ network-manager = ["talpid-dbus"]
rs-release = "0.1.7"
talpid-dbus = { path = "../talpid-dbus", optional = true }
+[target.'cfg(target_os = "windows")'.dependencies]
+talpid-windows = { path = "../talpid-windows" }
+
[target.'cfg(windows)'.dependencies.windows-sys]
workspace = true
features = [
diff --git a/talpid-platform-metadata/src/windows.rs b/talpid-platform-metadata/src/windows.rs
index 9a23cc21c4..6cb5599ceb 100644
--- a/talpid-platform-metadata/src/windows.rs
+++ b/talpid-platform-metadata/src/windows.rs
@@ -1,23 +1,20 @@
use std::{
- ffi::{OsStr, OsString},
+ ffi::OsStr,
io, iter,
mem::{self, MaybeUninit},
- os::{
- raw::c_void,
- windows::ffi::{OsStrExt, OsStringExt},
- },
- path::PathBuf,
+ os::{raw::c_void, windows::ffi::OsStrExt},
ptr,
};
+use talpid_windows::env::get_system_dir;
use windows_sys::Win32::{
- Foundation::{MAX_PATH, NTSTATUS, STATUS_SUCCESS},
+ Foundation::{NTSTATUS, STATUS_SUCCESS},
Storage::FileSystem::{
GetFileVersionInfoSizeW, GetFileVersionInfoW, VS_FFI_SIGNATURE, VS_FIXEDFILEINFO,
VerQueryValueW,
},
System::{
LibraryLoader::{GetModuleHandleW, GetProcAddress},
- SystemInformation::{GetSystemDirectoryW, OSVERSIONINFOEXW},
+ SystemInformation::OSVERSIONINFOEXW,
SystemServices::VER_NT_WORKSTATION,
},
};
@@ -223,18 +220,6 @@ fn ntoskrnl_version() -> io::Result<(u32, u32, u32)> {
Ok((major, minor, build))
}
-fn get_system_dir() -> io::Result<PathBuf> {
- let mut sysdir = [0u16; MAX_PATH as usize + 1];
- // SAFETY: `sysdir` points to a valid buffer
- let len = unsafe { GetSystemDirectoryW(sysdir.as_mut_ptr(), (sysdir.len() - 1) as u32) };
- if len == 0 {
- return Err(io::Error::last_os_error());
- }
- Ok(PathBuf::from(OsString::from_wide(
- &sysdir[0..(len as usize)],
- )))
-}
-
/// Return a null-terminated UTF16 string
fn to_wide(s: impl AsRef<OsStr>) -> Vec<u16> {
s.as_ref().encode_wide().chain(iter::once(0u16)).collect()
diff --git a/talpid-windows/src/env.rs b/talpid-windows/src/env.rs
new file mode 100644
index 0000000000..1f49307822
--- /dev/null
+++ b/talpid-windows/src/env.rs
@@ -0,0 +1,18 @@
+use std::io;
+use std::os::windows::ffi::OsStringExt;
+use std::{ffi::OsString, path::PathBuf};
+
+use windows_sys::Win32::{Foundation::MAX_PATH, System::SystemInformation::GetSystemDirectoryW};
+
+/// Get the system directory path. This is typically `C:\Windows\System32`.
+pub fn get_system_dir() -> io::Result<PathBuf> {
+ let mut sysdir = [0u16; MAX_PATH as usize + 1];
+ // SAFETY: We have a valid buffer and length
+ let len = unsafe { GetSystemDirectoryW(sysdir.as_mut_ptr(), (sysdir.len() - 1) as u32) };
+ if len == 0 {
+ return Err(io::Error::last_os_error());
+ }
+ Ok(PathBuf::from(OsString::from_wide(
+ &sysdir[0..(len as usize)],
+ )))
+}
diff --git a/talpid-windows/src/lib.rs b/talpid-windows/src/lib.rs
index bf6054ee79..27ddd877c2 100644
--- a/talpid-windows/src/lib.rs
+++ b/talpid-windows/src/lib.rs
@@ -3,6 +3,9 @@
#![deny(missing_docs)]
#![cfg(windows)]
+/// Environment
+pub mod env;
+
/// File system
pub mod fs;
diff --git a/test/Cargo.lock b/test/Cargo.lock
index fe9974abb2..ef2cb663c1 100644
--- a/test/Cargo.lock
+++ b/test/Cargo.lock
@@ -3662,6 +3662,7 @@ name = "talpid-platform-metadata"
version = "0.0.0"
dependencies = [
"rs-release",
+ "talpid-windows",
"windows-sys 0.52.0",
]