From efa62d44d4727926a2332564527398a117c3ffca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabian=20Gr=C3=BCnbichler?= Date: Tue, 24 May 2022 10:31:54 +0200 Subject: [PATCH] api: add new priv to priv name helper MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit for usage in permission check error messages, to allow easily indicating which privs are missing. Signed-off-by: Fabian Grünbichler --- pbs-api-types/src/acl.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pbs-api-types/src/acl.rs b/pbs-api-types/src/acl.rs index 6cdd0ee6..3142f6fc 100644 --- a/pbs-api-types/src/acl.rs +++ b/pbs-api-types/src/acl.rs @@ -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; -- 2.39.5