diff --git a/src/config.rs b/src/config.rs index 0b1f1e0..fb8ed81 100644 --- a/src/config.rs +++ b/src/config.rs @@ -402,39 +402,26 @@ impl TryFrom for OptionalPolicy { } } -#[derive(Clone, Debug, Deserialize, PartialEq)] +#[derive(Clone, Debug, Default, Deserialize, PartialEq)] pub struct ReceiveOperation { - pub error: String, - pub interface: String, - pub max_fds: u32, - pub min_fds: u32, - pub path: String, - pub sender: String, - pub r#type: MessageType, -} -impl Default for ReceiveOperation { - fn default() -> Self { - Self { - error: String::from("*"), - interface: String::from("*"), - max_fds: u32::MAX, - min_fds: 0, - path: String::from("*"), - r#type: MessageType::Any, - sender: String::default(), - } - } + pub error: Option, + pub interface: Option, + pub max_fds: Option, + pub min_fds: Option, + pub path: Option, + pub sender: Option, + pub r#type: Option, } impl From for ReceiveOperation { fn from(value: RuleAttributes) -> Self { Self { - error: value.receive_error.unwrap_or(String::from("*")), - interface: value.receive_interface.unwrap_or(String::from("*")), - max_fds: value.max_fds.unwrap_or(u32::MAX), - min_fds: value.min_fds.unwrap_or(0), - path: value.receive_path.unwrap_or(String::from("*")), - sender: value.receive_sender.unwrap_or(String::from("*")), - r#type: value.receive_type.unwrap_or_default(), + error: value.receive_error, + interface: value.receive_interface, + max_fds: value.max_fds, + min_fds: value.min_fds, + path: value.receive_path, + sender: value.receive_sender, + r#type: value.receive_type, } } } @@ -544,30 +531,16 @@ fn rules_try_from_rule_elements(value: Vec) -> Result> { pub type Rule = (Access, Operation); -#[derive(Clone, Debug, Deserialize, PartialEq)] +#[derive(Clone, Debug, Default, Deserialize, PartialEq)] pub struct SendOperation { pub broadcast: Option, pub destination: Option, - pub error: String, - pub interface: String, - pub max_fds: u32, - pub min_fds: u32, - pub path: String, - pub r#type: MessageType, -} -impl Default for SendOperation { - fn default() -> Self { - Self { - broadcast: None, - destination: None, - error: String::from("*"), - interface: String::from("*"), - max_fds: u32::MAX, - min_fds: 0, - path: String::from("*"), - r#type: MessageType::default(), - } - } + pub error: Option, + pub interface: Option, + pub max_fds: Option, + pub min_fds: Option, + pub path: Option, + pub r#type: Option, } impl From for SendOperation { fn from(value: RuleAttributes) -> Self { @@ -592,12 +565,12 @@ impl From for SendOperation { Self { broadcast: value.send_broadcast, destination, - error: value.send_error.unwrap_or(String::from("*")), - interface: value.send_interface.unwrap_or(String::from("*")), - max_fds: value.max_fds.unwrap_or(u32::MAX), - min_fds: value.min_fds.unwrap_or(0), - path: value.send_path.unwrap_or(String::from("*")), - r#type: value.send_type.unwrap_or_default(), + error: value.send_error, + interface: value.send_interface, + max_fds: value.max_fds, + min_fds: value.min_fds, + path: value.send_path, + r#type: value.send_type, } } } @@ -840,24 +813,28 @@ mod tests { destination: Some(Destination::Name(String::from( "org.freedesktop.DBus" ))), - error: String::from("something bad"), - interface: String::from("org.freedesktop.systemd1.Activator"), - max_fds: 128, - min_fds: 12, - path: String::from("/org/freedesktop"), - r#type: MessageType::Signal + error: Some(String::from("something bad")), + interface: Some(String::from( + "org.freedesktop.systemd1.Activator" + )), + max_fds: Some(128), + min_fds: Some(12), + path: Some(String::from("/org/freedesktop")), + r#type: Some(MessageType::Signal), }) ), ( Access::Allow, Operation::Receive(ReceiveOperation { - error: String::from("something bad"), - interface: String::from("org.freedesktop.systemd1.Activator"), - max_fds: 128, - min_fds: 12, - path: String::from("/org/freedesktop"), - sender: String::from("org.freedesktop.DBus"), - r#type: MessageType::Signal + error: Some(String::from("something bad")), + interface: Some(String::from( + "org.freedesktop.systemd1.Activator" + )), + max_fds: Some(128), + min_fds: Some(12), + path: Some(String::from("/org/freedesktop")), + sender: Some(String::from("org.freedesktop.DBus")), + r#type: Some(MessageType::Signal), }) ) ], @@ -878,7 +855,7 @@ mod tests { ( Access::Allow, Operation::Receive(ReceiveOperation { - sender: String::from("org.freedesktop.Avahi"), + sender: Some(String::from("org.freedesktop.Avahi")), ..Default::default() }) ), @@ -948,7 +925,7 @@ mod tests { destination: Some(Destination::Name(String::from( "org.gnome.DisplayManager" ))), - interface: String::from("org.gnome.DisplayManager.Manager"), + interface: Some(String::from("org.gnome.DisplayManager.Manager")), // `member=... is dropped` ..Default::default() }),