Skip to content

Commit

Permalink
Merge pull request #1035 from cgzones/master_mnc
Browse files Browse the repository at this point in the history
munin-node-configure: prepare for taint mode and fix help message
  • Loading branch information
sumpfralle authored Aug 26, 2018
2 parents 2728c5b + 90f4cf2 commit 91c2bde
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 40 deletions.
2 changes: 1 addition & 1 deletion dev_scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ EOF

configure_plugins() {
banner CONFIGURE PLUGINS
munin-node-configure --suggest --shell --families=contrib,auto --remove-also | sh -x
dev_scripts/run munin-node-configure --suggest --shell --families=contrib,auto --remove-also | sh -x
}

configure_node() {
Expand Down
8 changes: 4 additions & 4 deletions dev_scripts/run
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ if [ -z "${1:-}" ]; then
usage
fi

if command=$(command -v "$1"); then
echo "# [dev/run] Found: ${command}"
echo "# [dev/run] Command line: " "$@"
exec "$@"
if [ -x "${BASEDIR}/sandbox/bin/$1" ]; then
echo "# [dev/run] Found: ${BASEDIR}/sandbox/bin/$1"
echo "# [dev/run] Command line: /usr/bin/perl -T -Mlib=${BASEDIR}/sandbox/lib/perl5/ ${BASEDIR}/sandbox/bin/$@"
exec /usr/bin/perl -T -Mlib="${BASEDIR}/sandbox/lib/perl5/" "${BASEDIR}/sandbox/bin/$@"
else
echo >&2 "Failed to find '$1'"
exit 1
Expand Down
5 changes: 0 additions & 5 deletions script/munin-httpd
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
use strict;
use warnings;

# Trust PERL5LIB from environment
use lib map { /(.*)/ } split(/:/, ($ENV{PERL5LIB} || ''));

package Munin::Master::Http;

use HTTP::Server::Simple::CGI::PreFork;
Expand Down Expand Up @@ -61,7 +58,5 @@ sub handle_request

package main;

$ENV{PATH} = '/usr/bin:/bin';

# start the server on port 4948
Munin::Master::Http->new(4948)->run(prefork => 1, max_servers => 10);
8 changes: 0 additions & 8 deletions script/munin-node
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
use strict;
use warnings;

# Trust PERL5LIB from environment
use lib map { /(.*)/ } split(/:/, ($ENV{PERL5LIB} || ''));

use Getopt::Long;

use Munin::Common::Defaults;
Expand Down Expand Up @@ -92,11 +89,6 @@ sub main
conf_file => $conffile,
);

# Untaint $0 after Munin::Node::Server has had a chance of getting
# the original value
$0 =~ /([^\/]*)$/;
$0 = $1;

return 0;
}

Expand Down
27 changes: 21 additions & 6 deletions script/munin-node-configure
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/perl
#!/usr/bin/perl -T
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -32,7 +32,6 @@ my $config = Munin::Node::Config->instance();
my @all_families = qw/auto manual contrib/;
my @default_families = qw/auto/;


sub main
{
parse_args();
Expand Down Expand Up @@ -331,7 +330,15 @@ sub init_snmp
sub run_plugin
{
my ($plugins, $plugin, $mode) = @_;
my $name = $plugin->{name};

# un-taint the plugin name cause it is getting executed
my $name;
if ($plugin->{name} =~ /^([\w-]+)$/x) {
$name = $1;
} else {
$plugin->log_error("Invalid plugin name '$plugin->{name}'");
return;
}

DEBUG("Running '$mode' on $name" );
my $res = $plugins->{library}->fork_service($name, $mode);
Expand All @@ -349,10 +356,18 @@ sub run_plugin
# Definitely a bad sign
if ($plugin_signal) {
$plugin->log_error("Died with signal $plugin_signal during $mode");
if (my @junk = grep !/^#/, @{ $res->{stderr} }) {
$plugin->log_error("Junk printed to stderr");
DEBUG("Junk printed to stderr: @junk");
}
return;
}
elsif ($plugin_exit) {
$plugin->log_error("Non-zero exit during $mode ($plugin_exit)");
if (my @junk = grep !/^#/, @{ $res->{stderr} }) {
$plugin->log_error("Junk printed to stderr");
DEBUG("Junk printed to stderr: @junk");
}
return;

}
Expand Down Expand Up @@ -463,7 +478,7 @@ plugins will be printed. These can be reviewed or piped directly into a shell
to install the plugins.
=head1 GENERAL OPTIONS
=head1 OPTIONS
=over 4
Expand Down Expand Up @@ -666,13 +681,13 @@ not this works with any particular device, we do not know.
This is munin-node-configure (munin-node) v@@VERSION@@.
=head1 AUTHOR
=head1 AUTHORS
Copyright (C) 2009-2010 Matthew Boyle
Copyright (C) 2006 Nicolai Langfeldt
Copyright (C) 2003-2005 Jimmy Olsen
=head1 LICENSE
=head1 COPYRIGHT
This is free software; see the source for copying conditions. There is
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
Expand Down
15 changes: 0 additions & 15 deletions script/munin-run
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
use strict;
use warnings;

# Trust PERL5LIB from environment
use lib map { /(.*)/ } split(/:/, ($ENV{PERL5LIB} || ''));

use Getopt::Long;

use Munin::Common::Defaults;
Expand All @@ -47,20 +44,8 @@ my $paranoia = 0;

my $config = Munin::Node::Config->instance();


sub main
{
# "Clean" environment to disable taint-checking on the environment. We _know_
# that the environment is insecure, but we want to let admins shoot themselves
# in the foot with it, if they want to.
foreach my $key (keys %ENV) {
$ENV{$key} =~ /^(.*)$/;
$ENV{$key} = $1;
}

$0 =~ /^(.*)$/;
$0 = $1;

my ($plugin, $arg) = parse_args();

# Loads the settings from munin-node.conf.
Expand Down
2 changes: 1 addition & 1 deletion script/munin-update
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/perl
#!/usr/bin/perl -T

use warnings;
use strict;
Expand Down

0 comments on commit 91c2bde

Please sign in to comment.