public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
* [PATCH 1/3] openvpn-authenticator: Avoid infinite loop when losing socket connection
@ 2022-12-06 10:01 Michael Tremer
  2022-12-06 10:01 ` [PATCH 2/3] openvpn-authenticator: Drop some dead code Michael Tremer
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Michael Tremer @ 2022-12-06 10:01 UTC (permalink / raw)
  To: development

[-- Attachment #1: Type: text/plain, Size: 1321 bytes --]

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(a)ipfire.org>
---
 config/ovpn/openvpn-authenticator | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/config/ovpn/openvpn-authenticator b/config/ovpn/openvpn-authenticator
index 65844012b..5d9348d7e 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(" ", "\ ")
-- 
2.30.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/3] openvpn-authenticator: Drop some dead code
  2022-12-06 10:01 [PATCH 1/3] openvpn-authenticator: Avoid infinite loop when losing socket connection Michael Tremer
@ 2022-12-06 10:01 ` Michael Tremer
  2022-12-07 12:22   ` Adolf Belka
  2022-12-06 10:01 ` [PATCH 3/3] openvpn-authenticator: Break read loop when daemon goes away Michael Tremer
  2022-12-07 12:21 ` [PATCH 1/3] openvpn-authenticator: Avoid infinite loop when losing socket connection Adolf Belka
  2 siblings, 1 reply; 6+ messages in thread
From: Michael Tremer @ 2022-12-06 10:01 UTC (permalink / raw)
  To: development

[-- Attachment #1: Type: text/plain, Size: 879 bytes --]

Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>
---
 config/ovpn/openvpn-authenticator | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/config/ovpn/openvpn-authenticator b/config/ovpn/openvpn-authenticator
index 5d9348d7e..c22e08f0a 100644
--- a/config/ovpn/openvpn-authenticator
+++ b/config/ovpn/openvpn-authenticator
@@ -97,18 +97,6 @@ class OpenVPNAuthenticator(object):
 		# Send the command
 		self._write_line(command)
 
-		return # XXX Code below doesn't work
-
-		# Read response
-		response = self._read_line()
-
-		# Handle response
-		if not response.startswith("SUCCESS:"):
-			log.error("Command '%s' returned an error:" % command)
-			log.error("  %s" % response)
-
-			return response
-
 	def run(self):
 		# Connect to socket
 		self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-- 
2.30.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/3] openvpn-authenticator: Break read loop when daemon goes away
  2022-12-06 10:01 [PATCH 1/3] openvpn-authenticator: Avoid infinite loop when losing socket connection Michael Tremer
  2022-12-06 10:01 ` [PATCH 2/3] openvpn-authenticator: Drop some dead code Michael Tremer
@ 2022-12-06 10:01 ` Michael Tremer
  2022-12-07 12:22   ` Adolf Belka
  2022-12-07 12:21 ` [PATCH 1/3] openvpn-authenticator: Avoid infinite loop when losing socket connection Adolf Belka
  2 siblings, 1 reply; 6+ messages in thread
From: Michael Tremer @ 2022-12-06 10:01 UTC (permalink / raw)
  To: development

[-- Attachment #1: Type: text/plain, Size: 1075 bytes --]

Fixes: #12963
Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>
---
 config/ovpn/openvpn-authenticator | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/config/ovpn/openvpn-authenticator b/config/ovpn/openvpn-authenticator
index c22e08f0a..4341993e6 100644
--- a/config/ovpn/openvpn-authenticator
+++ b/config/ovpn/openvpn-authenticator
@@ -68,6 +68,12 @@ class OpenVPNAuthenticator(object):
 
 		while True:
 			char = self.sock.recv(1)
+
+			# Break if we could not read from the socket
+			if not char:
+				raise EOFError("Could not read from socket")
+
+			# Append to buffer
 			buf.append(char)
 
 			# Reached end of line
@@ -112,7 +118,7 @@ class OpenVPNAuthenticator(object):
 					self._client_event(line)
 
 		# Terminate the daemon when it loses its connection to the OpenVPN daemon
-		except ConnectionResetError as e:
+		except (ConnectionResetError, EOFError) as e:
 			log.error("Connection to OpenVPN has been lost: %s" % e)
 
 		log.info("OpenVPN Authenticator terminated")
-- 
2.30.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] openvpn-authenticator: Avoid infinite loop when losing socket connection
  2022-12-06 10:01 [PATCH 1/3] openvpn-authenticator: Avoid infinite loop when losing socket connection Michael Tremer
  2022-12-06 10:01 ` [PATCH 2/3] openvpn-authenticator: Drop some dead code Michael Tremer
  2022-12-06 10:01 ` [PATCH 3/3] openvpn-authenticator: Break read loop when daemon goes away Michael Tremer
@ 2022-12-07 12:21 ` Adolf Belka
  2 siblings, 0 replies; 6+ messages in thread
