aboutsummaryrefslogtreecommitdiffstats
path: root/iurt_root_command
diff options
context:
space:
mode:
authorFlorent Villard <warly@mandriva.com>2006-08-28 16:25:19 +0000
committerFlorent Villard <warly@mandriva.com>2006-08-28 16:25:19 +0000
commit32e362f9d93062fec2817fd7b2d74bd55ef45321 (patch)
tree694852c47bc75cb9d1fc6f95c6e9001798bc2685 /iurt_root_command
parentdc6a2067679bb1b0dfa48f3de06e22567441bc82 (diff)
downloadiurt-32e362f9d93062fec2817fd7b2d74bd55ef45321.tar
iurt-32e362f9d93062fec2817fd7b2d74bd55ef45321.tar.gz
iurt-32e362f9d93062fec2817fd7b2d74bd55ef45321.tar.bz2
iurt-32e362f9d93062fec2817fd7b2d74bd55ef45321.tar.xz
iurt-32e362f9d93062fec2817fd7b2d74bd55ef45321.zip
add a new wrapper to run command which needs privileges
Diffstat (limited to 'iurt_root_command')
-rw-r--r--iurt_root_command71
1 files changed, 71 insertions, 0 deletions
diff --git a/iurt_root_command b/iurt_root_command
new file mode 100644
index 0000000..a6fcedf
--- /dev/null
+++ b/iurt_root_command
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+#
+#!/usr/bin/perl
+#
+# Copyright (C) 2006 Mandriva
+#
+# Author: Florent Villard <warly@mandriva.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# run commands which needs root privilege
+#
+
+use strict;
+my $program_name = 'iurt_root_command';
+use Mkcd::Commandline qw(parseCommandLine usage);
+
+my $arg = @ARGV;
+my (@params, %run);
+$run{program_name} = $program_name;
+
+my %authorized_modules = ( 'unionfs' => 1 );
+my $sudo = '/usr/bin/sudo';
+
+$run{todo} = [ ];
+@params = (
+ # [ "one letter option", "long name option", "number of args (-X means ´at least X´)", "help text", "function to call", "log info"]
+ #
+ # no_rsync, config_help and copy_srpm kept for compatibility reasons
+ #
+ [ "", "$program_name", 0, "[--modprobe <module>]",
+ "$program_name is a perl script to execute commands which need root privilege, it helps probram which needs occasional root privileges for some commands.",
+ sub { $arg or usage($program_name, \@params) }, "" ],
+ [ "", "modprobe", 1, "<module>]",
+ "$program_name is a perl script to execute commands which need root privilege, it helps probram which needs occasional root privileges for some commands.",
+ \&modprobe, "" ],
+);
+
+open(my $LOG, ">&STDERR");
+$run{LOG} = $LOG;
+
+my $todo = parseCommandLine($program_name, \@ARGV, \@params);
+@ARGV and usage($program_name, \@params, "@ARGV, too many arguments");
+foreach my $t (@$todo) {
+ print {$run{LOG}} "$program_name: $t->[2]\n" if $run{verbose} > 5;
+ &{$t->[0]}(@{$t->[1]}) or print {$run{LOG}} "ERROR: $t->[2]\n";
+}
+
+exit
+
+sub modprobe {
+ my ($run, $module) = @_;
+ if (!$authorized_modules{$module}) {
+ print {$run->{LOG}} "ERROR $program_name: unauthorized module $module\n";
+ return 0
+ }
+ system($sudo, "/sbin/depmod", "-a");
+ !system($sudo, "/sbin/modprobe", "-f", $module)
+}