From 2ac8e8e43455b872fa3de397c6645674112bd80c Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sat, 8 Jul 2023 17:18:05 -0400 Subject: [PATCH] Fixed privilege escalation input in extension manager Former-commit-id: d75cdc8010eb8b5285c532284c9b14d553c7deaf Former-commit-id: 57edd15ca67e4f2e94f5201cdb18401b5ac40f59 --- lib/stweak.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/stweak.py b/lib/stweak.py index 1e9e33e..0b9d971 100644 --- a/lib/stweak.py +++ b/lib/stweak.py @@ -507,22 +507,12 @@ def global_menu(_scr, _device_type, _top_message): _ext_name, _escalator, _action = extension_menu() # if root is needed for extension management... if _ext_name: - if _action: - # install with privilege escalation (outside of curses) - from tempfile import gettempdir - _exe_dir, _ini_dir = f"{gettempdir()}/sshyp_exe", f"{gettempdir()}/sshyp_ini" - run((_escalator, 'chown', 'root:root', _exe_dir, _ini_dir)) - run((_escalator, 'mv', _exe_dir, f"/usr/lib/sshyp/{_ext_name}")) - run((_escalator, 'mv', _ini_dir, f"/usr/lib/sshyp/extensions/{_ext_name}.ini")) - else: - # uninstall with privilege escalation (outside of curses) - run((_escalator, 'rm', '-I', f"/usr/lib/sshyp/{_ext_name}", - f"/usr/lib/sshyp/extensions/{_ext_name}.ini")) - break + return _ext_name, _escalator, _action else: _exit_signal = True if _exit_signal: break + return False, False, False # runs initial configuration wizard @@ -589,7 +579,19 @@ def wrapped_entry(_gm_device_type, _gm_top_message='configuration options:'): wrapper(lambda _wrap_stdscr: (use_default_colors(), initial_setup(_wrap_stdscr))) # any other value will be provided as the global menu device type else: - wrapper(lambda _wrap_stdscr: (use_default_colors(), - global_menu(_wrap_stdscr, _gm_device_type, _gm_top_message))) + _ext_name, _escalator, _action = \ + wrapper(lambda _wrap_stdscr: (use_default_colors(), + global_menu(_wrap_stdscr, _gm_device_type, _gm_top_message)))[1] + if _action: + # install with privilege escalation (outside of curses) + from tempfile import gettempdir + _exe_dir, _ini_dir = f"{gettempdir()}/sshyp_exe", f"{gettempdir()}/sshyp_ini" + run((_escalator, 'chown', 'root:root', _exe_dir, _ini_dir)) + run((_escalator, 'mv', _exe_dir, f"/usr/lib/sshyp/{_ext_name}")) + run((_escalator, 'mv', _ini_dir, f"/usr/lib/sshyp/extensions/{_ext_name}.ini")) + else: + # uninstall with privilege escalation (outside of curses) + run((_escalator, 'rm', '-I', f"/usr/lib/sshyp/{_ext_name}", + f"/usr/lib/sshyp/extensions/{_ext_name}.ini")) for _message in term_messages: print(f"\n{_message}\n")