From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Tremer To: development@lists.ipfire.org Subject: Re: [PATCH] ovpnmain.cgi: Do not interpret $? as error code of move() Date: Thu, 04 Nov 2021 08:06:49 +0000 Message-ID: In-Reply-To: <20211103181855.1758-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4943013186254917883==" List-Id: --===============4943013186254917883== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 wrote: >=20 > Signed-off-by: Stefan Schantl > --- > html/cgi-bin/ovpnmain.cgi | 41 +++++++++++++++------------------------ > 1 file changed, 16 insertions(+), 25 deletions(-) >=20 > 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'}c= ert.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.p= em"); > - if ($? ne 0) { > + unless(move("$tempdir/hostcert.pem", "${General::swroot}/ovpn/certs/serve= rcert.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.p= em"); > - if ($? ne 0) { > + unless(move("$tempdir/serverkey.pem", "${General::swroot}/ovpn/certs/serv= erkey.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/$n2nna= me[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/$uplp1= 2name2")) { > $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.pe= m"); > - if ($? ne 0) { > + unless(move($filename, "${General::swroot}/ovpn/certs/$cgiparams{'NAME'}= cert.pem")) { > $errormessage =3D "$Lang::tr{'certificate file move failed'}: $!"; > unlink ($filename); > goto VPNCONF_ERROR; > --=20 > 2.30.2 >=20 --===============4943013186254917883==--