]> git.proxmox.com Git - pve-access-control.git/commitdiff
fix #1501: pveum: die when deleting special role
authorPhilip Abernethy <p.abernethy@proxmox.com>
Thu, 21 Sep 2017 09:09:14 +0000 (11:09 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 22 Sep 2017 06:38:21 +0000 (08:38 +0200)
Die with a helpful error message instead of silently ignoring the user
when trying to delete a special role.
Also add a property to the API answer for possible later use by the
WebUI.

Reviewed-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Role.pm
PVE/AccessControl.pm

index 6392e133a2bd673dcc96072c11f0a8ded689073f..0216c8dfc62c8cf50227923450d7ad2648bf6be1 100644 (file)
@@ -44,7 +44,8 @@ __PACKAGE__->register_method ({
  
        foreach my $role (keys %{$usercfg->{roles}}) {
            my $privs = join(',', sort keys %{$usercfg->{roles}->{$role}});
-           push @$res, { roleid => $role, privs => $privs };
+           push @$res, { roleid => $role, privs => $privs,
+               special => PVE::AccessControl::role_is_special($role) };
        }
 
        return $res;
@@ -195,6 +196,9 @@ __PACKAGE__->register_method ({
                die "role '$role' does not exist\n"
                    if !$usercfg->{roles}->{$role};
        
+               die "auto-generated role '$role' can not be deleted\n"
+                   if PVE::AccessControl::role_is_special($role);
+
                delete ($usercfg->{roles}->{$role});
 
                # fixme: delete role from acl?
index 7d02cdf27494b64a237963db408a6a28eca38517..98e2fd6849e68c548f5ebfbb3a9235b6662956d8 100644 (file)
@@ -502,6 +502,11 @@ sub create_roles {
 
 create_roles();
 
+sub role_is_special {
+    my ($role) = @_;
+    return exists $special_roles->{$role};
+}
+
 sub add_role_privs {
     my ($role, $usercfg, $privs) = @_;