Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/cspell.dictionaries/shell.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ rerast
rollup
sed
selinuxenabled
sestatus
wslpath
xargs

Expand Down
1 change: 1 addition & 0 deletions .vscode/cspell.dictionaries/workspace.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ blocksize
canonname
chroot
dlsym
execvp
fdatasync
freeaddrinfo
getaddrinfo
Expand Down
22 changes: 18 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ feat_require_unix_utmpx = [
# "feat_require_selinux" == set of utilities depending on SELinux.
feat_require_selinux = [
"chcon",
"runcon",
]
## (alternate/newer/smaller platforms) feature sets
# "feat_os_unix_fuchsia" == set of utilities which can be built/run on the "Fuchsia" OS (refs: <https://fuchsia.dev>; <https://en.wikipedia.org/wiki/Google_Fuchsia>)
Expand Down Expand Up @@ -241,7 +242,7 @@ clap = { version = "2.33", features = ["wrap_help"] }
lazy_static = { version="1.3" }
textwrap = { version="0.14", features=["terminal_size"] }
uucore = { version=">=0.0.9", package="uucore", path="src/uucore" }
selinux = { version="0.2.1", optional = true }
selinux = { version="0.2.3", optional = true }
# * uutils
uu_test = { optional=true, version="0.0.7", package="uu_test", path="src/uu/test" }
#
Expand Down Expand Up @@ -313,6 +314,7 @@ realpath = { optional=true, version="0.0.7", package="uu_realpath", path="src/uu
relpath = { optional=true, version="0.0.7", package="uu_relpath", path="src/uu/relpath" }
rm = { optional=true, version="0.0.7", package="uu_rm", path="src/uu/rm" }
rmdir = { optional=true, version="0.0.7", package="uu_rmdir", path="src/uu/rmdir" }
runcon = { optional=true, version="0.0.7", package="uu_runcon", path="src/uu/runcon" }
seq = { optional=true, version="0.0.7", package="uu_seq", path="src/uu/seq" }
shred = { optional=true, version="0.0.7", package="uu_shred", path="src/uu/shred" }
shuf = { optional=true, version="0.0.7", package="uu_shuf", path="src/uu/shuf" }
Expand Down
4 changes: 3 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ UNIX_PROGS := \
who

SELINUX_PROGS := \
chcon
chcon \
runcon

ifneq ($(OS),Windows_NT)
PROGS := $(PROGS) $(UNIX_PROGS)
Expand Down Expand Up @@ -216,6 +217,7 @@ TEST_PROGS := \
realpath \
rm \
rmdir \
runcon \
seq \
sort \
split \
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ To contribute to uutils, please see [CONTRIBUTING](CONTRIBUTING.md).

| Done | Semi-Done | To Do |
|-----------|-----------|--------|
| arch | cp | runcon |
| base32 | date | stty |
| arch | cp | stty |
| base32 | date | |
| base64 | dd | |
| basename | df | |
| basenc | expr | |
Expand Down Expand Up @@ -426,6 +426,7 @@ To contribute to uutils, please see [CONTRIBUTING](CONTRIBUTING.md).
| relpath | | |
| rm | | |
| rmdir | | |
| runcon | | |
| seq | | |
| shred | | |
| shuf | | |
Expand Down
27 changes: 27 additions & 0 deletions src/uu/runcon/Cargo.toml
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"
73 changes: 73 additions & 0 deletions src/uu/runcon/src/errors.rs
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
}
1 change: 1 addition & 0 deletions src/uu/runcon/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uucore_procs::main!(uu_runcon);
Loading