From 89d26002e791df95f4009ec3fe267ac002cbad5d Mon Sep 17 00:00:00 2001 From: Eugene Date: Sun, 4 Aug 2024 10:39:32 +0200 Subject: [PATCH] fixes & cleanup --- russh/src/client/encrypted.rs | 16 +----- russh/src/client/mod.rs | 8 +-- russh/src/client/session.rs | 8 +-- russh/src/parsing.rs | 2 +- russh/src/server/encrypted.rs | 28 +--------- russh/src/server/session.rs | 102 ---------------------------------- russh/src/session.rs | 3 +- 7 files changed, 15 insertions(+), 152 deletions(-) diff --git a/russh/src/client/encrypted.rs b/russh/src/client/encrypted.rs index 20de6a4..ea8b782 100644 --- a/russh/src/client/encrypted.rs +++ b/russh/src/client/encrypted.rs @@ -860,19 +860,7 @@ impl Session { let _ = return_channel.send(true); } Some(GlobalRequestResponse::StreamLocalForward(return_channel)) => { - let mut r = buf.reader(1); - let socket_path: Option = match r.read_string() { - Ok(socket_path) => Some( - std::str::from_utf8(socket_path) - .map_err(crate::Error::from)? - .into(), - ), - Err(e) => { - error!("Error parsing socket path for StreamLocalForward request: {e:?}"); - None - } - }; - let _ = return_channel.send(socket_path); + let _ = return_channel.send(true); } Some(GlobalRequestResponse::CancelStreamLocalForward(return_channel)) => { let _ = return_channel.send(true); @@ -896,7 +884,7 @@ impl Session { let _ = return_channel.send(false); } Some(GlobalRequestResponse::StreamLocalForward(return_channel)) => { - let _ = return_channel.send(None); + let _ = return_channel.send(false); } Some(GlobalRequestResponse::CancelStreamLocalForward(return_channel)) => { let _ = return_channel.send(false); diff --git a/russh/src/client/mod.rs b/russh/src/client/mod.rs index 09be265..447ca04 100644 --- a/russh/src/client/mod.rs +++ b/russh/src/client/mod.rs @@ -162,7 +162,7 @@ pub enum Msg { }, StreamLocalForward { /// Provide a channel for the reply result to request a reply from the server - reply_channel: Option>>, + reply_channel: Option>, socket_path: String, }, CancelStreamLocalForward { @@ -611,7 +611,7 @@ impl Handle { pub async fn streamlocal_forward>( &mut self, socket_path: A, - ) -> Result { + ) -> Result<(), crate::Error> { let (reply_send, reply_recv) = oneshot::channel(); self.sender .send(Msg::StreamLocalForward { @@ -622,8 +622,8 @@ impl Handle { .map_err(|_| crate::Error::SendError)?; match reply_recv.await { - Ok(Some(returned_socket_path)) => Ok(returned_socket_path), - Ok(None) => Err(crate::Error::RequestDenied), + Ok(true) => Ok(()), + Ok(false) => Err(crate::Error::RequestDenied), Err(e) => { error!("Unable to receive StreamLocalForward result: {e:?}"); Err(crate::Error::Disconnect) diff --git a/russh/src/client/session.rs b/russh/src/client/session.rs index 12da6ab..26f8a76 100644 --- a/russh/src/client/session.rs +++ b/russh/src/client/session.rs @@ -293,7 +293,7 @@ impl Session { /// Requests cancellation of TCP/IP forwarding from the server /// - /// If `want_reply` is `true`, returns a oneshot receiving the server's reply: + /// If `reply_channel` is not None, sets want_reply and returns the server's response via the channel, /// `true` for a success message, or `false` for failure pub fn cancel_tcpip_forward( &mut self, @@ -321,10 +321,10 @@ impl Session { /// Requests a UDS forwarding from the server, `socket path` being the server side socket path. /// /// If `reply_channel` is not None, sets want_reply and returns the server's response via the channel, - /// [`Some`] for a success message with the client side socket path, [`None`] for failure. + /// `true` for a success message, or `false` for failure pub fn streamlocal_forward( &mut self, - reply_channel: Option>>, + reply_channel: Option>, socket_path: &str, ) { if let Some(ref mut enc) = self.common.encrypted { @@ -346,7 +346,7 @@ impl Session { /// Requests cancellation of UDS forwarding from the server /// - /// If `want_reply` is true, returns a oneshot receiving the server's reply: + /// If `reply_channel` is not None, sets want_reply and returns the server's response via the channel, /// `true` for a success message and `false` for failure. pub fn cancel_streamlocal_forward( &mut self, diff --git a/russh/src/parsing.rs b/russh/src/parsing.rs index 1ea3256..fe80c97 100644 --- a/russh/src/parsing.rs +++ b/russh/src/parsing.rs @@ -32,7 +32,7 @@ impl OpenChannelMessage { } b"direct-tcpip" => ChannelType::DirectTcpip(TcpChannelInfo::new(r)?), b"forwarded-tcpip" => ChannelType::ForwardedTcpIp(TcpChannelInfo::new(r)?), - b"forwarded-streamlocal" => { + b"forwarded-streamlocal@openssh.com" => { ChannelType::ForwardedStreamLocal(StreamLocalChannelInfo::new(r)?) } b"auth-agent@openssh.com" => ChannelType::AgentForward, diff --git a/russh/src/server/encrypted.rs b/russh/src/server/encrypted.rs index d1e147d..70b47e5 100644 --- a/russh/src/server/encrypted.rs +++ b/russh/src/server/encrypted.rs @@ -1122,25 +1122,7 @@ impl Session { Some(GlobalRequestResponse::CancelTcpIpForward(return_channel)) => { let _ = return_channel.send(true); } - Some(GlobalRequestResponse::StreamLocalForward(return_channel)) => { - let mut r = buf.reader(1); - let socket_path: Option = match r.read_string() { - Ok(socket_path) => Some( - std::str::from_utf8(socket_path) - .map_err(crate::Error::from)? - .into(), - ), - Err(e) => { - error!("Error parsing socket path for StreamLocalForward request: {e:?}"); - None - } - }; - let _ = return_channel.send(socket_path); - } - Some(GlobalRequestResponse::CancelStreamLocalForward(return_channel)) => { - let _ = return_channel.send(true); - } - None => { + _ => { error!("Received global request failure for unknown request!") } } @@ -1158,13 +1140,7 @@ impl Session { Some(GlobalRequestResponse::CancelTcpIpForward(return_channel)) => { let _ = return_channel.send(false); } - Some(GlobalRequestResponse::StreamLocalForward(return_channel)) => { - let _ = return_channel.send(None); - } - Some(GlobalRequestResponse::CancelStreamLocalForward(return_channel)) => { - let _ = return_channel.send(false); - } - None => { + _ => { error!("Received global request failure for unknown request!") } } diff --git a/russh/src/server/session.rs b/russh/src/server/session.rs index de6f226..45d2245 100644 --- a/russh/src/server/session.rs +++ b/russh/src/server/session.rs @@ -64,16 +64,6 @@ pub enum Msg { address: String, port: u32, }, - StreamLocalForward { - // Provide a channel for the reply result to request a reply from the server - reply_channel: Option>>, - socket_path: String, - }, - CancelStreamLocalForward { - // Provide a channel for the reply result to request a reply from the server - reply_channel: Option>, - socket_path: String, - }, Disconnect { reason: crate::Disconnect, description: String, @@ -195,48 +185,6 @@ impl Handle { } } - // Notifies the client that it can open UDS forwarding channels for a given UDS - pub async fn forward_streamlocal(&self, socket_path: String) -> Result { - let (reply_send, reply_recv) = oneshot::channel(); - self.sender - .send(Msg::StreamLocalForward { - reply_channel: Some(reply_send), - socket_path, - }) - .await - .map_err(|_| ())?; - - match reply_recv.await { - Ok(Some(socket_path)) => Ok(socket_path), - Ok(None) => Err(()), - Err(e) => { - error!("Unable to receive StreamLocalForward result: {e:?}"); - Err(()) - } - } - } - - /// Notifies the client that it can no longer open TCP/IP forwarding channel for a port. - pub async fn cancel_forward_tcpip(&self, address: String, port: u32) -> Result<(), ()> { - let (reply_send, reply_recv) = oneshot::channel(); - self.sender - .send(Msg::CancelTcpIpForward { - reply_channel: Some(reply_send), - address, - port, - }) - .await - .map_err(|_| ())?; - match reply_recv.await { - Ok(true) => Ok(()), - Ok(false) => Err(()), // crate::Error::RequestDenied - Err(e) => { - error!("Unable to receive CancelTcpIpForward result: {e:?}"); - Err(()) // crate::Error::Disconnect - } - } - } - /// Request a session channel (the most basic type of /// channel). This function returns `Ok(..)` immediately if the /// connection is authenticated, but the channel only becomes @@ -594,12 +542,6 @@ impl Session { Some(Msg::CancelTcpIpForward { address, port, reply_channel }) => { self.cancel_tcpip_forward(&address, port, reply_channel); } - Some(Msg::StreamLocalForward { socket_path, reply_channel }) => { - self.streamlocal_forward(&socket_path, reply_channel); - } - Some(Msg::CancelStreamLocalForward { socket_path, reply_channel }) => { - self.cancel_streamlocal_forward(&socket_path, reply_channel); - } Some(Msg::Disconnect {reason, description, language_tag}) => { self.common.disconnect(reason, &description, &language_tag); } @@ -1105,50 +1047,6 @@ impl Session { } } - pub fn streamlocal_forward( - &mut self, - socket_path: &str, - reply_channel: Option>>, - ) { - if let Some(ref mut enc) = self.common.encrypted { - let want_reply = reply_channel.is_some(); - if let Some(reply_channel) = reply_channel { - self.open_global_requests.push_back( - crate::session::GlobalRequestResponse::StreamLocalForward(reply_channel), - ); - } - push_packet!(enc.write, { - enc.write.push(msg::GLOBAL_REQUEST); - enc.write - .extend_ssh_string(b"streamlocal-forward@openssh.com"); - enc.write.push(want_reply as u8); - enc.write.extend_ssh_string(socket_path.as_bytes()); - }) - } - } - - pub fn cancel_streamlocal_forward( - &mut self, - socket_path: &str, - reply_channel: Option>, - ) { - if let Some(ref mut enc) = self.common.encrypted { - let want_reply = reply_channel.is_some(); - if let Some(reply_channel) = reply_channel { - self.open_global_requests.push_back( - crate::session::GlobalRequestResponse::CancelStreamLocalForward(reply_channel), - ); - } - push_packet!(enc.write, { - enc.write.push(msg::GLOBAL_REQUEST); - enc.write - .extend_ssh_string(b"cancel-streamlocal-forward@openssh.com"); - enc.write.push(want_reply as u8); - enc.write.extend_ssh_string(socket_path.as_bytes()); - }); - } - } - /// Returns the SSH ID (Protocol Version + Software Version) the client sent when connecting /// /// This should contain only ASCII characters for implementations conforming to RFC4253, Section 4.2: diff --git a/russh/src/session.rs b/russh/src/session.rs index 78f20da..0a1f633 100644 --- a/russh/src/session.rs +++ b/russh/src/session.rs @@ -626,6 +626,7 @@ pub(crate) enum GlobalRequestResponse { TcpIpForward(oneshot::Sender>), /// request was for CancelTcpIpForward, sends true for success or false for failure CancelTcpIpForward(oneshot::Sender), - StreamLocalForward(oneshot::Sender>), + /// request was for StreamLocalForward, sends true for success or false for failure + StreamLocalForward(oneshot::Sender), CancelStreamLocalForward(oneshot::Sender), }