From: "cron2 (Code Review)" Date: Mon, 5 May 2025 16:27:10 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., lstipakov@...277... Message-ID: <4d8507e3f3cc3295093216757d80228f3eddea00-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="9PHVtxg3yHE="; 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: stipa Cc: plaisthos , flichtenheld , openvpn-devel --9PHVtxg3yHE= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/94= 4?usp=3Demail ) 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), amd64 executable" we now show the exact build number, e.g.: "Windows version: 10.0.22631,amd64" Remove "pre-Win7" checks in a few places. Change-Id: I39d660ebeec76280e4d4357192b74bf2c0980615 Signed-off-by: Lev Stipakov Acked-by: Gert Doering Message-Id: <20250505122712.5214-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31= 566.html Signed-off-by: Gert Doering --- M src/openvpn/options.c M src/openvpn/ssl.c M src/openvpn/tun.c M src/openvpn/win32.c M src/openvpn/win32.h 5 files changed, 36 insertions(+), 95 deletions(-) diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 8c41dec..02970a7 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -4847,7 +4847,7 @@ show_windows_version(const unsigned int flags) { struct gc_arena gc =3D gc_new(); - msg(flags, "Windows version %s", win32_version_string(&gc, true)); + msg(flags, "Windows version: %s", win32_version_string(&gc)); gc_free(&gc); } #endif diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 23f6423..fd299ef 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -2060,7 +2060,7 @@ } buf_printf(&out, "IV_SSL=3D%s\n", get_ssl_library_version() ); #if defined(_WIN32) - buf_printf(&out, "IV_PLAT_VER=3D%s\n", win32_version_string(&g= c, false)); + buf_printf(&out, "IV_PLAT_VER=3D%s\n", win32_version_string(&g= c)); #else struct utsname u; uname(&u); 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..caa14d6 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,52 +1384,40 @@ } } +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) { - 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, ", "); + RtlGetVersionPtr fn =3D (RtlGetVersionPtr)GetProcAddress(hMod, "RtlGet= Version"); + if (!fn) + { + 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); + + 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 "); diff --git a/src/openvpn/win32.h b/src/openvpn/win32.h index 081beeb..685898c 100644 --- a/src/openvpn/win32.h +++ b/src/openvpn/win32.h @@ -292,20 +292,13 @@ bool win_wfp_uninit(const NET_IFINDEX index, const HANDLE msg_channel); -#define WIN_XP 0 -#define WIN_VISTA 1 -#define WIN_7 2 -#define WIN_8 3 -#define WIN_8_1 4 -#define WIN_10 5 - -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 with architecture info. + * + * @param gc gc arena to allocate string. + * @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); /* * 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: 4 Gerrit-Owner: stipa Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --9PHVtxg3yHE= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

win: refactor get_windows_version()

It&= #39;s 2025, and almost all clients now run on Windows 10 or newer.
Inste= ad of displaying:

"Windows version 10.0 (Windows 10 or greate= r), amd64 executable"

we now show the exact build number, e.g.:=

"Windows version: 10.0.22631,amd64"

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

Change-Id: I39d660ebeec76280= e4d4357192b74bf2c0980615
Signed-off-by: Lev Stipakov <lev@...515...&g= t;
Acked-by: Gert Doering <gert@...1296...>
Message-Id: <202= 50505122712.5214-1-gert@...1296...>
URL: https://www.mail-archive.com= /openvpn-devel@lists.sourceforge.net/msg31566.html
Signed-off-by: Gert D= oering <gert@...1296...>
---
M src/openvpn/options.c
M src/o= penvpn/ssl.c
M src/openvpn/tun.c
M src/openvpn/win32.c
M src/openv= pn/win32.h
5 files changed, 36 insertions(+), 95 deletions(-)

diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index 8c41dec..02970a7 100644
--- a/src/openvpn/options.= c
+++ b/src/openvpn/options.c
@@ -4847,7 +4= 847,7 @@
show_windows_version(const unsigned int flags)
{
struct gc_arena gc =3D gc_new();
- msg(flags, "Windo= ws version %s", win32_version_string(&gc, true));
+ msg(flags, "Windows version= : %s", win32_version_string(&gc));
gc_free(&a= mp;gc);
}
#endif
diff --g= it a/src/openvpn/ssl.c b/src/openvpn/ssl.c
index 23f6423..f= d299ef 100644
--- a/src/openvpn/ssl.c
+++ b= /src/openvpn/ssl.c
@@ -2060,7 +2060,7 @@
= }
buf_printf(&out, "IV_SSL= =3D%s\n", get_ssl_library_version() );
#if defined(_W= IN32)
- buf_= printf(&out, "IV_PLAT_VER=3D%s\n", win32_version_string(&= gc, false));
+ = buf_printf(&out, "IV_PLAT_VER=3D%s\n", win32_version_str= ing(&gc));
#else
struct u= tsname u;
uname(&u);
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));