From: Adolf Belka @ 2022-12-07 12:21 UTC (permalink / raw)
  To: development

[-- Attachment #1: Type: text/plain, Size: 1532 bytes --]

Tested-by: Adolf Belka <adolf.belka(a)ipfire.org>

On 06/12/2022 11:01, Michael Tremer wrote:
> 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(a)ipfire.org>
> ---
>   config/ovpn/openvpn-authenticator | 15 ++++++++++-----
>   1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/config/ovpn/openvpn-authenticator b/config/ovpn/openvpn-authenticator
> index 65844012b..5d9348d7e 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(" ", "\ ")

-- 
Sent from my laptop


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] openvpn-authenticator: Drop some dead code
  2022-12-06 10:01 ` [PATCH 2/3] openvpn-authenticator: Drop some dead code Michael Tremer
@ 2022-12-07 12:22   ` Adolf Belka
  0 siblings, 0 replies; 6+ messages in thread
From: Adolf Belka @ 2022-12-07 12:22 UTC (permalink / raw)
  To: development

[-- Attachment #1: Type: text/plain, Size: 1054 bytes --]

Tested-by: Adolf Belka <adolf.belka(a)ipfire.org>

On 06/12/2022 11:01, Michael Tremer wrote:
> Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>
> ---
>   config/ovpn/openvpn-authenticator | 12 ------------
>   1 file changed, 12 deletions(-)
>
> diff --git a/config/ovpn/openvpn-authenticator b/config/ovpn/openvpn-authenticator
> index 5d9348d7e..c22e08f0a 100644
> --- a/config/ovpn/openvpn-authenticator
> +++ b/config/ovpn/openvpn-authenticator
> @@ -97,18 +97,6 @@ class OpenVPNAuthenticator(object):
>   		# Send the command
>   		self._write_line(command)
>   
> -		return # XXX Code below doesn't work
> -
> -		# Read response
> -		response = self._read_line()
> -
> -		# Handle response
> -		if not response.startswith("SUCCESS:"):
> -			log.error("Command '%s' returned an error:" % command)
> -			log.error("  %s" % response)
> -
> -			return response
> -
>   	def run(self):
>   		# Connect to socket
>   		self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

-- 
Sent from my laptop


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] openvpn-authenticator: Break read loop when daemon goes away
  2022-12-06 10:01 ` [PATCH 3/3] openvpn-authenticator: Break read loop when daemon goes away Michael Tremer
@ 2022-12-07 12:22   ` Adolf Belka
  0 siblings, 0 replies; 6+ messages in thread
From: Adolf Belka @ 2022-12-07 12:22 UTC (permalink / raw)
  To: development

[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]

Tested-by: Adolf Belka <adolf.belka(a)ipfire.org>

On 06/12/2022 11:01, Michael Tremer wrote:
> Fixes: #12963
> Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>
> ---
>   config/ovpn/openvpn-authenticator | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/config/ovpn/openvpn-authenticator b/config/ovpn/openvpn-authenticator
> index c22e08f0a..4341993e6 100644
> --- a/config/ovpn/openvpn-authenticator
> +++ b/config/ovpn/openvpn-authenticator
> @@ -68,6 +68,12 @@ class OpenVPNAuthenticator(object):
>   
>   		while True:
>   			char = self.sock.recv(1)
> +
> +			# Break if we could not read from the socket
> +			if not char:
> +				raise EOFError("Could not read from socket")
> +
> +			# Append to buffer
>   			buf.append(char)
>   
>   			# Reached end of line
> @@ -112,7 +118,7 @@ class OpenVPNAuthenticator(object):
>   					self._client_event(line)
>   
>   		# Terminate the daemon when it loses its connection to the OpenVPN daemon
> -		except ConnectionResetError as e:
> +		except (ConnectionResetError, EOFError) as e:
>   			log.error("Connection to OpenVPN has been lost: %s" % e)
>   
>   		log.info("OpenVPN Authenticator terminated")

-- 
Sent from my laptop


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-12-07 12:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-06 10:01 [PATCH 1/3] openvpn-authenticator: Avoid infinite loop when losing socket connection Michael Tremer
2022-12-06 10:01 ` [PATCH 2/3] openvpn-authenticator: Drop some dead code Michael Tremer
2022-12-07 12:22   ` Adolf Belka
2022-12-06 10:01 ` [PATCH 3/3] openvpn-authenticator: Break read loop when daemon goes away Michael Tremer
2022-12-07 12:22   ` Adolf Belka
2022-12-07 12:21 ` [PATCH 1/3] openvpn-authenticator: Avoid infinite loop when losing socket connection Adolf Belka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox