From patchwork Tue Aug 24 15:50:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 4646 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4GvD9G47qmz3xHv for ; Tue, 24 Aug 2021 15:50:58 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4GvD9C3SyQz6dt; Tue, 24 Aug 2021 15:50:55 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4GvD9B5BSrz2yxp; Tue, 24 Aug 2021 15:50:54 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4GvD995XMBz2y4S for ; Tue, 24 Aug 2021 15:50:53 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4GvD994JVVz6ZR; Tue, 24 Aug 2021 15:50:53 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1629820253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OEyAgLNE57fGoM3nq/uXflgH7htD98hkux6BAWDQ1TE=; b=NkDO1Ij+8ksCrM+Vu668GyNAy2qGfluQgh5dSYCn2mQwylEvjePrPUJDMcwrqcVnr63DrK Pv0CZSd66lxvX+Ag== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1629820253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OEyAgLNE57fGoM3nq/uXflgH7htD98hkux6BAWDQ1TE=; b=qXA/kYwD3Wi785gk/OJd/0YSvhTpyigqrML1d9VR4JpqepLyI9+OXNaZUNGlWKSBg1QKzW KioPBzDU9nQtbZ8uFaQxmp5hEgkjUp/6hR/QuvfEUdH9qNX9aLjhSosqadd2USWrk3D62z ID4+WoVLZB6Jlts7IKLMQDH1JNmUK58L+jceIzqzvBgpyES/FE0pZM/Ps5dmBaqpFRApYt pQD3tinchcXFlUSt3v6BRp2fDLAv78+GGJdnYwUyTO+PstUIMHxI97A2eCgxsgDosRli+7 9+IL08WMuKnHEBSfKCDkAo0R7uafCwVxD98qqO+3GcQhoKkLCLpwnQeub0TFFA== 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> References: <20210824155048.13859-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" From: Stefan Schantl Signed-off-by: Stefan Schantl Signed-off-by: Stefan Schantl Tested-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.pem")) { $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; unlink ($filename); goto UPLOADCA_ERROR; @@ -947,20 +946,23 @@ END if (!$errormessage) { &General::log("ipsec", "Moving cacert..."); - move("/tmp/newcacert", "${General::swroot}/ca/cacert.pem"); - $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0); + unless(move("/tmp/newcacert", "${General::swroot}/ca/cacert.pem")) { + $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; + } } if (!$errormessage) { &General::log("ipsec", "Moving host cert..."); - move("/tmp/newhostcert", "${General::swroot}/certs/hostcert.pem"); - $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0); + unless(move("/tmp/newhostcert", "${General::swroot}/certs/hostcert.pem")) { + $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; + } } if (!$errormessage) { &General::log("ipsec", "Moving private key..."); - move("/tmp/newhostkey", "${General::swroot}/certs/hostkey.pem"); - $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0); + unless(move("/tmp/newhostkey", "${General::swroot}/certs/hostkey.pem")) { + $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; + } } #cleanup temp files @@ -1979,8 +1981,11 @@ END while (grep(/Imported-$idx/, @names) ) {$idx++}; $cgiparams{'CA_NAME'}="Imported-$idx"; $cgiparams{'CERT_NAME'}=&Header::cleanhtml(getCNfromcert ('/tmp/newhostcert')); - move("/tmp/newcacert", "${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem"); - $errormessage = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0); + + unless(move("/tmp/newcacert", "${General::swroot}/ca/$cgiparams{'CA_NAME'}cert.pem")) { + $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; + } + if (!$errormessage) { my $key = &General::findhasharraykey (\%cahash); $cahash{$key}[0] = $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 = "$Lang::tr{'certificate file move failed'}: $!" if ($? ne 0); + unless(move("/tmp/newhostcert", "${General::swroot}/certs/$cgiparams{'NAME'}cert.pem")) { + $errormessage = "$Lang::tr{'certificate file move failed'}: $!"; + } } #cleanup temp files