From patchwork Sun Jul 19 07:34:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arne Schwabe X-Patchwork-Id: 1307 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director9.mail.ord1d.rsapps.net ([172.28.255.1]) by backend30.mail.ord1d.rsapps.net with LMTP id IPlXDG6EFF9TfgAAIUCqbw for ; Sun, 19 Jul 2020 13:35:42 -0400 Received: from proxy7.mail.ord1c.rsapps.net ([172.28.255.1]) by director9.mail.ord1d.rsapps.net with LMTP id OKQmDG6EFF9ZFwAAalYnBA ; Sun, 19 Jul 2020 13:35:42 -0400 Received: from smtp39.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy7.mail.ord1c.rsapps.net with LMTP id IEi5C26EFF+wSQAAknS3pQ ; Sun, 19 Jul 2020 13:35:42 -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: smtp39.gate.ord1c.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; dmarc=none (p=nil; dis=none) header.from=rfc2549.org X-Suspicious-Flag: YES X-Classification-ID: 442f48fc-c9e6-11ea-b51a-5452006c005a-1-1 Received: from [216.105.38.7] ([216.105.38.7:48732] helo=lists.sourceforge.net) by smtp39.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 20/E7-10705-D64841F5; Sun, 19 Jul 2020 13:35:41 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jxDDE-0004NY-Qb; Sun, 19 Jul 2020 17:34:56 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jxDDC-0004N8-5M for openvpn-devel@lists.sourceforge.net; Sun, 19 Jul 2020 17:34:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: 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=dIAfSutvT04g92ZD/hkpOkWR7UznPY+N4X3P3ha7BR0=; b=Fl15nTjrjsVloAlvkDxB2HhGB9 WtwojYW/ah3LnQ+pBPzTY/33fHiIsucL1ubK3kC9R4wchFJNQOA6qd7jxCntgXR9SeJI9jYWZO2Uo MAhprNHva/N7btbJgfCYxumwcDZQ2nqiAFKc6K31kZ907UHhNbeJtUa65BFWaNNWwANE=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc: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=dIAfSutvT04g92ZD/hkpOkWR7UznPY+N4X3P3ha7BR0=; b=QvYrzEyZm1VPCj0HDafv4/W6kh RZR9GrmKaFZnvyj0HY3qhZh2/PSdc8Qd25Rlo6C97zbpr2Un2IYgauTl7AvPX7/RiD9e6lYA/36Nn /ZKNea0hcSIW2IC4whFDZL3HgbNuzoDC003dCFqiCuB2NmpuQGtvHuAyUGQZLvyQFWJw=; Received: from [192.26.174.232] (helo=mail.blinkt.de) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jxDDA-00G7uy-PV for openvpn-devel@lists.sourceforge.net; Sun, 19 Jul 2020 17:34:54 +0000 Received: from kamera.blinkt.de ([2001:638:502:390:20c:29ff:fec8:535c]) by mail.blinkt.de with smtp (Exim 4.94 (FreeBSD)) (envelope-from ) id 1jxDCu-000BtA-H9 for openvpn-devel@lists.sourceforge.net; Sun, 19 Jul 2020 19:34:36 +0200 Received: (nullmailer pid 16476 invoked by uid 10006); Sun, 19 Jul 2020 17:34:36 -0000 From: Arne Schwabe To: openvpn-devel@lists.sourceforge.net Date: Sun, 19 Jul 2020 19:34:32 +0200 Message-Id: <20200719173436.16431-1-arne@rfc2549.org> X-Mailer: git-send-email 2.17.1 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: rfc2549.org] 0.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 1.0 RDNS_NONE Delivered to internal network by a host with no rDNS -0.5 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1jxDDA-00G7uy-PV Subject: [Openvpn-devel] [PATCH v8 1/5] Remove CAS_PARTIAL state 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 This state is used to handle a corner case when multiple connect handlers are active and one of them fails. Unfortunately, this state complicates the state machine a bit without a good benefit. Current behaviour: First/all connect handler(s) fail: - client disconnect handler is not called at all At least one connect handler succeeds but a subsequent handler fails: - client disconect is called when we actually disconnect the client (a few seconds later, max tls timeout) All connect handlers suceed: - client disconect is called when we actually disconnect the client This patches changes the behaviour in the second to immediately call disconnect_handler in this case. This simplifies the logic that already caused a bug and the behaviour change is very little and affects only a pretty exotic corner case. Signed-off-by: Arne Schwabe Acked-by: Gert Doering --- Changes.rst | 7 +++++ src/openvpn/multi.c | 59 ++++++++++++++++++++----------------------- src/openvpn/openvpn.h | 5 ---- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/Changes.rst b/Changes.rst index e5228696..de831889 100644 --- a/Changes.rst +++ b/Changes.rst @@ -38,6 +38,13 @@ https://community.openvpn.net/openvpn/wiki/DeprecatedOptions This option was made into a NOOP option with OpenVPN 2.4. This has now been completely removed. +User-visible Changes +-------------------- +- If multiple connect handlers are used (client-connect, ccd, connect + plugin) and one of the handler succeeds but a subsequent fails, the + client-disconnect-script is now called immediately. Previously it + was called, when the VPN session was terminated. + Overview of changes in 2.4 ========================== diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 0095c871..aab15cf7 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -574,35 +574,30 @@ multi_client_disconnect_setenv(struct multi_instance *mi) static void multi_client_disconnect_script(struct multi_instance *mi) { - if (mi->context.c2.context_auth == CAS_SUCCEEDED - || mi->context.c2.context_auth == CAS_PARTIAL) - { - multi_client_disconnect_setenv(mi); + multi_client_disconnect_setenv(mi); - if (plugin_defined(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_DISCONNECT)) + if (plugin_defined(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_DISCONNECT)) + { + if (plugin_call(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_DISCONNECT, NULL, NULL, mi->context.c2.es) != OPENVPN_PLUGIN_FUNC_SUCCESS) { - if (plugin_call(mi->context.plugins, OPENVPN_PLUGIN_CLIENT_DISCONNECT, NULL, NULL, mi->context.c2.es) != OPENVPN_PLUGIN_FUNC_SUCCESS) - { - msg(M_WARN, "WARNING: client-disconnect plugin call failed"); - } + msg(M_WARN, "WARNING: client-disconnect plugin call failed"); } + } - if (mi->context.options.client_disconnect_script) - { - struct argv argv = argv_new(); - setenv_str(mi->context.c2.es, "script_type", "client-disconnect"); - argv_parse_cmd(&argv, mi->context.options.client_disconnect_script); - openvpn_run_script(&argv, mi->context.c2.es, 0, "--client-disconnect"); - argv_free(&argv); - } + if (mi->context.options.client_disconnect_script) + { + struct argv argv = argv_new(); + setenv_str(mi->context.c2.es, "script_type", "client-disconnect"); + argv_parse_cmd(&argv, mi->context.options.client_disconnect_script); + openvpn_run_script(&argv, mi->context.c2.es, 0, "--client-disconnect"); + argv_free(&argv); + } #ifdef MANAGEMENT_DEF_AUTH - if (management) - { - management_notify_client_close(management, &mi->context.c2.mda_context, mi->context.c2.es); - } -#endif - + if (management) + { + management_notify_client_close(management, &mi->context.c2.mda_context, mi->context.c2.es); } +#endif } void @@ -683,8 +678,10 @@ multi_close_instance(struct multi_context *m, #ifdef MANAGEMENT_DEF_AUTH set_cc_config(mi, NULL); #endif - - multi_client_disconnect_script(mi); + if (mi->context.c2.context_auth == CAS_SUCCEEDED) + { + multi_client_disconnect_script(mi); + } close_context(&mi->context, SIGTERM, CC_GC_FREE); @@ -2375,16 +2372,14 @@ multi_connection_established(struct multi_context *m, struct multi_instance *mi) } else { - /* set context-level authentication flag to failed but remember - * if had a handler succeed (for cleanup) */ + /* run the disconnect script if we had a connect script that + * did not fail */ if (mi->context.c2.context_auth == CAS_PENDING_DEFERRED_PARTIAL) { - mi->context.c2.context_auth = CAS_PARTIAL; - } - else - { - mi->context.c2.context_auth = CAS_FAILED; + multi_client_disconnect_script(mi); } + + mi->context.c2.context_auth = CAS_FAILED; } /* increment number of current authenticated clients */ diff --git a/src/openvpn/openvpn.h b/src/openvpn/openvpn.h index ccc7f118..470d67dc 100644 --- a/src/openvpn/openvpn.h +++ b/src/openvpn/openvpn.h @@ -220,11 +220,6 @@ enum client_connect_status { CAS_PENDING_DEFERRED, CAS_PENDING_DEFERRED_PARTIAL, /**< at least handler succeeded, no result yet*/ CAS_FAILED, - CAS_PARTIAL, /**< Variant of CAS_FAILED: at least one - * client-connect script/plugin succeeded - * while a later one in the chain failed - * (we still need cleanup compared to FAILED) - */ }; static inline bool