From 3a234628f920d51dc5cf29d5324668dad599d9da Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Thu, 8 Jul 2010 15:04:43 +0000 Subject: [PATCH] 2010-07-08 Ramon Novoa * pandora_exec: Do not verify the command to allow pipes and complex commands. * pandora_agent: Quote the command passed to pandora_exec. Fixed the module cron. Modules without a module cron would not run. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2980 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_agents/unix/ChangeLog | 8 ++++++++ pandora_agents/unix/pandora_agent | 5 +++-- pandora_agents/unix/pandora_exec | 13 +++---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog index d5abc813e3..0f9cec35b3 100644 --- a/pandora_agents/unix/ChangeLog +++ b/pandora_agents/unix/ChangeLog @@ -1,3 +1,11 @@ +2010-07-08 Ramon Novoa + + * pandora_exec: Do not verify the command to allow pipes and complex + commands. + + * pandora_agent: Quote the command passed to pandora_exec. Fixed + the module cron. Modules without a module cron would not run. + 2010-07-05 Junichi Satoh * pandora_agent_installer: Fixed typo and directory permission diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index a75a0a000f..ede0c5ad67 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -761,7 +761,8 @@ sub module_exec ($) { if ($module->{'timeout'} == 0) { @data = `$module->{'params'} 2> /dev/null`; } else { - @data = `$Conf{'pandora_exec'} $module->{'timeout'} $module->{'params'} 2> /dev/null`; + my $cmd = quotemeta ($module->{'params'}); + @data = `$Conf{'pandora_exec'} $module->{'timeout'} $cmd 2> /dev/null`; } # Something went wrong or no data @@ -945,7 +946,7 @@ sub check_module_cron ($) { my $module = shift; # No cron string defined - return 0 unless ($module->{'cron'} ne ''); + return 1 unless ($module->{'cron'} ne ''); # Check if the module was already executed return 0 unless (time() > $module->{'cron_utimestamp'}); diff --git a/pandora_agents/unix/pandora_exec b/pandora_agents/unix/pandora_exec index 3e31d9f3cf..6cd4d48d01 100755 --- a/pandora_agents/unix/pandora_exec +++ b/pandora_agents/unix/pandora_exec @@ -6,7 +6,7 @@ # execution times out or the command does not exist nothing is printed # to stdout. This is part of Pandora FMS Plugin server, do not delete!. # -# Usage: pandora_exec [arguments] +# Usage: pandora_exec ########################################################################## # Copyright (c) 2008 Ramon Novoa, rnovoa@gmail.com # (c) 2008 Artica Soluciones Tecnologicas S.L @@ -34,23 +34,16 @@ if ($#ARGV < 1) { my @opts = @ARGV; my $timeout = shift(@opts); -my $command = quotemeta(shift(@opts)); -my $arguments = join(' ', @opts); +my $command = join(' ', @opts); my $output = ''; my $ReturnCode = 0; - -# Check that the command exists -if (system("$command >/dev/null 2>&1") == 32512) { - exit 2; -} - # Execute the command eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm $timeout; - $output = `$command $arguments`; + $output = `$command`; $ReturnCode = ($? >> 8) & 0xff; alarm 0; };