Skip to content

Commit 0645aa4

Browse files
committed
additional review comments
1 parent 49b73d3 commit 0645aa4

File tree

5 files changed

+38
-29
lines changed

5 files changed

+38
-29
lines changed

doc/TE.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,16 @@ file_type [obj_class])`
310310
Currently this is only valid for the proc filesystem, all other types must be
311311
"/". If not given, the field will default to "/".
312312
* `file_type` is an optional keyword representing a file type to apply the label
313-
to. Valid values are the same as in file_context function. If not given,
313+
to. Valid values are the same as in the file_context function. If not given,
314314
[any] is assumed.
315315
* Note: You must use SELinux userspace tools version 3.4 or newer to use this
316316
field.
317317

318318
`xattr`, `task`, and `trans` all represent filesystems that support SELinux
319319
security contexts. The filesystem itself has a labeled applied to it as a
320-
whole, which is the `fs_label` provided in this function. All files on the
321-
filesystem also store their own SELinux security context in their own extended
322-
attributes.
320+
whole, which is the `fs_label` provided in this function. Individual files
321+
may also have specific security contexts stored in their extended attributes
322+
if supported by the filesystem.
323323

324324
`genfscon` represents filesystems that do not support SELinux security contexts.
325325
Generally a filesystem has a single default security context, `fs_label`

src/compile.rs

+22-19
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,9 @@ pub fn build_func_map<'a>(
339339
Ok(decl_map)
340340
}
341341

342-
#[allow(clippy::collapsible_if)]
343-
pub fn validate_rules(statements: &BTreeSet<ValidatedStatement>) -> Result<(), CascadeErrors> {
342+
pub fn validate_fs_context_duplicates(
343+
statements: &BTreeSet<ValidatedStatement>,
344+
) -> Result<(), CascadeErrors> {
344345
let mut errors = CascadeErrors::new();
345346
let mut fsc_rules: BTreeMap<&String, BTreeSet<&FileSystemContextRule>> = BTreeMap::new();
346347

@@ -368,7 +369,7 @@ pub fn validate_rules(statements: &BTreeSet<ValidatedStatement>) -> Result<(), C
368369
continue 'key_loop;
369370
}
370371
FSContextType::GenFSCon => {
371-
// genfscon gets more complicated. We can have simlar rules as long as the paths different.
372+
// genfscon gets more complicated. We can have similar rules as long as the paths are different.
372373
// If we find a genfscon with the same path, they must have the same context and object type.
373374
if let Some(path) = &rule.path {
374375
for inner_rule in &v {
@@ -383,25 +384,19 @@ pub fn validate_rules(statements: &BTreeSet<ValidatedStatement>) -> Result<(), C
383384
inner_rule.context,
384385
))));
385386
continue 'key_loop;
386-
// else if let is not suppored currently (https://github.com/rust-lang/rust/issues/53667).
387-
// Thus we check if we are not none and then unwrap
388387
} else if path == inner_path
388+
&& rule.file_type != inner_rule.file_type
389389
&& rule.file_type.is_some()
390-
&& inner_rule.file_type.is_some()
391390
{
392-
if rule.file_type.as_ref().unwrap()
393-
!= inner_rule.file_type.as_ref().unwrap()
394-
{
395-
errors.append(CascadeErrors::from(InvalidFileSystemError::new(&format!(
396-
"Duplicate genfscon.\n Found duplicate genfscon rules with differing object types: {}\
397-
\n\tPath: {}\n\tObject Type 1: {}\n\tObject Type 2: {}",
398-
rule.fs_name,
399-
path,
400-
rule.file_type.as_ref().unwrap(),
401-
inner_rule.file_type.as_ref().unwrap(),
402-
))));
403-
continue 'key_loop;
404-
}
391+
errors.append(CascadeErrors::from(InvalidFileSystemError::new(&format!(
392+
"Duplicate genfscon.\n Found duplicate genfscon rules with differing object types: {}\
393+
\n\tPath: {}\n\tObject Type 1: {}\n\tObject Type 2: {}",
394+
rule.fs_name,
395+
path,
396+
rule.file_type.as_ref().unwrap(),
397+
inner_rule.file_type.as_ref().unwrap(),
398+
))));
399+
continue 'key_loop;
405400
}
406401
}
407402
}
@@ -410,7 +405,15 @@ pub fn validate_rules(statements: &BTreeSet<ValidatedStatement>) -> Result<(), C
410405
}
411406
}
412407
}
408+
errors.into_result(())
409+
}
410+
411+
pub fn validate_rules(statements: &BTreeSet<ValidatedStatement>) -> Result<(), CascadeErrors> {
412+
let mut errors = CascadeErrors::new();
413413

414+
if let Err(call_errors) = validate_fs_context_duplicates(statements) {
415+
errors.append(call_errors);
416+
}
414417
errors.into_result(())
415418
}
416419

src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl CascadeErrors {
301301
self.errors.push(error.into());
302302
}
303303

304-
fn is_empty(&self) -> bool {
304+
pub fn is_empty(&self) -> bool {
305305
self.errors.is_empty()
306306
}
307307

src/internal_rep.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1754,21 +1754,27 @@ fn call_to_fsc_rules<'a>(
17541754
file_type: None,
17551755
context: fs_context.clone(),
17561756
});
1757-
} else if !file_types.is_empty() {
1758-
return Err(CascadeErrors::from(ErrorItem::Compile(CompileError::new(
1757+
}
1758+
let mut errors = CascadeErrors::new();
1759+
if !file_types.is_empty() {
1760+
errors.append(CascadeErrors::from(ErrorItem::Compile(CompileError::new(
17591761
"File types can only be provided for 'genfscon'",
17601762
file,
17611763
file_types_arg.get_range(),
17621764
"",
17631765
))));
1764-
} else {
1765-
return Err(CascadeErrors::from(ErrorItem::Compile(CompileError::new(
1766+
}
1767+
if regex_string_arg.get_range().is_some() {
1768+
errors.append(CascadeErrors::from(ErrorItem::Compile(CompileError::new(
17661769
"File path can only be provided for 'genfscon'",
17671770
file,
17681771
regex_string_arg.get_range(),
17691772
"",
17701773
))));
17711774
}
1775+
if !errors.is_empty() {
1776+
return Err(errors);
1777+
}
17721778
}
17731779
FSContextType::GenFSCon => {
17741780
if file_types.is_empty() {

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ mod tests {
11891189

11901190
#[test]
11911191
fn invalid_fs_context() {
1192-
error_policy_test!("fs_context.cas", 8, ErrorItem::Compile(_));
1192+
error_policy_test!("fs_context.cas", 9, ErrorItem::Compile(_));
11931193
}
11941194

11951195
#[test]

0 commit comments

Comments
 (0)