From: Michael Tremer Date: Tue, 6 Dec 2022 09:50:23 +0000 (+0000) Subject: openvpn-authenticator: Avoid infinite loop when losing socket connection X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e66a000f91b9d30436b82ed73b438bb4fc512c11;p=people%2Fms%2Fipfire-2.x.git openvpn-authenticator: Avoid infinite loop when losing socket connection This patch will gracefully terminate the daemon when it loses its connection to the OpenVPN daemon. Fixes: #12963 Signed-off-by: Michael Tremer --- diff --git a/config/ovpn/openvpn-authenticator b/config/ovpn/openvpn-authenticator index 65844012b2..5d9348d7eb 100644 --- a/config/ovpn/openvpn-authenticator +++ b/config/ovpn/openvpn-authenticator @@ -116,11 +116,16 @@ class OpenVPNAuthenticator(object): log.info("OpenVPN Authenticator started") - while True: - line = self._read_line() + try: + while True: + line = self._read_line() - if line.startswith(">CLIENT"): - self._client_event(line) + if line.startswith(">CLIENT"): + self._client_event(line) + + # Terminate the daemon when it loses its connection to the OpenVPN daemon + except ConnectionResetError as e: + log.error("Connection to OpenVPN has been lost: %s" % e) log.info("OpenVPN Authenticator terminated") @@ -269,7 +274,7 @@ class OpenVPNAuthenticator(object): @staticmethod def _b64decode(s): return base64.b64decode(s.encode()).decode() - + @staticmethod def _escape(s): return s.replace(" ", "\ ")