mirror of
https://codeberg.org/dwl/dwl.git
synced 2026-04-08 08:21:00 -04:00
drop permissions
This commit is contained in:
parent
541ecea796
commit
bc79d95bca
1 changed files with 23 additions and 0 deletions
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
|
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();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue