mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-15 06:56:25 +00:00
permissions: introduce UserParam permission
to safely differentiate between checking - the current user matches some static string - the current user matches the value in some (path) parameter. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
f84ac35804
commit
3be70bc4a8
@ -16,6 +16,8 @@ pub enum Permission {
|
|||||||
Anybody,
|
Anybody,
|
||||||
/// Allow access for the specified user
|
/// Allow access for the specified user
|
||||||
User(&'static str),
|
User(&'static str),
|
||||||
|
/// Allow access if specified param matches logged in user
|
||||||
|
UserParam(&'static str),
|
||||||
/// Allow access for the specified group of users
|
/// Allow access for the specified group of users
|
||||||
Group(&'static str),
|
Group(&'static str),
|
||||||
/// Use a parameter value as userid to run sub-permission tests.
|
/// Use a parameter value as userid to run sub-permission tests.
|
||||||
@ -45,6 +47,9 @@ impl fmt::Debug for Permission {
|
|||||||
Permission::User(ref userid) => {
|
Permission::User(ref userid) => {
|
||||||
write!(f, "User({})", userid)
|
write!(f, "User({})", userid)
|
||||||
}
|
}
|
||||||
|
Permission::UserParam(param_name) => {
|
||||||
|
write!(f, "UserParam({})", param_name)
|
||||||
|
}
|
||||||
Permission::Group(ref group) => {
|
Permission::Group(ref group) => {
|
||||||
write!(f, "Group({})", group)
|
write!(f, "Group({})", group)
|
||||||
}
|
}
|
||||||
@ -123,6 +128,13 @@ fn check_api_permission_tail(
|
|||||||
Some(ref userid) => return userid == expected_userid,
|
Some(ref userid) => return userid == expected_userid,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Permission::UserParam(param_name) => {
|
||||||
|
match (userid, param.get(¶m_name.to_string())) {
|
||||||
|
(None, _) => return false,
|
||||||
|
(_, None) => return false,
|
||||||
|
(Some(ref userid), Some(ref expected)) => return userid == expected,
|
||||||
|
}
|
||||||
|
}
|
||||||
Permission::Group(expected_group) => {
|
Permission::Group(expected_group) => {
|
||||||
match userid {
|
match userid {
|
||||||
None => return false,
|
None => return false,
|
||||||
|
Loading…
Reference in New Issue
Block a user