Skip to content

Conversation

JeremyRand
Copy link
Contributor

The Bitcoin Core NSIS script runs with elevated privileges. Unfortunately, this means that it launches Bitcoin Core itself with elevated privileges when the user chooses to launch Bitcoin Core at the end of the installation procedure. This PR works around the issue by having explorer.exe launch Bitcoin Core. Seems to be a similar approach to what http://nsis.sourceforge.net/ShellExecAsUser_plug-in does, but without a plugin.

I've tested this with Sysinternals Process Explorer on Windows 10 32-bit. I wouldn't expect any differences in behavior on other Windows releases, but if anyone would like to test on other Windows releases, feel free.

h/t to "UK" at https://mdb-blog.blogspot.se/2013/01/nsis-lunch-program-as-user-from-uac.html?showComment=1410158039989#c2463780017054126736 for the sample code.

Fixes #7990.

The Bitcoin Core NSIS script runs with elevated privileges.  Unfortunately, this means that it launches Bitcoin Core itself with elevated privileges when the user chooses to launch Bitcoin Core at the end of the installation procedure.  This commit works around the issue by having explorer.exe launch Bitcoin Core.  Seems to be a similar approach to what http://nsis.sourceforge.net/ShellExecAsUser_plug-in does, but without a plugin.

h/t to "UK" at https://mdb-blog.blogspot.se/2013/01/nsis-lunch-program-as-user-from-uac.html?showComment=1410158039989#c2463780017054126736 for the sample code.

Fixes bitcoin#7990.
Copy link
Contributor

@ken2812221 ken2812221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK 7d8a8cc

@fanquake
Copy link
Member

@ken2812221 Could you provide the basic steps you used to test this, so anyone else can recreate on a Windows VM?

@ken2812221
Copy link
Contributor

@fanquake I just add wallet=C:\Windows\xxxx to my config file.

if bitcoin core has higher privilege, it can successfully create the directory, otherwise it crash

@laanwj
Copy link
Member

laanwj commented Apr 16, 2018

Concept ACK - would like to see some more tested ACKs.

@jonasschnelli
Copy link
Contributor

Gitian build is here: https://bitcoin.jonasschnelli.ch/build/573

@fanquake
Copy link
Member

fanquake commented Apr 18, 2018

I've tested this using the method @ken2812221 suggested. Basically create a bitcoin.conf with

wallet=C:\Windows\xxxx

If you then install 0.16.0, and choose to run at the end of the installation, Core will error on startup, because we can't specify a path as a wallet name.
error

2018-04-18 04:48:31 Using 4 threads for script verification
2018-04-18 04:48:31 scheduler thread start
2018-04-18 04:48:31 Using wallet directory C:\Users\User\AppData\Roaming\Bitcoin\wallets
2018-04-18 04:48:31 init message: Verifying wallet(s)...
2018-04-18 04:48:41 Shutdown: In progress...
2018-04-18 04:48:41 scheduler thread interrupt
2018-04-18 04:48:41 Shutdown: done

However if you then install the gitian build provided by @jonasschnelli, and launch Core at the end of the installation, we get an exception. Looking at the debug.log, we no longer have access to C:\Windows\.
fatal exception

2018-04-18T04:40:39Z init message: Verifying wallet(s)...
2018-04-18T04:40:39Z Using BerkeleyDB version Berkeley DB 4.8.30: (April  9, 2010)
2018-04-18T04:40:39Z Using wallet wallet.dat
2018-04-18T04:40:39Z 

************************
EXCEPTION: N5boost10filesystem16filesystem_errorE       
boost::filesystem::create_directory: Access is denied: "C:\Windows\xxxx"       
C:\Program Files\Bitcoin\bitcoin-qt.exe in Runaway exception   

@laanwj
Copy link
Member

laanwj commented Apr 18, 2018

@fanquake Thanks for testing. To be clear: All in all that seems a positive result? I suppose you used C:\windows as a path that bitcoin core is supposed to not have access to?

@fanquake
Copy link
Member

@laanwj Yes, I think it's a positive result. Core should not have access to write files into C:\Windows\.

@laanwj laanwj added this to the 0.16.1 milestone Apr 18, 2018
@laanwj
Copy link
Member

laanwj commented Apr 18, 2018

Right - it's similar to /usr/. I've kind of forgot about windows things somewhat.
Looks good to me, then. Also added "to backport" as sane installer behavior is very important.

@laanwj laanwj merged commit 7d8a8cc into bitcoin:master Apr 18, 2018
laanwj added a commit that referenced this pull request Apr 18, 2018
…nds.

7d8a8cc Avoid launching as admin when NSIS installer ends. (JeremyRand)

Pull request description:

  The Bitcoin Core NSIS script runs with elevated privileges.  Unfortunately, this means that it launches Bitcoin Core itself with elevated privileges when the user chooses to launch Bitcoin Core at the end of the installation procedure.  This PR works around the issue by having `explorer.exe` launch Bitcoin Core.  Seems to be a similar approach to what http://nsis.sourceforge.net/ShellExecAsUser_plug-in does, but without a plugin.

  I've tested this with Sysinternals Process Explorer on Windows 10 32-bit.  I wouldn't expect any differences in behavior on other Windows releases, but if anyone would like to test on other Windows releases, feel free.

  h/t to "UK" at https://mdb-blog.blogspot.se/2013/01/nsis-lunch-program-as-user-from-uac.html?showComment=1410158039989#c2463780017054126736 for the sample code.

  Fixes #7990.

Tree-SHA512: f40d6b6e5bb72952dcfbf223b68bfeb9a03bd5638f41b1700f4651f6452ce3fe7468129f6652c4f546210a5fd2521b2574c4b6068c5aea01ed2d719a8a838cd8
@fanquake fanquake mentioned this pull request Apr 18, 2018
@Michagogo
Copy link
Contributor

