Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions src/sudo/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::os::unix::ffi::OsStrExt;
use std::{borrow::Cow, mem};

use crate::common::{SudoPath, SudoString};
use crate::log::user_warn;

pub mod help;
pub mod help_edit;
Expand Down Expand Up @@ -649,8 +650,8 @@ impl SudoOptions {
options.bell = true;
}
"-E" | "--preserve-env" => {
eprintln_ignore_io_error!(
"warning: preserving the entire environment is not supported, `{flag}` is ignored"
user_warn!(
"preserving the entire environment is not supported, `{flag}` is ignored"
)
}
"-e" | "--edit" if !invoked_as_sudoedit => {
Expand Down Expand Up @@ -740,7 +741,7 @@ impl SudoOptions {
&& !is_dir
&& (cmd.ends_with("sudoedit") || cmd.ends_with("sudoedit-rs"))
{
eprintln_ignore_io_error!("sudoedit doesn't need to be run via sudo");
user_warn!("sudoedit doesn't need to be run via sudo");
options.edit = true;
rest.remove(0);
}
Expand Down
28 changes: 14 additions & 14 deletions src/sudo/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{io, process};

use crate::common::SudoPath;
use crate::exec::ExitReason;
use crate::log::user_info;
use crate::log::{user_error, user_info};
use crate::system::file::{create_temporary_dir, FileLock};
use crate::system::wait::{Wait, WaitError, WaitOptions};
use crate::system::{fork, ForkResult};
Expand Down Expand Up @@ -157,8 +157,8 @@ struct TempDirDropGuard(PathBuf);
impl Drop for TempDirDropGuard {
fn drop(&mut self) {
if let Err(e) = std::fs::remove_dir_all(&self.0) {
eprintln_ignore_io_error!(
"Failed to remove temporary directory {}: {e}",
user_error!(
"failed to remove temporary directory {}: {e}",
self.0.display(),
);
};
Expand All @@ -169,7 +169,7 @@ fn handle_child(editor: &Path, file: Vec<ChildFileInfo<'_>>) -> ! {
match handle_child_inner(editor, file) {
Ok(()) => process::exit(0),
Err(err) => {
eprintln_ignore_io_error!("{err}");
user_error!("{err}");
process::exit(1);
}
}
Expand All @@ -184,15 +184,15 @@ fn handle_child_inner(editor: &Path, mut files: Vec<ChildFileInfo<'_>>) -> Resul
}

let tempdir = TempDirDropGuard(
create_temporary_dir().map_err(|e| format!("Failed to create temporary directory: {e}"))?,
create_temporary_dir().map_err(|e| format!("failed to create temporary directory: {e}"))?,
);

for (i, file) in files.iter_mut().enumerate() {
// Create temp file
let dir = tempdir.0.join(format!("{i}"));
std::fs::create_dir(&dir).map_err(|e| {
format!(
"Failed to create temporary directory {}: {e}",
"failed to create temporary directory {}: {e}",
dir.display(),
)
})?;
Expand All @@ -205,15 +205,15 @@ fn handle_child_inner(editor: &Path, mut files: Vec<ChildFileInfo<'_>>) -> Resul
.open(&tempfile_path)
.map_err(|e| {
format!(
"Failed to create temporary file {}: {e}",
"failed to create temporary file {}: {e}",
tempfile_path.display(),
)
})?;

// Write to temp file
tempfile.write_all(&file.old_data).map_err(|e| {
format!(
"Failed to write to temporary file {}: {e}",
"failed to write to temporary file {}: {e}",
tempfile_path.display(),
)
})?;
Expand All @@ -229,7 +229,7 @@ fn handle_child_inner(editor: &Path, mut files: Vec<ChildFileInfo<'_>>) -> Resul
.map(|file| file.tempfile_path.as_ref().expect("filled in above")),
)
.status()
.map_err(|e| format!("Failed to run editor {}: {e}", editor.display()))?;
.map_err(|e| format!("failed to run editor {}: {e}", editor.display()))?;

if !status.success() {
drop(tempdir);
Expand All @@ -246,15 +246,15 @@ fn handle_child_inner(editor: &Path, mut files: Vec<ChildFileInfo<'_>>) -> Resul
// Read from temp file
let new_data = std::fs::read(tempfile_path).map_err(|e| {
format!(
"Failed to read from temporary file {}: {e}",
"failed to read from temporary file {}: {e}",
tempfile_path.display(),
)
})?;

// FIXME preserve temporary file if the original couldn't be written to
std::fs::remove_file(tempfile_path).map_err(|e| {
format!(
"Failed to remove temporary file {}: {e}",
"failed to remove temporary file {}: {e}",
tempfile_path.display(),
)
})?;
Expand All @@ -271,11 +271,11 @@ fn handle_child_inner(editor: &Path, mut files: Vec<ChildFileInfo<'_>>) -> Resul
) {
Ok(b'y') => {}
_ => {
eprintln_ignore_io_error!("Not overwriting {}", file.path.display());
user_info!("not overwriting {}", file.path.display());

// Parent ignores write when new data matches old data
write_stream(&mut file.new_data_tx, &file.old_data)
.map_err(|e| format!("Failed to write data to parent: {e}"))?;
.map_err(|e| format!("failed to write data to parent: {e}"))?;

continue;
}
Expand All @@ -284,7 +284,7 @@ fn handle_child_inner(editor: &Path, mut files: Vec<ChildFileInfo<'_>>) -> Resul

// Write to socket
write_stream(&mut file.new_data_tx, &new_data)
.map_err(|e| format!("Failed to write data to parent: {e}"))?;
.map_err(|e| format!("failed to write data to parent: {e}"))?;
}

process::exit(0);
Expand Down
4 changes: 2 additions & 2 deletions src/sudoers/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ impl Parse for MetaOrTag {
// this is less fatal
"LOG_INPUT" | "NOLOG_INPUT" | "LOG_OUTPUT" | "NOLOG_OUTPUT" | "MAIL" | "NOMAIL"
| "FOLLOW" => {
eprintln_ignore_io_error!(
"warning: {} tags are ignored by sudo-rs",
crate::log::user_warn!(
"{} tags in the sudoers policy are ignored by sudo-rs",
keyword.as_str()
);
switch(|_| {})?
Expand Down
2 changes: 1 addition & 1 deletion test-framework/sudo-compliance-tests/src/sudoedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ rm $1",
if sudo_test::is_original_sudo() {
assert_contains!(stderr, format!("sudoedit: {ETC_SUDOERS} left unmodified"));
} else {
assert_contains!(stderr, format!("Failed to read from temporary file"));
assert_contains!(stderr, format!("sudo: failed to read from temporary file"));
}
}

Expand Down