From patchwork Wed Jul 25 07:01:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristof Provost via Openvpn-devel X-Patchwork-Id: 430 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director7.mail.ord1d.rsapps.net ([172.27.255.57]) by backend30.mail.ord1d.rsapps.net (Dovecot) with LMTP id XMEvFECtWFvPGAAAIUCqbw for ; Wed, 25 Jul 2018 13:02:56 -0400 Received: from proxy5.mail.iad3a.rsapps.net ([172.27.255.57]) by director7.mail.ord1d.rsapps.net (Dovecot) with LMTP id A0/FGECtWFv5JAAAovjBpQ ; Wed, 25 Jul 2018 13:02:56 -0400 Received: from smtp6.gate.iad3a ([172.27.255.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy5.mail.iad3a.rsapps.net with LMTP id YHTdFkCtWFs1ewAAhn5joQ ; Wed, 25 Jul 2018 13:02:56 -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: smtp6.gate.iad3a.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=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=microsoft.com; dmarc=pass (p=none; dis=none) header.from=lists.sourceforge.net X-Suspicious-Flag: YES X-Classification-ID: 928e8a58-902c-11e8-8b89-5254002f0085-1-1 Received: from [216.105.38.7] ([216.105.38.7:47875] helo=lists.sourceforge.net) by smtp6.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.1.56364 r(Core:4.2.1.14)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 98/08-13037-F3DA85B5; Wed, 25 Jul 2018 13:02:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Type:Reply-To:From:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject: MIME-Version:Message-ID:Date:To:Sender:Cc: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-Owner; bh=ynx0QBVixU/pZKBMYLeiS1QwXepcbVkIvSu0GJNQuNQ=; b=Rtd7gKRiJxLy6+GnlzSObwSSYu W6Uj1JmW6ZwCT8ptmL84WcJHhMOWU395/g1qAqwiyL0quYLdPyy6wOFokQ469JhiSJ9YhvvyWnBG2 6OGF6lgaIkh1UdpGhmBveasJ7vXgxYgJ94k6XcY3Eyt1ELL/qO+gHYnYYJrB5oI2T8vE=; 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 1fiNAh-0004GR-7k; Wed, 25 Jul 2018 17:01:55 +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 1fiNAg-0004GH-Fg for openvpn-devel@lists.sourceforge.net; Wed, 25 Jul 2018 17:01:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Message-ID:Date:Subject: To:From:Sender:Reply-To:Cc: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=akt3ixTvm3bTEW5//4lqenfGXmcLyo5UAGO+84EiiC4=; b=NfUls2/1ObuuwoLhsuaNOXgdbc iAde1CLOtUH3Zf/JfB0wRfgeT9AvIkNQjB2Kop7iGSzdpmvJYhqhXB12Ik0dogqQnFCSZCC6gCP8B m+DnPNZstFumE7Fcg+/f6mMjH8A1PPuEJU+lZNb0dDIzR/ZGzq524eW4P65dTlNg9Hyo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Message-ID:Date:Subject:To:From:Sender:Reply-To :Cc: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=akt3ixTvm3bTEW5//4lqenfGXmcLyo5UAGO+84EiiC4=; b=h J7gbop9TJW2MyF4fUPNAq2eaLDggMqnMLp3OAd6Ml8ABCuzqhhcTFSft2OR85utK/24x1iSGmP3i+ btV3jKhHryg07DZ8d3LuL3IAwASDuhIubHbiL+NnZa4vxQt28j9LnZNg61vCeSrDvzJOCmSnJREHB joKS5jek11QsRTcM=; Received: from mail-eopbgr680102.outbound.protection.outlook.com ([40.107.68.102] helo=NAM04-BN3-obe.outbound.protection.outlook.com) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) (Exim 4.90_1) id 1fiNAd-00BUcV-Ri for openvpn-devel@lists.sourceforge.net; Wed, 25 Jul 2018 17:01:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=akt3ixTvm3bTEW5//4lqenfGXmcLyo5UAGO+84EiiC4=; b=N4N1QwMkvFTj0fmOkNvIa9oLaeizRaUUSZmXY3VsHOrXOdqIWYg3xdxQwim7tYp2veFAIGBPNZV78i0uZYWpgWP1vAGtSXgVm/N/Bf3WRcx+tN+hK0lFPIwwuAa1G+eNxKO+U5CM6XW0hXV1U3gUrSNtYl570tCrFj/VCz61QEk= Received: from BL0PR2101MB1058.namprd21.prod.outlook.com (52.132.24.16) by BL0PR2101MB0914.namprd21.prod.outlook.com (52.132.23.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1017.2; Wed, 25 Jul 2018 17:01:43 +0000 Received: from BL0PR2101MB1058.namprd21.prod.outlook.com ([fe80::178:4c86:5dda:c4db]) by BL0PR2101MB1058.namprd21.prod.outlook.com ([fe80::178:4c86:5dda:c4db%3]) with mapi id 15.20.1017.000; Wed, 25 Jul 2018 17:01:43 +0000 To: openvpn-devel Thread-Topic: [PATCH] [openvpn] Register/unregister trusted custom dialer DLL when installing/uninstalling service Thread-Index: AdQjeMq3SUfoAWYDSjG7Ni7FHII+qQ== Date: Wed, 25 Jul 2018 17:01:38 +0000 Deferred-Delivery: Wed, 25 Jul 2018 17:00:56 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Enabled=True; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SiteId=72f988bf-86f1-41af-91ab-2d7cd011db47; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Owner=kkane@microsoft.com; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_SetDate=2018-07-25T16:59:56.6516582Z; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Name=General; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Application=Microsoft Azure Information Protection; MSIP_Label_f42aa342-8706-4288-bd11-ebb85995028c_Extended_MSFT_Method=Automatic; Sensitivity=General x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; BL0PR2101MB0914; 6:FSxpoQUc9MWe5T2qfCEojODc5n66JiQg9mqpNA/azzc1DWgeAXl9KuBHYwekJqZI/JGmn/HssWxd09w+KTjzCspS8ayCtOuYCE3zyFKeAuRjwR9OF70NEHJLwIQ6qfhiW6hgu9cbg2x6S4axYfQUxFIOFqnh8lvrN6IsLIVBz0Sze2owhme6qfeldyHd6oIvFWGl6CL1Hb/pFLKXr4U1FsSFbU9IjgzZEsfPSmkl3ZgvqgFe7HKHPk1VkJ2TecCG/HRFVshkwFRF086ldfeCDipaKLdmVWEPWIlBnpKWlH4DNG0WLkq3FH0HjHaVdmHTgNbweyjKxIJm+CiDIgx/C3kGd63LGdJE3H5i6GRLKViIGelvIJclxowQDPnqlI01Pxvka1XCWOIUDBpdwIk6OY0LE2BJMPrhzNEEODosUo4HTqU4swonIN+1nw2Yiar+XVDdW20Te3D4lxtAzWXLAQ==; 5:a9d28xB8DkUg2HYtd6QNob9hzuN7ko71Wnl11KAyaRM/lZ0tKTHJHaCaMkY2WJ15LavrUYwNHvkzdC9xSCkiiJ0PMNEnRuL/7/t5oOlTPba8CenJbPf6Dawhd2EyLFXX4lA8l3KX2mG+mF7QzrnofMdAqLBuTnHh/oGpcEYcoQ8=; 7:jgSUYTWBrcwWS6Nw1rEuQ9YrAwLku/UNcaNA5niD8qZi7P+xEzukZzj+Tq+cn0aF8ZxAHaqeO4ZXZ5LNJDpT7QqEF73Q4zgPZvF9p69opEUxpJ53gQLNF7GW3mmFARA3EP8VkCFfblvK9KcIA113hJcVT+d5355gNXPPAUvUElMruzZqdAf0+TnumSz+UoSrskga/WTM3ln67wEa5KN2djHTfc8mdQeiUVYHLSfWZe/nyE6/TPAxzlawCHxRuu4B x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 55963f17-db1c-4ba9-1422-08d5f2504c32 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600073)(711020)(4618075)(2017052603328)(7193020); SRVR:BL0PR2101MB0914; x-ms-traffictypediagnostic: BL0PR2101MB0914: x-o365-sonar-daas-pilot: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(21748063052155)(197898729827340); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231311)(944501410)(52105095)(2018427008)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011)(7699016); SRVR:BL0PR2101MB0914; BCL:0; PCL:0; RULEID:; SRVR:BL0PR2101MB0914; x-forefront-prvs: 0744CFB5E8 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(366004)(346002)(396003)(136003)(39860400002)(199004)(189003)(81166006)(6116002)(9686003)(55016002)(790700001)(8990500004)(54896002)(6306002)(68736007)(14454004)(14444005)(33656002)(2900100001)(316002)(476003)(1857600001)(478600001)(102836004)(7736002)(7696005)(25786009)(10090500001)(22452003)(186003)(10290500003)(53546011)(6506007)(256004)(486006)(46003)(584604001)(97736004)(5250100002)(86612001)(575784001)(106356001)(5660300001)(105586002)(2906002)(53936002)(74316002)(8936002)(6666003)(6916009)(53946003)(81156014)(99286004)(6436002)(8676002)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:BL0PR2101MB0914; H:BL0PR2101MB1058.namprd21.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: Oc8LFtQsUMqr17wGzwc2KJkwSbeoav2S3q6ctFKhcg0wAV82U5mRVEYYJta4FJJM4jJg7/7m1Re0dVZjXK7PB9Rtb4PeQymrvQ5W/l3KwFgPdzhhD94E6sZ1VCtWkA/bL+jsR4r2q1/IIeaDDoHofqQupJWcf17128wYpTA1vQSHNpcx+NUvjZZdH0kCr/uAFEs09ux4xewLt2S8x2tEH6eZQdgVhN+zrqCd6T4BL2EBYvN9lOl/b6TTEmk92YgATRlgbA6pO/PkLOhoMsZf1HG2WlLUr9xd5i+KEnpjiTuVlkNDC10oUWM/00FaIw2yNbGuRTboxlebDvspAKdmv9VYhmZIUB5Unt2jg8ZmnXo= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55963f17-db1c-4ba9-1422-08d5f2504c32 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Jul 2018 17:01:42.4803 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB0914 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [40.107.68.102 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record 1.0 HTML_MESSAGE BODY: HTML included in message -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.0 T_DKIMWL_WL_HIGH DKIMwl.org - Whitelisted High sender X-Headers-End: 1fiNAd-00BUcV-Ri Subject: [Openvpn-devel] [PATCH] [openvpn] Register/unregister trusted custom dialer DLL when installing/uninstalling service 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: , X-Patchwork-Original-From: Kevin Kane via Openvpn-devel From: Kristof Provost via Openvpn-devel Reply-To: Kevin Kane Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From 58cc8b37f567da867e3a6e2efa4c15de36495a79 Mon Sep 17 00:00:00 2001 From: Kevin Kane Date: Fri, 13 Jul 2018 09:44:00 -0700 Subject: Register/unregister trusted custom dialer DLL when installing/uninstalling service Add copyright notice as required where Microsoft has contributed code Signed-off-by: Kevin Kane --- src/openvpnserv/service.c | 241 +++++++++++++++++++++++++++++++++++--- 1 file changed, 222 insertions(+), 19 deletions(-) -- 2.17.1.windows.2 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot diff --git a/src/openvpnserv/service.c b/src/openvpnserv/service.c index 7157bea2..edb21b0d 100644 --- a/src/openvpnserv/service.c +++ b/src/openvpnserv/service.c @@ -6,6 +6,7 @@ * * Copyright (C) 1993 - 2000. Microsoft Corporation. All rights reserved. * 2013 Heiko Hund + * Portions Copyright (C) 2018 Microsoft Corporation */ #include "service.h" @@ -53,6 +54,195 @@ ReportStatusToSCMgr(SERVICE_STATUS_HANDLE service, SERVICE_STATUS *status) return res; } +static const TCHAR DialerDllName[] = TEXT("libopenvpndialer-0.dll"); +static const TCHAR RegValueName[] = TEXT("CustomDLL"); + +static int +HandleDialerRegistration(int uninstall) +{ + TCHAR path[512], customDllString[1024]; + HKEY parametersKey; + LONG result; + DWORD customDllSize = sizeof(customDllString); + + /* Assumption is that the dialer DLL is installed to the same bin directory as everything else. */ + if (GetModuleFileName(NULL, path, sizeof(path)) == 0) + { + _tprintf(TEXT("Unable to get module path - %lu\n"), GetLastError()); + return 1; + } + + /* The version of NSIS we use to create the installer doesn't yet have support for + * writing multi-string registry entries, which we need to do in order to register our + * custom dialer DLL. Instead, we'll update this registry entry on install/uninstall. + */ + + TCHAR *lastBackslash = _tcsrchr(path, TEXT('\\')); + if (NULL == lastBackslash) + { + _tprintf(TEXT("Could not locate last backslash in path: %s\n"), path); + return 1; + } + + lastBackslash[1] = TEXT('\0'); + + /* Bounds checking. */ + if ((_tcslen(path) + _countof(DialerDllName)) > _countof(path)) + { + _tprintf(TEXT("Out of buffer adding dialer filename to path")); + return 1; + } + + _tcscat(path, DialerDllName); + + result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + TEXT("SYSTEM\\CurrentControlSet\\Services\\RasMan\\Parameters"), + 0, + KEY_ALL_ACCESS, + ¶metersKey); + if (ERROR_SUCCESS != result) + { + _tprintf(TEXT("Could not open RasMan parameters key: %ld\n"), result); + return 1; + } + + /* Must RegCloseKey(parametersKey) from this point */ + + result = RegGetValue(parametersKey, + NULL, + RegValueName, + RRF_RT_REG_MULTI_SZ, + NULL, + customDllString, + &customDllSize); + + /* If we're installing, the key being absent is okay. Any other error is fatal. */ + if (ERROR_FILE_NOT_FOUND == result) + { + if (0 != uninstall) + { + _tprintf(TEXT("CustomDLL value was not found; skipping unregistration step\n")); + RegCloseKey(parametersKey); + return 0; /* Not a fatal error but nothing to do */ + } + else + { + result = ERROR_SUCCESS; + customDllString[0] = TEXT('\0'); + customDllSize = 0; + } + } + else if (ERROR_SUCCESS != result) + { + _tprintf(TEXT("Could not open CustomDLL value: %ld\n"), result); + RegCloseKey(parametersKey); + return 1; + } + + /* Determine if the custom dialer DLL is present in the registry setting. This is a multi-string so we can't + * use _tcsstr. + */ + TCHAR* p; + for (p = customDllString; *p != TEXT('\0'); p += _tcslen(p) + 1) + { + if (0 == _tcsicmp(path, p)) + { + /* It is. p points to where it begins. */ + break; + } + } + /* If it's not present, p points at a NULL terminator. */ + + /* If we're installing and the DLL is present in the registry, do nothing. */ + /* If we're uninstalling and the DLL is not present in the registry, do nothing. */ + if ( ((0 == uninstall) && (*p != TEXT('\0'))) || + ((0 != uninstall) && (*p == TEXT('\0'))) ) + { + RegCloseKey(parametersKey); + return 0; + } + + /* If we're installing and the DLL is not present in the registry, append it at point p. */ + if ((0 == uninstall) && (*p == TEXT('\0'))) + { + /* Make sure the string buffer has enough space left. p points at the second in the double-terminating null + * (or the sole NULL if the registry entry was empty or absent). + */ + if (((p - customDllString) + _tcslen(path) + 2) > _countof(customDllString)) + { + _tprintf(TEXT("Not enough buffer to create new CustomDLL string\n")); + RegCloseKey(parametersKey); + return 1; + } + _tcscpy(p, path); + /* Add second terminating NULL we overwrote with the copy. */ + p += _tcslen(p) + 1; + *p++ = TEXT('\0'); + + /* Set in the registry. */ + result = RegSetValueEx(parametersKey, + RegValueName, + 0, + REG_MULTI_SZ, + (const BYTE*)customDllString, + (DWORD)(sizeof(TCHAR) * (p - customDllString))); + + RegCloseKey(parametersKey); + if (ERROR_SUCCESS != result) + { + _tprintf(TEXT("Failed to RegSetValueEx: %ld\n"), result); + return 1; + } + } + /* Else if we're uninstalling and the DLL is present, copy everything except strings matching path. */ + else if ((0 != uninstall) && (*p != TEXT('\0'))) + { + TCHAR newCustomDllString[1024]; + TCHAR *n, *c; + + /* newCustomDllString is the same size as customDllString, and we're only removing, so no + * way to overflow the buffer. + */ + for (c = customDllString, n = newCustomDllString; *c != TEXT('\0'); c += _tcslen(c) + 1) + { + if (0 != _tcsicmp(path, c)) + { + _tcscpy(n, c); + n += _tcslen(n) + 1; + } + } + + /* Add double-terminating NULL as is required for a multi-string. */ + *n++ = TEXT('\0'); + + /* If the new string is nonempty, set in the registry. Otherwise delete the value. */ + if (TEXT('\0') != *newCustomDllString) + { + result = RegSetValueEx(parametersKey, + RegValueName, + 0, + REG_MULTI_SZ, + (const BYTE*)newCustomDllString, + (DWORD)(sizeof(TCHAR) * (n - newCustomDllString))); + } + else + { + result = RegDeleteValue(parametersKey, RegValueName); + } + + RegCloseKey(parametersKey); + if (ERROR_SUCCESS != result) + { + _tprintf(TEXT("Failed to %s new registry value: %ld\n"), + (TEXT('\0') != *newCustomDllString)?TEXT("set"):TEXT("delete"), + result); + return 1; + } + } + + return 0; +} + static int CmdInstallServices() { @@ -77,27 +267,35 @@ CmdInstallServices() return 1; } - for (i = 0; i < _service_max; i++) + if (0 != HandleDialerRegistration(0)) { - service = CreateService(svc_ctl_mgr, - openvpn_service[i].name, - openvpn_service[i].display_name, - SERVICE_QUERY_STATUS, - SERVICE_WIN32_SHARE_PROCESS, - openvpn_service[i].start_type, - SERVICE_ERROR_NORMAL, - path, NULL, NULL, - openvpn_service[i].dependencies, - NULL, NULL); - if (service) - { - _tprintf(TEXT("%s installed.\n"), openvpn_service[i].display_name); - CloseServiceHandle(service); - --ret; - } - else + _tprintf(TEXT("HandleDialerRegistration failed\n")); + ret = 1; + } + else + { + for (i = 0; i < _service_max; i++) { - _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText()); + service = CreateService(svc_ctl_mgr, + openvpn_service[i].name, + openvpn_service[i].display_name, + SERVICE_QUERY_STATUS, + SERVICE_WIN32_SHARE_PROCESS, + openvpn_service[i].start_type, + SERVICE_ERROR_NORMAL, + path, NULL, NULL, + openvpn_service[i].dependencies, + NULL, NULL); + if (service) + { + _tprintf(TEXT("%s installed.\n"), openvpn_service[i].display_name); + CloseServiceHandle(service); + --ret; + } + else + { + _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText()); + } } } @@ -160,6 +358,11 @@ CmdRemoveServices() return 1; } + if (0 != HandleDialerRegistration(1)) + { + _tprintf(TEXT("HandleDialerRegistration uninstall failed; ignoring\n")); + } + for (i = 0; i < _service_max; i++) { openvpn_service_t *ovpn_svc = &openvpn_service[i];