From: Michael Tremer Date: Tue, 6 Dec 2022 10:01:42 +0000 (+0000) Subject: openvpn-authenticator: Avoid infinite loop when losing socket connection X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=91abc6660a4f26b2ba5e6623fc29c4c1297f6303;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 Tested-by: Adolf Belka --- diff --git a/config/ovpn/openvpn-authenticator b/config/ovpn/openvpn-authenticator index 36374caf83..c22e08f0a9 100644 --- a/config/ovpn/openvpn-authenticator +++ b/config/ovpn/openvpn-authenticator @@ -104,11 +104,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") @@ -257,7 +262,7 @@ class OpenVPNAuthenticator(object): @staticmethod def _b64decode(s): return base64.b64decode(s.encode()).decode() - + @staticmethod def _escape(s): return s.replace(" ", "\ ")