Check SMB credentials before using them
This commit is contained in:
parent
6ef63de244
commit
01bc2627be
|
@ -0,0 +1,19 @@
|
|||
Param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$username,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]$password
|
||||
)
|
||||
|
||||
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
|
||||
|
||||
$DSContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext(
|
||||
[System.DirectoryServices.AccountManagement.ContextType]::Machine,
|
||||
$env:COMPUTERNAME
|
||||
)
|
||||
|
||||
if ( $DSContext.ValidateCredentials( $username, $password ) ) {
|
||||
exit 0
|
||||
} else {
|
||||
exit 1
|
||||
}
|
|
@ -30,11 +30,6 @@ module VagrantPlugins
|
|||
def prepare(machine, folders, opts)
|
||||
machine.ui.output(I18n.t("vagrant_sf_smb.preparing"))
|
||||
|
||||
# Check if this host can start and SMB service
|
||||
if machine.env.host.capability?(:smb_start)
|
||||
machine.env.host.capability(:smb_start)
|
||||
end
|
||||
|
||||
smb_username = smb_password = nil
|
||||
|
||||
# If we need auth information, then ask the user.
|
||||
|
@ -48,12 +43,38 @@ module VagrantPlugins
|
|||
end
|
||||
end
|
||||
|
||||
script_path = File.expand_path("../scripts/check_credentials.ps1", __FILE__)
|
||||
|
||||
if !have_auth
|
||||
machine.env.ui.detail(I18n.t("vagrant_sf_smb.warning_password") + "\n ")
|
||||
smb_username = machine.env.ui.ask("Username: ")
|
||||
smb_password = machine.env.ui.ask("Password (will be hidden): ", echo: false)
|
||||
machine.ui.detail(I18n.t("vagrant_sf_smb.warning_password") + "\n ")
|
||||
auth_success = false
|
||||
while !auth_success do
|
||||
@creds[:username] = machine.ui.ask("Username: ")
|
||||
@creds[:password] = machine.ui.ask("Password (will be hidden): ", echo: false)
|
||||
|
||||
args = []
|
||||
args << "-username" << "'#{@creds[:username].gsub("'", "''")}'"
|
||||
args << "-password" << "'#{@creds[:password].gsub("'", "''")}'"
|
||||
|
||||
r = Vagrant::Util::PowerShell.execute(script_path, *args)
|
||||
|
||||
if r.exit_code == 0
|
||||
auth_success = true
|
||||
end
|
||||
|
||||
if !auth_success
|
||||
machine.ui.output(I18n.t("vagrant_sf_smb.incorrect_credentials") + "\n ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Check if this host can start and SMB service
|
||||
if machine.env.host.capability?(:smb_start)
|
||||
machine.env.host.capability(:smb_start)
|
||||
end
|
||||
|
||||
script_path = File.expand_path("../scripts/set_share.ps1", __FILE__)
|
||||
|
||||
folders.each do |id, data|
|
||||
data[:smb_username] ||= smb_username
|
||||
data[:smb_password] ||= smb_password
|
||||
|
|
|
@ -15,6 +15,8 @@ en:
|
|||
You will be asked for the username and password to use for the SMB
|
||||
folders shortly. Please use the proper username/password of your
|
||||
account.
|
||||
incorrect_credentials: |-
|
||||
Credentials incorrect. Please try again.
|
||||
|
||||
uac:
|
||||
prune_warning: |-
|
||||
|
|
Loading…
Reference in New Issue