drop permissions

This commit is contained in:
Lukas Zumvorde 2020-08-07 18:04:31 +02:00 committed by Owen Rafferty
parent 79b7e755b0
commit 6259c5f5d3
No known key found for this signature in database
GPG Key ID: A68B10E2554DEBCB

19
dwl.c
View File

@ -1117,6 +1117,23 @@ dirtomon(enum wlr_direction dir)
return selmon;
}
static void
drop_permissions(void)
{
if (getuid() != geteuid() || getgid() != getegid()) {
/* Set the gid and uid in the correct order. */
if (setgid(getgid()) != 0) {
die("Unable to drop root group, refusing to start");
}
if (setuid(getuid()) != 0) {
die("Unable to drop root user, refusing to start");
}
}
if (setgid(0) != -1 || setuid(0) != -1) {
die("Unable to drop root, refusing to start");
}
}
void
focusclient(Client *c, int lift)
{
@ -1929,6 +1946,8 @@ setup(void)
if (!(backend = wlr_backend_autocreate(dpy)))
die("couldn't create backend");
drop_permissions();
/* Initialize the scene graph used to lay out windows */
scene = wlr_scene_create();
layers[LyrBg] = &wlr_scene_tree_create(&scene->node)->node;