From 993b9ea5cd1893d9f6cda3b45055ce804fad0752 Mon Sep 17 00:00:00 2001 From: Marco Esters Date: Thu, 17 Oct 2024 10:14:08 -0700 Subject: [PATCH] Backport v2 privilege elevation logic to v1 (#260) * Backport v2 handling of privilege elevation to v1 legacy code * Add news file * Only use .nonadmin files for privilege elevation logic * Ensure that .nonadmin files do not exists before asking for privilege elevation --- menuinst/_legacy/__init__.py | 8 +++----- news/260-backport-v2-admin-to-v1 | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 news/260-backport-v2-admin-to-v1 diff --git a/menuinst/_legacy/__init__.py b/menuinst/_legacy/__init__.py index 18968f42..9726eabf 100644 --- a/menuinst/_legacy/__init__.py +++ b/menuinst/_legacy/__init__.py @@ -14,7 +14,7 @@ except ImportError: __version__ = "dev" -from ..utils import DEFAULT_BASE_PREFIX, DEFAULT_PREFIX +from ..utils import DEFAULT_BASE_PREFIX, DEFAULT_PREFIX, python_executable if sys.platform == 'win32': from ..platforms.win_utils.win_elevate import isUserAdmin, runAsAdmin @@ -59,9 +59,7 @@ def install(path, remove=False, prefix=None, recursing=False, root_prefix=None): if not sys.platform == 'win32': raise RuntimeError("menuinst._legacy is only supported on Windows.") - # this root_prefix is intentional. We want to reflect the state of the root installation. - - if not exists(join(root_prefix, '.nonadmin')): + if not exists(join(prefix, ".nonadmin")) and not exists(join(root_prefix, ".nonadmin")): if isUserAdmin(): _install(path, remove, prefix, mode='system', root_prefix=root_prefix) else: @@ -70,7 +68,7 @@ def install(path, remove=False, prefix=None, recursing=False, root_prefix=None): if not recursing: retcode = runAsAdmin( [ - join(root_prefix, 'python'), + *python_executable(), '-c', "import menuinst; menuinst.install(%r, %r, %r, %r, %r)" % (path, bool(remove), prefix, True, root_prefix), diff --git a/news/260-backport-v2-admin-to-v1 b/news/260-backport-v2-admin-to-v1 new file mode 100644 index 00000000..7947d50c --- /dev/null +++ b/news/260-backport-v2-admin-to-v1 @@ -0,0 +1,19 @@ +### Enhancements + +* Partially backport privilege elevation logic from v2 to v1. (#260) + +### Bug fixes + +* + +### Deprecations + +* + +### Docs + +* + +### Other + +*