mirror of
https://codeberg.org/dwl/dwl.git
synced 2025-10-26 17:54:14 +00:00
drop permissions
This commit is contained in:
parent
541ecea796
commit
bc79d95bca
23
dwl.c
23
dwl.c
@ -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
|
||||
focusclient(Client *old, Client *c, int lift)
|
||||
{
|
||||
@ -1846,6 +1865,10 @@ main(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!drop_permissions()) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* The Wayland display is managed by libwayland. It handles accepting
|
||||
* clients from the Unix socket, manging Wayland globals, and so on. */
|
||||
dpy = wl_display_create();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user