Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-sheets committed Jan 6, 2023
1 parent 5fa35f2 commit 2b89661
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
4 changes: 2 additions & 2 deletions data/error_policies/resource_trans.cas
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ resource foo {
resource_transition(foo, bbb, bar, [file]);
resource_transition(foo, zap, ccc, [file]);

// Policies must include at least one av rule
allow(domain, foo, file, [read]);
// Policies must include at least one av rule
allow(domain, foo, file, [read]);
}

resource bar {}
Expand Down
4 changes: 2 additions & 2 deletions data/policies/resource_trans.cas
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
resource foo {
resource_transition(this, domain, bar, [file dir]);

// Policies must include at least one av rule
allow(domain, foo, file, [read]);
// Policies must include at least one av rule
allow(domain, foo, file, [read]);
}

resource bar {}
43 changes: 27 additions & 16 deletions src/internal_rep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,18 @@ pub fn argument_to_typeinfo_vec<'a>(
Ok(ret)
}

fn rename_cow<'a>(
cow_str: &CascadeString,
renames: &BTreeMap<String, String>,
) -> Cow<'a, CascadeString> {
Cow::Owned(CascadeString::from(
renames
.get::<str>(cow_str.as_ref())
.unwrap_or(&cow_str.to_string())
.clone(),
))
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum AvRuleFlavor {
Allow,
Expand All @@ -792,18 +804,6 @@ pub struct AvRule<'a> {

impl AvRule<'_> {
fn get_renamed_statement(&self, renames: &BTreeMap<String, String>) -> Self {
fn rename_cow<'a>(
cow_str: &CascadeString,
renames: &BTreeMap<String, String>,
) -> Cow<'a, CascadeString> {
Cow::Owned(CascadeString::from(
renames
.get::<str>(cow_str.as_ref())
.unwrap_or(&cow_str.to_string())
.clone(),
))
}

AvRule {
av_rule_flavor: self.av_rule_flavor,
source: rename_cow(&self.source, renames),
Expand Down Expand Up @@ -1631,7 +1631,18 @@ pub struct ResourcetransRule<'a> {
pub default: Cow<'a, CascadeString>,
pub domain: Cow<'a, CascadeString>,
pub parent: Cow<'a, CascadeString>,
pub file_type: FileType, // Should this be Cow too?
pub file_type: FileType,
}

impl ResourcetransRule<'_> {
fn get_renamed_statement(&self, renames: &BTreeMap<String, String>) -> Self {
ResourcetransRule {
default: rename_cow(&self.default, renames),
domain: rename_cow(&self.domain, renames),
parent: rename_cow(&self.parent, renames),
file_type: self.file_type,
}
}
}

impl From<&ResourcetransRule<'_>> for sexp::Sexp {
Expand Down Expand Up @@ -2406,9 +2417,9 @@ impl<'a> ValidatedStatement<'a> {
ValidatedStatement::FcRule(f) => {
ValidatedStatement::FcRule(f.get_renamed_statement(renames))
}
// Not 100% sure what to do here since we are dealing with everything as cascade strings
// like domtrans is. With some testing it looks like nothing?
ValidatedStatement::ResourcetransRule(_) => self.clone(),
ValidatedStatement::ResourcetransRule(r) => {
ValidatedStatement::ResourcetransRule(r.get_renamed_statement(renames))
}
// DomtransRule is probably broken on derive anyways. It uses TypeInfos directly rather
// than strings. This probably means that deriving a DomTrans using "this" is broken
ValidatedStatement::DomtransRule(_) => self.clone(),
Expand Down

0 comments on commit 2b89661

Please sign in to comment.