]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/scripts/update-ids-ruleset
convert-dns-settings: Set correct ownership after convert is done.
[people/pmueller/ipfire-2.x.git] / src / scripts / update-ids-ruleset
index fe4f838445cd70cabe3406208e803fbf8fb7dc70..dbe5b6849c3da172c83f4c42c69057cd34151863 100644 (file)
 ###############################################################################
 
 use strict;
+use POSIX;
 
 require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/ids-functions.pl";
 require "${General::swroot}/lang.pl";
 
+# The user and group name as which this script should be run.
+my $run_as = 'nobody';
+
+# Get user and group id of the user.
+my ( $uid, $gid ) = ( getpwnam $run_as )[ 2, 3 ];
+
+# Check if the script currently runs as root.
+if ( $> == 0 ) {
+       # Drop privileges and switch to the specified user and group.
+       POSIX::setgid( $gid );
+       POSIX::setuid( $uid );
+}
+
 # Check if the red device is active.
 unless (-e "${General::swroot}/red/active") {
        # Store notice in the syslog.
        &IDS::_log_to_syslog("The system is offline.");
 
        # Store error message for displaying in the WUI.
-       &IDS::_store_error_message("$Lang::tr{'could not download latest updates'}");
+       &IDS::_store_error_message("$Lang::tr{'could not download latest updates'} - $Lang::tr{'system is offline'}");
 
        # Exit.
        exit 0;
@@ -46,18 +60,33 @@ if(&IDS::checkdiskspace()) {
        exit 0;
 }
 
+# Lock the IDS page.
+&IDS::lock_ids_page();
+
 # Call the download function and gather the new ruleset.
 if(&IDS::downloadruleset()) {
        # Store error message for displaying in the WUI.
        &IDS::_store_error_message("$Lang::tr{'could not download latest updates'}");
 
+       # Unlock the IDS page.
+       &IDS::unlock_ids_page();
+
        # Exit.
        exit 0;
 }
 
+# Set correct ownership for the downloaded tarball.
+&IDS::set_ownership("$IDS::rulestarball");
+
 # Call oinkmaster to alter the ruleset.
 &IDS::oinkmaster();
 
+# Set correct ownership for the rulesdir and files.
+&IDS::set_ownership("$IDS::rulespath");
+
+# Unlock the IDS page.
+&IDS::unlock_ids_page();
+
 # Check if the IDS is running.
 if(&IDS::ids_is_running()) {
        # Call suricatactrl to perform a reload.