cage: allow running as root when not using setuid bit

This commit is contained in:
Jan Beich 2021-09-13 13:30:59 +00:00 committed by Jente Hidskes Ankarberg
parent a81ab701d7
commit d3d4a129e7

5
cage.c
View file

@ -149,7 +149,12 @@ cleanup_primary_client(pid_t pid)
static bool
drop_permissions(void)
{
if (getuid() == 0 || getgid() == 0) {
wlr_log(WLR_INFO, "Running as root user, this is dangerous");
return true;
}
if (getuid() != geteuid() || getgid() != getegid()) {
wlr_log(WLR_INFO, "setuid/setgid bit detected, dropping permissions");
// Set the gid and uid in the correct order.
if (setgid(getgid()) != 0 || setuid(getuid()) != 0) {
wlr_log(WLR_ERROR, "Unable to drop root, refusing to start");