synced_folders/smb: ask for creds in prepare
This commit is contained in:
parent
79df69392f
commit
c9623a2a3f
|
@ -26,6 +26,7 @@ if (![string]::IsNullOrEmpty($host_share_username)) {
|
||||||
|
|
||||||
# Here we need to set the proper ACL for this folder. This lets full
|
# Here we need to set the proper ACL for this folder. This lets full
|
||||||
# recursive access to this folder.
|
# recursive access to this folder.
|
||||||
|
<#
|
||||||
Get-ChildItem $path -recurse -Force |% {
|
Get-ChildItem $path -recurse -Force |% {
|
||||||
$current_acl = Get-ACL $_.fullname
|
$current_acl = Get-ACL $_.fullname
|
||||||
$permission = "$computer_name\$host_share_username","FullControl","ContainerInherit,ObjectInherit","None","Allow"
|
$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.SetAccessRule($acl_access_rule)
|
||||||
$current_acl | Set-Acl $_.fullname
|
$current_acl | Set-Acl $_.fullname
|
||||||
}
|
}
|
||||||
|
#>
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = net share $share_name=$path /unlimited /GRANT:$grant
|
$result = net share $share_name=$path /unlimited /GRANT:$grant
|
||||||
|
|
|
@ -12,6 +12,7 @@ module VagrantPlugins
|
||||||
super
|
super
|
||||||
|
|
||||||
@logger = Log4r::Logger.new("vagrant::synced_folders::smb")
|
@logger = Log4r::Logger.new("vagrant::synced_folders::smb")
|
||||||
|
@creds = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def usable?(machine, raise_error=false)
|
def usable?(machine, raise_error=false)
|
||||||
|
@ -29,8 +30,25 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare(machine, folders, opts)
|
def prepare(machine, folders, opts)
|
||||||
|
machine.ui.output(I18n.t("vagrant_sf_smb.preparing"))
|
||||||
|
|
||||||
script_path = File.expand_path("../scripts/set_share.ps1", __FILE__)
|
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|
|
folders.each do |id, data|
|
||||||
hostpath = data[:hostpath]
|
hostpath = data[:hostpath]
|
||||||
|
|
||||||
|
@ -39,7 +57,7 @@ module VagrantPlugins
|
||||||
args = []
|
args = []
|
||||||
args << "-path" << hostpath.gsub("/", "\\")
|
args << "-path" << hostpath.gsub("/", "\\")
|
||||||
args << "-share_name" << data[:smb_id]
|
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)
|
r = Vagrant::Util::PowerShell.execute(script_path, *args)
|
||||||
if r.exit_code != 0
|
if r.exit_code != 0
|
||||||
|
@ -82,31 +100,14 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
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
|
# This is used for defaulting the owner/group
|
||||||
ssh_info = machine.ssh_info
|
ssh_info = machine.ssh_info
|
||||||
|
|
||||||
folders.each do |id, data|
|
folders.each do |id, data|
|
||||||
data = data.dup
|
data = data.dup
|
||||||
data[:smb_host] ||= host_ip
|
data[:smb_host] ||= host_ip
|
||||||
data[:smb_username] ||= username
|
data[:smb_username] ||= @creds[:username]
|
||||||
data[:smb_password] ||= password
|
data[:smb_password] ||= @creds[:password]
|
||||||
|
|
||||||
# Default the owner/group of the folder to the SSH user
|
# Default the owner/group of the folder to the SSH user
|
||||||
data[:owner] ||= ssh_info[:username]
|
data[:owner] ||= ssh_info[:username]
|
||||||
|
|
|
@ -4,8 +4,10 @@ en:
|
||||||
Mounting SMB shared folders...
|
Mounting SMB shared folders...
|
||||||
mounting_single: |-
|
mounting_single: |-
|
||||||
%{host} => %{guest}
|
%{host} => %{guest}
|
||||||
|
preparing: |-
|
||||||
|
Preparing SMB shared folders...
|
||||||
warning_password: |-
|
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
|
folders shortly. Please use the proper username/password of your
|
||||||
Windows account.
|
Windows account.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue