Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[munin-doc]: fix taint mode and some cleanup #1060

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 54 additions & 14 deletions script/munin-doc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/perl
#!/usr/bin/perl -T
#
# This script provides the basis for a plugin documentation system for
# munin. Please see "man perlpod" for the reference manual to writing
Expand Down Expand Up @@ -32,6 +32,8 @@ use Pod::Perldoc;
use File::Find;
use Munin::Common::Defaults;

local $ENV{PATH} = '/usr/bin/local:/usr/bin:/bin';
sumpfralle marked this conversation as resolved.
Show resolved Hide resolved

my @found = (); # Found plugin path names, by priority

my @myargv = @ARGV; # Save the ARGV we want for ourselves.
Expand All @@ -40,47 +42,79 @@ my ($plugin) = @myargv; # First argument is a plugin name

die "munindoc: Please name a plugin\n" unless $plugin;

# un-taint plugin name
die "munindoc: Invalid plugin name '$plugin'\n" unless $plugin =~ /^([\w-]+)$/x;
$plugin = $1;

my $plugin_re = quotemeta($plugin);

@ARGV=();
local @ARGV=();

# Dirs in which to look for $plugin.pod and $plugin files.
my @DIRS = ("$Munin::Common::Defaults::MUNIN_LIBDIR/plugins",
"$Munin::Common::Defaults::MUNIN_CONFDIR/plugins");

File::Find::find({wanted => \&wanted_pod}, @DIRS);
File::Find::find({wanted => \&wanted_basename}, @DIRS);
File::Find::find({wanted => \&wanted_pod, untaint => 1 }, @DIRS);
File::Find::find({wanted => \&wanted_basename, untaint => 1 }, @DIRS);

die "munin-doc: Plugin '$plugin' not found\n" if !@found;

# print "Found: ",join(", ",@found),"\n";
# exit 0;
my ($found_first) = @found;

# -F Arguments are file names, not modules
push(@ARGV,'-F',@found);
# -F The single Argument is file name, not module
push(@ARGV,'-F',$found_first);

# un-taint program name
$0 =~ /^(.*)$/x;
local $0 = $1; ## no critic qw(RegularExpressions::ProhibitCaptureWithoutTest)

exit( Pod::Perldoc->run() );

sub wanted_pod {
sumpfralle marked this conversation as resolved.
Show resolved Hide resolved
# print "Want pod: $File::Find::name\n";
/^$plugin_re\.pod$/so && push(@found,$File::Find::name);
/^$plugin_re\.pod$/xso && push(@found,$File::Find::name);
return;
}

sub wanted_basename {
# print "Want basename: $File::Find::name\n";
$_ eq $plugin && push(@found,$File::Find::name);
# un-taint full path
$File::Find::name =~ /^(.*)$/x;
push(@found,$1) if $_ eq $plugin; ## no critic qw(RegularExpressions::ProhibitCaptureWithoutTest)
return;
}


__END__

=head1 NAME

munindoc - Munin documentation
munin-doc - View Munin plugin documentation.

=head1 USAGE

munin-doc I<pluginname>

=head1 REQUIRED ARGUMENTS

The name of the plugin the documentation should be shown for.

=head1 OPTIONS

None.

=head1 EXIT STATUS

0 on success, non-zero otherwise.

=head1 CONFIGURATION

None needed.

=head1 DESCRIPTION

This program displays Munin documentation, esp. plugin documentation.
Note that not all plugins are documented yet.

Most Munin commands (such as munin-run, and munindoc itself) is only
Most Munin commands (such as munin-run, and munin-doc itself) is only
documented through the usual Unix man command.

=head1 PLUGIN DOCUMENTATION
Expand All @@ -99,10 +133,16 @@ http://munin-monitoring.org/wiki/munindoc for details on how to do it.
But all the work is handed off to the perldoc command once we have
located the Munin documentation files.

=head1 BUGS AND LIMITATIONS

None known. If you found one, please report under L<https://github.com/munin-monitoring/munin/issues>.

=head1 AUTHOR

Copyright (C) 2008-2009 Nicolai Langfeldt, Linpro AS

=head1 LICENSE

GPLv2

=cut