Skip to contentSkip to conversation

openvpnmsica: Remove required Windows driver certification detection

PATCH In review Simon Rozman 3 participants 37 messages Mar 9, 2020 – Sep 24, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/12 openvpnmsica: Remove required Windows driver certification detection

The MSI packages are switching to TAP-Windows6 and Wintun MSM modules to install the TAP/TUN driver. The MSM modules have built-in Windows version detection already.

This commit is now-dead-code clean up with uncrustification.

---
 src/openvpnmsica/openvpnmsica.c | 129 +-------------------------------
 1 file changed, 3 insertions(+), 126 deletions(-)
src/openvpnmsica/openvpnmsica.c +3 -126
index 16381ea1..4236330a 100644
@@ -203,128 +203,6 @@ _openvpnmsica_debug_popup(_In_z_ LPCTSTR szFunctionName)
 #endif /* ifdef _DEBUG */
 
 
-/**
- * Detects Windows version and sets DRIVERCERTIFICATION property to "", "whql", or "attsgn"
- * accordingly.
- *
- * @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
- */
-static UINT
-openvpnmsica_set_driver_certification(_In_ MSIHANDLE hInstall)
-{
-    UINT uiResult;
-
-    /* Get Windows version. */
-#ifdef _MSC_VER
-#pragma warning(push)
-#pragma warning(disable: 4996) /* 'GetVersionExW': was declared deprecated. */
-#endif
-    OSVERSIONINFOEX ver_info = { .dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX) };
-    if (!GetVersionEx((LPOSVERSIONINFO)&ver_info))
-    {
-        uiResult = GetLastError();
-        msg(M_NONFATAL | M_ERRNO, "%s: GetVersionEx() failed", __FUNCTION__);
-        return uiResult;
-    }
-#ifdef _MSC_VER
-#pragma warning(pop)
-#endif
-
-    /* The Windows version is usually spoofed, check using RtlGetVersion(). */
-    TCHAR szDllPath[0x1000];
-    ExpandEnvironmentStrings(TEXT("%SystemRoot%\\System32\\ntdll.dll"), szDllPath,
-#ifdef UNICODE
-                             _countof(szDllPath)
-#else
-                             _countof(szDllPath) - 1
-#endif
-                             );
-    HMODULE hNtDllModule = LoadLibrary(szDllPath);
-    if (hNtDllModule)
-    {
-        typedef NTSTATUS (WINAPI* fnRtlGetVersion)(PRTL_OSVERSIONINFOW);
-        fnRtlGetVersion RtlGetVersion = (fnRtlGetVersion)GetProcAddress(hNtDllModule, "RtlGetVersion");
-        if (RtlGetVersion)
-        {
-            RTL_OSVERSIONINFOW rtl_ver_info = { .dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOW) };
-            if (RtlGetVersion(&rtl_ver_info) == 0)
-            {
-                if (
-                    rtl_ver_info.dwMajorVersion >  ver_info.dwMajorVersion
-                    || rtl_ver_info.dwMajorVersion == ver_info.dwMajorVersion && rtl_ver_info.dwMinorVersion >  ver_info.dwMinorVersion
-                    || rtl_ver_info.dwMajorVersion == ver_info.dwMajorVersion && rtl_ver_info.dwMinorVersion == ver_info.dwMinorVersion && rtl_ver_info.dwBuildNumber > ver_info.dwBuildNumber)
-                {
-                    /* We got RtlGetVersion() and it reported newer version than GetVersionEx(). */
-                    ver_info.dwMajorVersion = rtl_ver_info.dwMajorVersion;
-                    ver_info.dwMinorVersion = rtl_ver_info.dwMinorVersion;
-                    ver_info.dwBuildNumber  = rtl_ver_info.dwBuildNumber;
-                    ver_info.dwPlatformId   = rtl_ver_info.dwPlatformId;
-                }
-            }
-        }
-
-        FreeLibrary(hNtDllModule);
-    }
-
-    /* We don't trust RtlGetVersion() either. Check the version resource of kernel32.dll. */
-    ExpandEnvironmentStrings(TEXT("%SystemRoot%\\System32\\kernel32.dll"), szDllPath,
-#ifdef UNICODE
-                             _countof(szDllPath)
-#else
-                             _countof(szDllPath) - 1
-#endif
-                             );
-
-    DWORD dwHandle;
-    DWORD dwVerInfoSize = GetFileVersionInfoSize(szDllPath, &dwHandle);
-    if (dwVerInfoSize)
-    {
-        LPVOID pVersionInfo = malloc(dwVerInfoSize);
-        if (pVersionInfo)
-        {
-            /* Read version info. */
-            if (GetFileVersionInfo(szDllPath, dwHandle, dwVerInfoSize, pVersionInfo))
-            {
-                /* Get the value for the root block. */
-                UINT uiSize = 0;
-                VS_FIXEDFILEINFO *pVSFixedFileInfo = NULL;
-                if (VerQueryValue(pVersionInfo, TEXT("\\"), &pVSFixedFileInfo, &uiSize) && uiSize && pVSFixedFileInfo)
-                {
-                    if (HIWORD(pVSFixedFileInfo->dwProductVersionMS) >  ver_info.dwMajorVersion
-                        || HIWORD(pVSFixedFileInfo->dwProductVersionMS) == ver_info.dwMajorVersion && LOWORD(pVSFixedFileInfo->dwProductVersionMS) >  ver_info.dwMinorVersion
-                        || HIWORD(pVSFixedFileInfo->dwProductVersionMS) == ver_info.dwMajorVersion && LOWORD(pVSFixedFileInfo->dwProductVersionMS) == ver_info.dwMinorVersion && HIWORD(pVSFixedFileInfo->dwProductVersionLS) > ver_info.dwBuildNumber)
-                    {
-                        /* We got kernel32.dll version and it is newer. */
-                        ver_info.dwMajorVersion = HIWORD(pVSFixedFileInfo->dwProductVersionMS);
-                        ver_info.dwMinorVersion = LOWORD(pVSFixedFileInfo->dwProductVersionMS);
-                        ver_info.dwBuildNumber  = HIWORD(pVSFixedFileInfo->dwProductVersionLS);
-                    }
-                }
-            }
-
-            free(pVersionInfo);
-        }
-        else
-        {
-            msg(M_NONFATAL, "%s: malloc(%u) failed", __FUNCTION__, dwVerInfoSize);
-        }
-    }
-
-    uiResult = MsiSetProperty(hInstall, TEXT("DRIVERCERTIFICATION"), ver_info.dwMajorVersion >= 10 ? ver_info.wProductType > VER_NT_WORKSTATION ? TEXT("whql") : TEXT("attsgn") : TEXT(""));
-    if (uiResult != ERROR_SUCCESS)
-    {
-        SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() to set GetLastError(). But we do have an error code. Set last error manually. */
-        msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"DRIVERCERTIFICATION\") failed", __FUNCTION__);
-        return uiResult;
-    }
-
-    return ERROR_SUCCESS;
-}
-
-
 /**
  * Detects if the OpenVPNService service is in use (running or paused) and sets
  * OPENVPNSERVICE to the service process PID, or its path if it is set to
@@ -451,7 +329,6 @@ FindSystemInfo(_In_ MSIHANDLE hInstall)
 
     OPENVPNMSICA_SAVE_MSI_SESSION(hInstall);
 
-    openvpnmsica_set_driver_certification(hInstall);
     openvpnmsica_set_openvpnserv_state(hInstall);
 
     if (bIsCoInitialized)
@@ -829,7 +706,7 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
         goto cleanup_hViewST_close;
     }
 
-    for (;;)
+    for (;; )
     {
         /* Fetch one record from the view. */
         MSIHANDLE hRecord = 0;
@@ -998,7 +875,7 @@ cleanup_szSeqFilename:
     if (uiResult != ERROR_SUCCESS)
     {
         /* Clean-up sequence files. */
-        for (size_t i = _countof(szActionNames); i--;)
+        for (size_t i = _countof(szActionNames); i--; )
         {
             if (szSeqFilename[i][0])
             {
@@ -1186,7 +1063,7 @@ cleanup_session:
         uiResult = ERROR_SUCCESS;
     }
 
-    for (size_t i = MSICA_CLEANUP_ACTION_COUNT; i--;)
+    for (size_t i = MSICA_CLEANUP_ACTION_COUNT; i--; )
     {
         msica_op_seq_free(&session.seq_cleanup[i]);
     }
Signature · 1 line
2.24.1.windows.2
#1 lore raw

PATCH 2/12 openvpnmsica: Fix TAPInterface.DisplayName field interpretation

The DisplayName field type is Filename in the MSI database. This means it must be authored as "8.3" filename, or "8.3|long filename".

This issue does not appear until interface names grow longer than 8 characters, or contain characters invalid in 8.3 filename notation.

---
 src/openvpnmsica/openvpnmsica.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
src/openvpnmsica/openvpnmsica.c +6 -3
index 4236330a..e1f0b77d 100644
@@ -2,7 +2,7 @@
  *  openvpnmsica -- Custom Action DLL to provide OpenVPN-specific support to MSI packages
  *                  https://community.openvpn.net/openvpn/wiki/OpenVPNMSICA
  *
- *  Copyright (C) 2018 Simon Rozman <[email protected]...>
+ *  Copyright (C) 2018-2020 Simon Rozman <[email protected]...>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2
@@ -752,6 +752,9 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
         {
             goto cleanup_hRecord;
         }
+        /* `DisplayName` field type is [Filename](https://docs.microsoft.com/en-us/windows/win32/msi/filename), which is either "8.3|long name" or "8.3". */
+        LPTSTR szDisplayNameEx = _tcschr(szDisplayName, TEXT('|'));
+        szDisplayNameEx = szDisplayNameEx != NULL ? szDisplayNameEx + 1 : szDisplayName;
 
         if (iAction > INSTALLSTATE_BROKEN)
         {
@@ -796,7 +799,7 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
                         msica_op_tap_interface_create,
                         MSICA_INTERFACE_TICK_SIZE,
                         NULL,
-                        szDisplayName));
+                        szDisplayNameEx));
             }
             else
             {
@@ -807,7 +810,7 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
                         msica_op_tap_interface_delete_by_name,
                         MSICA_INTERFACE_TICK_SIZE,
                         NULL,
-                        szDisplayName));
+                        szDisplayNameEx));
             }
 
             /* The amount of tick space to add for each interface to progress indicator. */
Signature · 1 line
2.24.1.windows.2
#3 lore raw

PATCH 3/12 tapctl: Update documentation

In reply to Simon Rozman
---
 src/tapctl/tap.c | 17 ++++++++---------
 src/tapctl/tap.h | 18 +++++++++---------
 2 files changed, 17 insertions(+), 18 deletions(-)
src/tapctl/tap.c +8 -9
index 464ce725..b8249919 100644
@@ -2,7 +2,7 @@
  *  tapctl -- Utility to manipulate TUN/TAP interfaces on Windows
  *            https://community.openvpn.net/openvpn/wiki/Tapctl
  *
