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

[BUG] - Sometimes an unexpected identity file path is parsed #2

Closed
teamwork-alockhart opened this issue Nov 9, 2022 · 0 comments · Fixed by #3
Closed

[BUG] - Sometimes an unexpected identity file path is parsed #2

teamwork-alockhart opened this issue Nov 9, 2022 · 0 comments · Fixed by #3
Assignees
Labels
bug Something isn't working

Comments

@teamwork-alockhart
Copy link

teamwork-alockhart commented Nov 9, 2022

Description

The wrong identity file path is parsed. When the wrong identity file path is present, there is a configuration in which the Host parameter is just a wildcard. If there are multiple wildcards, the last one is used when the wrong identity file path is parsed.

Steps to reproduce

Put the following in your ~/.ssh/config file

Host remote_host
  HostName hostname.com
  User user
  IdentityFile ~/.ssh/id_rsa_good

Host *
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_rsa_bad

Parse the config with the following code:

use ssh2_config::SshConfig;
use std::io::BufReader;

// Parsing ssh config
let config_path = <path to your config>;
let config = std::fs::File::open(config_path).unwrap();
let mut buf_rdr_conf = BufReader::new(config);
let ssh_config = SshConfig::default().parse(&mut buf_rdr_conf).unwrap();

// Get settings from config
let config = ssh_config.query("remote_host");
let host_name = config.host_name.unwrap();
eprintln!("host = {host_name}");
let mut identity_paths = config.identity_file.unwrap();
eprintln!("available identity paths = {identity_paths:#?}");

let identity_path = identity_paths.pop().unwrap();
eprintln!("identity path = {}", identity_path.display());
let user_name = config.user.unwrap();
eprintln!("user = {user_name}");

Note that the program prints other parameters just to be sure that all the others are correct.
Up until now, I've never had an issue with the others, but maybe that's because I don't actually use any other overlapping parameters in the wildcard configuration.

Expected behaviour

Program prints

identity path = ~/.ssh/id_rsa_good

Actual behavior

Program prints

identity path = ~/.ssh/id_rsa_bad

Environment

  • OS: MacOS Ventura
  • Architecture: Arm
  • Rust version: 1.64.0
  • remotefs version: N/A
  • Protocol used: N/A
  • Remote server version and name: N/A

Additional information

@teamwork-alockhart teamwork-alockhart added the bug Something isn't working label Nov 9, 2022
@teamwork-alockhart teamwork-alockhart changed the title [BUG] - Sometimes an unexpected identity file is parsed [BUG] - Sometimes an unexpected identity file path is parsed Nov 9, 2022
@veeso veeso linked a pull request Feb 2, 2023 that will close this issue
13 tasks
@veeso veeso closed this as completed in #3 Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants