From patchwork Mon Mar 9 23:40:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Rozman X-Patchwork-Id: 1035 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director9.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id ELVRNORuZ17JKQAAIUCqbw for ; Tue, 10 Mar 2020 06:41:40 -0400 Received: from proxy9.mail.ord1d.rsapps.net ([172.30.191.6]) by director9.mail.ord1d.rsapps.net with LMTP id wNo/NORuZ17daQAAalYnBA ; Tue, 10 Mar 2020 06:41:40 -0400 Received: from smtp35.gate.ord1c ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy9.mail.ord1d.rsapps.net with LMTP id 4CLEM+RuZ16YQgAA7h+8OQ ; Tue, 10 Mar 2020 06:41:40 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp35.gate.ord1c.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=rozman.si; dmarc=fail (p=none; dis=none) header.from=rozman.si X-Suspicious-Flag: YES X-Classification-ID: b93ce61e-62bb-11ea-b2a0-5452002f485d-1-1 Received: from [216.105.38.7] ([216.105.38.7:33112] helo=lists.sourceforge.net) by smtp35.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 78/43-03804-3EE676E5; Tue, 10 Mar 2020 06:41:40 -0400 Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jBcJd-0006Uh-JF; Tue, 10 Mar 2020 10:40:49 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jBcJc-0006Ua-7a for openvpn-devel@lists.sourceforge.net; Tue, 10 Mar 2020 10:40:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=OMKMdM1G/ekXIE3z8WtXLRqFZ2Q+vc175q2Izodapo0=; b=TeEQZhVWRCDfP8pNXYGpPaqNzJ KZp2I2CRK9RKW6OI2HmgOYHSDeW60mWF4ShpAKeIHa1NggEcaRwumOp7XZJKqgRceh8t+mgjSpZ8k ZWobwOFZycYgohBndZyuL5mtZhDS13NqVm+Nt90TbjBHqmSGz8epsBwdb4Vw+31CfhcQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=OMKMdM1G/ekXIE3z8WtXLRqFZ2Q+vc175q2Izodapo0=; b=j SePtkZdoKlvTmaBaQgMTbRKdbbsSdFYlnYE+ojqR3CkiahZTBXCL06Bt5qG3Jnqn/bN3blPFIjDKB wVK1ZN8HwqlaZfi+YG7gq1IVUoLpd51Mc22me+uEtbQfLxJFBxgsoDuxmSlLi0q/QLOaeMSxbt9E7 o/lOYtZvOILOzMhQ=; Received: from pub5.amebis.si ([213.250.55.21]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jBcJY-003qy9-SK for openvpn-devel@lists.sourceforge.net; Tue, 10 Mar 2020 10:40:48 +0000 Received: by pub5.amebis.si (Postfix, from userid 1000) id 0BE261002F94; Tue, 10 Mar 2020 11:40:33 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rozman.si; s=default; t=1583836833; bh=OMKMdM1G/ekXIE3z8WtXLRqFZ2Q+vc175q2Izodapo0=; h=From:To:Cc:Subject:Date:From; b=rEN7v/W/DnAMpI/dHHUYNuQ+KBJeqYZ4+fO2LXD751rXnjAWvajLWvmhNZSU+yK9B cVebwVw5F1Mnd2NDVcimYrFgYmnQ4xby/Qemp9ZoOc8ZnBpNzh5+oNoEWOMNA4J0Wd sKJfGzHWySK+2ir97i/drPmAuaIwuDCl9mwaLN2k= X-Spam-Checker-Version: SpamAssassin 3.4.3 (2019-12-06) on brana.amebis.doma X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.3 Received: from SR6.amebis.doma (unknown [IPv6:2a00:ee2:209:164:9d4:142e:b222:827d]) by pub5.amebis.si (Postfix) with ESMTP id 83B9B1002F87; Tue, 10 Mar 2020 11:40:27 +0100 (CET) From: Simon Rozman To: openvpn-devel@lists.sourceforge.net Date: Tue, 10 Mar 2020 11:40:22 +0100 Message-Id: <20200310104022.431-1-simon@rozman.si> X-Mailer: git-send-email 2.24.1.windows.2 MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: rozman.si] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1jBcJY-003qy9-SK Subject: [Openvpn-devel] [PATCH v2 12/12] tapctl: Support multiple hardware IDs X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox 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. Signed-off-by: Simon Rozman Acked-by: Lev Stipakov --- src/openvpnmsica/openvpnmsica.c | 43 ++++++++++++++++++--------------- src/tapctl/main.c | 24 +++++++++++------- src/tapctl/tap.c | 21 ++++++++++++---- src/tapctl/tap.h | 8 +++--- 4 files changed, 58 insertions(+), 38 deletions(-) diff --git a/src/openvpnmsica/openvpnmsica.c b/src/openvpnmsica/openvpnmsica.c index 28cf16b5..31e90bd2 100644 --- a/src/openvpnmsica/openvpnmsica.c +++ b/src/openvpnmsica/openvpnmsica.c @@ -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: diff --git a/src/tapctl/main.c b/src/tapctl/main.c index fdeda7bf..31bb2ec7 100644 --- a/src/tapctl/main.c +++ b/src/tapctl/main.c @@ -81,12 +81,13 @@ static const TCHAR usage_message_create[] = TEXT(" specified, a default adapter name is chosen by Windows. \n") TEXT(" Note: This name can also be specified as OpenVPN's --dev-node \n") TEXT(" option. \n") - TEXT("--hwid Adapter hardware id. Default value is root\\tap0901, which \n") + TEXT("--hwid Adapter hardware ID. Default value is root\\tap0901, which \n") TEXT(" describes tap-windows6 driver. To work with wintun driver, \n") TEXT(" specify 'wintun'. \n") + TEXT("\n") TEXT("Output:\n") TEXT("\n") - TEXT("This command prints newly created TUN/TAP adapter's GUID to stdout. \n") + TEXT("This command prints newly created TUN/TAP adapter's GUID to stdout. \n") ; static const TCHAR usage_message_list[] = @@ -100,12 +101,12 @@ static const TCHAR usage_message_list[] = TEXT("\n") TEXT("Options:\n") TEXT("\n") - TEXT("--hwid Adapter hardware id. Default value is root\\tap0901, which \n") - TEXT(" describes tap-windows6 driver. To work with wintun driver, \n") - TEXT(" specify 'wintun'. \n") + TEXT("--hwid Adapter hardware ID. By default, root\\tap0901, tap0901 and \n") + TEXT(" wintun adapters are listed. Use this switch to limit the list. \n") + TEXT("\n") TEXT("Output:\n") TEXT("\n") - TEXT("This command prints all TUN/TAP adapters to stdout. \n") + TEXT("This command prints all TUN/TAP adapters to stdout. \n") ; static const TCHAR usage_message_delete[] = @@ -271,14 +272,19 @@ 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") + TEXT("Wintun\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)); + ++i; + memcpy_s(szzHwId, sizeof(szzHwId) - 2*sizeof(TCHAR) /*requires double zero termination*/, argv[i], _tcslen(argv[i])*sizeof(TCHAR)); } else { @@ -288,7 +294,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); diff --git a/src/tapctl/tap.c b/src/tapctl/tap.c index bdef3fc1..8ece3fb9 100644 --- a/src/tapctl/tap.c +++ b/src/tapctl/tap.c @@ -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 diff --git a/src/tapctl/tap.h b/src/tapctl/tap.h index 68662c82..102de32d 100644 --- a/src/tapctl/tap.h +++ b/src/tapctl/tap.h @@ -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);