- *  Copyright (C) 2018 Simon Rozman <[email protected]...>
+ *  Copyright (C) 2018-2020 Simon Rozman <[email protected]...>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2
@@ -51,15 +51,15 @@ const static TCHAR szInterfaceRegKeyPathTemplate[] = TEXT("SYSTEM\\CurrentContro
  * Checks device install parameters if a system reboot is required.
  *
  * @param hDeviceInfoSet  A handle to a device information set that contains a device
- *                      information element that represents the device for which to
+ *                      information element that represents the device.
  *
  * @param pDeviceInfoData  A pointer to an SP_DEVINFO_DATA structure that specifies the
  *                      device information element in hDeviceInfoSet.
  *
- * @param pbRebootRequired  A pointer to a BOOL flag. If the interface installation requires
- *                      a system restart, this flag is set to TRUE. Otherwise, the flag is
- *                      left unmodified. This allows the flag to be globally initialized to
- *                      FALSE and reused for multiple interface installations.
+ * @param pbRebootRequired  A pointer to a BOOL flag. If the device requires a system restart,
+ *                      this flag is set to TRUE. Otherwise, the flag is left unmodified. This
+ *                      allows the flag to be globally initialized to FALSE and reused for multiple
+ *                      interface manipulations.
  *
  * @return ERROR_SUCCESS on success; Win32 error code otherwise
  **/
@@ -244,7 +244,7 @@ get_reg_string(
  * Returns network interface ID.
  *
  * @param hDeviceInfoSet  A handle to a device information set that contains a device
- *                      information element that represents the device for which to
+ *                      information element that represents the device.
  *
  * @param pDeviceInfoData  A pointer to an SP_DEVINFO_DATA structure that specifies the
  *                      device information element in hDeviceInfoSet.
@@ -330,8 +330,7 @@ get_net_interface_guid(
  * Returns a specified Plug and Play device property.
  *
  * @param hDeviceInfoSet  A handle to a device information set that contains a device
- *                      information element that represents the device for which to
- *                      retrieve a Plug and Play property.
+ *                      information element that represents the device.
  *
  * @param pDeviceInfoData  A pointer to an SP_DEVINFO_DATA structure that specifies the
  *                      device information element in hDeviceInfoSet.
src/tapctl/tap.h +9 -9
index f74a39df..ca66e5da 100644
@@ -2,7 +2,7 @@
  *  tapctl -- Utility to manipulate TUN/TAP interfaces on Windows
  *            https://community.openvpn.net/openvpn/wiki/Tapctl
  *
- *  Copyright (C) 2018 Simon Rozman <[email protected]...>
+ *  Copyright (C) 2018-2020 Simon Rozman <[email protected]...>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2
@@ -41,10 +41,10 @@
  *                      of the device. This pointer is optional and can be NULL. Default value
  *                      is root\tap0901.
  *
- * @param pbRebootRequired  A pointer to a BOOL flag. If the interface installation requires
- *                      a system restart, this flag is set to TRUE. Otherwise, the flag is
- *                      left unmodified. This allows the flag to be globally initialized to
- *                      FALSE and reused for multiple interface installations.
+ * @param pbRebootRequired  A pointer to a BOOL flag. If the device requires a system restart,
+ *                      this flag is set to TRUE. Otherwise, the flag is left unmodified. This
+ *                      allows the flag to be globally initialized to FALSE and reused for multiple
+ *                      interface manipulations.
  *
  * @param pguidInterface  A pointer to GUID that receives network interface ID.
  *
@@ -70,10 +70,10 @@ tap_create_interface(
  *
  * @param pguidInterface  A pointer to GUID that contains network interface ID.
  *
- * @param pbRebootRequired  A pointer to a BOOL flag. If the interface installation requires
- *                      a system restart, this flag is set to TRUE. Otherwise, the flag is
- *                      left unmodified. This allows the flag to be globally initialized to
- *                      FALSE and reused for multiple interface installations.
+ * @param pbRebootRequired  A pointer to a BOOL flag. If the device requires a system restart,
+ *                      this flag is set to TRUE. Otherwise, the flag is left unmodified. This
+ *                      allows the flag to be globally initialized to FALSE and reused for multiple
+ *                      interface manipulations.
  *
  * @return ERROR_SUCCESS on success; Win32 error code otherwise
  **/
Signature · 1 line
2.24.1.windows.2
#5 lore raw

PATCH 4/12 tapctl: Add functions for enabling/disabling adapters

In reply to Simon Rozman
---
 src/tapctl/tap.c | 287 ++++++++++++++++++++++++++++++++++++++++-------
 src/tapctl/tap.h |  28 +++++
 2 files changed, 275 insertions(+), 40 deletions(-)
src/tapctl/tap.c +247 -40
index b8249919..576f6740 100644
@@ -47,6 +47,28 @@ const static TCHAR szInterfaceRegKeyPathTemplate[] = TEXT("SYSTEM\\CurrentContro
 #define INTERFACE_REGKEY_PATH_MAX (_countof(TEXT("SYSTEM\\CurrentControlSet\\Control\\Network\\")) - 1 + 38 + _countof(TEXT("\\")) - 1 + 38 + _countof(TEXT("\\Connection")))
 
 
+/**
+ * Function that performs a specific task on a device
+ *
+ * @param hDeviceInfoSet  A handle to a device information set that contains a device
+ *                      information element that represents the device.
+ *
+ * @param pDeviceInfoData  A pointer to an SP_DEVINFO_DATA structure that specifies the
+ *                      device information element in hDeviceInfoSet.
+ *
+ * @param pbRebootRequired  A pointer to a BOOL flag. If the device requires a system restart,
+ *                      this flag is set to TRUE. Otherwise, the flag is left unmodified. This
+ *                      allows the flag to be globally initialized to FALSE and reused for multiple
+ *                      interface manipulations.
+ *
+ * @return ERROR_SUCCESS on success; Win32 error code otherwise
+ **/
+typedef DWORD (*devop_func_t)(
+    _In_ HDEVINFO hDeviceInfoSet,
+    _In_ PSP_DEVINFO_DATA pDeviceInfoData,
+    _Inout_ LPBOOL pbRebootRequired);
+
+
 /**
  * Checks device install parameters if a system reboot is required.
  *
@@ -94,6 +116,186 @@ check_reboot(
 }
 
 
+/**
+ * Deletes the device.
+ *
+ * @param hDeviceInfoSet  A handle to a device information set that contains a device
+ *                      information element that represents the device.
+ *
+ * @param pDeviceInfoData  A pointer to an SP_DEVINFO_DATA structure that specifies the
+ *                      device information element in hDeviceInfoSet.
+ *
+ * @param pbRebootRequired  A pointer to a BOOL flag. If the device requires a system restart,
+ *                      this flag is set to TRUE. Otherwise, the flag is left unmodified. This
+ *                      allows the flag to be globally initialized to FALSE and reused for multiple
+ *                      interface manipulations.
+ *
+ * @return ERROR_SUCCESS on success; Win32 error code otherwise
+ **/
+static DWORD
+delete_device(
+    _In_ HDEVINFO hDeviceInfoSet,
+    _In_ PSP_DEVINFO_DATA pDeviceInfoData,
+    _Inout_ LPBOOL pbRebootRequired)
+{
+    SP_REMOVEDEVICE_PARAMS params =
+    {
+        .ClassInstallHeader =
+        {
+            .cbSize = sizeof(SP_CLASSINSTALL_HEADER),
+            .InstallFunction = DIF_REMOVE,
+        },
+        .Scope = DI_REMOVEDEVICE_GLOBAL,
+        .HwProfile = 0,
+    };
+
+    /* Set class installer parameters for DIF_REMOVE. */
+    if (!SetupDiSetClassInstallParams(
+            hDeviceInfoSet,
+            pDeviceInfoData,
+            &params.ClassInstallHeader,
+            sizeof(SP_REMOVEDEVICE_PARAMS)))
+    {
+        DWORD dwResult = GetLastError();
+        msg(M_NONFATAL | M_ERRNO, "%s: SetupDiSetClassInstallParams failed", __FUNCTION__);
+        return dwResult;
+    }
+
+    /* Call appropriate class installer. */
+    if (!SetupDiCallClassInstaller(
+            DIF_REMOVE,
+            hDeviceInfoSet,
+            pDeviceInfoData))
+    {
+        DWORD dwResult = GetLastError();
+        msg(M_NONFATAL | M_ERRNO, "%s: SetupDiCallClassInstaller(DIF_REMOVE) failed", __FUNCTION__);
+        return dwResult;
+    }
+
+    /* Check if a system reboot is required. */
+    check_reboot(hDeviceInfoSet, pDeviceInfoData, pbRebootRequired);
+    return ERROR_SUCCESS;
+}
+
+
+/**
+ * Changes the device state.
+ *
+ * @param hDeviceInfoSet  A handle to a device information set that contains a device
+ *                      information element that represents the device.
+ *
+ * @param pDeviceInfoData  A pointer to an SP_DEVINFO_DATA structure that specifies the
+ *                      device information element in hDeviceInfoSet.
+ *
+ * @param bEnable       TRUE to enable the device; FALSE to disable.
+ *
+ * @param pbRebootRequired  A pointer to a BOOL flag. If the device requires a system restart,
+ *                      this flag is set to TRUE. Otherwise, the flag is left unmodified. This
+ *                      allows the flag to be globally initialized to FALSE and reused for multiple
+ *                      interface manipulations.
+ *
+ * @return ERROR_SUCCESS on success; Win32 error code otherwise
+ **/
+static DWORD
+change_device_state(
+    _In_ HDEVINFO hDeviceInfoSet,
+    _In_ PSP_DEVINFO_DATA pDeviceInfoData,
+    _In_ BOOL bEnable,
+    _Inout_ LPBOOL pbRebootRequired)
+{
+    SP_PROPCHANGE_PARAMS params =
+    {
+        .ClassInstallHeader =
+        {
+            .cbSize = sizeof(SP_CLASSINSTALL_HEADER),
+            .InstallFunction = DIF_PROPERTYCHANGE,
+        },
+        .StateChange = bEnable ? DICS_ENABLE : DICS_DISABLE,
+        .Scope = DICS_FLAG_GLOBAL,
+        .HwProfile = 0,
+    };
+
+    /* Set class installer parameters for DIF_PROPERTYCHANGE. */
+    if (!SetupDiSetClassInstallParams(
+            hDeviceInfoSet,
+            pDeviceInfoData,
+            &params.ClassInstallHeader,
+            sizeof(SP_PROPCHANGE_PARAMS)))
+    {
+        DWORD dwResult = GetLastError();
+        msg(M_NONFATAL | M_ERRNO, "%s: SetupDiSetClassInstallParams failed", __FUNCTION__);
+        return dwResult;
+    }
+
+    /* Call appropriate class installer. */
+    if (!SetupDiCallClassInstaller(
+            DIF_PROPERTYCHANGE,
+            hDeviceInfoSet,
+            pDeviceInfoData))
+    {
+        DWORD dwResult = GetLastError();
+        msg(M_NONFATAL | M_ERRNO, "%s: SetupDiCallClassInstaller(DIF_PROPERTYCHANGE) failed", __FUNCTION__);
+        return dwResult;
+    }
+
+    /* Check if a system reboot is required. */
+    check_reboot(hDeviceInfoSet, pDeviceInfoData, pbRebootRequired);
+    return ERROR_SUCCESS;
+}
+
+
+/**
+ * Enables the device.
+ *
+ * @param hDeviceInfoSet  A handle to a device information set that contains a device
+ *                      information element that represents the device.
+ *
+ * @param pDeviceInfoData  A pointer to an SP_DEVINFO_DATA structure that specifies the
+ *                      device information element in hDeviceInfoSet.
+ *
+ * @param pbRebootRequired  A pointer to a BOOL flag. If the device requires a system restart,
+ *                      this flag is set to TRUE. Otherwise, the flag is left unmodified. This
+ *                      allows the flag to be globally initialized to FALSE and reused for multiple
+ *                      interface manipulations.
+ *
+ * @return ERROR_SUCCESS on success; Win32 error code otherwise
+ **/
+static DWORD
+enable_device(
+    _In_ HDEVINFO hDeviceInfoSet,
+    _In_ PSP_DEVINFO_DATA pDeviceInfoData,
+    _Inout_ LPBOOL pbRebootRequired)
+{
+    return change_device_state(hDeviceInfoSet, pDeviceInfoData, TRUE, pbRebootRequired);
+}
+
+
+/**
+ * Disables the device.
+ *
+ * @param hDeviceInfoSet  A handle to a device information set that contains a device
+ *                      information element that represents the device.
+ *
+ * @param pDeviceInfoData  A pointer to an SP_DEVINFO_DATA structure that specifies the
+ *                      device information element in hDeviceInfoSet.
+ *
+ * @param pbRebootRequired  A pointer to a BOOL flag. If the device requires a system restart,
+ *                      this flag is set to TRUE. Otherwise, the flag is left unmodified. This
+ *                      allows the flag to be globally initialized to FALSE and reused for multiple
+ *                      interface manipulations.
+ *
+ * @return ERROR_SUCCESS on success; Win32 error code otherwise
+ **/
+static DWORD
+disable_device(
+    _In_ HDEVINFO hDeviceInfoSet,
+    _In_ PSP_DEVINFO_DATA pDeviceInfoData,
+    _Inout_ LPBOOL pbRebootRequired)
+{
+    return change_device_state(hDeviceInfoSet, pDeviceInfoData, FALSE, pbRebootRequired);
+}
+
+
 /**
  * Reads string value from registry key.
  *
@@ -754,10 +956,31 @@ cleanup_hDevInfoList:
 }
 
 
-DWORD
-tap_delete_interface(
+/**
+ * Performs a given task on an interface.
+ *
+ * @param hwndParent    A handle to the top-level window to use for any user interface that is
+ *                      related to non-device-specific actions (such as a select-device dialog
+ *                      box that uses the global class driver list). This handle is optional
+ *                      and can be NULL. If a specific top-level window is not required, set
+ *                      hwndParent to NULL.
+ *
+ * @param pguidInterface  A pointer to GUID that contains network interface ID.
+ *
+ * @param funcOperation  A pointer for the function to perform specific task on the interface.
+ *
+ * @param pbRebootRequired  A pointer to a BOOL flag. If the device requires a system restart,
+ *                      this flag is set to TRUE. Otherwise, the flag is left unmodified. This
+ *                      allows the flag to be globally initialized to FALSE and reused for multiple
+ *                      interface manipulations.
+ *
+ * @return ERROR_SUCCESS on success; Win32 error code otherwise
+ **/
+static DWORD
+execute_on_first_interface(
     _In_opt_ HWND hwndParent,
     _In_ LPCGUID pguidInterface,
+    _In_ devop_func_t funcOperation,
     _Inout_ LPBOOL pbRebootRequired)
 {
     DWORD dwResult;
@@ -831,44 +1054,7 @@ tap_delete_interface(
         /* Compare GUIDs. */
         if (memcmp(pguidInterface, &guidInterface, sizeof(GUID)) == 0)
         {
-            /* Remove the device. */
-            SP_REMOVEDEVICE_PARAMS removedevice_params =
-            {
-                .ClassInstallHeader =
-                {
-                    .cbSize = sizeof(SP_CLASSINSTALL_HEADER),
-                    .InstallFunction = DIF_REMOVE,
-                },
-                .Scope = DI_REMOVEDEVICE_GLOBAL,
-                .HwProfile = 0,
-            };
-
-            /* Set class installer parameters for DIF_REMOVE. */
-            if (!SetupDiSetClassInstallParams(
-                    hDevInfoList,
-                    &devinfo_data,
-                    &removedevice_params.ClassInstallHeader,
-                    sizeof(SP_REMOVEDEVICE_PARAMS)))
-            {
-                dwResult = GetLastError();
-                msg(M_NONFATAL, "%s: SetupDiSetClassInstallParams failed", __FUNCTION__);
-                goto cleanup_hDevInfoList;
-            }
-
-            /* Call appropriate class installer. */
-            if (!SetupDiCallClassInstaller(
-                    DIF_REMOVE,
-                    hDevInfoList,
-                    &devinfo_data))
-            {
-                dwResult = GetLastError();
-                msg(M_NONFATAL, "%s: SetupDiCallClassInstaller(DIF_REMOVE) failed", __FUNCTION__);
-                goto cleanup_hDevInfoList;
-            }
-
-            /* Check if a system reboot is required. */
-            check_reboot(hDevInfoList, &devinfo_data, pbRebootRequired);
-            dwResult = ERROR_SUCCESS;
+            dwResult = funcOperation(hDevInfoList, &devinfo_data, pbRebootRequired);
             break;
         }
     }
@@ -879,6 +1065,27 @@ cleanup_hDevInfoList:
 }
 
 
+DWORD
+tap_delete_interface(
+    _In_opt_ HWND hwndParent,
+    _In_ LPCGUID pguidInterface,
+    _Inout_ LPBOOL pbRebootRequired)
+{
+    return execute_on_first_interface(hwndParent, pguidInterface, delete_device, pbRebootRequired);
+}
+
+
+DWORD
+tap_enable_interface(
+    _In_opt_ HWND hwndParent,
+    _In_ LPCGUID pguidInterface,
+    _In_ BOOL bEnable,
+    _Inout_ LPBOOL pbRebootRequired)
+{
+    return execute_on_first_interface(hwndParent, pguidInterface, bEnable ? enable_device : disable_device, pbRebootRequired);
+}
+
+
 DWORD
 tap_set_interface_name(
     _In_ LPCGUID pguidInterface,
src/tapctl/tap.h +28 -0
index ca66e5da..4c2d73ba 100644
@@ -84,6 +84,34 @@ tap_delete_interface(
     _Inout_ LPBOOL pbRebootRequired);
 
 
+/**
+ * Enables or disables an interface.
+ *
+ * @param hwndParent    A handle to the top-level window to use for any user interface that is
+ *                      related to non-device-specific actions (such as a select-device dialog
+ *                      box that uses the global class driver list). This handle is optional
+ *                      and can be NULL. If a specific top-level window is not required, set
+ *                      hwndParent to NULL.
+ *
+ * @param pguidInterface  A pointer to GUID that contains network interface ID.
+ *
+ * @param bEnable       TRUE to enable; FALSE to disable
+ *
+ * @param pbRebootRequired  A pointer to a BOOL flag. If the device requires a system restart,
+ *                      this flag is set to TRUE. Otherwise, the flag is left unmodified. This
+ *                      allows the flag to be globally initialized to FALSE and reused for multiple
+ *                      interface manipulations.
+ *
+ * @return ERROR_SUCCESS on success; Win32 error code otherwise
+ **/
+DWORD
+tap_enable_interface(
+    _In_opt_ HWND hwndParent,
+    _In_ LPCGUID pguidInterface,
+    _In_ BOOL bEnable,
+    _Inout_ LPBOOL pbRebootRequired);
+
+
 /**
  * Sets interface name.
  *
Signature · 1 line
2.24.1.windows.2
#8 lore raw

PATCH 5/12 openvpnmsica: Revise MSI custom actions interop

In reply to Simon Rozman

Sequence scripts in temporary files has been discontinued in favor of much simpler sequence strings passed to individual custom actions.

Pros: no temporary files; less code
Cons: the evaluation phase must make a complete plan what to perform in each deferred custom action

---
 src/openvpnmsica/Makefile.am                  |    4 +-
 src/openvpnmsica/msica_arg.c                  |  139 +++
 src/openvpnmsica/msica_arg.h                  |  112 ++
 src/openvpnmsica/msica_op.c                   | 1043 -----------------
 src/openvpnmsica/msica_op.h                   |  430 -------
 src/openvpnmsica/openvpnmsica.c               |  713 ++++++-----
 src/openvpnmsica/openvpnmsica.vcxproj         |    4 +-
 src/openvpnmsica/openvpnmsica.vcxproj.filters |    4 +-
 src/tapctl/basic.h                            |   19 +-
 src/tapctl/tap.c                              |    1 +
 10 files changed, 678 insertions(+), 1791 deletions(-)
 create mode 100644 src/openvpnmsica/msica_arg.c
 create mode 100644 src/openvpnmsica/msica_arg.h
 delete mode 100644 src/openvpnmsica/msica_op.c
 delete mode 100644 src/openvpnmsica/msica_op.h
src/openvpnmsica/Makefile.am +2 -2
index db8502b8..9d18854a 100644
@@ -2,7 +2,7 @@
 #  openvpnmsica -- Custom Action DLL to provide OpenVPN-specific support to MSI packages
 #
 #  Copyright (C) 2002-2018 OpenVPN Inc <[email protected]...>
-#  Copyright (C) 2018-2019 Simon Rozman <[email protected]...>
+#  Copyright (C) 2018-2020 Simon Rozman <[email protected]...>
 #
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License version 2
@@ -48,7 +48,7 @@ endif
 libopenvpnmsica_la_SOURCES = \
 	dllmain.c \
 	msiex.c msiex.h \
-	msica_op.c msica_op.h \
+	msica_arg.c msica_arg.h \
 	openvpnmsica.c openvpnmsica.h \
 	$(top_srcdir)/src/tapctl/basic.h \
 	$(top_srcdir)/src/tapctl/error.c $(top_srcdir)/src/tapctl/error.h \
src/openvpnmsica/msica_arg.c new file +139 -0

139 lines not on this page · raw message

src/openvpnmsica/msica_arg.h new file +112 -0

112 lines not on this page · raw message

src/openvpnmsica/msica_op.c deleted +0 -1043

1,043 lines not on this page · raw message

src/openvpnmsica/msica_op.h deleted +0 -430

430 lines not on this page · raw message

src/openvpnmsica/openvpnmsica.c +405 -308

829 lines not on this page · raw message

src/openvpnmsica/openvpnmsica.vcxproj +2 -2
index afa4faec..4b429806 100644
@@ -116,7 +116,7 @@
     <ClCompile Include="..\tapctl\tap.c" />
     <ClCompile Include="dllmain.c" />
     <ClCompile Include="msiex.c" />
-    <ClCompile Include="msica_op.c" />
+    <ClCompile Include="msica_arg.c" />
     <ClCompile Include="openvpnmsica.c" />
   </ItemGroup>
   <ItemGroup>
@@ -124,7 +124,7 @@
     <ClInclude Include="..\tapctl\error.h" />
     <ClInclude Include="..\tapctl\tap.h" />
     <ClInclude Include="msiex.h" />
-    <ClInclude Include="msica_op.h" />
+    <ClInclude Include="msica_arg.h" />
     <ClInclude Include="openvpnmsica.h" />
   </ItemGroup>
   <ItemGroup>
src/openvpnmsica/openvpnmsica.vcxproj.filters +2 -2
index d0b6dcf0..cb050f97 100644
@@ -27,7 +27,7 @@
     <ClCompile Include="openvpnmsica.c">
       <Filter>Source Files</Filter>
     </ClCompile>
-    <ClCompile Include="msica_op.c">
+    <ClCompile Include="msica_arg.c">
       <Filter>Source Files</Filter>
     </ClCompile>
     <ClCompile Include="..\tapctl\tap.c">
@@ -41,7 +41,7 @@
     <ClInclude Include="msiex.h">
       <Filter>Header Files</Filter>
     </ClInclude>
-    <ClInclude Include="msica_op.h">
+    <ClInclude Include="msica_arg.h">
       <Filter>Header Files</Filter>
     </ClInclude>
     <ClInclude Include="..\tapctl\tap.h">
src/tapctl/basic.h +15 -4
index bfbcc30d..a0a88511 100644
@@ -23,12 +23,20 @@
 #define BASIC_H
 
 #ifdef _UNICODE
-#define PRIsLPTSTR "ls"
-#define PRIsLPOLESTR  "ls"
+#define PRIsLPTSTR      "ls"
+#define PRIsLPOLESTR    "ls"
 #else
-#define PRIsLPTSTR "s"
-#define PRIsLPOLESTR  "ls"
+#define PRIsLPTSTR      "s"
+#define PRIsLPOLESTR    "ls"
 #endif
+#define PRIXGUID        "{%08lX-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX}"
+#define PRIGUID_PARAM(g) \
+    (g).Data1, (g).Data2, (g).Data3, (g).Data4[0], (g).Data4[1], (g).Data4[2], (g).Data4[3], (g).Data4[4], (g).Data4[5], (g).Data4[6], (g).Data4[7]
+#define PRIGUID_PARAM_REF(g) \
+    &(g).Data1, &(g).Data2, &(g).Data3, &(g).Data4[0], &(g).Data4[1], &(g).Data4[2], &(g).Data4[3], &(g).Data4[4], &(g).Data4[5], &(g).Data4[6], &(g).Data4[7]
+
+#define __L(q)          L ## q
+#define _L(q)           __L(q)
 
 #ifndef _In_
 #define _In_
@@ -42,6 +50,9 @@
 #ifndef _Inout_
 #define _Inout_
 #endif
+#ifndef _Inout_opt_
+#define _Inout_opt_
+#endif
 #ifndef _Out_
 #define _Out_
 #endif
src/tapctl/tap.c +1 -0
index 576f6740..d4631679 100644
@@ -31,6 +31,7 @@
 #include <cfgmgr32.h>
 #include <objbase.h>
 #include <setupapi.h>
+#include <stdio.h>
 #include <tchar.h>
 
 #ifdef _MSC_VER
Signature · 1 line
2.24.1.windows.2
#11 lore raw

PATCH 6/12 openvpnmsica: Simplify static function names

In reply to Simon Rozman
---
 src/openvpnmsica/openvpnmsica.c | 63 +++++++++++++++++++--------------
 1 file changed, 37 insertions(+), 26 deletions(-)
src/openvpnmsica/openvpnmsica.c +37 -26
index 4c186b13..749dce56 100644
@@ -72,7 +72,7 @@
  * @return ERROR_SUCCESS on success; An error code otherwise
  */
 static UINT
-openvpnmsica_setup_sequence(
+setup_sequence(
     _In_ MSIHANDLE hInstall,
     _In_z_ LPCTSTR szProperty,
     _In_ struct msica_arg_seq *seq)
@@ -101,7 +101,7 @@ openvpnmsica_setup_sequence(
  *                        title.
  */
 static void
-_openvpnmsica_debug_popup(_In_z_ LPCTSTR szFunctionName)
+_debug_popup(_In_z_ LPCTSTR szFunctionName)
 {
     TCHAR szTitle[0x100], szMessage[0x100+MAX_PATH], szProcessPath[MAX_PATH];
 
@@ -129,9 +129,9 @@ _openvpnmsica_debug_popup(_In_z_ LPCTSTR szFunctionName)
     MessageBox(NULL, szMessage, szTitle, MB_OK);
 }
 
-#define openvpnmsica_debug_popup(f) _openvpnmsica_debug_popup(f)
+#define debug_popup(f) _debug_popup(f)
 #else  /* ifdef _DEBUG */
-#define openvpnmsica_debug_popup(f)
+#define debug_popup(f)
 #endif /* ifdef _DEBUG */
 
 
@@ -146,7 +146,7 @@ _openvpnmsica_debug_popup(_In_z_ LPCTSTR szFunctionName)
  *         See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
  */
 static UINT
-openvpnmsica_set_openvpnserv_state(_In_ MSIHANDLE hInstall)
+set_openvpnserv_state(_In_ MSIHANDLE hInstall)
 {
     UINT uiResult;
 
@@ -255,13 +255,13 @@ FindSystemInfo(_In_ MSIHANDLE hInstall)
 #pragma comment(linker, DLLEXP_EXPORT)
 #endif
 
-    openvpnmsica_debug_popup(TEXT(__FUNCTION__));
+    debug_popup(TEXT(__FUNCTION__));
 
     BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL));
 
     OPENVPNMSICA_SAVE_MSI_SESSION(hInstall);
 
-    openvpnmsica_set_openvpnserv_state(hInstall);
+    set_openvpnserv_state(hInstall);
 
     if (bIsCoInitialized)
     {
@@ -278,7 +278,7 @@ FindTAPInterfaces(_In_ MSIHANDLE hInstall)
 #pragma comment(linker, DLLEXP_EXPORT)
 #endif
 
-    openvpnmsica_debug_popup(TEXT(__FUNCTION__));
+    debug_popup(TEXT(__FUNCTION__));
 
     UINT uiResult;
     BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL));
@@ -444,7 +444,7 @@ CloseOpenVPNGUI(_In_ MSIHANDLE hInstall)
 #endif
     UNREFERENCED_PARAMETER(hInstall); /* This CA is does not interact with MSI session (report errors, access properties, tables, etc.). */
 
-    openvpnmsica_debug_popup(TEXT(__FUNCTION__));
+    debug_popup(TEXT(__FUNCTION__));
 
     /* Find OpenVPN GUI window. */
     HWND hWnd = FindWindow(TEXT("OpenVPN-GUI"), NULL);
@@ -466,7 +466,7 @@ StartOpenVPNGUI(_In_ MSIHANDLE hInstall)
 #pragma comment(linker, DLLEXP_EXPORT)
 #endif
 
-    openvpnmsica_debug_popup(TEXT(__FUNCTION__));
+    debug_popup(TEXT(__FUNCTION__));
 
     UINT uiResult;
     BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL));
@@ -564,7 +564,11 @@ cleanup_CoInitialize:
  * @return ERROR_SUCCESS on success; An error code otherwise
  */
 static DWORD
-openvpnmsica_schedule_interface_create(_Inout_ struct msica_arg_seq *seq, _Inout_opt_ struct msica_arg_seq *seqRollback, _In_z_ LPCTSTR szDisplayName, _Inout_ int *iTicks)
+schedule_interface_create(
+    _Inout_ struct msica_arg_seq *seq,
+    _Inout_opt_ struct msica_arg_seq *seqRollback,
+    _In_z_ LPCTSTR szDisplayName,
+    _Inout_ int *iTicks)
 {
     /* Get all available network interfaces. */
     struct tap_interface_node *pInterfaceList = NULL;
@@ -658,7 +662,12 @@ cleanup_pInterfaceList:
  * @return ERROR_SUCCESS on success; An error code otherwise
  */
 static DWORD
-openvpnmsica_schedule_interface_delete(_Inout_ struct msica_arg_seq *seq, _Inout_opt_ struct msica_arg_seq *seqCommit, _Inout_opt_ struct msica_arg_seq *seqRollback, _In_z_ LPCTSTR szDisplayName, _Inout_ int *iTicks)
+schedule_interface_delete(
+    _Inout_ struct msica_arg_seq *seq,
+    _Inout_opt_ struct msica_arg_seq *seqCommit,
+    _Inout_opt_ struct msica_arg_seq *seqRollback,
+    _In_z_ LPCTSTR szDisplayName,
+    _Inout_ int *iTicks)
 {
     /* Get available TUN/TAP interfaces. */
     struct tap_interface_node *pInterfaceList = NULL;
@@ -725,7 +734,7 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
 #pragma comment(linker, DLLEXP_EXPORT)
 #endif
 
-    openvpnmsica_debug_popup(TEXT(__FUNCTION__));
+    debug_popup(TEXT(__FUNCTION__));
 
     UINT uiResult;
     BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL));
@@ -887,7 +896,7 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
                 free(szValue);
 
                 /* Component is or should be installed. Schedule interface creation. */
-                if (openvpnmsica_schedule_interface_create(
+                if (schedule_interface_create(
                         &seqInstallTAPInterfaces,
                         bRollbackEnabled ? &seqInstallTAPInterfacesRollback : NULL,
                         szDisplayNameEx,
@@ -904,7 +913,7 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
                  * Note: On interface removal (product is being uninstalled), we tolerate dwResult error.
                  * Better a partial uninstallation than no uninstallation at all.
                  */
-                openvpnmsica_schedule_interface_delete(
+                schedule_interface_delete(
                     &seqUninstallTAPInterfaces,
                     bRollbackEnabled ? &seqUninstallTAPInterfacesCommit : NULL,
                     bRollbackEnabled ? &seqUninstallTAPInterfacesRollback : NULL,
@@ -934,12 +943,12 @@ cleanup_hRecord:
     }
 
     /* Store deferred custom action parameters. */
-    if ((uiResult = openvpnmsica_setup_sequence(hInstall, TEXT("InstallTAPInterfaces"          ), &seqInstallTAPInterfaces          )) != ERROR_SUCCESS
-        || (uiResult = openvpnmsica_setup_sequence(hInstall, TEXT("InstallTAPInterfacesCommit"    ), &seqInstallTAPInterfacesCommit    )) != ERROR_SUCCESS
-        || (uiResult = openvpnmsica_setup_sequence(hInstall, TEXT("InstallTAPInterfacesRollback"  ), &seqInstallTAPInterfacesRollback  )) != ERROR_SUCCESS
-        || (uiResult = openvpnmsica_setup_sequence(hInstall, TEXT("UninstallTAPInterfaces"        ), &seqUninstallTAPInterfaces        )) != ERROR_SUCCESS
-        || (uiResult = openvpnmsica_setup_sequence(hInstall, TEXT("UninstallTAPInterfacesCommit"  ), &seqUninstallTAPInterfacesCommit  )) != ERROR_SUCCESS
-        || (uiResult = openvpnmsica_setup_sequence(hInstall, TEXT("UninstallTAPInterfacesRollback"), &seqUninstallTAPInterfacesRollback)) != ERROR_SUCCESS)
+    if ((uiResult = setup_sequence(hInstall, TEXT("InstallTAPInterfaces"          ), &seqInstallTAPInterfaces          )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("InstallTAPInterfacesCommit"    ), &seqInstallTAPInterfacesCommit    )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("InstallTAPInterfacesRollback"  ), &seqInstallTAPInterfacesRollback  )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTAPInterfaces"        ), &seqUninstallTAPInterfaces        )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTAPInterfacesCommit"  ), &seqUninstallTAPInterfacesCommit  )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTAPInterfacesRollback"), &seqUninstallTAPInterfacesRollback)) != ERROR_SUCCESS)
     {
         goto cleanup_hRecordProg;
     }
@@ -979,7 +988,9 @@ cleanup_exec_seq:
  * @return TRUE on success; FALSE otherwise
  */
 static BOOL
-openvpnmsica_parse_guid(_In_z_ LPCWSTR szArg, _Out_ GUID *guid)
+parse_guid(
+    _In_z_ LPCWSTR szArg,
+    _Out_ GUID *guid)
 {
     if (swscanf_s(szArg, _L(PRIXGUID), PRIGUID_PARAM_REF(*guid)) != 11)
     {
@@ -997,7 +1008,7 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
 #pragma comment(linker, DLLEXP_EXPORT)
 #endif
 
-    openvpnmsica_debug_popup(TEXT(__FUNCTION__));
+    debug_popup(TEXT(__FUNCTION__));
 
     UINT uiResult;
     BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL));
@@ -1112,7 +1123,7 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
         {
             /* Delete the interface by GUID. */
             GUID guid;
-            if (!openvpnmsica_parse_guid(szArg[i] + 7, &guid))
+            if (!parse_guid(szArg[i] + 7, &guid))
             {
                 goto invalid_argument;
             }
@@ -1122,7 +1133,7 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
         {
             /* Enable the interface. */
             GUID guid;
-            if (!openvpnmsica_parse_guid(szArg[i] + 7, &guid))
+            if (!parse_guid(szArg[i] + 7, &guid))
             {
                 goto invalid_argument;
             }
@@ -1132,7 +1143,7 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
         {
             /* Disable the interface. */
             GUID guid;
-            if (!openvpnmsica_parse_guid(szArg[i] + 8, &guid))
+            if (!parse_guid(szArg[i] + 8, &guid))
             {
                 goto invalid_argument;
             }
Signature · 1 line
2.24.1.windows.2
#14 lore raw

PATCH 7/12 openvpnmsica, tapctl: "interface" => "adapter"

In reply to Simon Rozman

Interface is not equal to adapter. A quote from Microsoft documentation:

Quoted 3 lines

There is a one-to-one correspondence between the interfaces and adapters on a given computer. An interface is an IP-level abstraction, whereas an adapter is a datalink-level abstraction.

As tapctl and openvpnmsica are all about managing network adapters on Windows computers, the terminology has been updated.

---
 src/openvpnmsica/openvpnmsica.c | 366 ++++++++++++++++----------------
 src/openvpnmsica/openvpnmsica.h |  13 +-
 src/tapctl/main.c               | 150 ++++++-------
 src/tapctl/tap.c                | 182 ++++++++--------
 src/tapctl/tap.h                |  82 +++----
 src/tapctl/tapctl_resources.rc  |   4 +-
 6 files changed, 399 insertions(+), 398 deletions(-)
src/openvpnmsica/openvpnmsica.c +183 -183
index 749dce56..1438d3f7 100644
@@ -57,7 +57,7 @@
  * Local constants
  */
 
-#define MSICA_INTERFACE_TICK_SIZE (16*1024) /** Amount of tick space to reserve for one TAP/TUN interface creation/deletition. */
+#define MSICA_ADAPTER_TICK_SIZE (16*1024) /** Amount of tick space to reserve for one TAP/TUN adapter creation/deletition. */
 
 
 /**
@@ -272,7 +272,7 @@ FindSystemInfo(_In_ MSIHANDLE hInstall)
 
 
 UINT __stdcall
-FindTAPInterfaces(_In_ MSIHANDLE hInstall)
+FindTAPAdapters(_In_ MSIHANDLE hInstall)
 {
 #ifdef _MSC_VER
 #pragma comment(linker, DLLEXP_EXPORT)
@@ -285,15 +285,15 @@ FindTAPInterfaces(_In_ MSIHANDLE hInstall)
 
     OPENVPNMSICA_SAVE_MSI_SESSION(hInstall);
 
-    /* Get all TUN/TAP network interfaces. */
-    struct tap_interface_node *pInterfaceList = NULL;
-    uiResult = tap_list_interfaces(NULL, NULL, &pInterfaceList, FALSE);
+    /* Get all TUN/TAP network adapters. */
+    struct tap_adapter_node *pAdapterList = NULL;
+    uiResult = tap_list_adapters(NULL, NULL, &pAdapterList, FALSE);
     if (uiResult != ERROR_SUCCESS)
     {
         goto cleanup_CoInitialize;
     }
 
-    /* Get IPv4/v6 info for all network interfaces. Actually, we're interested in link status only: up/down? */
+    /* Get IPv4/v6 info for all network adapters. Actually, we're interested in link status only: up/down? */
     PIP_ADAPTER_ADDRESSES pAdapterAdresses = NULL;
     ULONG ulAdapterAdressesSize = 16*1024;
     for (size_t iteration = 0; iteration < 2; iteration++)
@@ -302,7 +302,7 @@ FindTAPInterfaces(_In_ MSIHANDLE hInstall)
         if (pAdapterAdresses == NULL)
         {
             msg(M_NONFATAL, "%s: malloc(%u) failed", __FUNCTION__, ulAdapterAdressesSize);
-            uiResult = ERROR_OUTOFMEMORY; goto cleanup_tap_list_interfaces;
+            uiResult = ERROR_OUTOFMEMORY; goto cleanup_tap_list_adapters;
         }
 
         ULONG ulResult = GetAdaptersAddresses(
@@ -322,101 +322,101 @@ FindTAPInterfaces(_In_ MSIHANDLE hInstall)
         {
             SetLastError(ulResult); /* MSDN does not mention GetAdaptersAddresses() to set GetLastError(). But we do have an error code. Set last error manually. */
             msg(M_NONFATAL | M_ERRNO, "%s: GetAdaptersAddresses() failed", __FUNCTION__);
-            uiResult = ulResult; goto cleanup_tap_list_interfaces;
+            uiResult = ulResult; goto cleanup_tap_list_adapters;
         }
     }
 
-    if (pInterfaceList != NULL)
+    if (pAdapterList != NULL)
     {
-        /* Count interfaces. */
-        size_t interface_count = 0;
-        for (struct tap_interface_node *pInterface = pInterfaceList; pInterface; pInterface = pInterface->pNext)
+        /* Count adapters. */
+        size_t adapter_count = 0;
+        for (struct tap_adapter_node *pAdapter = pAdapterList; pAdapter; pAdapter = pAdapter->pNext)
         {
-            interface_count++;
+            adapter_count++;
         }
 
-        /* Prepare semicolon delimited list of TAP interface ID(s) and active TAP interface ID(s). */
+        /* Prepare semicolon delimited list of TAP adapter ID(s) and active TAP adapter ID(s). */
         LPTSTR
-            szTAPInterfaces     = (LPTSTR)malloc(interface_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
-            szTAPInterfacesTail = szTAPInterfaces;
-        if (szTAPInterfaces == NULL)
+            szTAPAdapters     = (LPTSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
+            szTAPAdaptersTail = szTAPAdapters;
+        if (szTAPAdapters == NULL)
         {
-            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, interface_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR));
+            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR));
             uiResult = ERROR_OUTOFMEMORY; goto cleanup_pAdapterAdresses;
         }
 
         LPTSTR
-            szTAPInterfacesActive     = (LPTSTR)malloc(interface_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
-            szTAPInterfacesActiveTail = szTAPInterfacesActive;
-        if (szTAPInterfacesActive == NULL)
+            szTAPAdaptersActive     = (LPTSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
+            szTAPAdaptersActiveTail = szTAPAdaptersActive;
+        if (szTAPAdaptersActive == NULL)
         {
-            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, interface_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR));
-            uiResult = ERROR_OUTOFMEMORY; goto cleanup_szTAPInterfaces;
+            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR));
+            uiResult = ERROR_OUTOFMEMORY; goto cleanup_szTAPAdapters;
         }
 
-        for (struct tap_interface_node *pInterface = pInterfaceList; pInterface; pInterface = pInterface->pNext)
+        for (struct tap_adapter_node *pAdapter = pAdapterList; pAdapter; pAdapter = pAdapter->pNext)
         {
-            /* Convert interface GUID to UTF-16 string. (LPOLESTR defaults to LPWSTR) */
-            LPOLESTR szInterfaceId = NULL;
-            StringFromIID((REFIID)&pInterface->guid, &szInterfaceId);
+            /* Convert adapter GUID to UTF-16 string. (LPOLESTR defaults to LPWSTR) */
+            LPOLESTR szAdapterId = NULL;
+            StringFromIID((REFIID)&pAdapter->guid, &szAdapterId);
 
-            /* Append to the list of TAP interface ID(s). */
-            if (szTAPInterfaces < szTAPInterfacesTail)
+            /* Append to the list of TAP adapter ID(s). */
+            if (szTAPAdapters < szTAPAdaptersTail)
             {
-                *(szTAPInterfacesTail++) = TEXT(';');
+                *(szTAPAdaptersTail++) = TEXT(';');
             }
-            memcpy(szTAPInterfacesTail, szInterfaceId, 38 * sizeof(TCHAR));
-            szTAPInterfacesTail += 38;
+            memcpy(szTAPAdaptersTail, szAdapterId, 38 * sizeof(TCHAR));
+            szTAPAdaptersTail += 38;
 
-            /* If this interface is active (connected), add it to the list of active TAP interface ID(s). */
+            /* If this adapter is active (connected), add it to the list of active TAP adapter ID(s). */
             for (PIP_ADAPTER_ADDRESSES p = pAdapterAdresses; p; p = p->Next)
             {
                 OLECHAR szId[38 /*GUID*/ + 1 /*terminator*/];
                 GUID guid;
                 if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, p->AdapterName, -1, szId, _countof(szId)) > 0
                     && SUCCEEDED(IIDFromString(szId, &guid))
-                    && memcmp(&guid, &pInterface->guid, sizeof(GUID)) == 0)
+                    && memcmp(&guid, &pAdapter->guid, sizeof(GUID)) == 0)
                 {
                     if (p->OperStatus == IfOperStatusUp)
                     {
-                        /* This TAP interface is active (connected). */
-                        if (szTAPInterfacesActive < szTAPInterfacesActiveTail)
+                        /* This TAP adapter is active (connected). */
+                        if (szTAPAdaptersActive < szTAPAdaptersActiveTail)
                         {
-                            *(szTAPInterfacesActiveTail++) = TEXT(';');
+                            *(szTAPAdaptersActiveTail++) = TEXT(';');
                         }
-                        memcpy(szTAPInterfacesActiveTail, szInterfaceId, 38 * sizeof(TCHAR));
-                        szTAPInterfacesActiveTail += 38;
+                        memcpy(szTAPAdaptersActiveTail, szAdapterId, 38 * sizeof(TCHAR));
+                        szTAPAdaptersActiveTail += 38;
                     }
                     break;
                 }
             }
-            CoTaskMemFree(szInterfaceId);
+            CoTaskMemFree(szAdapterId);
         }
-        szTAPInterfacesTail      [0] = 0;
-        szTAPInterfacesActiveTail[0] = 0;
+        szTAPAdaptersTail      [0] = 0;
+        szTAPAdaptersActiveTail[0] = 0;
 
-        /* Set Installer TAPINTERFACES property. */
-        uiResult = MsiSetProperty(hInstall, TEXT("TAPINTERFACES"), szTAPInterfaces);
+        /* Set Installer TAPADAPTERS property. */
+        uiResult = MsiSetProperty(hInstall, TEXT("TAPADAPTERS"), szTAPAdapters);
         if (uiResult != ERROR_SUCCESS)
         {
             SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() to set GetLastError(). But we do have an error code. Set last error manually. */
-            msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"TAPINTERFACES\") failed", __FUNCTION__);
-            goto cleanup_szTAPInterfacesActive;
+            msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"TAPADAPTERS\") failed", __FUNCTION__);
+            goto cleanup_szTAPAdaptersActive;
         }
 
-        /* Set Installer ACTIVETAPINTERFACES property. */
-        uiResult = MsiSetProperty(hInstall, TEXT("ACTIVETAPINTERFACES"), szTAPInterfacesActive);
+        /* Set Installer ACTIVETAPADAPTERS property. */
+        uiResult = MsiSetProperty(hInstall, TEXT("ACTIVETAPADAPTERS"), szTAPAdaptersActive);
         if (uiResult != ERROR_SUCCESS)
         {
             SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() to set GetLastError(). But we do have an error code. Set last error manually. */
-            msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"ACTIVETAPINTERFACES\") failed", __FUNCTION__);
-            goto cleanup_szTAPInterfacesActive;
+            msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"ACTIVETAPADAPTERS\") failed", __FUNCTION__);
+            goto cleanup_szTAPAdaptersActive;
         }
 
