]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
openvpn-authenticator: Avoid infinite loop when losing socket connection
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 6 Dec 2022 10:01:42 +0000 (10:01 +0000)
committerPeter Müller <peter.mueller@ipfire.org>
Sun, 11 Dec 2022 11:53:12 +0000 (11:53 +0000)
This patch will gracefully terminate the daemon when it loses its
connection to the OpenVPN daemon.

Fixes: #12963
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Tested-by: Adolf Belka <adolf.belka@ipfire.org>
config/ovpn/openvpn-authenticator

index 65844012b24dd1067e0bb9f9afe37c7f5efd2cc3..5d9348d7eb087b6b165890b58374f683a95e84e1 100644 (file)
@@ -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(" ", "\ ")