From patchwork Thu Jul 28 01:17:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lev Stipakov X-Patchwork-Id: 2610 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 yI5VErtw4mKBGAAAIUCqbw (envelope-from ) for ; Thu, 28 Jul 2022 07:19:23 -0400 Received: from proxy17.mail.ord1d.rsapps.net ([172.30.191.6]) by director8.mail.ord1d.rsapps.net with LMTP id qAIMErtw4mKwXgAAfY0hYg (envelope-from ) for ; Thu, 28 Jul 2022 07:19:23 -0400 Received: from smtp17.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy17.mail.ord1d.rsapps.net with LMTPS id iJF/Ebtw4mJWYgAAWC7mWg (envelope-from ) for ; Thu, 28 Jul 2022 07:19:23 -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: smtp17.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=gmail.com; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Suspicious-Flag: YES X-Classification-ID: 21699e36-0e67-11ed-9693-5254008de1cb-1-1 Received: from [216.105.38.7] ([216.105.38.7:55292] helo=lists.sourceforge.net) by smtp17.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 61/0F-01072-AB072E26; Thu, 28 Jul 2022 07:19:22 -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.94.2) (envelope-from ) id 1oH1Wx-0003Qv-5P; Thu, 28 Jul 2022 11:18:16 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oH1Wv-0003Qp-Lh for openvpn-devel@lists.sourceforge.net; Thu, 28 Jul 2022 11:18:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: MIME-Version:Content-Type:Content-Transfer-Encoding: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=vEbYYP2qcZrzkJaN0NQ2u4px1RV95pNa9CYJBRPnoow=; b=Ud0R6KFRivVACB3rXiVZtFoRLU W+h4WEcKkkjVwxHSLNciotEm6+6nwxqpjosvOL1E6GvBgkqk6DBXjk/UIMcpo8HBIyPIgUWkWU9iA tIlhAvNjrnxABmFSMUA3sEJv2dAovescSbW8p96Tv7siHsnRPEw3kx5vFBayTZTlk3BY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version: Content-Type:Content-Transfer-Encoding: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=vEbYYP2qcZrzkJaN0NQ2u4px1RV95pNa9CYJBRPnoow=; b=MY9c+6WMduwrHr+HFIjCBUrob6 Wddr5Kxq7dLq+zGPY7VLz8s90cPxI4kEFX+oVoWLn5rEl2J2VnhjIlVDd+aPNV4Wu8oq32ijrnatH Qldyos55K+sD9saMkF8q+XnWmqGkxtImoYVpsTWljDeCEZkTn+4W7ngC4GQLO/s9fzR0=; Received: from mail-lf1-f51.google.com ([209.85.167.51]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.94.2) id 1oH1Wv-00Cu3m-JC for openvpn-devel@lists.sourceforge.net; Thu, 28 Jul 2022 11:18:14 +0000 Received: by mail-lf1-f51.google.com with SMTP id bf9so2315922lfb.13 for ; Thu, 28 Jul 2022 04:18:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id; bh=vEbYYP2qcZrzkJaN0NQ2u4px1RV95pNa9CYJBRPnoow=; b=og7lqvVBFg3MOA3FvlVaR2zZ1WnmZrOlBBRyGV+11/HUzdtUznl/xphiar+8DnGQPf 5FEcM3HPMn3fjKSY5ufHb3K/Fr4Mkau7elYGQBxR6R6Mxrg0BesgOPLX+UIxchuQd5b9 AdyaulB3ng/QNQ12J3NaMy8PfeGrUNuJpuWG0tZOd8jIQen8tM6j1H//ZgMb1zw+ra0R 737H9JJ42FDXtRmxfP30mDVw4HRG45tcyKoIz0F3d4jb8N8Zu2ro7y8XWMlh6pr0weRJ 6cOzQ0WgVBoQV1itpV0Gaw3vivUr+VPWudeE/v5iL9hKfltRC2LCV12PTKohOlAuS4mL hfQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=vEbYYP2qcZrzkJaN0NQ2u4px1RV95pNa9CYJBRPnoow=; b=ga03VF57iWw4Px4V7FWcY3hZpOpNsHBZBIx5MBqQqYxgqlcDVtj9BYr5sXBcNL7e/N u8keoY+FqnPI2SzU6U2lTp4mUii9HzfOHwMcleWs2PLZigqsLqysc5sX2FO90zrUXpzL wa3FgJJbJeOB/iZVvwRf8wkYZcYs1FDAPYd148HNQimE+jajvNnc+DFKppJaSVZY/i5a 1z6ioYCUzqACvvuu7oYzwlyWtryivoiav1IrVRuu0Z1J6MwYT9lnU6tZodFI+nd++xgs qqX3Pqo0lWiprFl3BzYPBSl6Zcn1a0BTqZ9mdY37E/NeNWGc1lYuN2NqOSPrhgOHivKD Vbtg== X-Gm-Message-State: AJIora97c24t6Ws+U71EWp67q3LgkxZ+KYkGADXC53BJYO3z2SmNabbY hPpv+4Lxf+qCRrOIRFq3j5IDffAvJmg= X-Google-Smtp-Source: AGRyM1sPSoXwk0gm3rqI8WH7FhEMS+KZznlAbxrOD5ggmnwwiTR5E1Os4zdUpKGIJkXeBfEXJiQ9uQ== X-Received: by 2002:a05:6512:3186:b0:48a:c33e:f5e with SMTP id i6-20020a056512318600b0048ac33e0f5emr1375248lfe.531.1659007086220; Thu, 28 Jul 2022 04:18:06 -0700 (PDT) Received: from LAPTOP-4L3N7KFS.localdomain (nat4.panoulu.net. [185.38.2.4]) by smtp.gmail.com with ESMTPSA id l21-20020a194955000000b00489ec0d7636sm153463lfj.110.2022.07.28.04.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jul 2022 04:18:05 -0700 (PDT) From: Lev Stipakov To: openvpn-devel@lists.sourceforge.net Date: Thu, 28 Jul 2022 14:17:12 +0300 Message-Id: <20220728111712.94-1-lstipakov@gmail.com> X-Mailer: git-send-email 2.17.1 X-Spam-Report: Spam detection software, running on the system "util-spamd-1.v13.lw.sourceforge.com", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Lev Stipakov This code reads the state of OpenVPNService, such as startup mode and running, and sets MSI property value. If that property is set, installer selects OpenVPNService as a feature to be installed. Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [lstipakov[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.167.51 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.167.51 listed in list.dnswl.org] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-Headers-End: 1oH1Wv-00Cu3m-JC Subject: [Openvpn-devel] [PATCH] openvpnmsica: remove OpenVPNService state check code 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: , Cc: Lev Stipakov MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Lev Stipakov This code reads the state of OpenVPNService, such as startup mode and running, and sets MSI property value. If that property is set, installer selects OpenVPNService as a feature to be installed. This has been superseded by change in installer: https://github.com/OpenVPN/openvpn-build/pull/261 which, in addition to checking the state of OpenVPNService, applies that state to the newly installed service. - by default, OpenVPNService feature is now checked and service is installed - in clean installation, service startup mode is set to "manual" and service is not started - in upgrade, installer preserves the service state, such as startup mode and started/stopped With all those changes to installer, we don't need this code in openvpnmsica. Signed-off-by: Lev Stipakov Acked-by: Selva Nair Signed-off-by: Lev Stipakov <lev@openvpn.net>
--- src/openvpnmsica/openvpnmsica.c | 115 -------------------------------- 1 file changed, 115 deletions(-) diff --git a/src/openvpnmsica/openvpnmsica.c b/src/openvpnmsica/openvpnmsica.c index 843b5762..538cdbaa 100644 --- a/src/openvpnmsica/openvpnmsica.c +++ b/src/openvpnmsica/openvpnmsica.c @@ -147,120 +147,6 @@ _debug_popup(_In_z_ LPCSTR szFunctionName) #define debug_popup(f) #endif /* ifdef _DEBUG */ - -/** - * 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 - * auto-start, but not running. - * - * @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 -set_openvpnserv_state(_In_ MSIHANDLE hInstall) -{ - UINT uiResult; - - /* Get Service Control Manager handle. */ - SC_HANDLE hSCManager = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CONNECT); - if (hSCManager == NULL) - { - uiResult = GetLastError(); - msg(M_NONFATAL | M_ERRNO, "%s: OpenSCManager() failed", __FUNCTION__); - return uiResult; - } - - /* Get OpenVPNService service handle. */ - SC_HANDLE hService = OpenService(hSCManager, TEXT("OpenVPNService"), SERVICE_QUERY_STATUS | SERVICE_QUERY_CONFIG); - if (hService == NULL) - { - uiResult = GetLastError(); - if (uiResult == ERROR_SERVICE_DOES_NOT_EXIST) - { - /* This is not actually an error. */ - goto cleanup_OpenSCManager; - } - msg(M_NONFATAL | M_ERRNO, "%s: OpenService(\"OpenVPNService\") failed", __FUNCTION__); - goto cleanup_OpenSCManager; - } - - /* Query service status. */ - SERVICE_STATUS_PROCESS ssp; - DWORD dwBufSize; - if (QueryServiceStatusEx(hService, SC_STATUS_PROCESS_INFO, (LPBYTE)&ssp, sizeof(ssp), &dwBufSize)) - { - switch (ssp.dwCurrentState) - { - case SERVICE_START_PENDING: - case SERVICE_RUNNING: - case SERVICE_STOP_PENDING: - case SERVICE_PAUSE_PENDING: - case SERVICE_PAUSED: - case SERVICE_CONTINUE_PENDING: - { - /* Service is started (kind of). Set OPENVPNSERVICE property to service PID. */ - TCHAR szPID[10 /*MAXDWORD in decimal*/ + 1 /*terminator*/]; - _stprintf_s( - szPID, _countof(szPID), - TEXT("%u"), - ssp.dwProcessId); - - uiResult = MsiSetProperty(hInstall, TEXT("OPENVPNSERVICE"), szPID); - 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(\"OPENVPNSERVICE\") failed", __FUNCTION__); - } - - /* We know user is using the service. Skip auto-start setting check. */ - goto cleanup_OpenService; - } - break; - } - } - else - { - uiResult = GetLastError(); - msg(M_NONFATAL | M_ERRNO, "%s: QueryServiceStatusEx(\"OpenVPNService\") failed", __FUNCTION__); - } - - /* Service is not started. Is it set to auto-start? */ - /* MSDN describes the maximum buffer size for QueryServiceConfig() to be 8kB. */ - /* This is small enough to fit on stack. */ - BYTE _buffer_8k[8192]; - LPQUERY_SERVICE_CONFIG pQsc = (LPQUERY_SERVICE_CONFIG)_buffer_8k; - dwBufSize = sizeof(_buffer_8k); - if (!QueryServiceConfig(hService, pQsc, dwBufSize, &dwBufSize)) - { - uiResult = GetLastError(); - msg(M_NONFATAL | M_ERRNO, "%s: QueryServiceStatusEx(\"QueryServiceConfig\") failed", __FUNCTION__); - goto cleanup_OpenService; - } - - if (pQsc->dwStartType <= SERVICE_AUTO_START) - { - /* Service is set to auto-start. Set OPENVPNSERVICE property to its path. */ - uiResult = MsiSetProperty(hInstall, TEXT("OPENVPNSERVICE"), pQsc->lpBinaryPathName); - 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(\"OPENVPNSERVICE\") failed", __FUNCTION__); - goto cleanup_OpenService; - } - } - - uiResult = ERROR_SUCCESS; - -cleanup_OpenService: - CloseServiceHandle(hService); -cleanup_OpenSCManager: - CloseServiceHandle(hSCManager); - return uiResult; -} - - static void find_adapters( _In_ MSIHANDLE hInstall, @@ -423,7 +309,6 @@ FindSystemInfo(_In_ MSIHANDLE hInstall) OPENVPNMSICA_SAVE_MSI_SESSION(hInstall); - set_openvpnserv_state(hInstall); find_adapters( hInstall, TEXT("root\\") TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0") TEXT(TAP_WIN_COMPONENT_ID) TEXT("\0"),