2012-05-30 Ramon Novoa <rnovoa@artica.es>
* pandora_agent: Merged from unix agent. Check for valid regular expressions before adding module conditions. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6374 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
6cfbb4205a
commit
7f1d4177df
|
@ -1,3 +1,8 @@
|
|||
2012-05-30 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* pandora_agent: Merged from unix agent. Check for valid regular
|
||||
expressions before adding module conditions.
|
||||
|
||||
2012-04-25 Miguel de Dios <miguel.dedios@artica.es>
|
||||
|
||||
* DEBIAN/postinst, DEBIAN/make_deb_package.sh: disabled the checking
|
||||
|
|
|
@ -220,7 +220,8 @@ my $OS_VERSION = guess_os_version ($OS);
|
|||
# Windows specific modules
|
||||
my $Win32 = undef;
|
||||
if ($OS eq 'windows') {
|
||||
use PandoraWin32;
|
||||
require PandoraWin32;
|
||||
PandoraWin32->import();
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
@ -241,6 +242,22 @@ sub error ($) {
|
|||
`logger -i -t pandora_agent_daemon [ERROR] $msg 2>/dev/null`;
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Check a regular expression. Returns 1 if its valid, 0 otherwise.
|
||||
################################################################################
|
||||
sub valid_regexp ($) {
|
||||
my $regexp = shift;
|
||||
|
||||
eval {
|
||||
'' =~ /$regexp/;
|
||||
};
|
||||
|
||||
# Something went wrong
|
||||
return 0 if ($@);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Recursively delete files and directories.
|
||||
################################################################################
|
||||
|
@ -405,7 +422,11 @@ sub parse_conf_modules($) {
|
|||
push (@{$module->{'precondition'}}, {'operator' => '()', 'value_1' => $1, 'value_2' => $2, 'command' => $3});
|
||||
# Regular expression
|
||||
} elsif ($action =~ /^\s*=~\s+(\S*)\s+(.*)$/) {
|
||||
push (@{$module->{'precondition'}}, {'operator' => '=~', 'value_1' => $1, 'command' => $2});
|
||||
if (valid_regexp ($1)) {
|
||||
push (@{$module->{'precondition'}}, {'operator' => '=~', 'value_1' => $1, 'command' => $2});
|
||||
} else {
|
||||
log_message ('setup', "Invalid regular expression in module precondition: $line");
|
||||
}
|
||||
}
|
||||
} elsif ($line =~ /^\s*module_exec\s+(.+)$/) {
|
||||
$module->{'func'} = \&module_exec;
|
||||
|
@ -462,7 +483,11 @@ sub parse_conf_modules($) {
|
|||
push (@{$module->{'conditions'}}, {'operator' => '()', 'value_1' => $1, 'value_2' => $2, 'command' => $3});
|
||||
# Regular expression
|
||||
} elsif ($action =~ /^\s*=~\s+(\S*)\s+(.*)$/) {
|
||||
push (@{$module->{'conditions'}}, {'operator' => '=~', 'value_1' => $1, 'command' => $2});
|
||||
if (valid_regexp ($1)) {
|
||||
push (@{$module->{'conditions'}}, {'operator' => '=~', 'value_1' => $1, 'command' => $2});
|
||||
} else {
|
||||
log_message ('setup', "Invalid regular expression in module condition: $line");
|
||||
}
|
||||
}
|
||||
} elsif ($line =~ /^\s*module_intensive_condition\s+(.*)$/) {
|
||||
my $action = $1;
|
||||
|
@ -477,7 +502,11 @@ sub parse_conf_modules($) {
|
|||
push (@{$module->{'intensive_conditions'}}, {'operator' => '()', 'value_1' => $1, 'value_2' => $2});
|
||||
# Regular expression
|
||||
} elsif ($action =~ /^\s*=~\s+(\S*)\s*$/) {
|
||||
push (@{$module->{'intensive_conditions'}}, {'operator' => '=~', 'value_1' => $1});
|
||||
if (valid_regexp ($1)) {
|
||||
push (@{$module->{'intensive_conditions'}}, {'operator' => '=~', 'value_1' => $1});
|
||||
} else {
|
||||
log_message ('setup', "Invalid regular expression in intensive condition: $line");
|
||||
}
|
||||
}
|
||||
} elsif ($line =~ /^\s*module_crontab\s+(((\*|(\d+(-\d+){0,1}))\s*){5}).*$/) {
|
||||
$module->{'cron'} = $1;
|
||||
|
|
Loading…
Reference in New Issue