SystemServer: Change user only when needed

This commit is contained in:
Lucas CHOLLET 2022-07-24 13:22:40 +02:00 committed by Linus Groh
parent a13ffffbec
commit a3b8a9a142
Notes: sideshowbarker 2024-07-17 08:16:08 +09:00

View File

@ -211,7 +211,7 @@ void Service::spawn(int socket_fd)
setenv("SOCKET_TAKEOVER", builder.to_string().characters(), true);
}
if (m_account.has_value()) {
if (m_account.has_value() && m_account.value().uid() != getuid()) {
auto& account = m_account.value();
if (setgid(account.gid()) < 0 || setgroups(account.extra_gids().size(), account.extra_gids().data()) < 0 || setuid(account.uid()) < 0) {
dbgln("Failed to drop privileges (GID={}, UID={})\n", account.gid(), account.uid());