]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
ids-functions.pl: Do not send HEAD requests to sourcefire (snort.org) servers
authorStefan Schantl <stefan.schantl@ipfire.org>
Wed, 6 Feb 2019 09:58:59 +0000 (10:58 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Wed, 6 Feb 2019 09:58:59 +0000 (10:58 +0100)
Using this feature to fetch the size of the requested tarball is not allowed by these
servers, so skip this feature for their rulesets.

Fixes #11987

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/ids-functions.pl

index 98bf5806bd984758ea77acccbb8f09d0421b2015..45159ffe974599e5b7875d436eba225f571de3a9 100644 (file)
@@ -210,33 +210,42 @@ sub downloadruleset {
                return 1;
        }
 
                return 1;
        }
 
-       # Pass the requrested url to the downloader.
-       my $request = HTTP::Request->new(HEAD => $url);
+       # Variable to store the filesize of the remote object.
+       my $remote_filesize;
 
 
-       # Accept the html header.
-       $request->header('Accept' => 'text/html');
+       # The sourcfire (snort rules) does not allow to send "HEAD" requests, so skip this check
+       # for this webserver.
+       #
+       # Check if the ruleset source contains "snort.org".
+       unless ($url =~ /\.snort\.org/) {
+               # Pass the requrested url to the downloader.
+               my $request = HTTP::Request->new(HEAD => $url);
 
 
-       # Perform the request and fetch the html header.
-       my $response = $downloader->request($request);
+               # Accept the html header.
+               $request->header('Accept' => 'text/html');
 
 
-       # Check if there was any error.
-       unless ($response->is_success) {
-               # Obtain error.
-               my $error = $response->status_line();
+               # Perform the request and fetch the html header.
+               my $response = $downloader->request($request);
 
 
-               # Log error message.
-               &_log_to_syslog("Unable to download the ruleset. \($error\)");
+               # Check if there was any error.
+               unless ($response->is_success) {
+                       # Obtain error.
+                       my $error = $response->status_line();
 
 
-               # Return "1" - false.
-               return 1;
-       }
+                       # Log error message.
+                       &_log_to_syslog("Unable to download the ruleset. \($error\)");
 
 
-       # Assign the fetched header object.
-       my $header = $response->headers();
+                       # Return "1" - false.
+                       return 1;
+               }
+
+               # Assign the fetched header object.
+               my $header = $response->headers();
 
 
-       # Grab the remote file size from the object and store it in the
-       # variable.
-       my $remote_filesize = $header->content_length;
+               # Grab the remote file size from the object and store it in the
+               # variable.
+               $remote_filesize = $header->content_length;
+       }
 
        # Load perl module to deal with temporary files.
        use File::Temp;
 
        # Load perl module to deal with temporary files.
        use File::Temp;
@@ -273,7 +282,7 @@ sub downloadruleset {
        my $local_filesize = $stat->size;
 
        # Check if both file sizes match.
        my $local_filesize = $stat->size;
 
        # Check if both file sizes match.
-       unless ($remote_filesize eq $local_filesize) {
+       if (($remote_filesize) && ($remote_filesize ne $local_filesize)) {
                # Log error message.
                &_log_to_syslog("Unable to completely download the ruleset. ");
                &_log_to_syslog("Only got $local_filesize Bytes instead of $remote_filesize Bytes. ");
                # Log error message.
                &_log_to_syslog("Unable to completely download the ruleset. ");
                &_log_to_syslog("Only got $local_filesize Bytes instead of $remote_filesize Bytes. ");