Skip to content

Commit b63dee9

Browse files
authored
Sudoedit compliance tests (batch 1) (#1213)
2 parents a38aed6 + a722b1c commit b63dee9

File tree

10 files changed

+444
-10
lines changed

10 files changed

+444
-10
lines changed

src/sudo/edit.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
use std::fs::File;
44
use std::io::{Read, Seek, Write};
55
use std::net::Shutdown;
6-
use std::os::unix::{net::UnixStream, process::ExitStatusExt};
6+
use std::os::unix::{fs::OpenOptionsExt, net::UnixStream, process::ExitStatusExt};
77
use std::path::{Path, PathBuf};
88
use std::process::Command;
99
use std::{io, process};
1010

1111
use crate::common::SudoPath;
1212
use crate::exec::ExitReason;
13+
use crate::log::user_info;
1314
use crate::system::file::{create_temporary_dir, FileLock};
1415
use crate::system::wait::{Wait, WaitError, WaitOptions};
1516
use crate::system::{fork, ForkResult};
@@ -122,6 +123,7 @@ pub(super) fn edit_files(
122123
let data = file.new_data.expect("filled in above");
123124
if data == file.old_data {
124125
// File unchanged. No need to write it again.
126+
user_info!("{} unchanged", file.path.display());
125127
continue;
126128
}
127129

@@ -199,6 +201,7 @@ fn handle_child_inner(editor: &Path, mut files: Vec<ChildFileInfo<'_>>) -> Resul
199201
.read(true)
200202
.write(true)
201203
.create_new(true)
204+
.mode(0o600)
202205
.open(&tempfile_path)
203206
.map_err(|e| {
204207
format!(

test-framework/sudo-compliance-tests/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod macros;
88
mod helpers;
99
mod su;
1010
mod sudo;
11+
mod sudoedit;
1112
mod visudo;
1213

1314
type Error = Box<dyn std::error::Error>;
@@ -46,6 +47,11 @@ const SUDOERS_NOT_USE_PTY: &str = "Defaults !use_pty";
4647

4748
const ENV_PATH: &str = "/usr/bin/env";
4849

50+
#[cfg(not(target_os = "freebsd"))]
51+
const DEFAULT_EDITOR: &str = "/usr/bin/editor";
52+
#[cfg(target_os = "freebsd")]
53+
const DEFAULT_EDITOR: &str = "/usr/bin/vi";
54+
4955
const PANIC_EXIT_CODE: i32 = 101;
5056

5157
enum EnvList {

test-framework/sudo-compliance-tests/src/sudo/child_process/signal_handling/kill-sudo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ for _ in $(seq 1 20); do
44
# when sudo runs with `use_pty` there are two sudo processes as sudo spawns
55
# a monitor process. We want the PID of the sudo process so we assume it
66
# must be the smallest of the returned PIDs.
7-
sudopid=$(pidof sudo | sort -gr | cut -f 1 -d ' ')
7+
sudopid=$(pidof sudo | tr ' ' '\n' | sort -g | head -n1)
88

99
if [ -n "$sudopid" ]; then
1010
# give `expects-signal.sh ` some time to execute the `trap` command

0 commit comments

Comments
 (0)