Commit d4d2ea23 authored by Chris McDonough's avatar Chris McDonough

When run as root, z2.py now changes GID context to UID-specified default group

parent 8f75cbb7
...@@ -550,21 +550,32 @@ if MONITOR_PORT: ...@@ -550,21 +550,32 @@ if MONITOR_PORT:
hostname='127.0.0.1', hostname='127.0.0.1',
port=MONITOR_PORT) port=MONITOR_PORT)
# Try to set uid to server's uid. # Try to set uid to "-u" -provided uid.
# Try to set gid to "-u" user's primary group.
# This will only work if this script is run by root. # This will only work if this script is run by root.
try: try:
import pwd import pwd
try: try:
try: gid = None
uid=string.atoi(UID)
except:
pass
if type(UID) == type(""): if type(UID) == type(""):
uid = pwd.getpwnam(UID)[2] uid = pwd.getpwnam(UID)[2]
gid = pwd.getpwnam(UID)[3]
elif type(UID) == type(1):
uid = pwd.getpwuid(UID)[2]
gid = pwd.getpwuid(UID)[3]
else:
raise KeyError
try:
if gid is not None:
try:
os.setgid(gid)
except OSError:
pass
os.setuid(uid) os.setuid(uid)
except OSError:
pass
except KeyError: except KeyError:
zLOG.LOG("z2", zLOG.ERROR, ("can't find UID %s" % UID)) zLOG.LOG("z2", zLOG.ERROR, ("can't find UID %s" % UID))
except: except:
pass pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment