From 8fb2ee4b836be2e905cfc8be0f6849216281e266 Mon Sep 17 00:00:00 2001 From: Mykola Grymalyuk Date: Mon, 27 May 2024 17:11:28 -0600 Subject: [PATCH] =?UTF-8?q?Remove=20stop=20gap=20=E2=80=9Csupports=5Fprivi?= =?UTF-8?q?leged=5Fhelper()=E2=80=9D=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Intended to handle transition better, now that it’s complete the code is no longer required --- .../support/global_settings.py | 3 --- opencore_legacy_patcher/support/install.py | 23 ++++--------------- .../support/kdk_handler.py | 16 ------------- .../support/logging_handler.py | 3 --- .../support/macos_installer_handler.py | 23 ++++--------------- .../support/subprocess_wrapper.py | 22 ------------------ .../sys_patch/sys_patch_auto.py | 6 +---- .../wx_gui/gui_settings.py | 22 +++++++----------- opencore_legacy_patcher/wx_gui/gui_support.py | 5 ---- 9 files changed, 19 insertions(+), 104 deletions(-) diff --git a/opencore_legacy_patcher/support/global_settings.py b/opencore_legacy_patcher/support/global_settings.py index b4ac0acb2..f02ff9b6a 100644 --- a/opencore_legacy_patcher/support/global_settings.py +++ b/opencore_legacy_patcher/support/global_settings.py @@ -116,9 +116,6 @@ class GlobalEnviromentSettings: This in turn breaks normal OCLP execution to write to settings file """ - if os.geteuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False: - return - # Set file permission to allow any user to write to log file result = subprocess_wrapper.run_as_root(["/bin/chmod", "777", self.global_settings_plist], capture_output=True) if result.returncode != 0: diff --git a/opencore_legacy_patcher/support/install.py b/opencore_legacy_patcher/support/install.py index b95c81934..5f1e4878c 100644 --- a/opencore_legacy_patcher/support/install.py +++ b/opencore_legacy_patcher/support/install.py @@ -92,24 +92,11 @@ class tui_disk_installation: def install_opencore(self, full_disk_identifier: str): # TODO: Apple Script fails in Yosemite(?) and older logging.info(f"Mounting partition: {full_disk_identifier}") - if self.constants.detected_os >= os_data.os_data.el_capitan and not self.constants.recovery_status and subprocess_wrapper.supports_privileged_helper() is False: - try: - applescript.AppleScript(f'''do shell script "diskutil mount {full_disk_identifier}" with prompt "OpenCore Legacy Patcher needs administrator privileges to mount this volume." with administrator privileges without altering line endings''').run() - except applescript.ScriptError as e: - if "User canceled" in str(e): - logging.info("Mount cancelled by user") - return - logging.info(f"An error occurred: {e}") - if utilities.check_boot_mode() == "safe_boot": - logging.info("\nSafe Mode detected. FAT32 is unsupported by macOS in this mode.") - logging.info("Please disable Safe Mode and try again.") - return - else: - result = subprocess_wrapper.run_as_root(["/usr/sbin/diskutil", "mount", full_disk_identifier], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - if result.returncode != 0: - logging.info("Mount failed") - subprocess_wrapper.log(result) - return + result = subprocess_wrapper.run_as_root(["/usr/sbin/diskutil", "mount", full_disk_identifier], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if result.returncode != 0: + logging.info("Mount failed") + subprocess_wrapper.log(result) + return partition_info = plistlib.loads(subprocess.run(["/usr/sbin/diskutil", "info", "-plist", full_disk_identifier], stdout=subprocess.PIPE).stdout.decode().strip().encode()) parent_disk = partition_info["ParentWholeDisk"] diff --git a/opencore_legacy_patcher/support/kdk_handler.py b/opencore_legacy_patcher/support/kdk_handler.py index ea46ee264..e3ad672fe 100644 --- a/opencore_legacy_patcher/support/kdk_handler.py +++ b/opencore_legacy_patcher/support/kdk_handler.py @@ -464,10 +464,6 @@ class KernelDebugKitObject: if self.passive is True: return - if os.getuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False: - logging.warning("Cannot remove KDK, not running as root") - return - if not Path(kdk_path).exists(): logging.warning(f"KDK does not exist: {kdk_path}") return @@ -579,10 +575,6 @@ class KernelDebugKitUtilities: bool: True if successful, False if not """ - if os.getuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False: - logging.warning("Cannot install KDK, not running as root") - return False - logging.info(f"Installing KDK package: {kdk_path.name}") logging.info(f"- This may take a while...") @@ -607,10 +599,6 @@ class KernelDebugKitUtilities: bool: True if successful, False if not """ - if os.getuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False: - logging.warning("Cannot install KDK, not running as root") - return False - logging.info(f"Extracting downloaded KDK disk image") with tempfile.TemporaryDirectory() as mount_point: result = subprocess_wrapper.run_as_root(["/usr/bin/hdiutil", "attach", kdk_path, "-mountpoint", mount_point, "-nobrowse"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) @@ -669,10 +657,6 @@ class KernelDebugKitUtilities: logging.warning("Malformed KDK Info.plist provided, cannot create backup") return - if os.getuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False: - logging.warning("Cannot create KDK backup, not running as root") - return - if not Path(KDK_INSTALL_PATH).exists(): subprocess_wrapper.run_as_root(["/bin/mkdir", "-p", KDK_INSTALL_PATH], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) diff --git a/opencore_legacy_patcher/support/logging_handler.py b/opencore_legacy_patcher/support/logging_handler.py index 8aff1efd9..70202309e 100644 --- a/opencore_legacy_patcher/support/logging_handler.py +++ b/opencore_legacy_patcher/support/logging_handler.py @@ -131,9 +131,6 @@ class InitializeLoggingSupport: This in turn breaks normal OCLP execution to write to log file """ - if os.geteuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False: - return - paths = [ self.log_filepath, # ~/Library/Logs/Dortania/OpenCore-Patcher_{version}_{date}.log self.log_filepath.parent, # ~/Library/Logs/Dortania diff --git a/opencore_legacy_patcher/support/macos_installer_handler.py b/opencore_legacy_patcher/support/macos_installer_handler.py index d18f301f1..56ed658b9 100644 --- a/opencore_legacy_patcher/support/macos_installer_handler.py +++ b/opencore_legacy_patcher/support/macos_installer_handler.py @@ -64,24 +64,11 @@ class InstallerCreation(): """ logging.info("Extracting macOS installer from InstallAssistant.pkg") - if subprocess_wrapper.supports_privileged_helper() is False: - try: - applescript.AppleScript( - f'''do shell script "installer -pkg {Path(download_path)}/InstallAssistant.pkg -target /"''' - ' with prompt "OpenCore Legacy Patcher needs administrator privileges to extract the installer."' - " with administrator privileges" - " without altering line endings", - ).run() - except Exception as e: - logging.info("Failed to install InstallAssistant") - logging.info(f" Error Code: {e}") - return False - else: - result = subprocess_wrapper.run_as_root(["/usr/sbin/installer", "-pkg", f"{Path(download_path)}/InstallAssistant.pkg", "-target", "/"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - if result.returncode != 0: - logging.info("Failed to install InstallAssistant") - subprocess_wrapper.log(result) - return False + result = subprocess_wrapper.run_as_root(["/usr/sbin/installer", "-pkg", f"{Path(download_path)}/InstallAssistant.pkg", "-target", "/"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if result.returncode != 0: + logging.info("Failed to install InstallAssistant") + subprocess_wrapper.log(result) + return False logging.info("InstallAssistant installed") return True diff --git a/opencore_legacy_patcher/support/subprocess_wrapper.py b/opencore_legacy_patcher/support/subprocess_wrapper.py index a846f234b..94bb7af45 100644 --- a/opencore_legacy_patcher/support/subprocess_wrapper.py +++ b/opencore_legacy_patcher/support/subprocess_wrapper.py @@ -9,9 +9,6 @@ import logging import subprocess from pathlib import Path -from functools import cache - -from . import utilities OCLP_PRIVILEGED_HELPER = "/Library/PrivilegedHelperTools/com.dortania.opencore-legacy-patcher.privileged-helper" @@ -37,17 +34,6 @@ class PrivilegedHelperErrorCodes(enum.IntEnum): OCLP_PHT_ERROR_CATCH_ALL = 170 -@cache -def supports_privileged_helper() -> bool: - """ - Check if Privileged Helper Tool is supported. - - When privileged helper is officially shipped, this function should always return True. - Something would have gone very wrong if it doesn't exist past that point. - """ - return Path(OCLP_PRIVILEGED_HELPER).exists() - - def run(*args, **kwargs) -> subprocess.CompletedProcess: """ Basic subprocess.run wrapper. @@ -66,14 +52,6 @@ def run_as_root(*args, **kwargs) -> subprocess.CompletedProcess: if not Path(args[0][0]).exists(): raise FileNotFoundError(f"File not found: {args[0][0]}") - if supports_privileged_helper() is False: - # Fall back to old logic - # This should be removed when we start shipping the helper tool officially - if os.getuid() == 0 or utilities.check_cli_args() is not None: - return subprocess.run(*args, **kwargs) - else: - return subprocess.run(["/usr/bin/sudo"] + [args[0][0]] + args[0][1:], **kwargs) - return subprocess.run([OCLP_PRIVILEGED_HELPER] + [args[0][0]] + args[0][1:], **kwargs) diff --git a/opencore_legacy_patcher/sys_patch/sys_patch_auto.py b/opencore_legacy_patcher/sys_patch/sys_patch_auto.py index 989ce5ec2..da46a3877 100644 --- a/opencore_legacy_patcher/sys_patch/sys_patch_auto.py +++ b/opencore_legacy_patcher/sys_patch/sys_patch_auto.py @@ -336,11 +336,7 @@ Please check the Github page for more information about this release.""" def install_auto_patcher_launch_agent(self, kdk_caching_needed: bool = False): """ - Install the Auto Patcher Launch Agent - - Installs the following: - - OpenCore-Patcher.app in /Library/Application Support/Dortania/ - - com.dortania.opencore-legacy-patcher.auto-patch.plist in /Library/LaunchAgents/ + Install patcher launch services See start_auto_patch() comments for more info """ diff --git a/opencore_legacy_patcher/wx_gui/gui_settings.py b/opencore_legacy_patcher/wx_gui/gui_settings.py index 201d1a690..838d14090 100644 --- a/opencore_legacy_patcher/wx_gui/gui_settings.py +++ b/opencore_legacy_patcher/wx_gui/gui_settings.py @@ -1325,21 +1325,15 @@ Hardware Information: raise Exception("Test Exception") def on_mount_root_vol(self, event: wx.Event) -> None: - if os.geteuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False: - wx.MessageDialog(self.parent, "Please relaunch as Root to mount the Root Volume", "Error", wx.OK | wx.ICON_ERROR).ShowModal() + #Don't need to pass model as we're bypassing all logic + if sys_patch.PatchSysVolume("",self.constants)._mount_root_vol() == True: + wx.MessageDialog(self.parent, "Root Volume Mounted, remember to fix permissions before saving the Root Volume", "Success", wx.OK | wx.ICON_INFORMATION).ShowModal() else: - #Don't need to pass model as we're bypassing all logic - if sys_patch.PatchSysVolume("",self.constants)._mount_root_vol() == True: - wx.MessageDialog(self.parent, "Root Volume Mounted, remember to fix permissions before saving the Root Volume", "Success", wx.OK | wx.ICON_INFORMATION).ShowModal() - else: - wx.MessageDialog(self.parent, "Root Volume Mount Failed, check terminal output", "Error", wx.OK | wx.ICON_ERROR).ShowModal() + wx.MessageDialog(self.parent, "Root Volume Mount Failed, check terminal output", "Error", wx.OK | wx.ICON_ERROR).ShowModal() def on_bless_root_vol(self, event: wx.Event) -> None: - if os.geteuid() != 0 and subprocess_wrapper.supports_privileged_helper() is False: - wx.MessageDialog(self.parent, "Please relaunch as Root to save changes", "Error", wx.OK | wx.ICON_ERROR).ShowModal() + #Don't need to pass model as we're bypassing all logic + if sys_patch.PatchSysVolume("",self.constants)._rebuild_root_volume() == True: + wx.MessageDialog(self.parent, "Root Volume saved, please reboot to apply changes", "Success", wx.OK | wx.ICON_INFORMATION).ShowModal() else: - #Don't need to pass model as we're bypassing all logic - if sys_patch.PatchSysVolume("",self.constants)._rebuild_root_volume() == True: - wx.MessageDialog(self.parent, "Root Volume saved, please reboot to apply changes", "Success", wx.OK | wx.ICON_INFORMATION).ShowModal() - else: - wx.MessageDialog(self.parent, "Root Volume update Failed, check terminal output", "Error", wx.OK | wx.ICON_ERROR).ShowModal() \ No newline at end of file + wx.MessageDialog(self.parent, "Root Volume update Failed, check terminal output", "Error", wx.OK | wx.ICON_ERROR).ShowModal() \ No newline at end of file diff --git a/opencore_legacy_patcher/wx_gui/gui_support.py b/opencore_legacy_patcher/wx_gui/gui_support.py index 67b7fd391..8cf498d10 100644 --- a/opencore_legacy_patcher/wx_gui/gui_support.py +++ b/opencore_legacy_patcher/wx_gui/gui_support.py @@ -66,8 +66,6 @@ class GenerateMenubar: aboutItem = fileMenu.Append(wx.ID_ABOUT, "&About OpenCore Legacy Patcher") fileMenu.AppendSeparator() - relaunchItem = fileMenu.Append(wx.ID_ANY, "&Relaunch as Root") - fileMenu.AppendSeparator() revealLogItem = fileMenu.Append(wx.ID_ANY, "&Reveal Log File") menubar.Append(fileMenu, "&File") @@ -76,9 +74,6 @@ class GenerateMenubar: self.frame.Bind(wx.EVT_MENU, lambda event: gui_about.AboutFrame(self.constants), aboutItem) self.frame.Bind(wx.EVT_MENU, lambda event: subprocess.run(["/usr/bin/open", "--reveal", self.constants.log_filepath]), revealLogItem) - if os.geteuid() == 0 or subprocess_wrapper.supports_privileged_helper() is True: - relaunchItem.Enable(False) - class GaugePulseCallback: """