mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 09:15:57 +02:00
Fix ssh kitten override parsing ignoring settings inherited from ssh.conf
Fixes #6639
This commit is contained in:
@@ -391,9 +391,20 @@ func (self *ConfigSet) line_handler(key, val string) error {
|
||||
func load_config(hostname_to_match string, username_to_match string, overrides []string, paths ...string) (*Config, []config.ConfigLine, error) {
|
||||
ans := &ConfigSet{all_configs: []*Config{NewConfig()}}
|
||||
p := config.ConfigParser{LineHandler: ans.line_handler}
|
||||
err := p.LoadConfig("ssh.conf", paths, overrides)
|
||||
err := p.LoadConfig("ssh.conf", paths, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return config_for_hostname(hostname_to_match, username_to_match, ans), p.BadLines(), nil
|
||||
final_conf := config_for_hostname(hostname_to_match, username_to_match, ans)
|
||||
bad_lines := p.BadLines()
|
||||
if len(overrides) > 0 {
|
||||
h := final_conf.Hostname
|
||||
override_parser := config.ConfigParser{LineHandler: final_conf.Parse}
|
||||
if err = override_parser.ParseOverrides(overrides...); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
bad_lines = append(bad_lines, override_parser.BadLines()...)
|
||||
final_conf.Hostname = h
|
||||
}
|
||||
return final_conf, bad_lines, nil
|
||||
}
|
||||
|
||||
@@ -24,11 +24,14 @@ func TestSSHConfigParsing(t *testing.T) {
|
||||
hostname := "unmatched"
|
||||
username := ""
|
||||
conf := ""
|
||||
overrides := []string{}
|
||||
for_python := false
|
||||
cf := filepath.Join(tdir, "ssh.conf")
|
||||
rt := func(expected_env ...string) {
|
||||
os.WriteFile(cf, []byte(conf), 0o600)
|
||||
c, bad_lines, err := load_config(hostname, username, nil, cf)
|
||||
if err := os.WriteFile(cf, []byte(conf), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c, bad_lines, err := load_config(hostname, username, overrides, cf)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -52,6 +55,10 @@ func TestSSHConfigParsing(t *testing.T) {
|
||||
rt()
|
||||
conf = "env a=b"
|
||||
rt(`export 'a'="b"`)
|
||||
conf = "env a=b"
|
||||
overrides = []string{"env=c=d"}
|
||||
rt(`export 'a'="b"`, `export 'c'="d"`)
|
||||
overrides = nil
|
||||
|
||||
conf = "env a=\\"
|
||||
rt(`export 'a'="\\"`)
|
||||
|
||||
@@ -115,9 +115,6 @@ func parse_kitten_args(found_extra_args []string, username, hostname_for_match s
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(overrides) > 0 {
|
||||
overrides = append([]string{"hostname " + username + "@" + hostname_for_match}, overrides...)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user