diff --git a/russh/examples/test.rs b/russh/examples/test.rs new file mode 100644 index 00000000..5e8ce6cd --- /dev/null +++ b/russh/examples/test.rs @@ -0,0 +1,99 @@ +use async_trait::async_trait; +use env_logger; +use log::debug; +use russh::server::{Auth, Msg, Session}; +use russh::*; +use russh_keys::*; +use std::collections::HashMap; +use std::sync::{Arc, Mutex}; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + env_logger::init(); + let mut config = russh::server::Config::default(); + config.auth_rejection_time = std::time::Duration::from_secs(3); + config + .keys + .push(russh_keys::key::KeyPair::generate_ed25519().unwrap()); + let config = Arc::new(config); + let sh = Server { + clients: Arc::new(Mutex::new(HashMap::new())), + id: 0, + }; + tokio::time::timeout( + std::time::Duration::from_secs(60), + russh::server::run(config, ("0.0.0.0", 2222), sh), + ) + .await + .unwrap_or(Ok(()))?; + + Ok(()) +} + +#[derive(Clone)] +struct Server { + clients: Arc>>>, + id: usize, +} + +impl server::Server for Server { + type Handler = Self; + fn new_client(&mut self, _: Option) -> Self { + debug!("new client"); + let s = self.clone(); + self.id += 1; + s + } +} + +#[async_trait] +impl server::Handler for Server { + type Error = anyhow::Error; + + async fn channel_open_session( + self, + channel: Channel, + session: Session, + ) -> Result<(Self, bool, Session), Self::Error> { + { + debug!("channel open session"); + let mut clients = self.clients.lock().unwrap(); + clients.insert((self.id, channel.id()), channel); + } + Ok((self, true, session)) + } + + /// The client requests a shell. + #[allow(unused_variables)] + async fn shell_request( + self, + channel: ChannelId, + mut session: Session, + ) -> Result<(Self, Session), Self::Error> { + session.request_success(); + Ok((self, session)) + } + + async fn auth_publickey( + self, + _: &str, + _: &key::PublicKey, + ) -> Result<(Self, Auth), Self::Error> { + Ok((self, server::Auth::Accept)) + } + async fn data( + self, + _channel: ChannelId, + data: &[u8], + mut session: Session, + ) -> Result<(Self, Session), Self::Error> { + debug!("data: {data:?}"); + { + let mut clients = self.clients.lock().unwrap(); + for ((_, _channel_id), ref mut channel) in clients.iter_mut() { + session.data(channel.id(), CryptoVec::from(data.to_vec())); + } + } + Ok((self, session)) + } +} diff --git a/russh/src/client/encrypted.rs b/russh/src/client/encrypted.rs index 8d34de88..cc7df2b4 100644 --- a/russh/src/client/encrypted.rs +++ b/russh/src/client/encrypted.rs @@ -15,18 +15,20 @@ use std::cell::RefCell; use std::convert::TryInto; +use log::{debug, error, info, trace, warn}; use russh_cryptovec::CryptoVec; use russh_keys::encoding::{Encoding, Reader}; use russh_keys::key::parse_public_key; use tokio::sync::mpsc::unbounded_channel; -use log::{debug, error, info, trace, warn}; use crate::client::{Handler, Msg, Prompt, Reply, Session}; use crate::key::PubKey; use crate::negotiation::{Named, Select}; use crate::parsing::{ChannelOpenConfirmation, ChannelType, OpenChannelMessage}; use crate::session::{Encrypted, EncryptedState, Kex, KexInit}; -use crate::{auth, msg, negotiation, Channel, ChannelId, ChannelOpenFailure, ChannelParams, Sig}; +use crate::{ + auth, msg, negotiation, Channel, ChannelId, ChannelMsg, ChannelOpenFailure, ChannelParams, Sig, +}; thread_local! { static SIGNATURE_BUFFER: RefCell = RefCell::new(CryptoVec::new()); @@ -184,7 +186,6 @@ impl Session { current: None, rejection_count: 0, }, - }; let len = enc.write.len(); #[allow(clippy::indexing_slicing)] // length checked @@ -246,7 +247,6 @@ impl Session { if no_more_methods { return Err(crate::Error::NoAuthMethod.into()); } - } else if buf.first() == Some(&msg::USERAUTH_INFO_REQUEST_OR_USERAUTH_PK_OK) { if let Some(auth::CurrentRequest::PublicKey { ref mut sent_pk_ok, .. @@ -254,7 +254,7 @@ impl Session { { debug!("userauth_pk_ok"); *sent_pk_ok = true; - } else if let Some(auth::CurrentRequest::KeyboardInteractive { .. }) = + } else if let Some(auth::CurrentRequest::KeyboardInteractive { .. }) = auth_request.current { debug!("keyboard_interactive"); @@ -307,7 +307,8 @@ impl Session { // write responses enc.client_send_auth_response(&responses)?; return Ok((client, self)); - } else {} + } else { + } // continue with userauth_pk_ok match self.common.auth_method.take() { @@ -396,6 +397,18 @@ impl Session { return Err(crate::Error::Inconsistent.into()); }; + if let Some(channel) = self.channels.get(&local_id) { + channel + .send(ChannelMsg::Open { + id: local_id, + max_packet_size: msg.maximum_packet_size, + window_size: msg.initial_window_size, + }) + .unwrap_or(()); + } else { + error!("no channel for id {local_id:?}"); + } + client .channel_open_confirmation( local_id, @@ -414,12 +427,16 @@ impl Session { // will not be released. enc.close(channel_num); } + self.channels.remove(&channel_num); client.channel_close(channel_num, self).await } Some(&msg::CHANNEL_EOF) => { debug!("channel_eof"); let mut r = buf.reader(1); let channel_num = ChannelId(r.read_u32().map_err(crate::Error::from)?); + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::Eof); + } client.channel_eof(channel_num, self).await } Some(&msg::CHANNEL_OPEN_FAILURE) => { @@ -436,6 +453,13 @@ impl Session { if let Some(ref mut enc) = self.common.encrypted { enc.channels.remove(&channel_num); } + + if let Some(sender) = self.channels.remove(&channel_num) { + let _ = sender.send(ChannelMsg::OpenFailure(reason_code)); + } + + let _ = self.sender.send(Reply::ChannelOpenFailure); + client .channel_open_failure(channel_num, reason_code, descr, language, self) .await @@ -455,6 +479,13 @@ impl Session { } } } + + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::Data { + data: CryptoVec::from_slice(data), + }); + } + client.data(channel_num, data, self).await } Some(&msg::CHANNEL_EXTENDED_DATA) => { @@ -473,6 +504,14 @@ impl Session { } } } + + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::ExtendedData { + ext: extended_code, + data: CryptoVec::from_slice(data), + }); + } + client .extended_data(channel_num, extended_code, data, self) .await @@ -489,30 +528,44 @@ impl Session { match req { b"xon-xoff" => { r.read_byte().map_err(crate::Error::from)?; // should be 0. - let client_can_do = r.read_byte().map_err(crate::Error::from)?; - client.xon_xoff(channel_num, client_can_do != 0, self).await + let client_can_do = r.read_byte().map_err(crate::Error::from)? != 0; + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::XonXoff { client_can_do }); + } + client.xon_xoff(channel_num, client_can_do, self).await } b"exit-status" => { r.read_byte().map_err(crate::Error::from)?; // should be 0. let exit_status = r.read_u32().map_err(crate::Error::from)?; + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::ExitStatus { exit_status }); + } client.exit_status(channel_num, exit_status, self).await } b"exit-signal" => { r.read_byte().map_err(crate::Error::from)?; // should be 0. let signal_name = Sig::from_name(r.read_string().map_err(crate::Error::from)?)?; - let core_dumped = r.read_byte().map_err(crate::Error::from)?; + let core_dumped = r.read_byte().map_err(crate::Error::from)? != 0; let error_message = std::str::from_utf8(r.read_string().map_err(crate::Error::from)?) .map_err(crate::Error::from)?; let lang_tag = std::str::from_utf8(r.read_string().map_err(crate::Error::from)?) .map_err(crate::Error::from)?; + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::ExitSignal { + signal_name: signal_name.clone(), + core_dumped, + error_message: error_message.to_string(), + lang_tag: lang_tag.to_string(), + }); + } client .exit_signal( channel_num, signal_name, - core_dumped != 0, + core_dumped, error_message, lang_tag, self, @@ -563,17 +616,24 @@ impl Session { let mut r = buf.reader(1); let channel_num = ChannelId(r.read_u32().map_err(crate::Error::from)?); let amount = r.read_u32().map_err(crate::Error::from)?; - let mut new_value = 0; + let mut new_size = 0; debug!("amount: {:?}", amount); if let Some(ref mut enc) = self.common.encrypted { if let Some(ref mut channel) = enc.channels.get_mut(&channel_num) { channel.recipient_window_size += amount; - new_value = channel.recipient_window_size; + new_size = channel.recipient_window_size; } else { return Err(crate::Error::WrongChannel.into()); } } - client.window_adjusted(channel_num, new_value, self).await + + if let Some(ref mut enc) = self.common.encrypted { + new_size -= enc.flush_pending(channel_num) as u32; + } + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::WindowAdjusted { new_size }); + } + client.window_adjusted(channel_num, new_size, self).await } Some(&msg::GLOBAL_REQUEST) => { let mut r = buf.reader(1); @@ -634,11 +694,17 @@ impl Session { Some(&msg::CHANNEL_SUCCESS) => { let mut r = buf.reader(1); let channel_num = ChannelId(r.read_u32().map_err(crate::Error::from)?); + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::Success); + } client.channel_success(channel_num, self).await } Some(&msg::CHANNEL_FAILURE) => { let mut r = buf.reader(1); let channel_num = ChannelId(r.read_u32().map_err(crate::Error::from)?); + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::Failure); + } client.channel_failure(channel_num, self).await } Some(&msg::CHANNEL_OPEN) => { @@ -891,10 +957,7 @@ impl Encrypted { Ok(()) } - fn client_send_auth_response( - &mut self, - responses: &[String] - ) -> Result<(), crate::Error> { + fn client_send_auth_response(&mut self, responses: &[String]) -> Result<(), crate::Error> { push_packet!(self.write, { self.write.push(msg::USERAUTH_INFO_RESPONSE); self.write diff --git a/russh/src/client/mod.rs b/russh/src/client/mod.rs index 842f2a5d..f812cad0 100644 --- a/russh/src/client/mod.rs +++ b/russh/src/client/mod.rs @@ -83,6 +83,7 @@ use std::sync::Arc; use async_trait::async_trait; use futures::task::{Context, Poll}; use futures::Future; +use log::{debug, error, info, trace}; use russh_cryptovec::CryptoVec; use russh_keys::encoding::Reader; #[cfg(feature = "openssl")] @@ -95,7 +96,6 @@ use tokio::pin; use tokio::sync::mpsc::{ channel, unbounded_channel, Receiver, Sender, UnboundedReceiver, UnboundedSender, }; -use log::{debug, error, info, trace}; use crate::channels::{Channel, ChannelMsg}; use crate::cipher::{self, clear, CipherPair, OpeningKey}; @@ -109,7 +109,6 @@ mod encrypted; mod kex; mod session; - /// Actual client session's state. /// /// It is in charge of multiplexing and keeping track of various channels @@ -133,7 +132,6 @@ impl Drop for Session { } } - #[derive(Debug)] #[allow(clippy::large_enum_variant)] enum Reply { @@ -220,7 +218,6 @@ pub enum KeyboardInteractiveAuthResponse { }, } - #[derive(Debug)] pub struct Prompt { pub prompt: String, @@ -306,7 +303,7 @@ impl Handle { } /// Respond to AuthInfoRequests from the server. A server can send any number of these Requests - /// including empty requests. You may have to call this function multple times in order to + /// including empty requests. You may have to call this function multple times in order to /// complete Keyboard-Interactive based SSH authentication. /// /// * `responses` - The responses to each prompt. The number of responses must match the number @@ -339,8 +336,8 @@ impl Handle { instructions, prompts, }); - }, - _ => {}, + } + _ => {} } } } @@ -894,9 +891,7 @@ impl Session { socket_path, sender, } => { - let id = self.channel_open_direct_streamlocal( - &socket_path, - )?; + let id = self.channel_open_direct_streamlocal(&socket_path)?; self.channels.insert(id, sender); } Msg::TcpIpForward { @@ -993,9 +988,7 @@ impl Session { Msg::Channel(id, ChannelMsg::AgentForward { want_reply }) => { self.agent_forward(id, want_reply) } - Msg::Channel(id, ChannelMsg::Close) => { - self.close(id) - } + Msg::Channel(id, ChannelMsg::Close) => self.close(id), msg => { // should be unreachable, since the receiver only gets // messages from methods implemented within russh @@ -1316,17 +1309,6 @@ pub trait Handler: Sized + Send { window_size: u32, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(channel) = session.channels.get(&id) { - channel - .send(ChannelMsg::Open { - id, - max_packet_size, - window_size, - }) - .unwrap_or(()); - } else { - error!("no channel for id {:?}", id); - } Ok((self, session)) } @@ -1337,9 +1319,6 @@ pub trait Handler: Sized + Send { channel: ChannelId, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::Success).unwrap_or(()) - } Ok((self, session)) } @@ -1350,9 +1329,6 @@ pub trait Handler: Sized + Send { channel: ChannelId, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::Failure).unwrap_or(()) - } Ok((self, session)) } @@ -1363,7 +1339,6 @@ pub trait Handler: Sized + Send { channel: ChannelId, mut session: Session, ) -> Result<(Self, Session), Self::Error> { - session.channels.remove(&channel); Ok((self, session)) } @@ -1374,9 +1349,6 @@ pub trait Handler: Sized + Send { channel: ChannelId, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::Eof).unwrap_or(()) - } Ok((self, session)) } @@ -1390,10 +1362,6 @@ pub trait Handler: Sized + Send { language: &str, mut session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(sender) = session.channels.remove(&channel) { - let _ = sender.send(ChannelMsg::OpenFailure(reason)); - } - session.sender.send(Reply::ChannelOpenFailure).unwrap_or(()); Ok((self, session)) } @@ -1476,12 +1444,6 @@ pub trait Handler: Sized + Send { data: &[u8], session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::Data { - data: CryptoVec::from_slice(data), - }) - .unwrap_or(()) - } Ok((self, session)) } @@ -1497,13 +1459,6 @@ pub trait Handler: Sized + Send { data: &[u8], session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::ExtendedData { - ext, - data: CryptoVec::from_slice(data), - }) - .unwrap_or(()) - } Ok((self, session)) } @@ -1517,10 +1472,6 @@ pub trait Handler: Sized + Send { client_can_do: bool, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::XonXoff { client_can_do }) - .unwrap_or(()) - } Ok((self, session)) } @@ -1532,10 +1483,6 @@ pub trait Handler: Sized + Send { exit_status: u32, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::ExitStatus { exit_status }) - .unwrap_or(()) - } Ok((self, session)) } @@ -1550,15 +1497,6 @@ pub trait Handler: Sized + Send { lang_tag: &str, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::ExitSignal { - signal_name, - core_dumped, - error_message: error_message.to_string(), - lang_tag: lang_tag.to_string(), - }) - .unwrap_or(()) - } Ok((self, session)) } @@ -1571,16 +1509,9 @@ pub trait Handler: Sized + Send { async fn window_adjusted( self, channel: ChannelId, - mut new_size: u32, - mut session: Session, + new_size: u32, + session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(ref mut enc) = session.common.encrypted { - new_size -= enc.flush_pending(channel) as u32; - } - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::WindowAdjusted { new_size }) - .unwrap_or(()) - } Ok((self, session)) } diff --git a/russh/src/server/encrypted.rs b/russh/src/server/encrypted.rs index a550c91f..ba6dd9b6 100644 --- a/russh/src/server/encrypted.rs +++ b/russh/src/server/encrypted.rs @@ -611,6 +611,9 @@ impl Session { Some(&msg::CHANNEL_EOF) => { let mut r = buf.reader(1); let channel_num = ChannelId(r.read_u32().map_err(crate::Error::from)?); + if let Some(chan) = self.channels.get(&channel_num) { + chan.send(ChannelMsg::Eof).unwrap_or(()) + } debug!("handler.channel_eof {:?}", channel_num); handler.channel_eof(channel_num, self).await } @@ -637,8 +640,21 @@ impl Session { } self.flush()?; if let Some(ext) = ext { + if let Some(chan) = self.channels.get(&channel_num) { + chan.send(ChannelMsg::ExtendedData { + ext, + data: CryptoVec::from_slice(data), + }) + .unwrap_or(()) + } handler.extended_data(channel_num, ext, data, self).await } else { + if let Some(chan) = self.channels.get(&channel_num) { + chan.send(ChannelMsg::Data { + data: CryptoVec::from_slice(data), + }) + .unwrap_or(()) + } handler.data(channel_num, data, self).await } } @@ -647,17 +663,24 @@ impl Session { let mut r = buf.reader(1); let channel_num = ChannelId(r.read_u32().map_err(crate::Error::from)?); let amount = r.read_u32().map_err(crate::Error::from)?; - let mut new_value = 0; + let mut new_size = 0; if let Some(ref mut enc) = self.common.encrypted { if let Some(channel) = enc.channels.get_mut(&channel_num) { channel.recipient_window_size += amount; - new_value = channel.recipient_window_size; + new_size = channel.recipient_window_size; } else { return Err(Error::WrongChannel.into()); } } + if let Some(ref mut enc) = self.common.encrypted { + enc.flush_pending(channel_num); + } + if let Some(chan) = self.channels.get(&channel_num) { + chan.send(ChannelMsg::WindowAdjusted { new_size }) + .unwrap_or(()) + } debug!("handler.window_adjusted {:?}", channel_num); - handler.window_adjusted(channel_num, new_value, self).await + handler.window_adjusted(channel_num, new_size, self).await } Some(&msg::CHANNEL_OPEN_CONFIRMATION) => { @@ -677,6 +700,17 @@ impl Session { return Err(Error::Inconsistent.into()); }; + if let Some(channel) = self.channels.get(&local_id) { + channel + .send(ChannelMsg::Open { + id: local_id, + max_packet_size: msg.maximum_packet_size, + window_size: msg.initial_window_size, + }) + .unwrap_or(()); + } else { + error!("no channel for id {:?}", local_id); + } handler .channel_open_confirmation( local_id, @@ -732,6 +766,19 @@ impl Session { i += 1 } } + + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::RequestPty { + want_reply: true, + term: term.into(), + col_width, + row_height, + pix_width, + pix_height, + terminal_modes: modes.into(), + }); + } + debug!("handler.pty_request {:?}", channel_num); #[allow(clippy::indexing_slicing)] // `modes` length checked handler @@ -756,6 +803,16 @@ impl Session { std::str::from_utf8(r.read_string().map_err(crate::Error::from)?) .map_err(crate::Error::from)?; let x11_screen_number = r.read_u32().map_err(crate::Error::from)?; + + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::RequestX11 { + want_reply: true, + single_connection, + x11_authentication_cookie: x11_auth_cookie.into(), + x11_authentication_protocol: x11_auth_protocol.into(), + x11_screen_number, + }); + } debug!("handler.x11_request {:?}", channel_num); handler .x11_request( @@ -775,16 +832,31 @@ impl Session { let env_value = std::str::from_utf8(r.read_string().map_err(crate::Error::from)?) .map_err(crate::Error::from)?; + + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::SetEnv { + want_reply: true, + variable_name: env_variable.into(), + variable_value: env_value.into(), + }); + } + debug!("handler.env_request {:?}", channel_num); handler .env_request(channel_num, env_variable, env_value, self) .await } b"shell" => { + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::RequestShell { want_reply: true }); + } debug!("handler.shell_request {:?}", channel_num); handler.shell_request(channel_num, self).await } b"auth-agent-req@openssh.com" => { + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::AgentForward { want_reply: true }); + } debug!("handler.agent_request {:?}", channel_num); let response; (handler, response, self) = @@ -798,6 +870,12 @@ impl Session { } b"exec" => { let req = r.read_string().map_err(crate::Error::from)?; + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::Exec { + want_reply: true, + command: req.into(), + }); + } debug!("handler.exec_request {:?}", channel_num); handler.exec_request(channel_num, req, self).await } @@ -805,6 +883,13 @@ impl Session { let name = std::str::from_utf8(r.read_string().map_err(crate::Error::from)?) .map_err(crate::Error::from)?; + + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::RequestSubsystem { + want_reply: true, + name: name.into(), + }); + } debug!("handler.subsystem_request {:?}", channel_num); handler.subsystem_request(channel_num, name, self).await } @@ -813,6 +898,16 @@ impl Session { let row_height = r.read_u32().map_err(crate::Error::from)?; let pix_width = r.read_u32().map_err(crate::Error::from)?; let pix_height = r.read_u32().map_err(crate::Error::from)?; + + if let Some(chan) = self.channels.get(&channel_num) { + let _ = chan.send(ChannelMsg::WindowChange { + col_width, + row_height, + pix_width, + pix_height, + }); + } + debug!("handler.window_change {:?}", channel_num); handler .window_change_request( @@ -826,10 +921,15 @@ impl Session { .await } b"signal" => { - let signal_name = - Sig::from_name(r.read_string().map_err(crate::Error::from)?)?; - debug!("handler.signal {:?} {:?}", channel_num, signal_name); - handler.signal(channel_num, signal_name, self).await + let signal = Sig::from_name(r.read_string().map_err(crate::Error::from)?)?; + if let Some(chan) = self.channels.get(&channel_num) { + chan.send(ChannelMsg::Signal { + signal: signal.clone(), + }) + .unwrap_or(()) + } + debug!("handler.signal {:?} {:?}", channel_num, signal); + handler.signal(channel_num, signal, self).await } x => { warn!("unknown channel request {}", String::from_utf8_lossy(x)); diff --git a/russh/src/server/mod.rs b/russh/src/server/mod.rs index 9d632a19..e6754361 100644 --- a/russh/src/server/mod.rs +++ b/russh/src/server/mod.rs @@ -340,9 +340,6 @@ pub trait Handler: Sized { channel: ChannelId, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::Eof).unwrap_or(()) - } Ok((self, session)) } @@ -411,17 +408,6 @@ pub trait Handler: Sized { window_size: u32, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(channel) = session.channels.get(&id) { - channel - .send(ChannelMsg::Open { - id, - max_packet_size, - window_size, - }) - .unwrap_or(()); - } else { - error!("no channel for id {:?}", id); - } Ok((self, session)) } @@ -434,12 +420,6 @@ pub trait Handler: Sized { data: &[u8], session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::Data { - data: CryptoVec::from_slice(data), - }) - .unwrap_or(()) - } Ok((self, session)) } @@ -455,13 +435,6 @@ pub trait Handler: Sized { data: &[u8], session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::ExtendedData { - ext: code, - data: CryptoVec::from_slice(data), - }) - .unwrap_or(()) - } Ok((self, session)) } @@ -472,15 +445,8 @@ pub trait Handler: Sized { self, channel: ChannelId, new_size: u32, - mut session: Session, + session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(ref mut enc) = session.common.encrypted { - enc.flush_pending(channel); - } - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::WindowAdjusted { new_size }) - .unwrap_or(()) - } Ok((self, session)) } @@ -505,18 +471,6 @@ pub trait Handler: Sized { modes: &[(Pty, u32)], session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::RequestPty { - want_reply: true, - term: term.into(), - col_width, - row_height, - pix_width, - pix_height, - terminal_modes: modes.into(), - }) - .unwrap_or(()) - } Ok((self, session)) } @@ -531,16 +485,6 @@ pub trait Handler: Sized { x11_screen_number: u32, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::RequestX11 { - want_reply: true, - single_connection, - x11_authentication_cookie: x11_auth_cookie.into(), - x11_authentication_protocol: x11_auth_protocol.into(), - x11_screen_number, - }) - .unwrap_or(()) - } Ok((self, session)) } @@ -555,14 +499,6 @@ pub trait Handler: Sized { variable_value: &str, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::SetEnv { - want_reply: true, - variable_name: variable_name.into(), - variable_value: variable_value.into(), - }) - .unwrap_or(()) - } Ok((self, session)) } @@ -573,10 +509,6 @@ pub trait Handler: Sized { channel: ChannelId, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::RequestShell { want_reply: true }) - .unwrap_or(()) - } Ok((self, session)) } @@ -589,13 +521,6 @@ pub trait Handler: Sized { data: &[u8], session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::Exec { - want_reply: true, - command: data.into(), - }) - .unwrap_or(()) - } Ok((self, session)) } @@ -608,13 +533,6 @@ pub trait Handler: Sized { name: &str, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::RequestSubsystem { - want_reply: true, - name: name.into(), - }) - .unwrap_or(()) - } Ok((self, session)) } @@ -629,15 +547,6 @@ pub trait Handler: Sized { pix_height: u32, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::WindowChange { - col_width, - row_height, - pix_width, - pix_height, - }) - .unwrap_or(()) - } Ok((self, session)) } @@ -648,10 +557,6 @@ pub trait Handler: Sized { channel: ChannelId, session: Session, ) -> Result<(Self, bool, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::AgentForward { want_reply: true }) - .unwrap_or(()) - } Ok((self, false, session)) } @@ -664,9 +569,6 @@ pub trait Handler: Sized { signal: Sig, session: Session, ) -> Result<(Self, Session), Self::Error> { - if let Some(chan) = session.channels.get(&channel) { - chan.send(ChannelMsg::Signal { signal }).unwrap_or(()) - } Ok((self, session)) } @@ -682,6 +584,7 @@ pub trait Handler: Sized { ) -> Result<(Self, bool, Session), Self::Error> { Ok((self, false, session)) } + /// Used to stop the reverse-forwarding of a port, see /// [RFC4254](https://tools.ietf.org/html/rfc4254#section-7). #[allow(unused_variables)]