mirror of
https://gitlab.redox-os.org/CoffeeCode/redox-ssh.git
synced 2025-12-28 15:22:18 +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,
|
||||
max_packet_size: u32,
|
||||
read_thread: Option<JoinHandle<()>>,
|
||||
env: Vec<(String, String)>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ChannelRequest {
|
||||
Pty(PtyConfig),
|
||||
Shell,
|
||||
Env(String, String),
|
||||
}
|
||||
|
||||
impl Channel {
|
||||
|
|
@ -52,6 +54,7 @@ impl Channel {
|
|||
peer_window_size,
|
||||
max_packet_size,
|
||||
read_thread: None,
|
||||
env: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,11 +71,12 @@ impl Channel {
|
|||
}
|
||||
|
||||
pub fn handle_request(&mut self, request: ChannelRequest) {
|
||||
debug!("Channel Request: {:?}", request);
|
||||
match request {
|
||||
ChannelRequest::Pty(ref pty) => self.setup_tty(pty),
|
||||
ChannelRequest::Shell => self.setup_shell(),
|
||||
ChannelRequest::Env(key, value) => self.env.push((key, value)),
|
||||
}
|
||||
debug!("Channel Request: {:?}", request);
|
||||
}
|
||||
|
||||
/// Writes `data` **to** this channel;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ impl Channel {
|
|||
match self.pty.as_ref() {
|
||||
Some((_, tty_path)) => with_tty(tty_path),
|
||||
None => {
|
||||
let pipes = without_tty();
|
||||
let pipes = self.without_tty();
|
||||
#[cfg(unix)]
|
||||
use crate::sys::non_blockify_reader;
|
||||
non_blockify_reader(pipes.stdout.get_ref());
|
||||
|
|
@ -30,11 +30,12 @@ impl Channel {
|
|||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn without_tty() -> PipeContainer {
|
||||
fn without_tty(&mut self) -> PipeContainer {
|
||||
let proc = unsafe {
|
||||
process::Command::new("/bin/sh")
|
||||
// .env_clear()
|
||||
.envs(self.env.drain(..))
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
|
|
@ -48,6 +49,7 @@ fn without_tty() -> PipeContainer {
|
|||
stdout: BufReader::with_capacity(1, proc.stdout.unwrap()),
|
||||
stderr: BufReader::with_capacity(1, proc.stderr.unwrap()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn with_tty(tty_path: &PathBuf) {
|
||||
|
|
|
|||
|
|
@ -356,6 +356,10 @@ impl Connection {
|
|||
modes: reader.read_string()?,
|
||||
})),
|
||||
"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,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue