File: restrict.pl

package info (click to toggle)
nagios-plugins 1.4.5-1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 6,520 kB
  • ctags: 3,564
  • sloc: ansic: 34,372; perl: 12,573; sh: 10,669; python: 444; makefile: 440; awk: 45
file content (26 lines) | stat: -rwxr-xr-x 719 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/perl

eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
    if 0;

# Set this to your local Nagios plugin path
my $pluginpath = "/usr/libexec/nagios/plugins/";

# Put all the legal commands (i.e. the commands that are
# not Nagios checks but are allowed to be executed anyway)
# in the following associative array.
my %legal_cmds = ("nc" => "/usr/sbin/nc");

# This will not work on OpenSSH
# It does work on ssh-1.2.27-1i
@arg = split ' ',$ENV{'SSH_ORIGINAL_COMMAND'};

$arg[0] =~ s/.*\///;            # strip leading path
$arg[0] =~ tr/-_.a-zA-Z0-9/X/c; # change atypical chars to X

if (!defined ($cmd = $legal_cmds{$arg[0]}))
{
  $cmd = $pluginpath . $arg[0];
}

exec { $cmd } @arg or die "Can't exec $cmd: $!";