summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2023-09-04 16:29:43 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-09-04 16:29:43 +0200
commit6c1058043051556644fc53663ea28bef0243ad11 (patch)
treef916ff45e0ab6524fd18ea06a078efb1ab216e31
parent2f0c588763b38145254806ed568e89061eb23756 (diff)
parentf5d8551cf3377219197eb3147cf31c9ad564e1cd (diff)
downloadmullvadvpn-6c1058043051556644fc53663ea28bef0243ad11.tar.xz
mullvadvpn-6c1058043051556644fc53663ea28bef0243ad11.zip
Merge branch 'detect-windows-server-des-339' into main
-rw-r--r--CHANGELOG.md4
-rw-r--r--talpid-platform-metadata/src/lib.rs3
-rw-r--r--talpid-platform-metadata/src/windows.rs22
3 files changed, 19 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7569ca5033..d52998e13d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,6 +37,10 @@ Line wrap the file at 100 chars. Th
#### Windows
- Remove wireguard-go (userspace WireGuard) support.
+### Fixed
+#### Windows
+- Correctly detect whether OS is Windows Server (primarily for logging in daemon.log).
+
## [android/2023.6-beta1] - 2023-08-29
diff --git a/talpid-platform-metadata/src/lib.rs b/talpid-platform-metadata/src/lib.rs
index 5fd43e62d4..f4ba78eaeb 100644
--- a/talpid-platform-metadata/src/lib.rs
+++ b/talpid-platform-metadata/src/lib.rs
@@ -15,6 +15,3 @@ mod imp;
mod imp;
pub use self::imp::{extra_metadata, short_version, version};
-
-#[cfg(target_os = "windows")]
-pub use self::imp::WindowsVersion;
diff --git a/talpid-platform-metadata/src/windows.rs b/talpid-platform-metadata/src/windows.rs
index d94bd02167..e2e6ccbd2b 100644
--- a/talpid-platform-metadata/src/windows.rs
+++ b/talpid-platform-metadata/src/windows.rs
@@ -6,11 +6,12 @@ use std::{
};
use windows_sys::Win32::System::{
LibraryLoader::{GetModuleHandleW, GetProcAddress},
- SystemInformation::OSVERSIONINFOW,
+ SystemInformation::OSVERSIONINFOEXW,
+ SystemServices::VER_NT_WORKSTATION,
};
#[allow(non_camel_case_types)]
-type RTL_OSVERSIONINFOW = OSVERSIONINFOW;
+type RTL_OSVERSIONINFOEXW = OSVERSIONINFOEXW;
pub fn version() -> String {
let (major, build) = WindowsVersion::new()
@@ -20,7 +21,7 @@ pub fn version() -> String {
version_info.build_number().to_string(),
)
})
- .unwrap_or_else(|_| ("N/A".to_string(), "N/A".to_string()));
+ .unwrap_or_else(|_| ("N/A".to_owned(), "N/A".to_owned()));
format!("Windows {} Build {}", major, build)
}
@@ -36,8 +37,8 @@ pub fn extra_metadata() -> impl Iterator<Item = (String, String)> {
std::iter::empty()
}
-pub struct WindowsVersion {
- inner: RTL_OSVERSIONINFOW,
+struct WindowsVersion {
+ inner: RTL_OSVERSIONINFOEXW,
}
impl WindowsVersion {
@@ -56,10 +57,10 @@ impl WindowsVersion {
let function_address = unsafe { GetProcAddress(ntdll, b"RtlGetVersion\0" as *const u8) }
.ok_or_else(io::Error::last_os_error)?;
- let rtl_get_version: extern "stdcall" fn(*mut RTL_OSVERSIONINFOW) =
+ let rtl_get_version: extern "stdcall" fn(*mut RTL_OSVERSIONINFOEXW) =
unsafe { *(&function_address as *const _ as *const _) };
- let mut version_info: MaybeUninit<RTL_OSVERSIONINFOW> = mem::MaybeUninit::zeroed();
+ let mut version_info: MaybeUninit<RTL_OSVERSIONINFOEXW> = mem::MaybeUninit::zeroed();
unsafe {
(*version_info.as_mut_ptr()).dwOSVersionInfoSize =
mem::size_of_val(&version_info) as u32;
@@ -72,6 +73,13 @@ impl WindowsVersion {
}
pub fn windows_version_string(&self) -> String {
+ // `wProductType != VER_NT_WORKSTATION` implies that OS is Windows Server
+ // https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_osversioninfoexw
+ // NOTE: This does not deduce which Windows Server version is running.
+ if u32::from(self.inner.wProductType) != VER_NT_WORKSTATION {
+ return "Server".to_owned();
+ }
+
// Check https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions#Personal_computer_versions 'Release version' column
// for the correct NT versions for specific windows releases.
match (self.major_version(), self.minor_version()) {