-cleanup_szTAPInterfacesActive:
-        free(szTAPInterfacesActive);
-cleanup_szTAPInterfaces:
-        free(szTAPInterfaces);
+cleanup_szTAPAdaptersActive:
+        free(szTAPAdaptersActive);
+cleanup_szTAPAdapters:
+        free(szTAPAdapters);
     }
     else
     {
@@ -425,8 +425,8 @@ cleanup_szTAPInterfaces:
 
 cleanup_pAdapterAdresses:
     free(pAdapterAdresses);
-cleanup_tap_list_interfaces:
-    tap_free_interface_list(pInterfaceList);
+cleanup_tap_list_adapters:
+    tap_free_adapter_list(pAdapterList);
 cleanup_CoInitialize:
     if (bIsCoInitialized)
     {
@@ -546,47 +546,47 @@ cleanup_CoInitialize:
 
 
 /**
- * Schedules interface creation.
+ * Schedules adapter creation.
  *
- * When the rollback is enabled, the interface deletition is scheduled on rollback.
+ * When the rollback is enabled, the adapter deletition is scheduled on rollback.
  *
- * @param seq           The argument sequence to pass to InstallTAPInterfaces custom action
+ * @param seq           The argument sequence to pass to InstallTAPAdapters custom action
  *
- * @param seqRollback   The argument sequence to pass to InstallTAPInterfacesRollback custom
+ * @param seqRollback   The argument sequence to pass to InstallTAPAdaptersRollback custom
  *                      action. NULL when rollback is disabled.
  *
- * @param szDisplayName  Interface display name.
+ * @param szDisplayName  Adapter display name.
  *
  * @param iTicks        Pointer to an integer that represents amount of work (on progress
- *                      indicator) the InstallTAPInterfaces will take. This function increments it
- *                      by MSICA_INTERFACE_TICK_SIZE for each interface to create.
+ *                      indicator) the InstallTAPAdapters will take. This function increments it
+ *                      by MSICA_ADAPTER_TICK_SIZE for each adapter to create.
  *
  * @return ERROR_SUCCESS on success; An error code otherwise
  */
 static DWORD
-schedule_interface_create(
+schedule_adapter_create(
     _Inout_ struct msica_arg_seq *seq,
     _Inout_opt_ struct msica_arg_seq *seqRollback,
     _In_z_ LPCTSTR szDisplayName,
     _Inout_ int *iTicks)
 {
-    /* Get all available network interfaces. */
-    struct tap_interface_node *pInterfaceList = NULL;
-    DWORD dwResult = tap_list_interfaces(NULL, NULL, &pInterfaceList, TRUE);
+    /* Get all available network adapters. */
+    struct tap_adapter_node *pAdapterList = NULL;
+    DWORD dwResult = tap_list_adapters(NULL, NULL, &pAdapterList, TRUE);
     if (dwResult != ERROR_SUCCESS)
     {
         return dwResult;
     }
 
-    /* Does interface exist? */
-    for (struct tap_interface_node *pInterfaceOther = pInterfaceList;; pInterfaceOther = pInterfaceOther->pNext)
+    /* Does adapter exist? */
+    for (struct tap_adapter_node *pAdapterOther = pAdapterList;; pAdapterOther = pAdapterOther->pNext)
     {
-        if (pInterfaceOther == NULL)
+        if (pAdapterOther == NULL)
         {
-            /* No interface with a same name found. */
+            /* No adapter with a same name found. */
             TCHAR szArgument[10 /*create=""|deleteN=""*/ + MAX_PATH /*szDisplayName*/ + 1 /*terminator*/];
 
-            /* InstallTAPInterfaces will create the interface. */
+            /* InstallTAPAdapters will create the adapter. */
             _stprintf_s(
                 szArgument, _countof(szArgument),
                 TEXT("create=\"%.*s\""),
@@ -595,7 +595,7 @@ schedule_interface_create(
 
             if (seqRollback)
             {
-                /* InstallTAPInterfacesRollback will delete the interface. */
+                /* InstallTAPAdaptersRollback will delete the adapter. */
                 _stprintf_s(
                     szArgument, _countof(szArgument),
                     TEXT("deleteN=\"%.*s\""),
@@ -603,132 +603,132 @@ schedule_interface_create(
                 msica_arg_seq_add_head(seqRollback, szArgument);
             }
 
-            *iTicks += MSICA_INTERFACE_TICK_SIZE;
+            *iTicks += MSICA_ADAPTER_TICK_SIZE;
             break;
         }
-        else if (_tcsicmp(szDisplayName, pInterfaceOther->szName) == 0)
+        else if (_tcsicmp(szDisplayName, pAdapterOther->szName) == 0)
         {
-            /* Interface with a same name found. */
-            for (LPCTSTR hwid = pInterfaceOther->szzHardwareIDs;; hwid += _tcslen(hwid) + 1)
+            /* Adapter with a same name found. */
+            for (LPCTSTR hwid = pAdapterOther->szzHardwareIDs;; hwid += _tcslen(hwid) + 1)
             {
                 if (hwid[0] == 0)
                 {
-                    /* This is not a TAP interface. */
-                    msg(M_NONFATAL, "%s: Interface with name \"%" PRIsLPTSTR "\" already exists", __FUNCTION__, pInterfaceOther->szName);
+                    /* This is not a TAP adapter. */
+                    msg(M_NONFATAL, "%s: Adapter with name \"%" PRIsLPTSTR "\" already exists", __FUNCTION__, pAdapterOther->szName);
                     dwResult = ERROR_ALREADY_EXISTS;
-                    goto cleanup_pInterfaceList;
+                    goto cleanup_pAdapterList;
                 }
                 else if (
                     _tcsicmp(hwid, TEXT(TAP_WIN_COMPONENT_ID)) == 0
                     || _tcsicmp(hwid, TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID)) == 0)
                 {
-                    /* This is a TAP-Windows6 interface. We already have what we want! */
+                    /* This is a TAP-Windows6 adapter. We already have what we want! */
                     break;
                 }
             }
-            break; /* Interface names are unique. There should be no other interface with this name. */
+            break; /* Adapter names are unique. There should be no other adapter with this name. */
         }
     }
 
-cleanup_pInterfaceList:
-    tap_free_interface_list(pInterfaceList);
+cleanup_pAdapterList:
+    tap_free_adapter_list(pAdapterList);
     return dwResult;
 }
 
 
 /**
- * Schedules interface deletion.
+ * Schedules adapter deletion.
  *
- * When the rollback is enabled, the interface deletition is scheduled as: disable in
- * UninstallTAPInterfaces, enable on rollback, delete on commit.
+ * When the rollback is enabled, the adapter deletition is scheduled as: disable in
+ * UninstallTAPAdapters, enable on rollback, delete on commit.
  *
- * When rollback is disabled, the interface deletition is scheduled as delete in
- * UninstallTAPInterfaces.
+ * When rollback is disabled, the adapter deletition is scheduled as delete in
+ * UninstallTAPAdapters.
  *
- * @param seq           The argument sequence to pass to UninstallTAPInterfaces custom action
+ * @param seq           The argument sequence to pass to UninstallTAPAdapters custom action
  *
- * @param seqCommit     The argument sequence to pass to UninstallTAPInterfacesCommit custom
+ * @param seqCommit     The argument sequence to pass to UninstallTAPAdaptersCommit custom
  *                      action. NULL when rollback is disabled.
  *
- * @param seqRollback   The argument sequence to pass to UninstallTAPInterfacesRollback custom
+ * @param seqRollback   The argument sequence to pass to UninstallTAPAdaptersRollback custom
  *                      action. NULL when rollback is disabled.
  *
- * @param szDisplayName  Interface display name.
+ * @param szDisplayName  Adapter display name.
  *
  * @param iTicks        Pointer to an integer that represents amount of work (on progress
- *                      indicator) the UninstallTAPInterfaces will take. This function increments
- *                      it by MSICA_INTERFACE_TICK_SIZE for each interface to delete.
+ *                      indicator) the UninstallTAPAdapters will take. This function increments
+ *                      it by MSICA_ADAPTER_TICK_SIZE for each adapter to delete.
  *
  * @return ERROR_SUCCESS on success; An error code otherwise
  */
 static DWORD
-schedule_interface_delete(
+schedule_adapter_delete(
     _Inout_ struct msica_arg_seq *seq,
     _Inout_opt_ struct msica_arg_seq *seqCommit,
     _Inout_opt_ struct msica_arg_seq *seqRollback,
     _In_z_ LPCTSTR szDisplayName,
     _Inout_ int *iTicks)
 {
-    /* Get available TUN/TAP interfaces. */
-    struct tap_interface_node *pInterfaceList = NULL;
-    DWORD dwResult = tap_list_interfaces(NULL, NULL, &pInterfaceList, FALSE);
+    /* Get available TUN/TAP adapters. */
+    struct tap_adapter_node *pAdapterList = NULL;
+    DWORD dwResult = tap_list_adapters(NULL, NULL, &pAdapterList, FALSE);
     if (dwResult != ERROR_SUCCESS)
     {
         return dwResult;
     }
 
-    /* Does interface exist? */
-    for (struct tap_interface_node *pInterface = pInterfaceList; pInterface != NULL; pInterface = pInterface->pNext)
+    /* Does adapter exist? */
+    for (struct tap_adapter_node *pAdapter = pAdapterList; pAdapter != NULL; pAdapter = pAdapter->pNext)
     {
-        if (_tcsicmp(szDisplayName, pInterface->szName) == 0)
+        if (_tcsicmp(szDisplayName, pAdapter->szName) == 0)
         {
-            /* Interface found. */
+            /* Adapter found. */
             TCHAR szArgument[8 /*disable=|enable=|delete=*/ + 38 /*{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}*/ + 1 /*terminator*/];
             if (seqCommit && seqRollback)
             {
-                /* UninstallTAPInterfaces will disable the interface. */
+                /* UninstallTAPAdapters will disable the adapter. */
                 _stprintf_s(
                     szArgument, _countof(szArgument),
                     TEXT("disable=") TEXT(PRIXGUID),
-                    PRIGUID_PARAM(pInterface->guid));
+                    PRIGUID_PARAM(pAdapter->guid));
                 msica_arg_seq_add_tail(seq, szArgument);
 
-                /* UninstallTAPInterfacesRollback will re-enable the interface. */
+                /* UninstallTAPAdaptersRollback will re-enable the adapter. */
                 _stprintf_s(
                     szArgument, _countof(szArgument),
                     TEXT("enable=") TEXT(PRIXGUID),
-                    PRIGUID_PARAM(pInterface->guid));
+                    PRIGUID_PARAM(pAdapter->guid));
                 msica_arg_seq_add_head(seqRollback, szArgument);
 
-                /* UninstallTAPInterfacesCommit will delete the interface. */
+                /* UninstallTAPAdaptersCommit will delete the adapter. */
                 _stprintf_s(
                     szArgument, _countof(szArgument),
                     TEXT("delete=") TEXT(PRIXGUID),
-                    PRIGUID_PARAM(pInterface->guid));
+                    PRIGUID_PARAM(pAdapter->guid));
                 msica_arg_seq_add_tail(seqCommit, szArgument);
             }
             else
             {
-                /* UninstallTAPInterfaces will delete the interface. */
+                /* UninstallTAPAdapters will delete the adapter. */
                 _stprintf_s(
                     szArgument, _countof(szArgument),
                     TEXT("delete=") TEXT(PRIXGUID),
-                    PRIGUID_PARAM(pInterface->guid));
+                    PRIGUID_PARAM(pAdapter->guid));
                 msica_arg_seq_add_tail(seq, szArgument);
             }
 
-            iTicks += MSICA_INTERFACE_TICK_SIZE;
-            break; /* Interface names are unique. There should be no other interface with this name. */
+            iTicks += MSICA_ADAPTER_TICK_SIZE;
+            break; /* Adapter names are unique. There should be no other adapter with this name. */
         }
     }
 
-    tap_free_interface_list(pInterfaceList);
+    tap_free_adapter_list(pAdapterList);
     return dwResult;
 }
 
 
 UINT __stdcall
-EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
+EvaluateTAPAdapters(_In_ MSIHANDLE hInstall)
 {
 #ifdef _MSC_VER
 #pragma comment(linker, DLLEXP_EXPORT)
@@ -742,18 +742,18 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
     OPENVPNMSICA_SAVE_MSI_SESSION(hInstall);
 
     struct msica_arg_seq
-        seqInstallTAPInterfaces,
-        seqInstallTAPInterfacesCommit,
-        seqInstallTAPInterfacesRollback,
-        seqUninstallTAPInterfaces,
-        seqUninstallTAPInterfacesCommit,
-        seqUninstallTAPInterfacesRollback;
-    msica_arg_seq_init(&seqInstallTAPInterfaces);
-    msica_arg_seq_init(&seqInstallTAPInterfacesCommit);
-    msica_arg_seq_init(&seqInstallTAPInterfacesRollback);
-    msica_arg_seq_init(&seqUninstallTAPInterfaces);
-    msica_arg_seq_init(&seqUninstallTAPInterfacesCommit);
-    msica_arg_seq_init(&seqUninstallTAPInterfacesRollback);
+        seqInstallTAPAdapters,
+        seqInstallTAPAdaptersCommit,
+        seqInstallTAPAdaptersRollback,
+        seqUninstallTAPAdapters,
+        seqUninstallTAPAdaptersCommit,
+        seqUninstallTAPAdaptersRollback;
+    msica_arg_seq_init(&seqInstallTAPAdapters);
+    msica_arg_seq_init(&seqInstallTAPAdaptersCommit);
+    msica_arg_seq_init(&seqInstallTAPAdaptersRollback);
+    msica_arg_seq_init(&seqUninstallTAPAdapters);
+    msica_arg_seq_init(&seqUninstallTAPAdaptersCommit);
+    msica_arg_seq_init(&seqUninstallTAPAdaptersRollback);
 
     /* Check rollback state. */
     bool bRollbackEnabled = MsiEvaluateCondition(hInstall, TEXT("RollbackDisabled")) != MSICONDITION_TRUE;
@@ -767,8 +767,8 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
         goto cleanup_exec_seq;
     }
 
-    /* Check if TAPInterface table exists. If it doesn't exist, there's nothing to do. */
-    switch (MsiDatabaseIsTablePersistent(hDatabase, TEXT("TAPInterface")))
+    /* Check if TAPAdapter table exists. If it doesn't exist, there's nothing to do. */
+    switch (MsiDatabaseIsTablePersistent(hDatabase, TEXT("TAPAdapter")))
     {
         case MSICONDITION_FALSE:
         case MSICONDITION_TRUE: break;
@@ -778,9 +778,9 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
             goto cleanup_hDatabase;
     }
 
-    /* Prepare a query to get a list/view of interfaces. */
+    /* Prepare a query to get a list/view of adapters. */
     MSIHANDLE hViewST = 0;
-    LPCTSTR szQuery = TEXT("SELECT `Interface`,`DisplayName`,`Condition`,`Component_` FROM `TAPInterface`");
+    LPCTSTR szQuery = TEXT("SELECT `Adapter`,`DisplayName`,`Condition`,`Component_` FROM `TAPAdapter`");
     uiResult = MsiDatabaseOpenView(hDatabase, szQuery, &hViewST);
     if (uiResult != ERROR_SUCCESS)
     {
@@ -826,7 +826,7 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
 
         INSTALLSTATE iInstalled, iAction;
         {
-            /* Read interface component ID (`Component_` is field #4). */
+            /* Read adapter component ID (`Component_` is field #4). */
             LPTSTR szValue = NULL;
             uiResult = msi_get_record_string(hRecord, 4, &szValue);
             if (uiResult != ERROR_SUCCESS)
@@ -846,7 +846,7 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
             free(szValue);
         }
 
-        /* Get interface display name (`DisplayName` is field #2). */
+        /* Get adapter display name (`DisplayName` is field #2). */
         LPTSTR szDisplayName = NULL;
         uiResult = msi_format_field(hInstall, hRecord, 2, &szDisplayName);
         if (uiResult != ERROR_SUCCESS)
@@ -863,7 +863,7 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
 
             if (iAction >= INSTALLSTATE_LOCAL)
             {
-                /* Read and evaluate interface condition (`Condition` is field #3). */
+                /* Read and evaluate adapter condition (`Condition` is field #3). */
                 LPTSTR szValue = NULL;
                 uiResult = msi_get_record_string(hRecord, 3, &szValue);
                 if (uiResult != ERROR_SUCCESS)
@@ -895,10 +895,10 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
 #endif
                 free(szValue);
 
-                /* Component is or should be installed. Schedule interface creation. */
-                if (schedule_interface_create(
-                        &seqInstallTAPInterfaces,
-                        bRollbackEnabled ? &seqInstallTAPInterfacesRollback : NULL,
+                /* Component is or should be installed. Schedule adapter creation. */
+                if (schedule_adapter_create(
+                        &seqInstallTAPAdapters,
+                        bRollbackEnabled ? &seqInstallTAPAdaptersRollback : NULL,
                         szDisplayNameEx,
                         &iTicks) != ERROR_SUCCESS)
                 {
@@ -908,15 +908,15 @@ EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall)
             }
             else
             {
-                /* Component is installed, but should be degraded to advertised/removed. Schedule interface deletition.
+                /* Component is installed, but should be degraded to advertised/removed. Schedule adapter deletition.
                  *
-                 * Note: On interface removal (product is being uninstalled), we tolerate dwResult error.
+                 * Note: On adapter removal (product is being uninstalled), we tolerate dwResult error.
                  * Better a partial uninstallation than no uninstallation at all.
                  */
-                schedule_interface_delete(
-                    &seqUninstallTAPInterfaces,
-                    bRollbackEnabled ? &seqUninstallTAPInterfacesCommit : NULL,
-                    bRollbackEnabled ? &seqUninstallTAPInterfacesRollback : NULL,
+                schedule_adapter_delete(
+                    &seqUninstallTAPAdapters,
+                    bRollbackEnabled ? &seqUninstallTAPAdaptersCommit : NULL,
+                    bRollbackEnabled ? &seqUninstallTAPAdaptersRollback : NULL,
                     szDisplayNameEx,
                     &iTicks);
             }
@@ -943,12 +943,12 @@ cleanup_hRecord:
     }
 
     /* Store deferred custom action parameters. */
-    if ((uiResult = setup_sequence(hInstall, TEXT("InstallTAPInterfaces"          ), &seqInstallTAPInterfaces          )) != ERROR_SUCCESS
-        || (uiResult = setup_sequence(hInstall, TEXT("InstallTAPInterfacesCommit"    ), &seqInstallTAPInterfacesCommit    )) != ERROR_SUCCESS
-        || (uiResult = setup_sequence(hInstall, TEXT("InstallTAPInterfacesRollback"  ), &seqInstallTAPInterfacesRollback  )) != ERROR_SUCCESS
-        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTAPInterfaces"        ), &seqUninstallTAPInterfaces        )) != ERROR_SUCCESS
-        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTAPInterfacesCommit"  ), &seqUninstallTAPInterfacesCommit  )) != ERROR_SUCCESS
-        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTAPInterfacesRollback"), &seqUninstallTAPInterfacesRollback)) != ERROR_SUCCESS)
+    if ((uiResult = setup_sequence(hInstall, TEXT("InstallTAPAdapters"          ), &seqInstallTAPAdapters          )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("InstallTAPAdaptersCommit"    ), &seqInstallTAPAdaptersCommit    )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("InstallTAPAdaptersRollback"  ), &seqInstallTAPAdaptersRollback  )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTAPAdapters"        ), &seqUninstallTAPAdapters        )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTAPAdaptersCommit"  ), &seqUninstallTAPAdaptersCommit  )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTAPAdaptersRollback"), &seqUninstallTAPAdaptersRollback)) != ERROR_SUCCESS)
     {
         goto cleanup_hRecordProg;
     }
@@ -964,12 +964,12 @@ cleanup_hViewST:
 cleanup_hDatabase:
     MsiCloseHandle(hDatabase);
 cleanup_exec_seq:
-    msica_arg_seq_free(&seqInstallTAPInterfaces);
-    msica_arg_seq_free(&seqInstallTAPInterfacesCommit);
-    msica_arg_seq_free(&seqInstallTAPInterfacesRollback);
-    msica_arg_seq_free(&seqUninstallTAPInterfaces);
-    msica_arg_seq_free(&seqUninstallTAPInterfacesCommit);
-    msica_arg_seq_free(&seqUninstallTAPInterfacesRollback);
+    msica_arg_seq_free(&seqInstallTAPAdapters);
+    msica_arg_seq_free(&seqInstallTAPAdaptersCommit);
+    msica_arg_seq_free(&seqInstallTAPAdaptersRollback);
+    msica_arg_seq_free(&seqUninstallTAPAdapters);
+    msica_arg_seq_free(&seqUninstallTAPAdaptersCommit);
+    msica_arg_seq_free(&seqUninstallTAPAdaptersRollback);
     if (bIsCoInitialized)
     {
         CoUninitialize();
@@ -1052,13 +1052,13 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
 
         if (wcsncmp(szArg[i], L"create=", 7) == 0)
         {
-            /* Create an interface with a given name. */
+            /* Create an adapter with a given name. */
             LPCWSTR szName = szArg[i] + 7;
 
             {
-                /* Report the name of the interface to installer. */
+                /* Report the name of the adapter to installer. */
                 MSIHANDLE hRecord = MsiCreateRecord(3);
-                MsiRecordSetString(hRecord, 1, TEXT("Creating interface"));
+                MsiRecordSetString(hRecord, 1, TEXT("Creating adapter"));
                 MsiRecordSetString(hRecord, 2, szName);
                 int iResult = MsiProcessMessage(hInstall, INSTALLMESSAGE_ACTIONDATA, hRecord);
                 MsiCloseHandle(hRecord);
@@ -1069,27 +1069,27 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
                 }
             }
 
-            GUID guidInterface;
-            dwResult = tap_create_interface(NULL, NULL, NULL, &bRebootRequired, &guidInterface);
+            GUID guidAdapter;
+            dwResult = tap_create_adapter(NULL, NULL, NULL, &bRebootRequired, &guidAdapter);
             if (dwResult == ERROR_SUCCESS)
             {
-                /* Set interface name. */
-                dwResult = tap_set_interface_name(&guidInterface, szName);
+                /* Set adapter name. */
+                dwResult = tap_set_adapter_name(&guidAdapter, szName);
                 if (dwResult != ERROR_SUCCESS)
                 {
-                    tap_delete_interface(NULL, &guidInterface, &bRebootRequired);
+                    tap_delete_adapter(NULL, &guidAdapter, &bRebootRequired);
                 }
             }
         }
         else if (wcsncmp(szArg[i], L"deleteN=", 8) == 0)
         {
-            /* Delete the interface by name. */
+            /* Delete the adapter by name. */
             LPCWSTR szName = szArg[i] + 8;
 
             {
-                /* Report the name of the interface to installer. */
+                /* Report the name of the adapter to installer. */
                 MSIHANDLE hRecord = MsiCreateRecord(3);
-                MsiRecordSetString(hRecord, 1, TEXT("Deleting interface"));
+                MsiRecordSetString(hRecord, 1, TEXT("Deleting adapter"));
                 MsiRecordSetString(hRecord, 2, szName);
                 int iResult = MsiProcessMessage(hInstall, INSTALLMESSAGE_ACTIONDATA, hRecord);
                 MsiCloseHandle(hRecord);
@@ -1100,54 +1100,54 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
                 }
             }
 
-            /* Get available TUN/TAP interfaces. */
-            struct tap_interface_node *pInterfaceList = NULL;
-            dwResult = tap_list_interfaces(NULL, NULL, &pInterfaceList, FALSE);
+            /* Get available TUN/TAP adapters. */
+            struct tap_adapter_node *pAdapterList = NULL;
+            dwResult = tap_list_adapters(NULL, NULL, &pAdapterList, FALSE);
             if (dwResult == ERROR_SUCCESS)
             {
-                /* Does the interface exist? */
-                for (struct tap_interface_node *pInterface = pInterfaceList; pInterface != NULL; pInterface = pInterface->pNext)
+                /* Does the adapter exist? */
+                for (struct tap_adapter_node *pAdapter = pAdapterList; pAdapter != NULL; pAdapter = pAdapter->pNext)
                 {
-                    if (_tcsicmp(szName, pInterface->szName) == 0)
+                    if (_tcsicmp(szName, pAdapter->szName) == 0)
                     {
-                        /* Interface found. */
-                        dwResult = tap_delete_interface(NULL, &pInterface->guid, &bRebootRequired);
+                        /* Adapter found. */
+                        dwResult = tap_delete_adapter(NULL, &pAdapter->guid, &bRebootRequired);
                         break;
                     }
                 }
 
-                tap_free_interface_list(pInterfaceList);
+                tap_free_adapter_list(pAdapterList);
             }
         }
         else if (wcsncmp(szArg[i], L"delete=", 7) == 0)
         {
-            /* Delete the interface by GUID. */
+            /* Delete the adapter by GUID. */
             GUID guid;
             if (!parse_guid(szArg[i] + 7, &guid))
             {
                 goto invalid_argument;
             }
-            dwResult = tap_delete_interface(NULL, &guid, &bRebootRequired);
+            dwResult = tap_delete_adapter(NULL, &guid, &bRebootRequired);
         }
         else if (wcsncmp(szArg[i], L"enable=", 7) == 0)
         {
-            /* Enable the interface. */
+            /* Enable the adapter. */
             GUID guid;
             if (!parse_guid(szArg[i] + 7, &guid))
             {
                 goto invalid_argument;
             }
-            dwResult = tap_enable_interface(NULL, &guid, TRUE, &bRebootRequired);
+            dwResult = tap_enable_adapter(NULL, &guid, TRUE, &bRebootRequired);
         }
         else if (wcsncmp(szArg[i], L"disable=", 8) == 0)
         {
-            /* Disable the interface. */
+            /* Disable the adapter. */
             GUID guid;
             if (!parse_guid(szArg[i] + 8, &guid))
             {
                 goto invalid_argument;
             }
-            dwResult = tap_enable_interface(NULL, &guid, FALSE, &bRebootRequired);
+            dwResult = tap_enable_adapter(NULL, &guid, FALSE, &bRebootRequired);
         }
         else
         {
@@ -1161,7 +1161,7 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
         }
 
         /* Report progress and check for user cancellation. */
-        MsiRecordSetInteger(hRecordProg, 2, MSICA_INTERFACE_TICK_SIZE);
+        MsiRecordSetInteger(hRecordProg, 2, MSICA_ADAPTER_TICK_SIZE);
         if (MsiProcessMessage(hInstall, INSTALLMESSAGE_PROGRESS, hRecordProg) == IDCANCEL)
         {
             dwResult = ERROR_INSTALL_USEREXIT;
src/openvpnmsica/openvpnmsica.h +7 -6
index 1486c043..14fb78a2 100644
@@ -90,8 +90,9 @@ FindSystemInfo(_In_ MSIHANDLE hInstall);
 
 
 /**
- * Find existing TAP interfaces and set TAPINTERFACES property with semicolon delimited list
- * of installed TAP interface GUIDs.
+ * Find existing TAP adapters and set TAPADAPTERS and ACTIVETAPADAPTERS properties with
+ * semicolon delimited list of all installed TAP adapter GUIDs and active adapter GUIDs
+ * respectively.
  *
  * @param hInstall      Handle to the installation provided to the DLL custom action
  *
@@ -99,7 +100,7 @@ FindSystemInfo(_In_ MSIHANDLE hInstall);
  *         See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
  */
 DLLEXP_DECL UINT __stdcall
-FindTAPInterfaces(_In_ MSIHANDLE hInstall);
+FindTAPAdapters(_In_ MSIHANDLE hInstall);
 
 
 /**
@@ -128,8 +129,8 @@ StartOpenVPNGUI(_In_ MSIHANDLE hInstall);
 
 
 /**
- * Evaluate the TAPInterface table of the MSI package database and prepare a list of TAP
- * interfaces to install/remove.
+ * Evaluate the TAPAdapter table of the MSI package database and prepare a list of TAP
+ * adapters to install/remove.
  *
  * @param hInstall      Handle to the installation provided to the DLL custom action
  *
@@ -137,7 +138,7 @@ StartOpenVPNGUI(_In_ MSIHANDLE hInstall);
  *         See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
  */
 DLLEXP_DECL UINT __stdcall
-EvaluateTAPInterfaces(_In_ MSIHANDLE hInstall);
+EvaluateTAPAdapters(_In_ MSIHANDLE hInstall);
 
 
 /**
src/tapctl/main.c +75 -75

294 lines not on this page · raw message

src/tapctl/tap.c +91 -91

468 lines not on this page · raw message

src/tapctl/tap.h +41 -41

191 lines not on this page · raw message

src/tapctl/tapctl_resources.rc +2 -2
index f6f3cb75..2b3ff238 100644
@@ -1,5 +1,5 @@
 /*
- *  tapctl -- Utility to manipulate TUN/TAP interfaces on Windows
+ *  tapctl -- Utility to manipulate TUN/TAP adapters on Windows
  *
  *  Copyright (C) 2018 Simon Rozman <[email protected]...>
  *
@@ -46,7 +46,7 @@ BEGIN
         BLOCK "040904b0"
         BEGIN
             VALUE "CompanyName", "The OpenVPN Project"
-            VALUE "FileDescription", "Utility to manipulate TUN/TAP interfaces on Windows"
+            VALUE "FileDescription", "Utility to manipulate TUN/TAP adapters on Windows"
             VALUE "FileVersion", PACKAGE_VERSION ".0"
             VALUE "InternalName", "OpenVPN"
             VALUE "LegalCopyright", "Copyright © The OpenVPN Project"
Signature · 1 line
2.24.1.windows.2
#17 lore raw

PATCH 8/12 openvpnmsica: "TAP" => "TUN/TAP"

In reply to Simon Rozman

The function and property names that are common to TAP and TUN from TAP-Windows6 and TUN from Wintun were renamed not to make the now mainstream TUN sad.

I would have go with just the "adapter". But, wouldn't that cause confusion when user sees "Deleting adapters" when uninstalling the OpenVPN?

Internal variable names were simplified thou to omit the TUN/TAP referencing.

---
 src/openvpnmsica/openvpnmsica.c | 156 ++++++++++++++++----------------
 src/openvpnmsica/openvpnmsica.h |   8 +-
 2 files changed, 82 insertions(+), 82 deletions(-)
src/openvpnmsica/openvpnmsica.c +78 -78
index 1438d3f7..4223b680 100644
@@ -272,7 +272,7 @@ FindSystemInfo(_In_ MSIHANDLE hInstall)
 
 
 UINT __stdcall
-FindTAPAdapters(_In_ MSIHANDLE hInstall)
+FindTUNTAPAdapters(_In_ MSIHANDLE hInstall)
 {
 #ifdef _MSC_VER
 #pragma comment(linker, DLLEXP_EXPORT)
@@ -337,21 +337,21 @@ FindTAPAdapters(_In_ MSIHANDLE hInstall)
 
         /* Prepare semicolon delimited list of TAP adapter ID(s) and active TAP adapter ID(s). */
         LPTSTR
-            szTAPAdapters     = (LPTSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
-            szTAPAdaptersTail = szTAPAdapters;
-        if (szTAPAdapters == NULL)
+            szAdapters     = (LPTSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
+            szAdaptersTail = szAdapters;
+        if (szAdapters == NULL)
         {
             msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR));
             uiResult = ERROR_OUTOFMEMORY; goto cleanup_pAdapterAdresses;
         }
 
         LPTSTR
-            szTAPAdaptersActive     = (LPTSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
-            szTAPAdaptersActiveTail = szTAPAdaptersActive;
-        if (szTAPAdaptersActive == NULL)
+            szAdaptersActive     = (LPTSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
+            szAdaptersActiveTail = szAdaptersActive;
+        if (szAdaptersActive == NULL)
         {
             msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR));
-            uiResult = ERROR_OUTOFMEMORY; goto cleanup_szTAPAdapters;
+            uiResult = ERROR_OUTOFMEMORY; goto cleanup_szAdapters;
         }
 
         for (struct tap_adapter_node *pAdapter = pAdapterList; pAdapter; pAdapter = pAdapter->pNext)
@@ -361,12 +361,12 @@ FindTAPAdapters(_In_ MSIHANDLE hInstall)
             StringFromIID((REFIID)&pAdapter->guid, &szAdapterId);
 
             /* Append to the list of TAP adapter ID(s). */
-            if (szTAPAdapters < szTAPAdaptersTail)
+            if (szAdapters < szAdaptersTail)
             {
-                *(szTAPAdaptersTail++) = TEXT(';');
+                *(szAdaptersTail++) = TEXT(';');
             }
-            memcpy(szTAPAdaptersTail, szAdapterId, 38 * sizeof(TCHAR));
-            szTAPAdaptersTail += 38;
+            memcpy(szAdaptersTail, szAdapterId, 38 * sizeof(TCHAR));
+            szAdaptersTail += 38;
 
             /* If this adapter is active (connected), add it to the list of active TAP adapter ID(s). */
             for (PIP_ADAPTER_ADDRESSES p = pAdapterAdresses; p; p = p->Next)
@@ -380,43 +380,43 @@ FindTAPAdapters(_In_ MSIHANDLE hInstall)
                     if (p->OperStatus == IfOperStatusUp)
                     {
                         /* This TAP adapter is active (connected). */
-                        if (szTAPAdaptersActive < szTAPAdaptersActiveTail)
+                        if (szAdaptersActive < szAdaptersActiveTail)
                         {
-                            *(szTAPAdaptersActiveTail++) = TEXT(';');
+                            *(szAdaptersActiveTail++) = TEXT(';');
                         }
-                        memcpy(szTAPAdaptersActiveTail, szAdapterId, 38 * sizeof(TCHAR));
-                        szTAPAdaptersActiveTail += 38;
+                        memcpy(szAdaptersActiveTail, szAdapterId, 38 * sizeof(TCHAR));
+                        szAdaptersActiveTail += 38;
                     }
                     break;
                 }
             }
             CoTaskMemFree(szAdapterId);
         }
-        szTAPAdaptersTail      [0] = 0;
-        szTAPAdaptersActiveTail[0] = 0;
+        szAdaptersTail      [0] = 0;
+        szAdaptersActiveTail[0] = 0;
 
-        /* Set Installer TAPADAPTERS property. */
-        uiResult = MsiSetProperty(hInstall, TEXT("TAPADAPTERS"), szTAPAdapters);
+        /* Set Installer TUNTAPADAPTERS property. */
+        uiResult = MsiSetProperty(hInstall, TEXT("TUNTAPADAPTERS"), szAdapters);
         if (uiResult != ERROR_SUCCESS)
         {
             SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() to set GetLastError(). But we do have an error code. Set last error manually. */
-            msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"TAPADAPTERS\") failed", __FUNCTION__);
-            goto cleanup_szTAPAdaptersActive;
+            msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"TUNTAPADAPTERS\") failed", __FUNCTION__);
+            goto cleanup_szAdaptersActive;
         }
 
