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.
This commit is contained in:
Andreas Kling 2020-06-18 22:19:57 +02:00
parent 0609eefd57
commit 6e78279614
Notes: sideshowbarker 2024-07-19 05:33:51 +09:00
4 changed files with 40 additions and 20 deletions

View file

@ -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);

View file

@ -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"

View file

@ -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)

35
Userland/keymap.cpp Normal file
View file

@ -0,0 +1,35 @@
#include <LibCore/ArgsParser.h>
#include <LibKeyboard/CharacterMap.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
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;
}