diff --git a/plugins/hosts/windows/cap/smb.rb b/plugins/hosts/windows/cap/smb.rb index 02e98da337b..da0cbc6a8fc 100644 --- a/plugins/hosts/windows/cap/smb.rb +++ b/plugins/hosts/windows/cap/smb.rb @@ -51,10 +51,8 @@ def self.smb_cleanup(env, machine, opts) @@logger.debug("shares to be removed: #{prune_shares}") if prune_shares.size > 0 - machine.env.ui.warn("\n" + I18n.t("vagrant_sf_smb.uac.prune_warning") + "\n") - sleep UAC_PROMPT_WAIT @@logger.info("remove shares: #{prune_shares}") - result = Vagrant::Util::PowerShell.execute(script_path, *prune_shares, sudo: true) + result = Vagrant::Util::PowerShell.execute(script_path, *prune_shares, sudo: false) if result.exit_code != 0 failed_name = result.stdout.to_s.sub("share name: ", "") raise SyncedFolderSMB::Errors::PruneShareFailed, @@ -100,14 +98,8 @@ def self.smb_prepare(env, machine, folders, opts) ] end if !shares.empty? - uac_notified = false shares.each_slice(10) do |s_shares| - if !uac_notified - machine.env.ui.warn("\n" + I18n.t("vagrant_sf_smb.uac.create_warning") + "\n") - uac_notified = true - sleep(UAC_PROMPT_WAIT) - end - result = Vagrant::Util::PowerShell.execute(script_path, *s_shares, sudo: true) + result = Vagrant::Util::PowerShell.execute(script_path, *s_shares, sudo: false) if result.exit_code != 0 share_path = result.stdout.to_s.sub("share path: ", "") raise SyncedFolderSMB::Errors::DefineShareFailed, diff --git a/plugins/hosts/windows/scripts/set_share.ps1 b/plugins/hosts/windows/scripts/set_share.ps1 index b483088af82..e3763928922 100644 --- a/plugins/hosts/windows/scripts/set_share.ps1 +++ b/plugins/hosts/windows/scripts/set_share.ps1 @@ -1,37 +1,36 @@ +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' + # The names of the user are language dependent! $objSID = New-Object System.Security.Principal.SecurityIdentifier("S-1-1-0") $objUser = $objSID.Translate([System.Security.Principal.NTAccount]) -$grant = "$objUser,Full" - -for ($i=0; $i -le $args.length; $i = $i + 3) { +for ($i = 0; ($i+2) -lt $args.length; $i = $i + 3) { $path = $args[$i] $share_name = $args[$i+1] $share_id = $args[$i+2] - - if ($path -eq $null) { - Write-Warning "empty path argument encountered - complete" - exit 0 + if (!$path) { + Write-Error "error - no share path provided" + exit 1 } - if ($share_name -eq $null) { + if (!$share_name) { Write-Output "share path: ${path}" Write-Error "error - no share name provided" exit 1 } - if ($share_id -eq $null) { + if (!$share_id) { Write-Output "share path: ${path}" Write-Error "error - no share ID provided" exit 1 } - $result = net share $share_id=$path /unlimited /GRANT:$grant /REMARK:"${share_name}" - if ($LastExitCode -ne 0) { - $host.ui.WriteLine("share path: ${path}") - $host.ui.WriteErrorLine("error ${result}") - exit 1 - } + New-SmbShare ` + -Name $share_id ` + -Path $path ` + -FullAccess $objUser ` + -Description $share_name } exit 0 diff --git a/plugins/hosts/windows/scripts/unset_share.ps1 b/plugins/hosts/windows/scripts/unset_share.ps1 index 69dad89d12c..6da7dcdc3d5 100644 --- a/plugins/hosts/windows/scripts/unset_share.ps1 +++ b/plugins/hosts/windows/scripts/unset_share.ps1 @@ -1,10 +1,10 @@ +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' + ForEach ($share_name in $args) { - $result = net share $share_name /DELETE /YES - if ($LastExitCode -ne 0) { - Write-Output "share name: ${share_name}" - Write-Error "error - ${result}" - exit 1 - } + Remove-SmbShare ` + -Name $share_name ` + -Force } Write-Output "share removal completed" exit 0 diff --git a/templates/locales/synced_folder_smb.yml b/templates/locales/synced_folder_smb.yml index 3819f8b32e2..5e2eafea83e 100644 --- a/templates/locales/synced_folder_smb.yml +++ b/templates/locales/synced_folder_smb.yml @@ -13,13 +13,6 @@ en: incorrect_credentials: |- Credentials incorrect. Please try again. - uac: - prune_warning: |- - Vagrant requires administrator access for pruning SMB shares and - may request access to complete removal of stale shares. - create_warning: |- - Vagrant requires administrator access to create SMB shares and - may request access to complete setup of configured shares. errors: not_supported: |- It appears your machine doesn't support SMB, has not been diff --git a/test/unit/plugins/hosts/windows/cap/smb_test.rb b/test/unit/plugins/hosts/windows/cap/smb_test.rb index 03f044b1e0d..1ee7d0d97ca 100644 --- a/test/unit/plugins/hosts/windows/cap/smb_test.rb +++ b/test/unit/plugins/hosts/windows/cap/smb_test.rb @@ -101,11 +101,6 @@ end after{ subject.smb_cleanup(env, machine, options) } - it "should pause after warning user" do - expect(machine.env.ui).to receive(:warn).and_call_original - expect(subject).to receive(:sleep) - end - it "should remove owned shares" do expect(Vagrant::Util::PowerShell).to receive(:execute) do |*args| expect(args).to include("vgt-CUSTOM_ID-1") @@ -122,7 +117,7 @@ end it "should remove all shares in single call" do - expect(Vagrant::Util::PowerShell).to receive(:execute).with(any_args, sudo: true).once + expect(Vagrant::Util::PowerShell).to receive(:execute).with(any_args, sudo: false).once end context "when no shares are defined" do @@ -182,14 +177,8 @@ expect(folders["/second/path"][:smb_id]).to eq("ID1") end - it "should pause after warning user" do - expect(machine.env.ui).to receive(:warn).and_call_original - expect(subject).to receive(:sleep) - subject.smb_prepare(env, machine, folders, options) - end - it "should add all shares in single call" do - expect(Vagrant::Util::PowerShell).to receive(:execute).with(any_args, sudo: true).once + expect(Vagrant::Util::PowerShell).to receive(:execute).with(any_args, sudo: false).once subject.smb_prepare(env, machine, folders, options) end @@ -236,7 +225,7 @@ after{ subject.smb_prepare(env, machine, folders, options) } it "should execute multiple powershell commands" do - expect(Vagrant::Util::PowerShell).to receive(:execute).twice.with(any_args, sudo: true) + expect(Vagrant::Util::PowerShell).to receive(:execute).twice.with(any_args, sudo: false) end end end