From b7d702ab5f6c790fa2af461860de5816c2b4160a Mon Sep 17 00:00:00 2001 From: John Rizzo Date: Mon, 9 Jul 2018 14:27:38 -0400 Subject: [PATCH 1/2] Update mount_shared_folder.rb This change allows special characters in the password such as ) which will cause cmdkey to fail without the quotes. --- plugins/guests/windows/cap/mount_shared_folder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/guests/windows/cap/mount_shared_folder.rb b/plugins/guests/windows/cap/mount_shared_folder.rb index 6ce3735e7..03cb120ea 100644 --- a/plugins/guests/windows/cap/mount_shared_folder.rb +++ b/plugins/guests/windows/cap/mount_shared_folder.rb @@ -22,7 +22,7 @@ module VagrantPlugins # Ensure password is scrubbed Vagrant::Util::CredentialScrubber.sensitive(options[:smb_password]) end - machine.communicate.execute("cmdkey /add:#{options[:smb_host]} /user:#{options[:smb_username]} /pass:#{options[:smb_password]}", {shell: :powershell, elevated: true}) + machine.communicate.execute("cmdkey /add:#{options[:smb_host]} /user:#{options[:smb_username]} /pass:\"#{options[:smb_password]}\"", {shell: :powershell, elevated: true}) mount_shared_folder(machine, name, guestpath, "\\\\#{options[:smb_host]}\\") end From 5ebb548be9914a00c6a72e64fd8a48502e47ab8c Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 18 Sep 2018 13:38:57 -0700 Subject: [PATCH 2/2] Add test for SMB mount_shared_folder function This commit ensures that the command that adds the smb username and password properly quotes the password given by the user. --- test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb b/test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb index 021805629..7c02ad6e8 100644 --- a/test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb +++ b/test/unit/plugins/guests/windows/cap/mount_shared_folder_test.rb @@ -98,6 +98,7 @@ describe "VagrantPlugins::GuestWindows::Cap::MountSharedFolder" do share_name: "name", vm_provider_unc_path: "\\\\host\\name", }) + expect(machine.communicate).to receive(:execute).with("cmdkey /add:host /user:user /pass:\"pass\"", {:shell=>:powershell, :elevated=>true}) described_class.mount_smb_shared_folder(machine, 'name', 'guestpath', {:smb_username => "user", :smb_password => "pass", :smb_host => "host"}) end end