1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-09 11:37:19 +03:00

ssh: make -v option work on Windows, adjust config overlaying

Route logging via the `log` crate because on Windows there is
no stderr visible to libssh.

libssh will override any explicitly set options when it parses
the config file, so we need to apply those after we've loaded it.
This commit is contained in:
Wez Furlong 2021-12-15 09:18:00 -07:00
parent 421bcd25c1
commit f398f333cd
2 changed files with 85 additions and 35 deletions

79
Cargo.lock generated
View File

@ -1382,9 +1382,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "futures"
version = "0.3.18"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8cd0210d8c325c245ff06fd95a3b13689a1a276ac8cfa8e8720cb840bfb84b9e"
checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca"
dependencies = [
"futures-channel",
"futures-core",
@ -1397,9 +1397,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.18"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fc8cd39e3dbf865f7340dce6a2d401d24fd37c6fe6c4f0ee0de8bfca2252d27"
checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888"
dependencies = [
"futures-core",
"futures-sink",
@ -1407,15 +1407,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.18"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "629316e42fe7c2a0b9a65b47d159ceaa5453ab14e8f0a3c5eedbb8cd55b4a445"
checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d"
[[package]]
name = "futures-executor"
version = "0.3.18"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b808bf53348a36cab739d7e04755909b9fcaaa69b7d7e588b37b6ec62704c97"
checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c"
dependencies = [
"futures-core",
"futures-task",
@ -1424,9 +1424,9 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.18"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e481354db6b5c353246ccf6a728b0c5511d752c08da7260546fc0933869daa11"
checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377"
[[package]]
name = "futures-lite"
@ -1445,10 +1445,12 @@ dependencies = [
[[package]]
name = "futures-macro"
version = "0.3.18"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89f17b21645bc4ed773c69af9c9a0effd4a3f1a3876eadd453469f8854e7fdd"
checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb"
dependencies = [
"autocfg",
"proc-macro-hack",
"proc-macro2",
"quote",
"syn",
@ -1456,22 +1458,23 @@ dependencies = [
[[package]]
name = "futures-sink"
version = "0.3.18"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "996c6442437b62d21a32cd9906f9c41e7dc1e19a9579843fad948696769305af"
checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11"
[[package]]
name = "futures-task"
version = "0.3.18"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dabf1872aaab32c886832f2276d2f5399887e2bd613698a02359e4ea83f8de12"
checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99"
[[package]]
name = "futures-util"
version = "0.3.18"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d22213122356472061ac0f1ab2cee28d2bac8491410fd68c2af53d1cedb83e"
checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481"
dependencies = [
"autocfg",
"futures-channel",
"futures-core",
"futures-io",
@ -1481,6 +1484,8 @@ dependencies = [
"memchr",
"pin-project-lite",
"pin-utils",
"proc-macro-hack",
"proc-macro-nested",
"slab",
]
@ -1830,9 +1835,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "0.4.8"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
[[package]]
name = "jobserver"
@ -1923,9 +1928,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67"
[[package]]
name = "libc"
version = "0.2.111"
version = "0.2.112"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e167738f1866a7ec625567bae89ca0d44477232a4f7c52b1c7f2adc2c98804f"
checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
[[package]]
name = "libloading"
@ -1950,7 +1955,7 @@ dependencies = [
[[package]]
name = "libssh-rs"
version = "0.1.2"
source = "git+https://github.com/wez/libssh-rs.git#3dc392c2b6c1a4104d1478e744c6ae8f12a4e9de"
source = "git+https://github.com/wez/libssh-rs.git#320535b1acbd307ca7136d2f63533796a35287e5"
dependencies = [
"bitflags",
"libssh-rs-sys",
@ -1959,8 +1964,8 @@ dependencies = [
[[package]]
name = "libssh-rs-sys"
version = "0.1.1"
source = "git+https://github.com/wez/libssh-rs.git#3dc392c2b6c1a4104d1478e744c6ae8f12a4e9de"
version = "0.1.2"
source = "git+https://github.com/wez/libssh-rs.git#320535b1acbd307ca7136d2f63533796a35287e5"
dependencies = [
"cc",
"libz-sys",
@ -2574,9 +2579,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.8.0"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
[[package]]
name = "opaque-debug"
@ -2622,9 +2627,9 @@ checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a"
[[package]]
name = "openssl-src"
version = "300.0.3+3.0.0"
version = "300.0.4+3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c51ecedef28dcb23c303944dce1d44a9729f3d28d59f39e56f0c847329d1b134"
checksum = "216e1c6b4549e24182b9d7aa268f645414888a69daf44c7b2d8118da8e7b23e7"
dependencies = [
"cc",
]
@ -3058,10 +3063,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
[[package]]
name = "proc-macro2"
version = "1.0.33"
name = "proc-macro-nested"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb37d2df5df740e582f28f8560cf425f52bb267d872fe58358eadb554909f07a"
checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
[[package]]
name = "proc-macro2"
version = "1.0.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f84e92c0f7c9d58328b85a78557813e4bd845130db68d7184635344399423b1"
dependencies = [
"unicode-xid",
]
@ -3584,9 +3595,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.72"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0ffa0837f2dfa6fb90868c2b5468cad482e175f7dad97e7421951e663f2b527"
checksum = "bcbd0344bc6533bc7ec56df11d42fb70f1b912351c0825ccb7211b59d8af7cf5"
dependencies = [
"itoa",
"ryu",

View File

@ -18,6 +18,7 @@ use libssh_rs as libssh;
use portable_pty::ExitStatus;
use smol::channel::{bounded, Receiver, Sender, TryRecvError};
use std::collections::{HashMap, VecDeque};
use std::ffi::CStr;
use std::io::{Read, Write};
use std::net::TcpStream;
use std::time::Duration;
@ -113,10 +114,49 @@ impl SessionInner {
== "true"
{
sess.set_option(libssh::SshOption::LogLevel(libssh::LogLevel::Packet))?;
/// libssh logs to stderr, but on Windows in the GUI there isn't a valid
/// stderr for it to log to.
/// So, we redirect logging via our own log callback and pipe it via
/// the `log` crate.
unsafe extern "C" fn log_callback(
_priority: std::os::raw::c_int,
function: *const std::os::raw::c_char,
message: *const std::os::raw::c_char,
_userdata: *mut std::os::raw::c_void,
) {
let function = CStr::from_ptr(function).to_string_lossy().to_string();
let message = CStr::from_ptr(message).to_string_lossy().to_string();
/// The message typically has "function: message" prefixed, which
/// looks redundant when logged with the function prefix by the
/// logging crate.
/// Strip that off!
let message = match message.strip_prefix(&format!("{}: ", function)) {
Some(m) => m,
None => &message,
};
log::logger().log(
&log::Record::builder()
.args(format_args!("{}", message))
.level(log::Level::Info)
.module_path(Some(&function))
.target(&format!("libssh::{}", function))
.build(),
);
}
unsafe {
libssh::sys::ssh_set_log_callback(Some(log_callback));
}
}
sess.set_option(libssh::SshOption::Hostname(hostname.clone()))?;
sess.set_option(libssh::SshOption::User(Some(user)))?;
sess.set_option(libssh::SshOption::Port(port))?;
sess.options_parse_config(None)?; // FIXME: overridden config path?
if let Some(agent) = self.config.get("identityagent") {
sess.set_option(libssh::SshOption::IdentityAgent(Some(agent.clone())))?;
}
if let Some(files) = self.config.get("identityfile") {
for file in files.split_whitespace() {
sess.set_option(libssh::SshOption::AddIdentity(file.to_string()))?;
@ -132,7 +172,6 @@ impl SessionInner {
sess.set_option(libssh::SshOption::ProxyCommand(Some(cmd.to_string())))?;
}
sess.options_parse_config(None)?; // FIXME: overridden config path?
sess.connect()?;
let banner = sess.get_server_banner()?;