-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update relevant channel request callbacks to return a bool
This is a breaking change, but it tweaks channel request callbacks to return a bool rather than requiring the user to manually call `session.channel_success` or `session.channel_failure`. This has the added advantage of changing the defaults of a number of request callbacks to more-secure defaults (deny), and makes it impossible for a user to miss responding to callbacks which require responses. Note that this does *not* handle sending responses for all requests, only channel requests listed in RFC4254 as having a "want reply" param rather than just "false", even though it may be more correct to respond to malformed requests which have improperly set that byte to "true" even though the RFC specifies "false".
- Loading branch information
Showing
5 changed files
with
75 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -822,7 +822,7 @@ impl Session { | |
|
||
debug!("handler.pty_request {:?}", channel_num); | ||
#[allow(clippy::indexing_slicing)] // `modes` length checked | ||
handler | ||
let response = handler | ||
.pty_request( | ||
channel_num, | ||
term, | ||
|
@@ -833,7 +833,13 @@ impl Session { | |
&modes[0..i], | ||
self, | ||
) | ||
.await | ||
.await?; | ||
if response { | ||
self.channel_success(channel_num); | ||
} else { | ||
self.channel_failure(channel_num); | ||
} | ||
Ok(()) | ||
} | ||
b"x11-req" => { | ||
let single_connection = r.read_byte().map_err(crate::Error::from)? != 0; | ||
|
@@ -855,7 +861,7 @@ impl Session { | |
}); | ||
} | ||
debug!("handler.x11_request {:?}", channel_num); | ||
handler | ||
let response = handler | ||
.x11_request( | ||
channel_num, | ||
single_connection, | ||
|
@@ -864,7 +870,13 @@ impl Session { | |
x11_screen_number, | ||
self, | ||
) | ||
.await | ||
.await?; | ||
if response { | ||
self.channel_success(channel_num); | ||
} else { | ||
self.channel_failure(channel_num); | ||
} | ||
Ok(()) | ||
} | ||
b"env" => { | ||
let env_variable = | ||
|
@@ -883,23 +895,34 @@ impl Session { | |
} | ||
|
||
debug!("handler.env_request {:?}", channel_num); | ||
handler | ||
let response = handler | ||
.env_request(channel_num, env_variable, env_value, self) | ||
.await | ||
.await?; | ||
if response { | ||
self.channel_success(channel_num); | ||
} else { | ||
self.channel_failure(channel_num); | ||
} | ||
Ok(()) | ||
} | ||
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 | ||
let response = handler.shell_request(channel_num, self).await?; | ||
if response { | ||
self.channel_success(channel_num); | ||
} else { | ||
self.channel_failure(channel_num); | ||
} | ||
Ok(()) | ||
} | ||
b"[email protected]" => { | ||
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.agent_request(channel_num, self).await?; | ||
if response { | ||
self.request_success() | ||
|
@@ -917,7 +940,13 @@ impl Session { | |
}); | ||
} | ||
debug!("handler.exec_request {:?}", channel_num); | ||
handler.exec_request(channel_num, req, self).await | ||
let response = handler.exec_request(channel_num, req, self).await?; | ||
if response { | ||
self.channel_success(channel_num); | ||
} else { | ||
self.channel_failure(channel_num); | ||
} | ||
Ok(()) | ||
} | ||
b"subsystem" => { | ||
let name = | ||
|
@@ -931,7 +960,13 @@ impl Session { | |
}); | ||
} | ||
debug!("handler.subsystem_request {:?}", channel_num); | ||
handler.subsystem_request(channel_num, name, self).await | ||
let response = handler.subsystem_request(channel_num, name, self).await?; | ||
if response { | ||
self.channel_success(channel_num); | ||
} else { | ||
self.channel_failure(channel_num); | ||
} | ||
Ok(()) | ||
} | ||
b"window-change" => { | ||
let col_width = r.read_u32().map_err(crate::Error::from)?; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters