Skip to content

Commit 437e0e9

Browse files
committed
set_selinux_security_context split the ContextRetrievalFailure error in two
1 parent eb3894e commit 437e0e9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/uucore/src/lib/features/selinux.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ pub enum SeLinuxError {
1616
#[error("Failed to open the file")]
1717
FileOpenFailure,
1818

19-
#[error("Failed to retrieve or set the security context")]
19+
#[error("Failed to retrieve the security context")]
2020
ContextRetrievalFailure,
2121

22+
#[error("Failed to set the security context")]
23+
ContextSetFailure,
24+
2225
#[error("Invalid context string or conversion failure")]
2326
ContextConversionFailure,
2427
}
@@ -29,7 +32,8 @@ impl From<SeLinuxError> for i32 {
2932
SeLinuxError::SELinuxNotEnabled => 1,
3033
SeLinuxError::FileOpenFailure => 2,
3134
SeLinuxError::ContextRetrievalFailure => 3,
32-
SeLinuxError::ContextConversionFailure => 4,
35+
SeLinuxError::ContextSetFailure => 4,
36+
SeLinuxError::ContextConversionFailure => 5,
3337
}
3438
}
3539
}
@@ -109,11 +113,10 @@ pub fn set_selinux_security_context(
109113
false,
110114
)
111115
.set_for_path(path, false, false)
112-
.map_err(|_| SeLinuxError::ContextRetrievalFailure)
116+
.map_err(|_| SeLinuxError::ContextSetFailure)
113117
} else {
114118
// If no context provided, set the default SELinux context for the path
115-
SecurityContext::set_default_for_path(path)
116-
.map_err(|_| SeLinuxError::ContextRetrievalFailure)
119+
SecurityContext::set_default_for_path(path).map_err(|_| SeLinuxError::ContextSetFailure)
117120
}
118121
}
119122

0 commit comments

Comments
 (0)