|
@ -147,42 +147,6 @@ impl<U: AsRef<str>> CommandRunner for SetuidCommandRunner<U> { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
|
pub struct SuCommandRunner<'a, C>
|
|
|
|
|
|
where
|
|
|
|
|
|
C: CommandRunner,
|
|
|
|
|
|
{
|
|
|
|
|
|
command_runner: &'a C,
|
|
|
|
|
|
user_name: &'a str,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a, C> SuCommandRunner<'a, C>
|
|
|
|
|
|
where
|
|
|
|
|
|
C: 'a + CommandRunner,
|
|
|
|
|
|
{
|
|
|
|
|
|
pub fn new(user_name: &'a str, command_runner: &'a C) -> SuCommandRunner<'a, C> {
|
|
|
|
|
|
SuCommandRunner {
|
|
|
|
|
|
command_runner,
|
|
|
|
|
|
user_name,
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Su doesn't set XDG_RUNTIME_DIR
|
|
|
|
|
|
// https://github.com/systemd/systemd/blob/master/src/login/pam_systemd.c#L439
|
|
|
|
|
|
#[async_trait(?Send)]
|
|
|
|
|
|
impl<'a, C> CommandRunner for SuCommandRunner<'a, C>
|
|
|
|
|
|
where
|
|
|
|
|
|
C: 'a + CommandRunner,
|
|
|
|
|
|
{
|
|
|
|
|
|
async fn run(&self, program: &str, args: &[&OsStr], input: &[u8]) -> IoResult<Output> {
|
|
|
|
|
|
let raw_new_args = [self.user_name, "-s", "/usr/bin/env", "--", program];
|
|
|
|
|
|
let mut new_args: Vec<&OsStr> = raw_new_args.iter().map(AsRef::as_ref).collect();
|
|
|
|
|
|
new_args.extend_from_slice(args);
|
|
|
|
|
|
self.command_runner.run("su", &new_args, input).await
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
#[cfg(test)]
|
|
|
mod test {
|
|
|
mod test {
|
|
|
use crate::args;
|
|
|
use crate::args;
|
|
|