From patchwork Sun Feb 9 17:33:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Selva Nair X-Patchwork-Id: 986 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id 4LeRJmDdQF5wXQAAIUCqbw for ; Sun, 09 Feb 2020 23:34:40 -0500 Received: from proxy16.mail.ord1d.rsapps.net ([172.30.191.6]) by director10.mail.ord1d.rsapps.net with LMTP id II41JmDdQF5WcgAApN4f7A ; Sun, 09 Feb 2020 23:34:40 -0500 Received: from smtp39.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy16.mail.ord1d.rsapps.net with LMTP id 6OucJWDdQF5NQQAAetu3IA ; Sun, 09 Feb 2020 23:34:40 -0500 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: smtp39.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: a6774b28-4bbe-11ea-9a3c-525400a97bbc-1-1 Received: from [216.105.38.7] ([216.105.38.7:37168] helo=lists.sourceforge.net) by smtp39.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id DB/7C-16874-06DD04E5; Sun, 09 Feb 2020 23:34:40 -0500 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 1j10lW-0002xQ-E1; Mon, 10 Feb 2020 04:33:46 +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 1j10lV-0002xC-6j for openvpn-devel@lists.sourceforge.net; Mon, 10 Feb 2020 04:33:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:In-Reply-To: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:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ik7SP25vKms6loK7BzLL1yE4igt7Qkj9t/vid781qpE=; b=f/T9nmcPc/2glexNqjMcClQob8 /vRPn54uab+HSkbi2R/kCPyWIq2dyEEINprhtG3VWOJTuzhOKoOD10m9icZ/13V79enD2pdLwMUiA hdNDc8UaKt+7bCL51ycTzyESDIqC3MPkfq6l2InDt6+ubAadm5nax+zfehSdEZmaWLHs=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:In-Reply-To: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:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Ik7SP25vKms6loK7BzLL1yE4igt7Qkj9t/vid781qpE=; b=VZP6SYf0RbD5fXRNG7sLY+PFIq 4C4LEAMFMolLDsasmGOfAmWKYLZEKF/u0DG9eLoQhqegtz5Jclp9kjV6++Cj/zex8zA6GPIpmIOr8 VjMdU5EK1XwWM3FM5bQVxkrM6jtLVXff4zwOD9B8opf5cEuELj0r6B9NMYbu4gmXGQNk=; Received: from mail-qv1-f41.google.com ([209.85.219.41]) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.92.2) id 1j10lT-00GlBo-0l for openvpn-devel@lists.sourceforge.net; Mon, 10 Feb 2020 04:33:45 +0000 Received: by mail-qv1-f41.google.com with SMTP id u10so2613068qvi.2 for ; Sun, 09 Feb 2020 20:33:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ik7SP25vKms6loK7BzLL1yE4igt7Qkj9t/vid781qpE=; b=Rg5DuA0qL3IXCqyY9tkntEoM0WIW/eG4nF8cqPE3Tm7l0PaCRVijexv1BIl2BbFCPm /3lC4o1VdYqfJ6NCLT0VnnhvmZ0wGF3X7RZUpUUHIL84k2Gh/X7gRNOU8IDmr5/LWV2w Bc3WBaAghUU9x270tMS1vye2J0P97W+wk+RG0sUMnaQpUa0SBtHc+T69ncsIcKsyzUe2 2MIvZJNglHYZObh3E+rfWyqjudynCnRml1u4RbHx/iPAxXbh4YyLwvTeeEUw8vN2YL9V +pMRlcwW/bzS+C6kPCXzRkfDmWWIuuOdLwOQLbCoWHSpe0ijaOw6MFj7s0cU68YcpYJJ 1xDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ik7SP25vKms6loK7BzLL1yE4igt7Qkj9t/vid781qpE=; b=H7Mk13mqryYH6pglcCADvOlHi/u2qj4qLcFbFIZcrP2o/UXILibOldwLeMxMgzh/rU fkmiul3NEdMbjxE70mI1YpLM/tRiByWx7XlxzxpHucDcautUY90hn9XC3dRH2Drd3mHI UxqrMmwiLFvbXNDRSjI25+aQ6pK8GPNWdvYVMT8hvPWkODPIG7MfPcM+E1Sph4/0zlyq gX06uo8fUstplkXSAAxDLRWmffNpLyfNpqVn1Wh8d537FV6RRf8Ofo9v+9uIcXDfDQRY NaITGjQy/vi3TFHOvYHdb2F8DXbLfKKxdSTTovrWsyF00n28EYtCaFXuLMTPPiu8XexJ VVEg== X-Gm-Message-State: APjAAAU5uw4iJosKbtMtBri9Xypd7j1J/TidGa0a2Af8j0aZAWjT3nbB WZ+gwv5D6A/fCRv/tPNHKISp6i4M X-Google-Smtp-Source: APXvYqzZqQKVHU5cTcDKxP2jdPIOisOSAazIT1jfdNTv50f7xx4NhKDgS/OZENt5qAnZ5Sn12sHiDg== X-Received: by 2002:ad4:49ca:: with SMTP id j10mr8080884qvy.155.1581309216715; Sun, 09 Feb 2020 20:33:36 -0800 (PST) Received: from saturn.home.sansel.ca (CPE40167ea0e1c2-CM788df74daaa0.cpe.net.cable.rogers.com. [99.228.216.21]) by smtp.gmail.com with ESMTPSA id u25sm2462927qkj.43.2020.02.09.20.33.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 09 Feb 2020 20:33:35 -0800 (PST) From: selva.nair@gmail.com To: openvpn-devel@lists.sourceforge.net Date: Sun, 9 Feb 2020 23:33:20 -0500 Message-Id: <1581309200-27870-1-git-send-email-selva.nair@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1580488320-10224-1-git-send-email-selva.nair@gmail.com> References: <1580488320-10224-1-git-send-email-selva.nair@gmail.com> X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (selva.nair[at]gmail.com) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.219.41 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.219.41 listed in wl.mailspike.net] -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: 1j10lT-00GlBo-0l Subject: [Openvpn-devel] [PATCH v3] Swap the order of checks for validating interactive service user 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: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Selva Nair Check the config file location and command line options first and membership in OpenVPNAdministrators group after that as the latter could be a slow process for active directory users. When connection to domain controllers is poor or unavailable, checking the group membership is slow and causes timeouts in the GUI (Trac 1051). However, in cases where the config is in the global directory, no group membership check should be required. The re-ordering here avoids the redundant check in such cases. In addition to this, its also proposed to improve the timeout handling in the GUI, but this change is still useful as it should completely eliminate the timeout issue for many users. v3: Do not send error message to the client pipe from ValidateOptions(). Instead save the error and send it on only if user authorization also fails. The error buffer size is increased to 512 wide chars as these messages could get long in some cases and may get truncated otherwise. Also see: https://github.com/OpenVPN/openvpn-gui/issues/332 Signed-off-by: Selva Nair Acked-by: Lev Stipakov --- v2: Add missing closing parenthesis and improve the comment above the edited chunk. src/openvpnserv/interactive.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/openvpnserv/interactive.c b/src/openvpnserv/interactive.c index 6e72a14..710f9c7 100644 --- a/src/openvpnserv/interactive.c +++ b/src/openvpnserv/interactive.c @@ -389,14 +389,13 @@ ReturnOpenvpnOutput(HANDLE pipe, HANDLE ovpn_output, DWORD count, LPHANDLE event /* * Validate options against a white list. Also check the config_file is * inside the config_dir. The white list is defined in validate.c - * Returns true on success + * Returns true on success, false on error with reason set in errmsg. */ static BOOL -ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options) +ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options, WCHAR *errmsg, DWORD capacity) { WCHAR **argv; int argc; - WCHAR buf[256]; BOOL ret = FALSE; int i; const WCHAR *msg1 = L"You have specified a config file location (%s relative to %s)" @@ -411,8 +410,9 @@ ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options) if (!argv) { - ReturnLastError(pipe, L"CommandLineToArgvW"); - ReturnError(pipe, ERROR_STARTUP_DATA, L"Cannot validate options", 1, &exit_event); + openvpn_swprintf(errmsg, capacity, + L"Cannot validate options: CommandLineToArgvW failed with error = 0x%08x", + GetLastError()); goto out; } @@ -432,9 +432,8 @@ ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options) if (!CheckOption(workdir, 2, argv_tmp, &settings)) { - openvpn_swprintf(buf, _countof(buf), msg1, argv[0], workdir, + openvpn_swprintf(errmsg, capacity, msg1, argv[0], workdir, settings.ovpn_admin_group); - ReturnError(pipe, ERROR_STARTUP_DATA, buf, 1, &exit_event); } goto out; } @@ -450,15 +449,13 @@ ValidateOptions(HANDLE pipe, const WCHAR *workdir, const WCHAR *options) { if (wcscmp(L"--config", argv[i]) == 0 && argc-i > 1) { - openvpn_swprintf(buf, _countof(buf), msg1, argv[i+1], workdir, + openvpn_swprintf(errmsg, capacity, msg1, argv[i+1], workdir, settings.ovpn_admin_group); - ReturnError(pipe, ERROR_STARTUP_DATA, buf, 1, &exit_event); } else { - openvpn_swprintf(buf, _countof(buf), msg2, argv[i], + openvpn_swprintf(errmsg, capacity, msg2, argv[i], settings.ovpn_admin_group); - ReturnError(pipe, ERROR_STARTUP_DATA, buf, 1, &exit_event); } goto out; } @@ -1487,6 +1484,7 @@ RunOpenvpn(LPVOID p) size_t cmdline_size; undo_lists_t undo_lists; ring_buffer_handles_t ring_buffer_handles; + WCHAR errmsg[512] = L""; SECURITY_ATTRIBUTES inheritable = { .nLength = sizeof(inheritable), @@ -1580,10 +1578,17 @@ RunOpenvpn(LPVOID p) goto out; } - /* Check user is authorized or options are white-listed */ - if (!IsAuthorizedUser(ovpn_user->User.Sid, imp_token, settings.ovpn_admin_group) - && !ValidateOptions(pipe, sud.directory, sud.options)) + /* + * Only authorized users are allowed to use any command line options or + * have the config file in locations other than the global config directory. + * + * Check options are white-listed and config is in the global directory + * OR user is authorized to run any config. + */ + if (!ValidateOptions(pipe, sud.directory, sud.options, errmsg, _countof(errmsg)) + && !IsAuthorizedUser(ovpn_user->User.Sid, imp_token, settings.ovpn_admin_group)) { + ReturnError(pipe, ERROR_STARTUP_DATA, errmsg, 1, &exit_event); goto out; }