Skip to content

Commit b9759d4

Browse files
committed
client channel handling changes
1 parent 67a6ba8 commit b9759d4

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

russh/src/client/encrypted.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,15 @@ impl Session {
761761
match &msg.typ {
762762
ChannelType::Session => {
763763
confirm();
764-
client.server_channel_open_session(id, self).await?
764+
let channel = self.accept_server_initiated_channel(id, &msg);
765+
client.server_channel_open_session(channel, self).await?
765766
}
766767
ChannelType::DirectTcpip(d) => {
767768
confirm();
769+
let channel = self.accept_server_initiated_channel(id, &msg);
768770
client
769771
.server_channel_open_direct_tcpip(
770-
id,
772+
channel,
771773
&d.host_to_connect,
772774
d.port_to_connect,
773775
&d.originator_address,
@@ -818,11 +820,16 @@ impl Session {
818820
}
819821
ChannelType::AgentForward => {
820822
confirm();
821-
client.server_channel_open_agent_forward(id, self).await?
823+
let channel = self.accept_server_initiated_channel(id, &msg);
824+
client
825+
.server_channel_open_agent_forward(channel, self)
826+
.await?
822827
}
823828
ChannelType::Unknown { typ } => {
824-
if client.server_channel_handle_unknown(id, typ) {
829+
if client.should_accept_unknown_server_channel(id, typ).await {
825830
confirm();
831+
let channel = self.accept_server_initiated_channel(id, &msg);
832+
client.server_channel_open_unknown(channel, self).await?;
826833
} else {
827834
debug!("unknown channel type: {}", String::from_utf8_lossy(typ));
828835
msg.unknown_type(&mut enc.write);

russh/src/client/mod.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,25 +1633,40 @@ pub trait Handler: Sized + Send {
16331633
#[allow(unused_variables)]
16341634
async fn server_channel_open_agent_forward(
16351635
&mut self,
1636-
channel: ChannelId,
1636+
channel: Channel<Msg>,
16371637
session: &mut Session,
16381638
) -> Result<(), Self::Error> {
16391639
Ok(())
16401640
}
16411641

1642-
/// Called when the server gets an unknown channel. It may return `true`,
1643-
/// if the channel of unknown type should be handled. If it returns `false`,
1644-
/// the channel will not be created and an error will be sent to the server.
1642+
/// Called when the server attempts to open a channel of unknown type. It may return `true`,
1643+
/// if the channel of unknown type should be accepted. In this case,
1644+
/// [Handler::server_channel_open_unknown] will be called soon after. If it returns `false`,
1645+
/// the channel will not be created and a rejection message will be sent to the server.
16451646
#[allow(unused_variables)]
1646-
fn server_channel_handle_unknown(&self, channel: ChannelId, channel_type: &[u8]) -> bool {
1647+
async fn should_accept_unknown_server_channel(
1648+
&mut self,
1649+
id: ChannelId,
1650+
channel_type: &[u8],
1651+
) -> bool {
16471652
false
16481653
}
16491654

1655+
/// Called when the server opens an unknown channel.
1656+
#[allow(unused_variables)]
1657+
async fn server_channel_open_unknown(
1658+
&mut self,
1659+
channel: Channel<Msg>,
1660+
session: &mut Session,
1661+
) -> Result<(), Self::Error> {
1662+
Ok(())
1663+
}
1664+
16501665
/// Called when the server opens a session channel.
16511666
#[allow(unused_variables)]
16521667
async fn server_channel_open_session(
16531668
&mut self,
1654-
channel: ChannelId,
1669+
channel: Channel<Msg>,
16551670
session: &mut Session,
16561671
) -> Result<(), Self::Error> {
16571672
Ok(())
@@ -1661,7 +1676,7 @@ pub trait Handler: Sized + Send {
16611676
#[allow(unused_variables)]
16621677
async fn server_channel_open_direct_tcpip(
16631678
&mut self,
1664-
channel: ChannelId,
1679+
channel: Channel<Msg>,
16651680
host_to_connect: &str,
16661681
port_to_connect: u32,
16671682
originator_address: &str,

0 commit comments

Comments
 (0)