]> git.proxmox.com Git - pve-access-control.git/commitdiff
return set of privileges on login - can be used to adopt GUI
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 17 Apr 2012 08:26:48 +0000 (10:26 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 17 Apr 2012 08:26:48 +0000 (10:26 +0200)
Makefile
PVE/API2/AccessControl.pm
changelog.Debian

index eb163d64c565a8e8f2fa8c9466644a36ff06ba40..9e3dd68c7d00717083b272e71edfebe00a845352 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ RELEASE=2.0
 
 VERSION=1.0
 PACKAGE=libpve-access-control
-PKGREL=18
+PKGREL=19
 
 DESTDIR=
 PREFIX=/usr
index 0ef31fa2068a70c0349fd7d1222dea96505f0367..141bc44831a61c5f55a3a3e6f3ff6c0965d78cb1 100644 (file)
@@ -131,6 +131,71 @@ my $create_ticket = sub {
     };
 };
 
+my $compute_api_permission = sub {
+    my ($rpcenv, $authuser) = @_;
+
+    my $usercfg = $rpcenv->{user_cfg};
+
+    my $nodelist = PVE::Cluster::get_nodelist();
+    my $vmlist = PVE::Cluster::get_vmlist() || {};
+    my $idlist = $vmlist->{ids} || {};
+
+    my $cfg = PVE::Storage::config();
+    my @sids =  PVE::Storage::storage_ids ($cfg);
+
+    my $res = {
+       vms => {},
+       storage => {},
+       access => {},
+       nodes => {},
+       dc => {},
+    };
+
+    foreach my $vmid (keys %$idlist, '__phantom__') {
+       my $perm = $rpcenv->permissions($authuser, "/vms/$vmid");
+       foreach my $priv (keys %$perm) {
+           next if !($priv eq 'Permissions.Modify' ||$priv =~ m/^VM\./);
+           $res->{vms}->{$priv} = 1;   
+       }
+    }
+
+    foreach my $storeid (@sids, '__phantom__') {
+       my $perm = $rpcenv->permissions($authuser, "/storage/$storeid");
+       foreach my $priv (keys %$perm) {
+           next if !($priv eq 'Permissions.Modify' || $priv =~ m/^Datastore\./);
+           $res->{storage}->{$priv} = 1;
+       }
+    }
+
+    foreach my $path (('/access/groups')) {
+       my $perm = $rpcenv->permissions($authuser, $path);
+       foreach my $priv (keys %$perm) {
+           next if $priv !~ m/^(User|Group)\./;
+           $res->{access}->{$priv} = 1;
+       }
+    }
+
+    foreach my $group (keys %{$usercfg->{users}->{$authuser}->{groups}}, '__phantom__') {
+       my $perm = $rpcenv->permissions($authuser, "/access/groups/$group");
+       if ($perm->{'User.Modify'}) {
+           $res->{access}->{'User.Modify'} = 1;
+       }
+    }
+
+    foreach my $node (@$nodelist) {
+       my $perm = $rpcenv->permissions($authuser, "/nodes/$node");
+       foreach my $priv (keys %$perm) {
+           next if $priv !~ m/^Sys\./;
+           $res->{nodes}->{$priv} = 1;
+       }
+    }
+
+    my $perm = $rpcenv->permissions($authuser, "/");
+    $res->{dc}->{'Sys.Audit'} = 1 if $perm->{'Sys.Audit'};
+
+    return $res;
+};
+
 __PACKAGE__->register_method ({
     name => 'create_ticket', 
     path => 'ticket', 
@@ -207,6 +272,8 @@ __PACKAGE__->register_method ({
            die $err;
        }
 
+       $res->{cap} = &$compute_api_permission($rpcenv, $username);
+
        PVE::Cluster::log_msg('info', 'root@pam', "successful auth for user '$username'");
 
        return $res;
index 492266e103d6a185615d5f90eee1e380aacc1bcf..2bc47f48cff524467bfac86a49ba999e642f62e1 100644 (file)
@@ -1,3 +1,9 @@
+libpve-access-control (1.0-19) unstable; urgency=low
+
+  * return set of privileges on login - can be used to adopt GUI
+
+ -- Proxmox Support Team <support@proxmox.com>  Tue, 17 Apr 2012 10:25:10 +0200
+
 libpve-access-control (1.0-18) unstable; urgency=low
 
   * fix bug #151: corretly parse username inside ticket