Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/uu/mkfifo/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ mkfifo-error-missing-operand = missing operand
mkfifo-error-cannot-create-fifo = cannot create fifo { $path }: File exists
mkfifo-error-cannot-set-permissions = cannot set permissions on { $path }: { $error }
mkfifo-error-non-file-permission = mode must specify only file permission bits

# Warning messages
mkfifo-warning-context-not-selinux = ignoring --context; it requires an SELinux/SMACK-enabled kernel
3 changes: 3 additions & 0 deletions src/uu/mkfifo/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ mkfifo-error-missing-operand = opérande manquant
mkfifo-error-cannot-create-fifo = impossible de créer le fifo { $path } : Le fichier existe
mkfifo-error-cannot-set-permissions = impossible de définir les permissions sur { $path } : { $error }
mkfifo-error-non-file-permission = le mode ne doit spécifier que des bits de permission de fichier

# Messages d'avertissement
mkfifo-warning-context-not-selinux = --context est ignoré ; cela nécessite un noyau avec SELinux/SMACK activé
10 changes: 8 additions & 2 deletions src/uu/mkfifo/src/mkfifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError};
use uucore::translate;

#[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))]
use uucore::show_warning;
use uucore::{format_usage, show};

mod options {
Expand Down Expand Up @@ -72,8 +74,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
if let Err(e) =
uucore::selinux::set_selinux_security_context(Path::new(&f), context)
{
let _ = std::fs::remove_file(f);
return Err(USimpleError::new(1, e.to_string()));
if matches!(e, uucore::selinux::SeLinuxError::SELinuxNotEnabled) {
show_warning!("{}", translate!("mkfifo-warning-context-not-selinux"));
} else {
let _ = std::fs::remove_file(f);
return Err(USimpleError::new(1, e.to_string()));
}
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions tests/by-util/test_mkfifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,31 @@ fn test_mkfifo_selinux_invalid() {
}
}

#[test]
#[cfg(all(
feature = "feat_selinux",
any(target_os = "linux", target_os = "android")
))]
fn test_mkfifo_context_warns_when_kernel_not_enabled() {
if uucore::selinux::is_selinux_enabled() {
return;
}

let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let dest = "test_fifo_context_warning";

scene
.ucmd()
.arg("--context=unconfined_u:object_r:user_tmp_t:s0")
.arg(dest)
.succeeds()
.no_stdout()
.stderr_contains("ignoring --context");

assert!(at.is_fifo(dest));
}

#[test]
fn test_mkfifo_permission_unchanged_when_failed() {
use uucore::fs::display_permissions;
Expand Down
Loading