FIXES #9870: Allow for windows path spaces with ssh utility

Prior to this commit, if a windows path contained a space, the ssh
utility could not properly find the private key path and the ssh command
would fail. This commit adds some additional logic to the ssh utility to
check if a path contains '%', and if so, use the IdentityFile argument.
Otherwise it will default to passing in the private key file with '-i',
which can support paths with spaces.
This commit is contained in:
Brian Cain 2018-11-09 10:19:35 -08:00
parent e8cee899a8
commit fc0707202a
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
1 changed files with 18 additions and 5 deletions

View File

@ -150,11 +150,24 @@ module Vagrant
if !plain_mode && options[:private_key_path]
options[:private_key_path].each do |path|
# Use '-o' instead of '-i' because '-i' does not call
# percent_expand in misc.c, but '-o' does. when passing the path,
# replace '%' in the path with '%%' to escape the '%'
path = path.to_s.gsub('%', '%%')
command_options += ["-o", "IdentityFile=\"#{path}\""]
private_key_arr = []
if path.include?('%')
if path.include?(' ') && Platform.windows?
LOGGER.warn("Paths with spaces and % on windows is not supported and will fail to read the file")
end
# Use '-o' instead of '-i' because '-i' does not call
# percent_expand in misc.c, but '-o' does. when passing the path,
# replace '%' in the path with '%%' to escape the '%'
path = path.to_s.gsub('%', '%%')
private_key_arr = ["-o", "IdentityFile=\"#{path}\""]
else
# Pass private key file directly with '-i', which properly supports
# paths with spaces on Windows guests
private_key_arr = ["-i", path]
end
command_options += private_key_arr
end
end