MCPcopy Create free account
hub / github.com/celery/celery / _setuid

Function _setuid

celery/platforms.py:622–647  ·  view source on GitHub ↗
(uid, gid)

Source from the content-addressed store, hash-verified

620
621
622def _setuid(uid, gid):
623 # If GID isn't defined, get the primary GID of the user.
624 if not gid and pwd:
625 gid = pwd.getpwuid(uid).pw_gid
626 # Must set the GID before initgroups(), as setgid()
627 # is known to zap the group list on some platforms.
628
629 # setgid must happen before setuid (otherwise the setgid operation
630 # may fail because of insufficient privileges and possibly stay
631 # in a privileged group).
632 setgid(gid)
633 initgroups(uid, gid)
634
635 # at last:
636 setuid(uid)
637 # ... and make sure privileges cannot be restored:
638 try:
639 setuid(0)
640 except OSError as exc:
641 if exc.errno != errno.EPERM:
642 raise
643 # we should get here: cannot restore privileges,
644 # everything was fine.
645 else:
646 raise SecurityError(
647 'non-root user able to restore privileges after setuid.')
648
649
650if hasattr(_signal, 'setitimer'):

Callers 1

maybe_drop_privilegesFunction · 0.85

Calls 4

setgidFunction · 0.85
initgroupsFunction · 0.85
setuidFunction · 0.85
SecurityErrorClass · 0.85

Tested by

no test coverage detected