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

ssh: don't override the ssh config User value

This commit is contained in:
Wez Furlong 2021-04-08 16:17:49 -07:00
parent 22440a3cb2
commit ecc500af05
6 changed files with 91 additions and 13 deletions

View File

@ -32,13 +32,17 @@ impl_lua_conversion!(SshDomain);
#[derive(Clone, Debug)]
pub struct SshParameters {
pub username: String,
pub username: Option<String>,
pub host_and_port: String,
}
impl Display for SshParameters {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}@{}", self.username, self.host_and_port)
if let Some(user) = &self.username {
write!(f, "{}@{}", user, self.host_and_port)
} else {
write!(f, "{}", self.host_and_port)
}
}
}
@ -59,12 +63,12 @@ impl FromStr for SshParameters {
if parts.len() == 2 {
Ok(Self {
username: parts[0].to_string(),
username: Some(parts[0].to_string()),
host_and_port: parts[1].to_string(),
})
} else if parts.len() == 1 {
Ok(Self {
username: username_from_env()?,
username: None,
host_and_port: parts[0].to_string(),
})
} else {

View File

@ -17,6 +17,7 @@ As features stabilize some brief notes about them will accumulate here.
* Fixed: support for "Variable" fonts such as Cascadia Code and Inconsolata on all platforms [#655](https://github.com/wez/wezterm/issues/655)
* New: [wezterm.font](config/lua/wezterm/font.md) and [wezterm.font_with_fallback](config/lua/wezterm.font_with_fallback.md) *attributes* parameter now allows matching more granular font weights and font widths. e.g.: `wezterm.font('Iosevka Term', {width="Expanded", weight="Regular"})`
* New: [freetype_render_target](config/lua/config/freetype_render_target.md) option for additional control over glyph rasterization.
* Fixed: `wezterm ssh HOST` no longer overrides the `User` config specified by `~/.ssh/config`
### 20210405-110924-a5bb5be8

View File

@ -53,7 +53,7 @@ impl LineEditorHost for PasswordPromptHost {
pub fn ssh_connect_with_ui(
remote_address: &str,
username: &str,
username: Option<&str>,
ui: &mut ConnectionUI,
) -> anyhow::Result<Session> {
let cloned_ui = ui.clone();
@ -72,7 +72,9 @@ pub fn ssh_connect_with_ui(
};
let mut ssh_config = ssh_config.for_host(&remote_host_name);
ssh_config.insert("user".to_string(), username.to_string());
if let Some(username) = username {
ssh_config.insert("user".to_string(), username.to_string());
}
if let Some(port) = port {
ssh_config.insert("port".to_string(), port.to_string());
}

View File

@ -425,7 +425,7 @@ impl Reconnectable {
initial: bool,
ui: &mut ConnectionUI,
) -> anyhow::Result<()> {
let sess = ssh_connect_with_ui(&ssh_dom.remote_address, &ssh_dom.username, ui)?;
let sess = ssh_connect_with_ui(&ssh_dom.remote_address, Some(&ssh_dom.username), ui)?;
let proxy_bin = Self::wezterm_bin_path(&ssh_dom.remote_wezterm_path);
let cmd = if initial {
@ -577,8 +577,11 @@ impl Reconnectable {
if let Some(Ok(ssh_params)) = tls_client.ssh_parameters() {
if self.tls_creds.is_none() {
// We need to bootstrap via an ssh session
let sess =
ssh_connect_with_ui(&ssh_params.host_and_port, &ssh_params.username, ui)?;
let sess = ssh_connect_with_ui(
&ssh_params.host_and_port,
ssh_params.username.as_ref().map(|s| s.as_str()),
ui,
)?;
let creds = ui.run_and_log_error(|| {
// The `tlscreds` command will start the server if needed and then

View File

@ -97,10 +97,9 @@ async fn async_run_ssh(opts: SshCommand) -> anyhow::Result<()> {
let port = fields.next();
let mut ssh_config = ssh_config.for_host(host);
ssh_config.insert(
"user".to_string(),
opts.user_at_host_and_port.username.to_string(),
);
if let Some(username) = &opts.user_at_host_and_port.username {
ssh_config.insert("user".to_string(), username.to_string());
}
if let Some(port) = port {
ssh_config.insert("port".to_string(), port.to_string());
}

View File

@ -389,6 +389,75 @@ mod test {
use super::*;
use k9::snapshot;
#[test]
fn parse_user() {
let mut config = Config::new();
let mut fake_env = ConfigMap::new();
fake_env.insert("HOME".to_string(), "/home/me".to_string());
fake_env.insert("USER".to_string(), "me".to_string());
config.assign_environment(fake_env);
config.add_config_string(
r#"
Host foo
HostName 10.0.0.1
User foo
IdentityFile "%d/.ssh/id_pub.dsa"
"#,
);
snapshot!(
&config,
r#"
Config {
config_files: [
ParsedConfigFile {
options: {},
groups: [
HostGroup {
patterns: [
Pattern {
negated: false,
pattern: "^foo$",
},
],
options: {
"hostname": "10.0.0.1",
"identityfile": "%d/.ssh/id_pub.dsa",
"user": "foo",
},
},
],
},
],
options: {},
tokens: {},
environment: Some(
{
"HOME": "/home/me",
"USER": "me",
},
),
}
"#
);
let opts = config.for_host("foo");
snapshot!(
opts,
r#"
{
"hostname": "10.0.0.1",
"identityfile": "/home/me/.ssh/id_pub.dsa",
"port": "22",
"user": "foo",
"userknownhostsfile": "/home/me/.ssh/known_hosts /home/me/.ssh/known_hosts2",
}
"#
);
}
#[test]
fn parse_simple() {
let mut config = Config::new();