restrict.pl 719 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/perl
  2. eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
  3. if 0;
  4. # Set this to your local Nagios plugin path
  5. my $pluginpath = "/usr/libexec/nagios/plugins/";
  6. # Put all the legal commands (i.e. the commands that are
  7. # not Nagios checks but are allowed to be executed anyway)
  8. # in the following associative array.
  9. my %legal_cmds = ("nc" => "/usr/sbin/nc");
  10. # This will not work on OpenSSH
  11. # It does work on ssh-1.2.27-1i
  12. @arg = split ' ',$ENV{'SSH_ORIGINAL_COMMAND'};
  13. $arg[0] =~ s/.*\///; # strip leading path
  14. $arg[0] =~ tr/-_.a-zA-Z0-9/X/c; # change atypical chars to X
  15. if (!defined ($cmd = $legal_cmds{$arg[0]}))
  16. {
  17. $cmd = $pluginpath . $arg[0];
  18. }
  19. exec { $cmd } @arg or die "Can't exec $cmd: $!";