Skip to contentSkip to conversation

openvpnmsica: add ovpn-dco custom actions

PATCH Superseded Lev Stipakov 2 participants 4 messages May 20, 2021 – Feb 20, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 openvpnmsica: add ovpn-dco custom actions

From: Lev Stipakov <[email protected]...>

Add two custom actions to service ovpn-dco driver installation.

- EvaluateDriver

Runs under user privileges. Determines what action (install/uninstall) should be performed on ovpn-dco component.

- ProcessDriver

Runs under SYSTEM privileges. Performs driver (un)installation. During uninstall, all existing adapters with given hwid (ovpn-dco) are removed.

The logic is inspired by custom actions from tap-windows6 installer
(https://github.com/OpenVPN/tap-windows6/tree/master/msm).

---
 src/openvpnmsica/Makefile.am    |   2 +-
 src/openvpnmsica/openvpnmsica.c | 348 ++++++++++++++++++++++++++++++++
 src/openvpnmsica/openvpnmsica.h |  30 +++
 3 files changed, 379 insertions(+), 1 deletion(-)
src/openvpnmsica/Makefile.am +1 -1
index 9d18854a..a5d9c170 100644
@@ -42,7 +42,7 @@ libopenvpnmsica_la_CFLAGS = \
 	-UNTDDI_VERSION -U_WIN32_WINNT \
 	-D_WIN32_WINNT=_WIN32_WINNT_VISTA \
 	-Wl,--kill-at
-libopenvpnmsica_la_LDFLAGS = -ladvapi32 -lole32 -lmsi -lsetupapi -liphlpapi -lshell32 -lshlwapi -lversion -no-undefined -avoid-version
+libopenvpnmsica_la_LDFLAGS = -ladvapi32 -lole32 -lmsi -lsetupapi -liphlpapi -lshell32 -lshlwapi -lversion -lnewdev -no-undefined -avoid-version
 endif
 
 libopenvpnmsica_la_SOURCES = \
src/openvpnmsica/openvpnmsica.c +348 -0

370 lines not on this page · raw message

src/openvpnmsica/openvpnmsica.h +30 -0
index 5af68470..f82af4a4 100644
@@ -88,6 +88,10 @@ extern "C" {
  *   with semicolon delimited list of all installed adapter GUIDs and active adapter GUIDs
  *   respectively.
  *
+ * - Finds existing ovpn-dco adapters and set OVPNDCOADAPTERS and ACTIVEOVPNDCOADAPTERS properties
+ *   with semicolon delimited list of all installed adapter GUIDs and active adapter GUIDs
+ *   respectively.
+ *
  * @param hInstall      Handle to the installation provided to the DLL custom action
  *
  * @return ERROR_SUCCESS on success; An error code otherwise
@@ -147,6 +151,32 @@ DLLEXP_DECL UINT __stdcall
 ProcessDeferredAction(_In_ MSIHANDLE hInstall);
 
 
+/**
+ * Check what operation shall be performed on ovpn-dco driver
+ * and set data value (path to inf and user temp dir) for ProcessDriver action.
+ *
+ * @param hInstall      Handle to the installation provided to the DLL custom action
+ *
+ * @return ERROR_SUCCESS on success; An error code otherwise
+ *         See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
+ */
+DLLEXP_DECL UINT __stdcall
+EvaluateDriver(_In_ MSIHANDLE hInstall);
+
+
+/**
+ * Install or uninstall ovpn-dco driver, removing all adapters using that driver.
+ * If reboot is required, creates reboot indication file in user's temp directory
+ *
+ * @param hInstall      Handle to the installation provided to the DLL custom action
+ *
+ * @return ERROR_SUCCESS on success; An error code otherwise
+ *         See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
+ */
+DLLEXP_DECL UINT __stdcall
+ProcessDriver(_In_ MSIHANDLE hInstall);
+
+
 /**
  * Schedule reboot after installation if reboot
  * indication file is found in user's temp directory
Signature · 1 line
2.23.0.windows.1
#1 lore raw

PATCH v2 1/1 openvpnmsica: add ovpn-dco custom actions

From: Lev Stipakov <[email protected]...>

Add two custom actions to service ovpn-dco driver installation.

- EvaluateDriver

Runs under user privileges. Determines what action (install/uninstall) should be performed on ovpn-dco component.

- ProcessDriver

Runs under SYSTEM privileges. Performs driver (un)installation. During uninstall, all existing adapters with given hwid (ovpn-dco) are removed.

The logic is inspired by custom actions from tap-windows6 installer
(https://github.com/OpenVPN/tap-windows6/tree/master/msm).

---
v2: fix string conversion warning

 src/openvpnmsica/Makefile.am    |   2 +-
 src/openvpnmsica/openvpnmsica.c | 348 ++++++++++++++++++++++++++++++++
 src/openvpnmsica/openvpnmsica.h |  30 +++
 3 files changed, 379 insertions(+), 1 deletion(-)
src/openvpnmsica/Makefile.am +1 -1
index a1a04afe..95482940 100644
@@ -42,7 +42,7 @@ libopenvpnmsica_la_CFLAGS = \
 	-UNTDDI_VERSION -U_WIN32_WINNT \
 	-D_WIN32_WINNT=_WIN32_WINNT_VISTA \
 	-Wl,--kill-at
-libopenvpnmsica_la_LDFLAGS = -ladvapi32 -lole32 -lmsi -lsetupapi -liphlpapi -lshell32 -lshlwapi -lversion -no-undefined -avoid-version
+libopenvpnmsica_la_LDFLAGS = -ladvapi32 -lole32 -lmsi -lsetupapi -liphlpapi -lshell32 -lshlwapi -lversion -lnewdev -no-undefined -avoid-version
 endif
 
 libopenvpnmsica_la_SOURCES = \
src/openvpnmsica/openvpnmsica.c +348 -0

370 lines not on this page · raw message

src/openvpnmsica/openvpnmsica.h +30 -0
index 8c53de45..a2d2d3f4 100644
@@ -88,6 +88,10 @@ extern "C" {
  *   with semicolon delimited list of all installed adapter GUIDs and active adapter GUIDs
  *   respectively.
  *
+ * - Finds existing ovpn-dco adapters and set OVPNDCOADAPTERS and ACTIVEOVPNDCOADAPTERS properties
+ *   with semicolon delimited list of all installed adapter GUIDs and active adapter GUIDs
+ *   respectively.
+ *
  * @param hInstall      Handle to the installation provided to the DLL custom action
  *
  * @return ERROR_SUCCESS on success; An error code otherwise
@@ -147,6 +151,32 @@ DLLEXP_DECL UINT __stdcall
 ProcessDeferredAction(_In_ MSIHANDLE hInstall);
 
 
+/**
+ * Check what operation shall be performed on ovpn-dco driver
+ * and set data value (path to inf and user temp dir) for ProcessDriver action.
+ *
+ * @param hInstall      Handle to the installation provided to the DLL custom action
+ *
+ * @return ERROR_SUCCESS on success; An error code otherwise
+ *         See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
+ */
+DLLEXP_DECL UINT __stdcall
+EvaluateDriver(_In_ MSIHANDLE hInstall);
+
+
+/**
+ * Install or uninstall ovpn-dco driver, removing all adapters using that driver.
+ * If reboot is required, creates reboot indication file in user's temp directory
+ *
+ * @param hInstall      Handle to the installation provided to the DLL custom action
+ *
+ * @return ERROR_SUCCESS on success; An error code otherwise
+ *         See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
+ */
+DLLEXP_DECL UINT __stdcall
+ProcessDriver(_In_ MSIHANDLE hInstall);
+
+
 /**
  * Schedule reboot after installation if reboot
  * indication file is found in user's temp directory
Signature · 1 line
2.23.0.windows.1
#2 lore raw

PATCH v3 1/1 openvpnmsica: add ovpn-dco custom actions

From: Lev Stipakov <[email protected]...>

Add two custom actions to service ovpn-dco driver installation.

- EvaluateDriver

Runs under user privileges. Determines what action (install/uninstall) should be performed on ovpn-dco component.

- ProcessDriver

Runs under SYSTEM privileges. Performs driver (un)installation. During uninstall, all existing adapters with given hwid (ovpn-dco) are removed.

The logic is inspired by custom actions from tap-windows6 installer
(https://github.com/OpenVPN/tap-windows6/tree/master/msm).

---

v3:
- Remove GetComponentNameById() and use hardcoded component name instead
- Use WCHAR consistently
- add msg() calls on failure paths
- fix a few memory leaks
- minor cleanups

v2:
- fix string conversion warning

 src/openvpnmsica/Makefile.am    |   2 +-
 src/openvpnmsica/openvpnmsica.c | 315 ++++++++++++++++++++++++++++++--
 src/openvpnmsica/openvpnmsica.h |  30 +++
 3 files changed, 334 insertions(+), 13 deletions(-)
src/openvpnmsica/Makefile.am +1 -1
index a1a04afe..95482940 100644
@@ -42,7 +42,7 @@ libopenvpnmsica_la_CFLAGS = \
 	-UNTDDI_VERSION -U_WIN32_WINNT \
 	-D_WIN32_WINNT=_WIN32_WINNT_VISTA \
 	-Wl,--kill-at
-libopenvpnmsica_la_LDFLAGS = -ladvapi32 -lole32 -lmsi -lsetupapi -liphlpapi -lshell32 -lshlwapi -lversion -no-undefined -avoid-version
+libopenvpnmsica_la_LDFLAGS = -ladvapi32 -lole32 -lmsi -lsetupapi -liphlpapi -lshell32 -lshlwapi -lversion -lnewdev -no-undefined -avoid-version
 endif
 
 libopenvpnmsica_la_SOURCES = \
src/openvpnmsica/openvpnmsica.c +303 -12

373 lines not on this page · raw message

src/openvpnmsica/openvpnmsica.h +30 -0
index 8c53de45..a2d2d3f4 100644
@@ -88,6 +88,10 @@ extern "C" {
  *   with semicolon delimited list of all installed adapter GUIDs and active adapter GUIDs
  *   respectively.
  *
+ * - Finds existing ovpn-dco adapters and set OVPNDCOADAPTERS and ACTIVEOVPNDCOADAPTERS properties
+ *   with semicolon delimited list of all installed adapter GUIDs and active adapter GUIDs
+ *   respectively.
+ *
  * @param hInstall      Handle to the installation provided to the DLL custom action
  *
  * @return ERROR_SUCCESS on success; An error code otherwise
@@ -147,6 +151,32 @@ DLLEXP_DECL UINT __stdcall
 ProcessDeferredAction(_In_ MSIHANDLE hInstall);
 
 
+/**
+ * Check what operation shall be performed on ovpn-dco driver
+ * and set data value (path to inf and user temp dir) for ProcessDriver action.
+ *
+ * @param hInstall      Handle to the installation provided to the DLL custom action
+ *
+ * @return ERROR_SUCCESS on success; An error code otherwise
+ *         See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
+ */
+DLLEXP_DECL UINT __stdcall
+EvaluateDriver(_In_ MSIHANDLE hInstall);
+
+
+/**
+ * Install or uninstall ovpn-dco driver, removing all adapters using that driver.
+ * If reboot is required, creates reboot indication file in user's temp directory
+ *
+ * @param hInstall      Handle to the installation provided to the DLL custom action
+ *
+ * @return ERROR_SUCCESS on success; An error code otherwise
+ *         See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
+ */
+DLLEXP_DECL UINT __stdcall
+ProcessDriver(_In_ MSIHANDLE hInstall);
+
+
 /**
  * Schedule reboot after installation if reboot
  * indication file is found in user's temp directory
Signature · 1 line
2.23.0.windows.1
Acked-by on v3 1/1
#3 lore raw

Thanks to Simon for testing & advising Lev here.

I would have preferred to have the WCHAR fixes decoupled from "new functionality" - that makes reviewing easier. This said, the WCHAR fixes look good, and the rest looks at least "reasonable" - as I have no much idea what's going on there I can only look at "safe pointer use" etc.

Your patch has been applied to the master branch.

commit 055605783ee08767d871fbeffb6871368bdf1ada

Author: Lev Stipakov
Date:   Mon Feb 14 14:24:09 2022 +0200
     openvpnmsica: add ovpn-dco custom actions

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

--
kind regards,

Gert Doering