From patchwork Mon Mar 9 02:17:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Rozman X-Patchwork-Id: 1026 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director8.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id IA/XElVCZl7BBwAAIUCqbw for ; Mon, 09 Mar 2020 09:19:17 -0400 Received: from proxy9.mail.ord1d.rsapps.net ([172.30.191.6]) by director8.mail.ord1d.rsapps.net with LMTP id QLizElVCZl7cagAAfY0hYg ; Mon, 09 Mar 2020 09:19:17 -0400 Received: from smtp13.gate.ord1d ([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 GMJtElVCZl4YcAAA7h+8OQ ; Mon, 09 Mar 2020 09:19:17 -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: smtp13.gate.ord1d.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: 939ae298-6208-11ea-a212-525400b197d9-1-1 Received: from [216.105.38.7] ([216.105.38.7:46282] helo=lists.sourceforge.net) by smtp13.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 4D/ED-16252-452466E5; Mon, 09 Mar 2020 09:19:17 -0400 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jBIIY-0005us-UU; Mon, 09 Mar 2020 13:18:22 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jBIIX-0005uc-Gy for openvpn-devel@lists.sourceforge.net; Mon, 09 Mar 2020 13:18:21 +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:References: In-Reply-To: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:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Vgofggg50l9duIhL2fpTVoxkWybZxkPrNKOoobeM7zA=; b=YRvzlQzv1P6RmPwjL79VBh4Vri Zua19V5ho7U/Z3OfGpbDjFKjyZ9RnNiuFw0IqhGiVB3tWwVfmNtQ5hwCVJy9TerIBCo2gXHGo0otS ebl80HBthoyztYOphAS1KZPdi14bt/j5Yf+zmurbcVYDq44Gd5vv1C/bQNBrPoMWREsY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: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:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Vgofggg50l9duIhL2fpTVoxkWybZxkPrNKOoobeM7zA=; b=Yj7YFxeNrN2OOBw1hfXrSwMCxT o25oLhKPsePVuSYxMpO9CRasy3wmdL4wTZjwFlexBu8oFG+m7W+LJ8wZo4ywKxsA3qxDEHLqJsjzP SBCt3Bg6aux451dV6ZrHIigzBdvOTfalTG42Lj9UKqmQjKwDQjM/hbkpbFHKZZRjSJy4=; Received: from pub5.amebis.si ([213.250.55.21]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jBIIV-00DVpS-M9 for openvpn-devel@lists.sourceforge.net; Mon, 09 Mar 2020 13:18:21 +0000 Received: by pub5.amebis.si (Postfix, from userid 1000) id 7D5F71002FBE; Mon, 9 Mar 2020 14:18:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rozman.si; s=default; t=1583759880; bh=Vgofggg50l9duIhL2fpTVoxkWybZxkPrNKOoobeM7zA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LefAEj6YZ3E/Za6czinKgxm8UhYS4GQMwwJwjb5exBjVcz8twmatyqMjqsVyPL+EW jZcrgh0S+rhbCYitpITVeacv/OXiyy1LBp754FonuaFiu4qkLMmAuopuWDsM+QC6Zi 8PvMcnIv/iiYxrFgWkqEyJ2rTYgJh66+Z3QJFUF4= 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, WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.3 Received: from SR6.amebis.doma (unknown [IPv6:2a00:ee2:209:164:a5ae:e83c:b7b:725]) by pub5.amebis.si (Postfix) with ESMTP id 942891002FCB; Mon, 9 Mar 2020 14:17:49 +0100 (CET) From: Simon Rozman To: openvpn-devel@lists.sourceforge.net Date: Mon, 9 Mar 2020 14:17:25 +0100 Message-Id: <20200309131728.380-9-simon@rozman.si> X-Mailer: git-send-email 2.24.1.windows.2 In-Reply-To: <20200309131728.380-1-simon@rozman.si> References: <20200309131728.380-1-simon@rozman.si> MIME-Version: 1.0 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 WEIRD_QUOTING BODY: Weird repeated double-quotation marks -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 -0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1jBIIV-00DVpS-M9 Subject: [Openvpn-devel] [PATCH 09/12] openvpnmsica: Extend to support arbitrary HWID network adapters 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 Signed-off-by: Simon Rozman Acked-by: Lev Stipakov --- src/openvpnmsica/openvpnmsica.c | 73 ++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/src/openvpnmsica/openvpnmsica.c b/src/openvpnmsica/openvpnmsica.c index 4223b680..cfbda8da 100644 --- a/src/openvpnmsica/openvpnmsica.c +++ b/src/openvpnmsica/openvpnmsica.c @@ -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? */