From 01cb4dd2285aa8bee3ed9dde54b69d0bf43f1056 Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Fri, 2 Apr 2021 09:13:17 +0200 Subject: [PATCH] ids-functions.pl: Introduce alter_oinkmaster_provider_includes_file(). This function can be used to directly modify the desired file. It takes two arguments: * An action which could be "add" or "remove" * A provider handle, which should be added or removed. Signed-off-by: Stefan Schantl --- config/cfgroot/ids-functions.pl | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl index 88405ab82b..28fbc2654d 100644 --- a/config/cfgroot/ids-functions.pl +++ b/config/cfgroot/ids-functions.pl @@ -910,6 +910,51 @@ sub get_oinkmaster_provider_modified_sids_file ($) { return $filename; } +# +## Function to directly altering the oinkmaster provider includes file. +## +## Requires tha acition "remove" or "add" and a provider handle. +# +sub alter_oinkmaster_provider_includes_file ($$) { + my ($action, $provider) = @_; + + # Call function to get the path and name for the given providers + # oinkmaster modified sids file. + my $provider_modified_sids_file = &get_oinkmaster_provider_modified_sids_file($provider); + + # Open the file for reading.. + open (FILE, $oinkmaster_provider_includes_file) or die "Could not read $oinkmaster_provider_includes_file. $!\n"; + + # Read-in file content. + my @lines = ; + + # Close file after reading. + close(FILE); + + # Re-open the file for writing. + open(FILE, ">", $oinkmaster_provider_includes_file) or die "Could not write to $oinkmaster_provider_includes_file. $!\n"; + + # Loop through the file content. + foreach my $line (@lines) { + # Remove newlines. + chomp($line); + + # Skip line if we found our given provider and the action should be remove. + next if (($line =~ /$provider/) && ($action eq "remove")); + + # Write the read-in line back to the file. + print FILE "$line\n"; + } + + # Add the provider to the file if requested. + if ($action eq "add") { + print FILE "include $provider_modified_sids_file\n"; + } + + # Close file handle. + close(FILE); +} + # ## Function to check if the IDS is running. # -- 2.39.5