qemu_command_builder/
sandbox.rs1use crate::common::OnOff;
2use crate::to_command::{ToArg, ToCommand};
3use bon::Builder;
4
5#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
6pub enum AllowDeny {
7 Allow,
8 Deny,
9}
10
11impl ToArg for AllowDeny {
12 fn to_arg(&self) -> &str {
13 match self {
14 AllowDeny::Allow => "allow",
15 AllowDeny::Deny => "deny",
16 }
17 }
18}
19#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
20pub enum AllowDenyChildren {
21 Allow,
22 Deny,
23 Children,
24}
25
26impl ToArg for AllowDenyChildren {
27 fn to_arg(&self) -> &str {
28 match self {
29 AllowDenyChildren::Allow => "allow",
30 AllowDenyChildren::Deny => "deny",
31 AllowDenyChildren::Children => "children",
32 }
33 }
34}
35#[derive(Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq, Builder)]
36pub struct Sandbox {
37 mode: OnOff,
38 obsolete: Option<AllowDeny>,
39 elevateprivileges: Option<AllowDenyChildren>,
40 spawn: Option<AllowDeny>,
41 resourcecontrol: Option<AllowDeny>,
42}
43
44impl ToCommand for Sandbox {
45 fn to_command(&self) -> Vec<String> {
46 let mut cmd = vec!["-sandbox".to_string()];
47
48 let mut args = vec![];
49 match &self.mode {
50 OnOff::On => {
51 args.push("on".to_string());
52 }
53 OnOff::Off => {
54 args.push("off".to_string());
55 }
56 }
57
58 if let Some(obsolete) = &self.obsolete {
59 args.push(obsolete.to_arg().to_string());
60 }
61 if let Some(elevateprivileges) = &self.elevateprivileges {
62 args.push(format!("elevateprivileges={}", elevateprivileges.to_arg()))
63 }
64 if let Some(spawn) = &self.spawn {
65 args.push(format!("spawn={}", spawn.to_arg()));
66 }
67 if let Some(resourcecontrol) = &self.resourcecontrol {
68 args.push(format!("resourcecontrol={}", resourcecontrol.to_arg()));
69 }
70
71 cmd.push(args.join(","));
72 cmd
73 }
74}