-        /* Set Installer ACTIVETAPADAPTERS property. */
-        uiResult = MsiSetProperty(hInstall, TEXT("ACTIVETAPADAPTERS"), szTAPAdaptersActive);
+        /* Set Installer ACTIVETUNTAPADAPTERS property. */
+        uiResult = MsiSetProperty(hInstall, TEXT("ACTIVETUNTAPADAPTERS"), szAdaptersActive);
         if (uiResult != ERROR_SUCCESS)
         {
             SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() to set GetLastError(). But we do have an error code. Set last error manually. */
-            msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"ACTIVETAPADAPTERS\") failed", __FUNCTION__);
-            goto cleanup_szTAPAdaptersActive;
+            msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"ACTIVETUNTAPADAPTERS\") failed", __FUNCTION__);
+            goto cleanup_szAdaptersActive;
         }
 
-cleanup_szTAPAdaptersActive:
-        free(szTAPAdaptersActive);
-cleanup_szTAPAdapters:
-        free(szTAPAdapters);
+cleanup_szAdaptersActive:
+        free(szAdaptersActive);
+cleanup_szAdapters:
+        free(szAdapters);
     }
     else
     {
@@ -550,15 +550,15 @@ cleanup_CoInitialize:
  *
  * When the rollback is enabled, the adapter deletition is scheduled on rollback.
  *
- * @param seq           The argument sequence to pass to InstallTAPAdapters custom action
+ * @param seq           The argument sequence to pass to InstallTUNTAPAdapters custom action
  *
- * @param seqRollback   The argument sequence to pass to InstallTAPAdaptersRollback custom
+ * @param seqRollback   The argument sequence to pass to InstallTUNTAPAdaptersRollback custom
  *                      action. NULL when rollback is disabled.
  *
  * @param szDisplayName  Adapter display name.
  *
  * @param iTicks        Pointer to an integer that represents amount of work (on progress
- *                      indicator) the InstallTAPAdapters will take. This function increments it
+ *                      indicator) the InstallTUNTAPAdapters will take. This function increments it
  *                      by MSICA_ADAPTER_TICK_SIZE for each adapter to create.
  *
  * @return ERROR_SUCCESS on success; An error code otherwise