@JeremyRand
Copy link
Contributor Author

@Michagogo I'm not sure whom at Microsoft Ericlaw talked to (he doesn't give any citation), but Microsoft has recommended the approach of using explorer.exe for this.

@Michagogo
Copy link
Contributor

Michagogo commented Apr 19, 2018 via email

@JeremyRand
Copy link
Contributor Author

@Michagogo the Microsoft page I linked says:

The solution here is to go back to Explorer and ask Explorer to launch the program for you. Since Explorer is running as the original unelevated user, the program (in this case, the Web browser) will run as Bob.

So while I haven't audited the Microsoft sample code to verify that it does that (Windows C API's aren't my specialty), I think it's reasonable to infer that the Microsoft sample code matches the Microsoft description (which matches what this PR does).

@Michagogo
Copy link
Contributor

Michagogo commented Apr 19, 2018 via email

fanquake pushed a commit to fanquake/bitcoin that referenced this pull request Apr 26, 2018
The Bitcoin Core NSIS script runs with elevated privileges.  Unfortunately, this means that it launches Bitcoin Core itself with elevated privileges when the user chooses to launch Bitcoin Core at the end of the installation procedure.  This commit works around the issue by having explorer.exe launch Bitcoin Core.  Seems to be a similar approach to what http://nsis.sourceforge.net/ShellExecAsUser_plug-in does, but without a plugin.

h/t to "UK" at https://mdb-blog.blogspot.se/2013/01/nsis-lunch-program-as-user-from-uac.html?showComment=1410158039989#c2463780017054126736 for the sample code.

Fixes bitcoin#7990.

GitHub-Pull: bitcoin#12985
Rebased-From: 7d8a8cc
laanwj added a commit that referenced this pull request May 16, 2018
8fca086 List support for BIP173 in bips.md (Pieter Wuille)
9645aa6 Remove blockmaxsize option from init.cpp (fanquake)
7847b92 Default to defining endian-conversion DECLs in compat w/o config (Matt Corallo)
1720eb3 qt:Show the entire Window when double clicking on taskbar (Chun Kuan Lee)
e055bc0 depends: Fix Qt build with XCode 9.3 (fanquake)
0684cf9 Avoid launching as admin when NSIS installer ends. (JeremyRand)
e802c22 [config] Remove blockmaxsize option (John Newbery)
f118a7a Fix illegal default `addProxy` and `addrSeparateProxyTor` settings. (251)
f60e84d Limit the number of IPs we use from each DNS seeder (e0)

Pull request description:

  Backports:
  - #12626 Limit the number of IPs addrman learns from each DNS seeder
  - #12650 gui: Fix issue: "default port not shown correctly in settings dialog"
  - #12756 [config] Remove blockmaxsize option
  - #12985 Windows: Avoid launching as admin when NSIS installer ends.
  - #12946 depends: Fix Qt build with XCode 9.3
  - #12998 Default to defining endian-conversion DECLs in compat w/o config
  - #12999 qt: Show the Window when double clicking the taskbar icon
  - #13064 List support for BIP173 in bips.md

  to the 0.16 branch.

Tree-SHA512: 3e6b47c54b2cd2bdd81fbc6176cb31e46423f6e05988984d3a09b3535e3cee101ffb071cf753a4beff3c9f0521eb5de4b7c0424a3e97da801d56b4015847ac0f
HashUnlimited pushed a commit to chaincoin/chaincoin that referenced this pull request Jun 29, 2018
The Bitcoin Core NSIS script runs with elevated privileges.  Unfortunately, this means that it launches Bitcoin Core itself with elevated privileges when the user chooses to launch Bitcoin Core at the end of the installation procedure.  This commit works around the issue by having explorer.exe launch Bitcoin Core.  Seems to be a similar approach to what http://nsis.sourceforge.net/ShellExecAsUser_plug-in does, but without a plugin.

h/t to "UK" at https://mdb-blog.blogspot.se/2013/01/nsis-lunch-program-as-user-from-uac.html?showComment=1410158039989#c2463780017054126736 for the sample code.

Fixes bitcoin#7990.

GitHub-Pull: bitcoin#12985
Rebased-From: 7d8a8cc
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Apr 3, 2020
…aller ends.

7d8a8cc Avoid launching as admin when NSIS installer ends. (JeremyRand)

Pull request description:

  The Bitcoin Core NSIS script runs with elevated privileges.  Unfortunately, this means that it launches Bitcoin Core itself with elevated privileges when the user chooses to launch Bitcoin Core at the end of the installation procedure.  This PR works around the issue by having `explorer.exe` launch Bitcoin Core.  Seems to be a similar approach to what http://nsis.sourceforge.net/ShellExecAsUser_plug-in does, but without a plugin.

  I've tested this with Sysinternals Process Explorer on Windows 10 32-bit.  I wouldn't expect any differences in behavior on other Windows releases, but if anyone would like to test on other Windows releases, feel free.

  h/t to "UK" at https://mdb-blog.blogspot.se/2013/01/nsis-lunch-program-as-user-from-uac.html?showComment=1410158039989#c2463780017054126736 for the sample code.

  Fixes bitcoin#7990.

Tree-SHA512: f40d6b6e5bb72952dcfbf223b68bfeb9a03bd5638f41b1700f4651f6452ce3fe7468129f6652c4f546210a5fd2521b2574c4b6068c5aea01ed2d719a8a838cd8
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
@JeremyRand JeremyRand deleted the nsis-de-elevate branch February 13, 2022 09:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows installer launches GUI as Admin
6 participants