Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ProxyUseFdPass to ssh #6103

Merged
merged 3 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions wezterm-ssh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ wezterm-uds = { path = "../wezterm-uds" }
# Not used directly, but is used to centralize the openssl vendor feature selection
async_ossl = { path = "../async_ossl" }

[target.'cfg(unix)'.dependencies]
passfd = "0.1.6"

[dev-dependencies]
assert_fs = "1.0.4"
clap = {version="4.0", features=["derive"]}
Expand Down
32 changes: 16 additions & 16 deletions wezterm-ssh/src/sessioninner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ impl SessionInner {
sess.set_option(libssh_rs::SshOption::HostKeys(host_key.to_string()))?;
}

let (sock, _child) =
self.connect_to_host(&hostname, port, verbose, self.config.get("proxycommand"))?;
let (sock, _child) = self.connect_to_host(&hostname, port, verbose)?;
let raw = {
#[cfg(unix)]
{
Expand Down Expand Up @@ -288,8 +287,7 @@ impl SessionInner {
))))
.context("notifying user of banner")?;

let (sock, _child) =
self.connect_to_host(&hostname, port, verbose, self.config.get("proxycommand"))?;
let (sock, _child) = self.connect_to_host(&hostname, port, verbose)?;

let mut sess = ssh2::Session::new()?;
if verbose {
Expand Down Expand Up @@ -331,19 +329,18 @@ impl SessionInner {
hostname: &str,
port: u16,
verbose: bool,
proxy_command: Option<&String>,
) -> anyhow::Result<(Socket, Option<KillOnDropChild>)> {
match proxy_command.map(|s| s.as_str()) {
match self.config.get("proxycommand").map(|s| s.as_str()) {
Some("none") | None => {}
Some(proxy_command) => {
let mut cmd;
if cfg!(windows) {
let comspec = std::env::var("COMSPEC").unwrap_or_else(|_| "cmd".to_string());
cmd = std::process::Command::new(comspec);
cmd.args(&["/c", proxy_command]);
cmd.args(["/c", proxy_command]);
} else {
cmd = std::process::Command::new("sh");
cmd.args(&["-c", &format!("exec {}", proxy_command)]);
cmd.args(["-c", &format!("exec {}", proxy_command)]);
}

let (a, b) = socketpair()?;
Expand All @@ -357,11 +354,16 @@ impl SessionInner {

#[cfg(unix)]
unsafe {
use passfd::FdPassingExt;
use std::os::unix::io::{FromRawFd, IntoRawFd};
return Ok((
Socket::from_raw_fd(a.into_raw_fd()),
Some(KillOnDropChild(child)),
));

let raw = a.into_raw_fd();
let dest = match self.config.get("proxyusefdpass").map(|s| s.as_str()) {
Some("yes") => raw.recv_fd()?,
_ => raw,
};

return Ok((Socket::from_raw_fd(dest), Some(KillOnDropChild(child))));
}
#[cfg(windows)]
unsafe {
Expand All @@ -376,8 +378,7 @@ impl SessionInner {

let addr = (hostname, port)
.to_socket_addrs()?
.filter(|addr| self.filter_sock_addr(addr))
.next()
.find(|addr| self.filter_sock_addr(addr))
.with_context(|| format!("resolving address for {}", hostname))?;
if verbose {
log::info!("resolved {hostname}:{port} -> {addr:?}");
Expand All @@ -386,8 +387,7 @@ impl SessionInner {
if let Some(bind_addr) = self.config.get("bindaddress") {
let bind_addr = (bind_addr.as_str(), 0)
.to_socket_addrs()?
.filter(|addr| self.filter_sock_addr(addr))
.next()
.find(|addr| self.filter_sock_addr(addr))
.with_context(|| format!("resolving bind address {bind_addr:?}"))?;
if verbose {
log::info!("binding to {bind_addr:?}");
Expand Down
Loading