drop permissions

This commit is contained in:
Lukas Zumvorde 2020-08-07 18:04:31 +02:00
parent 541ecea796
commit bc79d95bca

23
dwl.c
View File

@ -671,6 +671,25 @@ dirtomon(int dir)
} }
} }
static bool drop_permissions(void) {
if (getuid() != geteuid() || getgid() != getegid()) {
// Set the gid and uid in the correct order.
if (setgid(getgid()) != 0) {
fprintf(stderr, "Unable to drop root group, refusing to start\n");
return false;
}
if (setuid(getuid()) != 0) {
fprintf(stderr, "Unable to drop root user, refusing to start\n");
return false;
}
}
if (setgid(0) != -1 || setuid(0) != -1) {
fprintf(stderr, "Unable to drop root, refusing to start\n");
return false;
}
return true;
}
void void
focusclient(Client *old, Client *c, int lift) focusclient(Client *old, Client *c, int lift)
{ {
@ -1846,6 +1865,10 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!drop_permissions()) {
exit(EXIT_FAILURE);
}
/* The Wayland display is managed by libwayland. It handles accepting /* The Wayland display is managed by libwayland. It handles accepting
* clients from the Unix socket, manging Wayland globals, and so on. */ * clients from the Unix socket, manging Wayland globals, and so on. */
dpy = wl_display_create(); dpy = wl_display_create();