From: Sapan Bhatia Date: Wed, 18 Jun 2008 16:23:48 +0000 (+0000) Subject: Execute script for comon X-Git-Tag: vsys-0.7-9~2 X-Git-Url: http://git.onelab.eu/?p=vsys.git;a=commitdiff_plain;h=a06dc32b4ed114192b76e7b6f25182295b03a4ab Execute script for comon --- diff --git a/factory/comon_exec b/factory/comon_exec new file mode 100755 index 0000000..df6e7c0 --- /dev/null +++ b/factory/comon_exec @@ -0,0 +1,40 @@ +#!/usr/bin/perl +use strict; + +####################################################### +# +# run any (allowed) progam in the root context +# +####################################################### + +my @allowed = ("/bin/df"); # allowed commands +my $cmdline; +my $path; +my $p; + +# read command line +$cmdline = ; +chomp($cmdline); + +# identify the path +if ($cmdline =~ /\s*(.+)\s+/) { + $path = $1; +} else { + $path = $cmdline; +} + +# run the program if it's executable and allowed to run +if (-x $path) { + foreach $p (@allowed) { + if ($p eq $path) { + system($cmdline); + exit(0); + } + } + print "fatal: '$cmdline' is not allowed to run\n"; +} else { + print "fatal: $path either does not exist or is not executable\n"; +} + +# some error occurred +exit(-1);