Skip to contentSkip to conversation

In tap.c use DiInstallDevice to install the driver on a new adapter

PATCH In review [email protected]... 3 participants 3 messages Sep 3, 2020 – Sep 4, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 In tap.c use DiInstallDevice to install the driver on a new adapter

From: Selva Nair <[email protected]...>

As reported in Trac 1321, additional adapter instalaltion by tapctl.exe fails to fully setup the device node (some registry keys missing, error in setapi.dev.log etc.).
Although the exact cause of this failure is unclear, letting the Plug and Play subsystem handle the instalaltion by calling DiInsatllDevice() avoids it.

We let the system automatically choose the best driver by passing NULL for driverinfo to DiInstallDevice(). This also eliminates the need for enumerating all drivers in the Net class and selecting a matching one.

Somehow mingw-w64 fails to find DiInstallDriver() in newdev.lib although the header does define it. Use LoadLibrary() to locate it at run time (available in Vista and above).

Built using mingw and tested both the msi installer (code shared with libopenvpnmscia.dll) and tapctl.exe on Windows 10 64 bit.

Fixes Trac #1321
---
 config-msvc.h    |   1 +
 src/tapctl/tap.c | 231 +++++++++++++++++++------------------------------------
 2 files changed, 78 insertions(+), 154 deletions(-)
config-msvc.h +1 -0
index 8ef4897..f199bb2 100644
@@ -112,6 +112,7 @@
 #define HAVE_EC_GROUP_ORDER_BITS 1
 #define OPENSSL_NO_EC 1
 #define HAVE_EVP_CIPHER_CTX_RESET 1
+#define HAVE_DIINSTALLDEVICE 1
 
 #define PATH_SEPARATOR     '\\'
 #define PATH_SEPARATOR_STR "\\"
src/tapctl/tap.c +77 -154

286 lines not on this page · raw message

Signature · 1 line
2.1.4
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 1 line

+ HMODULE libnewdev = NULL;

I think we are moving to C99 so this could be defined closer to actual usage.

Tested with MSVC and mingw - compiled, built installer - installed - tested that tapctl creates
adapters which then can be used by non-admin users.

--
-Lev

#2 lore raw
In reply to [email protected]...

Your patch has been applied to the master and release/2.5 branch.

Minor typo in commit message ("instalaltion") fixed.

(I have not tested anything, fully trusting you and Lev here - thanks!)

commit f3f09541dcff3f0b307067bdf5dcaabc530db4c7 (master) commit 87b43ded380af06129ea59744d27684e36635c74 (release/2.5)

Author: Selva Nair
Date:   Thu Sep 3 19:56:44 2020 -0400
     In tap.c use DiInstallDevice to install the driver on a new adapter

     Signed-off-by: Selva Nair <[email protected]...>
     Acked-by: Lev Stipakov <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg20880.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering