From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH] ovpnmain.cgi: Do not interpret $? as error code of move() Date: Wed, 03 Nov 2021 19:18:55 +0100 Message-ID: <20211103181855.1758-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1755869048412701146==" List-Id: --===============1755869048412701146== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Signed-off-by: Stefan Schantl --- 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 =3D "$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'}cer= t.pem")) { $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!"; unlink ($filename); goto UPLOADCA_ERROR; @@ -1814,8 +1812,7 @@ END } } =20 - 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 =3D "$Lang::tr{'certificate file move failed'}: $!"; unlink ($filename); unlink ("${General::swroot}/ovpn/ca/cacert.pem"); @@ -1824,8 +1821,7 @@ END goto ROOTCERT_ERROR; } =20 - move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/servercert.pem= "); - if ($? ne 0) { + unless(move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/serverc= ert.pem")) { $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!"; unlink ($filename); unlink ("${General::swroot}/ovpn/ca/cacert.pem"); @@ -1834,8 +1830,7 @@ END goto ROOTCERT_ERROR; } =20 - move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serverkey.pem= "); - if ($? ne 0) { + unless(move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/server= key.pem")) { $errormessage =3D "$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; =20 - 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 =3D "*.conf move failed: $!"; unlink ($filename); goto N2N_ERROR; } =09 - move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12name2"); - chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name"; -=09 - if ($? ne 0) { + unless(move("$tempdir/$uplp12name", "${General::swroot}/ovpn/certs/$uplp12n= ame2")) { $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!"; unlink ($filename); goto N2N_ERROR; - }=09 + } + + chmod 0600, "${General::swroot}/ovpn/certs/$uplp12name"; =09 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'}ce= rt.pem")) { $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!"; unlink ($filename); goto VPNCONF_ERROR; --=20 2.30.2 --===============1755869048412701146==--