mirror of
https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git
synced 2025-12-28 17:02:19 +01:00
Feature: Allow setting environment variables
This commit is contained in:
parent
d9af15ae5a
commit
1386c1dc4c
3 changed files with 27 additions and 17 deletions
|
|
@ -26,12 +26,14 @@ pub struct Channel {
|
||||||
peer_window_size: u32,
|
peer_window_size: u32,
|
||||||
max_packet_size: u32,
|
max_packet_size: u32,
|
||||||
read_thread: Option<JoinHandle<()>>,
|
read_thread: Option<JoinHandle<()>>,
|
||||||
|
env: Vec<(String, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ChannelRequest {
|
pub enum ChannelRequest {
|
||||||
Pty(PtyConfig),
|
Pty(PtyConfig),
|
||||||
Shell,
|
Shell,
|
||||||
|
Env(String, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Channel {
|
impl Channel {
|
||||||
|
|
@ -52,6 +54,7 @@ impl Channel {
|
||||||
peer_window_size,
|
peer_window_size,
|
||||||
max_packet_size,
|
max_packet_size,
|
||||||
read_thread: None,
|
read_thread: None,
|
||||||
|
env: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -68,11 +71,12 @@ impl Channel {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_request(&mut self, request: ChannelRequest) {
|
pub fn handle_request(&mut self, request: ChannelRequest) {
|
||||||
|
debug!("Channel Request: {:?}", request);
|
||||||
match request {
|
match request {
|
||||||
ChannelRequest::Pty(ref pty) => self.setup_tty(pty),
|
ChannelRequest::Pty(ref pty) => self.setup_tty(pty),
|
||||||
ChannelRequest::Shell => self.setup_shell(),
|
ChannelRequest::Shell => self.setup_shell(),
|
||||||
|
ChannelRequest::Env(key, value) => self.env.push((key, value)),
|
||||||
}
|
}
|
||||||
debug!("Channel Request: {:?}", request);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Writes `data` **to** this channel;
|
/// Writes `data` **to** this channel;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ impl Channel {
|
||||||
match self.pty.as_ref() {
|
match self.pty.as_ref() {
|
||||||
Some((_, tty_path)) => with_tty(tty_path),
|
Some((_, tty_path)) => with_tty(tty_path),
|
||||||
None => {
|
None => {
|
||||||
let pipes = without_tty();
|
let pipes = self.without_tty();
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use crate::sys::non_blockify_reader;
|
use crate::sys::non_blockify_reader;
|
||||||
non_blockify_reader(pipes.stdout.get_ref());
|
non_blockify_reader(pipes.stdout.get_ref());
|
||||||
|
|
@ -30,23 +30,25 @@ impl Channel {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn without_tty() -> PipeContainer {
|
fn without_tty(&mut self) -> PipeContainer {
|
||||||
let proc = unsafe {
|
let proc = unsafe {
|
||||||
process::Command::new("/bin/sh")
|
process::Command::new("/bin/sh")
|
||||||
.stdin(Stdio::piped())
|
// .env_clear()
|
||||||
.stdout(Stdio::piped())
|
.envs(self.env.drain(..))
|
||||||
.stderr(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.pre_exec(sys::before_exec)
|
.stdout(Stdio::piped())
|
||||||
.spawn()
|
.stderr(Stdio::piped())
|
||||||
.unwrap()
|
.pre_exec(sys::before_exec)
|
||||||
};
|
.spawn()
|
||||||
|
.unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
PipeContainer {
|
PipeContainer {
|
||||||
stdin: proc.stdin.unwrap(),
|
stdin: proc.stdin.unwrap(),
|
||||||
stdout: BufReader::with_capacity(1, proc.stdout.unwrap()),
|
stdout: BufReader::with_capacity(1, proc.stdout.unwrap()),
|
||||||
stderr: BufReader::with_capacity(1, proc.stderr.unwrap()),
|
stderr: BufReader::with_capacity(1, proc.stderr.unwrap()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -356,6 +356,10 @@ impl Connection {
|
||||||
modes: reader.read_string()?,
|
modes: reader.read_string()?,
|
||||||
})),
|
})),
|
||||||
"shell" => Some(ChannelRequest::Shell),
|
"shell" => Some(ChannelRequest::Shell),
|
||||||
|
"env" => Some(ChannelRequest::Env(
|
||||||
|
String::from_utf8(reader.read_string()?).unwrap(), // TODO: error handling
|
||||||
|
String::from_utf8(reader.read_string()?).unwrap(),
|
||||||
|
)),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue