-
Notifications
You must be signed in to change notification settings - Fork 2k
Replace menuinst subprocessing by ctypes win elevation #7426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
86c6f8d
Replace menuinst subprocessing by ctypes win elevation
goanpeca d23ee57
Fix flake8
goanpeca fac530d
run_as_admin code review cleanup
kalefranz 3a7eeb7
Refactor code
goanpeca fc7c671
Fix the current normal user init case
goanpeca 425d637
Fix --anaconda-prompt cli flag
goanpeca 5c6c971
Fix code style
goanpeca d1ddebe
Refactor elevation code for windows
goanpeca be137d6
Fix test on windows
goanpeca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -509,24 +509,19 @@ def run_plan_elevated(plan): | |
|
|
||
| if any(step['result'] == Result.NEEDS_SUDO for step in plan): | ||
| if on_win: | ||
| from menuinst.win_elevate import runAsAdmin | ||
| # https://github.com/ContinuumIO/menuinst/blob/master/menuinst/windows/win_elevate.py # no stdin / stdout / stderr pipe support # NOQA | ||
| # https://github.com/saltstack/salt-windows-install/blob/master/deps/salt/python/App/Lib/site-packages/win32/Demos/pipes/runproc.py # NOQA | ||
| # https://github.com/twonds/twisted/blob/master/twisted/internet/_dumbwin32proc.py | ||
| # https://stackoverflow.com/a/19982092/2127762 | ||
| # https://www.codeproject.com/Articles/19165/Vista-UAC-The-Definitive-Guide | ||
|
|
||
| # from menuinst.win_elevate import isUserAdmin, runAsAdmin | ||
| # I do think we can pipe to stdin, so we're going to have to write to a temp file and read in the elevated process # NOQA | ||
|
|
||
| from ..common.os.windows import run_as_admin | ||
| temp_path = None | ||
| try: | ||
| with NamedTemporaryFile('w+b', suffix='.json', delete=False) as tf: | ||
| # the default mode is 'w+b', and universal new lines don't work in that mode | ||
| tf.write(ensure_binary(json.dumps(plan, ensure_ascii=False))) | ||
| temp_path = tf.name | ||
| rc = runAsAdmin((sys.executable, '-m', 'conda.initialize', '"%s"' % temp_path)) | ||
| assert rc == 0 | ||
| python_exe = '"%s"' % abspath(sys.executable) | ||
| hinstance, error_code = run_as_admin((python_exe, '-m', 'conda.core.initialize', | ||
| '"%s"' % temp_path)) | ||
| if error_code is not None: | ||
| print("ERROR during elevated execution.\n rc: %s" % error_code, | ||
| file=sys.stderr) | ||
|
|
||
| with open(temp_path) as fh: | ||
| _plan = json.loads(ensure_unicode(fh.read())) | ||
|
|
@@ -537,7 +532,7 @@ def run_plan_elevated(plan): | |
| else: | ||
| stdin = json.dumps(plan) | ||
| result = subprocess_call( | ||
| 'sudo %s -m conda.initialize' % sys.executable, | ||
| 'sudo %s -m conda.core.initialize' % sys.executable, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No wonder it wasn't working!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep I told you it was a silly bug 🤣 |
||
| env={}, | ||
| path=os.getcwd(), | ||
| stdin=stdin | ||
|
|
@@ -1033,17 +1028,23 @@ def _read_windows_registry(target_path): # pragma: no cover | |
| main_key, the_rest = target_path.split('\\', 1) | ||
| subkey_str, value_name = the_rest.rsplit('\\', 1) | ||
| main_key = getattr(winreg, main_key) | ||
|
|
||
| try: | ||
| key = winreg.OpenKey(main_key, subkey_str, 0, winreg.KEY_READ) | ||
| except EnvironmentError as e: | ||
| if e.errno != ENOENT: | ||
| raise | ||
| return None, None | ||
|
|
||
| try: | ||
| value_tuple = winreg.QueryValueEx(key, value_name) | ||
| value_value = value_tuple[0].strip() | ||
| value_type = value_tuple[1] | ||
| return value_value, value_type | ||
| except Exception: | ||
| # [WinError 2] The system cannot find the file specified | ||
| winreg.CloseKey(key) | ||
| return None, None | ||
| finally: | ||
| winreg.CloseKey(key) | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I must have put that in just for debug or something 😳