From 4e2e14942f8634b143d762b9a81cdce0365a11ac Mon Sep 17 00:00:00 2001 From: Adam Wierzbicki Date: Fri, 29 Mar 2019 15:23:22 +0100 Subject: [PATCH 1/5] Revert required administrator privilege to run the Windows installer This reverts commit 815490642156daea74f016073bef28c0d53cb657. --- Installer/Installer_Win/Golem.aip | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Installer/Installer_Win/Golem.aip b/Installer/Installer_Win/Golem.aip index ceee9edda0..be2073d42b 100644 --- a/Installer/Installer_Win/Golem.aip +++ b/Installer/Installer_Win/Golem.aip @@ -326,7 +326,7 @@ - + From 7e014a367559827b1ed5334121dfc7560b35f552 Mon Sep 17 00:00:00 2001 From: Adam Wierzbicki Date: Mon, 1 Apr 2019 16:49:44 +0200 Subject: [PATCH 2/5] A powershell script to elevate privileges --- Installer/Installer_Win/Golem.aip | 6 ++- scripts/docker/prepare-docker-as-admin.ps1 | 16 +++++++ scripts/docker/prepare-docker-for-windows.ps1 | 20 +------- scripts/run-as-admin.ps1 | 48 +++++++++++++++++++ 4 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 scripts/docker/prepare-docker-as-admin.ps1 create mode 100644 scripts/run-as-admin.ps1 diff --git a/Installer/Installer_Win/Golem.aip b/Installer/Installer_Win/Golem.aip index be2073d42b..2e9585ab99 100644 --- a/Installer/Installer_Win/Golem.aip +++ b/Installer/Installer_Win/Golem.aip @@ -406,7 +406,7 @@ - + @@ -468,7 +468,7 @@ - + @@ -690,6 +690,8 @@ + + diff --git a/scripts/docker/prepare-docker-as-admin.ps1 b/scripts/docker/prepare-docker-as-admin.ps1 new file mode 100644 index 0000000000..701216e627 --- /dev/null +++ b/scripts/docker/prepare-docker-as-admin.ps1 @@ -0,0 +1,16 @@ +$ErrorActionPreference = "Stop" +[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 + +$CurrentUserName = (AI_GetMsiProperty USERNAME) +# FIXME: LocalAppDataFolder property points to admin's AppData folder +$AppDataDir = (AI_GetMsiProperty LocalAppDataFolder) + +$RunAsAdminScript = (AI_GetMsiProperty AI_RUN_AS_ADMIN_FILE) +"RunAsAdminScript: " + $RunAsAdminScript +$PrepareDockerScript = (AI_GetMsiProperty AI_PREPARE_DOCKER_FILE) +"PrepareDockerScript: " + $PrepareDockerScript +$CreateShareScript = (AI_GetMsiProperty AI_CREATESHARE_FILE) +"CreateShareScript: " + $CreateShareScript + +&"$RunAsAdminScript" -ScriptPath "$PrepareDockerScript" ` + -ScriptParams "-createShareScript `"$CreateShareScript`" -appDataDir `"$AppDataDir`" -currentUserName `"$currentUserName`"" diff --git a/scripts/docker/prepare-docker-for-windows.ps1 b/scripts/docker/prepare-docker-for-windows.ps1 index 21b8ed3dfa..a5a79e3e30 100644 --- a/scripts/docker/prepare-docker-for-windows.ps1 +++ b/scripts/docker/prepare-docker-for-windows.ps1 @@ -1,26 +1,12 @@ # Block for declaring the script parameters. Param( - $createShareFolder = "", + $createShareScript = "", $appDataDir = "", - $currentUserName = "", - $productVersion = "" + $currentUserName = "" ) -if (Get-Command "AI_GetMsiProperty" -errorAction SilentlyContinue) -{ - $createShareFolder = (AI_GetMsiProperty TempFolder) - $appDataDir = (AI_GetMsiProperty LocalAppDataFolder) - $currentUserName = (AI_GetMsiProperty LogonUser) - $productVersion = (AI_GetMsiProperty ProductVersion) -} - $ErrorActionPreference = "Stop" -if ($productVersion) -{ - $createShareFolder += $productVersion + "\" -} - # Your code goes here. $golemUserName = "golem-docker" "golemUserName: " + $golemUserName @@ -39,8 +25,6 @@ if( ! $currentGolemUser ) "createShareFolder: " + $createShareFolder "appDataDir: " + $appDataDir -$createShareScript = $createShareFolder + "create-share.ps1" -"createShareScript: " + $createShareScript $golemDataDir = $appDataDir + "\golem\golem\default" $mainnetDir = $golemDataDir + "\mainnet\ComputerRes" diff --git a/scripts/run-as-admin.ps1 b/scripts/run-as-admin.ps1 new file mode 100644 index 0000000000..2ac9a7d438 --- /dev/null +++ b/scripts/run-as-admin.ps1 @@ -0,0 +1,48 @@ +<# + +.SYNOPSIS +This is a script for running an arbitrary powershell script with administrator privileges. + +.EXAMPLE +.\run-as-admin.ps1 -ScriptPath "C:\Users\golem\my-script.ps1" -ScriptParams "-Param1 `"this is example`"" + +#> + +param( + [Parameter(Mandatory=$true)] [string] $ScriptPath, + [Parameter(Mandatory=$false)] [string] $ScriptParams = "" +) + +$ErrorActionPreference = "Stop" +[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 + +# Convert path to absolute +$ScriptPath = Convert-Path -Path $ScriptPath + +# Creating temporary files for capturing stout & stderr +$StdoutPath = (New-TemporaryFile).FullName +$StderrPath = (New-TemporaryFile).FullName +$TmpScriptPath = "$env:TEMP/tmp-script.ps1" + +# Generate code for a script that will capture the original script's stdout & stderr +# This is done because powershell cannot redirect output of a process started with 'RunAs' verb +@" +`$ErrorActionPreference = "Stop" +[Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 + +try { + &"$ScriptPath" $ScriptParams >"$StdoutPath" 2>"$StderrPath" +} catch { + `$_ | Out-File -FilePath "$StderrPath" -Encoding "UTF8" + throw +} +"@ | Out-File -Encoding "UTF8" -FilePath $TmpScriptPath + +$Process = Start-Process -FilePath "powershell.exe" ` + -ArgumentList "-NoProfile -NoLogo -ExecutionPolicy RemoteSigned `"$TmpScriptPath`"" ` + -Wait -PassThru -Verb RunAs -WindowStyle Hidden + +Get-Content -Encoding "UTF8" -Path $StdoutPath | Write-Output +Get-Content -Encoding "UTF8" -Path $StderrPath | Write-Error + +exit $Process.ExitCode From 17fa73fa688a5166ac0bda25075420db086bffc7 Mon Sep 17 00:00:00 2001 From: maaktweluit <10008353+maaktweluit@users.noreply.github.com> Date: Tue, 2 Apr 2019 13:05:28 +0200 Subject: [PATCH 3/5] Get LocalAppData folder from the temp scripts --- scripts/docker/prepare-docker-as-admin.ps1 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/docker/prepare-docker-as-admin.ps1 b/scripts/docker/prepare-docker-as-admin.ps1 index 701216e627..694e64627d 100644 --- a/scripts/docker/prepare-docker-as-admin.ps1 +++ b/scripts/docker/prepare-docker-as-admin.ps1 @@ -1,10 +1,6 @@ $ErrorActionPreference = "Stop" [Console]::OutputEncoding = [Text.UTF8Encoding]::UTF8 -$CurrentUserName = (AI_GetMsiProperty USERNAME) -# FIXME: LocalAppDataFolder property points to admin's AppData folder -$AppDataDir = (AI_GetMsiProperty LocalAppDataFolder) - $RunAsAdminScript = (AI_GetMsiProperty AI_RUN_AS_ADMIN_FILE) "RunAsAdminScript: " + $RunAsAdminScript $PrepareDockerScript = (AI_GetMsiProperty AI_PREPARE_DOCKER_FILE) @@ -12,5 +8,12 @@ $PrepareDockerScript = (AI_GetMsiProperty AI_PREPARE_DOCKER_FILE) $CreateShareScript = (AI_GetMsiProperty AI_CREATESHARE_FILE) "CreateShareScript: " + $CreateShareScript +# FIXME: LocalAppDataFolder property points to admin's AppData folder +# $AppDataDir = (AI_GetMsiProperty LocalAppDataFolder) +# For now we use the default temp folder used by the installer +$pathList = $RunAsAdminScript -split "\\Temp" +$AppDataDir = $pathList[0] +"AppDataDir: " + $AppDataDir + &"$RunAsAdminScript" -ScriptPath "$PrepareDockerScript" ` -ScriptParams "-createShareScript `"$CreateShareScript`" -appDataDir `"$AppDataDir`" -currentUserName `"$currentUserName`"" From 9274bc5514a4136ff6ff663e7ff216a8925774a7 Mon Sep 17 00:00:00 2001 From: maaktweluit <10008353+maaktweluit@users.noreply.github.com> Date: Tue, 2 Apr 2019 14:38:38 +0200 Subject: [PATCH 4/5] Fetch current user name from installer --- scripts/docker/prepare-docker-as-admin.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/docker/prepare-docker-as-admin.ps1 b/scripts/docker/prepare-docker-as-admin.ps1 index 694e64627d..fce8a8c459 100644 --- a/scripts/docker/prepare-docker-as-admin.ps1 +++ b/scripts/docker/prepare-docker-as-admin.ps1 @@ -7,6 +7,10 @@ $PrepareDockerScript = (AI_GetMsiProperty AI_PREPARE_DOCKER_FILE) "PrepareDockerScript: " + $PrepareDockerScript $CreateShareScript = (AI_GetMsiProperty AI_CREATESHARE_FILE) "CreateShareScript: " + $CreateShareScript +$currentUserName = (AI_GetMsiProperty LogonUser) +"currentUserName: " + $currentUserName + + # FIXME: LocalAppDataFolder property points to admin's AppData folder # $AppDataDir = (AI_GetMsiProperty LocalAppDataFolder) From 7ae2faccf4bc38b68e7b5dfe98529cb47d4e20d8 Mon Sep 17 00:00:00 2001 From: maaktweluit <10008353+maaktweluit@users.noreply.github.com> Date: Tue, 2 Apr 2019 15:27:23 +0200 Subject: [PATCH 5/5] Store running user at the start of the installer --- Installer/Installer_Win/Golem.aip | 2 ++ scripts/docker/prepare-docker-as-admin.ps1 | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Installer/Installer_Win/Golem.aip b/Installer/Installer_Win/Golem.aip index 2e9585ab99..83c7b303dc 100644 --- a/Installer/Installer_Win/Golem.aip +++ b/Installer/Installer_Win/Golem.aip @@ -522,6 +522,7 @@ + @@ -614,6 +615,7 @@ + diff --git a/scripts/docker/prepare-docker-as-admin.ps1 b/scripts/docker/prepare-docker-as-admin.ps1 index fce8a8c459..59d746aceb 100644 --- a/scripts/docker/prepare-docker-as-admin.ps1 +++ b/scripts/docker/prepare-docker-as-admin.ps1 @@ -7,11 +7,9 @@ $PrepareDockerScript = (AI_GetMsiProperty AI_PREPARE_DOCKER_FILE) "PrepareDockerScript: " + $PrepareDockerScript $CreateShareScript = (AI_GetMsiProperty AI_CREATESHARE_FILE) "CreateShareScript: " + $CreateShareScript -$currentUserName = (AI_GetMsiProperty LogonUser) +$currentUserName = (AI_GetMsiProperty RUNNING_USER) "currentUserName: " + $currentUserName - - # FIXME: LocalAppDataFolder property points to admin's AppData folder # $AppDataDir = (AI_GetMsiProperty LocalAppDataFolder) # For now we use the default temp folder used by the installer