public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
* [PATCH] ovpnmain.cgi: Do not interpret $? as error code of move()
@ 2021-11-03 18:18 Stefan Schantl
  2021-11-04  8:06 ` Michael Tremer
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Schantl @ 2021-11-03 18:18 UTC (permalink / raw)
  To: development

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

Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
---
 html/cgi-bin/ovpnmain.cgi | 41 +++++++++++++++------------------------
 1 file changed, 16 insertions(+), 25 deletions(-)

diff --git a/html/cgi-bin/ovpnmain.cgi b/html/cgi-bin/ovpnmain.cgi
index 2ebf384ed..f99bfdef7 100644
--- a/html/cgi-bin/ovpnmain.cgi
+++ b/html/cgi-bin/ovpnmain.cgi
@@ -1432,18 +1432,17 @@ END
         unlink ($filename);
         goto UPLOADCA_ERROR;
     } else {
-    # Delete if old key exists
-    if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") {
-        unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}";
+	# Delete if old key exists
+	if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") {
+		unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}";
 	}
-    move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}");
-	if ($? ne 0) {
+
+ 	unless(move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}")) {
 		$errormessage = "$Lang::tr{'dh key move failed'}: $!";
 		unlink ($filename);
 		goto UPLOADCA_ERROR;
-	}
+    	}
     }
-
 ###
 ### Upload CA Certificate
 ###
@@ -1489,8 +1488,7 @@ END
 	unlink ($filename);
 	goto UPLOADCA_ERROR;
     } else {
-	move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem");
-	if ($? ne 0) {
+	unless(move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem")) {
 	    $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
 	    unlink ($filename);
 	    goto UPLOADCA_ERROR;
@@ -1814,8 +1812,7 @@ END
 	    }
 	}
 
-	move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem");
-	if ($? ne 0) {
+	unless(move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem")) {
 	    $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
 	    unlink ($filename);
 	    unlink ("${General::swroot}/ovpn/ca/cacert.pem");
@@ -1824,8 +1821,7 @@ END
 	    goto ROOTCERT_ERROR;
         }
 
-	move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem");
-	if ($? ne 0) {
+	unless(move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem")) {
 	    $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
 	    unlink ($filename);
 	    unlink ("${General::swroot}/ovpn/ca/cacert.pem");
@@ -1834,8 +1830,7 @@ END
 	    goto ROOTCERT_ERROR;
         }
 
-	move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem");
-	if ($? ne 0) {
+	unless(move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem")) {
 	    $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
 	    unlink ($filename);
 	    unlink ("${General::swroot}/ovpn/ca/cacert.pem");
@@ -3395,22 +3390,19 @@ END
 	print FILE "status /var/run/openvpn/$n2nname[0]-n2n 10\n";
 	close FILE;
 
-	move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename2");
-
-	if ($? ne 0) {
+	unless(move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename2")) {
 	    $errormessage = "*.conf move failed: $!";
 	    unlink ($filename);
 	    goto N2N_ERROR;
 	}
 	
-	move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2");
-	chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name";
-	
-	if ($? ne 0) {
+	unless(move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2")) {
 	    $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
 	    unlink ($filename);
 	    goto N2N_ERROR;
-	}	
+	}
+
+	chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name";
 	
 my $complzoactive;
 my $mssfixactive;
@@ -4175,8 +4167,7 @@ if ($cgiparams{'TYPE'} eq 'net') {
 		unlink ($filename);
 		goto VPNCONF_ERROR;
 	    } else {
-		move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem");
-		if ($? ne 0) {
+		unless(move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem")) {
 		    $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
 		    unlink ($filename);
 		    goto VPNCONF_ERROR;
-- 
2.30.2


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

* Re: [PATCH] ovpnmain.cgi: Do not interpret $? as error code of move()
  2021-11-03 18:18 [PATCH] ovpnmain.cgi: Do not interpret $? as error code of move() Stefan Schantl
@ 2021-11-04  8:06 ` Michael Tremer
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Tremer @ 2021-11-04  8:06 UTC (permalink / raw)
  To: development

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

Thank you for working on this.

I would suggest to include this with c161 since so many people ran into it.

