1
0
Fork 0
mirror of https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git synced 2025-12-28 15:02:18 +01:00

Feature: Specification of executable (exec channel request)

This commit is contained in:
Laurenz 2024-10-08 10:58:22 +02:00
parent 1386c1dc4c
commit 0ceefb1eca
Signed by: C0ffeeCode
SSH key fingerprint: SHA256:jnEltBNftC3wUZESLSMvM9zVPOkkevGRzqqoW2k2ORI
3 changed files with 25 additions and 6 deletions

View file

@ -27,6 +27,7 @@ pub struct Channel {
max_packet_size: u32,
read_thread: Option<JoinHandle<()>>,
env: Vec<(String, String)>,
executable: String,
}
#[derive(Debug)]
@ -34,6 +35,7 @@ pub enum ChannelRequest {
Pty(PtyConfig),
Shell,
Env(String, String),
Exec(String),
}
impl Channel {
@ -55,6 +57,7 @@ impl Channel {
max_packet_size,
read_thread: None,
env: Vec::new(),
executable: "/bin/sh".to_string(),
}
}
@ -76,6 +79,10 @@ impl Channel {
ChannelRequest::Pty(ref pty) => self.setup_tty(pty),
ChannelRequest::Shell => self.setup_shell(),
ChannelRequest::Env(key, value) => self.env.push((key, value)),
ChannelRequest::Exec(executable) => {
self.executable = executable;
self.setup_shell();
}
}
}
@ -84,10 +91,12 @@ impl Channel {
if let Some(ref mut master) = self.master {
master.write_all(data)?;
master.flush()
} else if let Some(PipeContainer { ref mut stdin, .. }) = self.pipes {
}
else if let Some(PipeContainer { ref mut stdin, .. }) = self.pipes {
stdin.write_all(data)?;
stdin.flush()
} else {
}
else {
Ok(())
}
}
@ -96,7 +105,8 @@ impl Channel {
pub fn read_pty_master(&mut self, buf: &mut [u8]) -> io::Result<usize> {
if let Some(ref mut master) = self.master {
master.read(buf)
} else {
}
else {
Ok(0)
}
}
@ -106,7 +116,8 @@ impl Channel {
if let Some(pipes) = &mut self.pipes {
let res_len = pipes.stdout.read_line(buf);
res_len
} else {
}
else {
Ok(0)
}
}
@ -115,7 +126,8 @@ impl Channel {
if let Some(pipes) = &mut self.pipes {
let res_len = pipes.stderr.read_line(buf);
res_len
} else {
}
else {
Ok(0)
}
}

View file

@ -32,9 +32,15 @@ impl Channel {
}
fn without_tty(&mut self) -> PipeContainer {
let mut args = self.executable.split_ascii_whitespace();
let exec = args.next().expect("Failed to get executable from args.");
info!("Executable {exec}, args: {args:?}");
let proc = unsafe {
process::Command::new("/bin/sh")
process::Command::new(exec)
// .env_clear()
.args(args)
.envs(self.env.drain(..))
.stdin(Stdio::piped())
.stdout(Stdio::piped())

View file

@ -360,6 +360,7 @@ impl Connection {
String::from_utf8(reader.read_string()?).unwrap(), // TODO: error handling
String::from_utf8(reader.read_string()?).unwrap(),
)),
"exec" => Some(ChannelRequest::Exec(String::from_utf8(reader.read_string()?).unwrap())),
_ => None,
};