"""This module contains the ``seteids`` function."""
__docformat__ = "restructuredtext"
import os
def seteids(user, group):
"""Change the ``euid`` and ``egid`` if run as root.
user, group
The user and group to change to.
This function is self contained so that subclasses can easily drop this
behavior. I won't, however, bother to catch exceptions because this is
something you need to think about.
"""
import pwd
import grp
UID = GID = 2
if not os.geteuid():
os.setegid(grp.getgrnam(group)[GID]) # This must come first.
os.seteuid(pwd.getpwnam(user)[UID])
|