}
#[api(
+ input: {
+ properties: {
+ path: {
+ schema: ACL_PATH_SCHEMA,
+ optional: true,
+ },
+ exact: {
+ description: "If set, returns only ACL for the exact path.",
+ type: bool,
+ optional: true,
+ default: false,
+ },
+ },
+ },
returns: {
description: "ACL entry list.",
type: Array,
)]
/// Read Access Control List (ACLs).
pub fn read_acl(
- _rpcenv: &mut dyn RpcEnvironment,
+ path: Option<String>,
+ exact: bool,
+ mut rpcenv: &mut dyn RpcEnvironment,
) -> Result<Vec<AclListItem>, Error> {
//let auth_user = rpcenv.get_user().unwrap();
- // fixme: return digest?
- let (tree, _digest) = acl::config()?;
+ let (mut tree, digest) = acl::config()?;
let mut list: Vec<AclListItem> = Vec::new();
- extract_acl_node_data(&tree.root, "", &mut list, false);
+ if let Some(path) = &path {
+ if let Some(node) = &tree.find_node(path) {
+ extract_acl_node_data(&node, path, &mut list, exact);
+ }
+ } else {
+ extract_acl_node_data(&tree.root, "", &mut list, exact);
+ }
+
+ rpcenv["digest"] = proxmox::tools::digest_to_hex(&digest).into();
Ok(list)
}
Self { root: AclTreeNode::new() }
}
+ pub fn find_node(&mut self, path: &str) -> Option<&mut AclTreeNode> {
+ let path = split_acl_path(path);
+ return self.get_node(&path);
+ }
+
fn get_node(&mut self, path: &[&str]) -> Option<&mut AclTreeNode> {
let mut node = &mut self.root;
for comp in path {