From patchwork Fri Jun 23 04:01:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 6952 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 4QnNpc3vPBz3wjw for ; Fri, 23 Jun 2023 04:01:44 +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 4QnNpX3WLbz2Sn; Fri, 23 Jun 2023 04:01:40 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4QnNpX1nJWz30HV; Fri, 23 Jun 2023 04:01:40 +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 4QnNpW3llYz2xYV for ; Fri, 23 Jun 2023 04:01:39 +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 4QnNpV5hFwz2SJ; Fri, 23 Jun 2023 04:01:38 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1687492899; 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=0R7sqsGZzUdME84mdiAYBYEvpW/QKqNrmBvPpcdsyfE=; b=d4r8aJAcBF268eakiuweZRxyi7BY9Fl2C2k/KT87gcXZyHOS6ZGNBdhiZhA0pD7o//wcWC i8Nlq2ZlS8v+1vCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1687492899; 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=0R7sqsGZzUdME84mdiAYBYEvpW/QKqNrmBvPpcdsyfE=; b=RinMlqIxF716SaB3SqtIcC0gEo/foAbAEXUjnJhLLa+O186iRQqa9aLiJYXcoJO+GAspKq T8w+SMDpZOwLYktWWrqADqZUgXFSAg1zhA/AX/a2nX2I12668A9b4Tbjq/7AZeEpLUodgc 5DjZKxLCa8KIgP8GNsxiBaXGadvB4sRcFu3VuU+0jbhbXHbrDZ2x/NcGFjH41PWu2IzWn3 XHE0a/fbdL54nJ9WNzFOmSOYEpgN9Dj3ntuFBMNAohZpLwAdR7nAJ/GdQzQD5QQFDDekJS JTFOBUkEEKDAN7Irv/VTv0i1YJcdABQjABygMFJv9Zw5nmduwdHWPoLbnwfySA== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH 7/8] extrahd.cgi: Re-order sanity check logic Date: Fri, 23 Jun 2023 06:01:23 +0200 Message-Id: <20230623040124.3826-7-stefan.schantl@ipfire.org> In-Reply-To: <20230623040124.3826-1-stefan.schantl@ipfire.org> References: <20230623040124.3826-1-stefan.schantl@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" Signed-off-by: Stefan Schantl --- html/cgi-bin/extrahd.cgi | 49 +++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/html/cgi-bin/extrahd.cgi b/html/cgi-bin/extrahd.cgi index a4d6e2e3a..89ba19921 100644 --- a/html/cgi-bin/extrahd.cgi +++ b/html/cgi-bin/extrahd.cgi @@ -98,28 +98,7 @@ $extrahdsettings{'UUID'} = ''; ## Add a new device. # if ($extrahdsettings{'ACTION'} eq $Lang::tr{'add'}) { - # Open device file for reading. - open( FILE, "< $devicefile" ) or die "Unable to read $devicefile"; - my @devices = ; - close FILE; - - # Loop through the entries line-by-line. - foreach my $entry (sort @devices) { - # Split the line into pieces and assign nice variables. - my ($uuid, $fs, $path) = split( /\;/, $entry ); - - # Check if the path is allready used. - if ( "$extrahdsettings{'PATH'}" eq "$path" ) { - $errormessage = "$Lang::tr{'extrahd you cant mount'} $extrahdsettings{'DEVICE'} $Lang::tr{'extrahd to'} $extrahdsettings{'PATH'}$Lang::tr{'extrahd because there is already a device mounted'}."; - } - - # Check if the uuid is allready used. - if ("$extrahdsettings{'DEVICE'} eq $uuid") { - $errormessage = "$extrahdsettings{'DEVICE'} is allready mounted."; - } - } - - # Check if a valid mount path has been choosen. + # Check if a valid mount path has been choosen. unless(&is_valid_dir("$extrahdsettings{'PATH'}")) { $errormessage = "$Lang::tr{'extrahd you cant mount'} $extrahdsettings{'DEVICE'} $Lang::tr{'extrahd to root'}."; } @@ -129,7 +108,31 @@ if ($extrahdsettings{'ACTION'} eq $Lang::tr{'add'}) { $errormessage = "$Lang::tr{'extrahd you cant mount'} $extrahdsettings{'DEVICE'} $Lang::tr{'extrahd to'} $extrahdsettings{'PATH'}$Lang::tr{'extrahd because there is already a device mounted'}."; } - # Check if there was an error message. + # Check against may previously configured drives. + unless ($errormessage) { + # Open device file for reading. + open( FILE, "< $devicefile" ) or die "Unable to read $devicefile"; + my @devices = ; + close FILE; + + # Loop through the entries line-by-line. + foreach my $entry (sort @devices) { + # Split the line into pieces and assign nice variables. + my ($uuid, $fs, $path) = split( /\;/, $entry ); + + # Check if the path is allready used. + if ( "$extrahdsettings{'PATH'}" eq "$path" ) { + $errormessage = "$Lang::tr{'extrahd you cant mount'} $extrahdsettings{'DEVICE'} $Lang::tr{'extrahd to'} $extrahdsettings{'PATH'}$Lang::tr{'extrahd because there is already a device mounted'}."; + } + + # Check if the uuid is allready used. + if ("$extrahdsettings{'DEVICE'} eq $uuid") { + $errormessage = "$extrahdsettings{'DEVICE'} is allready mounted."; + } + } + } + + # Go further if there was no error message. unless($errormessage) { # Re-open the device file for writing. open(FILE, ">> $devicefile" ) or die "Unable to write $devicefile";