From: "stipa (Code Review)" Date: Fri, 18 Apr 2025 13:06:41 +0000 References: Reply-To: lstipakov@...277..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="awA6vww8by0="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: win: refactor get_windows_version() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --awA6vww8by0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/944?usp=3Demail to review the following change. Change subject: win: refactor get_windows_version() ...................................................................... win: refactor get_windows_version() It's 2025, and almost all clients now run on Windows 10 or newer. Instead of displaying: "Windows version 10.0 (Windows 10 or greater)" we now show the exact build number, e.g.: "Windows version: 10.0.22631" Remove "pre-Win7" checks in a few places. For IV_PLAT_VER, we now provide only the version number without binary architecture info. Previously: IV_PLAT_VER=3D10.0,_amd64_executable Now: IV_PLAT_VER=3D10.0.22631 Change-Id: I39d660ebeec76280e4d4357192b74bf2c0980615 Signed-off-by: Lev Stipakov --- M src/openvpn/tun.c M src/openvpn/win32.c M src/openvpn/win32.h 3 files changed, 49 insertions(+), 93 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/44/944/1 diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c index 4f7de6c..5186afa 100644 --- a/src/openvpn/tun.c +++ b/src/openvpn/tun.c @@ -5428,11 +5428,8 @@ NETSH_PATH_SUFFIX, adapter_index, print_in6_addr(addr_list[i], 0, &gc)); - /* disable slow address validation on Windows 7 and higher */ - if (win32_version_info() >=3D WIN_7) - { - argv_printf_cat(&argv, "%s", "validate=3Dno"); - } + /* disable slow address validation */ + argv_printf_cat(&argv, "%s", "validate=3Dno"); /* Treat errors while adding as non-fatal as we do not check for d= uplicates */ netsh_command(&argv, 1, (i=3D=3D0) ? M_FATAL : M_NONFATAL); @@ -5498,9 +5495,8 @@ adapter_index, print_in_addr_t(addr_list[i], 0, &gc)); - /* disable slow address validation on Windows 7 and higher= */ - /* only for DNS */ - if (is_dns && win32_version_info() >=3D WIN_7) + /* disable slow address validation for DNS */ + if (is_dns) { argv_printf_cat(&argv, "%s", "validate=3Dno"); } diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c index edac71e..8d4c4a3 100644 --- a/src/openvpn/win32.c +++ b/src/openvpn/win32.c @@ -1283,42 +1283,6 @@ return true; } -int -win32_version_info(void) -{ - if (!IsWindowsXPOrGreater()) - { - msg(M_FATAL, "Error: Windows version must be XP or greater."); - } - - if (!IsWindowsVistaOrGreater()) - { - return WIN_XP; - } - - if (!IsWindows7OrGreater()) - { - return WIN_VISTA; - } - - if (!IsWindows8OrGreater()) - { - return WIN_7; - } - - if (!IsWindows8Point1OrGreater()) - { - return WIN_8; - } - - if (!IsWindows10OrGreater()) - { - return WIN_8_1; - } - - return WIN_10; -} - typedef enum { ARCH_X86, ARCH_AMD64, @@ -1420,57 +1384,50 @@ } } +typedef LONG (WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); + const char * -win32_version_string(struct gc_arena *gc, bool add_name) +win32_version_string(struct gc_arena *gc, bool add_exec_info) { - int version =3D win32_version_info(); - struct buffer out =3D alloc_buf_gc(256, gc); - - switch (version) + HMODULE hMod =3D GetModuleHandleW(L"ntdll.dll"); + if (!hMod) { - case WIN_XP: - buf_printf(&out, "5.1%s", add_name ? " (Windows XP)" : ""); - break; - - case WIN_VISTA: - buf_printf(&out, "6.0%s", add_name ? " (Windows Vista)" : ""); - break; - - case WIN_7: - buf_printf(&out, "6.1%s", add_name ? " (Windows 7)" : ""); - break; - - case WIN_8: - buf_printf(&out, "6.2%s", add_name ? " (Windows 8)" : ""); - break; - - case WIN_8_1: - buf_printf(&out, "6.3%s", add_name ? " (Windows 8.1)" : ""); - break; - - case WIN_10: - buf_printf(&out, "10.0%s", add_name ? " (Windows 10 or greater= )" : ""); - break; - - default: - msg(M_NONFATAL, "Unknown Windows version: %d", version); - buf_printf(&out, "0.0%s", add_name ? " (unknown)" : ""); - break; + return "N/A"; } - buf_printf(&out, ", "); - - arch_t process_arch, host_arch; - win32_get_arch(&process_arch, &host_arch); - win32_print_arch(process_arch, &out); - - buf_printf(&out, " executable"); - - if (host_arch !=3D ARCH_NATIVE) + RtlGetVersionPtr fn =3D (RtlGetVersionPtr)GetProcAddress(hMod, "RtlGet= Version"); + if (!fn) { - buf_printf(&out, " running on "); - win32_print_arch(host_arch, &out); - buf_printf(&out, " host"); + return "N/A"; + } + + RTL_OSVERSIONINFOW rovi =3D { 0 }; + rovi.dwOSVersionInfoSize =3D sizeof(rovi); + if (fn(&rovi) !=3D 0) + { + return "N/A"; + } + + struct buffer out =3D alloc_buf_gc(256, gc); + + buf_printf(&out, "%lu.%lu.%lu", rovi.dwMajorVersion, rovi.dwMinorVersi= on, rovi.dwBuildNumber); + + if (add_exec_info) + { + buf_printf(&out, ", "); + + arch_t process_arch, host_arch; + win32_get_arch(&process_arch, &host_arch); + win32_print_arch(process_arch, &out); + + buf_printf(&out, " executable"); + + if (host_arch !=3D ARCH_NATIVE) + { + buf_printf(&out, " running on "); + win32_print_arch(host_arch, &out); + buf_printf(&out, " host"); + } } return (const char *)out.data; diff --git a/src/openvpn/win32.h b/src/openvpn/win32.h index 081beeb..d663586 100644 --- a/src/openvpn/win32.h +++ b/src/openvpn/win32.h @@ -301,11 +301,14 @@ int win32_version_info(void); -/* - * String representation of Windows version number and name, see - * https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=3Dv= s.85).aspx +/** + * @brief Get Windows version string, optionally with architecture info. + * + * @param gc gc arena to allocate string. + * @param add_exec_info Whether to include architecture details. + * @return Version string, or "N/A" on failure. */ -const char *win32_version_string(struct gc_arena *gc, bool add_name); +const char *win32_version_string(struct gc_arena *gc, bool add_exec_info); /* * Send the |size| bytes in buffer |data| to the interactive service |pipe| -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/944?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I39d660ebeec76280e4d4357192b74bf2c0980615 Gerrit-Change-Number: 944 Gerrit-PatchSet: 1 Gerrit-Owner: stipa Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --awA6vww8by0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

