From: "cron2 (Code Review)" Date: Tue, 13 Aug 2024 06:55:21 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., lstipakov@...277... Message-ID: <45fabc205c9ac7fb05916ee2e2738e2ccbd67a6c-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="AWXuOC+n2dc="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Use a more robust way to get dco-win version List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: stipa Cc: plaisthos , flichtenheld , openvpn-devel --AWXuOC+n2dc= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/72= 3?usp=3Demail ) Change subject: Use a more robust way to get dco-win version ...................................................................... Use a more robust way to get dco-win version 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 Acked-by: Gert Doering Message-Id: <20240809192257.24208-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg29= 009.html Signed-off-by: Gert Doering --- M src/openvpn/dco_win.c 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index e3ada76..3ec946f 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -389,9 +389,16 @@ OVPN_VERSION version; ZeroMemory(&version, sizeof(OVPN_VERSION)); - /* try to open device by symbolic name */ - HANDLE h =3D CreateFile("\\\\.\\ovpn-dco", GENERIC_READ | GENERIC_WRIT= E, - 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 =3D CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ, + 0, NULL, OPEN_EXISTING, 0, NULL); + + if (h =3D=3D INVALID_HANDLE_VALUE) + { + /* fallback to a "normal" device, this will fail if device is alre= ady in use */ + h =3D CreateFile("\\\\.\\ovpn-dco", GENERIC_READ, + 0, NULL, OPEN_EXISTING, 0, NULL); + } if (h =3D=3D INVALID_HANDLE_VALUE) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/723?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: Ieb6f3a9d14d76000c1caf8ee1e959c6d0de832bf Gerrit-Change-Number: 723 Gerrit-PatchSet: 2 Gerrit-Owner: stipa Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --AWXuOC+n2dc= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

Use a more robust way to get dco-win version
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 sin= gle IOCTL to get
a version number.

https://github.com/OpenVPN/ovp= n-dco-win/pull/76

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

Change-Id: Ieb6f3a9d14d76000c1caf= 8ee1e959c6d0de832bf
Signed-off-by: Lev Stipakov <lev@...515...>Acked-by: Gert Doering <gert@...1296...>
Message-Id: <20240809= 192257.24208-1-gert@...1296...>
URL: https://www.mail-archive.com/ope= nvpn-devel@lists.sourceforge.net/msg29009.html
Signed-off-by: Gert Doeri= ng <gert@...1296...>
---
M src/openvpn/dco_win.c
1 file chan= ged, 10 insertions(+), 3 deletions(-)

diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c
index e3ada76..3ec946f 100644
--- a/src/openvpn/dco_win.= c
+++ b/src/openvpn/dco_win.c
@@ -389,9 +38= 9,16 @@
OVPN_VERSION version;
Zer= oMemory(&version, sizeof(OVPN_VERSION));

- /* try to open device by symbo= lic name */
- HANDLE= h =3D 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 =3D CreateFile("= ;\\\\.\\ovpn-dco-ver", GENERIC_READ,
+ 0, NULL, OPEN_EXISTING, 0, = NULL);
+
+ if (h =3D=3D INVALID_HANDLE_= VALUE)
+ {<= br>+ /* fallback to a &q= uot;normal" device, this will fail if device is already in use */
+ h =3D CreateFile= ("\\\\.\\ovpn-dco", GENERIC_READ,
+ 0, NULL, OPEN_EXISTING, 0, N= ULL);
+ }
if (h =3D=3D INVALID_HANDLE_VALUE) {

To view, visit change 723. To = unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ieb6f3a9d14d76000c1caf8ee1e9= 59c6d0de832bf
Gerrit-Change-Number: 723
Gerrit-PatchSet: 2
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
--AWXuOC+n2dc=--