From 6e78279614a0a27697c9c79b0c122298d5ee2b72 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 18 Jun 2020 22:19:57 +0200 Subject: [PATCH] keymap: Add back a tiny utility for setting the system keyboard layout This patch removes the setuid-root flag from the KeyboardSettings GUI application and adds back the old "keymap" program. It doesn't feel very safe and sound to have a GUI program runnable as setuid-root, so in the next patch I'll be making KeyboardSettings call out to the "keymap" program to do its bidding. --- Applications/KeyboardSettings/main.cpp | 15 ----------- Meta/build-root-filesystem.sh | 5 ++-- Userland/CMakeLists.txt | 5 ++-- Userland/keymap.cpp | 35 ++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 Userland/keymap.cpp diff --git a/Applications/KeyboardSettings/main.cpp b/Applications/KeyboardSettings/main.cpp index 6a70c1beb97..b1f16e70b2e 100644 --- a/Applications/KeyboardSettings/main.cpp +++ b/Applications/KeyboardSettings/main.cpp @@ -43,21 +43,6 @@ int main(int argc, char** argv) { - const char* path = nullptr; - Core::ArgsParser args_parser; - args_parser.add_positional_argument(path, "The mapping file to be used", "file", Core::ArgsParser::Required::No); - args_parser.parse(argc, argv); - - if (path != nullptr) { - Keyboard::CharacterMap character_map(path); - int rc = character_map.set_system_map(); - - if (rc != 0) { - fprintf(stderr, "%s\n", strerror(-rc)); - } - - return rc; - } // If there is no command line parameter go for GUI. GUI::Application app(argc, argv); diff --git a/Meta/build-root-filesystem.sh b/Meta/build-root-filesystem.sh index 3b69b31e558..3e6b882b60e 100755 --- a/Meta/build-root-filesystem.sh +++ b/Meta/build-root-filesystem.sh @@ -37,7 +37,7 @@ chown $window_uid:$window_gid mnt/etc/WindowServer/WindowServer.ini echo "/bin/sh" > mnt/etc/shells chown 0:$wheel_gid mnt/bin/su -chown 0:$wheel_gid mnt/bin/KeyboardSettings +chown 0:$phys_gid mnt/bin/keymap chown 0:$phys_gid mnt/bin/shutdown chown 0:$phys_gid mnt/bin/reboot chown 0:0 mnt/boot/Kernel @@ -48,7 +48,7 @@ chmod 4750 mnt/bin/su chmod 4755 mnt/bin/ping chmod 4750 mnt/bin/reboot chmod 4750 mnt/bin/shutdown -chmod 4750 mnt/bin/KeyboardSettings +chmod 4750 mnt/bin/keymap echo "done" @@ -161,7 +161,6 @@ ln -s Debugger mnt/bin/sdb ln -s SystemMonitor mnt/bin/sm ln -s ProfileViewer mnt/bin/pv ln -s WebServer mnt/bin/ws -ln -s KeyboardSettings mnt/bin/keymap ln -s Solitaire mnt/bin/sl ln -s WebView mnt/bin/wv echo "done" diff --git a/Userland/CMakeLists.txt b/Userland/CMakeLists.txt index 5ea7c15358e..707be29d2b6 100644 --- a/Userland/CMakeLists.txt +++ b/Userland/CMakeLists.txt @@ -12,8 +12,10 @@ target_link_libraries(avol LibAudio) target_link_libraries(copy LibGUI) target_link_libraries(disasm LibX86) target_link_libraries(functrace LibDebug LibX86) -target_link_libraries(html LibWeb) target_link_libraries(ht LibWeb) +target_link_libraries(html LibWeb) +target_link_libraries(js LibJS LibLine) +target_link_libraries(keymap LibKeyboard) target_link_libraries(lspci LibPCIDB) target_link_libraries(man LibMarkdown) target_link_libraries(md LibMarkdown) @@ -24,4 +26,3 @@ target_link_libraries(paste LibGUI) target_link_libraries(pro LibProtocol) target_link_libraries(test-crypto LibCrypto LibTLS LibLine) target_link_libraries(tt LibPthread) -target_link_libraries(js LibJS LibLine) diff --git a/Userland/keymap.cpp b/Userland/keymap.cpp new file mode 100644 index 00000000000..d97ac09d844 --- /dev/null +++ b/Userland/keymap.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + if (pledge("stdio setkeymap rpath", nullptr) < 0) { + perror("pledge"); + return 1; + } + + if (unveil("/res/keymaps", "r") < 0) { + perror("unveil"); + return 1; + } + + if (unveil(nullptr, nullptr) < 0) { + perror("unveil"); + return 1; + } + + const char* path = nullptr; + Core::ArgsParser args_parser; + args_parser.add_positional_argument(path, "The mapping file to be used", "file"); + args_parser.parse(argc, argv); + + Keyboard::CharacterMap character_map(path); + int rc = character_map.set_system_map(); + if (rc != 0) + fprintf(stderr, "%s\n", strerror(-rc)); + + return rc; +}