mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 06:28:13 +00:00
Escalator: Major rework and enable forwarding of stdin/stdout
- Escalator now uses `posix_spawn` instead of `exec` - Escalator is now able to forward stdin and stdout - A few general changes to improve code quality
This commit is contained in:
parent
059904371f
commit
27297d2817
3 changed files with 64 additions and 22 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Ashley N. <dev-serenity@ne0ndrag0n.com>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
* Copyright (c) 2023, Fabian Dellwing <fabian@dellwing.net>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -22,10 +23,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
Core::ArgsParser args_parser;
|
||||
StringView description;
|
||||
bool preserve_env = false;
|
||||
bool forward_stdin = false;
|
||||
bool forward_stdout = false;
|
||||
args_parser.set_general_help("Escalate privilege to root for a given command using a GUI prompt.");
|
||||
args_parser.set_stop_on_first_non_option(true);
|
||||
args_parser.add_option(description, "Custom prompt to use for dialog", "prompt", 'P', "prompt");
|
||||
args_parser.add_option(preserve_env, "Preserve user environment when running command", "preserve-env", 'E');
|
||||
args_parser.add_option(forward_stdin, "Forward stdin to targets stdin", "forward-stdin", 'I');
|
||||
args_parser.add_option(forward_stdout, "Forward targets stdout to stdout", "forward-stdout", 'O');
|
||||
args_parser.add_positional_argument(command, "Command to run at elevated privilege level", "command");
|
||||
args_parser.parse(arguments);
|
||||
|
||||
|
@ -33,14 +38,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
auto app = TRY(GUI::Application::create(arguments));
|
||||
|
||||
auto executable_path = FileSystem::resolve_executable_from_environment(command[0]);
|
||||
auto executable_path = FileSystem::resolve_executable_from_environment(command[0], AT_EACCESS);
|
||||
if (executable_path.is_error()) {
|
||||
GUI::MessageBox::show_error(nullptr, DeprecatedString::formatted("Could not execute command {}: Command not found.", command[0]));
|
||||
return 127;
|
||||
}
|
||||
|
||||
auto current_user = TRY(Core::Account::self());
|
||||
auto window = TRY(EscalatorWindow::try_create(executable_path.value(), command, EscalatorWindow::Options { description, current_user, preserve_env }));
|
||||
auto window = TRY(EscalatorWindow::try_create(executable_path.value(), command, EscalatorWindow::Options { description, current_user, preserve_env, forward_stdin, forward_stdout }));
|
||||
|
||||
if (current_user.uid() != 0) {
|
||||
window->show();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue