]> git.proxmox.com Git - proxmox-backup.git/commitdiff
api: add new priv to priv name helper
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Tue, 24 May 2022 08:31:54 +0000 (10:31 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 25 May 2022 15:18:56 +0000 (17:18 +0200)
for usage in permission check error messages, to allow easily indicating
which privs are missing.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
pbs-api-types/src/acl.rs

index 6cdd0ee66b83bae0cbab6905227f58db6b6a12a5..3142f6fc6f235f538f94fec63a69879619e8cc03 100644 (file)
@@ -73,6 +73,17 @@ constnamedbitmap! {
     }
 }
 
+pub fn privs_to_priv_names(privs: u64) -> Vec<&'static str> {
+    PRIVILEGES
+        .iter()
+        .fold(Vec::new(), |mut priv_names, (name, value)| {
+            if value & privs != 0 {
+                priv_names.push(name);
+            }
+            priv_names
+        })
+}
+
 /// Admin always has all privileges. It can do everything except a few actions
 /// which are limited to the 'root@pam` superuser
 pub const ROLE_ADMIN: u64 = u64::MAX;