diff --git a/src/configuration.rs b/src/configuration.rs index 595f78d..de23c34 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -8,10 +8,11 @@ use serde::Deserialize; mod raw; -#[derive(Clone, Debug, Deserialize, PartialEq)] +#[derive(Clone, Debug, Default, Deserialize, PartialEq)] #[serde(rename_all = "lowercase")] pub enum ApparmorMode { Disabled, + #[default] Enabled, Required, } @@ -27,13 +28,12 @@ pub struct Associate { #[derive(Clone, Debug, Default, PartialEq)] pub struct Configuration { allow_anonymous: Option, - apparmor: Option, + apparmor: ApparmorMode, auth: Vec, fork: Option, // TODO: consider processing `include` more to remove XML-specific structure include: Vec, - // TODO: consider processing `include` more to remove XML-specific structure - includedir: Vec, + includedir: Vec, keep_umask: Option, // TODO: consider processing `include` more to remove XML-specific structure limit: Vec, @@ -41,8 +41,7 @@ pub struct Configuration { pidfile: Option, policy: Vec, selinux: Vec, - // TODO: consider processing `include` more to remove XML-specific structure - servicedir: Vec, + servicedir: Vec, servicehelper: Option, standard_session_servicedirs: Option, standard_system_servicedirs: Option, @@ -78,11 +77,12 @@ impl TryFrom for Configuration { apparmor: match value.apparmor { Some(a) => a.mode, None => None, - }, + } + .unwrap_or_default(), auth: value.auth, fork: value.fork.map(|_| true), include: value.include, - includedir: value.includedir, + includedir: value.includedir.into_iter().map(|pb| pb.text).collect(), keep_umask: value.keep_umask.map(|_| true), limit: value.limit, listen: value.listen, @@ -94,7 +94,7 @@ impl TryFrom for Configuration { Some(s) => s.associate, None => vec![], }, - servicedir: value.servicedir, + servicedir: value.servicedir.into_iter().map(|pb| pb.text).collect(), servicehelper: value.servicehelper, standard_session_servicedirs: value.standard_session_servicedirs.map(|_| true), standard_system_servicedirs: value.standard_system_servicedirs.map(|_| true), @@ -180,15 +180,6 @@ pub struct OwnRule { own_prefix: Option, } -// reuse this between Vec fields, -// except those with field-specific attributes -#[derive(Clone, Debug, Deserialize, PartialEq)] -#[serde(rename_all = "lowercase")] -pub struct PathBufElement { - #[serde(rename = "$text")] - text: PathBuf, -} - #[derive(Clone, Debug, PartialEq)] pub enum Policy { Console { rules: Vec }, @@ -635,7 +626,7 @@ mod tests { "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> - + @@ -647,7 +638,7 @@ mod tests { assert_eq!( got, Configuration { - apparmor: Some(ApparmorMode::Enabled), + apparmor: ApparmorMode::Required, selinux: vec![Associate { context: String::from("foo_t"), own: String::from("org.freedesktop.Foobar") diff --git a/src/configuration/raw.rs b/src/configuration/raw.rs index c003c31..8ab7407 100644 --- a/src/configuration/raw.rs +++ b/src/configuration/raw.rs @@ -5,8 +5,8 @@ use std::{path::PathBuf, str::FromStr}; use serde::Deserialize; use super::{ - ApparmorMode, Associate, IncludeElement, LimitElement, PathBufElement, Principal, RuleMatch, - RuleMatchType, Type, + ApparmorMode, Associate, IncludeElement, LimitElement, Principal, RuleMatch, RuleMatchType, + Type, }; #[derive(Clone, Debug, Deserialize, PartialEq)] @@ -24,14 +24,14 @@ pub(super) struct RawConfiguration { pub auth: Vec, pub fork: Option<()>, pub include: Vec, - pub includedir: Vec, + pub includedir: Vec, pub keep_umask: Option<()>, pub limit: Vec, pub listen: Vec, pub pidfile: Option, pub policy: Vec, pub selinux: Option, - pub servicedir: Vec, + pub servicedir: Vec, pub servicehelper: Option, pub standard_session_servicedirs: Option<()>, pub standard_system_servicedirs: Option<()>, @@ -144,3 +144,12 @@ pub(super) struct RawUserElement { #[serde(rename = "$text")] pub text: Principal, } + +// reuse this between Vec fields, +// except those with field-specific attributes +#[derive(Clone, Debug, Deserialize, PartialEq)] +#[serde(rename_all = "lowercase")] +pub(super) struct RawPathBufElement { + #[serde(rename = "$text")] + pub text: PathBuf, +}