From: Stefan Schantl <stefan.schantl@ipfire.org>
To: development@lists.ipfire.org
Cc: Stefan Schantl <stefan.schantl@ipfire.org>
Subject: [PATCH 2/4] ids-functions.pl: Add function to get the provider by a given rule id
Date: Mon, 9 Feb 2026 15:23:20 +0100 [thread overview]
Message-ID: <20260209142322.2481-2-stefan.schantl@ipfire.org> (raw)
In-Reply-To: <20260209142322.2481-1-stefan.schantl@ipfire.org>
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
config/cfgroot/ids-functions.pl | 80 +++++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl
index bede5fca0..0271ef4fc 100644
--- a/config/cfgroot/ids-functions.pl
+++ b/config/cfgroot/ids-functions.pl
@@ -1829,4 +1829,84 @@ sub generate_report_generator_config() {
close(FILE);
}
+#
+## Function to get the provider handle by a given rule sid.
+#
+sub get_provider_by_sid ($) {
+ my ($sid) = @_;
+
+ # Get all known ruleset providers.
+ my @ruleset_providers = &get_ruleset_providers();
+
+ # Temporary hash to store found ranges.
+ my %tmphash = ();
+ my @tmparray;
+
+ # Loop through the array of known providers.
+ foreach my $provider (@ruleset_providers) {
+ # Skip provider if no sid range is specified.
+ next unless ($IDS::Ruleset::Providers{$provider}{"sid_range"});
+
+ # Grab and the dereference the sid range.
+ my @sid_range = @{ $IDS::Ruleset::Providers{$provider}{"sid_range"} };
+
+ # Check if the given sid is in the range of the current processed provider.
+ next unless (&is_sid_in_range($sid, \@sid_range));
+
+ # Assign some nice human-readable values.
+ my $start = $sid_range[0];
+ my $end = $sid_range[1];
+
+ # Calculate the sid range.
+ my $range = $end - $start;
+
+ # Assign the found provider and it's range to the temporary hash.
+ $tmphash{$range} = $provider;
+ }
+
+ # Sort the ranges of the found providers and store them in a temporary
+ # array - This is neccessary in case more than one range has been found.
+ @tmparray = sort (keys %tmphash);
+
+ # Return if nothing has been found.
+ return unless(@tmparray);
+
+ # The first element of the temporary array contains our smalles sid range
+ # which the given sid has to belong - grab the stored handle.
+ my $handle = $tmphash{$tmparray[0]};
+
+ # Return the obtained handle.
+ return $handle;
+}
+
+#
+## Function to check if a given single sid is in a given range.
+#
+sub is_sid_in_range($\@) {
+ my ($sid, $range_ref) = @_;
+
+ # Deref the array ref and assig to array.
+ my @range = @{ $range_ref };
+
+ # Assign some nice human-readable values.
+ my $range_start = $range[0];
+ my $range_stop = $range[1];
+
+ # Early exit in case the range has been passed the
+ # wrong way around.
+ return undef if ($range_start > $range_stop);
+
+ # Return if the given sid is lower than the start one.
+ return if ($sid < $range_start);
+
+ # Return if the given sid is higher than the max range.
+ return if ($sid > $range_stop);
+
+ # Return True if the given sid is lower or equals the max range.
+ return 1 if ($sid <= $range_stop);
+
+ # If we got here, something strange happend.
+ return undef;
+}
+
1;
--
2.47.3
next prev parent reply other threads:[~2026-02-09 14:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-09 14:23 [PATCH 1/4] ruleset-sources: Add details about rule sid and info URL Stefan Schantl
2026-02-09 14:23 ` Stefan Schantl [this message]
2026-02-09 14:23 ` [PATCH 3/4] ids-functions.pl: Add function to get the info url for a given rule id Stefan Schantl
2026-02-09 14:23 ` [PATCH 4/4] logs.cgi/ids.dat: Use new mechanic to obtain sid info url's Stefan Schantl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260209142322.2481-2-stefan.schantl@ipfire.org \
--to=stefan.schantl@ipfire.org \
--cc=development@lists.ipfire.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox