]> git.proxmox.com Git - pve-common.git/commitdiff
new helper raise_perm_exc
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 20 Jan 2012 06:05:16 +0000 (07:05 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 20 Jan 2012 06:05:16 +0000 (07:05 +0100)
data/PVE/Exception.pm

index 8004d0555221080675001b076e6c2cfc93b2b560..63b3843d5f94ea9859cb29f169b2d7ac7bcb9867 100755 (executable)
@@ -21,7 +21,7 @@ use overload 'cmp' => sub {
     return "$a" cmp "$b"; # compare as string
 };
 
     return "$a" cmp "$b"; # compare as string
 };
 
-@EXPORT_OK = qw(raise raise_param_exc);
+@EXPORT_OK = qw(raise raise_param_exc raise_perm_exc);
 
 sub new {
     my ($class, $msg, %param) = @_;
 
 sub new {
     my ($class, $msg, %param) = @_;
@@ -53,6 +53,25 @@ sub raise {
     die $exc;
 }
 
     die $exc;
 }
 
+sub raise_perm_exc {
+    my ($what) = @_;
+
+    my $param = { code => HTTP_FORBIDDEN };
+
+    my $msg = "Permission check failed";
+    
+    $msg .= " ($what)" if $what;
+
+    my $exc = PVE::Exception->new("$msg\n", %$param);
+    
+    my ($pkg, $filename, $line) = caller;
+
+    $exc->{filename} = $filename;
+    $exc->{line} = $line;
+
+    die $exc;
+}
+
 sub is_param_exc {
     my ($self) = @_;
 
 sub is_param_exc {
     my ($self) = @_;