- /* disabl= e slow address validation on Windows 7 and higher */
- if (win32_version_info() >=3D WI= N_7)
- {<= br>- argv_printf_cat(&= amp;argv, "%s", "validate=3Dno");
- }
+ /* disable slow address validation */<= br>+ argv_printf_cat(&am= p;argv, "%s", "validate=3Dno");

/* Treat errors while adding as non-fatal as we do not = check for duplicates */
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));<= /span>

- = /* disable slow address validation on Windows 7 and higher */
- /* only= for DNS */
- = if (is_dns && win32_version_info() >=3D WIN_7)
<= span style=3D"color: hsl(120, 100%, 40%);">+ /* disable slow= address validation for DNS */

+ if (is_dns)
{
argv_printf_cat(&argv, "%s&quo= t;, "validate=3Dno");
}diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c
index edac71e..caa14d6 100644

--- a/src/openvpn/win32.c=
+++ b/src/openvpn/win32.c
@@ -1283,42 +128= 3,6 @@
return true;
}

-int
-win32_version_info(void)
-{
- if (!IsWindowsXPOrGreater())
- {
- msg(M_FATAL, "Error: Windows version must be X= P or greater.");
-= }
-
- if (!IsWindowsVistaOrGreater())
- {
- return WIN_XP;
- }
-
-= if (!IsWindows7OrGreater())
- {
- = return WIN_VISTA;
- = }
-
- if (!IsWindows8OrGreater())<= br>- {
- return WIN_7;
- }
-
- i= f (!IsWindows8Point1OrGreater())
- {
- = return WIN_8;
- }=
-
- if (!IsWindows10OrGreater())- {
- return WIN_8_1;
- }
-
- r= eturn WIN_10;
-}=
-
typedef en= um {
ARCH_X86,
ARCH_AMD64,=
@@ -1420,52 +1384,40 @@
}
}=

+t= ypedef LONG (WINAPI *RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);
+
const char *

-win32_version_string(stru= ct gc_arena *gc, bool add_name)
+win32_version_string(struct gc_arena *gc)
{
- int version =3D win3= 2_version_info();
- = struct buffer out =3D alloc_buf_gc(256, gc);
-
- switch (version)
+ if (!hMod)
{

- case = WIN_XP:
- bu= f_printf(&out, "5.1%s", add_name ? " (Windows XP)" = : "");
- = break;
-<= br>- case WIN_VISTA:
- buf_printf(&= ;out, "6.0%s", add_name ? " (Windows Vista)" : "&q= uot;);
- bre= ak;
-
- case WIN_7:
- buf_printf(&out, "6.= 1%s", add_name ? " (Windows 7)" : "");
<= span style=3D"color: hsl(0, 100%, 40%);">- break;

-
- case WIN_8:
- buf_printf(&out, "6.2%s", add_nam= e ? " (Windows 8)" : "");
- break;
-
-= case WIN_8_1:
-= buf_printf(&out, "6.3%s", add_name ? " (Wind= ows 8.1)" : "");
- break;
-
- case W= IN_10:
- buf= _printf(&out, "10.0%s", add_name ? " (Windows 10 or grea= ter)" : "");
- break;
- default:
- msg(M_NONFA= TAL, "Unknown Windows version: %d", version);
- buf_printf(&out, "0.= 0%s", add_name ? " (unknown)" : "");
- break;

+ return "N/A";

}

- buf_printf(&out, ", ");
+ RtlGetVersionPtr fn =3D (RtlGetVer= sionPtr)GetProcAddress(hMod, "RtlGetVersion");
+ if (!fn)
+ {
+ return "N/A";
+ }
+
+ R= TL_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.dwMinorVersion, rovi.dwBuildNumber);
<= span style=3D"color: hsl(120, 100%, 40%);">+
+ 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 ");

diff --git a/src/openvpn/win32.h b/src/openvpn/win32.h<= br>index 081beeb..685898c 100644
--- a/src/openvpn/wi= n32.h
+++ b/src/openvpn/win32.h
@@ -292,20 = +292,13 @@

bool win_wfp_uninit(const NET= _IFINDEX index, const HANDLE msg_channel);

-#define WIN_XP 0
-#define WIN_VISTA 1
-#define WIN_7 2
-#define WIN_8 3
-#define WIN_8_1 4
-#define WIN_10 5
-
-int win32_version_info(void);
-
-/*=
- * String representat= ion of Windows version number and name, see
- * https://msdn.microsoft.com/en-us/library/windows/d= esktop/ms724832(v=3Dvs.85).aspx
+/**
+ * @= brief Get Windows version string with architecture info.
+ *
+ * @param gc gc arena to allocate string.
+ * @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);

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

To v= iew, visit change 944. To unsubscribe, or for help writing mail filters, visit <= a href=3D"http://gerrit.openvpn.net/settings">settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I39d660ebeec76280e4d4357192b= 74bf2c0980615
Gerrit-Change-Number: 944
Gerrit-PatchSet: 4
Gerrit-Owner: stipa <lstipakov@...277...>= ;
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: merged
--9PHVtxg3yHE=--