diff --git a/src/config.rs b/src/config.rs index 21a03f4..784e145 100644 --- a/src/config.rs +++ b/src/config.rs @@ -144,6 +144,20 @@ impl Config { } } +#[derive(Clone, Debug, Deserialize, PartialEq)] +pub struct ConnectOperation { + pub group: Option, + pub user: Option, +} +impl From for ConnectOperation { + fn from(value: RuleAttributes) -> Self { + Self { + group: value.group, + user: value.user, + } + } +} + #[derive(Clone, Debug, Deserialize, PartialEq)] #[serde(rename_all = "lowercase")] pub enum BusType { @@ -175,7 +189,7 @@ pub enum Name { #[derive(Clone, Debug, Deserialize, PartialEq)] pub enum Operation { /// rules checked when a new connection to the message bus is established - Connect, + Connect(ConnectOperation), /// rules checked when a connection attempts to own a well-known bus names Own(OwnOperation), /// rules that are checked for each recipient of a message @@ -188,7 +202,7 @@ impl TryFrom for OptionalOperation { type Error = Error; fn try_from(value: RuleAttributes) -> std::result::Result { - let has_connect = false; + let has_connect = value.group.is_some() || value.user.is_some(); let has_own = value.own.is_some() || value.own_prefix.is_some(); let has_send = value.send_broadcast.is_some() || value.send_destination.is_some() @@ -213,18 +227,22 @@ impl TryFrom for OptionalOperation { .sum(); if operations_count > 1 { - return Err(Error::msg(format!("do not mix rule attributes for connect, own, receive, and/or send operations in the same rule: {value:?}"))); + return Err(Error::msg(format!("do not mix rule attributes for connect, own, receive, and/or send attributes in the same rule: {value:?}"))); } - if value.send_destination.is_some() && value.send_destination_prefix.is_some() { - return Err(Error::msg(format!("send_destination_prefix cannot be combined with the send_destination in the same rule: {value:?}"))); + if value.group.is_some() && value.user.is_some() { + return Err(Error::msg(format!( + "`group` cannot be combined with `user` in the same rule: {value:?}" + ))); } - if value.own.is_some() && value.own_prefix.is_some() { return Err(Error::msg(format!( - "own_prefix cannot be combined with the own in the same rule: {value:?}" + "`own_prefix` cannot be combined with `own` in the same rule: {value:?}" ))); } + if value.send_destination.is_some() && value.send_destination_prefix.is_some() { + return Err(Error::msg(format!("`send_destination_prefix` cannot be combined with `send_destination` in the same rule: {value:?}"))); + } // https://github.com/dbus2/busd/issues/79 if value.receive_member.is_some() { @@ -235,7 +253,7 @@ impl TryFrom for OptionalOperation { } if has_connect { - Ok(Some(Operation::Connect)) + Ok(Some(Operation::Connect(ConnectOperation::from(value)))) } else if has_own { Ok(Some(Operation::Own(OwnOperation::from(value)))) } else if has_receive { @@ -734,6 +752,8 @@ mod tests { + + + + + + + + "#; + + Config::parse(input).expect("should parse XML input"); + } + #[test] fn bus_config_parse_with_policies_with_ignored_rules_and_rule_attributes_ok() { let input = r#"