setgid should be called before setuid

If you setuid to a non-zero value first(meaning you're no longer root),
then call setgroups, the effective uid of the process
is now no longer root, meaning that the internal setgid call fails

This also removes the duplicated if loop

Change-Id: I5d66fccd9ffb07df0c2e4435ec3da767b3b61117
This commit is contained in:
Max Lamprecht 2023-02-13 10:45:19 +01:00
parent c2b6df05e0
commit 476d358c7b
1 changed files with 1 additions and 3 deletions

View File

@ -414,13 +414,11 @@ class Daemon(object):
msg = _('Failed to remove supplemental groups')
LOG.critical(msg)
raise FailedToDropPrivileges(msg)
setgid(self.group)
if self.user is not None:
setuid(self.user)
if self.group is not None:
setgid(self.group)
finally:
capabilities.set_keepcaps(False)