Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit84d2959

Browse files
committed
install: fix -Z
1 parentb7f3a53 commit84d2959

File tree

4 files changed

+390
-9
lines changed

4 files changed

+390
-9
lines changed

‎src/uu/install/locales/en-US.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ install-help-no-target-directory = treat DEST as a normal file
1818
install-help-verbose =explain what is being done
1919
install-help-preserve-context =preserve security context
2020
install-help-context =set security context of files and directories
21+
install-help-default-context =set SELinux security context of destination file and each created directory to default type
2122
2223
# Error messages
2324
install-error-dir-needs-arg ={$util_name} with -d requires at least one argument.

‎src/uu/install/src/install.rs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ use uucore::mode::get_umask;
2727
use uucore::perms::{Verbosity,VerbosityLevel, wrap_chown};
2828
use uucore::process::{getegid, geteuid};
2929
#[cfg(feature ="selinux")]
30-
use uucore::selinux::{contexts_differ, set_selinux_security_context};
30+
use uucore::selinux::{
31+
contexts_differ, set_selinux_context_for_created_directories, set_selinux_security_context,
32+
};
3133
use uucore::{format_usage, show, show_error, show_if_err};
3234

3335
#[cfg(unix)]
@@ -57,6 +59,7 @@ pub struct Behavior {
5759
no_target_dir:bool,
5860
preserve_context:bool,
5961
context:Option<String>,
62+
default_context:bool,
6063
}
6164

6265
#[derive(Error,Debug)]
@@ -157,6 +160,7 @@ static OPT_NO_TARGET_DIRECTORY: &str = "no-target-directory";
157160
staticOPT_VERBOSE:&str ="verbose";
158161
staticOPT_PRESERVE_CONTEXT:&str ="preserve-context";
159162
staticOPT_CONTEXT:&str ="context";
163+
staticOPT_DEFAULT_CONTEXT:&str ="default-context";
160164

161165
staticARG_FILES:&str ="files";
162166

@@ -290,8 +294,13 @@ pub fn uu_app() -> Command {
290294
.action(ArgAction::SetTrue),
291295
)
292296
.arg(
293-
Arg::new(OPT_CONTEXT)
297+
Arg::new(OPT_DEFAULT_CONTEXT)
294298
.short('Z')
299+
.help(get_message("install-help-default-context"))
300+
.action(ArgAction::SetTrue),
301+
)
302+
.arg(
303+
Arg::new(OPT_CONTEXT)
295304
.long(OPT_CONTEXT)
296305
.help(get_message("install-help-context"))
297306
.value_name("CONTEXT")
@@ -403,6 +412,7 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
403412
};
404413

405414
let context = matches.get_one::<String>(OPT_CONTEXT).cloned();
415+
let default_context = matches.get_flag(OPT_DEFAULT_CONTEXT);
406416

407417
Ok(Behavior{
408418
main_function,
@@ -425,6 +435,7 @@ fn behavior(matches: &ArgMatches) -> UResult<Behavior> {
425435
no_target_dir,
426436
preserve_context: matches.get_flag(OPT_PRESERVE_CONTEXT),
427437
context,
438+
default_context,
428439
})
429440
}
430441

@@ -463,6 +474,13 @@ fn directory(paths: &[String], b: &Behavior) -> UResult<()> {
463474
continue;
464475
}
465476

477+
// Set SELinux context for all created directories if needed
478+
#[cfg(feature ="selinux")]
479+
if b.context.is_some() || b.default_context{
480+
let context =get_context_for_selinux(b);
481+
set_selinux_context_for_created_directories(path_to_create.as_path(), context);
482+
}
483+
466484
if b.verbose{
467485
println!(
468486
"{}",
@@ -487,7 +505,10 @@ fn directory(paths: &[String], b: &Behavior) -> UResult<()> {
487505

488506
// Set SELinux context for directory if needed
489507
#[cfg(feature ="selinux")]
490-
show_if_err!(set_selinux_context(path, b));
508+
if b.context.is_some() || b.default_context{
509+
let context =get_context_for_selinux(b);
510+
show_if_err!(set_selinux_security_context(path, context));
511+
}
491512
}
492513
// If the exit code was set, or show! has been called at least once
493514
// (which sets the exit code as well), function execution will end after
@@ -606,6 +627,13 @@ fn standard(mut paths: Vec<String>, b: &Behavior) -> UResult<()> {
606627
ifletErr(e) = fs::create_dir_all(to_create){
607628
returnErr(InstallError::CreateDirFailed(to_create.to_path_buf(), e).into());
608629
}
630+
631+
// Set SELinux context for all created directories if needed
632+
#[cfg(feature ="selinux")]
633+
if b.context.is_some() || b.default_context{
634+
let context =get_context_for_selinux(b);
635+
set_selinux_context_for_created_directories(to_create, context);
636+
}
609637
}
610638
}
611639
if b.target_dir.is_some(){
@@ -975,8 +1003,10 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> UResult<()> {
9751003
if b.preserve_context{
9761004
uucore::selinux::preserve_security_context(from, to)
9771005
.map_err(|e|InstallError::SelinuxContextFailed(e.to_string()))?;
978-
}elseif b.context.is_some(){
979-
set_selinux_context(to, b)?;
1006+
}elseif b.context.is_some() || b.default_context{
1007+
let context =get_context_for_selinux(b);
1008+
set_selinux_security_context(to, context)
1009+
.map_err(|e|InstallError::SelinuxContextFailed(e.to_string()))?;
9801010
}
9811011

9821012
if b.verbose{
@@ -1005,6 +1035,15 @@ fn copy(from: &Path, to: &Path, b: &Behavior) -> UResult<()> {
10051035
Ok(())
10061036
}
10071037

1038+
#[cfg(feature ="selinux")]
1039+
fnget_context_for_selinux(b:&Behavior) ->Option<&String>{
1040+
if b.default_context{
1041+
None
1042+
}else{
1043+
b.context.as_ref()
1044+
}
1045+
}
1046+
10081047
/// Check if a file needs to be copied due to ownership differences when no explicit group is specified.
10091048
/// Returns true if the destination file's ownership would differ from what it should be after installation.
10101049
fnneeds_copy_for_ownership(to:&Path,to_meta:&fs::Metadata) ->bool{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp