]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
ids-functions.pl: Rework &_cleanup_rulesdir() function
authorStefan Schantl <stefan.schantl@ipfire.org>
Fri, 12 Oct 2018 13:43:16 +0000 (15:43 +0200)
committerStefan Schantl <stefan.schantl@ipfire.org>
Fri, 12 Oct 2018 13:43:16 +0000 (15:43 +0200)
* Use a directory listing and delete the files.
* Keep files with "config" as file extension.

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

index 16232cc919793810051e0a1644a3aa206d93947f..684566731fddf635a684d9bf8ed212f946d03f55 100644 (file)
@@ -451,14 +451,20 @@ sub _check_rulesdir_permissions() {
 ## the IDS rules, before extracting and modifing the new ruleset.
 #
 sub _cleanup_rulesdir() {
-       # Loop through the rules-directory.
-       while ($item = glob($rulespath/*)) {
-               # Skip element if it is a directory.
-               next if -d $item;
+       # Open rules directory and do a directory listing.
+       opendir(DIR, $rulespath) or die $!;
+
+       # Loop through the direcory.
+       while (my $file = readdir(DIR)) {
+               # We only want files.
+               next unless (-f "$rulespath/$file");
+
+               # Skip element if it has config as file extension.
+               next if ($file =~ m/\.config$/);
 
-               # Delete the current processed item, if not, exit this function
+               # Delete the current processed file, if not, exit this function
                # and return an error message.
-               unlink($item) or return "Could not delete $item. $!\n";
+               unlink($rulespath/$file) or return "Could not delete $rulespath/$file. $!\n";
        }
 
        # Return nothing;