diff options
author | Akinori MUSHA <knu@idaemons.org> | 2017-03-24 09:05:20 +0900 |
---|---|---|
committer | Akinori MUSHA <knu@idaemons.org> | 2017-03-24 09:05:20 +0900 |
commit | 7722c25bbe53debfefe622b79b8e996715e2a229 (patch) | |
tree | 965351769e5c2e366b5a613919d2635f5f2f6c9f /lib | |
parent | b02d0537193c9819b367e52dc95bede51aee7352 (diff) | |
download | net-ssh-7722c25bbe53debfefe622b79b8e996715e2a229.tar.gz |
Resolve relative paths in the Include directive properly
According to ssh_config(5), relative paths in the Include directive is
relative from the directory of the root file, not from that of the
including file. If `~/.ssh/config` includes `~/.ssh/dir1/file1` which
has a line `Include dir2/file2`, ssh tries to include
`~/.ssh/dir2/file2`, not `~/.ssh/dir1/dir2/file2`.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net/ssh/config.rb | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/net/ssh/config.rb b/lib/net/ssh/config.rb index d278f5b..afe50c9 100644 --- a/lib/net/ssh/config.rb +++ b/lib/net/ssh/config.rb @@ -72,9 +72,9 @@ module Net; module SSH # ones. Returns a hash containing the OpenSSH options. (See # #translate for how to convert the OpenSSH options into Net::SSH # options.) - def load(path, host, settings={}) + def load(path, host, settings={}, base_dir = nil) file = File.expand_path(path) - base_dir = File.dirname(file) + base_dir ||= File.dirname(file) return settings unless File.readable?(file) globals = {} @@ -125,7 +125,7 @@ module Net; module SSH (globals[key] ||= []) << value when 'include' included_file_paths(base_dir, value).each do |file_path| - globals = load(file_path, host, globals) + globals = load(file_path, host, globals, base_dir) end else globals[key] = value unless settings.key?(key) @@ -136,7 +136,7 @@ module Net; module SSH (settings[key] ||= []) << value when 'include' included_file_paths(base_dir, value).each do |file_path| - settings = load(file_path, host, settings) + settings = load(file_path, host, settings, base_dir) end else settings[key] = value unless settings.key?(key) @@ -304,9 +304,7 @@ module Net; module SSH end def included_file_paths(base_dir, config_path) - paths = Dir.glob(File.expand_path(config_path)).select { |f| File.file?(f) } - paths += Dir.glob(File.join(base_dir, config_path)).select { |f| File.file?(f) } - paths.uniq + Dir.glob(File.expand_path(config_path, base_dir)).select { |f| File.file?(f) } end end |