From fb747a34557b1cc5bd7ffa6dd8faa0f2e3ddc0bd Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Wed, 29 Sep 2021 11:20:26 -0500 Subject: [PATCH] Add extra option as fallback for ssh options --- Cargo.lock | 7 ++++--- distant-ssh2/Cargo.toml | 3 +++ distant-ssh2/src/lib.rs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0c79a2f..a3c99dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -429,7 +429,7 @@ dependencies = [ [[package]] name = "distant" -version = "0.15.0-alpha.3" +version = "0.15.0-alpha.4" dependencies = [ "assert_cmd", "assert_fs", @@ -453,7 +453,7 @@ dependencies = [ [[package]] name = "distant-core" -version = "0.15.0-alpha.3" +version = "0.15.0-alpha.4" dependencies = [ "assert_fs", "bytes", @@ -478,7 +478,7 @@ dependencies = [ [[package]] name = "distant-ssh2" -version = "0.15.0-alpha.3" +version = "0.15.0-alpha.4" dependencies = [ "assert_cmd", "assert_fs", @@ -493,6 +493,7 @@ dependencies = [ "rand", "rpassword", "rstest", + "serde", "smol", "tokio", "wezterm-ssh", diff --git a/distant-ssh2/Cargo.toml b/distant-ssh2/Cargo.toml index 2a235ff..453355b 100644 --- a/distant-ssh2/Cargo.toml +++ b/distant-ssh2/Cargo.toml @@ -21,6 +21,9 @@ smol = "1.2" tokio = { version = "1.12.0", features = ["full"] } wezterm-ssh = { version = "0.2.0", features = ["vendored-openssl"], git = "https://github.com/chipsenkbeil/wezterm" } +# Optional serde support for data structures +serde = { version = "1.0.126", features = ["derive"], optional = true } + [dev-dependencies] assert_cmd = "2.0.0" assert_fs = "1.0.4" diff --git a/distant-ssh2/src/lib.rs b/distant-ssh2/src/lib.rs index 8eef084..01c692d 100644 --- a/distant-ssh2/src/lib.rs +++ b/distant-ssh2/src/lib.rs @@ -3,6 +3,7 @@ use distant_core::{Request, Session, Transport}; use log::*; use smol::channel::Receiver as SmolReceiver; use std::{ + collections::BTreeMap, io::{self, Write}, path::PathBuf, sync::Arc, @@ -13,6 +14,7 @@ use wezterm_ssh::{Config as WezConfig, Session as WezSession, SessionEvent as We mod handler; #[derive(Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Ssh2AuthPrompt { /// The label to show when prompting the user pub prompt: String, @@ -23,6 +25,7 @@ pub struct Ssh2AuthPrompt { } #[derive(Debug)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Ssh2AuthEvent { /// Represents the name of the user to be authenticated. This may be empty! pub username: String, @@ -35,13 +38,40 @@ pub struct Ssh2AuthEvent { } #[derive(Clone, Debug, Default)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Ssh2SessionOpts { + /// List of files from which the user's DSA, ECDSA, Ed25519, or RSA authentication identity + /// is read, defaulting to + /// + /// - `~/.ssh/id_dsa` + /// - `~/.ssh/id_ecdsa` + /// - `~/.ssh/id_ed25519` + /// - `~/.ssh/id_rsa` pub identity_files: Vec, + + /// If provided and true, specifies that ssh should only use the configured authentication + /// and certificate files (either the defaults or configured from `identity_files`) + /// + /// Default is false (aka no) pub identities_only: Option, + + /// Port to use when connecting to an SSHD instance pub port: Option, + + /// Specifies the command to use to connect to the server pub proxy_command: Option, + + /// Specifies the user to log in as pub user: Option, + + /// Specifies one or more files to use for the user host key database, defaulting to + /// + /// - `~/.ssh/known_hosts` + /// - `~/.ssh/known_hosts2` pub user_known_hosts_files: Vec, + + /// Additional options to provide as defined by `ssh_config(5)` + pub other: BTreeMap, } pub struct Ssh2AuthHandler { @@ -159,6 +189,9 @@ impl Ssh2Session { ); } + // Add in any of the other options provided + config.extend(opts.other); + // Establish a connection let (session, events) = WezSession::connect(config).map_err(|x| io::Error::new(io::ErrorKind::Other, x))?;