aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/ssh/auth_method.go
diff options
context:
space:
mode:
authorKuba Podgórski <kuba--@users.noreply.github.com>2018-09-07 10:25:23 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2018-09-07 10:25:23 +0200
commita4b12e4161738af6f724776c0c8c55f90542f06f (patch)
treee1db288d87e0ee1ab2c3cdc02ce6353926aec58d /plumbing/transport/ssh/auth_method.go
parentd3cec13ac0b195bfb897ed038a08b5130ab9969e (diff)
downloadgo-git-a4b12e4161738af6f724776c0c8c55f90542f06f.tar.gz
plumbing/transport: ssh check if list of known_hosts files is empty
Signed-off-by: kuba-- <kuba@sourced.tech>
Diffstat (limited to 'plumbing/transport/ssh/auth_method.go')
-rw-r--r--plumbing/transport/ssh/auth_method.go14
1 files changed, 8 insertions, 6 deletions
diff --git a/plumbing/transport/ssh/auth_method.go b/plumbing/transport/ssh/auth_method.go
index 84cfab2..dbb47c5 100644
--- a/plumbing/transport/ssh/auth_method.go
+++ b/plumbing/transport/ssh/auth_method.go
@@ -236,7 +236,7 @@ func (a *PublicKeysCallback) ClientConfig() (*ssh.ClientConfig, error) {
// NewKnownHostsCallback returns ssh.HostKeyCallback based on a file based on a
// known_hosts file. http://man.openbsd.org/sshd#SSH_KNOWN_HOSTS_FILE_FORMAT
//
-// If files is empty, the list of files will be read from the SSH_KNOWN_HOSTS
+// If list of files is empty, then it will be read from the SSH_KNOWN_HOSTS
// environment variable, example:
// /home/foo/custom_known_hosts_file:/etc/custom_known/hosts_file
//
@@ -244,13 +244,15 @@ func (a *PublicKeysCallback) ClientConfig() (*ssh.ClientConfig, error) {
// ~/.ssh/known_hosts
// /etc/ssh/ssh_known_hosts
func NewKnownHostsCallback(files ...string) (ssh.HostKeyCallback, error) {
- files, err := getDefaultKnownHostsFiles()
- if err != nil {
- return nil, err
+ var err error
+
+ if len(files) == 0 {
+ if files, err = getDefaultKnownHostsFiles(); err != nil {
+ return nil, err
+ }
}
- files, err = filterKnownHostsFiles(files...)
- if err != nil {
+ if files, err = filterKnownHostsFiles(files...); err != nil {
return nil, err
}