From patchwork Sat Mar 5 15:27:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 5317 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 4K9pWG5Bg9z3xgY for ; Sat, 5 Mar 2022 15:27:38 +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) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4K9pWB3kC7zs6; Sat, 5 Mar 2022 15:27:34 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4K9pWB2HVPz2y0s; Sat, 5 Mar 2022 15:27:34 +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) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4K9pW90sdxz2y0s for ; Sat, 5 Mar 2022 15:27:33 +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 4K9pW82pcszr; Sat, 5 Mar 2022 15:27:32 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1646494052; 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; bh=2cJh2343VKkFujoVh0gNyEXr7l4B08aEY9ZxPxkqHA0=; b=2tTGlEnZijQpMaR5HRg3Ko3WNeKcCIbrNl9QN+AOxotwc6JBGJF12zPG3vnlKHYFDtvU1x sOIzV/W19HUxzDBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1646494052; 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; bh=2cJh2343VKkFujoVh0gNyEXr7l4B08aEY9ZxPxkqHA0=; b=uU8kys4qDN6EbBbTnCM1G9VUDJn3CnJYpkQbAqbE6vhWNf4S0hfuh7meDGPKNtlyuqgKLG 7sf2ZdauqHcpi0Fy/Qga/TlnPpQsoe/4HUwSwFV8XeO1KMj1k2jJIamw6YfqSTLSTMbZaA dtyHUO9BhL8yBTRASsJennODRuvvKGF8WwyW1NV5uBKZYG9ckYPjccp33wQbjAHAx3pUNX RE6NMl8zN8cguynr7ehLTMwdMVIIpLbv729W5WszWqYlJxCDVTumXxlG+vUiW5GKCIGjx3 ahkHtLiOQzYimKmCVgzJ1DGwA+OSg12EH+DtjzE5gwMzuSgwUwLwGGne+bsoPA== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH] ids-functions.pl: Merge same named rulefiles during extract. Date: Sat, 5 Mar 2022 16:27:17 +0100 Message-Id: <20220305152717.5879-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" In case a rulestarball contains several same-named rulefiles they have been overwritten each time and so only contained the content from the last extracted one. Now the content of those files will be merged by appending the content to the first extracted one for each time. Fixes #12792. Signed-off-by: Stefan Schantl Reviewed-by: Bernhard Bitsch --- config/cfgroot/ids-functions.pl | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl index 74d55def6..53ca1bdd4 100644 --- a/config/cfgroot/ids-functions.pl +++ b/config/cfgroot/ids-functions.pl @@ -572,8 +572,38 @@ sub extractruleset ($) { next; } - # Extract the file to the temporary directory. - $tar->extract_file("$packed_file", "$destination"); + # Check if the destination file exists. + unless(-e "$destination") { + # Extract the file to the temporary directory. + $tar->extract_file("$packed_file", "$destination"); + } else { + # Load perl module to deal with temporary files. + use File::Temp; + + # Generate temporary file name, located in the temporary rules directory and a suffix of ".tmp". + my $tmp = File::Temp->new( SUFFIX => ".tmp", DIR => "$tmp_rules_directory", UNLINK => 0 ); + my $tmpfile = $tmp->filename(); + + # Extract the file to the new temporary file name. + $tar->extract_file("$packed_file", "$tmpfile"); + + # Open the the existing file. + open(DESTFILE, ">>", "$destination") or die "Could not open $destination. $!\n"; + open(TMPFILE, "<", "$tmpfile") or die "Could not open $tmpfile. $!\n"; + + # Loop through the content of the temporary file. + while () { + # Append the content line by line to the destination file. + print DESTFILE "$_"; + } + + # Close the file handles. + close(TMPFILE); + close(DESTFILE); + + # Remove the temporary file. + unlink("$tmpfile"); + } } } }