@@ -586,7 +586,7 @@ schedule_adapter_create(
             /* No adapter with a same name found. */
             TCHAR szArgument[10 /*create=""|deleteN=""*/ + MAX_PATH /*szDisplayName*/ + 1 /*terminator*/];
 
-            /* InstallTAPAdapters will create the adapter. */
+            /* InstallTUNTAPAdapters will create the adapter. */
             _stprintf_s(
                 szArgument, _countof(szArgument),
                 TEXT("create=\"%.*s\""),
@@ -595,7 +595,7 @@ schedule_adapter_create(
 
             if (seqRollback)
             {
-                /* InstallTAPAdaptersRollback will delete the adapter. */
+                /* InstallTUNTAPAdaptersRollback will delete the adapter. */
                 _stprintf_s(
                     szArgument, _countof(szArgument),
                     TEXT("deleteN=\"%.*s\""),
@@ -640,23 +640,23 @@ cleanup_pAdapterList:
  * Schedules adapter deletion.
  *
  * When the rollback is enabled, the adapter deletition is scheduled as: disable in
- * UninstallTAPAdapters, enable on rollback, delete on commit.
+ * UninstallTUNTAPAdapters, enable on rollback, delete on commit.
  *
  * When rollback is disabled, the adapter deletition is scheduled as delete in
- * UninstallTAPAdapters.
+ * UninstallTUNTAPAdapters.
  *
- * @param seq           The argument sequence to pass to UninstallTAPAdapters custom action
+ * @param seq           The argument sequence to pass to UninstallTUNTAPAdapters custom action
  *
- * @param seqCommit     The argument sequence to pass to UninstallTAPAdaptersCommit custom
+ * @param seqCommit     The argument sequence to pass to UninstallTUNTAPAdaptersCommit custom
  *                      action. NULL when rollback is disabled.
  *
- * @param seqRollback   The argument sequence to pass to UninstallTAPAdaptersRollback custom
+ * @param seqRollback   The argument sequence to pass to UninstallTUNTAPAdaptersRollback custom
  *                      action. NULL when rollback is disabled.
  *
  * @param szDisplayName  Adapter display name.
  *
  * @param iTicks        Pointer to an integer that represents amount of work (on progress
- *                      indicator) the UninstallTAPAdapters will take. This function increments
+ *                      indicator) the UninstallTUNTAPAdapters will take. This function increments
  *                      it by MSICA_ADAPTER_TICK_SIZE for each adapter to delete.
  *
  * @return ERROR_SUCCESS on success; An error code otherwise
@@ -686,21 +686,21 @@ schedule_adapter_delete(
             TCHAR szArgument[8 /*disable=|enable=|delete=*/ + 38 /*{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}*/ + 1 /*terminator*/];
             if (seqCommit && seqRollback)
             {
-                /* UninstallTAPAdapters will disable the adapter. */
+                /* UninstallTUNTAPAdapters will disable the adapter. */
                 _stprintf_s(
                     szArgument, _countof(szArgument),
                     TEXT("disable=") TEXT(PRIXGUID),
                     PRIGUID_PARAM(pAdapter->guid));
                 msica_arg_seq_add_tail(seq, szArgument);
 
-                /* UninstallTAPAdaptersRollback will re-enable the adapter. */
+                /* UninstallTUNTAPAdaptersRollback will re-enable the adapter. */
                 _stprintf_s(
                     szArgument, _countof(szArgument),
                     TEXT("enable=") TEXT(PRIXGUID),
                     PRIGUID_PARAM(pAdapter->guid));
                 msica_arg_seq_add_head(seqRollback, szArgument);
 
-                /* UninstallTAPAdaptersCommit will delete the adapter. */
+                /* UninstallTUNTAPAdaptersCommit will delete the adapter. */
                 _stprintf_s(
                     szArgument, _countof(szArgument),
                     TEXT("delete=") TEXT(PRIXGUID),
@@ -709,7 +709,7 @@ schedule_adapter_delete(
             }
             else
             {
-                /* UninstallTAPAdapters will delete the adapter. */
+                /* UninstallTUNTAPAdapters will delete the adapter. */
                 _stprintf_s(
                     szArgument, _countof(szArgument),
                     TEXT("delete=") TEXT(PRIXGUID),
@@ -728,7 +728,7 @@ schedule_adapter_delete(
 
 
 UINT __stdcall
-EvaluateTAPAdapters(_In_ MSIHANDLE hInstall)
+EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
 {
 #ifdef _MSC_VER
 #pragma comment(linker, DLLEXP_EXPORT)
@@ -742,18 +742,18 @@ EvaluateTAPAdapters(_In_ MSIHANDLE hInstall)
     OPENVPNMSICA_SAVE_MSI_SESSION(hInstall);
 
     struct msica_arg_seq
-        seqInstallTAPAdapters,
-        seqInstallTAPAdaptersCommit,
-        seqInstallTAPAdaptersRollback,
-        seqUninstallTAPAdapters,
-        seqUninstallTAPAdaptersCommit,
-        seqUninstallTAPAdaptersRollback;
-    msica_arg_seq_init(&seqInstallTAPAdapters);
-    msica_arg_seq_init(&seqInstallTAPAdaptersCommit);
-    msica_arg_seq_init(&seqInstallTAPAdaptersRollback);
-    msica_arg_seq_init(&seqUninstallTAPAdapters);
-    msica_arg_seq_init(&seqUninstallTAPAdaptersCommit);
-    msica_arg_seq_init(&seqUninstallTAPAdaptersRollback);
+        seqInstall,
+        seqInstallCommit,
+        seqInstallRollback,
+        seqUninstall,
+        seqUninstallCommit,
+        seqUninstallRollback;
+    msica_arg_seq_init(&seqInstall);
+    msica_arg_seq_init(&seqInstallCommit);
+    msica_arg_seq_init(&seqInstallRollback);
+    msica_arg_seq_init(&seqUninstall);
+    msica_arg_seq_init(&seqUninstallCommit);
+    msica_arg_seq_init(&seqUninstallRollback);
 
     /* Check rollback state. */
     bool bRollbackEnabled = MsiEvaluateCondition(hInstall, TEXT("RollbackDisabled")) != MSICONDITION_TRUE;
@@ -767,8 +767,8 @@ EvaluateTAPAdapters(_In_ MSIHANDLE hInstall)
         goto cleanup_exec_seq;
     }
 
-    /* Check if TAPAdapter table exists. If it doesn't exist, there's nothing to do. */
-    switch (MsiDatabaseIsTablePersistent(hDatabase, TEXT("TAPAdapter")))
+    /* Check if TUNTAPAdapter table exists. If it doesn't exist, there's nothing to do. */
+    switch (MsiDatabaseIsTablePersistent(hDatabase, TEXT("TUNTAPAdapter")))
     {
         case MSICONDITION_FALSE:
         case MSICONDITION_TRUE: break;
@@ -780,7 +780,7 @@ EvaluateTAPAdapters(_In_ MSIHANDLE hInstall)
 
     /* Prepare a query to get a list/view of adapters. */
     MSIHANDLE hViewST = 0;
-    LPCTSTR szQuery = TEXT("SELECT `Adapter`,`DisplayName`,`Condition`,`Component_` FROM `TAPAdapter`");
+    LPCTSTR szQuery = TEXT("SELECT `Adapter`,`DisplayName`,`Condition`,`Component_` FROM `TUNTAPAdapter`");
     uiResult = MsiDatabaseOpenView(hDatabase, szQuery, &hViewST);
     if (uiResult != ERROR_SUCCESS)
     {
@@ -897,8 +897,8 @@ EvaluateTAPAdapters(_In_ MSIHANDLE hInstall)
 
                 /* Component is or should be installed. Schedule adapter creation. */
                 if (schedule_adapter_create(
-                        &seqInstallTAPAdapters,
-                        bRollbackEnabled ? &seqInstallTAPAdaptersRollback : NULL,
+                        &seqInstall,
+                        bRollbackEnabled ? &seqInstallRollback : NULL,
                         szDisplayNameEx,
                         &iTicks) != ERROR_SUCCESS)
                 {
@@ -914,9 +914,9 @@ EvaluateTAPAdapters(_In_ MSIHANDLE hInstall)
                  * Better a partial uninstallation than no uninstallation at all.
                  */
                 schedule_adapter_delete(
-                    &seqUninstallTAPAdapters,
-                    bRollbackEnabled ? &seqUninstallTAPAdaptersCommit : NULL,
-                    bRollbackEnabled ? &seqUninstallTAPAdaptersRollback : NULL,
+                    &seqUninstall,
+                    bRollbackEnabled ? &seqUninstallCommit : NULL,
+                    bRollbackEnabled ? &seqUninstallRollback : NULL,
                     szDisplayNameEx,
                     &iTicks);
             }
@@ -943,12 +943,12 @@ cleanup_hRecord:
     }
 
     /* Store deferred custom action parameters. */
-    if ((uiResult = setup_sequence(hInstall, TEXT("InstallTAPAdapters"          ), &seqInstallTAPAdapters          )) != ERROR_SUCCESS
-        || (uiResult = setup_sequence(hInstall, TEXT("InstallTAPAdaptersCommit"    ), &seqInstallTAPAdaptersCommit    )) != ERROR_SUCCESS
-        || (uiResult = setup_sequence(hInstall, TEXT("InstallTAPAdaptersRollback"  ), &seqInstallTAPAdaptersRollback  )) != ERROR_SUCCESS
-        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTAPAdapters"        ), &seqUninstallTAPAdapters        )) != ERROR_SUCCESS
-        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTAPAdaptersCommit"  ), &seqUninstallTAPAdaptersCommit  )) != ERROR_SUCCESS
-        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTAPAdaptersRollback"), &seqUninstallTAPAdaptersRollback)) != ERROR_SUCCESS)
+    if ((uiResult = setup_sequence(hInstall, TEXT("InstallTUNTAPAdapters"          ), &seqInstall          )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("InstallTUNTAPAdaptersCommit"    ), &seqInstallCommit    )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("InstallTUNTAPAdaptersRollback"  ), &seqInstallRollback  )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTUNTAPAdapters"        ), &seqUninstall        )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTUNTAPAdaptersCommit"  ), &seqUninstallCommit  )) != ERROR_SUCCESS
+        || (uiResult = setup_sequence(hInstall, TEXT("UninstallTUNTAPAdaptersRollback"), &seqUninstallRollback)) != ERROR_SUCCESS)
     {
         goto cleanup_hRecordProg;
     }
@@ -964,12 +964,12 @@ cleanup_hViewST:
 cleanup_hDatabase:
     MsiCloseHandle(hDatabase);
 cleanup_exec_seq:
-    msica_arg_seq_free(&seqInstallTAPAdapters);
-    msica_arg_seq_free(&seqInstallTAPAdaptersCommit);
-    msica_arg_seq_free(&seqInstallTAPAdaptersRollback);
-    msica_arg_seq_free(&seqUninstallTAPAdapters);
-    msica_arg_seq_free(&seqUninstallTAPAdaptersCommit);
-    msica_arg_seq_free(&seqUninstallTAPAdaptersRollback);
+    msica_arg_seq_free(&seqInstall);
+    msica_arg_seq_free(&seqInstallCommit);
+    msica_arg_seq_free(&seqInstallRollback);
+    msica_arg_seq_free(&seqUninstall);
+    msica_arg_seq_free(&seqUninstallCommit);
+    msica_arg_seq_free(&seqUninstallRollback);
     if (bIsCoInitialized)
     {
         CoUninitialize();
src/openvpnmsica/openvpnmsica.h +4 -4
index 14fb78a2..5d140930 100644
@@ -90,7 +90,7 @@ FindSystemInfo(_In_ MSIHANDLE hInstall);
 
 
 /**
- * Find existing TAP adapters and set TAPADAPTERS and ACTIVETAPADAPTERS properties with
+ * Find existing TAP adapters and set TUNTAPADAPTERS and ACTIVETUNTAPADAPTERS properties with
  * semicolon delimited list of all installed TAP adapter GUIDs and active adapter GUIDs
  * respectively.
  *
@@ -100,7 +100,7 @@ FindSystemInfo(_In_ MSIHANDLE hInstall);
  *         See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
  */
 DLLEXP_DECL UINT __stdcall
-FindTAPAdapters(_In_ MSIHANDLE hInstall);
+FindTUNTAPAdapters(_In_ MSIHANDLE hInstall);
 
 
 /**
@@ -129,7 +129,7 @@ StartOpenVPNGUI(_In_ MSIHANDLE hInstall);
 
 
 /**
- * Evaluate the TAPAdapter table of the MSI package database and prepare a list of TAP
+ * Evaluate the TUNTAPAdapter table of the MSI package database and prepare a list of TAP
  * adapters to install/remove.
  *
  * @param hInstall      Handle to the installation provided to the DLL custom action
@@ -138,7 +138,7 @@ StartOpenVPNGUI(_In_ MSIHANDLE hInstall);
  *         See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
  */
 DLLEXP_DECL UINT __stdcall
-EvaluateTAPAdapters(_In_ MSIHANDLE hInstall);
+EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall);
 
 
 /**
Signature · 1 line
2.24.1.windows.2
#20 lore raw

PATCH 9/12 openvpnmsica: Extend to support arbitrary HWID network adapters

In reply to Simon Rozman
---
 src/openvpnmsica/openvpnmsica.c | 73 ++++++++++++++++++++++-----------
 1 file changed, 49 insertions(+), 24 deletions(-)
src/openvpnmsica/openvpnmsica.c +49 -24
index 4223b680..cfbda8da 100644
@@ -555,7 +555,9 @@ cleanup_CoInitialize:
  * @param seqRollback   The argument sequence to pass to InstallTUNTAPAdaptersRollback custom
  *                      action. NULL when rollback is disabled.
  *
- * @param szDisplayName  Adapter display name.
+ * @param szDisplayName  Adapter display name
+ *
+ * @param szHardwareId  Adapter hardware ID
  *
  * @param iTicks        Pointer to an integer that represents amount of work (on progress
  *                      indicator) the InstallTUNTAPAdapters will take. This function increments it
@@ -568,6 +570,7 @@ schedule_adapter_create(
     _Inout_ struct msica_arg_seq *seq,
     _Inout_opt_ struct msica_arg_seq *seqRollback,
     _In_z_ LPCTSTR szDisplayName,
+    _In_z_ LPCTSTR szHardwareId,
     _Inout_ int *iTicks)
 {
     /* Get all available network adapters. */
@@ -584,13 +587,14 @@ schedule_adapter_create(
         if (pAdapterOther == NULL)
         {
             /* No adapter with a same name found. */
-            TCHAR szArgument[10 /*create=""|deleteN=""*/ + MAX_PATH /*szDisplayName*/ + 1 /*terminator*/];
+            TCHAR szArgument[10 /*create=""|deleteN=""*/ + MAX_PATH /*szDisplayName*/ + 1 /*|*/ + MAX_PATH /*szHardwareId*/ + 1 /*terminator*/];
 
             /* InstallTUNTAPAdapters will create the adapter. */
             _stprintf_s(
                 szArgument, _countof(szArgument),
-                TEXT("create=\"%.*s\""),
-                MAX_PATH, szDisplayName);
+                TEXT("create=\"%.*s|%.*s\""),
+                MAX_PATH, szDisplayName,
+                MAX_PATH, szHardwareId);
             msica_arg_seq_add_tail(seq, szArgument);
 
             if (seqRollback)
@@ -613,16 +617,14 @@ schedule_adapter_create(
             {
                 if (hwid[0] == 0)
                 {
-                    /* This is not a TAP adapter. */
+                    /* This adapter has a different hardware ID. */
                     msg(M_NONFATAL, "%s: Adapter with name \"%" PRIsLPTSTR "\" already exists", __FUNCTION__, pAdapterOther->szName);
                     dwResult = ERROR_ALREADY_EXISTS;
                     goto cleanup_pAdapterList;
                 }
-                else if (
-                    _tcsicmp(hwid, TEXT(TAP_WIN_COMPONENT_ID)) == 0
-                    || _tcsicmp(hwid, TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID)) == 0)
+                else if (_tcsicmp(hwid, szHardwareId) == 0)
                 {
-                    /* This is a TAP-Windows6 adapter. We already have what we want! */
+                    /* This is an adapter with the requested hardware ID. We already have what we want! */
                     break;
                 }
             }
@@ -653,7 +655,9 @@ cleanup_pAdapterList:
  * @param seqRollback   The argument sequence to pass to UninstallTUNTAPAdaptersRollback custom
  *                      action. NULL when rollback is disabled.
  *
- * @param szDisplayName  Adapter display name.
+ * @param szDisplayName  Adapter display name
+ *
+ * @param szHardwareId  Adapter hardware ID
  *
  * @param iTicks        Pointer to an integer that represents amount of work (on progress
  *                      indicator) the UninstallTUNTAPAdapters will take. This function increments
@@ -667,11 +671,12 @@ schedule_adapter_delete(
     _Inout_opt_ struct msica_arg_seq *seqCommit,
     _Inout_opt_ struct msica_arg_seq *seqRollback,
     _In_z_ LPCTSTR szDisplayName,
+    _In_z_ LPCTSTR szHardwareId,
     _Inout_ int *iTicks)
 {
-    /* Get available TUN/TAP adapters. */
+    /* Get available adapters with given hardware ID. */
     struct tap_adapter_node *pAdapterList = NULL;
-    DWORD dwResult = tap_list_adapters(NULL, NULL, &pAdapterList, FALSE);
+    DWORD dwResult = tap_list_adapters(NULL, szHardwareId, &pAdapterList, FALSE);
     if (dwResult != ERROR_SUCCESS)
     {
         return dwResult;
@@ -780,7 +785,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
 
     /* Prepare a query to get a list/view of adapters. */
     MSIHANDLE hViewST = 0;
-    LPCTSTR szQuery = TEXT("SELECT `Adapter`,`DisplayName`,`Condition`,`Component_` FROM `TUNTAPAdapter`");
+    LPCTSTR szQuery = TEXT("SELECT `Adapter`,`DisplayName`,`Condition`,`Component_`,`HardwareId` FROM `TUNTAPAdapter`");
     uiResult = MsiDatabaseOpenView(hDatabase, szQuery, &hViewST);
     if (uiResult != ERROR_SUCCESS)
     {
@@ -857,6 +862,14 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
         LPTSTR szDisplayNameEx = _tcschr(szDisplayName, TEXT('|'));
         szDisplayNameEx = szDisplayNameEx != NULL ? szDisplayNameEx + 1 : szDisplayName;
 
+        /* Get adapter hardware ID (`HardwareId` is field #5). */
+        LPTSTR szHardwareId = NULL;
+        uiResult = msi_get_record_string(hRecord, 5, &szHardwareId);
+        if (uiResult != ERROR_SUCCESS)
+        {
+            goto cleanup_szDisplayName;
+        }
+
         if (iAction > INSTALLSTATE_BROKEN)
         {
             int iTicks = 0;
@@ -868,7 +881,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
                 uiResult = msi_get_record_string(hRecord, 3, &szValue);
                 if (uiResult != ERROR_SUCCESS)
                 {
-                    goto cleanup_szDisplayName;
+                    goto cleanup_szHardwareId;
                 }
 #ifdef __GNUC__
 /*
@@ -882,13 +895,13 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
                 {
                     case MSICONDITION_FALSE:
                         free(szValue);
-                        goto cleanup_szDisplayName;
+                        goto cleanup_szHardwareId;
 
                     case MSICONDITION_ERROR:
                         uiResult = ERROR_INVALID_FIELD;
                         msg(M_NONFATAL | M_ERRNO, "%s: MsiEvaluateCondition(\"%" PRIsLPTSTR "\") failed", __FUNCTION__, szValue);
                         free(szValue);
-                        goto cleanup_szDisplayName;
+                        goto cleanup_szHardwareId;
                 }
 #ifdef __GNUC__
 #pragma GCC diagnostic pop
@@ -900,10 +913,11 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
                         &seqInstall,
                         bRollbackEnabled ? &seqInstallRollback : NULL,
                         szDisplayNameEx,
+                        szHardwareId,
                         &iTicks) != ERROR_SUCCESS)
                 {
                     uiResult = ERROR_INSTALL_FAILED;
-                    goto cleanup_szDisplayName;
+                    goto cleanup_szHardwareId;
                 }
             }
             else
@@ -918,6 +932,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
                     bRollbackEnabled ? &seqUninstallCommit : NULL,
                     bRollbackEnabled ? &seqUninstallRollback : NULL,
                     szDisplayNameEx,
+                    szHardwareId,
                     &iTicks);
             }
 
@@ -928,10 +943,12 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
             if (MsiProcessMessage(hInstall, INSTALLMESSAGE_PROGRESS, hRecordProg) == IDCANCEL)
             {
                 uiResult = ERROR_INSTALL_USEREXIT;
-                goto cleanup_szDisplayName;
+                goto cleanup_szHardwareId;
             }
         }
 
+cleanup_szHardwareId:
+        free(szHardwareId);
 cleanup_szDisplayName:
         free(szDisplayName);
 cleanup_hRecord:
@@ -1052,14 +1069,22 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
 
         if (wcsncmp(szArg[i], L"create=", 7) == 0)
         {
-            /* Create an adapter with a given name. */
-            LPCWSTR szName = szArg[i] + 7;
+            /* Create an adapter with a given name and hardware ID. */
+            LPWSTR szName = szArg[i] + 7;
+            LPWSTR szHardwareId = wcschr(szName, L'|');
+            if (szHardwareId == NULL)
+            {
+                goto invalid_argument;
+            }
+            szHardwareId[0] = 0;
+            ++szHardwareId;
 
             {
                 /* Report the name of the adapter to installer. */
-                MSIHANDLE hRecord = MsiCreateRecord(3);
+                MSIHANDLE hRecord = MsiCreateRecord(4);
                 MsiRecordSetString(hRecord, 1, TEXT("Creating adapter"));
                 MsiRecordSetString(hRecord, 2, szName);
+                MsiRecordSetString(hRecord, 3, szHardwareId);
                 int iResult = MsiProcessMessage(hInstall, INSTALLMESSAGE_ACTIONDATA, hRecord);
                 MsiCloseHandle(hRecord);
                 if (iResult == IDCANCEL)
@@ -1070,7 +1095,7 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
             }
 
             GUID guidAdapter;
-            dwResult = tap_create_adapter(NULL, NULL, NULL, &bRebootRequired, &guidAdapter);
+            dwResult = tap_create_adapter(NULL, NULL, szHardwareId, &bRebootRequired, &guidAdapter);
             if (dwResult == ERROR_SUCCESS)
             {
                 /* Set adapter name. */
@@ -1100,9 +1125,9 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
                 }
             }
 
-            /* Get available TUN/TAP adapters. */
+            /* Get all available adapters. */
             struct tap_adapter_node *pAdapterList = NULL;
-            dwResult = tap_list_adapters(NULL, NULL, &pAdapterList, FALSE);
+            dwResult = tap_list_adapters(NULL, NULL, &pAdapterList, TRUE);
             if (dwResult == ERROR_SUCCESS)
             {
                 /* Does the adapter exist? */
Signature · 1 line
2.24.1.windows.2
#23 lore raw

PATCH 10/12 openvpnmsica, tapctl: Revise default hardware ID management

In reply to Simon Rozman

tap_create_adapter() and tap_list_adapter() no longer default to "root\tap0901". Defining a default hardware ID value is at the responsibility of upper layers that process user desires.

Since the tap_list_adapter() no longer defaults the hardware ID to anything, its behavior was simplified to return all existing adapters when a NULL hardware ID is specified.

---
 src/openvpnmsica/openvpnmsica.c |  16 ++--
 src/tapctl/main.c               |  14 ++--
 src/tapctl/tap.c                | 134 ++++++++++++++++----------------
 src/tapctl/tap.h                |  17 ++--
 4 files changed, 86 insertions(+), 95 deletions(-)
src/openvpnmsica/openvpnmsica.c +8 -8
index cfbda8da..ae9b007f 100644
@@ -285,9 +285,9 @@ FindTUNTAPAdapters(_In_ MSIHANDLE hInstall)
 
     OPENVPNMSICA_SAVE_MSI_SESSION(hInstall);
 
-    /* Get all TUN/TAP network adapters. */
+    /* Get existing network adapters. */
     struct tap_adapter_node *pAdapterList = NULL;
-    uiResult = tap_list_adapters(NULL, NULL, &pAdapterList, FALSE);
+    uiResult = tap_list_adapters(NULL, NULL, &pAdapterList);
     if (uiResult != ERROR_SUCCESS)
     {
         goto cleanup_CoInitialize;
@@ -573,9 +573,9 @@ schedule_adapter_create(
     _In_z_ LPCTSTR szHardwareId,
     _Inout_ int *iTicks)
 {
-    /* Get all available network adapters. */
+    /* Get existing network adapters. */
     struct tap_adapter_node *pAdapterList = NULL;
-    DWORD dwResult = tap_list_adapters(NULL, NULL, &pAdapterList, TRUE);
+    DWORD dwResult = tap_list_adapters(NULL, NULL, &pAdapterList);
     if (dwResult != ERROR_SUCCESS)
     {
         return dwResult;
@@ -674,9 +674,9 @@ schedule_adapter_delete(
     _In_z_ LPCTSTR szHardwareId,
     _Inout_ int *iTicks)
 {
-    /* Get available adapters with given hardware ID. */
+    /* Get adapters with given hardware ID. */
     struct tap_adapter_node *pAdapterList = NULL;
-    DWORD dwResult = tap_list_adapters(NULL, szHardwareId, &pAdapterList, FALSE);
+    DWORD dwResult = tap_list_adapters(NULL, szHardwareId, &pAdapterList);
     if (dwResult != ERROR_SUCCESS)
     {
         return dwResult;
@@ -1125,9 +1125,9 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
                 }
             }
 
-            /* Get all available adapters. */
+            /* Get existing adapters. */
             struct tap_adapter_node *pAdapterList = NULL;
-            dwResult = tap_list_adapters(NULL, NULL, &pAdapterList, TRUE);
+            dwResult = tap_list_adapters(NULL, NULL, &pAdapterList);
             if (dwResult == ERROR_SUCCESS)
             {
                 /* Does the adapter exist? */
src/tapctl/main.c +7 -7
index 1cc86424..fdeda7bf 100644
@@ -177,7 +177,7 @@ _tmain(int argc, LPCTSTR argv[])
     else if (_tcsicmp(argv[1], TEXT("create")) == 0)
     {
         LPCTSTR szName = NULL;
-        LPCTSTR szHwId = NULL;
+        LPCTSTR szHwId = TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID);
 
         /* Parse options. */
         for (int i = 2; i < argc; i++)
@@ -214,9 +214,9 @@ _tmain(int argc, LPCTSTR argv[])
 
         if (szName)
         {
-            /* Get the list of all available adapters. */
+            /* Get existing network adapters. */
             struct tap_adapter_node *pAdapterList = NULL;
-            dwResult = tap_list_adapters(NULL, szHwId, &pAdapterList, TRUE);
+            dwResult = tap_list_adapters(NULL, NULL, &pAdapterList);
             if (dwResult != ERROR_SUCCESS)
             {
                 _ftprintf(stderr, TEXT("Enumerating adapters failed (error 0x%x).\n"), dwResult);
@@ -271,7 +271,7 @@ create_delete_adapter:
     }
     else if (_tcsicmp(argv[1], TEXT("list")) == 0)
     {
-        LPCTSTR szHwId = NULL;
+        LPCTSTR szHwId = TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID);
 
         /* Parse options. */
         for (int i = 2; i < argc; i++)
@@ -286,9 +286,9 @@ create_delete_adapter:
             }
         }
 
-        /* Output list of TUN/TAP adapters. */
+        /* Output list of adapters with given hardware ID. */
         struct tap_adapter_node *pAdapterList = NULL;
-        DWORD dwResult = tap_list_adapters(NULL, szHwId, &pAdapterList, FALSE);
+        DWORD dwResult = tap_list_adapters(NULL, szHwId, &pAdapterList);
         if (dwResult != ERROR_SUCCESS)
         {
             _ftprintf(stderr, TEXT("Enumerating TUN/TAP adapters failed (error 0x%x).\n"), dwResult);
@@ -319,7 +319,7 @@ create_delete_adapter:
         {
             /* The argument failed to covert to GUID. Treat it as the adapter name. */
             struct tap_adapter_node *pAdapterList = NULL;
-            DWORD dwResult = tap_list_adapters(NULL, NULL, &pAdapterList, FALSE);
+            DWORD dwResult = tap_list_adapters(NULL, NULL, &pAdapterList);
             if (dwResult != ERROR_SUCCESS)
             {
                 _ftprintf(stderr, TEXT("Enumerating TUN/TAP adapters failed (error 0x%x).\n"), dwResult);
src/tapctl/tap.c +65 -69

198 lines not on this page · raw message

src/tapctl/tap.h +6 -11
index aec44ec8..68662c82 100644
@@ -38,8 +38,7 @@
  *                      description of the device. This pointer is optional and can be NULL.
  *
  * @param szHwId        A pointer to a NULL-terminated string that supplies the hardware id
- *                      of the device. This pointer is optional and can be NULL. Default value
- *                      is root\tap0901.
+ *                      of the device (e.g. "root\\tap0901", "Wintun").
  *
  * @param pbRebootRequired  A pointer to a BOOL flag. If the device requires a system restart,
  *                      this flag is set to TRUE. Otherwise, the flag is left unmodified. This
@@ -54,7 +53,7 @@ DWORD
 tap_create_adapter(
     _In_opt_ HWND hwndParent,
     _In_opt_ LPCTSTR szDeviceDescription,
-    _In_opt_ LPCTSTR szHwId,
+    _In_ LPCTSTR szHwId,
     _Inout_ LPBOOL pbRebootRequired,
     _Out_ LPGUID pguidAdapter);
 
@@ -141,7 +140,7 @@ struct tap_adapter_node
 
 
 /**
- * Creates a list of available network adapters.
+ * Creates a list of existing network adapters.
  *
  * @param hwndParent    A handle to the top-level window to use for any user adapter that is
  *                      related to non-device-specific actions (such as a select-device dialog
@@ -150,24 +149,20 @@ struct tap_adapter_node
  *                      hwndParent to NULL.
  *
  * @param szHwId        A pointer to a NULL-terminated string that supplies the hardware id
- *                      of the device. This pointer is optional and can be NULL. Default value
- *                      is root\tap0901.
+ *                      of the device. This pointer is optional and can be NULL. When NULL,
+ *                      all network adapters found are added to the list.
  *
  * @param ppAdapterList  A pointer to the list to receive pointer to the first adapter in
  *                      the list. After the list is no longer required, free it using
  *                      tap_free_adapter_list().
  *
- * @param bAll          When TRUE, all network adapters found are added to the list. When
- *                      FALSE, only TUN/TAP adapters found are added.
- *
  * @return ERROR_SUCCESS on success; Win32 error code otherwise
  */
 DWORD
 tap_list_adapters(
     _In_opt_ HWND hwndParent,
     _In_opt_ LPCTSTR szHwId,
-    _Out_ struct tap_adapter_node **ppAdapterList,
-    _In_ BOOL bAll);
+    _Out_ struct tap_adapter_node **ppAdapterList);
 
 
 /**
Signature · 1 line
2.24.1.windows.2
#27 lore raw

PATCH 11/12 openvpnmsica: Merge FindTUNTAPAdapters into FindSystemInfo

In reply to Simon Rozman

1. We don't need two custom actions to evaluate the system state, do we?

2. FindTUNTAPAdapters was actually broken. It enumerated all existing network adapters, rather than just the ones we are interested in:
TAP-Windows6 and Wintun.

3. TUNTAPADAPTER and ACTIVETUNTAPADAPTERS were split into TAPWINDOWS6ADAPTERS, ACTIVETAPWINDOWS6ADAPTERS, WINTUNADAPTERS and ACTIVEWINTUNADAPTERS to allow finer control.

---
 src/openvpnmsica/openvpnmsica.c | 235 ++++++++++++++++----------------
 src/openvpnmsica/openvpnmsica.h |  26 ++--
 2 files changed, 125 insertions(+), 136 deletions(-)
src/openvpnmsica/openvpnmsica.c +115 -120
index ae9b007f..28cf16b5 100644
@@ -248,49 +248,26 @@ cleanup_OpenSCManager:
 }
 
 
-UINT __stdcall
-FindSystemInfo(_In_ MSIHANDLE hInstall)
-{
-#ifdef _MSC_VER
-#pragma comment(linker, DLLEXP_EXPORT)
-#endif
-
-    debug_popup(TEXT(__FUNCTION__));
-
-    BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL));
-
-    OPENVPNMSICA_SAVE_MSI_SESSION(hInstall);
-
-    set_openvpnserv_state(hInstall);
-
-    if (bIsCoInitialized)
-    {
-        CoUninitialize();
-    }
-    return ERROR_SUCCESS;
-}
-
-
-UINT __stdcall
-FindTUNTAPAdapters(_In_ MSIHANDLE hInstall)
+static UINT
+find_adapters(
+    _In_ MSIHANDLE hInstall,
+    _In_z_ LPCTSTR szHardwareId,
+    _In_z_ LPCTSTR szAdaptersPropertyName,
+    _In_z_ LPCTSTR szActiveAdaptersPropertyName)
 {
-#ifdef _MSC_VER
-#pragma comment(linker, DLLEXP_EXPORT)
-#endif
-
-    debug_popup(TEXT(__FUNCTION__));
-
     UINT uiResult;
-    BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL));
-
-    OPENVPNMSICA_SAVE_MSI_SESSION(hInstall);
 
-    /* Get existing network adapters. */
+    /* Get network adapters with given hardware ID. */
     struct tap_adapter_node *pAdapterList = NULL;
-    uiResult = tap_list_adapters(NULL, NULL, &pAdapterList);
+    uiResult = tap_list_adapters(NULL, szHardwareId, &pAdapterList);
     if (uiResult != ERROR_SUCCESS)
     {
-        goto cleanup_CoInitialize;
+        return uiResult;
+    }
+    else if (pAdapterList == NULL)
+    {
+        /* No adapters - no fun. */
+        return ERROR_SUCCESS;
     }
 
     /* Get IPv4/v6 info for all network adapters. Actually, we're interested in link status only: up/down? */
@@ -302,7 +279,7 @@ FindTUNTAPAdapters(_In_ MSIHANDLE hInstall)
         if (pAdapterAdresses == NULL)
         {
             msg(M_NONFATAL, "%s: malloc(%u) failed", __FUNCTION__, ulAdapterAdressesSize);
-            uiResult = ERROR_OUTOFMEMORY; goto cleanup_tap_list_adapters;
+            uiResult = ERROR_OUTOFMEMORY; goto cleanup_pAdapterList;
         }
 
         ULONG ulResult = GetAdaptersAddresses(
@@ -322,117 +299,135 @@ FindTUNTAPAdapters(_In_ MSIHANDLE hInstall)
         {
             SetLastError(ulResult); /* MSDN does not mention GetAdaptersAddresses() to set GetLastError(). But we do have an error code. Set last error manually. */
             msg(M_NONFATAL | M_ERRNO, "%s: GetAdaptersAddresses() failed", __FUNCTION__);
-            uiResult = ulResult; goto cleanup_tap_list_adapters;
+            uiResult = ulResult; goto cleanup_pAdapterList;
         }
     }
 
-    if (pAdapterList != NULL)
+    /* Count adapters. */
+    size_t adapter_count = 0;
+    for (struct tap_adapter_node *pAdapter = pAdapterList; pAdapter; pAdapter = pAdapter->pNext)
     {
-        /* Count adapters. */
-        size_t adapter_count = 0;
-        for (struct tap_adapter_node *pAdapter = pAdapterList; pAdapter; pAdapter = pAdapter->pNext)
-        {
-            adapter_count++;
-        }
+        adapter_count++;
+    }
 
-        /* Prepare semicolon delimited list of TAP adapter ID(s) and active TAP adapter ID(s). */
-        LPTSTR
-            szAdapters     = (LPTSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
-            szAdaptersTail = szAdapters;
-        if (szAdapters == NULL)
-        {
-            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR));
-            uiResult = ERROR_OUTOFMEMORY; goto cleanup_pAdapterAdresses;
-        }
+    /* Prepare semicolon delimited list of TAP adapter ID(s) and active TAP adapter ID(s). */
+    LPTSTR
+        szAdapters     = (LPTSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
+        szAdaptersTail = szAdapters;
+    if (szAdapters == NULL)
+    {
+        msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR));
+        uiResult = ERROR_OUTOFMEMORY; goto cleanup_pAdapterAdresses;
+    }
+
+    LPTSTR
+        szAdaptersActive     = (LPTSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
+        szAdaptersActiveTail = szAdaptersActive;
+    if (szAdaptersActive == NULL)
+    {
+        msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR));
+        uiResult = ERROR_OUTOFMEMORY; goto cleanup_szAdapters;
+    }
 
-        LPTSTR
-            szAdaptersActive     = (LPTSTR)malloc(adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR)),
-            szAdaptersActiveTail = szAdaptersActive;
-        if (szAdaptersActive == NULL)
+    for (struct tap_adapter_node *pAdapter = pAdapterList; pAdapter; pAdapter = pAdapter->pNext)
+    {
+        /* Convert adapter GUID to UTF-16 string. (LPOLESTR defaults to LPWSTR) */
+        LPOLESTR szAdapterId = NULL;
+        StringFromIID((REFIID)&pAdapter->guid, &szAdapterId);
+
+        /* Append to the list of TAP adapter ID(s). */
+        if (szAdapters < szAdaptersTail)
         {
-            msg(M_FATAL, "%s: malloc(%u) failed", __FUNCTION__, adapter_count * (38 /*GUID*/ + 1 /*separator/terminator*/) * sizeof(TCHAR));
-            uiResult = ERROR_OUTOFMEMORY; goto cleanup_szAdapters;
+            *(szAdaptersTail++) = TEXT(';');
         }
+        memcpy(szAdaptersTail, szAdapterId, 38 * sizeof(TCHAR));
+        szAdaptersTail += 38;
 
-        for (struct tap_adapter_node *pAdapter = pAdapterList; pAdapter; pAdapter = pAdapter->pNext)
+        /* If this adapter is active (connected), add it to the list of active TAP adapter ID(s). */
+        for (PIP_ADAPTER_ADDRESSES p = pAdapterAdresses; p; p = p->Next)
         {
-            /* Convert adapter GUID to UTF-16 string. (LPOLESTR defaults to LPWSTR) */
-            LPOLESTR szAdapterId = NULL;
-            StringFromIID((REFIID)&pAdapter->guid, &szAdapterId);
-
-            /* Append to the list of TAP adapter ID(s). */
-            if (szAdapters < szAdaptersTail)
-            {
-                *(szAdaptersTail++) = TEXT(';');
-            }
-            memcpy(szAdaptersTail, szAdapterId, 38 * sizeof(TCHAR));
-            szAdaptersTail += 38;
-
-            /* If this adapter is active (connected), add it to the list of active TAP adapter ID(s). */
-            for (PIP_ADAPTER_ADDRESSES p = pAdapterAdresses; p; p = p->Next)
+            OLECHAR szId[38 /*GUID*/ + 1 /*terminator*/];
+            GUID guid;
+            if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, p->AdapterName, -1, szId, _countof(szId)) > 0
+                && SUCCEEDED(IIDFromString(szId, &guid))
+                && memcmp(&guid, &pAdapter->guid, sizeof(GUID)) == 0)
             {
-                OLECHAR szId[38 /*GUID*/ + 1 /*terminator*/];
-                GUID guid;
-                if (MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, p->AdapterName, -1, szId, _countof(szId)) > 0
-                    && SUCCEEDED(IIDFromString(szId, &guid))
-                    && memcmp(&guid, &pAdapter->guid, sizeof(GUID)) == 0)
+                if (p->OperStatus == IfOperStatusUp)
                 {
-                    if (p->OperStatus == IfOperStatusUp)
+                    /* This TAP adapter is active (connected). */
+                    if (szAdaptersActive < szAdaptersActiveTail)
                     {
-                        /* This TAP adapter is active (connected). */
-                        if (szAdaptersActive < szAdaptersActiveTail)
-                        {
-                            *(szAdaptersActiveTail++) = TEXT(';');
-                        }
-                        memcpy(szAdaptersActiveTail, szAdapterId, 38 * sizeof(TCHAR));
-                        szAdaptersActiveTail += 38;
+                        *(szAdaptersActiveTail++) = TEXT(';');
                     }
-                    break;
+                    memcpy(szAdaptersActiveTail, szAdapterId, 38 * sizeof(TCHAR));
+                    szAdaptersActiveTail += 38;
                 }
+                break;
             }
-            CoTaskMemFree(szAdapterId);
-        }
-        szAdaptersTail      [0] = 0;
-        szAdaptersActiveTail[0] = 0;
-
-        /* Set Installer TUNTAPADAPTERS property. */
-        uiResult = MsiSetProperty(hInstall, TEXT("TUNTAPADAPTERS"), szAdapters);
-        if (uiResult != ERROR_SUCCESS)
-        {
-            SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() to set GetLastError(). But we do have an error code. Set last error manually. */
-            msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"TUNTAPADAPTERS\") failed", __FUNCTION__);
-            goto cleanup_szAdaptersActive;
-        }
-
-        /* Set Installer ACTIVETUNTAPADAPTERS property. */
-        uiResult = MsiSetProperty(hInstall, TEXT("ACTIVETUNTAPADAPTERS"), szAdaptersActive);
-        if (uiResult != ERROR_SUCCESS)
-        {
-            SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() to set GetLastError(). But we do have an error code. Set last error manually. */
-            msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"ACTIVETUNTAPADAPTERS\") failed", __FUNCTION__);
-            goto cleanup_szAdaptersActive;
         }
+        CoTaskMemFree(szAdapterId);
+    }
+    szAdaptersTail      [0] = 0;
+    szAdaptersActiveTail[0] = 0;
 
-cleanup_szAdaptersActive:
-        free(szAdaptersActive);
-cleanup_szAdapters:
-        free(szAdapters);
+    /* Set Installer properties. */
+    uiResult = MsiSetProperty(hInstall, szAdaptersPropertyName, szAdapters);
+    if (uiResult != ERROR_SUCCESS)
+    {
+        SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() to set GetLastError(). But we do have an error code. Set last error manually. */
+        msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"%s\") failed", __FUNCTION__, szAdaptersPropertyName);
+        goto cleanup_szAdaptersActive;
     }
-    else
+    uiResult = MsiSetProperty(hInstall, szActiveAdaptersPropertyName, szAdaptersActive);
+    if (uiResult != ERROR_SUCCESS)
     {
-        uiResult = ERROR_SUCCESS;
+        SetLastError(uiResult); /* MSDN does not mention MsiSetProperty() to set GetLastError(). But we do have an error code. Set last error manually. */
+        msg(M_NONFATAL | M_ERRNO, "%s: MsiSetProperty(\"%s\") failed", __FUNCTION__, szActiveAdaptersPropertyName);
+        goto cleanup_szAdaptersActive;
     }
 
+cleanup_szAdaptersActive:
+    free(szAdaptersActive);
+cleanup_szAdapters:
+    free(szAdapters);
 cleanup_pAdapterAdresses:
     free(pAdapterAdresses);
-cleanup_tap_list_adapters:
+cleanup_pAdapterList:
     tap_free_adapter_list(pAdapterList);
-cleanup_CoInitialize:
+    return uiResult;
+}
+
+
+UINT __stdcall
+FindSystemInfo(_In_ MSIHANDLE hInstall)
+{
+#ifdef _MSC_VER
+#pragma comment(linker, DLLEXP_EXPORT)
+#endif
+
+    debug_popup(TEXT(__FUNCTION__));
+
+    BOOL bIsCoInitialized = SUCCEEDED(CoInitialize(NULL));
+
+    OPENVPNMSICA_SAVE_MSI_SESSION(hInstall);
+
+    set_openvpnserv_state(hInstall);
+    find_adapters(
+        hInstall,
+        TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID),
+        TEXT("TAPWINDOWS6ADAPTERS"),
+        TEXT("ACTIVETAPWINDOWS6ADAPTERS"));
+    find_adapters(
+        hInstall,
+        TEXT("Wintun"),
+        TEXT("WINTUNADAPTERS"),
+        TEXT("ACTIVEWINTUNADAPTERS"));
+
     if (bIsCoInitialized)
     {
         CoUninitialize();
     }
-    return uiResult;
+    return ERROR_SUCCESS;
 }
 
 
src/openvpnmsica/openvpnmsica.h +10 -16
index 5d140930..221d03ca 100644
@@ -76,23 +76,17 @@ extern "C" {
 
 /**
  * Determines Windows information:
- * - Sets `DriverCertification` MSI property to "", "attsgn" or "whql"
- *   according to the driver certification required by the running version of
- *   Windows.
  *
- * @param hInstall      Handle to the installation provided to the DLL custom action
+ * - Sets `OPENVPNSERVICE` MSI property to PID of OpenVPN Service if running, or its EXE path if
+ *   configured for auto-start.
  *
- * @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
-FindSystemInfo(_In_ MSIHANDLE hInstall);
-
-
-/**
- * Find existing TAP adapters and set TUNTAPADAPTERS and ACTIVETUNTAPADAPTERS properties with
- * semicolon delimited list of all installed TAP adapter GUIDs and active adapter GUIDs
- * respectively.
+ * - Finds existing TAP-Windows6 adapters and set TAPWINDOWS6ADAPTERS and
+ *   ACTIVETAPWINDOWS6ADAPTERS properties with semicolon delimited list of all installed adapter
+ *   GUIDs and active adapter GUIDs respectively.
+ *
+ * - Finds existing Wintun adapters and set WINTUNADAPTERS and ACTIVEWINTUNADAPTERS 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
  *
@@ -100,7 +94,7 @@ FindSystemInfo(_In_ MSIHANDLE hInstall);
  *         See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa368072.aspx
  */
 DLLEXP_DECL UINT __stdcall
-FindTUNTAPAdapters(_In_ MSIHANDLE hInstall);
+FindSystemInfo(_In_ MSIHANDLE hInstall);
 
 
 /**
Signature · 1 line
2.24.1.windows.2
#35 lore raw

PATCH 12/12 tapctl: Support multiple hardware IDs

In reply to Simon Rozman

TAP-Windows6 adapters created with tapinstall/devcon.exe have hardware ID "tap0901", where TAP-Windows6 adapters created with tapctl.exe have hardware ID "root\\tap0901".

The enumeration of the network adapters have been extended to detect adapters using a list of acceptable hardware IDs.

---
 src/openvpnmsica/openvpnmsica.c | 43 ++++++++++++++++++---------------
 src/tapctl/main.c               |  8 +++---
 src/tapctl/tap.c                | 21 ++++++++++++----
 src/tapctl/tap.h                |  8 +++---
 4 files changed, 48 insertions(+), 32 deletions(-)
src/openvpnmsica/openvpnmsica.c +23 -20
index 28cf16b5..31e90bd2 100644
@@ -251,7 +251,7 @@ cleanup_OpenSCManager:
 static UINT
 find_adapters(
     _In_ MSIHANDLE hInstall,
-    _In_z_ LPCTSTR szHardwareId,
+    _In_z_ LPCTSTR szzHardwareIDs,
     _In_z_ LPCTSTR szAdaptersPropertyName,
     _In_z_ LPCTSTR szActiveAdaptersPropertyName)
 {
@@ -259,7 +259,7 @@ find_adapters(
 
     /* Get network adapters with given hardware ID. */
     struct tap_adapter_node *pAdapterList = NULL;
-    uiResult = tap_list_adapters(NULL, szHardwareId, &pAdapterList);
+    uiResult = tap_list_adapters(NULL, szzHardwareIDs, &pAdapterList);
     if (uiResult != ERROR_SUCCESS)
     {
         return uiResult;
@@ -414,12 +414,12 @@ FindSystemInfo(_In_ MSIHANDLE hInstall)
     set_openvpnserv_state(hInstall);
     find_adapters(
         hInstall,
-        TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID),
+        TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0") TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0"),
         TEXT("TAPWINDOWS6ADAPTERS"),
         TEXT("ACTIVETAPWINDOWS6ADAPTERS"));
     find_adapters(
         hInstall,
-        TEXT("Wintun"),
+        TEXT("Wintun") TEXT("\0"),
         TEXT("WINTUNADAPTERS"),
         TEXT("ACTIVEWINTUNADAPTERS"));
 
@@ -652,7 +652,7 @@ cleanup_pAdapterList:
  *
  * @param szDisplayName  Adapter display name
  *
- * @param szHardwareId  Adapter hardware ID
+ * @param szzHardwareIDs  String of strings with acceptable adapter hardware IDs
  *
  * @param iTicks        Pointer to an integer that represents amount of work (on progress
  *                      indicator) the UninstallTUNTAPAdapters will take. This function increments
@@ -666,12 +666,12 @@ schedule_adapter_delete(
     _Inout_opt_ struct msica_arg_seq *seqCommit,
     _Inout_opt_ struct msica_arg_seq *seqRollback,
     _In_z_ LPCTSTR szDisplayName,
-    _In_z_ LPCTSTR szHardwareId,
+    _In_z_ LPCTSTR szzHardwareIDs,
     _Inout_ int *iTicks)
 {
     /* Get adapters with given hardware ID. */
     struct tap_adapter_node *pAdapterList = NULL;
-    DWORD dwResult = tap_list_adapters(NULL, szHardwareId, &pAdapterList);
+    DWORD dwResult = tap_list_adapters(NULL, szzHardwareIDs, &pAdapterList);
     if (dwResult != ERROR_SUCCESS)
     {
         return dwResult;
@@ -858,11 +858,16 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
         szDisplayNameEx = szDisplayNameEx != NULL ? szDisplayNameEx + 1 : szDisplayName;
 
         /* Get adapter hardware ID (`HardwareId` is field #5). */
-        LPTSTR szHardwareId = NULL;
-        uiResult = msi_get_record_string(hRecord, 5, &szHardwareId);
-        if (uiResult != ERROR_SUCCESS)
+        TCHAR szzHardwareIDs[0x100] = { 0 };
         {
-            goto cleanup_szDisplayName;
+            LPTSTR szHwId = NULL;
+            uiResult = msi_get_record_string(hRecord, 5, &szHwId);
+            if (uiResult != ERROR_SUCCESS)
+            {
+                goto cleanup_szDisplayName;
+            }
+            memcpy_s(szzHardwareIDs, sizeof(szzHardwareIDs) - 2*sizeof(TCHAR) /*requires double zero termination*/, szHwId, _tcslen(szHwId)*sizeof(TCHAR));
+            free(szHwId);
         }
 
         if (iAction > INSTALLSTATE_BROKEN)
@@ -876,7 +881,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
                 uiResult = msi_get_record_string(hRecord, 3, &szValue);
                 if (uiResult != ERROR_SUCCESS)
                 {
-                    goto cleanup_szHardwareId;
+                    goto cleanup_szDisplayName;
                 }
 #ifdef __GNUC__
 /*
@@ -890,13 +895,13 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
                 {
                     case MSICONDITION_FALSE:
                         free(szValue);
-                        goto cleanup_szHardwareId;
+                        goto cleanup_szDisplayName;
 
                     case MSICONDITION_ERROR:
                         uiResult = ERROR_INVALID_FIELD;
                         msg(M_NONFATAL | M_ERRNO, "%s: MsiEvaluateCondition(\"%" PRIsLPTSTR "\") failed", __FUNCTION__, szValue);
                         free(szValue);
-                        goto cleanup_szHardwareId;
+                        goto cleanup_szDisplayName;
                 }
 #ifdef __GNUC__
 #pragma GCC diagnostic pop
@@ -908,11 +913,11 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
                         &seqInstall,
                         bRollbackEnabled ? &seqInstallRollback : NULL,
                         szDisplayNameEx,
-                        szHardwareId,
+                        szzHardwareIDs,
                         &iTicks) != ERROR_SUCCESS)
                 {
                     uiResult = ERROR_INSTALL_FAILED;
-                    goto cleanup_szHardwareId;
+                    goto cleanup_szDisplayName;
                 }
             }
             else
@@ -927,7 +932,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
                     bRollbackEnabled ? &seqUninstallCommit : NULL,
                     bRollbackEnabled ? &seqUninstallRollback : NULL,
                     szDisplayNameEx,
-                    szHardwareId,
+                    szzHardwareIDs,
                     &iTicks);
             }
 
@@ -938,12 +943,10 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
             if (MsiProcessMessage(hInstall, INSTALLMESSAGE_PROGRESS, hRecordProg) == IDCANCEL)
             {
                 uiResult = ERROR_INSTALL_USEREXIT;
-                goto cleanup_szHardwareId;
+                goto cleanup_szDisplayName;
             }
         }
 
-cleanup_szHardwareId:
-        free(szHardwareId);
 cleanup_szDisplayName:
         free(szDisplayName);
 cleanup_hRecord:
src/tapctl/main.c +5 -3
index fdeda7bf..40164879 100644
@@ -271,14 +271,16 @@ create_delete_adapter:
     }
     else if (_tcsicmp(argv[1], TEXT("list")) == 0)
     {
-        LPCTSTR szHwId = TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID);
+        TCHAR szzHwId[0x100] = TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0") TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0");
 
         /* Parse options. */
         for (int i = 2; i < argc; i++)
         {
             if (_tcsicmp(argv[i], TEXT("--hwid")) == 0)
             {
-                szHwId = argv[++i];
+                memset(szzHwId, 0, sizeof(szzHwId));
+                memcpy_s(szzHwId, sizeof(szzHwId) - 2*sizeof(TCHAR) /*requires double zero termination*/, argv[i], _tcslen(argv[i])*sizeof(TCHAR));
+                ++i;
             }
             else
             {
@@ -288,7 +290,7 @@ create_delete_adapter:
 
         /* Output list of adapters with given hardware ID. */
         struct tap_adapter_node *pAdapterList = NULL;
-        DWORD dwResult = tap_list_adapters(NULL, szHwId, &pAdapterList);
+        DWORD dwResult = tap_list_adapters(NULL, szzHwId, &pAdapterList);
         if (dwResult != ERROR_SUCCESS)
         {
             _ftprintf(stderr, TEXT("Enumerating TUN/TAP adapters failed (error 0x%x).\n"), dwResult);
src/tapctl/tap.c +16 -5
index bdef3fc1..8ece3fb9 100644
@@ -1179,7 +1179,7 @@ cleanup_szAdapterId:
 DWORD
 tap_list_adapters(
     _In_opt_ HWND hwndParent,
-    _In_opt_ LPCTSTR szHwId,
+    _In_opt_ LPCTSTR szzHwIDs,
     _Out_ struct tap_adapter_node **ppAdapter)
 {
     DWORD dwResult;
@@ -1260,7 +1260,7 @@ tap_list_adapters(
         /* Check that hardware ID is REG_SZ/REG_MULTI_SZ, and optionally if it matches ours. */
         if (dwDataType == REG_SZ)
         {
-            if (szHwId && _tcsicmp(szzDeviceHardwareIDs, szHwId) != 0)
+            if (szzHwIDs && !_tcszistr(szzHwIDs, szzDeviceHardwareIDs))
             {
                 /* This is not our device. Skip it. */
                 goto cleanup_szzDeviceHardwareIDs;
@@ -1268,10 +1268,21 @@ tap_list_adapters(
         }
         else if (dwDataType == REG_MULTI_SZ)
         {
-            if (szHwId && _tcszistr(szzDeviceHardwareIDs, szHwId) == NULL)
+            if (szzHwIDs)
             {
-                /* This is not our device. Skip it. */
-                goto cleanup_szzDeviceHardwareIDs;
+                for (LPTSTR s = szzDeviceHardwareIDs;; s += _tcslen(s) + 1)
+                {
+                    if (s[0] == 0)
+                    {
+                        /* This is not our device. Skip it. */
+                        goto cleanup_szzDeviceHardwareIDs;
+                    }
+                    else if (_tcszistr(szzHwIDs, s))
+                    {
+                        /* This is our device. */
+                        break;
+                    }
+                }
             }
         }
         else
src/tapctl/tap.h +4 -4
index 68662c82..102de32d 100644
@@ -148,9 +148,9 @@ struct tap_adapter_node
  *                      and can be NULL. If a specific top-level window is not required, set
  *                      hwndParent to NULL.
  *
- * @param szHwId        A pointer to a NULL-terminated string that supplies the hardware id
- *                      of the device. This pointer is optional and can be NULL. When NULL,
- *                      all network adapters found are added to the list.
+ * @param szzHwIDs      A string of strings that supplies the list of hardware IDs of the device.
+ *                      This pointer is optional and can be NULL. When NULL, all network adapters
+ *                      found are added to the list.
  *
  * @param ppAdapterList  A pointer to the list to receive pointer to the first adapter in
  *                      the list. After the list is no longer required, free it using
@@ -161,7 +161,7 @@ struct tap_adapter_node
 DWORD
 tap_list_adapters(
     _In_opt_ HWND hwndParent,
-    _In_opt_ LPCTSTR szHwId,
+    _In_opt_ LPCTSTR szzHwIDs,
     _Out_ struct tap_adapter_node **ppAdapterList);
 
 
Signature · 1 line
2.24.1.windows.2
Acked-by on v1 1/12
#36 lore raw
In reply to Simon Rozman

It only takes code away, which is now handled outside in the tap-windows6.msm (tap-windows6/pull/106). Not claiming to understand any of this, but the code change does not introduce anything new which looks dangerous - and it's all your code anyway, so you'll know best :-)

Your patch has been applied to the master branch.

commit 026cf3e5d3ada763617bf86087cb651cc57bddb2

Author: Simon Rozman
Date:   Mon Mar 9 14:17:17 2020 +0100
     openvpnmsica: Remove required Windows driver certification detection

     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]/msg19530.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

Acked-by on v1 2/12
#2 lore raw

[Openvpn-devel] [PATCH applied] Re: openvpnmsica: Fix TAPInterface.DisplayName field interpretation

In reply to Simon Rozman

I won't claim to understand what this all does, but the change matches the documentation - if a "file name" is returned that has "8.3|long" format, it will use the "long" part of it, otherwise the string as it is.

Your patch has been applied to the master branch.

commit 36493bf6383767fe4e20f1dfda6be2a7ee0dc1f2

Author: Simon Rozman
Date:   Mon Mar 9 14:17:18 2020 +0100
     openvpnmsica: Fix TAPInterface.DisplayName field interpretation

     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]/msg19520.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

Acked-by on v1 3/12
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: tapctl: Update documentation

In reply to Simon Rozman

Documenation is good :-) - and proper text is even better.

Your patch has been applied to the master branch.

commit 57fe5a263b5a9f48d5c318498352fea7e8ac9908

Author: Simon Rozman
Date:   Mon Mar 9 14:17:19 2020 +0100
     tapctl: Update documentation

     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]/msg19522.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

Acked-by on v1 4/12
#6 lore raw

Re: [Openvpn-devel] [PATCH 04/12] tapctl: Add functions for enabling/disabling adapters

In reply to Simon Rozman

Stared at the patch, compiled with msvc and smoke-tested (tapctl delete {guid}).

New layering (like tap_enable_interface/enable_device/change_device_state/) makes code easy to follow.

#7 lore raw

[Openvpn-devel] [PATCH applied] Re: tapctl: Add functions for enabling/disabling adapters

In reply to Simon Rozman

Your patch has been applied to the master branch.

Test built on MinGW. No further review.

commit d15bc3ad1be515ed83baf87d025845c9ab8ccc57

Author: Simon Rozman
Date:   Mon Mar 9 14:17:20 2020 +0100
     tapctl: Add functions for enabling/disabling adapters

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

--
kind regards,

Gert Doering

Acked-by on v1 5/12
#9 lore raw

Re: [Openvpn-devel] [PATCH 05/12] openvpnmsica: Revise MSI custom actions interop

In reply to Simon Rozman

Hi,

I must say I am not super familiar with this component nor MSI in general.

Stared at the code, compiled with MSVC and tested some exported functions with rundll32.

This has removed lots of code, so it makes sense, assuming that all required functionality is still in place.

It would be nice to have unit tests for msica_arg_* functions - they're doing dangerous low-level stuff.

#24 lore raw

Re: [Openvpn-devel] [PATCH 10/12] openvpnmsica, tapctl: Revise default hardware ID management

In reply to Simon Rozman

Hi,

Since we are getting rid of default hwid, shouldn't we do it also for tapctl and make "tapctl list" return all adapters?

Since it defaults to root\tap0901, "tapctl list" doesn't show anything for me, which is a bit confusing:

Quoted 2 lines

c:\Users\lev\Projects\openvpn\x64-Output\Debug>tapctl.exe list

If I want to see tap adapters, I need to explicitly specify tap0901:

Quoted 2 lines

c:\Users\lev\Projects\openvpn\x64-Output\Debug>tapctl.exe list --hwid tap0901 {82A7A5F5-4D32-4274-84CF-DF36171159BD} Local Area Connection

#28 lore raw

Re: [Openvpn-devel] [PATCH 11/12] openvpnmsica: Merge FindTUNTAPAdapters into FindSystemInfo

In reply to Simon Rozman

Hi,

Compiled with msvc, smoke-tested with rundll32.

One thing:

src/openvpnmsica/openvpnmsica.c FindTUNTAPAdapters(_In_ MSIHANDLE hInstall) · line 419

Quoted 6 lines
src/openvpnmsica/openvpnmsica.c +6 -0
+    set_openvpnserv_state(hInstall);
+    find_adapters(
+        hInstall,
+        TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID),
+        TEXT("TAPWINDOWS6ADAPTERS"),
+        TEXT("ACTIVETAPWINDOWS6ADAPTERS"));

Both methods return error codes which we ignore.

#10 lore raw

[Openvpn-devel] [PATCH applied] Re: openvpnmsica: Revise MSI custom actions interop

In reply to Simon Rozman

Your patch has been applied to the master branch.

Very cursory review only. Test compiled on MinGW.

commit e24049d55644f698a8f1ddc199ba39944394edfa

Author: Simon Rozman
Date:   Mon Mar 9 14:17:21 2020 +0100
     openvpnmsica: Revise MSI custom actions interop

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

--
kind regards,

Gert Doering

#13 lore raw

[Openvpn-devel] [PATCH applied] Re: openvpnmsica: Simplify static function names

In reply to Simon Rozman

Your patch has been applied to the master branch.

Cursory review agrees :-) - test compiled on MinGW.

commit c8de3ddb2a660b96c6176901ac948d7c3b0a57e6

Author: Simon Rozman
Date:   Mon Mar 9 14:17:22 2020 +0100
     openvpnmsica: Simplify static function names

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

--
kind regards,

Gert Doering

#16 lore raw

[Openvpn-devel] [PATCH applied] Re: openvpnmsica, tapctl: interface => adapter

In reply to Simon Rozman

Your patch has been applied to the master branch.

What a search-and-replace orgy :-) - did some staring at the diff, plus a test compile with MinGW

commit 52b2414d3234d0fab5c1351f3035cda77a43fa2d

Author: Simon Rozman
Date:   Mon Mar 9 14:17:23 2020 +0100
     openvpnmsica, tapctl: interface => adapter

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

--
kind regards,

Gert Doering

#19 lore raw

[Openvpn-devel] [PATCH applied] Re: openvpnmsica: TAP => TUN/TAP

In reply to Simon Rozman

Your patch has been applied to the master branch.

From a granularity point of view, this one could have been merged into the other big rename fest, 07/12... but anyway. Seems to make sense, compiles with MinGW.

commit 8c487854323a23e1fd1bd5e8c2827f28272f74b9

Author: Simon Rozman
Date:   Mon Mar 9 14:17:24 2020 +0100
     openvpnmsica: TAP => TUN/TAP

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

--
kind regards,

Gert Doering

#22 lore raw

[Openvpn-devel] [PATCH applied] Re: openvpnmsica: Extend to support arbitrary HWID network adapters

In reply to Simon Rozman

Your patch has been applied to the master branch.

Looks reasonable. Compile tested with MSVC.

(It looks a bit incomplete wrt "how to specify the component HWID now?" but this is coming in the next patches, I think)

commit d263e4f300553ea77f1bf16538bcd0e81ed2e302

Author: Simon Rozman
Date:   Mon Mar 9 14:17:25 2020 +0100
     openvpnmsica: Extend to support arbitrary HWID network adapters

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

--
kind regards,

Gert Doering

#26 lore raw

[Openvpn-devel] [PATCH applied] Re: openvpnmsica, tapctl: Revise default hardware ID management

In reply to Simon Rozman

Your patch has been applied to the master branch.

Test compiled with MinGW. Change makes sense, code looks reasonable.

commit 50d68142f0926850122a78a6ca661d6778efacb3

Author: Simon Rozman
Date:   Mon Mar 9 14:17:26 2020 +0100
     openvpnmsica, tapctl: Revise default hardware ID management

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

--
kind regards,

Gert Doering

#29 lore raw

Re: [Openvpn-devel] [PATCH 11/12] openvpnmsica: Merge FindTUNTAPAdapters into FindSystemInfo

In reply to Lev Stipakov

Hi Lev,

I'm struggling with family duties now that schools are closed. This makes it hard to find any time for computers.

Nevertheless, should find_adapters() fail for some reason, it is not critical to bail out of FindSystemInfo() custom action.

The find_adapters() itself already displays a resumable error message (MSI also writes it to the log) on all of the error return paths:
- tap_list_adapters() calls msg(M_NONFATAL...) on error returns
- other returns have msg(M_NONFATAL...)

Mind that msg() is using MSI error messaging [https://github.com/rozmansi/openvpn/blob/feature/msi/src/openvpnmsica/dllmain.c#L108]. MsiProcessMessage(s->hInstall, INSTALLMESSAGE_ERROR, hRecordProg); will popup an error dialog in interactive MSI sessions, and write error message to the log in interactive and non-interactive sessions.

To summarize: the return value of find_adapters() call is ignored on purpose.

Regards,
Simon

-----Original Message-----
From: Lev Stipakov <[email protected]...>
Date: Tuesday, 24 March 2020 at 13:07
To: Simon Rozman <[email protected]...>
Cc: "[email protected]" <[email protected]>
Subject: Re: [Openvpn-devel] [PATCH 11/12] openvpnmsica: Merge FindTUNTAPAdapters into FindSystemInfo

    Hi,
    
    Compiled with msvc, smoke-tested with rundll32.
    
    One thing:
    
    > +    set_openvpnserv_state(hInstall);
    > +    find_adapters(
    > +        hInstall,
    > +        TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID),
    > +        TEXT("TAPWINDOWS6ADAPTERS"),
    > +        TEXT("ACTIVETAPWINDOWS6ADAPTERS"));
    
    Both methods return error codes which we ignore.
Acked-by
#30 lore raw

Re: [Openvpn-devel] [PATCH 11/12] openvpnmsica: Merge FindTUNTAPAdapters into FindSystemInfo

Hi,

Quoted 1 line

To summarize: the return value of find_adapters() call is ignored on purpose.

Shouldn't return type be void if return value is not used?

I'll ack it to not to further delay 2.5 release, but it would be good to get a follow-up
patch with either void or return value being not ignored.

#34 lore raw

[Openvpn-devel] [PATCH applied] Re: openvpnmsica: Merge FindTUNTAPAdapters into FindSystemInfo

In reply to Simon Rozman

Your patch has been applied to the master branch.

(I've read the discussion, and agree with Lev that a followup patch might be a good thing - "either void or return value being not ignored")

Tested on a mingw compile.

commit c6f8d1a7a3dcb3c8608126ebb34b9087c6c9fb1e

Author: Simon Rozman
Date:   Mon Mar 9 14:17:27 2020 +0100
     openvpnmsica: Merge FindTUNTAPAdapters into FindSystemInfo

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

--
kind regards,

Gert Doering

#31 lore raw

PATCH 1/1 openvpnmsica: Simplify find_adapters() to void return

In reply to Simon Rozman

As the find_adapters() failure is not critical and FindSystemInfo() should continue regardless, the find_adapters() has been simplified not to return result code. It still logs any error thou.

---
 src/openvpnmsica/openvpnmsica.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
src/openvpnmsica/openvpnmsica.c +3 -4
index f203f736..de1cf65c 100644
@@ -248,7 +248,7 @@ cleanup_OpenSCManager:
 }
 
 
-static UINT
+static void
 find_adapters(
     _In_ MSIHANDLE hInstall,
     _In_z_ LPCTSTR szzHardwareIDs,
@@ -262,12 +262,12 @@ find_adapters(
     uiResult = tap_list_adapters(NULL, szzHardwareIDs, &pAdapterList);
     if (uiResult != ERROR_SUCCESS)
     {
-        return uiResult;
+        return;
     }
     else if (pAdapterList == NULL)
     {
         /* No adapters - no fun. */
-        return ERROR_SUCCESS;
+        return;
     }
 
     /* Get IPv4/v6 info for all network adapters. Actually, we're interested in link status only: up/down? */
@@ -394,7 +394,6 @@ cleanup_pAdapterAdresses:
     free(pAdapterAdresses);
 cleanup_pAdapterList:
     tap_free_adapter_list(pAdapterList);
-    return uiResult;
 }
 
 
Signature · 1 line
2.28.0.windows.1
Acked-by on v1 1/1
#32 lore raw

Re: [Openvpn-devel] [PATCH] openvpnmsica: Simplify find_adapters() to void return

Hi,

Quoted 1 line

to return result code. It still logs any error thou.

though

src/openvpnmsica/openvpnmsica.c cleanup_OpenSCManager: · line 251

Quoted 2 lines
src/openvpnmsica/openvpnmsica.c +1 -1
-static UINT
+static void

Indeed, the return value of find_adapters() has never been used.

Compiled with MSVC.

#33 lore raw

[Openvpn-devel] [PATCH applied] Re: openvpnmsica: Simplify find_adapters() to void return

In reply to Simon Rozman

Indeed, that looks simple and straightforward :-) - compile tested on MinGW.

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

commit 7f7b05395c3eb634e198d12e212360958c3ca8fb (master) commit 29e61986af6bfe4ca41163c4a1c74d90b1b0bdea (release/2.5)

Author: Simon Rozman via Openvpn-devel
Date:   Thu Sep 24 08:55:19 2020 +0200
     openvpnmsica: Simplify find_adapters() to void return

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

--
kind regards,

Gert Doering