From 924ebbef685aaaa22357e1ff64ef3e242798588a Mon Sep 17 00:00:00 2001 From: Matteo Pasotti Date: Fri, 4 Jan 2013 11:51:29 +0000 Subject: - Privileges.pm: added support to sudo - apanel.pl: using polkit as default --- AdminPanel/Privileges.pm | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'AdminPanel/Privileges.pm') diff --git a/AdminPanel/Privileges.pm b/AdminPanel/Privileges.pm index 48a482b..b1d4ef7 100644 --- a/AdminPanel/Privileges.pm +++ b/AdminPanel/Privileges.pm @@ -26,20 +26,39 @@ use base qw(Exporter); use English qw(-no_match_vars); our @EXPORT = qw(require_root_capability - ask_for_authentication); + ask_for_authentication + $USE_SUDO + $USE_PKIT); + +our $USE_SUDO = 1; +our $USE_PKIT = 2; + +my $wrappers = { $USE_SUDO => "sudo", + $USE_PKIT => "pkexec" }; + +my $wrapper = 0; sub require_root_capability { return $EUID != 0; } sub ask_for_authentication { + my $wrapper_id = shift; + $wrapper = $wrappers->{$wrapper_id} if(defined($wrappers->{$wrapper_id})); my ($command, @args) = wrap_command($0, @ARGV); unshift(@args,$command->[1]); + unshift(@args, '-n') if($wrapper_id == $USE_SUDO); # let sudo die if password is needed exec { $command->[0] } $command->[1], @args or die ("command %s missing", $command->[0]); } sub wrap_command { - my $wrapper = "pkexec"; my ($app, @args) = @_; return ([$wrapper, $app], @args); } + +sub get_wrapper { + my $id = shift; + return $wrappers->{$id} if(defined($wrappers->{$id})); +} + +1; -- cgit v1.2.1