Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chcon: added implementation and integration tests #2075

Merged
merged 2 commits into from
Aug 6, 2021
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
5 changes: 5 additions & 0 deletions .vscode/cspell.dictionaries/shell.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ abspath
addprefix
addsuffix
endef
findstring
firstword
ifeq
ifneq
Expand All @@ -89,5 +90,9 @@ markdownlint
rerast
rollup
sed
selinuxenabled
wslpath
xargs

# * directories
sbin
14 changes: 14 additions & 0 deletions .vscode/cspell.dictionaries/workspace.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ whoami
# * vars/errno
errno
EEXIST
ENODATA
ENOENT
ENOSYS
EPERM
Expand All @@ -119,7 +120,9 @@ fcntl
vmsplice

# * vars/libc
COMFOLLOW
FILENO
FTSENT
HOSTSIZE
IDSIZE
IFBLK
Expand Down Expand Up @@ -152,6 +155,7 @@ SIGTERM
SYS_fdatasync
SYS_syncfs
USERSIZE
accpath
addrinfo
addrlen
blocksize
Expand All @@ -175,15 +179,18 @@ inode
inodes
isatty
lchown
pathlen
setgid
setgroups
settime
setuid
socktype
statfs
statp
statvfs
strcmp
strerror
strlen
syncfs
umask
waitpid
Expand Down Expand Up @@ -275,6 +282,13 @@ winerror
winnt
winsock

# * vars/selinux
freecon
getfilecon
lgetfilecon
lsetfilecon
setfilecon

# * vars/uucore
optflag
optflagmulti
Expand Down
24 changes: 24 additions & 0 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ feat_os_unix_musl = [
# NOTE:
# The selinux(-sys) crate requires `libselinux` headers and shared library to be accessible in the C toolchain at compile time.
# Running a uutils compiled with `feat_selinux` requires an SELinux enabled Kernel at run time.
feat_selinux = ["id/selinux", "selinux"]
feat_selinux = ["id/selinux", "selinux", "feat_require_selinux"]
## feature sets with requirements (restricting cross-platform availability)
#
# ** NOTE: these `feat_require_...` sets should be minimized as much as possible to encourage cross-platform availability of utilities
Expand Down Expand Up @@ -186,6 +186,10 @@ feat_require_unix_utmpx = [
"users",
"who",
]
# "feat_require_selinux" == set of utilities depending on SELinux.
feat_require_selinux = [
"chcon",
]
## (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>)
feat_os_unix_fuchsia = [
Expand Down Expand Up @@ -248,6 +252,7 @@ base64 = { optional=true, version="0.0.7", package="uu_base64", path="src/uu/b
basename = { optional=true, version="0.0.7", package="uu_basename", path="src/uu/basename" }
basenc = { optional=true, version="0.0.7", package="uu_basenc", path="src/uu/basenc" }
cat = { optional=true, version="0.0.7", package="uu_cat", path="src/uu/cat" }
chcon = { optional=true, version="0.0.7", package="uu_chcon", path="src/uu/chcon" }
chgrp = { optional=true, version="0.0.7", package="uu_chgrp", path="src/uu/chgrp" }
chmod = { optional=true, version="0.0.7", package="uu_chmod", path="src/uu/chmod" }
chown = { optional=true, version="0.0.7", package="uu_chown", path="src/uu/chown" }
Expand Down
20 changes: 20 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ BUSYBOX_ROOT := $(BASEDIR)/tmp
BUSYBOX_VER := 1.32.1
BUSYBOX_SRC := $(BUSYBOX_ROOT)/busybox-$(BUSYBOX_VER)

ifeq ($(SELINUX_ENABLED),)
SELINUX_ENABLED := 0
ifneq ($(OS),Windows_NT)
ifeq ($(shell /sbin/selinuxenabled 2>/dev/null ; echo $$?),0)
SELINUX_ENABLED := 1
endif
endif
endif

# Possible programs
PROGS := \
base32 \
Expand Down Expand Up @@ -147,10 +156,17 @@ UNIX_PROGS := \
users \
who

SELINUX_PROGS := \
chcon

ifneq ($(OS),Windows_NT)
PROGS := $(PROGS) $(UNIX_PROGS)
endif

ifeq ($(SELINUX_ENABLED),1)
PROGS := $(PROGS) $(SELINUX_PROGS)
endif

UTILS ?= $(PROGS)

# Programs with usable tests
Expand All @@ -159,6 +175,7 @@ TEST_PROGS := \
base64 \
basename \
cat \
chcon \
chgrp \
chmod \
chown \
Expand Down Expand Up @@ -228,6 +245,9 @@ TEST_SPEC_FEATURE :=
ifneq ($(SPEC),)
TEST_NO_FAIL_FAST :=--no-fail-fast
TEST_SPEC_FEATURE := test_unimplemented
else ifeq ($(SELINUX_ENABLED),1)
TEST_NO_FAIL_FAST :=
TEST_SPEC_FEATURE := feat_selinux
endif

define TEST_BUSYBOX
Expand Down
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,18 +371,20 @@ To contribute to uutils, please see [CONTRIBUTING](CONTRIBUTING.md).
| basename | df | |
| basenc | expr | |
| cat | install | |
| chgrp | join | |
| chmod | ls | |
| chown | more | |
| chroot | numfmt | |
| cksum | od (`--strings` and 128-bit data types missing) |
| comm | pr | |
| csplit | printf | |
| cut | sort | |
| dircolors | split | |
| dirname | tac | |
| du | tail | |
| echo | test | |
| chcon | join | |
| cat | ls | |
| chgrp | more | |
| chmod | numfmt | |
| chown | od (`--strings` and 128-bit data types missing) | |
| chroot | pr | |
| cksum | printf | |
| comm | sort | |
| csplit | split | |
| cut | tac | |
| dircolors | tail | |
| dirname | test | |
| du | | |
| echo | | |
| env | | |
| expand | | |
| factor | | |
Expand Down
27 changes: 27 additions & 0 deletions src/uu/chcon/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "uu_chcon"
version = "0.0.7"
authors = ["uutils developers"]
license = "MIT"
description = "chcon ~ (uutils) change file security context"
homepage = "https://github.com/uutils/coreutils"
repository = "https://github.com/uutils/coreutils/tree/master/src/uu/chcon"
keywords = ["coreutils", "uutils", "cli", "utility"]
categories = ["command-line-utilities"]
edition = "2018"

[lib]
path = "src/chcon.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-sys = { version = "0.5" }
fts-sys = { version = "0.2" }
thiserror = { version = "1.0" }
libc = { version = "0.2" }

[[bin]]
name = "chcon"
path = "src/main.rs"
Loading