cap_sys_admin->cap_setuid for gsr-global-hotkeys

This commit is contained in:
dec05eba
2024-11-24 23:49:24 +01:00
parent a872c07f7a
commit 7d19afc0ab
3 changed files with 12 additions and 5 deletions

View File

@@ -1,2 +1,2 @@
option('systemd', type : 'boolean', value : true, description : 'Install systemd service file')
option('capabilities', type : 'boolean', value : true, description : 'Set binary admin capability on gsr-global-hotkeys binary to allow global hotkeys')
option('capabilities', type : 'boolean', value : true, description : 'Set binary setuid capability on gsr-global-hotkeys binary to allow global hotkeys')

View File

@@ -1,4 +1,4 @@
#!/bin/sh
/usr/sbin/setcap cap_sys_admin+ep ${MESON_INSTALL_DESTDIR_PREFIX}/bin/gsr-global-hotkeys \
/usr/sbin/setcap cap_setuid+ep ${MESON_INSTALL_DESTDIR_PREFIX}/bin/gsr-global-hotkeys \
|| echo "\n!!! Please re-run install as root\n"

View File

@@ -44,7 +44,7 @@ static int open_restricted(const char *path, int flags, void *user_data) {
(void)user_data;
int fd = open(path, flags);
if(fd < 0)
fprintf(stderr, "Failed to open %s, error: %s\n", path, strerror(errno));
fprintf(stderr, "error: failed to open %s, error: %s\n", path, strerror(errno));
return fd < 0 ? -errno : fd;
}
@@ -178,7 +178,7 @@ static bool mapper_refresh_keymap(key_mapper *mapper) {
};
mapper->xkb_keymap = xkb_keymap_new_from_names(mapper->xkb_context, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
if(mapper->xkb_keymap == NULL) {
fprintf(stderr, "Failed to create XKB keymap.\n");
fprintf(stderr, "error: failed to create XKB keymap.\n");
return false;
}
@@ -189,7 +189,7 @@ static bool mapper_refresh_keymap(key_mapper *mapper) {
mapper->xkb_state = xkb_state_new(mapper->xkb_keymap);
if(mapper->xkb_state == NULL) {
fprintf(stderr, "Failed to create XKB state.\n");
fprintf(stderr, "error: failed to create XKB state.\n");
return false;
}
@@ -197,6 +197,13 @@ static bool mapper_refresh_keymap(key_mapper *mapper) {
}
int main(void) {
if(geteuid() != 0) {
if(setuid(0) == -1) {
fprintf(stderr, "error: failed to change user to root\n");
return 1;
}
}
struct udev *udev = udev_new();
if(!udev) {
fprintf(stderr, "error: udev_new failed\n");