From 308ba5e74c27e50e9fda4278749256d3ff541d5e Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Fri, 24 Aug 2018 07:37:10 +0200 Subject: [PATCH] ids-functions.pl: Add function to create empty files This generic function can be used to create any kind of emtpy files - it just requires the full path and filename to work. If the specified file exists at calltime, the function will abort to prevent from overwriting existing files and content. Signed-off-by: Stefan Schantl --- config/cfgroot/ids-functions.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/config/cfgroot/ids-functions.pl b/config/cfgroot/ids-functions.pl index cb16e1b493..6f7f3ee7ef 100644 --- a/config/cfgroot/ids-functions.pl +++ b/config/cfgroot/ids-functions.pl @@ -355,4 +355,26 @@ sub call_suricatactrl ($) { return; } +# +## Function to create a new empty file. +# +sub create_empty_file($) { + my ($file) = @_; + + # Check if the given file exists. + if(-e $file) { + # Do nothing to prevent from overwriting existing files. + return; + } + + # Open the file for writing. + open(FILE, ">$file") or die "Could not write to $file. $!\n"; + + # Close file handle. + close(FILE); + + # Return true. + return 1; +} + 1; -- 2.39.2