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
22 changes: 22 additions & 0 deletions src/uu/chroot/locales/en-US.ftl
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
chroot-about = Run COMMAND with root directory set to NEWROOT.
chroot-usage = chroot [OPTION]... NEWROOT [COMMAND [ARG]...]

# Help messages
chroot-help-groups = Comma-separated list of groups to switch to
chroot-help-userspec = Colon-separated user and group to switch to.
chroot-help-skip-chdir = Use this option to not change the working directory to / after changing the root directory to newroot, i.e., inside the chroot.

# Error messages
chroot-error-skip-chdir-only-permitted = option --skip-chdir only permitted if NEWROOT is old '/'
chroot-error-cannot-enter = cannot chroot to { $dir }: { $err }
chroot-error-command-failed = failed to run command { $cmd }: { $err }
chroot-error-command-not-found = failed to run command { $cmd }: { $err }
chroot-error-groups-parsing-failed = --groups parsing failed
chroot-error-invalid-group = invalid group: { $group }
chroot-error-invalid-group-list = invalid group list: { $list }
chroot-error-missing-newroot = Missing operand: NEWROOT\nTry '{ $util_name } --help' for more information.
chroot-error-no-group-specified = no group specified for unknown uid: { $uid }
chroot-error-no-such-user = invalid user
chroot-error-no-such-group = invalid group
chroot-error-no-such-directory = cannot change root directory to { $dir }: no such directory
chroot-error-set-gid-failed = cannot set gid to { $gid }: { $err }
chroot-error-set-groups-failed = cannot set groups: { $err }
chroot-error-set-user-failed = cannot set user to { $user }: { $err }
24 changes: 24 additions & 0 deletions src/uu/chroot/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
chroot-about = Exécuter COMMANDE avec le répertoire racine défini à NOUVRACINE.
chroot-usage = chroot [OPTION]... NOUVRACINE [COMMANDE [ARG]...]

# Messages d'aide
chroot-help-groups = Liste de groupes séparés par des virgules vers lesquels basculer
chroot-help-userspec = Utilisateur et groupe séparés par deux-points vers lesquels basculer.
chroot-help-skip-chdir = Utiliser cette option pour ne pas changer le répertoire de travail vers / après avoir changé le répertoire racine vers nouvracine, c.-à-d., à l'intérieur du chroot.

# Messages d'erreur
chroot-error-skip-chdir-only-permitted = l'option --skip-chdir n'est autorisée que si NOUVRACINE est l'ancien '/'
chroot-error-cannot-enter = impossible de faire chroot vers { $dir } : { $err }
chroot-error-command-failed = échec de l'exécution de la commande { $cmd } : { $err }
chroot-error-command-not-found = échec de l'exécution de la commande { $cmd } : { $err }
chroot-error-groups-parsing-failed = échec de l'analyse de --groups
chroot-error-invalid-group = groupe invalide : { $group }
chroot-error-invalid-group-list = liste de groupes invalide : { $list }
chroot-error-missing-newroot = Opérande manquant : NOUVRACINE\nEssayez '{ $util_name } --help' pour plus d'informations.
chroot-error-no-group-specified = aucun groupe spécifié pour l'uid inconnu : { $uid }
chroot-error-no-such-user = utilisateur invalide
chroot-error-no-such-group = groupe invalide
chroot-error-no-such-directory = impossible de changer le répertoire racine vers { $dir } : aucun répertoire de ce type
chroot-error-set-gid-failed = impossible de définir le gid à { $gid } : { $err }
chroot-error-set-groups-failed = impossible de définir les groupes : { $err }
chroot-error-set-user-failed = impossible de définir l'utilisateur à { $user } : { $err }
20 changes: 8 additions & 12 deletions src/uu/chroot/src/chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@
let name = split[0].trim();
if name.is_empty() {
// --groups=" "
// chroot: invalid group ‘ ’
// chroot: invalid group ' '
Err(ChrootError::InvalidGroup(name.to_string()))
} else {
// --groups="blah"
Ok(vec![name.to_string()])
}
} else if split.iter().all(|s| s.is_empty()) {
// --groups=","
// chroot: invalid group list ‘,’
// chroot: invalid group list ','
Err(ChrootError::InvalidGroupList(list_str.to_string()))
} else {
let mut result = vec![];
Expand All @@ -97,7 +97,7 @@
continue;
} else {
// --groups=", "
// chroot: invalid group ‘ ’
// chroot: invalid group ' '

Check warning on line 100 in src/uu/chroot/src/chroot.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/chroot/src/chroot.rs#L100

Added line #L100 was not covered by tests
show!(ChrootError::InvalidGroup(name.to_string()));
err = true;
}
Expand All @@ -107,7 +107,7 @@
&& trimmed_name.ends_with(|c: char| !c.is_numeric())
{
// --groups="0trail"
// chroot: invalid group 0trail
// chroot: invalid group '0trail'

Check warning on line 110 in src/uu/chroot/src/chroot.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/chroot/src/chroot.rs#L110

Added line #L110 was not covered by tests
show!(ChrootError::InvalidGroup(name.to_string()));
err = true;
} else {
Expand Down Expand Up @@ -176,7 +176,7 @@
{
return Err(UUsageError::new(
125,
"option --skip-chdir only permitted if NEWROOT is old '/'",
get_message("chroot-error-skip-chdir-only-permitted"),
));
}

Expand Down Expand Up @@ -251,23 +251,19 @@
Arg::new(options::GROUPS)
.long(options::GROUPS)
.overrides_with(options::GROUPS)
.help("Comma-separated list of groups to switch to")
.help(get_message("chroot-help-groups"))
.value_name("GROUP1,GROUP2..."),
)
.arg(
Arg::new(options::USERSPEC)
.long(options::USERSPEC)
.help("Colon-separated user and group to switch to.")
.help(get_message("chroot-help-userspec"))
.value_name("USER:GROUP"),
)
.arg(
Arg::new(options::SKIP_CHDIR)
.long(options::SKIP_CHDIR)
.help(
"Use this option to not change the working directory \
to / after changing the root directory to newroot, \
i.e., inside the chroot.",
)
.help(get_message("chroot-help-skip-chdir"))
.action(ArgAction::SetTrue),
)
.arg(
Expand Down
60 changes: 43 additions & 17 deletions src/uu/chroot/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,94 @@
// file that was distributed with this source code.
// spell-checker:ignore NEWROOT Userspec userspec
//! Errors returned by chroot.
use std::collections::HashMap;
use std::io::Error;
use thiserror::Error;
use uucore::display::Quotable;
use uucore::error::UError;
use uucore::libc;
use uucore::locale::{get_message, get_message_with_args};

/// Errors that can happen while executing chroot.
#[derive(Debug, Error)]
pub enum ChrootError {
/// Failed to enter the specified directory.
#[error("cannot chroot to {dir}: {err}", dir = .0.quote(), err = .1)]
#[error("{}", get_message_with_args("chroot-error-cannot-enter", HashMap::from([
("dir".to_string(), _0.quote().to_string()),
("err".to_string(), _1.to_string())
])))]
CannotEnter(String, #[source] Error),

/// Failed to execute the specified command.
#[error("failed to run command {cmd}: {err}", cmd = .0.to_string().quote(), err = .1)]
#[error("{}", get_message_with_args("chroot-error-command-failed", HashMap::from([
("cmd".to_string(), _0.to_string().quote().to_string()),
("err".to_string(), _1.to_string())
])))]
CommandFailed(String, #[source] Error),

/// Failed to find the specified command.
#[error("failed to run command {cmd}: {err}", cmd = .0.to_string().quote(), err = .1)]
#[error("{}", get_message_with_args("chroot-error-command-not-found", HashMap::from([
("cmd".to_string(), _0.to_string().quote().to_string()),
("err".to_string(), _1.to_string())
])))]
CommandNotFound(String, #[source] Error),

#[error("--groups parsing failed")]
#[error("{}", get_message("chroot-error-groups-parsing-failed"))]
GroupsParsingFailed,

#[error("invalid group: {group}", group = .0.quote())]
#[error("{}", get_message_with_args("chroot-error-invalid-group", HashMap::from([
("group".to_string(), _0.quote().to_string())
])))]
InvalidGroup(String),

