Execute script for comon
authorSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 18 Jun 2008 16:23:48 +0000 (16:23 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Wed, 18 Jun 2008 16:23:48 +0000 (16:23 +0000)
factory/comon_exec [new file with mode: 0755]

diff --git a/factory/comon_exec b/factory/comon_exec
new file mode 100755 (executable)
index 0000000..df6e7c0
--- /dev/null
@@ -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 = <STDIN>;
+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);