remove ctypes dependency for unsigned integer math related to setgid. this should re-enable selinux usage (and usage on other systems without ctypes).

This commit is contained in:
Mahmoud Hashemi 2013-02-12 23:01:56 -08:00
parent 318b365b8a
commit 22dccb3349

View File

@ -4,16 +4,6 @@
# See the NOTICE for more information. # See the NOTICE for more information.
try:
import ctypes
except MemoryError:
# selinux execmem denial
# https://bugzilla.redhat.com/show_bug.cgi?id=488396
ctypes = None
except ImportError:
# Python on Solaris compiled with Sun Studio doesn't have ctypes
ctypes = None
import fcntl import fcntl
import os import os
import pkg_resources import pkg_resources
@ -155,26 +145,17 @@ def load_class(uri, default="sync", section="gunicorn.workers"):
def set_owner_process(uid, gid): def set_owner_process(uid, gid):
""" set user and group of workers processes """ """ set user and group of workers processes """
if gid: if gid:
try: # versions of python < 2.6.2 don't manage unsigned int for
os.setgid(gid) # groups like on osx or fedora
except OverflowError: gid = abs(gid) & 0x7FFFFFFF
if not ctypes: os.setgid(gid)
raise
# versions of python < 2.6.2 don't manage unsigned int for
# groups like on osx or fedora
os.setgid(-ctypes.c_int(-gid).value)
if uid: if uid:
os.setuid(uid) os.setuid(uid)
def chown(path, uid, gid): def chown(path, uid, gid):
try: gid = abs(gid) & 0x7FFFFFFF # see note above.
os.chown(path, uid, gid) os.chown(path, uid, gid)
except OverflowError:
if not ctypes:
raise
os.chown(path, uid, -ctypes.c_int(-gid).value)
if sys.platform.startswith("win"): if sys.platform.startswith("win"):