diff --git a/plugins/synced_folders/smb/scripts/set_share.ps1 b/plugins/synced_folders/smb/scripts/set_share.ps1 index f6dcc9074..ec9097672 100644 --- a/plugins/synced_folders/smb/scripts/set_share.ps1 +++ b/plugins/synced_folders/smb/scripts/set_share.ps1 @@ -26,6 +26,7 @@ if (![string]::IsNullOrEmpty($host_share_username)) { # Here we need to set the proper ACL for this folder. This lets full # recursive access to this folder. + <# Get-ChildItem $path -recurse -Force |% { $current_acl = Get-ACL $_.fullname $permission = "$computer_name\$host_share_username","FullControl","ContainerInherit,ObjectInherit","None","Allow" @@ -33,6 +34,7 @@ if (![string]::IsNullOrEmpty($host_share_username)) { $current_acl.SetAccessRule($acl_access_rule) $current_acl | Set-Acl $_.fullname } + #> } $result = net share $share_name=$path /unlimited /GRANT:$grant diff --git a/plugins/synced_folders/smb/synced_folder.rb b/plugins/synced_folders/smb/synced_folder.rb index 5a56ac5d3..64d3e7fdb 100644 --- a/plugins/synced_folders/smb/synced_folder.rb +++ b/plugins/synced_folders/smb/synced_folder.rb @@ -12,6 +12,7 @@ module VagrantPlugins super @logger = Log4r::Logger.new("vagrant::synced_folders::smb") + @creds = {} end def usable?(machine, raise_error=false) @@ -29,8 +30,25 @@ module VagrantPlugins end def prepare(machine, folders, opts) + machine.ui.output(I18n.t("vagrant_sf_smb.preparing")) + script_path = File.expand_path("../scripts/set_share.ps1", __FILE__) + # If we need auth information, then ask the user. + need_auth = false + folders.each do |id, data| + if !data[:smb_username] || !data[:smb_password] + need_auth = true + break + end + end + + if need_auth + machine.ui.detail(I18n.t("vagrant_sf_smb.warning_password") + "\n ") + @creds[:username] = machine.ui.ask("Username: ") + @creds[:password] = machine.ui.ask("Password (will be hidden): ", echo: false) + end + folders.each do |id, data| hostpath = data[:hostpath] @@ -39,7 +57,7 @@ module VagrantPlugins args = [] args << "-path" << hostpath.gsub("/", "\\") args << "-share_name" << data[:smb_id] - #args << "-host_share_username" << "mitchellh" + #args << "-host_share_username" << @creds[:username] r = Vagrant::Util::PowerShell.execute(script_path, *args) if r.exit_code != 0 @@ -82,31 +100,14 @@ module VagrantPlugins end end - # If we need auth information, then ask the user - username = nil - password = nil - need_auth = false - folders.each do |id, data| - if !data[:smb_username] || !data[:smb_password] - need_auth = true - break - end - end - - if need_auth - machine.ui.detail(I18n.t("vagrant_sf_smb.warning_password") + "\n ") - username = machine.ui.ask("Username: ") - password = machine.ui.ask("Password (will be hidden): ", echo: false) - end - # This is used for defaulting the owner/group ssh_info = machine.ssh_info folders.each do |id, data| data = data.dup data[:smb_host] ||= host_ip - data[:smb_username] ||= username - data[:smb_password] ||= password + data[:smb_username] ||= @creds[:username] + data[:smb_password] ||= @creds[:password] # Default the owner/group of the folder to the SSH user data[:owner] ||= ssh_info[:username] diff --git a/templates/locales/synced_folder_smb.yml b/templates/locales/synced_folder_smb.yml index c3ce974fa..140bd0244 100644 --- a/templates/locales/synced_folder_smb.yml +++ b/templates/locales/synced_folder_smb.yml @@ -4,8 +4,10 @@ en: Mounting SMB shared folders... mounting_single: |- %{host} => %{guest} + preparing: |- + Preparing SMB shared folders... warning_password: |- - You will be asked for the username and password to use to mount the + You will be asked for the username and password to use for the SMB folders shortly. Please use the proper username/password of your Windows account.