synced_folders/smb: ask for creds in prepare

This commit is contained in:
Mitchell Hashimoto 2014-03-06 08:49:41 -08:00
parent 79df69392f
commit c9623a2a3f
3 changed files with 26 additions and 21 deletions

View File

@ -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

View File

@ -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]

View File

@ -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.