From patchwork Wed Jul 25 07:01:39 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: 431 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.27.255.7]) by backend30.mail.ord1d.rsapps.net (Dovecot) with LMTP id TNAsE0qtWFt7EwAAIUCqbw for ; Wed, 25 Jul 2018 13:03:07 -0400 Received: from proxy4.mail.iad3a.rsapps.net ([172.27.255.7]) by director10.mail.ord1d.rsapps.net (Dovecot) with LMTP id vaHFDkqtWFtaJgAApN4f7A ; Wed, 25 Jul 2018 13:03:06 -0400 Received: from smtp30.gate.iad3a ([172.27.255.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy4.mail.iad3a.rsapps.net with LMTP id MIqMMUqtWFsTdwAA8Zvu4w ; Wed, 25 Jul 2018 13:03:06 -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: smtp30.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=pass 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: NO X-Classification-ID: 9909fca0-902c-11e8-8191-525400089674-1-1 Received: from [216.105.38.7] ([216.105.38.7:31000] helo=lists.sourceforge.net) by smtp30.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 3F/00-12494-A4DA85B5; Wed, 25 Jul 2018 13:03:06 -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=VVKmYbtBVRcMjAMgjbCCUaDopYEvOKOx8X2Cvspk/ZY=; b=LTATu01ZOXACAe9HvEAiMBFWVV fwsQC03K/YyjjZAkPURZX4BtrcNaw12NAoGPJBfUadPSH2V5MD+m6a6kAumY3bKaiJ1HWdUWwtrBW UTsvU77J1T6/Gn8DFpa5aJAxK3sywOjbrYEyMbrUBwhi8aqttfO14TwVriT5HhG0frfs=; 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 1fiNAn-0002Fw-P7; Wed, 25 Jul 2018 17:02:01 +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 1fiNAl-0002Fk-VG for openvpn-devel@lists.sourceforge.net; Wed, 25 Jul 2018 17:01:59 +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=FbohwPmqqNXRC+yPeJpVmS7B1N9ctdhV4c/9/Ox5A0Y=; b=hy/EMWJtrLHTdI6gb4lp68wH3W GJFBpzNom3MyMqhgboynA0DUFcHwk/KbJC+BZWI6H6O9NrzcG73mrK/O2/tocJROdFawGkDbhpSdX C2UY2rj+kRLg0ZbK4moX6Vuw0hlpA2d5XZ3PV9us1OUfGFqNscFRPGJdnLPVjlBE9skA=; 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=FbohwPmqqNXRC+yPeJpVmS7B1N9ctdhV4c/9/Ox5A0Y=; b=O qA2mrulElcY3FeAM+veMXLGGmJzUIrmDcDQuAbFdRvXhRJHxyw8ST9qgNKRET8FQfizYfqzNO0tMN uFHWBNwq9/vLrwbsWwyceLAybIGjXXf0PiTf33j85JoNa64VxNX2Hcfa9YMD+ciJQmOMkTXigmdmE C7AX6ylh4YBsmYs0=; 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 1fiNAi-00BUcV-Ct for openvpn-devel@lists.sourceforge.net; Wed, 25 Jul 2018 17:01:59 +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=FbohwPmqqNXRC+yPeJpVmS7B1N9ctdhV4c/9/Ox5A0Y=; b=nURcUZPm5GkO1OCkZQj6Calwd//RgPcdNOkP849v/HfhVQhu4gVwk6DrRCb9IeJgSk6FHzIrx83ieczvrJ9T8BhVtg8Og7RUhQ7oTU5CyTFbUN4UA3yo2eLnzrGQAD70PJAHttHen50+G0N1fUK5CzEkWiOKyO7u2mUlfXhpO04= 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:44 +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:44 +0000 To: openvpn-devel Thread-Topic: [PATCH] [openvpn-gui] Update system tray to populate Windows VPN flyout Thread-Index: AdQjeUWXuy+qShlmSZ2lbCyxGt9GkA== Date: Wed, 25 Jul 2018 17:01:39 +0000 Deferred-Delivery: Wed, 25 Jul 2018 17:01:07 +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-25T17:00:07.6904314Z; 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:rsEK4pKjB8vRDty8TBRW+a3bRdQDMNfudhbxiEqc8soHNhRtbtWDAVAMlK3L4o44bddKdKfe0vOm7jLGYgV95pIjbUhYm+uQORB0KmbKwXF7wEjzMkSawN0Gvn6Srg1t00hMJmJa7p8fNStUVXnbsZDsTuXPmWO61+/F2uq0x7APF/MhGz7lF8DPTI98j0ntJlifReyN8ZJrh7ZYyM1SqCbP1l5Sp0qaApWBygOFblmqhpC8YbXwjWzOjcwaroee3j5aXT+qZ9wI/jXO7adLZa7VEnEUZejMrUKfpn+EzU3fFOprmGc6Chqu9Ch++qSAoJKV/zW2LhgCUOcY29H1/5b00G2AbjMMfhVu6MJnZaMa6tCfrHVGAiW2qvylT8o3FiRzbcSzLg97qjjHPtSfZOjNOHYr9rFruNPBM29N1g7wybvTyi8JgfsNMHChqvqEhiuVOkqNsNhd9s0IQRjaRQ==; 5:YfyK0F4noa67nwzJqwzQn5Ev+BU5lHBUU9i8JSVtDjSIYRHsUtBAlanx5/Z3xQoIV/+PO2/F+zlA2zY838uQWZWUjqDyjFlIy1+Puppwsw+ShDRFhDj1axfkr1eBj9f9CW6nghA8OV9g5wRb6jny42HG85UdDbAOn+FMwU0x/6A=; 7:lZlgMBAlug8Do9YiXyZ+tCilzDf2X9wuT66wuykfSsc3Z0uKAf6dIS9SUDj3cfLeO9PeUIixCC5fuRpxNI9mxaL18wR9yiRGKo9xAFoHdSz3gaqC9O6Wcg2uz7XRhxcG1+8xlrw0eR3l6XuHkiKjwvgUH0uEy1STpJEabe3ShSd1U8dbdqZDDukiakNwgcQFzFfH462WwiwFCUoBQ7v2kMG/W0XEYsp1lBcKy3vno8x1oI7IjWS1yIc56dPPEkzH x-ms-office365-filtering-correlation-id: 5804fe48-d560-4fba-9d71-08d5f2504cf4 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); 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)(10710500007)(106356001)(2420400007)(5660300001)(105586002)(2906002)(53936002)(74316002)(8936002)(6666003)(6916009)(53946003)(7110500001)(81156014)(99286004)(15650500001)(6436002)(8676002)(86362001)(2004002)(579004); 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: 12b6WWi/niXfsFnmuxQGtu8dIuDdP9hQZDgf6KnO9ILCJWv3oucP9Hq4rJqLjx40cdCbAg3AoZYwmuLDBdDdVeXbMRCVEFm2DzFXKzCQYGxy+uXZJ35/AIOIgWW9aWY257PpYxZyApOFz8bkvroHnvJFBMwgiZEQSo2HI+CwtNJNPk9rBCLQyW/B3pZd2udv9IKBfonnLNxp9sFlfbJpTiEoCm/UzlPs5Xf0IUZf1C7i24xg9FK2sCvKIENZzs2qOWw5YxgoEDf34yupICARJfeaS0tFMFNXCCjtIX1aNCBoatUVz7/DMUzTbVHuesk//wo1XgDZkbJBKTyK4jOC5B4capWPsUWdpxV9osdrTUg= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5804fe48-d560-4fba-9d71-08d5f2504cf4 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Jul 2018 17:01:42.4813 (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: 1fiNAi-00BUcV-Ct Subject: [Openvpn-devel] [PATCH] [openvpn-gui] Update system tray to populate Windows VPN flyout 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 ed96e2d91a0eb9ecdaab8d7104f397f7d77e5ced Mon Sep 17 00:00:00 2001 From: Kevin Kane Date: Fri, 13 Jul 2018 09:50:00 -0700 Subject: Update system tray to populate Windows VPN flyout Add a DLL to be wired in as a custom dialer, which introduces new build dependencies Add copyright notices as required where Microsoft has contributed code Signed-off-by: Kevin Kane --- .gitignore | 3 + BUILD.rst | 1 + Makefile.am | 10 ++- configure.ac | 4 ++ dialer.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++ tray.c | 117 +++++++++++++++++++++++++++++++++++ tray.h | 2 + 7 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 dialer.c -- 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/.gitignore b/.gitignore index ac37772..e36e0a6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ *.log *.tar.gz *.bak +*.lo +*.la .deps Makefile @@ -30,3 +32,4 @@ depcomp stamp-h1 install-sh missing +libtool diff --git a/BUILD.rst b/BUILD.rst index 9354784..3c70b52 100644 --- a/BUILD.rst +++ b/BUILD.rst @@ -24,6 +24,7 @@ their dependencies. You can install these packages using the standard - mingw64-x86_64-gcc-core - mingw64-x86_64-g++ - mingw64-x86_64-openssl +- libtool Build diff --git a/Makefile.am b/Makefile.am index 8301087..d8435ed 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,7 @@ # # Copyright (C) 2004 Mathias Sundman # 2010 Heiko Hund +# Portions Copyright (C) 2018 Microsoft Corporation # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,6 +23,7 @@ RCCOMPILE = $(WINDRES) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) AUTOMAKE_OPTIONS = foreign 1.9 +ACLOCAL_AMFLAGS = -I m4 MAINTAINERCLEANFILES = \ config.log config.status \ @@ -106,7 +108,13 @@ openvpn_gui_LDADD = \ -lnetapi32 \ -lole32 \ -lshlwapi \ - -lsecur32 + -lsecur32 \ + -lrasapi32 openvpn-gui-res.o: $(openvpn_gui_RESOURCES) $(srcdir)/openvpn-gui-res.h $(RCCOMPILE) -i $< -o $@ + +lib_LTLIBRARIES = libopenvpndialer.la +libopenvpndialer_la_SOURCES = dialer.c +libopenvpndialer_la_LDFLAGS = -no-undefined +libopenvpndialer_la_LIBADD = -lrasapi32 \ No newline at end of file diff --git a/configure.ac b/configure.ac index 9a2ba75..4fe6b81 100644 --- a/configure.ac +++ b/configure.ac @@ -2,6 +2,7 @@ dnl OpenVPN-GUI -- A Windows GUI for OpenVPN. dnl dnl Copyright (C) 2004 Mathias Sundman dnl 2010 Heiko Hund +dnl Portions Copyright (C) 2018 Microsoft Corporation dnl dnl This program is free software; you can redistribute it and/or modify dnl it under the terms of the GNU General Public License as published by @@ -29,10 +30,13 @@ AC_DEFINE([CORE_COPYRIGHT_YEAR_END], ["2018"], [Last copyright year for daemon i AC_CONFIG_AUX_DIR([.]) AM_CONFIG_HEADER([config.h]) AC_CONFIG_SRCDIR([main.h]) +AC_CONFIG_MACRO_DIRS([m4]) AM_INIT_AUTOMAKE AC_CANONICAL_HOST AC_USE_SYSTEM_EXTENSIONS AC_PROG_CC_C99 +LT_INIT([win32-dll]) +AC_LIBTOOL_WIN32_DLL AC_CHECK_TOOL([WINDRES], [windres]) AC_ARG_ENABLE( diff --git a/dialer.c b/dialer.c new file mode 100644 index 0000000..86a0f39 --- /dev/null +++ b/dialer.c @@ -0,0 +1,171 @@ +/* + * OpenVPN-GUI -- A Windows GUI for OpenVPN. + * + * Copyright (C) 2018 Microsoft Corporation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (see the file COPYING included with this + * distribution); if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +__declspec(dllexport) +DWORD WINAPI RasCustomDial( + HINSTANCE hInstDll __attribute__((unused)), + LPRASDIALEXTENSIONS lpRasDialExtensions __attribute__((unused)), + LPWSTR lpszPhonebook __attribute__((unused)), + LPRASDIALPARAMSW lpRasDialParams __attribute__((unused)), + DWORD dwNotifierType __attribute__((unused)), + LPVOID lpvNotifier __attribute__((unused)), + LPHRASCONN lphRasConn __attribute__((unused)), + DWORD dwFlags __attribute__((unused))) +{ + return ERROR_CALL_NOT_IMPLEMENTED; +} + +/* Copied from OpenVPN-GUI main.c */ +static const TCHAR OpenVPNGuiClassName[] = _T("OpenVPN-GUI"); + +/* Copied from OpenVPN-GUI tray.h */ +#define IDM_CONNECTMENU 300 + +static const TCHAR WindowCaption[] = _T("Walrus VPN"); + +__declspec(dllexport) +BOOL WINAPI RasCustomDialDlg( + HINSTANCE hInstDll __attribute__((unused)), + DWORD dwFlags __attribute__((unused)), + LPWSTR lpszwPhonebook, + LPWSTR lpszwEntry, + LPWSTR lpszwPhoneNumber __attribute__((unused)), + LPRASDIALDLG lpInfo, + PVOID pVoid __attribute__((unused))) +{ + HWND window = FindWindow(OpenVPNGuiClassName, NULL); + if (NULL == window) + { + MessageBox(NULL, _T("OpenVPN-GUI is not running. Please launch the GUI."), WindowCaption, MB_OK); + lpInfo->dwError = ERROR_UNKNOWN; + return FALSE; + } + else + { + DWORD result; + DWORD entrySize = 0; + LPRASENTRYW entry = NULL; + + result = RasGetEntryPropertiesW(lpszwPhonebook, lpszwEntry, NULL, &entrySize, NULL, NULL); + if (ERROR_SUCCESS != result && ERROR_BUFFER_TOO_SMALL != result) + { + MessageBox(NULL, _T("Could not get size of VPN entry"), WindowCaption, MB_OK); + lpInfo->dwError = result; + return FALSE; + } + + entry = (LPRASENTRYW)malloc(entrySize); + if (NULL == entry) + { + lpInfo->dwError = ERROR_OUTOFMEMORY; + return FALSE; + } + + memset(entry, 0, entrySize); + entry->dwSize = sizeof(RASENTRYW); + + result = RasGetEntryPropertiesW(lpszwPhonebook, lpszwEntry, entry, &entrySize, NULL, NULL); + if (ERROR_SUCCESS != result) + { + MessageBox(NULL, _T("Could not get VPN entry"), WindowCaption, MB_OK); + lpInfo->dwError = result; + free(entry); + return FALSE; + } + + /* Convert the number in the local phone number field to get the offset. */ + int offset = _wtoi(entry->szLocalPhoneNumber); + + /* Sanity check: There should not be more than 10 entries, and the value should never be negative.*/ + if (0 > offset || 10 < offset) + { + MessageBox(NULL, _T("Offset is invalid number"), WindowCaption, MB_OK); + lpInfo->dwError = ERROR_UNKNOWN; + free(entry); + return FALSE; + } + + if (0 == offset) + { + /* 0 is also used for an error condition. If that's the case, check that the string is actually + * a zero. + */ + if (entry->szLocalPhoneNumber[0] != L'0' && entry->szLocalPhoneNumber[1] != L'\0') + { + MessageBox(NULL, _T("Offset not recognized as a number"), WindowCaption, MB_OK); + lpInfo->dwError = ERROR_UNKNOWN; + free(entry); + return FALSE; + } + } + + /* No longer need entry at this point. */ + free(entry); + + if (FALSE == PostMessage(window, WM_COMMAND, IDM_CONNECTMENU + offset, 0)) + { + MessageBox(NULL, _T("Could not communicate with OpenVPN-GUI"), WindowCaption, MB_OK); + lpInfo->dwError = GetLastError(); + return FALSE; + } + else + { + return TRUE; + } + } +} + +__declspec(dllexport) +DWORD WINAPI RasCustomHangUp( + HRASCONN hRasConn __attribute__((unused))) +{ + return ERROR_CALL_NOT_IMPLEMENTED; +} + +__declspec(dllexport) +BOOL WINAPI RasCustomEntryDlg(HINSTANCE hInstDll __attribute__((unused)), + LPWSTR lpszwPhonebook __attribute__((unused)), + LPWSTR lpszwEntry __attribute__((unused)), + LPRASENTRYDLG lpInfo, + DWORD dwFlags __attribute__((unused))) +{ + lpInfo->dwError = ERROR_CALL_NOT_IMPLEMENTED; + return FALSE; +} + +__declspec(dllexport) +DWORD CALLBACK RasCustomDeleteEntryNotify( + LPCTSTR lpszPhonebook __attribute__((unused)), + LPCTSTR lpszEntry __attribute__((unused)), + DWORD dwFlags __attribute__((unused))) +{ + return ERROR_SUCCESS; +} diff --git a/tray.c b/tray.c index 1e1dc2e..9ce27a0 100644 --- a/tray.c +++ b/tray.c @@ -3,6 +3,7 @@ * * Copyright (C) 2004 Mathias Sundman * 2010 Heiko Hund + * Portions Copyright (C) 2018 Microsoft Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +29,8 @@ #include #include #include +#include +#include #include "tray.h" #include "service.h" @@ -47,6 +50,116 @@ HMENU hMenuService; NOTIFYICONDATA ni; extern options_t o; +static const TCHAR VpnEntryPrefix[] = _T("OpenVPN "); +static const TCHAR WindowCaption[] = _T("OpenVPN-GUI"); + +/* Delete OpenVPN entries from Windows networking/VPN flyout */ +void +ClearNetworkFlyout() +{ + DWORD result = ERROR_SUCCESS; + LPRASENTRYNAME entryName = NULL; + DWORD entryNameSize = 0; + DWORD entryCount = 0; + + /* Determine memory required */ + result = RasEnumEntries(NULL, NULL, NULL, &entryNameSize, &entryCount); + if (ERROR_BUFFER_TOO_SMALL != result) + { + /* Anything else is unexpected. */ + MessageBox(NULL, _T("ClearNetworkFlyout: Could not get memory needed for RAS entries"), WindowCaption, MB_OK); + return; + } + + entryName = (LPRASENTRYNAME)malloc(entryNameSize); + if (NULL == entryName) + { + /* No memory! */ + MessageBox(NULL, _T("ClearNetworkFlyout: No memory allocating entry name"), WindowCaption, MB_OK); + return; + } + + entryName[0].dwSize = sizeof(RASENTRYNAME); + + result = RasEnumEntries(NULL, NULL, entryName, &entryNameSize, &entryCount); + if (ERROR_SUCCESS != result) + { + MessageBox(NULL, _T("ClearNetworkFlyout: Could not enumerate RAS entries"), WindowCaption, MB_OK); + free(entryName); + return; + } + + for (DWORD i = 0; i < entryCount; i++) + { + if ((entryName[i].dwFlags == REN_User) && + (0 == _tcsncmp(VpnEntryPrefix, entryName[i].szEntryName, _countof(VpnEntryPrefix) - 1))) + { + /* TODO: Retrieve the entry and verify that it references our custom dialer DLL? RasEnumEntries doesn't + * give us this information but we could retrieve the entry and check. This would keep us from purging any + * entries which for some inexplicable reason started with the VpnEntryPrefix string. + */ + result = RasDeleteEntry(NULL, entryName[i].szEntryName); + if (ERROR_SUCCESS != result) + { + MessageBox(NULL, _T("ClearNetworkFlyout: Failed to delete entry"), WindowCaption, MB_OK); + /* Continue processing; don't return. */ + } + } + } + + free(entryName); + + return; +} + +static const TCHAR DialerFileName[] = _T("libopenvpndialer-0.dll"); +static const TCHAR DeviceName[] = _T("TAP-Windows Adapter V9"); + +/* Create VPN flyout entry for a new connection */ +static void +CreateNetworkFlyoutEntry(const connection_t *c, int number) +{ + DWORD result = ERROR_SUCCESS; + RASENTRY entry; + TCHAR entryName[RAS_MaxEntryName + 1]; + + memset(&entry, 0, sizeof(entry)); + entry.dwSize = sizeof(entry); + _tcsncpy(entry.szDeviceType, RASDT_Vpn, _countof(RASDT_Vpn)); + _tcsncpy(entry.szDeviceName, DeviceName, _countof(DeviceName)); + + entry.dwfOptions = RASEO_Custom; + /* Take the exe_path, strip off everything after the last backslash, and append DialerFileName */ + TCHAR* lastBackslash = _tcsrchr(o.exe_path, _T('\\')); + if (NULL == lastBackslash) + { + MessageBox(NULL, _T("CreateNetworkFlyoutEntry: No last backslash found"), WindowCaption, MB_OK); + return; + } + _tcsncpy(entry.szCustomDialDll, o.exe_path, (lastBackslash - o.exe_path + 1)); + /* Check for possible overrun */ + if (_tcslen(entry.szCustomDialDll) + _countof(DialerFileName) >= _countof(entry.szCustomDialDll)) + { + MessageBox(NULL, _T("CreateNetworkFlyoutEntry: Not enough space for custom dialer DLL filename"), WindowCaption, MB_OK); + return; + } + _tcsncat(entry.szCustomDialDll, DialerFileName, _countof(DialerFileName)); + + /* Use the local phone number space to store the entry number for the custom dialer to use. */ + _sntprintf_0(entry.szLocalPhoneNumber, _T("%d"), number); + entry.dwType = RASET_Vpn; + entry.dwEncryptionType = ET_Optional; + + _sntprintf_0(entryName, _T("%s%s"), VpnEntryPrefix, c->config_name); + result = RasSetEntryProperties(NULL, entryName, &entry, sizeof(entry), NULL, 0); + if (ERROR_SUCCESS != result) + { + TCHAR message[512]; + _sntprintf_0(message, _T("CreateNetworkFlyoutEntry: Could not RasSetEntryProperties: %lu"), result); + MessageBox(NULL, message, WindowCaption, MB_OK); + return; + } +} /* Create popup menus */ void @@ -92,6 +205,7 @@ CreatePopupMenus() AppendMenu(hMenu, MF_STRING ,IDM_CLOSE, LoadLocalizedString(IDS_MENU_CLOSE)); SetMenuStatus(&o.conn[0], o.conn[0].state); + CreateNetworkFlyoutEntry(&o.conn[0], 0); } else { /* Create Main menu with all connections */ @@ -135,6 +249,7 @@ CreatePopupMenus() #endif SetMenuStatus(&o.conn[i], o.conn[i].state); + CreateNetworkFlyoutEntry(&o.conn[i], i); } } @@ -152,6 +267,7 @@ DestroyPopupMenus() DestroyMenu(hMenuService); DestroyMenu(hMenu); + ClearNetworkFlyout(); } @@ -218,6 +334,7 @@ void OnDestroyTray() { DestroyMenu(hMenu); + ClearNetworkFlyout(); Shell_NotifyIcon(NIM_DELETE, &ni); } diff --git a/tray.h b/tray.h index 1ce5e07..f5a9ff4 100644 --- a/tray.h +++ b/tray.h @@ -3,6 +3,7 @@ * * Copyright (C) 2004 Mathias Sundman * 2010 Heiko Hund + * Portions Copyright (C) 2018 Microsoft Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -51,5 +52,6 @@ void SetMenuStatus(connection_t *, conn_state_t); void SetServiceMenuStatus(); void ShowTrayBalloon(TCHAR *, TCHAR *); void CheckAndSetTrayIcon(); +void ClearNetworkFlyout(); #endif