stipa would like plaisthos and flichtenheld to review t= his change.

Vi= ew Change

win: refactor get_windows_version()

It's 2025, and= almost all clients now run on Windows 10 or newer.
Instead of displayin= g:

"Windows version 10.0 (Windows 10 or greater)"
we now show the exact build number, e.g.:

"Windows version: = 10.0.22631"

Remove "pre-Win7" checks in a few places.=

For IV_PLAT_VER, we now provide only the version number without
= binary architecture info. Previously:

IV_PLAT_VER=3D10.0,_amd64_ex= ecutable

Now:

IV_PLAT_VER=3D10.0.22631

Change-Id: I3= 9d660ebeec76280e4d4357192b74bf2c0980615
Signed-off-by: Lev Stipakov <= lev@...515...>
---
M src/openvpn/tun.c
M src/openvpn/win32.cM src/openvpn/win32.h
3 files changed, 49 insertions(+), 93 deletions(-= )

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/44=
/944/1
diff --git a/src/openvpn/tun.c b/src/openvpn/tun.cindex 4f7de6c..5186afa 100644
--- a/src/openvpn/tun.= c
+++ b/src/openvpn/tun.c
@@ -5428,11 +5428= ,8 @@
NETSH_PATH_SUFFIX, adapter_index= ,
print_in6_addr(addr_list[i], 0, &= ;gc));

- if (win32_versio= n_info() >=3D WIN_7)
- {
- = argv_printf_cat(&argv, "%s", "validate=3Dno");
- }
+ /* disable slow address va= lidation */

+ = argv_printf_cat(&argv, "%s", "validate=3Dno");

/* Treat errors while adding as non-= fatal as we do not check for duplicates */
netsh_c= ommand(&argv, 1, (i=3D=3D0) ? M_FATAL : M_NONFATAL);
@@= -5498,9 +5495,8 @@
adapter_in= dex,
print_in_addr_t(addr_list= [i], 0, &gc));

- /* disable slow address validation on Window= s 7 and higher */
- = /* only for DNS */
- if (is_dns && win32_version_info() >=3D= WIN_7)
+ = /* disable slow address validation for DNS */
+ if (is_dns)
= {
argv_printf_cat(&= ;argv, "%s", "validate=3Dno");
= }
diff --git a/src/openvpn/win32.c b/src/openvpn/w= in32.c
index edac71e..8d4c4a3 100644
--- a/= src/openvpn/win32.c
+++ b/src/openvpn/win32.c
@@ -1283,42 +1283,6 @@

return true;
}