> On 3 Nov 2021, at 18:18, Stefan Schantl <stefan.schantl(a)ipfire.org> wrote:
> 
> Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
> ---
> html/cgi-bin/ovpnmain.cgi | 41 +++++++++++++++------------------------
> 1 file changed, 16 insertions(+), 25 deletions(-)
> 
> diff --git a/html/cgi-bin/ovpnmain.cgi b/html/cgi-bin/ovpnmain.cgi
> index 2ebf384ed..f99bfdef7 100644
> --- a/html/cgi-bin/ovpnmain.cgi
> +++ b/html/cgi-bin/ovpnmain.cgi
> @@ -1432,18 +1432,17 @@ END
>         unlink ($filename);
>         goto UPLOADCA_ERROR;
>     } else {
> -    # Delete if old key exists
> -    if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") {
> -        unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}";
> +	# Delete if old key exists
> +	if (-f "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}") {
> +		unlink "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}";
> 	}
> -    move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}");
> -	if ($? ne 0) {
> +
> + 	unless(move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'DH_NAME'}")) {
> 		$errormessage = "$Lang::tr{'dh key move failed'}: $!";
> 		unlink ($filename);
> 		goto UPLOADCA_ERROR;
> -	}
> +    	}
>     }
> -
> ###
> ### Upload CA Certificate
> ###
> @@ -1489,8 +1488,7 @@ END
> 	unlink ($filename);
> 	goto UPLOADCA_ERROR;
>     } else {
> -	move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem");
> -	if ($? ne 0) {
> +	unless(move($filename, "${General::swroot}/ovpn/ca/$cgiparams{'CA_NAME'}cert.pem")) {
> 	    $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
> 	    unlink ($filename);
> 	    goto UPLOADCA_ERROR;
> @@ -1814,8 +1812,7 @@ END
> 	    }
> 	}
> 
> -	move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem");
> -	if ($? ne 0) {
> +	unless(move("$tempdir/cacert.pem", "${General::swroot}/ovpn/ca/cacert.pem")) {
> 	    $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
> 	    unlink ($filename);
> 	    unlink ("${General::swroot}/ovpn/ca/cacert.pem");
> @@ -1824,8 +1821,7 @@ END
> 	    goto ROOTCERT_ERROR;
>         }
> 
> -	move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem");
> -	if ($? ne 0) {
> +	unless(move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem")) {
> 	    $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
> 	    unlink ($filename);
> 	    unlink ("${General::swroot}/ovpn/ca/cacert.pem");
> @@ -1834,8 +1830,7 @@ END
> 	    goto ROOTCERT_ERROR;
>         }
> 
> -	move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem");
> -	if ($? ne 0) {
> +	unless(move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem")) {
> 	    $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
> 	    unlink ($filename);
> 	    unlink ("${General::swroot}/ovpn/ca/cacert.pem");
> @@ -3395,22 +3390,19 @@ END
> 	print FILE "status /var/run/openvpn/$n2nname[0]-n2n 10\n";
> 	close FILE;
> 
> -	move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename2");
> -
> -	if ($? ne 0) {
> +	unless(move("$tempdir/$uplconffilename", "${General::swroot}/ovpn/n2nconf/$n2nname[0]/$uplconffilename2")) {
> 	    $errormessage = "*.conf move failed: $!";
> 	    unlink ($filename);
> 	    goto N2N_ERROR;
> 	}
> 	
> -	move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2");
> -	chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name";
> -	
> -	if ($? ne 0) {
> +	unless(move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2")) {
> 	    $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
> 	    unlink ($filename);
> 	    goto N2N_ERROR;
> -	}	
> +	}
> +
> +	chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name";
> 	
> my $complzoactive;
> my $mssfixactive;
> @@ -4175,8 +4167,7 @@ if ($cgiparams{'TYPE'} eq 'net') {
> 		unlink ($filename);
> 		goto VPNCONF_ERROR;
> 	    } else {
> -		move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem");
> -		if ($? ne 0) {
> +		unless(move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}cert.pem")) {
> 		    $errormessage = "$Lang::tr{'certificate file move failed'}: $!";
> 		    unlink ($filename);
> 		    goto VPNCONF_ERROR;
> -- 
> 2.30.2
> 


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

end of thread, other threads:[~2021-11-04  8:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-03 18:18 [PATCH] ovpnmain.cgi: Do not interpret $? as error code of move() Stefan Schantl
2021-11-04  8:06 ` Michael Tremer

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