From patchwork Wed Sep 6 17:17:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Fleischman X-Patchwork-Id: 3336 X-Patchwork-Delegate: davids@openvpn.net Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7300:390:b0:d7:3b0f:3938 with SMTP id 16csp2756599dyq; Wed, 6 Sep 2023 11:04:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErBpIeEqpT1nTXTmYxYdS7GQZyILAzqh4nRmWUeDzhdCiUQkrKB0bNuEIwyZiyvM3FT1U5 X-Received: by 2002:a05:6a20:a124:b0:137:3eba:b81f with SMTP id q36-20020a056a20a12400b001373ebab81fmr20680469pzk.3.1694023489991; Wed, 06 Sep 2023 11:04:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694023489; cv=none; d=google.com; s=arc-20160816; b=aQuCAzMBL9rNsffSaFFOZ4CKynxT2AqD5zYa3vO5u1k3DzZtjNdSrJSErVESNgFD7a p6Spw4N0EGpmah3Eo91y9rMwrbLidp1jdMpcGR8KSv2K4jlqR7Qs5+EcrVgZjh/5a5HC 3t4RmvaaA7+2dNfOY2Px3iokAJSjUlo8NiVFfPWtwiMUHChaOexdCnipmmyfMi/sSUH6 OfHuirFLEHrpQVonvVp38qKIk4Dn5qm1Z19kjpX6UJB/BDB7tY2VEeSx/hRX0ri3ubWm mKs09/VgFXYS/bR9/oJnuicrGoBEmvW8EVLgZARO7X2xX9r+QKA02SC//fbWFbHB8Jwk zgeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=ZzRgnyvVFgFww2/smqIp/DoUW8+LG5twGl/rBjr8DH4=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=hXjTmUeX96QDV4hdjcUGWPvICvBgpGCS85r+alL6zx43VN/uvSFo88rX1A0XXyH0Jm 6quc6utbDN8RRwyVyIHRHm8DJdW0AeRtgIvq9JLZmshS/zTnOlxi4zx2eFxtsSPEzuSW TYM90eDXCbUIZTJl3Ewp9+/TdyOPykCE/bQKeBDC8eht7MRPwohD3vM67beYxj1WZNl8 ZJTFGRcxWfcMsvNbsqaJZ7H16BMIaXe3bfAaz8LviOPKvkm4r4pv1Ljm53yygmyuvA4u gzYRV/mQzmfw4T6KFAH6Nu8Ks2tq10mfctZHO2mliercbMFZyMBhCj7L4uxKUivUpSsS be/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=AJSo7Z6o; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=LnJWA8Ka; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=bnsetBVu; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id w184-20020a6382c1000000b00565e98183d6si932842pgd.626.2023.09.06.11.04.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Sep 2023 11:04:49 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=AJSo7Z6o; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=LnJWA8Ka; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=bnsetBVu; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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.95) (envelope-from ) id 1qdwt2-0006Vo-As; Wed, 06 Sep 2023 18:04:20 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qdwCn-0005kN-Gd for openvpn-devel@lists.sourceforge.net; Wed, 06 Sep 2023 17:20:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: 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=j/LlAlMCUPk0A85ACH4i3ChxHa7cBIYOBws6C1LSpsI=; b=AJSo7Z6o7lC9nYh8k2YVZheWav 21fyc4qOapTWjmKPXGNb/cz+F5lJeq5rKyXv9dFtuuiOF1qNcnaYR2GyInul5oZUnGSbsDOZK3EZi 9nlC09hZXa54p9SLy3P3K9lr13ovNwyxgPoY4sTO0QbYvMasZthT3zPNMIHxfIoGFX9M=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=j/LlAlMCUPk0A85ACH4i3ChxHa7cBIYOBws6C1LSpsI=; b=LnJWA8KaZQHFpSgw74ptxFx0Vq cyYe/ZjHIVp3R7vbLUYe1e7r0oFRqoJx/3g6t7ls/9ip6ga6we6dF+tUjJ1xgPwYwZ5J+xUuGZQXP 5oF5YNsTsE8cSibemCuZDdBZCE8VetxNs7C9QL6dP9O/LwMZPJF7ffpdiC9S6jlML+Hc=; Received: from mail-oa1-f54.google.com ([209.85.160.54]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1qdwCk-0000a5-Gp for openvpn-devel@lists.sourceforge.net; Wed, 06 Sep 2023 17:20:41 +0000 Received: by mail-oa1-f54.google.com with SMTP id 586e51a60fabf-1d4db7959f6so70606fac.0 for ; Wed, 06 Sep 2023 10:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694020832; x=1694625632; darn=lists.sourceforge.net; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=j/LlAlMCUPk0A85ACH4i3ChxHa7cBIYOBws6C1LSpsI=; b=bnsetBVuQlkEJPgBVQDVDRoXXyMgYM3LbtH5QOB7VuRMTBsBbj9e504cxxU5Ezw/P+ KoSM5NxhQF01Rah8RSTGq0G+Waa4DAhhyBEAatT8GmigTUMA3FtZl01E26ygJo5DAhUu plIjdJw3yEznBSSOpQgAZw243/hR2v1Q3J9tebpn5vniTgvjGgFy+i0HQjkucxqHCMNK KCaer/O+12cmT2+dE9NQza0FDxFrINQCVPWhlWMYaokhMx7bdo+UHGL6yr5+cWhJX2la VUaO4w9UMqRJbCebUsD7vgGX1+bUfqewT196DD+r3Ffk9RFOWwkUcpjFn0mJL2EiRDCX JLOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694020832; x=1694625632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j/LlAlMCUPk0A85ACH4i3ChxHa7cBIYOBws6C1LSpsI=; b=gA6nuoQMWViRul3HRee5B/mi6lvVtSbk8nSJDYO5YxWNgYibN8CfRfB1nD2qjeRdEu oB6wnSFmn0ruclpB/roEn41exZ/98FAWqyMn4qrdLl7/YhvSaRLP0RJW0YlPJha9BhqZ PKvC08wSziCtdZpqQBcq9fXYxFPBkxsv22N23G6/OLxTyJYVWroZzu6CiOrzfCBT27HN +MWH9y5hSLydvWo744p8GM03iAUu9C6zNUywjtxrHkSPwdxjfJZt0FiHloGSCOhfXghf UUIPYGuWEOxo/2UjqQ4qVr5AogTs2P7Ug3J9e5zWa8RwTOW51t7/l+R6KkyZuQmYLsX4 2b2Q== X-Gm-Message-State: AOJu0Yx3CQ0H9I65NFwuwqrQvz/fJPUdfkaUFO+fdBR60kua4SsHKTio V2a1vrQy4rq2df08zfD98icufHmy34rmbg== X-Received: by 2002:a05:6870:4c0d:b0:1d5:3baa:58b3 with SMTP id pk13-20020a0568704c0d00b001d53baa58b3mr1159140oab.49.1694020832340; Wed, 06 Sep 2023 10:20:32 -0700 (PDT) Received: from pattern.lan ([2600:1700:a41a:381f:78f3:90d:a278:c78d]) by smtp.gmail.com with ESMTPSA id e5-20020a63ee05000000b0055386b1415dsm10393950pgi.51.2023.09.06.10.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Sep 2023 10:20:31 -0700 (PDT) From: Jeremy Fleischman To: openvpn-devel@lists.sourceforge.net Date: Wed, 6 Sep 2023 10:17:58 -0700 Message-ID: <20230906171758.344862-1-jeremyfleischman@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230709231929.195048-1-jeremyfleischman@gmail.com> References: <20230709231929.195048-1-jeremyfleischman@gmail.com> MIME-Version: 1.0 X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.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: `StatusChangeCallback` requires that LogForward be enabled, which previously only happened in `LogCallback`. Now both of them do it, which requires a bit of bookkeeping. This fixes https://github.com/ [...] Content analysis details: (-0.2 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [jeremyfleischman[at]gmail.com] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.160.54 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.160.54 listed in list.dnswl.org] -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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 RCVD_IN_MSPIKE_WL Mailspike good senders X-Headers-End: 1qdwCk-0000a5-Gp Subject: [Openvpn-devel] [PATCH v2] Fix StatusChangeCallback so it works without a LogCallback 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: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1770986997296112149?= X-GMAIL-MSGID: =?utf-8?q?1776312374614831735?= `StatusChangeCallback` requires that LogForward be enabled, which previously only happened in `LogCallback`. Now both of them do it, which requires a bit of bookkeeping. This fixes https://github.com/OpenVPN/openvpn3-linux/issues/197 Signed-off-by: Jeremy Fleischman --- src/python/openvpn3/SessionManager.py | 69 ++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/src/python/openvpn3/SessionManager.py b/src/python/openvpn3/SessionManager.py index 3632790..a175015 100644 --- a/src/python/openvpn3/SessionManager.py +++ b/src/python/openvpn3/SessionManager.py @@ -114,6 +114,7 @@ def __init__(self, dbuscon, objpath): self.__log_callback = None self.__status_callback = None self.__deleted = False + self.__log_forward_enabled = False def __del__(self): @@ -284,6 +285,16 @@ def GetFormattedStatistics(self, prefix='Connection statistics:\n', format_str=' # # def LogCallback(self, cbfnc): + if cbfnc is not None and self.__log_callback is not None: + # In this case, the program must first disable the + # current LogCallback() before setting a new one. + raise RuntimeError('LogCallback() is already enabled') + + if cbfnc is None and self.__log_callback is None: + # This is fine: disabling a callback when there is no callback is a + # simple no-op. + return + if cbfnc is not None: self.__log_callback = cbfnc self.__dbuscon.add_signal_receiver(cbfnc, @@ -291,16 +302,14 @@ def LogCallback(self, cbfnc): dbus_interface='net.openvpn.v3.backends', bus_name='net.openvpn.v3.log', path=self.__session_path) - self.__session_intf.LogForward(True) else: - try: - self.__session_intf.LogForward(False) - except dbus.exceptions.DBusException: - # If this fails, the session is typically already removed - pass - self.__dbuscon.remove_signal_receiver(self.__log_callback, 'Log') - self.__log_callback = None + # Only remove the callback if there actually *is* a callback + # currently. + if self.__log_callback is not None: + self.__dbuscon.remove_signal_receiver(self.__log_callback, 'Log') + self.__log_callback = None + self.__set_log_forward() ## # Subscribes to the StatusChange signals for this session and register @@ -310,6 +319,16 @@ def LogCallback(self, cbfnc): # (integer) StatusMajor, (integer) StatusMinor, (string) message # def StatusChangeCallback(self, cbfnc): + if cbfnc is not None and self.__status_callback is not None: + # In this case, the program must first disable the + # current StatusChangeCallback() before setting a new one. + raise RuntimeError('StatusChangeCallback() is already enabled') + + if cbfnc is None and self.__status_callback is None: + # This is fine: disabling a callback when there is no callback is a + # simple no-op. + return + if cbfnc is not None: self.__status_callback = cbfnc self.__dbuscon.add_signal_receiver(cbfnc, @@ -318,10 +337,14 @@ def StatusChangeCallback(self, cbfnc): bus_name='net.openvpn.v3.log', path=self.__session_path) else: - self.__dbuscon.remove_signal_receiver(self.__status_callback, - 'StatusChange') - self.__status_callback = None + # Only remove the callback if there actually *is* a callback + # currently. + if self.__status_callback is not None: + self.__dbuscon.remove_signal_receiver(self.__status_callback, + 'StatusChange') + self.__status_callback = None + self.__set_log_forward() ## @@ -417,6 +440,30 @@ def GetDCO(self): def SetDCO(self, dco): self.__prop_intf.Set('net.openvpn.v3.sessions', 'dco', dco) + ## + # Internal method to enable/disable LogForward as needed. + # Must be called whenever a callback that needs LogForward enabled is + # added or removed. + # + def __set_log_forward(self): + # The LogCallback and the StatusChangeCallback both need LogForward + # enabled. In other words, LogForward should be enabled iff one or both + # of those callbacks are registered. + should_log_forward_be_enabled = ( + self.__log_callback is not None or self.__status_callback is not None + ) + + if should_log_forward_be_enabled and not self.__log_forward_enabled: + self.__session_intf.LogForward(True) + self.__log_forward_enabled = True + elif not should_log_forward_be_enabled and self.__log_forward_enabled: + try: + self.__session_intf.LogForward(False) + except dbus.exceptions.DBusException: + # If this fails, the session is typically already removed + pass + + self.__log_forward_enabled = False ##