]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Use a more robust way to get dco-win version
authorLev Stipakov <lev@openvpn.net>
Fri, 9 Aug 2024 19:22:56 +0000 (21:22 +0200)
committerGert Doering <gert@greenie.muc.de>
Tue, 13 Aug 2024 06:36:32 +0000 (08:36 +0200)
The current way doesn't work if the device is already in use.

Starting from 1.3.0, dco-win creates a non-exclusive
control device \\.\ovpn-dco-ver which can be opened by
multiple apps and supports a single IOCTL to get
a version number.

https://github.com/OpenVPN/ovpn-dco-win/pull/76

This will be expecially handy later when checking which
features driver supports.

Change-Id: Ieb6f3a9d14d76000c1caf8ee1e959c6d0de832bf
Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20240809192257.24208-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg29009.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/dco_win.c

index e3ada76a88509ee1a42ceb8686556411ece270ac..3ec946ffb8673c97128d5e573e8ef690f68a8304 100644 (file)
@@ -389,9 +389,16 @@ dco_version_string(struct gc_arena *gc)
     OVPN_VERSION version;
     ZeroMemory(&version, sizeof(OVPN_VERSION));
 
-    /* try to open device by symbolic name */
-    HANDLE h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRITE,
-                          0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, NULL);
+    /* first, try a non-exclusive control device, available from 1.3.0 */
+    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
+                          0, NULL, OPEN_EXISTING, 0, NULL);
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        /* fallback to a "normal" device, this will fail if device is already in use */
+        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
+                       0, NULL, OPEN_EXISTING, 0, NULL);
+    }
 
     if (h == INVALID_HANDLE_VALUE)
     {