a little more verbose error message to point out the issue if vsys fails to execute...
[vsys.git] / factory / comon_exec
1 #!/usr/bin/perl
2 use strict;
3
4 #######################################################
5 #
6 # run any (allowed) progam in the root context
7 #
8 #######################################################
9
10 my @allowed = ("/bin/df"); # allowed commands
11 my $cmdline;
12 my $path;
13 my $p;
14
15 # read command line
16 $cmdline = <STDIN>;
17 chomp($cmdline);
18
19 # identify the path
20 if ($cmdline =~ /\s*(.+)\s+/) {
21    $path = $1;
22 } else {
23    $path = $cmdline;
24 }
25
26 # run the program if it's executable and allowed to run
27 if (-x $path) {
28    foreach $p (@allowed) {
29        if ($p eq $path) {
30            system($cmdline);
31            exit(0);
32        }
33    }
34    print "fatal: '$cmdline' is not allowed to run\n";
35 } else {
36    print "fatal: $path either does not exist or is not executable\n";
37 }
38
39 # some error occurred
40 exit(-1);