From 19afb4475cd53179ce71b4e2def154a2091380a0 Mon Sep 17 00:00:00 2001 From: Greg Williamson Date: Sun, 5 Apr 2020 03:06:47 -0400 Subject: [PATCH] Shell Execution Prompts (#1955) --- ENIGMAsystem/SHELL/Platforms/General/PFmain.h | 5 ++ .../SHELL/Platforms/General/POSIX/shell.cpp | 57 +++++++++++++------ .../SHELL/Widget_Systems/GTK+/dialogs.cpp | 5 ++ .../SHELL/Widget_Systems/widgets_mandatory.h | 2 + .../SHELL/Widget_Systems/xlib/Info/About.ey | 3 - .../SHELL/Widget_Systems/xlib/kdialog.cpp | 5 +- .../SHELL/Widget_Systems/xlib/zenity.cpp | 5 +- 7 files changed, 57 insertions(+), 25 deletions(-) diff --git a/ENIGMAsystem/SHELL/Platforms/General/PFmain.h b/ENIGMAsystem/SHELL/Platforms/General/PFmain.h index 4c4d2667f1..1b3e1f8f6f 100644 --- a/ENIGMAsystem/SHELL/Platforms/General/PFmain.h +++ b/ENIGMAsystem/SHELL/Platforms/General/PFmain.h @@ -45,6 +45,11 @@ namespace enigma { void set_room_speed(int rs); } +namespace enigma_insecure { + void execute_shell(std::string operation, std::string fname, std::string args, bool wait = false); + void execute_shell_for_output(const std::string &command, std::string& res); +} + namespace enigma_user { extern std::string working_directory; diff --git a/ENIGMAsystem/SHELL/Platforms/General/POSIX/shell.cpp b/ENIGMAsystem/SHELL/Platforms/General/POSIX/shell.cpp index 4f5e94db76..ec3b81b958 100644 --- a/ENIGMAsystem/SHELL/Platforms/General/POSIX/shell.cpp +++ b/ENIGMAsystem/SHELL/Platforms/General/POSIX/shell.cpp @@ -1,36 +1,57 @@ #include "Platforms/General/PFmain.h" #include "Widget_Systems/widgets_mandatory.h" +static bool asked_if_idiot = false; +static bool confirmed_idiot = false; + +static void ask_if_idiot() { + if (!asked_if_idiot) { + if (enigma_user::show_question("The following game runs shell functions that are almost always unnecessary\ + and can potentionally cause irreparable harm to your system such as deleting you home folder.\ + We advise only enabling these functions after careful inspection of the game's source code\ + Would you like to enable these dangerous funtions?")) { confirmed_idiot = true; } + asked_if_idiot = true; + } +} + +namespace enigma_insecure { + void execute_shell(std::string operation, std::string fname, std::string args, bool wait) { + if (system(NULL)) { + system(("\"" + fname + "\" " + args + (wait ? " &" : "")).c_str()); + } else { + DEBUG_MESSAGE("execute_program cannot be used as there is no command processor!", MESSAGE_TYPE::M_ERROR); + return; + } + } + + void execute_shell_for_output(const std::string &command, std::string& res) { + char buffer[BUFSIZ]; + FILE *pf = popen(command.c_str(), "r"); + while (!feof(pf)) { + res.append(buffer, fread(&buffer, sizeof(char), BUFSIZ, pf)); + } + pclose(pf); + } +} + namespace enigma_user { void execute_shell(std::string operation, std::string fname, std::string args) { - if (system(NULL)) { - system(("\"" + fname + "\" " + args + " &").c_str()); - } else { - DEBUG_MESSAGE("execute_shell cannot be used as there is no command processor!", MESSAGE_TYPE::M_ERROR); - return; - } + ask_if_idiot(); + if (confirmed_idiot) enigma_insecure::execute_shell(operation, fname, args, false); } void execute_shell(std::string fname, std::string args) { execute_shell("", fname, args); } void execute_program(std::string operation, std::string fname, std::string args, bool wait) { - if (system(NULL)) { - system(("\"" + fname + "\" " + args + (wait ? " &" : "")).c_str()); - } else { - DEBUG_MESSAGE("execute_program cannot be used as there is no command processor!", MESSAGE_TYPE::M_ERROR); - return; - } + ask_if_idiot(); + if (confirmed_idiot) enigma_insecure::execute_shell(operation, fname, args, wait); } std::string execute_shell_for_output(const std::string &command) { + ask_if_idiot(); std::string res; - char buffer[BUFSIZ]; - FILE *pf = popen(command.c_str(), "r"); - while (!feof(pf)) { - res.append(buffer, fread(&buffer, sizeof(char), BUFSIZ, pf)); - } - pclose(pf); + if (confirmed_idiot) enigma_insecure::execute_shell_for_output(command, res); return res; } diff --git a/ENIGMAsystem/SHELL/Widget_Systems/GTK+/dialogs.cpp b/ENIGMAsystem/SHELL/Widget_Systems/GTK+/dialogs.cpp index c25e6994b7..a461fab7de 100644 --- a/ENIGMAsystem/SHELL/Widget_Systems/GTK+/dialogs.cpp +++ b/ENIGMAsystem/SHELL/Widget_Systems/GTK+/dialogs.cpp @@ -40,6 +40,11 @@ void show_debug_message(string errortext, MESSAGE_TYPE type) { //TODO: Implement } +bool show_question(std::string str) { +//TODO: Implement +return false; +} + int get_color(int defcol) { gdk_threads_enter(); diff --git a/ENIGMAsystem/SHELL/Widget_Systems/widgets_mandatory.h b/ENIGMAsystem/SHELL/Widget_Systems/widgets_mandatory.h index 43f50e2b11..a3913aaa0b 100644 --- a/ENIGMAsystem/SHELL/Widget_Systems/widgets_mandatory.h +++ b/ENIGMAsystem/SHELL/Widget_Systems/widgets_mandatory.h @@ -73,6 +73,8 @@ namespace enigma { namespace enigma_user { +bool show_question(std::string str); + void show_debug_message(std::string msg, MESSAGE_TYPE type = M_INFO); // This obviously displays an error message. diff --git a/ENIGMAsystem/SHELL/Widget_Systems/xlib/Info/About.ey b/ENIGMAsystem/SHELL/Widget_Systems/xlib/Info/About.ey index 8e7473d718..9a383ebe3b 100644 --- a/ENIGMAsystem/SHELL/Widget_Systems/xlib/Info/About.ey +++ b/ENIGMAsystem/SHELL/Widget_Systems/xlib/Info/About.ey @@ -10,6 +10,3 @@ Author: Samuel Venable Depends: Build-Platforms: MacOSX, Linux, FreeBSD - -Represents: - Build-Platforms: Linux, FreeBSD diff --git a/ENIGMAsystem/SHELL/Widget_Systems/xlib/kdialog.cpp b/ENIGMAsystem/SHELL/Widget_Systems/xlib/kdialog.cpp index aac3d922f8..d8284c495e 100644 --- a/ENIGMAsystem/SHELL/Widget_Systems/xlib/kdialog.cpp +++ b/ENIGMAsystem/SHELL/Widget_Systems/xlib/kdialog.cpp @@ -36,7 +36,7 @@ using enigma_user::filename_name; using enigma_user::filename_path; #include "Platforms/General/PFmain.h" -using enigma_user::execute_shell_for_output; +using enigma_insecure::execute_shell_for_output; #include "Platforms/General/PFwindow.h" using enigma_user::window_get_caption; @@ -65,7 +65,8 @@ static bool message_cancel = false; static bool question_cancel = false; static string shellscript_evaluate(string command) { - string result = execute_shell_for_output(command); + string result; + execute_shell_for_output(command, result); if (result.back() == '\n') result.pop_back(); return result; } diff --git a/ENIGMAsystem/SHELL/Widget_Systems/xlib/zenity.cpp b/ENIGMAsystem/SHELL/Widget_Systems/xlib/zenity.cpp index 6a6bba051d..51318c0d77 100644 --- a/ENIGMAsystem/SHELL/Widget_Systems/xlib/zenity.cpp +++ b/ENIGMAsystem/SHELL/Widget_Systems/xlib/zenity.cpp @@ -36,7 +36,7 @@ using enigma_user::filename_name; using enigma_user::filename_path; #include "Platforms/General/PFmain.h" -using enigma_user::execute_shell_for_output; +using enigma_insecure::execute_shell_for_output; #include "Platforms/General/PFwindow.h" using enigma_user::window_get_caption; @@ -65,7 +65,8 @@ static bool message_cancel = false; static bool question_cancel = false; static string shellscript_evaluate(string command) { - string result = execute_shell_for_output(command); + string result; + execute_shell_for_output(command, result); if (result.back() == '\n') result.pop_back(); return result; }