summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-12-19 00:03:46 +0700
committerShulhan <ms@kilabit.info>2023-12-19 00:11:01 +0700
commita0c7d844b77315d796c1ab44501dff1226658982 (patch)
tree3e12a368bdf30d2f3059cb9d3c586f79a2e956ba
parent7a2a2949f6787d5301bfb9cd6e592658c7515818 (diff)
downloadpakakeh.go-a0c7d844b77315d796c1ab44501dff1226658982.tar.xz
ssh/config: set the Hostname if its not set on [Config.Get]
Per manual ssh_config(5) on Hostname, The default is the name given on the command line. So, if the requested host name match with one of Host or Match, but Hostname is not set, it should be default to the requested parameter name.
-rw-r--r--lib/ssh/config/config.go5
-rw-r--r--lib/ssh/config/config_test.go4
-rw-r--r--lib/ssh/config/testdata/config_get_test.txt11
3 files changed, 20 insertions, 0 deletions
diff --git a/lib/ssh/config/config.go b/lib/ssh/config/config.go
index 856bd6c8..25dd9b3b 100644
--- a/lib/ssh/config/config.go
+++ b/lib/ssh/config/config.go
@@ -124,6 +124,11 @@ func (cfg *Config) Get(s string) (section *Section) {
}
}
section.init(cfg.workDir, cfg.homeDir)
+
+ if s != `` && section.Field[KeyHostname] == `` {
+ section.Set(KeyHostname, s)
+ }
+
return section
}
diff --git a/lib/ssh/config/config_test.go b/lib/ssh/config/config_test.go
index 30e0ccdc..c7e479ce 100644
--- a/lib/ssh/config/config_test.go
+++ b/lib/ssh/config/config_test.go
@@ -89,6 +89,10 @@ func TestConfigGet(t *testing.T) {
}, {
name: `foo.local`,
exp: string(tdata.Output[`foo.local`]),
+ }, {
+ // With Hostname key not set but match Host wildcard.
+ name: `my.foo.local`,
+ exp: string(tdata.Output[`my.foo.local`]),
}}
var (
diff --git a/lib/ssh/config/testdata/config_get_test.txt b/lib/ssh/config/testdata/config_get_test.txt
index 21735853..2fc364e2 100644
--- a/lib/ssh/config/testdata/config_get_test.txt
+++ b/lib/ssh/config/testdata/config_get_test.txt
@@ -41,3 +41,14 @@ Host foo.local
port 22
user allfoo
xauthlocation /usr/X11R6/bin/xauth
+
+<<< my.foo.local
+Host my.foo.local
+ challengeresponseauthentication yes
+ checkhostip yes
+ connectionattempts 1
+ hostname my.foo.local
+ identityfile ~/.ssh/allfoo
+ port 22
+ user allfoo
+ xauthlocation /usr/X11R6/bin/xauth