From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH 3/3] vpnmain.cgi: Do not interpret $? as error code of move() Date: Tue, 24 Aug 2021 15:50:48 +0000 Message-ID: <20210824155048.13859-3-michael.tremer@ipfire.org> In-Reply-To: <20210824155048.13859-1-michael.tremer@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============7756905575331400279==" List-Id: --===============7756905575331400279== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Stefan Schantl Signed-off-by: Stefan Schantl --- html/cgi-bin/vpnmain.cgi | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/html/cgi-bin/vpnmain.cgi b/html/cgi-bin/vpnmain.cgi index e9064e19c..7bb0d1b35 100644 --- a/html/cgi-bin/vpnmain.cgi +++ b/html/cgi-bin/vpnmain.cgi @@ -675,8 +675,7 @@ END unlink ($filename); goto UPLOADCA_ERROR; } else { - move($filename, "${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem"); - if ($? ne 0) { + unless(move($filename, "${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pe= m")) { $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!"; unlink ($filename); goto UPLOADCA_ERROR; @@ -947,20 +946,23 @@ END =20 if (!$errormessage) { &General::log("ipsec", "Moving cacert..."); - move("/tmp/newcacert", "${General::swroot}/ca/cacert.pem"); - $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!" if ($? = ne 0); + unless(move("/tmp/newcacert", "${General::swroot}/ca/cacert.pem")) { + $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!"; + } } =20 if (!$errormessage) { &General::log("ipsec", "Moving host cert..."); - move("/tmp/newhostcert", "${General::swroot}/certs/hostcert.pem"); - $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!" if ($? = ne 0); + unless(move("/tmp/newhostcert", "${General::swroot}/certs/hostcert.pem"))= { + $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!"; + } } =20 if (!$errormessage) { &General::log("ipsec", "Moving private key..."); - move("/tmp/newhostkey", "${General::swroot}/certs/hostkey.pem"); - $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!" if ($? = ne 0); + unless(move("/tmp/newhostkey", "${General::swroot}/certs/hostkey.pem")) { + $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!"; + } } =20 #cleanup temp files @@ -1979,8 +1981,11 @@ END while (grep(/Imported-$idx/, @names) ) {$idx++}; $cgiparams{'CA_NAME'}=3D"Imported-$idx"; $cgiparams{'CERT_NAME'}=3D&Header::cleanhtml(getCNfromcert ('/tmp/newho= stcert')); - move("/tmp/newcacert", "${General::swroot}/ca/$cgiparams{'CA_NAME'}cert= .pem"); - $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!" if ($= ? ne 0); + + unless(move("/tmp/newcacert", "${General::swroot}/ca/$cgiparams{'CA_NAM= E'}cert.pem")) { + $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!"; + } + if (!$errormessage) { my $key =3D &General::findhasharraykey (\%cahash); $cahash{$key}[0] =3D $cgiparams{'CA_NAME'}; @@ -1993,8 +1998,9 @@ END } if (!$errormessage) { &General::log("ipsec", "Moving host cert..."); - move("/tmp/newhostcert", "${General::swroot}/certs/$cgiparams{'NAME'}cert= .pem"); - $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!" if ($? = ne 0); + unless(move("/tmp/newhostcert", "${General::swroot}/certs/$cgiparams{'NAM= E'}cert.pem")) { + $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!"; + } } =20 #cleanup temp files --=20 2.20.1 --===============7756905575331400279==--