From patchwork Thu Mar 3 04:49:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 5302 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 4K8JSK1Wz2z3xgV for ; Thu, 3 Mar 2022 04:49:53 +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 4K8JSH5pZ0z5WL; Thu, 3 Mar 2022 04:49:51 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4K8JSH4ftMz2yRM; Thu, 3 Mar 2022 04:49:51 +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 4K8JSG6j2Yz2xKn for ; Thu, 3 Mar 2022 04:49:50 +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 4K8JSF5qzkz341; Thu, 3 Mar 2022 04:49:49 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1646282990; 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=p/a52w3dXIlQ1Dl16Y+6bcEb37NlcEHwOuWg4MqY4qQ=; b=KghKjS0crGqrM/RrA2c1FYYHHIbxHMUwl7sPtQj5+/e+d5PcJ/qLV3KD5n/F75oxhEKsuT sXteuiZ7eoCOjRBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1646282990; 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=p/a52w3dXIlQ1Dl16Y+6bcEb37NlcEHwOuWg4MqY4qQ=; b=eG5jtlzdCDfcP8vhF2CPNFABiJY1WFvN6/qAdVqhIOgSHyNgrQpIQ7sQP1bXD7VhJWa5HC iTLGHAmQYKjTo07q9WqVkjbi9BJjkt8snnOVDQmtHBOgBweQgGUZmAaPuVmvq2W4kxukiV 01p06oku1+PUmoi0X937sp9fzfU9s80H1gOA0ixqqfWBhUCeqNbpCSIQj/YTiQhqSCL1X5 i2TLFk1ThQlwHkBjhbk4g26eI4RVBiCAiLrMhIhCXiG4ePuR3zogsF6pwWonmS2wcmdi8m fu1Xl72rM6BCX5+E6SDmaZUKNwX7qxoPmvxzzrcP6Nddj5udAHeqxMZ8avugNw== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH] update-ids-ruleset: Always drop the lock file if it has been created during runtime. Date: Thu, 3 Mar 2022 05:49:43 +0100 Message-Id: <20220303044943.3678-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 some situations or if an error happened, the lock file could be keep on the system. In such a case the IDS page would be locked forever until user interaction or reboot of the system. Now the script checks if it has created such a lock and release it when the script exists. Signed-off-by: Stefan Schantl Reviewed-by: Michael Tremer Acked-by: Peter Müller --- src/scripts/update-ids-ruleset | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/scripts/update-ids-ruleset b/src/scripts/update-ids-ruleset index 10a270907..c2970d20b 100644 --- a/src/scripts/update-ids-ruleset +++ b/src/scripts/update-ids-ruleset @@ -26,6 +26,9 @@ require '/var/ipfire/general-functions.pl'; require "${General::swroot}/ids-functions.pl"; require "${General::swroot}/lang.pl"; +# Variable to store if the process has written a lockfile. +my $locked; + # Hash to store the configured providers. my %providers = (); @@ -77,6 +80,9 @@ if(&IDS::checkdiskspace()) { # Lock the IDS page. &IDS::lock_ids_page(); +# The script has requested a lock, so set locket to "1". +$locked = "1"; + # Grab the configured providers. &General::readhasharray("$IDS::providers_settings_file", \%providers); @@ -114,13 +120,20 @@ foreach my $id (keys %providers) { # Set correct ownership for the rulesdir and files. &IDS::set_ownership("$IDS::rulespath"); -# Unlock the IDS page. -&IDS::unlock_ids_page(); - # Check if the IDS is running. if(&IDS::ids_is_running()) { # Call suricatactrl to perform a reload. &IDS::call_suricatactrl("reload"); } +# Custom END declaration to release a IDS page lock +# when the script has created one. +END { + # Check if a lock has been requested. + if ($locked) { + # Unlock the IDS page. + &IDS::unlock_ids_page(); + } +} + 1;