-= int
-win32_version_info= (void)
-{
- if (!IsWindowsXPOrGreater())
- {
- msg(M_FATAL, "Error: Window= s version must be XP or greater.");
- }
- if (!IsWindows= VistaOrGreater())
- = {
- return WIN_X= P;
- }
-
- if (!IsWindows7OrGreater())
- {
- return WIN_VISTA;
- }
= -
- if (!IsWindows8O= rGreater())
- {
- return WIN_7;
- }
-
- if (!IsWindows8Point1OrGreater())
- {
- return WIN_8;
- }
-

- if (!IsWindows10OrGre= ater())
- {- return WIN_8_1;=
- }
-
- return WIN_10;
-}
-
<= span> typedef enum {
ARCH_X86,
AR= CH_AMD64,
@@ -1420,57 +1384,50 @@
}
}

+typedef LONG (WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW)= ;
+
= const char *
-win32_ver= sion_string(struct gc_arena *gc, bool add_name)
+win32_version_string(struct gc_arena *gc, bool = add_exec_info)
{
- int version =3D win32_version_info();
- struct buffer out =3D alloc_buf_gc(256,= gc);
-
- switch (version)

+ HMODULE hMod =3D GetModuleHandle= W(L"ntdll.dll");
+ if (!hMod)
{
- case WIN_XP:
- buf_printf(&out, "5.1%s", a= dd_name ? " (Windows XP)" : "");
- break;
-
- case WIN_VISTA:
- buf_printf(&out, "6.0%s", add_name ? &q= uot; (Windows Vista)" : "");
- break;
-
- = case WIN_7:
- = buf_printf(&out, "6.1%s", add_name ? " (Windows = 7)" : "");
- break;
= -
- case WIN_8:<= /span>
- buf_printf= (&out, "6.2%s", add_name ? " (Windows 8)" : "&= quot;);
- br= eak;
-
- case WIN_8_1:
- buf_printf(&out, "= ;6.3%s", add_name ? " (Windows 8.1)" : "");=
- break;-
- case WIN_10:
- buf_printf(&out, "10.0%s", = add_name ? " (Windows 10 or greater)" : "");
= - break;
-

- default:
- msg(M_NONFATAL, "Unknown Windows version: %d= ", version);
- = buf_printf(&out, "0.0%s", add_name ? " (unknown)= " : "");
- break;
= + return "N/A";
}

- buf_printf(&out= , ", ");
-
- arch_t process_arch,= host_arch;
- win32_= get_arch(&process_arch, &host_arch);
- win32_print_arch(process_arch, &out);=
-
- buf_printf(&out, " executable")= ;
-
- if (host_arch !=3D ARCH_NATIVE)

+ RtlGetVersionPtr fn = =3D (RtlGetVersionPtr)GetProcAddress(hMod, "RtlGetVersion");
+ if (!fn)
<= span> {

- bu= f_printf(&out, " running on ");
- win32_print_arch(host_arch, &out);
- buf_printf(&ou= t, " host");
+ }
= +
+ RTL_OSVERSIONI= NFOW rovi =3D { 0 };
= + rovi.dwOSVersionInfoSize =3D sizeof(rovi);
+ if (fn(&rovi) !=3D 0)
+ {
+ return "N/A";
+ }
+
+
+ buf_printf(&out, "%lu.%lu.%lu", rovi.dwMaj= orVersion, rovi.dwMinorVersion, rovi.dwBuildNumber);
+
+ if (add_exec_info)
+ {
+ buf_printf(&out, ", ");
+
+ arch_t process_arch, host_arch;
+ win32_get_arch(&process_arch, &a= mp;host_arch);
+ = win32_print_arch(process_arch, &out);
+
+ buf_printf(&out, " executable");
+

+ if (host_arch !=3D ARCH_NATIVE)
+ {
+ buf_printf(&out, " r= unning on ");
+ = win32_print_arch(host_arch, &out);
+ buf_printf(&out, " host&= quot;);
+ }
}

return (const c= har *)out.data;
diff --git a/src/openvpn/win32.h b/src/open= vpn/win32.h
index 081beeb..d663586 100644
-= -- a/src/openvpn/win32.h
+++ b/src/openvpn/win32.h@@ -301,11 +301,14 @@

int win32_= version_info(void);

-/*
- * = String representation of Windows version number and name, see
- * https://msdn.microsoft.com/en-us= /library/windows/desktop/ms724832(v=3Dvs.85).aspx

+/**
+ * @brief Get Windows version string, optionally with archite= cture info.
+ *
+ * @param gc gc arena to = allocate string.
+ * = @param add_exec_info Whether to include architecture details.
+ * @return Version string, or &qu= ot;N/A" on failure.

*/
-const char *win32_version_string(struct gc_arena *g= c, bool add_name);
+c= onst char *win32_version_string(struct gc_arena *gc, bool add_exec_info);

/*
* Send the |size| by= tes in buffer |data| to the interactive service |pipe|

To view, visit change 944. To unsubscribe, or for help writing m= ail filters, visit settings<= /a>.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I39d660ebeec76280e4d4357192b= 74bf2c0980615
Gerrit-Change-Number: 944
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <lstipakov@...277...>= ;
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--awA6vww8by0=--