Repository navigation
implemented runuser - #612
mustafaelrasheid wants to merge 7 commits into
Conversation
| .map(|s| s.to_string()) | ||
| .collect::<Vec<_>>() | ||
| .to_vec(); | ||
| let (username, path, command_args) = match matches.get_one::<String>("user") { |
There was a problem hiding this comment.
maybe move this into a function?
There was a problem hiding this comment.
Just to clarify, do you mean the parsing for username, path and command_args or the entirety of the args parsing?
|
I just randomly noticed this PR. I haven't look at the code (and have no comment about it), but I do have a general observation. In util-linux, Now, In particular, it has PTY support (same code paths as those in sudo-rs, and enabled by default even), which would be quite essential for a modern implementation of So we could also open an issue over at sudo-rs to add a |
45a5b66 to
1da4d72
Compare
|
|
||
| if status != 0 { | ||
| return Err(USimpleError::new( | ||
| status + 128, |
There was a problem hiding this comment.
this returns 128+status for a normal non-zero exit, runuser should just propagate the child's code
and code().unwrap_or(0) above turns a signal kill into success, 128+signal is expected there
| let command = match matches.get_one::<String>("session_command") { | ||
| Some(cmd) => cmd, | ||
| None => { | ||
| sep_session()?; |
There was a problem hiding this comment.
setsid() in the parent fails with EPERM when runuser is a process group leader (the usual case from a shell)
shouldn't it be done in the child, via pre_exec?
|
|
||
| #[cfg(target_os = "linux")] | ||
| pub fn set_ids(uid: u32, gid: u32, supp_gids: &Vec<Gid>) -> UResult<()> { | ||
| setgroups(supp_gids.as_slice()) |
There was a problem hiding this comment.
without -G this calls setgroups with an empty list, so the target user loses all its supplementary groups
please use initgroups for the user, and add the -G ones on top
| pub shell: String, | ||
| } | ||
|
|
||
| pub fn get_user_info(username: &str) -> Result<Option<UserEntry>, Box<dyn Error>> { |
There was a problem hiding this comment.
why parse /etc/passwd by hand? this ignores NSS (ldap, sssd...)
nix::unistd::User::from_name / Group::from_name are already available with the features you enabled
| .short('w') | ||
| .long("whitelist-environment") | ||
| .value_name("list") | ||
| .num_args(0..), |
There was a problem hiding this comment.
-w takes a comma-separated list, num_args(0..) will eat the user and the command that follow
please add a test
| } | ||
|
|
||
| #[cfg(target_os = "linux")] | ||
| pub fn get_group_info(groupname: &str) -> Result<Option<u32>, Box<dyn Error>> { |
There was a problem hiding this comment.
please use a thiserror enum instead of Box<dyn Error> + USimpleError everywhere
|
|
||
| if is_login { | ||
| if preserve_env { | ||
| println!("--preserve-environment is ignored in case `--login` is enabled"); |
There was a problem hiding this comment.
this should go to stderr, not stdout
| } | ||
|
|
||
| #[cfg(not(target_os = "linux"))] | ||
| fn unsupported_platform() { |
There was a problem hiding this comment.
missing #[test], so this never runs
also, the tests only cover error paths, could you please add some that actually run a command (skipped when not root)?
I've implemented a basic version of runuser and I feel honored to be able to share it.
This is my first ever contribution and I was a bit hesitant to share it because of how complex the argument parsing was, but it came out well.