#[error("invalid group list: {list}", list = .0.quote())]
#[error("{}", get_message_with_args("chroot-error-invalid-group-list", HashMap::from([
("list".to_string(), _0.quote().to_string())
])))]
InvalidGroupList(String),

/// The new root directory was not given.
#[error(
"Missing operand: NEWROOT\nTry '{0} --help' for more information.",
uucore::execution_phrase()
)]
#[error("{}", get_message_with_args("chroot-error-missing-newroot", HashMap::from([
("util_name".to_string(), uucore::execution_phrase().to_string())
])))]
MissingNewRoot,

#[error("no group specified for unknown uid: {0}")]
#[error("{}", get_message_with_args("chroot-error-no-group-specified", HashMap::from([
("uid".to_string(), _0.to_string())
])))]
NoGroupSpecified(libc::uid_t),

/// Failed to find the specified user.
#[error("invalid user")]
#[error("{}", get_message("chroot-error-no-such-user"))]
NoSuchUser,

/// Failed to find the specified group.
#[error("invalid group")]
#[error("{}", get_message("chroot-error-no-such-group"))]
NoSuchGroup,

/// The given directory does not exist.
#[error("cannot change root directory to {dir}: no such directory", dir = .0.quote())]
#[error("{}", get_message_with_args("chroot-error-no-such-directory", HashMap::from([
("dir".to_string(), _0.quote().to_string())
])))]
NoSuchDirectory(String),

/// The call to `setgid()` failed.
#[error("cannot set gid to {gid}: {err}", gid = .0, err = .1)]
#[error("{}", get_message_with_args("chroot-error-set-gid-failed", HashMap::from([
("gid".to_string(), _0.to_string()),
("err".to_string(), _1.to_string())
])))]
SetGidFailed(String, #[source] Error),

/// The call to `setgroups()` failed.
#[error("cannot set groups: {0}")]
#[error("{}", get_message_with_args("chroot-error-set-groups-failed", HashMap::from([
("err".to_string(), _0.to_string())
])))]
SetGroupsFailed(Error),

/// The call to `setuid()` failed.
#[error("cannot set user to {user}: {err}", user = .0.maybe_quote(), err = .1)]
#[error("{}", get_message_with_args("chroot-error-set-user-failed", HashMap::from([
("user".to_string(), _0.maybe_quote().to_string()),
("err".to_string(), _1.to_string())
])))]
SetUserFailed(String, #[source] Error),
}

Expand Down
Loading