-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runcon: added implementation and tests.
- Loading branch information
Showing
11 changed files
with
731 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,7 @@ rerast | |
rollup | ||
sed | ||
selinuxenabled | ||
sestatus | ||
wslpath | ||
xargs | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,6 +162,7 @@ blocksize | |
canonname | ||
chroot | ||
dlsym | ||
execvp | ||
fdatasync | ||
freeaddrinfo | ||
getaddrinfo | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[package] | ||
name = "uu_runcon" | ||
version = "0.0.7" | ||
authors = ["uutils developers"] | ||
license = "MIT" | ||
description = "runcon ~ (uutils) run command with specified security context" | ||
homepage = "https://github.com/uutils/coreutils" | ||
repository = "https://github.com/uutils/coreutils/tree/master/src/uu/runcon" | ||
keywords = ["coreutils", "uutils", "cli", "utility"] | ||
categories = ["command-line-utilities"] | ||
edition = "2018" | ||
|
||
[lib] | ||
path = "src/runcon.rs" | ||
|
||
[dependencies] | ||
clap = { version = "2.33", features = ["wrap_help"] } | ||
uucore = { version = ">=0.0.9", package="uucore", path="../../uucore", features=["entries", "fs", "perms"] } | ||
uucore_procs = { version = ">=0.0.6", package="uucore_procs", path="../../uucore_procs" } | ||
selinux = { version = "0.2" } | ||
fts-sys = { version = "0.2" } | ||
thiserror = { version = "1.0" } | ||
libc = { version = "0.2" } | ||
|
||
[[bin]] | ||
name = "runcon" | ||
path = "src/main.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use std::ffi::OsString; | ||
use std::fmt::Write; | ||
use std::io; | ||
use std::str::Utf8Error; | ||
|
||
pub(crate) type Result<T> = std::result::Result<T, Error>; | ||
|
||
#[derive(thiserror::Error, Debug)] | ||
pub(crate) enum Error { | ||
#[error("No command is specified")] | ||
MissingCommand, | ||
|
||
#[error("SELinux is not enabled")] | ||
SELinuxNotEnabled, | ||
|
||
#[error(transparent)] | ||
NotUTF8(#[from] Utf8Error), | ||
|
||
#[error(transparent)] | ||
CommandLine(#[from] clap::Error), | ||
|
||
#[error("{operation} failed")] | ||
SELinux { | ||
operation: &'static str, | ||
source: selinux::errors::Error, | ||
}, | ||
|
||
#[error("{operation} failed")] | ||
Io { | ||
operation: &'static str, | ||
source: io::Error, | ||
}, | ||
|
||
#[error("{operation} failed on '{}'", .operand1.to_string_lossy())] | ||
Io1 { | ||
operation: &'static str, | ||
operand1: OsString, | ||
source: io::Error, | ||
}, | ||
} | ||
|
||
impl Error { | ||
pub(crate) fn from_io(operation: &'static str, source: io::Error) -> Self { | ||
Self::Io { operation, source } | ||
} | ||
|
||
pub(crate) fn from_io1( | ||
operation: &'static str, | ||
operand1: impl Into<OsString>, | ||
source: io::Error, | ||
) -> Self { | ||
Self::Io1 { | ||
operation, | ||
operand1: operand1.into(), | ||
source, | ||
} | ||
} | ||
|
||
pub(crate) fn from_selinux(operation: &'static str, source: selinux::errors::Error) -> Self { | ||
Self::SELinux { operation, source } | ||
} | ||
} | ||
|
||
pub(crate) fn report_full_error(mut err: &dyn std::error::Error) -> String { | ||
let mut desc = String::with_capacity(256); | ||
write!(&mut desc, "{}", err).unwrap(); | ||
while let Some(source) = err.source() { | ||
err = source; | ||
write!(&mut desc, ": {}", err).unwrap(); | ||
} | ||
desc.push('.'); | ||
desc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
uucore_procs::main!(uu_runcon); |
Oops, something went wrong.