Enable user access to pinephone hardware kernel interface through openrc script, remove setuid 0 requirement

master
Maarten van Gompel 4 years ago
parent 00cf2ba3ec
commit ca88d3029e
  1. 9
      Makefile
  2. 6
      configs/openrc/sxmo-pinephone
  3. 7
      programs/sxmo_screenlock.c
  4. 5
      programs/sxmo_setpinebacklight.c
  5. 6
      programs/sxmo_setpineled.c

@ -36,6 +36,8 @@ install: $(PROGRAMS)
cd configs && find . -type f -exec install -D -m 0644 "{}" "$(DESTDIR)$(PREFIX)/share/sxmo/{}" \; && cd ..
# Configs
install -D -m 0755 -t $(DESTDIR)/etc/init.d configs/openrc/sxmo-pinephone
install -D -m 0644 -t $(DESTDIR)/etc/alsa/conf.d/ configs/alsa/alsa_sxmo_enable_dmix.conf
install -D -m 0644 -t $(DESTDIR)/etc/polkit-1/rules.d/ configs/polkit/*.rules
@ -51,11 +53,12 @@ install: $(PROGRAMS)
# Bin
install -D -t $(DESTDIR)$(PREFIX)/bin scripts/*/*
install -D -o root -m 4755 programs/sxmo_setpineled $(DESTDIR)$(PREFIX)/bin/
install -D -m 0755 programs/sxmo_setpineled $(DESTDIR)$(PREFIX)/bin/
install -D -o root -m 4755 programs/sxmo_setpinebacklight $(DESTDIR)$(PREFIX)/bin/
install -D -m 0755 programs/sxmo_setpinebacklight $(DESTDIR)$(PREFIX)/bin/
install -D -o root -m 4755 programs/sxmo_screenlock $(DESTDIR)$(PREFIX)/bin/
install -D -m 0755 programs/sxmo_screenlock $(DESTDIR)$(PREFIX)/bin/
install -D programs/sxmo_megiaudioroute $(DESTDIR)$(PREFIX)/bin/
install -D programs/sxmo_vibratepine $(DESTDIR)$(PREFIX)/bin/

@ -0,0 +1,6 @@
#!/sbin/openrc-run
description="Enable user access to pinephone hardware kernel interface"
command="chmod"
command_args="a+rw /sys/module/8723cs/parameters/rtw_scan_interval_thr /sys/devices/platform/backlight/backlight/backlight/brightness /sys/power/state /sys/devices/platform/soc/1f00000.rtc/power/wakeup /sys/power/mem_sleep /sys/bus/usb/drivers/usb/unbind /sys/bus/usb/drivers/usb/bind /sys/class/leds/red:indicator/brightness /sys/class/leds/blue:indicator/brightness /sys/class/leds/green:indicator/brightness /sys/class/leds/white:flash/brightness /dev/rtc0"

@ -431,7 +431,7 @@ writefile(char *filepath, char *str)
}
void usage() {
fprintf(stderr, "Usage: sxmo_screenlock [--screen-off] [--suspend] [--wake-interval n]\n");
fprintf(stderr, "Usage: sxmo_screenlock [--screen-off] [--suspend] [--wake-interval n] [--setuid]\n");
}
@ -474,14 +474,15 @@ main(int argc, char **argv) {
target = StateSuspend;
} else if(!strcmp(argv[i], "--wake-interval")) {
wakeinterval = (time_t) atoi(argv[++i]);
} else if(!strcmp(argv[i], "--setuid")) {
if (setuid(0))
die("setuid(0) failed\n");
} else {
fprintf(stderr, "Invalid argument: %s\n", argv[i]);
return 2;
}
}
if (setuid(0))
die("setuid(0) failed\n");
if (!(dpy = XOpenDisplay(NULL)))
die("Cannot open display\n");

@ -28,11 +28,6 @@ int main(int argc, char *argv[]) {
argc--;
brightness = atoi(argv[argc--]);
if (setuid(0)) {
fprintf(stderr, "setuid(0) failed\n");
return 1;
}
if (access(pbpScreen, F_OK) != -1) {
writeFile(pbpScreen, brightness);
fprintf(stderr, "Set PBP brightness to %d\n", brightness);

@ -48,9 +48,5 @@ int main(int argc, char *argv[]) {
"sh -c 'echo %d > /sys/class/leds/%s:%s/brightness'",
brightness, color, type
);
if (setuid(0)) {
fprintf(stderr, "setuid(0) failed\n");
} else {
return system(command);
}
return system(command);
}

Loading…
Cancel
Save